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
14d6f71f
Commit
14d6f71f
authored
May 20, 2015
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix unit test
parent
29454e22
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
33 deletions
+27
-33
mongoose.c
mongoose.c
+11
-16
mongoose.h
mongoose.h
+2
-2
unit_test.c
test/unit_test.c
+14
-15
No files found.
mongoose.c
View file @
14d6f71f
...
@@ -5016,20 +5016,16 @@ struct mg_connection *mg_next(struct mg_server *s, struct mg_connection *c) {
...
@@ -5016,20 +5016,16 @@ struct mg_connection *mg_next(struct mg_server *s, struct mg_connection *c) {
static
int
get_var
(
const
char
*
data
,
size_t
data_len
,
const
char
*
name
,
static
int
get_var
(
const
char
*
data
,
size_t
data_len
,
const
char
*
name
,
char
*
dst
,
size_t
dst_len
,
int
n
)
{
char
*
dst
,
size_t
dst_len
,
int
n
)
{
const
char
*
p
,
*
e
,
*
s
;
const
char
*
p
,
*
e
=
data
+
data_len
,
*
s
;
size_t
name_len
;
size_t
name_len
;
int
i
,
len
;
int
i
=
0
,
len
=
-
1
;
if
(
dst
==
NULL
||
dst_len
==
0
)
{
if
(
dst
==
NULL
||
dst_len
==
0
)
{
len
=
-
2
;
len
=
-
2
;
}
else
if
(
data
==
NULL
||
name
==
NULL
||
data_len
==
0
)
{
}
else
if
(
data
==
NULL
||
name
==
NULL
||
data_len
==
0
)
{
len
=
-
1
;
dst
[
0
]
=
'\0'
;
dst
[
0
]
=
'\0'
;
}
else
{
}
else
{
i
=
0
;
name_len
=
strlen
(
name
);
name_len
=
strlen
(
name
);
e
=
data
+
data_len
;
len
=
-
1
;
dst
[
0
]
=
'\0'
;
dst
[
0
]
=
'\0'
;
// data is "var1=val1&var2=val2...". Find variable first
// data is "var1=val1&var2=val2...". Find variable first
...
@@ -5037,8 +5033,7 @@ static int get_var(const char *data, size_t data_len, const char *name,
...
@@ -5037,8 +5033,7 @@ static int get_var(const char *data, size_t data_len, const char *name,
if
((
p
==
data
||
p
[
-
1
]
==
'&'
)
&&
p
[
name_len
]
==
'='
&&
if
((
p
==
data
||
p
[
-
1
]
==
'&'
)
&&
p
[
name_len
]
==
'='
&&
!
mg_strncasecmp
(
name
,
p
,
name_len
))
{
!
mg_strncasecmp
(
name
,
p
,
name_len
))
{
if
(
n
!=
i
++
)
if
(
n
!=
i
++
)
continue
;
continue
;
// Point p to variable value
// Point p to variable value
p
+=
name_len
+
1
;
p
+=
name_len
+
1
;
...
@@ -5065,21 +5060,21 @@ static int get_var(const char *data, size_t data_len, const char *name,
...
@@ -5065,21 +5060,21 @@ static int get_var(const char *data, size_t data_len, const char *name,
return
len
;
return
len
;
}
}
int
mg_get_var
(
const
struct
mg_connection
*
conn
,
const
char
*
name
,
int
mg_get_var_n
(
const
struct
mg_connection
*
conn
,
const
char
*
name
,
char
*
dst
,
size_t
dst_len
)
{
return
mg_get_n_var
(
conn
,
name
,
dst
,
dst_len
,
0
);
}
int
mg_get_n_var
(
const
struct
mg_connection
*
conn
,
const
char
*
name
,
char
*
dst
,
size_t
dst_len
,
int
n
)
{
char
*
dst
,
size_t
dst_len
,
int
n
)
{
int
len
=
get_var
(
conn
->
query_string
,
conn
->
query_string
==
NULL
?
0
:
int
len
=
get_var
(
conn
->
query_string
,
conn
->
query_string
==
NULL
?
0
:
strlen
(
conn
->
query_string
),
name
,
dst
,
dst_len
,
n
);
strlen
(
conn
->
query_string
),
name
,
dst
,
dst_len
,
n
);
if
(
len
==
-
1
)
{
if
(
len
==
-
1
)
{
len
=
get_var
(
conn
->
content
,
conn
->
content_len
,
name
,
dst
,
dst_len
,
n
);
;
len
=
get_var
(
conn
->
content
,
conn
->
content_len
,
name
,
dst
,
dst_len
,
n
);
}
}
return
len
;
return
len
;
}
}
int
mg_get_var
(
const
struct
mg_connection
*
conn
,
const
char
*
name
,
char
*
dst
,
size_t
dst_len
)
{
return
mg_get_var_n
(
conn
,
name
,
dst
,
dst_len
,
0
);
}
static
int
get_line_len
(
const
char
*
buf
,
int
buf_len
)
{
static
int
get_line_len
(
const
char
*
buf
,
int
buf_len
)
{
int
len
=
0
;
int
len
=
0
;
while
(
len
<
buf_len
&&
buf
[
len
]
!=
'\n'
)
len
++
;
while
(
len
<
buf_len
&&
buf
[
len
]
!=
'\n'
)
len
++
;
...
@@ -5308,7 +5303,7 @@ static void send_ns_event(struct ns_connection *nc, int ev, void *p) {
...
@@ -5308,7 +5303,7 @@ static void send_ns_event(struct ns_connection *nc, int ev, void *p) {
}
}
#else
#else
static
void
send_ns_event
(
struct
ns_connection
*
nc
,
int
ev
,
void
*
p
)
{
static
void
send_ns_event
(
struct
ns_connection
*
nc
,
int
ev
,
void
*
p
)
{
(
void
)
nc
;
(
void
)
p
;
(
void
)
nc
;
(
void
)
p
;
(
void
)
ev
;
}
}
#endif
#endif
...
...
mongoose.h
View file @
14d6f71f
...
@@ -121,8 +121,8 @@ const char *mg_get_header(const struct mg_connection *, const char *name);
...
@@ -121,8 +121,8 @@ const char *mg_get_header(const struct mg_connection *, const char *name);
const
char
*
mg_get_mime_type
(
const
char
*
name
,
const
char
*
default_mime_type
);
const
char
*
mg_get_mime_type
(
const
char
*
name
,
const
char
*
default_mime_type
);
int
mg_get_var
(
const
struct
mg_connection
*
conn
,
const
char
*
var_name
,
int
mg_get_var
(
const
struct
mg_connection
*
conn
,
const
char
*
var_name
,
char
*
buf
,
size_t
buf_len
);
char
*
buf
,
size_t
buf_len
);
int
mg_get_
n_var
(
const
struct
mg_connection
*
conn
,
const
char
*
var_name
,
int
mg_get_
var_n
(
const
struct
mg_connection
*
conn
,
const
char
*
var_name
,
char
*
buf
,
size_t
buf_len
,
int
n
);
char
*
buf
,
size_t
buf_len
,
int
n
);
int
mg_parse_header
(
const
char
*
hdr
,
const
char
*
var_name
,
char
*
buf
,
size_t
);
int
mg_parse_header
(
const
char
*
hdr
,
const
char
*
var_name
,
char
*
buf
,
size_t
);
int
mg_parse_multipart
(
const
char
*
buf
,
int
buf_len
,
int
mg_parse_multipart
(
const
char
*
buf
,
int
buf_len
,
char
*
var_name
,
int
var_name_len
,
char
*
var_name
,
int
var_name_len
,
...
...
test/unit_test.c
View file @
14d6f71f
...
@@ -224,29 +224,28 @@ static const char *test_remove_double_dots() {
...
@@ -224,29 +224,28 @@ static const char *test_remove_double_dots() {
}
}
static
const
char
*
test_get_var
(
void
)
{
static
const
char
*
test_get_var
(
void
)
{
static
const
char
*
post
[]
=
{
static
const
char
*
data
=
"a=1&&b=2&d&=&c=3%20&e=&k=aa&a=23"
;
"a=1&&b=2&d&=&c=3%20&e="
,
static
const
char
*
data2
=
"q=&st=2012%2F11%2F13+17%3A05&et=&team_id="
;
"q=&st=2012%2F11%2F13+17%3A05&et=&team_id="
,
NULL
};
char
buf
[
20
];
char
buf
[
20
];
ASSERT
(
get_var
(
post
[
0
],
strlen
(
post
[
0
]),
"a"
,
buf
,
sizeof
(
buf
)
)
==
1
);
ASSERT
(
get_var
(
data
,
strlen
(
data
),
"a"
,
buf
,
sizeof
(
buf
),
0
)
==
1
);
ASSERT
(
buf
[
0
]
==
'1'
&&
buf
[
1
]
==
'\0'
);
ASSERT
(
buf
[
0
]
==
'1'
&&
buf
[
1
]
==
'\0'
);
ASSERT
(
get_var
(
post
[
0
],
strlen
(
post
[
0
]),
"b"
,
buf
,
sizeof
(
buf
))
==
1
);
ASSERT
(
get_var
(
data
,
strlen
(
data
),
"a"
,
buf
,
sizeof
(
buf
),
1
)
==
2
);
ASSERT
(
strcmp
(
buf
,
"23"
)
==
0
);
ASSERT
(
get_var
(
data
,
strlen
(
data
),
"b"
,
buf
,
sizeof
(
buf
),
0
)
==
1
);
ASSERT
(
buf
[
0
]
==
'2'
&&
buf
[
1
]
==
'\0'
);
ASSERT
(
buf
[
0
]
==
'2'
&&
buf
[
1
]
==
'\0'
);
ASSERT
(
get_var
(
post
[
0
],
strlen
(
post
[
0
]),
"c"
,
buf
,
sizeof
(
buf
)
)
==
2
);
ASSERT
(
get_var
(
data
,
strlen
(
data
),
"c"
,
buf
,
sizeof
(
buf
),
0
)
==
2
);
ASSERT
(
buf
[
0
]
==
'3'
&&
buf
[
1
]
==
' '
&&
buf
[
2
]
==
'\0'
);
ASSERT
(
buf
[
0
]
==
'3'
&&
buf
[
1
]
==
' '
&&
buf
[
2
]
==
'\0'
);
ASSERT
(
get_var
(
post
[
0
],
strlen
(
post
[
0
]),
"e"
,
buf
,
sizeof
(
buf
)
)
==
0
);
ASSERT
(
get_var
(
data
,
strlen
(
data
),
"e"
,
buf
,
sizeof
(
buf
),
0
)
==
0
);
ASSERT
(
buf
[
0
]
==
'\0'
);
ASSERT
(
buf
[
0
]
==
'\0'
);
ASSERT
(
get_var
(
post
[
0
],
strlen
(
post
[
0
]),
"d"
,
buf
,
sizeof
(
buf
)
)
==
-
1
);
ASSERT
(
get_var
(
data
,
strlen
(
data
),
"d"
,
buf
,
sizeof
(
buf
),
0
)
==
-
1
);
ASSERT
(
get_var
(
post
[
0
],
strlen
(
post
[
0
]),
"c"
,
buf
,
2
)
==
-
2
);
ASSERT
(
get_var
(
data
,
strlen
(
data
),
"c"
,
buf
,
2
,
0
)
==
-
2
);
ASSERT
(
get_var
(
post
[
0
],
strlen
(
post
[
0
]),
"x"
,
NULL
,
1
0
)
==
-
2
);
ASSERT
(
get_var
(
data
,
strlen
(
data
),
"x"
,
NULL
,
10
,
0
)
==
-
2
);
ASSERT
(
get_var
(
post
[
0
],
strlen
(
post
[
0
]),
"x"
,
buf
,
0
)
==
-
2
);
ASSERT
(
get_var
(
data
,
strlen
(
data
),
"x"
,
buf
,
0
,
0
)
==
-
2
);
ASSERT
(
get_var
(
post
[
1
],
strlen
(
post
[
1
]),
"st"
,
buf
,
16
)
==
-
2
);
ASSERT
(
get_var
(
data2
,
strlen
(
data2
),
"st"
,
buf
,
16
,
0
)
==
-
2
);
ASSERT
(
get_var
(
post
[
1
],
strlen
(
post
[
1
]),
"st"
,
buf
,
17
)
==
16
);
ASSERT
(
get_var
(
data2
,
strlen
(
data2
),
"st"
,
buf
,
17
,
0
)
==
16
);
return
NULL
;
return
NULL
;
}
}
...
...
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