bffa39d20a9bd1b9a9b02405b6ab8a4b8f841d0c
[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
33
34 typedef struct _TemplateParam {
35         const char *Start;
36         int Type;
37         long len;
38         long lvalue;
39 } TemplateParam;
40
41 /* make a template token a lookup key: */
42 #define TKEY(a) Tokens->Params[a]->Start, Tokens->Params[a]->len
43 typedef struct _TemplateToken {
44         const StrBuf *FileName; /* Reference to print error messages; not to be freed */
45         StrBuf *FlatToken;
46         long Line;
47         const char *pTokenStart;
48         size_t TokenStart;
49         size_t TokenEnd;
50         const char *pTokenEnd;
51         int Flags;
52         void *PreEval;
53
54         const char *pName;
55         size_t NameEnd;
56
57         int HaveParameters;
58         int nParameters;
59         TemplateParam *Params[MAXPARAM];
60 } WCTemplateToken;
61
62 typedef void (*WCHandlerFunc)();
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 #define CTX_NONE 0
78 #define CTX_SITECFG 1
79 #define CTX_SESSION 2
80 #define CTX_INETCFG 3
81 #define CTX_VNOTE 4
82 #define CTX_WHO 5
83 #define CTX_PREF 6
84 #define CTX_NODECONF 7
85 #define CTX_USERLIST 8
86 #define CTX_MAILSUM 9
87 #define CTX_MIME_ATACH 10
88 #define CTX_FILELIST 11
89 #define CTX_STRBUF 12
90 #define CTX_LONGVECTOR 13
91
92
93 void RegisterNS(const char *NSName, long len, 
94                 int nMinArgs, 
95                 int nMaxArgs, 
96                 WCHandlerFunc HandlerFunc,
97                 int ContextRequired);
98 #define RegisterNamespace(a, b, c, d, e) RegisterNS(a, sizeof(a)-1, b, c, d, e)
99
100 typedef int (*WCConditionalFunc)(WCTemplateToken *Token, void *Context, int ContextType);
101 typedef struct _ConditionalStruct {
102         const char *PlainName;
103         int nParams;
104         int ContextRequired;
105         WCConditionalFunc CondF;
106 } ConditionalStruct;
107 void RegisterConditional(const char *Name, long len, 
108                          int nParams,
109                          WCConditionalFunc CondF, 
110                          int ContextRequired);
111
112
113
114 typedef void (*SubTemplFunc)(StrBuf *TemplBuffer, void *Context, WCTemplateToken *Token);
115 typedef HashList *(*RetrieveHashlistFunc)(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType);
116 typedef void (*HashDestructorFunc) (HashList **KillMe);
117 void RegisterITERATOR(const char *Name, long len, /* Our identifier */
118                       int AdditionalParams,       /* doe we use more parameters? */
119                       HashList *StaticList,       /* pointer to webcit lifetime hashlists */
120                       RetrieveHashlistFunc GetHash, /* else retrieve the hashlist by calling this function */
121                       SubTemplFunc DoSubTempl,       /* call this function on each iteration for svput & friends */
122                       HashDestructorFunc Destructor, /* use this function to shut down the hash; NULL if its a reference */
123                       int ContextType,               /* which context do we provide to the subtemplate? */
124                       int XPectContextType,          /* which context do we expct to be called in? */
125                       int Flags);
126
127 #define IT_NOFLAG 0
128 #define IT_FLAG_DETECT_GROUPCHANGE (1<<0)
129
130 #define RegisterIterator(a, b, c, d, e, f, g, h, i) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f, g, h, i)
131
132 void GetTemplateTokenString(WCTemplateToken *Tokens,
133                             int N, 
134                             const char **Value, 
135                             long *len);
136
137
138 void SVPut(char *keyname, size_t keylen, int keytype, char *Data);
139 #define svput(a, b, c) SVPut(a, sizeof(a) - 1, b, c)
140 void SVPutLong(char *keyname, size_t keylen, long Data);
141 #define svputlong(a, b) SVPutLong(a, sizeof(a) - 1, b)
142 void svprintf(char *keyname, size_t keylen, int keytype, const char *format,...) __attribute__((__format__(__printf__,4,5)));
143 void SVPRINTF(char *keyname, int keytype, const char *format,...) __attribute__((__format__(__printf__,3,4)));
144 void SVCALLBACK(char *keyname, WCHandlerFunc fcn_ptr);
145 void SVCallback(char *keyname, size_t keylen,  WCHandlerFunc fcn_ptr);
146 #define svcallback(a, b) SVCallback(a, sizeof(a) - 1, b)
147
148 void SVPUTBuf(const char *keyname, int keylen, const StrBuf *Buf, int ref);
149 #define SVPutBuf(a, b, c); SVPUTBuf(a, sizeof(a) - 1, b, c)
150
151 void DoTemplate(const char *templatename, long len, StrBuf *Target, void *Context, int ContextType);
152 #define do_template(a, b) DoTemplate(a, sizeof(a) -1, NULL, b, 0);
153 void url_do_template(void);
154
155 int CompareSubstToToken(TemplateParam *ParamToCompare, TemplateParam *ParamToLookup);
156 int CompareSubstToStrBuf(StrBuf *Compare, TemplateParam *ParamToLookup);
157
158 void StrBufAppendTemplate(StrBuf *Target, 
159                           int nArgs, 
160                           WCTemplateToken *Tokens,
161                           void *Context, int ContextType,
162                           const StrBuf *Source, int FormatTypeIndex);
163 CompareFunc RetrieveSort(long ContextType, const char *OtherPrefix, 
164                          const char *Default, long ldefault, long DefaultDirection);
165 void RegisterSortFunc(const char *name, long len, 
166                       const char *prepend, long preplen,
167                       CompareFunc Forward, 
168                       CompareFunc Reverse, 
169                       CompareFunc GroupChange, 
170                       long ContextType);
171
172 void dbg_print_longvector(long *LongVector);