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