X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fsubst.c;h=dce5de89671ca107231b52381851085c20dd71a6;hb=a13d1d34c6f9bb9b2ffd448e177200151ce42e79;hp=bc6c747fab82040f1eb4895f3f86417d22324882;hpb=abc90f03433db7a011dd09c0a7e5323606965be4;p=citadel.git diff --git a/webcit/subst.c b/webcit/subst.c index bc6c747fa..dce5de896 100644 --- a/webcit/subst.c +++ b/webcit/subst.c @@ -18,8 +18,6 @@ extern char *static_dirs[PATH_MAX]; /* Disk representation */ -HashList *WirelessTemplateCache; -HashList *WirelessLocalTemplateCache; HashList *TemplateCache; HashList *LocalTemplateCache; @@ -159,7 +157,7 @@ void LogTemplateError (StrBuf *Target, const char *Type, int ErrorPos, WCTemplpu } if (TP->Tokens != NULL) { - lprintf(1, "%s [%s] (in '%s' line %ld); %s; [%s]\n", + syslog(1, "%s [%s] (in '%s' line %ld); %s; [%s]\n", Type, Err, ChrPtr(TP->Tokens->FileName), @@ -169,7 +167,7 @@ void LogTemplateError (StrBuf *Target, const char *Type, int ErrorPos, WCTemplpu } else { - lprintf(1, "%s: %s;\n", + syslog(1, "%s: %s;\n", Type, ChrPtr(Error)); } @@ -258,7 +256,7 @@ void LogError (StrBuf *Target, const char *Type, const char *Format, ...) StrBufVAppendPrintf(Error, Format, arg_ptr); va_end(arg_ptr); - lprintf(1, ChrPtr(Error)); + syslog(1, ChrPtr(Error)); WCC = WC; if (WCC->WFBuf == NULL) WCC->WFBuf = NewStrBuf(); @@ -529,7 +527,7 @@ void GetTemplateTokenString(StrBuf *Target, *Value = ChrPtr(Buf); *len = StrLength(Buf); /* we can't free it here, so we put it into the subst so its discarded later on. */ - ///SVPUTBuf(TKEY(N), Buf, 0); + PutRequestLocalMem(Buf, HFreeStrBuf); break; default: @@ -767,7 +765,7 @@ int GetNextParameter(StrBuf *Buf, } pche = pch; if (*pch != quote) { - lprintf(1, "Error (in '%s' line %ld); " + syslog(1, "Error (in '%s' line %ld); " "evaluating template param [%s] in Token [%s]\n", ChrPtr(pTmpl->FileName), Tokens->Line, @@ -781,7 +779,7 @@ int GetNextParameter(StrBuf *Buf, else { StrBufPeek(Buf, pch, -1, '\0'); if (LoadTemplates > 1) { - lprintf(1, "DBG: got param [%s] %ld %ld\n", + syslog(1, "DBG: got param [%s] %ld %ld\n", pchs, pche - pchs, strlen(pchs)); } Parm->Start = pchs; @@ -811,7 +809,7 @@ int GetNextParameter(StrBuf *Buf, else { Parm->lvalue = 0; /* TODO whUT? - lprintf(1, "Error (in '%s' line %ld); " + syslog(1, "Error (in '%s' line %ld); " "evaluating long template param [%s] in Token [%s]\n", ChrPtr(pTmpl->FileName), Tokens->Line, @@ -1211,13 +1209,13 @@ void *load_template(WCTemplate *NewTemplate) fd = open(ChrPtr(NewTemplate->FileName), O_RDONLY); if (fd <= 0) { - lprintf(1, "ERROR: could not open template '%s' - %s\n", + syslog(1, "ERROR: could not open template '%s' - %s\n", ChrPtr(NewTemplate->FileName), strerror(errno)); return NULL; } if (fstat(fd, &statbuf) == -1) { - lprintf(1, "ERROR: could not stat template '%s' - %s\n", + syslog(1, "ERROR: could not stat template '%s' - %s\n", ChrPtr(NewTemplate->FileName), strerror(errno)); return NULL; } @@ -1225,7 +1223,7 @@ void *load_template(WCTemplate *NewTemplate) NewTemplate->Data = NewStrBufPlain(NULL, statbuf.st_size + 1); if (StrBufReadBLOB(NewTemplate->Data, &fd, 1, statbuf.st_size, &Err) < 0) { close(fd); - lprintf(1, "ERROR: reading template '%s' - %s
\n", + syslog(1, "ERROR: reading template '%s' - %s
\n", ChrPtr(NewTemplate->FileName), strerror(errno)); //FreeWCTemplate(NewTemplate);/////tODO return NULL; @@ -1241,6 +1239,7 @@ void *load_template(WCTemplate *NewTemplate) const char *pts, *pte; int InQuotes = 0; int InDoubleQuotes = 0; + void *pv; /** Find one */ pos = (-1); @@ -1272,9 +1271,11 @@ void *load_template(WCTemplate *NewTemplate) if (pch + 1 > pE) continue; pte = pch; - PutNewToken(NewTemplate, - NewTemplateSubstitute(NewTemplate->Data, pS, pts, pte, Line, NewTemplate)); - pch ++; + pv = NewTemplateSubstitute(NewTemplate->Data, pS, pts, pte, Line, NewTemplate); + if (pv != NULL) { + PutNewToken(NewTemplate, pv); + pch ++; + } } return NewTemplate; } @@ -1288,7 +1289,7 @@ const char* PrintTemplate(void *vSubst) } -int LoadTemplateDir(const StrBuf *DirName, HashList *wireless, HashList *big, const StrBuf *BaseKey) +int LoadTemplateDir(const StrBuf *DirName, HashList *big, const StrBuf *BaseKey) { int Toplevel; StrBuf *FileName; @@ -1301,7 +1302,6 @@ int LoadTemplateDir(const StrBuf *DirName, HashList *wireless, HashList *big, co int d_type = 0; int d_namelen; int d_without_ext; - int IsMobile; d = (struct dirent *)malloc(offsetof(struct dirent, d_name) + PATH_MAX + 1); if (d == NULL) { @@ -1385,7 +1385,7 @@ int LoadTemplateDir(const StrBuf *DirName, HashList *wireless, HashList *big, co StrBufAppendBufPlain(SubDirectory, HKEY("/"), 0); StrBufAppendBufPlain(SubDirectory, filedir_entry->d_name, d_namelen, 0); - LoadTemplateDir(SubDirectory, wireless, big, SubKey); + LoadTemplateDir(SubDirectory, big, SubKey); break; case DT_LNK: /* TODO: check whether its a file or a directory */ @@ -1400,11 +1400,6 @@ int LoadTemplateDir(const StrBuf *DirName, HashList *wireless, HashList *big, co (strcmp(&filedir_entry->d_name[d_without_ext], ".orig") == 0) || (strcmp(&filedir_entry->d_name[d_without_ext], ".swp") == 0)) continue; /* Ignore backup files... */ - /* .m.xxx is for mobile useragents! */ - IsMobile = 0; - if (d_without_ext > 2) - IsMobile = (filedir_entry->d_name[d_without_ext - 1] == 'm') && - (filedir_entry->d_name[d_without_ext - 2] == '.'); PStart = filedir_entry->d_name; StrBufPrintf(FileName, "%s/%s", ChrPtr(DirName), filedir_entry->d_name); MinorPtr = strchr(filedir_entry->d_name, '.'); @@ -1419,8 +1414,8 @@ int LoadTemplateDir(const StrBuf *DirName, HashList *wireless, HashList *big, co StrBufAppendBufPlain(Key, filedir_entry->d_name, MinorPtr - filedir_entry->d_name, 0); if (LoadTemplates >= 1) - lprintf(1, "%s %d %s\n", ChrPtr(FileName), IsMobile, ChrPtr(Key)); - prepare_template(FileName, Key, (IsMobile)?wireless:big); + syslog(1, "%s %s\n", ChrPtr(FileName), ChrPtr(Key)); + prepare_template(FileName, Key, big); default: break; } @@ -1439,7 +1434,7 @@ void InitTemplateCache(void) int i; StrBuf *Key; StrBuf *Dir; - HashList *Templates[4]; + HashList *Templates[2]; Dir = NewStrBuf(); Key = NewStrBuf(); @@ -1447,14 +1442,12 @@ void InitTemplateCache(void) /* Primary Template set... */ StrBufPrintf(Dir, "%s/t", static_dirs[0]); LoadTemplateDir(Dir, - WirelessTemplateCache, TemplateCache, Key); /* User local Template set */ StrBufPrintf(Dir, "%s/t", static_dirs[1]); LoadTemplateDir(Dir, - WirelessLocalTemplateCache, LocalTemplateCache, Key); @@ -1462,17 +1455,14 @@ void InitTemplateCache(void) StrBufPrintf(Dir, "%s/dbg", static_dirs[0]); LoadTemplateDir(Dir, - WirelessTemplateCache, TemplateCache, Key); - Templates[0] = WirelessTemplateCache; - Templates[1] = TemplateCache; - Templates[2] = WirelessLocalTemplateCache; - Templates[3] = LocalTemplateCache; + Templates[0] = TemplateCache; + Templates[1] = LocalTemplateCache; if (LoadTemplates == 0) - for (i=0; i < 4; i++) { + for (i=0; i < 2; i++) { const char *Key; long KLen; HashPos *At; @@ -1518,7 +1508,7 @@ int EvaluateToken(StrBuf *Target, int state, WCTemplputParams *TP) void *vVar; /* much output, since pName is not terminated... - lprintf(1,"Doing token: %s\n",Token->pName); + syslog(1,"Doing token: %s\n",Token->pName); */ switch (TP->Tokens->Flags) { @@ -1602,7 +1592,7 @@ const StrBuf *ProcessTemplate(WCTemplate *Tmpl, StrBuf *Target, WCTemplputParams if (LoadTemplates != 0) { if (LoadTemplates > 1) - lprintf(1, "DBG: ----- loading: [%s] ------ \n", + syslog(1, "DBG: ----- loading: [%s] ------ \n", ChrPtr(Tmpl->FileName)); pTmpl = duplicate_template(Tmpl); if(load_template(pTmpl) == NULL) { @@ -1681,25 +1671,19 @@ const StrBuf *DoTemplate(const char *templatename, long len, StrBuf *Target, WCT TP = &LocalTP; } - if (WC->is_mobile > 0) { - Static = WirelessTemplateCache; - StaticLocal = WirelessLocalTemplateCache; - } - else { - Static = TemplateCache; - StaticLocal = LocalTemplateCache; - } + Static = TemplateCache; + StaticLocal = LocalTemplateCache; if (len == 0) { - lprintf (1, "Can't to load a template with empty name!\n"); + syslog(1, "Can't to load a template with empty name!\n"); StrBufAppendPrintf(Target, "
\nCan't to load a template with empty name!\n
"); return NULL; } if (!GetHash(StaticLocal, templatename, len, &vTmpl) && !GetHash(Static, templatename, len, &vTmpl)) { - lprintf (1, "didn't find Template [%s] %ld %ld\n", templatename, len , (long)strlen(templatename)); + syslog(1, "didn't find Template [%s] %ld %ld\n", templatename, len , (long)strlen(templatename)); StrBufAppendPrintf(Target, "
\ndidn't find Template [%s] %ld %ld\n
", templatename, len, (long)strlen(templatename)); @@ -1995,6 +1979,8 @@ int conditional_ITERATE_LASTN(StrBuf *Target, WCTemplputParams *TP) int EvaluateConditional(StrBuf *Target, int Neg, int state, WCTemplputParams *TP) { ConditionalStruct *Cond; + int rc = 0; + int res; if ((TP->Tokens->Params[0]->len == 1) && (TP->Tokens->Params[0]->Start[0] == 'X')) @@ -2011,10 +1997,14 @@ int EvaluateConditional(StrBuf *Target, int Neg, int state, WCTemplputParams *TP if (!CheckContext(Target, &Cond->Filter, TP, "Conditional")) { return 0; } - - if (Cond->CondF(Target, TP) == Neg) - return TP->Tokens->Params[1]->lvalue; - return 0; + res = Cond->CondF(Target, TP); + if (res == Neg) + rc = TP->Tokens->Params[1]->lvalue; + if (LoadTemplates > 5) + syslog(1, "<%s> : %d %d==%d\n", + ChrPtr(TP->Tokens->FlatToken), + rc, res, Neg); + return rc; } void RegisterConditional(const char *Name, long len, @@ -2343,7 +2333,7 @@ void RegisterSortFunc(const char *name, long len, NewSort->GroupChange = GroupChange; NewSort->ContextType = ContextType; if (ContextType == CTX_NONE) { - lprintf(1, "sorting requires a context. CTX_NONE won't make it.\n"); + syslog(1, "sorting requires a context. CTX_NONE won't make it.\n"); exit(1); } @@ -2639,7 +2629,7 @@ void dbg_print_longvector(long *LongVector) StrBufAppendPrintf(Buf, "%d: %ld]\n", i, LongVector[i]); } - lprintf(1, ChrPtr(Buf)); + syslog(1, ChrPtr(Buf)); FreeStrBuf(&Buf); } @@ -2733,8 +2723,6 @@ void ServerStartModule_SUBST (void) { - WirelessTemplateCache = NewHash(1, NULL); - WirelessLocalTemplateCache = NewHash(1, NULL); LocalTemplateCache = NewHash(1, NULL); TemplateCache = NewHash(1, NULL); @@ -2756,8 +2744,6 @@ void ServerShutdownModule_SUBST (void) { - DeleteHash(&WirelessTemplateCache); - DeleteHash(&WirelessLocalTemplateCache); DeleteHash(&TemplateCache); DeleteHash(&LocalTemplateCache);