From: Adam Dickmeiss Date: Tue, 2 Jul 2013 08:35:27 +0000 (+0200) Subject: Merge branch 'master' of ssh://git.indexdata.com/home/git/pub/yaz X-Git-Tag: v4.2.62~7 X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=commitdiff_plain;h=32714ab839d402d1e6194316d5909b2ce37e3ee3;hp=cdd67ab5b29250ce4c16dcaaecb62654346502c1 Merge branch 'master' of ssh://git.indexdata.com/home/git/pub/yaz --- diff --git a/doc/yaz-url-man.xml b/doc/yaz-url-man.xml index 65cd4ef..c98c467 100644 --- a/doc/yaz-url-man.xml +++ b/doc/yaz-url-man.xml @@ -33,6 +33,7 @@ -m method -O fname -p fname + -R num -u user/password -x proxy url @@ -87,6 +88,14 @@ + -R num + + Sets maximum number of HTTP redirects to be followed. + A value of zero disables follow of HTTP redirects. + + + + -u user/password Specifies a user and a password to be uesd in HTTP diff --git a/include/yaz/url.h b/include/yaz/url.h index aa5fd4d..0deb4db 100644 --- a/include/yaz/url.h +++ b/include/yaz/url.h @@ -60,6 +60,12 @@ YAZ_EXPORT void yaz_url_destroy(yaz_url_t p); */ YAZ_EXPORT void yaz_url_set_proxy(yaz_url_t p, const char *proxy); +/** \brief sets maximum number of redirects + \param p handle + \param num maximum number of redirects +*/ +YAZ_EXPORT void yaz_url_set_max_redirects(yaz_url_t p, int num); + /** \brief executes the actual HTTP request (including redirects, etc) \param p handle \param uri URL diff --git a/src/url.c b/src/url.c index 97e8247..ff7ff81 100644 --- a/src/url.c +++ b/src/url.c @@ -18,6 +18,7 @@ struct yaz_url { ODR odr_in; ODR odr_out; char *proxy; + int max_redirects; }; yaz_url_t yaz_url_create(void) @@ -26,6 +27,7 @@ yaz_url_t yaz_url_create(void) p->odr_in = odr_createmem(ODR_DECODE); p->odr_out = odr_createmem(ODR_ENCODE); p->proxy = 0; + p->max_redirects = 10; return p; } @@ -48,6 +50,11 @@ void yaz_url_set_proxy(yaz_url_t p, const char *proxy) p->proxy = xstrdup(proxy); } +void yaz_url_set_max_redirects(yaz_url_t p, int num) +{ + p->max_redirects = num; +} + static void extract_user_pass(NMEM nmem, const char *uri, char **uri_lean, char **http_user, @@ -189,7 +196,7 @@ Z_HTTP_Response *yaz_url_exec(yaz_url_t p, const char *uri, break; code = res->code; location = z_HTTP_header_lookup(res->headers, "Location"); - if (++number_of_redirects < 10 && + if (++number_of_redirects <= p->max_redirects && location && (code == 301 || code == 302 || code == 307)) { odr_reset(p->odr_out); diff --git a/util/yaz-url.c b/util/yaz-url.c index 498e2f8..54551dd 100644 --- a/util/yaz-url.c +++ b/util/yaz-url.c @@ -21,6 +21,7 @@ static void usage(void) printf(" -m method Sets HTTP method\n"); printf(" -O fname Writes HTTP content to file\n"); printf(" -p fname POSTs file at following url\n"); + printf(" -R num Set maximum number of HTTP redirects\n"); printf(" -u user/password Sets Basic HTTP auth\n"); printf(" -x proxy Sets HTTP proxy\n"); exit(1); @@ -72,7 +73,7 @@ int main(int argc, char **argv) int no_urls = 0; const char *outfname = 0; - while ((ret = options("hH:m:O:p:u:x:", argv, argc, &arg)) + while ((ret = options("h{help}H:m:O:p:R{max-redirs}:u:x:", argv, argc, &arg)) != YAZ_OPTIONS_EOF) { switch (ret) @@ -109,6 +110,9 @@ int main(int argc, char **argv) post_buf = get_file(arg, &post_len); method = "POST"; break; + case 'R': + yaz_url_set_max_redirects(p, atoi(arg)); + break; case 'u': if (strchr(arg, '/')) {