Module: SIP Session Timers module. More...
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "../../pvar.h"
#include "../../parser/parse_sst.h"
#include "../../parser/parse_supported.h"
#include "../../mem/mem.h"
#include "../../mem/shm_mem.h"
#include "../../data_lump.h"
#include "../../data_lump_rpl.h"
#include "../../ut.h"
#include "../../dprint.h"
#include "../../sr_module.h"
#include "../sl/sl_api.h"
#include "sst_handlers.h"
#include "sst_mi.h"

Go to the source code of this file.
Data Structures | |
| struct | sst_msg_info_st |
Defines | |
| #define | SST_SE_BUF_SIZE 80 |
Typedefs | |
| typedef struct sst_msg_info_st | sst_msg_info_t |
Functions | |
| static int | append_header (struct sip_msg *msg, const char *header) |
| static int | parse_msg_for_sst_info (struct sip_msg *msg, sst_msg_info_t *minfo) |
| static int | remove_header (struct sip_msg *msg, const char *header) |
| static int | send_reject (struct sip_msg *msg, unsigned int min_se) |
| static int | send_response (struct sip_msg *request, int code, str *reason, char *header, int header_len) |
| static int | set_timeout_avp (struct sip_msg *msg, unsigned int value) |
| static void | setup_dialog_callbacks (struct dlg_cell *did, sst_info_t *info) |
| static int | sst_build_minse_hdr (int seval, str *sehdr) |
| static int | sst_build_se_hdr (int seval, str *sehdr) |
| int | sst_check_min (struct sip_msg *msg, char *flag, char *str2) |
| The script function. | |
| void | sst_dialog_created_CB (struct dlg_cell *did, int type, struct dlg_cb_params *params) |
| The static (opening) callback function for all dialog creations. | |
| static void | sst_dialog_request_within_CB (struct dlg_cell *did, int type, struct dlg_cb_params *params) |
| static void | sst_dialog_response_fwded_CB (struct dlg_cell *did, int type, struct dlg_cb_params *params) |
| static void | sst_dialog_terminate_CB (struct dlg_cell *did, int type, struct dlg_cb_params *params) |
| void | sst_handler_init (pv_spec_t *timeout_avp_p, unsigned int min_se, int flag, unsigned int reject) |
| The handlers initializer function. | |
Variables | |
| struct dlg_binds * | dlg_binds |
| struct sl_binds | slb |
| static str | sst_422_rpl = str_init("Session Timer Too Small") |
| static int | sst_flag = 0 |
| static unsigned int | sst_min_se = 0 |
| static unsigned int | sst_reject = 1 |
| static char | sst_se_buf [SST_SE_BUF_SIZE] |
| static pv_spec_t * | timeout_avp = 0 |
Module: SIP Session Timers module.
Definition in file sst_handlers.c.
| #define SST_SE_BUF_SIZE 80 |
Definition at line 165 of file sst_handlers.c.
Referenced by sst_build_minse_hdr(), and sst_build_se_hdr().
| typedef struct sst_msg_info_st sst_msg_info_t |
A collection of information about SST in the current SIP message being processed.
| static int append_header | ( | struct sip_msg * | msg, | |
| const char * | header | |||
| ) | [static] |
Given some header text, append it to the passed in message.
| msg | The message to append the header text to. | |
| header | The header text to append. |
Definition at line 738 of file sst_handlers.c.
References anchor_lump(), sip_msg::buf, HDR_EOH_F, insert_new_lump_before(), len, LM_DBG, LM_ERR, NULL, parse_headers(), pkg_free, pkg_malloc, s, and sip_msg::unparsed.
Referenced by sst_dialog_created_CB(), and sst_dialog_response_fwded_CB().
| static int parse_msg_for_sst_info | ( | struct sip_msg * | msg, | |
| sst_msg_info_t * | minfo | |||
| ) | [static] |
Gether the message information about SST from the current message being processed.
| msg | The current message to parse. | |
| minfo | The SST information found in the message. |
Definition at line 863 of file sst_handlers.c.
References F_SUPPORTED_TIMER, session_expires::interval, sst_msg_info_st::min_se, parse_min_se(), parse_session_expires(), parse_sst_success, parse_supported(), hdr_field::parsed, session_expires::refresher, sst_msg_info_st::refresher, sst_msg_info_st::se, sst_refresher_unspecified, sip_msg::supported, and sst_msg_info_st::supported.
Referenced by sst_dialog_created_CB(), sst_dialog_request_within_CB(), and sst_dialog_response_fwded_CB().
| static int remove_header | ( | struct sip_msg * | msg, | |
| const char * | header | |||
| ) | [static] |
Remove a header from a message if found.
| msg | The message to look for the header to remove. | |
| header | The header name: text. |
Definition at line 779 of file sst_handlers.c.
References sip_msg::buf, del_lump(), HDR_EOH_F, sip_msg::headers, hdr_field::len, _str::len, len, LM_ERR, hdr_field::name, hdr_field::next, NULL, parse_headers(), and _str::s.
Referenced by sst_dialog_created_CB().
| static int send_reject | ( | struct sip_msg * | msg, | |
| unsigned int | min_se | |||
| ) | [static] |
Add the Min-SE: header and send a reply 422.
| msg | The message to opperate on. | |
| min_se | The Min-SE: value to use in the heaader. |
Definition at line 914 of file sst_handlers.c.
References _str::len, LM_DBG, LM_ERR, _str::s, send_response(), and sst_build_minse_hdr().
Referenced by sst_dialog_created_CB().
| static int send_response | ( | struct sip_msg * | request, | |
| int | code, | |||
| str * | reason, | |||
| char * | header, | |||
| int | header_len | |||
| ) | [static] |
Send a reply (response) to the passed in SIP request messsage with the code and reason. If the header is not NULL (and header_len != 0) the add the header to the reply message.
| request | The SIP request message to build the reply from. | |
| code | The response code. i.e 200 | |
| reason | The response reason. i.e. "OK" | |
| header | the header block to add to the reply. | |
| header_len | The length of the header block. (header) |
Definition at line 705 of file sst_handlers.c.
References add_lump_rpl(), LM_ERR, LUMP_RPL_HDR, sl_binds::send_reply, and slb.
Referenced by send_reject(), and sst_check_min().
| static int set_timeout_avp | ( | struct sip_msg * | msg, | |
| unsigned int | value | |||
| ) | [static] |
Set the dialog's AVP value so the dialog module will use this value and not the default when returning from the dialog callback.
| msg | The current message to bind the AVP to. | |
| value | The value you want to set the AVP to. |
Definition at line 818 of file sst_handlers.c.
References EQ_T, _pv_value::flags, LM_DBG, LM_ERR, pv_get_spec_value(), PV_VAL_INT, _pv_spec::pvp, _pv_value::ri, and _pv_spec::setf.
Referenced by sst_dialog_created_CB(), sst_dialog_request_within_CB(), and sst_dialog_response_fwded_CB().
| static void setup_dialog_callbacks | ( | struct dlg_cell * | did, | |
| sst_info_t * | info | |||
| ) | [static] |
A helper function to setup all the callbacks from the dialog module after we find interest in the dialog.
| did | The Dialog ID. | |
| info | The sst information. |
Definition at line 936 of file sst_handlers.c.
References DLGCB_CONFIRMED, DLGCB_EXPIRED, DLGCB_FAILED, DLGCB_MI_CONTEXT, DLGCB_REQ_WITHIN, DLGCB_RESPONSE_FWDED, DLGCB_TERMINATED, LM_DBG, NULL, dlg_binds::register_dlgcb, sst_dialog_mi_context_CB(), sst_dialog_request_within_CB(), sst_dialog_response_fwded_CB(), and sst_dialog_terminate_CB().
| static int sst_build_minse_hdr | ( | int | seval, | |
| str * | sehdr | |||
| ) | [inline, static] |
Definition at line 167 of file sst_handlers.c.
References _str::len, NULL, _str::s, snprintf, sst_se_buf, and SST_SE_BUF_SIZE.
Referenced by send_reject(), sst_check_min(), and sst_dialog_created_CB().
| static int sst_build_se_hdr | ( | int | seval, | |
| str * | sehdr | |||
| ) | [inline, static] |
Definition at line 177 of file sst_handlers.c.
References _str::len, NULL, _str::s, snprintf, sst_se_buf, and SST_SE_BUF_SIZE.
Referenced by sst_dialog_created_CB(), and sst_dialog_response_fwded_CB().
| int sst_check_min | ( | struct sip_msg * | msg, | |
| char * | flag, | |||
| char * | str2 | |||
| ) |
The script function.
The sstCheckMin() script command handler. Return 1 (true) if the MIN-SE: of the message is too small compared to the sst_min_se value. This will allow the script to reply to this INVITE with a "422 Session Timer Too Small" response. if sst_min_se was never set the recommended value of 1800 seconds will be used.
If the flag (str1) is set to 1, the 422 reply will be sent with the sst MIN_SE value in the header. If the flag is not set or is NULL, no reply is sent.
| msg | - The sip message from the script (INVITE only) | |
| flag | - Reply mode Flag. 0/NULL do not send reply, 1 send 422 reply if Session-Expires is to small with the MIN-SE header in the reply | |
| str2 | - Not used. |
Definition at line 610 of file sst_handlers.c.
References sip_msg::first_line, session_expires::interval, _str::len, LM_DBG, LM_ERR, METHOD_INVITE, MIN, parse_min_se(), parse_session_expires(), parse_sst_header_not_found, parse_sst_success, msg_start::request, _str::s, send_response(), SIP_REQUEST, sst_build_minse_hdr(), sst_min_se, msg_start::type, and msg_start::u.
| void sst_dialog_created_CB | ( | struct dlg_cell * | did, | |
| int | type, | |||
| struct dlg_cb_params * | params | |||
| ) |
The static (opening) callback function for all dialog creations.
Every time a new dialog is created (from a new INVITE) the dialog module will call this callback function. We need to track the dialogs lifespan from this point forward until it is terminated with a BYE, CANCEL, etc. In the process, we will see if either or both ends of the conversation supports SIP Session Timers and setup the dialog timeout to expire at the session timer expire time. Each time the new re-INVITE is seen to update the SST, we will reset the life span of the dialog to match it.
This function will setup the other types of dialog callbacks required to track the lifespan of the dialog. It will also start the state tracking to figure out if and who supports SST.
As per RFC4028: Request handling:
| did | - The dialog ID | |
| type | - The trigger event type (CREATED) | |
| params | - The pointer to nothing. As we did not attach anything to this callback in the dialog module. |
Definition at line 248 of file sst_handlers.c.
References append_header(), sip_msg::first_line, sip_msg::flags, sst_info_st::interval, LM_DBG, LM_ERR, LM_WARN, MAX, METHOD_INVITE, sst_msg_info_st::min_se, dlg_cb_params::msg, NULL, parse_msg_for_sst_info(), remove_header(), msg_start::request, sst_info_st::requester, _str::s, sst_msg_info_st::se, send_reject(), set_timeout_avp(), setup_dialog_callbacks(), shm_free, shm_malloc(), SIP_REQUEST, sst_build_minse_hdr(), sst_build_se_hdr(), sst_flag, sst_min_se, SST_PXY, sst_reject, SST_UAC, SST_UNDF, sst_msg_info_st::supported, sst_info_st::supported, msg_start::type, and msg_start::u.
Referenced by mod_init().
| static void sst_dialog_request_within_CB | ( | struct dlg_cell * | did, | |
| int | type, | |||
| struct dlg_cb_params * | params | |||
| ) | [static] |
Callback from the dialog module when the dialog is being updated in its life span. We are only interested in the INVITE or UPDATE if SST is supported and active for this dialog. In this case, we need to update the expire time for the dialog based on the Session-Expires: header in the reINVITE/UPDATE request.
When this callback returns control to the dialog module it WILL reset the timeout of the dialog. We need to make sure we set the AVP here or the dialog timeout will be reset to the DEFAULT value if this is a different transaction. (so the AVP value is gone)
| did | - The dialog structure. The pointer is used as an ID. | |
| type | - The reason for the callback. DLGCB_REQ_WITHIN | |
| params | - The sst information |
Definition at line 427 of file sst_handlers.c.
References sip_msg::first_line, sst_info_st::interval, LM_DBG, LM_ERR, METHOD_INVITE, METHOD_PRACK, METHOD_UPDATE, dlg_cb_params::msg, dlg_cb_params::param, parse_msg_for_sst_info(), msg_start::reply, msg_start::request, sst_msg_info_st::se, set_timeout_avp(), SIP_REPLY, SIP_REQUEST, msg_start::type, and msg_start::u.
Referenced by setup_dialog_callbacks().
| static void sst_dialog_response_fwded_CB | ( | struct dlg_cell * | did, | |
| int | type, | |||
| struct dlg_cb_params * | params | |||
| ) | [static] |
This callback is called on any response message in the lifespan of the dialog. The callback is called just before the message is copied to pkg memory so it is still mutable.
| did | - The dialog structure. The pointer is used as an ID. | |
| type | - The reason for the callback. DLGCB_CONFIRMED | |
| params | - The sst information |
Definition at line 495 of file sst_handlers.c.
References append_header(), sip_msg::cseq, sip_msg::first_line, get_cseq, HDR_CSEQ_F, sst_info_st::interval, LM_DBG, LM_ERR, MAX, METHOD_INVITE, METHOD_UPDATE, sst_msg_info_st::min_se, dlg_cb_params::msg, dlg_cb_params::param, parse_headers(), parse_msg_for_sst_info(), msg_start::reply, sst_info_st::requester, _str::s, sst_msg_info_st::se, set_timeout_avp(), SIP_REPLY, sst_build_se_hdr(), SST_PXY, SST_UAC, sst_info_st::supported, msg_start::type, and msg_start::u.
Referenced by setup_dialog_callbacks().
| static void sst_dialog_terminate_CB | ( | struct dlg_cell * | did, | |
| int | type, | |||
| struct dlg_cb_params * | params | |||
| ) | [static] |
Local function prototypes See function definition for documentation.
This callback is called when ever a dialog is terminated. The cause of the termination can be normal, failed call, or expired. It is the expired dialog we are really interested in.
| did | - The Dialog ID / structure pointer. Used as an ID only. | |
| type | - The termination cause/reason. | |
| params | - The sst information |
Definition at line 382 of file sst_handlers.c.
References DLGCB_EXPIRED, DLGCB_FAILED, LM_DBG, NULL, dlg_cb_params::param, and shm_free.
Referenced by setup_dialog_callbacks().
| void sst_handler_init | ( | pv_spec_t * | timeout_avp_p, | |
| unsigned int | min_se, | |||
| int | flag, | |||
| unsigned int | reject | |||
| ) |
The handlers initializer function.
This is not a public API. This function is called when the module is loaded from the mod_init() function in sst.c to initialize the callback handlers and local variables.
| timeout_avp_p | - The pointer to the dialog modules timeout AVP. | |
| min_se | - The minimum session expire value allowed by this PROXY. | |
| flag | - sst flag | |
| reject | - reject state |
Definition at line 198 of file sst_handlers.c.
References sst_flag, sst_min_se, and sst_reject.
Referenced by mod_init().
The pointer to the stateless reply function This is used to send a 422 reply if asked to with a Min-SE: header value to small.
SL binds
Definition at line 88 of file auth_mod.c.
Referenced by authorize(), extract_sdialog_info(), mod_init(), perl_exec2(), publ_send200ok(), reply_200(), reply_421(), reply_489(), rl_drop(), rls_handle_notify(), rls_handle_subscribe(), send_2XX_reply(), send_error_reply(), send_reply(), send_resp(), send_response(), update_presentity(), and xml_publ_handl().
str sst_422_rpl = str_init("Session Timer Too Small") [static] |
Definition at line 161 of file sst_handlers.c.
int sst_flag = 0 [static] |
The value of the message flag to flag an INVITE we want to process through the SST module.
Definition at line 158 of file sst_handlers.c.
unsigned int sst_min_se = 0 [static] |
Our Min-SE: header field value and test.
Definition at line 147 of file sst_handlers.c.
Referenced by sst_check_min(), sst_dialog_created_CB(), and sst_handler_init().
unsigned int sst_reject = 1 [static] |
Should the SE < sst_min_se be rehected with a 422 reply?
Definition at line 152 of file sst_handlers.c.
char sst_se_buf[SST_SE_BUF_SIZE] [static] |
Definition at line 166 of file sst_handlers.c.
Referenced by sst_build_minse_hdr(), and sst_build_se_hdr().
pv_spec_t* timeout_avp = 0 [static] |
The dialog modules timeout AVP spac.
Definition at line 142 of file sst_handlers.c.
1.5.6