From 3f3310ae5f3e42f714550f26e167ffea11005083 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Mon, 8 Sep 2008 12:23:13 +0000 Subject: [PATCH] * HAIL MELD! * reduce log noise while running from the console with debug binaries; output_static will be as quiet as sslg too. * add Filename and a copy of the whole token so we can output it in case of errors * adjusted all error lprintfs in subst.c to deliver file, line, and a matching snippet of the token analyzed so the logfile helps finding bugs in templates. * templated siteconfig allmost finished. --- webcit/context_loop.c | 1 + webcit/siteconfig.c | 14 ++- webcit/static/t/display_sitewide_config.html | 10 +- webcit/static/t/tab_siteconfig_access.html | 48 ++++---- .../static/t/tab_siteconfig_autopurger.html | 16 +-- webcit/static/t/tab_siteconfig_directory.html | 18 +-- webcit/static/t/tab_siteconfig_general.html | 26 ++--- webcit/static/t/tab_siteconfig_indexing.html | 48 +++----- webcit/static/t/tab_siteconfig_network.html | 59 ++++------ webcit/static/t/tab_siteconfig_pop3.html | 14 +-- webcit/static/t/tab_siteconfig_pushmail.html | 19 +--- webcit/static/t/tab_siteconfig_tuning.html | 28 ++--- webcit/subst.c | 105 ++++++++++++------ webcit/webcit.c | 2 + webcit/webcit.h | 2 + 15 files changed, 185 insertions(+), 225 deletions(-) diff --git a/webcit/context_loop.c b/webcit/context_loop.c index 45113cbc5..e505b5465 100644 --- a/webcit/context_loop.c +++ b/webcit/context_loop.c @@ -390,6 +390,7 @@ void context_loop(int *sock) /** Begin parsing the request. */ #ifdef TECH_PREVIEW if ((strncmp(req->line+4, "/sslg", 5) != 0) && + (strncmp(req->line+4, "/static/", 8) != 0) && (strncmp(req->line+4, "/wholist_section", 16) != 0)) { #endif lprintf(5, "HTTP: %s\n", buf); diff --git a/webcit/siteconfig.c b/webcit/siteconfig.c index 5e42ae5a2..bfcdc81d4 100644 --- a/webcit/siteconfig.c +++ b/webcit/siteconfig.c @@ -1008,15 +1008,17 @@ int ConditionalServCfg(WCTemplateToken *Tokens, void *Context) if (WCC->ServCfg == NULL) load_siteconfig(); GetHash(WCC->ServCfg, - Tokens->Params[0]->Start, - Tokens->Params[0]->len, + Tokens->Params[2]->Start, + Tokens->Params[2]->len, &vBuf); if (vBuf == NULL) return 0; Buf = (StrBuf*) vBuf; - if (Tokens->nParameters == 1) + if (Tokens->nParameters == 3) { return 1; - else - return (strcmp(Tokens->Params[0]->Start, ChrPtr(Buf)) == 0); + } + else if (Tokens->Params[3]->Type == TYPE_STR) + return (strcmp(Tokens->Params[3]->Start, ChrPtr(Buf)) == 0); + else return (StrTol(Buf) == Tokens->Params[3]->lvalue); } else return 0; } @@ -1029,6 +1031,6 @@ InitModule_SITECONFIG WebcitAddUrlHandler(HKEY("siteconfig"), siteconfig, 0); RegisterNamespace("SERV:CFG", 1, 1, tmplput_servcfg); - RegisterConditional(HKEY("COND:SERVCFG"), 1, ConditionalServCfg); + RegisterConditional(HKEY("COND:SERVCFG"), 3, ConditionalServCfg); } /*@}*/ diff --git a/webcit/static/t/display_sitewide_config.html b/webcit/static/t/display_sitewide_config.html index e2bf7a013..97e23d76f 100644 --- a/webcit/static/t/display_sitewide_config.html +++ b/webcit/static/t/display_sitewide_config.html @@ -1,12 +1,11 @@ - - - +
+
+ "subject_pop3", "tab_siteconfig_pop3", + "", "submit_siteconfig")> +
+
diff --git a/webcit/static/t/tab_siteconfig_access.html b/webcit/static/t/tab_siteconfig_access.html index 56168f8b8..8ae89d657 100644 --- a/webcit/static/t/tab_siteconfig_access.html +++ b/webcit/static/t/tab_siteconfig_access.html @@ -2,9 +2,7 @@ +'> + - +> - +> + +> - + + +> +> - + + +
-'> - -
-
-> -
-> -
- -
-> -
- -
-
-> -
-> -
'> + + + + + +
- -
- -
diff --git a/webcit/static/t/tab_siteconfig_autopurger.html b/webcit/static/t/tab_siteconfig_autopurger.html index ee3030733..f49152f6f 100644 --- a/webcit/static/t/tab_siteconfig_autopurger.html +++ b/webcit/static/t/tab_siteconfig_autopurger.html @@ -16,14 +16,13 @@ ); } --> - - - + + +
- - - + + >
@@ -36,7 +35,7 @@ -
+
> @@ -55,5 +54,6 @@ -
+
+ diff --git a/webcit/static/t/tab_siteconfig_directory.html b/webcit/static/t/tab_siteconfig_directory.html index 5cec44eab..05b40c627 100644 --- a/webcit/static/t/tab_siteconfig_directory.html +++ b/webcit/static/t/tab_siteconfig_directory.html @@ -8,28 +8,20 @@ + - + - + - + +
- -
- -
- -
- -
- -
diff --git a/webcit/static/t/tab_siteconfig_general.html b/webcit/static/t/tab_siteconfig_general.html index 51bc4dab4..b7bd2f1a4 100644 --- a/webcit/static/t/tab_siteconfig_general.html +++ b/webcit/static/t/tab_siteconfig_general.html @@ -6,39 +6,31 @@ - - - - - + + - - + - - + - - + - - + - - + - - + + diff --git a/webcit/static/t/tab_siteconfig_indexing.html b/webcit/static/t/tab_siteconfig_indexing.html index 0c1c0bb18..6f75f28d1 100644 --- a/webcit/static/t/tab_siteconfig_indexing.html +++ b/webcit/static/t/tab_siteconfig_indexing.html @@ -1,41 +1,23 @@
-

+

+

+ + + - + + + + + + - - - - - - - - - - - - - - -
+>
- -
+>
+>
+
- -
- -
- -
- -
- -
- -
-> -
diff --git a/webcit/static/t/tab_siteconfig_network.html b/webcit/static/t/tab_siteconfig_network.html index 0fa04ad5f..4380663b2 100644 --- a/webcit/static/t/tab_siteconfig_network.html +++ b/webcit/static/t/tab_siteconfig_network.html @@ -4,75 +4,54 @@ - - - + +> + + - + - + + + +> +> - + + +'> - +> - + + + +
- -
+
-> -
- -
- -
- -
- -
- -
- -
-> -
- -
() - -
- -
-'> -
-> -
- -
- -
diff --git a/webcit/static/t/tab_siteconfig_pop3.html b/webcit/static/t/tab_siteconfig_pop3.html index 0e18b256c..7d29add81 100644 --- a/webcit/static/t/tab_siteconfig_pop3.html +++ b/webcit/static/t/tab_siteconfig_pop3.html @@ -4,19 +4,15 @@ + + - + + +
- -
- -
- -
- -
diff --git a/webcit/static/t/tab_siteconfig_pushmail.html b/webcit/static/t/tab_siteconfig_pushmail.html index 972cbd862..d7ed93f88 100644 --- a/webcit/static/t/tab_siteconfig_pushmail.html +++ b/webcit/static/t/tab_siteconfig_pushmail.html @@ -4,25 +4,18 @@ - + - + - + + + +
- -
- -
- -
- -
- -
diff --git a/webcit/static/t/tab_siteconfig_tuning.html b/webcit/static/t/tab_siteconfig_tuning.html index 3ecfe664b..10021333b 100644 --- a/webcit/static/t/tab_siteconfig_tuning.html +++ b/webcit/static/t/tab_siteconfig_tuning.html @@ -2,39 +2,27 @@ + - + - + + - + - + + +>
- -
- -
- -
- -
- -
- -
- -
-> -
diff --git a/webcit/subst.c b/webcit/subst.c index 4716c8fb9..9d483ba17 100644 --- a/webcit/subst.c +++ b/webcit/subst.c @@ -493,7 +493,7 @@ void PutNewToken(WCTemplate *Template, WCTemplateToken *NewToken) Template->Tokens[(Template->nTokensUsed)++] = NewToken; } -TemplateParam *GetNextParameter(StrBuf *Buf, const char **pCh, const char *pe) +TemplateParam *GetNextParameter(StrBuf *Buf, const char **pCh, const char *pe, WCTemplateToken *Token, WCTemplate *pTmpl) { const char *pch = *pCh; const char *pchs, *pche; @@ -521,14 +521,22 @@ TemplateParam *GetNextParameter(StrBuf *Buf, const char **pCh, const char *pe) } pche = pch; if (*pch != quote) { - lprintf(1, "Error evaluating template param [%s]\n", *pCh); + lprintf(1, "Error (in '%s' line %ld); " + "evaluating template param [%s] in Token [%s]\n", + ChrPtr(pTmpl->FileName), + Token->Line, + ChrPtr(Token->FlatToken), + *pCh); pch ++; free(Parm); return NULL; } else { StrBufPeek(Buf, pch, -1, '\0'); - lprintf(1, "DBG: got param [%s] %ld %ld\n", pchs, pche - pchs, strlen(pchs)); + if (LoadTemplates > 1) { + lprintf(1, "DBG: got param [%s] %ld %ld\n", + pchs, pche - pchs, strlen(pchs)); + } Parm->Start = pchs; Parm->len = pche - pchs; pch ++; /* move after trailing quote */ @@ -551,7 +559,12 @@ TemplateParam *GetNextParameter(StrBuf *Buf, const char **pCh, const char *pe) } else { Parm->lvalue = 0; - lprintf(1, "Error evaluating template long param [%s]\n", *pCh); + lprintf(1, "Error (in '%s' line %ld); " + "evaluating long template param [%s] in Token [%s]\n", + ChrPtr(pTmpl->FileName), + Token->Line, + ChrPtr(Token->FlatToken), + *pCh); free(Parm); return NULL; } @@ -569,18 +582,22 @@ TemplateParam *GetNextParameter(StrBuf *Buf, const char **pCh, const char *pe) WCTemplateToken *NewTemplateSubstitute(StrBuf *Buf, const char *pStart, const char *pTmplStart, - const char *pTmplEnd) + const char *pTmplEnd, + long Line, + WCTemplate *pTmpl) { const char *pch; TemplateParam *Param; WCTemplateToken *NewToken = (WCTemplateToken*)malloc(sizeof(WCTemplateToken)); NewToken->Flags = 0; + NewToken->Line = Line + 1; NewToken->pTokenStart = pTmplStart; NewToken->TokenStart = pTmplStart - pStart; NewToken->TokenEnd = (pTmplEnd - pStart) - NewToken->TokenStart; NewToken->pTokenEnd = pTmplEnd; NewToken->NameEnd = NewToken->TokenEnd - 2; + NewToken->FlatToken = NewStrBufPlain(pTmplStart, pTmplEnd - pTmplStart); StrBufPeek(Buf, pTmplStart, + 1, '\0'); StrBufPeek(Buf, pTmplEnd, -1, '\0'); @@ -595,7 +612,7 @@ WCTemplateToken *NewTemplateSubstitute(StrBuf *Buf, NewToken->NameEnd = pch - NewToken->pName; pch ++; while (pch < pTmplEnd - 1) { - Param = GetNextParameter(Buf, &pch, pTmplEnd - 1); + Param = GetNextParameter(Buf, &pch, pTmplEnd - 1, NewToken, pTmpl); if (Param != NULL) { NewToken->HaveParameters = 1; if (NewToken->nParameters > MAXPARAM) { @@ -636,6 +653,7 @@ WCTemplateToken *NewTemplateSubstitute(StrBuf *Buf, void FreeToken(WCTemplateToken **Token) { int i; + FreeStrBuf(&(*Token)->FlatToken); if ((*Token)->HaveParameters) for (i = 0; i < (*Token)->nParameters; i++) free((*Token)->Params[i]); @@ -662,7 +680,7 @@ void FreeWCTemplate(void *vFreeMe) } -int EvaluateConditional(WCTemplateToken *Token, void *Context, int Neg, int state) +int EvaluateConditional(WCTemplateToken *Token, WCTemplate *pTmpl, void *Context, int Neg, int state) { void *vConditional; ConditionalStruct *Cond; @@ -675,21 +693,30 @@ int EvaluateConditional(WCTemplateToken *Token, void *Context, int Neg, int stat Token->Params[0]->Start, Token->Params[0]->len, &vConditional)) { - lprintf(1, "Conditional %s Not found!\n", - Token->Params[0]->Start); + lprintf(1, "Conditional [%s] (in '%s' line %ld); Not found![%s]\n", + Token->Params[0]->Start, + ChrPtr(pTmpl->FileName), + Token->Line, + ChrPtr(Token->FlatToken)); } Cond = (ConditionalStruct *) vConditional; if (Cond == NULL) { - lprintf(1, "Conditional %s Not found!\n", - Token->Params[0]->Start); + lprintf(1, "Conditional [%s] (in '%s' line %ld); Not found![%s]\n", + Token->Params[0]->Start, + ChrPtr(pTmpl->FileName), + Token->Line, + ChrPtr(Token->FlatToken)); return 0; } if (Token->nParameters < Cond->nParams) { - lprintf(1, "Conditional [%s] needs %ld Params!\n", + lprintf(1, "Conditional [%s] (in '%s' line %ld); needs %ld Params![%s]\n", Token->Params[0]->Start, - Cond->nParams); + ChrPtr(pTmpl->FileName), + Token->Line, + Cond->nParams, + ChrPtr(Token->FlatToken)); return 0; } if (Cond->CondF(Token, Context) == Neg) @@ -697,7 +724,7 @@ int EvaluateConditional(WCTemplateToken *Token, void *Context, int Neg, int stat return 0; } -int EvaluateToken(StrBuf *Target, WCTemplateToken *Token, void *Context, int state) +int EvaluateToken(StrBuf *Target, WCTemplateToken *Token, WCTemplate *pTmpl, void *Context, int state) { void *vVar; // much output, since pName is not terminated... @@ -707,22 +734,22 @@ int EvaluateToken(StrBuf *Target, WCTemplateToken *Token, void *Context, int sta TmplGettext(Target, Token->nParameters, Token); break; case SV_CONDITIONAL: /** Forward conditional evaluation */ - return EvaluateConditional(Token, Context, 1, state); + return EvaluateConditional(Token, pTmpl, Context, 1, state); break; case SV_NEG_CONDITIONAL: /** Reverse conditional evaluation */ - return EvaluateConditional(Token, Context, 0, state); + return EvaluateConditional(Token, pTmpl, Context, 0, state); break; case SV_CUST_STR_CONDITIONAL: /** Conditional put custom strings from params */ - if (Token->nParameters >= 7) { - if (EvaluateConditional(Token, Context, 0, state)) + if (Token->nParameters >= 6) { + if (EvaluateConditional(Token, pTmpl, Context, 0, state)) StrBufAppendBufPlain(Target, Token->Params[5]->Start, Token->Params[5]->len, 0); else StrBufAppendBufPlain(Target, - Token->Params[6]->Start, - Token->Params[6]->len, + Token->Params[4]->Start, + Token->Params[4]->len, 0); } break; @@ -765,7 +792,9 @@ void ProcessTemplate(WCTemplate *Tmpl, StrBuf *Target, void *Context) long len; if (LoadTemplates != 0) { - lprintf(1, "DBG: ----- loading: [%s] ------ \n", ChrPtr(Tmpl->FileName)); + if (LoadTemplates > 1) + lprintf(1, "DBG: ----- loading: [%s] ------ \n", + ChrPtr(Tmpl->FileName)); pTmpl = load_template(Tmpl->FileName, NULL, NULL); } @@ -784,13 +813,14 @@ void ProcessTemplate(WCTemplate *Tmpl, StrBuf *Target, void *Context) StrBufAppendBufPlain( Target, pData, pTmpl->Tokens[i]->pTokenStart - pData, 0); - state = EvaluateToken(Target, pTmpl->Tokens[i], Context, state); + state = EvaluateToken(Target, pTmpl->Tokens[i], pTmpl, Context, state); while ((state != 0) && (i+1 < pTmpl->nTokensUsed)) { /* condition told us to skip till its end condition */ i++; if ((pTmpl->Tokens[i]->Flags == SV_CONDITIONAL) || (pTmpl->Tokens[i]->Flags == SV_NEG_CONDITIONAL)) { if (state == EvaluateConditional(pTmpl->Tokens[i], + pTmpl, Context, pTmpl->Tokens[i]->Flags, state)) @@ -835,6 +865,7 @@ void *load_template(StrBuf *filename, StrBuf *Key, HashList *PutThere) int fd; struct stat statbuf; const char *pS, *pE, *pch, *Err; + long Line; int pos; WCTemplate *NewTemplate; @@ -853,7 +884,7 @@ void *load_template(StrBuf *filename, StrBuf *Key, HashList *PutThere) NewTemplate = (WCTemplate *) malloc(sizeof(WCTemplate)); NewTemplate->Data = NewStrBufPlain(NULL, statbuf.st_size); - NewTemplate->FileName = NULL; + NewTemplate->FileName = NewStrBufDup(filename); NewTemplate->nTokensUsed = 0; NewTemplate->TokenSpace = 0; NewTemplate->Tokens = NULL; @@ -866,6 +897,7 @@ void *load_template(StrBuf *filename, StrBuf *Key, HashList *PutThere) } close(fd); + Line = 0; pS = pch = ChrPtr(NewTemplate->Data); pE = pS + StrLength(NewTemplate->Data); while (pch < pE) { @@ -876,6 +908,7 @@ void *load_template(StrBuf *filename, StrBuf *Key, HashList *PutThere) for (; pch < pE; pch ++) { if ((*pch=='<')&&(*(pch + 1)=='?')) break; + if (*pch=='\n') Line ++; } if (pch >= pE) continue; @@ -895,7 +928,7 @@ void *load_template(StrBuf *filename, StrBuf *Key, HashList *PutThere) continue; pte = pch; PutNewToken(NewTemplate, - NewTemplateSubstitute(NewTemplate->Data, pS, pts, pte)); + NewTemplateSubstitute(NewTemplate->Data, pS, pts, pte, Line, NewTemplate)); pch ++; } if (LoadTemplates == 0) @@ -1189,28 +1222,34 @@ void tmpl_do_boxed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Con void tmpl_do_tabbed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context) { StrBuf **TabNames; - int i, ntabs; + int i, ntabs, nTabs; - ntabs = Tokens->nParameters / 2; + nTabs = ntabs = Tokens->nParameters / 2; TabNames = (StrBuf **) malloc(ntabs * sizeof(StrBuf*)); for (i = 0; i < ntabs; i++) { TabNames[i] = NewStrBuf(); - DoTemplate(Tokens->Params[i * 2]->Start, - Tokens->Params[i * 2]->len, - Context, - TabNames[i]); + if (Tokens->Params[i * 2]->len > 0) { + DoTemplate(Tokens->Params[i * 2]->Start, + Tokens->Params[i * 2]->len, + Context, + TabNames[i]); + } + else { + /** A Tab without subject? we can't count that, add it as silent */ + nTabs --; + } } - StrTabbedDialog(Target, ntabs, TabNames); + StrTabbedDialog(Target, nTabs, TabNames); for (i = 0; i < ntabs; i++) { - StrBeginTab(Target, ntabs, i); + StrBeginTab(Target, i, nTabs); DoTemplate(Tokens->Params[i * 2 + 1]->Start, Tokens->Params[i * 2 + 1]->len, Context, Target); - StrEndTab(Target, ntabs, i); + StrEndTab(Target, i, nTabs); } } diff --git a/webcit/webcit.c b/webcit/webcit.c index 34a66f315..bf8fd1f32 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -857,7 +857,9 @@ void output_static(char *what) close(fd); +#ifndef TECH_PREVIEW lprintf(9, "output_static('%s') %s\n", what, content_type); +#endif http_transmit_thing(content_type, 1); } if (yesbstr("force_close_session")) { diff --git a/webcit/webcit.h b/webcit/webcit.h index 2d0f29f8b..d91c24210 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -283,6 +283,8 @@ typedef struct _TemplateParam { } TemplateParam; typedef struct _TemplateToken { + StrBuf *FlatToken; + long Line; const char *pTokenStart; size_t TokenStart; size_t TokenEnd; -- 2.30.2