X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fsubst.c;h=7964ab4c2795f3481421da790a0acee9f743b687;hb=c19da2c87226fee57abdab376d09475cccb11fe5;hp=586f4f8c646df6b156107b9b25451c2892fed9e0;hpb=7ad28ef5f9698f8bc237937ea25e77739d5b208f;p=citadel.git diff --git a/webcit/subst.c b/webcit/subst.c index 586f4f8c6..7964ab4c2 100644 --- a/webcit/subst.c +++ b/webcit/subst.c @@ -679,6 +679,7 @@ void StrBufAppendTemplate(StrBuf *Target, char EscapeAs = ' '; if ((FormatTypeIndex < TP->Tokens->nParameters) && + (TP->Tokens->Params[FormatTypeIndex] != NULL) && (TP->Tokens->Params[FormatTypeIndex]->Type == TYPE_STR) && (TP->Tokens->Params[FormatTypeIndex]->len >= 1)) { pFmt = TP->Tokens->Params[FormatTypeIndex]->Start; @@ -1906,6 +1907,8 @@ const StrBuf *ProcessTemplate(WCTemplate *Tmpl, StrBuf *Target, WCTemplputParams } + +StrBuf *textPlainType; /** * \brief Display a variable-substituted template * \param templatename template file to load @@ -1932,23 +1935,28 @@ const StrBuf *DoTemplate(const char *templatename, long len, StrBuf *Target, WCT { syslog(LOG_WARNING, "Can't to load a template with empty name!\n"); StrBufAppendPrintf(Target, "
\nCan't to load a template with empty name!\n
"); - return NULL; + return textPlainType; } if (!GetHash(StaticLocal, templatename, len, &vTmpl) && !GetHash(Static, templatename, len, &vTmpl)) { - syslog(LOG_WARNING, "didn't find Template [%s] %ld %ld\n", templatename, len , (long)strlen(templatename)); + StrBuf *escapedString = NewStrBufPlain(NULL, len); + + StrHtmlEcmaEscAppend(escapedString, NULL, templatename, 1, 1); + syslog(LOG_WARNING, "didn't find Template [%s] %ld %ld\n", ChrPtr(escapedString), len , (long)strlen(templatename)); StrBufAppendPrintf(Target, "
\ndidn't find Template [%s] %ld %ld\n
", - templatename, len, + ChrPtr(escapedString), len, (long)strlen(templatename)); + WC->isFailure = 1; #if 0 dbg_PrintHash(Static, PrintTemplate, NULL); PrintHash(Static, VarPrintTransition, PrintTemplate); #endif - return NULL; + FreeStrBuf(&escapedString); + return textPlainType; } if (vTmpl == NULL) - return NULL; + return textPlainType; return ProcessTemplate(vTmpl, Target, TP); } @@ -1983,6 +1991,7 @@ typedef struct _HashIterator { RetrieveHashlistFunc GetHash; HashDestructorFunc Destructor; SubTemplFunc DoSubTemplate; + FilterByParamFunc Filter; } HashIterator; void RegisterITERATOR(const char *Name, long len, @@ -1991,6 +2000,7 @@ void RegisterITERATOR(const char *Name, long len, RetrieveHashlistFunc GetHash, SubTemplFunc DoSubTempl, HashDestructorFunc Destructor, + FilterByParamFunc Filter, CtxType ContextType, CtxType XPectContextType, int Flags) @@ -2004,6 +2014,7 @@ void RegisterITERATOR(const char *Name, long len, It->GetHash = GetHash; It->DoSubTemplate = DoSubTempl; It->Destructor = Destructor; + It->Filter = Filter; It->ContextType = ContextType; It->XPectContextType = XPectContextType; It->Flags = Flags; @@ -2157,6 +2168,13 @@ void tmpl_iterate_subtmpl(StrBuf *Target, WCTemplputParams *TP) } while (GetNextHashPos(List, it, &Status.KeyLen, &Status.Key, &vContext)) { if ((Status.n >= StartAt) && (Status.n <= StopAt)) { + + if ((It->Filter != NULL) && + It->Filter(Status.Key, Status.KeyLen, vContext, Target, TP)) + { + continue; + } + if (DetectGroupChange && Status.n > 0) { Status.GroupChange = SortBy->GroupChange(vContext, vLastContext); } @@ -2977,9 +2995,9 @@ void ServerStartModule_SUBST (void) { + textPlainType = NewStrBufPlain(HKEY("text/plain")); LocalTemplateCache = NewHash(1, NULL); TemplateCache = NewHash(1, NULL); - GlobalNS = NewHash(1, NULL); Iterators = NewHash(1, NULL); Conditionals = NewHash(1, NULL); @@ -3005,9 +3023,11 @@ void ServerShutdownModule_SUBST (void) { + FreeStrBuf(&textPlainType); + DeleteHash(&TemplateCache); DeleteHash(&LocalTemplateCache); - + DeleteHash(&GlobalNS); DeleteHash(&Iterators); DeleteHash(&Conditionals);