4 * 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") },
34 { HKEY("spamassassin") },
35 { HKEY("masqdomain") },
43 * display the inet config dialog
45 void load_inetconf(void)
48 StrBuf *Buf, *CfgToken, *Value;
54 WCC->InetCfg = NewHash(1, NULL);
56 for (i = 0; i < (sizeof(CfgNames) / sizeof(ConstStrBuf)); i++) {
57 Hash = NewHash(1, NULL);
58 Put(WCC->InetCfg, CfgNames[i].name, CfgNames[i].len, Hash, HDeleteHash);
61 serv_printf("CONF GETSYS|application/x-citadel-internet-config");
63 StrBuf_ServGetln(Buf);
65 if (GetServerStatus(Buf, NULL) == 1) {
66 CfgToken = NewStrBuf();
67 while ((len = StrBuf_ServGetln(Buf),
68 strcmp(ChrPtr(Buf), "000"))) {
71 StrBufExtract_token(CfgToken, Buf, 1, '|');
72 StrBufExtract_token(Value, Buf, 0, '|');
73 GetHash(WCC->InetCfg, ChrPtr(CfgToken), StrLength(CfgToken), &vHash);
74 Hash = (HashList*) vHash;
76 lprintf(1, "ERROR Loading inet config line: [%s]\n",
81 nUsed = GetCount(Hash);
82 nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
83 Put(Hash, nnn, nUsed, Value, HFreeStrBuf);
85 FreeStrBuf(&CfgToken);
92 * save changes to the inet config
94 void new_save_inetconf(void) {
99 const StrBuf *eType, *eNum, *eName;
105 eType = sbstr("etype");
107 GetHash(WCC->InetCfg, ChrPtr(eType), StrLength(eType), &vHash);
108 Hash = (HashList*) vHash;
110 StrBufPrintf(WCC->ImportantMsg, _("Invalid Parameter"));
115 if (strcasecmp(bstr("oper"), "delete") == 0) {
116 eNum = sbstr("ename");
117 if (!GetHash(Hash, ChrPtr(eNum), StrLength(eNum), &vStr) ||
119 StrBufPrintf(WCC->ImportantMsg, _("Invalid Parameter"));
125 StrBufPrintf(WCC->ImportantMsg, _("%s has been deleted."), ChrPtr(Str));
128 else if (!strcasecmp(bstr("oper"), "add")) {
129 eName = sbstr("ename");
131 StrBufPrintf(WCC->ImportantMsg, _("Invalid Parameter"));
136 nUsed = GetCount(Hash);
137 nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
139 Put(Hash, nnn, nUsed, NewStrBufDup(eName), HFreeStrBuf);
140 StrBufPrintf(WCC->ImportantMsg, "%s %s",
141 /*<domain> added status message*/ _("added."),
146 serv_printf("CONF PUTSYS|application/x-citadel-internet-config");
147 StrBuf_ServGetln(Buf);
148 if (GetServerStatus(Buf, NULL) == 4) {
149 for (i = 0; i < (sizeof(CfgNames) / sizeof(ConstStrBuf)); i++) {
154 GetHash(WCC->InetCfg, CfgNames[i].name, CfgNames[i].len, &vHash);
155 Hash = (HashList*) vHash;
157 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
161 if (GetCount(Hash) > 0) {
162 where = GetNewHashPos(Hash, 0);
163 while (GetNextHashPos(Hash, where, &KeyLen, &Key, &vStr)) {
164 Str = (StrBuf*) vStr;
165 if ((Str!= NULL) && (StrLength(Str) > 0))
170 DeleteHashPos(&where);
174 DeleteHash(&WCC->InetCfg);
180 void InetCfgSubst(StrBuf *TemplBuffer, WCTemplputParams *TP)
182 SVPutBuf("SERVCFG:INET:HOSTNAME", CTX, 1);
185 void DeleteInetConfHash(StrBuf *Target, WCTemplputParams *TP)
189 if (WCC->InetCfg != NULL)
190 DeleteHash(&WCC->InetCfg);
195 HashList *GetInetConfHash(StrBuf *Target, WCTemplputParams *TP)
200 if (WCC->InetCfg == NULL)
202 GetHash(WCC->InetCfg, TKEY(5), &vHash);
203 svprintf(HKEY("SERVCFG:INET:TYPE"), WCS_STRING, TP->Tokens->Params[5]->Start);
211 WebcitAddUrlHandler(HKEY("save_inetconf"), new_save_inetconf, 0);
212 RegisterIterator("SERVCFG:INET", 1, NULL, GetInetConfHash, InetCfgSubst, NULL, CTX_INETCFG, CTX_NONE, IT_NOFLAG);
213 RegisterNamespace("SERVCFG:FLUSHINETCFG",0, 0, DeleteInetConfHash, CTX_NONE);