Skip to content

Commit

Permalink
db_pi: add skeleton for provisioning PI connectors
Browse files Browse the repository at this point in the history
  • Loading branch information
razvancrainea committed Mar 28, 2020
1 parent 204bab1 commit e5d0580
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 12 deletions.
31 changes: 24 additions & 7 deletions db/db_pi.c
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions db/db_pi.h
Expand Up @@ -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);

Expand Down
8 changes: 7 additions & 1 deletion modules/domain/domain.c
Expand Up @@ -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"
Expand All @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion modules/domain/domain.h
Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions modules/domain/domain_mod.c
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}


Expand Down
6 changes: 6 additions & 0 deletions modules/rtpproxy/rtpproxy.c
Expand Up @@ -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"
Expand Down Expand Up @@ -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");
Expand All @@ -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;
Expand Down

0 comments on commit e5d0580

Please sign in to comment.