libcoap  4.3.0beta
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  * This file is part of the CoAP library libcoap. Please see README for terms
7  * of use.
8  */
9 
10 #ifndef COAP_DEBUG_H_
11 #define COAP_DEBUG_H_
12 
19 #ifndef COAP_DEBUG_FD
23 #define COAP_DEBUG_FD stdout
24 #endif
25 
26 #ifndef COAP_ERR_FD
30 #define COAP_ERR_FD stderr
31 #endif
32 
33 #ifdef HAVE_SYSLOG_H
34 #include <syslog.h>
38 typedef short coap_log_t;
39 /*
40  LOG_DEBUG+2 gives ciphers in GnuTLS
41  Use COAP_LOG_CIPHERS to output Cipher Info in OpenSSL etc.
42  */
43 #define COAP_LOG_CIPHERS (LOG_DEBUG+2)
44 #else /* !HAVE_SYSLOG_H */
48 #if !defined(RIOT_VERSION)
49 typedef enum {
60 #else /* RIOT_VERSION */
61 /* RIOT defines a subset of the syslog levels in log.h with different
62  * numeric values. The remaining levels are defined here. Note that
63  * output granularity differs from what would be expected when
64  * adhering to the syslog levels.
65  */
66 #include <log.h>
67 typedef short coap_log_t;
68 #define LOG_EMERG (0)
69 #define LOG_ALERT (1)
70 #define LOG_CRIT (2)
71 #define LOG_ERR (3)
72 /* LOG_WARNING (4) */
73 #define LOG_NOTICE (5)
74 /* LOG_INFO (6) */
75 /* LOG_DEBUG (7) */
76 #define COAP_LOG_CIPHERS (9)
77 #endif /* RIOT_VERSION */
78 
79 #endif /* !HAVE_SYSLOG_H */
80 
87 
93 void coap_set_log_level(coap_log_t level);
94 
101 typedef void (*coap_log_handler_t) (coap_log_t level, const char *message);
102 
109 
115 const char *coap_package_name(void);
116 
122 const char *coap_package_version(void);
123 
134 #if (defined(__GNUC__))
135 void coap_log_impl(coap_log_t level,
136  const char *format, ...) __attribute__ ((format(printf, 2, 3)));
137 #else
138 void coap_log_impl(coap_log_t level, const char *format, ...);
139 #endif
140 
141 #ifndef coap_log
150 #define coap_log(level, ...) do { \
151  if ((int)((level))<=(int)coap_get_log_level()) \
152  coap_log_impl((level), __VA_ARGS__); \
153 } while(0)
154 #endif
155 
156 #include "pdu.h"
157 
164 void coap_set_show_pdu_output(int use_fprintf);
165 
174 void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu);
175 
182 
192 char *coap_string_tls_version(char *buffer, size_t bufsize);
193 
205 size_t coap_print_addr(const struct coap_address_t *address,
206  unsigned char *buffer, size_t size);
207 
223 int coap_debug_set_packet_loss(const char *loss_level);
224 
232 int coap_debug_send_packet(void);
233 
234 
235 #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:866
int coap_debug_send_packet(void)
Check to see whether a packet should be sent or not.
Definition: coap_debug.c:906
void coap_set_log_handler(coap_log_handler_t handler)
Add a custom log callback handler.
Definition: coap_debug.c:805
const char * coap_package_name(void)
Get the library package name.
Definition: coap_debug.c:47
coap_log_t coap_get_log_level(void)
Get the current logging level.
Definition: coap_debug.c:61
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:711
void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu)
Display the contents of the specified pdu.
Definition: coap_debug.c:481
coap_log_t
Pre-defined log levels akin to what is used in syslog with LOG_CIPHERS added.
Definition: coap_debug.h:49
size_t coap_print_addr(const struct coap_address_t *address, unsigned char *buffer, size_t size)
Print the address into the defined buffer.
Definition: coap_debug.c:167
void coap_set_log_level(coap_log_t level)
Sets the log level to the specified value.
Definition: coap_debug.c:66
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:810
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:704
void coap_set_show_pdu_output(int use_fprintf)
Defines the output mode for the coap_show_pdu() function.
Definition: coap_debug.c:56
const char * coap_package_version(void)
Get the library package version.
Definition: coap_debug.c:51
void(* coap_log_handler_t)(coap_log_t level, const char *message)
Logging callback handler definition.
Definition: coap_debug.h:101
@ LOG_ERR
Error.
Definition: coap_debug.h:53
@ LOG_CRIT
Critical.
Definition: coap_debug.h:52
@ LOG_INFO
Information.
Definition: coap_debug.h:56
@ LOG_ALERT
Alert.
Definition: coap_debug.h:51
@ LOG_WARNING
Warning.
Definition: coap_debug.h:54
@ LOG_DEBUG
Debug.
Definition: coap_debug.h:57
@ COAP_LOG_CIPHERS
CipherInfo.
Definition: coap_debug.h:58
@ LOG_NOTICE
Notice.
Definition: coap_debug.h:55
@ LOG_EMERG
Emergency.
Definition: coap_debug.h:50
Pre-defined constants that reflect defaults for CoAP.
multi-purpose address abstraction
Definition: address.h:94
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
Definition: pdu.h:287