From c0b2a0ae4117e395e1c4724b7b91270d83a0d269 Mon Sep 17 00:00:00 2001 From: Liviu Chircu Date: Wed, 8 Jul 2020 10:39:52 +0300 Subject: [PATCH] dispatcher: Integrate with 'db_default_url' * both 'db_url' and a partition DB URL will inherit their starting value from the 'db_default_url' global * add the option to point the default partition to a known one, in order to avoid unwanted loading of the default table. Example: modparam("dispatcher", "partition", "default: trunks") modparam("dispatcher", "partition", "trunks: db_url = ...") (cherry picked from commit c7d668bad5b2b41a9c9065e1539914f0629ccf64) (cherry picked from commit ba7a4e33a6e2141aa7300f4e5db268c39f5e9520) --- modules/dispatcher/dispatch.c | 7 ++++--- modules/dispatcher/dispatcher.c | 36 ++++++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/modules/dispatcher/dispatch.c b/modules/dispatcher/dispatch.c index abacfc59635..e0d0942edfa 100644 --- a/modules/dispatcher/dispatch.c +++ b/modules/dispatcher/dispatch.c @@ -669,9 +669,10 @@ int init_ds_db(ds_partition_t *partition) LM_ERR("failed to query table version\n"); return -1; } else if (!supported_ds_version(_ds_table_version)) { - LM_ERR("invalid table version (found %d , required %d)\n" - "(use opensips-cli to migrate to latest schema)\n", - _ds_table_version, DS_TABLE_VERSION ); + LM_ERR("invalid version for table '%.*s' (found %d, required %d)\n" + "(use opensips-cli to migrate to latest schema)\n", + partition->table_name.len, partition->table_name.s, + _ds_table_version, DS_TABLE_VERSION ); return -1; } diff --git a/modules/dispatcher/dispatcher.c b/modules/dispatcher/dispatcher.c index 663dda6ccc6..2aa0cb859e2 100644 --- a/modules/dispatcher/dispatcher.c +++ b/modules/dispatcher/dispatcher.c @@ -108,6 +108,9 @@ ds_db_head_t default_db_head = { }; ds_db_head_t *ds_db_heads = NULL; +/* may be used to avoid the undesired loading of the standard table */ +str df_part_override; + typedef struct { str name; str default_value; @@ -494,14 +497,16 @@ static int set_partition_arguments(unsigned int type, void *val) static const char end_pair_delim = ';'; static const char eq_val_delim = '='; static const str blacklist_param = str_init("ds_define_blacklist"); - unsigned int i; + unsigned int i, fixed_end = 0; str raw_line = {(char*)val, strlen(val)}; str arg, value; ds_db_head_t *head = NULL; - if (raw_line.s[raw_line.len - 1] != end_pair_delim) + if (raw_line.s[raw_line.len - 1] != end_pair_delim) { raw_line.s[raw_line.len++] = end_pair_delim; + fixed_end = 1; + } if (parse_partition_argument(&raw_line, &head) != 0) return -1; @@ -510,6 +515,17 @@ static int set_partition_arguments(unsigned int type, void *val) char *end_pair_pos = q_memchr(raw_line.s, end_pair_delim, raw_line.len); char *eq_pos = q_memchr(raw_line.s, eq_val_delim, raw_line.len); + if ((!end_pair_pos || !eq_pos) && head == &default_db_head) { + if (fixed_end) + raw_line.len--; + df_part_override = raw_line; + trim(&df_part_override); + if (!ZSTR(df_part_override)) + return 0; + + memset(&df_part_override, 0, sizeof df_part_override); + } + while (end_pair_pos != NULL && eq_pos != NULL) { arg.s = raw_line.s; @@ -563,7 +579,11 @@ static int partition_init(ds_db_head_t *db_head, ds_partition_t *partition) } memset(partition, 0, sizeof(ds_partition_t)); + partition->name = db_head->partition_name; + if (str_match(&partition->name, &df_part_override)) + default_partition = partition; + partition->table_name = db_head->table_name; partition->db_url = db_head->db_url; partition->db_handle = pkg_malloc(sizeof(struct db_con_t *)); @@ -729,8 +749,8 @@ static inline int check_if_default_head_is_ok(void) */ static int mod_init(void) { - LM_DBG("initializing ...\n"); + init_db_url(default_db_head.db_url, 1 /* can be null */); if (check_if_default_head_is_ok()) { default_db_head.next = ds_db_heads; @@ -790,6 +810,9 @@ static int mod_init(void) /* Creating partitions from head */ ds_db_head_t *head_it = ds_db_heads; while (head_it){ + if (df_part_override.s && head_it == &default_db_head) + goto next_part; + if (inherit_from_default_head(head_it) != 0) return -1; @@ -824,11 +847,18 @@ static int mod_init(void) if (head_it == &default_db_head) default_partition = partition; +next_part: head_it = head_it->next; if (aux != &default_db_head) pkg_free(aux); } + if (df_part_override.s && !default_partition) { + LM_ERR("partition '%.*s' is not defined\n", + df_part_override.len, df_part_override.s); + return -1; + } + /* Only, if the Probing-Timer is enabled the TM-API needs to be loaded: */ if (ds_ping_interval > 0) {