static char * url_next(struct url_iter *it) { char *url; if (!it->uglob) { for (;;) { if (!*it->upats) return 0; if (!glob_url(&it->uglob, *it->upats, &it->nglob, stderr)) { if (verbose) fprintf(stderr, "# %s\n", *it->upats); break; } it->upats++; } } if (glob_next_url(&url, it->uglob)) abort(); if (--it->nglob == 0) { glob_cleanup(it->uglob); it->uglob = 0; it->upats++; } return url; }
CURLcode glob_url(URLGlob **glob, char *url, unsigned long *urlnum, FILE *error) { /* * We can deal with any-size, just make a buffer with the same length * as the specified URL! */ URLGlob *glob_expand; unsigned long amount = 0; char *glob_buffer; CURLcode res; *glob = NULL; glob_buffer = malloc(strlen(url) + 1); if(!glob_buffer) return CURLE_OUT_OF_MEMORY; glob_buffer[0] = 0; glob_expand = calloc(1, sizeof(URLGlob)); if(!glob_expand) { Curl_safefree(glob_buffer); return CURLE_OUT_OF_MEMORY; } glob_expand->urllen = strlen(url); glob_expand->glob_buffer = glob_buffer; res = glob_parse(glob_expand, url, 1, &amount); if(!res) *urlnum = amount; else { if(error && glob_expand->error) { char text[512]; const char *t; if(glob_expand->pos) { msnprintf(text, sizeof(text), "%s in URL position %zu:\n%s\n%*s^", glob_expand->error, glob_expand->pos, url, glob_expand->pos - 1, " "); t = text; } else t = glob_expand->error; /* send error description to the error-stream */ fprintf(error, "curl: (%d) %s\n", res, t); } /* it failed, we cleanup */ glob_cleanup(glob_expand); *urlnum = 1; return res; } *glob = glob_expand; return CURLE_OK; }