Extract flow-specific Master operations into FlowMaster.

This commit is contained in:
Aldo Cortesi 2011-02-16 16:03:22 +13:00
parent 33dac700fa
commit 27f0765cdd
3 changed files with 49 additions and 20 deletions

View File

@ -779,7 +779,7 @@ VIEW_CONNLIST = 0
VIEW_FLOW = 1 VIEW_FLOW = 1
VIEW_HELP = 2 VIEW_HELP = 2
class ConsoleMaster(controller.Master): class ConsoleMaster(flow.FlowMaster):
palette = [] palette = []
footer_text_default = [ footer_text_default = [
('key', "?"), ":help ", ('key', "?"), ":help ",
@ -794,10 +794,10 @@ class ConsoleMaster(controller.Master):
('key', "q"), ":back ", ('key', "q"), ":back ",
] ]
def __init__(self, server, options): def __init__(self, server, options):
flow.FlowMaster.__init__(self, server, ConsoleState())
self.conn_list_view = None self.conn_list_view = None
self.set_palette() self.set_palette()
controller.Master.__init__(self, server)
self.state = ConsoleState()
r = self.set_limit(options.limit) r = self.set_limit(options.limit)
if r: if r:
@ -1313,23 +1313,18 @@ class ConsoleMaster(controller.Master):
# Handlers # Handlers
def handle_clientconnection(self, r): def handle_clientconnection(self, r):
f = flow.Flow(r) f = flow.FlowMaster.handle_clientconnection(self, r)
self.state.add_browserconnect(f) if f:
r.ack()
self.sync_list_view() self.sync_list_view()
def handle_error(self, r): def handle_error(self, r):
f = self.state.add_error(r) f = flow.FlowMaster.handle_error(self, r)
if not f: if f:
r.ack()
else:
self.process_flow(f, r) self.process_flow(f, r)
def handle_request(self, r): def handle_request(self, r):
f = self.state.add_request(r) f = flow.FlowMaster.handle_request(self, r)
if not f: if f:
r.ack()
else:
if f.match(self.stickycookie): if f.match(self.stickycookie):
hid = (f.request.host, f.request.port) hid = (f.request.host, f.request.port)
if f.request.headers.has_key("cookie"): if f.request.headers.has_key("cookie"):
@ -1339,10 +1334,8 @@ class ConsoleMaster(controller.Master):
self.process_flow(f, r) self.process_flow(f, r)
def handle_response(self, r): def handle_response(self, r):
f = self.state.add_response(r) f = flow.FlowMaster.handle_request(self, r)
if not f: if f:
r.ack()
else:
if f.match(self.stickycookie): if f.match(self.stickycookie):
hid = (f.request.host, f.request.port) hid = (f.request.host, f.request.port)
if f.response.headers.has_key("set-cookie"): if f.response.headers.has_key("set-cookie"):

View File

@ -4,6 +4,7 @@
""" """
import subprocess, base64, sys, json import subprocess, base64, sys, json
import proxy, threading, netstring import proxy, threading, netstring
import controller
class RunException(Exception): class RunException(Exception):
def __init__(self, msg, returncode, errout): def __init__(self, msg, returncode, errout):
@ -286,6 +287,41 @@ class State:
#end nocover #end nocover
class FlowMaster(controller.Master):
def __init__(self, server, state):
controller.Master.__init__(self, server)
self.state = state
# Handlers
def handle_clientconnection(self, r):
f = Flow(r)
self.state.add_browserconnect(f)
r.ack()
return f
def handle_error(self, r):
f = self.state.add_error(r)
if not f:
r.ack()
return f
def handle_request(self, r):
f = self.state.add_request(r)
if not f:
r.ack()
return f
def handle_response(self, r):
f = self.state.add_response(r)
if not f:
r.ack()
else:
if f.match(self.stickycookie):
hid = (f.request.host, f.request.port)
if f.response.headers.has_key("set-cookie"):
self.stickyhosts[hid] = f.response.headers["set-cookie"]
self.process_flow(f, r)
class FlowWriter: class FlowWriter:
def __init__(self, fo): def __init__(self, fo):

View File

@ -307,7 +307,7 @@ class ClientConnection(controller.Msg):
controller.Msg.__init__(self) controller.Msg.__init__(self)
def get_state(self): def get_state(self):
return list(self.address) return list(self.address) if self.address else None
@classmethod @classmethod
def from_state(klass, state): def from_state(klass, state):