Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
mongoose
Commits
c06abbc5
Commit
c06abbc5
authored
May 15, 2015
by
NickCis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implementing array varibles
parent
c8e88e17
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
3 deletions
+81
-3
Makefile
examples/array_vars/Makefile
+21
-0
array_vars.c
examples/array_vars/array_vars.c
+46
-0
mongoose.c
mongoose.c
+12
-3
mongoose.h
mongoose.h
+2
-0
No files found.
examples/array_vars/Makefile
0 → 100644
View file @
c06abbc5
# Copyright (c) 2014 Cesanta Software
# All rights reserved
PROG
=
array_vars
CFLAGS
=
-W
-Wall
-I
../..
-pthread
-g
-O0
$(CFLAGS_EXTRA)
SOURCES
=
$(PROG)
.c ../../mongoose.c
all
:
$(PROG)
run
:
$(PROG)
./
$(PROG)
$(PROG)
:
$(SOURCES) Makefile
$(CC)
-o
$(PROG)
$(SOURCES)
$(CFLAGS)
win
:
wine cl
$(SOURCES)
/MD /nologo /DNDEBUG /O1 /I../.. /Fe
$(PROG)
.exe
wine
$(PROG)
.exe
clean
:
rm
-rf
$(PROG)
*
.exe
*
.dSYM
*
.obj
*
.exp .
*
o
*
.lib
*
.gc
*
examples/array_vars/array_vars.c
0 → 100644
View file @
c06abbc5
// Copyright (c) 2014 Cesanta Software
// All rights reserved
//
// This example demostrates basic use of Mongoose embedded web server.
// $Date: 2014-09-09 22:20:23 UTC $
#include <stdio.h>
#include <string.h>
#include "mongoose.h"
static
int
ev_handler
(
struct
mg_connection
*
conn
,
enum
mg_event
ev
)
{
switch
(
ev
)
{
case
MG_AUTH
:
return
MG_TRUE
;
case
MG_REQUEST
:
{
mg_printf_data
(
conn
,
"Hello! Requested URI is [%s] "
,
conn
->
uri
);
char
buffer
[
1024
];
int
ret
,
i
;
for
(
i
=
0
;
(
ret
=
mg_get_n_var
(
conn
,
"foo[]"
,
buffer
,
1024
,
i
))
>
0
;
i
++
)
mg_printf_data
(
conn
,
"
\n
foo[%d] = %s"
,
i
,
buffer
);
return
MG_TRUE
;
}
default:
return
MG_FALSE
;
}
}
int
main
(
void
)
{
struct
mg_server
*
server
;
// Create and configure the server
server
=
mg_create_server
(
NULL
,
ev_handler
);
mg_set_option
(
server
,
"listening_port"
,
"8080"
);
// Serve request. Hit Ctrl-C to terminate the program
printf
(
"Starting on port %s
\n
"
,
mg_get_option
(
server
,
"listening_port"
));
for
(;;)
{
mg_poll_server
(
server
,
1000
);
}
// Cleanup, and free server instance
mg_destroy_server
(
&
server
);
return
0
;
}
mongoose.c
View file @
c06abbc5
...
...
@@ -4998,7 +4998,7 @@ struct mg_connection *mg_next(struct mg_server *s, struct mg_connection *c) {
}
static
int
get_var
(
const
char
*
data
,
size_t
data_len
,
const
char
*
name
,
char
*
dst
,
size_t
dst_len
)
{
char
*
dst
,
size_t
dst_len
,
int
n
)
{
const
char
*
p
,
*
e
,
*
s
;
size_t
name_len
;
int
len
;
...
...
@@ -5014,11 +5014,15 @@ static int get_var(const char *data, size_t data_len, const char *name,
len
=
-
1
;
dst
[
0
]
=
'\0'
;
int
i
=
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
))
{
if
(
n
!=
i
++
)
continue
;
// Point p to variable value
p
+=
name_len
+
1
;
...
...
@@ -5046,10 +5050,15 @@ static int get_var(const char *data, size_t data_len, const char *name,
int
mg_get_var
(
const
struct
mg_connection
*
conn
,
const
char
*
name
,
char
*
dst
,
size_t
dst_len
)
{
return
mg_get_n_var
(
conn
,
name
,
dst
,
dst_len
,
0
);
}
int
mg_get_n_var
(
const
struct
mg_connection
*
conn
,
const
char
*
name
,
char
*
dst
,
size_t
dst_len
,
int
n
)
{
int
len
=
get_var
(
conn
->
query_string
,
conn
->
query_string
==
NULL
?
0
:
strlen
(
conn
->
query_string
),
name
,
dst
,
dst_len
);
strlen
(
conn
->
query_string
),
name
,
dst
,
dst_len
,
n
);
if
(
len
==
-
1
)
{
len
=
get_var
(
conn
->
content
,
conn
->
content_len
,
name
,
dst
,
dst_len
)
;
len
=
get_var
(
conn
->
content
,
conn
->
content_len
,
name
,
dst
,
dst_len
,
n
);
;
}
return
len
;
}
...
...
mongoose.h
View file @
c06abbc5
...
...
@@ -119,6 +119,8 @@ const char *mg_get_header(const struct mg_connection *, const char *name);
const
char
*
mg_get_mime_type
(
const
char
*
name
,
const
char
*
default_mime_type
);
int
mg_get_var
(
const
struct
mg_connection
*
conn
,
const
char
*
var_name
,
char
*
buf
,
size_t
buf_len
);
int
mg_get_n_var
(
const
struct
mg_connection
*
conn
,
const
char
*
var_name
,
char
*
buf
,
size_t
buf_len
,
int
n
);
int
mg_parse_header
(
const
char
*
hdr
,
const
char
*
var_name
,
char
*
buf
,
size_t
);
int
mg_parse_multipart
(
const
char
*
buf
,
int
buf_len
,
char
*
var_name
,
int
var_name_len
,
...
...
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