int frd_init_db(void) { int table_version; if (table_name.s == NULL || table_name.len == 0) { LM_ERR("invalid table name\n"); return -1; } if (db_bind_mod(&db_url, &dbf) != 0) { LM_ERR("unable to bind to a database driver\n"); return -1; } if(frd_connect_db() != 0) return -1; table_version = db_table_version(&dbf, db_handle, &table_name); if (table_version < 0) { LM_ERR("failed to query table version\n"); return -1; } else if (table_version != FRD_TABLE_VERSION) { LM_ERR("invalid table version (found %d , required %d)\n", table_version, FRD_TABLE_VERSION ); return -1; } return 0; }
int domainpolicy_db_ver(const str* db_url, const str* name) { int ver; db_con_t* dbh; if (domainpolicy_dbf.init==0){ LM_CRIT("unbound database\n"); return -1; } dbh=domainpolicy_dbf.init(db_url); if (dbh==0){ LM_CRIT("null database handler\n"); return -1; } ver=db_table_version(&domainpolicy_dbf, dbh, name); domainpolicy_dbf.close(dbh); return ver; }
/*initialize and verify DB stuff*/ int init_ds_db(void) { int _ds_table_version; int ret; if(ds_table_name.s == 0) { LM_ERR("invalid database name\n"); return -1; } /* Find a database module */ if (db_bind_mod(&ds_db_url, &ds_dbf) < 0) { LM_ERR("Unable to bind to a database driver\n"); return -1; } if(ds_connect_db()!=0){ LM_ERR("unable to connect to the database\n"); return -1; } _ds_table_version = db_table_version(&ds_dbf, ds_db_handle, &ds_table_name); if (_ds_table_version < 0) { LM_ERR("failed to query table version\n"); return -1; } else if (_ds_table_version != DS_TABLE_VERSION) { LM_ERR("invalid table version (found %d , required %d)\n" "(use opensipsdbctl reinit)\n", _ds_table_version, DS_TABLE_VERSION ); return -1; } ret = ds_load_db(); ds_disconnect_db(); return ret; }
int init_rtpproxy_db(void) { int ret; int rtpp_table_version; if (rtpp_db_url.s == NULL) /* Database not configured */ return 0; if (db_bind_mod(&rtpp_db_url, &rtpp_dbf) < 0) { LM_ERR("Unable to bind to db driver - %.*s\n", rtpp_db_url.len, rtpp_db_url.s); return -1; } if (rtpp_connect_db() != 0) { LM_ERR("Unable to connect to db\n"); return -1; } rtpp_table_version = db_table_version(&rtpp_dbf, rtpp_db_handle, &rtpp_table_name); if (rtpp_table_version < 0) { LM_ERR("failed to get rtpp table version\n"); ret = -1; goto done; } switch (rtpp_table_version) { case RTPP_TABLE_VERSION: break; default: LM_ERR("invalid table version (found %d, require %d)\n", rtpp_table_version, RTPP_TABLE_VERSION); ret = -1; goto done; } ret = rtpp_load_db(); done: rtpp_disconnect_db(); return ret; }