3 void display_netconf(void);
5 CtxType CTX_NODECONF = CTX_NONE;
7 /*----------------------------------------------------------------------*/
11 /*----------------------------------------------------------------------*/
13 typedef struct _nodeconf {
21 void DeleteNodeConf(void *vNode) {
22 NodeConf *Node = (NodeConf *) vNode;
23 FreeStrBuf(&Node->NodeName);
24 FreeStrBuf(&Node->Secret);
25 FreeStrBuf(&Node->Host);
26 FreeStrBuf(&Node->Port);
30 NodeConf *NewNode(StrBuf * SerializedNode) {
33 if (StrLength(SerializedNode) < 8)
35 return NULL; /** we need at least 4 pipes and some other text so its invalid. */
36 Node = (NodeConf *) malloc(sizeof(NodeConf));
38 Node->NodeName = NewStrBuf();
39 StrBufExtract_token(Node->NodeName, SerializedNode, 0, '|');
40 Node->Secret = NewStrBuf();
41 StrBufExtract_token(Node->Secret, SerializedNode, 1, '|');
42 Node->Host = NewStrBuf();
43 StrBufExtract_token(Node->Host, SerializedNode, 2, '|');
44 Node->Port = NewStrBuf();
45 StrBufExtract_token(Node->Port, SerializedNode, 3, '|');
49 NodeConf *HttpGetNewNode(void) {
52 if (!havebstr("node") || !havebstr("secret") || !havebstr("host") || !havebstr("port"))
55 Node = (NodeConf *) malloc(sizeof(NodeConf));
57 Node->NodeName = NewStrBufDup(sbstr("node"));
58 Node->Secret = NewStrBufDup(sbstr("secret"));
59 Node->Host = NewStrBufDup(sbstr("host"));
60 Node->Port = NewStrBufDup(sbstr("port"));
64 void SerializeNode(NodeConf * Node, StrBuf * Buf) {
65 StrBufPrintf(Buf, "%s|%s|%s|%s", ChrPtr(Node->NodeName), ChrPtr(Node->Secret), ChrPtr(Node->Host), ChrPtr(Node->Port));
69 HashList *load_netconf(StrBuf * Target, WCTemplputParams * TP) {
77 serv_puts("CONF getsys|application/x-citadel-ignet-config");
78 serv_getln(buf, sizeof buf);
80 Hash = NewHash(1, NULL);
83 while (StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) {
86 nUsed = GetCount(Hash);
87 nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed + 1);
88 Put(Hash, nnn, nUsed, Node, DeleteNodeConf);
99 void save_net_conf(HashList * Nodelist) {
108 serv_puts("CONF putsys|application/x-citadel-ignet-config");
109 serv_getln(buf, sizeof buf);
111 if ((Nodelist != NULL) && (GetCount(Nodelist) > 0)) {
112 where = GetNewHashPos(Nodelist, 0);
114 while (GetNextHashPos(Nodelist, where, &KeyLen, &Key, &vNode)) {
115 Node = (NodeConf *) vNode;
116 if (Node->DeleteMe == 0) {
117 SerializeNode(Node, Buf);
122 DeleteHashPos(&where);
130 /*----------------------------------------------------------------------*/
134 /*----------------------------------------------------------------------*/
139 * edit a network node
141 void edit_node(void) {
142 HashList *NodeConfig;
146 if (havebstr("ok_button")) {
147 Index = sbstr("index");
148 NewNode = HttpGetNewNode();
149 if ((NewNode == NULL) || (Index == NULL)) {
150 AppendImportantMessage(_("Invalid Parameter"), -1);
155 NodeConfig = load_netconf(NULL, &NoCtx);
156 Put(NodeConfig, ChrPtr(Index), StrLength(Index), NewNode, DeleteNodeConf);
157 save_net_conf(NodeConfig);
158 DeleteHash(&NodeConfig);
165 * modify an existing node
167 void display_edit_node(void) {
168 WCTemplputParams SubTP;
169 HashList *NodeConfig;
174 Index = sbstr("index");
176 AppendImportantMessage(_("Invalid Parameter"), -1);
181 NodeConfig = load_netconf(NULL, &NoCtx);
182 if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) || (vNode == NULL)) {
183 AppendImportantMessage(_("Invalid Parameter"), -1);
185 DeleteHash(&NodeConfig);
188 StackContext(NULL, &SubTP, vNode, CTX_NODECONF, 0, NULL);
191 Tmpl = sbstr("template");
192 output_headers(1, 0, 0, 0, 1, 0);
193 DoTemplate(SKEY(Tmpl), NULL, &SubTP);
196 UnStackContext(&SubTP);
197 DeleteHash(&NodeConfig);
203 * display all configured nodes
205 void display_netconf(void) {
210 * display the dialog to verify the deletion
212 void display_confirm_delete_node(void) {
218 * actually delete the node
220 void delete_node(void) {
221 HashList *NodeConfig;
226 Index = sbstr("index");
228 AppendImportantMessage(_("Invalid Parameter"), -1);
233 NodeConfig = load_netconf(NULL, &NoCtx);
234 if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) || (vNode == NULL)) {
235 AppendImportantMessage(_("Invalid Parameter"), -1);
237 DeleteHash(&NodeConfig);
240 Node = (NodeConf *) vNode;
242 save_net_conf(NodeConfig);
243 DeleteHash(&NodeConfig);
250 void tmplput_NodeName(StrBuf * Target, WCTemplputParams * TP) {
251 NodeConf *Node = (NodeConf *) CTX(CTX_NODECONF);
252 StrBufAppendTemplate(Target, TP, Node->NodeName, 0);
255 void tmplput_Secret(StrBuf * Target, WCTemplputParams * TP) {
256 NodeConf *Node = (NodeConf *) CTX(CTX_NODECONF);
257 StrBufAppendTemplate(Target, TP, Node->Secret, 0);
260 void tmplput_Host(StrBuf * Target, WCTemplputParams * TP) {
261 NodeConf *Node = (NodeConf *) CTX(CTX_NODECONF);
262 StrBufAppendTemplate(Target, TP, Node->Host, 0);
265 void tmplput_Port(StrBuf * Target, WCTemplputParams * TP) {
266 NodeConf *Node = (NodeConf *) CTX(CTX_NODECONF);
267 StrBufAppendTemplate(Target, TP, Node->Port, 0);
270 void InitModule_NETCONF(void) {
271 RegisterCTX(CTX_NODECONF);
272 WebcitAddUrlHandler(HKEY("display_edit_node"), "", 0, display_edit_node, 0);
274 WebcitAddUrlHandler(HKEY("aide_ignetconf_edit_node"), "", 0, edit_node, 0);
275 WebcitAddUrlHandler(HKEY("display_netconf"), "", 0, display_netconf, 0);
276 WebcitAddUrlHandler(HKEY("display_confirm_delete_node"), "", 0, display_confirm_delete_node, 0);
277 WebcitAddUrlHandler(HKEY("delete_node"), "", 0, delete_node, 0);
280 RegisterNamespace("CFG:IGNET:NODE", 0, 1, tmplput_NodeName, NULL, CTX_NODECONF);
281 RegisterNamespace("CFG:IGNET:SECRET", 0, 1, tmplput_Secret, NULL, CTX_NODECONF);
282 RegisterNamespace("CFG:IGNET:HOST", 0, 1, tmplput_Host, NULL, CTX_NODECONF);
283 RegisterNamespace("CFG:IGNET:PORT", 0, 1, tmplput_Port, NULL, CTX_NODECONF);
285 RegisterIterator("NODECONFIG", 0, NULL, load_netconf, NULL, DeleteHash, CTX_NODECONF, CTX_NONE, IT_NOFLAG);