From: Vsevolod Stakhov Date: Thu, 10 Mar 2016 14:18:45 +0000 (+0000) Subject: [Feature] Add function to *properly* print HTTP date X-Git-Tag: 1.2.0~83 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=77b8f3e342fae4cce70846c2334c4f95c32f54fe;p=thirdparty%2Frspamd.git [Feature] Add function to *properly* print HTTP date strftime is badly broken and polluted by brain-damaged people that think that locales in libc is a good idea. It isn't. --- diff --git a/src/libutil/http.c b/src/libutil/http.c index a5dcf6f038..0fe8588e77 100644 --- a/src/libutil/http.c +++ b/src/libutil/http.c @@ -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); +} diff --git a/src/libutil/http.h b/src/libutil/http.h index 34c72d5190..36158586dc 100644 --- a/src/libutil/http.h +++ b/src/libutil/http.h @@ -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_ */