diff options
Switched in NameSpaceChanges
Diffstat (limited to 'OpenSim/Framework/Servers')
-rw-r--r-- | OpenSim/Framework/Servers/BaseHttpServer.cs | 311 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/CheckSumServer.cs | 141 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/IRestHandler.cs | 35 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/OpenSim.Framework.Servers.csproj | 116 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/OpenSim.Framework.Servers.dll.build | 48 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/UDPServerBase.cs | 95 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/XmlRpcMethod.cs | 34 |
7 files changed, 780 insertions, 0 deletions
diff --git a/OpenSim/Framework/Servers/BaseHttpServer.cs b/OpenSim/Framework/Servers/BaseHttpServer.cs new file mode 100644 index 0000000..8c8204a --- /dev/null +++ b/OpenSim/Framework/Servers/BaseHttpServer.cs | |||
@@ -0,0 +1,311 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Net; | ||
31 | using System.Text; | ||
32 | using System.Text.RegularExpressions; | ||
33 | using System.Threading; | ||
34 | using Nwc.XmlRpc; | ||
35 | using System.Collections; | ||
36 | using OpenSim.Framework.Console; | ||
37 | |||
38 | namespace OpenSim.Framework.Servers | ||
39 | { | ||
40 | public class BaseHttpServer | ||
41 | { | ||
42 | protected class RestMethodEntry | ||
43 | { | ||
44 | private string m_path; | ||
45 | public string Path | ||
46 | { | ||
47 | get { return m_path; } | ||
48 | } | ||
49 | |||
50 | private RestMethod m_restMethod; | ||
51 | public RestMethod RestMethod | ||
52 | { | ||
53 | get { return m_restMethod; } | ||
54 | } | ||
55 | |||
56 | public RestMethodEntry(string path, RestMethod restMethod) | ||
57 | { | ||
58 | m_path = path; | ||
59 | m_restMethod = restMethod; | ||
60 | } | ||
61 | } | ||
62 | |||
63 | protected Thread m_workerThread; | ||
64 | protected HttpListener m_httpListener; | ||
65 | protected Dictionary<string, RestMethodEntry> m_restHandlers = new Dictionary<string, RestMethodEntry>(); | ||
66 | protected Dictionary<string, XmlRpcMethod> m_rpcHandlers = new Dictionary<string, XmlRpcMethod>(); | ||
67 | protected int m_port; | ||
68 | protected bool firstcaps = true; | ||
69 | |||
70 | public BaseHttpServer(int port) | ||
71 | { | ||
72 | m_port = port; | ||
73 | } | ||
74 | |||
75 | public bool AddRestHandler(string method, string path, RestMethod handler) | ||
76 | { | ||
77 | //Console.WriteLine("adding new REST handler for path " + path); | ||
78 | string methodKey = String.Format("{0}: {1}", method, path); | ||
79 | |||
80 | if (!this.m_restHandlers.ContainsKey(methodKey)) | ||
81 | { | ||
82 | this.m_restHandlers.Add(methodKey, new RestMethodEntry(path, handler)); | ||
83 | return true; | ||
84 | } | ||
85 | |||
86 | //must already have a handler for that path so return false | ||
87 | return false; | ||
88 | } | ||
89 | |||
90 | public bool RemoveRestHandler(string method, string path) | ||
91 | { | ||
92 | string methodKey = String.Format("{0}: {1}", method, path); | ||
93 | if (this.m_restHandlers.ContainsKey(methodKey)) | ||
94 | { | ||
95 | this.m_restHandlers.Remove(methodKey); | ||
96 | return true; | ||
97 | } | ||
98 | return false; | ||
99 | } | ||
100 | |||
101 | public bool AddXmlRPCHandler(string method, XmlRpcMethod handler) | ||
102 | { | ||
103 | if (!this.m_rpcHandlers.ContainsKey(method)) | ||
104 | { | ||
105 | this.m_rpcHandlers.Add(method, handler); | ||
106 | return true; | ||
107 | } | ||
108 | |||
109 | //must already have a handler for that path so return false | ||
110 | return false; | ||
111 | } | ||
112 | |||
113 | protected virtual string ProcessXMLRPCMethod(string methodName, XmlRpcRequest request) | ||
114 | { | ||
115 | XmlRpcResponse response; | ||
116 | |||
117 | XmlRpcMethod method; | ||
118 | if (this.m_rpcHandlers.TryGetValue(methodName, out method)) | ||
119 | { | ||
120 | response = method(request); | ||
121 | } | ||
122 | else | ||
123 | { | ||
124 | response = new XmlRpcResponse(); | ||
125 | Hashtable unknownMethodError = new Hashtable(); | ||
126 | unknownMethodError["reason"] = "XmlRequest"; ; | ||
127 | unknownMethodError["message"] = "Unknown Rpc request"; | ||
128 | unknownMethodError["login"] = "false"; | ||
129 | response.Value = unknownMethodError; | ||
130 | } | ||
131 | |||
132 | return XmlRpcResponseSerializer.Singleton.Serialize(response); | ||
133 | } | ||
134 | |||
135 | protected virtual string ParseREST(string request, string path, string method) | ||
136 | { | ||
137 | string response; | ||
138 | |||
139 | string requestKey = String.Format("{0}: {1}", method, path); | ||
140 | |||
141 | string bestMatch = String.Empty; | ||
142 | foreach (string currentKey in m_restHandlers.Keys) | ||
143 | { | ||
144 | if (requestKey.StartsWith(currentKey)) | ||
145 | { | ||
146 | if (currentKey.Length > bestMatch.Length) | ||
147 | { | ||
148 | bestMatch = currentKey; | ||
149 | } | ||
150 | } | ||
151 | } | ||
152 | |||
153 | RestMethodEntry restMethodEntry; | ||
154 | if (m_restHandlers.TryGetValue(bestMatch, out restMethodEntry)) | ||
155 | { | ||
156 | RestMethod restMethod = restMethodEntry.RestMethod; | ||
157 | |||
158 | string param = path.Substring(restMethodEntry.Path.Length); | ||
159 | response = restMethod(request, path, param); | ||
160 | |||
161 | } | ||
162 | else | ||
163 | { | ||
164 | response = String.Empty; | ||
165 | } | ||
166 | |||
167 | return response; | ||
168 | } | ||
169 | |||
170 | protected virtual string ParseLLSDXML(string requestBody) | ||
171 | { | ||
172 | // dummy function for now - IMPLEMENT ME! | ||
173 | //Console.WriteLine("LLSD request "+requestBody); | ||
174 | string resp = ""; | ||
175 | if (firstcaps) | ||
176 | { | ||
177 | resp = "<llsd><map><key>MapLayer</key><string>http://127.0.0.1:9000/CAPS/</string></map></llsd>"; | ||
178 | firstcaps = false; | ||
179 | } | ||
180 | return resp; | ||
181 | } | ||
182 | |||
183 | protected virtual string ParseXMLRPC(string requestBody) | ||
184 | { | ||
185 | string responseString = String.Empty; | ||
186 | |||
187 | try | ||
188 | { | ||
189 | XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody); | ||
190 | |||
191 | string methodName = request.MethodName; | ||
192 | |||
193 | responseString = ProcessXMLRPCMethod(methodName, request); | ||
194 | } | ||
195 | catch (Exception e) | ||
196 | { | ||
197 | //Console.WriteLine(e.ToString()); | ||
198 | } | ||
199 | return responseString; | ||
200 | } | ||
201 | |||
202 | public virtual void HandleRequest(Object stateinfo) | ||
203 | { | ||
204 | try | ||
205 | { | ||
206 | HttpListenerContext context = (HttpListenerContext)stateinfo; | ||
207 | |||
208 | HttpListenerRequest request = context.Request; | ||
209 | HttpListenerResponse response = context.Response; | ||
210 | |||
211 | response.KeepAlive = false; | ||
212 | response.SendChunked = false; | ||
213 | |||
214 | System.IO.Stream body = request.InputStream; | ||
215 | System.Text.Encoding encoding = System.Text.Encoding.UTF8; | ||
216 | System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding); | ||
217 | |||
218 | string requestBody = reader.ReadToEnd(); | ||
219 | body.Close(); | ||
220 | reader.Close(); | ||
221 | |||
222 | //Console.WriteLine(request.HttpMethod + " " + request.RawUrl + " Http/" + request.ProtocolVersion.ToString() + " content type: " + request.ContentType); | ||
223 | //Console.WriteLine(requestBody); | ||
224 | |||
225 | string responseString = ""; | ||
226 | // Console.WriteLine("new request " + request.ContentType +" at "+ request.RawUrl); | ||
227 | switch (request.ContentType) | ||
228 | { | ||
229 | case "text/xml": | ||
230 | // must be XML-RPC, so pass to the XML-RPC parser | ||
231 | |||
232 | responseString = ParseXMLRPC(requestBody); | ||
233 | responseString = Regex.Replace(responseString, "utf-16", "utf-8"); | ||
234 | |||
235 | response.AddHeader("Content-type", "text/xml"); | ||
236 | break; | ||
237 | |||
238 | case "application/xml": | ||
239 | // probably LLSD we hope, otherwise it should be ignored by the parser | ||
240 | // responseString = ParseLLSDXML(requestBody); | ||
241 | responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod); | ||
242 | response.AddHeader("Content-type", "application/xml"); | ||
243 | break; | ||
244 | |||
245 | case "application/octet-stream": | ||
246 | // probably LLSD we hope, otherwise it should be ignored by the parser | ||
247 | // responseString = ParseLLSDXML(requestBody); | ||
248 | responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod); | ||
249 | response.AddHeader("Content-type", "application/xml"); | ||
250 | break; | ||
251 | |||
252 | case "application/x-www-form-urlencoded": | ||
253 | // a form data POST so send to the REST parser | ||
254 | responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod); | ||
255 | response.AddHeader("Content-type", "text/html"); | ||
256 | break; | ||
257 | |||
258 | case null: | ||
259 | // must be REST or invalid crap, so pass to the REST parser | ||
260 | responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod); | ||
261 | response.AddHeader("Content-type", "text/html"); | ||
262 | break; | ||
263 | |||
264 | } | ||
265 | |||
266 | byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString); | ||
267 | System.IO.Stream output = response.OutputStream; | ||
268 | response.SendChunked = false; | ||
269 | response.ContentLength64 = buffer.Length; | ||
270 | output.Write(buffer, 0, buffer.Length); | ||
271 | output.Close(); | ||
272 | } | ||
273 | catch (Exception e) | ||
274 | { | ||
275 | //Console.WriteLine(e.ToString()); | ||
276 | } | ||
277 | } | ||
278 | |||
279 | public void Start() | ||
280 | { | ||
281 | OpenSim.Framework.Console.MainLog.Instance.WriteLine(LogPriority.LOW, "BaseHttpServer.cs: Starting up HTTP Server"); | ||
282 | |||
283 | m_workerThread = new Thread(new ThreadStart(StartHTTP)); | ||
284 | m_workerThread.IsBackground = true; | ||
285 | m_workerThread.Start(); | ||
286 | } | ||
287 | |||
288 | private void StartHTTP() | ||
289 | { | ||
290 | try | ||
291 | { | ||
292 | OpenSim.Framework.Console.MainLog.Instance.WriteLine(LogPriority.LOW, "BaseHttpServer.cs: StartHTTP() - Spawned main thread OK"); | ||
293 | m_httpListener = new HttpListener(); | ||
294 | |||
295 | m_httpListener.Prefixes.Add("http://+:" + m_port + "/"); | ||
296 | m_httpListener.Start(); | ||
297 | |||
298 | HttpListenerContext context; | ||
299 | while (true) | ||
300 | { | ||
301 | context = m_httpListener.GetContext(); | ||
302 | ThreadPool.QueueUserWorkItem(new WaitCallback(HandleRequest), context); | ||
303 | } | ||
304 | } | ||
305 | catch (Exception e) | ||
306 | { | ||
307 | OpenSim.Framework.Console.MainLog.Instance.WriteLine(LogPriority.MEDIUM, e.Message); | ||
308 | } | ||
309 | } | ||
310 | } | ||
311 | } | ||
diff --git a/OpenSim/Framework/Servers/CheckSumServer.cs b/OpenSim/Framework/Servers/CheckSumServer.cs new file mode 100644 index 0000000..6aeb58c --- /dev/null +++ b/OpenSim/Framework/Servers/CheckSumServer.cs | |||
@@ -0,0 +1,141 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using System.Text; | ||
30 | using System.IO; | ||
31 | using System.Threading; | ||
32 | using System.Net; | ||
33 | using System.Net.Sockets; | ||
34 | using System.Timers; | ||
35 | using System.Reflection; | ||
36 | using System.Collections; | ||
37 | using System.Collections.Generic; | ||
38 | using libsecondlife; | ||
39 | using libsecondlife.Packets; | ||
40 | using OpenSim.Framework.Console; | ||
41 | |||
42 | |||
43 | namespace OpenSim.Framework.Servers | ||
44 | { | ||
45 | /* public class CheckSumServer : UDPServerBase | ||
46 | { | ||
47 | //protected ConsoleBase m_log; | ||
48 | |||
49 | public CheckSumServer(int port) | ||
50 | : base(port) | ||
51 | { | ||
52 | } | ||
53 | |||
54 | protected override void OnReceivedData(IAsyncResult result) | ||
55 | { | ||
56 | ipeSender = new IPEndPoint(IPAddress.Any, 0); | ||
57 | epSender = (EndPoint)ipeSender; | ||
58 | Packet packet = null; | ||
59 | int numBytes = Server.EndReceiveFrom(result, ref epSender); | ||
60 | int packetEnd = numBytes - 1; | ||
61 | |||
62 | packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer); | ||
63 | |||
64 | if (packet.Type == PacketType.SecuredTemplateChecksumRequest) | ||
65 | { | ||
66 | SecuredTemplateChecksumRequestPacket checksum = (SecuredTemplateChecksumRequestPacket)packet; | ||
67 | TemplateChecksumReplyPacket checkreply = new TemplateChecksumReplyPacket(); | ||
68 | checkreply.DataBlock.Checksum = 3220703154;//180572585; | ||
69 | checkreply.DataBlock.Flags = 0; | ||
70 | checkreply.DataBlock.MajorVersion = 1; | ||
71 | checkreply.DataBlock.MinorVersion = 15; | ||
72 | checkreply.DataBlock.PatchVersion = 0; | ||
73 | checkreply.DataBlock.ServerVersion = 0; | ||
74 | checkreply.TokenBlock.Token = checksum.TokenBlock.Token; | ||
75 | this.SendPacket(checkreply, epSender); | ||
76 | |||
77 | /* | ||
78 | //if we wanted to echo the the checksum/ version from the client (so that any client worked) | ||
79 | SecuredTemplateChecksumRequestPacket checkrequest = new SecuredTemplateChecksumRequestPacket(); | ||
80 | checkrequest.TokenBlock.Token = checksum.TokenBlock.Token; | ||
81 | this.SendPacket(checkrequest, epSender); | ||
82 | |||
83 | } | ||
84 | else if (packet.Type == PacketType.TemplateChecksumReply) | ||
85 | { | ||
86 | //echo back the client checksum reply (Hegemon's method) | ||
87 | TemplateChecksumReplyPacket checksum2 = (TemplateChecksumReplyPacket)packet; | ||
88 | TemplateChecksumReplyPacket checkreply2 = new TemplateChecksumReplyPacket(); | ||
89 | checkreply2.DataBlock.Checksum = checksum2.DataBlock.Checksum; | ||
90 | checkreply2.DataBlock.Flags = checksum2.DataBlock.Flags; | ||
91 | checkreply2.DataBlock.MajorVersion = checksum2.DataBlock.MajorVersion; | ||
92 | checkreply2.DataBlock.MinorVersion = checksum2.DataBlock.MinorVersion; | ||
93 | checkreply2.DataBlock.PatchVersion = checksum2.DataBlock.PatchVersion; | ||
94 | checkreply2.DataBlock.ServerVersion = checksum2.DataBlock.ServerVersion; | ||
95 | checkreply2.TokenBlock.Token = checksum2.TokenBlock.Token; | ||
96 | this.SendPacket(checkreply2, epSender); | ||
97 | } | ||
98 | else | ||
99 | { | ||
100 | } | ||
101 | |||
102 | Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); | ||
103 | } | ||
104 | |||
105 | private void SendPacket(Packet Pack, EndPoint endp) | ||
106 | { | ||
107 | if (!Pack.Header.Resent) | ||
108 | { | ||
109 | Pack.Header.Sequence = 1; | ||
110 | } | ||
111 | |||
112 | byte[] ZeroOutBuffer = new byte[4096]; | ||
113 | byte[] sendbuffer; | ||
114 | sendbuffer = Pack.ToBytes(); | ||
115 | |||
116 | try | ||
117 | { | ||
118 | if (Pack.Header.Zerocoded) | ||
119 | { | ||
120 | int packetsize = Helpers.ZeroEncode(sendbuffer, sendbuffer.Length, ZeroOutBuffer); | ||
121 | this.SendPackTo(ZeroOutBuffer, packetsize, SocketFlags.None, endp); | ||
122 | } | ||
123 | else | ||
124 | { | ||
125 | this.SendPackTo(sendbuffer, sendbuffer.Length, SocketFlags.None, endp); | ||
126 | } | ||
127 | } | ||
128 | catch (Exception) | ||
129 | { | ||
130 | OpenSim.Framework.Console.MainLog.Instance.Warn("OpenSimClient.cs:ProcessOutPacket() - WARNING: Socket exception occurred on connection "); | ||
131 | |||
132 | } | ||
133 | } | ||
134 | |||
135 | private void SendPackTo(byte[] buffer, int size, SocketFlags flags, EndPoint endp) | ||
136 | { | ||
137 | this.Server.SendTo(buffer, size, flags, endp); | ||
138 | } | ||
139 | * | ||
140 | }*/ | ||
141 | } \ No newline at end of file | ||
diff --git a/OpenSim/Framework/Servers/IRestHandler.cs b/OpenSim/Framework/Servers/IRestHandler.cs new file mode 100644 index 0000000..a2b6bf0 --- /dev/null +++ b/OpenSim/Framework/Servers/IRestHandler.cs | |||
@@ -0,0 +1,35 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | |||
32 | namespace OpenSim.Framework.Servers | ||
33 | { | ||
34 | public delegate string RestMethod( string request, string path, string param ); | ||
35 | } | ||
diff --git a/OpenSim/Framework/Servers/OpenSim.Framework.Servers.csproj b/OpenSim/Framework/Servers/OpenSim.Framework.Servers.csproj new file mode 100644 index 0000000..399f456 --- /dev/null +++ b/OpenSim/Framework/Servers/OpenSim.Framework.Servers.csproj | |||
@@ -0,0 +1,116 @@ | |||
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>{2CC71860-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>OpenSim.Framework.Servers</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>OpenSim.Framework.Servers</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="libsecondlife.dll" > | ||
62 | <HintPath>..\..\..\bin\libsecondlife.dll</HintPath> | ||
63 | <Private>False</Private> | ||
64 | </Reference> | ||
65 | <Reference Include="System" > | ||
66 | <HintPath>System.dll</HintPath> | ||
67 | <Private>False</Private> | ||
68 | </Reference> | ||
69 | <Reference Include="System.Xml" > | ||
70 | <HintPath>System.Xml.dll</HintPath> | ||
71 | <Private>False</Private> | ||
72 | </Reference> | ||
73 | <Reference Include="XMLRPC.dll" > | ||
74 | <HintPath>..\..\..\bin\XMLRPC.dll</HintPath> | ||
75 | <Private>False</Private> | ||
76 | </Reference> | ||
77 | </ItemGroup> | ||
78 | <ItemGroup> | ||
79 | <ProjectReference Include="..\General\OpenSim.Framework.csproj"> | ||
80 | <Name>OpenSim.Framework</Name> | ||
81 | <Project>{8ACA2445-0000-0000-0000-000000000000}</Project> | ||
82 | <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package> | ||
83 | <Private>False</Private> | ||
84 | </ProjectReference> | ||
85 | <ProjectReference Include="..\Console\OpenSim.Framework.Console.csproj"> | ||
86 | <Name>OpenSim.Framework.Console</Name> | ||
87 | <Project>{A7CD0630-0000-0000-0000-000000000000}</Project> | ||
88 | <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package> | ||
89 | <Private>False</Private> | ||
90 | </ProjectReference> | ||
91 | </ItemGroup> | ||
92 | <ItemGroup> | ||
93 | <Compile Include="BaseHttpServer.cs"> | ||
94 | <SubType>Code</SubType> | ||
95 | </Compile> | ||
96 | <Compile Include="CheckSumServer.cs"> | ||
97 | <SubType>Code</SubType> | ||
98 | </Compile> | ||
99 | <Compile Include="IRestHandler.cs"> | ||
100 | <SubType>Code</SubType> | ||
101 | </Compile> | ||
102 | <Compile Include="UDPServerBase.cs"> | ||
103 | <SubType>Code</SubType> | ||
104 | </Compile> | ||
105 | <Compile Include="XmlRpcMethod.cs"> | ||
106 | <SubType>Code</SubType> | ||
107 | </Compile> | ||
108 | </ItemGroup> | ||
109 | <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" /> | ||
110 | <PropertyGroup> | ||
111 | <PreBuildEvent> | ||
112 | </PreBuildEvent> | ||
113 | <PostBuildEvent> | ||
114 | </PostBuildEvent> | ||
115 | </PropertyGroup> | ||
116 | </Project> | ||
diff --git a/OpenSim/Framework/Servers/OpenSim.Framework.Servers.dll.build b/OpenSim/Framework/Servers/OpenSim.Framework.Servers.dll.build new file mode 100644 index 0000000..7401b07 --- /dev/null +++ b/OpenSim/Framework/Servers/OpenSim.Framework.Servers.dll.build | |||
@@ -0,0 +1,48 @@ | |||
1 | <?xml version="1.0" ?> | ||
2 | <project name="OpenSim.Framework.Servers" 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="OpenSim.Framework.Servers" dynamicprefix="true" > | ||
12 | </resources> | ||
13 | <sources failonempty="true"> | ||
14 | <include name="BaseHttpServer.cs" /> | ||
15 | <include name="CheckSumServer.cs" /> | ||
16 | <include name="IRestHandler.cs" /> | ||
17 | <include name="UDPServerBase.cs" /> | ||
18 | <include name="XmlRpcMethod.cs" /> | ||
19 | </sources> | ||
20 | <references basedir="${project::get-base-directory()}"> | ||
21 | <lib> | ||
22 | <include name="${project::get-base-directory()}" /> | ||
23 | <include name="${project::get-base-directory()}/${build.dir}" /> | ||
24 | </lib> | ||
25 | <include name="../../../bin/libsecondlife.dll" /> | ||
26 | <include name="../../../bin/OpenSim.Framework.dll" /> | ||
27 | <include name="../../../bin/OpenSim.Framework.Console.dll" /> | ||
28 | <include name="System.dll" /> | ||
29 | <include name="System.Xml.dll" /> | ||
30 | <include name="../../../bin/XMLRPC.dll" /> | ||
31 | </references> | ||
32 | </csc> | ||
33 | <echo message="Copying from [${project::get-base-directory()}/${build.dir}/] to [${project::get-base-directory()}/../../../bin/" /> | ||
34 | <mkdir dir="${project::get-base-directory()}/../../../bin/"/> | ||
35 | <copy todir="${project::get-base-directory()}/../../../bin/"> | ||
36 | <fileset basedir="${project::get-base-directory()}/${build.dir}/" > | ||
37 | <include name="*.dll"/> | ||
38 | <include name="*.exe"/> | ||
39 | </fileset> | ||
40 | </copy> | ||
41 | </target> | ||
42 | <target name="clean"> | ||
43 | <delete dir="${bin.dir}" failonerror="false" /> | ||
44 | <delete dir="${obj.dir}" failonerror="false" /> | ||
45 | </target> | ||
46 | <target name="doc" description="Creates documentation."> | ||
47 | </target> | ||
48 | </project> | ||
diff --git a/OpenSim/Framework/Servers/UDPServerBase.cs b/OpenSim/Framework/Servers/UDPServerBase.cs new file mode 100644 index 0000000..610d23b --- /dev/null +++ b/OpenSim/Framework/Servers/UDPServerBase.cs | |||
@@ -0,0 +1,95 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using System.Text; | ||
30 | using System.IO; | ||
31 | using System.Threading; | ||
32 | using System.Net; | ||
33 | using System.Net.Sockets; | ||
34 | using System.Timers; | ||
35 | using System.Reflection; | ||
36 | using System.Collections; | ||
37 | using System.Collections.Generic; | ||
38 | using libsecondlife; | ||
39 | using libsecondlife.Packets; | ||
40 | |||
41 | namespace OpenSim.Framework.Servers | ||
42 | { | ||
43 | public class UDPServerBase | ||
44 | { | ||
45 | public Socket Server; | ||
46 | protected IPEndPoint ServerIncoming; | ||
47 | protected byte[] RecvBuffer = new byte[4096]; | ||
48 | protected byte[] ZeroBuffer = new byte[8192]; | ||
49 | protected IPEndPoint ipeSender; | ||
50 | protected EndPoint epSender; | ||
51 | protected AsyncCallback ReceivedData; | ||
52 | protected int listenPort; | ||
53 | |||
54 | public UDPServerBase(int port) | ||
55 | { | ||
56 | listenPort = port; | ||
57 | } | ||
58 | |||
59 | protected virtual void OnReceivedData(IAsyncResult result) | ||
60 | { | ||
61 | ipeSender = new IPEndPoint(IPAddress.Any, 0); | ||
62 | epSender = (EndPoint)ipeSender; | ||
63 | Packet packet = null; | ||
64 | int numBytes = Server.EndReceiveFrom(result, ref epSender); | ||
65 | int packetEnd = numBytes - 1; | ||
66 | |||
67 | packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer); | ||
68 | |||
69 | Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); | ||
70 | } | ||
71 | |||
72 | protected virtual void AddNewClient(Packet packet) | ||
73 | { | ||
74 | } | ||
75 | |||
76 | public virtual void ServerListener() | ||
77 | { | ||
78 | |||
79 | ServerIncoming = new IPEndPoint(IPAddress.Any, listenPort); | ||
80 | Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); | ||
81 | Server.Bind(ServerIncoming); | ||
82 | |||
83 | ipeSender = new IPEndPoint(IPAddress.Any, 0); | ||
84 | epSender = (EndPoint)ipeSender; | ||
85 | ReceivedData = new AsyncCallback(this.OnReceivedData); | ||
86 | Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); | ||
87 | } | ||
88 | |||
89 | public virtual void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode) | ||
90 | { | ||
91 | |||
92 | } | ||
93 | } | ||
94 | } | ||
95 | |||
diff --git a/OpenSim/Framework/Servers/XmlRpcMethod.cs b/OpenSim/Framework/Servers/XmlRpcMethod.cs new file mode 100644 index 0000000..51b3303 --- /dev/null +++ b/OpenSim/Framework/Servers/XmlRpcMethod.cs | |||
@@ -0,0 +1,34 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using Nwc.XmlRpc; | ||
30 | |||
31 | namespace OpenSim.Framework.Servers | ||
32 | { | ||
33 | public delegate XmlRpcResponse XmlRpcMethod( XmlRpcRequest request ); | ||
34 | } | ||