diff --git a/coap_config.h.windows b/coap_config.h.windows new file mode 100644 index 0000000000..ee3216a40a --- /dev/null +++ b/coap_config.h.windows @@ -0,0 +1,111 @@ +#ifndef _COAP_CONFIG_H_ +#define _COAP_CONFIG_H_ + +#if defined(_WIN32) + +/* Define to 1 if you have header file. */ +#define HAVE_WS2TCPIP_H 1 + +/* Define to 1 if you have header file. */ +#define HAVE_WINSOCK2_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ASSERT_H 1 + +/* Define to 1 if you have the `getaddrinfo' function. */ +#define HAVE_GETADDRINFO 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_LIMITS_H 1 + +/* Define to 1 if you have the `malloc' function. */ +#define HAVE_MALLOC 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `memset' function. */ +#define HAVE_MEMSET 1 + +/* Define to 1 if you have the `select' function. */ +#define HAVE_SELECT 1 + +/* Define to 1 if you have the `socket' function. */ +#define HAVE_SOCKET 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the `strnlen' function. */ +#define HAVE_STRNLEN 1 + +/* Define to 1 if you have the `strrchr' function. */ +#define HAVE_STRRCHR 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_TIME_H 1 + +#if defined(_MSC_VER) && (_MSC_VER < 1900) && !defined(snprintf) +#define snprintf _snprintf +#endif + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "libcoap-developers@lists.sourceforge.net" + +/* 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.2" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "libcoap" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "https://libcoap.net/" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "4.1.2" + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +/* # undef WORDS_BIGENDIAN */ +# endif +#endif + +/* Define this to 1 for ancillary data on MacOS */ +/* #undef __APPLE_USE_RFC_3542 */ + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ + +/* Define to `int' if does not define. */ +/* #undef ssize_t */ + +#endif + +#endif /* _COAP_CONFIG_H_ */ diff --git a/examples/client.c b/examples/client.c index 86902c7b39..5c6483a72a 100644 --- a/examples/client.c +++ b/examples/client.c @@ -8,20 +8,23 @@ * use. */ -#include "coap_config.h" - #include #include -#include #include #include -#include #include #include +#ifdef _WIN32 +#define strcasecmp _stricmp +#include "getopt.c" +#else +#include +#include #include #include #include #include +#endif #include "coap.h" #include "coap_list.h" @@ -61,7 +64,9 @@ 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)) @@ -144,7 +149,7 @@ coap_new_request(coap_context_t *ctx, pdu->hdr->id = coap_new_message_id(ctx); pdu->hdr->code = m; - pdu->hdr->token_length = the_token.length; + pdu->hdr->token_length = (uint16_t)the_token.length; if ( !coap_add_token(pdu, the_token.length, the_token.s)) { debug("cannot add token to request\n"); } @@ -1140,11 +1145,12 @@ main(int argc, char **argv) { log_level = strtol(optarg, NULL, 10); break; default: - usage( argv[0], PACKAGE_VERSION ); + usage( argv[0], LIBCOAP_PACKAGE_VERSION ); exit( 1 ); } } + coap_startup(); coap_set_log_level(log_level); if (optind < argc) { @@ -1153,7 +1159,7 @@ main(int argc, char **argv) { exit(1); } } else { - usage( argv[0], PACKAGE_VERSION ); + usage( argv[0], LIBCOAP_PACKAGE_VERSION ); exit( 1 ); } @@ -1258,22 +1264,29 @@ main(int argc, char **argv) { if (nextpdu && nextpdu->t < min(obs_wait ? obs_wait : max_wait, max_wait) - now) { /* set timeout if there is a pdu to send */ tv.tv_usec = ((nextpdu->t) % COAP_TICKS_PER_SECOND) * 1000000 / COAP_TICKS_PER_SECOND; - tv.tv_sec = (nextpdu->t) / COAP_TICKS_PER_SECOND; + tv.tv_sec = (long)((nextpdu->t) / COAP_TICKS_PER_SECOND); } else { /* check if obs_wait fires before max_wait */ if (obs_wait && obs_wait < max_wait) { tv.tv_usec = ((obs_wait - now) % COAP_TICKS_PER_SECOND) * 1000000 / COAP_TICKS_PER_SECOND; - tv.tv_sec = (obs_wait - now) / COAP_TICKS_PER_SECOND; + tv.tv_sec = (long)((obs_wait - now) / COAP_TICKS_PER_SECOND); } else { tv.tv_usec = ((max_wait - now) % COAP_TICKS_PER_SECOND) * 1000000 / COAP_TICKS_PER_SECOND; - tv.tv_sec = (max_wait - now) / COAP_TICKS_PER_SECOND; + tv.tv_sec = (long)((max_wait - now) / COAP_TICKS_PER_SECOND); } } result = select(ctx->sockfd + 1, &readfds, 0, 0, &tv); if ( result < 0 ) { /* error */ +#ifdef _WIN32 + char *szErrorMsg = NULL; + FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, (DWORD)WSAGetLastError(), MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), (LPSTR)&szErrorMsg, 0, NULL ); + fprintf( stderr, "select: %s\n", szErrorMsg ); + LocalFree( szErrorMsg ); +#else perror("select"); +#endif } else if ( result > 0 ) { /* read from socket */ if ( FD_ISSET( ctx->sockfd, &readfds ) ) { coap_read( ctx ); /* read received data */ @@ -1300,6 +1313,7 @@ main(int argc, char **argv) { coap_delete_list(optlist); coap_free_context( ctx ); + coap_cleanup(); return 0; } diff --git a/examples/coap-rd.c b/examples/coap-rd.c index 64f156f2d6..c6e7c4f243 100644 --- a/examples/coap-rd.c +++ b/examples/coap-rd.c @@ -19,21 +19,25 @@ #include #include -#include #include #include -#include #include +#include +#include +#include +#ifdef _WIN32 +#define strcasecmp _stricmp +#include "getopt.c" +#else +#include +#include #include #include #include #include -#include #include -#include -#include +#endif -#include "coap_config.h" #include "utlist.h" #include "resource.h" #include "coap.h" @@ -623,8 +627,8 @@ join(coap_context_t *ctx, char *group_name) { hints.ai_socktype = SOCK_DGRAM; result = getaddrinfo("::", NULL, &hints, &reslocal); - if ( result < 0 ) { - perror("join: cannot resolve link-local interface"); + if ( result != 0 ) { + fprintf( stderr, "join: cannot resolve link-local interface: %s\n", gai_strerror( result ) ); goto finish; } @@ -644,8 +648,8 @@ join(coap_context_t *ctx, char *group_name) { /* resolve the multicast group address */ result = getaddrinfo(group_name, NULL, &hints, &resmulti); - if ( result < 0 ) { - perror("join: cannot resolve multicast address"); + if ( result != 0 ) { + fprintf( stderr, "join: cannot resolve multicast address: %s\n", gai_strerror( result ) ); goto finish; } @@ -660,8 +664,16 @@ join(coap_context_t *ctx, char *group_name) { result = setsockopt(ctx->sockfd, IPPROTO_IPV6, IPV6_JOIN_GROUP, (char *)&mreq, sizeof(mreq) ); - if ( result < 0 ) + if ( result < 0 ) { +#ifdef _WIN32 + char *szErrorMsg = NULL; + FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, (DWORD)WSAGetLastError(), MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), (LPSTR)&szErrorMsg, 0, NULL ); + fprintf( stderr, "join: setsockopt: %s\n", szErrorMsg ); + LocalFree( szErrorMsg ); +#else perror("join: setsockopt"); +#endif + } finish: freeaddrinfo(resmulti); @@ -701,11 +713,12 @@ main(int argc, char **argv) { log_level = strtol(optarg, NULL, 10); break; default: - usage( argv[0], PACKAGE_VERSION ); + usage( argv[0], LIBCOAP_PACKAGE_VERSION ); exit( 1 ); } } + coap_startup(); coap_set_log_level(log_level); ctx = get_context(addr_str, port_str); @@ -735,7 +748,7 @@ main(int argc, char **argv) { /* set timeout if there is a pdu to send before our automatic timeout occurs */ tv.tv_usec = ((nextpdu->t - now) % COAP_TICKS_PER_SECOND) * 1000000 / COAP_TICKS_PER_SECOND; - tv.tv_sec = (nextpdu->t - now) / COAP_TICKS_PER_SECOND; + tv.tv_sec = (long)((nextpdu->t - now) / COAP_TICKS_PER_SECOND); timeout = &tv; } else { tv.tv_usec = 0; @@ -745,8 +758,15 @@ main(int argc, char **argv) { result = select( FD_SETSIZE, &readfds, 0, 0, timeout ); if ( result < 0 ) { /* error */ +#ifdef _WIN32 + char *szErrorMsg = NULL; + FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, (DWORD)WSAGetLastError(), MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), (LPSTR)&szErrorMsg, 0, NULL ); + fprintf( stderr, "select: %s\n", szErrorMsg ); + LocalFree( szErrorMsg ); +#else if (errno != EINTR) perror("select"); +#endif } else if ( result > 0 ) { /* read from socket */ if ( FD_ISSET( ctx->sockfd, &readfds ) ) { coap_read( ctx ); /* read received data */ @@ -758,6 +778,7 @@ main(int argc, char **argv) { } coap_free_context( ctx ); + coap_cleanup(); return 0; } diff --git a/examples/coap-server.c b/examples/coap-server.c index e5ee36f2ca..cf2e650931 100644 --- a/examples/coap-server.c +++ b/examples/coap-server.c @@ -11,21 +11,25 @@ #include #include -#include #include #include -#include #include +#include +#include +#include +#ifdef _WIN32 +#define strcasecmp _stricmp +#include "getopt.c" +#else +#include +#include #include #include #include #include -#include #include -#include -#include +#endif -#include "coap_config.h" #include "resource.h" #include "coap.h" @@ -395,7 +399,7 @@ join(coap_context_t *ctx, char *group_name){ hints.ai_socktype = SOCK_DGRAM; result = getaddrinfo("::", NULL, &hints, &reslocal); - if (result < 0) { + if (result != 0) { fprintf(stderr, "join: cannot resolve link-local interface: %s\n", gai_strerror(result)); goto finish; @@ -417,7 +421,7 @@ join(coap_context_t *ctx, char *group_name){ /* resolve the multicast group address */ result = getaddrinfo(group_name, NULL, &hints, &resmulti); - if (result < 0) { + if (result != 0) { fprintf(stderr, "join: cannot resolve multicast address: %s\n", gai_strerror(result)); goto finish; @@ -433,8 +437,16 @@ join(coap_context_t *ctx, char *group_name){ result = setsockopt(ctx->sockfd, IPPROTO_IPV6, IPV6_JOIN_GROUP, (char *)&mreq, sizeof(mreq)); - if (result < 0) + if (result < 0) { +#ifdef _WIN32 + char *szErrorMsg = NULL; + FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, (DWORD)WSAGetLastError(), MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), (LPSTR)&szErrorMsg, 0, NULL ); + fprintf( stderr, "join: setsockopt: %s\n", szErrorMsg ); + LocalFree( szErrorMsg ); +#else perror("join: setsockopt"); +#endif + } finish: freeaddrinfo(resmulti); @@ -476,11 +488,12 @@ main(int argc, char **argv) { log_level = strtol(optarg, NULL, 10); break; default: - usage( argv[0], PACKAGE_VERSION ); + usage( argv[0], LIBCOAP_PACKAGE_VERSION ); exit( 1 ); } } + coap_startup(); coap_set_log_level(log_level); ctx = get_context(addr_str, port_str); @@ -510,7 +523,7 @@ main(int argc, char **argv) { if (nextpdu && nextpdu->t <= (COAP_RESOURCE_CHECK_TIME * COAP_TICKS_PER_SECOND)) { /* set timeout if there is a pdu to send before our automatic timeout occurs */ tv.tv_usec = ((nextpdu->t) % COAP_TICKS_PER_SECOND) * 1000000 / COAP_TICKS_PER_SECOND; - tv.tv_sec = (nextpdu->t) / COAP_TICKS_PER_SECOND; + tv.tv_sec = (long)((nextpdu->t) / COAP_TICKS_PER_SECOND); timeout = &tv; } else { tv.tv_usec = 0; @@ -520,8 +533,15 @@ main(int argc, char **argv) { result = select( FD_SETSIZE, &readfds, 0, 0, timeout ); if ( result < 0 ) { /* error */ +#ifdef _WIN32 + char *szErrorMsg = NULL; + FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, (DWORD)WSAGetLastError(), MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), (LPSTR)&szErrorMsg, 0, NULL ); + fprintf( stderr, "select: %s\n", szErrorMsg ); + LocalFree( szErrorMsg ); +#else if (errno != EINTR) perror("select"); +#endif } else if ( result > 0 ) { /* read from socket */ if ( FD_ISSET( ctx->sockfd, &readfds ) ) { coap_read( ctx ); /* read received data */ @@ -545,6 +565,7 @@ main(int argc, char **argv) { } coap_free_context(ctx); + coap_cleanup(); return 0; } diff --git a/examples/coap_list.c b/examples/coap_list.c index 06e59168d9..2dd68d9470 100644 --- a/examples/coap_list.c +++ b/examples/coap_list.c @@ -13,6 +13,7 @@ #include #include +#include "libcoap.h" #include "debug.h" #include "mem.h" #include "coap_list.h" diff --git a/examples/getopt.c b/examples/getopt.c new file mode 100644 index 0000000000..6e09eeb6bb --- /dev/null +++ b/examples/getopt.c @@ -0,0 +1,66 @@ +/* + * This file was copied from the following newsgroup posting: + * + * Newsgroups: mod.std.unix + * Subject: public domain AT&T getopt source + * Date: 3 Nov 85 19:34:15 GMT + * + * Here's something you've all been waiting for: the AT&T public domain + * source for getopt(3). It is the code which was given out at the 1985 + * UNIFORUM conference in Dallas. I obtained it by electronic mail + * directly from AT&T. The people there assure me that it is indeed + * in the public domain. + */ + +#include +#include + +static int opterr = 1; +static int optind = 1; +static int optopt; +static char *optarg; + +static int getopt(int argc, char *argv[], char *opts) +{ + static int sp = 1; + int c; + char *cp; + + if (sp == 1) { + if (optind >= argc || + argv[optind][0] != '-' || argv[optind][1] == '\0') + return EOF; + else if (!strcmp(argv[optind], "--")) { + optind++; + return EOF; + } + } + optopt = c = argv[optind][sp]; + if (c == ':' || !(cp = strchr(opts, c))) { + fprintf(stderr, ": illegal option -- %c\n", c); + if (argv[optind][++sp] == '\0') { + optind++; + sp = 1; + } + return '?'; + } + if (*++cp == ':') { + if (argv[optind][sp+1] != '\0') + optarg = &argv[optind++][sp+1]; + else if(++optind >= argc) { + fprintf(stderr, ": option requires an argument -- %c\n", c); + sp = 1; + return '?'; + } else + optarg = argv[optind++]; + sp = 1; + } else { + if (argv[optind][++sp] == '\0') { + sp = 1; + optind++; + } + optarg = NULL; + } + + return c; +} diff --git a/include/coap/address.h b/include/coap/address.h index 85db2046e3..fb6f4c7c21 100644 --- a/include/coap/address.h +++ b/include/coap/address.h @@ -21,7 +21,8 @@ #include #include "libcoap.h" -#ifdef WITH_LWIP +#if defined(WITH_LWIP) + #include typedef struct coap_address_t { @@ -34,9 +35,9 @@ typedef struct coap_address_t { #define _coap_address_isany_impl(A) ip_addr_isany(&(A)->addr) #define _coap_is_mcast_impl(Address) ip_addr_ismulticast(&(Address)->addr) -#endif /* WITH_LWIP */ -#ifdef WITH_CONTIKI +#elif defined(WITH_CONTIKI) + #include "uip.h" typedef struct coap_address_t { @@ -52,10 +53,10 @@ typedef struct coap_address_t { #define _coap_address_isany_impl(A) 0 #define _coap_is_mcast_impl(Address) uip_is_addr_mcast(&((Address)->addr)) -#endif /* WITH_CONTIKI */ -#ifdef WITH_POSIX -/** multi-purpose address abstraction */ +#else /* WITH_LWIP || WITH_CONTIKI */ + + /** multi-purpose address abstraction */ typedef struct coap_address_t { socklen_t size; /**< size of addr */ union { @@ -73,7 +74,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) { @@ -89,7 +90,7 @@ _coap_address_isany_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 @@ -98,23 +99,23 @@ _coap_address_isany_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); @@ -126,27 +127,28 @@ 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); } -#ifdef WITH_POSIX +#if !defined(WITH_LWIP) && !defined(WITH_CONTIKI) + /** * Checks if given address @p a denotes a multicast address. This function * returns @c 1 if @p a is multicast, @c 0 otherwise. */ int coap_is_mcast(const coap_address_t *a); -#else /* WITH_POSIX */ +#else /* !WITH_LWIP && !WITH_CONTIKI */ /** * 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); } -#endif /* WITH_POSIX */ +#endif /* !WITH_LWIP && !WITH_CONTIKI */ #endif /* _COAP_ADDRESS_H_ */ diff --git a/include/coap/async.h b/include/coap/async.h index 0c36defacd..3fbcc09f52 100644 --- a/include/coap/async.h +++ b/include/coap/async.h @@ -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); } /** @} */ diff --git a/include/coap/bits.h b/include/coap/bits.h index 0b269166d5..1397dde169 100644 --- a/include/coap/bits.h +++ b/include/coap/bits.h @@ -28,9 +28,9 @@ * * @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)) + if (size <= ((size_t)bit >> 3)) return -1; *(vec + (bit >> 3)) |= (uint8_t)(1 << (bit & 0x07)); @@ -48,9 +48,9 @@ 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)) + if (size <= ((size_t)bit >> 3)) return -1; *(vec + (bit >> 3)) &= (uint8_t)(~(1 << (bit & 0x07))); @@ -67,9 +67,9 @@ 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)) + if (size <= ((size_t)bit >> 3)) return -1; return (*(vec + (bit >> 3)) & (1 << (bit & 0x07))) != 0; diff --git a/include/coap/block.h b/include/coap/block.h index 9ce00311cc..9535e29bb2 100644 --- a/include/coap/block.h +++ b/include/coap/block.h @@ -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; diff --git a/include/coap/coap.h.windows b/include/coap/coap.h.windows new file mode 100644 index 0000000000..e6d3df81ad --- /dev/null +++ b/include/coap/coap.h.windows @@ -0,0 +1,59 @@ +/* + * coap.h -- main header file for CoAP stack of libcoap + * + * Copyright (C) 2010-2012,2015-2016 Olaf Bergmann + * 2015 Carsten Schoenert + * + * This file is part of the CoAP library libcoap. Please see README for terms + * of use. + */ + +#ifndef _COAP_H_ +#define _COAP_H_ + +#include "libcoap.h" + +/* Define the address where bug reports for libcoap should be sent. */ +#define LIBCOAP_PACKAGE_BUGREPORT "libcoap-developers@lists.sourceforge.net" + +/* Define the full name of libcoap. */ +#define LIBCOAP_PACKAGE_NAME "libcoap" + +/* Define the full name and version of libcoap. */ +#define LIBCOAP_PACKAGE_STRING "libcoap 4.1.2" + +/* Define the home page for libcoap. */ +#define LIBCOAP_PACKAGE_URL "https://libcoap.net/" + +/* Define the version of libcoap this file belongs to. */ +#define LIBCOAP_PACKAGE_VERSION "4.1.2" + +#ifdef __cplusplus +extern "C" { +#endif + +#include "address.h" +#include "async.h" +#include "bits.h" +#include "block.h" +#include "coap_io.h" +#include "coap_time.h" +#include "debug.h" +#include "encode.h" +#include "mem.h" +#include "net.h" +#include "option.h" +#include "pdu.h" +#include "prng.h" +#include "resource.h" +#include "str.h" +#include "subscribe.h" +#include "uri.h" +#include "uthash.h" +#include "utlist.h" + +#ifdef __cplusplus +} +#endif + +#endif /* _COAP_H_ */ diff --git a/include/coap/coap_io.h b/include/coap/coap_io.h index 9996fb3d68..9f2b22be5b 100644 --- a/include/coap/coap_io.h +++ b/include/coap/coap_io.h @@ -15,10 +15,16 @@ #include "address.h" -#ifdef HAVE_WS2TCPIP_H +#ifdef _WIN32 typedef SOCKET coap_socket_t; +#define coap_closesocket closesocket +#define COAP_SOCKET_ERROR SOCKET_ERROR +#define COAP_INVALID_SOCKET INVALID_SOCKET #else typedef int coap_socket_t; +#define coap_closesocket close +#define COAP_SOCKET_ERROR (-1) +#define COAP_INVALID_SOCKET (-1) #endif /** @@ -39,12 +45,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) +#if !defined(WITH_LWIP) union { coap_socket_t fd; /**< on POSIX, Contiki and Windows systems */ void *conn; /**< opaque connection (e.g. uip_conn in Contiki) */ } handle; /**< opaque handle to identify this endpoint */ -#endif /* WITH_POSIX or WITH_CONTIKI */ +#endif /* !WITH_LWIP */ #ifdef WITH_LWIP struct udp_pcb *pcb; @@ -146,7 +152,7 @@ struct coap_packet_t { coap_if_handle_t hnd; /**< the interface handle */ coap_address_t src; /**< the packet's source address */ coap_address_t dst; /**< the packet's destination address */ - const coap_endpoint_t *interface; + const coap_endpoint_t *endpoint; int ifindex; void *session; /**< opaque session data */ size_t length; /**< length of payload */ diff --git a/include/coap/coap_time.h b/include/coap/coap_time.h index 9357e5ff7d..52cc098a0e 100644 --- a/include/coap/coap_time.h +++ b/include/coap/coap_time.h @@ -21,7 +21,7 @@ * @{ */ -#ifdef WITH_LWIP +#if defined(WITH_LWIP) #include #include @@ -33,22 +33,22 @@ 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 -#ifdef WITH_CONTIKI +#elif defined(WITH_CONTIKI) + #include "clock.h" typedef clock_time_t coap_tick_t; @@ -63,25 +63,26 @@ 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 +#else +#include + /** * This data type represents internal timer ticks with COAP_TICKS_PER_SECOND * resolution. */ -typedef unsigned long coap_tick_t; +typedef uint64_t coap_tick_t; /** * CoAP time in seconds since epoch. @@ -93,7 +94,7 @@ typedef time_t coap_time_t; * values. This data type must have the same size in memory as coap_tick_t to * allow wrapping. */ -typedef long coap_tick_diff_t; +typedef int64_t coap_tick_diff_t; /** Use ms resolution on POSIX systems */ #define COAP_TICKS_PER_SECOND 1000 @@ -119,13 +120,13 @@ 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 /** * 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; } @@ -133,7 +134,7 @@ static inline int coap_time_lt(coap_tick_t a, coap_tick_t b) { * 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); } diff --git a/include/coap/encode.h b/include/coap/encode.h index f17fe659d5..5a4f28c03a 100644 --- a/include/coap/encode.h +++ b/include/coap/encode.h @@ -10,7 +10,7 @@ #ifndef _COAP_ENCODE_H_ #define _COAP_ENCODE_H_ -#if (BSD >= 199103) || defined(WITH_CONTIKI) +#if (BSD >= 199103) || defined(WITH_CONTIKI) || defined(_WIN32) # include #else # include diff --git a/include/coap/libcoap.h b/include/coap/libcoap.h index 214b9e235e..cceac9c273 100644 --- a/include/coap/libcoap.h +++ b/include/coap/libcoap.h @@ -18,9 +18,30 @@ * * The CONTIKI variable is within the Contiki build environment! */ -#if !defined (CONTIKI) +#if defined(_WIN32) +#pragma comment(lib,"Ws2_32.lib") +#include +typedef SSIZE_T ssize_t; +typedef USHORT in_port_t; +#elif !defined (CONTIKI) #include #include #endif /* CONTIKI */ +#ifndef COAP_STATIC_INLINE +# if defined(__cplusplus) +# define COAP_STATIC_INLINE inline +# else +# if defined(_MSC_VER) +# define COAP_STATIC_INLINE static __inline +# else +# define COAP_STATIC_INLINE static inline +# endif +# endif +#endif + +void coap_startup(); + +void coap_cleanup(); + #endif /* _LIBCOAP_H_ */ diff --git a/include/coap/mem.h b/include/coap/mem.h index fd3c69aafd..f4bfce5d8a 100644 --- a/include/coap/mem.h +++ b/include/coap/mem.h @@ -67,14 +67,14 @@ void coap_free_type(coap_memory_tag_t type, void *p); /** * Wrapper function to coap_malloc_type() for backwards compatibility. */ -static inline void *coap_malloc(size_t size) { +COAP_STATIC_INLINE void *coap_malloc(size_t size) { return coap_malloc_type(COAP_STRING, size); } /** * Wrapper function to coap_free_type() for backwards compatibility. */ -static inline void coap_free(void *object) { +COAP_STATIC_INLINE void coap_free(void *object) { coap_free_type(COAP_STRING, object); } @@ -86,7 +86,7 @@ static inline void coap_free(void *object) { /* no initialization needed with lwip (or, more precisely: lwip must be * completely initialized anyway by the time coap gets active) */ -static inline void coap_memory_init(void) {} +COAP_STATIC_INLINE void coap_memory_init(void) {} /* It would be nice to check that size equals the size given at the memp * declaration, but i currently don't see a standard way to check that without @@ -98,11 +98,11 @@ static inline void coap_memory_init(void) {} /* Those are just here to make uri.c happy where string allocation has not been * made conditional. */ -static inline void *coap_malloc(size_t size) { +COAP_STATIC_INLINE void *coap_malloc(size_t size) { LWIP_ASSERT("coap_malloc must not be used in lwIP", 0); } -static inline void coap_free(void *pointer) { +COAP_STATIC_INLINE void coap_free(void *pointer) { LWIP_ASSERT("coap_free must not be used in lwIP", 0); } diff --git a/include/coap/net.h b/include/coap/net.h index 014b4903ab..c629c97971 100644 --- a/include/coap/net.h +++ b/include/coap/net.h @@ -13,7 +13,9 @@ #include #include #include +#ifndef _WIN32 #include +#endif #include #ifdef WITH_LWIP @@ -90,9 +92,9 @@ typedef struct coap_context_t { coap_queue_t *sendqueue; coap_endpoint_t *endpoint; /**< the endpoint used for listening */ -#ifdef WITH_POSIX - int sockfd; /**< send/receive socket */ -#endif /* WITH_POSIX */ +#if !defined(WITH_CONTIKI) && !defined(WITH_LWIP) + coap_socket_t sockfd; /**< send/receive socket */ +#endif #ifdef WITH_CONTIKI struct uip_udp_conn *conn; /**< uIP connection object */ @@ -137,7 +139,7 @@ typedef struct coap_context_t { * @param context The context to register the handler for. * @param handler The response handler to register. */ -static inline void +COAP_STATIC_INLINE void coap_register_response_handler(coap_context_t *context, coap_response_handler_t handler) { context->response_handler = handler; @@ -149,7 +151,7 @@ coap_register_response_handler(coap_context_t *context, * @param ctx The context to use. * @param type The option type to register. */ -inline static void +COAP_STATIC_INLINE void coap_register_option(coap_context_t *ctx, unsigned char type) { coap_option_setb(ctx->known_options, type); } @@ -185,7 +187,7 @@ coap_context_t *coap_new_context(const coap_address_t *listen_addr); * * @return Incremented message id in network byte order. */ -static inline unsigned short +COAP_STATIC_INLINE unsigned short coap_new_message_id(coap_context_t *context) { context->message_id++; #ifndef WITH_CONTIKI @@ -342,7 +344,7 @@ coap_tid_t coap_send_ack(coap_context_t *context, * @return The transaction id if RST was sent or @c * COAP_INVALID_TID on error. */ -static inline coap_tid_t +COAP_STATIC_INLINE coap_tid_t coap_send_rst(coap_context_t *context, const coap_endpoint_t *local_interface, const coap_address_t *dst, @@ -420,7 +422,7 @@ int coap_remove_from_queue(coap_queue_t **queue, * * @return @c 1 if node was found, removed and destroyed, @c 0 otherwise. */ -inline static int +COAP_STATIC_INLINE int coap_remove_transaction(coap_queue_t **queue, coap_tid_t id) { coap_queue_t *node; if (!coap_remove_from_queue(queue, id, &node)) diff --git a/include/coap/option.h b/include/coap/option.h index ace2b81c71..a87b0529e5 100644 --- a/include/coap/option.h +++ b/include/coap/option.h @@ -142,7 +142,7 @@ typedef uint16_t coap_opt_filter_t[COAP_OPT_FILTER_SIZE]; * * @param f The filter to clear. */ -static inline void +COAP_STATIC_INLINE void coap_option_filter_clear(coap_opt_filter_t f) { memset(f, 0, sizeof(coap_opt_filter_t)); } @@ -195,7 +195,7 @@ int coap_option_filter_get(const coap_opt_filter_t filter, unsigned short type); * * @return @c 1 if bit was set, @c -1 otherwise. */ -inline static int +COAP_STATIC_INLINE int coap_option_setb(coap_opt_filter_t filter, unsigned short type) { return coap_option_filter_set(filter, type) ? 1 : -1; } @@ -212,7 +212,7 @@ coap_option_setb(coap_opt_filter_t filter, unsigned short type) { * * @return @c 1 if bit was set, @c -1 otherwise. */ -inline static int +COAP_STATIC_INLINE int coap_option_clrb(coap_opt_filter_t filter, unsigned short type) { return coap_option_filter_unset(filter, type) ? 1 : -1; } @@ -229,7 +229,7 @@ coap_option_clrb(coap_opt_filter_t filter, unsigned short type) { * * @return @c 1 if bit was set, @c 0 if not, @c -1 on error. */ -inline static int +COAP_STATIC_INLINE int coap_option_getb(const coap_opt_filter_t filter, unsigned short type) { return coap_option_filter_get(filter, type); } diff --git a/include/coap/pdu.h b/include/coap/pdu.h index 2ac55b97e9..e6c05b61b8 100644 --- a/include/coap/pdu.h +++ b/include/coap/pdu.h @@ -174,7 +174,20 @@ typedef int coap_tid_t; */ #define COAP_DROPPED_RESPONSE -2 -#ifdef WORDS_BIGENDIAN +#if defined(_MSC_VER) +#include +#pragma pack( push, 1 ) +typedef struct { + uint16_t token_length : 4; /* length of Token */ + uint16_t type : 2; /* type flag */ + uint16_t version : 2; /* protocol version */ + uint16_t code : 8; /* request method (value 1--10) or response + code (value 40-255) */ + uint16_t id; /* transaction id (network byte order!) */ + uint8_t token[]; /* the actual token, if any */ +} coap_hdr_t; +#pragma pack( pop ) +#elif defined(WORDS_BIGENDIAN) typedef struct { unsigned int version:2; /* protocol version */ unsigned int type:2; /* type flag */ diff --git a/include/coap/prng.h b/include/coap/prng.h index da6d953440..373dc1787e 100644 --- a/include/coap/prng.h +++ b/include/coap/prng.h @@ -20,23 +20,7 @@ * @{ */ -#if defined(WITH_POSIX) || (defined(WITH_LWIP) && !defined(LWIP_RAND)) -#include - -/** - * Fills \p buf with \p len random bytes. This is the default implementation for - * prng(). You might want to change prng() to use a better PRNG on your specific - * platform. - */ -static inline int -coap_prng_impl(unsigned char *buf, size_t len) { - while (len--) - *buf++ = rand() & 0xFF; - return 1; -} -#endif /* WITH_POSIX */ - -#ifdef WITH_CONTIKI +#if defined(WITH_CONTIKI) #include /** @@ -44,7 +28,7 @@ coap_prng_impl(unsigned char *buf, size_t len) { * prng(). You might want to change prng() to use a better PRNG on your specific * platform. */ -static inline int +COAP_STATIC_INLINE int contiki_prng_impl(unsigned char *buf, size_t len) { unsigned short v = random_rand(); while (len > sizeof(v)) { @@ -60,10 +44,8 @@ contiki_prng_impl(unsigned char *buf, size_t len) { #define prng(Buf,Length) contiki_prng_impl((Buf), (Length)) #define prng_init(Value) random_init((unsigned short)(Value)) -#endif /* WITH_CONTIKI */ - -#if defined(WITH_LWIP) && defined(LWIP_RAND) -static inline int +#elif defined(WITH_LWIP) && defined(LWIP_RAND) +COAP_STATIC_INLINE int lwip_prng_impl(unsigned char *buf, size_t len) { u32_t v = LWIP_RAND(); while (len > sizeof(v)) { @@ -79,8 +61,22 @@ lwip_prng_impl(unsigned char *buf, size_t len) { #define prng(Buf,Length) lwip_prng_impl((Buf), (Length)) #define prng_init(Value) +#else +#include + + /** + * Fills \p buf with \p len random bytes. This is the default implementation for + * prng(). You might want to change prng() to use a better PRNG on your specific + * platform. + */ +COAP_STATIC_INLINE int +coap_prng_impl( unsigned char *buf, size_t len ) { + while ( len-- ) + *buf++ = rand() & 0xFF; + return 1; +} +#endif -#endif /* WITH_LWIP */ #ifndef prng /** diff --git a/include/coap/resource.h b/include/coap/resource.h index dbb19a8d1f..f8b8754fa6 100644 --- a/include/coap/resource.h +++ b/include/coap/resource.h @@ -126,7 +126,7 @@ coap_resource_t *coap_resource_init(const unsigned char *uri, * @p mode which must be one of @c COAP_RESOURCE_FLAGS_NOTIFY_NON * or @c COAP_RESOURCE_FLAGS_NOTIFY_CON. */ -static inline void +COAP_STATIC_INLINE void coap_resource_set_mode(coap_resource_t *r, int mode) { r->flags = (r->flags & !COAP_RESOURCE_FLAGS_NOTIFY_CON) | mode; } @@ -255,7 +255,7 @@ coap_print_status_t coap_print_link(const coap_resource_t *resource, * @param method The CoAP request method to handle. * @param handler The handler to register with @p resource. */ -static inline void +COAP_STATIC_INLINE void coap_register_handler(coap_resource_t *resource, unsigned char method, coap_method_handler_t handler) { diff --git a/include/coap/utlist.h b/include/coap/utlist.h index b5f3f04c10..cbaf66f3eb 100644 --- a/include/coap/utlist.h +++ b/include/coap/utlist.h @@ -111,6 +111,7 @@ do { LDECLTYPE(list) _ls_q; \ LDECLTYPE(list) _ls_e; \ LDECLTYPE(list) _ls_tail; \ + LDECLTYPE(list) _tmp; \ int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \ if (list) { \ _ls_insize = 1; \ @@ -174,6 +175,7 @@ do { LDECLTYPE(list) _ls_q; \ LDECLTYPE(list) _ls_e; \ LDECLTYPE(list) _ls_tail; \ + LDECLTYPE(list) _tmp; \ int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \ if (list) { \ _ls_insize = 1; \ diff --git a/src/address.c b/src/address.c index b4db76f031..8d7c98da35 100644 --- a/src/address.c +++ b/src/address.c @@ -6,11 +6,24 @@ * README for terms of use. */ -#ifdef WITH_POSIX +#include "coap_config.h" + +#if !defined(WITH_CONTIKI) && !defined(WITH_LWIP) +#ifdef HAVE_ASSERT_H #include +#endif +#ifdef HAVE_ARPA_INET_H #include +#endif +#ifdef HAVE_NETINET_IN_H #include +#endif +#ifdef HAVE_SYS_SOCKET_H #include +#endif +#ifdef HAVE_WS2TCPIP_H +#include +#endif #include "address.h" @@ -52,12 +65,11 @@ int coap_is_mcast(const coap_address_t *a) { } return 0; } -#else /* WITH_POSIX */ +#else /* !defined(WITH_CONTIKI) && !defined(WITH_LWIP) */ /* make compilers happy that do not like empty modules */ -static inline void dummy() +COAP_STATIC_INLINE void dummy() { } -#endif /* not WITH_POSIX */ - +#endif /* !defined(WITH_CONTIKI) && !defined(WITH_LWIP) */ diff --git a/src/block.c b/src/block.c index c48674728a..69fe9e9c16 100644 --- a/src/block.c +++ b/src/block.c @@ -12,6 +12,7 @@ # include #endif +#include "libcoap.h" #include "debug.h" #include "block.h" @@ -19,7 +20,9 @@ #error "COAP_MAX_BLOCK_SZX too large" #endif +#ifndef min #define min(a,b) ((a) < (b) ? (a) : (b)) +#endif #ifndef WITHOUT_BLOCK unsigned int @@ -49,7 +52,7 @@ coap_get_block(coap_pdu_t *pdu, unsigned short type, coap_block_t *block) { assert(block); memset(block, 0, sizeof(coap_block_t)); - if (pdu && (option = coap_check_option(pdu, type, &opt_iter))) { + if (pdu && (option = coap_check_option(pdu, type, &opt_iter)) != NULL) { unsigned int num; block->szx = COAP_OPT_BLOCK_SZX(option); diff --git a/src/coap_io.c b/src/coap_io.c index 44a9639677..08d55b9e7d 100644 --- a/src/coap_io.c +++ b/src/coap_io.c @@ -17,27 +17,36 @@ #endif #ifdef HAVE_SYS_SOCKET_H # include +# define OPTVAL_T(t) (t) #endif #ifdef HAVE_NETINET_IN_H # include #endif +#ifdef HAVE_WS2TCPIP_H +#include +# define OPTVAL_T(t) (const char*)(t) +# undef CMSG_DATA +# define CMSG_DATA WSA_CMSG_DATA +#endif #ifdef HAVE_SYS_UIO_H # include -#endif +#endif #ifdef HAVE_UNISTD_H # include -#endif +#endif #include #ifdef WITH_CONTIKI # include "uip.h" #endif +#include "libcoap.h" #include "debug.h" #include "mem.h" #include "coap_io.h" +#include "pdu.h" -#ifdef WITH_POSIX +#if !defined(WITH_CONTIKI) && !defined(WITH_LWIP) /* define generic PKTINFO for IPv4 */ #if defined(IP_PKTINFO) # define GEN_IP_PKTINFO IP_PKTINFO @@ -60,7 +69,7 @@ struct coap_packet_t { coap_if_handle_t hnd; /**< the interface handle */ coap_address_t src; /**< the packet's source address */ coap_address_t dst; /**< the packet's destination address */ - const coap_endpoint_t *interface; + const coap_endpoint_t *endpoint; int ifindex; void *session; /**< opaque session data */ @@ -75,7 +84,7 @@ struct coap_packet_t { #ifdef WITH_CONTIKI static int ep_initialized = 0; -static inline struct coap_endpoint_t * +COAP_STATIC_INLINE struct coap_endpoint_t * coap_malloc_contiki_endpoint() { static struct coap_endpoint_t ep; @@ -87,7 +96,7 @@ coap_malloc_contiki_endpoint() { } } -static inline void +COAP_STATIC_INLINE void coap_free_contiki_endpoint(struct coap_endpoint_t *ep) { ep_initialized = 0; } @@ -124,54 +133,54 @@ coap_free_endpoint(coap_endpoint_t *ep) { } #else /* WITH_CONTIKI */ -static inline struct coap_endpoint_t * +COAP_STATIC_INLINE struct coap_endpoint_t * coap_malloc_posix_endpoint(void) { return (struct coap_endpoint_t *)coap_malloc(sizeof(struct coap_endpoint_t)); } -static inline void +COAP_STATIC_INLINE void coap_free_posix_endpoint(struct coap_endpoint_t *ep) { coap_free(ep); } coap_endpoint_t * coap_new_endpoint(const coap_address_t *addr, int flags) { - int sockfd = socket(addr->addr.sa.sa_family, SOCK_DGRAM, 0); + coap_socket_t sockfd = socket(addr->addr.sa.sa_family, SOCK_DGRAM, 0); int on = 1; struct coap_endpoint_t *ep; - if (sockfd < 0) { + if (sockfd == COAP_INVALID_SOCKET) { coap_log(LOG_WARNING, "coap_new_endpoint: socket"); return NULL; } - if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0) + if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, OPTVAL_T(&on), sizeof(on)) == COAP_SOCKET_ERROR) coap_log(LOG_WARNING, "coap_new_endpoint: setsockopt SO_REUSEADDR"); on = 1; switch(addr->addr.sa.sa_family) { case AF_INET: - if (setsockopt(sockfd, IPPROTO_IP, GEN_IP_PKTINFO, &on, sizeof(on)) < 0) + if (setsockopt(sockfd, IPPROTO_IP, GEN_IP_PKTINFO, OPTVAL_T(&on), sizeof(on)) == COAP_SOCKET_ERROR) coap_log(LOG_ALERT, "coap_new_endpoint: setsockopt IP_PKTINFO\n"); break; case AF_INET6: - if (setsockopt(sockfd, IPPROTO_IPV6, GEN_IPV6_PKTINFO, &on, sizeof(on)) < 0) + if (setsockopt(sockfd, IPPROTO_IPV6, GEN_IPV6_PKTINFO, OPTVAL_T(&on), sizeof(on)) == COAP_SOCKET_ERROR) coap_log(LOG_ALERT, "coap_new_endpoint: setsockopt IPV6_PKTINFO\n"); break; default: coap_log(LOG_ALERT, "coap_new_endpoint: unsupported sa_family\n"); } - if (bind(sockfd, &addr->addr.sa, addr->size) < 0) { + if (bind(sockfd, &addr->addr.sa, addr->size) == COAP_SOCKET_ERROR) { coap_log(LOG_WARNING, "coap_new_endpoint: bind"); - close (sockfd); + coap_closesocket(sockfd); return NULL; } ep = coap_malloc_posix_endpoint(); if (!ep) { coap_log(LOG_WARNING, "coap_new_endpoint: malloc"); - close(sockfd); + coap_closesocket(sockfd); return NULL; } @@ -182,7 +191,7 @@ coap_new_endpoint(const coap_address_t *addr, int flags) { ep->addr.size = addr->size; if (getsockname(sockfd, &ep->addr.addr.sa, &ep->addr.size) < 0) { coap_log(LOG_WARNING, "coap_new_endpoint: cannot determine local address"); - close (sockfd); + coap_closesocket(sockfd); return NULL; } @@ -207,8 +216,8 @@ coap_new_endpoint(const coap_address_t *addr, int flags) { void coap_free_endpoint(coap_endpoint_t *ep) { if(ep) { - if (ep->handle.fd >= 0) - close(ep->handle.fd); + if (ep->handle.fd != COAP_INVALID_SOCKET) + coap_closesocket(ep->handle.fd); coap_free_posix_endpoint((struct coap_endpoint_t *)ep); } } @@ -218,7 +227,7 @@ coap_free_endpoint(coap_endpoint_t *ep) { #ifndef CUSTOM_COAP_NETWORK_SEND -#if defined(WITH_POSIX) != defined(HAVE_NETINET_IN_H) +#if (!defined(WITH_CONTIKI) && !defined(WITH_LWIP)) != ( defined(HAVE_NETINET_IN_H) || defined(HAVE_WS2TCPIP_H) ) /* define struct in6_pktinfo and struct in_pktinfo if not available FIXME: check with configure */ @@ -234,7 +243,7 @@ struct in_pktinfo { }; #endif -#if defined(WITH_POSIX) && !defined(SOL_IP) +#if !defined(WITH_CONTIKI) && !defined(WITH_LWIP) && !defined(SOL_IP) /* Solaris expects level IPPROTO_IP for ancillary data. */ #define SOL_IP IPPROTO_IP #endif @@ -245,6 +254,25 @@ struct in_pktinfo { #define UNUSED_PARAM #endif /* GCC */ +#if defined(_WIN32) +#include +static __declspec( thread ) LPFN_WSARECVMSG lpWSARecvMsg = NULL; +/* Map struct WSABUF fields to their posix counterpart */ +#define msghdr _WSAMSG +#define msg_name name +#define msg_namelen namelen +#define msg_iov lpBuffers +#define msg_iovlen dwBufferCount +#define msg_control Control.buf +#define msg_controllen Control.len +#define iovec _WSABUF +#define iov_base buf +#define iov_len len +#undef CMSG_DATA +#define CMSG_DATA WSA_CMSG_DATA +#define ipi_spec_dst ipi_addr +#endif + ssize_t coap_network_send(struct coap_context_t *context UNUSED_PARAM, const coap_endpoint_t *local_interface, @@ -259,6 +287,10 @@ coap_network_send(struct coap_context_t *context UNUSED_PARAM, /* a buffer large enough to hold all protocol address types */ char buf[CMSG_LEN(sizeof(struct sockaddr_storage))]; (void)context; +#ifdef _WIN32 + DWORD dwNumberOfBytesSent = 0; + int r; +#endif struct msghdr mhdr; struct iovec iov[1]; @@ -341,7 +373,15 @@ coap_network_send(struct coap_context_t *context UNUSED_PARAM, return -1; } +#ifdef _WIN32 + r = WSASendMsg( ep->handle.fd, &mhdr, 0 /*dwFlags*/, &dwNumberOfBytesSent, NULL /*lpOverlapped*/, NULL /*lpCompletionRoutine*/ ); + if ( r == 0 ) + return (ssize_t)dwNumberOfBytesSent; + else + return -1; +#else return sendmsg(ep->handle.fd, &mhdr, 0); +#endif #else /* WITH_CONTIKI */ /* FIXME: untested */ /* FIXME: is there a way to check if send was successful? */ @@ -359,7 +399,7 @@ coap_network_send(struct coap_context_t *context UNUSED_PARAM, #define SIN6(A) ((struct sockaddr_in6 *)(A)) -#ifdef WITH_POSIX +#if !defined(WITH_CONTIKI) && !defined(WITH_LWIP) static coap_packet_t * coap_malloc_packet(void) { coap_packet_t *packet; @@ -376,9 +416,9 @@ void coap_free_packet(coap_packet_t *packet) { coap_free(packet); } -#endif /* WITH_POSIX */ +#endif /* !defined(WITH_CONTIKI) && !defined(WITH_LWIP) */ #ifdef WITH_CONTIKI -static inline coap_packet_t * +COAP_STATIC_INLINE coap_packet_t * coap_malloc_packet(void) { return (coap_packet_t *)coap_malloc_type(COAP_PACKET, 0); } @@ -389,7 +429,7 @@ coap_free_packet(coap_packet_t *packet) { } #endif /* WITH_CONTIKI */ -static inline size_t +COAP_STATIC_INLINE size_t coap_get_max_packetlength(const coap_packet_t *packet) { (void)packet; return COAP_MAX_PDU_SIZE; @@ -398,7 +438,7 @@ coap_get_max_packetlength(const coap_packet_t *packet) { void coap_packet_populate_endpoint(coap_packet_t *packet, coap_endpoint_t *target) { - target->handle = packet->interface->handle; + target->handle = packet->endpoint->handle; memcpy(&target->addr, &packet->dst, sizeof(target->addr)); target->ifindex = packet->ifindex; target->flags = 0; /* FIXME */ @@ -420,7 +460,7 @@ coap_packet_get_memmapped(coap_packet_t *packet, unsigned char **address, size_t * local interface with address @p local. This function returns @c 1 * if @p dst is a valid match, and @c 0 otherwise. */ -static inline int +COAP_STATIC_INLINE int is_local_if(const coap_address_t *local, const coap_address_t *dst) { return coap_address_isany(local) || coap_address_equals(dst, local) || coap_is_mcast(dst); @@ -429,12 +469,16 @@ is_local_if(const coap_address_t *local, const coap_address_t *dst) { ssize_t coap_network_read(coap_endpoint_t *ep, coap_packet_t **packet) { ssize_t len = -1; +#if defined(_WIN32) + DWORD dwNumberOfBytesRecvd = 0; + int r; +#endif -#ifdef WITH_POSIX - char msg_control[CMSG_LEN(sizeof(struct sockaddr_storage))]; +#if !defined(WITH_CONTIKI) && !defined(WITH_LWIP) + char buf[CMSG_LEN(sizeof(struct sockaddr_storage))]; struct msghdr mhdr; struct iovec iov[1]; -#endif /* WITH_POSIX */ +#endif assert(ep); assert(packet); @@ -449,35 +493,57 @@ coap_network_read(coap_endpoint_t *ep, coap_packet_t **packet) { coap_address_init(&(*packet)->dst); /* the local interface address */ coap_address_init(&(*packet)->src); /* the remote peer */ -#ifdef WITH_POSIX +#if !defined(WITH_CONTIKI) && !defined(WITH_LWIP) iov[0].iov_base = (*packet)->payload; iov[0].iov_len = coap_get_max_packetlength(*packet); memset(&mhdr, 0, sizeof(struct msghdr)); - mhdr.msg_name = &(*packet)->src.addr.st; + mhdr.msg_name = (struct sockaddr*)&(*packet)->src.addr.st; mhdr.msg_namelen = sizeof((*packet)->src.addr.st); mhdr.msg_iov = iov; mhdr.msg_iovlen = 1; - mhdr.msg_control = msg_control; - mhdr.msg_controllen = sizeof(msg_control); - assert(sizeof(msg_control) == CMSG_LEN(sizeof(struct sockaddr_storage))); - + mhdr.msg_control = buf; + mhdr.msg_controllen = sizeof(buf); + assert(sizeof(buf) == CMSG_LEN(sizeof(struct sockaddr_storage))); + +#if defined(_WIN32) + if ( !lpWSARecvMsg ) { + GUID wsaid = WSAID_WSARECVMSG; + DWORD cbBytesReturned = 0; + if ( WSAIoctl( ep->handle.fd, SIO_GET_EXTENSION_FUNCTION_POINTER, &wsaid, sizeof( wsaid ), &lpWSARecvMsg, sizeof( lpWSARecvMsg ), &cbBytesReturned, NULL, NULL ) != 0 ) { + coap_log(LOG_WARNING, "coap_network_read: no WSARecvMsg\n"); + return -1; + } + } + r = lpWSARecvMsg( ep->handle.fd, &mhdr, &dwNumberOfBytesRecvd, NULL /* LPWSAOVERLAPPED */, NULL /* LPWSAOVERLAPPED_COMPLETION_ROUTINE */ ); + if ( r == 0 ) { + len = (ssize_t)dwNumberOfBytesRecvd; + } else { + char *szErrorMsg = NULL; + FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, (DWORD)WSAGetLastError(), MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), (LPSTR)&szErrorMsg, 0, NULL ); + coap_log(LOG_WARNING, "coap_network_read: %s\n", szErrorMsg); + LocalFree( szErrorMsg ); + len = -1; + } +#else len = recvmsg(ep->handle.fd, &mhdr, 0); + if ( len < 0 ) + coap_log(LOG_WARNING, "coap_network_read: %s\n", strerror(errno)); +#endif if (len < 0) { - coap_log(LOG_WARNING, "coap_network_read: %s\n", strerror(errno)); goto error; } else { struct cmsghdr *cmsg; - coap_log(LOG_DEBUG, "received %d bytes on fd %d\n", (int)len, ep->handle.fd); + coap_log(LOG_DEBUG, "received %d bytes on fd %d\n", (int)len, (int)ep->handle.fd); /* use getsockname() to get the local port */ (*packet)->dst.size = sizeof((*packet)->dst.addr); - if (getsockname(ep->handle.fd, &(*packet)->dst.addr.sa, &(*packet)->dst.size) < 0) { + if (getsockname(ep->handle.fd, &(*packet)->dst.addr.sa, &(*packet)->dst.size) == COAP_SOCKET_ERROR) { coap_log(LOG_DEBUG, "cannot determine local port\n"); goto error; } @@ -562,7 +628,7 @@ coap_network_read(coap_endpoint_t *ep, coap_packet_t **packet) { goto error; } } -#endif /* WITH_POSIX */ +#endif /* !defined(WITH_CONTIKI) && !defined(WITH_LWIP) */ #ifdef WITH_CONTIKI /* FIXME: untested, make this work */ #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) @@ -612,10 +678,10 @@ coap_network_read(coap_endpoint_t *ep, coap_packet_t **packet) { #error "coap_network_read() not implemented on this platform" #endif - (*packet)->interface = ep; + (*packet)->endpoint = ep; return len; -#if defined(WITH_POSIX) || defined(WITH_CONTIKI) +#if !defined(WITH_LWIP) error: coap_free_packet(*packet); *packet = NULL; diff --git a/src/coap_time.c b/src/coap_time.c index 9e0c860215..e80178ed94 100644 --- a/src/coap_time.c +++ b/src/coap_time.c @@ -6,12 +6,22 @@ * README for terms of use. */ -#ifdef WITH_POSIX +#include "coap_config.h" + +#ifdef HAVE_TIME_H #include +#ifdef HAVE_SYS_TIME_H #include +#endif +#ifdef HAVE_UNISTD_H #include /* _POSIX_TIMERS */ +#endif +#ifdef HAVE_WINSOCK2_H +#include +#include +#endif -#include "coap_config.h" +#include "libcoap.h" #include "coap_time.h" static coap_tick_t coap_clock_offset = 0; @@ -23,6 +33,27 @@ static coap_tick_t coap_clock_offset = 0; #define COAP_CLOCK CLOCK_REALTIME #endif +#ifdef HAVE_WINSOCK2_H +static int +gettimeofday(struct timeval *tp, TIME_ZONE_INFORMATION *tzp) { + (void)tzp; + static const uint64_t s_tUnixEpoch = 116444736000000000Ui64; + + FILETIME file_time; + ULARGE_INTEGER time; + uint64_t tUsSinceUnicEpoch; + + GetSystemTimeAsFileTime( &file_time ); + time.LowPart = file_time.dwLowDateTime; + time.HighPart = file_time.dwHighDateTime; + tUsSinceUnicEpoch = ( time.QuadPart - s_tUnixEpoch ) / 10; + + tp->tv_sec = (long)(tUsSinceUnicEpoch / 1000000); + tp->tv_usec = (long)(tUsSinceUnicEpoch % 1000000); + return 0; +} +#endif + void coap_clock_init(void) { #ifdef COAP_CLOCK @@ -47,7 +78,7 @@ coap_clock_init(void) { void coap_ticks(coap_tick_t *t) { - unsigned long tmp; + coap_tick_t tmp; #ifdef COAP_CLOCK struct timespec tv; @@ -87,12 +118,12 @@ coap_ticks_to_rt(coap_tick_t t) { #undef FRAC #undef SHR_FP -#else /* WITH_POSIX */ +#else /* HAVE_TIME_H */ /* make compilers happy that do not like empty modules */ -static inline void dummy() +COAP_STATIC_INLINE void dummy() { } -#endif /* not WITH_POSIX */ +#endif /* not HAVE_TIME_H */ diff --git a/src/debug.c b/src/debug.c index cc611fe40c..c72c9e07ec 100644 --- a/src/debug.c +++ b/src/debug.c @@ -24,11 +24,15 @@ #ifdef HAVE_ARPA_INET_H #include #endif +#ifdef HAVE_WS2TCPIP_H +#include +#endif #ifdef HAVE_TIME_H #include #endif +#include "libcoap.h" #include "block.h" #include "debug.h" #include "encode.h" @@ -73,7 +77,7 @@ static char *loglevels[] = { #ifdef HAVE_TIME_H -static inline size_t +COAP_STATIC_INLINE size_t print_timestamp(char *s, size_t len, coap_tick_t t) { struct tm *tmp; time_t now = coap_ticks_to_rt(t); @@ -83,7 +87,7 @@ print_timestamp(char *s, size_t len, coap_tick_t t) { #else /* alternative implementation: just print the timestamp */ -static inline size_t +COAP_STATIC_INLINE size_t print_timestamp(char *s, size_t len, coap_tick_t t) { #ifdef HAVE_SNPRINTF return snprintf(s, len, "%u.%03u", @@ -160,7 +164,7 @@ print_readable( const unsigned char *data, size_t len, size_t coap_print_addr(const struct coap_address_t *addr, unsigned char *buf, size_t len) { -#ifdef HAVE_ARPA_INET_H +#if defined( HAVE_ARPA_INET_H ) || defined( HAVE_WS2TCPIP_H ) const void *addrptr = NULL; in_port_t port; unsigned char *p = buf; @@ -364,7 +368,7 @@ print_content_format(unsigned int format_type, * to carry binary data. The return value @c 0 hence indicates * printable data which is also assumed if @p content_format is @c 01. */ -static inline int +COAP_STATIC_INLINE int is_binary(int content_format) { return !(content_format == -1 || content_format == COAP_MEDIATYPE_TEXT_PLAIN || diff --git a/src/mem.c b/src/mem.c index 54f3b5a5ee..a06c4ddb23 100644 --- a/src/mem.c +++ b/src/mem.c @@ -8,6 +8,7 @@ #include "coap_config.h" +#include "libcoap.h" #include "mem.h" #include "debug.h" diff --git a/src/net.c b/src/net.c index a54939587b..2a2ae2d24e 100644 --- a/src/net.c +++ b/src/net.c @@ -19,7 +19,9 @@ #elif HAVE_SYS_UNISTD_H #include #endif +#ifdef HAVE_SYS_TYPES_H #include +#endif #ifdef HAVE_SYS_SOCKET_H #include #endif @@ -29,6 +31,9 @@ #ifdef HAVE_ARPA_INET_H #include #endif +#ifdef HAVE_WS2TCPIP_H +#include +#endif #ifdef WITH_LWIP #include @@ -36,6 +41,7 @@ #include #endif +#include "libcoap.h" #include "debug.h" #include "mem.h" #include "str.h" @@ -113,20 +119,20 @@ /** creates a Qx.FRAC_BITS from COAP_DEFAULT_ACK_TIMEOUT */ #define ACK_TIMEOUT Q(FRAC_BITS, COAP_DEFAULT_ACK_TIMEOUT) -#if defined(WITH_POSIX) +#if !defined(WITH_LWIP) && !defined(WITH_CONTIKI) -time_t clock_offset; +time_t clock_offset = 0; -static inline coap_queue_t * +COAP_STATIC_INLINE coap_queue_t * coap_malloc_node(void) { return (coap_queue_t *)coap_malloc_type(COAP_NODE, sizeof(coap_queue_t)); } -static inline void +COAP_STATIC_INLINE void coap_free_node(coap_queue_t *node) { coap_free_type(COAP_NODE, node); } -#endif /* WITH_POSIX */ +#endif /* !defined(WITH_LWIP) && !defined(WITH_CONTIKI) */ #ifdef WITH_LWIP #include @@ -134,12 +140,12 @@ coap_free_node(coap_queue_t *node) { static void coap_retransmittimer_execute(void *arg); static void coap_retransmittimer_restart(coap_context_t *ctx); -static inline coap_queue_t * +COAP_STATIC_INLINE coap_queue_t * coap_malloc_node() { return (coap_queue_t *)memp_malloc(MEMP_COAP_NODE); } -static inline void +COAP_STATIC_INLINE void coap_free_node(coap_queue_t *node) { memp_free(MEMP_COAP_NODE, node); } @@ -153,7 +159,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]) @@ -165,12 +171,12 @@ coap_context_t the_coap_context; PROCESS(coap_retransmit_process, "message retransmit process"); -static inline coap_queue_t * +COAP_STATIC_INLINE coap_queue_t * coap_malloc_node() { return (coap_queue_t *)coap_malloc_type(COAP_NODE, 0); } -static inline void +COAP_STATIC_INLINE void coap_free_node(coap_queue_t *node) { coap_free_type(COAP_NODE, node); } @@ -386,14 +392,14 @@ coap_new_context( c->endpoint->context = c; #endif -#ifdef WITH_POSIX +#if !defined(WITH_LWIP) && !defined(WITH_CONTIKI) c->sockfd = c->endpoint->handle.fd; -#endif /* WITH_POSIX */ +#endif -#if defined(WITH_POSIX) || defined(WITH_CONTIKI) +#if !defined(WITH_LWIP) c->network_send = coap_network_send; c->network_read = coap_network_read; -#endif /* WITH_POSIX or WITH_CONTIKI */ +#endif #ifdef WITH_CONTIKI process_start(&coap_retransmit_process, (char *)c); @@ -500,7 +506,7 @@ coap_transaction_id(const coap_address_t *peer, const coap_pdu_t *pdu, /* Compare the transport address. */ -#ifdef WITH_POSIX +#if !defined(WITH_LWIP) && !defined(WITH_CONTIKI) switch (peer->addr.sa.sa_family) { case AF_INET: coap_hash((const unsigned char *)&peer->addr.sin.sin_port, @@ -517,12 +523,11 @@ coap_transaction_id(const coap_address_t *peer, const coap_pdu_t *pdu, default: return; } -#endif -#if defined(WITH_LWIP) || defined(WITH_CONTIKI) +#else /* !defined(WITH_LWIP) && !defined(WITH_CONTIKI) */ /* FIXME: with lwip, we can do better */ coap_hash((const unsigned char *)&peer->port, sizeof(peer->port), h); coap_hash((const unsigned char *)&peer->addr, sizeof(peer->addr), h); -#endif /* WITH_LWIP || WITH_CONTIKI */ +#endif /* !defined(WITH_LWIP) && !defined(WITH_CONTIKI) */ coap_hash((const unsigned char *)&pdu->hdr->id, sizeof(unsigned short), h); @@ -548,7 +553,7 @@ coap_send_ack(coap_context_t *context, return result; } -#if defined(WITH_POSIX) || defined(WITH_CONTIKI) +#if !defined(WITH_LWIP) static coap_tid_t coap_send_impl(coap_context_t *context, const coap_endpoint_t *local_interface, @@ -575,13 +580,19 @@ coap_send_impl(coap_context_t *context, if (bytes_written >= 0) { coap_transaction_id(dst, pdu, &id); } else { +#if defined(HAVE_WINSOCK2_H) + char *szErrorMsg = NULL; + FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, (DWORD)WSAGetLastError(), MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), (LPSTR)&szErrorMsg, 0, NULL ); + coap_log(LOG_CRIT, "coap_send_impl: %s\n", szErrorMsg); + LocalFree( szErrorMsg ); +#else coap_log(LOG_CRIT, "coap_send_impl: %s\n", strerror(errno)); +#endif } return id; } -#endif /* WITH_POSIX */ -#ifdef WITH_LWIP +#else /* !defined(WITH_LWIP) */ coap_tid_t coap_send_impl(coap_context_t *context, const coap_endpoint_t *local_interface, @@ -607,7 +618,7 @@ coap_send_impl(coap_context_t *context, return id; } -#endif /* WITH_LWIP */ +#endif /* !defined(WITH_LWIP) */ coap_tid_t coap_send(coap_context_t *context, @@ -669,7 +680,7 @@ coap_send_message_type(coap_context_t *context, * value * @return COAP_TICKS_PER_SECOND * ACK_TIMEOUT * (1 + (ACK_RANDOM_FACTOR - 1) * r) */ -static inline unsigned int +COAP_STATIC_INLINE unsigned int calc_timeout(unsigned char r) { unsigned int result; @@ -970,7 +981,7 @@ coap_remove_from_queue(coap_queue_t **queue, coap_tid_t id, coap_queue_t **node) } -static inline int +COAP_STATIC_INLINE int token_match(const unsigned char *a, size_t alen, const unsigned char *b, size_t blen) { return alen == blen && (alen == 0 || memcmp(a, b, alen) == 0); @@ -1122,7 +1133,7 @@ coap_new_error_response(coap_pdu_t *request, unsigned char code, * Quick hack to determine the size of the resource description for * .well-known/core. */ -static inline size_t +COAP_STATIC_INLINE size_t get_wkc_len(coap_context_t *context, coap_opt_t *query_filter) { unsigned char buf[1]; size_t len = 0; @@ -1535,7 +1546,7 @@ handle_request(coap_context_t *context, coap_queue_t *node) { assert(response == NULL); } -static inline void +COAP_STATIC_INLINE void handle_response(coap_context_t *context, coap_queue_t *sent, coap_queue_t *rcvd) { @@ -1667,6 +1678,20 @@ coap_can_exit( coap_context_t *context ) { return !context || (context->sendqueue == NULL); } +void coap_startup() { +#if defined(HAVE_WINSOCK2_H) + WORD wVersionRequested = MAKEWORD( 2, 2 ); + WSADATA wsaData; + WSAStartup( wVersionRequested, &wsaData ); +#endif +} + +void coap_cleanup() { +#if defined(HAVE_WINSOCK2_H) + WSACleanup(); +#endif +} + #ifdef WITH_CONTIKI /*---------------------------------------------------------------------------*/ diff --git a/src/option.c b/src/option.c index d3e5aa5f7e..92c0373122 100644 --- a/src/option.c +++ b/src/option.c @@ -17,6 +17,7 @@ #include #include +#include "libcoap.h" #include "option.h" #include "encode.h" /* for coap_fls() */ #include "debug.h" @@ -143,7 +144,7 @@ coap_option_iterator_init(coap_pdu_t *pdu, coap_opt_iterator_t *oi, return oi; } -static inline int +COAP_STATIC_INLINE int opt_finished(coap_opt_iterator_t *oi) { assert(oi); @@ -420,7 +421,7 @@ typedef struct { } opt_filter; /** Returns true iff @p type denotes an option type larger than 255. */ -static inline int +COAP_STATIC_INLINE int is_long_option(unsigned short type) { return type > 255; } /** Operation specifiers for coap_filter_op(). */ diff --git a/src/pdu.c b/src/pdu.c index 72a3ebb90a..206768ab59 100644 --- a/src/pdu.c +++ b/src/pdu.c @@ -22,7 +22,11 @@ #ifdef HAVE_ARPA_INET_H #include #endif +#ifdef HAVE_WINSOCK2_H +#include +#endif +#include "libcoap.h" #include "debug.h" #include "pdu.h" #include "option.h" @@ -89,7 +93,7 @@ coap_pdu_init(unsigned char type, unsigned char code, return NULL; /* size must be large enough for hdr */ -#if defined(WITH_POSIX) || defined(WITH_CONTIKI) +#if !defined(WITH_LWIP) pdu = coap_malloc_type(COAP_PDU, sizeof(coap_pdu_t)); if (!pdu) return NULL; pdu->hdr = coap_malloc_type(COAP_PDU_BUF, size); @@ -97,8 +101,7 @@ coap_pdu_init(unsigned char type, unsigned char code, coap_free_type(COAP_PDU, pdu); pdu = NULL; } -#endif /* WITH_POSIX or WITH_CONTIKI */ -#ifdef WITH_LWIP +#else /* 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); @@ -106,7 +109,7 @@ coap_pdu_init(unsigned char type, unsigned char code, coap_free_type(COAP_PDU, pdu); pdu = NULL; } -#endif +#endif /* WITH_LWIP */ if (pdu) { #ifdef WITH_LWIP pdu->pbuf = p; @@ -138,19 +141,16 @@ coap_new_pdu(void) { void coap_delete_pdu(coap_pdu_t *pdu) { -#if defined(WITH_POSIX) || defined(WITH_CONTIKI) if (pdu != NULL) { +#ifdef WITH_LWIP + pbuf_free(pdu->pbuf); +#else if (pdu->hdr != NULL) { coap_free_type(COAP_PDU_BUF, pdu->hdr); } +#endif coap_free_type(COAP_PDU, pdu); } -#endif -#ifdef WITH_LWIP - if (pdu != NULL) /* accepting double free as the other implementation accept that too */ - pbuf_free(pdu->pbuf); - coap_free_type(COAP_PDU, pdu); -#endif } int @@ -164,7 +164,7 @@ coap_add_token(coap_pdu_t *pdu, size_t len, const unsigned char *data) { if (len) memcpy(pdu->hdr->token, data, len); pdu->max_delta = 0; - pdu->length = HEADERLENGTH; + pdu->length = (unsigned short)HEADERLENGTH; pdu->data = NULL; return 1; @@ -401,7 +401,7 @@ coap_pdu_parse(unsigned char *data, size_t length, coap_pdu_t *pdu) { if (length > sizeof(coap_hdr_t)) { memcpy(pdu->hdr + 1, data + sizeof(coap_hdr_t), length - sizeof(coap_hdr_t)); } - pdu->length = length; + pdu->length = (unsigned short)length; /* Finally calculate beginning of data block and thereby check integrity * of the PDU structure. */ diff --git a/src/resource.c b/src/resource.c index 2967d4fa7b..2120ab23db 100644 --- a/src/resource.c +++ b/src/resource.c @@ -15,7 +15,7 @@ #include "subscribe.h" #include "utlist.h" -#ifdef WITH_LWIP +#if defined(WITH_LWIP) /* mem.h is only needed for the string free calls for * COAP_ATTR_FLAGS_RELEASE_NAME / COAP_ATTR_FLAGS_RELEASE_VALUE / * COAP_RESOURCE_FLAGS_RELEASE_URI. not sure what those lines should actually @@ -27,16 +27,7 @@ ((coap_##Type##_t *)memp_malloc(MEMP_COAP_##Type)) #define COAP_FREE_TYPE(Type, Object) memp_free(MEMP_COAP_##Type, Object) -#endif - -#ifdef WITH_POSIX - -#define COAP_MALLOC_TYPE(Type) \ - ((coap_##Type##_t *)coap_malloc(sizeof(coap_##Type##_t))) -#define COAP_FREE_TYPE(Type, Object) coap_free(Object) - -#endif /* WITH_POSIX */ -#ifdef WITH_CONTIKI +#elif defined(WITH_CONTIKI) #include "memb.h" #define COAP_MALLOC_TYPE(Type) \ @@ -50,21 +41,27 @@ coap_resources_init() { memb_init(&subscription_storage); } -static inline coap_subscription_t * +COAP_STATIC_INLINE coap_subscription_t * coap_malloc_subscription() { return memb_alloc(&subscription_storage); } -static inline void +COAP_STATIC_INLINE void coap_free_subscription(coap_subscription_t *subscription) { memb_free(&subscription_storage, subscription); } -#endif /* WITH_CONTIKI */ +#else +#define COAP_MALLOC_TYPE(Type) \ + ((coap_##Type##_t *)coap_malloc(sizeof(coap_##Type##_t))) +#define COAP_FREE_TYPE(Type, Object) coap_free(Object) +#endif #define COAP_PRINT_STATUS_MAX (~COAP_PRINT_STATUS_MASK) +#ifndef min #define min(a,b) ((a) < (b) ? (a) : (b)) +#endif /* Helper functions for conditional output of character sequences into * a given buffer. The first Offset characters are skipped. @@ -116,7 +113,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; diff --git a/src/str.c b/src/str.c index f5800c257b..2c535e363b 100644 --- a/src/str.c +++ b/src/str.c @@ -10,12 +10,13 @@ #include +#include "libcoap.h" #include "debug.h" #include "mem.h" #include "str.h" str *coap_new_string(size_t size) { - str *s = coap_malloc(sizeof(str) + size + 1); + str *s = (str *)coap_malloc(sizeof(str) + size + 1); if ( !s ) { #ifndef NDEBUG coap_log(LOG_CRIT, "coap_new_string: malloc\n"); diff --git a/src/uri.c b/src/uri.c index b111a0eef7..9ffad859de 100644 --- a/src/uri.c +++ b/src/uri.c @@ -20,6 +20,7 @@ #include #include +#include "libcoap.h" #include "mem.h" #include "debug.h" #include "pdu.h" @@ -37,7 +38,7 @@ * @return A pointer to the first occurence of @p c, or @c NULL * if not found. */ -static inline unsigned char * +COAP_STATIC_INLINE unsigned char * strnchr(unsigned char *s, size_t len, unsigned char c) { while (len && *s++ != c) --len; @@ -317,7 +318,7 @@ typedef void (*segment_handler_t)(unsigned char *, size_t, void *); /** * Checks if path segment @p s consists of one or two dots. */ -static inline int +COAP_STATIC_INLINE int dots(unsigned char *s, size_t len) { return *s == '.' && (len == 1 || (*(s+1) == '.' && len == 2)); } @@ -424,7 +425,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; @@ -484,7 +485,7 @@ coap_clone_uri(const coap_uri_t *uri) { /* The function signature of coap_hash() is different from * segment_handler_t hence we use this wrapper as safe typecast. */ -static inline void +COAP_STATIC_INLINE void hash_segment(unsigned char *s, size_t len, void *data) { assert(len <= UINT_MAX); coap_hash(s, (unsigned int)len, (unsigned char *)data); diff --git a/tests/test_options.c b/tests/test_options.c index eb94afb08d..20150fa09e 100644 --- a/tests/test_options.c +++ b/tests/test_options.c @@ -435,10 +435,16 @@ t_access_option7(void) { #define TEST_MAX_SIZE 1000 +#ifdef _MSC_VER +# define ALIGNED(x) +#else +# define ALIGNED(x) __attribute__ ((aligned (x))) +#endif + static void t_iterate_option1(void) { /* CoAP PDU without token, options, or data */ - uint8_t teststr[] __attribute__ ((aligned (8))) = { + uint8_t teststr[] ALIGNED(8) = { 0x00, 0x00, 0x00, 0x00 }; @@ -463,7 +469,7 @@ t_iterate_option1(void) { static void t_iterate_option2(void) { /* CoAP PDU with token but without options and data */ - uint8_t teststr[] __attribute__ ((aligned (8))) = { + uint8_t teststr[] ALIGNED(8) = { 0x03, 0x00, 0x00, 0x00, 't', 'o', 'k' }; @@ -488,7 +494,7 @@ t_iterate_option2(void) { static void t_iterate_option3(void) { /* CoAP PDU with token and options */ - uint8_t teststr[] __attribute__ ((aligned (8))) = { + uint8_t teststr[] ALIGNED(8) = { 0x03, 0x00, 0x00, 0x00, 't', 'o', 'k', 0x13, 'o', 'p', 't', 0x00, 0xd1, 0x10, 'x' }; @@ -529,7 +535,7 @@ t_iterate_option3(void) { static void t_iterate_option4(void) { /* CoAP PDU with token, options, and data */ - uint8_t teststr[] __attribute__ ((aligned (8))) = { + uint8_t teststr[] ALIGNED(8) = { 0x03, 0x00, 0x00, 0x00, 't', 'o', 'k', 0x13, 'o', 'p', 't', 0x00, 0xd1, 0x10, 'x', 0xff, 'd', 'a', 't', 'a' @@ -571,7 +577,7 @@ t_iterate_option4(void) { static void t_iterate_option5(void) { /* CoAP PDU with malformed option */ - uint8_t teststr[] __attribute__ ((aligned (8))) = { + uint8_t teststr[] ALIGNED(8) = { 0x00, 0x00, 0x00, 0x00, 0x52, 'o', 'p', 0xee, 0x12, 0x03, 0x00 }; @@ -603,7 +609,7 @@ static void t_iterate_option6(void) { /* option filter */ /* CoAP PDU with token, options, and data */ - uint8_t teststr[] __attribute__ ((aligned (8))) = { + uint8_t teststr[] ALIGNED(8) = { 0x00, 0x00, 0x00, 0x00, 0x80, 0x20, 0x00, 0x00, 0xc0, 0x00 }; @@ -647,7 +653,7 @@ t_iterate_option6(void) { static void t_iterate_option7(void) { /* option filter */ - uint8_t teststr[] __attribute__ ((aligned (8))) = { + uint8_t teststr[] ALIGNED(8) = { 0x00, 0x00, 0x00, 0x00, 0x80, 0x20, 0x00, 0x00, 0xc0, 0x00, 0x10, 0x10, 0x00 }; @@ -693,7 +699,7 @@ t_iterate_option7(void) { static void t_iterate_option8(void) { /* option filter */ - uint8_t teststr[] __attribute__ ((aligned (8))) = { + uint8_t teststr[] ALIGNED(8) = { 0x00, 0x00, 0x00, 0x00, 0x80, 0x20, 0x00, 0x00, 0xc0, 0x00, 0x10, 0x10, 0x00 }; @@ -723,7 +729,7 @@ t_iterate_option8(void) { static void t_iterate_option9(void) { /* options filter: option number too large for filter */ - uint8_t teststr[] __attribute__ ((aligned (8))) = { + uint8_t teststr[] ALIGNED(8) = { 0x00, 0x00, 0x00, 0x00, 0x80, 0x20, 0x00, 0x00, 0xc0, 0x00, 0x10, 0x10, 0x00 }; @@ -753,7 +759,7 @@ t_iterate_option9(void) { static void t_iterate_option10(void) { /* options filter: option numbers in PDU exceed filter size */ - uint8_t teststr[] __attribute__ ((aligned (8))) = { + uint8_t teststr[] ALIGNED(8) = { 0x00, 0x00, 0x00, 0x00, 0x80, 0x20, 0x00, 0x00, 0xd0, 0x26, 0xe0, 0x10, 0x00 }; diff --git a/tests/test_uri.c b/tests/test_uri.c index 004cbd6ab8..c5069718ac 100644 --- a/tests/test_uri.c +++ b/tests/test_uri.c @@ -316,9 +316,15 @@ t_parse_uri12(void) { } } +#ifdef _MSC_VER +# define ALIGNED(x) +#else +# define ALIGNED(x) __attribute__ ((aligned (x))) +#endif + static void t_parse_uri13(void) { - uint8_t teststr[] __attribute__ ((aligned (8))) = { + uint8_t teststr[] ALIGNED(8) = { 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 'f', 'o', 'o', 0x3b, '.', 'w', 'e', 'l', 'l', '-', 'k', 'n', 'o', 'w', 'n', 0x04, 'c', 'o', diff --git a/tests/test_wellknown.c b/tests/test_wellknown.c index 57a4db7a41..f3d3221452 100644 --- a/tests/test_wellknown.c +++ b/tests/test_wellknown.c @@ -12,7 +12,9 @@ #include #include +#ifdef HAVE_NETINET_IN_H #include +#endif #include #include #include diff --git a/tests/testdriver.c b/tests/testdriver.c index b65dd61827..39480199e8 100644 --- a/tests/testdriver.c +++ b/tests/testdriver.c @@ -11,6 +11,7 @@ #include "test_error_response.h" #include "test_sendqueue.h" #include "test_wellknown.h" +#include "libcoap.h" #ifdef __GNUC__ #define UNUSED_PARAM __attribute__ ((unused)) @@ -28,6 +29,7 @@ main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) { return -2; } + coap_startup(); t_init_uri_tests(); t_init_option_tests(); t_init_pdu_tests(); @@ -39,6 +41,7 @@ main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) { result = CU_basic_run_tests(); CU_cleanup_registry(); + coap_cleanup(); return result; } diff --git a/win32/coap-client/coap-client.vcxproj b/win32/coap-client/coap-client.vcxproj new file mode 100644 index 0000000000..a9ebadd019 --- /dev/null +++ b/win32/coap-client/coap-client.vcxproj @@ -0,0 +1,167 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {177F5822-F271-4903-9922-05ADAF358B1E} + Win32Proj + coap_client + 8.1 + coap-client + + + + Application + true + v140 + MultiByte + + + Application + false + v140 + true + MultiByte + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + false + $(ProjectName)d + + + true + + + false + + + false + + + + + + Level3 + Disabled + WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + ProgramDatabase + false + ../../include/coap + CompileAsC + + + Console + true + + + + + + + Level3 + Disabled + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + ../../include/coap + CompileAsC + + + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + true + true + + + + + + + + + + + + {96a98759-36b3-4246-a265-cafceec0f2f2} + + + + + + \ No newline at end of file diff --git a/win32/coap-client/coap-client.vcxproj.filters b/win32/coap-client/coap-client.vcxproj.filters new file mode 100644 index 0000000000..0bdc8cce9d --- /dev/null +++ b/win32/coap-client/coap-client.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + + + Header Files + + + \ No newline at end of file diff --git a/win32/coap-rp/coap-rp.vcxproj b/win32/coap-rp/coap-rp.vcxproj new file mode 100644 index 0000000000..37f86c142e --- /dev/null +++ b/win32/coap-rp/coap-rp.vcxproj @@ -0,0 +1,162 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {640AC988-FE9E-4580-BDF5-0D9FD57C3CE5} + Win32Proj + coaprp + 8.1 + + + + Application + true + v140 + MultiByte + + + Application + false + v140 + true + MultiByte + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + false + $(ProjectName)d + + + true + + + false + + + false + + + + + + Level3 + Disabled + WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + ProgramDatabase + ../../include/coap + false + CompileAsC + + + Console + true + + + + + + + Level3 + Disabled + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + ../../include/coap + CompileAsC + + + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + true + true + + + + + + + + {96a98759-36b3-4246-a265-cafceec0f2f2} + + + + + + \ No newline at end of file diff --git a/win32/coap-rp/coap-rp.vcxproj.filters b/win32/coap-rp/coap-rp.vcxproj.filters new file mode 100644 index 0000000000..0f4136fb73 --- /dev/null +++ b/win32/coap-rp/coap-rp.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/win32/coap-server/coap-server.vcxproj b/win32/coap-server/coap-server.vcxproj new file mode 100644 index 0000000000..6ab11d67fc --- /dev/null +++ b/win32/coap-server/coap-server.vcxproj @@ -0,0 +1,163 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {F9255447-0C93-47CB-8644-62F0E6995791} + Win32Proj + coap_server + 8.1 + coap-server + + + + Application + true + v140 + MultiByte + + + Application + false + v140 + true + MultiByte + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + false + $(ProjectName)d + + + true + + + false + + + false + + + + + + Level3 + Disabled + WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + ProgramDatabase + false + ../../include/coap + CompileAsC + + + Console + true + + + + + + + Level3 + Disabled + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + ../../include/coap + CompileAsC + + + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + true + true + + + + + + + + {96a98759-36b3-4246-a265-cafceec0f2f2} + + + + + + \ No newline at end of file diff --git a/win32/coap-server/coap-server.vcxproj.filters b/win32/coap-server/coap-server.vcxproj.filters new file mode 100644 index 0000000000..36191ab9d9 --- /dev/null +++ b/win32/coap-server/coap-server.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + + + Resource Files\Source Files + + + \ No newline at end of file diff --git a/win32/libcoap.sln b/win32/libcoap.sln new file mode 100644 index 0000000000..782f91912b --- /dev/null +++ b/win32/libcoap.sln @@ -0,0 +1,68 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcoap", "libcoap.vcxproj", "{96A98759-36B3-4246-A265-CAFCEEC0F2F2}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "coap-rp", "coap-rp\coap-rp.vcxproj", "{640AC988-FE9E-4580-BDF5-0D9FD57C3CE5}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "coap-client", "coap-client\coap-client.vcxproj", "{177F5822-F271-4903-9922-05ADAF358B1E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "coap-server", "coap-server\coap-server.vcxproj", "{F9255447-0C93-47CB-8644-62F0E6995791}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testdriver", "testdriver\testdriver.vcxproj", "{C21580DF-4786-441E-B921-21E66DFA926E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {96A98759-36B3-4246-A265-CAFCEEC0F2F2}.Debug|x64.ActiveCfg = Debug|x64 + {96A98759-36B3-4246-A265-CAFCEEC0F2F2}.Debug|x64.Build.0 = Debug|x64 + {96A98759-36B3-4246-A265-CAFCEEC0F2F2}.Debug|x86.ActiveCfg = Debug|Win32 + {96A98759-36B3-4246-A265-CAFCEEC0F2F2}.Debug|x86.Build.0 = Debug|Win32 + {96A98759-36B3-4246-A265-CAFCEEC0F2F2}.Release|x64.ActiveCfg = Release|x64 + {96A98759-36B3-4246-A265-CAFCEEC0F2F2}.Release|x64.Build.0 = Release|x64 + {96A98759-36B3-4246-A265-CAFCEEC0F2F2}.Release|x86.ActiveCfg = Release|Win32 + {96A98759-36B3-4246-A265-CAFCEEC0F2F2}.Release|x86.Build.0 = Release|Win32 + {640AC988-FE9E-4580-BDF5-0D9FD57C3CE5}.Debug|x64.ActiveCfg = Debug|x64 + {640AC988-FE9E-4580-BDF5-0D9FD57C3CE5}.Debug|x64.Build.0 = Debug|x64 + {640AC988-FE9E-4580-BDF5-0D9FD57C3CE5}.Debug|x86.ActiveCfg = Debug|Win32 + {640AC988-FE9E-4580-BDF5-0D9FD57C3CE5}.Debug|x86.Build.0 = Debug|Win32 + {640AC988-FE9E-4580-BDF5-0D9FD57C3CE5}.Release|x64.ActiveCfg = Release|x64 + {640AC988-FE9E-4580-BDF5-0D9FD57C3CE5}.Release|x64.Build.0 = Release|x64 + {640AC988-FE9E-4580-BDF5-0D9FD57C3CE5}.Release|x86.ActiveCfg = Release|Win32 + {640AC988-FE9E-4580-BDF5-0D9FD57C3CE5}.Release|x86.Build.0 = Release|Win32 + {177F5822-F271-4903-9922-05ADAF358B1E}.Debug|x64.ActiveCfg = Debug|x64 + {177F5822-F271-4903-9922-05ADAF358B1E}.Debug|x64.Build.0 = Debug|x64 + {177F5822-F271-4903-9922-05ADAF358B1E}.Debug|x86.ActiveCfg = Debug|Win32 + {177F5822-F271-4903-9922-05ADAF358B1E}.Debug|x86.Build.0 = Debug|Win32 + {177F5822-F271-4903-9922-05ADAF358B1E}.Release|x64.ActiveCfg = Release|x64 + {177F5822-F271-4903-9922-05ADAF358B1E}.Release|x64.Build.0 = Release|x64 + {177F5822-F271-4903-9922-05ADAF358B1E}.Release|x86.ActiveCfg = Release|Win32 + {177F5822-F271-4903-9922-05ADAF358B1E}.Release|x86.Build.0 = Release|Win32 + {F9255447-0C93-47CB-8644-62F0E6995791}.Debug|x64.ActiveCfg = Debug|x64 + {F9255447-0C93-47CB-8644-62F0E6995791}.Debug|x64.Build.0 = Debug|x64 + {F9255447-0C93-47CB-8644-62F0E6995791}.Debug|x86.ActiveCfg = Debug|Win32 + {F9255447-0C93-47CB-8644-62F0E6995791}.Debug|x86.Build.0 = Debug|Win32 + {F9255447-0C93-47CB-8644-62F0E6995791}.Release|x64.ActiveCfg = Release|x64 + {F9255447-0C93-47CB-8644-62F0E6995791}.Release|x64.Build.0 = Release|x64 + {F9255447-0C93-47CB-8644-62F0E6995791}.Release|x86.ActiveCfg = Release|Win32 + {F9255447-0C93-47CB-8644-62F0E6995791}.Release|x86.Build.0 = Release|Win32 + {C21580DF-4786-441E-B921-21E66DFA926E}.Debug|x64.ActiveCfg = Debug|x64 + {C21580DF-4786-441E-B921-21E66DFA926E}.Debug|x64.Build.0 = Debug|x64 + {C21580DF-4786-441E-B921-21E66DFA926E}.Debug|x86.ActiveCfg = Debug|Win32 + {C21580DF-4786-441E-B921-21E66DFA926E}.Debug|x86.Build.0 = Debug|Win32 + {C21580DF-4786-441E-B921-21E66DFA926E}.Release|x64.ActiveCfg = Release|x64 + {C21580DF-4786-441E-B921-21E66DFA926E}.Release|x64.Build.0 = Release|x64 + {C21580DF-4786-441E-B921-21E66DFA926E}.Release|x86.ActiveCfg = Release|Win32 + {C21580DF-4786-441E-B921-21E66DFA926E}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/win32/libcoap.vcxproj b/win32/libcoap.vcxproj new file mode 100644 index 0000000000..e8cdbd6be2 --- /dev/null +++ b/win32/libcoap.vcxproj @@ -0,0 +1,243 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {96A98759-36B3-4246-A265-CAFCEEC0F2F2} + Win32Proj + libcoap + 8.1 + + + + StaticLibrary + true + v140 + MultiByte + + + StaticLibrary + false + v140 + true + MultiByte + + + StaticLibrary + true + v140 + Unicode + + + StaticLibrary + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + $(ProjectName)d + + + + + + + + + + + + + + NotUsing + Level3 + Disabled + WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;_LIB;%(PreprocessorDefinitions) + ProgramDatabase + ../include/coap;.. + $(IntDir)$(TargetName).pdb + false + CompileAsC + + + Windows + + + copy /Y ..\coap_config.h.windows ..\coap_config.h +copy /Y ..\include\coap\coap.h.windows ..\include\coap\coap.h + + + Copying config files for windows + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + _DEBUG;_LIB;%(PreprocessorDefinitions) + ProgramDatabase + + + Windows + + + + + Level3 + NotUsing + MaxSpeed + true + true + WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;_LIB;%(PreprocessorDefinitions) + ../include/coap;.. + $(IntDir)$(TargetName).pdb + CompileAsC + + + Windows + true + true + + + copy /Y ..\coap_config.h.windows ..\coap_config.h +copy /Y ..\include\coap\coap.h.windows ..\include\coap\coap.h + + + Copying config files for windows + + + + + + + + + + + + + + + + + + + + + Level3 + + + MaxSpeed + true + true + NDEBUG;_LIB;%(PreprocessorDefinitions) + + + Windows + true + true + + + + + + \ No newline at end of file diff --git a/win32/libcoap.vcxproj.filters b/win32/libcoap.vcxproj.filters new file mode 100644 index 0000000000..a19e4c25e6 --- /dev/null +++ b/win32/libcoap.vcxproj.filters @@ -0,0 +1,143 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Resource Files + + + \ No newline at end of file diff --git a/win32/testdriver/testdriver.vcxproj b/win32/testdriver/testdriver.vcxproj new file mode 100644 index 0000000000..3dbc36caef --- /dev/null +++ b/win32/testdriver/testdriver.vcxproj @@ -0,0 +1,178 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {C21580DF-4786-441E-B921-21E66DFA926E} + Win32Proj + testdriver + 8.1 + + + + Application + true + v140 + MultiByte + + + Application + false + v140 + true + MultiByte + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + false + $(ProjectName)d + + + true + + + false + + + false + + + + + + Level3 + Disabled + WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + ProgramDatabase + false + ../../include/coap;../..;.. + CompileAsC + + + Console + true + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;../CUnit/libcunitd_dll.lib;%(AdditionalDependencies) + + + + + + + Level3 + Disabled + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + ../../include/coap;../..;.. + CompileAsC + + + Console + true + true + true + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;../CUnit/libcunit_dll.lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + true + true + + + + + {96a98759-36b3-4246-a265-cafceec0f2f2} + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/win32/testdriver/testdriver.vcxproj.filters b/win32/testdriver/testdriver.vcxproj.filters new file mode 100644 index 0000000000..4e2d565bfc --- /dev/null +++ b/win32/testdriver/testdriver.vcxproj.filters @@ -0,0 +1,60 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/win32/testdriver/testdriver.vcxproj.user b/win32/testdriver/testdriver.vcxproj.user new file mode 100644 index 0000000000..1239e0af6b --- /dev/null +++ b/win32/testdriver/testdriver.vcxproj.user @@ -0,0 +1,15 @@ + + + + + + WindowsLocalDebugger + $(ProjectDir)..\Cunit + + + + + WindowsLocalDebugger + $(ProjectDir)..\Cunit + + \ No newline at end of file