merged Sys.Web.Services 2.0 support in my branch:
[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 #endif
38
39 namespace System.Net.Configuration
40 {
41         class NetConfigurationHandler : IConfigurationSectionHandler
42         {
43 #if (XML_DEP)
44                 public virtual object Create (object parent, object configContext, XmlNode section)
45                 {
46                         if (section.Attributes != null && section.Attributes.Count != 0)
47                                 HandlersUtil.ThrowException ("Unrecognized attribute", section);
48
49                         NetConfig config = new NetConfig ();
50
51                         XmlNodeList reqHandlers = section.ChildNodes;
52                         foreach (XmlNode child in reqHandlers) {
53                                 XmlNodeType ntype = child.NodeType;
54                                 if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment)
55                                         continue;
56
57                                 if (ntype != XmlNodeType.Element)
58                                         HandlersUtil.ThrowException ("Only elements allowed", child);
59                                 
60                                 string name = child.Name;
61                                 if (name == "ipv6") {
62                                         string enabled = HandlersUtil.ExtractAttributeValue ("enabled", child, false);
63                                         if (child.Attributes != null && child.Attributes.Count != 0)
64                                                 HandlersUtil.ThrowException ("Unrecognized attribute", child);
65
66                                         if (enabled == "true")
67                                                 config.ipv6Enabled = true;
68                                         else if (enabled != "false")
69                                                 HandlersUtil.ThrowException ("Invalid boolean value", child);
70                                                 
71                                         continue;
72                                 }
73
74                                 if (name == "httpWebRequest") {
75                                         string max = HandlersUtil.ExtractAttributeValue
76                                                                 ("maximumResponseHeadersLength", child, true);
77
78                                         // this one is just ignored
79                                         HandlersUtil.ExtractAttributeValue ("useUnsafeHeaderParsing", child, true);
80
81                                         if (child.Attributes != null && child.Attributes.Count != 0)
82                                                 HandlersUtil.ThrowException ("Unrecognized attribute", child);
83
84                                         try {
85                                                 if (max != null) {
86                                                         int val = Int32.Parse (max.Trim ());
87                                                         if (val < -1)
88                                                                 HandlersUtil.ThrowException ("Must be -1 or >= 0", child);
89
90                                                         config.MaxResponseHeadersLength = val;
91                                                 }
92                                         } catch {
93                                                 HandlersUtil.ThrowException ("Invalid int value", child);
94                                         }
95
96                                         continue;
97                                 }
98
99                                 HandlersUtil.ThrowException ("Unexpected element", child);
100                         }
101
102                         return config;
103                 }
104 #endif
105         }
106 }