Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mongoose
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ganil-acq
GANILinux
linux-service
library
mongoose
Commits
3e780d21
Commit
3e780d21
authored
10 years ago
by
Sergey Lyubka
Browse files
Options
Downloads
Patches
Plain Diff
moved form.c example to separate dir
parent
63fcea01
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
examples/post.c
+0
-62
0 additions, 62 deletions
examples/post.c
examples/restful_api/Makefile
+1
-1
1 addition, 1 deletion
examples/restful_api/Makefile
examples/restful_api/restful_api.c
+0
-0
0 additions, 0 deletions
examples/restful_api/restful_api.c
with
1 addition
and
63 deletions
examples/post.c
deleted
100644 → 0
+
0
−
62
View file @
63fcea01
#include
<stdio.h>
#include
<string.h>
#include
"mongoose.h"
static
const
char
*
html_form
=
"<html><body>POST example."
"<form method=
\"
POST
\"
action=
\"
/handle_post_request
\"
>"
"Input 1: <input type=
\"
text
\"
name=
\"
input_1
\"
/> <br/>"
"Input 2: <input type=
\"
text
\"
name=
\"
input_2
\"
/> <br/>"
"<input type=
\"
submit
\"
/>"
"</form></body></html>"
;
static
void
send_reply
(
struct
mg_connection
*
conn
)
{
char
var1
[
500
],
var2
[
500
];
if
(
strcmp
(
conn
->
uri
,
"/handle_post_request"
)
==
0
)
{
// User has submitted a form, show submitted data and a variable value
// Parse form data. var1 and var2 are guaranteed to be NUL-terminated
mg_get_var
(
conn
,
"input_1"
,
var1
,
sizeof
(
var1
));
mg_get_var
(
conn
,
"input_2"
,
var2
,
sizeof
(
var2
));
// Send reply to the client, showing submitted form values.
// POST data is in conn->content, data length is in conn->content_len
mg_send_header
(
conn
,
"Content-Type"
,
"text/plain"
);
mg_printf_data
(
conn
,
"Submitted data: [%.*s]
\n
"
"Submitted data length: %d bytes
\n
"
"input_1: [%s]
\n
"
"input_2: [%s]
\n
"
,
conn
->
content_len
,
conn
->
content
,
conn
->
content_len
,
var1
,
var2
);
}
else
{
// Show HTML form.
mg_send_data
(
conn
,
html_form
,
strlen
(
html_form
));
}
}
static
int
ev_handler
(
struct
mg_connection
*
conn
,
enum
mg_event
ev
)
{
if
(
ev
==
MG_REQUEST
)
{
send_reply
(
conn
);
return
MG_TRUE
;
}
else
if
(
ev
==
MG_AUTH
)
{
return
MG_TRUE
;
}
else
{
return
MG_FALSE
;
}
}
int
main
(
void
)
{
struct
mg_server
*
server
=
mg_create_server
(
NULL
,
ev_handler
);
mg_set_option
(
server
,
"listening_port"
,
"8080"
);
printf
(
"Starting on port %s
\n
"
,
mg_get_option
(
server
,
"listening_port"
));
for
(;;)
{
mg_poll_server
(
server
,
1000
);
}
mg_destroy_server
(
&
server
);
return
0
;
}
This diff is collapsed.
Click to expand it.
examples/
mongoose_server
/Makefile
→
examples/
restful_api
/Makefile
+
1
−
1
View file @
3e780d21
# Copyright (c) 2014 Cesanta Software
# All rights reserved
PROG
=
mongoose_server
PROG
=
restful_api
CFLAGS
=
-W
-Wall
-I
../..
-g
-O0
$(
CFLAGS_EXTRA
)
SOURCES
=
$(
PROG
)
.c ../../mongoose.c
...
...
This diff is collapsed.
Click to expand it.
examples/
form_submit/form_submit
.c
→
examples/
restful_api/restful_api
.c
+
0
−
0
View file @
3e780d21
File moved
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment