X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fsubst.h;h=063f46d211e0883fe2be28a773943f4fd83b661a;hb=HEAD;hp=86b76d69070cb39638c9da72b9ba6506b200587f;hpb=82f8cebefd325c7eb8b98c6025bd43633fa9cd90;p=citadel.git diff --git a/webcit/subst.h b/webcit/subst.h index 86b76d690..063f46d21 100644 --- a/webcit/subst.h +++ b/webcit/subst.h @@ -1,5 +1,15 @@ -/** - * @defgroup subst Template processing functions +/* + * Copyright (c) 1996-2013 by the citadel.org team + * + * This program is open source software. You can redistribute it and/or + * modify it under the terms of the GNU General Public License, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * subst template processing functions */ extern HashList *Conditionals; @@ -153,6 +163,8 @@ struct WCTemplputParams { int nArgs; WCTemplateToken *Tokens; WCTemplputParams *Sub, *Super; + WCConditionalFunc ExitCtx; + long ExitCTXID; }; @@ -161,13 +173,14 @@ typedef struct _ConditionalStruct { ContextFilter Filter; const char *PlainName; WCConditionalFunc CondF; + WCConditionalFunc CondExitCtx; } 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; @@ -302,12 +315,21 @@ void RegisterNS(const char *NSName, long len, * @param len the token length so we don't have to measure it. * @param nParams how many parameters does your conditional need on top of the default conditional parameters * @param CondF your Callback to be called when the template is evaluated at runtime; return 0 or 1 to us please. + * @param ExitCtxCond if non-NULL, will be called after the area of the conditional is left behind. * @param ContextRequired if your token requires a specific context, else say CTX_NONE here. */ -void RegisterConditional(const char *Name, long len, - int nParams, - WCConditionalFunc CondF, - int ContextRequired); +void RegisterContextConditional(const char *Name, long len, + int nParams, + WCConditionalFunc CondF, + WCConditionalFunc ExitCtxCond, + int ContextRequired); + +#define RegisterCtxConditional(Name, nParams, CondF, ExitCtxCond, ContextRequired) \ + RegisterContextConditional(Name, sizeof(Name) -1, nParams, CondF, ExitCtxCond, ContextRequired) + +#define RegisterConditional(Name, nParams, CondF, ContextRequired) \ + RegisterContextConditional(Name, sizeof(Name) -1, nParams, CondF, NULL, ContextRequired) + /** * @ingroup subst @@ -340,25 +362,34 @@ 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 IT_ADDT_PARAM(n) 5 + n /* If you have AdditionalParams, use this macro to fetch them. */ +#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); -void StackContext(WCTemplputParams *Super, - WCTemplputParams *Sub, - void *Context, - CtxType ContextType, - int nArgs, - WCTemplateToken *Tokens); +void StackDynamicContext(WCTemplputParams *Super, + WCTemplputParams *Sub, + void *Context, + CtxType ContextType, + int nArgs, + WCTemplateToken *Tokens, + WCConditionalFunc ExitCtx, + long ExitCTXID); + +#define StackContext(Super, Sub, Context, ContextType, nArgs, Tokens) \ + StackDynamicContext(Super, Sub, Context, ContextType, nArgs, Tokens, NULL, 0) + void UnStackContext(WCTemplputParams *Sub);