Compare commits

..

No commits in common. "e004f116b7be4919223a087129b51662a1663399" and "55aa25eca3839ae6eebe75cfe9791eb8087aad88" have entirely different histories.

10 changed files with 49 additions and 56 deletions

View File

@ -18,7 +18,7 @@
## File formats, encodings and standards ## File formats, encodings and standards
- [x] migrate to pcre2, as pcre is obsolete - [ ] migrate to pcre2, as pcre is obsolete
- [ ] use a more modern hash function than MD5 - [ ] use a more modern hash function than MD5
- [ ] MIME support - [ ] MIME support
- [ ] support for GnuPG - [ ] support for GnuPG

View File

@ -34,35 +34,34 @@ AC_HEADER_DIRENT
# Checks for libraries. # Checks for libraries.
# Check for PCRE2 library # Check for PCRE library
AC_ARG_WITH(pcre2, [ --without-pcre2 Compile without Perl regexp support],, AC_ARG_WITH(pcre, [ --without-pcre Compile without Perl regexp support],,
[ [
AC_PATH_PROG(PCRE2_CONFIG, pcre2-config) AC_PATH_PROG(PCRE_CONFIG, pcre-config)
if test "$PCRE2_CONFIG"; then if test "$PCRE_CONFIG"; then
CFLAGS="$CFLAGS `$PCRE2_CONFIG --cflags`" CFLAGS="$CFLAGS `$PCRE_CONFIG --cflags`"
LIBS="$LIBS `$PCRE2_CONFIG --libs32`" LIBS="$LIBS `$PCRE_CONFIG --libs`"
AC_LINK_IFELSE( AC_LINK_IFELSE(
[ [
#define PCRE2_CODE_UNIT_WIDTH 32 #include <pcre.h>
#include <pcre2.h>
int main () int main ()
{ {
return 0; return 0;
} }
], ],
AC_DEFINE(HAVE_LIBPCRE2), AC_DEFINE(HAVE_LIBPCRE),
[ [
AC_MSG_NOTICE(found pcre2-config but could not compile test program.) AC_MSG_NOTICE(found pcre-config but could not compile test program.)
AC_MSG_FAILURE(is PCRE2 properly installed?) AC_MSG_FAILURE(is PCRE properly installed?)
] ]
) )
else else
AC_MSG_NOTICE(pcre2-config not found) AC_MSG_NOTICE(pcre-config not found)
AC_MSG_NOTICE(trying to find PCRE2 anyway) AC_MSG_NOTICE(trying to find PCRE anyway)
AC_CHECK_LIB(pcre2, main) AC_CHECK_LIB(pcre, main)
fi fi
] ]
) )

View File

@ -25,8 +25,8 @@
/* Define to 1 if you have the `garfield' library (-lgarfield). */ /* Define to 1 if you have the `garfield' library (-lgarfield). */
#undef HAVE_LIBGARFIELD #undef HAVE_LIBGARFIELD
/* Define to 1 if you have the `pcre2' library (-lpcre2). */ /* Define to 1 if you have the `pcre' library (-lpcre). */
#undef HAVE_LIBPCRE2 #undef HAVE_LIBPCRE
/* Define to 1 if you have the `z' library (-lz). */ /* Define to 1 if you have the `z' library (-lz). */
#undef HAVE_LIBZ #undef HAVE_LIBZ

View File

@ -74,9 +74,9 @@ version (void)
/* /*
fprintf (stdout, "HAVE_LIBLOCKFILE "); fprintf (stdout, "HAVE_LIBLOCKFILE ");
*/ */
#ifdef HAVE_LIBPCRE2 #ifdef HAVE_LIBPCRE
print_wrap ("HAVE_LIBPCRE2"); print_wrap ("HAVE_LIBPCRE");
#endif /* HAVE_LIBPCRE2 */ #endif /* HAVE_LIBPCRE */
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
print_wrap ("HAVE_LIBZ"); print_wrap ("HAVE_LIBZ");
#endif /* HAVE_LIBZ */ #endif /* HAVE_LIBZ */
@ -128,10 +128,10 @@ help (void)
"Matching criteria:\n\n" "Matching criteria:\n\n"
" -E, --extended-regexp\tPATTERN is an extended regular expression\n" " -E, --extended-regexp\tPATTERN is an extended regular expression\n"
" -G, --basic-regexp\t\tPATTERN is a basic regular expression\n"); " -G, --basic-regexp\t\tPATTERN is a basic regular expression\n");
#ifdef HAVE_LIBPCRE2 #ifdef HAVE_LIBPCRE
fprintf (stdout, fprintf (stdout,
" -P, --perl-regexp\t\tPATTERN is a Perl regular expression\n"); " -P, --perl-regexp\t\tPATTERN is a Perl regular expression\n");
#endif /* HAVE_LIBPCRE2 */ #endif /* HAVE_LIBPCRE */
fprintf (stdout, fprintf (stdout,
" -e, --regexp=PATTERN\t\tUse PATTERN as a regular expression\n" " -e, --regexp=PATTERN\t\tUse PATTERN as a regular expression\n"
" -i, --ignore-case\t\tIgnore case distinctions\n" " -i, --ignore-case\t\tIgnore case distinctions\n"

View File

@ -99,11 +99,11 @@ main (int argc, char **argv)
if (config.haveregex) if (config.haveregex)
{ {
#ifdef HAVE_LIBPCRE2 #ifdef HAVE_LIBPCRE
if (config.regextype == REGEX_PERL) if (config.regextype == REGEX_PERL)
pcre_init (); pcre_init ();
else else
#endif /* HAVE_LIBPCRE2 */ #endif /* HAVE_LIBPCRE */
regex_init (); regex_init ();
} }
else else

View File

@ -120,7 +120,7 @@ typedef struct
char hostname[HOST_NAME_SIZE]; char hostname[HOST_NAME_SIZE];
char *boxname, *outboxname, *pipecmd, *tmpfilename, *regex_s; char *boxname, *outboxname, *pipecmd, *tmpfilename, *regex_s;
void *pcre_pattern, *posix_pattern, *match_data; void *pcre_pattern, *pcre_hints, *posix_pattern;
int res1, res2; int res1, res2;
action_t action; action_t action;

View File

@ -373,7 +373,7 @@ set_option_regextype (regextype_t regextype)
exit (2); exit (2);
} }
#ifndef HAVE_LIBPCRE2 #ifndef HAVE_LIBPCRE
if (regextype == REGEX_PERL); if (regextype == REGEX_PERL);
{ {
fprintf (stderr, fprintf (stderr,
@ -381,6 +381,6 @@ set_option_regextype (regextype_t regextype)
APPNAME); APPNAME);
exit (2); exit (2);
} }
#endif /* HAVE_LIBPCRE2 */ #endif /* HAVE_LIBPCRE */
config.regextype = regextype; config.regextype = regextype;
} }

View File

@ -21,58 +21,52 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <regex.h> #include <regex.h>
#ifdef HAVE_LIBPCRE2 #ifdef HAVE_LIBPCRE
# define PCRE2_CODE_UNIT_WIDTH 32 # include <pcre.h>
# include <pcre2.h> #endif /* HAVE_LIBPCRE */
#endif /* HAVE_LIBPCRE2 */
#include "mboxgrep.h" #include "mboxgrep.h"
#include "message.h" #include "message.h"
#include "wrap.h" /* xcalloc() et cetera */ #include "wrap.h" /* xcalloc() et cetera */
#ifdef HAVE_LIBPCRE2 #ifdef HAVE_LIBPCRE
void void
pcre_init (void) pcre_init (void)
{ {
int errornumber; int errptr;
PCRE2_SIZE erroroffset; const char *error;
config.pcre_pattern = config.pcre_pattern =
(pcre2_code *) pcre2_compile ((PCRE2_SPTR) config.regex_s, (PCRE2_SIZE) strlen (config.regex_s), (pcre *) pcre_compile (config.regex_s,
(config.ignorecase ? PCRE2_CASELESS : 0), (config.ignorecase ? PCRE_CASELESS : 0),
&errornumber, &erroroffset, NULL); &error, &errptr, NULL);
if (config.pcre_pattern == NULL) if (config.pcre_pattern == NULL)
{ {
if (config.merr) if (config.merr)
{ fprintf (stderr, "%s: %s: %s\n", APPNAME, config.regex_s, error);
PCRE2_UCHAR buffer[256];
pcre2_get_error_message (errornumber, buffer, sizeof(buffer));
fprintf (stderr, "%s: PCRE2 compilation failed at offset %d: %s\n",
APPNAME, (int) erroroffset, (char *) buffer);
}
exit (2); exit (2);
} }
config.match_data =
(pcre2_match_data* ) pcre2_match_data_create_from_pattern (config.pcre_pattern, NULL);
} }
void void
pcre_match (message_t * msg) pcre_match (message_t * msg)
{ {
int of[BUFSIZ];
if (config.headers) if (config.headers)
config.res1 = config.res1 =
pcre2_match ((pcre2_code *) config.pcre_pattern, pcre_exec ((pcre *) config.pcre_pattern,
(PCRE2_SPTR) msg->headers, (int) strlen (msg->headers), 0, 0, config.match_data, NULL); (pcre_extra *) config.pcre_hints,
msg->headers, (int) strlen (msg->headers), 0, 0, of, BUFSIZ);
if (config.body) if (config.body)
config.res2 = config.res2 =
pcre2_match ((pcre2_code *) config.pcre_pattern, pcre_exec ((pcre *) config.pcre_pattern,
(PCRE2_SPTR) msg->body, (int) strlen (msg->body), 0, 0, config.match_data, NULL); (pcre_extra *) config.pcre_hints,
msg->body, (int) strlen (msg->body), 0, 0, of, BUFSIZ);
config.res1 = config.res1 ^ 1; config.res1 = config.res1 ^ 1;
config.res2 = config.res2 ^ 1; config.res2 = config.res2 ^ 1;
} }
#endif /* HAVE_LIBPCRE2 */ #endif /* HAVE_LIBPCRE */
void void
regex_init (void) regex_init (void)

View File

@ -19,9 +19,9 @@
#include "mboxgrep.h" #include "mboxgrep.h"
#ifdef HAVE_LIBPCRE2 #ifdef HAVE_LIBPCRE
void pcre_init (void); void pcre_init (void);
void pcre_match (message_t * msg); void pcre_match (message_t * msg);
#endif /* HAVE_LIBPCRE2 */ #endif /* HAVE_LIBPCRE */
void regex_init (void); void regex_init (void);
void regex_match (message_t * msg); void regex_match (message_t * msg);

View File

@ -146,11 +146,11 @@ scan_mailbox (char path[])
if (msg->from == NULL) if (msg->from == NULL)
msg->from = (char *) xstrdup ("nobody"); msg->from = (char *) xstrdup ("nobody");
#ifdef HAVE_LIBPCRE2 #ifdef HAVE_LIBPCRE
if (config.regextype == REGEX_PERL) if (config.regextype == REGEX_PERL)
pcre_match (msg); pcre_match (msg);
else else
#endif /* HAVE_LIBPCRE2 */ #endif /* HAVE_LIBPCRE */
regex_match (msg); regex_match (msg);
if (config.dedup) if (config.dedup)