#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "../../ut.h"
#include "../../trim.h"
#include "../../dprint.h"
#include "../../action.h"
#include "../../route.h"
#include "../../dset.h"
#include "../../mem/shm_mem.h"
#include "../../parser/parse_uri.h"
#include "../../parser/parse_from.h"
#include "../../usr_avp.h"
#include "../../mi/mi.h"
#include "../../parser/digest/digest.h"
#include "../../resolve.h"
#include "../tm/tm_load.h"
#include "../../db/db.h"
#include "../../db/db_res.h"
#include "../../str.h"
#include "dispatch.h"

Go to the source code of this file.
Data Structures | |
| struct | _ds_dest |
| struct | _ds_set |
Defines | |
| #define | _ds_list (ds_lists[*crt_idx]) |
| #define | _ds_list_nr (*ds_list_nr) |
| #define | DS_TABLE_VERSION 1 |
| #define | DS_TABLE_VERSION2 2 |
| #define | DS_TABLE_VERSION3 3 |
Typedefs | |
| typedef struct _ds_dest * | ds_dest_p |
| typedef struct _ds_dest | ds_dest_t |
| typedef struct _ds_set * | ds_set_p |
| typedef struct _ds_set | ds_set_t |
Functions | |
| int | add_dest2list (int id, str uri, int flags, int priority, int list_idx, int *setn) |
| void | destroy_list (int) |
| void | ds_check_timer (unsigned int ticks, void *param) |
| Timer for checking inactive destinations. | |
| int | ds_connect_db (void) |
| int | ds_destroy_list (void) |
| called from dispatcher.c: free all | |
| void | ds_disconnect_db (void) |
| unsigned int | ds_get_hash (str *x, str *y) |
| static int | ds_get_index (int group, ds_set_p *index) |
| int | ds_hash_authusername (struct sip_msg *msg, unsigned int *hash) |
| int | ds_hash_callid (struct sip_msg *msg, unsigned int *hash) |
| int | ds_hash_fromuri (struct sip_msg *msg, unsigned int *hash) |
| int | ds_hash_pvar (struct sip_msg *msg, unsigned int *hash) |
| int | ds_hash_ruri (struct sip_msg *msg, unsigned int *hash) |
| int | ds_hash_touri (struct sip_msg *msg, unsigned int *hash) |
| int | ds_is_from_list (struct sip_msg *_m, int group) |
| int | ds_load_db (void) |
| load groups of destinations from DB | |
| int | ds_load_list (char *lfile) |
| load groups of destinations from file | |
| int | ds_mark_dst (struct sip_msg *msg, int mode) |
| int | ds_next_dst (struct sip_msg *msg, int mode) |
| static void | ds_options_callback (struct cell *t, int type, struct tmcb_params *ps) |
| Callback-Function for the OPTIONS-Request This Function is called, as soon as the Transaction is finished (e. g. a Response came in, the timeout was hit, ...). | |
| int | ds_print_list (FILE *fout) |
| int | ds_print_mi_list (struct mi_node *rpl) |
| static int | ds_print_sets (void) |
| int | ds_select_dst (struct sip_msg *msg, int set, int alg, int mode) |
| int | ds_set_state (int group, str *address, int state, int type) |
| static int | ds_update_dst (struct sip_msg *msg, str *uri, int mode) |
| static int | get_uri_hash_keys (str *key1, str *key2, str *uri, struct sip_uri *parsed_uri, int flags) |
| gets the part of the uri we will use as a key for hashing | |
| int | init_data (void) |
| int | init_ds_db (void) |
| Initialize and verify DB stuff. | |
| int | reindex_dests (int list_idx, int setn) |
| compact destinations from sets for fast access | |
Variables | |
| static int | _ds_table_version = DS_TABLE_VERSION |
| int * | crt_idx = NULL |
| static db_con_t * | ds_db_handle = 0 |
| static db_func_t | ds_dbf |
| int | ds_force_dst |
| int * | ds_list_nr = NULL |
| ds_set_p * | ds_lists = NULL |
| int * | next_idx = NULL |
Definition in file dispatch.c.
Definition at line 107 of file dispatch.c.
Referenced by ds_check_timer(), ds_get_index(), ds_is_from_list(), ds_print_list(), ds_print_mi_list(), ds_print_sets(), ds_select_dst(), and ds_set_state().
| #define _ds_list_nr (*ds_list_nr) |
Definition at line 108 of file dispatch.c.
Referenced by ds_check_timer(), ds_load_db(), ds_load_list(), ds_print_list(), ds_print_mi_list(), ds_select_dst(), and ds_set_state().
| #define DS_TABLE_VERSION 1 |
| #define DS_TABLE_VERSION2 2 |
| #define DS_TABLE_VERSION3 3 |
| int add_dest2list | ( | int | id, | |
| str | uri, | |||
| int | flags, | |||
| int | priority, | |||
| int | list_idx, | |||
| int * | setn | |||
| ) |
Definition at line 164 of file dispatch.c.
References _ds_set::dlist, _ds_dest::flags, sip_uri::host, hostent2ip_addr, _ds_set::id, _ds_dest::ip_address, _str::len, LM_DBG, LM_ERR, _ds_dest::next, _ds_set::next, _ds_set::nr, NULL, parse_uri(), pkg_free, _ds_dest::port, sip_uri::port_no, _ds_dest::priority, resolvehost(), _str::s, shm_free, shm_malloc(), and _ds_dest::uri.
Referenced by ds_load_db(), and ds_load_list().
| void destroy_list | ( | int | list_id | ) |
Definition at line 641 of file dispatch.c.
References _ds_set::dlist, _ds_set::next, _ds_dest::next, NULL, _str::s, shm_free, and _ds_dest::uri.
Referenced by ds_destroy_list(), ds_load_db(), and ds_load_list().
| void ds_check_timer | ( | unsigned int | ticks, | |
| void * | param | |||
| ) |
Timer for checking inactive destinations.
This timer is regularly fired.
Definition at line 1624 of file dispatch.c.
References _ds_list, _ds_list_nr, _ds_set::dlist, ds_options_callback(), ds_ping_from, ds_ping_method, DS_PROBING_DST, ds_probing_mode, _ds_dest::flags, _ds_set::id, _str::len, LM_DBG, LM_ERR, _ds_set::next, _ds_set::nr, NULL, _str::s, tm_binds::t_request, tmb, and _ds_dest::uri.
Referenced by mod_init().
| int ds_connect_db | ( | void | ) |
Definition at line 453 of file dispatch.c.
References ds_db_url, db_func::init, LM_CRIT, and _str::s.
Referenced by init_ds_db(), and mi_child_init().
| int ds_destroy_list | ( | void | ) |
called from dispatcher.c: free all
Definition at line 627 of file dispatch.c.
References crt_idx, destroy_list(), and shm_free.
Referenced by destroy().
| void ds_disconnect_db | ( | void | ) |
Definition at line 471 of file dispatch.c.
References db_func::close.
Referenced by destroy(), and init_ds_db().
Definition at line 668 of file dispatch.c.
References _str::len, and _str::s.
Referenced by ds_hash_authusername(), ds_hash_callid(), ds_hash_fromuri(), ds_hash_pvar(), ds_hash_ruri(), and ds_hash_touri().
| static int ds_get_index | ( | int | group, | |
| ds_set_p * | index | |||
| ) | [inline, static] |
Definition at line 1003 of file dispatch.c.
References _ds_list, _ds_set::id, LM_ERR, _ds_set::next, and NULL.
Referenced by ds_select_dst(), and ds_set_state().
| int ds_hash_authusername | ( | struct sip_msg * | msg, | |
| unsigned int * | hash | |||
| ) |
Definition at line 914 of file dispatch.c.
References sip_msg::authorization, auth_body::digest, ds_get_hash(), HDR_AUTHORIZATION_F, HDR_PROXYAUTH_F, _str::len, LM_DBG, LM_ERR, NULL, parse_credentials(), parse_headers(), hdr_field::parsed, sip_msg::proxy_auth, _str::s, trim(), username::user, and dig_cred::username.
Referenced by ds_select_dst().
| int ds_hash_callid | ( | struct sip_msg * | msg, | |
| unsigned int * | hash | |||
| ) |
Definition at line 862 of file dispatch.c.
References hdr_field::body, sip_msg::callid, ds_get_hash(), HDR_CALLID_F, _str::len, LM_ERR, NULL, parse_headers(), _str::s, and trim().
Referenced by ds_select_dst().
| int ds_hash_fromuri | ( | struct sip_msg * | msg, | |
| unsigned int * | hash | |||
| ) |
Definition at line 790 of file dispatch.c.
References ds_flags, ds_get_hash(), sip_msg::from, get_from, get_uri_hash_keys(), LM_ERR, NULL, parse_from_header(), and trim().
Referenced by ds_select_dst().
| int ds_hash_pvar | ( | struct sip_msg * | msg, | |
| unsigned int * | hash | |||
| ) |
Definition at line 975 of file dispatch.c.
References ds_get_hash(), hash_param_model, _str::len, LM_DBG, LM_ERR, NULL, pv_printf_s(), _str::s, and trim().
Referenced by ds_select_dst().
| int ds_hash_ruri | ( | struct sip_msg * | msg, | |
| unsigned int * | hash | |||
| ) |
Definition at line 889 of file dispatch.c.
References ds_flags, ds_get_hash(), GET_RURI, get_uri_hash_keys(), LM_ERR, NULL, parse_sip_msg_uri(), and sip_msg::parsed_uri.
Referenced by ds_select_dst().
| int ds_hash_touri | ( | struct sip_msg * | msg, | |
| unsigned int * | hash | |||
| ) |
Definition at line 828 of file dispatch.c.
References ds_flags, ds_get_hash(), get_to, get_uri_hash_keys(), HDR_TO_F, LM_ERR, NULL, parse_headers(), sip_msg::to, and trim().
Referenced by ds_select_dst().
| int ds_is_from_list | ( | struct sip_msg * | _m, | |
| int | group | |||
| ) |
Definition at line 1471 of file dispatch.c.
References _ds_list, _ds_set::dlist, ds_setid_pv, ds_setid_pvname, EQ_T, _pv_value::flags, _ds_set::id, ip_addr_cmp, _ds_dest::ip_address, LM_ERR, _ds_set::next, _ds_set::nr, NULL, _ds_dest::port, PV_TYPE_INT, PV_VAL_INT, _pv_spec::pvp, sip_msg::rcv, _pv_value::ri, _str::s, _pv_spec::setf, receive_info::src_ip, and receive_info::src_port.
Referenced by w_ds_is_from_list0(), and w_ds_is_from_list1().
| int ds_load_db | ( | void | ) |
load groups of destinations from DB
Definition at line 527 of file dispatch.c.
References _ds_list_nr, _ds_table_version, add_dest2list(), crt_idx, destroy_list(), ds_dest_flags_col, ds_dest_priority_col, ds_dest_uri_col, ds_print_sets(), ds_set_id_col, ds_table_name, DS_TABLE_VERSION2, DS_TABLE_VERSION3, db_func::free_result, id, _str::len, LM_ERR, LM_WARN, next_idx, NULL, priority, db_func::query, reindex_dests(), RES_ROW_N, RES_ROWS, ROW_VALUES, _str::s, db_func::use_table, VAL_INT, and VAL_STR.
Referenced by ds_mi_reload(), and init_ds_db().
| int ds_load_list | ( | char * | lfile | ) |
load groups of destinations from file
Definition at line 329 of file dispatch.c.
References _ds_list_nr, add_dest2list(), crt_idx, destroy_list(), ds_print_sets(), id, _str::len, LM_ERR, LM_WARN, next_idx, NULL, priority, reindex_dests(), and _str::s.
Referenced by ds_mi_reload(), and mod_init().
| int ds_mark_dst | ( | struct sip_msg * | msg, | |
| int | mode | |||
| ) |
Definition at line 1320 of file dispatch.c.
References AVP_VAL_STR, DS_FAILOVER_ON, ds_flags, DS_INACTIVE_DST, DS_PROBING_DST, ds_set_state(), dst_avp_name, dst_avp_type, usr_avp::flags, group, grp_avp_name, grp_avp_type, _str::len, LM_DBG, LM_WARN, int_str::n, NULL, _str::s, int_str::s, and search_first_avp().
Referenced by w_ds_mark_dst0(), and w_ds_mark_dst1().
| int ds_next_dst | ( | struct sip_msg * | msg, | |
| int | mode | |||
| ) |
Definition at line 1288 of file dispatch.c.
References AVP_VAL_STR, destroy_avp(), DS_FAILOVER_ON, ds_flags, ds_update_dst(), dst_avp_name, dst_avp_type, usr_avp::flags, _str::len, LM_DBG, LM_ERR, LM_WARN, int_str::n, NULL, _str::s, int_str::s, search_first_avp(), and search_next_avp().
Referenced by w_ds_next_domain(), and w_ds_next_dst().
| static void ds_options_callback | ( | struct cell * | t, | |
| int | type, | |||
| struct tmcb_params * | ps | |||
| ) | [static] |
Callback-Function for the OPTIONS-Request This Function is called, as soon as the Transaction is finished (e. g. a Response came in, the timeout was hit, ...).
Definition at line 1566 of file dispatch.c.
References tmcb_params::code, DS_INACTIVE_DST, DS_PROBING_DST, ds_probing_mode, DS_RESET_FAIL_DST, ds_set_state(), group, _str::len, LM_DBG, LM_ERR, tmcb_params::param, _str::s, and cell::to.
Referenced by ds_check_timer().
| int ds_print_list | ( | FILE * | fout | ) |
Definition at line 1425 of file dispatch.c.
References _ds_list, _ds_list_nr, _ds_set::dlist, DS_INACTIVE_DST, DS_PROBING_DST, _ds_dest::failure_count, _ds_dest::flags, _ds_set::id, _str::len, LM_ERR, _ds_set::next, _ds_set::nr, NULL, probing_threshhold, _str::s, and _ds_dest::uri.
| int ds_print_mi_list | ( | struct mi_node * | rpl | ) |
Definition at line 1511 of file dispatch.c.
References _ds_list, _ds_list_nr, add_mi_attr(), add_mi_node_child(), _ds_set::dlist, DS_INACTIVE_DST, DS_PROBING_DST, _ds_dest::flags, _ds_set::id, int2str(), _str::len, len, LM_ERR, MI_DUP_VALUE, _ds_set::next, _ds_set::nr, NULL, _str::s, and _ds_dest::uri.
Referenced by ds_mi_list().
| static int ds_print_sets | ( | void | ) | [static] |
Definition at line 112 of file dispatch.c.
References _ds_list, _ds_set::dlist, _ds_dest::flags, _ds_set::id, _str::len, LM_DBG, _ds_set::next, _ds_set::nr, NULL, _ds_dest::priority, _str::s, and _ds_dest::uri.
Referenced by ds_load_db(), and ds_load_list().
| int ds_select_dst | ( | struct sip_msg * | msg, | |
| int | set, | |||
| int | alg, | |||
| int | mode | |||
| ) |
Definition at line 1074 of file dispatch.c.
References _ds_list, _ds_list_nr, add_avp(), AVP_VAL_STR, cnt_avp_name, cnt_avp_type, _ds_set::dlist, DS_FAILOVER_ON, ds_flags, ds_force_dst, ds_get_index(), ds_hash_authusername(), ds_hash_callid(), ds_hash_fromuri(), ds_hash_pvar(), ds_hash_ruri(), ds_hash_touri(), DS_INACTIVE_DST, DS_PROBING_DST, ds_update_dst(), ds_use_default, dst_avp_name, dst_avp_type, sip_msg::dst_uri, _ds_dest::flags, grp_avp_name, grp_avp_type, hash, _ds_set::last, _str::len, LM_DBG, LM_ERR, LM_WARN, int_str::n, _ds_set::nr, NULL, int_str::s, _str::s, and _ds_dest::uri.
Referenced by w_ds_select_domain(), and w_ds_select_dst().
| int ds_set_state | ( | int | group, | |
| str * | address, | |||
| int | state, | |||
| int | type | |||
| ) |
Definition at line 1362 of file dispatch.c.
References _ds_list, _ds_list_nr, _ds_set::dlist, ds_get_index(), DS_INACTIVE_DST, DS_PROBING_DST, DS_RESET_FAIL_DST, _ds_dest::failure_count, _ds_dest::flags, _str::len, LM_ERR, LM_INFO, NULL, probing_threshhold, _str::s, and _ds_dest::uri.
Referenced by ds_mark_dst(), ds_mi_set(), and ds_options_callback().
Definition at line 1031 of file dispatch.c.
References append_branch(), do_action(), ds_append_branch, action::elem, FAILURE_ROUTE, _str::len, LM_ERR, action::next, NULL, Q_UNSPECIFIED, route_type, _str::s, set_dst_uri(), SET_HOSTALL_T, action_elem_::string, STRING_ST, action_elem_::type, action::type, and action_elem_::u.
Referenced by ds_next_dst(), and ds_select_dst().
| static int get_uri_hash_keys | ( | str * | key1, | |
| str * | key2, | |||
| str * | uri, | |||
| struct sip_uri * | parsed_uri, | |||
| int | flags | |||
| ) | [inline, static] |
gets the part of the uri we will use as a key for hashing
| key1 | - will be filled with first part of the key (uri user or "" if no user) | |
| key2 | - will be filled with the second part of the key (uri host:port) | |
| uri | - str with the whole uri | |
| parsed_uri | - struct sip_uri pointer with the parsed uri (it must point inside uri). It can be null (in this case the uri will be parsed internally). | |
| flags | - if & DS_HASH_USER_ONLY, only the user part of the uri will be used |
Definition at line 736 of file dispatch.c.
References DS_HASH_USER_ONLY, sip_uri::host, _str::len, LM_ERR, LM_WARN, parse_uri(), sip_uri::port, sip_uri::port_no, _str::s, SIP_PORT, SIPS_PORT, SIPS_URI_T, sip_uri::type, and sip_uri::user.
Referenced by ds_hash_fromuri(), ds_hash_ruri(), and ds_hash_touri().
| int init_data | ( | void | ) |
Definition at line 136 of file dispatch.c.
References crt_idx, ds_list_nr, init_db_data(), LM_DBG, LM_ERR, next_idx, and shm_malloc().
Referenced by mod_init().
| int init_ds_db | ( | void | ) |
Initialize and verify DB stuff.
Definition at line 481 of file dispatch.c.
References _ds_table_version, db_bind_mod(), db_table_version(), ds_connect_db(), ds_db_url, ds_disconnect_db(), ds_load_db(), ds_table_name, DS_TABLE_VERSION, DS_TABLE_VERSION2, DS_TABLE_VERSION3, LM_ERR, and _str::s.
Referenced by mod_init().
| int reindex_dests | ( | int | list_idx, | |
| int | setn | |||
| ) |
compact destinations from sets for fast access
Definition at line 288 of file dispatch.c.
References _ds_set::dlist, LM_DBG, LM_ERR, _ds_dest::next, _ds_set::next, NULL, shm_free, and shm_malloc().
Referenced by ds_load_db(), and ds_load_list().
int _ds_table_version = DS_TABLE_VERSION [static] |
| int* crt_idx = NULL |
Definition at line 104 of file dispatch.c.
db_con_t* ds_db_handle = 0 [static] |
Definition at line 101 of file dispatch.c.
Definition at line 100 of file dispatch.c.
| int ds_force_dst |
| int* ds_list_nr = NULL |
Definition at line 102 of file dispatch.c.
| int* next_idx = NULL |
Definition at line 105 of file dispatch.c.
1.5.6