Call LoadExpirePolicy() unconditionally, this fixes the apparent snap back to old...
[citadel.git] / webcit / siteconfig.c
index 2f3d91cb5dcfec2f6b4fd3a66bfad500b1e45a3f..7a93d44af096e10b43b155c49a502584d88cc3bc 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Administrative screen for site-wide configuration
  *
- * Copyright (c) 1996-2011 by the citadel.org team
+ * Copyright (c) 1996-2012 by the citadel.org team
  *
  * This program is open source software.  You can redistribute it and/or
  * modify it under the terms of the GNU General Public License, version 3.
@@ -74,7 +74,7 @@ int ConditionalExpire(StrBuf *Target, WCTemplputParams *TP)
        which = GetTemplateTokenNumber(Target, TP, 2, 0);
        CompareWith = GetTemplateTokenNumber(Target, TP, 3, 0);
 
-       if (WCC->Policy[which].loaded == 0) LoadExpirePolicy(which);
+       LoadExpirePolicy(which);
        
        return WCC->Policy[which].expire_mode == CompareWith;
 }
@@ -85,7 +85,7 @@ void tmplput_ExpireValue(StrBuf *Target, WCTemplputParams *TP)
        wcsession *WCC = WC;
                
        which = GetTemplateTokenNumber(Target, TP, 0, 0);
-       if (WCC->Policy[which].loaded == 0) LoadExpirePolicy(which);
+       LoadExpirePolicy(which);
        StrBufAppendPrintf(Target, "%d", WCC->Policy[which].expire_value);
 }
 
@@ -96,7 +96,7 @@ void tmplput_ExpireMode(StrBuf *Target, WCTemplputParams *TP)
        wcsession *WCC = WC;
                
        which = GetTemplateTokenNumber(Target, TP, 2, 0);
-       if (WCC->Policy[which].loaded == 0) LoadExpirePolicy(which);
+       LoadExpirePolicy(which);
        StrBufAppendPrintf(Target, "%d", WCC->Policy[which].expire_mode);
 }
 
@@ -209,6 +209,7 @@ CfgMapping ServerConfig[] = {
 };
 
 
+
 /*
  *  display all configuration items
  */
@@ -218,7 +219,7 @@ void load_siteconfig(void)
        StrBuf *Buf;
        HashList *Cfg;
        long len;
-       int i;
+       int i, j;
        
        if (WCC->ServCfg == NULL)
                WCC->ServCfg = NewHash(1, NULL);
@@ -233,44 +234,35 @@ void load_siteconfig(void)
                AppendImportantMessage(SKEY(Buf));
                FreeStrBuf(&Buf);
                return;
+               
        }
-
-       i = 0;
+       j = i = 0;
        while (len = StrBuf_ServGetln(Buf),
-               (len >= 0)
-               && (i < (sizeof(ServerConfig) / sizeof(CfgMapping)))
-               && ((len != 3) || strcmp(ChrPtr(Buf), "000"))
-       ) {
-               Put(Cfg,
-                       ServerConfig[i].Key, 
-                       ServerConfig[i].len, 
-                       Buf, 
-                       HFreeStrBuf
-               );
-               i++;
-               if (i <= sizeof(ServerConfig) / sizeof(CfgMapping)) {
+              (len >= 0) && 
+              ((len != 3) || strcmp(ChrPtr(Buf), "000")))
+       {
+               if (i < (sizeof(ServerConfig) / sizeof(CfgMapping)))
+               {
+                       Put(Cfg,
+                           ServerConfig[i].Key, 
+                           ServerConfig[i].len, 
+                           Buf, 
+                           HFreeStrBuf);
+                       i++;
                        Buf = NewStrBuf();
                }
                else {
-                       Buf = NULL;
+                       if (j == 0)
+                               AppendImportantMessage(_("WARNING: Failed to parse Server Config; do you run a to new citserver?"), -1);
+                       j++;
                }
        }
-
-       if (strcmp(ChrPtr(Buf), "000") != 0)
-       {
-               /* Discard config lines which we don't yet support */
-               while ( (len = StrBuf_ServGetln(Buf),
-                       strcmp(ChrPtr(Buf), "000"))
-               ) {
-               }
-               AppendImportantMessage(_("WARNING: Failed to parse Server Config; do you run a to new citserver?"), -1);
-               FreeStrBuf(&Buf);
-               return;
-       }
        FreeStrBuf(&Buf);
 
-       LoadExpirePolicy(sitepolicy);
+       LoadExpirePolicy(roompolicy);
+       LoadExpirePolicy(floorpolicy);
        LoadExpirePolicy(mailboxespolicy);
+       LoadExpirePolicy(sitepolicy);
 }
 
 
@@ -397,6 +389,73 @@ int ConditionalServCfgCTXStrBuf(StrBuf *Target, WCTemplputParams *TP)
        else return 0;
 }
 
+/*----------------------------------------------------------------------------*
+ *              Displaying Logging                                            *
+ *----------------------------------------------------------------------------*/
+typedef struct __LogStatusStruct {
+       int Enable;
+       StrBuf *Name;
+}LogStatusStruct;
+
+void DeleteLogStatusStruct(void *v)
+{
+       LogStatusStruct *Stat = (LogStatusStruct*)v;
+
+       FreeStrBuf(&Stat->Name);
+       free(Stat);
+}
+
+void tmplput_servcfg_LogName(StrBuf *Target, WCTemplputParams *TP)
+{
+        LogStatusStruct *Stat = (LogStatusStruct*) CTX;
+       StrBufAppendTemplate(Target, TP, Stat->Name, 1);
+}
+
+int ConditionalServCfgThisLogEnabled(StrBuf *Target, WCTemplputParams *TP)
+{
+        LogStatusStruct *Stat = (LogStatusStruct*) CTX;
+       return Stat->Enable;
+}
+
+HashList *iterate_GetSrvLogEnable(StrBuf *Target, WCTemplputParams *TP)
+{
+        HashList *Hash = NULL;
+       StrBuf *Buf;
+       LogStatusStruct *Stat;
+       const char *Pos;
+       int Done = 0;
+       long len;
+       int num_logs = 0;
+
+        serv_puts("LOGP");
+        Buf = NewStrBuf();
+        StrBuf_ServGetln(Buf);
+        if (GetServerStatus(Buf, NULL) == 1) {
+                Hash = NewHash(1, Flathash);
+                while (!Done) {
+                        len = StrBuf_ServGetln(Buf);
+                        if ((len <0) || 
+                            ((len == 3) &&
+                             !strcmp(ChrPtr(Buf), "000")))
+                        {
+                                Done = 1;
+                                break;
+                        }
+                       Stat = (LogStatusStruct*) malloc (sizeof(LogStatusStruct));
+                       Pos = NULL;
+                       Stat->Name = NewStrBufPlain(NULL, len);
+                        StrBufExtract_NextToken(Stat->Name, Buf, &Pos, '|');
+                        Stat->Enable = StrBufExtractNext_int(Buf, &Pos, '|');
+
+                        Put(Hash, IKEY(num_logs), Stat, DeleteLogStatusStruct); 
+                       num_logs++;
+                }
+       }
+       FreeStrBuf(&Buf);
+       return Hash;
+}
+
+
 void 
 InitModule_SITECONFIG
 (void)
@@ -421,6 +480,10 @@ InitModule_SITECONFIG
        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);
+
+       RegisterConditional(HKEY("COND:SERVCFG:THISLOGENABLE"), 4, ConditionalServCfgThisLogEnabled, CTX_SRVLOG);
+       RegisterIterator("SERVCFG:LOGENABLE", 0, NULL, iterate_GetSrvLogEnable, NULL, DeleteHash, CTX_SRVLOG, CTX_NONE, IT_NOFLAG);
+       RegisterNamespace("SERVCFG:LOGNAME", 0, 1, tmplput_servcfg_LogName, NULL, CTX_SRVLOG);
 }
 
 void