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
ca9212c3
Commit
ca9212c3
authored
Dec 16, 2012
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #65 from nullable-type/master
Inconsistent error codes of mg_get_var(..)
parents
0912a7f4
c9183f38
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
18 deletions
+17
-18
mongoose.c
mongoose.c
+11
-12
mongoose.h
mongoose.h
+6
-6
No files found.
mongoose.c
View file @
ca9212c3
...
@@ -1646,13 +1646,7 @@ static int url_decode(const char *src, int src_len, char *dst,
...
@@ -1646,13 +1646,7 @@ static int url_decode(const char *src, int src_len, char *dst,
return
i
>=
src_len
?
j
:
-
1
;
return
i
>=
src_len
?
j
:
-
1
;
}
}
// Scan given buffer and fetch the value of the given variable.
int
mg_get_var
(
const
char
*
data
,
size_t
data_len
,
const
char
*
name
,
// It can be specified in query string, or in the POST data.
// Return -1 if the variable not found, or length of the URL-decoded value
// stored in dst. The dst buffer is guaranteed to be NUL-terminated if it
// is not NULL or zero-length. If dst is NULL or zero-length, then
// -2 is returned.
int
mg_get_var
(
const
char
*
buf
,
size_t
buf_len
,
const
char
*
name
,
char
*
dst
,
size_t
dst_len
)
{
char
*
dst
,
size_t
dst_len
)
{
const
char
*
p
,
*
e
,
*
s
;
const
char
*
p
,
*
e
,
*
s
;
size_t
name_len
;
size_t
name_len
;
...
@@ -1660,18 +1654,18 @@ int mg_get_var(const char *buf, size_t buf_len, const char *name,
...
@@ -1660,18 +1654,18 @@ int mg_get_var(const char *buf, size_t buf_len, const char *name,
if
(
dst
==
NULL
||
dst_len
==
0
)
{
if
(
dst
==
NULL
||
dst_len
==
0
)
{
len
=
-
2
;
len
=
-
2
;
}
else
if
(
buf
==
NULL
||
name
==
NULL
||
buf
_len
==
0
)
{
}
else
if
(
data
==
NULL
||
name
==
NULL
||
data
_len
==
0
)
{
len
=
-
1
;
len
=
-
1
;
dst
[
0
]
=
'\0'
;
dst
[
0
]
=
'\0'
;
}
else
{
}
else
{
name_len
=
strlen
(
name
);
name_len
=
strlen
(
name
);
e
=
buf
+
buf
_len
;
e
=
data
+
data
_len
;
len
=
-
1
;
len
=
-
1
;
dst
[
0
]
=
'\0'
;
dst
[
0
]
=
'\0'
;
//
buf
is "var1=val1&var2=val2...". Find variable first
//
data
is "var1=val1&var2=val2...". Find variable first
for
(
p
=
buf
;
p
+
name_len
<
e
;
p
++
)
{
for
(
p
=
data
;
p
+
name_len
<
e
;
p
++
)
{
if
((
p
==
buf
||
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
))
{
// Point p to variable value
// Point p to variable value
...
@@ -1686,6 +1680,11 @@ int mg_get_var(const char *buf, size_t buf_len, const char *name,
...
@@ -1686,6 +1680,11 @@ int mg_get_var(const char *buf, size_t buf_len, const char *name,
// Decode variable into destination buffer
// Decode variable into destination buffer
len
=
url_decode
(
p
,
(
size_t
)(
s
-
p
),
dst
,
dst_len
,
1
);
len
=
url_decode
(
p
,
(
size_t
)(
s
-
p
),
dst
,
dst_len
,
1
);
// Redirect error code from -1 to -2 (destination buffer too small).
if
(
len
==
-
1
)
{
len
=
-
2
;
}
break
;
break
;
}
}
}
}
...
...
mongoose.h
View file @
ca9212c3
...
@@ -286,19 +286,19 @@ const char *mg_get_header(const struct mg_connection *, const char *name);
...
@@ -286,19 +286,19 @@ const char *mg_get_header(const struct mg_connection *, const char *name);
// or request_info.query_string.
// or request_info.query_string.
// data_len: length of the encoded data.
// data_len: length of the encoded data.
// var_name: variable name to decode from the buffer
// var_name: variable name to decode from the buffer
//
buf
: destination buffer for the decoded variable
//
dst
: destination buffer for the decoded variable
//
buf
_len: length of the destination buffer
//
dst
_len: length of the destination buffer
//
//
// Return:
// Return:
// On success, length of the decoded variable.
// On success, length of the decoded variable.
// On error:
// On error:
// -1 (variable not found
, or destination buffer is too small
).
// -1 (variable not found).
// -2 (destination buffer is NULL
or zero length
).
// -2 (destination buffer is NULL
, zero length or too small to hold the decoded variable
).
//
//
// Destination buffer is guaranteed to be '\0' - terminated if it is not
// Destination buffer is guaranteed to be '\0' - terminated if it is not
// NULL or zero length.
In case of failure, dst[0] == '\0'.
// NULL or zero length.
int
mg_get_var
(
const
char
*
data
,
size_t
data_len
,
int
mg_get_var
(
const
char
*
data
,
size_t
data_len
,
const
char
*
var_name
,
char
*
buf
,
size_t
buf
_len
);
const
char
*
var_name
,
char
*
dst
,
size_t
dst
_len
);
// Fetch value of certain cookie variable into the destination buffer.
// Fetch value of certain cookie variable into the destination buffer.
//
//
...
...
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