Back to index

webcit  8.12-dfsg
subst.h
Go to the documentation of this file.
00001 
00005 extern HashList *Conditionals;
00006 extern HashList *GlobalNS;
00007 extern HashList *Iterators;
00008 extern HashList *WirelessTemplateCache;
00009 extern HashList *WirelessLocalTemplateCache;
00010 extern HashList *TemplateCache;
00011 extern HashList *LocalTemplateCache;
00012 
00013 
00014 #define TYPE_STR   1
00015 #define TYPE_LONG  2
00016 #define TYPE_PREFSTR 3
00017 #define TYPE_PREFINT 4
00018 #define TYPE_GETTEXT 5
00019 #define TYPE_BSTR 6
00020 #define TYPE_SUBTEMPLATE 7
00021 #define TYPE_INTDEFINE 8
00022 #define MAXPARAM  25
00023 
00024 #define IS_NUMBER(a) ((a == TYPE_LONG) || (a == TYPE_PREFINT) || (a == TYPE_INTDEFINE))
00025 
00026 /*
00027  * \brief Values for wcs_type
00028  */
00029 enum {
00030        WCS_STRING,       /* its a string */
00031        WCS_FUNCTION,     /* its a function callback */
00032        WCS_SERVCMD,      /* its a command to send to the citadel server */
00033        WCS_STRBUF,       /* its a strbuf we own */
00034        WCS_STRBUF_REF,   /* its a strbuf we mustn't free */
00035        WCS_LONG          /* its an integer */
00036 };
00037 
00038 #define CTX TP->Context
00039 #define CCTX TP->ControlContext
00040 
00041 #define CTX_NONE 0
00042 #define CTX_SITECFG 1
00043 #define CTX_SESSION 2
00044 #define CTX_INETCFG 3
00045 #define CTX_VNOTE 4
00046 #define CTX_WHO 5
00047 #define CTX_PREF 6
00048 #define CTX_NODECONF 7
00049 #define CTX_USERLIST 8
00050 #define CTX_MAILSUM 9
00051 #define CTX_MIME_ATACH 10
00052 #define CTX_FILELIST 11
00053 #define CTX_STRBUF 12
00054 #define CTX_STRBUFARR 13
00055 #define CTX_LONGVECTOR 14
00056 #define CTX_ROOMS 15
00057 #define CTX_FLOORS 16
00058 #define CTX_ITERATE 17
00059 #define CTX_ICAL 18
00060 #define CTX_DAVNS 19
00061 #define CTX_TAB 20
00062 #define CTX_VCARD 21
00063 #define CTX_SIEVELIST 22
00064 #define CTX_SIEVESCRIPT 23
00065 #define CTX_MAILQITEM 24
00066 #define CTX_MAILQ_RCPT 25
00067 #define CTX_SRVLOG 26
00068 
00069 #define CTX_UNKNOWN 27
00070 
00071 
00079 typedef struct _contexts {
00080        int ContextType;                /* do we require a User Context ? */
00081        int ControlContextType;         /* are we inside of a control structure? */
00082        int nMinArgs;                   /* How many arguments do we need at least? */
00083        int nMaxArgs;                   /* up to how many arguments can we handle? */
00084 } ContextFilter;
00085 
00086 
00087 /* Forward declarations... */
00088 typedef struct WCTemplateToken WCTemplateToken;
00089 typedef struct WCTemplputParams WCTemplputParams;
00090 
00091 /* this is the signature of a tmplput function */
00092 typedef void (*WCHandlerFunc)(StrBuf *Target, WCTemplputParams *TP);
00093 
00094 /* if you want to pre-evaluate parts of your token, or do additional syntax, use this. */ 
00095 typedef int (*WCPreevalFunc)(WCTemplateToken *Token);
00096 
00097 /* make a template token a lookup key: */
00098 #define TKEY(a) TP->Tokens->Params[a]->Start, TP->Tokens->Params[a]->len
00099 
00105 typedef int (*WCConditionalFunc)(StrBuf *Target, WCTemplputParams *TP);
00106 
00107 typedef enum _eBitMask {
00108        eNO = 0,
00109        eOR,
00110        eAND
00111 }eBitMask;
00112 
00113 typedef struct _TemplateParam {
00114         /* are we a string or a number? */
00115        int Type;
00116        /* string data: */
00117        const char *Start;
00118        long len;
00119        /* if we're a number: */
00120        long lvalue;
00121        eBitMask MaskBy;
00122 } TemplateParam;
00123 
00124 
00129 struct WCTemplateToken {
00130         /* Reference to the filename we're in to print error messages; not to be freed */
00131        const StrBuf *FileName; 
00132        /* Raw copy of our original token; for error printing */
00133        StrBuf *FlatToken;
00134        /* Which line did the template parser pick us up in? For error printing */
00135        long Line;
00136 
00137        /* our position in the template cache buffer */
00138        const char *pTokenStart;
00139        /* our token length */
00140        size_t TokenStart;
00141        size_t TokenEnd;
00142        /* point after us */
00143        const char *pTokenEnd;
00144        /* just our token name: */
00145        const char *pName;
00146        size_t NameEnd;
00147 
00148        /* stuff the pre-evaluater finds out: */
00149        int Flags;
00150        /* pointer to our runntime evaluator; so we can cache this and save hash-lookups */
00151        void *PreEval;
00152        void *Preeval2;
00153 
00154        /* if we have parameters here we go: */
00155        /* do we have parameters or not? */
00156        int HaveParameters;
00157        /* How many of them? */
00158        int nParameters;
00159        /* the parameters */
00160        TemplateParam *Params[MAXPARAM];
00161 };
00162 
00163 
00164 
00165 struct WCTemplputParams {
00166        ContextFilter Filter;
00167        void *Context;
00168        void *ControlContext;
00169        int nArgs;
00170        WCTemplateToken *Tokens;
00171 };
00172 
00173 
00174 
00175 typedef struct _ConditionalStruct {
00176        ContextFilter Filter;
00177        const char *PlainName;
00178        WCConditionalFunc CondF;
00179 } ConditionalStruct;
00180 
00181 
00182 typedef void (*SubTemplFunc)(StrBuf *TemplBuffer, WCTemplputParams *TP);
00183 typedef HashList *(*RetrieveHashlistFunc)(StrBuf *Target, WCTemplputParams *TP);
00184 typedef void (*HashDestructorFunc) (HashList **KillMe);
00185 
00186 
00187 extern WCTemplputParams NoCtx;
00188 
00189 #define HAVE_PARAM(a) (TP->Tokens->nParameters > a)
00190 
00191 
00192 #define ERR_NAME 0
00193 #define ERR_PARM1 1
00194 #define ERR_PARM2 2
00195 
00203 void LogTemplateError (StrBuf *Target, 
00204                      const char *Type, 
00205                      int ErrorPos, 
00206                      WCTemplputParams *TP, 
00207                      const char *Format, ...)__attribute__((__format__(__printf__,5,6)));
00208 
00209 
00217 void LogError (StrBuf *Target, const char *Type, const char *Format, ...);
00218 
00233 void GetTemplateTokenString(StrBuf *Target, 
00234                          WCTemplputParams *TP,
00235                          int N,
00236                          const char **Value, 
00237                          long *len);
00242 int HaveTemplateTokenString(StrBuf *Target, 
00243                          WCTemplputParams *TP,
00244                          int N,
00245                          const char **Value, 
00246                          long *len);
00247 
00248 
00249 
00264 long GetTemplateTokenNumber(StrBuf *Target, 
00265                          WCTemplputParams *TP, 
00266                          int N, long dflt);
00267 
00281 void StrBufAppendTemplate(StrBuf *Target, 
00282                        WCTemplputParams *TP,
00283                        const StrBuf *Source, 
00284                        int FormatTypeIndex);
00285 
00286 
00287 #define RegisterNamespace(a, b, c, d, e, f) RegisterNS(a, sizeof(a)-1, b, c, d, e, f)
00288 
00299 void RegisterNS(const char *NSName, long len, 
00300               int nMinArgs, 
00301               int nMaxArgs, 
00302               WCHandlerFunc HandlerFunc,
00303               WCPreevalFunc PreEvalFunc,
00304               int ContextRequired);
00305 
00317 void RegisterConditional(const char *Name, long len, 
00318                       int nParams,
00319                       WCConditionalFunc CondF, 
00320                       int ContextRequired);
00321 
00332 void RegisterTokenParamDefine(const char *Name, long len, 
00333                            long Value);
00337 #define REGISTERTokenParamDefine(a) RegisterTokenParamDefine(#a, sizeof(#a) - 1, a);
00338 
00346 long GetTokenDefine(const char *Name, 
00347                   long len, 
00348                   long DefValue);
00349 
00350 
00351 #define IT_NOFLAG 0
00352 #define IT_FLAG_DETECT_GROUPCHANGE (1<<0)
00353 #define RegisterIterator(a, b, c, d, e, f, g, h, i) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f, g, h, i)
00354 void RegisterITERATOR(const char *Name, long len, /* Our identifier */
00355                     int AdditionalParams,       /* doe we use more parameters? */
00356                     HashList *StaticList,       /* pointer to webcit lifetime hashlists */
00357                     RetrieveHashlistFunc GetHash, /* else retrieve the hashlist by calling this function */
00358                     SubTemplFunc DoSubTempl,       /* call this function on each iteration for svput & friends */
00359                     HashDestructorFunc Destructor, /* use this function to shut down the hash; NULL if its a reference */
00360                     int ContextType,               /* which context do we provide to the subtemplate? */
00361                     int XPectContextType,          /* which context do we expct to be called in? */
00362                     int Flags);
00363 
00364 
00365 
00366 
00367 
00368 
00369 CompareFunc RetrieveSort(WCTemplputParams *TP, 
00370                       const char *OtherPrefix, long OtherPrefixLen,  
00371                       const char *Default, long ldefault, 
00372                       long DefaultDirection);
00373 void RegisterSortFunc(const char *name, long len, 
00374                     const char *prepend, long preplen,
00375                     CompareFunc Forward, 
00376                     CompareFunc Reverse, 
00377                     CompareFunc GroupChange, 
00378                     long ContextType);
00379 
00380 void dbg_print_longvector(long *LongVector);
00381 
00382 #define do_template(a) DoTemplate(a, sizeof(a) -1, NULL, &NoCtx)
00383 const StrBuf *DoTemplate(const char *templatename, long len, StrBuf *Target, WCTemplputParams *TP);
00384 void url_do_template(void);
00385 
00386 
00387 int CompareSubstToToken(TemplateParam *ParamToCompare, TemplateParam *ParamToLookup);
00388 int CompareSubstToStrBuf(StrBuf *Compare, TemplateParam *ParamToLookup);