diff --git a/modules/dialplan/dialplan.c b/modules/dialplan/dialplan.c index 5cd5347b930..2704b86ff91 100644 --- a/modules/dialplan/dialplan.c +++ b/modules/dialplan/dialplan.c @@ -44,7 +44,6 @@ #define DEFAULT_PARAM "$ruri.user" -#define DEFAULT_PARTITION "default" #define PARAM_URL "db_url" #define PARAM_TABLE "table_name" #define DP_CHAR_COLON ':' @@ -315,6 +314,8 @@ static int dp_set_partition(modparam_t type, void* val) p.s = (char *)val; p.len = strlen(val); + default_dp_table.len = strlen(default_dp_table.s); + if (dp_create_head(&p)) { LM_ERR("Error creating head!\n"); return -1; @@ -346,6 +347,7 @@ static int mod_init(void) LM_INFO("initializing module...\n"); init_db_url(default_dp_db_url, 1 /* can be null */); + default_dp_table.len = strlen(default_dp_table.s); dpid_column.len = strlen(dpid_column.s); pr_column.len = strlen(pr_column.s); match_op_column.len = strlen(match_op_column.s); @@ -357,11 +359,9 @@ static int mod_init(void) timerec_column.len = strlen(timerec_column.s); disabled_column.len = strlen(disabled_column.s); - if (!dp_df_head && str_match(&dp_df_part, _str(DEFAULT_PARTITION))) { - if (default_dp_db_url.s) - dp_head_insert(DP_TYPE_URL, &default_dp_db_url, &dp_df_part); - - default_dp_table.len = strlen(default_dp_table.s); + if (!dp_df_head && str_match(&dp_df_part, _str(DEFAULT_PARTITION)) && + default_dp_db_url.s) { + dp_head_insert(DP_TYPE_URL, &default_dp_db_url, &dp_df_part); dp_head_insert(DP_TYPE_TABLE, &default_dp_table, &dp_df_part); } diff --git a/modules/dialplan/dialplan.h b/modules/dialplan/dialplan.h index ac551e8cdc2..4c8347ea73d 100644 --- a/modules/dialplan/dialplan.h +++ b/modules/dialplan/dialplan.h @@ -36,6 +36,8 @@ #define REGEX_OP 1 #define EQUAL_OP 0 +#define DEFAULT_PARTITION "default" + #define DP_CASE_INSENSITIVE 1 #define DP_INDEX_HASH_SIZE 16 diff --git a/modules/dialplan/dp_db.c b/modules/dialplan/dp_db.c index 76931d8da1e..53550a75f49 100644 --- a/modules/dialplan/dp_db.c +++ b/modules/dialplan/dp_db.c @@ -169,21 +169,45 @@ void dp_disconnect_db(dp_connection_list_p dp_conn) int init_data(void) { dp_head_p start, tmp; - int found_df_part = 0; - start = dp_hlist; - if (!start) { + if (!dp_hlist) { LM_ERR("no partition defined, not even the default one!\n"); return -1; } + /* was the default partition re-pointed? */ + if (!str_match(&dp_df_part, _str(DEFAULT_PARTITION))) { + int found = 0; + + for (start = dp_hlist; start; start = start->next) { + if (str_match(&dp_df_part, &start->partition)) { + found = 1; + break; + } + } + + if (!found) { + LM_ERR("partition not found: '%.*s'\n", + dp_df_part.len, dp_df_part.s); + return -1; + } + } + + if (!dp_df_head) { + if (pkg_str_dup(&dp_df_part, &dp_hlist->partition) < 0) { + LM_ERR("oom\n"); + return -1; + } + + LM_INFO("no 'default' partition set, assuming '%.*s'\n", + dp_df_part.len, dp_df_part.s); + } + + start = dp_hlist; while (start) { LM_DBG("Adding partition with name [%.*s]\n", start->partition.len, start->partition.s); - if (str_match(&start->partition, &dp_df_part)) - found_df_part = 1; - if (!dp_add_connection(start)) { LM_ERR("failed to initialize partition '%.*s'\n", start->partition.len, start->partition.s); @@ -195,13 +219,8 @@ int init_data(void) pkg_free(tmp); } - if (!found_df_part) { - LM_ERR("partition '%.*s' is not defined\n", - dp_df_part.len, dp_df_part.s); - return -1; - } - dp_hlist = NULL; + dp_df_head = NULL; return 0; }