X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=util%2Fyaz-url.c;h=5e6bbe916d3882832e8c5f7ee33b016fa83dc1d6;hp=56f152b4cc6a50aac40e519f0fa1d1c35baec3b8;hb=473824797f568578dc17d7242551cb2f7ccef46c;hpb=6d8c5abbb0477835de7e1fcca7915b2f952c3c9f diff --git a/util/yaz-url.c b/util/yaz-url.c index 56f152b..5e6bbe9 100644 --- a/util/yaz-url.c +++ b/util/yaz-url.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2012 Index Data + * Copyright (C) Index Data * See the file LICENSE for details. */ @@ -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); @@ -43,9 +44,15 @@ static char *get_file(const char *fname, size_t *len) *len = ftell(inf); if (*len) /* zero length not considered an error */ { + size_t r; buf = xmalloc(*len); fseek(inf, 0L, SEEK_SET); - (void) fread(buf, 1, *len, inf); + r = fread(buf, 1, *len, inf); + if (r != *len) + { + yaz_log(YLOG_FATAL|YLOG_ERRNO, "short fread of %s", fname); + exit(1); + } } fclose(inf); return buf; @@ -66,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) @@ -103,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, '/')) {