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, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
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);
116 void NodeCfgSubst(StrBuf *TemplBuffer, void *vContext, WCTemplateToken *Token)
118 NodeConf *Node= (NodeConf*)vContext;
120 SVPutBuf("CFG:IGNET:NODE", Node->NodeName, 1);
121 SVPutBuf("CFG:IGNET:SECRET", Node->Secret, 1);
122 SVPutBuf("CFG:IGNET:HOST", Node->Host, 1);
123 SVPutBuf("CFG:IGNET:PORT", Node->Port, 1);
127 void save_net_conf(HashList *Nodelist)
137 serv_puts("CONF putsys|application/x-citadel-ignet-config");
138 serv_getln(buf, sizeof buf);
140 if ((Nodelist != NULL) && (GetCount(Nodelist) > 0)) {
141 where = GetNewHashPos(Nodelist, 0);
143 while (GetNextHashPos(Nodelist, where, &KeyLen, &Key, &vNode)) {
144 Node = (NodeConf*) vNode;
145 if (Node->DeleteMe==0) {
146 SerializeNode(Node, Buf);
158 /*----------------------------------------------------------------------*/
160 /*----------------------------------------------------------------------*/
165 * \brief edit a network node
167 void edit_node(void) {
168 HashList *NodeConfig;
172 if (havebstr("ok_button")) {
173 Index = sbstr("index");
174 NewNode = HttpGetNewNode();
175 if ((NewNode == NULL) || (Index == NULL)) {
176 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
181 NodeConfig = load_netconf(NULL, 0, NULL, NULL, CTX_NONE);
182 Put(NodeConfig, ChrPtr(Index), StrLength(Index), NewNode, DeleteNodeConf);
183 save_net_conf(NodeConfig);
184 DeleteHash(&NodeConfig);
191 * \brief modify an existing node
193 void display_edit_node(void)
195 HashList *NodeConfig;
199 Index = sbstr("index");
201 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
206 NodeConfig = load_netconf(NULL, 0, NULL, NULL, CTX_NONE);
207 if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) ||
209 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
211 DeleteHash(&NodeConfig);
215 NodeCfgSubst(NULL, vNode, NULL);
216 SVPutBuf("ITERATE:KEY", Index, 1);
219 DeleteHash(&NodeConfig);
225 * \brief display all configured nodes
227 void display_netconf(void)
233 * \brief display the dialog to verify the deletion
235 void display_confirm_delete_node(void)
242 * \brief actually delete the node
244 void delete_node(void)
246 HashList *NodeConfig;
251 Index = sbstr("index");
253 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
258 NodeConfig = load_netconf(NULL, 0, NULL, NULL, CTX_NONE);
259 if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) ||
261 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
263 DeleteHash(&NodeConfig);
266 Node = (NodeConf *) vNode;
268 save_net_conf(NodeConfig);
269 DeleteHash(&NodeConfig);
279 WebcitAddUrlHandler(HKEY("display_edit_node"), display_edit_node, 0);
281 WebcitAddUrlHandler(HKEY("edit_node"), edit_node, 0);
282 WebcitAddUrlHandler(HKEY("display_netconf"), display_netconf, 0);
283 WebcitAddUrlHandler(HKEY("display_confirm_delete_node"), display_confirm_delete_node, 0);
284 WebcitAddUrlHandler(HKEY("delete_node"), delete_node, 0);
285 RegisterIterator("NODECONFIG", 0, NULL, load_netconf, NodeCfgSubst, DeleteHash, CTX_NODECONF, CTX_NONE);