coap_debug.h
Go to the documentation of this file.
/*
* coap_debug.h -- debug utilities
*
* Copyright (C) 2010-2011,2014 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.
*/
#ifndef COAP_DEBUG_H_
#define COAP_DEBUG_H_
#ifndef COAP_DEBUG_FD
#define COAP_DEBUG_FD stdout
#endif
#ifndef COAP_ERR_FD
#define COAP_ERR_FD stderr
#endif
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
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 /* !HAVE_SYSLOG_H */
#if !defined(RIOT_VERSION)
typedef enum {
LOG_EMERG=0,
LOG_ALERT,
LOG_CRIT,
LOG_ERR,
LOG_WARNING,
LOG_NOTICE,
LOG_INFO,
LOG_DEBUG,
COAP_LOG_CIPHERS=LOG_DEBUG+2
} coap_log_t;
#else /* RIOT_VERSION */
/* RIOT defines a subset of the syslog levels in log.h with different
* numeric values. The remaining levels are defined here. Note that
* output granularity differs from what would be expected when
* adhering to the syslog levels.
*/
#include <log.h>
typedef short coap_log_t;
#define LOG_EMERG (0)
#define LOG_ALERT (1)
#define LOG_CRIT (2)
#define LOG_ERR (3)
/* LOG_WARNING (4) */
#define LOG_NOTICE (5)
/* LOG_INFO (6) */
/* LOG_DEBUG (7) */
#define COAP_LOG_CIPHERS (9)
#endif /* RIOT_VERSION */
#endif /* !HAVE_SYSLOG_H */
coap_log_t coap_get_log_level(void);
void coap_set_log_level(coap_log_t level);
typedef void (*coap_log_handler_t) (coap_log_t level, const char *message);
void coap_set_log_handler(coap_log_handler_t handler);
const char *coap_package_name(void);
const char *coap_package_version(void);
#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
#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"
void coap_set_show_pdu_output(int use_fprintf);
void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu);
void coap_show_tls_version(coap_log_t level);
char *coap_string_tls_version(char *buffer, size_t bufsize);
char *coap_string_tls_support(char *buffer, size_t bufsize);
size_t coap_print_addr(const coap_address_t *address,
unsigned char *buffer, size_t size);
int coap_debug_set_packet_loss(const char *loss_level);
int coap_debug_send_packet(void);
#endif /* COAP_DEBUG_H_ */
coap_debug_set_packet_loss
int coap_debug_set_packet_loss(const char *loss_level)
Set the packet loss level for testing.
Definition: coap_debug.c:943
coap_debug_send_packet
int coap_debug_send_packet(void)
Check to see whether a packet should be sent or not.
Definition: coap_debug.c:983
coap_set_log_handler
void coap_set_log_handler(coap_log_handler_t handler)
Add a custom log callback handler.
Definition: coap_debug.c:882
coap_package_name
const char * coap_package_name(void)
Get the library package name.
Definition: coap_debug.c:49
coap_get_log_level
coap_log_t coap_get_log_level(void)
Get the current logging level.
Definition: coap_debug.c:63
coap_string_tls_version
char * coap_string_tls_version(char *buffer, size_t bufsize)
Build a string containing the current (D)TLS library linked with and built for version.
Definition: coap_debug.c:753
coap_show_pdu
void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu)
Display the contents of the specified pdu.
Definition: coap_debug.c:507
coap_log_t
coap_log_t
Pre-defined log levels akin to what is used in syslog with LOG_CIPHERS added.
Definition: coap_debug.h:51
coap_set_log_level
void coap_set_log_level(coap_log_t level)
Sets the log level to the specified value.
Definition: coap_debug.c:68
coap_log_impl
void coap_log_impl(coap_log_t level, const char *format,...)
Writes the given text to COAP_ERR_FD (for level <= LOG_CRIT) or COAP_DEBUG_FD (for level >= LOG_ERR).
Definition: coap_debug.c:887
coap_print_addr
size_t coap_print_addr(const coap_address_t *address, unsigned char *buffer, size_t size)
Print the address into the defined buffer.
Definition: coap_debug.c:173
coap_show_tls_version
void coap_show_tls_version(coap_log_t level)
Display the current (D)TLS library linked with and built for version.
Definition: coap_debug.c:746
coap_set_show_pdu_output
void coap_set_show_pdu_output(int use_fprintf)
Defines the output mode for the coap_show_pdu() function.
Definition: coap_debug.c:58
coap_package_version
const char * coap_package_version(void)
Get the library package version.
Definition: coap_debug.c:53
coap_string_tls_support
char * coap_string_tls_support(char *buffer, size_t bufsize)
Build a string containing the current (D)TLS library support.
Definition: coap_debug.c:845
coap_log_handler_t
void(* coap_log_handler_t)(coap_log_t level, const char *message)
Logging callback handler definition.
Definition: coap_debug.h:103
LOG_ERR
@ LOG_ERR
Error.
Definition: coap_debug.h:55
LOG_CRIT
@ LOG_CRIT
Critical.
Definition: coap_debug.h:54
LOG_INFO
@ LOG_INFO
Information.
Definition: coap_debug.h:58
LOG_ALERT
@ LOG_ALERT
Alert.
Definition: coap_debug.h:53
LOG_WARNING
@ LOG_WARNING
Warning.
Definition: coap_debug.h:56
LOG_DEBUG
@ LOG_DEBUG
Debug.
Definition: coap_debug.h:59
COAP_LOG_CIPHERS
@ COAP_LOG_CIPHERS
CipherInfo.
Definition: coap_debug.h:60
LOG_NOTICE
@ LOG_NOTICE
Notice.
Definition: coap_debug.h:57
LOG_EMERG
@ LOG_EMERG
Emergency.
Definition: coap_debug.h:52
pdu.h
Pre-defined constants that reflect defaults for CoAP.
coap_address_t
multi-purpose address abstraction
Definition: address.h:96
coap_pdu_t
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
Definition: coap_pdu_internal.h:94