#include "uni_log.h"
#include "uni_log.h"
#include <syslog.h>
#include
#include "pdu.h"
#include "pdu.h"
#define COAP_DEBUG_H_
#define COAP_DEBUG_FD stdout
/** * Used for output for @c LOG_DEBUG to @c LOG_ERR. */
#define COAP_ERR_FD stderr
/** * Used for output for @c LOG_CRIT to @c LOG_EMERG. */
#define coap_log(level, ...) do { \
if ((int)((level))<=(int)coap_get_log_level()) \
PR_DEBUG(__VA_ARGS__); \
} while(0)
/** * Logging function. * Writes the given text to @c COAP_ERR_FD (for @p level <= @c LOG_CRIT) or @c * COAP_DEBUG_FD (for @p level >= @c LOG_ERR). The text is output only when * @p level is below or equal to the log level that set by coap_set_log_level(). * * @param level One of the LOG_* values. */
void coap_set_log_level(coap_log_t level);
/** * Sets the log level to the specified value. * * @param level One of the LOG_* values. */
void coap_set_log_handler(coap_log_handler_t handler);
/** * Add a custom log callback handler. * * @param handler The logging handler to use or @p NULL to use default handler. */
void coap_log_impl(coap_log_t level,
const char *format, ...) __attribute__ ((format(printf, 2, 3)));
void coap_log_impl(coap_log_t level, const char *format, ...);
void coap_set_show_pdu_output(int use_fprintf);
/** * Defines the output mode for the coap_show_pdu() function. * * @param use_fprintf @p 1 if the output is to use fprintf() (the default) * @p 0 if the output is to use coap_log(). */
void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu);
/** * Display the contents of the specified @p pdu. * Note: The output method of coap_show_pdu() is dependent on the setting of * coap_set_show_pdu_output(). * * @param level The required minimum logging level. * @param pdu The PDU to decode. */
void coap_show_tls_version(coap_log_t level);
/** * Display the current (D)TLS library linked with and built for version. * * @param level The required minimum logging level. */
size_t coap_print_addr(const struct coap_address_t *address,
unsigned char *buffer, size_t size);
/** * Print the address into the defined buffer. * * Internal Function. * * @param address The address to print. * @param buffer The buffer to print into. * @param size The size of the buffer to print into. * * @return The amount written into the buffer. */
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. * * @param loss_level The defined loss level (percentage or list). * * @return @c 1 If loss level set, @c 0 if there is an error. */
int coap_debug_send_packet(void);
/** * Check to see whether a packet should be sent or not. * * Internal function * * @return @c 1 if packet is to be sent, @c 0 if packet is to be dropped. */
coap_log_t coap_get_log_level(void);
/** * Get the current logging level. * * @return One of the LOG_* values. */
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. * * @param buffer The buffer to put the string into. * @param bufsize The size of the buffer to put the string into. * * @return A pointer to the provided buffer. */
struct coap_address_t;
const char *coap_package_name(void);
/** * Get the library package name. * * @return Zero-terminated string with the name of this library. */
const char *coap_package_version(void);
/** * Get the library package version. * * @return Zero-terminated string with the library version. */
typedef short coap_log_t;
#else
/** Pre-defined log levels akin to what is used in \b syslog. */
typedef enum {
LOG_EMERG=0, /**< Emergency */
LOG_ALERT, /**< Alert */
LOG_CRIT, /**< Critical */
LOG_ERR, /**< Error */
LOG_WARNING, /**< Warning */
LOG_NOTICE, /**< Notice */
LOG_INFO, /**< Information */
LOG_DEBUG /**< Debug */
} coap_log_t;
/** * Logging type. One of LOG_* from @b syslog. */
typedef void (*coap_log_handler_t) (coap_log_t level, const char *message);
/** * Logging call-back handler definition. * * @param level One of the LOG_* values. * @param message Zero-terminated string message to log. */