From 3025a26988fe2de9d14867056c945e20f490ec1e Mon Sep 17 00:00:00 2001 From: James Willcox Date: Thu, 19 Apr 2007 21:01:45 +0000 Subject: [PATCH] add avahi-ui-sharp git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1444 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-ui-sharp/Makefile.am | 65 +++++ avahi-ui-sharp/ServiceDialog.cs | 238 +++++++++++++++++++ avahi-ui-sharp/avahi-ui-sharp-docs.source | 4 + avahi-ui-sharp/avahi-ui-sharp.dll.config.in | 4 + avahi-ui-sharp/en/Avahi.UI.xml | 6 + avahi-ui-sharp/en/Avahi.UI/ServiceDialog.xml | 171 +++++++++++++ avahi-ui-sharp/en/index.xml | 13 + avahi-ui-sharp/gencfg.sh | 6 + avahi-ui-sharp/zssh.cs | 37 +++ configure.ac | 1 + 10 files changed, 545 insertions(+) create mode 100644 avahi-ui-sharp/Makefile.am create mode 100644 avahi-ui-sharp/ServiceDialog.cs create mode 100644 avahi-ui-sharp/avahi-ui-sharp-docs.source create mode 100644 avahi-ui-sharp/avahi-ui-sharp.dll.config.in create mode 100644 avahi-ui-sharp/en/Avahi.UI.xml create mode 100644 avahi-ui-sharp/en/Avahi.UI/ServiceDialog.xml create mode 100644 avahi-ui-sharp/en/index.xml create mode 100755 avahi-ui-sharp/gencfg.sh create mode 100644 avahi-ui-sharp/zssh.cs diff --git a/avahi-ui-sharp/Makefile.am b/avahi-ui-sharp/Makefile.am new file mode 100644 index 0000000..b7f020e --- /dev/null +++ b/avahi-ui-sharp/Makefile.am @@ -0,0 +1,65 @@ +# $Id: Makefile.am 1251 2006-08-21 23:31:59Z lennart $ + +# 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. + +ASSEMBLY = avahi-ui-sharp.dll + +CLEANFILES = $(ASSEMBLY) $(ASSEMBLY).mdb $(ASSEMBLY).config + +AVAHISOURCES = \ + $(srcdir)/ServiceDialog.cs + +EXTRA_DIST = \ + $(AVAHISOURCES) \ + $(srcdir)/avahi-ui-sharp-docs.source \ + $(srcdir)/en/*.xml \ + $(srcdir)/en/*/*.xml \ + $(srcdir)/gencfg.sh + +$(ASSEMBLY): $(AVAHISOURCES) + mcs -keyfile:$(top_srcdir)/avahi-sharp/avahi.snk -target:library -out:$@ -debug $(AVAHISOURCES) -pkg:gtk-sharp-2.0 -r:$(top_builddir)/avahi-sharp/avahi-sharp.dll -r:Mono.Posix + +$(ASSEMBLY).config: $(ASSEMBLY).config.in + $(srcdir)/gencfg.sh $(top_builddir)/avahi-common/libavahi-common.la < $< > $@ + +if HAVE_MONO +if HAVE_DBUS +all: $(ASSEMBLY) $(ASSEMBLY).config + +if HAVE_MONODOC +update-docs: $(ASSEMBLY) + $(MONODOCER) -assembly:$(ASSEMBLY) -path:en + +avahi-ui-sharp-docs.zip: avahi-ui-sharp-docs.tree + +avahi-ui-sharp-docs.tree: $(srcdir)/en/*/* + $(MDASSEMBLER) --out avahi-ui-sharp-docs --ecma $(srcdir)/en + +monodocdir = $(MONODOC_DIR) +monodoc_DATA = avahi-ui-sharp-docs.zip avahi-ui-sharp-docs.tree avahi-ui-sharp-docs.source + +endif + +install-data-hook: $(ASSEMBLY) + $(GACUTIL) /i $(ASSEMBLY) /package avahi-ui-sharp /gacdir $(libdir) /root $(DESTDIR)$(libdir) + +uninstall-hook: $(ASSEMBLY) + $(GACUTIL) /u avahi-sharp /package avahi-ui-sharp /gacdir $(libdir) /root $(DESTDIR)$(libdir) + +endif +endif diff --git a/avahi-ui-sharp/ServiceDialog.cs b/avahi-ui-sharp/ServiceDialog.cs new file mode 100644 index 0000000..e0306e1 --- /dev/null +++ b/avahi-ui-sharp/ServiceDialog.cs @@ -0,0 +1,238 @@ +using System; +using System.Net; +using System.Collections; +using System.Runtime.InteropServices; +using Gtk; +using Mono.Unix; +using Mono.Unix.Native; + +namespace Avahi.UI +{ + public class ServiceDialog : Dialog + { + [DllImport ("avahi-ui")] + private static extern IntPtr aui_service_dialog_new (string title, IntPtr parent, IntPtr dummy); + + [DllImport ("avahi-ui")] + private static extern void aui_service_dialog_set_browse_service_typesv (IntPtr dialog, IntPtr[] types); + + [DllImport ("avahi-ui")] + private static extern IntPtr aui_service_dialog_get_browse_service_types (IntPtr dialog); + + [DllImport ("avahi-ui")] + private static extern IntPtr aui_service_dialog_get_domain (IntPtr dialog); + + [DllImport ("avahi-ui")] + private static extern void aui_service_dialog_set_domain (IntPtr dialog, IntPtr domain); + + [DllImport ("avahi-ui")] + private static extern IntPtr aui_service_dialog_get_service_type (IntPtr dialog); + + [DllImport ("avahi-ui")] + private static extern void aui_service_dialog_set_service_type (IntPtr dialog, IntPtr type); + + [DllImport ("avahi-ui")] + private static extern IntPtr aui_service_dialog_get_service_name (IntPtr dialog); + + [DllImport ("avahi-ui")] + private static extern void aui_service_dialog_set_service_name (IntPtr dialog, IntPtr type); + + [DllImport ("avahi-ui")] + private static extern IntPtr aui_service_dialog_get_address (IntPtr dialog); + + [DllImport ("avahi-ui")] + private static extern UInt16 aui_service_dialog_get_port (IntPtr dialog); + + [DllImport ("avahi-ui")] + private static extern IntPtr aui_service_dialog_get_host_name (IntPtr dialog); + + [DllImport ("avahi-ui")] + private static extern IntPtr aui_service_dialog_get_txt_data (IntPtr dialog); + + [DllImport ("avahi-ui")] + private static extern bool aui_service_dialog_get_resolve_service (IntPtr dialog); + + [DllImport ("avahi-ui")] + private static extern void aui_service_dialog_set_resolve_service (IntPtr dialog, bool val); + + [DllImport ("avahi-ui")] + private static extern bool aui_service_dialog_get_resolve_host_name (IntPtr dialog); + + [DllImport ("avahi-ui")] + private static extern void aui_service_dialog_set_resolve_host_name (IntPtr dialog, bool val); + + [DllImport ("avahi-ui")] + private static extern Protocol aui_service_dialog_get_address_family (IntPtr dialog); + + [DllImport ("avahi-ui")] + private static extern void aui_service_dialog_set_address_family (IntPtr dialog, Protocol proto); + + [DllImport ("avahi-common")] + private static extern IntPtr avahi_address_snprint (IntPtr buf, int size, IntPtr address); + + [DllImport ("avahi-common")] + private static extern IntPtr avahi_string_list_get_next (IntPtr list); + + [DllImport ("avahi-common")] + private static extern IntPtr avahi_string_list_get_text (IntPtr list); + + [DllImport ("avahi-common")] + private static extern int avahi_string_list_get_size (IntPtr list); + + public string[] BrowseServiceTypes { + get { + IntPtr arr = aui_service_dialog_get_browse_service_types (Raw); + + ArrayList values = new ArrayList (); + + for (int i = 0;;i++) { + IntPtr ptr = Marshal.ReadIntPtr (arr, i * Marshal.SizeOf (typeof (IntPtr))); + + if (ptr == IntPtr.Zero) + break; + + values.Add (GLib.Marshaller.Utf8PtrToString (ptr)); + } + + return (string[]) values.ToArray (typeof (string)); + } set { + IntPtr[] types; + if (value == null) { + types = new IntPtr[] { IntPtr.Zero }; + } else { + types = new IntPtr[value.Length + 1]; + + for (int i = 0; i < value.Length; i++) { + types[i] = GLib.Marshaller.StringToPtrGStrdup (value[i]); + } + + types[value.Length] = IntPtr.Zero; + } + + aui_service_dialog_set_browse_service_typesv (Raw, types); + + for (int i = 0;;i++) { + if (types[i] != IntPtr.Zero) + break; + + GLib.Marshaller.Free (types[i]); + } + } + } + + public string ServiceType { + get { + return GLib.Marshaller.Utf8PtrToString (aui_service_dialog_get_service_type (Raw)); + } set { + IntPtr type = GLib.Marshaller.StringToPtrGStrdup (value); + aui_service_dialog_set_service_type (Raw, type); + GLib.Marshaller.Free (type); + } + } + + public string ServiceName { + get { + return GLib.Marshaller.Utf8PtrToString (aui_service_dialog_get_service_name (Raw)); + } set { + IntPtr name = GLib.Marshaller.StringToPtrGStrdup (value); + aui_service_dialog_set_service_name (Raw, name); + GLib.Marshaller.Free (name); + } + } + + public IPAddress Address { + get { + return PtrToAddress (aui_service_dialog_get_address (Raw)); + } + } + + public UInt16 Port { + get { + return aui_service_dialog_get_port (Raw); + } + } + + public string HostName { + get { + return GLib.Marshaller.Utf8PtrToString (aui_service_dialog_get_host_name (Raw)); + } + } + + public string Domain { + get { + return GLib.Marshaller.Utf8PtrToString (aui_service_dialog_get_domain (Raw)); + } set { + IntPtr domain = GLib.Marshaller.StringToPtrGStrdup (value); + aui_service_dialog_set_domain (Raw, domain); + GLib.Marshaller.Free (domain); + } + } + + public byte[][] TxtData { + get { + ArrayList txtlist = new ArrayList (); + IntPtr txt = aui_service_dialog_get_txt_data (Raw); + + for (IntPtr l = txt; l != IntPtr.Zero; l = avahi_string_list_get_next (l)) { + IntPtr buf = avahi_string_list_get_text (l); + int len = avahi_string_list_get_size (l); + + byte[] txtbuf = new byte[len]; + Marshal.Copy (buf, txtbuf, 0, len); + txtlist.Add (txtbuf); + } + + return (byte[][]) txtlist.ToArray (typeof (byte[])); + } + } + + public bool ResolveServiceEnabled { + get { + return aui_service_dialog_get_resolve_service (Raw); + } set { + aui_service_dialog_set_resolve_service (Raw, value); + } + } + + public bool ResolveHostNameEnabled { + get { + return aui_service_dialog_get_resolve_host_name (Raw); + } set { + aui_service_dialog_set_resolve_host_name (Raw, value); + } + } + + public Protocol AddressFamily { + get { + return aui_service_dialog_get_address_family (Raw); + } set { + aui_service_dialog_set_address_family (Raw, value); + } + } + + public ServiceDialog (string title, Window parent, params object[] buttonData) + { + Raw = aui_service_dialog_new (title, parent == null ? IntPtr.Zero : parent.Handle, + IntPtr.Zero); + + for (int i = 0; i < buttonData.Length - 1; i += 2) { + AddButton ((string) buttonData[i], (int) buttonData[i + 1]); + } + } + + private static IPAddress PtrToAddress (IntPtr ptr) + { + IPAddress address = null; + + if (ptr != IntPtr.Zero) { + IntPtr buf = Stdlib.malloc (256); + IntPtr addrPtr = avahi_address_snprint (buf, 256, ptr); + address = IPAddress.Parse (GLib.Marshaller.Utf8PtrToString (addrPtr)); + + Stdlib.free (addrPtr); + } + + return address; + } + } +} diff --git a/avahi-ui-sharp/avahi-ui-sharp-docs.source b/avahi-ui-sharp/avahi-ui-sharp-docs.source new file mode 100644 index 0000000..2e7b172 --- /dev/null +++ b/avahi-ui-sharp/avahi-ui-sharp-docs.source @@ -0,0 +1,4 @@ + + + + diff --git a/avahi-ui-sharp/avahi-ui-sharp.dll.config.in b/avahi-ui-sharp/avahi-ui-sharp.dll.config.in new file mode 100644 index 0000000..819577f --- /dev/null +++ b/avahi-ui-sharp/avahi-ui-sharp.dll.config.in @@ -0,0 +1,4 @@ + + + + diff --git a/avahi-ui-sharp/en/Avahi.UI.xml b/avahi-ui-sharp/en/Avahi.UI.xml new file mode 100644 index 0000000..949581c --- /dev/null +++ b/avahi-ui-sharp/en/Avahi.UI.xml @@ -0,0 +1,6 @@ + + + To be added. + To be added. + + diff --git a/avahi-ui-sharp/en/Avahi.UI/ServiceDialog.xml b/avahi-ui-sharp/en/Avahi.UI/ServiceDialog.xml new file mode 100644 index 0000000..72fa8ed --- /dev/null +++ b/avahi-ui-sharp/en/Avahi.UI/ServiceDialog.xml @@ -0,0 +1,171 @@ + + + + avahi-ui-sharp + 0.0.0.0 + + + Gtk.Dialog + + + + + + Constructor + + + + + + + System.ParamArray + + + + + + To be added. + To be added. + To be added. + To be added. + To be added. + + + + + Property + + System.Net.IPAddress + + + To be added. + To be added. + To be added. + + + + + Property + + Avahi.Protocol + + + To be added. + To be added. + To be added. + + + + + Property + + System.String[] + + + To be added. + To be added. + To be added. + + + + + Property + + System.String + + + To be added. + To be added. + To be added. + + + + + Property + + System.String + + + To be added. + To be added. + To be added. + + + + + Property + + System.UInt16 + + + To be added. + To be added. + To be added. + + + + + Property + + System.Boolean + + + To be added. + To be added. + To be added. + + + + + Property + + System.Boolean + + + To be added. + To be added. + To be added. + + + + + Property + + System.String + + + To be added. + To be added. + To be added. + + + + + Property + + System.String + + + To be added. + To be added. + To be added. + + + + + Property + + System.Byte[][] + + + To be added. + To be added. + To be added. + + + + + To be added. + To be added. + + diff --git a/avahi-ui-sharp/en/index.xml b/avahi-ui-sharp/en/index.xml new file mode 100644 index 0000000..d1e808c --- /dev/null +++ b/avahi-ui-sharp/en/index.xml @@ -0,0 +1,13 @@ + + + + + To be added. + To be added. + + + + + + avahi-ui-sharp + diff --git a/avahi-ui-sharp/gencfg.sh b/avahi-ui-sharp/gencfg.sh new file mode 100755 index 0000000..44a6c81 --- /dev/null +++ b/avahi-ui-sharp/gencfg.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +. $1 +common_dlname=$dlname + +exec sed -e "s,@COMMON_DLNAME\@,${common_dlname},g" diff --git a/avahi-ui-sharp/zssh.cs b/avahi-ui-sharp/zssh.cs new file mode 100644 index 0000000..ad45ca9 --- /dev/null +++ b/avahi-ui-sharp/zssh.cs @@ -0,0 +1,37 @@ +using System; +using System.Diagnostics; +using Gtk; +using Avahi.UI; + +public class EntryPoint { + public static void Main () { + Application.Init (); + + ServiceDialog dialog = new ServiceDialog ("Choose SSH Server", null, Stock.Close, ResponseType.Cancel); + dialog.BrowseServiceTypes = new string[] { "_ssh._tcp" }; + dialog.ResolveServiceEnabled = true; + + if (dialog.Run () == (int) ResponseType.Accept) { + Console.WriteLine ("Connecting to {0}:{1}", dialog.Address, dialog.Port); + + string user = Environment.UserName; + + foreach (byte[] txtBytes in dialog.TxtData) { + string txt = System.Text.Encoding.UTF8.GetString (txtBytes); + string[] splitTxt = txt.Split(new char[] { '=' }, 2); + + if (splitTxt.Length != 2) + continue; + + if (splitTxt[0] == "u") { + user = splitTxt[1]; + } + + string args = String.Format ("gnome-terminal -t {0} -x ssh -p {1} -l {2} {3}", + dialog.HostName, dialog.Port, user, dialog.Address.ToString ()); + Console.WriteLine ("Launching: " + args); + Process.Start (args); + } + } + } +} diff --git a/configure.ac b/configure.ac index 81954a3..2286b80 100644 --- a/configure.ac +++ b/configure.ac @@ -989,6 +989,7 @@ man/Makefile tests/Makefile service-type-database/Makefile avahi-sharp/Makefile +avahi-ui-sharp/Makefile avahi-compat-libdns_sd/Makefile avahi-compat-howl/Makefile avahi-compat-howl/samples/Makefile -- 2.39.5