X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fhttp_datestring.c;h=33158dca92e20d1a9f48d54373a21bb597c4b48e;hb=HEAD;hp=aa0aa6ebfb306d9ba304546e564cbce8cead66bb;hpb=aa8ca3b0af3efdabd8559b886efb3164319bdce1;p=citadel.git diff --git a/webcit/http_datestring.c b/webcit/http_datestring.c index aa0aa6ebf..d1f6634e3 100644 --- a/webcit/http_datestring.c +++ b/webcit/http_datestring.c @@ -1,25 +1,26 @@ -/* - * $Id$ - * - * Function to generate HTTP-compliant textual time/date stamp - * (This module was lifted directly from the Citadel server source) - * - */ - #include "webcit.h" +#ifdef __FreeBSD__ +/** I like to believe there is a better way to do this. */ +#define HAVE_STRUCT_TM_TM_GMTOFF +#endif +/** HTTP Months - do not translate - these are not for human consumption */ static char *httpdate_months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; +/** HTTP Weekdays - do not translate - these are not for human consumption */ static char *httpdate_weekdays[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; -/* - * Supplied with a unix timestamp, generate a textual time/date stamp +/** + * \brief Supplied with a unix timestamp, generate a textual time/date stamp + * \param buf the return buffer + * \param n the size of the buffer + * \param xtime the time to format as string */ void http_datestring(char *buf, size_t n, time_t xtime) { struct tm t; @@ -29,7 +30,7 @@ void http_datestring(char *buf, size_t n, time_t xtime) { localtime_r(&xtime, &t); - /* Convert "seconds west of GMT" to "hours/minutes offset" */ + /** Convert "seconds west of GMT" to "hours/minutes offset" */ #ifdef HAVE_STRUCT_TM_TM_GMTOFF offset = t.tm_gmtoff; #else @@ -56,3 +57,37 @@ 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); +}