aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGridServices.UserServer/UserHttp.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenGridServices.UserServer/UserHttp.cs154
1 files changed, 0 insertions, 154 deletions
diff --git a/OpenGridServices.UserServer/UserHttp.cs b/OpenGridServices.UserServer/UserHttp.cs
deleted file mode 100644
index 191fccb..0000000
--- a/OpenGridServices.UserServer/UserHttp.cs
+++ /dev/null
@@ -1,154 +0,0 @@
1/*
2Copyright (c) OpenGrid 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 OpenSim.Framework.User;
41using OpenSim.Framework.Sims;
42using OpenSim.Framework.Inventory;
43using OpenSim.Framework.Console;
44using OpenSim.Servers;
45
46namespace OpenGridServices.UserServer
47{
48 public class UserHTTPServer : BaseHttpServer
49 {
50 public Thread HTTPD;
51 public HttpListener Listener;
52
53 public UserHTTPServer() : base( 8002 )
54 {
55 }
56
57 public void Start()
58 {
59 MainConsole.Instance.WriteLine("Starting up HTTP Server");
60 HTTPD = new Thread(new ThreadStart(StartHTTP));
61 HTTPD.Start();
62 }
63
64 public void StartHTTP()
65 {
66 MainConsole.Instance.WriteLine("UserHttp.cs:StartHTTP() - Spawned main thread OK");
67 Listener = new HttpListener();
68
69 Listener.Prefixes.Add("http://+:8002/userserver/");
70 Listener.Prefixes.Add("http://+:8002/usersessions/");
71 Listener.Start();
72
73 HttpListenerContext context;
74 while (true)
75 {
76 context = Listener.GetContext();
77 ThreadPool.QueueUserWorkItem(new WaitCallback(HandleRequest), context);
78 }
79 }
80
81 static string ParseXMLRPC(string requestBody)
82 {
83 return OpenUser_Main.userserver._profilemanager.ParseXMLRPC(requestBody);
84 }
85
86 static string ParseREST(HttpListenerRequest www_req)
87 {
88 Console.WriteLine("INCOMING REST - " + www_req.RawUrl);
89
90 char[] splitter = { '/' };
91 string[] rest_params = www_req.RawUrl.Split(splitter);
92 string req_type = rest_params[1]; // First part of the URL is the type of request - usersessions/userprofiles/inventory/blabla
93 switch (req_type)
94 {
95 case "usersessions":
96 string param = rest_params[2];
97 string result = "";
98 if (www_req.HttpMethod == "DELETE")
99 {
100 result = OpenUser_Main.userserver._profilemanager.RestDeleteUserSessionMethod( null, null, param );
101 }
102 return result;
103 }
104
105 return "";
106 }
107
108
109 static void HandleRequest(Object stateinfo)
110 {
111 HttpListenerContext context = (HttpListenerContext)stateinfo;
112
113 HttpListenerRequest request = context.Request;
114 HttpListenerResponse response = context.Response;
115
116 response.KeepAlive = false;
117 response.SendChunked = false;
118
119 System.IO.Stream body = request.InputStream;
120 System.Text.Encoding encoding = System.Text.Encoding.UTF8;
121 System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding);
122
123 string requestBody = reader.ReadToEnd();
124 body.Close();
125 reader.Close();
126
127 string responseString = "";
128 switch (request.ContentType)
129 {
130 case "text/xml":
131 // must be XML-RPC, so pass to the XML-RPC parser
132
133 responseString = ParseXMLRPC(requestBody);
134 response.AddHeader("Content-type", "text/xml");
135 break;
136
137 case "text/plaintext":
138 responseString = ParseREST(request);
139 response.AddHeader("Content-type", "text/plaintext");
140 break;
141 }
142
143
144 byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
145 System.IO.Stream output = response.OutputStream;
146 response.SendChunked = false;
147 response.ContentLength64 = buffer.Length;
148 output.Write(buffer, 0, buffer.Length);
149 output.Close();
150 }
151 }
152
153
154}