leafnode  1.12.0
About: Leafnode is a store & forward NNTP proxy for small (dialup) sites.
  Fossies Dox: leafnode-1.12.0.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

groupselect.c
Go to the documentation of this file.
1/* (C) Copyright 2002 - 2021 Matthias Andree, see COPYING for license. */
2
3#include <string.h>
4
5#include "config.h"
6#include "groupselect.h"
7#include "ln_log.h"
8
9pcre2_code_8 *gs_compile(const unsigned char *regex) {
10 int regex_errcode;
11 size_t regex_errpos;
12 pcre2_code_8 *re;
13
14 if (NULL == (re = pcre2_compile_8(regex, PCRE2_ZERO_TERMINATED, PCRE2_MULTILINE, &regex_errcode,
15 &regex_errpos, NULL))) {
16 unsigned char regex_errmsg[1024];
17 int len = pcre2_get_error_message_8(regex_errcode, regex_errmsg, sizeof(regex_errmsg));
18 ln_log(LNLOG_SERR, LNLOG_CTOP, "Invalid group pattern "
19 "in \"%s\" at char #%lu: %s%s", regex, (unsigned long)regex_errpos, regex_errmsg,
20 len == PCRE2_ERROR_NOMEMORY ? "[...]" : "");
21 }
22 return re;
23}
24
25/* match s against PCRE p
26 * WARNING: If p is NULL, every string s is considered a match
27 * returns 1 for match, 0 for mismatch, negative for error */
28int gs_match(const pcre2_code_8 *re, const unsigned char *s) {
29 int match;
30 pcre2_match_data_8 *match_data;
31
32 if (re == NULL) return 1;
33 match_data = pcre2_match_data_create_8(1, NULL);
34 if (NULL == match_data) {
35 ln_log(LNLOG_SERR, LNLOG_CTOP, "gs_match: out of memory allocating match_data");
36 return -1;
37 }
38
39 match = pcre2_match_8(re, s, PCRE2_ZERO_TERMINATED, 0,
40 PCRE2_ANCHORED, match_data, NULL);
41
42 pcre2_match_data_free_8(match_data);
43 if (match == PCRE2_ERROR_NOMATCH) return 0;
44 if (match >= 0) return 1;
45 return match; /* match < 0, but not PCRE2_ERROR_NOMATCH */
46}
pcre2_code_8 * gs_compile(const unsigned char *regex)
Definition: groupselect.c:9
int gs_match(const pcre2_code_8 *re, const unsigned char *s)
Definition: groupselect.c:28
void ln_log(int sev, int ctx, const char *format,...)
Definition: ln_log.c:103
#define LNLOG_SERR
Definition: ln_log.h:13
#define LNLOG_CTOP
Definition: ln_log.h:22
#define len
Definition: mastring.c:31