* add way to have tokens do their custom parse-time preevaluation; this involves...
[citadel.git] / webcit / who.c
index 6be0e6c67431e35b9e87da8fd9accd19d53070a3..dec178110e8b0041c6f64bb5351450de830bf40d 100644 (file)
@@ -40,20 +40,17 @@ int CompareUserStruct(const void *VUser1, const void *VUser2)
 }
 
 
-int GetWholistSection(HashList *List, time_t now)
+int GetWholistSection(HashList *List, time_t now, StrBuf *Buf)
 {
-       StrBuf *Buf;
        wcsession *WCC = WC;
        UserStateStruct *User, *OldUser;
        void *VOldUser;
        size_t BufLen;
-       char buf[SIZ];
        const char *Pos;
 
        serv_puts("RWHO");
-       serv_getln(buf, sizeof buf);
-       if (buf[0] == '1') {
-               Buf = NewStrBuf();
+       StrBuf_ServGetln(Buf);
+       if (GetServerStatus(Buf, NULL) == 1) {
                while (BufLen = StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) {
                        if (BufLen <= 0)
                            continue;
@@ -107,12 +104,11 @@ int GetWholistSection(HashList *List, time_t now)
                                    User, DestroyUserStruct);
                }
                SortByPayload(List, CompareUserStruct);
-
-               FreeStrBuf(&Buf);
                return 1;
        }
-       else
+       else {
                return 0;
+       }
 }
 
 /*
@@ -216,21 +212,25 @@ void _terminate_session(void) {
 HashList *GetWholistHash(StrBuf *Target, WCTemplputParams *TP)
 
 {
+       StrBuf *Buf;
        HashList *List;
-       char buf[SIZ];
         time_t now;
 
+       Buf = NewStrBuf();
+
        serv_puts("TIME");
-       serv_getln(buf, sizeof buf);
-       if (buf[0] == '2') {
-               now = extract_long(&buf[4], 0);
+       StrBuf_ServGetln(Buf);
+       if (GetServerStatus(Buf, NULL)  == 2) {
+               const char *pos = ChrPtr(Buf) + 4;
+               now = StrBufExtractNext_long(Buf, &pos, '|');
        }
        else {
                now = time(NULL);
        }
 
        List = NewHash(1, NULL);
-       GetWholistSection(List, now);
+       GetWholistSection(List, now, Buf);
+       FreeStrBuf(&Buf);
        return List;
 }
 
@@ -321,21 +321,23 @@ void
 InitModule_WHO
 (void)
 {
+       
+
        WebcitAddUrlHandler(HKEY("terminate_session"), _terminate_session, 0);
        WebcitAddUrlHandler(HKEY("edit_me"), edit_me, 0);
 
        RegisterIterator("WHOLIST", 0, NULL, GetWholistHash, NULL, DeleteWholistHash, CTX_WHO, CTX_NONE, IT_NOFLAG);
 
-       RegisterNamespace("WHO:NAME",        0, 1, tmplput_who_username, CTX_WHO);
-       RegisterNamespace("WHO:ROOM",        0, 1, tmplput_who_room, CTX_WHO);
-       RegisterNamespace("WHO:HOST",        0, 1, tmplput_who_host, CTX_WHO);
-       RegisterNamespace("WHO:REALROOM",    0, 1, tmplput_who_realroom, CTX_WHO);
-       RegisterNamespace("WHO:REALHOST",    0, 1, tmplput_who_realhost, CTX_WHO);
-       RegisterNamespace("WHO:LASTACTIVE",  0, 1, tmplput_who_lastactive, CTX_WHO);
-       RegisterNamespace("WHO:IDLESINCE",   0, 1, tmplput_who_idlesince, CTX_WHO);
-       RegisterNamespace("WHO:SESSION",     0, 1, tmplput_who_session, CTX_WHO);
-       RegisterNamespace("WHO:NSESSIONS",   0, 1, tmplput_who_nsessions, CTX_WHO);
-       RegisterNamespace("WHO:NSESSIONS",   0, 1, tmplput_who_nsessions, CTX_WHO);
+       RegisterNamespace("WHO:NAME",        0, 1, tmplput_who_username, 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);
+       RegisterNamespace("WHO:REALHOST",    0, 1, tmplput_who_realhost, NULL, CTX_WHO);
+       RegisterNamespace("WHO:LASTACTIVE",  0, 1, tmplput_who_lastactive, NULL, CTX_WHO);
+       RegisterNamespace("WHO:IDLESINCE",   0, 1, tmplput_who_idlesince, NULL, CTX_WHO);
+       RegisterNamespace("WHO:SESSION",     0, 1, tmplput_who_session, NULL, CTX_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);