3 void display_netconf(void);
5 /*----------------------------------------------------------------------*/
7 /*----------------------------------------------------------------------*/
9 typedef struct _nodeconf {
17 void DeleteNodeConf(void *vNode)
19 NodeConf *Node = (NodeConf*) vNode;
20 FreeStrBuf(&Node->NodeName);
21 FreeStrBuf(&Node->Secret);
22 FreeStrBuf(&Node->Host);
23 FreeStrBuf(&Node->Port);
27 NodeConf *NewNode(StrBuf *SerializedNode)
31 if (StrLength(SerializedNode) < 8)
32 return NULL; /** we need at least 4 pipes and some other text so its invalid. */
33 Node = (NodeConf *) malloc(sizeof(NodeConf));
35 Node->NodeName=NewStrBuf();
36 StrBufExtract_token(Node->NodeName, SerializedNode, 0, '|');
37 Node->Secret=NewStrBuf();
38 StrBufExtract_token(Node->Secret, SerializedNode, 1, '|');
39 Node->Host=NewStrBuf();
40 StrBufExtract_token(Node->Host, SerializedNode, 2, '|');
41 Node->Port=NewStrBuf();
42 StrBufExtract_token(Node->Port, SerializedNode, 3, '|');
46 NodeConf *HttpGetNewNode(void)
50 if (!havebstr("node") ||
56 Node = (NodeConf *) malloc(sizeof(NodeConf));
58 Node->NodeName = NewStrBufDup(sbstr("node"));
59 Node->Secret = NewStrBufDup(sbstr("secret"));
60 Node->Host = NewStrBufDup(sbstr("host"));
61 Node->Port = NewStrBufDup(sbstr("port"));
65 void SerializeNode(NodeConf *Node, StrBuf *Buf)
67 StrBufPrintf(Buf, "%s|%s|%s|%s",
68 ChrPtr(Node->NodeName),
75 HashList *load_netconf(StrBuf *Target, WCTemplputParams *TP)
85 serv_puts("CONF getsys|application/x-citadel-ignet-config");
86 serv_getln(buf, sizeof buf);
88 Hash = NewHash(1, NULL);
91 while (len = StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) {
94 nUsed = GetCount(Hash);
95 nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
96 Put(Hash, nnn, nUsed, Node, DeleteNodeConf);
107 void save_net_conf(HashList *Nodelist)
117 serv_puts("CONF putsys|application/x-citadel-ignet-config");
118 serv_getln(buf, sizeof buf);
120 if ((Nodelist != NULL) && (GetCount(Nodelist) > 0)) {
121 where = GetNewHashPos(Nodelist, 0);
123 while (GetNextHashPos(Nodelist, where, &KeyLen, &Key, &vNode)) {
124 Node = (NodeConf*) vNode;
125 if (Node->DeleteMe==0) {
126 SerializeNode(Node, Buf);
131 DeleteHashPos(&where);
139 /*----------------------------------------------------------------------*/
141 /*----------------------------------------------------------------------*/
146 * edit a network node
148 void edit_node(void) {
149 HashList *NodeConfig;
153 if (havebstr("ok_button")) {
154 Index = sbstr("index");
155 NewNode = HttpGetNewNode();
156 if ((NewNode == NULL) || (Index == NULL)) {
157 AppendImportantMessage(_("Invalid Parameter"), -1);
162 NodeConfig = load_netconf(NULL, &NoCtx);
163 Put(NodeConfig, ChrPtr(Index), StrLength(Index), NewNode, DeleteNodeConf);
164 save_net_conf(NodeConfig);
165 DeleteHash(&NodeConfig);
172 * modify an existing node
174 void display_edit_node(void)
176 WCTemplputParams SubTP;
177 HashList *NodeConfig;
182 Index = sbstr("index");
184 AppendImportantMessage(_("Invalid Parameter"), -1);
189 NodeConfig = load_netconf(NULL, &NoCtx);
190 if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) ||
192 AppendImportantMessage(_("Invalid Parameter"), -1);
194 DeleteHash(&NodeConfig);
198 memset(&SubTP, 0, sizeof(WCTemplputParams));
199 SubTP.Filter.ContextType = CTX_NODECONF;
200 SubTP.Context = vNode;
202 Tmpl = sbstr("template");
203 output_headers(1, 0, 0, 0, 1, 0);
204 DoTemplate(SKEY(Tmpl), NULL, &SubTP);
206 DeleteHash(&NodeConfig);
212 * display all configured nodes
214 void display_netconf(void)
220 * display the dialog to verify the deletion
222 void display_confirm_delete_node(void)
229 * actually delete the node
231 void delete_node(void)
233 HashList *NodeConfig;
238 Index = sbstr("index");
240 AppendImportantMessage(_("Invalid Parameter"), -1);
245 NodeConfig = load_netconf(NULL, &NoCtx);
246 if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) ||
248 AppendImportantMessage(_("Invalid Parameter"), -1);
250 DeleteHash(&NodeConfig);
253 Node = (NodeConf *) vNode;
255 save_net_conf(NodeConfig);
256 DeleteHash(&NodeConfig);
263 void tmplput_NodeName(StrBuf *Target, WCTemplputParams *TP)
265 NodeConf *Node = (NodeConf*) CTX;
266 StrBufAppendTemplate(Target, TP, Node->NodeName, 0);
269 void tmplput_Secret(StrBuf *Target, WCTemplputParams *TP)
271 NodeConf *Node = (NodeConf*) CTX;
272 StrBufAppendTemplate(Target, TP, Node->Secret, 0);
275 void tmplput_Host(StrBuf *Target, WCTemplputParams *TP)
277 NodeConf *Node= (NodeConf*) CTX;
278 StrBufAppendTemplate(Target, TP, Node->Host, 0);
281 void tmplput_Port(StrBuf *Target, WCTemplputParams *TP)
283 NodeConf *Node= (NodeConf*) CTX;
284 StrBufAppendTemplate(Target, TP, Node->Port, 0);
291 WebcitAddUrlHandler(HKEY("display_edit_node"), "", 0, display_edit_node, 0);
293 WebcitAddUrlHandler(HKEY("aide_ignetconf_edit_node"), "", 0, edit_node, 0);
294 WebcitAddUrlHandler(HKEY("display_netconf"), "", 0, display_netconf, 0);
295 WebcitAddUrlHandler(HKEY("display_confirm_delete_node"), "", 0, display_confirm_delete_node, 0);
296 WebcitAddUrlHandler(HKEY("delete_node"), "", 0, delete_node, 0);
299 RegisterNamespace("CFG:IGNET:NODE", 0, 1, tmplput_NodeName, NULL, CTX_NODECONF);
300 RegisterNamespace("CFG:IGNET:SECRET", 0, 1, tmplput_Secret, NULL, CTX_NODECONF);
301 RegisterNamespace("CFG:IGNET:HOST", 0, 1, tmplput_Host, NULL, CTX_NODECONF);
302 RegisterNamespace("CFG:IGNET:PORT", 0, 1, tmplput_Port, NULL, CTX_NODECONF);
304 RegisterIterator("NODECONFIG", 0, NULL, load_netconf, NULL, DeleteHash, CTX_NODECONF, CTX_NONE, IT_NOFLAG);