]> code.citadel.org Git - citadel.git/blobdiff - webcit/siteconfig.c
* fix COND:PREFS
[citadel.git] / webcit / siteconfig.c
index 5e42ae5a268e884b4f6e82bbbc7bd89d379bd661..bde63a706dec9eddf6cdc5bf990fc062c3ea51d5 100644 (file)
@@ -18,21 +18,18 @@ void LoadZoneFiles(void)
        icalarray *zones;
        int z;
        long len;
-       char this_zone[128];
-       char *ZName;
+       const char *this_zone;
+       StrBuf *ZName;
        
        ZoneHash = NewHash(1, NULL);
-       len = sizeof("UTC") + 1;
-       ZName = malloc(len + 1);
-       memcpy(ZName, "UTC", len + 1);
-       Put(ZoneHash, ZName, len, ZName, NULL);
+       ZName = NewStrBufPlain(HKEY("UTC"));
+       Put(ZoneHash, HKEY("UTC"), ZName, HFreeStrBuf);
        zones = icaltimezone_get_builtin_timezones();
        for (z = 0; z < zones->num_elements; ++z) {
-               strcpy(this_zone, icaltimezone_get_location(icalarray_element_at(zones, z)));
+               this_zone = icaltimezone_get_location(icalarray_element_at(zones, z));
                len = strlen(this_zone);
-               ZName = (char*)malloc(len +1);
-               memcpy(ZName, this_zone, len + 1);
-               Put(ZoneHash, ZName, len, ZName, NULL);
+               ZName = NewStrBufPlain(this_zone, len);
+               Put(ZoneHash, this_zone, len, ZName, HFreeStrBuf);
        }
        SortByHashKey(ZoneHash, 0);
 }
@@ -932,6 +929,7 @@ void load_siteconfig(void)
  */
 void siteconfig(void)
 {
+       struct wcsession *WCC = WC;
        int i;
        char buf[256];
 
@@ -942,13 +940,12 @@ void siteconfig(void)
        serv_printf("CONF set");
        serv_getln(buf, sizeof buf);
        if (buf[0] != '4') {
-               safestrncpy(WC->ImportantMessage, &buf[4], sizeof WC->ImportantMessage);
+               safestrncpy(WCC->ImportantMessage, &buf[4], sizeof WCC->ImportantMessage);
                display_aide_menu();
                return;
        }
 
-       i = sizeof(ServerConfig);
-       for (i=0; i < sizeof(ServerConfig); i ++)
+       for (i=0; i < (sizeof(ServerConfig) / sizeof(CfgMapping)); i ++)
        {
                switch (ServerConfig[i].type) {
                default:
@@ -967,6 +964,7 @@ void siteconfig(void)
                        break;
                }
        }
+        serv_puts("000");
 
        serv_printf("SPEX site|%d|%d", ibstr("sitepolicy"), ibstr("sitevalue"));
        serv_getln(buf, sizeof buf);
@@ -975,8 +973,9 @@ void siteconfig(void)
 
        strcpy(serv_info.serv_default_cal_zone, bstr("c_default_cal_zone"));
 
-       safestrncpy(WC->ImportantMessage, _("Your system configuration has been updated."),
-               sizeof WC->ImportantMessage);
+       safestrncpy(WCC->ImportantMessage, _("Your system configuration has been updated."),
+               sizeof WCC->ImportantMessage);
+       DeleteHash(&WCC->ServCfg);
        display_aide_menu();
 }
 
@@ -1008,15 +1007,38 @@ int ConditionalServCfg(WCTemplateToken *Tokens, void *Context)
                if (WCC->ServCfg == NULL)
                        load_siteconfig();
                GetHash(WCC->ServCfg, 
-                       Tokens->Params[0]->Start,
-                       Tokens->Params[0]->len, 
+                       Tokens->Params[2]->Start,
+                       Tokens->Params[2]->len, 
                        &vBuf);
                if (vBuf == NULL) return 0;
                Buf = (StrBuf*) vBuf;
-               if (Tokens->nParameters == 1)
+               if (Tokens->nParameters == 3) {
                        return 1;
-               else 
-                       return (strcmp(Tokens->Params[0]->Start, ChrPtr(Buf)) == 0);
+               }
+               else if (Tokens->Params[3]->Type == TYPE_STR)
+                       return (strcmp(Tokens->Params[3]->Start, ChrPtr(Buf)) == 0);
+               else return (StrTol(Buf) == Tokens->Params[3]->lvalue);
+       }
+       else return 0;
+}
+
+int ConditionalServCfgSubst(WCTemplateToken *Tokens, void *Context)
+{
+       struct wcsession *WCC = WC;
+       void *vBuf;
+       StrBuf *Buf;
+
+       if (WCC->is_aide) {
+               if (WCC->ServCfg == NULL)
+                       load_siteconfig();
+               GetHash(WCC->ServCfg, 
+                       Tokens->Params[2]->Start,
+                       Tokens->Params[2]->len, 
+                       &vBuf);
+               if (vBuf == NULL) return 0;
+               Buf = (StrBuf*) vBuf;
+
+               return CompareSubstToStrBuf(Buf, Tokens->Params[3]);
        }
        else return 0;
 }
@@ -1029,6 +1051,7 @@ InitModule_SITECONFIG
        WebcitAddUrlHandler(HKEY("siteconfig"), siteconfig, 0);
 
        RegisterNamespace("SERV:CFG", 1, 1, tmplput_servcfg);
-       RegisterConditional(HKEY("COND:SERVCFG"), 1, ConditionalServCfg);
+       RegisterConditional(HKEY("COND:SERVCFG"), 3, ConditionalServCfg);
+       RegisterConditional(HKEY("COND:SERVCFG:SUBST"), 4, ConditionalServCfgSubst);
 }
 /*@}*/