* serv_getln now is a wrapper around existing functionality. a new temporary var...
[citadel.git] / webcit / who.c
index 320ef01538701f61f988376210b9bc24c089bc45..1c19f775796badd2400a7fe9ed6315ced801cff6 100644 (file)
@@ -40,21 +40,18 @@ 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();
-               while (BufLen = StrBuf_ServGetlnBuffered(Buf), strcmp(ChrPtr(Buf), "000")) {
+       StrBuf_ServGetln(Buf);
+       if (GetServerStatus(Buf, NULL) == 1) {
+               while (BufLen = StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) {
                        if (BufLen <= 0)
                            continue;
                        Pos = NULL;
@@ -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;
 }