]> code.citadel.org Git - citadel.git/blobdiff - webcit/webserver.c
* Brought over the newer string tokenizer from Citadel
[citadel.git] / webcit / webserver.c
index 4a478412449e2a0a03eddf7e5390d75372be7fb9..266cd692998c77e3b88cf1700b943888fd38c329 100644 (file)
@@ -48,7 +48,7 @@ extern pthread_mutex_t SessionListMutex;
 extern pthread_key_t MyConKey;
 
 
-
+char *server_cookie = NULL;
 
 
 char *defaulthost = DEFAULT_HOST;
@@ -170,7 +170,7 @@ int client_gets(int sock, char *buf)
                        retval = client_read(sock, &buf[i], 1);
 
        /*
-        * Strip any trailing not-printable characters.
+        * Strip any trailing non-printable characters.
         */
        buf[i] = 0;
        while ((strlen(buf) > 0) && (!isprint(buf[strlen(buf) - 1]))) {
@@ -228,7 +228,7 @@ int main(int argc, char **argv)
        char tracefile[PATH_MAX];
 
        /* Parse command line */
-       while ((a = getopt(argc, argv, "hp:t:")) != EOF)
+       while ((a = getopt(argc, argv, "hp:t:c")) != EOF)
                switch (a) {
                case 'p':
                        port = atoi(optarg);
@@ -239,9 +239,22 @@ int main(int argc, char **argv)
                        freopen(tracefile, "w", stderr);
                        freopen(tracefile, "r", stdin);
                        break;
+               case 'c':
+                       server_cookie = malloc(SIZ);
+                       if (server_cookie != NULL) {
+                               strcpy(server_cookie, "Set-cookie: wcserver=");
+                               if (gethostname(
+                                  &server_cookie[strlen(server_cookie)],
+                                  200) != 0) {
+                                       fprintf(stderr, "gethostname: %s\n",
+                                               strerror(errno));
+                                       free(server_cookie);
+                               }
+                       }
+                       break;
                default:
                        fprintf(stderr, "usage: webserver [-p localport] "
-                               "[-t tracefile] "
+                               "[-t tracefile] [-c] "
                                "[remotehost [remoteport]]\n");
                        return 1;
                }
@@ -253,7 +266,9 @@ int main(int argc, char **argv)
        }
        /* Tell 'em who's in da house */
        fprintf(stderr, SERVER "\n"
-               "Copyright (C) 1996-1999.  All rights reserved.\n\n");
+               "Copyright (C) 1996-2001\n"
+               "This software is distributed under the terms of the GNU\n"
+               "General Public License.  All other rights reserved.\n\n");
 
        if (chdir(WEBCITDIR) != 0)
                perror("chdir");
@@ -290,14 +305,13 @@ int main(int argc, char **argv)
 
 
        /* Start a few initial worker threads */
-       for (i=0; i<(INITIAL_WORKER_THREADS-1); ++i) {
+       for (i=0; i<(INITIAL_WORKER_THREADS); ++i) {
                spawn_another_worker_thread();
        }
 
-
-       /* now the original thread becomes an ordinary worker thread */
-       worker_entry();
+       /* now the original thread can go away. */
        pthread_exit(NULL);
+       return 0;
 }
 
 
@@ -333,7 +347,12 @@ void worker_entry(void) {
                        i = 1;
                        setsockopt(ssock, SOL_SOCKET, SO_REUSEADDR,
                                &i, sizeof(i));
+
+                       /* Perform an HTTP transaction... */
                        context_loop(ssock);
+
+                       /* ...and close the socket. */
+                       lingering_close(ssock);
                }
 
        } while (!time_to_die);