src/utils_params.c: Actually, "gmtime_r" is required according to RFC 1123.
[collection4.git] / src / utils_params.c
index 2c7bcc2..5b63334 100644 (file)
@@ -3,6 +3,7 @@
 #include <string.h>
 #include <ctype.h>
 #include <errno.h>
+#include <time.h>
 
 #include "utils_params.h"
 
@@ -232,7 +233,7 @@ int uri_escape (char *dst, const char *src, size_t size) /* {{{ */
     else if ((src[in] < 32)
         || (src[in] == '&')
         || (src[in] == ';')
-        || (src[in] >= 128))
+        || (((unsigned char) src[in]) >= 128))
     {
       char esc[4];
 
@@ -254,9 +255,11 @@ int uri_escape (char *dst, const char *src, size_t size) /* {{{ */
       in++;
     }
   } /* while (42) */
+
+  return (0);
 } /* }}} int uri_escape */
 
-const char *script_name (void)
+const char *script_name (void) /* {{{ */
 {
   char *ret;
 
@@ -267,4 +270,22 @@ const char *script_name (void)
   return (ret);
 } /* }}} char *script_name */
 
+int time_to_rfc1123 (time_t t, char *buffer, size_t buffer_size) /* {{{ */
+{
+  struct tm tm_tmp;
+  size_t status;
+
+  /* RFC 1123 *requires* the time to be GMT and the "GMT" timezone string.
+   * Apache will ignore the timezone if "localtime_r" and "%z" is used,
+   * resulting in weird behavior. */
+  if (gmtime_r (&t, &tm_tmp) == NULL)
+    return (errno);
+
+  status = strftime (buffer, buffer_size, "%a, %d %b %Y %T GMT", &tm_tmp);
+  if (status == 0)
+    return (errno);
+
+  return (0);
+} /* }}} int time_to_rfc1123 */
+
 /* vim: set sw=2 sts=2 et fdm=marker : */