Reverts commit c6aec42f213ec284e34648f3d69bcf927dccddb1 because putting the opening...
[citadel.git] / webcit / netconf.c
index 2082499035809ae66409caa04f8497df697ce3df..83c391429c95aa0d7a4b10fed5706fa6facda289 100644 (file)
@@ -3,11 +3,8 @@
 void display_netconf(void);
 
 CtxType CTX_NODECONF = CTX_NONE;
-
 /*----------------------------------------------------------------------*/
-
 /*              Business Logic                                          */
-
 /*----------------------------------------------------------------------*/
 
 typedef struct _nodeconf {
@@ -16,10 +13,11 @@ typedef struct _nodeconf {
        StrBuf *Secret;
        StrBuf *Host;
        StrBuf *Port;
-} NodeConf;
+}NodeConf;
 
-void DeleteNodeConf(void *vNode) {
-       NodeConf *Node = (NodeConf *) vNode;
+void DeleteNodeConf(void *vNode)
+{
+       NodeConf *Node = (NodeConf*) vNode;
        FreeStrBuf(&Node->NodeName);
        FreeStrBuf(&Node->Secret);
        FreeStrBuf(&Node->Host);
@@ -27,29 +25,33 @@ void DeleteNodeConf(void *vNode) {
        free(Node);
 }
 
-NodeConf *NewNode(StrBuf * SerializedNode) {
+NodeConf *NewNode(StrBuf *SerializedNode)
+{
        NodeConf *Node;
 
-       if (StrLength(SerializedNode) < 8)
-
+       if (StrLength(SerializedNode) < 8) 
                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();
+       Node->NodeName=NewStrBuf();
        StrBufExtract_token(Node->NodeName, SerializedNode, 0, '|');
-       Node->Secret = NewStrBuf();
+       Node->Secret=NewStrBuf();
        StrBufExtract_token(Node->Secret, SerializedNode, 1, '|');
-       Node->Host = NewStrBuf();
+       Node->Host=NewStrBuf();
        StrBufExtract_token(Node->Host, SerializedNode, 2, '|');
-       Node->Port = NewStrBuf();
+       Node->Port=NewStrBuf();
        StrBufExtract_token(Node->Port, SerializedNode, 3, '|');
        return Node;
 }
 
-NodeConf *HttpGetNewNode(void) {
+NodeConf *HttpGetNewNode(void)
+{
        NodeConf *Node;
 
-       if (!havebstr("node") || !havebstr("secret") || !havebstr("host") || !havebstr("port"))
+       if (!havebstr("node") || 
+           !havebstr("secret")||
+           !havebstr("host")||
+           !havebstr("port"))
                return NULL;
 
        Node = (NodeConf *) malloc(sizeof(NodeConf));
@@ -61,12 +63,18 @@ NodeConf *HttpGetNewNode(void) {
        return Node;
 }
 
-void SerializeNode(NodeConf * Node, StrBuf * Buf) {
-       StrBufPrintf(Buf, "%s|%s|%s|%s", ChrPtr(Node->NodeName), ChrPtr(Node->Secret), ChrPtr(Node->Host), ChrPtr(Node->Port));
+void SerializeNode(NodeConf *Node, StrBuf *Buf)
+{
+       StrBufPrintf(Buf, "%s|%s|%s|%s", 
+                    ChrPtr(Node->NodeName),
+                    ChrPtr(Node->Secret),
+                    ChrPtr(Node->Host),
+                    ChrPtr(Node->Port));
 }
 
 
-HashList *load_netconf(StrBuf * Target, WCTemplputParams * TP) {
+HashList *load_netconf(StrBuf *Target, WCTemplputParams *TP)
+{
        StrBuf *Buf;
        HashList *Hash;
        char nnn[64];
@@ -84,8 +92,8 @@ HashList *load_netconf(StrBuf * Target, WCTemplputParams * TP) {
                        Node = NewNode(Buf);
                        if (Node != NULL) {
                                nUsed = GetCount(Hash);
-                               nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed + 1);
-                               Put(Hash, nnn, nUsed, Node, DeleteNodeConf);
+                               nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
+                               Put(Hash, nnn, nUsed, Node, DeleteNodeConf); 
                        }
                }
                FreeStrBuf(&Buf);
@@ -96,7 +104,8 @@ HashList *load_netconf(StrBuf * Target, WCTemplputParams * TP) {
 
 
 
-void save_net_conf(HashList * Nodelist) {
+void save_net_conf(HashList *Nodelist)
+{
        char buf[SIZ];
        StrBuf *Buf;
        HashPos *where;
@@ -112,8 +121,8 @@ void save_net_conf(HashList * Nodelist) {
                        where = GetNewHashPos(Nodelist, 0);
                        Buf = NewStrBuf();
                        while (GetNextHashPos(Nodelist, where, &KeyLen, &Key, &vNode)) {
-                               Node = (NodeConf *) vNode;
-                               if (Node->DeleteMe == 0) {
+                               Node = (NodeConf*) vNode;
+                               if (Node->DeleteMe==0) { 
                                        SerializeNode(Node, Buf);
                                        serv_putbuf(Buf);
                                }
@@ -128,9 +137,7 @@ void save_net_conf(HashList * Nodelist) {
 
 
 /*----------------------------------------------------------------------*/
-
 /*              WEB Handlers                                            */
-
 /*----------------------------------------------------------------------*/
 
 
@@ -145,13 +152,13 @@ void edit_node(void) {
 
        if (havebstr("ok_button")) {
                Index = sbstr("index");
-               NewNode = HttpGetNewNode();
+               NewNode = HttpGetNewNode();
                if ((NewNode == NULL) || (Index == NULL)) {
                        AppendImportantMessage(_("Invalid Parameter"), -1);
                        url_do_template();
                        return;
                }
-
+                       
                NodeConfig = load_netconf(NULL, &NoCtx);
                Put(NodeConfig, ChrPtr(Index), StrLength(Index), NewNode, DeleteNodeConf);
                save_net_conf(NodeConfig);
@@ -164,7 +171,8 @@ void edit_node(void) {
 /*
  * modify an existing node
  */
-void display_edit_node(void) {
+void display_edit_node(void)
+{
        WCTemplputParams SubTP;
        HashList *NodeConfig;
        const StrBuf *Index;
@@ -179,7 +187,8 @@ void display_edit_node(void) {
        }
 
        NodeConfig = load_netconf(NULL, &NoCtx);
-       if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) || (vNode == NULL)) {
+       if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) || 
+           (vNode == NULL)) {
                AppendImportantMessage(_("Invalid Parameter"), -1);
                url_do_template();
                DeleteHash(&NodeConfig);
@@ -195,21 +204,23 @@ void display_edit_node(void) {
        }
        UnStackContext(&SubTP);
        DeleteHash(&NodeConfig);
-
+       
 }
 
 
 /*
  * display all configured nodes
  */
-void display_netconf(void) {
+void display_netconf(void)
+{
        wDumpContent(1);
 }
 
 /*
  * display the dialog to verify the deletion
  */
-void display_confirm_delete_node(void) {
+void display_confirm_delete_node(void)
+{
        wDumpContent(1);
 }
 
@@ -217,7 +228,8 @@ void display_confirm_delete_node(void) {
 /*
  * actually delete the node
  */
-void delete_node(void) {
+void delete_node(void)
+{
        HashList *NodeConfig;
        const StrBuf *Index;
        NodeConf *Node;
@@ -231,7 +243,8 @@ void delete_node(void) {
        }
 
        NodeConfig = load_netconf(NULL, &NoCtx);
-       if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) || (vNode == NULL)) {
+       if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) || 
+           (vNode == NULL)) {
                AppendImportantMessage(_("Invalid Parameter"), -1);
                url_do_template();
                DeleteHash(&NodeConfig);
@@ -239,35 +252,42 @@ void delete_node(void) {
        }
        Node = (NodeConf *) vNode;
        Node->DeleteMe = 1;
-       save_net_conf(NodeConfig);
+               save_net_conf(NodeConfig);
        DeleteHash(&NodeConfig);
-
+       
        url_do_template();
 
 }
 
 
-void tmplput_NodeName(StrBuf * Target, WCTemplputParams * TP) {
-       NodeConf *Node = (NodeConf *) CTX(CTX_NODECONF);
+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);
+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);
+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);
+void tmplput_Port(StrBuf *Target, WCTemplputParams *TP)
+{
+       NodeConf *Node= (NodeConf*) CTX(CTX_NODECONF);
        StrBufAppendTemplate(Target, TP, Node->Port, 0);
 }
 
-void InitModule_NETCONF(void) {
+void 
+InitModule_NETCONF
+(void)
+{
        RegisterCTX(CTX_NODECONF);
        WebcitAddUrlHandler(HKEY("display_edit_node"), "", 0, display_edit_node, 0);
 
@@ -276,11 +296,11 @@ void InitModule_NETCONF(void) {
        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);
+                                                                                          
+        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);
 
        RegisterIterator("NODECONFIG", 0, NULL, load_netconf, NULL, DeleteHash, CTX_NODECONF, CTX_NONE, IT_NOFLAG);
 }