]> code.citadel.org Git - citadel.git/blobdiff - webcit/context_loop.c
* move some more vars from the session context to strbuf (the use of StrBufAppendTemp...
[citadel.git] / webcit / context_loop.c
index 0248c384f29d8e6c168aad5dbb60e90d54bad830..e0a816e1d351bb3b3e605fa09783807bf8d3b843 100644 (file)
@@ -43,6 +43,12 @@ void DestroySession(wcsession **sessions_to_kill)
        FreeStrBuf(&((*sessions_to_kill)->WBuf));
        FreeStrBuf(&((*sessions_to_kill)->HBuf));
        FreeStrBuf(&((*sessions_to_kill)->CLineBuf));
+       FreeStrBuf(&((*sessions_to_kill)->wc_username));
+       FreeStrBuf(&((*sessions_to_kill)->wc_fullname));
+       FreeStrBuf(&((*sessions_to_kill)->wc_password));
+       FreeStrBuf(&((*sessions_to_kill)->wc_roomname));
+       FreeStrBuf(&((*sessions_to_kill)->httpauth_user));
+       FreeStrBuf(&((*sessions_to_kill)->httpauth_pass));
        free((*sessions_to_kill));
        (*sessions_to_kill) = NULL;
 }
@@ -353,7 +359,7 @@ authentication
        if (GetHash(HTTPHeaders, HKEY("COOKIE"), &vLine) && 
            (vLine != NULL)) {
                cookie_to_stuff(vLine, &desired_session,
-                               NULL, 0, NULL, 0, NULL, 0);
+                               NULL, NULL, NULL);
                got_cookie = 1;
        }
 
@@ -471,8 +477,8 @@ authentication
 
                        /** If HTTP-AUTH, look for a session with matching credentials */
                        if ( (!IsEmptyStr(httpauth_user))
-                          &&(!strcasecmp(sptr->httpauth_user, httpauth_user))
-                          &&(!strcasecmp(sptr->httpauth_pass, httpauth_pass)) ) {
+                            &&(!strcasecmp(ChrPtr(sptr->httpauth_user), httpauth_user))
+                            &&(!strcasecmp(ChrPtr(sptr->httpauth_pass), httpauth_pass)) ) {
                                TheSession = sptr;
                        }
 
@@ -509,8 +515,17 @@ authentication
                        TheSession->wc_session = desired_session;
                }
 
-               strcpy(TheSession->httpauth_user, httpauth_user);
-               strcpy(TheSession->httpauth_pass, httpauth_pass);
+               if (TheSession->httpauth_user != NULL){
+                       FlushStrBuf(TheSession->httpauth_user);
+                       StrBufAppendBufPlain(TheSession->httpauth_user, httpauth_user, -1, 0);
+               }
+               else TheSession->httpauth_user = NewStrBufPlain(httpauth_user, -1);
+               if (TheSession->httpauth_user != NULL){
+                       FlushStrBuf(TheSession->httpauth_pass);
+                       StrBufAppendBufPlain(TheSession->httpauth_pass, httpauth_user, -1, 0);
+               }
+               else TheSession->httpauth_pass = NewStrBufPlain(httpauth_user, -1);
+
                TheSession->hash_prefs = NewHash(1,NULL);       /* Get a hash table for the user preferences */
                pthread_mutex_init(&TheSession->SessionMutex, NULL);
                pthread_mutex_lock(&SessionListMutex);
@@ -574,16 +589,30 @@ authentication
        
 }
 
-void tmpl_nonce(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void tmplput_nonce(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        StrBufAppendPrintf(Target, "%ld",
                           (WCC != NULL)? WCC->nonce:0);                   
 }
 
+void tmplput_current_user(StrBuf *Target, WCTemplputParams *TP)
+{
+       StrBufAppendTemplate(Target, TP, WC->wc_fullname, 0);
+}
+
+void tmplput_current_room(StrBuf *Target, WCTemplputParams *TP)
+{
+       StrBufAppendTemplate(Target, TP, WC->wc_roomname, 0); 
+}
+
+
+
 void 
 InitModule_CONTEXT
 (void)
 {
-       RegisterNamespace("NONCE", 0, 0, tmpl_nonce, 0);
+       RegisterNamespace("CURRENT_USER", 0, 1, tmplput_current_user, CTX_NONE);
+       RegisterNamespace("CURRENT_ROOM", 0, 1, tmplput_current_room, CTX_NONE);
+       RegisterNamespace("NONCE", 0, 0, tmplput_nonce, 0);
 }