jid.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #ifndef THIRD_PARTY_LIBJINGLE_XMPP_XMPP_JID_H_
  11. #define THIRD_PARTY_LIBJINGLE_XMPP_XMPP_JID_H_
  12. #include <string>
  13. #include "third_party/libjingle_xmpp/xmllite/xmlconstants.h"
  14. namespace jingle_xmpp {
  15. // The Jid class encapsulates and provides parsing help for Jids. A Jid
  16. // consists of three parts: the node, the domain and the resource, e.g.:
  17. //
  18. // node@domain/resource
  19. //
  20. // The node and resource are both optional. A valid jid is defined to have
  21. // a domain. A bare jid is defined to not have a resource and a full jid
  22. // *does* have a resource.
  23. class Jid {
  24. public:
  25. explicit Jid();
  26. explicit Jid(const std::string& jid_string);
  27. explicit Jid(const std::string& node_name,
  28. const std::string& domain_name,
  29. const std::string& resource_name);
  30. ~Jid();
  31. const std::string & node() const { return node_name_; }
  32. const std::string & domain() const { return domain_name_; }
  33. const std::string & resource() const { return resource_name_; }
  34. std::string Str() const;
  35. Jid BareJid() const;
  36. bool IsEmpty() const;
  37. bool IsValid() const;
  38. bool IsBare() const;
  39. bool IsFull() const;
  40. bool BareEquals(const Jid& other) const;
  41. void CopyFrom(const Jid& jid);
  42. bool operator==(const Jid& other) const;
  43. bool operator!=(const Jid& other) const { return !operator==(other); }
  44. bool operator<(const Jid& other) const { return Compare(other) < 0; }
  45. bool operator>(const Jid& other) const { return Compare(other) > 0; }
  46. int Compare(const Jid & other) const;
  47. private:
  48. void ValidateOrReset();
  49. static std::string PrepNode(const std::string& node, bool* valid);
  50. static char PrepNodeAscii(char ch, bool* valid);
  51. static std::string PrepResource(const std::string& start, bool* valid);
  52. static char PrepResourceAscii(char ch, bool* valid);
  53. static std::string PrepDomain(const std::string& domain, bool* valid);
  54. static void PrepDomain(const std::string& domain,
  55. std::string* buf, bool* valid);
  56. static void PrepDomainLabel(
  57. std::string::const_iterator start, std::string::const_iterator end,
  58. std::string* buf, bool* valid);
  59. static char PrepDomainLabelAscii(char ch, bool *valid);
  60. std::string node_name_;
  61. std::string domain_name_;
  62. std::string resource_name_;
  63. };
  64. }
  65. #endif // THIRD_PARTY_LIBJINGLE_XMPP_XMPP_JID_H_