00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "jid.h"
00014 #include "prep.h"
00015 #include "gloox.h"
00016
00017 namespace gloox
00018 {
00019
00020 bool JID::setJID( const std::string& jid )
00021 {
00022 if ( jid.empty() )
00023 {
00024 m_bare = m_full = m_server = m_username = m_serverRaw = m_resource = EmptyString;
00025 m_valid = false;
00026 return false;
00027 }
00028
00029 const std::string::size_type at = jid.find( '@' );
00030 const std::string::size_type slash = jid.find( '/', at == std::string::npos ? 0 : at );
00031
00032 if( at != std::string::npos && !( m_valid = prep::nodeprep( jid.substr( 0, at ), m_username ) ) )
00033 return false;
00034
00035 m_serverRaw = jid.substr( at == std::string::npos ? 0 : at + 1, slash - at - 1 );
00036 if( !( m_valid = prep::nameprep( m_serverRaw, m_server ) ) )
00037 return false;
00038
00039 if( slash != std::string::npos
00040 && !( m_valid = prep::resourceprep( jid.substr( slash + 1 ), m_resource ) ) )
00041 return false;
00042
00043 setStrings();
00044
00045 return m_valid;
00046 }
00047
00048 bool JID::setUsername( const std::string& uname )
00049 {
00050 m_valid = prep::nodeprep( uname, m_username );
00051 setStrings();
00052 return m_valid;
00053 }
00054
00055 bool JID::setServer( const std::string& serv )
00056 {
00057 m_serverRaw = serv;
00058 m_valid = prep::nameprep( m_serverRaw, m_server );
00059 setStrings();
00060 return m_valid;
00061 }
00062
00063 bool JID::setResource( const std::string& res )
00064 {
00065 m_valid = prep::resourceprep( res, m_resource );
00066 setFull();
00067 return m_valid;
00068 }
00069
00070 void JID::setFull()
00071 {
00072 m_full = bare();
00073 if( !m_resource.empty() )
00074 m_full += '/' + m_resource;
00075 }
00076
00077 void JID::setBare()
00078 {
00079 if( !m_username.empty() )
00080 m_bare = m_username + '@';
00081 else
00082 m_bare = EmptyString;
00083 m_bare += m_server;
00084 }
00085
00086 }