int init_db_data(void) { if(!dp_table_name.s || dp_table_name.len<=0){ LM_ERR("invalid database table name\n"); return -1; } /* Find a database module */ if (db_bind_mod(&dp_db_url, &dp_dbf) < 0){ LM_ERR("unable to bind to a database driver\n"); return -1; } if(dp_connect_db() !=0) return -1; if(db_check_table_version(&dp_dbf, dp_db_handle, &dp_table_name, DP_TABLE_VERSION) < 0) { DB_TABLE_VERSION_ERROR(dp_table_name); goto error; } if(dp_load_db() != 0){ LM_ERR("failed to load database data\n"); goto error; } dp_disconnect_db(); return 0; error: dp_disconnect_db(); return -1; }
int test_db(dp_connection_list_p dp_connection){ if (dp_connection->partition.s == 0) { LM_ERR("invalid partition name\n"); return -1; } if (db_bind_mod(&dp_connection->db_url, &dp_connection->dp_dbf) < 0){ LM_ERR("unable to bind to a database driver\n"); return -1; } if (dp_connect_db(dp_connection) !=0) return -1; if (db_check_table_version(&dp_connection->dp_dbf, *dp_connection->dp_db_handle, &dp_connection->table_name, DP_TABLE_VERSION) < 0) { LM_ERR("error during table version check.\n"); goto error; } dp_disconnect_db(dp_connection); return 0; error: dp_disconnect_db(dp_connection); return -1; }
int init_db_data(dp_connection_list_p dp_connection) { if (dp_connection->partition.s == 0) { LM_ERR("invalid partition name\n"); return -1; } if (dp_connect_db(dp_connection) !=0) return -1; if (db_check_table_version(&dp_connection->dp_dbf, *dp_connection->dp_db_handle, &dp_connection->table_name, DP_TABLE_VERSION) < 0) { LM_ERR("error during table version check.\n"); goto error; } if(dp_load_db(dp_connection) != 0){ LM_ERR("failed to load database data\n"); goto error; } return 0; error: dp_disconnect_db(dp_connection); return -1; }
static int mi_child_init(void) { dp_connection_list_p el; /*Connect to DB s and get rules*/ for(el = dp_conns; el; el = el->next){ if (dp_connect_db(el) != 0) { LM_ERR("Unable to init db data\n"); shm_free(el); return -1; } } return 0; }
static int mi_child_init(void) { dp_connection_list_p el; /*Connect to DB s and get rules*/ for(el = dp_conns; el; el = el->next){ if (dp_connect_db(el) != 0) { /* all el shall be freed in mod destroy */ LM_ERR("Unable to init db data\n"); return -1; } } return 0; }
/* * RPC command to reload dialplan table */ static void dialplan_rpc_reload(rpc_t* rpc, void* ctx) { if (dp_connect_db() < 0) { LM_ERR("failed to reload rules fron database (db connect)\n"); rpc->fault(ctx, 500, "DB Connection Error"); return; } if(dp_load_db() != 0){ LM_ERR("failed to reload rules fron database (db load)\n"); dp_disconnect_db(); rpc->fault(ctx, 500, "Dialplan Reload Failed"); return; } dp_disconnect_db(); return; }
static struct mi_root * mi_reload_rules(struct mi_root *cmd_tree, void *param) { struct mi_root* rpl_tree= NULL; if (dp_connect_db() < 0) { LM_ERR("failed to reload rules fron database (db connect)\n"); return 0; } if(dp_load_db() != 0){ LM_ERR("failed to reload rules fron database (db load)\n"); dp_disconnect_db(); return 0; } dp_disconnect_db(); rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN); if (rpl_tree==0) return 0; return rpl_tree; }
static int mi_child_init(void) { return dp_connect_db(); }