Finalize vcard editing:
[citadel.git] / webcit / subst.c
index ab4edce38692746f02a8a89f06cd0ab4ba8f9637..7aa54bff8ad451b36691366c016413487941051a 100644 (file)
@@ -1907,6 +1907,8 @@ const StrBuf *ProcessTemplate(WCTemplate *Tmpl, StrBuf *Target, WCTemplputParams
 
 }
 
+
+StrBuf *textPlainType;
 /**
  * \brief Display a variable-substituted template
  * \param templatename template file to load
@@ -1933,23 +1935,28 @@ const StrBuf *DoTemplate(const char *templatename, long len, StrBuf *Target, WCT
        {
                syslog(LOG_WARNING, "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 NULL;
+               return textPlainType;
        }
 
        if (!GetHash(StaticLocal, templatename, len, &vTmpl) &&
            !GetHash(Static, templatename, len, &vTmpl)) {
-               syslog(LOG_WARNING, "didn't find Template [%s] %ld %ld\n", templatename, len , (long)strlen(templatename));
+               StrBuf *escapedString = NewStrBufPlain(NULL, len);
+               
+               StrHtmlEcmaEscAppend(escapedString, NULL, templatename, 1, 1);
+               syslog(LOG_WARNING, "didn't find Template [%s] %ld %ld\n", ChrPtr(escapedString), len , (long)strlen(templatename));
                StrBufAppendPrintf(Target, "<pre>\ndidn't find Template [%s] %ld %ld\n</pre>", 
-                                  templatename, len, 
+                                  ChrPtr(escapedString), len, 
                                   (long)strlen(templatename));
+               WC->isFailure = 1;
 #if 0
                dbg_PrintHash(Static, PrintTemplate, NULL);
                PrintHash(Static, VarPrintTransition, PrintTemplate);
 #endif
-               return NULL;
+               FreeStrBuf(&escapedString);
+               return textPlainType;
        }
        if (vTmpl == NULL) 
-               return NULL;
+               return textPlainType;
        return ProcessTemplate(vTmpl, Target, TP);
 
 }
@@ -2133,7 +2140,7 @@ void tmpl_iterate_subtmpl(StrBuf *Target, WCTemplputParams *TP)
                                /** Ok, its us, lets see in which direction we should sort... */
                                    (havebstr("SortOrder"))) {
                                        int SortOrder;
-                                       SortOrder = LBSTR("SortOrder");
+                                       SortOrder = lbstr("SortOrder");
                                        if (SortOrder != 0)
                                                DetectGroupChange = 1;
                                }
@@ -2163,7 +2170,7 @@ void tmpl_iterate_subtmpl(StrBuf *Target, WCTemplputParams *TP)
                        if ((Status.n >= StartAt) && (Status.n <= StopAt)) {
 
                                if ((It->Filter != NULL) &&
-                                   It->Filter(Status.Key, Status.KeyLen, vContext, Target, TP)) 
+                                   !It->Filter(Status.Key, Status.KeyLen, vContext, Target, TP)) 
                                {
                                        continue;
                                }
@@ -2656,7 +2663,7 @@ CompareFunc RetrieveSort(WCTemplputParams *TP,
 
        /** Ok, its us, lets see in which direction we should sort... */
        if (havebstr("SortOrder")) {
-               SortOrder = LBSTR("SortOrder");
+               SortOrder = lbstr("SortOrder");
        }
        else { /** Try to fallback to our remembered values... */
                StrBuf *Buf = NULL;
@@ -2748,7 +2755,7 @@ int GetSortMetric(WCTemplputParams *TP, SortStruct **Next, SortStruct **Param, l
 
        /** Ok, its us, lets see in which direction we should sort... */
        if (havebstr("SortOrder")) {
-               *SortOrder = LBSTR("SortOrder");
+               *SortOrder = lbstr("SortOrder");
        }
        else { /** Try to fallback to our remembered values... */
                if ((*Param)->PrefPrepend == NULL) {
@@ -2988,9 +2995,9 @@ void
 ServerStartModule_SUBST
 (void)
 {
+       textPlainType = NewStrBufPlain(HKEY("text/plain"));
        LocalTemplateCache = NewHash(1, NULL);
        TemplateCache = NewHash(1, NULL);
-
        GlobalNS = NewHash(1, NULL);
        Iterators = NewHash(1, NULL);
        Conditionals = NewHash(1, NULL);
@@ -3016,9 +3023,11 @@ void
 ServerShutdownModule_SUBST
 (void)
 {
+       FreeStrBuf(&textPlainType);
+
        DeleteHash(&TemplateCache);
        DeleteHash(&LocalTemplateCache);
-
+       
        DeleteHash(&GlobalNS);
        DeleteHash(&Iterators);
        DeleteHash(&Conditionals);