From aafa773c33eef66c0d1836d034419bf96e94c156 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Sun, 23 Nov 2008 18:22:20 +0000 Subject: [PATCH] * finish selectboxes in Mailedit dialogs * new templating mechanism: if prepended by : ; _ B the tokens can be loaded via preferences / gettext / bstr * start implementing preferences screen with templates * fix some tiny bugs --- webcit/context_loop.c | 4 +- webcit/preferences.c | 25 ++- webcit/static/t/beginbox.html | 2 +- webcit/static/t/beginbox.m.html | 2 +- webcit/static/t/box_preferences.html | 143 ++++++++++++++++++ webcit/static/t/preferences.html | 9 ++ webcit/static/t/pushemail.html | 2 +- .../t/section_msg_sender_from_select.html | 2 +- .../t/section_msg_sender_name_select.html | 2 +- webcit/subst.c | 118 +++++++++++++-- webcit/webcit.h | 15 +- 11 files changed, 292 insertions(+), 32 deletions(-) create mode 100644 webcit/static/t/box_preferences.html create mode 100644 webcit/static/t/preferences.html diff --git a/webcit/context_loop.c b/webcit/context_loop.c index 9bbb477c4..ece52c754 100644 --- a/webcit/context_loop.c +++ b/webcit/context_loop.c @@ -356,7 +356,7 @@ void context_loop(int *sock) (isspace(*ChrPtr(Line)))) { pch = pchs = ChrPtr(Line); pche = pchs + StrLength(Line); - while (isspace(pch) && (pch < pche)) + while (isspace(*pch) && (pch < pche)) pch ++; StrBufCutLeft(Line, pch - pchs); StrBufAppendBuf(LastLine, Line, 0); @@ -444,7 +444,7 @@ void context_loop(int *sock) StrBufCutLeft(ReqLine, StrLength(ReqType) + 1); StrBufCutRight(ReqLine, StrLength(HTTPVersion) + 1); - if ((StrLength(ReqLine) >= 8) && + if ((follow_xff == 1) && (StrLength(ReqLine) >= 8) && (ptr = strstr(ChrPtr(ReqLine), "/webcit/"), /*< Handle "/webcit/" */ (ptr != NULL))) { StrBufCutLeft(ReqLine, 7); diff --git a/webcit/preferences.c b/webcit/preferences.c index e4689e8ad..c839d5738 100644 --- a/webcit/preferences.c +++ b/webcit/preferences.c @@ -654,6 +654,9 @@ void set_preferences(void) set_pref_long("dayend", lbstr("dayend"), 0); set_preference("default_header_charset", NewStrBufPlain(bstr("default_header_charset"), -1), 0); set_preference("emptyfloors", NewStrBufPlain(bstr("emptyfloors"), -1), 0); + set_preference("defaultfrom", NewStrBufDup(sbstr("defaultfrom")), 0); + set_preference("defaultname", NewStrBufDup(sbstr("defaultname")), 0); + buf = NewStrBufPlain(bstr("signature"), -1); encBuf = NewStrBuf(); @@ -751,11 +754,6 @@ void DeleteGVEAHash(HashList **KillMe) { DeleteHash(KillMe); } -void tmplput_EMAIL_ADDR(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType) -{ - StrBuf *EmailAddr = (StrBuf*) Context; - StrBufAppendBuf(Target, EmailAddr, 0); -} HashList *GetGVSNHash(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) { @@ -792,11 +790,7 @@ void DeleteGVSNHash(HashList **KillMe) { DeleteHash(KillMe); } -void tmplput_EMAIL_NAME(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType) -{ - StrBuf *EmailAddr = (StrBuf*) Context; - StrBufAppendBuf(Target, EmailAddr, 0); -} + void InitModule_PREFERENCES @@ -815,6 +809,11 @@ InitModule_PREFERENCES RegisterPreference("signature",_("Use this signature:"),PRF_QP_STRING); RegisterPreference("default_header_charset", _("Default character set for email headers:") ,PRF_STRING); RegisterPreference("emptyfloors", _("Show empty floors"), PRF_YESNO); + RegisterPreference("defaultfrom", _("Prefered Email Address"), PRF_STRING); + RegisterPreference("defaultname", _("Prefered Email Sendername"), PRF_STRING); + + + RegisterNamespace("PREF:VALUE", 1, 2, tmplput_CFG_Value, CTX_NONE); RegisterNamespace("PREF:DESCR", 1, 1, tmplput_CFG_Descr, CTX_NONE); @@ -822,12 +821,10 @@ InitModule_PREFERENCES RegisterConditional(HKEY("COND:PREF"), 4, ConditionalPreference, CTX_NONE); - RegisterNamespace("PREF:EMAIL:ADDR", 0, 1, tmplput_EMAIL_ADDR, CTX_GVEA); RegisterIterator("PREF:VALID:EMAIL:ADDR", 0, NULL, - GetGVEAHash, NULL, DeleteGVEAHash, CTX_GVEA, CTX_NONE); - RegisterNamespace("PREF:EMAIL:NAME", 0, 1, tmplput_EMAIL_NAME, CTX_GVSN); + GetGVEAHash, NULL, DeleteGVEAHash, CTX_STRBUF, CTX_NONE); RegisterIterator("PREF:VALID:EMAIL:NAME", 0, NULL, - GetGVSNHash, NULL, DeleteGVSNHash, CTX_GVSN, CTX_NONE); + GetGVSNHash, NULL, DeleteGVSNHash, CTX_STRBUF, CTX_NONE); } /*@}*/ diff --git a/webcit/static/t/beginbox.html b/webcit/static/t/beginbox.html index 593fefef9..32ecfedac 100644 --- a/webcit/static/t/beginbox.html +++ b/webcit/static/t/beginbox.html @@ -1,5 +1,5 @@
-
+
diff --git a/webcit/static/t/beginbox.m.html b/webcit/static/t/beginbox.m.html index 593fefef9..2d9cc609d 100644 --- a/webcit/static/t/beginbox.m.html +++ b/webcit/static/t/beginbox.m.html @@ -1,5 +1,5 @@
-
+
diff --git a/webcit/static/t/box_preferences.html b/webcit/static/t/box_preferences.html new file mode 100644 index 000000000..faa26c9de --- /dev/null +++ b/webcit/static/t/box_preferences.html @@ -0,0 +1,143 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ > +     + > +
+ + > +     + > +
+ +
+
+ + + +
+ + +signature + + + +  ,   + +

+ +
+
"> +
+ > +     + > +
+ +
+ ">  + "> +
diff --git a/webcit/static/t/preferences.html b/webcit/static/t/preferences.html new file mode 100644 index 000000000..3b30345c2 --- /dev/null +++ b/webcit/static/t/preferences.html @@ -0,0 +1,9 @@ + + + + +
+ +
+ diff --git a/webcit/static/t/pushemail.html b/webcit/static/t/pushemail.html index bf9213b8c..15711e910 100644 --- a/webcit/static/t/pushemail.html +++ b/webcit/static/t/pushemail.html @@ -5,7 +5,7 @@
-
+
diff --git a/webcit/static/t/section_msg_sender_from_select.html b/webcit/static/t/section_msg_sender_from_select.html index d683d6fa9..6fe807466 100644 --- a/webcit/static/t/section_msg_sender_from_select.html +++ b/webcit/static/t/section_msg_sender_from_select.html @@ -1 +1 @@ - + diff --git a/webcit/static/t/section_msg_sender_name_select.html b/webcit/static/t/section_msg_sender_name_select.html index 41373c54b..a0b760f4c 100644 --- a/webcit/static/t/section_msg_sender_name_select.html +++ b/webcit/static/t/section_msg_sender_name_select.html @@ -1 +1 @@ - + diff --git a/webcit/subst.c b/webcit/subst.c index c77851bf8..4d102045b 100644 --- a/webcit/subst.c +++ b/webcit/subst.c @@ -506,6 +506,54 @@ void StrBufAppendTemplate(StrBuf *Target, } +void GetTemplateTokenString(WCTemplateToken *Tokens, + int N, + const char **Value, + long *len) +{ + StrBuf *Buf; + + if (Tokens->HaveParameters < N) { + *Value = ""; + *len = 0; + return; + } + + switch (Tokens->Params[N]->Type) { + + case TYPE_STR: + *Value = Tokens->Params[N]->Start; + *len = Tokens->Params[N]->len; + break; + case TYPE_BSTR: + Buf = (StrBuf*) SBstr(Tokens->Params[N]->Start, + Tokens->Params[N]->len); + *Value = ChrPtr(Buf); + *len = StrLength(Buf); + break; + case TYPE_PREFSTR: + get_PREFERENCE( + Tokens->Params[N]->Start, + Tokens->Params[N]->len, + &Buf); + *Value = ChrPtr(Buf); + *len = StrLength(Buf); + break; + case TYPE_LONG: + case TYPE_PREFINT: + break; ///todo: string to text? + case TYPE_GETTEXT: + *Value = _(Tokens->Params[N]->Start); + *len = strlen(*Value); + break; + default: + break; +//todo log error + } +} + + + /** * \brief Print the value of a variable * \param keyname get a key to print @@ -658,11 +706,33 @@ TemplateParam *GetNextParameter(StrBuf *Buf, const char **pCh, const char *pe, W TemplateParam *Parm = (TemplateParam *) malloc(sizeof(TemplateParam)); char quote = '\0'; + + Parm->Type = TYPE_STR; + /* Skip leading whitespaces */ while ((*pch == ' ' )|| (*pch == '\t')|| (*pch == '\r')|| (*pch == '\n')) pch ++; + + if (*pch == ':') { + Parm->Type = TYPE_PREFSTR; + pch ++; + } + else if (*pch == ';') { + Parm->Type = TYPE_PREFINT; + pch ++; + } + else if (*pch == '_') { + Parm->Type = TYPE_GETTEXT; + pch ++; + } + else if (*pch == 'B') { + Parm->Type = TYPE_BSTR; + pch ++; + } + + if (*pch == '"') quote = '"'; else if (*pch == '\'') @@ -670,7 +740,6 @@ TemplateParam *GetNextParameter(StrBuf *Buf, const char **pCh, const char *pe, W if (quote != '\0') { pch ++; pchs = pch; - Parm->Type = TYPE_STR; while (pch <= pe && ((*pch != quote) || ( (pch > pchs) && (*(pch - 1) == '\\')) @@ -1572,19 +1641,46 @@ void RegisterConditional(const char *Name, long len, Put(Conditionals, Name, len, Cond, NULL); } + +void tmplput_ContextString(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) +{ + StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, (StrBuf*)Context, 0); +} +int ConditionalContextStr(WCTemplateToken *Tokens, void *Context, int ContextType) +{ + StrBuf *EmailAddr = (StrBuf*) Context; + const char *CompareToken; + long len; + + GetTemplateTokenString(Tokens, 3, &CompareToken, &len); + return strcmp(ChrPtr(EmailAddr), CompareToken) == 0; +} + + void tmpl_do_boxed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) { + StrBuf *Headline; if (nArgs == 2) { - StrBuf *Headline = NewStrBuf(); - DoTemplate(Tokens->Params[1]->Start, - Tokens->Params[1]->len, - Headline, - Context, - ContextType); - SVPutBuf("BOXTITLE", Headline, 0); + if (Tokens->Params[1]->Type == TYPE_STR) { + Headline = NewStrBuf(); + DoTemplate(Tokens->Params[1]->Start, + Tokens->Params[1]->len, + Headline, + Context, + ContextType); + } + else { + const char *Ch; + long *len; + GetTemplateTokenString(Tokens, + 1, + &Ch, + &len); + Headline = NewStrBufPlain(Ch, len); + } } - DoTemplate(HKEY("beginbox"), Target, Context, ContextType); + DoTemplate(HKEY("beginbox"), Target, Headline, CTX_STRBUF); DoTemplate(Tokens->Params[0]->Start, Tokens->Params[0]->len, Target, @@ -1593,6 +1689,7 @@ void tmpl_do_boxed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Con DoTemplate(HKEY("endbox"), Target, Context, ContextType); } + void tmpl_do_tabbed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) { StrBuf **TabNames; @@ -1633,10 +1730,13 @@ void InitModule_SUBST (void) { + RegisterNamespace("CONTEXTSTR", 0, 1, tmplput_ContextString, CTX_STRBUF); RegisterNamespace("ITERATE", 2, 100, tmpl_iterate_subtmpl, CTX_NONE); RegisterNamespace("DOBOXED", 1, 2, tmpl_do_boxed, CTX_NONE); RegisterNamespace("DOTABBED", 2, 100, tmpl_do_tabbed, CTX_NONE); RegisterConditional(HKEY("COND:SUBST"), 3, ConditionalVar, CTX_NONE); + RegisterConditional(HKEY("COND:CONTEXT"), 3, ConditionalContextStr, CTX_NONE); + } /*@}*/ diff --git a/webcit/webcit.h b/webcit/webcit.h index 4aa951252..7dd5922d5 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -260,7 +260,13 @@ struct roomlisting { #define TYPE_STR 1 #define TYPE_LONG 2 +#define TYPE_PREFSTR 3 +#define TYPE_PREFINT 4 +#define TYPE_GETTEXT 5 +#define TYPE_BSTR 6 #define MAXPARAM 20 + + typedef struct _TemplateParam { const char *Start; int Type; @@ -314,8 +320,7 @@ typedef struct _wcsubst { #define CTX_MAILSUM 9 #define CTX_MIME_ATACH 10 #define CTX_ATT 11 -#define CTX_GVEA 12 -#define CTX_GVSN 13 +#define CTX_STRBUF 12 void RegisterNS(const char *NSName, long len, int nMinArgs, @@ -350,6 +355,12 @@ void RegisterITERATOR(const char *Name, long len, /* Our identifier */ int XPectContextType); /* which context do we expct to be called in? */ #define RegisterIterator(a, b, c, d, e, f, g, h) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f, g, h) +void GetTemplateTokenString(WCTemplateToken *Tokens, + int N, + const char **Value, + long *len); + + void SVPut(char *keyname, size_t keylen, int keytype, char *Data); #define svput(a, b, c) SVPut(a, sizeof(a) - 1, b, c) void SVPutLong(char *keyname, size_t keylen, long Data); -- 2.30.2