Module: sip-router
Branch: master
Commit: 46e5cc861cec11c7d9ddfbbec7a0c986c95fc5e2
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=46e5cc8…
Author: Jason Penton <jason.penton(a)gmail.com>
Committer: Jason Penton <jason.penton(a)gmail.com>
Date: Thu Oct 9 14:18:29 2014 +0200
modules/ims_charging: added support for trunk ID in Ro CCR
---
modules/ims_charging/mod.c | 51 +++++++++++++++++++++++++--------
modules/ims_charging/ro_db_handler.c | 24 ++++++++++++---
modules/ims_charging/ro_db_handler.h | 5 ++-
3 files changed, 61 insertions(+), 19 deletions(-)
diff --git a/modules/ims_charging/mod.c b/modules/ims_charging/mod.c
index 82def69..10d4fee 100644
--- a/modules/ims_charging/mod.c
+++ b/modules/ims_charging/mod.c
@@ -91,7 +91,7 @@ static int mod_init(void);
static int mod_child_init(int);
static void mod_destroy(void);
-static int w_ro_ccr(struct sip_msg *msg, str* route_name, str* direction, str*
charge_type, str* unit_type, int reservation_units, str* trunk_id);
+static int w_ro_ccr(struct sip_msg *msg, char* route_name, char* direction, char*
charge_type, char* unit_type, int reservation_units, char* trunk_id);
//void ro_session_ontimeout(struct ro_tl *tl);
static int ro_fixup(void **param, int param_no);
@@ -346,7 +346,7 @@ static void mod_destroy(void) {
}
-static int w_ro_ccr(struct sip_msg *msg, str* route_name, str* direction, str*
charge_type, str* unit_type, int reservation_units, str* trunk_id) {
+static int w_ro_ccr(struct sip_msg *msg, char* c_route_name, char* c_direction, char*
c_charge_type, char* c_unit_type, int reservation_units, char* c_trunk_id) {
/* PSEUDOCODE/NOTES
* 1. What mode are we in - terminating or originating
* 2. check request type - IEC - Immediate Event Charging
@@ -377,12 +377,37 @@ static int w_ro_ccr(struct sip_msg *msg, str* route_name, str*
direction, str* c
struct ro_session *ro_session = 0;
int free_contact = 0;
- LM_DBG("Ro CCR initiated: direction:%.*s, charge_type:%.*s, unit_type:%.*s,
reservation_units:%i, route_name:%.*s",
- direction->len, direction->s,
- charge_type->len, charge_type->s,
- unit_type->len, unit_type->s,
+ str s_route_name, s_direction, s_charge_type, s_unit_type, s_trunk_id;
+
+ if (get_str_fparam(&s_route_name, msg, (fparam_t*) c_route_name) < 0) {
+ LM_ERR("failed to get s_route_name\n");
+ return RO_RETURN_ERROR;
+ }
+ if (get_str_fparam(&s_direction, msg, (fparam_t*) c_direction) < 0) {
+ LM_ERR("failed to get s_direction\n");
+ return RO_RETURN_ERROR;
+ }
+ if (get_str_fparam(&s_charge_type, msg, (fparam_t*) c_charge_type) < 0) {
+ LM_ERR("failed to get s_charge_type\n");
+ return RO_RETURN_ERROR;
+ }
+ if (get_str_fparam(&s_unit_type, msg, (fparam_t*) c_unit_type) < 0) {
+ LM_ERR("failed to get s_unit_type\n");
+ return RO_RETURN_ERROR;
+ }
+ if (get_str_fparam(&s_trunk_id, msg, (fparam_t*) c_trunk_id) < 0) {
+ LM_ERR("failed to get s_trunk_id\n");
+ return RO_RETURN_ERROR;
+ }
+
+ LM_DBG("Ro CCR initiated: direction:%.*s, charge_type:%.*s, unit_type:%.*s,
reservation_units:%i, route_name:%.*s, trunk_id:%.*s\n",
+ s_direction.len, s_direction.s,
+ s_charge_type.len, s_charge_type.s,
+ s_unit_type.len, s_unit_type.s,
reservation_units,
- route_name->len, route_name->s);
+ s_route_name.len, s_route_name.s,
+ s_trunk_id.len, s_trunk_id.s);
+
if (msg->first_line.type != SIP_REQUEST) {
LM_ERR("Ro_CCR() called from SIP reply.");
@@ -397,7 +422,7 @@ static int w_ro_ccr(struct sip_msg *msg, str* route_name, str*
direction, str* c
return RO_RETURN_ERROR;
}
- dir = get_direction_as_int(direction);
+ dir = get_direction_as_int(&s_direction);
if (dir == RO_ORIG_DIRECTION) {
//get caller IMPU from asserted identity
@@ -482,18 +507,18 @@ send_ccr:
goto done;
}
- LM_DBG("Looking for route block [%.*s]\n", route_name->len,
route_name->s);
+ LM_DBG("Looking for route block [%.*s]\n", s_route_name.len, s_route_name.s);
- int ri = route_get(&main_rt, route_name->s);
+ int ri = route_get(&main_rt, s_route_name.s);
if (ri < 0) {
- LM_ERR("unable to find route block [%.*s]\n", route_name->len,
route_name->s);
+ LM_ERR("unable to find route block [%.*s]\n", s_route_name.len,
s_route_name.s);
ret = RO_RETURN_ERROR;
goto done;
}
cfg_action = main_rt.rlist[ri];
if (!cfg_action) {
- LM_ERR("empty action lists in route block [%.*s]\n", route_name->len,
route_name->s);
+ LM_ERR("empty action lists in route block [%.*s]\n", s_route_name.len,
s_route_name.s);
ret = RO_RETURN_ERROR;
goto done;
}
@@ -521,7 +546,7 @@ send_ccr:
goto done;
}
- ret = Ro_Send_CCR(msg, dlg, dir, charge_type, unit_type, reservation_units, trunk_id,
cfg_action, tindex, tlabel);
+ ret = Ro_Send_CCR(msg, dlg, dir, &s_charge_type, &s_unit_type,
reservation_units, &s_trunk_id, cfg_action, tindex, tlabel);
if(ret < 0){
LM_ERR("Failed to send CCR\n");
diff --git a/modules/ims_charging/ro_db_handler.c b/modules/ims_charging/ro_db_handler.c
index e3cb05f..631ad4b 100644
--- a/modules/ims_charging/ro_db_handler.c
+++ b/modules/ims_charging/ro_db_handler.c
@@ -19,6 +19,9 @@ str last_event_ts_column = str_init(LAST_EVENT_TS_COL);
str reserved_sec_column = str_init(RESERVED_SECS_COL);
str valid_for_column = str_init(VALID_FOR_COL);
str state_column = str_init(STATE_COL);
+str trunk_id_column = str_init(TRUNK_ID_COL);
+str rating_group_column = str_init(RATING_GROUP_COL);
+str service_identifier_column = str_init(SERVICE_IDENTIFIER_COL);
typedef enum ro_session_field_idx {
ID_COL_IDX = 0,
@@ -34,7 +37,11 @@ typedef enum ro_session_field_idx {
LAST_EVENT_TS_COL_IDX,
RESERVED_SECS_COL_IDX,
VALID_FOR_COL_IDX,
- STATE_COL_IDX
+ STATE_COL_IDX,
+ TRUNK_ID_COL_IDX,
+ RATING_GROUP_COL_IDX,
+ SERVICE_IDENTIFIER_COL_IDX
+
} ro_session_field_idx_t;
#define GET_FIELD_IDX(_val, _idx)\
@@ -157,7 +164,7 @@ int update_ro_dbinfo_unsafe(struct ro_session* ro_session) {
db_key_t insert_keys[RO_SESSION_TABLE_COL_NUM] = {
&id_column, &h_entry_column, &h_id_column, &session_id_column,
&dlg_h_entry_column, &dlg_h_id_column,
&direction_column, &asserted_column, &callee_column,
&start_time_col, &last_event_ts_column,
- &reserved_sec_column, &valid_for_column, &state_column
+ &reserved_sec_column, &valid_for_column, &state_column,
&trunk_id_column, &rating_group_column, &service_identifier_column
};
VAL_TYPE(GET_FIELD_IDX(values, ID_COL_IDX)) = DB1_INT;
@@ -176,6 +183,10 @@ int update_ro_dbinfo_unsafe(struct ro_session* ro_session) {
db_set_int_val(values, RESERVED_SECS_COL_IDX, ro_session->reserved_secs);
db_set_int_val(values, VALID_FOR_COL_IDX, ro_session->valid_for);
db_set_int_val(values, STATE_COL_IDX, ro_session->active);
+ db_set_str_val(values, TRUNK_ID_COL_IDX, &ro_session->trunk_id);
+ db_set_int_val(values, RATING_GROUP_COL_IDX, ro_session->rating_group);
+ db_set_int_val(values, SERVICE_IDENTIFIER_COL_IDX, ro_session->service_identifier);
+
LM_DBG("Inserting ro_session into database\n");
if ((ro_dbf.insert(ro_db_handle, insert_keys, values, RO_SESSION_TABLE_COL_NUM)) != 0)
{
@@ -187,11 +198,11 @@ int update_ro_dbinfo_unsafe(struct ro_session* ro_session) {
} else if ((ro_session->flags & RO_SESSION_FLAG_CHANGED) != 0 &&
(ro_session->flags & RO_SESSION_FLAG_INSERTED) != 0) {
- db_val_t values[13];
- db_key_t update_keys[13] = {
+ db_val_t values[RO_SESSION_TABLE_COL_NUM-1];
+ db_key_t update_keys[RO_SESSION_TABLE_COL_NUM-1] = {
&h_entry_column, &h_id_column, &session_id_column,
&dlg_h_entry_column, &dlg_h_id_column,
&direction_column, &asserted_column, &callee_column,
&start_time_col, &last_event_ts_column,
- &reserved_sec_column, &valid_for_column, &state_column
+ &reserved_sec_column, &valid_for_column, &state_column,
&trunk_id_column, &rating_group_column, &service_identifier_column
};
db_set_int_val(values, HASH_ENTRY_COL_IDX - 1, ro_session->h_entry);
@@ -207,6 +218,9 @@ int update_ro_dbinfo_unsafe(struct ro_session* ro_session) {
db_set_int_val(values, RESERVED_SECS_COL_IDX - 1, ro_session->reserved_secs);
db_set_int_val(values, VALID_FOR_COL_IDX - 1, ro_session->valid_for);
db_set_int_val(values, STATE_COL_IDX - 1, ro_session->active);
+ db_set_str_val(values, TRUNK_ID_COL_IDX - 1, &ro_session->trunk_id);
+ db_set_int_val(values, RATING_GROUP_COL_IDX - 1, ro_session->rating_group);
+ db_set_int_val(values, SERVICE_IDENTIFIER_COL_IDX - 1,
ro_session->service_identifier);
LM_DBG("Updating ro_session in database\n");
if ((ro_dbf.update(ro_db_handle, update_keys/*match*/, 0/*match*/, values/*match*/,
update_keys/*update*/, values/*update*/, 3/*match*/, 13/*update*/)) != 0) {
diff --git a/modules/ims_charging/ro_db_handler.h b/modules/ims_charging/ro_db_handler.h
index c8b2029..fc56ccc 100644
--- a/modules/ims_charging/ro_db_handler.h
+++ b/modules/ims_charging/ro_db_handler.h
@@ -14,7 +14,7 @@
#define RO_TABLE_VERSION 1
#define RO_SESSION_TABLE_NAME "ro_session"
-#define RO_SESSION_TABLE_COL_NUM 14
+#define RO_SESSION_TABLE_COL_NUM 17
#define ID_COL "id"
#define HASH_ENTRY_COL "hash_entry"
@@ -30,6 +30,9 @@
#define RESERVED_SECS_COL "reserved_secs"
#define VALID_FOR_COL "valid_for"
#define STATE_COL "state"
+#define RATING_GROUP_COL "rating_group"
+#define SERVICE_IDENTIFIER_COL "service_identifier"
+#define TRUNK_ID_COL "trunk_id"
int init_ro_db(const str *db_url, int dlg_hash_size , int db_update_period, int
fetch_num_rows);
int load_ro_info_from_db(int hash_size, int fetch_num_rows);