24 char **content_buf,
int *content_len)
28 const char *buf = o->
op->
buf;
32 while (i < size-1 && buf[i] ==
'\n')
36 if (buf[i] ==
'\r' && i < size-1 && buf[i+1] ==
'\n')
50 else if (buf[i] ==
':')
54 (*headers)->name =
odr_strdupn(o, buf + po, i - po);
56 while (i < size-1 && buf[i] ==
' ')
58 for (po = i; i < size-1 && !strchr(
"\r\n", buf[i]); i++)
61 (*headers)->value =
odr_strdupn(o, buf + po, i - po);
66 headers = &(*headers)->
next;
67 if (i < size-1 && buf[i] ==
'\r')
83 *content_buf = (
char*)
odr_malloc(o, size - i);
108 *content_len = size - i;
109 *content_buf =
odr_strdupn(o, buf + i, *content_len);
116 const char *content_type,
119 const char *l =
"Content-Type";
123 content_type, charset);
136 const char *username,
const char *password)
146 buf = (
char *)
odr_malloc(o, strlen(tmp) * 8/6 + 12);
147 strcpy(buf,
"Basic ");
187 const char *v = (*hp)->value;
198 for (; hp; hp = hp->
next)
212 hreq = p->
u.HTTP_Request;
234 const char *cp0 = strstr(host,
"://");
241 cp1 = strchr(cp0,
'/');
243 cp1 = cp0+strlen(cp0);
258 const char *cp0 = strstr(uri,
"://");
265 cp1 = strchr(cp0,
'/');
267 cp1 = cp0+strlen(cp0);
282 p->
u.HTTP_Request->path =
odr_malloc(
odr, cp1 - uri + strlen(args) + 2);
285 memcpy(p->
u.HTTP_Request->path, uri, cp1 - uri);
286 strcpy(p->
u.HTTP_Request->path + (cp1 - uri),
"/");
289 strcpy(p->
u.HTTP_Request->path,
"/");
290 strcat(p->
u.HTTP_Request->path, args);
295 const char *server,
const char *server_url)
302 hres = p->
u.HTTP_Response;
312 size_t sz = 400 + strlen(http_err) + (details ?
313 strlen(details) : 0);
316 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\""
317 " \"http://www.w3.org/TR/html4/strict.dtd\">\n"
320 " <TITLE>%s</TITLE>\n"
323 " <P><A HREF=\"%s\">%s</A></P>\n"
324 " <P>Error: %d</P>\n"
325 " <P>Description: %s</P>\n", server, server_url, server,
331 "<P>Details: %s</P>\n", details);
346 "http://www.indexdata.com/yaz");
361 return "Switching Protocols";
369 return "Non-Authoritative Information";
373 return "Reset Content";
375 return "Partial Content";
377 return "Multiple Choices";
379 return "Moved Permenently";
385 return "Not Modified";
389 return "Temporary Redirect";
391 return "Bad Request";
395 return "Method Not Allowed";
397 return "Not Acceptable";
399 return "Proxy Authentication Required";
401 return "Request Timeout";
407 return "Length Required";
409 return "Precondition Failed";
411 return "Request Entity Too Large";
413 return "Request-URI Too Long";
415 return "Unsupported Media Type";
417 return "Requested Range Not Satisfiable";
419 return "Expectation Failed";
421 return "Internal Error";
423 return "Not Implemented";
425 return "Bad Gateway";
427 return "Service Unavailable";
429 return "Gateway Timeout";
431 return "HTTP Version Not Supported";
433 return "Unknown Error";
440 if (sz < 10 || memcmp(buf,
"HTTP/", 5))
445 else if (strchr(
" \r\n", buf[i]))
452 *version_len = i - 5;
461 if (buf[i] <
'0' || buf[i] >
'9')
463 *code = *code*10 + (buf[i] -
'0');
472 if (strchr(
"\r\n", buf[i]))
479 if (i < sz - 1 && buf[i] ==
'\r')
490 const char *buf = o->
op->
buf;
512 const char *buf = o->
op->
buf;
524 for (i = 0; buf[i] !=
' '; i++)
525 if (i >= size-5 || i > 30)
532 while (i < size && !strchr(
"\r\n", buf[i]))
538 if (!lspace || i >= size || lspace >= size - 5 ||
539 memcmp(buf + lspace + 1,
"HTTP/", 5))
546 if (i < size-1 && buf[i] ==
'\r')
571 odr_printf(o,
"(truncated from %ld to %d\n", (
long) len, i);
574 else if (buf[i] == 0)
587 int top0 = o->
op->
top;
623 int top0 = o->
op->
top;
629 cp = strchr(hr->
path,
'#');
639 yaz_snprintf(lstr,
sizeof(lstr),
"Content-Length: %d\r\n",
667 if (*location ==
'/')
672 strcpy(nlocation, uri);
675 args = nlocation + strlen(nlocation);
678 strcpy(args, location);
void yaz_base64encode(const char *in, char *out)
encodes Base64 string
Header for Base64 utilities.
Private Header for COMSTACK.
int yaz_http_parse_chunks(const char *buf, int len, char *content_buf, int *content_len)
void cs_get_host_args(const char *type_and_host, const char **args)
Extracts application arguments from a host or URI specification.
Transport-independent communication endpoints for BER and HTTP.
int yaz_decode_http_request(ODR o, Z_HTTP_Request **hr_p)
Z_GDU * z_get_HTTP_Response_details(ODR o, int code, const char *details)
int yaz_encode_http_request(ODR o, Z_HTTP_Request *hr)
void z_HTTP_header_add_basic_auth(ODR o, Z_HTTP_Header **hp, const char *username, const char *password)
int yaz_decode_http_response(ODR o, Z_HTTP_Response **hr_p)
Z_GDU * z_get_HTTP_Request_host_path(ODR odr, const char *host, const char *path)
int yaz_decode_http_response_first(const char *buf, int sz, int *code, const char **version, int *version_len, const char **msg, int *msg_len)
void z_HTTP_header_set(ODR o, Z_HTTP_Header **hp, const char *n, const char *v)
Z_GDU * z_get_HTTP_Response(ODR o, int code)
Z_GDU * z_get_HTTP_Request(ODR o)
Z_GDU * z_get_HTTP_Response_server(ODR o, int code, const char *details, const char *server, const char *server_url)
static int decode_headers_content(ODR o, int off, Z_HTTP_Header **headers, char **content_buf, int *content_len)
int yaz_encode_http_response(ODR o, Z_HTTP_Response *hr)
const char * z_HTTP_errmsg(int code)
const char * yaz_check_location(ODR odr, const char *uri, const char *location, int *host_change)
const char * z_HTTP_header_remove(Z_HTTP_Header **hp, const char *n)
static void dump_http_package(ODR o, const char *buf, size_t len)
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 z_HTTP_header_add_content_type(ODR o, Z_HTTP_Header **hp, const char *content_type, const char *charset)
int yaz_strcasecmp(const char *s1, const char *s2)
ala strcasecmp - no locale
Header for YAZ iconv interface.
char * nmem_printf(NMEM nmem, const char *fmt,...)
formats and prints a string into NMEM allocated memory
Internal ODR definitions.
void odr_printf(ODR o, const char *fmt,...)
#define ODR_VISIBLESTRING
void * odr_malloc(ODR o, size_t size)
char * odr_strdupn(ODR o, const char *str, size_t n)
char * odr_strdup(ODR o, const char *str)
int odr_write(ODR o, const char *buf, int bytes)
void yaz_snprintf(char *buf, size_t size, const char *fmt,...)
Header for config file reading utilities.
void(*) stream_write(ODR o, void *handle, int type, const char *buf, int len)
union Z_GDU::@057307356220171136236350364324260103365227025100 u
Header for YAZ iconv interface.
#define YAZ_VERSION
YAZ version as string.
Header for the Z_GDU (HTTP or Z39.50 package).
#define Z_GDU_HTTP_Response
#define Z_GDU_HTTP_Request