Changeset 4715
- Timestamp:
- Jan 24, 2014 9:32:27 AM (11 years ago)
- Location:
- pjproject/trunk/pjsip
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/include/pjsip-ua/sip_timer.h
r3553 r4715 201 201 pjsip_status_code *st_code); 202 202 203 /** 204 * Process Session Timers refresh error, this function will process 205 * error from refresh request. The error will be handle according the 206 * error code, i.e : BYE will be sent after error 503 (Transport Error). 207 * 208 * @param inv The invite session. 209 * @param event The event that trigger the error. 210 * 211 * @return PJ_SUCCESS on successful. 212 */ 213 PJ_DECL(pj_status_t) pjsip_timer_handle_refresh_error( 214 pjsip_inv_session *inv, 215 pjsip_event *event); 203 216 204 217 /** -
pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c
r4713 r4715 3335 3335 handled = PJ_TRUE; 3336 3336 } 3337 3338 /* Process 502/503 error */ 3339 else if ((tsx->state == PJSIP_TSX_STATE_TERMINATED) && 3340 (tsx->status_code == 503 || tsx->status_code == 502)) 3341 { 3342 status = pjsip_timer_handle_refresh_error(inv, e); 3343 3344 handled = PJ_TRUE; 3345 } 3337 3346 3338 3347 /* Get/attach invite session's transaction data */ … … 3607 3616 return PJ_TRUE; /* Handled */ 3608 3617 3609 } else { 3618 } 3619 /* Process 502/503 error */ 3620 else if ((tsx->state == PJSIP_TSX_STATE_TERMINATED) && 3621 (tsx->status_code == 503 || tsx->status_code == 502)) 3622 { 3623 pjsip_timer_handle_refresh_error(inv, e); 3624 3625 return PJ_TRUE; 3626 } 3627 else { 3610 3628 return PJ_FALSE; /* Unhandled */ 3611 3629 } -
pjproject/trunk/pjsip/src/pjsip-ua/sip_timer.c
r4695 r4715 20 20 #include <pjsip/print_util.h> 21 21 #include <pjsip/sip_endpoint.h> 22 #include <pjsip/sip_event.h> 23 #include <pjsip/sip_transaction.h> 22 24 #include <pj/log.h> 23 25 #include <pj/math.h> … … 29 31 30 32 /* Constant of Session Timers */ 31 #define ABS_MIN_SE 90 /* Absolute Min-SE, in seconds */32 33 #define ABS_MIN_SE 90 /* Absolute Min-SE, in seconds */ 34 #define REFRESHER_EXPIRE_TIMER_ID 2 /* Refresher expire timer id */ 33 35 34 36 /* String definitions */ … … 62 64 pj_bool_t with_sdp; /**< SDP in UPDATE? */ 63 65 pjsip_role_e role; /**< Role in last INVITE/ 64 UPDATE transaction. */ 65 66 UPDATE transaction. */ 67 void *refresh_tdata; /**< The tdata of refresh 68 request */ 69 pj_timer_entry expire_timer; /**< Timer entry for expire 70 refresher */ 66 71 }; 67 72 … … 332 337 pj_assert(inv); 333 338 334 inv->timer->timer.id = 0;335 336 339 PJ_UNUSED_ARG(timer_heap); 337 340 … … 342 345 as_refresher = 343 346 (inv->timer->refresher == TR_UAC && inv->timer->role == PJSIP_ROLE_UAC) || 344 (inv->timer->refresher == TR_UAS && inv->timer->role == PJSIP_ROLE_UAS); 345 346 /* Do action based on role, refresher or refreshee */ 347 if (as_refresher) { 347 (inv->timer->refresher == TR_UAS && inv->timer->role == PJSIP_ROLE_UAS); 348 349 /* Do action based on role(refresher or refreshee). 350 * As refresher: 351 * - send refresh, or 352 * - end session if there is no response to the refresh request. 353 * As refreshee: 354 * - end session if there is no refresh request received. 355 */ 356 if (as_refresher && (entry->id != REFRESHER_EXPIRE_TIMER_ID)) { 348 357 pj_time_val now; 349 358 350 359 /* As refresher, reshedule the refresh request on the following: 351 * - m sut not send re-INVITE if another INVITE or SDP negotiation360 * - must not send re-INVITE if another INVITE or SDP negotiation 352 361 * is in progress. 353 362 * - must not send UPDATE with SDP if SDP negotiation is in progress 354 363 */ 355 364 pjmedia_sdp_neg_state neg_state = pjmedia_sdp_neg_get_state(inv->neg); 365 366 inv->timer->timer.id = 0; 367 356 368 if ( (!inv->timer->use_update && ( 357 369 inv->invite_tsx != NULL || … … 411 423 pj_time_val now; 412 424 413 /* Refreshee, terminate the session */ 425 if (as_refresher) 426 inv->timer->expire_timer.id = 0; 427 else 428 inv->timer->timer.id = 0; 429 430 /* Terminate the session */ 414 431 status = pjsip_inv_end_session(inv, PJSIP_SC_REQUEST_TIMEOUT, 415 432 NULL, &tdata); … … 417 434 pj_gettimeofday(&now); 418 435 PJ_LOG(3, (inv->pool->obj_name, 419 "No session refreshreceived after %ds "436 "No session %s received after %ds " 420 437 "(expiration period=%ds), stopping session now!", 438 (as_refresher?"refresh response":"refresh"), 421 439 (now.sec-inv->timer->last_refresh.sec), 422 440 inv->timer->setting.sess_expires)); 441 423 442 } 424 443 … … 428 447 /* Send message, if any */ 429 448 if (tdata && status == PJ_SUCCESS) { 430 status = pjsip_inv_send_msg(inv, tdata); 449 inv->timer->refresh_tdata = tdata; 450 451 status = pjsip_inv_send_msg(inv, tdata); 431 452 } 432 453 … … 434 455 if (status != PJ_SUCCESS) { 435 456 PJ_PERROR(2, (inv->pool->obj_name, status, 436 "Error in %s session timer", 437 (as_refresher? "refreshing" : "terminating"))); 457 "Error in %s session timer", 458 ((as_refresher && entry->id != REFRESHER_EXPIRE_TIMER_ID)? 459 "refreshing" : "terminating"))); 438 460 } 439 461 } … … 467 489 (timer->refresher == TR_UAS && inv->timer->role == PJSIP_ROLE_UAS)) 468 490 { 491 /* Add refresher expire timer */ 492 pj_timer_entry_init(&timer->expire_timer, 493 REFRESHER_EXPIRE_TIMER_ID, /* id */ 494 inv, /* user data */ 495 timer_cb); /* callback */ 496 497 delay.sec = timer->setting.sess_expires; 498 /* Schedule the timer */ 499 pjsip_endpt_schedule_timer(inv->dlg->endpt, &timer->expire_timer, 500 &delay); 501 469 502 /* Next refresh, the delay is half of session expire */ 470 503 delay.sec = timer->setting.sess_expires / 2; … … 491 524 if (inv->timer->timer.id != 0) { 492 525 pjsip_endpt_cancel_timer(inv->dlg->endpt, &inv->timer->timer); 493 inv->timer->timer.id = 0; 526 inv->timer->timer.id = 0; 527 } 528 529 if (inv->timer->expire_timer.id != 0) { 530 pjsip_endpt_cancel_timer(inv->dlg->endpt, &inv->timer->expire_timer); 531 inv->timer->expire_timer.id = 0; 494 532 } 495 533 } … … 710 748 return PJ_SUCCESS; 711 749 } 712 750 713 751 if (msg->line.status.code == PJSIP_SC_SESSION_TIMER_TOO_SMALL) { 714 752 /* Our Session-Expires is too small, let's update it based on … … 887 925 inv->timer->with_sdp = PJ_TRUE; 888 926 timer_cb(NULL, &inv->timer->timer); 927 } 928 } 929 930 return PJ_SUCCESS; 931 } 932 933 PJ_DEF(pj_status_t) pjsip_timer_handle_refresh_error( 934 pjsip_inv_session *inv, 935 pjsip_event *event) 936 { 937 PJ_ASSERT_RETURN(inv && event, PJ_EINVAL); 938 939 /* Check if Session Timers is supported */ 940 if ((inv->options & PJSIP_INV_SUPPORT_TIMER) == 0) 941 return PJ_SUCCESS; 942 943 pj_assert(is_initialized); 944 945 if (inv->timer && inv->timer->active) { 946 pj_bool_t as_refresher; 947 948 /* Check our role */ 949 as_refresher = ((inv->timer->refresher == TR_UAC) && 950 (inv->timer->role == PJSIP_ROLE_UAC)) || 951 ((inv->timer->refresher == TR_UAS) && 952 (inv->timer->role == PJSIP_ROLE_UAS)); 953 954 955 if ((as_refresher) && (event->type == PJSIP_EVENT_TSX_STATE) && 956 (inv->timer->refresh_tdata == event->body.tsx_state.tsx->last_tx)) 957 { 958 pjsip_status_code st_code; 959 pjsip_tx_data *bye; 960 pj_status_t status; 961 962 st_code = 963 (pjsip_status_code)event->body.tsx_state.tsx->status_code; 964 965 PJ_LOG(3, (inv->pool->obj_name, 966 "Receive error %d for refresh request %.*s/cseq=%d, " 967 "stopping session now", st_code, 968 event->body.tsx_state.tsx->method.name.slen, 969 event->body.tsx_state.tsx->method.name.ptr, 970 event->body.tsx_state.tsx->cseq)); 971 972 status = pjsip_inv_end_session(inv, 973 event->body.tsx_state.tsx->status_code, 974 pjsip_get_status_text(st_code), 975 &bye); 976 977 if (status == PJ_SUCCESS && bye) 978 status = pjsip_inv_send_msg(inv, bye); 979 889 980 } 890 981 }
Note: See TracChangeset
for help on using the changeset viewer.