dlg.c File Reference

TM :: Dialog handling. More...

#include <string.h>
#include "../../mem/shm_mem.h"
#include "../../dprint.h"
#include "../../parser/contact/parse_contact.h"
#include "../../parser/parse_to.h"
#include "../../parser/parse_from.h"
#include "../../parser/parse_uri.h"
#include "../../trim.h"
#include "../../ut.h"
#include "../../config.h"
#include "dlg.h"
#include "t_reply.h"
#include "../../parser/parser_f.h"

Include dependency graph for dlg.c:

Go to the source code of this file.

Defines

#define NORMAL_ORDER   0
#define REVERSE_ORDER   1
#define ROUTE_PREFIX   "Route: "
#define ROUTE_PREFIX_LEN   (sizeof(ROUTE_PREFIX) - 1)
#define ROUTE_SEPARATOR   "," CRLF " "
#define ROUTE_SEPARATOR_LEN   (sizeof(ROUTE_SEPARATOR) - 1)

Functions

static int calculate_hooks (dlg_t *_d)
 Calculate dialog hooks.
int calculate_routeset_length (dlg_t *_d)
 Calculate length of the route set.
int dlg_add_extra (dlg_t *_d, str *_ldname, str *_rdname)
 Store display names into a dialog.
static int dlg_confirmed_resp_uac (dlg_t *_d, struct sip_msg *_m)
 Handle dialog in DLG_CONFIRMED state.
static int dlg_early_resp_uac (dlg_t *_d, struct sip_msg *_m)
 Handle dialog in DLG_EARLY state.
static int dlg_new_resp_uac (dlg_t *_d, struct sip_msg *_m)
 Handle dialog in DLG_NEW state.
int dlg_request_uas (dlg_t *_d, struct sip_msg *_m)
 UAS side - update a dialog from a request.
int dlg_response_uac (dlg_t *_d, struct sip_msg *_m)
 A response arrived, update dialog.
void free_dlg (dlg_t *_d)
 Destroy a dialog state.
static int get_callid (struct sip_msg *_m, str *_cid)
 Extract Call-ID value.
static int get_contact_uri (struct sip_msg *_m, str *_uri)
 Parse Contact header field body and extract URI.
static int get_cseq_method (struct sip_msg *_m, str *_method)
 Extract method from CSeq header field.
static int get_cseq_value (struct sip_msg *_m, unsigned int *_cs)
 Get CSeq number.
static int get_dlg_uri (struct hdr_field *_h, str *_s)
 Copy To or From URI without tag parameter.
static int get_from_tag (struct sip_msg *_m, str *_tag)
 Extract tag from From header field of a request.
void get_raw_uri (str *_s)
 This function skips a name part in a URI.
static int get_route_set (struct sip_msg *_m, rr_t **_rs, unsigned char _order)
 Create a copy of route set either in normal or reverse order.
static int get_to_tag (struct sip_msg *_m, str *_tag)
 Extract tag from To header field of a response.
int new_dlg_uac (str *_cid, str *_ltag, unsigned int _lseq, str *_luri, str *_ruri, dlg_t **_d)
 Create a new dialog.
int new_dlg_uas (struct sip_msg *_req, int _code, dlg_t **_d)
 Establishing a new dialog from the UAS side.
void print_dlg (FILE *out, dlg_t *_d)
 Print a dialog structure, just for debugging.
char * print_routeset (char *buf, dlg_t *_d)
 Print the route set.
static int request2dlg (struct sip_msg *_m, dlg_t *_d)
 Extract all information from request and update dialog structure.
static int response2dlg (struct sip_msg *_m, dlg_t *_d)
 Extract necessary information from response and insert it into dialog.
int w_calculate_hooks (dlg_t *_d)
 Small wrapper to calculate_hooks.


Detailed Description

TM :: Dialog handling.

Definition in file dlg.c.


Define Documentation

#define NORMAL_ORDER   0

Create route set in normal order - UAS

Definition at line 54 of file dlg.c.

Referenced by get_route_set(), and request2dlg().

#define REVERSE_ORDER   1

Create route set in reverse order - UAC

Definition at line 55 of file dlg.c.

Referenced by response2dlg().

#define ROUTE_PREFIX   "Route: "

Definition at line 57 of file dlg.c.

#define ROUTE_PREFIX_LEN   (sizeof(ROUTE_PREFIX) - 1)

Definition at line 58 of file dlg.c.

#define ROUTE_SEPARATOR   "," CRLF " "

Definition at line 60 of file dlg.c.

Referenced by print_routeset(), and print_rs().

#define ROUTE_SEPARATOR_LEN   (sizeof(ROUTE_SEPARATOR) - 1)

Definition at line 61 of file dlg.c.

Referenced by calc_routeset_len(), calculate_routeset_length(), print_routeset(), and print_rs().


Function Documentation

static int calculate_hooks ( dlg_t _d  )  [inline, static]

int calculate_routeset_length ( dlg_t _d  ) 

Calculate length of the route set.

Parameters:
_d dialog set
Returns:
the length of the route set, can be 0

Definition at line 896 of file dlg.c.

References CRLF_LEN, dlg_hooks::first_route, dlg::hooks, dlg_hooks::last_route, _str::len, rr::len, len, rr::next, ROUTE_PREFIX_LEN, and ROUTE_SEPARATOR_LEN.

Referenced by build_uac_req().

int dlg_add_extra ( dlg_t _d,
str _ldname,
str _rdname 
)

Store display names into a dialog.

Parameters:
_d dialog state
_ldname local display name
_rdname remote display name
Returns:
0 on success, negative on error

Definition at line 211 of file dlg.c.

References LM_ERR, dlg::loc_dname, dlg::rem_dname, and shm_str_dup().

Referenced by load_tm().

static int dlg_confirmed_resp_uac ( dlg_t _d,
struct sip_msg _m 
) [inline, static]

Handle dialog in DLG_CONFIRMED state.

Handle dialog in DLG_CONFIRMED state, we will be processing a response to a request sent within a dialog.

Parameters:
_d dialog state
_m SIP message
Returns:
1 if the dialog was destroyed, negative on errors, 0 otherwise

Definition at line 546 of file dlg.c.

References DLG_DESTROYED, sip_msg::first_line, get_contact_uri(), get_cseq_method(), HDR_CONTACT_F, _str::len, LM_ERR, parse_headers(), dlg::rem_target, msg_start::reply, _str::s, shm_free, shm_str_dup(), dlg::state, and msg_start::u.

Referenced by dlg_response_uac().

static int dlg_early_resp_uac ( dlg_t _d,
struct sip_msg _m 
) [inline, static]

Handle dialog in DLG_EARLY state.

Handle dialog in DLG_EARLY state we will be processing either next provisional response or a final response.

Parameters:
_d dialog state
_m SIP message
Returns:
1 if the dialog was destroyed, negative on errors, 0 otherwise

Definition at line 487 of file dlg.c.

References calculate_hooks(), DLG_CONFIRMED, DLG_DESTROYED, sip_msg::first_line, LM_ERR, msg_start::reply, response2dlg(), dlg::state, and msg_start::u.

Referenced by dlg_response_uac().

static int dlg_new_resp_uac ( dlg_t _d,
struct sip_msg _m 
) [inline, static]

Handle dialog in DLG_NEW state.

Handle dialog in DLG_NEW state, we will be processing the first response

Parameters:
_d dialog state
_m SIP message
Returns:
1 if the dialog was destroyed, negative on errors, 0 otherwise

Definition at line 432 of file dlg.c.

References calculate_hooks(), DLG_CONFIRMED, DLG_DESTROYED, sip_msg::first_line, LM_ERR, msg_start::reply, response2dlg(), dlg::state, and msg_start::u.

Referenced by dlg_response_uac().

int dlg_request_uas ( dlg_t _d,
struct sip_msg _m 
)

UAS side - update a dialog from a request.

Parameters:
_d dialog state
_m SIP request
Returns:
0 on success, negative on error

Definition at line 846 of file dlg.c.

References sip_msg::first_line, get_contact_uri(), get_cseq_value(), HDR_CONTACT_F, HDR_CSEQ_F, dlg_seq::is_set, _str::len, LM_ERR, METHOD_INVITE, parse_headers(), dlg::rem_seq, dlg::rem_target, msg_start::request, _str::s, shm_free, shm_str_dup(), msg_start::u, and dlg_seq::value.

Referenced by load_tm().

int dlg_response_uac ( dlg_t _d,
struct sip_msg _m 
)

A response arrived, update dialog.

Parameters:
_d dialog state
_m SIP message
Returns:
1 if the dialog was destroyed, negative on errors, 0 otherwise

Definition at line 605 of file dlg.c.

References DLG_CONFIRMED, dlg_confirmed_resp_uac(), DLG_DESTROYED, DLG_EARLY, dlg_early_resp_uac(), DLG_NEW, dlg_new_resp_uac(), LM_ERR, and dlg::state.

Referenced by load_tm(), and mi_print_uris().

void free_dlg ( dlg_t _d  ) 

static int get_callid ( struct sip_msg _m,
str _cid 
) [inline, static]

Extract Call-ID value.

Note:
Doesn't parse headers!
Parameters:
_m SIP message
_cid Callid
Returns:
0 on success, -1 on error

Definition at line 317 of file dlg.c.

References hdr_field::body, sip_msg::callid, _str::len, LM_ERR, _str::s, and trim().

static int get_contact_uri ( struct sip_msg _m,
str _uri 
) [inline, static]

Parse Contact header field body and extract URI.

Note:
Does not parse headers!
Parameters:
_m SIP message
_uri SIP URI
Returns:
0 on success, negative on error

Definition at line 235 of file dlg.c.

References sip_msg::contact, _str::len, LM_ERR, parse_contact(), hdr_field::parsed, _str::s, and contact::uri.

static int get_cseq_method ( struct sip_msg _m,
str _method 
) [inline, static]

Extract method from CSeq header field.

Parameters:
_m SIP message
_method SIP method
Returns:
0 on success, -1 on error

Definition at line 524 of file dlg.c.

References sip_msg::cseq, get_cseq, HDR_CSEQ_F, _str::len, LM_ERR, parse_headers(), and _str::s.

Referenced by dlg_confirmed_resp_uac().

static int get_cseq_value ( struct sip_msg _m,
unsigned int *  _cs 
) [inline, static]

Get CSeq number.

Note:
Does not parse headers!
Parameters:
_m SIP message
_cs CSeq number
Returns:
0 on success, negative on error

Definition at line 640 of file dlg.c.

References sip_msg::cseq, get_cseq, _str::len, LM_ERR, _str::s, str2int(), and trim_leading().

Referenced by dlg_request_uas(), and request2dlg().

static int get_dlg_uri ( struct hdr_field _h,
str _s 
) [inline, static]

Copy To or From URI without tag parameter.

Parameters:
_h SIP header
_s target string
Returns:
0 on success, -1 on error

Definition at line 667 of file dlg.c.

References hdr_field::body, to_body::body, _str::len, len, LM_ERR, to_param::next, to_body::param_lst, hdr_field::parsed, _str::s, shm_malloc(), TAG_PARAM, to_param::type, and to_param::value.

Referenced by request2dlg().

static int get_from_tag ( struct sip_msg _m,
str _tag 
) [inline, static]

Extract tag from From header field of a request.

Parameters:
_m SIP message
_tag tag
Returns:
0 on success, -1 on error

Definition at line 292 of file dlg.c.

References get_from, _str::len, LM_ERR, parse_from_header(), and _str::s.

void get_raw_uri ( str _s  ) 

This function skips a name part in a URI.

This function skips a name part in a URI. The URI parsed by parse_contact must be used (the URI must not contain any leading or trailing part and if angle bracket were used, right angle bracket must be the last character in the string)

Note:
Temporary hack!
Parameters:
_s URI, will be modified so it should be a temporary copy

Definition at line 76 of file dlg.c.

References find_not_quoted(), _str::len, and _str::s.

static int get_route_set ( struct sip_msg _m,
rr_t **  _rs,
unsigned char  _order 
) [inline, static]

Create a copy of route set either in normal or reverse order.

Parameters:
_m SIP message
_rs Route set
_order how to order the copy, set to NORMAL_ORDER for normal copy
Returns:
0 on success, -1 on error

Definition at line 338 of file dlg.c.

References HDR_RECORDROUTE_T, LM_ERR, hdr_field::next, rr::next, NORMAL_ORDER, parse_rr(), hdr_field::parsed, sip_msg::record_route, shm_duplicate_rr(), shm_free_rr(), and hdr_field::type.

Referenced by request2dlg(), and response2dlg().

static int get_to_tag ( struct sip_msg _m,
str _tag 
) [inline, static]

Extract tag from To header field of a response.

Note:
Doesn't parse message headers!
Parameters:
_m SIP message
_tag tag
Returns:
0 on success, -1 on error

Definition at line 268 of file dlg.c.

References get_to, _str::len, LM_ERR, _str::s, and sip_msg::to.

int new_dlg_uac ( str _cid,
str _ltag,
unsigned int  _lseq,
str _luri,
str _ruri,
dlg_t **  _d 
)

Create a new dialog.

Parameters:
_cid Callid
_ltag local tag (usually From tag)
_lseq local sequence (usually CSeq)
_luri local URI (usually From)
_ruri remote URI (usually To)
_d dialog state
Returns:
0 on success, negative on errors

Definition at line 160 of file dlg.c.

References calculate_hooks(), dlg_id::call_id, dlg::id, dlg_seq::is_set, LM_ERR, dlg::loc_seq, dlg_id::loc_tag, dlg::loc_uri, dlg::rem_uri, shm_free, shm_malloc(), shm_str_dup(), and dlg_seq::value.

Referenced by load_tm(), req_outside(), and request().

int new_dlg_uas ( struct sip_msg _req,
int  _code,
dlg_t **  _d 
)

Establishing a new dialog from the UAS side.

Parameters:
_req SIP request
_code request code
_d dialog state
Returns:
0 on success, negative on error

Definition at line 791 of file dlg.c.

References calc_crc_suffix(), calculate_hooks(), DLG_CONFIRMED, free_dlg(), dlg::id, _str::len, LM_DBG, LM_ERR, dlg_id::loc_tag, request2dlg(), _str::s, shm_free, shm_malloc(), shm_str_dup(), dlg::state, tm_tag_suffix, tm_tags, and TOTAG_VALUE_LEN.

Referenced by load_tm().

void print_dlg ( FILE *  out,
dlg_t _d 
)

char* print_routeset ( char *  buf,
dlg_t _d 
)

Print the route set.

Parameters:
buf buffer
_d dialog state
Returns:
pointer to the buffer

Definition at line 930 of file dlg.c.

References CRLF, CRLF_LEN, dlg_hooks::first_route, dlg::hooks, dlg_hooks::last_route, _str::len, rr::len, name_addr::name, rr::nameaddr, rr::next, ROUTE_PREFIX, ROUTE_PREFIX_LEN, ROUTE_SEPARATOR, ROUTE_SEPARATOR_LEN, and _str::s.

Referenced by build_uac_req().

static int request2dlg ( struct sip_msg _m,
dlg_t _d 
) [inline, static]

static int response2dlg ( struct sip_msg _m,
dlg_t _d 
) [inline, static]

Extract necessary information from response and insert it into dialog.

Extract all necessary information from a response and put it in a dialog structure

Parameters:
_m SIP message
_d dialog state
Returns:
0 on success, negative on error

Definition at line 392 of file dlg.c.

References get_contact_uri(), get_route_set(), get_to_tag(), HDR_EOH_F, dlg::id, _str::len, LM_ERR, parse_headers(), dlg_id::rem_tag, dlg::rem_target, REVERSE_ORDER, dlg::route_set, _str::s, shm_free, and shm_str_dup().

Referenced by dlg_early_resp_uac(), and dlg_new_resp_uac().

int w_calculate_hooks ( dlg_t _d  ) 

Small wrapper to calculate_hooks.

Parameters:
_d dialog state
Returns:
0 on success, -1 on error

Definition at line 144 of file dlg.c.

References calculate_hooks().

Referenced by request(), and t_uac().


Generated on Tue May 22 16:00:38 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6