static GlobCode glob_word(URLGlob *glob, char *pattern, size_t pos, int *amount) { /* processes a literal string component of a URL special characters '{' and '[' branch to set/range processing functions */ char* buf = glob->glob_buffer; size_t litindex; GlobCode res = GLOB_OK; *amount = 1; /* default is one single string */ while(*pattern != '\0' && *pattern != '{' && *pattern != '[') { if(*pattern == '}' || *pattern == ']') { snprintf(glob->errormsg, sizeof(glob->errormsg), "unmatched close brace/bracket at pos %zu\n", pos); return GLOB_ERROR; } /* only allow \ to escape known "special letters" */ if(*pattern == '\\' && (*(pattern+1) == '{' || *(pattern+1) == '[' || *(pattern+1) == '}' || *(pattern+1) == ']') ) { /* escape character, skip '\' */ ++pattern; ++pos; } *buf++ = *pattern++; /* copy character to literal */ ++pos; } *buf = '\0'; litindex = glob->size / 2; /* literals 0,1,2,... correspond to size=0,2,4,... */ glob->literal[litindex] = strdup(glob->glob_buffer); if(!glob->literal[litindex]) return GLOB_ERROR; ++glob->size; switch (*pattern) { case '\0': break; /* singular URL processed */ case '{': /* process set pattern */ res = glob_set(glob, ++pattern, ++pos, amount); break; case '[': /* process range pattern */ res= glob_range(glob, ++pattern, ++pos, amount); break; } if(GLOB_OK != res) /* free that strdup'ed string again */ Curl_safefree(glob->literal[litindex]); return res; /* something got wrong */ }
static CURLcode glob_parse(URLGlob *glob, char *pattern, size_t pos, unsigned long *amount) { /* processes a literal string component of a URL special characters '{' and '[' branch to set/range processing functions */ CURLcode res = CURLE_OK; int globindex = 0; /* count "actual" globs */ *amount = 1; while(*pattern && !res) { char *buf = glob->glob_buffer; size_t sublen = 0; while(*pattern && *pattern != '{') { if(*pattern == '[') { /* Skip over potential IPv6 literals. */ size_t skip; if(peek_ipv6(pattern, &skip)) { memcpy(buf, pattern, skip); buf += skip; pattern += skip; sublen += skip; continue; } break; } if(*pattern == '}' || *pattern == ']') return GLOBERROR("unmatched close brace/bracket", pos, CURLE_URL_MALFORMAT); /* only allow \ to escape known "special letters" */ if(*pattern == '\\' && (*(pattern+1) == '{' || *(pattern+1) == '[' || *(pattern+1) == '}' || *(pattern+1) == ']') ) { /* escape character, skip '\' */ ++pattern; ++pos; } *buf++ = *pattern++; /* copy character to literal */ ++pos; sublen++; } if(sublen) { /* we got a literal string, add it as a single-item list */ *buf = '\0'; res = glob_fixed(glob, glob->glob_buffer, sublen); } else { switch (*pattern) { case '\0': /* done */ break; case '{': /* process set pattern */ pattern++; pos++; res = glob_set(glob, &pattern, &pos, amount, globindex++); break; case '[': /* process range pattern */ pattern++; pos++; res = glob_range(glob, &pattern, &pos, amount, globindex++); break; } } if(++glob->size > GLOB_PATTERN_NUM) return GLOBERROR("too many globs", pos, CURLE_URL_MALFORMAT); } return res; }
static GlobCode glob_parse(URLGlob *glob, char *pattern, size_t pos, unsigned long *amount) { /* processes a literal string component of a URL special characters '{' and '[' branch to set/range processing functions */ char* buf = glob->glob_buffer; GlobCode res = GLOB_OK; int globindex = 0; /* count "actual" globs */ while(*pattern && !res) { int sublen = 0; while(*pattern && *pattern != '{' && *pattern != '[') { if(*pattern == '}' || *pattern == ']') return GLOBERROR("unmatched close brace/bracket", pos, GLOB_ERROR); /* only allow \ to escape known "special letters" */ if(*pattern == '\\' && (*(pattern+1) == '{' || *(pattern+1) == '[' || *(pattern+1) == '}' || *(pattern+1) == ']') ) { /* escape character, skip '\' */ ++pattern; ++pos; } *buf++ = *pattern++; /* copy character to literal */ ++pos; sublen++; } if(sublen) { /* we got a literal string, add it as a single-item list */ *buf = '\0'; res = glob_fixed(glob, amount); } else { if(!*amount) *amount = 1; switch (*pattern) { case '\0': /* done */ break; case '{': /* process set pattern */ pattern++; pos++; res = glob_set(glob, &pattern, &pos, amount, globindex++); break; case '[': /* process range pattern */ pattern++; pos++; res = glob_range(glob, &pattern, &pos, amount, globindex++); break; } } if(++glob->size > GLOB_PATTERN_NUM) return GLOBERROR("too many globs", pos, GLOB_ERROR); } return res; }