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);
95 typedef enum _eBitMask {
101 typedef struct _TemplateParam {
102 /* are we a string or a number? */
107 /* if we're a number: */
114 * Representation of a token; everything thats inbetween <? and >
116 struct WCTemplateToken {
117 /* Reference to the filename we're in to print error messages; not to be freed */
118 const StrBuf *FileName;
119 /* Raw copy of our original token; for error printing */
121 /* Which line did the template parser pick us up in? For error printing */
124 /* our position in the template cache buffer */
125 const char *pTokenStart;
126 /* our token length */
130 const char *pTokenEnd;
131 /* just our token name: */
135 /* stuff the pre-evaluater finds out: */
137 /* pointer to our runntime evaluator; so we can cache this and save hash-lookups */
141 /* if we have parameters here we go: */
142 /* do we have parameters or not? */
144 /* How many of them? */
147 TemplateParam *Params[MAXPARAM];
152 struct WCTemplputParams {
153 ContextFilter Filter;
155 void *ControlContext;
157 WCTemplateToken *Tokens;
162 typedef struct _ConditionalStruct {
163 ContextFilter Filter;
164 const char *PlainName;
165 WCConditionalFunc CondF;
169 typedef void (*SubTemplFunc)(StrBuf *TemplBuffer, WCTemplputParams *TP);
170 typedef HashList *(*RetrieveHashlistFunc)(StrBuf *Target, WCTemplputParams *TP);
171 typedef void (*HashDestructorFunc) (HashList **KillMe);
174 extern WCTemplputParams NoCtx;
176 #define HAVE_PARAM(a) (TP->Tokens->nParameters > a)
183 * @Brief log an error while evaluating a token; print it to the actual template
184 * @param Target your Target Buffer to print the error message next to the log
185 * @param Type What sort of thing are we talking about? Tokens? Conditionals?
186 * @param TP grab our set of default information here
187 * @param Format for the custom error message
189 void LogTemplateError (StrBuf *Target,
192 WCTemplputParams *TP,
193 const char *Format, ...)__attribute__((__format__(__printf__,5,6)));
197 * @Brief log an error while in global context; print it to Wildfire / Target
198 * @param Target your Target Buffer to print the error message next to the log
199 * @param Type What sort of thing are we talking about? Tokens? Conditionals?
200 * @param Format for the custom error message
202 void LogError (StrBuf *Target, const char *Type, const char *Format, ...);
205 * @Brief get the actual value of a token parameter
206 * in your tmplputs or conditionals use this function to access parameters that can also be
207 * retrieved from dynamic facilities:
208 * _ -> Gettext; retrieve this token from the i18n facilities
209 * : -> lookup a setting of that name
210 * B -> bstr; an URL-Parameter
211 * = -> subtemplate; parse a template by this name, and treat its content as this tokens value
213 * @param N which token do you want to lookup?
214 * @param Value reference to the string of the token; don't free me.
215 * @param len the length of Value
217 void GetTemplateTokenString(StrBuf *Target,
218 WCTemplputParams *TP,
223 * @return whether @ref GetTemplateTokenString would be able to give you a string
225 int HaveTemplateTokenString(StrBuf *Target,
226 WCTemplputParams *TP,
234 * @Brief get the actual integer value of a token parameter
235 * in your tmplputs or conditionals use this function to access parameters that can also be
236 * retrieved from dynamic facilities:
237 * _ -> Gettext; retrieve this token from the i18n facilities
238 * : -> lookup a setting of that name
239 * B -> bstr; an URL-Parameter
240 * = -> subtemplate; parse a template by this name, and treat its content as this tokens value
242 * @param N which token do you want to lookup?
243 * @param dflt default value to be retrieved if not found in preferences
244 * \returns the long value
246 long GetTemplateTokenNumber(StrBuf *Target,
247 WCTemplputParams *TP,
251 * @Brief put a token value into the template
252 * use this function to append your strings into a Template.
253 * it can escape your string according to the token at FormattypeIndex:
254 * H: de-QP and utf8-ify
255 * X: escapize for HTML
257 * @param Target the destination buffer
258 * @param TP the template token information
259 * @param Source string to append
260 * @param FormatTypeIndex which parameter contains the escaping functionality?
261 * if this token doesn't have as much parameters, plain append is done.
263 void StrBufAppendTemplate(StrBuf *Target,
264 WCTemplputParams *TP,
265 const StrBuf *Source,
266 int FormatTypeIndex);
269 #define RegisterNamespace(a, b, c, d, e, f) RegisterNS(a, sizeof(a)-1, b, c, d, e, f)
271 * @Brief register a template token handler
272 * call this function in your InitModule_MODULENAME which will be called at the server start
273 * @param nMinArgs how much parameters does your token require at least?
274 * @param nMaxArgs how many parameters does your token accept?
275 * @param HandlerFunc your callback when the template is rendered and your token is there
276 * @param PreEvalFunc is called when the template is parsed; you can do additional
277 * syntax checks here or pre-evaluate stuff for better performance
278 * @param ContextRequired if your token requires a specific context, else say CTX_NONE here.
280 void RegisterNS(const char *NSName, long len,
283 WCHandlerFunc HandlerFunc,
284 WCPreevalFunc PreEvalFunc,
285 int ContextRequired);
288 * @Brief register a conditional token <pair> handler
289 * call this function in your InitModule_MODULENAME which will be called at the server start
290 * conditionals can be ? or ! with a pair or % similar to an implicit if
291 * @param Name whats the name of your conditional? should start with COND:
292 * @param len the token length so we don't have to measure it.
293 * @param nParams how many parameters does your conditional need on top of the default conditional parameters
294 * @param CondF your Callback to be called when the template is evaluated at runtime; return 0 or 1 to us please.
295 * @param ContextRequired if your token requires a specific context, else say CTX_NONE here.
297 void RegisterConditional(const char *Name, long len,
299 WCConditionalFunc CondF,
300 int ContextRequired);
303 * @brief register a string that will represent a long value
304 * this will allow to resolve <?...(#"Name")> to Value; that way
305 * plain strings can be used an lexed in templates without having the
306 * lookup overhead at runtime.
307 * @param Name The name of the define
308 * @param len length of Name
309 * @param Value the value to associate with Name
311 void RegisterTokenParamDefine(const char *Name, long len,
314 * teh r0x0r! forward your favourite define from C to the templates with one easy call!
316 #define REGISTERTokenParamDefine(a) RegisterTokenParamDefine(#a, sizeof(#a) - 1, a);
319 * @brief retrieve the long value of a registered string define
320 * @param Name The name of the define
321 * @param len length of Name
322 * @param Value the value to return if not found
324 long GetTokenDefine(const char *Name,
330 #define IT_FLAG_DETECT_GROUPCHANGE (1<<0)
331 #define RegisterIterator(a, b, c, d, e, f, g, h, i) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f, g, h, i)
332 void RegisterITERATOR(const char *Name, long len, /* Our identifier */
333 int AdditionalParams, /* doe we use more parameters? */
334 HashList *StaticList, /* pointer to webcit lifetime hashlists */
335 RetrieveHashlistFunc GetHash, /* else retrieve the hashlist by calling this function */
336 SubTemplFunc DoSubTempl, /* call this function on each iteration for svput & friends */
337 HashDestructorFunc Destructor, /* use this function to shut down the hash; NULL if its a reference */
338 int ContextType, /* which context do we provide to the subtemplate? */
339 int XPectContextType, /* which context do we expct to be called in? */
347 CompareFunc RetrieveSort(WCTemplputParams *TP,
348 const char *OtherPrefix, long OtherPrefixLen,
349 const char *Default, long ldefault,
350 long DefaultDirection);
351 void RegisterSortFunc(const char *name, long len,
352 const char *prepend, long preplen,
355 CompareFunc GroupChange,
361 void dbg_print_longvector(long *LongVector);
367 #define do_template(a, b) DoTemplate(a, sizeof(a) -1, NULL, &NoCtx)
368 const StrBuf *DoTemplate(const char *templatename, long len, StrBuf *Target, WCTemplputParams *TP);
369 void url_do_template(void);
375 int CompareSubstToToken(TemplateParam *ParamToCompare, TemplateParam *ParamToLookup);
376 int CompareSubstToStrBuf(StrBuf *Compare, TemplateParam *ParamToLookup);
378 void SVPut(char *keyname, size_t keylen, int keytype, char *Data);
379 #define svput(a, b, c) SVPut(a, sizeof(a) - 1, b, c)
380 void SVPutLong(char *keyname, size_t keylen, long Data);
381 #define svputlong(a, b) SVPutLong(a, sizeof(a) - 1, b)
382 void svprintf(char *keyname, size_t keylen, int keytype, const char *format,...) __attribute__((__format__(__printf__,4,5)));
383 void SVPRINTF(char *keyname, int keytype, const char *format,...) __attribute__((__format__(__printf__,3,4)));
384 void SVCALLBACK(char *keyname, WCHandlerFunc fcn_ptr);
385 void SVCallback(char *keyname, size_t keylen, WCHandlerFunc fcn_ptr);
386 #define svcallback(a, b) SVCallback(a, sizeof(a) - 1, b)
388 void SVPUTBuf(const char *keyname, int keylen, const StrBuf *Buf, int ref);
389 #define SVPutBuf(a, b, c); SVPUTBuf(a, sizeof(a) - 1, b, c)