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),
92 (len != 3) || !strcmp(ChrPtr(Buf), "000"))) {
96 nUsed = GetCount(Hash);
97 nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
98 Put(Hash, nnn, nUsed, Node, DeleteNodeConf);
108 void save_net_conf(HashList *Nodelist)
118 serv_puts("CONF putsys|application/x-citadel-ignet-config");
119 serv_getln(buf, sizeof buf);
121 if ((Nodelist != NULL) && (GetCount(Nodelist) > 0)) {
122 where = GetNewHashPos(Nodelist, 0);
124 while (GetNextHashPos(Nodelist, where, &KeyLen, &Key, &vNode)) {
125 Node = (NodeConf*) vNode;
126 if (Node->DeleteMe==0) {
127 SerializeNode(Node, Buf);
132 DeleteHashPos(&where);
140 /*----------------------------------------------------------------------*/
142 /*----------------------------------------------------------------------*/
147 * edit a network node
149 void edit_node(void) {
150 HashList *NodeConfig;
154 if (havebstr("ok_button")) {
155 Index = sbstr("index");
156 NewNode = HttpGetNewNode();
157 if ((NewNode == NULL) || (Index == NULL)) {
158 AppendImportantMessage(_("Invalid Parameter"), -1);
163 NodeConfig = load_netconf(NULL, &NoCtx);
164 Put(NodeConfig, ChrPtr(Index), StrLength(Index), NewNode, DeleteNodeConf);
165 save_net_conf(NodeConfig);
166 DeleteHash(&NodeConfig);
173 * modify an existing node
175 void display_edit_node(void)
177 WCTemplputParams SubTP;
178 HashList *NodeConfig;
183 Index = sbstr("index");
185 AppendImportantMessage(_("Invalid Parameter"), -1);
190 NodeConfig = load_netconf(NULL, &NoCtx);
191 if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) ||
193 AppendImportantMessage(_("Invalid Parameter"), -1);
195 DeleteHash(&NodeConfig);
199 memset(&SubTP, 0, sizeof(WCTemplputParams));
200 SubTP.Filter.ContextType = CTX_NODECONF;
201 SubTP.Context = vNode;
203 Tmpl = sbstr("template");
204 output_headers(1, 0, 0, 0, 1, 0);
205 DoTemplate(SKEY(Tmpl), NULL, &SubTP);
207 DeleteHash(&NodeConfig);
213 * display all configured nodes
215 void display_netconf(void)
221 * display the dialog to verify the deletion
223 void display_confirm_delete_node(void)
230 * actually delete the node
232 void delete_node(void)
234 HashList *NodeConfig;
239 Index = sbstr("index");
241 AppendImportantMessage(_("Invalid Parameter"), -1);
246 NodeConfig = load_netconf(NULL, &NoCtx);
247 if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) ||
249 AppendImportantMessage(_("Invalid Parameter"), -1);
251 DeleteHash(&NodeConfig);
254 Node = (NodeConf *) vNode;
256 save_net_conf(NodeConfig);
257 DeleteHash(&NodeConfig);
264 void tmplput_NodeName(StrBuf *Target, WCTemplputParams *TP)
266 NodeConf *Node = (NodeConf*) CTX;
267 StrBufAppendTemplate(Target, TP, Node->NodeName, 0);
270 void tmplput_Secret(StrBuf *Target, WCTemplputParams *TP)
272 NodeConf *Node = (NodeConf*) CTX;
273 StrBufAppendTemplate(Target, TP, Node->Secret, 0);
276 void tmplput_Host(StrBuf *Target, WCTemplputParams *TP)
278 NodeConf *Node= (NodeConf*) CTX;
279 StrBufAppendTemplate(Target, TP, Node->Host, 0);
282 void tmplput_Port(StrBuf *Target, WCTemplputParams *TP)
284 NodeConf *Node= (NodeConf*) CTX;
285 StrBufAppendTemplate(Target, TP, Node->Port, 0);
292 WebcitAddUrlHandler(HKEY("display_edit_node"), "", 0, display_edit_node, 0);
294 WebcitAddUrlHandler(HKEY("aide_ignetconf_edit_node"), "", 0, edit_node, 0);
295 WebcitAddUrlHandler(HKEY("display_netconf"), "", 0, display_netconf, 0);
296 WebcitAddUrlHandler(HKEY("display_confirm_delete_node"), "", 0, display_confirm_delete_node, 0);
297 WebcitAddUrlHandler(HKEY("delete_node"), "", 0, delete_node, 0);
300 RegisterNamespace("CFG:IGNET:NODE", 0, 1, tmplput_NodeName, NULL, CTX_NODECONF);
301 RegisterNamespace("CFG:IGNET:SECRET", 0, 1, tmplput_Secret, NULL, CTX_NODECONF);
302 RegisterNamespace("CFG:IGNET:HOST", 0, 1, tmplput_Host, NULL, CTX_NODECONF);
303 RegisterNamespace("CFG:IGNET:PORT", 0, 1, tmplput_Port, NULL, CTX_NODECONF);
305 RegisterIterator("NODECONFIG", 0, NULL, load_netconf, NULL, DeleteHash, CTX_NODECONF, CTX_NONE, IT_NOFLAG);