26 "No error or unspecified error",
27 "System (lower-layer) error",
28 "Operation out of state",
29 "No data (operation would block)",
30 "New data while half of old buffer is on the line (flow control)",
33 "Too large incoming buffer"
51 if (!strncmp(type_and_host,
"unix:", 5))
53 const char *cp = strchr(type_and_host + 5,
':');
56 type_and_host = cp + 1;
57 if (!strchr(type_and_host,
':'))
59 *args = type_and_host;
65 const char *cp = strchr(type_and_host,
'/');
68 if (cp > type_and_host && !memcmp(cp - 1,
"://", 3))
69 cp = strchr(cp + 2,
'/');
83 if (strncmp(uri,
"connect:", 8) == 0)
85 const char *cp = strchr(uri,
',');
92 *connect_host = (
char *)
xmalloc(len + 1);
93 memcpy(*connect_host, uri, len);
94 (*connect_host)[len] =
'\0';
98 else if (strncmp(uri,
"unix:", 5) == 0)
103 cp = strchr(uri,
':');
106 size_t len = cp - uri;
107 *connect_host = (
char *)
xmalloc(len + 1);
108 memcpy(*connect_host, uri, len);
109 (*connect_host)[len] =
'\0';
113 xfree(*connect_host);
121 if (strncmp (uri,
"tcp:", 4) == 0)
126 else if (strncmp (uri,
"ssl:", 4) == 0)
133 xfree(*connect_host);
138 else if (strncmp(uri,
"http:", 5) == 0)
141 while (**host ==
'/')
145 else if (strncmp(uri,
"https:", 6) == 0)
150 while (**host ==
'/')
154 xfree(*connect_host);
173 const char *proxy_host)
180 const char *proxy_host,
int *proxy_mode)
183 const char *host = 0;
186 char *connect_host = 0;
188 const char *bind_host = strchr(vhost,
' ');
189 if (bind_host && bind_host[1])
206 if (proxy_host && !connect_host)
210 const char *host1 = 0;
212 if (!
cs_parse_host(proxy_host, &host1, &t1, &proto1, &connect_host))
247 if (!(*vp =
cs_straddr(cs, connect_host ? connect_host : host)))
266 if (buf[*i] ==
'\r' && *i < len-1 && buf[*i + 1] ==
'\n')
271 else if (buf[*i] ==
'\n')
280 #define CHUNK_DEBUG 0
293 for (j = i; j <= i+3; j++)
294 printf (
"%c", buf[j]);
302 printf (
"returning incomplete read at 1\n");
303 printf (
"i=%d len=%d\n", i, len);
307 chunk_len = chunk_len * 16 +
310 chunk_len = chunk_len * 16 +
311 (buf[i++] - (
'A'-10));
313 chunk_len = chunk_len * 16 +
314 (buf[i++] - (
'a'-10));
332 printf (
"chunk_len=%d\n", chunk_len);
352 printf (
"returning incomplete read at 2\n");
353 printf (
"i=%d len=%d\n", i, len);
361 int i, content_len = 0, chunked = 0;
367 else if (buf[i] ==
'\n' || buf[i] ==
'\r')
371 if (!head_only && !memcmp(buf,
"HTTP/", 5))
374 for (j = 5; j < i; j++)
380 else if (!memcmp(buf + j,
"204", 3))
382 else if (!memcmp(buf + j,
"304", 3))
390 printf(
"len = %d\n", len);
391 fwrite (buf, 1, len, stdout);
392 printf(
"----------\n");
394 for (i = 2; i <= len-2; )
411 if (content_len == -1)
413 else if (len >= i + content_len)
415 return i + content_len;
420 else if (i < len - 20 &&
422 "Transfer-Encoding:", 18))
425 while (buf[i] ==
' ')
431 else if (i < len - 17 &&
433 "Content-Length:", 15))
436 while (buf[i] ==
' ')
440 content_len = content_len*10 + (buf[i++] -
'0');
455 if (len > 5 && buf[0] >= 0x20 && buf[0] < 0x7f
456 && buf[1] >= 0x20 && buf[1] < 0x7f
457 && buf[2] >= 0x20 && buf[2] < 0x7f)
int completeBER(const char *buf, int len)
determine whether a buffer is a complete BER buffer
static int skip_crlf(const char *buf, int len, int *i)
COMSTACK cs_create_host(const char *vhost, int blocking, void **vp)
void cs_set_max_recv_bytes(COMSTACK cs, int max_recv_bytes)
static int cs_read_chunk(const char *buf, int i, int len)
int cs_complete_auto(const char *buf, int len)
const char * cs_strerror(COMSTACK h)
const char * cs_errmsg(int n)
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)
void cs_get_host_args(const char *type_and_host, const char **args)
static int cs_complete_auto_x(const char *buf, int len, int head_only)
int cs_complete_auto_head(const char *buf, int len)
static const char * cs_errlist[]
COMSTACK cs_create_host2(const char *vhost, int blocking, void **vp, const char *proxy_host, int *proxy_mode)
COMSTACK cs_create_host_proxy(const char *vhost, int blocking, void **vp, const char *proxy_host)
#define cs_straddr(handle, str)
#define cs_create(type, blocking, proto)
COMSTACK(* CS_TYPE)(int s, int flags, int protocol, void *vp)
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.