2007-05-11 Jorn Baayen <jorn@openedhand.com>
authorJorn Baayen <jorn@openedhand.com>
Sun, 13 May 2007 11:54:03 +0000 (11:54 +0000)
committerJorn Baayen <jorn@openedhand.com>
Sun, 13 May 2007 11:54:03 +0000 (11:54 +0000)
* AUTHORS: Added Zeeshan.

2007-05-11  Zeeshan Ali  <zeenix@gstreamer.net>

* tools/gssdp-device-sniffer.c: (on_ssdp_message),
(on_use_filter_radiobutton_toggled), (get_ip_filter),
(on_address_filter_dialog_response), (init_ui), (init_upnp):
* tools/gssdp-device-sniffer.glade:

- Correctly handle delete-event.
- Fix initial size of the window.
- Add support for IP-filtering of packets.
- Do active the resource-browser.
- Add copyright header.

git-svn-id: https://svn.o-hand.com/repos/gupnp/trunk/gssdp@213 d8cb91d7-bff9-0310-92b9-80b65e4482b2

AUTHORS
ChangeLog
tools/gssdp-device-sniffer.c
tools/gssdp-device-sniffer.glade

diff --git a/AUTHORS b/AUTHORS
index 3d4e269..96ddcd5 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -1 +1,6 @@
 Jorn Baayen <jorn@openedhand.com>
+
+
+Device sniffer:
+
+Zeeshan Ali <zeenix@gstreamer.net>
index a56356e..e1b1885 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2007-05-11  Jorn Baayen  <jorn@openedhand.com>
+
+       * AUTHORS: Added Zeeshan.
+
+2007-05-11  Zeeshan Ali  <zeenix@gstreamer.net>
+
+       * tools/gssdp-device-sniffer.c: (on_ssdp_message),
+       (on_use_filter_radiobutton_toggled), (get_ip_filter),
+       (on_address_filter_dialog_response), (init_ui), (init_upnp):
+       * tools/gssdp-device-sniffer.glade:
+
+       - Correctly handle delete-event.
+       - Fix initial size of the window. 
+       - Add support for IP-filtering of packets.
+       - Do active the resource-browser.
+       - Add copyright header.
+
 2007-05-11  Zeeshan Ali  <zeenix@gstreamer.net>
 
        * tools/gssdp-device-sniffer.c: (append_device), (find_device),
index 5b9f842..7a492d3 100644 (file)
@@ -1,14 +1,36 @@
+/* 
+ * Copyright (C) 2007 Zeeshan Ali <zeenix@gstreamer.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
 #include <libgssdp/gssdp.h>
 #include <libgssdp/gssdp-client-private.h>
 #include <gtk/gtk.h>
 #include <glade/glade.h>
 #include <string.h>
+#include <stdlib.h>
 
 #define GLADE_FILE "gssdp-device-sniffer.glade"
+#define MAX_IP_LEN 16
 
 GladeXML *glade_xml;
 GSSDPResourceBrowser *resource_browser;
 GSSDPClient *client;
+char *ip_filter = NULL;
 
 void
 on_enable_packet_capture_activate (GtkMenuItem *menuitem, gpointer user_data)
@@ -209,9 +231,14 @@ on_ssdp_message (GSSDPClient *client,
                 gpointer user_data)
 {
         time_t arrival_time;
+        gboolean allowed = TRUE;
         
         arrival_time = time (NULL);
-        if (type != _GSSDP_DISCOVERY_RESPONSE)
+     
+        if (ip_filter != NULL && strcmp (ip_filter, from_ip) != 0)
+                allowed = FALSE;
+
+        if (type != _GSSDP_DISCOVERY_RESPONSE && allowed)
                 append_packet (from_ip, arrival_time, type, headers);
 }
 
@@ -371,20 +398,66 @@ resource_unavailable_cb (GSSDPResourceBrowser *resource_browser,
 }
 
 void
-on_custom_search_dialog_response (GtkDialog *dialog,
+on_use_filter_radiobutton_toggled (GtkToggleButton *togglebutton,
+                gpointer         user_data)
+{
+        GtkWidget *filter_hbox;
+        gboolean use_filter;
+
+        filter_hbox = glade_xml_get_widget (glade_xml, "address-filter-hbox");
+        g_assert (filter_hbox != NULL);
+        
+        use_filter = gtk_toggle_button_get_active (togglebutton);
+        gtk_widget_set_sensitive (filter_hbox, use_filter);
+}
+
+static char *
+get_ip_filter ()
+{
+        int i;
+        char *ip;
+        guint8 quad[4];
+
+        ip = g_malloc (MAX_IP_LEN);
+        for (i=0; i<4; i++) {
+                GtkWidget *entry;
+                char entry_name[16];
+                gint val;
+
+                sprintf (entry_name, "address-entry%d", i);
+                entry = glade_xml_get_widget (glade_xml, entry_name);
+                g_assert (entry != NULL);
+
+                val = atoi (gtk_entry_get_text (GTK_ENTRY (entry)));
+                quad[i] = CLAMP (val, 0, 255);
+        }
+        sprintf (ip, "%u.%u.%u.%u", quad[0], quad[1], quad[2], quad[3]);
+        
+        return ip;
+}
+
+void
+on_address_filter_dialog_response (GtkDialog *dialog,
                 gint       response,
                 gpointer   user_data)
 {
-        GtkWidget *entry;
+        GtkWidget *use_filter_radio;
 
-        entry = glade_xml_get_widget (glade_xml, "search-target-entry");
-        g_assert (entry != NULL);
         gtk_widget_hide (GTK_WIDGET (dialog));
-        if (response == GTK_RESPONSE_OK) {
-                g_print ("search target: %s\n",
-                                gtk_entry_get_text (GTK_ENTRY (entry)));
+        
+        use_filter_radio = glade_xml_get_widget (glade_xml, "use-filter-radiobutton");
+        g_assert (use_filter_radio != NULL);
+        
+        if (response != GTK_RESPONSE_OK)
+                return;
+        
+        g_free (ip_filter);
+        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (use_filter_radio))) {
+                ip_filter = get_ip_filter ();
         }
-        gtk_entry_set_text (GTK_ENTRY (entry), "");
+       
+        else
+                ip_filter = NULL;
 }
 
 static GtkTreeModel *
@@ -494,6 +567,7 @@ static gboolean
 init_ui (gint *argc, gchar **argv[])
 {
         GtkWidget *main_window;
+        gint window_width, window_height;
         
         gtk_init (argc, argv);
         glade_init ();
@@ -512,6 +586,13 @@ init_ui (gint *argc, gchar **argv[])
         main_window = glade_xml_get_widget (glade_xml, "main-window");
         g_assert (main_window != NULL);
 
+        /* 80% of the screen but don't get bigger than 1000x800 */
+        window_width = CLAMP ((gdk_screen_width () * 80 / 100), 10, 1000);
+        window_height = CLAMP ((gdk_screen_height () * 80 / 100), 10, 800);
+        gtk_window_set_default_size (GTK_WINDOW (main_window),
+                                     window_width,
+                                     window_height);
+
         glade_xml_signal_autoconnect (glade_xml);
         setup_treeviews ();
         gtk_widget_show_all (main_window);
@@ -556,6 +637,8 @@ init_upnp (void)
                           G_CALLBACK (resource_unavailable_cb),
                           NULL);
 
+        gssdp_resource_browser_set_active (resource_browser, TRUE);
+
         return TRUE;
 }
 
@@ -578,7 +661,7 @@ main (gint argc, gchar *argv[])
         }
         
         gtk_main ();
-        
+       
         deinit_upnp ();
         deinit_ui ();
         
index 8f21c12..ee022cc 100644 (file)
@@ -5,13 +5,10 @@
 
 <widget class="GtkWindow" id="main-window">
   <property name="border_width">4</property>
-  <property name="visible">True</property>
   <property name="title" translatable="yes">GSSDP Device Sniffer</property>
   <property name="type">GTK_WINDOW_TOPLEVEL</property>
   <property name="window_position">GTK_WIN_POS_NONE</property>
   <property name="modal">False</property>
-  <property name="default_width">500</property>
-  <property name="default_height">600</property>
   <property name="resizable">True</property>
   <property name="destroy_with_parent">False</property>
   <property name="decorated">True</property>
@@ -21,7 +18,7 @@
   <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
   <property name="focus_on_map">True</property>
   <property name="urgency_hint">False</property>
-  <signal name="delete_event" handler="gtk_main_quit" last_modification_time="Sat, 21 Apr 2007 14:47:09 GMT"/>
+  <signal name="delete_event" handler="on_delete_event" last_modification_time="Fri, 11 May 2007 10:36:15 GMT"/>
 
   <child>
     <widget class="GtkVBox" id="vbox">
                      <property name="visible">True</property>
                      <property name="label" translatable="yes">Address Filter</property>
                      <property name="use_underline">True</property>
+                     <signal name="activate" handler="gtk_widget_show" object="address-filter-dialog" last_modification_time="Fri, 11 May 2007 10:58:14 GMT"/>
                    </widget>
                  </child>
                </widget>
        <widget class="GtkScrolledWindow" id="packet-scrolledwindow">
          <property name="visible">True</property>
          <property name="can_focus">True</property>
-         <property name="hscrollbar_policy">GTK_POLICY_ALWAYS</property>
-         <property name="vscrollbar_policy">GTK_POLICY_ALWAYS</property>
+         <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+         <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
          <property name="shadow_type">GTK_SHADOW_IN</property>
          <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
 
        <widget class="GtkScrolledWindow" id="packet-details-scrolledwindow">
          <property name="visible">True</property>
          <property name="can_focus">True</property>
-         <property name="hscrollbar_policy">GTK_POLICY_ALWAYS</property>
-         <property name="vscrollbar_policy">GTK_POLICY_ALWAYS</property>
+         <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+         <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
          <property name="shadow_type">GTK_SHADOW_IN</property>
          <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
 
        <widget class="GtkScrolledWindow" id="device-details-scrolledwindow">
          <property name="visible">True</property>
          <property name="can_focus">True</property>
-         <property name="hscrollbar_policy">GTK_POLICY_ALWAYS</property>
-         <property name="vscrollbar_policy">GTK_POLICY_ALWAYS</property>
+         <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+         <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
          <property name="shadow_type">GTK_SHADOW_IN</property>
          <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
 
@@ -269,4 +267,305 @@ Inspired by Intel Tools for UPnP.</property>
   <property name="translator_credits" translatable="yes" comments="TRANSLATORS: Replace this string with your names, one name per line.">translator-credits</property>
 </widget>
 
+<widget class="GtkDialog" id="address-filter-dialog">
+  <property name="title" translatable="yes">Address Filter</property>
+  <property name="type">GTK_WINDOW_TOPLEVEL</property>
+  <property name="window_position">GTK_WIN_POS_NONE</property>
+  <property name="modal">False</property>
+  <property name="resizable">True</property>
+  <property name="destroy_with_parent">False</property>
+  <property name="decorated">True</property>
+  <property name="skip_taskbar_hint">False</property>
+  <property name="skip_pager_hint">False</property>
+  <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
+  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
+  <property name="focus_on_map">True</property>
+  <property name="urgency_hint">False</property>
+  <property name="has_separator">True</property>
+  <signal name="response" handler="on_address_filter_dialog_response" last_modification_time="Fri, 11 May 2007 11:00:37 GMT"/>
+
+  <child internal-child="vbox">
+    <widget class="GtkVBox" id="dialog-vbox1">
+      <property name="visible">True</property>
+      <property name="homogeneous">False</property>
+      <property name="spacing">0</property>
+
+      <child internal-child="action_area">
+       <widget class="GtkHButtonBox" id="dialog-action_area1">
+         <property name="visible">True</property>
+         <property name="layout_style">GTK_BUTTONBOX_END</property>
+
+         <child>
+           <widget class="GtkButton" id="cancelbutton1">
+             <property name="visible">True</property>
+             <property name="can_default">True</property>
+             <property name="can_focus">True</property>
+             <property name="label">gtk-cancel</property>
+             <property name="use_stock">True</property>
+             <property name="relief">GTK_RELIEF_NORMAL</property>
+             <property name="focus_on_click">True</property>
+             <property name="response_id">-6</property>
+           </widget>
+         </child>
+
+         <child>
+           <widget class="GtkButton" id="okbutton1">
+             <property name="visible">True</property>
+             <property name="can_default">True</property>
+             <property name="can_focus">True</property>
+             <property name="label">gtk-ok</property>
+             <property name="use_stock">True</property>
+             <property name="relief">GTK_RELIEF_NORMAL</property>
+             <property name="focus_on_click">True</property>
+             <property name="response_id">-5</property>
+           </widget>
+         </child>
+       </widget>
+       <packing>
+         <property name="padding">0</property>
+         <property name="expand">False</property>
+         <property name="fill">True</property>
+         <property name="pack_type">GTK_PACK_END</property>
+       </packing>
+      </child>
+
+      <child>
+       <widget class="GtkVBox" id="vbox1">
+         <property name="visible">True</property>
+         <property name="homogeneous">False</property>
+         <property name="spacing">0</property>
+
+         <child>
+           <widget class="GtkRadioButton" id="dont-use-filter-radiobutton">
+             <property name="visible">True</property>
+             <property name="can_focus">True</property>
+             <property name="label" translatable="yes">No filter, capture all traffic</property>
+             <property name="use_underline">True</property>
+             <property name="relief">GTK_RELIEF_NORMAL</property>
+             <property name="focus_on_click">True</property>
+             <property name="active">True</property>
+             <property name="inconsistent">False</property>
+             <property name="draw_indicator">True</property>
+           </widget>
+           <packing>
+             <property name="padding">0</property>
+             <property name="expand">False</property>
+             <property name="fill">False</property>
+           </packing>
+         </child>
+
+         <child>
+           <widget class="GtkRadioButton" id="use-filter-radiobutton">
+             <property name="visible">True</property>
+             <property name="can_focus">True</property>
+             <property name="label" translatable="yes">Use IP address filter</property>
+             <property name="use_underline">True</property>
+             <property name="relief">GTK_RELIEF_NORMAL</property>
+             <property name="focus_on_click">True</property>
+             <property name="active">False</property>
+             <property name="inconsistent">False</property>
+             <property name="draw_indicator">True</property>
+             <property name="group">dont-use-filter-radiobutton</property>
+             <signal name="toggled" handler="on_use_filter_radiobutton_toggled" last_modification_time="Fri, 11 May 2007 10:55:01 GMT"/>
+           </widget>
+           <packing>
+             <property name="padding">0</property>
+             <property name="expand">False</property>
+             <property name="fill">False</property>
+           </packing>
+         </child>
+
+         <child>
+           <widget class="GtkAlignment" id="alignment1">
+             <property name="visible">True</property>
+             <property name="xalign">0.5</property>
+             <property name="yalign">0.5</property>
+             <property name="xscale">1</property>
+             <property name="yscale">1</property>
+             <property name="top_padding">0</property>
+             <property name="bottom_padding">0</property>
+             <property name="left_padding">50</property>
+             <property name="right_padding">0</property>
+
+             <child>
+               <widget class="GtkHBox" id="address-filter-hbox">
+                 <property name="visible">True</property>
+                 <property name="sensitive">False</property>
+                 <property name="homogeneous">False</property>
+                 <property name="spacing">0</property>
+
+                 <child>
+                   <widget class="GtkEntry" id="address-entry0">
+                     <property name="visible">True</property>
+                     <property name="can_focus">True</property>
+                     <property name="editable">True</property>
+                     <property name="visibility">True</property>
+                     <property name="max_length">3</property>
+                     <property name="text" translatable="yes"></property>
+                     <property name="has_frame">True</property>
+                     <property name="invisible_char">*</property>
+                     <property name="activates_default">True</property>
+                     <property name="width_chars">4</property>
+                   </widget>
+                   <packing>
+                     <property name="padding">0</property>
+                     <property name="expand">True</property>
+                     <property name="fill">True</property>
+                   </packing>
+                 </child>
+
+                 <child>
+                   <widget class="GtkLabel" id="address-label0">
+                     <property name="visible">True</property>
+                     <property name="label" translatable="yes">.</property>
+                     <property name="use_underline">False</property>
+                     <property name="use_markup">False</property>
+                     <property name="justify">GTK_JUSTIFY_LEFT</property>
+                     <property name="wrap">False</property>
+                     <property name="selectable">False</property>
+                     <property name="xalign">0.5</property>
+                     <property name="yalign">0.5</property>
+                     <property name="xpad">0</property>
+                     <property name="ypad">0</property>
+                     <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+                     <property name="width_chars">-1</property>
+                     <property name="single_line_mode">False</property>
+                     <property name="angle">0</property>
+                   </widget>
+                   <packing>
+                     <property name="padding">0</property>
+                     <property name="expand">False</property>
+                     <property name="fill">False</property>
+                   </packing>
+                 </child>
+
+                 <child>
+                   <widget class="GtkEntry" id="address-entry1">
+                     <property name="visible">True</property>
+                     <property name="can_focus">True</property>
+                     <property name="editable">True</property>
+                     <property name="visibility">True</property>
+                     <property name="max_length">3</property>
+                     <property name="text" translatable="yes"></property>
+                     <property name="has_frame">True</property>
+                     <property name="invisible_char">*</property>
+                     <property name="activates_default">True</property>
+                     <property name="width_chars">4</property>
+                   </widget>
+                   <packing>
+                     <property name="padding">0</property>
+                     <property name="expand">True</property>
+                     <property name="fill">True</property>
+                   </packing>
+                 </child>
+
+                 <child>
+                   <widget class="GtkLabel" id="address-label1">
+                     <property name="visible">True</property>
+                     <property name="label" translatable="yes">.</property>
+                     <property name="use_underline">False</property>
+                     <property name="use_markup">False</property>
+                     <property name="justify">GTK_JUSTIFY_LEFT</property>
+                     <property name="wrap">False</property>
+                     <property name="selectable">False</property>
+                     <property name="xalign">0.5</property>
+                     <property name="yalign">0.5</property>
+                     <property name="xpad">0</property>
+                     <property name="ypad">0</property>
+                     <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+                     <property name="width_chars">-1</property>
+                     <property name="single_line_mode">False</property>
+                     <property name="angle">0</property>
+                   </widget>
+                   <packing>
+                     <property name="padding">0</property>
+                     <property name="expand">False</property>
+                     <property name="fill">False</property>
+                   </packing>
+                 </child>
+
+                 <child>
+                   <widget class="GtkEntry" id="address-entry2">
+                     <property name="visible">True</property>
+                     <property name="can_focus">True</property>
+                     <property name="editable">True</property>
+                     <property name="visibility">True</property>
+                     <property name="max_length">3</property>
+                     <property name="text" translatable="yes"></property>
+                     <property name="has_frame">True</property>
+                     <property name="invisible_char">*</property>
+                     <property name="activates_default">True</property>
+                     <property name="width_chars">4</property>
+                   </widget>
+                   <packing>
+                     <property name="padding">0</property>
+                     <property name="expand">True</property>
+                     <property name="fill">True</property>
+                   </packing>
+                 </child>
+
+                 <child>
+                   <widget class="GtkLabel" id="address-label2">
+                     <property name="visible">True</property>
+                     <property name="label" translatable="yes">.</property>
+                     <property name="use_underline">False</property>
+                     <property name="use_markup">False</property>
+                     <property name="justify">GTK_JUSTIFY_LEFT</property>
+                     <property name="wrap">False</property>
+                     <property name="selectable">False</property>
+                     <property name="xalign">0.5</property>
+                     <property name="yalign">0.5</property>
+                     <property name="xpad">0</property>
+                     <property name="ypad">0</property>
+                     <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+                     <property name="width_chars">-1</property>
+                     <property name="single_line_mode">False</property>
+                     <property name="angle">0</property>
+                   </widget>
+                   <packing>
+                     <property name="padding">0</property>
+                     <property name="expand">False</property>
+                     <property name="fill">False</property>
+                   </packing>
+                 </child>
+
+                 <child>
+                   <widget class="GtkEntry" id="address-entry3">
+                     <property name="visible">True</property>
+                     <property name="can_focus">True</property>
+                     <property name="editable">True</property>
+                     <property name="visibility">True</property>
+                     <property name="max_length">3</property>
+                     <property name="text" translatable="yes"></property>
+                     <property name="has_frame">True</property>
+                     <property name="invisible_char">*</property>
+                     <property name="activates_default">True</property>
+                     <property name="width_chars">4</property>
+                   </widget>
+                   <packing>
+                     <property name="padding">0</property>
+                     <property name="expand">True</property>
+                     <property name="fill">True</property>
+                   </packing>
+                 </child>
+               </widget>
+             </child>
+           </widget>
+           <packing>
+             <property name="padding">0</property>
+             <property name="expand">True</property>
+             <property name="fill">True</property>
+           </packing>
+         </child>
+       </widget>
+       <packing>
+         <property name="padding">0</property>
+         <property name="expand">True</property>
+         <property name="fill">True</property>
+       </packing>
+      </child>
+    </widget>
+  </child>
+</widget>
+
 </glade-interface>