diff options
Diffstat (limited to 'Common/XmlRpcCS/XmlRpcRequest.cs')
-rw-r--r-- | Common/XmlRpcCS/XmlRpcRequest.cs | 177 |
1 files changed, 0 insertions, 177 deletions
diff --git a/Common/XmlRpcCS/XmlRpcRequest.cs b/Common/XmlRpcCS/XmlRpcRequest.cs deleted file mode 100644 index 71a0dc9..0000000 --- a/Common/XmlRpcCS/XmlRpcRequest.cs +++ /dev/null | |||
@@ -1,177 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | namespace Nwc.XmlRpc | ||
29 | { | ||
30 | using System; | ||
31 | using System.Collections; | ||
32 | using System.IO; | ||
33 | using System.Xml; | ||
34 | using System.Net; | ||
35 | using System.Text; | ||
36 | using System.Reflection; | ||
37 | using System.Net.Security; | ||
38 | using System.Security.Cryptography.X509Certificates; | ||
39 | |||
40 | internal class AcceptAllCertificatePolicy : ICertificatePolicy | ||
41 | { | ||
42 | public AcceptAllCertificatePolicy() | ||
43 | { | ||
44 | } | ||
45 | |||
46 | public bool CheckValidationResult(ServicePoint sPoint, | ||
47 | System.Security.Cryptography.X509Certificates.X509Certificate cert, | ||
48 | WebRequest wRequest, int certProb) | ||
49 | { | ||
50 | // Always accept | ||
51 | return true; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | /// <summary>Class supporting the request side of an XML-RPC transaction.</summary> | ||
56 | public class XmlRpcRequest | ||
57 | { | ||
58 | private String _methodName = null; | ||
59 | private Encoding _encoding = new UTF8Encoding(); | ||
60 | private XmlRpcRequestSerializer _serializer = new XmlRpcRequestSerializer(); | ||
61 | private XmlRpcResponseDeserializer _deserializer = new XmlRpcResponseDeserializer(); | ||
62 | |||
63 | /// <summary><c>ArrayList</c> containing the parameters.</summary> | ||
64 | protected IList _params = null; | ||
65 | |||
66 | /// <summary>Instantiate an <c>XmlRpcRequest</c></summary> | ||
67 | public XmlRpcRequest() | ||
68 | { | ||
69 | _params = new ArrayList(); | ||
70 | } | ||
71 | |||
72 | /// <summary>Instantiate an <c>XmlRpcRequest</c> for a specified method and parameters.</summary> | ||
73 | /// <param name="methodName"><c>String</c> designating the <i>object.method</i> on the server the request | ||
74 | /// should be directed to.</param> | ||
75 | /// <param name="parameters"><c>ArrayList</c> of XML-RPC type parameters to invoke the request with.</param> | ||
76 | public XmlRpcRequest(String methodName, IList parameters) | ||
77 | { | ||
78 | MethodName = methodName; | ||
79 | _params = parameters; | ||
80 | } | ||
81 | |||
82 | /// <summary><c>ArrayList</c> conntaining the parameters for the request.</summary> | ||
83 | public virtual IList Params | ||
84 | { | ||
85 | get { return _params; } | ||
86 | } | ||
87 | |||
88 | /// <summary><c>String</c> conntaining the method name, both object and method, that the request will be sent to.</summary> | ||
89 | public virtual String MethodName | ||
90 | { | ||
91 | get { return _methodName; } | ||
92 | set { _methodName = value; } | ||
93 | } | ||
94 | |||
95 | /// <summary><c>String</c> object name portion of the method name.</summary> | ||
96 | public String MethodNameObject | ||
97 | { | ||
98 | get | ||
99 | { | ||
100 | int index = MethodName.IndexOf("."); | ||
101 | |||
102 | if (index == -1) | ||
103 | return MethodName; | ||
104 | |||
105 | return MethodName.Substring(0, index); | ||
106 | } | ||
107 | } | ||
108 | |||
109 | /// <summary><c>String</c> method name portion of the object.method name.</summary> | ||
110 | public String MethodNameMethod | ||
111 | { | ||
112 | get | ||
113 | { | ||
114 | int index = MethodName.IndexOf("."); | ||
115 | |||
116 | if (index == -1) | ||
117 | return MethodName; | ||
118 | |||
119 | return MethodName.Substring(index + 1, MethodName.Length - index - 1); | ||
120 | } | ||
121 | } | ||
122 | |||
123 | /// <summary>Invoke this request on the server.</summary> | ||
124 | /// <param name="url"><c>String</c> The url of the XML-RPC server.</param> | ||
125 | /// <returns><c>Object</c> The value returned from the method invocation on the server.</returns> | ||
126 | /// <exception cref="XmlRpcException">If an exception generated on the server side.</exception> | ||
127 | public Object Invoke(String url) | ||
128 | { | ||
129 | XmlRpcResponse res = Send(url, 10000); | ||
130 | |||
131 | if (res.IsFault) | ||
132 | throw new XmlRpcException(res.FaultCode, res.FaultString); | ||
133 | |||
134 | return res.Value; | ||
135 | } | ||
136 | |||
137 | /// <summary>Send the request to the server.</summary> | ||
138 | /// <param name="url"><c>String</c> The url of the XML-RPC server.</param> | ||
139 | /// <param name="timeout">Milliseconds before the connection times out.</param> | ||
140 | /// <returns><c>XmlRpcResponse</c> The response generated.</returns> | ||
141 | public XmlRpcResponse Send(String url, int timeout) | ||
142 | { | ||
143 | // Override SSL authentication mechanisms | ||
144 | ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy(); | ||
145 | |||
146 | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); | ||
147 | if (request == null) | ||
148 | throw new XmlRpcException(XmlRpcErrorCodes.TRANSPORT_ERROR, | ||
149 | XmlRpcErrorCodes.TRANSPORT_ERROR_MSG + ": Could not create request with " + url); | ||
150 | request.Method = "POST"; | ||
151 | request.ContentType = "text/xml"; | ||
152 | request.AllowWriteStreamBuffering = true; | ||
153 | request.Timeout = timeout; | ||
154 | |||
155 | Stream stream = request.GetRequestStream(); | ||
156 | XmlTextWriter xml = new XmlTextWriter(stream, _encoding); | ||
157 | _serializer.Serialize(xml, this); | ||
158 | xml.Flush(); | ||
159 | xml.Close(); | ||
160 | |||
161 | HttpWebResponse response = (HttpWebResponse)request.GetResponse(); | ||
162 | StreamReader input = new StreamReader(response.GetResponseStream()); | ||
163 | |||
164 | XmlRpcResponse resp = (XmlRpcResponse)_deserializer.Deserialize(input); | ||
165 | input.Close(); | ||
166 | response.Close(); | ||
167 | return resp; | ||
168 | } | ||
169 | |||
170 | /// <summary>Produce <c>String</c> representation of the object.</summary> | ||
171 | /// <returns><c>String</c> representation of the object.</returns> | ||
172 | override public String ToString() | ||
173 | { | ||
174 | return _serializer.Serialize(this); | ||
175 | } | ||
176 | } | ||
177 | } | ||