jid.cpp

00001 /*
00002   Copyright (c) 2005-2008 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 #include "jid.h"
00015 
00016 #include "prep.h"
00017 
00018 namespace gloox
00019 {
00020 
00021   void JID::setJID( const std::string& jid )
00022   {
00023     if ( jid.empty() )
00024     {
00025       m_bare = m_full = m_server = m_username = m_serverRaw = m_resource = "";
00026       return;
00027     }
00028 
00029     size_t at = jid.find( "@", 0 );
00030     size_t slash = jid.find( "/", 0 );
00031 
00032     if( at == std::string::npos )
00033     {
00034       if( slash == std::string::npos )
00035       {
00036         m_serverRaw = jid;
00037       }
00038       else
00039       {
00040         m_serverRaw = jid.substr( 0, slash );
00041         m_resource = prep::resourceprep( jid.substr( slash + 1 ) );
00042       }
00043     }
00044     else
00045     {
00046       m_username = prep::nodeprep( jid.substr( 0, at ) );
00047       if( slash != std::string::npos )
00048       {
00049         m_serverRaw = jid.substr( at + 1, slash - at - 1 );
00050         m_resource = prep::resourceprep( jid.substr( slash + 1 ) );
00051       }
00052       else
00053       {
00054         m_serverRaw = jid.substr( at + 1 );
00055       }
00056     }
00057     m_server = prep::nameprep( m_serverRaw );
00058     setStrings();
00059   }
00060 
00061   void JID::setUsername( const std::string& username )
00062   {
00063     m_username = prep::nodeprep( username );
00064     setStrings();
00065   }
00066 
00067   void JID::setServer( const std::string& server )
00068   {
00069     m_serverRaw = server;
00070     m_server = prep::nameprep( m_serverRaw );
00071     setStrings();
00072   }
00073 
00074   void JID::setResource( const std::string& resource )
00075   {
00076     m_resource = prep::resourceprep( resource );
00077     setFull();
00078   }
00079 
00080   void JID::setFull()
00081   {
00082     m_full = bare();
00083     if( !m_resource.empty() )
00084       m_full += '/' + m_resource;
00085   }
00086 
00087   void JID::setBare()
00088   {
00089     if( !m_username.empty() )
00090       m_bare = m_username + '@';
00091     else
00092       m_bare = "";
00093     m_bare += m_server;
00094   }
00095 
00096 }

Generated on Mon Dec 7 13:28:19 2009 for gloox by  doxygen 1.6.1