wslog: Add ws_log_buffer()
Use the new API with dot11decrypt debug.
This commit is contained in:
parent
a918325324
commit
a34a234cf2
|
@ -368,6 +368,7 @@ libwsutil.so.0 libwsutil0 #MINVER#
|
|||
ws_init_sockets@Base 3.1.0
|
||||
ws_log@Base 3.5.0
|
||||
ws_log_add_custom_file@Base 3.5.0
|
||||
ws_log_buffer_full@Base 3.5.1
|
||||
ws_log_default_writer@Base 3.5.0
|
||||
ws_log_full@Base 3.5.0
|
||||
ws_log_get_level@Base 3.5.0
|
||||
|
|
|
@ -18,24 +18,13 @@
|
|||
/* Debug section: internal function to print debug information */
|
||||
/* */
|
||||
#ifndef WS_DISABLE_DEBUG
|
||||
#include <epan/to_str.h>
|
||||
|
||||
static inline void
|
||||
debug_dump(const char *file, int line, const char* func,
|
||||
const char* x, const guint8* y, size_t z, enum ws_log_level level)
|
||||
{
|
||||
if (!ws_log_msg_is_active(WS_LOG_DOMAIN, level))
|
||||
return;
|
||||
char* tmp_str = bytes_to_str(NULL, y, (z));
|
||||
ws_log_write_always_full(WS_LOG_DOMAIN, level, file, line, func, "%s: %s", x, tmp_str);
|
||||
wmem_free(NULL, tmp_str);
|
||||
}
|
||||
|
||||
#define DEBUG_DUMP(x, y, z, level) debug_dump(__FILE__, __LINE__, G_STRFUNC, x, y, z, level)
|
||||
#define DEBUG_DUMP(name, ptr, size, level) \
|
||||
ws_log_buffer_full(WS_LOG_DOMAIN, level, __FILE__, __LINE__, G_STRFUNC, ptr, size, 72, name);
|
||||
|
||||
#else /* defined WS_DISABLE_DEBUG */
|
||||
|
||||
#define DEBUG_DUMP(x, y, z, level)
|
||||
#define DEBUG_DUMP(name, ptr, size, level)
|
||||
|
||||
#endif /* ?defined WS_DISABLE_DEBUG */
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#endif
|
||||
|
||||
#include "file_util.h"
|
||||
#include "to_str.h"
|
||||
|
||||
|
||||
/* Runtime log level. */
|
||||
|
@ -908,6 +909,28 @@ void ws_log_write_always_full(const char *domain, enum ws_log_level level,
|
|||
}
|
||||
|
||||
|
||||
void ws_log_buffer_full(const char *domain, enum ws_log_level level,
|
||||
const char *file, int line, const char *func,
|
||||
const guint8 *ptr, size_t size, size_t max_len,
|
||||
const char *msg)
|
||||
{
|
||||
if (!ws_log_msg_is_active(domain, level))
|
||||
return;
|
||||
|
||||
char *bufstr = bytes_to_str_max(NULL, ptr, size, max_len);
|
||||
|
||||
if (G_UNLIKELY(msg == NULL))
|
||||
ws_log_write_always_full(domain, level, file, line, func,
|
||||
"<buffer:%p>: %s (%zu bytes)",
|
||||
ptr, bufstr, size);
|
||||
else
|
||||
ws_log_write_always_full(domain, level, file, line, func,
|
||||
"%s: %s (%zu bytes)",
|
||||
msg, bufstr, size);
|
||||
wmem_free(NULL, bufstr);
|
||||
}
|
||||
|
||||
|
||||
void ws_log_default_writer(const char *domain, enum ws_log_level level,
|
||||
ws_log_time_t timestamp,
|
||||
const char *file, int line, const char *func,
|
||||
|
|
|
@ -330,6 +330,32 @@ void ws_logv_full(const char *domain, enum ws_log_level level,
|
|||
} while (0)
|
||||
|
||||
|
||||
/** This function is called to log a buffer (bytes array).
|
||||
*
|
||||
* Accepts an optional 'msg' argument to provide a description.
|
||||
*/
|
||||
WS_DLL_PUBLIC
|
||||
void ws_log_buffer_full(const char *domain, enum ws_log_level level,
|
||||
const char *file, int line, const char *func,
|
||||
const guint8 *buffer, size_t size, size_t max_len,
|
||||
const char *msg);
|
||||
|
||||
|
||||
#define _LOG_BUFFER(buf, size) \
|
||||
ws_log_buffer_full(_LOG_DOMAIN, LOG_LEVEL_DEBUG, \
|
||||
__FILE__, __LINE__, __func__, \
|
||||
buf, size, 72, #buf)
|
||||
|
||||
#ifdef WS_DISABLE_DEBUG
|
||||
#define ws_log_buffer(buf, size) \
|
||||
G_STMT_START { \
|
||||
if (0) _LOG_BUFFER(buf, size); \
|
||||
} G_STMT_END
|
||||
#else
|
||||
#define ws_log_buffer(buf, size) _LOG_BUFFER(buf, size)
|
||||
#endif
|
||||
|
||||
|
||||
/** Auxiliary function to write custom logging functions.
|
||||
*
|
||||
* This function is the same as ws_log_full() but does not perform any
|
||||
|
|
Loading…
Reference in New Issue