Skip to content

Commit

Permalink
dialog: hexa representation for dlg_list_ctx binary values
Browse files Browse the repository at this point in the history
  • Loading branch information
razvancrainea committed Nov 28, 2013
1 parent 6c7e9c7 commit 62d644e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
4 changes: 3 additions & 1 deletion modules/dialog/README
Expand Up @@ -1445,7 +1445,9 @@ if (has_totag() && (uri == myself) && is_method("INVITE|ACK|BYE|UPDATE

The same as the “dlg_list” but including in the dialog
description the associated context from modules sitting on top
of the dialog module.
of the dialog module. This function also prints the dialog's
values. In case of binary values, the non-printable chars are
represented in hexa (e.g. \x00).

Name: dlg_list_ctx

Expand Down
29 changes: 27 additions & 2 deletions modules/dialog/dlg_hash.c
Expand Up @@ -914,6 +914,7 @@ void next_state_dlg(struct dlg_cell *dlg, int event, int dir, int *old_state,


/**************************** MI functions ******************************/
static char *dlg_val_buf;
static inline int internal_mi_print_dlg(struct mi_node *rpl,
struct dlg_cell *dlg, int with_context)
{
Expand All @@ -924,7 +925,7 @@ static inline int internal_mi_print_dlg(struct mi_node *rpl,
struct dlg_val* dv;
int len;
char* p;
int i;
int i, j;

node = add_mi_node_child(rpl, 0, "dialog",6 , 0, 0 );
if (node==0)
Expand Down Expand Up @@ -1044,8 +1045,32 @@ static inline int internal_mi_print_dlg(struct mi_node *rpl,
goto error;
/* print dlg values -> iterate the list */
for( dv=dlg->vals ; dv ; dv=dv->next) {
/* escape non-printable chars */
p = pkg_realloc(dlg_val_buf, 4 * dv->val.len + 1);
if (!p) {
LM_ERR("not enough mem to allocate: %d\n", dv->val.len);
continue;
}
for (i = 0, j = 0; i < dv->val.len; i++) {
if (dv->val.s[i] < 0x20) {
p[j++] = '\\';
switch ((unsigned char)dv->val.s[i]) {
case 0x9: p[j++] = 't'; break;
case 0xA: p[j++] = 'n'; break;
case 0xD: p[j++] = 'r'; break;
default:
p[j++] = 'x';
j += snprintf(&p[j], 3, "%02x",
(unsigned char)dv->val.s[i]);
break;
}
} else {
p[j++] = dv->val.s[i];
}
}
addf_mi_node_child(node1, MI_DUP_VALUE, MI_SSTR("value"),
"%.*s = %.*s",dv->name.len,dv->name.s,dv->val.len,dv->val.s);
"%.*s = %.*s",dv->name.len,dv->name.s,j,p);
dlg_val_buf = p;
}
/* print dlg profiles */
for( dl=dlg->profile_links ; dl ; dl=dl->next) {
Expand Down
3 changes: 3 additions & 0 deletions modules/dialog/doc/dialog_admin.xml
Expand Up @@ -2021,6 +2021,9 @@ if (has_totag() &amp;&amp; (uri == myself) &amp;&amp; is_method("INVITE|ACK|BY
dialog description
the associated context from modules sitting on top of
the dialog module.
This function also prints the dialog's values. In case of
binary values, the non-printable chars are represented in hex
(e.g. \x00)
</para>
<para>
Name: <emphasis>dlg_list_ctx</emphasis>
Expand Down

0 comments on commit 62d644e

Please sign in to comment.