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
5a04ab2c
Commit
5a04ab2c
authored
Mar 30, 2014
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added mg_template() function
parent
4739de6c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
0 deletions
+43
-0
mongoose.c
mongoose.c
+36
-0
mongoose.h
mongoose.h
+7
-0
No files found.
mongoose.c
View file @
5a04ab2c
...
@@ -2179,6 +2179,42 @@ int mg_match_prefix(const char *pattern, int pattern_len, const char *str) {
...
@@ -2179,6 +2179,42 @@ int mg_match_prefix(const char *pattern, int pattern_len, const char *str) {
return
j
;
return
j
;
}
}
// This function prints HTML pages, and expands "{{something}}" blocks
// inside HTML by calling appropriate callback functions.
// The output is done by the output function. In production case, the output
// function sends data to mongoose. In test case, it prints into a string.
// Note that {{@path/to/file}} construct outputs embedded file's contents,
// which provides SSI-like functionality.
void
mg_template
(
struct
mg_connection
*
conn
,
const
char
*
s
,
struct
mg_expansion
*
expansions
)
{
int
i
,
j
,
pos
=
0
,
inside_marker
=
0
;
for
(
i
=
0
;
s
[
i
]
!=
'\0'
;
i
++
)
{
if
(
inside_marker
==
0
&&
!
memcmp
(
&
s
[
i
],
"{{"
,
2
))
{
if
(
i
>
pos
)
{
mg_send_data
(
conn
,
&
s
[
pos
],
i
-
pos
);
}
pos
=
i
;
inside_marker
=
1
;
}
if
(
inside_marker
==
1
&&
!
memcmp
(
&
s
[
i
],
"}}"
,
2
))
{
for
(
j
=
0
;
expansions
[
j
].
keyword
!=
NULL
;
j
++
)
{
const
char
*
kw
=
expansions
[
j
].
keyword
;
if
((
int
)
strlen
(
kw
)
==
i
-
(
pos
+
2
)
&&
memcmp
(
kw
,
&
s
[
pos
+
2
],
i
-
(
pos
+
2
))
==
0
)
{
expansions
[
j
].
handler
(
conn
);
pos
=
i
+
2
;
break
;
}
}
inside_marker
=
0
;
}
}
if
(
i
>
pos
)
{
mg_send_data
(
conn
,
&
s
[
pos
],
i
-
pos
);
}
}
#ifndef MONGOOSE_NO_FILESYSTEM
#ifndef MONGOOSE_NO_FILESYSTEM
static
int
must_hide_file
(
struct
connection
*
conn
,
const
char
*
path
)
{
static
int
must_hide_file
(
struct
connection
*
conn
,
const
char
*
path
)
{
const
char
*
pw_pattern
=
"**"
PASSWORDS_FILE_NAME
"$"
;
const
char
*
pw_pattern
=
"**"
PASSWORDS_FILE_NAME
"$"
;
...
...
mongoose.h
View file @
5a04ab2c
...
@@ -113,6 +113,13 @@ void *mg_start_thread(void *(*func)(void *), void *param);
...
@@ -113,6 +113,13 @@ void *mg_start_thread(void *(*func)(void *), void *param);
char
*
mg_md5
(
char
buf
[
33
],
...);
char
*
mg_md5
(
char
buf
[
33
],
...);
int
mg_authorize_digest
(
struct
mg_connection
*
c
,
FILE
*
fp
);
int
mg_authorize_digest
(
struct
mg_connection
*
c
,
FILE
*
fp
);
struct
mg_expansion
{
const
char
*
keyword
;
void
(
*
handler
)(
struct
mg_connection
*
);
};
void
mg_template
(
struct
mg_connection
*
,
const
char
*
text
,
struct
mg_expansion
*
expansions
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
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