lcr_mod.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include <pcre.h>
#include "../../locking.h"
#include "../../sr_module.h"
#include "../../dprint.h"
#include "../../ut.h"
#include "../../error.h"
#include "../../mem/mem.h"
#include "../../mem/shm_mem.h"
#include "../../db/db.h"
#include "../../usr_avp.h"
#include "../../parser/parse_uri.h"
#include "../../parser/parse_from.h"
#include "../../parser/msg_parser.h"
#include "../../action.h"
#include "../../qvalue.h"
#include "../../dset.h"
#include "../../ip_addr.h"
#include "../../resolve.h"
#include "../../mi/mi.h"
#include "../../mod_fix.h"
#include "../../socket_info.h"
#include "../tm/tm_load.h"
#include "../../pvar.h"
#include "hash.h"
#include "mi.h"

Include dependency graph for lcr_mod.c:

Go to the source code of this file.

Data Structures

struct  gw_grp
struct  gw_info
struct  matched_gw_info

Defines

#define DEF_FETCH_ROWS   2000
#define DEF_LCR_HASH_SIZE   128
#define DEF_PING_TIMER   180
#define FLAGS_COL   "flags"
#define FROM_URI_COL   "from_uri"
#define GRP_ID_COL   "grp_id"
#define GW_NAME_COL   "gw_name"
#define GW_TABLE   "gw"
#define GW_TABLE_VERSION   9
#define HOSTNAME_COL   "hostname"
#define IP_ADDR_COL   "ip_addr"
#define LCR_TABLE   "lcr"
#define LCR_TABLE_VERSION   2
#define MAX_CODES   10
#define MAX_HOST_LEN   64
#define MAX_NO_OF_GWS   128
#define MAX_TAG_LEN   16
#define MAX_USER_LEN   64
#define PING_COL   "ping"
#define PORT_COL   "port"
#define PREFIX_COL   "prefix"
#define PRIORITY_COL   "priority"
#define Q_FLAG   (1<<2)
#define STRIP_COL   "strip"
#define TAG_COL   "tag"
#define TRANSPORT_COL   "transport"
#define URI_SCHEME_COL   "uri_scheme"
#define WEIGHT_COL   "weight"

Typedefs

typedef enum sip_protos uri_transport

Functions

static int add_code_to_array (str *codes, int local_codes[])
void add_gws_into_avps (struct matched_gw_info *matched_gws, unsigned int gw_cnt, str *ruri_user)
static void check_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, ...) Some part of this code was imported from dispatcher module.
int check_our_gws (void)
static int comp_gw_grps (const void *_g1, const void *_g2)
static int comp_gws (const void *_g1, const void *_g2)
static int comp_matched (const void *m1, const void *m2)
int decode_avp_value (char *value, str *scheme, unsigned int *strip, str *tag, str *addr, str *hostname, str *port, str *transport, unsigned int *flags)
static void destroy (void)
static int do_from_gw (struct sip_msg *_m, pv_spec_t *addr_sp, int grp_id)
static int do_load_gws (struct sip_msg *_m, str *_from_uri)
static int do_to_gw (struct sip_msg *_m, pv_spec_t *addr_sp, int grp_id)
int encode_avp_value (char *value, uri_type scheme, unsigned int strip, char *tag, unsigned int tag_len, unsigned int ip_addr, char *hostname, unsigned int hostname_len, unsigned int port, uri_transport transport, unsigned int flags)
static int find_first_gw (struct gw_grp *gw_grps, unsigned int grp_cnt, unsigned int grp_id)
static int fixstringloadgws (void **param, int param_count)
static void free_shared_memory (void)
static int from_gw_0 (struct sip_msg *_m, char *_s1, char *_s2)
static int from_gw_1 (struct sip_msg *_m, char *_s1, char *_s2)
static int from_gw_grp (struct sip_msg *_m, char *_s1, char *_s2)
static int generate_uris (char *r_uri, str *r_uri_user, unsigned int *r_uri_len, char *dst_uri, unsigned int *dst_uri_len, unsigned int *flags)
int gw_set_state (int index, struct sip_uri *uri, int ping)
static int gw_unique (const struct gw_info *gws, const unsigned int count, const unsigned int ip_addr, const unsigned int grp_id)
static int insert_gw (struct gw_info *gws, unsigned int i, unsigned int ip_addr, char *hostname, unsigned int hostname_len, unsigned int grp_id, char *ip_string, unsigned int port, unsigned int scheme, unsigned int transport, unsigned int flags, unsigned int strip, char *tag, unsigned int tag_len, unsigned short weight, unsigned short ping)
static int lcr_db_bind (const str *db_url)
static void lcr_db_close (void)
static int lcr_db_init (const str *db_url)
static void link_gw_grps (struct gw_info *gws, struct gw_grp *gw_grps, unsigned int *grp_cnt)
static int load_gws_0 (struct sip_msg *_m, char *_s1, char *_s2)
static int load_gws_1 (struct sip_msg *_m, char *_s1, char *_s2)
static int load_gws_from_grp (struct sip_msg *_m, char *_s1, char *_s2)
static int mi_child_init (void)
int mi_print_gws (struct mi_node *rpl)
int mi_print_lcrs (struct mi_node *rpl)
static int mod_init (void)
static int next_gw (struct sip_msg *_m, char *_s1, char *_s2)
static int prefix_len_insert (struct lcr_info **table, unsigned short prefix_len)
static pcre * reg_ex_comp (const char *pattern)
int reload_gws_and_lcrs (void)
int send_sip_options_request (str *to, int index)
static void timer (unsigned int ticks, void *param)
static int to_gw_0 (struct sip_msg *_m, char *_s1, char *_s2)
static int to_gw_1 (struct sip_msg *_m, char *_s1, char *_s2)
static int to_gw_grp (struct sip_msg *_m, char *_s1, char *_s2)

Variables

static cmd_export_t cmds []
static db_con_tdb_handle = 0
static str db_url = str_init(DEFAULT_RODB_URL)
struct module_exports exports
static int fetch_rows_param = DEF_FETCH_ROWS
static int_str flags_avp
static char * flags_avp_param = NULL
static int flags_avp_type
static str flags_col = str_init(FLAGS_COL)
static str from_uri_col = str_init(FROM_URI_COL)
static str grp_id_col = str_init(GRP_ID_COL)
static str gw_name_col = str_init(GW_NAME_COL)
static str gw_table = str_init(GW_TABLE)
static int_str gw_uri_avp
static char * gw_uri_avp_param = NULL
static int gw_uri_avp_type
struct gw_info ** gws
struct gw_infogws_1
struct gw_infogws_2
static str hostname_col = str_init(HOSTNAME_COL)
static str ip_addr_col = str_init(IP_ADDR_COL)
static db_func_t lcr_dbf
unsigned int lcr_hash_size_param = DEF_LCR_HASH_SIZE
static str lcr_table = str_init(LCR_TABLE)
struct lcr_info *** lcrs
struct lcr_info ** lcrs_1
struct lcr_info ** lcrs_2
static mi_export_t mi_cmds []
int negative_codes [MAX_CODES]
static str negative_codes_str = {"408", 3}
static param_export_t params []
static str ping_col = str_init(PING_COL)
static str ping_from = {"sip:127.0.0.1", 20}
int ping_interval = 0
static str ping_method = {"OPTIONS", 7}
static str port_col = str_init(PORT_COL)
int positive_codes [MAX_CODES]
static str positive_codes_str = {"200;501;403;404", 15}
static str prefix_col = str_init(PREFIX_COL)
static str priority_col = str_init(PRIORITY_COL)
gen_lock_t * reload_lock
static int_str rpid_avp
static char * rpid_avp_param = NULL
static int rpid_avp_type
static int_str ruri_user_avp
static char * ruri_user_avp_param = NULL
static int ruri_user_avp_type
static str strip_col = str_init(STRIP_COL)
static str tag_col = str_init(TAG_COL)
struct tm_binds tmb
static str transport_col = str_init(TRANSPORT_COL)
static str uri_scheme_col = str_init(URI_SCHEME_COL)
static str weight_col = str_init(WEIGHT_COL)


Define Documentation

#define DEF_FETCH_ROWS   2000

Definition at line 132 of file lcr_mod.c.

#define DEF_LCR_HASH_SIZE   128

Definition at line 131 of file lcr_mod.c.

#define DEF_PING_TIMER   180

Definition at line 133 of file lcr_mod.c.

Referenced by mod_init().

#define FLAGS_COL   "flags"

Definition at line 113 of file lcr_mod.c.

#define FROM_URI_COL   "from_uri"

Definition at line 121 of file lcr_mod.c.

#define GRP_ID_COL   "grp_id"

Definition at line 95 of file lcr_mod.c.

#define GW_NAME_COL   "gw_name"

Definition at line 93 of file lcr_mod.c.

#define GW_TABLE   "gw"

Definition at line 91 of file lcr_mod.c.

#define GW_TABLE_VERSION   9

Definition at line 79 of file lcr_mod.c.

Referenced by mod_init().

#define HOSTNAME_COL   "hostname"

Definition at line 99 of file lcr_mod.c.

#define IP_ADDR_COL   "ip_addr"

Definition at line 97 of file lcr_mod.c.

#define LCR_TABLE   "lcr"

Definition at line 117 of file lcr_mod.c.

#define LCR_TABLE_VERSION   2

Definition at line 80 of file lcr_mod.c.

Referenced by mod_init().

#define MAX_CODES   10

Definition at line 134 of file lcr_mod.c.

Referenced by add_code_to_array(), and check_options_callback().

#define MAX_HOST_LEN   64

Definition at line 127 of file lcr_mod.c.

Referenced by reload_gws_and_lcrs().

#define MAX_NO_OF_GWS   128

Definition at line 125 of file lcr_mod.c.

Referenced by mod_init().

#define MAX_TAG_LEN   16

Definition at line 126 of file lcr_mod.c.

Referenced by reload_gws_and_lcrs().

#define MAX_USER_LEN   64

Definition at line 128 of file lcr_mod.c.

Referenced by reload_gws_and_lcrs().

#define PING_COL   "ping"

Definition at line 115 of file lcr_mod.c.

#define PORT_COL   "port"

Definition at line 101 of file lcr_mod.c.

#define PREFIX_COL   "prefix"

Definition at line 119 of file lcr_mod.c.

#define PRIORITY_COL   "priority"

Definition at line 123 of file lcr_mod.c.

#define Q_FLAG   (1<<2)

Definition at line 83 of file lcr_mod.c.

Referenced by t_load_contacts(), and t_next_contacts().

#define STRIP_COL   "strip"

Definition at line 107 of file lcr_mod.c.

#define TAG_COL   "tag"

Definition at line 109 of file lcr_mod.c.

#define TRANSPORT_COL   "transport"

Definition at line 105 of file lcr_mod.c.

#define URI_SCHEME_COL   "uri_scheme"

Definition at line 103 of file lcr_mod.c.

#define WEIGHT_COL   "weight"

Definition at line 111 of file lcr_mod.c.


Typedef Documentation

typedef enum sip_protos uri_transport

Definition at line 143 of file lcr_mod.c.


Function Documentation

int add_code_to_array ( str codes,
int  local_codes[] 
) [static]

Definition at line 2636 of file lcr_mod.c.

References _str::len, LM_ERR, MAX_CODES, NULL, _str::s, str2int(), and trim_spaces_lr.

Referenced by mod_init().

void add_gws_into_avps ( struct matched_gw_info matched_gws,
unsigned int  gw_cnt,
str ruri_user 
)

static void check_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, ...) Some part of this code was imported from dispatcher module.

Definition at line 2414 of file lcr_mod.c.

References tmcb_params::code, gw_set_state(), sip_uri::host, _str::len, LM_DBG, LM_ERR, MAX_CODES, negative_codes, NULL, tmcb_params::param, parse_uri(), positive_codes, _str::s, and cell::to.

Referenced by send_sip_options_request().

int check_our_gws ( void   ) 

static int comp_gw_grps ( const void *  _g1,
const void *  _g2 
) [static]

Definition at line 808 of file lcr_mod.c.

References gw_info::grp_id, and gw_info::ip_addr.

Referenced by reload_gws_and_lcrs().

static int comp_gws ( const void *  _g1,
const void *  _g2 
) [static]

Definition at line 826 of file lcr_mod.c.

References gw_info::ip_addr.

static int comp_matched ( const void *  m1,
const void *  m2 
) [static]

int decode_avp_value ( char *  value,
str scheme,
unsigned int *  strip,
str tag,
str addr,
str hostname,
str port,
str transport,
unsigned int *  flags 
) [inline]

static void destroy ( void   )  [static]

static int do_from_gw ( struct sip_msg _m,
pv_spec_t addr_sp,
int  grp_id 
) [static]

static int do_load_gws ( struct sip_msg _m,
str _from_uri 
) [static]

static int do_to_gw ( struct sip_msg _m,
pv_spec_t addr_sp,
int  grp_id 
) [static]

int encode_avp_value ( char *  value,
uri_type  scheme,
unsigned int  strip,
char *  tag,
unsigned int  tag_len,
unsigned int  ip_addr,
char *  hostname,
unsigned int  hostname_len,
unsigned int  port,
uri_transport  transport,
unsigned int  flags 
) [inline]

Definition at line 1546 of file lcr_mod.c.

References append_chr, append_str, int2str(), and len.

Referenced by add_gws_into_avps().

static int find_first_gw ( struct gw_grp gw_grps,
unsigned int  grp_cnt,
unsigned int  grp_id 
) [static]

Definition at line 919 of file lcr_mod.c.

References gw_grp::first.

Referenced by reload_gws_and_lcrs().

static int fixstringloadgws ( void **  param,
int  param_count 
) [static]

static void free_shared_memory ( void   )  [static]

Definition at line 679 of file lcr_mod.c.

References lcr_hash_table_contents_free(), reload_lock, and shm_free.

Referenced by load_pcres(), and mod_init().

static int from_gw_0 ( struct sip_msg _m,
char *  _s1,
char *  _s2 
) [static]

Definition at line 2224 of file lcr_mod.c.

References do_from_gw().

static int from_gw_1 ( struct sip_msg _m,
char *  _s1,
char *  _s2 
) [static]

Definition at line 2234 of file lcr_mod.c.

References do_from_gw().

static int from_gw_grp ( struct sip_msg _m,
char *  _s1,
char *  _s2 
) [static]

Definition at line 2214 of file lcr_mod.c.

References do_from_gw().

static int generate_uris ( char *  r_uri,
str r_uri_user,
unsigned int *  r_uri_len,
char *  dst_uri,
unsigned int *  dst_uri_len,
unsigned int *  flags 
) [static]

int gw_set_state ( int  index,
struct sip_uri uri,
int  ping 
)

static int gw_unique ( const struct gw_info gws,
const unsigned int  count,
const unsigned int  ip_addr,
const unsigned int  grp_id 
) [static]

Definition at line 841 of file lcr_mod.c.

Referenced by insert_gw().

static int insert_gw ( struct gw_info gws,
unsigned int  i,
unsigned int  ip_addr,
char *  hostname,
unsigned int  hostname_len,
unsigned int  grp_id,
char *  ip_string,
unsigned int  port,
unsigned int  scheme,
unsigned int  transport,
unsigned int  flags,
unsigned int  strip,
char *  tag,
unsigned int  tag_len,
unsigned short  weight,
unsigned short  ping 
) [static]

static int lcr_db_bind ( const str db_url  )  [static]

Definition at line 386 of file lcr_mod.c.

References db_bind_mod(), DB_CAP_QUERY, DB_CAPABILITY, and LM_ERR.

Referenced by mod_init().

static void lcr_db_close ( void   )  [static]

Definition at line 402 of file lcr_mod.c.

References db_func::close.

static int lcr_db_init ( const str db_url  )  [static]

Definition at line 368 of file lcr_mod.c.

References db_func::init, LM_CRIT, and LM_ERR.

Referenced by mi_child_init().

static void link_gw_grps ( struct gw_info gws,
struct gw_grp gw_grps,
unsigned int *  grp_cnt 
) [static]

Definition at line 892 of file lcr_mod.c.

References gw_grp::first, gw_grp::grp_id, gw_info::grp_id, gw_info::ip_addr, and gw_info::next.

Referenced by reload_gws_and_lcrs().

static int load_gws_0 ( struct sip_msg _m,
char *  _s1,
char *  _s2 
) [static]

Definition at line 1866 of file lcr_mod.c.

References do_load_gws().

static int load_gws_1 ( struct sip_msg _m,
char *  _s1,
char *  _s2 
) [static]

static int load_gws_from_grp ( struct sip_msg _m,
char *  _s1,
char *  _s2 
) [static]

static int mi_child_init ( void   )  [static]

Definition at line 411 of file lcr_mod.c.

References lcr_db_init().

int mi_print_gws ( struct mi_node rpl  ) 

int mi_print_lcrs ( struct mi_node rpl  ) 

static int mod_init ( void   )  [static]

static int next_gw ( struct sip_msg _m,
char *  _s1,
char *  _s2 
) [static]

static int prefix_len_insert ( struct lcr_info **  table,
unsigned short  prefix_len 
) [static]

Definition at line 937 of file lcr_mod.c.

References lcr_hash_size_param, LM_ERR, lcr_info::next, NULL, lcr_info::prefix_len, and shm_malloc().

Referenced by reload_gws_and_lcrs().

static pcre* reg_ex_comp ( const char *  pattern  )  [static]

Definition at line 775 of file lcr_mod.c.

References LM_ERR, NULL, and shm_malloc().

int reload_gws_and_lcrs ( void   ) 

int send_sip_options_request ( str to,
int  index 
)

static void timer ( unsigned int  ticks,
void *  param 
) [static]

static int to_gw_0 ( struct sip_msg _m,
char *  _s1,
char *  _s2 
) [static]

Definition at line 2320 of file lcr_mod.c.

References do_to_gw().

static int to_gw_1 ( struct sip_msg _m,
char *  _s1,
char *  _s2 
) [static]

Definition at line 2330 of file lcr_mod.c.

References do_to_gw().

static int to_gw_grp ( struct sip_msg _m,
char *  _s1,
char *  _s2 
) [static]

Definition at line 2310 of file lcr_mod.c.

References do_to_gw().


Variable Documentation

cmd_export_t cmds[] [static]

Definition at line 276 of file lcr_mod.c.

db_con_t* db_handle = 0 [static]

Definition at line 177 of file lcr_mod.c.

str db_url = str_init(DEFAULT_RODB_URL) [static]

Definition at line 190 of file lcr_mod.c.

Definition at line 352 of file lcr_mod.c.

int fetch_rows_param = DEF_FETCH_ROWS [static]

Definition at line 210 of file lcr_mod.c.

Referenced by mod_init(), and reload_gws_and_lcrs().

int_str flags_avp [static]

Definition at line 247 of file lcr_mod.c.

char* flags_avp_param = NULL [static]

Definition at line 231 of file lcr_mod.c.

Referenced by mod_init().

int flags_avp_type [static]

Definition at line 246 of file lcr_mod.c.

Referenced by do_from_gw(), mod_init(), and next_gw().

str flags_col = str_init(FLAGS_COL) [static]

str from_uri_col = str_init(FROM_URI_COL) [static]

Definition at line 206 of file lcr_mod.c.

str grp_id_col = str_init(GRP_ID_COL) [static]

Definition at line 193 of file lcr_mod.c.

str gw_name_col = str_init(GW_NAME_COL) [static]

Definition at line 192 of file lcr_mod.c.

str gw_table = str_init(GW_TABLE) [static]

Definition at line 191 of file lcr_mod.c.

int_str gw_uri_avp [static]

Definition at line 241 of file lcr_mod.c.

char* gw_uri_avp_param = NULL [static]

Definition at line 228 of file lcr_mod.c.

Referenced by mod_init().

int gw_uri_avp_type [static]

Definition at line 240 of file lcr_mod.c.

Referenced by add_gws_into_avps(), generate_uris(), and mod_init().

struct gw_info** gws

Definition at line 249 of file lcr_mod.c.

struct gw_info* gws_1

Definition at line 250 of file lcr_mod.c.

struct gw_info* gws_2

Definition at line 251 of file lcr_mod.c.

str hostname_col = str_init(HOSTNAME_COL) [static]

Definition at line 195 of file lcr_mod.c.

str ip_addr_col = str_init(IP_ADDR_COL) [static]

Definition at line 194 of file lcr_mod.c.

Referenced by reload_address_table().

db_func_t lcr_dbf [static]

Definition at line 178 of file lcr_mod.c.

unsigned int lcr_hash_size_param = DEF_LCR_HASH_SIZE

str lcr_table = str_init(LCR_TABLE) [static]

Definition at line 204 of file lcr_mod.c.

struct lcr_info*** lcrs

Definition at line 253 of file lcr_mod.c.

struct lcr_info** lcrs_1

Definition at line 254 of file lcr_mod.c.

struct lcr_info** lcrs_2

Definition at line 255 of file lcr_mod.c.

mi_export_t mi_cmds[] [static]

Definition at line 341 of file lcr_mod.c.

int negative_codes[MAX_CODES]

Definition at line 222 of file lcr_mod.c.

Referenced by check_options_callback(), and mod_init().

str negative_codes_str = {"408", 3} [static]

Definition at line 225 of file lcr_mod.c.

param_export_t params[] [static]

Definition at line 304 of file lcr_mod.c.

str ping_col = str_init(PING_COL) [static]

Definition at line 203 of file lcr_mod.c.

str ping_from = {"sip:127.0.0.1", 20} [static]

Definition at line 217 of file lcr_mod.c.

int ping_interval = 0

Definition at line 214 of file lcr_mod.c.

str ping_method = {"OPTIONS", 7} [static]

Definition at line 218 of file lcr_mod.c.

str port_col = str_init(PORT_COL) [static]

Definition at line 196 of file lcr_mod.c.

Referenced by query_xcap_update(), and reload_address_table().

int positive_codes[MAX_CODES]

Definition at line 221 of file lcr_mod.c.

Referenced by check_options_callback(), and mod_init().

str positive_codes_str = {"200;501;403;404", 15} [static]

Definition at line 224 of file lcr_mod.c.

str prefix_col = str_init(PREFIX_COL) [static]

Definition at line 205 of file lcr_mod.c.

str priority_col = str_init(PRIORITY_COL) [static]

Definition at line 207 of file lcr_mod.c.

gen_lock_t* reload_lock

int_str rpid_avp [static]

Definition at line 245 of file lcr_mod.c.

char* rpid_avp_param = NULL [static]

Definition at line 230 of file lcr_mod.c.

int rpid_avp_type [static]

Definition at line 244 of file lcr_mod.c.

Definition at line 243 of file lcr_mod.c.

char* ruri_user_avp_param = NULL [static]

Definition at line 229 of file lcr_mod.c.

Referenced by mod_init().

int ruri_user_avp_type [static]

Definition at line 242 of file lcr_mod.c.

Referenced by mod_init(), and next_gw().

str strip_col = str_init(STRIP_COL) [static]

Definition at line 199 of file lcr_mod.c.

str tag_col = str_init(TAG_COL) [static]

Definition at line 200 of file lcr_mod.c.

Referenced by allow_trusted(), and reload_trusted_table().

struct tm_binds tmb

TM bind

Definition at line 141 of file lcr_mod.c.

str transport_col = str_init(TRANSPORT_COL) [static]

Definition at line 198 of file lcr_mod.c.

str uri_scheme_col = str_init(URI_SCHEME_COL) [static]

Definition at line 197 of file lcr_mod.c.

str weight_col = str_init(WEIGHT_COL) [static]

Definition at line 201 of file lcr_mod.c.


Generated on Wed May 23 08:01:16 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6