23 pod2usage
(-verbose
=> 2) if $Options{help
};
25 ###############################################################################
29 ###############################################################################
36 my($direction, $type, $transport, $time, @message) = @_;
38 # extract additional information from SIP messages
40 my($index, $callid, $from, $method);
41 foreach my $line (@message) {
43 last if $line =~ /^\s+$/;
45 next unless my($keyword, $value) = $line =~ /^([^:]+):\s+(.+)/;
46 $callid = $value if $keyword =~ /^call-id$/i;
47 ($from) = $value =~ /^<sip:([^;>]+)/ if $keyword =~ /^from$/i;
48 ($method) = $value =~ /^\d+\s+(\S+)/ if $keyword =~ /^cseq$/i;
50 push(@
{$callid{$callid}}, \
@message) if $Options{callid
} && defined $callid;
51 push(@
{$from{lc($from)}}, \
@message) if $Options{from
} && defined $from;
52 push(@
{$method{uc($method)}}, \
@message) if $Options{method
} && defined $method;
55 # information available for all message types
56 push(@
{$transport{$transport}}, \
@message) if $Options{transport
};
61 foreach my $callid (keys %callid) {
63 File
::Spec
->catfile($Options{directory
}, "callid-${callid}.txt"))) {
64 print $fh @
{$_} foreach (@
{$callid{$callid}});
68 foreach my $from (keys %from) {
70 File
::Spec
->catfile($Options{directory
}, "from-${from}.txt"))) {
71 print $fh @
{$_} foreach (@
{$from{$from}});
75 foreach my $method (keys %method) {
77 File
::Spec
->catfile($Options{directory
}, "method-${method}.txt"))) {
78 print $fh @
{$_} foreach (@
{$method{$method}});
82 foreach my $transport (keys %transport) {
84 File
::Spec
->catfile($Options{directory
}, "transport-${transport}.txt"))) {
85 print $fh @
{$_} foreach (@
{$transport{$transport}});
91 ###############################################################################
95 ###############################################################################
97 # For all lines from command line files or STDIN
103 if (my ($direction, $type, $transport, $time) =
104 /^MESSAGE START\s+([<>]+)\s+([^(]+)\((0x[\da-f]+)\)\s+-\s+(.+)/) {
106 "------------- NEXT MESSAGE: " .
107 (($direction =~ /^>/) ?
"outgoing" : "incoming") .
108 " $type($transport) at $time\n");
111 } elsif (($direction, $type, $transport, $time) =
112 /^MESSAGE END\s+([<>]+)\s+([^(]+)\((0x[\da-f]+)\)\s+-\s+(.+)/) {
114 if ($Options{filter
}) {
117 print STDERR
"." if (++$counter % 10 == 0);
118 AddMessage
($direction, $type, $transport, $time, @message);
121 # Done with the current message
127 # Collect message information
128 push(@message, $_) if @message;
132 unless ($Options{filter
}) {
133 print STDERR
"\n" unless $Options{filter
};
137 # That's all folks...
144 parse_log.pl - parse pidgin-sipe debug log
148 [perl} parse_log.pl --help|-h|-?
150 [perl} parse_log.pl --filter
153 [perl} parse_log.pl [--directory <dir>]
166 Dump all SIP messages belonging to one Call-ID to the same file.
170 Directory for output files. Default is the current directory.
174 Enable filter mode. Messages are simply printed to stdout.
178 Dump all SIP messages sent from the same SIP URI to the same file.
186 Print a brief help message and exits.
190 Dump all SIP messages with the same method to the same file.
194 Dump all messages from one transport to the same file.
200 B<This program> extracts SIP/HTTP messages from pidgin-sipe debug logs. If
201 no file is specified then it reads from STDIN.