28 "No error or unspecified error",
29 "System (lower-layer) error",
30 "Operation out of state",
31 "No data (operation would block)",
32 "New data while half of old buffer is on the line (flow control)",
35 "Too large incoming buffer",
36 "Protocol error in incoming data"
61 if (!strncmp(type_and_host,
"unix:", 5))
63 const char *cp = strchr(type_and_host + 5,
':');
66 type_and_host = cp + 1;
67 if (!strchr(type_and_host,
':'))
69 *args = type_and_host;
75 const char *cp = strchr(type_and_host,
'/');
78 if (cp > type_and_host && !memcmp(cp - 1,
"://", 3))
79 cp = strchr(cp + 2,
'/');
93 if (strncmp(uri,
"connect:", 8) == 0)
95 const char *cp = strchr(uri,
',');
102 *connect_host = (
char *)
xmalloc(len + 1);
103 memcpy(*connect_host, uri, len);
104 (*connect_host)[len] =
'\0';
108 else if (strncmp(uri,
"unix:", 5) == 0)
113 cp = strchr(uri,
':');
116 size_t len = cp - uri;
117 *connect_host = (
char *)
xmalloc(len + 1);
118 memcpy(*connect_host, uri, len);
119 (*connect_host)[len] =
'\0';
123 xfree(*connect_host);
131 if (strncmp (uri,
"tcp:", 4) == 0)
136 else if (strncmp (uri,
"ssl:", 4) == 0)
143 xfree(*connect_host);
148 else if (strncmp(uri,
"http:", 5) == 0)
151 while (**host ==
'/')
155 else if (strncmp(uri,
"https:", 6) == 0)
160 while (**host ==
'/')
164 xfree(*connect_host);
183 const char *proxy_host)
190 const char *proxy_host,
int *proxy_mode)
193 const char *host = 0;
196 char *connect_buf = 0;
197 char *connect_host = 0;
198 char *connect_auth = 0;
200 const char *bind_host = strchr(vhost,
' ');
201 if (bind_host && bind_host[1])
218 if (proxy_host && !connect_buf)
222 const char *host1 = 0;
224 if (!
cs_parse_host(proxy_host, &host1, &t1, &proto1, &connect_buf))
244 char *cp = strchr(connect_buf,
'@');
248 connect_host = cp + 1;
249 connect_auth = connect_buf;
251 connect_host = connect_buf;
257 connect_auth, bind_host);
262 connect_auth, bind_host);
270 if (!(*vp =
cs_straddr(cs, connect_host ? connect_host : host)))
289 if (buf[*i] ==
'\r' && *i < len-1 && buf[*i + 1] ==
'\n')
294 else if (buf[*i] ==
'\n')
307 || (c && strchr(
"!#$%&'*+-.^_`|~", c));
325 ret =
yaz_atoi(16, buf + i, len - i, &chunk_len);
341 if (chunk_len > len - i)
344 memcpy(content_buf + off, buf + i, chunk_len);
351 if (buf[i] ==
'\r' && i == len - 1)
361 if (buf[i] ==
'\r' && i == len - 1)
380 if (i == field_start)
406 int i, content_len = 0, chunked = 0;
412 else if (buf[i] ==
'\n' || buf[i] ==
'\r')
416 if (!head_only && !memcmp(buf,
"HTTP/", 5))
419 for (j = 5; j < i; j++)
425 else if (!memcmp(buf + j,
"204", 3))
427 else if (!memcmp(buf + j,
"304", 3))
434 for (i = 2; i <= len - 2; )
451 return r > 0 ? i + r : r;
453 if (content_len == -1)
455 if (content_len > (
unsigned)(INT_MAX - i))
457 if (len >= i + content_len)
458 return i + content_len;
465 while (i < len && buf[i] ==
' ')
473 if (i == token_start + 7 && !
yaz_strncasecmp(buf + token_start,
"chunked", 7))
481 else if (i < len - 16 && !
yaz_strncasecmp(buf+i,
"Content-Length:", 15))
486 while (i < len && buf[i] ==
' ')
490 no_read =
yaz_atoi(10, buf + i, len - i, &content_len);
503 if (len > 5 && buf[0] >= 0x20 && buf[0] < 0x7f
504 && buf[1] >= 0x20 && buf[1] < 0x7f
505 && buf[2] >= 0x20 && buf[2] < 0x7f
506 && buf[3] >= 0x20 && buf[3] < 0x7f)
ASCII to integer conversion.
int yaz_atoi(int base, const char *ptr, int len, int *val)
string to int conversion, with base
int completeBER_n(const char *buf, int len, int level)
determine whether a buffer is a complete BER buffer
Private Header for COMSTACK.
const char * yaz_tcpip_get_error_details(COMSTACK cs)
int yaz_http_parse_chunks(const char *buf, int len, char *content_buf, int *content_len)
int yaz_unix_set_head_only(COMSTACK cs, int head_only)
int yaz_tcpip_set_head_only(COMSTACK cs, int head_only)
int cs_get_error(COMSTACK cs, const char **details)
Returns the last COMSTACK error and optional transport details.
static int skip_crlf(const char *buf, int len, int *i)
void cs_set_max_recv_bytes(COMSTACK cs, int max_recv_bytes)
Sets the maximum incoming message size.
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.
int cs_complete_auto(const char *buf, int len)
Finds the length of a complete BER or HTTP message.
static int cs_complete_http(const char *buf, int len, int head_only)
int cs_parse_host(const char *uri, const char **host, CS_TYPE *t, enum oid_proto *proto, char **connect_host)
Parses transport and protocol prefixes without resolving an address.
void cs_get_host_args(const char *type_and_host, const char **args)
Extracts application arguments from a host or URI specification.
static int cs_complete_auto_x(const char *buf, int len, int head_only)
int cs_look(COMSTACK cs)
Returns the last recorded event (CS_NONE, CS_CONNECT, etc.).
int cs_complete_auto_head(const char *buf, int len)
Finds the length of a BER message or HTTP headers.
static const char * cs_errlist[]
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.
COMSTACK cs_create_host(const char *vhost, int flags, void **vp)
Creates an endpoint from a host or URI specification.
COMSTACK cs_create_host_proxy(const char *vhost, int flags, void **vp, const char *proxy_host)
Creates an endpoint with an optional proxy.
const char * cs_strerror(COMSTACK h)
Returns a static message for the endpoint's last error.
static int http_token_char(char c)
#define cs_close(handle)
Closes the socket and frees the endpoint and its transport state.
struct comstack * COMSTACK
Communication endpoint; release with cs_close.
#define cs_create(type, flags, proto)
Creates an endpoint using a transport constructor.
COMSTACK(*) CS_TYPE(int s, int flags, int protocol, void *vp)
Transport constructor and transport identity.
#define cs_straddr(handle, str)
Parses a transport-specific address and prepares the endpoint.
Header for errno utilities.
int yaz_strncasecmp(const char *s1, const char *s2, size_t n)
ala strncasecmp - no locale
Header for YAZ iconv interface.
Header for ODR (Open Data Representation).
COMSTACK yaz_ssl_create(int s, int flags, int protocol, const char *connect_host, const char *connect_auth, const char *bind_host)
COMSTACK tcpip_type(int s, int flags, int protocol, void *vp)
COMSTACK ssl_type(int s, int flags, int protocol, void *vp)
COMSTACK yaz_tcpip_create3(int s, int flags, int protocol, const char *connect_host, const char *connect_auth, const char *bind_host)
Header for TCP/IP + SSL COMSTACK.
COMSTACK unix_type(int s, int flags, int protocol, void *vp)
Header for UNIX domain socket COMSTACK.
#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
Header for YAZ iconv interface.