Bug 928930 - don't define std::string variables in nricectx.h; r=ekr
authorNathan Froyd <froydnj@mozilla.com>
Mon, 27 Jan 2014 11:02:51 -0500
changeset 184280 ad04260889bfed4f04da0c3357cb1db92a48b3c1
parent 184279 fa9b60c8811896cb9ef2b498f9ff88486bdad1a2
child 184281 f5fff3a6e9396b1119c2a14251bb815bb38779e9
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersekr
bugs928930
milestone30.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 928930 - don't define std::string variables in nricectx.h; r=ekr
media/mtransport/nricectx.cpp
media/mtransport/nricectx.h
media/mtransport/test/ice_unittest.cpp
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h
--- a/media/mtransport/nricectx.cpp
+++ b/media/mtransport/nricectx.cpp
@@ -86,16 +86,19 @@ extern "C" {
 #include "nr_socket_prsock.h"
 #include "nrinterfaceprioritizer.h"
 #include "rlogringbuffer.h"
 
 namespace mozilla {
 
 MOZ_MTLOG_MODULE("mtransport")
 
+const char kNrIceTransportUdp[] = "udp";
+const char kNrIceTransportTcp[] = "tcp";
+
 static bool initialized = false;
 
 // Implement NSPR-based crypto algorithms
 static int nr_crypto_nss_random_bytes(UCHAR *buf, int len) {
   ScopedPK11SlotInfo slot(PK11_GetInternalSlot());
   if (!slot)
     return R_INTERNAL;
 
@@ -181,24 +184,24 @@ static nr_ice_crypto_vtbl nr_ice_crypto_
   nr_crypto_nss_hmac,
   nr_crypto_nss_md5
 };
 
 
 
 
 nsresult NrIceStunServer::ToNicerStunStruct(nr_ice_stun_server *server,
-                                            std::string transport) const {
+                                            const char *transport) const {
   int r;
   int transport_int;
 
   memset(server, 0, sizeof(nr_ice_stun_server));
-  if (transport == kNrIceTransportUdp) {
+  if (strcmp(transport, kNrIceTransportUdp) == 0) {
     transport_int = IPPROTO_UDP;
-  } else if (transport == kNrIceTransportTcp) {
+  } else if (strcmp(transport, kNrIceTransportTcp) == 0) {
     transport_int = IPPROTO_TCP;
   } else {
     MOZ_ASSERT(false);
     return NS_ERROR_FAILURE;
   }
 
   if (has_addr_) {
     r = nr_praddr_to_transport_addr(&addr_, &server->u.addr,
--- a/media/mtransport/nricectx.h
+++ b/media/mtransport/nricectx.h
@@ -76,18 +76,18 @@ typedef struct nr_ice_turn_server_ nr_ic
 typedef struct nr_resolver_ nr_resolver;
 
 typedef void* NR_SOCKET;
 
 namespace mozilla {
 
 class NrIceMediaStream;
 
-const std::string kNrIceTransportUdp("udp");
-const std::string kNrIceTransportTcp("tcp");
+extern const char kNrIceTransportUdp[];
+extern const char kNrIceTransportTcp[];
 
 class NrIceStunServer {
  public:
   NrIceStunServer(const PRNetAddr& addr) : has_addr_(true) {
     memcpy(&addr_, &addr, sizeof(addr));
   }
 
    // The main function to use. Will take either an address or a hostname.
@@ -98,17 +98,17 @@ class NrIceStunServer {
     nsresult rv = server->Init(addr, port);
     if (NS_FAILED(rv))
       return nullptr;
 
     return server.forget();
   }
 
   nsresult ToNicerStunStruct(nr_ice_stun_server *server,
-                             const std::string transport =
+                             const char* transport =
                              kNrIceTransportUdp) const;
 
  protected:
   NrIceStunServer() : addr_() {}
 
   nsresult Init(const std::string& addr, uint16_t port) {
     PRStatus status = PR_StringToNetAddr(addr.c_str(), &addr_);
     if (status == PR_SUCCESS) {
@@ -135,38 +135,38 @@ class NrIceStunServer {
   PRNetAddr addr_;
 };
 
 class NrIceTurnServer : public NrIceStunServer {
  public:
   static NrIceTurnServer *Create(const std::string& addr, uint16_t port,
                                  const std::string& username,
                                  const std::vector<unsigned char>& password,
-                                 const std::string& transport = kNrIceTransportUdp) {
+                                 const char *transport = kNrIceTransportUdp) {
     ScopedDeletePtr<NrIceTurnServer> server(
         new NrIceTurnServer(username, password, transport));
 
     nsresult rv = server->Init(addr, port);
     if (NS_FAILED(rv))
       return nullptr;
 
     return server.forget();
   }
 
   nsresult ToNicerTurnStruct(nr_ice_turn_server *server) const;
 
  private:
   NrIceTurnServer(const std::string& username,
                   const std::vector<unsigned char>& password,
-                  const std::string& transport) :
+                  const char *transport) :
       username_(username), password_(password), transport_(transport) {}
 
   std::string username_;
   std::vector<unsigned char> password_;
-  std::string transport_;
+  const char* transport_;
 };
 
 class NrIceCtx {
  public:
   enum ConnectionState { ICE_CTX_INIT,
                          ICE_CTX_CHECKING,
                          ICE_CTX_OPEN,
                          ICE_CTX_FAILED
--- a/media/mtransport/test/ice_unittest.cpp
+++ b/media/mtransport/test/ice_unittest.cpp
@@ -184,26 +184,26 @@ class IceTestPeer : public sigslot::has_
                                                                     port));
     stun_servers.push_back(*server);
     ASSERT_TRUE(NS_SUCCEEDED(ice_ctx_->SetStunServers(stun_servers)));
   }
 
   void SetTurnServer(const std::string addr, uint16_t port,
                      const std::string username,
                      const std::string password,
-                     const std::string transport) {
+                     const char* transport) {
     std::vector<unsigned char> password_vec(password.begin(), password.end());
     SetTurnServer(addr, port, username, password_vec, transport);
   }
 
 
   void SetTurnServer(const std::string addr, uint16_t port,
                      const std::string username,
                      const std::vector<unsigned char> password,
-                     const std::string transport) {
+                     const char* transport) {
     std::vector<NrIceTurnServer> turn_servers;
     ScopedDeletePtr<NrIceTurnServer> server(NrIceTurnServer::Create(
         addr, port, username, password, transport));
     turn_servers.push_back(*server);
     ASSERT_TRUE(NS_SUCCEEDED(ice_ctx_->SetTurnServers(turn_servers)));
   }
 
   void SetTurnServers(const std::vector<NrIceTurnServer> servers) {
@@ -778,17 +778,17 @@ class IceConnectTest : public ::testing:
         return false;
     }
     return true;
   }
 
   void SetTurnServer(const std::string addr, uint16_t port,
                      const std::string username,
                      const std::string password,
-                     const std::string transport = kNrIceTransportUdp) {
+                     const char* transport = kNrIceTransportUdp) {
     p1_->SetTurnServer(addr, port, username, password, transport);
     p2_->SetTurnServer(addr, port, username, password, transport);
   }
 
   void SetTurnServers(const std::vector<NrIceTurnServer>& servers) {
     p1_->SetTurnServers(servers);
     p2_->SetTurnServers(servers);
   }
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h
@@ -126,17 +126,17 @@ public:
       return false;
     }
     addStunServer(*server);
     return true;
   }
   bool addTurnServer(const std::string& addr, uint16_t port,
                      const std::string& username,
                      const std::string& pwd,
-                     const std::string& transport)
+                     const char* transport)
   {
     // TODO(ekr@rtfm.com): Need support for SASLprep for
     // username and password. Bug # ???
     std::vector<unsigned char> password(pwd.begin(), pwd.end());
 
     NrIceTurnServer* server(NrIceTurnServer::Create(addr, port, username, password,
                                                     transport));
     if (!server) {