+/*----------------------------------------------------------------------*/
+/* Business Logic */
+/*----------------------------------------------------------------------*/
+
+typedef struct _nodeconf {
+ int DeleteMe;
+ StrBuf *NodeName;
+ StrBuf *Secret;
+ StrBuf *Host;
+ StrBuf *Port;
+}NodeConf;
+
+void DeleteNodeConf(void *vNode)
+{
+ NodeConf *Node = (NodeConf*) vNode;
+ FreeStrBuf(&Node->NodeName);
+ FreeStrBuf(&Node->Secret);
+ FreeStrBuf(&Node->Host);
+ FreeStrBuf(&Node->Port);
+ free(Node);
+}
+
+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. */
+ Node = (NodeConf *) malloc(sizeof(NodeConf));
+ Node->DeleteMe = 0;
+ Node->NodeName=NewStrBuf();
+ StrBufExtract_token(Node->NodeName, SerializedNode, 0, '|');
+ Node->Secret=NewStrBuf();
+ StrBufExtract_token(Node->Secret, SerializedNode, 1, '|');
+ Node->Host=NewStrBuf();
+ StrBufExtract_token(Node->Host, SerializedNode, 2, '|');
+ Node->Port=NewStrBuf();
+ StrBufExtract_token(Node->Port, SerializedNode, 3, '|');
+ return Node;
+}
+
+NodeConf *HttpGetNewNode(void)
+{
+ NodeConf *Node;
+
+ if (!havebstr("node") ||
+ !havebstr("secret")||
+ !havebstr("host")||
+ !havebstr("port"))
+ return NULL;
+
+ Node = (NodeConf *) malloc(sizeof(NodeConf));
+ Node->DeleteMe = 0;
+ Node->NodeName = NewStrBufDup(sbstr("node"));
+ Node->Secret = NewStrBufDup(sbstr("secret"));
+ Node->Host = NewStrBufDup(sbstr("host"));
+ Node->Port = NewStrBufDup(sbstr("port"));
+ 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));
+}
+
+
+HashList *load_netconf(WCTemplateToken *Token)
+{
+ StrBuf *Buf;
+ HashList *Hash;
+ char nnn[64];
+ char buf[SIZ];
+ long len;
+ int nUsed;
+ NodeConf *Node;
+
+ serv_puts("CONF getsys|application/x-citadel-ignet-config");
+ serv_getln(buf, sizeof buf);
+ if (buf[0] == '1') {
+ Hash = NewHash(1, NULL);
+
+ Buf = NewStrBuf();
+ while ((len = 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);
+ }
+ FreeStrBuf(&Buf);
+ return Hash;
+ }
+ return NULL;
+}
+
+
+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)
+{
+ char buf[SIZ];
+ StrBuf *Buf;
+ HashPos *where;
+ void *vNode;
+ NodeConf *Node;
+ const char *Key;
+ long KeyLen;
+
+ serv_puts("CONF putsys|application/x-citadel-ignet-config");
+ serv_getln(buf, sizeof buf);
+ if (buf[0] == '4') {
+ if ((Nodelist != NULL) && (GetCount(Nodelist) > 0)) {
+ where = GetNewHashPos();
+ Buf = NewStrBuf();
+ while (GetNextHashPos(Nodelist, where, &KeyLen, &Key, &vNode)) {
+ Node = (NodeConf*) vNode;
+ if (Node->DeleteMe==0) {
+ SerializeNode(Node, Buf);
+ serv_putbuf(Buf);
+ }
+ }
+ FreeStrBuf(&Buf);
+ }
+ serv_puts("000");
+ }
+}
+
+
+
+/*----------------------------------------------------------------------*/
+/* WEB Handlers */
+/*----------------------------------------------------------------------*/
+
+
+