gloox  1.0.28
jid.h
1 /*
2  Copyright (c) 2005-2023 by Jakob Schröter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 
15 #ifndef JID_H__
16 #define JID_H__
17 
18 #include "macros.h"
19 
20 #include <string>
21 
22 namespace gloox
23 {
30  class GLOOX_API JID
31  {
32  public:
33 
37  JID() : m_valid( false ) {}
38 
43  JID( const std::string& jid ) : m_valid( true ) { setJID( jid ); }
44 
48  ~JID() {}
49 
55  bool setJID( const std::string& jid );
56 
61  const std::string& full() const { return m_full; }
62 
67  const std::string& bare() const { return m_bare; }
68 
74  JID bareJID() const { return JID( bare() ); }
75 
80  bool setUsername( const std::string& username );
81 
86  bool setServer( const std::string& server );
87 
92  bool setResource( const std::string& resource );
93 
98  const std::string& username() const { return m_username; }
99 
104  const std::string& server() const { return m_server; }
105 
110  const std::string& serverRaw() const { return m_serverRaw; }
111 
116  const std::string& resource() const { return m_resource; }
117 
122  bool operator==( const std::string& right ) const { return full() == right; }
123 
128  bool operator!=( const std::string& right ) const { return full() != right; }
129 
134  bool operator==( const JID& right ) const { return full() == right.full(); }
135 
140  bool operator!=( const JID& right ) const { return full() != right.full(); }
141 
148  bool operator<( const JID& right ) const { return full() < right.full(); }
149 
155  bool operator<=( const JID& right ) const { return full() <= right.full(); }
156 
162  bool operator>( const JID& right ) const { return full() > right.full(); }
163 
169  bool operator>=( const JID& right ) const { return full() >= right.full(); }
170 
174  operator bool() const { return m_valid; }
175 
181  static std::string escapeNode( const std::string& node );
182 
188  static std::string unescapeNode( const std::string& node );
189 
190  private:
194  void setStrings() { setBare(); setFull(); }
195 
200  void setBare();
201 
205  void setFull();
206 
207  std::string m_resource;
208  std::string m_username;
209  std::string m_server;
210  std::string m_serverRaw;
211  std::string m_bare;
212  std::string m_full;
213  bool m_valid;
214 
215  };
216 
217 }
218 
219 #endif // JID_H__
An abstraction of a JID.
Definition: jid.h:31
bool operator!=(const std::string &right) const
Definition: jid.h:128
const std::string & server() const
Definition: jid.h:104
~JID()
Definition: jid.h:48
bool operator==(const JID &right) const
Definition: jid.h:134
const std::string & serverRaw() const
Definition: jid.h:110
bool operator<(const JID &right) const
Definition: jid.h:148
JID(const std::string &jid)
Definition: jid.h:43
bool operator==(const std::string &right) const
Definition: jid.h:122
const std::string & resource() const
Definition: jid.h:116
bool operator>=(const JID &right) const
Definition: jid.h:169
bool operator<=(const JID &right) const
Definition: jid.h:155
const std::string & username() const
Definition: jid.h:98
JID()
Definition: jid.h:37
const std::string & full() const
Definition: jid.h:61
bool operator!=(const JID &right) const
Definition: jid.h:140
const std::string & bare() const
Definition: jid.h:67
bool operator>(const JID &right) const
Definition: jid.h:162
JID bareJID() const
Definition: jid.h:74
The namespace for the gloox library.
Definition: adhoc.cpp:28