2 * Functions which handle Internet domain configuration etc.
23 /* These are server config keywords; do not localize! */
24 ConstStr CfgNames[] = {
25 { HKEY("localhost") },
26 { HKEY("directory") },
27 { HKEY("smarthost") },
28 { HKEY("fallbackhost") },
30 { HKEY("spamassassin") },
31 { HKEY("masqdomain") },
40 * display the inet config dialog
42 void load_inetconf(void)
45 StrBuf *Buf, *CfgToken, *Value;
51 WCC->InetCfg = NewHash(1, NULL);
53 for (i = 0; i < (sizeof(CfgNames) / sizeof(ConstStr)); i++) {
54 Hash = NewHash(1, NULL);
55 Put(WCC->InetCfg, CKEY(CfgNames[i]), Hash, HDeleteHash);
58 serv_printf("CONF GETSYS|application/x-citadel-internet-config");
60 StrBuf_ServGetln(Buf);
62 if (GetServerStatus(Buf, NULL) == 1) {
63 CfgToken = NewStrBuf();
64 while ((len = StrBuf_ServGetln(Buf),
65 strcmp(ChrPtr(Buf), "000"))) {
68 StrBufExtract_token(CfgToken, Buf, 1, '|');
69 StrBufExtract_token(Value, Buf, 0, '|');
70 GetHash(WCC->InetCfg, ChrPtr(CfgToken), StrLength(CfgToken), &vHash);
71 Hash = (HashList*) vHash;
73 syslog(1, "ERROR Loading inet config line: [%s]\n",
78 nUsed = GetCount(Hash);
79 nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
80 Put(Hash, nnn, nUsed, Value, HFreeStrBuf);
82 FreeStrBuf(&CfgToken);
89 * save changes to the inet config
91 void new_save_inetconf(void) {
96 const StrBuf *eType, *eNum, *eName;
102 eType = sbstr("etype");
104 GetHash(WCC->InetCfg, ChrPtr(eType), StrLength(eType), &vHash);
105 Hash = (HashList*) vHash;
107 StrBufPrintf(WCC->ImportantMsg, _("Invalid Parameter"));
112 if (strcasecmp(bstr("oper"), "delete") == 0) {
113 eNum = sbstr("ename");
114 if (!GetHash(Hash, ChrPtr(eNum), StrLength(eNum), &vStr) ||
116 StrBufPrintf(WCC->ImportantMsg, _("Invalid Parameter"));
122 StrBufPrintf(WCC->ImportantMsg, _("%s has been deleted."), ChrPtr(Str));
125 else if (!strcasecmp(bstr("oper"), "add")) {
127 eName = sbstr("ename");
129 StrBufPrintf(WCC->ImportantMsg, _("Invalid Parameter"));
134 nUsed = GetCount(Hash);
135 nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
136 name = NewStrBufDup(eName);
138 Put(Hash, nnn, nUsed, name, HFreeStrBuf);
139 StrBufPrintf(WCC->ImportantMsg, "%s %s",
140 /*<domain> added status message*/ _("added."),
145 serv_printf("CONF PUTSYS|application/x-citadel-internet-config");
146 StrBuf_ServGetln(Buf);
147 if (GetServerStatus(Buf, NULL) == 4) {
148 for (i = 0; i < (sizeof(CfgNames) / sizeof(ConstStr)); i++) {
153 GetHash(WCC->InetCfg, CKEY(CfgNames[i]), &vHash);
154 Hash = (HashList*) vHash;
156 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
160 if (GetCount(Hash) > 0) {
161 where = GetNewHashPos(Hash, 0);
162 while (GetNextHashPos(Hash, where, &KeyLen, &Key, &vStr)) {
163 Str = (StrBuf*) vStr;
164 if ((Str!= NULL) && (StrLength(Str) > 0))
169 DeleteHashPos(&where);
173 DeleteHash(&WCC->InetCfg);
179 void DeleteInetConfHash(StrBuf *Target, WCTemplputParams *TP)
183 if (WCC->InetCfg != NULL)
184 DeleteHash(&WCC->InetCfg);
189 HashList *GetInetConfHash(StrBuf *Target, WCTemplputParams *TP)
194 if (WCC->InetCfg == NULL)
196 GetHash(WCC->InetCfg, TKEY(5), &vHash);
197 PutBstr(HKEY("__SERVCFG:INET:TYPE"), NewStrBufPlain(TKEY(5)));
205 WebcitAddUrlHandler(HKEY("save_inetconf"), "", 0, new_save_inetconf, 0);
206 RegisterIterator("SERVCFG:INET", 1, NULL, GetInetConfHash, NULL, NULL, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
207 RegisterNamespace("SERVCFG:FLUSHINETCFG",0, 0, DeleteInetConfHash, NULL, CTX_NONE);