1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2011 Index Data
3 * See the file LICENSE for details.
14 #include <yaz/options.h>
17 static void usage(void)
19 printf("yaz-icu [options] url ..\n");
20 printf(" -H name=value HTTP header\n");
21 printf(" -p file POST content of file\n");
22 printf(" -u user/password Basic HTTP auth\n");
23 printf(" -x proxy HTTP proxy\n");
27 static char *get_file(const char *fname, size_t *len)
30 FILE *inf = fopen(fname, "rb");
33 yaz_log(YLOG_FATAL|YLOG_ERRNO, "Could not open %s", fname);
36 if (fseek(inf, 0L, SEEK_END))
38 yaz_log(YLOG_FATAL|YLOG_ERRNO, "fseek of %s failed", fname);
43 fseek(inf, 0L, SEEK_SET);
44 fread(buf, 1, *len, inf);
49 int main(int argc, char **argv)
53 yaz_url_t p = yaz_url_create();
56 const char *method = "GET";
57 Z_HTTP_Response *http_response;
58 Z_HTTP_Header *http_headers = 0;
59 ODR odr = odr_createmem(ODR_ENCODE);
63 while ((ret = options("hH:p:u:x:", argv, argc, &arg))
72 if (!strchr(arg, '='))
74 yaz_log(YLOG_FATAL, "bad header option (missing =): %s\n", arg);
79 char *cp = strchr(arg, '=');
80 char *name = odr_malloc(odr, 1 + cp - arg);
82 memcpy(name, arg, cp - arg);
83 name[cp - arg] = '\0';
84 z_HTTP_header_add(odr, &http_headers, name, value);
89 post_buf = get_file(arg, &post_len);
95 char *cp = strchr(arg, '/');
96 char *user = odr_malloc(odr, 1 + cp - arg);
97 char *password = cp + 1;
98 memcpy(user, arg, cp - arg);
99 user[cp - arg] = '\0';
100 z_HTTP_header_add_basic_auth(odr, &http_headers, user,
104 z_HTTP_header_add_basic_auth(odr, &http_headers, arg, 0);
107 yaz_url_set_proxy(p, arg);
110 http_response = yaz_url_exec(p, arg, method, http_headers,
116 fwrite(http_response->content_buf, 1,
117 http_response->content_len, stdout);
135 * c-file-style: "Stroustrup"
136 * indent-tabs-mode: nil
138 * vim: shiftwidth=4 tabstop=8 expandtab