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
......@@ -9,7 +9,7 @@ SDK_DIR:=$(TOP_DIR)/rtos-sdk
# This is, sadly, the cleanest way to resolve the different non-standard
# conventions for sized integers across the various components.
BASIC_TYPES=-Du32_t=uint32_t -Du16_t=uint16_t -Du8_t=uint8_t -Duint32=uint32_t -Duint16=uint16_t -Duint8=uint8_t -Dsint32=int32_t -Dsint16=int16_t -Dsint8=int8_t
BASIC_TYPES=-Du32_t=uint32_t -Du16_t=uint16_t -Du8_t=uint8_t -Ds32_t=int32_t -Ds16_t=int16_t -Duint32=uint32_t -Duint16=uint16_t -Duint8=uint8_t -Dsint32=int32_t -Dsint16=int16_t -Dsint8=int8_t
# Include dirs, ensure the overrides come first
INCLUDE_DIRS=$(TOP_DIR)/sdk-overrides/include $(SDK_DIR)/include $(SDK_DIR)/include/espressif $(SDK_DIR)/include/lwip $(SDK_DIR)/include/lwip/ipv4 $(SDK_DIR)/include/lwip/ipv6 $(SDK_DIR)/extra_include
......
......@@ -26,7 +26,6 @@ SUBDIRS= \
driver \
json \
platform \
libc \
lua \
coap \
mqtt \
......@@ -72,7 +71,6 @@ COMPONENTS_eagle.app.v6 = \
json/libjson.a \
platform/libplatform.a \
task/libtask.a \
libc/liblibc.a \
lua/liblua.a \
coap/coap.a \
mqtt/mqtt.a \
......
#include "cjson_mem.h"
#include "../lua/lauxlib.h"
#include <c_stdlib.h>
#include <stdlib.h>
static lua_State *gL;
static const char errfmt[] = "cjson %salloc: out of mem (%d bytes)";
......@@ -12,7 +12,7 @@ void cjson_mem_setlua (lua_State *L)
void *cjson_mem_malloc (uint32_t sz)
{
void *p = (void*)c_malloc (sz);
void *p = (void*)malloc (sz);
if (!p && gL)
luaL_error (gL, errfmt, "m", sz);
return p;
......@@ -21,7 +21,7 @@ void *cjson_mem_malloc (uint32_t sz)
void *cjson_mem_realloc (void *o, uint32_t sz)
{
void *p = (void*)c_realloc (o, sz);
void *p = (void*)realloc (o, sz);
if (!p && gL)
luaL_error (gL, errfmt, "re", sz);
return p;
......
#ifndef _CJSON_MEM_H_
#define _CJSON_MEM_H_
#include <stdint.h>
#include "../lua/lua.h"
void cjson_mem_setlua (lua_State *L);
......
......@@ -28,10 +28,10 @@
* fpconv_* will around these issues with a translation buffer if required.
*/
#include "c_stdio.h"
#include "c_stdlib.h"
#include <stdio.h>
#include <stdlib.h>
// #include <assert.h>
#include "c_string.h"
#include <string.h>
#include "fpconv.h"
......@@ -54,7 +54,7 @@ static void fpconv_update_locale()
{
char buf[8];
c_sprintf(buf, "%g", 0.5);
sprintf(buf, "%g", 0.5);
/* Failing this test might imply the platform has a buggy dtoa
* implementation or wide characters */
......@@ -125,7 +125,7 @@ double fpconv_strtod(const char *nptr, char **endptr)
/* Duplicate number into buffer */
if (buflen >= FPCONV_G_FMT_BUFSIZE) {
/* Handle unusually large numbers */
buf = c_malloc(buflen + 1);
buf = malloc(buflen + 1);
if (!buf) {
NODE_ERR("not enough memory\n");
return;
......@@ -134,18 +134,18 @@ double fpconv_strtod(const char *nptr, char **endptr)
/* This is the common case.. */
buf = localbuf;
}
c_memcpy(buf, nptr, buflen);
memcpy(buf, nptr, buflen);
buf[buflen] = 0;
/* Update decimal point character if found */
dp = c_strchr(buf, '.');
dp = strchr(buf, '.');
if (dp)
*dp = locale_decimal_point;
value = c_strtod(buf, &endbuf);
*endptr = (char *)&nptr[endbuf - buf];
if (buflen >= FPCONV_G_FMT_BUFSIZE)
c_free(buf);
free(buf);
return value;
}
......@@ -183,13 +183,13 @@ int fpconv_g_fmt(char *str, double num, int precision)
/* Pass through when decimal point character is dot. */
if (locale_decimal_point == '.'){
c_sprintf(str, fmt, num);
return c_strlen(str);
sprintf(str, fmt, num);
return strlen(str);
}
/* snprintf() to a buffer then translate for other decimal point characters */
c_sprintf(buf, fmt, num);
len = c_strlen(buf);
sprintf(buf, fmt, num);
len = strlen(buf);
/* Copy into target location. Translate decimal point if required */
b = buf;
......
......@@ -22,10 +22,10 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "c_stdio.h"
#include "c_stdlib.h"
#include "c_stdarg.h"
#include "c_string.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "strbuf.h"
#include "cjson_mem.h"
......@@ -103,11 +103,11 @@ void strbuf_free(strbuf_t *s)
debug_stats(s);
if (s->buf) {
c_free(s->buf);
free(s->buf);
s->buf = NULL;
}
if (s->dynamic)
c_free(s);
free(s);
}
char *strbuf_free_to_string(strbuf_t *s, int *len)
......@@ -123,7 +123,7 @@ char *strbuf_free_to_string(strbuf_t *s, int *len)
*len = s->length;
if (s->dynamic)
c_free(s);
free(s);
return buf;
}
......
......@@ -22,8 +22,8 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "c_stdlib.h"
#include "c_stdarg.h"
#include <stdlib.h>
#include <stdarg.h>
#include "user_config.h"
/* Size: Total bytes allocated to *buf
......@@ -128,13 +128,13 @@ static inline void strbuf_append_char_unsafe(strbuf_t *s, const char c)
static inline void strbuf_append_mem(strbuf_t *s, const char *c, int len)
{
strbuf_ensure_empty_length(s, len);
c_memcpy(s->buf + s->length, c, len);
memcpy(s->buf + s->length, c, len);
s->length += len;
}
static inline void strbuf_append_mem_unsafe(strbuf_t *s, const char *c, int len)
{
c_memcpy(s->buf + s->length, c, len);
memcpy(s->buf + s->length, c, len);
s->length += len;
}
......
#include "user_config.h"
#include "c_stdio.h"
#include "c_string.h"
#include <stdio.h>
#include <string.h>
#include "coap.h"
#include "uri.h"
......@@ -10,12 +10,12 @@ extern const coap_endpoint_t endpoints[];
#ifdef COAP_DEBUG
void coap_dumpHeader(coap_header_t *hdr)
{
c_printf("Header:\n");
c_printf(" ver 0x%02X\n", hdr->ver);
c_printf(" t 0x%02X\n", hdr->ver);
c_printf(" tkl 0x%02X\n", hdr->tkl);
c_printf(" code 0x%02X\n", hdr->code);
c_printf(" id 0x%02X%02X\n", hdr->id[0], hdr->id[1]);
printf("Header:\n");
printf(" ver 0x%02X\n", hdr->ver);
printf(" t 0x%02X\n", hdr->ver);
printf(" tkl 0x%02X\n", hdr->tkl);
printf(" code 0x%02X\n", hdr->code);
printf(" id 0x%02X%02X\n", hdr->id[0], hdr->id[1]);
}
void coap_dump(const uint8_t *buf, size_t buflen, bool bare)
......@@ -23,14 +23,14 @@ void coap_dump(const uint8_t *buf, size_t buflen, bool bare)
if (bare)
{
while(buflen--)
c_printf("%02X%s", *buf++, (buflen > 0) ? " " : "");
printf("%02X%s", *buf++, (buflen > 0) ? " " : "");
}
else
{
c_printf("Dump: ");
printf("Dump: ");
while(buflen--)
c_printf("%02X%s", *buf++, (buflen > 0) ? " " : "");
c_printf("\n");
printf("%02X%s", *buf++, (buflen > 0) ? " " : "");
printf("\n");
}
}
#endif
......@@ -100,7 +100,7 @@ int coap_buildToken(const coap_buffer_t *tokbuf, const coap_header_t *hdr, uint8
return COAP_ERR_UNSUPPORTED;
if (hdr->tkl > 0)
c_memcpy(p, tokbuf->p, hdr->tkl);
memcpy(p, tokbuf->p, hdr->tkl);
// http://tools.ietf.org/html/rfc7252#section-3.1
// inject options
......@@ -260,12 +260,12 @@ int coap_buildOptionHeader(uint32_t optDelta, size_t length, uint8_t *buf, size_
void coap_dumpOptions(coap_option_t *opts, size_t numopt)
{
size_t i;
c_printf(" Options:\n");
printf(" Options:\n");
for (i=0;i<numopt;i++)
{
c_printf(" 0x%02X [ ", opts[i].num);
printf(" 0x%02X [ ", opts[i].num);
coap_dump(opts[i].buf.p, opts[i].buf.len, true);
c_printf(" ]\n");
printf(" ]\n");
}
}
......@@ -273,9 +273,9 @@ void coap_dumpPacket(coap_packet_t *pkt)
{
coap_dumpHeader(&pkt->hdr);
coap_dumpOptions(pkt->opts, pkt->numopts);
c_printf("Payload: ");
printf("Payload: ");
coap_dump(pkt->payload.p, pkt->payload.len, true);
c_printf("\n");
printf("\n");
}
#endif
......@@ -325,7 +325,7 @@ int coap_buffer_to_string(char *strbuf, size_t strbuflen, const coap_buffer_t *b
{
if (buf->len+1 > strbuflen)
return COAP_ERR_BUFFER_TOO_SMALL;
c_memcpy(strbuf, buf->p, buf->len);
memcpy(strbuf, buf->p, buf->len);
strbuf[buf->len] = 0;
return 0;
}
......@@ -360,7 +360,7 @@ int coap_build(uint8_t *buf, size_t *buflen, const coap_packet_t *pkt)
p += rc;
left -= rc;
c_memcpy(p, pkt->opts[i].buf.p, pkt->opts[i].buf.len);
memcpy(p, pkt->opts[i].buf.p, pkt->opts[i].buf.len);
p += pkt->opts[i].buf.len;
left -= pkt->opts[i].buf.len;
running_delta = pkt->opts[i].num;
......@@ -373,7 +373,7 @@ int coap_build(uint8_t *buf, size_t *buflen, const coap_packet_t *pkt)
if (*buflen < 4 + 1 + pkt->payload.len + opts_len)
return COAP_ERR_BUFFER_TOO_SMALL;
buf[4 + opts_len] = 0xFF; // payload marker
c_memcpy(buf+5 + opts_len, pkt->payload.p, pkt->payload.len);
memcpy(buf+5 + opts_len, pkt->payload.p, pkt->payload.len);
*buflen = opts_len + 5 + pkt->payload.len;
}
else
......@@ -471,7 +471,7 @@ int coap_make_request(coap_rw_buffer_t *scratch, coap_packet_t *pkt, coap_msgtyp
/* split arg into Uri-* options */
// const char *addr = uri->host.s;
// if(uri->host.length && (c_strlen(addr) != uri->host.length || c_memcmp(addr, uri->host.s, uri->host.length) != 0)){
// if(uri->host.length && (strlen(addr) != uri->host.length || memcmp(addr, uri->host.s, uri->host.length) != 0)){
if(uri->host.length){
/* add Uri-Host */
// addr is destination address
......@@ -525,9 +525,9 @@ int coap_handle_req(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_
goto next;
for (i=0;i<ep->path->count;i++)
{
if (opt[i].buf.len != c_strlen(ep->path->elems[i]))
if (opt[i].buf.len != strlen(ep->path->elems[i]))
goto next;
if (0 != c_memcmp(ep->path->elems[i], opt[i].buf.p, opt[i].buf.len))
if (0 != memcmp(ep->path->elems[i], opt[i].buf.p, opt[i].buf.len))
goto next;
}
// pre-path match!
......@@ -551,5 +551,5 @@ void coap_setup(void)
inline int
check_token(coap_packet_t *pkt) {
return pkt->tok.len == the_token.len && c_memcmp(pkt->tok.p, the_token.p, the_token.len) == 0;
return pkt->tok.len == the_token.len && memcmp(pkt->tok.p, the_token.p, the_token.len) == 0;
}
......@@ -5,8 +5,8 @@
extern "C" {
#endif
#include "c_stdint.h"
#include "c_stddef.h"
#include <stdint.h>
#include <stddef.h>
#include "lualib.h"
#include "lauxlib.h"
......
#include "c_string.h"
#include <string.h>
#include "coap_io.h"
#include "node.h"
#include "espconn.h"
......@@ -16,10 +16,10 @@ coap_tid_t coap_send(struct espconn *pesp_conn, coap_pdu_t *pdu) {
espconn_sent(pesp_conn, (unsigned char *)(pdu->msg.p), pdu->msg.len);
if(pesp_conn->type == ESPCONN_TCP){
c_memcpy(&ip, pesp_conn->proto.tcp->remote_ip, sizeof(ip));
memcpy(&ip, pesp_conn->proto.tcp->remote_ip, sizeof(ip));
port = pesp_conn->proto.tcp->remote_port;
}else{
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, pdu->pkt, &id);
......
#include "user_config.h"
#include "c_types.h"
#include "c_stdlib.h"
#include <ctype.h>
#include <stdlib.h>
#include "coap.h"
......@@ -51,7 +51,7 @@ size_t coap_server_respond(char *req, unsigned short reqlen, char *rsp, unsigned
#endif
}
if(rsppkt.content.p){
c_free(rsppkt.content.p);
free(rsppkt.content.p);
rsppkt.content.p = NULL;
rsppkt.content.len = 0;
}
......
#include "node.h"
#include "coap_timer.h"
#include "os_type.h"
#include "esp_timer.h"
static os_timer_t coap_timer;
static coap_tick_t basetime = 0;
......
#include "c_stdio.h"
#include "c_string.h"
#include "c_stdlib.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "coap.h"
#include "lua.h"
......@@ -21,14 +21,14 @@ void endpoint_setup(void)
static const coap_endpoint_path_t path_well_known_core = {2, {".well-known", "core"}};
static int handle_get_well_known_core(const coap_endpoint_t *ep, coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt, uint8_t id_hi, uint8_t id_lo)
{
outpkt->content.p = (uint8_t *)c_zalloc(MAX_PAYLOAD_SIZE); // this should be free-ed when outpkt is built in coap_server_respond()
outpkt->content.p = (uint8_t *)zalloc(MAX_PAYLOAD_SIZE); // this should be free-ed when outpkt is built in coap_server_respond()
if(outpkt->content.p == NULL){
NODE_DBG("not enough memory\n");
return COAP_ERR_BUFFER_TOO_SMALL;
}
outpkt->content.len = MAX_PAYLOAD_SIZE;
build_well_known_rsp(outpkt->content.p, outpkt->content.len);
return coap_make_response(scratch, outpkt, (const uint8_t *)outpkt->content.p, c_strlen(outpkt->content.p), id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_APPLICATION_LINKFORMAT);
return coap_make_response(scratch, outpkt, (const uint8_t *)outpkt->content.p, strlen(outpkt->content.p), id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_APPLICATION_LINKFORMAT);
}
static const coap_endpoint_path_t path_variable = {2, {"v1", "v"}};
......@@ -48,19 +48,19 @@ static int handle_get_variable(const coap_endpoint_t *ep, coap_rw_buffer_t *scra
{
coap_luser_entry *h = ep->user_entry->next; // ->next: skip the first entry(head)
while(NULL != h){
if (opt[count-1].buf.len != c_strlen(h->name))
if (opt[count-1].buf.len != strlen(h->name))
{
h = h->next;
continue;
}
if (0 == c_memcmp(h->name, opt[count-1].buf.p, opt[count-1].buf.len))
if (0 == memcmp(h->name, opt[count-1].buf.p, opt[count-1].buf.len))
{
NODE_DBG("/v1/v/");
NODE_DBG((char *)h->name);
NODE_DBG(" match.\n");
if(h->L == NULL)
return coap_make_response(scratch, outpkt, NULL, 0, id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_NOT_FOUND, COAP_CONTENTTYPE_NONE);
if(c_strlen(h->name))
if(strlen(h->name))
{
n = lua_gettop(h->L);
lua_getglobal(h->L, h->name);
......@@ -71,7 +71,7 @@ static int handle_get_variable(const coap_endpoint_t *ep, coap_rw_buffer_t *scra
} else {
const char *res = lua_tostring(h->L,-1);
lua_settop(h->L, n);
return coap_make_response(scratch, outpkt, (const uint8_t *)res, c_strlen(res), id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, h->content_type);
return coap_make_response(scratch, outpkt, (const uint8_t *)res, strlen(res), id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, h->content_type);
}
}
} else {
......@@ -105,12 +105,12 @@ static int handle_post_function(const coap_endpoint_t *ep, coap_rw_buffer_t *scr
{
coap_luser_entry *h = ep->user_entry->next; // ->next: skip the first entry(head)
while(NULL != h){
if (opt[count-1].buf.len != c_strlen(h->name))
if (opt[count-1].buf.len != strlen(h->name))
{
h = h->next;
continue;
}
if (0 == c_memcmp(h->name, opt[count-1].buf.p, opt[count-1].buf.len))
if (0 == memcmp(h->name, opt[count-1].buf.p, opt[count-1].buf.len))
{
NODE_DBG("/v1/f/");
NODE_DBG((char *)h->name);
......@@ -119,7 +119,7 @@ static int handle_post_function(const coap_endpoint_t *ep, coap_rw_buffer_t *scr
if(h->L == NULL)
return coap_make_response(scratch, outpkt, NULL, 0, id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_NOT_FOUND, COAP_CONTENTTYPE_NONE);
if(c_strlen(h->name))
if(strlen(h->name))
{
n = lua_gettop(h->L);
lua_getglobal(h->L, h->name);
......@@ -176,7 +176,7 @@ static int handle_post_command(const coap_endpoint_t *ep, coap_rw_buffer_t *scra
lua_Load *load = &gLoad;
if(load->line_position == 0){
coap_buffer_to_string(load->line, load->len,&inpkt->payload);
load->line_position = c_strlen(load->line)+1;
load->line_position = strlen(load->line)+1;
// load->line[load->line_position-1] = '\n';
// load->line[load->line_position] = 0;
// load->line_position++;
......@@ -222,7 +222,7 @@ void build_well_known_rsp(char *rsp, uint16_t rsplen)
int i;
uint16_t len = rsplen;
c_memset(rsp, 0, len);
memset(rsp, 0, len);
len--; // Null-terminated string
......@@ -233,57 +233,57 @@ void build_well_known_rsp(char *rsp, uint16_t rsplen)
continue;
}
if (NULL == ep->user_entry){
if (0 < c_strlen(rsp)) {
c_strncat(rsp, ",", len);
if (0 < strlen(rsp)) {
strncat(rsp, ",", len);
len--;
}
c_strncat(rsp, "<", len);
strncat(rsp, "<", len);
len--;
for (i = 0; i < ep->path->count; i++) {
c_strncat(rsp, "/", len);
strncat(rsp, "/", len);
len--;
c_strncat(rsp, ep->path->elems[i], len);
len -= c_strlen(ep->path->elems[i]);
strncat(rsp, ep->path->elems[i], len);
len -= strlen(ep->path->elems[i]);
}
c_strncat(rsp, ">;", len);
strncat(rsp, ">;", len);
len -= 2;
c_strncat(rsp, ep->core_attr, len);
len -= c_strlen(ep->core_attr);
strncat(rsp, ep->core_attr, len);
len -= strlen(ep->core_attr);
} else {
coap_luser_entry *h = ep->user_entry->next; // ->next: skip the first entry(head)
while(NULL != h){
if (0 < c_strlen(rsp)) {
c_strncat(rsp, ",", len);
if (0 < strlen(rsp)) {
strncat(rsp, ",", len);
len--;
}
c_strncat(rsp, "<", len);
strncat(rsp, "<", len);
len--;
for (i = 0; i < ep->path->count; i++) {
c_strncat(rsp, "/", len);
strncat(rsp, "/", len);
len--;
c_strncat(rsp, ep->path->elems[i], len);
len -= c_strlen(ep->path->elems[i]);
strncat(rsp, ep->path->elems[i], len);
len -= strlen(ep->path->elems[i]);
}
c_strncat(rsp, "/", len);
strncat(rsp, "/", len);
len--;
c_strncat(rsp, h->name, len);
len -= c_strlen(h->name);
strncat(rsp, h->name, len);
len -= strlen(h->name);
c_strncat(rsp, ">;", len);
strncat(rsp, ">;", len);
len -= 2;
c_strncat(rsp, ep->core_attr, len);
len -= c_strlen(ep->core_attr);
strncat(rsp, ep->core_attr, len);
len -= strlen(ep->core_attr);
h = h->next;
}
......
#include "hash.h"
#include "c_string.h"
#include <string.h>
/* Caution: When changing this, update COAP_DEFAULT_WKC_HASHKEY
* accordingly (see int coap_hash_path());
*/
......@@ -20,7 +20,7 @@ void coap_hash(const unsigned char *s, unsigned int len, coap_key_t h) {
void coap_transaction_id(const uint32_t ip, const uint32_t port, const coap_packet_t *pkt, coap_tid_t *id) {
coap_key_t h;
c_memset(h, 0, sizeof(coap_key_t));
memset(h, 0, sizeof(coap_key_t));
/* Compare the transport address. */
coap_hash((const unsigned char *)&(port), sizeof(port), h);
......
#include "c_string.h"
#include "c_stdlib.h"
#include <string.h>
#include <stdlib.h>
#include "node.h"
static inline coap_queue_t *
coap_malloc_node(void) {
return (coap_queue_t *)c_zalloc(sizeof(coap_queue_t));
return (coap_queue_t *)zalloc(sizeof(coap_queue_t));
}
void coap_free_node(coap_queue_t *node) {
c_free(node);
free(node);
}
int coap_insert_node(coap_queue_t **queue, coap_queue_t *node) {
......@@ -73,7 +73,7 @@ coap_queue_t * coap_new_node(void) {
return NULL;
}
c_memset(node, 0, sizeof(*node));
memset(node, 0, sizeof(*node));
return node;
}
......
#include "c_stdlib.h"
#include <stdlib.h>
#include "pdu.h"
coap_pdu_t * coap_new_pdu(void) {
coap_pdu_t *pdu = NULL;
pdu = (coap_pdu_t *)c_zalloc(sizeof(coap_pdu_t));
pdu = (coap_pdu_t *)zalloc(sizeof(coap_pdu_t));
if(!pdu){
NODE_DBG("coap_new_pdu malloc error.\n");
return NULL;
}
pdu->scratch.p = (uint8_t *)c_zalloc(MAX_REQ_SCRATCH_SIZE);
pdu->scratch.p = (uint8_t *)zalloc(MAX_REQ_SCRATCH_SIZE);
if(!pdu->scratch.p){
NODE_DBG("coap_new_pdu malloc error.\n");
c_free(pdu);
free(pdu);
return NULL;
}
pdu->scratch.len = MAX_REQ_SCRATCH_SIZE;
pdu->pkt = (coap_packet_t *)c_zalloc(sizeof(coap_packet_t));
pdu->pkt = (coap_packet_t *)zalloc(sizeof(coap_packet_t));
if(!pdu->pkt){
NODE_DBG("coap_new_pdu malloc error.\n");
c_free(pdu->scratch.p);
c_free(pdu);
free(pdu->scratch.p);
free(pdu);
return NULL;
}
pdu->pkt->content.p = NULL;
pdu->pkt->content.len = 0;
pdu->msg.p = (uint8_t *)c_zalloc(MAX_REQUEST_SIZE+1); // +1 for string '\0'
pdu->msg.p = (uint8_t *)zalloc(MAX_REQUEST_SIZE+1); // +1 for string '\0'
if(!pdu->msg.p){
NODE_DBG("coap_new_pdu malloc error.\n");
c_free(pdu->pkt);
c_free(pdu->scratch.p);
c_free(pdu);
free(pdu->pkt);
free(pdu->scratch.p);
free(pdu);
return NULL;
}
pdu->msg.len = MAX_REQUEST_SIZE;
......@@ -44,22 +44,22 @@ void coap_delete_pdu(coap_pdu_t *pdu){
return;
if(pdu->scratch.p){
c_free(pdu->scratch.p);
free(pdu->scratch.p);
pdu->scratch.p = NULL;
pdu->scratch.len = 0;
}
if(pdu->pkt){
c_free(pdu->pkt);
free(pdu->pkt);
pdu->pkt = NULL;
}
if(pdu->msg.p){
c_free(pdu->msg.p);
free(pdu->msg.p);
pdu->msg.p = NULL;
pdu->msg.len = 0;
}
c_free(pdu);
free(pdu);
pdu = NULL;
}
......@@ -6,23 +6,23 @@
* README for terms of use.
*/
#include "c_stdlib.h"
#include "c_types.h"
#include <stdlib.h>
#include <ctype.h>
#include "str.h"
str * coap_new_string(size_t size) {
str *s = (str *)c_malloc(sizeof(str) + size + 1);
str *s = (str *)malloc(sizeof(str) + size + 1);
if ( !s ) {
return NULL;
}
c_memset(s, 0, sizeof(str));
memset(s, 0, sizeof(str));
s->s = ((unsigned char *)s) + sizeof(str);
return s;
}
void coap_delete_string(str *s) {
c_free(s);
free(s);
}
......@@ -9,7 +9,7 @@
#ifndef _COAP_STR_H_
#define _COAP_STR_H_
#include "c_string.h"
#include <string.h>
typedef struct {
size_t length; /* length of string */
......
/* uri.c -- helper functions for URI treatment
*/
#include "c_stdio.h"
#include "c_stdlib.h"
#include "c_string.h"
#include "c_ctype.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "coap.h"
#include "uri.h"
......@@ -43,7 +43,7 @@ int coap_split_uri(unsigned char *str_var, size_t len, coap_uri_t *uri) {
if (!str_var || !uri)
return -1;
c_memset(uri, 0, sizeof(coap_uri_t));
memset(uri, 0, sizeof(coap_uri_t));
uri->port = COAP_DEFAULT_PORT;
/* search for scheme */
......@@ -394,16 +394,16 @@ int coap_split_query(coap_rw_buffer_t *scratch, coap_packet_t *pkt, const unsign
coap_uri_t * coap_new_uri(const unsigned char *uri, unsigned int length) {
unsigned char *result;
result = (unsigned char *)c_malloc(length + 1 + sizeof(coap_uri_t));
result = (unsigned char *)malloc(length + 1 + sizeof(coap_uri_t));
if (!result)
return NULL;
c_memcpy(URI_DATA(result), uri, length);
memcpy(URI_DATA(result), uri, length);
URI_DATA(result)[length] = '\0'; /* make it zero-terminated */
if (coap_split_uri(URI_DATA(result), length, (coap_uri_t *)result) < 0) {
c_free(result);
free(result);
return NULL;
}
return (coap_uri_t *)result;
......
......@@ -33,7 +33,7 @@
#include "osapi.h"
#include "mem.h"
#include <string.h>
#include <c_errno.h>
#include <errno.h>
#ifdef MD2_ENABLE
#include "ssl/ssl_crypto.h"
......@@ -109,7 +109,7 @@ int ICACHE_FLASH_ATTR crypto_hash (const digest_mech_info_t *mi,
if (!mi)
return EINVAL;
void *ctx = (void *)os_malloc (mi->ctx_size);
void *ctx = (void *)malloc (mi->ctx_size);
if (!ctx)
return ENOMEM;
......@@ -117,7 +117,7 @@ int ICACHE_FLASH_ATTR crypto_hash (const digest_mech_info_t *mi,
mi->update (ctx, data, data_len);
mi->finalize (digest, ctx);
os_free (ctx);
free (ctx);
return 0;
}
......@@ -130,13 +130,13 @@ int ICACHE_FLASH_ATTR crypto_fhash (const digest_mech_info_t *mi,
return EINVAL;
// Initialise
void *ctx = (void *)os_malloc (mi->ctx_size);
void *ctx = (void *)malloc (mi->ctx_size);
if (!ctx)
return ENOMEM;
mi->create (ctx);
// Hash bytes from file in blocks
uint8_t* buffer = (uint8_t*)os_malloc (mi->block_size);
uint8_t* buffer = (uint8_t*)malloc (mi->block_size);
if (!buffer)
return ENOMEM;
......@@ -149,8 +149,8 @@ int ICACHE_FLASH_ATTR crypto_fhash (const digest_mech_info_t *mi,
// Finish up
mi->finalize (digest, ctx);
os_free (buffer);
os_free (ctx);
free (buffer);
free (ctx);
return 0;
}
......@@ -163,7 +163,7 @@ int ICACHE_FLASH_ATTR crypto_hmac (const digest_mech_info_t *mi,
if (!mi)
return EINVAL;
void *ctx = (void *)os_malloc (mi->ctx_size);
void *ctx = (void *)malloc (mi->ctx_size);
if (!ctx)
return ENOMEM;
......@@ -200,6 +200,6 @@ int ICACHE_FLASH_ATTR crypto_hmac (const digest_mech_info_t *mi,
mi->update (ctx, digest, mi->digest_size);
mi->finalize (digest, ctx);
os_free (ctx);
free (ctx);
return 0;
}
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