From: Wilfried Göesgens Date: Wed, 10 Sep 2008 16:00:03 +0000 (+0000) Subject: * print errormessages into templates if possible in
X-Git-Tag: v7.86~1953
X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=53c742f994c6d4a32b91c41ec92bc7abe8760df2

* print errormessages into templates if possible in 
* rework several error messages to be more clear
* put the hashkey in ITERATE:KEY while iterating
* put ITERATE parameters through to callbacks, so they can find custom things there.
* adjust old uses of the iterate api
* migrate inetconfig to templates.
---

diff --git a/webcit/.svnignore b/webcit/.svnignore
index b9cb88b3a..516dad4d7 100644
--- a/webcit/.svnignore
+++ b/webcit/.svnignore
@@ -1,3 +1,4 @@
 aclocal.m4
 *.d
-
+gmon.out
+modules_init.c
diff --git a/webcit/inetconf.c b/webcit/inetconf.c
index 87964d305..1f234a4f8 100644
--- a/webcit/inetconf.c
+++ b/webcit/inetconf.c
@@ -5,6 +5,7 @@
  */
 
 #include "webcit.h"
+#include "webserver.h"
 
 /*
  * display the inet config dialog 
@@ -154,6 +155,7 @@ void display_inetconf(void)
 }
 
 
+
 /*
  * save changes to the inet config
  */
@@ -195,7 +197,7 @@ void save_inetconf(void) {
 		serv_puts(newconfig);
 		if (!strcasecmp(bstr("oper"), "add")) {
 			serv_printf("%s|%s", bstr("ename"), bstr("etype") );
-			sprintf(WC->ImportantMessage, "%s added.", bstr("ename"));
+			sprintf(WC->ImportantMessage, _("%s added."), bstr("ename"));
 		}
 		serv_puts("000");
 	}
@@ -208,10 +210,207 @@ void save_inetconf(void) {
 	free(newconfig);
 }
 
+typedef enum _e_cfg {
+	ic_localhost,
+	ic_directory,
+	ic_smarthost,
+	ic_rbl,
+	ic_spamass,
+	ic_masq,
+	ic_max
+} ECfg;
+
+typedef struct _ConstStrBuf {
+	const char *name;
+	size_t len;
+} ConstStrBuf;
+
+
+  /* These are server config keywords; do not localize! */
+ConstStrBuf CfgNames[] = {
+	{ HKEY("localhost") },
+	{ HKEY("directory") },
+	{ HKEY("smarthost") },
+	{ HKEY("rbl") },
+	{ HKEY("spamassassin") },
+	{ HKEY("masqdomain") }
+};
+
+	
+
+
+/*
+ * display the inet config dialog 
+ */
+void load_inetconf(void)
+{
+	struct wcsession *WCC = WC;
+	StrBuf *Buf, *Token, *Value;
+	void *vHash;
+	HashList *Hash;
+	char nnn[64];
+	char buf[SIZ];
+	int i, len, nUsed;
+	
+	WCC->InetCfg = NewHash(1, NULL);
+
+	for (i = 0; i < (sizeof(CfgNames) / sizeof(ConstStrBuf)); i++) {
+		Hash = NewHash(1, NULL);
+		Put(WCC->InetCfg, CfgNames[i].name, CfgNames[i].len, Hash, HDeleteHash);
+	}
+
+	serv_printf("CONF GETSYS|application/x-citadel-internet-config");
+	serv_getln(buf, sizeof buf);
+	
+	if (buf[0] == '1') {
+		Buf = NewStrBuf();
+		Token = NewStrBuf();
+		while ((len = StrBuf_ServGetln(Buf),
+			strcmp(ChrPtr(Buf), "000"))) {
+			Value = NewStrBuf();
+ 
+			StrBufExtract_token(Token, Buf, 1, '|');
+			StrBufExtract_token(Value, Buf, 0, '|');
+			GetHash(WCC->InetCfg, ChrPtr(Token), StrLength(Token), &vHash);
+			Hash = (HashList*) vHash;
+			if (Hash == NULL) {
+				lprintf(1, "ERROR Loading inet config line: [%s]\n", 
+					ChrPtr(Buf));
+				FreeStrBuf(&Value);
+				continue;
+			}
+			nUsed = GetCount(Hash);
+			nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
+			Put(Hash, nnn, nUsed, Value, HFreeStrBuf); 
+		}
+		FreeStrBuf(&Buf);
+		FreeStrBuf(&Token);
+	}
+}
+
+
+/*
+ * save changes to the inet config
+ */
+void new_save_inetconf(void) {
+	struct wcsession *WCC = WC;
+	HashList *Hash;
+	StrBuf *Str;
+	const StrBuf *eType, *eNum, *eName;
+	char nnn[64];
+	void *vHash, *vStr;
+	char buf[SIZ];
+	int i, nUsed;
+
+	load_inetconf();
+	eType = sbstr("etype");
+
+	GetHash(WCC->InetCfg, ChrPtr(eType), StrLength(eType), &vHash);
+	Hash = (HashList*) vHash;
+	if (Hash == NULL) {
+		sprintf(WC->ImportantMessage, _("Invalid Parameter"));
+		url_do_template();
+		return;
+	}
+
+	if (strcasecmp(bstr("oper"), "delete") == 0) {
+		eNum = sbstr("ename");
+		if (!GetHash(Hash, ChrPtr(eNum), StrLength(eNum), &vStr) ||
+		    (vStr == NULL)) {
+			sprintf(WC->ImportantMessage, _("Invalid Parameter"));
+			url_do_template();
+			return;
+		}
+
+		Str = (StrBuf*)vStr;
+		sprintf(WC->ImportantMessage, _("%s has been deleted."), ChrPtr(Str));
+		FlushStrBuf(Str);	
+	}
+	else if (!strcasecmp(bstr("oper"), "add")) {
+		eName = sbstr("ename");
+		if (eName == NULL) {
+			sprintf(WC->ImportantMessage, _("Invalid Parameter"));
+			url_do_template();
+			return;
+		}
+
+		nUsed = GetCount(Hash);
+		nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
+	
+		Put(Hash, nnn, nUsed, NewStrBufDup(eName), HFreeStrBuf); 
+		sprintf(WC->ImportantMessage, "%s added.", ChrPtr(eName));
+	}
+
+	serv_printf("CONF PUTSYS|application/x-citadel-internet-config");
+	serv_getln(buf, SIZ);
+	if (buf[0] == '4') {
+		for (i = 0; i < (sizeof(CfgNames) / sizeof(ConstStrBuf)); i++) {
+			HashPos *where;
+			const char *Key;
+			long KeyLen;
+
+			GetHash(WCC->InetCfg, CfgNames[i].name, CfgNames[i].len, &vHash);
+			Hash = (HashList*) vHash;
+			if (Hash == NULL) {
+				sprintf(WC->ImportantMessage, _("Invalid Parameter"));
+				url_do_template();
+				return;
+			}
+			if (GetCount(Hash) > 0) {
+				where = GetNewHashPos();
+				while (GetNextHashPos(Hash, where, &KeyLen, &Key, &vStr)) {
+					Str = (StrBuf*) vStr;
+					if ((Str!= NULL) && (StrLength(Str) > 0))
+						serv_printf("%s|%s", 
+							    ChrPtr(Str),
+							    CfgNames[i].name); 
+				}
+				DeleteHashPos(&where);
+			}			
+		}
+		serv_puts("000");
+		DeleteHash(&WCC->InetCfg);
+	}
+	
+	url_do_template();
+}
+
+void InetCfgSubst(StrBuf *TemplBuffer, void *vContext, WCTemplateToken *Token)
+{
+	SVPutBuf("SERVCFG:INET:HOSTNAME", vContext, 1);
+}
+
+void DeleteInectConfHash(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context)
+{
+	struct wcsession *WCC = WC;
+	if (WCC->InetCfg == NULL)
+		load_inetconf();
+	DeleteHash(&WCC->InetCfg);
+
+}
+
+
+HashList *GetInetConfHash(WCTemplateToken *Token)
+{
+	struct wcsession *WCC = WC;
+	void *vHash;
+
+	if (WCC->InetCfg == NULL)
+		load_inetconf();
+	GetHash(WCC->InetCfg, 
+		Token->Params[2]->Start, 
+		Token->Params[2]->len,
+		&vHash);
+	svprintf(HKEY("SERVCFG:INET:TYPE"), WCS_STRING, Token->Params[2]->Start);
+	return vHash;
+}
+
 void 
 InitModule_INETCONF
 (void)
 {
 	WebcitAddUrlHandler(HKEY("display_inetconf"), display_inetconf, 0);
-	WebcitAddUrlHandler(HKEY("save_inetconf"), save_inetconf, AJAX);
+	WebcitAddUrlHandler(HKEY("save_inetconf"), new_save_inetconf, AJAX);
+	RegisterIterator("SERVCFG:INET", 1, NULL, GetInetConfHash, InetCfgSubst, NULL);
+	RegisterNamespace("SERVCFG:FLUSHINETCFG",0, 0, DeleteInectConfHash);
 }
diff --git a/webcit/preferences.c b/webcit/preferences.c
index 28aac7dfe..8d3b4f8dd 100644
--- a/webcit/preferences.c
+++ b/webcit/preferences.c
@@ -690,7 +690,7 @@ void tmplput_CFG_Descr(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *
 }
 
 
-void CfgZoneTempl(StrBuf *TemplBuffer, void *vContext)
+void CfgZoneTempl(StrBuf *TemplBuffer, void *vContext, WCTemplateToken *Token)
 {
 	StrBuf *Zone = (StrBuf*) vContext;
 
@@ -737,7 +737,7 @@ InitModule_PREFERENCES
 	
 	RegisterNamespace("PREF:VALUE", 1, 1, tmplput_CFG_Value);
 	RegisterNamespace("PREF:DESCR", 1, 1, tmplput_CFG_Descr);
-	RegisterIterator("PREF:ZONE", ZoneHash, NULL, CfgZoneTempl, NULL);
+	RegisterIterator("PREF:ZONE", 0, ZoneHash, NULL, CfgZoneTempl, NULL);
 
 	RegisterConditional(HKEY("COND:PREF"), 4, ConditionalPreference);
 }
diff --git a/webcit/siteconfig.c b/webcit/siteconfig.c
index bde63a706..00ebd60cd 100644
--- a/webcit/siteconfig.c
+++ b/webcit/siteconfig.c
@@ -880,17 +880,24 @@ void load_siteconfig(void)
 	serv_printf("CONF get");
 	serv_getln(buf, sizeof buf);
 	i = 0;
-	while (len = serv_getln(buf, sizeof buf), 
-	       strcmp(buf, "000") && 
-	       (i < sizeof(ServerConfig))) 
+	Buf = NewStrBuf();
+	while ((sizeof(ServerConfig) / sizeof(CfgMapping)) &&
+	       (len = StrBuf_ServGetln(Buf),
+		strcmp(ChrPtr(Buf), "000")) && 
+	       (i <= sizeof(ServerConfig))) 
 	{
 		Put(Cfg,
 		    ServerConfig[i].Key, 
 		    ServerConfig[i].len, 
-		    NewStrBufPlain(buf, len), 
+		    Buf, 
 		    HFreeStrBuf);
 		i++;
+		if (i <= sizeof(ServerConfig) / sizeof(CfgMapping))
+			Buf = NewStrBuf();
+		else
+			Buf = NULL;			
 	}
+	FreeStrBuf(&Buf);
 
 	serv_puts("GPEX site");
 	Buf = NewStrBuf();
diff --git a/webcit/static/t/aide_global_config.html b/webcit/static/t/aide_global_config.html
index 7247b0d3e..3149e66c3 100644
--- a/webcit/static/t/aide_global_config.html
+++ b/webcit/static/t/aide_global_config.html
@@ -1,6 +1,6 @@
 
  • -
  • +
diff --git a/webcit/static/t/aide_inet_aliases.html b/webcit/static/t/aide_inet_aliases.html new file mode 100644 index 000000000..24df4ee67 --- /dev/null +++ b/webcit/static/t/aide_inet_aliases.html @@ -0,0 +1,14 @@ + + +
+ + + + +
+ + + + + +
diff --git a/webcit/static/t/aide_inet_dirnames.html b/webcit/static/t/aide_inet_dirnames.html new file mode 100644 index 000000000..704928fa5 --- /dev/null +++ b/webcit/static/t/aide_inet_dirnames.html @@ -0,0 +1,14 @@ + + +
+ + + + +
+ + + + + +
diff --git a/webcit/static/t/aide_inet_masqdomains.html b/webcit/static/t/aide_inet_masqdomains.html new file mode 100644 index 000000000..da65d341f --- /dev/null +++ b/webcit/static/t/aide_inet_masqdomains.html @@ -0,0 +1,14 @@ + + +
+ + + + +
+ + + + + +
diff --git a/webcit/static/t/aide_inet_rbldns.html b/webcit/static/t/aide_inet_rbldns.html new file mode 100644 index 000000000..000eedef6 --- /dev/null +++ b/webcit/static/t/aide_inet_rbldns.html @@ -0,0 +1,14 @@ + + +
+ + + + +
+ + + + + +
diff --git a/webcit/static/t/aide_inet_smarthosts.html b/webcit/static/t/aide_inet_smarthosts.html new file mode 100644 index 000000000..5f66d937b --- /dev/null +++ b/webcit/static/t/aide_inet_smarthosts.html @@ -0,0 +1,14 @@ + + +
+ + + + +
+ + + + + +
diff --git a/webcit/static/t/aide_inet_spamass.html b/webcit/static/t/aide_inet_spamass.html new file mode 100644 index 000000000..a77f91ff7 --- /dev/null +++ b/webcit/static/t/aide_inet_spamass.html @@ -0,0 +1,14 @@ + + +
+ + + + +
+ + + + + +
diff --git a/webcit/static/t/aide_inetconf.html b/webcit/static/t/aide_inetconf.html new file mode 100644 index 000000000..fbccd2884 --- /dev/null +++ b/webcit/static/t/aide_inetconf.html @@ -0,0 +1,29 @@ + + + + +
+
+
+ + +
+
+ + +
+ + +
+
+ + + +
+ + diff --git a/webcit/static/t/section_aide_inetconf_entry.html b/webcit/static/t/section_aide_inetconf_entry.html new file mode 100644 index 000000000..b0af8bf8b --- /dev/null +++ b/webcit/static/t/section_aide_inetconf_entry.html @@ -0,0 +1,7 @@ + + + + + +\')' > + diff --git a/webcit/static/t/siteconfig_tzsection.html b/webcit/static/t/siteconfig_tzsection.html new file mode 100644 index 000000000..ab6471e36 --- /dev/null +++ b/webcit/static/t/siteconfig_tzsection.html @@ -0,0 +1 @@ + diff --git a/webcit/static/t/subject_inet_aliases.html b/webcit/static/t/subject_inet_aliases.html new file mode 100644 index 000000000..a68b51929 --- /dev/null +++ b/webcit/static/t/subject_inet_aliases.html @@ -0,0 +1 @@ + diff --git a/webcit/static/t/subject_inet_dirnames.html b/webcit/static/t/subject_inet_dirnames.html new file mode 100644 index 000000000..9a43094ae --- /dev/null +++ b/webcit/static/t/subject_inet_dirnames.html @@ -0,0 +1 @@ + diff --git a/webcit/static/t/subject_inet_masqdomains.html b/webcit/static/t/subject_inet_masqdomains.html new file mode 100644 index 000000000..151ab4d91 --- /dev/null +++ b/webcit/static/t/subject_inet_masqdomains.html @@ -0,0 +1 @@ + diff --git a/webcit/static/t/subject_inet_rbldns.html b/webcit/static/t/subject_inet_rbldns.html new file mode 100644 index 000000000..bc52ca274 --- /dev/null +++ b/webcit/static/t/subject_inet_rbldns.html @@ -0,0 +1 @@ + diff --git a/webcit/static/t/subject_inet_smarthosts.html b/webcit/static/t/subject_inet_smarthosts.html new file mode 100644 index 000000000..4f9928066 --- /dev/null +++ b/webcit/static/t/subject_inet_smarthosts.html @@ -0,0 +1 @@ + diff --git a/webcit/static/t/subject_inet_spamass.html b/webcit/static/t/subject_inet_spamass.html new file mode 100644 index 000000000..972a52b40 --- /dev/null +++ b/webcit/static/t/subject_inet_spamass.html @@ -0,0 +1 @@ + diff --git a/webcit/static/t/submit_siteconfig.html b/webcit/static/t/submit_siteconfig.html new file mode 100644 index 000000000..75e896e24 --- /dev/null +++ b/webcit/static/t/submit_siteconfig.html @@ -0,0 +1,3 @@ + +  + diff --git a/webcit/subst.c b/webcit/subst.c index 37c7b32d9..38f1bae35 100644 --- a/webcit/subst.c +++ b/webcit/subst.c @@ -464,7 +464,8 @@ void print_value_of(StrBuf *Target, const char *keyname, size_t keylen) { StrBufAppendPrintf(Target, "%ld", ptr->lvalue); break; default: - lprintf(1,"WARNING: invalid value in SV-Hash at %s!", keyname); + lprintf(1,"WARNING: invalid value in SV-Hash at %s!\n", keyname); + StrBufAppendPrintf(Target, "
WARNING: \ninvalid value in SV-Hash at %s!
", keyname); } } } @@ -500,7 +501,7 @@ int CompareSubstToToken(TemplateParam *ParamToCompare, TemplateParam *ParamToLoo return ParamToCompare->lvalue == ptr->lvalue; break; default: - lprintf(1,"WARNING: invalid value in SV-Hash at %s!", + lprintf(1,"WARNING: invalid value in SV-Hash at %s!\n", ParamToLookup->Start); } } @@ -530,7 +531,7 @@ int CompareSubstToStrBuf(StrBuf *Compare, TemplateParam *ParamToLookup) case WCS_LONG: return StrTol(Compare) == ptr->lvalue; default: - lprintf(1,"WARNING: invalid value in SV-Hash at %s!", + lprintf(1,"WARNING: invalid value in SV-Hash at %s!\n", ParamToLookup->Start); } } @@ -665,7 +666,7 @@ WCTemplateToken *NewTemplateSubstitute(StrBuf *Buf, NewToken->TokenEnd = (pTmplEnd - pStart) - NewToken->TokenStart; NewToken->pTokenEnd = pTmplEnd; NewToken->NameEnd = NewToken->TokenEnd - 2; - NewToken->FlatToken = NewStrBufPlain(pTmplStart, pTmplEnd - pTmplStart); + NewToken->FlatToken = NewStrBufPlain(pTmplStart + 2, pTmplEnd - pTmplStart - 2); StrBufPeek(Buf, pTmplStart, + 1, '\0'); StrBufPeek(Buf, pTmplEnd, -1, '\0'); @@ -684,7 +685,12 @@ WCTemplateToken *NewTemplateSubstitute(StrBuf *Buf, if (Param != NULL) { NewToken->HaveParameters = 1; if (NewToken->nParameters > MAXPARAM) { - lprintf(1, "Only %ld Tokens supported!\n", MAXPARAM); + lprintf(1, "Error (in '%s' line %ld); " + "only [%ld] Params allowed in Tokens [%s]\n", + ChrPtr(pTmpl->FileName), + NewToken->Line, + MAXPARAM, + ChrPtr(NewToken->FlatToken)); free(Param); return NULL; } @@ -748,9 +754,9 @@ void FreeWCTemplate(void *vFreeMe) } -int EvaluateConditional(WCTemplateToken *Token, WCTemplate *pTmpl, void *Context, int Neg, int state) +int EvaluateConditional(StrBuf *Target, WCTemplateToken *Token, WCTemplate *pTmpl, void *Context, int Neg, int state) { - void *vConditional; + void *vConditional = NULL; ConditionalStruct *Cond; if ((Token->Params[0]->len == 1) && @@ -760,26 +766,34 @@ int EvaluateConditional(WCTemplateToken *Token, WCTemplate *pTmpl, void *Context if (!GetHash(Contitionals, Token->Params[0]->Start, Token->Params[0]->len, - &vConditional)) { + &vConditional) || + (vConditional == NULL)) { lprintf(1, "Conditional [%s] (in '%s' line %ld); Not found![%s]\n", Token->Params[0]->Start, ChrPtr(pTmpl->FileName), Token->Line, ChrPtr(Token->FlatToken)); + StrBufAppendPrintf( + Target, + "
\nConditional [%s] (in '%s' line %ld); Not found!\n[%s]\n
\n", + Token->Params[0]->Start, + ChrPtr(pTmpl->FileName), + Token->Line, + ChrPtr(Token->FlatToken)); } Cond = (ConditionalStruct *) vConditional; - if (Cond == NULL) { - lprintf(1, "Conditional [%s] (in '%s' line %ld); Not found![%s]\n", + if (Token->nParameters < Cond->nParams) { + lprintf(1, "Conditional [%s] (in '%s' line %ld); needs %ld Params![%s]\n", Token->Params[0]->Start, ChrPtr(pTmpl->FileName), Token->Line, + Cond->nParams, ChrPtr(Token->FlatToken)); - return 0; - } - if (Token->nParameters < Cond->nParams) { - lprintf(1, "Conditional [%s] (in '%s' line %ld); needs %ld Params![%s]\n", + StrBufAppendPrintf( + Target, + "
\nConditional [%s] (in '%s' line %ld); needs %ld Params!\n[%s]\n
\n", Token->Params[0]->Start, ChrPtr(pTmpl->FileName), Token->Line, @@ -802,14 +816,14 @@ int EvaluateToken(StrBuf *Target, WCTemplateToken *Token, WCTemplate *pTmpl, voi TmplGettext(Target, Token->nParameters, Token); break; case SV_CONDITIONAL: /** Forward conditional evaluation */ - return EvaluateConditional(Token, pTmpl, Context, 1, state); + return EvaluateConditional(Target, Token, pTmpl, Context, 1, state); break; case SV_NEG_CONDITIONAL: /** Reverse conditional evaluation */ - return EvaluateConditional(Token, pTmpl, Context, 0, state); + return EvaluateConditional(Target, Token, pTmpl, Context, 0, state); break; case SV_CUST_STR_CONDITIONAL: /** Conditional put custom strings from params */ if (Token->nParameters >= 6) { - if (EvaluateConditional(Token, pTmpl, Context, 0, state)) + if (EvaluateConditional(Target, Token, pTmpl, Context, 0, state)) StrBufAppendBufPlain(Target, Token->Params[5]->Start, Token->Params[5]->len, @@ -832,12 +846,21 @@ int EvaluateToken(StrBuf *Target, WCTemplateToken *Token, WCTemplate *pTmpl, voi if ((Token->nParameters < Handler->nMinArgs) || (Token->nParameters > Handler->nMaxArgs)) { lprintf(1, "Handler [%s] (in '%s' line %ld); " - "doesn't work with %ld params [%s]", + "doesn't work with %ld params [%s]\n", Token->pName, ChrPtr(pTmpl->FileName), Token->Line, Token->nParameters, ChrPtr(Token->FlatToken)); + StrBufAppendPrintf( + Target, + "
\nHandler [%s] (in '%s' line %ld);"
+					" doesn't work with %ld params!\n[%s]\n
\n", + Token->pName, + ChrPtr(pTmpl->FileName), + Token->Line, + Token->nParameters, + ChrPtr(Token->FlatToken)); } else { Handler->HandlerFunc(Target, @@ -845,7 +868,6 @@ int EvaluateToken(StrBuf *Target, WCTemplateToken *Token, WCTemplate *pTmpl, voi Token, Context); /*TODO: subset of that */ - } } else { @@ -868,6 +890,16 @@ void ProcessTemplate(WCTemplate *Tmpl, StrBuf *Target, void *Context) lprintf(1, "DBG: ----- loading: [%s] ------ \n", ChrPtr(Tmpl->FileName)); pTmpl = load_template(Tmpl->FileName, NULL, NULL); + if(pTmpl == NULL) { + StrBufAppendPrintf( + Target, + "
\nError loading Template [%s]\n See Logfile for details\n
\n", + ChrPtr(Tmpl->FileName)); + return; + + + } + } pS = pData = ChrPtr(pTmpl->Data); @@ -891,11 +923,13 @@ void ProcessTemplate(WCTemplate *Tmpl, StrBuf *Target, void *Context) i++; if ((pTmpl->Tokens[i]->Flags == SV_CONDITIONAL) || (pTmpl->Tokens[i]->Flags == SV_NEG_CONDITIONAL)) { - if (state == EvaluateConditional(pTmpl->Tokens[i], - pTmpl, - Context, - pTmpl->Tokens[i]->Flags, - state)) + if (state == EvaluateConditional( + Target, + pTmpl->Tokens[i], + pTmpl, + Context, + pTmpl->Tokens[i]->Flags, + state)) state = 0; } } @@ -1040,9 +1074,19 @@ void DoTemplate(const char *templatename, long len, void *Context, StrBuf *Targe StaticLocal = LocalTemplateCache; } + if (len == 0) + { + lprintf (1, "Can't to load a template with empty name!\n"); + StrBufAppendPrintf(Target, "
\nCan't to load a template with empty name!\n
"); + return; + } + if (!GetHash(StaticLocal, templatename, len, &vTmpl) && !GetHash(Static, templatename, len, &vTmpl)) { - printf ("didn't find %s %ld %ld\n", templatename, len , (long)strlen(templatename)); + lprintf (1, "didn't find Template [%s] %ld %ld\n", templatename, len , (long)strlen(templatename)); + StrBufAppendPrintf(Target, "
\ndidn't find Template [%s] %ld %ld\n
", + templatename, len, + (long)strlen(templatename)); /// dbg_PrintHash(Static, PrintTemplate, NULL); // PrintHash(Static, VarPrintTransition, PrintTemplate); return; @@ -1087,6 +1131,8 @@ int LoadTemplateDir(const char *DirName, HashList *wireless, HashList *big) d_without_ext --; if ((d_without_ext == 0) || (d_namelen < 3)) continue; + if ((d_namelen > 1) && filedir_entry->d_name[d_namelen - 1] == '~') + continue; /* Ignore backup files... */ IsMobile = (strstr(filedir_entry->d_name, ".m.html")!= NULL); PStart = filedir_entry->d_name; @@ -1097,7 +1143,7 @@ int LoadTemplateDir(const char *DirName, HashList *wireless, HashList *big) StrBufPlain(Tag, filedir_entry->d_name, MinorPtr - filedir_entry->d_name); - printf("%s %d %s\n",ChrPtr(FileName), IsMobile, ChrPtr(Tag)); + lprintf(1, "%s %d %s\n",ChrPtr(FileName), IsMobile, ChrPtr(Tag)); if (LoadTemplates == 0) load_template(FileName, Tag, (IsMobile)?wireless:big); else @@ -1170,6 +1216,7 @@ void tmplput_current_room(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, vo typedef struct _HashIterator { HashList *StaticList; + int AdditionalParams; RetrieveHashlistFunc GetHash; HashDestructorFunc Destructor; SubTemplFunc DoSubTemplate; @@ -1192,9 +1239,29 @@ void tmpl_iterate_subtmpl(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, vo Tokens->Params[0]->len, &vIt)) return; + It = (HashIterator*) vIt; + + if (Tokens->nParameters < It->AdditionalParams + 2) { + lprintf(1, "Iterator [%s] (in line %ld); " + "doesn't work with %ld params [%s]\n", + Tokens->Params[0]->Start, + Tokens->Line, + Tokens->nParameters, + ChrPtr(Tokens->FlatToken)); + StrBufAppendPrintf( + Target, + "
Iterator [%s] \n(in line %ld);\n"
+			"doesn't work with %ld params \n[%s]\n
", + Tokens->Params[0]->Start, + Tokens->Line, + Tokens->nParameters, + ChrPtr(Tokens->FlatToken)); + return; + } + if (It->StaticList == NULL) - List = It->GetHash(); + List = It->GetHash(Tokens); else List = It->StaticList; @@ -1202,7 +1269,8 @@ void tmpl_iterate_subtmpl(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, vo it = GetNewHashPos(); while (GetNextHashPos(List, it, &len, &Key, &vContext)) { svprintf(HKEY("ITERATE:ODDEVEN"), WCS_STRING, "%s", (oddeven)?"odd":"even"); - It->DoSubTemplate(SubBuf, vContext); + svprintf(HKEY("ITERATE:KEY"), WCS_STRING, "%s",Key); + It->DoSubTemplate(SubBuf, vContext, Tokens); DoTemplate(Tokens->Params[1]->Start, Tokens->Params[1]->len, vContext, SubBuf); @@ -1251,6 +1319,7 @@ int ConditionalVar(WCTemplateToken *Tokens, void *Context) } void RegisterITERATOR(const char *Name, long len, + int AdditionalParams, HashList *StaticList, RetrieveHashlistFunc GetHash, SubTemplFunc DoSubTempl, @@ -1258,6 +1327,7 @@ void RegisterITERATOR(const char *Name, long len, { HashIterator *It = (HashIterator*)malloc(sizeof(HashIterator)); It->StaticList = StaticList; + It->AdditionalParams = AdditionalParams; It->GetHash = GetHash; It->DoSubTemplate = DoSubTempl; It->Destructor = Destructor; @@ -1341,7 +1411,7 @@ InitModule_SUBST /// RegisterNamespace("SERV:LDAP_SUPP", 0, 0, tmmplput_serv_ldap_enabled); RegisterNamespace("CURRENT_USER", 0, 0, tmplput_current_user); RegisterNamespace("CURRENT_ROOM", 0, 0, tmplput_current_room); - RegisterNamespace("ITERATE", 2, 4, tmpl_iterate_subtmpl); + RegisterNamespace("ITERATE", 2, 100, tmpl_iterate_subtmpl); RegisterNamespace("DOBOXED", 1, 2, tmpl_do_boxed); RegisterNamespace("DOTABBED", 2, 100, tmpl_do_tabbed); RegisterConditional(HKEY("COND:SUBST"), 3, ConditionalVar); diff --git a/webcit/webcit.h b/webcit/webcit.h index 365c2e67f..717645ea9 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -320,16 +320,16 @@ void RegisterConditional(const char *Name, long len, -typedef void (*SubTemplFunc)(StrBuf *TemplBuffer, void *Context); -typedef HashList *(*RetrieveHashlistFunc)(void); +typedef void (*SubTemplFunc)(StrBuf *TemplBuffer, void *Context, WCTemplateToken *Token); +typedef HashList *(*RetrieveHashlistFunc)(WCTemplateToken *Token); typedef void (*HashDestructorFunc) (HashList *KillMe); -void RegisterITERATOR(const char *Name, long len, +void RegisterITERATOR(const char *Name, long len, + int AdditionalParams, HashList *StaticList, RetrieveHashlistFunc GetHash, SubTemplFunc DoSubTempl, HashDestructorFunc Destructor); -#define RegisterIterator(a, b, c, d, e) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e) - +#define RegisterIterator(a, b, c, d, e, f) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f) /** * \brief Values for wcs_type @@ -472,6 +472,7 @@ struct wcsession { StrBuf *HBuf; /**< Our HeaderBuffer */ HashList *ServCfg; /**< cache our server config for editing */ + HashList *InetCfg; /**< Our inet server config for editing */ }; /** values for WC->current_iconbar */ diff --git a/webcit/who.c b/webcit/who.c index a57a3f20b..0d78dee59 100644 --- a/webcit/who.c +++ b/webcit/who.c @@ -444,7 +444,7 @@ void _terminate_session(void) { terminate_session(); } -HashList *GetWholistHash(void) +HashList *GetWholistHash(WCTemplateToken *Token) { HashList *List; char buf[SIZ]; @@ -464,7 +464,7 @@ HashList *GetWholistHash(void) return List; } -void WholistSubst(StrBuf *TemplBuffer, void *vContext) +void WholistSubst(StrBuf *TemplBuffer, void *vContext, WCTemplateToken *Token) { UserStateStruct *User = (UserStateStruct*) vContext; @@ -496,5 +496,5 @@ InitModule_WHO WebcitAddUrlHandler(HKEY("terminate_session"), _terminate_session, 0); WebcitAddUrlHandler(HKEY("edit_me"), edit_me, 0); - RegisterIterator("WHOLIST", NULL, GetWholistHash, WholistSubst, DeleteWholistHash); + RegisterIterator("WHOLIST", 0, NULL, GetWholistHash, WholistSubst, DeleteWholistHash); }