* serv_getln now is a wrapper around existing functionality. a new temporary var...
[citadel.git] / webcit / serv_func.c
index 6b36860f4cd520283c71e99896b0ec7c05f8f875..7dbc16c940d10037122e841f8e2df9d115492a78 100644 (file)
@@ -8,6 +8,8 @@
 
 void DeleteServInfo(ServInfo **FreeMe)
 {
+       if (*FreeMe == NULL)
+               return;
        FreeStrBuf(&(*FreeMe)->serv_nodename);
        FreeStrBuf(&(*FreeMe)->serv_humannode);
        FreeStrBuf(&(*FreeMe)->serv_fqdn);
@@ -168,7 +170,7 @@ void _fmout(StrBuf *Target, char *align)
                /** Activate embedded URL's */
                url(buf, sizeof(buf));
 
-               escputs(buf);/*/ TODO: Target */
+               escputs(buf);
                StrBufAppendBufPlain(Target, HKEY("\n"), 0);
        }
        if (bq == 1) {
@@ -190,7 +192,7 @@ void FmOut(StrBuf *Target, char *align, StrBuf *Source)
        long len;
        int intext = 0;
 
-       StrBufAppendPrintf(Target, "<div class=\"fmout\">\n", align);
+       StrBufAppendPrintf(Target, "<div class=\"fmout-%s\">\n", align);
        while ((n = StrBufSipLine(Line, Source, &BufPtr), n >= 0) && !done)
        {
                done = n == 0;
@@ -436,14 +438,12 @@ void server_to_text()
  * server READ commands.
  * \return the read content as StrBuf
  */
-int read_server_binary(StrBuf *Ret, size_t total_len) 
+int read_server_binary(StrBuf *Ret, size_t total_len, StrBuf *Buf
 {
        char buf[SIZ];
        size_t bytes = 0;
        size_t thisblock = 0;
-       StrBuf *Buf;
        
-       Buf = NewStrBuf();
        if (Ret == NULL)
            return -1;
 
@@ -462,14 +462,14 @@ int read_server_binary(StrBuf *Ret, size_t total_len)
                {
                        if (GetServerStatus(Buf, NULL) == 6)
                        {
-                           StrBufCutLeft(Buf, 4); /*/ TODO : thisblock = (size_t)atoi(&buf[4]); */
+                           StrBufCutLeft(Buf, 4);
                            thisblock = StrTol(Buf);
                            if (!WC->connected) {
                                    FlushStrBuf(Ret); 
                                    FreeStrBuf(&Buf); 
                                    return -1; 
                            }
-                           StrBuf_ServGetBLOB(Ret, thisblock);
+                           StrBuf_ServGetBLOBBuffered(Ret, thisblock);
                            bytes += thisblock;
                    }
                    else {
@@ -479,7 +479,6 @@ int read_server_binary(StrBuf *Ret, size_t total_len)
                    }
                }
        }
-       FreeStrBuf(&Buf);
        return StrLength(Ret);
 }
 
@@ -532,41 +531,65 @@ void tmplput_serv_ip(StrBuf *Target, WCTemplputParams *TP)
 
 void tmplput_serv_nodename(StrBuf *Target, WCTemplputParams *TP)
 {
-       StrBufAppendTemplate(Target, TP, WC->serv_info->serv_nodename, 0);
+       wcsession *WCC = WC;
+       if (WCC->serv_info == NULL)
+               return;
+       StrBufAppendTemplate(Target, TP, WCC->serv_info->serv_nodename, 0);
 }
 
 void tmplput_serv_humannode(StrBuf *Target, WCTemplputParams *TP)
 {
-       StrBufAppendTemplate(Target, TP, WC->serv_info->serv_humannode, 0);
+       wcsession *WCC = WC;
+       if (WCC->serv_info == NULL)
+               return;
+       StrBufAppendTemplate(Target, TP, WCC->serv_info->serv_humannode, 0);
 }
 
 void tmplput_serv_fqdn(StrBuf *Target, WCTemplputParams *TP)
 {
-       StrBufAppendTemplate(Target, TP, WC->serv_info->serv_fqdn, 0);
+       wcsession *WCC = WC;
+       if (WCC->serv_info == NULL)
+               return;
+       StrBufAppendTemplate(Target, TP, WCC->serv_info->serv_fqdn, 0);
 }
 
 void tmplput_serv_software(StrBuf *Target, WCTemplputParams *TP)
 {
-       StrBufAppendTemplate(Target, TP, WC->serv_info->serv_software, 0);
+       wcsession *WCC = WC;
+       if (WCC->serv_info == NULL)
+               return;
+       StrBufAppendTemplate(Target, TP, WCC->serv_info->serv_software, 0);
 }
 
 void tmplput_serv_rev_level(StrBuf *Target, WCTemplputParams *TP)
 {
+       wcsession *WCC = WC;
+       if (WCC->serv_info == NULL)
+               return;
        StrBufAppendPrintf(Target, "%d.%02d",
-                           WC->serv_info->serv_rev_level / 100,
-                           WC->serv_info->serv_rev_level % 100);
+                           WCC->serv_info->serv_rev_level / 100,
+                           WCC->serv_info->serv_rev_level % 100);
 }
 int conditional_serv_newuser_disabled(StrBuf *Target, WCTemplputParams *TP)
 {
-       return WC->serv_info->serv_newuser_disabled != 0;
+       wcsession *WCC = WC;
+       if (WCC->serv_info == NULL)
+               return 0;
+       return WCC->serv_info->serv_newuser_disabled != 0;
 }
 int conditional_serv_supports_openid(StrBuf *Target, WCTemplputParams *TP)
 {
-       return WC->serv_info->serv_supports_openid != 0;
+       wcsession *WCC = WC;
+       if (WCC->serv_info == NULL)
+               return 0;
+       return WCC->serv_info->serv_supports_openid != 0;
 }
 
 void tmplput_serv_bbs_city(StrBuf *Target, WCTemplputParams *TP)
 {
+       wcsession *WCC = WC;
+       if (WCC->serv_info == NULL)
+               return;
        StrBufAppendTemplate(Target, TP, WC->serv_info->serv_bbs_city, 0);
 }
 
@@ -581,22 +604,26 @@ void tmplput_mesg(StrBuf *Target, WCTemplputParams *TP)
        Buf = NewStrBuf();
        Line = NewStrBuf();
        serv_printf("MESG %s", TP->Tokens->Params[0]->Start);
+
        StrBuf_ServGetln(Line);
-       while (!Done &&  (StrBuf_ServGetln(Line)>=0)) {
-               if ( (StrLength(Line)==3) && 
-                   !strcmp(ChrPtr(Line), "000")) 
-                       Done = 1;
-               else
-               {
-                       if (n > 0)
-                               StrBufAppendBufPlain(Buf, "\n", 1, 0);
-                       StrBufAppendBuf(Buf, Line, 0);
+       if (GetServerStatus(Line, NULL) == 1) {
+               while (!Done &&  (StrBuf_ServGetln(Line)>=0)) {
+                       if ( (StrLength(Line)==3) && 
+                            !strcmp(ChrPtr(Line), "000")) 
+                               Done = 1;
+                       else
+                       {
+                               if (n > 0)
+                                       StrBufAppendBufPlain(Buf, "\n", 1, 0);
+                               StrBufAppendBuf(Buf, Line, 0);
+                       }
+                       n++;
                }
-               n++;
+       
+               FlushStrBuf(Line);
+               FmOut(Line, "center", Buf);
+               StrBufAppendTemplate(Target, TP, Line, 1);
        }
-       FlushStrBuf(Line);
-       FmOut(Line, "center", Buf);
-       StrBufAppendTemplate(Target, TP, Line, 1);
        FreeStrBuf(&Buf);
        FreeStrBuf(&Line);
 }