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
189cd8c5
Commit
189cd8c5
authored
7 years ago
by
Deomid Ryabkov
Committed by
Cesanta Bot
7 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add mg_assemble_uri
PUBLISHED_FROM=533e134a48e0fca55509c3eb16b0a6b64c1188e8
parent
692f436b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
106 additions
and
0 deletions
+106
-0
intro.md
docs/c-api/uri.h/intro.md
+1
-0
mg_assemble_uri.md
docs/c-api/uri.h/mg_assemble_uri.md
+20
-0
mongoose.c
mongoose.c
+70
-0
mongoose.h
mongoose.h
+15
-0
No files found.
docs/c-api/uri.h/intro.md
View file @
189cd8c5
...
...
@@ -3,6 +3,7 @@ title: "URI"
symbol_kind
:
"
intro"
decl_name
:
"
uri.h"
items
:
-
{
name
:
mg_assemble_uri.md
}
-
{
name
:
mg_parse_uri.md
}
---
...
...
This diff is collapsed.
Click to expand it.
docs/c-api/uri.h/mg_assemble_uri.md
0 → 100644
View file @
189cd8c5
---
title
:
"
mg_assemble_uri()"
decl_name
:
"
mg_assemble_uri"
symbol_kind
:
"
func"
signature
:
|
int mg_assemble_uri(const struct mg_str *scheme, const struct mg_str *user_info,
const struct mg_str *host, unsigned int port,
const struct mg_str *path, const struct mg_str *query,
const struct mg_str *fragment, int normalize_path,
struct mg_str *uri);
---
Assemble URI from parts. Any of the inputs can be NULL or zero-length mg_str.
If normalize_path is true, path is normalized by resolving relative refs.
Result is a heap-allocated string (uri->p must be free()d after use).
Returns 0 on success, -1 on error.
This diff is collapsed.
Click to expand it.
mongoose.c
View file @
189cd8c5
...
...
@@ -5021,6 +5021,76 @@ int mg_normalize_uri_path(const struct mg_str *in, struct mg_str *out) {
out
->
len
=
d
-
cp
;
return
1
;
}
int
mg_assemble_uri
(
const
struct
mg_str
*
scheme
,
const
struct
mg_str
*
user_info
,
const
struct
mg_str
*
host
,
unsigned
int
port
,
const
struct
mg_str
*
path
,
const
struct
mg_str
*
query
,
const
struct
mg_str
*
fragment
,
int
normalize_path
,
struct
mg_str
*
uri
)
{
int
result
=
-
1
;
struct
mbuf
out
;
mbuf_init
(
&
out
,
0
);
if
(
scheme
!=
NULL
&&
scheme
->
len
>
0
)
{
mbuf_append
(
&
out
,
scheme
->
p
,
scheme
->
len
);
mbuf_append
(
&
out
,
"://"
,
3
);
}
if
(
user_info
!=
NULL
&&
user_info
->
len
>
0
)
{
mbuf_append
(
&
out
,
user_info
->
p
,
user_info
->
len
);
mbuf_append
(
&
out
,
"@"
,
1
);
}
if
(
host
!=
NULL
&&
host
->
len
>
0
)
{
mbuf_append
(
&
out
,
host
->
p
,
host
->
len
);
}
if
(
port
!=
0
)
{
char
port_str
[
20
];
int
port_str_len
=
sprintf
(
port_str
,
":%u"
,
port
);
mbuf_append
(
&
out
,
port_str
,
port_str_len
);
}
if
(
path
!=
NULL
&&
path
->
len
>
0
)
{
if
(
normalize_path
)
{
struct
mg_str
npath
=
mg_strdup
(
*
path
);
if
(
npath
.
len
!=
path
->
len
)
goto
out
;
if
(
!
mg_normalize_uri_path
(
path
,
&
npath
))
{
free
((
void
*
)
npath
.
p
);
goto
out
;
}
mbuf_append
(
&
out
,
npath
.
p
,
npath
.
len
);
free
((
void
*
)
npath
.
p
);
}
else
{
mbuf_append
(
&
out
,
path
->
p
,
path
->
len
);
}
}
else
if
(
normalize_path
)
{
mbuf_append
(
&
out
,
"/"
,
1
);
}
if
(
query
!=
NULL
&&
query
->
len
>
0
)
{
mbuf_append
(
&
out
,
"?"
,
1
);
mbuf_append
(
&
out
,
query
->
p
,
query
->
len
);
}
if
(
fragment
!=
NULL
&&
fragment
->
len
>
0
)
{
mbuf_append
(
&
out
,
"#"
,
1
);
mbuf_append
(
&
out
,
fragment
->
p
,
fragment
->
len
);
}
result
=
0
;
out:
if
(
result
==
0
)
{
uri
->
p
=
out
.
buf
;
uri
->
len
=
out
.
len
;
}
else
{
mbuf_free
(
&
out
);
uri
->
p
=
NULL
;
uri
->
len
=
0
;
}
return
result
;
}
#ifdef MG_MODULE_LINES
#line 1 "mongoose/src/http.c"
#endif
...
...
This diff is collapsed.
Click to expand it.
mongoose.h
View file @
189cd8c5
...
...
@@ -3843,6 +3843,21 @@ int mg_parse_uri(const struct mg_str uri, struct mg_str *scheme,
unsigned
int
*
port
,
struct
mg_str
*
path
,
struct
mg_str
*
query
,
struct
mg_str
*
fragment
);
/*
* Assemble URI from parts. Any of the inputs can be NULL or zero-length mg_str.
*
* If normalize_path is true, path is normalized by resolving relative refs.
*
* Result is a heap-allocated string (uri->p must be free()d after use).
*
* Returns 0 on success, -1 on error.
*/
int
mg_assemble_uri
(
const
struct
mg_str
*
scheme
,
const
struct
mg_str
*
user_info
,
const
struct
mg_str
*
host
,
unsigned
int
port
,
const
struct
mg_str
*
path
,
const
struct
mg_str
*
query
,
const
struct
mg_str
*
fragment
,
int
normalize_path
,
struct
mg_str
*
uri
);
int
mg_normalize_uri_path
(
const
struct
mg_str
*
in
,
struct
mg_str
*
out
);
#ifdef __cplusplus
...
...
This diff is collapsed.
Click to expand it.
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