From: Bill Erickson Date: Thu, 23 Jul 2015 21:40:34 +0000 (-0400) Subject: LP#1468422 API uses pcre instead of regex.h -- needs autoconf -lpcre update X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=6412c84a94e4af78938d76d6ea6ca525ad3f5672;p=working%2FEvergreen.git LP#1468422 API uses pcre instead of regex.h -- needs autoconf -lpcre update Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/c-apps/oils_auth.c b/Open-ILS/src/c-apps/oils_auth.c index 9549c8e9fa..56f3a32feb 100644 --- a/Open-ILS/src/c-apps/oils_auth.c +++ b/Open-ILS/src/c-apps/oils_auth.c @@ -6,7 +6,7 @@ #include "openils/oils_utils.h" #include "openils/oils_constants.h" #include "openils/oils_event.h" -#include +#include #define OILS_AUTH_CACHE_PRFX "oils_auth_" #define OILS_AUTH_COUNT_SFFX "_count" @@ -341,33 +341,43 @@ static int oilsAuthIdentIsBarcode(const char* identifier) { if (!bc_regex) { // if no regex is set, assume any identifier starting // with a number is a barcode. - bc_regex = strdup("^[[:digit:]]"); // dupe for later free'ing + bc_regex = strdup("^\\d"); // dupe for later free'ing } - regex_t regex; - int is_barcode = 0; - int regret; - char regerr[100]; + const char *err_str; + int err_offset, match_ret; - regret = regcomp(®ex, bc_regex, 0); - if (regret) { - osrfLogError(OSRF_LOG_MARK, - "Cannot compile barcode regex: %s", bc_regex); - } else { - regret = regexec(®ex, identifier, 0, NULL, 0); - if (!regret) { - is_barcode = true; - } else if (regret != REG_NOMATCH) { - regerror(regret, ®ex, regerr, sizeof(regerr)); - osrfLogError(OSRF_LOG_MARK, - "Error processing regex %s on %s : %s", - bc_regex, identifier, regerr); - } + pcre *compiled = pcre_compile( + bc_regex, 0, &err_str, &err_offset, NULL); + + if (compiled == NULL) { + osrfLogError(OSRF_LOG_MARK, + "Could not compile '%s': %s", bc_regex, err_str); + pcre_free(compiled); + return 0; } - regfree(®ex); - free(bc_regex); - return is_barcode; + pcre_extra *extra = pcre_study(compiled, 0, &err_str); + + if(err_str != NULL) { + osrfLogError(OSRF_LOG_MARK, + "Could not study regex '%s': %s", bc_regex, err_str); + pcre_free(compiled); + return 0; + } + + match_ret = pcre_exec( + compiled, extra, identifier, strlen(identifier), 0, 0, NULL, 0); + + pcre_free(compiled); + if (extra) pcre_free(extra); + + if (match_ret >= 0) return 1; // regex matched + + if (match_ret != PCRE_ERROR_NOMATCH) + osrfLogError(OSRF_LOG_MARK, "Unknown error processing barcode regex"); + + return 0; // regex did not match }