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
29454e22
Commit
29454e22
authored
May 20, 2015
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #524 from NickCis/array_variables
Implementing array varibles
parents
b9fead4d
d6cbf9f7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
4 deletions
+81
-4
Makefile
examples/array_vars/Makefile
+21
-0
array_vars.c
examples/array_vars/array_vars.c
+45
-0
mongoose.c
mongoose.c
+13
-4
mongoose.h
mongoose.h
+2
-0
No files found.
examples/array_vars/Makefile
0 → 100644
View file @
29454e22
# 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 @
29454e22
// Copyright (c) 2014 Cesanta Software
// All rights reserved
//
// This example demostrates how to use array get variables using mg_get_n_var
// $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
i
,
ret
;
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 @
29454e22
...
...
@@ -5015,10 +5015,10 @@ 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
;
int
i
,
len
;
if
(
dst
==
NULL
||
dst_len
==
0
)
{
len
=
-
2
;
...
...
@@ -5026,6 +5026,7 @@ static int get_var(const char *data, size_t data_len, const char *name,
len
=
-
1
;
dst
[
0
]
=
'\0'
;
}
else
{
i
=
0
;
name_len
=
strlen
(
name
);
e
=
data
+
data_len
;
len
=
-
1
;
...
...
@@ -5036,6 +5037,9 @@ static int get_var(const char *data, size_t data_len, const char *name,
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
;
...
...
@@ -5063,10 +5067,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 @
29454e22
...
...
@@ -121,6 +121,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