*/
/*
- * $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.
*/
#include <cconfig.h>
#endif
-
+#ifdef WIN32
+#include <winsock.h>
+#else
+#include <unistd.h>
+#endif
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <yaz/log.h>
#include <yaz/comstack.h>
#include <yaz/xmalloc.h>
-#include <yaz/statserv.h>
-
#include "eventl.h"
+#include <yaz/statserv.h>
-
-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;
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;
* 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
*
#include <time.h>
-#ifdef WIN32
-#include <winsock.h>
-#else
-#include <unistd.h>
-#include <arpa/inet.h>
-#endif
-
-
struct iochan;
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
#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
/*
- * $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 <stdio.h>
#endif
#include <netinet/in.h>
+#include <arpa/inet.h>
#include <netdb.h>
#include <yaz/yaz-util.h>
#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;
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;
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);
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;
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;
}
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);
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;
}
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
/*
- * $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 <stdio.h>
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;
-/* $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 <stdlib.h>
#include <stdio.h>
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;