* webserver.c, context_loop.c, webcit.c: add commandline args for host
authorNathan Bryant <loanshark@uncensored.citadel.org>
Fri, 4 Dec 1998 19:39:02 +0000 (19:39 +0000)
committerNathan Bryant <loanshark@uncensored.citadel.org>
Fri, 4 Dec 1998 19:39:02 +0000 (19:39 +0000)
          and port

webcit/ChangeLog
webcit/context_loop.c
webcit/webcit.c
webcit/webserver.c

index 81b7c071956b067819e3f8303659bd467e1bd5ca..717360d170609dbca3074928f7f562ea7b9d8879 100644 (file)
@@ -1,2 +1,6 @@
+1998-12-04 Nathan Bryant <bryant@cs.usm.maine.edu>
+       * webserver.c, context_loop.c, webcit.c: add commandline args for host
+         and port
+
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
index f26d1e6f443233caaf38e38ca8539c5d82ed2b5b..cda7e9a37ed485a7cdfb3028b9e372cc1afdbd89 100644 (file)
@@ -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 <stdlib.h>
@@ -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");
index 2029902a1721b723058bb4d0f4dfae7cddb3eb2e..dfd9865ff02a70d7cd64c87eecdc3d5b8b8f12f9 100644 (file)
@@ -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 <stdlib.h>
@@ -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 <session_id>\n", argv[0], argv[0]);
-               exit(1);
+       if (argc < 2 || argc > 4) {
+               fprintf(stderr,
+                       "webcit: usage: webcit <session_id> [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);
        }
index feea112ef1274b25ccbdc11525950614e83777fa..be892c32d455977579f8cd9104dd273c1976dc05 100644 (file)
@@ -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);