]> git.meshlink.io Git - catta/commitdiff
* Add EntryGroup.UpdateService, EntryGroup.AddServiceSubtype,
authorJames Willcox <snopr@snorp.net>
Thu, 17 Nov 2005 19:08:58 +0000 (19:08 +0000)
committerJames Willcox <snopr@snorp.net>
Thu, 17 Nov 2005 19:08:58 +0000 (19:08 +0000)
  EntryGroup.AddAddress, EntryGroup.AddRecord,
  EntryGroup.JoinServiceName, EntryGroup.SplitServiceName

git-svn-id: file:///home/lennart/svn/public/avahi/trunk@998 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-sharp/AvahiTest.cs
avahi-sharp/EntryGroup.cs
avahi-sharp/en/Avahi/EntryGroup.xml

index 0fac04b09c320a709b544bb1725e04999dd1f15f..df95b906c6406ddea36e76649cadb6974cc135fa 100644 (file)
@@ -32,6 +32,8 @@ public class AvahiTest {
     public static void Main () {
         client = new Client ();
 
+       Console.WriteLine ("joined service name: " + EntryGroup.JoinServiceName ("FooBar", "_foo", "local"));
+
         EntryGroup eg = new EntryGroup (client);
         eg.StateChanged += OnEntryGroupChanged;
         eg.AddService ("foobar2", "_daap._tcp", client.DomainName,
index 443f198c0d0b0fa60e5caf4c5c21b9a934bc72c6..eb7d9e2725ebf5a35731dad73630181011512cfb 100644 (file)
@@ -20,8 +20,9 @@
 ***/
 
 using System;
+using System.Net;
 using System.Runtime.InteropServices;
-
+using Mono.Unix;
 
 namespace Avahi
 {
@@ -92,6 +93,26 @@ namespace Avahi
                                                                         PublishFlags flags, IntPtr name, IntPtr type,
                                                                         IntPtr domain, IntPtr host, UInt16 port,
                                                                         IntPtr strlst);
+
+        [DllImport ("avahi-client")]
+        private static extern int avahi_entry_group_update_service_strlst (IntPtr group, int iface, Protocol proto,
+                                                                           PublishFlags flags, IntPtr name,
+                                                                           IntPtr type, IntPtr domain, IntPtr strlst);
+
+        [DllImport ("avahi-client")]
+        private static extern int avahi_entry_group_add_service_subtype (IntPtr group, int iface, Protocol proto,
+                                                                         PublishFlags flags, IntPtr name, IntPtr type,
+                                                                         IntPtr domain, IntPtr subtype);
+
+        [DllImport ("avahi-client")]
+        private static extern int avahi_entry_group_add_address (IntPtr group, int iface, Protocol proto,
+                                                                 PublishFlags flags, IntPtr name, IntPtr address);
+
+
+        [DllImport ("avahi-client")]
+        private static extern int avahi_entry_group_add_record (IntPtr group, int iface, Protocol proto,
+                                                                PublishFlags flags, IntPtr name, RecordClass clazz,
+                                                                RecordType type, uint ttl, byte[] rdata, int size);
         
         [DllImport ("avahi-client")]
         private static extern void avahi_entry_group_free (IntPtr group);
@@ -105,6 +126,16 @@ namespace Avahi
         [DllImport ("avahi-common")]
         private static extern void avahi_string_list_free (IntPtr list);
 
+        [DllImport ("avahi-common")]
+        private static extern int avahi_service_name_join (IntPtr buf, int len, IntPtr name, IntPtr type,
+                                                           IntPtr domain);
+
+        [DllImport ("avahi-common")]
+        private static extern int avahi_service_name_split (IntPtr service, IntPtr name, int name_len,
+                                                            IntPtr type, int type_len,
+                                                            IntPtr domain, int domain_len);
+
+        
         [DllImport ("avahi-common")]
         private static extern IntPtr avahi_alternative_service_name (IntPtr name);
 
@@ -204,12 +235,186 @@ namespace Avahi
             lock (client) {
                 int ret = avahi_entry_group_add_service_strlst (handle, iface, proto, flags, namePtr, typePtr, domainPtr,
                                                                 hostPtr, port, list);
+
+                Utility.Free (namePtr);
+                Utility.Free (typePtr);
+                Utility.Free (domainPtr);
+                Utility.Free (hostPtr);
+                avahi_string_list_free (list);
+
                 if (ret < 0) {
                     client.ThrowError ();
                 }
             }
             
-            avahi_string_list_free (list);
+        }
+
+        public void UpdateService (string name, string type, string domain, params string[] txt)
+        {
+            UpdateService (-1, Protocol.Unspecified, PublishFlags.None, name, type, domain, txt);
+        }
+
+        public void UpdateService (int iface, Protocol proto, PublishFlags flags, string name, string type,
+                                   string domain, params string[] txt)
+        {
+            IntPtr list = avahi_string_list_new (IntPtr.Zero);
+
+            if (txt != null) {
+                foreach (string item in txt) {
+                    IntPtr itemPtr = Utility.StringToPtr (item);
+                    list = avahi_string_list_add (list, itemPtr);
+                    Utility.Free (itemPtr);
+                }
+            }
+
+            IntPtr namePtr = Utility.StringToPtr (name);
+            IntPtr typePtr = Utility.StringToPtr (type);
+            IntPtr domainPtr = Utility.StringToPtr (domain);
+
+            lock (client) {
+                int ret = avahi_entry_group_update_service_strlst (handle, iface, proto, flags, namePtr, typePtr, domainPtr, list);
+
+                Utility.Free (namePtr);
+                Utility.Free (typePtr);
+                Utility.Free (domainPtr);
+                
+                avahi_string_list_free (list);
+
+                if (ret < 0) {
+                    client.ThrowError ();
+                }
+            }
+        }
+
+        public void AddServiceSubtype (string name, string type, string domain, string subtype)
+        {
+            AddServiceSubtype (-1, Protocol.Unspecified, PublishFlags.None, name, type, domain, subtype);
+        }
+
+        public void AddServiceSubtype (int iface, Protocol proto, PublishFlags flags, string name,
+                                       string type, string domain, string subtype)
+        {
+            IntPtr namePtr = Utility.StringToPtr (name);
+            IntPtr typePtr = Utility.StringToPtr (type);
+            IntPtr domainPtr = Utility.StringToPtr (domain);
+            IntPtr subtypePtr = Utility.StringToPtr (subtype);
+
+            lock (client) {
+                int ret = avahi_entry_group_add_service_subtype (handle, iface, proto, flags, namePtr,
+                                                                 typePtr, domainPtr, subtypePtr);
+
+                Utility.Free (namePtr);
+                Utility.Free (typePtr);
+                Utility.Free (domainPtr);
+                Utility.Free (subtypePtr);
+                
+                if (ret < 0) {
+                    client.ThrowError ();
+                }
+            }
+        }
+
+        public void AddAddress (string name, IPAddress address)
+        {
+            AddAddress (-1, Protocol.Unspecified, PublishFlags.None, name, address);
+        }
+
+        public void AddAddress (int iface, Protocol proto, PublishFlags flags, string name, IPAddress address)
+        {
+            IntPtr namePtr = Utility.StringToPtr (name);
+            IntPtr addressPtr = Utility.AddressToPtr (address);
+
+            lock (client) {
+                int ret = avahi_entry_group_add_address (handle, iface, proto, flags, namePtr, addressPtr);
+
+                Utility.Free (namePtr);
+                Utility.Free (addressPtr);
+
+                if (ret < 0) {
+                    client.ThrowError ();
+                }
+            }
+        }
+
+        public void AddRecord (string name, RecordClass clazz, RecordType type, uint ttl, byte[] rdata, int length)
+        {
+            AddRecord (-1, Protocol.Unspecified, PublishFlags.None, name, clazz, type, ttl, rdata, length);
+        }
+
+        public void AddRecord (int iface, Protocol proto, PublishFlags flags, string name,
+                               RecordClass clazz, RecordType type, uint ttl, byte[] rdata, int length)
+        {
+            IntPtr namePtr = Utility.StringToPtr (name);
+
+            lock (client) {
+                int ret = avahi_entry_group_add_record (handle, iface, proto, flags, namePtr,
+                                                        clazz, type, ttl, rdata, length);
+
+                Utility.Free (namePtr);
+                
+                if (ret < 0) {
+                    client.ThrowError ();
+                }
+            }
+        }
+
+        public static string JoinServiceName (string name, string type, string domain)
+        {
+            int len = 4 * (name.Length + type.Length + domain.Length) + 4;
+            IntPtr buf = Stdlib.malloc ((ulong) len);
+
+            IntPtr namePtr = Utility.StringToPtr (name);
+            IntPtr typePtr = Utility.StringToPtr (type);
+            IntPtr domainPtr = Utility.StringToPtr (domain);
+
+            int ret = avahi_service_name_join (buf, len, namePtr, typePtr, domainPtr);
+
+            Utility.Free (namePtr);
+            Utility.Free (typePtr);
+            Utility.Free (domainPtr);
+
+            if (ret < 0) {
+                Utility.Free (buf);
+                return null; // FIXME, should throw exception
+            }
+
+            string service = Utility.PtrToString (buf);
+            Utility.Free (buf);
+
+            return service;
+        }
+
+        public static void SplitServiceName (string service, out string name, out string type, out string domain)
+        {
+            int len = 1024;
+
+            IntPtr servicePtr = Utility.StringToPtr (service);
+            IntPtr namePtr = Stdlib.malloc ((ulong) len);
+            IntPtr typePtr = Stdlib.malloc ((ulong) len);
+            IntPtr domainPtr = Stdlib.malloc ((ulong) len);
+            
+            int ret = avahi_service_name_split (servicePtr, namePtr, len, typePtr, len, domainPtr, len);
+
+            Utility.Free (servicePtr);
+            
+            if (ret < 0) {
+                Utility.Free (namePtr);
+                Utility.Free (typePtr);
+                Utility.Free (domainPtr);
+                
+                name = null;
+                type = null;
+                domain = null;
+                return;
+            }
+
+            name = Utility.PtrToString (namePtr);
+            type = Utility.PtrToString (typePtr);
+            domain = Utility.PtrToString (domainPtr);
+
+            Utility.Free (namePtr);
+            Utility.Free (typePtr);
+            Utility.Free (domainPtr);
         }
 
         public static string GetAlternativeServiceName (string name) {
index 8c9ea283cd82ed86bbfa5d6120ada25b405f2731..2d71786f9bdb6fae75593a9c446d0f26e69b8289 100644 (file)
         <remarks>To be added.</remarks>
       </Docs>
     </Member>
+    <Member MemberName="UpdateService">
+      <MemberSignature Language="C#" Value="public void UpdateService (string name, string type, string domain, string[] txt);" />
+      <MemberType>Method</MemberType>
+      <ReturnValue>
+        <ReturnType>System.Void</ReturnType>
+      </ReturnValue>
+      <Parameters>
+        <Parameter Name="name" Type="System.String" />
+        <Parameter Name="type" Type="System.String" />
+        <Parameter Name="domain" Type="System.String" />
+        <Parameter Name="txt" Type="System.String[]">
+          <Attributes>
+            <Attribute>
+              <AttributeName>System.ParamArray</AttributeName>
+            </Attribute>
+          </Attributes>
+        </Parameter>
+      </Parameters>
+      <Docs>
+        <param name="name">To be added.</param>
+        <param name="type">To be added.</param>
+        <param name="domain">To be added.</param>
+        <param name="txt">To be added.</param>
+        <summary>To be added.</summary>
+        <remarks>To be added.</remarks>
+      </Docs>
+    </Member>
+    <Member MemberName="UpdateService">
+      <MemberSignature Language="C#" Value="public void UpdateService (int iface, Avahi.Protocol proto, Avahi.PublishFlags flags, string name, string type, string domain, string[] txt);" />
+      <MemberType>Method</MemberType>
+      <ReturnValue>
+        <ReturnType>System.Void</ReturnType>
+      </ReturnValue>
+      <Parameters>
+        <Parameter Name="iface" Type="System.Int32" />
+        <Parameter Name="proto" Type="Avahi.Protocol" />
+        <Parameter Name="flags" Type="Avahi.PublishFlags" />
+        <Parameter Name="name" Type="System.String" />
+        <Parameter Name="type" Type="System.String" />
+        <Parameter Name="domain" Type="System.String" />
+        <Parameter Name="txt" Type="System.String[]">
+          <Attributes>
+            <Attribute>
+              <AttributeName>System.ParamArray</AttributeName>
+            </Attribute>
+          </Attributes>
+        </Parameter>
+      </Parameters>
+      <Docs>
+        <param name="iface">To be added.</param>
+        <param name="proto">To be added.</param>
+        <param name="flags">To be added.</param>
+        <param name="name">To be added.</param>
+        <param name="type">To be added.</param>
+        <param name="domain">To be added.</param>
+        <param name="txt">To be added.</param>
+        <summary>To be added.</summary>
+        <remarks>To be added.</remarks>
+      </Docs>
+    </Member>
+    <Member MemberName="AddServiceSubtype">
+      <MemberSignature Language="C#" Value="public void AddServiceSubtype (string name, string type, string domain, string subtype);" />
+      <MemberType>Method</MemberType>
+      <ReturnValue>
+        <ReturnType>System.Void</ReturnType>
+      </ReturnValue>
+      <Parameters>
+        <Parameter Name="name" Type="System.String" />
+        <Parameter Name="type" Type="System.String" />
+        <Parameter Name="domain" Type="System.String" />
+        <Parameter Name="subtype" Type="System.String" />
+      </Parameters>
+      <Docs>
+        <param name="name">To be added.</param>
+        <param name="type">To be added.</param>
+        <param name="domain">To be added.</param>
+        <param name="subtype">To be added.</param>
+        <summary>To be added.</summary>
+        <remarks>To be added.</remarks>
+      </Docs>
+    </Member>
+    <Member MemberName="AddServiceSubtype">
+      <MemberSignature Language="C#" Value="public void AddServiceSubtype (int iface, Avahi.Protocol proto, Avahi.PublishFlags flags, string name, string type, string domain, string subtype);" />
+      <MemberType>Method</MemberType>
+      <ReturnValue>
+        <ReturnType>System.Void</ReturnType>
+      </ReturnValue>
+      <Parameters>
+        <Parameter Name="iface" Type="System.Int32" />
+        <Parameter Name="proto" Type="Avahi.Protocol" />
+        <Parameter Name="flags" Type="Avahi.PublishFlags" />
+        <Parameter Name="name" Type="System.String" />
+        <Parameter Name="type" Type="System.String" />
+        <Parameter Name="domain" Type="System.String" />
+        <Parameter Name="subtype" Type="System.String" />
+      </Parameters>
+      <Docs>
+        <param name="iface">To be added.</param>
+        <param name="proto">To be added.</param>
+        <param name="flags">To be added.</param>
+        <param name="name">To be added.</param>
+        <param name="type">To be added.</param>
+        <param name="domain">To be added.</param>
+        <param name="subtype">To be added.</param>
+        <summary>To be added.</summary>
+        <remarks>To be added.</remarks>
+      </Docs>
+    </Member>
+    <Member MemberName="AddAddress">
+      <MemberSignature Language="C#" Value="public void AddAddress (string name, System.Net.IPAddress address);" />
+      <MemberType>Method</MemberType>
+      <ReturnValue>
+        <ReturnType>System.Void</ReturnType>
+      </ReturnValue>
+      <Parameters>
+        <Parameter Name="name" Type="System.String" />
+        <Parameter Name="address" Type="System.Net.IPAddress" />
+      </Parameters>
+      <Docs>
+        <param name="name">To be added.</param>
+        <param name="address">To be added.</param>
+        <summary>To be added.</summary>
+        <remarks>To be added.</remarks>
+      </Docs>
+    </Member>
+    <Member MemberName="AddAddress">
+      <MemberSignature Language="C#" Value="public void AddAddress (int iface, Avahi.Protocol proto, Avahi.PublishFlags flags, string name, System.Net.IPAddress address);" />
+      <MemberType>Method</MemberType>
+      <ReturnValue>
+        <ReturnType>System.Void</ReturnType>
+      </ReturnValue>
+      <Parameters>
+        <Parameter Name="iface" Type="System.Int32" />
+        <Parameter Name="proto" Type="Avahi.Protocol" />
+        <Parameter Name="flags" Type="Avahi.PublishFlags" />
+        <Parameter Name="name" Type="System.String" />
+        <Parameter Name="address" Type="System.Net.IPAddress" />
+      </Parameters>
+      <Docs>
+        <param name="iface">To be added.</param>
+        <param name="proto">To be added.</param>
+        <param name="flags">To be added.</param>
+        <param name="name">To be added.</param>
+        <param name="address">To be added.</param>
+        <summary>To be added.</summary>
+        <remarks>To be added.</remarks>
+      </Docs>
+    </Member>
+    <Member MemberName="AddRecord">
+      <MemberSignature Language="C#" Value="public void AddRecord (string name, Avahi.RecordClass clazz, Avahi.RecordType type, uint ttl, byte[] rdata, int length);" />
+      <MemberType>Method</MemberType>
+      <ReturnValue>
+        <ReturnType>System.Void</ReturnType>
+      </ReturnValue>
+      <Parameters>
+        <Parameter Name="name" Type="System.String" />
+        <Parameter Name="clazz" Type="Avahi.RecordClass" />
+        <Parameter Name="type" Type="Avahi.RecordType" />
+        <Parameter Name="ttl" Type="System.UInt32" />
+        <Parameter Name="rdata" Type="System.Byte[]" />
+        <Parameter Name="length" Type="System.Int32" />
+      </Parameters>
+      <Docs>
+        <param name="name">To be added.</param>
+        <param name="clazz">To be added.</param>
+        <param name="type">To be added.</param>
+        <param name="ttl">To be added.</param>
+        <param name="rdata">To be added.</param>
+        <param name="length">To be added.</param>
+        <summary>To be added.</summary>
+        <remarks>To be added.</remarks>
+      </Docs>
+    </Member>
+    <Member MemberName="AddRecord">
+      <MemberSignature Language="C#" Value="public void AddRecord (int iface, Avahi.Protocol proto, Avahi.PublishFlags flags, string name, Avahi.RecordClass clazz, Avahi.RecordType type, uint ttl, byte[] rdata, int length);" />
+      <MemberType>Method</MemberType>
+      <ReturnValue>
+        <ReturnType>System.Void</ReturnType>
+      </ReturnValue>
+      <Parameters>
+        <Parameter Name="iface" Type="System.Int32" />
+        <Parameter Name="proto" Type="Avahi.Protocol" />
+        <Parameter Name="flags" Type="Avahi.PublishFlags" />
+        <Parameter Name="name" Type="System.String" />
+        <Parameter Name="clazz" Type="Avahi.RecordClass" />
+        <Parameter Name="type" Type="Avahi.RecordType" />
+        <Parameter Name="ttl" Type="System.UInt32" />
+        <Parameter Name="rdata" Type="System.Byte[]" />
+        <Parameter Name="length" Type="System.Int32" />
+      </Parameters>
+      <Docs>
+        <param name="iface">To be added.</param>
+        <param name="proto">To be added.</param>
+        <param name="flags">To be added.</param>
+        <param name="name">To be added.</param>
+        <param name="clazz">To be added.</param>
+        <param name="type">To be added.</param>
+        <param name="ttl">To be added.</param>
+        <param name="rdata">To be added.</param>
+        <param name="length">To be added.</param>
+        <summary>To be added.</summary>
+        <remarks>To be added.</remarks>
+      </Docs>
+    </Member>
+    <Member MemberName="JoinServiceName">
+      <MemberSignature Language="C#" Value="public static string JoinServiceName (string name, string type, string domain);" />
+      <MemberType>Method</MemberType>
+      <ReturnValue>
+        <ReturnType>System.String</ReturnType>
+      </ReturnValue>
+      <Parameters>
+        <Parameter Name="name" Type="System.String" />
+        <Parameter Name="type" Type="System.String" />
+        <Parameter Name="domain" Type="System.String" />
+      </Parameters>
+      <Docs>
+        <param name="name">To be added.</param>
+        <param name="type">To be added.</param>
+        <param name="domain">To be added.</param>
+        <summary>To be added.</summary>
+        <returns>To be added.</returns>
+        <remarks>To be added.</remarks>
+      </Docs>
+    </Member>
+    <Member MemberName="SplitServiceName">
+      <MemberSignature Language="C#" Value="public static void SplitServiceName (string service, out string name, out string type, out string domain);" />
+      <MemberType>Method</MemberType>
+      <ReturnValue>
+        <ReturnType>System.Void</ReturnType>
+      </ReturnValue>
+      <Parameters>
+        <Parameter Name="service" Type="System.String" />
+        <Parameter Name="name" Type="System.String&amp;" RefType="out" />
+        <Parameter Name="type" Type="System.String&amp;" RefType="out" />
+        <Parameter Name="domain" Type="System.String&amp;" RefType="out" />
+      </Parameters>
+      <Docs>
+        <param name="service">To be added.</param>
+        <param name="name">To be added.</param>
+        <param name="type">To be added.</param>
+        <param name="domain">To be added.</param>
+        <summary>To be added.</summary>
+        <remarks>To be added.</remarks>
+      </Docs>
+    </Member>
   </Members>
   <Docs>
     <summary>To be added.</summary>