From 9741bee7af8136b35af8e6279e530aa0ad54f574 Mon Sep 17 00:00:00 2001 From: Huseyin Dikme Date: Tue, 12 Sep 2017 15:37:17 +0200 Subject: [PATCH] carrierroute: warning for the same carrier/domain having routes with only 0 probability - While starting kamailio or reloading the routes, if the same carrier/domain pairs do not have any route with a probability other than 0 (zero) then an error log will be printed on the screen. Besides, the log "invalid dice_max value" in the cr_func.c has been made more clear. --- src/modules/carrierroute/cr_db.c | 34 ++++++++++++++++++++++++++++++ src/modules/carrierroute/cr_db.h | 5 +++++ src/modules/carrierroute/cr_func.c | 2 +- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/modules/carrierroute/cr_db.c b/src/modules/carrierroute/cr_db.c index d651db1b49c..010f99d7158 100644 --- a/src/modules/carrierroute/cr_db.c +++ b/src/modules/carrierroute/cr_db.c @@ -265,6 +265,7 @@ int load_user_carrier(str * user, str * domain) { */ int load_route_data_db(struct route_data_t * rd) { db1_res_t * res = NULL; + db1_res_t * prob_res = NULL; db_row_t * row = NULL; int i, ret; struct carrier_data_t * tmp_carrier_data; @@ -352,6 +353,7 @@ int load_route_data_db(struct route_data_t * rd) { } } int n = 0; + boolean query_done = false; do { LM_DBG("loading, cycle %d", n++); for (i = 0; i < RES_ROW_N(res); ++i) { @@ -396,6 +398,35 @@ int load_route_data_db(struct route_data_t * rd) { p_tmp_comment) == -1) { goto errout; } + if (row->values[COL_PROB].val.double_val == 0 && !query_done) { + int ret_tmp; + char query_tmp[QUERY_LEN]; + str query_tmp_str; + + memset(query_tmp, 0, QUERY_LEN); + ret_tmp = snprintf(query_tmp, QUERY_LEN, "SELECT * FROM %.*s WHERE %.*s=%d and %.*s=%d and %.*s>%d", + carrierroute_table.len, carrierroute_table.s, columns[COL_CARRIER]->len, columns[COL_CARRIER]->s, row->values[COL_CARRIER].val.int_val, + columns[COL_DOMAIN]->len, columns[COL_DOMAIN]->s, row->values[COL_DOMAIN].val.int_val, columns[COL_PROB]->len, columns[COL_PROB]->s, 0); + + if (ret_tmp < 0) { + LM_ERR("error in snprintf while querying prob column"); + goto errout; + } + query_tmp_str.s = query_tmp; + query_tmp_str.len = ret_tmp; + + if (carrierroute_dbf.raw_query(carrierroute_dbh, &query_tmp_str, &prob_res) < 0) { + LM_ERR("Failed to query carrierroute db table based on prob column.\n"); + goto errout; + } + if(RES_ROW_N(prob_res) == 0) { + LM_ERR("Carrierroute db table contains route(s) with only 0 probability.\n"); + query_done = true; + } + carrierroute_dbf.free_result(carrierroute_dbh, prob_res); + prob_res = NULL; + } + } if (DB_CAPABILITY(carrierroute_dbf, DB_CAP_FETCH)) { if(carrierroute_dbf.fetch_result(carrierroute_dbh, &res, cfg_get(carrierroute, carrierroute_cfg, fetch_rows)) < 0) { @@ -462,5 +493,8 @@ int load_route_data_db(struct route_data_t * rd) { if (res) { carrierroute_dbf.free_result(carrierroute_dbh, res); } + if (prob_res) { + carrierroute_dbf.free_result(carrierroute_dbh, prob_res); + } return -1; } diff --git a/src/modules/carrierroute/cr_db.h b/src/modules/carrierroute/cr_db.h index 1f53c9307bd..ffea7311928 100644 --- a/src/modules/carrierroute/cr_db.h +++ b/src/modules/carrierroute/cr_db.h @@ -88,4 +88,9 @@ int load_route_data_db (struct route_data_t * rd); int load_user_carrier(str * user, str * domain); +typedef enum { + false = 0, + true = 1 +} boolean; + #endif diff --git a/src/modules/carrierroute/cr_func.c b/src/modules/carrierroute/cr_func.c index 6b6db1387bb..c4ce4d52a00 100644 --- a/src/modules/carrierroute/cr_func.c +++ b/src/modules/carrierroute/cr_func.c @@ -471,7 +471,7 @@ static int rewrite_on_rule(struct route_flags *rf_head, flag_t flags, str * dest avp_value_t cr_new_uri; if(rf->dice_max == 0) { - LM_ERR("invalid dice_max value\n"); + LM_ERR("invalid dice_max value (route has probability 0)\n"); return -1; } if ((prob = hash_func(msg, hash_source, rf->dice_max)) < 0) {