udomain.c File Reference

USRLOC - Userloc domain handling functions

More...

#include "udomain.h"
#include <string.h>
#include "../../parser/parse_methods.h"
#include "../../mem/shm_mem.h"
#include "../../dprint.h"
#include "../../db/db.h"
#include "../../socket_info.h"
#include "../../ut.h"
#include "../../hash_func.h"
#include "ul_mod.h"
#include "utime.h"

Include dependency graph for udomain.c:

Go to the source code of this file.

Functions

urecord_tdb_load_urecord (db_con_t *_c, udomain_t *_d, str *_aor)
 Loads from DB all contacts for an AOR.
int db_timer_udomain (udomain_t *_d)
 Timer function to cleanup expired contacts, DB_ONLY db_mode.
static ucontact_info_tdbrow2info (db_val_t *vals, str *contact)
 Convert database values into ucontact_info.
int delete_urecord (udomain_t *_d, str *_aor, struct urecord *_r)
 Delete a urecord from domain.
void free_udomain (udomain_t *_d)
 Free all memory allocated for the domain.
static void get_static_urecord (udomain_t *_d, str *_aor, struct urecord **_r)
 Returns a static dummy urecord for temporary usage.
int get_urecord (udomain_t *_d, str *_aor, struct urecord **_r)
 Obtain a urecord pointer if the urecord exists in domain.
int insert_urecord (udomain_t *_d, str *_aor, struct urecord **_r)
 Create and insert a new record.
void lock_udomain (udomain_t *_d, str *_aor)
 Get lock for a domain.
void lock_ulslot (udomain_t *_d, int i)
 Get lock for a slot.
void mem_delete_urecord (udomain_t *_d, struct urecord *_r)
 Remove a record from domain in memory.
int mem_insert_urecord (udomain_t *_d, str *_aor, struct urecord **_r)
 Insert a new record into domain in memory.
void mem_timer_udomain (udomain_t *_d)
 Run timer handler for given domain.
int new_udomain (str *_n, int _s, udomain_t **_d)
 Create a new domain structure.
int preload_udomain (db_con_t *_c, udomain_t *_d)
 Load all records from a udomain.
void print_udomain (FILE *_f, udomain_t *_d)
 Debugging helper function.
int testdb_udomain (db_con_t *con, udomain_t *d)
 performs a dummy query just to see if DB is ok
void unlock_udomain (udomain_t *_d, str *_aor)
 Release lock for a domain.
void unlock_ulslot (udomain_t *_d, int i)
 Release lock for a slot.


Detailed Description

USRLOC - Userloc domain handling functions

Definition in file udomain.c.


Function Documentation

urecord_t* db_load_urecord ( db_con_t _c,
udomain_t _d,
str _aor 
)

Loads from DB all contacts for an AOR.

Parameters:
_c database connection
_d domain
_aor address of record
Returns:
pointer to the record on success, 0 on errors or if nothing is found

Definition at line 505 of file udomain.c.

References callid_col, cflags_col, columns, contact_col, CS_SYNC, cseq_col, DB_STR, dbrow2info(), desc_time_order, domain_col, expires_col, flags_col, db_func::free_result, free_urecord(), get_static_urecord(), last_mod_col, _str::len, LM_DBG, LM_ERR, mem_insert_ucontact(), methods_col, udomain::name, db_val_t::nul, NULL, path_col, q_col, db_func::query, received_col, RES_ROW_N, RES_ROWS, ROW_VALUES, _str::s, sock_col, ucontact::state, db_val_t::str_val, db_val_t::type, ul_dbf, use_domain, db_func::use_table, user_agent_col, user_col, db_val_t::val, and vals.

Referenced by get_urecord().

int db_timer_udomain ( udomain_t _d  ) 

Timer function to cleanup expired contacts, DB_ONLY db_mode.

Parameters:
_d cleaned domain
Returns:
0 on success, -1 on failure

Definition at line 612 of file udomain.c.

References act_time, DB_DATETIME, db_func::delete, expires_col, LM_ERR, udomain::name, db_val_t::nul, _str::s, db_val_t::time_val, db_val_t::type, ul_dbf, ul_dbh, db_func::use_table, db_val_t::val, and vals.

Referenced by synchronize_all_udomains().

static ucontact_info_t* dbrow2info ( db_val_t vals,
str contact 
) [inline, static]

Convert database values into ucontact_info.

Convert database values into ucontact_info, expects 12 rows (contact, expirs, q, callid, cseq, flags, ua, received, path, socket, methods, last_modified)

Parameters:
vals database values
contact contact
Returns:
pointer to the ucontact_info on success, 0 on failure

Definition at line 224 of file udomain.c.

References ALL_METHODS, ucontact_info::callid, ucontact_info::cflags, ucontact_info::cseq, double2q(), ucontact_info::expires, ucontact_info::flags, grep_sock_info(), ucontact_info::last_modified, _str::len, LM_CRIT, LM_ERR, LM_WARN, ucontact_info::methods, parse_phostport(), ucontact_info::path, port, ucontact_info::q, ucontact_info::received, _str::s, ucontact_info::sock, ucontact_info::user_agent, VAL_BITMAP, VAL_DOUBLE, VAL_INT, VAL_NULL, VAL_STRING, and VAL_TIME.

Referenced by db_load_urecord(), and preload_udomain().

int delete_urecord ( udomain_t _d,
str _aor,
struct urecord _r 
)

Delete a urecord from domain.

Parameters:
_d domain where the record should be deleted
_aor address of record
_r deleted record
Returns:
0 on success, -1 if the record could not be deleted

Definition at line 885 of file udomain.c.

References ucontact::c, urecord::contacts, db_delete_urecord(), db_mode, DB_ONLY, delete_ucontact(), free_urecord(), get_static_urecord(), get_urecord(), LM_ERR, ucontact::next, and release_urecord().

Referenced by bind_usrloc(), and mi_usrloc_rm_aor().

void free_udomain ( udomain_t _d  ) 

Free all memory allocated for the domain.

Parameters:
_d freed domain

Definition at line 148 of file udomain.c.

References deinit_slot(), lock_ulslot(), shm_free, udomain::size, udomain::table, and unlock_ulslot().

Referenced by free_all_udomains(), and register_udomain().

static void get_static_urecord ( udomain_t _d,
str _aor,
struct urecord **  _r 
) [inline, static]

Returns a static dummy urecord for temporary usage.

Parameters:
_d domain (needed for the name)
_aor address of record
_r new created urecord

Definition at line 170 of file udomain.c.

References urecord::aor, urecord::domain, and udomain::name.

Referenced by db_load_urecord(), delete_urecord(), and insert_urecord().

int get_urecord ( udomain_t _d,
str _aor,
struct urecord **  _r 
)

Obtain a urecord pointer if the urecord exists in domain.

Parameters:
_d domain to search the record
_aor address of record
_r new created record
Returns:
0 if a record was found, 1 if nothing could be found

Definition at line 845 of file udomain.c.

References urecord::aorhash, core_hash(), db_load_urecord(), db_mode, DB_ONLY, hslot::first, _str::len, hslot::n, urecord::next, _str::s, udomain::size, udomain::table, and ul_dbh.

Referenced by bind_usrloc(), delete_urecord(), mi_usrloc_add(), mi_usrloc_rm_contact(), mi_usrloc_show_contact(), and preload_udomain().

int insert_urecord ( udomain_t _d,
str _aor,
struct urecord **  _r 
)

Create and insert a new record.

Parameters:
_d domain to insert the new record
_aor address of the record
_r new created record
Returns:
return 0 on success, -1 on failure

Definition at line 824 of file udomain.c.

References db_mode, DB_ONLY, get_static_urecord(), LM_ERR, and mem_insert_urecord().

Referenced by bind_usrloc(), and mi_usrloc_add().

void lock_udomain ( udomain_t _d,
str _aor 
)

Get lock for a domain.

Parameters:
_d domain
_aor adress of record, used as hash source for the lock slot

Definition at line 749 of file udomain.c.

References core_hash(), db_mode, DB_ONLY, hslot::lockidx, udomain::size, udomain::table, and ul_lock_idx().

Referenced by bind_usrloc(), mi_usrloc_add(), mi_usrloc_rm_aor(), mi_usrloc_rm_contact(), mi_usrloc_show_contact(), and preload_udomain().

void lock_ulslot ( udomain_t _d,
int  i 
)

Get lock for a slot.

Parameters:
_d domain
i slot number

Definition at line 789 of file udomain.c.

References db_mode, DB_ONLY, hslot::lockidx, udomain::table, and ul_lock_idx().

Referenced by free_udomain(), get_all_mem_ucontacts(), mem_timer_udomain(), and mi_usrloc_dump().

void mem_delete_urecord ( udomain_t _d,
struct urecord _r 
)

Remove a record from domain in memory.

Parameters:
_d domain the record belongs to
_r deleted record

Definition at line 705 of file udomain.c.

References free_urecord(), urecord::slot, slot_rem(), update_stat, and udomain::users.

Referenced by mem_timer_udomain(), and release_urecord().

int mem_insert_urecord ( udomain_t _d,
str _aor,
struct urecord **  _r 
)

Insert a new record into domain in memory.

Parameters:
_d domain the record belongs to
_aor address of record
_r new created record
Returns:
0 on success, -1 on failure

Definition at line 684 of file udomain.c.

References LM_ERR, udomain::name, new_urecord(), udomain::size, slot_add(), udomain::table, update_stat, and udomain::users.

Referenced by insert_urecord(), and preload_udomain().

void mem_timer_udomain ( udomain_t _d  ) 

Run timer handler for given domain.

Parameters:
_d domain

Definition at line 717 of file udomain.c.

References urecord::contacts, hslot::first, lock_ulslot(), mem_delete_urecord(), urecord::next, udomain::size, udomain::table, timer_urecord(), and unlock_ulslot().

Referenced by synchronize_all_udomains().

int new_udomain ( str _n,
int  _s,
udomain_t **  _d 
)

Create a new domain structure.

Parameters:
_n is pointer to str representing name of the domain, the string is not copied, it should point to str structure stored in domain list
_s is hash table size
_d new created domain
Returns:
0 on success, -1 on failure

Definition at line 83 of file udomain.c.

References init_slot(), LM_ERR, register_stat, shm_free, shm_malloc(), STAT_NO_RESET, and STAT_SHM_NAME.

Referenced by new_dlist().

int preload_udomain ( db_con_t _c,
udomain_t _d 
)

void print_udomain ( FILE *  _f,
udomain_t _d 
)

Debugging helper function.

Print udomain, debugging helper function.

Definition at line 185 of file udomain.c.

References hslot::first, _str::len, max, hslot::n, udomain::name, urecord::next, print_urecord(), _str::s, udomain::size, urecord::slot, table, udomain::table, and ZSW.

Referenced by print_all_udomains().

int testdb_udomain ( db_con_t con,
udomain_t d 
)

performs a dummy query just to see if DB is ok

Parameters:
con database connection
d domain

Definition at line 649 of file udomain.c.

References DB_STRING, db_func::free_result, LM_ERR, udomain::name, NULL, db_func::query, ul_dbf, db_func::use_table, user_col, VAL_NULL, VAL_STRING, and VAL_TYPE.

Referenced by register_udomain().

void unlock_udomain ( udomain_t _d,
str _aor 
)

Release lock for a domain.

Parameters:
_d domain
_aor address of record, uses as hash source for the lock slot

Definition at line 770 of file udomain.c.

References core_hash(), db_mode, DB_ONLY, hslot::lockidx, udomain::size, udomain::table, and ul_release_idx().

Referenced by bind_usrloc(), mi_usrloc_add(), mi_usrloc_rm_aor(), mi_usrloc_rm_contact(), mi_usrloc_show_contact(), and preload_udomain().

void unlock_ulslot ( udomain_t _d,
int  i 
)

Release lock for a slot.

Parameters:
_d domain
i slot number

Definition at line 805 of file udomain.c.

References db_mode, DB_ONLY, hslot::lockidx, udomain::table, and ul_release_idx().

Referenced by free_udomain(), get_all_mem_ucontacts(), mem_timer_udomain(), and mi_usrloc_dump().


Generated on Thu May 24 22:00:45 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6