23 #include <sys/types.h>
54 static inline int rfilter_check(
struct rfilter *rf,
const char *str,
65 for (i = 0; i < array_list_len(&rf->
list); ++
i) {
67 if (regexec(rfe->
regex,str,0,NULL,0) == 0) {
81 static inline int rfilter_add(
struct rfilter *rf,
82 char *rstr,
int accept,
void *
data) {
88 regex = (regex_t *)
malloc(
sizeof(*regex));
89 memset(regex,0,
sizeof(*regex));
90 if ((rc = regcomp(regex,rstr,REG_EXTENDED | REG_NOSUB))) {
91 regerror(rc,regex,errbuf,64);
92 verror(
"bad regex '%s': %s\n",rstr,errbuf);
99 memset(rfe,0,
sizeof(*rfe));
104 array_list_add(&rf->
list,rfe);
111 memset(rf,0,
sizeof(*rf));
113 array_list_init(&rf->
list,0);
118 static inline void rfilter_free(
struct rfilter *rf) {
122 for (i = 0; i < array_list_len(&rf->
list); ++
i) {
135 static inline struct rfilter *rfilter_create_parse(
char *fstr) {
141 while (*fstr ==
' ' || *fstr ==
'\t')
144 if (*fstr ==
'.' || *fstr ==
'*' || *fstr ==
'\0')
148 if ((*fstr ==
'1' || *fstr ==
'A' || *fstr ==
'a')
149 && *(fstr+1) ==
':' && *(fstr+2) ==
':') {
153 else if ((*fstr ==
'1' || *fstr ==
'A' || *fstr ==
'a')
154 && *(fstr+1) ==
'\0') {
158 else if ((*fstr ==
'0' || *fstr ==
'R' || *fstr ==
'r')
159 && *(fstr+1) ==
':' && *(fstr+2) ==
':') {
163 else if ((*fstr ==
'0' || *fstr ==
'R' || *fstr ==
'r')
164 && *(fstr+1) ==
'\0') {
172 rf = rfilter_create(pol);
174 while ((token = strtok_r((!token)?fstr:NULL,
";",&saveptr))) {
177 if ((*token ==
'1' || *token ==
'A' || *token ==
'a')
178 && *(token+1) ==
':') {
182 else if ((*token ==
'0' || *token ==
'R' || *token ==
'r')
183 && *(token+1) ==
':') {
190 if (rfilter_add(rf,token,pol,NULL))
201 static inline struct rfilter *rfilter_create_simple(
int defaccept,
206 rf = rfilter_create(defaccept);
208 if (rfilter_add(rf,rstr,0,NULL)) {
214 while ((rstr = va_arg(ap,
char *))) {
215 if (rfilter_add(rf,va_arg(ap,
char *),0,NULL))
static uint64_t unsigned int i
#define verror(format,...)
#define vdebug(devel, areas, flags, format,...)
void * malloc(size_t size)