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(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; }
void dp_disconnect_all_db(void) { dp_connection_list_t *el; for (el = dp_conns; el; el = el->next) dp_disconnect_db(el); }
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; }
/* * 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 void mod_destroy(void) { dp_connection_list_p el; /*destroy shared memory*/ if(default_par2){ shm_free(default_par2); default_par2 = NULL; } LM_DBG("Disconnecting from all databases\n"); for(el = dp_conns; el ; el = el->next){ dp_disconnect_db(el); LM_DBG("Succesfully disconnected from DB %.*s\n" , el->db_url.len, el->db_url.s); } destroy_data(); }