NetConfigurationHandler.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // System.Net.Configuration.NetConfigurationHandler.cs
  3. //
  4. // Authors:
  5. // Jerome Laban ([email protected])
  6. // Gonzalo Paniagua Javier ([email protected])
  7. //
  8. // (C) 2003 Ximian, Inc (http://www.ximian.com)
  9. // (c) 2004 Novell, Inc. (http://www.novell.com)
  10. //
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. using System.Collections;
  32. using System.Configuration;
  33. #if (XML_DEP)
  34. using System.Xml;
  35. #endif
  36. namespace System.Net.Configuration
  37. {
  38. class NetConfigurationHandler : IConfigurationSectionHandler
  39. {
  40. #if (XML_DEP)
  41. public virtual object Create (object parent, object configContext, XmlNode section)
  42. {
  43. if (section.Attributes != null && section.Attributes.Count != 0)
  44. HandlersUtil.ThrowException ("Unrecognized attribute", section);
  45. NetConfig config = new NetConfig ();
  46. XmlNodeList reqHandlers = section.ChildNodes;
  47. foreach (XmlNode child in reqHandlers) {
  48. XmlNodeType ntype = child.NodeType;
  49. if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment)
  50. continue;
  51. if (ntype != XmlNodeType.Element)
  52. HandlersUtil.ThrowException ("Only elements allowed", child);
  53. string name = child.Name;
  54. if (name == "ipv6") {
  55. string enabled = HandlersUtil.ExtractAttributeValue ("enabled", child, false);
  56. if (child.Attributes != null && child.Attributes.Count != 0)
  57. HandlersUtil.ThrowException ("Unrecognized attribute", child);
  58. if (enabled == "true")
  59. config.ipv6Enabled = true;
  60. else if (enabled != "false")
  61. HandlersUtil.ThrowException ("Invalid boolean value", child);
  62. continue;
  63. }
  64. if (name == "httpWebRequest") {
  65. string value = HandlersUtil.ExtractAttributeValue
  66. ("maximumResponseHeadersLength", child, false);
  67. if (child.Attributes != null && child.Attributes.Count != 0)
  68. HandlersUtil.ThrowException ("Unrecognized attribute", child);
  69. try {
  70. int val = Int32.Parse (value.Trim ());
  71. if (val < -1)
  72. HandlersUtil.ThrowException ("Must be -1 or >= 0", child);
  73. config.MaxResponseHeadersLength = val;
  74. } catch (Exception e) {
  75. HandlersUtil.ThrowException ("Invalid int value", child);
  76. }
  77. continue;
  78. }
  79. HandlersUtil.ThrowException ("Unexpected element", child);
  80. }
  81. return config;
  82. }
  83. #endif
  84. }
  85. }