diff options
author | James Willcox <snopr@snorp.net> | 2005-11-17 19:08:58 +0000 |
---|---|---|
committer | James Willcox <snopr@snorp.net> | 2005-11-17 19:08:58 +0000 |
commit | 84e07c25895dd6a8f706499a867afa44b9444ce2 (patch) | |
tree | 0a7f8a8218d9cae0c5538bb858a8ba4229fcaca0 /avahi-sharp | |
parent | 8bfdc03f068c79186402a73471f94563a8346757 (diff) |
* Add EntryGroup.UpdateService, EntryGroup.AddServiceSubtype,
EntryGroup.AddAddress, EntryGroup.AddRecord,
EntryGroup.JoinServiceName, EntryGroup.SplitServiceName
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@998 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'avahi-sharp')
-rw-r--r-- | avahi-sharp/AvahiTest.cs | 2 | ||||
-rw-r--r-- | avahi-sharp/EntryGroup.cs | 209 | ||||
-rw-r--r-- | avahi-sharp/en/Avahi/EntryGroup.xml | 245 |
3 files changed, 454 insertions, 2 deletions
diff --git a/avahi-sharp/AvahiTest.cs b/avahi-sharp/AvahiTest.cs index 0fac04b..df95b90 100644 --- a/avahi-sharp/AvahiTest.cs +++ b/avahi-sharp/AvahiTest.cs @@ -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, diff --git a/avahi-sharp/EntryGroup.cs b/avahi-sharp/EntryGroup.cs index 443f198..eb7d9e2 100644 --- a/avahi-sharp/EntryGroup.cs +++ b/avahi-sharp/EntryGroup.cs @@ -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); @@ -106,6 +127,16 @@ namespace Avahi 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); public event EntryGroupStateHandler StateChanged; @@ -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) { diff --git a/avahi-sharp/en/Avahi/EntryGroup.xml b/avahi-sharp/en/Avahi/EntryGroup.xml index 8c9ea28..2d71786 100644 --- a/avahi-sharp/en/Avahi/EntryGroup.xml +++ b/avahi-sharp/en/Avahi/EntryGroup.xml @@ -209,6 +209,251 @@ <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&" RefType="out" /> + <Parameter Name="type" Type="System.String&" RefType="out" /> + <Parameter Name="domain" Type="System.String&" 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> |