Skip to content

Commit

Permalink
rr: new config variables $fti and $tti
Browse files Browse the repository at this point in the history
- $fti - from tag as in initial INVITE
- $tti - to tag as in the response to the initial INVITE
- requires append_fromtag to be set in order to detect the direction for
  requests within dialog
  • Loading branch information
miconda committed Mar 10, 2015
1 parent 6e1b56c commit 5f98fdd
Showing 1 changed file with 83 additions and 1 deletion.
84 changes: 83 additions & 1 deletion modules/rr/rr_mod.c
Expand Up @@ -38,6 +38,8 @@
#include "../../mem/mem.h"
#include "../../mod_fix.h"
#include "../../parser/parse_rr.h"
#include "../../parser/parse_from.h"
#include "../../parser/parse_to.h"
#include "../outbound/api.h"
#include "loose.h"
#include "record.h"
Expand Down Expand Up @@ -77,6 +79,10 @@ static int w_is_direction(struct sip_msg *,char *, char *);
static int remove_record_route(sip_msg_t*, char*, char*);
/* PV functions */
static int pv_get_route_uri_f(struct sip_msg *, pv_param_t *, pv_value_t *);
static int pv_get_from_tag_initial(sip_msg_t *msg, pv_param_t *param,
pv_value_t *res);
static int pv_get_to_tag_initial(sip_msg_t *msg, pv_param_t *param,
pv_value_t *res);
/*!
* \brief Exported functions
*/
Expand Down Expand Up @@ -127,7 +133,11 @@ static param_export_t params[] ={
*/
static pv_export_t mod_pvs[] = {
{{"route_uri", (sizeof("route_uri")-1)}, /* URI of the first Route-Header */
PVT_OTHER, pv_get_route_uri_f, 0, 0, 0, 0, 0},
PVT_OTHER, pv_get_route_uri_f, 0, 0, 0, 0, 0},
{{"fti", (sizeof("fti")-1)}, /* From-Tag as for initial request */
PVT_OTHER, pv_get_from_tag_initial, 0, 0, 0, 0, 0},
{{"tti", (sizeof("tti")-1)}, /* To-Tag as for response to initial request */
PVT_OTHER, pv_get_to_tag_initial, 0, 0, 0, 0, 0},
{{0, 0}, 0, 0, 0, 0, 0, 0, 0}
};

Expand Down Expand Up @@ -478,3 +488,75 @@ static int remove_record_route(sip_msg_t* _m, char* _s1, char* _s2)
free_rr_lump(&(_m->add_rm));
return 1;
}

static int pv_get_to_tag_initial(sip_msg_t *msg, pv_param_t *param,
pv_value_t *res)
{
struct to_body *xto;
if(msg==NULL)
return -1;

if(msg->to==NULL && parse_headers(msg, HDR_TO_F, 0)==-1) {
LM_ERR("cannot parse To header\n");
return pv_get_null(msg, param, res);
}
if(msg->to==NULL || get_to(msg)==NULL) {
LM_DBG("no To header\n");
return pv_get_null(msg, param, res);
}
xto = get_to(msg);

if(is_direction(msg, RR_FLOW_UPSTREAM)==0) {
if(parse_from_header(msg)<0) {
LM_ERR("cannot parse From header\n");
return pv_get_null(msg, param, res);
}
if(msg->from==NULL || get_from(msg)==NULL) {
LM_DBG("no From header\n");
return pv_get_null(msg, param, res);
}
xto = get_from(msg);
}

if (xto->tag_value.s==NULL || xto->tag_value.len<=0) {
LM_DBG("no Tag parameter\n");
return pv_get_null(msg, param, res);
}
return pv_get_strval(msg, param, res, &xto->tag_value);
}

static int pv_get_from_tag_initial(sip_msg_t *msg, pv_param_t *param,
pv_value_t *res)
{
struct to_body *xto;
if(msg==NULL)
return -1;

if(parse_from_header(msg)<0) {
LM_ERR("cannot parse From header\n");
return pv_get_null(msg, param, res);
}
if(msg->from==NULL || get_from(msg)==NULL) {
LM_DBG("no From header\n");
return pv_get_null(msg, param, res);
}
xto = get_from(msg);

if(is_direction(msg, RR_FLOW_UPSTREAM)==0) {
if(msg->to==NULL && parse_headers(msg, HDR_TO_F, 0)==-1) {
LM_ERR("cannot parse To header\n");
return pv_get_null(msg, param, res);
}
if(msg->to==NULL || get_to(msg)==NULL) {
LM_DBG("no To header\n");
return pv_get_null(msg, param, res);
}
xto = get_to(msg);
}

if (xto->tag_value.s==NULL || xto->tag_value.len<=0) {
LM_DBG("no Tag parameter\n");
return pv_get_null(msg, param, res);
}
return pv_get_strval(msg, param, res, &xto->tag_value);
}

0 comments on commit 5f98fdd

Please sign in to comment.