Skip to content

Commit

Permalink
coap_cleanup: Allow coap_startup() to be called after coap_cleanup()
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdeep1 committed Sep 14, 2023
1 parent c41b747 commit 0156924
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 18 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ EXTRA_DIST = \
include/coap$(LIBCOAP_API_VERSION)/coap_block_internal.h \
include/coap$(LIBCOAP_API_VERSION)/coap_cache_internal.h \
include/coap$(LIBCOAP_API_VERSION)/coap_crypto_internal.h \
include/coap$(LIBCOAP_API_VERSION)/coap_debug_internal.h \
include/coap$(LIBCOAP_API_VERSION)/coap_dtls_internal.h \
include/coap$(LIBCOAP_API_VERSION)/coap_hashkey_internal.h \
include/coap$(LIBCOAP_API_VERSION)/coap_io_internal.h \
Expand Down
14 changes: 0 additions & 14 deletions include/coap3/coap_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,6 @@ char *coap_string_tls_support(char *buffer, size_t bufsize);
/**
* Print the address into the defined buffer.
*
* Internal Function.
*
* @param address The address to print.
* @param buffer The buffer to print into.
* @param size The size of the buffer to print into.
Expand All @@ -361,8 +359,6 @@ size_t coap_print_addr(const coap_address_t *address,
/**
* Print the IP address into the defined buffer.
*
* Internal Function.
*
* @param address The address to print.
* @param buffer The buffer to print into.
* @param size The size of the buffer to print into.
Expand Down Expand Up @@ -390,14 +386,4 @@ const char *coap_print_ip_addr(const coap_address_t *address,
*/
int coap_debug_set_packet_loss(const char *loss_level);

/**
* Check to see whether a packet should be sent or not.
*
* Internal function
*
* @return @c 1 if packet is to be sent, @c 0 if packet is to be dropped.
*/
int coap_debug_send_packet(void);


#endif /* COAP_DEBUG_H_ */
36 changes: 36 additions & 0 deletions include/coap3/coap_debug_internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* coap_debug_internal.h -- debug utilities
*
* Copyright (C) 2010-2011,2014-2023 Olaf Bergmann <bergmann@tzi.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*
* This file is part of the CoAP library libcoap. Please see README for terms
* of use.
*/

/**
* @file coap_debug_internal.h
* @brief CoAP Logging support internal information
*/

#ifndef COAP_DEBUG_INTERNAL_H_
#define COAP_DEBUG_INTERNAL_H_

/**
* Check to see whether a packet should be sent or not.
*
* Internal function
*
* @return @c 1 if packet is to be sent, @c 0 if packet is to be dropped.
*/
int coap_debug_send_packet(void);

/**
* Reset all the defined logging parameters.
*
* Internal function
*/
void coap_debug_reset(void);

#endif /* COAP_DEBUG_INTERNAL_H_ */
1 change: 1 addition & 0 deletions include/coap3/coap_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ typedef struct oscore_ctx_t oscore_ctx_t;
#if defined(COAP_OSCORE_SUPPORT) || defined(COAP_WS_SUPPORT)
#include "coap_crypto_internal.h"
#endif /* COAP_OSCORE_SUPPORT || COAP_WS_SUPPORT */
#include "coap_debug_internal.h"
#include "coap_dtls_internal.h"
#include "coap_hashkey_internal.h"
#include "coap_io_internal.h"
Expand Down
1 change: 0 additions & 1 deletion libcoap-3.map
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ global:
coap_context_set_psk2;
coap_context_set_psk;
coap_context_set_session_timeout;
coap_debug_send_packet;
coap_debug_set_packet_loss;
coap_decode_var_bytes8;
coap_decode_var_bytes;
Expand Down
1 change: 0 additions & 1 deletion libcoap-3.sym
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ coap_context_set_pki_root_cas
coap_context_set_psk
coap_context_set_psk2
coap_context_set_session_timeout
coap_debug_send_packet
coap_debug_set_packet_loss
coap_decode_var_bytes
coap_decode_var_bytes8
Expand Down
9 changes: 8 additions & 1 deletion man/coap_init.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,18 @@ random number gererators, clocks, TLS libraries etc.
*NOTE:* This should be called after any other lower layer is initialized.
For example, for LwIP, lwip_init() must be called before *coap_startup*().

*NOTE:* After the inital call to *coap_startup*(), subsequent calls are ignored
until *coap_cleanup*() is called.

*Function: coap_cleanup()*

The *coap_cleanup*() function is used to cleanup / free any information set
up by the *coap_startup*() function and should be the last *coap_**() function
called.
called. It is possible to call *coap_startup*() after *coap_cleanup*() to
re-initialize the libcoap logic.

*NOTE:* All other libcoap cleanups should called prior to *coap_cleanup*(), e.g.
*coap_free_context*(3).

FURTHER INFORMATION
-------------------
Expand Down
9 changes: 9 additions & 0 deletions src/coap_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -1304,3 +1304,12 @@ coap_debug_send_packet(void) {
}
return 1;
}

void
coap_debug_reset(void) {
maxlog = COAP_LOG_WARN;
use_fprintf_for_show_pdu = 1;
num_packet_loss_intervals = 0;
packet_loss_level = 0;
send_packet_count = 0;
}
3 changes: 2 additions & 1 deletion src/coap_gnutls.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ typedef enum coap_free_bye_t {
G_CHECK(xx, func); \
} while 0

static coap_log_t dtls_log_level = 0;
static coap_log_t dtls_log_level = COAP_LOG_EMERG;

#if COAP_SERVER_SUPPORT
static int post_client_hello_gnutls_pki(gnutls_session_t g_session);
Expand Down Expand Up @@ -434,6 +434,7 @@ coap_dtls_startup(void) {

void
coap_dtls_shutdown(void) {
coap_dtls_set_log_level(COAP_LOG_EMERG);
}

void *
Expand Down
1 change: 1 addition & 0 deletions src/coap_mbedtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -2481,6 +2481,7 @@ coap_dtls_shutdown(void) {
pki_ciphers = NULL;
processed_ciphers = 0;
#endif /* COAP_CLIENT_SUPPORT */
coap_dtls_set_log_level(COAP_LOG_EMERG);
}

void *
Expand Down
2 changes: 2 additions & 0 deletions src/coap_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -4052,6 +4052,8 @@ coap_cleanup(void) {
coap_mutex_destroy(&m_read_endpoint);
coap_mutex_destroy(&m_persist_add);
#endif /* COAP_CONSTRAINED_STACK */
coap_debug_reset();
coap_started = 0;
}

void
Expand Down
1 change: 1 addition & 0 deletions src/coap_notls.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ coap_dtls_get_tls(const coap_session_t *c_session COAP_UNUSED,

void
coap_dtls_shutdown(void) {
coap_dtls_set_log_level(COAP_LOG_EMERG);
}

void
Expand Down
1 change: 1 addition & 0 deletions src/coap_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ coap_dtls_shutdown(void) {
ssl_engine = NULL;
}
ERR_free_strings();
coap_dtls_set_log_level(COAP_LOG_EMERG);
}

void *
Expand Down
2 changes: 2 additions & 0 deletions src/coap_tinydtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,12 @@ coap_dtls_startup(void) {
/* Valid after TinyDTLS submodule has been updated */
dtls_set_log_handler(dtls_logging);
#endif /* HAVE_DTLS_SET_LOG_HANDLER */
coap_dtls_set_log_level(COAP_LOG_EMERG);
}

void
coap_dtls_shutdown(void) {
coap_dtls_set_log_level(COAP_LOG_EMERG);
}

void *
Expand Down

0 comments on commit 0156924

Please sign in to comment.