aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/CAPS/SimHttp.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/CAPS/SimHttp.cs')
-rw-r--r--src/CAPS/SimHttp.cs165
1 files changed, 0 insertions, 165 deletions
diff --git a/src/CAPS/SimHttp.cs b/src/CAPS/SimHttp.cs
deleted file mode 100644
index c0373de..0000000
--- a/src/CAPS/SimHttp.cs
+++ /dev/null
@@ -1,165 +0,0 @@
1/*
2Copyright (c) OpenSimCAPS project, http://osgrid.org/
3
4
5* All rights reserved.
6*
7* Redistribution and use in source and binary forms, with or without
8* modification, are permitted provided that the following conditions are met:
9* * Redistributions of source code must retain the above copyright
10* notice, this list of conditions and the following disclaimer.
11* * Redistributions in binary form must reproduce the above copyright
12* notice, this list of conditions and the following disclaimer in the
13* documentation and/or other materials provided with the distribution.
14* * Neither the name of the <organization> nor the
15* names of its contributors may be used to endorse or promote products
16* derived from this software without specific prior written permission.
17*
18* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
19* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
22* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30using System;
31using System.Text;
32using Nwc.XmlRpc;
33using System.Threading;
34using System.Text.RegularExpressions;
35using System.Net;
36using System.IO;
37using System.Collections;
38using System.Collections.Generic;
39using libsecondlife;
40using ServerConsole;
41using OpenSim.GridServers;
42
43namespace OpenSim
44{
45 // Dummy HTTP server, does nothing useful for now
46
47 public class SimCAPSHTTPServer {
48 public Thread HTTPD;
49 public HttpListener Listener;
50
51 public SimCAPSHTTPServer() {
52 ServerConsole.MainConsole.Instance.WriteLine("Starting up HTTP Server");
53 HTTPD = new Thread(new ThreadStart(StartHTTP));
54 HTTPD.Start();
55 }
56
57 public void StartHTTP() {
58 try
59 {
60 ServerConsole.MainConsole.Instance.WriteLine("SimHttp.cs:StartHTTP() - Spawned main thread OK");
61 Listener = new HttpListener();
62
63 Listener.Prefixes.Add("http://+:" + OpenSim_Main.cfg.IPListenPort + "/");
64 Listener.Start();
65
66 HttpListenerContext context;
67 while(true) {
68 context = Listener.GetContext();
69 ThreadPool.QueueUserWorkItem(new WaitCallback(HandleRequest), context);
70 }
71 }
72 catch (Exception e)
73 {
74 ServerConsole.MainConsole.Instance.WriteLine(e.Message);
75 }
76 }
77
78 static string ParseXMLRPC(string requestBody) {
79 try
80 {
81 XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody);
82
83 Hashtable requestData = (Hashtable)request.Params[0];
84 switch(request.MethodName) {
85 case "expect_user":
86 GridServers.agentcircuitdata agent_data = new GridServers.agentcircuitdata();
87 agent_data.SessionID = new LLUUID((string)requestData["session_id"]);
88 agent_data.SecureSessionID = new LLUUID((string)requestData["secure_session_id"]);
89 agent_data.firstname = (string)requestData["firstname"];
90 agent_data.lastname = (string)requestData["lastname"];
91 agent_data.AgentID = new LLUUID((string)requestData["agent_id"]);
92 agent_data.circuitcode = Convert.ToUInt32(requestData["circuit_code"]);
93 if (OpenSim_Main.gridServers.GridServer.GetName() == "Remote")
94 {
95 ((RemoteGridBase) OpenSim_Main.gridServers.GridServer).agentcircuits.Add((uint)agent_data.circuitcode,agent_data);
96 }
97 return "<?xml version=\"1.0\"?><methodResponse><params /></methodResponse>";
98 break;
99 }
100 }
101 catch(Exception e)
102 {
103 Console.WriteLine(e.ToString());
104 }
105 return "";
106 }
107
108 static string ParseREST(string requestBody, string requestURL) {
109 return "";
110 }
111
112 static string ParseLLSDXML(string requestBody) {
113 // dummy function for now - IMPLEMENT ME!
114 return "";
115 }
116
117 static void HandleRequest(Object stateinfo) {
118 HttpListenerContext context=(HttpListenerContext)stateinfo;
119
120 HttpListenerRequest request = context.Request;
121 HttpListenerResponse response = context.Response;
122
123 response.KeepAlive=false;
124 response.SendChunked=false;
125
126 System.IO.Stream body = request.InputStream;
127 System.Text.Encoding encoding = System.Text.Encoding.UTF8;
128 System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding);
129
130 string requestBody = reader.ReadToEnd();
131 body.Close();
132 reader.Close();
133
134 string responseString="";
135 switch(request.ContentType) {
136 case "text/xml":
137 // must be XML-RPC, so pass to the XML-RPC parser
138
139 responseString=ParseXMLRPC(requestBody);
140 response.AddHeader("Content-type","text/xml");
141 break;
142
143 case "application/xml":
144 // probably LLSD we hope, otherwise it should be ignored by the parser
145 responseString=ParseLLSDXML(requestBody);
146 response.AddHeader("Content-type","application/xml");
147 break;
148
149 case null:
150 // must be REST or invalid crap, so pass to the REST parser
151 responseString=ParseREST(request.Url.OriginalString,requestBody);
152 break;
153 }
154
155 byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
156 System.IO.Stream output = response.OutputStream;
157 response.SendChunked=false;
158 response.ContentLength64=buffer.Length;
159 output.Write(buffer,0,buffer.Length);
160 output.Close();
161 }
162 }
163
164
165}