diff --git a/libs/libgloox/adhoc.cpp b/libs/libgloox/adhoc.cpp index 629ed37..708d3b2 100644 --- a/libs/libgloox/adhoc.cpp +++ b/libs/libgloox/adhoc.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -15,11 +15,14 @@ #include "adhochandler.h" #include "adhoccommandprovider.h" #include "disco.h" +#include "dataform.h" #include "error.h" +#include "iodata.h" #include "discohandler.h" #include "clientbase.h" -#include "dataform.h" +#include "adhocplugin.h" #include "util.h" +#include "mutexguard.h" namespace gloox { @@ -78,37 +81,37 @@ namespace gloox // ---- Adhoc::Command ---- Adhoc::Command::Command( const std::string& node, Adhoc::Command::Action action, - DataForm* form ) - : StanzaExtension( ExtAdhocCommand ), m_node( node ), m_form( form ), m_action( action ), + AdhocPlugin* plugin ) + : StanzaExtension( ExtAdhocCommand ), m_node( node ), m_plugin( plugin ), m_action( action ), m_status( InvalidStatus ), m_actions( 0 ) { } Adhoc::Command::Command( const std::string& node, const std::string& sessionid, Status status, - DataForm* form ) + AdhocPlugin* plugin ) : StanzaExtension( ExtAdhocCommand ), m_node( node ), m_sessionid( sessionid ), - m_form( form ), m_action( InvalidAction ), m_status( status ), m_actions( 0 ) + m_plugin( plugin ), m_action( InvalidAction ), m_status( status ), m_actions( 0 ) { } Adhoc::Command::Command( const std::string& node, const std::string& sessionid, Adhoc::Command::Action action, - DataForm* form ) + AdhocPlugin* plugin ) : StanzaExtension( ExtAdhocCommand ), m_node( node ), m_sessionid( sessionid ), - m_form( form ), m_action( action ), m_actions( 0 ) + m_plugin( plugin ), m_action( action ), m_actions( 0 ) { } Adhoc::Command::Command( const std::string& node, const std::string& sessionid, Status status, Action executeAction, int allowedActions, - DataForm* form ) + AdhocPlugin* plugin ) : StanzaExtension( ExtAdhocCommand ), m_node( node ), m_sessionid( sessionid ), - m_form( form ), m_action( executeAction ), m_status( status ), m_actions( allowedActions ) + m_plugin( plugin ), m_action( executeAction ), m_status( status ), m_actions( allowedActions ) { } Adhoc::Command::Command( const Tag* tag ) - : StanzaExtension( ExtAdhocCommand ), m_form( 0 ), m_actions( 0 ) + : StanzaExtension( ExtAdhocCommand ), m_plugin( 0 ), m_actions( 0 ) { if( !tag || tag->name() != "command" || tag->xmlns() != XMLNS_ADHOC_COMMANDS ) return; @@ -141,13 +144,19 @@ namespace gloox Tag* x = tag->findChild( "x", "xmlns", XMLNS_X_DATA ); if( x ) - m_form = new DataForm( x ); + m_plugin = new DataForm( x ); + else + { + Tag* x = tag->findChild( "iodata", "xmlns", XMLNS_IODATA ); + if( x ) + m_plugin = new IOData( x ); + } } Adhoc::Command::~Command() { util::clearList( m_notes ); - delete m_form; + delete m_plugin; } const std::string& Adhoc::Command::filterString() const @@ -200,8 +209,8 @@ namespace gloox if ( !m_sessionid.empty() ) c->addAttribute( "sessionid", m_sessionid ); - if( m_form && *m_form ) - c->addChild( m_form->tag() ); + if( m_plugin && *m_plugin ) + c->addChild( m_plugin->tag() ); NoteList::const_iterator it = m_notes.begin(); for( ; it != m_notes.end(); ++it ) @@ -227,6 +236,10 @@ namespace gloox Adhoc::~Adhoc() { + m_adhocTrackMapMutex.lock(); + m_adhocTrackMap.clear(); + m_adhocTrackMapMutex.unlock(); + if( !m_parent || !m_parent->disco() ) return; @@ -306,27 +319,32 @@ namespace gloox if( context != ExecuteAdhocCommand ) return; + m_adhocTrackMapMutex.lock(); AdhocTrackMap::iterator it = m_adhocTrackMap.find( iq.id() ); - if( it == m_adhocTrackMap.end() || (*it).second.context != context + bool haveIdHandler = ( it != m_adhocTrackMap.end() ); + m_adhocTrackMapMutex.unlock(); + if( !haveIdHandler || (*it).second.context != context || (*it).second.remote != iq.from() ) return; switch( iq.subtype() ) { case IQ::Error: - (*it).second.ah->handleAdhocError( iq.from(), iq.error() ); + (*it).second.ah->handleAdhocError( iq.from(), iq.error(), (*it).second.handlerContext ); break; case IQ::Result: { const Adhoc::Command* ac = iq.findExtension( ExtAdhocCommand ); if( ac ) - (*it).second.ah->handleAdhocExecutionResult( iq.from(), *ac ); + (*it).second.ah->handleAdhocExecutionResult( iq.from(), *ac, (*it).second.handlerContext ); break; } default: break; } + m_adhocTrackMapMutex.lock(); m_adhocTrackMap.erase( it ); + m_adhocTrackMapMutex.unlock(); } void Adhoc::registerAdhocCommandProvider( AdhocCommandProvider* acp, const std::string& command, @@ -345,6 +363,8 @@ namespace gloox if( context != CheckAdhocSupport ) return; + util::MutexGuard m( m_adhocTrackMapMutex ); + AdhocTrackMap::iterator it = m_adhocTrackMap.begin(); for( ; it != m_adhocTrackMap.end() && (*it).second.context != context && (*it).second.remote != from; ++it ) @@ -352,7 +372,7 @@ namespace gloox if( it == m_adhocTrackMap.end() ) return; - (*it).second.ah->handleAdhocSupport( from, info.hasFeature( XMLNS_ADHOC_COMMANDS ) ); + (*it).second.ah->handleAdhocSupport( from, info.hasFeature( XMLNS_ADHOC_COMMANDS ), (*it).second.handlerContext ); m_adhocTrackMap.erase( it ); } @@ -361,6 +381,8 @@ namespace gloox if( context != FetchAdhocCommands ) return; + util::MutexGuard m( m_adhocTrackMapMutex ); + AdhocTrackMap::iterator it = m_adhocTrackMap.begin(); for( ; it != m_adhocTrackMap.end(); ++it ) { @@ -373,7 +395,7 @@ namespace gloox { commands[(*it2)->node()] = (*it2)->name(); } - (*it).second.ah->handleAdhocCommands( from, commands ); + (*it).second.ah->handleAdhocCommands( from, commands, (*it).second.handlerContext ); m_adhocTrackMap.erase( it ); break; @@ -383,19 +405,28 @@ namespace gloox void Adhoc::handleDiscoError( const JID& from, const Error* error, int context ) { - AdhocTrackMap::iterator it = m_adhocTrackMap.begin(); - for( ; it != m_adhocTrackMap.end(); ++it ) + util::MutexGuard m( m_adhocTrackMapMutex ); + for( AdhocTrackMap::iterator it = m_adhocTrackMap.begin(); it != m_adhocTrackMap.end(); ) { if( (*it).second.context == context && (*it).second.remote == from ) { - (*it).second.ah->handleAdhocError( from, error ); + (*it).second.ah->handleAdhocError( from, error, (*it).second.handlerContext ); - m_adhocTrackMap.erase( it ); + // Normally we'd just assign it to the return value of the .erase() call, + // which is either the next element, or .end(). However, + // it's only since C++11 that this works; C++03 version returns void. + // So instead, we do a post-increment. this increments the iterator to point + // to the next element, then passes a copy of the old iterator (that is to the item to be deleted) + m_adhocTrackMap.erase( it++ ); + } + else + { + ++it; } } } - void Adhoc::checkSupport( const JID& remote, AdhocHandler* ah ) + void Adhoc::checkSupport( const JID& remote, AdhocHandler* ah, int context ) { if( !remote || !ah || !m_parent || !m_parent->disco() ) return; @@ -404,12 +435,15 @@ namespace gloox track.remote = remote; track.context = CheckAdhocSupport; track.ah = ah; + track.handlerContext = context; const std::string& id = m_parent->getID(); + m_adhocTrackMapMutex.lock(); m_adhocTrackMap[id] = track; + m_adhocTrackMapMutex.unlock(); m_parent->disco()->getDiscoInfo( remote, EmptyString, this, CheckAdhocSupport, id ); } - void Adhoc::getCommands( const JID& remote, AdhocHandler* ah ) + void Adhoc::getCommands( const JID& remote, AdhocHandler* ah, int context ) { if( !remote || !ah || !m_parent || !m_parent->disco() ) return; @@ -418,12 +452,15 @@ namespace gloox track.remote = remote; track.context = FetchAdhocCommands; track.ah = ah; + track.handlerContext = context; const std::string& id = m_parent->getID(); + m_adhocTrackMapMutex.lock(); m_adhocTrackMap[id] = track; + m_adhocTrackMapMutex.unlock(); m_parent->disco()->getDiscoItems( remote, XMLNS_ADHOC_COMMANDS, this, FetchAdhocCommands, id ); } - void Adhoc::execute( const JID& remote, const Adhoc::Command* command, AdhocHandler* ah ) + void Adhoc::execute( const JID& remote, const Adhoc::Command* command, AdhocHandler* ah, int context ) { if( !remote || !command || !m_parent || !ah ) return; @@ -437,7 +474,10 @@ namespace gloox track.context = ExecuteAdhocCommand; track.session = command->sessionID(); track.ah = ah; + track.handlerContext = context; + m_adhocTrackMapMutex.lock(); m_adhocTrackMap[id] = track; + m_adhocTrackMapMutex.unlock(); m_parent->send( iq, this, ExecuteAdhocCommand ); } diff --git a/libs/libgloox/adhoc.h b/libs/libgloox/adhoc.h index 849fbf8..d2fe7af 100644 --- a/libs/libgloox/adhoc.h +++ b/libs/libgloox/adhoc.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -15,12 +15,13 @@ #ifndef ADHOC_H__ #define ADHOC_H__ -#include "dataform.h" +#include "adhocplugin.h" #include "disco.h" #include "disconodehandler.h" #include "discohandler.h" #include "iqhandler.h" #include "stanzaextension.h" +#include "mutex.h" #include #include @@ -35,7 +36,7 @@ namespace gloox class AdhocCommandProvider; /** - * @brief This class implements a provider for XEP-0050 (Ad-hoc Commands). + * @brief This class implements a provider for @xep{0050} (Ad-hoc Commands). * * The current, not complete, implementation is probably best suited for fire-and-forget * type of commands. Any additional feature, like multiple stages, etc., would have to be @@ -75,16 +76,16 @@ namespace gloox * ...TBC... * * XEP version: 1.2 - * @author Jakob Schroeter + * @author Jakob Schröter */ class GLOOX_API Adhoc : public DiscoNodeHandler, public DiscoHandler, public IqHandler { public: /** - * @brief An abstraction of an Adhoc Command element (from Adhoc Commands, XEP-0050) + * @brief An abstraction of an Adhoc Command element (from Adhoc Commands, @xep{0050}) * as a StanzaExtension. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API Command : public StanzaExtension @@ -123,7 +124,7 @@ namespace gloox /** * An abstraction of a command note. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API Note @@ -203,11 +204,11 @@ namespace gloox * @param node The node (command) to perform the action on. * @param sessionid The session ID of an already running adhoc command session. * @param action The action to perform. - * @param form An optional DataForm to include in the request. Will be deleted in Command's + * @param plugin An optional AdhocPlugin (e.g. DataForm) to include in the request. Will be deleted in Command's * destructor. */ Command( const std::string& node, const std::string& sessionid, Action action, - DataForm* form = 0 ); + AdhocPlugin* plugin = 0 ); /** * Creates a Command object that can be used to perform the provided Action. @@ -215,11 +216,11 @@ namespace gloox * @param node The node (command) to perform the action on. * @param sessionid The (possibly newly created) session ID of the adhoc command session. * @param status The execution status. - * @param form An optional DataForm to include in the reply. Will be deleted in Command's + * @param plugin An optional AdhocPlugin (e.g. DataForm) to include in the reply. Will be deleted in Command's * destructor. */ Command( const std::string& node, const std::string& sessionid, Status status, - DataForm* form = 0 ); + AdhocPlugin* plugin = 0 ); /** * Creates a Command object that can be used to perform the provided Action. @@ -230,12 +231,12 @@ namespace gloox * @param status The execution status. * @param executeAction The action to execute. * @param allowedActions Allowed reply actions. - * @param form An optional DataForm to include in the reply. Will be deleted in Command's + * @param plugin An optional AdhocPlugin (e.g. DataForm) to include in the reply. Will be deleted in Command's * destructor. */ Command( const std::string& node, const std::string& sessionid, Status status, Action executeAction, int allowedActions = Complete, - DataForm* form = 0 ); + AdhocPlugin* plugin = 0 ); /** * Creates a Command object that can be used to perform the provided Action. @@ -243,11 +244,11 @@ namespace gloox * (single or multi stage). * @param node The node (command) to perform the action on. * @param action The action to perform. - * @param form An optional DataForm to include in the request. Will be deleted in Command's + * @param plugin An optional AdhocPlugin (e.g. DataForm) to include in the request. Will be deleted in Command's * destructor. */ Command( const std::string& node, Action action, - DataForm* form = 0 ); + AdhocPlugin* plugin = 0 ); /** * Creates a Command object from the given Tag. @@ -306,10 +307,17 @@ namespace gloox void addNote( const Note* note ) { m_notes.push_back( note ); } /** - * Returns the command's embedded DataForm. - * @return The command's embedded DataForm. May be 0. + * Returns the command's embedded AdhocPlugin (e.g. DataForm). + * @return The command's embedded AdhocPlugin (e.g. DataForm). May be 0. + * @note This will be removed in 1.1. Use plugin() instead. */ - const DataForm* form() const { return m_form; } + GLOOX_DEPRECATED const AdhocPlugin* form() const { return m_plugin; } + + /** + * Returns the command's embedded AdhocPlugin (e.g. DataForm). + * @return The command's embedded AdhocPlugin (e.g. DataForm). May be 0. + */ + const AdhocPlugin* plugin() const { return m_plugin; } // reimplemented from StanzaExtension virtual const std::string& filterString() const; @@ -334,7 +342,7 @@ namespace gloox c->m_node = m_node; c->m_sessionid = m_sessionid; - c->m_form = m_form ? static_cast( m_form->clone() ) : 0; + c->m_plugin = m_plugin ? static_cast( m_plugin->clone() ) : 0; c->m_action = m_action; c->m_status = m_status; c->m_actions = m_actions; @@ -350,7 +358,7 @@ namespace gloox std::string m_node; std::string m_sessionid; - DataForm* m_form; + AdhocPlugin* m_plugin; Action m_action; Status m_status; int m_actions; @@ -372,16 +380,18 @@ namespace gloox * This function queries the given remote entity for Adhoc Commands support. * @param remote The remote entity's JID. * @param ah The object handling the result of this request. + * @param context A user defined context. */ - void checkSupport( const JID& remote, AdhocHandler* ah ); + void checkSupport( const JID& remote, AdhocHandler* ah, int context = 0 ); /** * Retrieves a list of commands from the remote entity. You should check whether the remote * entity actually supports Adhoc Commands by means of checkSupport(). * @param remote The remote entity's JID. * @param ah The object handling the result of this request. + * @param context A user defined context. */ - void getCommands( const JID& remote, AdhocHandler* ah ); + void getCommands( const JID& remote, AdhocHandler* ah, int context = 0 ); /** * Executes or continues the given command on the given remote entity. @@ -392,14 +402,15 @@ namespace gloox * @param remote The remote entity's JID. * @param command The command to execute. * @param ah The object handling the result of this request. + * @param context A user defined context. */ - void execute( const JID& remote, const Adhoc::Command* command, AdhocHandler* ah ); + void execute( const JID& remote, const Adhoc::Command* command, AdhocHandler* ah, int context = 0 ); /** * Use this function to respond to an execution request submitted by means * of AdhocCommandProvider::handleAdhocCommand(). * It is recommended to use - * Command( const std::string&, const std::string&, Status, DataForm* ) + * Command( const std::string&, const std::string&, Status, AdhocPlugin* ) * to construct the @c command object. * Optionally, an Error object can be included. In that case the IQ sent is of type @c error. * @param remote The requester's JID. @@ -411,8 +422,8 @@ namespace gloox /** * Using this function, you can register a AdhocCommandProvider -derived object as - * handler for a specific Ad-hoc Command as defined in XEP-0050. - * @param acp The obejct to register as handler for the specified command. + * handler for a specific Ad-hoc Command as defined in @xep{0050}. + * @param acp The object to register as handler for the specified command. * @param command The node name of the command. Will be announced in disco#items. * @param name The natural-language name of the command. Will be announced in disco#items. */ @@ -471,9 +482,11 @@ namespace gloox AdhocContext context; std::string session; AdhocHandler* ah; + int handlerContext; }; typedef std::map AdhocTrackMap; AdhocTrackMap m_adhocTrackMap; + util::Mutex m_adhocTrackMapMutex; ClientBase* m_parent; diff --git a/libs/libgloox/adhoccommandprovider.h b/libs/libgloox/adhoccommandprovider.h index 97bd937..508f6eb 100644 --- a/libs/libgloox/adhoccommandprovider.h +++ b/libs/libgloox/adhoccommandprovider.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -27,11 +27,11 @@ namespace gloox { /** - * @brief A virtual interface for an Ad-hoc Command Provider according to XEP-0050. + * @brief A virtual interface for an Ad-hoc Command Provider according to @xep{0050}. * * Derived classes can be registered as Command Providers with the Adhoc object. * - * @author Jakob Schroeter + * @author Jakob Schröter */ class GLOOX_API AdhocCommandProvider { diff --git a/libs/libgloox/adhochandler.h b/libs/libgloox/adhochandler.h index 8b83065..7510c1d 100644 --- a/libs/libgloox/adhochandler.h +++ b/libs/libgloox/adhochandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -21,12 +21,12 @@ namespace gloox { /** - * @brief A virtual interface for an Ad-hoc Command users according to XEP-0050. + * @brief A virtual interface for an Ad-hoc Command users according to @xep{0050}. * * Derived classes can be registered with the Adhoc object to receive notifications * about Adhoc Commands remote entities support. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API AdhocHandler @@ -41,17 +41,19 @@ namespace gloox * This function is called in response to a call to Adhoc::checkSupport(). * @param remote The queried remote entity's JID. * @param support Whether the remote entity supports Adhoc Commands. + * @param context A user defined context. */ - virtual void handleAdhocSupport( const JID& remote, bool support ) = 0; + virtual void handleAdhocSupport( const JID& remote, bool support, int context ) = 0; /** * This function is called in response to a call to Adhoc::getCommands() * and delivers a list of supported commands. * @param remote The queried remote entity's JID. * @param commands A map of supported commands and their human-readable name. + * @param context A user defined context. * The map may be empty. */ - virtual void handleAdhocCommands( const JID& remote, const StringMap& commands ) = 0; + virtual void handleAdhocCommands( const JID& remote, const StringMap& commands, int context ) = 0; /** * This function is called in response to a call to Adhoc::getCommands() or @@ -59,15 +61,17 @@ namespace gloox * an error. * @param remote The queried remote entity's JID. * @param error The error condition. May be 0. + * @param context A user defined context. */ - virtual void handleAdhocError( const JID& remote, const Error* error ) = 0; + virtual void handleAdhocError( const JID& remote, const Error* error, int context ) = 0; /** * This function is called in response to a remote command execution. * @param remote The remote entity's JID. * @param command The command being executed. + * @param context A user defined context. */ - virtual void handleAdhocExecutionResult( const JID& remote, const Adhoc::Command& command ) = 0; + virtual void handleAdhocExecutionResult( const JID& remote, const Adhoc::Command& command, int context ) = 0; }; } diff --git a/libs/libgloox/amp.cpp b/libs/libgloox/amp.cpp index 3ff2c2c..1014012 100644 --- a/libs/libgloox/amp.cpp +++ b/libs/libgloox/amp.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/amp.h b/libs/libgloox/amp.h index dc44d09..f9cd570 100644 --- a/libs/libgloox/amp.h +++ b/libs/libgloox/amp.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -28,11 +28,11 @@ namespace gloox class Tag; /** - * @brief This is an implementation of XEP-0079 (Advanced Message Processing) + * @brief This is an implementation of @xep{0079} (Advanced Message Processing) * as a StanzaExtension. * * XEP Version: 1.2 - * @author Jakob Schroeter + * @author Jakob Schröter * @author Vincent Thomasset * @since 1.0 */ @@ -110,7 +110,7 @@ namespace gloox /** * Describes an AMP rule. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API Rule @@ -125,7 +125,7 @@ namespace gloox /** * Creates a new AMP rule object with a condition of 'expire-at'. - * @param date The expiry date/time in the format defined in XEP-0082. + * @param date The expiry date/time in the format defined in @xep{0082}. * @param action The rule's action. */ Rule( const std::string& date, ActionType action ); diff --git a/libs/libgloox/annotations.cpp b/libs/libgloox/annotations.cpp index bc3ac04..d3ac006 100644 --- a/libs/libgloox/annotations.cpp +++ b/libs/libgloox/annotations.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/annotations.h b/libs/libgloox/annotations.h index ff65ba0..1751fb9 100644 --- a/libs/libgloox/annotations.h +++ b/libs/libgloox/annotations.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -30,7 +30,7 @@ namespace gloox class Tag; /** - * @brief This is an implementation of XEP-0145 (Annotations). + * @brief This is an implementation of @xep{0145} (Annotations). * * You can use this class to store arbitrary notes about a roster item on the server * (and to retrieve them later on). @@ -88,7 +88,7 @@ namespace gloox * } * @endcode * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.3 */ class GLOOX_API Annotations : public PrivateXML, public PrivateXMLHandler diff --git a/libs/libgloox/annotationshandler.h b/libs/libgloox/annotationshandler.h index 99178ea..93d0368 100644 --- a/libs/libgloox/annotationshandler.h +++ b/libs/libgloox/annotationshandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -43,7 +43,7 @@ namespace gloox * @brief A virtual interface which can be reimplemented to receive notes with help of * the Annotations object. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.3 */ class GLOOX_API AnnotationsHandler diff --git a/libs/libgloox/attention.cpp b/libs/libgloox/attention.cpp index 437e804..5df9b14 100644 --- a/libs/libgloox/attention.cpp +++ b/libs/libgloox/attention.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2009 by Jakob Schroeter + Copyright (c) 2009-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/attention.h b/libs/libgloox/attention.h index 1a81af5..b7c93ff 100644 --- a/libs/libgloox/attention.h +++ b/libs/libgloox/attention.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2009 by Jakob Schroeter + Copyright (c) 2009-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -26,9 +26,9 @@ namespace gloox class Tag; /** - * @brief This is an implementation of XEP-0224 as a StanzaExtension. + * @brief This is an implementation of @xep{0224} as a StanzaExtension. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API Attention : public StanzaExtension diff --git a/libs/libgloox/base64.cpp b/libs/libgloox/base64.cpp index 3c0253f..d442281 100644 --- a/libs/libgloox/base64.cpp +++ b/libs/libgloox/base64.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/base64.h b/libs/libgloox/base64.h index 158528f..ede3bb4 100644 --- a/libs/libgloox/base64.h +++ b/libs/libgloox/base64.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -24,7 +24,7 @@ namespace gloox /** * @brief An implementation of the Base64 data encoding (RFC 3548) * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.8 */ namespace Base64 diff --git a/libs/libgloox/bookmarkhandler.h b/libs/libgloox/bookmarkhandler.h index 141b3f9..b63867b 100644 --- a/libs/libgloox/bookmarkhandler.h +++ b/libs/libgloox/bookmarkhandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -58,7 +58,7 @@ namespace gloox * @brief A virtual interface which can be reimplemented to receive bookmarks with help of a * BookmarkStorage object. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.3 */ class GLOOX_API BookmarkHandler diff --git a/libs/libgloox/bookmarkstorage.cpp b/libs/libgloox/bookmarkstorage.cpp index a5c1904..acd1259 100644 --- a/libs/libgloox/bookmarkstorage.cpp +++ b/libs/libgloox/bookmarkstorage.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/bookmarkstorage.h b/libs/libgloox/bookmarkstorage.h index c3c7fb0..fac00e1 100644 --- a/libs/libgloox/bookmarkstorage.h +++ b/libs/libgloox/bookmarkstorage.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -30,7 +30,7 @@ namespace gloox class Tag; /** - * @brief This is an implementation of XEP-0048 (Bookmark Storage). + * @brief This is an implementation of @xep{0048} (Bookmark Storage). * * You can use this class to store bookmarks to multi-user chat rooms or ordinary URLs * on the server (and to retrieve them later on). @@ -91,7 +91,7 @@ namespace gloox * } * @endcode * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.3 */ class GLOOX_API BookmarkStorage : public PrivateXML, public PrivateXMLHandler diff --git a/libs/libgloox/bytestream.h b/libs/libgloox/bytestream.h index b790f51..ed6bdc6 100644 --- a/libs/libgloox/bytestream.h +++ b/libs/libgloox/bytestream.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -30,7 +30,7 @@ namespace gloox * Used as a base class for InBand Bytestreams as well as SOCKS5 Bytestreams. * You should not need to use this class directly. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API Bytestream diff --git a/libs/libgloox/bytestreamdatahandler.h b/libs/libgloox/bytestreamdatahandler.h index 8f0ff0a..cb7771e 100644 --- a/libs/libgloox/bytestreamdatahandler.h +++ b/libs/libgloox/bytestreamdatahandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -26,14 +26,14 @@ namespace gloox /** * @brief A virtual interface that allows implementors to receive data - * sent over a SOCKS5 Bytestream as defined in XEP-0066, or an In-Band Bytestream - * as defined in XEP-0047. You'll also need it for sending of data. + * sent over a SOCKS5 Bytestream as defined in @xep{0066}, or an In-Band Bytestream + * as defined in @xep{0047}. You'll also need it for sending of data. * * An BytestreamDataHandler is registered with a Bytestream. * * See SIProfileFT for more information regarding file transfer. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API BytestreamDataHandler diff --git a/libs/libgloox/bytestreamhandler.h b/libs/libgloox/bytestreamhandler.h index a083f5b..b504b60 100644 --- a/libs/libgloox/bytestreamhandler.h +++ b/libs/libgloox/bytestreamhandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -30,7 +30,7 @@ namespace gloox * * See SIProfileFT on how to implement file transfer in general. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API BytestreamHandler diff --git a/libs/libgloox/capabilities.cpp b/libs/libgloox/capabilities.cpp index 0bdbc00..a76e58a 100644 --- a/libs/libgloox/capabilities.cpp +++ b/libs/libgloox/capabilities.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/capabilities.h b/libs/libgloox/capabilities.h index a5d63e3..a801a68 100644 --- a/libs/libgloox/capabilities.h +++ b/libs/libgloox/capabilities.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -27,10 +27,10 @@ namespace gloox class Tag; /** - * @brief This is an implementation of XEP-0115 (Entity Capabilities). + * @brief This is an implementation of @xep{0115} (Entity Capabilities). * * XEP Version: 1.5-15 - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API Capabilities : public StanzaExtension, public DiscoNodeHandler diff --git a/libs/libgloox/chatstate.cpp b/libs/libgloox/chatstate.cpp index 8a2a400..0ddf77a 100644 --- a/libs/libgloox/chatstate.cpp +++ b/libs/libgloox/chatstate.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -32,7 +32,8 @@ namespace gloox } ChatState::ChatState( const Tag* tag ) - : StanzaExtension( ExtChatState ) + : StanzaExtension( ExtChatState ), + m_state( ChatStateInvalid ) { if( tag ) m_state = chatStateType( tag->name() ); diff --git a/libs/libgloox/chatstate.h b/libs/libgloox/chatstate.h index 6f1c426..748716f 100644 --- a/libs/libgloox/chatstate.h +++ b/libs/libgloox/chatstate.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -24,10 +24,10 @@ namespace gloox class Tag; /** - * @brief An implementation of Chat State Notifications (XEP-0085) as a StanzaExtension. + * @brief An implementation of Chat State Notifications (@xep{0085}) as a StanzaExtension. * * @author Vincent Thomasset - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API ChatState : public StanzaExtension diff --git a/libs/libgloox/chatstatefilter.cpp b/libs/libgloox/chatstatefilter.cpp index 8644689..24dae85 100644 --- a/libs/libgloox/chatstatefilter.cpp +++ b/libs/libgloox/chatstatefilter.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/chatstatefilter.h b/libs/libgloox/chatstatefilter.h index b0f5a6b..31f90be 100644 --- a/libs/libgloox/chatstatefilter.h +++ b/libs/libgloox/chatstatefilter.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -26,7 +26,7 @@ namespace gloox class Message; /** - * @brief This class adds Chat State Notifications (XEP-0085) support to a MessageSession. + * @brief This class adds Chat State Notifications (@xep{0085}) support to a MessageSession. * * This implementation of Chat States is fully transparent to the user of the class. * If the remote entity does not request chat states, ChatStateFilter will not send @@ -34,7 +34,10 @@ namespace gloox * You MUST annouce this capability by use of Disco (associated namespace is XMLNS_CHAT_STATES). * (This is also required by the protocol specification.) * - * @author Jakob Schroeter + * @note You must register ChatState as a StanzaExtension by calling + * ClientBase::registerStanzaExtension() for notifications to work. + * + * @author Jakob Schröter * @since 0.8 */ class GLOOX_API ChatStateFilter : public MessageFilter @@ -52,7 +55,7 @@ namespace gloox virtual ~ChatStateFilter(); /** - * Use this function to set a chat state as defined in XEP-0085. + * Use this function to set a chat state as defined in @xep{0085}. * @note The Spec states that Chat States shall not be sent to an entity * which did not request them. Reasonable effort is taken in this function to * avoid spurious state sending. You should be safe to call this even if Message @@ -65,7 +68,7 @@ namespace gloox /** * The ChatStateHandler registered here will receive Chat States according - * to XEP-0085. + * to @xep{0085}. * @param csh The ChatStateHandler to register. */ void registerChatStateHandler( ChatStateHandler* csh ) diff --git a/libs/libgloox/chatstatehandler.h b/libs/libgloox/chatstatehandler.h index 8c302c8..1b94626 100644 --- a/libs/libgloox/chatstatehandler.h +++ b/libs/libgloox/chatstatehandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -23,9 +23,9 @@ namespace gloox /** * @brief A virtual interface that enables an object to be notified about - * a remote entity's Chat States (XEP-0085). + * a remote entity's Chat States (@xep{0085}). * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.8 */ class GLOOX_API ChatStateHandler diff --git a/libs/libgloox/client.cpp b/libs/libgloox/client.cpp index 6df569d..abd9bc1 100644 --- a/libs/libgloox/client.cpp +++ b/libs/libgloox/client.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -30,8 +30,6 @@ # include #endif -#include - namespace gloox { @@ -107,6 +105,7 @@ namespace gloox m_rosterManager( 0 ), m_auth( 0 ), m_presence( Presence::Available, JID() ), m_resourceBound( false ), m_forceNonSasl( false ), m_manageRoster( true ), + m_smId( EmptyString ), m_smLocation( EmptyString ), m_smResume( false ), m_smWanted( false ), m_smMax( 0 ), m_streamFeatures( 0 ) { m_jid.setServer( server ); @@ -118,6 +117,7 @@ namespace gloox m_rosterManager( 0 ), m_auth( 0 ), m_presence( Presence::Available, JID() ), m_resourceBound( false ), m_forceNonSasl( false ), m_manageRoster( true ), + m_smId( EmptyString ), m_smLocation( EmptyString ), m_smResume( false ), m_smWanted( false ), m_smMax( 0 ), m_streamFeatures( 0 ) { m_jid = jid; @@ -176,7 +176,11 @@ namespace gloox { if( m_authed ) { - if( m_streamFeatures & StreamFeatureBind ) + if( m_streamFeatures & StreamFeatureStreamManagement && m_smWanted && m_smContext >= CtxSMEnabled ) + { + sendStreamManagement(); + } + else if( m_streamFeatures & StreamFeatureBind && m_smContext < CtxSMEnabled ) { notifyStreamEvent( StreamEventResourceBinding ); bindResource( resource() ); @@ -290,11 +294,66 @@ namespace gloox } else if( name == "success" && xmlns == XMLNS_STREAM_SASL ) { + if( !processSASLSuccess( tag->cdata() ) ) + { + logInstance().err( LogAreaClassClient, "The Server response could not be verified!" ); + disconnect( ConnAuthenticationFailed ); + return false; + } + logInstance().dbg( LogAreaClassClient, "SASL authentication successful" ); - processSASLSuccess(); setAuthed( true ); header(); } + else if( name == "enabled" && xmlns == XMLNS_STREAM_MANAGEMENT ) + { + m_smContext = CtxSMEnabled; + m_smMax = atoi( tag->findAttribute( "max" ).c_str() ); + m_smId = tag->findAttribute( "id" ); + const std::string res = tag->findAttribute( "resume" ); + m_smResume = ( ( res == "true" || res == "1" ) && !m_smId.empty() ) ? true : false; + m_smLocation = tag->findAttribute( "location" ); + + if( m_streamFeatures & StreamFeatureSession ) + createSession(); + else + connected(); + } + else if( name == "resumed" && xmlns == XMLNS_STREAM_MANAGEMENT && m_smContext == CtxSMResume ) + { + if( tag->findAttribute( "previd" ) == m_smId ) + { + m_smContext = CtxSMResumed; + notifyStreamEvent( StreamEventSMResumed ); + int h = atoi( tag->findAttribute( "h" ).c_str() ); + connected(); + checkQueue( h, true ); + } + } + else if( name == "a" && xmlns == XMLNS_STREAM_MANAGEMENT && m_smContext >= CtxSMEnabled ) + { + int h = atoi( tag->findAttribute( "h" ).c_str() ); + checkQueue( h, false ); + } + else if( name == "r" && xmlns == XMLNS_STREAM_MANAGEMENT ) + { + ackStreamManagement(); + } + else if( name == "failed" && xmlns == XMLNS_STREAM_MANAGEMENT ) + { + switch( m_smContext ) + { + case CtxSMEnable: + notifyStreamEvent( StreamEventSMEnableFailed ); + break; + case CtxSMResume: + notifyStreamEvent( StreamEventSMResumeFailed ); + break; + default: + break; + } + m_smContext = CtxSMFailed; + } else return false; } @@ -333,6 +392,9 @@ namespace gloox if( tag->hasChild( "compression", XMLNS, XMLNS_STREAM_COMPRESS ) ) features |= getCompressionMethods( tag->findChild( "compression" ) ); + if( tag->hasChild( "sm", XMLNS, XMLNS_STREAM_MANAGEMENT ) ) + features |= StreamFeatureStreamManagement; + if( features == 0 ) features = StreamFeatureIqAuth; @@ -345,6 +407,12 @@ namespace gloox const std::string mech = "mechanism"; + if( tag->hasChildWithCData( mech, "SCRAM-SHA-1-PLUS" ) ) + mechs |= SaslMechScramSha1Plus; + + if( tag->hasChildWithCData( mech, "SCRAM-SHA-1" ) ) + mechs |= SaslMechScramSha1; + if( tag->hasChildWithCData( mech, "DIGEST-MD5" ) ) mechs |= SaslMechDigestMd5; @@ -383,8 +451,21 @@ namespace gloox { bool retval = true; - if( m_streamFeatures & SaslMechDigestMd5 && m_availableSaslMechs & SaslMechDigestMd5 + if( ( m_streamFeatures & SaslMechScramSha1Plus && m_availableSaslMechs & SaslMechScramSha1Plus + && m_encryption && m_encryptionActive && m_encryption->hasChannelBinding() ) && !m_forceNonSasl ) + { + notifyStreamEvent( StreamEventAuthentication ); + startSASL( SaslMechScramSha1Plus ); + } + else if( m_streamFeatures & SaslMechScramSha1 && m_availableSaslMechs & SaslMechScramSha1 + && !m_forceNonSasl ) + { + notifyStreamEvent( StreamEventAuthentication ); + startSASL( SaslMechScramSha1 ); + } + else if( m_streamFeatures & SaslMechDigestMd5 && m_availableSaslMechs & SaslMechDigestMd5 + && !m_forceNonSasl ) { notifyStreamEvent( StreamEventAuthentication ); startSASL( SaslMechDigestMd5 ); @@ -438,11 +519,12 @@ namespace gloox bool Client::selectResource( const std::string& resource ) { + m_selectedResource = resource; // TODO: remove for 1.1 + m_jid.setResource( resource ); + if( !( m_streamFeatures & StreamFeatureUnbind ) ) return false; - m_selectedResource = resource; - return true; } @@ -461,10 +543,12 @@ namespace gloox m_jid = rb->jid(); m_resourceBound = true; - m_selectedResource = m_jid.resource(); + m_selectedResource = m_jid.resource(); // TODO: remove for 1.1 notifyOnResourceBind( m_jid.resource() ); - if( m_streamFeatures & StreamFeatureSession ) + if( m_streamFeatures & StreamFeatureStreamManagement && m_smWanted ) + sendStreamManagement(); + else if( m_streamFeatures & StreamFeatureSession ) createSession(); else connected(); @@ -480,6 +564,71 @@ namespace gloox } } + void Client::setStreamManagement( bool enable, bool resume ) + { + m_smWanted = enable; + m_smResume = resume; + + if( !m_smWanted ) + { + m_smId = EmptyString; + m_smLocation = EmptyString; + m_smMax = 0; + m_smResume = false; + return; + } + + if( m_smWanted && m_resourceBound ) + sendStreamManagement(); + } + + void Client::sendStreamManagement() + { + if( !m_smWanted ) + return; + + if( m_smContext == CtxSMInvalid ) + { + notifyStreamEvent( StreamEventSMEnable ); + Tag* e = new Tag( "enable" ); + e->setXmlns( XMLNS_STREAM_MANAGEMENT ); + if( m_smResume ) + e->addAttribute( "resume", "true" ); + send( e ); + m_smContext = CtxSMEnable; + m_smHandled = 0; + } + else if( m_smContext == CtxSMEnabled ) + { + notifyStreamEvent( StreamEventSMResume ); + Tag* r = new Tag( "resume" ); + r->setXmlns( XMLNS_STREAM_MANAGEMENT ); + r->addAttribute( "h", m_smHandled ); + r->addAttribute( "previd", m_smId ); + send( r ); + m_smContext = CtxSMResume; + } + } + + void Client::ackStreamManagement() + { + if( m_smContext >= CtxSMEnabled ) + { + Tag* a = new Tag( "a", "xmlns", XMLNS_STREAM_MANAGEMENT ); + a->addAttribute( "h", m_smHandled ); + send( a ); + } + } + + void Client::reqStreamManagement() + { + if( m_smContext >= CtxSMEnabled ) + { + Tag* r = new Tag( "r", "xmlns", XMLNS_STREAM_MANAGEMENT ); + send( r ); + } + } + void Client::createSession() { notifyStreamEvent( StreamEventSessionCreation ); @@ -556,7 +705,7 @@ namespace gloox void Client::connected() { - if( m_authed ) + if( m_authed && m_smContext != CtxSMResumed ) { if( m_manageRoster ) { @@ -582,6 +731,14 @@ namespace gloox void Client::disconnect() { + m_smContext = CtxSMInvalid; + m_smHandled = 0; + m_smId = EmptyString; + m_smLocation = EmptyString; + m_smMax = 0; + m_smResume = false; + m_smWanted = false; + disconnect( ConnUserDisconnected ); } diff --git a/libs/libgloox/client.h b/libs/libgloox/client.h index 5eb53f3..098a481 100644 --- a/libs/libgloox/client.h +++ b/libs/libgloox/client.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -28,7 +28,7 @@ namespace gloox class IQ; /** - * @brief This class implements a basic Jabber Client. + * @brief This class implements a basic Jabber/XMPP Client. * * It supports @ref sasl_auth as well as TLS (Encryption), which can be * switched on/off separately. They are used automatically if the server supports them. @@ -36,7 +36,7 @@ namespace gloox * To use, create a new Client instance and feed it connection credentials, either in the Constructor or * afterwards using the setters. You should then register packet handlers implementing the corresponding * Interfaces (ConnectionListener, PresenceHandler, MessageHandler, IqHandler, SubscriptionHandler), - * and call @ref connect() to establish the connection to the server.
+ * and call @ref connect() to establish the connection to the server. * * @note While the MessageHandler interface is still available (and will be in future versions) * it is now recommended to use the new @link gloox::MessageSession MessageSession @endlink for any @@ -67,9 +67,9 @@ namespace gloox * include: * @li jabber:iq:roster: by default the server-side roster is fetched and handled. Use * @ref rosterManager() and @ref RosterManager to interact with the Roster. - * @li XEP-0092 (Software Version): If no version is specified, a name of "based on gloox" with + * @li @xep{0092} (Software Version): If no version is specified, a name of "based on gloox" with * gloox's current version is announced. - * @li XEP-0030 (Service Discovery): All supported/available services are announced. No items are + * @li @xep{0030} (Service Discovery): All supported/available services are announced. No items are * returned. * @note As of gloox 0.9, by default a priority of 0 is sent along with the initial presence. * @note As of gloox 0.9, initial presence is automatically sent. Presence: available, Priority: 0. @@ -78,7 +78,7 @@ namespace gloox * * @section sasl_auth SASL Authentication * - * Besides the simple, IQ-based authentication (XEP-0078), gloox supports several SASL (Simple + * Besides the simple, IQ-based authentication (@xep{0078}), gloox supports several SASL (Simple * Authentication and Security Layer, RFC 2222) authentication mechanisms. * @li DIGEST-MD5: This mechanism is preferred over all other mechanisms if username and password are * provided to the Client instance. It is secure even without TLS encryption. @@ -93,7 +93,25 @@ namespace gloox * * Of course, all these mechanisms are not tried unless the server offers them. * - * @author Jakob Schroeter + * @section stream_management Stream Management + * + * To enable Stream Management (@xep{0198}), call @ref setStreamManagement() with the first parameter set to @b true + * at any time. This will tell the server to enable Stream Management, if the feature is available. Once switched on, + * Stream Management can not be disabled for a given active stream. However, setting the first + * parameter to @b false, it can be disabled inside gloox so that Stream Management will not be used + * for subsequent connections. + * + * To enable the stream resumption feature, pass @b true as the second parameter to @ref setStreamManagement(). + * Upon re-connect after an unexpected (i.e. neither user-triggered nor server-triggered) disconnect, gloox will try + * to resume the stream and re-send any non-acknowledged stanzas automatically. + * For stream resumption to work you have to re-connect using the very same Client instance. + * + * After an unexpected disconnect you may check the send queue using @link ClientBase::sendQueue() sendQueue() @endlink. + * Stanzas in the queue have been sent but not yet acknowledged by the server. Depending on the circumstances of the + * disconnect, this does not mean that those stanzas have not been received by the recipient. + * + * + * @author Jakob Schröter */ class GLOOX_API Client : public ClientBase { @@ -149,7 +167,7 @@ namespace gloox * Use this function to select a resource identifier that has been bound * previously by means of bindResource(). It is not necessary to call this function * if only one resource is bound. Use hasResourceBind() to find out if the - * server supports binding of multiple resources. selectResource() is a NOOP if it doesn't. + * server supports binding of multiple resources. * @param resource A resource string that has been bound previously. * @note If the resource string has not been bound previously, future sending of * stanzas will fail. @@ -181,6 +199,39 @@ namespace gloox */ const std::string& resource() const { return m_jid.resource(); } + /** + * This function enables Stream Management (@xep{0198}) if the server supports it. + * Optionally, stream resumption can be disabled. + * @note You can use this function at any time. However, gloox will make sure Stream Management + * requests are sent only when allowed by the specification. + * @param enable Enable or disable Stream Management. Note: once enabled on a connection, Stream + * Management can not be disabled for that connection. + * @param resume Tells the server whether to enable stream resumption. Defaults to @b true. + * @note This function is part of @xep{0198}. + * @since 1.0.4 + */ + void setStreamManagement( bool enable = true, bool resume = true ); + + /** + * Use this function to send an unrequested 'ack' to the server to let it know the number of handled stanzas. + * You may use this function at any time. However, gloox will also reply to incoming 'ack requests' automatically. + * These automatic 'acks' are not announced anywhere in gloox. + * This function is a no-op if called in situations where sending an ack is not + * allowed by the protocol. + * @note This function is part of @xep{0198}. + * @since 1.0.4 + */ + void ackStreamManagement(); + + /** + * Use this function to request the number of handled stanzas from the server. + * You may use this function at any time. gloox does not send any such requests + * automatically. + * @note This function is part of @xep{0198}. + * @since 1.0.4 + */ + void reqStreamManagement(); + /** * Returns the current priority. * @return The priority of the current resource. @@ -288,10 +339,13 @@ namespace gloox void nonSaslLogin(); private: +#ifdef CLIENT_TEST + public: +#endif /** * @brief This is an implementation of a resource binding StanzaExtension. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class ResourceBind : public StanzaExtension @@ -363,7 +417,7 @@ namespace gloox /** * @brief This is an implementation of a session creating StanzaExtension. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class SessionCreation : public StanzaExtension @@ -396,7 +450,7 @@ namespace gloox }; - virtual void handleStartNode() {} + virtual void handleStartNode( const Tag* /*start*/ ) {} virtual bool handleNormalNode( Tag* tag ); virtual void disconnect( ConnectionError reason ); virtual void handleIqIDForward( const IQ& iq, int context ); @@ -413,6 +467,7 @@ namespace gloox virtual void rosterFilled(); virtual void cleanup(); bool bindOperation( const std::string& resource, bool bind ); + void sendStreamManagement(); void init(); @@ -432,6 +487,12 @@ namespace gloox bool m_forceNonSasl; bool m_manageRoster; + std::string m_smId; + std::string m_smLocation; + bool m_smResume; + bool m_smWanted; + int m_smMax; + int m_streamFeatures; }; diff --git a/libs/libgloox/clientbase.cpp b/libs/libgloox/clientbase.cpp index 1619107..07f5b1c 100644 --- a/libs/libgloox/clientbase.cpp +++ b/libs/libgloox/clientbase.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -14,38 +14,41 @@ #include "config.h" +#include "base64.h" #include "clientbase.h" -#include "connectionbase.h" -#include "tlsbase.h" #include "compressionbase.h" +#include "compressionzlib.h" +#include "connectionbase.h" +#include "connectionlistener.h" #include "connectiontcpclient.h" #include "disco.h" -#include "messagesessionhandler.h" -#include "tag.h" -#include "iq.h" -#include "message.h" -#include "subscription.h" -#include "presence.h" -#include "connectionlistener.h" -#include "iqhandler.h" -#include "messagehandler.h" -#include "presencehandler.h" -#include "rosterlistener.h" -#include "subscriptionhandler.h" -#include "loghandler.h" -#include "taghandler.h" -#include "mucinvitationhandler.h" -#include "mucroom.h" -#include "jid.h" -#include "base64.h" #include "error.h" -#include "md5.h" -#include "util.h" -#include "tlsdefault.h" -#include "compressionzlib.h" -#include "stanzaextensionfactory.h" #include "eventhandler.h" #include "event.h" +#include "iq.h" +#include "iqhandler.h" +#include "jid.h" +#include "loghandler.h" +#include "md5.h" +#include "message.h" +#include "messagehandler.h" +#include "messagesessionhandler.h" +#include "mucinvitationhandler.h" +#include "mucroom.h" +#include "mutexguard.h" +#include "presence.h" +#include "presencehandler.h" +#include "rosterlistener.h" +#include "stanzaextensionfactory.h" +#include "sha.h" +#include "subscription.h" +#include "subscriptionhandler.h" +#include "tag.h" +#include "taghandler.h" +#include "tlsbase.h" +#include "tlsdefault.h" +#include "prep.h" +#include "util.h" #include #include @@ -60,6 +63,11 @@ #if defined( _WIN32 ) && !defined( __SYMBIAN32__ ) #include +# ifdef __MINGW32__ +# ifndef SecureZeroMemory +# define SecureZeroMemory(p,s) RtlFillMemory((p),(s),0) +# endif +# endif #endif namespace gloox @@ -87,13 +95,15 @@ namespace gloox : m_connection( 0 ), m_encryption( 0 ), m_compression( 0 ), m_disco( 0 ), m_namespace( ns ), m_xmllang( "en" ), m_server( server ), m_compressionActive( false ), m_encryptionActive( false ), m_compress( true ), m_authed( false ), m_block( false ), m_sasl( true ), m_tls( TLSOptional ), m_port( port ), - m_availableSaslMechs( SaslMechAll ), + m_availableSaslMechs( SaslMechAll ), m_smContext( CtxSMInvalid ), m_smHandled( 0 ), m_statisticsHandler( 0 ), m_mucInvitationHandler( 0 ), m_messageSessionHandlerChat( 0 ), m_messageSessionHandlerGroupchat( 0 ), m_messageSessionHandlerHeadline( 0 ), m_messageSessionHandlerNormal( 0 ), m_parser( this ), m_seFactory( 0 ), m_authError( AuthErrorUndefined ), m_streamError( StreamErrorUndefined ), m_streamErrorAppCondition( 0 ), - m_selectedSaslMech( SaslMechNone ), m_autoMessageSession( false ) + m_selectedSaslMech( SaslMechNone ), m_customConnection( false ), + m_uniqueBaseId( (unsigned int)( ( (unsigned long long)time( 0 ) & 0xFFFF ) << 16 ) | ( ( (unsigned long long) & m_nextId ) & 0xFFFF ) ), + m_smSent( 0 ) { init(); } @@ -104,19 +114,23 @@ namespace gloox m_password( password ), m_xmllang( "en" ), m_server( server ), m_compressionActive( false ), m_encryptionActive( false ), m_compress( true ), m_authed( false ), m_block( false ), m_sasl( true ), m_tls( TLSOptional ), - m_port( port ), m_availableSaslMechs( SaslMechAll ), + m_port( port ), m_availableSaslMechs( SaslMechAll ), m_smContext( CtxSMInvalid ), m_smHandled( 0 ), m_statisticsHandler( 0 ), m_mucInvitationHandler( 0 ), m_messageSessionHandlerChat( 0 ), m_messageSessionHandlerGroupchat( 0 ), m_messageSessionHandlerHeadline( 0 ), m_messageSessionHandlerNormal( 0 ), m_parser( this ), m_seFactory( 0 ), m_authError( AuthErrorUndefined ), m_streamError( StreamErrorUndefined ), m_streamErrorAppCondition( 0 ), - m_selectedSaslMech( SaslMechNone ), m_autoMessageSession( false ) + m_selectedSaslMech( SaslMechNone ), m_customConnection( false ), + m_uniqueBaseId( (unsigned int)( ( (unsigned long long)time( 0 ) & 0xFFFF ) << 16 ) | ( ( (unsigned long long) & m_nextId ) & 0xFFFF ) ), + m_smSent( 0 ) { init(); } void ClientBase::init() { + srand( time( 0 ) ); + if( !m_disco ) { m_disco = new Disco( this ); @@ -136,9 +150,20 @@ namespace gloox ClientBase::~ClientBase() { - delete m_connection; - delete m_encryption; - delete m_compression; + m_iqHandlerMapMutex.lock(); + m_iqIDHandlers.clear(); + m_iqHandlerMapMutex.unlock(); + + m_iqExtHandlerMapMutex.lock(); + m_iqExtHandlers.clear(); + m_iqExtHandlerMapMutex.unlock(); + + util::clearList( m_presenceExtensions ); + util::clearMap( m_smQueue ); + + setConnectionImpl( 0 ); + setEncryptionImpl( 0 ); + setCompressionImpl( 0 ); delete m_seFactory; m_seFactory = 0; // to avoid usage when Disco gets deleted below delete m_disco; @@ -177,7 +202,7 @@ namespace gloox m_compression = getDefaultCompression(); m_logInstance.dbg( LogAreaClassClientbase, "This is gloox " + GLOOX_VERSION + ", connecting to " - + m_server + ":" + util::int2string( m_port ) + "..." ); + + m_server + ( ( m_customConnection )?( " using a custom connection" ):( m_port > 0 ? ( ":" + util::int2string( m_port ) ) : EmptyString ) ) + "..." ); m_block = block; ConnectionError ret = m_connection->connect(); if( ret != ConnNoError ) @@ -213,7 +238,7 @@ namespace gloox } m_sid = tag->findAttribute( "id" ); - handleStartNode(); + handleStartNode( tag ); } else if( tag->name() == "error" && tag->xmlns() == XMLNS_STREAM ) { @@ -230,15 +255,23 @@ namespace gloox { IQ iq( tag ); m_seFactory->addExtensions( iq, tag ); + if( iq.hasEmbeddedStanza() ) + m_seFactory->addExtensions( *iq.embeddedStanza(), iq.embeddedTag() ); notifyIqHandlers( iq ); ++m_stats.iqStanzasReceived; + if( m_smContext >= CtxSMEnabled ) + ++m_smHandled; } else if( tag->name() == "message" ) { Message msg( tag ); m_seFactory->addExtensions( msg, tag ); + if( msg.hasEmbeddedStanza() ) + m_seFactory->addExtensions( *msg.embeddedStanza(), msg.embeddedTag() ); notifyMessageHandlers( msg ); ++m_stats.messageStanzasReceived; + if( m_smContext >= CtxSMEnabled ) + ++m_smHandled; } else if( tag->name() == "presence" ) { @@ -248,6 +281,8 @@ namespace gloox { Subscription sub( tag ); m_seFactory->addExtensions( sub, tag ); + if( sub.hasEmbeddedStanza() ) + m_seFactory->addExtensions( *sub.embeddedStanza(), sub.embeddedTag() ); notifySubscriptionHandlers( sub ); ++m_stats.s10nStanzasReceived; } @@ -255,12 +290,16 @@ namespace gloox { Presence pres( tag ); m_seFactory->addExtensions( pres, tag ); + if( pres.hasEmbeddedStanza() ) + m_seFactory->addExtensions( *pres.embeddedStanza(), pres.embeddedTag() ); notifyPresenceHandlers( pres ); ++m_stats.presenceStanzasReceived; } + if( m_smContext >= CtxSMEnabled ) + ++m_smHandled; } else - m_logInstance.err( LogAreaClassClientbase, "Received invalid stanza." ); + m_logInstance.err( LogAreaClassClientbase, "Invalid stanza received: " + tag->name() ); } else { @@ -377,8 +416,13 @@ namespace gloox m_encryptionActive = false; m_compressionActive = false; + m_smSent = 0; notifyOnDisconnect( reason ); + +#ifdef CLIENTBASE_TEST + m_nextId.reset(); +#endif } void ClientBase::parse( const std::string& data ) @@ -442,6 +486,40 @@ namespace gloox switch( type ) { + case SaslMechScramSha1Plus: + case SaslMechScramSha1: + { + if( type == SaslMechScramSha1 ) + { + if( ( m_availableSaslMechs & SaslMechScramSha1Plus ) != SaslMechScramSha1Plus ) + m_gs2Header = "y,"; + else + m_gs2Header = "n,"; + a->addAttribute( "mechanism", "SCRAM-SHA-1" ); + } + else // SaslMechScramSha1Plus + { + m_gs2Header = "p=tls-unique,"; + a->addAttribute( "mechanism", "SCRAM-SHA-1-PLUS" ); + } + + std::string t; + if( m_authzid && prep::saslprep( m_authzid.bare(), t ) ) + m_gs2Header += "a=" + t; + + m_gs2Header += ","; + + m_clientFirstMessageBare = "n="; + if( !m_authcid.empty() && prep::saslprep( m_authcid, t ) ) + m_clientFirstMessageBare += t; + else if( prep::saslprep( m_jid.username(), t ) ) + m_clientFirstMessageBare += t; + + m_clientFirstMessageBare += ",r=" + getRandom(); + + a->setCData( Base64::encode64( m_gs2Header + m_clientFirstMessageBare ) ); + break; + } case SaslMechDigestMd5: a->addAttribute( "mechanism", "DIGEST-MD5" ); break; @@ -495,20 +573,70 @@ namespace gloox { #if defined( _WIN32 ) && !defined( __SYMBIAN32__ ) a->addAttribute( "mechanism", "NTLM" ); - SEC_WINNT_AUTH_IDENTITY identity, *ident = 0; + SEC_WINNT_AUTH_IDENTITY_W identity, *ident = 0; memset( &identity, 0, sizeof( identity ) ); + + WCHAR *usernameW = 0, *domainW = 0, *passwordW = 0; + int cchUsernameW = 0, cchDomainW = 0, cchPasswordW = 0; + if( m_jid.username().length() > 0 ) { - identity.User = (unsigned char*)m_jid.username().c_str(); - identity.UserLength = (unsigned long)m_jid.username().length(); - identity.Domain = (unsigned char*)m_ntlmDomain.c_str(); - identity.DomainLength = (unsigned long)m_ntlmDomain.length(); - identity.Password = (unsigned char*)m_password.c_str(); - identity.PasswordLength = (unsigned long)m_password.length(); + // NOTE: The return values of MultiByteToWideChar will include room + // for the NUL character since we use -1 for the input length. + + cchUsernameW = ::MultiByteToWideChar( CP_UTF8, 0, m_jid.username().c_str(), -1, 0, 0 ); + if( cchUsernameW > 0 ) + { + usernameW = new WCHAR[cchUsernameW]; + ::MultiByteToWideChar( CP_UTF8, 0, m_jid.username().c_str(), -1, usernameW, cchUsernameW ); + // Guarantee its NUL terminated. + usernameW[cchUsernameW-1] = L'\0'; + } + cchDomainW = ::MultiByteToWideChar( CP_UTF8, 0, m_ntlmDomain.c_str(), -1, 0, 0 ); + if( cchDomainW > 0 ) + { + domainW = new WCHAR[cchDomainW]; + ::MultiByteToWideChar( CP_UTF8, 0, m_ntlmDomain.c_str(), -1, domainW, cchDomainW ); + // Guarantee its NUL terminated. + domainW[cchDomainW-1] = L'\0'; + } + cchPasswordW = ::MultiByteToWideChar( CP_UTF8, 0, m_password.c_str(), -1, 0, 0 ); + if( cchPasswordW > 0 ) + { + passwordW = new WCHAR[cchPasswordW]; + ::MultiByteToWideChar( CP_UTF8, 0, m_password.c_str(), -1, passwordW, cchPasswordW ); + // Guarantee its NUL terminated. + passwordW[cchPasswordW-1] = L'\0'; + } + identity.User = (unsigned short*)usernameW; + identity.UserLength = (unsigned long)cchUsernameW-1; + identity.Domain = (unsigned short*)domainW; + identity.DomainLength = (unsigned long)cchDomainW-1; + identity.Password = (unsigned short*)passwordW; + identity.PasswordLength = (unsigned long)cchPasswordW-1; identity.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE; ident = &identity; } - AcquireCredentialsHandle( 0, _T( "NTLM" ), SECPKG_CRED_OUTBOUND, 0, ident, 0, 0, &m_credHandle, 0 ); + + AcquireCredentialsHandleW( 0, L"NTLM", SECPKG_CRED_OUTBOUND, 0, ident, 0, 0, &m_credHandle, 0 ); + + if( usernameW != 0 ) + { + delete[] usernameW; + usernameW = 0; + } + if( domainW != 0 ) + { + delete[] domainW; + domainW = 0; + } + if( passwordW != 0 ) + { + ::SecureZeroMemory( passwordW, cchPasswordW* sizeof( WCHAR ) ); + delete[] passwordW; + passwordW = 0; + } + #else logInstance().err( LogAreaClassClientbase, "SASL NTLM is not supported on this platform. You should never see this." ); @@ -522,6 +650,52 @@ namespace gloox send( a ); } + std::string ClientBase::hmac( const std::string& key, const std::string& str ) + { + SHA sha; + std::string key_ = key; + if( key_.length() > 64 ) + { + sha.feed( key_ ); + key_ = sha.binary(); + sha.reset(); + } + unsigned char ipad[65]; + unsigned char opad[65]; + memset( ipad, '\0', sizeof( ipad ) ); + memset( opad, '\0', sizeof( opad ) ); + memcpy( ipad, key_.c_str(), key_.length() ); + memcpy( opad, key_.c_str(), key_.length() ); + for( int i = 0; i < 64; i++ ) + { + ipad[i] ^= 0x36; + opad[i] ^= 0x5c; + } + sha.feed( ipad, 64 ); + sha.feed( str ); + key_ = sha.binary(); + sha.reset(); + sha.feed( opad, 64 ); + sha.feed( key_ ); + + return sha.binary(); // hex() for testing + } + + std::string ClientBase::hi( const std::string& str, const std::string& salt, int iter ) + { + unsigned char xored[20]; + memset( xored, '\0', sizeof( xored ) ); + std::string tmp = salt; + tmp.append( "\0\0\0\1", 4 ); + for( int i = 0; i < iter; ++i ) + { + tmp = hmac( str, tmp ); + for( int j = 0; j < 20; ++j ) + xored[j] ^= tmp.c_str()[j]; + } + return std::string( (char*)xored, 20 ); + } + void ClientBase::processSASLChallenge( const std::string& challenge ) { Tag* t = new Tag( "response", XMLNS, XMLNS_STREAM_SASL ); @@ -530,6 +704,53 @@ namespace gloox switch( m_selectedSaslMech ) { + case SaslMechScramSha1Plus: + case SaslMechScramSha1: + { + std::string snonce, salt, tmp; + int iter = 0; + std::string::size_type posn = decoded.find( "r=" ); + std::string::size_type poss = decoded.find( "s=" ); + std::string::size_type posi = decoded.find( "i=" ); + if( posn == std::string::npos || poss == std::string::npos || posi == std::string::npos ) + break; + + snonce = decoded.substr( posn + 2, poss - posn - 3 ); + salt = Base64::decode64( decoded.substr( poss + 2, posi - poss - 3 ) ); + tmp = decoded.substr( posi + 2, decoded.length() - posi - 2 ); + iter = atoi( tmp.c_str() ); + + if( !prep::saslprep( m_password, tmp ) ) + break; + + std::string saltedPwd = hi( tmp, salt, iter ); + std::string ck = hmac( saltedPwd, "Client Key" ); + SHA sha; + sha.feed( ck ); + std::string storedKey = sha.binary(); + + if( m_selectedSaslMech == SaslMechScramSha1Plus ) + tmp = "c=" + Base64::encode64( m_gs2Header + m_encryption->channelBinding() ); + else + tmp = "c=biws"; + tmp += ",r=" + snonce; + + std::string authMessage = m_clientFirstMessageBare + "," + decoded + "," + tmp; // client-final-message-without-proof + std::string clientSignature = hmac( storedKey, authMessage ); + unsigned char clientProof[20]; // ck XOR clientSignature + memcpy( clientProof, ck.c_str(), 20 ); + for( int i = 0; i < 20; ++i ) + clientProof[i] ^= clientSignature.c_str()[i]; + std::string serverKey = hmac( saltedPwd, "Server Key" ); + m_serverSignature = hmac( serverKey, authMessage ); + + tmp += ",p="; + tmp.append( Base64::encode64( std::string( (char*)clientProof, 20 ) ) ); + + t->setCData( Base64::encode64( tmp ) ); + + break; + } case SaslMechDigestMd5: { if( !decoded.compare( 0, 7, "rspauth" ) ) @@ -555,11 +776,7 @@ namespace gloox end = decoded.find( '"', end + 1 ); std::string nonce = decoded.substr( pos + 7, end - ( pos + 7 ) ); - std::string cnonce; - char cn[4*8+1]; - for( int i = 0; i < 4; ++i ) - sprintf( cn + i*8, "%08x", rand() ); - cnonce.assign( cn, 4*8 ); + std::string cnonce = getRandom(); MD5 md5; md5.feed( m_jid.username() ); @@ -699,7 +916,7 @@ namespace gloox #endif } - void ClientBase::processSASLSuccess() + bool ClientBase::processSASLSuccess( const std::string& payload ) { #if defined( _WIN32 ) && !defined( __SYMBIAN32__ ) if( m_selectedSaslMech == SaslMechNTLM ) @@ -708,6 +925,14 @@ namespace gloox DeleteSecurityContext( &m_ctxtHandle ); } #endif + if( m_selectedSaslMech == SaslMechScramSha1 || m_selectedSaslMech == SaslMechScramSha1Plus ) + { + const std::string decoded = Base64::decode64( payload ); + if( decoded.length() < 3 || Base64::decode64( decoded.substr( 2 ) ) != m_serverSignature ) + return false; + } + + return true; } void ClientBase::send( IQ& iq, IqHandler* ih, int context, bool del ) @@ -735,7 +960,7 @@ namespace gloox Tag* tag = iq.tag(); addFrom( tag ); addNamespace( tag ); - send( tag ); + send( tag, true, false ); } void ClientBase::send( const Message& msg ) @@ -744,7 +969,7 @@ namespace gloox Tag* tag = msg.tag(); addFrom( tag ); addNamespace( tag ); - send( tag ); + send( tag, true, false ); } void ClientBase::send( const Subscription& sub ) @@ -753,10 +978,10 @@ namespace gloox Tag* tag = sub.tag(); addFrom( tag ); addNamespace( tag ); - send( tag ); + send( tag, true, false ); } - void ClientBase::send( Presence& pres ) + void ClientBase::send( const Presence& pres ) { ++m_stats.presenceStanzasSent; Tag* tag = pres.tag(); @@ -765,7 +990,7 @@ namespace gloox tag->addChild( (*it)->tag() ); addFrom( tag ); addNamespace( tag ); - send( tag ); + send( tag, true, false ); } void ClientBase::send( Tag* tag ) @@ -773,6 +998,14 @@ namespace gloox if( !tag ) return; + send( tag, false, true ); + } + + void ClientBase::send( Tag* tag, bool queue, bool del ) + { + if( !tag ) + return; + send( tag->xml() ); ++m_stats.totalStanzasSent; @@ -780,7 +1013,14 @@ namespace gloox if( m_statisticsHandler ) m_statisticsHandler->handleStatistics( getStatistics() ); - delete tag; + if( queue && m_smContext >= CtxSMEnabled ) + { + m_queueMutex.lock(); + m_smQueue.insert( std::make_pair( ++m_smSent, tag ) ); + m_queueMutex.unlock(); + } + else if( del || m_smContext < CtxSMEnabled ) + delete tag; } void ClientBase::send( const std::string& xml ) @@ -798,15 +1038,49 @@ namespace gloox } } + void ClientBase::checkQueue( int handled, bool resend ) + { + if( m_smContext < CtxSMEnabled || handled < 0 ) + return; + + util::MutexGuard mg( m_queueMutex ); + SMQueueMap::iterator it = m_smQueue.begin(); + while( it != m_smQueue.end() ) + { + if( (*it).first <= handled ) + { + delete (*it).second; + m_smQueue.erase( it++ ); + } + else if( resend && (*it).first > handled ) + { + send( (*it).second, false, false ); + ++it; + } + else + { + ++it; + } + } + } + + const TagList ClientBase::sendQueue() + { + TagList l; + util::MutexGuard mg( m_queueMutex ); + SMQueueMap::iterator it = m_smQueue.begin(); + for( ; it != m_smQueue.end(); ++it ) + l.push_back( (*it).second->clone() ); + + return l; + } + void ClientBase::addFrom( Tag* tag ) { if( !m_authed /*for IQ Auth */ || !tag || tag->hasAttribute( "from" ) ) return; - if ( m_selectedResource.empty() ) - tag->addAttribute( "from", m_jid.bare() ); - else - tag->addAttribute( "from", m_jid.bare() + '/' + m_selectedResource ); + tag->addAttribute( "from", m_jid.full() ); } void ClientBase::addNamespace( Tag* tag ) @@ -885,11 +1159,14 @@ namespace gloox const std::string ClientBase::getID() { - static unsigned int uniqueBaseID = (unsigned int)time( 0 ); +#ifdef CLIENTBASE_TEST // to create predictable UIDs in test mode + return "uid" + util::int2string( m_nextId.increment() ); +#else char r[21+1]; - sprintf( r, "uid:%08x:%08x", uniqueBaseID, rand() ); + sprintf( r, "uid-%08x-%08x", m_uniqueBaseId, m_nextId.increment() ); std::string ret( r, 21 ); return ret; +#endif } bool ClientBase::checkStreamVersion( const std::string& version ) @@ -898,44 +1175,42 @@ namespace gloox return false; int major = 0; - int minor = 0; +// int minor = 0; int myMajor = atoi( XMPP_STREAM_VERSION_MAJOR.c_str() ); size_t dot = version.find( '.' ); if( !version.empty() && dot && dot != std::string::npos ) { major = atoi( version.substr( 0, dot ).c_str() ); - minor = atoi( version.substr( dot ).c_str() ); +// minor = atoi( version.substr( dot ).c_str() ); } return myMajor >= major; } - void ClientBase::setConnectionImpl( ConnectionBase* cb ) + void ClientBase::setConnectionImpl( ConnectionBase* connection ) { - if( m_connection ) - { - delete m_connection; - } - m_connection = cb; + ConnectionBase* old = m_connection; + m_connection = connection; + m_customConnection = true; + if( old ) + delete old; } - void ClientBase::setEncryptionImpl( TLSBase* tb ) + void ClientBase::setEncryptionImpl( TLSBase* encryption ) { - if( m_encryption ) - { - delete m_encryption; - } - m_encryption = tb; + TLSBase* old = m_encryption; + m_encryption = encryption; + if( old ) + delete old; } - void ClientBase::setCompressionImpl( CompressionBase* cb ) + void ClientBase::setCompressionImpl( CompressionBase* compression ) { - if( m_compression ) - { - delete m_compression; - } - m_compression = cb; + CompressionBase* old = m_compression; + m_compression = compression; + if( old ) + delete old; } void ClientBase::handleStreamError( Tag* tag ) @@ -1093,11 +1368,14 @@ namespace gloox if( !ih ) return; + util::MutexGuard m( m_iqExtHandlerMapMutex ); typedef IqHandlerMap::const_iterator IQci; std::pair g = m_iqExtHandlers.equal_range( exttype ); for( IQci it = g.first; it != g.second; ++it ) + { if( (*it).second == ih ) return; + } m_iqExtHandlers.insert( std::make_pair( exttype, ih ) ); } @@ -1107,6 +1385,7 @@ namespace gloox if( !ih ) return; + util::MutexGuard m( m_iqExtHandlerMapMutex ); typedef IqHandlerMap::iterator IQi; std::pair g = m_iqExtHandlers.equal_range( exttype ); IQi it2; @@ -1180,11 +1459,21 @@ namespace gloox { if( th ) { - TagHandlerList::iterator it = m_tagHandlers.begin(); - for( ; it != m_tagHandlers.end(); ++it ) + for( TagHandlerList::iterator it = m_tagHandlers.begin(); it != m_tagHandlers.end(); ) { if( (*it).th == th && (*it).tag == tag && (*it).xmlns == xmlns ) - m_tagHandlers.erase( it ); + { + // Normally we'd just assign it to the return value of the .erase() call, + // which is either the next element, or .end(). However, + // it's only since C++11 that this works; C++03 version returns void. + // So instead, we do a post-increment. this increments the iterator to point + // to the next element, then passes a copy of the old iterator (that is to the item to be deleted) + m_tagHandlers.erase( it++ ); + } + else + { + ++it; + } } } } @@ -1309,8 +1598,9 @@ namespace gloox { m_iqHandlerMapMutex.lock(); IqTrackMap::iterator it_id = m_iqIDHandlers.find( iq.id() ); + bool haveIdHandler = ( it_id != m_iqIDHandlers.end() ); m_iqHandlerMapMutex.unlock(); - if( it_id != m_iqIDHandlers.end() && iq.subtype() & ( IQ::Result | IQ::Error ) ) + if( haveIdHandler && ( iq.subtype() == IQ::Result || iq.subtype() == IQ::Error ) ) { (*it_id).second.ih->handleIqID( iq, (*it_id).second.context ); if( (*it_id).second.del ) @@ -1322,9 +1612,17 @@ namespace gloox } if( iq.extensions().empty() ) + { + if ( iq.subtype() == IQ::Get || iq.subtype() == IQ::Set ) + { + IQ re( IQ::Error, iq.from(), iq.id() ); + re.addExtension( new Error( StanzaErrorTypeCancel, StanzaErrorFeatureNotImplemented ) ); + send( re ); + } return; + } - bool res = false; + bool handled = false; // FIXME remove for 1.1 // typedef IqHandlerMapXmlns::const_iterator IQciXmlns @@ -1337,20 +1635,22 @@ namespace gloox // } // delete tag; + m_iqExtHandlerMapMutex.lock(); typedef IqHandlerMap::const_iterator IQci; const StanzaExtensionList& sel = iq.extensions(); StanzaExtensionList::const_iterator itse = sel.begin(); - for( ; itse != sel.end(); ++itse ) + for( ; !handled && itse != sel.end(); ++itse ) { std::pair g = m_iqExtHandlers.equal_range( (*itse)->extensionType() ); - for( IQci it = g.first; it != g.second; ++it ) + for( IQci it = g.first; !handled && it != g.second; ++it ) { if( (*it).second->handleIq( iq ) ) - res = true; + handled = true; } } + m_iqExtHandlerMapMutex.unlock(); - if( !res && iq.subtype() & ( IQ::Get | IQ::Set ) ) + if( !handled && ( iq.subtype() == IQ::Get || iq.subtype() == IQ::Set ) ) { IQ re( IQ::Error, iq.from(), iq.id() ); re.addExtension( new Error( StanzaErrorTypeCancel, StanzaErrorServiceUnavailable ) ); @@ -1429,8 +1729,6 @@ namespace gloox if( msHandler ) { - if( msg.subtype() == Message::Chat && msg.body().empty() ) - return; // don't want a new MS for empty messages MessageSession* session = new MessageSession( this, msg.from(), true, msg.subtype() ); msHandler->handleMessageSession( session ); session->handleMessage( msg ); @@ -1483,6 +1781,14 @@ namespace gloox return false; } + std::string ClientBase::getRandom() + { + char cn[4*8+1]; + for( int i = 0; i < 4; ++i ) + sprintf( cn + i*8, "%08x", rand() ); + return std::string( cn, 4*8 );; + } + CompressionBase* ClientBase::getDefaultCompression() { if( !m_compress ) diff --git a/libs/libgloox/clientbase.h b/libs/libgloox/clientbase.h index 4aadbda..ea5fe3a 100644 --- a/libs/libgloox/clientbase.h +++ b/libs/libgloox/clientbase.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -28,6 +28,7 @@ #include "compressiondatahandler.h" #include "connectiondatahandler.h" #include "parser.h" +#include "atomicrefcount.h" #include #include @@ -69,7 +70,7 @@ namespace gloox * It manages connection establishing, authentication, filter registration and invocation. * You should normally use Client for client connections and Component for component connections. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.3 */ class GLOOX_API ClientBase : public TagHandler, public ConnectionDataHandler, @@ -128,7 +129,7 @@ namespace gloox * until data was available. * @return The state of the connection. */ - ConnectionError recv( int timeout = -1 ); + virtual ConnectionError recv( int timeout = -1 ); /** * Reimplement this function to provide a username for connection purposes. @@ -147,7 +148,7 @@ namespace gloox /** * Switches usage of SASL on/off. Default: on. SASL should only be disabled if there are - * problems with using it. + * problems with using it, and if an alternative authentication method exists. * @param sasl Whether to switch SASL usage on or off. */ void setSasl( bool sasl ) { m_sasl = sasl; } @@ -280,7 +281,7 @@ namespace gloox * A convenience function that sends the given Presence stanza. * @param pres The Presence stanza to send. */ - void send( Presence& pres ); + void send( const Presence& pres ); /** * Returns whether authentication has taken place and was successful. @@ -363,7 +364,7 @@ namespace gloox void whitespacePing(); /** - * Sends a XMPP Ping (XEP-0199) to the given JID. + * Sends a XMPP Ping (@xep{0199}) to the given JID. * @param to Then entity to ping. * @param eh An EventHandler to inform about the reply. * @since 0.9 @@ -433,7 +434,7 @@ namespace gloox /** * Removes the given IqHandler from the list of handlers of pending operations, added - * using trackID(). Necessary, for example, when closing a GUI element that has an + * using send( IQ&, IqHandler*, int, bool ). Necessary, for example, when closing a GUI element that has an * operation pending. * @param ih The IqHandler to remove. * @since 0.8.7 @@ -678,6 +679,15 @@ namespace gloox */ const StanzaExtensionList& presenceExtensions() const { return m_presenceExtensions; } + /** + * Returns a list of Tags that are currently in the send queue. + * You should not rely on the currentness of this data when there is an established connection. + * @return A 'decoupled' list of Tags (deep copies) in the send queue. The caller is responsible + * for deleting the tags. + * @since 1.0.6 + */ + const TagList sendQueue(); + // reimplemented from ParserHandler virtual void handleTag( Tag* tag ); @@ -706,6 +716,9 @@ namespace gloox virtual void handleHandshakeResult( const TLSBase* base, bool success, CertInfo &certinfo ); protected: +#ifdef CLIENTBASE_TEST + public: +#endif /** * This function is called when resource binding yieled an error. * @param error A pointer to an Error object that contains more @@ -786,9 +799,13 @@ namespace gloox void startSASL( SaslMechanism type ); /** - * Releases SASL related resources. + * Verifies the server response after successful authentication (if applicable) and + * releases SASL related resources (if applicable). + * @param payload The server's verification string. + * @return @b True if verification is not supported by the chosen SASL mechanism or could be completed successfully, + * @b false if verification failed. */ - void processSASLSuccess(); + bool processSASLSuccess( const std::string& payload ); /** * Processes the given SASL challenge and sends a response. @@ -819,6 +836,35 @@ namespace gloox */ bool hasTls(); + /** + * Sends the given data unchecked over the underlying transport connection. Use at your own risk. + * The server will check any data received anyway and disconnect if something is wrong. + * @param xml The data to send. + */ + void send( const std::string& xml ); + + /** + * This function checks if there are any unacknowledged Tags in the send queue and resends + * as necessary. + * @param handled The sequence number of the last handled stanza. + * @param resend Whether to resend unhandled stanzas. + * @note This function is part of @xep{0198}. You should not need to use it directly. + * @since 1.0.4 + */ + void checkQueue( int handled, bool resend ); + + /** + * Returns the number of sent stanzas, if Stream Management is enabled. + * @return The number of sent stanzas. + */ + int stanzasSent() const { return m_smSent; } + + /** + * Returns 32 octets of random characters. + * @return Random characters. + */ + std::string getRandom(); + JID m_jid; /**< The 'self' JID. */ JID m_authzid; /**< An optional authorization ID. See setAuthzid(). */ std::string m_authcid; /**< An alternative authentication ID. See setAuthcid(). */ @@ -830,8 +876,10 @@ namespace gloox /** A list of permanent presence extensions. */ StanzaExtensionList m_presenceExtensions; - std::string m_selectedResource; /**< The currently selected resource. - * See Client::selectResource() and Client::binRessource(). */ + GLOOX_DEPRECATED std::string m_selectedResource; /**< The currently selected resource. + * See Client::selectResource() and Client::bindRessource(). + * @deprecated Not used anymore. Will be removed for 1.1. + * @todo Remove for 1.1 */ std::string m_clientCerts; /**< TLS client certificates. */ std::string m_clientKey; /**< TLS client private key. */ std::string m_namespace; /**< Default namespace. */ @@ -855,14 +903,31 @@ namespace gloox int m_availableSaslMechs; /**< The SASL mechanisms the server offered. */ + /** + * An enum for the Stream Management state machine. + */ + enum SMContext + { + CtxSMInvalid, /**< Initial value. */ + CtxSMFailed, /**< Either of the below failed. */ + CtxSMEnable, /**< 'enable' request sent */ + CtxSMResume, /**< 'resume' request sent */ + CtxSMEnabled, /**< Stream Management successfully enabled. */ + CtxSMResumed /**< Stream successfully resumed. */ + }; + + SMContext m_smContext; /**< The Stream Management state. Used in @xep{0198}. */ + int m_smHandled; /**< The number of handled stanzas. Used in @xep{0198}. + * You should NOT mess with this. */ + private: #ifdef CLIENTBASE_TEST public: #endif /** - * @brief This is an implementation of an XMPP Ping (XEP-199). + * @brief This is an implementation of an XMPP Ping (@xep{0199}). * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class Ping : public StanzaExtension @@ -908,18 +973,24 @@ namespace gloox /** * This function is called right after the opening <stream:stream> was received. + * @param start The complete stream opening tag. Note that the XML representation (Tag::xml()) + * will contain a closed stream tag. The original is open. */ - virtual void handleStartNode() = 0; + virtual void handleStartNode( const Tag* start ) = 0; /** * This function is called for each Tag. Only stream initiation/negotiation should * be done here. * @param tag A Tag to handle. + * @return Returns @b true if the tag has been handled inside the function, @b false otherwise. */ virtual bool handleNormalNode( Tag* tag ) = 0; virtual void rosterFilled() = 0; virtual void cleanup() {} virtual void handleIqIDForward( const IQ& iq, int context ) { (void) iq; (void) context; } + void send( Tag* tag, bool queue, bool del ); + std::string hmac( const std::string& str, const std::string& key ); + std::string hi( const std::string& str, const std::string& key, int iter ); void parse( const std::string& data ); void init(); @@ -933,7 +1004,6 @@ namespace gloox void notifySubscriptionHandlers( Subscription& s10n ); void notifyTagHandlers( Tag* tag ); void notifyOnDisconnect( ConnectionError e ); - void send( const std::string& xml ); void addFrom( Tag* tag ); void addNamespace( Tag* tag ); @@ -973,6 +1043,7 @@ namespace gloox typedef std::multimap IqHandlerMap; typedef std::map IqTrackMap; typedef std::map MessageHandlerMap; + typedef std::map SMQueueMap; typedef std::list MessageSessionList; typedef std::list MessageHandlerList; typedef std::list PresenceHandlerList; @@ -984,6 +1055,7 @@ namespace gloox IqHandlerMapXmlns m_iqNSHandlers; IqHandlerMap m_iqExtHandlers; IqTrackMap m_iqIDHandlers; + SMQueueMap m_smQueue; MessageSessionList m_messageSessions; MessageHandlerList m_messageHandlers; PresenceHandlerList m_presenceHandlers; @@ -999,6 +1071,8 @@ namespace gloox MessageSessionHandler * m_messageSessionHandlerNormal; util::Mutex m_iqHandlerMapMutex; + util::Mutex m_iqExtHandlerMapMutex; + util::Mutex m_queueMutex; Parser m_parser; LogSink m_logInstance; @@ -1015,8 +1089,16 @@ namespace gloox SaslMechanism m_selectedSaslMech; + std::string m_clientFirstMessageBare; + std::string m_serverSignature; + std::string m_gs2Header; std::string m_ntlmDomain; - bool m_autoMessageSession; + bool m_customConnection; + + int m_uniqueBaseId; + util::AtomicRefCount m_nextId; + + int m_smSent; #if defined( _WIN32 ) && !defined( __SYMBIAN32__ ) CredHandle m_credHandle; diff --git a/libs/libgloox/component.cpp b/libs/libgloox/component.cpp index 9f2e202..a49ff74 100644 --- a/libs/libgloox/component.cpp +++ b/libs/libgloox/component.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -32,7 +32,7 @@ namespace gloox m_disco->setIdentity( "component", "generic" ); } - void Component::handleStartNode() + void Component::handleStartNode( const Tag* /*start*/ ) { if( m_sid.empty() ) return; diff --git a/libs/libgloox/component.h b/libs/libgloox/component.h index d6c02d7..6fb0a81 100644 --- a/libs/libgloox/component.h +++ b/libs/libgloox/component.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -25,9 +25,9 @@ namespace gloox /** * @brief This is an implementation of a basic jabber Component. * - * It's using XEP-0114 (Jabber Component Protocol) to authenticate with a server. + * It's using @xep{0114} (Jabber Component Protocol) to authenticate with a server. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.3 */ class GLOOX_API Component : public ClientBase @@ -36,7 +36,7 @@ namespace gloox /** * Constructs a new Component. * @param ns The namespace that qualifies the stream. Either @b jabber:component:accept or - * @b jabber:component:connect. See XEP-0114 for details. + * @b jabber:component:connect. See @xep{0114} for details. * @param server The server to connect to. * @param component The component's hostname. FQDN. * @param password The component's password. @@ -54,11 +54,11 @@ namespace gloox /** * Disconnects from the server. */ - void disconnect() { ClientBase::disconnect( ConnUserDisconnected ); } + virtual void disconnect() { ClientBase::disconnect( ConnUserDisconnected ); } protected: // reimplemented from ClientBase - virtual void handleStartNode(); + virtual void handleStartNode( const Tag* start ); // reimplemented from ClientBase virtual bool handleNormalNode( Tag* tag ); diff --git a/libs/libgloox/compressionbase.h b/libs/libgloox/compressionbase.h index c3a178b..40e6227 100644 --- a/libs/libgloox/compressionbase.h +++ b/libs/libgloox/compressionbase.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -28,7 +28,7 @@ namespace gloox * * You should not need to use this class directly. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API CompressionBase diff --git a/libs/libgloox/compressiondatahandler.h b/libs/libgloox/compressiondatahandler.h index 0eb5178..190ca8d 100644 --- a/libs/libgloox/compressiondatahandler.h +++ b/libs/libgloox/compressiondatahandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -28,7 +28,7 @@ namespace gloox * * You should not need to use this class directly. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API CompressionDataHandler diff --git a/libs/libgloox/compressiondefault.cpp b/libs/libgloox/compressiondefault.cpp index 066cc93..6486bab 100644 --- a/libs/libgloox/compressiondefault.cpp +++ b/libs/libgloox/compressiondefault.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009 by Jakob Schroeter + * Copyright (c) 2009-2015 by Jakob Schröter * This file is part of the gloox library. http://camaya.net/gloox * * This software is distributed under a license. The full license diff --git a/libs/libgloox/compressiondefault.h b/libs/libgloox/compressiondefault.h index 38b83f0..43fb510 100644 --- a/libs/libgloox/compressiondefault.h +++ b/libs/libgloox/compressiondefault.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009 by Jakob Schroeter + * Copyright (c) 2009-2015 by Jakob Schröter * This file is part of the gloox library. http://camaya.net/gloox * * This software is distributed under a license. The full license @@ -24,7 +24,7 @@ namespace gloox /** * @brief This is an abstraction of the various Compression implementations. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API CompressionDefault : public CompressionBase diff --git a/libs/libgloox/compressionzlib.cpp b/libs/libgloox/compressionzlib.cpp index 4d0b937..b947626 100644 --- a/libs/libgloox/compressionzlib.cpp +++ b/libs/libgloox/compressionzlib.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -71,13 +71,12 @@ namespace gloox m_zdeflate.avail_in = static_cast( data.length() ); m_zdeflate.next_in = (Bytef*)in; - int ret; std::string result; do { m_zdeflate.avail_out = static_cast( CHUNK ); m_zdeflate.next_out = (Bytef*)out; - ret = deflate( &m_zdeflate, Z_SYNC_FLUSH ); + deflate( &m_zdeflate, Z_SYNC_FLUSH ); result.append( (char*)out, CHUNK - m_zdeflate.avail_out ); } while( m_zdeflate.avail_out == 0 ); @@ -103,14 +102,13 @@ namespace gloox m_zinflate.avail_in = static_cast( data.length() ); m_zinflate.next_in = (Bytef*)in; - int ret = Z_OK; std::string result; do { m_zinflate.avail_out = CHUNK; m_zinflate.next_out = (Bytef*)out; - ret = inflate( &m_zinflate, Z_SYNC_FLUSH ); + inflate( &m_zinflate, Z_SYNC_FLUSH ); result.append( out, CHUNK - m_zinflate.avail_out ); } while( m_zinflate.avail_out == 0 ); @@ -121,13 +119,17 @@ namespace gloox void CompressionZlib::cleanup() { - if( !m_valid ) - return; + m_compressMutex.lock(); - inflateEnd( &m_zinflate ); - deflateEnd( &m_zdeflate ); + if( m_valid ) + { + inflateEnd( &m_zinflate ); + deflateEnd( &m_zdeflate ); - m_valid = false; + m_valid = false; + } + + m_compressMutex.unlock(); } } diff --git a/libs/libgloox/compressionzlib.h b/libs/libgloox/compressionzlib.h index 3f7ba6e..b275eaf 100644 --- a/libs/libgloox/compressionzlib.h +++ b/libs/libgloox/compressionzlib.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -30,7 +30,7 @@ namespace gloox /** * An implementation of CompressionBase using zlib. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API CompressionZlib : public CompressionBase diff --git a/libs/libgloox/config.h b/libs/libgloox/config.h index fb5d2af..20046e8 100644 --- a/libs/libgloox/config.h +++ b/libs/libgloox/config.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2009 by Jakob Schroeter + Copyright (c) 2009-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/config.h.unix b/libs/libgloox/config.h.unix index 9d24b5b..4464741 100644 --- a/libs/libgloox/config.h.unix +++ b/libs/libgloox/config.h.unix @@ -13,12 +13,18 @@ /* Define to 1 if you have the header file. */ #define HAVE_ERRNO_H 1 +/* Define to 1 if GCC atomic builtins are available */ +#define HAVE_GCC_ATOMIC_BUILTINS 1 + /* Define to 1 if you have the `getaddrinfo' function. */ /* #undef HAVE_GETADDRINFO */ /* Define to 1 if you want TLS support (GnuTLS). Undefine HAVE_OPENSSL. */ /* #undef HAVE_GNUTLS */ +/* Define to 1 if you have GnuTLS 2.12.0 or above. */ +/* #undef HAVE_GNUTLS_SESSION_CHANNEL_BINDING */ + /* Define to 1 if you have the header file. */ #define HAVE_INTTYPES_H 1 @@ -28,15 +34,15 @@ /* Define to 1 if you want IDN support. */ /* #undef HAVE_LIBIDN */ -/* Define to 1 if you have the `network' library (-lnetwork). */ -#define HAVE_LIBNETWORK 1 - /* Define to 1 if you have the `resolv' library (-lresolv). */ /* #undef HAVE_LIBRESOLV */ /* Define to 1 if you have the `socket' library (-lsocket). */ /* #undef HAVE_LIBSOCKET */ +/* enable mdns support */ +/* #undef HAVE_MDNS */ + /* Define to 1 if you have the header file. */ #define HAVE_MEMORY_H 1 @@ -53,7 +59,7 @@ /* #undef HAVE_RES_QUERYDOMAIN */ /* Define to 1 if you have the `setsockopt' function. */ -#define HAVE_SETSOCKOPT 1 +/* #undef HAVE_SETSOCKOPT */ /* Define to 1 if you have the header file. */ #define HAVE_STDINT_H 1 @@ -93,7 +99,7 @@ #define PACKAGE_NAME "gloox" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "gloox 1.0" +#define PACKAGE_STRING "gloox 1.0.13" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "gloox" @@ -102,7 +108,7 @@ #define PACKAGE_URL "" /* Define to the version of this package. */ -#define PACKAGE_VERSION "1.0" +#define PACKAGE_VERSION "1.0.13" /* Define to necessary symbol if this constant uses a non-standard name on your system. */ @@ -112,6 +118,7 @@ #define STDC_HEADERS 1 /* Version number of package */ +#define VERSION "1.0.13" /* Define to empty if `const' does not conform to ANSI C. */ /* #undef const */ diff --git a/libs/libgloox/connectionbase.h b/libs/libgloox/connectionbase.h index ca2a96c..b5ae5c7 100644 --- a/libs/libgloox/connectionbase.h +++ b/libs/libgloox/connectionbase.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -28,7 +28,7 @@ namespace gloox * * You should not need to use this class directly. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API ConnectionBase diff --git a/libs/libgloox/connectionbosh.cpp b/libs/libgloox/connectionbosh.cpp index c433564..58b9961 100644 --- a/libs/libgloox/connectionbosh.cpp +++ b/libs/libgloox/connectionbosh.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007-2009 by Jakob Schroeter + * Copyright (c) 2007-2015 by Jakob Schröter * This file is part of the gloox library. http://camaya.net/gloox * * This software is distributed under a license. The full license @@ -110,7 +110,7 @@ namespace gloox m_state = StateConnecting; m_logInstance.dbg( LogAreaClassConnectionBOSH, - "bosh initiating connection to server: " + + "Initiating BOSH connection to server: " + ( ( m_connMode == ModePipelining ) ? std::string( "Pipelining" ) : ( ( m_connMode == ModeLegacyHTTP ) ? std::string( "LegacyHTTP" ) : std::string( "PersistentHTTP" ) ) ) ); @@ -142,12 +142,12 @@ namespace gloox } sendRequest( requestBody ); - m_logInstance.dbg( LogAreaClassConnectionBOSH, "bosh disconnection request sent" ); + m_logInstance.dbg( LogAreaClassConnectionBOSH, "BOSH disconnection request sent" ); } else { m_logInstance.err( LogAreaClassConnectionBOSH, - "disconnecting from server in a non-graceful fashion" ); + "Disconnecting from server in a non-graceful fashion" ); } util::ForEach( m_activeConnections, &ConnectionBase::disconnect ); @@ -160,13 +160,15 @@ namespace gloox ConnectionError ConnectionBOSH::recv( int timeout ) { + ConnectionError ret = ConnNoError; + if( m_state == StateDisconnected ) return ConnNotConnected; if( !m_connectionPool.empty() ) - m_connectionPool.front()->recv( 0 ); + ret = m_connectionPool.front()->recv( 0 ); if( !m_activeConnections.empty() ) - m_activeConnections.front()->recv( timeout ); + ret = m_activeConnections.front()->recv( timeout ); // If there are no open requests then the spec allows us to send an empty request... // (Some CMs do not obey this, it seems) @@ -177,7 +179,7 @@ namespace gloox sendXML(); } - return ConnNoError; // FIXME? + return ret; } bool ConnectionBOSH::send( const std::string& data ) @@ -197,7 +199,7 @@ namespace gloox // else // { // m_initialStreamSent = true; -// m_logInstance.dbg( LogAreaClassConnectionBOSH, "initial dropped" ); +// m_logInstance.dbg( LogAreaClassConnectionBOSH, "Initial dropped" ); // return true; // } } @@ -260,7 +262,7 @@ namespace gloox --m_rid; // I think... (may need to rethink when acks are implemented) m_logInstance.warn( LogAreaClassConnectionBOSH, "Unable to send. Connection not complete, or too many open requests," - " so added to buffer.\n" ); + " so added to buffer." ); } return true; @@ -303,7 +305,7 @@ namespace gloox bool ci_equal( char ch1, char ch2 ) { - return toupper( (unsigned char)ch1 ) == toupper( (unsigned char)ch2 ); + return std::toupper( (unsigned char)ch1 ) == std::toupper( (unsigned char)ch2 ); } std::string::size_type ci_find( const std::string& str1, const std::string& str2 ) @@ -397,7 +399,7 @@ namespace gloox } else { - m_logInstance.warn( LogAreaClassConnectionBOSH, "buffer length mismatch" ); + m_logInstance.warn( LogAreaClassConnectionBOSH, "Buffer length mismatch" ); break; } } @@ -425,7 +427,7 @@ namespace gloox requestBody.addAttribute( "xmpp:version", "1.0" ); requestBody.addAttribute( "to", m_server ); - m_logInstance.dbg( LogAreaClassConnectionBOSH, "sending bosh connection request" ); + m_logInstance.dbg( LogAreaClassConnectionBOSH, "Sending BOSH connection request" ); sendRequest( requestBody.xml() ); } } @@ -445,7 +447,7 @@ namespace gloox case ModePipelining: m_connMode = ModeLegacyHTTP; // Server seems not to support pipelining m_logInstance.dbg( LogAreaClassConnectionBOSH, - "connection closed - falling back to HTTP/1.0 connection method" ); + "Connection closed - falling back to HTTP/1.0 connection method" ); break; case ModeLegacyHTTP: case ModePersistentHTTP: @@ -463,7 +465,7 @@ namespace gloox if( m_streamRestart ) { m_streamRestart = false; - m_logInstance.dbg( LogAreaClassConnectionBOSH, "sending spoofed " ); + m_logInstance.dbg( LogAreaClassConnectionBOSH, "Sending spoofed " ); m_handler->handleReceivedData( this, "" "findAttribute( "requests" ) ); + "BOSH parameter 'requests' now set to " + tag->findAttribute( "requests" ) ); } } if( tag->hasAttribute( "hold" ) ) @@ -493,7 +495,7 @@ namespace gloox { m_hold = maxHold; m_logInstance.dbg( LogAreaClassConnectionBOSH, - "bosh parameter 'hold' now set to " + tag->findAttribute( "hold" ) ); + "BOSH parameter 'hold' now set to " + tag->findAttribute( "hold" ) ); } } if( tag->hasAttribute( "wait" ) ) @@ -503,7 +505,7 @@ namespace gloox { m_wait = maxWait; m_logInstance.dbg( LogAreaClassConnectionBOSH, - "bosh parameter 'wait' now set to " + tag->findAttribute( "wait" ) + "BOSH parameter 'wait' now set to " + tag->findAttribute( "wait" ) + " seconds" ); } } @@ -512,7 +514,7 @@ namespace gloox const int minTime = atoi( tag->findAttribute( "polling" ).c_str() ); m_minTimePerRequest = minTime; m_logInstance.dbg( LogAreaClassConnectionBOSH, - "bosh parameter 'polling' now set to " + tag->findAttribute( "polling" ) + "BOSH parameter 'polling' now set to " + tag->findAttribute( "polling" ) + " seconds" ); } @@ -531,7 +533,7 @@ namespace gloox if( tag->findAttribute( "type" ) == "terminate" ) { m_logInstance.dbg( LogAreaClassConnectionBOSH, - "bosh connection closed by server: " + tag->findAttribute( "condition" ) ); + "BOSH connection closed by server: " + tag->findAttribute( "condition" ) ); m_state = StateDisconnected; m_handler->handleDisconnect( this, ConnStreamClosed ); return; diff --git a/libs/libgloox/connectionbosh.h b/libs/libgloox/connectionbosh.h index 8781c4c..ef74882 100644 --- a/libs/libgloox/connectionbosh.h +++ b/libs/libgloox/connectionbosh.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007-2009 by Jakob Schroeter + * Copyright (c) 2007-2015 by Jakob Schröter * This file is part of the gloox library. http://camaya.net/gloox * * This software is distributed under a license. The full license @@ -58,7 +58,7 @@ namespace gloox * with gloox in the @b src/examples/ directory. * * @author Matthew Wild - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API ConnectionBOSH : public ConnectionBase, ConnectionDataHandler, TagHandler diff --git a/libs/libgloox/connectiondatahandler.h b/libs/libgloox/connectiondatahandler.h index 424ca55..6481644 100644 --- a/libs/libgloox/connectiondatahandler.h +++ b/libs/libgloox/connectiondatahandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -29,7 +29,7 @@ namespace gloox * * You should not need to use this class directly. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API ConnectionDataHandler diff --git a/libs/libgloox/connectionhandler.h b/libs/libgloox/connectionhandler.h index fc0d1eb..20b0060 100644 --- a/libs/libgloox/connectionhandler.h +++ b/libs/libgloox/connectionhandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -27,7 +27,7 @@ namespace gloox * * You should not need to use this class directly. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API ConnectionHandler diff --git a/libs/libgloox/connectionhttpproxy.cpp b/libs/libgloox/connectionhttpproxy.cpp index fa3223a..8a4d48e 100644 --- a/libs/libgloox/connectionhttpproxy.cpp +++ b/libs/libgloox/connectionhttpproxy.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -139,7 +139,7 @@ namespace gloox m_proxyHandshakeBuffer = EmptyString; m_state = StateConnected; m_logInstance.dbg( LogAreaClassConnectionHTTPProxy, - "http proxy connection established" ); + "HTTP proxy connection established" ); m_handler->handleConnect( this ); } else if( !m_proxyHandshakeBuffer.compare( 9, 3, "407" ) ) @@ -174,7 +174,7 @@ namespace gloox port = host.second; } } - std::string message = "Requesting http proxy connection to " + server + ":" + std::string message = "Requesting HTTP proxy connection to " + server + ":" + util::int2string( port ); m_logInstance.dbg( LogAreaClassConnectionHTTPProxy, message ); diff --git a/libs/libgloox/connectionhttpproxy.h b/libs/libgloox/connectionhttpproxy.h index 69ba399..d830f92 100644 --- a/libs/libgloox/connectionhttpproxy.h +++ b/libs/libgloox/connectionhttpproxy.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -47,7 +47,7 @@ namespace gloox * The reason why ConnectionHTTPProxy doesn't manage its own ConnectionTCPClient is that it allows it * to be used with other transports (like IPv6 or chained SOCKS5/HTTP proxies). * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API ConnectionHTTPProxy : public ConnectionBase, public ConnectionDataHandler diff --git a/libs/libgloox/connectionlistener.h b/libs/libgloox/connectionlistener.h index 27940cf..fe945e5 100644 --- a/libs/libgloox/connectionlistener.h +++ b/libs/libgloox/connectionlistener.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -28,7 +28,7 @@ namespace gloox * In onTLSConnect(), the server's certificate information needs to be checked, and @b true * returned if the certificate is to be accepted. * - * @author Jakob Schroeter + * @author Jakob Schröter */ class GLOOX_API ConnectionListener { diff --git a/libs/libgloox/connectionsocks5proxy.cpp b/libs/libgloox/connectionsocks5proxy.cpp index 0ee42f5..d77d078 100644 --- a/libs/libgloox/connectionsocks5proxy.cpp +++ b/libs/libgloox/connectionsocks5proxy.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/connectionsocks5proxy.h b/libs/libgloox/connectionsocks5proxy.h index dfcbe1c..68dc980 100644 --- a/libs/libgloox/connectionsocks5proxy.h +++ b/libs/libgloox/connectionsocks5proxy.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -47,7 +47,7 @@ namespace gloox * @note Simple @b plain-text username/password authentication is supported. GSSAPI authentication * is not supported. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API ConnectionSOCKS5Proxy : public ConnectionBase, public ConnectionDataHandler diff --git a/libs/libgloox/connectiontcpbase.cpp b/libs/libgloox/connectiontcpbase.cpp index 6a103a6..bceb025 100644 --- a/libs/libgloox/connectiontcpbase.cpp +++ b/libs/libgloox/connectiontcpbase.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -19,6 +19,7 @@ #include "logsink.h" #include "prep.h" #include "mutexguard.h" +#include "util.h" #ifdef __MINGW32__ # include @@ -32,6 +33,7 @@ # include # include # include +# include #elif ( defined( _WIN32 ) || defined( _WIN32_WCE ) ) && !defined( __SYMBIAN32__ ) # include typedef int socklen_t; @@ -49,7 +51,7 @@ namespace gloox const std::string& server, int port ) : ConnectionBase( 0 ), m_logInstance( logInstance ), m_buf( 0 ), m_socket( -1 ), m_totalBytesIn( 0 ), - m_totalBytesOut( 0 ), m_bufsize( 1024 ), m_cancel( true ) + m_totalBytesOut( 0 ), m_bufsize( 8192 ), m_cancel( true ) { init( server, port ); } @@ -58,7 +60,7 @@ namespace gloox const std::string& server, int port ) : ConnectionBase( cdh ), m_logInstance( logInstance ), m_buf( 0 ), m_socket( -1 ), m_totalBytesIn( 0 ), - m_totalBytesOut( 0 ), m_bufsize( 1024 ), m_cancel( true ) + m_totalBytesOut( 0 ), m_bufsize( 8192 ), m_cancel( true ) { init( server, port ); } @@ -110,7 +112,7 @@ namespace gloox return ConnNotConnected; ConnectionError err = ConnNoError; - while( !m_cancel && ( err = recv( 10 ) ) == ConnNoError ) + while( !m_cancel && ( err = recv( 1000000 ) ) == ConnNoError ) ; return err == ConnNoError ? ConnNotConnected : err; } @@ -135,8 +137,20 @@ namespace gloox m_sendMutex.unlock(); - if( sent == -1 && m_handler ) - m_handler->handleDisconnect( this, ConnIoError ); + if( sent == -1 ) + { + // send() failed for an unexpected reason + std::string message = "send() failed. " +#if defined( _WIN32 ) && !defined( __SYMBIAN32__ ) + "WSAGetLastError: " + util::int2string( ::WSAGetLastError() ); +#else + "errno: " + util::int2string( errno ) + ": " + strerror( errno ); +#endif + m_logInstance.err( LogAreaClassConnectionTCPBase, message ); + + if( m_handler ) + m_handler->handleDisconnect( this, ConnIoError ); + } return sent != -1; } diff --git a/libs/libgloox/connectiontcpbase.h b/libs/libgloox/connectiontcpbase.h index 5ece2b1..a247afb 100644 --- a/libs/libgloox/connectiontcpbase.h +++ b/libs/libgloox/connectiontcpbase.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -34,7 +34,7 @@ namespace gloox * * You should not need to use this class directly. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API ConnectionTCPBase : public ConnectionBase diff --git a/libs/libgloox/connectiontcpclient.cpp b/libs/libgloox/connectiontcpclient.cpp index 4b35bf6..ab52bd3 100644 --- a/libs/libgloox/connectiontcpclient.cpp +++ b/libs/libgloox/connectiontcpclient.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -18,6 +18,7 @@ #include "dns.h" #include "logsink.h" #include "mutexguard.h" +#include "util.h" #ifdef __MINGW32__ # include @@ -28,6 +29,8 @@ # include # include # include +# include +# include #elif ( defined( _WIN32 ) || defined( _WIN32_WCE ) ) && !defined( __SYMBIAN32__ ) # include #endif @@ -142,6 +145,18 @@ namespace gloox if( size <= 0 ) { + if( size == -1 ) + { + // recv() failed for an unexpected reason + std::string message = "recv() failed. " +#if defined( _WIN32 ) && !defined( __SYMBIAN32__ ) + "WSAGetLastError: " + util::int2string( ::WSAGetLastError() ); +#else + "errno: " + util::int2string( errno ) + ": " + strerror( errno ); +#endif + m_logInstance.err( LogAreaClassConnectionTCPClient, message ); + } + ConnectionError error = ( size ? ConnIoError : ConnStreamClosed ); if( m_handler ) m_handler->handleDisconnect( this, error ); diff --git a/libs/libgloox/connectiontcpclient.h b/libs/libgloox/connectiontcpclient.h index 0f3a5b5..4213b7d 100644 --- a/libs/libgloox/connectiontcpclient.h +++ b/libs/libgloox/connectiontcpclient.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -30,7 +30,7 @@ namespace gloox * the raw socket(), or if you need HTTP proxy support (see @ref gloox::ConnectionHTTPProxy for more * information). * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API ConnectionTCPClient : public ConnectionTCPBase diff --git a/libs/libgloox/connectiontcpserver.cpp b/libs/libgloox/connectiontcpserver.cpp index fa108e2..a342cbc 100644 --- a/libs/libgloox/connectiontcpserver.cpp +++ b/libs/libgloox/connectiontcpserver.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -14,6 +14,8 @@ #include "gloox.h" +#include "config.h" + #include "connectiontcpserver.h" #include "connectiontcpclient.h" #include "connectionhandler.h" @@ -38,7 +40,6 @@ # include # include # include -# include #endif #if defined( _WIN32 ) && !defined( __SYMBIAN32__ ) @@ -88,6 +89,22 @@ namespace gloox if( m_socket < 0 ) return ConnIoError; +#ifdef HAVE_SETSOCKOPT + int buf = 0; +#if defined( _WIN32 ) && !defined( __SYMBIAN32__ ) + int bufbytes = sizeof( int ); +#else + socklen_t bufbytes = sizeof( int ); +#endif + if( ( getsockopt( m_socket, SOL_SOCKET, SO_RCVBUF, (char*)&buf, &bufbytes ) != -1 ) && + ( m_bufsize > buf ) ) + setsockopt( m_socket, SOL_SOCKET, SO_RCVBUF, (char*)&m_bufsize, sizeof( m_bufsize ) ); + + if( ( getsockopt( m_socket, SOL_SOCKET, SO_SNDBUF, (char*)&buf, &bufbytes ) != -1 ) && + ( m_bufsize > buf ) ) + setsockopt( m_socket, SOL_SOCKET, SO_SNDBUF, (char*)&m_bufsize, sizeof( m_bufsize ) ); +#endif + struct sockaddr_in local; local.sin_family = AF_INET; local.sin_port = static_cast( htons( m_port ) ); diff --git a/libs/libgloox/connectiontcpserver.h b/libs/libgloox/connectiontcpserver.h index ef0bd08..3d0e899 100644 --- a/libs/libgloox/connectiontcpserver.h +++ b/libs/libgloox/connectiontcpserver.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -30,7 +30,7 @@ namespace gloox * * You should not need to use this class directly. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API ConnectionTCPServer : public ConnectionTCPBase @@ -38,7 +38,7 @@ namespace gloox public: /** * Constructs a new ConnectionTCPServer object. - * @param ch An ConnectionHandler-derived object that will handle incoming connections. + * @param ch A ConnectionHandler-derived object that will handle incoming connections. * @param logInstance The log target. Obtain it from ClientBase::logInstance(). * @param ip The local IP address to listen on. This must @b not be a hostname. * Leave this empty to listen on all local interfaces. diff --git a/libs/libgloox/connectiontls.cpp b/libs/libgloox/connectiontls.cpp index 7429bed..8f3cfd0 100644 --- a/libs/libgloox/connectiontls.cpp +++ b/libs/libgloox/connectiontls.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007-2009 by Jakob Schroeter + * Copyright (c) 2007-2015 by Jakob Schröter * This file is part of the gloox library. http://camaya.net/gloox * * This software is distributed under a license. The full license @@ -14,6 +14,8 @@ #include "connectiontls.h" #include "tlsdefault.h" +#include + namespace gloox { @@ -84,16 +86,7 @@ namespace gloox ConnectionError ConnectionTLS::recv( int timeout ) { - if( m_connection->state() == StateConnected ) - { - return m_connection->recv( timeout ); - } - else - { - m_log.log( LogLevelWarning, LogAreaClassConnectionTLS, - "Attempt to receive data on a connection that is not connected (or is connecting)" ); - return ConnNotConnected; - } + return m_connection ? m_connection->recv( timeout ) : ConnNotConnected; } bool ConnectionTLS::send( const std::string& data ) @@ -198,6 +191,9 @@ namespace gloox m_log.log( LogLevelWarning, LogAreaClassConnectionTLS, "TLS handshake failed" ); if( m_tlsHandler ) m_tlsHandler->handleHandshakeResult( tls, success, certinfo ); + cleanup(); + if( m_handler ) + m_handler->handleDisconnect( this, ConnTlsFailed ); } } diff --git a/libs/libgloox/connectiontls.h b/libs/libgloox/connectiontls.h index fc197c0..d508ee1 100644 --- a/libs/libgloox/connectiontls.h +++ b/libs/libgloox/connectiontls.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007-2009 by Jakob Schroeter + * Copyright (c) 2007-2015 by Jakob Schröter * This file is part of the gloox library. http://camaya.net/gloox * * This software is distributed under a license. The full license @@ -35,7 +35,7 @@ namespace gloox * @code * Client *c = new Client( ... ); * c->setConnectionImpl( new ConnectionTLS( c, - * new ConnectionTCP( c->logInstance(), server, 5223 ), + * new ConnectionTCPClient( c->logInstance(), server, 5223 ), * c->logInstance()) ); * @endcode * @@ -43,7 +43,7 @@ namespace gloox * established, be sure not to use the connection until ConnectionDataHandler::handleConnect() * of the specified ConnectionDataHandler is called. * - * @author Jakob Schroeter + * @author Jakob Schröter * @author Matthew Wild * @since 1.0 */ diff --git a/libs/libgloox/connectiontlsserver.cpp b/libs/libgloox/connectiontlsserver.cpp index 01aff74..0b9c663 100644 --- a/libs/libgloox/connectiontlsserver.cpp +++ b/libs/libgloox/connectiontlsserver.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009 by Jakob Schroeter + * Copyright (c) 2009-2015 by Jakob Schröter * This file is part of the gloox library. http://camaya.net/gloox * * This software is distributed under a license. The full license diff --git a/libs/libgloox/connectiontlsserver.h b/libs/libgloox/connectiontlsserver.h index 7fb5637..68d822c 100644 --- a/libs/libgloox/connectiontlsserver.h +++ b/libs/libgloox/connectiontlsserver.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009 by Jakob Schroeter + * Copyright (c) 2009-2015 by Jakob Schröter * This file is part of the gloox library. http://camaya.net/gloox * * This software is distributed under a license. The full license @@ -32,7 +32,7 @@ namespace gloox * * You should not need to use this class directly. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API ConnectionTLSServer : public ConnectionTLS diff --git a/libs/libgloox/dataform.cpp b/libs/libgloox/dataform.cpp index 7cb6b12..e4fc2ad 100644 --- a/libs/libgloox/dataform.cpp +++ b/libs/libgloox/dataform.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -22,26 +22,26 @@ namespace gloox { DataForm::DataForm( FormType type, const StringList& instructions, const std::string& title ) - : StanzaExtension( ExtDataForm ), + : AdhocPlugin( ExtDataForm ), m_type( type ), m_instructions( instructions ), m_title( title ), m_reported( 0 ) { } DataForm::DataForm( FormType type, const std::string& title ) - : StanzaExtension( ExtDataForm ), + : AdhocPlugin( ExtDataForm ), m_type( type ), m_title( title ), m_reported( 0 ) { } DataForm::DataForm( const Tag* tag ) - : StanzaExtension( ExtDataForm ), + : AdhocPlugin( ExtDataForm ), m_type( TypeInvalid ), m_reported( 0 ) { parse( tag ); } DataForm::DataForm( const DataForm& form ) - : StanzaExtension( ExtDataForm ), DataFormFieldContainer( form ), + : AdhocPlugin( ExtDataForm ), DataFormFieldContainer( form ), m_type( form.m_type ), m_instructions( form.m_instructions ), m_title( form.m_title ), m_reported( form.m_reported ? new DataFormReported( form.m_reported->tag() ) : 0 ) { diff --git a/libs/libgloox/dataform.h b/libs/libgloox/dataform.h index 6fb75d5..23ca086 100644 --- a/libs/libgloox/dataform.h +++ b/libs/libgloox/dataform.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -15,7 +15,7 @@ #define DATAFORM_H__ #include "dataformfieldcontainer.h" -#include "stanzaextension.h" +#include "adhocplugin.h" #include #include @@ -46,14 +46,14 @@ namespace gloox }; /** - * @brief An abstraction of a XEP-0004 Data Form. + * @brief An abstraction of a @xep{0004} Data Form. * * * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.7 */ - class GLOOX_API DataForm : public StanzaExtension, public DataFormFieldContainer + class GLOOX_API DataForm : public AdhocPlugin, public DataFormFieldContainer { public: /** diff --git a/libs/libgloox/dataformfield.cpp b/libs/libgloox/dataformfield.cpp index 462181c..6b46a0e 100644 --- a/libs/libgloox/dataformfield.cpp +++ b/libs/libgloox/dataformfield.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/dataformfield.h b/libs/libgloox/dataformfield.h index c3e21c8..a75e9d0 100644 --- a/libs/libgloox/dataformfield.h +++ b/libs/libgloox/dataformfield.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -25,9 +25,9 @@ namespace gloox class Tag; /** - * @brief An abstraction of a single field in a XEP-0004 Data Form. + * @brief An abstraction of a single field in a @xep{0004} Data Form. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.7 */ class GLOOX_API DataFormField diff --git a/libs/libgloox/dataformfieldcontainer.cpp b/libs/libgloox/dataformfieldcontainer.cpp index dc639bc..6638cd1 100644 --- a/libs/libgloox/dataformfieldcontainer.cpp +++ b/libs/libgloox/dataformfieldcontainer.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/dataformfieldcontainer.h b/libs/libgloox/dataformfieldcontainer.h index fbd2378..7e05338 100644 --- a/libs/libgloox/dataformfieldcontainer.h +++ b/libs/libgloox/dataformfieldcontainer.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -25,11 +25,11 @@ namespace gloox class DataFormField; /** - * @brief An abstract base class for a XEP-0004 Data Form. + * @brief An abstract base class for a @xep{0004} Data Form. * * You shouldn't need to use this class directly. Use DataForm instead. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.7 */ class GLOOX_API DataFormFieldContainer @@ -52,7 +52,7 @@ namespace gloox virtual ~DataFormFieldContainer(); /** - * A list of XEP-0004 Data Form Fields. + * A list of @xep{0004} Data Form Fields. */ typedef std::list FieldList; diff --git a/libs/libgloox/dataformitem.cpp b/libs/libgloox/dataformitem.cpp index af8f6ca..63c7ac8 100644 --- a/libs/libgloox/dataformitem.cpp +++ b/libs/libgloox/dataformitem.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/dataformitem.h b/libs/libgloox/dataformitem.h index 2f95dde..27e2824 100644 --- a/libs/libgloox/dataformitem.h +++ b/libs/libgloox/dataformitem.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -20,12 +20,12 @@ namespace gloox { /** - * @brief An abstraction of an <item> element in a XEP-0004 Data Form of type result. + * @brief An abstraction of an <item> element in a @xep{0004} Data Form of type result. * - * There are some constraints regarding usage of this element you should be aware of. Check XEP-0004 + * There are some constraints regarding usage of this element you should be aware of. Check @xep{0004} * section 3.4. This class does not enforce correct usage at this point. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.7 */ class GLOOX_API DataFormItem : public DataFormFieldContainer diff --git a/libs/libgloox/dataformreported.cpp b/libs/libgloox/dataformreported.cpp index 4a7264f..1fd46e7 100644 --- a/libs/libgloox/dataformreported.cpp +++ b/libs/libgloox/dataformreported.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/dataformreported.h b/libs/libgloox/dataformreported.h index 91294c6..057a915 100644 --- a/libs/libgloox/dataformreported.h +++ b/libs/libgloox/dataformreported.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -22,12 +22,12 @@ namespace gloox class Tag; /** - * @brief An abstraction of a <reported> element in a XEP-0004 Data Form of type result. + * @brief An abstraction of a <reported> element in a @xep{0004} Data Form of type result. * - * There are some constraints regarding usage of this element you should be aware of. Check XEP-0004 + * There are some constraints regarding usage of this element you should be aware of. Check @xep{0004} * section 3.4. This class does not enforce correct usage at this point. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.7 */ class GLOOX_API DataFormReported : public DataFormFieldContainer diff --git a/libs/libgloox/delayeddelivery.cpp b/libs/libgloox/delayeddelivery.cpp index 71038fb..0c7181d 100644 --- a/libs/libgloox/delayeddelivery.cpp +++ b/libs/libgloox/delayeddelivery.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -31,6 +31,7 @@ namespace gloox { if( !tag || !tag->hasAttribute( "stamp" ) ) return; + if( !( tag->name() == "x" && tag->hasAttribute( XMLNS, XMLNS_X_DELAY ) ) ) if( !( tag->name() == "delay" && tag->hasAttribute( XMLNS, XMLNS_DELAY ) ) ) return; diff --git a/libs/libgloox/delayeddelivery.h b/libs/libgloox/delayeddelivery.h index f9953fa..c06fb90 100644 --- a/libs/libgloox/delayeddelivery.h +++ b/libs/libgloox/delayeddelivery.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -26,13 +26,13 @@ namespace gloox class Tag; /** - * @brief This is an implementation of XEP-0203 (Delayed Delivery). + * @brief This is an implementation of @xep{0203} (Delayed Delivery). * - * The class also implements the deprecated XEP-0091 (Delayed Delivery) in a read-only fashion. - * It understands both XEP formats for input, but any output will conform to XEP-0203. + * The class also implements the deprecated @xep{0091} (Delayed Delivery) in a read-only fashion. + * It understands both XEP formats for input, but any output will conform to @xep{0203}. * * XEP Version: 0.1 - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API DelayedDelivery : public StanzaExtension @@ -61,7 +61,7 @@ namespace gloox /** * Returns the datetime when the stanza was originally sent. - * The format MUST adhere to the dateTime format specified in XEP-0082 and MUST + * The format MUST adhere to the dateTime format specified in @xep{0082} and MUST * be expressed in UTC. * @return The original datetime. */ @@ -76,7 +76,7 @@ namespace gloox /** * Returns the JID of the original sender of the stanza or the entity that * delayed the sending. - * The format MUST adhere to the dateTime format specified in XEP-0082 and MUST + * The format MUST adhere to the dateTime format specified in @xep{0082} and MUST * be expressed in UTC. * @return The JID. */ diff --git a/libs/libgloox/disco.cpp b/libs/libgloox/disco.cpp index bfd0cf5..31d36e0 100644 --- a/libs/libgloox/disco.cpp +++ b/libs/libgloox/disco.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/disco.h b/libs/libgloox/disco.h index fa180a6..9eee26b 100644 --- a/libs/libgloox/disco.h +++ b/libs/libgloox/disco.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -34,13 +34,13 @@ namespace gloox class IQ; /** - * @brief This class implements XEP-0030 (Service Discovery) and XEP-0092 (Software Version). + * @brief This class implements @xep{0030} (Service Discovery) and @xep{0092} (Software Version). * * ClientBase will automatically instantiate a Disco object. It can be used to * announce special features of your client, or its version, or... * * XEP version: 2.2 - * @author Jakob Schroeter + * @author Jakob Schröter */ class GLOOX_API Disco : public IqHandler { @@ -56,10 +56,10 @@ namespace gloox typedef std::list IdentityList; /** - * @brief An abstraction of a Disco Info element (from Service Discovery, XEP-0030) + * @brief An abstraction of a Disco Info element (from Service Discovery, @xep{0030}) * as a StanzaExtension. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API Info : public StanzaExtension @@ -93,13 +93,13 @@ namespace gloox const IdentityList& identities() const { return m_identities; } /** - * Returns an optionally included data form. This is used by e.g. MUC (XEP-0045). + * Returns an optionally included data form. This is used by e.g. MUC (@xep{0045}). * @return An optional data form included in the disco#info. May be 0. */ const DataForm* form() const { return m_form; } /** - * Adds an optional DataForm, e.g. for XEP-0232. Only one form can be added + * Adds an optional DataForm, e.g. for @xep{0232}. Only one form can be added * at this point. * @param form An optional DataForm to include in the Info reply. * The form will be owned by and deleted on destruction of the Info object. @@ -188,9 +188,9 @@ namespace gloox }; /** - * @brief An abstraction of a Disco identity (Service Discovery, XEP-0030). + * @brief An abstraction of a Disco identity (Service Discovery, @xep{0030}). * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API Identity @@ -266,10 +266,10 @@ namespace gloox typedef std::list ItemList; /** - * @brief An abstraction of a Disco query element (from Service Discovery, XEP-0030) + * @brief An abstraction of a Disco query element (from Service Discovery, @xep{0030}) * in the disco#items namespace, implemented as a StanzaExtension. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API Items : public StanzaExtension @@ -278,7 +278,7 @@ namespace gloox public: // This needs to be public so one can proactively send a list of adhoc commands - // see XEP-0050 + // see @xep{0050} /** * Creates an empty Items object, suitable for making disco#items requests. * @param node The node identifier to query (optional). @@ -344,9 +344,9 @@ namespace gloox }; /** - * @brief An abstraction of a Disco item (Service Discovery, XEP-0030). + * @brief An abstraction of a Disco item (Service Discovery, @xep{0030}). * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API Item @@ -439,7 +439,7 @@ namespace gloox /** * Queries the given JID for general infomation according to - * XEP-0030 (Service Discovery). + * @xep{0030} (Service Discovery). * To receive the results inherit from DiscoHandler and register with the Disco object. * @param to The destination-JID of the query. * @param node An optional node to query. Not inserted if empty. @@ -454,7 +454,7 @@ namespace gloox /** * Queries the given JID for its items according to - * XEP-0030 (Service Discovery). + * @xep{0030} (Service Discovery). * To receive the results inherit from DiscoHandler and register with the Disco object. * @param to The destination-JID of the query. * @param node An optional node to query. Not inserted if empty. @@ -471,8 +471,8 @@ namespace gloox * Sets the version of the host application using this library. * The library takes care of jabber:iq:version requests. These * IQ packets will not be forwarded to the IqHandlers. - * @param name The name to be returned to inquireing clients. - * @param version The version to be returned to inquireing clients. + * @param name The name to be returned to inquiring clients. + * @param version The version to be returned to inquiring clients. * @param os The operating system to announce. Default: don't include. */ void setVersion( const std::string& name, const std::string& version, @@ -500,10 +500,10 @@ namespace gloox * Sets the identity of this entity. * The library uses this information to answer disco#info requests * with a correct identity. - * XEP-0030 requires an entity to have at least one identity. See XEP-0030 + * @xep{0030} requires an entity to have at least one identity. See @xep{0030} * for more information on categories and types. - * @param category The entity category of this client. Default: client. - * @param type The type of this entity. Default: bot. + * @param category The entity category of this client. Default: client. May not be empty. + * @param type The type of this entity. Default: bot. May not be empty. * @param name The name of the entity. Default: empty. * @note An entity can have more than one identity. You cann add more identities * using addIdentity(). A call to setIdentity() will clear the list of identities @@ -514,8 +514,8 @@ namespace gloox /** * Adds another identity to the list of identities. - * @param category The entity category of this client. Default: client. - * @param type The type of this entity. Default: bot. + * @param category The entity category of this client. Default: client. May not be empty. + * @param type The type of this entity. Default: bot. May not be empty. * @param name The name of the entity. Default: empty. */ void addIdentity( const std::string& category, const std::string& type, @@ -529,7 +529,7 @@ namespace gloox const IdentityList& identities() const { return m_identities; } /** - * Adds an optional DataForm to Disco:Info replies, e.g. for XEP-0232. + * Adds an optional DataForm to Disco:Info replies, e.g. for @xep{0232}. * Only one form can be added at this point. * @param form An optional DataForm to include in the Info reply. * The form will be owned by and deleted on destruction of the Disco object. diff --git a/libs/libgloox/discohandler.h b/libs/libgloox/discohandler.h index 1a0941d..ca69430 100644 --- a/libs/libgloox/discohandler.h +++ b/libs/libgloox/discohandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -25,11 +25,11 @@ namespace gloox class IQ; /** - * @brief A virtual interface that enables objects to receive Service Discovery (XEP-0030) events. + * @brief A virtual interface that enables objects to receive Service Discovery (@xep{0030}) events. * * A class implementing this interface can receive the results of sent disco queries. * - * @author Jakob Schroeter + * @author Jakob Schröter */ class GLOOX_API DiscoHandler { diff --git a/libs/libgloox/disconodehandler.h b/libs/libgloox/disconodehandler.h index 8cdde36..db4f58f 100644 --- a/libs/libgloox/disconodehandler.h +++ b/libs/libgloox/disconodehandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -30,7 +30,7 @@ namespace gloox * * Incoming disco#info and disco#items queries are delegated to their respective handlers. * - * @author Jakob Schroeter + * @author Jakob Schröter */ class GLOOX_API DiscoNodeHandler { diff --git a/libs/libgloox/dns.cpp b/libs/libgloox/dns.cpp index 0ddc081..3513524 100644 --- a/libs/libgloox/dns.cpp +++ b/libs/libgloox/dns.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -22,7 +22,6 @@ #endif #include -#include #if ( !defined( _WIN32 ) && !defined( _WIN32_WCE ) ) || defined( __SYMBIAN32__ ) # include @@ -99,7 +98,7 @@ namespace gloox HEADER* hdr = (HEADER*)srvbuf.buf; unsigned char* here = srvbuf.buf + NS_HFIXEDSZ; - if( ( hdr->tc ) || ( srvbuf.len < NS_HFIXEDSZ ) ) + if( srvbuf.len < NS_HFIXEDSZ ) error = true; if( hdr->rcode >= 1 && hdr->rcode <= 5 ) @@ -157,7 +156,7 @@ namespace gloox return servers; } -#elif defined( _WIN32 ) && defined( HAVE_WINDNS_H ) +#elif defined( _WIN32 ) && defined( HAVE_WINDNS_H ) && !defined( __MINGW32__ ) DNS::HostMap DNS::resolve( const std::string& service, const std::string& proto, const std::string& domain, const LogSink& logInstance ) { @@ -169,7 +168,10 @@ namespace gloox DNS_STATUS status = DnsQuery_UTF8( dname.c_str(), DNS_TYPE_SRV, DNS_QUERY_STANDARD, NULL, &pRecord, NULL ); if( status == ERROR_SUCCESS ) { - DNS_RECORD* pRec = pRecord; + // NOTE: DnsQuery_UTF8 and DnsQuery_A really should have been defined with + // PDNS_RECORDA instead of PDNS_RECORD, since that's what it is (even with _UNICODE defined). + // We'll correct for that mistake with a cast. + DNS_RECORDA* pRec = (DNS_RECORDA*)pRecord; do { if( pRec->wType == DNS_TYPE_SRV ) @@ -290,10 +292,9 @@ namespace gloox } if( res->ai_canonname ) - logInstance.dbg( LogAreaClassDns, "Connecting to " + std::string( res->ai_canonname ) - + " (" + ip + "), port " + port ); + logInstance.dbg( LogAreaClassDns, std::string( "Connecting to " ).append( res->ai_canonname ).append( " (" ).append( ip ).append( "), port " ).append( port ) ); else - logInstance.dbg( LogAreaClassDns, "Connecting to " + ip + ":" + port ); + logInstance.dbg( LogAreaClassDns, std::string( "Connecting to " ).append( ip ).append( ":" ).append( port ) ); return fd; } @@ -302,7 +303,7 @@ namespace gloox #if defined( _WIN32 ) && !defined( __SYMBIAN32__ ) "WSAGetLastError: " + util::int2string( ::WSAGetLastError() ); #else - "errno: " + util::int2string( errno ); + "errno: " + util::int2string( errno ) + ": " + strerror( errno ); #endif logInstance.dbg( LogAreaClassDns, message ); @@ -343,6 +344,7 @@ namespace gloox #endif int protocol = IPPROTO_TCP; +#if !defined( __APPLE__ ) // Sandboxing on Apple doesn't like you to use getprotobyname struct protoent* prot; if( ( prot = getprotobyname( "tcp" ) ) != 0 ) { @@ -354,13 +356,14 @@ namespace gloox #if defined( _WIN32 ) && !defined( __SYMBIAN32__ ) "WSAGetLastError: " + util::int2string( ::WSAGetLastError() ) #else - "errno: " + util::int2string( errno ); + "errno: " + util::int2string( errno ) + ": " + strerror( errno ); #endif + ". Falling back to IPPROTO_TCP: " + util::int2string( IPPROTO_TCP ); logInstance.dbg( LogAreaClassDns, message ); // Do not return an error. We'll fall back to IPPROTO_TCP. } +#endif // !defined( __APPLE__ ) return getSocket( PF_INET, SOCK_STREAM, protocol, logInstance ); } @@ -382,7 +385,7 @@ namespace gloox #if defined( _WIN32 ) && !defined( __SYMBIAN32__ ) "WSAGetLastError: " + util::int2string( ::WSAGetLastError() ); #else - "errno: " + util::int2string( errno ); + "errno: " + util::int2string( errno ) + ": " + strerror( errno ); #endif logInstance.dbg( LogAreaClassDns, message ); @@ -392,8 +395,9 @@ namespace gloox #ifdef HAVE_SETSOCKOPT int timeout = 5000; + int reuseaddr = 1; setsockopt( fd, SOL_SOCKET, SO_SNDTIMEO, (char*)&timeout, sizeof( timeout ) ); - setsockopt( fd, SOL_SOCKET, SO_REUSEADDR, (char*)&timeout, sizeof( timeout ) ); + setsockopt( fd, SOL_SOCKET, SO_REUSEADDR, (char*)&reuseaddr, sizeof( reuseaddr ) ); #endif return (int)fd; @@ -410,6 +414,7 @@ namespace gloox { logInstance.dbg( LogAreaClassDns, "gethostbyname() failed for " + host + "." ); cleanup( logInstance ); + closeSocket( fd, logInstance ); return -ConnDnsError; } @@ -421,6 +426,7 @@ namespace gloox { logInstance.dbg( LogAreaClassDns, "gethostbyname() returned unexpected structure." ); cleanup( logInstance ); + closeSocket( fd, logInstance ); return -ConnDnsError; } else @@ -444,7 +450,7 @@ namespace gloox #if defined( _WIN32 ) && !defined( __SYMBIAN32__ ) "WSAGetLastError: " + util::int2string( ::WSAGetLastError() ); #else - "errno: " + util::int2string( errno ); + "errno: " + util::int2string( errno ) + ": " + strerror( errno ); #endif logInstance.dbg( LogAreaClassDns, message ); @@ -466,7 +472,7 @@ namespace gloox #if defined( _WIN32 ) && !defined( __SYMBIAN32__ ) "WSAGetLastError: " + util::int2string( ::WSAGetLastError() ); #else - "errno: " + util::int2string( errno ); + "errno: " + util::int2string( errno ) + ": " + strerror( errno ); #endif logInstance.dbg( LogAreaClassDns, message ); } diff --git a/libs/libgloox/dns.h b/libs/libgloox/dns.h index 5be2a6f..37ac547 100644 --- a/libs/libgloox/dns.h +++ b/libs/libgloox/dns.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -55,7 +55,7 @@ namespace gloox * * You should not need to use these functions directly. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.3 */ class GLOOX_API DNS diff --git a/libs/libgloox/error.cpp b/libs/libgloox/error.cpp index d0c23cf..8a80f3a 100644 --- a/libs/libgloox/error.cpp +++ b/libs/libgloox/error.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/error.h b/libs/libgloox/error.h index 24eccce..2541fcb 100644 --- a/libs/libgloox/error.h +++ b/libs/libgloox/error.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -28,7 +28,7 @@ namespace gloox * @brief A stanza error abstraction implemented as a StanzaExtension. * * @author Vincent Thomasset - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API Error : public StanzaExtension diff --git a/libs/libgloox/event.h b/libs/libgloox/event.h index 3a2e3f2..d96e916 100644 --- a/libs/libgloox/event.h +++ b/libs/libgloox/event.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2008-2009 by Jakob Schroeter + Copyright (c) 2008-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -22,7 +22,7 @@ namespace gloox /** * @brief A base class for events. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class Event @@ -34,9 +34,9 @@ namespace gloox */ enum EventType { - PingPing, /**< Incoming Ping (XEP-0199). */ - PingPong, /**< Incoming Pong (XEP-0199). */ - PingError /**< Incoming Error Pong (XEP-0199). */ + PingPing, /**< Incoming Ping (@xep{0199}). */ + PingPong, /**< Incoming Pong (@xep{0199}). */ + PingError /**< Incoming Error Pong (@xep{0199}). */ }; /** diff --git a/libs/libgloox/eventdispatcher.cpp b/libs/libgloox/eventdispatcher.cpp index 7db22a9..c2cec64 100644 --- a/libs/libgloox/eventdispatcher.cpp +++ b/libs/libgloox/eventdispatcher.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2008-2009 by Jakob Schroeter + Copyright (c) 2008-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/eventdispatcher.h b/libs/libgloox/eventdispatcher.h index 5c530fc..12a1ca8 100644 --- a/libs/libgloox/eventdispatcher.h +++ b/libs/libgloox/eventdispatcher.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2008-2009 by Jakob Schroeter + Copyright (c) 2008-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -27,7 +27,7 @@ namespace gloox /** * @brief An Event dispatcher. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class EventDispatcher diff --git a/libs/libgloox/eventhandler.h b/libs/libgloox/eventhandler.h index d841cd0..ebdafa9 100644 --- a/libs/libgloox/eventhandler.h +++ b/libs/libgloox/eventhandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2008-2009 by Jakob Schroeter + Copyright (c) 2008-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -22,7 +22,7 @@ namespace gloox /** * @brief An base class for event handlers. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class EventHandler diff --git a/libs/libgloox/featureneg.cpp b/libs/libgloox/featureneg.cpp index 628dd97..2e6b303 100644 --- a/libs/libgloox/featureneg.cpp +++ b/libs/libgloox/featureneg.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/featureneg.h b/libs/libgloox/featureneg.h index 5dca1a5..9f8f255 100644 --- a/libs/libgloox/featureneg.h +++ b/libs/libgloox/featureneg.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -25,11 +25,11 @@ namespace gloox class Tag; /** - * @brief An abstraction of Feature Negotiation (XEP-0020), implemented + * @brief An abstraction of Feature Negotiation (@xep{0020}), implemented * as a StanzaExtension. * * XEP Version: 1.5 - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API FeatureNeg : public StanzaExtension diff --git a/libs/libgloox/flexoff.cpp b/libs/libgloox/flexoff.cpp index 9716718..2976137 100644 --- a/libs/libgloox/flexoff.cpp +++ b/libs/libgloox/flexoff.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/flexoff.h b/libs/libgloox/flexoff.h index 92db971..3863f99 100644 --- a/libs/libgloox/flexoff.h +++ b/libs/libgloox/flexoff.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -24,11 +24,11 @@ namespace gloox { /** - * @brief An implementation of XEP-0013 (Flexible Offline Message Retrieval). + * @brief An implementation of @xep{0013} (Flexible Offline Message Retrieval). * * Use the FlexibleOfflineHandler to receive results. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.7 */ class GLOOX_API FlexibleOffline : public DiscoHandler, public IqHandler @@ -84,7 +84,7 @@ namespace gloox { messageOperation( FORemoveMsgs, msgs ); } /** - * Registers a FlexibleOfflineHandler as object that receives results of XEP-0013 queries. + * Registers a FlexibleOfflineHandler as object that receives results of @xep{0013} queries. * Only one Handler at a time is possible. * @param foh The Handler object to register. */ diff --git a/libs/libgloox/flexoffhandler.h b/libs/libgloox/flexoffhandler.h index 803654d..b9bf89f 100644 --- a/libs/libgloox/flexoffhandler.h +++ b/libs/libgloox/flexoffhandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -30,14 +30,14 @@ namespace gloox FomrForbidden, /**< The requester is a JID other than an authorized resource of the * user. Something wnet serieously wrong */ FomrItemNotFound, /**< The requested node (message ID) does not exist. */ - FomrUnknownError /**< An error occurred which is not specified in XEP-0013. */ + FomrUnknownError /**< An error occurred which is not specified in @xep{0013}. */ }; /** * @brief Implementation of this virtual interface allows for retrieval of offline messages following - * XEP-0030. + * @xep{0030}. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.7 */ class GLOOX_API FlexibleOfflineHandler @@ -49,9 +49,9 @@ namespace gloox virtual ~FlexibleOfflineHandler() {} /** - * This function is called to indicate whether the server supports XEP-0013 or not. + * This function is called to indicate whether the server supports @xep{0013} or not. * Call @ref FlexibleOffline::checkSupport() to trigger the check. - * @param support Whether the server support XEP-0013 or not. + * @param support Whether the server support @xep{0013} or not. */ virtual void handleFlexibleOfflineSupport( bool support ) = 0; diff --git a/libs/libgloox/gloox.cpp b/libs/libgloox/gloox.cpp index eb3eaa6..3d4e08d 100644 --- a/libs/libgloox/gloox.cpp +++ b/libs/libgloox/gloox.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -25,50 +25,50 @@ namespace gloox const std::string XMLNS_DISCO_PUBLISH = "http://jabber.org/protocol/disco#publish"; const std::string XMLNS_ADHOC_COMMANDS = "http://jabber.org/protocol/commands"; const std::string XMLNS_COMPRESSION = "http://jabber.org/protocol/compress"; - const std::string XMLNS_OFFLINE = "http://jabber.org/protocol/offline"; + const std::string XMLNS_OFFLINE = "http://jabber.org/protocol/offline"; const std::string XMLNS_CHAT_STATES = "http://jabber.org/protocol/chatstates"; const std::string XMLNS_AMP = "http://jabber.org/protocol/amp"; const std::string XMLNS_IBB = "http://jabber.org/protocol/ibb"; const std::string XMLNS_FEATURE_NEG = "http://jabber.org/protocol/feature-neg"; - const std::string XMLNS_CHATNEG = "http://jabber.org/protocol/chatneg"; + const std::string XMLNS_CHATNEG = "http://jabber.org/protocol/chatneg"; const std::string XMLNS_XHTML_IM = "http://jabber.org/protocol/xhtml-im"; const std::string XMLNS_DELAY = "urn:xmpp:delay"; const std::string XMLNS_ROSTER = "jabber:iq:roster"; const std::string XMLNS_VERSION = "jabber:iq:version"; - const std::string XMLNS_REGISTER = "jabber:iq:register"; + const std::string XMLNS_REGISTER = "jabber:iq:register"; const std::string XMLNS_PRIVACY = "jabber:iq:privacy"; const std::string XMLNS_AUTH = "jabber:iq:auth"; const std::string XMLNS_PRIVATE_XML = "jabber:iq:private"; const std::string XMLNS_LAST = "jabber:iq:last"; - const std::string XMLNS_SEARCH = "jabber:iq:search"; + const std::string XMLNS_SEARCH = "jabber:iq:search"; const std::string XMLNS_IQ_OOB = "jabber:iq:oob"; const std::string XMLNS_X_DATA = "jabber:x:data"; const std::string XMLNS_X_EVENT = "jabber:x:event"; const std::string XMLNS_X_OOB = "jabber:x:oob"; - const std::string XMLNS_X_DELAY = "jabber:x:delay"; + const std::string XMLNS_X_DELAY = "jabber:x:delay"; const std::string XMLNS_X_GPGSIGNED = "jabber:x:signed"; const std::string XMLNS_X_GPGENCRYPTED = "jabber:x:encrypted"; const std::string XMLNS_VCARD_TEMP = "vcard-temp"; const std::string XMLNS_X_VCARD_UPDATE = "vcard-temp:x:update"; - const std::string XMLNS_BOOKMARKS = "storage:bookmarks"; + const std::string XMLNS_BOOKMARKS = "storage:bookmarks"; const std::string XMLNS_ANNOTATIONS = "storage:rosternotes"; const std::string XMLNS_ROSTER_DELIMITER = "roster:delimiter"; const std::string XMLNS_XMPP_PING = "urn:xmpp:ping"; const std::string XMLNS_SI = "http://jabber.org/protocol/si"; - const std::string XMLNS_SI_FT = "http://jabber.org/protocol/si/profile/file-transfer"; + const std::string XMLNS_SI_FT = "http://jabber.org/protocol/si/profile/file-transfer"; const std::string XMLNS_BYTESTREAMS = "http://jabber.org/protocol/bytestreams"; const std::string XMLNS_MUC = "http://jabber.org/protocol/muc"; const std::string XMLNS_MUC_USER = "http://jabber.org/protocol/muc#user"; const std::string XMLNS_MUC_ADMIN = "http://jabber.org/protocol/muc#admin"; - const std::string XMLNS_MUC_UNIQUE = "http://jabber.org/protocol/muc#unique"; + const std::string XMLNS_MUC_UNIQUE = "http://jabber.org/protocol/muc#unique"; const std::string XMLNS_MUC_OWNER = "http://jabber.org/protocol/muc#owner"; const std::string XMLNS_MUC_ROOMINFO = "http://jabber.org/protocol/muc#roominfo"; const std::string XMLNS_MUC_ROOMS = "http://jabber.org/protocol/muc#rooms"; @@ -78,39 +78,44 @@ namespace gloox const std::string XMLNS_PUBSUB_ERRORS = "http://jabber.org/protocol/pubsub#errors"; const std::string XMLNS_PUBSUB_EVENT = "http://jabber.org/protocol/pubsub#event"; const std::string XMLNS_PUBSUB_OWNER = "http://jabber.org/protocol/pubsub#owner"; - const std::string XMLNS_CAPS = "http://jabber.org/protocol/caps"; - const std::string XMLNS_FT_FASTMODE = "http://affinix.com/jabber/stream"; + const std::string XMLNS_FT_FASTMODE = "http://affinix.com/jabber/stream"; const std::string XMLNS_STREAM = "http://etherx.jabber.org/streams"; const std::string XMLNS_XMPP_STREAM = "urn:ietf:params:xml:ns:xmpp-streams"; const std::string XMLNS_XMPP_STANZAS = "urn:ietf:params:xml:ns:xmpp-stanzas"; const std::string XMLNS_STREAM_TLS = "urn:ietf:params:xml:ns:xmpp-tls"; - const std::string XMLNS_STREAM_SASL = "urn:ietf:params:xml:ns:xmpp-sasl"; + const std::string XMLNS_STREAM_SASL = "urn:ietf:params:xml:ns:xmpp-sasl"; const std::string XMLNS_STREAM_BIND = "urn:ietf:params:xml:ns:xmpp-bind"; const std::string XMLNS_STREAM_SESSION = "urn:ietf:params:xml:ns:xmpp-session"; const std::string XMLNS_STREAM_IQAUTH = "http://jabber.org/features/iq-auth"; const std::string XMLNS_STREAM_IQREGISTER = "http://jabber.org/features/iq-register"; - const std::string XMLNS_STREAM_COMPRESS = "http://jabber.org/features/compress"; + const std::string XMLNS_STREAM_COMPRESS = "http://jabber.org/features/compress"; const std::string XMLNS_HTTPBIND = "http://jabber.org/protocol/httpbind"; const std::string XMLNS_XMPP_BOSH = "urn:xmpp:xbosh"; const std::string XMLNS_RECEIPTS = "urn:xmpp:receipts"; const std::string XMLNS_NICKNAME = "http://jabber.org/protocol/nick"; - const std::string XMLNS_JINGLE = "urn:xmpp:tmp:jingle"; - const std::string XMLNS_JINGLE_AUDIO_RTP = "urn:xmpp:tmp:jingle:apps:audio-rtp"; - const std::string XMLNS_JINGLE_ICE_UDP = "urn:xmpp:tmp:jingle:transports:ice-udp"; - const std::string XMLNS_JINGLE_RAW_UDP = "urn:xmpp:tmp:jingle:transports:raw-udp"; - const std::string XMLNS_JINGLE_VIDEO_RTP = "urn:xmpp:tmp:jingle:apps:video-rtp"; + const std::string XMLNS_JINGLE = "urn:xmpp:jingle:1"; + const std::string XMLNS_JINGLE_ERRORS = "urn:xmpp:jingle:errors:1"; + const std::string XMLNS_JINGLE_ICE_UDP = "urn:xmpp:jingle:transports:ice-udp:1"; + const std::string XMLNS_JINGLE_FILE_TRANSFER = "urn:xmpp:jingle:apps:file-transfer:3"; + const std::string XMLNS_JINGLE_FILE_TRANSFER_MULTI = "urn:xmpp:jingle:apps:file-transfer:multi"; const std::string XMLNS_SHIM = "http://jabber.org/protocol/shim"; const std::string XMLNS_ATTENTION = "urn:xmpp:attention:0"; + const std::string XMLNS_STREAM_MANAGEMENT = "urn:xmpp:sm:3"; + const std::string XMLNS_STANZA_FORWARDING = "urn:xmpp:forward:0"; + const std::string XMLNS_MESSAGE_CARBONS = "urn:xmpp:carbons:2"; + + const std::string XMLNS_HASHES = "urn:xmpp:hashes:1"; + const std::string XMLNS_IODATA = "urn:xmpp:tmp:io-data"; const std::string XMPP_STREAM_VERSION_MAJOR = "1"; const std::string XMPP_STREAM_VERSION_MINOR = "0"; - const std::string GLOOX_VERSION = "1.0"; + const std::string GLOOX_VERSION = "1.0.13"; const std::string GLOOX_CAPS_NODE = "http://camaya.net/gloox"; const std::string XMLNS = "xmlns"; diff --git a/libs/libgloox/gloox.h b/libs/libgloox/gloox.h index 8186d20..6702d3e 100644 --- a/libs/libgloox/gloox.h +++ b/libs/libgloox/gloox.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -115,7 +115,7 @@ * * A component in the Jabber/XMPP network is an add-on to a server which runs externally * to the actual server software, but can have similar privileges. Components use a protocol described in - * XEP-0114 to connect and authenticate to a server. + * @xep{0114} to connect and authenticate to a server. * * The @link gloox::Component Component @endlink class supports this protocol and can be used to create * a new Jabber component. It's as simple as: @@ -262,7 +262,7 @@ * * @section auth_sec Authentication * - * gloox supports old-style IQ-based authentication defined in XEP-0078 as well as several SASL mechanisms. + * gloox supports old-style IQ-based authentication defined in @xep{0078} as well as several SASL mechanisms. * See the documentation of the @link gloox::Client Client @endlink class for more information. * * @section msg_sec Sending and Receiving of Chat Messages @@ -276,58 +276,65 @@ * The XMPP Standards Foundation has published a number of extensions to the core protocols, called * XMPP Extension Protocols (XEPs). A couple of these XEPs are implemented in gloox: * - * @li XEP-0004 @link gloox::DataForm Data Forms @endlink - * @li XEP-0012 @link gloox::LastActivity Last Activity @endlink - * @li XEP-0013 @link gloox::FlexibleOffline Flexible Offline Message Retrieval @endlink - * @li XEP-0022 Message Events (see @link gloox::MessageSession MessageSession @endlink for examples) - * @li XEP-0027 Current Jabber OpenPGP Usage (see @link gloox::GPGSigned GPGSigned @endlink + * @li @xep{0004} @link gloox::DataForm Data Forms @endlink + * @li @xep{0012} @link gloox::LastActivity Last Activity @endlink + * @li @xep{0013} @link gloox::FlexibleOffline Flexible Offline Message Retrieval @endlink + * @li @xep{0022} Message Events (see @link gloox::MessageSession MessageSession @endlink for examples) + * @li @xep{0027} Current Jabber OpenPGP Usage (see @link gloox::GPGSigned GPGSigned @endlink * and @link gloox::GPGEncrypted GPGEncrypted @endlink) - * @li XEP-0030 @link gloox::Disco Service Discovery @endlink - * @li XEP-0045 @link gloox::MUCRoom Multi-User Chat @endlink - * @li XEP-0047 Used with @ref filetransfer_sec - * @li XEP-0048 @link gloox::BookmarkStorage Bookmark Storage @endlink - * @li XEP-0049 @link gloox::PrivateXML Private XML Storage @endlink - * @li XEP-0050 @link gloox::Adhoc Ad-hoc Commands @endlink - * @li XEP-0054 @link gloox::VCardManager vcard-temp @endlink - * @li XEP-0060 @link gloox::PubSub::Manager Publish-Subscribe @endlink - * @li XEP-0065 @link gloox::SOCKS5BytestreamManager SOCKS5 Bytestreams @endlink, used with + * @li @xep{0030} @link gloox::Disco Service Discovery @endlink + * @li @xep{0045} @link gloox::MUCRoom Multi-User Chat @endlink + * @li @xep{0047} Used with @ref filetransfer_sec + * @li @xep{0048} @link gloox::BookmarkStorage Bookmark Storage @endlink + * @li @xep{0049} @link gloox::PrivateXML Private XML Storage @endlink + * @li @xep{0050} @link gloox::Adhoc Ad-hoc Commands @endlink + * @li @xep{0054} @link gloox::VCardManager vcard-temp @endlink + * @li @xep{0060} @link gloox::PubSub::Manager Publish-Subscribe @endlink + * @li @xep{0065} @link gloox::SOCKS5BytestreamManager SOCKS5 Bytestreams @endlink, used with * @ref filetransfer_sec and @ref proxy_sec - * @li XEP-0066 @link gloox::OOB Out of Band Data @endlink, also used with @ref filetransfer_sec - * @li XEP-0077 @link gloox::Registration In-Band Registration @endlink - * @li XEP-0078 Non-SASL Authentication (automatically used if the server does not support SASL) - * @li XEP-0079 @link gloox::AMP Advanced Message Processing @endlink - * @li XEP-0083 Nested Roster Groups (automatically used if supported by the server. see + * @li @xep{0066} @link gloox::OOB Out of Band Data @endlink, also used with @ref filetransfer_sec + * @li @xep{0077} @link gloox::Registration In-Band Registration @endlink + * @li @xep{0078} Non-SASL Authentication (automatically used if the server does not support SASL) + * @li @xep{0079} @link gloox::AMP Advanced Message Processing @endlink + * @li @xep{0083} Nested Roster Groups (automatically used if supported by the server. see * @link gloox::RosterManager::delimiter() RosterManager @endlink) - * @li XEP-0085 Chat State Notifications (see @link gloox::MessageSession MessageSession @endlink for + * @li @xep{0085} Chat State Notifications (see @link gloox::MessageSession MessageSession @endlink for * examples) - * @li XEP-0091 @link gloox::DelayedDelivery Delayed Delivery @endlink (old spec) - * @li XEP-0092 Software Version (integrated into @link gloox::Disco Service Discovery @endlink) - * @li XEP-0095 @link gloox::SIManager Stream Initiation @endlink, used with @ref filetransfer_sec - * @li XEP-0096 @ref filetransfer_sec - * @li XEP-0106 @link gloox::JID::escapeNode() JID Escaping @endlink - * @li XEP-0114 @link gloox::Component Jabber Component Protocol @endlink - * @li XEP-0115 @link gloox::Capabilities Entity Capabilities @endlink (used automatically internally) - * @li XEP-0124 @link gloox::ConnectionBOSH Bidirectional-streams Over Synchronous HTTP (BOSH) @endlink - * @li XEP-0131 @link gloox::SHIM Stanza Headers and Internet Metadata @endlink - * @li XEP-0138 Stream Compression (used automatically if gloox is compiled with zlib and if the server + * @li @xep{0091} @link gloox::DelayedDelivery Delayed Delivery @endlink (old spec) + * @li @xep{0092} Software Version (integrated into @link gloox::Disco Service Discovery @endlink) + * @li @xep{0095} @link gloox::SIManager Stream Initiation @endlink, used with @ref filetransfer_sec + * @li @xep{0096} @ref filetransfer_sec + * @li @xep{0106} @link gloox::JID::escapeNode() JID Escaping @endlink + * @li @xep{0114} @link gloox::Component Jabber Component Protocol @endlink + * @li @xep{0115} @link gloox::Capabilities Entity Capabilities @endlink (used automatically internally) + * @li @xep{0124} @link gloox::ConnectionBOSH Bidirectional-streams Over Synchronous HTTP (BOSH) @endlink + * @li @xep{0131} @link gloox::SHIM Stanza Headers and Internet Metadata @endlink + * @li @xep{0138} Stream Compression (used automatically if gloox is compiled with zlib and if the server * supports it) - * @li XEP-0145 @link gloox::Annotations Annotations @endlink - * @li XEP-0153 @link gloox::VCardUpdate vCard-based Avatars @endlink - * @li XEP-0172 @link gloox::Nickname User Nickname @endlink - * @li XEP-0184 @link gloox::Receipt Message Receipts @endlink - * @li XEP-0199 @link gloox::ClientBase::xmppPing() XMPP Ping @endlink - * @li XEP-0203 @link gloox::DelayedDelivery Delayed Delivery @endlink (new spec) - * @li XEP-0206 @link gloox::ConnectionBOSH see BOSH @endlink - * @li XEP-0224 @link gloox::Attention Attention @endlink - * @li XEP-0256 @link gloox::LastActivity::Query Last Activity in Presence @endlink + * @li @xep{0145} @link gloox::Annotations Annotations @endlink + * @li @xep{0153} @link gloox::VCardUpdate vCard-based Avatars @endlink + * @li @xep{0166} @link gloox::Jingle::SessionManager Jingle @endlink + * @li @xep{0172} @link gloox::Nickname User Nickname @endlink + * @li @xep{0174} @link gloox::LinkLocal::Manager Link-local Messaging @endlink + * @li @xep{0176} @link gloox::Jingle::ICEUDP Jingle ICE-UDP Transport Method @endlink + * @li @xep{0184} @link gloox::Receipt Message Receipts @endlink + * @li @xep{0198} Stream Management (integrated into @link gloox::Client @endlink) + * @li @xep{0199} @link gloox::ClientBase::xmppPing() XMPP Ping @endlink + * @li @xep{0203} @link gloox::DelayedDelivery Delayed Delivery @endlink (new spec) + * @li @xep{0206} @link gloox::ConnectionBOSH see BOSH @endlink + * @li @xep{0224} @link gloox::Attention Attention @endlink + * @li @xep{0234} @link gloox::Jingle::FileTransfer Jingle File Transfer @endlink + * @li @xep{0256} @link gloox::LastActivity::Query Last Activity in Presence @endlink + * @li @xep{0280} @link gloox::Carbons Message Carbons @endlink + * @li @xep{0297} @link gloox::Forward Stanza Forwarding @endlink * * Further extensions can easily be implemented using * @link gloox::StanzaExtension StanzaExtensions @endlink. * * @section filetransfer_sec File Transfer * - * For file transfer, gloox implements XEP-0095 (Stream Initiation) as well XEP-0096 (File Transfer) - * for the signalling, and XEP-0065 (SOCKS5 Bytestreams) as well as XEP-0047 (In-Band Bytestreams) + * For file transfer, gloox implements @xep{0095} (Stream Initiation) as well @xep{0096} (File Transfer) + * for the signalling, and @xep{0065} (SOCKS5 Bytestreams) as well as @xep{0047} (In-Band Bytestreams) * for the transport. See @link gloox::SIProfileFT SIProfileFT @endlink. * * @section proxy_sec HTTP and SOCKS5 Proxy support @@ -354,7 +361,7 @@ /** * @brief The namespace for the gloox library. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.3 */ namespace gloox @@ -362,160 +369,160 @@ namespace gloox /** Client namespace (RFC 3920)*/ GLOOX_API extern const std::string XMLNS_CLIENT; - /** Component Accept namespace (XEP-0114) */ + /** Component Accept namespace (@xep{0114}) */ GLOOX_API extern const std::string XMLNS_COMPONENT_ACCEPT; - /** Component Connect namespace (XEP-0114) */ + /** Component Connect namespace (@xep{0114}) */ GLOOX_API extern const std::string XMLNS_COMPONENT_CONNECT; - /** Service Discovery Info namespace (XEP-0030) */ + /** Service Discovery Info namespace (@xep{0030}) */ GLOOX_API extern const std::string XMLNS_DISCO_INFO; - /** Service Discovery Items namespace (XEP-0030) */ + /** Service Discovery Items namespace (@xep{0030}) */ GLOOX_API extern const std::string XMLNS_DISCO_ITEMS; - /** Service Discovery Publish namespace (XEP-0030) */ + /** Service Discovery Publish namespace (@xep{0030}) */ GLOOX_API extern const std::string XMLNS_DISCO_PUBLISH; - /** Adhoc Commands namespace (XEP-0050) */ + /** Adhoc Commands namespace (@xep{0050}) */ GLOOX_API extern const std::string XMLNS_ADHOC_COMMANDS; - /** Stream Compression namespace (XEP-0138) */ + /** Stream Compression namespace (@xep{0138}) */ GLOOX_API extern const std::string XMLNS_COMPRESSION; - /** Flexible Offline Message Retrieval (XEP-0013) */ + /** Flexible Offline Message Retrieval (@xep{0013}) */ GLOOX_API extern const std::string XMLNS_OFFLINE; - /** Chat State Notifications namespace (XEP-0085) */ + /** Chat State Notifications namespace (@xep{0085}) */ GLOOX_API extern const std::string XMLNS_CHAT_STATES; - /** Advanced Message Processing (XEP-0079) */ + /** Advanced Message Processing (@xep{0079}) */ GLOOX_API extern const std::string XMLNS_AMP; - /** In-Band Bytestreams namespace (XEP-0047) */ + /** In-Band Bytestreams namespace (@xep{0047}) */ GLOOX_API extern const std::string XMLNS_IBB; - /** Feature Negotiation namespace (XEP-0020) */ + /** Feature Negotiation namespace (@xep{0020}) */ GLOOX_API extern const std::string XMLNS_FEATURE_NEG; - /** Chat Session Negotiation namespace (XEP-0155) */ + /** Chat Session Negotiation namespace (@xep{0155}) */ GLOOX_API extern const std::string XMLNS_CHATNEG; - /** XHTML-IM namespace (XEP-0071) */ + /** XHTML-IM namespace (@xep{0071}) */ GLOOX_API extern const std::string XMLNS_XHTML_IM; - /** Delayed Delivery namespace (XEP-0203) */ + /** Delayed Delivery namespace (@xep{0203}) */ GLOOX_API extern const std::string XMLNS_DELAY; /** Roster namespace (RFC 3921) */ GLOOX_API extern const std::string XMLNS_ROSTER; - /** Software Version namespace (XEP-0092) */ + /** Software Version namespace (@xep{0092}) */ GLOOX_API extern const std::string XMLNS_VERSION; - /** In-Band Registration namespace (XEP-0077) */ + /** In-Band Registration namespace (@xep{0077}) */ GLOOX_API extern const std::string XMLNS_REGISTER; /** Privacy lists namespace (RFC 3921) */ GLOOX_API extern const std::string XMLNS_PRIVACY; - /** Non-SASL Authentication namespace (XEP-0078) */ + /** Non-SASL Authentication namespace (@xep{0078}) */ GLOOX_API extern const std::string XMLNS_AUTH; - /** Private XML Storage namespace (XEP-0049) */ + /** Private XML Storage namespace (@xep{0049}) */ GLOOX_API extern const std::string XMLNS_PRIVATE_XML; - /** Last Activity namespace (XEP-0012) */ + /** Last Activity namespace (@xep{0012}) */ GLOOX_API extern const std::string XMLNS_LAST; - /** Jabber Search namespace (XEP-0055) */ + /** Jabber Search namespace (@xep{0055}) */ GLOOX_API extern const std::string XMLNS_SEARCH; - /** Out of Band Data (IQ) namespace (XEP-0066) */ + /** Out of Band Data (IQ) namespace (@xep{0066}) */ GLOOX_API extern const std::string XMLNS_IQ_OOB; - /** Data Forms namespace (XEP-0004) */ + /** Data Forms namespace (@xep{0004}) */ GLOOX_API extern const std::string XMLNS_X_DATA; - /** Message Events (XEP-0022) */ + /** Message Events (@xep{0022}) */ GLOOX_API extern const std::string XMLNS_X_EVENT; - /** Out of Band Data (X) namespace (XEP-0066) */ + /** Out of Band Data (X) namespace (@xep{0066}) */ GLOOX_API extern const std::string XMLNS_X_OOB; - /** Delayed Delivery namespace (XEP-0091) */ + /** Delayed Delivery namespace (@xep{0091}) */ GLOOX_API extern const std::string XMLNS_X_DELAY; - /** Current Jabber OpenPGP Usage (Sign.) (XEP-0027) */ + /** Current Jabber OpenPGP Usage (Sign.) (@xep{0027}) */ GLOOX_API extern const std::string XMLNS_X_GPGSIGNED; - /** Current Jabber OpenPGP Usage (Enc.) (XEP-0027) */ + /** Current Jabber OpenPGP Usage (Enc.) (@xep{0027}) */ GLOOX_API extern const std::string XMLNS_X_GPGENCRYPTED; - /** vcard-temp namespace (XEP-0054) */ + /** vcard-temp namespace (@xep{0054}) */ GLOOX_API extern const std::string XMLNS_VCARD_TEMP; - /** vCard-Based Avatars namespace (XEP-0153) */ + /** vCard-Based Avatars namespace (@xep{0153}) */ GLOOX_API extern const std::string XMLNS_X_VCARD_UPDATE; - /** Bookmark Storage namespace (XEP-0048) */ + /** Bookmark Storage namespace (@xep{0048}) */ GLOOX_API extern const std::string XMLNS_BOOKMARKS; - /** Annotations namespace (XEP-0145) */ + /** Annotations namespace (@xep{0145}) */ GLOOX_API extern const std::string XMLNS_ANNOTATIONS; - /** Nested Roster Groups namespace (XEP-0083) */ + /** Nested Roster Groups namespace (@xep{0083}) */ GLOOX_API extern const std::string XMLNS_ROSTER_DELIMITER; - /** XMPP Ping namespace (XEP-0199) */ + /** XMPP Ping namespace (@xep{0199}) */ GLOOX_API extern const std::string XMLNS_XMPP_PING; - /** Stream Initiation namespace (XEP-0095) */ + /** Stream Initiation namespace (@xep{0095}) */ GLOOX_API extern const std::string XMLNS_SI; - /** File transfer profile of Stream Initiation (XEP-0096) */ + /** File transfer profile of Stream Initiation (@xep{0096}) */ GLOOX_API extern const std::string XMLNS_SI_FT; - /** SOCKS5 Bytestreams namespace (XEP-0065) */ + /** SOCKS5 Bytestreams namespace (@xep{0065}) */ GLOOX_API extern const std::string XMLNS_BYTESTREAMS; - /** Multi-User Chat namespace (XEP-0045) */ + /** Multi-User Chat namespace (@xep{0045}) */ GLOOX_API extern const std::string XMLNS_MUC; - /** Multi-User Chat namespace (user) (XEP-0045) */ + /** Multi-User Chat namespace (user) (@xep{0045}) */ GLOOX_API extern const std::string XMLNS_MUC_USER; - /** Multi-User Chat namespace (admin) (XEP-0045) */ + /** Multi-User Chat namespace (admin) (@xep{0045}) */ GLOOX_API extern const std::string XMLNS_MUC_ADMIN; - /** Multi-User Chat namespace (unique) (XEP-0045) */ + /** Multi-User Chat namespace (unique) (@xep{0045}) */ GLOOX_API extern const std::string XMLNS_MUC_UNIQUE; - /** Multi-User Chat namespace (owner) (XEP-0045) */ + /** Multi-User Chat namespace (owner) (@xep{0045}) */ GLOOX_API extern const std::string XMLNS_MUC_OWNER; - /** Multi-User Chat namespace (roominfo) (XEP-0045) */ + /** Multi-User Chat namespace (roominfo) (@xep{0045}) */ GLOOX_API extern const std::string XMLNS_MUC_ROOMINFO; - /** Multi-User Chat namespace (rooms) (XEP-0045) */ + /** Multi-User Chat namespace (rooms) (@xep{0045}) */ GLOOX_API extern const std::string XMLNS_MUC_ROOMS; - /** Multi-User Chat namespace (request) (XEP-0045) */ + /** Multi-User Chat namespace (request) (@xep{0045}) */ GLOOX_API extern const std::string XMLNS_MUC_REQUEST; - /** PubSub namespace (XEP-0060) */ + /** PubSub namespace (@xep{0060}) */ GLOOX_API extern const std::string XMLNS_PUBSUB; - /** PubSub namespace (errors) (XEP-0060) */ + /** PubSub namespace (errors) (@xep{0060}) */ GLOOX_API extern const std::string XMLNS_PUBSUB_ERRORS; - /** PubSub namespace (event) (XEP-0060) */ + /** PubSub namespace (event) (@xep{0060}) */ GLOOX_API extern const std::string XMLNS_PUBSUB_EVENT; - /** PubSub namespace (owner) (XEP-0060) */ + /** PubSub namespace (owner) (@xep{0060}) */ GLOOX_API extern const std::string XMLNS_PUBSUB_OWNER; - /** Entity Capabilities namespace (XEP-0115) */ + /** Entity Capabilities namespace (@xep{0115}) */ GLOOX_API extern const std::string XMLNS_CAPS; /** SOCKS5 Fast Mode namespace */ @@ -542,48 +549,65 @@ namespace gloox /** Session Create Stream Feature (RFC 3921) */ GLOOX_API extern const std::string XMLNS_STREAM_SESSION; - /** Non-SASL Auth. Stream Feature (XEP-0078) */ + /** Non-SASL Auth. Stream Feature (@xep{0078}) */ GLOOX_API extern const std::string XMLNS_STREAM_IQAUTH; - /** In-Band Registration namespace (XEP-0077) */ + /** In-Band Registration namespace (@xep{0077}) */ GLOOX_API extern const std::string XMLNS_STREAM_IQREGISTER; - /** Stream Compression Feature namespace (XEP-0138) */ + /** Stream Compression Feature namespace (@xep{0138}) */ GLOOX_API extern const std::string XMLNS_STREAM_COMPRESS; - /** General HTTP binding (BOSH) namespace (XEP-0124) */ + /** General HTTP binding (BOSH) namespace (@xep{0124}) */ GLOOX_API extern const std::string XMLNS_HTTPBIND; - /** XMPP-over-BOSH extensions (XEP-0206) */ + /** XMPP-over-BOSH extensions (@xep{0206}) */ GLOOX_API extern const std::string XMLNS_XMPP_BOSH; - /** Message Receipt namespace (XEP-0184) */ + /** Message Receipt namespace (@xep{0184}) */ GLOOX_API extern const std::string XMLNS_RECEIPTS; - /** Message Receipt namespace (XEP-0172) */ + /** Message Receipt namespace (@xep{0172}) */ GLOOX_API extern const std::string XMLNS_NICKNAME; - /** Jingle namespace (XEP-0166) */ + /** Jabber RPC namespace (@xep{0009}) */ + GLOOX_API extern const std::string XMLNS_JABBER_RPC; + + /** Jingle namespace (@xep{0166}) */ GLOOX_API extern const std::string XMLNS_JINGLE; - /** Jingle Audio via RTP namespace (XEP-0167) */ - GLOOX_API extern const std::string XMLNS_JINGLE_AUDIO_RTP; + /** Jingle error namespace (@xep{0166}) */ + GLOOX_API extern const std::string XMLNS_JINGLE_ERRORS; - /** Jingle ICE-UDP Transport namespace (XEP-0176) */ + /** Jingle ICE-UDP Transport namespace (@xep{0176}) */ GLOOX_API extern const std::string XMLNS_JINGLE_ICE_UDP; - /** Jingle Raw UDP Transport namespace (XEP-0177) */ - GLOOX_API extern const std::string XMLNS_JINGLE_RAW_UDP; + /** Jingle File Transfer namespace (@xep{0234}) */ + GLOOX_API extern const std::string XMLNS_JINGLE_FILE_TRANSFER; - /** Jingle Video via RTP namespace (XEP-0180) */ - GLOOX_API extern const std::string XMLNS_JINGLE_VIDEO_RTP; + /** Jingle File Transfer namespace (multiple files) (@xep{0234}) */ + GLOOX_API extern const std::string XMLNS_JINGLE_FILE_TRANSFER_MULTI; - /** Stanza Headers and Internet Metadata (SHIM) namespace (XEP-0131) */ + /** Stanza Headers and Internet Metadata (SHIM) namespace (@xep{0131}) */ GLOOX_API extern const std::string XMLNS_SHIM; - /** Attention namespace (XEP-0224) */ + /** Attention namespace (@xep{0224}) */ GLOOX_API extern const std::string XMLNS_ATTENTION; + /** Stream Management namespace (@xep{0198}) */ + GLOOX_API extern const std::string XMLNS_STREAM_MANAGEMENT; + + /** Stanza Forwarding namespace (@xep{0297}) */ + GLOOX_API extern const std::string XMLNS_STANZA_FORWARDING; + + /** Message Carbons namespace (@xep{0280}) */ + GLOOX_API extern const std::string XMLNS_MESSAGE_CARBONS; + + /** Use of Cryptographic Hash Functions in XMPP namespace (@xep{0300}) */ + GLOOX_API extern const std::string XMLNS_HASHES; + + /** IO Data (@xep 0244) */ + GLOOX_API extern const std::string XMLNS_IODATA; /** Supported stream version (major). */ GLOOX_API extern const std::string XMPP_STREAM_VERSION_MAJOR; @@ -629,6 +653,20 @@ namespace gloox StreamEventAuthentication, /**< The Client is about to authenticate. */ StreamEventSessionInit, /**< The Client is about to create a session. */ StreamEventResourceBinding, /**< The Client is about to bind a resource to the stream. */ + StreamEventSMEnable, /**< The Client is about to request Stream Management (@xep{0198}). + * @since 1.0.4 */ + StreamEventSMResume, /**< The Client is about to request resumption by means of Stream Management + * (@xep{0198}). + * @since 1.0.4 */ + StreamEventSMResumed, /**< The stream has successfully been resumed by means of Stream Management + * (@xep{0198}). + * @since 1.0.4 */ + StreamEventSMEnableFailed, /**< The attempt to enable Stream Management + * (@xep{0198}) failed. This is not critical. + * @since 1.0.4 */ + StreamEventSMResumeFailed, /**< The attempt to resume an aborted session by means of Stream Management + * (@xep{0198}) failed. This is not critical. + * @since 1.0.4 */ StreamEventSessionCreation, /**< The Client is about to create a session. * @since 0.9.1 */ StreamEventRoster, /**< The Client is about to request the roster. */ @@ -694,15 +732,16 @@ namespace gloox StreamFeatureUnbind = 2, /**< The server supports binding multiple resources. */ StreamFeatureSession = 4, /**< The server supports sessions. */ StreamFeatureStartTls = 8, /**< The server supports <starttls>. */ - StreamFeatureIqRegister = 16, /**< The server supports XEP-0077 (In-Band + StreamFeatureIqRegister = 16, /**< The server supports @xep{0077} (In-Band * Registration). */ - StreamFeatureIqAuth = 32, /**< The server supports XEP-0078 (Non-SASL + StreamFeatureIqAuth = 32, /**< The server supports @xep{0078} (Non-SASL * Authentication). */ - StreamFeatureCompressZlib = 64, /**< The server supports XEP-0138 (Stream + StreamFeatureCompressZlib = 64, /**< The server supports @xep{0138} (Stream * Compression) (Zlib). */ - StreamFeatureCompressDclz = 128 /**< The server supports XEP-0138 (Stream + StreamFeatureCompressDclz = 128, /**< The server supports @xep{0138} (Stream * Compression) (LZW/DCLZ). */ - // SASLMechanism below must be adjusted accordingly. + StreamFeatureStreamManagement = 256 /**< The server supports @xep{0198} (Stream Management). */ + // SaslMechanism below must be adjusted accordingly. }; /** @@ -711,15 +750,17 @@ namespace gloox // must be adjusted with changes to StreamFeature enum above enum SaslMechanism { - SaslMechNone = 0, /**< Invalid SASL Mechanism. */ - SaslMechDigestMd5 = 256, /**< SASL Digest-MD5 according to RFC 2831. */ - SaslMechPlain = 512, /**< SASL PLAIN according to RFC 2595 Section 6. */ - SaslMechAnonymous = 1024, /**< SASL ANONYMOUS according to draft-ietf-sasl-anon-05.txt/ + SaslMechNone = 0, /**< Invalid SASL Mechanism. */ + SaslMechScramSha1 = 2048, /**< SASL SCRAM-SHA-1-PLUS accroding to RFC 5801 */ + SaslMechScramSha1Plus = 1024, /**< SASL SCRAM-SHA-1 accroding to RFC 5801 */ + SaslMechDigestMd5 = 4096, /**< SASL Digest-MD5 according to RFC 2831. */ + SaslMechPlain = 8192, /**< SASL PLAIN according to RFC 2595 Section 6. */ + SaslMechAnonymous = 16384, /**< SASL ANONYMOUS according to draft-ietf-sasl-anon-05.txt/ * RFC 2245 Section 6. */ - SaslMechExternal = 2048, /**< SASL EXTERNAL according to RFC 2222 Section 7.4. */ - SaslMechGssapi = 4096, /**< SASL GSSAPI (Win32 only). */ - SaslMechNTLM = 8192, /**< SASL NTLM (Win32 only). */ - SaslMechAll = 65535 /**< Includes all supported SASL mechanisms. */ + SaslMechExternal = 32768, /**< SASL EXTERNAL according to RFC 2222 Section 7.4. */ + SaslMechGssapi = 65536, /**< SASL GSSAPI (Win32 only). */ + SaslMechNTLM = 131072, /**< SASL NTLM (Win32 only). */ + SaslMechAll = 262143 /**< Includes all supported SASL mechanisms. */ }; /** @@ -800,7 +841,7 @@ namespace gloox StreamErrorXmlNotWellFormed, /**< The initiating entity has sent XML that is not well-formed as * defined by [XML]. */ StreamErrorUndefined /**< An undefined/unknown error occured. Also used if a diconnect was - * user-initiated. Also set before and during a established connection + * user-initiated. Also set before and during a established connection * (where obviously no error occured). */ }; @@ -993,9 +1034,9 @@ namespace gloox SaslTemporaryAuthFailure, /**< The authentication failed because of a temporary error condition * within the receiving entity; sent in reply to an <auth/> element * or <response/> element. */ - NonSaslConflict, /**< XEP-0078: Resource Conflict */ - NonSaslNotAcceptable, /**< XEP-0078: Required Information Not Provided */ - NonSaslNotAuthorized /**< XEP-0078: Incorrect Credentials */ + NonSaslConflict, /**< @xep{0078}: Resource Conflict */ + NonSaslNotAcceptable, /**< @xep{0078}: Required Information Not Provided */ + NonSaslNotAuthorized /**< @xep{0078}: Incorrect Credentials */ }; /** @@ -1017,6 +1058,7 @@ namespace gloox LogAreaClassSOCKS5Bytestream = 0x000800, /**< Log messages from SOCKS5Bytestream. */ LogAreaClassConnectionBOSH = 0x001000, /**< Log messages from ConnectionBOSH */ LogAreaClassConnectionTLS = 0x002000, /**< Log messages from ConnectionTLS */ + LogAreaLinkLocalManager = 0x004000, /**< Log messages from LinkLocalManager */ LogAreaAllClasses = 0x01FFFF, /**< All log messages from all the classes. */ LogAreaXmlIncoming = 0x020000, /**< Incoming XML. */ LogAreaXmlOutgoing = 0x040000, /**< Outgoing XML. */ @@ -1035,7 +1077,7 @@ namespace gloox }; /** - * The possible Message Events according to XEP-0022. + * The possible Message Events according to @xep{0022}. */ enum MessageEventType { @@ -1050,7 +1092,7 @@ namespace gloox }; /** - * The possible Chat States according to XEP-0085. + * The possible Chat States according to @xep{0085}. */ enum ChatStateType { @@ -1091,12 +1133,12 @@ namespace gloox */ enum MessageSessionFilter { - FilterMessageEvents = 1, /**< Message Events (XEP-0022) */ - FilterChatStates = 2 /**< Chat State Notifications (XEP-0085) */ + FilterMessageEvents = 1, /**< Message Events (@xep{0022}) */ + FilterChatStates = 2 /**< Chat State Notifications (@xep{0085}) */ }; /** - * Defined MUC room affiliations. See XEP-0045 for default privileges. + * Defined MUC room affiliations. See @xep{0045} for default privileges. */ enum MUCRoomAffiliation { @@ -1109,7 +1151,7 @@ namespace gloox }; /** - * Defined MUC room roles. See XEP-0045 for default privileges. + * Defined MUC room roles. See @xep{0045} for default privileges. */ enum MUCRoomRole { @@ -1214,7 +1256,7 @@ namespace gloox /** * A multimap of strings. */ - typedef std::multimap StringMultiMap; + typedef std::multimap StringMultiMap; class StanzaExtension; /** diff --git a/libs/libgloox/glooxversion.h b/libs/libgloox/glooxversion.h index 9b4b282..500d989 100644 --- a/libs/libgloox/glooxversion.h +++ b/libs/libgloox/glooxversion.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2009 by Jakob Schroeter + Copyright (c) 2009-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -10,4 +10,4 @@ This software is distributed without any warranty. */ -#define GLOOXVERSION 0x010000 +#define GLOOXVERSION 0x010013 diff --git a/libs/libgloox/gpgencrypted.cpp b/libs/libgloox/gpgencrypted.cpp index 95e1ab0..11bb23c 100644 --- a/libs/libgloox/gpgencrypted.cpp +++ b/libs/libgloox/gpgencrypted.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/gpgencrypted.h b/libs/libgloox/gpgencrypted.h index f6e16df..e2c5a1e 100644 --- a/libs/libgloox/gpgencrypted.h +++ b/libs/libgloox/gpgencrypted.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -25,14 +25,14 @@ namespace gloox class Tag; /** - * @brief This is an abstraction of a jabber:x:encrypted namespace element, as used in XEP-0027 + * @brief This is an abstraction of a jabber:x:encrypted namespace element, as used in @xep{0027} * (Current Jabber OpenPGP Usage). * * This class does not encrypt or decrypt any stanza content. It's meant to be an abstraction * of the XML representation only. * * XEP version: 1.3 - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API GPGEncrypted : public StanzaExtension diff --git a/libs/libgloox/gpgsigned.cpp b/libs/libgloox/gpgsigned.cpp index bcc40ce..663d5c3 100644 --- a/libs/libgloox/gpgsigned.cpp +++ b/libs/libgloox/gpgsigned.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/gpgsigned.h b/libs/libgloox/gpgsigned.h index 93eb7eb..f90c621 100644 --- a/libs/libgloox/gpgsigned.h +++ b/libs/libgloox/gpgsigned.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -25,14 +25,14 @@ namespace gloox class Tag; /** - * @brief This is an abstraction of a jabber:x:signed namespace element, as used in XEP-0027 + * @brief This is an abstraction of a jabber:x:signed namespace element, as used in @xep{0027} * (Current Jabber OpenPGP Usage). * * This class does not sign or verify any stanza content. It's meant to be an abstraction * of the XML representation only. * * XEP version: 1.3 - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API GPGSigned : public StanzaExtension diff --git a/libs/libgloox/inbandbytestream.cpp b/libs/libgloox/inbandbytestream.cpp index cf6254d..3a94203 100644 --- a/libs/libgloox/inbandbytestream.cpp +++ b/libs/libgloox/inbandbytestream.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -113,6 +113,8 @@ namespace gloox InBandBytestream::~InBandBytestream() { + m_handler = 0; // to prevent handleBytestreamClose() from being called in close() + if( m_open ) close(); @@ -161,7 +163,7 @@ namespace gloox bool InBandBytestream::handleIq( const IQ& iq ) // data or open request, always 'set' { const IBB* i = iq.findExtension( ExtIBB ); - if( !i || !m_handler || iq.subtype() != IQ::Set ) + if( !i || !m_handler || iq.subtype() != IQ::Set || i->sid() != this->sid() ) return false; if( !m_open ) @@ -254,7 +256,7 @@ namespace gloox do { const std::string& id = m_clientbase->getID(); - IQ iq( IQ::Set, m_target, id ); + IQ iq( IQ::Set, m_clientbase->jid() == m_target ? m_initiator : m_target, id ); iq.addExtension( new IBB( m_sid, ++m_sequence, data.substr( pos, m_blockSize ) ) ); m_clientbase->send( iq, this, IBBData ); diff --git a/libs/libgloox/inbandbytestream.h b/libs/libgloox/inbandbytestream.h index 9a6267a..b9aaa87 100644 --- a/libs/libgloox/inbandbytestream.h +++ b/libs/libgloox/inbandbytestream.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -27,7 +27,7 @@ namespace gloox class Message; /** - * @brief An implementation of a single In-Band Bytestream (XEP-0047). + * @brief An implementation of a single In-Band Bytestream (@xep{0047}). * * One instance of this class handles a single byte stream. * @@ -37,7 +37,7 @@ namespace gloox * are not using MessageSessions. However, it will always send * data using IQ stanzas (which will always work). * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.8 */ class GLOOX_API InBandBytestream : public Bytestream, public IqHandler, public MessageHandler @@ -100,7 +100,7 @@ namespace gloox /** * @brief An abstraction of IBB elements, implemented as as StanzaExtension. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class IBB : public StanzaExtension diff --git a/libs/libgloox/instantmucroom.cpp b/libs/libgloox/instantmucroom.cpp index 3303a2b..2501697 100644 --- a/libs/libgloox/instantmucroom.cpp +++ b/libs/libgloox/instantmucroom.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/instantmucroom.h b/libs/libgloox/instantmucroom.h index 88462ba..ae5d174 100644 --- a/libs/libgloox/instantmucroom.h +++ b/libs/libgloox/instantmucroom.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -24,7 +24,7 @@ namespace gloox * @brief This class implements an instant MUC room. * * XEP version: 1.21 - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API InstantMUCRoom : public MUCRoom diff --git a/libs/libgloox/iq.cpp b/libs/libgloox/iq.cpp index e33e971..aab62ae 100644 --- a/libs/libgloox/iq.cpp +++ b/libs/libgloox/iq.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/iq.h b/libs/libgloox/iq.h index 7270531..266cc80 100644 --- a/libs/libgloox/iq.h +++ b/libs/libgloox/iq.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -27,7 +27,7 @@ namespace gloox * @brief An abstraction of an IQ stanza. * * @author Vincent Thomasset - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API IQ : public Stanza diff --git a/libs/libgloox/iqhandler.h b/libs/libgloox/iqhandler.h index 809e36f..8bc9b96 100644 --- a/libs/libgloox/iqhandler.h +++ b/libs/libgloox/iqhandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -26,7 +26,7 @@ namespace gloox * Derived classes can be registered as IqHandlers with the Client. * Upon an incoming IQ packet @ref handleIq() will be called. * - * @author Jakob Schroeter + * @author Jakob Schröter */ class GLOOX_API IqHandler { @@ -40,7 +40,7 @@ namespace gloox * Reimplement this function if you want to be notified about incoming IQs. * @param iq The complete IQ stanza. * @return Indicates whether a request of type 'get' or 'set' has been handled. This includes - * the obligatory 'result' answer. If you return @b false, a 'error' will be sent. + * the obligatory 'result' answer. If you return @b false, an 'error' will be sent. * @since 1.0 */ virtual bool handleIq( const IQ& iq ) = 0; diff --git a/libs/libgloox/jid.cpp b/libs/libgloox/jid.cpp index d91396e..a3a90c7 100644 --- a/libs/libgloox/jid.cpp +++ b/libs/libgloox/jid.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -80,7 +80,7 @@ namespace gloox if( !m_username.empty() ) m_bare = m_username + '@'; else - m_bare = EmptyString; + m_bare = ""/*EmptyString*/; m_bare += m_server; } diff --git a/libs/libgloox/jid.h b/libs/libgloox/jid.h index 841f6c6..2c5869a 100644 --- a/libs/libgloox/jid.h +++ b/libs/libgloox/jid.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -24,7 +24,7 @@ namespace gloox /** * @brief An abstraction of a JID. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.4 */ class GLOOX_API JID @@ -139,20 +139,49 @@ namespace gloox */ bool operator!=( const JID& right ) const { return full() != right.full(); } + /** + * Compares two JIDs to see if the left is less than the right. + * Needed for JID to be a key in a map. + * @param right The second JID. + * @since 1.0.4 + */ + bool operator<( const JID& right ) const { return full() < right.full(); } + + /** + * Compares two JIDs to see if the left is less than or equal to the right. + * @param right The second JID. + * @since 1.0.4 + */ + bool operator<=( const JID& right ) const { return full() <= right.full(); } + + /** + * Compares two JIDs to see if the left is greater than the right. + * @param right The second JID. + * @since 1.0.4 + */ + bool operator>( const JID& right ) const { return full() > right.full(); } + + /** + * Compares two JIDs to see if the left is greater than the right. + * @param right The second JID. + * @since 1.0.4 + */ + bool operator>=( const JID& right ) const { return full() >= right.full(); } + /** * Converts to @b true if the JID is valid, @b false otherwise. */ operator bool() const { return m_valid; } /** - * XEP-0106: JID Escaping + * @xep{0106}: JID Escaping * @param node The node to escape. * @return The escaped node. */ static std::string escapeNode( const std::string& node ); /** - * XEP-0106: JID Escaping + * @xep{0106}: JID Escaping * @param node The node to unescape. * @return The unescaped node. */ diff --git a/libs/libgloox/lastactivity.cpp b/libs/libgloox/lastactivity.cpp index 3760dfb..8942f35 100644 --- a/libs/libgloox/lastactivity.cpp +++ b/libs/libgloox/lastactivity.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/lastactivity.h b/libs/libgloox/lastactivity.h index f0c6eb1..a40e6f4 100644 --- a/libs/libgloox/lastactivity.h +++ b/libs/libgloox/lastactivity.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -26,14 +26,14 @@ namespace gloox class LastActivityHandler; /** - * @brief This is an implementation of XEP-0012 (Last Activity) for both clients and components. + * @brief This is an implementation of @xep{0012} (Last Activity) for both clients and components. * * LastActivity can be used to query remote entities about their last activity time as well * as answer incoming last-activity-queries. * * XEP Version: 2.0 * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.6 */ class GLOOX_API LastActivity : public IqHandler @@ -41,12 +41,12 @@ namespace gloox public: /** * @brief This is an abstraction of a LastActivity Query that - * can be used in XEP-0012 as well as XEP-0256. + * can be used in @xep{0012} as well as @xep{0256}. * - * XEP-Version: 2.0 (XEP-0012) - * XEP-Version: 0.1 (XEP-0256) + * XEP-Version: 2.0 (@xep{0012}) + * XEP-Version: 0.1 (@xep{0256}) * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API Query : public StanzaExtension diff --git a/libs/libgloox/lastactivityhandler.h b/libs/libgloox/lastactivityhandler.h index fb3217d..3518123 100644 --- a/libs/libgloox/lastactivityhandler.h +++ b/libs/libgloox/lastactivityhandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -24,7 +24,7 @@ namespace gloox * @brief This is an virtual interface that, once reimplemented, allows to receive the * results of Last-Activity-queries to other entities. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.6 */ class GLOOX_API LastActivityHandler diff --git a/libs/libgloox/loghandler.h b/libs/libgloox/loghandler.h index fa45a1b..732957f 100644 --- a/libs/libgloox/loghandler.h +++ b/libs/libgloox/loghandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -27,7 +27,7 @@ namespace gloox * * @ref handleLog() is called for log messages. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.5 */ class GLOOX_API LogHandler diff --git a/libs/libgloox/logsink.cpp b/libs/libgloox/logsink.cpp index 30719de..1577304 100644 --- a/libs/libgloox/logsink.cpp +++ b/libs/libgloox/logsink.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/logsink.h b/libs/libgloox/logsink.h index 6b92280..872a26c 100644 --- a/libs/libgloox/logsink.h +++ b/libs/libgloox/logsink.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -32,7 +32,7 @@ namespace gloox * * You should not need to use this class directly. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.8 */ class GLOOX_API LogSink diff --git a/libs/libgloox/macros.h b/libs/libgloox/macros.h index c8f622f..752fe3b 100644 --- a/libs/libgloox/macros.h +++ b/libs/libgloox/macros.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/md5.cpp b/libs/libgloox/md5.cpp index 3b41b62..af540a0 100644 --- a/libs/libgloox/md5.cpp +++ b/libs/libgloox/md5.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/md5.h b/libs/libgloox/md5.h index 47dbdfc..dd5ef50 100644 --- a/libs/libgloox/md5.h +++ b/libs/libgloox/md5.h @@ -63,7 +63,7 @@ namespace gloox * This is an implementation of the Message Digest Algorithm as decribed in RFC 1321. * The original code has been taken from an implementation by L. Peter Deutsch. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API MD5 diff --git a/libs/libgloox/message.cpp b/libs/libgloox/message.cpp index 66290d7..813c775 100644 --- a/libs/libgloox/message.cpp +++ b/libs/libgloox/message.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -71,7 +71,7 @@ namespace gloox if( m_subtype == Invalid ) return 0; - Tag* t = new Tag( "message" ); + Tag* t = new Tag( "message", XMLNS, XMLNS_CLIENT ); if( m_to ) t->addAttribute( "to", m_to.full() ); if( m_from ) diff --git a/libs/libgloox/message.h b/libs/libgloox/message.h index 4eb21c4..2c486bf 100644 --- a/libs/libgloox/message.h +++ b/libs/libgloox/message.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -27,13 +27,14 @@ namespace gloox * @brief An abstraction of a message stanza. * * @author Vincent Thomasset - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API Message : public Stanza { friend class ClientBase; + friend class Forward; public: @@ -123,6 +124,8 @@ namespace gloox /** * Convenience function that returns a pointer to a DelayedDelivery StanzaExtension, if the * message contains one. + * Make sure you have registered a DelayedDelivery instance with your ClientBase (this is not done automatically), + * otherwise this method will always return 0. * @return A pointer to a DelayedDelivery object, or 0. */ const DelayedDelivery* when() const diff --git a/libs/libgloox/messageevent.cpp b/libs/libgloox/messageevent.cpp index 3e5c8b6..a778750 100644 --- a/libs/libgloox/messageevent.cpp +++ b/libs/libgloox/messageevent.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -28,6 +28,9 @@ namespace gloox MessageEvent::MessageEvent( const Tag* tag ) : StanzaExtension( ExtMessageEvent ), m_event( MessageEventCancel ) { + if( !tag ) + return; + const TagList& l = tag->children(); TagList::const_iterator it = l.begin(); int event = 0; diff --git a/libs/libgloox/messageevent.h b/libs/libgloox/messageevent.h index dc60b5b..0cbb3a3 100644 --- a/libs/libgloox/messageevent.h +++ b/libs/libgloox/messageevent.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -24,9 +24,9 @@ namespace gloox class Tag; /** - * @brief An implementation of Message Events (XEP-0022) as a StanzaExtension. + * @brief An implementation of Message Events (@xep{0022}) as a StanzaExtension. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API MessageEvent : public StanzaExtension diff --git a/libs/libgloox/messageeventfilter.cpp b/libs/libgloox/messageeventfilter.cpp index 12f71e1..f9a9111 100644 --- a/libs/libgloox/messageeventfilter.cpp +++ b/libs/libgloox/messageeventfilter.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/messageeventfilter.h b/libs/libgloox/messageeventfilter.h index b1c91a7..3382530 100644 --- a/libs/libgloox/messageeventfilter.h +++ b/libs/libgloox/messageeventfilter.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -26,13 +26,13 @@ namespace gloox class MessageSession; /** - * @brief This class adds Message Event (XEP-0022) support to a MessageSession. + * @brief This class adds Message Event (@xep{0022}) support to a MessageSession. * * This implementation of Message Events is fully transparent to the user of the class. * If the remote entity does not request message events, MessageEventFilter will not send * any, even if the user requests it. (This is required by the protocol specification.) * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.8 */ class GLOOX_API MessageEventFilter : public MessageFilter @@ -50,7 +50,7 @@ namespace gloox virtual ~MessageEventFilter(); /** - * Use this function to raise an event as defined in XEP-0022. + * Use this function to raise an event as defined in @xep{0022}. * @note The Spec states that Message Events shall not be sent to an entity * which did not request them. Reasonable effort is taken in this function to * avoid spurious event sending. You should be safe to call this even if Message @@ -63,7 +63,7 @@ namespace gloox /** * The MessageEventHandler registered here will receive Message Events according - * to XEP-0022. + * to @xep{0022}. * @param meh The MessageEventHandler to register. */ void registerMessageEventHandler( MessageEventHandler* meh ); diff --git a/libs/libgloox/messageeventhandler.h b/libs/libgloox/messageeventhandler.h index 6dbacb3..55a355d 100644 --- a/libs/libgloox/messageeventhandler.h +++ b/libs/libgloox/messageeventhandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -23,9 +23,9 @@ namespace gloox /** * @brief A virtual interface that enables an object to be notified about - * Message Events (XEP-0022). + * Message Events (@xep{0022}). * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.8 */ class GLOOX_API MessageEventHandler diff --git a/libs/libgloox/messagefilter.cpp b/libs/libgloox/messagefilter.cpp index 2f80e6c..c5b5969 100644 --- a/libs/libgloox/messagefilter.cpp +++ b/libs/libgloox/messagefilter.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/messagefilter.h b/libs/libgloox/messagefilter.h index 43e2cfa..76428f5 100644 --- a/libs/libgloox/messagefilter.h +++ b/libs/libgloox/messagefilter.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -31,7 +31,7 @@ namespace gloox * Messages to be sent out are presented to the filter via the decorate() function, incoming * messages can be filtered in the -- filter() method. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.8 */ class GLOOX_API MessageFilter diff --git a/libs/libgloox/messagehandler.h b/libs/libgloox/messagehandler.h index 47f302c..bda2faa 100644 --- a/libs/libgloox/messagehandler.h +++ b/libs/libgloox/messagehandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -31,7 +31,7 @@ namespace gloox * the registered handler will receive all messages originating from the Session's contact. See * MessageSession for more details. * - * @author Jakob Schroeter + * @author Jakob Schröter */ class GLOOX_API MessageHandler { diff --git a/libs/libgloox/messagesession.cpp b/libs/libgloox/messagesession.cpp index e8fd442..ae88e23 100644 --- a/libs/libgloox/messagesession.cpp +++ b/libs/libgloox/messagesession.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -21,9 +21,9 @@ namespace gloox { - MessageSession::MessageSession( ClientBase* parent, const JID& jid, bool wantUpgrade, int types, bool honorTID ) + MessageSession::MessageSession( ClientBase* parent, const JID& jid, bool wantResourceTracking, int types, bool honorTID ) : m_parent( parent ), m_target( jid ), m_messageHandler( 0 ), - m_types( types ), m_wantUpgrade( wantUpgrade ), m_hadMessages( false ), m_honorThreadID( honorTID ) + m_types( types ), m_wantResourceTracking( wantResourceTracking ), m_hadMessages( false ), m_honorThreadID( honorTID ) { if( m_parent ) m_parent->registerMessageSession( this ); @@ -36,7 +36,7 @@ namespace gloox void MessageSession::handleMessage( Message& msg ) { - if( m_wantUpgrade && msg.from().bare() == m_target.full() ) + if( m_wantResourceTracking && msg.from().resource() != m_target.resource() ) setResource( msg.from().resource() ); if( !m_hadMessages ) @@ -55,10 +55,15 @@ namespace gloox for( ; it != m_messageFilterList.end(); ++it ) (*it)->filter( msg ); - if( m_messageHandler && !msg.body().empty() ) + if( m_messageHandler ) m_messageHandler->handleMessage( msg, this ); } + void MessageSession::send( const std::string& message ) + { + send( message, EmptyString ); + } + void MessageSession::send( const std::string& message, const std::string& subject, const StanzaExtensionList& sel ) { if( !m_hadMessages ) @@ -93,7 +98,6 @@ namespace gloox void MessageSession::resetResource() { - m_wantUpgrade = true; m_target.setResource( EmptyString ); } diff --git a/libs/libgloox/messagesession.h b/libs/libgloox/messagesession.h index d2232cd..724631d 100644 --- a/libs/libgloox/messagesession.h +++ b/libs/libgloox/messagesession.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -139,7 +139,7 @@ namespace gloox * @note You should never delete a MessageSession manually. Use ClientBase::disposeMessageSession() * instead. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.8 */ class GLOOX_API MessageSession @@ -163,7 +163,8 @@ namespace gloox * JID that has no resource. This 'upgrade' will only happen once. * @param types ORed list of Message::MessageType values this MessageSession shall receive. * Defaults to 0 which means any type is received. - * @param honorTID Indicates whether thread IDs should be honored when matching incoming messages to MessageSessions. The default is usually fine. + * @param honorTID Indicates whether thread IDs should be honored when matching incoming messages to MessageSessions. + * The default (@b true) is usually fine. */ MessageSession( ClientBase* parent, const JID& jid, bool wantUpgrade = true, int types = 0, bool honorTID = true ); @@ -218,6 +219,12 @@ namespace gloox void removeMessageHandler() { m_messageHandler = 0; } + /** + * A convenience function to quickly send a message. + * @param message The message to send. + */ + virtual void send( const std::string& message ); + /** * A convenience function to quickly send a message (optionally with subject). This is * the preferred way to send a message from a MessageSession. @@ -226,7 +233,7 @@ namespace gloox * @param sel An optional list of StanzaExtensions. The extensions will be owned by the message-to-be-sent; * do not attempt to re-use or delete them. */ - virtual void send( const std::string& message, const std::string& subject = EmptyString, + virtual void send( const std::string& message, const std::string& subject, const StanzaExtensionList& sel = StanzaExtensionList() ); /** @@ -265,7 +272,9 @@ namespace gloox * This function resets the session's target JID to its bare form such that * subsequently sent messages will be sent to that bare JID. The server will * determine the best resource to deliver to. Useful if the target - * resource changed presence to e.g. away or offline. + * resource changed presence to e.g. away or offline. This does not automatically + * set the wantResourceTracking option. If you need escalation, be sure to set + * this option in the constructor. */ void resetResource(); @@ -298,7 +307,7 @@ namespace gloox std::string m_thread; int m_types; - bool m_wantUpgrade; + bool m_wantResourceTracking; bool m_hadMessages; bool m_honorThreadID; diff --git a/libs/libgloox/messagesessionhandler.h b/libs/libgloox/messagesessionhandler.h index f6c4003..612564b 100644 --- a/libs/libgloox/messagesessionhandler.h +++ b/libs/libgloox/messagesessionhandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -24,11 +24,11 @@ namespace gloox * @brief A virtual interface which can be reimplemented to receive incoming message sessions. * * Derived classes can be registered as MessageSessionHandlers with the Client. - * If you have enabled automatic MessageSession creation by calling Client::setAutoMessageSession(), + * If you have registered as a MessageSessionHandler by calling ClientBase::registerMessageSessionHandler(), * handleMessageSession() will be called if a message stanza arrives for which there is no * MessageSession yet. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.8 */ class GLOOX_API MessageSessionHandler @@ -48,10 +48,10 @@ namespace gloox * @note Make sure to read the note in ClientBase::registerMessageSessionHandler() * regarding the feeding of decorators. * - * @note After receiving a MessageSession your object is the owner and is responsible - * for the destruction of the session. + * @note You should never delete the MessageSession manually. Instead call + * ClientBase::disposeMessageSession() when you no longer need the session. * - * @note If you don't need the MessageSession, you should not delete it here. You will + * @note If you don't need the MessageSession, you should not dispose it here. You will * get an endless loop if you do. * * @note You should register your MessageHandler here, or else the first message diff --git a/libs/libgloox/mucinvitationhandler.h b/libs/libgloox/mucinvitationhandler.h index fed2a06..1eb108e 100644 --- a/libs/libgloox/mucinvitationhandler.h +++ b/libs/libgloox/mucinvitationhandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -18,7 +18,6 @@ #include "clientbase.h" #include "macros.h" #include "jid.h" -#include "mucroom.h" #include @@ -30,7 +29,7 @@ namespace gloox * * Register a derived class with ClientBase::registerMUCInvitationHandler(). * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API MUCInvitationHandler @@ -40,11 +39,7 @@ namespace gloox * Constructor. Prepares the given ClientBase for receiving MUC invitations.. * @param parent A ClientBase instance to prepare. */ - MUCInvitationHandler( ClientBase* parent ) - { - if( parent ) - parent->registerStanzaExtension( new MUCRoom::MUCUser() ); - } + MUCInvitationHandler( ClientBase* parent ); /** * Virtual Destructor. diff --git a/libs/libgloox/mucmessagesession.cpp b/libs/libgloox/mucmessagesession.cpp index 36f97b6..8686910 100644 --- a/libs/libgloox/mucmessagesession.cpp +++ b/libs/libgloox/mucmessagesession.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/mucmessagesession.h b/libs/libgloox/mucmessagesession.h index ece85c9..e97c3d9 100644 --- a/libs/libgloox/mucmessagesession.h +++ b/libs/libgloox/mucmessagesession.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -26,7 +26,7 @@ namespace gloox * * This class is used internally by MUCRoom. You should not need to use it directly. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API MUCMessageSession : public MessageSession diff --git a/libs/libgloox/mucroom.cpp b/libs/libgloox/mucroom.cpp index d7074fb..3fdf623 100644 --- a/libs/libgloox/mucroom.cpp +++ b/libs/libgloox/mucroom.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -969,6 +969,9 @@ namespace gloox m_roomHandler->handleMUCParticipantPresence( this, party, presence ); delete party.nick; + delete party.jid; + delete party.actor; + delete party.alternate; } } @@ -1081,12 +1084,9 @@ namespace gloox { std::string when; bool privMsg = false; - bool history = false; if( msg.when() ) - { when = msg.when()->stamp(); - history = true; - } + if( msg.subtype() & ( Message::Chat | Message::Normal ) ) privMsg = true; diff --git a/libs/libgloox/mucroom.h b/libs/libgloox/mucroom.h index 444fff5..238cb4b 100644 --- a/libs/libgloox/mucroom.h +++ b/libs/libgloox/mucroom.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -36,7 +36,7 @@ namespace gloox class Message; /** - * @brief This is an implementation of XEP-0045 (Multi-User Chat). + * @brief This is an implementation of @xep{0045} (Multi-User Chat). * * Usage is pretty simple: * @@ -79,7 +79,7 @@ namespace gloox * (room\@service/nick). * * XEP version: 1.21 - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API MUCRoom : private DiscoHandler, private PresenceHandler, @@ -99,7 +99,7 @@ namespace gloox HistorySeconds, /**< Send only the messages received in the last "X" seconds. */ HistorySince, /**< Send only the messages received since the datetime specified * (which MUST conform to the DateTime profile specified in Jabber - * Date and Time Profiles (XEP-0082)). */ + * Date and Time Profiles (@xep{0082})). */ HistoryUnknown /**< It is up to the service to decide how much history to send. * This is the default. */ }; @@ -121,7 +121,7 @@ namespace gloox * * You should not need to use this class directly. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class MUC : public StanzaExtension @@ -195,7 +195,7 @@ namespace gloox * * You should not need to use this class directly. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class MUCUser : public StanzaExtension @@ -535,7 +535,7 @@ namespace gloox * Use this function to request room history since specific datetime. * History is sent only once after entering a room. You should use this function before joining. * @param since A string representing a datetime conforming to the DateTime profile specified - * in Jabber Date and Time Profiles (XEP-0082). + * in Jabber Date and Time Profiles (@xep{0082}). * @note If this function is not used to request a specific amount of room history, it is up * to the MUC service to decide how much history to send. */ @@ -789,7 +789,7 @@ namespace gloox /** * @brief An abstraction of a MUC owner query. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class MUCOwner : public StanzaExtension @@ -879,7 +879,7 @@ namespace gloox /** * @brief An abstraction of a MUC admin query. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class MUCAdmin : public StanzaExtension diff --git a/libs/libgloox/mucroomconfighandler.h b/libs/libgloox/mucroomconfighandler.h index 67223d8..3a79cd0 100644 --- a/libs/libgloox/mucroomconfighandler.h +++ b/libs/libgloox/mucroomconfighandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -32,7 +32,7 @@ namespace gloox * used when manipulating the lists of members, admins, owners, etc. * of a room. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class MUCListItem @@ -170,7 +170,7 @@ namespace gloox /** * @brief An abstract interface that can be implemented for MUC room configuration. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API MUCRoomConfigHandler diff --git a/libs/libgloox/mucroomhandler.h b/libs/libgloox/mucroomhandler.h index d1e47eb..594be70 100644 --- a/libs/libgloox/mucroomhandler.h +++ b/libs/libgloox/mucroomhandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -84,7 +84,7 @@ namespace gloox * @note This interface does not notify about room configuration related events. Use * MUCRoomConfigHandler for that puprose. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API MUCRoomHandler @@ -192,7 +192,7 @@ namespace gloox * @param features ORed MUCRoomFlag's. * @param name The room's name as returned by Service Discovery. * @param infoForm A DataForm containing extended room information. May be 0 if the service - * doesn't support extended room information. See Section 15.5 of XEP-0045 for defined + * doesn't support extended room information. See Section 15.5 of @xep{0045} for defined * field types. You should not delete the form. * * @note This function may be called without a prior call to MUCRoom::getRoomInfo(). This diff --git a/libs/libgloox/mutex.cpp b/libs/libgloox/mutex.cpp index 0f9898c..1cf222d 100644 --- a/libs/libgloox/mutex.cpp +++ b/libs/libgloox/mutex.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -56,9 +56,17 @@ namespace gloox Mutex::MutexImpl::MutexImpl() { #if defined( _WIN32 ) && !defined( __SYMBIAN32__ ) + // NOTE: Critical sections by nature allow "recursive" + // (the same thread can get it again, and just bump the ref count). InitializeCriticalSection( &m_cs ); #elif defined( HAVE_PTHREAD ) - pthread_mutex_init( &m_mutex, 0 ); + // For pthreads, configured the mutex to be recursive + // (the same thread can get it again, and just bump the ref count). + pthread_mutexattr_t mutexAttribute; + pthread_mutexattr_init( &mutexAttribute ); + pthread_mutexattr_settype( &mutexAttribute, PTHREAD_MUTEX_RECURSIVE ); + pthread_mutex_init( &m_mutex, &mutexAttribute ); + pthread_mutexattr_destroy( &mutexAttribute ); #endif } diff --git a/libs/libgloox/mutex.h b/libs/libgloox/mutex.h index dab121c..e8b38ee 100644 --- a/libs/libgloox/mutex.h +++ b/libs/libgloox/mutex.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -27,7 +27,7 @@ namespace gloox * * If you locked a mutex you MUST unlock it within the same thread. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API Mutex diff --git a/libs/libgloox/mutexguard.h b/libs/libgloox/mutexguard.h index 09ade92..12d3dd9 100644 --- a/libs/libgloox/mutexguard.h +++ b/libs/libgloox/mutexguard.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -25,7 +25,7 @@ namespace gloox /** * @brief A simple implementation of a mutex guard. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API MutexGuard diff --git a/libs/libgloox/nickname.cpp b/libs/libgloox/nickname.cpp index 0b1ab6b..3206a66 100644 --- a/libs/libgloox/nickname.cpp +++ b/libs/libgloox/nickname.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/nickname.h b/libs/libgloox/nickname.h index 8b21003..a4095ce 100644 --- a/libs/libgloox/nickname.h +++ b/libs/libgloox/nickname.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -24,10 +24,10 @@ namespace gloox class Tag; /** - * @brief An implementation of User Nickname (XEP-0172) as a StanzaExtension. + * @brief An implementation of User Nickname (@xep{0172}) as a StanzaExtension. * * XEP version: 1.0 - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API Nickname : public StanzaExtension diff --git a/libs/libgloox/nonsaslauth.cpp b/libs/libgloox/nonsaslauth.cpp index a0cf734..7e3d628 100644 --- a/libs/libgloox/nonsaslauth.cpp +++ b/libs/libgloox/nonsaslauth.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/nonsaslauth.h b/libs/libgloox/nonsaslauth.h index cfc1eae..fce8711 100644 --- a/libs/libgloox/nonsaslauth.h +++ b/libs/libgloox/nonsaslauth.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -26,14 +26,14 @@ namespace gloox class Tag; /** - * @brief This class is an implementation of XEP-0078 (Non-SASL Authentication). + * @brief This class is an implementation of @xep{0078} (Non-SASL Authentication). * * It is invoked by @ref Client automatically if supported by the server and if SASL authentication * is not supported. * You should not need to use this class manually. * * XEP Version: 2.3 - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.3 */ class GLOOX_API NonSaslAuth : public IqHandler @@ -68,9 +68,9 @@ namespace gloox public: #endif /** - * @brief An abstraction of an IQ extension used for Non-SASL authentication (XEP-0078). + * @brief An abstraction of an IQ extension used for Non-SASL authentication (@xep{0078}). * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class Query : public StanzaExtension diff --git a/libs/libgloox/oob.cpp b/libs/libgloox/oob.cpp index c59244f..fc17f3d 100644 --- a/libs/libgloox/oob.cpp +++ b/libs/libgloox/oob.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/oob.h b/libs/libgloox/oob.h index c3095b2..721de59 100644 --- a/libs/libgloox/oob.h +++ b/libs/libgloox/oob.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -26,10 +26,10 @@ namespace gloox /** * @brief This is an abstraction of a jabber:x:oob namespace element or a jabber:iq:oob namespace element - * as specified in XEP-0066. + * as specified in @xep{0066}. * * XEP version: 1.5 - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API OOB : public StanzaExtension diff --git a/libs/libgloox/parser.cpp b/libs/libgloox/parser.cpp index 4b32352..976ad5c 100644 --- a/libs/libgloox/parser.cpp +++ b/libs/libgloox/parser.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -123,6 +123,7 @@ namespace gloox switch( m_state ) { + case InterTag: case TagInside: m_cdata += rep; break; @@ -141,8 +142,7 @@ namespace gloox { if( pos + needle.length() <= data.length() ) { - // if( !data.compare(pos, needle.length(), needle ) ) - if( !data.compare(needle.substr(pos, needle.length())) ) + if( !data.compare( pos, needle.length(), needle ) ) { pos += needle.length() - 1; return ForwardFound; @@ -173,12 +173,6 @@ namespace gloox const unsigned char c = data[i]; // printf( "found char: %c, ", c ); - if( !isValid( c ) ) - { - cleanup(); - return static_cast( i ); - } - switch( m_state ) { case Initial: @@ -201,10 +195,29 @@ namespace gloox // printf( "InterTag: %c\n", c ); m_tag = EmptyString; if( isWhitespace( c ) ) + { + m_state = TagInside; + if( m_current ) + m_cdata += c; break; + } switch( c ) { + case '&': +// printf( "InterTag, calling decode\n" ); + switch( decode( i, data ) ) + { + case DecodeValid: + m_state = TagInside; + break; + case DecodeInvalid: + cleanup(); + return static_cast( i ); + case DecodeInsufficient: + return -1; + } + break; case '<': m_state = TagOpening; break; @@ -782,11 +795,6 @@ namespace gloox m_preamble = 0; } - bool Parser::isValid( unsigned char c ) - { - return ( c != 0xc0 || c != 0xc1 || c < 0xf5 ); - } - bool Parser::isWhitespace( unsigned char c ) { return ( c == 0x09 || c == 0x0a || c == 0x0d || c == 0x20 ); diff --git a/libs/libgloox/parser.h b/libs/libgloox/parser.h index c8e333c..51b4735 100644 --- a/libs/libgloox/parser.h +++ b/libs/libgloox/parser.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -28,7 +28,7 @@ namespace gloox /** * @brief This class implements an XML parser. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API Parser @@ -104,7 +104,6 @@ namespace gloox void addCData(); bool closeTag(); bool isWhitespace( unsigned char c ); - bool isValid( unsigned char c ); void streamEvent( Tag* tag ); ForwardScanState forwardScan( std::string::size_type& pos, const std::string& data, const std::string& needle ); diff --git a/libs/libgloox/prep.cpp b/libs/libgloox/prep.cpp index 64dcc8d..43d1410 100644 --- a/libs/libgloox/prep.cpp +++ b/libs/libgloox/prep.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -92,6 +92,18 @@ namespace gloox #endif } + bool saslprep( const std::string& input, std::string& out ) + { + #ifdef HAVE_LIBIDN + return prepare( input, out, stringprep_saslprep ); + #else + if( input.length() > JID_PORTION_SIZE ) + return false; + out = input; + return true; + #endif + } + bool idna( const std::string& domain, std::string& out ) { #ifdef HAVE_LIBIDN @@ -103,6 +115,7 @@ namespace gloox if( rc == IDNA_SUCCESS ) { out = prepped; + free( prepped ); return true; } if( rc != IDNA_MALLOC_ERROR ) diff --git a/libs/libgloox/prep.h b/libs/libgloox/prep.h index d8c5d37..767ece0 100644 --- a/libs/libgloox/prep.h +++ b/libs/libgloox/prep.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -32,7 +32,7 @@ namespace gloox * LibIDN is not installed these functions return the string they are given * without any modification. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.2 */ namespace prep @@ -42,7 +42,7 @@ namespace gloox * @param node The string to apply the profile to. * @param out The prepped string. In case of an error this string is not touched. * If LibIDN is not available the string is returned unchanged. - * @return @b True if prepping was successful, @b false otherwise or of LibIDN + * @return @b True if prepping was successful, @b false otherwise or if LibIDN * is not available. */ bool nodeprep( const std::string& node, std::string& out ); @@ -52,7 +52,7 @@ namespace gloox * @param domain The string to apply the profile to. * @param out The prepped string. In case of an error this string is not touched. * If LibIDN is not available the string is returned unchanged. - * @return @b True if prepping was successful, @b false otherwise or of LibIDN + * @return @b True if prepping was successful, @b false otherwise or if LibIDN * is not available. */ bool nameprep( const std::string& domain, std::string& out ); @@ -62,18 +62,28 @@ namespace gloox * @param resource The string to apply the profile to. * @param out The prepped string. In case of an error this string is not touched. * If LibIDN is not available the string is returned unchanged. - * @return @b True if prepping was successful, @b false otherwise or of LibIDN + * @return @b True if prepping was successful, @b false otherwise or if LibIDN * is not available. */ bool resourceprep( const std::string& resource, std::string& out ); + /** + * This function applies the Saslprep profile of Stringprep to a std::string. + * @param input The string to apply the profile to. + * @param out The prepped string. In case of an error this string is not touched. + * If LibIDN is not available the string is returned unchanged. + * @return @b True if prepping was successful, @b false otherwise or if LibIDN + * is not available. + */ + bool saslprep( const std::string& input, std::string& out ); + /** * This function applies the idna() function to a string. I.e. it transforms * internationalized domain names into plain ASCII. * @param domain The string to convert. * @param out The converted string. In case of an error this string is not touched. * If LibIDN is not available the string is returned unchanged. - * @return @b True if prepping was successful, @b false otherwise or of LibIDN + * @return @b True if prepping was successful, @b false otherwise or if LibIDN * is not available. */ bool idna( const std::string& domain, std::string& out ); diff --git a/libs/libgloox/presence.cpp b/libs/libgloox/presence.cpp index 67c54a8..e55a35c 100644 --- a/libs/libgloox/presence.cpp +++ b/libs/libgloox/presence.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/presence.h b/libs/libgloox/presence.h index 1611181..0280ea0 100644 --- a/libs/libgloox/presence.h +++ b/libs/libgloox/presence.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -26,7 +26,7 @@ namespace gloox /** * @brief An abstraction of a presence stanza. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API Presence : public Stanza diff --git a/libs/libgloox/presencehandler.h b/libs/libgloox/presencehandler.h index 8e727e3..4106de0 100644 --- a/libs/libgloox/presencehandler.h +++ b/libs/libgloox/presencehandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -25,7 +25,7 @@ namespace gloox * * Derived classes can be registered as PresenceHandlers with the Client. * Upon an incoming Presence packet @ref handlePresence() will be called. - * @author Jakob Schroeter + * @author Jakob Schröter */ class GLOOX_API PresenceHandler { diff --git a/libs/libgloox/privacyitem.cpp b/libs/libgloox/privacyitem.cpp index e2f6f02..bfd0529 100644 --- a/libs/libgloox/privacyitem.cpp +++ b/libs/libgloox/privacyitem.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/privacyitem.h b/libs/libgloox/privacyitem.h index 727b982..d22620b 100644 --- a/libs/libgloox/privacyitem.h +++ b/libs/libgloox/privacyitem.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -26,7 +26,7 @@ namespace gloox * @brief This is an abstraction of a single item of a privacy list, describing an allowed or * forbidden action. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.3 */ class GLOOX_API PrivacyItem diff --git a/libs/libgloox/privacylisthandler.h b/libs/libgloox/privacylisthandler.h index 7a5c167..68a1d01 100644 --- a/libs/libgloox/privacylisthandler.h +++ b/libs/libgloox/privacylisthandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -44,7 +44,7 @@ namespace gloox /** * @brief A virtual interface that allows to retrieve Privacy Lists. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.3 */ class GLOOX_API PrivacyListHandler diff --git a/libs/libgloox/privacymanager.cpp b/libs/libgloox/privacymanager.cpp index f7e8fc8..4389230 100644 --- a/libs/libgloox/privacymanager.cpp +++ b/libs/libgloox/privacymanager.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/privacymanager.h b/libs/libgloox/privacymanager.h index 84d8f69..9b7a961 100644 --- a/libs/libgloox/privacymanager.h +++ b/libs/libgloox/privacymanager.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -28,7 +28,7 @@ namespace gloox /** * @brief This class implements a manager for privacy lists as defined in section 10 of RFC 3921. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.3 */ class GLOOX_API PrivacyManager : public IqHandler diff --git a/libs/libgloox/privatexml.cpp b/libs/libgloox/privatexml.cpp index ada2a2a..fea3697 100644 --- a/libs/libgloox/privatexml.cpp +++ b/libs/libgloox/privatexml.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/privatexml.h b/libs/libgloox/privatexml.h index b0e00f3..3f5d0a9 100644 --- a/libs/libgloox/privatexml.h +++ b/libs/libgloox/privatexml.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -30,9 +30,9 @@ namespace gloox class Stanza; /** - * @brief This class implements XEP-0049 (Private XML Storage). + * @brief This class implements @xep{0049} (Private XML Storage). * - * @author Jakob Schroeter + * @author Jakob Schröter */ class GLOOX_API PrivateXML : public IqHandler { @@ -84,7 +84,7 @@ namespace gloox /** * @brief An implementation of the Private XML Storage protocol as StanzaExtension. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class Query : public StanzaExtension diff --git a/libs/libgloox/privatexmlhandler.h b/libs/libgloox/privatexmlhandler.h index 1a315d3..b20cc1a 100644 --- a/libs/libgloox/privatexmlhandler.h +++ b/libs/libgloox/privatexmlhandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -30,7 +30,7 @@ namespace gloox * Derived classes can be registered as PrivateXMLHandlers with the PrivateXML object. * Upon an incoming PrivateXML packet @ref handlePrivateXML() will be called. * - * @author Jakob Schroeter + * @author Jakob Schröter */ class GLOOX_API PrivateXMLHandler { diff --git a/libs/libgloox/pubsub.h b/libs/libgloox/pubsub.h index dd06a8d..9f5c9ae 100644 --- a/libs/libgloox/pubsub.h +++ b/libs/libgloox/pubsub.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -128,7 +128,7 @@ namespace gloox }; /** - * Describes the different PubSub features (XEP-0060 Sect. 10). + * Describes the different PubSub features (@xep{0060} Sect. 10). */ enum PubSubFeature { diff --git a/libs/libgloox/pubsubevent.cpp b/libs/libgloox/pubsubevent.cpp index 2ae86b8..d70985a 100644 --- a/libs/libgloox/pubsubevent.cpp +++ b/libs/libgloox/pubsubevent.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/pubsubevent.h b/libs/libgloox/pubsubevent.h index 10227bd..574e632 100644 --- a/libs/libgloox/pubsubevent.h +++ b/libs/libgloox/pubsubevent.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/pubsubitem.cpp b/libs/libgloox/pubsubitem.cpp index a8e995a..b35508f 100644 --- a/libs/libgloox/pubsubitem.cpp +++ b/libs/libgloox/pubsubitem.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/pubsubitem.h b/libs/libgloox/pubsubitem.h index 00406f3..893d169 100644 --- a/libs/libgloox/pubsubitem.h +++ b/libs/libgloox/pubsubitem.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -27,11 +27,11 @@ namespace gloox { /** - * @brief Abstracts a PubSub Item (XEP-0060). + * @brief Abstracts a PubSub Item (@xep{0060}). * * XEP Version: 1.12 * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API Item diff --git a/libs/libgloox/pubsubmanager.cpp b/libs/libgloox/pubsubmanager.cpp index 9742ea1..a32246b 100644 --- a/libs/libgloox/pubsubmanager.cpp +++ b/libs/libgloox/pubsubmanager.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -343,8 +343,21 @@ namespace gloox if( o ) { if( m_ctx == InvalidContext ) - m_ctx = GetSubscriptionOptions; - m_jid.setJID( o->findAttribute( "jid" ) ); + { + Tag* parent = tag->parent(); + if( parent && parent->findAttribute("type") == "set" ) + m_ctx = SetSubscriptionOptions; + else + m_ctx = GetSubscriptionOptions; + } + if( m_ctx == SetSubscriptionOptions || m_ctx == GetSubscriptionOptions ) + { + // We set both m_node and m_options.node for + // get/set options, since m_options.node is not exposed externally + m_node = o->findAttribute( "node" ); + m_jid.setJID( o->findAttribute( "jid" ) ); + m_subid = o->findAttribute( "subid" ); + } m_options.node = o->findAttribute( "node" ); m_options.df = new DataForm( o->findChild( "x", "xmlns", XMLNS_X_DATA ) ); } @@ -389,7 +402,7 @@ namespace gloox m_ctx = DeleteItem; m_node = r->findAttribute( "node" ); m_notify = r->hasAttribute( "notify", "1" ) || r->hasAttribute( "notify", "true" ); - const TagList& l = p->children(); + const TagList& l = r->children(); TagList::const_iterator it = l.begin(); for( ; it != l.end(); ++it ) m_items.push_back( new Item( (*it) ) ); @@ -475,12 +488,13 @@ namespace gloox u->addAttribute( "subid", m_subid ); } else if( m_ctx == GetSubscriptionOptions - || m_ctx == SetSubscriptionOptions - || ( m_ctx == Subscription && m_options.df ) ) + || m_ctx == SetSubscriptionOptions ) { Tag* o = new Tag( t, "options" ); o->addAttribute( "node", m_options.node ); o->addAttribute( "jid", m_jid.full() ); + if( !m_subid.empty() ) + o->addAttribute( "subid", m_subid ); if( m_options.df ) o->addChild( m_options.df->tag() ); } @@ -594,22 +608,18 @@ namespace gloox if( !m_parent || !handler || !service || node.empty() ) return EmptyString; - const std::string& id = m_parent->getID(); - IQ iq( IQ::Set, service, id ); - PubSub* ps = new PubSub( Subscription ); - ps->setJID( jid ? jid : m_parent->jid() ); - ps->setNode( node ); + DataForm* options = 0; if( type != SubscriptionNodes || depth != 1 ) { - DataForm* df = new DataForm( TypeSubmit ); - df->addField( DataFormField::TypeHidden, "FORM_TYPE", XMLNS_PUBSUB_SUBSCRIBE_OPTIONS ); + options = new DataForm( TypeSubmit ); + options->addField( DataFormField::TypeHidden, "FORM_TYPE", XMLNS_PUBSUB_SUBSCRIBE_OPTIONS ); if( type == SubscriptionItems ) - df->addField( DataFormField::TypeNone, "pubsub#subscription_type", "items" ); + options->addField( DataFormField::TypeNone, "pubsub#subscription_type", "items" ); if( depth != 1 ) { - DataFormField* field = df->addField( DataFormField::TypeNone, "pubsub#subscription_depth" ); + DataFormField* field = options->addField( DataFormField::TypeNone, "pubsub#subscription_depth" ); if( depth == 0 ) field->setValue( "all" ); else @@ -618,12 +628,31 @@ namespace gloox if( !expire.empty() ) { - DataFormField* field = df->addField( DataFormField::TypeNone, "pubsub#expire" ); + DataFormField* field = options->addField( DataFormField::TypeNone, "pubsub#expire" ); field->setValue( expire ); } - - ps->setOptions( node, df ); } + + return subscribe( service, node, handler, jid, options ); + } + + const std::string Manager::subscribe( const JID& service, + const std::string& node, + ResultHandler* handler, + const JID& jid, + DataForm* options + ) + { + if( !m_parent || !handler || !service || node.empty() ) + return EmptyString; + + const std::string& id = m_parent->getID(); + IQ iq( IQ::Set, service, id ); + PubSub* ps = new PubSub( Subscription ); + ps->setJID( jid ? jid : m_parent->jid() ); + ps->setNode( node ); + if( options != NULL ) + ps->setOptions( node, options ); iq.addExtension( ps ); m_trackMapMutex.lock(); @@ -664,7 +693,8 @@ namespace gloox const JID& jid, const std::string& node, ResultHandler* handler, - DataForm* df ) + DataForm* df, + const std::string& subid ) { if( !m_parent || !handler || !service ) return EmptyString; @@ -673,6 +703,8 @@ namespace gloox IQ iq( df ? IQ::Set : IQ::Get, service, id ); PubSub* ps = new PubSub( context ); ps->setJID( jid ? jid : m_parent->jid() ); + if( !subid.empty() ) + ps->setSubscriptionID( subid ); ps->setOptions( node, df ); iq.addExtension( ps ); @@ -1041,12 +1073,9 @@ namespace gloox case PublishItem: { const PubSub* ps = iq.findExtension( ExtPubSub ); - if( ps && ps->items().size()) - { - const ItemList il = ps->items(); - rh->handleItemPublication( id, service, "", - il, error ); - } + rh->handleItemPublication( id, service, "", + ps ? ps->items() : ItemList(), + error ); break; } case DeleteItem: @@ -1094,6 +1123,7 @@ namespace gloox ps->jid(), ps->node(), ps->options(), + ps->subscriptionID(), error ); } break; @@ -1123,8 +1153,22 @@ namespace gloox switch( context ) { case SetSubscriptionOptions: - rh->handleSubscriptionOptionsResult( id, service, JID( /* FIXME */ ), node, error ); + { + const PubSub* ps = iq.findExtension( ExtPubSub ); + if( ps ) + { + rh->handleSubscriptionOptionsResult( id, service, + ps->jid(), + node, + ps->subscriptionID(), + error ); + } + else + { + rh->handleSubscriptionOptionsResult( id, service, JID( /* FIXME */ ), node, /* FIXME */ EmptyString, error ); + } break; + } case SetSubscriberList: rh->handleSubscribersResult( id, service, node, 0, error ); break; diff --git a/libs/libgloox/pubsubmanager.h b/libs/libgloox/pubsubmanager.h index 4c448b1..66a93ff 100644 --- a/libs/libgloox/pubsubmanager.h +++ b/libs/libgloox/pubsubmanager.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -32,7 +32,7 @@ namespace gloox class ResultHandler; /** - * @brief This manager is used to interact with PubSub services (XEP-0060). + * @brief This manager is used to interact with PubSub services (@xep{0060}). * * @note PubSub support in gloox is still relatively young and you are most * welcome to ask questions, criticize the API and so on. @@ -70,7 +70,7 @@ namespace gloox * * XEP Version: 1.12 * - * @author Jakob Schroeter + * @author Jakob Schröter * @author Vincent Thomasset * * @since 1.0 @@ -110,6 +110,27 @@ namespace gloox SubscriptionObject type = SubscriptionNodes, int depth = 1, const std::string& expire = EmptyString ); + /** + * Subscribe to a node and configure options. + * + * @param service Service hosting the node. + * @param node ID of the node to subscribe to. + * @param handler The ResultHandler. + * @param jid JID to subscribe. If empty, the client's JID will be used + * (ie. self subscription). + * @param options The options to configure while subscribing. + * Should be a TypeSubmit form, with a field named FORM_TYPE having the value + * http://jabber.org/protocol/pubsub#subscribe_options + * See @xep{0060}, "Subscribe and Configure". + * Will be owned and deleted by the PubSub object. + * @return The IQ ID used in the request. + * + * @see ResultHandler::handleSubscriptionResult + */ + const std::string subscribe( const JID& service, const std::string& node, + ResultHandler* handler, const JID& jid, + DataForm* options ); + /** * Unsubscribe from a node. * @@ -170,6 +191,7 @@ namespace gloox * @param jid Subscribed entity. * @param node Node ID of the node. * @param handler The SubscriptionListHandler to handle the result. + * @param subid An optional subscription ID. * @return The IQ ID used in the request. * * @see ResultHandler::handleSubscriptionOptions @@ -177,8 +199,9 @@ namespace gloox const std::string getSubscriptionOptions( const JID& service, const JID& jid, const std::string& node, - ResultHandler* handler) - { return subscriptionOptions( GetSubscriptionOptions, service, jid, node, handler, 0 ); } + ResultHandler* handler, + const std::string& subid = EmptyString) + { return subscriptionOptions( GetSubscriptionOptions, service, jid, node, handler, 0, subid ); } /** * Modifies subscription options. @@ -188,6 +211,7 @@ namespace gloox * @param node Node ID of the node. * @param df New configuration. The DataForm will be owned and deleted by the Manager. * @param handler The handler to handle the result. + * @param subid An optional subscription ID. * @return The IQ ID used in the request. * * @see ResultHandler::handleSubscriptionOptionsResult @@ -196,8 +220,9 @@ namespace gloox const JID& jid, const std::string& node, DataForm* df, - ResultHandler* handler ) - { return subscriptionOptions( SetSubscriptionOptions, service, jid, node, handler, df ); } + ResultHandler* handler, + const std::string& subid = EmptyString ) + { return subscriptionOptions( SetSubscriptionOptions, service, jid, node, handler, df, subid ); } /** * Requests the affiliation list for a node. @@ -660,6 +685,8 @@ namespace gloox void setOptions( const std::string& node, DataForm* df ) { m_options.node = node; + if( m_options.df != 0 ) + delete m_options.df; m_options.df = df; } @@ -803,7 +830,8 @@ namespace gloox const JID& jid, const std::string& node, ResultHandler* handler, - DataForm* df ); + DataForm* df, + const std::string& subid = EmptyString ); const std::string getSubscriptionsOrAffiliations( const JID& service, ResultHandler* handler, diff --git a/libs/libgloox/pubsubresulthandler.h b/libs/libgloox/pubsubresulthandler.h index 174febc..a11158f 100644 --- a/libs/libgloox/pubsubresulthandler.h +++ b/libs/libgloox/pubsubresulthandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -160,6 +160,7 @@ namespace gloox * @param jid Subscribed entity. * @param node ID of the node. * @param options Options DataForm. + * @param sid An optional subscription ID. * @param error Subscription options retrieval Error. * * @see Manager::getSubscriptionOptions @@ -169,6 +170,7 @@ namespace gloox const JID& jid, const std::string& node, const DataForm* options, + const std::string& sid = EmptyString, const Error* error = 0 ) = 0; /** @@ -178,6 +180,7 @@ namespace gloox * @param service Service hosting the queried node. * @param jid Subscribed entity. * @param node ID of the queried node. + * @param sid An optional subscription ID. * @param error Subscription options modification Error. * * @see Manager::setSubscriptionOptions @@ -186,6 +189,7 @@ namespace gloox const JID& service, const JID& jid, const std::string& node, + const std::string& sid = EmptyString, const Error* error = 0 ) = 0; diff --git a/libs/libgloox/receipt.cpp b/libs/libgloox/receipt.cpp index 99cfba7..3b4780d 100644 --- a/libs/libgloox/receipt.cpp +++ b/libs/libgloox/receipt.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -29,9 +29,13 @@ namespace gloox } Receipt::Receipt( const Tag* tag ) - : StanzaExtension( ExtReceipt ), - m_rcpt( receiptType( tag->name() ) ) + : StanzaExtension( ExtReceipt ), m_rcpt( Invalid ) { + if( !tag ) + return; + + m_rcpt = receiptType( tag->name() ); + m_id = tag->findAttribute( "id" ); } const std::string& Receipt::filterString() const @@ -47,7 +51,10 @@ namespace gloox if( m_rcpt == Invalid ) return 0; - return new Tag( util::lookup( m_rcpt, receiptValues ), XMLNS, XMLNS_RECEIPTS ); + Tag* tag = new Tag( util::lookup( m_rcpt, receiptValues ), XMLNS, XMLNS_RECEIPTS ); + if ( !m_id.empty() ) + tag->addAttribute( "id", m_id ); + return tag; } } diff --git a/libs/libgloox/receipt.h b/libs/libgloox/receipt.h index 21141d5..dcf65cc 100644 --- a/libs/libgloox/receipt.h +++ b/libs/libgloox/receipt.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -24,16 +24,16 @@ namespace gloox class Tag; /** - * @brief An implementation of Message Receipts (XEP-0184) as a StanzaExtension. + * @brief An implementation of Message Receipts (@xep{0184}) as a StanzaExtension. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API Receipt : public StanzaExtension { public: /** - * Contains valid receipt types (XEP-0184). + * Contains valid receipt types (@xep{0184}). */ enum ReceiptType { @@ -51,9 +51,10 @@ namespace gloox /** * Constructs a new object of the given type. * @param rcpt The receipt type. + * @param id The message ID. */ - Receipt( ReceiptType rcpt ) - : StanzaExtension( ExtReceipt ), m_rcpt( rcpt ) + Receipt( ReceiptType rcpt, const std::string& id = EmptyString ) + : StanzaExtension( ExtReceipt ), m_rcpt( rcpt ), m_id( id ) {} /** @@ -67,6 +68,12 @@ namespace gloox */ ReceiptType rcpt() const { return m_rcpt; } + /** + * Returns the message id for acknowledgement tracking. + * @return The message ID for acknowledgement tracking. + */ + std::string id() const { return m_id; } + // reimplemented from StanzaExtension virtual const std::string& filterString() const; @@ -87,6 +94,7 @@ namespace gloox private: ReceiptType m_rcpt; + std::string m_id; }; diff --git a/libs/libgloox/registration.cpp b/libs/libgloox/registration.cpp index c5f900a..ad7eaa6 100644 --- a/libs/libgloox/registration.cpp +++ b/libs/libgloox/registration.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/registration.h b/libs/libgloox/registration.h index 3fef509..fac0c09 100644 --- a/libs/libgloox/registration.h +++ b/libs/libgloox/registration.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -31,7 +31,7 @@ namespace gloox /** * Holds all the possible fields a server may require for registration according - * to Section 14.1, XEP-0077. + * to Section 14.1, @xep{0077}. */ struct RegistrationFields { @@ -54,7 +54,7 @@ namespace gloox }; /** - * @brief This class is an implementation of XEP-0077 (In-Band Registration). + * @brief This class is an implementation of @xep{0077} (In-Band Registration). * * Derive your object from @ref RegistrationHandler and implement the * virtual functions offered by that interface. Then use it like this: @@ -86,7 +86,7 @@ namespace gloox * * Check @c tests/register_test.cpp for an example. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.2 */ class GLOOX_API Registration : public IqHandler @@ -94,32 +94,32 @@ namespace gloox public: /** - * The possible fields of a XEP-0077 account registration. + * The possible fields of a @xep{0077} account registration. */ enum fieldEnum { - FieldUsername = 1, - FieldNick = 2, - FieldPassword = 4, - FieldName = 8, - FieldFirst = 16, - FieldLast = 32, - FieldEmail = 64, - FieldAddress = 128, - FieldCity = 256, - FieldState = 512, - FieldZip = 1024, - FieldPhone = 2048, - FieldUrl = 4096, - FieldDate = 8192, - FieldMisc = 16384, - FieldText = 32768 + FieldUsername = 1, /**< Username requested */ + FieldNick = 2, /**< Nickname requested */ + FieldPassword = 4, /**< Password requested */ + FieldName = 8, /**< Name requested */ + FieldFirst = 16, /**< Given name requested */ + FieldLast = 32, /**< Family name requested */ + FieldEmail = 64, /**< Email address requested */ + FieldAddress = 128, /**< Postal address requested */ + FieldCity = 256, /**< Locality requested */ + FieldState = 512, /**< State/Province requested */ + FieldZip = 1024, /**< ZIP requested */ + FieldPhone = 2048, /**< Phone no. requested */ + FieldUrl = 4096, /**< Homepage or other URL requested */ + FieldDate = 8192, /**< Date requested (unknown purpose; see @xep{0077}) */ + FieldMisc = 16384, /**< Misc data requested (unknown purpose; see @xep{0077}) */ + FieldText = 32768 /**< Extra text requested (unknown purpose; see @xep{0077}) */ }; /** - * @brief A wrapping class for the XEP-0077 <query> element. + * @brief A wrapping class for the @xep{0077} <query> element. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class Query : public StanzaExtension @@ -276,7 +276,7 @@ namespace gloox /** * Attempts to register an account with the given credentials. This can only be called with an * unauthenticated parent (@ref Client). - * @note According to XEP-0077, if the server sends both old-style fields and data form, + * @note According to @xep{0077}, if the server sends both old-style fields and data form, * implementations SHOULD prefer data forms. * @param form The DataForm containing the registration credentials. */ diff --git a/libs/libgloox/registrationhandler.h b/libs/libgloox/registrationhandler.h index f7422ad..d3781ac 100644 --- a/libs/libgloox/registrationhandler.h +++ b/libs/libgloox/registrationhandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -27,7 +27,7 @@ namespace gloox class DataForm; /** - * Possible results of a XEP-0077 operation. + * Possible results of a @xep{0077} operation. */ enum RegistrationResult { @@ -71,7 +71,7 @@ namespace gloox * Registration object. Incoming results for operations initiated through * the Registration object are forwarded to this handler. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.2 */ class GLOOX_API RegistrationHandler diff --git a/libs/libgloox/resource.h b/libs/libgloox/resource.h index c209d25..713d6ee 100644 --- a/libs/libgloox/resource.h +++ b/libs/libgloox/resource.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -29,7 +29,7 @@ namespace gloox * * This holds the information of a single resource of a contact that is online. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.8 */ class GLOOX_API Resource diff --git a/libs/libgloox/rosteritem.cpp b/libs/libgloox/rosteritem.cpp index bfd0e8a..a46dc23 100644 --- a/libs/libgloox/rosteritem.cpp +++ b/libs/libgloox/rosteritem.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -19,8 +19,10 @@ namespace gloox { + JID EmptyJID(); + RosterItem::RosterItem( const std::string& jid, const std::string& name ) - : m_data( new RosterItemData( jid, name, StringList() ) ) + : m_data( new RosterItemData( JID( jid ), name, StringList() ) ) { } @@ -49,6 +51,14 @@ namespace gloox return EmptyString; } + const JID& RosterItem::jidJID() const + { + if( m_data ) + return m_data->jidJID(); + else + return EmptyJID; + } + const std::string& RosterItem::jid() const { if( m_data ) diff --git a/libs/libgloox/rosteritem.h b/libs/libgloox/rosteritem.h index 27597c3..b9180b6 100644 --- a/libs/libgloox/rosteritem.h +++ b/libs/libgloox/rosteritem.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -14,6 +14,7 @@ #ifndef ROSTERITEM_H__ #define ROSTERITEM_H__ +#include "jid.h" #include "gloox.h" #include "resource.h" #include "presence.h" @@ -33,7 +34,7 @@ namespace gloox * For each RosterItem all resources that are available (online in some way) are stored in * a ResourceMap. This map is accessible using the resources() function. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.3 */ class GLOOX_API RosterItem @@ -46,6 +47,11 @@ namespace gloox */ typedef std::map ResourceMap; + /** + * An empty string. + */ + const JID EmptyJID; + /** * Constructs a new item of the roster. * @param jid The JID of the contact. @@ -80,8 +86,16 @@ namespace gloox /** * Returns the contact's bare JID. * @return The contact's bare JID. + * @deprecated Use jidJID() for now. In 1.1, jidJID() will be renamed back to jid(). */ - const std::string& jid() const; + GLOOX_DEPRECATED const std::string& jid() const; + + /** + * Returns the contact's bare JID. + * @return The contact's bare JID. + * @todo Rename to jid() for 1.1. + */ + const JID& jidJID() const; /** * Sets the current subscription status of the contact. diff --git a/libs/libgloox/rosteritemdata.h b/libs/libgloox/rosteritemdata.h index cd5e9a6..2aa4355 100644 --- a/libs/libgloox/rosteritemdata.h +++ b/libs/libgloox/rosteritemdata.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -30,7 +30,7 @@ namespace gloox * * You should not need to use this class directly. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API RosterItemData @@ -43,9 +43,9 @@ namespace gloox * @param name The displayed name of the contact. * @param groups A list of groups the contact belongs to. */ - RosterItemData( const std::string& jid, const std::string& name, + RosterItemData( const JID& jid, const std::string& name, const StringList& groups ) - : m_jid( jid ), m_name( name ), m_groups( groups ), + : m_jid( jid.full() ), m_jidJID( jid ), m_name( name ), m_groups( groups ), m_subscription( S10nNone ), m_changed( false ), m_remove( false ) {} @@ -53,8 +53,41 @@ namespace gloox * Constructs a new item of the roster, scheduled for removal. * @param jid The JID of the contact to remove. */ - RosterItemData( const std::string& jid ) - : m_jid( jid ), m_subscription( S10nNone ), m_changed( false ), + RosterItemData( const JID& jid ) + : m_jid( jid.full() ), m_jidJID( jid ), m_subscription( S10nNone ), m_changed( false ), + m_remove( true ) + {} + + /** + * Copy constructor. + * @param right The RosterItemData to copy. + */ + RosterItemData( const RosterItemData& right ) + : m_jid( right.m_jid ), m_jidJID( right.m_jidJID ), m_name( right.m_name ), + m_groups( right.m_groups ), m_subscription( right.m_subscription ), + m_changed( right.m_changed ), m_remove( right.m_remove ) + {} + + /** + * Constructs a new item of the roster. + * @param jid The JID of the contact. + * @param name The displayed name of the contact. + * @param groups A list of groups the contact belongs to. + * @deprecated Will be removed for 1.1. + */ + GLOOX_DEPRECATED_CTOR RosterItemData( const std::string& jid, const std::string& name, + const StringList& groups ) + : m_jid( jid ), m_jidJID( jid), m_name( name ), m_groups( groups ), + m_subscription( S10nNone ), m_changed( false ), m_remove( false ) + {} + + /** + * Constructs a new item of the roster, scheduled for removal. + * @param jid The JID of the contact to remove. + * @deprecated Will be removed for 1.1. + */ + GLOOX_DEPRECATED_CTOR RosterItemData( const std::string& jid ) + : m_jid( jid ), m_jidJID( jid), m_subscription( S10nNone ), m_changed( false ), m_remove( true ) {} @@ -66,8 +99,16 @@ namespace gloox /** * Returns the contact's bare JID. * @return The contact's bare JID. + * @deprecated Will be removed for 1.1. */ - const std::string& jid() const { return m_jid; } + GLOOX_DEPRECATED const std::string& jid() const { return m_jid; } + + /** + * Returns the contact's bare JID. + * @return The contact's bare JID. + * @todo Rename to jid() for 1.1. + */ + const JID& jidJID() const { return m_jidJID; } /** * Sets the displayed name of a contact/roster item. @@ -158,7 +199,7 @@ namespace gloox Tag* tag() const { Tag* i = new Tag( "item" ); - i->addAttribute( "jid", m_jid ); + i->addAttribute( "jid", m_jidJID.full() ); if( m_remove ) i->addAttribute( "subscription", "remove" ); else @@ -174,7 +215,8 @@ namespace gloox } protected: - std::string m_jid; + GLOOX_DEPRECATED std::string m_jid; /**< @deprecated Will be removed for 1.1. */ + JID m_jidJID; /**< @todo Rename to m_jid for 1.1. */ std::string m_name; StringList m_groups; SubscriptionType m_subscription; diff --git a/libs/libgloox/rosterlistener.h b/libs/libgloox/rosterlistener.h index ce93777..a6c40d6 100644 --- a/libs/libgloox/rosterlistener.h +++ b/libs/libgloox/rosterlistener.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -37,7 +37,7 @@ namespace gloox * RosterManager object receives notifications about all the changes in the server-side * roster. Only one RosterListener per Roster at a time is possible. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.3 */ class GLOOX_API RosterListener diff --git a/libs/libgloox/rostermanager.cpp b/libs/libgloox/rostermanager.cpp index 207d11e..c46120d 100644 --- a/libs/libgloox/rostermanager.cpp +++ b/libs/libgloox/rostermanager.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -30,13 +30,13 @@ namespace gloox RosterManager::Query::Query( const JID& jid, const std::string& name, const StringList& groups ) : StanzaExtension( ExtRoster ) { - m_roster.push_back( new RosterItemData( jid.bare(), name, groups ) ); + m_roster.push_back( new RosterItemData( jid, name, groups ) ); } RosterManager::Query::Query( const JID& jid ) : StanzaExtension( ExtRoster ) { - m_roster.push_back( new RosterItemData( jid.bare() ) ); + m_roster.push_back( new RosterItemData( jid ) ); } RosterManager::Query::Query( const Tag* tag ) @@ -57,10 +57,10 @@ namespace gloox const std::string sub = (*it)->findAttribute( "subscription" ); if( sub == "remove" ) - m_roster.push_back( new RosterItemData( (*it)->findAttribute( "jid" ) ) ); + m_roster.push_back( new RosterItemData( JID( (*it)->findAttribute( "jid" ) ) ) ); else { - RosterItemData* rid = new RosterItemData( (*it)->findAttribute( "jid" ), + RosterItemData* rid = new RosterItemData( JID( (*it)->findAttribute( "jid" ) ), (*it)->findAttribute( "name" ), groups ); rid->setSubscription( sub, (*it)->findAttribute( "ask" ) ); @@ -203,7 +203,7 @@ namespace gloox bool self = false; Roster::iterator it = m_roster.find( presence.from().bare() ); - if( it != m_roster.end() || ( self = ( presence.from().bare() == m_self->jid() ) ) ) + if( it != m_roster.end() || ( self = ( presence.from().bareJID() == m_self->jidJID() ) ) ) { RosterItem* ri = self ? m_self : (*it).second; const std::string& resource = presence.from().resource(); @@ -288,7 +288,7 @@ namespace gloox continue; IQ iq( IQ::Set, JID(), m_parent->getID() ); - iq.addExtension( new Query( (*it).second->jid(), (*it).second->name(), (*it).second->groups() ) ); + iq.addExtension( new Query( (*it).second->jidJID(), (*it).second->name(), (*it).second->groups() ) ); m_parent->send( iq, this, SynchronizeRoster ); } } @@ -385,13 +385,13 @@ namespace gloox RosterData::const_iterator it = data.begin(); for( ; it != data.end(); ++it ) { - Roster::iterator itr = m_roster.find( (*it)->jid() ); + Roster::iterator itr = m_roster.find( (*it)->jidJID().full() ); if( itr != m_roster.end() ) { if( (*it)->remove() ) { if( m_rosterListener ) - m_rosterListener->handleItemRemoved( (*it)->jid() ); + m_rosterListener->handleItemRemoved( (*it)->jidJID().full() ); delete (*itr).second; m_roster.erase( itr ); } @@ -399,14 +399,14 @@ namespace gloox { (*itr).second->setData( *(*it) ); if( m_rosterListener ) - m_rosterListener->handleItemUpdated( (*it)->jid() ); + m_rosterListener->handleItemUpdated( (*it)->jidJID().full() ); } } else if( !(*it)->remove() ) { - m_roster.insert( std::make_pair( (*it)->jid(), new RosterItem( *(*it) ) ) ); + m_roster.insert( std::make_pair( (*it)->jidJID().full(), new RosterItem( *(*it) ) ) ); if( m_rosterListener ) - m_rosterListener->handleItemAdded( (*it)->jid() ); + m_rosterListener->handleItemAdded( (*it)->jidJID().full() ); } } } @@ -415,7 +415,7 @@ namespace gloox { RosterData::const_iterator it = data.begin(); for( ; it != data.end(); ++it ) - m_roster.insert( std::make_pair( (*it)->jid(), new RosterItem( *(*it) ) ) ); + m_roster.insert( std::make_pair( (*it)->jidJID().full(), new RosterItem( *(*it) ) ) ); } } diff --git a/libs/libgloox/rostermanager.h b/libs/libgloox/rostermanager.h index 0428873..d0da289 100644 --- a/libs/libgloox/rostermanager.h +++ b/libs/libgloox/rostermanager.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -39,9 +39,9 @@ namespace gloox * You can modify any number of RosterItems within the Roster at any time. These changes must be * synchronized with the server by calling @ref synchronize(). Note that incoming Roster pushes * initiated by other resources may overwrite changed values. - * Additionally, XEP-0083 (Nested Roster Groups) is implemented herein. + * Additionally, @xep{0083} (Nested Roster Groups) is implemented herein. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.3 */ class GLOOX_API RosterManager : public IqHandler, public PresenceHandler, public SubscriptionHandler, @@ -134,14 +134,14 @@ namespace gloox void ackSubscriptionRequest( const JID& to, bool ack ); /** - * Use this function to retrieve the delimiter of Nested Roster Groups (XEP-0083). + * Use this function to retrieve the delimiter of Nested Roster Groups (@xep{0083}). * @return The group delimiter. * @since 0.7 */ const std::string& delimiter() const { return m_delimiter; } /** - * Use this function to set the group delimiter (XEP-0083). + * Use this function to set the group delimiter (@xep{0083}). * @param delimiter The group delimiter. * @since 0.7 */ @@ -197,7 +197,7 @@ namespace gloox /** * @brief An implementation of StanzaExtension that helps in roster management. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class Query : public StanzaExtension diff --git a/libs/libgloox/search.cpp b/libs/libgloox/search.cpp index 097b529..9a1428d 100644 --- a/libs/libgloox/search.cpp +++ b/libs/libgloox/search.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -157,7 +157,7 @@ namespace gloox const std::string& id = m_parent->getID(); - IQ iq( IQ::Set, directory ); + IQ iq( IQ::Set, directory, id ); iq.addExtension( new Query( fields, values ) ); m_track[id] = sh; diff --git a/libs/libgloox/search.h b/libs/libgloox/search.h index 677305d..d25c061 100644 --- a/libs/libgloox/search.h +++ b/libs/libgloox/search.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -32,7 +32,7 @@ namespace gloox class Disco; /** - * @brief An implementation of XEP-0055 (Jabber Search) + * @brief An implementation of @xep{0055} (Jabber Search) * * To perform a search in a directory (e.g., a User Directory): * @@ -43,7 +43,7 @@ namespace gloox * @li Search by either using a DataForm or the SearchFieldStruct. * @li The results can be either a (empty) list of SearchFieldStructs or a DataForm. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.8.5 */ class GLOOX_API Search : public IqHandler @@ -113,9 +113,9 @@ namespace gloox public: #endif /** - * @brief A wrapping class for the XEP-0055 <query> element. + * @brief A wrapping class for the @xep{0055} <query> element. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class Query : public StanzaExtension diff --git a/libs/libgloox/searchhandler.h b/libs/libgloox/searchhandler.h index 1a790e4..07657d5 100644 --- a/libs/libgloox/searchhandler.h +++ b/libs/libgloox/searchhandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -25,9 +25,9 @@ namespace gloox /** * Holds all the possible fields a server may require for searching according - * to Section 7, XEP-0055. + * to Section 7, @xep{0055}. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class SearchFieldStruct @@ -118,7 +118,7 @@ namespace gloox }; /** - * The possible fields of a XEP-0055 user search. + * The possible fields of a @xep{0055} user search. */ enum SearchFieldEnum { @@ -134,11 +134,11 @@ namespace gloox typedef std::list SearchResultList; /** - * @brief A virtual interface that enables objects to receive Jabber Search (XEP-0055) results. + * @brief A virtual interface that enables objects to receive Jabber Search (@xep{0055}) results. * * A class implementing this interface can receive the result of a Jabber Search. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.8.5 */ class GLOOX_API SearchHandler diff --git a/libs/libgloox/sha.cpp b/libs/libgloox/sha.cpp index 6e0266e..9449497 100644 --- a/libs/libgloox/sha.cpp +++ b/libs/libgloox/sha.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -55,7 +55,8 @@ namespace gloox if( m_corrupted ) return EmptyString; - finalize(); + if( !m_finished ) + finalize(); char buf[41]; for( int i = 0; i < 20; ++i ) @@ -214,7 +215,7 @@ namespace gloox { Message_Block[Message_Block_Index++] = 0x80; - if( Message_Block_Index > 55 ) + if( Message_Block_Index > 56 ) { while( Message_Block_Index < 64 ) { diff --git a/libs/libgloox/sha.h b/libs/libgloox/sha.h index 0eabd5e..563e4e7 100644 --- a/libs/libgloox/sha.h +++ b/libs/libgloox/sha.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -23,7 +23,7 @@ namespace gloox /** * @brief An implementation of SHA1. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API SHA diff --git a/libs/libgloox/shim.cpp b/libs/libgloox/shim.cpp index 2aa1dc1..239424b 100644 --- a/libs/libgloox/shim.cpp +++ b/libs/libgloox/shim.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/shim.h b/libs/libgloox/shim.h index fbe0197..5a6ec19 100644 --- a/libs/libgloox/shim.h +++ b/libs/libgloox/shim.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -25,11 +25,11 @@ namespace gloox class Tag; /** - * @brief An implementation/abstraction of Stanza Headers and Internet Metadata (SHIM, XEP-0131). + * @brief An implementation/abstraction of Stanza Headers and Internet Metadata (SHIM, @xep{0131}). * * XEP Version: 1.2 * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API SHIM : public StanzaExtension diff --git a/libs/libgloox/sihandler.h b/libs/libgloox/sihandler.h index c0c69dd..2b12df8 100644 --- a/libs/libgloox/sihandler.h +++ b/libs/libgloox/sihandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -33,7 +33,7 @@ namespace gloox * You should usually not need to use this class directly, unless your profile is not supported * by gloox. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API SIHandler diff --git a/libs/libgloox/simanager.cpp b/libs/libgloox/simanager.cpp index 0162c6d..b2a6e99 100644 --- a/libs/libgloox/simanager.cpp +++ b/libs/libgloox/simanager.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/simanager.h b/libs/libgloox/simanager.h index ace715a..3cbae53 100644 --- a/libs/libgloox/simanager.h +++ b/libs/libgloox/simanager.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -24,11 +24,11 @@ namespace gloox class SIHandler; /** - * @brief This class manages streams initiated using XEP-0095. + * @brief This class manages streams initiated using @xep{0095}. * * You need only one SIManager object per ClientBase instance. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API SIManager : public IqHandler @@ -148,11 +148,11 @@ namespace gloox * Starts negotiating a stream with a remote entity. * @param sih The SIHandler to handle the result of this request. * @param to The entity to talk to. - * @param profile The SI profile to use. See XEP-0095 for more info. + * @param profile The SI profile to use. See @xep{0095} for more info. * @param child1 The first of the two allowed children of the SI offer. See - * XEP-0095 for more info. + * @xep{0095} for more info. * @param child2 The second of the two allowed children of the SI offer. See - * XEP-0095 for more info. Defaults to 0. + * @xep{0095} for more info. Defaults to 0. * @param mimetype The stream's/file's mime-type. Defaults to 'binary/octet-stream'. * @param from An optional 'from' address to stamp outgoing requests with. * Used in component scenario only. Defaults to empty JID. @@ -170,8 +170,8 @@ namespace gloox * SIProfileHandler::handleSIRequest(). * @param to The requestor. * @param id The request's id, as passed to SIProfileHandler::handleSIRequest(). - * @param child1 The <feature/> child of the SI request. See XEP-0095 for details. - * @param child2 The profile-specific child of the SI request. May be 0. See XEP-0095 + * @param child1 The <feature/> child of the SI request. See @xep{0095} for details. + * @param child2 The profile-specific child of the SI request. May be 0. See @xep{0095} * for details. * @param from An optional 'from' address to stamp outgoing stanzas with. * Used in component scenario only. Defaults to empty JID. diff --git a/libs/libgloox/siprofileft.cpp b/libs/libgloox/siprofileft.cpp index aeafac4..765cb41 100644 --- a/libs/libgloox/siprofileft.cpp +++ b/libs/libgloox/siprofileft.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -84,11 +84,11 @@ namespace gloox DataFormField* dff = df.addField( DataFormField::TypeListSingle, "stream-method" ); StringMultiMap sm; if( streamTypes & FTTypeS5B ) - sm.insert( std::make_pair( "s5b", XMLNS_BYTESTREAMS ) ); + sm.insert( std::make_pair( "s5b", XMLNS_BYTESTREAMS ) ); if( streamTypes & FTTypeIBB ) - sm.insert( std::make_pair( "ibb", XMLNS_IBB ) ); + sm.insert( std::make_pair( "ibb", XMLNS_IBB ) ); if( streamTypes & FTTypeOOB ) - sm.insert( std::make_pair( "oob", XMLNS_IQ_OOB ) ); + sm.insert( std::make_pair( "oob", XMLNS_IQ_OOB ) ); dff->setOptions( sm ); feature->addChild( df.tag() ); diff --git a/libs/libgloox/siprofileft.h b/libs/libgloox/siprofileft.h index b83c859..6f4580f 100644 --- a/libs/libgloox/siprofileft.h +++ b/libs/libgloox/siprofileft.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -35,7 +35,7 @@ namespace gloox class SOCKS5Bytestream; /** - * @brief An implementation of the file transfer SI profile (XEP-0096). + * @brief An implementation of the file transfer SI profile (@xep{0096}). * * An SIProfileFT object acts as a 'plugin' to the SIManager. SIProfileFT * manages most of the file transfer functionality. The naming comes from the fact that @@ -144,7 +144,7 @@ namespace gloox * * For usage examples see src/examples/ft_send.cpp and src/examples/ft_recv.cpp. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API SIProfileFT : public SIProfileHandler, public SIHandler, @@ -190,7 +190,7 @@ namespace gloox * @param size The file's size. Mandatory and must be > 0. * @param hash The file content's MD5 hash. * @param desc A description. - * @param date The file's last modification date/time. See XEP-0082 for details. + * @param date The file's last modification date/time. See @xep{0082} for details. * @param mimetype The file's mime-type. Defaults to 'binary/octet-stream' if empty. * @param streamTypes ORed StreamType that can be used for this transfer. * @param from An optional 'from' address to stamp outgoing requests with. diff --git a/libs/libgloox/siprofilefthandler.h b/libs/libgloox/siprofilefthandler.h index 3a7c0f4..f133537 100644 --- a/libs/libgloox/siprofilefthandler.h +++ b/libs/libgloox/siprofilefthandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -30,7 +30,7 @@ namespace gloox * * See SIProfileFT for more information regarding file transfer. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API SIProfileFTHandler diff --git a/libs/libgloox/siprofilehandler.h b/libs/libgloox/siprofilehandler.h index 9af75b4..d2e0c3d 100644 --- a/libs/libgloox/siprofilehandler.h +++ b/libs/libgloox/siprofilehandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -31,7 +31,7 @@ namespace gloox * You should usually not need to use this class directly, unless your profile is not supported * by gloox. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API SIProfileHandler diff --git a/libs/libgloox/socks5bytestream.cpp b/libs/libgloox/socks5bytestream.cpp index e4d80b3..43dd342 100644 --- a/libs/libgloox/socks5bytestream.cpp +++ b/libs/libgloox/socks5bytestream.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -144,12 +144,17 @@ namespace gloox void SOCKS5Bytestream::handleConnect( const ConnectionBase* /*connection*/ ) { m_manager->acknowledgeStreamHost( true, m_proxy, m_sid ); + + if( !m_open ) + { + m_open = true; + m_handler->handleBytestreamOpen( this ); + } } void SOCKS5Bytestream::handleDisconnect( const ConnectionBase* /*connection*/, ConnectionError /*reason*/ ) { - if( m_handler && m_connected ) - m_handler->handleBytestreamClose( this ); + close(); } } diff --git a/libs/libgloox/socks5bytestream.h b/libs/libgloox/socks5bytestream.h index d2a6201..395d9de 100644 --- a/libs/libgloox/socks5bytestream.h +++ b/libs/libgloox/socks5bytestream.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -29,14 +29,14 @@ namespace gloox class LogSink; /** - * @brief An implementation of a single SOCKS5 Bytestream (XEP-0065). + * @brief An implementation of a single SOCKS5 Bytestream (@xep{0065}). * * One instance of this class handles one bytestream. * * See SOCKS5BytestreamManager for a detailed description on how to implement * SOCKS5 Bytestreams in your application. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API SOCKS5Bytestream : public ConnectionDataHandler, public Bytestream diff --git a/libs/libgloox/socks5bytestreammanager.cpp b/libs/libgloox/socks5bytestreammanager.cpp index e885688..8e3114a 100644 --- a/libs/libgloox/socks5bytestreammanager.cpp +++ b/libs/libgloox/socks5bytestreammanager.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/socks5bytestreammanager.h b/libs/libgloox/socks5bytestreammanager.h index 49fbebb..eaee066 100644 --- a/libs/libgloox/socks5bytestreammanager.h +++ b/libs/libgloox/socks5bytestreammanager.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -45,7 +45,7 @@ namespace gloox /** * @brief An SOCKS5BytestreamManager dispatches SOCKS5 Bytestreams. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API SOCKS5BytestreamManager : public IqHandler @@ -101,7 +101,7 @@ namespace gloox * without waiting for success. * @param to The recipient of the requested bytestream. * @param mode The desired transport layer protocol. - * @param sid The bytestream's stream ID, if previously negotiated e.g. using SI (XEP-0095). + * @param sid The bytestream's stream ID, if previously negotiated e.g. using SI (@xep{0095}). * @param from An optional 'from' address to stamp outgoing * requests with. Only useful in component scenarios. Defaults to empty JID. * @return @b False in case of an error, @b true otherwise. A return value of @b true does diff --git a/libs/libgloox/socks5bytestreamserver.cpp b/libs/libgloox/socks5bytestreamserver.cpp index 55f5fcc..de54a28 100644 --- a/libs/libgloox/socks5bytestreamserver.cpp +++ b/libs/libgloox/socks5bytestreamserver.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -12,7 +12,6 @@ #include "socks5bytestreamserver.h" -#include "connectiontcpserver.h" #include "mutexguard.h" #include "util.h" @@ -30,10 +29,15 @@ namespace gloox { if( m_tcpServer ) delete m_tcpServer; + m_tcpServer = 0; + m_mutex.lock(); ConnectionMap::const_iterator it = m_connections.begin(); for( ; it != m_connections.end(); ++it ) delete (*it).first; + m_connections.clear(); + util::clearList( m_oldConnections ); + m_mutex.unlock(); } ConnectionError SOCKS5BytestreamServer::listen() @@ -53,15 +57,26 @@ namespace gloox if( ce != ConnNoError ) return ce; - ConnectionMap::const_iterator it = m_connections.begin(); - ConnectionMap::const_iterator it2; - while( it != m_connections.end() ) - { - it2 = it++; - (*it2).first->recv( timeout ); - } + // First take a snapshot of our connections, and then iterate the snapshot + // (so that the live map can be modified by an erase while we + // iterate the snapshot of the map) + ConnectionMap connectionsSnapshot; + m_mutex.lock(); + connectionsSnapshot.insert( m_connections.begin(), m_connections.end() ); + m_mutex.unlock(); + + ConnectionMap::const_iterator it = connectionsSnapshot.begin(); + for( ; it != connectionsSnapshot.end(); ++it ) + { + (*it).first->recv( timeout ); + } + connectionsSnapshot.clear(); + + m_mutex.lock(); util::clearList( m_oldConnections ); + m_mutex.unlock(); + return ConnNoError; } @@ -126,15 +141,23 @@ namespace gloox connection->registerConnectionDataHandler( this ); ConnectionInfo ci; ci.state = StateUnnegotiated; + + m_mutex.lock(); m_connections[connection] = ci; + m_mutex.unlock(); } void SOCKS5BytestreamServer::handleReceivedData( const ConnectionBase* connection, const std::string& data ) { + m_mutex.lock(); ConnectionMap::iterator it = m_connections.find( const_cast( connection ) ); if( it == m_connections.end() ) + { + m_mutex.unlock(); return; + } + m_mutex.unlock(); switch( (*it).second.state ) { @@ -184,6 +207,7 @@ namespace gloox { const std::string hash = data.substr( 5, 40 ); + m_mutex.lock(); HashMap::const_iterator ith = m_hashes.begin(); for( ; ith != m_hashes.end() && (*ith) != hash; ++ith ) ; @@ -194,6 +218,7 @@ namespace gloox (*it).second.hash = hash; (*it).second.state = StateDestinationAccepted; } + m_mutex.unlock(); } (*it).first->send( reply ); break; @@ -213,6 +238,7 @@ namespace gloox void SOCKS5BytestreamServer::handleDisconnect( const ConnectionBase* connection, ConnectionError /*reason*/ ) { + util::MutexGuard mg( m_mutex ); m_connections.erase( const_cast( connection ) ); m_oldConnections.push_back( connection ); } diff --git a/libs/libgloox/socks5bytestreamserver.h b/libs/libgloox/socks5bytestreamserver.h index 1910e8d..b4dcd50 100644 --- a/libs/libgloox/socks5bytestreamserver.h +++ b/libs/libgloox/socks5bytestreamserver.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -16,14 +16,13 @@ #include "macros.h" #include "connectionhandler.h" +#include "connectiontcpserver.h" #include "logsink.h" #include "mutex.h" namespace gloox { - class ConnectionTCPServer; - /** * @brief A server listening for SOCKS5 bytestreams. * @@ -31,7 +30,7 @@ namespace gloox * * @note It is safe to put a SOCKS5BytestreamServer instance into a separate thread. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API SOCKS5BytestreamServer : public ConnectionHandler, public ConnectionDataHandler @@ -87,6 +86,12 @@ namespace gloox */ const std::string localInterface() const; + /** + * Exposes the local socket. + * @return The local socket. + */ + int serverSocket() const { return m_tcpServer->socket(); } + // reimplemented from ConnectionHandler virtual void handleIncomingConnection( ConnectionBase* server, ConnectionBase* connection ); diff --git a/libs/libgloox/softwareversion.cpp b/libs/libgloox/softwareversion.cpp index 6705de1..f7ae5db 100644 --- a/libs/libgloox/softwareversion.cpp +++ b/libs/libgloox/softwareversion.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2008-2009 by Jakob Schroeter + Copyright (c) 2008-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/softwareversion.h b/libs/libgloox/softwareversion.h index 2fe654d..a83f121 100644 --- a/libs/libgloox/softwareversion.h +++ b/libs/libgloox/softwareversion.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2008-2009 by Jakob Schroeter + Copyright (c) 2008-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -26,9 +26,9 @@ namespace gloox class Tag; /** - * @brief This is an implementation of XEP-0092 as a StanzaExtension. + * @brief This is an implementation of @xep{0092} as a StanzaExtension. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API SoftwareVersion : public StanzaExtension diff --git a/libs/libgloox/stanza.cpp b/libs/libgloox/stanza.cpp index f0d979a..e4c0d38 100644 --- a/libs/libgloox/stanza.cpp +++ b/libs/libgloox/stanza.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -24,12 +24,12 @@ namespace gloox { Stanza::Stanza( const JID& to ) - : m_xmllang( "default" ), m_to( to ) + : m_xmllang( "default" ), m_to( to ), m_hasEmbeddedStanza( false ) { } Stanza::Stanza( Tag* tag ) - : m_xmllang( "default" ) + : m_xmllang( "default" ), m_hasEmbeddedStanza( false ) { if( !tag ) return; @@ -66,6 +66,20 @@ namespace gloox util::clearList( m_extensionList ); } + Stanza* Stanza::embeddedStanza() const + { + StanzaExtensionList::const_iterator it = m_extensionList.begin(); + for( ; it != m_extensionList.end() && !(*it)->embeddedStanza(); ++it ) ; + return it != m_extensionList.end() ? (*it)->embeddedStanza() : 0; + } + + Tag* Stanza::embeddedTag() const + { + StanzaExtensionList::const_iterator it = m_extensionList.begin(); + for( ; it != m_extensionList.end() && !(*it)->embeddedTag(); ++it ) ; + return it != m_extensionList.end() ? (*it)->embeddedTag() : 0; + } + void Stanza::setLang( StringMap** map, std::string& defaultLang, const Tag* tag ) diff --git a/libs/libgloox/stanza.h b/libs/libgloox/stanza.h index 45acdd6..ec60713 100644 --- a/libs/libgloox/stanza.h +++ b/libs/libgloox/stanza.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -27,7 +27,7 @@ namespace gloox /** * @brief This is the base class for XMPP stanza abstractions. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.4 */ class GLOOX_API Stanza @@ -117,11 +117,50 @@ namespace gloox */ void removeExtensions(); + /** + * This function is used by StanzaExtensionFactory to signal ClientBase + * that this Stanza instance contains an embedded Stanza that needs to be + * checked for further StanzaExtensions. + * You should not need to use this function directly. + */ + void setEmbeddedStanza() { m_hasEmbeddedStanza = true; } + + /** + * This function indicates whether this Stanza instance contains an embedded + * Stanza that needs to be checked for further StanzaExtensions. + * You should not need to use this function directly. + * @return Whether this Stanza instance contains an embedded + * Stanza. + */ + bool hasEmbeddedStanza() const { return m_hasEmbeddedStanza; } + + /** + * This function returns the embedded Stanza. It is only needed by + * ClientBase/StanzaExtensionFactory. + * If hasEmbeddedStanza() is true, this function checks every + * embedded StanzaExtension for an embedded Stanza and returns the first it finds. + * You should not need to use this function directly. + * @return The embedded Stanza. May be 0. + */ + Stanza* embeddedStanza() const; + + /** + * This function returns the embedded Tag that the embedded Stanza is based on. + * It is only needed by ClientBase/StanzaExtensionFactory. + * If hasEmbeddedStanza() is true, this function checks every + * embedded StanzaExtension for an embedded Tag and returns the first it finds. + * You should not need to use this function directly. + * + * @return The embedded Tag. May be 0. + */ + Tag* embeddedTag() const; + /** * Creates a Tag representation of the Stanza. The Tag is completely * independent of the Stanza and will not be updated when the Stanza * is modified. * @return A pointer to a Tag representation. It is the job of the + * * caller to delete the Tag. */ virtual Tag* tag() const = 0; @@ -166,6 +205,8 @@ namespace gloox private: Stanza( const Stanza& ); + + bool m_hasEmbeddedStanza; }; diff --git a/libs/libgloox/stanzaextension.h b/libs/libgloox/stanzaextension.h index 89d71ee..ebdf72e 100644 --- a/libs/libgloox/stanzaextension.h +++ b/libs/libgloox/stanzaextension.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -22,6 +22,7 @@ namespace gloox { class Tag; + class Stanza; /** * Supported Stanza extension types. @@ -30,62 +31,66 @@ namespace gloox { ExtNone, /**< Invalid StanzaExtension. */ ExtVCardUpdate, /**< Extension in the vcard-temp:x:update namespace, - * advertising a user avatar's SHA1 hash (XEP-0153). */ + * advertising a user avatar's SHA1 hash (@xep{0153}). */ ExtOOB, /**< An extension in the jabber:iq:oob or jabber:x:oob - * namespaces (XEP-0066). */ + * namespaces (@xep{0066}). */ ExtGPGSigned, /**< An extension containing a GPG/PGP signature - * (XEP-0027). */ + * (@xep{0027}). */ ExtGPGEncrypted, /**< An extension containing a GPG/PGP encrypted message - * (XEP-0027). */ + * (@xep{0027}). */ ExtReceipt, /**< An extension containing a Message Receipt/Request - * (XEP-0184). */ + * (@xep{0184}). */ ExtDelay, /**< An extension containing notice of delayed delivery - * (XEP-0203 & XEP-0091). */ + * (@xep{0203} & @xep{0091}). */ ExtAMP, /**< An extension containing advanced message processing - * rules (XEP-0079). */ + * rules (@xep{0079}). */ ExtError, /**< An extension containing an error. */ ExtCaps, /**< An extension containing Entity Capabilities - * (XEP-0115). */ - ExtChatState, /**< An extension containing a chat state (XEP-0085). */ - ExtMessageEvent, /**< An extension containing a message event (XEP-0022). */ - ExtDataForm, /**< An extension containing a Data Form (XEP-0004). */ - ExtNickname, /**< An extension containing a User Nickname (XEP-0172). */ + * (@xep{0115}). */ + ExtChatState, /**< An extension containing a chat state (@xep{0085}). */ + ExtMessageEvent, /**< An extension containing a message event (@xep{0022}). */ + ExtDataForm, /**< An extension containing a Data Form (@xep{0004}). */ + ExtNickname, /**< An extension containing a User Nickname (@xep{0172}). */ ExtResourceBind, /**< A resource bind SE (RFC3921). */ ExtSessionCreation, /**< A session establishing SE (RFC3921). */ ExtVersion, /**< An extension containing a Version request/reply - * (XEP-0092). */ + * (@xep{0092}). */ ExtXHtmlIM, /**< An extension containing an XHTML message - * representation (XEP-0071) */ - ExtDiscoInfo, /**< An extension containing a disco#info element (XEP-0030). */ - ExtDiscoItems, /**< An extension containing a disco#items element (XEP-0030). */ - ExtAdhocCommand, /**< An extension containing a Adhoc Command (XEP-0050). */ - ExtPrivateXML, /**< An extension used for Private XML Storage (XEP-0048). */ + * representation (@xep{0071}) */ + ExtDiscoInfo, /**< An extension containing a disco#info element (@xep{0030}). */ + ExtDiscoItems, /**< An extension containing a disco#items element (@xep{0030}). */ + ExtAdhocCommand, /**< An extension containing a Adhoc Command (@xep{0050}). */ + ExtPrivateXML, /**< An extension used for Private XML Storage (@xep{0048}). */ ExtRoster, /**< An extension dealing with the user's roster (RFC-3921). */ ExtFeatureNeg, /**< An extension abstracting a Feature Negotiation element - * (XEP-0020). */ - ExtIBB, /**< An extension dealing with IBBs (XEP-0047). */ - ExtNonSaslAuth, /**< An extension for doing Non-SASL Authentication (XEP-0078). */ - ExtMUC, /**< An extension dealing with the muc namespace of XEP-0045. */ - ExtMUCOwner, /**< An extension dealing with the muc#owner namespace of XEP-0045. */ - ExtMUCAdmin, /**< An extension dealing with the muc#admin namespace of XEP-0045. */ - ExtMUCUser, /**< An extension dealing with the muc#user namespace of XEP-0045. */ - ExtMUCUnique, /**< An extension dealing with the muc#unique namespace of XEP-0045. */ - ExtPing, /**< An XMPP Ping (XEP-0199). */ - ExtSearch, /**< A XEP-0055 (Jabber Search) wrapper. */ - ExtRegistration, /**< A XEP-0077 (In-Band Registration) wrapper. */ - ExtJingle, /**< An extension dealing with Jingle (XEP-0166) */ - ExtVCard, /**< An extension dealing with vcard-temp (XEP-0054) */ - ExtPrivacy, /**< An extension dealing with Privacy Lists (XEP-0016) */ - ExtLastActivity, /**< An extension dealing with Last Activity (XEP-0012). */ - ExtFlexOffline, /**< An extension dealing with Flexible Offline Messages (XEP-0013). */ - ExtSI, /**< An extension dealing with Stream Initiation (XEP-0095). */ - ExtS5BQuery, /**< An extension dealing with stream host offers (XEP-0065) */ - ExtPubSub, /**< An extension dealing with PubSub requests (XEP-0060). */ - ExtPubSubOwner, /**< An extension dealing with PubSub owner requests (XEP-0060). */ + * (@xep{0020}). */ + ExtIBB, /**< An extension dealing with IBBs (@xep{0047}). */ + ExtNonSaslAuth, /**< An extension for doing Non-SASL Authentication (@xep{0078}). */ + ExtMUC, /**< An extension dealing with the muc namespace of @xep{0045}. */ + ExtMUCOwner, /**< An extension dealing with the muc#owner namespace of @xep{0045}. */ + ExtMUCAdmin, /**< An extension dealing with the muc#admin namespace of @xep{0045}. */ + ExtMUCUser, /**< An extension dealing with the muc#user namespace of @xep{0045}. */ + ExtMUCUnique, /**< An extension dealing with the muc#unique namespace of @xep{0045}. */ + ExtPing, /**< An XMPP Ping (@xep{0199}). */ + ExtSearch, /**< A @xep{0055} (Jabber Search) wrapper. */ + ExtRegistration, /**< A @xep{0077} (In-Band Registration) wrapper. */ + ExtJingle, /**< An extension dealing with Jingle (@xep{0166}) */ + ExtVCard, /**< An extension dealing with vcard-temp (@xep{0054}) */ + ExtPrivacy, /**< An extension dealing with Privacy Lists (@xep{0016}) */ + ExtLastActivity, /**< An extension dealing with Last Activity (@xep{0012}). */ + ExtFlexOffline, /**< An extension dealing with Flexible Offline Messages (@xep{0013}). */ + ExtSI, /**< An extension dealing with Stream Initiation (@xep{0095}). */ + ExtS5BQuery, /**< An extension dealing with stream host offers (@xep{0065}) */ + ExtPubSub, /**< An extension dealing with PubSub requests (@xep{0060}). */ + ExtPubSubOwner, /**< An extension dealing with PubSub owner requests (@xep{0060}). */ ExtPubSubEvent, /**< An extension for PubSub event notifications - * (XEP-0060) */ - ExtSHIM, /**< An extension dealing with Stanza Headers and Internet Metadata (XEP-0131). */ - ExtAttention, /**< An extension dealing with Attention (XEP-0224). */ + * (@xep{0060}) */ + ExtSHIM, /**< An extension dealing with Stanza Headers and Internet Metadata (@xep{0131}). */ + ExtAttention, /**< An extension dealing with Attention (@xep{0224}). */ + ExtForward, /**< An extension dealing with Stanza Forwarding (@xep{0297}). */ + ExtCarbons, /**< An extension dealing with Message Carbons (@xep{0280}). */ + ExtIOData, /**< An extension dealing with IO Data (@xep{0244}) (though the IOData extension + * is not actually used as/meant to be a StanzaExtension. */ ExtUser /**< User-supplied extensions must use IDs above this. Do * not hard-code ExtUser's value anywhere, it is subject * to change. */ @@ -171,7 +176,7 @@ namespace gloox * must be reimplemented. The output Tag should -- like the input Tag -- be embeddable * into the respective stanza. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API StanzaExtension @@ -189,6 +194,22 @@ namespace gloox */ virtual ~StanzaExtension() {} + /** + * This function returns the embedded Stanza, if any. + * You only have to reimplement it if your protocol flow contains embedded Stanzas. + * + * @return The embedded Stanza. May be 0. + */ + virtual Stanza* embeddedStanza() const { return 0; } + + /** + * This function returns the embedded Tag that the embedded Stanza is based on, if any. + * You only have to reimplement it if your protocol flow contains embedded Stanzas. + * + * @return The embedded Tag. May be 0. + */ + virtual Tag* embeddedTag() const { return 0; } + /** * Returns an XPath expression that describes a path to child elements of a * stanza that an extension handles. diff --git a/libs/libgloox/stanzaextensionfactory.cpp b/libs/libgloox/stanzaextensionfactory.cpp index 06d65e2..9941ebd 100644 --- a/libs/libgloox/stanzaextensionfactory.cpp +++ b/libs/libgloox/stanzaextensionfactory.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -14,6 +14,7 @@ #include "stanzaextensionfactory.h" #include "gloox.h" +#include "mutexguard.h" #include "util.h" #include "stanza.h" #include "stanzaextension.h" @@ -28,7 +29,9 @@ namespace gloox StanzaExtensionFactory::~StanzaExtensionFactory() { + m_extensionsMutex.lock(); util::clearList( m_extensions ); + m_extensionsMutex.unlock(); } void StanzaExtensionFactory::registerExtension( StanzaExtension* ext ) @@ -36,6 +39,7 @@ namespace gloox if( !ext ) return; + util::MutexGuard m( m_extensionsMutex ); SEList::iterator it = m_extensions.begin(); SEList::iterator it2; while( it != m_extensions.end() ) @@ -52,6 +56,7 @@ namespace gloox bool StanzaExtensionFactory::removeExtension( int ext ) { + util::MutexGuard m( m_extensionsMutex ); SEList::iterator it = m_extensions.begin(); for( ; it != m_extensions.end(); ++it ) { @@ -68,6 +73,8 @@ namespace gloox void StanzaExtensionFactory::addExtensions( Stanza& stanza, Tag* tag ) { ConstTagList::const_iterator it; + + util::MutexGuard m( m_extensionsMutex ); SEList::const_iterator ite = m_extensions.begin(); for( ; ite != m_extensions.end(); ++ite ) { @@ -77,7 +84,11 @@ namespace gloox { StanzaExtension* se = (*ite)->newInstance( (*it) ); if( se ) + { stanza.addExtension( se ); + if( se->embeddedStanza() ) + stanza.setEmbeddedStanza(); + } } } } diff --git a/libs/libgloox/stanzaextensionfactory.h b/libs/libgloox/stanzaextensionfactory.h index ab53451..c5b6ae2 100644 --- a/libs/libgloox/stanzaextensionfactory.h +++ b/libs/libgloox/stanzaextensionfactory.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -14,6 +14,8 @@ #ifndef STANZAEXTENSIONFACTORY_H__ #define STANZAEXTENSIONFACTORY_H__ +#include "mutex.h" + #include namespace gloox @@ -33,7 +35,7 @@ namespace gloox * instead. See StanzaExtension for more information about adding protocol implementations * to gloox. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class StanzaExtensionFactory @@ -82,6 +84,7 @@ namespace gloox private: typedef std::list SEList; SEList m_extensions; + util::Mutex m_extensionsMutex; }; diff --git a/libs/libgloox/statisticshandler.h b/libs/libgloox/statisticshandler.h index 74ef964..71d6161 100644 --- a/libs/libgloox/statisticshandler.h +++ b/libs/libgloox/statisticshandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -57,7 +57,7 @@ namespace gloox * * Derived classes can be registered as StatisticsHandlers with the ClientBase. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API StatisticsHandler diff --git a/libs/libgloox/subscription.cpp b/libs/libgloox/subscription.cpp index bb310d6..2ac2ab5 100644 --- a/libs/libgloox/subscription.cpp +++ b/libs/libgloox/subscription.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/subscription.h b/libs/libgloox/subscription.h index ae377d1..de6976d 100644 --- a/libs/libgloox/subscription.h +++ b/libs/libgloox/subscription.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -25,7 +25,7 @@ namespace gloox /** * @brief An abstraction of a subscription stanza. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API Subscription : public Stanza @@ -40,7 +40,7 @@ namespace gloox */ enum S10nType { - Subscribe, /**> A subscription request. */ + Subscribe, /**< A subscription request. */ Subscribed, /**< A subscription notification. */ Unsubscribe, /**< An unsubscription request. */ Unsubscribed, /**< An unsubscription notification. */ diff --git a/libs/libgloox/subscriptionhandler.h b/libs/libgloox/subscriptionhandler.h index d891a7f..9c84b2d 100644 --- a/libs/libgloox/subscriptionhandler.h +++ b/libs/libgloox/subscriptionhandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2009 by Jakob Schroeter + Copyright (c) 2004-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -24,7 +24,7 @@ namespace gloox * * Derived classes can be registered as SubscriptionHandlers with the Client. * Upon an incoming Subscription packet @ref handleSubscription() will be called. - * @author Jakob Schroeter + * @author Jakob Schröter */ class GLOOX_API SubscriptionHandler { diff --git a/libs/libgloox/tag.cpp b/libs/libgloox/tag.cpp index 8416157..5e42483 100644 --- a/libs/libgloox/tag.cpp +++ b/libs/libgloox/tag.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -127,7 +127,7 @@ namespace gloox } xml += m_name; xml += "='"; - xml += util::escape( m_value ); + util::appendEscaped( xml, m_value ); xml += '\''; return xml; @@ -333,7 +333,7 @@ namespace gloox xml += (*it_n)->tag->xml(); break; case TypeString: - xml += util::escape( *((*it_n)->str) ); + util::appendEscaped( xml, *((*it_n)->str) ); break; } } @@ -467,6 +467,10 @@ namespace gloox delete (*t); m_nodes->erase( t ); } + else + { + it++; + } } } diff --git a/libs/libgloox/tag.h b/libs/libgloox/tag.h index 3575bb7..d53d1d3 100644 --- a/libs/libgloox/tag.h +++ b/libs/libgloox/tag.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -40,7 +40,7 @@ namespace gloox * * @note Use setXmlns() to set namespaces and namespace prefixes. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.4 */ class GLOOX_API Tag @@ -53,7 +53,7 @@ namespace gloox /** * An XML element's attribute. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API Attribute diff --git a/libs/libgloox/taghandler.h b/libs/libgloox/taghandler.h index 9766851..ab57f5e 100644 --- a/libs/libgloox/taghandler.h +++ b/libs/libgloox/taghandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -27,7 +27,7 @@ namespace gloox * * It can also be used to handle Tags emitted by Parser. * - * @author Jakob Schroeter + * @author Jakob Schröter */ class GLOOX_API TagHandler { diff --git a/libs/libgloox/tlsbase.h b/libs/libgloox/tlsbase.h index 101c493..567ce8b 100644 --- a/libs/libgloox/tlsbase.h +++ b/libs/libgloox/tlsbase.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -25,7 +25,7 @@ namespace gloox /** * @brief An abstract base class for TLS implementations. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API TLSBase @@ -61,7 +61,7 @@ namespace gloox /** * Enables/disables initialization of the underlying TLS library. By default, * initialization is performed. You may want to switch it off if the TLS library - * is used elsewhere in your applicationas well and you have no control over the + * is used elsewhere in your application as well and you have no control over the * initialization. * @param init Whether or not to intialize the underlying TLS library. */ @@ -104,6 +104,18 @@ namespace gloox */ virtual bool isSecure() const { return m_secure; } + /** + * This function indicates whether the underlying TLS implementation supports channel binding (used in e.g. SASL SCRAM-SHA-1-PLUS). + * @return @b True if channel binding is supported, @b false otherwise. + */ + virtual bool hasChannelBinding() const { return false; } + + /** + * Returns the channel binding data for the established connection. + * @return The channel binding data, if any, or the empty string. + */ + virtual const std::string channelBinding() const { return EmptyString; } + /** * Use this function to set a number of trusted root CA certificates which shall be * used to verify a servers certificate. diff --git a/libs/libgloox/tlsdefault.cpp b/libs/libgloox/tlsdefault.cpp index 2c09640..c9999e3 100644 --- a/libs/libgloox/tlsdefault.cpp +++ b/libs/libgloox/tlsdefault.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007-2009 by Jakob Schroeter + * Copyright (c) 2007-2015 by Jakob Schröter * This file is part of the gloox library. http://camaya.net/gloox * * This software is distributed under a license. The full license @@ -126,6 +126,16 @@ namespace gloox return m_impl ? m_impl->isSecure() : false; } + bool TLSDefault::hasChannelBinding() const + { + return m_impl ? m_impl->hasChannelBinding() : false; + } + + const std::string TLSDefault::channelBinding() const + { + return m_impl ? m_impl->channelBinding() : EmptyString; + } + void TLSDefault::setCACerts( const StringList& cacerts ) { if( m_impl ) diff --git a/libs/libgloox/tlsdefault.h b/libs/libgloox/tlsdefault.h index cee4940..5f9d17b 100644 --- a/libs/libgloox/tlsdefault.h +++ b/libs/libgloox/tlsdefault.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007-2009 by Jakob Schroeter + * Copyright (c) 2007-2015 by Jakob Schröter * This file is part of the gloox library. http://camaya.net/gloox * * This software is distributed under a license. The full license @@ -27,7 +27,7 @@ namespace gloox * You should use an instance of this class should you whish to use TLS encryption. * TLS support for the main XMPP connection is managed by Client/ClientBase directly. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API TLSDefault : public TLSBase @@ -81,6 +81,12 @@ namespace gloox // reimplemented from TLSBase virtual bool isSecure() const; + // reimplemented from TLSBase + virtual bool hasChannelBinding() const; + + // reimplemented from TLSBase + virtual const std::string channelBinding() const; + // reimplemented from TLSBase virtual void setCACerts( const StringList& cacerts ); diff --git a/libs/libgloox/tlsgnutlsbase.cpp b/libs/libgloox/tlsgnutlsbase.cpp index d98c802..289fb0a 100644 --- a/libs/libgloox/tlsgnutlsbase.cpp +++ b/libs/libgloox/tlsgnutlsbase.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -19,6 +19,7 @@ #include #include #include +#include namespace gloox { @@ -97,12 +98,13 @@ namespace gloox gnutls_bye( *m_session, GNUTLS_SHUT_RDWR ); gnutls_db_remove_session( *m_session ); gnutls_credentials_clear( *m_session ); - if( m_secure ) + if( m_session ) gnutls_deinit( *m_session ); + delete m_session; + m_secure = false; m_valid = false; - delete m_session; m_session = 0; m_session = new gnutls_session_t; m_handler = handler; @@ -139,6 +141,28 @@ namespace gloox return true; } + bool GnuTLSBase::hasChannelBinding() const + { +#ifdef HAVE_GNUTLS_SESSION_CHANNEL_BINDING + return true; +#else + return false; +#endif + } + + const std::string GnuTLSBase::channelBinding() const + { +#ifdef HAVE_GNUTLS_SESSION_CHANNEL_BINDING + gnutls_datum_t cb; + int rc; + rc = gnutls_session_channel_binding( *m_session, GNUTLS_CB_TLS_UNIQUE, &cb ); + if( !rc ) + return std::string( (char*)cb.data, cb.size ); + else +#endif + return EmptyString; + } + ssize_t GnuTLSBase::pullFunc( void* data, size_t len ) { ssize_t cpy = ( len > m_recvBuffer.length() ) ? ( m_recvBuffer.length() ) : ( len ); diff --git a/libs/libgloox/tlsgnutlsbase.h b/libs/libgloox/tlsgnutlsbase.h index 79ef968..88dc420 100644 --- a/libs/libgloox/tlsgnutlsbase.h +++ b/libs/libgloox/tlsgnutlsbase.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -32,7 +32,7 @@ namespace gloox * * You should not need to use this class directly. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GnuTLSBase : public TLSBase @@ -62,6 +62,12 @@ namespace gloox // reimplemented from TLSBase virtual bool handshake(); + // reimplemented from TLSBase + virtual bool hasChannelBinding() const; + + // reimplemented from TLSBase + virtual const std::string channelBinding() const; + // reimplemented from TLSBase virtual void setCACerts( const StringList& /*cacerts*/ ) {} diff --git a/libs/libgloox/tlsgnutlsclient.cpp b/libs/libgloox/tlsgnutlsclient.cpp index c1d24c2..fc03135 100644 --- a/libs/libgloox/tlsgnutlsclient.cpp +++ b/libs/libgloox/tlsgnutlsclient.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -33,24 +33,15 @@ namespace gloox void GnuTLSClient::cleanup() { GnuTLSBase::cleanup(); + if( m_credentials ) + gnutls_certificate_free_credentials( m_credentials ); init(); } - bool GnuTLSClient::init( const std::string& clientKey, - const std::string& clientCerts, - const StringList& cacerts ) + bool GnuTLSClient::init( const std::string& /*clientKey*/, + const std::string& /*clientCerts*/, + const StringList& /*cacerts*/ ) { - const int protocolPriority[] = { -#ifdef GNUTLS_TLS1_2 - GNUTLS_TLS1_2, -#endif - GNUTLS_TLS1_1, GNUTLS_TLS1, 0 }; - const int kxPriority[] = { GNUTLS_KX_RSA, GNUTLS_KX_DHE_RSA, GNUTLS_KX_DHE_DSS, 0 }; - const int cipherPriority[] = { GNUTLS_CIPHER_AES_256_CBC, GNUTLS_CIPHER_AES_128_CBC, - GNUTLS_CIPHER_3DES_CBC, GNUTLS_CIPHER_ARCFOUR, 0 }; - const int compPriority[] = { GNUTLS_COMP_ZLIB, GNUTLS_COMP_NULL, 0 }; - const int macPriority[] = { GNUTLS_MAC_SHA, GNUTLS_MAC_MD5, 0 }; - if( m_initLib && gnutls_global_init() != 0 ) return false; @@ -63,11 +54,28 @@ namespace gloox return false; } +#if GNUTLS_VERSION_NUMBER >= 0x020600 + int ret = gnutls_priority_set_direct( *m_session, "SECURE128:+PFS:+COMP-ALL:+VERS-TLS-ALL:-VERS-SSL3.0:+SIGN-ALL:+CURVE-ALL", 0 ); + if( ret != GNUTLS_E_SUCCESS ) + return false; +#else + const int protocolPriority[] = { +#ifdef GNUTLS_TLS1_2 + GNUTLS_TLS1_2, +#endif + GNUTLS_TLS1_1, GNUTLS_TLS1, 0 }; + const int kxPriority[] = { GNUTLS_KX_RSA, GNUTLS_KX_DHE_RSA, GNUTLS_KX_DHE_DSS, 0 }; + const int cipherPriority[] = { GNUTLS_CIPHER_AES_256_CBC, GNUTLS_CIPHER_AES_128_CBC, + GNUTLS_CIPHER_3DES_CBC, GNUTLS_CIPHER_ARCFOUR, 0 }; + const int compPriority[] = { GNUTLS_COMP_ZLIB, GNUTLS_COMP_NULL, 0 }; + const int macPriority[] = { GNUTLS_MAC_SHA, GNUTLS_MAC_MD5, 0 }; gnutls_protocol_set_priority( *m_session, protocolPriority ); gnutls_cipher_set_priority( *m_session, cipherPriority ); gnutls_compression_set_priority( *m_session, compPriority ); gnutls_kx_set_priority( *m_session, kxPriority ); gnutls_mac_set_priority( *m_session, macPriority ); +#endif + gnutls_credentials_set( *m_session, GNUTLS_CRD_CERTIFICATE, m_credentials ); gnutls_transport_set_ptr( *m_session, (gnutls_transport_ptr_t)this ); @@ -119,10 +127,12 @@ namespace gloox if( status & GNUTLS_CERT_SIGNER_NOT_CA ) m_certInfo.status |= CertSignerNotCa; const gnutls_datum_t* certList = 0; - unsigned int certListSize; + unsigned int certListSize = 0; if( !error && ( ( certList = gnutls_certificate_get_peers( *m_session, &certListSize ) ) == 0 ) ) error = true; + unsigned int certListSizeFull = certListSize; + gnutls_x509_crt_t* cert = new gnutls_x509_crt_t[certListSize+1]; for( unsigned int i=0; !error && ( i + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -32,7 +32,7 @@ namespace gloox * * You should not need to use this class directly. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GnuTLSClient : public GnuTLSBase @@ -70,7 +70,7 @@ namespace gloox bool verifyAgainst( gnutls_x509_crt_t cert, gnutls_x509_crt_t issuer ); bool verifyAgainstCAs( gnutls_x509_crt_t cert, gnutls_x509_crt_t *CAList, int CAListSize ); - gnutls_certificate_credentials m_credentials; + gnutls_certificate_credentials_t m_credentials; }; diff --git a/libs/libgloox/tlsgnutlsclientanon.cpp b/libs/libgloox/tlsgnutlsclientanon.cpp index d46464f..9545aa5 100644 --- a/libs/libgloox/tlsgnutlsclientanon.cpp +++ b/libs/libgloox/tlsgnutlsclientanon.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -41,13 +41,6 @@ namespace gloox const std::string&, const StringList& ) { - const int protocolPriority[] = { GNUTLS_TLS1, 0 }; - const int kxPriority[] = { GNUTLS_KX_ANON_DH, 0 }; - const int cipherPriority[] = { GNUTLS_CIPHER_AES_256_CBC, GNUTLS_CIPHER_AES_128_CBC, - GNUTLS_CIPHER_3DES_CBC, GNUTLS_CIPHER_ARCFOUR, 0 }; - const int compPriority[] = { GNUTLS_COMP_ZLIB, GNUTLS_COMP_NULL, 0 }; - const int macPriority[] = { GNUTLS_MAC_SHA, GNUTLS_MAC_MD5, 0 }; - if( m_initLib && gnutls_global_init() != 0 ) return false; @@ -57,11 +50,29 @@ namespace gloox if( gnutls_init( m_session, GNUTLS_CLIENT ) != 0 ) return false; +#if GNUTLS_VERSION_NUMBER >= 0x020600 + int ret = gnutls_priority_set_direct( *m_session, "SECURE128:+PFS:+COMP-ALL:+VERS-TLS-ALL:-VERS-SSL3.0:+SIGN-ALL:+CURVE-ALL", 0 ); + if( ret != GNUTLS_E_SUCCESS ) + return false; +#else + const int protocolPriority[] = { +#ifdef GNUTLS_TLS1_2 + GNUTLS_TLS1_2, +#endif + GNUTLS_TLS1_1, GNUTLS_TLS1, 0 }; + const int protocolPriority[] = { GNUTLS_TLS1, 0 }; + const int kxPriority[] = { GNUTLS_KX_ANON_DH, 0 }; + const int cipherPriority[] = { GNUTLS_CIPHER_AES_256_CBC, GNUTLS_CIPHER_AES_128_CBC, + GNUTLS_CIPHER_3DES_CBC, GNUTLS_CIPHER_ARCFOUR, 0 }; + const int compPriority[] = { GNUTLS_COMP_ZLIB, GNUTLS_COMP_NULL, 0 }; + const int macPriority[] = { GNUTLS_MAC_SHA, GNUTLS_MAC_MD5, 0 }; gnutls_protocol_set_priority( *m_session, protocolPriority ); gnutls_cipher_set_priority( *m_session, cipherPriority ); gnutls_compression_set_priority( *m_session, compPriority ); gnutls_kx_set_priority( *m_session, kxPriority ); gnutls_mac_set_priority( *m_session, macPriority ); +#endif + gnutls_credentials_set( *m_session, GNUTLS_CRD_ANON, m_anoncred ); gnutls_transport_set_ptr( *m_session, (gnutls_transport_ptr_t)this ); diff --git a/libs/libgloox/tlsgnutlsclientanon.h b/libs/libgloox/tlsgnutlsclientanon.h index 3faec75..acbd845 100644 --- a/libs/libgloox/tlsgnutlsclientanon.h +++ b/libs/libgloox/tlsgnutlsclientanon.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -32,7 +32,7 @@ namespace gloox * * You should not need to use this class directly. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GnuTLSClientAnon : public GnuTLSBase diff --git a/libs/libgloox/tlsgnutlsserveranon.cpp b/libs/libgloox/tlsgnutlsserveranon.cpp index f851fdd..a7c9a3c 100644 --- a/libs/libgloox/tlsgnutlsserveranon.cpp +++ b/libs/libgloox/tlsgnutlsserveranon.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -42,13 +42,6 @@ namespace gloox const std::string&, const StringList& ) { - const int protocolPriority[] = { GNUTLS_TLS1, 0 }; - const int kxPriority[] = { GNUTLS_KX_ANON_DH, 0 }; - const int cipherPriority[] = { GNUTLS_CIPHER_AES_256_CBC, GNUTLS_CIPHER_AES_128_CBC, - GNUTLS_CIPHER_3DES_CBC, GNUTLS_CIPHER_ARCFOUR, 0 }; - const int compPriority[] = { GNUTLS_COMP_ZLIB, GNUTLS_COMP_NULL, 0 }; - const int macPriority[] = { GNUTLS_MAC_SHA, GNUTLS_MAC_MD5, 0 }; - if( m_initLib && gnutls_global_init() != 0 ) return false; @@ -61,11 +54,28 @@ namespace gloox if( gnutls_init( m_session, GNUTLS_SERVER ) != 0 ) return false; +#if GNUTLS_VERSION_NUMBER >= 0x020600 + int ret = gnutls_priority_set_direct( *m_session, "SECURE128:+PFS:+COMP-ALL:+VERS-TLS-ALL:-VERS-SSL3.0:+SIGN-ALL:+CURVE-ALL", 0 ); + if( ret != GNUTLS_E_SUCCESS ) + return false; +#else + const int protocolPriority[] = { +#ifdef GNUTLS_TLS1_2 + GNUTLS_TLS1_2, +#endif + GNUTLS_TLS1_1, GNUTLS_TLS1, 0 }; + const int kxPriority[] = { GNUTLS_KX_ANON_DH, 0 }; + const int cipherPriority[] = { GNUTLS_CIPHER_AES_256_CBC, GNUTLS_CIPHER_AES_128_CBC, + GNUTLS_CIPHER_3DES_CBC, GNUTLS_CIPHER_ARCFOUR, 0 }; + const int compPriority[] = { GNUTLS_COMP_ZLIB, GNUTLS_COMP_NULL, 0 }; + const int macPriority[] = { GNUTLS_MAC_SHA, GNUTLS_MAC_MD5, 0 }; gnutls_protocol_set_priority( *m_session, protocolPriority ); gnutls_cipher_set_priority( *m_session, cipherPriority ); gnutls_compression_set_priority( *m_session, compPriority ); gnutls_kx_set_priority( *m_session, kxPriority ); gnutls_mac_set_priority( *m_session, macPriority ); +#endif + gnutls_credentials_set( *m_session, GNUTLS_CRD_ANON, m_anoncred ); gnutls_dh_set_prime_bits( *m_session, m_dhBits ); diff --git a/libs/libgloox/tlsgnutlsserveranon.h b/libs/libgloox/tlsgnutlsserveranon.h index f66ae28..14ac0df 100644 --- a/libs/libgloox/tlsgnutlsserveranon.h +++ b/libs/libgloox/tlsgnutlsserveranon.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -32,7 +32,7 @@ namespace gloox * * You should not need to use this class directly. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GnuTLSServerAnon : public GnuTLSBase diff --git a/libs/libgloox/tlshandler.h b/libs/libgloox/tlshandler.h index aa42fe7..a3c6fd1 100644 --- a/libs/libgloox/tlshandler.h +++ b/libs/libgloox/tlshandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -28,7 +28,7 @@ namespace gloox /** * @brief An interface that allows for interacting with TLS implementations derived from TLSBase. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API TLSHandler diff --git a/libs/libgloox/tlsopensslbase.cpp b/libs/libgloox/tlsopensslbase.cpp index 2936bad..393c483 100644 --- a/libs/libgloox/tlsopensslbase.cpp +++ b/libs/libgloox/tlsopensslbase.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2009 by Jakob Schroeter + Copyright (c) 2009-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -22,6 +22,7 @@ #include #include +#include namespace gloox { @@ -269,6 +270,8 @@ namespace gloox if( ASN1_UTCTIME_cmp_time_t( X509_get_notAfter( peer ), time( 0 ) ) != 1 ) m_certInfo.status |= CertExpired; + + X509_free( peer ); } else { diff --git a/libs/libgloox/tlsopensslbase.h b/libs/libgloox/tlsopensslbase.h index 8e35f67..76105e0 100644 --- a/libs/libgloox/tlsopensslbase.h +++ b/libs/libgloox/tlsopensslbase.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2009 by Jakob Schroeter + Copyright (c) 2009-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -30,7 +30,7 @@ namespace gloox * This is a common base class for client and server-side TLS * stream encryption implementations using OpenSSL. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class OpenSSLBase : public TLSBase diff --git a/libs/libgloox/tlsopensslclient.cpp b/libs/libgloox/tlsopensslclient.cpp index 8642a47..6b7e07a 100644 --- a/libs/libgloox/tlsopensslclient.cpp +++ b/libs/libgloox/tlsopensslclient.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2009 by Jakob Schroeter + Copyright (c) 2005-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -30,13 +30,25 @@ namespace gloox bool OpenSSLClient::setType() { - m_ctx = SSL_CTX_new( SSLv23_client_method() ); // FIXME: use TLSv1_client_method() as soon as OpenSSL/gtalk combo is fixed! + m_ctx = SSL_CTX_new( TLSv1_client_method() ); if( !m_ctx ) return false; return true; } + bool OpenSSLClient::hasChannelBinding() const + { + return true; + } + + const std::string OpenSSLClient::channelBinding() const + { + unsigned char* buf[128]; + int res = SSL_get_finished( m_ssl, buf, 128 ); + return std::string( (char*)buf, res ); + } + int OpenSSLClient::handshakeFunction() { return SSL_connect( m_ssl ); diff --git a/libs/libgloox/tlsopensslclient.h b/libs/libgloox/tlsopensslclient.h index 0ad5640..48734ee 100644 --- a/libs/libgloox/tlsopensslclient.h +++ b/libs/libgloox/tlsopensslclient.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -29,7 +29,7 @@ namespace gloox /** * This class implements a TLS client backend using OpenSSL. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class OpenSSLClient : public OpenSSLBase @@ -47,7 +47,13 @@ namespace gloox */ virtual ~OpenSSLClient(); - private: + // reimplemented from TLSBase + virtual bool hasChannelBinding() const; + + // reimplemented from TLSBase + virtual const std::string channelBinding() const; + + private: // reimplemented from OpenSSLBase virtual bool setType(); diff --git a/libs/libgloox/tlsopensslserver.cpp b/libs/libgloox/tlsopensslserver.cpp index ae0fab3..8cb1c4c 100644 --- a/libs/libgloox/tlsopensslserver.cpp +++ b/libs/libgloox/tlsopensslserver.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2009 by Jakob Schroeter + Copyright (c) 2009-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -36,7 +36,7 @@ namespace gloox bool OpenSSLServer::setType() { - m_ctx = SSL_CTX_new( SSLv23_server_method() ); + m_ctx = SSL_CTX_new( TLSv1_server_method() ); if( !m_ctx ) return false; @@ -254,7 +254,6 @@ namespace gloox { SSL_CTX_set_tmp_rsa_callback( m_ctx, tmp_rsa_callback ); SSL_CTX_set_tmp_dh_callback( m_ctx, tmp_dh_callback ); - SSL_CTX_set_tmp_ecdh( m_ctx, EC_KEY_new_by_curve_name( NID_sect163r2 ) ); SSL_CTX_set_options( m_ctx, SSL_OP_CIPHER_SERVER_PREFERENCE ); return true; } diff --git a/libs/libgloox/tlsopensslserver.h b/libs/libgloox/tlsopensslserver.h index 5b5d8e5..d7ae63e 100644 --- a/libs/libgloox/tlsopensslserver.h +++ b/libs/libgloox/tlsopensslserver.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2009 by Jakob Schroeter + Copyright (c) 2009-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -29,7 +29,7 @@ namespace gloox /** * This class implements a TLS server backend using OpenSSL. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class OpenSSLServer : public OpenSSLBase diff --git a/libs/libgloox/tlsschannel.cpp b/libs/libgloox/tlsschannel.cpp index d06eddb..ae1910a 100644 --- a/libs/libgloox/tlsschannel.cpp +++ b/libs/libgloox/tlsschannel.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007-2009 by Jakob Schroeter + * Copyright (c) 2007-2015 by Jakob Schröter * This file is part of the gloox library. http://camaya.net/gloox * * This software is distributed under a license. The full license @@ -43,7 +43,7 @@ namespace gloox SecBufferDesc buffer_desc; DWORD cbIoBufferLength = m_sizes.cbHeader + m_sizes.cbMaximumMessage + m_sizes.cbTrailer; - PBYTE e_iobuffer = static_cast( LocalAlloc( LMEM_FIXED, cbIoBufferLength ) ); + PBYTE e_iobuffer = static_cast( malloc( cbIoBufferLength ) ); if( e_iobuffer == NULL ) { @@ -93,7 +93,8 @@ namespace gloox } else { - LocalFree( e_iobuffer ); + free( e_iobuffer ); + e_iobuffer = 0; if( !m_secure ) m_handler->handleHandshakeResult( this, false, m_certInfo ); cleanup(); @@ -101,7 +102,8 @@ namespace gloox } } while( data_copy.size() > 0 ); - LocalFree( e_iobuffer ); + free( e_iobuffer ); + e_iobuffer = 0; return true; } @@ -121,7 +123,7 @@ namespace gloox DWORD cbIoBufferLength = m_sizes.cbHeader + m_sizes.cbMaximumMessage + m_sizes.cbTrailer; bool wantNewBufferSize = false; - PBYTE e_iobuffer = static_cast( LocalAlloc( LMEM_FIXED, cbIoBufferLength ) ); + PBYTE e_iobuffer = static_cast( malloc( cbIoBufferLength ) ); if( e_iobuffer == NULL ) { //printf("**** Out of memory (2)\n"); @@ -136,8 +138,19 @@ namespace gloox { if( wantNewBufferSize ) { - e_iobuffer = static_cast( LocalReAlloc( e_iobuffer, cbIoBufferLength, 0 ) ); - wantNewBufferSize = false; + void* tmp = realloc( e_iobuffer, cbIoBufferLength ); + if( tmp ) + { + e_iobuffer = static_cast( tmp ); + wantNewBufferSize = false; + } + else + { + //printf("**** Out of memory (2)\n"); + cleanup(); + m_handler->handleHandshakeResult( this, false, m_certInfo ); + return 0; + } } // copy data chunk from tmp string into encryption memory buffer @@ -221,7 +234,7 @@ namespace gloox } } while( m_buffer.size() != 0 ); - LocalFree( e_iobuffer ); + free( e_iobuffer ); } else { @@ -465,6 +478,27 @@ namespace gloox while( true ); } + bool SChannel::hasChannelBinding() const + { +#ifdef HAVE_WINTLS_CHANNEL_BINDING + return true; +#else + return false; +#endif + } + + const std::string SChannel::channelBinding() const + { +#ifdef HAVE_WINTLS_CHANNEL_BINDING // see ../config.h.win if the following doesn't compile + SecPkgContext_Bindings buf; + if( QueryContextAttributes( &m_context, SECPKG_ATTR_UNIQUE_BINDINGS, &buf ) == SEC_E_OK ) + { + return std::string( buf->Bindings[buf->Bindings.dwApplicationDataOffset], buf->Bindings.cbApplicationDataLength ); + } +#endif + return EmptyString; + } + void SChannel::setCACerts( const StringList& /*cacerts*/ ) {} void SChannel::setClientCert( const std::string& /*clientKey*/, const std::string& /*clientCerts*/ ) {} @@ -537,8 +571,7 @@ namespace gloox // unicode conversation // calculating unicode server name size csizeServerName = MultiByteToWideChar( CP_ACP, 0, serverName, -1, NULL, 0 ); - uServerName = reinterpret_cast( LocalAlloc( LMEM_FIXED, - csizeServerName * sizeof( WCHAR ) ) ); + uServerName = reinterpret_cast( malloc( csizeServerName * sizeof( WCHAR ) ) ); if( uServerName == NULL ) { //printf("SEC_E_INSUFFICIENT_MEMORY ~ Not enough memory!!!\n"); diff --git a/libs/libgloox/tlsschannel.h b/libs/libgloox/tlsschannel.h index 8286835..71b4a40 100644 --- a/libs/libgloox/tlsschannel.h +++ b/libs/libgloox/tlsschannel.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007-2009 by Jakob Schroeter + * Copyright (c) 2007-2015 by Jakob Schröter * This file is part of the gloox library. http://camaya.net/gloox * * This software is distributed under a license. The full license @@ -32,7 +32,7 @@ namespace gloox /** * This class implements a TLS backend using SChannel. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class SChannel : public TLSBase @@ -68,6 +68,12 @@ namespace gloox // reimplemented from TLSBase virtual bool handshake(); + // reimplemented from TLSBase + virtual bool hasChannelBinding() const; + + // reimplemented from TLSBase + virtual const std::string channelBinding() const; + // reimplemented from TLSBase virtual void setCACerts( const StringList& cacerts ); diff --git a/libs/libgloox/uniquemucroom.cpp b/libs/libgloox/uniquemucroom.cpp index 1ed1784..8f4cfcf 100644 --- a/libs/libgloox/uniquemucroom.cpp +++ b/libs/libgloox/uniquemucroom.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/uniquemucroom.h b/libs/libgloox/uniquemucroom.h index bfc39e2..39db8cf 100644 --- a/libs/libgloox/uniquemucroom.h +++ b/libs/libgloox/uniquemucroom.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -28,7 +28,7 @@ namespace gloox * to be used when converting one-to-one chats to multi-user chats. * * XEP version: 1.21 - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API UniqueMUCRoom : public InstantMUCRoom @@ -62,7 +62,7 @@ namespace gloox /** * @brief A stanza extension wrapping MUC's <unique> element. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class Unique : public StanzaExtension diff --git a/libs/libgloox/util.cpp b/libs/libgloox/util.cpp index f50026c..e4c6297 100644 --- a/libs/libgloox/util.cpp +++ b/libs/libgloox/util.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -13,6 +13,8 @@ #include "util.h" #include "gloox.h" +#include + namespace gloox { @@ -55,10 +57,21 @@ namespace gloox return i < size ? std::string( values[i] ) : def; } + std::string hex( const std::string& input ) + { + const char* H = input.c_str(); + char* buf = new char[input.length() * 2 + 1]; + for( unsigned int i = 0; i < input.length(); ++i ) + sprintf( buf + i * 2, "%02x", (unsigned char)( H[i] ) ); + return std::string( buf, 40 ); + } + static const char escape_chars[] = { '&', '<', '>', '\'', '"' }; static const std::string escape_seqs[] = { "amp;", "lt;", "gt;", "apos;", "quot;" }; + static const std::string escape_seqs_full[] = { "&", "<", ">", "'", """ }; + static const unsigned escape_size = 5; const std::string escape( std::string what ) @@ -79,23 +92,86 @@ namespace gloox return what; } + void appendEscaped( std::string& target, const std::string& data ) + { + size_t rangeStart = 0, rangeCount = 0; + size_t length = data.length(); + const char* dataPtr = data.data(); + for( size_t val, i = 0; i < length; ++i ) + { + const char current = dataPtr[i]; + for( val = 0; val < escape_size; ++val ) + { + if( current == escape_chars[val] ) + { + // We have a character that needs to be escaped. + if( rangeCount > 0 ) + { + // We have a range of the data that needs to be appended + // before we escape the current character. + // NOTE: Use "data" (std::string) here not dataPtr (const char*). + // Both have the same content, but there isn't + // an append override that takes const char*, pos, n + // (so a temporary std::string would be created) + target.append( data, rangeStart, rangeCount ); + } + target.append( escape_seqs_full[val] ); + rangeStart = i + 1; + rangeCount = 0; + break; + } + } + + if( rangeStart <= i ) + { + // current did not need to be escaped + ++rangeCount; + } + } + + if( rangeCount > 0 ) + { + // Append the remaining pending range of data that does + // not need to be escaped. + // NOTE: See previous comment on using data not dataPtr for append. + target.append( data, rangeStart, rangeCount ); + } + } + bool checkValidXMLChars( const std::string& data ) { if( data.empty() ) return true; - std::string::const_iterator it = data.begin(); - for( ; it != data.end() - && ( (unsigned char)(*it) == 0x09 - || (unsigned char)(*it) == 0x0a - || (unsigned char)(*it) == 0x0d - || ( (unsigned char)(*it) >= 0x20 - && (unsigned char)(*it) != 0xc0 - && (unsigned char)(*it) != 0xc1 - && (unsigned char)(*it) < 0xf5 ) ); ++it ) - ; + const char* dataPtr = data.data(); + const char* end = dataPtr + data.length(); + for( ; dataPtr != end; ++dataPtr ) + { + unsigned char current = (unsigned char) *dataPtr; + if( current < 0x20 ) + { + if( current == 0x09 + || current == 0x0a + || current == 0x0d ) + // Valid character + continue; + else + // Invalid character + break; + } + else if( current >= 0xf5 ) + // Invalid character + break; + else if( current == 0xc0 + || current == 0xc1 ) + // Invalid character + break; + else + // Valid character + continue; + } - return ( it == data.end() ); + return ( dataPtr == end ); } void replaceAll( std::string& target, const std::string& find, const std::string& replace ) diff --git a/libs/libgloox/util.h b/libs/libgloox/util.h index 63b3feb..d6dae97 100644 --- a/libs/libgloox/util.h +++ b/libs/libgloox/util.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -20,6 +20,7 @@ #include #include #include +#include namespace gloox { @@ -79,6 +80,13 @@ namespace gloox GLOOX_API const std::string _lookup2( unsigned code, const char* values[], unsigned size, const std::string& def = EmptyString ); + /** + * Returns the input string in hex notation. + * @param input The (binary) input string. + * @return The input string in hex notation. + */ + std::string hex( const std::string& input ); + /** * A convenience function that executes the given function on each object in a given list. * @param t The object to execute the function on. @@ -190,11 +198,24 @@ namespace gloox /** * Does some fancy escaping. (& --> &amp;, etc). + * @note If you intend to append the result of escape + * to another string, use the faster appendEscaped. * @param what A string to escape. * @return The escaped string. */ GLOOX_API const std::string escape( std::string what ); + /** + * Append the data to the target, doing any necessary escaping + * along the way (& --> &amp;, etc). + * This method is faster than calling "escape" and appending the + * return value, especially for source strings that don't need + * any escaping. + * @param target The string to append the data to. + * @param data The string to append that might need escaping. + */ + GLOOX_API void appendEscaped( std::string& target, const std::string& data ); + /** * Checks whether the given input is valid UTF-8. * @param data The data to check for validity. @@ -228,28 +249,25 @@ namespace gloox */ static inline const std::string long2string( long int value, const int base = 10 ) { - int add = 0; if( base < 2 || base > 16 || value == 0 ) return "0"; - else if( value < 0 ) + + std::string output; + std::string sign; + + if( value < 0 ) { - ++add; + sign += "-"; value = -value; } - int len = (int)( log( (double)( value ? value : 1 ) ) / log( (double)base ) ) + 1; - const char digits[] = "0123456789ABCDEF"; - char* num = (char*)calloc( len + 1 + add, sizeof( char ) ); - num[len--] = '\0'; - if( add ) - num[0] = '-'; - while( value && len > -1 ) + + while( output.empty() || value > 0 ) { - num[len-- + add] = digits[(int)( value % base )]; + output.insert( 0, 1, static_cast( value % base + '0' ) ); value /= base; } - const std::string result( num ); - free( num ); - return result; + + return sign + output; } /** diff --git a/libs/libgloox/vcard.cpp b/libs/libgloox/vcard.cpp index 740dcbe..cacda21 100644 --- a/libs/libgloox/vcard.cpp +++ b/libs/libgloox/vcard.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -104,6 +104,8 @@ namespace gloox std::string::size_type pos = 0; while( ( pos = binval.find( '\n' ) ) != std::string::npos ) binval.erase( pos, 1 ); + while( ( pos = binval.find( '\r' ) ) != std::string::npos ) + binval.erase( pos, 1 ); m_photo.type = tag.findChild( "TYPE" )->cdata(); m_photo.binval = Base64::decode64( binval ); m_PHOTO = true; @@ -122,6 +124,8 @@ namespace gloox std::string::size_type pos = 0; while( ( pos = binval.find( '\n' ) ) != std::string::npos ) binval.erase( pos, 1 ); + while( ( pos = binval.find( '\r' ) ) != std::string::npos ) + binval.erase( pos, 1 ); m_logo.type = tag.findChild( "TYPE" )->cdata(); m_logo.binval = Base64::decode64( binval ); m_LOGO = true; @@ -236,7 +240,7 @@ namespace gloox m_N = true; } - void VCard::setPhoto( const std::string& extval ) + void VCard::setPhotoUri( const std::string& extval ) { if( !extval.empty() ) { diff --git a/libs/libgloox/vcard.h b/libs/libgloox/vcard.h index 3d28f19..ed8f405 100644 --- a/libs/libgloox/vcard.h +++ b/libs/libgloox/vcard.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -28,7 +28,7 @@ namespace gloox * See @link gloox::VCardManager VCardManager @endlink for info on how to * fetch VCards. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.8 */ class GLOOX_API VCard : public StanzaExtension @@ -39,7 +39,7 @@ namespace gloox * @note @c AddrTypeDom and @c AddrTypeIntl are mutually exclusive. If both are present, * @c AddrTypeDom takes precendence. * @note Also note that not all adress types are applicable everywhere. For example, - * @c AddrTypeIsdn does not make sense for a postal address. Check XEP-0054 + * @c AddrTypeIsdn does not make sense for a postal address. Check @xep{0054} * for details. */ enum AddressType @@ -428,7 +428,7 @@ namespace gloox * Sets a URI to a photo. * @param extval The URI to the photo. */ - void setPhoto( const std::string& extval ); + void setPhotoUri( const std::string& extval ); /** * Sets the photo directly. @@ -475,7 +475,7 @@ namespace gloox * Returns a list of email addresses. * @return A list of email addresses. */ - EmailList& emailAddresses() { return m_emailList; } + const EmailList& emailAddresses() const { return m_emailList; } /** * Adds an address. @@ -504,13 +504,13 @@ namespace gloox * Returns a list of addresses. * @return A list of addresses. */ - AddressList& addresses() { return m_addressList; } + const AddressList& addresses() const { return m_addressList; } /** * Returns a list of address labels. * @return A list of address labels. */ - LabelList& labels() { return m_labelList; } + const LabelList& labels() const { return m_labelList; } /** * Adds a telephone number. @@ -523,7 +523,7 @@ namespace gloox * Returns a list of telephone numbers. * @return A list of telephone numbers. */ - TelephoneList& telephone() { return m_telephoneList; } + const TelephoneList& telephone() const { return m_telephoneList; } /** * Sets "Geographical position. Values are the decimal degrees of @@ -562,7 +562,7 @@ namespace gloox * Returns information about classification. * @return Info about the classification. */ - VCardClassification classification() const { return m_class; } + const VCardClassification& classification() const { return m_class; } // reimplemented from StanzaExtension virtual const std::string& filterString() const; diff --git a/libs/libgloox/vcardhandler.h b/libs/libgloox/vcardhandler.h index c1e2c67..a78d55a 100644 --- a/libs/libgloox/vcardhandler.h +++ b/libs/libgloox/vcardhandler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -30,7 +30,7 @@ namespace gloox * See @link gloox::VCardManager VCardManager @endlink for info on how to * fetch VCards. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.8 */ class GLOOX_API VCardHandler diff --git a/libs/libgloox/vcardmanager.cpp b/libs/libgloox/vcardmanager.cpp index 2845e82..91864f8 100644 --- a/libs/libgloox/vcardmanager.cpp +++ b/libs/libgloox/vcardmanager.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license diff --git a/libs/libgloox/vcardmanager.h b/libs/libgloox/vcardmanager.h index 4796890..3c190b4 100644 --- a/libs/libgloox/vcardmanager.h +++ b/libs/libgloox/vcardmanager.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -72,7 +72,7 @@ namespace gloox * @section sec_store Storing one's own VCard * * @note Some, if not many, servers do not implement support for all the fields specified - * in XEP-0054. Therefore it is possible that you cannot retrieve fields you stored previously. + * in @xep{0054}. Therefore it is possible that you cannot retrieve fields you stored previously. * * Similar to the above, you need a VCardManager and a VCardHandler. Then construct * your VCard and call storeVCard(). @@ -94,7 +94,7 @@ namespace gloox * * When cleaning up, delete your VCardManager instance @b before deleting the Client/ClientBase instance. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.8 */ class GLOOX_API VCardManager : public IqHandler diff --git a/libs/libgloox/vcardupdate.cpp b/libs/libgloox/vcardupdate.cpp index fd88ce1..e0b83f5 100644 --- a/libs/libgloox/vcardupdate.cpp +++ b/libs/libgloox/vcardupdate.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -19,24 +19,21 @@ namespace gloox VCardUpdate::VCardUpdate() : StanzaExtension( ExtVCardUpdate ), - m_notReady( true ), m_noImage( true ), m_valid( true ) + m_notReady( true ), m_noImage( true ), m_valid( true ), m_hasPhoto( false ) { } VCardUpdate::VCardUpdate( const std::string& hash ) : StanzaExtension( ExtVCardUpdate ), - m_hash( hash ), m_notReady( false ), m_noImage( false ), m_valid( true ) + m_hash( hash ), m_notReady( false ), m_noImage( false ), m_valid( true ), m_hasPhoto( false ) { if( m_hash.empty() ) - { m_noImage = true; - m_valid = false; - } } VCardUpdate::VCardUpdate( const Tag* tag ) : StanzaExtension( ExtVCardUpdate ), - m_notReady( true ), m_noImage( true ), m_valid( false ) + m_notReady( true ), m_noImage( true ), m_valid( false ), m_hasPhoto( false ) { if( tag && tag->name() == "x" && tag->hasAttribute( XMLNS, XMLNS_X_VCARD_UPDATE ) ) { @@ -44,6 +41,9 @@ namespace gloox if( tag->hasChild( "photo" ) ) { m_notReady = false; + if( tag->hasChild( "photo" ) ) + m_hasPhoto = true; + m_hash = tag->findChild( "photo" )->cdata(); if( !m_hash.empty() ) m_noImage = false; diff --git a/libs/libgloox/vcardupdate.h b/libs/libgloox/vcardupdate.h index e952ecf..3dd080b 100644 --- a/libs/libgloox/vcardupdate.h +++ b/libs/libgloox/vcardupdate.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 by Jakob Schroeter + Copyright (c) 2006-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -25,11 +25,11 @@ namespace gloox class Tag; /** - * @brief This is an abstraction of a vcard-temp:x:update namespace element, as used in XEP-0153 + * @brief This is an abstraction of a vcard-temp:x:update namespace element, as used in @xep{0153} * (vCard-Based Avatars). * * XEP version: 1.0 - * @author Jakob Schroeter + * @author Jakob Schröter * @since 0.9 */ class GLOOX_API VCardUpdate : public StanzaExtension @@ -63,6 +63,16 @@ namespace gloox * @return The avatar's SHA hash. */ const std::string& hash() const { return m_hash; } + + /** + * Indicates whether the VCard update contained a @c photo tag + * (which might have been empty). + * This function is only useful for incoming VCardUpdate objects. + * @return @b True if the VCard update contained a @c photo + * tag (empty or non-empty), @b false otherwise. + * @since 1.0.3 + */ + bool hasPhoto() { return m_hasPhoto; } // reimplemented from StanzaExtension virtual const std::string& filterString() const; @@ -87,6 +97,7 @@ namespace gloox bool m_notReady; bool m_noImage; bool m_valid; + bool m_hasPhoto; }; diff --git a/libs/libgloox/xhtmlim.cpp b/libs/libgloox/xhtmlim.cpp index 9261eec..7ea56c3 100644 --- a/libs/libgloox/xhtmlim.cpp +++ b/libs/libgloox/xhtmlim.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -50,7 +50,7 @@ namespace gloox { XHtmlIM* x = new XHtmlIM(); x->m_xhtml = m_xhtml ? m_xhtml->clone() : 0; - return 0; + return x; } } diff --git a/libs/libgloox/xhtmlim.h b/libs/libgloox/xhtmlim.h index 974ee9f..0b0ae15 100644 --- a/libs/libgloox/xhtmlim.h +++ b/libs/libgloox/xhtmlim.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2007-2009 by Jakob Schroeter + Copyright (c) 2007-2015 by Jakob Schröter This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license @@ -26,9 +26,9 @@ namespace gloox class Tag; /** - * @brief This is a wrapper of an XHTML-IM (XEP-0071) message body. + * @brief This is a wrapper of an XHTML-IM (@xep{0071}) message body. * - * @author Jakob Schroeter + * @author Jakob Schröter * @since 1.0 */ class GLOOX_API XHtmlIM : public StanzaExtension