Added parsing of either space or colon for sctp-port.

BUG=https://code.google.com/p/webrtc/issues/detail?id=5039

Review URL: https://codereview.webrtc.org/1395523002

Cr-Commit-Position: refs/heads/master@{#10225}
This commit is contained in:
lally 2015-10-08 10:15:04 -07:00 committed by Commit bot
parent e76fb36982
commit 69f576010e
2 changed files with 43 additions and 5 deletions

View File

@ -1127,16 +1127,17 @@ bool ParseSctpPort(const std::string& line,
// draft-ietf-mmusic-sctp-sdp-07
// a=sctp-port
std::vector<std::string> fields;
rtc::split(line.substr(kLinePrefixLength),
kSdpDelimiterSpace, &fields);
const size_t expected_min_fields = 2;
rtc::split(line.substr(kLinePrefixLength), kSdpDelimiterColon, &fields);
if (fields.size() < expected_min_fields) {
fields.resize(0);
rtc::split(line.substr(kLinePrefixLength), kSdpDelimiterSpace, &fields);
}
if (fields.size() < expected_min_fields) {
return ParseFailedExpectMinFieldNum(line, expected_min_fields, error);
}
if (!rtc::FromString(fields[1], sctp_port)) {
return ParseFailed(line,
"Invalid sctp port value.",
error);
return ParseFailed(line, "Invalid sctp port value.", error);
}
return true;
}
@ -1350,6 +1351,8 @@ void BuildMediaDescription(const ContentInfo* content_info,
void BuildSctpContentAttributes(std::string* message, int sctp_port) {
// draft-ietf-mmusic-sctp-sdp-04
// a=sctpmap:sctpmap-number protocol [streams]
// TODO(lally): switch this over to mmusic-sctp-sdp-12 (or later), with
// 'a=sctp-port:'
std::ostringstream os;
InitAttrLine(kAttributeSctpmap, &os);
os << kSdpDelimiterColon << sctp_port << kSdpDelimiterSpace

View File

@ -295,6 +295,15 @@ static const char kSdpSctpDataChannelStringWithSctpPort[] =
"a=ice-pwd:pwd_data\r\n"
"a=mid:data_content_name\r\n";
static const char kSdpSctpDataChannelStringWithSctpColonPort[] =
"m=application 9 DTLS/SCTP webrtc-datachannel\r\n"
"a=max-message-size=100000\r\n"
"a=sctp-port:5000\r\n"
"c=IN IP4 0.0.0.0\r\n"
"a=ice-ufrag:ufrag_data\r\n"
"a=ice-pwd:pwd_data\r\n"
"a=mid:data_content_name\r\n";
static const char kSdpSctpDataChannelWithCandidatesString[] =
"m=application 2345 DTLS/SCTP 5000\r\n"
"c=IN IP4 74.125.127.126\r\n"
@ -2124,6 +2133,32 @@ TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpPort) {
EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
}
TEST_F(WebRtcSdpTest, DeserializeSdpWithSctpDataChannelsWithSctpColonPort) {
AddSctpDataChannel();
JsepSessionDescription jdesc(kDummyString);
ASSERT_TRUE(jdesc.Initialize(desc_.Copy(), kSessionId, kSessionVersion));
std::string sdp_with_data = kSdpString;
sdp_with_data.append(kSdpSctpDataChannelStringWithSctpColonPort);
JsepSessionDescription jdesc_output(kDummyString);
// Verify with DTLS/SCTP.
EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
// Verify with UDP/DTLS/SCTP.
sdp_with_data.replace(sdp_with_data.find(kDtlsSctp),
strlen(kDtlsSctp), kUdpDtlsSctp);
EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
// Verify with TCP/DTLS/SCTP.
sdp_with_data.replace(sdp_with_data.find(kUdpDtlsSctp),
strlen(kUdpDtlsSctp), kTcpDtlsSctp);
EXPECT_TRUE(SdpDeserialize(sdp_with_data, &jdesc_output));
EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output));
}
// Test to check the behaviour if sctp-port is specified
// on the m= line and in a=sctp-port.
TEST_F(WebRtcSdpTest, DeserializeSdpWithMultiSctpPort) {