Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
b8aeba06
Commit
b8aeba06
authored
Oct 31, 2015
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit test for mg_parse_date_string
PUBLISHED_FROM=aec7d5e6c6598fbc5141c40c9638cc96d288c8dc
parent
8a0bc2d6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
6 deletions
+10
-6
mongoose.c
mongoose.c
+10
-6
No files found.
mongoose.c
View file @
b8aeba06
...
...
@@ -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
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment