From 836c829b448402fabc06b420bd878583a725f608 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Tue, 12 Aug 2008 21:56:39 +0000 Subject: [PATCH] * move templates to static/t/ ; made make install target respect this * load templates on webcit start into memory --- webcit/Makefile.in | 4 +- webcit/static/{ => t}/beginbox.html | 0 webcit/static/{ => t}/beginbox.m.html | 0 webcit/static/{ => t}/beginbox_nt.html | 0 webcit/static/{ => t}/chatframeset.html | 0 webcit/static/{ => t}/endbox.html | 0 webcit/static/{ => t}/endbox.m.html | 0 webcit/static/{ => t}/head.html | 0 webcit/static/{ => t}/head.m.html | 0 webcit/static/{ => t}/msgcontrols.m.html | 0 webcit/static/{ => t}/newstartpage.html | 0 webcit/static/{ => t}/openid_login.html | 0 .../static/{ => t}/openid_manual_create.html | 0 webcit/static/{ => t}/pushemail.html | 0 webcit/static/{ => t}/roombanner.html | 0 webcit/static/{ => t}/roombanner.m.html | 0 webcit/subst.c | 114 ++++++++++++------ webcit/webserver.c | 2 + 18 files changed, 82 insertions(+), 38 deletions(-) rename webcit/static/{ => t}/beginbox.html (100%) rename webcit/static/{ => t}/beginbox.m.html (100%) rename webcit/static/{ => t}/beginbox_nt.html (100%) rename webcit/static/{ => t}/chatframeset.html (100%) rename webcit/static/{ => t}/endbox.html (100%) rename webcit/static/{ => t}/endbox.m.html (100%) rename webcit/static/{ => t}/head.html (100%) rename webcit/static/{ => t}/head.m.html (100%) rename webcit/static/{ => t}/msgcontrols.m.html (100%) rename webcit/static/{ => t}/newstartpage.html (100%) rename webcit/static/{ => t}/openid_login.html (100%) rename webcit/static/{ => t}/openid_manual_create.html (100%) rename webcit/static/{ => t}/pushemail.html (100%) rename webcit/static/{ => t}/roombanner.html (100%) rename webcit/static/{ => t}/roombanner.m.html (100%) diff --git a/webcit/Makefile.in b/webcit/Makefile.in index 5042d4f56..0b607b909 100644 --- a/webcit/Makefile.in +++ b/webcit/Makefile.in @@ -102,8 +102,8 @@ install-setupbin: install-bin install-wwwdata: - test -d $(DESTDIR)$(WWWDIR)/static.local || mkdir -p $(DESTDIR)$(WWWDIR)/static.local - test -d $(DESTDIR)$(WWWDIR)/static || mkdir -p $(DESTDIR)$(WWWDIR)/static + test -d $(DESTDIR)$(WWWDIR)/static.local/t || mkdir -p $(DESTDIR)$(WWWDIR)/static.local/t + test -d $(DESTDIR)$(WWWDIR)/static/t || mkdir -p $(DESTDIR)$(WWWDIR)/static/t for i in `find static -type f | grep -v .svn`; do \ $(INSTALL) $$i $(DESTDIR)$(WWWDIR)/$$i; \ done diff --git a/webcit/static/beginbox.html b/webcit/static/t/beginbox.html similarity index 100% rename from webcit/static/beginbox.html rename to webcit/static/t/beginbox.html diff --git a/webcit/static/beginbox.m.html b/webcit/static/t/beginbox.m.html similarity index 100% rename from webcit/static/beginbox.m.html rename to webcit/static/t/beginbox.m.html diff --git a/webcit/static/beginbox_nt.html b/webcit/static/t/beginbox_nt.html similarity index 100% rename from webcit/static/beginbox_nt.html rename to webcit/static/t/beginbox_nt.html diff --git a/webcit/static/chatframeset.html b/webcit/static/t/chatframeset.html similarity index 100% rename from webcit/static/chatframeset.html rename to webcit/static/t/chatframeset.html diff --git a/webcit/static/endbox.html b/webcit/static/t/endbox.html similarity index 100% rename from webcit/static/endbox.html rename to webcit/static/t/endbox.html diff --git a/webcit/static/endbox.m.html b/webcit/static/t/endbox.m.html similarity index 100% rename from webcit/static/endbox.m.html rename to webcit/static/t/endbox.m.html diff --git a/webcit/static/head.html b/webcit/static/t/head.html similarity index 100% rename from webcit/static/head.html rename to webcit/static/t/head.html diff --git a/webcit/static/head.m.html b/webcit/static/t/head.m.html similarity index 100% rename from webcit/static/head.m.html rename to webcit/static/t/head.m.html diff --git a/webcit/static/msgcontrols.m.html b/webcit/static/t/msgcontrols.m.html similarity index 100% rename from webcit/static/msgcontrols.m.html rename to webcit/static/t/msgcontrols.m.html diff --git a/webcit/static/newstartpage.html b/webcit/static/t/newstartpage.html similarity index 100% rename from webcit/static/newstartpage.html rename to webcit/static/t/newstartpage.html diff --git a/webcit/static/openid_login.html b/webcit/static/t/openid_login.html similarity index 100% rename from webcit/static/openid_login.html rename to webcit/static/t/openid_login.html diff --git a/webcit/static/openid_manual_create.html b/webcit/static/t/openid_manual_create.html similarity index 100% rename from webcit/static/openid_manual_create.html rename to webcit/static/t/openid_manual_create.html diff --git a/webcit/static/pushemail.html b/webcit/static/t/pushemail.html similarity index 100% rename from webcit/static/pushemail.html rename to webcit/static/t/pushemail.html diff --git a/webcit/static/roombanner.html b/webcit/static/t/roombanner.html similarity index 100% rename from webcit/static/roombanner.html rename to webcit/static/t/roombanner.html diff --git a/webcit/static/roombanner.m.html b/webcit/static/t/roombanner.m.html similarity index 100% rename from webcit/static/roombanner.m.html rename to webcit/static/t/roombanner.m.html diff --git a/webcit/subst.c b/webcit/subst.c index 35c117d47..35dbfb012 100644 --- a/webcit/subst.c +++ b/webcit/subst.c @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include "webcit.h" #include "webserver.h" @@ -488,53 +490,26 @@ void ProcessTemplate(WCTemplate *Tmpl, StrBuf *Target) * \brief Display a variable-substituted template * \param templatename template file to load */ -void *load_template(const char *templatename, long len) { - HashList *pCache; - HashList *Static; - HashList *StaticLocal; - StrBuf *flat_filename; - char filename[PATH_MAX]; +void *load_template(StrBuf *filename, StrBuf *Key, HashList *PutThere) +{ int fd; struct stat statbuf; const char *pS, *pE, *pch, *Err; int pos; - struct stat mystat; WCTemplate *NewTemplate; - flat_filename = NewStrBufPlain(templatename, len); - if (WC->is_mobile) { - Static = WirelessTemplateCache; - StaticLocal = WirelessLocalTemplateCache; - StrBufAppendBufPlain(flat_filename, HKEY(".m.html"), 0); - } - else { - Static = TemplateCache; - StaticLocal = LocalTemplateCache; - StrBufAppendBufPlain(flat_filename, HKEY(".html"), 0); - } - - strcpy(filename, static_dirs[1]); - strcat(filename, ChrPtr(flat_filename)); - pCache = StaticLocal; - if (stat(filename, &mystat) == -1) - { - pCache = Static; - strcpy(filename, static_dirs[0]); - strcat(filename, ChrPtr(flat_filename)); - } - - fd = open(filename, O_RDONLY); + fd = open(ChrPtr(filename), O_RDONLY); if (fd <= 0) { wprintf(_("ERROR: could not open template ")); wprintf("'%s' - %s
\n", - (const char*)templatename, strerror(errno)); + ChrPtr(filename), strerror(errno)); return NULL; } if (fstat(fd, &statbuf) == -1) { wprintf(_("ERROR: could not stat template ")); wprintf("'%s' - %s
\n", - (const char*)templatename, strerror(errno)); + ChrPtr(filename), strerror(errno)); return NULL; } @@ -548,7 +523,7 @@ void *load_template(const char *templatename, long len) { FreeWCTemplate(NewTemplate); wprintf(_("ERROR: reading template ")); wprintf("'%s' - %s
\n", - (const char*)templatename, strerror(errno)); + ChrPtr(filename), strerror(errno)); return NULL; } close(fd); @@ -584,7 +559,7 @@ void *load_template(const char *templatename, long len) { PutNewToken(NewTemplate, NewTemlpateSubstitute(pS, pts, pte)); pch ++; } - Put(pCache, filename, strlen(filename), NewTemplate, FreeWCTemplate); + Put(PutThere, ChrPtr(Key), StrLength(Key), NewTemplate, FreeWCTemplate); return NewTemplate; } @@ -609,8 +584,8 @@ void DoTemplate(const char *templatename, long len) if (!GetHash(StaticLocal, templatename, len, &vTmpl) && !GetHash(Static, templatename, len, &vTmpl)) { - vTmpl = load_template(templatename, len); - //////TODO: lock this! + printf ("didn't find %s\n", templatename); + return; } if (vTmpl == NULL) return; @@ -618,6 +593,73 @@ void DoTemplate(const char *templatename, long len) } +int LoadTemplateDir(const char *DirName, HashList *wireless, HashList *big) +{ + StrBuf *FileName; + StrBuf *Tag; + StrBuf *Dir; + DIR *filedir = NULL; + struct dirent *filedir_entry; + int d_namelen; + int d_without_ext; + int IsMobile; + + Dir = NewStrBuf(); + StrBufPrintf(Dir, "%s/t", DirName); + filedir = opendir (ChrPtr(Dir)); + if (filedir == NULL) { + return 0; + } + + FileName = NewStrBuf(); + Tag = NewStrBuf(); + while ((filedir_entry = readdir(filedir))) + { + char *MinorPtr; + char *PStart; +#ifdef _DIRENT_HAVE_D_NAMELEN + d_namelen = filedir_entry->d_namelen; +#else + d_namelen = strlen(filedir_entry->d_name); +#endif + d_without_ext = d_namelen; + while ((d_without_ext > 0) && (filedir_entry->d_name[d_without_ext] != '.')) + d_without_ext --; + if ((d_without_ext == 0) || (d_namelen < 3)) + continue; + + IsMobile = (strstr(filedir_entry->d_name, ".m.html")!= NULL); + PStart = filedir_entry->d_name; + StrBufPrintf(FileName, "%s/t/%s", ChrPtr(Dir), filedir_entry->d_name); + MinorPtr = strchr(filedir_entry->d_name, '.'); + if (MinorPtr != NULL) + *MinorPtr = '\0'; + StrBufPlain(Tag, filedir_entry->d_name, MinorPtr - filedir_entry->d_name); + + + printf("%s %d %s\n",ChrPtr(FileName), IsMobile, ChrPtr(Tag)); + load_template(FileName, Tag, (IsMobile)?wireless:big); + } + closedir(filedir); + FreeStrBuf(&FileName); + FreeStrBuf(&Tag); + FreeStrBuf(&Dir); + return 1; +} + +void InitTemplateCache(void) +{ + + LoadTemplateDir(static_dirs[0], + WirelessTemplateCache, + TemplateCache); + LoadTemplateDir(static_dirs[1], + WirelessLocalTemplateCache, + LocalTemplateCache); + + +} + void InitModule_SUBST (void) diff --git a/webcit/webserver.c b/webcit/webserver.c index b6cdd9960..6a0c80abf 100644 --- a/webcit/webserver.c +++ b/webcit/webserver.c @@ -587,6 +587,7 @@ void spawn_another_worker_thread() const char foobuf[32]; const char *nix(void *vptr) {snprintf(foobuf, 32, "%0x", (long) vptr); return foobuf;} #endif +void InitTemplateCache(void); /* * \brief Here's where it all begins. @@ -621,6 +622,7 @@ int main(int argc, char **argv) WirelessLocalTemplateCache = NewHash(1, NULL); TemplateCache = NewHash(1, NULL); LocalTemplateCache = NewHash(1, NULL); + InitTemplateCache(); initialise_modules(); -- 2.30.2