]> git.meshlink.io Git - catta/commitdiff
add avahi-ui-sharp
authorJames Willcox <snopr@snorp.net>
Thu, 19 Apr 2007 21:01:45 +0000 (21:01 +0000)
committerJames Willcox <snopr@snorp.net>
Thu, 19 Apr 2007 21:01:45 +0000 (21:01 +0000)
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1444 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-ui-sharp/Makefile.am [new file with mode: 0644]
avahi-ui-sharp/ServiceDialog.cs [new file with mode: 0644]
avahi-ui-sharp/avahi-ui-sharp-docs.source [new file with mode: 0644]
avahi-ui-sharp/avahi-ui-sharp.dll.config.in [new file with mode: 0644]
avahi-ui-sharp/en/Avahi.UI.xml [new file with mode: 0644]
avahi-ui-sharp/en/Avahi.UI/ServiceDialog.xml [new file with mode: 0644]
avahi-ui-sharp/en/index.xml [new file with mode: 0644]
avahi-ui-sharp/gencfg.sh [new file with mode: 0755]
avahi-ui-sharp/zssh.cs [new file with mode: 0644]
configure.ac

diff --git a/avahi-ui-sharp/Makefile.am b/avahi-ui-sharp/Makefile.am
new file mode 100644 (file)
index 0000000..b7f020e
--- /dev/null
@@ -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 (file)
index 0000000..e0306e1
--- /dev/null
@@ -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 (file)
index 0000000..2e7b172
--- /dev/null
@@ -0,0 +1,4 @@
+<?xml version="1.0"?>
+<monodoc>
+  <source provider="ecma" basefile="avahi-ui-sharp-docs" path="various" title="Avahi" />
+</monodoc>
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 (file)
index 0000000..819577f
--- /dev/null
@@ -0,0 +1,4 @@
+<configuration>
+  <dllmap dll="avahi-ui" target="libavahi-ui.so.0"/>
+  <dllmap dll="avahi-common" target="@COMMON_DLNAME@"/>
+</configuration>
diff --git a/avahi-ui-sharp/en/Avahi.UI.xml b/avahi-ui-sharp/en/Avahi.UI.xml
new file mode 100644 (file)
index 0000000..949581c
--- /dev/null
@@ -0,0 +1,6 @@
+<Namespace Name="Avahi.UI">
+  <Docs>
+    <summary>To be added.</summary>
+    <remarks>To be added.</remarks>
+  </Docs>
+</Namespace>
diff --git a/avahi-ui-sharp/en/Avahi.UI/ServiceDialog.xml b/avahi-ui-sharp/en/Avahi.UI/ServiceDialog.xml
new file mode 100644 (file)
index 0000000..72fa8ed
--- /dev/null
@@ -0,0 +1,171 @@
+<Type Name="ServiceDialog" FullName="Avahi.UI.ServiceDialog">
+  <TypeSignature Language="C#" Value="public class ServiceDialog : Gtk.Dialog" />
+  <AssemblyInfo>
+    <AssemblyName>avahi-ui-sharp</AssemblyName>
+    <AssemblyVersion>0.0.0.0</AssemblyVersion>
+  </AssemblyInfo>
+  <Base>
+    <BaseTypeName>Gtk.Dialog</BaseTypeName>
+  </Base>
+  <Interfaces />
+  <Members>
+    <Member MemberName=".ctor">
+      <MemberSignature Language="C#" Value="public ServiceDialog (string title, Gtk.Window parent, object[] buttonData);" />
+      <MemberType>Constructor</MemberType>
+      <Parameters>
+        <Parameter Name="title" Type="System.String" />
+        <Parameter Name="parent" Type="Gtk.Window" />
+        <Parameter Name="buttonData" Type="System.Object[]">
+          <Attributes>
+            <Attribute>
+              <AttributeName>System.ParamArray</AttributeName>
+            </Attribute>
+          </Attributes>
+        </Parameter>
+      </Parameters>
+      <Docs>
+        <param name="title">To be added.</param>
+        <param name="parent">To be added.</param>
+        <param name="buttonData">To be added.</param>
+        <summary>To be added.</summary>
+        <remarks>To be added.</remarks>
+      </Docs>
+    </Member>
+    <Member MemberName="Address">
+      <MemberSignature Language="C#" Value="public System.Net.IPAddress Address { get; };" />
+      <MemberType>Property</MemberType>
+      <ReturnValue>
+        <ReturnType>System.Net.IPAddress</ReturnType>
+      </ReturnValue>
+      <Docs>
+        <summary>To be added.</summary>
+        <value>To be added.</value>
+        <remarks>To be added.</remarks>
+      </Docs>
+    </Member>
+    <Member MemberName="AddressFamily">
+      <MemberSignature Language="C#" Value="public Avahi.Protocol AddressFamily { set; get; };" />
+      <MemberType>Property</MemberType>
+      <ReturnValue>
+        <ReturnType>Avahi.Protocol</ReturnType>
+      </ReturnValue>
+      <Docs>
+        <summary>To be added.</summary>
+        <value>To be added.</value>
+        <remarks>To be added.</remarks>
+      </Docs>
+    </Member>
+    <Member MemberName="BrowseServiceTypes">
+      <MemberSignature Language="C#" Value="public string[] BrowseServiceTypes { set; get; };" />
+      <MemberType>Property</MemberType>
+      <ReturnValue>
+        <ReturnType>System.String[]</ReturnType>
+      </ReturnValue>
+      <Docs>
+        <summary>To be added.</summary>
+        <value>To be added.</value>
+        <remarks>To be added.</remarks>
+      </Docs>
+    </Member>
+    <Member MemberName="Domain">
+      <MemberSignature Language="C#" Value="public string Domain { set; get; };" />
+      <MemberType>Property</MemberType>
+      <ReturnValue>
+        <ReturnType>System.String</ReturnType>
+      </ReturnValue>
+      <Docs>
+        <summary>To be added.</summary>
+        <value>To be added.</value>
+        <remarks>To be added.</remarks>
+      </Docs>
+    </Member>
+    <Member MemberName="HostName">
+      <MemberSignature Language="C#" Value="public string HostName { get; };" />
+      <MemberType>Property</MemberType>
+      <ReturnValue>
+        <ReturnType>System.String</ReturnType>
+      </ReturnValue>
+      <Docs>
+        <summary>To be added.</summary>
+        <value>To be added.</value>
+        <remarks>To be added.</remarks>
+      </Docs>
+    </Member>
+    <Member MemberName="Port">
+      <MemberSignature Language="C#" Value="public ushort Port { get; };" />
+      <MemberType>Property</MemberType>
+      <ReturnValue>
+        <ReturnType>System.UInt16</ReturnType>
+      </ReturnValue>
+      <Docs>
+        <summary>To be added.</summary>
+        <value>To be added.</value>
+        <remarks>To be added.</remarks>
+      </Docs>
+    </Member>
+    <Member MemberName="ResolveHostNameEnabled">
+      <MemberSignature Language="C#" Value="public bool ResolveHostNameEnabled { set; get; };" />
+      <MemberType>Property</MemberType>
+      <ReturnValue>
+        <ReturnType>System.Boolean</ReturnType>
+      </ReturnValue>
+      <Docs>
+        <summary>To be added.</summary>
+        <value>To be added.</value>
+        <remarks>To be added.</remarks>
+      </Docs>
+    </Member>
+    <Member MemberName="ResolveServiceEnabled">
+      <MemberSignature Language="C#" Value="public bool ResolveServiceEnabled { set; get; };" />
+      <MemberType>Property</MemberType>
+      <ReturnValue>
+        <ReturnType>System.Boolean</ReturnType>
+      </ReturnValue>
+      <Docs>
+        <summary>To be added.</summary>
+        <value>To be added.</value>
+        <remarks>To be added.</remarks>
+      </Docs>
+    </Member>
+    <Member MemberName="ServiceName">
+      <MemberSignature Language="C#" Value="public string ServiceName { set; get; };" />
+      <MemberType>Property</MemberType>
+      <ReturnValue>
+        <ReturnType>System.String</ReturnType>
+      </ReturnValue>
+      <Docs>
+        <summary>To be added.</summary>
+        <value>To be added.</value>
+        <remarks>To be added.</remarks>
+      </Docs>
+    </Member>
+    <Member MemberName="ServiceType">
+      <MemberSignature Language="C#" Value="public string ServiceType { set; get; };" />
+      <MemberType>Property</MemberType>
+      <ReturnValue>
+        <ReturnType>System.String</ReturnType>
+      </ReturnValue>
+      <Docs>
+        <summary>To be added.</summary>
+        <value>To be added.</value>
+        <remarks>To be added.</remarks>
+      </Docs>
+    </Member>
+    <Member MemberName="TxtData">
+      <MemberSignature Language="C#" Value="public byte[][] TxtData { get; };" />
+      <MemberType>Property</MemberType>
+      <ReturnValue>
+        <ReturnType>System.Byte[][]</ReturnType>
+      </ReturnValue>
+      <Docs>
+        <summary>To be added.</summary>
+        <value>To be added.</value>
+        <remarks>To be added.</remarks>
+      </Docs>
+    </Member>
+  </Members>
+  <Docs>
+    <summary>To be added.</summary>
+    <remarks>To be added.</remarks>
+  </Docs>
+</Type>
diff --git a/avahi-ui-sharp/en/index.xml b/avahi-ui-sharp/en/index.xml
new file mode 100644 (file)
index 0000000..d1e808c
--- /dev/null
@@ -0,0 +1,13 @@
+<Overview>
+  <Assemblies>
+    <Assembly Name="avahi-ui-sharp" Version="0.0.0.0" />
+  </Assemblies>
+  <Remarks>To be added.</Remarks>
+  <Copyright>To be added.</Copyright>
+  <Types>
+    <Namespace Name="Avahi.UI">
+      <Type Name="ServiceDialog" />
+    </Namespace>
+  </Types>
+  <Title>avahi-ui-sharp</Title>
+</Overview>
diff --git a/avahi-ui-sharp/gencfg.sh b/avahi-ui-sharp/gencfg.sh
new file mode 100755 (executable)
index 0000000..44a6c81
--- /dev/null
@@ -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 (file)
index 0000000..ad45ca9
--- /dev/null
@@ -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);
+            }
+        }
+    }
+}
index 81954a329d773623a8520b9a484a83b05e982262..2286b8090bbdf102229f9d712e099fd037bfd6b2 100644 (file)
@@ -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