mirror of
https://github.com/cesanta/mongoose.git
synced 2024-11-28 05:39:00 +08:00
Add unit test for mg_parse_date_string
PUBLISHED_FROM=aec7d5e6c6598fbc5141c40c9638cc96d288c8dc
This commit is contained in:
parent
8a0bc2d614
commit
b8aeba06a2
16
mongoose.c
16
mongoose.c
@ -101,6 +101,10 @@ MG_INTERNAL size_t mg_handle_chunked(struct mg_connection *nc,
|
||||
struct http_message *hm, char *buf,
|
||||
size_t blen);
|
||||
|
||||
#ifndef MG_DISABLE_FILESYSTEM
|
||||
MG_INTERNAL time_t mg_parse_date_string(const char *datetime);
|
||||
#endif
|
||||
|
||||
/* Forward declarations for testing. */
|
||||
extern void *(*test_malloc)(size_t);
|
||||
extern void *(*test_calloc)(size_t, size_t);
|
||||
@ -5914,7 +5918,7 @@ static void handle_cgi(struct mg_connection *nc, const char *prog,
|
||||
}
|
||||
#endif
|
||||
|
||||
static int get_month_index(const char *s) {
|
||||
static int mg_get_month_index(const char *s) {
|
||||
static const char *month_names[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
size_t i;
|
||||
@ -5925,12 +5929,12 @@ static int get_month_index(const char *s) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int num_leap_years(int year) {
|
||||
static int mg_num_leap_years(int year) {
|
||||
return year / 4 - year / 100 + year / 400;
|
||||
}
|
||||
|
||||
/* Parse UTC date-time string, and return the corresponding time_t value. */
|
||||
static time_t parse_date_string(const char *datetime) {
|
||||
MG_INTERNAL time_t mg_parse_date_string(const char *datetime) {
|
||||
static const unsigned short days_before_month[] = {
|
||||
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
|
||||
char month_str[32];
|
||||
@ -5945,8 +5949,8 @@ static time_t parse_date_string(const char *datetime) {
|
||||
&hour, &minute, &second) == 6) ||
|
||||
(sscanf(datetime, "%d-%3s-%d %d:%d:%d", &day, month_str, &year, &hour,
|
||||
&minute, &second) == 6)) &&
|
||||
year > 1970 && (month = get_month_index(month_str)) != -1) {
|
||||
leap_days = num_leap_years(year) - num_leap_years(1970);
|
||||
year > 1970 && (month = mg_get_month_index(month_str)) != -1) {
|
||||
leap_days = mg_num_leap_years(year) - mg_num_leap_years(1970);
|
||||
year -= 1970;
|
||||
days = year * 365 + days_before_month[month] + (day - 1) + leap_days;
|
||||
result = days * 24 * 3600 + hour * 3600 + minute * 60 + second;
|
||||
@ -5961,7 +5965,7 @@ static int mg_is_not_modified(struct http_message *hm, cs_stat_t *st) {
|
||||
struct mg_str *inm = mg_get_http_header(hm, "If-None-Match");
|
||||
construct_etag(etag, sizeof(etag), st);
|
||||
return (inm != NULL && !mg_vcasecmp(inm, etag)) ||
|
||||
(ims != NULL && st->st_mtime <= parse_date_string(ims->p));
|
||||
(ims != NULL && st->st_mtime <= mg_parse_date_string(ims->p));
|
||||
}
|
||||
|
||||
static void mg_send_digest_auth_request(struct mg_connection *c,
|
||||
|
Loading…
Reference in New Issue
Block a user