Changeset 482 for pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c
- Timestamp:
- May 28, 2006 2:58:12 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c
r476 r482 236 236 if (buddy) { 237 237 PJ_LOG(3,(THIS_FILE, 238 "Presence subscription to %s is %s", 239 buddy->uri.ptr, 238 "Presence subscription to %.*s is %s", 239 (int)pjsua.config.buddy_uri[buddy->index].slen, 240 pjsua.config.buddy_uri[buddy->index].ptr, 240 241 pjsip_evsub_get_state_name(sub))); 241 242 … … 245 246 pjsip_evsub_set_mod_data(sub, pjsua.mod.id, NULL); 246 247 } 248 249 /* Call callback */ 250 if (pjsua.cb.on_buddy_state) 251 (*pjsua.cb.on_buddy_state)(buddy->index); 247 252 } 248 253 } … … 262 267 /* Update our info. */ 263 268 pjsip_pres_get_status(sub, &buddy->status); 264 265 if (buddy->status.info_cnt) {266 PJ_LOG(3,(THIS_FILE, "%s is %s",267 buddy->uri.ptr,268 (buddy->status.info[0].basic_open?"online":"offline")));269 } else {270 PJ_LOG(3,(THIS_FILE, "No presence info for %s",271 buddy->uri.ptr));272 }273 269 } 274 270 … … 321 317 &acc_config->id, 322 318 &acc_config->contact, 323 &pjsua. buddies[index].uri,319 &pjsua.config.buddy_uri[index], 324 320 NULL, &dlg); 325 321 if (status != PJ_SUCCESS) { … … 401 397 static void refresh_client_subscription(void) 402 398 { 403 inti;404 405 for (i=0; i<pjsua. buddy_cnt; ++i) {399 unsigned i; 400 401 for (i=0; i<pjsua.config.buddy_cnt; ++i) { 406 402 407 403 if (pjsua.buddies[i].monitor && !pjsua.buddies[i].sub) { … … 433 429 434 430 /* 431 * Get buddy count. 432 */ 433 PJ_DEF(unsigned) pjsua_get_buddy_count(void) 434 { 435 return pjsua.config.buddy_cnt; 436 } 437 438 439 /** 440 * Get buddy info. 441 */ 442 PJ_DEF(pj_status_t) pjsua_buddy_get_info(unsigned index, 443 pjsua_buddy_info *info) 444 { 445 pjsua_buddy *buddy; 446 447 PJ_ASSERT_RETURN(index < pjsua.config.buddy_cnt, PJ_EINVAL); 448 449 pj_memset(info, 0, sizeof(pjsua_buddy_info)); 450 451 buddy = &pjsua.buddies[index]; 452 info->index = buddy->index; 453 info->is_valid = pjsua.config.buddy_uri[index].slen; 454 if (!info->is_valid) 455 return PJ_SUCCESS; 456 457 info->name = buddy->name; 458 info->display_name = buddy->display; 459 info->host = buddy->host; 460 info->port = buddy->port; 461 info->uri = pjsua.config.buddy_uri[index]; 462 463 if (buddy->sub == NULL || buddy->status.info_cnt==0) { 464 info->status = PJSUA_BUDDY_STATUS_UNKNOWN; 465 info->status_text = pj_str("?"); 466 } else if (pjsua.buddies[index].status.info[0].basic_open) { 467 info->status = PJSUA_BUDDY_STATUS_ONLINE; 468 info->status_text = pj_str("Online"); 469 } else { 470 info->status = PJSUA_BUDDY_STATUS_OFFLINE; 471 info->status_text = pj_str("Offline"); 472 } 473 474 return PJ_SUCCESS; 475 } 476 477 478 /** 479 * Add new buddy. 480 */ 481 PJ_DEF(pj_status_t) pjsua_buddy_add( const pj_str_t *uri, 482 int *buddy_index) 483 { 484 pjsip_name_addr *url; 485 pjsip_sip_uri *sip_uri; 486 int index; 487 pj_str_t tmp; 488 489 PJ_ASSERT_RETURN(pjsua.config.buddy_cnt <= PJ_ARRAY_SIZE(pjsua.config.buddy_uri), 490 PJ_ETOOMANY); 491 492 index = pjsua.config.buddy_cnt; 493 494 /* Get name and display name for buddy */ 495 pj_strdup_with_null(pjsua.pool, &tmp, uri); 496 url = (pjsip_name_addr*)pjsip_parse_uri(pjsua.pool, tmp.ptr, tmp.slen, 497 PJSIP_PARSE_URI_AS_NAMEADDR); 498 499 if (url == NULL) 500 return PJSIP_EINVALIDURI; 501 502 /* Save URI */ 503 pjsua.config.buddy_uri[index] = tmp; 504 505 sip_uri = (pjsip_sip_uri*) url->uri; 506 pjsua.buddies[index].name = sip_uri->user; 507 pjsua.buddies[index].display = url->display; 508 pjsua.buddies[index].host = sip_uri->host; 509 pjsua.buddies[index].port = sip_uri->port; 510 if (pjsua.buddies[index].port == 0) 511 pjsua.buddies[index].port = 5060; 512 513 /* Find account for outgoing preence subscription */ 514 pjsua.buddies[index].acc_index = 515 pjsua_find_account_for_outgoing(&pjsua.config.buddy_uri[index]); 516 517 if (buddy_index) 518 *buddy_index = index; 519 520 pjsua.config.buddy_cnt++; 521 522 return PJ_SUCCESS; 523 } 524 525 526 527 PJ_DEF(pj_status_t) pjsua_buddy_subscribe_pres( unsigned index, 528 pj_bool_t monitor) 529 { 530 pjsua_buddy *buddy; 531 532 PJ_ASSERT_RETURN(index < pjsua.config.buddy_cnt, PJ_EINVAL); 533 534 buddy = &pjsua.buddies[index]; 535 buddy->monitor = monitor; 536 return PJ_SUCCESS; 537 } 538 539 540 PJ_DEF(pj_status_t) pjsua_acc_set_online_status( unsigned acc_index, 541 pj_bool_t is_online) 542 { 543 PJ_ASSERT_RETURN(acc_index < pjsua.config.acc_cnt, PJ_EINVAL); 544 pjsua.acc[acc_index].online_status = is_online; 545 return PJ_SUCCESS; 546 } 547 548 549 /* 435 550 * Refresh presence 436 551 */ … … 447 562 void pjsua_pres_shutdown(void) 448 563 { 449 intacc_index;450 inti;564 unsigned acc_index; 565 unsigned i; 451 566 452 567 for (acc_index=0; acc_index<(int)pjsua.config.acc_cnt; ++acc_index) { … … 454 569 } 455 570 456 for (i=0; i<pjsua. buddy_cnt; ++i) {571 for (i=0; i<pjsua.config.buddy_cnt; ++i) { 457 572 pjsua.buddies[i].monitor = 0; 458 573 } … … 468 583 void pjsua_pres_dump(pj_bool_t detail) 469 584 { 470 intacc_index;471 inti;585 unsigned acc_index; 586 unsigned i; 472 587 473 588 … … 498 613 count = 0; 499 614 500 for (i=0; i<pjsua. buddy_cnt; ++i) {615 for (i=0; i<pjsua.config.buddy_cnt; ++i) { 501 616 if (pjsua.buddies[i].sub) { 502 617 ++count; … … 545 660 PJ_LOG(3,(THIS_FILE, "Dumping pjsua client subscriptions:")); 546 661 547 if (pjsua. buddy_cnt == 0) {662 if (pjsua.config.buddy_cnt == 0) { 548 663 549 664 PJ_LOG(3,(THIS_FILE, " - no buddy list - ")); 550 665 551 666 } else { 552 for (i=0; i<pjsua. buddy_cnt; ++i) {667 for (i=0; i<pjsua.config.buddy_cnt; ++i) { 553 668 554 669 if (pjsua.buddies[i].sub) { 555 PJ_LOG(3,(THIS_FILE, " %10s % s",670 PJ_LOG(3,(THIS_FILE, " %10s %.*s", 556 671 pjsip_evsub_get_state_name(pjsua.buddies[i].sub), 557 pjsua.buddies[i].uri.ptr)); 672 (int)pjsua.config.buddy_uri[i].slen, 673 pjsua.config.buddy_uri[i].ptr)); 558 674 } else { 559 PJ_LOG(3,(THIS_FILE, " %10s % s",675 PJ_LOG(3,(THIS_FILE, " %10s %.*s", 560 676 "(null)", 561 pjsua.buddies[i].uri.ptr)); 677 (int)pjsua.config.buddy_uri[i].slen, 678 pjsua.config.buddy_uri[i].ptr)); 562 679 } 563 680 }
Note: See TracChangeset
for help on using the changeset viewer.