From 9bc5ec96ade0b798a0b237ac2b081df37df125c1 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 7 Feb 2007 10:52:09 +0000 Subject: [PATCH] overload zssh to zvnc git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1389 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-ui/Makefile.am | 5 +++ avahi-ui/zssh.c | 72 +++++++++++++++++++++++++++++--------------- 2 files changed, 52 insertions(+), 25 deletions(-) diff --git a/avahi-ui/Makefile.am b/avahi-ui/Makefile.am index b7a2edf..854eacf 100644 --- a/avahi-ui/Makefile.am +++ b/avahi-ui/Makefile.am @@ -56,5 +56,10 @@ zssh_SOURCES = zssh.c zssh_CFLAGS = $(AM_CFLAGS) $(GTK20_CFLAGS) zssh_LDADD = $(AM_LDADD) $(GTK20_LIBS) ../avahi-client/libavahi-client.la ../avahi-common/libavahi-common.la libavahi-ui.la +install-exec-local: + cd $(DESTDIR)/$(bindir) && \ + rm -f zvnc && \ + $(LN_S) zssh zvnc + endif endif diff --git a/avahi-ui/zssh.c b/avahi-ui/zssh.c index 12b78bf..e4cf16e 100644 --- a/avahi-ui/zssh.c +++ b/avahi-ui/zssh.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "avahi-ui.h" @@ -39,53 +40,74 @@ int main(int argc, char*argv[]) { GtkWidget *d; gtk_init(&argc, &argv); - - d = aui_service_dialog_new("Choose SSH server"); - aui_service_dialog_set_browse_service_types(AUI_SERVICE_DIALOG(d), "_ssh._tcp", /*"_ftp._tcp", "_http._tcp",*/ NULL); + + if (g_str_has_suffix(argv[0], "zvnc")) { + d = aui_service_dialog_new("Choose VNC server"); + aui_service_dialog_set_browse_service_types(AUI_SERVICE_DIALOG(d), "_rfb._tcp", NULL); + } else { + d = aui_service_dialog_new("Choose SSH server"); + aui_service_dialog_set_browse_service_types(AUI_SERVICE_DIALOG(d), "_ssh._tcp", NULL); + } + aui_service_dialog_set_resolve_service(AUI_SERVICE_DIALOG(d), TRUE); aui_service_dialog_set_resolve_host_name(AUI_SERVICE_DIALOG(d), !avahi_nss_support()); gtk_window_present(GTK_WINDOW(d)); if (gtk_dialog_run(GTK_DIALOG(d)) == GTK_RESPONSE_OK) { - char p[16], a[AVAHI_ADDRESS_STR_MAX], *u = NULL; - char *h = NULL; + char a[AVAHI_ADDRESS_STR_MAX], *u = NULL; + char *h = NULL, *t = NULL; const AvahiStringList *txt; - snprintf(p, sizeof(p), "%u", aui_service_dialog_get_port(AUI_SERVICE_DIALOG(d))); - + t = g_strdup(aui_service_dialog_get_service_type(AUI_SERVICE_DIALOG(d))); + if (avahi_nss_support()) h = g_strdup(aui_service_dialog_get_host_name(AUI_SERVICE_DIALOG(d))); else h = g_strdup(avahi_address_snprint(a, sizeof(a), aui_service_dialog_get_address(AUI_SERVICE_DIALOG(d)))); + + if (avahi_domain_equal(t, "_rfb._tcp")) { + char p[AVAHI_DOMAIN_NAME_MAX+16]; + snprintf(p, sizeof(p), "%s:%u", h, aui_service_dialog_get_port(AUI_SERVICE_DIALOG(d))-5900); - for (txt = aui_service_dialog_get_txt_data(AUI_SERVICE_DIALOG(d)); txt; txt = txt->next) { - char *key, *value; + gtk_widget_destroy(d); - if (avahi_string_list_get_pair((AvahiStringList*) txt, &key, &value, NULL) < 0) - break; - - if (strcmp(key, "u") == 0) - u = g_strdup(value); + g_print("xvncviewer %s\n", p); + execlp("xvncviewer", "xvncviewer", p, NULL); - avahi_free(key); - avahi_free(value); - } - - gtk_widget_destroy(d); - - if (u) { - g_print("ssh -p %s -l %s %s\n", p, u, h); - execlp("ssh", "ssh", "-p", p, "-l", u, h, NULL); } else { - g_print("ssh -p %s %s\n", p, h); - execlp("ssh", "ssh", "-p", p, h, NULL); + char p[16]; + snprintf(p, sizeof(p), "%u", aui_service_dialog_get_port(AUI_SERVICE_DIALOG(d))); + + for (txt = aui_service_dialog_get_txt_data(AUI_SERVICE_DIALOG(d)); txt; txt = txt->next) { + char *key, *value; + + if (avahi_string_list_get_pair((AvahiStringList*) txt, &key, &value, NULL) < 0) + break; + + if (strcmp(key, "u") == 0) + u = g_strdup(value); + + avahi_free(key); + avahi_free(value); + } + + gtk_widget_destroy(d); + + if (u) { + g_print("ssh -p %s -l %s %s\n", p, u, h); + execlp("ssh", "ssh", "-p", p, "-l", u, h, NULL); + } else { + g_print("ssh -p %s %s\n", p, h); + execlp("ssh", "ssh", "-p", p, h, NULL); + } } g_warning("execlp() failed: %s", strerror(errno)); g_free(h); g_free(u); + g_free(t); } else { gtk_widget_destroy(d); -- 2.39.5