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_UNKNOWN 21
64 * ContextFilter resembles our RTTI information. With this structure
65 * we can make shure a tmplput function can live with the environment
67 * if not, we will log/print an error and refuse to call it.
69 typedef struct _contexts {
70 int ContextType; /* do we require a User Context ? */
71 int ControlContextType; /* are we inside of a control structure? */
72 int nMinArgs; /* How many arguments do we need at least? */
73 int nMaxArgs; /* up to how many arguments can we handle? */
77 /* Forward declarations... */
78 typedef struct WCTemplateToken WCTemplateToken;
79 typedef struct WCTemplputParams WCTemplputParams;
81 /* this is the signature of a tmplput function */
82 typedef void (*WCHandlerFunc)(StrBuf *Target, WCTemplputParams *TP);
84 /* if you want to pre-evaluate parts of your token, or do additional syntax, use this. */
85 typedef int (*WCPreevalFunc)(WCTemplateToken *Token);
87 /* make a template token a lookup key: */
88 #define TKEY(a) TP->Tokens->Params[a]->Start, TP->Tokens->Params[a]->len
91 * this is the signature of a conditional function
92 * Note: Target is just passed in for error messages; don't write onto it in regular cases.
94 typedef int (*WCConditionalFunc)(StrBuf *Target, WCTemplputParams *TP);
96 typedef enum _eBitMask {
102 typedef struct _TemplateParam {
103 /* are we a string or a number? */
108 /* if we're a number: */
115 * Representation of a token; everything thats inbetween <? and >
117 struct WCTemplateToken {
118 /* Reference to the filename we're in to print error messages; not to be freed */
119 const StrBuf *FileName;
120 /* Raw copy of our original token; for error printing */
122 /* Which line did the template parser pick us up in? For error printing */
125 /* our position in the template cache buffer */
126 const char *pTokenStart;
127 /* our token length */
131 const char *pTokenEnd;
132 /* just our token name: */
136 /* stuff the pre-evaluater finds out: */
138 /* pointer to our runntime evaluator; so we can cache this and save hash-lookups */
142 /* if we have parameters here we go: */
143 /* do we have parameters or not? */
145 /* How many of them? */
148 TemplateParam *Params[MAXPARAM];
153 struct WCTemplputParams {
154 ContextFilter Filter;
156 void *ControlContext;
158 WCTemplateToken *Tokens;
163 typedef struct _ConditionalStruct {
164 ContextFilter Filter;
165 const char *PlainName;
166 WCConditionalFunc CondF;
170 typedef void (*SubTemplFunc)(StrBuf *TemplBuffer, WCTemplputParams *TP);
171 typedef HashList *(*RetrieveHashlistFunc)(StrBuf *Target, WCTemplputParams *TP);
172 typedef void (*HashDestructorFunc) (HashList **KillMe);
175 extern WCTemplputParams NoCtx;
177 #define HAVE_PARAM(a) (TP->Tokens->nParameters > a)
184 * @Brief log an error while evaluating a token; print it to the actual template
185 * @param Target your Target Buffer to print the error message next to the log
186 * @param Type What sort of thing are we talking about? Tokens? Conditionals?
187 * @param TP grab our set of default information here
188 * @param Format for the custom error message
190 void LogTemplateError (StrBuf *Target,
193 WCTemplputParams *TP,
194 const char *Format, ...)__attribute__((__format__(__printf__,5,6)));
198 * @Brief log an error while in global context; print it to Wildfire / Target
199 * @param Target your Target Buffer to print the error message next to the log
200 * @param Type What sort of thing are we talking about? Tokens? Conditionals?
201 * @param Format for the custom error message
203 void LogError (StrBuf *Target, const char *Type, const char *Format, ...);
206 * @Brief get the actual value of a token parameter
207 * in your tmplputs or conditionals use this function to access parameters that can also be
208 * retrieved from dynamic facilities:
209 * _ -> Gettext; retrieve this token from the i18n facilities
210 * : -> lookup a setting of that name
211 * B -> bstr; an URL-Parameter
212 * = -> subtemplate; parse a template by this name, and treat its content as this tokens value
214 * @param N which token do you want to lookup?
215 * @param Value reference to the string of the token; don't free me.
216 * @param len the length of Value
218 void GetTemplateTokenString(StrBuf *Target,
219 WCTemplputParams *TP,
224 * @return whether @ref GetTemplateTokenString would be able to give you a string
226 int HaveTemplateTokenString(StrBuf *Target,
227 WCTemplputParams *TP,
235 * @Brief get the actual integer value of a token parameter
236 * in your tmplputs or conditionals use this function to access parameters that can also be
237 * retrieved from dynamic facilities:
238 * _ -> Gettext; retrieve this token from the i18n facilities
239 * : -> lookup a setting of that name
240 * B -> bstr; an URL-Parameter
241 * = -> subtemplate; parse a template by this name, and treat its content as this tokens value
243 * @param N which token do you want to lookup?
244 * @param dflt default value to be retrieved if not found in preferences
245 * \returns the long value
247 long GetTemplateTokenNumber(StrBuf *Target,
248 WCTemplputParams *TP,
252 * @Brief put a token value into the template
253 * use this function to append your strings into a Template.
254 * it can escape your string according to the token at FormattypeIndex:
255 * H: de-QP and utf8-ify
256 * X: escapize for HTML
258 * @param Target the destination buffer
259 * @param TP the template token information
260 * @param Source string to append
261 * @param FormatTypeIndex which parameter contains the escaping functionality?
262 * if this token doesn't have as much parameters, plain append is done.
264 void StrBufAppendTemplate(StrBuf *Target,
265 WCTemplputParams *TP,
266 const StrBuf *Source,
267 int FormatTypeIndex);
270 #define RegisterNamespace(a, b, c, d, e, f) RegisterNS(a, sizeof(a)-1, b, c, d, e, f)
272 * @Brief register a template token handler
273 * call this function in your InitModule_MODULENAME which will be called at the server start
274 * @param nMinArgs how much parameters does your token require at least?
275 * @param nMaxArgs how many parameters does your token accept?
276 * @param HandlerFunc your callback when the template is rendered and your token is there
277 * @param PreEvalFunc is called when the template is parsed; you can do additional
278 * syntax checks here or pre-evaluate stuff for better performance
279 * @param ContextRequired if your token requires a specific context, else say CTX_NONE here.
281 void RegisterNS(const char *NSName, long len,
284 WCHandlerFunc HandlerFunc,
285 WCPreevalFunc PreEvalFunc,
286 int ContextRequired);
289 * @Brief register a conditional token <pair> handler
290 * call this function in your InitModule_MODULENAME which will be called at the server start
291 * conditionals can be ? or ! with a pair or % similar to an implicit if
292 * @param Name whats the name of your conditional? should start with COND:
293 * @param len the token length so we don't have to measure it.
294 * @param nParams how many parameters does your conditional need on top of the default conditional parameters
295 * @param CondF your Callback to be called when the template is evaluated at runtime; return 0 or 1 to us please.
296 * @param ContextRequired if your token requires a specific context, else say CTX_NONE here.
298 void RegisterConditional(const char *Name, long len,
300 WCConditionalFunc CondF,
301 int ContextRequired);
304 * @brief register a string that will represent a long value
305 * this will allow to resolve <?...(#"Name")> to Value; that way
306 * plain strings can be used an lexed in templates without having the
307 * lookup overhead at runtime.
308 * @param Name The name of the define
309 * @param len length of Name
310 * @param Value the value to associate with Name
312 void RegisterTokenParamDefine(const char *Name, long len,
315 * teh r0x0r! forward your favourite define from C to the templates with one easy call!
317 #define REGISTERTokenParamDefine(a) RegisterTokenParamDefine(#a, sizeof(#a) - 1, a);
320 * @brief retrieve the long value of a registered string define
321 * @param Name The name of the define
322 * @param len length of Name
323 * @param Value the value to return if not found
325 long GetTokenDefine(const char *Name,
331 #define IT_FLAG_DETECT_GROUPCHANGE (1<<0)
332 #define RegisterIterator(a, b, c, d, e, f, g, h, i) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f, g, h, i)
333 void RegisterITERATOR(const char *Name, long len, /* Our identifier */
334 int AdditionalParams, /* doe we use more parameters? */
335 HashList *StaticList, /* pointer to webcit lifetime hashlists */
336 RetrieveHashlistFunc GetHash, /* else retrieve the hashlist by calling this function */
337 SubTemplFunc DoSubTempl, /* call this function on each iteration for svput & friends */
338 HashDestructorFunc Destructor, /* use this function to shut down the hash; NULL if its a reference */
339 int ContextType, /* which context do we provide to the subtemplate? */
340 int XPectContextType, /* which context do we expct to be called in? */
348 CompareFunc RetrieveSort(WCTemplputParams *TP,
349 const char *OtherPrefix, long OtherPrefixLen,
350 const char *Default, long ldefault,
351 long DefaultDirection);
352 void RegisterSortFunc(const char *name, long len,
353 const char *prepend, long preplen,
356 CompareFunc GroupChange,
359 void dbg_print_longvector(long *LongVector);
361 #define do_template(a, b) DoTemplate(a, sizeof(a) -1, NULL, &NoCtx)
362 const StrBuf *DoTemplate(const char *templatename, long len, StrBuf *Target, WCTemplputParams *TP);
363 void url_do_template(void);
366 int CompareSubstToToken(TemplateParam *ParamToCompare, TemplateParam *ParamToLookup);
367 int CompareSubstToStrBuf(StrBuf *Compare, TemplateParam *ParamToLookup);