]> code.citadel.org Git - citadel.git/blobdiff - webcit/siteconfig.c
* load_siteconfig(): revalidate what the server gives us as siteconfig, and bail...
[citadel.git] / webcit / siteconfig.c
index 67c954a7118ea660cfadce1848c52b803356d975..24f97212c3abf30c57f4bb40a99ef99690498295 100644 (file)
 
 HashList *ZoneHash = NULL;
 
+ConstStr ExpirePolicyString = {CStrOf(roompolicy)     };
+
+ConstStr ExpirePolicyStrings[][2] = {
+       { { CStrOf(roompolicy)     } , { strof(roompolicy)     "_value", sizeof(strof(roompolicy)     "_value") - 1 } },
+       { { CStrOf(floorpolicy)    } , { strof(floorpolicy)    "_value", sizeof(strof(floorpolicy)    "_value") - 1 } },
+       { { CStrOf(sitepolicy)     } , { strof(sitepolicy)     "_value", sizeof(strof(sitepolicy)     "_value") - 1 } },
+       { { CStrOf(mailboxespolicy)} , { strof(mailboxespolicy)"_value", sizeof(strof(mailboxespolicy)"_value") - 1 } }
+};
+
+void LoadExpirePolicy(GPEXWhichPolicy which)
+{
+       StrBuf *Buf;
+       wcsession *WCC = WC;
+       long State;
+       const char *Pos = NULL;
+
+       serv_printf("GPEX %s", ExpirePolicyStrings[which][0].Key);
+       Buf = NewStrBuf();
+       StrBuf_ServGetln(Buf);
+       WCC->Policy[which].loaded = 1;
+       if (GetServerStatus(Buf, &State) == 2) {
+               Pos = ChrPtr(Buf) + 4;
+               WCC->Policy[which].expire_mode = StrBufExtractNext_long(Buf, &Pos, '|');
+               WCC->Policy[which].expire_value = StrBufExtractNext_long(Buf, &Pos, '|');
+       }
+       else if (State == 550)
+               StrBufAppendBufPlain(WCC->ImportantMsg,
+                                    _("Higher access is required to access this function."), -1, 0);
+       FreeStrBuf(&Buf);
+}
+
+void SaveExpirePolicyFromHTTP(GPEXWhichPolicy which)
+{
+       StrBuf *Buf;
+       long State;
+
+       serv_printf("SPEX %s|%d|%d", 
+                           ExpirePolicyStrings[which][0].Key,
+                   ibcstr( ExpirePolicyStrings[which][1] ),
+                   ibcstr( ExpirePolicyStrings[which][1] )  );
+
+       Buf = NewStrBuf();
+       StrBuf_ServGetln(Buf);
+       GetServerStatus(Buf, &State);
+       if (State == 550)
+               StrBufAppendBufPlain(WC->ImportantMsg,
+                                    _("Higher access is required to access this function."), -1, 0);
+       FreeStrBuf(&Buf);
+}
+
+int ConditionalExpire(StrBuf *Target, WCTemplputParams *TP)
+{
+       wcsession *WCC = WC;
+       GPEXWhichPolicy which;
+       int CompareWith;
+
+       which = GetTemplateTokenNumber(Target, TP, 2, 0);
+       CompareWith = GetTemplateTokenNumber(Target, TP, 3, 0);
+
+       if (WCC->Policy[which].loaded == 0) LoadExpirePolicy(which);
+       
+       return WCC->Policy[which].expire_mode == CompareWith;
+}
+
+void tmplput_ExpireValue(StrBuf *Target, WCTemplputParams *TP)
+{
+       GPEXWhichPolicy which;
+       wcsession *WCC = WC;
+               
+       which = GetTemplateTokenNumber(Target, TP, 0, 0);
+       if (WCC->Policy[which].loaded == 0) LoadExpirePolicy(which);
+       StrBufAppendPrintf(Target, "%d", WCC->Policy[which].expire_value);
+}
+
+
+void tmplput_ExpireMode(StrBuf *Target, WCTemplputParams *TP)
+{
+       GPEXWhichPolicy which;
+       wcsession *WCC = WC;
+               
+       which = GetTemplateTokenNumber(Target, TP, 2, 0);
+       if (WCC->Policy[which].loaded == 0) LoadExpirePolicy(which);
+       StrBufAppendPrintf(Target, "%d", WCC->Policy[which].expire_mode);
+}
+
 
 
 void LoadZoneFiles(void)
@@ -126,9 +211,8 @@ CfgMapping ServerConfig[] = {
 void load_siteconfig(void)
 {
        wcsession *WCC = WC;
-       StrBuf *Buf, *CfgToken;
+       StrBuf *Buf;
        HashList *Cfg;
-       char buf[SIZ];
        long len;
        int i;
        
@@ -136,14 +220,21 @@ void load_siteconfig(void)
                WCC->ServCfg = NewHash(1, NULL);
        Cfg = WCC->ServCfg;
 
+       Buf = NewStrBuf();
+
        serv_printf("CONF get");
-       serv_getln(buf, sizeof buf);
+       StrBuf_ServGetln(Buf);
+       if (GetServerStatus(Buf, NULL) != 1) {
+               StrBufCutLeft(Buf, 4);
+               AppendImportantMessage(SKEY(Buf));
+               return;
+               
+       }
        i = 0;
-       Buf = NewStrBuf();
-       while ((sizeof(ServerConfig) / sizeof(CfgMapping)) &&
-              (len = StrBuf_ServGetln(Buf),
-               strcmp(ChrPtr(Buf), "000")) && 
-              (i <= sizeof(ServerConfig))) 
+       while (len = StrBuf_ServGetln(Buf),
+              (i <= (sizeof(ServerConfig) / sizeof(CfgMapping))) &&
+              ((len != 3) || (strcmp(ChrPtr(Buf), "000")!= 0))
+               )
        {
                Put(Cfg,
                    ServerConfig[i].Key, 
@@ -156,41 +247,22 @@ void load_siteconfig(void)
                else
                        Buf = NULL;                     
        }
-       FreeStrBuf(&Buf);
-
-       serv_puts("GPEX site");
-       Buf = NewStrBuf();
-       CfgToken = NULL;
-       StrBuf_ServGetln(Buf);
-       if (GetServerStatus(Buf, NULL) == 2) {
-               StrBufCutLeft(Buf, 4);
-
-               CfgToken = NewStrBuf();
-               StrBufExtract_token(CfgToken, Buf, 0, '|');
-               Put(Cfg, HKEY("sitepolicy"), CfgToken, HFreeStrBuf);
-
-               CfgToken = NewStrBuf();
-               StrBufExtract_token(CfgToken, Buf, 1, '|');
-               Put(Cfg, HKEY("sitevalue"), CfgToken, HFreeStrBuf);
-       }
-
-       serv_puts("GPEX mailboxes");
-       StrBuf_ServGetln(Buf);
-       if (GetServerStatus(Buf, NULL) == 2) {
-               StrBufCutLeft(Buf, 4);
-
-               CfgToken = NewStrBuf();
-               StrBufExtract_token(CfgToken, Buf, 0, '|');
-               Put(Cfg, HKEY("mboxpolicy"), CfgToken, HFreeStrBuf);
-
-               CfgToken = NewStrBuf();
-               StrBufExtract_token(CfgToken, Buf, 1, '|');
-               Put(Cfg, HKEY("mboxvalue"), CfgToken, HFreeStrBuf);
+       if (strcmp(ChrPtr(Buf), "000")!=0)
+       {
+               /* WHOOOOPSI??? burn the lines we don't understand */
+               while ((len = StrBuf_ServGetln(Buf),
+                       strcmp(ChrPtr(Buf), "000"))) {}
+               AppendImportantMessage(_("WARNING: Failed to parse Server Config; do you run a to new citserver?"), -1);
+               return;
        }
        FreeStrBuf(&Buf);
+
+       LoadExpirePolicy(sitepolicy);
+       LoadExpirePolicy(mailboxespolicy);
 }
 
 
+
 /**
  * parse siteconfig changes 
  */
@@ -233,10 +305,9 @@ void siteconfig(void)
        }
         serv_puts("000");
 
-       serv_printf("SPEX site|%d|%d", ibstr("sitepolicy"), ibstr("sitevalue"));
-       serv_getln(buf, sizeof buf);
-       serv_printf("SPEX mailboxes|%d|%d", ibstr("mboxpolicy"), ibstr("mboxvalue"));
-       serv_getln(buf, sizeof buf);
+       SaveExpirePolicyFromHTTP(sitepolicy);
+       SaveExpirePolicyFromHTTP(mailboxespolicy);
+
        FreeStrBuf(&WCC->serv_info->serv_default_cal_zone);
        WCC->serv_info->serv_default_cal_zone = NewStrBufDup(sbstr("c_default_cal_zone"));
 
@@ -276,9 +347,19 @@ int ConditionalServCfg(StrBuf *Target, WCTemplputParams *TP)
                if (TP->Tokens->nParameters == 3) {
                        return 1;
                }
-               else if (TP->Tokens->Params[3]->Type == TYPE_STR)
-                       return (strcmp(TP->Tokens->Params[3]->Start, ChrPtr(Buf)) == 0);
-               else return (StrTol(Buf) == TP->Tokens->Params[3]->lvalue);
+               else if (IS_NUMBER(TP->Tokens->Params[3]->Type))
+                       return (StrTol(Buf) == GetTemplateTokenNumber (Target, TP, 3, 0));
+               else
+               {
+                       const char *pch;
+                       long len;
+                       
+                       GetTemplateTokenString(Target, TP, 3, &pch, &len);
+               
+                       return ((len == StrLength(Buf)) &&
+                               (strcmp(pch, ChrPtr(Buf)) == 0));
+               }
+
        }
        else return 0;
 }
@@ -312,12 +393,26 @@ void
 InitModule_SITECONFIG
 (void)
 {
-       WebcitAddUrlHandler(HKEY("siteconfig"), siteconfig, CTX_NONE);
+       WebcitAddUrlHandler(HKEY("siteconfig"), "", 0, siteconfig, CTX_NONE);
 
        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);
+
+       REGISTERTokenParamDefine(roompolicy);
+       REGISTERTokenParamDefine(floorpolicy);
+       REGISTERTokenParamDefine(sitepolicy);
+       REGISTERTokenParamDefine(mailboxespolicy);
+
+       REGISTERTokenParamDefine(EXPIRE_NEXTLEVEL);
+       REGISTERTokenParamDefine(EXPIRE_MANUAL);
+       REGISTERTokenParamDefine(EXPIRE_NUMMSGS);
+       REGISTERTokenParamDefine(EXPIRE_AGE);
+
+       RegisterConditional(HKEY("COND:EXPIRE:MODE"), 2, ConditionalExpire, CTX_NONE);
+       RegisterNamespace("EXPIRE:VALUE", 1, 2, tmplput_ExpireValue, NULL, CTX_NONE);
+       RegisterNamespace("EXPIRE:MODE", 1, 2, tmplput_ExpireMode, NULL, CTX_NONE);
 }
 
 void