Skip to content

Commit

Permalink
sca: sca_call_info_update() add [to|from] optional parameters
Browse files Browse the repository at this point in the history
* skip parsing msg for header [to|from] if value is given

Fix #775
  • Loading branch information
linuxmaniac committed Sep 13, 2016
1 parent 8a5b4d7 commit 2f151fc
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 9 deletions.
12 changes: 10 additions & 2 deletions modules/sca/doc/sca_admin.xml
Expand Up @@ -342,7 +342,7 @@ if ( is_method( "SUBSCRIBE" )) {

<section id="sca.f.sca_call_info_update">
<title>
<function moreinfo="none">sca_call_info_update([mask])</function>
<function moreinfo="none">sca_call_info_update([mask, to, from])</function>
</title>
<para>
<itemizedlist>
Expand All @@ -355,6 +355,14 @@ if ( is_method( "SUBSCRIBE" )) {
<listitem><para>2 - SCA_CALL_INFO_SHARED_CALLEE</para></listitem>
</itemizedlist>
</listitem>
<listitem>
<para><emphasis>to</emphasis> - string (optional)</para>
<para>string to use as To and skip parsing To header from the message. The parameter allows pseudo-variables usage</para>
</listitem>
<listitem>
<para><emphasis>from</emphasis> - string (optional)</para>
<para>string to use as From and skip parsing From header from the message. The parameter allows pseudo-variables usage</para>
</listitem>
</itemizedlist>
</para>
<para>
Expand Down Expand Up @@ -400,7 +408,7 @@ if ( is_method( "SUBSCRIBE" )) {
route
{
...
sca_call_info_update();
sca_call_info_update(0, "$var(to)", "$var(from)@$var(domain)");
...
}

Expand Down
39 changes: 36 additions & 3 deletions modules/sca/sca.c
Expand Up @@ -40,6 +40,7 @@

#include "../../timer.h"
#include "../../timer_proc.h"
#include "../../mod_fix.h"

#include "sca.h"
#include "sca_appearance.h"
Expand Down Expand Up @@ -69,6 +70,8 @@ static int sca_mod_init(void);
static int sca_child_init(int);
static void sca_mod_destroy(void);
static int sca_set_config(sca_mod *);
int fixup_ciu(void **, int);
int fixup_free_ciu(void **param, int param_no);

/*
* EXPORTED COMMANDS
Expand All @@ -78,9 +81,13 @@ static cmd_export_t cmds[] = {
REQUEST_ROUTE},
{"sca_call_info_update", (cmd_function)sca_call_info_update, 0, NULL, 0,
REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE},
{"sca_call_info_update", (cmd_function)sca_call_info_update, 1, fixup_var_int_1, 0,
REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE},
{0, 0, 0, 0, 0, 0},
{"sca_call_info_update", (cmd_function)sca_call_info_update, 1,
fixup_ciu, fixup_free_ciu, REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE},
{"sca_call_info_update", (cmd_function)sca_call_info_update, 2,
fixup_ciu, fixup_free_ciu, REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE},
{"sca_call_info_update", (cmd_function)sca_call_info_update, 3,
fixup_ciu, fixup_free_ciu, REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE},
{ 0, 0, 0, 0, 0, 0 }
};

/*
Expand Down Expand Up @@ -400,3 +407,29 @@ void sca_mod_destroy(void)

sca_db_disconnect();
}

int fixup_ciu(void **param, int param_no)
{
switch (param_no) {
case 1:
return fixup_var_int_1(param, param_no);
case 2:
case 3:
return fixup_spve_null(param, 1);
default:
return E_UNSPEC;
}
}

int fixup_free_ciu(void **param, int param_no)
{
switch (param_no) {
case 1:
return 0;
case 2:
case 3:
return fixup_free_spve_null(param, 1);
default:
return E_UNSPEC;
}
}
18 changes: 15 additions & 3 deletions modules/sca/sca_call_info.c
Expand Up @@ -1816,7 +1816,7 @@ struct sca_call_info_dispatch call_info_dispatch[] = {
#define SCA_CALL_INFO_UPDATE_FLAG_FROM_ALLOC (1 << 0)
#define SCA_CALL_INFO_UPDATE_FLAG_TO_ALLOC (1 << 1)

int sca_call_info_update(sip_msg_t *msg, char *p1, char *p2)
int sca_call_info_update(sip_msg_t *msg, char *p1, char *p2, char *p3)
{
sca_call_info call_info;
hdr_field_t *call_info_hdr;
Expand Down Expand Up @@ -1886,11 +1886,23 @@ int sca_call_info_update(sip_msg_t *msg, char *p1, char *p2)
}
}

if (sca_get_msg_from_header(msg, &from) < 0) {
if (p3 != NULL) {
if (sca_get_pv_from_header(msg, &from, (pv_spec_t *) p3) < 0) {
LM_ERR("Bad From pvar\n");
return (-1);
}
}
else if (sca_get_msg_from_header(msg, &from) < 0) {
LM_ERR("Bad From header\n");
return (-1);
}
if (sca_get_msg_to_header(msg, &to) < 0) {
if (p2 != NULL) {
if (sca_get_pv_to_header(msg, &to, (pv_spec_t *) p2) < 0) {
LM_ERR("Bad To pvar\n");
return (-1);
}
}
else if (sca_get_msg_to_header(msg, &to) < 0) {
LM_ERR("Bad To header\n");
return (-1);
}
Expand Down
2 changes: 1 addition & 1 deletion modules/sca/sca_call_info.h
Expand Up @@ -59,7 +59,7 @@ typedef struct _sca_call_info sca_call_info;

extern const str SCA_CALL_INFO_HEADER_STR;

int sca_call_info_update(sip_msg_t *, char *, char *);
int sca_call_info_update(sip_msg_t *, char *, char *, char *);
void sca_call_info_sl_reply_cb(void *);
void sca_call_info_ack_cb(struct cell *, int, struct tmcb_params *);

Expand Down
56 changes: 56 additions & 0 deletions modules/sca/sca_util.c
Expand Up @@ -178,6 +178,62 @@ int sca_get_msg_to_header(sip_msg_t *msg, struct to_body **to)
return (0);
}

int sca_get_pv_from_header(sip_msg_t *msg, struct to_body **from, pv_spec_t *sp)
{
struct to_body parsed_from;
pv_value_t pv_val;

assert(msg != NULL);
assert(from != NULL);
assert(sp != NULL);

if (pv_get_spec_value(msg, sp, &pv_val) < 0) {
LM_ERR("can't get value from to_pvar\n");
return (-1);
}
if (pv_val.flags & PV_VAL_STR) {
parse_to(pv_val.rs.s, pv_val.rs.s + pv_val.rs.len + 1, &parsed_from);
if (parsed_from.error != PARSE_OK) {
LM_ERR("Bad From value from from_pvar\n");
return (-1);
}
*from = &parsed_from;
return (0);
}
else {
LM_ERR("value from from_pvar is not a string\n");
}
return (-1);
}

int sca_get_pv_to_header(sip_msg_t *msg, struct to_body **to, pv_spec_t *sp)
{
struct to_body parsed_to;
pv_value_t pv_val;

assert(msg != NULL);
assert(to != NULL);
assert(sp != NULL);

if (pv_get_spec_value(msg, sp, &pv_val) < 0) {
LM_ERR("can't get value from to_pvar\n");
return (-1);
}
if (pv_val.flags & PV_VAL_STR) {
parse_to(pv_val.rs.s, pv_val.rs.s + pv_val.rs.len + 1, &parsed_to);
if (parsed_to.error != PARSE_OK) {
LM_ERR("Bad To value from to_pvar\n");
return (-1);
}
*to = &parsed_to;
return (0);
}
else {
LM_ERR("value from to_pvar is not a string\n");
}
return (-1);
}

/*
* count characters requiring escape as defined by escape_common
*/
Expand Down
3 changes: 3 additions & 0 deletions modules/sca/sca_util.h
Expand Up @@ -46,6 +46,9 @@ int sca_get_msg_from_header(sip_msg_t *, struct to_body **);
// convenient To header parsing and extraction
int sca_get_msg_to_header(sip_msg_t *, struct to_body **);

int sca_get_pv_from_header(sip_msg_t *, struct to_body **, pv_spec_t *);
int sca_get_pv_to_header(sip_msg_t *, struct to_body **, pv_spec_t *);

// count number of characters requiring escape as defined by escape_common
int sca_uri_display_escapes_count(str *);

Expand Down

0 comments on commit 2f151fc

Please sign in to comment.