static IAuthenticationModule CreateInstance(string typeName, XmlNode node) { IAuthenticationModule module = null; try { Type type = Type.GetType(typeName, true); module = (IAuthenticationModule)Activator.CreateInstance(type); } catch (Exception e) { HandlersUtil.ThrowException(e.Message, node); } return(module); }
public virtual object Create(object parent, object configContext, XmlNode section) { ConnectionManagementData cmd = new ConnectionManagementData(parent); if (section.Attributes != null && section.Attributes.Count != 0) { HandlersUtil.ThrowException("Unrecognized attribute", section); } XmlNodeList httpHandlers = section.ChildNodes; foreach (XmlNode child in httpHandlers) { XmlNodeType ntype = child.NodeType; if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment) { continue; } if (ntype != XmlNodeType.Element) { HandlersUtil.ThrowException("Only elements allowed", child); } string name = child.Name; if (name == "clear") { if (child.Attributes != null && child.Attributes.Count != 0) { HandlersUtil.ThrowException("Unrecognized attribute", child); } cmd.Clear(); continue; } //LAMESPEC: the MS doc says that <remove name="..."/> but they throw an exception // if you use that. "address" is correct. string address = HandlersUtil.ExtractAttributeValue("address", child); if (name == "add") { string maxcnc = HandlersUtil.ExtractAttributeValue("maxconnection", child, true); if (child.Attributes != null && child.Attributes.Count != 0) { HandlersUtil.ThrowException("Unrecognized attribute", child); } cmd.Add(address, maxcnc); continue; } if (name == "remove") { if (child.Attributes != null && child.Attributes.Count != 0) { HandlersUtil.ThrowException("Unrecognized attribute", child); } cmd.Remove(address); continue; } HandlersUtil.ThrowException("Unexpected element", child); } return(cmd); }
public virtual object Create(object parent, object configContext, XmlNode section) { IWebProxy result = parent as IWebProxy; #if (XML_DEP) if (section.Attributes != null && section.Attributes.Count != 0) { HandlersUtil.ThrowException("Unrecognized attribute", section); } XmlNodeList nodes = section.ChildNodes; foreach (XmlNode child in nodes) { XmlNodeType ntype = child.NodeType; if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment) { continue; } if (ntype != XmlNodeType.Element) { HandlersUtil.ThrowException("Only elements allowed", child); } string name = child.Name; if (name == "proxy") { string sysdefault = HandlersUtil.ExtractAttributeValue("usesystemdefault", child, true); string bypass = HandlersUtil.ExtractAttributeValue("bypassonlocal", child, true); string address = HandlersUtil.ExtractAttributeValue("proxyaddress", child, true); if (child.Attributes != null && child.Attributes.Count != 0) { HandlersUtil.ThrowException("Unrecognized attribute", child); } result = new WebProxy(); bool bp = (bypass != null && String.Compare(bypass, "true", true) == 0); if (bp == false) { if (bypass != null && String.Compare(bypass, "false", true) != 0) { HandlersUtil.ThrowException("Invalid boolean value", child); } } if (!(result is WebProxy)) { continue; } ((WebProxy)result).BypassProxyOnLocal = bp; if (address != null) { try { ((WebProxy)result).Address = new Uri(address); continue; } catch (UriFormatException) {} //MS: ignore bad URIs, fall through to default } //MS: presence of valid address URI takes precedence over usesystemdefault if (sysdefault != null && String.Compare(sysdefault, "true", true) == 0) { address = Environment.GetEnvironmentVariable("http_proxy"); if (address == null) { address = Environment.GetEnvironmentVariable("HTTP_PROXY"); } if (address != null) { try { Uri uri = new Uri(address); IPAddress ip; if (IPAddress.TryParse(uri.Host, out ip)) { if (IPAddress.Any.Equals(ip)) { UriBuilder builder = new UriBuilder(uri); builder.Host = "127.0.0.1"; uri = builder.Uri; } else if (IPAddress.IPv6Any.Equals(ip)) { UriBuilder builder = new UriBuilder(uri); builder.Host = "[::1]"; uri = builder.Uri; } } ((WebProxy)result).Address = uri; } catch (UriFormatException) { } } } continue; } if (name == "bypasslist") { if (!(result is WebProxy)) { continue; } FillByPassList(child, (WebProxy)result); continue; } if (name == "module") { HandlersUtil.ThrowException("WARNING: module not implemented yet", child); } HandlersUtil.ThrowException("Unexpected element", child); } #endif return(result); }
public virtual object Create(object parent, object configContext, XmlNode section) { NetConfig config = new NetConfig(); #if (XML_DEP) if (section.Attributes != null && section.Attributes.Count != 0) { HandlersUtil.ThrowException("Unrecognized attribute", section); } XmlNodeList reqHandlers = section.ChildNodes; foreach (XmlNode child in reqHandlers) { XmlNodeType ntype = child.NodeType; if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment) { continue; } if (ntype != XmlNodeType.Element) { HandlersUtil.ThrowException("Only elements allowed", child); } string name = child.Name; if (name == "ipv6") { string enabled = HandlersUtil.ExtractAttributeValue("enabled", child, false); if (child.Attributes != null && child.Attributes.Count != 0) { HandlersUtil.ThrowException("Unrecognized attribute", child); } if (enabled == "true") { config.ipv6Enabled = true; } else if (enabled != "false") { HandlersUtil.ThrowException("Invalid boolean value", child); } continue; } if (name == "httpWebRequest") { string max = HandlersUtil.ExtractAttributeValue ("maximumResponseHeadersLength", child, true); // this one is just ignored HandlersUtil.ExtractAttributeValue("useUnsafeHeaderParsing", child, true); if (child.Attributes != null && child.Attributes.Count != 0) { HandlersUtil.ThrowException("Unrecognized attribute", child); } try { if (max != null) { int val = Int32.Parse(max.Trim()); if (val < -1) { HandlersUtil.ThrowException("Must be -1 or >= 0", child); } config.MaxResponseHeadersLength = val; } } catch { HandlersUtil.ThrowException("Invalid int value", child); } continue; } HandlersUtil.ThrowException("Unexpected element", child); } #endif return(config); }
public virtual object Create(object parent, object configContext, XmlNode section) { #if XML_DEP if (section.Attributes != null && section.Attributes.Count != 0) { HandlersUtil.ThrowException("Unrecognized attribute", section); } XmlNodeList reqHandlers = section.ChildNodes; foreach (XmlNode child in reqHandlers) { XmlNodeType ntype = child.NodeType; if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment) { continue; } if (ntype != XmlNodeType.Element) { HandlersUtil.ThrowException("Only elements allowed", child); } string name = child.Name; if (name == "clear") { if (child.Attributes != null && child.Attributes.Count != 0) { HandlersUtil.ThrowException("Unrecognized attribute", child); } WebRequest.PrefixList = new ArrayList(); continue; } //string prefix = HandlersUtil.ExtractAttributeValue ("prefix", child); if (name == "add") { //string type = HandlersUtil.ExtractAttributeValue ("type", child, false); if (child.Attributes != null && child.Attributes.Count != 0) { HandlersUtil.ThrowException("Unrecognized attribute", child); } throw new NotImplementedException(); //WebRequest.PrefixList.Add (new WebRequestPrefixElement(prefix, type)); //continue; } if (name == "remove") { if (child.Attributes != null && child.Attributes.Count != 0) { HandlersUtil.ThrowException("Unrecognized attribute", child); } throw new NotImplementedException(); // WebRequest.RemovePrefix (prefix); // continue; } HandlersUtil.ThrowException("Unexpected element", child); } #endif return(null); }