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
6a9494b6
Commit
6a9494b6
authored
Dec 07, 2013
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added mg_get_var() to core, with unit test
parent
63c5658a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
4 deletions
+59
-4
core.c
build/src/core.c
+57
-0
core.h
build/src/core.h
+2
-4
No files found.
build/src/core.c
View file @
6a9494b6
...
...
@@ -2658,6 +2658,63 @@ void mg_add_uri_handler(struct mg_server *server, const char *uri,
}
}
static
int
get_var
(
const
char
*
data
,
size_t
data_len
,
const
char
*
name
,
char
*
dst
,
size_t
dst_len
)
{
const
char
*
p
,
*
e
,
*
s
;
size_t
name_len
;
int
len
;
if
(
dst
==
NULL
||
dst_len
==
0
)
{
len
=
-
2
;
}
else
if
(
data
==
NULL
||
name
==
NULL
||
data_len
==
0
)
{
len
=
-
1
;
dst
[
0
]
=
'\0'
;
}
else
{
name_len
=
strlen
(
name
);
e
=
data
+
data_len
;
len
=
-
1
;
dst
[
0
]
=
'\0'
;
// data is "var1=val1&var2=val2...". Find variable first
for
(
p
=
data
;
p
+
name_len
<
e
;
p
++
)
{
if
((
p
==
data
||
p
[
-
1
]
==
'&'
)
&&
p
[
name_len
]
==
'='
&&
!
mg_strncasecmp
(
name
,
p
,
name_len
))
{
// Point p to variable value
p
+=
name_len
+
1
;
// Point s to the end of the value
s
=
(
const
char
*
)
memchr
(
p
,
'&'
,
(
size_t
)(
e
-
p
));
if
(
s
==
NULL
)
{
s
=
e
;
}
assert
(
s
>=
p
);
// Decode variable into destination buffer
len
=
mg_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
;
}
}
}
return
len
;
}
int
mg_get_var
(
const
struct
mg_connection
*
conn
,
const
char
*
name
,
char
*
dst
,
size_t
dst_len
)
{
int
len
=
get_var
(
conn
->
query_string
,
conn
->
query_string
==
NULL
?
0
:
strlen
(
conn
->
query_string
),
name
,
dst
,
dst_len
);
if
(
len
<
0
)
{
len
=
get_var
(
conn
->
content
,
conn
->
content_len
,
name
,
dst
,
dst_len
);
}
return
len
;
}
const
char
**
mg_get_valid_option_names
(
void
)
{
return
static_config_options
;
}
...
...
build/src/core.h
View file @
6a9494b6
...
...
@@ -77,10 +77,8 @@ int mg_websocket_write(struct mg_connection *, int opcode,
const
char
*
mg_get_header
(
const
struct
mg_connection
*
,
const
char
*
name
);
const
char
*
mg_get_mime_type
(
const
char
*
file_name
);
int
mg_get_var
(
const
struct
mg_connection
*
conn
,
const
char
*
var_name
,
char
*
dst
,
size_t
dst_len
);
int
mg_get_cookie
(
const
char
*
cookie
,
const
char
*
var_name
,
char
*
buf
,
size_t
buf_len
);
int
mg_get_var
(
const
struct
mg_connection
*
conn
,
const
char
*
var_name
,
char
*
buf
,
size_t
buf_len
);
int
mg_parse_header
(
const
char
*
hdr
,
const
char
*
var_name
,
char
*
buf
,
size_t
);
// Utility functions
...
...
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