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
4120b9bc
Commit
4120b9bc
authored
Apr 11, 2013
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mg_get_cookie() signature change
parent
f7725f2e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
8 deletions
+24
-8
mongoose.c
mongoose.c
+5
-6
mongoose.h
mongoose.h
+2
-2
unit_test.c
test/unit_test.c
+17
-0
No files found.
mongoose.c
View file @
4120b9bc
...
...
@@ -1709,23 +1709,22 @@ int mg_get_var(const char *data, size_t data_len, const char *name,
return
len
;
}
int
mg_get_cookie
(
const
struct
mg_connection
*
conn
,
const
char
*
cookie
_name
,
int
mg_get_cookie
(
const
char
*
cookie_header
,
const
char
*
var
_name
,
char
*
dst
,
size_t
dst_size
)
{
const
char
*
s
,
*
p
,
*
end
;
int
name_len
,
len
=
-
1
;
if
(
dst
==
NULL
||
dst_size
==
0
)
{
len
=
-
2
;
}
else
if
(
cookie_name
==
NULL
||
(
s
=
mg_get_header
(
conn
,
"Cookie"
))
==
NULL
)
{
}
else
if
(
var_name
==
NULL
||
(
s
=
cookie_header
)
==
NULL
)
{
len
=
-
1
;
dst
[
0
]
=
'\0'
;
}
else
{
name_len
=
(
int
)
strlen
(
cookie
_name
);
name_len
=
(
int
)
strlen
(
var
_name
);
end
=
s
+
strlen
(
s
);
dst
[
0
]
=
'\0'
;
for
(;
(
s
=
mg_strcasestr
(
s
,
cookie
_name
))
!=
NULL
;
s
+=
name_len
)
{
for
(;
(
s
=
mg_strcasestr
(
s
,
var
_name
))
!=
NULL
;
s
+=
name_len
)
{
if
(
s
[
name_len
]
==
'='
)
{
s
+=
name_len
+
1
;
if
((
p
=
strchr
(
s
,
' '
))
==
NULL
)
...
...
@@ -1740,7 +1739,7 @@ int mg_get_cookie(const struct mg_connection *conn, const char *cookie_name,
len
=
p
-
s
;
mg_strlcpy
(
dst
,
s
,
(
size_t
)
len
+
1
);
}
else
{
len
=
-
2
;
len
=
-
3
;
}
break
;
}
...
...
mongoose.h
View file @
4120b9bc
...
...
@@ -285,8 +285,8 @@ int mg_get_var(const char *data, size_t data_len,
// parameter is not found).
// -2 (destination buffer is NULL, zero length or too small to hold the
// value).
int
mg_get_cookie
(
const
struct
mg_connection
*
,
c
onst
char
*
cookie_name
,
c
har
*
buf
,
size_t
buf_len
);
int
mg_get_cookie
(
const
char
*
cookie
,
const
char
*
var_name
,
char
*
buf
,
size_t
buf_len
);
// Download data from the remote web server.
...
...
test/unit_test.c
View file @
4120b9bc
...
...
@@ -609,6 +609,22 @@ static void test_mg_strcasestr(void) {
ASSERT
(
mg_strcasestr
(
"aa"
,
"AAB"
)
==
NULL
);
}
static
void
test_mg_get_cookie
(
void
)
{
char
buf
[
20
];
ASSERT
(
mg_get_cookie
(
""
,
"foo"
,
NULL
,
sizeof
(
buf
))
==
-
2
);
ASSERT
(
mg_get_cookie
(
""
,
"foo"
,
buf
,
0
)
==
-
2
);
ASSERT
(
mg_get_cookie
(
""
,
"foo"
,
buf
,
sizeof
(
buf
))
==
-
1
);
ASSERT
(
mg_get_cookie
(
""
,
NULL
,
buf
,
sizeof
(
buf
))
==
-
1
);
ASSERT
(
mg_get_cookie
(
"a=1; b=2; c; d"
,
"a"
,
buf
,
sizeof
(
buf
))
==
1
);
ASSERT
(
strcmp
(
buf
,
"1"
)
==
0
);
ASSERT
(
mg_get_cookie
(
"a=1; b=2; c; d"
,
"b"
,
buf
,
sizeof
(
buf
))
==
1
);
ASSERT
(
strcmp
(
buf
,
"2"
)
==
0
);
ASSERT
(
mg_get_cookie
(
"a=1; b=123"
,
"b"
,
buf
,
sizeof
(
buf
))
==
3
);
ASSERT
(
strcmp
(
buf
,
"123"
)
==
0
);
ASSERT
(
mg_get_cookie
(
"a=1; b=2; c; d"
,
"c"
,
buf
,
sizeof
(
buf
))
==
-
1
);
}
int
__cdecl
main
(
void
)
{
test_mg_strcasestr
();
test_alloc_vprintf
();
...
...
@@ -627,6 +643,7 @@ int __cdecl main(void) {
test_request_replies
();
test_api_calls
();
test_url_decode
();
test_mg_get_cookie
();
#ifdef USE_LUA
test_lua
();
#endif
...
...
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