MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / db_init_test_conn

Function db_init_test_conn

modules/sql_cacher/sql_cacher.c:773–914  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

771}
772
773static db_handlers_t *db_init_test_conn(cache_entry_t *c_entry)
774{
775 db_handlers_t *new_db_hdls;
776 str test_query_key_str = str_init(TEST_QUERY_STR);
777 str cdb_test_key = str_init(CDB_TEST_KEY_STR);
778 str cdb_test_val = str_init(CDB_TEST_VAL_STR);
779 db_key_t query_key_col;
780 db_val_t query_key_val;
781 db_res_t *sql_res;
782 str cachedb_res;
783 unsigned int i;
784 int rc;
785
786 new_db_hdls = pkg_malloc(sizeof(db_handlers_t));
787 if (!new_db_hdls) {
788 LM_ERR("No more pkg memory for db handlers\n");
789 return NULL;
790 }
791 new_db_hdls->c_entry = c_entry;
792 new_db_hdls->db_con = 0;
793 new_db_hdls->query_ps = NULL;
794 new_db_hdls->cdbcon = 0;
795
796 /* cachedb init and test connection */
797 if (cachedb_bind_mod(&c_entry->cachedb_url, &new_db_hdls->cdbf) < 0) {
798 LM_ERR("Unable to bind to a cachedb database driver for URL: %s\n",
799 db_url_escape(&c_entry->cachedb_url));
800 return NULL;
801 }
802 /* open a test connection */
803 new_db_hdls->cdbcon = new_db_hdls->cdbf.init(&c_entry->cachedb_url);
804 if (!new_db_hdls->cdbcon) {
805 LM_ERR("Cannot init connection to cachedb: %s\n",
806 db_url_escape(&c_entry->cachedb_url));
807 return NULL;
808 }
809
810 if (new_db_hdls->cdbf.is_replicated &&
811 new_db_hdls->cdbf.is_replicated(new_db_hdls->cdbcon)) {
812 LM_ERR("Cannot use an OpenSIPS replicated cacheDB\n");
813 return NULL;
814 }
815
816 /* setting and getting a test key in cachedb */
817 if (new_db_hdls->cdbf.set(new_db_hdls->cdbcon, &cdb_test_key, &cdb_test_val,
818 0) < 0) {
819 LM_ERR("Failed to set test key in cachedb: %s\n",
820 db_url_escape(&c_entry->cachedb_url));
821 new_db_hdls->cdbf.destroy(new_db_hdls->cdbcon);
822 new_db_hdls->cdbcon = 0;
823 return NULL;
824 }
825 if (new_db_hdls->cdbf.get(new_db_hdls->cdbcon, &cdb_test_key, &cachedb_res) < 0) {
826 LM_ERR("Failed to get test key from cachedb: %s\n",
827 db_url_escape(&c_entry->cachedb_url));
828 new_db_hdls->cdbf.destroy(new_db_hdls->cdbcon);
829 new_db_hdls->cdbcon = 0;
830 return NULL;

Callers 1

mod_initFunction · 0.85

Calls 5

cachedb_bind_modFunction · 0.85
db_url_escapeFunction · 0.85
db_bind_modFunction · 0.85
shm_mallocFunction · 0.85
build_column_typesFunction · 0.85

Tested by

no test coverage detected