[Zope-CVS] CVS: Packages/tcpwatch - tcpwatch:1.10
Shane Hathaway
shane@cvs.zope.org
Fri, 22 Feb 2002 18:18:28 -0500
Update of /cvs-repository/Packages/tcpwatch
In directory cvs.zope.org:/tmp/cvs-serv14913
Modified Files:
tcpwatch
Log Message:
Added option to turn carriage return display on and added TODOs
=== Packages/tcpwatch/tcpwatch 1.9 => 1.10 ===
RECV_BUFFER_SIZE = 8192
+show_cr = 0
#############################################################################
@@ -336,6 +337,8 @@
else:
newline = 0
+ if not show_cr:
+ data = data.replace('\r', '')
lines = data.split('\n')
lines = map(escape, lines)
s = ('\n%s' % arrow).join(lines)
@@ -499,6 +502,10 @@
if not self._colorized:
BasicObserver.received(self, data, from_client)
return
+
+ if not show_cr:
+ data = data.replace('\r', '')
+
output = []
extra_color = (self._colorized == 2)
@@ -932,6 +939,8 @@
class HTTPProxyResponseBuffer:
"""Ensures that responses to a persistent HTTP connection occur
in the correct order."""
+ # TODO: inherit from ForwardingEndpoint so it's possible to
+ # close the server connection. Rename to HTTPProxyToServerConnection.
finished = 0
@@ -986,6 +995,9 @@
"""
for s in self.watching_streams:
s.close()
+ if not self.finished:
+ # TODO: cancel the proxy connection.
+ pass
self.finished = 1
self.flush()
@@ -998,6 +1010,7 @@
class HTTPProxyConnection (ForwardingEndpoint):
"""A connection from a client to the proxy server"""
+ # TODO: rename to HTTPProxyToClientConnection.
_req_parser = None
_transaction = 0
@@ -1090,14 +1103,19 @@
ep = ForwardingEndpoint() # connects server to buf (to self)
ep.write('%s %s %s\r\n' % (command, path, protocol))
# Duplicate the headers sent by the client.
- ep.write(request.header)
- ep.write('\r\n')
+ if request.header:
+ ep.write(request.header)
+ else:
+ ep.write('\r\n')
if request.body_data:
ep.write(''.join(request.body_data))
ep.set_dests((buf,))
ep.create_socket(socket.AF_INET, socket.SOCK_STREAM)
ep.connect((host, port))
+ def close(self):
+ ForwardingEndpoint.close(self)
+ # TODO: Close the open connections to HTTP servers.
class HTTPProxyService (asyncore.dispatcher):
@@ -1140,7 +1158,7 @@
print 'Utility for monitoring TCP and HTTP connections'
print 'Simple usage: tcpwatch -L listen_port:dest_hostname:dest_port'
print """
-Forwarded connection setup:
+TCP forwarded connection setup:
-L <listen_port>:<dest_port>
Set up a local forwarded connection
-L <listen_port>:<dest_host>:<dest_port>
@@ -1149,12 +1167,13 @@
Set up a forwarded connection to a specified host, bound to an interface
HTTP setup:
- -h (or --http) Parse as HTTP, splitting up multi-transaction connections
- -p [<listen_host>:]<listen_port> Run an HTTP proxy (implies -h)
+ -h (or --http) Split forwarded HTTP persistent connections
+ -p [<listen_host>:]<listen_port> Run an HTTP proxy
Output options:
-n No color in GUI (faster and consumes less RAM)
-c Extra color (colorizes escaped characters)
+ -r Show carriage returns (ASCII 13)
-s Output to stdout instead of a Tkinter window
"""
sys.exit()
@@ -1166,8 +1185,9 @@
def main(args):
+ global show_cr
- optlist, extra = getopt.getopt(args, 'chL:np:s', ['help', 'http'])
+ optlist, extra = getopt.getopt(args, 'chL:np:rs', ['help', 'http'])
fwd_params = []
proxy_params = []
@@ -1185,6 +1205,8 @@
colorized = 0
elif option == '-c':
colorized = 2
+ elif option == '-r':
+ show_cr = 1
elif option == '-s':
show_config = 1
obs_factory = StdoutObserver