+ guess mimetype by template extension
authorWilfried Göesgens <willi@citadel.org>
Sat, 31 Jan 2009 13:48:07 +0000 (13:48 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sat, 31 Jan 2009 13:48:07 +0000 (13:48 +0000)
+ do_template now uses the guessed mimetype and sets it as http header

webcit/subst.c
webcit/subst.h
webcit/webcit.c

index 62d616b7b6bea15706fd6437398c4af3b5fde520..72659c9b2f351fa948dba0cbe4eaf78039b24f52 100644 (file)
@@ -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, 
                                "<pre>\nError loading Template [%s]\n See Logfile for details\n</pre>\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, "<pre>\nCan't to load a template with empty name!\n</pre>");
-               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);
+
 }
 
 /*-----------------------------------------------------------------------------
index 743aac03a97f332430a8971613d44d8bdb1057e1..4f53cc3726cdf5accc4e689a0ee95fbc2bfdda94 100644 (file)
@@ -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);
 
 
index eaf4d30b735522bce9a94ece3cf1739dc18bddb2..3904d043199465dc1ed46c2fee4b220423972526 100644 (file)
@@ -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);
 }