Outgoing client stream: handle the situation when user's domain is hosted by another domain.

git-svn-id: http://voip.null.ro/svn/yate@4616 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
marian 2011-09-15 14:54:12 +00:00
parent 82c1ece8bf
commit 38e791aaff
3 changed files with 33 additions and 13 deletions

View File

@ -562,7 +562,7 @@ void SASL::buildMD5Digest(String& dest, const NamedList& params,
*/ */
// Constructor. Add itself to the stream's engine // Constructor. Add itself to the stream's engine
JBConnect::JBConnect(const JBStream& stream) JBConnect::JBConnect(const JBStream& stream)
: m_status(Start), m_domain(stream.remote().domain()), m_port(0), : m_status(Start), m_domain(stream.serverHost()), m_port(0),
m_engine(stream.engine()), m_stream(stream.toString()), m_engine(stream.engine()), m_stream(stream.toString()),
m_streamType((JBStream::Type)stream.type()) m_streamType((JBStream::Type)stream.type())
{ {
@ -1679,10 +1679,18 @@ JBClientStream* JBClientEngine::create(const String& account, const NamedList& p
{ {
if (!account) if (!account)
return 0; return 0;
const char* domain = params.getValue("domain"); String serverHost;
if (TelEngine::null(domain)) String username = params.getValue("username");
String domain = params.getValue("domain");
int pos = username.find("@");
if (pos > 0) {
serverHost = domain;
domain = username.substr(pos + 1);
username = username.substr(0,pos);
}
if (!domain)
domain = params.getValue("server",params.getValue("address")); domain = params.getValue("server",params.getValue("address"));
JabberID jid(params.getValue("username"),domain,params.getValue("resource")); JabberID jid(username,domain,params.getValue("resource"));
if (!jid.bare()) { if (!jid.bare()) {
Debug(this,DebugNote,"Can't create client stream: invalid jid=%s",jid.bare().c_str()); Debug(this,DebugNote,"Can't create client stream: invalid jid=%s",jid.bare().c_str());
return 0; return 0;
@ -1690,7 +1698,7 @@ JBClientStream* JBClientEngine::create(const String& account, const NamedList& p
Lock lock(this); Lock lock(this);
JBClientStream* stream = static_cast<JBClientStream*>(findAccount(account)); JBClientStream* stream = static_cast<JBClientStream*>(findAccount(account));
if (!stream) { if (!stream) {
stream = new JBClientStream(this,jid,account,params,name); stream = new JBClientStream(this,jid,account,params,name,serverHost);
stream->ref(); stream->ref();
addStream(stream); addStream(stream);
} }

View File

@ -173,10 +173,10 @@ JBStream::JBStream(JBEngine* engine, Socket* socket, Type t, bool ssl)
// Outgoing // Outgoing
JBStream::JBStream(JBEngine* engine, Type t, const JabberID& local, const JabberID& remote, JBStream::JBStream(JBEngine* engine, Type t, const JabberID& local, const JabberID& remote,
const char* name, const NamedList* params) const char* name, const NamedList* params, const char* serverHost)
: Mutex(true,"JBStream"), : Mutex(true,"JBStream"),
m_sasl(0), m_sasl(0),
m_state(Idle), m_local(local), m_remote(remote), m_state(Idle), m_local(local), m_remote(remote), m_serverHost(serverHost),
m_flags(0), m_xmlns(XMPPNamespace::Count), m_lastEvent(0), m_flags(0), m_xmlns(XMPPNamespace::Count), m_lastEvent(0),
m_setupTimeout(0), m_startTimeout(0), m_setupTimeout(0), m_startTimeout(0),
m_pingTimeout(0), m_nextPing(0), m_pingTimeout(0), m_nextPing(0),
@ -204,8 +204,8 @@ JBStream::JBStream(JBEngine* engine, Type t, const JabberID& local, const Jabber
// Compress always defaults to true if not explicitly disabled // Compress always defaults to true if not explicitly disabled
if (!flag(Compress) && !(params && params->getBoolValue("nocompression"))) if (!flag(Compress) && !(params && params->getBoolValue("nocompression")))
setFlags(Compress); setFlags(Compress);
Debug(this,DebugAll,"JBStream::JBStream(%p,%s,%s,%s) outgoing [%p]", Debug(this,DebugAll,"JBStream::JBStream(%p,%s,%s,%s,%s) outgoing [%p]",
engine,typeName(),local.c_str(),remote.c_str(),this); engine,typeName(),local.c_str(),remote.c_str(),m_serverHost.safe(),this);
setXmlns(); setXmlns();
changeState(Idle); changeState(Idle);
} }
@ -2488,8 +2488,9 @@ JBClientStream::JBClientStream(JBEngine* engine, Socket* socket, bool ssl)
} }
JBClientStream::JBClientStream(JBEngine* engine, const JabberID& jid, const String& account, JBClientStream::JBClientStream(JBEngine* engine, const JabberID& jid, const String& account,
const NamedList& params, const char* name) const NamedList& params, const char* name, const char* serverHost)
: JBStream(engine,c2s,jid,jid.domain(),TelEngine::null(name) ? account.c_str() : name,&params), : JBStream(engine,c2s,jid,jid.domain(),TelEngine::null(name) ? account.c_str() : name,
&params,serverHost),
m_account(account), m_userData(0), m_registerReq(0) m_account(account), m_userData(0), m_registerReq(0)
{ {
m_password = params.getValue("password"); m_password = params.getValue("password");

View File

@ -731,6 +731,14 @@ public:
void connectAddr(String& addr, int& port, String& localip, int& stat, void connectAddr(String& addr, int& port, String& localip, int& stat,
ObjList& srvs) const; ObjList& srvs) const;
/**
* Retrieve server host when connecting.
* This method is not thread safe
* @return Server host if set, remote jid's domain otherwise
*/
inline const String& serverHost() const
{ return m_serverHost ? m_serverHost : m_remote.domain(); }
/** /**
* Set/reset RosterRequested flag * Set/reset RosterRequested flag
* This method is thread safe * This method is thread safe
@ -954,9 +962,10 @@ protected:
* @param remote Remote party jabber id * @param remote Remote party jabber id
* @param name Optional stream name * @param name Optional stream name
* @param params Optional stream parameters * @param params Optional stream parameters
* @param serverHost Optional server host to use instead of jid domain
*/ */
JBStream(JBEngine* engine, Type t, const JabberID& local, const JabberID& remote, JBStream(JBEngine* engine, Type t, const JabberID& local, const JabberID& remote,
const char* name = 0, const NamedList* params = 0); const char* name = 0, const NamedList* params = 0, const char* serverHost = 0);
/** /**
* Close the stream. Release memory * Close the stream. Release memory
@ -1194,6 +1203,7 @@ protected:
String m_id; // Stream id String m_id; // Stream id
JabberID m_local; // Local peer's jid JabberID m_local; // Local peer's jid
JabberID m_remote; // Remote peer's jid JabberID m_remote; // Remote peer's jid
String m_serverHost; // Outgoing: optional server host (replaces remote domain when connecting)
int m_flags; // Stream flags int m_flags; // Stream flags
XMPPNamespace::Type m_xmlns; // Stream namespace XMPPNamespace::Type m_xmlns; // Stream namespace
XMPPFeatureList m_features; // Advertised features XMPPFeatureList m_features; // Advertised features
@ -1361,9 +1371,10 @@ public:
* @param account Account (stream) name * @param account Account (stream) name
* @param params Stream parameters * @param params Stream parameters
* @param name Optional stream name * @param name Optional stream name
* @param serverHost Optional server host to use instead of jid domain
*/ */
JBClientStream(JBEngine* engine, const JabberID& jid, const String& account, JBClientStream(JBEngine* engine, const JabberID& jid, const String& account,
const NamedList& params, const char* name = 0); const NamedList& params, const char* name = 0, const char* serverHost = 0);
/** /**
* Retrieve stream's account * Retrieve stream's account