From: Sebastien Estienne Date: Thu, 4 Aug 2005 00:57:03 +0000 (+0000) Subject: * renamed avahi-discover to avahi-discover-standalone X-Git-Url: http://git.meshlink.io/?p=catta;a=commitdiff_plain;h=3bf52c1e00fd8cf4850329adb4f76c3c2649df79 * renamed avahi-discover to avahi-discover-standalone * install python avahi-discover * added missing file acinclude.m4 git-svn-id: file:///home/lennart/svn/public/avahi/trunk@225 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- diff --git a/Makefile.am b/Makefile.am index 874b9fc..a8b50d1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,7 +22,7 @@ ACLOCAL_AMFLAGS = -I common include $(srcdir)/common/doxygen.mk EXTRA_DIST = bootstrap.sh LICENSE $(DX_CONFIG) -SUBDIRS = common avahi-common avahi-core avahi-discover avahi-client avahi-daemon initscript avahi-dnsconfd avahi-utils examples +SUBDIRS = common avahi-common avahi-core avahi-discover-standalone avahi-client avahi-daemon initscript avahi-dnsconfd avahi-utils examples pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = avahi-core.pc diff --git a/acinclude.m4 b/acinclude.m4 new file mode 100644 index 0000000..4d07999 --- /dev/null +++ b/acinclude.m4 @@ -0,0 +1 @@ +sinclude(common/doxygen.m4) \ No newline at end of file diff --git a/avahi-discover-standalone/Makefile.am b/avahi-discover-standalone/Makefile.am new file mode 100644 index 0000000..2d3ddaf --- /dev/null +++ b/avahi-discover-standalone/Makefile.am @@ -0,0 +1,46 @@ +# $Id$ +# +# This file is part of avahi. +# +# avahi is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# avahi 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 Lesser General Public +# License along with avahi; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. + +AM_CFLAGS=-I$(top_srcdir) \ + -DAVAHI_INTERFACES_DIR=\"$(interfacesdir)\" + +AM_CFLAGS+=$(GLIB20_CFLAGS) $(GTK20_CFLAGS) $(GLADE20_CFLAGS) +AM_LDADD=$(GLIB20_LIBS) $(GTK20_LIBS) $(GLADE20_LIBS) + +# This cool debug trap works on i386/gcc only +AM_CFLAGS+='-DDEBUG_TRAP=__asm__("int $$3")' + +if ENABLE_GTK +bin_PROGRAMS = \ + avahi-discover-standalone + +avahi_discover_standalone_SOURCES = \ + main.c + +avahi_discover_standalone_CFLAGS = $(AM_CFLAGS) +avahi_discover_standalone_LDADD = $(AM_LDADD) ../avahi-core/libavahi-core.la ../avahi-common/libavahi-common.la + +interfaces = \ + avahi-discover.glade + +interfaces_DATA = $(interfaces) + +EXTRA_DIST = \ + $(interfaces) +endif diff --git a/avahi-discover-standalone/avahi-discover.glade b/avahi-discover-standalone/avahi-discover.glade new file mode 100644 index 0000000..ca6b51f --- /dev/null +++ b/avahi-discover-standalone/avahi-discover.glade @@ -0,0 +1,90 @@ + + + + + + + True + Avahi Discovery + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + 500 + 400 + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST + True + + + + 12 + True + False + 12 + + + + True + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + True + False + False + True + False + False + False + + + + + + 0 + True + True + + + + + + True + True + <i>No service currently selected.</i> + False + True + GTK_JUSTIFY_LEFT + False + True + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + + diff --git a/avahi-discover-standalone/avahi-discover.gladep b/avahi-discover-standalone/avahi-discover.gladep new file mode 100644 index 0000000..a9feaa6 --- /dev/null +++ b/avahi-discover-standalone/avahi-discover.gladep @@ -0,0 +1,8 @@ + + + + + Avahi-discover + avahi-discover + FALSE + diff --git a/avahi-discover-standalone/main.c b/avahi-discover-standalone/main.c new file mode 100644 index 0000000..daecdaa --- /dev/null +++ b/avahi-discover-standalone/main.c @@ -0,0 +1,306 @@ +/* $Id$ */ + +/*** + This file is part of avahi. + + avahi is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + avahi 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 Lesser General + Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with avahi; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include +#include +#include +#include +#include + +struct ServiceType; + +struct Service { + struct ServiceType *service_type; + gchar *service_name; + gchar *domain_name; + + AvahiIfIndex interface; + AvahiProtocol protocol; + + GtkTreeRowReference *tree_ref; +}; + +struct ServiceType { + gchar *service_type; + AvahiServiceBrowser *browser; + + GList *services; + GtkTreeRowReference *tree_ref; +}; + +static GtkWidget *main_window = NULL; +static GtkTreeView *tree_view = NULL; +static GtkTreeStore *tree_store = NULL; +static GtkLabel *info_label = NULL; +static AvahiServer *server = NULL; +static AvahiServiceTypeBrowser *service_type_browser = NULL; +static GHashTable *service_type_hash_table = NULL; +static AvahiServiceResolver *service_resolver = NULL; +static struct Service *current_service = NULL; + +static struct Service *get_service(const gchar *service_type, const gchar *service_name, const gchar*domain_name, AvahiIfIndex interface, AvahiProtocol protocol) { + struct ServiceType *st; + GList *l; + + if (!(st = g_hash_table_lookup(service_type_hash_table, service_type))) + return NULL; + + for (l = st->services; l; l = l->next) { + struct Service *s = l->data; + + if (s->interface == interface && + s->protocol == protocol && + avahi_domain_equal(s->service_name, service_name) && + avahi_domain_equal(s->domain_name, domain_name)) + return s; + } + + return NULL; +} + +static void free_service(struct Service *s) { + GtkTreeIter iter; + GtkTreePath *path; + + if (current_service == s) { + current_service = NULL; + + if (service_resolver) { + avahi_service_resolver_free(service_resolver); + service_resolver = NULL; + } + + gtk_label_set_text(info_label, "Service removed"); + } + + s->service_type->services = g_list_remove(s->service_type->services, s); + + path = gtk_tree_row_reference_get_path(s->tree_ref); + gtk_tree_model_get_iter(GTK_TREE_MODEL(tree_store), &iter, path); + gtk_tree_path_free(path); + + gtk_tree_store_remove(tree_store, &iter); + + gtk_tree_row_reference_free(s->tree_ref); + + g_free(s->service_name); + g_free(s->domain_name); + g_free(s); +} + +static void service_browser_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const gchar *service_name, const gchar *service_type, const gchar *domain_name, gpointer userdata) { + + if (event == AVAHI_BROWSER_NEW) { + struct Service *s; + GtkTreeIter iter, piter; + GtkTreePath *path, *ppath; + gchar iface[256]; + + s = g_new(struct Service, 1); + s->service_name = g_strdup(service_name); + s->domain_name = g_strdup(domain_name); + s->interface = interface; + s->protocol = protocol; + s->service_type = g_hash_table_lookup(service_type_hash_table, service_type); + g_assert(s->service_type); + + s->service_type->services = g_list_prepend(s->service_type->services, s); + + ppath = gtk_tree_row_reference_get_path(s->service_type->tree_ref); + gtk_tree_model_get_iter(GTK_TREE_MODEL(tree_store), &piter, ppath); + + snprintf(iface, sizeof(iface), "#%i %s", interface, protocol == AF_INET ? "IPv4" : "IPv6"); + + gtk_tree_store_append(tree_store, &iter, &piter); + gtk_tree_store_set(tree_store, &iter, 0, s->service_name, 1, iface, 2, s, -1); + + path = gtk_tree_model_get_path(GTK_TREE_MODEL(tree_store), &iter); + s->tree_ref = gtk_tree_row_reference_new(GTK_TREE_MODEL(tree_store), path); + gtk_tree_path_free(path); + + gtk_tree_view_expand_row(tree_view, ppath, FALSE); + gtk_tree_path_free(ppath); + + + } else if (event == AVAHI_BROWSER_REMOVE) { + struct Service* s; + + if ((s = get_service(service_type, service_name, domain_name, interface, protocol))) + free_service(s); + } +} + +static void service_type_browser_callback(AvahiServiceTypeBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const gchar *service_type, const gchar *domain, gpointer userdata) { + struct ServiceType *st; + GtkTreePath *path; + GtkTreeIter iter; + + if (event != AVAHI_BROWSER_NEW) + return; + + if (g_hash_table_lookup(service_type_hash_table, service_type)) + return; + + st = g_new(struct ServiceType, 1); + st->service_type = g_strdup(service_type); + st->services = NULL; + + gtk_tree_store_append(tree_store, &iter, NULL); + gtk_tree_store_set(tree_store, &iter, 0, st->service_type, 1, "", 2, NULL, -1); + + path = gtk_tree_model_get_path(GTK_TREE_MODEL(tree_store), &iter); + st->tree_ref = gtk_tree_row_reference_new(GTK_TREE_MODEL(tree_store), path); + gtk_tree_path_free(path); + + g_hash_table_insert(service_type_hash_table, st->service_type, st); + + st->browser = avahi_service_browser_new(server, -1, AF_UNSPEC, st->service_type, domain, service_browser_callback, NULL); +} + +static void update_label(struct Service *s, const gchar *hostname, const AvahiAddress *a, guint16 port, AvahiStringList *txt) { + gchar t[512], address[64], *txt_s; + + if (a && hostname) { + char na[256]; + avahi_address_snprint(na, sizeof(na), a); + snprintf(address, sizeof(address), "%s/%s:%u", hostname, na, port); + txt_s = avahi_string_list_to_string(txt); + } else { + snprintf(address, sizeof(address), "n/a"); + txt_s = g_strdup("n/a"); + } + + snprintf(t, sizeof(t), + "Service Type: %s\n" + "Service Name: %s\n" + "Domain Name: %s\n" + "Interface: %i %s\n" + "Address: %s\n" + "TXT Data: %s", + s->service_type->service_type, + s->service_name, + s->domain_name, + s->interface, + s->protocol == AF_INET ? "IPv4" : "IPv6", + address, + txt_s); + + gtk_label_set_markup(info_label, t); + + g_free(txt_s); +} + +static struct Service *get_service_on_cursor(void) { + GtkTreePath *path; + struct Service *s; + GtkTreeIter iter; + + gtk_tree_view_get_cursor(tree_view, &path, NULL); + gtk_tree_model_get_iter(GTK_TREE_MODEL(tree_store), &iter, path); + gtk_tree_model_get(GTK_TREE_MODEL(tree_store), &iter, 2, &s, -1); + gtk_tree_path_free(path); + + return s; +} + + +static void service_resolver_callback(AvahiServiceResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const gchar *name, const gchar *type, const gchar *domain, const gchar *host_name, const AvahiAddress *a, guint16 port, AvahiStringList *txt, gpointer userdata) { + struct Service *s; + g_assert(r); + + if (!(s = get_service_on_cursor()) || userdata != s) { + g_assert(r == service_resolver); + avahi_service_resolver_free(service_resolver); + service_resolver = NULL; + } + + if (event == AVAHI_RESOLVER_TIMEOUT) + gtk_label_set_markup(info_label, "Failed to resolve."); + else + update_label(s, host_name, a, port, txt); +} + +static void tree_view_on_cursor_changed(GtkTreeView *tv, gpointer userdata) { + struct Service *s; + + if (!(s = get_service_on_cursor())) + return; + + if (service_resolver) + avahi_service_resolver_free(service_resolver); + + update_label(s, NULL, NULL, 0, NULL); + + service_resolver = avahi_service_resolver_new(server, s->interface, s->protocol, s->service_name, s->service_type->service_type, s->domain_name, AF_UNSPEC, service_resolver_callback, s); +} + +static gboolean main_window_on_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data) { + gtk_main_quit(); + return FALSE; +} + +int main(int argc, char *argv[]) { + GladeXML *xml; + AvahiServerConfig config; + GtkTreeViewColumn *c; + + gtk_init(&argc, &argv); + glade_init(); + + xml = glade_xml_new(AVAHI_INTERFACES_DIR"avahi-discover.glade", NULL, NULL); + main_window = glade_xml_get_widget(xml, "main_window"); + g_signal_connect(main_window, "delete-event", (GCallback) main_window_on_delete_event, NULL); + + tree_view = GTK_TREE_VIEW(glade_xml_get_widget(xml, "tree_view")); + g_signal_connect(GTK_WIDGET(tree_view), "cursor-changed", (GCallback) tree_view_on_cursor_changed, NULL); + + info_label = GTK_LABEL(glade_xml_get_widget(xml, "info_label")); + + tree_store = gtk_tree_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); + gtk_tree_view_set_model(tree_view, GTK_TREE_MODEL(tree_store)); + gtk_tree_view_insert_column_with_attributes(tree_view, -1, "Name", gtk_cell_renderer_text_new(), "text", 0, NULL); + gtk_tree_view_insert_column_with_attributes(tree_view, -1, "Interface", gtk_cell_renderer_text_new(), "text", 1, NULL); + + gtk_tree_view_column_set_resizable(c = gtk_tree_view_get_column(tree_view, 0), TRUE); + gtk_tree_view_column_set_sizing(c, GTK_TREE_VIEW_COLUMN_GROW_ONLY); + gtk_tree_view_column_set_expand(c, TRUE); + + service_type_hash_table = g_hash_table_new((GHashFunc) avahi_domain_hash, (GEqualFunc) avahi_domain_equal); + + avahi_server_config_init(&config); + config.publish_hinfo = config.publish_addresses = config.publish_domain = config.publish_workstation = FALSE; + server = avahi_server_new(NULL, &config, NULL, NULL); + avahi_server_config_free(&config); + + service_type_browser = avahi_service_type_browser_new(server, -1, AF_UNSPEC, argc >= 2 ? argv[1] : NULL, service_type_browser_callback, NULL); + + gtk_main(); + + avahi_server_free(server); + + return 0; +} diff --git a/avahi-discover/Makefile.am b/avahi-discover/Makefile.am deleted file mode 100644 index 7890522..0000000 --- a/avahi-discover/Makefile.am +++ /dev/null @@ -1,46 +0,0 @@ -# $Id$ -# -# This file is part of avahi. -# -# avahi is free software; you can redistribute it and/or modify it -# under the terms of the GNU Lesser General Public License as -# published by the Free Software Foundation; either version 2 of the -# License, or (at your option) any later version. -# -# avahi 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 Lesser General Public -# License along with avahi; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 -# USA. - -AM_CFLAGS=-I$(top_srcdir) \ - -DAVAHI_INTERFACES_DIR=\"$(interfacesdir)\" - -AM_CFLAGS+=$(GLIB20_CFLAGS) $(GTK20_CFLAGS) $(GLADE20_CFLAGS) -AM_LDADD=$(GLIB20_LIBS) $(GTK20_LIBS) $(GLADE20_LIBS) - -# This cool debug trap works on i386/gcc only -AM_CFLAGS+='-DDEBUG_TRAP=__asm__("int $$3")' - -if ENABLE_GTK -bin_PROGRAMS = \ - avahi-discover - -avahi_discover_SOURCES = \ - main.c - -avahi_discover_CFLAGS = $(AM_CFLAGS) -avahi_discover_LDADD = $(AM_LDADD) ../avahi-core/libavahi-core.la ../avahi-common/libavahi-common.la - -interfaces = \ - avahi-discover.glade - -interfaces_DATA = $(interfaces) - -EXTRA_DIST = \ - $(interfaces) -endif diff --git a/avahi-discover/avahi-discover.glade b/avahi-discover/avahi-discover.glade deleted file mode 100644 index ca6b51f..0000000 --- a/avahi-discover/avahi-discover.glade +++ /dev/null @@ -1,90 +0,0 @@ - - - - - - - True - Avahi Discovery - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - 500 - 400 - True - False - True - False - False - GDK_WINDOW_TYPE_HINT_NORMAL - GDK_GRAVITY_NORTH_WEST - True - - - - 12 - True - False - 12 - - - - True - True - GTK_POLICY_AUTOMATIC - GTK_POLICY_AUTOMATIC - GTK_SHADOW_IN - GTK_CORNER_TOP_LEFT - - - - True - True - True - False - False - True - False - False - False - - - - - - 0 - True - True - - - - - - True - True - <i>No service currently selected.</i> - False - True - GTK_JUSTIFY_LEFT - False - True - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - - diff --git a/avahi-discover/avahi-discover.gladep b/avahi-discover/avahi-discover.gladep deleted file mode 100644 index a9feaa6..0000000 --- a/avahi-discover/avahi-discover.gladep +++ /dev/null @@ -1,8 +0,0 @@ - - - - - Avahi-discover - avahi-discover - FALSE - diff --git a/avahi-discover/main.c b/avahi-discover/main.c deleted file mode 100644 index daecdaa..0000000 --- a/avahi-discover/main.c +++ /dev/null @@ -1,306 +0,0 @@ -/* $Id$ */ - -/*** - This file is part of avahi. - - avahi is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of the - License, or (at your option) any later version. - - avahi 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 Lesser General - Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with avahi; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - USA. -***/ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - -#include -#include -#include -#include -#include - -struct ServiceType; - -struct Service { - struct ServiceType *service_type; - gchar *service_name; - gchar *domain_name; - - AvahiIfIndex interface; - AvahiProtocol protocol; - - GtkTreeRowReference *tree_ref; -}; - -struct ServiceType { - gchar *service_type; - AvahiServiceBrowser *browser; - - GList *services; - GtkTreeRowReference *tree_ref; -}; - -static GtkWidget *main_window = NULL; -static GtkTreeView *tree_view = NULL; -static GtkTreeStore *tree_store = NULL; -static GtkLabel *info_label = NULL; -static AvahiServer *server = NULL; -static AvahiServiceTypeBrowser *service_type_browser = NULL; -static GHashTable *service_type_hash_table = NULL; -static AvahiServiceResolver *service_resolver = NULL; -static struct Service *current_service = NULL; - -static struct Service *get_service(const gchar *service_type, const gchar *service_name, const gchar*domain_name, AvahiIfIndex interface, AvahiProtocol protocol) { - struct ServiceType *st; - GList *l; - - if (!(st = g_hash_table_lookup(service_type_hash_table, service_type))) - return NULL; - - for (l = st->services; l; l = l->next) { - struct Service *s = l->data; - - if (s->interface == interface && - s->protocol == protocol && - avahi_domain_equal(s->service_name, service_name) && - avahi_domain_equal(s->domain_name, domain_name)) - return s; - } - - return NULL; -} - -static void free_service(struct Service *s) { - GtkTreeIter iter; - GtkTreePath *path; - - if (current_service == s) { - current_service = NULL; - - if (service_resolver) { - avahi_service_resolver_free(service_resolver); - service_resolver = NULL; - } - - gtk_label_set_text(info_label, "Service removed"); - } - - s->service_type->services = g_list_remove(s->service_type->services, s); - - path = gtk_tree_row_reference_get_path(s->tree_ref); - gtk_tree_model_get_iter(GTK_TREE_MODEL(tree_store), &iter, path); - gtk_tree_path_free(path); - - gtk_tree_store_remove(tree_store, &iter); - - gtk_tree_row_reference_free(s->tree_ref); - - g_free(s->service_name); - g_free(s->domain_name); - g_free(s); -} - -static void service_browser_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const gchar *service_name, const gchar *service_type, const gchar *domain_name, gpointer userdata) { - - if (event == AVAHI_BROWSER_NEW) { - struct Service *s; - GtkTreeIter iter, piter; - GtkTreePath *path, *ppath; - gchar iface[256]; - - s = g_new(struct Service, 1); - s->service_name = g_strdup(service_name); - s->domain_name = g_strdup(domain_name); - s->interface = interface; - s->protocol = protocol; - s->service_type = g_hash_table_lookup(service_type_hash_table, service_type); - g_assert(s->service_type); - - s->service_type->services = g_list_prepend(s->service_type->services, s); - - ppath = gtk_tree_row_reference_get_path(s->service_type->tree_ref); - gtk_tree_model_get_iter(GTK_TREE_MODEL(tree_store), &piter, ppath); - - snprintf(iface, sizeof(iface), "#%i %s", interface, protocol == AF_INET ? "IPv4" : "IPv6"); - - gtk_tree_store_append(tree_store, &iter, &piter); - gtk_tree_store_set(tree_store, &iter, 0, s->service_name, 1, iface, 2, s, -1); - - path = gtk_tree_model_get_path(GTK_TREE_MODEL(tree_store), &iter); - s->tree_ref = gtk_tree_row_reference_new(GTK_TREE_MODEL(tree_store), path); - gtk_tree_path_free(path); - - gtk_tree_view_expand_row(tree_view, ppath, FALSE); - gtk_tree_path_free(ppath); - - - } else if (event == AVAHI_BROWSER_REMOVE) { - struct Service* s; - - if ((s = get_service(service_type, service_name, domain_name, interface, protocol))) - free_service(s); - } -} - -static void service_type_browser_callback(AvahiServiceTypeBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const gchar *service_type, const gchar *domain, gpointer userdata) { - struct ServiceType *st; - GtkTreePath *path; - GtkTreeIter iter; - - if (event != AVAHI_BROWSER_NEW) - return; - - if (g_hash_table_lookup(service_type_hash_table, service_type)) - return; - - st = g_new(struct ServiceType, 1); - st->service_type = g_strdup(service_type); - st->services = NULL; - - gtk_tree_store_append(tree_store, &iter, NULL); - gtk_tree_store_set(tree_store, &iter, 0, st->service_type, 1, "", 2, NULL, -1); - - path = gtk_tree_model_get_path(GTK_TREE_MODEL(tree_store), &iter); - st->tree_ref = gtk_tree_row_reference_new(GTK_TREE_MODEL(tree_store), path); - gtk_tree_path_free(path); - - g_hash_table_insert(service_type_hash_table, st->service_type, st); - - st->browser = avahi_service_browser_new(server, -1, AF_UNSPEC, st->service_type, domain, service_browser_callback, NULL); -} - -static void update_label(struct Service *s, const gchar *hostname, const AvahiAddress *a, guint16 port, AvahiStringList *txt) { - gchar t[512], address[64], *txt_s; - - if (a && hostname) { - char na[256]; - avahi_address_snprint(na, sizeof(na), a); - snprintf(address, sizeof(address), "%s/%s:%u", hostname, na, port); - txt_s = avahi_string_list_to_string(txt); - } else { - snprintf(address, sizeof(address), "n/a"); - txt_s = g_strdup("n/a"); - } - - snprintf(t, sizeof(t), - "Service Type: %s\n" - "Service Name: %s\n" - "Domain Name: %s\n" - "Interface: %i %s\n" - "Address: %s\n" - "TXT Data: %s", - s->service_type->service_type, - s->service_name, - s->domain_name, - s->interface, - s->protocol == AF_INET ? "IPv4" : "IPv6", - address, - txt_s); - - gtk_label_set_markup(info_label, t); - - g_free(txt_s); -} - -static struct Service *get_service_on_cursor(void) { - GtkTreePath *path; - struct Service *s; - GtkTreeIter iter; - - gtk_tree_view_get_cursor(tree_view, &path, NULL); - gtk_tree_model_get_iter(GTK_TREE_MODEL(tree_store), &iter, path); - gtk_tree_model_get(GTK_TREE_MODEL(tree_store), &iter, 2, &s, -1); - gtk_tree_path_free(path); - - return s; -} - - -static void service_resolver_callback(AvahiServiceResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const gchar *name, const gchar *type, const gchar *domain, const gchar *host_name, const AvahiAddress *a, guint16 port, AvahiStringList *txt, gpointer userdata) { - struct Service *s; - g_assert(r); - - if (!(s = get_service_on_cursor()) || userdata != s) { - g_assert(r == service_resolver); - avahi_service_resolver_free(service_resolver); - service_resolver = NULL; - } - - if (event == AVAHI_RESOLVER_TIMEOUT) - gtk_label_set_markup(info_label, "Failed to resolve."); - else - update_label(s, host_name, a, port, txt); -} - -static void tree_view_on_cursor_changed(GtkTreeView *tv, gpointer userdata) { - struct Service *s; - - if (!(s = get_service_on_cursor())) - return; - - if (service_resolver) - avahi_service_resolver_free(service_resolver); - - update_label(s, NULL, NULL, 0, NULL); - - service_resolver = avahi_service_resolver_new(server, s->interface, s->protocol, s->service_name, s->service_type->service_type, s->domain_name, AF_UNSPEC, service_resolver_callback, s); -} - -static gboolean main_window_on_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data) { - gtk_main_quit(); - return FALSE; -} - -int main(int argc, char *argv[]) { - GladeXML *xml; - AvahiServerConfig config; - GtkTreeViewColumn *c; - - gtk_init(&argc, &argv); - glade_init(); - - xml = glade_xml_new(AVAHI_INTERFACES_DIR"avahi-discover.glade", NULL, NULL); - main_window = glade_xml_get_widget(xml, "main_window"); - g_signal_connect(main_window, "delete-event", (GCallback) main_window_on_delete_event, NULL); - - tree_view = GTK_TREE_VIEW(glade_xml_get_widget(xml, "tree_view")); - g_signal_connect(GTK_WIDGET(tree_view), "cursor-changed", (GCallback) tree_view_on_cursor_changed, NULL); - - info_label = GTK_LABEL(glade_xml_get_widget(xml, "info_label")); - - tree_store = gtk_tree_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); - gtk_tree_view_set_model(tree_view, GTK_TREE_MODEL(tree_store)); - gtk_tree_view_insert_column_with_attributes(tree_view, -1, "Name", gtk_cell_renderer_text_new(), "text", 0, NULL); - gtk_tree_view_insert_column_with_attributes(tree_view, -1, "Interface", gtk_cell_renderer_text_new(), "text", 1, NULL); - - gtk_tree_view_column_set_resizable(c = gtk_tree_view_get_column(tree_view, 0), TRUE); - gtk_tree_view_column_set_sizing(c, GTK_TREE_VIEW_COLUMN_GROW_ONLY); - gtk_tree_view_column_set_expand(c, TRUE); - - service_type_hash_table = g_hash_table_new((GHashFunc) avahi_domain_hash, (GEqualFunc) avahi_domain_equal); - - avahi_server_config_init(&config); - config.publish_hinfo = config.publish_addresses = config.publish_domain = config.publish_workstation = FALSE; - server = avahi_server_new(NULL, &config, NULL, NULL); - avahi_server_config_free(&config); - - service_type_browser = avahi_service_type_browser_new(server, -1, AF_UNSPEC, argc >= 2 ? argv[1] : NULL, service_type_browser_callback, NULL); - - gtk_main(); - - avahi_server_free(server); - - return 0; -} diff --git a/avahi-utils/Makefile.am b/avahi-utils/Makefile.am index 64781d2..c2c7842 100644 --- a/avahi-utils/Makefile.am +++ b/avahi-utils/Makefile.am @@ -20,7 +20,11 @@ SUBDIRS=avahi if HAVE_PYTHON -bin_SCRIPTS = avahi-publish-address avahi-publish-service avahi-dump-all +bin_SCRIPTS = \ + avahi-publish-address \ + avahi-publish-service \ + avahi-dump-all \ + avahi-discover endif CLEANFILES = $(bin_SCRIPTS) diff --git a/configure.ac b/configure.ac index 4d12a0c..dee7593 100644 --- a/configure.ac +++ b/configure.ac @@ -278,7 +278,7 @@ avahi-common/Makefile avahi-core/Makefile avahi-daemon/Makefile avahi-daemon/avahi-dbus.conf -avahi-discover/Makefile +avahi-discover-standalone/Makefile avahi-client/Makefile initscript/Makefile initscript/Debian/Makefile