diff options
author | James Willcox <snopr@snorp.net> | 2005-09-09 20:48:41 +0000 |
---|---|---|
committer | James Willcox <snopr@snorp.net> | 2005-09-09 20:48:41 +0000 |
commit | 223014183d626cd4cf6fb2cb7b17319375688138 (patch) | |
tree | a7c02650b51fec8eafceb3397741ff03d46d1f46 | |
parent | 8a3450396a4d60565b34cbce73aa03eb61389bb0 (diff) |
add some data access api to string list, and use it in ServiceResolver
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@550 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
-rw-r--r-- | avahi-common/strlst.c | 15 | ||||
-rw-r--r-- | avahi-common/strlst.h | 9 | ||||
-rw-r--r-- | avahi-sharp/AvahiTest.cs | 4 | ||||
-rw-r--r-- | avahi-sharp/ServiceResolver.cs | 22 |
4 files changed, 49 insertions, 1 deletions
diff --git a/avahi-common/strlst.c b/avahi-common/strlst.c index 0c61857..72a0059 100644 --- a/avahi-common/strlst.c +++ b/avahi-common/strlst.c @@ -446,3 +446,18 @@ int avahi_string_list_get_pair(AvahiStringList *l, char **key, char **value, siz return 0; } + +AvahiStringList *avahi_string_list_get_next(AvahiStringList *l) { + assert(l); + return l->next; +} + +const uint8_t *avahi_string_list_get_text(AvahiStringList *l) { + assert(l); + return l->text; +} + +size_t avahi_string_list_get_size(AvahiStringList *l) { + assert(l); + return l->size; +} diff --git a/avahi-common/strlst.h b/avahi-common/strlst.h index 47fd14b..0f8c8d4 100644 --- a/avahi-common/strlst.h +++ b/avahi-common/strlst.h @@ -133,6 +133,15 @@ AvahiStringList *avahi_string_list_add_pair(AvahiStringList *l, const char *key, /** Same as avahi_string_list_add_pair() but allow strings containing NUL bytes in *value. */ AvahiStringList *avahi_string_list_add_pair_arbitrary(AvahiStringList *l, const char *key, const uint8_t *value, size_t size); +/** Returns the next item in the string list */ +AvahiStringList *avahi_string_list_get_next(AvahiStringList *l); + +/** Returns the text for the current item */ +const uint8_t *avahi_string_list_get_text(AvahiStringList *l); + +/** Returns the size of the current text */ +size_t avahi_string_list_get_size(AvahiStringList *l); + AVAHI_C_DECL_END #endif diff --git a/avahi-sharp/AvahiTest.cs b/avahi-sharp/AvahiTest.cs index 1679ee2..7be4b06 100644 --- a/avahi-sharp/AvahiTest.cs +++ b/avahi-sharp/AvahiTest.cs @@ -20,6 +20,7 @@ ***/ using System; +using System.Text; using System.Net; using Gtk; using Avahi; @@ -73,6 +74,9 @@ public class AvahiTest { private static void OnServiceResolved (object o, ServiceInfo info) { Console.WriteLine ("Service '{0}' at {1}:{2}", info.Name, info.Host, info.Port); + foreach (byte[] bytes in info.Text) { + Console.WriteLine ("Text: " + Encoding.UTF8.GetString (bytes)); + } AddressResolver ar = new AddressResolver (client, info.Address); ar.Found += OnAddressResolved; } diff --git a/avahi-sharp/ServiceResolver.cs b/avahi-sharp/ServiceResolver.cs index 7737994..1b5d51a 100644 --- a/avahi-sharp/ServiceResolver.cs +++ b/avahi-sharp/ServiceResolver.cs @@ -54,6 +54,15 @@ namespace Avahi Protocol aproto, ServiceResolverCallback cb, IntPtr userdata); + [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); + [DllImport ("avahi-client")] private static extern void avahi_service_resolver_free (IntPtr handle); @@ -161,8 +170,19 @@ namespace Avahi info.Host = Utility.PtrToString (host); info.Address = Utility.PtrToAddress (address); info.Port = port; - info.Text = null; + ArrayList txtlist = new ArrayList (); + 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); + } + + info.Text = (byte[][]) txtlist.ToArray (typeof (byte[])); + if (revent == ResolverEvent.Found) { currentInfo = info; |