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,30 @@
//------------------------------------------------------------------------------
// <copyright file="IPartialSessionState.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
* IPartialSessionState
*
* Copyright (c) 1998-1999, Microsoft Corporation
*
*/
namespace System.Web.SessionState {
using System.Security.Permissions;
using System.Collections.Generic;
/*
* Marker interface to indicate that class uses granular session state.
*/
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public interface IPartialSessionState {
IList<string> PartialSessionStateKeys { get; }
}
}

View File

@@ -0,0 +1,28 @@
//------------------------------------------------------------------------------
// <copyright file="IReadOnlySessionState.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
* IReadOnlySessionState
*
* Copyright (c) 1998-1999, Microsoft Corporation
*
*/
namespace System.Web.SessionState {
/*
* Marker interface to indicate that class needs only read-only
* access to session state.
*/
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public interface IReadOnlySessionState : IRequiresSessionState {
}
}

View File

@@ -0,0 +1,27 @@
//------------------------------------------------------------------------------
// <copyright file="IRequiresSessionState.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
* IRequiresSessionState
*
* Copyright (c) 1998-1999, Microsoft Corporation
*
*/
namespace System.Web.SessionState {
/*
* Marker interface to indicate that class uses session state.
*/
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public interface IRequiresSessionState {
}
}

View File

@@ -0,0 +1,163 @@
//------------------------------------------------------------------------------
// <copyright file="SessionStateStore.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
* SessionStateStoreProviderBase
*
*/
namespace System.Web.SessionState {
using System.Xml;
using System.Security.Permissions;
using System.Configuration.Provider;
using System.Collections.Specialized;
[FlagsAttribute()]
internal enum SessionStateItemFlags : int {
None = 0x00000000,
Uninitialized = 0x00000001,
IgnoreCacheItemRemoved = 0x00000002
}
[FlagsAttribute()]
public enum SessionStateActions : int {
None = 0x00000000,
InitializeItem = 0x00000001
}
// This interface is used by SessionStateModule to read/write the session state data
public abstract class SessionStateStoreProviderBase : ProviderBase {
public abstract void Dispose();
// Called by SessionStateModule to notify the provider that Session_End is defined
// in global.asax, and so when an item expires, it should call the expireCallback
// If the provider does not support session expiry, it should return false.
public abstract bool SetItemExpireCallback(SessionStateItemExpireCallback expireCallback);
// Called at the beginning of the AcquireRequestState event
public abstract void InitializeRequest(HttpContext context);
// Get and return a SessionStateStoreData.
// Please note that we are implementing a reader/writer lock mechanism.
//
// If successful:
// - returns the item
//
// If not found:
// - set 'locked' to false
// - returns null
//
// If the item is already locked by another request:
// - set 'locked' to true
// - set 'lockAge' to how long has the item been locked
// - set 'lockId' to the context of the lock
// - returns null
public abstract SessionStateStoreData GetItem(HttpContext context,
String id,
out bool locked,
out TimeSpan lockAge,
out object lockId,
out SessionStateActions actions);
// Get and lock a SessionStateStoreData.
// Please note that we are implementing a reader/writer lock mechanism.
//
// If successful:
// - set 'lockId' to the context of the lock
// - returns the item
//
// If not found:
// - set 'locked' to false
// - returns null
//
// If the item is already locked by another request:
// - set 'locked' to true
// - set 'lockAge' to how long has the item been locked
// - set 'lockId' to the context of the lock
// - returns null
public abstract SessionStateStoreData GetItemExclusive(HttpContext context,
String id,
out bool locked,
out TimeSpan lockAge,
out object lockId,
out SessionStateActions actions);
// Unlock an item locked by GetExclusive
// 'lockId' is the lock context returned by previous call to GetExclusive
public abstract void ReleaseItemExclusive(HttpContext context,
String id,
object lockId);
// Write an item.
// Note: The item is originally obtained by GetExclusive
// Because SessionStateModule will release (by ReleaseExclusive) am item if
// it has been locked for too long, so it is possible that the request calling
// Set() may have lost the lock to someone else already. This can be
// discovered by comparing the supplied lockId with the lockId value
// stored with the state item.
public abstract void SetAndReleaseItemExclusive(HttpContext context,
String id,
SessionStateStoreData item,
object lockId,
bool newItem);
// Remove an item. See the note in Set.
public abstract void RemoveItem(HttpContext context,
String id,
object lockId,
SessionStateStoreData item);
// Reset the expire time of an item based on its timeout value
public abstract void ResetItemTimeout(HttpContext context, String id);
// Create a brand new SessionStateStoreData. The created SessionStateStoreData must have
// a non-null ISessionStateItemCollection.
public abstract SessionStateStoreData CreateNewStoreData(HttpContext context, int timeout);
public abstract void CreateUninitializedItem(HttpContext context, String id, int timeout);
// Called during EndRequest event
public abstract void EndRequest(HttpContext context);
internal virtual void Initialize(string name, NameValueCollection config, IPartitionResolver partitionResolver) {
}
}
public class SessionStateStoreData {
ISessionStateItemCollection _sessionItems;
HttpStaticObjectsCollection _staticObjects;
int _timeout;
public SessionStateStoreData(ISessionStateItemCollection sessionItems,
HttpStaticObjectsCollection staticObjects,
int timeout) {
_sessionItems = sessionItems;
_staticObjects = staticObjects;
_timeout = timeout;
}
virtual public ISessionStateItemCollection Items {
get {
return _sessionItems;
}
}
virtual public HttpStaticObjectsCollection StaticObjects {
get {
return _staticObjects;
}
}
virtual public int Timeout {
get {
return _timeout;
}
set {
_timeout = value;
}
}
}
}

File diff suppressed because it is too large Load Diff

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,481 @@
//------------------------------------------------------------------------------
// <copyright file="SessionState.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
* HttpSessionState
*
* Copyright (c) 1998-1999, Microsoft Corporation
*
*/
namespace System.Web.SessionState {
using System.Threading;
using System.Runtime.InteropServices;
using System.Web;
using System.Collections;
using System.Collections.Specialized;
using System.Text;
using System.Globalization;
using System.Security.Permissions;
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public enum SessionStateMode {
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
Off = 0,
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
InProc = 1,
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
StateServer = 2,
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
SQLServer = 3,
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
Custom = 4
};
public interface IHttpSessionState {
string SessionID {
get;
}
/*
* The length of a session before it times out, in minutes.
*/
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
int Timeout {
get;
set;
}
/*
* Is this a new session?
*/
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
bool IsNewSession {
get;
}
/*
* Is session state in a separate process
*/
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
SessionStateMode Mode {
get;
}
/*
* Is session state cookieless?
*/
bool IsCookieless {
get;
}
HttpCookieMode CookieMode {
get;
}
/*
* Abandon the session.
*
*/
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
void Abandon();
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
int LCID {
get;
set;
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
int CodePage {
get;
set;
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
HttpStaticObjectsCollection StaticObjects {
get;
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
Object this[String name]
{
get;
set;
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
Object this[int index]
{
get;
set;
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
void Add(String name, Object value);
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
void Remove(String name);
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
void RemoveAt(int index);
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
void Clear();
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
void RemoveAll();
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
int Count {
get;
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
NameObjectCollectionBase.KeysCollection Keys {
get;
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
IEnumerator GetEnumerator();
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
void CopyTo(Array array, int index);
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
Object SyncRoot {
get;
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
bool IsReadOnly {
get;
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
bool IsSynchronized {
get;
}
}
public sealed class HttpSessionState : ICollection {
private IHttpSessionState _container;
internal HttpSessionState(IHttpSessionState container) {
_container = container;
}
internal IHttpSessionState Container {
get { return _container; }
}
/*
* The Id of the session.
*/
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public String SessionID {
get {return _container.SessionID;}
}
/*
* The length of a session before it times out, in minutes.
*/
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public int Timeout {
get {return _container.Timeout;}
set {_container.Timeout = value;}
}
/*
* Is this a new session?
*/
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public bool IsNewSession {
get {return _container.IsNewSession;}
}
/*
* Is session state in a separate process
*/
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public SessionStateMode Mode {
get {return _container.Mode;}
}
/*
* Is session state cookieless?
*/
public bool IsCookieless {
get {return _container.IsCookieless;}
}
public HttpCookieMode CookieMode {
get {return _container.CookieMode; }
}
/*
* Abandon the session.
*
*/
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void Abandon() {
_container.Abandon();
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public int LCID {
get { return _container.LCID; }
set { _container.LCID = value; }
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public int CodePage {
get { return _container.CodePage; }
set { _container.CodePage = value; }
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public HttpSessionState Contents {
get {return this;}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public HttpStaticObjectsCollection StaticObjects {
get { return _container.StaticObjects;}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public Object this[String name]
{
get {
return _container[name];
}
set {
_container[name] = value;
}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public Object this[int index]
{
get {return _container[index];}
set {_container[index] = value;}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void Add(String name, Object value) {
_container[name] = value;
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void Remove(String name) {
_container.Remove(name);
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void RemoveAt(int index) {
_container.RemoveAt(index);
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void Clear() {
_container.Clear();
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void RemoveAll() {
Clear();
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public int Count {
get {return _container.Count;}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public NameObjectCollectionBase.KeysCollection Keys {
get {return _container.Keys;}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public IEnumerator GetEnumerator() {
return _container.GetEnumerator();
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void CopyTo(Array array, int index) {
_container.CopyTo(array, index);
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public Object SyncRoot {
get { return _container.SyncRoot;}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public bool IsReadOnly {
get { return _container.IsReadOnly;}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public bool IsSynchronized {
get { return _container.IsSynchronized;}
}
}
}

View File

@@ -0,0 +1,8 @@
namespace System.Web.SessionState {
public enum SessionStateBehavior {
Default = 0,
Required = 1,
ReadOnly = 2,
Disabled = 3
}
}

View File

@@ -0,0 +1,325 @@
//------------------------------------------------------------------------------
// <copyright file="SessionState.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
* HttpSessionState
*
* Copyright (c) 1998-1999, Microsoft Corporation
*
*/
namespace System.Web.SessionState {
using System.Threading;
using System.Runtime.InteropServices;
using System.Web;
using System.Web.Util;
using System.Collections;
using System.Collections.Specialized;
using System.Text;
using System.Globalization;
using System.Security.Permissions;
public class HttpSessionStateContainer : IHttpSessionState {
String _id;
ISessionStateItemCollection _sessionItems;
HttpStaticObjectsCollection _staticObjects;
int _timeout;
bool _newSession;
HttpCookieMode _cookieMode;
SessionStateMode _mode;
bool _abandon;
bool _isReadonly;
SessionStateModule _stateModule; // used for optimized InProc session id callback
public HttpSessionStateContainer(
String id,
ISessionStateItemCollection sessionItems,
HttpStaticObjectsCollection staticObjects,
int timeout,
bool newSession,
HttpCookieMode cookieMode,
SessionStateMode mode,
bool isReadonly)
: this(null, id, sessionItems, staticObjects, timeout, newSession, cookieMode, mode, isReadonly) {
if (id == null) {
throw new ArgumentNullException("id");
}
}
internal HttpSessionStateContainer(
SessionStateModule stateModule,
string id,
ISessionStateItemCollection sessionItems,
HttpStaticObjectsCollection staticObjects,
int timeout,
bool newSession,
HttpCookieMode cookieMode,
SessionStateMode mode,
bool isReadonly) {
_stateModule = stateModule;
_id = id; // If null, it means we're delaying session id reading
_sessionItems = sessionItems;
_staticObjects = staticObjects;
_timeout = timeout;
_newSession = newSession;
_cookieMode = cookieMode;
_mode = mode;
_isReadonly = isReadonly;
}
internal HttpSessionStateContainer() {
}
/*
* The Id of the session.
*/
public String SessionID {
get {
if (_id == null) {
Debug.Assert(_stateModule != null, "_stateModule != null");
_id = _stateModule.DelayedGetSessionId();
}
return _id;
}
}
/*
* The length of a session before it times out, in minutes.
*/
public int Timeout {
get {return _timeout;}
set {
if (value <= 0) {
throw new ArgumentException(SR.GetString(SR.Timeout_must_be_positive));
}
if (value > SessionStateModule.MAX_CACHE_BASED_TIMEOUT_MINUTES &&
(Mode == SessionStateMode.InProc ||
Mode == SessionStateMode.StateServer)) {
throw new ArgumentException(
SR.GetString(SR.Invalid_cache_based_session_timeout));
}
_timeout = value;
}
}
/*
* Is this a new session?
*/
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public bool IsNewSession {
get {return _newSession;}
}
/*
* Is session state in a separate process
*/
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public SessionStateMode Mode {
get {return _mode;}
}
/*
* Is session state cookieless?
*/
public bool IsCookieless {
get {
if (_stateModule != null) {
// See VSWhidbey 399907
return _stateModule.SessionIDManagerUseCookieless;
}
else {
// For container created by custom session state module,
// sorry, we currently don't have a way to tell and thus we rely blindly
// on cookieMode.
return CookieMode == HttpCookieMode.UseUri;
}
}
}
public HttpCookieMode CookieMode {
get {return _cookieMode;}
}
/*
* Abandon the session.
*
*/
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void Abandon() {
_abandon = true;
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public int LCID {
//
get { return Thread.CurrentThread.CurrentCulture.LCID; }
set { Thread.CurrentThread.CurrentCulture = HttpServerUtility.CreateReadOnlyCultureInfo(value); }
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public int CodePage {
//
get {
if (HttpContext.Current != null)
return HttpContext.Current.Response.ContentEncoding.CodePage;
else
return Encoding.Default.CodePage;
}
set {
if (HttpContext.Current != null)
HttpContext.Current.Response.ContentEncoding = Encoding.GetEncoding(value);
}
}
public bool IsAbandoned {
get {return _abandon;}
}
public HttpStaticObjectsCollection StaticObjects {
get { return _staticObjects;}
}
public Object this[String name]
{
get {
return _sessionItems[name];
}
set {
_sessionItems[name] = value;
}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public Object this[int index]
{
get {return _sessionItems[index];}
set {_sessionItems[index] = value;}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void Add(String name, Object value) {
_sessionItems[name] = value;
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void Remove(String name) {
_sessionItems.Remove(name);
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void RemoveAt(int index) {
_sessionItems.RemoveAt(index);
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void Clear() {
_sessionItems.Clear();
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void RemoveAll() {
Clear();
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public int Count {
get {return _sessionItems.Count;}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public NameObjectCollectionBase.KeysCollection Keys {
get {return _sessionItems.Keys;}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public IEnumerator GetEnumerator() {
return _sessionItems.GetEnumerator();
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void CopyTo(Array array, int index) {
for (IEnumerator e = this.GetEnumerator(); e.MoveNext();)
array.SetValue(e.Current, index++);
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public Object SyncRoot {
get { return this;}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public bool IsReadOnly {
get { return _isReadonly;}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public bool IsSynchronized {
get { return false;}
}
}
}

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,203 @@
//------------------------------------------------------------------------------
// <copyright file="SessionStateUtil.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
* SessionStateUtil
*
*/
namespace System.Web.SessionState {
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Web;
using System.Web.Util;
using System.Xml;
public static class SessionStateUtility {
internal const String SESSION_KEY = "AspSession";
// Used by AltSerialization's BinaryFormatter for session serialization customization
public static ISurrogateSelector SerializationSurrogateSelector {
[SecurityPermission(SecurityAction.LinkDemand, SerializationFormatter = true)]
get;
[SecurityPermission(SecurityAction.LinkDemand, SerializationFormatter = true)]
set;
}
// Called by custom session state module if they want to raise Session_End.
static public void RaiseSessionEnd(IHttpSessionState session, Object eventSource, EventArgs eventArgs) {
HttpApplicationFactory.EndSession(new HttpSessionState(session), eventSource, eventArgs);
}
// Called by custom session state module
static public void AddHttpSessionStateToContext(HttpContext context, IHttpSessionState container) {
HttpSessionState sessionState = new HttpSessionState(container);
try {
context.Items.Add(SESSION_KEY, sessionState);
}
catch (ArgumentException) {
throw new HttpException(SR.GetString(SR.Cant_have_multiple_session_module));
}
}
static internal void AddHttpSessionStateModuleToContext(HttpContext context, SessionStateModule module, bool delayed) {
context.AddHttpSessionStateModule(module, delayed);
}
static internal void RemoveHttpSessionStateFromContext(HttpContext context, bool delayed) {
if (!delayed) {
context.Items.Remove(SESSION_KEY);
}
context.RemoveHttpSessionStateModule();
}
// Called by custom session state module
static public void RemoveHttpSessionStateFromContext(HttpContext context) {
RemoveHttpSessionStateFromContext(context, false);
}
// Called by custom session state module
static public IHttpSessionState GetHttpSessionStateFromContext(HttpContext context) {
return context.Session.Container;
}
static public HttpStaticObjectsCollection GetSessionStaticObjects(HttpContext context) {
return context.Application.SessionStaticObjects.Clone();
}
internal static SessionStateStoreData CreateLegitStoreData(HttpContext context,
ISessionStateItemCollection sessionItems,
HttpStaticObjectsCollection staticObjects,
int timeout) {
if (sessionItems == null) {
sessionItems = new SessionStateItemCollection();
}
if (staticObjects == null && context != null) {
staticObjects = SessionStateUtility.GetSessionStaticObjects(context);
}
return new SessionStateStoreData(sessionItems, staticObjects, timeout);
}
// This method will take an item and serialize it
[SecurityPermission(SecurityAction.Assert, SerializationFormatter = true)]
internal static void Serialize(SessionStateStoreData item, Stream stream) {
bool hasItems = true;
bool hasStaticObjects = true;
BinaryWriter writer = new BinaryWriter(stream);
writer.Write(item.Timeout);
if (item.Items == null || item.Items.Count == 0) {
hasItems = false;
}
writer.Write(hasItems);
if (item.StaticObjects == null || item.StaticObjects.NeverAccessed) {
hasStaticObjects = false;
}
writer.Write(hasStaticObjects);
if (hasItems) {
((SessionStateItemCollection)item.Items).Serialize(writer);
}
if (hasStaticObjects) {
item.StaticObjects.Serialize(writer);
}
// Prevent truncation of the stream
writer.Write(unchecked((byte)0xff));
}
// This will deserialize and return an item.
// This version uses the default classes for SessionStateItemCollection, HttpStaticObjectsCollection
// and SessionStateStoreData
[SecurityPermission(SecurityAction.Assert, SerializationFormatter = true)]
internal static SessionStateStoreData Deserialize(HttpContext context, Stream stream) {
int timeout;
SessionStateItemCollection sessionItems;
bool hasItems;
bool hasStaticObjects;
HttpStaticObjectsCollection staticObjects;
Byte eof;
Debug.Assert(context != null);
try {
BinaryReader reader = new BinaryReader(stream);
timeout = reader.ReadInt32();
hasItems = reader.ReadBoolean();
hasStaticObjects = reader.ReadBoolean();
if (hasItems) {
sessionItems = SessionStateItemCollection.Deserialize(reader);
}
else {
sessionItems = new SessionStateItemCollection();
}
if (hasStaticObjects) {
staticObjects = HttpStaticObjectsCollection.Deserialize(reader);
}
else {
staticObjects = SessionStateUtility.GetSessionStaticObjects(context);
}
eof = reader.ReadByte();
if (eof != 0xff) {
throw new HttpException(SR.GetString(SR.Invalid_session_state));
}
}
catch (EndOfStreamException) {
throw new HttpException(SR.GetString(SR.Invalid_session_state));
}
return new SessionStateStoreData(sessionItems, staticObjects, timeout);
}
static internal void SerializeStoreData(SessionStateStoreData item, int initialStreamSize, out byte[] buf, out int length, bool compressionEnabled) {
using(MemoryStream s = new MemoryStream(initialStreamSize)) {
SessionStateUtility.Serialize(item, s);
if(compressionEnabled) {
byte[] serializedBuffer = s.GetBuffer();
int serializedLength = (int)s.Length;
// truncate the MemoryStream so we can write the compressed data in it
s.SetLength(0);
// compress the serialized bytes
using(DeflateStream zipStream = new DeflateStream(s, CompressionMode.Compress, true)) {
zipStream.Write(serializedBuffer, 0, serializedLength);
}
// if the session state tables have ANSI_PADDING disabled, last )s are trimmed.
// This shouldn't happen, but to be sure, we are padding with an extra byte
s.WriteByte((byte)0xff);
}
buf = s.GetBuffer();
length = (int) s.Length;
}
}
static internal SessionStateStoreData DeserializeStoreData(HttpContext context, Stream stream, bool compressionEnabled) {
if(compressionEnabled) {
// apply the compression decorator on top of the stream
// the data should not be bigger than 4GB - compression doesn't work for more than that
using(DeflateStream zipStream = new DeflateStream(stream, CompressionMode.Decompress, true)) {
return SessionStateUtility.Deserialize(context, zipStream);
}
}
return SessionStateUtility.Deserialize(context, stream);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,455 @@
//------------------------------------------------------------------------------
// <copyright file="StateWorkerRequest.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
* StateHttpWorkerRequest
*
* Copyright (c) 1998-1999, Microsoft Corporation
*
*/
namespace System.Web.SessionState {
using System.Text;
using System.Configuration.Assemblies;
using System.Runtime.InteropServices;
using System.Collections;
using System.Web;
using System.Web.Util;
using System.Globalization;
class StateHttpWorkerRequest : HttpWorkerRequest {
/* long enough to hold the string representation of an IPv4 or IPv6 address; keep in [....] with tracker.cxx */
private const int ADDRESS_LENGTH_MAX = 64;
IntPtr _tracker;
string _uri;
UnsafeNativeMethods.StateProtocolExclusive _exclusive;
int _extraFlags;
int _timeout;
int _lockCookie;
bool _lockCookieExists;
int _contentLength;
byte[] _content;
UnsafeNativeMethods.StateProtocolVerb _methodIndex;
string _method;
string _remoteAddress;
int _remotePort;
string _localAddress;
int _localPort;
StringBuilder _status;
int _statusCode;
StringBuilder _headers;
IntPtr _unmanagedState;
bool _sent;
internal StateHttpWorkerRequest(
IntPtr tracker,
UnsafeNativeMethods.StateProtocolVerb methodIndex,
string uri,
UnsafeNativeMethods.StateProtocolExclusive exclusive,
int extraFlags,
int timeout,
int lockCookieExists,
int lockCookie,
int contentLength,
IntPtr content
) {
_tracker = tracker;
_methodIndex = methodIndex;
switch (_methodIndex) {
case UnsafeNativeMethods.StateProtocolVerb.GET:
_method = "GET";
break;
case UnsafeNativeMethods.StateProtocolVerb.PUT:
_method = "PUT";
break;
case UnsafeNativeMethods.StateProtocolVerb.HEAD:
_method = "HEAD";
break;
case UnsafeNativeMethods.StateProtocolVerb.DELETE:
_method = "DELETE";
break;
default:
Debug.Assert(false, "Shouldn't get here!");
break;
}
_uri = uri;
// Handle the ASP1.1 case which prepends an extra / to the URI
if (_uri.StartsWith("//", StringComparison.Ordinal)) {
_uri = _uri.Substring(1);
}
_exclusive = exclusive;
_extraFlags = extraFlags;
_timeout = timeout;
_lockCookie = lockCookie;
_lockCookieExists = lockCookieExists != 0;
_contentLength = contentLength;
if (contentLength != 0) {
Debug.Assert(_contentLength == IntPtr.Size);
// Need to convert 'content', which is a ptr to native StateItem,
// into a byte array because that's what GetPreloadedEntityBody
// must return, and GetPreloadedEntityBody is what the pipeline uses
// to read the body of the request, which in our case is just a pointer
// to a native StateItem object.
#if WIN64
ulong p = (ulong) content;
_content = new byte[8]
{
(byte) ((p & 0x00000000000000ff)),
(byte) ((p & 0x000000000000ff00) >> 8),
(byte) ((p & 0x0000000000ff0000) >> 16),
(byte) ((p & 0x00000000ff000000) >> 24),
(byte) ((p & 0x000000ff00000000) >> 32),
(byte) ((p & 0x0000ff0000000000) >> 40),
(byte) ((p & 0x00ff000000000000) >> 48),
(byte) ((p & 0xff00000000000000) >> 56),
};
#else
uint p = (uint) content;
_content = new byte[4]
{
(byte) ((p & 0x000000ff)),
(byte) ((p & 0x0000ff00) >> 8),
(byte) ((p & 0x00ff0000) >> 16),
(byte) ((p & 0xff000000) >> 24),
};
#endif
}
_status = new StringBuilder(256);
_headers = new StringBuilder(256);
}
public override string GetUriPath() {
return HttpUtility.UrlDecode(_uri);
}
// The file path is used as the path for configuration.
// This path should always be null, in order to retrieve
// the machine configuration.
public override string GetFilePath() {
return null;
}
public override string GetQueryString() {
return null;
}
public override string GetRawUrl() {
return _uri;
}
public override string GetHttpVerbName() {
return _method;
}
public override string GetHttpVersion() {
return "HTTP/1.0";
}
public override string GetRemoteAddress() {
StringBuilder buf;
if (_remoteAddress == null) {
buf = new StringBuilder(ADDRESS_LENGTH_MAX);
UnsafeNativeMethods.STWNDGetRemoteAddress(_tracker, buf);
_remoteAddress = buf.ToString();
}
return _remoteAddress;
}
public override int GetRemotePort() {
if (_remotePort == 0) {
_remotePort = UnsafeNativeMethods.STWNDGetRemotePort(_tracker);
}
return _remotePort;
}
public override string GetLocalAddress() {
StringBuilder buf;
if (_localAddress == null) {
buf = new StringBuilder(ADDRESS_LENGTH_MAX);
UnsafeNativeMethods.STWNDGetLocalAddress(_tracker, buf);
_localAddress = buf.ToString();
}
return _localAddress;
}
public override int GetLocalPort() {
if (_localPort == 0) {
_localPort = UnsafeNativeMethods.STWNDGetLocalPort(_tracker);
}
return _localPort;
}
public override byte[] GetPreloadedEntityBody() {
return _content;
}
public override bool IsEntireEntityBodyIsPreloaded() {
/* Request is always preloaded */
return true;
}
public override string MapPath(string virtualPath) {
/*
* Physical and virtual are identical to state server.
*/
return virtualPath;
}
public override int ReadEntityBody(byte[] buffer, int size) {
/* pretend everything is preloaded */
return 0;
}
public override long GetBytesRead() {
/* State web doesn't support partial reads */
throw new NotSupportedException(SR.GetString(SR.Not_supported));
}
public override string GetKnownRequestHeader(int index) {
string s = null;
switch (index) {
/* special case important ones */
case HeaderContentLength:
s = (_contentLength).ToString(CultureInfo.InvariantCulture);
break;
}
return s;
}
public override string GetUnknownRequestHeader(string name) {
string s = null;
if (name.Equals(StateHeaders.EXCLUSIVE_NAME)) {
switch (_exclusive) {
case UnsafeNativeMethods.StateProtocolExclusive.ACQUIRE:
s = StateHeaders.EXCLUSIVE_VALUE_ACQUIRE;
break;
case UnsafeNativeMethods.StateProtocolExclusive.RELEASE:
s = StateHeaders.EXCLUSIVE_VALUE_RELEASE;
break;
}
}
else if (name.Equals(StateHeaders.TIMEOUT_NAME)) {
if (_timeout != -1) {
s = (_timeout).ToString(CultureInfo.InvariantCulture);
}
}
else if (name.Equals(StateHeaders.LOCKCOOKIE_NAME)) {
if (_lockCookieExists) {
s = (_lockCookie).ToString(CultureInfo.InvariantCulture);
}
}
else if (name.Equals(StateHeaders.EXTRAFLAGS_NAME)) {
if (_extraFlags != -1) {
s = (_extraFlags).ToString(CultureInfo.InvariantCulture);
}
}
return s;
}
public override string[][] GetUnknownRequestHeaders() {
string [][] ret;
int c, i;
c = 0;
if (_exclusive != (UnsafeNativeMethods.StateProtocolExclusive) (-1)) {
c++;
}
if (_extraFlags != -1) {
c++;
}
if (_timeout != -1) {
c++;
}
if (_lockCookieExists) {
c++;
}
if (c == 0)
return null;
ret = new string[c][];
i = 0;
if (_exclusive != (UnsafeNativeMethods.StateProtocolExclusive) (-1)) {
ret[0] = new string[2];
ret[0][0] = StateHeaders.EXCLUSIVE_NAME;
if (_exclusive == UnsafeNativeMethods.StateProtocolExclusive.ACQUIRE) {
ret[0][1] = StateHeaders.EXCLUSIVE_VALUE_ACQUIRE;
}
else {
Debug.Assert(_exclusive == UnsafeNativeMethods.StateProtocolExclusive.RELEASE, "_exclusive == UnsafeNativeMethods.StateProtocolExclusive.RELEASE");
ret[0][1] = StateHeaders.EXCLUSIVE_VALUE_RELEASE;
}
i++;
}
if (_timeout != -1) {
ret[i] = new string[2];
ret[i][0] = StateHeaders.TIMEOUT_NAME;
ret[i][1] = (_timeout).ToString(CultureInfo.InvariantCulture);
i++;
}
if (_lockCookieExists) {
ret[i] = new string[2];
ret[i][0] = StateHeaders.LOCKCOOKIE_NAME;
ret[i][1] = (_lockCookie).ToString(CultureInfo.InvariantCulture);
i++;
}
if (_extraFlags != -1) {
ret[i] = new string[2];
ret[i][0] = StateHeaders.EXTRAFLAGS_NAME;
ret[i][1] = (_extraFlags).ToString(CultureInfo.InvariantCulture);
i++;
}
return ret;
}
public override void SendStatus(int statusCode, string statusDescription) {
Debug.Assert(!_sent);
_statusCode = statusCode;
_status.Append((statusCode).ToString(CultureInfo.InvariantCulture) + " " + statusDescription + "\r\n");
}
public override void SendKnownResponseHeader(int index, string value) {
Debug.Assert(!_sent);
_headers.Append(GetKnownResponseHeaderName(index));
_headers.Append(": ");
_headers.Append(value);
_headers.Append("\r\n");
}
public override void SendUnknownResponseHeader(string name, string value) {
Debug.Assert(!_sent);
_headers.Append(name);
_headers.Append(": ");
_headers.Append(value);
_headers.Append("\r\n");
}
public override void SendCalculatedContentLength(int contentLength) {
Debug.Assert(!_sent);
/*
* Do nothing - we append the content-length in STWNDSendResponse.
*/
}
public override bool HeadersSent() {
return _sent;
}
public override bool IsClientConnected() {
return UnsafeNativeMethods.STWNDIsClientConnected(_tracker);
}
public override void CloseConnection() {
UnsafeNativeMethods.STWNDCloseConnection(_tracker);
}
private void SendResponse() {
if (!_sent) {
_sent = true;
UnsafeNativeMethods.STWNDSendResponse(
_tracker,
_status,
_status.Length,
_headers,
_headers.Length,
_unmanagedState);
}
}
public override void SendResponseFromMemory(byte[] data, int length) {
/*
* The only content besides error message text is the pointer
* to the state item in unmanaged memory.
*/
if (_statusCode == 200) {
Debug.Assert(_unmanagedState == IntPtr.Zero, "_unmanagedState == 0");
Debug.Assert(length == IntPtr.Size, "length == IntPtr.Size");
Debug.Assert(_methodIndex == UnsafeNativeMethods.StateProtocolVerb.GET, "verb == GET");
Debug.Assert(_exclusive != UnsafeNativeMethods.StateProtocolExclusive.RELEASE,
"correct exclusive method");
if (IntPtr.Size == 4) {
_unmanagedState = (IntPtr)
(((int)data[0]) |
((int)data[1] << 8) |
((int)data[2] << 16) |
((int)data[3] << 24));
}
else {
_unmanagedState = (IntPtr)
(((long)data[0]) |
((long)data[1] << 8) |
((long)data[2] << 16) |
((long)data[3] << 24) |
((long)data[4] << 32) |
((long)data[5] << 40) |
((long)data[6] << 48) |
((long)data[7] << 56));
}
Debug.Assert(_unmanagedState != IntPtr.Zero, "_unmanagedState != 0");
}
SendResponse();
}
public override void SendResponseFromFile(string filename, long offset, long length) {
/* Not needed by state application */
throw new NotSupportedException(SR.GetString(SR.Not_supported));
}
public override void SendResponseFromFile(IntPtr handle, long offset, long length) {
/* Not needed by state application */
throw new NotSupportedException(SR.GetString(SR.Not_supported));
}
public override void FlushResponse(bool finalFlush) {
SendResponse();
}
public override void EndOfRequest() {
SendResponse();
UnsafeNativeMethods.STWNDEndOfRequest(_tracker);
}
}
}

File diff suppressed because it is too large Load Diff