| 118 | |
| 119 | #define CACHEDBSQL_DB_DELIMITER '-' |
| 120 | cachedbsql_con* dbcache_new_connection(struct cachedb_id* id) |
| 121 | { |
| 122 | cachedbsql_con *con; |
| 123 | str db_url; |
| 124 | char *p,*end; |
| 125 | int group_name_len,scheme_len; |
| 126 | |
| 127 | if(id == NULL) { |
| 128 | LM_ERR("null db_id\n"); |
| 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | if((id->flags & (CACHEDB_ID_NO_URL | CACHEDB_ID_MULTIPLE_HOSTS)) != 0) { |
| 133 | LM_ERR("bogus url for local cachedb\n"); |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | if (id->group_name == NULL) { |
| 138 | LM_ERR("No sql back-end info provided \n"); |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | group_name_len = strlen(id->group_name); |
| 143 | scheme_len = strlen(id->scheme); |
| 144 | db_url.s = id->initial_url + scheme_len + 1; |
| 145 | db_url.len = strlen(id->initial_url) - scheme_len - 1; |
| 146 | |
| 147 | for (p=id->group_name,end=p+group_name_len;p<end;p++) { |
| 148 | if (*p == CACHEDBSQL_DB_DELIMITER) { |
| 149 | db_url.s += (p-id->group_name) + 1; |
| 150 | db_url.len -= (p-id->group_name) + 1; |
| 151 | break; |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | con = pkg_malloc(sizeof(cachedbsql_con)); |
| 156 | if(con == NULL) { |
| 157 | LM_ERR("no more pkg\n"); |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | memset(con,0,sizeof(cachedbsql_con)); |
| 162 | con->id = id; |
| 163 | con->ref = 1; |
| 164 | |
| 165 | if (db_bind_mod(&db_url, &con->cdb_dbf) < 0){ |
| 166 | LM_ERR("unable to bind to a database driver\n"); |
| 167 | pkg_free(con); |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | con->cdb_db_handle = con->cdb_dbf.init(&db_url); |
| 172 | if (con->cdb_db_handle == 0) { |
| 173 | LM_ERR("Failed to connect to the DB \n"); |
| 174 | pkg_free(con); |
| 175 | return 0; |
| 176 | } |
| 177 |
nothing calls this directly
no test coverage detected