X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fhttp.c;h=cbba2a8a094e866f029bea708496bda1b1de4047;hb=717296a6a0e0a47ab62fea3597fea7ea7b9177f9;hp=401f5ae4ceb931ed23daf91b663efb0aeba5b25b;hpb=fe3383c0559a453df1e5076fc6faac6d1a11685c;p=pazpar2-moved-to-github.git diff --git a/src/http.c b/src/http.c index 401f5ae..cbba2a8 100644 --- a/src/http.c +++ b/src/http.c @@ -1,5 +1,5 @@ /* - * $Id: http.c,v 1.1 2006-12-20 20:47:16 quinn Exp $ + * $Id: http.c,v 1.8 2007-01-10 10:04:23 adam Exp $ */ #include @@ -15,11 +15,14 @@ #include #include +#if HAVE_CONFIG_H +#include +#endif + #include #include #include -#include "command.h" #include "util.h" #include "eventl.h" #include "pazpar2.h" @@ -89,10 +92,10 @@ static struct http_buf *http_buf_bybuf(char *b, int len) while (len) { - *p = http_buf_create(); int tocopy = len; if (tocopy > HTTP_BUF_SIZE) tocopy = HTTP_BUF_SIZE; + *p = http_buf_create(); memcpy((*p)->buf, b, tocopy); (*p)->len = tocopy; len -= tocopy; @@ -263,6 +266,7 @@ struct http_request *http_parse_request(struct http_channel *c, struct http_buf if (http_buf_read(queue, buf, len) < len) return 0; + r->search = ""; r->channel = c; r->arguments = 0; r->headers = 0; @@ -293,6 +297,7 @@ struct http_request *http_parse_request(struct http_channel *c, struct http_buf r->path = nmem_strdup(c->nmem, buf); if (p2) { + r->search = nmem_strdup(c->nmem, p2); // Parse Arguments while (*p2) { @@ -370,9 +375,9 @@ struct http_request *http_parse_request(struct http_channel *c, struct http_buf static struct http_buf *http_serialize_response(struct http_channel *c, struct http_response *r) { - wrbuf_rewind(c->wrbuf); struct http_header *h; + wrbuf_rewind(c->wrbuf); wrbuf_printf(c->wrbuf, "HTTP/1.1 %s %s\r\n", r->code, r->msg); for (h = r->headers; h; h = h->next) wrbuf_printf(c->wrbuf, "%s: %s\r\n", h->name, h->value); @@ -390,10 +395,10 @@ static struct http_buf *http_serialize_response(struct http_channel *c, static struct http_buf *http_serialize_request(struct http_request *r) { struct http_channel *c = r->channel; - wrbuf_rewind(c->wrbuf); struct http_header *h; struct http_argument *a; + wrbuf_rewind(c->wrbuf); wrbuf_printf(c->wrbuf, "%s %s", r->method, r->path); if (r->arguments) @@ -490,8 +495,10 @@ static int http_proxy(struct http_request *rq) void http_send_response(struct http_channel *ch) { struct http_response *rs = ch->response; + struct http_buf *hb; + assert(rs); - struct http_buf *hb = http_serialize_response(ch, rs); + hb = http_serialize_response(ch, rs); if (!hb) { yaz_log(YLOG_WARN, "Failed to serialize HTTP response"); @@ -517,7 +524,12 @@ static void http_io(IOCHAN i, int event) case EVENT_INPUT: htbuf = http_buf_create(); res = read(iochan_getfd(i), htbuf->buf, HTTP_BUF_SIZE -1); - if (res <= 0 && errno != EAGAIN) + if (res == -1 && errno == EAGAIN) + { + http_buf_destroy(htbuf); + return; + } + if (res <= 0) { http_buf_destroy(htbuf); http_destroy(i); @@ -532,7 +544,6 @@ static void http_io(IOCHAN i, int event) if (hc->state == Http_Busy) return; - if ((reqlen = request_check(hc->iqueue)) <= 2) return; @@ -544,8 +555,10 @@ static void http_io(IOCHAN i, int event) return; } hc->response = 0; - yaz_log(YLOG_LOG, "Request: %s %s v %s", hc->request->method, - hc->request->path, hc->request->http_version); + yaz_log(YLOG_LOG, "Request: %s %s%s%s", hc->request->method, + hc->request->path, + *hc->request->search ? "?" : "", + hc->request->search); if (http_weshouldproxy(hc->request)) http_proxy(hc->request); else @@ -750,7 +763,7 @@ static void http_accept(IOCHAN i, int event) if (fcntl(s, F_SETFL, flags | O_NONBLOCK) < 0) yaz_log(YLOG_FATAL|YLOG_ERRNO, "fcntl2"); - yaz_log(YLOG_LOG, "New command connection"); + yaz_log(YLOG_DEBUG, "New command connection"); c = iochan_create(s, http_io, EVENT_INPUT | EVENT_EXCEPT); ch = http_create(); @@ -774,7 +787,7 @@ void http_init(const char *addr) yaz_log(YLOG_LOG, "HTTP listener is %s", addr); - bzero(&myaddr, sizeof myaddr); + memset(&myaddr, 0, sizeof myaddr); myaddr.sin_family = AF_INET; pp = strchr(addr, ':'); if (pp)