Skip to content

Commit

Permalink
Supported: Break out run-time checks and libcoap build #defines
Browse files Browse the repository at this point in the history
Group together and document the run-time checks available for checking
the libcoap built-in functionality based on the ./cconfigure and / or
CMakeLists.txt options.

Create include/coap3/coap_defines.h file that contains a list of
COAP_ #defines created from the options defined when running ./configure
or cmake.

Add additional coap_*_is_supported() functions.
  • Loading branch information
mrdeep1 committed Aug 1, 2024
1 parent 9656876 commit 802e83f
Show file tree
Hide file tree
Showing 33 changed files with 627 additions and 262 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ examples/riot/pkg_libcoap/patches

# the include/ folder
include/coap3/coap.h
include/coap3/coap_defines.h

# the tests/ folder
tests/.deps
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,9 @@ configure_file(${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap
configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake_coap_config.h.in
${CMAKE_CURRENT_BINARY_DIR}/coap_config.h)

configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake_coap_defines.h.in
${CMAKE_CURRENT_BINARY_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_defines.h)

configure_file(${CMAKE_CURRENT_LIST_DIR}/tests/test_common.h.in
${CMAKE_CURRENT_LIST_DIR}/tests/test_common.h)

Expand Down Expand Up @@ -788,6 +791,7 @@ target_sources(
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_session.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_str.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_subscribe.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_supported.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_time.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_uri.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_ws.h)
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,9 @@ configure_file(${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap
configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake_coap_config.h.in
${CMAKE_CURRENT_BINARY_DIR}/coap_config.h)

configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake_coap_defines.h.in
${CMAKE_CURRENT_BINARY_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_defines.h)

configure_file(${CMAKE_CURRENT_LIST_DIR}/tests/test_common.h.in
${CMAKE_CURRENT_LIST_DIR}/tests/test_common.h)

Expand Down Expand Up @@ -788,6 +791,7 @@ target_sources(
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_session.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_str.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_subscribe.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_supported.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_time.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_uri.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_ws.h)
Expand Down
3 changes: 3 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ EXTRA_DIST = \
LICENSE \
CMakeLists.txt \
cmake_coap_config.h.in \
cmake_coap_defines.h.in \
cmake/Config.cmake.in \
cmake/FindMbedTLS.cmake \
cmake/FindTinyDTLS.cmake \
Expand Down Expand Up @@ -249,6 +250,7 @@ libcoap_include_HEADERS = \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_block.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_cache.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_debug.h \
$(top_builddir)/include/coap$(LIBCOAP_API_VERSION)/coap_defines.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_dtls.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_encode.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_event.h \
Expand All @@ -264,6 +266,7 @@ libcoap_include_HEADERS = \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_session.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_str.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_subscribe.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_supported.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_time.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_uri.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_ws.h
Expand Down
63 changes: 1 addition & 62 deletions cmake_coap_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,68 +17,7 @@
#define _GNU_SOURCE
#endif

/* Define to 1 if the system has small stack size. */
#cmakedefine COAP_CONSTRAINED_STACK @COAP_CONSTRAINED_STACK@

/* Define to 1 if the library has client support. */
#cmakedefine COAP_CLIENT_SUPPORT @COAP_CLIENT_SUPPORT@

/* Define to 1 if the library has server support. */
#cmakedefine COAP_SERVER_SUPPORT @COAP_SERVER_SUPPORT@

/* Define to 1 if the library is to have observe persistence. */
#cmakedefine COAP_WITH_OBSERVE_PERSIST @COAP_WITH_OBSERVE_PERSIST@

/* Define to 1 if the system has epoll support. */
#cmakedefine COAP_EPOLL_SUPPORT @COAP_EPOLL_SUPPORT@

/* Define to 1 if the library has OSCORE support. */
#cmakedefine COAP_OSCORE_SUPPORT @COAP_OSCORE_SUPPORT@

/* Define to 1 if the library has WebSockets support. */
#cmakedefine COAP_WS_SUPPORT @COAP_WS_SUPPORT@

/* Define to 1 if the library has async separate response support. */
#cmakedefine COAP_ASYNC_SUPPORT @COAP_ASYNC_SUPPORT@

/* Define to 1 if the library has thread safe support. */
#cmakedefine COAP_THREAD_SAFE @COAP_THREAD_SAFE@

/* Define to 1 if the library has thread deadlock detection support. */
#cmakedefine COAP_THREAD_RECURSIVE_CHECK @COAP_THREAD_RECURSIVE_CHECK@

/* Define to 0-8 for maximum logging level. */
#cmakedefine COAP_MAX_LOGGING_LEVEL @COAP_MAX_LOGGING_LEVEL@

/* Define to 1 to build without TCP support. */
#cmakedefine01 COAP_DISABLE_TCP

/* Define to 1 to build with IPv4 support. */
#cmakedefine COAP_IPV4_SUPPORT @COAP_IPV4_SUPPORT@

/* Define to 1 to build with IPv6 support. */
#cmakedefine COAP_IPV6_SUPPORT @COAP_IPV6_SUPPORT@

/* Define to 1 to build with Unix socket support. */
#cmakedefine COAP_AF_UNIX_SUPPORT @COAP_AF_UNIX_SUPPORT@

/* Define to 1 to build with Q-Block (RFC 9177) support. */
#cmakedefine COAP_Q_BLOCK_SUPPORT @COAP_Q_BLOCK_SUPPORT@

/* Define to 1 if the system has openssl */
#cmakedefine COAP_WITH_LIBOPENSSL @COAP_WITH_LIBOPENSSL@

/* Define to 1 if the system has wolfSSL */
#cmakedefine COAP_WITH_LIBWOLFSSL @COAP_WITH_LIBWOLFSSL@

/* Define to 1 if the system has libgnutls28 */
#cmakedefine COAP_WITH_LIBGNUTLS @COAP_WITH_LIBGNUTLS@

/* Define to 1 if the system has libtinydtls */
#cmakedefine COAP_WITH_LIBTINYDTLS @COAP_WITH_LIBTINYDTLS@

/* Define to 1 if the system has libmbedtls */
#cmakedefine COAP_WITH_LIBMBEDTLS @COAP_WITH_LIBMBEDTLS@
#include <coap@LIBCOAP_API_VERSION@/coap_defines.h>

/* Define to 1 if you have the <arpa/inet.h> header file. */
#cmakedefine HAVE_ARPA_INET_H @HAVE_ARPA_INET_H@
Expand Down
78 changes: 78 additions & 0 deletions cmake_coap_defines.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* cmake_coap_defines.h -- optional #defines used for building libcoap
*
* Copyright (C) 2024 Jon Shallow <supjps-libcoap@jpshallow.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*
* This file is part of the CoAP library libcoap. Please see README for terms
* of use.
*/

#ifndef COAP_DEFINES_H_
#define COAP_DEFINES_H_

/* Define to 1 to build with Unix socket support. */
#cmakedefine COAP_AF_UNIX_SUPPORT @COAP_AF_UNIX_SUPPORT@

/* Define to 1 if the library has async separate response support. */
#cmakedefine COAP_ASYNC_SUPPORT @COAP_ASYNC_SUPPORT@

/* Define to 1 if the library has client support. */
#cmakedefine COAP_CLIENT_SUPPORT @COAP_CLIENT_SUPPORT@

/* Define to 1 if the system has small stack size. */
#cmakedefine COAP_CONSTRAINED_STACK @COAP_CONSTRAINED_STACK@

/* Define to 1 to build without TCP support. */
#cmakedefine01 COAP_DISABLE_TCP

/* Define to 1 if the system has epoll support. */
#cmakedefine COAP_EPOLL_SUPPORT @COAP_EPOLL_SUPPORT@

/* Define to 1 to build with IPv4 support. */
#cmakedefine COAP_IPV4_SUPPORT @COAP_IPV4_SUPPORT@

/* Define to 1 to build with IPv6 support. */
#cmakedefine COAP_IPV6_SUPPORT @COAP_IPV6_SUPPORT@

/* Define to 0-8 for maximum logging level. */
#cmakedefine COAP_MAX_LOGGING_LEVEL @COAP_MAX_LOGGING_LEVEL@

/* Define to 1 if the library has OSCORE support. */
#cmakedefine COAP_OSCORE_SUPPORT @COAP_OSCORE_SUPPORT@

/* Define to 1 to build with Q-Block (RFC 9177) support. */
#cmakedefine COAP_Q_BLOCK_SUPPORT @COAP_Q_BLOCK_SUPPORT@

/* Define to 1 if the library has server support. */
#cmakedefine COAP_SERVER_SUPPORT @COAP_SERVER_SUPPORT@

/* Define to 1 if the library has thread deadlock detection support. */
#cmakedefine COAP_THREAD_RECURSIVE_CHECK @COAP_THREAD_RECURSIVE_CHECK@

/* Define to 1 if the library has thread safe support. */
#cmakedefine COAP_THREAD_SAFE @COAP_THREAD_SAFE@

/* Define to 1 if the system has libgnutls28 */
#cmakedefine COAP_WITH_LIBGNUTLS @COAP_WITH_LIBGNUTLS@

/* Define to 1 if the system has libmbedtls */
#cmakedefine COAP_WITH_LIBMBEDTLS @COAP_WITH_LIBMBEDTLS@

/* Define to 1 if the system has openssl */
#cmakedefine COAP_WITH_LIBOPENSSL @COAP_WITH_LIBOPENSSL@

/* Define to 1 if the system has libtinydtls */
#cmakedefine COAP_WITH_LIBTINYDTLS @COAP_WITH_LIBTINYDTLS@

/* Define to 1 if the system has wolfSSL */
#cmakedefine COAP_WITH_LIBWOLFSSL @COAP_WITH_LIBWOLFSSL@

/* Define to 1 if the library is to have observe persistence. */
#cmakedefine COAP_WITH_OBSERVE_PERSIST @COAP_WITH_OBSERVE_PERSIST@

/* Define to 1 if the library has WebSockets support. */
#cmakedefine COAP_WS_SUPPORT @COAP_WS_SUPPORT@

#endif /* COAP_DEFINES_H_ */
6 changes: 6 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,7 @@ man/coap_recovery.txt
man/coap_resource.txt
man/coap_session.txt
man/coap_string.txt
man/coap_supported.txt
man/coap_tls_library.txt
man/coap_uri.txt
man/coap_websockets.txt
Expand Down Expand Up @@ -1527,3 +1528,8 @@ if test "x$enable_static" = "xyes"; then
else
AC_MSG_RESULT([ build static library : "no"])
fi

LT_TEMP=`grep -B2 " COAP_" coap_config.h > include/coap$LIBCOAP_API_VERSION/coap_defines.h`
if test "x$LT_TEMP" != "x" ; then
AC_MSG_ERROR([Unable to build coap_defines.h])
fi
1 change: 1 addition & 0 deletions include/coap3/coap.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ extern "C" {
#include "coap@LIBCOAP_API_VERSION@/coap_resource.h"
#include "coap@LIBCOAP_API_VERSION@/coap_str.h"
#include "coap@LIBCOAP_API_VERSION@/coap_subscribe.h"
#include "coap@LIBCOAP_API_VERSION@/coap_supported.h"
#include "coap@LIBCOAP_API_VERSION@/coap_time.h"
#include "coap@LIBCOAP_API_VERSION@/coap_uri.h"
#include "coap@LIBCOAP_API_VERSION@/coap_ws.h"
Expand Down
1 change: 1 addition & 0 deletions include/coap3/coap.h.riot
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ extern "C" {
#include "coap_resource.h"
#include "coap_str.h"
#include "coap_subscribe.h"
#include "coap_supported.h"
#include "coap_time.h"
#include "coap_uri.h"
#include "coap_ws.h"
Expand Down
1 change: 1 addition & 0 deletions include/coap3/coap.h.riot.in
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ extern "C" {
#include "coap_resource.h"
#include "coap_str.h"
#include "coap_subscribe.h"
#include "coap_supported.h"
#include "coap_time.h"
#include "coap_uri.h"
#include "coap_ws.h"
Expand Down
1 change: 1 addition & 0 deletions include/coap3/coap.h.windows
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ extern "C" {
#include "coap3/coap_resource.h"
#include "coap3/coap_str.h"
#include "coap3/coap_subscribe.h"
#include "coap3/coap_supported.h"
#include "coap3/coap_time.h"
#include "coap3/coap_uri.h"
#include "coap3/coap_ws.h"
Expand Down
1 change: 1 addition & 0 deletions include/coap3/coap.h.windows.in
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ extern "C" {
#include "coap@LIBCOAP_API_VERSION@/coap_resource.h"
#include "coap@LIBCOAP_API_VERSION@/coap_str.h"
#include "coap@LIBCOAP_API_VERSION@/coap_subscribe.h"
#include "coap@LIBCOAP_API_VERSION@/coap_supported.h"
#include "coap@LIBCOAP_API_VERSION@/coap_time.h"
#include "coap@LIBCOAP_API_VERSION@/coap_uri.h"
#include "coap@LIBCOAP_API_VERSION@/coap_ws.h"
Expand Down
6 changes: 0 additions & 6 deletions include/coap3/coap_async.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@
* cannot be delivered immediately.
*/

/**
* Returns @c 1 if libcoap was built with separate messages enabled,
* @c 0 otherwise.
*/
int coap_async_is_supported(void);

/**
* Allocates a new coap_async_t object and fills its fields according to
* the given @p request. This function returns a pointer to the registered
Expand Down
6 changes: 0 additions & 6 deletions include/coap3/coap_block.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,6 @@ typedef struct {
block1 */
/* WARNING: Added defined values must not encroach into 0xff000000 which are defined elsewhere */

/**
* Returns @c 1 if libcoap was built with option Q-BlockX support,
* @c 0 otherwise.
*/
int coap_q_block_is_supported(void);

/**
* Returns the value of the least significant byte of a Block option @p opt.
* For zero-length options (i.e. num == m == szx == 0), COAP_OPT_BLOCK_LAST
Expand Down
42 changes: 0 additions & 42 deletions include/coap3/coap_dtls.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,48 +48,6 @@ typedef enum coap_dtls_role_t {

#define COAP_DTLS_RPK_CERT_CN "RPK"

/**
* Check whether DTLS is available.
*
* @return @c 1 if support for DTLS is available, or @c 0 otherwise.
*/
int coap_dtls_is_supported(void);

/**
* Check whether TLS is available.
*
* @return @c 1 if support for TLS is available, or @c 0 otherwise.
*/
int coap_tls_is_supported(void);

/**
* Check whether (D)TLS PSK is available.
*
* @return @c 1 if support for (D)TLS PSK is available, or @c 0 otherwise.
*/
int coap_dtls_psk_is_supported(void);

/**
* Check whether (D)TLS PKI is available.
*
* @return @c 1 if support for (D)TLS PKI is available, or @c 0 otherwise.
*/
int coap_dtls_pki_is_supported(void);

/**
* Check whether (D)TLS PKCS11 is available.
*
* @return @c 1 if support for (D)TLS PKCS11 is available, or @c 0 otherwise.
*/
int coap_dtls_pkcs11_is_supported(void);

/**
* Check whether (D)TLS RPK is available.
*
* @return @c 1 if support for (D)TLS RPK is available, or @c 0 otherwise.
*/
int coap_dtls_rpk_is_supported(void);

/**
* Configure an ENGINE for a TLS library.
* (Currently only OpenSSL is supported)
Expand Down
7 changes: 0 additions & 7 deletions include/coap3/coap_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ typedef struct coap_addr_tuple_t {

const char *coap_socket_strerror(void);

/**
* Check whether TCP is available.
*
* @return @c 1 if support for TCP is enabled, or @c 0 otherwise.
*/
int coap_tcp_is_supported(void);

typedef enum {
COAP_NACK_TOO_MANY_RETRIES,
COAP_NACK_NOT_DELIVERABLE,
Expand Down
7 changes: 0 additions & 7 deletions include/coap3/coap_oscore.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@
* @{
*/

/**
* Check whether OSCORE is available.
*
* @return @c 1 if support for OSCORE is enabled, or @c 0 otherwise.
*/
int coap_oscore_is_supported(void);

/**
* Creates a new client session to the designated server, protecting the data
* using OSCORE.
Expand Down
Loading

0 comments on commit 802e83f

Please sign in to comment.