YAZ  5.23.1
Data Structures | Functions
url.c File Reference

URL fetch utility. More...

#include <yaz/url.h>
#include <yaz/comstack.h>
#include <yaz/log.h>
#include <yaz/wrbuf.h>
#include <yaz/cookie.h>
#include <yaz/poll.h>

Go to the source code of this file.

Data Structures

struct  yaz_url
 

Functions

yaz_url_t yaz_url_create (void)
 creates a URL fetcher handle More...
 
void yaz_url_destroy (yaz_url_t p)
 destroys a URL fetcher More...
 
void yaz_url_set_proxy (yaz_url_t p, const char *proxy)
 sets proxy for URL fetcher More...
 
void yaz_url_set_max_redirects (yaz_url_t p, int num)
 sets maximum number of redirects More...
 
void yaz_url_set_verbose (yaz_url_t p, int num)
 sets verbose level 0=none, >0 verbose More...
 
void yaz_url_set_timeout (yaz_url_t p, int sec, int ns)
 sets I/O timeout More...
 
static void extract_user_pass (NMEM nmem, const char *uri, char **uri_lean, char **http_user, char **http_pass)
 
const char * yaz_url_get_error (yaz_url_t p)
 get last error from yaz_url_exec More...
 
static void log_warn (yaz_url_t p)
 
Z_HTTP_Responseyaz_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) More...
 

Detailed Description

URL fetch utility.

Definition in file url.c.

Function Documentation

static void extract_user_pass ( NMEM  nmem,
const char *  uri,
char **  uri_lean,
char **  http_user,
char **  http_pass 
)
static

Definition at line 84 of file url.c.

References nmem_malloc(), nmem_strdup(), and nmem_strdupn().

Referenced by yaz_url_exec().

static void log_warn ( yaz_url_t  p)
static

Definition at line 127 of file url.c.

References yaz_url::w_error, wrbuf_cstr(), yaz_log(), and YLOG_WARN.

Referenced by yaz_url_exec().

yaz_url_t yaz_url_create ( void  )
void yaz_url_destroy ( yaz_url_t  p)

destroys a URL fetcher

Parameters
phandle

Note: OK to pass NULL as p

Definition at line 47 of file url.c.

References yaz_url::cookies, odr_destroy(), yaz_url::odr_in, yaz_url::odr_out, yaz_url::proxy, yaz_url::w_error, wrbuf_destroy(), xfree, and yaz_cookies_destroy().

Referenced by rdf_lookup_node().

Z_HTTP_Response* yaz_url_exec ( yaz_url_t  p,
const char *  uri,
const char *  method,
Z_HTTP_Header headers,
const char *  buf,
size_t  len 
)

executes the actual HTTP request (including redirects, etc)

Parameters
phandle
uriURL
methodHTTP method
headersHTTP headers to be used (NULL for no custom headers)
bufcontent buffer for HTTP request, NULL for empty content
lencontent length for HTTP request
Returns
HTTP response; NULL on ERROR.

Use yaz_url_get_error to get details if NULL is returned.

Definition at line 132 of file url.c.

References Z_HTTP_Response::code, Z_HTTP_Request::content_buf, Z_HTTP_Request::content_len, yaz_url::cookies, cs_close, cs_connect, cs_create_host2(), cs_fileno, cs_get, cs_put, cs_rcvconnect, cs_set_head_only(), CS_WANT_READ, CS_WANT_WRITE, extract_user_pass(), yaz_poll_fd::fd, Z_HTTP_Request::headers, Z_HTTP_Response::headers, Z_GDU::HTTP_Request, Z_GDU::HTTP_Response, yaz_poll_fd::input_mask, comstack::io_pending, log_warn(), yaz_url::max_redirects, odr::mem, Z_HTTP_Request::method, Z_HTTP_Header::name, Z_HTTP_Header::next, odr_getbuf(), yaz_url::odr_in, yaz_url::odr_out, odr_reset(), odr_setbuf(), odr_strdup(), yaz_url::proxy, yaz_url::timeout_ns, yaz_url::timeout_sec, Z_GDU::u, Z_HTTP_Header::value, yaz_url::verbose, yaz_url::w_error, Z_GDU::which, wrbuf_printf(), wrbuf_rewind(), xfree, yaz_check_location(), yaz_cookies_request(), yaz_cookies_reset(), yaz_cookies_response(), yaz_poll(), yaz_poll_add, yaz_poll_except, yaz_poll_none, yaz_poll_read, yaz_poll_write, z_GDU(), Z_GDU_HTTP_Response, z_get_HTTP_Request_uri(), z_HTTP_header_add(), z_HTTP_header_add_basic_auth(), z_HTTP_header_lookup(), and z_HTTP_header_set().

Referenced by rdf_lookup_node().

const char* yaz_url_get_error ( yaz_url_t  p)

get last error from yaz_url_exec

Parameters
phandle
Returns
message (possibly empty string no error occurred)

Definition at line 122 of file url.c.

References yaz_url::w_error, and wrbuf_cstr().

Referenced by rdf_lookup_node().

void yaz_url_set_max_redirects ( yaz_url_t  p,
int  num 
)

sets maximum number of redirects

Parameters
phandle
nummaximum number of redirects

Definition at line 68 of file url.c.

References yaz_url::max_redirects.

Referenced by rdf_lookup_node().

void yaz_url_set_proxy ( yaz_url_t  p,
const char *  proxy 
)

sets proxy for URL fetcher

Parameters
phandle
proxyproxy address , e.g "localhost:3128"

Passing a proxy of NULL disables proxy use.

Definition at line 60 of file url.c.

References yaz_url::proxy, xfree, and xstrdup.

void yaz_url_set_timeout ( yaz_url_t  p,
int  sec,
int  ns 
)

sets I/O timeout

Parameters
phandle
secmajor part of timeout in seconds
nsminor part of timeout in nanoseconds

Definition at line 78 of file url.c.

References yaz_url::timeout_ns, and yaz_url::timeout_sec.

Referenced by rdf_lookup_node().

void yaz_url_set_verbose ( yaz_url_t  p,
int  num 
)

sets verbose level 0=none, >0 verbose

Parameters
phandle
numverbose level

Definition at line 73 of file url.c.

References yaz_url::verbose.