]> code.citadel.org Git - citadel.git/blobdiff - webcit/http_datestring.c
* add configure detection for solaris localtime_r, it needs to know the size of the...
[citadel.git] / webcit / http_datestring.c
index 3a7c806cd2d46bac65ac6008feca5bacda53bad3..50cfae68f8d5abfbdbbd94f1d9611bc3806cac96 100644 (file)
@@ -5,6 +5,7 @@
  * \defgroup HTTPDateTime Function to generate HTTP-compliant textual time/date stamp
  * (This module was lifted directly from the Citadel server source)
  *
+ * \ingroup WebcitHttpServer
  */
 /*@{*/
 #include "webcit.h"
@@ -63,4 +64,38 @@ void http_datestring(char *buf, size_t n, time_t xtime) {
 }
 
 
+void tmplput_nowstr(StrBuf *Target, WCTemplputParams *TP)
+{
+       char buf[64];
+       long bufused;
+       time_t now;
+       
+       now = time(NULL);
+#ifdef HAVE_SOLARIS_LOCALTIME_R
+       asctime_r(localtime(&now), buf, sizeof(buf));
+#else
+       asctime_r(localtime(&now), buf);
+#endif
+       bufused = strlen(buf);
+       if ((bufused > 0) && (buf[bufused - 1] == '\n')) {
+               buf[bufused - 1] = '\0';
+               bufused --;
+       }
+       StrEscAppend(Target, NULL, buf, 0, 0);
+}
+void tmplput_nowno(StrBuf *Target, WCTemplputParams *TP)
+{
+       time_t now;
+       now = time(NULL);
+       StrBufAppendPrintf(Target, "%ld", now);
+}
+
+void 
+InitModule_DATE
+(void)
+{
+       RegisterNamespace("DATE:NOW:STR", 0, 0, tmplput_nowstr, NULL, CTX_NONE);
+       RegisterNamespace("DATE:NOW:NO", 0, 0, tmplput_nowno, NULL, CTX_NONE);
+}
+
 /*@}*/