[gnome-network]whois function
- From: William Jon McCann <mccannwj pha jhu edu>
- To: gnome-network-list gnome org
- Subject: [gnome-network]whois function
- Date: Wed, 19 Nov 2003 02:50:56 -0500
Hi,
Here is a patch and two new files that add a whois function to
gnome-netinfo.
Ok to commit?
Jon
? finger.c.new
? info.c.new
? whois.c
? whois.h
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/ChangeLog,v
retrieving revision 1.96
diff -u -r1.96 ChangeLog
--- ChangeLog 18 Nov 2003 21:55:54 -0000 1.96
+++ ChangeLog 19 Nov 2003 07:46:38 -0000
@@ -1,3 +1,18 @@
+2003-11-19 William Jon McCann <mccann jhu edu>
+
+ * netinfo.h:
+ * main.c (main):
+ * gnome-netinfo.glade:
+ * callbacks.h:
+ * callbacks.c (on_copy_activate):
+ * Makefile.am (gnome_netinfo_SOURCES):
+ Added whois function.
+
+ * main.c (load_whois_widgets_from_xml):
+ * callbacks.c (on_whois_activate): New functions for whois query.
+
+ * whois.[ch]: New files for whois query.
+
2003-11-18 William Jon McCann <mccann jhu edu>
* lookup.c (lookup_do): Add hostname validation to lookup function.
Index: Makefile.am
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/Makefile.am,v
retrieving revision 1.14
diff -u -r1.14 Makefile.am
--- Makefile.am 25 Aug 2003 15:54:37 -0000 1.14
+++ Makefile.am 19 Nov 2003 07:46:38 -0000
@@ -22,6 +22,7 @@
scan.c scan.h \
lookup.c lookup.h \
finger.c finger.h \
+ whois.c whois.h \
utils.c utils.h \
util-mii.c util-mii.h mii.h \
util-mii-wireless.h \
Index: callbacks.c
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/callbacks.c,v
retrieving revision 1.26
diff -u -r1.26 callbacks.c
--- callbacks.c 18 Nov 2003 20:51:50 -0000 1.26
+++ callbacks.c 19 Nov 2003 07:46:38 -0000
@@ -31,6 +31,7 @@
#include "netstat.h"
#include "scan.h"
#include "finger.h"
+#include "whois.h"
#include "sys/wait.h"
#include "unistd.h"
@@ -142,6 +143,21 @@
}
}
+/* Whois callbacks */
+void
+on_whois_activate (GtkWidget * widget, gpointer data)
+{
+ Netinfo *whois = data;
+
+ g_return_if_fail (whois != NULL);
+
+ if (whois->running) {
+ whois_stop (whois);
+ } else {
+ whois_do (whois);
+ }
+}
+
void
gn_quit_app (GtkWidget * widget, gpointer data)
{
@@ -241,6 +257,9 @@
break;
case FINGER:
netinfo = g_object_get_data (G_OBJECT (notebook), "finger");
+ break;
+ case WHOIS:
+ netinfo = g_object_get_data (G_OBJECT (notebook), "whois");
break;
default:
g_print ("default notebook page?\n");
Index: callbacks.h
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/callbacks.h,v
retrieving revision 1.10
diff -u -r1.10 callbacks.h
--- callbacks.h 18 Nov 2003 20:51:50 -0000 1.10
+++ callbacks.h 19 Nov 2003 07:46:38 -0000
@@ -14,6 +14,8 @@
void on_finger_activate (GtkWidget * editable, gpointer data);
+void on_whois_activate (GtkWidget * editable, gpointer data);
+
/* General stuff */
void gn_quit_app (GtkWidget * widget, gpointer data);
Index: gnome-netinfo.glade
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/gnome-netinfo.glade,v
retrieving revision 1.27
diff -u -r1.27 gnome-netinfo.glade
--- gnome-netinfo.glade 18 Nov 2003 20:51:50 -0000 1.27
+++ gnome-netinfo.glade 19 Nov 2003 07:46:47 -0000
@@ -2344,7 +2344,7 @@
</child>
<child>
- <widget class="GtkLabel" id="label25">
+ <widget class="GtkLabel" id="netstat">
<property name="visible">True</property>
<property name="label" translatable="yes">_Netstat</property>
<property name="use_underline">True</property>
@@ -2852,7 +2852,7 @@
</child>
<child>
- <widget class="GtkLabel" id="label45">
+ <widget class="GtkLabel" id="scan">
<property name="visible">True</property>
<property name="label" translatable="yes">Port _Scan</property>
<property name="use_underline">True</property>
@@ -3273,7 +3273,7 @@
</child>
<child>
- <widget class="GtkVBox" id="vbox11">
+ <widget class="GtkVBox" id="vbox_finger">
<property name="border_width">6</property>
<property name="visible">True</property>
<property name="homogeneous">False</property>
@@ -3563,9 +3563,270 @@
</child>
<child>
- <widget class="GtkLabel" id="label74">
+ <widget class="GtkLabel" id="finger">
<property name="visible">True</property>
<property name="label" translatable="yes">_Finger</property>
+ <property name="use_underline">True</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>
+ </widget>
+ <packing>
+ <property name="type">tab</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkVBox" id="vbox_whois">
+ <property name="border_width">6</property>
+ <property name="visible">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">6</property>
+
+ <child>
+ <widget class="GtkVBox" id="vbox14">
+ <property name="border_width">6</property>
+ <property name="visible">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">6</property>
+
+ <child>
+ <widget class="GtkLabel" id="label81">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes"><span weight="bold">Enter a domain address to lookup its "whois" information</span></property>
+ <property name="use_underline">False</property>
+ <property name="use_markup">True</property>
+ <property name="justify">GTK_JUSTIFY_LEFT</property>
+ <property name="wrap">False</property>
+ <property name="selectable">False</property>
+ <property name="xalign">0</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkHBox" id="whois_input_box">
+ <property name="visible">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">12</property>
+
+ <child>
+ <widget class="GtkLabel" id="label82">
+ <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>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GnomeEntry" id="whois_host">
+ <property name="visible">True</property>
+ <property name="history_id">GNOME_Network_netinfo_domain</property>
+ <property name="max_saved">10</property>
+
+ <child internal-child="entry">
+ <widget class="GtkEntry" id="entry6">
+ <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">0</property>
+ <property name="text" translatable="yes"></property>
+ <property name="has_frame">True</property>
+ <property name="invisible_char" translatable="yes">*</property>
+ <property name="activates_default">False</property>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkLabel" id="label84">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">(for example: domain.com)</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>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkHButtonBox" id="hbuttonbox8">
+ <property name="visible">True</property>
+ <property name="layout_style">GTK_BUTTONBOX_END</property>
+ <property name="spacing">0</property>
+
+ <child>
+ <widget class="GtkButton" id="whois_button">
+ <property name="visible">True</property>
+ <property name="can_default">True</property>
+ <property name="can_focus">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+
+ <child>
+ <widget class="GtkAlignment" id="alignment12">
+ <property name="visible">True</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xscale">0</property>
+ <property name="yscale">0</property>
+
+ <child>
+ <widget class="GtkHBox" id="hbox32">
+ <property name="visible">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">2</property>
+
+ <child>
+ <widget class="GtkImage" id="image11">
+ <property name="visible">True</property>
+ <property name="stock">gtk-ok</property>
+ <property name="icon_size">4</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkLabel" id="label85">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Whois</property>
+ <property name="use_underline">True</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>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkScrolledWindow" id="scrolledwindow7">
+ <property name="visible">True</property>
+ <property name="can_focus">True</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>
+
+ <child>
+ <widget class="GtkTextView" id="whois_output">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="editable">True</property>
+ <property name="justification">GTK_JUSTIFY_LEFT</property>
+ <property name="wrap_mode">GTK_WRAP_NONE</property>
+ <property name="cursor_visible">True</property>
+ <property name="pixels_above_lines">0</property>
+ <property name="pixels_below_lines">0</property>
+ <property name="pixels_inside_wrap">0</property>
+ <property name="left_margin">0</property>
+ <property name="right_margin">0</property>
+ <property name="indent">0</property>
+ <property name="text" translatable="yes"></property>
+ </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="tab_expand">False</property>
+ <property name="tab_fill">True</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkLabel" id="whois">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Whois</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
Index: main.c
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/main.c,v
retrieving revision 1.38
diff -u -r1.38 main.c
--- main.c 18 Nov 2003 20:51:50 -0000 1.38
+++ main.c 19 Nov 2003 07:46:48 -0000
@@ -32,6 +32,7 @@
#include "scan.h"
#include "lookup.h"
#include "finger.h"
+#include "whois.h"
Netinfo *load_ping_widgets_from_xml (GladeXML * xml);
Netinfo *load_traceroute_widgets_from_xml (GladeXML * xml);
@@ -39,6 +40,7 @@
Netinfo *load_scan_widgets_from_xml (GladeXML * xml);
Netinfo *load_lookup_widgets_from_xml (GladeXML * xml);
Netinfo *load_finger_widgets_from_xml (GladeXML * xml);
+Netinfo *load_whois_widgets_from_xml (GladeXML * xml);
Netinfo *load_info_widgets_from_xml (GladeXML * xml);
int
@@ -57,6 +59,7 @@
Netinfo *scan;
Netinfo *lookup;
Netinfo *finger;
+ Netinfo *whois;
gchar *icon_path;
#ifdef ENABLE_NLS
@@ -91,6 +94,7 @@
scan = load_scan_widgets_from_xml (xml);
lookup = load_lookup_widgets_from_xml (xml);
finger = load_finger_widgets_from_xml (xml);
+ whois = load_whois_widgets_from_xml (xml);
notebook = glade_xml_get_widget (xml, "notebook");
g_object_set_data (G_OBJECT (notebook), "pinger", pinger);
@@ -100,6 +104,7 @@
g_object_set_data (G_OBJECT (notebook), "scan", scan);
g_object_set_data (G_OBJECT (notebook), "lookup", lookup);
g_object_set_data (G_OBJECT (notebook), "finger", finger);
+ g_object_set_data (G_OBJECT (notebook), "whois", whois);
glade_xml_signal_autoconnect (xml);
g_object_unref (G_OBJECT (xml));
@@ -115,6 +120,7 @@
g_free (scan);
g_free (lookup);
g_free (finger);
+ g_free (whois);
return 0;
}
@@ -297,7 +303,6 @@
g_signal_connect (G_OBJECT (info->nic), "changed",
G_CALLBACK (info_nic_changed),
info);
-
info_load_iface (info, combo);
/*
#else
@@ -441,4 +446,55 @@
finger);
return finger;
+}
+
+/* The value returned must be released from memory */
+Netinfo *
+load_whois_widgets_from_xml (GladeXML * xml)
+{
+ Netinfo *whois;
+ GtkWidget *vbox_whois;
+ PangoFontDescription *font_desc;
+
+ g_return_val_if_fail (xml != NULL, NULL);
+
+ whois = g_new0 (Netinfo, 1);
+
+ whois->main_window = glade_xml_get_widget (xml, "main_window");
+ whois->running = FALSE;
+ whois->child_pid = 0;
+ whois->host = glade_xml_get_widget (xml, "whois_host");
+ whois->output = glade_xml_get_widget (xml, "whois_output");
+ whois->button = glade_xml_get_widget (xml, "whois_button");
+ whois->count = NULL;
+ whois->limited = NULL;
+ whois->sensitive = glade_xml_get_widget (xml, "whois_input_box");
+ whois->label_run = _("Whois");
+ whois->label_stop = NULL;
+ whois->routing = NULL;
+ whois->protocol = NULL;
+ whois->multicast = NULL;
+
+ vbox_whois = glade_xml_get_widget (xml, "vbox_whois");
+
+ font_desc = pango_font_description_new ();
+ pango_font_description_set_family (font_desc, "fixed");
+ gtk_widget_modify_font (whois->output, font_desc);
+ pango_font_description_free (font_desc);
+
+ whois->button_callback = G_CALLBACK (on_whois_activate);
+ whois->process_line = NETINFO_FOREACH_FUNC (whois_foreach);
+ whois->copy_output = NETINFO_COPY_FUNC (whois_copy_to_clipboard);
+
+ g_signal_connect (G_OBJECT (whois->user), "activate",
+ G_CALLBACK (on_whois_activate),
+ whois);
+ g_signal_connect (G_OBJECT (whois->host), "activate",
+ G_CALLBACK (on_whois_activate),
+ whois);
+ g_signal_connect (G_OBJECT (whois->button), "clicked",
+ whois->button_callback,
+ whois);
+
+ return whois;
}
Index: netinfo.h
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/netinfo.h,v
retrieving revision 1.15
diff -u -r1.15 netinfo.h
--- netinfo.h 18 Nov 2003 20:51:50 -0000 1.15
+++ netinfo.h 19 Nov 2003 07:46:48 -0000
@@ -98,6 +98,7 @@
PORTSCAN,
LOOKUP,
FINGER,
+ WHOIS,
NUM_PAGES
};
/* -*- mode:C; indent-tabs-mode:t; tab-width:8; c-basic-offset:8; -*- */
/* gnome-netinfo - A GUI Interface for network utilities
* Copyright (C) 2003 by William Jon McCann
* Copyright (C) 2003 by German Poo-Caaman~o
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <gnome.h>
#include "whois.h"
#include "utils.h"
void
whois_stop (Netinfo * netinfo)
{
g_return_if_fail (netinfo != NULL);
netinfo_stop_process_command (netinfo);
}
void
whois_do (Netinfo * netinfo)
{
GtkTextBuffer *buffer = NULL;
GtkTextIter start, end;
gushort count;
const gchar *host = NULL;
gchar *command = NULL;
gchar *program = NULL;
GtkWidget *parent;
gchar **command_line;
gchar **command_options;
gchar *tmptr;
gint i, j, num_terms;
gchar *command_arg = NULL;
gboolean host_is_set;
g_return_if_fail (netinfo != NULL);
host = netinfo_get_host (netinfo);
host_is_set = (strcmp (host, "") != 0);
if (! host_is_set)
return;
buffer =
gtk_text_view_get_buffer (GTK_TEXT_VIEW (netinfo->output));
gtk_text_buffer_get_start_iter (buffer, &start);
gtk_text_buffer_get_end_iter (buffer, &end);
gtk_text_buffer_delete (buffer, &start, &end);
parent = gtk_widget_get_toplevel (netinfo->output);
program = util_find_program_dialog ("whois", parent);
if (program != NULL) {
if (host_is_set) {
command_arg = g_strdup (host);
}
num_terms = 3;
if (command_arg != NULL)
num_terms++;
command_options = g_strsplit (WHOIS_OPTIONS, " ", -1);
if (command_options != NULL) {
for (j = 0; command_options[j] != NULL; j++)
num_terms++;
}
command_line = g_new (gchar *, num_terms + 1);
i = 0;
command_line[i++] = g_strdup (program);
command_line[i++] = g_strdup ("whois");
if (command_options != NULL) {
for (j = 0; command_options[j] != NULL; j++)
command_line[i++] = g_strdup (command_options[j]);
}
if (command_arg != NULL)
command_line[i++] = g_strdup (command_arg);
command_line[i++] = NULL;
netinfo->command_line = command_line;
netinfo_process_command (netinfo);
g_free (command_arg);
g_strfreev (command_options);
g_strfreev (netinfo->command_line);
}
g_free (command);
g_free (program);
}
/* Process each line from whois command */
void
whois_foreach (Netinfo * netinfo, gchar * line, gint len,
gpointer user_data)
{
gchar *text_utf8;
gssize bytes_written;
GtkWidget *entry = NULL;
GtkTextBuffer *buffer = NULL;
GtkTextIter iter;
g_return_if_fail (netinfo != NULL);
g_return_if_fail (line != NULL);
buffer =
gtk_text_view_get_buffer (GTK_TEXT_VIEW (netinfo->output));
gtk_text_buffer_get_end_iter (buffer, &iter);
if (len > 0) {
text_utf8 = g_locale_to_utf8 (line, len,
NULL, &bytes_written, NULL);
gtk_text_buffer_insert
(GTK_TEXT_BUFFER (buffer), &iter, text_utf8,
bytes_written);
g_free (text_utf8);
}
}
void
whois_copy_to_clipboard (Netinfo * netinfo, gpointer user_data)
{
GtkTextBuffer *buffer = NULL;
GtkTextIter start, end;
gchar *result;
g_return_if_fail (netinfo != NULL);
buffer =
gtk_text_view_get_buffer (GTK_TEXT_VIEW (netinfo->output));
gtk_text_buffer_get_start_iter (buffer, &start);
gtk_text_buffer_get_end_iter (buffer, &end);
result = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
gtk_clipboard_set_text (gtk_clipboard_get (GDK_NONE), result, -1);
g_free (result);
}
/* gnome-netinfo - A GUI Interface for network utilities
* Copyright (C) 2003 by William Jon McCann
* Copyright (C) 2003 by German Poo-Caaman~o
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <gnome.h>
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "netinfo.h"
#define WHOIS_OPTIONS ""
void whois_do (Netinfo *netinfo);
void whois_stop (Netinfo *netinfo);
void whois_foreach (Netinfo * netinfo, gchar * line, gint len, gpointer user_data);
void whois_copy_to_clipboard (Netinfo * netinfo, gpointer user_data);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]