2 extern HashList *Conditionals;
3 extern HashList *GlobalNS;
4 extern HashList *Iterators;
5 extern HashList *WirelessTemplateCache;
6 extern HashList *WirelessLocalTemplateCache;
7 extern HashList *TemplateCache;
8 extern HashList *LocalTemplateCache;
13 #define TYPE_PREFSTR 3
14 #define TYPE_PREFINT 4
15 #define TYPE_GETTEXT 5
17 #define TYPE_SUBTEMPLATE 7
18 #define TYPE_INTDEFINE 8
21 #define IS_NUMBER(a) ((a == TYPE_LONG) || (a == TYPE_PREFINT) || (a == TYPE_INTDEFINE))
24 * \brief Values for wcs_type
27 WCS_STRING, /* its a string */
28 WCS_FUNCTION, /* its a function callback */
29 WCS_SERVCMD, /* its a command to send to the citadel server */
30 WCS_STRBUF, /* its a strbuf we own */
31 WCS_STRBUF_REF, /* its a strbuf we mustn't free */
32 WCS_LONG /* its an integer */
35 #define CTX TP->Context
36 #define CCTX TP->ControlContext
45 #define CTX_NODECONF 7
46 #define CTX_USERLIST 8
48 #define CTX_MIME_ATACH 10
49 #define CTX_FILELIST 11
51 #define CTX_STRBUFARR 13
52 #define CTX_LONGVECTOR 14
55 #define CTX_ITERATE 17
61 #define CTX_UNKNOWN 22
65 * ContextFilter resembles our RTTI information. With this structure
66 * we can make shure a tmplput function can live with the environment
68 * if not, we will log/print an error and refuse to call it.
70 typedef struct _contexts {
71 int ContextType; /* do we require a User Context ? */
72 int ControlContextType; /* are we inside of a control structure? */
73 int nMinArgs; /* How many arguments do we need at least? */
74 int nMaxArgs; /* up to how many arguments can we handle? */
78 /* Forward declarations... */
79 typedef struct WCTemplateToken WCTemplateToken;
80 typedef struct WCTemplputParams WCTemplputParams;
82 /* this is the signature of a tmplput function */
83 typedef void (*WCHandlerFunc)(StrBuf *Target, WCTemplputParams *TP);
85 /* if you want to pre-evaluate parts of your token, or do additional syntax, use this. */
86 typedef int (*WCPreevalFunc)(WCTemplateToken *Token);
88 /* make a template token a lookup key: */
89 #define TKEY(a) TP->Tokens->Params[a]->Start, TP->Tokens->Params[a]->len
92 * this is the signature of a conditional function
93 * Note: Target is just passed in for error messages; don't write onto it in regular cases.
95 typedef int (*WCConditionalFunc)(StrBuf *Target, WCTemplputParams *TP);
97 typedef enum _eBitMask {
103 typedef struct _TemplateParam {
104 /* are we a string or a number? */
109 /* if we're a number: */
116 * Representation of a token; everything thats inbetween <? and >
118 struct WCTemplateToken {
119 /* Reference to the filename we're in to print error messages; not to be freed */
120 const StrBuf *FileName;
121 /* Raw copy of our original token; for error printing */
123 /* Which line did the template parser pick us up in? For error printing */
126 /* our position in the template cache buffer */
127 const char *pTokenStart;
128 /* our token length */
132 const char *pTokenEnd;
133 /* just our token name: */
137 /* stuff the pre-evaluater finds out: */
139 /* pointer to our runntime evaluator; so we can cache this and save hash-lookups */
143 /* if we have parameters here we go: */
144 /* do we have parameters or not? */
146 /* How many of them? */
149 TemplateParam *Params[MAXPARAM];
154 struct WCTemplputParams {
155 ContextFilter Filter;
157 void *ControlContext;
159 WCTemplateToken *Tokens;
164 typedef struct _ConditionalStruct {
165 ContextFilter Filter;
166 const char *PlainName;
167 WCConditionalFunc CondF;
171 typedef void (*SubTemplFunc)(StrBuf *TemplBuffer, WCTemplputParams *TP);
172 typedef HashList *(*RetrieveHashlistFunc)(StrBuf *Target, WCTemplputParams *TP);
173 typedef void (*HashDestructorFunc) (HashList **KillMe);
176 extern WCTemplputParams NoCtx;
178 #define HAVE_PARAM(a) (TP->Tokens->nParameters > a)
185 * @Brief log an error while evaluating a token; print it to the actual template
186 * @param Target your Target Buffer to print the error message next to the log
187 * @param Type What sort of thing are we talking about? Tokens? Conditionals?
188 * @param TP grab our set of default information here
189 * @param Format for the custom error message
191 void LogTemplateError (StrBuf *Target,
194 WCTemplputParams *TP,
195 const char *Format, ...)__attribute__((__format__(__printf__,5,6)));
199 * @Brief log an error while in global context; print it to Wildfire / Target
200 * @param Target your Target Buffer to print the error message next to the log
201 * @param Type What sort of thing are we talking about? Tokens? Conditionals?
202 * @param Format for the custom error message
204 void LogError (StrBuf *Target, const char *Type, const char *Format, ...);
207 * @Brief get the actual value of a token parameter
208 * in your tmplputs or conditionals use this function to access parameters that can also be
209 * retrieved from dynamic facilities:
210 * _ -> Gettext; retrieve this token from the i18n facilities
211 * : -> lookup a setting of that name
212 * B -> bstr; an URL-Parameter
213 * = -> subtemplate; parse a template by this name, and treat its content as this tokens value
215 * @param N which token do you want to lookup?
216 * @param Value reference to the string of the token; don't free me.
217 * @param len the length of Value
219 void GetTemplateTokenString(StrBuf *Target,
220 WCTemplputParams *TP,
225 * @return whether @ref GetTemplateTokenString would be able to give you a string
227 int HaveTemplateTokenString(StrBuf *Target,
228 WCTemplputParams *TP,
236 * @Brief get the actual integer value of a token parameter
237 * in your tmplputs or conditionals use this function to access parameters that can also be
238 * retrieved from dynamic facilities:
239 * _ -> Gettext; retrieve this token from the i18n facilities
240 * : -> lookup a setting of that name
241 * B -> bstr; an URL-Parameter
242 * = -> subtemplate; parse a template by this name, and treat its content as this tokens value
244 * @param N which token do you want to lookup?
245 * @param dflt default value to be retrieved if not found in preferences
246 * \returns the long value
248 long GetTemplateTokenNumber(StrBuf *Target,
249 WCTemplputParams *TP,
253 * @Brief put a token value into the template
254 * use this function to append your strings into a Template.
255 * it can escape your string according to the token at FormattypeIndex:
256 * H: de-QP and utf8-ify
257 * X: escapize for HTML
259 * @param Target the destination buffer
260 * @param TP the template token information
261 * @param Source string to append
262 * @param FormatTypeIndex which parameter contains the escaping functionality?
263 * if this token doesn't have as much parameters, plain append is done.
265 void StrBufAppendTemplate(StrBuf *Target,
266 WCTemplputParams *TP,
267 const StrBuf *Source,
268 int FormatTypeIndex);
271 #define RegisterNamespace(a, b, c, d, e, f) RegisterNS(a, sizeof(a)-1, b, c, d, e, f)
273 * @Brief register a template token handler
274 * call this function in your InitModule_MODULENAME which will be called at the server start
275 * @param nMinArgs how much parameters does your token require at least?
276 * @param nMaxArgs how many parameters does your token accept?
277 * @param HandlerFunc your callback when the template is rendered and your token is there
278 * @param PreEvalFunc is called when the template is parsed; you can do additional
279 * syntax checks here or pre-evaluate stuff for better performance
280 * @param ContextRequired if your token requires a specific context, else say CTX_NONE here.
282 void RegisterNS(const char *NSName, long len,
285 WCHandlerFunc HandlerFunc,
286 WCPreevalFunc PreEvalFunc,
287 int ContextRequired);
290 * @Brief register a conditional token <pair> handler
291 * call this function in your InitModule_MODULENAME which will be called at the server start
292 * conditionals can be ? or ! with a pair or % similar to an implicit if
293 * @param Name whats the name of your conditional? should start with COND:
294 * @param len the token length so we don't have to measure it.
295 * @param nParams how many parameters does your conditional need on top of the default conditional parameters
296 * @param CondF your Callback to be called when the template is evaluated at runtime; return 0 or 1 to us please.
297 * @param ContextRequired if your token requires a specific context, else say CTX_NONE here.
299 void RegisterConditional(const char *Name, long len,
301 WCConditionalFunc CondF,
302 int ContextRequired);
305 * @brief register a string that will represent a long value
306 * this will allow to resolve <?...(#"Name")> to Value; that way
307 * plain strings can be used an lexed in templates without having the
308 * lookup overhead at runtime.
309 * @param Name The name of the define
310 * @param len length of Name
311 * @param Value the value to associate with Name
313 void RegisterTokenParamDefine(const char *Name, long len,
316 * teh r0x0r! forward your favourite define from C to the templates with one easy call!
318 #define REGISTERTokenParamDefine(a) RegisterTokenParamDefine(#a, sizeof(#a) - 1, a);
321 * @brief retrieve the long value of a registered string define
322 * @param Name The name of the define
323 * @param len length of Name
324 * @param Value the value to return if not found
326 long GetTokenDefine(const char *Name,
332 #define IT_FLAG_DETECT_GROUPCHANGE (1<<0)
333 #define RegisterIterator(a, b, c, d, e, f, g, h, i) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f, g, h, i)
334 void RegisterITERATOR(const char *Name, long len, /* Our identifier */
335 int AdditionalParams, /* doe we use more parameters? */
336 HashList *StaticList, /* pointer to webcit lifetime hashlists */
337 RetrieveHashlistFunc GetHash, /* else retrieve the hashlist by calling this function */
338 SubTemplFunc DoSubTempl, /* call this function on each iteration for svput & friends */
339 HashDestructorFunc Destructor, /* use this function to shut down the hash; NULL if its a reference */
340 int ContextType, /* which context do we provide to the subtemplate? */
341 int XPectContextType, /* which context do we expct to be called in? */
349 CompareFunc RetrieveSort(WCTemplputParams *TP,
350 const char *OtherPrefix, long OtherPrefixLen,
351 const char *Default, long ldefault,
352 long DefaultDirection);
353 void RegisterSortFunc(const char *name, long len,
354 const char *prepend, long preplen,
357 CompareFunc GroupChange,
360 void dbg_print_longvector(long *LongVector);
362 #define do_template(a) DoTemplate(a, sizeof(a) -1, NULL, &NoCtx)
363 const StrBuf *DoTemplate(const char *templatename, long len, StrBuf *Target, WCTemplputParams *TP);
364 void url_do_template(void);
367 int CompareSubstToToken(TemplateParam *ParamToCompare, TemplateParam *ParamToLookup);
368 int CompareSubstToStrBuf(StrBuf *Compare, TemplateParam *ParamToLookup);