Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes from Iotivity for draft-ietf-core-coap-tcp-tls and cross-platform support #47

Open
wants to merge 49 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
1b3818d
Patches from IoTivity
dthaler Jul 27, 2016
c1bda6e
Patches from IoTivity
dthaler Jul 27, 2016
673a575
Merge branch 'develop' of https://github.com/dthaler/libcoap into dev…
dthaler Jul 27, 2016
c11591d
Merge branch 'develop' of https://github.com/dthaler/libcoap into dev…
dthaler Jul 27, 2016
0e35a2f
Merge branch 'develop' of https://github.com/dthaler/libcoap into dev…
dthaler Jul 28, 2016
40a6d09
Merge branch 'develop' of https://github.com/dthaler/libcoap into dev…
dthaler Jul 28, 2016
c044245
Merge branch 'develop' of https://github.com/dthaler/libcoap into dev…
dthaler Jul 28, 2016
62c0186
More work on merging IoTivity patches
dthaler Jul 28, 2016
fd5c9ec
More work on merging IoTivity patches
dthaler Jul 28, 2016
72c7ce6
Merge branch 'develop' of https://github.com/dthaler/libcoap into dev…
dthaler Jul 29, 2016
42aedb2
Fix merge bug
dthaler Sep 22, 2016
65e7398
Windows-specific fix
dthaler Sep 22, 2016
e43531b
Port tests to windows
dthaler Sep 22, 2016
749514f
Fix for x86 Windows
dthaler Oct 11, 2016
9feaa9e
Fix release build error
dthaler Oct 14, 2016
9373a4c
Linux compilation fix
dthaler Jan 20, 2017
0012bae
Merge remote-tracking branch 'upstream/develop' into develop
dthaler Jan 20, 2017
fa987b4
Fixes from merging
dthaler Jan 20, 2017
d03c8a0
Addressed feedback from tijuca, don't use negative logic in ifdefs
dthaler Jan 20, 2017
ccc0f01
Fix typo
dthaler Jan 20, 2017
ee5123d
Merge pull request #1 from dthaler/develop
PawelWMS Jan 27, 2017
092d7e2
Fixing C4018 warnings for x86 builds.
PawelWMS Jan 27, 2017
a455214
Merge pull request #2 from PawelWMS/develop
dthaler Jan 27, 2017
bc69a9f
Fix travis issues
dthaler Jan 27, 2017
4d3805f
Merge branch 'develop' of https://github.com/dthaler/libcoap into dev…
dthaler Jan 27, 2017
2238ebb
Fix more travis issues
dthaler Jan 27, 2017
c38dc95
Fix more travis issues
dthaler Jan 27, 2017
7d34f47
Merge branch 'develop' of https://github.com/dthaler/libcoap into dev…
dthaler Jan 27, 2017
8c39fe4
Fix more travis issues
dthaler Jan 27, 2017
62c6792
Fix more travis issues
dthaler Jan 27, 2017
39fabf2
Merge branch 'develop' of https://github.com/dthaler/libcoap into dev…
dthaler Jan 27, 2017
d0ed3e8
Merge branch 'develop' of https://github.com/dthaler/libcoap into dev…
dthaler Jan 27, 2017
60a0af0
Merge branch 'develop' of https://github.com/dthaler/libcoap into dev…
dthaler Feb 9, 2017
40a2641
Fix pdu length truncation
danmihai1 Mar 8, 2017
a8b1149
Merge pull request #4 from danmihai1/develop
dthaler Mar 8, 2017
f21c7fb
Merge remote-tracking branch 'upstream/develop' into develop
dthaler Mar 21, 2017
358bd58
Merge remote-tracking branch 'upstream/develop' into develop
dthaler Apr 3, 2017
d54f001
Fixing libcoap W4 warnings.
PawelWMS Mar 7, 2017
9f1d956
Bracket fixes.
PawelWMS Apr 4, 2017
577804c
Merge pull request #5 from PawelWMS/origin_W4_fix
dthaler Apr 5, 2017
2f6ff0c
Added CoAP over WebSocket support.
SenthilKumarGS Apr 28, 2017
f4d20bc
Merge pull request #6 from SenthilKumarGS/develop
dthaler May 30, 2017
5f2d238
Update pdu.c
Koushik4082 May 17, 2018
5dc2fdc
Update pdu.c
Koushik4082 May 17, 2018
7164418
Merge pull request #1 from Koushik4082/Koushik4082-patch-1
Koushik4082 May 17, 2018
bd60461
Update pdu.h
Koushik4082 May 17, 2018
fa8b2b9
Merge pull request #7 from Koushik4082/develop
dthaler Jun 4, 2018
b497109
Fix for where WITH_TCP is defined, WITH_WS is not.
mwichmann Sep 13, 2018
5a16b17
Merge pull request #8 from mwichmann/ws-fix
dthaler Sep 13, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ libcoap_@LIBCOAP_API_VERSION@_la_SOURCES = \
src/async.c \
src/block.c \
src/coap_io.c \
src/coap_list.c \
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why you have moved coap_list back into the library. The code has been used only in examples/client.c for some time now and thus should live there (until it is removed entirely).

src/coap_time.c \
src/debug.c \
src/encode.c \
Expand Down
12 changes: 11 additions & 1 deletion 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 Expand Up @@ -120,7 +121,7 @@ typedef void FILE;
# endif /* UIP_CONF_BYTE_ORDER */
#endif /* BYTE_ORDER */

/* Define assert() as emtpy directive unless HAVE_ASSERT_H is given. */
/* Define assert() as empty directive unless HAVE_ASSERT_H is given. */
#ifndef HAVE_ASSERT_H
# define assert(x)
#endif
Expand All @@ -130,5 +131,14 @@ typedef void FILE;
#include <stdio.h>
#define coap_log(fd, ...) printf(__VA_ARGS__)

/* Make libcoap headers safe to use from C++ */
#ifndef COAP_STATIC_INLINE
# if defined(__cplusplus)
# define COAP_STATIC_INLINE inline
# else
# define COAP_STATIC_INLINE static inline
# endif
#endif

#endif /* _CONFIG_H_ */

9 changes: 9 additions & 0 deletions coap_config.h.lwip
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,13 @@

#define COAP_RESOURCES_NOHASH

/* Make libcoap headers safe to use from C++ */
#ifndef COAP_STATIC_INLINE
# if defined(__cplusplus)
# define COAP_STATIC_INLINE inline
# else
# define COAP_STATIC_INLINE static inline
# endif
#endif

#endif /* _CONFIG_H_ */
64 changes: 64 additions & 0 deletions coap_config.h.windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#ifndef _COAP_CONFIG_H_
#define _COAP_CONFIG_H_

#if defined(_WIN32)

/* Define to 1 if you have <ws2tcpip.h> header file. */
#define HAVE_WS2TCPIP_H 1

/* Define to 1 if you have <winsock2.h> header file. */
#define HAVE_WINSOCK2_H 1

/* Define to 1 if you have <assert.h> header file. */
#define HAVE_ASSERT_H 1

/* Define to 1 if you have <limits.h> header file. */
#define HAVE_LIMITS_H 1

/* Define to 1 if you have <stdio.h> header file. */
#define HAVE_STDIO_H 1

/* Define to 1 if you have <time.h> header file. */
#define HAVE_TIME_H 1

/* Define to 1 if you have malloc(). */
#define HAVE_MALLOC 1

/* Define to 1 if you have vprintf(). */
#define HAVE_VPRINTF 1

/* Define to 1 if you have strnlen(). */
#define HAVE_STRNLEN 1

/* Define to 1 if you have snprintf(). */
#if defined(_MSC_VER) && (_MSC_VER >= 1900)
#define HAVE_SNPRINTF 1
#endif

#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 version of this package. */
#define PACKAGE_VERSION "4.1.1"

/* 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_ */
14 changes: 13 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,13 @@ fi

# Checks for header files.
AC_CHECK_HEADERS([assert.h arpa/inet.h limits.h netdb.h netinet/in.h \
stdlib.h string.h strings.h sys/socket.h sys/time.h \
stdlib.h string.h strings.h sys/select.h sys/socket.h sys/time.h \
time.h unistd.h sys/unistd.h syslog.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_C_INLINE

# Checks for library functions.
AC_CHECK_FUNCS([memset select socket strcasecmp strrchr getaddrinfo \
Expand Down Expand Up @@ -385,6 +386,17 @@ tests/Makefile
libcoap-$LIBCOAP_API_VERSION.pc:libcoap-$LIBCOAP_API_VERSION.pc.in
])

AH_BOTTOM([
/* Make libcoap headers safe to use from C++ */
#ifndef COAP_STATIC_INLINE
# if defined(__cplusplus)
# define COAP_STATIC_INLINE inline
# else
# define COAP_STATIC_INLINE static inline
# endif
#endif
])

AC_OUTPUT

AC_MSG_RESULT([
Expand Down
2 changes: 1 addition & 1 deletion examples/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ AM_CFLAGS = -isystem$(top_builddir)/include/coap -I$(top_srcdir)/include/coap $(
# etsi_iot_01 and tiny are missing
bin_PROGRAMS = coap-client coap-server coap-rd

coap_client_SOURCES = client.c coap_list.c
coap_client_SOURCES = client.c coap_append.c
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Renaming this file would not be necessary when keeping coap_list.{h,c} in the examples folder.)

coap_client_LDADD = $(top_builddir)/.libs/libcoap-$(LIBCOAP_API_VERSION).la

coap_server_SOURCES = coap-server.c
Expand Down
57 changes: 39 additions & 18 deletions examples/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,37 @@

#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#else
# include "getopt.h"
#endif
#include <stdio.h>
#include <ctype.h>
#include <sys/select.h>
#ifdef HAVE_SYS_SELECT_H
# include <sys/select.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
#ifdef HAVE_NETDB_H
# include <netdb.h>
#endif
#ifndef HAVE_STRCASECMP
/* The POSIX strcasecmp() is not supported, so use the ISO C++ conformant _stricmp instead. */
# define strcasecmp _stricmp
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder where _stricmp() might be defined. In my (draft version) of ISO 14882:2011, there is no such thing. Please enlighten me.

#endif

#include "coap.h"
#include "coap_append.h"
#include "coap_list.h"

int flags = 0;
Expand Down Expand Up @@ -61,15 +80,17 @@ coap_tick_t max_wait; /* global timeout (changed by set_timeou
unsigned int obs_seconds = 30; /* default observe time */
coap_tick_t obs_wait = 0; /* timeout for current subscription */

#ifndef min
#define min(a,b) ((a) < (b) ? (a) : (b))
#endif

#ifdef __GNUC__
#define UNUSED_PARAM __attribute__ ((unused))
#else /* not a GCC */
#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 +326,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 @@ -694,7 +715,7 @@ cmdline_uri(char *arg, int create_uri_opts) {
if (proxy.length) { /* create Proxy-Uri from argument */
size_t len = strlen(arg);
while (len > 270) {
coap_insert(&optlist,
coap_append(&optlist,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above for notes on these changes.

new_option_node(COAP_OPTION_PROXY_URI,
270,
(unsigned char *)arg));
Expand All @@ -703,7 +724,7 @@ cmdline_uri(char *arg, int create_uri_opts) {
arg += 270;
}

coap_insert(&optlist,
coap_append(&optlist,
new_option_node(COAP_OPTION_PROXY_URI,
len,
(unsigned char *)arg));
Expand All @@ -714,7 +735,7 @@ cmdline_uri(char *arg, int create_uri_opts) {
}

if (uri.port != COAP_DEFAULT_PORT && create_uri_opts) {
coap_insert(&optlist,
coap_append(&optlist,
new_option_node(COAP_OPTION_URI_PORT,
coap_encode_var_bytes(portbuf, uri.port),
portbuf));
Expand All @@ -725,7 +746,7 @@ cmdline_uri(char *arg, int create_uri_opts) {
res = coap_split_path(uri.path.s, uri.path.length, buf, &buflen);

while (res--) {
coap_insert(&optlist,
coap_append(&optlist,
new_option_node(COAP_OPTION_URI_PATH,
COAP_OPT_LENGTH(buf),
COAP_OPT_VALUE(buf)));
Expand All @@ -740,7 +761,7 @@ cmdline_uri(char *arg, int create_uri_opts) {
res = coap_split_query(uri.query.s, uri.query.length, buf, &buflen);

while (res--) {
coap_insert(&optlist,
coap_append(&optlist,
new_option_node(COAP_OPTION_URI_QUERY,
COAP_OPT_LENGTH(buf),
COAP_OPT_VALUE(buf)));
Expand Down Expand Up @@ -792,14 +813,14 @@ set_blocksize(void) {
opt_length = coap_encode_var_bytes(buf,
(block.num << 4 | block.m << 3 | block.szx));

coap_insert(&optlist, new_option_node(opt, opt_length, buf));
coap_append(&optlist, new_option_node(opt, opt_length, buf));
}
}

static void
cmdline_subscribe(char *arg) {
obs_seconds = atoi(arg);
coap_insert(&optlist, new_option_node(COAP_OPTION_SUBSCRIPTION, 0, NULL));
coap_append(&optlist, new_option_node(COAP_OPTION_SUBSCRIPTION, 0, NULL));
}

static int
Expand Down Expand Up @@ -835,7 +856,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 All @@ -852,7 +873,7 @@ cmdline_option(char *arg) {
if (*arg == ',')
++arg;

coap_insert(&optlist,
coap_append(&optlist,
new_option_node(num, strlen(arg), (unsigned char *)arg));
}

Expand Down Expand Up @@ -1212,7 +1233,7 @@ main(int argc, char **argv) {
&& create_uri_opts) {
/* add Uri-Host */

coap_insert(&optlist,
coap_append(&optlist,
new_option_node(COAP_OPTION_URI_HOST,
uri.host.length,
uri.host.s));
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
28 changes: 3 additions & 25 deletions examples/coap_list.c → examples/coap_append.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@
* use.
*/

/* #include "coap_config.h" */
#include "coap_config.h"

#include <stdio.h>
#include <string.h>

#include "debug.h"
#include "mem.h"
#include "coap_list.h"

#include "coap_append.h"

int
coap_insert(coap_list_t **head, coap_list_t *node) {
coap_append(coap_list_t **head, coap_list_t *node) {
if (!node) {
coap_log(LOG_WARNING, "cannot create option Proxy-Uri\n");
} else {
Expand All @@ -30,24 +29,3 @@ coap_insert(coap_list_t **head, coap_list_t *node) {

return node != NULL;
}

int
coap_delete(coap_list_t *node) {
if (node) {
coap_free(node);
}
return 1;
}

void
coap_delete_list(coap_list_t *queue) {
coap_list_t *elt, *tmp;

if (!queue)
return;

LL_FOREACH_SAFE(queue, elt, tmp) {
coap_delete(elt);
}
}

Loading