"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/plugins/test_lib.c" between
libextractor-1.10.tar.gz and libextractor-1.11.tar.gz

About: GNU libextractor is a library used to extract meta-data from files of arbitrary type.

test_lib.c  (libextractor-1.10):test_lib.c  (libextractor-1.11)
skipping to change at line 27 skipping to change at line 27
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. Boston, MA 02110-1301, USA.
*/ */
/** /**
* @file plugins/test_lib.c * @file plugins/test_lib.c
* @brief helper library for writing testcases * @brief helper library for writing testcases
* @author Christian Grothoff * @author Christian Grothoff
*/ */
#include "platform.h" #include "platform.h"
#include "test_lib.h" #include "test_lib.h"
#include <sys/types.h>
#include <regex.h>
#include <signal.h>
/** /**
* Function that libextractor calls for each * Function that libextractor calls for each
* meta data item found. * meta data item found.
* *
* @param cls closure the 'struct SolutionData' we are currently working on * @param cls closure the 'struct SolutionData' we are currently working on
* @param plugin_name should be "test" * @param plugin_name should be "test"
* @param type should be "COMMENT" * @param type should be "COMMENT"
* @param format should be "UTF8" * @param format should be "UTF8"
* @param data_mime_type should be "<no mime>" * @param data_mime_type should be "<no mime>"
skipping to change at line 59 skipping to change at line 62
{ {
struct SolutionData *sd = cls; struct SolutionData *sd = cls;
unsigned int i; unsigned int i;
for (i = 0; -1 != sd[i].solved; i++) for (i = 0; -1 != sd[i].solved; i++)
{ {
if ( (0 != sd[i].solved) || if ( (0 != sd[i].solved) ||
(sd[i].type != type) || (sd[i].type != type) ||
(sd[i].format != format) ) (sd[i].format != format) )
continue; continue;
if ( (EXTRACTOR_METAFORMAT_BINARY != format) && if ( (sd[i].regex) &&
( (sd[i].data_len != data_len) || (EXTRACTOR_METAFORMAT_BINARY != format) )
(0 != memcmp (sd[i].data, data, data_len)) ) ) {
continue; regex_t re;
if ( (EXTRACTOR_METAFORMAT_BINARY == format) && regmatch_t match;
( (sd[i].data_len > data_len) ||
(0 != memcmp (sd[i].data, data, sd[i].data_len)) ) ) if (0 !=
continue; regcomp (&re,
sd[i].data,
REG_EXTENDED))
{
fprintf (stderr,
"Not a valid regex: %s\n",
sd[i].data);
abort ();
}
if ( ('\0' != data[data_len - 1]) ||
(0 != regexec (&re,
data,
1,
&match,
0)) )
{
regfree (&re);
continue;
}
regfree (&re);
}
else
{
if ( (EXTRACTOR_METAFORMAT_BINARY != format) &&
( (sd[i].data_len != data_len) ||
(0 != memcmp (sd[i].data, data, data_len)) ) )
continue;
if ( (EXTRACTOR_METAFORMAT_BINARY == format) &&
( (sd[i].data_len > data_len) ||
(0 != memcmp (sd[i].data, data, sd[i].data_len)) ) )
continue;
}
if (NULL != sd[i].data_mime_type) if (NULL != sd[i].data_mime_type)
{ {
if (NULL == data_mime_type) if (NULL == data_mime_type)
continue; continue;
if (0 != strcmp (sd[i].data_mime_type, data_mime_type)) if (0 != strcmp (sd[i].data_mime_type, data_mime_type))
continue; continue;
} }
else else
{ {
skipping to change at line 142 skipping to change at line 176
(int) ps[i].solution[j].data_len, (int) ps[i].solution[j].data_len,
ps[i].solution[j].data, ps[i].solution[j].data,
plugin_name); plugin_name);
} }
else else
ps[i].solution[j].solved = 0; ps[i].solution[j].solved = 0;
/* reset for next round */ /* reset for next round */
return ret; return ret;
} }
#ifndef WINDOWS
/**
* Install a signal handler to ignore SIGPIPE.
*/
static void
ignore_sigpipe ()
{
struct sigaction oldsig;
struct sigaction sig;
memset (&sig, 0, sizeof (struct sigaction));
sig.sa_handler = SIG_IGN;
sigemptyset (&sig.sa_mask);
#ifdef SA_INTERRUPT
sig.sa_flags = SA_INTERRUPT; /* SunOS */
#else
sig.sa_flags = SA_RESTART;
#endif
if (0 != sigaction (SIGPIPE, &sig, &oldsig))
fprintf (stderr,
"Failed to install SIGPIPE handler: %s\n", strerror (errno));
}
#endif
/** /**
* Main function to be called to test a plugin. * Main function to be called to test a plugin.
* *
* @param plugin_name name of the plugin to load * @param plugin_name name of the plugin to load
* @param ps array of problems the plugin should solve; * @param ps array of problems the plugin should solve;
* NULL in filename terminates the array. * NULL in filename terminates the array.
* @return 0 on success, 1 on failure * @return 0 on success, 1 on failure
*/ */
int int
ET_main (const char *plugin_name, ET_main (const char *plugin_name,
struct ProblemSet *ps) struct ProblemSet *ps)
{ {
int ret; int ret;
/* change environment to find plugins which may not yet be /* change environment to find plugins which may not yet be
not installed but should be in the current directory (or .libs) not installed but should be in the current directory (or .libs)
on 'make check' */ on 'make check' */
if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/")) #ifndef WINDOWS
ignore_sigpipe ();
#endif
if (0 != putenv ("LIBEXTRACTOR_PREFIX=./.libs/"))
fprintf (stderr, fprintf (stderr,
"Failed to update my environment, plugin loading may fail: %s\n", "Failed to update my environment, plugin loading may fail: %s\n",
strerror (errno)); strerror (errno));
ret = run (plugin_name, ps, EXTRACTOR_OPTION_DEFAULT_POLICY); ret = run (plugin_name, ps, EXTRACTOR_OPTION_DEFAULT_POLICY);
if (0 != ret) if (0 != ret)
return ret; return ret;
ret = run (plugin_name, ps, EXTRACTOR_OPTION_IN_PROCESS); ret = run (plugin_name, ps, EXTRACTOR_OPTION_IN_PROCESS);
if (0 != ret) if (0 != ret)
return ret; return ret;
return 0; return 0;
 End of changes. 4 change blocks. 
9 lines changed or deleted 71 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)