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

Function cachedb_do_init

cachedb/cachedb.c:635–691  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

633}
634
635cachedb_con* cachedb_do_init(str *url,void* (*new_connection)(struct cachedb_id *))
636{
637 struct cachedb_id* id;
638 cachedb_con* res;
639 void *con;
640
641 if (url == NULL || url->s == NULL || new_connection == NULL) {
642 LM_ERR("NULL parameter provided\n");
643 return 0;
644 }
645
646 res = pkg_malloc(sizeof(cachedb_con) + url->len);
647 if (res == NULL) {
648 LM_ERR("no more pkg mem\n");
649 return 0;
650 }
651
652 id = NULL;
653
654 memset(res,0,sizeof(cachedb_con) + url->len);
655 res->url.s = (char *)res + sizeof(cachedb_con);
656 res->url.len = url->len;
657 memcpy(res->url.s,url->s,url->len);
658
659 id = new_cachedb_id(url);
660 if (!id) {
661 LM_ERR("cannot parse url [%s]\n", db_url_escape(url));
662 pkg_free(res);
663 return 0;
664 }
665
666 con = cachedb_pool_get(id);
667 if (con == NULL) {
668 LM_DBG("opening new connection\n");
669 con = new_connection(id);
670 if (con == NULL) {
671 LM_ERR("failed to open connection\n");
672 goto err;
673 }
674
675 cachedb_pool_insert((cachedb_pool_con *)con);
676 } else {
677 LM_DBG("connection already in pool\n");
678 free_cachedb_id(id);
679 }
680
681 res->data = con;
682 return res;
683
684err:
685 if (res)
686 pkg_free(res);
687 if (id)
688 free_cachedb_id(id);
689
690 return 0;
691}
692

Callers 8

mongo_con_initFunction · 0.85
dbcache_initFunction · 0.85
lcache_initFunction · 0.85
dynamodb_initFunction · 0.85
couchbase_initFunction · 0.85
redis_initFunction · 0.85
cassandra_initFunction · 0.85
memcached_initFunction · 0.85

Calls 5

new_cachedb_idFunction · 0.85
db_url_escapeFunction · 0.85
cachedb_pool_getFunction · 0.85
cachedb_pool_insertFunction · 0.85
free_cachedb_idFunction · 0.85

Tested by

no test coverage detected