loose.c File Reference

Route & Record-Route module, loose routing support. More...

#include <string.h>
#include "../../ut.h"
#include "../../str.h"
#include "../../dprint.h"
#include "../../forward.h"
#include "../../data_lump.h"
#include "../../socket_info.h"
#include "../../parser/parse_rr.h"
#include "../../parser/parse_uri.h"
#include "../../parser/parse_from.h"
#include "../../mem/mem.h"
#include "../../dset.h"
#include "loose.h"
#include "rr_cb.h"
#include "rr_mod.h"

Include dependency graph for loose.c:

Go to the source code of this file.

Defines

#define NOT_RR_DRIVEN   -1
#define ROUTE_PREFIX   "Route: <"
#define ROUTE_PREFIX_LEN   (sizeof(ROUTE_PREFIX)-1)
#define ROUTE_SUFFIX   ">\r\n"
#define ROUTE_SUFFIX_LEN   (sizeof(ROUTE_SUFFIX)-1)
#define RR_DRIVEN   1
#define RR_ERROR   -1

Functions

static int after_loose (struct sip_msg *_m, int preloaded)
 Previous hop was a loose router, handle this case.
static int after_strict (struct sip_msg *_m)
 Previous hop was a strict router, handle this case.
int check_route_param (struct sip_msg *msg, regex_t *re)
 Check if the route hdr has the required parameter.
static int find_first_route (struct sip_msg *_m)
 Parse the message and find first occurrence of Route header field.
static int find_next_route (struct sip_msg *_m, struct hdr_field **_hdr)
 Find and parse next Route header field.
static int find_rem_target (struct sip_msg *_m, struct hdr_field **_h, rr_t **_l, rr_t **_p)
 Find last route in the last Route header field.
static int get_maddr_uri (str *uri, struct sip_uri *puri)
 Parse URI and check if it has a maddr parameter.
int get_route_param (struct sip_msg *msg, str *name, str *val)
 Gets the value of a route parameter.
static int handle_sr (struct sip_msg *_m, struct hdr_field *_hdr, rr_t *_r)
 Necessary logic to forward request to strict routers.
static int is_2rr (str *_params)
 Find out if a URI contains r2 parameter which indicates that we put 2 record routes.
int is_direction (struct sip_msg *msg, int dir)
 Check the direction of the message.
static int is_myself (str *_host, unsigned short _port)
 Check if URI is myself.
static int is_preloaded (struct sip_msg *msg)
 Test whether we are processing pre-loaded route set by looking at the To tag.
static int is_strict (str *_params)
 Check if the given uri contains lr parameter which marks loose routers.
int loose_route (struct sip_msg *_m, char *_s1, char *_s2)
 Do loose routing as per RFC3261.
static int save_ruri (struct sip_msg *_m)
 Set Request-URI as last Route header of a SIP.

Variables

static unsigned int routed_msg_id
static str routed_params = {0,0}


Detailed Description

Route & Record-Route module, loose routing support.

Definition in file loose.c.


Define Documentation

#define NOT_RR_DRIVEN   -1

The next hop is not determined from the route set

Definition at line 50 of file loose.c.

Referenced by after_loose(), and after_strict().

#define ROUTE_PREFIX   "Route: <"

SIP header prefix

Definition at line 52 of file loose.c.

Referenced by print_routeset(), print_rs(), and save_ruri().

#define ROUTE_PREFIX_LEN   (sizeof(ROUTE_PREFIX)-1)

#define ROUTE_SUFFIX   ">\r\n"

SIP header suffix

Definition at line 55 of file loose.c.

Referenced by save_ruri().

#define ROUTE_SUFFIX_LEN   (sizeof(ROUTE_SUFFIX)-1)

Definition at line 56 of file loose.c.

Referenced by save_ruri().

#define RR_DRIVEN   1

The next hop is determined from the route set

Definition at line 49 of file loose.c.

Referenced by after_loose(), and after_strict().

#define RR_ERROR   -1

An error occured while processing route set

Definition at line 48 of file loose.c.

Referenced by after_loose(), after_strict(), get_maddr_uri(), and handle_sr().


Function Documentation

static int after_loose ( struct sip_msg _m,
int  preloaded 
) [inline, static]

static int after_strict ( struct sip_msg _m  )  [inline, static]

int check_route_param ( struct sip_msg msg,
regex_t *  re 
)

Check if the route hdr has the required parameter.

The function checks for the request "msg" if the URI parameters of the local Route header (corresponding to the local server) matches the given regular expression "re". It must be call after the loose_route was done.

Parameters:
msg SIP message request that will has the Route header parameters checked
re compiled regular expression to be checked against the Route header parameters
Returns:
-1 on failure, 1 on success

Definition at line 950 of file loose.c.

References sip_msg::id, _str::len, LM_DBG, params, routed_msg_id, and _str::s.

Referenced by load_rr(), and w_check_route_param().

static int find_first_route ( struct sip_msg _m  )  [inline, static]

Parse the message and find first occurrence of Route header field.

Parameters:
_m SIP message
Returns:
-1 or -2 on a parser error, 0 if there is a Route HF and 1 if there is no Route HF

Definition at line 98 of file loose.c.

References HDR_ROUTE_F, LM_DBG, LM_ERR, parse_headers(), parse_rr(), and sip_msg::route.

Referenced by loose_route().

static int find_next_route ( struct sip_msg _m,
struct hdr_field **  _hdr 
) [inline, static]

Find and parse next Route header field.

Parameters:
_m SIP message
_hdr SIP header
Returns:
negative on failure, 0 if the Route header was already parsed, 1 if no next Route header could be found

Definition at line 238 of file loose.c.

References HDR_ROUTE_F, HDR_ROUTE_T, sip_msg::last_header, LM_DBG, LM_ERR, hdr_field::next, parse_headers(), parse_rr(), and hdr_field::type.

Referenced by after_loose(), and after_strict().

static int find_rem_target ( struct sip_msg _m,
struct hdr_field **  _h,
rr_t **  _l,
rr_t **  _p 
) [inline, static]

Find last route in the last Route header field.

Find last route in the last Route header field, if there was a previous route in the last Route header field, it will be saved in _p parameter

Parameters:
_m SIP message
_h SIP header field
_l Route & Record-Route header field body
_p Route & Record-Route header field body
Returns:
negative on failure, 0 on success

Definition at line 529 of file loose.c.

References HDR_EOH_F, HDR_ROUTE_T, LM_ERR, rr::next, hdr_field::next, parse_headers(), parse_rr(), hdr_field::parsed, sip_msg::route, and hdr_field::type.

Referenced by after_strict().

static int get_maddr_uri ( str uri,
struct sip_uri puri 
) [inline, static]

Parse URI and check if it has a maddr parameter.

Parameters:
uri URI to be checked if it has maddr, and also the output URI
puri parsed URI
Returns:
-1 on failure, 0 on success

Definition at line 424 of file loose.c.

References _str::len, LM_DBG, LM_ERR, sip_uri::maddr, sip_uri::maddr_val, NULL, parse_uri(), sip_uri::port, RR_ERROR, and _str::s.

Referenced by after_loose(), after_strict(), and handle_sr().

int get_route_param ( struct sip_msg msg,
str name,
str val 
)

Gets the value of a route parameter.

The function search in to the "msg"'s Route header parameters the parameter called "name" and returns its value into "val". It must be call only after the loose_route is done.

Parameters:
msg - request that will have the Route header parameter searched
name - contains the Route header parameter to be serached
val returns the value of the searched Route header parameter if found. It might be an empty string if the parameter had no value.
Returns:
0 if parameter was found (even if it has no value), -1 otherwise

Definition at line 994 of file loose.c.

References sip_msg::id, len, _str::len, routed_msg_id, and _str::s.

Referenced by is_direction(), and load_rr().

static int handle_sr ( struct sip_msg _m,
struct hdr_field _hdr,
rr_t _r 
) [inline, static]

Necessary logic to forward request to strict routers.

Parameters:
_m SIP message
_hdr SIP header field
_r Route & Record-Route header field body
Returns:
0 on success, negative on an error

Definition at line 478 of file loose.c.

References hdr_field::body, sip_msg::buf, del_lump(), get_maddr_uri(), hdr_field::len, LM_ERR, name_addr::name, hdr_field::name, rr::nameaddr, rr::next, rewrite_uri(), RR_ERROR, _str::s, save_ruri(), and name_addr::uri.

Referenced by after_loose().

static int is_2rr ( str _params  )  [inline, static]

Find out if a URI contains r2 parameter which indicates that we put 2 record routes.

Parameters:
_params URI
Returns:
1 if URI contains a r2 parameter, 0 otherwise

Definition at line 123 of file loose.c.

References _str::len, _str::s, and s.

Referenced by after_loose(), and after_strict().

int is_direction ( struct sip_msg msg,
int  dir 
)

Check the direction of the message.

The function checks the flow direction of the request "msg". As for checking it's used the "ftag" Route header parameter, the append_fromtag module parameter must be enables. Also this must be call only after the loose_route is done.

Parameters:
msg SIP message request that will have the direction checked
dir direction to be checked against. It may be RR_FLOW_UPSTREAM or RR_FLOW_DOWNSTREAM
Returns:
0 if the request flow direction is the same as the given direction, -1 otherwise

Definition at line 1086 of file loose.c.

References sip_msg::from, get_route_param(), sip_msg::id, _str::len, LM_DBG, parse_from_header(), hdr_field::parsed, RR_FLOW_DOWNSTREAM, RR_FLOW_UPSTREAM, and _str::s.

Referenced by load_rr(), and w_is_direction().

static int is_myself ( str _host,
unsigned short  _port 
) [inline, static]

Check if URI is myself.

Parameters:
_host host
_port port
Returns:
0 if the URI is not myself, 1 otherwise

Definition at line 210 of file loose.c.

References check_self(), _str::len, LM_DBG, _str::s, and SIP_PORT.

Referenced by after_loose(), after_strict(), and loose_route().

static int is_preloaded ( struct sip_msg msg  )  [static]

Test whether we are processing pre-loaded route set by looking at the To tag.

Parameters:
msg SIP message
Returns:
-1 on failure, 0 on success

Definition at line 68 of file loose.c.

References get_to, HDR_TO_F, _str::len, LM_DBG, LM_ERR, parse_headers(), _str::s, and sip_msg::to.

Referenced by loose_route().

static int is_strict ( str _params  )  [inline, static]

Check if the given uri contains lr parameter which marks loose routers.

Parameters:
_params URI string
Returns:
1 if URI contains no lr parameter, 0 if it contains a lr parameter

Definition at line 281 of file loose.c.

References _str::len, _str::s, and s.

Referenced by after_loose(), and after_strict().

int loose_route ( struct sip_msg _m,
char *  _s1,
char *  _s2 
)

Do loose routing as per RFC3261.

Parameters:
_m SIP message
_s1 unused
_s2 unused
Returns:
-1 on failure, 1 on success

Definition at line 904 of file loose.c.

References after_loose(), after_strict(), find_first_route(), sip_uri::host, is_myself(), is_preloaded(), LM_DBG, LM_ERR, parse_sip_msg_uri(), sip_msg::parsed_uri, sip_uri::port_no, and sip_uri::user.

static int save_ruri ( struct sip_msg _m  )  [inline, static]

Set Request-URI as last Route header of a SIP.

Set Request-URI as last Route header of a SIP message, this is necessary when forwarding to a strict router. Allocates memory for message lump in private memory.

Parameters:
_m SIP message
Returns:
negative on failure, 0 on success

Definition at line 371 of file loose.c.

References anchor_lump(), sip_msg::buf, sip_msg::first_line, HDR_EOH_F, insert_new_lump_before(), len, LM_DBG, LM_ERR, parse_headers(), pkg_free, pkg_malloc, msg_start::request, ROUTE_PREFIX, ROUTE_PREFIX_LEN, ROUTE_SUFFIX, ROUTE_SUFFIX_LEN, s, msg_start::u, sip_msg::unparsed, and ZSW.

Referenced by handle_sr().


Variable Documentation

unsigned int routed_msg_id [static]

variables used to hook the param part of the local route

Definition at line 59 of file loose.c.

Referenced by after_loose(), after_strict(), check_route_param(), and get_route_param().

str routed_params = {0,0} [static]

Definition at line 60 of file loose.c.


Generated on Wed May 23 18:00:41 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6