From: Marc Cromme Date: Tue, 27 Mar 2007 13:41:23 +0000 (+0000) Subject: added HTTP headers "pazpar2-version", "pazpar2-server-host", "pazpar2-server-port... X-Git-Tag: PAZPAR2.1.0.0~396 X-Git-Url: http://lists.indexdata.com/cgi-bin?a=commitdiff_plain;h=19e8783985686ff7d094da7d843131deea4ced1b;p=pazpar2-moved-to-github.git added HTTP headers "pazpar2-version", "pazpar2-server-host", "pazpar2-server-port", "pazpar2-remote-host", and "pazpar2-remote-port" such that the HTTP proxy PHP script can fetch these values and use them for authentification and other pazpar2 specific stuff (this is needed, because the "Remote-Addr" PHP variable is always set to the paraz2 server IP adress, due to tunneling through pazpar2. The only thing which needs completion is actually finding the correct values for these host and port parameters from the server configuration and the TCP/IP connection object. More digging in the source is needed to find these values the right places.. --- diff --git a/src/http.c b/src/http.c index 1e5058a..533df30 100644 --- a/src/http.c +++ b/src/http.c @@ -1,5 +1,5 @@ /* - * $Id: http.c,v 1.12 2007-03-15 16:50:56 quinn Exp $ + * $Id: http.c,v 1.13 2007-03-27 13:41:23 marc Exp $ */ #include @@ -25,6 +25,7 @@ #include #include +#include "cconfig.h" #include "util.h" #include "eventl.h" #include "pazpar2.h" @@ -509,12 +510,35 @@ static int http_weshouldproxy(struct http_request *rq) return 0; } + +struct http_header * http_header_append(struct http_channel *ch, + struct http_header * hp, + const char *name, + const char *value) +{ + struct http_header *hpnew = nmem_malloc(ch->nmem, sizeof *hpnew); + + while (hp && hp->next) + hp = hp->next; + + hpnew->name = nmem_strdup(ch->nmem, name); + hpnew->value = nmem_strdup(ch->nmem, value); + hpnew->next = 0; + hp->next = hpnew; + hp = hp->next; + return hpnew; +} + + + static int http_proxy(struct http_request *rq) { struct http_channel *c = rq->channel; struct http_proxy *p = c->proxy; struct http_header *hp; struct http_buf *requestbuf; + //struct conf_server *ser = global_parameters.server; + if (!p) // This is a new connection. Create a proxy channel { @@ -538,7 +562,8 @@ static int http_proxy(struct http_request *rq) yaz_log(YLOG_FATAL|YLOG_ERRNO, "fcntl"); if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) < 0) yaz_log(YLOG_FATAL|YLOG_ERRNO, "fcntl2"); - if (connect(sock, (struct sockaddr *) proxy_addr, sizeof(*proxy_addr)) < 0) + if (connect(sock, (struct sockaddr *) proxy_addr, + sizeof(*proxy_addr)) < 0) if (errno != EINPROGRESS) { yaz_log(YLOG_WARN|YLOG_ERRNO, "Proxy connect"); @@ -567,6 +592,16 @@ static int http_proxy(struct http_request *rq) return -1; } hp->value = nmem_strdup(c->nmem, proxy_url); + + // Add new header about paraz2 version, host, remote client address, etc. + + hp = rq->headers; + hp = http_header_append(c, hp, PACKAGE_NAME "-version", PACKAGE_VERSION); + //hp = http_header_append(c, hp, PACKAGE_NAME "-server-host", ser->host); + //hp = http_header_append(c, hp, PACKAGE_NAME "-server-port", ser->port); + //hp = http_header_append(c, hp, PACKAGE_NAME "-remote-host", "blabla"); + //hp = http_header_append(c, hp, PACKAGE_NAME "-remote-port", "blabla"); + requestbuf = http_serialize_request(rq); http_buf_enqueue(&p->oqueue, requestbuf); iochan_setflag(p->iochan, EVENT_OUTPUT); diff --git a/src/http.h b/src/http.h index 5c7ac26..20f0521 100644 --- a/src/http.h +++ b/src/http.h @@ -74,7 +74,12 @@ struct http_response void http_set_proxyaddr(char *url, char *baseurl); void http_init(const char *addr); -void http_addheader(struct http_response *r, const char *name, const char *value); +void http_addheader(struct http_response *r, + const char *name, const char *value); +struct http_header * http_header_append(struct http_channel *ch, + struct http_header * hp, + const char *name, + const char *value); char *http_argbyname(struct http_request *r, char *name); char *http_headerbyname(struct http_header *r, char *name); struct http_response *http_create_response(struct http_channel *c);