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
00a23ee3
Commit
00a23ee3
authored
9 years ago
by
rojer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Good bye osdep.h, you won't be missed
PUBLISHED_FROM=f08a8324dfde5f9e22eee0e5e4dbae0e3d45cb3f
parent
51ad50a6
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
419 additions
and
143 deletions
+419
-143
Makefile
examples/ESP8266_RTOS/Makefile
+1
-1
Makefile
examples/ESP8266_RTOS/user/Makefile
+6
-3
esp_libc.c
examples/ESP8266_RTOS/user/esp_libc.c
+6
-1
user_main.c
examples/ESP8266_RTOS/user/user_main.c
+7
-2
mongoose.c
mongoose.c
+28
-22
mongoose.h
mongoose.h
+371
-114
No files found.
examples/ESP8266_RTOS/Makefile
View file @
00a23ee3
...
...
@@ -55,7 +55,7 @@ LINKFLAGS_eagle.app.v6 = \
-u
call_user_start
\
-Wl,-static
\
-Wl,--start-group
\
-lc
irom
\
-lc
\
-lgcc
\
-lhal
\
-lphy
\
...
...
This diff is collapsed.
Click to expand it.
examples/ESP8266_RTOS/user/Makefile
View file @
00a23ee3
...
...
@@ -23,11 +23,14 @@ endif
# makefile at its root level - these are then overridden
# for a subtree within the makefile rooted therein
#
DEFINES
+=
-DMG_DISABLE_DAV
-DMG_DISABLE_SYNC_RESOLVER
-DMG_DISABLE_CGI
\
-DMG_DISABLE_SOCKETPAIR
-DMG_DISABLE_DIRECTORY_LISTING
\
DEFINES
+=
-DMG_LOCALS
\
-DMG_NO_BSD_SOCKETS
\
-DMG_DISABLE_FILESYSTEM
\
-DMG_DISABLE_STDIO
\
-DMG_MAX_HTTP_HEADERS
=
20
-DMG_MAX_HTTP_REQUEST_SIZE
=
1024
\
-DMG_MAX_PATH
=
40
-DMG_MAX_HTTP_SEND_IOBUF
=
1024
\
-DMG_ESP8266
-DRTOS_SDK
-DMG_LWIP
-DRTOS_SDK
-DMG_LWIP
-DLWIP_TIMEVAL_PRIVATE
=
0
\
-DMG_INTERNAL
=
#############################################################
# Recursion Magic - Don't touch this!!
...
...
This diff is collapsed.
Click to expand it.
examples/ESP8266_RTOS/user/esp_libc.c
View file @
00a23ee3
...
...
@@ -16,6 +16,7 @@
#include "esp_common.h"
/* Makes fprintf(stdout) and stderr work. */
/*
_ssize_t _write_r(struct _reent *r, int fd, void *buf, size_t len) {
if (fd == 1 || fd == 2) {
size_t i;
...
...
@@ -26,6 +27,7 @@ _ssize_t _write_r(struct _reent *r, int fd, void *buf, size_t len) {
}
return -1;
}
*/
/*
* You'll need to implement _open_r and friends if you want file operations. See
...
...
@@ -42,7 +44,6 @@ void abort(void) {
}
void
_exit
(
int
status
)
{
printf
(
"_exit(%d)
\n
"
,
status
);
abort
();
}
...
...
@@ -52,3 +53,7 @@ int _gettimeofday_r(struct _reent *r, struct timeval *tp, void *tzp) {
tp
->
tv_usec
=
time
%
1000000
;
return
0
;
}
long
int
random
(
void
)
{
return
os_random
();
}
This diff is collapsed.
Click to expand it.
examples/ESP8266_RTOS/user/user_main.c
View file @
00a23ee3
...
...
@@ -37,6 +37,7 @@ void ev_handler(struct mg_connection *nc, int ev, void *p) {
case
MG_EV_HTTP_REQUEST
:
{
char
addr
[
32
];
struct
http_message
*
hm
=
(
struct
http_message
*
)
p
;
(
void
)
hm
;
mg_sock_addr_to_str
(
&
nc
->
sa
,
addr
,
sizeof
(
addr
),
MG_SOCK_STRINGIFY_IP
|
MG_SOCK_STRINGIFY_PORT
);
LOG
(
LL_INFO
,
...
...
@@ -100,9 +101,13 @@ xTaskHandle s_mg_task_handle;
void
user_init
(
void
)
{
uart_div_modify
(
0
,
UART_CLK_FREQ
/
115200
);
setvbuf
(
stdout
,
NULL
,
_IONBF
,
0
);
setvbuf
(
stderr
,
NULL
,
_IONBF
,
0
);
//
setvbuf(stdout, NULL, _IONBF, 0);
//
setvbuf(stderr, NULL, _IONBF, 0);
xTaskCreate
(
mg_task
,
(
const
signed
char
*
)
"mongoose"
,
MG_TASK_STACK_SIZE
,
NULL
,
MG_TASK_PRIORITY
,
&
s_mg_task_handle
);
}
void
call_user_start
(
void
)
{
user_init
();
}
This diff is collapsed.
Click to expand it.
mongoose.c
View file @
00a23ee3
...
...
@@ -76,8 +76,7 @@ MG_INTERNAL int mg_parse_address(const char *str, union socket_address *sa,
int
*
proto
,
char
*
host
,
size_t
host_len
);
MG_INTERNAL
void
mg_call
(
struct
mg_connection
*
nc
,
mg_event_handler_t
ev_handler
,
int
ev
,
void
*
ev_data
);
MG_INTERNAL
void
mg_forward
(
struct
mg_connection
*
from
,
struct
mg_connection
*
to
);
void
mg_forward
(
struct
mg_connection
*
from
,
struct
mg_connection
*
to
);
MG_INTERNAL
void
mg_add_conn
(
struct
mg_mgr
*
mgr
,
struct
mg_connection
*
c
);
MG_INTERNAL
void
mg_remove_conn
(
struct
mg_connection
*
c
);
MG_INTERNAL
size_t
recv_avail_size
(
struct
mg_connection
*
conn
,
size_t
max
);
...
...
@@ -251,6 +250,7 @@ void cs_base64_encode(const unsigned char *src, int src_len, char *dst) {
#undef BASE64_OUT
#undef BASE64_FLUSH
#ifndef CS_DISABLE_STDIO
#define BASE64_OUT(ch) \
do { \
fprintf(f, "%c", (ch)); \
...
...
@@ -265,6 +265,7 @@ void cs_fprint_base64(FILE *f, const unsigned char *src, int src_len) {
#undef BASE64_OUT
#undef BASE64_FLUSH
#endif
/* !CS_DISABLE_STDIO */
/* Convert one byte of encoded base64 input stream to 6-bit chunk */
static
unsigned
char
from_b64
(
unsigned
char
ch
)
{
...
...
@@ -346,6 +347,7 @@ enum cs_log_level s_cs_log_level =
LL_ERROR
;
#endif
#ifndef CS_DISABLE_STDIO
void
cs_log_printf
(
const
char
*
fmt
,
...)
{
va_list
ap
;
va_start
(
ap
,
fmt
);
...
...
@@ -354,6 +356,7 @@ void cs_log_printf(const char *fmt, ...) {
fputc
(
'\n'
,
stderr
);
fflush
(
stderr
);
}
#endif
/* !CS_DISABLE_STDIO */
void
cs_log_set_level
(
enum
cs_log_level
level
)
{
s_cs_log_level
=
level
;
...
...
@@ -368,7 +371,6 @@ void cs_log_set_level(enum cs_log_level level) {
#ifndef EXCLUDE_COMMON
/* Amalgamated: #include "common/osdep.h" */
/* Amalgamated: #include "common/cs_dirent.h" */
/*
...
...
@@ -1630,7 +1632,7 @@ void cs_hmac_sha1(const unsigned char *key, size_t keylen,
#ifndef EXCLUDE_COMMON
/* Amalgamated: #include "common/
osdep
.h" */
/* Amalgamated: #include "common/
platform
.h" */
/* Amalgamated: #include "common/str_util.h" */
#ifdef _MG_PROVIDE_STRNLEN
...
...
@@ -2038,7 +2040,7 @@ void mg_mgr_init(struct mg_mgr *m, void *user_data) {
WSADATA
data
;
WSAStartup
(
MAKEWORD
(
2
,
2
),
&
data
);
}
#elif
!defined(AVR_LIBC) && !defined(MG_ESP8266
)
#elif
defined(__unix__
)
/* Ignore SIGPIPE signal, so if client cancels the request, it
* won't kill the whole process. */
signal
(
SIGPIPE
,
SIG_IGN
);
...
...
@@ -3984,7 +3986,9 @@ int mg_normalize_uri_path(const struct mg_str *in, struct mg_str *out) {
enum
http_proto_data_type
{
DATA_NONE
,
DATA_FILE
,
DATA_PUT
,
DATA_CGI
};
struct
proto_data_http
{
FILE
*
fp
;
/* Opened file. */
#ifndef MG_DISABLE_FILESYSTEM
FILE
*
fp
;
/* Opened file. */
#endif
int64_t
cl
;
/* Content-Length. How many bytes to send. */
int64_t
sent
;
/* How many bytes have been already sent. */
int64_t
body_len
;
/* How many bytes of chunked body was reassembled. */
...
...
@@ -4521,17 +4525,18 @@ static void ws_handshake(struct mg_connection *nc, const struct mg_str *key) {
static
void
free_http_proto_data
(
struct
mg_connection
*
nc
)
{
struct
proto_data_http
*
dp
=
(
struct
proto_data_http
*
)
nc
->
proto_data
;
if
(
dp
!=
NULL
)
{
if
(
dp
->
fp
!=
NULL
)
{
fclose
(
dp
->
fp
);
}
if
(
dp
->
cgi_nc
!=
NULL
)
{
dp
->
cgi_nc
->
flags
|=
MG_F_CLOSE_IMMEDIATELY
;
}
#ifndef MG_DISABLE_FILESYSTEM
if
(
dp
->
fp
!=
NULL
)
fclose
(
dp
->
fp
);
#endif
#ifndef MG_DISABLE_CGI
if
(
dp
->
cgi_nc
!=
NULL
)
dp
->
cgi_nc
->
flags
|=
MG_F_CLOSE_IMMEDIATELY
;
#endif
MG_FREE
(
dp
);
nc
->
proto_data
=
NULL
;
}
}
#ifndef MG_DISABLE_FILESYSTEM
static
void
transfer_file_data
(
struct
mg_connection
*
nc
)
{
struct
proto_data_http
*
dp
=
(
struct
proto_data_http
*
)
nc
->
proto_data
;
char
buf
[
MG_MAX_HTTP_SEND_IOBUF
];
...
...
@@ -4583,6 +4588,7 @@ static void transfer_file_data(struct mg_connection *nc) {
}
}
}
#endif
/* MG_DISABLE_FILESYSTEM */
/*
* Parse chunked-encoded buffer. Return 0 if the buffer is not encoded, or
...
...
@@ -4689,7 +4695,7 @@ MG_INTERNAL size_t mg_handle_chunked(struct mg_connection *nc,
* If a big structure is declared in a big function, lx106 gcc will make it
* even bigger (round up to 4k, from 700 bytes of actual size).
*/
#ifdef
MG_ESP8266
#ifdef
__xtensa__
static
void
http_handler2
(
struct
mg_connection
*
nc
,
int
ev
,
void
*
ev_data
,
struct
http_message
*
hm
)
__attribute__
((
noinline
));
...
...
@@ -4700,11 +4706,11 @@ void http_handler(struct mg_connection *nc, int ev, void *ev_data) {
static
void
http_handler2
(
struct
mg_connection
*
nc
,
int
ev
,
void
*
ev_data
,
struct
http_message
*
hm
)
{
#else
#else
/* !__XTENSA__ */
void
http_handler
(
struct
mg_connection
*
nc
,
int
ev
,
void
*
ev_data
)
{
struct
http_message
shm
;
struct
http_message
*
hm
=
&
shm
;
#endif
#endif
/* __XTENSA__ */
struct
mbuf
*
io
=
&
nc
->
recv_mbuf
;
int
req_len
;
const
int
is_req
=
(
nc
->
listener
!=
NULL
);
...
...
@@ -4725,9 +4731,11 @@ void http_handler(struct mg_connection *nc, int ev, void *ev_data) {
free_http_proto_data
(
nc
);
}
#ifndef MG_DISABLE_FILESYSTEM
if
(
nc
->
proto_data
!=
NULL
)
{
transfer_file_data
(
nc
);
}
#endif
mg_call
(
nc
,
nc
->
handler
,
ev
,
ev_data
);
...
...
@@ -6273,10 +6281,6 @@ static pid_t start_process(const char *interp, const char *cmd, const char *env,
}
to_wchar
(
cmdline
,
wcmd
,
ARRAY_SIZE
(
wcmd
));
#if 0
printf("[%ls] [%ls]\n", full_dir, wcmd);
#endif
if
(
CreateProcessW
(
NULL
,
wcmd
,
NULL
,
NULL
,
TRUE
,
CREATE_NEW_PROCESS_GROUP
,
(
void
*
)
env
,
full_dir
,
&
si
,
&
pi
)
!=
0
)
{
spawn_stdio_thread
(
sock
,
a
[
1
],
push_to_stdin
);
...
...
@@ -7113,7 +7117,7 @@ void mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len,
if
(
inet_ntop
(
sa
->
sa
.
sa_family
,
addr
,
start
,
capacity
)
==
NULL
)
{
*
buf
=
'\0'
;
}
#elif defined(_WIN32) || defined(MG_
ESP8266
)
#elif defined(_WIN32) || defined(MG_
LWIP
)
/* Only Windoze Vista (and newer) have inet_ntop() */
strncpy
(
buf
,
inet_ntoa
(
sa
->
sin
.
sin_addr
),
len
);
#else
...
...
@@ -7199,9 +7203,10 @@ int mg_avprintf(char **buf, size_t size, const char *fmt, va_list ap) {
return
len
;
}
#if !defined(
NO_LIBC) && !defined(
MG_DISABLE_HEXDUMP)
#if !defined(MG_DISABLE_HEXDUMP)
void
mg_hexdump_connection
(
struct
mg_connection
*
nc
,
const
char
*
path
,
const
void
*
buf
,
int
num_bytes
,
int
ev
)
{
#if !defined(NO_LIBC) && !defined(MG_DISABLE_STDIO)
FILE
*
fp
=
NULL
;
char
*
hexbuf
,
src
[
60
],
dst
[
60
];
int
buf_size
=
num_bytes
*
5
+
100
;
...
...
@@ -7236,6 +7241,7 @@ void mg_hexdump_connection(struct mg_connection *nc, const char *path,
MG_FREE
(
hexbuf
);
}
if
(
fp
!=
stdin
&&
fp
!=
stdout
)
fclose
(
fp
);
#endif
}
#endif
...
...
@@ -7554,7 +7560,7 @@ static int parse_mqtt(struct mbuf *io, struct mg_mqtt_message *mm) {
var_len
=
2
;
break
;
default:
printf
(
"TODO: UNHANDLED COMMAND %d
\n
"
,
cmd
);
/* Unhandled command */
break
;
}
...
...
This diff is collapsed.
Click to expand it.
mongoose.h
View file @
00a23ee3
This diff is collapsed.
Click to expand it.
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