PeerIdentity.h (2063B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * vim: sw=2 ts=2 sts=2 expandtab 3 * This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef PeerIdentity_h 8 #define PeerIdentity_h 9 10 #include "nsISupportsImpl.h" 11 #include "nsString.h" 12 13 namespace mozilla { 14 15 /** 16 * This class implements the identifier used in WebRTC identity. Peers are 17 * identified using a string in the form [<user>@]<domain>, for instance, 18 * "user@example.com'. The (optional) user portion is a site-controlled string 19 * containing any character other than '@'. The domain portion is a valid IDN 20 * domain name and is compared accordingly. 21 * 22 * See: 23 * http://tools.ietf.org/html/draft-ietf-rtcweb-security-arch-09#section-5.6.5.3.3.1 24 */ 25 class PeerIdentity final { 26 public: 27 NS_INLINE_DECL_REFCOUNTING(PeerIdentity) 28 29 explicit PeerIdentity(const nsAString& aPeerIdentity) 30 : mPeerIdentity(aPeerIdentity) {} 31 32 bool Equals(const PeerIdentity& aOther) const; 33 bool Equals(const nsAString& aOtherString) const; 34 const nsString& ToString() const { return mPeerIdentity; } 35 36 private: 37 ~PeerIdentity() = default; 38 static void GetUser(const nsAString& aPeerIdentity, nsAString& aUser); 39 static void GetHost(const nsAString& aPeerIdentity, nsAString& aHost); 40 41 static void GetNormalizedHost(const nsAString& aHost, 42 nsACString& aNormalizedHost); 43 44 nsString mPeerIdentity; 45 }; 46 47 inline bool operator==(const PeerIdentity& aOne, const PeerIdentity& aTwo) { 48 return aOne.Equals(aTwo); 49 } 50 51 inline bool operator==(const PeerIdentity& aOne, const nsAString& aString) { 52 return aOne.Equals(aString); 53 } 54 55 inline bool operator!=(const PeerIdentity& aOne, const PeerIdentity& aTwo) { 56 return !aOne.Equals(aTwo); 57 } 58 59 inline bool operator!=(const PeerIdentity& aOne, const nsAString& aString) { 60 return !aOne.Equals(aString); 61 } 62 63 } /* namespace mozilla */ 64 65 #endif /* PeerIdentity_h */