libcoap  4.2.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 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
20 
23 #define COAP_DEBUG_FD stdout
24 #endif
25 
26 #ifndef COAP_ERR_FD
27 
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
45 
47 typedef enum {
57 } coap_log_t;
58 #endif
59 
66 
72 void coap_set_log_level(coap_log_t level);
73 
80 typedef void (*coap_log_handler_t) (coap_log_t level, const char *message);
81 
88 
94 const char *coap_package_name(void);
95 
101 const char *coap_package_version(void);
102 
113 #if (defined(__GNUC__))
114 void coap_log_impl(coap_log_t level,
115  const char *format, ...) __attribute__ ((format(printf, 2, 3)));
116 #else
117 void coap_log_impl(coap_log_t level, const char *format, ...);
118 #endif
119 
120 #ifndef coap_log
121 
129 #define coap_log(level, ...) do { \
130  if ((int)((level))<=(int)coap_get_log_level()) \
131  coap_log_impl((level), __VA_ARGS__); \
132 } while(0)
133 #endif
134 
135 #include "pdu.h"
136 
143 void coap_set_show_pdu_output(int use_fprintf);
144 
153 void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu);
154 
161 
171 char *coap_string_tls_version(char *buffer, size_t bufsize);
172 
173 struct coap_address_t;
174 
186 size_t coap_print_addr(const struct coap_address_t *address,
187  unsigned char *buffer, size_t size);
188 
204 int coap_debug_set_packet_loss(const char *loss_level);
205 
213 int coap_debug_send_packet(void);
214 
215 
216 #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:812
void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu)
Display the contents of the specified pdu.
Definition: coap_debug.c:455
multi-purpose address abstraction
Definition: address.h:62
const char * coap_package_name(void)
Get the library package name.
Definition: coap_debug.c:47
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:161
Debug.
Definition: coap_debug.h:55
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:669
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:758
void(* coap_log_handler_t)(coap_log_t level, const char *message)
Logging call-back handler definition.
Definition: coap_debug.h:80
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
Definition: pdu.h:287
Warning.
Definition: coap_debug.h:52
Notice.
Definition: coap_debug.h:53
Error.
Definition: coap_debug.h:51
void coap_set_show_pdu_output(int use_fprintf)
Defines the output mode for the coap_show_pdu() function.
Definition: coap_debug.c:56
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:662
Pre-defined constants that reflect defaults for CoAP.
coap_log_t
Pre-defined log levels akin to what is used in syslog with LOG_CIPHERS added.
Definition: coap_debug.h:47
const char * coap_package_version(void)
Get the library package version.
Definition: coap_debug.c:51
CipherInfo.
Definition: coap_debug.h:56
coap_log_t coap_get_log_level(void)
Get the current logging level.
Definition: coap_debug.c:61
socklen_t size
size of addr
Definition: address.h:63
void coap_set_log_handler(coap_log_handler_t handler)
Add a custom log callback handler.
Definition: coap_debug.c:753
Emergency.
Definition: coap_debug.h:48
Critical.
Definition: coap_debug.h:50
Information.
Definition: coap_debug.h:54
Alert.
Definition: coap_debug.h:49
int coap_debug_send_packet(void)
Check to see whether a packet should be sent or not.
Definition: coap_debug.c:852