From 0dd1aa7cc7b15b3bedc3dc4da2fc15d5b726c10a Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 16 Feb 2011 22:10:24 +1300 Subject: Initial port of mitmdump to Flows. --- libmproxy/dump.py | 66 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 27 deletions(-) (limited to 'libmproxy/dump.py') diff --git a/libmproxy/dump.py b/libmproxy/dump.py index 1fe1c095..7eff4992 100644 --- a/libmproxy/dump.py +++ b/libmproxy/dump.py @@ -1,40 +1,52 @@ import sys -import controller +import flow -#begin nocover -class DumpMaster(controller.Master): - """ - A simple master that just dumps to screen. - """ - def __init__(self, server, verbosity): - self.verbosity = verbosity - controller.Master.__init__(self, server) +class DumpMaster(flow.FlowMaster): + def __init__(self, server, verbosity, outfile=sys.stderr): + self.verbosity, self.outfile = verbosity, outfile + flow.FlowMaster.__init__(self, server, flow.State()) - def run(self): - try: - return controller.Master.run(self) - except KeyboardInterrupt: - self.shutdown() + def handle_clientconnection(self, r): + flow.FlowMaster.handle_clientconnection(self, r) + r.ack() + + def handle_error(self, r): + flow.FlowMaster.handle_error(self, r) + r.ack() + + def handle_request(self, r): + flow.FlowMaster.handle_request(self, r) + r.ack() def handle_response(self, msg): + f = flow.FlowMaster.handle_response(self, msg) if 0 < self.verbosity < 3: - print >> sys.stderr, ">>", - print >> sys.stderr, msg.request.short() + print >> self.outfile, ">>", + print >> self.outfile, msg.request.short() if self.verbosity == 1: - print >> sys.stderr, "<<", - print >> sys.stderr, msg.short() + print >> self.outfile, "<<", + print >> self.outfile, msg.short() elif self.verbosity == 2: - print >> sys.stderr, "<<" + print >> self.outfile, "<<" for i in msg.assemble().splitlines(): - print >> sys.stderr, "\t", i - print >> sys.stderr, "<<" + print >> self.outfile, "\t", i + print >> self.outfile, "<<" elif self.verbosity == 3: - print >> sys.stderr, ">>" + print >> self.outfile, ">>" for i in msg.request.assemble().splitlines(): - print >> sys.stderr, "\t", i - print >> sys.stderr, ">>" - print >> sys.stderr, "<<" + print >> self.outfile, "\t", i + print >> self.outfile, ">>" + print >> self.outfile, "<<" for i in msg.assemble().splitlines(): - print >> sys.stderr, "\t", i - print >> sys.stderr, "<<" + print >> self.outfile, "\t", i + print >> self.outfile, "<<" msg.ack() + + +# begin nocover + def run(self): + try: + return flow.FlowMaster.run(self) + except KeyboardInterrupt: + self.shutdown() + -- cgit v1.2.3