version 1.37, 2017/03/10 04:24:55 |
version 1.38, 2018/07/04 13:49:31 |
|
|
} |
} |
|
|
/* |
/* |
* Filters a comma-separated list of strings, excluding any entry matching |
* Filter proposal using pattern-list filter. |
* the 'filter' pattern list. Caller must free returned string. |
* "blacklist" determines sense of filter: |
|
* non-zero indicates that items matching filter should be excluded. |
|
* zero indicates that only items matching filter should be included. |
|
* returns NULL on allocation error, otherwise caller must free result. |
*/ |
*/ |
char * |
static char * |
match_filter_list(const char *proposal, const char *filter) |
filter_list(const char *proposal, const char *filter, int blacklist) |
{ |
{ |
size_t len = strlen(proposal) + 1; |
size_t len = strlen(proposal) + 1; |
char *fix_prop = malloc(len); |
char *fix_prop = malloc(len); |
char *orig_prop = strdup(proposal); |
char *orig_prop = strdup(proposal); |
char *cp, *tmp; |
char *cp, *tmp; |
|
int r; |
|
|
if (fix_prop == NULL || orig_prop == NULL) { |
if (fix_prop == NULL || orig_prop == NULL) { |
free(orig_prop); |
free(orig_prop); |
|
|
tmp = orig_prop; |
tmp = orig_prop; |
*fix_prop = '\0'; |
*fix_prop = '\0'; |
while ((cp = strsep(&tmp, ",")) != NULL) { |
while ((cp = strsep(&tmp, ",")) != NULL) { |
if (match_pattern_list(cp, filter, 0) != 1) { |
r = match_pattern_list(cp, filter, 0); |
|
if ((blacklist && r != 1) || (!blacklist && r == 1)) { |
if (*fix_prop != '\0') |
if (*fix_prop != '\0') |
strlcat(fix_prop, ",", len); |
strlcat(fix_prop, ",", len); |
strlcat(fix_prop, cp, len); |
strlcat(fix_prop, cp, len); |
|
|
return fix_prop; |
return fix_prop; |
} |
} |
|
|
|
/* |
|
* Filters a comma-separated list of strings, excluding any entry matching |
|
* the 'filter' pattern list. Caller must free returned string. |
|
*/ |
|
char * |
|
match_filter_blacklist(const char *proposal, const char *filter) |
|
{ |
|
return filter_list(proposal, filter, 1); |
|
} |
|
|
|
/* |
|
* Filters a comma-separated list of strings, including only entries matching |
|
* the 'filter' pattern list. Caller must free returned string. |
|
*/ |
|
char * |
|
match_filter_whitelist(const char *proposal, const char *filter) |
|
{ |
|
return filter_list(proposal, filter, 0); |
|
} |