[reSIProcate] app callback for close-to-the-wire message traces
Our device uses resiprocate and has a debug mode in which we want to
dump into our log a trace of every message we send or receive, as close
to the wire as possible. Basically, the next best thing to wireshark.
Sometimes resiprocate itself discards received messages or generates
messages without telling the app above it, so we found it necessary to
give resiprocate a callback that takes a const * SipMessage and a
direction flag:
typedef void (*msgTraceCb_t)(const SipMessage * msg, bool inNotOut);
We simply put a pointer to this callback in the Transport object as a
public member variable so the app manipulates it directly; I suppose if
we wanted to be nice we would have wrapped it in an accessor method.
Anyway, every time the stack receives a SipMessage off the wire, and
every time it is about to send one on the wire, it calls the callback
(if not NULL), and the app can then do whatever logging or accounting it
wants, in whatever format it likes, without actually changing the
message at all. Five files changed, but relatively trivial changes. All
based on 1.9.6 sources.
-John Gregg
Index: ssl/DtlsTransport.cxx
===================================================================
--- ssl/DtlsTransport.cxx (revision 27529)
+++ ssl/DtlsTransport.cxx (working copy)
@@ -434,6 +434,12 @@
}
#endif
+ // AYLUS_CHANGE
+ if (mMsgTraceCb)
+ {
+ (mMsgTraceCb)(message, true);
+ }
+
mStateMachineFifo.add( message ) ;
}
Index: Transport.cxx
===================================================================
--- Transport.cxx (revision 27529)
+++ Transport.cxx (working copy)
@@ -37,6 +37,7 @@
const Data& tlsDomain,
AfterSocketCreationFuncPtr socketFunc,
Compression &compression) :
+ mMsgTraceCb(NULL), // AYLUS_CHANGE
mTuple(address),
mHasRecordRoute(false),
mKey(0),
@@ -59,6 +60,7 @@
AfterSocketCreationFuncPtr socketFunc,
Compression &compression,
unsigned transportFlags) :
+ mMsgTraceCb(NULL), // AYLUS_CHANGE
mInterface(intfc),
mTuple(intfc, portNum, version),
mHasRecordRoute(false),
@@ -433,6 +435,12 @@
void
Transport::pushRxMsgUp(TransactionMessage* msg)
{
+ // AYLUS_CHANGE
+ SipMessage * sipMsg = dynamic_cast<SipMessage *>(msg);
+ if (sipMsg && mMsgTraceCb)
+ {
+ (mMsgTraceCb)(sipMsg, true);
+ }
mStateMachineFifo.add(msg);
}
Index: Transport.hxx
===================================================================
--- Transport.hxx (revision 27529)
+++ Transport.hxx (working copy)
@@ -59,6 +59,9 @@
#define RESIP_TRANSPORT_FLAG_TXNOW (1<<4)
#define RESIP_TRANSPORT_FLAG_OWNTHREAD (1<<5)
+typedef void (*msgTraceCb_t)(const SipMessage * msg, bool inNotOut); // AYLUS_CHANGE
+
+
/**
@brief The base class for Transport classes.
@@ -354,6 +357,8 @@
inline unsigned int getKey() const {return mKey;}
+ msgTraceCb_t mMsgTraceCb; // AYLUS_CHANGE
+
protected:
friend class TransportSelector;
inline void setKey(unsigned int pKey) { mKey = pKey;}
Index: TransportSelector.cxx
===================================================================
--- TransportSelector.cxx (revision 27529)
+++ TransportSelector.cxx (working copy)
@@ -1182,6 +1182,12 @@
*sendData = *send;
}
+ // AYLUS_CHANGE
+ if (target.transport->mMsgTraceCb)
+ {
+ (target.transport->mMsgTraceCb)(msg, false);
+ }
+
transport->send(send);
return Sent;
}
@@ -1232,6 +1238,13 @@
if(transport)
{
+#if 0
+ // AYLUS_CHANGE
+ if (target.transport->mMsgTraceCb)
+ {
+ (target.transport->mMsgTraceCb)(msg, false);
+ }
+#endif
// If this is not true, it means the transport has been removed.
transport->send(std::auto_ptr<SendData>(data.clone()));
}
Index: UdpTransport.cxx
===================================================================
--- UdpTransport.cxx (revision 27529)
+++ UdpTransport.cxx (working copy)
@@ -693,6 +693,12 @@
}
#endif
+ // AYLUS_CHANGE
+ if (mMsgTraceCb)
+ {
+ (mMsgTraceCb)(message, true);
+ }
+
mStateMachineFifo.add(message);
++mRxTransactionCnt;
return origBufferConsumed;