Reformatted
FossilOrigin-Name: 33d28e0eae5a610121fa6d139c8922ada5b935286d9cb5909b348f16753fd53d
This commit is contained in:
parent
cea7e10c37
commit
2ab86e8fc6
67
src/cw/dbg.c
67
src/cw/dbg.c
@ -106,6 +106,7 @@ static struct cw_strlist_elem color_on[] = {
|
||||
{DBG_MOD, "\x1b[91m"},
|
||||
{CW_STR_STOP, ""}
|
||||
};
|
||||
|
||||
static struct cw_strlist_elem color_ontext[] = {
|
||||
|
||||
{DBG_ELEM_DMP, "\x1b[30m"},
|
||||
@ -143,24 +144,28 @@ static struct cw_strlist_elem prefix[] = {
|
||||
|
||||
|
||||
|
||||
static const char * get_dbg_color_on(int level){
|
||||
static const char *get_dbg_color_on(int level)
|
||||
{
|
||||
if (!(cw_dbg_opt_display & DBG_DISP_COLORS))
|
||||
return "";
|
||||
return cw_strlist_get_str(color_on, level);
|
||||
}
|
||||
|
||||
static const char * get_dbg_color_off(int level){
|
||||
static const char *get_dbg_color_off(int level)
|
||||
{
|
||||
if (!(cw_dbg_opt_display & DBG_DISP_COLORS))
|
||||
return "";
|
||||
return cw_strlist_get_str(color_off, level);
|
||||
}
|
||||
|
||||
static const char * get_dbg_prefix(int level){
|
||||
static const char *get_dbg_prefix(int level)
|
||||
{
|
||||
return cw_strlist_get_str(prefix, level);
|
||||
|
||||
}
|
||||
|
||||
static const char * get_dbg_color_ontext(int level){
|
||||
static const char *get_dbg_color_ontext(int level)
|
||||
{
|
||||
if (!(cw_dbg_opt_display & DBG_DISP_COLORS))
|
||||
return "";
|
||||
return cw_strlist_get_str(color_ontext, level);
|
||||
@ -202,23 +207,23 @@ void cw_dbg_missing_mand(int level, struct conn *conn, cw_action_in_t ** ml, int
|
||||
/**
|
||||
* Format a Packet Header
|
||||
*/
|
||||
int cw_format_pkt_hdr(char *dst,int level,struct conn *conn, uint8_t * packet, int len,struct sockaddr *from)
|
||||
int cw_format_pkt_hdr(char *dst, int level, struct conn *conn, uint8_t * packet, int len,
|
||||
struct sockaddr *from)
|
||||
{
|
||||
char *s = dst;
|
||||
switch (level) {
|
||||
case DBG_PKT_IN:
|
||||
if (cw_get_hdr_flag_f(packet)) {
|
||||
s+=sprintf(s,"Fragment from %s",sock_addr2str_p(from));
|
||||
}
|
||||
else{
|
||||
s += sprintf(s, "Fragment from %s",
|
||||
sock_addr2str_p(from));
|
||||
} else {
|
||||
s += sprintf(s, "From %s", sock_addr2str_p(from));
|
||||
}
|
||||
break;
|
||||
case DBG_PKT_OUT:
|
||||
if (cw_get_hdr_flag_f(packet)) {
|
||||
s += sprintf(s, "Fragment to %s", sock_addr2str(from));
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
s += sprintf(s, "To %s", sock_addr2str(from));
|
||||
}
|
||||
break;
|
||||
@ -353,7 +358,6 @@ char * cw_dbg_mkdmp_c( const uint8_t * data, int len, int invlen)
|
||||
*ascdst = c;
|
||||
ascdst++;
|
||||
}
|
||||
|
||||
// pdst += 3;
|
||||
if ((i + 1) % rowlen == 0) {
|
||||
int l;
|
||||
@ -404,7 +408,8 @@ char * cw_dbg_mkdmp( const uint8_t * data, int len)
|
||||
/**
|
||||
* Display a packet on for debugger
|
||||
*/
|
||||
void cw_dbg_pkt(int level,struct conn *conn, uint8_t * packet, int len,struct sockaddr *from)
|
||||
void cw_dbg_pkt(int level, struct conn *conn, uint8_t * packet, int len,
|
||||
struct sockaddr *from)
|
||||
{
|
||||
if (!cw_dbg_is_level(level))
|
||||
return;
|
||||
@ -418,12 +423,12 @@ void cw_dbg_pkt(int level,struct conn *conn, uint8_t * packet, int len,struct so
|
||||
char *dmp = cw_dbg_mkdmp_c(packet, len, hlen);
|
||||
cw_dbg(level, "%s%s", buf, dmp);
|
||||
free(dmp);
|
||||
}
|
||||
else
|
||||
} else
|
||||
cw_dbg(level, "%s", buf);
|
||||
}
|
||||
|
||||
void cw_dbg_pkt_nc(int level,struct netconn *nc, uint8_t * packet, int len,struct sockaddr *from)
|
||||
void cw_dbg_pkt_nc(int level, struct netconn *nc, uint8_t * packet, int len,
|
||||
struct sockaddr *from)
|
||||
{
|
||||
if (!cw_dbg_is_level(level))
|
||||
return;
|
||||
@ -437,8 +442,7 @@ void cw_dbg_pkt_nc(int level,struct netconn *nc, uint8_t * packet, int len,struc
|
||||
char *dmp = cw_dbg_mkdmp_c(packet, len, hlen);
|
||||
cw_dbg(level, "%s%s", buf, dmp);
|
||||
free(dmp);
|
||||
}
|
||||
else
|
||||
} else
|
||||
cw_dbg(level, "%s", buf);
|
||||
}
|
||||
|
||||
@ -464,7 +468,8 @@ void cw_dbg_dmp_(int level, const char *file, int line,
|
||||
|
||||
|
||||
|
||||
void cw_dbg_msg(int level,struct conn *conn, uint8_t * packet, int len,struct sockaddr *from)
|
||||
void cw_dbg_msg(int level, struct conn *conn, uint8_t * packet, int len,
|
||||
struct sockaddr *from)
|
||||
{
|
||||
if (!cw_dbg_is_level(level))
|
||||
return;
|
||||
@ -484,7 +489,8 @@ void cw_dbg_msg(int level,struct conn *conn, uint8_t * packet, int len,struct so
|
||||
else
|
||||
s += sprintf(s, "to %s ", sock_addr2str(from));
|
||||
|
||||
s+=sprintf(s,", Seqnum: %d ElemLen: %d",cw_get_msg_seqnum(msgptr),cw_get_msg_elems_len(msgptr));
|
||||
s += sprintf(s, ", Seqnum: %d ElemLen: %d", cw_get_msg_seqnum(msgptr),
|
||||
cw_get_msg_elems_len(msgptr));
|
||||
|
||||
//abort:
|
||||
cw_dbg(level, "%s", buf);
|
||||
@ -506,8 +512,7 @@ static int cw_format_vendor(char *dst, uint32_t vendor_id, int elem_id,
|
||||
uint32_t lw_elem_id = lw_get_word(elem_data + 4 + 6);
|
||||
return sprintf(dst, "%d/LWAPP Vendor: %d - %s",
|
||||
elem_id,
|
||||
lw_elem_id,
|
||||
lw_cisco_id_to_str(lw_elem_id));
|
||||
lw_elem_id, lw_cisco_id_to_str(lw_elem_id));
|
||||
|
||||
|
||||
|
||||
@ -559,18 +564,12 @@ void cw_dbg_elem_colored(int level, struct conn *conn, int msg, int msgelem,
|
||||
|
||||
|
||||
if (!cw_dbg_is_level(DBG_ELEM_DMP)) {
|
||||
cw_dbg(DBG_ELEM, "%d (%s), len=%d",
|
||||
msgelem, elemname, len);
|
||||
}
|
||||
else{
|
||||
cw_dbg(DBG_ELEM, "%d (%s), len=%d", msgelem, elemname, len);
|
||||
} else {
|
||||
char *dmp = cw_dbg_mkdmp(msgbuf, len);
|
||||
|
||||
cw_dbg(DBG_ELEM, "%d (%s), len=%d%s%s",
|
||||
msgelem,
|
||||
elemname,
|
||||
len,
|
||||
get_dbg_color_ontext(DBG_ELEM_DMP),
|
||||
dmp);
|
||||
msgelem, elemname, len, get_dbg_color_ontext(DBG_ELEM_DMP), dmp);
|
||||
|
||||
free(dmp);
|
||||
}
|
||||
@ -588,9 +587,7 @@ void cw_dbg_colored(int level, const char *file, int line, const char *format, .
|
||||
sprintf(fbuf, "DBG:%s%s %s%s%s",
|
||||
get_dbg_color_on(level),
|
||||
get_dbg_prefix(level),
|
||||
get_dbg_color_ontext(level),
|
||||
format,
|
||||
get_dbg_color_off(level)
|
||||
get_dbg_color_ontext(level), format, get_dbg_color_off(level)
|
||||
);
|
||||
|
||||
|
||||
@ -637,8 +634,7 @@ static int cw_format_version(char *s, bstrv_t ver, char * def)
|
||||
rs += sprintf(s + rs, "%.*s", len, version);
|
||||
else
|
||||
rs += sprintf(s + rs, "''");
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
for (i = 0; i < len && i < 20; i++) {
|
||||
rs += sprintf(s + rs, "%02X", version[i]);
|
||||
}
|
||||
@ -704,4 +700,3 @@ void dbg_istore_dmp(mbag_t s)
|
||||
|
||||
|
||||
/**@}*/
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user