Log SIP account with INPUT/OUTPUT message logs user/berick/log-sip-account-with-messages
authorBill Erickson <berickxx@gmail.com>
Mon, 22 Feb 2016 15:30:24 +0000 (10:30 -0500)
committerBill Erickson <berickxx@gmail.com>
Mon, 22 Feb 2016 15:30:24 +0000 (10:30 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
SIPServer.pm
Sip.pm
Sip/MsgType.pm

index 7573ffe..8dbb512 100644 (file)
@@ -275,7 +275,7 @@ sub sip_protocol_loop {
     #$expect = SC_STATUS;
     $expect = '';
 
-    while ( $input = Sip::read_SIP_packet(*STDIN) ) {
+    while ( $input = Sip::read_SIP_packet(*STDIN, $self) ) {
         $input =~ s/[\r\n]+$//sm;    # Strip off any trailing line ends
 
         my $start = time;
diff --git a/Sip.pm b/Sip.pm
index df75664..57b2e47 100644 (file)
--- a/Sip.pm
+++ b/Sip.pm
@@ -157,10 +157,16 @@ sub boolspace {
 # Read a packet from $file, using the correct record separator
 #
 sub read_SIP_packet {
-    my $record;
     my $fh = shift or syslog("LOG_ERR", "read_SIP_packet: no filehandle argument!");
+    my $sip_server = shift;
+    my $record;
     my $len1 = 999;
 
+    # during login, the account will not exist yet.
+    my $account = '';
+    $account = $sip_server->{account}->{id}
+        if $sip_server && $sip_server->{account};
+
     # local $/ = "\r";      # don't need any of these here.  use whatever the prevailing $/ is.
     local $/ = "\015";    # proper SPEC: (octal) \015 = (hex) x0D = (dec) 13 = (ascii) carriage return
     {    # adapted from http://perldoc.perl.org/5.8.8/functions/readline.html
@@ -190,7 +196,6 @@ sub read_SIP_packet {
     }
     if ($record) {
         my $len2 = length($record);
-        syslog("LOG_INFO", "read_SIP_packet, INPUT MSG: '$record'") if $record;
         ($len1 != $len2) and syslog("LOG_DEBUG", "read_SIP_packet, trimmed %s character(s) (after chomps).", $len1-$len2);
     } else {
         syslog("LOG_WARNING", "read_SIP_packet input %s, end of input.", (defined($record) ? "empty ($record)" : 'undefined'));
@@ -207,7 +212,7 @@ sub read_SIP_packet {
     # on the input.
     #  
     # This is now handled by the vigorous cleansing above.
-    syslog("LOG_INFO", encode_utf8("INPUT MSG: '$record'")) if $record;
+    syslog("LOG_INFO", encode_utf8("INPUT MSG [$account]: '$record'")) if $record;
     return $record;
 }
 
@@ -226,6 +231,10 @@ sub write_msg {
     my ($self, $msg, $file) = @_;
     my $cksum;
 
+    my $account = '';
+    $account = $self->{server}->{account}->{id} 
+        if $self->{server} && $self->{server}->{account};
+
     $msg = encode_utf8($msg);
     if ($error_detection) {
         if (defined($self->{seqno})) {
@@ -241,7 +250,7 @@ sub write_msg {
         print $file "$msg\r";
     } else {
         print "$msg\r";
-        syslog("LOG_INFO", "OUTPUT MSG: '$msg'");
+        syslog("LOG_INFO", "OUTPUT MSG [$account]: '$msg'");
     }
 
     $last_response = $msg;
index 6805294..d152e5a 100644 (file)
@@ -422,6 +422,10 @@ sub handle {
        $req && (substr($msg, 0, 2) ne $req)) {
        return substr($msg, 0, 2);
     }
+
+    # link the server to the message so we don't have to 
+    # propagate the server to subs called by the handler (below).
+    $self->{server} = $server;
     return($self->{handler}->($self, $server));
 }