From: Wilfried Göesgens Date: Sat, 31 Jan 2009 13:48:07 +0000 (+0000) Subject: + guess mimetype by template extension X-Git-Tag: v7.86~1520 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=c442a8ab662bd4b0f9d3aed7085f95c54ad0b3c6 + guess mimetype by template extension + do_template now uses the guessed mimetype and sets it as http header --- diff --git a/webcit/subst.c b/webcit/subst.c index 62d616b7b..72659c9b2 100644 --- a/webcit/subst.c +++ b/webcit/subst.c @@ -48,6 +48,7 @@ typedef struct _WCTemplate { StrBuf *FileName; int nTokensUsed; int TokenSpace; + StrBuf *MimeType; WCTemplateToken **Tokens; } WCTemplate; @@ -325,6 +326,7 @@ void FreeWCTemplate(void *vFreeMe) } FreeStrBuf(&FreeMe->FileName); FreeStrBuf(&FreeMe->Data); + FreeStrBuf(&FreeMe->MimeType); free(FreeMe); } @@ -1285,6 +1287,7 @@ void *load_template(StrBuf *filename, StrBuf *Key, HashList *PutThere) NewTemplate->nTokensUsed = 0; NewTemplate->TokenSpace = 0; NewTemplate->Tokens = NULL; + NewTemplate->MimeType = NewStrBufPlain(GuessMimeByFilename (SKEY(NewTemplate->FileName)), -1); if (StrBufReadBLOB(NewTemplate->Data, &fd, 1, statbuf.st_size, &Err) < 0) { close(fd); FreeWCTemplate(NewTemplate); @@ -1504,7 +1507,7 @@ int EvaluateToken(StrBuf *Target, int state, WCTemplputParams *TP) -void ProcessTemplate(WCTemplate *Tmpl, StrBuf *Target, WCTemplputParams *CallingTP) +const StrBuf *ProcessTemplate(WCTemplate *Tmpl, StrBuf *Target, WCTemplputParams *CallingTP) { WCTemplate *pTmpl = Tmpl; int done = 0; @@ -1529,7 +1532,7 @@ void ProcessTemplate(WCTemplate *Tmpl, StrBuf *Target, WCTemplputParams *Calling Target, "
\nError loading Template [%s]\n See Logfile for details\n
\n", ChrPtr(Tmpl->FileName)); - return; + return NULL; } } @@ -1576,13 +1579,16 @@ void ProcessTemplate(WCTemplate *Tmpl, StrBuf *Target, WCTemplputParams *Calling if (LoadTemplates != 0) { FreeWCTemplate(pTmpl); } + return Tmpl->MimeType; + } /** * \brief Display a variable-substituted template * \param templatename template file to load + * \returns the mimetype of the template its doing */ -void DoTemplate(const char *templatename, long len, StrBuf *Target, WCTemplputParams *TP) +const StrBuf *DoTemplate(const char *templatename, long len, StrBuf *Target, WCTemplputParams *TP) { WCTemplputParams LocalTP; HashList *Static; @@ -1609,7 +1615,7 @@ void DoTemplate(const char *templatename, long len, StrBuf *Target, WCTemplputPa { lprintf (1, "Can't to load a template with empty name!\n"); StrBufAppendPrintf(Target, "
\nCan't to load a template with empty name!\n
"); - return; + return NULL; } if (!GetHash(StaticLocal, templatename, len, &vTmpl) && @@ -1622,11 +1628,12 @@ void DoTemplate(const char *templatename, long len, StrBuf *Target, WCTemplputPa dbg_PrintHash(Static, PrintTemplate, NULL); PrintHash(Static, VarPrintTransition, PrintTemplate); #endif - return; + return NULL; } if (vTmpl == NULL) - return; - ProcessTemplate(vTmpl, Target, TP); + return NULL; + return ProcessTemplate(vTmpl, Target, TP); + } /*----------------------------------------------------------------------------- diff --git a/webcit/subst.h b/webcit/subst.h index 743aac03a..4f53cc372 100644 --- a/webcit/subst.h +++ b/webcit/subst.h @@ -291,7 +291,7 @@ void dbg_print_longvector(long *LongVector); #define do_template(a, b) DoTemplate(a, sizeof(a) -1, NULL, &NoCtx); -void DoTemplate(const char *templatename, long len, StrBuf *Target, WCTemplputParams *TP); +const StrBuf *DoTemplate(const char *templatename, long len, StrBuf *Target, WCTemplputParams *TP); void url_do_template(void); diff --git a/webcit/webcit.c b/webcit/webcit.c index eaf4d30b7..3904d0431 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -368,11 +368,12 @@ void blank_page(void) { * A template has been requested */ void url_do_template(void) { + const StrBuf *MimeType; const StrBuf *Tmpl = sbstr("template"); begin_burst(); - output_headers(1, 0, 0, 0, 1, 0); - DoTemplate(SKEY(Tmpl), NULL, &NoCtx); - end_burst(); + output_headers(0, 0, 0, 0, 1, 0); + MimeType = DoTemplate(SKEY(Tmpl), NULL, &NoCtx); + http_transmit_thing(ChrPtr(MimeType), 0); }