104 char **uri_lean,
char **http_user,
107 const char *cp1 = strchr(uri,
'/');
111 if (cp1 && cp1 > uri)
115 if (!strncmp(cp1,
"://", 3))
118 const char *cp2 = cp1 + 3;
119 while (*cp2 && *cp2 !=
'/' && *cp2 !=
'@')
125 if (*cp2 ==
'@' && cp3)
128 memcpy(*uri_lean, uri, cp1 + 3 - uri);
129 strcpy(*uri_lean + (cp1 + 3 - uri), cp2 + 1);
131 *http_user =
nmem_strdupn(nmem, cp1 + 3, cp3 - (cp1 + 3));
132 *http_pass =
nmem_strdupn(nmem, cp3 + 1, cp2 - (cp3 + 1));
162 const char *buf,
size_t len)
165 int number_of_redirects = 0;
175 const char *location = 0;
186 &http_user, &http_pass);
199 for ( ; user_headers; user_headers = user_headers->
next)
202 if (!strcmp(user_headers->
name,
"Host"))
205 else if (!strcmp(user_headers->
name,
"User-Agent"))
207 user_headers->
name, user_headers->
value);
210 user_headers->
name, user_headers->
value);
212 if (http_user && http_pass)
214 &gdu->
u.HTTP_Request->headers,
215 http_user, http_pass);
218 gdu->
u.HTTP_Request->content_buf = (
char *) buf;
219 gdu->
u.HTTP_Request->content_len = len;
241 fwrite(buf_out, 1, len_out, stdout);
242 if (!strcmp(gdu->
u.HTTP_Request->method,
"HEAD"))
286 ret =
cs_put(conn, buf_out, len_out);
301 ret =
cs_get(conn, &netbuffer, &netlen);
307 "cs_get failed for URL %s", uri);
312 "Connection closed while reading"
321 fwrite(netbuffer, 1, ret, stdout);
332 res = gdu->
u.HTTP_Response;
345 if (++number_of_redirects <= p->max_redirects &&
346 location && (code == 301 || code == 302 || code == 307))
350 location, &host_change);
int cs_get_error(COMSTACK cs, const char **details)
Returns the last COMSTACK error and optional transport details.
COMSTACK cs_create_host2(const char *vhost, int flags, void **vp, const char *proxy_host, int *proxy_mode)
Creates an endpoint and selects direct or proxy connection handling.
const char * cs_errmsg(int n)
Returns a static message for a COMSTACK error code.
int cs_set_head_only(COMSTACK cs, int head_only)
Selects HTTP header-only framing for TCP/IP, SSL or UNIX transports.
Transport-independent communication endpoints for BER and HTTP.
#define cs_close(handle)
Closes the socket and frees the endpoint and its transport state.
#define cs_connect(handle, address)
Starts an outgoing connection.
#define cs_put(handle, buf, size)
Sends a complete message.
#define cs_get(handle, buf, size)
Receives a BER or HTTP message.
#define CS_FLAGS_CHECK_CERT
#define cs_fileno(handle)
Returns the socket descriptor, or -1 if none has been created.
struct comstack * COMSTACK
Communication endpoint; release with cs_close.
#define cs_rcvconnect(handle)
Continues a pending outgoing connection, including TLS or CONNECT.
void yaz_cookies_reset(yaz_cookies_t yc)
void yaz_cookies_destroy(yaz_cookies_t yc)
yaz_cookies_t yaz_cookies_create(void)
void yaz_cookies_request(yaz_cookies_t yc, ODR odr, Z_HTTP_Request *req)
void yaz_cookies_response(yaz_cookies_t yc, Z_HTTP_Response *res)
struct yaz_cookies_s * yaz_cookies_t
void z_HTTP_header_add_basic_auth(ODR o, Z_HTTP_Header **hp, const char *username, const char *password)
void z_HTTP_header_set(ODR o, Z_HTTP_Header **hp, const char *n, const char *v)
const char * yaz_check_location(ODR odr, const char *uri, const char *location, int *host_change)
const char * z_HTTP_header_lookup(const Z_HTTP_Header *hp, const char *n)
Z_GDU * z_get_HTTP_Request_uri(ODR odr, const char *uri, const char *args, int use_full_uri)
void z_HTTP_header_add(ODR o, Z_HTTP_Header **hp, const char *n, const char *v)
void yaz_log(int level, const char *fmt,...)
Writes log message.
#define YLOG_WARN
log level: warning
void * nmem_malloc(NMEM n, size_t size)
allocates memory block on NMEM handle
struct nmem_control * NMEM
NMEM handle (an opaque pointer to memory).
char * nmem_strdup(NMEM mem, const char *src)
allocates string on NMEM handle (similar strdup)
char * nmem_strdupn(NMEM mem, const char *src, size_t n)
allocates string of certain size on NMEM handle
char * odr_getbuf(ODR o, int *len, int *size)
ODR odr_createmem(int direction)
void odr_setbuf(ODR o, char *buf, int len, int can_grow)
char * odr_strdup(ODR o, const char *str)
int yaz_poll(struct yaz_poll_fd *fds, int num_fds, int sec, int nsec)
poll wrapper for poll or select
#define yaz_poll_add(var, value)
yaz_poll_mask
select/poll masks .. timeout is "output" only
union Z_GDU::@057307356220171136236350364324260103365227025100 u
enum yaz_poll_mask input_mask
int cs_set_ssl_certificate_file(COMSTACK cs, const char *fname)
Selects certificate and private key files for a TLS endpoint.
void yaz_url_set_timeout(yaz_url_t p, int sec, int ns)
sets I/O timeout
yaz_url_t yaz_url_create(void)
creates a URL fetcher handle
void yaz_url_set_cert_fname(yaz_url_t p, const char *fname)
sets file with client-side certificate
static void extract_user_pass(NMEM nmem, const char *uri, char **uri_lean, char **http_user, char **http_pass)
Z_HTTP_Response * yaz_url_exec(yaz_url_t p, const char *uri, const char *method, Z_HTTP_Header *user_headers, const char *buf, size_t len)
executes the actual HTTP request (including redirects, etc)
static void log_warn(yaz_url_t p)
void yaz_url_set_max_redirects(yaz_url_t p, int num)
sets maximum number of redirects
void yaz_url_destroy(yaz_url_t p)
destroys a URL fetcher
void yaz_url_set_proxy(yaz_url_t p, const char *proxy)
sets proxy for URL fetcher
const char * yaz_url_get_error(yaz_url_t p)
get last error from yaz_url_exec
static void add_comstack_details(yaz_url_t p, COMSTACK conn)
void yaz_url_set_check_cert(yaz_url_t p, int check_cert)
sets whether to check SSL certificates
void yaz_url_set_verbose(yaz_url_t p, int num)
sets verbose level 0=none, >0 verbose
struct yaz_url * yaz_url_t
handle for our URL fetcher
void wrbuf_destroy(WRBUF b)
destroy WRBUF and its buffer
const char * wrbuf_cstr(WRBUF b)
returns WRBUF content as C-string
void wrbuf_rewind(WRBUF b)
empty WRBUF content (length of buffer set to 0)
WRBUF wrbuf_alloc(void)
construct WRBUF
void wrbuf_printf(WRBUF b, const char *fmt,...)
writes printf result to WRBUF
Header for WRBUF (growing buffer).
#define xstrdup(s)
utility macro which calls xstrdup_f
#define xfree(x)
utility macro which calls xfree_f
#define xmalloc(x)
utility macro which calls malloc_f
#define Z_GDU_HTTP_Response
int z_GDU(ODR o, Z_GDU **p, int opt, const char *name)