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

Function bdblib_get_table

modules/db_berkeley/bdb_lib.c:419–481  ·  view source on GitHub ↗

* look thru a linked list for the table. if dne, create a new one * and add to the list */

Source from the content-addressed store, hash-verified

417 * and add to the list
418*/
419tbl_cache_p bdblib_get_table(database_p _db, str *_s)
420{
421 tbl_cache_p _tbc = NULL;
422 table_p _tp = NULL;
423
424 if(!_db || !_s || !_s->s || _s->len<=0)
425 return NULL;
426
427 if(!_db->dbenv)
428 {
429 return NULL;
430 }
431
432 _tbc = _db->tables;
433 while(_tbc)
434 {
435 if(_tbc->dtp)
436 {
437
438 if(_tbc->dtp->name.len == _s->len
439 && !strncasecmp(_tbc->dtp->name.s, _s->s, _s->len ))
440 {
441 return _tbc;
442 }
443 }
444 _tbc = _tbc->next;
445 }
446
447 _tbc = (tbl_cache_p)pkg_malloc(sizeof(tbl_cache_t));
448 if(!_tbc)
449 return NULL;
450
451 if(!lock_init(&_tbc->sem))
452 {
453 pkg_free(_tbc);
454 return NULL;
455 }
456
457 _tp = bdblib_create_table(_db, _s);
458
459#ifdef BDB_EXTRA_DEBUG
460 LM_DBG("table: %.*s\n", _s->len, _s->s);
461#endif
462
463 if(!_tp)
464 {
465 LM_ERR("failed to create table.\n");
466 pkg_free(_tbc);
467 return NULL;
468 }
469
470 lock_get(&_tbc->sem);
471 _tbc->dtp = _tp;
472
473 if(_db->tables)
474 (_db->tables)->prev = _tbc;
475
476 _tbc->next = _db->tables;

Callers 6

bdb_check_reloadFunction · 0.85
bdb_queryFunction · 0.85
bdb_insertFunction · 0.85
bdb_deleteFunction · 0.85
_bdb_delete_cursorFunction · 0.85
bdb_updateFunction · 0.85

Calls 4

lock_initFunction · 0.85
bdblib_create_tableFunction · 0.85
lock_getFunction · 0.85
lock_releaseFunction · 0.85

Tested by

no test coverage detected