Skip to content

Commit

Permalink
Patches from IoTivity
Browse files Browse the repository at this point in the history
Change-Id: Idddee819530e8eb497a8abf72aa1f94a7b30d40b
Signed-off-by: Dave Thaler <[email protected]>
  • Loading branch information
dthaler committed Jul 27, 2016
1 parent edf42a6 commit c1bda6e
Show file tree
Hide file tree
Showing 33 changed files with 679 additions and 164 deletions.
1 change: 1 addition & 0 deletions coap_config.h.contiki
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

#define HAVE_STRNLEN 1
#define HAVE_SNPRINTF 1
#define HAVE_STRINGS_H 1

/* there is no file-oriented output */
#define COAP_DEBUG_FD NULL
Expand Down
37 changes: 37 additions & 0 deletions coap_config.h.windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef _COAP_CONFIG_H_
#define _COAP_CONFIG_H_

/* Define to 1 if you have <Ws2tcpip.h> header file. */
#if defined(_WIN32)
#define HAVE_WS2TCPIP_H 1
#endif

/* Define to 1 if you have <Winsock2.h> header file. */
#if defined(_WIN32)
#define HAVE_WINSOCK2_H 1
#endif

#ifdef _WIN32
#define ssize_t SSIZE_T
#define in_port_t uint16_t
#endif

/* Define to the full name of this package. */
#define PACKAGE_NAME "libcoap"

/* Define to the full name and version of this package. */
#define PACKAGE_STRING "libcoap 4.1.1"

#ifndef COAP_STATIC_INLINE
# if defined(__cplusplus)
# define COAP_STATIC_INLINE inline
# else
# ifdef _MSC_VER
# define COAP_STATIC_INLINE static __inline
# else
# define COAP_STATIC_INLINE static inline
# endif
# endif
#endif

#endif /* _COAP_CONFIG_H_ */
6 changes: 3 additions & 3 deletions examples/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ coap_tick_t obs_wait = 0; /* timeout for current subscription */
#define UNUSED_PARAM
#endif /* GCC */

static inline void
COAP_STATIC_INLINE void
set_timeout(coap_tick_t *timer, const unsigned int seconds) {
coap_ticks(timer);
*timer += seconds * COAP_TICKS_PER_SECOND;
Expand Down Expand Up @@ -305,7 +305,7 @@ resolve_address(const str *server, struct sockaddr *dst) {
((Pdu)->hdr->code == COAP_RESPONSE_CODE(201) || \
(Pdu)->hdr->code == COAP_RESPONSE_CODE(204)))

static inline int
COAP_STATIC_INLINE int
check_token(coap_pdu_t *received) {
return received->hdr->token_length == the_token.length &&
memcmp(received->hdr->token, the_token.s, the_token.length) == 0;
Expand Down Expand Up @@ -808,7 +808,7 @@ cmdline_proxy(char *arg) {
return 1;
}

static inline void
COAP_STATIC_INLINE void
cmdline_token(char *arg) {
strncpy((char *)the_token.s, arg, min(sizeof(_token_data), strlen(arg)));
the_token.length = strlen(arg);
Expand Down
4 changes: 2 additions & 2 deletions examples/coap-rd.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ rd_t *resources = NULL;
#define UNUSED_PARAM
#endif /* GCC */

static inline rd_t *
COAP_STATIC_INLINE rd_t *
rd_new(void) {
rd_t *rd;
rd = (rd_t *)coap_malloc(sizeof(rd_t));
Expand All @@ -75,7 +75,7 @@ rd_new(void) {
return rd;
}

static inline void
COAP_STATIC_INLINE void
rd_delete(rd_t *rd) {
if (rd) {
coap_free(rd->data.s);
Expand Down
6 changes: 3 additions & 3 deletions examples/etsi_iot_01.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ coap_new_payload(size_t size) {
return p;
}

static inline coap_payload_t *
COAP_STATIC_INLINE coap_payload_t *
coap_find_payload(const coap_key_t key) {
coap_payload_t *p;
HASH_FIND(hh, test_resources, key, sizeof(coap_key_t), p);
return p;
}

static inline void
COAP_STATIC_INLINE void
coap_add_payload(const coap_key_t key, coap_payload_t *payload,
coap_dynamic_uri_t *uri) {
assert(payload);
Expand All @@ -109,7 +109,7 @@ coap_add_payload(const coap_key_t key, coap_payload_t *payload,
}
}

static inline void
COAP_STATIC_INLINE void
coap_delete_payload(coap_payload_t *payload) {
if (payload) {
coap_dynamic_uri_t *uri;
Expand Down
20 changes: 10 additions & 10 deletions include/coap/address.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ typedef struct coap_address_t {
#define _coap_is_mcast_impl(Address) uip_is_addr_mcast(&((Address)->addr))
#endif /* WITH_CONTIKI */

#ifdef WITH_POSIX
#if !defined(WITH_LWIP) && !defined(WITH_CONTIKI)
/** multi-purpose address abstraction */
typedef struct coap_address_t {
socklen_t size; /**< size of addr */
Expand All @@ -71,7 +71,7 @@ typedef struct coap_address_t {
*/
int coap_address_equals(const coap_address_t *a, const coap_address_t *b);

static inline int
COAP_STATIC_INLINE int
_coap_address_isany_impl(const coap_address_t *a) {
/* need to compare only relevant parts of sockaddr_in6 */
switch (a->addr.sa.sa_family) {
Expand All @@ -88,7 +88,7 @@ _coap_address_isany_impl(const coap_address_t *a) {
return 0;
}

static inline int
COAP_STATIC_INLINE int
_coap_is_mcast_impl(const coap_address_t *a) {
if (!a)
return 0;
Expand All @@ -103,7 +103,7 @@ _coap_is_mcast_impl(const coap_address_t *a) {
}
return 0;
}
#endif /* WITH_POSIX */
#endif /* !WITH_LWIP && !WITH_CONTIKI */

/**
* Resets the given coap_address_t object @p addr to its default values. In
Expand All @@ -112,23 +112,23 @@ _coap_is_mcast_impl(const coap_address_t *a) {
*
* @param addr The coap_address_t object to initialize.
*/
static inline void
COAP_STATIC_INLINE void
coap_address_init(coap_address_t *addr) {
assert(addr);
memset(addr, 0, sizeof(coap_address_t));
#ifdef WITH_POSIX
#if defined(WITH_LWIP) || defined(WITH_CONTIKI)
/* lwip and Contiki have constant address sizes and doesn't need the .size part */
addr->size = sizeof(addr->addr);
#endif
}

#ifndef WITH_POSIX
#if defined(WITH_LWIP) || defined(WITH_CONTIKI)
/**
* Compares given address objects @p a and @p b. This function returns @c 1 if
* addresses are equal, @c 0 otherwise. The parameters @p a and @p b must not be
* @c NULL;
*/
static inline int
COAP_STATIC_INLINE int
coap_address_equals(const coap_address_t *a, const coap_address_t *b) {
assert(a); assert(b);
return _coap_address_equals_impl(a, b);
Expand All @@ -140,7 +140,7 @@ coap_address_equals(const coap_address_t *a, const coap_address_t *b) {
* function returns @c 1 if this is the case, @c 0 otherwise. The parameters @p
* a must not be @c NULL;
*/
static inline int
COAP_STATIC_INLINE int
coap_address_isany(const coap_address_t *a) {
assert(a);
return _coap_address_isany_impl(a);
Expand All @@ -150,7 +150,7 @@ coap_address_isany(const coap_address_t *a) {
* Checks if given address @p a denotes a multicast address. This function
* returns @c 1 if @p a is multicast, @c 0 otherwise.
*/
static inline int
COAP_STATIC_INLINE int
coap_is_mcast(const coap_address_t *a) {
return a && _coap_is_mcast_impl(a);
}
Expand Down
2 changes: 1 addition & 1 deletion include/coap/async.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ coap_async_state_t *coap_find_async(coap_context_t *context, coap_tid_t id);
*
* @param s The state object to update.
*/
static inline void
COAP_STATIC_INLINE void
coap_touch_async(coap_async_state_t *s) { coap_ticks(&s->created); }

/** @} */
Expand Down
6 changes: 3 additions & 3 deletions include/coap/bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*
* @return @c -1 if @p bit does not fit into @p vec, @c 1 otherwise.
*/
inline static int
COAP_STATIC_INLINE int
bits_setb(uint8_t *vec, size_t size, uint8_t bit) {
if (size <= (bit >> 3))
return -1;
Expand All @@ -48,7 +48,7 @@ bits_setb(uint8_t *vec, size_t size, uint8_t bit) {
*
* @return @c -1 if @p bit does not fit into @p vec, @c 1 otherwise.
*/
inline static int
COAP_STATIC_INLINE int
bits_clrb(uint8_t *vec, size_t size, uint8_t bit) {
if (size <= (bit >> 3))
return -1;
Expand All @@ -67,7 +67,7 @@ bits_clrb(uint8_t *vec, size_t size, uint8_t bit) {
*
* @return @c 1 if the bit is set, @c 0 otherwise.
*/
inline static int
COAP_STATIC_INLINE int
bits_getb(const uint8_t *vec, size_t size, uint8_t bit) {
if (size <= (bit >> 3))
return -1;
Expand Down
4 changes: 2 additions & 2 deletions include/coap/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ unsigned int coap_opt_block_num(const coap_opt_t *block_opt);
* Checks if more than @p num blocks are required to deliver @p data_len
* bytes of data for a block size of 1 << (@p szx + 4).
*/
static inline int
COAP_STATIC_INLINE int
coap_more_blocks(size_t data_len, unsigned int num, unsigned short szx) {
return ((num+1) << (szx + 4)) < data_len;
}

/** Sets the More-bit in @p block_opt */
static inline void
COAP_STATIC_INLINE void
coap_opt_block_set_m(coap_opt_t *block_opt, int m) {
if (m)
*(COAP_OPT_VALUE(block_opt) + (COAP_OPT_LENGTH(block_opt) - 1)) |= 0x08;
Expand Down
1 change: 1 addition & 0 deletions include/coap/coap.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extern "C" {
#include "bits.h"
#include "block.h"
#include "coap_io.h"
#include "coap_list.h"
#include "coap_time.h"
#include "debug.h"
#include "encode.h"
Expand Down
6 changes: 2 additions & 4 deletions include/coap/coap_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ struct coap_context_t;
* tuple (handle, addr) must uniquely identify this endpoint.
*/
typedef struct coap_endpoint_t {
#if defined(WITH_POSIX) || defined(WITH_CONTIKI)
#ifndef WITH_LWIP
union {
int fd; /**< on POSIX systems */
void *conn; /**< opaque connection (e.g. uip_conn in Contiki) */
} handle; /**< opaque handle to identify this endpoint */
#endif /* WITH_POSIX or WITH_CONTIKI */

#ifdef WITH_LWIP
#else
struct udp_pcb *pcb;
/**< @FIXME --chrysn
* this was added in a hurry, not sure it confirms to the overall model */
Expand Down
48 changes: 48 additions & 0 deletions include/coap/coap_list.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 * -*- */

/* coap_list.h -- CoAP list structures
*
* Copyright (C) 2010,2011,2015 Olaf Bergmann <[email protected]>
*
* This file is part of the CoAP library libcoap. Please see README for terms of
* use.
*/

#ifndef _COAP_LIST_H_
#define _COAP_LIST_H_

#include "utlist.h"

struct coap_linkedlistnode {
struct coap_linkedlistnode *next;
void *data;

/**
* Callback function that is called from coap_delete to release
* additional memory allocated by data Set to NULL if you do not
* need this. Note that data is free'd automatically. */
void (*delete_func)(void *);
};

typedef struct coap_linkedlistnode coap_list_t;

/**
* Adds node to given queue, ordered by specified order function. Returns 1
* when insert was successful, 0 otherwise.
*/
int coap_insert(coap_list_t **queue, coap_list_t *node, int (*order)(void *, void *));

/* destroys specified node */
int coap_delete(coap_list_t *node);

/* removes all items from given queue and frees the allocated storage */
void coap_delete_list(coap_list_t *queue);

/**
* Creates a new list node and adds the given data object. The memory allocated
* by data will be released by coap_delete() with the new node. Returns the
* new list node.
*/
coap_list_t *coap_new_listnode(void *data, void (*delete_func)(void *));

#endif /* _COAP_LIST_H_ */
20 changes: 10 additions & 10 deletions include/coap/coap_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ typedef uint32_t coap_tick_t;
typedef uint32_t coap_time_t;
typedef int32_t coap_tick_diff_t;

static inline void coap_ticks_impl(coap_tick_t *t) {
COAP_STATIC_INLINE void coap_ticks_impl(coap_tick_t *t) {
*t = sys_now();
}

static inline void coap_clock_init_impl(void) {
COAP_STATIC_INLINE void coap_clock_init_impl(void) {
}

#define coap_clock_init coap_clock_init_impl
#define coap_ticks coap_ticks_impl

static inline coap_time_t coap_ticks_to_rt(coap_tick_t t) {
COAP_STATIC_INLINE coap_time_t coap_ticks_to_rt(coap_tick_t t) {
return t / COAP_TICKS_PER_SECOND;
}
#endif
Expand All @@ -63,20 +63,20 @@ typedef int coap_tick_diff_t;

#define COAP_TICKS_PER_SECOND CLOCK_SECOND

static inline void coap_clock_init(void) {
COAP_STATIC_INLINE void coap_clock_init(void) {
clock_init();
}

static inline void coap_ticks(coap_tick_t *t) {
COAP_STATIC_INLINE void coap_ticks(coap_tick_t *t) {
*t = clock_time();
}

static inline coap_time_t coap_ticks_to_rt(coap_tick_t t) {
COAP_STATIC_INLINE coap_time_t coap_ticks_to_rt(coap_tick_t t) {
return t / COAP_TICKS_PER_SECOND;
}
#endif /* WITH_CONTIKI */

#ifdef WITH_POSIX
#if !defined(WITH_LWIP) && !defined(WITH_CONTIKI)
/**
* This data type represents internal timer ticks with COAP_TICKS_PER_SECOND
* resolution.
Expand Down Expand Up @@ -119,21 +119,21 @@ void coap_ticks(coap_tick_t *t);
* point (seconds since epoch on POSIX).
*/
coap_time_t coap_ticks_to_rt(coap_tick_t t);
#endif /* WITH_POSIX */
#endif /* !WITH_LWIP && !WITH_CONTIKI */

/**
* Returns @c 1 if and only if @p a is less than @p b where less is defined on a
* signed data type.
*/
static inline int coap_time_lt(coap_tick_t a, coap_tick_t b) {
COAP_STATIC_INLINE int coap_time_lt(coap_tick_t a, coap_tick_t b) {
return ((coap_tick_diff_t)(a - b)) < 0;
}

/**
* Returns @c 1 if and only if @p a is less than or equal @p b where less is
* defined on a signed data type.
*/
static inline int coap_time_le(coap_tick_t a, coap_tick_t b) {
COAP_STATIC_INLINE int coap_time_le(coap_tick_t a, coap_tick_t b) {
return a == b || coap_time_lt(a,b);
}

Expand Down
Loading

0 comments on commit c1bda6e

Please sign in to comment.