Skip to content

Commit

Permalink
pv: new variables for common escaped characters
Browse files Browse the repository at this point in the history
- $En - '\n'; $Er - '\r'; $Et - '\t'; $Es - ' ';
  • Loading branch information
miconda committed Jun 26, 2024
1 parent 754f9ae commit 3174159
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/modules/pv/pv.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ static pv_export_t mod_pvs[] = {
PVT_OTHER, pv_get_errinfo_attr, 0, 0, 0, pv_init_iname, 3},
{{"err.rreason", (sizeof("err.rreason") - 1)}, /* */
PVT_OTHER, pv_get_errinfo_attr, 0, 0, 0, pv_init_iname, 4},
{{"En", (sizeof("En") - 1)}, /* */
PVT_OTHER, pv_get_escstr, 0, 0, 0, pv_init_iname, 1},
{{"Er", (sizeof("Er") - 1)}, /* */
PVT_OTHER, pv_get_escstr, 0, 0, 0, pv_init_iname, 2},
{{"Es", (sizeof("Es") - 1)}, /* */
PVT_OTHER, pv_get_escstr, 0, 0, 0, pv_init_iname, 4},
{{"Et", (sizeof("Et") - 1)}, /* */
PVT_OTHER, pv_get_escstr, 0, 0, 0, pv_init_iname, 3},
{{"fd", (sizeof("fd") - 1)}, /* */
PVT_OTHER, pv_get_from_attr, pv_set_from_domain, 0, 0,
pv_init_iname, 3},
Expand Down
33 changes: 33 additions & 0 deletions src/modules/pv/pv_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,39 @@ int pv_get_body_size(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
}


#define PV_ESCSTR_SIZE 16
int pv_get_escstr(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
{
static char _pv_escstr[PV_ESCSTR_SIZE];
int i;
str s;

if(param->pvn.u.isname.name.n < 0) {
return pv_get_null(msg, param, res);
}

i = (2 * param->pvn.u.isname.name.n) % PV_ESCSTR_SIZE;
switch(param->pvn.u.isname.name.n) {
case 2:
_pv_escstr[i] = '\r';
break;
case 3:
_pv_escstr[i] = '\t';
break;
case 4:
_pv_escstr[i] = ' ';
break;
default:
_pv_escstr[i] = '\n';
break;
}
_pv_escstr[i + 1] = '\0';
s.s = &_pv_escstr[i];
s.len = 1;
return pv_get_strval(msg, param, res, &s);
}


int pv_get_authattr(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
{
struct hdr_field *hdr;
Expand Down
2 changes: 2 additions & 0 deletions src/modules/pv/pv_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ int pv_get_msg_body(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);

int pv_get_body_size(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);

int pv_get_escstr(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);

int pv_get_authattr(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);

int pv_get_acc_user(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
Expand Down

0 comments on commit 3174159

Please sign in to comment.