if StrBuf_ServGetln() is called in a loop, its return value has to be checked for...
[citadel.git] / webcit / siteconfig.c
index 24f97212c3abf30c57f4bb40a99ef99690498295..f893b4833e9437fa037ab3e337a5304ec2035e49 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * Administrative screen for site-wide configuration
  */
 
@@ -111,7 +109,7 @@ void LoadZoneFiles(void)
        Put(ZoneHash, HKEY("UTC"), ZName, HFreeStrBuf);
        zones = icaltimezone_get_builtin_timezones();
        for (z = 0; z < zones->num_elements; ++z) {
-               /* lprintf(9, "Location: %-40s tzid: %s\n",
+               /* syslog(9, "Location: %-40s tzid: %s\n",
                        icaltimezone_get_location(icalarray_element_at(zones, z)),
                        icaltimezone_get_tzid(icalarray_element_at(zones, z))
                ); */
@@ -201,7 +199,8 @@ CfgMapping ServerConfig[] = {
        {CFG_STR, HKEY("c_xmpp_s2s_port")},
        {CFG_STR, HKEY("c_pop3_fetch")},
        {CFG_STR, HKEY("c_pop3_fastest")},
-       {CFG_YES , HKEY("c_spam_flag_only")}
+       {CFG_YES , HKEY("c_spam_flag_only")},
+       {CFG_YES , HKEY("c_guest_logins")}
 };
 
 
@@ -232,9 +231,9 @@ void load_siteconfig(void)
        }
        i = 0;
        while (len = StrBuf_ServGetln(Buf),
+              (len >= 0) && 
               (i <= (sizeof(ServerConfig) / sizeof(CfgMapping))) &&
-              ((len != 3) || (strcmp(ChrPtr(Buf), "000")!= 0))
-               )
+              ((len != 3) || strcmp(ChrPtr(Buf), "000")))
        {
                Put(Cfg,
                    ServerConfig[i].Key, 
@@ -364,31 +363,25 @@ int ConditionalServCfg(StrBuf *Target, WCTemplputParams *TP)
        else return 0;
 }
 
-int ConditionalServCfgSubst(StrBuf *Target, WCTemplputParams *TP)
+int ConditionalServCfgCTXStrBuf(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
        void *vBuf;
        StrBuf *Buf;
+       StrBuf *ZoneToCheck = (StrBuf*) CTX;
 
-       if (WCC->is_aide) {
+       if ((WCC->is_aide) || (ZoneToCheck == NULL)) {
                if (WCC->ServCfg == NULL)
                        load_siteconfig();
                GetHash(WCC->ServCfg, TKEY(2), &vBuf);
                if (vBuf == NULL) return 0;
                Buf = (StrBuf*) vBuf;
 
-               return CompareSubstToStrBuf(Buf, TP->Tokens->Params[3]);
+               return strcmp(ChrPtr(Buf), ChrPtr(ZoneToCheck)) == 0;
        }
        else return 0;
 }
 
-void CfgZoneTempl(StrBuf *TemplBuffer, WCTemplputParams *TP)
-{
-       StrBuf *Zone = (StrBuf*) CTX;
-
-       SVPutBuf("ZONENAME", Zone, 1);
-}
-
 void 
 InitModule_SITECONFIG
 (void)
@@ -397,8 +390,8 @@ InitModule_SITECONFIG
 
        RegisterNamespace("SERV:CFG", 1, 2, tmplput_servcfg, NULL, CTX_NONE);
        RegisterConditional(HKEY("COND:SERVCFG"), 3, ConditionalServCfg, CTX_NONE);
-       RegisterConditional(HKEY("COND:SERVCFG:SUBST"), 4, ConditionalServCfgSubst, CTX_NONE);
-       RegisterIterator("PREF:ZONE", 0, ZoneHash, NULL, CfgZoneTempl, NULL, CTX_PREF, CTX_NONE, IT_NOFLAG);
+       RegisterConditional(HKEY("COND:SERVCFG:CTXSTRBUF"), 4, ConditionalServCfgCTXStrBuf, CTX_STRBUF);
+       RegisterIterator("PREF:ZONE", 0, ZoneHash, NULL, NULL, NULL, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
 
        REGISTERTokenParamDefine(roompolicy);
        REGISTERTokenParamDefine(floorpolicy);