| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <pjsip-ua/sip_regc.h> |
| 20 |
#include <pjsip/sip_endpoint.h> |
| 21 |
#include <pjsip/sip_parser.h> |
| 22 |
#include <pjsip/sip_module.h> |
| 23 |
#include <pjsip/sip_transaction.h> |
| 24 |
#include <pjsip/sip_event.h> |
| 25 |
#include <pjsip/sip_util.h> |
| 26 |
#include <pjsip/sip_auth_msg.h> |
| 27 |
#include <pjsip/sip_errno.h> |
| 28 |
#include <pj/assert.h> |
| 29 |
#include <pj/guid.h> |
| 30 |
#include <pj/lock.h> |
| 31 |
#include <pj/os.h> |
| 32 |
#include <pj/pool.h> |
| 33 |
#include <pj/log.h> |
| 34 |
#include <pj/rand.h> |
| 35 |
#include <pj/string.h> |
| 36 |
|
| 37 |
|
| 38 |
#define REFRESH_TIMER 1 |
| 39 |
#define DELAY_BEFORE_REFRESH PJSIP_REGISTER_CLIENT_DELAY_BEFORE_REFRESH |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
#define MIN_REFRESH_MSEC 500 |
| 45 |
#define THIS_FILE "sip_reg.c" |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
#define REGC_TSX_TIMEOUT 33000 |
| 51 |
|
| 52 |
#define NOEXP PJSIP_REGC_EXPIRATION_NOT_SPECIFIED |
| 53 |
|
| 54 |
static const pj_str_t XUID_PARAM_NAME = { "x-uid", 5 }; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
enum regc_op |
| 59 |
{ |
| 60 |
REGC_IDLE, |
| 61 |
REGC_REGISTERING, |
| 62 |
REGC_UNREGISTERING |
| 63 |
}; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
struct pjsip_regc |
| 69 |
{ |
| 70 |
pj_pool_t *pool; |
| 71 |
pjsip_endpoint *endpt; |
| 72 |
pj_lock_t *lock; |
| 73 |
pj_bool_t _delete_flag; |
| 74 |
pj_bool_t has_tsx; |
| 75 |
pj_atomic_t *busy_ctr; |
| 76 |
enum regc_op current_op; |
| 77 |
|
| 78 |
pj_bool_t add_xuid_param; |
| 79 |
|
| 80 |
void *token; |
| 81 |
pjsip_regc_cb *cb; |
| 82 |
pjsip_regc_tsx_cb *tsx_cb; |
| 83 |
|
| 84 |
pj_str_t str_srv_url; |
| 85 |
pjsip_uri *srv_url; |
| 86 |
pjsip_cid_hdr *cid_hdr; |
| 87 |
pjsip_cseq_hdr *cseq_hdr; |
| 88 |
pj_str_t from_uri; |
| 89 |
pjsip_from_hdr *from_hdr; |
| 90 |
pjsip_to_hdr *to_hdr; |
| 91 |
pjsip_contact_hdr contact_hdr_list; |
| 92 |
pjsip_contact_hdr removed_contact_hdr_list; |
| 93 |
pjsip_expires_hdr *expires_hdr; |
| 94 |
pj_uint32_t expires; |
| 95 |
pj_uint32_t expires_requested; |
| 96 |
pj_uint32_t delay_before_refresh; |
| 97 |
pjsip_route_hdr route_set; |
| 98 |
pjsip_hdr hdr_list; |
| 99 |
pjsip_host_port via_addr; |
| 100 |
const void *via_tp; |
| 101 |
|
| 102 |
|
| 103 |
pjsip_auth_clt_sess auth_sess; |
| 104 |
|
| 105 |
|
| 106 |
pj_bool_t auto_reg; |
| 107 |
pj_time_val last_reg; |
| 108 |
pj_time_val next_reg; |
| 109 |
pj_timer_entry timer; |
| 110 |
|
| 111 |
|
| 112 |
pjsip_tpselector tp_sel; |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
pjsip_transport *last_transport; |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
pjsip_transport *info_transport; |
| 123 |
}; |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
static pj_status_t async_auth_send_impl(pjsip_auth_clt_sess *auth_sess, |
| 128 |
void *user_data, |
| 129 |
pjsip_tx_data *tdata); |
| 130 |
|
| 131 |
|
| 132 |
static void async_auth_abandon_impl(pjsip_auth_clt_sess *auth_sess, |
| 133 |
void *user_data); |
| 134 |
|
| 135 |
|
| 136 |
PJ_DEF(pj_status_t) pjsip_regc_create( pjsip_endpoint *endpt, void *token, |
| 137 |
pjsip_regc_cb *cb, |
| 138 |
pjsip_regc **p_regc) |
| 139 |
{ |
| 140 |
pj_pool_t *pool; |
| 141 |
pjsip_regc *regc; |
| 142 |
pj_status_t status; |
| 143 |
|
| 144 |
|
| 145 |
PJ_ASSERT_RETURN(endpt && cb && p_regc, PJ_EINVAL); |
| 146 |
|
| 147 |
pool = pjsip_endpt_create_pool(endpt, "regc%p", 1024, 1024); |
| 148 |
PJ_ASSERT_RETURN(pool != NULL, PJ_ENOMEM); |
| 149 |
|
| 150 |
regc = PJ_POOL_ZALLOC_T(pool, pjsip_regc); |
| 151 |
|
| 152 |
regc->pool = pool; |
| 153 |
regc->endpt = endpt; |
| 154 |
regc->token = token; |
| 155 |
regc->cb = cb; |
| 156 |
regc->expires = PJSIP_REGC_EXPIRATION_NOT_SPECIFIED; |
| 157 |
regc->add_xuid_param = pjsip_cfg()->regc.add_xuid_param; |
| 158 |
|
| 159 |
status = pj_lock_create_recursive_mutex(pool, pool->obj_name, |
| 160 |
®c->lock); |
| 161 |
if (status != PJ_SUCCESS) { |
| 162 |
pj_pool_release(pool); |
| 163 |
return status; |
| 164 |
} |
| 165 |
|
| 166 |
status = pj_atomic_create(pool, 0, ®c->busy_ctr); |
| 167 |
if (status != PJ_SUCCESS) { |
| 168 |
pj_lock_destroy(regc->lock); |
| 169 |
pj_pool_release(pool); |
| 170 |
return status; |
| 171 |
} |
| 172 |
|
| 173 |
status = pjsip_auth_clt_init(®c->auth_sess, endpt, regc->pool, 0); |
| 174 |
if (status != PJ_SUCCESS) |
| 175 |
return status; |
| 176 |
|
| 177 |
pj_list_init(®c->route_set); |
| 178 |
pj_list_init(®c->hdr_list); |
| 179 |
pj_list_init(®c->contact_hdr_list); |
| 180 |
pj_list_init(®c->removed_contact_hdr_list); |
| 181 |
|
| 182 |
|
| 183 |
*p_regc = regc; |
| 184 |
return PJ_SUCCESS; |
| 185 |
} |
| 186 |
|
| 187 |
PJ_DEF(pj_status_t) pjsip_regc_destroy(pjsip_regc *regc) |
| 188 |
{ |
| 189 |
return pjsip_regc_destroy2(regc, PJ_TRUE); |
| 190 |
} |
| 191 |
|
| 192 |
PJ_DEF(pj_status_t) pjsip_regc_destroy2(pjsip_regc *regc, pj_bool_t force) |
| 193 |
{ |
| 194 |
PJ_ASSERT_RETURN(regc, PJ_EINVAL); |
| 195 |
|
| 196 |
pj_lock_acquire(regc->lock); |
| 197 |
|
| 198 |
if (!force && regc->has_tsx) { |
| 199 |
pj_lock_release(regc->lock); |
| 200 |
return PJ_EBUSY; |
| 201 |
} |
| 202 |
|
| 203 |
if (regc->has_tsx || pj_atomic_get(regc->busy_ctr) != 0) { |
| 204 |
regc->_delete_flag = 1; |
| 205 |
regc->cb = NULL; |
| 206 |
pj_lock_release(regc->lock); |
| 207 |
} else { |
| 208 |
pjsip_tpselector_dec_ref(®c->tp_sel); |
| 209 |
if (regc->last_transport) { |
| 210 |
pjsip_transport_dec_ref(regc->last_transport); |
| 211 |
regc->last_transport = NULL; |
| 212 |
} |
| 213 |
if (regc->timer.id != 0) { |
| 214 |
pjsip_endpt_cancel_timer(regc->endpt, ®c->timer); |
| 215 |
regc->timer.id = 0; |
| 216 |
} |
| 217 |
pj_atomic_destroy(regc->busy_ctr); |
| 218 |
pj_lock_release(regc->lock); |
| 219 |
pj_lock_destroy(regc->lock); |
| 220 |
regc->lock = NULL; |
| 221 |
|
| 222 |
pjsip_auth_clt_deinit(®c->auth_sess); |
| 223 |
pjsip_endpt_release_pool(regc->endpt, regc->pool); |
| 224 |
} |
| 225 |
|
| 226 |
return PJ_SUCCESS; |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
PJ_DEF(pj_status_t) pjsip_regc_get_info( pjsip_regc *regc, |
| 231 |
pjsip_regc_info *info ) |
| 232 |
{ |
| 233 |
PJ_ASSERT_RETURN(regc && info, PJ_EINVAL); |
| 234 |
|
| 235 |
pj_lock_acquire(regc->lock); |
| 236 |
|
| 237 |
info->server_uri = regc->str_srv_url; |
| 238 |
info->client_uri = regc->from_uri; |
| 239 |
info->is_busy = (pj_atomic_get(regc->busy_ctr) || regc->has_tsx); |
| 240 |
info->auto_reg = regc->auto_reg; |
| 241 |
info->interval = regc->expires; |
| 242 |
info->transport = regc->has_tsx? regc->info_transport : |
| 243 |
regc->last_transport; |
| 244 |
|
| 245 |
if (regc->has_tsx) |
| 246 |
info->next_reg = 0; |
| 247 |
else if (regc->auto_reg == 0) |
| 248 |
info->next_reg = 0; |
| 249 |
else if (regc->expires == PJSIP_REGC_EXPIRATION_NOT_SPECIFIED) |
| 250 |
info->next_reg = regc->expires; |
| 251 |
else { |
| 252 |
pj_time_val now, next_reg; |
| 253 |
|
| 254 |
next_reg = regc->next_reg; |
| 255 |
pj_gettimeofday(&now); |
| 256 |
if (PJ_TIME_VAL_GT(next_reg, now)) { |
| 257 |
PJ_TIME_VAL_SUB(next_reg, now); |
| 258 |
info->next_reg = next_reg.sec; |
| 259 |
} else { |
| 260 |
info->next_reg = 0; |
| 261 |
} |
| 262 |
} |
| 263 |
|
| 264 |
pj_lock_release(regc->lock); |
| 265 |
|
| 266 |
return PJ_SUCCESS; |
| 267 |
} |
| 268 |
|
| 269 |
|
| 270 |
PJ_DEF(pj_pool_t*) pjsip_regc_get_pool(pjsip_regc *regc) |
| 271 |
{ |
| 272 |
return regc->pool; |
| 273 |
} |
| 274 |
|
| 275 |
static void set_expires( pjsip_regc *regc, pj_uint32_t expires) |
| 276 |
{ |
| 277 |
if (expires != regc->expires) { |
| 278 |
regc->expires_hdr = pjsip_expires_hdr_create(regc->pool, expires); |
| 279 |
} else { |
| 280 |
regc->expires_hdr = NULL; |
| 281 |
} |
| 282 |
} |
| 283 |
|
| 284 |
|
| 285 |
static pj_status_t set_contact( pjsip_regc *regc, |
| 286 |
int contact_cnt, |
| 287 |
const pj_str_t contact[] ) |
| 288 |
{ |
| 289 |
const pj_str_t CONTACT = { "Contact", 7 }; |
| 290 |
pjsip_contact_hdr *h; |
| 291 |
int i; |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
pj_list_merge_last(®c->removed_contact_hdr_list, |
| 297 |
®c->contact_hdr_list); |
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
h = regc->removed_contact_hdr_list.next; |
| 303 |
while (h != ®c->removed_contact_hdr_list) { |
| 304 |
h->expires = 0; |
| 305 |
h = h->next; |
| 306 |
} |
| 307 |
|
| 308 |
|
| 309 |
for (i=0; i<contact_cnt; ++i) { |
| 310 |
pjsip_contact_hdr *hdr; |
| 311 |
pj_str_t tmp; |
| 312 |
|
| 313 |
pj_strdup_with_null(regc->pool, &tmp, &contact[i]); |
| 314 |
hdr = (pjsip_contact_hdr*) |
| 315 |
pjsip_parse_hdr(regc->pool, &CONTACT, tmp.ptr, tmp.slen, NULL); |
| 316 |
if (hdr == NULL) { |
| 317 |
PJ_LOG(4,(THIS_FILE, "Invalid Contact: \"%.*s\"", |
| 318 |
(int)tmp.slen, tmp.ptr)); |
| 319 |
return PJSIP_EINVALIDURI; |
| 320 |
} |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
h = regc->removed_contact_hdr_list.next; |
| 326 |
while (h != ®c->removed_contact_hdr_list) { |
| 327 |
int rc; |
| 328 |
|
| 329 |
rc = pjsip_uri_cmp(PJSIP_URI_IN_CONTACT_HDR, |
| 330 |
h->uri, hdr->uri); |
| 331 |
if (rc == 0) { |
| 332 |
|
| 333 |
pj_list_erase(h); |
| 334 |
break; |
| 335 |
} |
| 336 |
|
| 337 |
h = h->next; |
| 338 |
} |
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
if (regc->add_xuid_param && (PJSIP_URI_SCHEME_IS_SIP(hdr->uri) || |
| 345 |
PJSIP_URI_SCHEME_IS_SIPS(hdr->uri))) |
| 346 |
{ |
| 347 |
pjsip_param *xuid_param; |
| 348 |
pjsip_sip_uri *sip_uri; |
| 349 |
|
| 350 |
xuid_param = PJ_POOL_ZALLOC_T(regc->pool, pjsip_param); |
| 351 |
xuid_param->name = XUID_PARAM_NAME; |
| 352 |
pj_create_unique_string(regc->pool, &xuid_param->value); |
| 353 |
|
| 354 |
sip_uri = (pjsip_sip_uri*) pjsip_uri_get_uri(hdr->uri); |
| 355 |
pj_list_push_back(&sip_uri->other_param, xuid_param); |
| 356 |
} |
| 357 |
|
| 358 |
pj_list_push_back(®c->contact_hdr_list, hdr); |
| 359 |
} |
| 360 |
|
| 361 |
return PJ_SUCCESS; |
| 362 |
} |
| 363 |
|
| 364 |
|
| 365 |
PJ_DEF(pj_status_t) pjsip_regc_init( pjsip_regc *regc, |
| 366 |
const pj_str_t *srv_url, |
| 367 |
const pj_str_t *from_url, |
| 368 |
const pj_str_t *to_url, |
| 369 |
int contact_cnt, |
| 370 |
const pj_str_t contact[], |
| 371 |
pj_uint32_t expires) |
| 372 |
{ |
| 373 |
pj_str_t tmp; |
| 374 |
pj_status_t status; |
| 375 |
|
| 376 |
PJ_ASSERT_RETURN(regc && srv_url && from_url && to_url && |
| 377 |
expires, PJ_EINVAL); |
| 378 |
|
| 379 |
|
| 380 |
pj_strdup_with_null(regc->pool, ®c->str_srv_url, srv_url); |
| 381 |
|
| 382 |
|
| 383 |
tmp = regc->str_srv_url; |
| 384 |
regc->srv_url = pjsip_parse_uri( regc->pool, tmp.ptr, tmp.slen, 0); |
| 385 |
if (regc->srv_url == NULL) { |
| 386 |
return PJSIP_EINVALIDURI; |
| 387 |
} |
| 388 |
|
| 389 |
|
| 390 |
pj_strdup_with_null(regc->pool, ®c->from_uri, from_url); |
| 391 |
tmp = regc->from_uri; |
| 392 |
regc->from_hdr = pjsip_from_hdr_create(regc->pool); |
| 393 |
regc->from_hdr->uri = pjsip_parse_uri(regc->pool, tmp.ptr, tmp.slen, |
| 394 |
PJSIP_PARSE_URI_AS_NAMEADDR); |
| 395 |
if (!regc->from_hdr->uri) { |
| 396 |
PJ_LOG(4,(THIS_FILE, "regc: invalid source URI %.*s", |
| 397 |
(int)from_url->slen, from_url->ptr)); |
| 398 |
return PJSIP_EINVALIDURI; |
| 399 |
} |
| 400 |
|
| 401 |
|
| 402 |
pj_strdup_with_null(regc->pool, &tmp, to_url); |
| 403 |
regc->to_hdr = pjsip_to_hdr_create(regc->pool); |
| 404 |
regc->to_hdr->uri = pjsip_parse_uri(regc->pool, tmp.ptr, tmp.slen, |
| 405 |
PJSIP_PARSE_URI_AS_NAMEADDR); |
| 406 |
if (!regc->to_hdr->uri) { |
| 407 |
PJ_LOG(4,(THIS_FILE, "regc: invalid target URI %.*s", |
| 408 |
(int)to_url->slen, to_url->ptr)); |
| 409 |
return PJSIP_EINVALIDURI; |
| 410 |
} |
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
status = set_contact( regc, contact_cnt, contact); |
| 415 |
if (status != PJ_SUCCESS) |
| 416 |
return status; |
| 417 |
|
| 418 |
|
| 419 |
set_expires( regc, expires); |
| 420 |
regc->delay_before_refresh = DELAY_BEFORE_REFRESH; |
| 421 |
|
| 422 |
|
| 423 |
regc->cid_hdr = pjsip_cid_hdr_create(regc->pool); |
| 424 |
pj_create_unique_string(regc->pool, ®c->cid_hdr->id); |
| 425 |
|
| 426 |
|
| 427 |
regc->cseq_hdr = pjsip_cseq_hdr_create(regc->pool); |
| 428 |
regc->cseq_hdr->cseq = pj_rand() % 0xFFFF; |
| 429 |
pjsip_method_set( ®c->cseq_hdr->method, PJSIP_REGISTER_METHOD); |
| 430 |
|
| 431 |
|
| 432 |
return PJ_SUCCESS; |
| 433 |
} |
| 434 |
|
| 435 |
PJ_DEF(void) pjsip_regc_add_ref( pjsip_regc *regc ) |
| 436 |
{ |
| 437 |
pj_assert(regc); |
| 438 |
pj_atomic_inc(regc->busy_ctr); |
| 439 |
} |
| 440 |
|
| 441 |
PJ_DEF(pj_status_t) pjsip_regc_dec_ref( pjsip_regc *regc ) |
| 442 |
{ |
| 443 |
pj_assert(regc); |
| 444 |
if (pj_atomic_dec_and_get(regc->busy_ctr)==0 && regc->_delete_flag) { |
| 445 |
pjsip_regc_destroy(regc); |
| 446 |
return PJ_EGONE; |
| 447 |
} |
| 448 |
|
| 449 |
return PJ_SUCCESS; |
| 450 |
} |
| 451 |
|
| 452 |
PJ_DEF(pj_status_t) pjsip_regc_set_credentials( pjsip_regc *regc, |
| 453 |
int count, |
| 454 |
const pjsip_cred_info cred[] ) |
| 455 |
{ |
| 456 |
PJ_ASSERT_RETURN(regc && count && cred, PJ_EINVAL); |
| 457 |
return pjsip_auth_clt_set_credentials(®c->auth_sess, count, cred); |
| 458 |
} |
| 459 |
|
| 460 |
PJ_DEF(pj_status_t) pjsip_regc_set_prefs( pjsip_regc *regc, |
| 461 |
const pjsip_auth_clt_pref *pref) |
| 462 |
{ |
| 463 |
PJ_ASSERT_RETURN(regc && pref, PJ_EINVAL); |
| 464 |
return pjsip_auth_clt_set_prefs(®c->auth_sess, pref); |
| 465 |
} |
| 466 |
|
| 467 |
PJ_DEF(pj_status_t) pjsip_regc_set_route_set( pjsip_regc *regc, |
| 468 |
const pjsip_route_hdr *route_set) |
| 469 |
{ |
| 470 |
const pjsip_route_hdr *chdr; |
| 471 |
|
| 472 |
PJ_ASSERT_RETURN(regc && route_set, PJ_EINVAL); |
| 473 |
|
| 474 |
pj_list_init(®c->route_set); |
| 475 |
|
| 476 |
chdr = route_set->next; |
| 477 |
while (chdr != route_set) { |
| 478 |
pj_list_push_back(®c->route_set, pjsip_hdr_clone(regc->pool, chdr)); |
| 479 |
chdr = chdr->next; |
| 480 |
} |
| 481 |
|
| 482 |
return PJ_SUCCESS; |
| 483 |
} |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
PJ_DEF(pj_status_t) pjsip_regc_set_transport( pjsip_regc *regc, |
| 490 |
const pjsip_tpselector *sel) |
| 491 |
{ |
| 492 |
PJ_ASSERT_RETURN(regc && sel, PJ_EINVAL); |
| 493 |
|
| 494 |
pjsip_tpselector_dec_ref(®c->tp_sel); |
| 495 |
pj_memcpy(®c->tp_sel, sel, sizeof(*sel)); |
| 496 |
pjsip_tpselector_add_ref(®c->tp_sel); |
| 497 |
|
| 498 |
return PJ_SUCCESS; |
| 499 |
} |
| 500 |
|
| 501 |
|
| 502 |
PJ_DEF(pj_status_t) pjsip_regc_release_transport(pjsip_regc *regc) |
| 503 |
{ |
| 504 |
PJ_ASSERT_RETURN(regc, PJ_EINVAL); |
| 505 |
if (regc->last_transport) { |
| 506 |
pjsip_transport_dec_ref(regc->last_transport); |
| 507 |
regc->last_transport = NULL; |
| 508 |
} |
| 509 |
if (regc->info_transport) { |
| 510 |
regc->info_transport = NULL; |
| 511 |
} |
| 512 |
return PJ_SUCCESS; |
| 513 |
} |
| 514 |
|
| 515 |
|
| 516 |
PJ_DEF(pj_status_t) pjsip_regc_add_headers( pjsip_regc *regc, |
| 517 |
const pjsip_hdr *hdr_list) |
| 518 |
{ |
| 519 |
const pjsip_hdr *hdr; |
| 520 |
|
| 521 |
PJ_ASSERT_RETURN(regc && hdr_list, PJ_EINVAL); |
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
hdr = hdr_list->next; |
| 527 |
while (hdr != hdr_list) { |
| 528 |
pj_list_push_back(®c->hdr_list, pjsip_hdr_clone(regc->pool, hdr)); |
| 529 |
hdr = hdr->next; |
| 530 |
} |
| 531 |
|
| 532 |
return PJ_SUCCESS; |
| 533 |
} |
| 534 |
|
| 535 |
static pj_status_t create_request(pjsip_regc *regc, |
| 536 |
pjsip_tx_data **p_tdata) |
| 537 |
{ |
| 538 |
pj_status_t status; |
| 539 |
pjsip_tx_data *tdata; |
| 540 |
|
| 541 |
PJ_ASSERT_RETURN(regc && p_tdata, PJ_EINVAL); |
| 542 |
|
| 543 |
|
| 544 |
status = pjsip_endpt_create_request_from_hdr( regc->endpt, |
| 545 |
pjsip_get_register_method(), |
| 546 |
regc->srv_url, |
| 547 |
regc->from_hdr, |
| 548 |
regc->to_hdr, |
| 549 |
NULL, |
| 550 |
regc->cid_hdr, |
| 551 |
regc->cseq_hdr->cseq, |
| 552 |
NULL, |
| 553 |
&tdata); |
| 554 |
if (status != PJ_SUCCESS) |
| 555 |
return status; |
| 556 |
|
| 557 |
|
| 558 |
pjsip_auth_clt_init_req( ®c->auth_sess, tdata ); |
| 559 |
|
| 560 |
|
| 561 |
if (!pj_list_empty(®c->route_set)) { |
| 562 |
pjsip_hdr *route_pos; |
| 563 |
const pjsip_route_hdr *route; |
| 564 |
|
| 565 |
route_pos = (pjsip_hdr*) |
| 566 |
pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL); |
| 567 |
if (!route_pos) |
| 568 |
route_pos = &tdata->msg->hdr; |
| 569 |
|
| 570 |
route = regc->route_set.next; |
| 571 |
while (route != ®c->route_set) { |
| 572 |
pjsip_hdr *new_hdr = (pjsip_hdr*) |
| 573 |
pjsip_hdr_clone(tdata->pool, route); |
| 574 |
pj_list_insert_after(route_pos, new_hdr); |
| 575 |
route_pos = new_hdr; |
| 576 |
route = route->next; |
| 577 |
} |
| 578 |
} |
| 579 |
|
| 580 |
|
| 581 |
if (!pj_list_empty(®c->hdr_list)) { |
| 582 |
const pjsip_hdr *hdr; |
| 583 |
|
| 584 |
hdr = regc->hdr_list.next; |
| 585 |
while (hdr != ®c->hdr_list) { |
| 586 |
pjsip_hdr *new_hdr = (pjsip_hdr*) |
| 587 |
pjsip_hdr_clone(tdata->pool, hdr); |
| 588 |
pjsip_msg_add_hdr(tdata->msg, new_hdr); |
| 589 |
hdr = hdr->next; |
| 590 |
} |
| 591 |
} |
| 592 |
|
| 593 |
|
| 594 |
*p_tdata = tdata; |
| 595 |
return PJ_SUCCESS; |
| 596 |
} |
| 597 |
|
| 598 |
|
| 599 |
PJ_DEF(pj_status_t) pjsip_regc_register(pjsip_regc *regc, pj_bool_t autoreg, |
| 600 |
pjsip_tx_data **p_tdata) |
| 601 |
{ |
| 602 |
pjsip_msg *msg; |
| 603 |
pjsip_contact_hdr *hdr; |
| 604 |
const pjsip_hdr *h_allow; |
| 605 |
pj_status_t status; |
| 606 |
pjsip_tx_data *tdata; |
| 607 |
|
| 608 |
PJ_ASSERT_RETURN(regc && p_tdata, PJ_EINVAL); |
| 609 |
|
| 610 |
pj_lock_acquire(regc->lock); |
| 611 |
|
| 612 |
regc->expires_requested = 1; |
| 613 |
|
| 614 |
status = create_request(regc, &tdata); |
| 615 |
if (status != PJ_SUCCESS) { |
| 616 |
pj_lock_release(regc->lock); |
| 617 |
return status; |
| 618 |
} |
| 619 |
|
| 620 |
msg = tdata->msg; |
| 621 |
|
| 622 |
|
| 623 |
hdr = regc->contact_hdr_list.next; |
| 624 |
while (hdr != ®c->contact_hdr_list) { |
| 625 |
pjsip_msg_add_hdr(msg, (pjsip_hdr*) |
| 626 |
pjsip_hdr_clone(tdata->pool, hdr)); |
| 627 |
hdr = hdr->next; |
| 628 |
} |
| 629 |
|
| 630 |
|
| 631 |
while (!pj_list_empty(®c->removed_contact_hdr_list)) { |
| 632 |
hdr = regc->removed_contact_hdr_list.next; |
| 633 |
pjsip_msg_add_hdr(msg, (pjsip_hdr*) |
| 634 |
pjsip_hdr_clone(tdata->pool, hdr)); |
| 635 |
pj_list_erase(hdr); |
| 636 |
} |
| 637 |
|
| 638 |
|
| 639 |
if (regc->expires_hdr) |
| 640 |
pjsip_msg_add_hdr(msg, (pjsip_hdr*) |
| 641 |
pjsip_hdr_clone(tdata->pool, |
| 642 |
regc->expires_hdr)); |
| 643 |
|
| 644 |
if (regc->timer.id != 0) { |
| 645 |
pjsip_endpt_cancel_timer(regc->endpt, ®c->timer); |
| 646 |
regc->timer.id = 0; |
| 647 |
} |
| 648 |
|
| 649 |
|
| 650 |
h_allow = pjsip_endpt_get_capability(regc->endpt, PJSIP_H_ALLOW, NULL); |
| 651 |
if (h_allow) { |
| 652 |
pjsip_msg_add_hdr(msg, (pjsip_hdr*) |
| 653 |
pjsip_hdr_clone(tdata->pool, h_allow)); |
| 654 |
|
| 655 |
} |
| 656 |
|
| 657 |
regc->auto_reg = autoreg; |
| 658 |
|
| 659 |
pj_lock_release(regc->lock); |
| 660 |
|
| 661 |
|
| 662 |
*p_tdata = tdata; |
| 663 |
return PJ_SUCCESS; |
| 664 |
} |
| 665 |
|
| 666 |
|
| 667 |
PJ_DEF(pj_status_t) pjsip_regc_unregister(pjsip_regc *regc, |
| 668 |
pjsip_tx_data **p_tdata) |
| 669 |
{ |
| 670 |
pjsip_tx_data *tdata; |
| 671 |
pjsip_msg *msg; |
| 672 |
pjsip_hdr *hdr; |
| 673 |
pj_status_t status; |
| 674 |
|
| 675 |
PJ_ASSERT_RETURN(regc && p_tdata, PJ_EINVAL); |
| 676 |
|
| 677 |
pj_lock_acquire(regc->lock); |
| 678 |
|
| 679 |
if (regc->timer.id != 0) { |
| 680 |
pjsip_endpt_cancel_timer(regc->endpt, ®c->timer); |
| 681 |
regc->timer.id = 0; |
| 682 |
} |
| 683 |
|
| 684 |
regc->expires_requested = 0; |
| 685 |
|
| 686 |
status = create_request(regc, &tdata); |
| 687 |
if (status != PJ_SUCCESS) { |
| 688 |
pj_lock_release(regc->lock); |
| 689 |
return status; |
| 690 |
} |
| 691 |
|
| 692 |
msg = tdata->msg; |
| 693 |
|
| 694 |
|
| 695 |
hdr = (pjsip_hdr*)regc->contact_hdr_list.next; |
| 696 |
while ((void*)hdr != (void*)®c->contact_hdr_list) { |
| 697 |
pjsip_msg_add_hdr(msg, (pjsip_hdr*) |
| 698 |
pjsip_hdr_clone(tdata->pool, hdr)); |
| 699 |
hdr = hdr->next; |
| 700 |
} |
| 701 |
|
| 702 |
|
| 703 |
while (!pj_list_empty(®c->removed_contact_hdr_list)) { |
| 704 |
hdr = (pjsip_hdr*)regc->removed_contact_hdr_list.next; |
| 705 |
pjsip_msg_add_hdr(msg, (pjsip_hdr*) |
| 706 |
pjsip_hdr_clone(tdata->pool, hdr)); |
| 707 |
pj_list_erase(hdr); |
| 708 |
} |
| 709 |
|
| 710 |
|
| 711 |
hdr = (pjsip_hdr*) pjsip_expires_hdr_create(tdata->pool, 0); |
| 712 |
pjsip_msg_add_hdr(msg, hdr); |
| 713 |
|
| 714 |
pj_lock_release(regc->lock); |
| 715 |
|
| 716 |
*p_tdata = tdata; |
| 717 |
return PJ_SUCCESS; |
| 718 |
} |
| 719 |
|
| 720 |
PJ_DEF(pj_status_t) pjsip_regc_unregister_all(pjsip_regc *regc, |
| 721 |
pjsip_tx_data **p_tdata) |
| 722 |
{ |
| 723 |
pjsip_tx_data *tdata; |
| 724 |
pjsip_contact_hdr *hcontact; |
| 725 |
pjsip_hdr *hdr; |
| 726 |
pjsip_msg *msg; |
| 727 |
pj_status_t status; |
| 728 |
|
| 729 |
PJ_ASSERT_RETURN(regc && p_tdata, PJ_EINVAL); |
| 730 |
|
| 731 |
pj_lock_acquire(regc->lock); |
| 732 |
|
| 733 |
if (regc->timer.id != 0) { |
| 734 |
pjsip_endpt_cancel_timer(regc->endpt, ®c->timer); |
| 735 |
regc->timer.id = 0; |
| 736 |
} |
| 737 |
|
| 738 |
status = create_request(regc, &tdata); |
| 739 |
if (status != PJ_SUCCESS) { |
| 740 |
pj_lock_release(regc->lock); |
| 741 |
return status; |
| 742 |
} |
| 743 |
|
| 744 |
msg = tdata->msg; |
| 745 |
|
| 746 |
|
| 747 |
pj_list_init(®c->removed_contact_hdr_list); |
| 748 |
|
| 749 |
|
| 750 |
hcontact = pjsip_contact_hdr_create(tdata->pool); |
| 751 |
hcontact->star = 1; |
| 752 |
pjsip_msg_add_hdr(msg, (pjsip_hdr*)hcontact); |
| 753 |
|
| 754 |
|
| 755 |
hdr = (pjsip_hdr*) pjsip_expires_hdr_create(tdata->pool, 0); |
| 756 |
pjsip_msg_add_hdr(msg, hdr); |
| 757 |
|
| 758 |
pj_lock_release(regc->lock); |
| 759 |
|
| 760 |
*p_tdata = tdata; |
| 761 |
return PJ_SUCCESS; |
| 762 |
} |
| 763 |
|
| 764 |
|
| 765 |
PJ_DEF(pj_status_t) pjsip_regc_update_contact( pjsip_regc *regc, |
| 766 |
int contact_cnt, |
| 767 |
const pj_str_t contact[] ) |
| 768 |
{ |
| 769 |
pj_status_t status; |
| 770 |
|
| 771 |
PJ_ASSERT_RETURN(regc, PJ_EINVAL); |
| 772 |
|
| 773 |
pj_lock_acquire(regc->lock); |
| 774 |
status = set_contact( regc, contact_cnt, contact ); |
| 775 |
pj_lock_release(regc->lock); |
| 776 |
|
| 777 |
return status; |
| 778 |
} |
| 779 |
|
| 780 |
|
| 781 |
PJ_DEF(pj_status_t) pjsip_regc_update_expires( pjsip_regc *regc, |
| 782 |
pj_uint32_t expires ) |
| 783 |
{ |
| 784 |
PJ_ASSERT_RETURN(regc, PJ_EINVAL); |
| 785 |
|
| 786 |
pj_lock_acquire(regc->lock); |
| 787 |
set_expires( regc, expires ); |
| 788 |
pj_lock_release(regc->lock); |
| 789 |
|
| 790 |
return PJ_SUCCESS; |
| 791 |
} |
| 792 |
|
| 793 |
static void cbparam_init( struct pjsip_regc_cbparam *cbparam, |
| 794 |
pjsip_regc *regc, |
| 795 |
pj_status_t status, int st_code, |
| 796 |
const pj_str_t *reason, |
| 797 |
pjsip_rx_data *rdata, pj_uint32_t expiration, |
| 798 |
int contact_cnt, pjsip_contact_hdr *contact[], |
| 799 |
pj_bool_t is_unreg) |
| 800 |
{ |
| 801 |
cbparam->regc = regc; |
| 802 |
cbparam->token = regc->token; |
| 803 |
cbparam->status = status; |
| 804 |
cbparam->code = st_code; |
| 805 |
cbparam->reason = *reason; |
| 806 |
cbparam->rdata = rdata; |
| 807 |
cbparam->contact_cnt = contact_cnt; |
| 808 |
cbparam->expiration = (expiration != PJSIP_REGC_EXPIRATION_NOT_SPECIFIED? |
| 809 |
expiration: regc->expires_requested); |
| 810 |
cbparam->is_unreg = is_unreg; |
| 811 |
if (contact_cnt) { |
| 812 |
pj_memcpy( cbparam->contact, contact, |
| 813 |
contact_cnt*sizeof(pjsip_contact_hdr*)); |
| 814 |
} |
| 815 |
} |
| 816 |
|
| 817 |
static void call_callback(pjsip_regc *regc, pj_status_t status, int st_code, |
| 818 |
const pj_str_t *reason, |
| 819 |
pjsip_rx_data *rdata, pj_uint32_t expiration, |
| 820 |
int contact_cnt, pjsip_contact_hdr *contact[], |
| 821 |
pj_bool_t is_unreg) |
| 822 |
{ |
| 823 |
struct pjsip_regc_cbparam cbparam; |
| 824 |
|
| 825 |
if (!regc->cb) |
| 826 |
return; |
| 827 |
|
| 828 |
cbparam_init(&cbparam, regc, status, st_code, reason, rdata, expiration, |
| 829 |
contact_cnt, contact, is_unreg); |
| 830 |
(*regc->cb)(&cbparam); |
| 831 |
} |
| 832 |
|
| 833 |
static void regc_refresh_timer_cb( pj_timer_heap_t *timer_heap, |
| 834 |
struct pj_timer_entry *entry) |
| 835 |
{ |
| 836 |
pjsip_regc *regc = (pjsip_regc*) entry->user_data; |
| 837 |
pjsip_tx_data *tdata; |
| 838 |
pj_status_t status; |
| 839 |
|
| 840 |
PJ_UNUSED_ARG(timer_heap); |
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
pjsip_regc_add_ref(regc); |
| 846 |
|
| 847 |
entry->id = 0; |
| 848 |
status = pjsip_regc_register(regc, 1, &tdata); |
| 849 |
if (status == PJ_SUCCESS) { |
| 850 |
status = pjsip_regc_send(regc, tdata); |
| 851 |
} |
| 852 |
|
| 853 |
if (status != PJ_SUCCESS && regc->cb) { |
| 854 |
char errmsg[PJ_ERR_MSG_SIZE]; |
| 855 |
pj_str_t reason = pj_strerror(status, errmsg, sizeof(errmsg)); |
| 856 |
call_callback(regc, status, 400, &reason, NULL, NOEXP, 0, NULL, |
| 857 |
PJ_FALSE); |
| 858 |
} |
| 859 |
|
| 860 |
|
| 861 |
pjsip_regc_dec_ref(regc); |
| 862 |
} |
| 863 |
|
| 864 |
static void schedule_registration ( pjsip_regc *regc, pj_uint32_t expiration ) |
| 865 |
{ |
| 866 |
if (regc->auto_reg && expiration > 0 && expiration != NOEXP) { |
| 867 |
const pj_time_val min_delay = {MIN_REFRESH_MSEC / 1000, |
| 868 |
MIN_REFRESH_MSEC % 1000}; |
| 869 |
pj_time_val delay = {0, 0}; |
| 870 |
|
| 871 |
pj_timer_heap_cancel_if_active(pjsip_endpt_get_timer_heap(regc->endpt), |
| 872 |
®c->timer, 0); |
| 873 |
|
| 874 |
|
| 875 |
if (expiration > regc->delay_before_refresh) { |
| 876 |
delay.sec = expiration - regc->delay_before_refresh; |
| 877 |
} |
| 878 |
if (regc->expires != PJSIP_REGC_EXPIRATION_NOT_SPECIFIED && |
| 879 |
delay.sec > (pj_int32_t)regc->expires) { |
| 880 |
delay.sec = regc->expires; |
| 881 |
} |
| 882 |
if (delay.sec < DELAY_BEFORE_REFRESH) { |
| 883 |
if (expiration <= DELAY_BEFORE_REFRESH) { |
| 884 |
|
| 885 |
delay.sec = (expiration > 1) ? (long)expiration - 1 : 0; |
| 886 |
delay.msec = (expiration > 1) ? 0 : 500; |
| 887 |
} else { |
| 888 |
delay.sec = DELAY_BEFORE_REFRESH; |
| 889 |
} |
| 890 |
} |
| 891 |
|
| 892 |
|
| 893 |
if (PJ_TIME_VAL_LT(delay, min_delay)) { |
| 894 |
delay = min_delay; |
| 895 |
} |
| 896 |
regc->timer.cb = ®c_refresh_timer_cb; |
| 897 |
regc->timer.id = REFRESH_TIMER; |
| 898 |
regc->timer.user_data = regc; |
| 899 |
pjsip_endpt_schedule_timer( regc->endpt, ®c->timer, &delay); |
| 900 |
pj_gettimeofday(®c->last_reg); |
| 901 |
regc->next_reg = regc->last_reg; |
| 902 |
PJ_TIME_VAL_ADD(regc->next_reg, delay); |
| 903 |
} |
| 904 |
} |
| 905 |
|
| 906 |
PJ_DEF(pj_status_t) pjsip_regc_set_reg_tsx_cb( pjsip_regc *regc, |
| 907 |
pjsip_regc_tsx_cb *tsx_cb) |
| 908 |
{ |
| 909 |
PJ_ASSERT_RETURN(regc, PJ_EINVAL); |
| 910 |
regc->tsx_cb = tsx_cb; |
| 911 |
return PJ_SUCCESS; |
| 912 |
} |
| 913 |
|
| 914 |
|
| 915 |
PJ_DEF(pj_status_t) pjsip_regc_set_via_sent_by( pjsip_regc *regc, |
| 916 |
pjsip_host_port *via_addr, |
| 917 |
pjsip_transport *via_tp) |
| 918 |
{ |
| 919 |
PJ_ASSERT_RETURN(regc, PJ_EINVAL); |
| 920 |
|
| 921 |
if (!via_addr) |
| 922 |
pj_bzero(®c->via_addr, sizeof(regc->via_addr)); |
| 923 |
else { |
| 924 |
if (pj_strcmp(®c->via_addr.host, &via_addr->host)) |
| 925 |
pj_strdup(regc->pool, ®c->via_addr.host, &via_addr->host); |
| 926 |
regc->via_addr.port = via_addr->port; |
| 927 |
} |
| 928 |
regc->via_tp = via_tp; |
| 929 |
|
| 930 |
return PJ_SUCCESS; |
| 931 |
} |
| 932 |
|
| 933 |
PJ_DEF(pj_status_t) |
| 934 |
pjsip_regc_set_delay_before_refresh( pjsip_regc *regc, |
| 935 |
pj_uint32_t delay ) |
| 936 |
{ |
| 937 |
PJ_ASSERT_RETURN(regc, PJ_EINVAL); |
| 938 |
|
| 939 |
if (delay > regc->expires) |
| 940 |
return PJ_ETOOBIG; |
| 941 |
|
| 942 |
pj_lock_acquire(regc->lock); |
| 943 |
|
| 944 |
if (regc->delay_before_refresh != delay) |
| 945 |
{ |
| 946 |
regc->delay_before_refresh = delay; |
| 947 |
|
| 948 |
if (regc->timer.id != 0) { |
| 949 |
|
| 950 |
pjsip_endpt_cancel_timer(regc->endpt, ®c->timer); |
| 951 |
regc->timer.id = 0; |
| 952 |
|
| 953 |
|
| 954 |
schedule_registration(regc, regc->expires); |
| 955 |
} |
| 956 |
} |
| 957 |
|
| 958 |
pj_lock_release(regc->lock); |
| 959 |
|
| 960 |
return PJ_SUCCESS; |
| 961 |
} |
| 962 |
|
| 963 |
|
| 964 |
static pj_uint32_t calculate_response_expiration(const pjsip_regc *regc, |
| 965 |
const pjsip_rx_data *rdata, |
| 966 |
unsigned *contact_cnt, |
| 967 |
unsigned max_contact, |
| 968 |
pjsip_contact_hdr *contacts[]) |
| 969 |
{ |
| 970 |
pj_uint32_t expiration = NOEXP; |
| 971 |
const pjsip_msg *msg = rdata->msg_info.msg; |
| 972 |
const pjsip_hdr *hdr; |
| 973 |
|
| 974 |
|
| 975 |
*contact_cnt = 0; |
| 976 |
for (hdr=msg->hdr.next; hdr!=&msg->hdr; hdr=hdr->next) { |
| 977 |
if (hdr->type == PJSIP_H_CONTACT && |
| 978 |
*contact_cnt < max_contact) |
| 979 |
{ |
| 980 |
contacts[*contact_cnt] = (pjsip_contact_hdr*)hdr; |
| 981 |
++(*contact_cnt); |
| 982 |
} |
| 983 |
} |
| 984 |
|
| 985 |
if (regc->current_op == REGC_REGISTERING) { |
| 986 |
pj_bool_t has_our_contact = PJ_FALSE; |
| 987 |
const pjsip_expires_hdr *expires; |
| 988 |
|
| 989 |
|
| 990 |
expires = (const pjsip_expires_hdr*) |
| 991 |
pjsip_msg_find_hdr(msg, PJSIP_H_EXPIRES, NULL); |
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
if (pjsip_cfg()->regc.check_contact || regc->add_xuid_param) { |
| 998 |
unsigned i; |
| 999 |
for (i=0; i<*contact_cnt; ++i) { |
| 1000 |
const pjsip_contact_hdr *our_hdr; |
| 1001 |
|
| 1002 |
our_hdr = (const pjsip_contact_hdr*) |
| 1003 |
regc->contact_hdr_list.next; |
| 1004 |
|
| 1005 |
|
| 1006 |
while ((void*)our_hdr != (void*)®c->contact_hdr_list) { |
| 1007 |
|
| 1008 |
const pjsip_uri *uri1, *uri2; |
| 1009 |
pj_bool_t matched = PJ_FALSE; |
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
uri1 = (const pjsip_uri*) |
| 1015 |
pjsip_uri_get_uri(contacts[i]->uri); |
| 1016 |
uri2 = (const pjsip_uri*) |
| 1017 |
pjsip_uri_get_uri(our_hdr->uri); |
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
if (pjsip_cfg()->regc.check_contact) { |
| 1023 |
matched = pjsip_uri_cmp(PJSIP_URI_IN_CONTACT_HDR, |
| 1024 |
uri1, uri2)==0; |
| 1025 |
} |
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
if (!matched && regc->add_xuid_param && |
| 1031 |
(PJSIP_URI_SCHEME_IS_SIP(uri1) || |
| 1032 |
PJSIP_URI_SCHEME_IS_SIPS(uri1)) && |
| 1033 |
(PJSIP_URI_SCHEME_IS_SIP(uri2) || |
| 1034 |
PJSIP_URI_SCHEME_IS_SIPS(uri2))) |
| 1035 |
{ |
| 1036 |
const pjsip_sip_uri *sip_uri1, *sip_uri2; |
| 1037 |
const pjsip_param *p1, *p2; |
| 1038 |
|
| 1039 |
sip_uri1 = (const pjsip_sip_uri*)uri1; |
| 1040 |
sip_uri2 = (const pjsip_sip_uri*)uri2; |
| 1041 |
|
| 1042 |
p1 = pjsip_param_cfind(&sip_uri1->other_param, |
| 1043 |
&XUID_PARAM_NAME); |
| 1044 |
p2 = pjsip_param_cfind(&sip_uri2->other_param, |
| 1045 |
&XUID_PARAM_NAME); |
| 1046 |
matched = p1 && p2 && |
| 1047 |
pj_strcmp(&p1->value, &p2->value)==0; |
| 1048 |
|
| 1049 |
} |
| 1050 |
|
| 1051 |
if (matched) { |
| 1052 |
has_our_contact = PJ_TRUE; |
| 1053 |
|
| 1054 |
if (contacts[i]->expires != PJSIP_EXPIRES_NOT_SPECIFIED |
| 1055 |
&& contacts[i]->expires < expiration) |
| 1056 |
{ |
| 1057 |
|
| 1058 |
expiration = contacts[i]->expires; |
| 1059 |
} |
| 1060 |
|
| 1061 |
break; |
| 1062 |
} |
| 1063 |
|
| 1064 |
our_hdr = our_hdr->next; |
| 1065 |
|
| 1066 |
} |
| 1067 |
|
| 1068 |
} |
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
if (has_our_contact && expiration == NOEXP) { |
| 1077 |
if (expires) { |
| 1078 |
expiration = expires->ivalue; |
| 1079 |
} else if (regc->expires_hdr) { |
| 1080 |
expiration = regc->expires_hdr->ivalue; |
| 1081 |
} else { |
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
expiration = 3600; |
| 1088 |
} |
| 1089 |
} |
| 1090 |
|
| 1091 |
} |
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
if (expiration==NOEXP) { |
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
pj_size_t our_contact_cnt; |
| 1105 |
|
| 1106 |
our_contact_cnt = pj_list_size(®c->contact_hdr_list); |
| 1107 |
|
| 1108 |
if (*contact_cnt == our_contact_cnt && *contact_cnt && |
| 1109 |
contacts[0]->expires != PJSIP_EXPIRES_NOT_SPECIFIED) |
| 1110 |
{ |
| 1111 |
expiration = contacts[0]->expires; |
| 1112 |
} else if (expires) |
| 1113 |
expiration = expires->ivalue; |
| 1114 |
else if (regc->expires_hdr) |
| 1115 |
expiration = regc->expires_hdr->ivalue; |
| 1116 |
else |
| 1117 |
expiration = 3600; |
| 1118 |
} |
| 1119 |
|
| 1120 |
} else { |
| 1121 |
|
| 1122 |
expiration = 0; |
| 1123 |
} |
| 1124 |
|
| 1125 |
|
| 1126 |
pj_assert(expiration != NOEXP); |
| 1127 |
|
| 1128 |
return expiration; |
| 1129 |
} |
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
static pj_status_t async_auth_send_impl(pjsip_auth_clt_sess *auth_sess, |
| 1134 |
void *user_data, |
| 1135 |
pjsip_tx_data *tdata) |
| 1136 |
{ |
| 1137 |
pj_status_t status; |
| 1138 |
pjsip_regc *regc = (pjsip_regc*)user_data; |
| 1139 |
|
| 1140 |
PJ_UNUSED_ARG(auth_sess); |
| 1141 |
|
| 1142 |
status = pjsip_regc_send(regc, tdata); |
| 1143 |
if (status != PJ_SUCCESS) { |
| 1144 |
char errmsg[PJ_ERR_MSG_SIZE]; |
| 1145 |
pj_bool_t is_unreg = (regc->current_op == REGC_UNREGISTERING); |
| 1146 |
pj_str_t reason = pj_strerror(status, errmsg, sizeof(errmsg)); |
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
call_callback(regc, status, 0, &reason, NULL, NOEXP, 0, NULL, |
| 1154 |
is_unreg); |
| 1155 |
} |
| 1156 |
|
| 1157 |
return status; |
| 1158 |
} |
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
static void async_auth_abandon_impl(pjsip_auth_clt_sess *auth_sess, |
| 1163 |
void *user_data) |
| 1164 |
{ |
| 1165 |
pjsip_regc *regc = (pjsip_regc*)user_data; |
| 1166 |
pj_bool_t is_unreg = (regc->current_op == REGC_UNREGISTERING); |
| 1167 |
pj_str_t reason = { "Authentication abandoned", 24 }; |
| 1168 |
|
| 1169 |
PJ_UNUSED_ARG(auth_sess); |
| 1170 |
|
| 1171 |
|
| 1172 |
call_callback(regc, PJ_ECANCELLED, PJSIP_SC_UNAUTHORIZED, &reason, |
| 1173 |
NULL, NOEXP, 0, NULL, is_unreg); |
| 1174 |
} |
| 1175 |
|
| 1176 |
|
| 1177 |
static void regc_tsx_callback(void *token, pjsip_event *event) |
| 1178 |
{ |
| 1179 |
pj_status_t status; |
| 1180 |
pjsip_regc *regc = (pjsip_regc*) token; |
| 1181 |
pjsip_transaction *tsx = event->body.tsx_state.tsx; |
| 1182 |
pj_bool_t handled = PJ_TRUE; |
| 1183 |
pj_bool_t update_contact = PJ_FALSE; |
| 1184 |
|
| 1185 |
pjsip_regc_add_ref(regc); |
| 1186 |
pj_lock_acquire(regc->lock); |
| 1187 |
|
| 1188 |
|
| 1189 |
pj_assert(regc->has_tsx); |
| 1190 |
regc->has_tsx = PJ_FALSE; |
| 1191 |
|
| 1192 |
|
| 1193 |
if (tsx->transport != regc->last_transport) { |
| 1194 |
if (regc->last_transport) { |
| 1195 |
pjsip_transport_dec_ref(regc->last_transport); |
| 1196 |
regc->last_transport = NULL; |
| 1197 |
} |
| 1198 |
|
| 1199 |
if (tsx->transport) { |
| 1200 |
regc->last_transport = tsx->transport; |
| 1201 |
pjsip_transport_add_ref(regc->last_transport); |
| 1202 |
} |
| 1203 |
} |
| 1204 |
|
| 1205 |
if (regc->_delete_flag == 0 && regc->tsx_cb && |
| 1206 |
regc->current_op == REGC_REGISTERING) |
| 1207 |
{ |
| 1208 |
struct pjsip_regc_tsx_cb_param param; |
| 1209 |
|
| 1210 |
param.contact_cnt = -1; |
| 1211 |
cbparam_init(¶m.cbparam, regc, PJ_SUCCESS, tsx->status_code, |
| 1212 |
&tsx->status_text, |
| 1213 |
(event->body.tsx_state.type==PJSIP_EVENT_RX_MSG) ? |
| 1214 |
event->body.tsx_state.src.rdata : NULL, |
| 1215 |
NOEXP, 0, NULL, PJ_FALSE); |
| 1216 |
|
| 1217 |
|
| 1218 |
pj_lock_release(regc->lock); |
| 1219 |
(*regc->tsx_cb)(¶m); |
| 1220 |
pj_lock_acquire(regc->lock); |
| 1221 |
|
| 1222 |
if (param.contact_cnt >= 0) { |
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
if (tsx->status_code/100 != 2) { |
| 1229 |
pjsip_contact_hdr *h; |
| 1230 |
|
| 1231 |
h = regc->contact_hdr_list.next; |
| 1232 |
while (h != ®c->contact_hdr_list) { |
| 1233 |
pjsip_contact_hdr *next = h->next; |
| 1234 |
|
| 1235 |
if (h->expires == PJSIP_EXPIRES_NOT_SPECIFIED) { |
| 1236 |
pj_list_erase(h); |
| 1237 |
} |
| 1238 |
h = next; |
| 1239 |
} |
| 1240 |
} |
| 1241 |
|
| 1242 |
|
| 1243 |
pjsip_regc_update_contact(regc, param.contact_cnt, param.contact); |
| 1244 |
update_contact = PJ_TRUE; |
| 1245 |
} |
| 1246 |
} |
| 1247 |
|
| 1248 |
|
| 1249 |
if (tsx->status_code == PJSIP_SC_PROXY_AUTHENTICATION_REQUIRED || |
| 1250 |
tsx->status_code == PJSIP_SC_UNAUTHORIZED) |
| 1251 |
{ |
| 1252 |
pjsip_rx_data *rdata = event->body.tsx_state.src.rdata; |
| 1253 |
pjsip_tx_data *tdata; |
| 1254 |
pj_bool_t is_unreg; |
| 1255 |
pjsip_auth_clt_async_on_chal_param chal_param = { 0 }; |
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
is_unreg = (regc->current_op == REGC_UNREGISTERING); |
| 1263 |
|
| 1264 |
if (update_contact) { |
| 1265 |
pjsip_msg *msg; |
| 1266 |
pjsip_hdr *hdr, *ins_hdr; |
| 1267 |
pjsip_contact_hdr *chdr; |
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
msg = tsx->last_tx->msg; |
| 1274 |
hdr = msg->hdr.next; |
| 1275 |
ins_hdr = &msg->hdr; |
| 1276 |
while (hdr != &msg->hdr) { |
| 1277 |
pjsip_hdr *next = hdr->next; |
| 1278 |
|
| 1279 |
if (hdr->type == PJSIP_H_CONTACT) { |
| 1280 |
chdr = (pjsip_contact_hdr *)hdr; |
| 1281 |
if (chdr->expires != 0) { |
| 1282 |
pj_list_erase(hdr); |
| 1283 |
ins_hdr = next; |
| 1284 |
} |
| 1285 |
} |
| 1286 |
hdr = next; |
| 1287 |
} |
| 1288 |
|
| 1289 |
|
| 1290 |
chdr = regc->contact_hdr_list.next; |
| 1291 |
while (chdr != ®c->contact_hdr_list) { |
| 1292 |
pj_list_insert_before(ins_hdr, (pjsip_hdr*) |
| 1293 |
pjsip_hdr_clone(tsx->last_tx->pool, chdr)); |
| 1294 |
chdr = chdr->next; |
| 1295 |
} |
| 1296 |
|
| 1297 |
|
| 1298 |
while (!pj_list_empty(®c->removed_contact_hdr_list)) { |
| 1299 |
chdr = regc->removed_contact_hdr_list.next; |
| 1300 |
pj_list_insert_before(ins_hdr, (pjsip_hdr*) |
| 1301 |
pjsip_hdr_clone(tsx->last_tx->pool, chdr)); |
| 1302 |
pj_list_erase(chdr); |
| 1303 |
} |
| 1304 |
} |
| 1305 |
|
| 1306 |
if (regc->_delete_flag != 0) { |
| 1307 |
pjsip_auth_clt_set_parent(®c->auth_sess, NULL); |
| 1308 |
} |
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
{ |
| 1318 |
pjsip_auth_clt_async_impl_token *auth_token; |
| 1319 |
auth_token = PJ_POOL_ZALLOC_T(tsx->pool, |
| 1320 |
pjsip_auth_clt_async_impl_token); |
| 1321 |
auth_token->user_data = regc; |
| 1322 |
auth_token->send_impl = &async_auth_send_impl; |
| 1323 |
auth_token->abandon_impl = &async_auth_abandon_impl; |
| 1324 |
auth_token->grp_lock = tsx->grp_lock; |
| 1325 |
pj_grp_lock_add_ref(tsx->grp_lock); |
| 1326 |
|
| 1327 |
pj_bzero(&chal_param, sizeof(chal_param)); |
| 1328 |
chal_param.rdata = rdata; |
| 1329 |
chal_param.tdata = tsx->last_tx; |
| 1330 |
pj_lock_release(regc->lock); |
| 1331 |
status = pjsip_auth_clt_async_impl_on_challenge( |
| 1332 |
®c->auth_sess, |
| 1333 |
auth_token, &chal_param); |
| 1334 |
pj_lock_acquire(regc->lock); |
| 1335 |
if (status != PJ_SUCCESS) |
| 1336 |
pj_grp_lock_dec_ref(tsx->grp_lock); |
| 1337 |
} |
| 1338 |
if (status != PJ_SUCCESS) { |
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
regc->current_op = REGC_IDLE; |
| 1344 |
|
| 1345 |
|
| 1346 |
status = pjsip_auth_clt_reinit_req( ®c->auth_sess, |
| 1347 |
rdata, |
| 1348 |
tsx->last_tx, |
| 1349 |
&tdata); |
| 1350 |
|
| 1351 |
|
| 1352 |
if (status == PJ_SUCCESS && tdata) { |
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
pj_lock_release(regc->lock); |
| 1359 |
status = pjsip_regc_send(regc, tdata); |
| 1360 |
pj_lock_acquire(regc->lock); |
| 1361 |
} |
| 1362 |
|
| 1363 |
if (status != PJ_SUCCESS) { |
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
if (regc->_delete_flag == 0) { |
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
pj_lock_release(regc->lock); |
| 1372 |
call_callback(regc, status, tsx->status_code, |
| 1373 |
&rdata->msg_info.msg->line.status.reason, |
| 1374 |
rdata, NOEXP, 0, NULL, is_unreg); |
| 1375 |
pj_lock_acquire(regc->lock); |
| 1376 |
} |
| 1377 |
} |
| 1378 |
} |
| 1379 |
|
| 1380 |
} else if (regc->_delete_flag) { |
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
regc->current_op = REGC_IDLE; |
| 1388 |
|
| 1389 |
} else if (tsx->status_code == PJSIP_SC_INTERVAL_TOO_BRIEF && |
| 1390 |
regc->current_op == REGC_REGISTERING) |
| 1391 |
{ |
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
pjsip_rx_data *rdata = event->body.tsx_state.src.rdata; |
| 1400 |
pjsip_min_expires_hdr *me_hdr; |
| 1401 |
pjsip_tx_data *tdata; |
| 1402 |
pj_uint32_t min_exp; |
| 1403 |
|
| 1404 |
|
| 1405 |
regc->current_op = REGC_IDLE; |
| 1406 |
|
| 1407 |
|
| 1408 |
me_hdr = (pjsip_min_expires_hdr*) |
| 1409 |
pjsip_msg_find_hdr(rdata->msg_info.msg, |
| 1410 |
PJSIP_H_MIN_EXPIRES, NULL); |
| 1411 |
if (me_hdr) { |
| 1412 |
min_exp = me_hdr->ivalue; |
| 1413 |
} else { |
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
enum { |
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
UNSPECIFIED_MIN_EXPIRES = 3601 |
| 1423 |
}; |
| 1424 |
if (!regc->expires_hdr || |
| 1425 |
regc->expires_hdr->ivalue != UNSPECIFIED_MIN_EXPIRES) |
| 1426 |
{ |
| 1427 |
min_exp = UNSPECIFIED_MIN_EXPIRES; |
| 1428 |
} else { |
| 1429 |
handled = PJ_FALSE; |
| 1430 |
PJ_LOG(4,(THIS_FILE, "Registration failed: 423 response " |
| 1431 |
"without Min-Expires header is invalid")); |
| 1432 |
goto handle_err; |
| 1433 |
} |
| 1434 |
} |
| 1435 |
|
| 1436 |
if (regc->expires_hdr && regc->expires_hdr->ivalue >= min_exp) { |
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
handled = PJ_FALSE; |
| 1441 |
PJ_LOG(4,(THIS_FILE, "Registration failed: invalid " |
| 1442 |
"Min-Expires header value in response")); |
| 1443 |
goto handle_err; |
| 1444 |
} |
| 1445 |
|
| 1446 |
set_expires(regc, min_exp); |
| 1447 |
|
| 1448 |
status = pjsip_regc_register(regc, regc->auto_reg, &tdata); |
| 1449 |
if (status == PJ_SUCCESS) { |
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
pj_lock_release(regc->lock); |
| 1456 |
status = pjsip_regc_send(regc, tdata); |
| 1457 |
pj_lock_acquire(regc->lock); |
| 1458 |
} |
| 1459 |
|
| 1460 |
if (status != PJ_SUCCESS) { |
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
if (!regc->_delete_flag) { |
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
pj_lock_release(regc->lock); |
| 1469 |
call_callback(regc, status, tsx->status_code, |
| 1470 |
&rdata->msg_info.msg->line.status.reason, |
| 1471 |
rdata, NOEXP, 0, NULL, PJ_FALSE); |
| 1472 |
pj_lock_acquire(regc->lock); |
| 1473 |
} |
| 1474 |
} |
| 1475 |
|
| 1476 |
} else { |
| 1477 |
handled = PJ_FALSE; |
| 1478 |
} |
| 1479 |
|
| 1480 |
handle_err: |
| 1481 |
if (!handled) { |
| 1482 |
pjsip_rx_data *rdata; |
| 1483 |
pj_uint32_t expiration = NOEXP; |
| 1484 |
unsigned contact_cnt = 0; |
| 1485 |
pjsip_contact_hdr *contact[PJSIP_REGC_MAX_CONTACT]; |
| 1486 |
pj_bool_t is_unreg; |
| 1487 |
|
| 1488 |
if (tsx->status_code/100 == 2) { |
| 1489 |
|
| 1490 |
rdata = event->body.tsx_state.src.rdata; |
| 1491 |
|
| 1492 |
|
| 1493 |
expiration = calculate_response_expiration(regc, rdata, |
| 1494 |
&contact_cnt, |
| 1495 |
PJSIP_REGC_MAX_CONTACT, |
| 1496 |
contact); |
| 1497 |
|
| 1498 |
#if PJSIP_REGISTER_ALLOW_EXP_REFRESH |
| 1499 |
if (expiration == 0 && regc->current_op != REGC_UNREGISTERING) { |
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
const pjsip_msg *msg = rdata->msg_info.msg; |
| 1505 |
const pjsip_expires_hdr *expires; |
| 1506 |
expires = (const pjsip_expires_hdr*) pjsip_msg_find_hdr(msg, |
| 1507 |
PJSIP_H_EXPIRES, NULL); |
| 1508 |
|
| 1509 |
if (expires) { |
| 1510 |
expiration = expires->ivalue; |
| 1511 |
} else if (regc->expires_hdr && regc->expires_hdr->ivalue) { |
| 1512 |
expiration = regc->expires_hdr->ivalue; |
| 1513 |
} else { |
| 1514 |
expiration = 3600; |
| 1515 |
} |
| 1516 |
PJ_LOG(4, (THIS_FILE, "Modify response's expiration from 0 " |
| 1517 |
"to %d", expiration)); |
| 1518 |
} |
| 1519 |
#endif |
| 1520 |
|
| 1521 |
schedule_registration(regc, expiration); |
| 1522 |
|
| 1523 |
} else { |
| 1524 |
rdata = (event->body.tsx_state.type==PJSIP_EVENT_RX_MSG) ? |
| 1525 |
event->body.tsx_state.src.rdata : NULL; |
| 1526 |
} |
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
regc->expires = expiration; |
| 1531 |
|
| 1532 |
|
| 1533 |
is_unreg = (regc->current_op == REGC_UNREGISTERING); |
| 1534 |
regc->current_op = REGC_IDLE; |
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
pj_lock_release(regc->lock); |
| 1541 |
call_callback(regc, PJ_SUCCESS, tsx->status_code, |
| 1542 |
(rdata ? &rdata->msg_info.msg->line.status.reason |
| 1543 |
: &tsx->status_text), |
| 1544 |
rdata, expiration, |
| 1545 |
contact_cnt, contact, is_unreg); |
| 1546 |
pj_lock_acquire(regc->lock); |
| 1547 |
} |
| 1548 |
|
| 1549 |
pj_lock_release(regc->lock); |
| 1550 |
|
| 1551 |
|
| 1552 |
pjsip_regc_dec_ref(regc); |
| 1553 |
} |
| 1554 |
|
| 1555 |
PJ_DEF(pj_status_t) pjsip_regc_send(pjsip_regc *regc, pjsip_tx_data *tdata) |
| 1556 |
{ |
| 1557 |
pj_status_t status; |
| 1558 |
pjsip_cseq_hdr *cseq_hdr; |
| 1559 |
pjsip_expires_hdr *expires_hdr; |
| 1560 |
pj_int32_t cseq; |
| 1561 |
|
| 1562 |
pjsip_regc_add_ref(regc); |
| 1563 |
pj_lock_acquire(regc->lock); |
| 1564 |
|
| 1565 |
|
| 1566 |
if (regc->has_tsx) { |
| 1567 |
PJ_LOG(4,(THIS_FILE, "Unable to send request, regc has another " |
| 1568 |
"transaction pending")); |
| 1569 |
pjsip_tx_data_dec_ref( tdata ); |
| 1570 |
pj_lock_release(regc->lock); |
| 1571 |
pj_atomic_dec(regc->busy_ctr); |
| 1572 |
return PJSIP_EBUSY; |
| 1573 |
} |
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
|
| 1582 |
|
| 1583 |
pjsip_tx_data_invalidate_msg(tdata); |
| 1584 |
|
| 1585 |
|
| 1586 |
cseq = ++regc->cseq_hdr->cseq; |
| 1587 |
cseq_hdr = (pjsip_cseq_hdr*) |
| 1588 |
pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CSEQ, NULL); |
| 1589 |
cseq_hdr->cseq = cseq; |
| 1590 |
|
| 1591 |
|
| 1592 |
expires_hdr = (pjsip_expires_hdr*) |
| 1593 |
pjsip_msg_find_hdr(tdata->msg, PJSIP_H_EXPIRES, NULL); |
| 1594 |
|
| 1595 |
|
| 1596 |
pjsip_tx_data_set_transport(tdata, ®c->tp_sel); |
| 1597 |
|
| 1598 |
regc->has_tsx = PJ_TRUE; |
| 1599 |
|
| 1600 |
|
| 1601 |
if (expires_hdr && expires_hdr->ivalue==0) |
| 1602 |
regc->current_op = REGC_UNREGISTERING; |
| 1603 |
else |
| 1604 |
regc->current_op = REGC_REGISTERING; |
| 1605 |
|
| 1606 |
if (expires_hdr && expires_hdr->ivalue) |
| 1607 |
regc->expires_requested = expires_hdr->ivalue; |
| 1608 |
|
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
pjsip_tx_data_add_ref(tdata); |
| 1613 |
|
| 1614 |
|
| 1615 |
if (regc->via_addr.host.slen > 0) { |
| 1616 |
tdata->via_addr = regc->via_addr; |
| 1617 |
tdata->via_tp = regc->via_tp; |
| 1618 |
} |
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
|
| 1623 |
|
| 1624 |
|
| 1625 |
pj_lock_release(regc->lock); |
| 1626 |
|
| 1627 |
|
| 1628 |
status = pjsip_endpt_send_request(regc->endpt, tdata, REGC_TSX_TIMEOUT, |
| 1629 |
regc, ®c_tsx_callback); |
| 1630 |
|
| 1631 |
|
| 1632 |
pj_lock_acquire(regc->lock); |
| 1633 |
|
| 1634 |
if (status!=PJ_SUCCESS) { |
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
if (cseq == regc->cseq_hdr->cseq) { |
| 1641 |
regc->has_tsx = PJ_FALSE; |
| 1642 |
} |
| 1643 |
|
| 1644 |
PJ_PERROR(4,(THIS_FILE, status, "Error sending request")); |
| 1645 |
} |
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
|
| 1650 |
|
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
|
| 1656 |
|
| 1657 |
|
| 1658 |
|
| 1659 |
|
| 1660 |
|
| 1661 |
|
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
|
| 1667 |
regc->info_transport = status==PJ_SUCCESS? tdata->tp_info.transport : |
| 1668 |
NULL; |
| 1669 |
|
| 1670 |
|
| 1671 |
pjsip_tx_data_dec_ref(tdata); |
| 1672 |
|
| 1673 |
pj_lock_release(regc->lock); |
| 1674 |
|
| 1675 |
|
| 1676 |
pjsip_regc_dec_ref(regc); |
| 1677 |
|
| 1678 |
return status; |
| 1679 |
} |
| 1680 |
|
| 1681 |
PJ_DEF(pj_status_t) pjsip_regc_set_auth_sess( pjsip_regc *regc, |
| 1682 |
pjsip_auth_clt_sess *session ) |
| 1683 |
{ |
| 1684 |
PJ_ASSERT_RETURN(regc, PJ_EINVAL); |
| 1685 |
return pjsip_auth_clt_set_parent(®c->auth_sess, session); |
| 1686 |
} |
| 1687 |
|
| 1688 |
|
| 1689 |
PJ_DEF(pjsip_auth_clt_sess*) pjsip_regc_get_auth_sess( pjsip_regc *regc ) |
| 1690 |
{ |
| 1691 |
PJ_ASSERT_RETURN(regc, NULL); |
| 1692 |
return ®c->auth_sess; |
| 1693 |
} |