X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fsubst.c;h=6e5ab6fc690248e63532ddf0408ae3c8bfff4cac;hb=715008dfb6283528fcac64dc21b88dcbb237abad;hp=54a59a425487e7ec8c45c9a5997dfb5c367fc922;hpb=d8ffbdf6d717dc1f2ffa82920cefc1a3048b07bc;p=citadel.git diff --git a/webcit/subst.c b/webcit/subst.c index 54a59a425..6e5ab6fc6 100644 --- a/webcit/subst.c +++ b/webcit/subst.c @@ -71,7 +71,7 @@ typedef struct _HashHandler { WCHandlerFunc HandlerFunc; }HashHandler; -void *load_template(WCTemplate *NewTemplate); +void *load_template(StrBuf *Target, WCTemplate *NewTemplate); int EvaluateConditional(StrBuf *Target, int Neg, int state, WCTemplputParams *TP); @@ -111,6 +111,8 @@ const char *CtxNames[] = { "Context VCARD", "Context SIEVE List", "Context SIEVE Script", + "Context MailQ-Item", + "Context MailQ-Recipient", "Context UNKNOWN" }; @@ -758,8 +760,10 @@ int GetNextParameter(StrBuf *Buf, else { StrBufPeek(Buf, pch, -1, '\0'); if (LoadTemplates > 1) { - syslog(1, "DBG: got param [%s] %ld %ld\n", - pchs, pche - pchs, strlen(pchs)); + syslog(1, + "DBG: got param [%s] %d %d\n", + pchs, pche - pchs, strlen(pchs) + ); } Parm->Start = pchs; Parm->len = pche - pchs; @@ -1193,11 +1197,57 @@ void *duplicate_template(WCTemplate *OldTemplate) return NewTemplate; } + +void SanityCheckTemplate(StrBuf *Target, WCTemplate *CheckMe) +{ + int i = 0; + int j; + int FoundConditionalEnd; + + for (i = 0; i < CheckMe->nTokensUsed; i++) + { + switch(CheckMe->Tokens[i]->Flags) + { + case SV_CONDITIONAL: + case SV_NEG_CONDITIONAL: + FoundConditionalEnd = 0; + if ((CheckMe->Tokens[i]->Params[0]->len == 1) && + (CheckMe->Tokens[i]->Params[0]->Start[0] == 'X')) + break; + for (j = i + 1; j < CheckMe->nTokensUsed; j++) + { + if (((CheckMe->Tokens[j]->Flags == SV_CONDITIONAL) || + (CheckMe->Tokens[j]->Flags == SV_NEG_CONDITIONAL)) && + (CheckMe->Tokens[i]->Params[1]->lvalue == + CheckMe->Tokens[j]->Params[1]->lvalue)) + { + FoundConditionalEnd = 1; + break; + } + + } + if (!FoundConditionalEnd) + { + WCTemplputParams TP; + memset(&TP, 0, sizeof(WCTemplputParams)); + TP.Tokens = CheckMe->Tokens[i]; + LogTemplateError( + Target, "Token", ERR_PARM1, &TP, + "Conditional without Endconditional" + ); + } + break; + default: + break; + } + } +} + /** * \brief Display a variable-substituted template * \param templatename template file to load */ -void *load_template(WCTemplate *NewTemplate) +void *load_template(StrBuf *Target, WCTemplate *NewTemplate) { int fd; struct stat statbuf; @@ -1233,8 +1283,7 @@ void *load_template(WCTemplate *NewTemplate) pE = pS + StrLength(NewTemplate->Data); while (pch < pE) { const char *pts, *pte; - int InQuotes = 0; - int InDoubleQuotes = 0; + char InQuotes = '\0'; void *pv; /** Find one */ @@ -1253,13 +1302,24 @@ void *load_template(WCTemplate *NewTemplate) /** Found one? parse it. */ for (; pch <= pE - 1; pch ++) { - if (*pch == '"') - InDoubleQuotes = ! InDoubleQuotes; - else if (*pch == '\'') - InQuotes = ! InQuotes; - else if ((!InQuotes && !InDoubleQuotes) && - ((*pch!='\\')&&(*(pch + 1)=='>'))) { - pch ++; + if ((!InQuotes) && + ((*pch == '\'') || (*pch == '"'))) + { + InQuotes = *pch; + } + else if (InQuotes && (InQuotes == *pch)) + { + InQuotes = '\0'; + } + else if ((InQuotes) && + (*pch == '\\') && + (*(pch + 1) == InQuotes)) + { + pch++; + } + else if ((!InQuotes) && + (*pch == '>')) + { break; } } @@ -1272,6 +1332,8 @@ void *load_template(WCTemplate *NewTemplate) pch ++; } } + + SanityCheckTemplate(NULL, NewTemplate); return NewTemplate; } @@ -1470,7 +1532,7 @@ void InitTemplateCache(void) &vTemplate) && (vTemplate != NULL)) { - load_template((WCTemplate *)vTemplate); + load_template(NULL, (WCTemplate *)vTemplate); } DeleteHashPos(&At); } @@ -1589,7 +1651,7 @@ const StrBuf *ProcessTemplate(WCTemplate *Tmpl, StrBuf *Target, WCTemplputParams syslog(1, "DBG: ----- loading: [%s] ------ \n", ChrPtr(Tmpl->FileName)); pTmpl = duplicate_template(Tmpl); - if(load_template(pTmpl) == NULL) { + if(load_template(Target, pTmpl) == NULL) { StrBufAppendPrintf( Target, "
\nError loading Template [%s]\n See Logfile for details\n
\n",