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)
84 serv_puts("CONF getsys|application/x-citadel-ignet-config");
85 serv_getln(buf, sizeof buf);
87 Hash = NewHash(1, NULL);
90 while (StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) {
93 nUsed = GetCount(Hash);
94 nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
95 Put(Hash, nnn, nUsed, Node, DeleteNodeConf);
106 void save_net_conf(HashList *Nodelist)
116 serv_puts("CONF putsys|application/x-citadel-ignet-config");
117 serv_getln(buf, sizeof buf);
119 if ((Nodelist != NULL) && (GetCount(Nodelist) > 0)) {
120 where = GetNewHashPos(Nodelist, 0);
122 while (GetNextHashPos(Nodelist, where, &KeyLen, &Key, &vNode)) {
123 Node = (NodeConf*) vNode;
124 if (Node->DeleteMe==0) {
125 SerializeNode(Node, Buf);
130 DeleteHashPos(&where);
138 /*----------------------------------------------------------------------*/
140 /*----------------------------------------------------------------------*/
145 * edit a network node
147 void edit_node(void) {
148 HashList *NodeConfig;
152 if (havebstr("ok_button")) {
153 Index = sbstr("index");
154 NewNode = HttpGetNewNode();
155 if ((NewNode == NULL) || (Index == NULL)) {
156 AppendImportantMessage(_("Invalid Parameter"), -1);
161 NodeConfig = load_netconf(NULL, &NoCtx);
162 Put(NodeConfig, ChrPtr(Index), StrLength(Index), NewNode, DeleteNodeConf);
163 save_net_conf(NodeConfig);
164 DeleteHash(&NodeConfig);
171 * modify an existing node
173 void display_edit_node(void)
175 WCTemplputParams SubTP;
176 HashList *NodeConfig;
181 Index = sbstr("index");
183 AppendImportantMessage(_("Invalid Parameter"), -1);
188 NodeConfig = load_netconf(NULL, &NoCtx);
189 if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) ||
191 AppendImportantMessage(_("Invalid Parameter"), -1);
193 DeleteHash(&NodeConfig);
196 StackContext(NULL, &SubTP, vNode, CTX_NODECONF, 0, NULL);
199 Tmpl = sbstr("template");
200 output_headers(1, 0, 0, 0, 1, 0);
201 DoTemplate(SKEY(Tmpl), NULL, &SubTP);
204 UnStackContext(&SubTP);
205 DeleteHash(&NodeConfig);
211 * display all configured nodes
213 void display_netconf(void)
219 * display the dialog to verify the deletion
221 void display_confirm_delete_node(void)
228 * actually delete the node
230 void delete_node(void)
232 HashList *NodeConfig;
237 Index = sbstr("index");
239 AppendImportantMessage(_("Invalid Parameter"), -1);
244 NodeConfig = load_netconf(NULL, &NoCtx);
245 if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) ||
247 AppendImportantMessage(_("Invalid Parameter"), -1);
249 DeleteHash(&NodeConfig);
252 Node = (NodeConf *) vNode;
254 save_net_conf(NodeConfig);
255 DeleteHash(&NodeConfig);
262 void tmplput_NodeName(StrBuf *Target, WCTemplputParams *TP)
264 NodeConf *Node = (NodeConf*) CTX(CTX_NODECONF);
265 StrBufAppendTemplate(Target, TP, Node->NodeName, 0);
268 void tmplput_Secret(StrBuf *Target, WCTemplputParams *TP)
270 NodeConf *Node = (NodeConf*) CTX(CTX_NODECONF);
271 StrBufAppendTemplate(Target, TP, Node->Secret, 0);
274 void tmplput_Host(StrBuf *Target, WCTemplputParams *TP)
276 NodeConf *Node= (NodeConf*) CTX(CTX_NODECONF);
277 StrBufAppendTemplate(Target, TP, Node->Host, 0);
280 void tmplput_Port(StrBuf *Target, WCTemplputParams *TP)
282 NodeConf *Node= (NodeConf*) CTX(CTX_NODECONF);
283 StrBufAppendTemplate(Target, TP, Node->Port, 0);
290 WebcitAddUrlHandler(HKEY("display_edit_node"), "", 0, display_edit_node, 0);
292 WebcitAddUrlHandler(HKEY("aide_ignetconf_edit_node"), "", 0, edit_node, 0);
293 WebcitAddUrlHandler(HKEY("display_netconf"), "", 0, display_netconf, 0);
294 WebcitAddUrlHandler(HKEY("display_confirm_delete_node"), "", 0, display_confirm_delete_node, 0);
295 WebcitAddUrlHandler(HKEY("delete_node"), "", 0, delete_node, 0);
298 RegisterNamespace("CFG:IGNET:NODE", 0, 1, tmplput_NodeName, NULL, CTX_NODECONF);
299 RegisterNamespace("CFG:IGNET:SECRET", 0, 1, tmplput_Secret, NULL, CTX_NODECONF);
300 RegisterNamespace("CFG:IGNET:HOST", 0, 1, tmplput_Host, NULL, CTX_NODECONF);
301 RegisterNamespace("CFG:IGNET:PORT", 0, 1, tmplput_Port, NULL, CTX_NODECONF);
303 RegisterIterator("NODECONFIG", 0, NULL, load_netconf, NULL, DeleteHash, CTX_NODECONF, CTX_NONE, IT_NOFLAG);