11,14 → 11,26 |
// FIXME: |
// - add soap validation |
// - icons for all items in the tree |
// - update text view, not override whole text |
// - use pool of threads? |
// - do not store intermediate info, just row packets and the parsed fragments to display |
// - make the text fragment store switchable |
// - save/restore window layout |
namespace TCPproxy |
{ |
public class MainForm : System.Windows.Forms.Form |
{ |
#region private fields |
|
private TcpListener tcpListener = null; |
private LogMessages logMessages = null; |
private Hashtable treeNodes = new Hashtable(); |
|
private TcpShowMode tcpShowMode = TcpShowMode.ByDirection; |
private bool autoExpand = true; |
|
#endregion private fields |
|
#region web forms fields |
private System.ComponentModel.IContainer components; |
private System.Windows.Forms.Label label2; |
private System.Windows.Forms.Button startButton; |
60,20 → 72,6 |
private System.Windows.Forms.ImageList treeImageList; |
private System.Windows.Forms.MenuItem wordWrapMenuItem; |
private System.Windows.Forms.TextBox resendHostBox; |
#region private fields |
|
private TcpListener tcpListener = null; |
private LogMessages logMessages = null; |
private Hashtable treeNodes = new Hashtable(); |
|
private TcpShowMode tcpShowMode = TcpShowMode.ByDirection; |
private bool autoExpand = true; |
|
#endregion private fields |
|
#region web forms fields |
|
|
#endregion web forms fields |
|
#region Windows Form Designer generated code |
521,7 → 519,7 |
private void LoadFromRegistry() |
{ |
Microsoft.Win32.RegistryKey subkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey( |
@"Software\Echelon\TCPproxy"); |
@"Software\Anatoli Klassen\TCPproxy"); |
|
if(subkey != null) |
{ |
535,6 → 533,11 |
object tcpShowModeStr = (object)subkey.GetValue("Tcp Show Mode", TcpShowMode.ByDirection); |
tcpShowMode = (tcpShowModeStr as string) == "ByDirection" |
? TcpShowMode.ByDirection : TcpShowMode.ByTime; |
|
// this.Top = (int)subkey.GetValue("Window.Top", this.Top); |
// this.Left = (int)subkey.GetValue("Window.Left", this.Left); |
// this.Hight = (int)subkey.GetValue("Window.Hight", this.Hight); |
// this.Width = (int)subkey.GetValue("Window.Width", this.Width); |
} |
} |
|
541,7 → 544,7 |
private void SaveToRegistry() |
{ |
Microsoft.Win32.RegistryKey subkey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey( |
@"Software\Echelon\TCPproxy"); |
@"Software\Anatoli Klassen\TCPproxy"); |
|
subkey.SetValue("Listen Port", listenPortBox.Text); |
subkey.SetValue("Resend Host", resendHostBox.Text); |
550,6 → 553,11 |
subkey.SetValue("Tcp Show Mode", tcpShowMode); |
subkey.SetValue("Auto Expand", autoExpand ? 1 : 0); |
subkey.SetValue("Word Wrap", messagesBox.WordWrap ? 1 : 0); |
|
subkey.SetValue("Window.Top", this.Top); |
subkey.SetValue("Window.Left", this.Left); |
subkey.SetValue("Window.Hight", this.Height); |
subkey.SetValue("Window.Width", this.Width); |
} |
|
private void startButton_Click(object sender, System.EventArgs e) |
650,6 → 658,11 |
|
private void clearButton_Click(object sender, System.EventArgs e) |
{ |
// close all connetions |
foreach(object tcp in treeNodes.Keys) |
if(tcp is TcpConnection) |
((TcpConnection)tcp).Cancel(); |
|
treeNodes.Clear(); |
messageView.Nodes.Clear(); |
messagesBox.Clear(); |
891,78 → 904,93 |
#region network events handlers |
private void TcpConnectionLog(object sender, TcpLogEventArgs e) |
{ |
TcpConnection tcp = sender as TcpConnection; |
LogMessage message = new LogMessage(tcp, e.Level, e.Message, e.Exception); |
lock(this) |
{ |
TcpConnection tcp = sender as TcpConnection; |
LogMessage message = new LogMessage(tcp, e.Level, e.Message, e.Exception); |
|
try |
{ |
this.BeginInvoke(new AddLogMessageHandler(AddLogMessageInternal), new object[] { message } ); |
try |
{ |
this.BeginInvoke(new AddLogMessageHandler(AddLogMessageInternal), new object[] { message } ); |
} |
catch(InvalidOperationException ex) |
{ |
if(!this.Disposing && !this.IsDisposed) |
Console.WriteLine(ex.Message + " (" + ex.GetType().Name + ")\n" + ex.StackTrace); |
} |
} |
catch(InvalidOperationException ex) |
{ |
if(!this.Disposing && !this.IsDisposed) |
Console.WriteLine(ex.Message + " (" + ex.GetType().Name + ")\n" + ex.StackTrace); |
} |
} |
|
private void AddTcpConnetion(object sender, TcpConnectionEventArgs e) |
{ |
e.Tcp.Log += new TcpLogEventHandler(TcpConnectionLog); |
e.Tcp.Update += new TcpEventHandler(UpdateTcpNode); |
e.Tcp.Close += new TcpEventHandler(UpdateTcpNode); |
e.Tcp.NewHttp += new TcpHttpEventHandler(AddHttpMessageNode); |
lock(this) |
{ |
e.Tcp.Log += new TcpLogEventHandler(TcpConnectionLog); |
e.Tcp.Update += new TcpEventHandler(UpdateTcpNode); |
e.Tcp.Close += new TcpEventHandler(UpdateTcpNode); |
e.Tcp.NewHttp += new TcpHttpEventHandler(AddHttpMessageNode); |
|
try |
{ |
this.BeginInvoke(new AddTcpNodeHandler(AddTcpNodeInternal), new object[] { e.Tcp } ); |
try |
{ |
this.BeginInvoke(new AddTcpNodeHandler(AddTcpNodeInternal), new object[] { e.Tcp } ); |
} |
catch(InvalidOperationException ex) |
{ |
if(!this.Disposing && !this.IsDisposed) |
Console.WriteLine(ex.Message + " (" + ex.GetType().Name + ")\n" + ex.StackTrace); |
} |
} |
catch(InvalidOperationException ex) |
{ |
if(!this.Disposing && !this.IsDisposed) |
Console.WriteLine(ex.Message + " (" + ex.GetType().Name + ")\n" + ex.StackTrace); |
} |
} |
|
private void UpdateTcpNode(object sender, TcpEventArgs e) |
{ |
try |
lock(this) |
{ |
this.BeginInvoke(new UpdateTcpNodeHandler(UpdateTcpNodeInternal), new object[] { (TcpConnection)sender } ); |
try |
{ |
this.BeginInvoke(new UpdateTcpNodeHandler(UpdateTcpNodeInternal), new object[] { (TcpConnection)sender } ); |
} |
catch(InvalidOperationException ex) |
{ |
if(!this.Disposing && !this.IsDisposed) |
Console.WriteLine(ex.Message + " (" + ex.GetType().Name + ")\n" + ex.StackTrace); |
} |
} |
catch(InvalidOperationException ex) |
{ |
if(!this.Disposing && !this.IsDisposed) |
Console.WriteLine(ex.Message + " (" + ex.GetType().Name + ")\n" + ex.StackTrace); |
} |
} |
|
private void AddHttpMessageNode(object sender, TcpHttpEventArgs e) |
{ |
e.Http.Update += new TcpEventHandler(UpdateHttpNode); |
lock(this) |
{ |
e.Http.Update += new TcpEventHandler(UpdateHttpNode); |
|
try |
{ |
this.BeginInvoke(new AddHttpNodeHandler(AddHttpNodeInternal), |
new object[] { (TcpConnection)sender, e.Http } ); |
try |
{ |
this.BeginInvoke(new AddHttpNodeHandler(AddHttpNodeInternal), |
new object[] { (TcpConnection)sender, e.Http } ); |
} |
catch(InvalidOperationException ex) |
{ |
if(!this.Disposing && !this.IsDisposed) |
Console.WriteLine(ex.Message + " (" + ex.GetType().Name + ")\n" + ex.StackTrace); |
} |
} |
catch(InvalidOperationException ex) |
{ |
if(!this.Disposing && !this.IsDisposed) |
Console.WriteLine(ex.Message + " (" + ex.GetType().Name + ")\n" + ex.StackTrace); |
} |
} |
|
private void UpdateHttpNode(object sender, TcpEventArgs e) |
{ |
try |
lock(this) |
{ |
this.BeginInvoke(new UpdateHttpNodeHandler(UpdateHttpNodeInternal), new object[] { (HttpMessage)sender } ); |
try |
{ |
this.BeginInvoke(new UpdateHttpNodeHandler(UpdateHttpNodeInternal), new object[] { (HttpMessage)sender } ); |
} |
catch(InvalidOperationException ex) |
{ |
if(!this.Disposing && !this.IsDisposed) |
Console.WriteLine(ex.Message + " (" + ex.GetType().Name + ")\n" + ex.StackTrace); |
} |
} |
catch(InvalidOperationException ex) |
{ |
if(!this.Disposing && !this.IsDisposed) |
Console.WriteLine(ex.Message + " (" + ex.GetType().Name + ")\n" + ex.StackTrace); |
} |
} |
|
#endregion network events handlers |
1003,7 → 1031,7 |
private void UpdateTcpNodeInternal(TcpConnection tcp) |
{ |
TcpNodeData data = treeNodes[tcp] as TcpNodeData; |
if(data == null) throw new ArgumentException("Unknown TCP node"); |
if(data == null) return; // might be call by Cancel |
|
string title = tcp.ToString(); |
if(title != data.Node.Text) data.Node.Text = title; |
1039,7 → 1067,7 |
private void UpdateHttpNodeInternal(HttpMessage http) |
{ |
HttpNodeData httpData = treeNodes[http] as HttpNodeData; |
if(httpData == null) throw new ArgumentException("No node found for HTTP message"); |
if(httpData == null) return; // might be call by Cancel |
|
string title = http.ToString(); |
if(httpData.Node.Text != title) httpData.Node.Text = title; |
1378,6 → 1406,7 |
private bool responseXmlShown = false; |
|
private object stateMarker = null; |
private object requestStartMarker = null; |
private object requestMethodMarker = null; |
private object requestUriMarker = null; |
private object requestVersionMarker = null; |
1386,6 → 1415,7 |
private object requestContentTypeMarker = null; |
private object requestCharsetMarker = null; |
private object requestHeadersMarker = null; |
private object responseStartMarker = null; |
private object responseVersionMarker = null; |
private object responseStatusMarker = null; |
private object responseLengthMarker = null; |
1451,6 → 1481,15 |
owner.messagesBox.AppendNewLine(); |
|
// request info |
owner.messagesBox.AppendText("Request Start: ", |
Color.DarkRed, Color.Transparent, false, false, 0, 0); |
requestStartMarker = owner.messagesBox.BeginMark(); |
owner.messagesBox.AppendText(http.RequestStartTimestamp == DateTime.MinValue |
? "<unknown>" : http.RequestStartTimestamp.ToString("HH:mm:ss.ffff"), |
Color.DarkRed, Color.LightGray, false, false, 0, 27); |
owner.messagesBox.EndMark(requestStartMarker); |
owner.messagesBox.AppendNewLine(); |
|
owner.messagesBox.AppendText("Request Method: ", |
Color.DarkRed, Color.Transparent, false, false, 0, 0); |
requestMethodMarker = owner.messagesBox.BeginMark(); |
1520,6 → 1559,15 |
|
// response info |
owner.messagesBox.AppendNewLine(); |
owner.messagesBox.AppendText("Response Start: ", |
Color.DarkRed, Color.Transparent, false, false, 0, 0); |
responseStartMarker = owner.messagesBox.BeginMark(); |
owner.messagesBox.AppendText(http.ResponseStartTimestamp == DateTime.MinValue |
? "<unknown>" : http.ResponseStartTimestamp.ToString("HH:mm:ss.ffff"), |
Color.DarkRed, Color.LightGray, false, false, 0, 27); |
owner.messagesBox.EndMark(responseStartMarker); |
owner.messagesBox.AppendNewLine(); |
|
owner.messagesBox.AppendText("Response Version: ", |
Color.DarkRed, Color.Transparent, false, false, 0, 0); |
responseVersionMarker = owner.messagesBox.BeginMark(); |