* Added a new category 'fallback smart host'. These are smart hosts that are used...
[citadel.git] / webcit / inetconf.c
index 5e0bd5b11403f45604577734de56451748c308ce..269967e4a7f9c243d7184c66fcd6885633f76a3c 100644 (file)
@@ -12,10 +12,12 @@ typedef enum _e_cfg {
        ic_localhost,
        ic_directory,
        ic_smarthost,
+       ic_fallback,
        ic_rbl,
        ic_spamass,
        ic_masq,
        ic_clamav,
+       ic_notify,
        ic_max
 } ECfg;
 
@@ -30,10 +32,12 @@ ConstStrBuf CfgNames[] = {
        { HKEY("localhost") },
        { HKEY("directory") },
        { HKEY("smarthost") },
+       { HKEY("fallbackhost") },
        { HKEY("rbl") },
        { HKEY("spamassassin") },
        { HKEY("masqdomain") },
-       { HKEY("clamav") }
+       { HKEY("clamav") },
+       { HKEY("notify") }
 };
 
        
@@ -49,7 +53,6 @@ void load_inetconf(void)
        void *vHash;
        HashList *Hash;
        char nnn[64];
-       char buf[SIZ];
        int i, len, nUsed;
        
        WCC->InetCfg = NewHash(1, NULL);
@@ -60,10 +63,10 @@ void load_inetconf(void)
        }
 
        serv_printf("CONF GETSYS|application/x-citadel-internet-config");
-       serv_getln(buf, sizeof buf);
-       
-       if (buf[0] == '1') {
-               Buf = NewStrBuf();
+       Buf = NewStrBuf();
+       StrBuf_ServGetln(Buf);
+               
+       if (GetServerStatus(Buf, NULL) == 1) {
                CfgToken = NewStrBuf();
                while ((len = StrBuf_ServGetln(Buf),
                        strcmp(ChrPtr(Buf), "000"))) {
@@ -83,9 +86,9 @@ void load_inetconf(void)
                        nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
                        Put(Hash, nnn, nUsed, Value, HFreeStrBuf); 
                }
-               FreeStrBuf(&Buf);
                FreeStrBuf(&CfgToken);
        }
+       FreeStrBuf(&Buf);
 }
 
 
@@ -96,10 +99,10 @@ void new_save_inetconf(void) {
        wcsession *WCC = WC;
        HashList *Hash;
        StrBuf *Str;
+       StrBuf *Buf;
        const StrBuf *eType, *eNum, *eName;
        char nnn[64];
        void *vHash, *vStr;
-       char buf[SIZ];
        int i, nUsed;
 
        load_inetconf();
@@ -108,7 +111,7 @@ void new_save_inetconf(void) {
        GetHash(WCC->InetCfg, ChrPtr(eType), StrLength(eType), &vHash);
        Hash = (HashList*) vHash;
        if (Hash == NULL) {
-               sprintf(WC->ImportantMessage, _("Invalid Parameter"));
+               StrBufPrintf(WCC->ImportantMsg, _("Invalid Parameter"));
                url_do_template();
                return;
        }
@@ -117,33 +120,38 @@ void new_save_inetconf(void) {
                eNum = sbstr("ename");
                if (!GetHash(Hash, ChrPtr(eNum), StrLength(eNum), &vStr) ||
                    (vStr == NULL)) {
-                       sprintf(WC->ImportantMessage, _("Invalid Parameter"));
+                       StrBufPrintf(WCC->ImportantMsg, _("Invalid Parameter"));
                        url_do_template();
                        return;
                }
 
                Str = (StrBuf*)vStr;
-               sprintf(WC->ImportantMessage, _("%s has been deleted."), ChrPtr(Str));
+               StrBufPrintf(WCC->ImportantMsg, _("%s has been deleted."), ChrPtr(Str));
                FlushStrBuf(Str);       
        }
        else if (!strcasecmp(bstr("oper"), "add")) {
+               StrBuf *name;
                eName = sbstr("ename");
                if (eName == NULL) {
-                       sprintf(WC->ImportantMessage, _("Invalid Parameter"));
+                       StrBufPrintf(WCC->ImportantMsg, _("Invalid Parameter"));
                        url_do_template();
                        return;
                }
 
                nUsed = GetCount(Hash);
                nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
-       
-               Put(Hash, nnn, nUsed, NewStrBufDup(eName), HFreeStrBuf); 
-               sprintf(WC->ImportantMessage, "%s added.", ChrPtr(eName));
+               name = NewStrBufDup(eName);
+               StrBufTrim(name);
+               Put(Hash, nnn, nUsed, name, HFreeStrBuf); 
+               StrBufPrintf(WCC->ImportantMsg, "%s %s", 
+                            /*<domain> added status message*/ _("added."), 
+                            ChrPtr(eName));
        }
 
+       Buf = NewStrBuf();
        serv_printf("CONF PUTSYS|application/x-citadel-internet-config");
-       serv_getln(buf, SIZ);
-       if (buf[0] == '4') {
+       StrBuf_ServGetln(Buf);
+       if (GetServerStatus(Buf, NULL) == 4) {
                for (i = 0; i < (sizeof(CfgNames) / sizeof(ConstStrBuf)); i++) {
                        HashPos *where;
                        const char *Key;
@@ -171,7 +179,7 @@ void new_save_inetconf(void) {
                serv_puts("000");
                DeleteHash(&WCC->InetCfg);
        }
-       
+       FreeStrBuf(&Buf);
        url_do_template();
 }
 
@@ -197,8 +205,8 @@ HashList *GetInetConfHash(StrBuf *Target, WCTemplputParams *TP)
 
        if (WCC->InetCfg == NULL)
                load_inetconf();
-       GetHash(WCC->InetCfg, TKEY(2), &vHash);
-       svprintf(HKEY("SERVCFG:INET:TYPE"), WCS_STRING, TP->Tokens->Params[2]->Start);
+       GetHash(WCC->InetCfg, TKEY(5), &vHash);
+       svprintf(HKEY("SERVCFG:INET:TYPE"), WCS_STRING, TP->Tokens->Params[5]->Start);
        return vHash;
 }
 
@@ -206,7 +214,7 @@ void
 InitModule_INETCONF
 (void)
 {
-       WebcitAddUrlHandler(HKEY("save_inetconf"), new_save_inetconf, AJAX);
+       WebcitAddUrlHandler(HKEY("save_inetconf"), "", 0, new_save_inetconf, 0);
        RegisterIterator("SERVCFG:INET", 1, NULL, GetInetConfHash, InetCfgSubst, NULL, CTX_INETCFG, CTX_NONE, IT_NOFLAG);
-       RegisterNamespace("SERVCFG:FLUSHINETCFG",0, 0, DeleteInetConfHash, CTX_NONE);
+       RegisterNamespace("SERVCFG:FLUSHINETCFG",0, 0, DeleteInetConfHash, NULL, CTX_NONE);
 }