Module: kamailio Branch: master Commit: 85fc1db80d246effdef55d6244914e1cb73a76ab URL: https://github.com/kamailio/kamailio/commit/85fc1db80d246effdef55d6244914e1c...
Author: Richard Good richard.good@smilecoms.com Committer: Richard Good richard.good@smilecoms.com Date: 2015-07-21T10:52:25+02:00
modules/ims_charging: allow ro session id to be used from cfg file as avp
---
Modified: modules/ims_charging/doc/ims_charging_admin.xml Modified: modules/ims_charging/mod.c
---
Diff: https://github.com/kamailio/kamailio/commit/85fc1db80d246effdef55d6244914e1c... Patch: https://github.com/kamailio/kamailio/commit/85fc1db80d246effdef55d6244914e1c...
---
diff --git a/modules/ims_charging/doc/ims_charging_admin.xml b/modules/ims_charging/doc/ims_charging_admin.xml index a00b126..789690f 100644 --- a/modules/ims_charging/doc/ims_charging_admin.xml +++ b/modules/ims_charging/doc/ims_charging_admin.xml @@ -815,6 +815,27 @@ route[CHARGING_CCR_REPLY] </programlisting> </example> </section> + + <section> + <title><function moreinfo="none">Ro_set_session_id_avp()</function> + </title> + + <para>Sets the Ro session ID to an AVP for use in the config file</para> + + <para>This function can be used from REQUEST_ROUTE or ONREPLY_ROUTE.</para> + + <example> + <title>Ro_set_session_id_avp</title> + + <programlisting format="linespecific"> +... + Ro_set_session_id_avp(); + xlog("L_DBG","Ro session AVP has been set: $avp(ro_session_id)\n"); +... + </programlisting> + </example> + </section> + </section>
<section> diff --git a/modules/ims_charging/mod.c b/modules/ims_charging/mod.c index 2b45f72..a0d94b2 100644 --- a/modules/ims_charging/mod.c +++ b/modules/ims_charging/mod.c @@ -83,10 +83,15 @@ static void mod_destroy(void); static int w_ro_ccr(struct sip_msg *msg, char* route_name, char* direction, int reservation_units, char* incoming_trunk_id, char* outgoing_trunk_id); //void ro_session_ontimeout(struct ro_tl *tl);
+ +int create_response_avp_string(char* name, str* val); +static int w_ro_set_session_id_avp(struct sip_msg *msg, char *str1, char *str2); + static int ro_fixup(void **param, int param_no);
static cmd_export_t cmds[] = { { "Ro_CCR", (cmd_function) w_ro_ccr, 5, ro_fixup, 0, REQUEST_ROUTE }, + { "Ro_set_session_id_avp", (cmd_function) w_ro_set_session_id_avp, 0, 0, 0, REQUEST_ROUTE | ONREPLY_ROUTE }, { 0, 0, 0, 0, 0, 0 } };
@@ -311,6 +316,52 @@ static void mod_destroy(void) {
}
+int create_response_avp_string(char* name, str* val) { + int rc; + int_str avp_val, avp_name; + avp_name.s.s = name; + avp_name.s.len = strlen(name); + + avp_val.s = *val; + + rc = add_avp(AVP_NAME_STR|AVP_VAL_STR, avp_name, avp_val); + + if (rc < 0) + LM_ERR("couldnt create AVP\n"); + else + LM_INFO("created AVP successfully : [%.*s] - [%.*s]\n", avp_name.s.len, avp_name.s.s, val->len, val->s); + + return 1; +} + +//This function gets the dlg from the current msg, gets the ro_session from the dlg and sets a AVP for use in the cfg file: ro_session_id +static int w_ro_set_session_id_avp(struct sip_msg *msg, char *str1, char *str2) { + struct ro_session *ro_session = 0; + struct dlg_cell* dlg; + int res = -1; + + //get dlg from msg + dlg = dlgb.get_dlg(msg); + if (!dlg) { + LM_ERR("Unable to find dialog and cannot do Ro charging without it\n"); + return RO_RETURN_ERROR; + } + + //get ro session id from dialog + ro_session= lookup_ro_session(dlg->h_entry, &dlg->callid, 0, 0); + if(!ro_session) { + LM_ERR("Unable to find Ro charging data\n"); + return RO_RETURN_ERROR; + } + + //set avp response with session id + res = create_response_avp_string("ro_session_id", &ro_session->ro_session_id); + return res; +} + + + + static int w_ro_ccr(struct sip_msg *msg, char* c_route_name, char* c_direction, int reservation_units, char* c_incoming_trunk_id, char* c_outgoing_trunk_id) { /* PSEUDOCODE/NOTES * 1. What mode are we in - terminating or originating