5 * \defgroup NetShareConf Functions which handle network and sharing configuration.
7 * \ingroup CitadelConfig
12 void display_netconf(void);
14 /*----------------------------------------------------------------------*/
16 /*----------------------------------------------------------------------*/
18 typedef struct _nodeconf {
26 void DeleteNodeConf(void *vNode)
28 NodeConf *Node = (NodeConf*) vNode;
29 FreeStrBuf(&Node->NodeName);
30 FreeStrBuf(&Node->Secret);
31 FreeStrBuf(&Node->Host);
32 FreeStrBuf(&Node->Port);
36 NodeConf *NewNode(StrBuf *SerializedNode)
40 if (StrLength(SerializedNode) < 8)
41 return NULL; /** we need at least 4 pipes and some other text so its invalid. */
42 Node = (NodeConf *) malloc(sizeof(NodeConf));
44 Node->NodeName=NewStrBuf();
45 StrBufExtract_token(Node->NodeName, SerializedNode, 0, '|');
46 Node->Secret=NewStrBuf();
47 StrBufExtract_token(Node->Secret, SerializedNode, 1, '|');
48 Node->Host=NewStrBuf();
49 StrBufExtract_token(Node->Host, SerializedNode, 2, '|');
50 Node->Port=NewStrBuf();
51 StrBufExtract_token(Node->Port, SerializedNode, 3, '|');
55 NodeConf *HttpGetNewNode(void)
59 if (!havebstr("node") ||
65 Node = (NodeConf *) malloc(sizeof(NodeConf));
67 Node->NodeName = NewStrBufDup(sbstr("node"));
68 Node->Secret = NewStrBufDup(sbstr("secret"));
69 Node->Host = NewStrBufDup(sbstr("host"));
70 Node->Port = NewStrBufDup(sbstr("port"));
74 void SerializeNode(NodeConf *Node, StrBuf *Buf)
76 StrBufPrintf(Buf, "%s|%s|%s|%s",
77 ChrPtr(Node->NodeName),
84 HashList *load_netconf(StrBuf *Target, WCTemplputParams *TP)
94 serv_puts("CONF getsys|application/x-citadel-ignet-config");
95 serv_getln(buf, sizeof buf);
97 Hash = NewHash(1, NULL);
100 while ((len = StrBuf_ServGetln(Buf),
101 strcmp(ChrPtr(Buf), "000"))) {
105 nUsed = GetCount(Hash);
106 nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
107 Put(Hash, nnn, nUsed, Node, DeleteNodeConf);
117 void save_net_conf(HashList *Nodelist)
127 serv_puts("CONF putsys|application/x-citadel-ignet-config");
128 serv_getln(buf, sizeof buf);
130 if ((Nodelist != NULL) && (GetCount(Nodelist) > 0)) {
131 where = GetNewHashPos(Nodelist, 0);
133 while (GetNextHashPos(Nodelist, where, &KeyLen, &Key, &vNode)) {
134 Node = (NodeConf*) vNode;
135 if (Node->DeleteMe==0) {
136 SerializeNode(Node, Buf);
148 /*----------------------------------------------------------------------*/
150 /*----------------------------------------------------------------------*/
155 * \brief edit a network node
157 void edit_node(void) {
158 HashList *NodeConfig;
162 if (havebstr("ok_button")) {
163 Index = sbstr("index");
164 NewNode = HttpGetNewNode();
165 if ((NewNode == NULL) || (Index == NULL)) {
166 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
171 NodeConfig = load_netconf(NULL, &NoCtx);
172 Put(NodeConfig, ChrPtr(Index), StrLength(Index), NewNode, DeleteNodeConf);
173 save_net_conf(NodeConfig);
174 DeleteHash(&NodeConfig);
181 * \brief modify an existing node
183 void display_edit_node(void)
185 WCTemplputParams SubTP;
186 HashList *NodeConfig;
191 Index = sbstr("index");
193 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
198 NodeConfig = load_netconf(NULL, &NoCtx);
199 if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) ||
201 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
203 DeleteHash(&NodeConfig);
207 memset(&SubTP, 0, sizeof(WCTemplputParams));
208 SVPutBuf("ITERATE:KEY", Index, 1);
209 SubTP.Filter.ContextType = CTX_NODECONF;
210 SubTP.Context = vNode;
212 Tmpl = sbstr("template");
213 output_headers(1, 0, 0, 0, 1, 0);
214 DoTemplate(SKEY(Tmpl), NULL, &SubTP);
216 DeleteHash(&NodeConfig);
222 * \brief display all configured nodes
224 void display_netconf(void)
230 * \brief display the dialog to verify the deletion
232 void display_confirm_delete_node(void)
239 * \brief actually delete the node
241 void delete_node(void)
243 HashList *NodeConfig;
248 Index = sbstr("index");
250 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
255 NodeConfig = load_netconf(NULL, &NoCtx);
256 if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) ||
258 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
260 DeleteHash(&NodeConfig);
263 Node = (NodeConf *) vNode;
265 save_net_conf(NodeConfig);
266 DeleteHash(&NodeConfig);
273 void tmplput_NodeName(StrBuf *Target, WCTemplputParams *TP)
275 NodeConf *Node = (NodeConf*) CTX;
276 StrBufAppendTemplate(Target, TP, Node->NodeName, 0);
279 void tmplput_Secret(StrBuf *Target, WCTemplputParams *TP)
281 NodeConf *Node = (NodeConf*) CTX;
282 StrBufAppendTemplate(Target, TP, Node->Secret, 0);
285 void tmplput_Host(StrBuf *Target, WCTemplputParams *TP)
287 NodeConf *Node= (NodeConf*) CTX;
288 StrBufAppendTemplate(Target, TP, Node->Host, 0);
291 void tmplput_Port(StrBuf *Target, WCTemplputParams *TP)
293 NodeConf *Node= (NodeConf*) CTX;
294 StrBufAppendTemplate(Target, TP, Node->Port, 0);
301 WebcitAddUrlHandler(HKEY("display_edit_node"), "", 0, display_edit_node, 0);
303 WebcitAddUrlHandler(HKEY("aide_ignetconf_edit_node"), "", 0, edit_node, 0);
304 WebcitAddUrlHandler(HKEY("display_netconf"), "", 0, display_netconf, 0);
305 WebcitAddUrlHandler(HKEY("display_confirm_delete_node"), "", 0, display_confirm_delete_node, 0);
306 WebcitAddUrlHandler(HKEY("delete_node"), "", 0, delete_node, 0);
309 RegisterNamespace("CFG:IGNET:NODE", 0, 1, tmplput_NodeName, NULL, CTX_NODECONF);
310 RegisterNamespace("CFG:IGNET:SECRET", 0, 1, tmplput_Secret, NULL, CTX_NODECONF);
311 RegisterNamespace("CFG:IGNET:HOST", 0, 1, tmplput_Host, NULL, CTX_NODECONF);
312 RegisterNamespace("CFG:IGNET:PORT", 0, 1, tmplput_Port, NULL, CTX_NODECONF);
314 RegisterIterator("NODECONFIG", 0, NULL, load_netconf, NULL, DeleteHash, CTX_NODECONF, CTX_NONE, IT_NOFLAG);