Mono.Zeroconf – Diff between revs 1 and 2

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 1 Rev 2
1 // 1 //
2 // Native.cs 2 // Native.cs
3 // 3 //
4 // Authors: 4 // Authors:
5 // Aaron Bockover <abockover@novell.com> 5 // Aaron Bockover <abockover@novell.com>
6 // 6 //
7 // Copyright (C) 2006-2007 Novell, Inc (http://www.novell.com) 7 // Copyright (C) 2006-2007 Novell, Inc (http://www.novell.com)
8 // 8 //
9 // Permission is hereby granted, free of charge, to any person obtaining 9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the 10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including 11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish, 12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to 13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to 14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions: 15 // the following conditions:
16 // 16 //
17 // The above copyright notice and this permission notice shall be 17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software. 18 // included in all copies or substantial portions of the Software.
19 // 19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 // 27 //
28   28  
29 using System; 29 using System;
-   30 using System.Text;
30 using System.Runtime.InteropServices; 31 using System.Runtime.InteropServices;
31   32  
32 namespace Mono.Zeroconf.Providers.Bonjour 33 namespace Mono.Zeroconf.Providers.Bonjour
33 { 34 {
34 public static class Native 35 public static class Native
35 { 36 {
36 // ServiceRef 37 // ServiceRef
37 38
38 [DllImport("dnssd.dll")] 39 [DllImport("dnssd.dll")]
39 public static extern void DNSServiceRefDeallocate(IntPtr sdRef); 40 public static extern void DNSServiceRefDeallocate(IntPtr sdRef);
40 41
41 [DllImport("dnssd.dll")] 42 [DllImport("dnssd.dll")]
42 public static extern ServiceError DNSServiceProcessResult(IntPtr sdRef); 43 public static extern ServiceError DNSServiceProcessResult(IntPtr sdRef);
43 44
44 [DllImport("dnssd.dll")] 45 [DllImport("dnssd.dll")]
45 public static extern int DNSServiceRefSockFD(IntPtr sdRef); 46 public static extern int DNSServiceRefSockFD(IntPtr sdRef);
46 47
47 [DllImport("dnssd.dll")] 48 [DllImport("dnssd.dll")]
48 public static extern ServiceError DNSServiceCreateConnection(out ServiceRef sdRef); 49 public static extern ServiceError DNSServiceCreateConnection(out ServiceRef sdRef);
49 50
50 // DNSServiceBrowse 51 // DNSServiceBrowse
51 52
52 public delegate void DNSServiceBrowseReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex, 53 public delegate void DNSServiceBrowseReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex,
53 ServiceError errorCode, string serviceName, string regtype, string replyDomain, 54 ServiceError errorCode, IntPtr serviceName, string regtype, string replyDomain,
54 IntPtr context); 55 IntPtr context);
55 56
56 [DllImport("dnssd.dll")] 57 [DllImport("dnssd.dll")]
57 public static extern ServiceError DNSServiceBrowse(out ServiceRef sdRef, ServiceFlags flags, 58 public static extern ServiceError DNSServiceBrowse(out ServiceRef sdRef, ServiceFlags flags,
58 uint interfaceIndex, string regtype, string domain, DNSServiceBrowseReply callBack, 59 uint interfaceIndex, string regtype, string domain, DNSServiceBrowseReply callBack,
59 IntPtr context); 60 IntPtr context);
60 61
61 // DNSServiceResolve 62 // DNSServiceResolve
62 63
63 public delegate void DNSServiceResolveReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex, 64 public delegate void DNSServiceResolveReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex,
64 ServiceError errorCode, string fullname, string hosttarget, ushort port, ushort txtLen, 65 ServiceError errorCode, IntPtr fullname, string hosttarget, ushort port, ushort txtLen,
65 IntPtr txtRecord, IntPtr context); 66 IntPtr txtRecord, IntPtr context);
66 67
67 [DllImport("dnssd.dll")] 68 [DllImport("dnssd.dll")]
68 public static extern ServiceError DNSServiceResolve(out ServiceRef sdRef, ServiceFlags flags, 69 public static extern ServiceError DNSServiceResolve(out ServiceRef sdRef, ServiceFlags flags,
69 uint interfaceIndex, string name, string regtype, string domain, DNSServiceResolveReply callBack, 70 uint interfaceIndex, byte[] name, string regtype, string domain, DNSServiceResolveReply callBack,
70 IntPtr context); 71 IntPtr context);
71 72
72 // DNSServiceRegister 73 // DNSServiceRegister
73 74
74 public delegate void DNSServiceRegisterReply(ServiceRef sdRef, ServiceFlags flags, ServiceError errorCode, 75 public delegate void DNSServiceRegisterReply(ServiceRef sdRef, ServiceFlags flags, ServiceError errorCode,
75 string name, string regtype, string domain, IntPtr context); 76 IntPtr name, string regtype, string domain, IntPtr context);
-   77  
76 78  
77 [DllImport("dnssd.dll")] 79 [DllImport("dnssd.dll")]
78 public static extern ServiceError DNSServiceRegister(out ServiceRef sdRef, ServiceFlags flags, 80 public static extern ServiceError DNSServiceRegister(out ServiceRef sdRef, ServiceFlags flags,
79 uint interfaceIndex, string name, string regtype, string domain, string host, ushort port, 81 uint interfaceIndex, byte[] name, string regtype, string domain, string host, ushort port,
80 ushort txtLen, byte [] txtRecord, DNSServiceRegisterReply callBack, IntPtr context); 82 ushort txtLen, byte [] txtRecord, DNSServiceRegisterReply callBack, IntPtr context);
81   83  
82 // DNSServiceQueryRecord 84 // DNSServiceQueryRecord
83 85
84 public delegate void DNSServiceQueryRecordReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex, 86 public delegate void DNSServiceQueryRecordReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex,
85 ServiceError errorCode, string fullname, ServiceType rrtype, ServiceClass rrclass, ushort rdlen, 87 ServiceError errorCode, string fullname, ServiceType rrtype, ServiceClass rrclass, ushort rdlen,
86 IntPtr rdata, uint ttl, IntPtr context); 88 IntPtr rdata, uint ttl, IntPtr context);
87 89
88 [DllImport("dnssd.dll")] 90 [DllImport("dnssd.dll")]
89 public static extern ServiceError DNSServiceQueryRecord(out ServiceRef sdRef, ServiceFlags flags, 91 public static extern ServiceError DNSServiceQueryRecord(out ServiceRef sdRef, ServiceFlags flags,
90 uint interfaceIndex, string fullname, ServiceType rrtype, ServiceClass rrclass, 92 uint interfaceIndex, string fullname, ServiceType rrtype, ServiceClass rrclass,
91 DNSServiceQueryRecordReply callBack, IntPtr context); 93 DNSServiceQueryRecordReply callBack, IntPtr context);
92 94
93 // TXT Record Handling 95 // TXT Record Handling
94 96
95 [DllImport("dnssd.dll")] 97 [DllImport("dnssd.dll")]
96 public static extern void TXTRecordCreate( IntPtr txtRecord, ushort bufferLen, IntPtr buffer); 98 public static extern void TXTRecordCreate( IntPtr txtRecord, ushort bufferLen, IntPtr buffer);
97 99
98 [DllImport("dnssd.dll")] 100 [DllImport("dnssd.dll")]
99 public static extern void TXTRecordDeallocate(IntPtr txtRecord); 101 public static extern void TXTRecordDeallocate(IntPtr txtRecord);
100 102
101 [DllImport("dnssd.dll")] 103 [DllImport("dnssd.dll")]
102 public static extern ServiceError TXTRecordGetItemAtIndex(ushort txtLen, IntPtr txtRecord, 104 public static extern ServiceError TXTRecordGetItemAtIndex(ushort txtLen, IntPtr txtRecord,
103 ushort index, ushort keyBufLen, byte [] key, out byte valueLen, out IntPtr value); 105 ushort index, ushort keyBufLen, byte [] key, out byte valueLen, out IntPtr value);
104 106
105 [DllImport("dnssd.dll")] 107 [DllImport("dnssd.dll")]
106 public static extern ServiceError TXTRecordSetValue(IntPtr txtRecord, byte [] key, 108 public static extern ServiceError TXTRecordSetValue(IntPtr txtRecord, byte [] key,
107 sbyte valueSize, byte [] value); 109 sbyte valueSize, byte [] value);
108 110
109 [DllImport("dnssd.dll")] 111 [DllImport("dnssd.dll")]
110 public static extern ServiceError TXTRecordRemoveValue(IntPtr txtRecord, byte [] key); 112 public static extern ServiceError TXTRecordRemoveValue(IntPtr txtRecord, byte [] key);
111 113
112 [DllImport("dnssd.dll")] 114 [DllImport("dnssd.dll")]
113 public static extern ushort TXTRecordGetLength(IntPtr txtRecord); 115 public static extern ushort TXTRecordGetLength(IntPtr txtRecord);
114 116
115 [DllImport("dnssd.dll")] 117 [DllImport("dnssd.dll")]
116 public static extern IntPtr TXTRecordGetBytesPtr(IntPtr txtRecord); 118 public static extern IntPtr TXTRecordGetBytesPtr(IntPtr txtRecord);
117 119
118 [DllImport("dnssd.dll")] 120 [DllImport("dnssd.dll")]
119 public static extern ushort TXTRecordGetCount(ushort txtLen, IntPtr txtRecord); 121 public static extern ushort TXTRecordGetCount(ushort txtLen, IntPtr txtRecord);
-   122  
-   123 public static string Utf8toString(IntPtr ptr)
-   124 {
-   125 int len = 0;
-   126 while (Marshal.ReadByte(ptr, len) != 0)
-   127 {
-   128 len++;
-   129 }
-   130 byte[] raw = new byte[len];
-   131 Marshal.Copy(ptr, raw, 0, len);
-   132 return Encoding.UTF8.GetString(raw);
-   133 }
120 } 134 }
121 } 135 }
122   136