Commit 00a23ee3 authored by rojer's avatar rojer

Good bye osdep.h, you won't be missed

    PUBLISHED_FROM=f08a8324dfde5f9e22eee0e5e4dbae0e3d45cb3f
parent 51ad50a6
...@@ -55,7 +55,7 @@ LINKFLAGS_eagle.app.v6 = \ ...@@ -55,7 +55,7 @@ LINKFLAGS_eagle.app.v6 = \
-u call_user_start \ -u call_user_start \
-Wl,-static \ -Wl,-static \
-Wl,--start-group \ -Wl,--start-group \
-lcirom \ -lc \
-lgcc \ -lgcc \
-lhal \ -lhal \
-lphy \ -lphy \
......
...@@ -23,11 +23,14 @@ endif ...@@ -23,11 +23,14 @@ endif
# makefile at its root level - these are then overridden # makefile at its root level - these are then overridden
# for a subtree within the makefile rooted therein # for a subtree within the makefile rooted therein
# #
DEFINES += -DMG_DISABLE_DAV -DMG_DISABLE_SYNC_RESOLVER -DMG_DISABLE_CGI \ DEFINES += -DMG_LOCALS \
-DMG_DISABLE_SOCKETPAIR -DMG_DISABLE_DIRECTORY_LISTING \ -DMG_NO_BSD_SOCKETS \
-DMG_DISABLE_FILESYSTEM \
-DMG_DISABLE_STDIO \
-DMG_MAX_HTTP_HEADERS=20 -DMG_MAX_HTTP_REQUEST_SIZE=1024 \ -DMG_MAX_HTTP_HEADERS=20 -DMG_MAX_HTTP_REQUEST_SIZE=1024 \
-DMG_MAX_PATH=40 -DMG_MAX_HTTP_SEND_IOBUF=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!! # Recursion Magic - Don't touch this!!
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "esp_common.h" #include "esp_common.h"
/* Makes fprintf(stdout) and stderr work. */ /* Makes fprintf(stdout) and stderr work. */
/*
_ssize_t _write_r(struct _reent *r, int fd, void *buf, size_t len) { _ssize_t _write_r(struct _reent *r, int fd, void *buf, size_t len) {
if (fd == 1 || fd == 2) { if (fd == 1 || fd == 2) {
size_t i; size_t i;
...@@ -26,6 +27,7 @@ _ssize_t _write_r(struct _reent *r, int fd, void *buf, size_t len) { ...@@ -26,6 +27,7 @@ _ssize_t _write_r(struct _reent *r, int fd, void *buf, size_t len) {
} }
return -1; return -1;
} }
*/
/* /*
* You'll need to implement _open_r and friends if you want file operations. See * You'll need to implement _open_r and friends if you want file operations. See
...@@ -42,7 +44,6 @@ void abort(void) { ...@@ -42,7 +44,6 @@ void abort(void) {
} }
void _exit(int status) { void _exit(int status) {
printf("_exit(%d)\n", status);
abort(); abort();
} }
...@@ -52,3 +53,7 @@ int _gettimeofday_r(struct _reent *r, struct timeval *tp, void *tzp) { ...@@ -52,3 +53,7 @@ int _gettimeofday_r(struct _reent *r, struct timeval *tp, void *tzp) {
tp->tv_usec = time % 1000000; tp->tv_usec = time % 1000000;
return 0; return 0;
} }
long int random(void) {
return os_random();
}
...@@ -37,6 +37,7 @@ void ev_handler(struct mg_connection *nc, int ev, void *p) { ...@@ -37,6 +37,7 @@ void ev_handler(struct mg_connection *nc, int ev, void *p) {
case MG_EV_HTTP_REQUEST: { case MG_EV_HTTP_REQUEST: {
char addr[32]; char addr[32];
struct http_message *hm = (struct http_message *) p; struct http_message *hm = (struct http_message *) p;
(void) hm;
mg_sock_addr_to_str(&nc->sa, addr, sizeof(addr), mg_sock_addr_to_str(&nc->sa, addr, sizeof(addr),
MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT); MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT);
LOG(LL_INFO, LOG(LL_INFO,
...@@ -100,9 +101,13 @@ xTaskHandle s_mg_task_handle; ...@@ -100,9 +101,13 @@ xTaskHandle s_mg_task_handle;
void user_init(void) { void user_init(void) {
uart_div_modify(0, UART_CLK_FREQ / 115200); uart_div_modify(0, UART_CLK_FREQ / 115200);
setvbuf(stdout, NULL, _IONBF, 0); // setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0); // setvbuf(stderr, NULL, _IONBF, 0);
xTaskCreate(mg_task, (const signed char *) "mongoose", MG_TASK_STACK_SIZE, xTaskCreate(mg_task, (const signed char *) "mongoose", MG_TASK_STACK_SIZE,
NULL, MG_TASK_PRIORITY, &s_mg_task_handle); NULL, MG_TASK_PRIORITY, &s_mg_task_handle);
} }
void call_user_start(void) {
user_init();
}
...@@ -76,8 +76,7 @@ MG_INTERNAL int mg_parse_address(const char *str, union socket_address *sa, ...@@ -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); int *proto, char *host, size_t host_len);
MG_INTERNAL void mg_call(struct mg_connection *nc, MG_INTERNAL void mg_call(struct mg_connection *nc,
mg_event_handler_t ev_handler, int ev, void *ev_data); mg_event_handler_t ev_handler, int ev, void *ev_data);
MG_INTERNAL void mg_forward(struct mg_connection *from, void mg_forward(struct mg_connection *from, struct mg_connection *to);
struct mg_connection *to);
MG_INTERNAL void mg_add_conn(struct mg_mgr *mgr, struct mg_connection *c); 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 void mg_remove_conn(struct mg_connection *c);
MG_INTERNAL size_t recv_avail_size(struct mg_connection *conn, size_t max); 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) { ...@@ -251,6 +250,7 @@ void cs_base64_encode(const unsigned char *src, int src_len, char *dst) {
#undef BASE64_OUT #undef BASE64_OUT
#undef BASE64_FLUSH #undef BASE64_FLUSH
#ifndef CS_DISABLE_STDIO
#define BASE64_OUT(ch) \ #define BASE64_OUT(ch) \
do { \ do { \
fprintf(f, "%c", (ch)); \ fprintf(f, "%c", (ch)); \
...@@ -265,6 +265,7 @@ void cs_fprint_base64(FILE *f, const unsigned char *src, int src_len) { ...@@ -265,6 +265,7 @@ void cs_fprint_base64(FILE *f, const unsigned char *src, int src_len) {
#undef BASE64_OUT #undef BASE64_OUT
#undef BASE64_FLUSH #undef BASE64_FLUSH
#endif /* !CS_DISABLE_STDIO */
/* Convert one byte of encoded base64 input stream to 6-bit chunk */ /* Convert one byte of encoded base64 input stream to 6-bit chunk */
static unsigned char from_b64(unsigned char ch) { static unsigned char from_b64(unsigned char ch) {
...@@ -346,6 +347,7 @@ enum cs_log_level s_cs_log_level = ...@@ -346,6 +347,7 @@ enum cs_log_level s_cs_log_level =
LL_ERROR; LL_ERROR;
#endif #endif
#ifndef CS_DISABLE_STDIO
void cs_log_printf(const char *fmt, ...) { void cs_log_printf(const char *fmt, ...) {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
...@@ -354,6 +356,7 @@ void cs_log_printf(const char *fmt, ...) { ...@@ -354,6 +356,7 @@ void cs_log_printf(const char *fmt, ...) {
fputc('\n', stderr); fputc('\n', stderr);
fflush(stderr); fflush(stderr);
} }
#endif /* !CS_DISABLE_STDIO */
void cs_log_set_level(enum cs_log_level level) { void cs_log_set_level(enum cs_log_level level) {
s_cs_log_level = level; s_cs_log_level = level;
...@@ -368,7 +371,6 @@ void cs_log_set_level(enum cs_log_level level) { ...@@ -368,7 +371,6 @@ void cs_log_set_level(enum cs_log_level level) {
#ifndef EXCLUDE_COMMON #ifndef EXCLUDE_COMMON
/* Amalgamated: #include "common/osdep.h" */
/* Amalgamated: #include "common/cs_dirent.h" */ /* Amalgamated: #include "common/cs_dirent.h" */
/* /*
...@@ -1630,7 +1632,7 @@ void cs_hmac_sha1(const unsigned char *key, size_t keylen, ...@@ -1630,7 +1632,7 @@ void cs_hmac_sha1(const unsigned char *key, size_t keylen,
#ifndef EXCLUDE_COMMON #ifndef EXCLUDE_COMMON
/* Amalgamated: #include "common/osdep.h" */ /* Amalgamated: #include "common/platform.h" */
/* Amalgamated: #include "common/str_util.h" */ /* Amalgamated: #include "common/str_util.h" */
#ifdef _MG_PROVIDE_STRNLEN #ifdef _MG_PROVIDE_STRNLEN
...@@ -2038,7 +2040,7 @@ void mg_mgr_init(struct mg_mgr *m, void *user_data) { ...@@ -2038,7 +2040,7 @@ void mg_mgr_init(struct mg_mgr *m, void *user_data) {
WSADATA data; WSADATA data;
WSAStartup(MAKEWORD(2, 2), &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 /* Ignore SIGPIPE signal, so if client cancels the request, it
* won't kill the whole process. */ * won't kill the whole process. */
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
...@@ -3984,7 +3986,9 @@ int mg_normalize_uri_path(const struct mg_str *in, struct mg_str *out) { ...@@ -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 }; enum http_proto_data_type { DATA_NONE, DATA_FILE, DATA_PUT, DATA_CGI };
struct proto_data_http { 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 cl; /* Content-Length. How many bytes to send. */
int64_t sent; /* How many bytes have been already sent. */ int64_t sent; /* How many bytes have been already sent. */
int64_t body_len; /* How many bytes of chunked body was reassembled. */ 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) { ...@@ -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) { static void free_http_proto_data(struct mg_connection *nc) {
struct proto_data_http *dp = (struct proto_data_http *) nc->proto_data; struct proto_data_http *dp = (struct proto_data_http *) nc->proto_data;
if (dp != NULL) { if (dp != NULL) {
if (dp->fp != NULL) { #ifndef MG_DISABLE_FILESYSTEM
fclose(dp->fp); if (dp->fp != NULL) fclose(dp->fp);
} #endif
if (dp->cgi_nc != NULL) { #ifndef MG_DISABLE_CGI
dp->cgi_nc->flags |= MG_F_CLOSE_IMMEDIATELY; if (dp->cgi_nc != NULL) dp->cgi_nc->flags |= MG_F_CLOSE_IMMEDIATELY;
} #endif
MG_FREE(dp); MG_FREE(dp);
nc->proto_data = NULL; nc->proto_data = NULL;
} }
} }
#ifndef MG_DISABLE_FILESYSTEM
static void transfer_file_data(struct mg_connection *nc) { static void transfer_file_data(struct mg_connection *nc) {
struct proto_data_http *dp = (struct proto_data_http *) nc->proto_data; struct proto_data_http *dp = (struct proto_data_http *) nc->proto_data;
char buf[MG_MAX_HTTP_SEND_IOBUF]; char buf[MG_MAX_HTTP_SEND_IOBUF];
...@@ -4583,6 +4588,7 @@ static void transfer_file_data(struct mg_connection *nc) { ...@@ -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 * 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, ...@@ -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 * 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). * 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, static void http_handler2(struct mg_connection *nc, int ev, void *ev_data,
struct http_message *hm) __attribute__((noinline)); struct http_message *hm) __attribute__((noinline));
...@@ -4700,11 +4706,11 @@ void http_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -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, static void http_handler2(struct mg_connection *nc, int ev, void *ev_data,
struct http_message *hm) { struct http_message *hm) {
#else #else /* !__XTENSA__ */
void http_handler(struct mg_connection *nc, int ev, void *ev_data) { void http_handler(struct mg_connection *nc, int ev, void *ev_data) {
struct http_message shm; struct http_message shm;
struct http_message *hm = &shm; struct http_message *hm = &shm;
#endif #endif /* __XTENSA__ */
struct mbuf *io = &nc->recv_mbuf; struct mbuf *io = &nc->recv_mbuf;
int req_len; int req_len;
const int is_req = (nc->listener != NULL); const int is_req = (nc->listener != NULL);
...@@ -4725,9 +4731,11 @@ void http_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -4725,9 +4731,11 @@ void http_handler(struct mg_connection *nc, int ev, void *ev_data) {
free_http_proto_data(nc); free_http_proto_data(nc);
} }
#ifndef MG_DISABLE_FILESYSTEM
if (nc->proto_data != NULL) { if (nc->proto_data != NULL) {
transfer_file_data(nc); transfer_file_data(nc);
} }
#endif
mg_call(nc, nc->handler, ev, ev_data); 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, ...@@ -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)); 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, if (CreateProcessW(NULL, wcmd, NULL, NULL, TRUE, CREATE_NEW_PROCESS_GROUP,
(void *) env, full_dir, &si, &pi) != 0) { (void *) env, full_dir, &si, &pi) != 0) {
spawn_stdio_thread(sock, a[1], push_to_stdin); 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, ...@@ -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) { if (inet_ntop(sa->sa.sa_family, addr, start, capacity) == NULL) {
*buf = '\0'; *buf = '\0';
} }
#elif defined(_WIN32) || defined(MG_ESP8266) #elif defined(_WIN32) || defined(MG_LWIP)
/* Only Windoze Vista (and newer) have inet_ntop() */ /* Only Windoze Vista (and newer) have inet_ntop() */
strncpy(buf, inet_ntoa(sa->sin.sin_addr), len); strncpy(buf, inet_ntoa(sa->sin.sin_addr), len);
#else #else
...@@ -7199,9 +7203,10 @@ int mg_avprintf(char **buf, size_t size, const char *fmt, va_list ap) { ...@@ -7199,9 +7203,10 @@ int mg_avprintf(char **buf, size_t size, const char *fmt, va_list ap) {
return len; 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, void mg_hexdump_connection(struct mg_connection *nc, const char *path,
const void *buf, int num_bytes, int ev) { const void *buf, int num_bytes, int ev) {
#if !defined(NO_LIBC) && !defined(MG_DISABLE_STDIO)
FILE *fp = NULL; FILE *fp = NULL;
char *hexbuf, src[60], dst[60]; char *hexbuf, src[60], dst[60];
int buf_size = num_bytes * 5 + 100; int buf_size = num_bytes * 5 + 100;
...@@ -7236,6 +7241,7 @@ void mg_hexdump_connection(struct mg_connection *nc, const char *path, ...@@ -7236,6 +7241,7 @@ void mg_hexdump_connection(struct mg_connection *nc, const char *path,
MG_FREE(hexbuf); MG_FREE(hexbuf);
} }
if (fp != stdin && fp != stdout) fclose(fp); if (fp != stdin && fp != stdout) fclose(fp);
#endif
} }
#endif #endif
...@@ -7554,7 +7560,7 @@ static int parse_mqtt(struct mbuf *io, struct mg_mqtt_message *mm) { ...@@ -7554,7 +7560,7 @@ static int parse_mqtt(struct mbuf *io, struct mg_mqtt_message *mm) {
var_len = 2; var_len = 2;
break; break;
default: default:
printf("TODO: UNHANDLED COMMAND %d\n", cmd); /* Unhandled command */
break; break;
} }
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment