From: Wilfried Goesgens Date: Wed, 3 Jun 2015 06:18:13 +0000 (+0200) Subject: Add filter option to iterators X-Git-Tag: Release_902~156^2~1^2~4^2~3 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=01dab5c387efaa597377d1264e832474f30a754b Add filter option to iterators --- diff --git a/webcit/subst.c b/webcit/subst.c index 83540918a..ab4edce38 100644 --- a/webcit/subst.c +++ b/webcit/subst.c @@ -1984,6 +1984,7 @@ typedef struct _HashIterator { RetrieveHashlistFunc GetHash; HashDestructorFunc Destructor; SubTemplFunc DoSubTemplate; + FilterByParamFunc Filter; } HashIterator; void RegisterITERATOR(const char *Name, long len, @@ -1992,6 +1993,7 @@ void RegisterITERATOR(const char *Name, long len, RetrieveHashlistFunc GetHash, SubTemplFunc DoSubTempl, HashDestructorFunc Destructor, + FilterByParamFunc Filter, CtxType ContextType, CtxType XPectContextType, int Flags) @@ -2005,6 +2007,7 @@ void RegisterITERATOR(const char *Name, long len, It->GetHash = GetHash; It->DoSubTemplate = DoSubTempl; It->Destructor = Destructor; + It->Filter = Filter; It->ContextType = ContextType; It->XPectContextType = XPectContextType; It->Flags = Flags; @@ -2158,6 +2161,13 @@ void tmpl_iterate_subtmpl(StrBuf *Target, WCTemplputParams *TP) } while (GetNextHashPos(List, it, &Status.KeyLen, &Status.Key, &vContext)) { if ((Status.n >= StartAt) && (Status.n <= StopAt)) { + + if ((It->Filter != NULL) && + It->Filter(Status.Key, Status.KeyLen, vContext, Target, TP)) + { + continue; + } + if (DetectGroupChange && Status.n > 0) { Status.GroupChange = SortBy->GroupChange(vContext, vLastContext); } diff --git a/webcit/subst.h b/webcit/subst.h index bd6f8318d..d80c97f52 100644 --- a/webcit/subst.h +++ b/webcit/subst.h @@ -180,7 +180,7 @@ typedef struct _ConditionalStruct { typedef void (*SubTemplFunc)(StrBuf *TemplBuffer, WCTemplputParams *TP); typedef HashList *(*RetrieveHashlistFunc)(StrBuf *Target, WCTemplputParams *TP); typedef void (*HashDestructorFunc) (HashList **KillMe); - +typedef int (*FilterByParamFunc)(const char* key, long len, void *Context, StrBuf *Target, WCTemplputParams *TP); extern WCTemplputParams NoCtx; @@ -362,13 +362,15 @@ long GetTokenDefine(const char *Name, #define IT_NOFLAG 0 #define IT_FLAG_DETECT_GROUPCHANGE (1<<0) -#define RegisterIterator(a, b, c, d, e, f, g, h, i) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f, g, h, i) +#define RegisterIterator(a, b, c, d, e, f, g, h, i) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f, NULL, g, h, i) +#define RegisterFilteredIterator(a, b, c, d, e, f, g, h, i, j) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f, g, h, i, j) void RegisterITERATOR(const char *Name, long len, /* Our identifier */ - int AdditionalParams, /* doe we use more parameters? */ + int AdditionalParams, /* do we use more parameters? */ HashList *StaticList, /* pointer to webcit lifetime hashlists */ RetrieveHashlistFunc GetHash, /* else retrieve the hashlist by calling this function */ SubTemplFunc DoSubTempl, /* call this function on each iteration for svput & friends */ HashDestructorFunc Destructor, /* use this function to shut down the hash; NULL if its a reference */ + FilterByParamFunc Filter, /* use this function if you want to skip items */ CtxType ContextType, /* which context do we provide to the subtemplate? */ CtxType XPectContextType, /* which context do we expct to be called in? */ int Flags);