]> code.citadel.org Git - citadel.git/blobdiff - webcit/serv_func.c
* serv_getln now is a wrapper around existing functionality. a new temporary var...
[citadel.git] / webcit / serv_func.c
index 0e25c28d9d8c2f9cc3593d0b91febfe90728c2e9..7dbc16c940d10037122e841f8e2df9d115492a78 100644 (file)
@@ -5,26 +5,44 @@
 #include "webcit.h"
 #include "webserver.h"
 
-struct serv_info serv_info; /**< our connection data to the server */
+
+void DeleteServInfo(ServInfo **FreeMe)
+{
+       if (*FreeMe == NULL)
+               return;
+       FreeStrBuf(&(*FreeMe)->serv_nodename);
+       FreeStrBuf(&(*FreeMe)->serv_humannode);
+       FreeStrBuf(&(*FreeMe)->serv_fqdn);
+       FreeStrBuf(&(*FreeMe)->serv_software);
+       FreeStrBuf(&(*FreeMe)->serv_bbs_city);
+       FreeStrBuf(&(*FreeMe)->serv_sysadm);
+       FreeStrBuf(&(*FreeMe)->serv_moreprompt);
+       FreeStrBuf(&(*FreeMe)->serv_default_cal_zone);
+       FreeStrBuf(&(*FreeMe)->serv_svn_revision);
+       free(*FreeMe);
+       *FreeMe = NULL;
+}
+
 /*
  * get info about the server we've connected to
  *
  * browser_host                the citadell we want to connect to
  * user_agent          which browser uses our client?
  */
-void get_serv_info(char *browser_host, char *user_agent)
+ServInfo *get_serv_info(StrBuf *browser_host, char *user_agent)
 {
+       ServInfo *info;
        StrBuf *Buf;
        char buf[SIZ];
        int a;
 
        /** Tell the server what kind of client is connecting */
        serv_printf("IDEN %d|%d|%d|%s|%s",
-               DEVELOPER_ID,
-               CLIENT_ID,
-               CLIENT_VERSION,
-               user_agent,
-               browser_host
+                   DEVELOPER_ID,
+                   CLIENT_ID,
+                   CLIENT_VERSION,
+                   user_agent,
+                   ChrPtr(browser_host)
        );
        serv_getln(buf, sizeof buf);
 
@@ -44,65 +62,69 @@ void get_serv_info(char *browser_host, char *user_agent)
        serv_puts("INFO");
        serv_getln(buf, sizeof buf);
        if (buf[0] != '1')
-               return;
+               return NULL;
 
+       info = (ServInfo*)malloc(sizeof(ServInfo));
+       memset(info, 0, sizeof(ServInfo));
        a = 0;
        Buf = NewStrBuf();
        while (StrBuf_ServGetln(Buf), (strcmp(ChrPtr(Buf), "000")!= 0)) {
 /*             lprintf (1, "a: %d [%s]", a, ChrPtr(Buf));*/
                switch (a) {
                case 0:
-                       serv_info.serv_pid = StrToi(Buf);
-                       WC->ctdl_pid = serv_info.serv_pid;
+                       info->serv_pid = StrToi(Buf);
+                       WC->ctdl_pid = info->serv_pid;
                        break;
                case 1:
-                       serv_info.serv_nodename = NewStrBufDup(Buf);
+                       info->serv_nodename = NewStrBufDup(Buf);
                        break;
                case 2:
-                       serv_info.serv_humannode = NewStrBufDup(Buf);
+                       info->serv_humannode = NewStrBufDup(Buf);
                        break;
                case 3:
-                       serv_info.serv_fqdn = NewStrBufDup(Buf);
+                       info->serv_fqdn = NewStrBufDup(Buf);
                        break;
                case 4:
-                       serv_info.serv_software = NewStrBufDup(Buf);
+                       info->serv_software = NewStrBufDup(Buf);
                        break;
                case 5:
-                       serv_info.serv_rev_level = StrToi(Buf);
+                       info->serv_rev_level = StrToi(Buf);
                        break;
                case 6:
-                       serv_info.serv_bbs_city = NewStrBufDup(Buf);
+                       info->serv_bbs_city = NewStrBufDup(Buf);
                        break;
                case 7:
-                       serv_info.serv_sysadm = NewStrBufDup(Buf);
+                       info->serv_sysadm = NewStrBufDup(Buf);
                        break;
                case 9:
-                       serv_info.serv_moreprompt = NewStrBufDup(Buf);
+                       info->serv_moreprompt = NewStrBufDup(Buf);
                        break;
                case 14:
-                       serv_info.serv_supports_ldap = StrToi(Buf);
+                       info->serv_supports_ldap = StrToi(Buf);
                        break;
                case 15:
-                       serv_info.serv_newuser_disabled = StrToi(Buf);
+                       info->serv_newuser_disabled = StrToi(Buf);
                        break;
                case 16:
-                       serv_info.serv_default_cal_zone = NewStrBufDup(Buf);
+                       info->serv_default_cal_zone = NewStrBufDup(Buf);
                        break;
                case 20:
-                       serv_info.serv_supports_sieve = StrToi(Buf);
+                       info->serv_supports_sieve = StrToi(Buf);
                        break;
                case 21:
-                       serv_info.serv_fulltext_enabled = StrToi(Buf);
+                       info->serv_fulltext_enabled = StrToi(Buf);
                        break;
                case 22:
-                       serv_info.serv_svn_revision = NewStrBufDup(Buf);
+                       info->serv_svn_revision = NewStrBufDup(Buf);
                        break;
                case 23:
-                       serv_info.serv_supports_openid = StrToi(Buf);
+                       info->serv_supports_openid = StrToi(Buf);
                        break;
                }
                ++a;
        }
+       FreeStrBuf(&Buf);
+       return info;
 }
 
 
@@ -148,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) {
@@ -170,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;
@@ -416,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;
 
@@ -442,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 {
@@ -459,7 +479,6 @@ int read_server_binary(StrBuf *Ret, size_t total_len)
                    }
                }
        }
-       FreeStrBuf(&Buf);
        return StrLength(Ret);
 }
 
@@ -512,42 +531,66 @@ void tmplput_serv_ip(StrBuf *Target, WCTemplputParams *TP)
 
 void tmplput_serv_nodename(StrBuf *Target, WCTemplputParams *TP)
 {
-       StrBufAppendTemplate(Target, TP, 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, 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, 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, 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",
-                           serv_info.serv_rev_level / 100,
-                           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 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 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)
 {
-       StrBufAppendTemplate(Target, TP, serv_info.serv_bbs_city, 0);
+       wcsession *WCC = WC;
+       if (WCC->serv_info == NULL)
+               return;
+       StrBufAppendTemplate(Target, TP, WC->serv_info->serv_bbs_city, 0);
 }
 
 
@@ -561,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);
 }