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
23 * \brief Values for wcs_type
26 WCS_STRING, /* its a string */
27 WCS_FUNCTION, /* its a function callback */
28 WCS_SERVCMD, /* its a command to send to the citadel server */
29 WCS_STRBUF, /* its a strbuf we own */
30 WCS_STRBUF_REF, /* its a strbuf we mustn't free */
31 WCS_LONG /* its an integer */
34 #define CTX TP->Context
35 #define CCTX TP->ControlContext
44 #define CTX_NODECONF 7
45 #define CTX_USERLIST 8
47 #define CTX_MIME_ATACH 10
48 #define CTX_FILELIST 11
50 #define CTX_STRBUFARR 13
51 #define CTX_LONGVECTOR 14
54 #define CTX_ITERATE 17
58 #define CTX_UNKNOWN 20
62 * ContextFilter resembles our RTTI information. With this structure
63 * we can make shure a tmplput function can live with the environment
65 * if not, we will log/print an error and refuse to call it.
67 typedef struct _contexts {
68 int ContextType; /* do we require a User Context ? */
69 int ControlContextType; /* are we inside of a control structure? */
70 int nMinArgs; /* How many arguments do we need at least? */
71 int nMaxArgs; /* up to how many arguments can we handle? */
75 /* Forward declarations... */
76 typedef struct WCTemplateToken WCTemplateToken;
77 typedef struct WCTemplputParams WCTemplputParams;
79 /* this is the signature of a tmplput function */
80 typedef void (*WCHandlerFunc)(StrBuf *Target, WCTemplputParams *TP);
82 /* if you want to pre-evaluate parts of your token, or do additional syntax, use this. */
83 typedef int (*WCPreevalFunc)(WCTemplateToken *Token);
85 /* make a template token a lookup key: */
86 #define TKEY(a) TP->Tokens->Params[a]->Start, TP->Tokens->Params[a]->len
89 * this is the signature of a conditional function
90 * Note: Target is just passed in for error messages; don't write onto it in regular cases.
92 typedef int (*WCConditionalFunc)(StrBuf *Target, WCTemplputParams *TP);
95 typedef struct _TemplateParam {
96 /* are we a string or a number? */
101 /* if we're a number: */
107 * Representation of a token; everything thats inbetween <? and >
109 struct WCTemplateToken {
110 /* Reference to the filename we're in to print error messages; not to be freed */
111 const StrBuf *FileName;
112 /* Raw copy of our original token; for error printing */
114 /* Which line did the template parser pick us up in? For error printing */
117 /* our position in the template cache buffer */
118 const char *pTokenStart;
119 /* our token length */
123 const char *pTokenEnd;
124 /* just our token name: */
128 /* stuff the pre-evaluater finds out: */
130 /* pointer to our runntime evaluator; so we can cache this and save hash-lookups */
134 /* if we have parameters here we go: */
135 /* do we have parameters or not? */
137 /* How many of them? */
140 TemplateParam *Params[MAXPARAM];
145 struct WCTemplputParams {
146 ContextFilter Filter;
148 void *ControlContext;
150 WCTemplateToken *Tokens;
155 typedef struct _ConditionalStruct {
156 ContextFilter Filter;
157 const char *PlainName;
158 WCConditionalFunc CondF;
162 typedef void (*SubTemplFunc)(StrBuf *TemplBuffer, WCTemplputParams *TP);
163 typedef HashList *(*RetrieveHashlistFunc)(StrBuf *Target, WCTemplputParams *TP);
164 typedef void (*HashDestructorFunc) (HashList **KillMe);
167 extern WCTemplputParams NoCtx;
169 #define HAVE_PARAM(a) (TP->Tokens->nParameters > a)
176 * @Brief log an error while evaluating a token; print it to the actual template
177 * @param Target your Target Buffer to print the error message next to the log
178 * @param Type What sort of thing are we talking about? Tokens? Conditionals?
179 * @param TP grab our set of default information here
180 * @param Format for the custom error message
182 void LogTemplateError (StrBuf *Target,
185 WCTemplputParams *TP,
186 const char *Format, ...)__attribute__((__format__(__printf__,5,6)));
190 * @Brief log an error while in global context; print it to Wildfire / Target
191 * @param Target your Target Buffer to print the error message next to the log
192 * @param Type What sort of thing are we talking about? Tokens? Conditionals?
193 * @param Format for the custom error message
195 void LogError (StrBuf *Target, const char *Type, const char *Format, ...);
198 * @Brief get the actual value of a token parameter
199 * in your tmplputs or conditionals use this function to access parameters that can also be
200 * retrieved from dynamic facilities:
201 * _ -> Gettext; retrieve this token from the i18n facilities
202 * : -> lookup a setting of that name
203 * B -> bstr; an URL-Parameter
204 * = -> subtemplate; parse a template by this name, and treat its content as this tokens value
206 * @param N which token do you want to lookup?
207 * @param Value reference to the string of the token; don't free me.
208 * @param len the length of Value
210 void GetTemplateTokenString(StrBuf *Target,
211 WCTemplputParams *TP,
216 * @return whether @ref GetTemplateTokenString would be able to give you a string
218 int HaveTemplateTokenString(StrBuf *Target,
219 WCTemplputParams *TP,
227 * @Brief get the actual integer value of a token parameter
228 * in your tmplputs or conditionals use this function to access parameters that can also be
229 * retrieved from dynamic facilities:
230 * _ -> Gettext; retrieve this token from the i18n facilities
231 * : -> lookup a setting of that name
232 * B -> bstr; an URL-Parameter
233 * = -> subtemplate; parse a template by this name, and treat its content as this tokens value
235 * @param N which token do you want to lookup?
236 * @param dflt default value to be retrieved if not found in preferences
237 * \returns the long value
239 long GetTemplateTokenNumber(StrBuf *Target,
240 WCTemplputParams *TP,
244 * @Brief put a token value into the template
245 * use this function to append your strings into a Template.
246 * it can escape your string according to the token at FormattypeIndex:
247 * H: de-QP and utf8-ify
248 * X: escapize for HTML
250 * @param Target the destination buffer
251 * @param TP the template token information
252 * @param Source string to append
253 * @param FormatTypeIndex which parameter contains the escaping functionality?
254 * if this token doesn't have as much parameters, plain append is done.
256 void StrBufAppendTemplate(StrBuf *Target,
257 WCTemplputParams *TP,
258 const StrBuf *Source,
259 int FormatTypeIndex);
262 #define RegisterNamespace(a, b, c, d, e, f) RegisterNS(a, sizeof(a)-1, b, c, d, e, f)
264 * @Brief register a template token handler
265 * call this function in your InitModule_MODULENAME which will be called at the server start
266 * @param nMinArgs how much parameters does your token require at least?
267 * @param nMaxArgs how many parameters does your token accept?
268 * @param HandlerFunc your callback when the template is rendered and your token is there
269 * @param PreEvalFunc is called when the template is parsed; you can do additional
270 * syntax checks here or pre-evaluate stuff for better performance
271 * @param ContextRequired if your token requires a specific context, else say CTX_NONE here.
273 void RegisterNS(const char *NSName, long len,
276 WCHandlerFunc HandlerFunc,
277 WCPreevalFunc PreEvalFunc,
278 int ContextRequired);
281 * @Brief register a conditional token <pair> handler
282 * call this function in your InitModule_MODULENAME which will be called at the server start
283 * conditionals can be ? or ! with a pair or % similar to an implicit if
284 * @param Name whats the name of your conditional? should start with COND:
285 * @param len the token length so we don't have to measure it.
286 * @param nParams how many parameters does your conditional need on top of the default conditional parameters
287 * @param CondF your Callback to be called when the template is evaluated at runtime; return 0 or 1 to us please.
288 * @param ContextRequired if your token requires a specific context, else say CTX_NONE here.
290 void RegisterConditional(const char *Name, long len,
292 WCConditionalFunc CondF,
293 int ContextRequired);
296 * @brief register a string that will represent a long value
297 * this will allow to resolve <?...(#"Name")> to Value; that way
298 * plain strings can be used an lexed in templates without having the
299 * lookup overhead at runtime.
300 * @param Name The name of the define
301 * @param len length of Name
302 * @param Value the value to associate with Name
304 void RegisterTokenParamDefine(const char *Name, long len,
307 * teh r0x0r! forward your favourite define from C to the templates with one easy call!
309 #define REGISTERTokenParamDefine(a) RegisterTokenParamDefine(#a, sizeof(#a) - 1, a);
312 * @brief retrieve the long value of a registered string define
313 * @param Name The name of the define
314 * @param len length of Name
315 * @param Value the value to return if not found
317 long GetTokenDefine(const char *Name,
323 #define IT_FLAG_DETECT_GROUPCHANGE (1<<0)
324 #define RegisterIterator(a, b, c, d, e, f, g, h, i) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f, g, h, i)
325 void RegisterITERATOR(const char *Name, long len, /* Our identifier */
326 int AdditionalParams, /* doe we use more parameters? */
327 HashList *StaticList, /* pointer to webcit lifetime hashlists */
328 RetrieveHashlistFunc GetHash, /* else retrieve the hashlist by calling this function */
329 SubTemplFunc DoSubTempl, /* call this function on each iteration for svput & friends */
330 HashDestructorFunc Destructor, /* use this function to shut down the hash; NULL if its a reference */
331 int ContextType, /* which context do we provide to the subtemplate? */
332 int XPectContextType, /* which context do we expct to be called in? */
340 CompareFunc RetrieveSort(WCTemplputParams *TP,
341 const char *OtherPrefix, long OtherPrefixLen,
342 const char *Default, long ldefault,
343 long DefaultDirection);
344 void RegisterSortFunc(const char *name, long len,
345 const char *prepend, long preplen,
348 CompareFunc GroupChange,
354 void dbg_print_longvector(long *LongVector);
360 #define do_template(a, b) DoTemplate(a, sizeof(a) -1, NULL, &NoCtx);
361 const StrBuf *DoTemplate(const char *templatename, long len, StrBuf *Target, WCTemplputParams *TP);
362 void url_do_template(void);
368 int CompareSubstToToken(TemplateParam *ParamToCompare, TemplateParam *ParamToLookup);
369 int CompareSubstToStrBuf(StrBuf *Compare, TemplateParam *ParamToLookup);
371 void SVPut(char *keyname, size_t keylen, int keytype, char *Data);
372 #define svput(a, b, c) SVPut(a, sizeof(a) - 1, b, c)
373 void SVPutLong(char *keyname, size_t keylen, long Data);
374 #define svputlong(a, b) SVPutLong(a, sizeof(a) - 1, b)
375 void svprintf(char *keyname, size_t keylen, int keytype, const char *format,...) __attribute__((__format__(__printf__,4,5)));
376 void SVPRINTF(char *keyname, int keytype, const char *format,...) __attribute__((__format__(__printf__,3,4)));
377 void SVCALLBACK(char *keyname, WCHandlerFunc fcn_ptr);
378 void SVCallback(char *keyname, size_t keylen, WCHandlerFunc fcn_ptr);
379 #define svcallback(a, b) SVCallback(a, sizeof(a) - 1, b)
381 void SVPUTBuf(const char *keyname, int keylen, const StrBuf *Buf, int ref);
382 #define SVPutBuf(a, b, c); SVPUTBuf(a, sizeof(a) - 1, b, c)