23 char **content_buf,
int *content_len)
27 const char *buf = o->
op->
buf;
31 while (i < size-1 && buf[i] ==
'\n')
35 if (buf[i] ==
'\r' && i < size-1 && buf[i+1] ==
'\n')
49 else if (buf[i] ==
':')
55 while (i < size-1 && buf[i] ==
' ')
57 for (po = i; i < size-1 && !strchr(
"\r\n", buf[i]); i++)
60 (*headers)->value =
odr_strdupn(o, buf + po, i - po);
65 headers = &(*headers)->
next;
66 if (i < size-1 && buf[i] ==
'\r')
82 *content_buf = (
char*)
odr_malloc(o, size - i);
88 for (; i < size-2; i++)
90 chunk_len = chunk_len * 16 +
93 chunk_len = chunk_len * 16 +
96 chunk_len = chunk_len * 16 +
101 while (buf[i] !=
'\r' && buf[i+1] !=
'\n')
113 if (chunk_len < 0 || off + chunk_len > size)
119 memcpy (*content_buf + off, buf + i, chunk_len);
141 *content_len = size - i;
142 *content_buf =
odr_strdupn(o, buf + i, *content_len);
149 const char *content_type,
152 const char *l =
"Content-Type";
156 content_type, charset);
169 const char *username,
const char *password)
179 buf = (
char *)
odr_malloc(o, strlen(tmp) * 8/6 + 12);
180 strcpy(buf,
"Basic ");
220 const char *v = (*hp)->value;
231 for (; hp; hp = hp->
next)
267 const char *cp0 = strstr(host,
"://");
274 cp1 = strchr(cp0,
'/');
276 cp1 = cp0+strlen(cp0);
291 const char *cp0 = strstr(uri,
"://");
298 cp1 = strchr(cp0,
'/');
300 cp1 = cp0+strlen(cp0);
328 const char *server,
const char *server_url)
345 size_t sz = 400 + strlen(http_err) + (details ?
346 strlen(details) : 0);
349 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\""
350 " \"http://www.w3.org/TR/html4/strict.dtd\">\n"
353 " <TITLE>%s</TITLE>\n"
356 " <P><A HREF=\"%s\">%s</A></P>\n"
357 " <P>Error: %d</P>\n"
358 " <P>Description: %s</P>\n", server, server_url, server,
364 "<P>Details: %s</P>\n", details);
379 "http://www.indexdata.com/yaz");
394 return "Switching Protocols";
402 return "Non-Authoritative Information";
406 return "Reset Content";
408 return "Partial Content";
410 return "Multiple Choices";
412 return "Moved Permenently";
418 return "Not Modified";
422 return "Temporary Redirect";
424 return "Bad Request";
428 return "Method Not Allowed";
430 return "Not Acceptable";
432 return "Proxy Authentication Required";
434 return "Request Timeout";
440 return "Length Required";
442 return "Precondition Failed";
444 return "Request Entity Too Large";
446 return "Request-URI Too Long";
448 return "Unsupported Media Type";
450 return "Requested Range Not Satisfiable";
452 return "Expectation Failed";
454 return "Internal Error";
456 return "Not Implemented";
458 return "Bad Gateway";
460 return "Service Unavailable";
462 return "Gateway Timeout";
464 return "HTTP Version Not Supported";
466 return "Unknown Error";
474 const char *buf = o->
op->
buf;
482 while (i < size-2 && !strchr(
" \r\n", buf[i]))
492 while (i < size-2 && buf[i] >=
'0' && buf[i] <=
'9')
494 hr->
code = hr->
code*10 + (buf[i] -
'0');
497 while (i < size-1 && buf[i] !=
'\n')
507 const char *buf = o->
op->
buf;
519 for (i = 0; buf[i] !=
' '; i++)
520 if (i >= size-5 || i > 30)
527 while (i < size && !strchr(
"\r\n", buf[i]))
533 if (!lspace || i >= size || lspace >= size - 5 ||
534 memcmp(buf + lspace + 1,
"HTTP/", 5))
541 if (i < size-1 && buf[i] ==
'\r')
566 odr_printf(o,
"(truncated from %ld to %d\n", (
long) len, i);
569 else if (buf[i] == 0)
582 int top0 = o->
op->
top;
618 int top0 = o->
op->
top;
624 cp = strchr(hr->
path,
'#');
634 yaz_snprintf(lstr,
sizeof(lstr),
"Content-Length: %d\r\n",
662 if (*location ==
'/')
667 strcpy(nlocation, uri);
670 args = nlocation + strlen(nlocation);
673 strcpy(args, location);
void yaz_base64encode(const char *in, char *out)
encodes Base64 string
Header for Base64 utilities.
void cs_get_host_args(const char *type_and_host, const char **args)
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)
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)
Z_HTTP_Request * HTTP_Request
Z_HTTP_Response * HTTP_Response
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