idnode: added regexp filtering
This commit is contained in:
parent
1ed3627e77
commit
7037697cca
2 changed files with 19 additions and 4 deletions
20
src/idnode.c
20
src/idnode.c
|
@ -502,7 +502,9 @@ idnode_filter
|
|||
return 1;
|
||||
break;
|
||||
case IC_RE:
|
||||
break; // TODO: not yet supported
|
||||
if (regexec(&f->u.re, str, 0, NULL, 0))
|
||||
return 1;
|
||||
break;
|
||||
}
|
||||
} else if (f->type == IF_NUM || f->type == IF_BOOL) {
|
||||
uint32_t u32;
|
||||
|
@ -542,7 +544,13 @@ idnode_filter_add_str
|
|||
ele->key = strdup(key);
|
||||
ele->type = IF_STR;
|
||||
ele->comp = comp;
|
||||
ele->u.s = strdup(val);
|
||||
if (comp == IC_RE) {
|
||||
if (regcomp(&ele->u.re, val, REG_ICASE | REG_EXTENDED | REG_NOSUB)) {
|
||||
free(ele);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
ele->u.s = strdup(val);
|
||||
LIST_INSERT_HEAD(filt, ele, link);
|
||||
}
|
||||
|
||||
|
@ -577,8 +585,12 @@ idnode_filter_clear
|
|||
idnode_filter_ele_t *ele;
|
||||
while ((ele = LIST_FIRST(filt))) {
|
||||
LIST_REMOVE(ele, link);
|
||||
if (ele->type == IF_STR)
|
||||
free(ele->u.s);
|
||||
if (ele->type == IF_STR) {
|
||||
if (ele->comp == IC_RE)
|
||||
regfree(&ele->u.re);
|
||||
else
|
||||
free(ele->u.s);
|
||||
}
|
||||
free(ele);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include "tvheadend.h"
|
||||
#include "prop.h"
|
||||
|
||||
#include <regex.h>
|
||||
|
||||
struct htsmsg;
|
||||
struct idnode;
|
||||
|
||||
|
@ -46,6 +48,7 @@ typedef struct idnode_filter_ele
|
|||
int b;
|
||||
char *s;
|
||||
int64_t n;
|
||||
regex_t re;
|
||||
} u;
|
||||
enum {
|
||||
IC_EQ, // Equals
|
||||
|
|
Loading…
Add table
Reference in a new issue