From: Sebastian Hammer Date: Tue, 19 Dec 2006 04:49:34 +0000 (+0000) Subject: Added [host:]port syntax to -h to bind HTTP listener to specific local IP X-Git-Tag: before.append.child~98 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=f0fb67815fb47683e2c00a2dea706ac9258c927c;p=pazpar2-moved-to-github.git Added [host:]port syntax to -h to bind HTTP listener to specific local IP --- diff --git a/Makefile b/Makefile index 70f9404..b5eefb2 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # ParaZ. Copyright (C) 2000-2004, Index Data ApS # All rights reserved. -# $Id: Makefile,v 1.5 2006-12-08 22:21:36 quinn Exp $ +# $Id: Makefile,v 1.6 2006-12-19 04:49:34 quinn Exp $ SHELL=/bin/sh @@ -25,3 +25,21 @@ $(PROG): $(PROGO) clean: rm -f *.[oa] test core mon.out gmon.out errlist $(PROG) + +## Dependencies go below + +command.o: command.c command.h util.h eventl.h pazpar2.h termlists.h \ + relevance.h reclists.h +eventl.o: eventl.c eventl.h +http.o: http.c command.h util.h eventl.h pazpar2.h termlists.h \ + relevance.h reclists.h http.h http_command.h +http_command.o: http_command.c command.h util.h eventl.h pazpar2.h \ + termlists.h relevance.h reclists.h http.h http_command.h +pazpar2.o: pazpar2.c pazpar2.h termlists.h relevance.h reclists.h \ + eventl.h command.h http.h +reclists.o: reclists.c pazpar2.h termlists.h relevance.h reclists.h \ + eventl.h +relevance.o: relevance.c relevance.h pazpar2.h termlists.h eventl.h \ + reclists.h +termlists.o: termlists.c termlists.h +util.o: util.c diff --git a/http.c b/http.c index 93f7707..bf47090 100644 --- a/http.c +++ b/http.c @@ -1,5 +1,5 @@ /* - * $Id: http.c,v 1.5 2006-12-08 21:40:58 quinn Exp $ + * $Id: http.c,v 1.6 2006-12-19 04:49:34 quinn Exp $ */ #include @@ -761,16 +761,45 @@ static void http_accept(IOCHAN i, int event) channel_list = c; } -/* Create a http-channel listener */ -void http_init(int port) +/* Create a http-channel listener, syntax [host:]port */ +void http_init(const char *addr) { IOCHAN c; int l; struct protoent *p; struct sockaddr_in myaddr; int one = 1; + const char *pp; + int port; + + yaz_log(YLOG_LOG, "HTTP listener is %s", addr); + + bzero(&myaddr, sizeof myaddr); + myaddr.sin_family = AF_INET; + pp = strchr(addr, ':'); + if (pp) + { + int len = pp - addr; + char hostname[128]; + struct hostent *he; + + strncpy(hostname, addr, len); + hostname[len] = '\0'; + if (!(he = gethostbyname(hostname))) + { + yaz_log(YLOG_FATAL, "Unable to resolve '%s'", hostname); + exit(1); + } + memcpy(&myaddr.sin_addr.s_addr, he->h_addr_list[0], he->h_length); + port = atoi(pp + 1); + } + else + { + port = atoi(addr); + myaddr.sin_addr.s_addr = INADDR_ANY; + } + myaddr.sin_port = htons(port); - yaz_log(YLOG_LOG, "HTTP port is %d", port); if (!(p = getprotobyname("tcp"))) { abort(); } @@ -780,10 +809,6 @@ void http_init(int port) &one, sizeof(one)) < 0) abort(); - bzero(&myaddr, sizeof myaddr); - myaddr.sin_family = AF_INET; - myaddr.sin_addr.s_addr = INADDR_ANY; - myaddr.sin_port = htons(port); if (bind(l, (struct sockaddr *) &myaddr, sizeof myaddr) < 0) yaz_log(YLOG_FATAL|YLOG_ERRNO, "bind"); if (listen(l, SOMAXCONN) < 0) diff --git a/http.h b/http.h index d5b1d07..7501424 100644 --- a/http.h +++ b/http.h @@ -71,7 +71,7 @@ struct http_response }; void http_set_proxyaddr(char *url); -void http_init(int port); +void http_init(const char *addr); void http_addheader(struct http_response *r, const char *name, const char *value); char *http_argbyname(struct http_request *r, char *name); char *http_headerbyname(struct http_request *r, char *name); diff --git a/pazpar2.c b/pazpar2.c index d01a024..4105ba2 100644 --- a/pazpar2.c +++ b/pazpar2.c @@ -1,4 +1,4 @@ -/* $Id: pazpar2.c,v 1.16 2006-12-18 16:29:57 quinn Exp $ */; +/* $Id: pazpar2.c,v 1.17 2006-12-19 04:49:34 quinn Exp $ */; #include #include @@ -1336,7 +1336,7 @@ int main(int argc, char **argv) if (signal(SIGPIPE, SIG_IGN) < 0) yaz_log(YLOG_WARN|YLOG_ERRNO, "signal"); - yaz_log_init(YLOG_DEFAULT_LEVEL|YLOG_DEBUG, "pazpar2", 0); + yaz_log_init(YLOG_DEFAULT_LEVEL, "pazpar2", 0); while ((ret = options("c:h:p:C:s:", argv, argc, &arg)) != -2) { @@ -1346,7 +1346,7 @@ int main(int argc, char **argv) setport++; break; case 'h': - http_init(atoi(arg)); + http_init(arg); setport++; break; case 'C': @@ -1360,7 +1360,7 @@ int main(int argc, char **argv) break; default: fprintf(stderr, "Usage: pazpar2\n" - " -h httpport (REST)\n" + " -h [host:]port (REST protocol listener)\n" " -c cmdport (telnet-style)\n" " -C cclconfig\n" " -s simpletargetfile\n"