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
22 * \brief Values for wcs_type
25 WCS_STRING, /* its a string */
26 WCS_FUNCTION, /* its a function callback */
27 WCS_SERVCMD, /* its a command to send to the citadel server */
28 WCS_STRBUF, /* its a strbuf we own */
29 WCS_STRBUF_REF, /* its a strbuf we mustn't free */
30 WCS_LONG /* its an integer */
33 #define CTX TP->Context
34 #define CCTX TP->ControlContext
43 #define CTX_NODECONF 7
44 #define CTX_USERLIST 8
46 #define CTX_MIME_ATACH 10
47 #define CTX_FILELIST 11
49 #define CTX_LONGVECTOR 13
52 #define CTX_ITERATE 16
56 * ContextFilter resembles our RTTI information. With this structure
57 * we can make shure a tmplput function can live with the environment
59 * if not, we will log/print an error and refuse to call it.
61 typedef struct _contexts {
62 int ContextType; /* do we require a User Context ? */
63 int ControlContextType; /* are we inside of a control structure? */
64 int nMinArgs; /* How many arguments do we need at least? */
65 int nMaxArgs; /* up to how many arguments can we handle? */
69 /* Forward declarations... */
70 typedef struct WCTemplateToken WCTemplateToken;
71 typedef struct WCTemplputParams WCTemplputParams;
73 /* this is the signature of a tmplput function */
74 typedef void (*WCHandlerFunc)(StrBuf *Target, WCTemplputParams *TP);
76 /* make a template token a lookup key: */
77 #define TKEY(a) TP->Tokens->Params[a]->Start, TP->Tokens->Params[a]->len
79 /* TODO: wcsubst should be private! */
82 * \brief Dynamic content for variable substitution in templates
84 typedef struct _wcsubst {
86 int wcs_type; /* which type of Substitution are we */
87 char wcs_key[32]; /* copy of our hashkey for debugging */
88 StrBuf *wcs_value; /* if we're a string, keep it here */
89 long lvalue; /* type long? keep data here */
90 WCHandlerFunc wcs_function; /* funcion hook ???*/
95 * this is the signature of a conditional function
96 * Note: Target is just passed in for error messages; don't write onto it in regular cases.
98 typedef int (*WCConditionalFunc)(StrBuf *Target, WCTemplputParams *TP);
101 typedef struct _TemplateParam {
102 /* are we a string or a number? */
107 /* if we're a number: */
113 * Representation of a token; everything thats inbetween <? and >
115 struct WCTemplateToken {
116 /* Reference to the filename we're in to print error messages; not to be freed */
117 const StrBuf *FileName;
118 /* Raw copy of our original token; for error printing */
120 /* Which line did the template parser pick us up in? For error printing */
123 /* our position in the template cache buffer */
124 const char *pTokenStart;
125 /* our token length */
129 const char *pTokenEnd;
130 /* just our token name: */
134 /* stuff the pre-evaluater finds out: */
136 /* pointer to our runntime evaluator; so we can cache this and save hash-lookups */
139 /* if we have parameters here we go: */
140 /* do we have parameters or not? */
142 /* How many of them? */
145 TemplateParam *Params[MAXPARAM];
150 struct WCTemplputParams {
151 ContextFilter Filter;
153 void *ControlContext;
155 WCTemplateToken *Tokens;
160 typedef struct _ConditionalStruct {
161 ContextFilter Filter;
162 const char *PlainName;
163 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;
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)));
196 * \Brief get the actual value of a token parameter
197 * in your tmplputs or conditionals use this function to access parameters that can also be
198 * retrieved from dynamic facilities:
199 * _ -> Gettext; retrieve this token from the i18n facilities
200 * : -> lookup a setting of that name
201 * B -> bstr; an URL-Parameter
202 * = -> subtemplate; parse a template by this name, and treat its content as this tokens value
204 * \param N which token do you want to lookup?
205 * \param Value reference to the string of the token; don't free me.
206 * \param len the length of Value
208 void GetTemplateTokenString(WCTemplputParams *TP,
214 * \Brief put a token value into the template
215 * use this function to append your strings into a Template.
216 * it can escape your string according to the token at FormattypeIndex:
217 * H: de-QP and utf8-ify
218 * X: escapize for HTML
220 * \param Target the destination buffer
221 * \param TP the template token information
222 * \param Source string to append
223 * \param FormatTypeIndex which parameter contains the escaping functionality?
224 * if this token doesn't have as much parameters, plain append is done.
226 void StrBufAppendTemplate(StrBuf *Target,
227 WCTemplputParams *TP,
228 const StrBuf *Source,
229 int FormatTypeIndex);
232 #define RegisterNamespace(a, b, c, d, e) RegisterNS(a, sizeof(a)-1, b, c, d, e)
233 void RegisterNS(const char *NSName, long len,
236 WCHandlerFunc HandlerFunc,
237 int ContextRequired);
239 void RegisterConditional(const char *Name, long len,
241 WCConditionalFunc CondF,
242 int ContextRequired);
247 #define IT_FLAG_DETECT_GROUPCHANGE (1<<0)
248 #define RegisterIterator(a, b, c, d, e, f, g, h, i) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f, g, h, i)
249 void RegisterITERATOR(const char *Name, long len, /* Our identifier */
250 int AdditionalParams, /* doe we use more parameters? */
251 HashList *StaticList, /* pointer to webcit lifetime hashlists */
252 RetrieveHashlistFunc GetHash, /* else retrieve the hashlist by calling this function */
253 SubTemplFunc DoSubTempl, /* call this function on each iteration for svput & friends */
254 HashDestructorFunc Destructor, /* use this function to shut down the hash; NULL if its a reference */
255 int ContextType, /* which context do we provide to the subtemplate? */
256 int XPectContextType, /* which context do we expct to be called in? */
264 CompareFunc RetrieveSort(WCTemplputParams *TP,
265 const char *OtherPrefix, long OtherPrefixLen,
266 const char *Default, long ldefault,
267 long DefaultDirection);
268 void RegisterSortFunc(const char *name, long len,
269 const char *prepend, long preplen,
272 CompareFunc GroupChange,
278 void dbg_print_longvector(long *LongVector);
284 #define do_template(a, b) DoTemplate(a, sizeof(a) -1, NULL, &NoCtx);
285 void DoTemplate(const char *templatename, long len, StrBuf *Target, WCTemplputParams *TP);
286 void url_do_template(void);
292 int CompareSubstToToken(TemplateParam *ParamToCompare, TemplateParam *ParamToLookup);
293 int CompareSubstToStrBuf(StrBuf *Compare, TemplateParam *ParamToLookup);
295 void SVPut(char *keyname, size_t keylen, int keytype, char *Data);
296 #define svput(a, b, c) SVPut(a, sizeof(a) - 1, b, c)
297 void SVPutLong(char *keyname, size_t keylen, long Data);
298 #define svputlong(a, b) SVPutLong(a, sizeof(a) - 1, b)
299 void svprintf(char *keyname, size_t keylen, int keytype, const char *format,...) __attribute__((__format__(__printf__,4,5)));
300 void SVPRINTF(char *keyname, int keytype, const char *format,...) __attribute__((__format__(__printf__,3,4)));
301 void SVCALLBACK(char *keyname, WCHandlerFunc fcn_ptr);
302 void SVCallback(char *keyname, size_t keylen, WCHandlerFunc fcn_ptr);
303 #define svcallback(a, b) SVCallback(a, sizeof(a) - 1, b)
305 void SVPUTBuf(const char *keyname, int keylen, const StrBuf *Buf, int ref);
306 #define SVPutBuf(a, b, c); SVPUTBuf(a, sizeof(a) - 1, b, c)