Changeset 1709
- Timestamp:
- Jan 18, 2008 6:49:29 PM (17 years ago)
- Location:
- pjproject/branches/users/nanang
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/users/nanang/pjsip-apps/src/pjsua/pjsua_app.c
r1698 r1709 121 121 puts ("SIP Account options:"); 122 122 puts (" --use-ims Enable 3GPP/IMS related settings on this account"); 123 puts (" --use-srtp=N Use SRTP N= 0: disabled, 1: optional, 2: mandatory"); 123 124 puts (" --registrar=url Set the URL of registrar server"); 124 125 puts (" --id=url Set the URL of local ID (used in From header)"); … … 166 167 puts ("Media Options:"); 167 168 puts (" --use-ice Enable ICE (default:no)"); 168 puts (" --use-srtp Enable SRTP (default:no)");169 169 puts (" --add-codec=name Manually add codec (default is to enable all)"); 170 170 puts (" --dis-codec=name Disable codec (can be specified multiple times)"); … … 443 443 { "rtp-port", 1, 0, OPT_RTP_PORT}, 444 444 { "use-ice", 0, 0, OPT_USE_ICE}, 445 { "use-srtp", 0, 0, OPT_USE_SRTP},445 { "use-srtp", 1, 0, OPT_USE_SRTP}, 446 446 { "add-codec", 1, 0, OPT_ADD_CODEC}, 447 447 { "dis-codec", 1, 0, OPT_DIS_CODEC}, … … 800 800 801 801 case OPT_USE_SRTP: 802 cfg->media_cfg.enable_srtp = PJ_TRUE; 802 i = my_atoi(pj_optarg); 803 if (!pj_isdigit(*pj_optarg) || i > 2) { 804 PJ_LOG(1,(THIS_FILE, "Invalid value for --use-srtp option")); 805 return -1; 806 } 807 cur_acc->use_srtp = i; 803 808 break; 804 809 … … 1115 1120 pj_ansi_sprintf(line, "--auto-update-nat %i\n", 1116 1121 (int)acc_cfg->auto_update_nat); 1122 pj_strcat2(result, line); 1123 } 1124 1125 /* SRTP */ 1126 if (acc_cfg->use_srtp) { 1127 pj_ansi_sprintf(line, "--use-srtp %i\n", 1128 (int)acc_cfg->use_srtp); 1117 1129 pj_strcat2(result, line); 1118 1130 } -
pjproject/branches/users/nanang/pjsip/include/pjsua-lib/pjsua.h
r1698 r1709 1972 1972 pj_str_t ka_data; 1973 1973 1974 /** 1975 * Specify whether secure media transport should be used for this account. 1976 * Valid values are PJMEDIA_SRTP_DISABLED, PJMEDIA_SRTP_OPTIONAL, and 1977 * PJMEDIA_SRTP_MANDATORY. 1978 * 1979 * Default: 1980 * PJMEDIA_SRTP_DISABLED 1981 */ 1982 pjmedia_srtp_use use_srtp; 1983 1984 /** 1985 * Specify whether SRTP requires secure signaling to be used. This option 1986 * is only used when \a use_srtp option above is non-zero. 1987 * 1988 * Valid values are: 1989 * 0: SRTP does not require secure signaling 1990 * 1: SRTP requires secure transport such as TLS 1991 * 2: SRTP requires secure end-to-end transport (SIPS) 1992 * 1993 * Default: 0 1994 */ 1995 int srtp_secure_signaling; 1996 1974 1997 } pjsua_acc_config; 1975 1998 … … 3769 3792 */ 3770 3793 pj_bool_t enable_relay; 3771 3772 /**3773 * Enable SRTP3774 */3775 pj_bool_t enable_srtp;3776 3794 }; 3777 3795 -
pjproject/branches/users/nanang/pjsip/include/pjsua-lib/pjsua_internal.h
r1698 r1709 51 51 pjsip_evsub *xfer_sub; /**< Xfer server subscription, if this 52 52 call was triggered by xfer. */ 53 pjmedia_transport *med_tp; /**< Media transport. */ 53 pjmedia_transport *med_tp; /**< Current media transport. */ 54 pjmedia_transport *med_orig; /**< Original media transport */ 54 55 pj_timer_entry refresh_tm;/**< Timer to send re-INVITE. */ 55 56 pj_timer_entry hangup_tm; /**< Timer to hangup call. */ … … 313 314 */ 314 315 pj_status_t pjsua_media_channel_init(pjsua_call_id call_id, 315 pjsip_role_e role); 316 pjsip_role_e role, 317 int security_level); 316 318 pj_status_t pjsua_media_channel_create_sdp(pjsua_call_id call_id, 317 319 pj_pool_t *pool, -
pjproject/branches/users/nanang/pjsip/src/pjsua-lib/pjsua_call.c
r1698 r1709 215 215 #define LATE_SDP 0 216 216 217 static pj_bool_t pj_stristr(const pj_str_t *str, const pj_str_t *substr) 218 { 219 int i; 220 221 for (i=0; i<(str->slen-substr->slen); ++i) { 222 pj_str_t s; 223 s.ptr = str->ptr+i; 224 s.slen = substr->slen; 225 226 if (pj_stricmp(&s, substr)==0) 227 return PJ_TRUE; 228 } 229 return PJ_FALSE; 230 } 231 232 /* Get signaling secure level. 233 * Return: 234 * 0: if signaling is not secure 235 * 1: if TLS transport is used for immediate hop 236 * 2: if end-to-end signaling is secure. 237 * 238 * NOTE: 239 * THIS IS WRONG. It should take into account the route-set. 240 */ 241 static int get_secure_level(const pj_str_t *dst_uri) 242 { 243 const pj_str_t tls = pj_str(";transport=tls"); 244 const pj_str_t sips = pj_str("sips:"); 245 246 PJ_TODO(Fix_get_secure_level); 247 248 if (pj_stristr(dst_uri, &sips)) 249 return 2; 250 if (pj_stristr(dst_uri, &tls)) 251 return 1; 252 return 0; 253 } 254 217 255 /* 218 256 * Make outgoing call to the specified URI using the specified account. … … 325 363 326 364 /* Init media channel */ 327 status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC); 365 status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC, 366 get_secure_level(dest_uri)); 328 367 if (status != PJ_SUCCESS) { 329 368 pjsua_perror(THIS_FILE, "Error initializing media channel", status); … … 482 521 pjsua_call *call; 483 522 int call_id = -1; 523 int secure_level; 484 524 pjmedia_sdp_session *offer, *answer; 485 525 pj_status_t status; … … 580 620 } 581 621 622 /* 623 * Get which account is most likely to be associated with this incoming 624 * call. We need the account to find which contact URI to put for 625 * the call. 626 */ 627 acc_id = call->acc_id = pjsua_acc_find_for_incoming(rdata); 628 629 /* Get signaling security level, only when required by SRTP */ 630 if (pjsua_var.acc[acc_id].cfg.srtp_secure_signaling < 2) { 631 secure_level = PJSIP_TRANSPORT_IS_SECURE(rdata->tp_info.transport)!=0; 632 } else { 633 char *uri; 634 int uri_len; 635 pj_str_t dst; 636 637 uri = pj_pool_alloc(rdata->tp_info.pool, PJSIP_MAX_URL_SIZE); 638 uri_len = pjsip_uri_print(PJSIP_URI_IN_REQ_URI, 639 rdata->msg_info.msg->line.req.uri, 640 uri, PJSIP_MAX_URL_SIZE); 641 if (uri_len < 1) { 642 pjsua_perror(THIS_FILE, "Error analyzing dst URI", 643 PJSIP_EURITOOLONG); 644 uri_len = 0; 645 } 646 647 dst.ptr = uri; 648 dst.slen = uri_len; 649 650 secure_level = get_secure_level(&dst); 651 } 582 652 583 653 /* Init media channel */ 584 status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAS); 654 status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAS, 655 secure_level); 585 656 if (status != PJ_SUCCESS) { 586 657 pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata, 500, NULL, … … 618 689 } 619 690 620 /*621 * Get which account is most likely to be associated with this incoming622 * call. We need the account to find which contact URI to put for623 * the call.624 */625 acc_id = call->acc_id = pjsua_acc_find_for_incoming(rdata);626 627 691 /* Verify that we can handle the request. */ 628 692 options |= PJSIP_INV_SUPPORT_100REL; … … 1321 1385 1322 1386 /* Init media channel */ 1323 status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC); 1387 status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC, 1388 get_secure_level(&dlg->remote.info_str)); 1324 1389 if (status != PJ_SUCCESS) { 1325 1390 pjsua_perror(THIS_FILE, "Error initializing media channel", status); … … 1390 1455 1391 1456 /* Init media channel */ 1392 status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC); 1457 status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC, 1458 get_secure_level(&dlg->remote.info_str)); 1393 1459 if (status != PJ_SUCCESS) { 1394 1460 pjsua_perror(THIS_FILE, "Error initializing media channel", status); … … 2509 2575 status = create_inactive_sdp( call, &answer ); 2510 2576 } else { 2577 int secure_level; 2511 2578 2512 2579 PJ_LOG(4,(THIS_FILE, "Call %d: received updated media offer", … … 2514 2581 2515 2582 /* Init media channel */ 2516 status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAS); 2583 secure_level = get_secure_level(&call->inv->dlg->remote.info_str); 2584 status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAS, 2585 secure_level); 2517 2586 if (status != PJ_SUCCESS) { 2518 2587 pjsua_perror(THIS_FILE, "Error initializing media channel", status); … … 2562 2631 status = create_inactive_sdp( call, offer ); 2563 2632 } else { 2633 int secure_level; 2564 2634 2565 2635 PJ_LOG(4,(THIS_FILE, "Call %d: asked to send a new offer", … … 2567 2637 2568 2638 /* Init media channel */ 2569 status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC); 2639 secure_level = get_secure_level(&call->inv->dlg->remote.info_str); 2640 status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC, 2641 secure_level); 2570 2642 if (status != PJ_SUCCESS) { 2571 2643 pjsua_perror(THIS_FILE, "Error initializing media channel", status); -
pjproject/branches/users/nanang/pjsip/src/pjsua-lib/pjsua_core.c
r1675 r1709 143 143 cfg->ka_interval = 15; 144 144 cfg->ka_data = pj_str("\r\n"); 145 cfg->use_srtp = PJMEDIA_SRTP_DISABLED; 146 cfg->srtp_secure_signaling = 0; 145 147 } 146 148 -
pjproject/branches/users/nanang/pjsip/src/pjsua-lib/pjsua_media.c
r1700 r1709 536 536 } 537 537 538 if (pjsua_var.media_cfg.enable_srtp) { 539 pjmedia_transport *tp; 540 unsigned srtp_options = 0; 541 542 status = pjmedia_transport_udp_attach(pjsua_var.med_endpt, NULL, 543 &skinfo, 0, &tp); 544 status = pjmedia_transport_srtp_create(pjsua_var.med_endpt, tp, 545 srtp_options, 546 &pjsua_var.calls[i].med_tp); 547 } else { 548 status = pjmedia_transport_udp_attach(pjsua_var.med_endpt, NULL, 549 &skinfo, 0, 550 &pjsua_var.calls[i].med_tp); 551 } 538 status = pjmedia_transport_udp_attach(pjsua_var.med_endpt, NULL, 539 &skinfo, 0, 540 &pjsua_var.calls[i].med_tp); 552 541 if (status != PJ_SUCCESS) { 553 542 pjsua_perror(THIS_FILE, "Unable to create media transport", … … 757 746 758 747 pj_status_t pjsua_media_channel_init(pjsua_call_id call_id, 759 pjsip_role_e role) 748 pjsip_role_e role, 749 int security_level) 760 750 { 761 751 pjsua_call *call = &pjsua_var.calls[call_id]; 762 763 if (pjsua_var.media_cfg.enable_ice) { 764 pj_ice_sess_role ice_role; 765 pj_status_t status; 766 767 ice_role = (role==PJSIP_ROLE_UAC ? PJ_ICE_SESS_ROLE_CONTROLLING : 768 PJ_ICE_SESS_ROLE_CONTROLLED); 769 770 /* Restart ICE */ 771 pjmedia_transport_media_stop(call->med_tp); 772 773 status = pjmedia_ice_init_ice(call->med_tp, ice_role, NULL, NULL); 774 if (status != PJ_SUCCESS) 775 return status; 776 } 777 778 return PJ_SUCCESS; 779 } 780 781 pj_status_t pjsua_media_channel_create_sdp(pjsua_call_id call_id, 782 pj_pool_t *pool, 783 const pjmedia_sdp_session *rem_sdp, 784 pjmedia_sdp_session **p_sdp) 785 { 786 pjmedia_sdp_session *sdp; 787 pjmedia_sock_info skinfo; 788 pjsua_call *call = &pjsua_var.calls[call_id]; 789 pj_status_t status; 752 pjsua_acc *acc = &pjsua_var.acc[call->acc_id]; 753 pjmedia_srtp_use use_srtp; 754 755 PJ_UNUSED_ARG(role); 790 756 791 757 /* Return error if media transport has not been created yet … … 796 762 } 797 763 764 /* Stop media transport (for good measure!) */ 765 pjmedia_transport_media_stop(call->med_tp); 766 767 /* See if we need to use SRTP */ 768 use_srtp = acc->cfg.use_srtp; 769 if (use_srtp != PJMEDIA_SRTP_DISABLED) { 770 pj_status_t status; 771 pjmedia_transport *srtp; 772 773 if (security_level < acc->cfg.srtp_secure_signaling) { 774 return PJSIP_ESESSIONINSECURE; 775 } 776 777 /* Create SRTP */ 778 status = pjmedia_transport_srtp_create(pjsua_var.med_endpt, 779 call->med_tp, 780 NULL, &srtp); 781 if (status != PJ_SUCCESS) 782 return status; 783 784 /* Set SRTP as current media transport */ 785 call->med_tp = srtp; 786 } 787 788 return PJ_SUCCESS; 789 } 790 791 pj_status_t pjsua_media_channel_create_sdp(pjsua_call_id call_id, 792 pj_pool_t *pool, 793 const pjmedia_sdp_session *rem_sdp, 794 pjmedia_sdp_session **p_sdp) 795 { 796 enum { MAX_MEDIA = 1, MEDIA_IDX = 0 }; 797 pjmedia_sdp_session *sdp; 798 pjmedia_sock_info skinfo; 799 pjsua_call *call = &pjsua_var.calls[call_id]; 800 pj_status_t status; 801 802 /* Return error if media transport has not been created yet 803 * (e.g. application is starting) 804 */ 805 if (call->med_tp == NULL) { 806 return PJ_EBUSY; 807 } 808 798 809 /* Get media socket info */ 799 810 pjmedia_transport_get_info(call->med_tp, &skinfo); 800 811 801 812 /* Create SDP */ 802 status = pjmedia_endpt_create_sdp(pjsua_var.med_endpt, pool, 1,813 status = pjmedia_endpt_create_sdp(pjsua_var.med_endpt, pool, MAX_MEDIA, 803 814 &skinfo, &sdp); 804 815 if (status != PJ_SUCCESS) … … 829 840 } 830 841 831 //if (pjsua_var.media_cfg.enable_ice) { 832 //status = pjmedia_transport_media_create(call->med_tp, pool, sdp, NULL); 833 status = pjmedia_transport_media_create(call->med_tp, pool, 834 sdp, rem_sdp); 835 if (status != PJ_SUCCESS) 836 goto on_error; 837 //} 842 /* Give the SDP to media transport */ 843 status = pjmedia_transport_media_create(call->med_tp, pool, 844 sdp, rem_sdp, MEDIA_IDX); 845 if (status != PJ_SUCCESS) 846 goto on_error; 838 847 839 848 *p_sdp = sdp; … … 874 883 stop_media_session(call_id); 875 884 876 //if (pjsua_var.media_cfg.enable_ice) { 877 pjmedia_transport_media_stop(call->med_tp); 878 //} 879 885 pjmedia_transport_media_stop(call->med_tp); 886 887 if (call->med_tp != call->med_orig) { 888 pjmedia_transport_close(call->med_tp); 889 call->med_tp = call->med_orig; 890 } 880 891 return PJ_SUCCESS; 881 892 } … … 962 973 call->media_dir = PJMEDIA_DIR_NONE; 963 974 964 /* Shutdown ICE session */ 965 //if (pjsua_var.media_cfg.enable_ice) { 966 pjmedia_transport_media_stop(call->med_tp); 967 //} 975 /* Shutdown transport's session */ 976 pjmedia_transport_media_stop(call->med_tp); 968 977 969 978 /* No need because we need keepalive? */ 970 979 971 980 } else { 972 /* Start ICE */ 973 //if (pjsua_var.media_cfg.enable_ice) { 974 status = pjmedia_transport_media_start(call->med_tp, 975 call->inv->pool, 976 local_sdp, remote_sdp, 0); 977 if (status != PJ_SUCCESS) 978 return status; 979 //} 981 /* Start media transport */ 982 status = pjmedia_transport_media_start(call->med_tp, 983 call->inv->pool, 984 local_sdp, remote_sdp, 0); 985 if (status != PJ_SUCCESS) 986 return status; 980 987 981 988 /* Override ptime, if this option is specified. */
Note: See TracChangeset
for help on using the changeset viewer.