libcoap  4.2.0rc3
debug.c File Reference
#include "coap_config.h"
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "libcoap.h"
#include "block.h"
#include "debug.h"
#include "encode.h"
#include "net.h"
+ Include dependency graph for debug.c:

Go to the source code of this file.

Data Structures

struct  packet_num_interval
 

Macros

#define min(a, b)   ((a) < (b) ? (a) : (b))
 
#define COAP_DO_SHOW_OUTPUT_LINE
 

Functions

const char * coap_package_name (void)
 Get the library package name. More...
 
const char * coap_package_version (void)
 Get the library package version. More...
 
void coap_set_show_pdu_output (int use_fprintf)
 Defines the output mode for the coap_show_pdu() function. More...
 
coap_log_t coap_get_log_level (void)
 Get the current logging level. More...
 
void coap_set_log_level (coap_log_t level)
 Sets the log level to the specified value. More...
 
COAP_STATIC_INLINE size_t print_timestamp (char *s, size_t len, coap_tick_t t)
 
static size_t strnlen (const char *s, size_t maxlen)
 A length-safe strlen() fake. More...
 
static size_t print_readable (const uint8_t *data, size_t len, unsigned char *result, size_t buflen, int encode_always)
 
size_t coap_print_addr (const struct coap_address_t *addr, unsigned char *buf, size_t len)
 Print the address into the defined buffer. More...
 
static const char * msg_type_string (uint16_t t)
 Returns a textual description of the message type t. More...
 
static const char * msg_code_string (uint16_t c)
 Returns a textual description of the method or response code. More...
 
static const char * msg_option_string (uint8_t code, uint16_t option_type)
 Returns a textual description of the option name. More...
 
static unsigned int print_content_format (unsigned int format_type, unsigned char *result, unsigned int buflen)
 
COAP_STATIC_INLINE int is_binary (int content_format)
 Returns 1 if the given content_format is either unknown or known to carry binary data. More...
 
void coap_show_pdu (coap_log_t level, const coap_pdu_t *pdu)
 Display the contents of the specified pdu. More...
 
void coap_show_tls_version (coap_log_t level)
 Display the current (D)TLS library linked with and built for version. More...
 
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. More...
 
void coap_set_log_handler (coap_log_handler_t handler)
 Add a custom log callback handler. More...
 
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). More...
 
int coap_debug_set_packet_loss (const char *loss_level)
 Set the packet loss level for testing. More...
 
int coap_debug_send_packet (void)
 Check to see whether a packet should be sent or not. More...
 

Variables

static coap_log_t maxlog = LOG_WARNING
 
static int use_fprintf_for_show_pdu = 1
 
static const char * loglevels []
 
static coap_log_handler_t log_handler = NULL
 
static struct packet_num_interval packet_loss_intervals [10]
 
static int num_packet_loss_intervals = 0
 
static int packet_loss_level = 0
 
static int send_packet_count = 0
 

Macro Definition Documentation

◆ COAP_DO_SHOW_OUTPUT_LINE

#define COAP_DO_SHOW_OUTPUT_LINE
Value:
do { \
fprintf(COAP_DEBUG_FD, "%s", outbuf); \
} \
else { \
coap_log(level, "%s", outbuf); \
} \
} while (0)
static int use_fprintf_for_show_pdu
Definition: debug.c:55
#define COAP_DEBUG_FD
Used for output for LOG_DEBUG to LOG_ERR.
Definition: debug.h:23

Definition at line 450 of file debug.c.

◆ min

#define min (   a,
 
)    ((a) < (b) ? (a) : (b))

Definition at line 167 of file debug.c.

Function Documentation

◆ coap_debug_send_packet()

int coap_debug_send_packet ( void  )

Check to see whether a packet should be sent or not.

Internal function

Returns
1 if packet is to be sent, 0 if packet is to be dropped.

Definition at line 832 of file debug.c.

+ Here is the caller graph for this function:

◆ coap_debug_set_packet_loss()

int coap_debug_set_packet_loss ( const char *  loss_level)

Set the packet loss level for testing.

This can be in one of two forms.

Percentage : 0% to 100%. Use the specified probability. 0% is send all packets, 100% is drop all packets.

List: A comma separated list of numbers or number ranges that are the packets to drop.

Parameters
loss_levelThe defined loss level (percentage or list).
Returns
1 If loss level set, 0 if there is an error.

Definition at line 792 of file debug.c.

◆ is_binary()

COAP_STATIC_INLINE int is_binary ( int  content_format)

Returns 1 if the given content_format is either unknown or known to carry binary data.

The return value 0 hence indicates printable data which is also assumed if content_format is 01.

Definition at line 442 of file debug.c.

+ Here is the caller graph for this function:

◆ msg_code_string()

static const char* msg_code_string ( uint16_t  c)
static

Returns a textual description of the method or response code.

Definition at line 282 of file debug.c.

+ Here is the caller graph for this function:

◆ msg_option_string()

static const char* msg_option_string ( uint8_t  code,
uint16_t  option_type 
)
static

Returns a textual description of the option name.

Definition at line 301 of file debug.c.

+ Here is the caller graph for this function:

◆ msg_type_string()

static const char* msg_type_string ( uint16_t  t)
static

Returns a textual description of the message type t.

Definition at line 274 of file debug.c.

+ Here is the caller graph for this function:

◆ print_content_format()

static unsigned int print_content_format ( unsigned int  format_type,
unsigned char *  result,
unsigned int  buflen 
)
static

Definition at line 389 of file debug.c.

+ Here is the caller graph for this function:

◆ print_readable()

static size_t print_readable ( const uint8_t data,
size_t  len,
unsigned char *  result,
size_t  buflen,
int  encode_always 
)
static

Definition at line 130 of file debug.c.

+ Here is the caller graph for this function:

◆ print_timestamp()

COAP_STATIC_INLINE size_t print_timestamp ( char *  s,
size_t  len,
coap_tick_t  t 
)

Definition at line 98 of file debug.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ strnlen()

static size_t strnlen ( const char *  s,
size_t  maxlen 
)
inlinestatic

A length-safe strlen() fake.

Parameters
sThe string to count characters != 0.
maxlenThe maximum length of s.
Returns
The length of s.

Definition at line 121 of file debug.c.

+ Here is the caller graph for this function:

Variable Documentation

◆ log_handler

coap_log_handler_t log_handler = NULL
static

Definition at line 739 of file debug.c.

◆ loglevels

const char* loglevels[]
static
Initial value:
= {
"EMRG", "ALRT", "CRIT", "ERR ", "WARN", "NOTE", "INFO", "DEBG"
}

Definition at line 81 of file debug.c.

◆ maxlog

coap_log_t maxlog = LOG_WARNING
static

Definition at line 53 of file debug.c.

◆ num_packet_loss_intervals

int num_packet_loss_intervals = 0
static

Definition at line 788 of file debug.c.

◆ packet_loss_intervals

struct packet_num_interval packet_loss_intervals[10]
static

◆ packet_loss_level

int packet_loss_level = 0
static

Definition at line 789 of file debug.c.

◆ send_packet_count

int send_packet_count = 0
static

Definition at line 790 of file debug.c.

◆ use_fprintf_for_show_pdu

int use_fprintf_for_show_pdu = 1
static

Definition at line 55 of file debug.c.