* Reduced iconbar button size to 90% because it looked obtuse on a smaller screen
[citadel.git] / webcit / subst.h
bloba45dfb2582e08f61cac3ffaa4cde23490df3641b
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;
11 #define TYPE_STR 1
12 #define TYPE_LONG 2
13 #define TYPE_PREFSTR 3
14 #define TYPE_PREFINT 4
15 #define TYPE_GETTEXT 5
16 #define TYPE_BSTR 6
17 #define TYPE_SUBTEMPLATE 7
18 #define MAXPARAM 20
22 * \brief Values for wcs_type
24 enum {
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
36 #define CTX_NONE 0
37 #define CTX_SITECFG 1
38 #define CTX_SESSION 2
39 #define CTX_INETCFG 3
40 #define CTX_VNOTE 4
41 #define CTX_WHO 5
42 #define CTX_PREF 6
43 #define CTX_NODECONF 7
44 #define CTX_USERLIST 8
45 #define CTX_MAILSUM 9
46 #define CTX_MIME_ATACH 10
47 #define CTX_FILELIST 11
48 #define CTX_STRBUF 12
49 #define CTX_LONGVECTOR 13
50 #define CTX_ROOMS 14
51 #define CTX_FLOORS 15
52 #define CTX_ITERATE 16
54 #define CTX_UNKNOWN 17
57 /**
58 * ContextFilter resembles our RTTI information. With this structure
59 * we can make shure a tmplput function can live with the environment
60 * we call it in.
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? */
68 } ContextFilter;
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
81 /**
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? */
90 int Type;
91 /* string data: */
92 const char *Start;
93 long len;
94 /* if we're a number: */
95 long lvalue;
96 } TemplateParam;
99 /**
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 */
106 StrBuf *FlatToken;
107 /* Which line did the template parser pick us up in? For error printing */
108 long Line;
110 /* our position in the template cache buffer */
111 const char *pTokenStart;
112 /* our token length */
113 size_t TokenStart;
114 size_t TokenEnd;
115 /* point after us */
116 const char *pTokenEnd;
117 /* just our token name: */
118 const char *pName;
119 size_t NameEnd;
121 /* stuff the pre-evaluater finds out: */
122 int Flags;
123 /* pointer to our runntime evaluator; so we can cache this and save hash-lookups */
124 void *PreEval;
126 /* if we have parameters here we go: */
127 /* do we have parameters or not? */
128 int HaveParameters;
129 /* How many of them? */
130 int nParameters;
131 /* the parameters */
132 TemplateParam *Params[MAXPARAM];
137 struct WCTemplputParams {
138 ContextFilter Filter;
139 void *Context;
140 void *ControlContext;
141 int nArgs;
142 WCTemplateToken *Tokens;
147 typedef struct _ConditionalStruct {
148 ContextFilter Filter;
149 const char *PlainName;
150 WCConditionalFunc CondF;
151 } ConditionalStruct;
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)
164 #define ERR_NAME 0
165 #define ERR_PARM1 1
166 #define ERR_PARM2 2
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,
175 const char *Type,
176 int ErrorPos,
177 WCTemplputParams *TP,
178 const char *Format, ...)__attribute__((__format__(__printf__,5,6)));
182 * \Brief log an error while in global context; print it to Wildfire / Target
183 * \param Target your Target Buffer to print the error message next to the log
184 * \param Type What sort of thing are we talking about? Tokens? Conditionals?
185 * \param Format for the custom error message
187 void LogError (StrBuf *Target, const char *Type, const char *Format, ...);
190 * \Brief get the actual value of a token parameter
191 * in your tmplputs or conditionals use this function to access parameters that can also be
192 * retrieved from dynamic facilities:
193 * _ -> Gettext; retrieve this token from the i18n facilities
194 * : -> lookup a setting of that name
195 * B -> bstr; an URL-Parameter
196 * = -> subtemplate; parse a template by this name, and treat its content as this tokens value
198 * \param N which token do you want to lookup?
199 * \param Value reference to the string of the token; don't free me.
200 * \param len the length of Value
202 void GetTemplateTokenString(StrBuf *Target,
203 WCTemplputParams *TP,
204 int N,
205 const char **Value,
206 long *len);
211 * \Brief get the actual integer value of a token parameter
212 * in your tmplputs or conditionals use this function to access parameters that can also be
213 * retrieved from dynamic facilities:
214 * _ -> Gettext; retrieve this token from the i18n facilities
215 * : -> lookup a setting of that name
216 * B -> bstr; an URL-Parameter
217 * = -> subtemplate; parse a template by this name, and treat its content as this tokens value
219 * \param N which token do you want to lookup?
220 * \param dflt default value to be retrieved if not found in preferences
221 * \returns the long value
223 long GetTemplateTokenNumber(StrBuf *Target,
224 WCTemplputParams *TP,
225 int N, long dflt);
228 * \Brief put a token value into the template
229 * use this function to append your strings into a Template.
230 * it can escape your string according to the token at FormattypeIndex:
231 * H: de-QP and utf8-ify
232 * X: escapize for HTML
233 * J: JSON Escapize
234 * \param Target the destination buffer
235 * \param TP the template token information
236 * \param Source string to append
237 * \param FormatTypeIndex which parameter contains the escaping functionality?
238 * if this token doesn't have as much parameters, plain append is done.
240 void StrBufAppendTemplate(StrBuf *Target,
241 WCTemplputParams *TP,
242 const StrBuf *Source,
243 int FormatTypeIndex);
246 #define RegisterNamespace(a, b, c, d, e) RegisterNS(a, sizeof(a)-1, b, c, d, e)
247 void RegisterNS(const char *NSName, long len,
248 int nMinArgs,
249 int nMaxArgs,
250 WCHandlerFunc HandlerFunc,
251 int ContextRequired);
253 void RegisterConditional(const char *Name, long len,
254 int nParams,
255 WCConditionalFunc CondF,
256 int ContextRequired);
260 #define IT_NOFLAG 0
261 #define IT_FLAG_DETECT_GROUPCHANGE (1<<0)
262 #define RegisterIterator(a, b, c, d, e, f, g, h, i) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f, g, h, i)
263 void RegisterITERATOR(const char *Name, long len, /* Our identifier */
264 int AdditionalParams, /* doe we use more parameters? */
265 HashList *StaticList, /* pointer to webcit lifetime hashlists */
266 RetrieveHashlistFunc GetHash, /* else retrieve the hashlist by calling this function */
267 SubTemplFunc DoSubTempl, /* call this function on each iteration for svput & friends */
268 HashDestructorFunc Destructor, /* use this function to shut down the hash; NULL if its a reference */
269 int ContextType, /* which context do we provide to the subtemplate? */
270 int XPectContextType, /* which context do we expct to be called in? */
271 int Flags);
278 CompareFunc RetrieveSort(WCTemplputParams *TP,
279 const char *OtherPrefix, long OtherPrefixLen,
280 const char *Default, long ldefault,
281 long DefaultDirection);
282 void RegisterSortFunc(const char *name, long len,
283 const char *prepend, long preplen,
284 CompareFunc Forward,
285 CompareFunc Reverse,
286 CompareFunc GroupChange,
287 long ContextType);
292 void dbg_print_longvector(long *LongVector);
298 #define do_template(a, b) DoTemplate(a, sizeof(a) -1, NULL, &NoCtx);
299 const StrBuf *DoTemplate(const char *templatename, long len, StrBuf *Target, WCTemplputParams *TP);
300 void url_do_template(void);
306 int CompareSubstToToken(TemplateParam *ParamToCompare, TemplateParam *ParamToLookup);
307 int CompareSubstToStrBuf(StrBuf *Compare, TemplateParam *ParamToLookup);
309 void SVPut(char *keyname, size_t keylen, int keytype, char *Data);
310 #define svput(a, b, c) SVPut(a, sizeof(a) - 1, b, c)
311 void SVPutLong(char *keyname, size_t keylen, long Data);
312 #define svputlong(a, b) SVPutLong(a, sizeof(a) - 1, b)
313 void svprintf(char *keyname, size_t keylen, int keytype, const char *format,...) __attribute__((__format__(__printf__,4,5)));
314 void SVPRINTF(char *keyname, int keytype, const char *format,...) __attribute__((__format__(__printf__,3,4)));
315 void SVCALLBACK(char *keyname, WCHandlerFunc fcn_ptr);
316 void SVCallback(char *keyname, size_t keylen, WCHandlerFunc fcn_ptr);
317 #define svcallback(a, b) SVCallback(a, sizeof(a) - 1, b)
319 void SVPUTBuf(const char *keyname, int keylen, const StrBuf *Buf, int ref);
320 #define SVPutBuf(a, b, c); SVPUTBuf(a, sizeof(a) - 1, b, c)