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
54 #define CTX_UNKNOWN 17
58 * ContextFilter resembles our RTTI information. With this structure
59 * we can make shure a tmplput function can live with the environment
61 * if not, we will log/print an error and refuse to call it.
63 typedef struct _contexts {
64 int ContextType; /* do we require a User Context ? */
65 int ControlContextType; /* are we inside of a control structure? */
66 int nMinArgs; /* How many arguments do we need at least? */
67 int nMaxArgs; /* up to how many arguments can we handle? */
71 /* Forward declarations... */
72 typedef struct WCTemplateToken WCTemplateToken;
73 typedef struct WCTemplputParams WCTemplputParams;
75 /* this is the signature of a tmplput function */
76 typedef void (*WCHandlerFunc)(StrBuf *Target, WCTemplputParams *TP);
78 /* make a template token a lookup key: */
79 #define TKEY(a) TP->Tokens->Params[a]->Start, TP->Tokens->Params[a]->len
82 * this is the signature of a conditional function
83 * Note: Target is just passed in for error messages; don't write onto it in regular cases.
85 typedef int (*WCConditionalFunc)(StrBuf *Target, WCTemplputParams *TP);
88 typedef struct _TemplateParam {
89 /* are we a string or a number? */
94 /* if we're a number: */
100 * Representation of a token; everything thats inbetween <? and >
102 struct WCTemplateToken {
103 /* Reference to the filename we're in to print error messages; not to be freed */
104 const StrBuf *FileName;
105 /* Raw copy of our original token; for error printing */
107 /* Which line did the template parser pick us up in? For error printing */
110 /* our position in the template cache buffer */
111 const char *pTokenStart;
112 /* our token length */
116 const char *pTokenEnd;
117 /* just our token name: */
121 /* stuff the pre-evaluater finds out: */
123 /* pointer to our runntime evaluator; so we can cache this and save hash-lookups */
126 /* if we have parameters here we go: */
127 /* do we have parameters or not? */
129 /* How many of them? */
132 TemplateParam *Params[MAXPARAM];
137 struct WCTemplputParams {
138 ContextFilter Filter;
140 void *ControlContext;
142 WCTemplateToken *Tokens;
147 typedef struct _ConditionalStruct {
148 ContextFilter Filter;
149 const char *PlainName;
150 WCConditionalFunc CondF;
154 typedef void (*SubTemplFunc)(StrBuf *TemplBuffer, WCTemplputParams *TP);
155 typedef HashList *(*RetrieveHashlistFunc)(StrBuf *Target, WCTemplputParams *TP);
156 typedef void (*HashDestructorFunc) (HashList **KillMe);
159 extern WCTemplputParams NoCtx;
161 #define HAVE_PARAM(a) (TP->Tokens->nParameters > a)
168 * \Brief log an error while evaluating a token; print it to the actual template
169 * \param Target your Target Buffer to print the error message next to the log
170 * \param Type What sort of thing are we talking about? Tokens? Conditionals?
171 * \param TP grab our set of default information here
172 * \param Format for the custom error message
174 void LogTemplateError (StrBuf *Target,
177 WCTemplputParams *TP,
178 const char *Format, ...)__attribute__((__format__(__printf__,5,6)));
181 * \Brief get the actual value of a token parameter
182 * in your tmplputs or conditionals use this function to access parameters that can also be
183 * retrieved from dynamic facilities:
184 * _ -> Gettext; retrieve this token from the i18n facilities
185 * : -> lookup a setting of that name
186 * B -> bstr; an URL-Parameter
187 * = -> subtemplate; parse a template by this name, and treat its content as this tokens value
189 * \param N which token do you want to lookup?
190 * \param Value reference to the string of the token; don't free me.
191 * \param len the length of Value
193 void GetTemplateTokenString(StrBuf *Target,
194 WCTemplputParams *TP,
202 * \Brief get the actual integer value of a token parameter
203 * in your tmplputs or conditionals use this function to access parameters that can also be
204 * retrieved from dynamic facilities:
205 * _ -> Gettext; retrieve this token from the i18n facilities
206 * : -> lookup a setting of that name
207 * B -> bstr; an URL-Parameter
208 * = -> subtemplate; parse a template by this name, and treat its content as this tokens value
210 * \param N which token do you want to lookup?
211 * \param dflt default value to be retrieved if not found in preferences
212 * \returns the long value
214 long GetTemplateTokenNumber(StrBuf *Target,
215 WCTemplputParams *TP,
219 * \Brief put a token value into the template
220 * use this function to append your strings into a Template.
221 * it can escape your string according to the token at FormattypeIndex:
222 * H: de-QP and utf8-ify
223 * X: escapize for HTML
225 * \param Target the destination buffer
226 * \param TP the template token information
227 * \param Source string to append
228 * \param FormatTypeIndex which parameter contains the escaping functionality?
229 * if this token doesn't have as much parameters, plain append is done.
231 void StrBufAppendTemplate(StrBuf *Target,
232 WCTemplputParams *TP,
233 const StrBuf *Source,
234 int FormatTypeIndex);
237 #define RegisterNamespace(a, b, c, d, e) RegisterNS(a, sizeof(a)-1, b, c, d, e)
238 void RegisterNS(const char *NSName, long len,
241 WCHandlerFunc HandlerFunc,
242 int ContextRequired);
244 void RegisterConditional(const char *Name, long len,
246 WCConditionalFunc CondF,
247 int ContextRequired);
252 #define IT_FLAG_DETECT_GROUPCHANGE (1<<0)
253 #define RegisterIterator(a, b, c, d, e, f, g, h, i) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f, g, h, i)
254 void RegisterITERATOR(const char *Name, long len, /* Our identifier */
255 int AdditionalParams, /* doe we use more parameters? */
256 HashList *StaticList, /* pointer to webcit lifetime hashlists */
257 RetrieveHashlistFunc GetHash, /* else retrieve the hashlist by calling this function */
258 SubTemplFunc DoSubTempl, /* call this function on each iteration for svput & friends */
259 HashDestructorFunc Destructor, /* use this function to shut down the hash; NULL if its a reference */
260 int ContextType, /* which context do we provide to the subtemplate? */
261 int XPectContextType, /* which context do we expct to be called in? */
269 CompareFunc RetrieveSort(WCTemplputParams *TP,
270 const char *OtherPrefix, long OtherPrefixLen,
271 const char *Default, long ldefault,
272 long DefaultDirection);
273 void RegisterSortFunc(const char *name, long len,
274 const char *prepend, long preplen,
277 CompareFunc GroupChange,
283 void dbg_print_longvector(long *LongVector);
289 #define do_template(a, b) DoTemplate(a, sizeof(a) -1, NULL, &NoCtx);
290 const StrBuf *DoTemplate(const char *templatename, long len, StrBuf *Target, WCTemplputParams *TP);
291 void url_do_template(void);
297 int CompareSubstToToken(TemplateParam *ParamToCompare, TemplateParam *ParamToLookup);
298 int CompareSubstToStrBuf(StrBuf *Compare, TemplateParam *ParamToLookup);
300 void SVPut(char *keyname, size_t keylen, int keytype, char *Data);
301 #define svput(a, b, c) SVPut(a, sizeof(a) - 1, b, c)
302 void SVPutLong(char *keyname, size_t keylen, long Data);
303 #define svputlong(a, b) SVPutLong(a, sizeof(a) - 1, b)
304 void svprintf(char *keyname, size_t keylen, int keytype, const char *format,...) __attribute__((__format__(__printf__,4,5)));
305 void SVPRINTF(char *keyname, int keytype, const char *format,...) __attribute__((__format__(__printf__,3,4)));
306 void SVCALLBACK(char *keyname, WCHandlerFunc fcn_ptr);
307 void SVCallback(char *keyname, size_t keylen, WCHandlerFunc fcn_ptr);
308 #define svcallback(a, b) SVCallback(a, sizeof(a) - 1, b)
310 void SVPUTBuf(const char *keyname, int keylen, const StrBuf *Buf, int ref);
311 #define SVPutBuf(a, b, c); SVPUTBuf(a, sizeof(a) - 1, b, c)