X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fnetconf.c;h=83c391429c95aa0d7a4b10fed5706fa6facda289;hb=HEAD;hp=a62c96526e5f28800e2f4c6765f8307d0c22d71b;hpb=a15ba5c1ede7c86a85d62ed5b539dcfc9f415bc1;p=citadel.git diff --git a/webcit/netconf.c b/webcit/netconf.c index a62c96526..6ff53fa56 100644 --- a/webcit/netconf.c +++ b/webcit/netconf.c @@ -1,7 +1,12 @@ +// 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 */ /*----------------------------------------------------------------------*/ @@ -12,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); @@ -24,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(); @@ -43,8 +46,7 @@ NodeConf *NewNode(StrBuf *SerializedNode) return Node; } -NodeConf *HttpGetNewNode(void) -{ +NodeConf *HttpGetNewNode(void) { NodeConf *Node; if (!havebstr("node") || @@ -62,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), @@ -72,14 +73,12 @@ void SerializeNode(NodeConf *Node, StrBuf *Buf) } -HashList *load_netconf(StrBuf *Target, WCTemplputParams *TP) -{ +HashList *load_netconf(StrBuf *Target, WCTemplputParams *TP) { StrBuf *Buf; HashList *Hash; char nnn[64]; char buf[SIZ]; int nUsed; - long len; NodeConf *Node; serv_puts("CONF getsys|application/x-citadel-ignet-config"); @@ -88,14 +87,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; @@ -105,8 +103,7 @@ 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; @@ -155,7 +152,7 @@ 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; } @@ -172,8 +169,7 @@ 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; @@ -182,7 +178,7 @@ void display_edit_node(void) Index = sbstr("index"); if (Index == NULL) { - sprintf(WC->ImportantMessage, _("Invalid Parameter")); + AppendImportantMessage(_("Invalid Parameter"), -1); url_do_template(); return; } @@ -190,20 +186,20 @@ void display_edit_node(void) 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; } - - 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); } @@ -212,16 +208,14 @@ void display_edit_node(void) /* * 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); } @@ -229,8 +223,7 @@ 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; @@ -238,7 +231,7 @@ void delete_node(void) Index = sbstr("index"); if (Index == NULL) { - sprintf(WC->ImportantMessage, _("Invalid Parameter")); + AppendImportantMessage(_("Invalid Parameter"), -1); url_do_template(); return; } @@ -246,7 +239,7 @@ void delete_node(void) 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; @@ -261,27 +254,23 @@ void delete_node(void) } -void tmplput_NodeName(StrBuf *Target, WCTemplputParams *TP) -{ - NodeConf *Node = (NodeConf*) CTX; +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; +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; +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; +void tmplput_Port(StrBuf *Target, WCTemplputParams *TP) { + NodeConf *Node= (NodeConf*) CTX(CTX_NODECONF); StrBufAppendTemplate(Target, TP, Node->Port, 0); } @@ -289,6 +278,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);