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),
72 strcmp(ChrPtr(Buf), "000"))) {
75 StrBufExtract_token(CfgToken, Buf, 1, '|');
76 StrBufExtract_token(Value, Buf, 0, '|');
77 GetHash(WCC->InetCfg, ChrPtr(CfgToken), StrLength(CfgToken), &vHash);
78 Hash = (HashList*) vHash;
80 lprintf(1, "ERROR Loading inet config line: [%s]\n",
85 nUsed = GetCount(Hash);
86 nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
87 Put(Hash, nnn, nUsed, Value, HFreeStrBuf);
89 FreeStrBuf(&CfgToken);
96 * save changes to the inet config
98 void new_save_inetconf(void) {
103 const StrBuf *eType, *eNum, *eName;
109 eType = sbstr("etype");
111 GetHash(WCC->InetCfg, ChrPtr(eType), StrLength(eType), &vHash);
112 Hash = (HashList*) vHash;
114 StrBufPrintf(WCC->ImportantMsg, _("Invalid Parameter"));
119 if (strcasecmp(bstr("oper"), "delete") == 0) {
120 eNum = sbstr("ename");
121 if (!GetHash(Hash, ChrPtr(eNum), StrLength(eNum), &vStr) ||
123 StrBufPrintf(WCC->ImportantMsg, _("Invalid Parameter"));
129 StrBufPrintf(WCC->ImportantMsg, _("%s has been deleted."), ChrPtr(Str));
132 else if (!strcasecmp(bstr("oper"), "add")) {
134 eName = sbstr("ename");
136 StrBufPrintf(WCC->ImportantMsg, _("Invalid Parameter"));
141 nUsed = GetCount(Hash);
142 nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
143 name = NewStrBufDup(eName);
145 Put(Hash, nnn, nUsed, name, HFreeStrBuf);
146 StrBufPrintf(WCC->ImportantMsg, "%s %s",
147 /*<domain> added status message*/ _("added."),
152 serv_printf("CONF PUTSYS|application/x-citadel-internet-config");
153 StrBuf_ServGetln(Buf);
154 if (GetServerStatus(Buf, NULL) == 4) {
155 for (i = 0; i < (sizeof(CfgNames) / sizeof(ConstStrBuf)); i++) {
160 GetHash(WCC->InetCfg, CfgNames[i].name, CfgNames[i].len, &vHash);
161 Hash = (HashList*) vHash;
163 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
167 if (GetCount(Hash) > 0) {
168 where = GetNewHashPos(Hash, 0);
169 while (GetNextHashPos(Hash, where, &KeyLen, &Key, &vStr)) {
170 Str = (StrBuf*) vStr;
171 if ((Str!= NULL) && (StrLength(Str) > 0))
176 DeleteHashPos(&where);
180 DeleteHash(&WCC->InetCfg);
186 void InetCfgSubst(StrBuf *TemplBuffer, WCTemplputParams *TP)
188 SVPutBuf("SERVCFG:INET:HOSTNAME", CTX, 1);
191 void DeleteInetConfHash(StrBuf *Target, WCTemplputParams *TP)
195 if (WCC->InetCfg != NULL)
196 DeleteHash(&WCC->InetCfg);
201 HashList *GetInetConfHash(StrBuf *Target, WCTemplputParams *TP)
206 if (WCC->InetCfg == NULL)
208 GetHash(WCC->InetCfg, TKEY(5), &vHash);
209 svprintf(HKEY("SERVCFG:INET:TYPE"), WCS_STRING, TP->Tokens->Params[5]->Start);
217 WebcitAddUrlHandler(HKEY("save_inetconf"), "", 0, new_save_inetconf, 0);
218 RegisterIterator("SERVCFG:INET", 1, NULL, GetInetConfHash, InetCfgSubst, NULL, CTX_INETCFG, CTX_NONE, IT_NOFLAG);
219 RegisterNamespace("SERVCFG:FLUSHINETCFG",0, 0, DeleteInetConfHash, NULL, CTX_NONE);