Added jingle session 'no ping' flag to prevent sending session ping. Fixed debug.

git-svn-id: http://yate.null.ro/svn/yate/trunk@4280 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
marian 2011-04-11 14:48:35 +00:00
parent 8c477b27cb
commit 56af3d65b1
3 changed files with 96 additions and 6 deletions

View File

@ -59,6 +59,8 @@ void JGEngine::initialize(const NamedList& params)
if (lvl != -1)
debugLevel(lvl);
m_sessionFlags = 0;
m_sessionFlags = decodeFlags(params["jingle_flags"],JGSession::s_flagName);
int timeout = params.getIntValue("stanza_timeout",(int)m_stanzaTimeout);
m_stanzaTimeout = timeout > 10000 ? timeout : 10000;
int ping = params.getIntValue("ping_interval",(int)m_pingInterval);
@ -72,19 +74,19 @@ void JGEngine::initialize(const NamedList& params)
if (m_pingInterval && m_stanzaTimeout && m_pingInterval <= m_stanzaTimeout)
m_pingInterval = m_stanzaTimeout + 100;
if (debugAt(DebugInfo)) {
if (debugAt(DebugAll)) {
String s;
s << " jingle_flags=" << m_sessionFlags;
s << " stanza_timeout=" << (unsigned int)m_stanzaTimeout;
s << " ping_interval=" << (unsigned int)m_pingInterval;
Debug(this,DebugInfo,"Jabber Jingle service initialized:%s [%p]",
s.c_str(),this);
Debug(this,DebugAll,"Jingle engine initialized:%s [%p]",s.c_str(),this);
}
}
// Make an outgoing call
JGSession* JGEngine::call(JGSession::Version ver, const JabberID& caller,
const JabberID& called, const ObjList& contents, XmlElement* extra,
const char* msg, const char* subject, const char* line)
const char* msg, const char* subject, const char* line, int* flags)
{
DDebug(this,DebugAll,"call() from '%s' to '%s'",caller.c_str(),called.c_str());
JGSession* session = 0;
@ -101,6 +103,8 @@ JGSession* JGEngine::call(JGSession::Version ver, const JabberID& caller,
return 0;
}
if (session) {
if (flags)
session->setFlags(*flags);
session->line(line);
if (!TelEngine::null(msg))
sendMessage(session,msg);
@ -276,6 +280,30 @@ void JGEngine::processEvent(JGEvent* event)
defProcessEvent(event);
}
// Decode a comma separated list of flags
int JGEngine::decodeFlags(const String& list, const TokenDict* dict)
{
if (!(list && dict))
return 0;
int ret = 0;
ObjList* l = list.split(',',false);
for (; dict->token; dict++)
if (l->find(dict->token))
ret += dict->value;
TelEngine::destruct(l);
return ret;
}
// Encode flags to a comma separated list
void JGEngine::encodeFlags(String& buf, int flags, const TokenDict* dict)
{
if (!(flags && dict))
return;
for (; dict->token; dict++)
if (0 != (flags & dict->value))
buf.append(dict->token,",");
}
// Create a local session id
void JGEngine::createSessionId(String& id)
{

View File

@ -153,6 +153,12 @@ const TokenDict JGSession::s_actions1[] = {
{0,0}
};
// Session flag names
const TokenDict JGSession::s_flagName[] = {
{"noping", FlagNoPing},
{0,0}
};
// Output a debug message on unhandled actions
// Confirm received element
static void unhandledAction(JGSession* sess, XmlElement*& xml, int act,
@ -896,6 +902,7 @@ JGSession::JGSession(Version ver, JGEngine* engine,
: Mutex(true,"JGSession"),
m_version(ver),
m_state(Idle),
m_flags(engine->sessionFlags()),
m_timeToPing(0),
m_engine(engine),
m_outgoing(true),
@ -921,6 +928,7 @@ JGSession::JGSession(Version ver, JGEngine* engine, const JabberID& caller,
: Mutex(true,"JGSession"),
m_version(ver),
m_state(Idle),
m_flags(engine->sessionFlags()),
m_timeToPing(0),
m_engine(engine),
m_outgoing(false),
@ -1226,7 +1234,8 @@ JGEvent* JGSession::getEvent(u_int64_t time)
}
// Ping the remote party
sendPing(time);
if (!flag(FlagNoPing))
sendPing(time);
return 0;
}

View File

@ -887,6 +887,13 @@ public:
ActCount,
};
/**
* Session flags
*/
enum SessionFlag {
FlagNoPing = 0x0001, // Don't send ping
};
/**
* Destructor
*/
@ -941,6 +948,21 @@ public:
inline State state() const
{ return m_state; }
/**
* Retrieve session flags
* @param mask Mask to retrieve
* @return Session flags
*/
inline int flag(int mask) const
{ return m_flags & mask; }
/**
* Replace session flags
* @param value The new session flags
*/
inline void setFlags(int value)
{ m_flags = value; }
/**
* Get the arbitrary user data of this session
* @return The arbitrary user data of this session
@ -1243,6 +1265,11 @@ public:
*/
static const TokenDict s_actions1[];
/**
* Session flag names
*/
static const TokenDict s_flagName[];
protected:
/**
* Constructor. Create an outgoing session
@ -1373,6 +1400,7 @@ protected:
Version m_version; // Session version
State m_state; // Session state
int m_flags; // Session flags
u_int64_t m_timeToPing; // Time to send ping (empty session-info)
JGEngine* m_engine; // The engine that owns this session
bool m_outgoing; // Session direction
@ -1880,6 +1908,13 @@ public:
*/
virtual ~JGEngine();
/**
* Retrieve the default session flags value
* @return The default session flags value
*/
inline int sessionFlags() const
{ return m_sessionFlags; }
/**
* Get the timeout interval of a sent stanza
* @return The timeout interval of a sent stanza
@ -1936,11 +1971,12 @@ public:
* @param msg Optional message to send before call
* @param subject Optional session subject
* @param line Optional session account
* @param flags Optional session flags to set
* @return Valid JGSession pointer (referenced) on success
*/
JGSession* call(JGSession::Version ver, const JabberID& caller, const JabberID& called,
const ObjList& contents, XmlElement* extra = 0, const char* msg = 0,
const char* subject = 0, const char* line = 0);
const char* subject = 0, const char* line = 0, int* flags = 0);
/**
* Ask this engine to accept an incoming xml 'iq' element
@ -1972,6 +2008,22 @@ public:
*/
virtual void processEvent(JGEvent* event);
/**
* Decode a comma separated list of flags
* @param list The list of flags
* @param dict Dictionary to use
* @return Found flags
*/
static int decodeFlags(const String& list, const TokenDict* dict);
/**
* Encode (append) flags to a comma separated list
* @param buf Destination buffer
* @param flags Flags to encode
* @param dict Dictionary to use
*/
static void encodeFlags(String& buf, int flags, const TokenDict* dict);
private:
// Create a local session id
void createSessionId(String& id);
@ -1980,6 +2032,7 @@ private:
u_int32_t m_sessionId; // Session id counter
u_int64_t m_stanzaTimeout; // The timeout of a sent stanza
u_int64_t m_pingInterval; // Interval to send ping (empty session-info)
int m_sessionFlags; // Default session flags
};