#include <errno.h>
#include <stdlib.h>
#include <locale.h>
+#include <getopt.h>
#include <gtk/gtk.h>
#include "avahi-ui.h"
+typedef enum {
+ COMMAND_HELP,
+ COMMAND_SSH,
+ COMMAND_VNC,
+ COMMAND_SHELL
+} Command;
+
+typedef struct Config {
+ char *domain;
+ Command command;
+} Config;
+
+static void help(FILE *f, const char *argv0) {
+ fprintf(f,
+ _("%s [options]\n\n"
+ " -h --help Show this help\n"
+ " -s --ssh Browse SSH servers\n"
+ " -v --vnc Browse VNC servers\n"
+ " -S --shell Browse both SSH and VNC\n"
+ " -d --domain=DOMAIN The domain to browse in\n"),
+ argv0);
+}
+
+static int parse_command_line(Config *c, int argc, char *argv[]) {
+ int o;
+
+ static const struct option long_options[] = {
+ { "help", no_argument, NULL, 'h' },
+ { "ssh", no_argument, NULL, 's' },
+ { "vnc", no_argument, NULL, 'v' },
+ { "shell", no_argument, NULL, 'S' },
+ { "domain", required_argument, NULL, 'd' },
+ { NULL, 0, NULL, 0 }
+ };
+
+ while ((o = getopt_long(argc, argv, "hVd:svS", long_options, NULL)) >= 0) {
+
+ switch(o) {
+ case 'h':
+ c->command = COMMAND_HELP;
+ break;
+ case 's':
+ c->command = COMMAND_SSH;
+ break;
+ case 'v':
+ c->command = COMMAND_VNC;
+ break;
+ case 'S':
+ c->command = COMMAND_SHELL;
+ break;
+ case 'd':
+ avahi_free(c->domain);
+ c->domain = avahi_strdup(optarg);
+ break;
+ default:
+ return -1;
+ }
+ }
+
+ if (optind < argc) {
+ fprintf(stderr, _("Too many arguments\n"));
+ return -1;
+ }
+
+ return 0;
+}
+
int main(int argc, char*argv[]) {
GtkWidget *d;
+ Config config;
+ const char *argv0;
avahi_init_i18n();
setlocale(LC_ALL, "");
+ if ((argv0 = strrchr(argv[0], '/')))
+ argv0++;
+ else
+ argv0 = argv[0];
+
+ if (g_str_has_suffix(argv[0], "bshell"))
+ config.command = COMMAND_SHELL;
+ else if (g_str_has_suffix(argv[0], "bvnc"))
+ config.command = COMMAND_VNC;
+ else
+ config.command = COMMAND_SSH;
+
+ /* defaults to local */
+ config.domain = NULL;
+
+ if (parse_command_line(&config, argc, argv) < 0) {
+ help(stderr, argv0);
+ return 1;
+ }
+
gtk_init(&argc, &argv);
- if (g_str_has_suffix(argv[0], "bshell")) {
- d = aui_service_dialog_new(_("Choose Shell Server"), NULL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_CONNECT, GTK_RESPONSE_ACCEPT, NULL);
- aui_service_dialog_set_browse_service_types(AUI_SERVICE_DIALOG(d), "_rfb._tcp", "_ssh._tcp", NULL);
- aui_service_dialog_set_service_type_name(AUI_SERVICE_DIALOG(d), "_rfb._tcp", _("Desktop"));
- aui_service_dialog_set_service_type_name(AUI_SERVICE_DIALOG(d), "_ssh._tcp", _("Terminal"));
- } else if (g_str_has_suffix(argv[0], "bvnc")) {
- d = aui_service_dialog_new(_("Choose VNC server"), NULL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_CONNECT, GTK_RESPONSE_ACCEPT, NULL);
- aui_service_dialog_set_browse_service_types(AUI_SERVICE_DIALOG(d), "_rfb._tcp", NULL);
- } else {
- d = aui_service_dialog_new(_("Choose SSH server"), NULL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_CONNECT, GTK_RESPONSE_ACCEPT, NULL);
- aui_service_dialog_set_browse_service_types(AUI_SERVICE_DIALOG(d), "_ssh._tcp", NULL);
+ switch (config.command) {
+ case COMMAND_HELP:
+ help(stdout, argv0);
+ return 0;
+ break;
+
+ case COMMAND_SHELL:
+ d = aui_service_dialog_new(_("Choose Shell Server"), NULL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_CONNECT, GTK_RESPONSE_ACCEPT, NULL);
+ aui_service_dialog_set_browse_service_types(AUI_SERVICE_DIALOG(d), "_rfb._tcp", "_ssh._tcp", NULL);
+ aui_service_dialog_set_service_type_name(AUI_SERVICE_DIALOG(d), "_rfb._tcp", _("Desktop"));
+ aui_service_dialog_set_service_type_name(AUI_SERVICE_DIALOG(d), "_ssh._tcp", _("Terminal"));
+ break;
+
+ case COMMAND_VNC:
+ d = aui_service_dialog_new(_("Choose VNC server"), NULL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_CONNECT, GTK_RESPONSE_ACCEPT, NULL);
+ aui_service_dialog_set_browse_service_types(AUI_SERVICE_DIALOG(d), "_rfb._tcp", NULL);
+ break;
+
+ case COMMAND_SSH:
+ d = aui_service_dialog_new(_("Choose SSH server"), NULL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_CONNECT, GTK_RESPONSE_ACCEPT, NULL);
+ aui_service_dialog_set_browse_service_types(AUI_SERVICE_DIALOG(d), "_ssh._tcp", NULL);
+ break;
}
+ aui_service_dialog_set_domain (AUI_SERVICE_DIALOG(d), config.domain);
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_widget_destroy(d);
- g_print("xvncviewer %s\n", p);
+ g_print("vncviewer %s\n", p);
execlp("xvncviewer", "xvncviewer", p, NULL);
+ execlp("vncviewer", "vncviewer", p, NULL);
} else {
char p[16];
g_print(_("Canceled.\n"));
}
+ g_free(config.domain);
+
return 1;
}
<!-- $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
<cmd>avahi-browse [<arg>options</arg>] <opt>--dump-db</opt></cmd>
<cmd>avahi-browse-domains [<arg>options</arg>]</cmd>
</synopsis>
-
+
<description>
<p>Browse for mDNS/DNS-SD network services and browsing domains using the Avahi daemon.</p>
-
+
</description>
-
+
<options>
<p>Specify a DNS-SD service type (e.g. _http._tcp) to browse for
on the command line, or <opt>-a</opt> to browse for all
available service types. Items that appear on the network are prefixed with "+", items that disappear are prefixed with "-". If <opt>--resolve</opt> is passed items that are resolved are prefixed with "=".</p>
-
+
<option>
<p><opt>-a | --all</opt></p>
<optdesc><p>Browse for all service types registered on the LAN, not just the one specified on the command line.</p></optdesc>
</option>
</options>
-
+
<section name="Authors">
<p>The Avahi Developers <@PACKAGE_BUGREPORT@>; Avahi is
available from <url href="@PACKAGE_URL@"/></p>
</section>
-
+
<section name="See also">
<p>
<manref name="avahi-publish" section="1"/>, <manref name="avahi-resolve" section="1"/>, <manref name="avahi-daemon" section="8"/>
</p>
</section>
-
+
<section name="Comments">
<p>This man page was written using <manref name="xml2man" section="1"
href="http://masqmail.cx/xml2man/"/> by Oliver Kurth.</p>
</section>
-
+
</manpage>
<!-- $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.
-->
- <manpage name="bssh/bvnc" section="1" desc="Browse for SSH/VNC servers on the local network">
+ <manpage name="bssh/bvnc/bshell" section="1" desc="Browse for SSH/VNC servers on the local network">
<synopsis>
<cmd>bssh</cmd>
<cmd>bvnc</cmd>
+ <cmd>bshell</cmd>
</synopsis>
-
+
<description>
- <p>bssh/bvnc browses for local SSH/VNC servers on the local
+ <p>bssh/bvnc/bshell browses for SSH/VNC servers on the local
network, shows them in a GUI for the user to select one and
- finally calls ssh/xvncviewer after a selection was made.</p>
-
+ finally calls ssh/vncviewer after a selection was made.</p>
+
+ <p>If the binary is called as bssh only ssh servers will be shown. If the binary is called as bvnc only VNC servers will be shown. If the binary is called as bshell both VNC and SSH servers are shown.</p>
+
</description>
-
+
<options>
- <p>bssh/bvnc takes no command line arguments at the moment.</p>
+ <option>
+ <p><opt>-s | --ssh</opt></p>
+ <optdesc><p>Browse for SSH servers (and only SSH servers) regardless under which name the binary is called.</p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-v | --vnc</opt></p>
+ <optdesc><p>Browse for VNC servers (and only VNC servers) regardless under which name the binary is called.</p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-S | --shell</opt></p>
+ <optdesc><p>Browse for both VNC and SSH servers regardless under which name the binary is called.</p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-d | --domain=</opt> <arg>DOMAIN</arg></p>
+ <optdesc><p>Browse in the specified domain. If omitted
+ bssh/bvnc/bshell will browse in the default browsing domain
+ (usually .local)</p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-h | --help</opt></p>
+ <optdesc><p>Show help.</p></optdesc>
+ </option>
</options>
-
+
<section name="Authors">
<p>The Avahi Developers <@PACKAGE_BUGREPORT@>; Avahi is
available from <url href="@PACKAGE_URL@"/></p>
</section>
-
+
<section name="See also">
<p>
- <manref name="avahi-browse" section="1"/>, <manref name="ssh" section="1"/>, <manref name="xvncviewer" section="1"/>
+ <manref name="avahi-browse" section="1"/>, <manref name="ssh" section="1"/>, <manref name="vncviewer" section="1"/>
</p>
</section>
-
+
<section name="Comments">
<p>This man page was written using <manref name="xml2man" section="1"
href="http://masqmail.cx/xml2man/"/> by Oliver Kurth.</p>
</section>
-
+
</manpage>