Fix lots of warnings all over the place, make inbound buffers of FMOUT const.
[citadel.git] / webcit / netconf.c
index d95c6ea5e15fdbd252702553748d079c075571d6..a62c96526e5f28800e2f4c6765f8307d0c22d71b 100644 (file)
@@ -1,12 +1,3 @@
-/* 
- * $Id$
- */
-/**
- * \defgroup NetShareConf Functions which handle network and sharing configuration.
- *
- * \ingroup CitadelConfig
- */
-/*@{*/
 #include "webcit.h"
 
 void display_netconf(void);
@@ -81,14 +72,14 @@ void SerializeNode(NodeConf *Node, StrBuf *Buf)
 }
 
 
-HashList *load_netconf(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+HashList *load_netconf(StrBuf *Target, WCTemplputParams *TP)
 {
        StrBuf *Buf;
        HashList *Hash;
        char nnn[64];
        char buf[SIZ];
-       long len;
        int nUsed;
+       long len;
        NodeConf *Node;
 
        serv_puts("CONF getsys|application/x-citadel-ignet-config");
@@ -98,7 +89,7 @@ HashList *load_netconf(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void
 
                Buf = NewStrBuf();
                while ((len = StrBuf_ServGetln(Buf),
-                       strcmp(ChrPtr(Buf), "000"))) {
+                       (len != 3) || !strcmp(ChrPtr(Buf), "000"))) {
                        Node = NewNode(Buf);
                        if (Node == NULL)
                                continue;
@@ -113,16 +104,6 @@ HashList *load_netconf(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void
 }
 
 
-void NodeCfgSubst(StrBuf *TemplBuffer, void *vContext, WCTemplateToken *Token)
-{
-       NodeConf *Node= (NodeConf*)vContext;
-
-       SVPutBuf("CFG:IGNET:NODE", Node->NodeName, 1);
-       SVPutBuf("CFG:IGNET:SECRET", Node->Secret, 1);
-       SVPutBuf("CFG:IGNET:HOST", Node->Host, 1);
-       SVPutBuf("CFG:IGNET:PORT", Node->Port, 1);
-}
-
 
 void save_net_conf(HashList *Nodelist)
 {
@@ -148,6 +129,7 @@ void save_net_conf(HashList *Nodelist)
                                }
                        }
                        FreeStrBuf(&Buf);
+                       DeleteHashPos(&where);
                }
                serv_puts("000");
        }
@@ -161,8 +143,8 @@ void save_net_conf(HashList *Nodelist)
 
 
 
-/**
- * \brief edit a network node
+/*
+ * edit a network node
  */
 void edit_node(void) {
        HashList *NodeConfig;
@@ -178,7 +160,7 @@ void edit_node(void) {
                        return;
                }
                        
-               NodeConfig = load_netconf(NULL, 0, NULL, NULL, CTX_NONE);
+               NodeConfig = load_netconf(NULL, &NoCtx);
                Put(NodeConfig, ChrPtr(Index), StrLength(Index), NewNode, DeleteNodeConf);
                save_net_conf(NodeConfig);
                DeleteHash(&NodeConfig);
@@ -187,14 +169,16 @@ void edit_node(void) {
 }
 
 
-/**
- * \brief modify an existing node
+/*
+ * modify an existing node
  */
 void display_edit_node(void)
 {
+       WCTemplputParams SubTP;
        HashList *NodeConfig;
        const StrBuf *Index;
        void *vNode;
+       const StrBuf *Tmpl;
 
        Index = sbstr("index");
        if (Index == NULL) {
@@ -203,7 +187,7 @@ void display_edit_node(void)
                return;
        }
 
-       NodeConfig = load_netconf(NULL, 0, NULL, NULL, CTX_NONE);
+       NodeConfig = load_netconf(NULL, &NoCtx);
        if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) || 
            (vNode == NULL)) {
                sprintf(WC->ImportantMessage, _("Invalid Parameter"));
@@ -212,25 +196,29 @@ void display_edit_node(void)
                return;
        }
        
-       NodeCfgSubst(NULL, vNode, NULL);
-       SVPutBuf("ITERATE:KEY", Index, 1);
-       url_do_template();
-
+       memset(&SubTP, 0, sizeof(WCTemplputParams));
+       SubTP.Filter.ContextType = CTX_NODECONF;
+       SubTP.Context = vNode;
+       begin_burst();
+       Tmpl = sbstr("template");
+        output_headers(1, 0, 0, 0, 1, 0);
+        DoTemplate(SKEY(Tmpl), NULL, &SubTP);
+        end_burst();                                                                               
        DeleteHash(&NodeConfig);
        
 }
 
 
-/**
- * \brief display all configured nodes
+/*
+ * display all configured nodes
  */
 void display_netconf(void)
 {
        wDumpContent(1);
 }
 
-/**
- * \brief display the dialog to verify the deletion
+/*
+ * display the dialog to verify the deletion
  */
 void display_confirm_delete_node(void)
 {
@@ -238,8 +226,8 @@ void display_confirm_delete_node(void)
 }
 
 
-/**
- * \brief actually delete the node
+/*
+ * actually delete the node
  */
 void delete_node(void)
 {
@@ -255,7 +243,7 @@ void delete_node(void)
                return;
        }
 
-       NodeConfig = load_netconf(NULL, 0, NULL, NULL, CTX_NONE);
+       NodeConfig = load_netconf(NULL, &NoCtx);
        if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) || 
            (vNode == NULL)) {
                sprintf(WC->ImportantMessage, _("Invalid Parameter"));
@@ -272,16 +260,47 @@ void delete_node(void)
 
 }
 
+
+void tmplput_NodeName(StrBuf *Target, WCTemplputParams *TP)
+{
+       NodeConf *Node = (NodeConf*) CTX;       
+       StrBufAppendTemplate(Target, TP, Node->NodeName, 0);
+}
+
+void tmplput_Secret(StrBuf *Target, WCTemplputParams *TP)
+{
+       NodeConf *Node = (NodeConf*) CTX;
+       StrBufAppendTemplate(Target, TP, Node->Secret, 0);
+}
+
+void tmplput_Host(StrBuf *Target, WCTemplputParams *TP) 
+{
+       NodeConf *Node= (NodeConf*) CTX;
+       StrBufAppendTemplate(Target, TP, Node->Host, 0);
+}
+
+void tmplput_Port(StrBuf *Target, WCTemplputParams *TP)
+{
+       NodeConf *Node= (NodeConf*) CTX;
+       StrBufAppendTemplate(Target, TP, Node->Port, 0);
+}
+
 void 
 InitModule_NETCONF
 (void)
 {
-       WebcitAddUrlHandler(HKEY("display_edit_node"), display_edit_node, 0);
+       WebcitAddUrlHandler(HKEY("display_edit_node"), "", 0, display_edit_node, 0);
+
+       WebcitAddUrlHandler(HKEY("aide_ignetconf_edit_node"), "", 0, edit_node, 0);
+       WebcitAddUrlHandler(HKEY("display_netconf"), "", 0, display_netconf, 0);
+       WebcitAddUrlHandler(HKEY("display_confirm_delete_node"), "", 0, display_confirm_delete_node, 0);
+       WebcitAddUrlHandler(HKEY("delete_node"), "", 0, delete_node, 0);
+
+                                                                                          
+        RegisterNamespace("CFG:IGNET:NODE", 0, 1, tmplput_NodeName, NULL, CTX_NODECONF);
+        RegisterNamespace("CFG:IGNET:SECRET", 0, 1, tmplput_Secret, NULL, CTX_NODECONF);
+        RegisterNamespace("CFG:IGNET:HOST", 0, 1, tmplput_Host, NULL, CTX_NODECONF);
+        RegisterNamespace("CFG:IGNET:PORT", 0, 1, tmplput_Port, NULL, CTX_NODECONF);
 
-       WebcitAddUrlHandler(HKEY("edit_node"), edit_node, 0);
-       WebcitAddUrlHandler(HKEY("display_netconf"), display_netconf, 0);
-       WebcitAddUrlHandler(HKEY("display_confirm_delete_node"), display_confirm_delete_node, 0);
-       WebcitAddUrlHandler(HKEY("delete_node"), delete_node, 0);
-       RegisterIterator("NODECONFIG", 0, NULL, load_netconf, NodeCfgSubst, DeleteHash, CTX_NODECONF, CTX_NONE);
+       RegisterIterator("NODECONFIG", 0, NULL, load_netconf, NULL, DeleteHash, CTX_NODECONF, CTX_NONE, IT_NOFLAG);
 }
-/*@}*/