diff --git a/Makefile.libcoap b/Makefile.libcoap index 09275aae..1035c64b 100644 --- a/Makefile.libcoap +++ b/Makefile.libcoap @@ -1,4 +1,4 @@ -libcoap_src = pdu.c net.c coap_debug.c encode.c uri.c subscribe.c resource.c str.c option.c async.c block.c mem.c coap_io.c coap_session.c coap_notls.c coap_hashkey.c address.c +libcoap_src = pdu.c net.c coap_debug.c encode.c uri.c subscribe.c resource.c str.c option.c async.c block.c mem.c coap_io.c coap_session.c coap_notls.c coap_hashkey.c address.c coap_tcp.c libcoap_dir := $(filter %libcoap,$(APPDS)) vpath %c $(libcoap_dir)/src diff --git a/examples/client.c b/examples/client.c index 2ce48de5..794148f5 100644 --- a/examples/client.c +++ b/examples/client.c @@ -829,6 +829,13 @@ cmdline_uri(char *arg, int create_uri_opts) { return -1; } + if (uri.scheme==COAP_URI_SCHEME_COAP_TCP && !coap_tcp_is_supported()) { + /* coaps+tcp caught above */ + coap_log(LOG_EMERG, + "coap+tcp URI scheme not supported in this version of libcoap\n"); + return -1; + } + if (uri.port != get_default_port(&uri) && create_uri_opts) { coap_insert_optlist(&optlist, coap_new_optlist(COAP_OPTION_URI_PORT, diff --git a/examples/lwip/Makefile b/examples/lwip/Makefile index 1e9073c7..819dd54f 100644 --- a/examples/lwip/Makefile +++ b/examples/lwip/Makefile @@ -39,7 +39,7 @@ CFLAGS += -I$(top_srcdir)/include/coap2 vpath %.c $(top_srcdir)/src -COAPOBJS = net.o coap_debug.o option.o resource.o pdu.o encode.o subscribe.o coap_io_lwip.o block.o uri.o str.o coap_session.o coap_notls.o coap_hashkey.o address.o +COAPOBJS = net.o coap_debug.o option.o resource.o pdu.o encode.o subscribe.o coap_io_lwip.o block.o uri.o str.o coap_session.o coap_notls.o coap_hashkey.o address.o coap_tcp.o CFLAGS += -g3 -Wall -Wextra -pedantic -O0 -fpack-struct # not sorted out yet diff --git a/src/coap_session.c b/src/coap_session.c index b5873a6c..1d05d625 100644 --- a/src/coap_session.c +++ b/src/coap_session.c @@ -658,8 +658,33 @@ coap_session_create_client( coap_session_t *session = NULL; assert(server); - assert(proto != COAP_PROTO_NONE); + switch(proto) { + case COAP_PROTO_UDP: + break; + case COAP_PROTO_DTLS: + if (!coap_dtls_is_supported()) { + coap_log(LOG_CRIT, "coap_new_client_session*: DTLS not supported\n"); + return NULL; + } + break; + case COAP_PROTO_TCP: + if (!coap_tcp_is_supported()) { + coap_log(LOG_CRIT, "coap_new_client_session*: TCP not supported\n"); + return NULL; + } + break; + case COAP_PROTO_TLS: + if (!coap_tls_is_supported()) { + coap_log(LOG_CRIT, "coap_new_client_session*: TLS not supported\n"); + return NULL; + } + break; + case COAP_PROTO_NONE: + default: + assert(0); + break; + } session = coap_make_session(proto, COAP_SESSION_TYPE_CLIENT, local_if, local_if, server, 0, ctx, NULL); if (!session) @@ -1024,12 +1049,15 @@ coap_new_endpoint(coap_context_t *context, const coap_address_t *listen_addr, co goto error; } -#if !COAP_DISABLE_TCP if (proto == COAP_PROTO_TLS && !coap_tls_is_supported()) { coap_log(LOG_CRIT, "coap_new_endpoint: TLS not supported\n"); goto error; } -#endif /* !COAP_DISABLE_TCP */ + + if (proto == COAP_PROTO_TCP && !coap_tcp_is_supported()) { + coap_log(LOG_CRIT, "coap_new_endpoint: TCP not supported\n"); + goto error; + } if (proto == COAP_PROTO_DTLS || proto == COAP_PROTO_TLS) { if (!coap_dtls_context_check_keys_enabled(context)) { diff --git a/src/uri.c b/src/uri.c index 2107ce95..67ab8603 100644 --- a/src/uri.c +++ b/src/uri.c @@ -79,7 +79,6 @@ coap_split_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri) { } /* There might be and addition "+tcp", indicating reliable transport: */ -#if !COAP_DISABLE_TCP if (len>=4 && p[0] == '+' && p[1] == 't' && p[2] == 'c' && p[3] == 'p' ) { p += 4; len -= 4; @@ -88,7 +87,6 @@ coap_split_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri) { else uri->scheme = COAP_URI_SCHEME_COAP_TCP; } -#endif /* !COAP_DISABLE_TCP */ q = (const uint8_t *)"://"; while (len && *q && *p == *q) { ++p; ++q; --len;