[asterisk-commits] oej: branch group/sip_session_timers r89284 - /team/group/sip_session_timers/...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Nov 15 06:13:19 CST 2007
Author: oej
Date: Thu Nov 15 06:13:19 2007
New Revision: 89284
URL: http://svn.digium.com/view/asterisk?view=rev&rev=89284
Log:
- Adding comments
- Merging two functions
Still needs to avoid all the find_peer and find_user calls.
Modified:
team/group/sip_session_timers/channels/chan_sip.c
Modified: team/group/sip_session_timers/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/group/sip_session_timers/channels/chan_sip.c?view=diff&rev=89284&r1=89283&r2=89284
==============================================================================
--- team/group/sip_session_timers/channels/chan_sip.c (original)
+++ team/group/sip_session_timers/channels/chan_sip.c Thu Nov 15 06:13:19 2007
@@ -1884,8 +1884,7 @@
static const char *strefresher2str (enum st_refresher r);
static int parse_session_expires (const char *p_hdrval, int *const p_interval, enum st_refresher *const p_ref);
static int parse_minse (const char *p_hdrval, int *const p_interval);
-static int st_get_max_se(struct sip_pvt *);
-static int st_get_min_se(struct sip_pvt *);
+static int st_get_se(struct sip_pvt *, int max);
static enum st_refresher st_get_refresher(struct sip_pvt *);
static enum st_mode st_get_mode(struct sip_pvt *);
@@ -6768,7 +6767,7 @@
strefresher2str(p->st_ref));
add_header(req, "Require", "timer");
add_header(req, "Session-Expires", se_hdr);
- snprintf(se_hdr, sizeof(se_hdr), "%d", st_get_min_se(p));
+ snprintf(se_hdr, sizeof(se_hdr), "%d", st_get_se(p, FALSE));
add_header(req, "Min-SE", se_hdr);
}
@@ -7992,14 +7991,14 @@
char i2astr[10];
if (!p->st_interval)
- p->st_interval = st_get_max_se(p);
+ p->st_interval = st_get_se(p, TRUE);
p->st_active = TRUE;
snprintf(i2astr, sizeof(i2astr), "%d", p->st_interval);
add_header(&req, "Session-Expires", i2astr);
- snprintf(i2astr, sizeof(i2astr), "%d", st_get_min_se(p));
+ snprintf(i2astr, sizeof(i2astr), "%d", st_get_se(p, FALSE));
add_header(&req, "Min-SE", i2astr);
}
@@ -15393,7 +15392,7 @@
}
}
- dlg_min_se = st_get_min_se(p);
+ dlg_min_se = st_get_se(p, FALSE);
switch (st_get_mode(p)) {
case SESSION_TIMER_MODE_ACCEPT:
case SESSION_TIMER_MODE_ORIGINATE:
@@ -15413,7 +15412,7 @@
}
if (uac_max_se > 0) {
- int dlg_max_se = st_get_max_se(p);
+ int dlg_max_se = st_get_se(p, TRUE);
if (dlg_max_se >= uac_min_se) {
st_interval = (uac_max_se < dlg_max_se) ? uac_max_se : dlg_max_se;
} else {
@@ -15448,7 +15447,7 @@
switch (st_get_mode(p)) {
case SESSION_TIMER_MODE_ORIGINATE:
st_active = TRUE;
- st_interval = st_get_max_se(p);
+ st_interval = st_get_se(p, TRUE);
st_ref = SESSION_TIMER_REFRESHER_UAS;
break;
@@ -17416,6 +17415,13 @@
}
+/*! \brief Handle 422 response to INVITE with session-timer requested
+
+ Session-Timers: An INVITE originated by Asterisk that asks for session-timers support
+ from the UAS can result into a 422 response. This is how a UAS or an intermediary proxy
+ server tells Asterisk that the session refresh interval offered by Asterisk is too low
+ for them. The proc_422_rsp() function handles a 422 response. It extracts the Min-SE
+ header that comes back in 422 and sends a new INVITE accordingly. */
static void proc_422_rsp(struct sip_pvt *p, struct sip_request *rsp)
{
int rtn;
@@ -17423,52 +17429,39 @@
int minse;
p_hdrval = get_header(rsp, "Min-SE");
- if (!ast_strlen_zero(p_hdrval)) {
- rtn = parse_minse(p_hdrval, &minse);
- if (rtn != 0) {
- ast_log(LOG_WARNING, "Parsing of Min-SE header failed %s\n", p_hdrval);
- return;
- }
- p->st_interval = minse;
- transmit_invite(p, SIP_INVITE, 1, 2);
- } else {
+ if (ast_strlen_zero(p_hdrval)) {
ast_log(LOG_WARNING, "422 response without a Min-SE header %s\n", p_hdrval);
- }
-}
-
-
-int st_get_max_se(struct sip_pvt *p)
+ return;
+ }
+ rtn = parse_minse(p_hdrval, &minse);
+ if (rtn != 0) {
+ ast_log(LOG_WARNING, "Parsing of Min-SE header failed %s\n", p_hdrval);
+ return;
+ }
+ p->st_interval = minse;
+ transmit_invite(p, SIP_INVITE, 1, 2);
+}
+
+
+/*! \brief Get Max or Min SE (session timer expiry)
+ \param max if true, get max se, otherwise min se
+
+ This functions will cause havoc with realtime.
+ We should cache the values in the pvt at start.
+*/
+int st_get_se(struct sip_pvt *p, int max)
{
if (p->username) {
struct sip_user *up = find_user(p->username, 1);
- if (up) {
- return up->st_max_se;
- }
+ if (up)
+ return (max ? up->st_max_se : up->st_min_se);
}
if (p->peername) {
struct sip_peer *pp = find_peer(p->peername, NULL, 1);
- if (pp) {
- return pp->st_max_se;
- }
+ if (pp)
+ return (max ? pp->st_max_se : pp->st_min_se);
}
return global_max_se;
-}
-
-int st_get_min_se(struct sip_pvt *p)
-{
- if (p->username) {
- struct sip_user *up = find_user(p->username, 1);
- if (up) {
- return up->st_min_se;
- }
- }
- if (p->peername) {
- struct sip_peer *pp = find_peer(p->peername, NULL, 1);
- if (pp) {
- return pp->st_min_se;
- }
- }
- return global_min_se;
}
enum st_refresher st_get_refresher(struct sip_pvt *p)
More information about the asterisk-commits
mailing list