* print errormessages into templates if possible in <pre>
authorWilfried Göesgens <willi@citadel.org>
Wed, 10 Sep 2008 16:00:03 +0000 (16:00 +0000)
committerWilfried Göesgens <willi@citadel.org>
Wed, 10 Sep 2008 16:00:03 +0000 (16:00 +0000)
* 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.

24 files changed:
webcit/.svnignore
webcit/inetconf.c
webcit/preferences.c
webcit/siteconfig.c
webcit/static/t/aide_global_config.html
webcit/static/t/aide_inet_aliases.html [new file with mode: 0644]
webcit/static/t/aide_inet_dirnames.html [new file with mode: 0644]
webcit/static/t/aide_inet_masqdomains.html [new file with mode: 0644]
webcit/static/t/aide_inet_rbldns.html [new file with mode: 0644]
webcit/static/t/aide_inet_smarthosts.html [new file with mode: 0644]
webcit/static/t/aide_inet_spamass.html [new file with mode: 0644]
webcit/static/t/aide_inetconf.html [new file with mode: 0644]
webcit/static/t/section_aide_inetconf_entry.html [new file with mode: 0644]
webcit/static/t/siteconfig_tzsection.html [new file with mode: 0644]
webcit/static/t/subject_inet_aliases.html [new file with mode: 0644]
webcit/static/t/subject_inet_dirnames.html [new file with mode: 0644]
webcit/static/t/subject_inet_masqdomains.html [new file with mode: 0644]
webcit/static/t/subject_inet_rbldns.html [new file with mode: 0644]
webcit/static/t/subject_inet_smarthosts.html [new file with mode: 0644]
webcit/static/t/subject_inet_spamass.html [new file with mode: 0644]
webcit/static/t/submit_siteconfig.html [new file with mode: 0644]
webcit/subst.c
webcit/webcit.h
webcit/who.c

index b9cb88b3ab0202daaaa1de2d3c5428f4bdd5eef9..516dad4d7af5a4c44f56353efac4ed57461d4e23 100644 (file)
@@ -1,3 +1,4 @@
 aclocal.m4
 *.d
-
+gmon.out
+modules_init.c
index 87964d30554208acc8c65a8d22bba9ef0b8ceaa8..1f234a4f8866f2b46b8823f7906d7dbb4a5d3a21 100644 (file)
@@ -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);
 }
index 28aac7dfef72640d99d7a947c414e9d1de725504..8d3b4f8dd586c54035ab8fe79677cb9362d702e1 100644 (file)
@@ -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);
 }
index bde63a706dec9eddf6cdc5bf990fc062c3ea51d5..00ebd60cdaf8f035bf0c3d321f9916aa40c247b4 100644 (file)
@@ -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();
index 7247b0d3ef4a11afe7003dda3b754bcfce8c0344..3149e66c31e06f07a7fde683849785135207a221 100644 (file)
@@ -1,6 +1,6 @@
 <ul class="adminitems">
 <li><a href="do_template?template=display_sitewide_config"><?_("Edit site-wide configuration")></a></li>
-<li><a href="display_inetconf"><?_("Domain names and Internet mail configuration")></a></li>
+<li><a href="do_template?template=aide_inetconf"><?_("Domain names and Internet mail configuration")></a></li>
 <li><a href="display_netconf"><?_("Configure replication with other Citadel servers")></a></li>
 <li><a href="display_smtpqueue"><?_("View the outbound SMTP queue")></a></li>
 </ul>
diff --git a/webcit/static/t/aide_inet_aliases.html b/webcit/static/t/aide_inet_aliases.html
new file mode 100644 (file)
index 0000000..24df4ee
--- /dev/null
@@ -0,0 +1,14 @@
+<span class="menudesc">
+<?_("(domains for which this host receives mail)")>
+</span><br />
+<table border=0 cellspacing="2px" cellpadding="2px" width=94%% class="altern" >
+<?ITERATE("SERVCFG:INET", "section_aide_inetconf_entry", "localhost")>
+<form method="post" action="save_inetconf">
+<input type="hidden" name="nonce" value='<?NONCE>'>
+<tr><td>
+<input type="text" name="ename" maxlength="64">
+<input type="hidden" name="etype" VALUE="localhost">
+</td><td align=left>
+<input type="submit" name="oper" value="Add">
+<input type="hidden" name="template" value="aide_inetconf">
+</td></tr></table></form>
diff --git a/webcit/static/t/aide_inet_dirnames.html b/webcit/static/t/aide_inet_dirnames.html
new file mode 100644 (file)
index 0000000..704928f
--- /dev/null
@@ -0,0 +1,14 @@
+<span class="menudesc">
+<?_("(domains mapped with the Global Address Book)")>
+</span><br />
+<table border=0 cellspacing="2px" cellpadding="2px" width=94%% class="altern" >
+<?ITERATE("SERVCFG:INET", "section_aide_inetconf_entry", "directory")>
+<form method="post" action="save_inetconf">
+<input type="hidden" name="nonce" value='<?NONCE>'>
+<tr><td>
+<input type="text" name="ename" maxlength="64">
+<input type="hidden" name="etype" VALUE="directory">
+</td><td align=left>
+<input type="submit" name="oper" value="Add">
+<input type="hidden" name="template" value="aide_inetconf">
+</td></tr></table></form>
diff --git a/webcit/static/t/aide_inet_masqdomains.html b/webcit/static/t/aide_inet_masqdomains.html
new file mode 100644 (file)
index 0000000..da65d34
--- /dev/null
@@ -0,0 +1,14 @@
+<span class="menudesc">
+<?_("(Domains as which users are allowed to masquerade)")>
+</span><br />
+<table border=0 cellspacing="2px" cellpadding="2px" width=94%% class="altern" >
+<?ITERATE("SERVCFG:INET", "section_aide_inetconf_entry", "masqdomain")>
+<form method="post" action="save_inetconf">
+<input type="hidden" name="nonce" value='<?NONCE>'>
+<tr><td>
+<input type="text" name="ename" maxlength="64">
+<input type="hidden" name="etype" VALUE="directory">
+</td><td align=left>
+<input type="submit" name="oper" value="Add">
+<input type="hidden" name="template" value="aide_inetconf">
+</td></tr></table></form>
diff --git a/webcit/static/t/aide_inet_rbldns.html b/webcit/static/t/aide_inet_rbldns.html
new file mode 100644 (file)
index 0000000..000eede
--- /dev/null
@@ -0,0 +1,14 @@
+<span class="menudesc">
+<?_("(hosts running a Realtime Blackhole List)")>
+</span><br />
+<table border=0 cellspacing="2px" cellpadding="2px" width=94%% class="altern" >
+<?ITERATE("SERVCFG:INET", "section_aide_inetconf_entry", "rbl")>
+<form method="post" action="save_inetconf">
+<input type="hidden" name="nonce" value='<?NONCE>'>
+<tr><td>
+<input type="text" name="ename" maxlength="64">
+<input type="hidden" name="etype" VALUE="rbl">
+</td><td align=left>
+<input type="submit" name="oper" value="Add">
+<input type="hidden" name="template" value="aide_inetconf">
+</td></tr></table></form>
diff --git a/webcit/static/t/aide_inet_smarthosts.html b/webcit/static/t/aide_inet_smarthosts.html
new file mode 100644 (file)
index 0000000..5f66d93
--- /dev/null
@@ -0,0 +1,14 @@
+<span class="menudesc">
+<?_("(if present, forward all outbound mail to one of these hosts)")>
+</span><br />
+<table border=0 cellspacing="2px" cellpadding="2px" width=94%% class="altern" >
+<?ITERATE("SERVCFG:INET", "section_aide_inetconf_entry", "smarthost")>
+<form method="post" action="save_inetconf">
+<input type="hidden" name="nonce" value='<?NONCE>'>
+<tr><td>
+<input type="text" name="ename" maxlength="64">
+<input type="hidden" name="etype" VALUE="rbl">
+</td><td align=left>
+<input type="submit" name="oper" value="Add">
+<input type="hidden" name="template" value="aide_inetconf">
+</td></tr></table></form>
diff --git a/webcit/static/t/aide_inet_spamass.html b/webcit/static/t/aide_inet_spamass.html
new file mode 100644 (file)
index 0000000..a77f91f
--- /dev/null
@@ -0,0 +1,14 @@
+<span class="menudesc">
+<?_("(hosts running the SpamAssassin service)")>
+</span><br />
+<table border=0 cellspacing="2px" cellpadding="2px" width=94%% class="altern" >
+<?ITERATE("SERVCFG:INET", "section_aide_inetconf_entry", "spamassassin")>
+<form method="post" action="save_inetconf">
+<input type="hidden" name="nonce" value='<?NONCE>'>
+<tr><td>
+<input type="text" name="ename" maxlength="64">
+<input type="hidden" name="etype" VALUE="spamassassin">
+</td><td align=left>
+<input type="submit" name="oper" value="Add">
+<input type="hidden" name="template" value="aide_inetconf">
+</td></tr></table></form>
diff --git a/webcit/static/t/aide_inetconf.html b/webcit/static/t/aide_inetconf.html
new file mode 100644 (file)
index 0000000..fbccd28
--- /dev/null
@@ -0,0 +1,29 @@
+<?=("head")>
+<?=("important_msg")>
+<?ICONBAR>
+<div id="banner">
+<h1>
+<??("COND:AIDE", 1)><?_("System Administration Menu")><??("X", 1)>
+<?!("COND:AIDE", 2)><?_("Room Aide Menu")><?!("X", 2)>
+</h1>
+</div>
+<div id="content" class="service">
+<div class="fix_scrollbar_bug">
+<table border=0 width=100% cellspacing="10px" cellpadding="10px"> <tr><td valign=top width=50%>
+
+
+<?DOBOXED("aide_inet_aliases", "subject_inet_aliases")><br />
+<?DOBOXED("aide_inet_dirnames", "subject_inet_dirnames")><br />
+<?DOBOXED("aide_inet_smarthosts", "subject_inet_smarthosts")>
+
+</td><td valign=top>
+
+
+<?DOBOXED("aide_inet_rbldns", "subject_inet_rbldns")><br />
+<?DOBOXED("aide_inet_spamass", "subject_inet_spamass")><br />
+<?DOBOXED("aide_inet_masqdomains", "subject_inet_masqdomains")>
+
+
+</td></tr></table>
+<?SERVCFG:FLUSHINETCFG>
+<?=("trailing")>
diff --git a/webcit/static/t/section_aide_inetconf_entry.html b/webcit/static/t/section_aide_inetconf_entry.html
new file mode 100644 (file)
index 0000000..b0af8bf
--- /dev/null
@@ -0,0 +1,7 @@
+<tr class='<?ITERATE:ODDEVEN>'>
+<td align=left>
+<?SERVCFG:INET:HOSTNAME>
+</td><td align=left>
+<span class="button_link">
+<a href='save_inetconf?template=aide_inetconf&oper=delete&ename=<?ITERATE:KEY>&etype=<?SERVCFG:INET:TYPE>' onClick='return confirm(\'<?_("Delete this entry?")>\')' >
+<?_("Delete")> </a></span></td></tr>
diff --git a/webcit/static/t/siteconfig_tzsection.html b/webcit/static/t/siteconfig_tzsection.html
new file mode 100644 (file)
index 0000000..ab6471e
--- /dev/null
@@ -0,0 +1 @@
+<OPTION <?%("COND:SERVCFG:SUBST", 1, "c_default_cal_zone", "ZONENAME", 'selected="selected"', "")> VALUE='<?ZONENAME>'><?ZONENAME></OPTION>
diff --git a/webcit/static/t/subject_inet_aliases.html b/webcit/static/t/subject_inet_aliases.html
new file mode 100644 (file)
index 0000000..a68b519
--- /dev/null
@@ -0,0 +1 @@
+<?_("Local host aliases")>
diff --git a/webcit/static/t/subject_inet_dirnames.html b/webcit/static/t/subject_inet_dirnames.html
new file mode 100644 (file)
index 0000000..9a43094
--- /dev/null
@@ -0,0 +1 @@
+<?_("Directory domains")>
diff --git a/webcit/static/t/subject_inet_masqdomains.html b/webcit/static/t/subject_inet_masqdomains.html
new file mode 100644 (file)
index 0000000..151ab4d
--- /dev/null
@@ -0,0 +1 @@
+<?_("Masqueradable domains")>
diff --git a/webcit/static/t/subject_inet_rbldns.html b/webcit/static/t/subject_inet_rbldns.html
new file mode 100644 (file)
index 0000000..bc52ca2
--- /dev/null
@@ -0,0 +1 @@
+<?_("RBL hosts")>
diff --git a/webcit/static/t/subject_inet_smarthosts.html b/webcit/static/t/subject_inet_smarthosts.html
new file mode 100644 (file)
index 0000000..4f99280
--- /dev/null
@@ -0,0 +1 @@
+<?_("Smart hosts")>
diff --git a/webcit/static/t/subject_inet_spamass.html b/webcit/static/t/subject_inet_spamass.html
new file mode 100644 (file)
index 0000000..972a52b
--- /dev/null
@@ -0,0 +1 @@
+<?_("SpamAssassin hosts")>
diff --git a/webcit/static/t/submit_siteconfig.html b/webcit/static/t/submit_siteconfig.html
new file mode 100644 (file)
index 0000000..75e896e
--- /dev/null
@@ -0,0 +1,3 @@
+<input type="submit" NAME="ok_button" VALUE='<?_("Save changes")>'>
+&nbsp;
+<input type="submit" NAME="cancel_button" VALUE='<?_("Cancel")>'>
index 37c7b32d96114aea08b6fcaafd43bf3f5e106c9c..38f1bae356a1631921c6cb999a617c58b1a23707 100644 (file)
@@ -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, "<pre>WARNING: \ninvalid value in SV-Hash at %s!</pre>", 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, 
+                       "<pre>\nConditional [%s] (in '%s' line %ld); Not found!\n[%s]\n</pre>\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, 
+                       "<pre>\nConditional [%s] (in '%s' line %ld); needs %ld Params!\n[%s]\n</pre>\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, 
+                                       "<pre>\nHandler [%s] (in '%s' line %ld);"
+                                       " doesn't work with %ld params!\n[%s]\n</pre>\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, 
+                               "<pre>\nError loading Template [%s]\n See Logfile for details\n</pre>\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, "<pre>\nCan't to load a template with empty name!\n</pre>");
+               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, "<pre>\ndidn't find Template [%s] %ld %ld\n</pre>", 
+                                  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,
+                       "<pre>Iterator [%s] \n(in line %ld);\n"
+                       "doesn't work with %ld params \n[%s]\n</pre>", 
+                       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);
index 365c2e67f36b6727ce4c12ee064add24a3687c1b..717645ea9031e5d58e4c7eca3c994ea41560879e 100644 (file)
@@ -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 */
index a57a3f20bb5dbd73194d28ec4a7d2cb9796efa6a..0d78dee59eef68f95747068f6c467d80b0d5af95 100644 (file)
@@ -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);
 }