+
+ if (ret < 0) {
+ client.ThrowError ();
+ }
+ }
+
+ 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) {
+ list = avahi_string_list_add (list, Utility.StringToBytes (item));
+ }
+ }
+
+ UpdateService (iface, proto, flags, name, type, domain, list);
+ }
+
+ public void UpdateService (int iface, Protocol proto, PublishFlags flags, string name, string type,
+ string domain, params byte[][] txt)
+ {
+ IntPtr list = avahi_string_list_new (IntPtr.Zero);
+
+ if (txt != null) {
+ foreach (byte[] item in txt) {
+ list = avahi_string_list_add (list, item);
+ }
+ }
+
+ UpdateService (iface, proto, flags, name, type, domain, list);
+ }
+
+ private void UpdateService (int iface, Protocol proto, PublishFlags flags, string name, string type,
+ string domain, IntPtr list)
+ {
+ lock (client) {
+ int ret = avahi_entry_group_update_service_strlst (handle, iface, proto, flags,
+ Utility.StringToBytes (name),
+ Utility.StringToBytes (type),
+ Utility.StringToBytes (domain),
+ list);
+
+ 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)
+ {
+ lock (client) {
+ int ret = avahi_entry_group_add_service_subtype (handle, iface, proto, flags,
+ Utility.StringToBytes (name),
+ Utility.StringToBytes (type),
+ Utility.StringToBytes (domain),
+ Utility.StringToBytes (subtype));
+
+ 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 addressPtr = Utility.AddressToPtr (address);
+
+ lock (client) {
+ int ret = avahi_entry_group_add_address (handle, iface, proto, flags,
+ Utility.StringToBytes (name), addressPtr);
+
+ 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)
+ {
+ lock (client) {
+ int ret = avahi_entry_group_add_record (handle, iface, proto, flags,
+ Utility.StringToBytes (name),
+ clazz, type, ttl, rdata, length);
+
+ 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);
+
+ int ret = avahi_service_name_join (buf, len,
+ Utility.StringToBytes (name),
+ Utility.StringToBytes (type),
+ Utility.StringToBytes (domain));
+
+ 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 namePtr = Stdlib.malloc ((ulong) len);
+ IntPtr typePtr = Stdlib.malloc ((ulong) len);
+ IntPtr domainPtr = Stdlib.malloc ((ulong) len);
+
+ int ret = avahi_service_name_split (Utility.StringToBytes (service), namePtr, len, typePtr, len,
+ domainPtr, len);
+
+ 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);
+ }