diff --git a/db/db_pi.c b/db/db_pi.c index 7492fffba60..5c9f11db674 100644 --- a/db/db_pi.c +++ b/db/db_pi.c @@ -20,18 +20,35 @@ #include "../str.h" #include "../mi/mi.h" +#include "../db/db.h" - static str pi_conns[] = { - str_init("auth_db"), - str_init("call_center"), - str_init("domain"), - str_init("dialplan"), - str_init("rtpproxy"), - }; +struct pi_conns { + str name; /* the name of the connector */ + str table; /* the name of the table */ + db_con_t *con; /* database connector */ + unsigned int flags; /* different flags */ + struct pi_conns *next; +} *pi_conns_list; + +int db_pi_add(str *name, str *table, db_con_t *con, unsigned int flags) +{ + LM_INFO("adding %.*s connector to PI table=%.*s\n", + name->len, name->s, table->len, table->s); + /* TODO: add a new element in pi_conns_list */ + return 0; +} mi_response_t *w_mi_pi_list(const mi_params_t *params, struct mi_handler *async_hdl) { + static str pi_conns[] = { + str_init("auth_db"), + str_init("call_center"), + str_init("domain"), + str_init("dialplan"), + str_init("rtpproxy"), + }; + int i; mi_item_t *resp_arr; mi_response_t *resp = init_mi_result_array(&resp_arr); diff --git a/db/db_pi.h b/db/db_pi.h index d41ef9d0fa9..b47eeb77577 100644 --- a/db/db_pi.h +++ b/db/db_pi.h @@ -21,6 +21,8 @@ #ifndef _DB_PI_H_ #define _DB_PI_H_ +int db_pi_add(str *name, str *table, db_con_t *con, unsigned int flags); + mi_response_t *w_mi_pi_list(const mi_params_t *params, struct mi_handler *async_hdl); diff --git a/modules/domain/domain.c b/modules/domain/domain.c index 81679d01efd..ba1e6a22ba7 100644 --- a/modules/domain/domain.c +++ b/modules/domain/domain.c @@ -30,6 +30,7 @@ #include "domain_mod.h" #include "hash.h" #include "../../db/db.h" +#include "../../db/db_pi.h" #include "../../parser/parse_uri.h" #include "../../parser/parse_from.h" #include "../../ut.h" @@ -56,8 +57,10 @@ int domain_db_bind(const str* db_url) -int domain_db_init(const str* db_url) +int domain_db_init(const str* db_url, int mi) { + str name = str_init("domain"); + if (domain_dbf.init==0){ LM_ERR("Unbound database module\n"); goto error; @@ -67,6 +70,9 @@ int domain_db_init(const str* db_url) LM_ERR("Cannot initialize database connection\n"); goto error; } + if (mi && db_pi_add(&name, &domain_table, db_handle, 0) < 0) + LM_ERR("Failed to add table to provisioning interface\n"); + return 0; error: return -1; diff --git a/modules/domain/domain.h b/modules/domain/domain.h index bb401be2305..0e64807e7cb 100644 --- a/modules/domain/domain.h +++ b/modules/domain/domain.h @@ -55,7 +55,7 @@ int w_is_domain_local(struct sip_msg* _msg, str *domain, pv_spec_t* _s2); int is_domain_local(str* domain); int domain_db_bind(const str* db_url); -int domain_db_init(const str* db_url); +int domain_db_init(const str* db_url, int mi); void domain_db_close(); int domain_db_ver(str* name, int version); diff --git a/modules/domain/domain_mod.c b/modules/domain/domain_mod.c index 9075ff09de9..b752ed37715 100644 --- a/modules/domain/domain_mod.c +++ b/modules/domain/domain_mod.c @@ -196,7 +196,7 @@ static int mod_init(void) /* Check if cache needs to be loaded from domain table */ if (db_mode != 0) { - if (domain_db_init(&db_url)<0) return -1; + if (domain_db_init(&db_url, 0)<0) return -1; /* Check table version */ if (domain_db_ver(&domain_table, TABLE_VERSION) < 0) { @@ -251,7 +251,7 @@ static int child_init(int rank) { /* Check if database is needed by worker processes only */ if ( db_mode==0 && (rank>PROC_MAIN) ) { - if (domain_db_init(&db_url)<0) { + if (domain_db_init(&db_url, 0)<0) { LM_ERR("Unable to connect to the database\n"); return -1; } @@ -262,7 +262,7 @@ static int child_init(int rank) static int mi_child_init(void) { - return domain_db_init(&db_url); + return domain_db_init(&db_url, 1); } diff --git a/modules/rtpproxy/rtpproxy.c b/modules/rtpproxy/rtpproxy.c index 974c73be0b2..f8e12d33bdd 100644 --- a/modules/rtpproxy/rtpproxy.c +++ b/modules/rtpproxy/rtpproxy.c @@ -169,6 +169,7 @@ #include "../../parser/sdp/sdp_helpr_funcs.h" #include "../../parser/sdp/sdp.h" #include "../../db/db.h" +#include "../../db/db_pi.h" #include "../../parser/parse_content.h" #include "../../parser/msg_parser.h" #include "../../parser/parse_body.h" @@ -1249,6 +1250,8 @@ mod_init(void) static int mi_child_init(void) { + str name = str_init("rtpproxy"); + if(child_init(1) < 0) { LM_ERR("Failed to initial rtpp socks\n"); @@ -1270,6 +1273,9 @@ static int mi_child_init(void) return -1; } + if (db_pi_add(&name, &table, db_connection, 0) < 0) + LM_ERR("Failed to add table to provisioning interface\n"); + LM_DBG("Database connection opened successfully\n"); return 0;