Line data Source code
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 "nsString.h"
11 :
12 : template <class T> class nsCOMPtr;
13 : class nsIIDNService;
14 :
15 : namespace mozilla {
16 :
17 : /**
18 : * This class implements the identifier used in WebRTC identity. Peers are
19 : * identified using a string in the form [<user>@]<domain>, for instance,
20 : * "user@example.com'. The (optional) user portion is a site-controlled string
21 : * containing any character other than '@'. The domain portion is a valid IDN
22 : * domain name and is compared accordingly.
23 : *
24 : * See: http://tools.ietf.org/html/draft-ietf-rtcweb-security-arch-09#section-5.6.5.3.3.1
25 : */
26 : class PeerIdentity final : public RefCounted<PeerIdentity>
27 : {
28 : public:
29 0 : MOZ_DECLARE_REFCOUNTED_TYPENAME(PeerIdentity)
30 :
31 0 : explicit PeerIdentity(const nsAString& aPeerIdentity)
32 0 : : mPeerIdentity(aPeerIdentity) {}
33 0 : ~PeerIdentity() {}
34 :
35 : bool Equals(const PeerIdentity& aOther) const;
36 : bool Equals(const nsAString& aOtherString) const;
37 0 : const nsString& ToString() const { return mPeerIdentity; }
38 :
39 : private:
40 : static void GetUser(const nsAString& aPeerIdentity, nsAString& aUser);
41 : static void GetHost(const nsAString& aPeerIdentity, nsAString& aHost);
42 :
43 : static void GetNormalizedHost(const nsCOMPtr<nsIIDNService>& aIdnService,
44 : const nsAString& aHost,
45 : nsACString& aNormalizedHost);
46 :
47 : nsString mPeerIdentity;
48 : };
49 :
50 : inline bool
51 0 : operator==(const PeerIdentity& aOne, const PeerIdentity& aTwo)
52 : {
53 0 : return aOne.Equals(aTwo);
54 : }
55 :
56 : inline bool
57 : operator==(const PeerIdentity& aOne, const nsAString& aString)
58 : {
59 : return aOne.Equals(aString);
60 : }
61 :
62 : inline bool
63 : operator!=(const PeerIdentity& aOne, const PeerIdentity& aTwo)
64 : {
65 : return !aOne.Equals(aTwo);
66 : }
67 :
68 : inline bool
69 : operator!=(const PeerIdentity& aOne, const nsAString& aString)
70 : {
71 : return !aOne.Equals(aString);
72 : }
73 :
74 :
75 : } /* namespace mozilla */
76 :
77 : #endif /* PeerIdentity_h */
|