| 36 | extern struct cachedb_url *db_cachedb_script_urls; |
| 37 | |
| 38 | db_con_t* db_cachedb_init(const str* _url) |
| 39 | { |
| 40 | char *p; |
| 41 | int len; |
| 42 | struct cachedb_url *it; |
| 43 | cachedb_funcs cdbf; |
| 44 | cachedb_con *cdbc = NULL; |
| 45 | struct db_cachedb_con* ptr; |
| 46 | db_con_t *res; |
| 47 | |
| 48 | if (!_url) { |
| 49 | LM_ERR("invalid parameter value\n"); |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | res = pkg_malloc(sizeof(db_con_t)); |
| 54 | if (!res) { |
| 55 | LM_ERR("No more pkg mem\n"); |
| 56 | return NULL; |
| 57 | } |
| 58 | |
| 59 | memset(res,0,sizeof(db_con_t)); |
| 60 | |
| 61 | p=_url->s+sizeof("cachedb:/"); |
| 62 | len=_url->len-sizeof("cachedb:/"); |
| 63 | |
| 64 | for (it=db_cachedb_script_urls;it;it=it->next) { |
| 65 | if (memcmp(it->url.s,p,len) == 0) { |
| 66 | LM_DBG("Found matching URL : [%s]\n", db_url_escape(&it->url)); |
| 67 | |
| 68 | if (cachedb_bind_mod(&it->url,&cdbf) < 0) { |
| 69 | LM_ERR("Cannot bind cachedb functions for URL [%s]\n", |
| 70 | db_url_escape(&it->url)); |
| 71 | return NULL; |
| 72 | } |
| 73 | |
| 74 | cdbc = cdbf.init(&it->url); |
| 75 | if (cdbc == NULL) { |
| 76 | LM_ERR("Failed to connect to the cachedb back-end\n"); |
| 77 | return NULL; |
| 78 | } |
| 79 | |
| 80 | ptr = pkg_malloc(sizeof(struct db_cachedb_con)); |
| 81 | if (!ptr) { |
| 82 | LM_ERR("no private memory left\n"); |
| 83 | pkg_free(res); |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | memset(ptr, 0, sizeof(struct db_cachedb_con)); |
| 88 | ptr->ref = 1; |
| 89 | |
| 90 | ptr->cdbc = cdbc; |
| 91 | ptr->cdbf = cdbf; |
| 92 | |
| 93 | res->tail = (unsigned long)ptr; |
| 94 | LM_DBG("Successfully initiated connection to [%.*s] \n",len,p); |
| 95 |
nothing calls this directly
no test coverage detected