Changeset 1721
- Timestamp:
- Jan 21, 2008 3:28:16 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/users/nanang/pjmedia/src/pjmedia/transport_srtp.c
r1713 r1721 261 261 opt->close_member_tp = PJ_TRUE; 262 262 opt->use = PJMEDIA_SRTP_OPTIONAL; 263 opt->crypto_count = sizeof(crypto_suites)/sizeof(crypto_suites[0]); 263 264 /* Copy default crypto-suites, but skip crypto 'NULL' */ 265 opt->crypto_count = sizeof(crypto_suites)/sizeof(crypto_suites[0]) - 1; 264 266 for (i=0; i<opt->crypto_count; ++i) 265 opt->crypto[i].name = pj_str(crypto_suites[i ].name);267 opt->crypto[i].name = pj_str(crypto_suites[i+1].name); 266 268 } 267 269 … … 328 330 srtp->setting.crypto[i].name = pj_str(crypto_suites[cs_idx].name); 329 331 /* cut key length */ 330 tmp_key.slen = crypto_suites[cs_idx].cipher_key_len; 332 if (tmp_key.slen) 333 tmp_key.slen = crypto_suites[cs_idx].cipher_key_len; 331 334 pj_strdup(pool, &srtp->setting.crypto[i].key, &tmp_key); 332 335 } … … 872 875 enum { MAXLEN = 512 }; 873 876 char buffer[MAXLEN]; 874 int buffer_len = MAXLEN;877 int buffer_len; 875 878 pj_status_t status; 876 879 pjmedia_sdp_attr *attr; … … 880 883 PJ_ASSERT_RETURN(tp && pool && sdp_local, PJ_EINVAL); 881 884 882 pj_bzero(&srtp->rx_policy, sizeof(srtp-> rx_policy));885 pj_bzero(&srtp->rx_policy, sizeof(srtp->tx_policy)); 883 886 pj_bzero(&srtp->tx_policy, sizeof(srtp->rx_policy)); 884 887 … … 889 892 if (pj_stricmp(&m_loc->desc.transport, &ID_RTP_AVP) != 0 && 890 893 pj_stricmp(&m_loc->desc.transport, &ID_RTP_SAVP) != 0) 891 goto PROPAGATE_MEDIA_CREATE;894 goto BYPASS_SRTP; 892 895 893 896 /* If the media is inactive, do nothing. */ … … 895 898 (m_rem && pjmedia_sdp_media_find_attr(m_rem, &ID_INACTIVE, NULL))) 896 899 { 897 goto PROPAGATE_MEDIA_CREATE;900 goto BYPASS_SRTP; 898 901 } 899 902 … … 905 908 if (srtp->offerer_side) { 906 909 if (srtp->setting.use == PJMEDIA_SRTP_DISABLED) { 907 goto PROPAGATE_MEDIA_CREATE;910 goto BYPASS_SRTP; 908 911 } else if (srtp->setting.use == PJMEDIA_SRTP_OPTIONAL) { 909 912 m_loc->desc.transport = ID_RTP_AVP; … … 931 934 for (i=0; i<srtp->setting.crypto_count; ++i) { 932 935 /* Offer crypto-suites based on setting. */ 936 buffer_len = MAXLEN; 933 937 status = generate_crypto_attr_value(pool, buffer, &buffer_len, 934 938 &srtp->setting.crypto[i], … … 958 962 continue; 959 963 964 /* SRTP is disabled but there is crypto attr in remote media */ 960 965 if (srtp->setting.use == PJMEDIA_SRTP_DISABLED) { 961 966 DEACTIVATE_MEDIA(pool, m_loc); … … 1002 1007 if (srtp->setting.use == PJMEDIA_SRTP_DISABLED) { 1003 1008 /* At this point, it is ensured remote has no crypto attr */ 1004 goto PROPAGATE_MEDIA_CREATE;1009 goto BYPASS_SRTP; 1005 1010 } else if (srtp->setting.use == PJMEDIA_SRTP_OPTIONAL) { 1006 if (!has_crypto_attr) 1007 goto PROPAGATE_MEDIA_CREATE;; 1011 /* bypass SRTP when no crypto-attr but remote uses RTP/AVP */ 1012 if (!has_crypto_attr && 1013 pj_stricmp(&m_rem->desc.transport, &ID_RTP_AVP) == 0) 1014 goto BYPASS_SRTP; 1015 /* bypass SRTP when nothing match but remote uses RTP/AVP */ 1016 if (!has_match && 1017 pj_stricmp(&m_rem->desc.transport, &ID_RTP_AVP) == 0) 1018 goto BYPASS_SRTP; 1008 1019 } else if (srtp->setting.use == PJMEDIA_SRTP_MANDATORY) { 1009 1020 if (!has_crypto_attr) { … … 1023 1034 * and rem_tag contains matched offer tag. 1024 1035 */ 1036 buffer_len = MAXLEN; 1025 1037 status = generate_crypto_attr_value(pool, buffer, &buffer_len, 1026 1038 &srtp->tx_policy, … … 1040 1052 */ 1041 1053 } 1054 goto PROPAGATE_MEDIA_CREATE; 1055 1056 BYPASS_SRTP: 1057 srtp->bypass_srtp = PJ_TRUE; 1042 1058 1043 1059 PROPAGATE_MEDIA_CREATE: … … 1062 1078 PJ_ASSERT_RETURN(tp && pool && sdp_local && sdp_remote, PJ_EINVAL); 1063 1079 1080 if (srtp->bypass_srtp) 1081 goto BYPASS_SRTP; 1082 1064 1083 m_rem = sdp_remote->media[media_index]; 1065 1084 m_loc = sdp_local->media[media_index]; 1066 1067 /* bypass if media transport is not RTP/AVP or RTP/SAVP */1068 if (pj_stricmp(&m_loc->desc.transport, &ID_RTP_AVP) != 0 &&1069 pj_stricmp(&m_loc->desc.transport, &ID_RTP_SAVP) != 0)1070 {1071 srtp->bypass_srtp = PJ_TRUE;1072 goto PROPAGATE_MEDIA_START;1073 }1074 1075 /* If the media is inactive, do nothing. */1076 if (pjmedia_sdp_media_find_attr(m_loc, &ID_INACTIVE, NULL) ||1077 (m_rem && pjmedia_sdp_media_find_attr(m_rem, &ID_INACTIVE, NULL)))1078 {1079 srtp->bypass_srtp = PJ_TRUE;1080 goto PROPAGATE_MEDIA_START;1081 }1082 1085 1083 1086 /* For answerer side, this function will just have to start SRTP */ … … 1092 1095 return PJMEDIA_SRTP_ESDPINCRYPTO; 1093 1096 } 1094 srtp->bypass_srtp = PJ_TRUE; 1095 goto PROPAGATE_MEDIA_START; 1097 goto BYPASS_SRTP; 1096 1098 } else if (srtp->setting.use == PJMEDIA_SRTP_OPTIONAL) { 1097 1099 if (pj_stricmp(&m_rem->desc.transport, &m_loc->desc.transport)) { … … 1151 1153 if (srtp->setting.use == PJMEDIA_SRTP_DISABLED) { 1152 1154 /* should never reach here */ 1153 srtp->bypass_srtp = PJ_TRUE; 1154 goto PROPAGATE_MEDIA_START; 1155 goto BYPASS_SRTP; 1155 1156 } else if (srtp->setting.use == PJMEDIA_SRTP_OPTIONAL) { 1156 if (!has_crypto_attr) { 1157 srtp->bypass_srtp = PJ_TRUE; 1158 goto PROPAGATE_MEDIA_START; 1159 } 1157 if (!has_crypto_attr) 1158 goto BYPASS_SRTP; 1160 1159 } else if (srtp->setting.use == PJMEDIA_SRTP_MANDATORY) { 1161 1160 if (!has_crypto_attr) { … … 1175 1174 return status; 1176 1175 1176 goto PROPAGATE_MEDIA_START; 1177 1178 BYPASS_SRTP: 1179 srtp->bypass_srtp = PJ_TRUE; 1180 1177 1181 PROPAGATE_MEDIA_START: 1178 1182 return pjmedia_transport_media_start(srtp->real_tp, pool, … … 1186 1190 pj_status_t status; 1187 1191 1188 if (srtp->setting.close_member_tp) { 1189 status = pjmedia_transport_media_stop(srtp->real_tp); 1190 if (status != PJ_SUCCESS) 1191 PJ_LOG(4, (THIS_FILE, "Failed deinit session.")); 1192 } 1192 status = pjmedia_transport_media_stop(srtp->real_tp); 1193 if (status != PJ_SUCCESS) 1194 PJ_LOG(4, (THIS_FILE, "SRTP failed stop underlying media transport.")); 1193 1195 1194 1196 return pjmedia_transport_srtp_stop(tp);
Note: See TracChangeset
for help on using the changeset viewer.