Fixed bug: print a received answer to a request sent without trace id while tracing is enabled. Fixed bug: set channel's trace id when building a dialog message. Added configuration option to enable sip tracing.

git-svn-id: http://yate.null.ro/svn/yate/trunk@6415 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
marian 2020-07-15 13:34:04 +00:00
parent 073f33a3fb
commit 7fd35b99be
3 changed files with 32 additions and 12 deletions

View File

@ -33,7 +33,7 @@ SIPMessage::SIPMessage(const SIPMessage& original)
: RefObject(),
version(original.version), method(original.method), uri(original.uri),
code(original.code), reason(original.reason),
body(0), msgTraceId(original.msgTraceId), m_ep(0),
body(0), msgTraceId(original.msgTraceId), msgPrint(true), m_ep(0),
m_valid(original.isValid()), m_answer(original.isAnswer()),
m_outgoing(original.isOutgoing()), m_ack(original.isACK()),
m_cseq(-1), m_flags(original.getFlags()), m_dontSend(original.m_dontSend)
@ -65,7 +65,7 @@ SIPMessage::SIPMessage(const SIPMessage& original)
SIPMessage::SIPMessage(const char* _method, const char* _uri, const char* _version)
: version(_version), method(_method), uri(_uri), code(0),
body(0), m_ep(0), m_valid(true),
body(0), msgPrint(true), m_ep(0), m_valid(true),
m_answer(false), m_outgoing(true), m_ack(false), m_cseq(-1), m_flags(-1),
m_dontSend(false)
{
@ -74,7 +74,7 @@ SIPMessage::SIPMessage(const char* _method, const char* _uri, const char* _versi
}
SIPMessage::SIPMessage(SIPParty* ep, const char* buf, int len, unsigned int* bodyLen)
: code(0), body(0), m_ep(ep), m_valid(false),
: code(0), body(0), msgPrint(true), m_ep(ep), m_valid(false),
m_answer(false), m_outgoing(false), m_ack(false), m_cseq(-1), m_flags(-1),
m_dontSend(false)
{
@ -92,7 +92,7 @@ SIPMessage::SIPMessage(SIPParty* ep, const char* buf, int len, unsigned int* bod
}
SIPMessage::SIPMessage(const SIPMessage* message, int _code, const char* _reason)
: code(_code), body(0),
: code(_code), body(0), msgPrint(true),
m_ep(0), m_valid(false),
m_answer(true), m_outgoing(true), m_ack(false), m_cseq(-1), m_flags(-1),
m_dontSend(false)
@ -124,7 +124,7 @@ SIPMessage::SIPMessage(const SIPMessage* message, int _code, const char* _reason
SIPMessage::SIPMessage(const SIPMessage* original, const SIPMessage* answer)
: method("ACK"), code(0),
body(0), m_ep(0), m_valid(false),
body(0), msgPrint(true), m_ep(0), m_valid(false),
m_answer(false), m_outgoing(true), m_ack(true), m_cseq(-1), m_flags(-1),
m_dontSend(false)
{

View File

@ -533,6 +533,11 @@ public:
*/
String msgTraceId;
/**
* Message print in debug
*/
bool msgPrint;
protected:
bool parse(const char* buf, int len, unsigned int* bodyLen);
bool parseFirst(String& line);

View File

@ -1150,10 +1150,9 @@ public:
{ return m_parser; }
inline bool traceActive() const
{
return Engine::sharedVars().exists(YSTRING("trace")) ||
Engine::sharedVars().exists(YSTRING("trace_sip"));
return s_trace || Engine::sharedVars().exists(YSTRING("trace")) ||
Engine::sharedVars().exists(YSTRING("trace_sip"));
}
void epTerminated(YateSIPEndPoint* ep);
YateSIPConnection* findCall(const String& callid, bool incRef = false);
YateSIPConnection* findDialog(const SIPDialog& dialog, bool incRef = false);
@ -1175,6 +1174,9 @@ public:
// Send a SIP method
bool sendMethod(Message& msg, const char* method, bool msgExec = false,
const char* target = 0);
static bool s_trace;
protected:
virtual void genUpdate(Message& msg);
// Setup a listener from config
@ -1291,6 +1293,7 @@ static const String s_username = "username";
static u_int64_t s_printFloodTime = 0;
int YateSIPEndPoint::s_evCount = 0;
bool SIPDriver::s_trace = false;
// DTMF methods
static bool s_checkAllowInfo = true; // Check Allow in INVITE and OK for INFO support
@ -3389,16 +3392,22 @@ int YateSIPUDPTransport::process()
}
char* b = (char*)m_buffer.data();
b[res] = 0;
if (s_printMsg && !plugin.traceActive())
bool print = true;
if (s_printMsg && !plugin.traceActive()) {
print = false;
printRecvMsg(b,res);
}
if (s_floodProtection && s_floodEvents && evc >= s_floodEvents) {
if (!s_printFloodTime)
Alarm(&plugin,"performance",DebugWarn,
"Flood detected, dropping INVITE/REGISTER/SUBSCRIBE/OPTIONS, allowing reINVITES");
s_printFloodTime = Time::now() + 10000000;
if (!msgIsAllowed(b,res))
if (!msgIsAllowed(b,res)) {
if (s_printMsg && print)
printRecvMsg(b,res);
return 0;
}
}
else if (s_printFloodTime && s_printFloodTime < Time::now()) {
s_printFloodTime = 0;
@ -3406,6 +3415,7 @@ int YateSIPUDPTransport::process()
}
SIPMessage* msg = SIPMessage::fromParsing(0,b,res);
msg->msgPrint = print;
receiveMsg(msg);
return 0;
}
@ -3968,9 +3978,13 @@ bool YateSIPTCPTransport::readData(const Time& time, bool& read)
m_sipBufOffs += m_contentLen;
m_contentLen = 0;
}
if (s_printMsg && !plugin.traceActive())
bool print = true;
if (s_printMsg && !plugin.traceActive()) {
print = false;
printRecvMsg(data,m_sipBufOffs);
}
SIPMessage* msg = m_msg;
msg->msgPrint = print;
m_msg = 0;
receiveMsg(msg);
data += m_sipBufOffs;
@ -4751,7 +4765,7 @@ void YateSIPEngine::allocTraceId(String& id)
void YateSIPEngine::traceMsg(SIPMessage* message, bool incoming)
{
if (!(message && message->traceId() && message->getParty()))
if (!(message && message->msgPrint && s_printMsg && message->getParty()))
return;
YateSIPTransport* trans = static_cast<YateSIPTransport*>(message->getParty()->getTransport());
if (!trans)
@ -9479,6 +9493,7 @@ void SIPDriver::initialize()
s_changeParty2xx = s_cfg.getBoolValue("general","change_party_2xx",false);
s_initialHeaders = s_cfg.getBoolValue("general","initial_headers");
m_parser.initialize(s_cfg.getSection("codecs"),s_cfg.getSection("hacks"),s_cfg.getSection("general"));
s_trace = s_cfg.getBoolValue("general","trace");
if (!m_endpoint) {
Thread::Priority prio = Thread::priority(s_cfg.getValue("general","thread"));
unsigned int partyMutexCount = s_cfg.getIntValue("general","party_mutexcount",47,13,101);