From 7cb18e001c719f24b9f440f91fc44ddaaeda3303 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Sun, 8 Apr 2007 23:04:20 +0000 Subject: [PATCH] Moved HTTP channel address from struct iochan to struct http_channel. This fixes compilation on FreeBSD and reverts eventl.{c,h} to original paraz state. This change, simple as it is, is untested. --- src/eventl.c | 23 ++++++++--------------- src/eventl.h | 20 +++++++------------- src/http.c | 29 ++++++++++++++++++----------- src/http.h | 1 + src/http_command.c | 4 ++-- src/pazpar2.c | 4 ++-- 6 files changed, 38 insertions(+), 43 deletions(-) diff --git a/src/eventl.c b/src/eventl.c index cc8a6b9..c9ecbd4 100644 --- a/src/eventl.c +++ b/src/eventl.c @@ -6,7 +6,7 @@ */ /* - * $Id: eventl.c,v 1.3 2007-03-28 12:05:18 marc Exp $ + * $Id: eventl.c,v 1.4 2007-04-08 23:04:20 adam Exp $ * Based on revision YAZ' server/eventl.c 1.29. */ @@ -17,7 +17,11 @@ #include #endif - +#ifdef WIN32 +#include +#else +#include +#endif #include #include #include @@ -26,13 +30,10 @@ #include #include #include -#include - #include "eventl.h" +#include - -IOCHAN iochan_create(int fd, struct sockaddr_in *addr_in, - IOC_CALLBACK cb, int flags) +IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags) { IOCHAN new_iochan; @@ -40,14 +41,6 @@ IOCHAN iochan_create(int fd, struct sockaddr_in *addr_in, return 0; new_iochan->destroyed = 0; new_iochan->fd = fd; - - if(addr_in){ - new_iochan->addr_in.sin_family = addr_in->sin_family; - new_iochan->addr_in.sin_port = addr_in->sin_port; - new_iochan->addr_in.sin_addr = addr_in->sin_addr; - strncpy(new_iochan->addr_str, inet_ntoa(addr_in->sin_addr), 64); - } - new_iochan->flags = flags; new_iochan->fun = cb; new_iochan->force_event = 0; diff --git a/src/eventl.h b/src/eventl.h index aee2106..169044c 100644 --- a/src/eventl.h +++ b/src/eventl.h @@ -3,7 +3,12 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: eventl.h,v 1.2 2007-03-28 12:05:18 marc Exp $ + * $Log: eventl.h,v $ + * Revision 1.3 2007-04-08 23:04:20 adam + * Moved HTTP channel address from struct iochan to struct http_channel. + * This fixes compilation on FreeBSD and reverts eventl.{c,h} to original + * paraz state. This change, simple as it is, is untested. + * * Revision 1.1 2006/12/20 20:47:16 quinn * Reorganized source tree * @@ -61,14 +66,6 @@ #include -#ifdef WIN32 -#include -#else -#include -#include -#endif - - struct iochan; typedef void (*IOC_CALLBACK)(struct iochan *i, int event); @@ -76,8 +73,6 @@ typedef void (*IOC_CALLBACK)(struct iochan *i, int event); typedef struct iochan { int fd; - struct sockaddr_in addr_in; - char addr_str[64]; int flags; #define EVENT_INPUT 0x01 #define EVENT_OUTPUT 0x02 @@ -111,8 +106,7 @@ typedef struct iochan #define iochan_settimeout(i, t) ((i)->max_idle = (t), (i)->last_event = time(0)) #define iochan_activity(i) ((i)->last_event = time(0)) -IOCHAN iochan_create(int fd, struct sockaddr_in * addr_in, - IOC_CALLBACK cb, int flags); +IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags); int event_loop(IOCHAN *iochans); #endif diff --git a/src/http.c b/src/http.c index a327cf3..527e887 100644 --- a/src/http.c +++ b/src/http.c @@ -1,5 +1,5 @@ /* - * $Id: http.c,v 1.21 2007-04-02 09:43:08 marc Exp $ + * $Id: http.c,v 1.22 2007-04-08 23:04:20 adam Exp $ */ #include @@ -21,6 +21,7 @@ #endif #include +#include #include #include @@ -35,7 +36,7 @@ #include "http_command.h" static void proxy_io(IOCHAN i, int event); -static struct http_channel *http_create(void); +static struct http_channel *http_create(const char *addr); static void http_destroy(IOCHAN i); extern IOCHAN channel_list; @@ -592,7 +593,7 @@ static int http_proxy(struct http_request *rq) p->first_response = 1; c->proxy = p; // We will add EVENT_OUTPUT below - p->iochan = iochan_create(sock, 0, proxy_io, EVENT_INPUT); + p->iochan = iochan_create(sock, proxy_io, EVENT_INPUT); iochan_setdata(p->iochan, p); p->iochan->next = channel_list; channel_list = p->iochan; @@ -621,9 +622,9 @@ static int http_proxy(struct http_request *rq) sprintf(server_via, "1.1 %s:%s (%s/%s)", ser->host, server_port, PACKAGE_NAME, PACKAGE_VERSION); hp = http_header_append(c, hp, "Via" , server_via); - hp = http_header_append(c, hp,"X-Forwarded-For", c->iochan->addr_str); - } - + hp = http_header_append(c, hp, "X-Forwarded-For", c->addr); + } + requestbuf = http_serialize_request(rq); http_buf_enqueue(&p->oqueue, requestbuf); iochan_setflag(p->iochan, EVENT_OUTPUT); @@ -902,7 +903,7 @@ static void http_destroy(IOCHAN i) iochan_destroy(i); } -static struct http_channel *http_create(void) +static struct http_channel *http_create(const char *addr) { struct http_channel *r = http_channel_freelist; @@ -924,6 +925,12 @@ static struct http_channel *http_create(void) r->state = Http_Idle; r->request = 0; r->response = 0; + if (!addr) + { + yaz_log(YLOG_WARN, "Invalid HTTP forward address"); + exit(1); + } + r->addr = nmem_strdup(r->nmem, addr); return r; } @@ -951,9 +958,9 @@ static void http_accept(IOCHAN i, int event) yaz_log(YLOG_FATAL|YLOG_ERRNO, "fcntl2"); yaz_log(YLOG_DEBUG, "New command connection"); - c = iochan_create(s, &addr, http_io, EVENT_INPUT | EVENT_EXCEPT); - - ch = http_create(); + c = iochan_create(s, http_io, EVENT_INPUT | EVENT_EXCEPT); + + ch = http_create(inet_ntoa(addr.sin_addr)); ch->iochan = c; iochan_setdata(c, ch); @@ -1035,7 +1042,7 @@ void http_init(const char *addr) if (listen(l, SOMAXCONN) < 0) yaz_log(YLOG_FATAL|YLOG_ERRNO, "listen"); - c = iochan_create(l, &myaddr, http_accept, EVENT_INPUT | EVENT_EXCEPT); + c = iochan_create(l, http_accept, EVENT_INPUT | EVENT_EXCEPT); c->next = channel_list; channel_list = c; } diff --git a/src/http.h b/src/http.h index 20f0521..4e8cc33 100644 --- a/src/http.h +++ b/src/http.h @@ -28,6 +28,7 @@ struct http_channel struct http_request *request; struct http_response *response; struct http_channel *next; // for freelist + char *addr; /* forwarded address */ }; struct http_proxy // attached to iochan for proxy connection diff --git a/src/http_command.c b/src/http_command.c index 4d6c355..ae6e8f8 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -1,5 +1,5 @@ /* - * $Id: http_command.c,v 1.29 2007-03-28 12:05:18 marc Exp $ + * $Id: http_command.c,v 1.30 2007-04-08 23:04:20 adam Exp $ */ #include @@ -53,7 +53,7 @@ struct http_session *http_session_create() r->timestamp = 0; r->next = session_list; session_list = r; - r->timeout_iochan = iochan_create(-1, 0, session_timeout, 0); + r->timeout_iochan = iochan_create(-1, session_timeout, 0); iochan_setdata(r->timeout_iochan, r); iochan_settimeout(r->timeout_iochan, global_parameters.session_timeout); r->timeout_iochan->next = channel_list; diff --git a/src/pazpar2.c b/src/pazpar2.c index 79bc2ba..1fa0d0c 100644 --- a/src/pazpar2.c +++ b/src/pazpar2.c @@ -1,4 +1,4 @@ -/* $Id: pazpar2.c,v 1.66 2007-04-08 22:38:45 quinn Exp $ */ +/* $Id: pazpar2.c,v 1.67 2007-04-08 23:04:20 adam Exp $ */ #include #include @@ -1078,7 +1078,7 @@ static struct connection *connection_create(struct client *cl) cl->connection = new; new->link = link; - new->iochan = iochan_create(cs_fileno(link), 0, handler, 0); + new->iochan = iochan_create(cs_fileno(link), handler, 0); iochan_setdata(new->iochan, new); new->iochan->next = channel_list; channel_list = new->iochan; -- 1.7.10.4