Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
2008-12-19 Marek Habersack <mhabersack@novell.com>
* SettingsMappingManager.cs: make sure _runningOnWindows is set
correctly on MacOS/X.
2008-09-18 Marek Habersack <mhabersack@novell.com>
* SettingsMappingManager.cs: take care of a small race condition
when mapping sections.
2008-03-01 Marek Habersack <mhabersack@novell.com>
* ISectionSettingsMapper.cs, MembershipSectionMapper.cs,
RoleManagerSectionMapper.cs, SettingsMapping.cs,
SettingsMappingManager.cs, SettingsMappingWhat.cs: moved to here
from System.Web

View File

@@ -0,0 +1,41 @@
//
// Mono.Web.Util.ISectionSettingsMapper
//
// Authors:
// Marek Habersack (mhabersack@novell.com)
//
// (C) 2007 Novell, Inc
//
//
// 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 NET_2_0
using System;
using System.Collections.Generic;
namespace Mono.Web.Util
{
public interface ISectionSettingsMapper
{
object MapSection (object section, List <SettingsMappingWhat> whats);
}
}
#endif

View File

@@ -0,0 +1,165 @@
//
// Mono.Web.Util.MembershipSectionMapper
//
// Authors:
// Marek Habersack (mhabersack@novell.com)
//
// (C) 2007 Novell, Inc
//
//
// 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 NET_2_0
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Web.Configuration;
namespace Mono.Web.Util
{
internal class MembershipSectionMapper : ISectionSettingsMapper
{
public object MapSection (object _section, List <SettingsMappingWhat> whats)
{
MembershipSection section = _section as MembershipSection;
if (section == null)
return _section;
List <SettingsMappingWhatContents> contents;
foreach (SettingsMappingWhat what in whats) {
contents = what.Contents;
if (contents == null || contents.Count == 0)
continue;
foreach (SettingsMappingWhatContents item in contents) {
switch (item.Operation) {
case SettingsMappingWhatOperation.Add:
ProcessAdd (section, item);
break;
case SettingsMappingWhatOperation.Clear:
ProcessClear (section, item);
break;
case SettingsMappingWhatOperation.Replace:
ProcessReplace (section, item);
break;
case SettingsMappingWhatOperation.Remove:
ProcessRemove (section, item);
break;
}
}
}
return section;
}
bool GetCommonAttributes (SettingsMappingWhatContents how, out string name, out string type)
{
name = type = null;
Dictionary <string, string> attrs = how.Attributes;
if (attrs == null || attrs.Count == 0)
return false;
if (!attrs.TryGetValue ("name", out name))
return false;
if (String.IsNullOrEmpty (name))
return false;
attrs.TryGetValue ("type", out type);
return true;
}
void SetProviderProperties (SettingsMappingWhatContents how, ProviderSettings prov)
{
Dictionary <string, string> attrs = how.Attributes;
if (attrs == null || attrs.Count == 0)
return;
string key;
foreach (KeyValuePair <string, string> kvp in attrs) {
key = kvp.Key;
if (key == "name")
continue;
if (key == "type") {
prov.Type = kvp.Value;
continue;
}
prov.Parameters [key] = kvp.Value;
}
}
void ProcessAdd (MembershipSection section, SettingsMappingWhatContents how)
{
string name, type;
if (!GetCommonAttributes (how, out name, out type))
return;
ProviderSettingsCollection providers = section.Providers;
ProviderSettings provider = providers [name];
if (provider != null)
return;
ProviderSettings prov = new ProviderSettings (name, type);
SetProviderProperties (how, prov);
providers.Add (prov);
}
void ProcessRemove (MembershipSection section, SettingsMappingWhatContents how)
{
string name, type;
if (!GetCommonAttributes (how, out name, out type))
return;
ProviderSettingsCollection providers = section.Providers;
ProviderSettings provider = providers [name];
if (provider != null) {
if (provider.Type != type)
return;
providers.Remove (name);
}
}
void ProcessClear (MembershipSection section, SettingsMappingWhatContents how)
{
section.Providers.Clear ();
}
void ProcessReplace (MembershipSection section, SettingsMappingWhatContents how)
{
string name, type;
if (!GetCommonAttributes (how, out name, out type))
return;
ProviderSettings provider = section.Providers [name];
if (provider != null)
SetProviderProperties (how, provider);
}
}
}
#endif

View File

@@ -0,0 +1,165 @@
//
// Mono.Web.Util.RoleManagerSectionMapper
//
// Authors:
// Marek Habersack (mhabersack@novell.com)
//
// (C) 2007 Novell, Inc
//
//
// 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 NET_2_0
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Web.Configuration;
namespace Mono.Web.Util
{
internal class RoleManagerSectionMapper : ISectionSettingsMapper
{
public object MapSection (object _section, List <SettingsMappingWhat> whats)
{
RoleManagerSection section = _section as RoleManagerSection;
if (section == null)
return _section;
List <SettingsMappingWhatContents> contents;
foreach (SettingsMappingWhat what in whats) {
contents = what.Contents;
if (contents == null || contents.Count == 0)
continue;
foreach (SettingsMappingWhatContents item in contents) {
switch (item.Operation) {
case SettingsMappingWhatOperation.Add:
ProcessAdd (section, item);
break;
case SettingsMappingWhatOperation.Clear:
ProcessClear (section, item);
break;
case SettingsMappingWhatOperation.Replace:
ProcessReplace (section, item);
break;
case SettingsMappingWhatOperation.Remove:
ProcessRemove (section, item);
break;
}
}
}
return section;
}
bool GetCommonAttributes (SettingsMappingWhatContents how, out string name, out string type)
{
name = type = null;
Dictionary <string, string> attrs = how.Attributes;
if (attrs == null || attrs.Count == 0)
return false;
if (!attrs.TryGetValue ("name", out name))
return false;
if (String.IsNullOrEmpty (name))
return false;
attrs.TryGetValue ("type", out type);
return true;
}
void SetProviderProperties (SettingsMappingWhatContents how, ProviderSettings prov)
{
Dictionary <string, string> attrs = how.Attributes;
if (attrs == null || attrs.Count == 0)
return;
string key;
foreach (KeyValuePair <string, string> kvp in attrs) {
key = kvp.Key;
if (key == "name")
continue;
if (key == "type") {
prov.Type = kvp.Value;
continue;
}
prov.Parameters [key] = kvp.Value;
}
}
void ProcessAdd (RoleManagerSection section, SettingsMappingWhatContents how)
{
string name, type;
if (!GetCommonAttributes (how, out name, out type))
return;
ProviderSettingsCollection providers = section.Providers;
ProviderSettings provider = providers [name];
if (provider != null)
return;
ProviderSettings prov = new ProviderSettings (name, type);
SetProviderProperties (how, prov);
providers.Add (prov);
}
void ProcessRemove (RoleManagerSection section, SettingsMappingWhatContents how)
{
string name, type;
if (!GetCommonAttributes (how, out name, out type))
return;
ProviderSettingsCollection providers = section.Providers;
ProviderSettings provider = providers [name];
if (provider != null) {
if (provider.Type != type)
return;
providers.Remove (name);
}
}
void ProcessClear (RoleManagerSection section, SettingsMappingWhatContents how)
{
section.Providers.Clear ();
}
void ProcessReplace (RoleManagerSection section, SettingsMappingWhatContents how)
{
string name, type;
if (!GetCommonAttributes (how, out name, out type))
return;
ProviderSettings provider = section.Providers [name];
if (provider != null)
SetProviderProperties (how, provider);
}
}
}
#endif

View File

@@ -0,0 +1,112 @@
//
// Mono.Web.Util.SettingsMapping
//
// Authors:
// Marek Habersack (mhabersack@novell.com)
//
// (C) 2007 Novell, Inc
//
//
// 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 NET_2_0
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Xml;
using System.Xml.XPath;
namespace Mono.Web.Util
{
public enum SettingsMappingPlatform
{
Windows,
Unix
};
internal class SettingsMapping
{
string _sectionTypeName;
Type _sectionType;
string _mapperTypeName;
Type _mapperType;
SettingsMappingPlatform _platform;
List <SettingsMappingWhat> _whats;
public Type SectionType {
get {
if (_sectionType == null)
_sectionType = Type.GetType (_sectionTypeName, false);
return _sectionType;
}
}
public Type MapperType {
get {
if (_mapperType == null) {
_mapperType = Type.GetType (_mapperTypeName, true);
if (!typeof (ISectionSettingsMapper).IsAssignableFrom (_mapperType)) {
_mapperType = null;
throw new InvalidOperationException ("Mapper type does not implement the ISectionSettingsMapper interface");
}
}
return _mapperType;
}
}
public SettingsMappingPlatform Platform {
get { return _platform; }
}
public SettingsMapping (XPathNavigator nav)
{
_sectionTypeName = nav.GetAttribute ("sectionType", String.Empty);
_mapperTypeName = nav.GetAttribute ("mapperType", String.Empty);
EnumConverter cvt = new EnumConverter (typeof (SettingsMappingPlatform));
_platform = (SettingsMappingPlatform) cvt.ConvertFromInvariantString (nav.GetAttribute ("platform", String.Empty));
LoadContents (nav);
}
public object MapSection (object input, Type type)
{
if (type != SectionType)
throw new ArgumentException ("type", "Invalid section type for this mapper");
ISectionSettingsMapper mapper = Activator.CreateInstance (MapperType) as ISectionSettingsMapper;
if (mapper == null)
return input;
return mapper.MapSection (input, _whats);
}
void LoadContents (XPathNavigator nav)
{
XPathNodeIterator iter = nav.Select ("./what[string-length (@value) > 0]");
_whats = new List <SettingsMappingWhat> ();
while (iter.MoveNext ())
_whats.Add (new SettingsMappingWhat (iter.Current));
}
}
}
#endif

View File

@@ -0,0 +1,186 @@
//
// Mono.Web.Util.SettingsMappingManager
//
// Authors:
// Marek Habersack (mhabersack@novell.com)
//
// (C) 2007 Novell, Inc
//
//
// 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 NET_2_0
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Runtime.InteropServices;
using System.Web;
using System.Web.Configuration;
using System.Xml;
using System.Xml.XPath;
namespace Mono.Web.Util
{
public class SettingsMappingManager
{
const string settingsMapFileName = "settings.map";
const string localSettingsMapFileName = settingsMapFileName + ".config";
static object mapperLock = new object ();
static SettingsMappingManager _instance;
static string _mappingFile;
Dictionary <Type, SettingsMapping> _mappers;
static Dictionary <object, object> _mappedSections;
static SettingsMappingPlatform _myPlatform;
static bool _runningOnWindows;
internal static bool IsRunningOnWindows {
get { return _runningOnWindows; }
}
public static SettingsMappingPlatform Platform {
get { return _myPlatform; }
}
public bool HasMappings {
get { return (_mappers != null && _mappers.Count > 0); }
}
static SettingsMappingManager ()
{
_mappingFile = Path.Combine (Path.GetDirectoryName (RuntimeEnvironment.SystemConfigurationFile), settingsMapFileName);
PlatformID pid = Environment.OSVersion.Platform;
_runningOnWindows = ((int) pid != 128 && (int) pid != 4 && (int) pid != 6);
}
static public void Init ()
{
if (_instance != null)
return;
if (Environment.GetEnvironmentVariable ("MONO_ASPNET_INHIBIT_SETTINGSMAP") != null)
return;
NameValueCollection appSettings = WebConfigurationManager.AppSettings;
if (appSettings != null) {
string inhibit = appSettings ["MonoAspnetInhibitSettingsMap"];
if (String.Compare (inhibit, "true", StringComparison.OrdinalIgnoreCase) == 0)
return;
}
if (IsRunningOnWindows)
_myPlatform = SettingsMappingPlatform.Windows;
else
_myPlatform = SettingsMappingPlatform.Unix;
SettingsMappingManager mapper = new SettingsMappingManager ();
mapper.LoadMappings ();
if (mapper.HasMappings) {
_instance = mapper;
_mappedSections = new Dictionary <object, object> ();
}
}
void LoadMappings ()
{
if (File.Exists (_mappingFile))
LoadMappings (_mappingFile);
AppDomainSetup domain = AppDomain.CurrentDomain.SetupInformation;
string appMappingFile = Path.Combine (domain.ApplicationBase, localSettingsMapFileName);
if (File.Exists (appMappingFile))
LoadMappings (appMappingFile);
}
void LoadMappings (string mappingFilePath)
{
XPathNavigator top;
XPathDocument doc;
try {
doc = new XPathDocument (mappingFilePath);
top = doc.CreateNavigator ();
} catch (Exception ex) {
throw new ApplicationException ("Error loading mapping settings", ex);
}
XPathNodeIterator iter;
if (_mappers == null)
_mappers = new Dictionary <Type, SettingsMapping> ();
else {
iter = top.Select ("//settingsMap/clear");
if (iter.MoveNext ())
_mappers.Clear ();
}
iter = top.Select ("//settingsMap/map[string-length (@sectionType) > 0 and string-length (@mapperType) > 0 and string-length (@platform) > 0]");
SettingsMapping map;
while (iter.MoveNext ()) {
map = new SettingsMapping (iter.Current);
if (_myPlatform != map.Platform)
continue;
if (!_mappers.ContainsKey (map.SectionType))
_mappers.Add (map.SectionType, map);
else
_mappers [map.SectionType] = map;
}
}
public static object MapSection (object input)
{
if (_instance == null || input == null)
return input;
object mappedSection;
if (_mappedSections.TryGetValue (input, out mappedSection))
return mappedSection;
object ret = _instance.MapSection (input, input.GetType ());
lock (mapperLock) {
if (ret != null && !_mappedSections.ContainsKey (ret))
_mappedSections.Add (ret, ret);
}
return ret;
}
object MapSection (object input, Type type)
{
if (_mappers == null || _mappers.Count == 0 || !_mappers.ContainsKey (type))
return input;
SettingsMapping map;
if (!_mappers.TryGetValue (type, out map))
return input;
if (map == null)
return input;
return map.MapSection (input, type);
}
}
}
#endif

View File

@@ -0,0 +1,117 @@
//
// Mono.Web.Util.SettingsMappingWhat
//
// Authors:
// Marek Habersack (mhabersack@novell.com)
//
// (C) 2007 Novell, Inc
//
//
// 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 NET_2_0
using System;
using System.Collections.Generic;
using System.Xml;
using System.Xml.XPath;
namespace Mono.Web.Util
{
public enum SettingsMappingWhatOperation
{
Add,
Clear,
Replace,
Remove
}
public class SettingsMappingWhatContents
{
SettingsMappingWhatOperation _operation;
Dictionary <string, string> _attributes = new Dictionary <string, string> ();
public SettingsMappingWhatOperation Operation {
get { return _operation; }
}
public Dictionary <string, string> Attributes {
get { return _attributes; }
}
public SettingsMappingWhatContents (XPathNavigator nav, SettingsMappingWhatOperation operation)
{
_operation = operation;
if (nav.HasAttributes) {
nav.MoveToFirstAttribute ();
_attributes.Add (nav.Name, nav.Value);
while (nav.MoveToNextAttribute ())
_attributes.Add (nav.Name, nav.Value);
}
}
}
public class SettingsMappingWhat
{
string _value;
List <SettingsMappingWhatContents> _contents;
public string Value {
get { return _value; }
}
public List <SettingsMappingWhatContents> Contents {
get { return _contents; }
}
public SettingsMappingWhat (XPathNavigator nav)
{
_value = nav.GetAttribute ("value", String.Empty);
XPathNodeIterator iter = nav.Select ("./*");
XPathNavigator cur;
_contents = new List <SettingsMappingWhatContents> ();
while (iter.MoveNext ()) {
cur = iter.Current;
switch (cur.LocalName) {
case "replace":
_contents.Add (new SettingsMappingWhatContents (cur, SettingsMappingWhatOperation.Replace));
break;
case "add":
_contents.Add (new SettingsMappingWhatContents (cur, SettingsMappingWhatOperation.Add));
break;
case "clear":
_contents.Add (new SettingsMappingWhatContents (cur, SettingsMappingWhatOperation.Clear));
break;
case "remove":
_contents.Add (new SettingsMappingWhatContents (cur, SettingsMappingWhatOperation.Remove));
break;
}
}
}
}
}
#endif