X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fsubst.h;h=75bbf3e33d7d4346f8f9b322f5238550e84820cd;hb=5d38a76f8f06640e3a3f097d584ac52336110f7c;hp=d1157d87ab90f1515e7097acd639fad108855f35;hpb=24fb51aa089fb0d81bfe455789e99aec52b2d413;p=citadel.git diff --git a/webcit/subst.h b/webcit/subst.h index d1157d87a..75bbf3e33 100644 --- a/webcit/subst.h +++ b/webcit/subst.h @@ -1,3 +1,6 @@ +/** + * @defgroup subst Template processing functions + */ extern HashList *Conditionals; extern HashList *GlobalNS; @@ -15,8 +18,10 @@ extern HashList *LocalTemplateCache; #define TYPE_GETTEXT 5 #define TYPE_BSTR 6 #define TYPE_SUBTEMPLATE 7 -#define MAXPARAM 20 +#define TYPE_INTDEFINE 8 +#define MAXPARAM 25 +#define IS_NUMBER(a) ((a == TYPE_LONG) || (a == TYPE_PREFINT) || (a == TYPE_INTDEFINE)) /* * \brief Values for wcs_type @@ -30,41 +35,31 @@ enum { WCS_LONG /* its an integer */ }; -#define CTX TP->Context -#define CCTX TP->ControlContext - #define CTX_NONE 0 -#define CTX_SITECFG 1 -#define CTX_SESSION 2 -#define CTX_INETCFG 3 -#define CTX_VNOTE 4 -#define CTX_WHO 5 -#define CTX_PREF 6 -#define CTX_NODECONF 7 -#define CTX_USERLIST 8 -#define CTX_MAILSUM 9 -#define CTX_MIME_ATACH 10 -#define CTX_FILELIST 11 -#define CTX_STRBUF 12 -#define CTX_LONGVECTOR 13 -#define CTX_ROOMS 14 -#define CTX_FLOORS 15 -#define CTX_ITERATE 16 -#define CTX_ICAL 17 -#define CTX_DAVNS 18 - -#define CTX_UNKNOWN 19 +typedef int CtxType; +typedef struct __CtxTypeStruct { + CtxType Type; + StrBuf *Name; +} CtxTypeStruct; + +CtxTypeStruct *GetContextType(CtxType Type); +void RegisterContextType(const char *name, long len, CtxType *TheCtx); +#define RegisterCTX(a) RegisterContextType(#a, sizeof(#a) - 1, &a) + +extern CtxType CTX_STRBUF; +extern CtxType CTX_STRBUFARR; +extern CtxType CTX_LONGVECTOR; /** + * @ingroup subst * ContextFilter resembles our RTTI information. With this structure * we can make shure a tmplput function can live with the environment * we call it in. * if not, we will log/print an error and refuse to call it. */ typedef struct _contexts { - int ContextType; /* do we require a User Context ? */ - int ControlContextType; /* are we inside of a control structure? */ + CtxType ContextType; /* do we require a User Context ? */ int nMinArgs; /* How many arguments do we need at least? */ int nMaxArgs; /* up to how many arguments can we handle? */ } ContextFilter; @@ -83,12 +78,21 @@ typedef int (*WCPreevalFunc)(WCTemplateToken *Token); /* make a template token a lookup key: */ #define TKEY(a) TP->Tokens->Params[a]->Start, TP->Tokens->Params[a]->len +void *GetContextPayload(WCTemplputParams *TP, CtxType ContextType); +#define CTX(a) GetContextPayload(TP, a) + /** + * @ingroup subst * this is the signature of a conditional function * Note: Target is just passed in for error messages; don't write onto it in regular cases. */ typedef int (*WCConditionalFunc)(StrBuf *Target, WCTemplputParams *TP); +typedef enum _eBitMask { + eNO = 0, + eOR, + eAND +}eBitMask; typedef struct _TemplateParam { /* are we a string or a number? */ @@ -98,10 +102,12 @@ typedef struct _TemplateParam { long len; /* if we're a number: */ long lvalue; + eBitMask MaskBy; } TemplateParam; /** + * @ingroup subst * Representation of a token; everything thats inbetween */ struct WCTemplateToken { @@ -143,9 +149,9 @@ struct WCTemplateToken { struct WCTemplputParams { ContextFilter Filter; void *Context; - void *ControlContext; int nArgs; WCTemplateToken *Tokens; + WCTemplputParams *Sub, *Super; }; @@ -171,7 +177,8 @@ extern WCTemplputParams NoCtx; #define ERR_PARM1 1 #define ERR_PARM2 2 /** - * @Brief log an error while evaluating a token; print it to the actual template + * @ingroup subst + * @brief log an error while evaluating a token; print it to the actual template * @param Target your Target Buffer to print the error message next to the log * @param Type What sort of thing are we talking about? Tokens? Conditionals? * @param TP grab our set of default information here @@ -185,7 +192,8 @@ void LogTemplateError (StrBuf *Target, /** - * @Brief log an error while in global context; print it to Wildfire / Target + * @ingroup subst + * @brief log an error while in global context; print it to Wildfire / Target * @param Target your Target Buffer to print the error message next to the log * @param Type What sort of thing are we talking about? Tokens? Conditionals? * @param Format for the custom error message @@ -193,7 +201,8 @@ void LogTemplateError (StrBuf *Target, void LogError (StrBuf *Target, const char *Type, const char *Format, ...); /** - * @Brief get the actual value of a token parameter + * @ingroup subst + * @brief get the actual value of a token parameter * in your tmplputs or conditionals use this function to access parameters that can also be * retrieved from dynamic facilities: * _ -> Gettext; retrieve this token from the i18n facilities @@ -210,11 +219,21 @@ void GetTemplateTokenString(StrBuf *Target, int N, const char **Value, long *len); +/** + * @ingroup subst + * @return whether @ref GetTemplateTokenString would be able to give you a string + */ +int HaveTemplateTokenString(StrBuf *Target, + WCTemplputParams *TP, + int N, + const char **Value, + long *len); /** - * @Brief get the actual integer value of a token parameter + * @ingroup subst + * @brief get the actual integer value of a token parameter * in your tmplputs or conditionals use this function to access parameters that can also be * retrieved from dynamic facilities: * _ -> Gettext; retrieve this token from the i18n facilities @@ -231,7 +250,7 @@ long GetTemplateTokenNumber(StrBuf *Target, int N, long dflt); /** - * @Brief put a token value into the template + * @brief put a token value into the template * use this function to append your strings into a Template. * it can escape your string according to the token at FormattypeIndex: * H: de-QP and utf8-ify @@ -251,7 +270,8 @@ void StrBufAppendTemplate(StrBuf *Target, #define RegisterNamespace(a, b, c, d, e, f) RegisterNS(a, sizeof(a)-1, b, c, d, e, f) /** - * @Brief register a template token handler + * @ingroup subst + * @brief register a template token handler * call this function in your InitModule_MODULENAME which will be called at the server start * @param nMinArgs how much parameters does your token require at least? * @param nMaxArgs how many parameters does your token accept? @@ -268,7 +288,8 @@ void RegisterNS(const char *NSName, long len, int ContextRequired); /** - * @Brief register a conditional token handler + * @ingroup subst + * @brief register a conditional token handler * call this function in your InitModule_MODULENAME which will be called at the server start * conditionals can be ? or ! with a pair or % similar to an implicit if * @param Name whats the name of your conditional? should start with COND: @@ -282,6 +303,33 @@ void RegisterConditional(const char *Name, long len, WCConditionalFunc CondF, int ContextRequired); +/** + * @ingroup subst + * @brief register a string that will represent a long value + * this will allow to resolve to Value; that way + * plain strings can be used an lexed in templates without having the + * lookup overhead at runtime. + * @param Name The name of the define + * @param len length of Name + * @param Value the value to associate with Name + */ +void RegisterTokenParamDefine(const char *Name, long len, + long Value); +/** + * teh r0x0r! forward your favourite define from C to the templates with one easy call! + */ +#define REGISTERTokenParamDefine(a) RegisterTokenParamDefine(#a, sizeof(#a) - 1, a); + +/** + * @ingroup subst + * @brief retrieve the long value of a registered string define + * @param Name The name of the define + * @param len length of Name + * @param Value the value to return if not found + */ +long GetTokenDefine(const char *Name, + long len, + long DefValue); #define IT_NOFLAG 0 @@ -293,12 +341,20 @@ void RegisterITERATOR(const char *Name, long len, /* Our identifier */ 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 */ - int ContextType, /* which context do we provide to the subtemplate? */ - int XPectContextType, /* which context do we expct to be called in? */ + 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 UnStackContext(WCTemplputParams *Sub); @@ -311,37 +367,14 @@ void RegisterSortFunc(const char *name, long len, CompareFunc Forward, CompareFunc Reverse, CompareFunc GroupChange, - long ContextType); - - - + CtxType ContextType); void dbg_print_longvector(long *LongVector); - - - - -#define do_template(a, b) DoTemplate(a, sizeof(a) -1, NULL, &NoCtx); +#define do_template(a) DoTemplate(a, sizeof(a) -1, NULL, &NoCtx) const StrBuf *DoTemplate(const char *templatename, long len, StrBuf *Target, WCTemplputParams *TP); void url_do_template(void); - - - int CompareSubstToToken(TemplateParam *ParamToCompare, TemplateParam *ParamToLookup); int CompareSubstToStrBuf(StrBuf *Compare, TemplateParam *ParamToLookup); - -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); -#define svputlong(a, b) SVPutLong(a, sizeof(a) - 1, b) -void svprintf(char *keyname, size_t keylen, int keytype, const char *format,...) __attribute__((__format__(__printf__,4,5))); -void SVPRINTF(char *keyname, int keytype, const char *format,...) __attribute__((__format__(__printf__,3,4))); -void SVCALLBACK(char *keyname, WCHandlerFunc fcn_ptr); -void SVCallback(char *keyname, size_t keylen, WCHandlerFunc fcn_ptr); -#define svcallback(a, b) SVCallback(a, sizeof(a) - 1, b) - -void SVPUTBuf(const char *keyname, int keylen, const StrBuf *Buf, int ref); -#define SVPutBuf(a, b, c); SVPUTBuf(a, sizeof(a) - 1, b, c)