Skip to content

Commit

Permalink
More work on merging IoTivity patches
Browse files Browse the repository at this point in the history
Change-Id: I41875348e9667a999bbb223bca3d99d4201fc8fb
Signed-off-by: Dave Thaler <[email protected]>
  • Loading branch information
dthaler committed Jul 29, 2016
1 parent c044245 commit fd5c9ec
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 43 deletions.
14 changes: 7 additions & 7 deletions src/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@

#if !defined(WITH_LWIP) && !defined(WITH_CONTIKI)

time_t clock_offset;
time_t clock_offset = 0;

COAP_STATIC_INLINE coap_queue_t *
coap_malloc_node(void) {
Expand Down Expand Up @@ -158,7 +158,7 @@ coap_free_node(coap_queue_t *node) {
#include "mem.h"
#include "net/ip/uip-debug.h"

clock_time_t clock_offset;
clock_time_t clock_offset = 0;

#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[UIP_LLIPH_LEN])
Expand Down Expand Up @@ -337,6 +337,11 @@ is_wkc(coap_key_t k) {
coap_context_t *
coap_new_context(
const coap_address_t *listen_addr) {
if (!listen_addr) {
coap_log(LOG_EMERG, "no listen address specified\n");
return NULL;
}

#ifndef WITH_CONTIKI
coap_context_t *c = coap_malloc_type(COAP_CONTEXT, sizeof( coap_context_t ) );
#endif /* not WITH_CONTIKI */
Expand All @@ -347,11 +352,6 @@ coap_new_context(
return NULL;
#endif /* WITH_CONTIKI */

if (!listen_addr) {
coap_log(LOG_EMERG, "no listen address specified\n");
return NULL;
}

coap_clock_init();
#ifdef WITH_LWIP
prng_init(LWIP_RAND());
Expand Down
54 changes: 25 additions & 29 deletions src/pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ coap_pdu_init2(unsigned char type, unsigned char code, unsigned short id,
#endif

unsigned int length = 0;
switch(transport) {
switch (transport) {
case COAP_UDP:
length = sizeof(coap_hdr_t);
break;
Expand Down Expand Up @@ -129,21 +129,21 @@ coap_pdu_init2(unsigned char type, unsigned char code, unsigned short id,
#endif

/* size must be large enough for hdr */
#if defined(WITH_POSIX) || defined(WITH_ARDUINO) || defined(_WIN32)
pdu = (coap_pdu_t *)coap_malloc(sizeof(coap_pdu_t) + size);
#endif
#ifdef WITH_CONTIKI
pdu = (coap_pdu_t *)memb_alloc(&pdu_storage);
#if defined(WITH_POSIX) || defined(WITH_CONTIKI) || defined(WITH_ARDUINO) || defined(_WIN32)
pdu = (coap_pdu_t *)coap_malloc_type(COAP_PDU, sizeof(coap_pdu_t));
if (!pdu) return NULL;
pdu->hdr = coap_malloc_type(COAP_PDU_BUF, size);
if (pdu->hdr == NULL) {
coap_free_type(COAP_PDU, pdu);
pdu = NULL;
}
#endif
#ifdef WITH_LWIP
pdu = (coap_pdu_t*)coap_malloc_type(COAP_PDU, sizeof(coap_pdu_t));
if (!pdu) return NULL;
p = pbuf_alloc(PBUF_TRANSPORT, size, PBUF_RAM);
if (p != NULL) {
u8_t header_error = pbuf_header(p, sizeof(coap_pdu_t));
/* we could catch that case and allocate larger memory in advance, but then
* again, we'd run into greater trouble with incoming packages anyway */
LWIP_ASSERT("CoAP PDU header does not fit in transport header", header_error == 0);
pdu = p->payload;
} else {
if (p == NULL) {
coap_free_type(COAP_PDU, pdu);
pdu = NULL;
}
#endif
Expand Down Expand Up @@ -185,7 +185,7 @@ coap_pdu_init2(unsigned char type, unsigned char code, unsigned short id,

coap_pdu_t *
coap_new_pdu(void) {
return coap_new_pdu2(COAP_UDP, 0);
return coap_new_pdu2(COAP_UDP, COAP_MAX_PDU_SIZE);
}

coap_pdu_t *
Expand All @@ -198,11 +198,7 @@ coap_new_pdu2(coap_transport_t transport, unsigned int size) {
#else /* WITH_CONTIKI */
uip_ntohs(COAP_INVALID_TID),
#endif /* WITH_CONTIKI */
#ifndef WITH_TCP
COAP_MAX_PDU_SIZE,
#else
size,
#endif
transport);

#ifndef NDEBUG
Expand Down Expand Up @@ -259,7 +255,7 @@ coap_get_tcp_header_type_from_size(unsigned int size) {
coap_transport_t
coap_get_tcp_header_type_from_initbyte(unsigned int length) {
coap_transport_t type;
switch(length) {
switch (length) {
case COAP_TCP_LENGTH_FIELD_NUM_8_BIT:
type = COAP_TCP_8BIT;
break;
Expand All @@ -279,7 +275,7 @@ void
coap_add_length(const coap_pdu_t *pdu, coap_transport_t transport, unsigned int length) {
assert(pdu);

switch(transport) {
switch (transport) {
case COAP_TCP:
pdu->transport_hdr->tcp.header_data[0] = length << 4;
break;
Expand Down Expand Up @@ -316,7 +312,7 @@ coap_get_length_from_header(const unsigned char *header, coap_transport_t transp

unsigned int length = 0;
unsigned int length_field_data = 0;
switch(transport) {
switch (transport) {
case COAP_TCP:
length = header[0] >> 4;
break;
Expand Down Expand Up @@ -344,7 +340,7 @@ coap_get_length(const coap_pdu_t *pdu, coap_transport_t transport) {

unsigned int length = 0;
unsigned int length_field_data = 0;
switch(transport) {
switch (transport) {
case COAP_TCP:
length = pdu->transport_hdr->tcp.header_data[0] >> 4;
break;
Expand Down Expand Up @@ -388,7 +384,7 @@ coap_get_tcp_header_length(unsigned char *data) {
unsigned int
coap_get_tcp_header_length_for_transport(coap_transport_t transport) {
unsigned int length = 0;
switch(transport) {
switch (transport) {
case COAP_TCP:
length = COAP_TCP_HEADER_NO_FIELD;
break;
Expand Down Expand Up @@ -443,7 +439,7 @@ void
coap_add_code(const coap_pdu_t *pdu, coap_transport_t transport, unsigned int code) {
assert(pdu);

switch(transport) {
switch (transport) {
case COAP_UDP:
pdu->transport_hdr->udp.code = COAP_RESPONSE_CODE(code);
break;
Expand Down Expand Up @@ -471,7 +467,7 @@ coap_get_code(const coap_pdu_t *pdu, coap_transport_t transport) {
assert(pdu);

unsigned int code = 0;
switch(transport) {
switch (transport) {
case COAP_UDP:
code = pdu->transport_hdr->udp.code;
break;
Expand Down Expand Up @@ -509,7 +505,7 @@ coap_add_token2(coap_pdu_t *pdu, size_t len, const unsigned char *data,
return 0;

unsigned char* token = NULL;
switch(transport) {
switch (transport) {
case COAP_UDP:
pdu->transport_hdr->udp.token_length = len;
token = pdu->transport_hdr->udp.token;
Expand Down Expand Up @@ -568,7 +564,7 @@ coap_get_token2(const coap_hdr_transport_t *pdu_hdr, coap_transport_t transport,
assert(token);
assert(token_length);

switch(transport) {
switch (transport) {
case COAP_UDP:
*token_length = pdu_hdr->udp.token_length;
*token = (unsigned char *)pdu_hdr->udp.token;
Expand Down Expand Up @@ -616,7 +612,7 @@ coap_add_option2(coap_pdu_t *pdu, unsigned short type, unsigned int len,
return 0;
}

switch(transport) {
switch (transport) {
#ifdef WITH_TCP
case COAP_TCP:
opt = (unsigned char *) &(pdu->transport_hdr->tcp) + pdu->length;
Expand Down Expand Up @@ -825,7 +821,7 @@ coap_pdu_parse2(unsigned char *data, size_t length, coap_pdu_t *pdu,
coap_opt_t *opt = NULL;
unsigned int tokenLength = 0;
#ifdef WITH_TCP
switch(transport) {
switch (transport) {
case COAP_UDP:
break;
case COAP_TCP:
Expand Down
2 changes: 1 addition & 1 deletion src/resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ match(const str *text, const str *pattern, int match_prefix, int match_substring
while (remaining_length) {
size_t token_length;
unsigned char *token = next_token;
next_token = memchr(token, ' ', remaining_length);
next_token = (unsigned char *)memchr(token, ' ', remaining_length);

if (next_token) {
token_length = next_token - token;
Expand Down
4 changes: 2 additions & 2 deletions src/str.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include "str.h"

str *coap_new_string(size_t size) {
str *s = coap_malloc(sizeof(str) + size + 1);
if ( !s ) {
str *s = (str *)coap_malloc(sizeof(str) + size + 1);
if (!s) {
#ifndef NDEBUG
coap_log(LOG_CRIT, "coap_new_string: malloc\n");
#endif
Expand Down
8 changes: 4 additions & 4 deletions src/uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ coap_uri_t *
coap_new_uri(const unsigned char *uri, unsigned int length) {
unsigned char *result;

result = coap_malloc(length + 1 + sizeof(coap_uri_t));
result = (unsigned char *)coap_malloc(length + 1 + sizeof(coap_uri_t));

if (!result)
return NULL;
Expand Down Expand Up @@ -476,7 +476,7 @@ coap_clone_uri(const coap_uri_t *uri) {
* segment_handler_t hence we use this wrapper as safe typecast. */
COAP_STATIC_INLINE void
hash_segment(unsigned char *s, size_t len, void *data) {
coap_hash(s, len, data);
coap_hash(s, len, (unsigned char *)data);
}

int
Expand Down Expand Up @@ -530,14 +530,14 @@ coap_parse_next(coap_parse_iterator_t *pi) {

/* skip following separator (the first segment might not have one) */

if (strchr((const char*)s,*(pi->pos))) {
if (strchr((const char*)s, *(pi->pos))) {
++pi->pos;
--pi->n;
}

p = pi->pos;

while ((pi->segment_length < pi->n) && (!strchr((const char*)s,*p))
while ((pi->segment_length < pi->n) && (!strchr((const char*)s, *p))
&& (!strnchr(pi->delim, pi->dlen, *p))) {
++p;
++pi->segment_length;
Expand Down

0 comments on commit fd5c9ec

Please sign in to comment.