Added ASCII option for dumps.

FossilOrigin-Name: e30af60fc465a1e34713518b6c91c84e4078afa49faf382229112d168a76cb04
This commit is contained in:
7u83@mail.ru 2014-08-14 09:25:33 +00:00
parent 9925ca8eec
commit ed803a1094
1 changed files with 115 additions and 4 deletions

View File

@ -19,6 +19,7 @@
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "cw_log.h"
@ -107,14 +108,15 @@ int cw_log_debug_dump_(int level,const uint8_t * data, int len,const char * form
int cw_log_debug_level=0;
static int dbg_opt_line_numbers=1;
static int dbg_opt_type=DBG_CAPWAP_MSG;
int cw_dbg_opt_detail=0;
int cw_dbg_opt_type=0;
void cw_log_dbg_(int type, const char * file, int line, const char * format, ...)
{
if (!(type & dbg_opt_type))
if (!(type & cw_dbg_opt_type))
return;
char buf[2048];
@ -124,7 +126,7 @@ void cw_log_dbg_(int type, const char * file, int line, const char * format, ...
vsprintf(buf,format,args);
va_end(args);
if (dbg_opt_line_numbers)
if (cw_dbg_opt_detail & DBG_DETAIL_LINE_NUMBERS)
cw_log(LOG_DEBUG,"%s:%d: %s",file,line,buf);
else
cw_log(LOG_DEBUG,buf);
@ -132,6 +134,115 @@ void cw_log_dbg_(int type, const char * file, int line, const char * format, ...
void cw_log_dbg_dmp_(int type,const char * file, int line, const uint8_t * data, int len,const char * format, ...)
{
if (!(type & cw_dbg_opt_type))
return;
int maxtlen=2048;
int i;
int rowlen = CW_LOG_DUMP_ROW_LEN;
int rows = len/rowlen;
int tlen=0;
int md;
if (cw_dbg_opt_detail & DBG_DETAIL_ASC_DMP)
md=2;
else
md=1;
char * dst = malloc(md*( len*3+(rows*2) + 8+maxtlen)) ;
if ( !dst )
return;
if (format != NULL){
va_list args;
va_start(args,format);
tlen = vsnprintf(dst,maxtlen,format,args);
va_end(args);
}
if (len%CW_LOG_DUMP_ROW_LEN)
rows++;
char * pdst=dst+tlen;
sprintf(pdst,"\n\t");
pdst+=2;
char asc_buffer[128];
char *ascdst=asc_buffer;
for (i=0; i<len;i++){
sprintf(pdst,"%02X ",data[i]&0xff);
if (cw_dbg_opt_detail & DBG_DETAIL_ASC_DMP){
int c=data[i]&0xff;
if (c<0x20 || c>0x80)
c='.';
*ascdst=c;
ascdst++;
}
pdst+=3;
if ((i+1)%rowlen==0){
int l;
if (cw_dbg_opt_detail & DBG_DETAIL_ASC_DMP){
*ascdst=0;
l=sprintf(pdst," | %s\n\t",asc_buffer);
ascdst=asc_buffer;
}
else{
l=sprintf(pdst,"\n\t");
}
pdst+=l;
}
}
if (cw_dbg_opt_detail & DBG_DETAIL_ASC_DMP){
*ascdst=0;
if (strlen(asc_buffer))
pdst+=sprintf(pdst," | %s",asc_buffer);
}
if (cw_dbg_opt_detail & DBG_DETAIL_LINE_NUMBERS)
cw_log(LOG_DEBUG,"%s:%d: %s",file,line,dst);
else
cw_log(LOG_DEBUG,dst);
free (dst);
return;
}
void (*cw_log_debug_cbs[])(const char * fromat, ...) = {
cw_log_debug0_,
cw_log_debug1_,