Skip to content

Commit

Permalink
dialplan: Allow re-pointing the default partition
Browse files Browse the repository at this point in the history
This is useful in situations where script writers do not intend to cache
the default 'dialplan' table, rather only the named partitions.

Example syntax:
    db_default_url = "mysql://opensips:opensipsrw@127.0.0.1/opensips"
    ...
    modparam("dialplan", "partition", "
	pstn:
	    table_name = dialplan_pstn")
    modparam("dialplan", "partition", "default: pstn")

(cherry picked from commit efee343)
(cherry picked from commit 4abd261)
(cherry picked from commit 03bf0ae)
  • Loading branch information
liviuchircu committed Nov 4, 2020
1 parent bff98ff commit e64845a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
10 changes: 9 additions & 1 deletion modules/dialplan/dialplan.c
Expand Up @@ -268,6 +268,14 @@ static int dp_create_head(const str *in)
if (!params)
goto bad_input;

/* support for the "default: my_part" syntax */
if (!props->next && !params->next && !ZSTR(params->s)) {
dp_df_part = params->s;
LM_DBG("changing the default partition to '%.*s'\n",
dp_df_part.len, dp_df_part.s);
return 0;
}

if (str_match(&params->s, _str(PARAM_URL))) {
have_db_url = 1;
dp_head_insert(DP_TYPE_URL, &params->next->s, &partition);
Expand Down Expand Up @@ -358,7 +366,7 @@ static int mod_init(void)
timerec_column.len = strlen(timerec_column.s);
disabled_column.len = strlen(disabled_column.s);

if (!dp_df_head) {
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);

Expand Down
7 changes: 4 additions & 3 deletions modules/dialplan/doc/dialplan_admin.xml
Expand Up @@ -346,15 +346,16 @@ modparam("dialplan", "partition", "
</example>

<example>
<title> The 'default' partition inherits its URL from <varname>'db_default_url'</varname></title>
<title> Define the 'pstn' partition and make it the 'default' partition, so we avoid loading the 'dialplan' table</title>
<programlisting format="linespecific">
...
db_default_url = "mysql://opensips:opensipsrw@localhost/opensips"

loadmodule "dialplan.so"
modparam("dialplan", "partition", "
default:
table_name = dialplan")
pstn:
table_name = dialplan_pstn")
modparam("dialplan", "partition", "default: pstn")
...
</programlisting>
</example>
Expand Down
11 changes: 11 additions & 0 deletions modules/dialplan/dp_db.c
Expand Up @@ -169,6 +169,7 @@ 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) {
Expand All @@ -179,6 +180,10 @@ int init_data(void)
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);
Expand All @@ -190,6 +195,12 @@ 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;
return 0;
}
Expand Down

0 comments on commit e64845a

Please sign in to comment.