Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mongoose
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ganil-acq
GANILinux
linux-service
library
mongoose
Commits
b8aeba06
Commit
b8aeba06
authored
9 years ago
by
Sergey Lyubka
Browse files
Options
Downloads
Patches
Plain Diff
Add unit test for mg_parse_date_string
PUBLISHED_FROM=aec7d5e6c6598fbc5141c40c9638cc96d288c8dc
parent
8a0bc2d6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mongoose.c
+10
-6
10 additions, 6 deletions
mongoose.c
with
10 additions
and
6 deletions
mongoose.c
+
10
−
6
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
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment