14 #include "configmanager.h"
19 #include <gloox/error.h>
20 #include <gloox/gloox.h>
22 #include <gloox/logsink.h>
23 #include <gloox/message.h>
24 #include <gloox/presence.h>
25 #include <gloox/taghandler.h>
26 #include <gloox/util.h>
34 : m_cm( cm ), m_logInstance( logInstance ), m_threading( threading )
41 gloox::util::clearList( m_queue );
46 if( !m_threading && !m_queue.size() )
51 m_queueSemaphore.
wait();
52 gloox::Tag* t = m_queue.front();
55 m_queueMutex.unlock();
57 }
while( m_threading );
64 m_queue.push_back( 0 );
65 m_queueMutex.unlock();
72 m_logInstance.dbg( static_cast<gloox::LogArea>(
LogAreaRouter ),
73 "Registered target for " + domain +
", for user traffic" );
74 gloox::util::MutexGuard mg(m_userRoutingMutex );
75 m_userRouting.insert( std::make_pair( domain, th ) );
79 m_logInstance.dbg( static_cast<gloox::LogArea>(
LogAreaRouter ),
80 "Registered target for " + domain +
", for domain traffic" );
81 gloox::util::MutexGuard mg(m_domainRoutingMutex );
82 m_domainRouting.insert( std::make_pair( domain, th ) );
86 bool Router::isLocal(
const std::string& )
92 void Router::removeDomain( TagHandler* ,
const std::string& domain,
bool node )
96 gloox::util::MutexGuard mg(m_userRoutingMutex );
97 RoutingTable::iterator it = m_userRouting.find( domain );
98 if( it !=m_userRouting.end() )
100 m_userRouting.erase( it );
101 m_logInstance.dbg( static_cast<gloox::LogArea>(
LogAreaRouter ),
102 "Removed target for " + domain +
", for user traffic" );
107 gloox::util::MutexGuard mg(m_domainRoutingMutex );
108 RoutingTable::iterator it = m_domainRouting.find( domain );
109 if( it != m_domainRouting.end() )
111 m_domainRouting.erase( it );
112 m_logInstance.dbg( static_cast<gloox::LogArea>(
LogAreaRouter ),
113 "Removed target for " + domain +
", for domain traffic" );
118 void Router::handleIncomingTag( gloox::Tag* tag )
124 m_queue.push_back( tag );
125 m_queueMutex.unlock();
126 m_queueSemaphore.
post();
129 void Router::handleTag( gloox::Tag* tag )
135 printf(
"!!!!!Router::handleTag(): %s\n", tag->xml().c_str() );
137 const gloox::JID to( tag->findAttribute(
"to" ) );
140 routeBySender( tag );
141 else if( isLocal( to.server() ) )
142 routeByReceipient( tag );
145 gloox::Tag* t =
returnError( tag, gloox::StanzaErrorRemoteServerNotFound );
146 handleIncomingTag( t );
151 void Router::routeBySender( gloox::Tag* tag )
156 printf(
"!!!!!Router::routeBySender(): %s\n", tag->xml().c_str() );
159 const gloox::JID from( tag->findAttribute(
"from" ) );
161 gloox::util::MutexGuard mg( m_domainRoutingMutex );
162 RoutingTable::const_iterator it = m_domainRouting.find( from.server() );
163 if( it == m_domainRouting.end() )
170 printf(
"!!!!!found domain destination by 'from'\n" );
172 (*it).second->handleIncomingTag( tag );
175 void Router::routeByReceipient( gloox::Tag* tag )
181 printf(
"!!!!!Router::routeByReceipient(): %s\n", tag->xml().c_str() );
183 const gloox::JID to( tag->findAttribute(
"to" ) );
186 if( to.username().empty() || to.resource().empty() )
188 gloox::util::MutexGuard mg( m_domainRoutingMutex );
189 RoutingTable::const_iterator it = m_domainRouting.find( to.server() );
190 if( it != m_domainRouting.end() )
193 printf(
"!!!!!found domain destination by 'to'\n" );
195 (*it).second->handleIncomingTag( tag );
201 gloox::util::MutexGuard mg( m_userRoutingMutex );
202 RoutingTable::const_iterator it = m_userRouting.find( to.server() );
203 if( it != m_userRouting.end() )
206 printf(
"!!!!!found user destination by 'to'\n" );
208 (*it).second->handleOutgoingTag( tag );
213 gloox::Tag* t =
returnError( tag, gloox::StanzaErrorRemoteServerNotFound );
214 handleIncomingTag( t );