Module: kamailio Branch: master Commit: 5f98fddd971a28dbc2f29d19337a1645e869f69a URL: https://github.com/kamailio/kamailio/commit/5f98fddd971a28dbc2f29d19337a1645...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2015-03-10T09:48:15+01:00
rr: new config variables $fti and $tti
- $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
---
Modified: modules/rr/rr_mod.c
---
Diff: https://github.com/kamailio/kamailio/commit/5f98fddd971a28dbc2f29d19337a1645... Patch: https://github.com/kamailio/kamailio/commit/5f98fddd971a28dbc2f29d19337a1645...
---
diff --git a/modules/rr/rr_mod.c b/modules/rr/rr_mod.c index 9147abe..67eb905 100644 --- a/modules/rr/rr_mod.c +++ b/modules/rr/rr_mod.c @@ -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" @@ -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 */ @@ -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} };
@@ -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); +}