X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Flib%2Flistparser.hc;h=bc35153122fa06c59f8604762d51f79d83caadf5;hb=0c1e4aa88cd3f5b075014eac88241fe3a7459029;hp=4c5769af611b6c67853ec79b03fb71db6ac97910;hpb=9215c73e89c692ee2ce9abafe644d1a5b144e320;p=util-vserver.git diff --git a/util-vserver/lib/listparser.hc b/util-vserver/lib/listparser.hc index 4c5769a..bc35153 100644 --- a/util-vserver/lib/listparser.hc +++ b/util-vserver/lib/listparser.hc @@ -27,13 +27,18 @@ #define TONUMBER_uint64(S,E,B) strtoll(S,E,B) #define TONUMBER_uint32(S,E,B) strtol (S,E,B) -#define ISNUMBER(TYPE,SHORT) \ - static inline ALWAYSINLINE bool \ - isNumber_##SHORT(char const *str,TYPE *res, char end_chr) \ - { \ - char *err_ptr; \ - *res = TONUMBER_##SHORT(str, &err_ptr, 0); \ - return err_ptr>str && *err_ptr==end_chr; \ +#define ISNUMBER(TYPE,SHORT) \ + static inline ALWAYSINLINE bool \ + isNumber_##SHORT(char const **str,size_t *len,TYPE *res,char end_chr) \ + { \ + char *err_ptr; \ + if (**str=='^') { \ + *res = ((TYPE)(1)) << TONUMBER_##SHORT(++*str, &err_ptr, 0); \ + if (len) --*len; \ + } \ + else \ + *res = TONUMBER_##SHORT(*str, &err_ptr, 0); \ + return err_ptr>*str && *err_ptr==end_chr; \ } @@ -51,11 +56,12 @@ for (;len>0;) { \ char const *ptr = strchr(str, ','); \ size_t cnt; \ - TYPE tmp; \ - bool is_neg; \ - \ - is_neg = *str=='!' || *str=='~'; \ - if (is_neg) { \ + TYPE tmp = 0; \ + bool is_neg = false; \ + bool allow_zero = true; \ + \ + while (len>0 && (*str=='!' || *str=='~')) { \ + is_neg = !is_neg; \ ++str; \ --len; \ } \ @@ -64,15 +70,18 @@ if (cnt>=len) { cnt=len; len=0; } \ else len-=(cnt+1); \ \ - if (cnt==0) \ - tmp = 0; \ + if (cnt==0) \ + allow_zero = false; \ else if (strncasecmp(str,"all",cnt)==0 || \ strncasecmp(str,"any",cnt)==0) \ tmp = ~(TYPE)(0); \ - else if (!isNumber_##SHORT(str, &tmp, str[cnt])) \ - tmp = (*func)(str,cnt); \ + else if (strncasecmp(str,"none",cnt)==0) {} \ + else if (!isNumber_##SHORT(&str, &cnt, &tmp, str[cnt])) { \ + tmp = (*func)(str,cnt); \ + allow_zero = false; \ + } \ \ - if (tmp!=0) { \ + if (tmp!=0 || allow_zero) { \ if (!is_neg) *flag |= tmp; \ else *flag &= ~tmp; \ *mask |= tmp; \