aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Common/XmlRpcCS
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Common/XmlRpcCS/Logger.cs46
-rw-r--r--Common/XmlRpcCS/SimpleHttpRequest.cs234
-rw-r--r--Common/XmlRpcCS/XMLRPC.csproj138
-rw-r--r--Common/XmlRpcCS/XMLRPC.dll.build58
-rw-r--r--Common/XmlRpcCS/XmlRpcBoxcarRequest.cs78
-rw-r--r--Common/XmlRpcCS/XmlRpcClientProxy.cs88
-rw-r--r--Common/XmlRpcCS/XmlRpcDeserializer.cs222
-rw-r--r--Common/XmlRpcCS/XmlRpcErrorCodes.cs78
-rw-r--r--Common/XmlRpcCS/XmlRpcException.cs66
-rw-r--r--Common/XmlRpcCS/XmlRpcExposedAttribute.cs87
-rw-r--r--Common/XmlRpcCS/XmlRpcRequest.cs177
-rw-r--r--Common/XmlRpcCS/XmlRpcRequestDeserializer.cs92
-rw-r--r--Common/XmlRpcCS/XmlRpcRequestSerializer.cs78
-rw-r--r--Common/XmlRpcCS/XmlRpcResponder.cs127
-rw-r--r--Common/XmlRpcCS/XmlRpcResponse.cs112
-rw-r--r--Common/XmlRpcCS/XmlRpcResponseDeserializer.cs92
-rw-r--r--Common/XmlRpcCS/XmlRpcResponseSerializer.cs84
-rw-r--r--Common/XmlRpcCS/XmlRpcSerializer.cs143
-rw-r--r--Common/XmlRpcCS/XmlRpcServer.cs266
-rw-r--r--Common/XmlRpcCS/XmlRpcSystemObject.cs279
-rw-r--r--Common/XmlRpcCS/XmlRpcXmlTokens.cs103
21 files changed, 0 insertions, 2648 deletions
diff --git a/Common/XmlRpcCS/Logger.cs b/Common/XmlRpcCS/Logger.cs
deleted file mode 100644
index ebf804b..0000000
--- a/Common/XmlRpcCS/Logger.cs
+++ /dev/null
@@ -1,46 +0,0 @@
1namespace Nwc.XmlRpc
2{
3 using System;
4
5 /// <summary>Define levels of logging.</summary><remarks> This duplicates
6 /// similar enumerations in System.Diagnostics.EventLogEntryType. The
7 /// duplication was merited because .NET Compact Framework lacked the EventLogEntryType enum.</remarks>
8 public enum LogLevel
9 {
10 /// <summary>Information level, log entry for informational reasons only.</summary>
11 Information,
12 /// <summary>Warning level, indicates a possible problem.</summary>
13 Warning,
14 /// <summary>Error level, implies a significant problem.</summary>
15 Error
16 }
17
18 ///<summary>
19 ///Logging singleton with swappable output delegate.
20 ///</summary>
21 ///<remarks>
22 ///This singleton provides a centralized log. The actual WriteEntry calls are passed
23 ///off to a delegate however. Having a delegate do the actual logginh allows you to
24 ///implement different logging mechanism and have them take effect throughout the system.
25 ///</remarks>
26 public class Logger
27 {
28 ///<summary>Delegate definition for logging.</summary>
29 ///<param name="message">The message <c>String</c> to log.</param>
30 ///<param name="level">The <c>LogLevel</c> of your message.</param>
31 public delegate void LoggerDelegate(String message, LogLevel level);
32 ///<summary>The LoggerDelegate that will recieve WriteEntry requests.</summary>
33 static public LoggerDelegate Delegate = null;
34
35 ///<summary>
36 ///Method logging events are sent to.
37 ///</summary>
38 ///<param name="message">The message <c>String</c> to log.</param>
39 ///<param name="level">The <c>LogLevel</c> of your message.</param>
40 static public void WriteEntry(String message, LogLevel level)
41 {
42 if (Delegate != null)
43 Delegate(message, level);
44 }
45 }
46}
diff --git a/Common/XmlRpcCS/SimpleHttpRequest.cs b/Common/XmlRpcCS/SimpleHttpRequest.cs
deleted file mode 100644
index b331ce0..0000000
--- a/Common/XmlRpcCS/SimpleHttpRequest.cs
+++ /dev/null
@@ -1,234 +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*/
28namespace Nwc.XmlRpc
29{
30 using System;
31 using System.IO;
32 using System.Net.Sockets;
33 using System.Collections;
34 using System.Text;
35
36 ///<summary>Very basic HTTP request handler.</summary>
37 ///<remarks>This class is designed to accept a TcpClient and treat it as an HTTP request.
38 /// It will do some basic header parsing and manage the input and output streams associated
39 /// with the request.</remarks>
40 public class SimpleHttpRequest
41 {
42 private String _httpMethod = null;
43 private String _protocol;
44 private String _filePathFile = null;
45 private String _filePathDir = null;
46 private String __filePath;
47 private TcpClient _client;
48 private StreamReader _input;
49 private StreamWriter _output;
50 private Hashtable _headers;
51
52 /// <summary>A constructor which accepts the TcpClient.</summary>
53 /// <remarks>It creates the associated input and output streams, determines the request type,
54 /// and parses the remaining HTTP header.</remarks>
55 /// <param name="client">The <c>TcpClient</c> associated with the HTTP connection.</param>
56 public SimpleHttpRequest(TcpClient client)
57 {
58 _client = client;
59
60 _output = new StreamWriter(client.GetStream() );
61 _input = new StreamReader(client.GetStream() );
62
63 GetRequestMethod();
64 GetRequestHeaders();
65 }
66
67 /// <summary>The output <c>StreamWriter</c> associated with the request.</summary>
68 public StreamWriter Output
69 {
70 get { return _output; }
71 }
72
73 /// <summary>The input <c>StreamReader</c> associated with the request.</summary>
74 public StreamReader Input
75 {
76 get { return _input; }
77 }
78
79 /// <summary>The <c>TcpClient</c> with the request.</summary>
80 public TcpClient Client
81 {
82 get { return _client; }
83 }
84
85 private String _filePath
86 {
87 get { return __filePath; }
88 set
89 {
90 __filePath = value;
91 _filePathDir = null;
92 _filePathFile = null;
93 }
94 }
95
96 /// <summary>The type of HTTP request (i.e. PUT, GET, etc.).</summary>
97 public String HttpMethod
98 {
99 get { return _httpMethod; }
100 }
101
102 /// <summary>The level of the HTTP protocol.</summary>
103 public String Protocol
104 {
105 get { return _protocol; }
106 }
107
108 /// <summary>The "path" which is part of any HTTP request.</summary>
109 public String FilePath
110 {
111 get { return _filePath; }
112 }
113
114 /// <summary>The file portion of the "path" which is part of any HTTP request.</summary>
115 public String FilePathFile
116 {
117 get
118 {
119 if (_filePathFile != null)
120 return _filePathFile;
121
122 int i = FilePath.LastIndexOf("/");
123
124 if (i == -1)
125 return "";
126
127 i++;
128 _filePathFile = FilePath.Substring(i, FilePath.Length - i);
129 return _filePathFile;
130 }
131 }
132
133 /// <summary>The directory portion of the "path" which is part of any HTTP request.</summary>
134 public String FilePathDir
135 {
136 get
137 {
138 if (_filePathDir != null)
139 return _filePathDir;
140
141 int i = FilePath.LastIndexOf("/");
142
143 if (i == -1)
144 return "";
145
146 i++;
147 _filePathDir = FilePath.Substring(0, i);
148 return _filePathDir;
149 }
150 }
151
152 private void GetRequestMethod()
153 {
154 string req = _input.ReadLine();
155 if (req == null)
156 throw new ApplicationException("Void request.");
157
158 if (0 == String.Compare("GET ", req.Substring(0, 4), true))
159 _httpMethod = "GET";
160 else if (0 == String.Compare("POST ", req.Substring(0, 5), true))
161 _httpMethod = "POST";
162 else
163 throw new InvalidOperationException("Unrecognized method in query: " + req);
164
165 req = req.TrimEnd();
166 int idx = req.IndexOf(' ') + 1;
167 if (idx >= req.Length)
168 throw new ApplicationException("What do you want?");
169
170 string page_protocol = req.Substring(idx);
171 int idx2 = page_protocol.IndexOf(' ');
172 if (idx2 == -1)
173 idx2 = page_protocol.Length;
174
175 _filePath = page_protocol.Substring(0, idx2).Trim();
176 _protocol = page_protocol.Substring(idx2).Trim();
177 }
178
179 private void GetRequestHeaders()
180 {
181 String line;
182 int idx;
183
184 _headers = new Hashtable();
185
186 while ((line = _input.ReadLine()) != "")
187 {
188 if (line == null)
189 {
190 break;
191 }
192
193 idx = line.IndexOf(':');
194 if (idx == -1 || idx == line.Length - 1)
195 {
196 Logger.WriteEntry("Malformed header line: " + line, LogLevel.Information);
197 continue;
198 }
199
200 String key = line.Substring(0, idx);
201 String value = line.Substring(idx + 1);
202
203 try
204 {
205 _headers.Add(key, value);
206 }
207 catch (Exception)
208 {
209 Logger.WriteEntry("Duplicate header key in line: " + line, LogLevel.Information);
210 }
211 }
212 }
213
214 /// <summary>
215 /// Format the object contents into a useful string representation.
216 /// </summary>
217 ///<returns><c>String</c> representation of the <c>SimpleHttpRequest</c> as the <i>HttpMethod FilePath Protocol</i>.</returns>
218 override public String ToString()
219 {
220 return HttpMethod + " " + FilePath + " " + Protocol;
221 }
222
223 /// <summary>
224 /// Close the <c>SimpleHttpRequest</c>. This flushes and closes all associated io streams.
225 /// </summary>
226 public void Close()
227 {
228 _output.Flush();
229 _output.Close();
230 _input.Close();
231 _client.Close();
232 }
233 }
234}
diff --git a/Common/XmlRpcCS/XMLRPC.csproj b/Common/XmlRpcCS/XMLRPC.csproj
deleted file mode 100644
index 61f8be0..0000000
--- a/Common/XmlRpcCS/XMLRPC.csproj
+++ /dev/null
@@ -1,138 +0,0 @@
1<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2 <PropertyGroup>
3 <ProjectType>Local</ProjectType>
4 <ProductVersion>8.0.50727</ProductVersion>
5 <SchemaVersion>2.0</SchemaVersion>
6 <ProjectGuid>{8E81D43C-0000-0000-0000-000000000000}</ProjectGuid>
7 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
8 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
9 <ApplicationIcon></ApplicationIcon>
10 <AssemblyKeyContainerName>
11 </AssemblyKeyContainerName>
12 <AssemblyName>XMLRPC</AssemblyName>
13 <DefaultClientScript>JScript</DefaultClientScript>
14 <DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>
15 <DefaultTargetSchema>IE50</DefaultTargetSchema>
16 <DelaySign>false</DelaySign>
17 <OutputType>Library</OutputType>
18 <AppDesignerFolder></AppDesignerFolder>
19 <RootNamespace>XMLRPC</RootNamespace>
20 <StartupObject></StartupObject>
21 <FileUpgradeFlags>
22 </FileUpgradeFlags>
23 </PropertyGroup>
24 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
25 <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
26 <BaseAddress>285212672</BaseAddress>
27 <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
28 <ConfigurationOverrideFile>
29 </ConfigurationOverrideFile>
30 <DefineConstants>TRACE;DEBUG</DefineConstants>
31 <DocumentationFile></DocumentationFile>
32 <DebugSymbols>True</DebugSymbols>
33 <FileAlignment>4096</FileAlignment>
34 <Optimize>False</Optimize>
35 <OutputPath>..\..\bin\</OutputPath>
36 <RegisterForComInterop>False</RegisterForComInterop>
37 <RemoveIntegerChecks>False</RemoveIntegerChecks>
38 <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
39 <WarningLevel>4</WarningLevel>
40 <NoWarn></NoWarn>
41 </PropertyGroup>
42 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
43 <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
44 <BaseAddress>285212672</BaseAddress>
45 <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
46 <ConfigurationOverrideFile>
47 </ConfigurationOverrideFile>
48 <DefineConstants>TRACE</DefineConstants>
49 <DocumentationFile></DocumentationFile>
50 <DebugSymbols>False</DebugSymbols>
51 <FileAlignment>4096</FileAlignment>
52 <Optimize>True</Optimize>
53 <OutputPath>..\..\bin\</OutputPath>
54 <RegisterForComInterop>False</RegisterForComInterop>
55 <RemoveIntegerChecks>False</RemoveIntegerChecks>
56 <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
57 <WarningLevel>4</WarningLevel>
58 <NoWarn></NoWarn>
59 </PropertyGroup>
60 <ItemGroup>
61 <Reference Include="System" >
62 <HintPath>System.dll</HintPath>
63 <Private>False</Private>
64 </Reference>
65 <Reference Include="System.Xml" >
66 <HintPath>System.Xml.dll</HintPath>
67 <Private>False</Private>
68 </Reference>
69 </ItemGroup>
70 <ItemGroup>
71 </ItemGroup>
72 <ItemGroup>
73 <Compile Include="Logger.cs">
74 <SubType>Code</SubType>
75 </Compile>
76 <Compile Include="SimpleHttpRequest.cs">
77 <SubType>Code</SubType>
78 </Compile>
79 <Compile Include="XmlRpcBoxcarRequest.cs">
80 <SubType>Code</SubType>
81 </Compile>
82 <Compile Include="XmlRpcClientProxy.cs">
83 <SubType>Code</SubType>
84 </Compile>
85 <Compile Include="XmlRpcDeserializer.cs">
86 <SubType>Code</SubType>
87 </Compile>
88 <Compile Include="XmlRpcErrorCodes.cs">
89 <SubType>Code</SubType>
90 </Compile>
91 <Compile Include="XmlRpcException.cs">
92 <SubType>Code</SubType>
93 </Compile>
94 <Compile Include="XmlRpcExposedAttribute.cs">
95 <SubType>Code</SubType>
96 </Compile>
97 <Compile Include="XmlRpcRequest.cs">
98 <SubType>Code</SubType>
99 </Compile>
100 <Compile Include="XmlRpcRequestDeserializer.cs">
101 <SubType>Code</SubType>
102 </Compile>
103 <Compile Include="XmlRpcRequestSerializer.cs">
104 <SubType>Code</SubType>
105 </Compile>
106 <Compile Include="XmlRpcResponder.cs">
107 <SubType>Code</SubType>
108 </Compile>
109 <Compile Include="XmlRpcResponse.cs">
110 <SubType>Code</SubType>
111 </Compile>
112 <Compile Include="XmlRpcResponseDeserializer.cs">
113 <SubType>Code</SubType>
114 </Compile>
115 <Compile Include="XmlRpcResponseSerializer.cs">
116 <SubType>Code</SubType>
117 </Compile>
118 <Compile Include="XmlRpcSerializer.cs">
119 <SubType>Code</SubType>
120 </Compile>
121 <Compile Include="XmlRpcServer.cs">
122 <SubType>Code</SubType>
123 </Compile>
124 <Compile Include="XmlRpcSystemObject.cs">
125 <SubType>Code</SubType>
126 </Compile>
127 <Compile Include="XmlRpcXmlTokens.cs">
128 <SubType>Code</SubType>
129 </Compile>
130 </ItemGroup>
131 <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
132 <PropertyGroup>
133 <PreBuildEvent>
134 </PreBuildEvent>
135 <PostBuildEvent>
136 </PostBuildEvent>
137 </PropertyGroup>
138</Project>
diff --git a/Common/XmlRpcCS/XMLRPC.dll.build b/Common/XmlRpcCS/XMLRPC.dll.build
deleted file mode 100644
index 2eabfcd..0000000
--- a/Common/XmlRpcCS/XMLRPC.dll.build
+++ /dev/null
@@ -1,58 +0,0 @@
1<?xml version="1.0" ?>
2<project name="XMLRPC" default="build">
3 <target name="build">
4 <echo message="Build Directory is ${project::get-base-directory()}/${build.dir}" />
5 <mkdir dir="${project::get-base-directory()}/${build.dir}" />
6 <copy todir="${project::get-base-directory()}/${build.dir}">
7 <fileset basedir="${project::get-base-directory()}">
8 </fileset>
9 </copy>
10 <csc target="library" debug="${build.debug}" unsafe="False" define="TRACE;DEBUG" output="${project::get-base-directory()}/${build.dir}/${project::get-name()}.dll">
11 <resources prefix="XMLRPC" dynamicprefix="true" >
12 </resources>
13 <sources failonempty="true">
14 <include name="Logger.cs" />
15 <include name="SimpleHttpRequest.cs" />
16 <include name="XmlRpcBoxcarRequest.cs" />
17 <include name="XmlRpcClientProxy.cs" />
18 <include name="XmlRpcDeserializer.cs" />
19 <include name="XmlRpcErrorCodes.cs" />
20 <include name="XmlRpcException.cs" />
21 <include name="XmlRpcExposedAttribute.cs" />
22 <include name="XmlRpcRequest.cs" />
23 <include name="XmlRpcRequestDeserializer.cs" />
24 <include name="XmlRpcRequestSerializer.cs" />
25 <include name="XmlRpcResponder.cs" />
26 <include name="XmlRpcResponse.cs" />
27 <include name="XmlRpcResponseDeserializer.cs" />
28 <include name="XmlRpcResponseSerializer.cs" />
29 <include name="XmlRpcSerializer.cs" />
30 <include name="XmlRpcServer.cs" />
31 <include name="XmlRpcSystemObject.cs" />
32 <include name="XmlRpcXmlTokens.cs" />
33 </sources>
34 <references basedir="${project::get-base-directory()}">
35 <lib>
36 <include name="${project::get-base-directory()}" />
37 <include name="${project::get-base-directory()}/${build.dir}" />
38 </lib>
39 <include name="System.dll" />
40 <include name="System.Xml.dll" />
41 </references>
42 </csc>
43 <echo message="Copying from [${project::get-base-directory()}/${build.dir}/] to [${project::get-base-directory()}/../../bin/" />
44 <mkdir dir="${project::get-base-directory()}/../../bin/"/>
45 <copy todir="${project::get-base-directory()}/../../bin/">
46 <fileset basedir="${project::get-base-directory()}/${build.dir}/" >
47 <include name="*.dll"/>
48 <include name="*.exe"/>
49 </fileset>
50 </copy>
51 </target>
52 <target name="clean">
53 <delete dir="${bin.dir}" failonerror="false" />
54 <delete dir="${obj.dir}" failonerror="false" />
55 </target>
56 <target name="doc" description="Creates documentation.">
57 </target>
58</project>
diff --git a/Common/XmlRpcCS/XmlRpcBoxcarRequest.cs b/Common/XmlRpcCS/XmlRpcBoxcarRequest.cs
deleted file mode 100644
index 064c165..0000000
--- a/Common/XmlRpcCS/XmlRpcBoxcarRequest.cs
+++ /dev/null
@@ -1,78 +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*/
28namespace 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
38 /// <summary>Class that collects individual <c>XmlRpcRequest</c> objects and submits them as a <i>boxcarred</i> request.</summary>
39 /// <remarks>A boxcared request is when a number of request are collected before being sent via XML-RPC, and then are sent via
40 /// a single HTTP connection. This results in a speed up from reduced connection time. The results are then retuned collectively
41 /// as well.
42 ///</remarks>
43 /// <seealso cref="XmlRpcRequest"/>
44 public class XmlRpcBoxcarRequest : XmlRpcRequest
45 {
46 /// <summary>ArrayList to collect the requests to boxcar.</summary>
47 public IList Requests = new ArrayList();
48
49 /// <summary>Basic constructor.</summary>
50 public XmlRpcBoxcarRequest()
51 {
52 }
53
54 /// <summary>Returns the <c>String</c> "system.multiCall" which is the server method that handles boxcars.</summary>
55 public override String MethodName
56 {
57 get { return "system.multiCall"; }
58 }
59
60 /// <summary>The <c>ArrayList</c> of boxcarred <paramref>Requests</paramref> as properly formed parameters.</summary>
61 public override IList Params
62 {
63 get {
64 _params.Clear();
65 ArrayList reqArray = new ArrayList();
66 foreach (XmlRpcRequest request in Requests)
67 {
68 Hashtable requestEntry = new Hashtable();
69 requestEntry.Add(XmlRpcXmlTokens.METHOD_NAME, request.MethodName);
70 requestEntry.Add(XmlRpcXmlTokens.PARAMS, request.Params);
71 reqArray.Add(requestEntry);
72 }
73 _params.Add(reqArray);
74 return _params;
75 }
76 }
77 }
78}
diff --git a/Common/XmlRpcCS/XmlRpcClientProxy.cs b/Common/XmlRpcCS/XmlRpcClientProxy.cs
deleted file mode 100644
index e9af1ac..0000000
--- a/Common/XmlRpcCS/XmlRpcClientProxy.cs
+++ /dev/null
@@ -1,88 +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*/
28namespace Nwc.XmlRpc
29{
30 using System;
31 using System.Runtime.Remoting.Proxies;
32 using System.Runtime.Remoting.Messaging;
33
34 /// <summary>This class provides support for creating local proxies of XML-RPC remote objects</summary>
35 /// <remarks>
36 /// To create a local proxy you need to create a local C# interface and then, via <i>createProxy</i>
37 /// associate that interface with a remote object at a given URL.
38 /// </remarks>
39public class XmlRpcClientProxy : RealProxy
40{
41 private String _remoteObjectName;
42 private String _url;
43 private XmlRpcRequest _client = new XmlRpcRequest();
44
45 /// <summary>Factory method to create proxies.</summary>
46 /// <remarks>
47 /// To create a local proxy you need to create a local C# interface with methods that mirror those of the server object.
48 /// Next, pass that interface into <c>createProxy</c> along with the object name and URL of the remote object and
49 /// cast the resulting object to the specifice interface.
50 /// </remarks>
51 /// <param name="remoteObjectName"><c>String</c> The name of the remote object.</param>
52 /// <param name="url"><c>String</c> The URL of the remote object.</param>
53 /// <param name="anInterface"><c>Type</c> The typeof() of a C# interface.</param>
54 /// <returns><c>Object</c> A proxy for your specified interface. Cast to appropriate type.</returns>
55 public static Object createProxy(String remoteObjectName, String url, Type anInterface)
56 {
57 return new XmlRpcClientProxy(remoteObjectName, url, anInterface).GetTransparentProxy();
58 }
59
60 private XmlRpcClientProxy(String remoteObjectName, String url, Type t) : base(t)
61 {
62 _remoteObjectName = remoteObjectName;
63 _url = url;
64 }
65
66 /// <summary>The local method dispatcher - do not invoke.</summary>
67 override public IMessage Invoke(IMessage msg)
68 {
69 IMethodCallMessage methodMessage = (IMethodCallMessage)msg;
70
71 _client.MethodName = _remoteObjectName + "." + methodMessage.MethodName;
72 _client.Params.Clear();
73 foreach (Object o in methodMessage.Args)
74 _client.Params.Add(o);
75
76 try
77 {
78 Object ret = _client.Invoke(_url);
79 return new ReturnMessage(ret,null,0,
80 methodMessage.LogicalCallContext, methodMessage);
81 }
82 catch (Exception e)
83 {
84 return new ReturnMessage(e, methodMessage);
85 }
86 }
87}
88}
diff --git a/Common/XmlRpcCS/XmlRpcDeserializer.cs b/Common/XmlRpcCS/XmlRpcDeserializer.cs
deleted file mode 100644
index bffda57..0000000
--- a/Common/XmlRpcCS/XmlRpcDeserializer.cs
+++ /dev/null
@@ -1,222 +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*/
28namespace Nwc.XmlRpc
29{
30 using System;
31 using System.Collections;
32 using System.IO;
33 using System.Xml;
34 using System.Globalization;
35
36 /// <summary>Parser context, we maintain contexts in a stack to avoiding recursion. </summary>
37 struct Context
38 {
39 public String Name;
40 public Object Container;
41 }
42
43 /// <summary>Basic XML-RPC data deserializer.</summary>
44 /// <remarks>Uses <c>XmlTextReader</c> to parse the XML data. This level of the class
45 /// only handles the tokens common to both Requests and Responses. This class is not useful in and of itself
46 /// but is designed to be subclassed.</remarks>
47 public class XmlRpcDeserializer : XmlRpcXmlTokens
48 {
49 private static DateTimeFormatInfo _dateFormat = new DateTimeFormatInfo();
50
51 private Object _container;
52 private Stack _containerStack;
53
54 /// <summary>Protected reference to last text.</summary>
55 protected String _text;
56 /// <summary>Protected reference to last deserialized value.</summary>
57 protected Object _value;
58 /// <summary>Protected reference to last name field.</summary>
59 protected String _name;
60
61
62 /// <summary>Basic constructor.</summary>
63 public XmlRpcDeserializer()
64 {
65 Reset();
66 _dateFormat.FullDateTimePattern = ISO_DATETIME;
67 }
68
69 /// <summary>Static method that parses XML data into a response using the Singleton.</summary>
70 /// <param name="xmlData"><c>StreamReader</c> containing an XML-RPC response.</param>
71 /// <returns><c>Object</c> object resulting from the deserialization.</returns>
72 virtual public Object Deserialize(TextReader xmlData)
73 {
74 return null;
75 }
76
77 /// <summary>Protected method to parse a node in an XML-RPC XML stream.</summary>
78 /// <remarks>Method deals with elements common to all XML-RPC data, subclasses of
79 /// this object deal with request/response spefic elements.</remarks>
80 /// <param name="reader"><c>XmlTextReader</c> of the in progress parsing data stream.</param>
81 protected void DeserializeNode(XmlTextReader reader)
82 {
83 switch (reader.NodeType)
84 {
85 case XmlNodeType.Element:
86 if (Logger.Delegate != null)
87 Logger.WriteEntry("START " + reader.Name, LogLevel.Information);
88 switch (reader.Name)
89 {
90 case VALUE:
91 _value = null;
92 _text = null;
93 break;
94 case STRUCT:
95 PushContext();
96 _container = new Hashtable();
97 break;
98 case ARRAY:
99 PushContext();
100 _container = new ArrayList();
101 break;
102 }
103 break;
104 case XmlNodeType.EndElement:
105 if (Logger.Delegate != null)
106 Logger.WriteEntry("END " + reader.Name, LogLevel.Information);
107 switch (reader.Name)
108 {
109 case BASE64:
110 _value = Convert.FromBase64String(_text);
111 break;
112 case BOOLEAN:
113 int val = Int16.Parse(_text);
114 if (val == 0)
115 _value = false;
116 else if (val == 1)
117 _value = true;
118 break;
119 case STRING:
120 _value = _text;
121 break;
122 case DOUBLE:
123 _value = Double.Parse(_text);
124 break;
125 case INT:
126 case ALT_INT:
127 _value = Int32.Parse(_text);
128 break;
129 case DATETIME:
130#if __MONO__
131 _value = DateParse(_text);
132#else
133 _value = DateTime.ParseExact(_text, "F", _dateFormat);
134#endif
135 break;
136 case NAME:
137 _name = _text;
138 break;
139 case VALUE:
140 if (_value == null)
141 _value = _text; // some kits don't use <string> tag, they just do <value>
142
143 if ((_container != null) && (_container is IList)) // in an array? If so add value to it.
144 ((IList)_container).Add(_value);
145 break;
146 case MEMBER:
147 if ((_container != null) && (_container is IDictionary)) // in an struct? If so add value to it.
148 ((IDictionary)_container).Add(_name, _value);
149 break;
150 case ARRAY:
151 case STRUCT:
152 _value = _container;
153 PopContext();
154 break;
155 }
156 break;
157 case XmlNodeType.Text:
158 if (Logger.Delegate != null)
159 Logger.WriteEntry("Text " + reader.Value, LogLevel.Information);
160 _text = reader.Value;
161 break;
162 default:
163 break;
164 }
165 }
166
167 /// <summary>Static method that parses XML in a <c>String</c> into a
168 /// request using the Singleton.</summary>
169 /// <param name="xmlData"><c>String</c> containing an XML-RPC request.</param>
170 /// <returns><c>XmlRpcRequest</c> object resulting from the parse.</returns>
171 public Object Deserialize(String xmlData)
172 {
173 StringReader sr = new StringReader(xmlData);
174 return Deserialize(sr);
175 }
176
177 /// <summary>Pop a Context of the stack, an Array or Struct has closed.</summary>
178 private void PopContext()
179 {
180 Context c = (Context)_containerStack.Pop();
181 _container = c.Container;
182 _name = c.Name;
183 }
184
185 /// <summary>Push a Context on the stack, an Array or Struct has opened.</summary>
186 private void PushContext()
187 {
188 Context context;
189
190 context.Container = _container;
191 context.Name = _name;
192
193 _containerStack.Push(context);
194 }
195
196 /// <summary>Reset the internal state of the deserializer.</summary>
197 protected void Reset()
198 {
199 _text = null;
200 _value = null;
201 _name = null;
202 _container = null;
203 _containerStack = new Stack();
204 }
205
206#if __MONO__
207 private DateTime DateParse(String str)
208 {
209 int year = Int32.Parse(str.Substring(0,4));
210 int month = Int32.Parse(str.Substring(4,2));
211 int day = Int32.Parse(str.Substring(6,2));
212 int hour = Int32.Parse(str.Substring(9,2));
213 int min = Int32.Parse(str.Substring(12,2));
214 int sec = Int32.Parse(str.Substring(15,2));
215 return new DateTime(year,month,day,hour,min,sec);
216 }
217#endif
218
219 }
220}
221
222
diff --git a/Common/XmlRpcCS/XmlRpcErrorCodes.cs b/Common/XmlRpcCS/XmlRpcErrorCodes.cs
deleted file mode 100644
index 258ebe6..0000000
--- a/Common/XmlRpcCS/XmlRpcErrorCodes.cs
+++ /dev/null
@@ -1,78 +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*/
28namespace Nwc.XmlRpc
29{
30 using System;
31
32 /// <summary>Standard XML-RPC error codes.</summary>
33 public class XmlRpcErrorCodes
34 {
35 /// <summary></summary>
36 public const int PARSE_ERROR_MALFORMED = -32700;
37 /// <summary></summary>
38 public const String PARSE_ERROR_MALFORMED_MSG = "Parse Error, not well formed";
39
40 /// <summary></summary>
41 public const int PARSE_ERROR_ENCODING = -32701;
42 /// <summary></summary>
43 public const String PARSE_ERROR_ENCODING_MSG = "Parse Error, unsupported encoding";
44
45 //
46 // -32702 ---> parse error. invalid character for encoding
47 // -32600 ---> server error. invalid xml-rpc. not conforming to spec.
48 //
49
50 /// <summary></summary>
51 public const int SERVER_ERROR_METHOD = -32601;
52 /// <summary></summary>
53 public const String SERVER_ERROR_METHOD_MSG = "Server Error, requested method not found";
54
55 /// <summary></summary>
56 public const int SERVER_ERROR_PARAMS = -32602;
57 /// <summary></summary>
58 public const String SERVER_ERROR_PARAMS_MSG = "Server Error, invalid method parameters";
59
60 //
61 // -32603 ---> server error. internal xml-rpc error
62 //
63
64 /// <summary></summary>
65 public const int APPLICATION_ERROR = -32500;
66 /// <summary></summary>
67 public const String APPLICATION_ERROR_MSG = "Application Error";
68
69 //
70 // -32400 ---> system error
71 //
72
73 /// <summary></summary>
74 public const int TRANSPORT_ERROR = -32300;
75 /// <summary></summary>
76 public const String TRANSPORT_ERROR_MSG = "Transport Layer Error";
77 }
78}
diff --git a/Common/XmlRpcCS/XmlRpcException.cs b/Common/XmlRpcCS/XmlRpcException.cs
deleted file mode 100644
index f728f90..0000000
--- a/Common/XmlRpcCS/XmlRpcException.cs
+++ /dev/null
@@ -1,66 +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*/
28namespace Nwc.XmlRpc
29{
30 using System;
31
32 /// <summary>An XML-RPC Exception.</summary>
33 /// <remarks>Maps a C# exception to an XML-RPC fault. Normal exceptions
34 /// include a message so this adds the code needed by XML-RPC.</remarks>
35 public class XmlRpcException : Exception
36 {
37 private int _code;
38
39 /// <summary>Instantiate an <c>XmlRpcException</c> with a code and message.</summary>
40 /// <param name="code"><c>Int</c> faultCode associated with this exception.</param>
41 /// <param name="message"><c>String</c> faultMessage associated with this exception.</param>
42 public XmlRpcException(int code, String message)
43 : base(message)
44 {
45 _code = code;
46 }
47
48 /// <summary>The value of the faults message, i.e. the faultString.</summary>
49 public String FaultString
50 {
51 get { return Message; }
52 }
53
54 /// <summary>The value of the faults code, i.e. the faultCode.</summary>
55 public int FaultCode
56 {
57 get { return _code; }
58 }
59
60 /// <summary>Format the message to include the code.</summary>
61 override public String ToString()
62 {
63 return "Code: " + FaultCode + " Message: " + base.ToString();
64 }
65 }
66}
diff --git a/Common/XmlRpcCS/XmlRpcExposedAttribute.cs b/Common/XmlRpcCS/XmlRpcExposedAttribute.cs
deleted file mode 100644
index 261ade3..0000000
--- a/Common/XmlRpcCS/XmlRpcExposedAttribute.cs
+++ /dev/null
@@ -1,87 +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*/
28namespace Nwc.XmlRpc
29{
30 using System;
31 using System.Reflection;
32
33 /// <summary>
34 /// Simple tagging attribute to indicate participation is XML-RPC exposure.
35 /// </summary>
36 /// <remarks>
37 /// If present at the class level it indicates that this class does explicitly
38 /// expose methods. If present at the method level it denotes that the method
39 /// is exposed.
40 /// </remarks>
41 [AttributeUsage(
42 AttributeTargets.Class | AttributeTargets.Method,
43 AllowMultiple = false,
44 Inherited = true
45 )]
46 public class XmlRpcExposedAttribute : Attribute
47 {
48 /// <summary>Check if <paramref>obj</paramref> is an object utilizing the XML-RPC exposed Attribute.</summary>
49 /// <param name="obj"><c>Object</c> of a class or method to check for attribute.</param>
50 /// <returns><c>Boolean</c> true if attribute present.</returns>
51 public static Boolean ExposedObject(Object obj)
52 {
53 return IsExposed(obj.GetType());
54 }
55
56 /// <summary>Check if <paramref>obj</paramref>.<paramref>methodName</paramref> is an XML-RPC exposed method.</summary>
57 /// <remarks>A method is considered to be exposed if it exists and, either, the object does not use the XmlRpcExposed attribute,
58 /// or the object does use the XmlRpcExposed attribute and the method has the XmlRpcExposed attribute as well.</remarks>
59 /// <returns><c>Boolean</c> true if the method is exposed.</returns>
60 public static Boolean ExposedMethod(Object obj, String methodName)
61 {
62 Type type = obj.GetType();
63 MethodInfo method = type.GetMethod(methodName);
64
65 if (method == null)
66 throw new MissingMethodException("Method " + methodName + " not found.");
67
68 if (!IsExposed(type))
69 return true;
70
71 return IsExposed(method);
72 }
73
74 /// <summary>Check if <paramref>mi</paramref> is XML-RPC exposed.</summary>
75 /// <param name="mi"><c>MemberInfo</c> of a class or method to check for attribute.</param>
76 /// <returns><c>Boolean</c> true if attribute present.</returns>
77 public static Boolean IsExposed(MemberInfo mi)
78 {
79 foreach (Attribute attr in mi.GetCustomAttributes(true))
80 {
81 if (attr is XmlRpcExposedAttribute)
82 return true;
83 }
84 return false;
85 }
86 }
87}
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*/
28namespace 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}
diff --git a/Common/XmlRpcCS/XmlRpcRequestDeserializer.cs b/Common/XmlRpcCS/XmlRpcRequestDeserializer.cs
deleted file mode 100644
index 126a172..0000000
--- a/Common/XmlRpcCS/XmlRpcRequestDeserializer.cs
+++ /dev/null
@@ -1,92 +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*/
28namespace Nwc.XmlRpc
29{
30 using System;
31 using System.Collections;
32 using System.Diagnostics;
33 using System.IO;
34 using System.Xml;
35
36 /// <summary>Class to deserialize XML data representing a request.</summary>
37 public class XmlRpcRequestDeserializer : XmlRpcDeserializer
38 {
39 static private XmlRpcRequestDeserializer _singleton;
40 /// <summary>A static singleton instance of this deserializer.</summary>
41 [Obsolete("This object is now thread safe, just use an instance.", false)]
42 static public XmlRpcRequestDeserializer Singleton
43 {
44 get
45 {
46 if (_singleton == null)
47 _singleton = new XmlRpcRequestDeserializer();
48
49 return _singleton;
50 }
51 }
52
53 /// <summary>Static method that parses XML data into a request using the Singleton.</summary>
54 /// <param name="xmlData"><c>StreamReader</c> containing an XML-RPC request.</param>
55 /// <returns><c>XmlRpcRequest</c> object resulting from the parse.</returns>
56 override public Object Deserialize(TextReader xmlData)
57 {
58 XmlTextReader reader = new XmlTextReader(xmlData);
59
60 XmlRpcRequest request = new XmlRpcRequest();
61 bool done = false;
62
63 lock (this)
64 {
65 Reset();
66 while (!done && reader.Read())
67 {
68 DeserializeNode(reader); // Parent parse...
69 switch (reader.NodeType)
70 {
71 case XmlNodeType.EndElement:
72 switch (reader.Name)
73 {
74 case METHOD_NAME:
75 request.MethodName = _text;
76 break;
77 case METHOD_CALL:
78 done = true;
79 break;
80 case PARAM:
81 request.Params.Add(_value);
82 _text = null;
83 break;
84 }
85 break;
86 }
87 }
88 }
89 return request;
90 }
91 }
92}
diff --git a/Common/XmlRpcCS/XmlRpcRequestSerializer.cs b/Common/XmlRpcCS/XmlRpcRequestSerializer.cs
deleted file mode 100644
index 9bf95c7..0000000
--- a/Common/XmlRpcCS/XmlRpcRequestSerializer.cs
+++ /dev/null
@@ -1,78 +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*/
28namespace Nwc.XmlRpc
29{
30 using System;
31 using System.Collections;
32 using System.Xml;
33 using System.IO;
34
35 /// <summary>Class responsible for serializing an XML-RPC request.</summary>
36 /// <remarks>This class handles the request envelope, depending on <c>XmlRpcSerializer</c>
37 /// to serialize the payload.</remarks>
38 /// <seealso cref="XmlRpcSerializer"/>
39 public class XmlRpcRequestSerializer : XmlRpcSerializer
40 {
41 static private XmlRpcRequestSerializer _singleton;
42 /// <summary>A static singleton instance of this deserializer.</summary>
43 static public XmlRpcRequestSerializer Singleton
44 {
45 get
46 {
47 if (_singleton == null)
48 _singleton = new XmlRpcRequestSerializer();
49
50 return _singleton;
51 }
52 }
53
54 /// <summary>Serialize the <c>XmlRpcRequest</c> to the output stream.</summary>
55 /// <param name="output">An <c>XmlTextWriter</c> stream to write data to.</param>
56 /// <param name="obj">An <c>XmlRpcRequest</c> to serialize.</param>
57 /// <seealso cref="XmlRpcRequest"/>
58 override public void Serialize(XmlTextWriter output, Object obj)
59 {
60 XmlRpcRequest request = (XmlRpcRequest)obj;
61 output.WriteStartDocument();
62 output.WriteStartElement(METHOD_CALL);
63 output.WriteElementString(METHOD_NAME, request.MethodName);
64 output.WriteStartElement(PARAMS);
65 foreach (Object param in request.Params)
66 {
67 output.WriteStartElement(PARAM);
68 output.WriteStartElement(VALUE);
69 SerializeObject(output, param);
70 output.WriteEndElement();
71 output.WriteEndElement();
72 }
73
74 output.WriteEndElement();
75 output.WriteEndElement();
76 }
77 }
78}
diff --git a/Common/XmlRpcCS/XmlRpcResponder.cs b/Common/XmlRpcCS/XmlRpcResponder.cs
deleted file mode 100644
index 05377a2..0000000
--- a/Common/XmlRpcCS/XmlRpcResponder.cs
+++ /dev/null
@@ -1,127 +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*/
28namespace Nwc.XmlRpc
29{
30 using System;
31 using System.Xml;
32 using System.Net.Sockets;
33 using System.Text;
34
35 /// <summary>The class is a container of the context of an XML-RPC dialog on the server side.</summary>
36 /// <remarks>Instances of this class maintain the context for an individual XML-RPC server
37 /// side dialog. Namely they manage an inbound deserializer and an outbound serializer. </remarks>
38 public class XmlRpcResponder
39 {
40 private XmlRpcRequestDeserializer _deserializer = new XmlRpcRequestDeserializer();
41 private XmlRpcResponseSerializer _serializer = new XmlRpcResponseSerializer();
42 private XmlRpcServer _server;
43 private TcpClient _client;
44 private SimpleHttpRequest _httpReq;
45
46 /// <summary>The SimpleHttpRequest based on the TcpClient.</summary>
47 public SimpleHttpRequest HttpReq
48 {
49 get { return _httpReq; }
50 }
51
52 /// <summary>Basic constructor.</summary>
53 /// <param name="server">XmlRpcServer that this XmlRpcResponder services.</param>
54 /// <param name="client">TcpClient with the connection.</param>
55 public XmlRpcResponder(XmlRpcServer server, TcpClient client)
56 {
57 _server = server;
58 _client = client;
59 _httpReq = new SimpleHttpRequest(_client);
60 }
61
62 /// <summary>Call close to insure proper shutdown.</summary>
63 ~XmlRpcResponder()
64 {
65 Close();
66 }
67
68 ///<summary>Respond using this responders HttpReq.</summary>
69 public void Respond()
70 {
71 Respond(HttpReq);
72 }
73
74 /// <summary>Handle an HTTP request containing an XML-RPC request.</summary>
75 /// <remarks>This method deserializes the XML-RPC request, invokes the
76 /// described method, serializes the response (or fault) and sends the XML-RPC response
77 /// back as a valid HTTP page.
78 /// </remarks>
79 /// <param name="httpReq"><c>SimpleHttpRequest</c> containing the request.</param>
80 public void Respond(SimpleHttpRequest httpReq)
81 {
82 XmlRpcRequest xmlRpcReq = (XmlRpcRequest)_deserializer.Deserialize(httpReq.Input);
83 XmlRpcResponse xmlRpcResp = new XmlRpcResponse();
84
85 try
86 {
87 xmlRpcResp.Value = _server.Invoke(xmlRpcReq);
88 }
89 catch (XmlRpcException e)
90 {
91 xmlRpcResp.SetFault(e.FaultCode, e.FaultString);
92 }
93 catch (Exception e2)
94 {
95 xmlRpcResp.SetFault(XmlRpcErrorCodes.APPLICATION_ERROR,
96 XmlRpcErrorCodes.APPLICATION_ERROR_MSG + ": " + e2.Message);
97 }
98
99 if (Logger.Delegate != null)
100 Logger.WriteEntry(xmlRpcResp.ToString(), LogLevel.Information);
101
102 XmlRpcServer.HttpHeader(httpReq.Protocol, "text/xml", 0, " 200 OK", httpReq.Output);
103 httpReq.Output.Flush();
104
105 XmlTextWriter xml = new XmlTextWriter(httpReq.Output);
106 _serializer.Serialize(xml, xmlRpcResp);
107 xml.Flush();
108 httpReq.Output.Flush();
109 }
110
111 ///<summary>Close all contained resources, both the HttpReq and client.</summary>
112 public void Close()
113 {
114 if (_httpReq != null)
115 {
116 _httpReq.Close();
117 _httpReq = null;
118 }
119
120 if (_client != null)
121 {
122 _client.Close();
123 _client = null;
124 }
125 }
126 }
127}
diff --git a/Common/XmlRpcCS/XmlRpcResponse.cs b/Common/XmlRpcCS/XmlRpcResponse.cs
deleted file mode 100644
index 414998e..0000000
--- a/Common/XmlRpcCS/XmlRpcResponse.cs
+++ /dev/null
@@ -1,112 +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*/
28namespace Nwc.XmlRpc
29{
30 using System;
31 using System.Collections;
32 using System.IO;
33 using System.Xml;
34
35 /// <summary>Class designed to represent an XML-RPC response.</summary>
36 public class XmlRpcResponse
37 {
38 private Object _value;
39 /// <summary><c>bool</c> indicating if this response represents a fault.</summary>
40 public bool IsFault;
41
42 /// <summary>Basic constructor</summary>
43 public XmlRpcResponse()
44 {
45 Value = null;
46 IsFault = false;
47 }
48
49 /// <summary>Constructor for a fault.</summary>
50 /// <param name="code"><c>int</c> the numeric faultCode value.</param>
51 /// <param name="message"><c>String</c> the faultString value.</param>
52 public XmlRpcResponse(int code, String message)
53 : this()
54 {
55 SetFault(code, message);
56 }
57
58 /// <summary>The data value of the response, may be fault data.</summary>
59 public Object Value
60 {
61 get { return _value; }
62 set
63 {
64 IsFault = false;
65 _value = value;
66 }
67 }
68
69 /// <summary>The faultCode if this is a fault.</summary>
70 public int FaultCode
71 {
72 get
73 {
74 if (!IsFault)
75 return 0;
76 else
77 return (int)((Hashtable)_value)[XmlRpcXmlTokens.FAULT_CODE];
78 }
79 }
80
81 /// <summary>The faultString if this is a fault.</summary>
82 public String FaultString
83 {
84 get
85 {
86 if (!IsFault)
87 return "";
88 else
89 return (String)((Hashtable)_value)[XmlRpcXmlTokens.FAULT_STRING];
90 }
91 }
92
93 /// <summary>Set this response to be a fault.</summary>
94 /// <param name="code"><c>int</c> the numeric faultCode value.</param>
95 /// <param name="message"><c>String</c> the faultString value.</param>
96 public void SetFault(int code, String message)
97 {
98 Hashtable fault = new Hashtable();
99 fault.Add("faultCode", code);
100 fault.Add("faultString", message);
101 Value = fault;
102 IsFault = true;
103 }
104
105 /// <summary>Form a useful string representation of the object, in this case the XML response.</summary>
106 /// <returns><c>String</c> The XML serialized XML-RPC response.</returns>
107 override public String ToString()
108 {
109 return XmlRpcResponseSerializer.Singleton.Serialize(this);
110 }
111 }
112}
diff --git a/Common/XmlRpcCS/XmlRpcResponseDeserializer.cs b/Common/XmlRpcCS/XmlRpcResponseDeserializer.cs
deleted file mode 100644
index 46c5742..0000000
--- a/Common/XmlRpcCS/XmlRpcResponseDeserializer.cs
+++ /dev/null
@@ -1,92 +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*/
28namespace Nwc.XmlRpc
29{
30 using System;
31 using System.Collections;
32 using System.IO;
33 using System.Xml;
34
35 /// <summary>Class to deserialize XML data representing a response.</summary>
36 public class XmlRpcResponseDeserializer : XmlRpcDeserializer
37 {
38 static private XmlRpcResponseDeserializer _singleton;
39 /// <summary>A static singleton instance of this deserializer.</summary>
40 [Obsolete("This object is now thread safe, just use an instance.", false)]
41 static public XmlRpcResponseDeserializer Singleton
42 {
43 get
44 {
45 if (_singleton == null)
46 _singleton = new XmlRpcResponseDeserializer();
47
48 return _singleton;
49 }
50 }
51
52 /// <summary>Static method that parses XML data into a response using the Singleton.</summary>
53 /// <param name="xmlData"><c>StreamReader</c> containing an XML-RPC response.</param>
54 /// <returns><c>XmlRpcResponse</c> object resulting from the parse.</returns>
55 override public Object Deserialize(TextReader xmlData)
56 {
57 XmlTextReader reader = new XmlTextReader(xmlData);
58 XmlRpcResponse response = new XmlRpcResponse();
59 bool done = false;
60
61 lock (this)
62 {
63 Reset();
64
65 while (!done && reader.Read())
66 {
67 DeserializeNode(reader); // Parent parse...
68 switch (reader.NodeType)
69 {
70 case XmlNodeType.EndElement:
71 switch (reader.Name)
72 {
73 case FAULT:
74 response.Value = _value;
75 response.IsFault = true;
76 break;
77 case PARAM:
78 response.Value = _value;
79 _value = null;
80 _text = null;
81 break;
82 }
83 break;
84 default:
85 break;
86 }
87 }
88 }
89 return response;
90 }
91 }
92}
diff --git a/Common/XmlRpcCS/XmlRpcResponseSerializer.cs b/Common/XmlRpcCS/XmlRpcResponseSerializer.cs
deleted file mode 100644
index 5ee4954..0000000
--- a/Common/XmlRpcCS/XmlRpcResponseSerializer.cs
+++ /dev/null
@@ -1,84 +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*/
28namespace Nwc.XmlRpc
29{
30 using System;
31 using System.Collections;
32 using System.Xml;
33
34 /// <summary>Class responsible for serializing an XML-RPC response.</summary>
35 /// <remarks>This class handles the response envelope, depending on XmlRpcSerializer
36 /// to serialize the payload.</remarks>
37 /// <seealso cref="XmlRpcSerializer"/>
38 public class XmlRpcResponseSerializer : XmlRpcSerializer
39 {
40 static private XmlRpcResponseSerializer _singleton;
41 /// <summary>A static singleton instance of this deserializer.</summary>
42 static public XmlRpcResponseSerializer Singleton
43 {
44 get
45 {
46 if (_singleton == null)
47 _singleton = new XmlRpcResponseSerializer();
48
49 return _singleton;
50 }
51 }
52
53 /// <summary>Serialize the <c>XmlRpcResponse</c> to the output stream.</summary>
54 /// <param name="output">An <c>XmlTextWriter</c> stream to write data to.</param>
55 /// <param name="obj">An <c>Object</c> to serialize.</param>
56 /// <seealso cref="XmlRpcResponse"/>
57 override public void Serialize(XmlTextWriter output, Object obj)
58 {
59 XmlRpcResponse response = (XmlRpcResponse)obj;
60
61 output.WriteStartDocument();
62 output.WriteStartElement(METHOD_RESPONSE);
63
64 if (response.IsFault)
65 output.WriteStartElement(FAULT);
66 else
67 {
68 output.WriteStartElement(PARAMS);
69 output.WriteStartElement(PARAM);
70 }
71
72 output.WriteStartElement(VALUE);
73
74 SerializeObject(output, response.Value);
75
76 output.WriteEndElement();
77
78 output.WriteEndElement();
79 if (!response.IsFault)
80 output.WriteEndElement();
81 output.WriteEndElement();
82 }
83 }
84}
diff --git a/Common/XmlRpcCS/XmlRpcSerializer.cs b/Common/XmlRpcCS/XmlRpcSerializer.cs
deleted file mode 100644
index b3b9af3..0000000
--- a/Common/XmlRpcCS/XmlRpcSerializer.cs
+++ /dev/null
@@ -1,143 +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*/
28namespace Nwc.XmlRpc
29{
30 using System;
31 using System.Collections;
32 using System.IO;
33 using System.Xml;
34 using System.Text;
35
36 /// <summary>Base class of classes serializing data to XML-RPC's XML format.</summary>
37 /// <remarks>This class handles the basic type conversions like Integer to &lt;i4&gt;. </remarks>
38 /// <seealso cref="XmlRpcXmlTokens"/>
39 public class XmlRpcSerializer : XmlRpcXmlTokens
40 {
41
42 /// <summary>Serialize the <c>XmlRpcRequest</c> to the output stream.</summary>
43 /// <param name="output">An <c>XmlTextWriter</c> stream to write data to.</param>
44 /// <param name="obj">An <c>Object</c> to serialize.</param>
45 /// <seealso cref="XmlRpcRequest"/>
46 virtual public void Serialize(XmlTextWriter output, Object obj)
47 {
48 }
49
50 /// <summary>Serialize the <c>XmlRpcRequest</c> to a String.</summary>
51 /// <remarks>Note this may represent a real memory hog for a large request.</remarks>
52 /// <param name="obj">An <c>Object</c> to serialize.</param>
53 /// <returns><c>String</c> containing XML-RPC representation of the request.</returns>
54 /// <seealso cref="XmlRpcRequest"/>
55 public String Serialize(Object obj)
56 {
57 using (MemoryStream memStream = new MemoryStream(4096))
58 {
59 XmlTextWriter xml = new XmlTextWriter( memStream, null );
60 xml.Formatting = Formatting.Indented;
61 xml.Indentation = 4;
62 Serialize(xml, obj);
63 xml.Flush();
64
65 byte[] resultBytes = memStream.ToArray();
66
67 UTF8Encoding encoder = new UTF8Encoding();
68 String returns = encoder.GetString( resultBytes, 0, resultBytes.Length );
69 xml.Close();
70 return returns;
71 }
72 }
73
74 /// <remarks>Serialize the object to the output stream.</remarks>
75 /// <param name="output">An <c>XmlTextWriter</c> stream to write data to.</param>
76 /// <param name="obj">An <c>Object</c> to serialize.</param>
77 public void SerializeObject(XmlTextWriter output, Object obj)
78 {
79 if (obj == null)
80 return;
81
82 if (obj is byte[])
83 {
84 byte[] ba = (byte[])obj;
85 output.WriteStartElement(BASE64);
86 output.WriteBase64(ba, 0, ba.Length);
87 output.WriteEndElement();
88 }
89 else if (obj is String)
90 {
91 output.WriteElementString(STRING, obj.ToString());
92 }
93 else if (obj is Int32)
94 {
95 output.WriteElementString(INT, obj.ToString());
96 }
97 else if (obj is DateTime)
98 {
99 output.WriteElementString(DATETIME, ((DateTime)obj).ToString(ISO_DATETIME));
100 }
101 else if (obj is Double)
102 {
103 output.WriteElementString(DOUBLE, obj.ToString());
104 }
105 else if (obj is Boolean)
106 {
107 output.WriteElementString(BOOLEAN, ((((Boolean)obj) == true) ? "1" : "0"));
108 }
109 else if (obj is IList)
110 {
111 output.WriteStartElement(ARRAY);
112 output.WriteStartElement(DATA);
113 if (((ArrayList)obj).Count > 0)
114 {
115 foreach (Object member in ((IList)obj))
116 {
117 output.WriteStartElement(VALUE);
118 SerializeObject(output, member);
119 output.WriteEndElement();
120 }
121 }
122 output.WriteEndElement();
123 output.WriteEndElement();
124 }
125 else if (obj is IDictionary)
126 {
127 IDictionary h = (IDictionary)obj;
128 output.WriteStartElement(STRUCT);
129 foreach (String key in h.Keys)
130 {
131 output.WriteStartElement(MEMBER);
132 output.WriteElementString(NAME, key);
133 output.WriteStartElement(VALUE);
134 SerializeObject(output, h[key]);
135 output.WriteEndElement();
136 output.WriteEndElement();
137 }
138 output.WriteEndElement();
139 }
140
141 }
142 }
143}
diff --git a/Common/XmlRpcCS/XmlRpcServer.cs b/Common/XmlRpcCS/XmlRpcServer.cs
deleted file mode 100644
index 6d1f33a..0000000
--- a/Common/XmlRpcCS/XmlRpcServer.cs
+++ /dev/null
@@ -1,266 +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*/
28namespace Nwc.XmlRpc
29{
30 using System;
31 using System.Collections;
32 using System.IO;
33 using System.Net;
34 using System.Net.Sockets;
35 using System.Text;
36 using System.Threading;
37 using System.Xml;
38
39 /// <summary>A restricted HTTP server for use with XML-RPC.</summary>
40 /// <remarks>It only handles POST requests, and only POSTs representing XML-RPC calls.
41 /// In addition to dispatching requests it also provides a registry for request handlers.
42 /// </remarks>
43 public class XmlRpcServer : IEnumerable
44 {
45#pragma warning disable 0414 // disable "private field assigned but not used"
46 const int RESPONDER_COUNT = 10;
47 private TcpListener _myListener;
48 private int _port;
49 private IPAddress _address;
50 private IDictionary _handlers;
51 private XmlRpcSystemObject _system;
52 private WaitCallback _wc;
53#pragma warning restore 0414
54
55 ///<summary>Constructor with port and address.</summary>
56 ///<remarks>This constructor sets up a TcpListener listening on the
57 ///given port and address. It also calls a Thread on the method StartListen().</remarks>
58 ///<param name="address"><c>IPAddress</c> value of the address to listen on.</param>
59 ///<param name="port"><c>Int</c> value of the port to listen on.</param>
60 public XmlRpcServer(IPAddress address, int port)
61 {
62 _port = port;
63 _address = address;
64 _handlers = new Hashtable();
65 _system = new XmlRpcSystemObject(this);
66 _wc = new WaitCallback(WaitCallback);
67 }
68
69 ///<summary>Basic constructor.</summary>
70 ///<remarks>This constructor sets up a TcpListener listening on the
71 ///given port. It also calls a Thread on the method StartListen(). IPAddress.Any
72 ///is assumed as the address here.</remarks>
73 ///<param name="port"><c>Int</c> value of the port to listen on.</param>
74 public XmlRpcServer(int port) : this(IPAddress.Any, port) { }
75
76 /// <summary>Start the server.</summary>
77 public void Start()
78 {
79 try
80 {
81 Stop();
82 //start listing on the given port
83 // IPAddress addr = IPAddress.Parse("127.0.0.1");
84 lock (this)
85 {
86 _myListener = new TcpListener(IPAddress.Any, _port);
87 _myListener.Start();
88 //start the thread which calls the method 'StartListen'
89 Thread th = new Thread(new ThreadStart(StartListen));
90 th.Start();
91 }
92 }
93 catch (Exception e)
94 {
95 Logger.WriteEntry("An Exception Occurred while Listening :" + e.ToString(), LogLevel.Error);
96 }
97 }
98
99 /// <summary>Stop the server.</summary>
100 public void Stop()
101 {
102 try
103 {
104 if (_myListener != null)
105 {
106 lock (this)
107 {
108 _myListener.Stop();
109 _myListener = null;
110 }
111 }
112 }
113 catch (Exception e)
114 {
115 Logger.WriteEntry("An Exception Occurred while stopping :" +
116 e.ToString(), LogLevel.Error);
117 }
118 }
119
120 /// <summary>Get an enumeration of my XML-RPC handlers.</summary>
121 /// <returns><c>IEnumerable</c> the handler enumeration.</returns>
122 public IEnumerator GetEnumerator()
123 {
124 return _handlers.GetEnumerator();
125 }
126
127 /// <summary>Retrieve a handler by name.</summary>
128 /// <param name="name"><c>String</c> naming a handler</param>
129 /// <returns><c>Object</c> that is the handler.</returns>
130 public Object this[String name]
131 {
132 get { return _handlers[name]; }
133 }
134
135 ///<summary>
136 ///This method Accepts new connections and dispatches them when appropriate.
137 ///</summary>
138 public void StartListen()
139 {
140 while (true && _myListener != null)
141 {
142 //Accept a new connection
143 XmlRpcResponder responder = new XmlRpcResponder(this, _myListener.AcceptTcpClient());
144 ThreadPool.QueueUserWorkItem(_wc, responder);
145 }
146 }
147
148
149 ///<summary>
150 ///Add an XML-RPC handler object by name.
151 ///</summary>
152 ///<param name="name"><c>String</c> XML-RPC dispatch name of this object.</param>
153 ///<param name="obj"><c>Object</c> The object that is the XML-RPC handler.</param>
154 public void Add(String name, Object obj)
155 {
156 _handlers.Add(name, obj);
157 }
158
159 ///<summary>Return a C# object.method name for and XML-RPC object.method name pair.</summary>
160 ///<param name="methodName">The XML-RPC object.method.</param>
161 ///<returns><c>String</c> of form object.method for the underlying C# method.</returns>
162 public String MethodName(String methodName)
163 {
164 int dotAt = methodName.LastIndexOf('.');
165
166 if (dotAt == -1)
167 {
168 throw new XmlRpcException(XmlRpcErrorCodes.SERVER_ERROR_METHOD,
169 XmlRpcErrorCodes.SERVER_ERROR_METHOD_MSG + ": Bad method name " + methodName);
170 }
171
172 String objectName = methodName.Substring(0, dotAt);
173 Object target = _handlers[objectName];
174
175 if (target == null)
176 {
177 throw new XmlRpcException(XmlRpcErrorCodes.SERVER_ERROR_METHOD,
178 XmlRpcErrorCodes.SERVER_ERROR_METHOD_MSG + ": Object " + objectName + " not found");
179 }
180
181 return target.GetType().FullName + "." + methodName.Substring(dotAt + 1);
182 }
183
184 ///<summary>Invoke a method described in a request.</summary>
185 ///<param name="req"><c>XmlRpcRequest</c> containing a method descriptions.</param>
186 /// <seealso cref="XmlRpcSystemObject.Invoke"/>
187 /// <seealso cref="XmlRpcServer.Invoke(String,String,IList)"/>
188 public Object Invoke(XmlRpcRequest req)
189 {
190 return Invoke(req.MethodNameObject, req.MethodNameMethod, req.Params);
191 }
192
193 ///<summary>Invoke a method on a named handler.</summary>
194 ///<param name="objectName"><c>String</c> The name of the handler.</param>
195 ///<param name="methodName"><c>String</c> The name of the method to invoke on the handler.</param>
196 ///<param name="parameters"><c>IList</c> The parameters to invoke the method with.</param>
197 /// <seealso cref="XmlRpcSystemObject.Invoke"/>
198 public Object Invoke(String objectName, String methodName, IList parameters)
199 {
200 Object target = _handlers[objectName];
201
202 if (target == null)
203 {
204 throw new XmlRpcException(XmlRpcErrorCodes.SERVER_ERROR_METHOD,
205 XmlRpcErrorCodes.SERVER_ERROR_METHOD_MSG + ": Object " + objectName + " not found");
206 }
207
208 return XmlRpcSystemObject.Invoke(target, methodName, parameters);
209 }
210
211 /// <summary>The method the thread pool invokes when a thread is available to handle an HTTP request.</summary>
212 /// <param name="responder">TcpClient from the socket accept.</param>
213 public void WaitCallback(object responder)
214 {
215 XmlRpcResponder resp = (XmlRpcResponder)responder;
216
217 if (resp.HttpReq.HttpMethod == "POST")
218 {
219 try
220 {
221 resp.Respond();
222 }
223 catch (Exception e)
224 {
225 Logger.WriteEntry("Failed on post: " + e, LogLevel.Error);
226 }
227 }
228 else
229 {
230 Logger.WriteEntry("Only POST methods are supported: " + resp.HttpReq.HttpMethod +
231 " ignored", LogLevel.Error);
232 }
233
234 resp.Close();
235 }
236
237 /// <summary>
238 /// This function send the Header Information to the client (Browser)
239 /// </summary>
240 /// <param name="sHttpVersion">HTTP Version</param>
241 /// <param name="sMIMEHeader">Mime Type</param>
242 /// <param name="iTotBytes">Total Bytes to be sent in the body</param>
243 /// <param name="sStatusCode"></param>
244 /// <param name="output">Socket reference</param>
245 static public void HttpHeader(string sHttpVersion, string sMIMEHeader, long iTotBytes, string sStatusCode, TextWriter output)
246 {
247 String sBuffer = "";
248
249 // if Mime type is not provided set default to text/html
250 if (sMIMEHeader.Length == 0)
251 {
252 sMIMEHeader = "text/html"; // Default Mime Type is text/html
253 }
254
255 sBuffer += sHttpVersion + sStatusCode + "\r\n";
256 sBuffer += "Connection: close\r\n";
257 if (iTotBytes > 0)
258 sBuffer += "Content-Length: " + iTotBytes + "\r\n";
259 sBuffer += "Server: XmlRpcServer \r\n";
260 sBuffer += "Content-Type: " + sMIMEHeader + "\r\n";
261 sBuffer += "\r\n";
262
263 output.Write(sBuffer);
264 }
265 }
266}
diff --git a/Common/XmlRpcCS/XmlRpcSystemObject.cs b/Common/XmlRpcCS/XmlRpcSystemObject.cs
deleted file mode 100644
index 4055d29..0000000
--- a/Common/XmlRpcCS/XmlRpcSystemObject.cs
+++ /dev/null
@@ -1,279 +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*/
28namespace Nwc.XmlRpc
29{
30 using System;
31 using System.Collections;
32 using System.Reflection;
33
34 /// <summary> XML-RPC System object implementation of extended specifications.</summary>
35 [XmlRpcExposed]
36 public class XmlRpcSystemObject
37 {
38 private XmlRpcServer _server;
39 static private IDictionary _methodHelp = new Hashtable();
40
41 /// <summary>Static <c>IDictionary</c> to hold mappings of method name to associated documentation String</summary>
42 static public IDictionary MethodHelp
43 {
44 get { return _methodHelp; }
45 }
46
47 /// <summary>Constructor.</summary>
48 /// <param name="server"><c>XmlRpcServer</c> server to be the system object for.</param>
49 public XmlRpcSystemObject(XmlRpcServer server)
50 {
51 _server = server;
52 server.Add("system", this);
53 _methodHelp.Add(this.GetType().FullName + ".methodHelp", "Return a string description.");
54 }
55
56 /// <summary>Invoke a method on a given object.</summary>
57 /// <remarks>Using reflection, and respecting the <c>XmlRpcExposed</c> attribute,
58 /// invoke the <paramref>methodName</paramref> method on the <paramref>target</paramref>
59 /// instance with the <paramref>parameters</paramref> provided. All this packages other <c>Invoke</c> methods
60 /// end up calling this.</remarks>
61 /// <returns><c>Object</c> the value the invoked method returns.</returns>
62 /// <exception cref="XmlRpcException">If method does not exist, is not exposed, parameters invalid, or invocation
63 /// results in an exception. Note, the <c>XmlRpcException.Code</c> will indicate cause.</exception>
64 static public Object Invoke(Object target, String methodName, IList parameters)
65 {
66 if (target == null)
67 throw new XmlRpcException(XmlRpcErrorCodes.SERVER_ERROR_METHOD,
68 XmlRpcErrorCodes.SERVER_ERROR_METHOD_MSG + ": Invalid target object.");
69
70 Type type = target.GetType();
71 MethodInfo method = type.GetMethod(methodName);
72
73 try
74 {
75 if (!XmlRpcExposedAttribute.ExposedMethod(target, methodName))
76 throw new XmlRpcException(XmlRpcErrorCodes.SERVER_ERROR_METHOD,
77 XmlRpcErrorCodes.SERVER_ERROR_METHOD_MSG + ": Method " + methodName + " is not exposed.");
78 }
79 catch (MissingMethodException me)
80 {
81 throw new XmlRpcException(XmlRpcErrorCodes.SERVER_ERROR_METHOD,
82 XmlRpcErrorCodes.SERVER_ERROR_METHOD_MSG + ": " + me.Message);
83 }
84
85 Object[] args = new Object[parameters.Count];
86
87 int index = 0;
88 foreach (Object arg in parameters)
89 {
90 args[index] = arg;
91 index++;
92 }
93
94 try
95 {
96 Object retValue = method.Invoke(target, args);
97 if (retValue == null)
98 throw new XmlRpcException(XmlRpcErrorCodes.APPLICATION_ERROR,
99 XmlRpcErrorCodes.APPLICATION_ERROR_MSG + ": Method returned NULL.");
100 return retValue;
101 }
102 catch (XmlRpcException e)
103 {
104 throw e;
105 }
106 catch (ArgumentException ae)
107 {
108 Logger.WriteEntry(XmlRpcErrorCodes.SERVER_ERROR_PARAMS_MSG + ": " + ae.Message,
109 LogLevel.Information);
110 String call = methodName + "( ";
111 foreach (Object o in args)
112 {
113 call += o.GetType().Name;
114 call += " ";
115 }
116 call += ")";
117 throw new XmlRpcException(XmlRpcErrorCodes.SERVER_ERROR_PARAMS,
118 XmlRpcErrorCodes.SERVER_ERROR_PARAMS_MSG + ": Arguement type mismatch invoking " + call);
119 }
120 catch (TargetParameterCountException tpce)
121 {
122 Logger.WriteEntry(XmlRpcErrorCodes.SERVER_ERROR_PARAMS_MSG + ": " + tpce.Message,
123 LogLevel.Information);
124 throw new XmlRpcException(XmlRpcErrorCodes.SERVER_ERROR_PARAMS,
125 XmlRpcErrorCodes.SERVER_ERROR_PARAMS_MSG + ": Arguement count mismatch invoking " + methodName);
126 }
127 catch (TargetInvocationException tie)
128 {
129 throw new XmlRpcException(XmlRpcErrorCodes.APPLICATION_ERROR,
130 XmlRpcErrorCodes.APPLICATION_ERROR_MSG + " Invoked method " + methodName + ": " + tie.Message);
131 }
132 }
133
134 /// <summary>List methods available on all handlers of this server.</summary>
135 /// <returns><c>IList</c> An array of <c>Strings</c>, each <c>String</c> will have form "object.method".</returns>
136 [XmlRpcExposed]
137 public IList listMethods()
138 {
139 IList methods = new ArrayList();
140 Boolean considerExposure;
141
142 foreach (DictionaryEntry handlerEntry in _server)
143 {
144 considerExposure = XmlRpcExposedAttribute.IsExposed(handlerEntry.Value.GetType());
145
146 foreach (MemberInfo mi in handlerEntry.Value.GetType().GetMembers())
147 {
148 if (mi.MemberType != MemberTypes.Method)
149 continue;
150
151 if (!((MethodInfo)mi).IsPublic)
152 continue;
153
154 if (considerExposure && !XmlRpcExposedAttribute.IsExposed(mi))
155 continue;
156
157 methods.Add(handlerEntry.Key + "." + mi.Name);
158 }
159 }
160
161 return methods;
162 }
163
164 /// <summary>Given a method name return the possible signatures for it.</summary>
165 /// <param name="name"><c>String</c> The object.method name to look up.</param>
166 /// <returns><c>IList</c> Of arrays of signatures.</returns>
167 [XmlRpcExposed]
168 public IList methodSignature(String name)
169 {
170 IList signatures = new ArrayList();
171 int index = name.IndexOf('.');
172
173 if (index < 0)
174 return signatures;
175
176 String oName = name.Substring(0, index);
177 Object obj = _server[oName];
178
179 if (obj == null)
180 return signatures;
181
182 MemberInfo[] mi = obj.GetType().GetMember(name.Substring(index + 1));
183
184 if (mi == null || mi.Length != 1) // for now we want a single signature
185 return signatures;
186
187 MethodInfo method;
188
189 try
190 {
191 method = (MethodInfo)mi[0];
192 }
193 catch (Exception e)
194 {
195 Logger.WriteEntry("Attempted methodSignature call on " + mi[0] + " caused: " + e,
196 LogLevel.Information);
197 return signatures;
198 }
199
200 if (!method.IsPublic)
201 return signatures;
202
203 IList signature = new ArrayList();
204 signature.Add(method.ReturnType.Name);
205
206 foreach (ParameterInfo param in method.GetParameters())
207 {
208 signature.Add(param.ParameterType.Name);
209 }
210
211
212 signatures.Add(signature);
213
214 return signatures;
215 }
216
217 /// <summary>Help for given method signature. Not implemented yet.</summary>
218 /// <param name="name"><c>String</c> The object.method name to look up.</param>
219 /// <returns><c>String</c> help text. Rich HTML text.</returns>
220 [XmlRpcExposed]
221 public String methodHelp(String name)
222 {
223 String help = null;
224
225 try
226 {
227 help = (String)_methodHelp[_server.MethodName(name)];
228 }
229 catch (XmlRpcException e)
230 {
231 throw e;
232 }
233 catch (Exception) { /* ignored */ };
234
235 if (help == null)
236 help = "No help available for: " + name;
237
238 return help;
239 }
240
241 /// <summary>Boxcarring support method.</summary>
242 /// <param name="calls"><c>IList</c> of calls</param>
243 /// <returns><c>ArrayList</c> of results/faults.</returns>
244 [XmlRpcExposed]
245 public IList multiCall(IList calls)
246 {
247 IList responses = new ArrayList();
248 XmlRpcResponse fault = new XmlRpcResponse();
249
250 foreach (IDictionary call in calls)
251 {
252 try
253 {
254 XmlRpcRequest req = new XmlRpcRequest((String)call[XmlRpcXmlTokens.METHOD_NAME],
255 (ArrayList)call[XmlRpcXmlTokens.PARAMS]);
256 Object results = _server.Invoke(req);
257 IList response = new ArrayList();
258 response.Add(results);
259 responses.Add(response);
260 }
261 catch (XmlRpcException e)
262 {
263 fault.SetFault(e.FaultCode, e.FaultString);
264 responses.Add(fault.Value);
265 }
266 catch (Exception e2)
267 {
268 fault.SetFault(XmlRpcErrorCodes.APPLICATION_ERROR,
269 XmlRpcErrorCodes.APPLICATION_ERROR_MSG + ": " + e2.Message);
270 responses.Add(fault.Value);
271 }
272 }
273
274 return responses;
275 }
276
277 }
278}
279
diff --git a/Common/XmlRpcCS/XmlRpcXmlTokens.cs b/Common/XmlRpcCS/XmlRpcXmlTokens.cs
deleted file mode 100644
index 27447bb..0000000
--- a/Common/XmlRpcCS/XmlRpcXmlTokens.cs
+++ /dev/null
@@ -1,103 +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*/
28namespace Nwc.XmlRpc
29{
30 using System;
31
32 /// <summary>Class collecting <c>String</c> tokens that are part of XML-RPC files.</summary>
33 public class XmlRpcXmlTokens
34 {
35 /// <summary>C# formatting string to describe an ISO 8601 date.</summary>
36 public const String ISO_DATETIME = "yyyyMMdd\\THH\\:mm\\:ss";
37 /// <summary>Base64 field indicator.</summary>
38 /// <remarks>Corresponds to the &lt;base64&gt; tag.</remarks>
39 public const String BASE64 = "base64";
40 /// <summary>String field indicator.</summary>
41 /// <remarks>Corresponds to the &lt;string&gt; tag.</remarks>
42 public const String STRING = "string";
43 /// <summary>Integer field integer.</summary>
44 /// <remarks>Corresponds to the &lt;i4&gt; tag.</remarks>
45 public const String INT = "i4";
46 /// <summary>Alternate integer field indicator.</summary>
47 /// <remarks>Corresponds to the &lt;int&gt; tag.</remarks>
48 public const String ALT_INT = "int";
49 /// <summary>Date field indicator.</summary>
50 /// <remarks>Corresponds to the &lt;dateTime.iso8601&gt; tag.</remarks>
51 public const String DATETIME = "dateTime.iso8601";
52 /// <summary>Boolean field indicator.</summary>
53 /// <remarks>Corresponds to the &lt;boolean&gt; tag.</remarks>
54 public const String BOOLEAN = "boolean";
55 /// <summary>Value token.</summary>
56 /// <remarks>Corresponds to the &lt;value&gt; tag.</remarks>
57 public const String VALUE = "value";
58 /// <summary>Name token.</summary>
59 /// <remarks>Corresponds to the &lt;name&gt; tag.</remarks>
60 public const String NAME = "name";
61 /// <summary>Array field indicator..</summary>
62 /// <remarks>Corresponds to the &lt;array&gt; tag.</remarks>
63 public const String ARRAY = "array";
64 /// <summary>Data token.</summary>
65 /// <remarks>Corresponds to the &lt;data&gt; tag.</remarks>
66 public const String DATA = "data";
67 /// <summary>Member token.</summary>
68 /// <remarks>Corresponds to the &lt;member&gt; tag.</remarks>
69 public const String MEMBER = "member";
70 /// <summary>Stuct field indicator.</summary>
71 /// <remarks>Corresponds to the &lt;struct&gt; tag.</remarks>
72 public const String STRUCT = "struct";
73 /// <summary>Double field indicator.</summary>
74 /// <remarks>Corresponds to the &lt;double&gt; tag.</remarks>
75 public const String DOUBLE = "double";
76 /// <summary>Param token.</summary>
77 /// <remarks>Corresponds to the &lt;param&gt; tag.</remarks>
78 public const String PARAM = "param";
79 /// <summary>Params token.</summary>
80 /// <remarks>Corresponds to the &lt;params&gt; tag.</remarks>
81 public const String PARAMS = "params";
82 /// <summary>MethodCall token.</summary>
83 /// <remarks>Corresponds to the &lt;methodCall&gt; tag.</remarks>
84 public const String METHOD_CALL = "methodCall";
85 /// <summary>MethodName token.</summary>
86 /// <remarks>Corresponds to the &lt;methodName&gt; tag.</remarks>
87 public const String METHOD_NAME = "methodName";
88 /// <summary>MethodResponse token</summary>
89 /// <remarks>Corresponds to the &lt;methodResponse&gt; tag.</remarks>
90 public const String METHOD_RESPONSE = "methodResponse";
91 /// <summary>Fault response token.</summary>
92 /// <remarks>Corresponds to the &lt;fault&gt; tag.</remarks>
93 public const String FAULT = "fault";
94 /// <summary>FaultCode token.</summary>
95 /// <remarks>Corresponds to the &lt;faultCode&gt; tag.</remarks>
96 public const String FAULT_CODE = "faultCode";
97 /// <summary>FaultString token.</summary>
98 /// <remarks>Corresponds to the &lt;faultString&gt; tag.</remarks>
99 public const String FAULT_STRING = "faultString";
100 }
101}
102
103