2 * Functions which handle Internet domain configuration etc.
22 typedef struct _ConstStrBuf {
28 /* These are server config keywords; do not localize! */
29 ConstStrBuf CfgNames[] = {
30 { HKEY("localhost") },
31 { HKEY("directory") },
32 { HKEY("smarthost") },
33 { HKEY("fallbackhost") },
35 { HKEY("spamassassin") },
36 { HKEY("masqdomain") },
45 * display the inet config dialog
47 void load_inetconf(void)
50 StrBuf *Buf, *CfgToken, *Value;
56 WCC->InetCfg = NewHash(1, NULL);
58 for (i = 0; i < (sizeof(CfgNames) / sizeof(ConstStrBuf)); i++) {
59 Hash = NewHash(1, NULL);
60 Put(WCC->InetCfg, CfgNames[i].name, CfgNames[i].len, Hash, HDeleteHash);
63 serv_printf("CONF GETSYS|application/x-citadel-internet-config");
65 StrBuf_ServGetln(Buf);
67 if (GetServerStatus(Buf, NULL) == 1) {
68 CfgToken = NewStrBuf();
69 while ((len = StrBuf_ServGetln(Buf),
70 strcmp(ChrPtr(Buf), "000"))) {
73 StrBufExtract_token(CfgToken, Buf, 1, '|');
74 StrBufExtract_token(Value, Buf, 0, '|');
75 GetHash(WCC->InetCfg, ChrPtr(CfgToken), StrLength(CfgToken), &vHash);
76 Hash = (HashList*) vHash;
78 lprintf(1, "ERROR Loading inet config line: [%s]\n",
83 nUsed = GetCount(Hash);
84 nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
85 Put(Hash, nnn, nUsed, Value, HFreeStrBuf);
87 FreeStrBuf(&CfgToken);
94 * save changes to the inet config
96 void new_save_inetconf(void) {
101 const StrBuf *eType, *eNum, *eName;
107 eType = sbstr("etype");
109 GetHash(WCC->InetCfg, ChrPtr(eType), StrLength(eType), &vHash);
110 Hash = (HashList*) vHash;
112 StrBufPrintf(WCC->ImportantMsg, _("Invalid Parameter"));
117 if (strcasecmp(bstr("oper"), "delete") == 0) {
118 eNum = sbstr("ename");
119 if (!GetHash(Hash, ChrPtr(eNum), StrLength(eNum), &vStr) ||
121 StrBufPrintf(WCC->ImportantMsg, _("Invalid Parameter"));
127 StrBufPrintf(WCC->ImportantMsg, _("%s has been deleted."), ChrPtr(Str));
130 else if (!strcasecmp(bstr("oper"), "add")) {
132 eName = sbstr("ename");
134 StrBufPrintf(WCC->ImportantMsg, _("Invalid Parameter"));
139 nUsed = GetCount(Hash);
140 nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
141 name = NewStrBufDup(eName);
143 Put(Hash, nnn, nUsed, name, HFreeStrBuf);
144 StrBufPrintf(WCC->ImportantMsg, "%s %s",
145 /*<domain> added status message*/ _("added."),
150 serv_printf("CONF PUTSYS|application/x-citadel-internet-config");
151 StrBuf_ServGetln(Buf);
152 if (GetServerStatus(Buf, NULL) == 4) {
153 for (i = 0; i < (sizeof(CfgNames) / sizeof(ConstStrBuf)); i++) {
158 GetHash(WCC->InetCfg, CfgNames[i].name, CfgNames[i].len, &vHash);
159 Hash = (HashList*) vHash;
161 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
165 if (GetCount(Hash) > 0) {
166 where = GetNewHashPos(Hash, 0);
167 while (GetNextHashPos(Hash, where, &KeyLen, &Key, &vStr)) {
168 Str = (StrBuf*) vStr;
169 if ((Str!= NULL) && (StrLength(Str) > 0))
174 DeleteHashPos(&where);
178 DeleteHash(&WCC->InetCfg);
184 void DeleteInetConfHash(StrBuf *Target, WCTemplputParams *TP)
188 if (WCC->InetCfg != NULL)
189 DeleteHash(&WCC->InetCfg);
194 HashList *GetInetConfHash(StrBuf *Target, WCTemplputParams *TP)
199 if (WCC->InetCfg == NULL)
201 GetHash(WCC->InetCfg, TKEY(5), &vHash);
202 PutBstr(HKEY("__SERVCFG:INET:TYPE"), NewStrBufPlain(TKEY(5)));
210 WebcitAddUrlHandler(HKEY("save_inetconf"), "", 0, new_save_inetconf, 0);
211 RegisterIterator("SERVCFG:INET", 1, NULL, GetInetConfHash, NULL, NULL, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
212 RegisterNamespace("SERVCFG:FLUSHINETCFG",0, 0, DeleteInetConfHash, NULL, CTX_NONE);