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 @@
#include "module.h"
#include "c_limits.h"
#include <limits.h>
#include "lauxlib.h"
......
......@@ -11,7 +11,7 @@
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "c_math.h"
#include <math.h>
#include "user_interface.h"
/****************************************************/
......
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "c_stdlib.h"
#include "c_string.h"
#include <stdlib.h>
#include <string.h>
#include "esp_misc.h"
static const uint32_t bmp085_i2c_id = 0;
......
......@@ -38,9 +38,9 @@
// #include <assert.h>
#include "module.h"
#include "c_string.h"
#include "c_math.h"
#include "c_limits.h"
#include <string.h>
#include <math.h>
#include <limits.h>
#include "lauxlib.h"
#include "flash_api.h"
#include "ctype.h"
......@@ -340,7 +340,7 @@ static int json_integer_option(lua_State *l, int optindex, int *setting,
if (!lua_isnil(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);
*setting = value;
}
......@@ -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);
// 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);
len = c_strlen(strbuf_empty_ptr(json));
sprintf(strbuf_empty_ptr(json), LUA_NUMBER_FMT, (LUA_NUMBER)num);
len = strlen(strbuf_empty_ptr(json));
strbuf_extend_length(json, len);
}
......@@ -1148,7 +1148,7 @@ static int json_is_invalid_number(json_parse_t *json)
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;
for (i = 0; i < 3; ++i)
{
......@@ -1160,9 +1160,9 @@ static int json_is_invalid_number(json_parse_t *json)
tmp[3] = 0;
/* Reject inf/nan */
if (!c_strncasecmp(tmp, "inf", 3))
if (!strncasecmp(tmp, "inf", 3))
return 1;
if (!c_strncasecmp(tmp, "nan", 3))
if (!strncasecmp(tmp, "nan", 3))
return 1;
/* 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)
}
json_next_number_token(json, token);
return;
} else if (!c_strncmp(json->ptr, "true", 4)) {
} else if (!strncmp(json->ptr, "true", 4)) {
token->type = T_BOOLEAN;
token->value.boolean = 1;
json->ptr += 4;
return;
} else if (!c_strncmp(json->ptr, "false", 5)) {
} else if (!strncmp(json->ptr, "false", 5)) {
token->type = T_BOOLEAN;
token->value.boolean = 0;
json->ptr += 5;
return;
} else if (!c_strncmp(json->ptr, "null", 4)) {
} else if (!strncmp(json->ptr, "null", 4)) {
token->type = T_NULL;
json->ptr += 4;
return;
......
......@@ -4,8 +4,8 @@
#include "lauxlib.h"
#include "platform.h"
#include "c_string.h"
#include "c_stdlib.h"
#include <string.h>
#include <stdlib.h>
#include "c_types.h"
#include "mem.h"
......@@ -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'
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) {
NODE_DBG("Request Entity Too Large.\n"); // NOTE: should response 4.13 to client...
return;
}
// c_memcpy(buf, pdata, len);
// memcpy(buf, pdata, len);
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)
if (espconn_get_connection_info (pesp_conn, &pr, 0) != ESPCONN_OK)
return;
pesp_conn->proto.udp->remote_port = pr->remote_port;
os_memmove (pesp_conn->proto.udp->remote_ip, pr->remote_ip, 4);
// The remot_info apparently should *not* be os_free()d, fyi
memmove (pesp_conn->proto.udp->remote_ip, pr->remote_ip, 4);
// The remot_info apparently should *not* be free()d, fyi
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)
......@@ -85,7 +85,7 @@ static int coap_create( lua_State* L, const char* mt )
lua_setmetatable(L, -2);
// create the espconn struct
pesp_conn = (struct espconn *)c_zalloc(sizeof(struct espconn));
pesp_conn = (struct espconn *)zalloc(sizeof(struct espconn));
if(!pesp_conn)
return luaL_error(L, "not enough memory");
......@@ -95,9 +95,9 @@ static int coap_create( lua_State* L, const char* mt )
pesp_conn->proto.tcp = 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){
c_free(pesp_conn);
free(pesp_conn);
cud->pesp_conn = pesp_conn = NULL;
return luaL_error(L, "not enough memory");
}
......@@ -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)
espconn_delete(cud->pesp_conn);
c_free(cud->pesp_conn->proto.udp);
free(cud->pesp_conn->proto.udp);
cud->pesp_conn->proto.udp = NULL;
c_free(cud->pesp_conn);
free(cud->pesp_conn);
cud->pesp_conn = NULL;
}
......@@ -174,7 +174,7 @@ static int coap_start( lua_State* L, const char* mt )
ip = "0.0.0.0";
}
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(IPSTR, IP2STR(&ipaddr.addr));
NODE_DBG("\n");
......@@ -239,7 +239,7 @@ static void coap_response_handler(void *arg, char *pdata, unsigned short len)
pkt.content.len = 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'
c_memset(buf, 0, sizeof(buf)); // wipe prev data
memset(buf, 0, sizeof(buf)); // wipe prev data
int rc;
if( len > MAX_MESSAGE_SIZE )
......@@ -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...
return;
}
c_memcpy(buf, pdata, len);
memcpy(buf, pdata, len);
if (0 != (rc = coap_parse(&pkt, buf, len))){
NODE_DBG("Bad packet rc=%d\n", rc);
......@@ -275,7 +275,7 @@ static void coap_response_handler(void *arg, char *pdata, unsigned short len)
uint32_t ip = 0, port = 0;
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;
coap_transaction_id(ip, port, &pkt, &id);
......@@ -307,7 +307,7 @@ end:
if(pesp_conn->proto.udp->remote_port || pesp_conn->proto.udp->local_port)
espconn_delete(pesp_conn);
}
// c_memset(buf, 0, sizeof(buf));
// memset(buf, 0, sizeof(buf));
}
// Lua: client:request( [CON], uri, [payload] )
......@@ -358,7 +358,7 @@ static int coap_request( lua_State* L, coap_method_t m )
pesp_conn->proto.udp->local_port = espconn_port();
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';
ipaddr.addr = ipaddr_addr(host);
......@@ -366,7 +366,7 @@ static int coap_request( lua_State* L, coap_method_t m )
NODE_DBG(host);
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(IPSTR, IP2STR(&ipaddr.addr));
NODE_DBG("\n");
......@@ -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
if(!pdu){
if(uri)
c_free(uri);
free(uri);
return luaL_error (L, "alloc fail");
}
......@@ -426,7 +426,7 @@ static int coap_request( lua_State* L, coap_method_t m )
}
if(uri)
c_free((void *)uri);
free((void *)uri);
NODE_DBG("coap_request is called.\n");
return 0;
......@@ -451,13 +451,13 @@ static int coap_regist( lua_State* L, const char* mt, int isvar )
h = function_entry;
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;
h = h->next;
}
if(h->name==NULL || c_strcmp(h->name, name)!=0){ // not exists. make a new one.
h->next = (coap_luser_entry *)c_zalloc(sizeof(coap_luser_entry));
if(h->name==NULL || strcmp(h->name, name)!=0){ // not exists. make a new one.
h->next = (coap_luser_entry *)zalloc(sizeof(coap_luser_entry));
h = h->next;
if(h == NULL)
return luaL_error(L, "not enough memory");
......
// Module for cryptography
#include <c_errno.h>
#include <errno.h>
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "c_types.h"
#include "c_stdlib.h"
#include <stdlib.h>
#include "flash_fs.h"
#include "../crypto/digests.h"
#include "../crypto/mech.h"
......@@ -71,7 +71,7 @@ static int crypto_base64_encode( lua_State* L )
int len;
const char* msg = luaL_checklstring(L, 1, &len);
int blen = (len + 2) / 3 * 4;
char* out = (char*)c_malloc(blen);
char* out = (char*)malloc(blen);
int j = 0, i;
for (i = 0; i < len; i += 3) {
int a = msg[i];
......@@ -83,7 +83,7 @@ static int crypto_base64_encode( lua_State* L )
out[j++] = (i + 2 < len) ? bytes64[(c & 63)] : 61;
}
lua_pushlstring(L, out, j);
c_free(out);
free(out);
return 1;
}
......@@ -96,14 +96,14 @@ static int crypto_hex_encode( lua_State* L)
{
int 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;
for (i = 0; i < len; i++) {
out[j++] = crypto_hexbytes[msg[i] >> 4];
out[j++] = crypto_hexbytes[msg[i] & 0xf];
}
lua_pushlstring(L, out, len*2);
c_free(out);
free(out);
return 1;
}
#endif
......@@ -118,12 +118,12 @@ static int crypto_mask( lua_State* L )
const char* msg = luaL_checklstring(L, 1, &len);
const char* mask = luaL_checklstring(L, 2, &mask_len);
int i;
char* copy = (char*)c_malloc(len);
char* copy = (char*)malloc(len);
for (i = 0; i < len; i++) {
copy[i] = msg[i] ^ mask[i % 4];
}
lua_pushlstring(L, copy, len);
c_free(copy);
free(copy);
return 1;
}
......@@ -169,7 +169,7 @@ static int crypto_new_hash (lua_State *L)
if (!mi)
return bad_mech (L);
void *ctx = os_malloc (mi->ctx_size);
void *ctx = malloc (mi->ctx_size);
if (ctx==NULL)
return bad_mem (L);
......@@ -237,7 +237,7 @@ static int crypto_hash_gcdelete (lua_State *L)
dudat = (digest_user_datum_t *)luaL_checkudata(L, 1, "crypto.hash");
luaL_argcheck(L, dudat, 1, "crypto.hash expected");
os_free(dudat->ctx);
free(dudat->ctx);
return 0;
}
......@@ -325,7 +325,7 @@ static int crypto_encdec (lua_State *L, bool enc)
size_t bs = mech->block_size;
size_t outlen = ((dlen + bs -1) / bs) * bs;
char *buf = (char *)os_zalloc (outlen);
char *buf = (char *)zalloc (outlen);
if (!buf)
return luaL_error (L, "crypto init failed");
......@@ -339,14 +339,14 @@ static int crypto_encdec (lua_State *L, bool enc)
};
if (!mech->run (&op))
{
os_free (buf);
free (buf);
return luaL_error (L, "crypto op failed");
}
else
{
lua_pushlstring (L, buf, outlen);
// note: if lua_pushlstring runs out of memory, we leak buf :(
os_free (buf);
free (buf);
return 1;
}
}
......
......@@ -3,7 +3,8 @@
#include "module.h"
#include "lauxlib.h"
#include "lmem.h"
#include "c_string.h"
#include <string.h>
#include <stdint.h>
#define BASE64_INVALID '\xff'
#define BASE64_PADDING '='
#define ISBASE64(c) (unbytes64[c] != BASE64_INVALID)
......@@ -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 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) {
int a = msg[i];
......@@ -44,7 +45,7 @@ static uint8 *fromBase64 ( lua_State* L, const uint8 *enc_msg, size_t *len){
if (n & 3)
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
if (enc_msg[n-1] == BASE64_PADDING) {
......
......@@ -39,14 +39,16 @@
#include "lwip/pbuf.h"
#include "lmem.h"
#include "platform.h"
#include "c_stdlib.h"
#include "c_stdio.h"
#include "c_string.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "ctype.h"
#include "espconn.h"
#include "flash_fs.h"
#include "task/task.h"
#include "esp_wifi.h"
#include "esp_sta.h"
#include "esp_softap.h"
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#define LITLEN(strliteral) (sizeof (strliteral) -1)
......@@ -366,7 +368,7 @@ static void enduser_setup_check_station(void *p)
(void)p;
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);
......@@ -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);
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)
{
return 2;
}
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 += c_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));
offset += sprintf(state->http_payload_data + offset, cl_hdr, LITLEN(http_html_backup));
memcpy(&(state->http_payload_data[offset]), &(http_html_backup), LITLEN(http_html_backup));
return 1;
}
int payload_len = LITLEN(http_header_200) + cl_len + file_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)
{
return 2;
}
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 += 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);
return 0;
......@@ -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));
c_memset(cnf, 0, sizeof(struct station_config));
memset(cnf, 0, sizeof(struct station_config));
int err;
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)
wifi_station_get_config(&config);
config.ssid[31] = '\0';
int state_len = c_strlen(s);
int ssid_len = c_strlen(config.ssid);
int state_len = strlen(s);
int ssid_len = strlen(config.ssid);
int status_len = state_len + ssid_len + 1;
char status_buf[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
char buf[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);
}
......@@ -826,11 +828,11 @@ static void serve_status(struct tcp_pcb *conn)
default:
{
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
char buf[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);
}
......@@ -858,7 +860,7 @@ static void free_scan_listeners (void)
while (l)
{
next = l->next;
c_free (l);
free (l);
l = next;
}
state->scan_listeners = 0;
......@@ -876,7 +878,7 @@ static void remove_scan_listener (scan_listener_t *l)
if (*sl == l)
{
*sl = l->next;
c_free (l);
free (l);
/* No early exit to guard against multi-entry on list */
}
else
......@@ -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 */
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;
char *http = os_zalloc (alloc_sz);
char *http = zalloc (alloc_sz);
if (!http)
{
goto serve_500;
......@@ -976,18 +978,18 @@ static void on_scan_done (void *arg, STATUS status)
strcpy (p, entry_mid);
p += sizeof (entry_mid) -1;
p += c_sprintf (p, "%d", wn->rssi);
p += sprintf (p, "%d", wn->rssi);
*p++ = '}';
}
*p++ = ']';
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 */
notify_scan_listeners (http, hdr_sz + body_sz);
c_free (http);
free (http);
return;
}
......@@ -1020,7 +1022,7 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s
return ERR_OK;
}
char *data = os_zalloc (p->tot_len + 1);
char *data = zalloc (p->tot_len + 1);
if (!data)
return ERR_MEM;
......@@ -1029,9 +1031,9 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s
pbuf_free (p);
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)
{
......@@ -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 */
}
}
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)
{
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
}
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);
}
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))
{
......@@ -1089,7 +1091,7 @@ static err_t enduser_setup_http_recvcb(void *arg, struct tcp_pcb *http_client, s
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. */
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
deferred_close (http_client);
free_out:
os_free (data);
free (data);
return ret;
}
......@@ -1200,20 +1202,20 @@ static void enduser_setup_ap_start(void)
ENDUSER_SETUP_DEBUG("enduser_setup_ap_start");
struct softap_config cnf;
c_memset(&(cnf), 0, sizeof(struct softap_config));
memset(&(cnf), 0, sizeof(struct softap_config));
#ifndef ENDUSER_SETUP_AP_SSID
#define ENDUSER_SETUP_AP_SSID "SetupGadget"
#endif
char ssid[] = ENDUSER_SETUP_AP_SSID;
int ssid_name_len = c_strlen(ssid);
c_memcpy(&(cnf.ssid), ssid, ssid_name_len);
int ssid_name_len = strlen(ssid);
memcpy(&(cnf.ssid), ssid, ssid_name_len);
uint8_t mac[6];
wifi_get_macaddr(SOFTAP_IF, mac);
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.channel = 1;
cnf.authmode = AUTH_OPEN;
......@@ -1232,7 +1234,7 @@ static void enduser_setup_dns_recv_callback(void *arg, char *recv_data, unsigned
struct espconn *callback_espconn = arg;
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_len = dns_reply_static_len + qname_len;
......@@ -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)
{
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;
c_memcpy(&(dns_reply[insert_byte]), recv_data, 2);
memcpy(&(dns_reply[insert_byte]), recv_data, 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);
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;
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);
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
remot_info *pr = 0;
......@@ -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);
}
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;
err = espconn_send(callback_espconn, dns_reply, dns_reply_len);
c_free(dns_reply);
free(dns_reply);
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);
......@@ -1310,16 +1312,16 @@ static void enduser_setup_free(void)
{
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 ();
c_free(state);
free(state);
state = NULL;
}
......@@ -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);
}
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)
{
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)
{
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));
c_memset(esp_udp_data, 0, sizeof(esp_udp));
memset(state->espconn_dns_udp, 0, sizeof(struct espconn));
memset(esp_udp_data, 0, sizeof(esp_udp));
state->espconn_dns_udp->proto.udp = esp_udp_data;
state->espconn_dns_udp->type = ESPCONN_UDP;
state->espconn_dns_udp->state = ESPCONN_NONE;
......@@ -1397,13 +1399,13 @@ static int enduser_setup_init(lua_State *L)
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)
{
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;
}
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_err_cb_ref = LUA_NOREF;
......
......@@ -6,7 +6,7 @@
#include "c_types.h"
#include "flash_fs.h"
#include "c_string.h"
#include <string.h>
static volatile int file_fd = FS_OPEN_OK - 1;
......@@ -20,7 +20,7 @@ static int file_open( lua_State* L )
}
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");
......
......@@ -6,7 +6,7 @@
#include "platform.h"
#include "user_interface.h"
#include "c_types.h"
#include "c_string.h"
#include <string.h>
#include "gpio.h"
#undef INTERRUPT
......
......@@ -14,13 +14,13 @@ static int http_callback_registry = LUA_NOREF;
static void http_callback( char * response, int http_status, char * full_response )
{
#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 (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
if (http_callback_registry != LUA_NOREF)
......
......@@ -4,8 +4,8 @@
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "c_stdlib.h"
#include "c_string.h"
#include <stdlib.h>
#include <string.h>
#include "user_interface.h"
#include "esp_system.h"
......
......@@ -3,8 +3,8 @@
#include "module.h"
#include "lauxlib.h"
#include "c_string.h"
#include "c_stdlib.h"
#include <string.h>
#include <stdlib.h>
#include "c_types.h"
#include "mem.h"
......@@ -43,16 +43,16 @@ static int mdns_register(lua_State *L)
luaL_checktype(L, -2, LUA_TSTRING);
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);
} else if (c_strcmp(key, "service") == 0) {
} else if (strcmp(key, "service") == 0) {
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);
} else {
int len = c_strlen(key) + 1;
int len = strlen(key) + 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);
strcat(p, "=");
strcat(p, value);
......
......@@ -4,8 +4,8 @@
#include "lauxlib.h"
#include "platform.h"
#include "c_string.h"
#include "c_stdlib.h"
#include <string.h>
#include <stdlib.h>
#include "c_types.h"
#include "mem.h"
......@@ -121,9 +121,9 @@ static void mqtt_socket_disconnected(void *arg) // tcp only
if(mud->pesp_conn){
mud->pesp_conn->reverse = NULL;
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;
c_free(mud->pesp_conn);
free(mud->pesp_conn);
mud->pesp_conn = NULL;
}
......@@ -270,7 +270,7 @@ READPACKET:
if(length > MQTT_BUF_SIZE || length <= 0)
return;
// c_memcpy(in_buffer, pdata, length);
// memcpy(in_buffer, pdata, length);
uint8_t temp_buffer[MQTT_BUF_SIZE];
mqtt_msg_init(&mud->mqtt_state.mqtt_connection, temp_buffer, MQTT_BUF_SIZE);
mqtt_message_t *temp_msg = NULL;
......@@ -654,12 +654,12 @@ static int mqtt_socket_client( lua_State* L )
lmqtt_userdata *mud;
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("\n");
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;
int keepalive = 0;
int stack = 1;
......@@ -687,9 +687,9 @@ static int mqtt_socket_client( lua_State* L )
mud->event_timeout = 0;
mud->connState = MQTT_INIT;
mud->connected = false;
c_memset(&mud->mqttTimer, 0, sizeof(ETSTimer));
c_memset(&mud->mqtt_state, 0, sizeof(mqtt_state_t));
c_memset(&mud->connect_info, 0, sizeof(mqtt_connect_info_t));
memset(&mud->mqttTimer, 0, sizeof(ETSTimer));
memset(&mud->mqtt_state, 0, sizeof(mqtt_state_t));
memset(&mud->connect_info, 0, sizeof(mqtt_connect_info_t));
// set its metatable
luaL_getmetatable(L, "mqtt.socket");
......@@ -738,30 +738,30 @@ static int mqtt_socket_client( lua_State* L )
}
// TODO: check the zalloc result.
mud->connect_info.client_id = (uint8_t *)c_zalloc(idl+1);
mud->connect_info.username = (uint8_t *)c_zalloc(unl + 1);
mud->connect_info.password = (uint8_t *)c_zalloc(pwl + 1);
mud->connect_info.client_id = (uint8_t *)zalloc(idl+1);
mud->connect_info.username = (uint8_t *)zalloc(unl + 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) {
c_free(mud->connect_info.client_id);
free(mud->connect_info.client_id);
mud->connect_info.client_id = NULL;
}
if(mud->connect_info.username) {
c_free(mud->connect_info.username);
free(mud->connect_info.username);
mud->connect_info.username = NULL;
}
if(mud->connect_info.password) {
c_free(mud->connect_info.password);
free(mud->connect_info.password);
mud->connect_info.password = NULL;
}
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;
c_memcpy(mud->connect_info.username, username, unl);
memcpy(mud->connect_info.username, username, unl);
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;
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 )
if(mud->pesp_conn){ // for client connected to tcp server, this should set NULL in disconnect cb
mud->pesp_conn->reverse = NULL;
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;
c_free(mud->pesp_conn);
free(mud->pesp_conn);
mud->pesp_conn = NULL; // for socket, it will free this when disconnected
}
// ---- alloc-ed in mqtt_socket_lwt()
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;
}
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;
}
// ----
//--------- alloc-ed in mqtt_socket_client()
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;
}
if(mud->connect_info.username){
c_free(mud->connect_info.username);
free(mud->connect_info.username);
mud->connect_info.username = NULL;
}
if(mud->connect_info.password){
c_free(mud->connect_info.password);
free(mud->connect_info.password);
mud->connect_info.password = NULL;
}
// -------
......@@ -938,7 +938,7 @@ static sint8 socket_dns_found(const char *name, ip_addr_t *ipaddr, void *arg)
if(ipaddr->addr != 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(IPSTR, IP2STR(&(ipaddr->addr)));
NODE_DBG("\n");
......@@ -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()???
mud->pesp_conn->reverse = NULL;
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;
c_free(mud->pesp_conn);
free(mud->pesp_conn);
mud->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)
return luaL_error(L, "not enough memory");
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){
c_free(pesp_conn);
free(pesp_conn);
pesp_conn = mud->pesp_conn = NULL;
return luaL_error(L, "not enough memory");
}
......@@ -1010,7 +1010,7 @@ static int mqtt_socket_connect( lua_State* L )
domain = "127.0.0.1";
}
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(IPSTR, IP2STR(&ipaddr.addr));
NODE_DBG("\n");
......@@ -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);
// 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;
dns_reconn_count = 0;
......@@ -1179,13 +1179,13 @@ static int mqtt_socket_on( lua_State* L )
luaL_checkanyfunction(L, 3);
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);
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);
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);
mud->cb_message_ref = luaL_ref(L, LUA_REGISTRYINDEX);
}else{
......@@ -1528,30 +1528,30 @@ static int mqtt_socket_lwt( lua_State* L )
}
stack++;
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;
}
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_topic = (uint8_t*) c_zalloc( topicSize + 1 );
mud->connect_info.will_message = (uint8_t*) c_zalloc( msgSize + 1 );
mud->connect_info.will_topic = (uint8_t*) zalloc( topicSize + 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){
c_free(mud->connect_info.will_topic);
free(mud->connect_info.will_topic);
mud->connect_info.will_topic = NULL;
}
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;
}
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;
c_memcpy(mud->connect_info.will_message, lwtMsg, msgSize);
memcpy(mud->connect_info.will_message, lwtMsg, msgSize);
mud->connect_info.will_message[msgSize] = 0;
if ( lua_isnumber(L, stack) )
......
......@@ -5,8 +5,8 @@
#include "platform.h"
#include "lmem.h"
#include "c_string.h"
#include "c_stdlib.h"
#include <string.h>
#include <stdlib.h>
#include "c_types.h"
#include "mem.h"
......@@ -70,7 +70,7 @@ static void net_server_disconnected(void *arg) // for tcp server only
return;
#if 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(temp);
NODE_DBG(":");
......@@ -117,10 +117,10 @@ static void net_socket_disconnected(void *arg) // tcp only
}
if(pesp_conn->proto.tcp)
c_free(pesp_conn->proto.tcp);
free(pesp_conn->proto.tcp);
pesp_conn->proto.tcp = NULL;
if(nud->pesp_conn)
c_free(nud->pesp_conn);
free(nud->pesp_conn);
nud->pesp_conn = NULL; // espconn is already disconnected
lua_gc(gL, LUA_GCSTOP, 0);
if(nud->self_ref != LUA_NOREF){
......@@ -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
char ip_str[20];
c_memset(ip_str, 0, sizeof(ip_str));
memset(ip_str, 0, sizeof(ip_str));
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
......@@ -237,10 +237,10 @@ static void net_dns_found(const char *name, ip_addr_t *ipaddr, void *arg)
}else{
// ipaddr->addr is a uint32_t ip
char ip_str[20];
c_memset(ip_str, 0, sizeof(ip_str));
memset(ip_str, 0, sizeof(ip_str));
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
}
......@@ -271,7 +271,7 @@ static void net_server_connected(void *arg) // for tcp only
#if 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(temp);
NODE_DBG(":");
......@@ -377,9 +377,9 @@ static int net_create( lua_State* L, const char* mt )
uint8_t stack = 1;
bool isserver = false;
if (mt!=NULL && c_strcmp(mt, "net.server")==0)
if (mt!=NULL && strcmp(mt, "net.server")==0)
isserver = true;
else if (mt!=NULL && c_strcmp(mt, "net.socket")==0)
else if (mt!=NULL && strcmp(mt, "net.socket")==0)
isserver = false;
else
{
......@@ -454,7 +454,7 @@ static int net_create( lua_State* L, const char* mt )
}
pesp_conn = nud->pesp_conn = pUdpServer;
} 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)
return luaL_error(L, "not enough memory");
......@@ -463,9 +463,9 @@ static int net_create( lua_State* L, const char* mt )
pesp_conn->reverse = NULL;
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){
c_free(pesp_conn);
free(pesp_conn);
pesp_conn = nud->pesp_conn = NULL;
return luaL_error(L, "not enough memory");
}
......@@ -473,9 +473,9 @@ static int net_create( lua_State* L, const char* mt )
}
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){
c_free(pesp_conn);
free(pesp_conn);
pesp_conn = nud->pesp_conn = NULL;
return luaL_error(L, "not enough memory");
}
......@@ -515,9 +515,9 @@ static int net_delete( lua_State* L, const char* mt )
{
NODE_DBG("net_delete is called.\n");
bool isserver = false;
if (mt!=NULL && c_strcmp(mt, "net.server")==0)
if (mt!=NULL && strcmp(mt, "net.server")==0)
isserver = true;
else if (mt!=NULL && c_strcmp(mt, "net.socket")==0)
else if (mt!=NULL && strcmp(mt, "net.socket")==0)
isserver = false;
else
{
......@@ -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->proto.udp)
c_free(nud->pesp_conn->proto.udp);
free(nud->pesp_conn->proto.udp);
nud->pesp_conn->proto.udp = NULL;
} else if (nud->pesp_conn->type == ESPCONN_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;
}
c_free(nud->pesp_conn);
free(nud->pesp_conn);
}
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)
dns_reconn_count = 0;
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(IPSTR, IP2STR(&(ipaddr->addr)));
NODE_DBG("\n");
}
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(IPSTR, IP2STR(&(ipaddr->addr)));
NODE_DBG("\n");
......@@ -683,9 +683,9 @@ static int net_start( lua_State* L, const char* mt )
const char *domain;
uint8_t stack = 1;
if (mt!=NULL && c_strcmp(mt, "net.server")==0)
if (mt!=NULL && strcmp(mt, "net.server")==0)
isserver = true;
else if (mt!=NULL && c_strcmp(mt, "net.socket")==0)
else if (mt!=NULL && strcmp(mt, "net.socket")==0)
isserver = false;
else
{
......@@ -744,9 +744,9 @@ static int net_start( lua_State* L, const char* mt )
if( pesp_conn->type == ESPCONN_TCP )
{
if(isserver)
c_memcpy(pesp_conn->proto.tcp->local_ip, &ipaddr.addr, 4);
memcpy(pesp_conn->proto.tcp->local_ip, &ipaddr.addr, 4);
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(IPSTR, IP2STR(&ipaddr.addr));
NODE_DBG("\n");
......@@ -754,9 +754,9 @@ static int net_start( lua_State* L, const char* mt )
else if (pesp_conn->type == ESPCONN_UDP)
{
if(isserver)
c_memcpy(pesp_conn->proto.udp->local_ip, &ipaddr.addr, 4);
memcpy(pesp_conn->proto.udp->local_ip, &ipaddr.addr, 4);
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(IPSTR, IP2STR(&ipaddr.addr));
NODE_DBG("\n");
......@@ -831,7 +831,7 @@ static int net_start( lua_State* L, const char* mt )
}
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;
dns_reconn_count = 0;
......@@ -865,9 +865,9 @@ static int net_close( lua_State* L, const char* mt )
if(nud->pesp_conn == NULL)
return 0;
if (mt!=NULL && c_strcmp(mt, "net.server")==0)
if (mt!=NULL && strcmp(mt, "net.server")==0)
isserver = true;
else if (mt!=NULL && c_strcmp(mt, "net.socket")==0)
else if (mt!=NULL && strcmp(mt, "net.socket")==0)
isserver = false;
else
{
......@@ -973,9 +973,9 @@ static int net_on( lua_State* L, const char* mt )
return 0;
}
if (mt!=NULL && c_strcmp(mt, "net.server")==0)
if (mt!=NULL && strcmp(mt, "net.server")==0)
isserver = true;
else if (mt!=NULL && c_strcmp(mt, "net.socket")==0)
else if (mt!=NULL && strcmp(mt, "net.socket")==0)
isserver = false;
else
{
......@@ -990,27 +990,27 @@ static int net_on( lua_State* L, const char* mt )
luaL_checkanyfunction(L, 3);
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)
luaL_unref(L, LUA_REGISTRYINDEX, nud->cb_connect_ref);
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)
luaL_unref(L, LUA_REGISTRYINDEX, nud->cb_reconnect_ref);
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)
luaL_unref(L, LUA_REGISTRYINDEX, nud->cb_disconnect_ref);
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)
luaL_unref(L, LUA_REGISTRYINDEX, nud->cb_receive_ref);
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)
luaL_unref(L, LUA_REGISTRYINDEX, nud->cb_send_ref);
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)
luaL_unref(L, LUA_REGISTRYINDEX, nud->cb_dns_found_ref);
nud->cb_dns_found_ref = luaL_ref(L, LUA_REGISTRYINDEX);
......@@ -1044,9 +1044,9 @@ static int net_send( lua_State* L, const char* mt )
}
pesp_conn = nud->pesp_conn;
if (mt!=NULL && c_strcmp(mt, "net.server")==0)
if (mt!=NULL && strcmp(mt, "net.server")==0)
isserver = true;
else if (mt!=NULL && c_strcmp(mt, "net.socket")==0)
else if (mt!=NULL && strcmp(mt, "net.socket")==0)
isserver = false;
else
{
......@@ -1060,7 +1060,7 @@ static int net_send( lua_State* L, const char* mt )
#if 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(temp);
NODE_DBG(":");
......@@ -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)
return luaL_error (L, "remote ip/port unavailable");
pesp_conn->proto.udp->remote_port = pr->remote_port;
os_memmove (pesp_conn->proto.udp->remote_ip, pr->remote_ip, 4);
// The remot_info apparently should *not* be os_free()d, fyi
memmove (pesp_conn->proto.udp->remote_ip, pr->remote_ip, 4);
// The remot_info apparently should *not* be free()d, fyi
}
#ifdef CLIENT_SSL_ENABLE
if(nud->secure)
......@@ -1114,9 +1114,9 @@ static int net_dns( lua_State* L, const char* mt )
return 0;
}
if (mt!=NULL && c_strcmp(mt, "net.server")==0)
if (mt!=NULL && strcmp(mt, "net.server")==0)
isserver = true;
else if (mt!=NULL && c_strcmp(mt, "net.socket")==0)
else if (mt!=NULL && strcmp(mt, "net.socket")==0)
isserver = false;
else
{
......@@ -1365,7 +1365,7 @@ static int net_socket_getpeer( lua_State* L )
if(nud!=NULL && nud->pesp_conn!=NULL ){
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 ) {
lua_pushstring( L, temp );
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
memset(buffer, 0xff, buffer_limit - buffer);
// 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
if (platform_flash_erase_sector(flash_offset / INTERNAL_FLASH_SECTOR_SIZE) != PLATFORM_OK) {
luaM_free(L, buffer_base);
......@@ -1672,7 +1672,7 @@ static int net_getdnsserver( lua_State* L )
lua_pushnil( L );
} else {
char temp[20] = {0};
c_sprintf(temp, IPSTR, IP2STR( &ipaddr.addr ) );
sprintf(temp, IPSTR, IP2STR( &ipaddr.addr ) );
lua_pushstring( L, temp );
}
......
......@@ -19,7 +19,7 @@
#include "lrodefs.h"
#include "c_types.h"
#include "c_string.h"
#include <string.h>
#include "driver/uart.h"
#include "user_interface.h"
#include "flash_api.h"
......@@ -276,9 +276,9 @@ static int node_key( lua_State* L )
if (str == NULL)
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;
} else if (sl == 4 && c_strcmp(str, "long") == 0) {
} else if (sl == 4 && strcmp(str, "long") == 0) {
ref = &long_key_ref;
} else {
ref = &short_key_ref;
......@@ -311,9 +311,9 @@ static int node_input( lua_State* L )
{
lua_Load *load = &gLoad;
if (load->line_position == 0) {
c_memcpy(load->line, s, l);
memcpy(load->line, s, l);
load->line[l + 1] = '\0';
load->line_position = c_strlen(load->line) + 1;
load->line_position = strlen(load->line) + 1;
load->done = 1;
NODE_DBG("Get command:\n");
NODE_DBG(load->line); // buggy here
......@@ -328,7 +328,7 @@ static int output_redir_ref = LUA_NOREF;
static int serial_debug = 1;
void output_redirect(const char *str) {
lua_State *L = lua_getstate();
// if(c_strlen(str)>=TX_BUFF_SIZE){
// if(strlen(str)>=TX_BUFF_SIZE){
// NODE_ERR("output too long.\n");
// return;
// }
......@@ -402,13 +402,13 @@ static int node_compile( lua_State* L )
return luaL_error(L, "filename too long");
char output[FS_NAME_MAX_LENGTH];
c_strcpy(output, fname);
strcpy(output, fname);
// 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");
output[c_strlen(output) - 2] = 'c';
output[c_strlen(output) - 1] = '\0';
output[strlen(output) - 2] = 'c';
output[strlen(output) - 1] = '\0';
NODE_DBG(output);
NODE_DBG("\n");
if (luaL_loadfsfile(L, fname) != 0) {
......
......@@ -9,7 +9,7 @@
#include "ets_sys.h"
#include "os_type.h"
#include "osapi.h"
#include "c_stdlib.h"
#include <stdlib.h>
#include "module.h"
#include "lauxlib.h"
......
......@@ -12,7 +12,7 @@
#include "c_types.h"
#include "user_interface.h"
#include "driver/rotary.h"
#include "../libc/c_stdlib.h"
#include <stdlib.h>
#define MASK(x) (1 << ROTARY_ ## x ## _INDEX)
......@@ -143,7 +143,7 @@ static int lrotary_setup( lua_State* L )
callback_free(L, id, ROTARY_ALL);
if (!data[id]) {
data[id] = (DATA *) os_zalloc(sizeof(DATA));
data[id] = (DATA *) zalloc(sizeof(DATA));
if (!data[id]) {
return -1;
}
......@@ -202,7 +202,7 @@ static int lrotary_close( lua_State* L )
DATA *d = data[id];
if (d) {
data[id] = NULL;
os_free(d);
free(d);
}
if (rotary_close( id )) {
......
......@@ -6,6 +6,7 @@
#include "rtc/rtctime.h"
#define RTCTIME_SLEEP_ALIGNED rtctime_deep_sleep_until_aligned_us
#include "rtc/rtcfifo.h"
#include <string.h>
// rtcfifo.prepare ([{sensor_count=n, interval_us=m, storage_begin=x, storage_end=y}])
static int rtcfifo_prepare (lua_State *L)
......
......@@ -38,7 +38,7 @@
#include "os_type.h"
#include "osapi.h"
#include "lwip/udp.h"
#include "c_stdlib.h"
#include <stdlib.h>
#include "user_modules.h"
#include "lwip/dns.h"
#include "user_interface.h"
......@@ -53,7 +53,7 @@
#define MAX_ATTEMPTS 5
#if 0
# define sntp_dbg(...) c_printf(__VA_ARGS__)
# define sntp_dbg(...) printf(__VA_ARGS__)
#else
# define sntp_dbg(...)
#endif
......@@ -110,7 +110,7 @@ static void cleanup (lua_State *L)
udp_remove (state->pcb);
luaL_unref (L, LUA_REGISTRYINDEX, state->sync_cb_ref);
luaL_unref (L, LUA_REGISTRYINDEX, state->err_cb_ref);
os_free (state);
free (state);
state = 0;
}
......@@ -328,7 +328,7 @@ static int sntp_sync (lua_State *L)
if (state)
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)
sync_err ("out of memory");
......@@ -386,7 +386,7 @@ error:
{
if (state->pcb)
udp_remove (state->pcb);
c_free (state);
free (state);
state = 0;
}
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