| 336 | } |
| 337 | |
| 338 | int init_cachedb_utils(void) |
| 339 | { |
| 340 | if (profile_timeout<=0) { |
| 341 | LM_ERR("0 or negative profile_timeout not accepted!!\n"); |
| 342 | return -1; |
| 343 | } |
| 344 | if (cachedb_bind_mod(&cdb_url, &cdbf) < 0) { |
| 345 | LM_ERR("cannot bind functions for cachedb_url %s\n", |
| 346 | db_url_escape(&cdb_url)); |
| 347 | return -1; |
| 348 | } |
| 349 | if (!CACHEDB_CAPABILITY(&cdbf, |
| 350 | CACHEDB_CAP_GET|CACHEDB_CAP_ADD|CACHEDB_CAP_SUB)) { |
| 351 | LM_ERR("not enough capabilities\n"); |
| 352 | return -1; |
| 353 | } |
| 354 | |
| 355 | cdbc = cdbf.init(&cdb_url); |
| 356 | if (!cdbc) { |
| 357 | LM_ERR("cannot connect to cachedb_url %s\n", db_url_escape(&cdb_url)); |
| 358 | return -1; |
| 359 | } |
| 360 | |
| 361 | dlg_prof_val_buf.s = pkg_malloc(cdb_val_prefix.len + 32); |
| 362 | if (!dlg_prof_val_buf.s) { |
| 363 | LM_ERR("no more memory to allocate buffer\n"); |
| 364 | return -1; |
| 365 | } |
| 366 | |
| 367 | dlg_prof_noval_buf.s = pkg_malloc(cdb_noval_prefix.len + 32); |
| 368 | if (!dlg_prof_noval_buf.s) { |
| 369 | LM_ERR("no more memory to allocate buffer\n"); |
| 370 | return -1; |
| 371 | } |
| 372 | |
| 373 | dlg_prof_size_buf.s = pkg_malloc(cdb_size_prefix.len + 32); |
| 374 | if (!dlg_prof_size_buf.s) { |
| 375 | LM_ERR("no more memory to allocate buffer\n"); |
| 376 | return -1; |
| 377 | } |
| 378 | |
| 379 | /* copy prefixes in buffer */ |
| 380 | memcpy(dlg_prof_val_buf.s, cdb_val_prefix.s, cdb_val_prefix.len); |
| 381 | memcpy(dlg_prof_noval_buf.s, cdb_noval_prefix.s, cdb_noval_prefix.len); |
| 382 | memcpy(dlg_prof_size_buf.s, cdb_size_prefix.s, cdb_size_prefix.len); |
| 383 | |
| 384 | return 0; |
| 385 | } |
| 386 | |
| 387 | /* faster method to match a profile by name, no other checks */ |
| 388 | struct dlg_profile_table *get_dlg_profile(str *name) |
no test coverage detected