aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/CAPS/SimHttp.cs
diff options
context:
space:
mode:
authorgareth2007-03-14 03:34:49 +0000
committergareth2007-03-14 03:34:49 +0000
commit7a54467bed7e1da77f7e1a45ee01dfc709b5608d (patch)
treee0b575e4e87c4b127556597798186b7040d94b2a /src/CAPS/SimHttp.cs
parentMerged ogs-cs into trunk (diff)
downloadopensim-SC_OLD-7a54467bed7e1da77f7e1a45ee01dfc709b5608d.zip
opensim-SC_OLD-7a54467bed7e1da77f7e1a45ee01dfc709b5608d.tar.gz
opensim-SC_OLD-7a54467bed7e1da77f7e1a45ee01dfc709b5608d.tar.bz2
opensim-SC_OLD-7a54467bed7e1da77f7e1a45ee01dfc709b5608d.tar.xz
merged new OpenSim from branches/ogs-cs
Diffstat (limited to '')
-rw-r--r--src/CAPS/SimHttp.cs152
1 files changed, 152 insertions, 0 deletions
diff --git a/src/CAPS/SimHttp.cs b/src/CAPS/SimHttp.cs
new file mode 100644
index 0000000..eb20f3e
--- /dev/null
+++ b/src/CAPS/SimHttp.cs
@@ -0,0 +1,152 @@
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;
41
42namespace OpenSim
43{
44 // Dummy HTTP server, does nothing useful for now
45
46 public class SimCAPSHTTPServer {
47 public Thread HTTPD;
48 public HttpListener Listener;
49
50 public SimCAPSHTTPServer() {
51 ServerConsole.MainConsole.Instance.WriteLine("Starting up HTTP Server");
52 HTTPD = new Thread(new ThreadStart(StartHTTP));
53 HTTPD.Start();
54 }
55
56 public void StartHTTP() {
57 ServerConsole.MainConsole.Instance.WriteLine("SimHttp.cs:StartHTTP() - Spawned main thread OK");
58 Listener = new HttpListener();
59
60 Listener.Prefixes.Add("http://+:" + OpenSim_Main.cfg.IPListenPort + "/");
61 Listener.Start();
62
63 HttpListenerContext context;
64 while(true) {
65 context = Listener.GetContext();
66 ThreadPool.QueueUserWorkItem(new WaitCallback(HandleRequest), context);
67 }
68 }
69
70 static string ParseXMLRPC(string requestBody) {
71 try{
72 XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody);
73
74 Hashtable requestData = (Hashtable)request.Params[0];
75 switch(request.MethodName) {
76 case "expect_user":
77 GridServers.agentcircuitdata agent_data = new GridServers.agentcircuitdata();
78 agent_data.SessionID = new LLUUID((string)requestData["session_id"]);
79 agent_data.SecureSessionID = new LLUUID((string)requestData["secure_session_id"]);
80 agent_data.firstname = (string)requestData["firstname"];
81 agent_data.lastname = (string)requestData["lastname"];
82 agent_data.AgentID = new LLUUID((string)requestData["agent_id"]);
83 agent_data.circuitcode = Convert.ToUInt32(requestData["circuit_code"]);
84 OpenSim_Main.gridServers.GridServer.agentcircuits.Add((uint)agent_data.circuitcode,agent_data);
85 return "<?xml version=\"1.0\"?><methodResponse><params /></methodResponse>";
86 break;
87 }
88 } catch(Exception e) {
89 Console.WriteLine(e.ToString());
90 }
91 return "";
92 }
93
94 static string ParseREST(string requestBody, string requestURL) {
95 return "";
96 }
97
98 static string ParseLLSDXML(string requestBody) {
99 // dummy function for now - IMPLEMENT ME!
100 return "";
101 }
102
103 static void HandleRequest(Object stateinfo) {
104 HttpListenerContext context=(HttpListenerContext)stateinfo;
105
106 HttpListenerRequest request = context.Request;
107 HttpListenerResponse response = context.Response;
108
109 response.KeepAlive=false;
110 response.SendChunked=false;
111
112 System.IO.Stream body = request.InputStream;
113 System.Text.Encoding encoding = System.Text.Encoding.UTF8;
114 System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding);
115
116 string requestBody = reader.ReadToEnd();
117 body.Close();
118 reader.Close();
119
120 string responseString="";
121 switch(request.ContentType) {
122 case "text/xml":
123 // must be XML-RPC, so pass to the XML-RPC parser
124
125 responseString=ParseXMLRPC(requestBody);
126 response.AddHeader("Content-type","text/xml");
127 break;
128
129 case "application/xml":
130 // probably LLSD we hope, otherwise it should be ignored by the parser
131 responseString=ParseLLSDXML(requestBody);
132 response.AddHeader("Content-type","application/xml");
133 break;
134
135 case null:
136 // must be REST or invalid crap, so pass to the REST parser
137 responseString=ParseREST(request.Url.OriginalString,requestBody);
138 break;
139 }
140
141
142 byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
143 System.IO.Stream output = response.OutputStream;
144 response.SendChunked=false;
145 response.ContentLength64=buffer.Length;
146 output.Write(buffer,0,buffer.Length);
147 output.Close();
148 }
149 }
150
151
152}