]> code.citadel.org Git - citadel.git/blobdiff - webcit/subst.h
* temporarily disable parameter-checking. Conditionals don't contain enough informati...
[citadel.git] / webcit / subst.h
index bffa39d20a9bd1b9a9b02405b6ab8a4b8f841d0c..1d66e496661d631b8ef1273b455f03f71fb69b2e 100644 (file)
@@ -14,6 +14,7 @@ extern HashList *LocalTemplateCache;
 #define TYPE_PREFINT 4
 #define TYPE_GETTEXT 5
 #define TYPE_BSTR 6
+#define TYPE_SUBTEMPLATE 7
 #define MAXPARAM  20
 
 
@@ -29,8 +30,18 @@ enum {
        WCS_LONG          /* its an integer */
 };
 
+typedef struct _contexts {
+       int ContextType;                /* do we require a context type? */
+       int ControlContextType;
+       int nMinArgs;
+       int nMaxArgs;
+} ContextFilter;
 
 
+typedef struct WCTemplateToken WCTemplateToken;
+typedef struct WCTemplputParams WCTemplputParams;
+typedef void (*WCHandlerFunc)(StrBuf *Target, WCTemplputParams *TP);
+
 typedef struct _TemplateParam {
        const char *Start;
        int Type;
@@ -39,8 +50,8 @@ typedef struct _TemplateParam {
 } TemplateParam;
 
 /* make a template token a lookup key: */
-#define TKEY(a) Tokens->Params[a]->Start, Tokens->Params[a]->len
-typedef struct _TemplateToken {
+#define TKEY(a) TP->Tokens->Params[a]->Start, TP->Tokens->Params[a]->len
+struct WCTemplateToken {
        const StrBuf *FileName; /* Reference to print error messages; not to be freed */
        StrBuf *FlatToken;
        long Line;
@@ -57,23 +68,37 @@ typedef struct _TemplateToken {
        int HaveParameters;
        int nParameters;
        TemplateParam *Params[MAXPARAM];
-} WCTemplateToken;
-
-typedef void (*WCHandlerFunc)();
+};
 
 
 /*
  * \brief Dynamic content for variable substitution in templates
  */
 typedef struct _wcsubst {
+       ContextFilter Filter;
        int wcs_type;                       /* which type of Substitution are we */
        char wcs_key[32];                   /* copy of our hashkey for debugging */
        StrBuf *wcs_value;                  /* if we're a string, keep it here */
        long lvalue;                        /* type long? keep data here */
-       int ContextRequired;                /* do we require a context type? */
        WCHandlerFunc wcs_function; /* funcion hook ???*/
 } wcsubst;
 
+struct WCTemplputParams {
+       ContextFilter Filter;
+       void *Context;
+       void *ControlContext;
+       int nArgs;
+       WCTemplateToken *Tokens;
+};
+
+
+extern WCTemplputParams NoCtx;
+
+#define CTX TP->Context
+#define CCTX TP->ControlContext
+
+
+
 #define CTX_NONE 0
 #define CTX_SITECFG 1
 #define CTX_SESSION 2
@@ -88,7 +113,9 @@ typedef struct _wcsubst {
 #define CTX_FILELIST 11
 #define CTX_STRBUF 12
 #define CTX_LONGVECTOR 13
-
+#define CTX_ROOMS 14
+#define CTX_FLOORS 15
+#define CTX_ITERATE 16
 
 void RegisterNS(const char *NSName, long len, 
                int nMinArgs, 
@@ -97,11 +124,10 @@ void RegisterNS(const char *NSName, long len,
                int ContextRequired);
 #define RegisterNamespace(a, b, c, d, e) RegisterNS(a, sizeof(a)-1, b, c, d, e)
 
-typedef int (*WCConditionalFunc)(WCTemplateToken *Token, void *Context, int ContextType);
+typedef int (*WCConditionalFunc)(StrBuf *Target, WCTemplputParams *TP);
 typedef struct _ConditionalStruct {
+       ContextFilter Filter;
        const char *PlainName;
-       int nParams;
-       int ContextRequired;
        WCConditionalFunc CondF;
 } ConditionalStruct;
 void RegisterConditional(const char *Name, long len, 
@@ -111,8 +137,8 @@ void RegisterConditional(const char *Name, long len,
 
 
 
-typedef void (*SubTemplFunc)(StrBuf *TemplBuffer, void *Context, WCTemplateToken *Token);
-typedef HashList *(*RetrieveHashlistFunc)(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType);
+typedef void (*SubTemplFunc)(StrBuf *TemplBuffer, WCTemplputParams *TP);
+typedef HashList *(*RetrieveHashlistFunc)(StrBuf *Target, WCTemplputParams *TP);
 typedef void (*HashDestructorFunc) (HashList **KillMe);
 void RegisterITERATOR(const char *Name, long len, /* Our identifier */
                      int AdditionalParams,       /* doe we use more parameters? */
@@ -129,8 +155,8 @@ void RegisterITERATOR(const char *Name, long len, /* Our identifier */
 
 #define RegisterIterator(a, b, c, d, e, f, g, h, i) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f, g, h, i)
 
-void GetTemplateTokenString(WCTemplateToken *Tokens,
-                           int N, 
+void GetTemplateTokenString(WCTemplputParams *TP,
+                           int N,
                            const char **Value, 
                            long *len);
 
@@ -148,20 +174,21 @@ void SVCallback(char *keyname, size_t keylen,  WCHandlerFunc fcn_ptr);
 void SVPUTBuf(const char *keyname, int keylen, const StrBuf *Buf, int ref);
 #define SVPutBuf(a, b, c); SVPUTBuf(a, sizeof(a) - 1, b, c)
 
-void DoTemplate(const char *templatename, long len, StrBuf *Target, void *Context, int ContextType);
-#define do_template(a, b) DoTemplate(a, sizeof(a) -1, NULL, b, 0);
+void DoTemplate(const char *templatename, long len, StrBuf *Target, WCTemplputParams *TP);
+#define do_template(a, b) DoTemplate(a, sizeof(a) -1, NULL, &NoCtx);
 void url_do_template(void);
 
 int CompareSubstToToken(TemplateParam *ParamToCompare, TemplateParam *ParamToLookup);
 int CompareSubstToStrBuf(StrBuf *Compare, TemplateParam *ParamToLookup);
 
 void StrBufAppendTemplate(StrBuf *Target, 
-                         int nArgs, 
-                         WCTemplateToken *Tokens,
-                         void *Context, int ContextType,
-                         const StrBuf *Source, int FormatTypeIndex);
-CompareFunc RetrieveSort(long ContextType, const char *OtherPrefix, 
-                        const char *Default, long ldefault, long DefaultDirection);
+                         WCTemplputParams *TP,
+                         const StrBuf *Source, 
+                         int FormatTypeIndex);
+CompareFunc RetrieveSort(WCTemplputParams *TP, 
+                        const char *OtherPrefix, long OtherPrefixLen,  
+                        const char *Default, long ldefault, 
+                        long DefaultDirection);
 void RegisterSortFunc(const char *name, long len, 
                      const char *prepend, long preplen,
                      CompareFunc Forward, 
@@ -170,3 +197,13 @@ void RegisterSortFunc(const char *name, long len,
                      long ContextType);
 
 void dbg_print_longvector(long *LongVector);
+
+
+#define ERR_NAME 0
+#define ERR_PARM1 1
+#define ERR_PARM2 2
+void LogTemplateError (StrBuf *Target, 
+                      const char *Type, 
+                      int ErrorPos, 
+                      WCTemplputParams *TP, 
+                      const char *Format, ...);