libcoap 4.3.1
coap_debug.h
Go to the documentation of this file.
1/*
2 * coap_debug.h -- debug utilities
3 *
4 * Copyright (C) 2010-2011,2014-2022 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
17#ifndef COAP_DEBUG_H_
18#define COAP_DEBUG_H_
19
27#ifndef COAP_DEBUG_FD
31#define COAP_DEBUG_FD stdout
32#endif
33
34#ifndef COAP_ERR_FD
38#define COAP_ERR_FD stderr
39#endif
40
44typedef int coap_log_t;
45
46#ifdef HAVE_SYSLOG_H
47#include <syslog.h>
48#else
49#if defined(RIOT_VERSION)
50/* RIOT defines a subset of the syslog levels in log.h with different
51 * numeric values. The remaining levels are defined here. Note that
52 * output granularity differs from what would be expected when
53 * adhering to the syslog levels.
54 */
55#include <log.h>
56#endif /* RIOT_VERSION */
57#endif /* HAVE_SYSLOG_H */
58
59#ifndef LOG_EMERG
60# define LOG_EMERG 0
61#endif
62#ifndef LOG_ALERT
63# define LOG_ALERT 1
64#endif
65#ifndef LOG_CRIT
66# define LOG_CRIT 2
67#endif
68#ifndef LOG_ERR
69# define LOG_ERR 3
70#endif
71#ifndef LOG_WARNING
72# define LOG_WARNING 4
73#endif
74#ifndef LOG_NOTICE
75# define LOG_NOTICE 5
76#endif
77#ifndef LOG_INFO
78# define LOG_INFO 6
79#endif
80#ifndef LOG_DEBUG
81# define LOG_DEBUG 7
82#endif
83/*
84 LOG_DEBUG+2 gives ciphers in GnuTLS
85 Use COAP_LOG_CIPHERS to output Cipher Info in OpenSSL etc.
86 */
87#define COAP_LOG_CIPHERS (LOG_DEBUG+2)
88
95
102
109typedef void (*coap_log_handler_t) (coap_log_t level, const char *message);
110
117
123const char *coap_package_name(void);
124
130const char *coap_package_version(void);
131
137const char *coap_package_build(void);
138
149#if (defined(__GNUC__))
150void coap_log_impl(coap_log_t level,
151 const char *format, ...) __attribute__ ((format(printf, 2, 3)));
152#else
153void coap_log_impl(coap_log_t level, const char *format, ...);
154#endif
155
156#ifndef coap_log
165#define coap_log(level, ...) do { \
166 if ((int)((level))<=(int)coap_get_log_level()) \
167 coap_log_impl((level), __VA_ARGS__); \
168} while(0)
169#endif
170
171#include "pdu.h"
172
179void coap_set_show_pdu_output(int use_fprintf);
180
189void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu);
190
197
207char *coap_string_tls_version(char *buffer, size_t bufsize);
208
217char *coap_string_tls_support(char *buffer, size_t bufsize);
218
230size_t coap_print_addr(const coap_address_t *address,
231 unsigned char *buffer, size_t size);
232
248int coap_debug_set_packet_loss(const char *loss_level);
249
257int coap_debug_send_packet(void);
258
259
260#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:991
int coap_debug_send_packet(void)
Check to see whether a packet should be sent or not.
Definition: coap_debug.c:1031
void coap_set_log_handler(coap_log_handler_t handler)
Add a custom log callback handler.
Definition: coap_debug.c:930
coap_log_t coap_get_log_level(void)
Get the current logging level.
Definition: coap_debug.c:76
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:785
int coap_log_t
Logging type.
Definition: coap_debug.h:44
void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu)
Display the contents of the specified pdu.
Definition: coap_debug.c:523
char * coap_string_tls_support(char *buffer, size_t bufsize)
Build a string containing the current (D)TLS library support.
Definition: coap_debug.c:877
const char * coap_package_version(void)
Get the library package version.
Definition: coap_debug.c:58
void coap_set_log_level(coap_log_t level)
Sets the log level to the specified value.
Definition: coap_debug.c:81
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:935
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:186
const char * coap_package_build(void)
Get the library package build.
Definition: coap_debug.c:62
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:778
void coap_set_show_pdu_output(int use_fprintf)
Defines the output mode for the coap_show_pdu() function.
Definition: coap_debug.c:71
const char * coap_package_name(void)
Get the library package name.
Definition: coap_debug.c:54
void(* coap_log_handler_t)(coap_log_t level, const char *message)
Logging callback handler definition.
Definition: coap_debug.h:109
Pre-defined constants that reflect defaults for CoAP.
multi-purpose address abstraction
Definition: coap_address.h:96
structure for CoAP PDUs