~ubuntu-branches/debian/experimental/openchange/experimental

« back to all changes in this revision

Viewing changes to utils/mapitrace/lib/MAPI/Dump_EcDoRpc.pm

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2008-08-06 18:32:45 UTC
  • Revision ID: james.westby@ubuntu.com-20080806183245-nauuj71be5mm03w7
Tags: upstream-1.0~svn679
ImportĀ upstreamĀ versionĀ 1.0~svn679

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#############################################
 
2
# EcDoRpc Dump utility for mapitrace tool
 
3
# Copyright Julien Kerihuel 2007
 
4
# <j.kerihuel@openchange.org>
 
5
#
 
6
# released under the GNU GPL v3 or later
 
7
#
 
8
package MAPI::Dump_EcDoRpc;
 
9
 
 
10
require Exporter;
 
11
@ISA = qw(Exporter);
 
12
@EXPORT = qw();
 
13
use vars qw($AUTOLOAD $VERSION);
 
14
$VERSION = '0.01';
 
15
 
 
16
use strict;
 
17
use Data::Dumper;
 
18
 
 
19
#######################################################
 
20
# convenient sort functions                           #
 
21
#######################################################
 
22
sub pkt_number 
 
23
{
 
24
    my ($aa) = $a =~ /(\d+)/;
 
25
    my($bb) = $b =~ /(\d+)/;
 
26
    ($aa) <=> ($bb);
 
27
}
 
28
 
 
29
sub asc_num {
 
30
   hex($a) <=> hex($b);
 
31
}
 
32
#######################################################
 
33
# BRACE DUMPING FUNCTIONS
 
34
#######################################################
 
35
 
 
36
sub dump_error_brace
 
37
{
 
38
    my $_self = shift;
 
39
    my $self = shift;
 
40
 
 
41
    foreach my $key (sort asc_num (keys(%{$self->{BRACES_ERROR}}))) {
 
42
        my $inout = $self->{BRACES_ERROR}->{$key}->{error};
 
43
        if ($inout) {
 
44
            print "[mapitrace] error in [$inout]: ";
 
45
            print $self->{BRACES_ERROR}->{$key}->{$inout}->{filename} . "\n";
 
46
        }
 
47
    }
 
48
}
 
49
 
 
50
sub dump_brace_start
 
51
{
 
52
    my $_self = shift;
 
53
    my $in = shift;
 
54
    my $out = shift;
 
55
 
 
56
    print MAPI::EcDoRpc->get_filename($in->{filename});
 
57
    print " / ";
 
58
    print MAPI::EcDoRpc->get_filename($out->{filename});
 
59
    print "\n";
 
60
    print "----------------------------------------------\n";
 
61
}
 
62
 
 
63
sub dump_brace_end
 
64
{
 
65
    print "\n\n";
 
66
}
 
67
 
 
68
#######################################################
 
69
# DUMP FUNCTIONS FOR THE ANALYZE PART
 
70
#######################################################
 
71
 
 
72
#
 
73
# Dump the handles array from a request or response
 
74
#
 
75
sub dump_handles
 
76
{
 
77
    my $_self = shift;
 
78
    my $self = shift;
 
79
    my @handles = @_;
 
80
 
 
81
    print $self->{filename} . " :\n";
 
82
    print "handles array (" . ($#handles + 1) . "):\n";
 
83
    print "\t$_\n" foreach (@handles);
 
84
    print "\n";
 
85
}
 
86
 
 
87
#
 
88
# Provides a dual dump view for the handle array
 
89
# both in request and response
 
90
#
 
91
# MAPI Semantic tells that request and response have the same
 
92
# number of handles elements
 
93
#
 
94
sub dump_brace_handles
 
95
{
 
96
    my $_self = shift;
 
97
    my $mapi_call = shift;
 
98
 
 
99
    my @handles_in = @{$mapi_call->{handles_in}};
 
100
    my @handles_out = @{$mapi_call->{handles_out}};
 
101
 
 
102
    print "handles array (" . ($#handles_in + 1) . "):\n";
 
103
    for (my $i = 0; $handles_in[$i]; $i++) {
 
104
        printf "\t[%.2x] %s -> %s\n", $i, $handles_in[$i], $handles_out[$i];
 
105
    }
 
106
}
 
107
 
 
108
#
 
109
# Print a call
 
110
#
 
111
#
 
112
sub dump_call
 
113
{
 
114
    my $mapi_call = shift;
 
115
    my $key = shift;
 
116
    my $call_idx = shift;
 
117
    my $space = shift;
 
118
 
 
119
    my $in  = $mapi_call->{calls}->{REQ};
 
120
    my $out = $mapi_call->{calls}->{REPL};
 
121
 
 
122
    my $new_idx;
 
123
    
 
124
    if ($call_idx) {
 
125
        $new_idx = MAPI::EcDoRpc->get_call_index($mapi_call, $call_idx);
 
126
        printf "\t%s+-- [0x%.2x] [%s] (opnum = %s) %15s (handle_idx = %s) (child of %s)\n", 
 
127
        $space, hex($call_idx), 
 
128
        (exists $out->{$new_idx}->{retval}) ? $out->{$new_idx}->{retval}:'',
 
129
        $in->{$call_idx}->{opnum}, $in->{$call_idx}->{opname}, 
 
130
        $in->{$call_idx}->{handle_idx}, $in->{$key}->{opname};
 
131
    } else {
 
132
        $new_idx = MAPI::EcDoRpc->get_call_index($mapi_call, $key);
 
133
        printf "\t[0x%.2x] [%s] (opnum = %s) %25s (handle_idx = %s) (self_handle_idx = %s)\n", 
 
134
        hex($key), 
 
135
        (exists $out->{$new_idx}->{retval}) ? $out->{$new_idx}->{retval} : '', 
 
136
        $in->{$key}->{opnum}, $in->{$key}->{opname}, 
 
137
        $in->{$key}->{handle_idx},
 
138
        $in->{$key}->{self_handle_idx};
 
139
    }
 
140
}
 
141
 
 
142
#
 
143
# Dump mapi calls
 
144
#
 
145
# Since calls with self_handles have a smaller index than other calls relying on them
 
146
# When a parent value is > than the current idx, we can skip display the call.
 
147
# It should have normally been printing earlier when checking for call children
 
148
# Return -1 if we have an error
 
149
#
 
150
 
 
151
sub dump_mapi_calls
 
152
{
 
153
    my $_self = shift;
 
154
    my $mapi_call = shift;
 
155
 
 
156
    my $in  = $mapi_call->{calls}->{REQ};
 
157
    my $out = $mapi_call->{calls}->{REPL};
 
158
 
 
159
    my $in_call_count = MAPI::EcDoRpc->get_mapi_calls_request_count($in);
 
160
 
 
161
    if ($in_call_count != keys(%{$out})) {
 
162
        print "[mapitrace] error: Oops seems like we have some trouble ...\n";
 
163
        print "[mapitrace] error: Mismatch call count between request ($in_call_count) and response (". keys(%{$out})  .")\n";
 
164
        return -1;
 
165
    }
 
166
    
 
167
    printf "serialized mapi calls (count = %.2d):\n", $in_call_count;
 
168
    foreach my $key (sort asc_num (keys(%{$in}))) {
 
169
        if ($in->{$key}->{self_handle_idx}) {
 
170
            # If this self_handle call has a child ;p
 
171
            my $space = "  ";
 
172
            if (exists $in->{$key}->{parent}) {
 
173
                $space .= "       ";
 
174
            } else {
 
175
                dump_call($mapi_call, $key, 0, 0);
 
176
            }
 
177
            # Check if the call with self_handle_idx has children
 
178
            # The dump will fail if we have Release call.
 
179
            # In order to avoid this problem we use out instead
 
180
            
 
181
            if ($in->{$key}->{children}) {
 
182
                foreach my $call_idx (sort asc_num @{$in->{$key}->{children}}) {
 
183
                    dump_call($mapi_call, $key, $call_idx, $space);
 
184
                }
 
185
            }
 
186
        }
 
187
        else {
 
188
            if (exists $in->{$key}->{parent} && hex($in->{$key}->{parent}) < hex($key)) {
 
189
            } else {
 
190
                printf "\t[0x%.2x] [%s] (opnum = %s) %25s (handle_idx = %s)\n", 
 
191
                hex($key),
 
192
                (exists $out->{$key}->{retval}) ? $out->{$key}->{retval}: '', 
 
193
                $in->{$key}->{opnum}, $in->{$key}->{opname}, $in->{$key}->{handle_idx};     
 
194
            }
 
195
        }
 
196
    }
 
197
    print "\n";
 
198
    return 0;
 
199
}
 
200
 
 
201
1;