]> git.meshlink.io Git - catta/blobdiff - avahi-sharp/HostNameResolver.cs
fix detection whether an interface has a routable address assigned on BSD. Patch...
[catta] / avahi-sharp / HostNameResolver.cs
index d522cea66425594164784853b41254b979d55f6d..81305fd778efd9c35b4ee3bdc7591b2e802d8de8 100644 (file)
@@ -23,6 +23,7 @@ using System;
 using System.Collections;
 using System.Net;
 using System.Runtime.InteropServices;
 using System.Collections;
 using System.Net;
 using System.Runtime.InteropServices;
+using System.Text;
 using Mono.Unix;
 
 namespace Avahi
 using Mono.Unix;
 
 namespace Avahi
@@ -30,9 +31,9 @@ namespace Avahi
 
     internal delegate void HostNameResolverCallback (IntPtr resolver, int iface, Protocol proto,
                                                      ResolverEvent revent, IntPtr hostname, IntPtr address,
 
     internal delegate void HostNameResolverCallback (IntPtr resolver, int iface, Protocol proto,
                                                      ResolverEvent revent, IntPtr hostname, IntPtr address,
-                                                     IntPtr userdata);
+                                                     LookupResultFlags flags, IntPtr userdata);
 
 
-    public class HostNameResolver : IDisposable
+    public class HostNameResolver : ResolverBase, IDisposable
     {
         private IntPtr handle;
         private Client client;
     {
         private IntPtr handle;
         private Client client;
@@ -40,6 +41,7 @@ namespace Avahi
         private Protocol proto;
         private string hostname;
         private Protocol aproto;
         private Protocol proto;
         private string hostname;
         private Protocol aproto;
+        private LookupFlags flags;
         private HostNameResolverCallback cb;
 
         private IPAddress currentAddress;
         private HostNameResolverCallback cb;
 
         private IPAddress currentAddress;
@@ -50,7 +52,7 @@ namespace Avahi
         
         [DllImport ("avahi-client")]
         private static extern IntPtr avahi_host_name_resolver_new (IntPtr client, int iface, Protocol proto,
         
         [DllImport ("avahi-client")]
         private static extern IntPtr avahi_host_name_resolver_new (IntPtr client, int iface, Protocol proto,
-                                                                   IntPtr hostname, Protocol aproto,
+                                                                   byte[] hostname, Protocol aproto, LookupFlags flags,
                                                                    HostNameResolverCallback cb, IntPtr userdata);
 
         [DllImport ("avahi-client")]
                                                                    HostNameResolverCallback cb, IntPtr userdata);
 
         [DllImport ("avahi-client")]
@@ -91,18 +93,20 @@ namespace Avahi
         }
 
         public HostNameResolver (Client client, string hostname) : this (client, -1, Protocol.Unspecified,
         }
 
         public HostNameResolver (Client client, string hostname) : this (client, -1, Protocol.Unspecified,
-                                                                         hostname, Protocol.Unspecified)
+                                                                         hostname, Protocol.Unspecified,
+                                                                         LookupFlags.None)
         {
         }
 
         public HostNameResolver (Client client, int iface, Protocol proto, string hostname,
         {
         }
 
         public HostNameResolver (Client client, int iface, Protocol proto, string hostname,
-                                 Protocol aproto)
+                                 Protocol aproto, LookupFlags flags)
         {
             this.client = client;
             this.iface = iface;
             this.proto = proto;
             this.hostname = hostname;
             this.aproto = aproto;
         {
             this.client = client;
             this.iface = iface;
             this.proto = proto;
             this.hostname = hostname;
             this.aproto = aproto;
+            this.flags = flags;
             cb = OnHostNameResolverCallback;
         }
 
             cb = OnHostNameResolverCallback;
         }
 
@@ -122,14 +126,14 @@ namespace Avahi
                 (foundListeners.Count == 0 && timeoutListeners.Count == 0))
                 return;
 
                 (foundListeners.Count == 0 && timeoutListeners.Count == 0))
                 return;
 
-            IntPtr hostPtr = Utility.StringToPtr (hostname);
-
             lock (client) {
             lock (client) {
-                handle = avahi_host_name_resolver_new (client.Handle, iface, proto, hostPtr, aproto,
+                handle = avahi_host_name_resolver_new (client.Handle, iface, proto,
+                                                       Utility.StringToBytes (hostname), aproto, flags,
                                                        cb, IntPtr.Zero);
                                                        cb, IntPtr.Zero);
+
+                if (handle == IntPtr.Zero)
+                    client.ThrowError ();
             }
             }
-            
-            Utility.Free (hostPtr);
         }
 
         private void Stop (bool force)
         }
 
         private void Stop (bool force)
@@ -146,20 +150,19 @@ namespace Avahi
 
         private void OnHostNameResolverCallback (IntPtr resolver, int iface, Protocol proto,
                                                  ResolverEvent revent, IntPtr hostname, IntPtr address,
 
         private void OnHostNameResolverCallback (IntPtr resolver, int iface, Protocol proto,
                                                  ResolverEvent revent, IntPtr hostname, IntPtr address,
-                                                 IntPtr userdata)
+                                                 LookupResultFlags flags, IntPtr userdata)
         {
         {
-            if (revent == ResolverEvent.Found) {
+            switch (revent) {
+            case ResolverEvent.Found:
                 currentAddress = Utility.PtrToAddress (address);
                 currentHost = Utility.PtrToString (hostname);
 
                 foreach (HostAddressHandler handler in foundListeners)
                 currentAddress = Utility.PtrToAddress (address);
                 currentHost = Utility.PtrToString (hostname);
 
                 foreach (HostAddressHandler handler in foundListeners)
-                    handler (this, currentHost, currentAddress);
-            } else {
-                currentAddress = null;
-                currentHost = null;
-                
-                foreach (EventHandler handler in timeoutListeners)
-                    handler (this, new EventArgs ());
+                    handler (this, new HostAddressArgs (currentHost, currentAddress));
+                break;
+            case ResolverEvent.Failure:
+                EmitFailure (client.LastError);
+                break;
             }
         }
     }
             }
         }
     }