From ebe5470d5b2d61612cd0c7271862f309adfa526d Mon Sep 17 00:00:00 2001 From: Stefan Sayer Date: Fri, 2 May 2008 12:17:18 +0000 Subject: [PATCH] configurable logging of raw and parsed SIP messages git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@929 8eb893ce-cfd4-0310-b710-fb5ebe64c474 --- core/plug-in/sipctrl/SipCtrlInterface.cpp | 67 +++++++++++++++-------- core/plug-in/sipctrl/SipCtrlInterface.h | 2 + core/plug-in/sipctrl/etc/sipctrl.conf | 14 +++++ core/plug-in/sipctrl/trans_layer.cpp | 8 ++- core/plug-in/sipctrl/udp_trsp.cpp | 16 +++++- 5 files changed, 81 insertions(+), 26 deletions(-) diff --git a/core/plug-in/sipctrl/SipCtrlInterface.cpp b/core/plug-in/sipctrl/SipCtrlInterface.cpp index 8a22c5c0..b4838232 100644 --- a/core/plug-in/sipctrl/SipCtrlInterface.cpp +++ b/core/plug-in/sipctrl/SipCtrlInterface.cpp @@ -37,6 +37,8 @@ EXPORT_CONTROL_INTERFACE_FACTORY(SipCtrlInterfaceFactory,MOD_NAME); string SipCtrlInterfaceFactory::outbound_host = ""; unsigned int SipCtrlInterfaceFactory::outbound_port = 0; bool SipCtrlInterfaceFactory::accept_fr_without_totag = false; +int SipCtrlInterfaceFactory::log_raw_messages = 3; +bool SipCtrlInterfaceFactory::log_parsed_messages = true; AmCtrlInterface* SipCtrlInterfaceFactory::instance() { @@ -70,11 +72,31 @@ int SipCtrlInterfaceFactory::onLoad() AmConfigReader cfg; string cfgfile = AmConfig::ModConfigPath + string(MOD_NAME ".conf"); - if (file_exists(cfgfile) && cfg.loadFile(cfgfile)) { + if (file_exists(cfgfile) && !cfg.loadFile(cfgfile)) { if (cfg.hasParameter("accept_fr_without_totag")) { accept_fr_without_totag = cfg.getParameter("accept_fr_without_totag") == "yes"; } + DBG("sipctrl: accept_fr_without_totag = %s\n", + accept_fr_without_totag?"yes":"no"); + + if (cfg.hasParameter("log_raw_messages")) { + string msglog = cfg.getParameter("log_raw_messages"); + if (msglog == "no") log_raw_messages = -1; + else if (msglog == "error") log_raw_messages = 0; + else if (msglog == "warn") log_raw_messages = 1; + else if (msglog == "info") log_raw_messages = 2; + else if (msglog == "debug") log_raw_messages = 3; + } + DBG("sipctrl: log_raw_messages level = %d\n", + log_raw_messages); + + if (cfg.hasParameter("log_parsed_messages")) { + log_parsed_messages = cfg.getParameter("log_parsed_messages")=="yes"; + } + DBG("sipctrl: log_parsed_messages = %s\n", + log_parsed_messages?"yes":"no"); + } else { DBG("assuming SIP default settings.\n"); } @@ -371,27 +393,28 @@ int SipCtrlInterface::send(const AmSipReply &rep) void SipCtrlInterface::handleSipMsg(AmSipRequest &req) { - DBG("Received new request:\n"); - -// DBG_PARAM(req.cmd); - DBG_PARAM(req.method); -// DBG_PARAM(req.user); -// DBG_PARAM(req.domain); -// DBG_PARAM(req.dstip); -// DBG_PARAM(req.port); - DBG_PARAM(req.r_uri); - DBG_PARAM(req.from_uri); - DBG_PARAM(req.from); - DBG_PARAM(req.to); - DBG_PARAM(req.callid); - DBG_PARAM(req.from_tag); - DBG_PARAM(req.to_tag); - DBG("cseq = <%i>\n",req.cseq); - DBG_PARAM(req.serKey); - DBG_PARAM(req.route); - DBG_PARAM(req.next_hop); - DBG("hdrs = <%s>\n",req.hdrs.c_str()); - DBG("body = <%s>\n",req.body.c_str()); + DBG("Received new request\n"); + if (SipCtrlInterfaceFactory::log_parsed_messages) { + // DBG_PARAM(req.cmd); + DBG_PARAM(req.method); + // DBG_PARAM(req.user); + // DBG_PARAM(req.domain); + // DBG_PARAM(req.dstip); + // DBG_PARAM(req.port); + DBG_PARAM(req.r_uri); + DBG_PARAM(req.from_uri); + DBG_PARAM(req.from); + DBG_PARAM(req.to); + DBG_PARAM(req.callid); + DBG_PARAM(req.from_tag); + DBG_PARAM(req.to_tag); + DBG("cseq = <%i>\n",req.cseq); + DBG_PARAM(req.serKey); + DBG_PARAM(req.route); + DBG_PARAM(req.next_hop); + DBG("hdrs = <%s>\n",req.hdrs.c_str()); + DBG("body = <%s>\n",req.body.c_str()); + } if(req.method == "ACK") return; diff --git a/core/plug-in/sipctrl/SipCtrlInterface.h b/core/plug-in/sipctrl/SipCtrlInterface.h index 8eec49d2..a8564bf6 100644 --- a/core/plug-in/sipctrl/SipCtrlInterface.h +++ b/core/plug-in/sipctrl/SipCtrlInterface.h @@ -32,6 +32,8 @@ public: static unsigned int outbound_port; static bool accept_fr_without_totag; + static int log_raw_messages; + static bool log_parsed_messages; SipCtrlInterfaceFactory(const string& name): AmCtrlInterfaceFactory(name) {} ~SipCtrlInterfaceFactory() {} diff --git a/core/plug-in/sipctrl/etc/sipctrl.conf b/core/plug-in/sipctrl/etc/sipctrl.conf index 03631eac..b1cc9521 100644 --- a/core/plug-in/sipctrl/etc/sipctrl.conf +++ b/core/plug-in/sipctrl/etc/sipctrl.conf @@ -6,3 +6,17 @@ # Accept final replies without To-tag? [yes|no] # #accept_fr_without_totag=yes + +# +# Log raw messages? [no|debug|info|warn|error] +# +# Default: debug +# +#log_raw_messages=no + +# +# Log parsed received messages? [yes|no] +# +# Default: yes +# +#log_parsed_messages=no diff --git a/core/plug-in/sipctrl/trans_layer.cpp b/core/plug-in/sipctrl/trans_layer.cpp index 2a6bc877..8d94c39d 100644 --- a/core/plug-in/sipctrl/trans_layer.cpp +++ b/core/plug-in/sipctrl/trans_layer.cpp @@ -204,7 +204,7 @@ int trans_layer::send_reply(trans_bucket* bucket, sip_trans* t, memcpy(c,body.s,body.len); } - DBG("Sending: <%.*s>\n",reply_len,reply_buf); + // DBG("Sending: <%.*s>\n",reply_len,reply_buf); assert(transport); int err = transport->send(&req->remote_ip,reply_buf,reply_len); @@ -1081,7 +1081,8 @@ void trans_layer::send_non_200_ack(sip_trans* t, sip_msg* reply) *c++ = CR; *c++ = LF; - DBG("About to send ACK: \n<%.*s>\n",ack_len,ack_buf); + DBG("About to send ACK\n"); +// DBG("About to send ACK: \n<%.*s>\n",ack_len,ack_buf); assert(transport); int send_err = transport->send(&inv->remote_ip,ack_buf,ack_len); @@ -1166,7 +1167,8 @@ void trans_layer::send_200_ack(sip_msg* reply) *msg++ = CR; *msg++ = LF; - DBG("About to send 200 ACK: \n<%.*s>\n",request_len,ack_buf); + DBG("About to send 200 ACK\n"); + // DBG("About to send 200 ACK: \n<%.*s>\n",request_len,ack_buf); assert(transport); int send_err = transport->send(&remote_ip,ack_buf,request_len); diff --git a/core/plug-in/sipctrl/udp_trsp.cpp b/core/plug-in/sipctrl/udp_trsp.cpp index a2523c99..1fbe830a 100644 --- a/core/plug-in/sipctrl/udp_trsp.cpp +++ b/core/plug-in/sipctrl/udp_trsp.cpp @@ -4,6 +4,8 @@ #include "trans_layer.h" #include "log.h" +#include "SipCtrlInterface.h" + #include #include #include @@ -105,9 +107,12 @@ void udp_trsp::run() ERROR("Message was too big (>%d)\n",MAX_UDP_MSGLEN); continue; } - sip_msg* s_msg = new sip_msg(buf,buf_len); + if (SipCtrlInterfaceFactory::log_raw_messages >= 0) { + _LOG(SipCtrlInterfaceFactory::log_raw_messages, + "recvd msg\n--++--\n%s--++--\n", s_msg->buf); + } memcpy(&s_msg->remote_ip,msg.msg_name,msg.msg_namelen); //msg->remote_ip_len = sizeof(sockaddr_storage); @@ -204,6 +209,15 @@ int udp_trsp::bind(const string& address, unsigned short port) /** @see transport */ int udp_trsp::send(const sockaddr_storage* sa, const char* msg, const int msg_len) { + if ((SipCtrlInterfaceFactory::log_raw_messages >= 0) + && (SipCtrlInterfaceFactory::log_raw_messages <=log_level)) { + char buf[MAX_UDP_MSGLEN]; + memcpy(buf, msg, msg_len); + buf[msg_len]='\0'; + _LOG(SipCtrlInterfaceFactory::log_raw_messages, + "send msg\n--++--\n%s--++--\n", buf); + } + int err; #ifdef SUPPORT_IPV6 if (sa->ss_family == AF_INET6) {