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