Commit e49f2bb1 authored by Johny Mattsson's avatar Johny Mattsson
Browse files

Remove conflicting libc, rename c_xx and os_xx to xx.

c_strtod and c_getenv are kept since strtod doesn't appear in the SDK's libc,
and we want our own c_getenv to initialize the Lua main anyway.
parent 3a3e9ee0
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "module.h" #include "module.h"
#include "c_limits.h" #include <limits.h>
#include "lauxlib.h" #include "lauxlib.h"
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "module.h" #include "module.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "c_math.h" #include <math.h>
#include "user_interface.h" #include "user_interface.h"
/****************************************************/ /****************************************************/
......
#include "module.h" #include "module.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "c_stdlib.h" #include <stdlib.h>
#include "c_string.h" #include <string.h>
#include "esp_misc.h" #include "esp_misc.h"
static const uint32_t bmp085_i2c_id = 0; static const uint32_t bmp085_i2c_id = 0;
......
...@@ -38,9 +38,9 @@ ...@@ -38,9 +38,9 @@
// #include <assert.h> // #include <assert.h>
#include "module.h" #include "module.h"
#include "c_string.h" #include <string.h>
#include "c_math.h" #include <math.h>
#include "c_limits.h" #include <limits.h>
#include "lauxlib.h" #include "lauxlib.h"
#include "flash_api.h" #include "flash_api.h"
#include "ctype.h" #include "ctype.h"
...@@ -340,7 +340,7 @@ static int json_integer_option(lua_State *l, int optindex, int *setting, ...@@ -340,7 +340,7 @@ static int json_integer_option(lua_State *l, int optindex, int *setting,
if (!lua_isnil(l, optindex)) { if (!lua_isnil(l, optindex)) {
value = luaL_checkinteger(l, optindex); value = luaL_checkinteger(l, optindex);
c_sprintf(errmsg, "expected integer between %d and %d", min, max); sprintf(errmsg, "expected integer between %d and %d", min, max);
luaL_argcheck(l, min <= value && value <= max, 1, errmsg); luaL_argcheck(l, min <= value && value <= max, 1, errmsg);
*setting = value; *setting = value;
} }
...@@ -774,8 +774,8 @@ static void json_append_number(lua_State *l, json_config_t *cfg, ...@@ -774,8 +774,8 @@ static void json_append_number(lua_State *l, json_config_t *cfg,
strbuf_ensure_empty_length(json, FPCONV_G_FMT_BUFSIZE); strbuf_ensure_empty_length(json, FPCONV_G_FMT_BUFSIZE);
// len = fpconv_g_fmt(strbuf_empty_ptr(json), num, cfg->encode_number_precision); // len = fpconv_g_fmt(strbuf_empty_ptr(json), num, cfg->encode_number_precision);
c_sprintf(strbuf_empty_ptr(json), LUA_NUMBER_FMT, (LUA_NUMBER)num); sprintf(strbuf_empty_ptr(json), LUA_NUMBER_FMT, (LUA_NUMBER)num);
len = c_strlen(strbuf_empty_ptr(json)); len = strlen(strbuf_empty_ptr(json));
strbuf_extend_length(json, len); strbuf_extend_length(json, len);
} }
...@@ -1148,7 +1148,7 @@ static int json_is_invalid_number(json_parse_t *json) ...@@ -1148,7 +1148,7 @@ static int json_is_invalid_number(json_parse_t *json)
return 0; /* Ordinary number */ return 0; /* Ordinary number */
} }
char tmp[4]; // conv to lower. because c_strncasecmp == c_strcmp char tmp[4]; // conv to lower. because strncasecmp == strcmp
int i; int i;
for (i = 0; i < 3; ++i) for (i = 0; i < 3; ++i)
{ {
...@@ -1160,9 +1160,9 @@ static int json_is_invalid_number(json_parse_t *json) ...@@ -1160,9 +1160,9 @@ static int json_is_invalid_number(json_parse_t *json)
tmp[3] = 0; tmp[3] = 0;
/* Reject inf/nan */ /* Reject inf/nan */
if (!c_strncasecmp(tmp, "inf", 3)) if (!strncasecmp(tmp, "inf", 3))
return 1; return 1;
if (!c_strncasecmp(tmp, "nan", 3)) if (!strncasecmp(tmp, "nan", 3))
return 1; return 1;
/* Pass all other numbers which may still be invalid, but /* Pass all other numbers which may still be invalid, but
...@@ -1238,17 +1238,17 @@ static void json_next_token(json_parse_t *json, json_token_t *token) ...@@ -1238,17 +1238,17 @@ static void json_next_token(json_parse_t *json, json_token_t *token)
} }
json_next_number_token(json, token); json_next_number_token(json, token);
return; return;
} else if (!c_strncmp(json->ptr, "true", 4)) { } else if (!strncmp(json->ptr, "true", 4)) {
token->type = T_BOOLEAN; token->type = T_BOOLEAN;
token->value.boolean = 1; token->value.boolean = 1;
json->ptr += 4; json->ptr += 4;
return; return;
} else if (!c_strncmp(json->ptr, "false", 5)) { } else if (!strncmp(json->ptr, "false", 5)) {
token->type = T_BOOLEAN; token->type = T_BOOLEAN;
token->value.boolean = 0; token->value.boolean = 0;
json->ptr += 5; json->ptr += 5;
return; return;
} else if (!c_strncmp(json->ptr, "null", 4)) { } else if (!strncmp(json->ptr, "null", 4)) {
token->type = T_NULL; token->type = T_NULL;
json->ptr += 4; json->ptr += 4;
return; return;
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "c_string.h" #include <string.h>
#include "c_stdlib.h" #include <stdlib.h>
#include "c_types.h" #include "c_types.h"
#include "mem.h" #include "mem.h"
...@@ -38,13 +38,13 @@ static void coap_received(void *arg, char *pdata, unsigned short len) ...@@ -38,13 +38,13 @@ static void coap_received(void *arg, char *pdata, unsigned short len)
// static uint8_t buf[MAX_MESSAGE_SIZE+1] = {0}; // +1 for string '\0' // static uint8_t buf[MAX_MESSAGE_SIZE+1] = {0}; // +1 for string '\0'
uint8_t buf[MAX_MESSAGE_SIZE+1] = {0}; // +1 for string '\0' uint8_t buf[MAX_MESSAGE_SIZE+1] = {0}; // +1 for string '\0'
c_memset(buf, 0, sizeof(buf)); // wipe prev data memset(buf, 0, sizeof(buf)); // wipe prev data
if (len > MAX_MESSAGE_SIZE) { if (len > MAX_MESSAGE_SIZE) {
NODE_DBG("Request Entity Too Large.\n"); // NOTE: should response 4.13 to client... NODE_DBG("Request Entity Too Large.\n"); // NOTE: should response 4.13 to client...
return; return;
} }
// c_memcpy(buf, pdata, len); // memcpy(buf, pdata, len);
size_t rsplen = coap_server_respond(pdata, len, buf, MAX_MESSAGE_SIZE+1); size_t rsplen = coap_server_respond(pdata, len, buf, MAX_MESSAGE_SIZE+1);
...@@ -53,12 +53,12 @@ static void coap_received(void *arg, char *pdata, unsigned short len) ...@@ -53,12 +53,12 @@ static void coap_received(void *arg, char *pdata, unsigned short len)
if (espconn_get_connection_info (pesp_conn, &pr, 0) != ESPCONN_OK) if (espconn_get_connection_info (pesp_conn, &pr, 0) != ESPCONN_OK)
return; return;
pesp_conn->proto.udp->remote_port = pr->remote_port; pesp_conn->proto.udp->remote_port = pr->remote_port;
os_memmove (pesp_conn->proto.udp->remote_ip, pr->remote_ip, 4); memmove (pesp_conn->proto.udp->remote_ip, pr->remote_ip, 4);
// The remot_info apparently should *not* be os_free()d, fyi // The remot_info apparently should *not* be free()d, fyi
espconn_sent(pesp_conn, (unsigned char *)buf, rsplen); espconn_sent(pesp_conn, (unsigned char *)buf, rsplen);
// c_memset(buf, 0, sizeof(buf)); // memset(buf, 0, sizeof(buf));
} }
static void coap_sent(void *arg) static void coap_sent(void *arg)
...@@ -85,7 +85,7 @@ static int coap_create( lua_State* L, const char* mt ) ...@@ -85,7 +85,7 @@ static int coap_create( lua_State* L, const char* mt )
lua_setmetatable(L, -2); lua_setmetatable(L, -2);
// create the espconn struct // create the espconn struct
pesp_conn = (struct espconn *)c_zalloc(sizeof(struct espconn)); pesp_conn = (struct espconn *)zalloc(sizeof(struct espconn));
if(!pesp_conn) if(!pesp_conn)
return luaL_error(L, "not enough memory"); return luaL_error(L, "not enough memory");
...@@ -95,9 +95,9 @@ static int coap_create( lua_State* L, const char* mt ) ...@@ -95,9 +95,9 @@ static int coap_create( lua_State* L, const char* mt )
pesp_conn->proto.tcp = NULL; pesp_conn->proto.tcp = NULL;
pesp_conn->proto.udp = NULL; pesp_conn->proto.udp = NULL;
pesp_conn->proto.udp = (esp_udp *)c_zalloc(sizeof(esp_udp)); pesp_conn->proto.udp = (esp_udp *)zalloc(sizeof(esp_udp));
if(!pesp_conn->proto.udp){ if(!pesp_conn->proto.udp){
c_free(pesp_conn); free(pesp_conn);
cud->pesp_conn = pesp_conn = NULL; cud->pesp_conn = pesp_conn = NULL;
return luaL_error(L, "not enough memory"); return luaL_error(L, "not enough memory");
} }
...@@ -135,9 +135,9 @@ static int coap_delete( lua_State* L, const char* mt ) ...@@ -135,9 +135,9 @@ static int coap_delete( lua_State* L, const char* mt )
{ {
if(cud->pesp_conn->proto.udp->remote_port || cud->pesp_conn->proto.udp->local_port) if(cud->pesp_conn->proto.udp->remote_port || cud->pesp_conn->proto.udp->local_port)
espconn_delete(cud->pesp_conn); espconn_delete(cud->pesp_conn);
c_free(cud->pesp_conn->proto.udp); free(cud->pesp_conn->proto.udp);
cud->pesp_conn->proto.udp = NULL; cud->pesp_conn->proto.udp = NULL;
c_free(cud->pesp_conn); free(cud->pesp_conn);
cud->pesp_conn = NULL; cud->pesp_conn = NULL;
} }
...@@ -174,7 +174,7 @@ static int coap_start( lua_State* L, const char* mt ) ...@@ -174,7 +174,7 @@ static int coap_start( lua_State* L, const char* mt )
ip = "0.0.0.0"; ip = "0.0.0.0";
} }
ipaddr.addr = ipaddr_addr(ip); ipaddr.addr = ipaddr_addr(ip);
c_memcpy(pesp_conn->proto.udp->local_ip, &ipaddr.addr, 4); memcpy(pesp_conn->proto.udp->local_ip, &ipaddr.addr, 4);
NODE_DBG("UDP ip is set: "); NODE_DBG("UDP ip is set: ");
NODE_DBG(IPSTR, IP2STR(&ipaddr.addr)); NODE_DBG(IPSTR, IP2STR(&ipaddr.addr));
NODE_DBG("\n"); NODE_DBG("\n");
...@@ -239,7 +239,7 @@ static void coap_response_handler(void *arg, char *pdata, unsigned short len) ...@@ -239,7 +239,7 @@ static void coap_response_handler(void *arg, char *pdata, unsigned short len)
pkt.content.len = 0; pkt.content.len = 0;
// static uint8_t buf[MAX_MESSAGE_SIZE+1] = {0}; // +1 for string '\0' // static uint8_t buf[MAX_MESSAGE_SIZE+1] = {0}; // +1 for string '\0'
uint8_t buf[MAX_MESSAGE_SIZE+1] = {0}; // +1 for string '\0' uint8_t buf[MAX_MESSAGE_SIZE+1] = {0}; // +1 for string '\0'
c_memset(buf, 0, sizeof(buf)); // wipe prev data memset(buf, 0, sizeof(buf)); // wipe prev data
int rc; int rc;
if( len > MAX_MESSAGE_SIZE ) if( len > MAX_MESSAGE_SIZE )
...@@ -247,7 +247,7 @@ static void coap_response_handler(void *arg, char *pdata, unsigned short len) ...@@ -247,7 +247,7 @@ static void coap_response_handler(void *arg, char *pdata, unsigned short len)
NODE_DBG("Request Entity Too Large.\n"); // NOTE: should response 4.13 to client... NODE_DBG("Request Entity Too Large.\n"); // NOTE: should response 4.13 to client...
return; return;
} }
c_memcpy(buf, pdata, len); memcpy(buf, pdata, len);
if (0 != (rc = coap_parse(&pkt, buf, len))){ if (0 != (rc = coap_parse(&pkt, buf, len))){
NODE_DBG("Bad packet rc=%d\n", rc); NODE_DBG("Bad packet rc=%d\n", rc);
...@@ -275,7 +275,7 @@ static void coap_response_handler(void *arg, char *pdata, unsigned short len) ...@@ -275,7 +275,7 @@ static void coap_response_handler(void *arg, char *pdata, unsigned short len)
uint32_t ip = 0, port = 0; uint32_t ip = 0, port = 0;
coap_tid_t id = COAP_INVALID_TID; coap_tid_t id = COAP_INVALID_TID;
c_memcpy(&ip, pesp_conn->proto.udp->remote_ip, sizeof(ip)); memcpy(&ip, pesp_conn->proto.udp->remote_ip, sizeof(ip));
port = pesp_conn->proto.udp->remote_port; port = pesp_conn->proto.udp->remote_port;
coap_transaction_id(ip, port, &pkt, &id); coap_transaction_id(ip, port, &pkt, &id);
...@@ -307,7 +307,7 @@ end: ...@@ -307,7 +307,7 @@ end:
if(pesp_conn->proto.udp->remote_port || pesp_conn->proto.udp->local_port) if(pesp_conn->proto.udp->remote_port || pesp_conn->proto.udp->local_port)
espconn_delete(pesp_conn); espconn_delete(pesp_conn);
} }
// c_memset(buf, 0, sizeof(buf)); // memset(buf, 0, sizeof(buf));
} }
// Lua: client:request( [CON], uri, [payload] ) // Lua: client:request( [CON], uri, [payload] )
...@@ -358,7 +358,7 @@ static int coap_request( lua_State* L, coap_method_t m ) ...@@ -358,7 +358,7 @@ static int coap_request( lua_State* L, coap_method_t m )
pesp_conn->proto.udp->local_port = espconn_port(); pesp_conn->proto.udp->local_port = espconn_port();
if(uri->host.length){ if(uri->host.length){
c_memcpy(host, uri->host.s, uri->host.length); memcpy(host, uri->host.s, uri->host.length);
host[uri->host.length] = '\0'; host[uri->host.length] = '\0';
ipaddr.addr = ipaddr_addr(host); ipaddr.addr = ipaddr_addr(host);
...@@ -366,7 +366,7 @@ static int coap_request( lua_State* L, coap_method_t m ) ...@@ -366,7 +366,7 @@ static int coap_request( lua_State* L, coap_method_t m )
NODE_DBG(host); NODE_DBG(host);
NODE_DBG("\n"); NODE_DBG("\n");
c_memcpy(pesp_conn->proto.udp->remote_ip, &ipaddr.addr, 4); memcpy(pesp_conn->proto.udp->remote_ip, &ipaddr.addr, 4);
NODE_DBG("UDP ip is set: "); NODE_DBG("UDP ip is set: ");
NODE_DBG(IPSTR, IP2STR(&ipaddr.addr)); NODE_DBG(IPSTR, IP2STR(&ipaddr.addr));
NODE_DBG("\n"); NODE_DBG("\n");
...@@ -375,7 +375,7 @@ static int coap_request( lua_State* L, coap_method_t m ) ...@@ -375,7 +375,7 @@ static int coap_request( lua_State* L, coap_method_t m )
coap_pdu_t *pdu = coap_new_pdu(); // should call coap_delete_pdu() somewhere coap_pdu_t *pdu = coap_new_pdu(); // should call coap_delete_pdu() somewhere
if(!pdu){ if(!pdu){
if(uri) if(uri)
c_free(uri); free(uri);
return luaL_error (L, "alloc fail"); return luaL_error (L, "alloc fail");
} }
...@@ -426,7 +426,7 @@ static int coap_request( lua_State* L, coap_method_t m ) ...@@ -426,7 +426,7 @@ static int coap_request( lua_State* L, coap_method_t m )
} }
if(uri) if(uri)
c_free((void *)uri); free((void *)uri);
NODE_DBG("coap_request is called.\n"); NODE_DBG("coap_request is called.\n");
return 0; return 0;
...@@ -451,13 +451,13 @@ static int coap_regist( lua_State* L, const char* mt, int isvar ) ...@@ -451,13 +451,13 @@ static int coap_regist( lua_State* L, const char* mt, int isvar )
h = function_entry; h = function_entry;
while(NULL!=h->next){ // goto the end of the list while(NULL!=h->next){ // goto the end of the list
if(h->name!= NULL && c_strcmp(h->name, name)==0) // key exist, override it if(h->name!= NULL && strcmp(h->name, name)==0) // key exist, override it
break; break;
h = h->next; h = h->next;
} }
if(h->name==NULL || c_strcmp(h->name, name)!=0){ // not exists. make a new one. if(h->name==NULL || strcmp(h->name, name)!=0){ // not exists. make a new one.
h->next = (coap_luser_entry *)c_zalloc(sizeof(coap_luser_entry)); h->next = (coap_luser_entry *)zalloc(sizeof(coap_luser_entry));
h = h->next; h = h->next;
if(h == NULL) if(h == NULL)
return luaL_error(L, "not enough memory"); return luaL_error(L, "not enough memory");
......
// Module for cryptography // Module for cryptography
#include <c_errno.h> #include <errno.h>
#include "module.h" #include "module.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "c_types.h" #include "c_types.h"
#include "c_stdlib.h" #include <stdlib.h>
#include "flash_fs.h" #include "flash_fs.h"
#include "../crypto/digests.h" #include "../crypto/digests.h"
#include "../crypto/mech.h" #include "../crypto/mech.h"
...@@ -71,7 +71,7 @@ static int crypto_base64_encode( lua_State* L ) ...@@ -71,7 +71,7 @@ static int crypto_base64_encode( lua_State* L )
int len; int len;
const char* msg = luaL_checklstring(L, 1, &len); const char* msg = luaL_checklstring(L, 1, &len);
int blen = (len + 2) / 3 * 4; int blen = (len + 2) / 3 * 4;
char* out = (char*)c_malloc(blen); char* out = (char*)malloc(blen);
int j = 0, i; int j = 0, i;
for (i = 0; i < len; i += 3) { for (i = 0; i < len; i += 3) {
int a = msg[i]; int a = msg[i];
...@@ -83,7 +83,7 @@ static int crypto_base64_encode( lua_State* L ) ...@@ -83,7 +83,7 @@ static int crypto_base64_encode( lua_State* L )
out[j++] = (i + 2 < len) ? bytes64[(c & 63)] : 61; out[j++] = (i + 2 < len) ? bytes64[(c & 63)] : 61;
} }
lua_pushlstring(L, out, j); lua_pushlstring(L, out, j);
c_free(out); free(out);
return 1; return 1;
} }
...@@ -96,14 +96,14 @@ static int crypto_hex_encode( lua_State* L) ...@@ -96,14 +96,14 @@ static int crypto_hex_encode( lua_State* L)
{ {
int len; int len;
const char* msg = luaL_checklstring(L, 1, &len); const char* msg = luaL_checklstring(L, 1, &len);
char* out = (char*)c_malloc(len * 2); char* out = (char*)malloc(len * 2);
int i, j = 0; int i, j = 0;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
out[j++] = crypto_hexbytes[msg[i] >> 4]; out[j++] = crypto_hexbytes[msg[i] >> 4];
out[j++] = crypto_hexbytes[msg[i] & 0xf]; out[j++] = crypto_hexbytes[msg[i] & 0xf];
} }
lua_pushlstring(L, out, len*2); lua_pushlstring(L, out, len*2);
c_free(out); free(out);
return 1; return 1;
} }
#endif #endif
...@@ -118,12 +118,12 @@ static int crypto_mask( lua_State* L ) ...@@ -118,12 +118,12 @@ static int crypto_mask( lua_State* L )
const char* msg = luaL_checklstring(L, 1, &len); const char* msg = luaL_checklstring(L, 1, &len);
const char* mask = luaL_checklstring(L, 2, &mask_len); const char* mask = luaL_checklstring(L, 2, &mask_len);
int i; int i;
char* copy = (char*)c_malloc(len); char* copy = (char*)malloc(len);
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
copy[i] = msg[i] ^ mask[i % 4]; copy[i] = msg[i] ^ mask[i % 4];
} }
lua_pushlstring(L, copy, len); lua_pushlstring(L, copy, len);
c_free(copy); free(copy);
return 1; return 1;
} }
...@@ -169,7 +169,7 @@ static int crypto_new_hash (lua_State *L) ...@@ -169,7 +169,7 @@ static int crypto_new_hash (lua_State *L)
if (!mi) if (!mi)
return bad_mech (L); return bad_mech (L);
void *ctx = os_malloc (mi->ctx_size); void *ctx = malloc (mi->ctx_size);
if (ctx==NULL) if (ctx==NULL)
return bad_mem (L); return bad_mem (L);
...@@ -237,7 +237,7 @@ static int crypto_hash_gcdelete (lua_State *L) ...@@ -237,7 +237,7 @@ static int crypto_hash_gcdelete (lua_State *L)
dudat = (digest_user_datum_t *)luaL_checkudata(L, 1, "crypto.hash"); dudat = (digest_user_datum_t *)luaL_checkudata(L, 1, "crypto.hash");
luaL_argcheck(L, dudat, 1, "crypto.hash expected"); luaL_argcheck(L, dudat, 1, "crypto.hash expected");
os_free(dudat->ctx); free(dudat->ctx);
return 0; return 0;
} }
...@@ -325,7 +325,7 @@ static int crypto_encdec (lua_State *L, bool enc) ...@@ -325,7 +325,7 @@ static int crypto_encdec (lua_State *L, bool enc)
size_t bs = mech->block_size; size_t bs = mech->block_size;
size_t outlen = ((dlen + bs -1) / bs) * bs; size_t outlen = ((dlen + bs -1) / bs) * bs;
char *buf = (char *)os_zalloc (outlen); char *buf = (char *)zalloc (outlen);
if (!buf) if (!buf)
return luaL_error (L, "crypto init failed"); return luaL_error (L, "crypto init failed");
...@@ -339,14 +339,14 @@ static int crypto_encdec (lua_State *L, bool enc) ...@@ -339,14 +339,14 @@ static int crypto_encdec (lua_State *L, bool enc)
}; };
if (!mech->run (&op)) if (!mech->run (&op))
{ {
os_free (buf); free (buf);
return luaL_error (L, "crypto op failed"); return luaL_error (L, "crypto op failed");
} }
else else
{ {
lua_pushlstring (L, buf, outlen); lua_pushlstring (L, buf, outlen);
// note: if lua_pushlstring runs out of memory, we leak buf :( // note: if lua_pushlstring runs out of memory, we leak buf :(
os_free (buf); free (buf);
return 1; return 1;
} }
} }
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
#include "module.h" #include "module.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "lmem.h" #include "lmem.h"
#include "c_string.h" #include <string.h>
#include <stdint.h>
#define BASE64_INVALID '\xff' #define BASE64_INVALID '\xff'
#define BASE64_PADDING '=' #define BASE64_PADDING '='
#define ISBASE64(c) (unbytes64[c] != BASE64_INVALID) #define ISBASE64(c) (unbytes64[c] != BASE64_INVALID)
...@@ -18,7 +19,7 @@ static uint8 *toBase64 ( lua_State* L, const uint8 *msg, size_t *len){ ...@@ -18,7 +19,7 @@ static uint8 *toBase64 ( lua_State* L, const uint8 *msg, size_t *len){
uint8 * q, *out = (uint8 *)luaM_malloc(L, (n + 2) / 3 * 4); uint8 * q, *out = (uint8 *)luaM_malloc(L, (n + 2) / 3 * 4);
uint8 bytes64[sizeof(b64)]; uint8 bytes64[sizeof(b64)];
c_memcpy(bytes64, b64, sizeof(b64)); //Avoid lots of flash unaligned fetches memcpy(bytes64, b64, sizeof(b64)); //Avoid lots of flash unaligned fetches
for (i = 0, q = out; i < n; i += 3) { for (i = 0, q = out; i < n; i += 3) {
int a = msg[i]; int a = msg[i];
...@@ -44,7 +45,7 @@ static uint8 *fromBase64 ( lua_State* L, const uint8 *enc_msg, size_t *len){ ...@@ -44,7 +45,7 @@ static uint8 *fromBase64 ( lua_State* L, const uint8 *enc_msg, size_t *len){
if (n & 3) if (n & 3)
luaL_error (L, "Invalid base64 string"); luaL_error (L, "Invalid base64 string");
c_memset(unbytes64, BASE64_INVALID, sizeof(unbytes64)); memset(unbytes64, BASE64_INVALID, sizeof(unbytes64));
for (i = 0; i < sizeof(b64)-1; i++) unbytes64[b64[i]] = i; // sequential so no exceptions for (i = 0; i < sizeof(b64)-1; i++) unbytes64[b64[i]] = i; // sequential so no exceptions
if (enc_msg[n-1] == BASE64_PADDING) { if (enc_msg[n-1] == BASE64_PADDING) {
......
...@@ -39,14 +39,16 @@ ...@@ -39,14 +39,16 @@
#include "lwip/pbuf.h" #include "lwip/pbuf.h"
#include "lmem.h" #include "lmem.h"
#include "platform.h" #include "platform.h"
#include "c_stdlib.h" #include <stdlib.h>
#include "c_stdio.h" #include <stdio.h>
#include "c_string.h" #include <string.h>
#include "ctype.h" #include "ctype.h"
#include "espconn.h" #include "espconn.h"
#include "flash_fs.h" #include "flash_fs.h"
#include "task/task.h" #include "task/task.h"
#include "esp_wifi.h" #include "esp_wifi.h"
#include "esp_sta.h"
#include "esp_softap.h"
#define MIN(x, y) (((x) < (y)) ? (x) : (y)) #define MIN(x, y) (((x) < (y)) ? (x) : (y))
#define LITLEN(strliteral) (sizeof (strliteral) -1) #define LITLEN(strliteral) (sizeof (strliteral) -1)
...@@ -366,7 +368,7 @@ static void enduser_setup_check_station(void *p) ...@@ -366,7 +368,7 @@ static void enduser_setup_check_station(void *p)
(void)p; (void)p;
struct ip_info ip; struct ip_info ip;
c_memset(&ip, 0, sizeof(struct ip_info)); memset(&ip, 0, sizeof(struct ip_info));
wifi_get_ip_info(STATION_IF, &ip); wifi_get_ip_info(STATION_IF, &ip);
...@@ -499,33 +501,33 @@ static int enduser_setup_http_load_payload(void) ...@@ -499,33 +501,33 @@ static int enduser_setup_http_load_payload(void)
int payload_len = LITLEN(http_header_200) + cl_len + LITLEN(http_html_backup); int payload_len = LITLEN(http_header_200) + cl_len + LITLEN(http_html_backup);
state->http_payload_len = payload_len; state->http_payload_len = payload_len;
state->http_payload_data = (char *) c_malloc(payload_len); state->http_payload_data = (char *) malloc(payload_len);
if (state->http_payload_data == NULL) if (state->http_payload_data == NULL)
{ {
return 2; return 2;
} }
int offset = 0; int offset = 0;
c_memcpy(&(state->http_payload_data[offset]), &(http_header_200), LITLEN(http_header_200)); memcpy(&(state->http_payload_data[offset]), &(http_header_200), LITLEN(http_header_200));
offset += LITLEN(http_header_200); offset += LITLEN(http_header_200);
offset += c_sprintf(state->http_payload_data + offset, cl_hdr, LITLEN(http_html_backup)); offset += sprintf(state->http_payload_data + offset, cl_hdr, LITLEN(http_html_backup));
c_memcpy(&(state->http_payload_data[offset]), &(http_html_backup), LITLEN(http_html_backup)); memcpy(&(state->http_payload_data[offset]), &(http_html_backup), LITLEN(http_html_backup));
return 1; return 1;
} }
int payload_len = LITLEN(http_header_200) + cl_len + file_len; int payload_len = LITLEN(http_header_200) + cl_len + file_len;
state->http_payload_len = payload_len; state->http_payload_len = payload_len;
state->http_payload_data = (char *) c_malloc(payload_len); state->http_payload_data = (char *) malloc(payload_len);
if (state->http_payload_data == NULL) if (state->http_payload_data == NULL)
{ {
return 2; return 2;
} }
int offset = 0; int offset = 0;
c_memcpy(&(state->http_payload_data[offset]), &(http_header_200), LITLEN(http_header_200)); memcpy(&(state->http_payload_data[offset]), &(http_header_200), LITLEN(http_header_200));
offset += LITLEN(http_header_200); offset += LITLEN(http_header_200);
offset += c_sprintf(state->http_payload_data + offset, cl_hdr, file_len); offset += sprintf(state->http_payload_data + offset, cl_hdr, file_len);
fs_read(f, &(state->http_payload_data[offset]), file_len); fs_read(f, &(state->http_payload_data[offset]), file_len);
return 0; return 0;
...@@ -652,7 +654,7 @@ static int enduser_setup_http_handle_credentials(char *data, unsigned short data ...@@ -652,7 +654,7 @@ static int enduser_setup_http_handle_credentials(char *data, unsigned short data
struct station_config *cnf = luaM_malloc(lua_getstate(), sizeof(struct station_config)); struct station_config *cnf = luaM_malloc(lua_getstate(), sizeof(struct station_config));
c_memset(cnf, 0, sizeof(struct station_config)); memset(cnf, 0, sizeof(struct station_config));
int err; int err;
err = enduser_setup_http_urldecode(cnf->ssid, name_str_start, name_str_len, sizeof(cnf->ssid)); err = enduser_setup_http_urldecode(cnf->ssid, name_str_start, name_str_len, sizeof(cnf->ssid));
...@@ -806,17 +808,17 @@ static void serve_status(struct tcp_pcb *conn) ...@@ -806,17 +808,17 @@ static void serve_status(struct tcp_pcb *conn)
wifi_station_get_config(&config); wifi_station_get_config(&config);
config.ssid[31] = '\0'; config.ssid[31] = '\0';
int state_len = c_strlen(s); int state_len = strlen(s);
int ssid_len = c_strlen(config.ssid); int ssid_len = strlen(config.ssid);
int status_len = state_len + ssid_len + 1; int status_len = state_len + ssid_len + 1;
char status_buf[status_len]; char status_buf[status_len];
memset(status_buf, 0, status_len); memset(status_buf, 0, status_len);
status_len = c_sprintf(status_buf, s, config.ssid); status_len = sprintf(status_buf, s, config.ssid);
int buf_len = sizeof(fmt) + status_len + 10; //10 = (9+1), 1 byte is '\0' and 9 are reserved for length field int buf_len = sizeof(fmt) + status_len + 10; //10 = (9+1), 1 byte is '\0' and 9 are reserved for length field
char buf[buf_len]; char buf[buf_len];
memset(buf, 0, buf_len); memset(buf, 0, buf_len);
int output_len = c_sprintf(buf, fmt, status_len, status_buf); int output_len = sprintf(buf, fmt, status_len, status_buf);
enduser_setup_http_serve_header(conn, buf, output_len); enduser_setup_http_serve_header(conn, buf, output_len);
} }
...@@ -826,11 +828,11 @@ static void serve_status(struct tcp_pcb *conn) ...@@ -826,11 +828,11 @@ static void serve_status(struct tcp_pcb *conn)
default: default:
{ {
const char *s = state[curr_state]; const char *s = state[curr_state];
int status_len = c_strlen(s); int status_len = strlen(s);
int buf_len = sizeof(fmt) + status_len + 10; //10 = (9+1), 1 byte is '\0' and 9 are reserved for length field int buf_len = sizeof(fmt) + status_len + 10; //10 = (9+1), 1 byte is '\0' and 9 are reserved for length field
char buf[buf_len]; char buf[buf_len];
memset(buf, 0, buf_len); memset(buf, 0, buf_len);
int output_len = c_sprintf(buf, fmt, status_len, s); int output_len = sprintf(buf, fmt, status_len, s);
enduser_setup_http_serve_header(conn, buf, output_len); enduser_setup_http_serve_header(conn, buf, output_len);
} }
...@@ -858,7 +860,7 @@ static void free_scan_listeners (void) ...@@ -858,7 +860,7 @@ static void free_scan_listeners (void)
while (l) while (l)
{ {
next = l->next; next = l->next;
c_free (l); free (l);
l = next; l = next;
} }
state->scan_listeners = 0; state->scan_listeners = 0;
...@@ -876,7 +878,7 @@ static void remove_scan_listener (scan_listener_t *l) ...@@ -876,7 +878,7 @@ static void remove_scan_listener (scan_listener_t *l)
if (*sl == l) if (*sl == l)
{ {
*sl = l->next; *sl = l->next;
c_free (l); free (l);
/* No early exit to guard against multi-entry on list */ /* No early exit to guard against multi-entry on list */
} }
else else
...@@ -950,7 +952,7 @@ static void on_scan_done (void *arg, STATUS status) ...@@ -950,7 +952,7 @@ static void on_scan_done (void *arg, STATUS status)
/* To be able to safely escape a pathological SSID, we need 2*32 bytes */ /* To be able to safely escape a pathological SSID, we need 2*32 bytes */
const size_t max_entry_sz = sizeof("{\"ssid\":\"\",\"rssi\":},") + 2*32 + 6; const size_t max_entry_sz = sizeof("{\"ssid\":\"\",\"rssi\":},") + 2*32 + 6;
const size_t alloc_sz = hdr_sz + num_nets * max_entry_sz + 3; const size_t alloc_sz = hdr_sz + num_nets * max_entry_sz + 3;
char *http = os_zalloc (alloc_sz); char *http = zalloc (alloc_sz);
if (!http) if (!http)
{ {
goto serve_500; goto serve_500;
...@@ -976,18 +978,18 @@ static void on_scan_done (void *arg, STATUS status) ...@@ -976,18 +978,18 @@ static void on_scan_done (void *arg, STATUS status)
strcpy (p, entry_mid); strcpy (p, entry_mid);
p += sizeof (entry_mid) -1; p += sizeof (entry_mid) -1;
p += c_sprintf (p, "%d", wn->rssi); p += sprintf (p, "%d", wn->rssi);
*p++ = '}'; *p++ = '}';
} }
*p++ = ']'; *p++ = ']';
size_t body_sz = (p - http) - hdr_sz; size_t body_sz = (p - http) - hdr_sz;
c_sprintf (http, header_fmt, body_sz); sprintf (http, header_fmt, body_sz);
http[hdr_sz] = '['; /* Rewrite the \0 with the correct start of body */ http[hdr_sz] = '['; /* Rewrite the \0 with the correct start of body */
notify_scan_listeners (http, hdr_sz + body_sz); notify_scan_listeners (http, hdr_sz + body_sz);
c_free (http); free (http);
return; return;
} }
...@@ -1020,7 +1022,7 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s ...@@ -1020,7 +1022,7 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s
return ERR_OK; return ERR_OK;
} }
char *data = os_zalloc (p->tot_len + 1); char *data = zalloc (p->tot_len + 1);
if (!data) if (!data)
return ERR_MEM; return ERR_MEM;
...@@ -1029,9 +1031,9 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s ...@@ -1029,9 +1031,9 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s
pbuf_free (p); pbuf_free (p);
err_t ret = ERR_OK; err_t ret = ERR_OK;
if (c_strncmp(data, "GET ", 4) == 0) if (strncmp(data, "GET ", 4) == 0)
{ {
if (c_strncmp(data + 4, "/ ", 2) == 0) if (strncmp(data + 4, "/ ", 2) == 0)
{ {
if (enduser_setup_http_serve_html(http_client) != 0) if (enduser_setup_http_serve_html(http_client) != 0)
{ {
...@@ -1042,9 +1044,9 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s ...@@ -1042,9 +1044,9 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s
goto free_out; /* streaming now in progress */ goto free_out; /* streaming now in progress */
} }
} }
else if (c_strncmp(data + 4, "/aplist ", 8) == 0) else if (strncmp(data + 4, "/aplist ", 8) == 0)
{ {
scan_listener_t *l = os_malloc (sizeof (scan_listener_t)); scan_listener_t *l = malloc (sizeof (scan_listener_t));
if (!l) if (!l)
{ {
ENDUSER_SETUP_ERROR("out of memory", ENDUSER_SETUP_ERR_OUT_OF_MEMORY, ENDUSER_SETUP_ERR_NONFATAL); ENDUSER_SETUP_ERROR("out of memory", ENDUSER_SETUP_ERR_OUT_OF_MEMORY, ENDUSER_SETUP_ERR_NONFATAL);
...@@ -1070,11 +1072,11 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s ...@@ -1070,11 +1072,11 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s
} }
goto free_out; /* request queued */ goto free_out; /* request queued */
} }
else if (c_strncmp(data + 4, "/status ", 8) == 0) else if (strncmp(data + 4, "/status ", 8) == 0)
{ {
serve_status(http_client); serve_status(http_client);
} }
else if (c_strncmp(data + 4, "/update?", 8) == 0) else if (strncmp(data + 4, "/update?", 8) == 0)
{ {
switch (enduser_setup_http_handle_credentials(data, data_len)) switch (enduser_setup_http_handle_credentials(data, data_len))
{ {
...@@ -1089,7 +1091,7 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s ...@@ -1089,7 +1091,7 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s
break; break;
} }
} }
else if (c_strncmp(data + 4, "/generate_204 ", 14) == 0) else if (strncmp(data + 4, "/generate_204 ", 14) == 0)
{ {
/* Convince Android devices that they have internet access to avoid pesky dialogues. */ /* Convince Android devices that they have internet access to avoid pesky dialogues. */
enduser_setup_http_serve_header(http_client, http_header_204, LITLEN(http_header_204)); enduser_setup_http_serve_header(http_client, http_header_204, LITLEN(http_header_204));
...@@ -1109,7 +1111,7 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s ...@@ -1109,7 +1111,7 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s
deferred_close (http_client); deferred_close (http_client);
free_out: free_out:
os_free (data); free (data);
return ret; return ret;
} }
...@@ -1200,20 +1202,20 @@ static void enduser_setup_ap_start(void) ...@@ -1200,20 +1202,20 @@ static void enduser_setup_ap_start(void)
ENDUSER_SETUP_DEBUG("enduser_setup_ap_start"); ENDUSER_SETUP_DEBUG("enduser_setup_ap_start");
struct softap_config cnf; struct softap_config cnf;
c_memset(&(cnf), 0, sizeof(struct softap_config)); memset(&(cnf), 0, sizeof(struct softap_config));
#ifndef ENDUSER_SETUP_AP_SSID #ifndef ENDUSER_SETUP_AP_SSID
#define ENDUSER_SETUP_AP_SSID "SetupGadget" #define ENDUSER_SETUP_AP_SSID "SetupGadget"
#endif #endif
char ssid[] = ENDUSER_SETUP_AP_SSID; char ssid[] = ENDUSER_SETUP_AP_SSID;
int ssid_name_len = c_strlen(ssid); int ssid_name_len = strlen(ssid);
c_memcpy(&(cnf.ssid), ssid, ssid_name_len); memcpy(&(cnf.ssid), ssid, ssid_name_len);
uint8_t mac[6]; uint8_t mac[6];
wifi_get_macaddr(SOFTAP_IF, mac); wifi_get_macaddr(SOFTAP_IF, mac);
cnf.ssid[ssid_name_len] = '_'; cnf.ssid[ssid_name_len] = '_';
c_sprintf(cnf.ssid + ssid_name_len + 1, "%02X%02X%02X", mac[3], mac[4], mac[5]); sprintf(cnf.ssid + ssid_name_len + 1, "%02X%02X%02X", mac[3], mac[4], mac[5]);
cnf.ssid_len = ssid_name_len + 7; cnf.ssid_len = ssid_name_len + 7;
cnf.channel = 1; cnf.channel = 1;
cnf.authmode = AUTH_OPEN; cnf.authmode = AUTH_OPEN;
...@@ -1232,7 +1234,7 @@ static void enduser_setup_dns_recv_callback(void *arg, char *recv_data, unsigned ...@@ -1232,7 +1234,7 @@ static void enduser_setup_dns_recv_callback(void *arg, char *recv_data, unsigned
struct espconn *callback_espconn = arg; struct espconn *callback_espconn = arg;
struct ip_info ip_info; struct ip_info ip_info;
uint32_t qname_len = c_strlen(&(recv_data[12])) + 1; // \0=1byte uint32_t qname_len = strlen(&(recv_data[12])) + 1; // \0=1byte
uint32_t dns_reply_static_len = (uint32_t) sizeof(dns_header) + (uint32_t) sizeof(dns_body) + 2 + 4; // dns_id=2bytes, ip=4bytes uint32_t dns_reply_static_len = (uint32_t) sizeof(dns_header) + (uint32_t) sizeof(dns_body) + 2 + 4; // dns_id=2bytes, ip=4bytes
uint32_t dns_reply_len = dns_reply_static_len + qname_len; uint32_t dns_reply_len = dns_reply_static_len + qname_len;
...@@ -1249,22 +1251,22 @@ static void enduser_setup_dns_recv_callback(void *arg, char *recv_data, unsigned ...@@ -1249,22 +1251,22 @@ static void enduser_setup_dns_recv_callback(void *arg, char *recv_data, unsigned
} }
char *dns_reply = (char *) c_malloc(dns_reply_len); char *dns_reply = (char *) malloc(dns_reply_len);
if (dns_reply == NULL) if (dns_reply == NULL)
{ {
ENDUSER_SETUP_ERROR_VOID("dns_recv_callback failed. Failed to allocate memory.", ENDUSER_SETUP_ERR_OUT_OF_MEMORY, ENDUSER_SETUP_ERR_NONFATAL); ENDUSER_SETUP_ERROR_VOID("dns_recv_callback failed. Failed to allocate memory.", ENDUSER_SETUP_ERR_OUT_OF_MEMORY, ENDUSER_SETUP_ERR_NONFATAL);
} }
uint32_t insert_byte = 0; uint32_t insert_byte = 0;
c_memcpy(&(dns_reply[insert_byte]), recv_data, 2); memcpy(&(dns_reply[insert_byte]), recv_data, 2);
insert_byte += 2; insert_byte += 2;
c_memcpy(&(dns_reply[insert_byte]), dns_header, sizeof(dns_header)); memcpy(&(dns_reply[insert_byte]), dns_header, sizeof(dns_header));
insert_byte += (uint32_t) sizeof(dns_header); insert_byte += (uint32_t) sizeof(dns_header);
c_memcpy(&(dns_reply[insert_byte]), &(recv_data[12]), qname_len); memcpy(&(dns_reply[insert_byte]), &(recv_data[12]), qname_len);
insert_byte += qname_len; insert_byte += qname_len;
c_memcpy(&(dns_reply[insert_byte]), dns_body, sizeof(dns_body)); memcpy(&(dns_reply[insert_byte]), dns_body, sizeof(dns_body));
insert_byte += (uint32_t) sizeof(dns_body); insert_byte += (uint32_t) sizeof(dns_body);
c_memcpy(&(dns_reply[insert_byte]), &(ip_info.ip), 4); memcpy(&(dns_reply[insert_byte]), &(ip_info.ip), 4);
// SDK 1.4.0 changed behaviour, for UDP server need to look up remote ip/port // SDK 1.4.0 changed behaviour, for UDP server need to look up remote ip/port
remot_info *pr = 0; remot_info *pr = 0;
...@@ -1273,11 +1275,11 @@ static void enduser_setup_dns_recv_callback(void *arg, char *recv_data, unsigned ...@@ -1273,11 +1275,11 @@ static void enduser_setup_dns_recv_callback(void *arg, char *recv_data, unsigned
ENDUSER_SETUP_ERROR_VOID("dns_recv_callback failed. Unable to get IP of UDP sender.", ENDUSER_SETUP_ERR_CONNECTION_NOT_FOUND, ENDUSER_SETUP_ERR_FATAL); ENDUSER_SETUP_ERROR_VOID("dns_recv_callback failed. Unable to get IP of UDP sender.", ENDUSER_SETUP_ERR_CONNECTION_NOT_FOUND, ENDUSER_SETUP_ERR_FATAL);
} }
callback_espconn->proto.udp->remote_port = pr->remote_port; callback_espconn->proto.udp->remote_port = pr->remote_port;
os_memmove(callback_espconn->proto.udp->remote_ip, pr->remote_ip, 4); memmove(callback_espconn->proto.udp->remote_ip, pr->remote_ip, 4);
int8_t err; int8_t err;
err = espconn_send(callback_espconn, dns_reply, dns_reply_len); err = espconn_send(callback_espconn, dns_reply, dns_reply_len);
c_free(dns_reply); free(dns_reply);
if (err == ESPCONN_MEM) if (err == ESPCONN_MEM)
{ {
ENDUSER_SETUP_ERROR_VOID("dns_recv_callback failed. Failed to allocate memory for send.", ENDUSER_SETUP_ERR_OUT_OF_MEMORY, ENDUSER_SETUP_ERR_FATAL); ENDUSER_SETUP_ERROR_VOID("dns_recv_callback failed. Failed to allocate memory for send.", ENDUSER_SETUP_ERR_OUT_OF_MEMORY, ENDUSER_SETUP_ERR_FATAL);
...@@ -1310,16 +1312,16 @@ static void enduser_setup_free(void) ...@@ -1310,16 +1312,16 @@ static void enduser_setup_free(void)
{ {
if (state->espconn_dns_udp->proto.udp != NULL) if (state->espconn_dns_udp->proto.udp != NULL)
{ {
c_free(state->espconn_dns_udp->proto.udp); free(state->espconn_dns_udp->proto.udp);
} }
c_free(state->espconn_dns_udp); free(state->espconn_dns_udp);
} }
c_free(state->http_payload_data); free(state->http_payload_data);
free_scan_listeners (); free_scan_listeners ();
c_free(state); free(state);
state = NULL; state = NULL;
} }
...@@ -1332,20 +1334,20 @@ static int enduser_setup_dns_start(void) ...@@ -1332,20 +1334,20 @@ static int enduser_setup_dns_start(void)
{ {
ENDUSER_SETUP_ERROR("dns_start failed. Appears to already be started (espconn_dns_udp != NULL).", ENDUSER_SETUP_ERR_UNKOWN_ERROR, ENDUSER_SETUP_ERR_FATAL); ENDUSER_SETUP_ERROR("dns_start failed. Appears to already be started (espconn_dns_udp != NULL).", ENDUSER_SETUP_ERR_UNKOWN_ERROR, ENDUSER_SETUP_ERR_FATAL);
} }
state->espconn_dns_udp = (struct espconn *) c_malloc(sizeof(struct espconn)); state->espconn_dns_udp = (struct espconn *) malloc(sizeof(struct espconn));
if (state->espconn_dns_udp == NULL) if (state->espconn_dns_udp == NULL)
{ {
ENDUSER_SETUP_ERROR("dns_start failed. Memory allocation failed (espconn_dns_udp == NULL).", ENDUSER_SETUP_ERR_OUT_OF_MEMORY, ENDUSER_SETUP_ERR_FATAL); ENDUSER_SETUP_ERROR("dns_start failed. Memory allocation failed (espconn_dns_udp == NULL).", ENDUSER_SETUP_ERR_OUT_OF_MEMORY, ENDUSER_SETUP_ERR_FATAL);
} }
esp_udp *esp_udp_data = (esp_udp *) c_malloc(sizeof(esp_udp)); esp_udp *esp_udp_data = (esp_udp *) malloc(sizeof(esp_udp));
if (esp_udp_data == NULL) if (esp_udp_data == NULL)
{ {
ENDUSER_SETUP_ERROR("dns_start failed. Memory allocation failed (esp_udp == NULL).", ENDUSER_SETUP_ERR_OUT_OF_MEMORY, ENDUSER_SETUP_ERR_FATAL); ENDUSER_SETUP_ERROR("dns_start failed. Memory allocation failed (esp_udp == NULL).", ENDUSER_SETUP_ERR_OUT_OF_MEMORY, ENDUSER_SETUP_ERR_FATAL);
} }
c_memset(state->espconn_dns_udp, 0, sizeof(struct espconn)); memset(state->espconn_dns_udp, 0, sizeof(struct espconn));
c_memset(esp_udp_data, 0, sizeof(esp_udp)); memset(esp_udp_data, 0, sizeof(esp_udp));
state->espconn_dns_udp->proto.udp = esp_udp_data; state->espconn_dns_udp->proto.udp = esp_udp_data;
state->espconn_dns_udp->type = ESPCONN_UDP; state->espconn_dns_udp->type = ESPCONN_UDP;
state->espconn_dns_udp->state = ESPCONN_NONE; state->espconn_dns_udp->state = ESPCONN_NONE;
...@@ -1397,13 +1399,13 @@ static int enduser_setup_init(lua_State *L) ...@@ -1397,13 +1399,13 @@ static int enduser_setup_init(lua_State *L)
return ENDUSER_SETUP_ERR_UNKOWN_ERROR; return ENDUSER_SETUP_ERR_UNKOWN_ERROR;
} }
state = (enduser_setup_state_t *) os_zalloc(sizeof(enduser_setup_state_t)); state = (enduser_setup_state_t *) zalloc(sizeof(enduser_setup_state_t));
if (state == NULL) if (state == NULL)
{ {
ENDUSER_SETUP_ERROR("init failed. Unable to allocate memory.", ENDUSER_SETUP_ERR_OUT_OF_MEMORY, ENDUSER_SETUP_ERR_FATAL); ENDUSER_SETUP_ERROR("init failed. Unable to allocate memory.", ENDUSER_SETUP_ERR_OUT_OF_MEMORY, ENDUSER_SETUP_ERR_FATAL);
return ENDUSER_SETUP_ERR_OUT_OF_MEMORY; return ENDUSER_SETUP_ERR_OUT_OF_MEMORY;
} }
c_memset(state, 0, sizeof(enduser_setup_state_t)); memset(state, 0, sizeof(enduser_setup_state_t));
state->lua_connected_cb_ref = LUA_NOREF; state->lua_connected_cb_ref = LUA_NOREF;
state->lua_err_cb_ref = LUA_NOREF; state->lua_err_cb_ref = LUA_NOREF;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "c_types.h" #include "c_types.h"
#include "flash_fs.h" #include "flash_fs.h"
#include "c_string.h" #include <string.h>
static volatile int file_fd = FS_OPEN_OK - 1; static volatile int file_fd = FS_OPEN_OK - 1;
...@@ -20,7 +20,7 @@ static int file_open( lua_State* L ) ...@@ -20,7 +20,7 @@ static int file_open( lua_State* L )
} }
const char *fname = luaL_checklstring( L, 1, &len ); const char *fname = luaL_checklstring( L, 1, &len );
luaL_argcheck(L, len < FS_NAME_MAX_LENGTH && c_strlen(fname) == len, 1, "filename invalid"); luaL_argcheck(L, len < FS_NAME_MAX_LENGTH && strlen(fname) == len, 1, "filename invalid");
const char *mode = luaL_optstring(L, 2, "r"); const char *mode = luaL_optstring(L, 2, "r");
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "platform.h" #include "platform.h"
#include "user_interface.h" #include "user_interface.h"
#include "c_types.h" #include "c_types.h"
#include "c_string.h" #include <string.h>
#include "gpio.h" #include "gpio.h"
#undef INTERRUPT #undef INTERRUPT
......
...@@ -14,13 +14,13 @@ static int http_callback_registry = LUA_NOREF; ...@@ -14,13 +14,13 @@ static int http_callback_registry = LUA_NOREF;
static void http_callback( char * response, int http_status, char * full_response ) static void http_callback( char * response, int http_status, char * full_response )
{ {
#if defined(HTTPCLIENT_DEBUG_ON) #if defined(HTTPCLIENT_DEBUG_ON)
c_printf( "http_status=%d\n", http_status ); printf( "http_status=%d\n", http_status );
if ( http_status != HTTP_STATUS_GENERIC_ERROR ) if ( http_status != HTTP_STATUS_GENERIC_ERROR )
{ {
if (full_response != NULL) { if (full_response != NULL) {
c_printf( "strlen(full_response)=%d\n", strlen( full_response ) ); printf( "strlen(full_response)=%d\n", strlen( full_response ) );
} }
c_printf( "response=%s<EOF>\n", response ); printf( "response=%s<EOF>\n", response );
} }
#endif #endif
if (http_callback_registry != LUA_NOREF) if (http_callback_registry != LUA_NOREF)
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
#include "module.h" #include "module.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "c_stdlib.h" #include <stdlib.h>
#include "c_string.h" #include <string.h>
#include "user_interface.h" #include "user_interface.h"
#include "esp_system.h" #include "esp_system.h"
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
#include "module.h" #include "module.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "c_string.h" #include <string.h>
#include "c_stdlib.h" #include <stdlib.h>
#include "c_types.h" #include "c_types.h"
#include "mem.h" #include "mem.h"
...@@ -43,16 +43,16 @@ static int mdns_register(lua_State *L) ...@@ -43,16 +43,16 @@ static int mdns_register(lua_State *L)
luaL_checktype(L, -2, LUA_TSTRING); luaL_checktype(L, -2, LUA_TSTRING);
const char *key = luaL_checkstring(L, -2); const char *key = luaL_checkstring(L, -2);
if (c_strcmp(key, "port") == 0) { if (strcmp(key, "port") == 0) {
info.service_port = luaL_checknumber(L, -1); info.service_port = luaL_checknumber(L, -1);
} else if (c_strcmp(key, "service") == 0) { } else if (strcmp(key, "service") == 0) {
info.service_name = luaL_checkstring(L, -1); info.service_name = luaL_checkstring(L, -1);
} else if (c_strcmp(key, "description") == 0) { } else if (strcmp(key, "description") == 0) {
info.host_desc = luaL_checkstring(L, -1); info.host_desc = luaL_checkstring(L, -1);
} else { } else {
int len = c_strlen(key) + 1; int len = strlen(key) + 1;
const char *value = luaL_checkstring(L, -1); const char *value = luaL_checkstring(L, -1);
char *p = alloca(len + c_strlen(value) + 1); char *p = alloca(len + strlen(value) + 1);
strcpy(p, key); strcpy(p, key);
strcat(p, "="); strcat(p, "=");
strcat(p, value); strcat(p, value);
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "c_string.h" #include <string.h>
#include "c_stdlib.h" #include <stdlib.h>
#include "c_types.h" #include "c_types.h"
#include "mem.h" #include "mem.h"
...@@ -121,9 +121,9 @@ static void mqtt_socket_disconnected(void *arg) // tcp only ...@@ -121,9 +121,9 @@ static void mqtt_socket_disconnected(void *arg) // tcp only
if(mud->pesp_conn){ if(mud->pesp_conn){
mud->pesp_conn->reverse = NULL; mud->pesp_conn->reverse = NULL;
if(mud->pesp_conn->proto.tcp) if(mud->pesp_conn->proto.tcp)
c_free(mud->pesp_conn->proto.tcp); free(mud->pesp_conn->proto.tcp);
mud->pesp_conn->proto.tcp = NULL; mud->pesp_conn->proto.tcp = NULL;
c_free(mud->pesp_conn); free(mud->pesp_conn);
mud->pesp_conn = NULL; mud->pesp_conn = NULL;
} }
...@@ -270,7 +270,7 @@ READPACKET: ...@@ -270,7 +270,7 @@ READPACKET:
if(length > MQTT_BUF_SIZE || length <= 0) if(length > MQTT_BUF_SIZE || length <= 0)
return; return;
// c_memcpy(in_buffer, pdata, length); // memcpy(in_buffer, pdata, length);
uint8_t temp_buffer[MQTT_BUF_SIZE]; uint8_t temp_buffer[MQTT_BUF_SIZE];
mqtt_msg_init(&mud->mqtt_state.mqtt_connection, temp_buffer, MQTT_BUF_SIZE); mqtt_msg_init(&mud->mqtt_state.mqtt_connection, temp_buffer, MQTT_BUF_SIZE);
mqtt_message_t *temp_msg = NULL; mqtt_message_t *temp_msg = NULL;
...@@ -654,12 +654,12 @@ static int mqtt_socket_client( lua_State* L ) ...@@ -654,12 +654,12 @@ static int mqtt_socket_client( lua_State* L )
lmqtt_userdata *mud; lmqtt_userdata *mud;
char tempid[20] = {0}; char tempid[20] = {0};
c_sprintf(tempid, "%s%x", "NodeMCU_", system_get_chip_id() ); sprintf(tempid, "%s%x", "NodeMCU_", system_get_chip_id() );
NODE_DBG(tempid); NODE_DBG(tempid);
NODE_DBG("\n"); NODE_DBG("\n");
const char *clientId = tempid, *username = NULL, *password = NULL; const char *clientId = tempid, *username = NULL, *password = NULL;
size_t idl = c_strlen(tempid); size_t idl = strlen(tempid);
size_t unl = 0, pwl = 0; size_t unl = 0, pwl = 0;
int keepalive = 0; int keepalive = 0;
int stack = 1; int stack = 1;
...@@ -687,9 +687,9 @@ static int mqtt_socket_client( lua_State* L ) ...@@ -687,9 +687,9 @@ static int mqtt_socket_client( lua_State* L )
mud->event_timeout = 0; mud->event_timeout = 0;
mud->connState = MQTT_INIT; mud->connState = MQTT_INIT;
mud->connected = false; mud->connected = false;
c_memset(&mud->mqttTimer, 0, sizeof(ETSTimer)); memset(&mud->mqttTimer, 0, sizeof(ETSTimer));
c_memset(&mud->mqtt_state, 0, sizeof(mqtt_state_t)); memset(&mud->mqtt_state, 0, sizeof(mqtt_state_t));
c_memset(&mud->connect_info, 0, sizeof(mqtt_connect_info_t)); memset(&mud->connect_info, 0, sizeof(mqtt_connect_info_t));
// set its metatable // set its metatable
luaL_getmetatable(L, "mqtt.socket"); luaL_getmetatable(L, "mqtt.socket");
...@@ -738,30 +738,30 @@ static int mqtt_socket_client( lua_State* L ) ...@@ -738,30 +738,30 @@ static int mqtt_socket_client( lua_State* L )
} }
// TODO: check the zalloc result. // TODO: check the zalloc result.
mud->connect_info.client_id = (uint8_t *)c_zalloc(idl+1); mud->connect_info.client_id = (uint8_t *)zalloc(idl+1);
mud->connect_info.username = (uint8_t *)c_zalloc(unl + 1); mud->connect_info.username = (uint8_t *)zalloc(unl + 1);
mud->connect_info.password = (uint8_t *)c_zalloc(pwl + 1); mud->connect_info.password = (uint8_t *)zalloc(pwl + 1);
if(!mud->connect_info.client_id || !mud->connect_info.username || !mud->connect_info.password){ if(!mud->connect_info.client_id || !mud->connect_info.username || !mud->connect_info.password){
if(mud->connect_info.client_id) { if(mud->connect_info.client_id) {
c_free(mud->connect_info.client_id); free(mud->connect_info.client_id);
mud->connect_info.client_id = NULL; mud->connect_info.client_id = NULL;
} }
if(mud->connect_info.username) { if(mud->connect_info.username) {
c_free(mud->connect_info.username); free(mud->connect_info.username);
mud->connect_info.username = NULL; mud->connect_info.username = NULL;
} }
if(mud->connect_info.password) { if(mud->connect_info.password) {
c_free(mud->connect_info.password); free(mud->connect_info.password);
mud->connect_info.password = NULL; mud->connect_info.password = NULL;
} }
return luaL_error(L, "not enough memory"); return luaL_error(L, "not enough memory");
} }
c_memcpy(mud->connect_info.client_id, clientId, idl); memcpy(mud->connect_info.client_id, clientId, idl);
mud->connect_info.client_id[idl] = 0; mud->connect_info.client_id[idl] = 0;
c_memcpy(mud->connect_info.username, username, unl); memcpy(mud->connect_info.username, username, unl);
mud->connect_info.username[unl] = 0; mud->connect_info.username[unl] = 0;
c_memcpy(mud->connect_info.password, password, pwl); memcpy(mud->connect_info.password, password, pwl);
mud->connect_info.password[pwl] = 0; mud->connect_info.password[pwl] = 0;
NODE_DBG("MQTT: Init info: %s, %s, %s\r\n", mud->connect_info.client_id, mud->connect_info.username, mud->connect_info.password); NODE_DBG("MQTT: Init info: %s, %s, %s\r\n", mud->connect_info.client_id, mud->connect_info.username, mud->connect_info.password);
...@@ -801,35 +801,35 @@ static int mqtt_delete( lua_State* L ) ...@@ -801,35 +801,35 @@ static int mqtt_delete( lua_State* L )
if(mud->pesp_conn){ // for client connected to tcp server, this should set NULL in disconnect cb if(mud->pesp_conn){ // for client connected to tcp server, this should set NULL in disconnect cb
mud->pesp_conn->reverse = NULL; mud->pesp_conn->reverse = NULL;
if(mud->pesp_conn->proto.tcp) if(mud->pesp_conn->proto.tcp)
c_free(mud->pesp_conn->proto.tcp); free(mud->pesp_conn->proto.tcp);
mud->pesp_conn->proto.tcp = NULL; mud->pesp_conn->proto.tcp = NULL;
c_free(mud->pesp_conn); free(mud->pesp_conn);
mud->pesp_conn = NULL; // for socket, it will free this when disconnected mud->pesp_conn = NULL; // for socket, it will free this when disconnected
} }
// ---- alloc-ed in mqtt_socket_lwt() // ---- alloc-ed in mqtt_socket_lwt()
if(mud->connect_info.will_topic){ if(mud->connect_info.will_topic){
c_free(mud->connect_info.will_topic); free(mud->connect_info.will_topic);
mud->connect_info.will_topic = NULL; mud->connect_info.will_topic = NULL;
} }
if(mud->connect_info.will_message){ if(mud->connect_info.will_message){
c_free(mud->connect_info.will_message); free(mud->connect_info.will_message);
mud->connect_info.will_message = NULL; mud->connect_info.will_message = NULL;
} }
// ---- // ----
//--------- alloc-ed in mqtt_socket_client() //--------- alloc-ed in mqtt_socket_client()
if(mud->connect_info.client_id){ if(mud->connect_info.client_id){
c_free(mud->connect_info.client_id); free(mud->connect_info.client_id);
mud->connect_info.client_id = NULL; mud->connect_info.client_id = NULL;
} }
if(mud->connect_info.username){ if(mud->connect_info.username){
c_free(mud->connect_info.username); free(mud->connect_info.username);
mud->connect_info.username = NULL; mud->connect_info.username = NULL;
} }
if(mud->connect_info.password){ if(mud->connect_info.password){
c_free(mud->connect_info.password); free(mud->connect_info.password);
mud->connect_info.password = NULL; mud->connect_info.password = NULL;
} }
// ------- // -------
...@@ -938,7 +938,7 @@ static sint8 socket_dns_found(const char *name, ip_addr_t *ipaddr, void *arg) ...@@ -938,7 +938,7 @@ static sint8 socket_dns_found(const char *name, ip_addr_t *ipaddr, void *arg)
if(ipaddr->addr != 0) if(ipaddr->addr != 0)
{ {
dns_reconn_count = 0; dns_reconn_count = 0;
c_memcpy(pesp_conn->proto.tcp->remote_ip, &(ipaddr->addr), 4); memcpy(pesp_conn->proto.tcp->remote_ip, &(ipaddr->addr), 4);
NODE_DBG("TCP ip is set: "); NODE_DBG("TCP ip is set: ");
NODE_DBG(IPSTR, IP2STR(&(ipaddr->addr))); NODE_DBG(IPSTR, IP2STR(&(ipaddr->addr)));
NODE_DBG("\n"); NODE_DBG("\n");
...@@ -976,21 +976,21 @@ static int mqtt_socket_connect( lua_State* L ) ...@@ -976,21 +976,21 @@ static int mqtt_socket_connect( lua_State* L )
if(mud->pesp_conn){ //TODO: should I free tcp struct directly or ask user to call close()??? if(mud->pesp_conn){ //TODO: should I free tcp struct directly or ask user to call close()???
mud->pesp_conn->reverse = NULL; mud->pesp_conn->reverse = NULL;
if(mud->pesp_conn->proto.tcp) if(mud->pesp_conn->proto.tcp)
c_free(mud->pesp_conn->proto.tcp); free(mud->pesp_conn->proto.tcp);
mud->pesp_conn->proto.tcp = NULL; mud->pesp_conn->proto.tcp = NULL;
c_free(mud->pesp_conn); free(mud->pesp_conn);
mud->pesp_conn = NULL; mud->pesp_conn = NULL;
} }
struct espconn *pesp_conn = NULL; struct espconn *pesp_conn = NULL;
pesp_conn = mud->pesp_conn = (struct espconn *)c_zalloc(sizeof(struct espconn)); pesp_conn = mud->pesp_conn = (struct espconn *)zalloc(sizeof(struct espconn));
if(!pesp_conn) if(!pesp_conn)
return luaL_error(L, "not enough memory"); return luaL_error(L, "not enough memory");
pesp_conn->proto.udp = NULL; pesp_conn->proto.udp = NULL;
pesp_conn->proto.tcp = (esp_tcp *)c_zalloc(sizeof(esp_tcp)); pesp_conn->proto.tcp = (esp_tcp *)zalloc(sizeof(esp_tcp));
if(!pesp_conn->proto.tcp){ if(!pesp_conn->proto.tcp){
c_free(pesp_conn); free(pesp_conn);
pesp_conn = mud->pesp_conn = NULL; pesp_conn = mud->pesp_conn = NULL;
return luaL_error(L, "not enough memory"); return luaL_error(L, "not enough memory");
} }
...@@ -1010,7 +1010,7 @@ static int mqtt_socket_connect( lua_State* L ) ...@@ -1010,7 +1010,7 @@ static int mqtt_socket_connect( lua_State* L )
domain = "127.0.0.1"; domain = "127.0.0.1";
} }
ipaddr.addr = ipaddr_addr(domain); ipaddr.addr = ipaddr_addr(domain);
c_memcpy(pesp_conn->proto.tcp->remote_ip, &ipaddr.addr, 4); memcpy(pesp_conn->proto.tcp->remote_ip, &ipaddr.addr, 4);
NODE_DBG("TCP ip is set: "); NODE_DBG("TCP ip is set: ");
NODE_DBG(IPSTR, IP2STR(&ipaddr.addr)); NODE_DBG(IPSTR, IP2STR(&ipaddr.addr));
NODE_DBG("\n"); NODE_DBG("\n");
...@@ -1085,7 +1085,7 @@ static int mqtt_socket_connect( lua_State* L ) ...@@ -1085,7 +1085,7 @@ static int mqtt_socket_connect( lua_State* L )
os_timer_setfn(&mud->mqttTimer, (os_timer_func_t *)mqtt_socket_timer, mud); os_timer_setfn(&mud->mqttTimer, (os_timer_func_t *)mqtt_socket_timer, mud);
// timer started in socket_connect() // timer started in socket_connect()
if((ipaddr.addr == IPADDR_NONE) && (c_memcmp(domain,"255.255.255.255",16) != 0)) if((ipaddr.addr == IPADDR_NONE) && (memcmp(domain,"255.255.255.255",16) != 0))
{ {
host_ip.addr = 0; host_ip.addr = 0;
dns_reconn_count = 0; dns_reconn_count = 0;
...@@ -1179,13 +1179,13 @@ static int mqtt_socket_on( lua_State* L ) ...@@ -1179,13 +1179,13 @@ static int mqtt_socket_on( lua_State* L )
luaL_checkanyfunction(L, 3); luaL_checkanyfunction(L, 3);
lua_pushvalue(L, 3); // copy argument (func) to the top of stack lua_pushvalue(L, 3); // copy argument (func) to the top of stack
if( sl == 7 && c_strcmp(method, "connect") == 0){ if( sl == 7 && strcmp(method, "connect") == 0){
luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_connect_ref); luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_connect_ref);
mud->cb_connect_ref = luaL_ref(L, LUA_REGISTRYINDEX); mud->cb_connect_ref = luaL_ref(L, LUA_REGISTRYINDEX);
}else if( sl == 7 && c_strcmp(method, "offline") == 0){ }else if( sl == 7 && strcmp(method, "offline") == 0){
luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_disconnect_ref); luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_disconnect_ref);
mud->cb_disconnect_ref = luaL_ref(L, LUA_REGISTRYINDEX); mud->cb_disconnect_ref = luaL_ref(L, LUA_REGISTRYINDEX);
}else if( sl == 7 && c_strcmp(method, "message") == 0){ }else if( sl == 7 && strcmp(method, "message") == 0){
luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_message_ref); luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_message_ref);
mud->cb_message_ref = luaL_ref(L, LUA_REGISTRYINDEX); mud->cb_message_ref = luaL_ref(L, LUA_REGISTRYINDEX);
}else{ }else{
...@@ -1528,30 +1528,30 @@ static int mqtt_socket_lwt( lua_State* L ) ...@@ -1528,30 +1528,30 @@ static int mqtt_socket_lwt( lua_State* L )
} }
stack++; stack++;
if(mud->connect_info.will_topic){ // free the previous one if there is any if(mud->connect_info.will_topic){ // free the previous one if there is any
c_free(mud->connect_info.will_topic); free(mud->connect_info.will_topic);
mud->connect_info.will_topic = NULL; mud->connect_info.will_topic = NULL;
} }
if(mud->connect_info.will_message){ if(mud->connect_info.will_message){
c_free(mud->connect_info.will_message); free(mud->connect_info.will_message);
mud->connect_info.will_message = NULL; mud->connect_info.will_message = NULL;
} }
mud->connect_info.will_topic = (uint8_t*) c_zalloc( topicSize + 1 ); mud->connect_info.will_topic = (uint8_t*) zalloc( topicSize + 1 );
mud->connect_info.will_message = (uint8_t*) c_zalloc( msgSize + 1 ); mud->connect_info.will_message = (uint8_t*) zalloc( msgSize + 1 );
if(!mud->connect_info.will_topic || !mud->connect_info.will_message){ if(!mud->connect_info.will_topic || !mud->connect_info.will_message){
if(mud->connect_info.will_topic){ if(mud->connect_info.will_topic){
c_free(mud->connect_info.will_topic); free(mud->connect_info.will_topic);
mud->connect_info.will_topic = NULL; mud->connect_info.will_topic = NULL;
} }
if(mud->connect_info.will_message){ if(mud->connect_info.will_message){
c_free(mud->connect_info.will_message); free(mud->connect_info.will_message);
mud->connect_info.will_message = NULL; mud->connect_info.will_message = NULL;
} }
return luaL_error( L, "not enough memory"); return luaL_error( L, "not enough memory");
} }
c_memcpy(mud->connect_info.will_topic, lwtTopic, topicSize); memcpy(mud->connect_info.will_topic, lwtTopic, topicSize);
mud->connect_info.will_topic[topicSize] = 0; mud->connect_info.will_topic[topicSize] = 0;
c_memcpy(mud->connect_info.will_message, lwtMsg, msgSize); memcpy(mud->connect_info.will_message, lwtMsg, msgSize);
mud->connect_info.will_message[msgSize] = 0; mud->connect_info.will_message[msgSize] = 0;
if ( lua_isnumber(L, stack) ) if ( lua_isnumber(L, stack) )
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
#include "platform.h" #include "platform.h"
#include "lmem.h" #include "lmem.h"
#include "c_string.h" #include <string.h>
#include "c_stdlib.h" #include <stdlib.h>
#include "c_types.h" #include "c_types.h"
#include "mem.h" #include "mem.h"
...@@ -70,7 +70,7 @@ static void net_server_disconnected(void *arg) // for tcp server only ...@@ -70,7 +70,7 @@ static void net_server_disconnected(void *arg) // for tcp server only
return; return;
#if 0 #if 0
char temp[20] = {0}; char temp[20] = {0};
c_sprintf(temp, IPSTR, IP2STR( &(pesp_conn->proto.tcp->remote_ip) ) ); sprintf(temp, IPSTR, IP2STR( &(pesp_conn->proto.tcp->remote_ip) ) );
NODE_DBG("remote "); NODE_DBG("remote ");
NODE_DBG(temp); NODE_DBG(temp);
NODE_DBG(":"); NODE_DBG(":");
...@@ -117,10 +117,10 @@ static void net_socket_disconnected(void *arg) // tcp only ...@@ -117,10 +117,10 @@ static void net_socket_disconnected(void *arg) // tcp only
} }
if(pesp_conn->proto.tcp) if(pesp_conn->proto.tcp)
c_free(pesp_conn->proto.tcp); free(pesp_conn->proto.tcp);
pesp_conn->proto.tcp = NULL; pesp_conn->proto.tcp = NULL;
if(nud->pesp_conn) if(nud->pesp_conn)
c_free(nud->pesp_conn); free(nud->pesp_conn);
nud->pesp_conn = NULL; // espconn is already disconnected nud->pesp_conn = NULL; // espconn is already disconnected
lua_gc(gL, LUA_GCSTOP, 0); lua_gc(gL, LUA_GCSTOP, 0);
if(nud->self_ref != LUA_NOREF){ if(nud->self_ref != LUA_NOREF){
...@@ -214,10 +214,10 @@ static void net_dns_found(const char *name, ip_addr_t *ipaddr, void *arg) ...@@ -214,10 +214,10 @@ static void net_dns_found(const char *name, ip_addr_t *ipaddr, void *arg)
} }
// ipaddr->addr is a uint32_t ip // ipaddr->addr is a uint32_t ip
char ip_str[20]; char ip_str[20];
c_memset(ip_str, 0, sizeof(ip_str)); memset(ip_str, 0, sizeof(ip_str));
if(ipaddr->addr != 0) if(ipaddr->addr != 0)
{ {
c_sprintf(ip_str, IPSTR, IP2STR(&(ipaddr->addr))); sprintf(ip_str, IPSTR, IP2STR(&(ipaddr->addr)));
} }
lua_rawgeti(gL, LUA_REGISTRYINDEX, nud->cb_dns_found_ref); // the callback function lua_rawgeti(gL, LUA_REGISTRYINDEX, nud->cb_dns_found_ref); // the callback function
...@@ -237,10 +237,10 @@ static void net_dns_found(const char *name, ip_addr_t *ipaddr, void *arg) ...@@ -237,10 +237,10 @@ static void net_dns_found(const char *name, ip_addr_t *ipaddr, void *arg)
}else{ }else{
// ipaddr->addr is a uint32_t ip // ipaddr->addr is a uint32_t ip
char ip_str[20]; char ip_str[20];
c_memset(ip_str, 0, sizeof(ip_str)); memset(ip_str, 0, sizeof(ip_str));
if(ipaddr->addr != 0) if(ipaddr->addr != 0)
{ {
c_sprintf(ip_str, IPSTR, IP2STR(&(ipaddr->addr))); sprintf(ip_str, IPSTR, IP2STR(&(ipaddr->addr)));
} }
lua_pushstring(gL, ip_str); // the ip para lua_pushstring(gL, ip_str); // the ip para
} }
...@@ -271,7 +271,7 @@ static void net_server_connected(void *arg) // for tcp only ...@@ -271,7 +271,7 @@ static void net_server_connected(void *arg) // for tcp only
#if 0 #if 0
char temp[20] = {0}; char temp[20] = {0};
c_sprintf(temp, IPSTR, IP2STR( &(pesp_conn->proto.tcp->remote_ip) ) ); sprintf(temp, IPSTR, IP2STR( &(pesp_conn->proto.tcp->remote_ip) ) );
NODE_DBG("remote "); NODE_DBG("remote ");
NODE_DBG(temp); NODE_DBG(temp);
NODE_DBG(":"); NODE_DBG(":");
...@@ -377,9 +377,9 @@ static int net_create( lua_State* L, const char* mt ) ...@@ -377,9 +377,9 @@ static int net_create( lua_State* L, const char* mt )
uint8_t stack = 1; uint8_t stack = 1;
bool isserver = false; bool isserver = false;
if (mt!=NULL && c_strcmp(mt, "net.server")==0) if (mt!=NULL && strcmp(mt, "net.server")==0)
isserver = true; isserver = true;
else if (mt!=NULL && c_strcmp(mt, "net.socket")==0) else if (mt!=NULL && strcmp(mt, "net.socket")==0)
isserver = false; isserver = false;
else else
{ {
...@@ -454,7 +454,7 @@ static int net_create( lua_State* L, const char* mt ) ...@@ -454,7 +454,7 @@ static int net_create( lua_State* L, const char* mt )
} }
pesp_conn = nud->pesp_conn = pUdpServer; pesp_conn = nud->pesp_conn = pUdpServer;
} else { } else {
pesp_conn = nud->pesp_conn = (struct espconn *)c_zalloc(sizeof(struct espconn)); pesp_conn = nud->pesp_conn = (struct espconn *)zalloc(sizeof(struct espconn));
if(!pesp_conn) if(!pesp_conn)
return luaL_error(L, "not enough memory"); return luaL_error(L, "not enough memory");
...@@ -463,9 +463,9 @@ static int net_create( lua_State* L, const char* mt ) ...@@ -463,9 +463,9 @@ static int net_create( lua_State* L, const char* mt )
pesp_conn->reverse = NULL; pesp_conn->reverse = NULL;
if( type==ESPCONN_TCP ) if( type==ESPCONN_TCP )
{ {
pesp_conn->proto.tcp = (esp_tcp *)c_zalloc(sizeof(esp_tcp)); pesp_conn->proto.tcp = (esp_tcp *)zalloc(sizeof(esp_tcp));
if(!pesp_conn->proto.tcp){ if(!pesp_conn->proto.tcp){
c_free(pesp_conn); free(pesp_conn);
pesp_conn = nud->pesp_conn = NULL; pesp_conn = nud->pesp_conn = NULL;
return luaL_error(L, "not enough memory"); return luaL_error(L, "not enough memory");
} }
...@@ -473,9 +473,9 @@ static int net_create( lua_State* L, const char* mt ) ...@@ -473,9 +473,9 @@ static int net_create( lua_State* L, const char* mt )
} }
else if( type==ESPCONN_UDP ) else if( type==ESPCONN_UDP )
{ {
pesp_conn->proto.udp = (esp_udp *)c_zalloc(sizeof(esp_udp)); pesp_conn->proto.udp = (esp_udp *)zalloc(sizeof(esp_udp));
if(!pesp_conn->proto.udp){ if(!pesp_conn->proto.udp){
c_free(pesp_conn); free(pesp_conn);
pesp_conn = nud->pesp_conn = NULL; pesp_conn = nud->pesp_conn = NULL;
return luaL_error(L, "not enough memory"); return luaL_error(L, "not enough memory");
} }
...@@ -515,9 +515,9 @@ static int net_delete( lua_State* L, const char* mt ) ...@@ -515,9 +515,9 @@ static int net_delete( lua_State* L, const char* mt )
{ {
NODE_DBG("net_delete is called.\n"); NODE_DBG("net_delete is called.\n");
bool isserver = false; bool isserver = false;
if (mt!=NULL && c_strcmp(mt, "net.server")==0) if (mt!=NULL && strcmp(mt, "net.server")==0)
isserver = true; isserver = true;
else if (mt!=NULL && c_strcmp(mt, "net.socket")==0) else if (mt!=NULL && strcmp(mt, "net.socket")==0)
isserver = false; isserver = false;
else else
{ {
...@@ -539,14 +539,14 @@ static int net_delete( lua_State* L, const char* mt ) ...@@ -539,14 +539,14 @@ static int net_delete( lua_State* L, const char* mt )
{ {
if(nud->pesp_conn->type == ESPCONN_UDP){ if(nud->pesp_conn->type == ESPCONN_UDP){
if(nud->pesp_conn->proto.udp) if(nud->pesp_conn->proto.udp)
c_free(nud->pesp_conn->proto.udp); free(nud->pesp_conn->proto.udp);
nud->pesp_conn->proto.udp = NULL; nud->pesp_conn->proto.udp = NULL;
} else if (nud->pesp_conn->type == ESPCONN_TCP) { } else if (nud->pesp_conn->type == ESPCONN_TCP) {
if(nud->pesp_conn->proto.tcp) if(nud->pesp_conn->proto.tcp)
c_free(nud->pesp_conn->proto.tcp); free(nud->pesp_conn->proto.tcp);
nud->pesp_conn->proto.tcp = NULL; nud->pesp_conn->proto.tcp = NULL;
} }
c_free(nud->pesp_conn); free(nud->pesp_conn);
} }
nud->pesp_conn = NULL; // for socket, it will free this when disconnected nud->pesp_conn = NULL; // for socket, it will free this when disconnected
} }
...@@ -653,14 +653,14 @@ static void socket_dns_found(const char *name, ip_addr_t *ipaddr, void *arg) ...@@ -653,14 +653,14 @@ static void socket_dns_found(const char *name, ip_addr_t *ipaddr, void *arg)
dns_reconn_count = 0; dns_reconn_count = 0;
if( pesp_conn->type == ESPCONN_TCP ) if( pesp_conn->type == ESPCONN_TCP )
{ {
c_memcpy(pesp_conn->proto.tcp->remote_ip, &(ipaddr->addr), 4); memcpy(pesp_conn->proto.tcp->remote_ip, &(ipaddr->addr), 4);
NODE_DBG("TCP ip is set: "); NODE_DBG("TCP ip is set: ");
NODE_DBG(IPSTR, IP2STR(&(ipaddr->addr))); NODE_DBG(IPSTR, IP2STR(&(ipaddr->addr)));
NODE_DBG("\n"); NODE_DBG("\n");
} }
else if (pesp_conn->type == ESPCONN_UDP) else if (pesp_conn->type == ESPCONN_UDP)
{ {
c_memcpy(pesp_conn->proto.udp->remote_ip, &(ipaddr->addr), 4); memcpy(pesp_conn->proto.udp->remote_ip, &(ipaddr->addr), 4);
NODE_DBG("UDP ip is set: "); NODE_DBG("UDP ip is set: ");
NODE_DBG(IPSTR, IP2STR(&(ipaddr->addr))); NODE_DBG(IPSTR, IP2STR(&(ipaddr->addr)));
NODE_DBG("\n"); NODE_DBG("\n");
...@@ -683,9 +683,9 @@ static int net_start( lua_State* L, const char* mt ) ...@@ -683,9 +683,9 @@ static int net_start( lua_State* L, const char* mt )
const char *domain; const char *domain;
uint8_t stack = 1; uint8_t stack = 1;
if (mt!=NULL && c_strcmp(mt, "net.server")==0) if (mt!=NULL && strcmp(mt, "net.server")==0)
isserver = true; isserver = true;
else if (mt!=NULL && c_strcmp(mt, "net.socket")==0) else if (mt!=NULL && strcmp(mt, "net.socket")==0)
isserver = false; isserver = false;
else else
{ {
...@@ -744,9 +744,9 @@ static int net_start( lua_State* L, const char* mt ) ...@@ -744,9 +744,9 @@ static int net_start( lua_State* L, const char* mt )
if( pesp_conn->type == ESPCONN_TCP ) if( pesp_conn->type == ESPCONN_TCP )
{ {
if(isserver) if(isserver)
c_memcpy(pesp_conn->proto.tcp->local_ip, &ipaddr.addr, 4); memcpy(pesp_conn->proto.tcp->local_ip, &ipaddr.addr, 4);
else else
c_memcpy(pesp_conn->proto.tcp->remote_ip, &ipaddr.addr, 4); memcpy(pesp_conn->proto.tcp->remote_ip, &ipaddr.addr, 4);
NODE_DBG("TCP ip is set: "); NODE_DBG("TCP ip is set: ");
NODE_DBG(IPSTR, IP2STR(&ipaddr.addr)); NODE_DBG(IPSTR, IP2STR(&ipaddr.addr));
NODE_DBG("\n"); NODE_DBG("\n");
...@@ -754,9 +754,9 @@ static int net_start( lua_State* L, const char* mt ) ...@@ -754,9 +754,9 @@ static int net_start( lua_State* L, const char* mt )
else if (pesp_conn->type == ESPCONN_UDP) else if (pesp_conn->type == ESPCONN_UDP)
{ {
if(isserver) if(isserver)
c_memcpy(pesp_conn->proto.udp->local_ip, &ipaddr.addr, 4); memcpy(pesp_conn->proto.udp->local_ip, &ipaddr.addr, 4);
else else
c_memcpy(pesp_conn->proto.udp->remote_ip, &ipaddr.addr, 4); memcpy(pesp_conn->proto.udp->remote_ip, &ipaddr.addr, 4);
NODE_DBG("UDP ip is set: "); NODE_DBG("UDP ip is set: ");
NODE_DBG(IPSTR, IP2STR(&ipaddr.addr)); NODE_DBG(IPSTR, IP2STR(&ipaddr.addr));
NODE_DBG("\n"); NODE_DBG("\n");
...@@ -831,7 +831,7 @@ static int net_start( lua_State* L, const char* mt ) ...@@ -831,7 +831,7 @@ static int net_start( lua_State* L, const char* mt )
} }
if(!isserver){ if(!isserver){
if((ipaddr.addr == IPADDR_NONE) && (c_memcmp(domain,"255.255.255.255",16) != 0)) if((ipaddr.addr == IPADDR_NONE) && (memcmp(domain,"255.255.255.255",16) != 0))
{ {
host_ip.addr = 0; host_ip.addr = 0;
dns_reconn_count = 0; dns_reconn_count = 0;
...@@ -865,9 +865,9 @@ static int net_close( lua_State* L, const char* mt ) ...@@ -865,9 +865,9 @@ static int net_close( lua_State* L, const char* mt )
if(nud->pesp_conn == NULL) if(nud->pesp_conn == NULL)
return 0; return 0;
if (mt!=NULL && c_strcmp(mt, "net.server")==0) if (mt!=NULL && strcmp(mt, "net.server")==0)
isserver = true; isserver = true;
else if (mt!=NULL && c_strcmp(mt, "net.socket")==0) else if (mt!=NULL && strcmp(mt, "net.socket")==0)
isserver = false; isserver = false;
else else
{ {
...@@ -973,9 +973,9 @@ static int net_on( lua_State* L, const char* mt ) ...@@ -973,9 +973,9 @@ static int net_on( lua_State* L, const char* mt )
return 0; return 0;
} }
if (mt!=NULL && c_strcmp(mt, "net.server")==0) if (mt!=NULL && strcmp(mt, "net.server")==0)
isserver = true; isserver = true;
else if (mt!=NULL && c_strcmp(mt, "net.socket")==0) else if (mt!=NULL && strcmp(mt, "net.socket")==0)
isserver = false; isserver = false;
else else
{ {
...@@ -990,27 +990,27 @@ static int net_on( lua_State* L, const char* mt ) ...@@ -990,27 +990,27 @@ static int net_on( lua_State* L, const char* mt )
luaL_checkanyfunction(L, 3); luaL_checkanyfunction(L, 3);
lua_pushvalue(L, 3); // copy argument (func) to the top of stack lua_pushvalue(L, 3); // copy argument (func) to the top of stack
if(!isserver && nud->pesp_conn->type == ESPCONN_TCP && sl == 10 && c_strcmp(method, "connection") == 0){ if(!isserver && nud->pesp_conn->type == ESPCONN_TCP && sl == 10 && strcmp(method, "connection") == 0){
if(nud->cb_connect_ref != LUA_NOREF) if(nud->cb_connect_ref != LUA_NOREF)
luaL_unref(L, LUA_REGISTRYINDEX, nud->cb_connect_ref); luaL_unref(L, LUA_REGISTRYINDEX, nud->cb_connect_ref);
nud->cb_connect_ref = luaL_ref(L, LUA_REGISTRYINDEX); nud->cb_connect_ref = luaL_ref(L, LUA_REGISTRYINDEX);
}else if(!isserver && nud->pesp_conn->type == ESPCONN_TCP && sl == 12 && c_strcmp(method, "reconnection") == 0){ }else if(!isserver && nud->pesp_conn->type == ESPCONN_TCP && sl == 12 && strcmp(method, "reconnection") == 0){
if(nud->cb_reconnect_ref != LUA_NOREF) if(nud->cb_reconnect_ref != LUA_NOREF)
luaL_unref(L, LUA_REGISTRYINDEX, nud->cb_reconnect_ref); luaL_unref(L, LUA_REGISTRYINDEX, nud->cb_reconnect_ref);
nud->cb_reconnect_ref = luaL_ref(L, LUA_REGISTRYINDEX); nud->cb_reconnect_ref = luaL_ref(L, LUA_REGISTRYINDEX);
}else if(!isserver && nud->pesp_conn->type == ESPCONN_TCP && sl == 13 && c_strcmp(method, "disconnection") == 0){ }else if(!isserver && nud->pesp_conn->type == ESPCONN_TCP && sl == 13 && strcmp(method, "disconnection") == 0){
if(nud->cb_disconnect_ref != LUA_NOREF) if(nud->cb_disconnect_ref != LUA_NOREF)
luaL_unref(L, LUA_REGISTRYINDEX, nud->cb_disconnect_ref); luaL_unref(L, LUA_REGISTRYINDEX, nud->cb_disconnect_ref);
nud->cb_disconnect_ref = luaL_ref(L, LUA_REGISTRYINDEX); nud->cb_disconnect_ref = luaL_ref(L, LUA_REGISTRYINDEX);
}else if((!isserver || nud->pesp_conn->type == ESPCONN_UDP) && sl == 7 && c_strcmp(method, "receive") == 0){ }else if((!isserver || nud->pesp_conn->type == ESPCONN_UDP) && sl == 7 && strcmp(method, "receive") == 0){
if(nud->cb_receive_ref != LUA_NOREF) if(nud->cb_receive_ref != LUA_NOREF)
luaL_unref(L, LUA_REGISTRYINDEX, nud->cb_receive_ref); luaL_unref(L, LUA_REGISTRYINDEX, nud->cb_receive_ref);
nud->cb_receive_ref = luaL_ref(L, LUA_REGISTRYINDEX); nud->cb_receive_ref = luaL_ref(L, LUA_REGISTRYINDEX);
}else if((!isserver || nud->pesp_conn->type == ESPCONN_UDP) && sl == 4 && c_strcmp(method, "sent") == 0){ }else if((!isserver || nud->pesp_conn->type == ESPCONN_UDP) && sl == 4 && strcmp(method, "sent") == 0){
if(nud->cb_send_ref != LUA_NOREF) if(nud->cb_send_ref != LUA_NOREF)
luaL_unref(L, LUA_REGISTRYINDEX, nud->cb_send_ref); luaL_unref(L, LUA_REGISTRYINDEX, nud->cb_send_ref);
nud->cb_send_ref = luaL_ref(L, LUA_REGISTRYINDEX); nud->cb_send_ref = luaL_ref(L, LUA_REGISTRYINDEX);
}else if(!isserver && nud->pesp_conn->type == ESPCONN_TCP && sl == 3 && c_strcmp(method, "dns") == 0){ }else if(!isserver && nud->pesp_conn->type == ESPCONN_TCP && sl == 3 && strcmp(method, "dns") == 0){
if(nud->cb_dns_found_ref != LUA_NOREF) if(nud->cb_dns_found_ref != LUA_NOREF)
luaL_unref(L, LUA_REGISTRYINDEX, nud->cb_dns_found_ref); luaL_unref(L, LUA_REGISTRYINDEX, nud->cb_dns_found_ref);
nud->cb_dns_found_ref = luaL_ref(L, LUA_REGISTRYINDEX); nud->cb_dns_found_ref = luaL_ref(L, LUA_REGISTRYINDEX);
...@@ -1044,9 +1044,9 @@ static int net_send( lua_State* L, const char* mt ) ...@@ -1044,9 +1044,9 @@ static int net_send( lua_State* L, const char* mt )
} }
pesp_conn = nud->pesp_conn; pesp_conn = nud->pesp_conn;
if (mt!=NULL && c_strcmp(mt, "net.server")==0) if (mt!=NULL && strcmp(mt, "net.server")==0)
isserver = true; isserver = true;
else if (mt!=NULL && c_strcmp(mt, "net.socket")==0) else if (mt!=NULL && strcmp(mt, "net.socket")==0)
isserver = false; isserver = false;
else else
{ {
...@@ -1060,7 +1060,7 @@ static int net_send( lua_State* L, const char* mt ) ...@@ -1060,7 +1060,7 @@ static int net_send( lua_State* L, const char* mt )
#if 0 #if 0
char temp[20] = {0}; char temp[20] = {0};
c_sprintf(temp, IPSTR, IP2STR( &(pesp_conn->proto.tcp->remote_ip) ) ); sprintf(temp, IPSTR, IP2STR( &(pesp_conn->proto.tcp->remote_ip) ) );
NODE_DBG("remote "); NODE_DBG("remote ");
NODE_DBG(temp); NODE_DBG(temp);
NODE_DBG(":"); NODE_DBG(":");
...@@ -1085,8 +1085,8 @@ static int net_send( lua_State* L, const char* mt ) ...@@ -1085,8 +1085,8 @@ static int net_send( lua_State* L, const char* mt )
if (espconn_get_connection_info (pesp_conn, &pr, 0) != ESPCONN_OK) if (espconn_get_connection_info (pesp_conn, &pr, 0) != ESPCONN_OK)
return luaL_error (L, "remote ip/port unavailable"); return luaL_error (L, "remote ip/port unavailable");
pesp_conn->proto.udp->remote_port = pr->remote_port; pesp_conn->proto.udp->remote_port = pr->remote_port;
os_memmove (pesp_conn->proto.udp->remote_ip, pr->remote_ip, 4); memmove (pesp_conn->proto.udp->remote_ip, pr->remote_ip, 4);
// The remot_info apparently should *not* be os_free()d, fyi // The remot_info apparently should *not* be free()d, fyi
} }
#ifdef CLIENT_SSL_ENABLE #ifdef CLIENT_SSL_ENABLE
if(nud->secure) if(nud->secure)
...@@ -1114,9 +1114,9 @@ static int net_dns( lua_State* L, const char* mt ) ...@@ -1114,9 +1114,9 @@ static int net_dns( lua_State* L, const char* mt )
return 0; return 0;
} }
if (mt!=NULL && c_strcmp(mt, "net.server")==0) if (mt!=NULL && strcmp(mt, "net.server")==0)
isserver = true; isserver = true;
else if (mt!=NULL && c_strcmp(mt, "net.socket")==0) else if (mt!=NULL && strcmp(mt, "net.socket")==0)
isserver = false; isserver = false;
else else
{ {
...@@ -1365,7 +1365,7 @@ static int net_socket_getpeer( lua_State* L ) ...@@ -1365,7 +1365,7 @@ static int net_socket_getpeer( lua_State* L )
if(nud!=NULL && nud->pesp_conn!=NULL ){ if(nud!=NULL && nud->pesp_conn!=NULL ){
char temp[20] = {0}; char temp[20] = {0};
c_sprintf(temp, IPSTR, IP2STR( &(nud->pesp_conn->proto.tcp->remote_ip) ) ); sprintf(temp, IPSTR, IP2STR( &(nud->pesp_conn->proto.tcp->remote_ip) ) );
if ( nud->pesp_conn->proto.tcp->remote_port != 0 ) { if ( nud->pesp_conn->proto.tcp->remote_port != 0 ) {
lua_pushstring( L, temp ); lua_pushstring( L, temp );
lua_pushinteger( L, nud->pesp_conn->proto.tcp->remote_port ); lua_pushinteger( L, nud->pesp_conn->proto.tcp->remote_port );
...@@ -1532,7 +1532,7 @@ static const char *fill_page_with_pem(lua_State *L, const unsigned char *flash_m ...@@ -1532,7 +1532,7 @@ static const char *fill_page_with_pem(lua_State *L, const unsigned char *flash_m
memset(buffer, 0xff, buffer_limit - buffer); memset(buffer, 0xff, buffer_limit - buffer);
// Lets see if it matches what is already there.... // Lets see if it matches what is already there....
if (c_memcmp(buffer_base, flash_memory, INTERNAL_FLASH_SECTOR_SIZE) != 0) { if (memcmp(buffer_base, flash_memory, INTERNAL_FLASH_SECTOR_SIZE) != 0) {
// Starts being dangerous // Starts being dangerous
if (platform_flash_erase_sector(flash_offset / INTERNAL_FLASH_SECTOR_SIZE) != PLATFORM_OK) { if (platform_flash_erase_sector(flash_offset / INTERNAL_FLASH_SECTOR_SIZE) != PLATFORM_OK) {
luaM_free(L, buffer_base); luaM_free(L, buffer_base);
...@@ -1672,7 +1672,7 @@ static int net_getdnsserver( lua_State* L ) ...@@ -1672,7 +1672,7 @@ static int net_getdnsserver( lua_State* L )
lua_pushnil( L ); lua_pushnil( L );
} else { } else {
char temp[20] = {0}; char temp[20] = {0};
c_sprintf(temp, IPSTR, IP2STR( &ipaddr.addr ) ); sprintf(temp, IPSTR, IP2STR( &ipaddr.addr ) );
lua_pushstring( L, temp ); lua_pushstring( L, temp );
} }
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include "lrodefs.h" #include "lrodefs.h"
#include "c_types.h" #include "c_types.h"
#include "c_string.h" #include <string.h>
#include "driver/uart.h" #include "driver/uart.h"
#include "user_interface.h" #include "user_interface.h"
#include "flash_api.h" #include "flash_api.h"
...@@ -276,9 +276,9 @@ static int node_key( lua_State* L ) ...@@ -276,9 +276,9 @@ static int node_key( lua_State* L )
if (str == NULL) if (str == NULL)
return luaL_error( L, "wrong arg type" ); return luaL_error( L, "wrong arg type" );
if (sl == 5 && c_strcmp(str, "short") == 0) { if (sl == 5 && strcmp(str, "short") == 0) {
ref = &short_key_ref; ref = &short_key_ref;
} else if (sl == 4 && c_strcmp(str, "long") == 0) { } else if (sl == 4 && strcmp(str, "long") == 0) {
ref = &long_key_ref; ref = &long_key_ref;
} else { } else {
ref = &short_key_ref; ref = &short_key_ref;
...@@ -311,9 +311,9 @@ static int node_input( lua_State* L ) ...@@ -311,9 +311,9 @@ static int node_input( lua_State* L )
{ {
lua_Load *load = &gLoad; lua_Load *load = &gLoad;
if (load->line_position == 0) { if (load->line_position == 0) {
c_memcpy(load->line, s, l); memcpy(load->line, s, l);
load->line[l + 1] = '\0'; load->line[l + 1] = '\0';
load->line_position = c_strlen(load->line) + 1; load->line_position = strlen(load->line) + 1;
load->done = 1; load->done = 1;
NODE_DBG("Get command:\n"); NODE_DBG("Get command:\n");
NODE_DBG(load->line); // buggy here NODE_DBG(load->line); // buggy here
...@@ -328,7 +328,7 @@ static int output_redir_ref = LUA_NOREF; ...@@ -328,7 +328,7 @@ static int output_redir_ref = LUA_NOREF;
static int serial_debug = 1; static int serial_debug = 1;
void output_redirect(const char *str) { void output_redirect(const char *str) {
lua_State *L = lua_getstate(); lua_State *L = lua_getstate();
// if(c_strlen(str)>=TX_BUFF_SIZE){ // if(strlen(str)>=TX_BUFF_SIZE){
// NODE_ERR("output too long.\n"); // NODE_ERR("output too long.\n");
// return; // return;
// } // }
...@@ -402,13 +402,13 @@ static int node_compile( lua_State* L ) ...@@ -402,13 +402,13 @@ static int node_compile( lua_State* L )
return luaL_error(L, "filename too long"); return luaL_error(L, "filename too long");
char output[FS_NAME_MAX_LENGTH]; char output[FS_NAME_MAX_LENGTH];
c_strcpy(output, fname); strcpy(output, fname);
// check here that filename end with ".lua". // check here that filename end with ".lua".
if (len < 4 || (c_strcmp( output + len - 4, ".lua") != 0) ) if (len < 4 || (strcmp( output + len - 4, ".lua") != 0) )
return luaL_error(L, "not a .lua file"); return luaL_error(L, "not a .lua file");
output[c_strlen(output) - 2] = 'c'; output[strlen(output) - 2] = 'c';
output[c_strlen(output) - 1] = '\0'; output[strlen(output) - 1] = '\0';
NODE_DBG(output); NODE_DBG(output);
NODE_DBG("\n"); NODE_DBG("\n");
if (luaL_loadfsfile(L, fname) != 0) { if (luaL_loadfsfile(L, fname) != 0) {
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "ets_sys.h" #include "ets_sys.h"
#include "os_type.h" #include "os_type.h"
#include "osapi.h" #include "osapi.h"
#include "c_stdlib.h" #include <stdlib.h>
#include "module.h" #include "module.h"
#include "lauxlib.h" #include "lauxlib.h"
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "c_types.h" #include "c_types.h"
#include "user_interface.h" #include "user_interface.h"
#include "driver/rotary.h" #include "driver/rotary.h"
#include "../libc/c_stdlib.h" #include <stdlib.h>
#define MASK(x) (1 << ROTARY_ ## x ## _INDEX) #define MASK(x) (1 << ROTARY_ ## x ## _INDEX)
...@@ -143,7 +143,7 @@ static int lrotary_setup( lua_State* L ) ...@@ -143,7 +143,7 @@ static int lrotary_setup( lua_State* L )
callback_free(L, id, ROTARY_ALL); callback_free(L, id, ROTARY_ALL);
if (!data[id]) { if (!data[id]) {
data[id] = (DATA *) os_zalloc(sizeof(DATA)); data[id] = (DATA *) zalloc(sizeof(DATA));
if (!data[id]) { if (!data[id]) {
return -1; return -1;
} }
...@@ -202,7 +202,7 @@ static int lrotary_close( lua_State* L ) ...@@ -202,7 +202,7 @@ static int lrotary_close( lua_State* L )
DATA *d = data[id]; DATA *d = data[id];
if (d) { if (d) {
data[id] = NULL; data[id] = NULL;
os_free(d); free(d);
} }
if (rotary_close( id )) { if (rotary_close( id )) {
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "rtc/rtctime.h" #include "rtc/rtctime.h"
#define RTCTIME_SLEEP_ALIGNED rtctime_deep_sleep_until_aligned_us #define RTCTIME_SLEEP_ALIGNED rtctime_deep_sleep_until_aligned_us
#include "rtc/rtcfifo.h" #include "rtc/rtcfifo.h"
#include <string.h>
// rtcfifo.prepare ([{sensor_count=n, interval_us=m, storage_begin=x, storage_end=y}]) // rtcfifo.prepare ([{sensor_count=n, interval_us=m, storage_begin=x, storage_end=y}])
static int rtcfifo_prepare (lua_State *L) static int rtcfifo_prepare (lua_State *L)
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
#include "os_type.h" #include "os_type.h"
#include "osapi.h" #include "osapi.h"
#include "lwip/udp.h" #include "lwip/udp.h"
#include "c_stdlib.h" #include <stdlib.h>
#include "user_modules.h" #include "user_modules.h"
#include "lwip/dns.h" #include "lwip/dns.h"
#include "user_interface.h" #include "user_interface.h"
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
#define MAX_ATTEMPTS 5 #define MAX_ATTEMPTS 5
#if 0 #if 0
# define sntp_dbg(...) c_printf(__VA_ARGS__) # define sntp_dbg(...) printf(__VA_ARGS__)
#else #else
# define sntp_dbg(...) # define sntp_dbg(...)
#endif #endif
...@@ -110,7 +110,7 @@ static void cleanup (lua_State *L) ...@@ -110,7 +110,7 @@ static void cleanup (lua_State *L)
udp_remove (state->pcb); udp_remove (state->pcb);
luaL_unref (L, LUA_REGISTRYINDEX, state->sync_cb_ref); luaL_unref (L, LUA_REGISTRYINDEX, state->sync_cb_ref);
luaL_unref (L, LUA_REGISTRYINDEX, state->err_cb_ref); luaL_unref (L, LUA_REGISTRYINDEX, state->err_cb_ref);
os_free (state); free (state);
state = 0; state = 0;
} }
...@@ -328,7 +328,7 @@ static int sntp_sync (lua_State *L) ...@@ -328,7 +328,7 @@ static int sntp_sync (lua_State *L)
if (state) if (state)
return luaL_error (L, "sync in progress"); return luaL_error (L, "sync in progress");
state = (sntp_state_t *)c_malloc (sizeof (sntp_state_t)); state = (sntp_state_t *)malloc (sizeof (sntp_state_t));
if (!state) if (!state)
sync_err ("out of memory"); sync_err ("out of memory");
...@@ -386,7 +386,7 @@ error: ...@@ -386,7 +386,7 @@ error:
{ {
if (state->pcb) if (state->pcb)
udp_remove (state->pcb); udp_remove (state->pcb);
c_free (state); free (state);
state = 0; state = 0;
} }
return luaL_error (L, errmsg); return luaL_error (L, errmsg);
......
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