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
39b0b8e2
Commit
39b0b8e2
authored
Nov 23, 2016
by
Marko Mikulicic
Committed by
Cesanta Bot
Nov 23, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix clang formatting
PUBLISHED_FROM=ea64670e42ae58bbe26abee5d928f2afcd83bd46
parent
3a611864
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
80 additions
and
68 deletions
+80
-68
stdafx.h
examples/WinCE/http_server/stdafx.h
+13
-13
db_plugin_sqlite.c
examples/api_server/db_plugin_sqlite.c
+34
-22
http_client.c
examples/http_client/http_client.c
+1
-1
mqtt_client.c
examples/mqtt_client/mqtt_client.c
+2
-2
bleconfig.h
examples/nRF51/http/bleconfig.h
+0
-1
main.c
examples/nRF51/http/main.c
+6
-8
main.c
examples/nRF52/http/main.c
+6
-8
mongoose.c
mongoose.c
+14
-11
mongoose.h
mongoose.h
+4
-2
No files found.
examples/WinCE/http_server/stdafx.h
View file @
39b0b8e2
...
...
@@ -8,7 +8,8 @@
#pragma comment(linker, "/nodefaultlib:libc.lib")
#pragma comment(linker, "/nodefaultlib:libcd.lib")
// NOTE - this value is not strongly correlated to the Windows CE OS version being targeted
// NOTE - this value is not strongly correlated to the Windows CE OS version
// being targeted
#define WINVER _WIN32_WCE
#include <ceconfig.h>
...
...
@@ -23,9 +24,7 @@
#include <windows.h>
#include <aygshell.h>
#pragma comment(lib, "aygshell.lib")
#pragma comment(lib, "aygshell.lib")
#include <stdio.h>
#include <tchar.h>
...
...
@@ -40,15 +39,16 @@
#include "DeviceResolutionAware.h"
#endif
#if _WIN32_WCE < 0x500 && ( defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP) )
#pragma comment(lib, "ccrtrtti.lib")
#ifdef _X86_
#if defined(_DEBUG)
#pragma comment(lib, "libcmtx86d.lib")
#else
#pragma comment(lib, "libcmtx86.lib")
#endif
#endif
#if _WIN32_WCE < 0x500 && \
(
defined
(
WIN32_PLATFORM_PSPC
)
||
defined
(
WIN32_PLATFORM_WFSP
))
#pragma comment(lib, "ccrtrtti.lib")
#ifdef _X86_
#if defined(_DEBUG)
#pragma comment(lib, "libcmtx86d.lib")
#else
#pragma comment(lib, "libcmtx86.lib")
#endif
#endif
#endif
#include <altcecrt.h>
...
...
examples/api_server/db_plugin_sqlite.c
View file @
39b0b8e2
...
...
@@ -8,10 +8,11 @@
void
*
db_open
(
const
char
*
db_path
)
{
sqlite3
*
db
=
NULL
;
if
(
sqlite3_open_v2
(
db_path
,
&
db
,
SQLITE_OPEN_READWRITE
|
SQLITE_OPEN_CREATE
|
SQLITE_OPEN_FULLMUTEX
,
NULL
)
==
SQLITE_OK
)
{
sqlite3_exec
(
db
,
"CREATE TABLE IF NOT EXISTS kv(key PRIMARY KEY, val);"
,
0
,
0
,
0
);
if
(
sqlite3_open_v2
(
db_path
,
&
db
,
SQLITE_OPEN_READWRITE
|
SQLITE_OPEN_CREATE
|
SQLITE_OPEN_FULLMUTEX
,
NULL
)
==
SQLITE_OK
)
{
sqlite3_exec
(
db
,
"CREATE TABLE IF NOT EXISTS kv(key PRIMARY KEY, val);"
,
0
,
0
,
0
);
}
return
db
;
}
...
...
@@ -27,12 +28,12 @@ static void op_set(struct mg_connection *nc, const struct http_message *hm,
const
struct
mg_str
*
key
,
void
*
db
)
{
sqlite3_stmt
*
stmt
=
NULL
;
char
value
[
200
];
const
struct
mg_str
*
body
=
hm
->
query_string
.
len
>
0
?
&
hm
->
query_string
:
&
hm
->
body
;
const
struct
mg_str
*
body
=
hm
->
query_string
.
len
>
0
?
&
hm
->
query_string
:
&
hm
->
body
;
mg_get_http_var
(
body
,
"value"
,
value
,
sizeof
(
value
));
if
(
sqlite3_prepare_v2
(
db
,
"INSERT OR REPLACE INTO kv VALUES (?, ?);"
,
-
1
,
&
stmt
,
NULL
)
==
SQLITE_OK
)
{
if
(
sqlite3_prepare_v2
(
db
,
"INSERT OR REPLACE INTO kv VALUES (?, ?);"
,
-
1
,
&
stmt
,
NULL
)
==
SQLITE_OK
)
{
sqlite3_bind_text
(
stmt
,
1
,
key
->
p
,
key
->
len
,
SQLITE_STATIC
);
sqlite3_bind_text
(
stmt
,
2
,
value
,
strlen
(
value
),
SQLITE_STATIC
);
sqlite3_step
(
stmt
);
...
...
@@ -48,23 +49,26 @@ static void op_get(struct mg_connection *nc, const struct http_message *hm,
int
result
;
(
void
)
hm
;
if
(
sqlite3_prepare_v2
(
db
,
"SELECT val FROM kv WHERE key = ?;"
,
-
1
,
&
stmt
,
NULL
)
==
SQLITE_OK
)
{
if
(
sqlite3_prepare_v2
(
db
,
"SELECT val FROM kv WHERE key = ?;"
,
-
1
,
&
stmt
,
NULL
)
==
SQLITE_OK
)
{
sqlite3_bind_text
(
stmt
,
1
,
key
->
p
,
key
->
len
,
SQLITE_STATIC
);
result
=
sqlite3_step
(
stmt
);
data
=
(
char
*
)
sqlite3_column_text
(
stmt
,
0
);
if
((
result
==
SQLITE_OK
||
result
==
SQLITE_ROW
)
&&
data
!=
NULL
)
{
mg_printf
(
nc
,
"HTTP/1.1 200 OK
\r\n
"
mg_printf
(
nc
,
"HTTP/1.1 200 OK
\r\n
"
"Content-Type: text/plain
\r\n
"
"Content-Length: %d
\r\n\r\n
%s"
,
(
int
)
strlen
(
data
),
data
);
}
else
{
mg_printf
(
nc
,
"%s"
,
"HTTP/1.1 404 Not Found
\r\n
"
mg_printf
(
nc
,
"%s"
,
"HTTP/1.1 404 Not Found
\r\n
"
"Content-Length: 0
\r\n\r\n
"
);
}
sqlite3_finalize
(
stmt
);
}
else
{
mg_printf
(
nc
,
"%s"
,
"HTTP/1.1 500 Server Error
\r\n
"
mg_printf
(
nc
,
"%s"
,
"HTTP/1.1 500 Server Error
\r\n
"
"Content-Length: 0
\r\n\r\n
"
);
}
}
...
...
@@ -75,19 +79,21 @@ static void op_del(struct mg_connection *nc, const struct http_message *hm,
int
result
;
(
void
)
hm
;
if
(
sqlite3_prepare_v2
(
db
,
"DELETE FROM kv WHERE key = ?;"
,
-
1
,
&
stmt
,
NULL
)
==
SQLITE_OK
)
{
if
(
sqlite3_prepare_v2
(
db
,
"DELETE FROM kv WHERE key = ?;"
,
-
1
,
&
stmt
,
NULL
)
==
SQLITE_OK
)
{
sqlite3_bind_text
(
stmt
,
1
,
key
->
p
,
key
->
len
,
SQLITE_STATIC
);
result
=
sqlite3_step
(
stmt
);
if
(
result
==
SQLITE_OK
||
result
==
SQLITE_ROW
)
{
mg_printf
(
nc
,
"%s"
,
"HTTP/1.1 200 OK
\r\n
Content-Length: 0
\r\n\r\n
"
);
}
else
{
mg_printf
(
nc
,
"%s"
,
"HTTP/1.1 404 Not Found
\r\n
"
mg_printf
(
nc
,
"%s"
,
"HTTP/1.1 404 Not Found
\r\n
"
"Content-Length: 0
\r\n\r\n
"
);
}
sqlite3_finalize
(
stmt
);
}
else
{
mg_printf
(
nc
,
"%s"
,
"HTTP/1.1 500 Server Error
\r\n
"
mg_printf
(
nc
,
"%s"
,
"HTTP/1.1 500 Server Error
\r\n
"
"Content-Length: 0
\r\n\r\n
"
);
}
}
...
...
@@ -95,13 +101,19 @@ static void op_del(struct mg_connection *nc, const struct http_message *hm,
void
db_op
(
struct
mg_connection
*
nc
,
const
struct
http_message
*
hm
,
const
struct
mg_str
*
key
,
void
*
db
,
int
op
)
{
switch
(
op
)
{
case
API_OP_GET
:
op_get
(
nc
,
hm
,
key
,
db
);
break
;
case
API_OP_SET
:
op_set
(
nc
,
hm
,
key
,
db
);
break
;
case
API_OP_DEL
:
op_del
(
nc
,
hm
,
key
,
db
);
break
;
case
API_OP_GET
:
op_get
(
nc
,
hm
,
key
,
db
);
break
;
case
API_OP_SET
:
op_set
(
nc
,
hm
,
key
,
db
);
break
;
case
API_OP_DEL
:
op_del
(
nc
,
hm
,
key
,
db
);
break
;
default:
mg_printf
(
nc
,
"%s"
,
"HTTP/1.0 501 Not Implemented
\r\n
"
mg_printf
(
nc
,
"%s"
,
"HTTP/1.0 501 Not Implemented
\r\n
"
"Content-Length: 0
\r\n\r\n
"
);
break
;
}
}
examples/http_client/http_client.c
View file @
39b0b8e2
...
...
@@ -32,7 +32,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
s_exit_flag
=
1
;
break
;
case
MG_EV_CLOSE
:
if
(
s_exit_flag
==
0
)
{
if
(
s_exit_flag
==
0
)
{
printf
(
"Server closed connection
\n
"
);
s_exit_flag
=
1
;
}
...
...
examples/mqtt_client/mqtt_client.c
View file @
39b0b8e2
...
...
@@ -65,8 +65,8 @@ static void ev_handler(struct mg_connection *nc, int ev, void *p) {
mg_hexdump(nc->recv_mbuf.buf, msg->payload.len, hex, sizeof(hex));
printf("Got incoming message %.*s:\n%s", (int)msg->topic.len, msg->topic.p, hex);
#else
printf
(
"Got incoming message %.*s: %.*s
\n
"
,
(
int
)
msg
->
topic
.
len
,
msg
->
topic
.
p
,
(
int
)
msg
->
payload
.
len
,
msg
->
payload
.
p
);
printf
(
"Got incoming message %.*s: %.*s
\n
"
,
(
int
)
msg
->
topic
.
len
,
msg
->
topic
.
p
,
(
int
)
msg
->
payload
.
len
,
msg
->
payload
.
p
);
#endif
printf
(
"Forwarding to /test
\n
"
);
...
...
examples/nRF51/http/bleconfig.h
View file @
39b0b8e2
...
...
@@ -5,4 +5,3 @@
void
bleconfig_init
(
void
);
void
bleconfig_poll
(
void
);
examples/nRF51/http/main.c
View file @
39b0b8e2
...
...
@@ -10,12 +10,12 @@
/*
* This is a callback invoked by Mongoose to signal that a poll is needed soon.
* Since we're in a tight polling loop anyway (see below), we don't need to do anything.
* Since we're in a tight polling loop anyway (see below), we don't need to do
* anything.
*/
void
mg_lwip_mgr_schedule_poll
(
struct
mg_mgr
*
mgr
)
{
}
// Define an event handler function
void
ev_handler
(
struct
mg_connection
*
nc
,
int
ev
,
void
*
ev_data
)
{
if
(
ev
==
MG_EV_POLL
)
return
;
...
...
@@ -53,13 +53,10 @@ void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
}
}
/**
* @brief Function for application main entry.
*/
int
main
(
void
)
{
int
main
(
void
)
{
cs_log_set_file
(
stdout
);
bleconfig_init
();
...
...
@@ -76,7 +73,9 @@ int main(void)
struct
mg_connection
*
nc
=
NULL
;
memset
(
&
opts
,
0x00
,
sizeof
(
opts
));
opts
.
error_string
=
&
err
;
nc
=
mg_bind_opt
(
&
mgr
,
"80"
,
ev_handler
,
opts
);
// Create listening connection and add it to the event manager
nc
=
mg_bind_opt
(
&
mgr
,
"80"
,
ev_handler
,
opts
);
// Create listening connection and add it to the event manager
if
(
nc
==
NULL
)
{
printf
(
"Failed to create listener: %s
\n
"
,
err
);
return
1
;
...
...
@@ -88,5 +87,4 @@ int main(void)
mg_mgr_poll
(
&
mgr
,
0
);
}
}
}
examples/nRF52/http/main.c
View file @
39b0b8e2
...
...
@@ -10,12 +10,12 @@
/*
* This is a callback invoked by Mongoose to signal that a poll is needed soon.
* Since we're in a tight polling loop anyway (see below), we don't need to do anything.
* Since we're in a tight polling loop anyway (see below), we don't need to do
* anything.
*/
void
mg_lwip_mgr_schedule_poll
(
struct
mg_mgr
*
mgr
)
{
}
// Define an event handler function
void
ev_handler
(
struct
mg_connection
*
nc
,
int
ev
,
void
*
ev_data
)
{
if
(
ev
==
MG_EV_POLL
)
return
;
...
...
@@ -53,13 +53,10 @@ void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
}
}
/**
* @brief Function for application main entry.
*/
int
main
(
void
)
{
int
main
(
void
)
{
cs_log_set_file
(
stdout
);
bleconfig_init
();
...
...
@@ -76,7 +73,9 @@ int main(void)
struct
mg_connection
*
nc
=
NULL
;
memset
(
&
opts
,
0x00
,
sizeof
(
opts
));
opts
.
error_string
=
&
err
;
nc
=
mg_bind_opt
(
&
mgr
,
"80"
,
ev_handler
,
opts
);
// Create listening connection and add it to the event manager
nc
=
mg_bind_opt
(
&
mgr
,
"80"
,
ev_handler
,
opts
);
// Create listening connection and add it to the event manager
if
(
nc
==
NULL
)
{
printf
(
"Failed to create listener: %s
\n
"
,
err
);
return
1
;
...
...
@@ -91,5 +90,4 @@ int main(void)
mg_mgr_free
(
&
mgr
);
return
0
;
}
}
mongoose.c
View file @
39b0b8e2
...
...
@@ -2695,7 +2695,7 @@ struct mg_connection *mg_connect_opt(struct mg_mgr *mgr, const char *address,
if
(
strcmp
(
opts
.
ssl_server_name
,
"*"
)
!=
0
)
{
params
.
server_name
=
opts
.
ssl_server_name
;
}
}
else
if
(
rc
==
0
)
{
/* If it's a DNS name, use host. */
}
else
if
(
rc
==
0
)
{
/* If it's a DNS name, use host. */
params
.
server_name
=
host
;
}
}
...
...
@@ -3091,13 +3091,13 @@ static int mg_is_error(int n) {
int
err
=
mg_get_errno
();
return
(
n
<
0
&&
err
!=
EINPROGRESS
&&
err
!=
EWOULDBLOCK
#ifndef WINCE
&&
err
!=
EAGAIN
&&
err
!=
EINTR
&&
err
!=
EAGAIN
&&
err
!=
EINTR
#endif
#ifdef _WIN32
&&
WSAGetLastError
()
!=
WSAEINTR
&&
WSAGetLastError
()
!=
WSAEWOULDBLOCK
&&
WSAGetLastError
()
!=
WSAEINTR
&&
WSAGetLastError
()
!=
WSAEWOULDBLOCK
#endif
);
);
}
void
mg_socket_if_connect_tcp
(
struct
mg_connection
*
nc
,
...
...
@@ -4046,7 +4046,8 @@ enum mg_ssl_if_result mg_ssl_if_conn_init(
mg_set_cipher_list
(
ctx
->
ssl_ctx
);
if
(
!
(
nc
->
flags
&
MG_F_LISTENING
)
&&
(
ctx
->
ssl
=
SSL_new
(
ctx
->
ssl_ctx
))
==
NULL
)
{
if
(
!
(
nc
->
flags
&
MG_F_LISTENING
)
&&
(
ctx
->
ssl
=
SSL_new
(
ctx
->
ssl_ctx
))
==
NULL
)
{
MG_SET_PTRPTR
(
err_msg
,
"Failed to create SSL session"
);
return
MG_SSL_ERROR
;
}
...
...
@@ -4056,7 +4057,8 @@ enum mg_ssl_if_result mg_ssl_if_conn_init(
return
MG_SSL_OK
;
}
static
enum
mg_ssl_if_result
mg_ssl_if_ssl_err
(
struct
mg_connection
*
nc
,
int
res
)
{
static
enum
mg_ssl_if_result
mg_ssl_if_ssl_err
(
struct
mg_connection
*
nc
,
int
res
)
{
struct
mg_ssl_if_ctx
*
ctx
=
(
struct
mg_ssl_if_ctx
*
)
nc
->
ssl_if_data
;
int
err
=
SSL_get_error
(
ctx
->
ssl
,
res
);
if
(
err
==
SSL_ERROR_WANT_READ
)
return
MG_SSL_WANT_READ
;
...
...
@@ -4154,7 +4156,8 @@ static const char mg_s_cipher_list[] =
* Will be used if none are provided by the user in the certificate file.
*/
#if !MG_DISABLE_PFS && !defined(KR_VERSION)
static
const
char
mg_s_default_dh_params
[]
=
"\
static
const
char
mg_s_default_dh_params
[]
=
"\
-----BEGIN DH PARAMETERS-----
\n
\
MIIBCAKCAQEAlvbgD/qh9znWIlGFcV0zdltD7rq8FeShIqIhkQ0C7hYFThrBvF2E
\n
\
Z9bmgaP+sfQwGpVlv9mtaWjvERbu6mEG7JTkgmVUJrUt/wiRzwTaCXBqZkdUO8Tq
\n
\
...
...
@@ -7524,8 +7527,8 @@ struct mg_connection *mg_connect_http_opt(struct mg_mgr *mgr,
mg_printf
(
nc
,
"%s %s HTTP/1.1
\r\n
Host: %s
\r\n
Content-Length: %"
SIZE_T_FMT
"
\r\n
%.*s%s
\r\n
%s"
,
post_data
==
NULL
?
"GET"
:
"POST"
,
path
,
addr
,
post_data
==
NULL
?
0
:
strlen
(
post_data
),
(
int
)
auth
.
len
,
(
auth
.
buf
==
NULL
?
""
:
auth
.
buf
),
post_data
==
NULL
?
0
:
strlen
(
post_data
),
(
int
)
auth
.
len
,
(
auth
.
buf
==
NULL
?
""
:
auth
.
buf
),
extra_headers
==
NULL
?
""
:
extra_headers
,
post_data
==
NULL
?
""
:
post_data
);
...
...
@@ -9470,7 +9473,7 @@ void mg_send_mqtt_handshake_opt(struct mg_connection *nc, const char *client_id,
uint8_t
rem_len
;
uint16_t
keep_alive
;
uint16_t
len
;
struct
mg_mqtt_proto_data
*
pd
=
(
struct
mg_mqtt_proto_data
*
)
nc
->
proto_data
;
struct
mg_mqtt_proto_data
*
pd
=
(
struct
mg_mqtt_proto_data
*
)
nc
->
proto_data
;
/*
* 9: version_header(len, magic_string, version_number), 1: flags, 2:
...
...
mongoose.h
View file @
39b0b8e2
...
...
@@ -2982,9 +2982,11 @@ struct mg_ssl_if_conn_params {
const
char
*
server_name
;
};
enum
mg_ssl_if_result
mg_ssl_if_conn_init
(
struct
mg_connection
*
nc
,
const
struct
mg_ssl_if_conn_params
*
params
,
enum
mg_ssl_if_result
mg_ssl_if_conn_init
(
struct
mg_connection
*
nc
,
const
struct
mg_ssl_if_conn_params
*
params
,
const
char
**
err_msg
);
enum
mg_ssl_if_result
mg_ssl_if_conn_accept
(
struct
mg_connection
*
nc
,
struct
mg_connection
*
lc
);
enum
mg_ssl_if_result
mg_ssl_if_conn_accept
(
struct
mg_connection
*
nc
,
struct
mg_connection
*
lc
);
void
mg_ssl_if_conn_free
(
struct
mg_connection
*
nc
);
enum
mg_ssl_if_result
mg_ssl_if_handshake
(
struct
mg_connection
*
nc
);
...
...
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