Author: sayer
Date: 2008-05-02 14:17:18 +0200 (Fri, 02 May 2008)
New Revision: 929

Modified:
   trunk/core/plug-in/sipctrl/SipCtrlInterface.cpp
   trunk/core/plug-in/sipctrl/SipCtrlInterface.h
   trunk/core/plug-in/sipctrl/etc/sipctrl.conf
   trunk/core/plug-in/sipctrl/trans_layer.cpp
   trunk/core/plug-in/sipctrl/udp_trsp.cpp
Log:
configurable logging of raw and parsed SIP messages

Modified: trunk/core/plug-in/sipctrl/SipCtrlInterface.cpp
===================================================================
--- trunk/core/plug-in/sipctrl/SipCtrlInterface.cpp     2008-05-02 12:15:59 UTC 
(rev 928)
+++ trunk/core/plug-in/sipctrl/SipCtrlInterface.cpp     2008-05-02 12:17:18 UTC 
(rev 929)
@@ -37,6 +37,8 @@
 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 @@
 
     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,28 +393,29 @@
 
 void SipCtrlInterface::handleSipMsg(AmSipRequest &req)
 {
-    DBG("Received new request:\n");
+    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());
+    }
 
-//     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;
     

Modified: trunk/core/plug-in/sipctrl/SipCtrlInterface.h
===================================================================
--- trunk/core/plug-in/sipctrl/SipCtrlInterface.h       2008-05-02 12:15:59 UTC 
(rev 928)
+++ trunk/core/plug-in/sipctrl/SipCtrlInterface.h       2008-05-02 12:17:18 UTC 
(rev 929)
@@ -32,6 +32,8 @@
     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() {}

Modified: trunk/core/plug-in/sipctrl/etc/sipctrl.conf
===================================================================
--- trunk/core/plug-in/sipctrl/etc/sipctrl.conf 2008-05-02 12:15:59 UTC (rev 
928)
+++ trunk/core/plug-in/sipctrl/etc/sipctrl.conf 2008-05-02 12:17:18 UTC (rev 
929)
@@ -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

Modified: trunk/core/plug-in/sipctrl/trans_layer.cpp
===================================================================
--- trunk/core/plug-in/sipctrl/trans_layer.cpp  2008-05-02 12:15:59 UTC (rev 
928)
+++ trunk/core/plug-in/sipctrl/trans_layer.cpp  2008-05-02 12:17:18 UTC (rev 
929)
@@ -204,7 +204,7 @@
        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 @@
     *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 @@
     *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);

Modified: trunk/core/plug-in/sipctrl/udp_trsp.cpp
===================================================================
--- trunk/core/plug-in/sipctrl/udp_trsp.cpp     2008-05-02 12:15:59 UTC (rev 
928)
+++ trunk/core/plug-in/sipctrl/udp_trsp.cpp     2008-05-02 12:17:18 UTC (rev 
929)
@@ -4,6 +4,8 @@
 #include "trans_layer.h"
 #include "log.h"
 
+#include "SipCtrlInterface.h"
+
 #include <netinet/in.h>
 #include <sys/param.h>
 #include <arpa/inet.h>
@@ -105,9 +107,12 @@
            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 @@
 /** @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) {

_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

Reply via email to