/trunk/Mono.Zeroconf.sln |
@@ -1,6 +1,8 @@ |
 |
Microsoft Visual Studio Solution File, Format Version 9.00 |
# Visual C# Express 2005 |
Microsoft Visual Studio Solution File, Format Version 12.00 |
# Visual Studio 15 |
VisualStudioVersion = 15.0.28307.572 |
MinimumVisualStudioVersion = 10.0.40219.1 |
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MZClient", "src\MZClient\MZClient.csproj", "{839D9048-31CF-4010-B427-6A8362556485}" |
EndProject |
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Zeroconf", "src\Mono.Zeroconf\Mono.Zeroconf.csproj", "{5CF88E3A-13DD-4114-BAD9-DA826946516F}" |
@@ -14,21 +16,23 @@ |
Debug|Any CPU = Debug|Any CPU |
EndGlobalSection |
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
{839D9048-31CF-4010-B427-6A8362556485}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
{839D9048-31CF-4010-B427-6A8362556485}.Debug|Any CPU.Build.0 = Debug|Any CPU |
{5CF88E3A-13DD-4114-BAD9-DA826946516F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
{5CF88E3A-13DD-4114-BAD9-DA826946516F}.Debug|Any CPU.Build.0 = Debug|Any CPU |
{623325E2-5821-4701-A40C-3759097008DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
{623325E2-5821-4701-A40C-3759097008DD}.Debug|Any CPU.Build.0 = Debug|Any CPU |
{839D9048-31CF-4010-B427-6A8362556485}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
{839D9048-31CF-4010-B427-6A8362556485}.Debug|Any CPU.Build.0 = Debug|Any CPU |
{EF6ED6D1-D201-42ED-B680-5A77641BEB77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
{EF6ED6D1-D201-42ED-B680-5A77641BEB77}.Debug|Any CPU.Build.0 = Debug|Any CPU |
EndGlobalSection |
GlobalSection(SolutionProperties) = preSolution |
HideSolutionNode = FALSE |
EndGlobalSection |
GlobalSection(ExtensibilityGlobals) = postSolution |
SolutionGuid = {408D8048-93CB-4BFE-90EE-9A3466056346} |
EndGlobalSection |
GlobalSection(MonoDevelopProperties) = preSolution |
name = Mono.Zeroconf |
version = 0.1 |
StartupItem = src\MZClient\MZClient.csproj |
EndGlobalSection |
GlobalSection(SolutionProperties) = preSolution |
HideSolutionNode = FALSE |
EndGlobalSection |
EndGlobal |
/trunk/src/MZClient/MZClient.csproj |
@@ -1,5 +1,5 @@ |
<?xml version="1.0" encoding="utf-8"?> |
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="15.0"> |
<PropertyGroup> |
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
@@ -13,6 +13,11 @@ |
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion> |
<FileAlignment>512</FileAlignment> |
<StartupObject>MZClient</StartupObject> |
<FileUpgradeFlags> |
</FileUpgradeFlags> |
<UpgradeBackupLocation> |
</UpgradeBackupLocation> |
<OldToolsVersion>2.0</OldToolsVersion> |
</PropertyGroup> |
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
<DebugSymbols>true</DebugSymbols> |
/trunk/src/Mono.Zeroconf/Mono.Zeroconf.Providers/ProviderFactory.cs |
@@ -90,18 +90,28 @@ |
directories.Add(Path.Combine(new_path, "mono-zeroconf")); |
} |
|
foreach(string directory in directories) { |
foreach(string file in Directory.GetFiles(directory, "Mono.Zeroconf.Providers.*.dll")) { |
if(Path.GetFileName(file) != Path.GetFileName(this_asm_path)) { |
try |
{ |
foreach (string directory in directories) |
{ |
foreach (string file in Directory.GetFiles(directory, "Mono.Zeroconf.Providers.*.dll")) |
{ |
if (Path.GetFileName(file) != Path.GetFileName(this_asm_path)) |
{ |
Assembly provider_asm = Assembly.LoadFile(file); |
foreach(Attribute attr in provider_asm.GetCustomAttributes(false)) { |
if(attr is ZeroconfProviderAttribute) { |
foreach (Attribute attr in provider_asm.GetCustomAttributes(false)) |
{ |
if (attr is ZeroconfProviderAttribute) |
{ |
Type type = (attr as ZeroconfProviderAttribute).ProviderType; |
IZeroconfProvider provider = (IZeroconfProvider)Activator.CreateInstance(type); |
try { |
try |
{ |
provider.Initialize(); |
providers_list.Add(provider); |
} catch (Exception e) { |
} |
catch (Exception e) |
{ |
Console.WriteLine (e); |
} |
} |
@@ -109,6 +119,11 @@ |
} |
} |
} |
} |
catch |
{ |
// Could not load a provider. |
} |
|
if(providers_list.Count == 0) { |
throw new Exception("No Zeroconf providers could be found or initialized. Necessary daemon may not be running."); |
/trunk/src/Mono.Zeroconf/Mono.Zeroconf.csproj |
@@ -1,5 +1,5 @@ |
<?xml version="1.0" encoding="utf-8"?> |
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="15.0"> |
<PropertyGroup> |
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
@@ -12,6 +12,11 @@ |
<AssemblyName>Mono.Zeroconf</AssemblyName> |
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion> |
<FileAlignment>512</FileAlignment> |
<FileUpgradeFlags> |
</FileUpgradeFlags> |
<UpgradeBackupLocation> |
</UpgradeBackupLocation> |
<OldToolsVersion>2.0</OldToolsVersion> |
</PropertyGroup> |
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
<DebugSymbols>true</DebugSymbols> |
/trunk/src/Mono.Zeroconf.Providers.AvahiDBus/Mono.Zeroconf.Providers.AvahiDBus/RegisterService.cs |
@@ -39,6 +39,9 @@ |
|
public event RegisterServiceEventHandler Response; |
|
private string originalName; |
private int retryNameModifier = 2; |
|
public RegisterService () |
{ |
} |
@@ -95,12 +98,20 @@ |
switch (state) { |
case EntryGroupState.Collision: |
if (!OnResponse (ErrorCode.Collision)) { |
throw new ApplicationException (); |
if (originalName == null) |
originalName = Name; |
|
Name = originalName + " (" + retryNameModifier + ")"; |
retryNameModifier++; |
|
Console.WriteLine("ZeroConf had a name collision, trying: " + Name); |
|
Register(); |
} |
break; |
case EntryGroupState.Failure: |
if (!OnResponse (ErrorCode.Failure)) { |
throw new ApplicationException (); |
Console.WriteLine("Mono.ZeroConf failed to register name with AvahiDBus"); |
} |
break; |
case EntryGroupState.Established: |
/trunk/src/Mono.Zeroconf.Providers.AvahiDBus/Mono.Zeroconf.Providers.AvahiDBus.csproj |
@@ -1,5 +1,5 @@ |
<?xml version="1.0" encoding="utf-8"?> |
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="15.0"> |
<PropertyGroup> |
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
@@ -9,6 +9,12 @@ |
<OutputType>Library</OutputType> |
<AssemblyName>Mono.Zeroconf.Providers.AvahiDBus</AssemblyName> |
<UseParentDirectoryAsNamespace>true</UseParentDirectoryAsNamespace> |
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion> |
<FileUpgradeFlags> |
</FileUpgradeFlags> |
<UpgradeBackupLocation> |
</UpgradeBackupLocation> |
<OldToolsVersion>2.0</OldToolsVersion> |
</PropertyGroup> |
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
<DebugSymbols>true</DebugSymbols> |
/trunk/src/Mono.Zeroconf.Providers.Bonjour/Mono.Zeroconf.Providers.Bonjour/BrowseService.cs |
@@ -58,11 +58,18 @@ |
{ |
resolve_reply_handler = new Native.DNSServiceResolveReply(OnResolveReply); |
query_record_reply_handler = new Native.DNSServiceQueryRecordReply(OnQueryRecordReply); |
resolveAction = new Action<bool>(Resolve); |
} |
|
private Action<bool> resolveAction; |
|
public void Resolve() |
{ |
Resolve(false); |
// If people call this in a ServiceAdded eventhandler (which they genreally do) |
// We need to invoke onto another thread otherwise we block processing any more results. |
|
resolveAction.BeginInvoke(false, null, null); |
} |
|
public void Resolve(bool requery) |
@@ -80,7 +87,7 @@ |
|
ServiceRef sd_ref; |
ServiceError error = Native.DNSServiceResolve(out sd_ref, ServiceFlags.None, |
InterfaceIndex, Name, RegType, ReplyDomain, resolve_reply_handler, IntPtr.Zero); |
InterfaceIndex, Encoding.UTF8.GetBytes(Name), RegType, ReplyDomain, resolve_reply_handler, IntPtr.Zero); |
|
if(error != ServiceError.NoError) { |
throw new ServiceErrorException(error); |
@@ -105,7 +112,7 @@ |
} |
|
private void OnResolveReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex, |
ServiceError errorCode, string fullname, string hosttarget, ushort port, ushort txtLen, |
ServiceError errorCode, IntPtr fullname, string hosttarget, ushort port, ushort txtLen, |
IntPtr txtRecord, IntPtr contex) |
{ |
is_resolved = true; |
@@ -112,9 +119,10 @@ |
resolve_pending = false; |
|
InterfaceIndex = interfaceIndex; |
FullName = fullname; |
this.port = port; |
FullName = Native.Utf8toString(fullname); |
this.port = (ushort)IPAddress.NetworkToHostOrder((short)port); |
TxtRecord = new TxtRecord(txtLen, txtRecord); |
this.hosttarget = hosttarget; |
|
sdRef.Deallocate(); |
|
@@ -142,7 +150,16 @@ |
|
sd_ref.Process(); |
} |
|
if (hostentry.AddressList != null) |
{ |
ServiceResolvedEventHandler handler = Resolved; |
if (handler != null) |
{ |
handler(this, new ServiceResolvedEventArgs(this)); |
} |
} |
} |
|
private void OnQueryRecordReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex, |
ServiceError errorCode, string fullname, ServiceType rrtype, ServiceClass rrclass, ushort rdlen, |
@@ -150,6 +167,7 @@ |
{ |
switch(rrtype) { |
case ServiceType.A: |
case ServiceType.AAAA: |
IPAddress address; |
|
if(rdlen == 4) { |
@@ -198,8 +216,12 @@ |
break; |
} |
|
|
if ((flags & ServiceFlags.MoreComing) != ServiceFlags.MoreComing) |
{ |
sdRef.Deallocate(); |
} |
} |
|
public bool IsResolved { |
get { return is_resolved; } |
/trunk/src/Mono.Zeroconf.Providers.Bonjour/Mono.Zeroconf.Providers.Bonjour/Native.cs |
@@ -27,6 +27,7 @@ |
// |
|
using System; |
using System.Text; |
using System.Runtime.InteropServices; |
|
namespace Mono.Zeroconf.Providers.Bonjour |
@@ -50,7 +51,7 @@ |
// DNSServiceBrowse |
|
public delegate void DNSServiceBrowseReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex, |
ServiceError errorCode, string serviceName, string regtype, string replyDomain, |
ServiceError errorCode, IntPtr serviceName, string regtype, string replyDomain, |
IntPtr context); |
|
[DllImport("dnssd.dll")] |
@@ -61,22 +62,23 @@ |
// DNSServiceResolve |
|
public delegate void DNSServiceResolveReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex, |
ServiceError errorCode, string fullname, string hosttarget, ushort port, ushort txtLen, |
ServiceError errorCode, IntPtr fullname, string hosttarget, ushort port, ushort txtLen, |
IntPtr txtRecord, IntPtr context); |
|
[DllImport("dnssd.dll")] |
public static extern ServiceError DNSServiceResolve(out ServiceRef sdRef, ServiceFlags flags, |
uint interfaceIndex, string name, string regtype, string domain, DNSServiceResolveReply callBack, |
uint interfaceIndex, byte[] name, string regtype, string domain, DNSServiceResolveReply callBack, |
IntPtr context); |
|
// DNSServiceRegister |
|
public delegate void DNSServiceRegisterReply(ServiceRef sdRef, ServiceFlags flags, ServiceError errorCode, |
string name, string regtype, string domain, IntPtr context); |
IntPtr name, string regtype, string domain, IntPtr context); |
|
|
[DllImport("dnssd.dll")] |
public static extern ServiceError DNSServiceRegister(out ServiceRef sdRef, ServiceFlags flags, |
uint interfaceIndex, string name, string regtype, string domain, string host, ushort port, |
uint interfaceIndex, byte[] name, string regtype, string domain, string host, ushort port, |
ushort txtLen, byte [] txtRecord, DNSServiceRegisterReply callBack, IntPtr context); |
|
// DNSServiceQueryRecord |
@@ -117,5 +119,17 @@ |
|
[DllImport("dnssd.dll")] |
public static extern ushort TXTRecordGetCount(ushort txtLen, IntPtr txtRecord); |
|
public static string Utf8toString(IntPtr ptr) |
{ |
int len = 0; |
while (Marshal.ReadByte(ptr, len) != 0) |
{ |
len++; |
} |
byte[] raw = new byte[len]; |
Marshal.Copy(ptr, raw, 0, len); |
return Encoding.UTF8.GetString(raw); |
} |
} |
} |
/trunk/src/Mono.Zeroconf.Providers.Bonjour/Mono.Zeroconf.Providers.Bonjour/RegisterService.cs |
@@ -30,6 +30,7 @@ |
using System.Net; |
using System.Threading; |
using System.Runtime.InteropServices; |
using System.Text; |
|
namespace Mono.Zeroconf.Providers.Bonjour |
{ |
@@ -107,7 +108,7 @@ |
|
ServiceError error = Native.DNSServiceRegister(out sd_ref, |
auto_rename ? ServiceFlags.None : ServiceFlags.NoAutoRename, InterfaceIndex, |
Name, RegType, ReplyDomain, HostTarget, (ushort)IPAddress.HostToNetworkOrder((short)port), txt_rec_length, txt_rec, |
Encoding.UTF8.GetBytes(Name), RegType, ReplyDomain, HostTarget, (ushort)IPAddress.HostToNetworkOrder((short)port), txt_rec_length, txt_rec, |
register_reply_handler, IntPtr.Zero); |
|
if(error != ServiceError.NoError) { |
@@ -128,7 +129,7 @@ |
} |
|
private void OnRegisterReply(ServiceRef sdRef, ServiceFlags flags, ServiceError errorCode, |
string name, string regtype, string domain, IntPtr context) |
IntPtr name, string regtype, string domain, IntPtr context) |
{ |
RegisterServiceEventArgs args = new RegisterServiceEventArgs(); |
|
@@ -137,7 +138,7 @@ |
args.ServiceError = (ServiceErrorCode)errorCode; |
|
if(errorCode == ServiceError.NoError) { |
Name = name; |
Name = Native.Utf8toString(name); |
RegType = regtype; |
ReplyDomain = domain; |
args.IsRegistered = true; |
/trunk/src/Mono.Zeroconf.Providers.Bonjour/Mono.Zeroconf.Providers.Bonjour/ServiceBrowser.cs |
@@ -168,11 +168,12 @@ |
} |
|
private void OnBrowseReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex, ServiceError errorCode, |
string serviceName, string regtype, string replyDomain, IntPtr context) |
IntPtr serviceName, string regtype, string replyDomain, IntPtr context) |
{ |
string name = Native.Utf8toString(serviceName); |
BrowseService service = new BrowseService(); |
service.Flags = flags; |
service.Name = serviceName; |
service.Name = name; |
service.RegType = regtype; |
service.ReplyDomain = replyDomain; |
service.InterfaceIndex = interfaceIndex; |
@@ -183,10 +184,10 @@ |
|
if((flags & ServiceFlags.Add) != 0) { |
lock (service_table) { |
if (service_table.ContainsKey (serviceName)) { |
service_table[serviceName] = service; |
if (service_table.ContainsKey (name)) { |
service_table[name] = service; |
} else { |
service_table.Add (serviceName, service); |
service_table.Add(name, service); |
} |
} |
|
@@ -196,8 +197,8 @@ |
} |
} else { |
lock (service_table) { |
if (service_table.ContainsKey (serviceName)) { |
service_table.Remove (serviceName); |
if (service_table.ContainsKey (name)) { |
service_table.Remove (name); |
} |
} |
|
/trunk/src/Mono.Zeroconf.Providers.Bonjour/Mono.Zeroconf.Providers.Bonjour.csproj |
@@ -1,5 +1,5 @@ |
<?xml version="1.0" encoding="utf-8"?> |
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="15.0"> |
<PropertyGroup> |
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
@@ -12,6 +12,11 @@ |
<AssemblyName>Mono.Zeroconf.Providers.Bonjour</AssemblyName> |
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion> |
<FileAlignment>512</FileAlignment> |
<FileUpgradeFlags> |
</FileUpgradeFlags> |
<UpgradeBackupLocation> |
</UpgradeBackupLocation> |
<OldToolsVersion>2.0</OldToolsVersion> |
</PropertyGroup> |
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
<DebugSymbols>true</DebugSymbols> |