* The code that handled session establishment via http-auth was also handling re...
authorArt Cancro <ajc@citadel.org>
Wed, 20 May 2009 17:07:21 +0000 (17:07 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 20 May 2009 17:07:21 +0000 (17:07 +0000)
* When re-establishing a session, use gotoroom() instead of explicitly doing a GOTO server command.  This causes the wc_view and other session data to be loaded properly.

webcit/auth.c
webcit/webcit.c
webcit/webcit.h

index 61d7ecc00db16599fab3e0a04c9a93a8d8549d74..8dfce2214e839c7422098e687df52ada03960bcf 100644 (file)
@@ -28,43 +28,6 @@ void initialize_axdefs(void) {
        axdefs[6] = _("Aide");          /* chief */
 }
 
-int ReEstablish_Session(void)
-{
-       StrBuf *Buf = NewStrBuf();
-       wcsession *WCC = WC;
-
-       serv_printf("USER %s", ChrPtr(WCC->Hdr->c_username));
-       StrBuf_ServGetln(Buf);
-       if (GetServerStatus(Buf, NULL) == 3) {
-               serv_printf("PASS %s", ChrPtr(WCC->Hdr->c_password));
-               StrBuf_ServGetln(Buf);
-               if (GetServerStatus(Buf, NULL) == 2) {
-                       become_logged_in(WCC->Hdr->c_username, 
-                                        WCC->Hdr->c_password, Buf);
-                       get_preference("default_header_charset", &WCC->DefaultCharset);
-               }
-       }
-       /*
-        * If we don't have a current room, but a cookie specifying the
-        * current room is supplied, make an effort to go there.
-        */
-       if ((StrLength(WCC->wc_roomname) == 0) && (StrLength(WCC->Hdr->c_roomname) > 0)) {
-               serv_printf("GOTO %s", 
-                           ChrPtr(WCC->Hdr->c_roomname));
-               StrBuf_ServGetln(Buf);
-               if (GetServerStatus(Buf, NULL) == 2) {
-                       if (WCC->wc_roomname == NULL) {
-                               WCC->wc_roomname = NewStrBufDup(WCC->Hdr->c_roomname);
-                       }
-                       else {
-                               FlushStrBuf(WCC->wc_roomname);
-                               StrBufAppendBuf(WCC->wc_roomname, WCC->Hdr->c_roomname, 0);
-                       }
-               }
-       }
-       FreeStrBuf(&Buf);
-       return 0;
-}
 
 
 /* 
index 4908d44f436f7a93b270d50f5b98142ed98b05ae..f3f91033700ca9f841349aa33f399695bf22d00d 100644 (file)
@@ -604,8 +604,8 @@ void session_loop(void)
 
 
        /*
-        * If we're not logged in, but we have HTTP Authentication data,
-        * try logging in to Citadel using that.
+        * If we're not logged in, but we have authentication data (either from
+        * a cookie or from http-auth), try logging in to Citadel using that.
         */
        if ((!WCC->logged_in)
            && (StrLength(WCC->Hdr->c_username) > 0)
@@ -634,24 +634,33 @@ void session_loop(void)
                (WCC->Hdr->eReqType != eHEAD);
 
        /*
-        * If we're not logged in, but we have username and password cookies
-        * supplied by the browser, try using them to log in.
+        * If a 'gotofirst' parameter has been specified, attempt to goto that room
+        * prior to doing anything else.
         */
-       if ((!WCC->logged_in)
-          && (StrLength(WCC->Hdr->c_username)>0)
-          && (StrLength(WCC->Hdr->c_password)>0)) {
-               ReEstablish_Session();
+       if (havebstr("gotofirst")) {
+               int ret;
+               ret = gotoroom(sbstr("gotofirst"));     /* do quietly to avoid session output! */
+               if ((ret/100) != 2) {
+                       lprintf(1, "GOTOFIRST: Unable to change to [%s]; Reason: %d\n",
+                               bstr("gotofirst"), ret);
+               }
        }
 
        /*
-        * If a 'gotofirst' parameter has been specified, attempt to goto that room
-        * prior to doing anything else.
+        * If we aren't in any room yet, but we have cookie data telling us where we're
+        * supposed to be, and 'gotofirst' was not specified, then go there.
         */
-       if (havebstr("gotofirst")) {
+       else if ( (StrLength(WCC->wc_roomname) == 0) && ( (StrLength(WCC->Hdr->c_roomname) > 0) )) {
+               lprintf(9, "We are in '%s' but cookie indicates '%s', going there...\n",
+                       ChrPtr(WCC->wc_roomname),
+                       ChrPtr(WCC->Hdr->c_roomname)
+               );
                int ret;
-               ret = gotoroom(sbstr("gotofirst"));     /* do this quietly to avoid session output! */
-               if (ret != 0)
-                       lprintf(1, "GOTOFIRST: Unable to change to [%s]; Reason: %d\n", bstr("gotofirst"), ret);
+               ret = gotoroom(WCC->Hdr->c_roomname);   /* do quietly to avoid session output! */
+               if ((ret/100) != 2) {
+                       lprintf(1, "COOKIEGOTO: Unable to change to [%s]; Reason: %d\n",
+                               ChrPtr(WCC->Hdr->c_roomname), ret);
+               }
        }
 
        if (WCC->Hdr->Handler != NULL) {
index cf085c2be3aee19b93a519f0ee5507b02406993d..074b4f8da307303f908a4fd294d7378206e69a1d 100644 (file)
@@ -717,9 +717,6 @@ void display_success(char *);
 void authorization_required(const char *message);
 void CheckAuthBasic(ParsedHttpHdrs *hdr);
 void GetAuthBasic(ParsedHttpHdrs *hdr);
-
-int ReEstablish_Session(void);
-
 void server_to_text(void);
 void save_edit(char *description, char *enter_cmd, int regoto);
 void display_edit(char *description, char *check_cmd,