Debian Codegraph @

Xpjproject/pjsip/src/pjsip-ua/sip_timer.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2009-2011 Teluu Inc. (http://www.teluu.com)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 #include <pjsip-ua/sip_timer.h>
19 #include <pjsip/print_util.h>
20 #include <pjsip/sip_endpoint.h>
21 #include <pjsip/sip_event.h>
22 #include <pjsip/sip_transaction.h>
23 #include <pj/log.h>
24 #include <pj/math.h>
25 #include <pj/os.h>
26 #include <pj/pool.h>
27
28 #define THIS_FILE "sip_timer.c"
29
30
31 /* Constant of Session Timers */
32 #define ABS_MIN_SE 90 /* Absolute Min-SE, in seconds */
33 #define REFRESHER_EXPIRE_TIMER_ID 2 /* Refresher expire timer id */
34
35 /* String definitions */
36 static const pj_str_t STR_SE = {"Session-Expires", 15};
37 static const pj_str_t STR_SHORT_SE = {"x", 1};
38 static const pj_str_t STR_MIN_SE = {"Min-SE", 6};
39 static const pj_str_t STR_REFRESHER = {"refresher", 9};
40 static const pj_str_t STR_UAC = {"uac", 3};
41 static const pj_str_t STR_UAS = {"uas", 3};
42 static const pj_str_t STR_TIMER = {"timer", 5};
43
44
45 /* Enumeration of refresher */
46 enum timer_refresher {
47 TR_UNKNOWN,
48 TR_UAC,
49 TR_UAS
50 };
51
52 /* Structure definition of Session Timers */
53 struct pjsip_timer
54 {
55 pj_bool_t active; /**< Active/inactive flag */
56 pjsip_timer_setting setting; /**< Session Timers setting */
57 enum timer_refresher refresher; /**< Session refresher */
58 pj_time_val last_refresh; /**< Timestamp of last
59 refresh */
60 pj_timer_entry timer; /**< Timer entry */
61 pj_bool_t use_update; /**< Use UPDATE method to
62 refresh the session */
63 pj_bool_t with_sdp; /**< SDP in UPDATE? */
64 pjsip_role_e role; /**< Role in last INVITE/
65 UPDATE transaction. */
66 void *refresh_tdata; /**< The tdata of refresh
67 request */
68 pj_timer_entry expire_timer; /**< Timer entry for expire
69 refresher */
70 pj_int32_t last_422_cseq; /**< Last 422 resp CSeq. */
71 };
72
73 /* Local functions & vars */
74 static void stop_timer(pjsip_inv_session *inv);
75 static void start_timer(pjsip_inv_session *inv);
76 static pj_bool_t is_initialized;
77 const pjsip_method pjsip_update_method = { PJSIP_OTHER_METHOD, {"UPDATE", 6}};
78 /*
79 * Session-Expires header vptr.
80 */
81 static int se_hdr_print(pjsip_sess_expires_hdr *hdr,
82 char *buf, pj_size_t size);
83 static pjsip_sess_expires_hdr* se_hdr_clone(pj_pool_t *pool,
84 const pjsip_sess_expires_hdr *hdr);
85 static pjsip_sess_expires_hdr* se_hdr_shallow_clone(
86 pj_pool_t *pool,
87 const pjsip_sess_expires_hdr* hdr);
88
89 static pjsip_hdr_vptr se_hdr_vptr =
90 {
91 (pjsip_hdr_clone_fptr) &se_hdr_clone,
92 (pjsip_hdr_clone_fptr) &se_hdr_shallow_clone,
93 (pjsip_hdr_print_fptr) &se_hdr_print,
94 };
95
96 /*
97 * Min-SE header vptr.
98 */
99 static int min_se_hdr_print(pjsip_min_se_hdr *hdr,
100 char *buf, pj_size_t size);
101 static pjsip_min_se_hdr* min_se_hdr_clone(pj_pool_t *pool,
102 const pjsip_min_se_hdr *hdr);
103 static pjsip_min_se_hdr* min_se_hdr_shallow_clone(
104 pj_pool_t *pool,
105 const pjsip_min_se_hdr* hdr);
106
107 static pjsip_hdr_vptr min_se_hdr_vptr =
108 {
109 (pjsip_hdr_clone_fptr) &min_se_hdr_clone,
110 (pjsip_hdr_clone_fptr) &min_se_hdr_shallow_clone,
111 (pjsip_hdr_print_fptr) &min_se_hdr_print,
112 };
113
114 /*
115 * Session-Expires header vptr.
116 */
117 static int se_hdr_print(pjsip_sess_expires_hdr *hdr,
118 char *buf, pj_size_t size)
119 {
120 char *p = buf;
121 char *endbuf = buf+size;
122 pj_ssize_t printed;
123 const pjsip_parser_const_t *pc = pjsip_parser_const();
124 const pj_str_t *hname = pjsip_cfg()->endpt.use_compact_form?
125 &hdr->sname : &hdr->name;
126
127 /* Print header name and value */
128 if ((endbuf - p) < (hname->slen + 16))
129 return -1;
130
131 copy_advance(p, (*hname));
132 *p++ = ':';
133 *p++ = ' ';
134
135 printed = pj_utoa(hdr->sess_expires, p);
136 p += printed;
137
138 /* Print 'refresher' param */
139 if (hdr->refresher.slen)
140 {
141 if ((endbuf - p) < (STR_REFRESHER.slen + 2 + hdr->refresher.slen))
142 return -1;
143
144 *p++ = ';';
145 copy_advance(p, STR_REFRESHER);
146 *p++ = '=';
147 copy_advance(p, hdr->refresher);
148 }
149
150 /* Print generic params */
151 printed = pjsip_param_print_on(&hdr->other_param, p, endbuf-p,
152 &pc->pjsip_TOKEN_SPEC,
153 &pc->pjsip_TOKEN_SPEC, ';');
154 if (printed < 0)
155 return (int)printed;
156
157 p += printed;
158 return (int)(p - buf);
159 }
160
161 static pjsip_sess_expires_hdr* se_hdr_clone(pj_pool_t *pool,
162 const pjsip_sess_expires_hdr *hsrc)
163 {
164 pjsip_sess_expires_hdr *hdr = pjsip_sess_expires_hdr_create(pool);
165 hdr->sess_expires = hsrc->sess_expires;
166 pj_strdup(pool, &hdr->refresher, &hsrc->refresher);
167 pjsip_param_clone(pool, &hdr->other_param, &hsrc->other_param);
168 return hdr;
169 }
170
171 static pjsip_sess_expires_hdr* se_hdr_shallow_clone(
172 pj_pool_t *pool,
173 const pjsip_sess_expires_hdr* hsrc)
174 {
175 pjsip_sess_expires_hdr *hdr = PJ_POOL_ALLOC_T(pool,pjsip_sess_expires_hdr);
176 pj_memcpy(hdr, hsrc, sizeof(*hdr));
177 pjsip_param_shallow_clone(pool, &hdr->other_param, &hsrc->other_param);
178 return hdr;
179 }
180
181 /*
182 * Min-SE header vptr.
183 */
184 static int min_se_hdr_print(pjsip_min_se_hdr *hdr,
185 char *buf, pj_size_t size)
186 {
187 char *p = buf;
188 char *endbuf = buf+size;
189 pj_ssize_t printed;
190 const pjsip_parser_const_t *pc = pjsip_parser_const();
191
192 /* Print header name and value */
193 if ((endbuf - p) < (hdr->name.slen + 16))
194 return -1;
195
196 copy_advance(p, hdr->name);
197 *p++ = ':';
198 *p++ = ' ';
199
200 printed = pj_utoa(hdr->min_se, p);
201 p += printed;
202
203 /* Print generic params */
204 printed = pjsip_param_print_on(&hdr->other_param, p, endbuf-p,
205 &pc->pjsip_TOKEN_SPEC,
206 &pc->pjsip_TOKEN_SPEC, ';');
207 if (printed < 0)
208 return (int)printed;
209
210 p += printed;
211 return (int)(p - buf);
212 }
213
214 static pjsip_min_se_hdr* min_se_hdr_clone(pj_pool_t *pool,
215 const pjsip_min_se_hdr *hsrc)
216 {
217 pjsip_min_se_hdr *hdr = pjsip_min_se_hdr_create(pool);
218 hdr->min_se = hsrc->min_se;
219 pjsip_param_clone(pool, &hdr->other_param, &hsrc->other_param);
220 return hdr;
221 }
222
223 static pjsip_min_se_hdr* min_se_hdr_shallow_clone(
224 pj_pool_t *pool,
225 const pjsip_min_se_hdr* hsrc)
226 {
227 pjsip_min_se_hdr *hdr = PJ_POOL_ALLOC_T(pool, pjsip_min_se_hdr);
228 pj_memcpy(hdr, hsrc, sizeof(*hdr));
229 pjsip_param_shallow_clone(pool, &hdr->other_param, &hsrc->other_param);
230 return hdr;
231 }
232
233
234 /*
235 * Parse Session-Expires header.
236 */
237 static pjsip_hdr *parse_hdr_se(pjsip_parse_ctx *ctx)
238 {
239 pjsip_sess_expires_hdr *hdr = pjsip_sess_expires_hdr_create(ctx->pool);
240 const pjsip_parser_const_t *pc = pjsip_parser_const();
241 pj_str_t token;
242
243 pj_scan_get(ctx->scanner, &pc->pjsip_DIGIT_SPEC, &token);
244 hdr->sess_expires = pj_strtoul(&token);
245
246 while (*ctx->scanner->curptr == ';') {
247 pj_str_t pname, pvalue;
248
249 pj_scan_get_char(ctx->scanner);
250 pjsip_parse_param_imp(ctx->scanner, ctx->pool, &pname, &pvalue, 0);
251
252 if (pj_stricmp(&pname, &STR_REFRESHER)==0) {
253 hdr->refresher = pvalue;
254 } else {
255 pjsip_param *param = PJ_POOL_ALLOC_T(ctx->pool, pjsip_param);
256 param->name = pname;
257 param->value = pvalue;
258 pj_list_push_back(&hdr->other_param, param);
259 }
260 }
261 pjsip_parse_end_hdr_imp( ctx->scanner );
262 return (pjsip_hdr*)hdr;
263 }
264
265 /*
266 * Parse Min-SE header.
267 */
268 static pjsip_hdr *parse_hdr_min_se(pjsip_parse_ctx *ctx)
269 {
270 pjsip_min_se_hdr *hdr = pjsip_min_se_hdr_create(ctx->pool);
271 const pjsip_parser_const_t *pc = pjsip_parser_const();
272 pj_str_t token;
273
274 pj_scan_get(ctx->scanner, &pc->pjsip_DIGIT_SPEC, &token);
275 hdr->min_se = pj_strtoul(&token);
276
277 while (*ctx->scanner->curptr == ';') {
278 pj_str_t pname, pvalue;
279 pjsip_param *param = PJ_POOL_ALLOC_T(ctx->pool, pjsip_param);
280
281 pj_scan_get_char(ctx->scanner);
282 pjsip_parse_param_imp(ctx->scanner, ctx->pool, &pname, &pvalue, 0);
283
284 param->name = pname;
285 param->value = pvalue;
286 pj_list_push_back(&hdr->other_param, param);
287 }
288 pjsip_parse_end_hdr_imp( ctx->scanner );
289 return (pjsip_hdr*)hdr;
290 }
291
292
293 /* Add "Session-Expires" and "Min-SE" headers. Note that "Min-SE" header
294 * can only be added to INVITE/UPDATE request and 422 response.
295 */
296 static void add_timer_headers(pjsip_inv_session *inv, pjsip_tx_data *tdata,
297 pj_bool_t add_se, pj_bool_t add_min_se)
298 {
299 pjsip_timer *timer = inv->timer;
300
301 /* Add Session-Expires header */
302 if (add_se) {
303 pjsip_sess_expires_hdr *hdr;
304
305 hdr = pjsip_sess_expires_hdr_create(tdata->pool);
306 hdr->sess_expires = timer->setting.sess_expires;
307 if (timer->refresher != TR_UNKNOWN)
308 hdr->refresher = (timer->refresher == TR_UAC? STR_UAC : STR_UAS);
309
310 pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*) hdr);
311 }
312
313 /* Add Min-SE header */
314 if (add_min_se) {
315 pjsip_min_se_hdr *hdr;
316
317 hdr = pjsip_min_se_hdr_create(tdata->pool);
318 hdr->min_se = timer->setting.min_se;
319
320 pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*) hdr);
321 }
322 }
323
324 /* Timer callback. When the timer is fired, it can be time to refresh
325 * the session if UA is the refresher, otherwise it is time to end
326 * the session.
327 */
328 static void timer_cb(pj_timer_heap_t *timer_heap, struct pj_timer_entry *entry)
329 {
330 pjsip_inv_session *inv = (pjsip_inv_session*) entry->user_data;
331 pjsip_tx_data *tdata = NULL;
332 pj_status_t status;
333 pj_bool_t as_refresher;
334 int entry_id;
335 char obj_name[PJ_MAX_OBJ_NAME];
336
337 pj_assert(inv);
338
339 PJ_UNUSED_ARG(timer_heap);
340
341 /* Lock dialog. */
342 pjsip_dlg_inc_lock(inv->dlg);
343
344 /* Check our role */
345 as_refresher =
346 (inv->timer->refresher == TR_UAC && inv->timer->role == PJSIP_ROLE_UAC) ||
347 (inv->timer->refresher == TR_UAS && inv->timer->role == PJSIP_ROLE_UAS);
348
349 entry_id = entry->id;
350 pj_ansi_strxcpy(obj_name, inv->pool->obj_name, PJ_MAX_OBJ_NAME);
351
352 /* Do action based on role(refresher or refreshee).
353 * As refresher:
354 * - send refresh, or
355 * - end session if there is no response to the refresh request.
356 * As refreshee:
357 * - end session if there is no refresh request received.
358 */
359 if (as_refresher && (entry_id != REFRESHER_EXPIRE_TIMER_ID)) {
360 pj_time_val now;
361
362 /* As refresher, reshedule the refresh request on the following:
363 * - must not send re-INVITE if another INVITE or SDP negotiation
364 * is in progress.
365 * - must not send UPDATE with SDP if SDP negotiation is in progress
366 */
367 pjmedia_sdp_neg_state neg_state = pjmedia_sdp_neg_get_state(inv->neg);
368
369 inv->timer->timer.id = 0;
370
371 if ( (!inv->timer->use_update && (
372 inv->invite_tsx != NULL ||
373 neg_state != PJMEDIA_SDP_NEG_STATE_DONE)
374 )
375 ||
376 (inv->timer->use_update && inv->timer->with_sdp &&
377 neg_state != PJMEDIA_SDP_NEG_STATE_DONE
378 )
379 )
380 {
381 pj_time_val delay = {1, 0};
382
383 inv->timer->timer.id = 1;
384 pjsip_endpt_schedule_timer(inv->dlg->endpt, &inv->timer->timer,
385 &delay);
386 pjsip_dlg_dec_lock(inv->dlg);
387
388 PJ_LOG(3, (obj_name,
389 "Reschedule refresh request after %ld seconds as "
390 "there is another SDP negotiation in progress",
391 delay.sec));
392 return;
393 }
394
395 /* Refresher, refresh the session */
396 if (inv->timer->use_update) {
397 const pjmedia_sdp_session *offer = NULL;
398
399 if (inv->timer->with_sdp) {
400 pjmedia_sdp_neg_get_active_local(inv->neg, &offer);
401 }
402 status = pjsip_inv_update(inv, NULL, offer, &tdata);
403 } else {
404 /* Create re-INVITE without modifying session */
405 pjsip_msg_body *body;
406 const pjmedia_sdp_session *offer = NULL;
407
408 pj_assert(pjmedia_sdp_neg_get_state(inv->neg) ==
409 PJMEDIA_SDP_NEG_STATE_DONE);
410
411 status = pjsip_inv_invite(inv, &tdata);
412 if (status == PJ_SUCCESS)
413 status = pjmedia_sdp_neg_send_local_offer(inv->pool_prov,
414 inv->neg, &offer);
415 if (status == PJ_SUCCESS)
416 status = pjmedia_sdp_neg_get_neg_local(inv->neg, &offer);
417 if (status == PJ_SUCCESS) {
418 status = pjsip_create_sdp_body(tdata->pool,
419 (pjmedia_sdp_session*)offer, &body);
420 tdata->msg->body = body;
421 }
422 }
423
424 pj_gettimeofday(&now);
425 PJ_LOG(4, (obj_name,
426 "Refreshing session after %lds (expiration period=%ds)",
427 (now.sec-inv->timer->last_refresh.sec),
428 inv->timer->setting.sess_expires));
429 } else {
430
431 pj_time_val now;
432 pj_str_t reason = pj_str("No session refresh received.");
433
434 if (as_refresher)
435 inv->timer->expire_timer.id = 0;
436 else
437 inv->timer->timer.id = 0;
438
439 /* Terminate the session */
440 status = pjsip_inv_end_session(inv, PJSIP_SC_REQUEST_TIMEOUT,
441 &reason, &tdata);
442
443 pj_gettimeofday(&now);
444 PJ_LOG(3, (obj_name,
445 "No session %s received after %lds "
446 "(expiration period=%ds), stopping session now!",
447 (as_refresher?"refresh response":"refresh"),
448 (now.sec-inv->timer->last_refresh.sec),
449 inv->timer->setting.sess_expires));
450
451 }
452
453 /* Unlock dialog. */
454 pjsip_dlg_dec_lock(inv->dlg);
455
456 /* Send message, if any */
457 if (tdata && status == PJ_SUCCESS) {
458 inv->timer->refresh_tdata = tdata;
459
460 status = pjsip_inv_send_msg(inv, tdata);
461 }
462
463 /*
464 * At this point, dialog might have already been destroyed,
465 * including its pool used by the invite session.
466 */
467
468 /* Print error message, if any */
469 if (status != PJ_SUCCESS) {
470 PJ_PERROR(2, (obj_name, status,
471 "Error in %s session timer",
472 ((as_refresher && entry_id != REFRESHER_EXPIRE_TIMER_ID)?
473 "refreshing" : "terminating")));
474 }
475 }
476
477 /* Start Session Timers */
478 static void start_timer(pjsip_inv_session *inv)
479 {
480 const pj_str_t UPDATE = { "UPDATE", 6 };
481 pjsip_timer *timer = inv->timer;
482 pj_time_val delay = {0};
483
484 pj_assert(inv->timer->active == PJ_TRUE);
485
486 stop_timer(inv);
487
488 inv->timer->use_update =
489 (pjsip_dlg_remote_has_cap(inv->dlg, PJSIP_H_ALLOW, NULL,
490 &UPDATE) == PJSIP_DIALOG_CAP_SUPPORTED);
491 if (!inv->timer->use_update) {
492 /* INVITE always needs SDP */
493 inv->timer->with_sdp = PJ_TRUE;
494 }
495
496 pj_timer_entry_init(&timer->timer,
497 1, /* id */
498 inv, /* user data */
499 timer_cb); /* callback */
500
501 /* Set delay based on role, refresher or refreshee */
502 if ((timer->refresher == TR_UAC && inv->timer->role == PJSIP_ROLE_UAC) ||
503 (timer->refresher == TR_UAS && inv->timer->role == PJSIP_ROLE_UAS))
504 {
505 /* Add refresher expire timer */
506 pj_timer_entry_init(&timer->expire_timer,
507 REFRESHER_EXPIRE_TIMER_ID, /* id */
508 inv, /* user data */
509 timer_cb); /* callback */
510
511 delay.sec = timer->setting.sess_expires;
512 /* Schedule the timer */
513 pjsip_endpt_schedule_timer(inv->dlg->endpt, &timer->expire_timer,
514 &delay);
515
516 /* Next refresh, the delay is half of session expire */
517 delay.sec = timer->setting.sess_expires / 2;
518 } else {
519 /* Send BYE if no refresh received until this timer fired, delay
520 * is the minimum of 32 seconds and one third of the session interval
521 * before session expiration.
522 */
523 delay.sec = timer->setting.sess_expires -
524 timer->setting.sess_expires/3;
525 delay.sec = PJ_MAX((long)timer->setting.sess_expires-32, delay.sec);
526 }
527
528 /* Schedule the timer */
529 pjsip_endpt_schedule_timer(inv->dlg->endpt, &timer->timer, &delay);
530
531 /* Update last refresh time */
532 pj_gettimeofday(&timer->last_refresh);
533 }
534
535 /* Stop Session Timers */
536 static void stop_timer(pjsip_inv_session *inv)
537 {
538 if (inv->timer->timer.id != 0) {
539 pjsip_endpt_cancel_timer(inv->dlg->endpt, &inv->timer->timer);
540 inv->timer->timer.id = 0;
541 }
542
543 if (inv->timer->expire_timer.id != 0) {
544 pjsip_endpt_cancel_timer(inv->dlg->endpt, &inv->timer->expire_timer);
545 inv->timer->expire_timer.id = 0;
546 }
547 }
548
549 /* Deinitialize Session Timers */
550 static void pjsip_timer_deinit_module(pjsip_endpoint *endpt)
551 {
552 PJ_TODO(provide_initialized_flag_for_each_endpoint);
553 PJ_UNUSED_ARG(endpt);
554 is_initialized = PJ_FALSE;
555 }
556
557 /*
558 * Initialize Session Timers support in PJSIP.
559 */
560 PJ_DEF(pj_status_t) pjsip_timer_init_module(pjsip_endpoint *endpt)
561 {
562 pj_status_t status;
563
564 PJ_ASSERT_RETURN(endpt, PJ_EINVAL);
565
566 if (is_initialized)
567 return PJ_SUCCESS;
568
569 /* Register Session-Expires header parser */
570 status = pjsip_register_hdr_parser( STR_SE.ptr, STR_SHORT_SE.ptr,
571 &parse_hdr_se);
572 if (status != PJ_SUCCESS)
573 return status;
574
575 /* Register Min-SE header parser */
576 status = pjsip_register_hdr_parser( STR_MIN_SE.ptr, NULL,
577 &parse_hdr_min_se);
578 if (status != PJ_SUCCESS)
579 return status;
580
581 /* Register 'timer' capability to endpoint */
582 status = pjsip_endpt_add_capability(endpt, NULL, PJSIP_H_SUPPORTED,
583 NULL, 1, &STR_TIMER);
584 if (status != PJ_SUCCESS)
585 return status;
586
587 /* Register deinit module to be executed when PJLIB shutdown */
588 if (pjsip_endpt_atexit(endpt, &pjsip_timer_deinit_module) != PJ_SUCCESS) {
589 /* Failure to register this function may cause this module won't
590 * work properly when the stack is restarted (without quitting
591 * application).
592 */
593 pj_assert(!"Failed to register Session Timer deinit.");
594 PJ_LOG(1, (THIS_FILE, "Failed to register Session Timer deinit."));
595 }
596
597 is_initialized = PJ_TRUE;
598
599 return PJ_SUCCESS;
600 }
601
602
603 /*
604 * Initialize Session Timers setting with default values.
605 */
606 PJ_DEF(pj_status_t) pjsip_timer_setting_default(pjsip_timer_setting *setting)
607 {
608 pj_bzero(setting, sizeof(pjsip_timer_setting));
609
610 setting->sess_expires = PJSIP_SESS_TIMER_DEF_SE;
611 setting->min_se = ABS_MIN_SE;
612
613 return PJ_SUCCESS;
614 }
615
616 /*
617 * Initialize Session Timers in an INVITE session.
618 */
619 PJ_DEF(pj_status_t) pjsip_timer_init_session(
620 pjsip_inv_session *inv,
621 const pjsip_timer_setting *setting)
622 {
623 pjsip_timer_setting *s;
624
625 pj_assert(is_initialized);
626 PJ_ASSERT_RETURN(inv, PJ_EINVAL);
627
628 /* Allocate and/or reset Session Timers structure */
629 if (!inv->timer)
630 inv->timer = PJ_POOL_ZALLOC_T(inv->pool, pjsip_timer);
631 else
632 pj_bzero(inv->timer, sizeof(pjsip_timer));
633
634 s = &inv->timer->setting;
635
636 /* Init Session Timers setting */
637 if (setting) {
638 PJ_ASSERT_RETURN(setting->min_se >= ABS_MIN_SE,
639 PJ_ETOOSMALL);
640 PJ_ASSERT_RETURN(setting->sess_expires >= setting->min_se,
641 PJ_EINVAL);
642
643 pj_memcpy(s, setting, sizeof(*s));
644 } else {
645 pjsip_timer_setting_default(s);
646 }
647
648 return PJ_SUCCESS;
649 }
650
651
652 /*
653 * Create Session-Expires header.
654 */
655 PJ_DEF(pjsip_sess_expires_hdr*) pjsip_sess_expires_hdr_create(
656 pj_pool_t *pool)
657 {
658 pjsip_sess_expires_hdr *hdr = PJ_POOL_ZALLOC_T(pool,
659 pjsip_sess_expires_hdr);
660
661 pj_assert(is_initialized);
662
663 hdr->type = PJSIP_H_OTHER;
664 hdr->name = STR_SE;
665 hdr->sname = STR_SHORT_SE;
666 hdr->vptr = &se_hdr_vptr;
667 pj_list_init(hdr);
668 pj_list_init(&hdr->other_param);
669 return hdr;
670 }
671
672
673 /*
674 * Create Min-SE header.
675 */
676 PJ_DEF(pjsip_min_se_hdr*) pjsip_min_se_hdr_create(pj_pool_t *pool)
677 {
678 pjsip_min_se_hdr *hdr = PJ_POOL_ZALLOC_T(pool, pjsip_min_se_hdr);
679
680 pj_assert(is_initialized);
681
682 hdr->type = PJSIP_H_OTHER;
683 hdr->name = STR_MIN_SE;
684 hdr->vptr = &min_se_hdr_vptr;
685 pj_list_init(hdr);
686 pj_list_init(&hdr->other_param);
687 return hdr;
688 }
689
690
691 /*
692 * This function generates headers for Session Timers for intial and
693 * refresh INVITE or UPDATE.
694 */
695 PJ_DEF(pj_status_t) pjsip_timer_update_req(pjsip_inv_session *inv,
696 pjsip_tx_data *tdata)
697 {
698 PJ_ASSERT_RETURN(inv && tdata, PJ_EINVAL);
699
700 /* Check if Session Timers is supported */
701 if ((inv->options & PJSIP_INV_SUPPORT_TIMER) == 0)
702 return PJ_SUCCESS;
703
704 pj_assert(is_initialized);
705
706 /* Make sure Session Timers is initialized */
707 if (inv->timer == NULL)
708 pjsip_timer_init_session(inv, NULL);
709
710 /* If refresher role (i.e: ours or peer) has been set/negotiated,
711 * better to keep it.
712 */
713 if (inv->timer->refresher != TR_UNKNOWN) {
714 pj_bool_t as_refresher;
715
716 /* Check our refresher role */
717 as_refresher =
718 (inv->timer->refresher==TR_UAC && inv->timer->role==PJSIP_ROLE_UAC) ||
719 (inv->timer->refresher==TR_UAS && inv->timer->role==PJSIP_ROLE_UAS);
720
721 /* Update transaction role */
722 inv->timer->role = PJSIP_ROLE_UAC;
723
724 /* Update refresher role */
725 inv->timer->refresher = as_refresher? TR_UAC : TR_UAS;
726 }
727
728 /* Add Session Timers headers */
729 add_timer_headers(inv, tdata, PJ_TRUE, PJ_TRUE);
730
731 return PJ_SUCCESS;
732 }
733
734 /*
735 * This function will handle Session Timers part of INVITE/UPDATE
736 * responses with code:
737 * - 422 (Session Interval Too Small)
738 * - 2xx final response
739 */
740 PJ_DEF(pj_status_t) pjsip_timer_process_resp(pjsip_inv_session *inv,
741 const pjsip_rx_data *rdata,
742 pjsip_status_code *st_code)
743 {
744 const pjsip_msg *msg;
745
746 PJ_ASSERT_ON_FAIL(inv && rdata,
747 {if(st_code)*st_code=PJSIP_SC_INTERNAL_SERVER_ERROR;return PJ_EINVAL;});
748
749 /* Check if Session Timers is supported */
750 if ((inv->options & PJSIP_INV_SUPPORT_TIMER) == 0) {
751 if (rdata->msg_info.msg->line.status.code ==
752 PJSIP_SC_SESSION_TIMER_TOO_SMALL)
753 {
754 return PJSIP_EINVALIDSTATUS;
755 } else {
756 return PJ_SUCCESS;
757 }
758 }
759
760 pj_assert(is_initialized);
761
762 msg = rdata->msg_info.msg;
763 pj_assert(msg->type == PJSIP_RESPONSE_MSG);
764
765 /* Only process response of INVITE or UPDATE */
766 if (rdata->msg_info.cseq->method.id != PJSIP_INVITE_METHOD &&
767 pjsip_method_cmp(&rdata->msg_info.cseq->method, &pjsip_update_method))
768 {
769 return PJ_SUCCESS;
770 }
771
772 if (msg->line.status.code == PJSIP_SC_SESSION_TIMER_TOO_SMALL) {
773 /* Our Session-Expires is too small, let's update it based on
774 * Min-SE header in the response.
775 */
776 pjsip_tx_data *tdata;
777 pjsip_min_se_hdr *min_se_hdr;
778 pjsip_hdr *hdr;
779 pjsip_via_hdr *via;
780
781 /* Get Min-SE value from response */
782 min_se_hdr = (pjsip_min_se_hdr*)
783 pjsip_msg_find_hdr_by_name(msg, &STR_MIN_SE, NULL);
784 if (min_se_hdr == NULL) {
785 /* Response 422 MUST contain Min-SE header */
786 PJ_LOG(3, (inv->pool->obj_name,
787 "Received 422 (Session Interval Too Small) response "
788 "without Min-SE header!"));
789
790 pjsip_timer_end_session(inv);
791 return PJSIP_EMISSINGHDR;
792 }
793
794 /* Avoid 422 retry loop. Ignore it and stop retrying if dialog is
795 * established, otherwise, just return error to disconnect the call.
796 */
797 if (rdata->msg_info.cseq->cseq == inv->timer->last_422_cseq + 1) {
798 if (inv->state == PJSIP_INV_STATE_CONFIRMED) {
799 inv->invite_tsx = NULL;
800 return PJ_SUCCESS;
801 } else {
802 return PJSIP_ERRNO_FROM_SIP_STATUS(
803 PJSIP_SC_SESSION_TIMER_TOO_SMALL);
804 }
805 }
806 inv->timer->last_422_cseq = rdata->msg_info.cseq->cseq;
807
808 /* Session Timers should have been initialized here */
809 pj_assert(inv->timer);
810
811 /* Update Min-SE */
812 inv->timer->setting.min_se = PJ_MAX(min_se_hdr->min_se,
813 inv->timer->setting.min_se);
814
815 /* Update Session Timers setting */
816 if (inv->timer->setting.sess_expires < inv->timer->setting.min_se)
817 inv->timer->setting.sess_expires = inv->timer->setting.min_se;
818
819 /* Prepare to restart the request */
820
821 /* Get the original INVITE/UPDATE request. */
822 tdata = pjsip_rdata_get_tsx((pjsip_rx_data*)rdata)->last_tx;
823
824 /* Remove branch param in Via header. */
825 via = (pjsip_via_hdr*) pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL);
826 pj_assert(via);
827 via->branch_param.slen = 0;
828
829 /* Restore strict route set.
830 * See https://github.com/pjsip/pjproject/issues/492
831 */
832 pjsip_restore_strict_route_set(tdata);
833
834 /* Must invalidate the message! */
835 pjsip_tx_data_invalidate_msg(tdata);
836
837 pjsip_tx_data_add_ref(tdata);
838
839 /* Update Session Timers headers */
840 hdr = (pjsip_hdr*) pjsip_msg_find_hdr_by_name(tdata->msg,
841 &STR_MIN_SE, NULL);
842 if (hdr != NULL) pj_list_erase(hdr);
843
844 hdr = (pjsip_hdr*) pjsip_msg_find_hdr_by_names(tdata->msg, &STR_SE,
845 &STR_SHORT_SE, NULL);
846 if (hdr != NULL) pj_list_erase(hdr);
847
848 add_timer_headers(inv, tdata, PJ_TRUE, PJ_TRUE);
849
850 /* Restart UAC if this is initial INVITE, or simply reset tsx for
851 * subsequent INVITE.
852 */
853 if (inv->state < PJSIP_INV_STATE_CONFIRMED)
854 pjsip_inv_uac_restart(inv, PJ_FALSE);
855 else if (tdata->msg->line.req.method.id == PJSIP_INVITE_METHOD)
856 inv->invite_tsx = NULL;
857
858 /* Resend the updated request */
859 pjsip_inv_send_msg(inv, tdata);
860
861 return PJ_SUCCESS;
862
863 } else if (msg->line.status.code/100 == 2) {
864
865 pjsip_sess_expires_hdr *se_hdr;
866
867 /* Find Session-Expires header */
868 se_hdr = (pjsip_sess_expires_hdr*) pjsip_msg_find_hdr_by_names(
869 msg, &STR_SE,
870 &STR_SHORT_SE, NULL);
871 if (se_hdr == NULL) {
872 /* Remote doesn't support/want Session Timers, check if local
873 * require or force to use Session Timers.
874 */
875 if (inv->options & PJSIP_INV_REQUIRE_TIMER) {
876 if (st_code)
877 *st_code = PJSIP_SC_EXTENSION_REQUIRED;
878 pjsip_timer_end_session(inv);
879 return PJSIP_ERRNO_FROM_SIP_STATUS(
880 PJSIP_SC_EXTENSION_REQUIRED);
881 }
882
883 if ((inv->options & PJSIP_INV_ALWAYS_USE_TIMER) == 0) {
884 /* Session Timers not forced */
885 pjsip_timer_end_session(inv);
886 return PJ_SUCCESS;
887 }
888 }
889
890 /* Make sure Session Timers is initialized */
891 if (inv->timer == NULL)
892 pjsip_timer_init_session(inv, NULL);
893
894 /* Session expiration period specified by remote is lower than our
895 * Min-SE.
896 */
897 if (se_hdr &&
898 se_hdr->sess_expires < inv->timer->setting.min_se)
899 {
900 /* See ticket #954, instead of returning non-PJ_SUCCESS (which
901 * may cause disconnecting call/dialog), let's just accept the
902 * SE and update our local SE, as long as it isn't less than 90s.
903 */
904 if (se_hdr->sess_expires >= ABS_MIN_SE) {
905 PJ_LOG(3, (inv->pool->obj_name,
906 "Peer responds with bad Session-Expires, %ds, "
907 "which is less than Min-SE specified in request, "
908 "%ds. Well, let's just accept and use it.",
909 se_hdr->sess_expires, inv->timer->setting.min_se));
910
911 inv->timer->setting.sess_expires = se_hdr->sess_expires;
912 inv->timer->setting.min_se = se_hdr->sess_expires;
913 }
914
915 //if (st_code)
916 // *st_code = PJSIP_SC_SESSION_TIMER_TOO_SMALL;
917 //pjsip_timer_end_session(inv);
918 //return PJSIP_ERRNO_FROM_SIP_STATUS(
919 // PJSIP_SC_SESSION_TIMER_TOO_SMALL);
920 }
921
922 /* Update SE. Session-Expires in response cannot be lower than Min-SE.
923 * Session-Expires in response can only be equal or lower than in
924 * request.
925 */
926 if (se_hdr &&
927 se_hdr->sess_expires <= inv->timer->setting.sess_expires &&
928 se_hdr->sess_expires >= inv->timer->setting.min_se)
929 {
930 /* Good SE from remote, update local SE */
931 inv->timer->setting.sess_expires = se_hdr->sess_expires;
932 }
933
934 /* Set the refresher */
935 if (se_hdr && pj_stricmp(&se_hdr->refresher, &STR_UAC) == 0)
936 inv->timer->refresher = TR_UAC;
937 else if (se_hdr && pj_stricmp(&se_hdr->refresher, &STR_UAS) == 0)
938 inv->timer->refresher = TR_UAS;
939 else
940 /* UAS should set the refresher, however, there is a case that
941 * UAS doesn't support/want Session Timers but the UAC insists
942 * to use Session Timers.
943 */
944 inv->timer->refresher = TR_UAC;
945
946 /* Remember our role in this transaction */
947 inv->timer->role = PJSIP_ROLE_UAC;
948
949 /* Finally, set active flag and start the Session Timers */
950 inv->timer->active = PJ_TRUE;
951 start_timer(inv);
952
953 } else if (pjsip_method_cmp(&rdata->msg_info.cseq->method,
954 &pjsip_update_method) == 0 &&
955 msg->line.status.code >= 400 && msg->line.status.code < 600)
956 {
957 /* This is to handle error response to previous UPDATE that was
958 * sent without SDP. In this case, retry sending UPDATE but
959 * with SDP this time.
960 * Note: the additional expressions are to check that the
961 * UPDATE was really the one sent by us, not by other
962 * call components (e.g. to change codec)
963 */
964 if (inv->timer->timer.id == 0 && inv->timer->use_update &&
965 inv->timer->with_sdp == PJ_FALSE)
966 {
967 inv->timer->with_sdp = PJ_TRUE;
968 timer_cb(NULL, &inv->timer->timer);
969 }
970 }
971
972 return PJ_SUCCESS;
973 }
974
975 PJ_DEF(pj_status_t) pjsip_timer_handle_refresh_error(
976 pjsip_inv_session *inv,
977 pjsip_event *event)
978 {
979 PJ_ASSERT_RETURN(inv && event, PJ_EINVAL);
980
981 /* Check if Session Timers is supported */
982 if ((inv->options & PJSIP_INV_SUPPORT_TIMER) == 0)
983 return PJ_SUCCESS;
984
985 pj_assert(is_initialized);
986
987 if (inv->timer && inv->timer->active) {
988 pj_bool_t as_refresher;
989
990 /* Check our role */
991 as_refresher = ((inv->timer->refresher == TR_UAC) &&
992 (inv->timer->role == PJSIP_ROLE_UAC)) ||
993 ((inv->timer->refresher == TR_UAS) &&
994 (inv->timer->role == PJSIP_ROLE_UAS));
995
996
997 if ((as_refresher) && (event->type == PJSIP_EVENT_TSX_STATE) &&
998 (inv->timer->refresh_tdata == event->body.tsx_state.tsx->last_tx))
999 {
1000 pjsip_status_code st_code;
1001 pjsip_tx_data *bye;
1002 pj_status_t status;
1003
1004 st_code =
1005 (pjsip_status_code)event->body.tsx_state.tsx->status_code;
1006
1007 PJ_LOG(3, (inv->pool->obj_name,
1008 "Receive error %d for refresh request %.*s/cseq=%d",
1009 st_code, (int)event->body.tsx_state.tsx->method.name.slen,
1010 event->body.tsx_state.tsx->method.name.ptr,
1011 event->body.tsx_state.tsx->cseq));
1012
1013 if (st_code == 503 && PJSIP_SESS_TIMER_RETRY_DELAY >= 0) {
1014 /* Retry the refresh after some delay */
1015 pj_time_val delay = {PJSIP_SESS_TIMER_RETRY_DELAY, 0};
1016
1017 PJ_LOG(3, (inv->pool->obj_name, "Scheduling to retry refresh "
1018 "request after %ld second(s)", delay.sec));
1019
1020 inv->timer->timer.id = 1;
1021 pjsip_endpt_schedule_timer(inv->dlg->endpt,
1022 &inv->timer->timer, &delay);
1023 } else {
1024 PJ_LOG(3, (inv->pool->obj_name, "Ending session now"));
1025
1026 status = pjsip_inv_end_session(inv,
1027 event->body.tsx_state.tsx->status_code,
1028 pjsip_get_status_text(st_code),
1029 &bye);
1030
1031 if (status == PJ_SUCCESS && bye)
1032 status = pjsip_inv_send_msg(inv, bye);
1033 }
1034 }
1035 }
1036
1037 return PJ_SUCCESS;
1038 }
1039
1040 /*
1041 * Handle incoming INVITE or UPDATE request.
1042 */
1043 PJ_DEF(pj_status_t) pjsip_timer_process_req(pjsip_inv_session *inv,
1044 const pjsip_rx_data *rdata,
1045 pjsip_status_code *st_code)
1046 {
1047 pjsip_min_se_hdr *min_se_hdr;
1048 pjsip_sess_expires_hdr *se_hdr;
1049 const pjsip_msg *msg;
1050 unsigned min_se;
1051
1052 PJ_ASSERT_ON_FAIL(inv && rdata,
1053 {if(st_code)*st_code=PJSIP_SC_INTERNAL_SERVER_ERROR;return PJ_EINVAL;});
1054
1055 /* Check if Session Timers is supported */
1056 if ((inv->options & PJSIP_INV_SUPPORT_TIMER) == 0)
1057 return PJ_SUCCESS;
1058
1059 pj_assert(is_initialized);
1060
1061 msg = rdata->msg_info.msg;
1062 pj_assert(msg->type == PJSIP_REQUEST_MSG);
1063
1064 /* Only process INVITE or UPDATE request */
1065 if (msg->line.req.method.id != PJSIP_INVITE_METHOD &&
1066 pjsip_method_cmp(&rdata->msg_info.cseq->method, &pjsip_update_method))
1067 {
1068 return PJ_SUCCESS;
1069 }
1070
1071 /* Make sure Session Timers is initialized */
1072 if (inv->timer == NULL)
1073 pjsip_timer_init_session(inv, NULL);
1074
1075 /* Find Session-Expires header */
1076 se_hdr = (pjsip_sess_expires_hdr*) pjsip_msg_find_hdr_by_names(
1077 msg, &STR_SE, &STR_SHORT_SE, NULL);
1078 /* Find Min-SE header */
1079 min_se_hdr = (pjsip_min_se_hdr*) pjsip_msg_find_hdr_by_name(msg,
1080 &STR_MIN_SE, NULL);
1081 /* Update Min-SE */
1082 min_se = inv->timer->setting.min_se;
1083 if (min_se_hdr)
1084 min_se = PJ_MAX(min_se_hdr->min_se, min_se);
1085
1086 /* Validate SE. Session-Expires cannot be lower than Min-SE
1087 * (or 90 seconds if Min-SE is not set).
1088 */
1089 if (se_hdr && se_hdr->sess_expires < min_se) {
1090 if (st_code)
1091 *st_code = PJSIP_SC_SESSION_TIMER_TOO_SMALL;
1092 return PJSIP_ERRNO_FROM_SIP_STATUS(PJSIP_SC_SESSION_TIMER_TOO_SMALL);
1093 }
1094
1095 /* Update SE. Note that there is a case that SE is not available in the
1096 * request (which means remote doesn't want/support it), but local insists
1097 * to use Session Timers.
1098 */
1099 if (se_hdr) {
1100 /* Update SE as specified by peer. */
1101 inv->timer->setting.sess_expires = se_hdr->sess_expires;
1102 } else if (inv->timer->setting.sess_expires < min_se) {
1103 /* There is no SE in the request (remote support Session Timers but
1104 * doesn't want to use it, it just specify Min-SE) and local SE is
1105 * lower than Min-SE specified by remote.
1106 */
1107 inv->timer->setting.sess_expires = min_se;
1108 }
1109
1110 /* If incoming request has no SE header, it means remote doesn't
1111 * support/want Session Timers. So let's check if local require or
1112 * force to use Session Timers. Note that Supported and Require headers
1113 * negotiation should have been verified by invite session.
1114 */
1115 if (se_hdr == NULL) {
1116 if ((inv->options &
1117 (PJSIP_INV_REQUIRE_TIMER | PJSIP_INV_ALWAYS_USE_TIMER)) == 0)
1118 {
1119 /* Session Timers not forced/required */
1120 pjsip_timer_end_session(inv);
1121 return PJ_SUCCESS;
1122 }
1123 }
1124
1125 /* Set the refresher */
1126 if (se_hdr && pj_stricmp(&se_hdr->refresher, &STR_UAC) == 0)
1127 inv->timer->refresher = TR_UAC;
1128 else if (se_hdr && pj_stricmp(&se_hdr->refresher, &STR_UAS) == 0)
1129 inv->timer->refresher = TR_UAS;
1130 else {
1131 /* If refresher role (i.e: ours or peer) has been set/negotiated,
1132 * better to keep it.
1133 */
1134 if (inv->timer->refresher != TR_UNKNOWN) {
1135 pj_bool_t as_refresher;
1136
1137 /* Check our refresher role */
1138 as_refresher =
1139 (inv->timer->refresher==TR_UAC && inv->timer->role==PJSIP_ROLE_UAC) ||
1140 (inv->timer->refresher==TR_UAS && inv->timer->role==PJSIP_ROLE_UAS);
1141
1142 /* Update refresher role */
1143 inv->timer->refresher = as_refresher? TR_UAS : TR_UAC;
1144 } else {
1145 /* If UAC supports timer and Session-Expires header is present
1146 * in the request, set UAC as refresher.
1147 * If UAC doesn't support timer and a proxy inserts a
1148 * Session-Expires header, then UAS has to be the
1149 * refresher (according to RFC 4028 Section 9).
1150 */
1151 pj_bool_t uac_supports_timer = PJ_FALSE;
1152 pjsip_supported_hdr *sup_hdr;
1153
1154 sup_hdr = (pjsip_supported_hdr*)
1155 pjsip_msg_find_hdr(msg, PJSIP_H_SUPPORTED, NULL);
1156 if (sup_hdr) {
1157 unsigned i;
1158
1159 for (i = 0; i < sup_hdr->count; i++) {
1160 if (pj_stricmp(&sup_hdr->values[i], &STR_TIMER) == 0) {
1161 uac_supports_timer = PJ_TRUE;
1162 break;
1163 }
1164 }
1165 }
1166 inv->timer->refresher = (uac_supports_timer && se_hdr)? TR_UAC:
1167 TR_UAS;
1168 }
1169 }
1170
1171 /* Remember our role in this transaction */
1172 inv->timer->role = PJSIP_ROLE_UAS;
1173
1174 /* Set active flag */
1175 inv->timer->active = PJ_TRUE;
1176
1177 return PJ_SUCCESS;
1178 }
1179
1180 /*
1181 * Handle outgoing response with status code 2xx & 422.
1182 */
1183 PJ_DEF(pj_status_t) pjsip_timer_update_resp(pjsip_inv_session *inv,
1184 pjsip_tx_data *tdata)
1185 {
1186 pjsip_msg *msg;
1187
1188 /* Check if Session Timers is supported */
1189 if ((inv->options & PJSIP_INV_SUPPORT_TIMER) == 0)
1190 return PJ_SUCCESS;
1191
1192 pj_assert(is_initialized);
1193 PJ_ASSERT_RETURN(inv && tdata, PJ_EINVAL);
1194
1195 msg = tdata->msg;
1196
1197 if (msg->line.status.code/100 == 2)
1198 {
1199 if (inv->timer && inv->timer->active) {
1200 /* Add Session-Expires header and start the timer */
1201 add_timer_headers(inv, tdata, PJ_TRUE, PJ_FALSE);
1202
1203 /* Add 'timer' to Require header (see ticket #1560). */
1204 if (inv->timer->refresher == TR_UAC) {
1205 pjsip_require_hdr *req_hdr;
1206 pj_bool_t req_hdr_has_timer = PJ_FALSE;
1207
1208 req_hdr = (pjsip_require_hdr*)
1209 pjsip_msg_find_hdr(tdata->msg, PJSIP_H_REQUIRE,
1210 NULL);
1211 if (req_hdr == NULL) {
1212 req_hdr = pjsip_require_hdr_create(tdata->pool);
1213 PJ_ASSERT_RETURN(req_hdr, PJ_ENOMEM);
1214 pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)req_hdr);
1215 } else {
1216 unsigned i;
1217 for (i = 0; i < req_hdr->count; ++i) {
1218 if (pj_stricmp(&req_hdr->values[i], &STR_TIMER)) {
1219 req_hdr_has_timer = PJ_TRUE;
1220 break;
1221 }
1222 }
1223 }
1224 if (!req_hdr_has_timer)
1225 req_hdr->values[req_hdr->count++] = STR_TIMER;
1226 }
1227
1228 /* Finally, start timer. */
1229 start_timer(inv);
1230 }
1231 }
1232 else if (msg->line.status.code == PJSIP_SC_SESSION_TIMER_TOO_SMALL)
1233 {
1234 /* Add Min-SE header */
1235 add_timer_headers(inv, tdata, PJ_FALSE, PJ_TRUE);
1236 }
1237
1238 return PJ_SUCCESS;
1239 }
1240
1241
1242 /*
1243 * End the Session Timers.
1244 */
1245 PJ_DEF(pj_status_t) pjsip_timer_end_session(pjsip_inv_session *inv)
1246 {
1247 PJ_ASSERT_RETURN(inv, PJ_EINVAL);
1248
1249 if (inv->timer) {
1250 /* Reset active flag */
1251 inv->timer->active = PJ_FALSE;
1252
1253 /* Stop Session Timers */
1254 stop_timer(inv);
1255 }
1256
1257 return PJ_SUCCESS;
1258 }