Skip to content

Commit

Permalink
carrierroute: warning for the same carrier/domain having routes with …
Browse files Browse the repository at this point in the history
…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.

(cherry picked from commit 9741bee)
  • Loading branch information
hdikme authored and miconda committed Oct 24, 2017
1 parent 5057930 commit 9800aba
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/modules/carrierroute/cr_db.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -350,6 +351,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) {
Expand Down Expand Up @@ -394,6 +396,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) {
Expand Down Expand Up @@ -460,5 +491,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;
}
5 changes: 5 additions & 0 deletions src/modules/carrierroute/cr_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/modules/carrierroute/cr_func.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 9800aba

Please sign in to comment.