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
59 #define CTX_UNKNOWN 20
63 * ContextFilter resembles our RTTI information. With this structure
64 * we can make shure a tmplput function can live with the environment
66 * if not, we will log/print an error and refuse to call it.
68 typedef struct _contexts {
69 int ContextType; /* do we require a User Context ? */
70 int ControlContextType; /* are we inside of a control structure? */
71 int nMinArgs; /* How many arguments do we need at least? */
72 int nMaxArgs; /* up to how many arguments can we handle? */
76 /* Forward declarations... */
77 typedef struct WCTemplateToken WCTemplateToken;
78 typedef struct WCTemplputParams WCTemplputParams;
80 /* this is the signature of a tmplput function */
81 typedef void (*WCHandlerFunc)(StrBuf *Target, WCTemplputParams *TP);
83 /* if you want to pre-evaluate parts of your token, or do additional syntax, use this. */
84 typedef int (*WCPreevalFunc)(WCTemplateToken *Token);
86 /* make a template token a lookup key: */
87 #define TKEY(a) TP->Tokens->Params[a]->Start, TP->Tokens->Params[a]->len
90 * this is the signature of a conditional function
91 * Note: Target is just passed in for error messages; don't write onto it in regular cases.
93 typedef int (*WCConditionalFunc)(StrBuf *Target, WCTemplputParams *TP);
96 typedef struct _TemplateParam {
97 /* are we a string or a number? */
102 /* if we're a number: */
108 * Representation of a token; everything thats inbetween <? and >
110 struct WCTemplateToken {
111 /* Reference to the filename we're in to print error messages; not to be freed */
112 const StrBuf *FileName;
113 /* Raw copy of our original token; for error printing */
115 /* Which line did the template parser pick us up in? For error printing */
118 /* our position in the template cache buffer */
119 const char *pTokenStart;
120 /* our token length */
124 const char *pTokenEnd;
125 /* just our token name: */
129 /* stuff the pre-evaluater finds out: */
131 /* pointer to our runntime evaluator; so we can cache this and save hash-lookups */
135 /* if we have parameters here we go: */
136 /* do we have parameters or not? */
138 /* How many of them? */
141 TemplateParam *Params[MAXPARAM];
146 struct WCTemplputParams {
147 ContextFilter Filter;
149 void *ControlContext;
151 WCTemplateToken *Tokens;
156 typedef struct _ConditionalStruct {
157 ContextFilter Filter;
158 const char *PlainName;
159 WCConditionalFunc CondF;
163 typedef void (*SubTemplFunc)(StrBuf *TemplBuffer, WCTemplputParams *TP);
164 typedef HashList *(*RetrieveHashlistFunc)(StrBuf *Target, WCTemplputParams *TP);
165 typedef void (*HashDestructorFunc) (HashList **KillMe);
168 extern WCTemplputParams NoCtx;
170 #define HAVE_PARAM(a) (TP->Tokens->nParameters > a)
177 * @Brief log an error while evaluating a token; print it to the actual template
178 * @param Target your Target Buffer to print the error message next to the log
179 * @param Type What sort of thing are we talking about? Tokens? Conditionals?
180 * @param TP grab our set of default information here
181 * @param Format for the custom error message
183 void LogTemplateError (StrBuf *Target,
186 WCTemplputParams *TP,
187 const char *Format, ...)__attribute__((__format__(__printf__,5,6)));
191 * @Brief log an error while in global context; print it to Wildfire / Target
192 * @param Target your Target Buffer to print the error message next to the log
193 * @param Type What sort of thing are we talking about? Tokens? Conditionals?
194 * @param Format for the custom error message
196 void LogError (StrBuf *Target, const char *Type, const char *Format, ...);
199 * @Brief get the actual value of a token parameter
200 * in your tmplputs or conditionals use this function to access parameters that can also be
201 * retrieved from dynamic facilities:
202 * _ -> Gettext; retrieve this token from the i18n facilities
203 * : -> lookup a setting of that name
204 * B -> bstr; an URL-Parameter
205 * = -> subtemplate; parse a template by this name, and treat its content as this tokens value
207 * @param N which token do you want to lookup?
208 * @param Value reference to the string of the token; don't free me.
209 * @param len the length of Value
211 void GetTemplateTokenString(StrBuf *Target,
212 WCTemplputParams *TP,
217 * @return whether @ref GetTemplateTokenString would be able to give you a string
219 int HaveTemplateTokenString(StrBuf *Target,
220 WCTemplputParams *TP,
228 * @Brief get the actual integer value of a token parameter
229 * in your tmplputs or conditionals use this function to access parameters that can also be
230 * retrieved from dynamic facilities:
231 * _ -> Gettext; retrieve this token from the i18n facilities
232 * : -> lookup a setting of that name
233 * B -> bstr; an URL-Parameter
234 * = -> subtemplate; parse a template by this name, and treat its content as this tokens value
236 * @param N which token do you want to lookup?
237 * @param dflt default value to be retrieved if not found in preferences
238 * \returns the long value
240 long GetTemplateTokenNumber(StrBuf *Target,
241 WCTemplputParams *TP,
245 * @Brief put a token value into the template
246 * use this function to append your strings into a Template.
247 * it can escape your string according to the token at FormattypeIndex:
248 * H: de-QP and utf8-ify
249 * X: escapize for HTML
251 * @param Target the destination buffer
252 * @param TP the template token information
253 * @param Source string to append
254 * @param FormatTypeIndex which parameter contains the escaping functionality?
255 * if this token doesn't have as much parameters, plain append is done.
257 void StrBufAppendTemplate(StrBuf *Target,
258 WCTemplputParams *TP,
259 const StrBuf *Source,
260 int FormatTypeIndex);
263 #define RegisterNamespace(a, b, c, d, e, f) RegisterNS(a, sizeof(a)-1, b, c, d, e, f)
265 * @Brief register a template token handler
266 * call this function in your InitModule_MODULENAME which will be called at the server start
267 * @param nMinArgs how much parameters does your token require at least?
268 * @param nMaxArgs how many parameters does your token accept?
269 * @param HandlerFunc your callback when the template is rendered and your token is there
270 * @param PreEvalFunc is called when the template is parsed; you can do additional
271 * syntax checks here or pre-evaluate stuff for better performance
272 * @param ContextRequired if your token requires a specific context, else say CTX_NONE here.
274 void RegisterNS(const char *NSName, long len,
277 WCHandlerFunc HandlerFunc,
278 WCPreevalFunc PreEvalFunc,
279 int ContextRequired);
282 * @Brief register a conditional token <pair> handler
283 * call this function in your InitModule_MODULENAME which will be called at the server start
284 * conditionals can be ? or ! with a pair or % similar to an implicit if
285 * @param Name whats the name of your conditional? should start with COND:
286 * @param len the token length so we don't have to measure it.
287 * @param nParams how many parameters does your conditional need on top of the default conditional parameters
288 * @param CondF your Callback to be called when the template is evaluated at runtime; return 0 or 1 to us please.
289 * @param ContextRequired if your token requires a specific context, else say CTX_NONE here.
291 void RegisterConditional(const char *Name, long len,
293 WCConditionalFunc CondF,
294 int ContextRequired);
297 * @brief register a string that will represent a long value
298 * this will allow to resolve <?...(#"Name")> to Value; that way
299 * plain strings can be used an lexed in templates without having the
300 * lookup overhead at runtime.
301 * @param Name The name of the define
302 * @param len length of Name
303 * @param Value the value to associate with Name
305 void RegisterTokenParamDefine(const char *Name, long len,
308 * teh r0x0r! forward your favourite define from C to the templates with one easy call!
310 #define REGISTERTokenParamDefine(a) RegisterTokenParamDefine(#a, sizeof(#a) - 1, a);
313 * @brief retrieve the long value of a registered string define
314 * @param Name The name of the define
315 * @param len length of Name
316 * @param Value the value to return if not found
318 long GetTokenDefine(const char *Name,
324 #define IT_FLAG_DETECT_GROUPCHANGE (1<<0)
325 #define RegisterIterator(a, b, c, d, e, f, g, h, i) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f, g, h, i)
326 void RegisterITERATOR(const char *Name, long len, /* Our identifier */
327 int AdditionalParams, /* doe we use more parameters? */
328 HashList *StaticList, /* pointer to webcit lifetime hashlists */
329 RetrieveHashlistFunc GetHash, /* else retrieve the hashlist by calling this function */
330 SubTemplFunc DoSubTempl, /* call this function on each iteration for svput & friends */
331 HashDestructorFunc Destructor, /* use this function to shut down the hash; NULL if its a reference */
332 int ContextType, /* which context do we provide to the subtemplate? */
333 int XPectContextType, /* which context do we expct to be called in? */
341 CompareFunc RetrieveSort(WCTemplputParams *TP,
342 const char *OtherPrefix, long OtherPrefixLen,
343 const char *Default, long ldefault,
344 long DefaultDirection);
345 void RegisterSortFunc(const char *name, long len,
346 const char *prepend, long preplen,
349 CompareFunc GroupChange,
355 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);
369 int CompareSubstToToken(TemplateParam *ParamToCompare, TemplateParam *ParamToLookup);
370 int CompareSubstToStrBuf(StrBuf *Compare, TemplateParam *ParamToLookup);
372 void SVPut(char *keyname, size_t keylen, int keytype, char *Data);
373 #define svput(a, b, c) SVPut(a, sizeof(a) - 1, b, c)
374 void SVPutLong(char *keyname, size_t keylen, long Data);
375 #define svputlong(a, b) SVPutLong(a, sizeof(a) - 1, b)
376 void svprintf(char *keyname, size_t keylen, int keytype, const char *format,...) __attribute__((__format__(__printf__,4,5)));
377 void SVPRINTF(char *keyname, int keytype, const char *format,...) __attribute__((__format__(__printf__,3,4)));
378 void SVCALLBACK(char *keyname, WCHandlerFunc fcn_ptr);
379 void SVCallback(char *keyname, size_t keylen, WCHandlerFunc fcn_ptr);
380 #define svcallback(a, b) SVCallback(a, sizeof(a) - 1, b)
382 void SVPUTBuf(const char *keyname, int keylen, const StrBuf *Buf, int ref);
383 #define SVPutBuf(a, b, c); SVPUTBuf(a, sizeof(a) - 1, b, c)