Changeset 3243 for pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c
- Timestamp:
- Aug 1, 2010 9:48:51 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c
r3222 r3243 24 24 #include <pjsip/sip_endpoint.h> 25 25 #include <pjsip/sip_event.h> 26 #include <pjsip/sip_multipart.h> 26 27 #include <pjsip/sip_transaction.h> 27 28 #include <pjmedia/sdp.h> … … 746 747 } 747 748 749 PJ_DEF(pjsip_rdata_sdp_info*) pjsip_rdata_get_sdp_info(pjsip_rx_data *rdata) 750 { 751 pjsip_rdata_sdp_info *sdp_info; 752 pjsip_msg_body *body = rdata->msg_info.msg->body; 753 pjsip_ctype_hdr *ctype_hdr = rdata->msg_info.ctype; 754 pjsip_media_type app_sdp; 755 756 sdp_info = (pjsip_rdata_sdp_info*) 757 rdata->endpt_info.mod_data[mod_inv.mod.id]; 758 if (sdp_info) 759 return sdp_info; 760 761 sdp_info = PJ_POOL_ZALLOC_T(rdata->tp_info.pool, 762 pjsip_rdata_sdp_info); 763 PJ_ASSERT_RETURN(mod_inv.mod.id >= 0, sdp_info); 764 rdata->endpt_info.mod_data[mod_inv.mod.id] = sdp_info; 765 766 pjsip_media_type_init2(&app_sdp, "application", "sdp"); 767 768 if (body && ctype_hdr && 769 pj_stricmp(&ctype_hdr->media.type, &app_sdp.type)==0 && 770 pj_stricmp(&ctype_hdr->media.subtype, &app_sdp.subtype)==0) 771 { 772 sdp_info->body.ptr = (char*)body->data; 773 sdp_info->body.slen = body->len; 774 } else if (body && ctype_hdr && 775 pj_stricmp2(&ctype_hdr->media.type, "multipart")==0 && 776 (pj_stricmp2(&ctype_hdr->media.subtype, "mixed")==0 || 777 pj_stricmp2(&ctype_hdr->media.subtype, "alternative")==0)) 778 { 779 pjsip_multipart_part *part; 780 781 part = pjsip_multipart_find_part(body, &app_sdp, NULL); 782 if (part) { 783 sdp_info->body.ptr = (char*)part->body->data; 784 sdp_info->body.slen = part->body->len; 785 } 786 } 787 788 if (sdp_info->body.ptr) { 789 pj_status_t status; 790 status = pjmedia_sdp_parse(rdata->tp_info.pool, 791 sdp_info->body.ptr, 792 sdp_info->body.slen, 793 &sdp_info->sdp); 794 if (status == PJ_SUCCESS) 795 status = pjmedia_sdp_validate(sdp_info->sdp); 796 797 if (status != PJ_SUCCESS) { 798 sdp_info->sdp = NULL; 799 PJ_PERROR(1,(THIS_FILE, status, 800 "Error parsing/validating SDP body")); 801 } 802 803 sdp_info->sdp_err = status; 804 } 805 806 return sdp_info; 807 } 808 809 748 810 /* 749 811 * Verify incoming INVITE request. … … 766 828 pj_status_t status = PJ_SUCCESS; 767 829 pjsip_hdr res_hdr_list; 830 pjsip_rdata_sdp_info *sdp_info; 768 831 769 832 /* Init return arguments. */ … … 822 885 * only when the body hasn't been parsed before. 823 886 */ 887 if (r_sdp == NULL) { 888 sdp_info = pjsip_rdata_get_sdp_info(rdata); 889 } else { 890 sdp_info = NULL; 891 } 892 824 893 if (r_sdp==NULL && msg->body) { 825 pjsip_msg_body *body = msg->body; 826 pj_str_t str_application = {"application", 11}; 827 pj_str_t str_sdp = { "sdp", 3 }; 828 pjmedia_sdp_session *sdp; 829 830 /* Check content type. */ 831 if (pj_stricmp(&body->content_type.type, &str_application) != 0 || 832 pj_stricmp(&body->content_type.subtype, &str_sdp) != 0) 833 { 834 /* Not "application/sdp" */ 894 895 /* Check if body really contains SDP. */ 896 if (sdp_info->body.ptr == NULL) { 897 /* Couldn't find "application/sdp" */ 835 898 code = PJSIP_SC_UNSUPPORTED_MEDIA_TYPE; 836 899 status = PJSIP_ERRNO_FROM_SIP_STATUS(code); … … 849 912 } 850 913 851 /* Parse and validate SDP */ 852 status = pjmedia_sdp_parse(rdata->tp_info.pool, 853 (char*)body->data, body->len, &sdp); 854 if (status == PJ_SUCCESS) 855 status = pjmedia_sdp_validate(sdp); 856 857 if (status != PJ_SUCCESS) { 914 if (sdp_info->sdp_err != PJ_SUCCESS) { 858 915 /* Unparseable or invalid SDP */ 859 916 code = PJSIP_SC_BAD_REQUEST; … … 865 922 w = pjsip_warning_hdr_create_from_status(rdata->tp_info.pool, 866 923 pjsip_endpt_name(endpt), 867 s tatus);924 sdp_info->sdp_err); 868 925 PJ_ASSERT_RETURN(w, PJ_ENOMEM); 869 926 … … 874 931 } 875 932 876 r_sdp = sdp ;933 r_sdp = sdp_info->sdp; 877 934 } 878 935 … … 1164 1221 struct tsx_inv_data *tsx_inv_data; 1165 1222 pjsip_msg *msg; 1166 pj media_sdp_session *rem_sdp = NULL;1223 pjsip_rdata_sdp_info *sdp_info; 1167 1224 pj_status_t status; 1168 1225 … … 1212 1269 pj_ansi_snprintf(inv->obj_name, PJ_MAX_OBJ_NAME, "inv%p", dlg); 1213 1270 1214 /* Parse SDP in message body, if present. */ 1215 if (msg->body) { 1216 pjsip_msg_body *body = msg->body; 1217 1218 /* Parse and validate SDP */ 1219 status = pjmedia_sdp_parse(inv->pool, (char*)body->data, body->len, 1220 &rem_sdp); 1221 if (status == PJ_SUCCESS) 1222 status = pjmedia_sdp_validate(rem_sdp); 1223 1224 if (status != PJ_SUCCESS) { 1225 pjsip_dlg_dec_lock(dlg); 1226 return status; 1227 } 1271 /* Process SDP in message body, if present. */ 1272 sdp_info = pjsip_rdata_get_sdp_info(rdata); 1273 if (sdp_info->sdp_err) { 1274 pjsip_dlg_dec_lock(dlg); 1275 return sdp_info->sdp_err; 1228 1276 } 1229 1277 1230 1278 /* Create negotiator. */ 1231 if ( rem_sdp) {1232 status = pjmedia_sdp_neg_create_w_remote_offer(inv->pool, 1233 local_sdp, rem_sdp,1279 if (sdp_info->sdp) { 1280 status = pjmedia_sdp_neg_create_w_remote_offer(inv->pool, local_sdp, 1281 sdp_info->sdp, 1234 1282 &inv->neg); 1235 1283 … … 1375 1423 PJ_ASSERT_RETURN(body != NULL, PJ_ENOMEM); 1376 1424 1377 body->content_type.type = STR_APPLICATION;1378 body->content_type.subtype = STR_SDP;1425 pjsip_media_type_init(&body->content_type, (pj_str_t*)&STR_APPLICATION, 1426 (pj_str_t*)&STR_SDP); 1379 1427 body->data = sdp; 1380 1428 body->len = 0; … … 1528 1576 } 1529 1577 1578 1530 1579 /* 1531 1580 * Initiate SDP negotiation in the SDP negotiator. … … 1576 1625 { 1577 1626 struct tsx_inv_data *tsx_inv_data; 1578 static const pj_str_t str_application = { "application", 11 };1579 static const pj_str_t str_sdp = { "sdp", 3 };1580 1627 pj_status_t status; 1581 1628 pjsip_msg *msg; 1582 pj media_sdp_session *rem_sdp;1629 pjsip_rdata_sdp_info *sdp_info; 1583 1630 1584 1631 /* Check if SDP is present in the message. */ … … 1590 1637 } 1591 1638 1592 if (pj_stricmp(&msg->body->content_type.type, &str_application) || 1593 pj_stricmp(&msg->body->content_type.subtype, &str_sdp)) 1594 { 1639 sdp_info = pjsip_rdata_get_sdp_info(rdata); 1640 if (sdp_info->body.ptr == NULL) { 1595 1641 /* Message body is not "application/sdp" */ 1596 1642 return PJMEDIA_SDP_EINSDP; … … 1661 1707 } 1662 1708 1663 /* Parse the SDP body. */ 1664 1665 status = pjmedia_sdp_parse(rdata->tp_info.pool, 1666 (char*)msg->body->data, 1667 msg->body->len, &rem_sdp); 1668 if (status == PJ_SUCCESS) 1669 status = pjmedia_sdp_validate(rem_sdp); 1670 1671 if (status != PJ_SUCCESS) { 1672 char errmsg[PJ_ERR_MSG_SIZE]; 1673 pj_strerror(status, errmsg, sizeof(errmsg)); 1674 PJ_LOG(4,(THIS_FILE, "Error parsing SDP in %s: %s", 1675 pjsip_rx_data_get_info(rdata), errmsg)); 1709 /* Process the SDP body. */ 1710 if (sdp_info->sdp_err) { 1711 PJ_PERROR(4,(THIS_FILE, sdp_info->sdp_err, 1712 "Error parsing SDP in %s", 1713 pjsip_rx_data_get_info(rdata))); 1676 1714 return PJMEDIA_SDP_EINSDP; 1677 1715 } 1716 1717 pj_assert(sdp_info->sdp != NULL); 1678 1718 1679 1719 /* The SDP can be an offer or answer, depending on negotiator's state */ … … 1690 1730 if (inv->neg == NULL) { 1691 1731 status=pjmedia_sdp_neg_create_w_remote_offer(inv->pool, NULL, 1692 rem_sdp, &inv->neg); 1732 sdp_info->sdp, 1733 &inv->neg); 1693 1734 } else { 1694 1735 status=pjmedia_sdp_neg_set_remote_offer(inv->pool_prov, inv->neg, 1695 rem_sdp);1736 sdp_info->sdp); 1696 1737 } 1697 1738 1698 1739 if (status != PJ_SUCCESS) { 1699 char errmsg[PJ_ERR_MSG_SIZE]; 1700 pj_strerror(status, errmsg, sizeof(errmsg)); 1701 PJ_LOG(4,(THIS_FILE, "Error processing SDP offer in %s: %s", 1702 pjsip_rx_data_get_info(rdata), errmsg)); 1740 PJ_PERROR(4,(THIS_FILE, status, "Error processing SDP offer in %", 1741 pjsip_rx_data_get_info(rdata))); 1703 1742 return PJMEDIA_SDP_EINSDP; 1704 1743 } … … 1708 1747 if (mod_inv.cb.on_rx_offer && inv->notify) { 1709 1748 1710 (*mod_inv.cb.on_rx_offer)(inv, rem_sdp);1749 (*mod_inv.cb.on_rx_offer)(inv, sdp_info->sdp); 1711 1750 1712 1751 } … … 1725 1764 1726 1765 status = pjmedia_sdp_neg_set_remote_answer(inv->pool_prov, inv->neg, 1727 rem_sdp);1766 sdp_info->sdp); 1728 1767 1729 1768 if (status != PJ_SUCCESS) { 1730 char errmsg[PJ_ERR_MSG_SIZE]; 1731 pj_strerror(status, errmsg, sizeof(errmsg)); 1732 PJ_LOG(4,(THIS_FILE, "Error processing SDP answer in %s: %s", 1733 pjsip_rx_data_get_info(rdata), errmsg)); 1769 PJ_PERROR(4,(THIS_FILE, status, "Error processing SDP answer in %s", 1770 pjsip_rx_data_get_info(rdata))); 1734 1771 return PJMEDIA_SDP_EINSDP; 1735 1772 } … … 3856 3893 pjsip_tx_data *tdata; 3857 3894 pj_status_t status; 3895 pjsip_rdata_sdp_info *sdp_info; 3858 3896 pjsip_status_code st_code; 3859 3897 … … 3926 3964 * Otherwise generate offer from local active SDP. 3927 3965 */ 3928 if (rdata->msg_info.msg->body != NULL) { 3966 sdp_info = pjsip_rdata_get_sdp_info(rdata); 3967 if (sdp_info->sdp != NULL) { 3929 3968 status = process_answer(inv, 200, tdata, NULL); 3930 3969 } else {
Note: See TracChangeset
for help on using the changeset viewer.