conf.c File Reference

#include "conf.h"
#include "../../mem/mem.h"
#include "../../mem/shm_mem.h"
#include "../../sr_module.h"
#include "../../proxy.h"
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

Include dependency graph for conf.c:

Go to the source code of this file.

Data Structures

struct  fwd_setting

Defines

#define BUFSIZE   1000

Enumerations

enum  { sfidx_request = 0, sfidx_reply, sfilter_cnt }

Functions

void conf_destroy (void)
 Destroy configuration.
int conf_init (int max_id)
 Initialize configuration.
struct proxy_lconf_needs_forward (struct sip_msg *msg, int id)
 Checks forwarding is needed.
int conf_parse_filter (char *settings)
 Parses a configuration string for the filter Parses a configuration string for switch settings and updates the configuration structure.
int conf_parse_proxy (char *settings)
 Parses a configuration string for proxy settings Parses a configuration string for proxy settings and updates the configuration structure.
int conf_parse_switch (char *settings)
 Parses configuration string for the switch Parses a configuration string for switch settings and updates the configuration structure.
int conf_show (struct mi_root *rpl_tree)
 Output configuration in FIFO format.
int conf_str2id (char *id_str)
 Converts string to integer and checks for validity.
static int conf_str2int (char *s)
 Converts a string to integer.
static int filter_methods_contains_request (int id, char *method, int method_len)
 Checks if method string is in filter_methods.
static void remove_spaces (char *s)
 Removes white spaces and new lines from s.
static int update_filter (int id, char *flist)
 Updates filter configuration. Updates filter configuration. If filter_methods is not NULL, memory is freed. If filter methods are found, memory for the string is allocated, otherwise filter_methods is set to NULL.
static int update_proxy (int id, char *host_str, char *port_str)
static int update_switch (int id, char *param_str)
 Updates switch configuration.

Variables

static int fwd_max_id = 0
static struct fwd_settingfwd_settings = NULL
static int sfilter_mask [sfilter_cnt] = { 1, 2 }
static char * sfilter_str [sfilter_cnt]


Define Documentation

#define BUFSIZE   1000

Definition at line 37 of file conf.c.

Referenced by conf_show(), and update_filter().


Enumeration Type Documentation

anonymous enum

Enumerator:
sfidx_request 
sfidx_reply 
sfilter_cnt 

Definition at line 41 of file conf.c.


Function Documentation

void conf_destroy ( void   ) 

Destroy configuration.

Definition at line 556 of file conf.c.

References fwd_setting::active, free_shm_proxy(), fwd_max_id, id, proxy, and shm_free.

int conf_init ( int  max_id  ) 

Initialize configuration.

Parameters:
max_id number of configuration statements
Returns:
0 on success, -1 on failure

Definition at line 539 of file conf.c.

References fwd_max_id, NULL, shm_malloc(), and SHM_MEM_ERROR.

Referenced by mod_init().

struct proxy_l* conf_needs_forward ( struct sip_msg msg,
int  id 
) [read]

Checks forwarding is needed.

Parameters:
msg the SIP message to be forwarded
id use configuration with this ID when checking
Returns:
pointer to proxy structure of destination if forwarding is needed, NULL otherwise

Definition at line 508 of file conf.c.

References filter_methods_contains_request(), sip_msg::first_line, NULL, fwd_setting::proxy, msg_start::request, sfidx_reply, sfidx_request, sfilter_mask, SIP_REPLY, SIP_REQUEST, msg_start::type, and msg_start::u.

Referenced by utils_forward().

int conf_parse_filter ( char *  settings  ) 

Parses a configuration string for the filter Parses a configuration string for switch settings and updates the configuration structure.

Parameters:
settings The configuration string in the following form: <id>=<filter>[:<filter>]...[,<id>=<filter>[:<filter>]...]...
Returns:
1 on success, -1 otherwise

Definition at line 398 of file conf.c.

References conf_str2id(), len, LM_ERR, NULL, pkg_free, pkg_malloc, PKG_MEM_ERROR, remove_spaces(), and update_filter().

Referenced by forward_fifo_filter(), and mod_init().

int conf_parse_proxy ( char *  settings  ) 

Parses a configuration string for proxy settings Parses a configuration string for proxy settings and updates the configuration structure.

Parameters:
settings,: The configuration string in the following form: <id>=<host>:<port>[,<id>=<host>:<port>]...
Returns:
: 1 on success, -1 otherwise

Definition at line 441 of file conf.c.

References conf_str2id(), len, LM_ERR, NULL, pkg_free, pkg_malloc, PKG_MEM_ERROR, remove_spaces(), and update_proxy().

Referenced by forward_fifo_proxy(), and mod_init().

int conf_parse_switch ( char *  settings  ) 

Parses configuration string for the switch Parses a configuration string for switch settings and updates the configuration structure.

Parameters:
settings the configuration string in the following form: <id>=<switch>[,<id>=<switch>]...
Returns:
1 on success, -1 otherwise

Definition at line 298 of file conf.c.

References conf_str2id(), len, LM_ERR, NULL, pkg_free, pkg_malloc, PKG_MEM_ERROR, remove_spaces(), and update_switch().

Referenced by forward_fifo_switch(), and mod_init().

int conf_show ( struct mi_root rpl_tree  ) 

Output configuration in FIFO format.

Parameters:
rpl_tree FIFO root
Returns:
0 on success, -1 on failure

Definition at line 340 of file conf.c.

References fwd_setting::active, addf_mi_node_child(), buf, BUFSIZE, fwd_max_id, id, proxy_l::name, mi_root::node, NULL, proxy_l::port, fwd_setting::proxy, _str::s, sfilter_cnt, sfilter_mask, sfilter_str, and snprintf.

Referenced by forward_fifo_list().

int conf_str2id ( char *  id_str  ) 

Converts string to integer and checks for validity.

Todo:
check if we can use the functions from ut.h params: id_str: ID as string to be converted to int. returns: >=0 on success -1 otherwise

Definition at line 121 of file conf.c.

References conf_str2int(), fwd_max_id, and LM_ERR.

Referenced by conf_parse_filter(), conf_parse_proxy(), and conf_parse_switch().

static int conf_str2int ( char *  s  )  [static]

Converts a string to integer.

Todo:
check if we can use the functions from ut.h params: s: The string to be converted to int. returns: >=0 on success -1 otherwise

Definition at line 96 of file conf.c.

References LM_ERR, and NULL.

Referenced by conf_str2id(), and update_proxy().

static int filter_methods_contains_request ( int  id,
char *  method,
int  method_len 
) [static]

Checks if method string is in filter_methods.

Parameters:
id use configuration with this ID when checking
method method string to be searched for
method_len length of method string
Returns:
1 if method is found in filter_methods, 0 otherwise

Definition at line 486 of file conf.c.

References fwd_setting::filter_methods, and NULL.

Referenced by conf_needs_forward().

static void remove_spaces ( char *  s  )  [static]

Removes white spaces and new lines from s.

Todo:
check if we can use the functions from ut.h Removes white spaces and new lines from s, the contents of s are modified.
Parameters:
s the string.

Definition at line 75 of file conf.c.

Referenced by conf_parse_filter(), conf_parse_proxy(), and conf_parse_switch().

static int update_filter ( int  id,
char *  flist 
) [static]

Updates filter configuration. Updates filter configuration. If filter_methods is not NULL, memory is freed. If filter methods are found, memory for the string is allocated, otherwise filter_methods is set to NULL.

Parameters:
id update the configuration with this ID.
flist a list of filter names.
Returns:
0 on success, -1 otherwise

Definition at line 170 of file conf.c.

References buf, BUFSIZE, fwd_setting::filter_methods, len, LM_ERR, NULL, fwd_setting::sfilter, sfilter_cnt, sfilter_mask, sfilter_str, shm_free, shm_malloc(), SHM_MEM_ERROR, and snprintf.

Referenced by conf_parse_filter().

static int update_proxy ( int  id,
char *  host_str,
char *  port_str 
) [static]

Updates proxy configuration

Parameters:
id update the configuration with this ID.
host_str the destination host.
port_str the port number as string.
Returns:
0 on success, -1 otherwise

Definition at line 240 of file conf.c.

References conf_str2int(), free_shm_proxy(), _str::len, LM_ERR, mk_shm_proxy(), NULL, port, PROTO_UDP, fwd_setting::proxy, proxy, _str::s, shm_free, shm_malloc(), and SHM_MEM_ERROR.

Referenced by conf_parse_proxy().

static int update_switch ( int  id,
char *  param_str 
) [static]

Updates switch configuration.

Parameters:
id Update the configuration with this ID.
param_str can be either "off" or "on".
Returns:
0 on success, -1 otherwise

Definition at line 140 of file conf.c.

References fwd_setting::active, LM_ERR, and NULL.

Referenced by conf_parse_switch().


Variable Documentation

int fwd_max_id = 0 [static]

Definition at line 66 of file conf.c.

Referenced by conf_destroy(), conf_init(), conf_show(), and conf_str2id().

struct fwd_setting* fwd_settings = NULL [static]

Definition at line 65 of file conf.c.

int sfilter_mask[sfilter_cnt] = { 1, 2 } [static]

special filter masks

Definition at line 48 of file conf.c.

Referenced by conf_needs_forward(), conf_show(), and update_filter().

char* sfilter_str[sfilter_cnt] [static]

Initial value:

 {
   "REQUEST",
   "REPLY"
}
special filter names

Definition at line 51 of file conf.c.

Referenced by conf_show(), and update_filter().


Generated on Mon May 21 18:00:37 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6