22 pod2usage
(-verbose
=> 2) if $Options{help
};
24 ###############################################################################
28 ###############################################################################
34 my($direction, $type, $time, @message) = @_;
36 # Only handle SIP for now...
37 return unless $type eq "SIP";
39 my($index, $callid, $from, $method);
40 foreach my $line (@message) {
42 last if $line =~ /^\s+$/;
44 next unless my($keyword, $value) = $line =~ /^([^:]+):\s+(.+)/;
45 $callid = $value if $keyword =~ /^call-id$/i;
46 ($from) = $value =~ /^<sip:([^;>]+)/ if $keyword =~ /^from$/i;
47 ($method) = $value =~ /^\d+\s+(\S+)/ if $keyword =~ /^cseq$/i;
49 push(@
{$callid{$callid}}, \
@message) if $Options{callid
} && defined $callid;
50 push(@
{$from{lc($from)}}, \
@message) if $Options{from
} && defined $from;
51 push(@
{$method{uc($method)}}, \
@message) if $Options{method
} && defined $method;
56 foreach my $callid (keys %callid) {
58 File
::Spec
->catfile($Options{directory
}, "callid-${callid}.txt"))) {
59 print $fh @
{$_} foreach (@
{$callid{$callid}});
63 foreach my $from (keys %from) {
65 File
::Spec
->catfile($Options{directory
}, "from-${from}.txt"))) {
66 print $fh @
{$_} foreach (@
{$from{$from}});
70 foreach my $method (keys %method) {
72 File
::Spec
->catfile($Options{directory
}, "method-${method}.txt"))) {
73 print $fh @
{$_} foreach (@
{$method{$method}});
79 ###############################################################################
83 ###############################################################################
85 # For all lines from command line files or STDIN
91 if (my ($direction, $type, $time) =
92 /^MESSAGE START\s+([<>]+)\s+(\S+)\s+-\s+(.+)/) {
94 "------------- NEXT MESSAGE: " .
95 (($direction =~ /^>/) ?
"outgoing" : "incoming") .
99 } elsif (($direction, $type, $time) =
100 /^MESSAGE END\s+([<>]+)\s+(\S+)\s+-\s+(.+)/) {
102 if ($Options{filter
}) {
105 print STDERR
"." if (++$counter % 10 == 0);
106 AddMessage
($direction, $type, $time, @message);
109 # Done with the current message
115 # Collect message information
116 push(@message, $_) if @message;
120 unless ($Options{filter
}) {
121 print STDERR
"\n" unless $Options{filter
};
125 # That's all folks...
132 parse_log.pl - parse pidgin-sipe debug log
136 [perl} parse_log.pl --help|-h|-?
138 [perl} parse_log.pl --filter
141 [perl} parse_log.pl [--directory <dir>]
153 Dump all SIP messages belonging to one Call-ID to the same file.
157 Directory for output files. Default is the current directory.
161 Enable filter mode. Messages are simply printed to stdout.
165 Dump all SIP messages sent from the same SIP URI to the same file.
173 Print a brief help message and exits.
177 Dump all SIP messages with the same method to the same file.
183 B<This program> extracts SIP/HTTP messages from pidgin-sipe debug logs. If
184 no file is specified then it reads from STDIN.