From: Nathan Bryant Date: Fri, 4 Dec 1998 19:39:02 +0000 (+0000) Subject: * webserver.c, context_loop.c, webcit.c: add commandline args for host X-Git-Tag: v7.86~8065 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=97c1253a62acb5a06ca5248ea621628a57a6fb62;p=citadel.git * webserver.c, context_loop.c, webcit.c: add commandline args for host and port --- diff --git a/webcit/ChangeLog b/webcit/ChangeLog index 81b7c0719..717360d17 100644 --- a/webcit/ChangeLog +++ b/webcit/ChangeLog @@ -1,2 +1,6 @@ +1998-12-04 Nathan Bryant + * webserver.c, context_loop.c, webcit.c: add commandline args for host + and port + 1998-12-03 Nathan Bryant * webserver.c: warning fix diff --git a/webcit/context_loop.c b/webcit/context_loop.c index f26d1e6f4..cda7e9a37 100644 --- a/webcit/context_loop.c +++ b/webcit/context_loop.c @@ -5,6 +5,8 @@ * up HTTP requests with the session they belong to, using HTTP cookies to * keep track of things. If the HTTP request doesn't belong to any currently * active session, a new session is spawned. + * + * $Id$ */ #include @@ -80,6 +82,8 @@ void req_gets(int sock, char *buf, char *hold) { } } +extern const char *defaulthost; +extern const char *defaultport; /* * This loop gets called once for every HTTP connection made to WebCit. @@ -148,7 +152,8 @@ void *context_loop(int sock) { if (f==0) { dup2(TheSession->inpipe[0], 0); dup2(TheSession->outpipe[1], 1); - execlp("./webcit", "webcit", str_session, NULL); + execlp("./webcit", "webcit", str_session, defaulthost, + defaultport, NULL); printf("HTTP/1.0 404 WebCit Failure\n\n"); printf("Server: %s\n", SERVER); printf("Content-type: text/html\n"); diff --git a/webcit/webcit.c b/webcit/webcit.c index 2029902a1..dfd9865ff 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -4,6 +4,8 @@ * This is the actual program called by the webserver. It maintains a * persistent session to the Citadel server, handling HTTP WebCit requests as * they arrive and presenting a user interface. + * + * $Id$ */ #include @@ -340,6 +342,8 @@ void output_static(char *what) { } } +static const char *defaulthost = DEFAULT_HOST; +static const char *defaultport = DEFAULT_PORT; void session_loop() { char cmd[256]; @@ -357,8 +361,8 @@ void session_loop() { char c_password[256]; char c_roomname[256]; - strcpy(c_host, DEFAULT_HOST); - strcpy(c_port, DEFAULT_PORT); + strcpy(c_host, defaulthost); + strcpy(c_port, defaultport); strcpy(c_username, ""); strcpy(c_password, ""); strcpy(c_roomname, ""); @@ -526,16 +530,22 @@ void session_loop() { free_urls(); } - - int main(int argc, char *argv[]) { - if (argc != 2) { - printf("%s: usage: %s \n", argv[0], argv[0]); - exit(1); + if (argc < 2 || argc > 4) { + fprintf(stderr, + "webcit: usage: webcit [host [port]]\n"); + return 1; } wc_session = atoi(argv[1]); + + if (argc > 2) { + defaulthost = argv[2]; + if (argc > 3) + defaultport = argv[3]; + } + strcpy(wc_host, ""); strcpy(wc_port, ""); strcpy(wc_username, ""); @@ -545,6 +555,4 @@ int main(int argc, char *argv[]) { while (1) { session_loop(); } - - exit(0); } diff --git a/webcit/webserver.c b/webcit/webserver.c index feea112ef..be892c32d 100644 --- a/webcit/webserver.c +++ b/webcit/webserver.c @@ -221,6 +221,8 @@ void redirect(char *url) { printf("Location: %s\n\n", url); } +const char *defaulthost = DEFAULT_HOST; +const char *defaultport = DEFAULT_PORT; /* * Here's where it all begins. @@ -233,7 +235,26 @@ int main(int argc, char **argv) pthread_t SessThread; /* Thread descriptor */ pthread_attr_t attr; /* Thread attributes */ int a, i; /* General-purpose variables */ + int port = PORT_NUM; /* Port to listen on */ char convbuf[128]; + + /* Parse command line */ + while ((a = getopt(argc, argv, "hp:")) != EOF) + switch (a) { + case 'p': + port = atoi(optarg); + break; + default: + fprintf(stderr, "usage: webserver [-p localport] " + "[remotehost [remoteport]]\n"); + return 1; + } + + if (optind < argc) { + defaulthost = argv[optind]; + if (++optind < argc) + defaultport = argv[optind]; + } /* Tell 'em who's in da house */ printf("WebCit v2 experimental\n"); @@ -245,8 +266,8 @@ int main(int argc, char **argv) * There is no need to check for errors, because ig_tcp_server() * exits if it doesn't succeed. */ - printf("Attempting to bind to port %d...\n", PORT_NUM); - msock = ig_tcp_server(PORT_NUM, 5); + printf("Attempting to bind to port %d...\n", port); + msock = ig_tcp_server(port, 5); printf("Listening on socket %d\n", msock); pthread_mutex_init(&MasterCritter, NULL);