Integrated the DKIM signer into serv_smtpclient, but disabled it
[citadel.git] / webcit / netconf.c
index 456b7f6c7340bdf601435685aa32e5b54ed296c9..6ff53fa5656fea83884cffef096c91ab80f8811b 100644 (file)
@@ -1,16 +1,12 @@
-/* 
- * $Id$
- */
-/**
- * \defgroup NetShareConf Functions which handle network and sharing configuration.
- *
- * \ingroup CitadelConfig
- */
-/*@{*/
+// Copyright (c) 1999-2004 by the citadel.org team
+// This program is open source software.  Use, duplication, or disclosure is subject to the GNU General Public License v3.
+
+
 #include "webcit.h"
 
 void display_netconf(void);
 
+CtxType CTX_NODECONF = CTX_NONE;
 /*----------------------------------------------------------------------*/
 /*              Business Logic                                          */
 /*----------------------------------------------------------------------*/
@@ -21,10 +17,9 @@ typedef struct _nodeconf {
        StrBuf *Secret;
        StrBuf *Host;
        StrBuf *Port;
-}NodeConf;
+} NodeConf;
 
-void DeleteNodeConf(void *vNode)
-{
+void DeleteNodeConf(void *vNode) {
        NodeConf *Node = (NodeConf*) vNode;
        FreeStrBuf(&Node->NodeName);
        FreeStrBuf(&Node->Secret);
@@ -33,12 +28,11 @@ void DeleteNodeConf(void *vNode)
        free(Node);
 }
 
-NodeConf *NewNode(StrBuf *SerializedNode)
-{
+NodeConf *NewNode(StrBuf *SerializedNode) {
        NodeConf *Node;
 
        if (StrLength(SerializedNode) < 8) 
-               return NULL; /** we need at least 4 pipes and some other text so its invalid. */
+               return NULL; /* we need at least 4 pipes and some other text so its invalid. */
        Node = (NodeConf *) malloc(sizeof(NodeConf));
        Node->DeleteMe = 0;
        Node->NodeName=NewStrBuf();
@@ -52,8 +46,7 @@ NodeConf *NewNode(StrBuf *SerializedNode)
        return Node;
 }
 
-NodeConf *HttpGetNewNode(void)
-{
+NodeConf *HttpGetNewNode(void) {
        NodeConf *Node;
 
        if (!havebstr("node") || 
@@ -71,8 +64,7 @@ NodeConf *HttpGetNewNode(void)
        return Node;
 }
 
-void SerializeNode(NodeConf *Node, StrBuf *Buf)
-{
+void SerializeNode(NodeConf *Node, StrBuf *Buf) {
        StrBufPrintf(Buf, "%s|%s|%s|%s", 
                     ChrPtr(Node->NodeName),
                     ChrPtr(Node->Secret),
@@ -81,13 +73,11 @@ 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;
        NodeConf *Node;
 
@@ -97,14 +87,13 @@ HashList *load_netconf(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void
                Hash = NewHash(1, NULL);
 
                Buf = NewStrBuf();
-               while ((len = StrBuf_ServGetln(Buf),
-                       strcmp(ChrPtr(Buf), "000"))) {
+               while (StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) {
                        Node = NewNode(Buf);
-                       if (Node == NULL)
-                               continue;
-                       nUsed = GetCount(Hash);
-                       nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
-                       Put(Hash, nnn, nUsed, Node, DeleteNodeConf); 
+                       if (Node != NULL) {
+                               nUsed = GetCount(Hash);
+                               nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
+                               Put(Hash, nnn, nUsed, Node, DeleteNodeConf); 
+                       }
                }
                FreeStrBuf(&Buf);
                return Hash;
@@ -113,19 +102,8 @@ 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)
-{
+void save_net_conf(HashList *Nodelist) {
        char buf[SIZ];
        StrBuf *Buf;
        HashPos *where;
@@ -148,6 +126,7 @@ void save_net_conf(HashList *Nodelist)
                                }
                        }
                        FreeStrBuf(&Buf);
+                       DeleteHashPos(&where);
                }
                serv_puts("000");
        }
@@ -161,8 +140,8 @@ void save_net_conf(HashList *Nodelist)
 
 
 
-/**
- * \brief edit a network node
+/*
+ * edit a network node
  */
 void edit_node(void) {
        HashList *NodeConfig;
@@ -173,12 +152,12 @@ void edit_node(void) {
                Index = sbstr("index");
                NewNode = HttpGetNewNode();
                if ((NewNode == NULL) || (Index == NULL)) {
-                       sprintf(WC->ImportantMessage, _("Invalid Parameter"));
+                       AppendImportantMessage(_("Invalid Parameter"), -1);
                        url_do_template();
                        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,62 +166,64 @@ void edit_node(void) {
 }
 
 
-/**
- * \brief modify an existing node
+/*
+ * modify an existing node
  */
-void display_edit_node(void)
-{
+void display_edit_node(void) {
+       WCTemplputParams SubTP;
        HashList *NodeConfig;
        const StrBuf *Index;
        void *vNode;
+       const StrBuf *Tmpl;
 
        Index = sbstr("index");
        if (Index == NULL) {
-               sprintf(WC->ImportantMessage, _("Invalid Parameter"));
+               AppendImportantMessage(_("Invalid Parameter"), -1);
                url_do_template();
                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"));
+               AppendImportantMessage(_("Invalid Parameter"), -1);
                url_do_template();
                DeleteHash(&NodeConfig);
                return;
        }
-       
-       NodeCfgSubst(NULL, vNode, NULL);
-       SVPutBuf("ITERATE:KEY", Index, 1);
-       url_do_template();
-
+       StackContext(NULL, &SubTP, vNode, CTX_NODECONF, 0, NULL);
+       {
+               begin_burst();
+               Tmpl = sbstr("template");
+               output_headers(1, 0, 0, 0, 1, 0);
+               DoTemplate(SKEY(Tmpl), NULL, &SubTP);
+               end_burst();
+       }
+       UnStackContext(&SubTP);
        DeleteHash(&NodeConfig);
        
 }
 
 
-/**
- * \brief display all configured nodes
+/*
+ * display all configured nodes
  */
-void display_netconf(void)
-{
+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)
-{
+void display_confirm_delete_node(void) {
        wDumpContent(1);
 }
 
 
-/**
- * \brief actually delete the node
+/*
+ * actually delete the node
  */
-void delete_node(void)
-{
+void delete_node(void) {
        HashList *NodeConfig;
        const StrBuf *Index;
        NodeConf *Node;
@@ -250,15 +231,15 @@ void delete_node(void)
 
        Index = sbstr("index");
        if (Index == NULL) {
-               sprintf(WC->ImportantMessage, _("Invalid Parameter"));
+               AppendImportantMessage(_("Invalid Parameter"), -1);
                url_do_template();
                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"));
+               AppendImportantMessage(_("Invalid Parameter"), -1);
                url_do_template();
                DeleteHash(&NodeConfig);
                return;
@@ -272,16 +253,44 @@ void delete_node(void)
 
 }
 
+
+void tmplput_NodeName(StrBuf *Target, WCTemplputParams *TP) {
+       NodeConf *Node = (NodeConf*) CTX(CTX_NODECONF); 
+       StrBufAppendTemplate(Target, TP, Node->NodeName, 0);
+}
+
+void tmplput_Secret(StrBuf *Target, WCTemplputParams *TP) {
+       NodeConf *Node = (NodeConf*) CTX(CTX_NODECONF);
+       StrBufAppendTemplate(Target, TP, Node->Secret, 0);
+}
+
+void tmplput_Host(StrBuf *Target, WCTemplputParams *TP) {
+       NodeConf *Node= (NodeConf*) CTX(CTX_NODECONF);
+       StrBufAppendTemplate(Target, TP, Node->Host, 0);
+}
+
+void tmplput_Port(StrBuf *Target, WCTemplputParams *TP) {
+       NodeConf *Node= (NodeConf*) CTX(CTX_NODECONF);
+       StrBufAppendTemplate(Target, TP, Node->Port, 0);
+}
+
 void 
 InitModule_NETCONF
 (void)
 {
-       WebcitAddUrlHandler(HKEY("display_edit_node"), display_edit_node, 0);
+       RegisterCTX(CTX_NODECONF);
+       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, IT_NOFLAG);
+       RegisterIterator("NODECONFIG", 0, NULL, load_netconf, NULL, DeleteHash, CTX_NODECONF, CTX_NONE, IT_NOFLAG);
 }
-/*@}*/