]> code.citadel.org Git - citadel.git/commitdiff
Got webcit-initiated session cleanups to work properly.
authorArt Cancro <ajc@citadel.org>
Fri, 4 Dec 1998 04:01:48 +0000 (04:01 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 4 Dec 1998 04:01:48 +0000 (04:01 +0000)
webcit/auth.c
webcit/context_loop.c
webcit/mainmenu.c
webcit/static/login.html [deleted file]
webcit/webcit.c
webcit/webserver.c

index f48a44d414f2267d17843aa666c2efe5e3d2199e..cd234ad2c3b34faa9ff2a49af11975aeadc6d388 100644 (file)
 #include "webcit.h"
 
 
+
+/*
+ * Display the login screen
+ */
+void display_login() {
+       char buf[256];
+
+       printf("HTTP/1.0 200 OK\n");
+       output_headers();
+
+       wprintf("<HTML><BODY>\n");
+       wprintf("<CENTER><TABLE border=0><TR><TD>\n");
+
+       /* FIX replace with the correct image */
+       wprintf("<IMG SRC=\"/static/velma.gif\">");
+       wprintf("</TD><TD><CENTER>\n");
+
+       serv_puts("MESG hello");
+       serv_gets(buf);
+       if (buf[0]=='1') fmout(NULL);
+
+       wprintf("</CENTER></TD></TR></TABLE></CENTER>\n");
+
+       wprintf("<HR>\n");
+       /* FIX add instructions here */
+       wprintf("<CENTER><FORM ACTION=\"/login\" METHOD=\"POST\">\n");
+       wprintf("<TABLE border><TR>\n");
+       wprintf("<TD>User Name:</TD>\n");
+       wprintf("<TD><INPUT TYPE=\"text\" NAME=\"name\" MAXLENGTH=\"25\">\n");
+       wprintf("</TD></TR><TR>\n");
+       wprintf("<TD>Password:</TD>\n");
+       wprintf("<TD><INPUT TYPE=\"password\" NAME=\"pass\" MAXLENGTH=\"20\"></TD>\n");
+       wprintf("</TR></TABLE>\n");
+       wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Login\">\n");
+        wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"New User\">\n");
+        wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Exit\">\n");
+        wprintf("</FORM></CENTER>\n");
+       wprintf("</BODY></HTML>\n");
+       wDumpContent();
+       }
+
+
+
+
 /*
  * This function needs to get called whenever a PASS or NEWU succeeds
  */
@@ -69,3 +113,31 @@ void do_welcome() {
        wprintf("</BODY></HTML>\n");
        wDumpContent();
        }
+
+
+void do_logout() {
+       char buf[256];
+
+       strcpy(wc_username, "");
+       strcpy(wc_password, "");
+       strcpy(wc_roomname, "");
+       strcpy(wc_host, "");
+       strcpy(wc_port, "");
+
+       printf("HTTP/1.0 200 OK\n");
+       output_headers();
+       printf("X-WebCit-Session: close\n");
+       
+       wprintf("<HTML><HEAD><TITLE>Goodbye</TITLE></HEAD><BODY><CENTER>\n");
+
+       serv_puts("MESG goodbye");
+       serv_gets(buf);
+
+       if (buf[0]=='1') fmout(NULL);
+       else wprintf("Goodbye\n");
+
+       wprintf("</CENTER></BODY></HTML>\n");
+       wDumpContent();
+       serv_puts("QUIT");
+       exit(0);
+       }
index 1f8f4caed6f782c359efc45b13756cff5d2afa9e..f26d1e6f443233caaf38e38ca8539c5d82ed2b5b 100644 (file)
@@ -38,6 +38,9 @@ struct wc_session {
 
 struct wc_session *SessionList = NULL;
 
+/* Only one thread may manipulate SessionList at a time... */
+pthread_mutex_t MasterCritter;
+
 int GenerateSessionID() {
        return getpid();
        }
@@ -92,6 +95,7 @@ void *context_loop(int sock) {
        struct wc_session *sptr;
        struct wc_session *TheSession;
        int ContentLength;
+       int CloseSession = 0;
 
        printf("Reading request from socket %d\n", sock);
 
@@ -115,11 +119,13 @@ void *context_loop(int sock) {
         */
        TheSession = NULL;
        if (desired_session != 0) {
+               pthread_mutex_lock(&MasterCritter);
                for (sptr=SessionList; sptr!=NULL; sptr=sptr->next) {
                        if (sptr->session_id == desired_session) {
                                TheSession = sptr;
                                }
                        }
+               pthread_mutex_unlock(&MasterCritter);
                }
 
        /*
@@ -127,6 +133,7 @@ void *context_loop(int sock) {
         */
        if (TheSession == NULL) {
                printf("Creating a new session\n");
+               pthread_mutex_lock(&MasterCritter);
                TheSession = (struct wc_session *)
                        malloc(sizeof(struct wc_session));
                TheSession->session_id = GenerateSessionID();
@@ -151,6 +158,7 @@ void *context_loop(int sock) {
                        printf("<BODY>execlp() failed</BODY></HTML>\n");
                        exit(0);
                        }
+               pthread_mutex_unlock(&MasterCritter);
                }
 
        /*
@@ -187,6 +195,9 @@ void *context_loop(int sock) {
                write(sock, "\n", 1);
                if (!strncasecmp(buf, "Content-length: ", 16))
                        ContentLength = atoi(&buf[16]);
+               if (!strcasecmp(buf, "X-WebCit-Session: close")) {
+                       CloseSession = 1;
+                       }
                } while (strlen(buf) > 0);
 
        printf("   Reading %d bytes of content\n");
@@ -209,6 +220,34 @@ void *context_loop(int sock) {
        printf("Unlocking.\n");
        pthread_mutex_unlock(&TheSession->critter);
 
+
+
+       /*
+        * If the last response included a "close session" directive,
+        * remove the context now.
+        */
+       if (CloseSession) {
+               printf("Removing session.\n");
+               pthread_mutex_lock(&MasterCritter);
+
+               if (SessionList==TheSession) {
+                       SessionList = SessionList->next;
+                       }
+               else {
+                       for (sptr=SessionList; sptr!=NULL; sptr=sptr->next) {
+                               if (sptr->next == TheSession) {
+                                       sptr->next = TheSession->next;
+                                       }
+                               }
+                       }
+       
+               free(TheSession);
+       
+               pthread_mutex_unlock(&MasterCritter);
+               }
+
+
+
        /*
         * The thread handling this HTTP connection is now finished.
         */
index 0ead5a93b65e7cd8551ab33872eee8883a38253e..c4e950c38e88aff612b4e9130dff17446cd069d4 100644 (file)
@@ -62,7 +62,7 @@ void embed_main_menu() {
        wprintf("<LI><B><A HREF=\"/advanced\">\n");
        wprintf("Advanced options</B></A><BR>...and maintenance</LI>\n");
 
-       wprintf("<LI><B><A HREF=\"/termquit\">\n");
+       wprintf("<LI><B><A HREF=\"/termquit\" TARGET=\"_top\">\n");
        wprintf("Log off</B></A><BR>Bye!</LI>\n");
        wprintf("</UL>\n");
 
diff --git a/webcit/static/login.html b/webcit/static/login.html
deleted file mode 100644 (file)
index a55cb9d..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-<HTML><BODY>
-<TABLE border=0><TR>
-       <TD><IMG SRC="/static/velma.gif"></TD>
-       <TD><H1>&quot;Velma&quot;
-       </H1><H2>(next generation WebCit)</H2>
-       Please log in...<BR>
-       <FORM ACTION="/login" METHOD="POST">
-       <TABLE border><TR>
-               <TD>User Name:</TD>
-               <TD><INPUT TYPE="text" NAME="name" MAXLENGTH="25"></TD>
-               </TR><TR>
-               <TD>Password:</TD>
-               <TD><INPUT TYPE="password" NAME="pass" MAXLENGTH="20"></TD>
-               </TR>
-       </TABLE>
-
-       <INPUT type="submit" NAME="action" VALUE="Login">
-        <INPUT type="submit" NAME="action" VALUE="New User">
-        <INPUT type="submit" NAME="action" VALUE="Exit">
-        </FORM>
-
-</TD></TR></TABLE>
-</BODY></HTML>
index 95a7146993db92a991f916637a106e5d7de9684b..2029902a1721b723058bb4d0f4dfae7cddb3eb2e 100644 (file)
@@ -459,7 +459,7 @@ void session_loop() {
                }
 
        else if (!logged_in) {
-               output_static("login.html");
+               display_login();
                }
 
        /* Various commands... */
@@ -502,18 +502,8 @@ void session_loop() {
                dotgoto();
                }
 
-       else if (!strncasecmp(cmd, "GET /test", 9)) {
-               printf("HTTP/1.0 200 OK\n");
-               output_headers();
-       
-               wprintf("<HTML><BODY>\n");
-               wprintf("<H1>diagnostic page</H1>\n");
-               wprintf("TransactionCount is %d<HR>\n", TransactionCount);
-               wprintf("You're in session %d<BR>\n", wc_session);
-               wprintf("Logged in as <em>"); escputs(wc_username);
-               wprintf("</em><BR>\n");
-               wprintf("</BODY></HTML>\n");
-               wDumpContent();
+       else if (!strncasecmp(cmd, "GET /termquit", 13)) {
+               do_logout();
                }
 
        /* When all else fails... */
index f3246ff5bd8860223c1d470afdba90ab649b3975..80bd0c2c584889f0f14133a44f3e342959e2a8ef 100644 (file)
@@ -28,6 +28,7 @@
 
 int msock;                                     /* master listening socket */
 extern void *context_loop(int);
+extern pthread_mutex_t MasterCritter;
 
 /*
  * This is a generic function to set up a master socket for listening on
@@ -247,6 +248,8 @@ int main(int argc, char **argv)
        msock = ig_tcp_server(PORT_NUM, 5);
        printf("Listening on socket %d\n", msock);
 
+       pthread_mutex_init(&MasterCritter, NULL);
+
        /* 
         * Endless loop.  Listen on the master socket.  When a connection
         * comes in, create a socket, a context, and a thread.