* temporarily disable parameter-checking. Conditionals don't contain enough informati...
[citadel.git] / webcit / subst.h
1
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;
9
10
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
19
20
21 /*
22  * \brief Values for wcs_type
23  */
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 */
31 };
32
33 typedef struct _contexts {
34         int ContextType;                /* do we require a context type? */
35         int ControlContextType;
36         int nMinArgs;
37         int nMaxArgs;
38 } ContextFilter;
39
40
41 typedef struct WCTemplateToken WCTemplateToken;
42 typedef struct WCTemplputParams WCTemplputParams;
43 typedef void (*WCHandlerFunc)(StrBuf *Target, WCTemplputParams *TP);
44
45 typedef struct _TemplateParam {
46         const char *Start;
47         int Type;
48         long len;
49         long lvalue;
50 } TemplateParam;
51
52 /* make a template token a lookup key: */
53 #define TKEY(a) TP->Tokens->Params[a]->Start, TP->Tokens->Params[a]->len
54 struct WCTemplateToken {
55         const StrBuf *FileName; /* Reference to print error messages; not to be freed */
56         StrBuf *FlatToken;
57         long Line;
58         const char *pTokenStart;
59         size_t TokenStart;
60         size_t TokenEnd;
61         const char *pTokenEnd;
62         int Flags;
63         void *PreEval;
64
65         const char *pName;
66         size_t NameEnd;
67
68         int HaveParameters;
69         int nParameters;
70         TemplateParam *Params[MAXPARAM];
71 };
72
73
74 /*
75  * \brief Dynamic content for variable substitution in templates
76  */
77 typedef struct _wcsubst {
78         ContextFilter Filter;
79         int wcs_type;                       /* which type of Substitution are we */
80         char wcs_key[32];                   /* copy of our hashkey for debugging */
81         StrBuf *wcs_value;                  /* if we're a string, keep it here */
82         long lvalue;                        /* type long? keep data here */
83         WCHandlerFunc wcs_function; /* funcion hook ???*/
84 } wcsubst;
85
86 struct WCTemplputParams {
87         ContextFilter Filter;
88         void *Context;
89         void *ControlContext;
90         int nArgs;
91         WCTemplateToken *Tokens;
92 };
93
94
95 extern WCTemplputParams NoCtx;
96
97 #define CTX TP->Context
98 #define CCTX TP->ControlContext
99
100
101
102 #define CTX_NONE 0
103 #define CTX_SITECFG 1
104 #define CTX_SESSION 2
105 #define CTX_INETCFG 3
106 #define CTX_VNOTE 4
107 #define CTX_WHO 5
108 #define CTX_PREF 6
109 #define CTX_NODECONF 7
110 #define CTX_USERLIST 8
111 #define CTX_MAILSUM 9
112 #define CTX_MIME_ATACH 10
113 #define CTX_FILELIST 11
114 #define CTX_STRBUF 12
115 #define CTX_LONGVECTOR 13
116 #define CTX_ROOMS 14
117 #define CTX_FLOORS 15
118 #define CTX_ITERATE 16
119
120 void RegisterNS(const char *NSName, long len, 
121                 int nMinArgs, 
122                 int nMaxArgs, 
123                 WCHandlerFunc HandlerFunc,
124                 int ContextRequired);
125 #define RegisterNamespace(a, b, c, d, e) RegisterNS(a, sizeof(a)-1, b, c, d, e)
126
127 typedef int (*WCConditionalFunc)(StrBuf *Target, WCTemplputParams *TP);
128 typedef struct _ConditionalStruct {
129         ContextFilter Filter;
130         const char *PlainName;
131         WCConditionalFunc CondF;
132 } ConditionalStruct;
133 void RegisterConditional(const char *Name, long len, 
134                          int nParams,
135                          WCConditionalFunc CondF, 
136                          int ContextRequired);
137
138
139
140 typedef void (*SubTemplFunc)(StrBuf *TemplBuffer, WCTemplputParams *TP);
141 typedef HashList *(*RetrieveHashlistFunc)(StrBuf *Target, WCTemplputParams *TP);
142 typedef void (*HashDestructorFunc) (HashList **KillMe);
143 void RegisterITERATOR(const char *Name, long len, /* Our identifier */
144                       int AdditionalParams,       /* doe we use more parameters? */
145                       HashList *StaticList,       /* pointer to webcit lifetime hashlists */
146                       RetrieveHashlistFunc GetHash, /* else retrieve the hashlist by calling this function */
147                       SubTemplFunc DoSubTempl,       /* call this function on each iteration for svput & friends */
148                       HashDestructorFunc Destructor, /* use this function to shut down the hash; NULL if its a reference */
149                       int ContextType,               /* which context do we provide to the subtemplate? */
150                       int XPectContextType,          /* which context do we expct to be called in? */
151                       int Flags);
152
153 #define IT_NOFLAG 0
154 #define IT_FLAG_DETECT_GROUPCHANGE (1<<0)
155
156 #define RegisterIterator(a, b, c, d, e, f, g, h, i) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f, g, h, i)
157
158 void GetTemplateTokenString(WCTemplputParams *TP,
159                             int N,
160                             const char **Value, 
161                             long *len);
162
163
164 void SVPut(char *keyname, size_t keylen, int keytype, char *Data);
165 #define svput(a, b, c) SVPut(a, sizeof(a) - 1, b, c)
166 void SVPutLong(char *keyname, size_t keylen, long Data);
167 #define svputlong(a, b) SVPutLong(a, sizeof(a) - 1, b)
168 void svprintf(char *keyname, size_t keylen, int keytype, const char *format,...) __attribute__((__format__(__printf__,4,5)));
169 void SVPRINTF(char *keyname, int keytype, const char *format,...) __attribute__((__format__(__printf__,3,4)));
170 void SVCALLBACK(char *keyname, WCHandlerFunc fcn_ptr);
171 void SVCallback(char *keyname, size_t keylen,  WCHandlerFunc fcn_ptr);
172 #define svcallback(a, b) SVCallback(a, sizeof(a) - 1, b)
173
174 void SVPUTBuf(const char *keyname, int keylen, const StrBuf *Buf, int ref);
175 #define SVPutBuf(a, b, c); SVPUTBuf(a, sizeof(a) - 1, b, c)
176
177 void DoTemplate(const char *templatename, long len, StrBuf *Target, WCTemplputParams *TP);
178 #define do_template(a, b) DoTemplate(a, sizeof(a) -1, NULL, &NoCtx);
179 void url_do_template(void);
180
181 int CompareSubstToToken(TemplateParam *ParamToCompare, TemplateParam *ParamToLookup);
182 int CompareSubstToStrBuf(StrBuf *Compare, TemplateParam *ParamToLookup);
183
184 void StrBufAppendTemplate(StrBuf *Target, 
185                           WCTemplputParams *TP,
186                           const StrBuf *Source, 
187                           int FormatTypeIndex);
188 CompareFunc RetrieveSort(WCTemplputParams *TP, 
189                          const char *OtherPrefix, long OtherPrefixLen,  
190                          const char *Default, long ldefault, 
191                          long DefaultDirection);
192 void RegisterSortFunc(const char *name, long len, 
193                       const char *prepend, long preplen,
194                       CompareFunc Forward, 
195                       CompareFunc Reverse, 
196                       CompareFunc GroupChange, 
197                       long ContextType);
198
199 void dbg_print_longvector(long *LongVector);
200
201
202 #define ERR_NAME 0
203 #define ERR_PARM1 1
204 #define ERR_PARM2 2
205 void LogTemplateError (StrBuf *Target, 
206                        const char *Type, 
207                        int ErrorPos, 
208                        WCTemplputParams *TP, 
209                        const char *Format, ...);