4 * Functions which handle Internet domain configuration etc.
23 typedef struct _ConstStrBuf {
29 /* These are server config keywords; do not localize! */
30 ConstStrBuf CfgNames[] = {
31 { HKEY("localhost") },
32 { HKEY("directory") },
33 { HKEY("smarthost") },
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")) {
131 eName = sbstr("ename");
133 StrBufPrintf(WCC->ImportantMsg, _("Invalid Parameter"));
138 nUsed = GetCount(Hash);
139 nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
141 Put(Hash, nnn, nUsed, NewStrBufDup(eName), HFreeStrBuf);
142 StrBufPrintf(WCC->ImportantMsg, "%s %s",
143 /*<domain> added status message*/ _("added."),
148 serv_printf("CONF PUTSYS|application/x-citadel-internet-config");
149 StrBuf_ServGetln(Buf);
150 if (GetServerStatus(Buf, NULL) == 4) {
151 for (i = 0; i < (sizeof(CfgNames) / sizeof(ConstStrBuf)); i++) {
156 GetHash(WCC->InetCfg, CfgNames[i].name, CfgNames[i].len, &vHash);
157 Hash = (HashList*) vHash;
159 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
163 if (GetCount(Hash) > 0) {
164 where = GetNewHashPos(Hash, 0);
165 while (GetNextHashPos(Hash, where, &KeyLen, &Key, &vStr)) {
166 Str = (StrBuf*) vStr;
167 if ((Str!= NULL) && (StrLength(Str) > 0))
172 DeleteHashPos(&where);
176 DeleteHash(&WCC->InetCfg);
182 void InetCfgSubst(StrBuf *TemplBuffer, WCTemplputParams *TP)
184 SVPutBuf("SERVCFG:INET:HOSTNAME", CTX, 1);
187 void DeleteInetConfHash(StrBuf *Target, WCTemplputParams *TP)
191 if (WCC->InetCfg != NULL)
192 DeleteHash(&WCC->InetCfg);
197 HashList *GetInetConfHash(StrBuf *Target, WCTemplputParams *TP)
202 if (WCC->InetCfg == NULL)
204 GetHash(WCC->InetCfg, TKEY(5), &vHash);
205 svprintf(HKEY("SERVCFG:INET:TYPE"), WCS_STRING, TP->Tokens->Params[5]->Start);
213 WebcitAddUrlHandler(HKEY("save_inetconf"), new_save_inetconf, 0);
214 RegisterIterator("SERVCFG:INET", 1, NULL, GetInetConfHash, InetCfgSubst, NULL, CTX_INETCFG, CTX_NONE, IT_NOFLAG);
215 RegisterNamespace("SERVCFG:FLUSHINETCFG",0, 0, DeleteInetConfHash, CTX_NONE);