final touches on dkim test harness
[citadel.git] / webcit / who.c
index ac30cc72dd2e040fdc4d2ac212ea10bf692649fb..dee492caf8e641da9c5d82d3117318caa5b5edd8 100644 (file)
@@ -1,10 +1,13 @@
 
 #include "webcit.h"
 
+CtxType CTX_WHO = CTX_NONE;
+
 typedef struct UserStateStruct {
        StrBuf *UserName;
        StrBuf *Room;
        StrBuf *Host;
+       StrBuf *UserAgent;
        StrBuf *RealRoom;
        StrBuf *RealHost;
        long LastActive;
@@ -22,6 +25,7 @@ void DestroyUserStruct(void *vUser)
        FreeStrBuf(&User->Host);
        FreeStrBuf(&User->RealRoom);
        FreeStrBuf(&User->RealHost);
+       FreeStrBuf(&User->UserAgent);
        free(User);
 }
 
@@ -39,7 +43,6 @@ int CompareUserStruct(const void *VUser1, const void *VUser2)
 
 int GetWholistSection(HashList *List, time_t now, StrBuf *Buf, const char *FilterName, long FNLen)
 {
-       wcsession *WCC = WC;
        UserStateStruct *User, *OldUser;
        void *VOldUser;
        size_t BufLen;
@@ -67,7 +70,8 @@ int GetWholistSection(HashList *List, time_t now, StrBuf *Buf, const char *Filte
                        User->Host = NewStrBufPlain(NULL, BufLen);
                        StrBufExtract_NextToken(User->Host, Buf, &Pos, '|');
 
-                       StrBufSkip_NTokenS(Buf, &Pos, '|', 1);
+                       User->UserAgent = NewStrBufPlain(NULL, BufLen);
+                       StrBufExtract_NextToken(User->UserAgent, Buf, &Pos, '|');
 
                        User->LastActive = StrBufExtractNext_long(Buf, &Pos, '|');
                        StrBufSkip_NTokenS(Buf, &Pos, '|', 3);
@@ -89,7 +93,7 @@ int GetWholistSection(HashList *List, time_t now, StrBuf *Buf, const char *Filte
                                        OldUser = VOldUser;
                                        OldUser->SessionCount++;
                                        if (!User->Idle) {
-                                               if (User->Session == WCC->ctdl_pid) 
+                                               if (User->Session == WC->ctdl_pid) 
                                                        OldUser->Session = User->Session;
                                                
                                                OldUser->Idle = User->Idle;
@@ -137,34 +141,6 @@ void terminate_session(void)
 }
 
 
-/*
- * Change your session info (fake roomname and hostname)
- */
-void edit_me(void)
-{
-       char buf[SIZ];
-
-       output_headers(1, 0, 0, 0, 0, 0);
-       if (havebstr("change_room_name_button")) {
-               serv_printf("RCHG %s", bstr("fake_roomname"));
-               serv_getln(buf, sizeof buf);
-               do_template("who");
-       } else if (havebstr("change_host_name_button")) {
-               serv_printf("HCHG %s", bstr("fake_hostname"));
-               serv_getln(buf, sizeof buf);
-               do_template("who");
-       } else if (havebstr("change_user_name_button")) {
-               serv_printf("UCHG %s", bstr("fake_username"));
-               serv_getln(buf, sizeof buf);
-               do_template("who");
-       } else if (havebstr("cancel_button")) {
-               do_template("who");
-       } else {
-               do_template("who_edit");
-       }
-       end_burst();
-}
-
 void _terminate_session(void) {
        slrp_highest();
        terminate_session();
@@ -218,6 +194,12 @@ void tmplput_who_username(StrBuf *Target, WCTemplputParams *TP)
        StrBufAppendTemplate(Target, TP, User->UserName, 0);
 }
 
+void tmplput_who_UserAgent(StrBuf *Target, WCTemplputParams *TP)
+{
+       UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO);
+       StrBufAppendTemplate(Target, TP, User->UserAgent, 0);
+}
+
 void tmplput_who_room(StrBuf *Target, WCTemplputParams *TP)
 {
        UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO);
@@ -298,14 +280,14 @@ void
 InitModule_WHO
 (void)
 {
-       
+       RegisterCTX(CTX_WHO);
 
        WebcitAddUrlHandler(HKEY("terminate_session"), "", 0, _terminate_session, 0);
-       WebcitAddUrlHandler(HKEY("edit_me"), "", 0, edit_me, 0);
 
        RegisterIterator("WHOLIST", 1, NULL, GetWholistHash, NULL, DeleteWholistHash, CTX_WHO, CTX_NONE, IT_NOFLAG);
 
        RegisterNamespace("WHO:NAME",        0, 1, tmplput_who_username, NULL, CTX_WHO);
+       RegisterNamespace("WHO:USERAGENT",   0, 1, tmplput_who_UserAgent, NULL, CTX_WHO);
        RegisterNamespace("WHO:ROOM",        0, 1, tmplput_who_room, NULL, CTX_WHO);
        RegisterNamespace("WHO:HOST",        0, 1, tmplput_who_host, NULL, CTX_WHO);
        RegisterNamespace("WHO:REALROOM",    0, 1, tmplput_who_realroom, NULL, CTX_WHO);
@@ -316,9 +298,9 @@ InitModule_WHO
        RegisterNamespace("WHO:NSESSIONS",   0, 1, tmplput_who_nsessions, NULL, CTX_WHO);
        RegisterNamespace("WHO:NSESSIONS",   0, 1, tmplput_who_nsessions, NULL, CTX_WHO);
 
-       RegisterConditional(HKEY("WHO:IDLE"),      1, conditional_who_idle, CTX_WHO);
-       RegisterConditional(HKEY("WHO:NSESSIONS"), 1, conditional_who_nsessions, CTX_WHO);
-       RegisterConditional(HKEY("WHO:ISME"),      1, conditional_who_isme, CTX_WHO);
-       RegisterConditional(HKEY("WHO:REALROOM"),  1, conditional_who_realroom, CTX_WHO);
-       RegisterConditional(HKEY("WHO:REALHOST"),  1, conditional_who_realhost, CTX_WHO);
+       RegisterConditional("WHO:IDLE",      1, conditional_who_idle, CTX_WHO);
+       RegisterConditional("WHO:NSESSIONS", 1, conditional_who_nsessions, CTX_WHO);
+       RegisterConditional("WHO:ISME",      1, conditional_who_isme, CTX_WHO);
+       RegisterConditional("WHO:REALROOM",  1, conditional_who_realroom, CTX_WHO);
+       RegisterConditional("WHO:REALHOST",  1, conditional_who_realhost, CTX_WHO);
 }