OLD | NEW |
(Empty) | |
| 1 // Copyright 2004 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef WEBRTC_LIBJINGLE_XMPP_JID_H_ |
| 6 #define WEBRTC_LIBJINGLE_XMPP_JID_H_ |
| 7 |
| 8 #include <string> |
| 9 #include "third_party/xmllite/xmlconstants.h" |
| 10 |
| 11 namespace buzz { |
| 12 |
| 13 // The Jid class encapsulates and provides parsing help for Jids. A Jid |
| 14 // consists of three parts: the node, the domain and the resource, e.g.: |
| 15 // |
| 16 // node@domain/resource |
| 17 // |
| 18 // The node and resource are both optional. A valid jid is defined to have |
| 19 // a domain. A bare jid is defined to not have a resource and a full jid |
| 20 // *does* have a resource. |
| 21 class Jid { |
| 22 public: |
| 23 explicit Jid(); |
| 24 explicit Jid(const std::string& jid_string); |
| 25 explicit Jid(const std::string& node_name, |
| 26 const std::string& domain_name, |
| 27 const std::string& resource_name); |
| 28 ~Jid(); |
| 29 |
| 30 const std::string & node() const { return node_name_; } |
| 31 const std::string & domain() const { return domain_name_; } |
| 32 const std::string & resource() const { return resource_name_; } |
| 33 |
| 34 std::string Str() const; |
| 35 Jid BareJid() const; |
| 36 |
| 37 bool IsEmpty() const; |
| 38 bool IsValid() const; |
| 39 bool IsBare() const; |
| 40 bool IsFull() const; |
| 41 |
| 42 bool BareEquals(const Jid& other) const; |
| 43 void CopyFrom(const Jid& jid); |
| 44 bool operator==(const Jid& other) const; |
| 45 bool operator!=(const Jid& other) const { return !operator==(other); } |
| 46 |
| 47 bool operator<(const Jid& other) const { return Compare(other) < 0; }; |
| 48 bool operator>(const Jid& other) const { return Compare(other) > 0; }; |
| 49 |
| 50 int Compare(const Jid & other) const; |
| 51 |
| 52 private: |
| 53 void ValidateOrReset(); |
| 54 |
| 55 static std::string PrepNode(const std::string& node, bool* valid); |
| 56 static char PrepNodeAscii(char ch, bool* valid); |
| 57 static std::string PrepResource(const std::string& start, bool* valid); |
| 58 static char PrepResourceAscii(char ch, bool* valid); |
| 59 static std::string PrepDomain(const std::string& domain, bool* valid); |
| 60 static void PrepDomain(const std::string& domain, |
| 61 std::string* buf, bool* valid); |
| 62 static void PrepDomainLabel( |
| 63 std::string::const_iterator start, std::string::const_iterator end, |
| 64 std::string* buf, bool* valid); |
| 65 static char PrepDomainLabelAscii(char ch, bool *valid); |
| 66 |
| 67 std::string node_name_; |
| 68 std::string domain_name_; |
| 69 std::string resource_name_; |
| 70 }; |
| 71 |
| 72 } |
| 73 |
| 74 #endif // WEBRTC_LIBJINGLE_XMPP_JID_H_ |
OLD | NEW |