gloox  1.1-svn
jid.h
1 /*
2  Copyright (c) 2005-2009 by Jakob Schroeter <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 
145  operator bool() const { return m_valid; }
146 
152  static std::string escapeNode( const std::string& node );
153 
159  static std::string unescapeNode( const std::string& node );
160 
161  private:
165  void setStrings() { setBare(); setFull(); }
166 
171  void setBare();
172 
176  void setFull();
177 
178  std::string m_resource;
179  std::string m_username;
180  std::string m_server;
181  std::string m_serverRaw;
182  std::string m_bare;
183  std::string m_full;
184  bool m_valid;
185 
186  };
187 
188 }
189 
190 #endif // JID_H__