Changeset 201 for pjproject/trunk/pjsip/src/pjsip-ua/sip_reg.c
- Timestamp:
- Feb 19, 2006 3:37:19 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsip-ua/sip_reg.c
r167 r201 26 26 #include <pjsip/sip_auth_msg.h> 27 27 #include <pjsip/sip_errno.h> 28 #include <pj/assert.h> 29 #include <pj/guid.h> 30 #include <pj/os.h> 28 31 #include <pj/pool.h> 32 #include <pj/log.h> 29 33 #include <pj/string.h> 30 #include <pj/guid.h>31 #include <pj/log.h>32 #include <pj/assert.h>33 34 34 35 … … 54 55 pjsip_cid_hdr *cid_hdr; 55 56 pjsip_cseq_hdr *cseq_hdr; 57 pj_str_t from_uri; 56 58 pjsip_from_hdr *from_hdr; 57 59 pjsip_to_hdr *to_hdr; … … 69 71 /* Auto refresh registration. */ 70 72 pj_bool_t auto_reg; 73 pj_time_val last_reg; 74 pj_time_val next_reg; 71 75 pj_timer_entry timer; 72 76 }; … … 111 115 PJ_DEF(pj_status_t) pjsip_regc_destroy(pjsip_regc *regc) 112 116 { 117 PJ_ASSERT_RETURN(regc, PJ_EINVAL); 118 113 119 if (regc->pending_tsx) { 114 120 regc->_delete_flag = 1; … … 116 122 } else { 117 123 pjsip_endpt_release_pool(regc->endpt, regc->pool); 124 } 125 126 return PJ_SUCCESS; 127 } 128 129 130 PJ_DEF(pj_status_t) pjsip_regc_get_info( pjsip_regc *regc, 131 pjsip_regc_info *info ) 132 { 133 PJ_ASSERT_RETURN(regc && info, PJ_EINVAL); 134 135 info->server_uri = regc->str_srv_url; 136 info->client_uri = regc->from_uri; 137 info->is_busy = (regc->pending_tsx != 0); 138 info->auto_reg = regc->auto_reg; 139 info->interval = regc->expires; 140 141 if (regc->pending_tsx) 142 info->next_reg = 0; 143 else if (regc->auto_reg == 0) 144 info->next_reg = 0; 145 else if (regc->expires < 0) 146 info->next_reg = regc->expires; 147 else { 148 pj_time_val now, next_reg; 149 150 next_reg = regc->next_reg; 151 pj_gettimeofday(&now); 152 PJ_TIME_VAL_SUB(next_reg, now); 153 info->next_reg = next_reg.sec; 118 154 } 119 155 … … 195 231 196 232 /* Set "From" header. */ 197 pj_strdup_with_null(regc->pool, &tmp, from_url); 233 pj_strdup_with_null(regc->pool, ®c->from_uri, from_url); 234 tmp = regc->from_uri; 198 235 regc->from_hdr = pjsip_from_hdr_create(regc->pool); 199 236 regc->from_hdr->uri = pjsip_parse_uri(regc->pool, tmp.ptr, tmp.slen, … … 326 363 pjsip_tx_data *tdata; 327 364 365 PJ_ASSERT_RETURN(regc && p_tdata, PJ_EINVAL); 366 328 367 status = create_request(regc, &tdata); 329 368 if (status != PJ_SUCCESS) … … 356 395 pj_status_t status; 357 396 397 PJ_ASSERT_RETURN(regc && p_tdata, PJ_EINVAL); 398 358 399 if (regc->timer.id != 0) { 359 400 pjsip_endpt_cancel_timer(regc->endpt, ®c->timer); … … 378 419 const pj_str_t contact[] ) 379 420 { 421 PJ_ASSERT_RETURN(regc, PJ_EINVAL); 380 422 return set_contact( regc, contact_cnt, contact ); 381 423 } … … 385 427 pj_uint32_t expires ) 386 428 { 429 PJ_ASSERT_RETURN(regc, PJ_EINVAL); 387 430 set_expires( regc, expires ); 388 431 return PJ_SUCCESS; … … 390 433 391 434 392 static void call_callback(pjsip_regc *regc, int status, const pj_str_t *reason, 435 static void call_callback(pjsip_regc *regc, pj_status_t status, int st_code, 436 const pj_str_t *reason, 393 437 pjsip_rx_data *rdata, pj_int32_t expiration, 394 438 int contact_cnt, pjsip_contact_hdr *contact[]) … … 399 443 cbparam.regc = regc; 400 444 cbparam.token = regc->token; 401 cbparam.code = status; 445 cbparam.status = status; 446 cbparam.code = st_code; 402 447 cbparam.reason = *reason; 403 448 cbparam.rdata = rdata; … … 428 473 char errmsg[PJ_ERR_MSG_SIZE]; 429 474 pj_str_t reason = pj_strerror(status, errmsg, sizeof(errmsg)); 430 call_callback(regc, -1, &reason, NULL, -1, 0, NULL);475 call_callback(regc, status, 400, &reason, NULL, -1, 0, NULL); 431 476 } 432 477 } … … 438 483 pjsip_transaction *tsx = event->body.tsx_state.tsx; 439 484 485 /* Decrement pending transaction counter. */ 486 --regc->pending_tsx; 487 440 488 /* If registration data has been deleted by user then remove registration 441 489 * data from transaction's callback, and don't call callback. 442 490 */ 443 491 if (regc->_delete_flag) { 444 --regc->pending_tsx; 492 493 /* Nothing to do */ 494 ; 445 495 446 496 } else if (tsx->status_code == PJSIP_SC_PROXY_AUTHENTICATION_REQUIRED || … … 456 506 457 507 if (status == PJ_SUCCESS) { 458 --regc->pending_tsx;459 508 pjsip_regc_send(regc, tdata); 460 509 return; 461 510 } else { 462 call_callback(regc, tsx->status_code, &rdata->msg_info.msg->line.status.reason, 511 call_callback(regc, status, tsx->status_code, 512 &rdata->msg_info.msg->line.status.reason, 463 513 rdata, -1, 0, NULL); 464 --regc->pending_tsx;465 514 } 466 515 } else { … … 513 562 regc->timer.user_data = regc; 514 563 pjsip_endpt_schedule_timer( regc->endpt, ®c->timer, &delay); 564 pj_gettimeofday(®c->last_reg); 565 regc->next_reg = regc->last_reg; 566 regc->next_reg.sec += delay.sec; 515 567 } 516 568 … … 523 575 /* Call callback. */ 524 576 if (expiration == 0xFFFF) expiration = -1; 525 call_callback(regc, tsx->status_code,577 call_callback(regc, PJ_SUCCESS, tsx->status_code, 526 578 (rdata ? &rdata->msg_info.msg->line.status.reason 527 579 : pjsip_get_status_text(tsx->status_code)), … … 529 581 contact_cnt, contact); 530 582 531 --regc->pending_tsx;532 583 } 533 584 … … 544 595 /* Make sure we don't have pending transaction. */ 545 596 if (regc->pending_tsx) { 546 pj_str_t reason = pj_str("Transaction in progress");547 call_callback(regc, -1, &reason, NULL, -1, 0, NULL);548 597 pjsip_tx_data_dec_ref( tdata ); 549 return PJ _EINVALIDOP;598 return PJSIP_EBUSY; 550 599 } 551 600 … … 560 609 if (status==PJ_SUCCESS) 561 610 ++regc->pending_tsx; 562 else {563 char errmsg[PJ_ERR_MSG_SIZE];564 pj_str_t reason = pj_strerror(status, errmsg, sizeof(errmsg));565 call_callback(regc, status, &reason, NULL, -1, 0, NULL);566 }567 611 568 612 return status;
Note: See TracChangeset
for help on using the changeset viewer.