Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1231 → Rev 1232

/TCPproxy/trunk/MainForm.cs
174,41 → 174,41
this.panel3.SuspendLayout();
this.panel4.SuspendLayout();
this.SuspendLayout();
//
//
// wordWrapMenuItem
//
//
this.wordWrapMenuItem.Index = 2;
this.wordWrapMenuItem.Text = "Word &Wrap";
this.wordWrapMenuItem.Click += new System.EventHandler(this.wordWrapMenuItem_Click);
//
//
// treeImageList
//
//
this.treeImageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("treeImageList.ImageStream")));
this.treeImageList.TransparentColor = System.Drawing.Color.Magenta;
//
//
// messagesContextMenu
//
//
this.messagesContextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.selectAllmenuItem,
this.copyMenuItem,
this.wordWrapMenuItem});
//
//
// selectAllmenuItem
//
//
this.selectAllmenuItem.Index = 0;
this.selectAllmenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlA;
this.selectAllmenuItem.Text = "Select &All";
this.selectAllmenuItem.Click += new System.EventHandler(this.selectAllMenuItem_Click);
//
//
// copyMenuItem
//
//
this.copyMenuItem.Index = 1;
this.copyMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlC;
this.copyMenuItem.Text = "&Copy";
this.copyMenuItem.Click += new System.EventHandler(this.copyMenuItem_Click);
//
//
// statusBar
//
//
this.statusBar.Location = new System.Drawing.Point(0, 339);
this.statusBar.Name = "statusBar";
this.statusBar.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
216,44 → 216,44
this.statusBar.ShowPanels = true;
this.statusBar.Size = new System.Drawing.Size(780, 22);
this.statusBar.TabIndex = 0;
//
//
// connectionStatusBar
//
//
this.connectionStatusBar.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
this.connectionStatusBar.Width = 764;
//
//
// saveButtonImageList
//
//
this.saveButtonImageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("saveButtonImageList.ImageStream")));
this.saveButtonImageList.TransparentColor = System.Drawing.Color.Magenta;
//
//
// closeConnectionMenuItem
//
//
this.closeConnectionMenuItem.Index = 0;
this.closeConnectionMenuItem.Text = "&Close connection";
this.closeConnectionMenuItem.Click += new System.EventHandler(this.closeConnectionMenuItem_Click);
//
//
// viewContextMenu
//
//
this.viewContextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.closeConnectionMenuItem,
this.autoExpandMenuItem});
//
//
// saveLogDialog
//
//
this.saveLogDialog.DefaultExt = "txt";
this.saveLogDialog.Filter = "Text Files (*.txt)|*.txt|All Files|*.*";
this.saveLogDialog.Title = "Save Log";
//
//
// mainMenu
//
//
this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.fileMenu,
this.viewMenu,
this.helpMenu});
//
//
// fileMenu
//
//
this.fileMenu.Index = 0;
this.fileMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.startMenuItem,
270,91 → 270,91
this.menuSeparator2,
this.exitMenuItem});
this.fileMenu.Text = "&File";
//
//
// startMenuItem
//
//
this.startMenuItem.Index = 0;
this.startMenuItem.Text = "&Start...";
this.startMenuItem.Click += new System.EventHandler(this.startMenuItem_Click);
//
//
// stopMenuItem
//
//
this.stopMenuItem.Enabled = false;
this.stopMenuItem.Index = 1;
this.stopMenuItem.Text = "S&top";
this.stopMenuItem.Click += new System.EventHandler(this.stopMenuItem_Click);
//
//
// recentListeningMenu
//
//
this.recentListeningMenu.Index = 2;
this.recentListeningMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.recentListeningNoItem});
this.recentListeningMenu.Text = "&Recent Listenings";
//
//
// recentListeningNoItem
//
//
this.recentListeningNoItem.Enabled = false;
this.recentListeningNoItem.Index = 0;
this.recentListeningNoItem.Text = "(no items)";
//
//
// menuSeparator5
//
//
this.menuSeparator5.Index = 3;
this.menuSeparator5.Text = "-";
//
//
// loadBinLogMenuItem
//
//
this.loadBinLogMenuItem.Index = 4;
this.loadBinLogMenuItem.Text = "&Load Bin Log...";
this.loadBinLogMenuItem.Click += new System.EventHandler(this.loadBinLogMenuItem_Click);
//
//
// saveBinLogMenuItem
//
//
this.saveBinLogMenuItem.Index = 5;
this.saveBinLogMenuItem.Text = "&Save Bin Log...";
this.saveBinLogMenuItem.Click += new System.EventHandler(this.saveBinLogMenuItem_Click);
//
//
// menuSeparator1
//
//
this.menuSeparator1.Index = 6;
this.menuSeparator1.Text = "-";
//
//
// saveLogMenuItem
//
//
this.saveLogMenuItem.Index = 7;
this.saveLogMenuItem.Text = "Save Log Messa&ges...";
this.saveLogMenuItem.Click += new System.EventHandler(this.saveLogMenuItem_Click);
//
//
// saveTcoLogMenuItem
//
//
this.saveTcoLogMenuItem.Index = 8;
this.saveTcoLogMenuItem.Text = "Save T&CP Log...";
this.saveTcoLogMenuItem.Click += new System.EventHandler(this.saveTcpMenuItem_Click);
//
//
// saveHttpLogMenuItem
//
//
this.saveHttpLogMenuItem.Index = 9;
this.saveHttpLogMenuItem.Text = "Save Htt&p Log...";
this.saveHttpLogMenuItem.Click += new System.EventHandler(this.saveHttpMenuItem_Click);
//
//
// saveXmlLogMenuItem
//
//
this.saveXmlLogMenuItem.Index = 10;
this.saveXmlLogMenuItem.Text = "Save X&ML Log...";
this.saveXmlLogMenuItem.Click += new System.EventHandler(this.saveXmlMenuItem_Click);
//
//
// menuSeparator2
//
//
this.menuSeparator2.Index = 11;
this.menuSeparator2.Text = "-";
//
//
// exitMenuItem
//
//
this.exitMenuItem.Index = 12;
this.exitMenuItem.Text = "E&xit";
//
//
// viewMenu
//
//
this.viewMenu.Index = 1;
this.viewMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.clearMainMenuItem,
366,15 → 366,15
this.autoExpandMainMenuItem,
this.wordWrapMainMenuItem});
this.viewMenu.Text = "&View";
//
//
// clearMainMenuItem
//
//
this.clearMainMenuItem.Index = 0;
this.clearMainMenuItem.Text = "&Clear";
this.clearMainMenuItem.Click += new System.EventHandler(this.clearMenuItem_Click);
//
//
// messagesMenu
//
//
this.messagesMenu.Index = 1;
this.messagesMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.allMessagesMenuItem,
381,76 → 381,76
this.infoMessagesMenuItem,
this.importantMessagesMenuItem});
this.messagesMenu.Text = "&Messages";
//
//
// allMessagesMenuItem
//
//
this.allMessagesMenuItem.Checked = true;
this.allMessagesMenuItem.Index = 0;
this.allMessagesMenuItem.Text = "&All";
this.allMessagesMenuItem.Click += new System.EventHandler(this.messagesMenuItem_Click);
//
//
// infoMessagesMenuItem
//
//
this.infoMessagesMenuItem.Index = 1;
this.infoMessagesMenuItem.Text = "&Info";
this.infoMessagesMenuItem.Click += new System.EventHandler(this.messagesMenuItem_Click);
//
//
// importantMessagesMenuItem
//
//
this.importantMessagesMenuItem.Index = 2;
this.importantMessagesMenuItem.Text = "I&mportant";
this.importantMessagesMenuItem.Click += new System.EventHandler(this.messagesMenuItem_Click);
//
//
// menuSeparator3
//
//
this.menuSeparator3.Index = 2;
this.menuSeparator3.Text = "-";
//
//
// tcpShowByDirectionMenuItem
//
//
this.tcpShowByDirectionMenuItem.Checked = true;
this.tcpShowByDirectionMenuItem.Index = 3;
this.tcpShowByDirectionMenuItem.Text = "TCP Show by &Direction";
this.tcpShowByDirectionMenuItem.Click += new System.EventHandler(this.tcpShowByDirectionMenuItem_Click);
//
//
// tcpShowByTimeMenuItem
//
//
this.tcpShowByTimeMenuItem.Index = 4;
this.tcpShowByTimeMenuItem.Text = "TCP Show by &Time";
this.tcpShowByTimeMenuItem.Click += new System.EventHandler(this.tcpShowByTimeMenuItem_Click);
//
//
// menuSeparator4
//
//
this.menuSeparator4.Index = 5;
this.menuSeparator4.Text = "-";
//
//
// autoExpandMainMenuItem
//
//
this.autoExpandMainMenuItem.Index = 6;
this.autoExpandMainMenuItem.Text = "Auto E&xpand";
this.autoExpandMainMenuItem.Click += new System.EventHandler(this.autoExpandMenuItem_Click);
//
//
// wordWrapMainMenuItem
//
//
this.wordWrapMainMenuItem.Index = 7;
this.wordWrapMainMenuItem.Text = "Word &Wrap";
this.wordWrapMainMenuItem.Click += new System.EventHandler(this.wordWrapMenuItem_Click);
//
//
// helpMenu
//
//
this.helpMenu.Index = 2;
this.helpMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.aboutMenuItem});
this.helpMenu.Text = "&Help";
//
//
// aboutMenuItem
//
//
this.aboutMenuItem.Index = 0;
this.aboutMenuItem.Text = "&About...";
this.aboutMenuItem.Click += new System.EventHandler(this.aboutMenuItem_Click);
//
//
// panel1
//
//
this.panel1.Controls.Add(this.panel3);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(0, 0);
457,9 → 457,9
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(780, 339);
this.panel1.TabIndex = 11;
//
//
// panel3
//
//
this.panel3.Controls.Add(this.panel4);
this.panel3.Controls.Add(this.splitter1);
this.panel3.Controls.Add(this.messageView);
468,9 → 468,9
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(780, 339);
this.panel3.TabIndex = 5;
//
//
// panel4
//
//
this.panel4.Controls.Add(this.messagesBox);
this.panel4.Controls.Add(this.splitter2);
this.panel4.Controls.Add(this.logBox);
479,9 → 479,9
this.panel4.Name = "panel4";
this.panel4.Size = new System.Drawing.Size(617, 339);
this.panel4.TabIndex = 13;
//
//
// splitter2
//
//
this.splitter2.Dock = System.Windows.Forms.DockStyle.Bottom;
this.splitter2.Location = new System.Drawing.Point(0, 268);
this.splitter2.Name = "splitter2";
488,9 → 488,9
this.splitter2.Size = new System.Drawing.Size(617, 3);
this.splitter2.TabIndex = 9;
this.splitter2.TabStop = false;
//
//
// logBox
//
//
this.logBox.Dock = System.Windows.Forms.DockStyle.Bottom;
this.logBox.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.logBox.HorizontalScrollbar = true;
500,17 → 500,17
this.logBox.ScrollAlwaysVisible = true;
this.logBox.Size = new System.Drawing.Size(617, 68);
this.logBox.TabIndex = 8;
//
//
// splitter1
//
//
this.splitter1.Location = new System.Drawing.Point(160, 0);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(3, 339);
this.splitter1.TabIndex = 12;
this.splitter1.TabStop = false;
//
//
// messageView
//
//
this.messageView.ContextMenu = this.viewContextMenu;
this.messageView.Dock = System.Windows.Forms.DockStyle.Left;
this.messageView.HideSelection = false;
523,27 → 523,27
this.messageView.TabIndex = 11;
this.messageView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.messageView_AfterSelect);
this.messageView.BeforeSelect += new System.Windows.Forms.TreeViewCancelEventHandler(this.messageView_BeforeSelect);
//
//
// saveBinLogDialog
//
//
this.saveBinLogDialog.DefaultExt = "tcp";
this.saveBinLogDialog.Filter = "TCP Logs (*.bin)|*.bin|All Files|*.*";
this.saveBinLogDialog.Title = "Save Binary Log";
//
//
// loadBinLogDialog
//
//
this.loadBinLogDialog.FileName = "openFileDialog1";
this.loadBinLogDialog.Filter = "TCP Logs (*.bin)|*.bin|All Files|*.*";
this.loadBinLogDialog.Title = "Load Binary Log";
//
//
// autoExpandMenuItem
//
//
this.autoExpandMenuItem.Index = 1;
this.autoExpandMenuItem.Text = "Auto E&xpand";
this.autoExpandMenuItem.Click += new System.EventHandler(this.autoExpandMenuItem_Click);
//
//
// messagesBox
//
//
this.messagesBox.ContextMenu = this.messagesContextMenu;
this.messagesBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.messagesBox.Font = new System.Drawing.Font("Courier New", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
552,9 → 552,9
this.messagesBox.Size = new System.Drawing.Size(617, 268);
this.messagesBox.TabIndex = 7;
this.messagesBox.WordWrap = true;
//
//
// MainForm
//
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(780, 361);
this.Controls.Add(this.panel1);
624,6 → 624,8
}
}
base.Dispose( disposing );
 
ThreadDebugger.PrintStatus();
}
 
[STAThread]
916,9 → 918,9
this.ClientSize = new Size(
(int)subkey.GetValue("Window.Width", this.ClientSize.Width),
(int)subkey.GetValue("Window.Hight", this.ClientSize.Height));
this.messageView.Width
this.messageView.Width
= (int)subkey.GetValue("Splitter.Left", this.messageView.Width);
this.logBox.Height
this.logBox.Height
= (int)subkey.GetValue("Splitter.Bottom", this.logBox.Height);
}
}
1053,10 → 1055,10
if(count == 0) {
}
else if(count < 10)
item.Text = string.Format("&{3} {0} to {1}:{2}", recentItem.ListenPort,
item.Text = string.Format("&{3} {0} to {1}:{2}", recentItem.ListenPort,
recentItem.ResendHost, recentItem.ResendPort, count + 1);
else
item.Text = string.Format("{0} to {1}:{2}", recentItem.ListenPort,
item.Text = string.Format("{0} to {1}:{2}", recentItem.ListenPort,
recentItem.ResendHost, recentItem.ResendPort);
count++;
}
1223,7 → 1225,7
StopListening();
ClearAll();
 
FileStream file = new FileStream(fileName, FileMode.Open);
FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
BinaryReader reader = new BinaryReader(file);
 
// header
1374,7 → 1376,7
 
data.Tcp = tcp;
treeNode.Tag = data;
treeNode.ImageIndex = (tcp.LocalState == SocketState.Closed
treeNode.ImageIndex = (tcp.LocalState == SocketState.Closed
&& tcp.RemoteState == SocketState.Closed) ? 2 : 1;
treeNode.SelectedImageIndex = treeNode.ImageIndex;
treeNodes[tcp] = data;
/TCPproxy/trunk/Network.cs
11,6 → 11,7
// FIXME deny write access to all public properties
// FIXME for text/xml get encoding from body if not specified in header
// FIXME option to not store parsed data, just raw packets and reparse on demand
// FIXME implement chunk-encoding
namespace TCPproxy
{
public enum BinLogTypes
157,7 → 158,7
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Bind(new IPEndPoint(IPAddress.Any, listenPort));
socket.Listen(100);
socket.BeginAccept(new AsyncCallback(OnClientConnect), null);
ThreadDebugger.Add(socket.BeginAccept(new AsyncCallback(OnClientConnect), null), "StartListening");
SendLog(null, LogLevel.Important, "Listen on " + socket.LocalEndPoint);
}
 
200,7 → 201,7
try
{
Socket worker = socket.EndAccept(asyn);
socket.BeginAccept(new AsyncCallback(OnClientConnect), null); // wait for next client
ThreadDebugger.Add(socket.BeginAccept(new AsyncCallback(OnClientConnect), null), "OnClientConnect"); // wait for next client
 
TcpConnection tcp = new TcpConnection(string.Format("{0:0000}", tcpId++));
tcp.Close += new TcpEventHandler(TcpConnectionClosed);
754,6 → 755,7
this.localSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, 1);
 
localSendThread = new Thread(new ThreadStart(LocalSendProc));
ThreadDebugger.Add(localSendThread, "LocalSendProc");
localSendThread.Name = "SocketWorker.LocalSendProc";
localSendThread.Start();
 
775,6 → 777,7
tcp.SetRemotePoint((IPEndPoint)remoteSocket.RemoteEndPoint);
 
remoteSendThread = new Thread(new ThreadStart(RemoteSendProc));
ThreadDebugger.Add(remoteSendThread, "RemoteSendProc");
remoteSendThread.Name = "SocketWorker.RemoteSendProc";
remoteSendThread.Start();
 
801,7 → 804,9
try
{
localDataBuffer = new byte[BUF_SIZE];
localSocket.BeginReceive(localDataBuffer, 0, BUF_SIZE, SocketFlags.None, receiveLocalMethod, this);
ThreadDebugger.Add(
localSocket.BeginReceive(localDataBuffer, 0, BUF_SIZE, SocketFlags.None, receiveLocalMethod, this),
"ContinueLocalReceive");
}
catch(ObjectDisposedException ex) // the socket is closed
{
820,7 → 825,9
try
{
remoteDataBuffer = new byte[BUF_SIZE];
remoteSocket.BeginReceive(remoteDataBuffer, 0, BUF_SIZE, SocketFlags.None, receiveRemoteMethod, this);
ThreadDebugger.Add(
remoteSocket.BeginReceive(remoteDataBuffer, 0, BUF_SIZE, SocketFlags.None, receiveRemoteMethod, this),
"ContinueRemoteReceive");
}
catch(ObjectDisposedException ex) // the socket is closed
{
1432,6 → 1439,7
{
HttpParser parser = new HttpParser(messages);
parser.runThread = new Thread(new ThreadStart(parser.Run));
ThreadDebugger.Add(parser.runThread, "HttpParser.Run");
parser.runThread.Name = "HttpParser.Run";
parser.runThread.Start();
 
1467,6 → 1475,7
try
{
responseThread = new Thread(new ThreadStart(MatchResponses));
ThreadDebugger.Add(responseThread, "MatchResponses");
responseThread.Name = "HttpParser.MatchResponses";
responseThread.Start();
 
2451,4 → 2460,61
}
}
 
public class ThreadDebugger
{
private static ArrayList threads = new ArrayList();
private static ArrayList asyncs = new ArrayList();
 
internal static void Add(Thread thread, string comment)
{
threads.Add(new ThreadItem(thread, comment));
Console.WriteLine("ThreadDebugger: thread added {0}", comment);
}
 
internal static void Add(IAsyncResult async, string comment)
{
asyncs.Add(new AsyncItem(async, comment));
Console.WriteLine("ThreadDebugger: async added ", comment);
}
 
public static void PrintStatus()
{
Console.WriteLine("=== ThreadDebugger Status Begin ======");
Console.WriteLine("--- Threads --------------------------");
foreach(ThreadItem t in threads)
{
Console.WriteLine("{0} ({1}): {2}", t.thread.Name, t.comment, t.thread.IsAlive ? "alive" : "dead");
}
Console.WriteLine("--- Asyncs ---------------------------");
foreach(AsyncItem a in asyncs)
{
Console.WriteLine("{0}: {1}", a.comment, a.async.IsCompleted ? "alive" : "dead");
}
Console.WriteLine("=== ThreadDebugger Status End ========");
}
 
private class ThreadItem
{
public Thread thread;
public string comment;
 
public ThreadItem(Thread thread, string comment)
{
this.thread = thread;
this.comment = comment;
}
}
 
private class AsyncItem
{
public IAsyncResult async;
public string comment;
 
public AsyncItem(IAsyncResult async, string comment)
{
this.async = async;
this.comment = comment;
}
}
}
}