-
Notifications
You must be signed in to change notification settings - Fork 0
/
parseops3.rb
50 lines (42 loc) · 1.17 KB
/
parseops3.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/ruby -I ./lib
require 'ldapreplay/parsers/openldap'
require 'ldapreplay/ldapoperation'
require 'ldapreplay/ldapconnection'
require 'pp'
require 'yaml'
parser = LdapReplay::Parsers::OpenLDAP.new( *ARGV )
conn_hsh = {}
conn_ary = []
op_hsh = Hash.new { |hh, kk| hh[kk] = [] }
parser.emit { |args|
begin
op_time, op_conn, op_id, op_type, op_args = *args
# puts "args: #{args.join(' ')}"
case op_type
when 'ACCEPT'
nc = LdapReplay::LdapConnection.new( *op_args )
nc.id = (conn_ary.push(nc).size) - 1
conn_hsh[op_conn] = nc.id
when 'closed'
conn_hsh.delete op_conn
when 'RESULT'
else
if conn_hsh[op_conn] and conn = conn_ary[conn_hsh[op_conn]]
if new_op = conn.add_op(*args)
op_hsh[new_op.op_time].push(new_op)
end
end
end
rescue Errno::EPIPE
break
end
}
# puts "--------------------"
# puts "conn_hsh: %s" % conn_hsh.pretty_inspect
# puts "===================="
# puts "conn_ary: %s" % conn_ary.pretty_inspect
# puts "conn_ary: #{conn_ary}"
# puts "^^^^^^^^^^^^^^^^^^^^"
# puts YAML.dump conn_ary
# puts "op_hsh: %s" % op_hsh.pretty_inspect
puts YAML.dump [conn_ary, op_hsh]