libcoap 4.3.0
coap_debug.h
Go to the documentation of this file.
1/*
2 * coap_debug.h -- debug utilities
3 *
4 * Copyright (C) 2010-2011,2014 Olaf Bergmann <bergmann@tzi.org>
5 *
6 * SPDX-License-Identifier: BSD-2-Clause
7 *
8 * This file is part of the CoAP library libcoap. Please see README for terms
9 * of use.
10 */
11
12#ifndef COAP_DEBUG_H_
13#define COAP_DEBUG_H_
14
21#ifndef COAP_DEBUG_FD
25#define COAP_DEBUG_FD stdout
26#endif
27
28#ifndef COAP_ERR_FD
32#define COAP_ERR_FD stderr
33#endif
34
35#ifdef HAVE_SYSLOG_H
36#include <syslog.h>
40typedef short coap_log_t;
41/*
42 LOG_DEBUG+2 gives ciphers in GnuTLS
43 Use COAP_LOG_CIPHERS to output Cipher Info in OpenSSL etc.
44 */
45#define COAP_LOG_CIPHERS (LOG_DEBUG+2)
46#else /* !HAVE_SYSLOG_H */
50#if !defined(RIOT_VERSION)
51typedef enum {
62#else /* RIOT_VERSION */
63/* RIOT defines a subset of the syslog levels in log.h with different
64 * numeric values. The remaining levels are defined here. Note that
65 * output granularity differs from what would be expected when
66 * adhering to the syslog levels.
67 */
68#include <log.h>
69typedef short coap_log_t;
70#define LOG_EMERG (0)
71#define LOG_ALERT (1)
72#define LOG_CRIT (2)
73#define LOG_ERR (3)
74/* LOG_WARNING (4) */
75#define LOG_NOTICE (5)
76/* LOG_INFO (6) */
77/* LOG_DEBUG (7) */
78#define COAP_LOG_CIPHERS (9)
79#endif /* RIOT_VERSION */
80
81#endif /* !HAVE_SYSLOG_H */
82
89
96
103typedef void (*coap_log_handler_t) (coap_log_t level, const char *message);
104
111
117const char *coap_package_name(void);
118
124const char *coap_package_version(void);
125
136#if (defined(__GNUC__))
137void coap_log_impl(coap_log_t level,
138 const char *format, ...) __attribute__ ((format(printf, 2, 3)));
139#else
140void coap_log_impl(coap_log_t level, const char *format, ...);
141#endif
142
143#ifndef coap_log
152#define coap_log(level, ...) do { \
153 if ((int)((level))<=(int)coap_get_log_level()) \
154 coap_log_impl((level), __VA_ARGS__); \
155} while(0)
156#endif
157
158#include "pdu.h"
159
166void coap_set_show_pdu_output(int use_fprintf);
167
176void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu);
177
184
194char *coap_string_tls_version(char *buffer, size_t bufsize);
195
204char *coap_string_tls_support(char *buffer, size_t bufsize);
205
217size_t coap_print_addr(const coap_address_t *address,
218 unsigned char *buffer, size_t size);
219
235int coap_debug_set_packet_loss(const char *loss_level);
236
244int coap_debug_send_packet(void);
245
246
247#endif /* COAP_DEBUG_H_ */
int coap_debug_set_packet_loss(const char *loss_level)
Set the packet loss level for testing.
Definition: coap_debug.c:943
int coap_debug_send_packet(void)
Check to see whether a packet should be sent or not.
Definition: coap_debug.c:983
void coap_set_log_handler(coap_log_handler_t handler)
Add a custom log callback handler.
Definition: coap_debug.c:882
coap_log_t coap_get_log_level(void)
Get the current logging level.
Definition: coap_debug.c:63
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
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
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_t
Pre-defined log levels akin to what is used in syslog with LOG_CIPHERS added.
Definition: coap_debug.h:51
const char * coap_package_version(void)
Get the library package version.
Definition: coap_debug.c:53
void coap_set_log_level(coap_log_t level)
Sets the log level to the specified value.
Definition: coap_debug.c:68
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
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
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
void coap_set_show_pdu_output(int use_fprintf)
Defines the output mode for the coap_show_pdu() function.
Definition: coap_debug.c:58
const char * coap_package_name(void)
Get the library package name.
Definition: coap_debug.c:49
void(* coap_log_handler_t)(coap_log_t level, const char *message)
Logging callback handler definition.
Definition: coap_debug.h:103
@ LOG_ERR
Error.
Definition: coap_debug.h:55
@ LOG_CRIT
Critical.
Definition: coap_debug.h:54
@ LOG_INFO
Information.
Definition: coap_debug.h:58
@ LOG_ALERT
Alert.
Definition: coap_debug.h:53
@ LOG_WARNING
Warning.
Definition: coap_debug.h:56
@ LOG_DEBUG
Debug.
Definition: coap_debug.h:59
@ COAP_LOG_CIPHERS
CipherInfo.
Definition: coap_debug.h:60
@ LOG_NOTICE
Notice.
Definition: coap_debug.h:57
@ LOG_EMERG
Emergency.
Definition: coap_debug.h:52
Pre-defined constants that reflect defaults for CoAP.
multi-purpose address abstraction
Definition: address.h:96
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...