Removed client stream useless class. Added more stanza types and namespaces.
git-svn-id: http://yate.null.ro/svn/yate/trunk@1726 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
73a496ae0b
commit
f87630067c
|
@ -408,6 +408,7 @@ void JBEngine::cleanup()
|
||||||
for (ObjList* o = m_streams.skipNull(); o; o = o->skipNext()) {
|
for (ObjList* o = m_streams.skipNull(); o; o = o->skipNext()) {
|
||||||
JBStream* s = static_cast<JBStream*>(o->get());
|
JBStream* s = static_cast<JBStream*>(o->get());
|
||||||
s->terminate(true,0,XMPPError::Shutdown,0,true);
|
s->terminate(true,0,XMPPError::Shutdown,0,true);
|
||||||
|
s->cleanup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -446,10 +447,7 @@ JBStream* JBEngine::getStream(const JabberID* jid, bool create, const char* pwd)
|
||||||
const JabberID* remote = jid;
|
const JabberID* remote = jid;
|
||||||
// Set remote to be a valid pointer
|
// Set remote to be a valid pointer
|
||||||
if (!remote)
|
if (!remote)
|
||||||
if (m_protocol == Component)
|
remote = &m_componentDomain;
|
||||||
remote = &m_componentDomain;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
// Find the stream
|
// Find the stream
|
||||||
JBStream* stream = 0;
|
JBStream* stream = 0;
|
||||||
for (ObjList* o = m_streams.skipNull(); o; o = o->skipNext()) {
|
for (ObjList* o = m_streams.skipNull(); o; o = o->skipNext()) {
|
||||||
|
@ -469,12 +467,9 @@ JBStream* JBEngine::getStream(const JabberID* jid, bool create, const char* pwd)
|
||||||
SocketAddr addr(PF_INET);
|
SocketAddr addr(PF_INET);
|
||||||
addr.host(info->address());
|
addr.host(info->address());
|
||||||
addr.port(info->port());
|
addr.port(info->port());
|
||||||
if (m_protocol == Component)
|
stream = new JBComponentStream(this,JabberID(0,info->identity(),0),
|
||||||
stream = new JBComponentStream(this,JabberID(0,info->identity(),0),
|
*remote,info->password(),addr,
|
||||||
*remote,info->password(),addr,
|
info->autoRestart(),m_restartCount,m_restartUpdateInterval);
|
||||||
true,m_restartCount,m_restartUpdateInterval);
|
|
||||||
else
|
|
||||||
stream = new JBClientStream(this,*jid,pwd,addr,m_restartCount,m_restartUpdateInterval);
|
|
||||||
m_streams.append(stream);
|
m_streams.append(stream);
|
||||||
}
|
}
|
||||||
return ((stream && stream->ref()) ? stream : 0);
|
return ((stream && stream->ref()) ? stream : 0);
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
using namespace TelEngine;
|
using namespace TelEngine;
|
||||||
|
|
||||||
static XMPPNamespace s_ns;
|
static XMPPNamespace s_ns; // Just use the operators
|
||||||
static XMPPError s_err;
|
static XMPPError s_err;
|
||||||
|
|
||||||
static TokenDict s_streamState[] = {
|
static TokenDict s_streamState[] = {
|
||||||
|
@ -39,10 +39,13 @@ static TokenDict s_streamState[] = {
|
||||||
{0,0},
|
{0,0},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static String s_version = "1.0"; // Protocol version
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JBSocket
|
* JBSocket
|
||||||
*/
|
*/
|
||||||
|
// Connect the socket
|
||||||
bool JBSocket::connect(const SocketAddr& addr, bool& terminated)
|
bool JBSocket::connect(const SocketAddr& addr, bool& terminated)
|
||||||
{
|
{
|
||||||
terminate();
|
terminate();
|
||||||
|
@ -82,6 +85,7 @@ bool JBSocket::connect(const SocketAddr& addr, bool& terminated)
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close the socket
|
||||||
void JBSocket::terminate()
|
void JBSocket::terminate()
|
||||||
{
|
{
|
||||||
Lock2 lck(m_streamMutex,m_receiveMutex);
|
Lock2 lck(m_streamMutex,m_receiveMutex);
|
||||||
|
@ -94,6 +98,7 @@ void JBSocket::terminate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Read data from socket
|
||||||
bool JBSocket::recv(char* buffer, unsigned int& len)
|
bool JBSocket::recv(char* buffer, unsigned int& len)
|
||||||
{
|
{
|
||||||
if (!valid())
|
if (!valid())
|
||||||
|
@ -122,6 +127,7 @@ bool JBSocket::recv(char* buffer, unsigned int& len)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write data to socket
|
||||||
bool JBSocket::send(const char* buffer, unsigned int& len)
|
bool JBSocket::send(const char* buffer, unsigned int& len)
|
||||||
{
|
{
|
||||||
if (!valid())
|
if (!valid())
|
||||||
|
@ -230,22 +236,21 @@ void JBStream::connect()
|
||||||
"Stream. Attempt to connect local=%s remote=%s addr=%s:%d count=%u [%p]",
|
"Stream. Attempt to connect local=%s remote=%s addr=%s:%d count=%u [%p]",
|
||||||
m_local.safe(),m_remote.safe(),m_address.host().safe(),m_address.port(),
|
m_local.safe(),m_remote.safe(),m_address.host().safe(),m_address.port(),
|
||||||
m_restart,this);
|
m_restart,this);
|
||||||
changeState(Connecting);
|
// Check if we can restart. Destroy the stream if not auto restarting
|
||||||
// Check if we can restart
|
if (m_restart)
|
||||||
if (!m_restart) {
|
m_restart--;
|
||||||
terminate(true,0,XMPPError::NoError,"restart counter is 0",false);
|
else
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
m_restart--;
|
|
||||||
// Reset data
|
// Reset data
|
||||||
m_id = "";
|
m_id = "";
|
||||||
m_parser.reset();
|
m_parser.reset();
|
||||||
lck.drop();
|
lck.drop();
|
||||||
// Re-connect socket
|
// Re-connect socket
|
||||||
bool terminated = false;
|
bool terminated = false;
|
||||||
|
changeState(Connecting);
|
||||||
if (!m_socket.connect(m_address,terminated)) {
|
if (!m_socket.connect(m_address,terminated)) {
|
||||||
if (!terminated)
|
if (!terminated)
|
||||||
terminate(false,0,XMPPError::NoError,"connection failed",false);
|
terminate(false,0,XMPPError::NoError,"connection-failed",false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,7 +258,8 @@ void JBStream::connect()
|
||||||
m_local.safe(),m_remote.safe(),m_address.host().safe(),m_address.port(),this);
|
m_local.safe(),m_remote.safe(),m_address.host().safe(),m_address.port(),this);
|
||||||
|
|
||||||
// Send declaration
|
// Send declaration
|
||||||
static String declaration = "<?xml version='1.0' encoding='UTF-8'?>";
|
String declaration;
|
||||||
|
declaration << "<?xml version='" << s_version << "' encoding='UTF-8'?>";
|
||||||
if (m_engine->printXml() && m_engine->debugAt(DebugInfo))
|
if (m_engine->printXml() && m_engine->debugAt(DebugInfo))
|
||||||
Debug(m_engine,DebugInfo,"Stream. Sending XML declaration %s [%p]",
|
Debug(m_engine,DebugInfo,"Stream. Sending XML declaration %s [%p]",
|
||||||
declaration.c_str(),this);
|
declaration.c_str(),this);
|
||||||
|
@ -325,26 +331,43 @@ JBEvent* JBStream::getEvent(u_int64_t time)
|
||||||
{
|
{
|
||||||
Lock lock(m_socket.m_streamMutex);
|
Lock lock(m_socket.m_streamMutex);
|
||||||
|
|
||||||
// Do nothing if destroying or connecting
|
|
||||||
if (state() == Destroy || state() == Connecting)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
// Increase stream restart counter if it's time to
|
// Increase stream restart counter if it's time to
|
||||||
if (m_timeToFillRestart < time) {
|
if (m_timeToFillRestart < time) {
|
||||||
if (m_restart < m_restartMax)
|
if (m_restart < m_restartMax) {
|
||||||
m_restart++;
|
m_restart++;
|
||||||
|
Debug(m_engine,DebugAll,"Stream. restart count=%u max=%u [%p]",
|
||||||
|
m_restart,m_restartMax,this);
|
||||||
|
}
|
||||||
m_timeToFillRestart = time + m_fillRestartInterval;
|
m_timeToFillRestart = time + m_fillRestartInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state() == Idle) {
|
|
||||||
if (m_autoRestart && m_restart)
|
|
||||||
m_engine->connect(this);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_lastEvent)
|
if (m_lastEvent)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
// Do nothing if destroying or connecting
|
||||||
|
// Just check Terminated or Running events
|
||||||
|
// Idle: check if we can restart. Destroy the stream if not auto restarting
|
||||||
|
if (state() == Idle || state() == Destroy || state() == Connecting) {
|
||||||
|
if (state() == Idle) {
|
||||||
|
if (m_restart && m_autoRestart) {
|
||||||
|
lock.drop();
|
||||||
|
m_engine->connect(this);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (!m_autoRestart)
|
||||||
|
terminate(true,0,XMPPError::NoError,"connection-failed",false);
|
||||||
|
}
|
||||||
|
if (m_terminateEvent) {
|
||||||
|
m_lastEvent = m_terminateEvent;
|
||||||
|
m_terminateEvent = 0;
|
||||||
|
}
|
||||||
|
else if (m_startEvent) {
|
||||||
|
m_lastEvent = m_startEvent;
|
||||||
|
m_startEvent = 0;
|
||||||
|
}
|
||||||
|
return m_lastEvent;
|
||||||
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (m_terminateEvent)
|
if (m_terminateEvent)
|
||||||
break;
|
break;
|
||||||
|
@ -452,7 +475,7 @@ void JBStream::terminate(bool destroy, XMLElement* recvStanza, XMPPError::Type e
|
||||||
const char* reason, bool send, bool final)
|
const char* reason, bool send, bool final)
|
||||||
{
|
{
|
||||||
Lock2 lock(m_socket.m_streamMutex,m_socket.m_receiveMutex);
|
Lock2 lock(m_socket.m_streamMutex,m_socket.m_receiveMutex);
|
||||||
if (state() == Destroy || state() == Idle) {
|
if (state() == Destroy) {
|
||||||
if (recvStanza)
|
if (recvStanza)
|
||||||
delete recvStanza;
|
delete recvStanza;
|
||||||
return;
|
return;
|
||||||
|
@ -463,11 +486,11 @@ void JBStream::terminate(bool destroy, XMLElement* recvStanza, XMPPError::Type e
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug(m_engine,DebugAll,
|
Debug(m_engine,DebugAll,
|
||||||
"Stream. Terminate state=%s destroy=%u error=%s reason=%s final=%u [%p]",
|
"Stream. Terminate state=%s destroy=%u error=%s reason='%s' final=%u [%p]",
|
||||||
lookupState(state()),destroy,s_err[error],reason,final,this);
|
lookupState(state()),destroy,s_err[error],reason,final,this);
|
||||||
|
|
||||||
// Send ending stream element
|
// Send ending stream element
|
||||||
if (send && state() != Connecting) {
|
if (send && state() != Connecting && state() != Idle) {
|
||||||
XMLElement* e;
|
XMLElement* e;
|
||||||
if (error == XMPPError::NoError)
|
if (error == XMPPError::NoError)
|
||||||
e = new XMLElement(XMLElement::StreamEnd);
|
e = new XMLElement(XMLElement::StreamEnd);
|
||||||
|
@ -498,14 +521,18 @@ void JBStream::terminate(bool destroy, XMLElement* recvStanza, XMPPError::Type e
|
||||||
removePending(false,0,true);
|
removePending(false,0,true);
|
||||||
// Always set termination event, except when exiting
|
// Always set termination event, except when exiting
|
||||||
TelEngine::destruct(m_startEvent);
|
TelEngine::destruct(m_startEvent);
|
||||||
if (!m_terminateEvent) {
|
if (!(m_terminateEvent || m_engine->exiting())) {
|
||||||
if (!recvStanza && error != XMPPError::NoError)
|
if (!recvStanza && error != XMPPError::NoError)
|
||||||
recvStanza = XMPPUtils::createStreamError(error,reason);
|
recvStanza = XMPPUtils::createStreamError(error,reason);
|
||||||
if (error != XMPPError::Shutdown)
|
Debug(m_engine,DebugAll,"Stream. Set terminate error=%s reason=%s [%p]",
|
||||||
m_terminateEvent = new JBEvent(destroy?JBEvent::Destroy:JBEvent::Terminated,
|
s_err[error],reason,this);
|
||||||
this,recvStanza);
|
m_terminateEvent = new JBEvent(destroy?JBEvent::Destroy:JBEvent::Terminated,
|
||||||
|
this,recvStanza);
|
||||||
|
if (!recvStanza)
|
||||||
|
m_terminateEvent->m_text = reason;
|
||||||
|
recvStanza = 0;
|
||||||
}
|
}
|
||||||
else if (recvStanza)
|
if (recvStanza)
|
||||||
delete recvStanza;
|
delete recvStanza;
|
||||||
|
|
||||||
// Change state
|
// Change state
|
||||||
|
@ -886,46 +913,6 @@ void JBStream::removePending(bool notify, const String* id, bool force)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JBClientStream
|
|
||||||
*/
|
|
||||||
JBClientStream::JBClientStream(JBEngine* engine, const JabberID& jid,
|
|
||||||
const String& password, const SocketAddr& address,
|
|
||||||
unsigned int maxRestart, u_int64_t incRestartInterval, bool outgoing)
|
|
||||||
: JBStream(engine,jid,JabberID(0,jid.domain(),0),password,address,
|
|
||||||
true,maxRestart,incRestartInterval,outgoing,JBEngine::Client)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the starting stream element to be sent after stream connected
|
|
||||||
XMLElement* JBClientStream::getStreamStart()
|
|
||||||
{
|
|
||||||
Debug(engine(),DebugStub,"Please implement JBComponentStream::getStreamStart()");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process a received element in Securing state
|
|
||||||
void JBClientStream::processSecuring(XMLElement* xml)
|
|
||||||
{
|
|
||||||
Debug(engine(),DebugStub,"Please implement JBComponentStream::processSecuring()");
|
|
||||||
dropXML(xml);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process a received element in Auth state
|
|
||||||
void JBClientStream::processAuth(XMLElement* xml)
|
|
||||||
{
|
|
||||||
Debug(engine(),DebugStub,"Please implement JBComponentStream::processAuth()");
|
|
||||||
dropXML(xml);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process a received element in Started state
|
|
||||||
void JBClientStream::processStarted(XMLElement* xml)
|
|
||||||
{
|
|
||||||
Debug(engine(),DebugStub,"Please implement JBComponentStream::processStarted()");
|
|
||||||
dropXML(xml);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JBComponentStream
|
* JBComponentStream
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -30,29 +30,42 @@ using namespace TelEngine;
|
||||||
* XMLElement
|
* XMLElement
|
||||||
*/
|
*/
|
||||||
TokenDict XMLElement::s_names[] = {
|
TokenDict XMLElement::s_names[] = {
|
||||||
{"stream:stream", StreamStart},
|
{"stream:stream", StreamStart},
|
||||||
{"/stream:stream", StreamEnd},
|
{"/stream:stream", StreamEnd},
|
||||||
{"stream:error", StreamError},
|
{"stream:error", StreamError},
|
||||||
{"handshake", Handshake},
|
{"stream::features", StreamFeatures},
|
||||||
{"iq", Iq},
|
{"starttls", Starttls},
|
||||||
{"message", Message},
|
{"handshake", Handshake},
|
||||||
{"presence", Presence},
|
{"auth", Auth},
|
||||||
{"error", Error},
|
{"challenge", Challenge},
|
||||||
{"query", Query},
|
{"abort", Abort},
|
||||||
{"session", Jingle},
|
{"aborted", Aborted},
|
||||||
{"description", Description},
|
{"response", Response},
|
||||||
{"payload-type", PayloadType},
|
{"success", Success},
|
||||||
{"transport", Transport},
|
{"failure", Failure},
|
||||||
{"candidate", Candidate},
|
{"mechanisms", Mechanisms},
|
||||||
{"body", Body},
|
{"mechanism", Mechanism},
|
||||||
{"feature", Feature},
|
{"session", Session},
|
||||||
{"bind", Bind},
|
{"iq", Iq},
|
||||||
{"resource", Resource},
|
{"message", Message},
|
||||||
{"dtmf", Dtmf},
|
{"presence", Presence},
|
||||||
{"dtmf-method", DtmfMethod},
|
{"error", Error},
|
||||||
{"command", Command},
|
{"query", Query},
|
||||||
{0,0}
|
{"session", Jingle},
|
||||||
};
|
{"description", Description},
|
||||||
|
{"payload-type", PayloadType},
|
||||||
|
{"transport", Transport},
|
||||||
|
{"candidate", Candidate},
|
||||||
|
{"body", Body},
|
||||||
|
{"feature", Feature},
|
||||||
|
{"bind", Bind},
|
||||||
|
{"resource", Resource},
|
||||||
|
{"Required", Required},
|
||||||
|
{"dtmf", Dtmf},
|
||||||
|
{"dtmf-method", DtmfMethod},
|
||||||
|
{"command", Command},
|
||||||
|
{0,0}
|
||||||
|
};
|
||||||
|
|
||||||
XMLElement::XMLElement()
|
XMLElement::XMLElement()
|
||||||
: m_type(StreamEnd), m_owner(true), m_element(0)
|
: m_type(StreamEnd), m_owner(true), m_element(0)
|
||||||
|
|
|
@ -70,7 +70,19 @@ public:
|
||||||
StreamStart, // stream:stream
|
StreamStart, // stream:stream
|
||||||
StreamEnd, // /stream:stream
|
StreamEnd, // /stream:stream
|
||||||
StreamError, // stream::error
|
StreamError, // stream::error
|
||||||
|
StreamFeatures, // stream::features
|
||||||
|
Starttls, // starttls
|
||||||
Handshake, // handshake
|
Handshake, // handshake
|
||||||
|
Auth, // auth
|
||||||
|
Challenge, // challenge
|
||||||
|
Abort, // abort
|
||||||
|
Aborted, // aborted
|
||||||
|
Response, // response
|
||||||
|
Success, // success
|
||||||
|
Failure, // failure
|
||||||
|
Mechanisms, // mechanisms
|
||||||
|
Mechanism, // mechanism
|
||||||
|
Session, // session
|
||||||
// *** Stanzas
|
// *** Stanzas
|
||||||
Iq, // iq
|
Iq, // iq
|
||||||
Message, // message
|
Message, // message
|
||||||
|
@ -92,6 +104,7 @@ public:
|
||||||
Bind, // bind
|
Bind, // bind
|
||||||
Resource, // resource
|
Resource, // resource
|
||||||
// Miscellanous
|
// Miscellanous
|
||||||
|
Required, // required
|
||||||
Dtmf, // dtmf
|
Dtmf, // dtmf
|
||||||
DtmfMethod, // dtmf-method
|
DtmfMethod, // dtmf-method
|
||||||
Command, // command
|
Command, // command
|
||||||
|
|
|
@ -33,23 +33,28 @@ static XMPPError s_err;
|
||||||
* XMPPNamespace
|
* XMPPNamespace
|
||||||
*/
|
*/
|
||||||
TokenDict XMPPNamespace::s_value[] = {
|
TokenDict XMPPNamespace::s_value[] = {
|
||||||
{"http://etherx.jabber.org/streams", Stream},
|
{"http://etherx.jabber.org/streams", Stream},
|
||||||
{"jabber:component:accept", ComponentAccept},
|
{"jabber:client", Client},
|
||||||
{"jabber:component:connect", ComponentConnect},
|
{"jabber:server", Server},
|
||||||
{"urn:ietf:params:xml:ns:xmpp-streams", StreamError},
|
{"jabber:component:accept", ComponentAccept},
|
||||||
{"urn:ietf:params:xml:ns:xmpp-stanzas", StanzaError},
|
{"jabber:component:connect", ComponentConnect},
|
||||||
{"urn:ietf:params:xml:ns:xmpp-bind", Bind},
|
{"urn:ietf:params:xml:ns:xmpp-streams", StreamError},
|
||||||
{"http://jabber.org/protocol/disco#info", DiscoInfo},
|
{"urn:ietf:params:xml:ns:xmpp-stanzas", StanzaError},
|
||||||
{"http://jabber.org/protocol/disco#items", DiscoItems},
|
{"urn:ietf:params:xml:ns:xmpp-tls", Starttls},
|
||||||
{"http://www.google.com/session", Jingle},
|
{"urn:ietf:params:xml:ns:xmpp-sasl", Sasl},
|
||||||
{"http://www.google.com/session/phone", JingleAudio},
|
{"urn:ietf:params:xml:ns:xmpp-session", Session},
|
||||||
{"http://www.google.com/transport/p2p", JingleTransport},
|
{"urn:ietf:params:xml:ns:xmpp-bind", Bind},
|
||||||
{"http://jabber.org/protocol/jingle/info/dtmf", Dtmf},
|
{"http://jabber.org/protocol/disco#info", DiscoInfo},
|
||||||
{"http://jabber.org/protocol/jingle/info/dtmf#errors", DtmfError},
|
{"http://jabber.org/protocol/disco#items", DiscoItems},
|
||||||
{"http://jabber.org/protocol/commands", Command},
|
{"http://www.google.com/session", Jingle},
|
||||||
{"http://www.google.com/xmpp/protocol/voice/v1", CapVoiceV1},
|
{"http://www.google.com/session/phone", JingleAudio},
|
||||||
{0,0}
|
{"http://www.google.com/transport/p2p", JingleTransport},
|
||||||
};
|
{"http://jabber.org/protocol/jingle/info/dtmf", Dtmf},
|
||||||
|
{"http://jabber.org/protocol/jingle/info/dtmf#errors", DtmfError},
|
||||||
|
{"http://jabber.org/protocol/commands", Command},
|
||||||
|
{"http://www.google.com/xmpp/protocol/voice/v1", CapVoiceV1},
|
||||||
|
{0,0}
|
||||||
|
};
|
||||||
|
|
||||||
bool XMPPNamespace::isText(Type index, const char* txt)
|
bool XMPPNamespace::isText(Type index, const char* txt)
|
||||||
{
|
{
|
||||||
|
@ -63,59 +68,59 @@ bool XMPPNamespace::isText(Type index, const char* txt)
|
||||||
* XMPPError
|
* XMPPError
|
||||||
*/
|
*/
|
||||||
TokenDict XMPPError::s_value[] = {
|
TokenDict XMPPError::s_value[] = {
|
||||||
{"cancel", TypeCancel},
|
{"cancel", TypeCancel},
|
||||||
{"continue", TypeContinue},
|
{"continue", TypeContinue},
|
||||||
{"modify", TypeModify},
|
{"modify", TypeModify},
|
||||||
{"auth", TypeAuth},
|
{"auth", TypeAuth},
|
||||||
{"wait", TypeWait},
|
{"wait", TypeWait},
|
||||||
{"bad-format", BadFormat},
|
{"bad-format", BadFormat},
|
||||||
{"bad-namespace-prefix", BadNamespace},
|
{"bad-namespace-prefix", BadNamespace},
|
||||||
{"connection-timeout", ConnTimeout},
|
{"connection-timeout", ConnTimeout},
|
||||||
{"host-gone", HostGone},
|
{"host-gone", HostGone},
|
||||||
{"host-unknown", HostUnknown},
|
{"host-unknown", HostUnknown},
|
||||||
{"improper-addressing", BadAddressing},
|
{"improper-addressing", BadAddressing},
|
||||||
{"internal-server-error", Internal},
|
{"internal-server-error", Internal},
|
||||||
{"invalid-from", InvalidFrom},
|
{"invalid-from", InvalidFrom},
|
||||||
{"invalid-id", InvalidId},
|
{"invalid-id", InvalidId},
|
||||||
{"invalid-namespace", InvalidNamespace},
|
{"invalid-namespace", InvalidNamespace},
|
||||||
{"invalid-xml", InvalidXml},
|
{"invalid-xml", InvalidXml},
|
||||||
{"not-authorized", NotAuth},
|
{"not-authorized", NotAuth},
|
||||||
{"policy-violation", Policy},
|
{"policy-violation", Policy},
|
||||||
{"remote-connection-failed", RemoteConn},
|
{"remote-connection-failed", RemoteConn},
|
||||||
{"resource-constraint", ResConstraint},
|
{"resource-constraint", ResConstraint},
|
||||||
{"restricted-xml", RestrictedXml},
|
{"restricted-xml", RestrictedXml},
|
||||||
{"see-other-host", SeeOther},
|
{"see-other-host", SeeOther},
|
||||||
{"system-shutdown", Shutdown},
|
{"system-shutdown", Shutdown},
|
||||||
{"undefined-condition", UndefinedCondition},
|
{"undefined-condition", UndefinedCondition},
|
||||||
{"unsupported-encoding", UnsupportedEnc},
|
{"unsupported-encoding", UnsupportedEnc},
|
||||||
{"unsupported-stanza-type", UnsupportedStanza},
|
{"unsupported-stanza-type", UnsupportedStanza},
|
||||||
{"unsupported-version", UnsupportedVersion},
|
{"unsupported-version", UnsupportedVersion},
|
||||||
{"xml-not-well-formed", Xml},
|
{"xml-not-well-formed", Xml},
|
||||||
{"bad-request", SBadRequest},
|
{"bad-request", SBadRequest},
|
||||||
{"conflict", SConflict},
|
{"conflict", SConflict},
|
||||||
{"feature-not-implemented", SFeatureNotImpl},
|
{"feature-not-implemented", SFeatureNotImpl},
|
||||||
{"forbidden", SForbidden},
|
{"forbidden", SForbidden},
|
||||||
{"gone", SGone},
|
{"gone", SGone},
|
||||||
{"internal-server-error", SInternal},
|
{"internal-server-error", SInternal},
|
||||||
{"item-not-found", SItemNotFound},
|
{"item-not-found", SItemNotFound},
|
||||||
{"jid-malformed", SBadJid},
|
{"jid-malformed", SBadJid},
|
||||||
{"not-acceptable", SNotAcceptable},
|
{"not-acceptable", SNotAcceptable},
|
||||||
{"not-allowed", SNotAllowed},
|
{"not-allowed", SNotAllowed},
|
||||||
{"not-authorized", SNotAuth},
|
{"not-authorized", SNotAuth},
|
||||||
{"payment-required", SPayment},
|
{"payment-required", SPayment},
|
||||||
{"recipient-unavailable", SUnavailable},
|
{"recipient-unavailable", SUnavailable},
|
||||||
{"redirect", SRedirect},
|
{"redirect", SRedirect},
|
||||||
{"registration-required", SReg},
|
{"registration-required", SReg},
|
||||||
{"remote-server-not-found", SNoRemote},
|
{"remote-server-not-found", SNoRemote},
|
||||||
{"remote-server-timeout", SRemoteTimeout},
|
{"remote-server-timeout", SRemoteTimeout},
|
||||||
{"resource-constraint", SResource},
|
{"resource-constraint", SResource},
|
||||||
{"service-unavailable", SServiceUnavailable},
|
{"service-unavailable", SServiceUnavailable},
|
||||||
{"subscription-required", SSubscription},
|
{"subscription-required", SSubscription},
|
||||||
{"undefined-condition", SUndefinedCondition},
|
{"undefined-condition", SUndefinedCondition},
|
||||||
{"unexpected-request", SRequest},
|
{"unexpected-request", SRequest},
|
||||||
{"unsupported-dtmf-method", DtmfNoMethod},
|
{"unsupported-dtmf-method", DtmfNoMethod},
|
||||||
{0,0}
|
{0,0}
|
||||||
};
|
};
|
||||||
|
|
||||||
bool XMPPError::isText(int index, const char* txt)
|
bool XMPPError::isText(int index, const char* txt)
|
||||||
{
|
{
|
||||||
|
|
|
@ -71,16 +71,17 @@ public:
|
||||||
* @param address IP address
|
* @param address IP address
|
||||||
* @param port IP port
|
* @param port IP port
|
||||||
* @param password Component only: Password used for authentication
|
* @param password Component only: Password used for authentication
|
||||||
* @param identity Component only: the stream identity used when connecting
|
* @param identity Component only: The stream identity used when connecting
|
||||||
* @param fullidentity Component only: the user identity
|
* @param fullidentity Component only: The user identity
|
||||||
* @param roster Component only: Keep the user roster
|
* @param roster Component only: Keep the user roster
|
||||||
* @param autoRestart Component only: Auto restart stream when connection is down
|
* @param autoRestart Auto restart stream when connection is down
|
||||||
*/
|
*/
|
||||||
inline XMPPServerInfo(const char* name, const char* address, int port,
|
inline XMPPServerInfo(const char* name, const char* address, int port,
|
||||||
const char* password, const char* identity, const char* fullidentity,
|
const char* password, const char* identity, const char* fullidentity,
|
||||||
bool roster, bool autoRestart)
|
bool roster, bool autoRestart)
|
||||||
: m_name(name), m_address(address), m_port(port), m_password(password),
|
: m_name(name), m_address(address), m_port(port), m_password(password),
|
||||||
m_identity(identity), m_fullIdentity(fullidentity), m_roster(roster)
|
m_identity(identity), m_fullIdentity(fullidentity),
|
||||||
|
m_roster(roster), m_autoRestart(autoRestart)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -141,6 +142,13 @@ public:
|
||||||
inline bool roster() const
|
inline bool roster() const
|
||||||
{ return m_roster; }
|
{ return m_roster; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the stream should restart when down
|
||||||
|
* @return True if the stream should restart when down
|
||||||
|
*/
|
||||||
|
inline bool autoRestart() const
|
||||||
|
{ return m_autoRestart; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
String m_name; // Domain name
|
String m_name; // Domain name
|
||||||
String m_address; // IP address
|
String m_address; // IP address
|
||||||
|
@ -149,6 +157,7 @@ private:
|
||||||
String m_identity; // Identity. Used for Jabber Component protocol
|
String m_identity; // Identity. Used for Jabber Component protocol
|
||||||
String m_fullIdentity; // Full identity for this server
|
String m_fullIdentity; // Full identity for this server
|
||||||
bool m_roster; // Keep roster for this server
|
bool m_roster; // Keep roster for this server
|
||||||
|
bool m_autoRestart; // Auto restart stream when down
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -161,10 +170,15 @@ class YJINGLE_API XMPPNamespace
|
||||||
public:
|
public:
|
||||||
enum Type {
|
enum Type {
|
||||||
Stream, // http://etherx.jabber.org/streams
|
Stream, // http://etherx.jabber.org/streams
|
||||||
|
Client, // jabber:client
|
||||||
|
Server, // jabber:server
|
||||||
ComponentAccept, // jabber:component:accept
|
ComponentAccept, // jabber:component:accept
|
||||||
ComponentConnect, // jabber:component:connect
|
ComponentConnect, // jabber:component:connect
|
||||||
StreamError, // urn:ietf:params:xml:ns:xmpp-streams
|
StreamError, // urn:ietf:params:xml:ns:xmpp-streams
|
||||||
StanzaError, // urn:ietf:params:xml:ns:xmpp-stanzas
|
StanzaError, // urn:ietf:params:xml:ns:xmpp-stanzas
|
||||||
|
Starttls, // urn:ietf:params:xml:ns:xmpp-tls
|
||||||
|
Sasl, // urn:ietf:params:xml:ns:xmpp-sasl
|
||||||
|
Session, // urn:ietf:params:xml:ns:xmpp-session
|
||||||
Bind, // urn:ietf:params:xml:ns:xmpp-bind
|
Bind, // urn:ietf:params:xml:ns:xmpp-bind
|
||||||
DiscoInfo, // http://jabber.org/protocol/disco#info
|
DiscoInfo, // http://jabber.org/protocol/disco#info
|
||||||
DiscoItems, // http://jabber.org/protocol/disco#items
|
DiscoItems, // http://jabber.org/protocol/disco#items
|
||||||
|
|
|
@ -35,7 +35,6 @@ namespace TelEngine {
|
||||||
class JBEvent; // A Jabber event
|
class JBEvent; // A Jabber event
|
||||||
class JBStream; // A Jabber stream
|
class JBStream; // A Jabber stream
|
||||||
class JBComponentStream; // A Jabber Component stream
|
class JBComponentStream; // A Jabber Component stream
|
||||||
class JBClientStream; // A Jabber client to server stream
|
|
||||||
class JBThread; // Base class for private threads
|
class JBThread; // Base class for private threads
|
||||||
class JBThreadList; // A list of threads
|
class JBThreadList; // A list of threads
|
||||||
class JBEngine; // A Jabber engine
|
class JBEngine; // A Jabber engine
|
||||||
|
@ -476,6 +475,17 @@ public:
|
||||||
removePending(notify,&id,false);
|
removePending(notify,&id,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cleanup the stream before destroying
|
||||||
|
* This method is thread safe
|
||||||
|
*/
|
||||||
|
inline void cleanup() {
|
||||||
|
Lock lock(m_socket.m_streamMutex);
|
||||||
|
m_events.clear();
|
||||||
|
TelEngine::destruct(m_terminateEvent);
|
||||||
|
TelEngine::destruct(m_startEvent);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the name of a stream state
|
* Get the name of a stream state
|
||||||
* @param state The requested state number
|
* @param state The requested state number
|
||||||
|
@ -683,66 +693,6 @@ private:
|
||||||
bool m_shaAuth; // Use SHA1/MD5 digest authentication
|
bool m_shaAuth; // Use SHA1/MD5 digest authentication
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* This class holds a Jabber client stream used to connect an user to its server
|
|
||||||
* @short A Jabber client to server stream
|
|
||||||
*/
|
|
||||||
class YJINGLE_API JBClientStream : public JBStream
|
|
||||||
{
|
|
||||||
friend class JBEngine;
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Destructor
|
|
||||||
*/
|
|
||||||
virtual ~JBClientStream()
|
|
||||||
{}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
/**
|
|
||||||
* Constructor
|
|
||||||
* @param engine The engine that owns this stream
|
|
||||||
* @param jid User's JID
|
|
||||||
* @param password Password used for authentication
|
|
||||||
* @param address The remote address to connect to
|
|
||||||
* @param maxRestart The maximum restart attempts allowed
|
|
||||||
* @param incRestartInterval The interval to increase the restart counter
|
|
||||||
* @param outgoing Stream direction
|
|
||||||
*/
|
|
||||||
JBClientStream(JBEngine* engine, const JabberID& jid,
|
|
||||||
const String& password, const SocketAddr& address,
|
|
||||||
unsigned int maxRestart, u_int64_t incRestartInterval,
|
|
||||||
bool outgoing = true);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the starting stream element to be sent after stream connected
|
|
||||||
* @return XMLElement pointer
|
|
||||||
*/
|
|
||||||
virtual XMLElement* getStreamStart();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Process a received element in Securing state
|
|
||||||
* @param xml Valid XMLElement pointer
|
|
||||||
*/
|
|
||||||
virtual void processSecuring(XMLElement* xml);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Process a received element in Auth state
|
|
||||||
* @param xml Valid XMLElement pointer
|
|
||||||
*/
|
|
||||||
virtual void processAuth(XMLElement* xml);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Process a received element in Started state
|
|
||||||
* @param xml Valid XMLElement pointer
|
|
||||||
*/
|
|
||||||
virtual void processStarted(XMLElement* xml);
|
|
||||||
|
|
||||||
private:
|
|
||||||
// Default constructor is private to avoid unwanted use
|
|
||||||
JBClientStream() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class holds encapsulates a private library thread
|
* This class holds encapsulates a private library thread
|
||||||
* @short A Jabber thread that can be added to a list of threads
|
* @short A Jabber thread that can be added to a list of threads
|
||||||
|
|
Loading…
Reference in New Issue