4 * Functions which handle Internet domain configuration etc.
24 typedef struct _ConstStrBuf {
30 /* These are server config keywords; do not localize! */
31 ConstStrBuf CfgNames[] = {
32 { HKEY("localhost") },
33 { HKEY("directory") },
34 { HKEY("smarthost") },
35 { HKEY("fallbackhost") },
37 { HKEY("spamassassin") },
38 { HKEY("masqdomain") },
47 * display the inet config dialog
49 void load_inetconf(void)
52 StrBuf *Buf, *CfgToken, *Value;
58 WCC->InetCfg = NewHash(1, NULL);
60 for (i = 0; i < (sizeof(CfgNames) / sizeof(ConstStrBuf)); i++) {
61 Hash = NewHash(1, NULL);
62 Put(WCC->InetCfg, CfgNames[i].name, CfgNames[i].len, Hash, HDeleteHash);
65 serv_printf("CONF GETSYS|application/x-citadel-internet-config");
67 StrBuf_ServGetln(Buf);
69 if (GetServerStatus(Buf, NULL) == 1) {
70 CfgToken = NewStrBuf();
71 while ((len = StrBuf_ServGetln(Buf),
74 strcmp(ChrPtr(Buf), "000")))))
78 StrBufExtract_token(CfgToken, Buf, 1, '|');
79 StrBufExtract_token(Value, Buf, 0, '|');
80 GetHash(WCC->InetCfg, ChrPtr(CfgToken), StrLength(CfgToken), &vHash);
81 Hash = (HashList*) vHash;
83 lprintf(1, "ERROR Loading inet config line: [%s]\n",
88 nUsed = GetCount(Hash);
89 nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
90 Put(Hash, nnn, nUsed, Value, HFreeStrBuf);
92 FreeStrBuf(&CfgToken);
99 * save changes to the inet config
101 void new_save_inetconf(void) {
106 const StrBuf *eType, *eNum, *eName;
112 eType = sbstr("etype");
114 GetHash(WCC->InetCfg, ChrPtr(eType), StrLength(eType), &vHash);
115 Hash = (HashList*) vHash;
117 StrBufPrintf(WCC->ImportantMsg, _("Invalid Parameter"));
122 if (strcasecmp(bstr("oper"), "delete") == 0) {
123 eNum = sbstr("ename");
124 if (!GetHash(Hash, ChrPtr(eNum), StrLength(eNum), &vStr) ||
126 StrBufPrintf(WCC->ImportantMsg, _("Invalid Parameter"));
132 StrBufPrintf(WCC->ImportantMsg, _("%s has been deleted."), ChrPtr(Str));
135 else if (!strcasecmp(bstr("oper"), "add")) {
137 eName = sbstr("ename");
139 StrBufPrintf(WCC->ImportantMsg, _("Invalid Parameter"));
144 nUsed = GetCount(Hash);
145 nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
146 name = NewStrBufDup(eName);
148 Put(Hash, nnn, nUsed, name, HFreeStrBuf);
149 StrBufPrintf(WCC->ImportantMsg, "%s %s",
150 /*<domain> added status message*/ _("added."),
155 serv_printf("CONF PUTSYS|application/x-citadel-internet-config");
156 StrBuf_ServGetln(Buf);
157 if (GetServerStatus(Buf, NULL) == 4) {
158 for (i = 0; i < (sizeof(CfgNames) / sizeof(ConstStrBuf)); i++) {
163 GetHash(WCC->InetCfg, CfgNames[i].name, CfgNames[i].len, &vHash);
164 Hash = (HashList*) vHash;
166 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
170 if (GetCount(Hash) > 0) {
171 where = GetNewHashPos(Hash, 0);
172 while (GetNextHashPos(Hash, where, &KeyLen, &Key, &vStr)) {
173 Str = (StrBuf*) vStr;
174 if ((Str!= NULL) && (StrLength(Str) > 0))
179 DeleteHashPos(&where);
183 DeleteHash(&WCC->InetCfg);
189 void InetCfgSubst(StrBuf *TemplBuffer, WCTemplputParams *TP)
191 SVPutBuf("SERVCFG:INET:HOSTNAME", CTX, 1);
194 void DeleteInetConfHash(StrBuf *Target, WCTemplputParams *TP)
198 if (WCC->InetCfg != NULL)
199 DeleteHash(&WCC->InetCfg);
204 HashList *GetInetConfHash(StrBuf *Target, WCTemplputParams *TP)
209 if (WCC->InetCfg == NULL)
211 GetHash(WCC->InetCfg, TKEY(5), &vHash);
212 svprintf(HKEY("SERVCFG:INET:TYPE"), WCS_STRING, TP->Tokens->Params[5]->Start);
220 WebcitAddUrlHandler(HKEY("save_inetconf"), "", 0, new_save_inetconf, 0);
221 RegisterIterator("SERVCFG:INET", 1, NULL, GetInetConfHash, InetCfgSubst, NULL, CTX_INETCFG, CTX_NONE, IT_NOFLAG);
222 RegisterNamespace("SERVCFG:FLUSHINETCFG",0, 0, DeleteInetConfHash, NULL, CTX_NONE);