diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2015-01-22 00:44:27 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2015-01-22 00:44:27 +0200 |
commit | 0c7bb2d5cb81eb6077a8907ce2049278fb8e47ce (patch) | |
tree | 7392dad30ac09b3ff32bfb2882710b5117fdde35 /src/ispeek.c | |
parent | 03c5b9aac73c6a70b1c67f467bbd484d2a532f10 (diff) | |
download | eclat-0c7bb2d5cb81eb6077a8907ce2049278fb8e47ce.tar.gz eclat-0c7bb2d5cb81eb6077a8907ce2049278fb8e47ce.tar.bz2 |
authentication-provider instance-store does not require role name argument
* NEWS: Update.
* doc/eclat.conf.5: Update.
* lib/Makefile.am: Add new sources.
* lib/istore.c: New file.
* lib/path.c: New file.
* lib/libeclat.h (path_concat)
(instance_store_curl_new)
(instance_store_read): New protos.
* src/config.c (cb_authentication_provider): second argument is
optional for instance-store type.
New compound statement: instance-store.
* src/eclat.h (instance_store_base_url)
(instance_store_port,instance_store_document_path):
(instance_store_credentials_path): New externs.
* src/ispeek.c: Rewrite using new functions.
* src/util.c: Likewise.
Diffstat (limited to 'src/ispeek.c')
-rw-r--r-- | src/ispeek.c | 92 |
1 files changed, 15 insertions, 77 deletions
diff --git a/src/ispeek.c b/src/ispeek.c index 95e1a4c..2c518cb 100644 --- a/src/ispeek.c +++ b/src/ispeek.c @@ -40,81 +40,26 @@ char *delim = ":"; int recursive; long port; -static char * -make_url(const char *url, const char *path) -{ - char *p; - size_t len = strlen(url); - - while (len > 0 && url[len-1] == '/') - --len; - - while (*path == '/') - ++path; - - p = grecs_malloc(len + strlen(path) + 2); - memcpy(p, url, len); - p[len++] = '/'; - strcpy(p + len, path); - return p; -} - -static size_t -acc_cb(void *ptr, size_t size, size_t nmemb, void *data) -{ - size_t realsize = size * nmemb; - struct grecs_txtacc *acc = data; - - grecs_txtacc_grow(acc, ptr, realsize); - - return realsize; -} +struct closure { + char *text; + CURL *curl; + struct grecs_txtacc *acc; + char **argv; +}; static char * read_from(const char *path, CURL *curl, struct grecs_txtacc *acc) { - CURLcode res; - long http_resp; - char *text; char *url; - - url = make_url(base_url, path); - curl_easy_setopt(curl, CURLOPT_URL, url); - - res = curl_easy_perform(curl); - if (res != CURLE_OK) - die(EX_UNAVAILABLE, "CURL: %s", curl_easy_strerror(res)); - - res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_resp); - if (res != CURLE_OK) - die(EX_UNAVAILABLE, "CURL: %s", curl_easy_strerror(res)); - - grecs_txtacc_grow_char(acc, 0); - text = grecs_txtacc_finish(acc, 0); - switch (http_resp) { - case 200: - break; + url = path_concat(base_url, path); - case 404: - grecs_txtacc_free_string(acc, text); + if (instance_store_read(url, curl)) return NULL; - - default: - die(EX_UNAVAILABLE, "CURL: got response %3d, url %s", - http_resp, url); - } - free(url); - return text; + grecs_txtacc_grow_char(acc, 0); + return grecs_txtacc_finish(acc, 0); } -struct closure { - char *text; - CURL *curl; - struct grecs_txtacc *acc; - char **argv; -}; - static void print_dir(const char *path, struct closure *cl); static void @@ -149,11 +94,11 @@ print_dir(const char *path, struct closure *cl) printf("%s%s\n", path, ws.ws_wordv[i]); if (recursive) { if (isroot) { - char *p = make_url(path, ws.ws_wordv[i]); - url = make_url(p, "/"); + char *p = path_concat(path, ws.ws_wordv[i]); + url = path_concat(p, "/"); free(p); } else if (ws.ws_wordv[i][strlen(ws.ws_wordv[i]) - 1] == '/') { - url = make_url(path, ws.ws_wordv[i]); + url = path_concat(path, ws.ws_wordv[i]); } else continue; list(url, cl); @@ -245,18 +190,11 @@ ispeek_do(char **argv) const char *path = *argv++; char *text; - curl = curl_easy_init(); - if (!curl) - die(EX_UNAVAILABLE, "curl_easy_init failed"); + acc = grecs_txtacc_create(); + curl = instance_store_curl_new(acc); if (port) curl_easy_setopt(curl, CURLOPT_PORT, (long) port); - curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); eclat_set_curl_trace(curl, debug_level(0)); - - acc = grecs_txtacc_create(); - - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, acc_cb); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, acc); text = read_from(path, curl, acc); if (text) { |