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
60 #define CTX_SIEVELIST 22
61 #define CTX_SIEVESCRIPT 23
63 #define CTX_UNKNOWN 24
67 * ContextFilter resembles our RTTI information. With this structure
68 * we can make shure a tmplput function can live with the environment
70 * if not, we will log/print an error and refuse to call it.
72 typedef struct _contexts {
73 int ContextType; /* do we require a User Context ? */
74 int ControlContextType; /* are we inside of a control structure? */
75 int nMinArgs; /* How many arguments do we need at least? */
76 int nMaxArgs; /* up to how many arguments can we handle? */
80 /* Forward declarations... */
81 typedef struct WCTemplateToken WCTemplateToken;
82 typedef struct WCTemplputParams WCTemplputParams;
84 /* this is the signature of a tmplput function */
85 typedef void (*WCHandlerFunc)(StrBuf *Target, WCTemplputParams *TP);
87 /* if you want to pre-evaluate parts of your token, or do additional syntax, use this. */
88 typedef int (*WCPreevalFunc)(WCTemplateToken *Token);
90 /* make a template token a lookup key: */
91 #define TKEY(a) TP->Tokens->Params[a]->Start, TP->Tokens->Params[a]->len
94 * this is the signature of a conditional function
95 * Note: Target is just passed in for error messages; don't write onto it in regular cases.
97 typedef int (*WCConditionalFunc)(StrBuf *Target, WCTemplputParams *TP);
99 typedef enum _eBitMask {
105 typedef struct _TemplateParam {
106 /* are we a string or a number? */
111 /* if we're a number: */
118 * Representation of a token; everything thats inbetween <? and >
120 struct WCTemplateToken {
121 /* Reference to the filename we're in to print error messages; not to be freed */
122 const StrBuf *FileName;
123 /* Raw copy of our original token; for error printing */
125 /* Which line did the template parser pick us up in? For error printing */
128 /* our position in the template cache buffer */
129 const char *pTokenStart;
130 /* our token length */
134 const char *pTokenEnd;
135 /* just our token name: */
139 /* stuff the pre-evaluater finds out: */
141 /* pointer to our runntime evaluator; so we can cache this and save hash-lookups */
145 /* if we have parameters here we go: */
146 /* do we have parameters or not? */
148 /* How many of them? */
151 TemplateParam *Params[MAXPARAM];
156 struct WCTemplputParams {
157 ContextFilter Filter;
159 void *ControlContext;
161 WCTemplateToken *Tokens;
166 typedef struct _ConditionalStruct {
167 ContextFilter Filter;
168 const char *PlainName;
169 WCConditionalFunc CondF;
173 typedef void (*SubTemplFunc)(StrBuf *TemplBuffer, WCTemplputParams *TP);
174 typedef HashList *(*RetrieveHashlistFunc)(StrBuf *Target, WCTemplputParams *TP);
175 typedef void (*HashDestructorFunc) (HashList **KillMe);
178 extern WCTemplputParams NoCtx;
180 #define HAVE_PARAM(a) (TP->Tokens->nParameters > a)
187 * @Brief log an error while evaluating a token; print it to the actual template
188 * @param Target your Target Buffer to print the error message next to the log
189 * @param Type What sort of thing are we talking about? Tokens? Conditionals?
190 * @param TP grab our set of default information here
191 * @param Format for the custom error message
193 void LogTemplateError (StrBuf *Target,
196 WCTemplputParams *TP,
197 const char *Format, ...)__attribute__((__format__(__printf__,5,6)));
201 * @Brief log an error while in global context; print it to Wildfire / Target
202 * @param Target your Target Buffer to print the error message next to the log
203 * @param Type What sort of thing are we talking about? Tokens? Conditionals?
204 * @param Format for the custom error message
206 void LogError (StrBuf *Target, const char *Type, const char *Format, ...);
209 * @Brief get the actual value of a token parameter
210 * in your tmplputs or conditionals use this function to access parameters that can also be
211 * retrieved from dynamic facilities:
212 * _ -> Gettext; retrieve this token from the i18n facilities
213 * : -> lookup a setting of that name
214 * B -> bstr; an URL-Parameter
215 * = -> subtemplate; parse a template by this name, and treat its content as this tokens value
217 * @param N which token do you want to lookup?
218 * @param Value reference to the string of the token; don't free me.
219 * @param len the length of Value
221 void GetTemplateTokenString(StrBuf *Target,
222 WCTemplputParams *TP,
227 * @return whether @ref GetTemplateTokenString would be able to give you a string
229 int HaveTemplateTokenString(StrBuf *Target,
230 WCTemplputParams *TP,
238 * @Brief get the actual integer value of a token parameter
239 * in your tmplputs or conditionals use this function to access parameters that can also be
240 * retrieved from dynamic facilities:
241 * _ -> Gettext; retrieve this token from the i18n facilities
242 * : -> lookup a setting of that name
243 * B -> bstr; an URL-Parameter
244 * = -> subtemplate; parse a template by this name, and treat its content as this tokens value
246 * @param N which token do you want to lookup?
247 * @param dflt default value to be retrieved if not found in preferences
248 * \returns the long value
250 long GetTemplateTokenNumber(StrBuf *Target,
251 WCTemplputParams *TP,
255 * @Brief put a token value into the template
256 * use this function to append your strings into a Template.
257 * it can escape your string according to the token at FormattypeIndex:
258 * H: de-QP and utf8-ify
259 * X: escapize for HTML
261 * @param Target the destination buffer
262 * @param TP the template token information
263 * @param Source string to append
264 * @param FormatTypeIndex which parameter contains the escaping functionality?
265 * if this token doesn't have as much parameters, plain append is done.
267 void StrBufAppendTemplate(StrBuf *Target,
268 WCTemplputParams *TP,
269 const StrBuf *Source,
270 int FormatTypeIndex);
273 #define RegisterNamespace(a, b, c, d, e, f) RegisterNS(a, sizeof(a)-1, b, c, d, e, f)
275 * @Brief register a template token handler
276 * call this function in your InitModule_MODULENAME which will be called at the server start
277 * @param nMinArgs how much parameters does your token require at least?
278 * @param nMaxArgs how many parameters does your token accept?
279 * @param HandlerFunc your callback when the template is rendered and your token is there
280 * @param PreEvalFunc is called when the template is parsed; you can do additional
281 * syntax checks here or pre-evaluate stuff for better performance
282 * @param ContextRequired if your token requires a specific context, else say CTX_NONE here.
284 void RegisterNS(const char *NSName, long len,
287 WCHandlerFunc HandlerFunc,
288 WCPreevalFunc PreEvalFunc,
289 int ContextRequired);
292 * @Brief register a conditional token <pair> handler
293 * call this function in your InitModule_MODULENAME which will be called at the server start
294 * conditionals can be ? or ! with a pair or % similar to an implicit if
295 * @param Name whats the name of your conditional? should start with COND:
296 * @param len the token length so we don't have to measure it.
297 * @param nParams how many parameters does your conditional need on top of the default conditional parameters
298 * @param CondF your Callback to be called when the template is evaluated at runtime; return 0 or 1 to us please.
299 * @param ContextRequired if your token requires a specific context, else say CTX_NONE here.
301 void RegisterConditional(const char *Name, long len,
303 WCConditionalFunc CondF,
304 int ContextRequired);
307 * @brief register a string that will represent a long value
308 * this will allow to resolve <?...(#"Name")> to Value; that way
309 * plain strings can be used an lexed in templates without having the
310 * lookup overhead at runtime.
311 * @param Name The name of the define
312 * @param len length of Name
313 * @param Value the value to associate with Name
315 void RegisterTokenParamDefine(const char *Name, long len,
318 * teh r0x0r! forward your favourite define from C to the templates with one easy call!
320 #define REGISTERTokenParamDefine(a) RegisterTokenParamDefine(#a, sizeof(#a) - 1, a);
323 * @brief retrieve the long value of a registered string define
324 * @param Name The name of the define
325 * @param len length of Name
326 * @param Value the value to return if not found
328 long GetTokenDefine(const char *Name,
334 #define IT_FLAG_DETECT_GROUPCHANGE (1<<0)
335 #define RegisterIterator(a, b, c, d, e, f, g, h, i) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f, g, h, i)
336 void RegisterITERATOR(const char *Name, long len, /* Our identifier */
337 int AdditionalParams, /* doe we use more parameters? */
338 HashList *StaticList, /* pointer to webcit lifetime hashlists */
339 RetrieveHashlistFunc GetHash, /* else retrieve the hashlist by calling this function */
340 SubTemplFunc DoSubTempl, /* call this function on each iteration for svput & friends */
341 HashDestructorFunc Destructor, /* use this function to shut down the hash; NULL if its a reference */
342 int ContextType, /* which context do we provide to the subtemplate? */
343 int XPectContextType, /* which context do we expct to be called in? */
351 CompareFunc RetrieveSort(WCTemplputParams *TP,
352 const char *OtherPrefix, long OtherPrefixLen,
353 const char *Default, long ldefault,
354 long DefaultDirection);
355 void RegisterSortFunc(const char *name, long len,
356 const char *prepend, long preplen,
359 CompareFunc GroupChange,
362 void dbg_print_longvector(long *LongVector);
364 #define do_template(a) DoTemplate(a, sizeof(a) -1, NULL, &NoCtx)
365 const StrBuf *DoTemplate(const char *templatename, long len, StrBuf *Target, WCTemplputParams *TP);
366 void url_do_template(void);
369 int CompareSubstToToken(TemplateParam *ParamToCompare, TemplateParam *ParamToLookup);
370 int CompareSubstToStrBuf(StrBuf *Compare, TemplateParam *ParamToLookup);