fix read_server_text; it was broken.
[citadel.git] / webcit / serv_func.c
index 14a4d655937151e456e1269cad7c6ea03d20fd22..a6c41f711e858a9ec61cc87c88570d2d3cba6450 100644 (file)
@@ -172,6 +172,7 @@ int GetConnected (void)
                WCC->serv_sock = tcp_connectsock(ctdlhost, ctdlport);
        
        if (WCC->serv_sock < 0) {
+               WCC->connected = 0;
                FreeStrBuf(&WCC->ReadBuf);
                return 1;
        }
@@ -257,12 +258,12 @@ int GetConnected (void)
  *  Read Citadel variformat text and spit it out as HTML.
  *  align html align string
  */
-inline void fmout(char *align)
+inline void fmout(const char *align)
 {
        _fmout(WC->WBuf, align);
 }
 
-void _fmout(StrBuf *Target, char *align)
+void _fmout(StrBuf *Target, const char *align)
 {
        int intext = 0;
        int bq = 0;
@@ -303,7 +304,7 @@ void _fmout(StrBuf *Target, char *align)
        wc_printf("</div><br>\n");
 }
 
-void FmOut(StrBuf *Target, char *align, StrBuf *Source)
+void FmOut(StrBuf *Target, const char *align, const StrBuf *Source)
 {
        const char *ptr, *pte;
        const char *BufPtr = NULL;
@@ -523,32 +524,41 @@ void server_to_text()
 int read_server_text(StrBuf *Buf, long *nLines)
 {
        wcsession *WCC = WC;
+       StrBuf *ReadBuf;
        long nRead;
        long nTotal = 0;
        long nlines;
        
        nlines = 0;
+       ReadBuf = NewStrBuf();
        while ((WCC->serv_sock!=-1) &&
-              (nRead = StrBuf_ServGetln(Buf), (nRead >= 0) ))
+              (nRead = StrBuf_ServGetln(ReadBuf), (nRead >= 0) &&
+               ((nRead != 3)||(strcmp(ChrPtr(ReadBuf), "000") != 0))))
        {
-               if (strcmp(ChrPtr(Buf) + nTotal, "000") != 0) {
-                       StrBufCutRight(Buf, nRead);
-                       break;
-               }
+               StrBufAppendBuf(Buf, ReadBuf, 0);
+               StrBufAppendBufPlain(Buf, HKEY("\n"), 0);
                nTotal += nRead;
                nlines ++;
        }
-
+       FreeStrBuf(&ReadBuf);
        *nLines = nlines;
        return nTotal;
 }
 
 
-int GetServerStatus(StrBuf *Line, long* FullState)
+int GetServerStatusMsg(StrBuf *Line, long* FullState, int PutImportantMessage, int MajorOK)
 {
+       int rc;
        if (FullState != NULL)
                *FullState = StrTol(Line);
-       return ChrPtr(Line)[0] - 48;
+       rc = ChrPtr(Line)[0] - 48;
+       if ((!PutImportantMessage) || 
+           (MajorOK == rc)||
+           (StrLength(Line) <= 4))
+               return rc;
+
+       AppendImportantMessage(ChrPtr(Line) + 4, StrLength(Line) - 4);
+       return rc;
 }