From c5d32a4b382cc366776eb0ec06c93ab15245c6da Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Thu, 6 Nov 2008 21:12:25 +0000 Subject: [PATCH] * put filename reference into token, so we can put in errormessages where we wouldn't have it otherwise. * split horizon context in iterators; expect one context, provide another into the subiterators * first work on mime iterators --- webcit/inetconf.c | 2 +- webcit/messages.c | 29 +++++++++++++++++++++++++--- webcit/netconf.c | 2 +- webcit/preferences.c | 2 +- webcit/subst.c | 45 +++++++++++++++++++++++++++++++++++++++----- webcit/useredit.c | 2 +- webcit/webcit.h | 8 +++++--- webcit/who.c | 2 +- 8 files changed, 76 insertions(+), 16 deletions(-) diff --git a/webcit/inetconf.c b/webcit/inetconf.c index 126e4afae..c025792b0 100644 --- a/webcit/inetconf.c +++ b/webcit/inetconf.c @@ -417,6 +417,6 @@ InitModule_INETCONF { WebcitAddUrlHandler(HKEY("display_inetconf"), display_inetconf, 0); WebcitAddUrlHandler(HKEY("save_inetconf"), new_save_inetconf, AJAX); - RegisterIterator("SERVCFG:INET", 1, NULL, GetInetConfHash, InetCfgSubst, NULL, CTX_INETCFG); + RegisterIterator("SERVCFG:INET", 1, NULL, GetInetConfHash, InetCfgSubst, NULL, CTX_INETCFG, CTX_NONE); RegisterNamespace("SERVCFG:FLUSHINETCFG",0, 0, DeleteInetConfHash, CTX_NONE); } diff --git a/webcit/messages.c b/webcit/messages.c index 8480ce618..d05d988ef 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -811,9 +811,25 @@ void render_MAIL_UNKNOWN(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *Foun -HashList *iterate_get_mime(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) +HashList *iterate_get_mime_All(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) { - return NULL; + message_summary *Msg = (message_summary*) Context; + return Msg->AllAttach; +} +HashList *iterate_get_mime_Submessages(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) +{ + message_summary *Msg = (message_summary*) Context; + return Msg->Submessages; +} +HashList *iterate_get_mime_AttachLinks(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) +{ + message_summary *Msg = (message_summary*) Context; + return Msg->AttachLinks; +} +HashList *iterate_get_mime_Attachments(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) +{ + message_summary *Msg = (message_summary*) Context; + return Msg->AllAttach; } @@ -3896,7 +3912,14 @@ InitModule_MSG RegisterConditional(HKEY("COND:MAIL:SUMM:OTHERNODE"), 0, Conditional_MAIL_SUMM_OTHERNODE, CTX_MAILSUM); - RegisterIterator("MAIL:MIME:ATTACH", 0, NULL, iterate_get_mime, tmplput_MIME_ATTACH, NULL, CTX_MAILSUM); + RegisterIterator("MAIL:MIME:ATTACH", 0, NULL, iterate_get_mime_All, + tmplput_MIME_ATTACH, NULL, CTX_MIME_ATACH, CTX_MAILSUM); + RegisterIterator("MAIL:MIME:ATTACH:SUBMESSAGES", 0, NULL, iterate_get_mime_Submessages, + tmplput_MIME_ATTACH, NULL, CTX_MIME_ATACH, CTX_MAILSUM); + RegisterIterator("MAIL:MIME:ATTACH:LINKS", 0, NULL, iterate_get_mime_AttachLinks, + tmplput_MIME_ATTACH, NULL, CTX_MIME_ATACH, CTX_MAILSUM); + RegisterIterator("MAIL:MIME:ATTACH:ATT", 0, NULL, iterate_get_mime_Attachments, + tmplput_MIME_ATTACH, NULL, CTX_MIME_ATACH, CTX_MAILSUM); RegisterMimeRenderer(HKEY("text/x-citadel-variformat"), render_MAIL_variformat); RegisterMimeRenderer(HKEY("text/plain"), render_MAIL_text_plain); diff --git a/webcit/netconf.c b/webcit/netconf.c index dcdfe4316..671954046 100644 --- a/webcit/netconf.c +++ b/webcit/netconf.c @@ -540,6 +540,6 @@ InitModule_NETCONF 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); + RegisterIterator("NODECONFIG", 0, NULL, load_netconf, NodeCfgSubst, DeleteHash, CTX_NODECONF, CTX_NONE); } /*@}*/ diff --git a/webcit/preferences.c b/webcit/preferences.c index 8887f6fe5..f6e4bab14 100644 --- a/webcit/preferences.c +++ b/webcit/preferences.c @@ -737,7 +737,7 @@ InitModule_PREFERENCES RegisterNamespace("PREF:VALUE", 1, 1, tmplput_CFG_Value, CTX_SESSION); RegisterNamespace("PREF:DESCR", 1, 1, tmplput_CFG_Descr, CTX_SESSION); - RegisterIterator("PREF:ZONE", 0, ZoneHash, NULL, CfgZoneTempl, NULL, CTX_PREF); + RegisterIterator("PREF:ZONE", 0, ZoneHash, NULL, CfgZoneTempl, NULL, CTX_PREF, CTX_NONE); RegisterConditional(HKEY("COND:PREF"), 4, ConditionalPreference, CTX_NONE); } diff --git a/webcit/subst.c b/webcit/subst.c index cca998a40..c764ce652 100644 --- a/webcit/subst.c +++ b/webcit/subst.c @@ -696,6 +696,7 @@ WCTemplateToken *NewTemplateSubstitute(StrBuf *Buf, TemplateParam *Param; WCTemplateToken *NewToken = (WCTemplateToken*)malloc(sizeof(WCTemplateToken)); + NewToken->FileName = pTmpl->FileName; /* to print meaningfull log messages... */ NewToken->Flags = 0; NewToken->Line = Line + 1; NewToken->pTokenStart = pTmplStart; @@ -1312,6 +1313,7 @@ typedef struct _HashIterator { HashList *StaticList; int AdditionalParams; int ContextType; + int XPectContextType; RetrieveHashlistFunc GetHash; HashDestructorFunc Destructor; SubTemplFunc DoSubTemplate; @@ -1333,16 +1335,18 @@ void tmpl_iterate_subtmpl(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, vo Tokens->Params[0]->Start, Tokens->Params[0]->len, &vIt)) { - lprintf(1, "unknown Iterator [%s] (in line %ld); " + lprintf(1, "unknown Iterator [%s] (in '%s' line %ld); " " [%s]\n", Tokens->Params[0]->Start, + ChrPtr(Tokens->FileName), Tokens->Line, ChrPtr(Tokens->FlatToken)); StrBufAppendPrintf( Target, - "
\nunknown Iterator [%s] (in line %ld); \n"
+			"
\nunknown Iterator [%s] (in '%s' line %ld); \n"
 			" [%s]\n
", Tokens->Params[0]->Start, + ChrPtr(Tokens->FileName), Tokens->Line, ChrPtr(Tokens->FlatToken)); return; @@ -1351,23 +1355,52 @@ void tmpl_iterate_subtmpl(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, vo It = (HashIterator*) vIt; if (Tokens->nParameters < It->AdditionalParams + 2) { - lprintf(1, "Iterator [%s] (in line %ld); " + lprintf(1, "Iterator [%s] (in '%s' line %ld); " "doesn't work with %ld params [%s]\n", Tokens->Params[0]->Start, + ChrPtr(Tokens->FileName), Tokens->Line, Tokens->nParameters, ChrPtr(Tokens->FlatToken)); StrBufAppendPrintf( Target, - "
Iterator [%s] \n(in line %ld);\n"
+			"
Iterator [%s] \n(in '%s' line %ld);\n"
 			"doesn't work with %ld params \n[%s]\n
", Tokens->Params[0]->Start, + ChrPtr(Tokens->FileName), Tokens->Line, Tokens->nParameters, ChrPtr(Tokens->FlatToken)); return; } + if ((It->XPectContextType != CTX_NONE) && + (It->XPectContextType != ContextType)) { + lprintf(1, "Iterator [%s] (in '%s' line %ld); " + "requires context of type %ld, have %ld [%s]\n", + Tokens->pName, + ChrPtr(Tokens->FileName), + Tokens->Line, + It->XPectContextType, + ContextType, + ChrPtr(Tokens->FlatToken)); + StrBufAppendPrintf( + Target, + "
\nIterator [%s] (in '%s' line %ld);"
+			" requires context of type %ld, have %ld!\n[%s]\n
\n", + Tokens->pName, + ChrPtr(Tokens->FileName), + Tokens->Line, + It->XPectContextType, + ContextType, + ChrPtr(Tokens->FlatToken)); + return ; + + } + + + + if (It->StaticList == NULL) List = It->GetHash(Target, nArgs, Tokens, Context, ContextType); else @@ -1443,7 +1476,8 @@ void RegisterITERATOR(const char *Name, long len, RetrieveHashlistFunc GetHash, SubTemplFunc DoSubTempl, HashDestructorFunc Destructor, - int ContextType) + int ContextType, + int XPectContextType) { HashIterator *It = (HashIterator*)malloc(sizeof(HashIterator)); It->StaticList = StaticList; @@ -1452,6 +1486,7 @@ void RegisterITERATOR(const char *Name, long len, It->DoSubTemplate = DoSubTempl; It->Destructor = Destructor; It->ContextType = ContextType; + It->XPectContextType = XPectContextType; Put(Iterators, Name, len, It, NULL); } diff --git a/webcit/useredit.c b/webcit/useredit.c index 77c98e667..97e59de1d 100644 --- a/webcit/useredit.c +++ b/webcit/useredit.c @@ -950,5 +950,5 @@ InitModule_USEREDIT RegisterConditional(HKEY("COND:USERACCESS"), 0, ConditionalUserAccess, CTX_USERLIST); RegisterConditional(HKEY("COND:USERLIST:FLAG:USE_INTERNET"), 0, ConditionalFlagINetEmail, CTX_USERLIST); - RegisterIterator("USERLIST", 0, NULL, iterate_load_userlist, NULL, DeleteHash, CTX_USERLIST); + RegisterIterator("USERLIST", 0, NULL, iterate_load_userlist, NULL, DeleteHash, CTX_USERLIST, CTX_NONE); } diff --git a/webcit/webcit.h b/webcit/webcit.h index 59a361e8e..0848579da 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -269,6 +269,7 @@ typedef struct _TemplateParam { } TemplateParam; typedef struct _TemplateToken { + const StrBuf *FileName; /* Reference to print error messages; not to be freed */ StrBuf *FlatToken; long Line; const char *pTokenStart; @@ -311,7 +312,7 @@ typedef struct _wcsubst { #define CTX_NODECONF 7 #define CTX_USERLIST 8 #define CTX_MAILSUM 9 - +#define CTX_MIME_ATACH 10 void RegisterNS(const char *NSName, long len, int nMinArgs, @@ -342,8 +343,9 @@ void RegisterITERATOR(const char *Name, long len, RetrieveHashlistFunc GetHash, SubTemplFunc DoSubTempl, HashDestructorFunc Destructor, - int ContextType); -#define RegisterIterator(a, b, c, d, e, f, g) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f, g) + int ContextType, + int XPectContextType); +#define RegisterIterator(a, b, c, d, e, f, g, h) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f, g, h) void SVPut(char *keyname, size_t keylen, int keytype, char *Data); #define svput(a, b, c) SVPut(a, sizeof(a) - 1, b, c) diff --git a/webcit/who.c b/webcit/who.c index 5b011690d..bd863e7ee 100644 --- a/webcit/who.c +++ b/webcit/who.c @@ -499,5 +499,5 @@ InitModule_WHO WebcitAddUrlHandler(HKEY("terminate_session"), _terminate_session, 0); WebcitAddUrlHandler(HKEY("edit_me"), edit_me, 0); - RegisterIterator("WHOLIST", 0, NULL, GetWholistHash, WholistSubst, DeleteWholistHash, CTX_WHO); + RegisterIterator("WHOLIST", 0, NULL, GetWholistHash, WholistSubst, DeleteWholistHash, CTX_WHO, CTX_NONE); } -- 2.30.2