mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-06 17:52:54 +03:00
This fix is in preparation for the full coap_new_client_session_psk2() and coap_context_set_psk2() functions. Structures are updated with the necessary information, as well as provide the high level support. As new sessions are now created for every genuine incoming session (#333), coap_context_t will only hold the initial information provided by coap_context_set_psk2() (server mode), but if there is any updated (triggered by SNI or Indentity), this will be kept in coap_session_t. Likewise, the client initial information will be kept in the coap_session_t, and if modified (triggered by Hint) will be kept separately in coap_session_t. This change does not include the support required in the DTLS interface modules other than changes required to make the code compilable and still run the existing examples - so it is a standalone change. Makefile.am: Make coap_dtls_context_set_cpsk, coap_dtls_context_set_spsk, coap_session_refresh_psk_key and coap_session_refresh_psk_hint hidden Remove coap_dtls_context_set_psk include/coap2/*.h: Replace call-back with callback for consistency include/coap2/coap_dtls.h: Include coap_dtls_cpsk_key_t and coap_dtls_spsk_key_t definitions Define coap_dtls_spsk_key_t for the new coap_*_psk2 functions. Include all the new call back function definitions include/coap2/coap_session.h: Update coap_session_t with the new PSK information Define coap_new_client_session_psk2(), coap_session_refresh_psk_key() and coap_session_refresh_psk_hint() functions include/coap2/net.h: Update coap_context_t with the new PSK information Define the coap_context_set_psk2() function include/coap2/str.h: Add in a new struct coap_bin_const_t Define new functions coap_new_bin_const(), coap_delete_bin_const() and coap_binary_equal(). libcoap-2.{map|sym} Expose the new coap_context_set_psk2, coap_new_client_session_psk2, coap_new_bin_const and coap_delete_bin_const functions src/coap_gnutls.c: src/coap_notls.c: src/coap_tinydtls.c: Replace coap_dtls_context_set_psk() with coap_dtls_context_set_spsk() and coap_dtls_context_set_cpsk() src/coap_openssl.c: Replace coap_dtls_context_set_psk() with coap_dtls_context_set_spsk() and coap_dtls_context_set_cpsk() Update the SSL_CTX_use* and SSL_set_* functions with the new variable locations src/coap_session.c: Free off new information on coap_session_t in coap_session_mfree() Build parameters for coap_new_client_session_psk2() in coap_new_client_session_psk() and call coap_new_client_session_psk2() instead of coap_session_create_client(). Create new coap_new_client_session_psk2(). Create new coap_session_refresh_psk_key() (will be used when DTLS interface code is updated src/net.c: Update coap_get_session_client_psk() to use the new PSK locations. Update coap_get_session_server_psk() to use the new PSK locations. Update coap_get_session_server_hint() to use the new PSK locations. Build parameters for coap_context_set_psk2() in coap_context_set_psk() and call coap_context_set_psk2(). Create new coap_context_set_psk2(). Cleanup usage of old PSK information in coap_free_context() src/str.c: Code for coap_new_bin_const() and coap_delete_bin_const() functions
217 lines
5.4 KiB
C
217 lines
5.4 KiB
C
/*
|
|
* coap_debug.h -- debug utilities
|
|
*
|
|
* Copyright (C) 2010-2011,2014 Olaf Bergmann <bergmann@tzi.org>
|
|
*
|
|
* This file is part of the CoAP library libcoap. Please see README for terms
|
|
* of use.
|
|
*/
|
|
|
|
#ifndef COAP_DEBUG_H_
|
|
#define COAP_DEBUG_H_
|
|
|
|
/**
|
|
* @defgroup logging Logging Support
|
|
* API functions for logging support
|
|
* @{
|
|
*/
|
|
|
|
#ifndef COAP_DEBUG_FD
|
|
/**
|
|
* Used for output for @c LOG_DEBUG to @c LOG_ERR.
|
|
*/
|
|
#define COAP_DEBUG_FD stdout
|
|
#endif
|
|
|
|
#ifndef COAP_ERR_FD
|
|
/**
|
|
* Used for output for @c LOG_CRIT to @c LOG_EMERG.
|
|
*/
|
|
#define COAP_ERR_FD stderr
|
|
#endif
|
|
|
|
#ifdef HAVE_SYSLOG_H
|
|
#include <syslog.h>
|
|
/**
|
|
* Logging type. One of LOG_* from @b syslog.
|
|
*/
|
|
typedef short coap_log_t;
|
|
/*
|
|
LOG_DEBUG+2 gives ciphers in GnuTLS
|
|
Use COAP_LOG_CIPHERS to output Cipher Info in OpenSSL etc.
|
|
*/
|
|
#define COAP_LOG_CIPHERS (LOG_DEBUG+2)
|
|
#else
|
|
/** Pre-defined log levels akin to what is used in \b syslog
|
|
with LOG_CIPHERS added. */
|
|
typedef enum {
|
|
LOG_EMERG=0, /**< Emergency */
|
|
LOG_ALERT, /**< Alert */
|
|
LOG_CRIT, /**< Critical */
|
|
LOG_ERR, /**< Error */
|
|
LOG_WARNING, /**< Warning */
|
|
LOG_NOTICE, /**< Notice */
|
|
LOG_INFO, /**< Information */
|
|
LOG_DEBUG, /**< Debug */
|
|
COAP_LOG_CIPHERS=LOG_DEBUG+2 /**< CipherInfo */
|
|
} coap_log_t;
|
|
#endif
|
|
|
|
/**
|
|
* Get the current logging level.
|
|
*
|
|
* @return One of the LOG_* values.
|
|
*/
|
|
coap_log_t coap_get_log_level(void);
|
|
|
|
/**
|
|
* Sets the log level to the specified value.
|
|
*
|
|
* @param level One of the LOG_* values.
|
|
*/
|
|
void coap_set_log_level(coap_log_t level);
|
|
|
|
/**
|
|
* Logging callback handler definition.
|
|
*
|
|
* @param level One of the LOG_* values.
|
|
* @param message Zero-terminated string message to log.
|
|
*/
|
|
typedef void (*coap_log_handler_t) (coap_log_t level, const char *message);
|
|
|
|
/**
|
|
* Add a custom log callback handler.
|
|
*
|
|
* @param handler The logging handler to use or @p NULL to use default handler.
|
|
*/
|
|
void coap_set_log_handler(coap_log_handler_t handler);
|
|
|
|
/**
|
|
* Get the library package name.
|
|
*
|
|
* @return Zero-terminated string with the name of this library.
|
|
*/
|
|
const char *coap_package_name(void);
|
|
|
|
/**
|
|
* Get the library package version.
|
|
*
|
|
* @return Zero-terminated string with the library version.
|
|
*/
|
|
const char *coap_package_version(void);
|
|
|
|
/**
|
|
* Writes the given text to @c COAP_ERR_FD (for @p level <= @c LOG_CRIT) or @c
|
|
* COAP_DEBUG_FD (for @p level >= @c LOG_ERR). The text is output only when
|
|
* @p level is below or equal to the log level that set by coap_set_log_level().
|
|
*
|
|
* Internal function.
|
|
*
|
|
* @param level One of the LOG_* values.
|
|
& @param format The format string to use.
|
|
*/
|
|
#if (defined(__GNUC__))
|
|
void coap_log_impl(coap_log_t level,
|
|
const char *format, ...) __attribute__ ((format(printf, 2, 3)));
|
|
#else
|
|
void coap_log_impl(coap_log_t level, const char *format, ...);
|
|
#endif
|
|
|
|
#ifndef coap_log
|
|
/**
|
|
* Logging function.
|
|
* Writes the given text to @c COAP_ERR_FD (for @p level <= @c LOG_CRIT) or @c
|
|
* COAP_DEBUG_FD (for @p level >= @c LOG_ERR). The text is output only when
|
|
* @p level is below or equal to the log level that set by coap_set_log_level().
|
|
*
|
|
* @param level One of the LOG_* values.
|
|
*/
|
|
#define coap_log(level, ...) do { \
|
|
if ((int)((level))<=(int)coap_get_log_level()) \
|
|
coap_log_impl((level), __VA_ARGS__); \
|
|
} while(0)
|
|
#endif
|
|
|
|
#include "pdu.h"
|
|
|
|
/**
|
|
* Defines the output mode for the coap_show_pdu() function.
|
|
*
|
|
* @param use_fprintf @p 1 if the output is to use fprintf() (the default)
|
|
* @p 0 if the output is to use coap_log().
|
|
*/
|
|
void coap_set_show_pdu_output(int use_fprintf);
|
|
|
|
/**
|
|
* Display the contents of the specified @p pdu.
|
|
* Note: The output method of coap_show_pdu() is dependent on the setting of
|
|
* coap_set_show_pdu_output().
|
|
*
|
|
* @param level The required minimum logging level.
|
|
* @param pdu The PDU to decode.
|
|
*/
|
|
void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu);
|
|
|
|
/**
|
|
* Display the current (D)TLS library linked with and built for version.
|
|
*
|
|
* @param level The required minimum logging level.
|
|
*/
|
|
void coap_show_tls_version(coap_log_t level);
|
|
|
|
/**
|
|
* Build a string containing the current (D)TLS library linked with and
|
|
* built for version.
|
|
*
|
|
* @param buffer The buffer to put the string into.
|
|
* @param bufsize The size of the buffer to put the string into.
|
|
*
|
|
* @return A pointer to the provided buffer.
|
|
*/
|
|
char *coap_string_tls_version(char *buffer, size_t bufsize);
|
|
|
|
struct coap_address_t;
|
|
|
|
/**
|
|
* 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.
|
|
*
|
|
* @return The amount written into the buffer.
|
|
*/
|
|
size_t coap_print_addr(const struct coap_address_t *address,
|
|
unsigned char *buffer, size_t size);
|
|
|
|
/** @} */
|
|
|
|
/**
|
|
* Set the packet loss level for testing. This can be in one of two forms.
|
|
*
|
|
* Percentage : 0% to 100%. Use the specified probability.
|
|
* 0% is send all packets, 100% is drop all packets.
|
|
*
|
|
* List: A comma separated list of numbers or number ranges that are the
|
|
* packets to drop.
|
|
*
|
|
* @param loss_level The defined loss level (percentage or list).
|
|
*
|
|
* @return @c 1 If loss level set, @c 0 if there is an error.
|
|
*/
|
|
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_ */
|