]> code.citadel.org Git - citadel.git/blobdiff - webcit/subst.c
* migrate message creation to templates (citing still missing)
[citadel.git] / webcit / subst.c
index 6ede4a74cbc9c9c93d713df2c268caef8d4c6417..690a21f7a8da58548b6b79125d73b0516027d3c6 100644 (file)
@@ -505,6 +505,14 @@ void print_value_of(StrBuf *Target, WCTemplateToken *Token, void *Context, int C
                        StrBufAppendPrintf(Target, "<pre>WARNING: \ninvalid value in SV-Hash at %s!\n</pre>", Token->pName);
                }
        }
+       else
+               lprintf(1, "didn't find Handler [%s] (in '%s' line %ld); "
+                       " [%s]\n", 
+                       Token->pName,
+                       ChrPtr(Token->FileName),
+                       Token->Line,
+                       ChrPtr(Token->FlatToken));
+
 }
 
 int CompareSubstToToken(TemplateParam *ParamToCompare, TemplateParam *ParamToLookup)
@@ -696,6 +704,7 @@ WCTemplateToken *NewTemplateSubstitute(StrBuf *Buf,
        TemplateParam *Param;
        WCTemplateToken *NewToken = (WCTemplateToken*)malloc(sizeof(WCTemplateToken));
 
+       NewToken->FileName = pTmpl->FileName; /* to print meaningfull log messages... */
        NewToken->Flags = 0;
        NewToken->Line = Line + 1;
        NewToken->pTokenStart = pTmplStart;
@@ -1312,6 +1321,7 @@ typedef struct _HashIterator {
        HashList *StaticList;
        int AdditionalParams;
        int ContextType;
+       int XPectContextType;
        RetrieveHashlistFunc GetHash;
        HashDestructorFunc Destructor;
        SubTemplFunc DoSubTemplate;
@@ -1333,16 +1343,18 @@ void tmpl_iterate_subtmpl(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, vo
                     Tokens->Params[0]->Start,
                     Tokens->Params[0]->len,
                     &vIt)) {
-               lprintf(1, "unknown Iterator [%s] (in line %ld); "
+               lprintf(1, "unknown Iterator [%s] (in '%s' line %ld); "
                        " [%s]\n", 
                        Tokens->Params[0]->Start,
+                       ChrPtr(Tokens->FileName),
                        Tokens->Line,
                        ChrPtr(Tokens->FlatToken));
                StrBufAppendPrintf(
                        Target,
-                       "<pre>\nunknown Iterator [%s] (in line %ld); \n"
+                       "<pre>\nunknown Iterator [%s] (in '%s' line %ld); \n"
                        " [%s]\n</pre>", 
                        Tokens->Params[0]->Start,
+                       ChrPtr(Tokens->FileName),
                        Tokens->Line,
                        ChrPtr(Tokens->FlatToken));
                return;
@@ -1351,25 +1363,54 @@ void tmpl_iterate_subtmpl(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, vo
        It = (HashIterator*) vIt;
 
        if (Tokens->nParameters < It->AdditionalParams + 2) {
-               lprintf(1, "Iterator [%s] (in line %ld); "
+               lprintf(1, "Iterator [%s] (in '%s' line %ld); "
                        "doesn't work with %ld params [%s]\n", 
                        Tokens->Params[0]->Start,
+                       ChrPtr(Tokens->FileName),
                        Tokens->Line,
                        Tokens->nParameters, 
                        ChrPtr(Tokens->FlatToken));
                StrBufAppendPrintf(
                        Target,
-                       "<pre>Iterator [%s] \n(in line %ld);\n"
+                       "<pre>Iterator [%s] \n(in '%s' line %ld);\n"
                        "doesn't work with %ld params \n[%s]\n</pre>", 
                        Tokens->Params[0]->Start,
+                       ChrPtr(Tokens->FileName),
                        Tokens->Line,
                        Tokens->nParameters, 
                        ChrPtr(Tokens->FlatToken));
                return;
        }
 
+       if ((It->XPectContextType != CTX_NONE) &&
+           (It->XPectContextType != ContextType)) {
+               lprintf(1, "Iterator [%s] (in '%s' line %ld); "
+                       "requires context of type %ld, have %ld [%s]\n", 
+                       Tokens->pName,
+                       ChrPtr(Tokens->FileName),
+                       Tokens->Line,
+                       It->XPectContextType, 
+                       ContextType,
+                       ChrPtr(Tokens->FlatToken));
+               StrBufAppendPrintf(
+                       Target, 
+                       "<pre>\nIterator [%s] (in '%s' line %ld);"
+                       " requires context of type %ld, have %ld!\n[%s]\n</pre>\n", 
+                       Tokens->pName,
+                       ChrPtr(Tokens->FileName),
+                       Tokens->Line,
+                       It->XPectContextType, 
+                       ContextType,
+                       ChrPtr(Tokens->FlatToken));
+               return ;
+               
+       }
+
+
+
+
        if (It->StaticList == NULL)
-               List = It->GetHash(Tokens);
+               List = It->GetHash(Target, nArgs, Tokens, Context, ContextType);
        else
                List = It->StaticList;
 
@@ -1443,7 +1484,8 @@ void RegisterITERATOR(const char *Name, long len,
                      RetrieveHashlistFunc GetHash, 
                      SubTemplFunc DoSubTempl,
                      HashDestructorFunc Destructor,
-                     int ContextType)
+                     int ContextType, 
+                     int XPectContextType)
 {
        HashIterator *It = (HashIterator*)malloc(sizeof(HashIterator));
        It->StaticList = StaticList;
@@ -1452,6 +1494,7 @@ void RegisterITERATOR(const char *Name, long len,
        It->DoSubTemplate = DoSubTempl;
        It->Destructor = Destructor;
        It->ContextType = ContextType;
+       It->XPectContextType = XPectContextType;
        Put(Iterators, Name, len, It, NULL);
 }