]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Add function to *properly* print HTTP date
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 10 Mar 2016 14:18:45 +0000 (14:18 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 10 Mar 2016 14:18:45 +0000 (14:18 +0000)
strftime is badly broken and polluted by brain-damaged people that
think that locales in libc is a good idea. It isn't.

src/libutil/http.c
src/libutil/http.h

index a5dcf6f0385f436da6a0d2a070bccb50d656bf44..0fe8588e77edc42a10bc0b488ffa2d1104829e45 100644 (file)
@@ -83,7 +83,10 @@ static const rspamd_ftok_t date_header = {
                .begin = "Date",
                .len = 4
 };
-
+static const rspamd_ftok_t last_modified_header = {
+               .begin = "Last-Modified",
+               .len = 13
+};
 
 #define HTTP_ERROR http_error_quark ()
 GQuark
@@ -454,6 +457,11 @@ rspamd_http_check_special_header (struct rspamd_http_connection *conn,
        else if (rspamd_ftok_casecmp (priv->header->name, &key_header) == 0) {
                rspamd_http_parse_key (priv->header->value, conn, priv);
        }
+       else if (rspamd_ftok_casecmp (priv->header->name, &last_modified_header) == 0) {
+               priv->msg->last_modified = rspamd_http_parse_date (
+                               priv->header->value->begin,
+                               priv->header->value->len);
+       }
 }
 
 static gint
@@ -2443,3 +2451,17 @@ rspamd_http_message_parse_query (struct rspamd_http_message *msg)
 
        return res;
 }
+
+
+glong
+rspamd_http_date_format (gchar *buf, gsize len, time_t time)
+{
+       struct tm tms;
+
+       tms = *gmtime (&time);
+
+       return rspamd_snprintf (buf, len, "%s, %02d %s %4d %02d:%02d:%02d GMT",
+                       http_week[tms.tm_wday], tms.tm_mday,
+                       http_month[tms.tm_mon], tms.tm_year + 1900,
+                       tms.tm_hour, tms.tm_min, tms.tm_sec);
+}
index 34c72d5190081137439b9a5cc93e7c764ae3d6e2..36158586dc7a89091ca13385deb1359333e9038b 100644 (file)
@@ -55,14 +55,15 @@ struct rspamd_http_header {
 struct rspamd_http_message {
        rspamd_fstring_t *url;
        rspamd_fstring_t *host;
-       unsigned port;
        rspamd_fstring_t *status;
        struct rspamd_http_header *headers;
        rspamd_fstring_t *body;
        rspamd_ftok_t body_buf;
        struct rspamd_cryptobox_pubkey *peer_key;
-       enum http_parser_type type;
        time_t date;
+       time_t last_modified;
+       unsigned port;
+       enum http_parser_type type;
        gint code;
        enum http_method method;
        gint flags;
@@ -357,4 +358,13 @@ void rspamd_http_router_free (struct rspamd_http_connection_router *router);
  */
 GHashTable* rspamd_http_message_parse_query (struct rspamd_http_message *msg);
 
+/**
+ * Prints HTTP date from `time` to `buf` using standard HTTP date format
+ * @param buf date buffer
+ * @param len length of buffer
+ * @param time time in unix seconds
+ * @return number of bytes written
+ */
+glong rspamd_http_date_format (gchar *buf, gsize len, time_t time);
+
 #endif /* HTTP_H_ */