- Timestamp:
- Sep 11, 2007 9:04:51 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsip-ua/sip_reg.c
r1417 r1431 66 66 pjsip_from_hdr *from_hdr; 67 67 pjsip_to_hdr *to_hdr; 68 char *contact_buf; 69 pjsip_generic_string_hdr *contact_hdr; 68 pjsip_hdr contact_hdr_list; 70 69 pjsip_expires_hdr *expires_hdr; 71 70 pjsip_contact_hdr *unreg_contact_hdr; … … 110 109 regc->token = token; 111 110 regc->cb = cb; 112 regc->contact_buf = (char*)pj_pool_alloc(pool, PJSIP_REGC_CONTACT_BUF_SIZE);113 111 regc->expires = PJSIP_REGC_EXPIRATION_NOT_SPECIFIED; 114 112 … … 119 117 pj_list_init(®c->route_set); 120 118 pj_list_init(®c->hdr_list); 119 pj_list_init(®c->contact_hdr_list); 121 120 122 121 /* Done */ … … 191 190 const pj_str_t contact[] ) 192 191 { 192 const pj_str_t CONTACT = { "Contact", 7 }; 193 193 int i; 194 char *s; 195 const pj_str_t contact_STR = { "Contact", 7}; 196 197 /* Concatenate contacts. */ 198 for (i=0, s=regc->contact_buf; i<contact_cnt; ++i) { 199 if ((s-regc->contact_buf) + contact[i].slen + 2 > PJSIP_REGC_CONTACT_BUF_SIZE) { 200 return PJSIP_EURITOOLONG; 194 195 /* Clear existing contacts */ 196 pj_list_init(®c->contact_hdr_list); 197 198 for (i=0; i<contact_cnt; ++i) { 199 pjsip_hdr *hdr; 200 pj_str_t tmp; 201 202 pj_strdup_with_null(regc->pool, &tmp, &contact[i]); 203 hdr = pjsip_parse_hdr(regc->pool, &CONTACT, tmp.ptr, tmp.slen, NULL); 204 if (hdr == NULL) { 205 PJ_LOG(4,(THIS_FILE, "Invalid Contact URI: \"%.*s\"", 206 (int)tmp.slen, tmp.ptr)); 207 return PJSIP_EINVALIDURI; 201 208 } 202 pj_memcpy(s, contact[i].ptr, contact[i].slen); 203 s += contact[i].slen; 204 205 if (i != contact_cnt - 1) { 206 *s++ = ','; 207 *s++ = ' '; 208 } 209 } 210 211 /* Set "Contact" header. */ 212 regc->contact_hdr = pjsip_generic_string_hdr_create(regc->pool, 213 &contact_STR, 214 NULL); 215 regc->contact_hdr->hvalue.ptr = regc->contact_buf; 216 regc->contact_hdr->hvalue.slen = (s - regc->contact_buf); 209 210 pj_list_push_back(®c->contact_hdr_list, hdr); 211 } 217 212 218 213 return PJ_SUCCESS; … … 425 420 { 426 421 pjsip_msg *msg; 422 pjsip_hdr *hdr; 427 423 pj_status_t status; 428 424 pjsip_tx_data *tdata; … … 434 430 return status; 435 431 436 /* Add Contact header. */437 432 msg = tdata->msg; 438 pjsip_msg_add_hdr(msg, (pjsip_hdr*) 439 pjsip_hdr_shallow_clone(tdata->pool, 440 regc->contact_hdr)); 433 434 /* Add Contact headers. */ 435 hdr = regc->contact_hdr_list.next; 436 while (hdr != ®c->contact_hdr_list) { 437 pjsip_msg_add_hdr(msg, (pjsip_hdr*) 438 pjsip_hdr_shallow_clone(tdata->pool, hdr)); 439 hdr = hdr->next; 440 } 441 441 442 if (regc->expires_hdr) 442 443 pjsip_msg_add_hdr(msg, (pjsip_hdr*) … … 462 463 pjsip_tx_data *tdata; 463 464 pjsip_msg *msg; 465 pjsip_hdr *hdr; 464 466 pj_status_t status; 465 467 … … 476 478 477 479 msg = tdata->msg; 478 pjsip_msg_add_hdr(msg, (pjsip_hdr*) 479 pjsip_hdr_shallow_clone(tdata->pool, 480 regc->contact_hdr)); 480 481 /* Add Contact headers. */ 482 hdr = regc->contact_hdr_list.next; 483 while (hdr != ®c->contact_hdr_list) { 484 pjsip_msg_add_hdr(msg, (pjsip_hdr*) 485 pjsip_hdr_shallow_clone(tdata->pool, hdr)); 486 hdr = hdr->next; 487 } 488 481 489 pjsip_msg_add_hdr( msg, (pjsip_hdr*)regc->unreg_expires_hdr); 482 490 … … 681 689 for (i=0; i<contact_cnt; ++i) { 682 690 hdr = contact[i]; 683 if (hdr->expires >= 0 && hdr->expires < expiration) 684 expiration = contact[i]->expires; 691 if (hdr->expires >= 0 && hdr->expires < expiration) { 692 pjsip_contact_hdr *our_contact; 693 694 our_contact = (pjsip_contact_hdr*) 695 regc->contact_hdr_list.next; 696 if ((void*)our_contact==(void*)®c->contact_hdr_list.next) 697 continue; 698 699 /* Only set expiration time if this is the same Contact 700 * that we register. 701 */ 702 if (pjsip_uri_cmp(PJSIP_URI_IN_CONTACT_HDR, 703 hdr->uri, 704 our_contact->uri)==0) 705 { 706 expiration = contact[i]->expires; 707 } 708 } 685 709 } 686 710
Note: See TracChangeset
for help on using the changeset viewer.