From 48b40c677af024cbf96a4e63a8deb68be484d785 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Mon, 8 Sep 2008 15:28:24 +0000 Subject: [PATCH] * fix COND:PREFS * add NONCE replacer to contextloop; please re-bootstrap so that the initializer does its job * added selectboxes to the config dialog templates * added COND:SERVCFG:SUBST for the TZ dropdown --- webcit/context_loop.c | 14 ++++ webcit/preferences.c | 26 +++--- webcit/siteconfig.c | 51 ++++++++---- webcit/static/t/aide_global_config.html | 2 +- webcit/static/t/tab_siteconfig_access.html | 31 ++++--- .../static/t/tab_siteconfig_autopurger.html | 62 +++++++++++--- webcit/static/t/tab_siteconfig_general.html | 2 +- webcit/static/t/tab_siteconfig_indexing.html | 3 - webcit/static/t/whosection.html | 2 +- webcit/subst.c | 81 ++++++++++++++++++- webcit/webcit.h | 2 + 11 files changed, 214 insertions(+), 62 deletions(-) diff --git a/webcit/context_loop.c b/webcit/context_loop.c index e505b5465..4cf0b5bfe 100644 --- a/webcit/context_loop.c +++ b/webcit/context_loop.c @@ -553,3 +553,17 @@ void context_loop(int *sock) } + +void tmpl_nonce(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context) +{ + struct wcsession *WCC = WC; + StrBufAppendPrintf(Target, "%ld", + (WCC != NULL)? WCC->nonce:0); +} + +void +InitModule_CONTEXT +(void) +{ + RegisterNamespace("NONCE", 0, 0, tmpl_nonce); +} diff --git a/webcit/preferences.c b/webcit/preferences.c index 49f430b73..28aac7dfe 100644 --- a/webcit/preferences.c +++ b/webcit/preferences.c @@ -690,24 +690,30 @@ void tmplput_CFG_Descr(StrBuf *Target, int nArgs, WCTemplateToken *Token, void * } -void CfgZoneTempl(StrBuf *TemplBuffer, void *Context) +void CfgZoneTempl(StrBuf *TemplBuffer, void *vContext) { + StrBuf *Zone = (StrBuf*) vContext; + SVPutBuf("ZONENAME", Zone, 1); } int ConditionalPreference(WCTemplateToken *Token, void *Context) { + StrBuf *Pref; - void *hash_value; - - if (!GetHash(PreferenceHooks, - Token->Params[2]->Start, - Token->Params[2]->len, - &hash_value)) + if (!get_PREFERENCE(Token->Params[2]->Start, + Token->Params[2]->len, + &Pref)) return 0; - - Prefs *Newpref = (Prefs*) hash_value; - return (strcmp(Token->Params[3]->Start, Newpref->PrefStr) == 0); + + if (Token->nParameters == 3) { + return 1; + } + else if (Token->Params[3]->Type == TYPE_STR) + return ((Token->Params[3]->len == StrLength(Pref)) && + (strcmp(Token->Params[3]->Start, ChrPtr(Pref)) == 0)); + else + return (StrTol(Pref) == Token->Params[3]->lvalue); } diff --git a/webcit/siteconfig.c b/webcit/siteconfig.c index bfcdc81d4..bde63a706 100644 --- a/webcit/siteconfig.c +++ b/webcit/siteconfig.c @@ -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(); } @@ -1023,6 +1022,27 @@ int ConditionalServCfg(WCTemplateToken *Tokens, void *Context) 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; +} + void InitModule_SITECONFIG (void) @@ -1032,5 +1052,6 @@ InitModule_SITECONFIG RegisterNamespace("SERV:CFG", 1, 1, tmplput_servcfg); RegisterConditional(HKEY("COND:SERVCFG"), 3, ConditionalServCfg); + RegisterConditional(HKEY("COND:SERVCFG:SUBST"), 4, ConditionalServCfgSubst); } /*@}*/ diff --git a/webcit/static/t/aide_global_config.html b/webcit/static/t/aide_global_config.html index c202fe9a1..7247b0d3e 100644 --- a/webcit/static/t/aide_global_config.html +++ b/webcit/static/t/aide_global_config.html @@ -1,5 +1,5 @@