2009-04-20 06:57:07 +00:00
/ *
* Copyright ( c ) 2009 , openmetaverse . org
* All rights reserved .
*
* - Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions are met :
*
* - Redistributions of source code must retain the above copyright notice , this
* list of conditions and the following disclaimer .
* - Neither the name of the openmetaverse . org nor the names
* of its contributors may be used to endorse or promote products derived from
* this software without specific prior written permission .
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR
* CONSEQUENTIAL DAMAGES ( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS
* INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY , WHETHER IN
* CONTRACT , STRICT LIABILITY , OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE )
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE , EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE .
* /
using System ;
using System.IO ;
2009-04-16 05:14:07 +00:00
using System.Net ;
using System.Collections ;
using System.Collections.Generic ;
using System.ComponentModel ;
2009-04-26 09:38:34 +00:00
2009-04-16 05:14:07 +00:00
using System.Drawing ;
using System.Text ;
using System.Windows.Forms ;
using System.Reflection ;
using System.Threading ;
using GridProxy ;
using OpenMetaverse ;
using OpenMetaverse.Packets ;
using OpenMetaverse.StructuredData ;
using OpenMetaverse.Interfaces ;
using System.Xml ;
2009-04-20 06:57:07 +00:00
using Nwc.XmlRpc ;
2009-04-16 05:14:07 +00:00
namespace WinGridProxy
{
2009-04-23 10:02:39 +00:00
public partial class FormWinGridProxy : Form
2009-04-16 05:14:07 +00:00
{
2009-04-17 10:02:16 +00:00
private static SettingsStore Store = new SettingsStore ( ) ;
2009-04-26 09:38:34 +00:00
private static bool IsProxyRunning ;
2009-04-16 05:14:07 +00:00
2009-04-26 09:38:34 +00:00
private bool AutoScrollSessions ;
2009-04-20 06:57:07 +00:00
2009-04-16 05:14:07 +00:00
ProxyManager proxy ;
2009-04-23 10:02:39 +00:00
2009-04-16 05:14:07 +00:00
2009-04-26 09:38:34 +00:00
private int PacketCounter ;
2009-04-23 10:02:39 +00:00
2009-04-26 09:38:34 +00:00
private int CapsInCounter ;
private int CapsInBytes ;
private int CapsOutCounter ;
private int CapsOutBytes ;
2009-04-17 00:48:52 +00:00
2009-04-26 09:38:34 +00:00
private int PacketsInCounter ;
2009-04-17 00:48:52 +00:00
private int PacketsInBytes ;
2009-04-26 09:38:34 +00:00
private int PacketsOutCounter ;
2009-04-17 00:48:52 +00:00
private int PacketsOutBytes ;
2009-04-16 05:14:07 +00:00
2009-04-23 10:02:39 +00:00
public FormWinGridProxy ( )
2009-04-16 05:14:07 +00:00
{
InitializeComponent ( ) ;
2009-04-26 09:38:34 +00:00
// populate the listen box with IPs
IPHostEntry iphostentry = Dns . GetHostByName ( Dns . GetHostName ( ) ) ;
2009-05-08 07:32:49 +00:00
foreach ( IPAddress address in iphostentry . AddressList )
2009-04-26 09:38:34 +00:00
comboBoxListenAddress . Items . Add ( address . ToString ( ) ) ;
ProxyManager . OnPacketLog + = ProxyManager_OnPacketLog ;
ProxyManager . OnMessageLog + = ProxyManager_OnMessageLog ;
ProxyManager . OnLoginResponse + = ProxyManager_OnLoginResponse ;
ProxyManager . OnCapabilityAdded + = ProxyManager_OnCapabilityAdded ;
ProxyManager . OnEventMessageLog + = ProxyManager_OnEventMessageLog ;
2009-04-16 05:14:07 +00:00
}
2009-04-22 00:01:30 +00:00
#region Event Handlers for Messages / Packets
2009-04-23 10:02:39 +00:00
public ListViewItem FindListViewItem ( ListView listView , string key , bool searchAll )
{
foreach ( ListViewItem item in listView . Items )
{
if ( item . Text . Equals ( key )
| | ( searchAll & & item . SubItems . ContainsKey ( key ) ) )
return item ;
}
return null ;
}
2009-04-22 00:01:30 +00:00
/// <summary>
/// Adds a new EventQueue message to the Message Filters listview.
/// </summary>
/// <param name="req"></param>
/// <param name="stage"></param>
void ProxyManager_OnEventMessageLog ( CapsRequest req , CapsStage stage )
{
if ( this . InvokeRequired )
{
this . BeginInvoke ( new MethodInvoker ( delegate ( )
{
ProxyManager_OnEventMessageLog ( req , stage ) ;
} ) ) ;
}
else
{
2009-04-23 10:02:39 +00:00
ListViewItem foundCap = FindListViewItem ( listViewMessageFilters , req . Info . CapType , false ) ;
2009-05-08 07:32:49 +00:00
2009-04-22 00:01:30 +00:00
if ( foundCap = = null )
{
ListViewItem addedItem = listViewMessageFilters . Items . Add ( new ListViewItem ( req . Info . CapType , new ListViewGroup ( "EventQueue Messages" ) ) ) ;
addedItem . SubItems . Add ( "EventMessage" ) ;
addedItem . BackColor = Color . AliceBlue ;
if ( autoAddNewDiscoveredMessagesToolStripMenuItem . Checked )
addedItem . Checked = true ;
}
else
{
ProxyManager_OnMessageLog ( req , CapsStage . Response ) ;
}
}
}
/// <summary>
/// Adds a new Capability message to the message filters listview
/// </summary>
/// <param name="cap"></param>
2009-04-20 06:57:07 +00:00
void ProxyManager_OnCapabilityAdded ( CapInfo cap )
2009-04-16 05:14:07 +00:00
{
2009-04-20 06:57:07 +00:00
if ( this . InvokeRequired )
2009-04-16 05:14:07 +00:00
{
2009-04-20 06:57:07 +00:00
this . BeginInvoke ( new MethodInvoker ( delegate ( )
2009-04-16 05:14:07 +00:00
{
2009-04-20 06:57:07 +00:00
ProxyManager_OnCapabilityAdded ( cap ) ;
} ) ) ;
2009-04-16 05:14:07 +00:00
}
2009-04-20 06:57:07 +00:00
else
2009-04-17 10:02:16 +00:00
{
2009-04-20 06:57:07 +00:00
ListViewItem foundCap = listViewMessageFilters . FindItemWithText ( cap . CapType ) ;
if ( foundCap = = null )
{
2009-04-22 00:01:30 +00:00
ListViewItem addedItem = listViewMessageFilters . Items . Add ( new ListViewItem ( cap . CapType , new ListViewGroup ( "Capabilities Messages" ) ) ) ;
addedItem . SubItems . Add ( "CapMessage" ) ;
addedItem . BackColor = Color . Honeydew ;
2009-04-20 06:57:07 +00:00
if ( autoAddNewDiscoveredMessagesToolStripMenuItem . Checked )
addedItem . Checked = true ;
}
2009-04-17 10:02:16 +00:00
}
2009-04-16 05:14:07 +00:00
}
void ProxyManager_OnPacketLog ( Packet packet , Direction direction , IPEndPoint endpoint )
{
PacketAnalyzer_OnPacketLog ( packet , direction , endpoint ) ;
}
void ProxyManager_OnLoginResponse ( object request , Direction direction )
{
if ( this . InvokeRequired )
{
this . BeginInvoke ( new MethodInvoker ( delegate ( )
{
ProxyManager_OnLoginResponse ( request , direction ) ;
} ) ) ;
}
else
{
PacketCounter + + ;
2009-04-16 08:19:45 +00:00
2009-04-23 10:02:39 +00:00
string loginType = ( request is XmlRpcRequest ) ? "Login Request" : "Login Response" ;
2009-05-08 07:32:49 +00:00
ListViewItem session = new ListViewItem ( new string [ ] { PacketCounter . ToString ( ) , "HTTPS" , loginType , request . ToString ( ) . Length . ToString ( ) , comboBoxLoginURL . Text , "xml-rpc" } ) ;
2009-04-16 05:14:07 +00:00
session . Tag = request ;
2009-04-17 00:48:52 +00:00
session . ImageIndex = ( request is XmlRpcRequest ) ? 1 : 0 ;
2009-04-25 06:40:43 +00:00
2009-04-16 05:14:07 +00:00
listViewSessions . Items . Add ( session ) ;
}
}
void PacketAnalyzer_OnPacketLog ( Packet packet , Direction direction , IPEndPoint endpoint )
{
if ( this . InvokeRequired )
{
this . BeginInvoke ( new MethodInvoker ( delegate ( )
{
PacketAnalyzer_OnPacketLog ( packet , direction , endpoint ) ;
} ) ) ;
}
else
{
PacketCounter + + ;
2009-04-17 00:48:52 +00:00
if ( direction = = Direction . Incoming )
{
PacketsInCounter + + ;
PacketsInBytes + = packet . Length ;
}
else
{
PacketsOutCounter + + ;
PacketsOutBytes + = packet . Length ;
}
2009-05-08 07:32:49 +00:00
ListViewItem session = new ListViewItem ( new string [ ] { PacketCounter . ToString ( ) , "UDP" , packet . Type . ToString ( ) , packet . Length . ToString ( ) , endpoint . ToString ( ) , "binary udp" } ) ;
2009-04-23 10:02:39 +00:00
session . Tag = packet ;
session . ImageIndex = ( direction = = Direction . Incoming ) ? 0 : 1 ;
2009-04-16 05:14:07 +00:00
listViewSessions . Items . Add ( session ) ;
2009-04-20 06:57:07 +00:00
2009-04-23 10:02:39 +00:00
if ( listViewSessions . Items . Count > 0 & & AutoScrollSessions )
2009-04-20 06:57:07 +00:00
listViewSessions . EnsureVisible ( listViewSessions . Items . Count - 1 ) ;
2009-04-16 05:14:07 +00:00
}
}
void ProxyManager_OnMessageLog ( CapsRequest req , CapsStage stage )
{
if ( this . InvokeRequired )
{
this . BeginInvoke ( new MethodInvoker ( delegate ( )
{
ProxyManager_OnMessageLog ( req , stage ) ;
} ) ) ;
}
else
{
2009-04-23 10:02:39 +00:00
ListViewItem found = FindListViewItem ( listViewMessageFilters , req . Info . CapType , false ) ;
2009-04-16 05:14:07 +00:00
2009-04-20 06:57:07 +00:00
if ( found ! = null & & found . Checked )
2009-04-17 00:48:52 +00:00
{
2009-04-20 06:57:07 +00:00
PacketCounter + + ;
2009-04-23 10:02:39 +00:00
int size = 0 ;
string cType = String . Empty ;
2009-05-08 07:32:49 +00:00
if ( req . RawRequest ! = null )
2009-04-23 10:02:39 +00:00
{
size + = req . RawRequest . Length ;
cType = req . RequestHeaders . Get ( "Content-Type" ) ; //req.RequestHeaders["Content-Type"];
}
if ( req . RawResponse ! = null )
{
size + = req . RawResponse . Length ;
cType = req . ResponseHeaders . Get ( "Content-Type" ) ;
}
string [ ] s = { PacketCounter . ToString ( ) , found . SubItems [ 1 ] . Text , req . Info . CapType , size . ToString ( ) , req . Info . URI , cType } ;
2009-04-20 06:57:07 +00:00
ListViewItem session = new ListViewItem ( s ) ;
2009-04-22 00:01:30 +00:00
session . BackColor = found . BackColor ;
2009-04-20 06:57:07 +00:00
session . Tag = req ;
if ( stage = = CapsStage . Request )
{
CapsOutCounter + + ;
CapsOutBytes + = req . Request . ToString ( ) . Length ;
session . ImageIndex = 1 ;
}
else
{
CapsInCounter + + ;
CapsInBytes + = req . Response . ToString ( ) . Length ;
session . ImageIndex = 0 ;
}
listViewSessions . Items . Add ( session ) ;
2009-04-17 00:48:52 +00:00
}
else
{
2009-04-20 06:57:07 +00:00
if ( found = = null )
{
// must be a new event not in KnownCaps, lets add it to the listview
ListViewItem addedItem = listViewMessageFilters . Items . Add ( new ListViewItem ( req . Info . CapType ) ) ;
addedItem . BackColor = Color . AliceBlue ;
2009-04-17 00:48:52 +00:00
2009-04-20 06:57:07 +00:00
if ( autoAddNewDiscoveredMessagesToolStripMenuItem . Checked )
addedItem . Checked = true ;
}
}
2009-04-23 10:02:39 +00:00
if ( listViewSessions . Items . Count > 0 & & AutoScrollSessions )
listViewSessions . EnsureVisible ( listViewSessions . Items . Count - 1 ) ;
2009-04-16 05:14:07 +00:00
}
}
2009-04-20 06:57:07 +00:00
#endregion
#region GUI Event Handlers
private void buttonStartProxy_Click ( object sender , EventArgs e )
2009-04-16 05:14:07 +00:00
{
2009-04-23 10:02:39 +00:00
2009-04-16 05:14:07 +00:00
if ( button1 . Text . StartsWith ( "Start" ) & & IsProxyRunning . Equals ( false ) )
{
2009-04-26 09:38:34 +00:00
proxy = new ProxyManager ( textBoxProxyPort . Text , comboBoxListenAddress . Text , comboBoxLoginURL . Text ) ;
2009-04-23 10:02:39 +00:00
// disable any gui elements
2009-04-26 09:38:34 +00:00
comboBoxListenAddress . Enabled = textBoxProxyPort . Enabled = comboBoxLoginURL . Enabled = false ;
2009-04-17 10:02:16 +00:00
InitProxyFilters ( ) ;
2009-04-16 05:14:07 +00:00
proxy . Start ( ) ;
2009-04-23 10:02:39 +00:00
// enable any gui elements
toolStripDropDownButton5 . Enabled =
2009-05-07 20:55:03 +00:00
toolStripMenuItemPlugins . Enabled = grpUDPFilters . Enabled = grpCapsFilters . Enabled = IsProxyRunning = true ;
2009-04-16 05:14:07 +00:00
button1 . Text = "Stop Proxy" ;
2009-04-16 16:25:47 +00:00
2009-04-20 06:57:07 +00:00
if ( enableStatisticsToolStripMenuItem . Checked & & ! timer1 . Enabled )
2009-04-17 00:48:52 +00:00
timer1 . Enabled = true ;
2009-04-16 05:14:07 +00:00
}
else if ( button1 . Text . StartsWith ( "Stop" ) & & IsProxyRunning . Equals ( true ) )
{
// stop the proxy
proxy . Stop ( ) ;
2009-05-07 20:55:03 +00:00
toolStripMenuItemPlugins . Enabled = grpUDPFilters . Enabled = grpCapsFilters . Enabled = IsProxyRunning = false ;
2009-04-16 05:14:07 +00:00
button1 . Text = "Start Proxy" ;
2009-04-26 09:38:34 +00:00
comboBoxListenAddress . Enabled = textBoxProxyPort . Enabled = comboBoxLoginURL . Enabled = true ;
2009-04-16 16:25:47 +00:00
2009-04-20 06:57:07 +00:00
if ( ! enableStatisticsToolStripMenuItem . Checked & & timer1 . Enabled )
2009-04-17 00:48:52 +00:00
timer1 . Enabled = false ;
2009-04-16 05:14:07 +00:00
}
}
2009-04-20 06:57:07 +00:00
private void checkBoxCheckAllPackets_CheckedChanged ( object sender , EventArgs e )
2009-04-16 05:14:07 +00:00
{
2009-04-20 06:57:07 +00:00
foreach ( ListViewItem item in listViewPacketFilters . Items )
2009-04-16 05:14:07 +00:00
{
2009-04-20 06:57:07 +00:00
item . Checked = checkBoxCheckAllPackets . Checked ;
2009-04-16 05:14:07 +00:00
}
}
private void listViewSessions_ItemSelectionChanged ( object sender , ListViewItemSelectionChangedEventArgs e )
{
2009-04-23 10:02:39 +00:00
2009-04-20 06:57:07 +00:00
if ( e . IsSelected & & listViewSessions . SelectedItems . Count = = 1 )
2009-04-16 05:14:07 +00:00
{
2009-04-23 10:02:39 +00:00
// update the context menus
contextMenuStripSessions_Opening ( sender , null ) ;
2009-04-16 08:19:45 +00:00
tabControl1 . SelectTab ( "tabPageInspect" ) ;
2009-04-17 00:48:52 +00:00
object tag = e . Item . Tag ;
2009-04-20 06:57:07 +00:00
2009-04-17 00:48:52 +00:00
if ( tag is XmlRpcRequest )
2009-04-16 05:14:07 +00:00
{
2009-04-17 00:48:52 +00:00
XmlRpcRequest requestData = ( XmlRpcRequest ) tag ;
2009-04-22 00:01:30 +00:00
richTextBoxDecodedRequest . Text = requestData . ToString ( ) ;
richTextBoxRawRequest . Text = requestData . ToString ( ) ;
richTextBoxNotationRequest . Text = "Notation Not Available for XML Request" ;
updateTreeView ( requestData . ToString ( ) , treeViewXMLRequest ) ;
2009-04-17 00:48:52 +00:00
Be . Windows . Forms . DynamicByteProvider data = new Be . Windows . Forms . DynamicByteProvider ( Utils . StringToBytes ( requestData . ToString ( ) ) ) ;
2009-04-17 10:02:16 +00:00
hexBoxRequest . ByteProvider = data ;
2009-04-22 00:01:30 +00:00
richTextBoxDecodedResponse . Text = String . Empty ;
richTextBoxRawResponse . Text = String . Empty ;
richTextBoxNotationResponse . Text = String . Empty ;
treeViewXmlResponse . Nodes . Clear ( ) ;
2009-04-17 10:02:16 +00:00
hexBoxResponse . ByteProvider = null ;
2009-04-16 05:14:07 +00:00
}
2009-04-17 00:48:52 +00:00
else if ( tag is XmlRpcResponse )
2009-04-16 05:14:07 +00:00
{
2009-04-17 00:48:52 +00:00
XmlRpcResponse responseData = ( XmlRpcResponse ) tag ;
2009-04-23 10:02:39 +00:00
richTextBoxDecodedResponse . Text = responseData . ToString ( ) ;
2009-04-22 00:01:30 +00:00
richTextBoxRawResponse . Text = responseData . ToString ( ) ;
richTextBoxNotationResponse . Text = "Notation Not Available for XML Request" ;
updateTreeView ( responseData . ToString ( ) , treeViewXmlResponse ) ;
2009-04-17 00:48:52 +00:00
Be . Windows . Forms . DynamicByteProvider data = new Be . Windows . Forms . DynamicByteProvider ( Utils . StringToBytes ( responseData . ToString ( ) ) ) ;
2009-04-17 10:02:16 +00:00
hexBoxResponse . ByteProvider = data ;
2009-04-22 00:01:30 +00:00
richTextBoxDecodedRequest . Text = String . Empty ;
richTextBoxRawRequest . Text = String . Empty ;
richTextBoxNotationRequest . Text = String . Empty ;
treeViewXMLRequest . Nodes . Clear ( ) ;
2009-04-17 10:02:16 +00:00
hexBoxRequest . ByteProvider = null ;
2009-04-23 10:02:39 +00:00
2009-04-16 05:14:07 +00:00
}
2009-04-17 00:48:52 +00:00
else if ( tag is Packet )
2009-04-16 05:14:07 +00:00
{
2009-04-17 00:48:52 +00:00
Packet packet = ( Packet ) tag ;
2009-04-20 06:57:07 +00:00
2009-04-17 00:48:52 +00:00
Be . Windows . Forms . DynamicByteProvider data = new Be . Windows . Forms . DynamicByteProvider ( packet . ToBytes ( ) ) ;
2009-04-22 00:01:30 +00:00
// we have no conversion from Packet to xml or notation
richTextBoxNotationRequest . Text = String . Empty ;
richTextBoxNotationResponse . Text = String . Empty ;
treeViewXmlResponse . Nodes . Clear ( ) ;
treeViewXMLRequest . Nodes . Clear ( ) ;
2009-04-18 04:21:51 +00:00
2009-04-20 06:57:07 +00:00
// 0 = incoming, 1 = outgoing
2009-04-23 10:02:39 +00:00
if ( e . Item . ImageIndex = = 0 )
2009-04-20 06:57:07 +00:00
{
2009-04-22 00:01:30 +00:00
richTextBoxDecodedResponse . Text = TagToString ( tag , listViewSessions . FocusedItem . SubItems [ 2 ] . Text ) ;
richTextBoxRawResponse . Text = TagToString ( tag , listViewSessions . FocusedItem . SubItems [ 2 ] . Text ) ;
richTextBoxNotationResponse . Text = "Notation Not Available for Packet Types" ;
2009-04-20 06:57:07 +00:00
hexBoxResponse . ByteProvider = data ;
2009-04-22 00:01:30 +00:00
richTextBoxDecodedRequest . Text = String . Empty ;
richTextBoxRawRequest . Text = String . Empty ;
hexBoxRequest . ByteProvider = null ;
2009-05-08 07:32:49 +00:00
}
else
2009-04-23 10:02:39 +00:00
{
richTextBoxDecodedRequest . Text = TagToString ( tag , listViewSessions . FocusedItem . SubItems [ 2 ] . Text ) ;
richTextBoxRawRequest . Text = TagToString ( tag , listViewSessions . FocusedItem . SubItems [ 2 ] . Text ) ;
richTextBoxNotationRequest . Text = "Notation Not Available for Packet Types" ;
hexBoxRequest . ByteProvider = data ;
richTextBoxDecodedResponse . Text = String . Empty ;
richTextBoxRawResponse . Text = String . Empty ;
hexBoxResponse . ByteProvider = null ;
2009-04-20 06:57:07 +00:00
}
2009-05-08 07:32:49 +00:00
2009-04-16 05:14:07 +00:00
}
2009-04-17 00:48:52 +00:00
else if ( tag is CapsRequest )
2009-04-16 05:14:07 +00:00
{
2009-04-17 00:48:52 +00:00
CapsRequest capsData = ( CapsRequest ) tag ;
2009-04-17 10:02:16 +00:00
if ( capsData . Request ! = null )
2009-04-17 00:48:52 +00:00
{
2009-04-22 00:01:30 +00:00
StringBuilder rawRequest = new StringBuilder ( ) ;
2009-04-23 10:02:39 +00:00
if ( capsData . RequestHeaders ! = null )
2009-04-22 00:01:30 +00:00
{
2009-04-23 10:02:39 +00:00
foreach ( string key in capsData . RequestHeaders . Keys )
{
rawRequest . AppendFormat ( "{0}: {1}" + System . Environment . NewLine , key , capsData . RequestHeaders [ key ] ) ;
}
rawRequest . AppendLine ( ) ;
2009-04-22 00:01:30 +00:00
}
rawRequest . AppendLine ( Utils . BytesToString ( capsData . RawRequest ) ) ;
OSD requestOSD = OSDParser . DeserializeLLSDXml ( capsData . RawRequest ) ;
richTextBoxDecodedRequest . Text = TagToString ( requestOSD , listViewSessions . FocusedItem . SubItems [ 2 ] . Text ) ; //.ToString();
richTextBoxRawRequest . Text = rawRequest . ToString ( ) ;
richTextBoxNotationRequest . Text = requestOSD . ToString ( ) ;
updateTreeView ( Utils . BytesToString ( capsData . RawRequest ) , treeViewXMLRequest ) ;
Be . Windows . Forms . DynamicByteProvider data = new Be . Windows . Forms . DynamicByteProvider ( capsData . RawRequest ) ;
2009-04-17 10:02:16 +00:00
hexBoxRequest . ByteProvider = data ;
}
2009-04-16 05:14:07 +00:00
else
2009-04-16 08:19:45 +00:00
{
2009-04-22 00:01:30 +00:00
richTextBoxDecodedRequest . Text = "No Data" ;
richTextBoxRawRequest . Text = "No Data" ;
richTextBoxNotationRequest . Text = "No Data" ;
treeViewXMLRequest . Nodes . Clear ( ) ;
2009-04-17 10:02:16 +00:00
hexBoxRequest . ByteProvider = null ;
2009-04-22 00:01:30 +00:00
2009-04-17 10:02:16 +00:00
}
if ( capsData . Response ! = null )
{
2009-04-22 00:01:30 +00:00
StringBuilder rawResponse = new StringBuilder ( ) ;
if ( capsData . ResponseHeaders ! = null )
{
foreach ( string key in capsData . ResponseHeaders . Keys )
{
rawResponse . AppendFormat ( "{0}: {1}" + System . Environment . NewLine , key , capsData . ResponseHeaders [ key ] ) ;
}
rawResponse . AppendLine ( ) ;
}
rawResponse . AppendLine ( Utils . BytesToString ( capsData . RawResponse ) ) ;
OSD responseOSD = OSDParser . DeserializeLLSDXml ( capsData . RawResponse ) ;
richTextBoxDecodedResponse . Text = TagToString ( responseOSD , listViewSessions . FocusedItem . SubItems [ 2 ] . Text ) ; //.ToString();
richTextBoxRawResponse . Text = rawResponse . ToString ( ) ;
richTextBoxNotationResponse . Text = responseOSD . ToString ( ) ;
updateTreeView ( Utils . BytesToString ( capsData . RawResponse ) , treeViewXmlResponse ) ;
Be . Windows . Forms . DynamicByteProvider data = new Be . Windows . Forms . DynamicByteProvider ( capsData . RawResponse ) ;
2009-04-17 10:02:16 +00:00
hexBoxResponse . ByteProvider = data ;
2009-04-20 06:57:07 +00:00
}
else
{
2009-04-22 00:01:30 +00:00
richTextBoxDecodedResponse . Text = "No Data" ;
richTextBoxRawResponse . Text = "No Data" ;
richTextBoxNotationResponse . Text = "No Data" ;
treeViewXmlResponse . Nodes . Clear ( ) ;
2009-04-17 10:02:16 +00:00
hexBoxResponse . ByteProvider = null ;
2009-04-16 08:19:45 +00:00
}
2009-04-16 05:14:07 +00:00
}
}
}
2009-04-20 06:57:07 +00:00
private void Form1_FormClosing ( object sender , FormClosingEventArgs e )
{
if ( IsProxyRunning )
proxy . Stop ( ) ;
2009-04-18 04:21:51 +00:00
2009-04-23 10:02:39 +00:00
if ( saveOptionsOnExitToolStripMenuItem . Checked )
2009-04-20 06:57:07 +00:00
SaveAllSettings ( "settings.osd" ) ;
}
// select all items in session list
private void sessionSelectAll_Click ( object sender , EventArgs e )
2009-04-16 08:19:45 +00:00
{
2009-04-20 06:57:07 +00:00
foreach ( ListViewItem item in listViewSessions . Items )
2009-04-16 08:19:45 +00:00
{
2009-04-20 06:57:07 +00:00
item . Selected = true ;
2009-04-16 08:19:45 +00:00
}
2009-04-20 06:57:07 +00:00
}
// unselect all items in session list
private void sessionSelectNone_Click ( object sender , EventArgs e )
{
foreach ( ListViewItem item in listViewSessions . Items )
2009-04-16 08:19:45 +00:00
{
2009-04-20 06:57:07 +00:00
item . Selected = false ;
2009-04-16 08:19:45 +00:00
}
}
2009-04-16 05:14:07 +00:00
2009-04-20 06:57:07 +00:00
// invert selection
private void sessionInvertSelection_Click ( object sender , EventArgs e )
2009-04-16 08:19:45 +00:00
{
2009-04-20 06:57:07 +00:00
foreach ( ListViewItem item in listViewSessions . Items )
2009-04-16 08:19:45 +00:00
{
2009-04-20 06:57:07 +00:00
item . Selected = ! item . Selected ;
2009-04-16 08:19:45 +00:00
}
}
2009-04-16 05:14:07 +00:00
2009-04-20 06:57:07 +00:00
// remove all sessions
private void sessionRemoveAll_Click ( object sender , EventArgs e )
2009-04-16 08:19:45 +00:00
{
2009-04-20 06:57:07 +00:00
listViewSessions . Items . Clear ( ) ;
2009-04-16 08:19:45 +00:00
}
2009-04-16 05:14:07 +00:00
2009-04-20 06:57:07 +00:00
// remove sessions that are currently selected
private void sessionRemoveSelected_Click ( object sender , EventArgs e )
2009-04-16 05:14:07 +00:00
{
2009-04-20 06:57:07 +00:00
foreach ( ListViewItem item in listViewSessions . Items )
2009-04-16 05:14:07 +00:00
{
2009-04-20 06:57:07 +00:00
if ( item . Selected )
listViewSessions . Items . Remove ( item ) ;
2009-04-16 05:14:07 +00:00
}
2009-04-16 08:19:45 +00:00
}
2009-04-16 05:14:07 +00:00
2009-04-20 06:57:07 +00:00
// remove sessions that are not currently selected
private void sessionRemoveUnselected_Click ( object sender , EventArgs e )
2009-04-16 05:14:07 +00:00
{
2009-04-20 06:57:07 +00:00
foreach ( ListViewItem item in listViewSessions . Items )
{
if ( ! item . Selected )
listViewSessions . Items . Remove ( item ) ;
}
2009-04-17 10:02:16 +00:00
}
2009-04-20 06:57:07 +00:00
// Colorize selected sessions
private void sessionMarkSelected_Click ( object sender , EventArgs e )
2009-04-17 10:02:16 +00:00
{
2009-04-20 06:57:07 +00:00
ToolStripMenuItem menu = ( ToolStripMenuItem ) sender ;
2009-04-17 10:02:16 +00:00
2009-04-20 06:57:07 +00:00
foreach ( ListViewItem item in listViewSessions . Items )
2009-04-17 10:02:16 +00:00
{
2009-04-20 06:57:07 +00:00
if ( item . Selected )
item . BackColor = Color . FromName ( menu . Text ) ;
2009-04-17 10:02:16 +00:00
}
2009-04-20 06:57:07 +00:00
sessionSelectNone_Click ( sender , e ) ;
}
2009-04-17 10:02:16 +00:00
2009-04-20 06:57:07 +00:00
// Unmark selected sessions
private void sessionUnmarkSelected_Click ( object sender , EventArgs e )
{
foreach ( ListViewItem item in listViewSessions . Items )
2009-04-17 10:02:16 +00:00
{
2009-04-20 06:57:07 +00:00
if ( item . Selected )
item . BackColor = Color . White ;
2009-04-17 10:02:16 +00:00
}
2009-04-20 06:57:07 +00:00
sessionSelectNone_Click ( sender , e ) ;
}
2009-04-17 10:02:16 +00:00
2009-04-20 06:57:07 +00:00
private void aboutWinGridProxyToolStripMenuItem_Click ( object sender , EventArgs e )
{
AboutBox1 about = new AboutBox1 ( ) ;
about . ShowDialog ( ) ;
2009-04-16 05:14:07 +00:00
}
2009-04-17 00:48:52 +00:00
2009-04-20 06:57:07 +00:00
// Update Request Hexbox status bar with current cursor location
private void RequestPosition_Changed ( object sender , EventArgs e )
{
if ( hexBoxRequest . ByteProvider ! = null )
{
labelRequestHex . Text = string . Format ( "Ln {0} Col {1} bytes {2}" ,
hexBoxRequest . CurrentLine , hexBoxRequest . CurrentPositionInLine , hexBoxRequest . ByteProvider . Length ) ;
}
}
// Update Response Hexbox status bar with current cursor location
2009-04-18 04:21:51 +00:00
void ReplyPosition_Changed ( object sender , EventArgs e )
2009-04-17 00:48:52 +00:00
{
2009-04-18 04:21:51 +00:00
if ( hexBoxResponse . ByteProvider ! = null )
{
labelResponseHex . Text = string . Format ( "Ln {0} Col {1} bytes {2}" ,
hexBoxResponse . CurrentLine , hexBoxResponse . CurrentPositionInLine , hexBoxResponse . ByteProvider . Length ) ;
}
2009-04-17 00:48:52 +00:00
}
2009-04-20 06:57:07 +00:00
/// <summary>Enable or Disable Autoscrolling of the session list, Updates the Preferences and context menus</summary>
/// <param name="sender">The ToolStripMenuItem sending the event</param>
/// <param name="e"></param>
private void sessionEnableAutoScroll_CheckedChanged ( object sender , EventArgs e )
2009-04-17 00:48:52 +00:00
{
2009-04-20 06:57:07 +00:00
ToolStripMenuItem autoscroll = ( ToolStripMenuItem ) sender ;
AutoScrollSessions = autoScrollSessionsToolStripMenuItem . Checked = toolStripMenuItemAutoScroll . Checked = autoscroll . Checked ;
2009-04-17 00:48:52 +00:00
}
2009-04-17 10:02:16 +00:00
2009-04-20 06:57:07 +00:00
// select all specified sessions by packet name
private void sessionSelectAllPacketType_Click ( object sender , EventArgs e )
2009-04-17 10:02:16 +00:00
{
foreach ( ListViewItem item in listViewSessions . Items )
{
2009-04-20 06:57:07 +00:00
if ( item . SubItems [ 2 ] . Text . Equals ( toolStripMenuItemSelectPacketName . Tag ) & & ! item . Selected )
item . Selected = true ;
2009-04-17 10:02:16 +00:00
}
}
2009-04-23 10:02:39 +00:00
//private void sessionSelectAllProtocol_Click(object sender, EventArgs e)
//{
// foreach (ListViewItem item in listViewSessions.Items)
// {
// if (item.SubItems[1].Text.Equals(toolStripMenuItemSelectProtocol.Tag) && !item.Selected)
// item.Selected = true;
// }
//}
2009-04-17 10:02:16 +00:00
2009-04-20 06:57:07 +00:00
// stop capturing selected filters
private void filterDisableByPacketName_CheckedChanged ( object sender , EventArgs e )
2009-04-17 10:02:16 +00:00
{
2009-04-20 06:57:07 +00:00
if ( enableDisableFilterByNameToolStripMenuItem . Tag ! = null )
2009-04-23 10:02:39 +00:00
{
2009-04-20 06:57:07 +00:00
ListViewItem found = listViewMessageFilters . FindItemWithText ( enableDisableFilterByNameToolStripMenuItem . Tag . ToString ( ) ) ;
if ( found ! = null )
{
listViewMessageFilters . Items [ found . Index ] . Checked = enableDisableFilterByNameToolStripMenuItem . Checked ;
}
else
{
found = listViewPacketFilters . FindItemWithText ( enableDisableFilterByNameToolStripMenuItem . Tag . ToString ( ) ) ;
if ( found ! = null )
listViewPacketFilters . Items [ found . Index ] . Checked = enableDisableFilterByNameToolStripMenuItem . Checked ;
}
2009-04-17 10:02:16 +00:00
}
2009-04-20 06:57:07 +00:00
}
2009-04-17 10:02:16 +00:00
2009-04-20 06:57:07 +00:00
/// <summary>
/// Setup the context menu prior to it being displayed with specific entries for filtering packets/messages
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void contextMenuStripSessions_Opening ( object sender , CancelEventArgs e )
2009-04-17 10:02:16 +00:00
{
2009-04-20 06:57:07 +00:00
if ( listViewSessions . FocusedItem ! = null )
2009-04-17 10:02:16 +00:00
{
2009-04-20 06:57:07 +00:00
string strPacketOrMessage = ( listViewSessions . FocusedItem . SubItems [ 1 ] . Text . Equals ( "UDP" ) ) ? "Packets" : "Messages" ;
enableDisableFilterByNameToolStripMenuItem . Text = String . Format ( "Capture {0} {1}" , listViewSessions . FocusedItem . SubItems [ 2 ] . Text , strPacketOrMessage ) ;
toolStripMenuItemSelectPacketName . Tag = enableDisableFilterByNameToolStripMenuItem . Tag = listViewSessions . FocusedItem . SubItems [ 2 ] . Text ;
2009-04-25 06:40:43 +00:00
toolStripMenuItemSelectPacketName . Text = String . Format ( "All {0} {1}" , listViewSessions . FocusedItem . SubItems [ 2 ] . Text , strPacketOrMessage ) ;
2009-04-20 06:57:07 +00:00
2009-04-23 10:02:39 +00:00
enableDisableFilterByNameToolStripMenuItem . Visible =
toolStripSeparatorSelectPacketProto . Visible =
toolStripSeparatorFilterPacketByName . Visible =
toolStripMenuItemSelectPacketName . Visible = true ;
2009-04-20 06:57:07 +00:00
// find checkstate of selected menuitem in packets or messages filters checkedListBoxes
bool ctxChecked = false ;
2009-04-23 10:02:39 +00:00
2009-04-20 06:57:07 +00:00
if ( strPacketOrMessage . Equals ( "Packets" ) )
{
ListViewItem found = listViewPacketFilters . FindItemWithText ( toolStripMenuItemSelectPacketName . Tag . ToString ( ) ) ;
if ( found ! = null )
ctxChecked = found . Checked ;
}
else if ( strPacketOrMessage . Equals ( "Messages" ) ) // && listViewMessageFilters.Items.ContainsKey(toolStripMenuItemSelectPacketName.Tag.ToString()))
{
ListViewItem found = listViewMessageFilters . FindItemWithText ( toolStripMenuItemSelectPacketName . Tag . ToString ( ) ) ;
if ( found ! = null )
ctxChecked = found . Checked ;
}
enableDisableFilterByNameToolStripMenuItem . Checked = ctxChecked ;
}
else
{
// Hide specific selection options on context menu
2009-04-23 10:02:39 +00:00
enableDisableFilterByNameToolStripMenuItem . Visible =
toolStripSeparatorSelectPacketProto . Visible =
toolStripSeparatorFilterPacketByName . Visible =
toolStripMenuItemSelectPacketName . Visible = false ;
}
if ( listViewSessions . Items . Count > 0 )
{
markToolStripMenuItem2 . Enabled =
findToolStripMenuItem1 . Enabled =
toolStripMenuSessionsRemove . Enabled =
selectToolStripMenuItem2 . Enabled = true ;
2009-04-17 10:02:16 +00:00
}
2009-04-23 10:02:39 +00:00
else
{
markToolStripMenuItem2 . Enabled =
findToolStripMenuItem1 . Enabled =
toolStripMenuSessionsRemove . Enabled =
selectToolStripMenuItem2 . Enabled = false ;
}
2009-04-17 10:02:16 +00:00
}
2009-04-20 06:57:07 +00:00
private void findSessions_Click ( object sender , EventArgs e )
2009-04-17 10:02:16 +00:00
{
2009-04-20 06:57:07 +00:00
FilterOptions opts = new FilterOptions ( ( listViewSessions . SelectedItems . Count > 0 ) ) ;
FormSessionSearch search = new FormSessionSearch ( ref opts ) ;
search . ShowDialog ( ) ;
2009-04-23 10:02:39 +00:00
if ( ! String . IsNullOrEmpty ( opts . SearchText ) )
{
Thread sThread = new Thread ( delegate ( )
{
SearchSessions ( opts ) ;
} ) ;
sThread . Name = "Search" ;
sThread . Start ( ) ;
}
2009-04-17 10:02:16 +00:00
}
2009-04-20 06:57:07 +00:00
// Enable Inject button if box contains text
private void richTextBoxInject_TextChanged ( object sender , EventArgs e )
2009-04-17 10:02:16 +00:00
{
2009-04-20 06:57:07 +00:00
buttonInjectPacket . Enabled = ( richTextBoxInject . TextLength > 0 ) ;
}
private void buttonInjectPacket_Click ( object sender , EventArgs e )
{
proxy . InjectPacket ( richTextBoxInject . Text , true ) ;
}
private void saveFilterSelectionsToolStripMenuItem_Click ( object sender , EventArgs e )
{
if ( saveFileDialog2 . ShowDialog ( ) = = DialogResult . OK )
2009-04-17 10:02:16 +00:00
{
2009-04-20 06:57:07 +00:00
SaveAllSettings ( saveFileDialog2 . FileName ) ;
2009-04-17 10:02:16 +00:00
}
}
2009-04-20 06:57:07 +00:00
private void loadFilterSelectionsToolStripMenuItem_Click ( object sender , EventArgs e )
2009-04-17 10:02:16 +00:00
{
2009-04-20 06:57:07 +00:00
if ( openFileDialog2 . ShowDialog ( ) = = DialogResult . OK )
2009-04-17 10:02:16 +00:00
{
2009-04-20 06:57:07 +00:00
RestoreSavedSettings ( openFileDialog2 . FileName ) ;
2009-05-08 07:32:49 +00:00
if ( listViewSessions . Items . Count > 0 )
2009-05-07 20:55:03 +00:00
{
2009-05-08 07:32:49 +00:00
if ( MessageBox . Show ( "Would you like to apply these settings to the currention session list?" , "Apply Filter" , MessageBoxButtons . YesNo , MessageBoxIcon . Question ) = = System . Windows . Forms . DialogResult . Yes )
2009-05-07 20:55:03 +00:00
{
2009-05-08 03:13:51 +00:00
listViewSessions . BeginUpdate ( ) ;
2009-05-08 07:32:49 +00:00
foreach ( ListViewItem item in listViewSessions . Items )
2009-05-07 20:55:03 +00:00
{
ListViewItem found = FindListViewItem ( listViewPacketFilters , item . SubItems [ 2 ] . Text , false ) ;
if ( found = = null )
found = FindListViewItem ( listViewMessageFilters , item . SubItems [ 2 ] . Text , false ) ;
2009-05-08 07:32:49 +00:00
if ( found ! = null & & ! found . Checked )
2009-05-07 20:55:03 +00:00
listViewSessions . Items . Remove ( item ) ;
}
2009-05-08 03:13:51 +00:00
listViewSessions . EndUpdate ( ) ;
2009-05-07 20:55:03 +00:00
}
}
2009-04-17 10:02:16 +00:00
}
2009-04-17 23:13:33 +00:00
}
2009-04-20 06:57:07 +00:00
private void listViewMessageFilters_ItemChecked ( object sender , ItemCheckedEventArgs e )
2009-04-17 23:13:33 +00:00
{
2009-04-20 06:57:07 +00:00
proxy . AddCapsDelegate ( e . Item . Text , e . Item . Checked ) ;
2009-04-18 04:21:51 +00:00
}
2009-04-20 06:57:07 +00:00
private void listViewPacketFilters_ItemChecked ( object sender , ItemCheckedEventArgs e )
2009-04-18 04:21:51 +00:00
{
2009-04-20 06:57:07 +00:00
proxy . AddUDPDelegate ( packetTypeFromName ( e . Item . Text ) , e . Item . Checked ) ;
}
private void checkBoxCheckallCaps_CheckedChanged ( object sender , EventArgs e )
{
foreach ( ListViewItem item in listViewMessageFilters . Items )
2009-04-18 04:21:51 +00:00
{
2009-04-20 06:57:07 +00:00
item . Checked = checkBoxCheckAllMessages . Checked ;
2009-04-18 04:21:51 +00:00
}
}
2009-04-20 06:57:07 +00:00
#endregion
2009-04-16 05:14:07 +00:00
2009-04-20 06:57:07 +00:00
/// <summary>
/// Start/Stop the statistics gathering timer
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void enableStatisticsToolStripMenuItem_CheckedChanged ( object sender , EventArgs e )
{
if ( timer1 . Enabled & & ! enableStatisticsToolStripMenuItem . Checked )
timer1 . Enabled = false ;
2009-04-16 05:14:07 +00:00
2009-04-20 06:57:07 +00:00
if ( ! timer1 . Enabled & & enableStatisticsToolStripMenuItem . Checked )
timer1 . Enabled = true ;
}
2009-04-16 05:14:07 +00:00
2009-04-20 06:57:07 +00:00
private void saveSessionArchiveToolStripMenuItem_Click ( object sender , EventArgs e )
{
if ( saveFileDialog1 . ShowDialog ( ) = = DialogResult . OK )
{
2009-05-08 07:32:49 +00:00
OSDMap map = new OSDMap ( 1 ) ;
OSDArray sessionArray = new OSDArray ( ) ;
foreach ( ListViewItem item in listViewSessions . Items )
{
OSDMap session = new OSDMap ( ) ;
session [ "name" ] = OSD . FromString ( item . Name ) ;
session [ "image_index" ] = OSD . FromInteger ( item . ImageIndex ) ;
session [ "id" ] = OSD . FromString ( item . SubItems [ 0 ] . Text ) ;
session [ "protocol" ] = OSD . FromString ( item . SubItems [ 1 ] . Text ) ;
session [ "packet" ] = OSD . FromString ( item . SubItems [ 2 ] . Text ) ;
session [ "size" ] = OSD . FromString ( item . SubItems [ 3 ] . Text ) ;
session [ "host" ] = OSD . FromString ( item . SubItems [ 4 ] . Text ) ;
try
2009-04-20 06:57:07 +00:00
{
2009-05-08 07:32:49 +00:00
session [ "tag" ] = OSD . FromBinary ( ( byte [ ] ) item . Tag ) ;
}
catch
{
session [ "tag" ] = OSD . FromBinary ( Utils . EmptyBytes ) ;
2009-04-20 06:57:07 +00:00
}
2009-05-08 07:32:49 +00:00
finally
{
sessionArray . Add ( session ) ;
}
}
2009-04-16 05:14:07 +00:00
2009-05-08 07:32:49 +00:00
map [ "sessions" ] = sessionArray ;
2009-04-17 10:02:16 +00:00
2009-05-08 03:13:51 +00:00
try
{
File . WriteAllText ( saveFileDialog1 . FileName , map . ToString ( ) ) ;
}
catch ( Exception ex )
{
MessageBox . Show ( "Exception occurred trying to save session archive: " + ex ) ;
2009-04-20 06:57:07 +00:00
}
2009-04-23 10:02:39 +00:00
}
2009-04-20 06:57:07 +00:00
}
2009-04-17 10:02:16 +00:00
2009-04-20 06:57:07 +00:00
private void loadSessionArchiveToolStripMenuItem_Click ( object sender , EventArgs e )
2009-04-16 05:14:07 +00:00
{
2009-04-20 06:57:07 +00:00
if ( openFileDialog1 . ShowDialog ( ) = = DialogResult . OK )
{
OSD osd = OSDParser . DeserializeLLSDNotation ( File . ReadAllText ( openFileDialog1 . FileName ) ) ;
OSDMap map = ( OSDMap ) osd ;
OSDArray sessionsArray = ( OSDArray ) map [ "sessions" ] ;
2009-04-16 08:19:45 +00:00
2009-04-20 06:57:07 +00:00
listViewSessions . Items . Clear ( ) ;
listViewSessions . BeginUpdate ( ) ;
for ( int i = 0 ; i < sessionsArray . Count ; i + + )
{
OSDMap session = ( OSDMap ) sessionsArray [ i ] ;
ListViewItem addedItem = listViewSessions . Items . Add ( new ListViewItem ( new string [ ] {
session [ "id" ] . AsString ( ) ,
session [ "protocol" ] . AsString ( ) ,
session [ "packet" ] . AsString ( ) ,
session [ "size" ] . AsString ( ) ,
session [ "host" ] . AsString ( ) } ) ) ;
addedItem . ImageIndex = session [ "image_index" ] . AsInteger ( ) ;
2009-04-25 06:40:43 +00:00
addedItem . Tag = LitJson . JsonMapper . ToObject ( Utils . BytesToString ( session [ "tag" ] . AsBinary ( ) , 0 , session [ "tag" ] . AsBinary ( ) . Length ) ) ;
2009-04-20 06:57:07 +00:00
}
2009-04-16 08:19:45 +00:00
2009-04-20 06:57:07 +00:00
listViewSessions . EndUpdate ( ) ;
}
}
//Generic ListView sort event
private void listViewFilterSorter_ColumnClick ( object sender , ColumnClickEventArgs e )
{
ListView lv = ( ListView ) sender ;
ListViewItemComparer columnSorter = new ListViewItemComparer ( ) ;
columnSorter . column = e . Column ;
2009-04-16 08:19:45 +00:00
2009-04-20 06:57:07 +00:00
if ( ( columnSorter . bAscending = ( lv . Sorting = = SortOrder . Ascending ) ) )
lv . Sorting = SortOrder . Descending ;
2009-04-17 10:02:16 +00:00
else
2009-04-20 06:57:07 +00:00
lv . Sorting = SortOrder . Ascending ;
2009-04-16 08:19:45 +00:00
2009-04-20 06:57:07 +00:00
lv . ListViewItemSorter = columnSorter as IComparer ;
}
2009-04-16 08:19:45 +00:00
2009-04-20 06:57:07 +00:00
private void exitToolStripMenuItem1_Click ( object sender , EventArgs e )
{
2009-05-08 03:13:51 +00:00
// TODO: warn if client is connected!
2009-04-20 06:57:07 +00:00
this . Close ( ) ;
}
2009-04-16 08:19:45 +00:00
2009-04-20 06:57:07 +00:00
#region Helpers
2009-04-16 08:19:45 +00:00
2009-04-22 00:01:30 +00:00
/// <summary>
/// Decode an IMessage object into a string of key/value pairs
/// </summary>
/// <param name="message">The IMessage object</param>
/// <returns>A formatted string containing the names and values of the source object</returns>
2009-04-25 06:40:43 +00:00
public static string IMessageToString ( object message )
2009-04-22 00:01:30 +00:00
{
2009-04-27 23:59:49 +00:00
if ( message = = null )
return String . Empty ;
2009-04-22 00:01:30 +00:00
StringBuilder result = new StringBuilder ( ) ;
// common/custom types
result . AppendFormat ( "Message Type {0}" + System . Environment . NewLine , message . GetType ( ) . Name ) ;
foreach ( FieldInfo messageField in message . GetType ( ) . GetFields ( ) )
{
2009-04-25 06:40:43 +00:00
2009-04-22 00:01:30 +00:00
// a byte array
if ( messageField . GetValue ( message ) . GetType ( ) = = typeof ( Byte [ ] ) )
{
2009-04-23 10:02:39 +00:00
result . AppendFormat ( "{0, 30}: ({1})" + System . Environment . NewLine ,
messageField . Name , messageField . FieldType . Name ) ;
result . AppendFormat ( "{0}" + System . Environment . NewLine , Utils . BytesToHexString ( ( byte [ ] ) messageField . GetValue ( message ) , string . Format ( "{0,30}" , "" ) ) ) ;
2009-04-22 00:01:30 +00:00
}
// an array of class objects
else if ( messageField . FieldType . IsArray )
{
2009-04-26 09:38:34 +00:00
var messageObjectData = messageField . GetValue ( message ) ;
2009-04-22 00:01:30 +00:00
result . AppendFormat ( "-- {0} --" + System . Environment . NewLine , messageField . FieldType . Name ) ;
foreach ( object nestedArrayObject in messageObjectData as Array )
{
result . AppendFormat ( " [{0}]" + System . Environment . NewLine , nestedArrayObject . GetType ( ) . Name ) ;
foreach ( FieldInfo nestedField in nestedArrayObject . GetType ( ) . GetFields ( ) )
{
2009-04-23 10:02:39 +00:00
if ( nestedField . FieldType . IsEnum )
{
result . AppendFormat ( "{0, 30}: {1} {2} ({3})" + System . Environment . NewLine ,
nestedField . Name ,
Enum . Format ( nestedField . GetValue ( nestedArrayObject ) . GetType ( ) ,
nestedField . GetValue ( nestedArrayObject ) , "D" ) ,
nestedField . GetValue ( nestedArrayObject ) ,
nestedField . GetValue ( nestedArrayObject ) . GetType ( ) . Name ) ;
2009-04-27 23:59:49 +00:00
}
else if ( nestedField . FieldType . IsInterface )
{
result . AppendLine ( IMessageToString ( nestedField . GetValue ( nestedArrayObject ) ) ) ;
}
2009-04-23 10:02:39 +00:00
else
{
result . AppendFormat ( "{0, 30}: {1} ({2})" + System . Environment . NewLine ,
nestedField . Name ,
nestedField . GetValue ( nestedArrayObject ) ,
nestedField . GetValue ( nestedArrayObject ) . GetType ( ) . Name ) ;
}
2009-04-22 00:01:30 +00:00
}
}
}
else
{
2009-04-23 10:02:39 +00:00
if ( messageField . FieldType . IsEnum )
{
result . AppendFormat ( "{0, 30}: {1} {2} ({3})" + System . Environment . NewLine ,
messageField . Name ,
Enum . Format ( messageField . GetValue ( message ) . GetType ( ) ,
messageField . GetValue ( message ) , "D" ) ,
messageField . GetValue ( message ) , messageField . FieldType . Name ) ;
}
2009-04-25 06:40:43 +00:00
else if ( messageField . FieldType . IsInterface )
{
result . AppendLine ( IMessageToString ( messageField . GetValue ( message ) ) ) ;
}
2009-04-23 10:02:39 +00:00
else
{
result . AppendFormat ( "{0, 30}: {1} ({2})" + System . Environment . NewLine ,
messageField . Name , messageField . GetValue ( message ) , messageField . FieldType . Name ) ;
}
2009-04-22 00:01:30 +00:00
}
}
return result . ToString ( ) ;
}
2009-05-08 06:38:28 +00:00
private static string InterpretOptions ( Header header )
2009-04-25 06:40:43 +00:00
{
return "["
2009-05-08 06:38:28 +00:00
+ ( header . AppendedAcks ? "Ack" : " " )
2009-04-25 06:40:43 +00:00
+ " "
2009-05-08 06:38:28 +00:00
+ ( header . Resent ? "Res" : " " )
2009-04-25 06:40:43 +00:00
+ " "
2009-05-08 06:38:28 +00:00
+ ( header . Reliable ? "Rel" : " " )
2009-04-25 06:40:43 +00:00
+ " "
2009-05-08 06:38:28 +00:00
+ ( header . Zerocoded ? "Zer" : " " )
2009-04-25 06:40:43 +00:00
+ "]"
;
}
2009-04-23 10:02:39 +00:00
/// <summary>
/// Creates a formatted string containing the values of a Packet
/// </summary>
/// <param name="packet">The Packet</param>
/// <returns>A formatted string of values of the nested items in the Packet object</returns>
2009-05-08 03:13:51 +00:00
/// <remarks>TODO: This is overly complex. Static helpers should be created to clean this up and it
/// should be made generic enough to decode IMessage objects too.</remarks>
2009-04-20 06:57:07 +00:00
public static string PacketToString ( Packet packet )
{
StringBuilder result = new StringBuilder ( ) ;
2009-04-16 05:14:07 +00:00
2009-04-22 00:01:30 +00:00
result . AppendFormat ( "Packet Type: {0}" + System . Environment . NewLine , packet . Type ) ;
2009-04-25 06:40:43 +00:00
result . AppendLine ( "[Packet Header]" ) ;
// payload
result . AppendFormat ( "Sequence: {0}" + System . Environment . NewLine , packet . Header . Sequence ) ;
2009-05-08 06:38:28 +00:00
result . AppendFormat ( " Options: {0}" + System . Environment . NewLine , InterpretOptions ( packet . Header ) ) ;
2009-04-25 06:40:43 +00:00
result . AppendLine ( ) ;
2009-04-16 08:19:45 +00:00
2009-04-25 06:40:43 +00:00
result . AppendLine ( "[Packet Payload]" ) ;
2009-04-20 06:57:07 +00:00
foreach ( FieldInfo packetField in packet . GetType ( ) . GetFields ( ) )
{
object packetDataObject = packetField . GetValue ( packet ) ;
2009-04-16 05:14:07 +00:00
2009-04-20 06:57:07 +00:00
result . AppendFormat ( "-- {0,20} --" + System . Environment . NewLine , packetField . Name ) ;
foreach ( FieldInfo packetValueField in packetField . GetValue ( packet ) . GetType ( ) . GetFields ( ) )
{
result . AppendFormat ( "{0,30}: {1}" + System . Environment . NewLine ,
packetValueField . Name , packetValueField . GetValue ( packetDataObject ) ) ;
}
// handle blocks that are arrays
if ( packetDataObject . GetType ( ) . IsArray )
{
foreach ( object nestedArrayRecord in packetDataObject as Array )
{
2009-05-07 20:55:03 +00:00
// handle properties
foreach ( PropertyInfo propertyInfo in nestedArrayRecord . GetType ( ) . GetProperties ( ) )
{
if ( propertyInfo . GetValue ( nestedArrayRecord , null ) . GetType ( ) = = typeof ( byte [ ] ) )
{
result . AppendFormat ( "{0, 30}: {1}" + Environment . NewLine ,
2009-05-08 07:32:49 +00:00
propertyInfo . Name ,
2009-05-08 03:13:51 +00:00
Utils . BytesToString ( ( byte [ ] ) propertyInfo . GetValue ( nestedArrayRecord , null ) ) ) ;
2009-05-07 20:55:03 +00:00
}
}
// handle fields
2009-04-20 06:57:07 +00:00
foreach ( FieldInfo packetArrayField in nestedArrayRecord . GetType ( ) . GetFields ( ) )
{
2009-05-07 20:55:03 +00:00
if ( packetArrayField . GetValue ( nestedArrayRecord ) . GetType ( ) = = typeof ( Byte [ ] ) )
2009-04-23 10:02:39 +00:00
{
2009-05-07 20:55:03 +00:00
result . AppendFormat ( "{0,30}: {1}" + Environment . NewLine ,
2009-04-23 10:02:39 +00:00
packetArrayField . Name ,
2009-05-07 20:55:03 +00:00
new Color4 ( ( byte [ ] ) packetArrayField . GetValue ( nestedArrayRecord ) , 0 , false ) ) ;
2009-04-20 06:57:07 +00:00
}
else
{
2009-05-07 20:55:03 +00:00
result . AppendFormat ( "{0,30}: {1}" + Environment . NewLine ,
2009-04-20 06:57:07 +00:00
packetArrayField . Name , packetArrayField . GetValue ( nestedArrayRecord ) ) ;
}
}
}
}
2009-05-07 20:55:03 +00:00
2009-04-20 06:57:07 +00:00
else
{
// handle non array data blocks
foreach ( PropertyInfo packetPropertyField in packetField . GetValue ( packet ) . GetType ( ) . GetProperties ( ) )
{
// Handle fields named "Data" specifically, this is generally binary data, we'll display it as hex values
2009-05-07 20:55:03 +00:00
if ( packetPropertyField . PropertyType . Equals ( typeof ( Byte [ ] ) )
2009-04-20 06:57:07 +00:00
& & packetPropertyField . Name . Equals ( "Data" ) )
{
result . AppendFormat ( "{0}" + System . Environment . NewLine ,
Utils . BytesToHexString ( ( byte [ ] ) packetPropertyField . GetValue ( packetDataObject , null ) ,
packetPropertyField . Name ) ) ;
}
// decode bytes into strings
2009-05-07 20:55:03 +00:00
else if ( packetPropertyField . PropertyType . Equals ( typeof ( Byte [ ] ) ) )
2009-04-20 06:57:07 +00:00
{
// Handle TextureEntry fields specifically
if ( packetPropertyField . Name . Equals ( "TextureEntry" ) )
{
byte [ ] tebytes = ( byte [ ] ) packetPropertyField . GetValue ( packetDataObject , null ) ;
2009-04-16 08:19:45 +00:00
2009-04-20 06:57:07 +00:00
Primitive . TextureEntry te = new Primitive . TextureEntry ( tebytes , 0 , tebytes . Length ) ;
result . AppendFormat ( "{0,30}:\n{1}" , packetPropertyField . Name , te . ToString ( ) ) ;
}
else
{
2009-04-25 06:40:43 +00:00
// Decode the BinaryBucket
if ( packetPropertyField . Name . Equals ( "BinaryBucket" ) )
{
byte [ ] bytes = ( byte [ ] ) packetPropertyField . GetValue ( packetDataObject , null ) ;
string bbDecoded = String . Empty ;
if ( bytes . Length = = 1 )
{
bbDecoded = String . Format ( "{0}" , bytes [ 0 ] ) ;
2009-05-08 07:32:49 +00:00
}
2009-04-25 06:40:43 +00:00
else if ( bytes . Length = = 17 )
{
2009-05-08 07:32:49 +00:00
bbDecoded = String . Format ( "{0} {1} ({2})" ,
new UUID ( bytes , 1 ) ,
bytes [ 0 ] ,
2009-05-07 20:55:03 +00:00
( AssetType ) bytes [ 0 ] ) ;
2009-04-25 06:40:43 +00:00
}
else
{
bbDecoded = Utils . BytesToString ( bytes ) ;
}
result . AppendFormat ( "{0,30}: {1}" + System . Environment . NewLine ,
packetPropertyField . Name ,
bbDecoded ) ;
}
else
{
result . AppendFormat ( "{0,30}: {1}" + System . Environment . NewLine ,
packetPropertyField . Name ,
Utils . BytesToString ( ( byte [ ] ) packetPropertyField . GetValue ( packetDataObject , null ) ) ) ;
}
2009-04-20 06:57:07 +00:00
}
}
else
{
// this seems to be limited to the length property, since all others have been previously handled
if ( packetPropertyField . Name ! = "Length" )
{
2009-04-23 10:02:39 +00:00
result . AppendFormat ( "{0,30}: {1} [{2}]" + System . Environment . NewLine ,
2009-04-20 06:57:07 +00:00
packetPropertyField . Name , packetPropertyField . GetValue ( packetDataObject , null ) ,
packetPropertyField . GetType ( ) ) ;
}
}
}
}
}
return result . ToString ( ) ;
2009-04-16 05:14:07 +00:00
}
2009-04-20 06:57:07 +00:00
private void SaveAllSettings ( string fileName )
2009-04-16 05:14:07 +00:00
{
2009-04-20 06:57:07 +00:00
Store . MessageSessions . Clear ( ) ;
Store . PacketSessions . Clear ( ) ;
foreach ( ListViewItem item in listViewPacketFilters . Items )
{
2009-04-22 00:01:30 +00:00
FilterEntry entry = new FilterEntry ( ) ;
entry . Checked = item . Checked ;
entry . pType = item . SubItems [ 1 ] . Text ;
Store . PacketSessions . Add ( item . Text , entry ) ;
2009-04-20 06:57:07 +00:00
}
foreach ( ListViewItem item in listViewMessageFilters . Items )
{
2009-04-22 00:01:30 +00:00
FilterEntry entry = new FilterEntry ( ) ;
entry . Checked = item . Checked ;
entry . pType = item . SubItems [ 1 ] . Text ;
Store . MessageSessions . Add ( item . Text , entry ) ;
2009-04-20 06:57:07 +00:00
}
2009-04-23 10:02:39 +00:00
2009-04-20 06:57:07 +00:00
Store . StatisticsEnabled = enableStatisticsToolStripMenuItem . Checked ;
Store . AutoScrollEnabled = autoScrollSessionsToolStripMenuItem . Checked ;
Store . SaveSessionOnExit = saveOptionsOnExitToolStripMenuItem . Checked ;
Store . AutoCheckNewCaps = autoAddNewDiscoveredMessagesToolStripMenuItem . Checked ;
Store . SerializeToFile ( fileName ) ;
2009-04-16 05:14:07 +00:00
}
2009-04-20 06:57:07 +00:00
private void RestoreSavedSettings ( string fileName )
2009-04-16 05:14:07 +00:00
{
2009-04-20 06:57:07 +00:00
// load saved settings from OSD Formatted file
if ( Store . DeserializeFromFile ( fileName ) )
{
autoScrollSessionsToolStripMenuItem . Checked = Store . AutoScrollEnabled ;
enableStatisticsToolStripMenuItem . Checked = Store . StatisticsEnabled ;
saveOptionsOnExitToolStripMenuItem . Checked = Store . SaveSessionOnExit ;
autoAddNewDiscoveredMessagesToolStripMenuItem . Checked = Store . AutoCheckNewCaps ;
// Update message filter listview
listViewMessageFilters . BeginUpdate ( ) ;
2009-04-22 00:01:30 +00:00
foreach ( KeyValuePair < string , FilterEntry > kvp in Store . MessageSessions )
2009-04-20 06:57:07 +00:00
{
ListViewItem foundMessage = listViewPacketFilters . FindItemWithText ( kvp . Key ) ;
if ( foundMessage = = null )
{
ListViewItem addedItem = listViewMessageFilters . Items . Add ( kvp . Key ) ;
2009-04-22 00:01:30 +00:00
addedItem . Checked = kvp . Value . Checked ;
addedItem . SubItems . Add ( kvp . Value . pType ) ;
addedItem . BackColor = ( kvp . Value . pType . Equals ( "CapMessage" ) ) ? Color . Honeydew : Color . AliceBlue ;
2009-04-20 06:57:07 +00:00
}
else
{
2009-04-22 00:01:30 +00:00
foundMessage . Checked = kvp . Value . Checked ;
2009-04-20 06:57:07 +00:00
}
}
listViewMessageFilters . EndUpdate ( ) ;
// updateTreeView packet filter listview
listViewPacketFilters . BeginUpdate ( ) ;
2009-04-22 00:01:30 +00:00
foreach ( KeyValuePair < string , FilterEntry > kvp in Store . PacketSessions )
2009-04-20 06:57:07 +00:00
{
ListViewItem foundPacket = listViewPacketFilters . FindItemWithText ( kvp . Key ) ;
if ( foundPacket = = null )
{
ListViewItem addedItem = listViewPacketFilters . Items . Add ( new ListViewItem ( kvp . Key ) ) ;
2009-04-22 00:01:30 +00:00
addedItem . Checked = kvp . Value . Checked ;
addedItem . SubItems . Add ( kvp . Value . pType ) ;
2009-04-20 06:57:07 +00:00
}
else
{
2009-04-22 00:01:30 +00:00
foundPacket . Checked = kvp . Value . Checked ;
2009-04-20 06:57:07 +00:00
}
}
listViewPacketFilters . EndUpdate ( ) ;
}
2009-04-16 05:14:07 +00:00
}
2009-04-20 06:57:07 +00:00
private void InitProxyFilters ( )
2009-04-16 05:14:07 +00:00
{
2009-04-20 06:57:07 +00:00
RestoreSavedSettings ( "settings.osd" ) ;
2009-04-16 05:14:07 +00:00
2009-04-20 06:57:07 +00:00
Type packetTypeType = typeof ( PacketType ) ;
System . Reflection . MemberInfo [ ] packetTypes = packetTypeType . GetMembers ( ) ;
2009-04-16 05:14:07 +00:00
2009-04-20 06:57:07 +00:00
listViewPacketFilters . BeginUpdate ( ) ;
for ( int i = 0 ; i < packetTypes . Length ; i + + )
{
if ( packetTypes [ i ] . MemberType = = System . Reflection . MemberTypes . Field
& & packetTypes [ i ] . DeclaringType = = packetTypeType )
{
string name = packetTypes [ i ] . Name ;
PacketType pType ;
try
{
pType = packetTypeFromName ( name ) ;
2009-05-08 07:32:49 +00:00
2009-04-20 06:57:07 +00:00
ListViewItem found = listViewPacketFilters . FindItemWithText ( name ) ;
if ( ! String . IsNullOrEmpty ( name ) & & found = = null )
{
ListViewItem addedItem = listViewPacketFilters . Items . Add ( new ListViewItem ( name ) ) ;
2009-04-22 00:01:30 +00:00
addedItem . SubItems . Add ( "UDP" ) ;
2009-04-20 06:57:07 +00:00
}
}
catch ( Exception )
{
continue ;
}
}
}
2009-04-22 00:01:30 +00:00
//listViewPacketFilters.Sort();
2009-04-23 10:02:39 +00:00
2009-04-20 06:57:07 +00:00
listViewPacketFilters . EndUpdate ( ) ;
2009-04-16 05:14:07 +00:00
}
2009-04-16 08:19:45 +00:00
2009-04-20 06:57:07 +00:00
private static PacketType packetTypeFromName ( string name )
2009-04-16 05:14:07 +00:00
{
2009-04-20 06:57:07 +00:00
Type packetTypeType = typeof ( PacketType ) ;
System . Reflection . FieldInfo f = packetTypeType . GetField ( name ) ;
if ( f = = null ) throw new ArgumentException ( "Bad packet type" ) ;
2009-04-16 05:14:07 +00:00
2009-04-20 06:57:07 +00:00
return ( PacketType ) Enum . ToObject ( packetTypeType , ( int ) f . GetValue ( packetTypeType ) ) ;
2009-04-16 05:14:07 +00:00
}
2009-04-20 06:57:07 +00:00
private void SearchSessions ( FilterOptions opts )
2009-04-16 05:14:07 +00:00
{
2009-04-23 10:02:39 +00:00
if ( this . InvokeRequired )
2009-04-20 06:57:07 +00:00
{
2009-04-23 10:02:39 +00:00
this . BeginInvoke ( new MethodInvoker ( delegate ( )
{
SearchSessions ( opts ) ;
} ) ) ;
}
else
{
int resultCount = 0 ;
foreach ( ListViewItem item in listViewSessions . Items )
{
if ( opts . UnMarkPrevious )
item . BackColor = Color . White ;
if ( opts . SearchSelected & & ! item . Selected )
{
continue ;
}
if (
( opts . MatchCase
& & ( item . SubItems [ 2 ] . Text . Contains ( opts . SearchText )
| | TagToString ( item . Tag , item . SubItems [ 2 ] . Text ) . Contains ( opts . SearchText ) )
) // no case matching
| | ( ( item . SubItems [ 2 ] . Text . ToLower ( ) . Contains ( opts . SearchText . ToLower ( ) )
| | TagToString ( item . Tag , item . SubItems [ 2 ] . Text ) . ToLower ( ) . Contains ( opts . SearchText . ToLower ( ) )
) )
)
2009-04-20 06:57:07 +00:00
{
2009-04-23 10:02:39 +00:00
resultCount + + ;
2009-04-20 06:57:07 +00:00
2009-04-23 10:02:39 +00:00
if ( opts . MarkMatches )
item . BackColor = opts . HighlightMatchColor ;
2009-04-20 06:57:07 +00:00
if ( opts . SelectResults )
item . Selected = true ;
else
item . Selected = false ;
2009-04-23 10:02:39 +00:00
}
2009-04-20 06:57:07 +00:00
}
2009-04-23 10:02:39 +00:00
toolStripMainLabel . Text = String . Format ( "Search found {0} Matches" , resultCount ) ;
2009-04-20 06:57:07 +00:00
}
2009-04-23 10:02:39 +00:00
}
2009-04-20 06:57:07 +00:00
2009-04-22 00:01:30 +00:00
private string TagToString ( object tag , string key )
2009-04-16 05:14:07 +00:00
{
2009-04-20 06:57:07 +00:00
if ( tag is XmlRpcRequest )
2009-04-16 05:14:07 +00:00
{
2009-04-20 06:57:07 +00:00
XmlRpcRequest requestData = ( XmlRpcRequest ) tag ;
return requestData . ToString ( ) ;
2009-04-16 05:14:07 +00:00
}
2009-04-20 06:57:07 +00:00
else if ( tag is XmlRpcResponse )
{
XmlRpcResponse responseData = ( XmlRpcResponse ) tag ;
return responseData . ToString ( ) ;
}
else if ( tag is Packet )
2009-04-16 05:14:07 +00:00
{
2009-04-20 06:57:07 +00:00
Packet packet = ( Packet ) tag ;
return PacketToString ( packet ) ;
2009-04-16 05:14:07 +00:00
}
2009-04-20 06:57:07 +00:00
else if ( tag is CapsRequest )
{
CapsRequest capsData = ( CapsRequest ) tag ;
if ( capsData . Request ! = null )
{
return capsData . Request . ToString ( ) ;
}
if ( capsData . Response ! = null )
{
2009-04-23 10:02:39 +00:00
return capsData . Response . ToString ( ) ;
2009-04-20 06:57:07 +00:00
}
2009-04-22 00:01:30 +00:00
return "Unable to decode CapsRequest" ;
}
else if ( tag is OSD )
{
OSD osd = ( OSD ) tag ;
if ( osd . Type = = OSDType . Map )
{
OSDMap data = ( OSDMap ) osd ;
IMessage message ;
if ( data . ContainsKey ( "body" ) )
2009-04-27 23:59:49 +00:00
message = OpenMetaverse . Messages . MessageUtils . DecodeEvent ( key , ( OSDMap ) data [ "body" ] ) ;
2009-04-22 00:01:30 +00:00
else
2009-04-27 23:59:49 +00:00
message = OpenMetaverse . Messages . MessageUtils . DecodeEvent ( key , data ) ;
2009-04-22 00:01:30 +00:00
if ( message ! = null )
return IMessageToString ( message ) ;
else
return "No Decoder for " + key + System . Environment . NewLine
+ osd . ToString ( ) ;
}
else
{
return osd . ToString ( ) ;
}
}
else
{
return "Could not decode object type: " + tag . GetType ( ) . ToString ( ) ;
2009-04-20 06:57:07 +00:00
}
2009-04-16 05:14:07 +00:00
}
2009-04-20 06:57:07 +00:00
#endregion
2009-04-23 10:02:39 +00:00
2009-04-20 06:57:07 +00:00
#region XML Tree
2009-04-16 05:14:07 +00:00
2009-04-20 06:57:07 +00:00
private void updateTreeView ( string xml , TreeView treeView )
{
try
{
2009-04-22 00:01:30 +00:00
treeView . Nodes . Clear ( ) ;
2009-04-23 10:02:39 +00:00
2009-04-20 06:57:07 +00:00
XmlDocument tmpxmldoc = new XmlDocument ( ) ;
tmpxmldoc . LoadXml ( xml ) ;
FillTree ( tmpxmldoc . DocumentElement , treeView . Nodes ) ;
treeView . ExpandAll ( ) ;
}
catch ( Exception ex )
{
Console . WriteLine ( "Error during xml conversion:" + ex . Message ) ;
}
2009-04-16 05:14:07 +00:00
}
2009-04-20 06:57:07 +00:00
private void FillTree ( XmlNode node , TreeNodeCollection parentnode )
2009-04-17 00:48:52 +00:00
{
2009-04-20 06:57:07 +00:00
// End recursion if the node is a text type
if ( node = = null | | node . NodeType = = XmlNodeType . Text | | node . NodeType = = XmlNodeType . CDATA )
return ;
TreeNodeCollection tmptreenodecollection = AddNodeToTree ( node , parentnode ) ;
2009-04-17 00:48:52 +00:00
2009-04-20 06:57:07 +00:00
// Add all the children of the current node to the treeview
foreach ( XmlNode tmpchildnode in node . ChildNodes )
{
FillTree ( tmpchildnode , tmptreenodecollection ) ;
}
2009-04-17 00:48:52 +00:00
}
2009-04-20 06:57:07 +00:00
private TreeNodeCollection AddNodeToTree ( XmlNode node , TreeNodeCollection parentnode )
{
TreeNode newchildnode = CreateTreeNodeFromXmlNode ( node ) ;
2009-04-16 05:14:07 +00:00
2009-04-20 06:57:07 +00:00
// if nothing to add, return the parent item
if ( newchildnode = = null ) return parentnode ;
2009-04-16 05:14:07 +00:00
2009-04-20 06:57:07 +00:00
// add the newly created tree node to its parent
if ( parentnode ! = null ) parentnode . Add ( newchildnode ) ;
return newchildnode . Nodes ;
}
2009-04-16 05:14:07 +00:00
2009-04-20 06:57:07 +00:00
private TreeNode CreateTreeNodeFromXmlNode ( XmlNode node )
2009-04-16 05:14:07 +00:00
{
2009-04-20 06:57:07 +00:00
TreeNode tmptreenode = new TreeNode ( ) ;
if ( ( node . HasChildNodes ) & & ( node . FirstChild . Value ! = null ) )
{
tmptreenode = new TreeNode ( node . Name ) ;
TreeNode tmptreenode2 = new TreeNode ( node . FirstChild . Value ) ;
tmptreenode . Nodes . Add ( tmptreenode2 ) ;
}
else if ( node . NodeType ! = XmlNodeType . CDATA )
{
tmptreenode = new TreeNode ( node . Name ) ;
}
return tmptreenode ;
2009-04-16 05:14:07 +00:00
}
2009-04-20 06:57:07 +00:00
#endregion
#region Timers
private void timer1_Tick ( object sender , EventArgs e )
2009-04-16 05:14:07 +00:00
{
2009-04-20 06:57:07 +00:00
if ( this . InvokeRequired )
{
this . BeginInvoke ( new MethodInvoker ( delegate ( )
{
timer1_Tick ( sender , e ) ;
} ) ) ;
}
else
{
label1PacketsOut . Text = String . Format ( "{0} ({1} bytes)" , PacketsOutCounter , PacketsOutBytes ) ;
labelPacketsIn . Text = String . Format ( "{0} ({1} bytes)" , PacketsInCounter , PacketsInBytes ) ;
labelPacketsTotal . Text = String . Format ( "{0} ({1} bytes)" , PacketsOutCounter + PacketsInCounter , PacketsOutBytes + PacketsInBytes ) ;
2009-04-16 08:19:45 +00:00
2009-04-20 06:57:07 +00:00
labelCapsIn . Text = String . Format ( "{0} ({1} bytes)" , CapsInCounter , CapsInBytes ) ;
labelCapsOut . Text = String . Format ( "{0} ({1} bytes)" , CapsOutCounter , CapsOutBytes ) ;
labelCapsTotal . Text = String . Format ( "{0} ({1} bytes)" , CapsInCounter + CapsOutCounter , CapsOutBytes + CapsInBytes ) ;
}
2009-04-16 05:14:07 +00:00
}
2009-04-20 06:57:07 +00:00
2009-04-23 10:02:39 +00:00
#endregion
private void EditToolStripButton_DropDownOpening ( object sender , EventArgs e )
{
if ( listViewSessions . Items . Count > 0 )
{
toolStripMenuSessionsRemove . Enabled =
removeToolStripMenuItem2 . Enabled =
selectToolStripMenuItem1 . Enabled =
saveSessionArchiveToolStripMenuItem . Enabled =
toolStripMenuItemRemoveAll . Enabled = true ;
if ( listViewSessions . SelectedItems . Count < listViewSessions . Items . Count )
{
toolStripMenuItemRemoveUnselected . Enabled = true ;
}
else
{
toolStripMenuItemRemoveUnselected . Enabled = false ;
}
if ( listViewSessions . SelectedItems . Count > 0 )
{
markToolStripMenuItem1 . Enabled =
toolStripSeparatorSelectPacketProto . Visible =
toolStripMenuItemSelectPacketName . Visible =
noneToolStripMenuItem2 . Enabled =
copyToolStripMenuItem1 . Enabled =
toolStripMenuItemRemoveSelected . Enabled = true ;
}
else
{
markToolStripMenuItem1 . Enabled =
toolStripSeparatorSelectPacketProto . Visible =
toolStripMenuItemSelectPacketName . Visible =
noneToolStripMenuItem2 . Enabled =
noneToolStripMenuItem2 . Enabled =
copyToolStripMenuItem1 . Enabled =
toolStripMenuItemRemoveSelected . Enabled = false ;
}
if ( listViewSessions . SelectedItems . Count > 0
& & listViewSessions . SelectedItems . Count ! = listViewSessions . Items . Count )
{
toolStripMenuItemRemoveUnselected . Enabled =
invertToolStripMenuItem1 . Enabled =
noneToolStripMenuItem2 . Enabled = true ;
}
else
{
toolStripMenuItemRemoveUnselected . Enabled =
invertToolStripMenuItem1 . Enabled =
noneToolStripMenuItem2 . Enabled = false ;
}
}
else
{
toolStripMenuSessionsRemove . Enabled =
toolStripSeparatorSelectPacketProto . Visible =
// toolStripMenuItemSelectProtocol.Visible =
toolStripMenuItemSelectPacketName . Visible =
findToolStripMenuItem . Enabled =
selectToolStripMenuItem1 . Enabled =
removeToolStripMenuItem2 . Enabled =
toolStripMenuItemRemoveUnselected . Enabled =
copyToolStripMenuItem1 . Enabled =
markToolStripMenuItem1 . Enabled =
saveSessionArchiveToolStripMenuItem . Enabled =
toolStripMenuItemRemoveAll . Enabled = false ;
}
if ( listViewPacketFilters . Items . Count + listViewSessions . Items . Count > 0 )
{
saveFilterSelectionsToolStripMenuItem . Enabled = true ;
}
else
{
saveFilterSelectionsToolStripMenuItem . Enabled = false ;
}
}
private void autoColorizeToolStripMenuItem_Click ( object sender , EventArgs e )
{
if ( colorDialog1 . ShowDialog ( ) = = DialogResult . OK )
{
//listview.BackColor = colorDialog1.Color;
}
}
2009-05-07 20:55:03 +00:00
private void toolStripMenuItem1_Click ( object sender , EventArgs e )
{
FormPluginManager pluginManager = new FormPluginManager ( proxy . Proxy ) ;
pluginManager . ShowDialog ( ) ;
}
2009-04-23 10:02:39 +00:00
}
2009-04-16 05:14:07 +00:00
}