]> code.citadel.org Git - citadel.git/commitdiff
started on the static loader stuff
authorArt Cancro <ajc@citadel.org>
Tue, 24 Nov 1998 19:28:12 +0000 (19:28 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 24 Nov 1998 19:28:12 +0000 (19:28 +0000)
added pthread locking

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

index 9d9cf93750e04fffccf8335c76172075756e6571..814f1355a6f7b142817e8d09ee3ec6243b3dd7df 100644 (file)
@@ -33,6 +33,7 @@ struct wc_session {
        int session_id;                 /* Session ID */
        int inpipe[2];                  /* Data from webserver to session */
        int outpipe[2];                 /* Data from session to webserver */
+       pthread_mutex_t critter;        /* Critical section uses pipes */
        };
 
 struct wc_session *SessionList = NULL;
@@ -104,6 +105,7 @@ void *context_loop(int *socknumptr) {
                TheSession = (struct wc_session *)
                        malloc(sizeof(struct wc_session));
                TheSession->session_id = GenerateSessionID();
+               pthread_mutex_init(&TheSession->critter, NULL);
                pipe(TheSession->inpipe);
                pipe(TheSession->outpipe);
                TheSession->next = SessionList;
@@ -128,6 +130,7 @@ void *context_loop(int *socknumptr) {
        /* 
         * Send the request to the appropriate session
         */
+       pthread_mutex_lock(&TheSession->critter);
        for (a=0; a<num_lines; ++a) {
                write(TheSession->inpipe[1], &req[a][0], strlen(&req[a][0]));
                write(TheSession->inpipe[1], "\n", 1);
@@ -151,6 +154,8 @@ void *context_loop(int *socknumptr) {
                write(sock, buf, 1);
                }
 
+       pthread_mutex_unlock(&TheSession->critter);
+
        /*
         * Now our HTTP connection is done.  It would be relatively easy
         * to support HTTP/1.1 "persistent" connections by looping back to
index 3d057f84a1b35f7569771b5f630700dc158cd5d4..3a914ce094ffde31c2a83259c454379cbd15d234 100644 (file)
@@ -11,6 +11,7 @@
 #include <stdio.h>
 #include <ctype.h>
 #include <string.h>
+#include <errno.h>
 
 int wc_session;
 char wc_host[256];
@@ -39,35 +40,81 @@ void output_reconnect_cookies() {
                wc_roomname);
        }
 
+void output_static(char *what) {
+       char buf[256];
+       FILE *fp;
+
+       sprintf(buf, "static/%s", what);
+       fp = fopen(buf, "rb");
+       if (fp == NULL) {
+               printf("HTTP/1.0 404 %s\n", strerror(errno));
+               printf("Server: WebCit v2 (Velma)\n");
+               printf("Connection: close\n");
+               output_reconnect_cookies();
+               printf("Content-Type: text/plain\n");
+               sprintf(buf, "%s: %s\n", what, strerror(errno));
+               printf("Content-length: %d\n", strlen(buf));
+               printf("\n");
+               fwrite(buf, strlen(buf), 1, stdout);
+               }
+       else {
+               printf("HTTP/1.0 200 OK\n");
+               printf("Server: WebCit v2 (Velma)\n");
+               printf("Connection: close\n");
+               output_reconnect_cookies();
+               printf("Content-Type: text/plain\n");
+               printf("Content-length: 11\n");
+               printf("\n");
+               printf("Hi from IG\n");
+               fclose(fp);
+               }
+       }
+
+
 void session_loop() {
+       char cmd[256];
        char buf[256];
        char content[4096];
        static int TransactionCount = 0;
+       int a;
 
+       getz(cmd);
        do {
                getz(buf);
                } while(strlen(buf)>0);
 
-       printf("HTTP/1.0 200 OK\n");
-       printf("Server: WebCit v2 (Velma)\n");
-       printf("Connection: close\n");
-       output_reconnect_cookies();
-       printf("Content-Type: text/html\n");
-
-       strcpy(content, "");
-
-       sprintf(&content[strlen(content)],
-               "<HTML><HEAD><TITLE>WebCit</TITLE></HEAD><BODY>\n");
-       sprintf(&content[strlen(content)],
-               "TransactionCount is %d<HR>\n", ++TransactionCount);
-       sprintf(&content[strlen(content)],
-               "You're in session %d<BR>\n", wc_session);
-       sprintf(&content[strlen(content)],
-               "</BODY></HTML>\n");
-
-       printf("Content-length: %d\n", strlen(content));
-       printf("\n");
-       fwrite(content, strlen(content), 1, stdout);
+       fprintf(stderr, "Command: %s\n", cmd);
+       fflush(stderr);
+
+       if (!strncasecmp(cmd, "GET /static/", 12)) {
+               strcpy(buf, &cmd[12]);
+               for (a=0; a<strlen(buf); ++a) if (isspace(buf[a])) buf[a]=0;
+               output_static(buf);
+               }
+
+       else {
+               printf("HTTP/1.0 200 OK\n");
+               printf("Server: WebCit v2 (Velma)\n");
+               printf("Connection: close\n");
+               output_reconnect_cookies();
+               printf("Content-Type: text/html\n");
+       
+               strcpy(content, "");
+       
+               sprintf(&content[strlen(content)],
+                       "<HTML><HEAD><TITLE>WebCit</TITLE></HEAD><BODY>\n");
+               sprintf(&content[strlen(content)],
+                       "TransactionCount is %d<HR>\n", ++TransactionCount);
+               sprintf(&content[strlen(content)],
+                       "You're in session %d<BR>\n", wc_session);
+               sprintf(&content[strlen(content)],
+                       "</BODY></HTML>\n");
+       
+               printf("Content-length: %d\n", strlen(content));
+               printf("\n");
+               fwrite(content, strlen(content), 1, stdout);
+               }
+
        fflush(stdout);
        }
 
index 4ab8060faa0c714052fb0b9a058bd3326599ea7d..3948c8143a6d2ae6948c0c9e3c6bddb51dd17fd4 100644 (file)
@@ -26,7 +26,7 @@
 #include <pthread.h>
 
 #define SLEEPING       180                     /* TCP connection timeout */
-#define PORT_NUM       32766                   /* port number to listen on */
+#define PORT_NUM       32765                   /* port number to listen on */
 
 int msock;                                     /* master listening socket */
 extern void *context_loop(int);