StringToBytes() public static method

public static StringToBytes ( string str ) : byte[]
str string
return byte[]
Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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();
                }
            }
        }
Ejemplo n.º 3
0
        private static IntPtr StringToPtr(string str)
        {
            if (str == null)
            {
                return(IntPtr.Zero);
            }

            byte[] bytes = Utility.StringToBytes(str);
            IntPtr buf   = Stdlib.malloc((uint)bytes.Length + 1);

            Marshal.Copy(bytes, 0, buf, bytes.Length);
            Marshal.WriteByte(buf, bytes.Length, 0);
            return(buf);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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();
                }
            }
        }
Ejemplo n.º 6
0
        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();
                }
            }
        }
Ejemplo n.º 7
0
        private void Start()
        {
            if (client.Handle == IntPtr.Zero || handle != IntPtr.Zero ||
                (addListeners.Count == 0 && removeListeners.Count == 0))
            {
                return;
            }

            lock (client) {
                handle = avahi_record_browser_new(client.Handle, iface, proto, Utility.StringToBytes(name),
                                                  (ushort)clazz, (ushort)type, flags, cb, IntPtr.Zero);

                if (handle == IntPtr.Zero)
                {
                    client.ThrowError();
                }
            }
        }
Ejemplo n.º 8
0
        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();
                }
            }
        }
        private void Start()
        {
            if (client.Handle == IntPtr.Zero || handle != IntPtr.Zero ||
                (addListeners.Count == 0 && removeListeners.Count == 0))
            {
                return;
            }

            lock (client) {
                handle = avahi_service_type_browser_new(client.Handle, iface, (int)proto,
                                                        Utility.StringToBytes(domain), flags,
                                                        cb, IntPtr.Zero);

                if (handle == IntPtr.Zero)
                {
                    client.ThrowError();
                }
            }
        }
Ejemplo n.º 10
0
        private void Start()
        {
            if (client.Handle == IntPtr.Zero || handle != IntPtr.Zero ||
                (foundListeners.Count == 0 && timeoutListeners.Count == 0))
            {
                return;
            }

            lock (client) {
                handle = avahi_host_name_resolver_new(client.Handle, iface, proto,
                                                      Utility.StringToBytes(hostname), aproto, flags,
                                                      cb, IntPtr.Zero);

                if (handle == IntPtr.Zero)
                {
                    client.ThrowError();
                }
            }
        }
Ejemplo n.º 11
0
        private void AddService(int iface, Protocol proto, PublishFlags flags, string name, string type,
                                string domain, string host, UInt16 port, IntPtr list)
        {
            int ret;

            lock (client) {
                ret = avahi_entry_group_add_service_strlst(handle, iface, proto, flags,
                                                           Utility.StringToBytes(name),
                                                           Utility.StringToBytes(type),
                                                           Utility.StringToBytes(domain),
                                                           Utility.StringToBytes(host), port, list);
            }

            avahi_string_list_free(list);

            if (ret < 0)
            {
                client.ThrowError();
            }
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
 public static string GetAlternativeServiceName(string name)
 {
     return(Utility.PtrToStringFree(avahi_alternative_service_name(Utility.StringToBytes(name))));
 }