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