YAZ  5.26.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


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

◆ extract_user_pass()

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

Definition at line 84 of file url.c.

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

Referenced by yaz_url_exec().

◆ log_warn()

static void log_warn ( yaz_url_t  p)

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_create()

yaz_url_t yaz_url_create ( void  )

◆ yaz_url_destroy()

void yaz_url_destroy ( yaz_url_t  p)

destroys a URL fetcher


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().

◆ yaz_url_exec()

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)

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
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().

◆ yaz_url_get_error()

const char* yaz_url_get_error ( yaz_url_t  p)

get last error from yaz_url_exec

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().

◆ yaz_url_set_max_redirects()

void yaz_url_set_max_redirects ( yaz_url_t  p,
int  num 

sets maximum number of redirects

nummaximum number of redirects

Definition at line 68 of file url.c.

References yaz_url::max_redirects.

Referenced by rdf_lookup_node().

◆ yaz_url_set_proxy()

void yaz_url_set_proxy ( yaz_url_t  p,
const char *  proxy 

sets proxy for URL fetcher

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.

◆ yaz_url_set_timeout()

void yaz_url_set_timeout ( yaz_url_t  p,
int  sec,
int  ns 

sets I/O timeout

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().

◆ yaz_url_set_verbose()

void yaz_url_set_verbose ( yaz_url_t  p,
int  num 

sets verbose level 0=none, >0 verbose

numverbose level

Definition at line 73 of file url.c.

References yaz_url::verbose.