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;
} }
......
...@@ -20,6 +20,9 @@ ...@@ -20,6 +20,9 @@
* license, as set out in <https://www.cesanta.com/license>. * license, as set out in <https://www.cesanta.com/license>.
*/ */
#ifndef _MG_COMMON_H_
#define _MG_COMMON_H_
#define MG_VERSION "6.2" #define MG_VERSION "6.2"
/* Local tweaks, applied before any of Mongoose's own headers. */ /* Local tweaks, applied before any of Mongoose's own headers. */
...@@ -30,53 +33,89 @@ ...@@ -30,53 +33,89 @@
#if defined(MG_ENABLE_DEBUG) && !defined(CS_ENABLE_DEBUG) #if defined(MG_ENABLE_DEBUG) && !defined(CS_ENABLE_DEBUG)
#define CS_ENABLE_DEBUG #define CS_ENABLE_DEBUG
#endif #endif
#if defined(MG_DISABLE_STDIO) && !defined(CS_DISABLE_STDIO)
#define CS_DISABLE_STDIO
#endif
/* All of the below features depend on filesystem access, disable them. */
#ifdef MG_DISABLE_FILESYSTEM
#ifndef MG_DISABLE_DAV
#define MG_DISABLE_DAV
#endif
#ifndef MG_DISABLE_CGI
#define MG_DISABLE_CGI
#endif
#ifndef MG_DISABLE_DIRECTORY_LISTING
#define MG_DISABLE_DIRECTORY_LISTING
#endif
#ifndef MG_DISABLE_DAV
#define MG_DISABLE_DAV
#endif
#endif /* MG_DISABLE_FILESYSTEM */
#ifdef MG_NO_BSD_SOCKETS
#ifndef MG_DISABLE_SYNC_RESOLVER
#define MG_DISABLE_SYNC_RESOLVER
#endif
#ifndef MG_DISABLE_SOCKETPAIR
#define MG_DISABLE_SOCKETPAIR
#endif
#endif /* MG_NO_BSD_SOCKETS */
#endif /* _MG_COMMON_H_ */
#ifndef _CS_PLATFORM_H_
#define _CS_PLATFORM_H_
/* /*
* Copyright (c) 2015 Cesanta Software Limited * For the "custom" platform, includes and dependencies can be
* All rights reserved * provided through mg_locals.h.
*/ */
#define CS_P_CUSTOM 0
#define CS_P_UNIX 1
#define CS_P_WINDOWS 2
#define CS_P_ESP_LWIP 3
#define CS_P_CC3200 4
#ifndef OSDEP_HEADER_INCLUDED /* If not specified explicitly, we guess platform by defines. */
#define OSDEP_HEADER_INCLUDED #ifndef CS_PLATFORM
#if !defined(MG_DISABLE_FILESYSTEM) && defined(AVR_NOFS) #if defined(__unix__) || defined(__APPLE__)
#define MG_DISABLE_FILESYSTEM #define CS_PLATFORM CS_P_UNIX
#elif defined(_WIN32)
#define CS_PLATFORM CS_P_WINDOWS
#endif #endif
#undef UNICODE /* Use ANSI WinAPI functions */ #ifndef CS_PLATFORM
#undef _UNICODE /* Use multibyte encoding on Windows */ #error "CS_PLATFORM is not specified and we couldn't guess it."
#define _MBCS /* Use multibyte encoding on Windows */
#define _INTEGRAL_MAX_BITS 64 /* Enable _stati64() on Windows */
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS /* Disable deprecation warning in VS2005+ */
#endif
#undef WIN32_LEAN_AND_MEAN /* Let windows.h always include winsock2.h */
#undef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600 /* For flockfile() on Linux */
#define __STDC_FORMAT_MACROS /* <inttypes.h> wants this for C++ */
#define __STDC_LIMIT_MACROS /* C++ wants that for INT64_MAX */
#ifndef _LARGEFILE_SOURCE
#define _LARGEFILE_SOURCE /* Enable fseeko() and ftello() functions */
#endif #endif
#define _FILE_OFFSET_BITS 64 /* Enable 64-bit file offsets */
#if !(defined(AVR_LIBC) || defined(PICOTCP)) #endif /* !defined(CS_PLATFORM) */
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h> /* Common stuff */
#include <time.h>
#include <signal.h> #ifdef __GNUC__
#endif #define NORETURN __attribute__((noreturn))
#define UNUSED __attribute__((unused))
#define NOINLINE __attribute__((noinline))
#define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#else
#define NORETURN
#define UNUSED
#define NOINLINE
#define WARN_UNUSED_RESULT
#endif /* __GNUC__ */
#ifndef BYTE_ORDER #ifndef ARRAY_SIZE
#define LITTLE_ENDIAN 0x41424344 #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
#define BIG_ENDIAN 0x44434241
#define PDP_ENDIAN 0x42414443
/* TODO(lsm): fix for big-endian machines. 'ABCD' is not portable */
/*#define BYTE_ORDER 'ABCD'*/
#define BYTE_ORDER LITTLE_ENDIAN
#endif #endif
#endif /* _CS_PLATFORM_H_ */
#ifndef _CS_PLATFORM_WINDOWS_H_
#define _CS_PLATFORM_WINDOWS_H_
#if CS_PLATFORM == CS_P_WINDOWS
/* /*
* MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015) * MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015)
* MSVC++ 12.0 _MSC_VER == 1800 (Visual Studio 2013) * MSVC++ 12.0 _MSC_VER == 1800 (Visual Studio 2013)
...@@ -94,34 +133,15 @@ ...@@ -94,34 +133,15 @@
#pragma warning(disable : 4204) /* missing c99 support */ #pragma warning(disable : 4204) /* missing c99 support */
#endif #endif
#ifdef PICOTCP
#define time(x) PICO_TIME()
#ifndef SOMAXCONN
#define SOMAXCONN (16)
#endif
#ifdef _POSIX_VERSION
#define signal(...)
#endif
#endif
#include <assert.h> #include <assert.h>
#include <ctype.h> #include <errno.h>
#include <limits.h> #include <fcntl.h>
#include <stdarg.h> #include <signal.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <sys/stat.h>
#ifndef va_copy
#ifdef __va_copy
#define va_copy __va_copy
#else
#define va_copy(x, y) (x) = (y)
#endif
#endif
#ifdef _WIN32
#define random() rand() #define random() rand()
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma comment(lib, "ws2_32.lib") /* Linking with winsock library */ #pragma comment(lib, "ws2_32.lib") /* Linking with winsock library */
...@@ -203,93 +223,321 @@ DIR *opendir(const char *name); ...@@ -203,93 +223,321 @@ DIR *opendir(const char *name);
int closedir(DIR *dir); int closedir(DIR *dir);
struct dirent *readdir(DIR *dir); struct dirent *readdir(DIR *dir);
#elif /* not _WIN32 */ defined(MG_CC3200) #ifndef va_copy
#ifdef __va_copy
#define va_copy __va_copy
#else
#define va_copy(x, y) (x) = (y)
#endif
#endif
#include <fcntl.h> #endif /* CS_PLATFORM == CS_P_WINDOWS */
#include <unistd.h> #endif /* _CS_PLATFORM_WINDOWS_H_ */
#include <cc3200_libc.h> #ifndef _CS_PLATFORM_UNIX_H_
#include <cc3200_socket.h> #define _CS_PLATFORM_UNIX_H_
#if CS_PLATFORM == CS_P_UNIX
#elif /* not CC3200 */ defined(MG_LWIP) #ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#endif
#include <lwip/sockets.h> /* <inttypes.h> wants this for C++ */
#include <lwip/netdb.h> #ifndef __STDC_FORMAT_MACROS
#include <lwip/dns.h> #define __STDC_FORMAT_MACROS
#endif
#if defined(MG_ESP8266) && defined(RTOS_SDK) /* C++ wants that for INT64_MAX */
#include <esp_libc.h> #ifndef __STDC_LIMIT_MACROS
#define random() os_random() #define __STDC_LIMIT_MACROS
#endif #endif
/* TODO(alashkin): check if zero is OK */ /* Enable fseeko() and ftello() functions */
#define SOMAXCONN 0 #ifndef _LARGEFILE_SOURCE
#include <stdlib.h> #define _LARGEFILE_SOURCE
#endif
#elif /* not ESP8266 RTOS */ !defined(NO_LIBC) && !defined(NO_BSD_SOCKETS) /* Enable 64-bit file offsets */
#ifndef _FILE_OFFSET_BITS
#define _FILE_OFFSET_BITS 64
#endif
#include <arpa/inet.h>
#include <assert.h>
#include <ctype.h>
#include <dirent.h> #include <dirent.h>
#include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <inttypes.h>
#include <math.h>
#include <netdb.h> #include <netdb.h>
#include <pthread.h>
#include <unistd.h>
#include <arpa/inet.h> /* For inet_pton() when MG_ENABLE_IPV6 is defined */
#include <netinet/in.h> #include <netinet/in.h>
#include <pthread.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/select.h> #include <sys/select.h>
#endif #include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#ifndef LWIP_PROVIDE_ERRNO typedef int sock_t;
#include <errno.h> #define INVALID_SOCKET (-1)
#define SIZE_T_FMT "zu"
typedef struct stat cs_stat_t;
#define DIRSEP '/'
#define to64(x) strtoll(x, NULL, 10)
#define INT64_FMT PRId64
#define INT64_X_FMT PRIx64
#define __cdecl
#ifndef va_copy
#ifdef __va_copy
#define va_copy __va_copy
#else
#define va_copy(x, y) (x) = (y)
#endif
#endif #endif
#ifndef _WIN32 #define closesocket(x) close(x)
#endif /* CS_PLATFORM == CS_P_UNIX */
#endif /* _CS_PLATFORM_UNIX_H_ */
#ifndef _CS_PLATFORM_ESP_LWIP_H_
#define _CS_PLATFORM_ESP_LWIP_H_
#if CS_PLATFORM == CS_P_ESP_LWIP
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdarg.h> #include <string.h>
#include <sys/stat.h>
#include <sys/time.h>
#ifndef AVR_LIBC #include <lwip/err.h>
#ifndef MG_ESP8266 #include <lwip/ip_addr.h>
#define closesocket(x) close(x) #include <lwip/inet.h>
#endif #include <lwip/netdb.h>
#ifndef __cdecl #include <lwip/dns.h>
#define __cdecl
#define LWIP_TIMEVAL_PRIVATE 0
#if LWIP_SOCKET
#include <lwip/sockets.h>
#define SOMAXCONN 10
#else
/* We really need the definitions from sockets.h. */
#undef LWIP_SOCKET
#define LWIP_SOCKET 1
#include <lwip/sockets.h>
#undef LWIP_SOCKET
#define LWIP_SOCKET 0
#endif #endif
typedef int sock_t;
#define INVALID_SOCKET (-1) #define INVALID_SOCKET (-1)
#define INT64_FMT PRId64
#define INT64_X_FMT PRIx64
#if defined(ESP8266) || defined(MG_ESP8266) || defined(MG_CC3200)
#define SIZE_T_FMT "u" #define SIZE_T_FMT "u"
#else typedef struct stat cs_stat_t;
#define SIZE_T_FMT "zu" #define DIRSEP '/'
#endif
#define to64(x) strtoll(x, NULL, 10) #define to64(x) strtoll(x, NULL, 10)
#define INT64_FMT PRId64
#define INT64_X_FMT PRIx64
#define __cdecl
#endif /* CS_PLATFORM == CS_P_ESP_LWIP */
#endif /* _CS_PLATFORM_ESP_LWIP_H_ */
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
#ifndef _CS_PLATFORM_CC3200_H_
#define _CS_PLATFORM_CC3200_H_
#if CS_PLATFORM == CS_P_CC3200
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stdint.h>
#include <time.h>
#include <simplelink.h>
#define SOMAXCONN 8
/* Undefine a bunch of conflicting symbols so we can use SDK defs verbatim. */
#undef FD_CLR
#undef FD_SET
#undef FD_ZERO
#undef FD_ISSET
#undef FD_SETSIZE
#undef fd_set
#undef EACCES
#undef EBADF
#undef EAGAIN
#undef EWOULDBLOCK
#undef ENOMEM
#undef EFAULT
#undef EINVAL
#undef EDESTADDRREQ
#undef EPROTOTYPE
#undef ENOPROTOOPT
#undef EPROTONOSUPPORT
#undef EOPNOTSUPP
#undef EAFNOSUPPORT
#undef EAFNOSUPPORT
#undef EADDRINUSE
#undef EADDRNOTAVAIL
#undef ENETUNREACH
#undef ENOBUFS
#undef EISCONN
#undef ENOTCONN
#undef ETIMEDOUT
#undef ECONNREFUSED
/* The following comes from $SDK/simplelink/include/socket.h */
/* clang-format off */
#define FD_SETSIZE SL_FD_SETSIZE
#define SOCK_STREAM SL_SOCK_STREAM
#define SOCK_DGRAM SL_SOCK_DGRAM
#define SOCK_RAW SL_SOCK_RAW
#define IPPROTO_TCP SL_IPPROTO_TCP
#define IPPROTO_UDP SL_IPPROTO_UDP
#define IPPROTO_RAW SL_IPPROTO_RAW
#define AF_INET SL_AF_INET
#define AF_INET6 SL_AF_INET6
#define AF_INET6_EUI_48 SL_AF_INET6_EUI_48
#define AF_RF SL_AF_RF
#define AF_PACKET SL_AF_PACKET
#define PF_INET SL_PF_INET
#define PF_INET6 SL_PF_INET6
#define INADDR_ANY SL_INADDR_ANY
#define ERROR SL_SOC_ERROR
#define INEXE SL_INEXE
#define EBADF SL_EBADF
#define ENSOCK SL_ENSOCK
#define EAGAIN SL_EAGAIN
#define EWOULDBLOCK SL_EWOULDBLOCK
#define ENOMEM SL_ENOMEM
#define EACCES SL_EACCES
#define EFAULT SL_EFAULT
#define EINVAL SL_EINVAL
#define EDESTADDRREQ SL_EDESTADDRREQ
#define EPROTOTYPE SL_EPROTOTYPE
#define ENOPROTOOPT SL_ENOPROTOOPT
#define EPROTONOSUPPORT SL_EPROTONOSUPPORT
#define ESOCKTNOSUPPORT SL_ESOCKTNOSUPPORT
#define EOPNOTSUPP SL_EOPNOTSUPP
#define EAFNOSUPPORT SL_EAFNOSUPPORT
#define EADDRINUSE SL_EADDRINUSE
#define EADDRNOTAVAIL SL_EADDRNOTAVAIL
#define ENETUNREACH SL_ENETUNREACH
#define ENOBUFS SL_ENOBUFS
#define EOBUFF SL_EOBUFF
#define EISCONN SL_EISCONN
#define ENOTCONN SL_ENOTCONN
#define ETIMEDOUT SL_ETIMEDOUT
#define ECONNREFUSED SL_ECONNREFUSED
#define SOL_SOCKET SL_SOL_SOCKET
#define IPPROTO_IP SL_IPPROTO_IP
#define SO_KEEPALIVE SL_SO_KEEPALIVE
#define SO_RCVTIMEO SL_SO_RCVTIMEO
#define SO_NONBLOCKING SL_SO_NONBLOCKING
#define IP_MULTICAST_IF SL_IP_MULTICAST_IF
#define IP_MULTICAST_TTL SL_IP_MULTICAST_TTL
#define IP_ADD_MEMBERSHIP SL_IP_ADD_MEMBERSHIP
#define IP_DROP_MEMBERSHIP SL_IP_DROP_MEMBERSHIP
#define socklen_t SlSocklen_t
#define timeval SlTimeval_t
#define sockaddr SlSockAddr_t
#define in6_addr SlIn6Addr_t
#define sockaddr_in6 SlSockAddrIn6_t
#define in_addr SlInAddr_t
#define sockaddr_in SlSockAddrIn_t
#define MSG_DONTWAIT SL_MSG_DONTWAIT
#define FD_SET SL_FD_SET
#define FD_CLR SL_FD_CLR
#define FD_ISSET SL_FD_ISSET
#define FD_ZERO SL_FD_ZERO
#define fd_set SlFdSet_t
#define socket sl_Socket
#define close sl_Close
#define accept sl_Accept
#define bind sl_Bind
#define listen sl_Listen
#define connect sl_Connect
#define select sl_Select
#define setsockopt sl_SetSockOpt
#define getsockopt sl_GetSockOpt
#define recv sl_Recv
#define recvfrom sl_RecvFrom
#define write sl_Write
#define send sl_Send
#define sendto sl_SendTo
/* rojer: gethostbyname() and sl_NetAppDnsGetHostByName are NOT compatible. */
/* #define gethostbyname sl_NetAppDnsGetHostByName */
#define htonl sl_Htonl
#define ntohl sl_Ntohl
#define htons sl_Htons
#define ntohs sl_Ntohs
/* clang-format on */
typedef int sock_t; typedef int sock_t;
#define INVALID_SOCKET (-1)
#define SIZE_T_FMT "u"
typedef struct stat cs_stat_t; typedef struct stat cs_stat_t;
#define DIRSEP '/' #define DIRSEP '/'
#endif /* !AVR_LIBC */ #define to64(x) strtoll(x, NULL, 10)
#define INT64_FMT PRId64
#define INT64_X_FMT PRIx64
#define __cdecl
#ifdef __APPLE__ #define closesocket(x) close(x)
int64_t strtoll(const char *str, char **endptr, int base);
#endif
#endif /* !_WIN32 */
#ifndef ARRAY_SIZE /* Some functions we implement for Mongoose. */
#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
#endif
#ifdef __GNUC__ const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
#define NORETURN __attribute__((noreturn)) char *inet_ntoa(struct in_addr in);
#define UNUSED __attribute__((unused)) int inet_pton(int af, const char *src, void *dst);
#define NOINLINE __attribute__((noinline))
#define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#else
#define NORETURN
#define UNUSED
#define NOINLINE
#define WARN_UNUSED_RESULT
#endif
#endif /* OSDEP_HEADER_INCLUDED */ void cc3200_set_non_blocking_mode(int fd);
struct hostent {
char *h_name; /* official name of host */
char **h_aliases; /* alias list */
int h_addrtype; /* host address type */
int h_length; /* length of address */
char **h_addr_list; /* list of addresses */
};
struct hostent *gethostbyname(const char *name);
struct timeval;
int gettimeofday(struct timeval *t, void *tz);
long int random(void);
#endif /* CS_PLATFORM == CS_P_CC3200 */
#endif /* _CS_PLATFORM_CC3200_H_ */
/* /*
* Copyright (c) 2014-2016 Cesanta Software Limited * Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved * All rights reserved
...@@ -313,6 +561,8 @@ enum cs_log_level { ...@@ -313,6 +561,8 @@ enum cs_log_level {
extern enum cs_log_level s_cs_log_level; extern enum cs_log_level s_cs_log_level;
void cs_log_set_level(enum cs_log_level level); void cs_log_set_level(enum cs_log_level level);
#ifndef CS_DISABLE_STDIO
void cs_log_printf(const char *fmt, ...); void cs_log_printf(const char *fmt, ...);
#define LOG(l, x) \ #define LOG(l, x) \
...@@ -335,6 +585,13 @@ void cs_log_printf(const char *fmt, ...); ...@@ -335,6 +585,13 @@ void cs_log_printf(const char *fmt, ...);
#endif #endif
#else /* CS_DISABLE_STDIO */
#define LOG(l, x)
#define DBG(x)
#endif
#endif /* _CS_DBG_H_ */ #endif /* _CS_DBG_H_ */
/* /*
* Copyright (c) 2014-2016 Cesanta Software Limited * Copyright (c) 2014-2016 Cesanta Software Limited
......
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