Bug 928060: Parse ?transport=[udp|tcp] in TURN uri. r=ehsan

This commit is contained in:
Jan-Ivar Bruaroey 2013-10-18 18:14:21 -04:00
parent 39b292cc30
commit 9e04440e70
3 changed files with 33 additions and 6 deletions

View File

@ -81,6 +81,9 @@ namespace mozilla {
class NrIceMediaStream; class NrIceMediaStream;
const std::string kNrIceTransportUdp("udp");
const std::string kNrIceTransportTcp("tcp");
class NrIceStunServer { class NrIceStunServer {
public: public:
NrIceStunServer(const PRNetAddr& addr) : has_addr_(true) { NrIceStunServer(const PRNetAddr& addr) : has_addr_(true) {
@ -134,7 +137,9 @@ class NrIceTurnServer : public NrIceStunServer {
public: public:
static NrIceTurnServer *Create(const std::string& addr, uint16_t port, static NrIceTurnServer *Create(const std::string& addr, uint16_t port,
const std::string& username, const std::string& username,
const std::vector<unsigned char>& password) { const std::vector<unsigned char>& password,
const std::string& transport = kNrIceTransportUdp) {
// TODO: Bug 906968 - Support TCP
ScopedDeletePtr<NrIceTurnServer> server( ScopedDeletePtr<NrIceTurnServer> server(
new NrIceTurnServer(username, password)); new NrIceTurnServer(username, password));

View File

@ -573,6 +573,12 @@ PeerConnectionImpl::ConvertRTCConfiguration(const RTCConfiguration& aSrc,
for (uint32_t i = 0; i < aSrc.mIceServers.Value().Length(); i++) { for (uint32_t i = 0; i < aSrc.mIceServers.Value().Length(); i++) {
const RTCIceServer& server = aSrc.mIceServers.Value()[i]; const RTCIceServer& server = aSrc.mIceServers.Value()[i];
NS_ENSURE_TRUE(server.mUrl.WasPassed(), NS_ERROR_UNEXPECTED); NS_ENSURE_TRUE(server.mUrl.WasPassed(), NS_ERROR_UNEXPECTED);
// Without STUN/TURN handlers, NS_NewURI returns nsSimpleURI rather than
// nsStandardURL. To parse STUN/TURN URI's to spec
// http://tools.ietf.org/html/draft-nandakumar-rtcweb-stun-uri-02#section-3
// http://tools.ietf.org/html/draft-petithuguenin-behave-turn-uri-03#section-3
// we parse out the query-string, and use ParseAuthority() on the rest
nsRefPtr<nsIURI> url; nsRefPtr<nsIURI> url;
nsresult rv = NS_NewURI(getter_AddRefs(url), server.mUrl.Value()); nsresult rv = NS_NewURI(getter_AddRefs(url), server.mUrl.Value());
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -588,9 +594,10 @@ PeerConnectionImpl::ConvertRTCConfiguration(const RTCConfiguration& aSrc,
rv = url->GetSpec(spec); rv = url->GetSpec(spec);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// TODO(jib@mozilla.com): Revisit once nsURI has STUN host+port (Bug 833509) // TODO(jib@mozilla.com): Revisit once nsURI supports STUN/TURN (Bug 833509)
int32_t port; int32_t port;
nsAutoCString host; nsAutoCString host;
nsAutoCString transport;
{ {
uint32_t hostPos; uint32_t hostPos;
int32_t hostLen; int32_t hostLen;
@ -598,9 +605,20 @@ PeerConnectionImpl::ConvertRTCConfiguration(const RTCConfiguration& aSrc,
rv = url->GetPath(path); rv = url->GetPath(path);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// Tolerate '?transport=udp' by stripping it. // Tolerate query-string + parse 'transport=[udp|tcp]' by hand.
int32_t questionmark = path.FindChar('?'); int32_t questionmark = path.FindChar('?');
if (questionmark >= 0) { if (questionmark >= 0) {
const nsCString match = NS_LITERAL_CSTRING("transport=");
for (int32_t i = questionmark, endPos; i >= 0; i = endPos) {
endPos = path.FindCharInSet("&", i + 1);
const nsDependentCSubstring fieldvaluepair = Substring(path, i + 1,
endPos);
if (StringBeginsWith(fieldvaluepair, match)) {
transport = Substring(fieldvaluepair, match.Length());
ToLowerCase(transport);
}
}
path.SetLength(questionmark); path.SetLength(questionmark);
} }
@ -625,7 +643,9 @@ PeerConnectionImpl::ConvertRTCConfiguration(const RTCConfiguration& aSrc,
if (!aDst->addTurnServer(host.get(), port, if (!aDst->addTurnServer(host.get(), port,
username.get(), username.get(),
credential.get())) { credential.get(),
(transport.IsEmpty() ?
kNrIceTransportUdp : transport.get()))) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
} else { } else {

View File

@ -126,13 +126,15 @@ public:
} }
bool addTurnServer(const std::string& addr, uint16_t port, bool addTurnServer(const std::string& addr, uint16_t port,
const std::string& username, const std::string& username,
const std::string& pwd) const std::string& pwd,
const std::string& transport)
{ {
// TODO(ekr@rtfm.com): Need support for SASLprep for // TODO(ekr@rtfm.com): Need support for SASLprep for
// username and password. Bug # ??? // username and password. Bug # ???
std::vector<unsigned char> password(pwd.begin(), pwd.end()); std::vector<unsigned char> password(pwd.begin(), pwd.end());
NrIceTurnServer* server(NrIceTurnServer::Create(addr, port, username, password)); NrIceTurnServer* server(NrIceTurnServer::Create(addr, port, username, password,
transport));
if (!server) { if (!server) {
return false; return false;
} }