Changeset 685 for pjproject/trunk/pjsip/src/pjsip-simple/presence.c
- Timestamp:
- Aug 15, 2006 8:26:34 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsip-simple/presence.c
r519 r685 180 180 PJ_DEF(pj_status_t) pjsip_pres_create_uac( pjsip_dialog *dlg, 181 181 const pjsip_evsub_user *user_cb, 182 unsigned options, 182 183 pjsip_evsub **p_evsub ) 183 184 { … … 191 192 192 193 /* Create event subscription */ 193 status = pjsip_evsub_create_uac( dlg, &pres_user, &STR_PRESENCE, 0, &sub); 194 status = pjsip_evsub_create_uac( dlg, &pres_user, &STR_PRESENCE, 195 options, &sub); 194 196 if (status != PJ_SUCCESS) 195 197 goto on_return; … … 413 415 414 416 /* 415 * Create PIDF document based on the presence info. 416 */ 417 static pjpidf_pres* pres_create_pidf( pj_pool_t *pool, 418 pjsip_pres *pres ) 419 { 420 pjpidf_pres *pidf; 421 unsigned i; 417 * Create message body. 418 */ 419 static pj_status_t pres_create_msg_body( pjsip_pres *pres, 420 pjsip_tx_data *tdata) 421 { 422 422 pj_str_t entity; 423 423 424 424 /* Get publisher URI */ 425 entity.ptr = pj_pool_alloc( pool, PJSIP_MAX_URL_SIZE);425 entity.ptr = pj_pool_alloc(tdata->pool, PJSIP_MAX_URL_SIZE); 426 426 entity.slen = pjsip_uri_print(PJSIP_URI_IN_REQ_URI, 427 427 pres->dlg->local.info->uri, 428 428 entity.ptr, PJSIP_MAX_URL_SIZE); 429 429 if (entity.slen < 1) 430 return NULL; 431 432 /* Create <presence>. */ 433 pidf = pjpidf_create(pool, &entity); 434 435 /* Create <tuple> */ 436 for (i=0; i<pres->status.info_cnt; ++i) { 437 438 pjpidf_tuple *pidf_tuple; 439 pjpidf_status *pidf_status; 440 441 /* Add tuple id. */ 442 pidf_tuple = pjpidf_pres_add_tuple(pool, pidf, 443 &pres->status.info[i].id); 444 445 /* Set <contact> */ 446 if (pres->status.info[i].contact.slen) 447 pjpidf_tuple_set_contact(pool, pidf_tuple, 448 &pres->status.info[i].contact); 449 450 451 /* Set basic status */ 452 pidf_status = pjpidf_tuple_get_status(pidf_tuple); 453 pjpidf_status_set_basic_open(pidf_status, 454 pres->status.info[i].basic_open); 455 } 456 457 return pidf; 458 } 459 460 461 /* 462 * Create XPIDF document based on the presence info. 463 */ 464 static pjxpidf_pres* pres_create_xpidf( pj_pool_t *pool, 465 pjsip_pres *pres ) 466 { 467 /* Note: PJSIP implementation of XPIDF is not complete! 468 */ 469 pjxpidf_pres *xpidf; 470 pj_str_t publisher_uri; 471 472 PJ_LOG(4,(THIS_FILE, "Warning: XPIDF format is not fully supported " 473 "by PJSIP")); 474 475 publisher_uri.ptr = pj_pool_alloc(pool, PJSIP_MAX_URL_SIZE); 476 publisher_uri.slen = pjsip_uri_print(PJSIP_URI_IN_REQ_URI, 477 pres->dlg->local.info->uri, 478 publisher_uri.ptr, 479 PJSIP_MAX_URL_SIZE); 480 if (publisher_uri.slen < 1) 481 return NULL; 482 483 /* Create XPIDF document. */ 484 xpidf = pjxpidf_create(pool, &publisher_uri); 485 486 /* Set basic status. */ 487 if (pres->status.info_cnt > 0) 488 pjxpidf_set_status( xpidf, pres->status.info[0].basic_open); 489 else 490 pjxpidf_set_status( xpidf, PJ_FALSE); 491 492 return xpidf; 493 } 494 495 496 /* 497 * Function to print XML message body. 498 */ 499 static int pres_print_body(struct pjsip_msg_body *msg_body, 500 char *buf, pj_size_t size) 501 { 502 return pj_xml_print(msg_body->data, buf, size, PJ_TRUE); 503 } 504 505 506 /* 507 * Function to clone XML document. 508 */ 509 static void* xml_clone_data(pj_pool_t *pool, const void *data, unsigned len) 510 { 511 PJ_UNUSED_ARG(len); 512 return pj_xml_clone( pool, data); 513 } 514 515 516 /* 517 * Create message body. 518 */ 519 static pj_status_t pres_create_msg_body( pjsip_pres *pres, 520 pjsip_tx_data *tdata) 521 { 522 pjsip_msg_body *body; 523 524 body = pj_pool_zalloc(tdata->pool, sizeof(pjsip_msg_body)); 525 430 return PJ_ENOMEM; 431 526 432 if (pres->content_type == CONTENT_TYPE_PIDF) { 527 433 528 body->data = pres_create_pidf(tdata->pool, pres); 529 body->content_type.type = pj_str("application"); 530 body->content_type.subtype = pj_str("pidf+xml"); 434 return pjsip_pres_create_pidf(tdata->pool, &pres->status, 435 &entity, &tdata->msg->body); 531 436 532 437 } else if (pres->content_type == CONTENT_TYPE_XPIDF) { 533 438 534 body->data = pres_create_xpidf(tdata->pool, pres); 535 body->content_type.type = pj_str("application"); 536 body->content_type.subtype = pj_str("xpidf+xml"); 439 return pjsip_pres_create_xpidf(tdata->pool, &pres->status, 440 &entity, &tdata->msg->body); 537 441 538 442 } else { 539 443 return PJSIP_SIMPLE_EBADCONTENT; 540 444 } 541 542 543 body->print_body = &pres_print_body;544 body->clone_data = &xml_clone_data;545 546 tdata->msg->body = body;547 548 return PJ_SUCCESS;549 445 } 550 446 … … 723 619 } 724 620 725 /*726 * Parse PIDF to info.727 */728 static pj_status_t pres_parse_pidf( pjsip_pres *pres,729 pjsip_rx_data *rdata,730 pjsip_pres_status *pres_status)731 {732 pjpidf_pres *pidf;733 pjpidf_tuple *pidf_tuple;734 735 pidf = pjpidf_parse(rdata->tp_info.pool,736 rdata->msg_info.msg->body->data,737 rdata->msg_info.msg->body->len);738 if (pidf == NULL)739 return PJSIP_SIMPLE_EBADPIDF;740 741 pres_status->info_cnt = 0;742 743 pidf_tuple = pjpidf_pres_get_first_tuple(pidf);744 while (pidf_tuple) {745 pjpidf_status *pidf_status;746 747 pj_strdup(pres->dlg->pool,748 &pres_status->info[pres_status->info_cnt].id,749 pjpidf_tuple_get_id(pidf_tuple));750 751 pj_strdup(pres->dlg->pool,752 &pres_status->info[pres_status->info_cnt].contact,753 pjpidf_tuple_get_contact(pidf_tuple));754 755 pidf_status = pjpidf_tuple_get_status(pidf_tuple);756 if (pidf_status) {757 pres_status->info[pres_status->info_cnt].basic_open =758 pjpidf_status_is_basic_open(pidf_status);759 } else {760 pres_status->info[pres_status->info_cnt].basic_open = PJ_FALSE;761 }762 763 pidf_tuple = pjpidf_pres_get_next_tuple( pidf, pidf_tuple );764 pres_status->info_cnt++;765 }766 767 return PJ_SUCCESS;768 }769 770 /*771 * Parse XPIDF info.772 */773 static pj_status_t pres_parse_xpidf( pjsip_pres *pres,774 pjsip_rx_data *rdata,775 pjsip_pres_status *pres_status)776 {777 pjxpidf_pres *xpidf;778 779 xpidf = pjxpidf_parse(rdata->tp_info.pool,780 rdata->msg_info.msg->body->data,781 rdata->msg_info.msg->body->len);782 if (xpidf == NULL)783 return PJSIP_SIMPLE_EBADXPIDF;784 785 pres_status->info_cnt = 1;786 787 pj_strdup(pres->dlg->pool,788 &pres_status->info[0].contact,789 pjxpidf_get_uri(xpidf));790 pres_status->info[0].basic_open = pjxpidf_get_status(xpidf);791 pres_status->info[0].id.slen = 0;792 793 return PJ_SUCCESS;794 }795 796 621 797 622 /* … … 837 662 pj_stricmp(&ctype_hdr->media.subtype, &STR_PIDF_XML)==0) 838 663 { 839 status = pres_parse_pidf( pres, rdata, &pres->tmp_status); 664 status = pjsip_pres_parse_pidf( rdata, pres->dlg->pool, 665 &pres->tmp_status); 840 666 } 841 667 else … … 843 669 pj_stricmp(&ctype_hdr->media.subtype, &STR_XPIDF_XML)==0) 844 670 { 845 status = pres_parse_xpidf( pres, rdata, &pres->tmp_status); 671 status = pjsip_pres_parse_xpidf( rdata, pres->dlg->pool, 672 &pres->tmp_status); 846 673 } 847 674 else
Note: See TracChangeset
for help on using the changeset viewer.