gloox 1.0
jid.h
00001 /*
00002   Copyright (c) 2005-2009 by Jakob Schroeter <js@camaya.net>
00003   This file is part of the gloox library. http://camaya.net/gloox
00004 
00005   This software is distributed under a license. The full license
00006   agreement can be found in the file LICENSE in this distribution.
00007   This software may not be copied, modified, sold or distributed
00008   other than expressed in the named license agreement.
00009 
00010   This software is distributed without any warranty.
00011 */
00012 
00013 
00014 
00015 #ifndef JID_H__
00016 #define JID_H__
00017 
00018 #include "macros.h"
00019 
00020 #include <string>
00021 
00022 namespace gloox
00023 {
00030   class GLOOX_API JID
00031   {
00032     public:
00033 
00037       JID() : m_valid( false ) {}
00038 
00043       JID( const std::string& jid ) : m_valid( true ) { setJID( jid ); }
00044 
00048       ~JID() {}
00049 
00055       bool setJID( const std::string& jid );
00056 
00061       const std::string& full() const { return m_full; }
00062 
00067       const std::string& bare() const { return m_bare; }
00068 
00074       JID bareJID() const { return JID( bare() ); }
00075 
00080       bool setUsername( const std::string& username );
00081 
00086       bool setServer( const std::string& server );
00087 
00092       bool setResource( const std::string& resource );
00093 
00098       const std::string& username() const { return m_username; }
00099 
00104       const std::string& server() const { return m_server; }
00105 
00110       const std::string& serverRaw() const { return m_serverRaw; }
00111 
00116       const std::string& resource() const { return m_resource; }
00117 
00122       bool operator==( const std::string& right ) const { return full() == right; }
00123 
00128       bool operator!=( const std::string& right ) const { return full() != right; }
00129 
00134       bool operator==( const JID& right ) const { return full() == right.full(); }
00135 
00140       bool operator!=( const JID& right ) const { return full() != right.full(); }
00141 
00145       operator bool() const { return m_valid; }
00146 
00152       static std::string escapeNode( const std::string& node );
00153 
00159       static std::string unescapeNode( const std::string& node );
00160 
00161     private:
00165       void setStrings() { setBare(); setFull(); }
00166 
00171       void setBare();
00172 
00176       void setFull();
00177 
00178       std::string m_resource;
00179       std::string m_username;
00180       std::string m_server;
00181       std::string m_serverRaw;
00182       std::string m_bare;
00183       std::string m_full;
00184       bool m_valid;
00185 
00186   };
00187 
00188 }
00189 
00190 #endif // JID_H__