SUBST: Dynamicaly generate contexts
[citadel.git] / webcit / netconf.c
index 8683879ffc2bbd74873bda4caad4855a7a21d508..83c391429c95aa0d7a4b10fed5706fa6facda289 100644 (file)
@@ -2,6 +2,7 @@
 
 void display_netconf(void);
 
+CtxType CTX_NODECONF = CTX_NONE;
 /*----------------------------------------------------------------------*/
 /*              Business Logic                                          */
 /*----------------------------------------------------------------------*/
@@ -79,7 +80,6 @@ HashList *load_netconf(StrBuf *Target, WCTemplputParams *TP)
        char nnn[64];
        char buf[SIZ];
        int nUsed;
-       long len;
        NodeConf *Node;
 
        serv_puts("CONF getsys|application/x-citadel-ignet-config");
@@ -88,14 +88,13 @@ HashList *load_netconf(StrBuf *Target, WCTemplputParams *TP)
                Hash = NewHash(1, NULL);
 
                Buf = NewStrBuf();
-               while ((len = StrBuf_ServGetln(Buf),
-                       (len != 3) || !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;
@@ -195,15 +194,15 @@ void display_edit_node(void)
                DeleteHash(&NodeConfig);
                return;
        }
-       
-       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();                                                                               
+       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);
        
 }
@@ -263,25 +262,25 @@ void delete_node(void)
 
 void tmplput_NodeName(StrBuf *Target, WCTemplputParams *TP)
 {
-       NodeConf *Node = (NodeConf*) CTX;       
+       NodeConf *Node = (NodeConf*) CTX(CTX_NODECONF); 
        StrBufAppendTemplate(Target, TP, Node->NodeName, 0);
 }
 
 void tmplput_Secret(StrBuf *Target, WCTemplputParams *TP)
 {
-       NodeConf *Node = (NodeConf*) CTX;
+       NodeConf *Node = (NodeConf*) CTX(CTX_NODECONF);
        StrBufAppendTemplate(Target, TP, Node->Secret, 0);
 }
 
 void tmplput_Host(StrBuf *Target, WCTemplputParams *TP) 
 {
-       NodeConf *Node= (NodeConf*) CTX;
+       NodeConf *Node= (NodeConf*) CTX(CTX_NODECONF);
        StrBufAppendTemplate(Target, TP, Node->Host, 0);
 }
 
 void tmplput_Port(StrBuf *Target, WCTemplputParams *TP)
 {
-       NodeConf *Node= (NodeConf*) CTX;
+       NodeConf *Node= (NodeConf*) CTX(CTX_NODECONF);
        StrBufAppendTemplate(Target, TP, Node->Port, 0);
 }
 
@@ -289,6 +288,7 @@ void
 InitModule_NETCONF
 (void)
 {
+       RegisterCTX(CTX_NODECONF);
        WebcitAddUrlHandler(HKEY("display_edit_node"), "", 0, display_edit_node, 0);
 
        WebcitAddUrlHandler(HKEY("aide_ignetconf_edit_node"), "", 0, edit_node, 0);