X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fnetconf.c;h=caecca46f42681401be6e724d4067d40fd0a8864;hb=efccdcf4db04e63bfa3512c80215357ee9ffd98f;hp=521c765a78ed0dadd892d9e8ea222d4476d9132a;hpb=b4ad306de9560ec731db113ed509a1172209c444;p=citadel.git
diff --git a/webcit/netconf.c b/webcit/netconf.c
index 521c765a7..caecca46f 100644
--- a/webcit/netconf.c
+++ b/webcit/netconf.c
@@ -1,12 +1,3 @@
-/*
- * $Id$
- */
-/**
- * \defgroup NetShareConf Functions which handle network and sharing configuration.
- *
- * \ingroup CitadelConfig
- */
-/*@{*/
#include "webcit.h"
void display_netconf(void);
@@ -81,13 +72,12 @@ void SerializeNode(NodeConf *Node, StrBuf *Buf)
}
-HashList *load_netconf(WCTemplateToken *Token)
+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(WCTemplateToken *Token)
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,16 +102,6 @@ HashList *load_netconf(WCTemplateToken *Token)
}
-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)
{
@@ -138,7 +117,7 @@ void save_net_conf(HashList *Nodelist)
serv_getln(buf, sizeof buf);
if (buf[0] == '4') {
if ((Nodelist != NULL) && (GetCount(Nodelist) > 0)) {
- where = GetNewHashPos();
+ where = GetNewHashPos(Nodelist, 0);
Buf = NewStrBuf();
while (GetNextHashPos(Nodelist, where, &KeyLen, &Key, &vNode)) {
Node = (NodeConf*) vNode;
@@ -148,6 +127,7 @@ void save_net_conf(HashList *Nodelist)
}
}
FreeStrBuf(&Buf);
+ DeleteHashPos(&where);
}
serv_puts("000");
}
@@ -161,307 +141,91 @@ void save_net_conf(HashList *Nodelist)
-/**
- * \brief edit a network node
+/*
+ * edit a network node
*/
void edit_node(void) {
HashList *NodeConfig;
const StrBuf *Index;
NodeConf *NewNode;
-/*
- char buf[SIZ];
- char node[SIZ];
- char cnode[SIZ];
- FILE *fp;
-*/
+
if (havebstr("ok_button")) {
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);
+ NodeConfig = load_netconf(NULL, &NoCtx);
Put(NodeConfig, ChrPtr(Index), StrLength(Index), NewNode, DeleteNodeConf);
save_net_conf(NodeConfig);
DeleteHash(&NodeConfig);
-/*
- strcpy(node, bstr("node") );
- fp = tmpfile();
- if (fp != NULL) {
- serv_puts("CONF getsys|application/x-citadel-ignet-config");
- serv_getln(buf, sizeof buf);
- if (buf[0] == '1') {
- while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
- extract_token(cnode, buf, 0, '|', sizeof cnode);
- if (strcasecmp(node, cnode)) {
- fprintf(fp, "%s\n", buf);
- }
- }
- rewind(fp);
- }
-
- serv_puts("CONF putsys|application/x-citadel-ignet-config");
- serv_getln(buf, sizeof buf);
- if (buf[0] == '4') {
- if (fp != NULL) {
- while (fgets(buf, sizeof buf, fp) != NULL) {
- buf[strlen(buf)-1] = 0;
- if (buf[0] != 0) {
- serv_puts(buf);
- }
- }
- fclose(fp);
- }
- serv_printf("%s|%s|%s|%s",
- bstr("node"),
- bstr("secret"),
- bstr("host"),
- bstr("port") );
- }
- serv_puts("000");
- }
-*/
}
-
- //display_netconf();
url_do_template();
}
-/**
- * \brief add a node
- */
-void display_add_node(void)
-{/*
- output_headers(1, 1, 2, 0, 0, 0);
- wprintf("
\n");
- wprintf("
");
- wprintf(_("Add a new node"));
- wprintf("
");
- wprintf("\n");
-
- wprintf("\n");
-
- wprintf("
\n");
-
- wDumpContent(1);
- */
-}
-
-/**
- * \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) {
- sprintf(WC->ImportantMessage, _("Invalid Parameter"));
+ AppendImportantMessage(_("Invalid Parameter"), -1);
url_do_template();
return;
}
- NodeConfig = load_netconf(NULL);
+ 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();
-
+ 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);
-/*
- char buf[512];
- char node[256];
- char cnode[256];
- char csecret[256];
- char chost[256];
- char cport[256];
-
- strcpy(node, bstr("node"));
-
- output_headers(1, 1, 2, 0, 0, 0);
- wprintf("
\n");
- wprintf("
");
- wprintf(_("Edit node configuration for "));
- escputs(node);
- wprintf("
");
- wprintf("\n");
-
- wprintf("
\n");
-
- serv_puts("CONF getsys|application/x-citadel-ignet-config");
- serv_getln(buf, sizeof buf);
- if (buf[0] == '1') {
- while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
- extract_token(cnode, buf, 0, '|', sizeof cnode);
- extract_token(csecret, buf, 1, '|', sizeof csecret);
- extract_token(chost, buf, 2, '|', sizeof chost);
- extract_token(cport, buf, 3, '|', sizeof cport);
-
- if (!strcasecmp(node, cnode)) {
- wprintf("
\n");
- }
-
- }
- }
-
- else { / ** command error getting configuration * /
- wprintf("%s
\n", &buf[4]);
- }
-
- wDumpContent(1);
-*/
}
-
-
-//CFG:IGNET:NODE
-/**
- * \brief display all configured nodes
+/*
+ * display all configured nodes
*/
void display_netconf(void)
{
-/*
- char buf[SIZ];
- char node[SIZ];
- output_headers(1, 1, 2, 0, 0, 0);
- wprintf("
\n");
- wprintf("
");
- wprintf(_("Network configuration"));
- wprintf("
");
- wprintf("\n");
-
- wprintf("
\n");
-
- wprintf("
");
- wprintf("");
- wprintf(_("Add a new node"));
- wprintf("
\n");
- wprintf("");
-
- wprintf("
");
- wprintf("");
- wprintf(_("Currently configured nodes"));
- wprintf("\n");
- wprintf(" |
\n");
- serv_puts("CONF getsys|application/x-citadel-ignet-config");
- serv_getln(buf, sizeof buf);
- if (buf[0] == '1') {
- wprintf("
\n");
- }
-*/
wDumpContent(1);
}
-/**
- * \brief display the dialog to verify the deletion
+/*
+ * display the dialog to verify the deletion
*/
void display_confirm_delete_node(void)
{
-/*
- char node[SIZ];
- output_headers(1, 1, 2, 0, 0, 0);
- wprintf("
\n");
- wprintf("
");
- wprintf(_("Confirm delete"));
- wprintf("
");
- wprintf("\n");
-
- wprintf("
\n");
-
- strcpy(node, bstr("node"));
- wprintf("
");
- wprintf(_("Are you sure you want to delete "));
- wprintf("");
- escputs(node);
- wprintf("?
\n");
- wprintf("");
- wprintf(_("Yes"));
- wprintf(" ");
- wprintf("");
- wprintf(_("No"));
- wprintf("
\n");
-*/
wDumpContent(1);
}
-/**
- * \brief actually delete the node
+/*
+ * actually delete the node
*/
void delete_node(void)
{
@@ -472,15 +236,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);
+ 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;
@@ -492,54 +256,49 @@ void delete_node(void)
url_do_template();
-/*
- char buf[SIZ];
- char node[SIZ];
- char cnode[SIZ];
- FILE *fp;
-
- strcpy(node, bstr("node") );
- fp = tmpfile();
- if (fp != NULL) {
- serv_puts("CONF getsys|application/x-citadel-ignet-config");
- serv_getln(buf, sizeof buf);
- if (buf[0] == '1') {
- while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
- extract_token(cnode, buf, 0, '|', sizeof cnode);
- if (strcasecmp(node, cnode)) {
- fprintf(fp, "%s\n", buf);
- }
- }
- }
- rewind(fp);
-
- serv_puts("CONF putsys|application/x-citadel-ignet-config");
- serv_getln(buf, sizeof buf);
- if (buf[0] == '4') {
- while (fgets(buf, sizeof buf, fp) != NULL) {
- buf[strlen(buf)-1] = 0;
- serv_puts(buf);
- }
- serv_puts("000");
- }
- fclose(fp);
- }
+}
+
+
+void tmplput_NodeName(StrBuf *Target, WCTemplputParams *TP)
+{
+ NodeConf *Node = (NodeConf*) CTX;
+ StrBufAppendTemplate(Target, TP, Node->NodeName, 0);
+}
- display_netconf();
-*/
+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("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);
- WebcitAddUrlHandler(HKEY("display_add_node"), display_add_node, 0);
- RegisterIterator("NODECONFIG", 0, NULL, load_netconf, NodeCfgSubst, DeleteHash, 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);
+
+ RegisterIterator("NODECONFIG", 0, NULL, load_netconf, NULL, DeleteHash, CTX_NODECONF, CTX_NONE, IT_NOFLAG);
}
-/*@}*/