Imported Upstream version 4.3.2.467

Former-commit-id: 9c2cb47f45fa221e661ab616387c9cda183f283d
This commit is contained in:
Xamarin Public Jenkins
2016-02-22 11:00:01 -05:00
parent f302175246
commit f3e3aab35a
4097 changed files with 122406 additions and 82300 deletions

View File

@@ -0,0 +1,89 @@
//
// HttpMethodConstraint.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2008 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Security.Permissions;
using System.Web;
namespace System.Web.Routing
{
[TypeForwardedFrom ("System.Web.Routing, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35")]
[AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class HttpMethodConstraint : IRouteConstraint
{
public HttpMethodConstraint (params string[] allowedMethods)
{
if (allowedMethods == null)
throw new ArgumentNullException ("allowedMethods");
AllowedMethods = allowedMethods;
}
public ICollection<string> AllowedMethods { get; private set; }
bool IRouteConstraint.Match (HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
return Match (httpContext, route, parameterName, values, routeDirection);
}
protected virtual bool Match (HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
if (httpContext == null)
throw new ArgumentNullException ("httpContext");
if (route == null)
throw new ArgumentNullException ("route");
if (parameterName == null)
throw new ArgumentNullException ("parameterName");
if (values == null)
throw new ArgumentNullException ("values");
switch (routeDirection) {
case RouteDirection.IncomingRequest:
// LAMESPEC: .NET allows case-insensitive comparison, which violates RFC 2616
return AllowedMethods.Contains (httpContext.Request.HttpMethod);
case RouteDirection.UrlGeneration:
// See: aspnetwebstack's WebAPI equivalent for details.
object method;
if (!values.TryGetValue (parameterName, out method))
return true;
// LAMESPEC: .NET allows case-insensitive comparison, which violates RFC 2616
return AllowedMethods.Contains (Convert.ToString (method));
default:
throw new ArgumentException ("Invalid routeDirection: " + routeDirection);
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,81 @@
//
// PatternToken.cs
//
// Author:
// Marek Habersack <mhabersack@novell.com>
//
// Copyright (C) 2009 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Text;
using System.Web;
namespace System.Web.Routing
{
sealed class PatternToken
{
public PatternTokenType Type {
get;
private set;
}
public string Name {
get;
private set;
}
public PatternToken (PatternTokenType type, string name)
{
this.Type = type;
this.Name = name;
}
public override string ToString ()
{
StringBuilder sb = new StringBuilder ();
switch (Type) {
case PatternTokenType.Standard:
sb.Append ("PatternToken_Standard");
break;
case PatternTokenType.Literal:
sb.Append ("PatternToken_Literal");
break;
case PatternTokenType.CatchAll:
sb.Append ("PatternToken_CatchAll");
break;
default:
sb.Append ("PatternToken_UNKNOWN");
break;
}
sb.AppendFormat (" [Name = '{0}']", Name);
return sb.ToString ();
}
}
}

View File

@@ -0,0 +1,40 @@
//
// PatternTokenType.cs
//
// Author:
// Marek Habersack <mhabersack@novell.com>
//
// Copyright (C) 2009 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
namespace System.Web.Routing
{
enum PatternTokenType
{
Standard,
Literal,
CatchAll
}
}

View File

@@ -0,0 +1,262 @@
//
// Route.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2008 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Runtime.CompilerServices;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using System.Web;
using System.Globalization;
namespace System.Web.Routing
{
[TypeForwardedFrom ("System.Web.Routing, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35")]
[AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class Route : RouteBase
{
static readonly Type httpRequestBaseType = typeof (HttpRequestBase);
PatternParser url;
public RouteValueDictionary Constraints { get; set; }
public RouteValueDictionary DataTokens { get; set; }
public RouteValueDictionary Defaults { get; set; }
public IRouteHandler RouteHandler { get; set; }
public string Url {
get { return url != null ? url.Url : String.Empty; }
set { url = value != null ? new PatternParser (value) : new PatternParser (String.Empty); }
}
public Route (string url, IRouteHandler routeHandler)
: this (url, null, routeHandler)
{
}
public Route (string url, RouteValueDictionary defaults, IRouteHandler routeHandler)
: this (url, defaults, null, routeHandler)
{
}
public Route (string url, RouteValueDictionary defaults, RouteValueDictionary constraints, IRouteHandler routeHandler)
: this (url, defaults, constraints, null, routeHandler)
{
}
public Route (string url, RouteValueDictionary defaults, RouteValueDictionary constraints, RouteValueDictionary dataTokens, IRouteHandler routeHandler)
{
Url = url;
Defaults = defaults;
Constraints = constraints;
DataTokens = dataTokens;
RouteHandler = routeHandler;
}
public override RouteData GetRouteData (HttpContextBase httpContext)
{
var path = httpContext.Request.AppRelativeCurrentExecutionFilePath;
var pathInfo = httpContext.Request.PathInfo;
if (!String.IsNullOrEmpty (pathInfo))
path += pathInfo;
// probably code like this causes ArgumentOutOfRangeException under .NET.
// It somehow allows such path that is completely equivalent to the Url. Dunno why.
if (Url != path && path.Substring (0, 2) != "~/")
return null;
path = path.Substring (2);
var values = url.Match (path, Defaults);
if (values == null)
return null;
if (!ProcessConstraints (httpContext, values, RouteDirection.IncomingRequest))
return null;
var rd = new RouteData (this, RouteHandler);
RouteValueDictionary rdValues = rd.Values;
foreach (var p in values)
rdValues.Add (p.Key, p.Value);
RouteValueDictionary dataTokens = DataTokens;
if (dataTokens != null) {
RouteValueDictionary rdDataTokens = rd.DataTokens;
foreach (var token in dataTokens)
rdDataTokens.Add (token.Key, token.Value);
}
return rd;
}
public override VirtualPathData GetVirtualPath (RequestContext requestContext, RouteValueDictionary values)
{
if (requestContext == null)
throw new ArgumentNullException ("requestContext");
if (url == null)
return new VirtualPathData (this, String.Empty);
// null values is allowed.
// if (values == null)
// values = requestContext.RouteData.Values;
RouteValueDictionary usedValues;
string resultUrl = url.BuildUrl (this, requestContext, values, Constraints, out usedValues);
if (resultUrl == null)
return null;
if (!ProcessConstraints (requestContext.HttpContext, usedValues, RouteDirection.UrlGeneration))
return null;
var result = new VirtualPathData (this, resultUrl);
RouteValueDictionary dataTokens = DataTokens;
if (dataTokens != null) {
foreach (var item in dataTokens)
result.DataTokens[item.Key] = item.Value;
}
return result;
}
private bool ProcessConstraintInternal (HttpContextBase httpContext, Route route, object constraint, string parameterName,
RouteValueDictionary values, RouteDirection routeDirection, RequestContext reqContext,
out bool invalidConstraint)
{
invalidConstraint = false;
IRouteConstraint irc = constraint as IRouteConstraint;
if (irc != null)
return irc.Match (httpContext, route, parameterName, values, routeDirection);
string s = constraint as string;
if (s != null) {
string v = null;
object o;
// NOTE: If constraint was not an IRouteConstraint, is is asumed
// to be an object 'convertible' to string, or at least this is how
// ASP.NET seems to work by the tests i've done latelly. (pruiz)
if (values != null && values.TryGetValue (parameterName, out o))
v = Convert.ToString (o, CultureInfo.InvariantCulture);
if (!String.IsNullOrEmpty (v))
return MatchConstraintRegex (v, s);
else if (reqContext != null) {
RouteData rd = reqContext != null ? reqContext.RouteData : null;
RouteValueDictionary rdValues = rd != null ? rd.Values : null;
if (rdValues == null || rdValues.Count == 0)
return false;
if (!rdValues.TryGetValue (parameterName, out o))
return false;
v = Convert.ToString (o, CultureInfo.InvariantCulture);
if (String.IsNullOrEmpty (v))
return false;
return MatchConstraintRegex (v, s);
}
return false;
}
invalidConstraint = true;
return false;
}
static bool MatchConstraintRegex (string value, string constraint)
{
int len = constraint.Length;
if (len > 0) {
// Bug #651966 - regexp constraints must be treated
// as absolute expressions
if (constraint [0] != '^') {
constraint = "^" + constraint;
len++;
}
if (constraint [len - 1] != '$')
constraint += "$";
}
return Regex.IsMatch (value, constraint, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | RegexOptions.Compiled);
}
protected virtual bool ProcessConstraint (HttpContextBase httpContext, object constraint, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
if (parameterName == null)
throw new ArgumentNullException ("parameterName");
// .NET "compatibility"
if (values == null)
throw new NullReferenceException ();
RequestContext reqContext;
reqContext = SafeGetContext (httpContext != null ? httpContext.Request : null);
bool invalidConstraint;
bool ret = ProcessConstraintInternal (httpContext, this, constraint, parameterName, values, routeDirection, reqContext, out invalidConstraint);
if (invalidConstraint)
throw new InvalidOperationException (
String.Format (
"Constraint parameter '{0}' on the route with URL '{1}' must have a string value type or be a type which implements IRouteConstraint",
parameterName, Url
)
);
return ret;
}
private bool ProcessConstraints (HttpContextBase httpContext, RouteValueDictionary values, RouteDirection routeDirection)
{
var constraints = Constraints;
if (Constraints != null) {
foreach (var p in constraints)
if (!ProcessConstraint (httpContext, p.Value, p.Key, values, routeDirection))
return false;
}
return true;
}
RequestContext SafeGetContext (HttpRequestBase req)
{
if (req == null || req.GetType () != httpRequestBaseType)
return null;
return req.RequestContext;
}
}
}

View File

@@ -0,0 +1,270 @@
//
// RouteCollection.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2008 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Runtime.CompilerServices;
using System.Security.Permissions;
using System.Web;
using System.Web.Hosting;
namespace System.Web.Routing
{
[TypeForwardedFrom ("System.Web.Routing, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35")]
[AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class RouteCollection : Collection<RouteBase>
{
class Lock : IDisposable
{
//RouteCollection owner;
//bool read;
public Lock (RouteCollection owner, bool read)
{
//this.owner = owner;
//this.read = read;
}
public void Dispose ()
{
//if (read)
// owner.read_lock = null;
//else
// owner_write_lock = null;
}
}
public RouteCollection ()
: this (null)
{
}
public RouteCollection (VirtualPathProvider virtualPathProvider)
{
// null argument is allowed
//provider = virtualPathProvider;
read_lock = new Lock (this, true);
write_lock = new Lock (this, false);
}
//VirtualPathProvider provider;
Dictionary<string,RouteBase> d = new Dictionary<string,RouteBase> ();
Lock read_lock, write_lock;
public RouteBase this [string name] {
get {
foreach (var p in d)
if (p.Key == name)
return p.Value;
return null;
}
}
public bool LowercaseUrls { get; set; }
public bool AppendTrailingSlash { get; set; }
public bool RouteExistingFiles { get; set; }
public void Add (string name, RouteBase item)
{
lock (GetWriteLock ()) {
base.Add (item);
if (!String.IsNullOrEmpty (name))
d.Add (name, item);
}
}
protected override void ClearItems ()
{
lock (GetWriteLock ()) {
base.ClearItems ();
d.Clear ();
}
}
public IDisposable GetReadLock ()
{
return read_lock;
}
public RouteData GetRouteData (HttpContextBase httpContext)
{
if (httpContext == null)
throw new ArgumentNullException ("httpContext");
if (httpContext.Request == null)
throw new ArgumentException ("The context does not contain any request data.", "httpContext");
if (Count == 0)
return null;
if (!RouteExistingFiles) {
var path = httpContext.Request.AppRelativeCurrentExecutionFilePath;
VirtualPathProvider vpp = HostingEnvironment.VirtualPathProvider;
if (path != "~/" && vpp != null && (vpp.FileExists (path) || vpp.DirectoryExists (path)))
return null;
}
foreach (RouteBase rb in this) {
var rd = rb.GetRouteData (httpContext);
if (rd != null)
return rd;
}
return null;
}
public VirtualPathData GetVirtualPath (RequestContext requestContext, RouteValueDictionary values)
{
return GetVirtualPath (requestContext, null, values);
}
public VirtualPathData GetVirtualPath (RequestContext requestContext, string name, RouteValueDictionary values)
{
if (requestContext == null)
throw new ArgumentNullException ("httpContext");
VirtualPathData vp = null;
if (!String.IsNullOrEmpty (name)) {
RouteBase rb = this [name];
if (rb != null)
vp = rb.GetVirtualPath (requestContext, values);
else
throw new ArgumentException ("A route named '" + name + "' could not be found in the route collection.", "name");
} else {
foreach (RouteBase rb in this) {
vp = rb.GetVirtualPath (requestContext, values);
if (vp != null)
break;
}
}
if (vp != null) {
string appPath = requestContext.HttpContext.Request.ApplicationPath;
if (appPath != null && (appPath.Length == 0 || !appPath.EndsWith ("/", StringComparison.Ordinal)))
appPath += "/";
string pathWithApp = String.Concat (appPath, vp.VirtualPath);
vp.VirtualPath = requestContext.HttpContext.Response.ApplyAppPathModifier (pathWithApp);
return vp;
}
return null;
}
public IDisposable GetWriteLock ()
{
return write_lock;
}
public void Ignore (string url)
{
Ignore (url, null);
}
public void Ignore (string url, object constraints)
{
if (url == null)
throw new ArgumentNullException ("url");
Add (new Route (url, null, new RouteValueDictionary (constraints), new StopRoutingHandler ()));
}
public Route MapPageRoute (string routeName, string routeUrl, string physicalFile)
{
return MapPageRoute (routeName, routeUrl, physicalFile, true, null, null, null);
}
public Route MapPageRoute (string routeName, string routeUrl, string physicalFile, bool checkPhysicalUrlAccess)
{
return MapPageRoute (routeName, routeUrl, physicalFile, checkPhysicalUrlAccess, null, null, null);
}
public Route MapPageRoute (string routeName, string routeUrl, string physicalFile, bool checkPhysicalUrlAccess,
RouteValueDictionary defaults)
{
return MapPageRoute (routeName, routeUrl, physicalFile, checkPhysicalUrlAccess, defaults, null, null);
}
public Route MapPageRoute (string routeName, string routeUrl, string physicalFile, bool checkPhysicalUrlAccess,
RouteValueDictionary defaults, RouteValueDictionary constraints)
{
return MapPageRoute (routeName, routeUrl, physicalFile, checkPhysicalUrlAccess, defaults, constraints, null);
}
public Route MapPageRoute (string routeName, string routeUrl, string physicalFile, bool checkPhysicalUrlAccess,
RouteValueDictionary defaults, RouteValueDictionary constraints, RouteValueDictionary dataTokens)
{
if (routeUrl == null)
throw new ArgumentNullException ("routeUrl");
var route = new Route (routeUrl, defaults, constraints, dataTokens, new PageRouteHandler (physicalFile, checkPhysicalUrlAccess));
Add (routeName, route);
return route;
}
protected override void InsertItem (int index, RouteBase item)
{
// FIXME: what happens wrt its name?
lock (GetWriteLock ())
base.InsertItem (index, item);
}
protected override void RemoveItem (int index)
{
// FIXME: what happens wrt its name?
lock (GetWriteLock ()) {
string k = GetKey (index);
base.RemoveItem (index);
if (k != null)
d.Remove (k);
}
}
protected override void SetItem (int index, RouteBase item)
{
// FIXME: what happens wrt its name?
lock (GetWriteLock ()) {
string k = GetKey (index);
base.SetItem (index, item);
if (k != null)
d.Remove (k);
}
}
string GetKey (int index)
{
var item = this [index];
foreach (var p in d)
if (p.Value == item)
return p.Key;
return null;
}
}
}

View File

@@ -0,0 +1,76 @@
//
// RouteData.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2008 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Runtime.CompilerServices;
using System.Security.Permissions;
using System.Web;
namespace System.Web.Routing
{
[TypeForwardedFrom ("System.Web.Routing, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35")]
[AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class RouteData
{
public RouteData ()
: this (null, null)
{
}
public RouteData (RouteBase route, IRouteHandler routeHandler)
{
// arguments can be null.
Route = route;
RouteHandler = routeHandler;
DataTokens = new RouteValueDictionary ();
Values = new RouteValueDictionary ();
}
public RouteValueDictionary DataTokens { get; private set; }
public RouteBase Route { get; set; }
public IRouteHandler RouteHandler { get; set; }
public RouteValueDictionary Values { get; private set; }
public string GetRequiredString (string valueName)
{
object o;
if (!Values.TryGetValue (valueName, out o))
throw new InvalidOperationException (String.Format ("value name {0} does not match any of the values.", valueName));
string s = o as string;
if (String.IsNullOrEmpty (s))
throw new InvalidOperationException (String.Format ("The value for the name {0} must be a non-empty string", valueName));
return s;
}
}
}

View File

@@ -0,0 +1,101 @@
//
// PatternParser.cs
//
// Author:
// Marek Habersack <mhabersack@novell.com>
//
// Copyright (C) 2009 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if SYSTEMCORE_DEP
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace System.Web.Routing
{
static class RouteValueDictionaryExtensions
{
public static bool Has (this RouteValueDictionary dict, string key)
{
if (dict == null)
return false;
return dict.ContainsKey (key);
}
public static bool Has (this RouteValueDictionary dict, string key, object value)
{
if (dict == null)
return false;
object entryValue;
if (dict.TryGetValue (key, out entryValue)) {
if (value is string) {
if (!(entryValue is string))
return false;
string s1 = value as string;
string s2 = entryValue as string;
return String.Compare (s1, s2, StringComparison.OrdinalIgnoreCase) == 0;
}
return entryValue == null ? value == null : entryValue.Equals (value);
}
return false;
}
public static bool GetValue (this RouteValueDictionary dict, string key, out object value)
{
if (dict == null) {
value = null;
return false;
}
return dict.TryGetValue (key, out value);
}
[Conditional ("DEBUG")]
public static void Dump (this RouteValueDictionary dict, string name, string indent)
{
if (indent == null)
indent = String.Empty;
if (dict == null) {
Console.WriteLine (indent + "Dictionary '{0}' is null", name);
return;
}
if (dict.Count == 0) {
Console.WriteLine (indent + "Dictionary '{0}' is empty", name);
return;
}
Console.WriteLine (indent + "Dictionary '{0}':", name);
foreach (var de in dict)
Console.WriteLine (indent + "\t'{0}' == {1}", de.Key, de.Value);
}
}
}
#endif

View File

@@ -0,0 +1,52 @@
//
// StopRoutingHandler.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2008 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Runtime.CompilerServices;
using System.Security.Permissions;
using System.Web;
namespace System.Web.Routing
{
[TypeForwardedFrom ("System.Web.Routing, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35")]
[AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class StopRoutingHandler : IRouteHandler
{
protected virtual IHttpHandler GetHttpHandler (RequestContext requestContext)
{
throw new NotSupportedException ();
}
IHttpHandler IRouteHandler.GetHttpHandler (RequestContext requestContext)
{
return GetHttpHandler (requestContext);
}
}
}

View File

@@ -0,0 +1,88 @@
//
// UrlRoutingHandler.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2008-2010 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Runtime.CompilerServices;
using System.Security.Permissions;
using System.Web;
namespace System.Web.Routing
{
[TypeForwardedFrom ("System.Web.Routing, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35")]
[AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public abstract class UrlRoutingHandler : IHttpHandler
{
RouteCollection routes;
bool IHttpHandler.IsReusable {
get { return IsReusable; }
}
protected virtual bool IsReusable { get { return false; } }
public RouteCollection RouteCollection {
get {
if (routes == null)
routes = RouteTable.Routes;
return routes;
}
set { routes = value; }
}
void IHttpHandler.ProcessRequest (HttpContext context)
{
ProcessRequest (context);
}
protected virtual void ProcessRequest (HttpContext httpContext)
{
ProcessRequest (new HttpContextWrapper (httpContext));
}
protected virtual void ProcessRequest (HttpContextBase httpContext)
{
if (httpContext == null)
throw new ArgumentNullException ("httpContext");
var rd = RouteCollection.GetRouteData (httpContext);
if (rd == null)
throw new HttpException ("The incoming request does not match any route");
if (rd.RouteHandler == null)
throw new InvalidOperationException ("No IRouteHandler is assigned to the selected route");
RequestContext rc = new RequestContext (httpContext, rd);
var hh = rd.RouteHandler.GetHttpHandler (rc);
VerifyAndProcessRequest (hh, httpContext);
}
protected abstract void VerifyAndProcessRequest (IHttpHandler httpHandler, HttpContextBase httpContext);
}
}

View File

@@ -0,0 +1,114 @@
//
// UrlRoutingModule.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2008 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Runtime.CompilerServices;
using System.Security.Permissions;
using System.Threading;
using System.Web;
namespace System.Web.Routing
{
[TypeForwardedFrom ("System.Web.Routing, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35")]
[AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class UrlRoutingModule : IHttpModule
{
RouteCollection routes;
public RouteCollection RouteCollection {
get {
if (routes == null)
routes = RouteTable.Routes;
return routes;
}
set { routes = value; }
}
protected virtual void Dispose ()
{
}
void IHttpModule.Dispose ()
{
Dispose ();
}
void IHttpModule.Init (HttpApplication application)
{
Init (application);
}
protected virtual void Init (HttpApplication application)
{
application.PostMapRequestHandler += PostMapRequestHandler;
application.PostResolveRequestCache += PostResolveRequestCache;
}
void PostMapRequestHandler (object o, EventArgs e)
{
var app = (HttpApplication) o;
PostMapRequestHandler (new HttpContextWrapper (app.Context));
}
void PostResolveRequestCache (object o, EventArgs e)
{
var app = (HttpApplication) o;
PostResolveRequestCache (new HttpContextWrapper (app.Context));
}
[Obsolete]
public virtual void PostMapRequestHandler (HttpContextBase context)
{
}
[MonoTODO]
public virtual void PostResolveRequestCache (HttpContextBase context)
{
if (context == null)
throw new ArgumentNullException ("context");
var rd = RouteCollection.GetRouteData (context);
if (rd == null)
return; // do nothing
if (rd.RouteHandler == null)
throw new InvalidOperationException ("No IRouteHandler is assigned to the selected route");
if (rd.RouteHandler is StopRoutingHandler)
return; //stop further processing
var rc = new RequestContext (context, rd);
IHttpHandler http = rd.RouteHandler.GetHttpHandler (rc);
if (http == null)
throw new InvalidOperationException ("The mapped IRouteHandler did not return an IHttpHandler");
context.Request.RequestContext = rc;
context.RemapHandler (http);
}
}
}