Imported Upstream version 4.6.0.125

Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-08-03 10:59:49 +00:00
parent a569aebcfd
commit e79aa3c0ed
17047 changed files with 3137615 additions and 392334 deletions

View File

@@ -0,0 +1,64 @@
using System;
using System.ComponentModel;
namespace System.Net.Sockets
{
//introduced for supporting design-time loading of System.Windows.dll
[Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
public class HttpPolicyDownloaderProtocol
{
//introduced for supporting design-time loading of System.Windows.dll
[Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
public HttpPolicyDownloaderProtocol(Uri appUri, IPAddress address) { }
//introduced for supporting design-time loading of System.Windows.dll
[Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
public void Abort() { }
//introduced for supporting design-time loading of System.Windows.dll
[Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
public void BeginDownload(SecurityCriticalAction callback) { }
//introduced for supporting design-time loading of System.Windows.dll
[Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
public void DownloadCallback(IAsyncResult ar) { }
//introduced for supporting design-time loading of System.Windows.dll
[Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
public void ReadCallback(IAsyncResult ar) { }
//introduced for supporting design-time loading of System.Windows.dll
[Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
public static void RegisterUnsafeWebRequestCreator(IUnsafeWebRequestCreate creator) { }
//introduced for supporting design-time loading of System.Windows.dll
[Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
public SocketPolicy Result { get { throw new PlatformNotSupportedException(); } }
}
//introduced for supporting design-time loading of System.Windows.dll
[Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
public delegate void SecurityCriticalAction();
//introduced for supporting design-time loading of System.Windows.dll
[Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
public class SocketPolicy
{
}
}

View File

@@ -0,0 +1,49 @@
using System;
using System.ComponentModel;
namespace System.Net
{
//introduced for supporting design-time loading of System.Windows.dll
[Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
public interface INetworkProgress
{
//introduced for supporting design-time loading of System.Windows.dll
[Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
event EventHandler<NetworkProgressChangedEventArgs> ProgressChanged;
//introduced for supporting design-time loading of System.Windows.dll
[Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
event EventHandler<NetworkProgressChangedEventArgs> ProgressCompleted;
//introduced for supporting design-time loading of System.Windows.dll
[Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
event EventHandler<NetworkProgressChangedEventArgs> ProgressFailed;
}
//introduced for supporting design-time loading of System.Windows.dll
[Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
public class NetworkProgressChangedEventArgs : ProgressChangedEventArgs
{
//introduced for supporting design-time loading of System.Windows.dll
[Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
public NetworkProgressChangedEventArgs(int percentage, int processedBytes, int totalBytes, object userState) : base(default(int), null) { }
// Properties
//introduced for supporting design-time loading of System.Windows.dll
[Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
public int ProcessedBytes { get { throw new PlatformNotSupportedException(); } }
//introduced for supporting design-time loading of System.Windows.dll
[Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
public int TotalBytes { get { throw new PlatformNotSupportedException(); } }
}
}

View File

@@ -0,0 +1,34 @@
//------------------------------------------------------------------------------
// <copyright file="IPEndPointCollection.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Net
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
[Serializable]
public class IPEndPointCollection : Collection<IPEndPoint>
{
public IPEndPointCollection() { }
protected override void SetItem(int index, IPEndPoint item)
{
if (item == null)
{
throw new ArgumentNullException("item");
}
base.SetItem(index, item);
}
protected override void InsertItem(int index, IPEndPoint item)
{
if (item == null)
{
throw new ArgumentNullException("item");
}
base.InsertItem(index, item);
}
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.ComponentModel;
namespace System.Net
{
//introduced for supporting design-time loading of System.Windows.dll
[Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
public interface IUnsafeWebRequestCreate
{
[Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
[EditorBrowsable(EditorBrowsableState.Never)]
WebRequest Create(Uri uri);
}
}

View File

@@ -0,0 +1,187 @@
//------------------------------------------------------------------------------
// <copyright file="Logging.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Net
{
using System.Collections;
using System.IO;
using System.Threading;
using System.Diagnostics;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Globalization;
using Microsoft.Win32;
using System.Text;
internal static class Logging
{
private static P2PTraceSource s_P2PTraceSource;
// <SecurityKernel Critical="True" Ring="0">
// <SatisfiesLinkDemand Name="AppDomain.add_ProcessExit(System.EventHandler):System.Void" />
// <SatisfiesLinkDemand Name="AppDomain.add_DomainUnload(System.EventHandler):System.Void" />
// <ReferencesCritical Name="Method: ProcessExitEventHandler(Object, EventArgs):Void" Ring="2" />
// <ReferencesCritical Name="Method: DomainUnloadEventHandler(Object, EventArgs):Void" Ring="2" />
// </SecurityKernel>
[System.Security.SecurityCritical]
static Logging()
{
s_P2PTraceSource = new P2PTraceSource();
if (s_P2PTraceSource.Switch.ShouldTrace(TraceEventType.Critical))
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.ProcessExit += new EventHandler(ProcessExitEventHandler);
//currentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionEventHandler);
currentDomain.DomainUnload += new EventHandler(DomainUnloadEventHandler);
}
}
// <SecurityKernel Critical="True" Ring="1">
// <ReferencesCritical Name="Method: Close():Void" Ring="1" />
// </SecurityKernel>
[System.Security.SecurityCritical]
private static void DomainUnloadEventHandler(object sender, EventArgs e)
{
Close();
}
/*
private static void UnhandledExceptionEventHandler(object sender, UnhandledExceptionEventArgs e)
{
s_P2PTraceSource.TraceEvent(TraceEventType.Critical, UNHANDLED_EXCEPTION_EVENT_ID, "Unhandled Exception {0}", e.ExceptionObject);
}
*/
// <SecurityKernel Critical="True" Ring="1">
// <ReferencesCritical Name="Method: Close():Void" Ring="1" />
// </SecurityKernel>
[System.Security.SecurityCritical]
private static void ProcessExitEventHandler(object sender, EventArgs e)
{
Close();
}
// <SecurityKernel Critical="True" Ring="0">
// <SatisfiesLinkDemand Name="TraceSource.Close():System.Void" />
// </SecurityKernel>
[System.Security.SecurityCritical]
private static void Close()
{
s_P2PTraceSource.Close();
}
//private Logging() {}
internal static P2PTraceSource P2PTraceSource
{
get
{
return s_P2PTraceSource;
}
}
internal static void Enter(TraceSource source, string method)
{
if(source.Switch.ShouldTrace(TraceEventType.Verbose))
{
source.TraceEvent(TraceEventType.Verbose, 0, "Entering --> " + method);
}
}
internal static void Leave(TraceSource source, string message)
{
if (source.Switch.ShouldTrace(TraceEventType.Verbose))
{
source.TraceEvent(TraceEventType.Verbose, 0, "Leaving <-- " + message);
}
}
/*
internal static void Enter(TraceSource source, string type, object obj, string method)
{
}
internal static void Enter(TraceSource source, string type, object obj, string method, params object[] args)
{
}
* */
internal static void DumpData(TraceSource source, TraceEventType eventType, int maxDataSize, byte[] buffer, int offset, int length)
{
if (buffer == null ||
buffer.Length == 0 ||
offset > buffer.Length)
{
return;
}
if (length > maxDataSize)
{
source.TraceEvent(eventType, 0, "dumping {0} of {1} bytes", maxDataSize, length);
length = maxDataSize;
}
if ((length < 0) || (length > buffer.Length - offset))
{
length = buffer.Length - offset;
}
do
{
int n = Math.Min(length, 16);
StringBuilder sb = new StringBuilder();
sb.Append(String.Format(CultureInfo.CurrentCulture, "{0:X8} : ", offset));
for (int i = 0; i < n; ++i)
{
sb.Append(String.Format(CultureInfo.CurrentCulture, "{0:X2}", buffer[offset + i]) + ((i == 7) ? '-' : ' '));
}
for (int i = n; i < 16; ++i)
{
sb.Append(" ");
}
sb.Append(": ");
for (int i = 0; i < n; ++i)
{
sb.Append(((buffer[offset + i] < 0x20) || (buffer[offset + i] > 0x7e))
? '.'
: (char)(buffer[offset + i]));
}
source.TraceEvent(eventType, 0, sb.ToString());
offset += n;
length -= n;
} while (length > 0);
}
}
internal class P2PTraceSource : TraceSource
{
private const string P2PTraceSourceName = "System.Net.PeerToPeer";
private const int DefaultMaxDataSize = 1024;
private const string AttributeNameMaxDataSize = "maxdatasize";
private static readonly string[] P2PTraceSourceSupportedAttributes = new string[] { AttributeNameMaxDataSize };
private readonly int m_maxDataSize = DefaultMaxDataSize;
internal P2PTraceSource() :base(P2PTraceSourceName)
{
if (Attributes.ContainsKey(AttributeNameMaxDataSize))
{
try{
m_maxDataSize = Int32.Parse(Attributes[AttributeNameMaxDataSize], NumberFormatInfo.InvariantInfo);
}
catch (Exception exception) {
if (exception is ThreadAbortException || exception is StackOverflowException || exception is OutOfMemoryException) {
throw;
}
}
}
}
protected override string[] GetSupportedAttributes()
{
return P2PTraceSourceSupportedAttributes;
}
internal int MaxDataSize
{
get
{
return m_maxDataSize;
}
}
}
}

View File

@@ -0,0 +1,362 @@
//------------------------------------------------------------------------------
// <copyright file="Cloud.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Net.PeerToPeer
{
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
/// <remarks>
/// The Cloud class directly represents the native cloud concept in the P2P APIs
/// There are two special static readonly members we support
/// Cloud.All and Cloud.AllLinkLocal
/// Cloud.All is really a notational convinience of null in the native world
/// Cloud.AllLinkLocal is equivalent to PEER_PNRP_ALL_LINK_CLOUDS const in the header file (declared in p2p.h)
///
/// This class is serializable.
/// This class is not sealed because there is no reason for it to be sealed.
/// </remarks>
/// <
[Serializable]
public class Cloud : ISerializable, IEquatable<Cloud>
{
private const string PEER_PNRP_ALL_LINK_CLOUDS = "PEER_PNRP_ALL_LINKS";
private string m_CloudName; //name of the cloud
private PnrpScope m_PnrpScope; //scope of the cloud
private int m_ScopeId; //scope Id of the scope
/// <summary>
/// Cloud.AllAvailable is a notational convinience. The native side uses a null for cloud parameter
/// to indicate all clouds.
/// </summary>
public static readonly Cloud Available = new Cloud("AllAvailable", PnrpScope.All, -1);
/// <summary>
/// AllLinkLocal is a managed abstraction of the native const PEER_PNRP_ALL_LINK_CLOUDS
/// </summary>
public static readonly Cloud AllLinkLocal = new Cloud("AllLinkLocal", PnrpScope.LinkLocal, -1);
/// <summary>
/// The static constructor serves the purpose of checking the
/// availability of the P2P apis on this platform
/// </summary>
static Cloud()
{
//-------------------------------------------------
//Check for the availability of the simpler PNRP APIs
//-------------------------------------------------
if (!PeerToPeerOSHelper.SupportsP2P)
{
throw new PlatformNotSupportedException(SR.GetString(SR.P2P_NotAvailable));
}
}
/// <summary>
/// Constructs an instance of a Cloud.
/// This is not public and accessible for internal members only
/// </summary>
/// <param name="name">Name of the cloud</param>
/// <param name="pnrpScope">scope</param>
/// <param name="scopeId">id ofthe scope</param>
internal Cloud(string name, PnrpScope pnrpScope, int scopeId) {
Logging.P2PTraceSource.TraceEvent(TraceEventType.Information, 0, "Creating cloud with Name: {0}, PnrpScope: {1}, ScopeID: {2}", name, pnrpScope, scopeId);
m_CloudName = name;
m_PnrpScope = pnrpScope;
m_ScopeId = scopeId;
}
/// <summary>
/// Name
/// </summary>
public string Name {
get {
if (this == Cloud.AllLinkLocal || this == Cloud.Available)
return null;
return m_CloudName;
}
}
internal string InternalName
{
get
{
if (this == Cloud.AllLinkLocal)
return PEER_PNRP_ALL_LINK_CLOUDS;
else if (this == Cloud.Available)
return null;
return m_CloudName;
}
}
/// <summary>
/// Scope
/// </summary>
public PnrpScope Scope {
get {
return m_PnrpScope;
}
}
/// <summary>
/// ScopeId
/// </summary>
public int ScopeId {
get {
return m_ScopeId;
}
}
public static Cloud Global
{
// <SecurityKernel Critical="True" Ring="1">
// <ReferencesCritical Name="Method: GetCloudOrClouds(String, Boolean, CloudCollection&, Cloud&):Void" Ring="1" />
// </SecurityKernel>
//[System.Security.SecurityCritical]
get
{
//throw new PeerToPeerException(SR.GetString(SR.Collab_SubscribeLocalContactFailed));
CloudCollection dummy = null;
Cloud cloud = null;
GetCloudOrClouds(null, true, out dummy, out cloud);
return cloud;
}
}
// <SecurityKernel Critical="True" Ring="1">
// <ReferencesCritical Name="Method: GetCloudOrClouds(String, Boolean, CloudCollection&, Cloud&):Void" Ring="1" />
// </SecurityKernel>
//[System.Security.SecurityCritical]
public static Cloud GetCloudByName(string cloudName)
{
if (cloudName == null || cloudName.Length == 0)
{
throw new ArgumentException(SR.GetString(SR.Pnrp_CloudNameCantBeNull), "cloudName");
}
CloudCollection dummy = null;
Cloud cloud = null;
GetCloudOrClouds(cloudName, false, out dummy, out cloud);
return cloud;
}
/// <summary>
/// The static member returns the list of clouds
/// </summary>
/// <returns></returns>
// <SecurityKernel Critical="True" Ring="1">
// <ReferencesCritical Name="Method: GetCloudOrClouds(String, Boolean, CloudCollection&, Cloud&):Void" Ring="1" />
// </SecurityKernel>
//[System.Security.SecurityCritical]
public static CloudCollection GetAvailableClouds()
{
CloudCollection clouds = null;
Cloud dummy = null;
GetCloudOrClouds(null, false, out clouds, out dummy);
return clouds;
}
// <SecurityKernel Critical="True" Ring="0">
// <CallsSuppressUnmanagedCode Name="UnsafeP2PNativeMethods.PeerPnrpGetCloudInfo(System.UInt32&,System.Net.PeerToPeer.SafePeerData&):System.Int32" />
// <SatisfiesLinkDemand Name="SafeHandle.DangerousGetHandle():System.IntPtr" />
// <SatisfiesLinkDemand Name="Marshal.PtrToStructure(System.IntPtr,System.Type):System.Object" />
// <SatisfiesLinkDemand Name="Marshal.PtrToStringUni(System.IntPtr):System.String" />
// <SatisfiesLinkDemand Name="Marshal.SizeOf(System.Type):System.Int32" />
// <SatisfiesLinkDemand Name="SafeHandle.Dispose():System.Void" />
// <ReferencesCritical Name="Local ArrayOfCloudInfoStructures of type: SafePeerData" Ring="1" />
// <ReferencesCritical Name="Method: UnsafeP2PNativeMethods.PnrpStartup():System.Void" Ring="1" />
// <ReferencesCritical Name="Method: PeerToPeerException.CreateFromHr(System.String,System.Int32):System.Net.PeerToPeer.PeerToPeerException" Ring="1" />
// </SecurityKernel>
[SuppressMessage("Microsoft.Security","CA2129:SecurityTransparentCodeShouldNotReferenceNonpublicSecurityCriticalCode", Justification="System.Net.dll is still using pre-v4 security model and needs this demand")]
[System.Security.SecuritySafeCritical]
private static void GetCloudOrClouds(string cloudName, bool bGlobalCloudOnly, out CloudCollection clouds, out Cloud cloud)
{
cloud = null;
clouds = null;
Logging.Enter(Logging.P2PTraceSource, "Cloud::GetCloudOrClouds()");
//-------------------------------------------------
//Demand for the Unrestricted Pnrp Permission
//-------------------------------------------------
PnrpPermission.UnrestrictedPnrpPermission.Demand();
Int32 result = 0;
UInt32 numClouds = 0;
SafePeerData ArrayOfCloudInfoStructures = null;
if (cloudName == null)
{
//-----------------------------------------
//We need the collection only when we are not
//getting a specific cloud
//-----------------------------------------
clouds = new CloudCollection();
}
try
{
//---------------------------------------------------------------
//No perf hit here, real native call happens only one time if it
//did not already happen
//---------------------------------------------------------------
UnsafeP2PNativeMethods.PnrpStartup();
result = UnsafeP2PNativeMethods.PeerPnrpGetCloudInfo(out numClouds, out ArrayOfCloudInfoStructures);
if (result != 0)
{
throw PeerToPeerException.CreateFromHr(SR.GetString(SR.Pnrp_CouldNotEnumerateClouds), result);
}
if (numClouds != 0)
{
Logging.P2PTraceSource.TraceEvent(TraceEventType.Information, 0, "Number of clouds returned {0}", numClouds);
IntPtr pPEER_PNRP_CLOUD_INFO = ArrayOfCloudInfoStructures.DangerousGetHandle();
for (ulong i = 0; i < numClouds; i++)
{
PEER_PNRP_CLOUD_INFO cloudinfo = (PEER_PNRP_CLOUD_INFO)Marshal.PtrToStructure(pPEER_PNRP_CLOUD_INFO, typeof(PEER_PNRP_CLOUD_INFO));
string nativeCloudName = Marshal.PtrToStringUni(cloudinfo.pwzCloudName);
pPEER_PNRP_CLOUD_INFO = (IntPtr)((long)pPEER_PNRP_CLOUD_INFO + Marshal.SizeOf(typeof(PEER_PNRP_CLOUD_INFO)));
Cloud c = new Cloud(nativeCloudName, (PnrpScope)((int)cloudinfo.dwScope), (int)cloudinfo.dwScopeId);
if (cloudName == null && !bGlobalCloudOnly)
{
clouds.Add(c);
continue;
}
//If a specific cloud by name is required, then test for name
//note that scope is PnrpScope.All but we don't test that now
if (cloudName != null && cloudName == nativeCloudName)
{
cloud = c;
break;
}
if (bGlobalCloudOnly && c.Scope == PnrpScope.Global)
{
cloud = c;
break;
}
}
}
else
{
Logging.P2PTraceSource.TraceEvent(TraceEventType.Warning, 0, "No Clouds returned from the native call");
}
}
finally
{
if (ArrayOfCloudInfoStructures != null)
{
ArrayOfCloudInfoStructures.Dispose();
}
}
if (cloudName != null && cloud == null)
{
Logging.P2PTraceSource.TraceEvent(TraceEventType.Information, 0, "The specific cloud name {0} asked for is not found", cloudName);
}
Logging.Leave(Logging.P2PTraceSource, "Cloud::GetCloudOrClouds()");
}
/// <summary>
/// Two Clouds are equal only when all of the information matches
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public bool Equals(Cloud other)
{
if (other == null) return false;
return other.Name == Name && other.Scope == Scope && other.ScopeId == ScopeId;
}
public override bool Equals(object obj)
{
if (obj == null) return false;
Cloud other = obj as Cloud;
if (other == null)
return false;
return Equals(other);
}
/// <summary>
/// The hash code comes from just the cloud name - for no partular reason.
/// This implementation seems sufficient - since the cloud names or typically
/// unique
/// </summary>
/// <returns></returns>
public override int GetHashCode()
{
return m_CloudName.GetHashCode();
}
/// <summary>
/// A friendly string for the Cloud object
/// </summary>
/// <returns></returns>
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("Cloud Name:");
sb.Append(Name);
sb.Append(" Scope:");
sb.Append(Scope);
sb.Append(" ScopeId:");
sb.Append(ScopeId);
return sb.ToString();
}
/// <summary>
/// Constructor to enable serialization
/// </summary>
/// <param name="serializationInfo"></param>
/// <param name="streamingContext"></param>
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
protected Cloud(SerializationInfo info, StreamingContext context)
{
m_CloudName = info.GetString("_CloudName");
m_PnrpScope = (PnrpScope)info.GetValue("_CloudScope", typeof(PnrpScope));
m_ScopeId = info.GetInt32("_CloudScopeId");
}
// <SecurityKernel Critical="True" Ring="0">
// <SatisfiesLinkDemand Name="GetObjectData(SerializationInfo, StreamingContext):Void" />
// </SecurityKernel>
[SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase", Justification = "System.Net.dll is still using pre-v4 security model and needs this demand")]
[System.Security.SecurityCritical]
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter, SerializationFormatter = true)]
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
GetObjectData(info, context);
}
/// <summary>
/// This is made virtual so that derived types can be implemented correctly
/// </summary>
/// <param name="serializationInfo"></param>
/// <param name="streamingContext"></param>
[SecurityPermission(SecurityAction.LinkDemand, SerializationFormatter = true)]
protected virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
//Name is tricky since it can be null for AllLinkLocal and Available clouds
//but internally we represent them with non null strings
//so we should use the property here
info.AddValue("_CloudName", Name);
info.AddValue("_CloudScope", m_PnrpScope);
info.AddValue("_CloudScopeId", m_ScopeId);
}
}
}

View File

@@ -0,0 +1,34 @@
//------------------------------------------------------------------------------
// <copyright file="CloudCollection.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Net.PeerToPeer
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
[Serializable]
public class CloudCollection : Collection<Cloud>
{
public CloudCollection() { }
protected override void SetItem(int index, Cloud item)
{
if (item == null)
{
throw new ArgumentNullException("item");
}
base.SetItem(index, item);
}
protected override void InsertItem(int index, Cloud item)
{
if (item == null)
{
throw new ArgumentNullException("item");
}
base.InsertItem(index, item);
}
}
}

View File

@@ -0,0 +1,73 @@
//------------------------------------------------------------------------------
// <copyright file="CollabEnumTypes.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Net.PeerToPeer.Collaboration
{
//
// Defines all the enums used by peer collaboration
//
public enum PeerPresenceStatus
{
Offline = 0,
OutToLunch,
Away,
BeRightBack,
Idle,
Busy,
OnThePhone,
Online
}
public enum PeerScope
{
None = 0,
NearMe,
Internet,
All = NearMe | Internet
}
public enum PeerApplicationRegistrationType
{
CurrentUser = 0,
AllUsers
}
public enum PeerInvitationResponseType
{
Declined = 0,
Accepted,
Expired
}
public enum PeerChangeType
{
Added = 0,
Deleted,
Updated
}
public enum SubscriptionType
{
Blocked = 0,
Allowed
}
internal enum PeerCollabEventType
{
WatchListChanged = 1,
EndPointChanged = 2,
EndPointPresenceChanged = 3,
EndPointApplicationChanged = 4,
EndPointObjectChanged = 5,
MyEndPointChanged = 6,
MyPresenceChanged = 7,
MyApplicationChanged = 8,
MyObjectChanged = 9,
PeopleNearMeChanged = 10,
RequestStatusChanged = 11
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,76 @@
//------------------------------------------------------------------------------
// <copyright file="PeerApplicationLaunchInfo.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Net.PeerToPeer.Collaboration
{
using System;
/// <summary>
/// Represents launch info that collab gives back for the running application.
/// If this application has been started up via collab invitation then it gives
/// back the details of that invitation.
/// </summary>
public class PeerApplicationLaunchInfo
{
private PeerContact m_peerContact;
private PeerEndPoint m_peerEndPoint;
private PeerApplication m_peerApplication;
private byte[] m_inviteData;
private string m_message;
internal PeerApplicationLaunchInfo() { }
public PeerContact PeerContact
{
get{
return m_peerContact;
}
internal set{
m_peerContact = value;
}
}
public PeerEndPoint PeerEndPoint
{
get{
return m_peerEndPoint;
}
internal set{
m_peerEndPoint = value;
}
}
public PeerApplication PeerApplication
{
get{
return m_peerApplication;
}
internal set{
m_peerApplication = value;
}
}
public byte[] Data
{
get{
return m_inviteData;
}
internal set{
m_inviteData = value;
}
}
public string Message
{
get{
return m_message;
}
internal set{
m_message = value;
}
}
}
}

View File

@@ -0,0 +1,204 @@
//------------------------------------------------------------------------------
// <copyright file="PeerCollaborationPermission.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Net.PeerToPeer.Collaboration
{
using System.Security;
using System.Security.Permissions;
using System.Globalization;
/// <remarks>
/// PeerCollaborationPermissionAttribute atrribute
/// </remarks>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor |
AttributeTargets.Class | AttributeTargets.Struct |
AttributeTargets.Assembly,
AllowMultiple = true, Inherited = false)]
[Serializable()]
public sealed class PeerCollaborationPermissionAttribute : CodeAccessSecurityAttribute
{
/// <summary>
/// Just call base constructor
/// </summary>
/// <param name="action"></param>
public PeerCollaborationPermissionAttribute(SecurityAction action) : base(action) { }
/// <summary>
/// As required by the SecurityAttribute class.
/// </summary>
/// <returns></returns>
public override IPermission CreatePermission()
{
if (Unrestricted){
return new PeerCollaborationPermission(PermissionState.Unrestricted);
}
else{
return new PeerCollaborationPermission(PermissionState.None);
}
}
}
/// <remarks>
/// Currently we only support two levels - Unrestrictred or none
/// </remarks>
[Serializable]
public sealed class PeerCollaborationPermission : CodeAccessPermission, IUnrestrictedPermission
{
private bool m_noRestriction;
internal static readonly PeerCollaborationPermission UnrestrictedPeerCollaborationPermission =
new PeerCollaborationPermission(PermissionState.Unrestricted);
/// <summary>
/// <para>
/// Creates a new instance of the <see cref='System.Net.PeerToPeer.Collaboration.PeerCollaborationPermission'/>
/// class that passes all demands or that fails all demands.
/// </para>
/// </summary>
public PeerCollaborationPermission(PermissionState state)
{
m_noRestriction = (state == PermissionState.Unrestricted);
}
internal PeerCollaborationPermission(bool free)
{
m_noRestriction = free;
}
// IUnrestrictedPermission interface methods
/// <summary>
/// <para>
/// Checks the overall permission state of the object.
/// </para>
/// </summary>
public bool IsUnrestricted()
{
return m_noRestriction;
}
// IPermission interface methods
/// <summary>
/// <para>
/// Creates a copy of a <see cref='System.Net.PeerToPeer..Collaboration.PeerCollaborationPermission'/> instance.
/// </para>
/// </summary>
public override IPermission Copy()
{
if (m_noRestriction)
return new PeerCollaborationPermission(true);
else
return new PeerCollaborationPermission(false);
}
/// <summary>
/// <para>Returns the logical union between two <see cref='System.Net.PeerToPeer..Collaboration.PeerCollaborationPermission'/> instances.</para>
/// </summary>
public override IPermission Union(IPermission target)
{
// Pattern suggested by Security engine
if (target == null){
return this.Copy();
}
PeerCollaborationPermission other = target as PeerCollaborationPermission;
if (other == null){
throw new ArgumentException(SR.GetString(SR.Collab_PermissionUnionError), "target");
}
return new PeerCollaborationPermission(m_noRestriction || other.m_noRestriction);
}
/// <summary>
/// <para>Returns the logical intersection between two <see cref='System.Net.PeerToPeer..Collaboration.PeerCollaborationPermission'/> instances.</para>
/// </summary>
public override IPermission Intersect(IPermission target)
{
// Pattern suggested by Security engine
if (target == null){
return null;
}
PeerCollaborationPermission other = target as PeerCollaborationPermission;
if (other == null){
throw new ArgumentException(SR.GetString(SR.Collab_PermissionIntersectError), "target");
}
// return null if resulting permission is restricted and empty
// Hence, the only way for a bool permission will be.
if (this.m_noRestriction && other.m_noRestriction){
return new PeerCollaborationPermission(true);
}
return null;
}
/// <summary>
/// <para>Compares two <see cref='System.Net.PeerToPeer..Collaboration.PeerCollaborationPermission'/> instances.</para>
/// </summary>
public override bool IsSubsetOf(IPermission target)
{
// Pattern suggested by Security engine
if (target == null){
return m_noRestriction == false;
}
PeerCollaborationPermission other = target as PeerCollaborationPermission;
if (other == null){
throw new ArgumentException(SR.GetString(SR.Collab_BadPermissionTarget), "target");
}
//Here is the matrix of result based on m_noRestriction for me and she
// me.noRestriction she.noRestriction me.isSubsetOf(she)
// 0 0 1
// 0 1 1
// 1 0 0
// 1 1 1
return (!m_noRestriction || other.m_noRestriction);
}
/// <summary>
/// Copy from a security element
/// </summary>
/// <param name="securityElement"></param>
public override void FromXml(SecurityElement e)
{
if (e == null){
throw new ArgumentNullException("e");
}
// SecurityElement must be a permission element
if (!e.Tag.Equals("IPermission"))
{
throw new ArgumentException(SR.GetString(SR.InvalidSecurityElem), "e");
}
string className = e.Attribute("class");
// SecurityElement must be a permission element for this type
if (className == null){
throw new ArgumentException(SR.GetString(SR.InvalidSecurityElemNoClass), "e");
}
if (className.IndexOf(this.GetType().FullName, StringComparison.Ordinal) < 0){
throw new ArgumentException(SR.GetString(SR.InvalidSecurityElemNoType), "e");
}
string str = e.Attribute("Unrestricted");
m_noRestriction = (str != null ? (0 == string.Compare(str, "true", StringComparison.OrdinalIgnoreCase)) : false);
}
/// <summary>
/// Copyto a security element
/// </summary>
/// <returns></returns>
public override SecurityElement ToXml()
{
SecurityElement securityElement = new SecurityElement("IPermission");
securityElement.AddAttribute("class", this.GetType().FullName + ", " + this.GetType().Module.Assembly.FullName.Replace('\"', '\''));
securityElement.AddAttribute("version", "1");
if (m_noRestriction){
securityElement.AddAttribute("Unrestricted", "true");
}
return securityElement;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,25 @@
using System;
namespace System.Net.PeerToPeer.Collaboration
{
public class PeerInvitationResponse
{
private PeerInvitationResponseType m_peerInvResponseType;
internal PeerInvitationResponse() { }
internal PeerInvitationResponse(PeerInvitationResponseType reponseType)
{
m_peerInvResponseType = reponseType;
}
public PeerInvitationResponseType PeerInvitationResponseType
{
get{
return m_peerInvResponseType;
}
internal set{
m_peerInvResponseType = value;
}
}
}
}

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More