aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGridServices.UserServer
diff options
context:
space:
mode:
authorgareth2007-03-24 18:10:05 +0000
committergareth2007-03-24 18:10:05 +0000
commitd1fbe870afc5b89c7b1f8bf33d27e431f886ec07 (patch)
tree5c0dc4125f90ce2f8de79d84e25ce39524cba7d6 /OpenGridServices.UserServer
parentUncommented line (diff)
downloadopensim-SC-d1fbe870afc5b89c7b1f8bf33d27e431f886ec07.zip
opensim-SC-d1fbe870afc5b89c7b1f8bf33d27e431f886ec07.tar.gz
opensim-SC-d1fbe870afc5b89c7b1f8bf33d27e431f886ec07.tar.bz2
opensim-SC-d1fbe870afc5b89c7b1f8bf33d27e431f886ec07.tar.xz
Brought in the OGS user server into the main trunk (in a rather messy way)
Diffstat (limited to '')
-rw-r--r--OpenGridServices.UserServer/ConsoleCmds.cs57
-rw-r--r--OpenGridServices.UserServer/Main.cs259
-rw-r--r--OpenGridServices.UserServer/OGS-UserServer.csproj63
-rw-r--r--OpenGridServices.UserServer/OGS-UserServer.csproj.user8
-rw-r--r--OpenGridServices.UserServer/OpenGridServices.UserServer.exe.build48
-rw-r--r--OpenGridServices.UserServer/Properties/AssemblyInfo.cs33
-rw-r--r--OpenGridServices.UserServer/UserHttp.cs146
7 files changed, 614 insertions, 0 deletions
diff --git a/OpenGridServices.UserServer/ConsoleCmds.cs b/OpenGridServices.UserServer/ConsoleCmds.cs
new file mode 100644
index 0000000..f2568fc
--- /dev/null
+++ b/OpenGridServices.UserServer/ConsoleCmds.cs
@@ -0,0 +1,57 @@
1/*
2Copyright (c) OpenSim 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 ServerConsole;
33
34namespace OpenGridServices
35{
36
37 public class UserConsole : conscmd_callback {
38 public UserConsole() { }
39
40 public override void RunCmd(string cmd, string[] cmdparams) {
41 switch(cmd) {
42 case "help":
43 ServerConsole.MainConsole.Instance.WriteLine("shutdown - shutdown the user server (USE CAUTION!)"
44);
45 break;
46
47 case "shutdown":
48 ServerConsole.MainConsole.Instance.Close();
49 Environment.Exit(0);
50 break;
51 }
52 }
53
54 public override void Show(string ShowWhat) {
55 }
56 }
57}
diff --git a/OpenGridServices.UserServer/Main.cs b/OpenGridServices.UserServer/Main.cs
new file mode 100644
index 0000000..d27f34e
--- /dev/null
+++ b/OpenGridServices.UserServer/Main.cs
@@ -0,0 +1,259 @@
1/*
2Copyright (c) OpenSim 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.Collections;
32using System.Collections.Generic;
33using System.IO;
34using System.Text;
35using libsecondlife;
36using ServerConsole;
37using OpenSim.Framework.User;
38using OpenSim.Framework.Sims;
39using OpenSim.Framework.Inventory;
40
41namespace OpenGridServices
42{
43 /// <summary>
44 /// </summary>
45 public class OpenUser_Main
46 {
47
48 public static OpenUser_Main userserver;
49
50 public UserHTTPServer _httpd;
51 public UserProfileManager _profilemanager;
52 public UserProfile GridGod;
53 public string DefaultStartupMsg;
54 public string GridURL;
55 public string GridSendKey;
56 public string GridRecvKey;
57
58 public Dictionary<LLUUID, UserProfile> UserSessions = new Dictionary<LLUUID, UserProfile>();
59
60 [STAThread]
61 public static void Main( string[] args )
62 {
63 Console.WriteLine("Starting...\n");
64 ServerConsole.MainConsole.Instance = new MServerConsole(ServerConsole.ConsoleBase.ConsoleType.Local, "", 0, "opengrid-console.log", "OpenUser", new UserConsole());
65
66 userserver = new OpenUser_Main();
67 userserver.Startup();
68
69 ServerConsole.MainConsole.Instance.WriteLine("\nEnter help for a list of commands\n");
70
71 while(true) {
72 ServerConsole.MainConsole.Instance.MainConsolePrompt();
73 }
74 }
75
76 public void Startup() {
77 ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Please press enter to retain default settings");
78
79 this.GridURL=ServerConsole.MainConsole.Instance.CmdPrompt("Grid URL: ");
80 this.GridSendKey=ServerConsole.MainConsole.Instance.CmdPrompt("Key to send to grid: ");
81 this.GridRecvKey=ServerConsole.MainConsole.Instance.CmdPrompt("Key to expect from grid: ");
82
83 this.DefaultStartupMsg=ServerConsole.MainConsole.Instance.CmdPrompt("Default startup message for clients [Welcome to OGS!] :","Welcome to OGS!");
84
85 ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Creating user profile manager");
86 _profilemanager = new UserProfileManager();
87 _profilemanager.InitUserProfiles();
88 _profilemanager.SetKeys(GridSendKey, GridRecvKey, GridURL, DefaultStartupMsg);
89
90
91 string tempfirstname;
92 string templastname;
93 string tempMD5Passwd;
94 ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Please configure the grid god user:");
95 tempfirstname=ServerConsole.MainConsole.Instance.CmdPrompt("First name: ");
96 templastname=ServerConsole.MainConsole.Instance.CmdPrompt("Last name: ");
97 tempMD5Passwd=ServerConsole.MainConsole.Instance.PasswdPrompt("Password: ");
98
99 System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
100 byte[] bs = System.Text.Encoding.UTF8.GetBytes(tempMD5Passwd);
101 bs = x.ComputeHash(bs);
102 System.Text.StringBuilder s = new System.Text.StringBuilder();
103 foreach (byte b in bs)
104 {
105 s.Append(b.ToString("x2").ToLower());
106 }
107 tempMD5Passwd = "$1$" + s.ToString();
108
109 GridGod=_profilemanager.CreateNewProfile(tempfirstname,templastname,tempMD5Passwd);
110 _profilemanager.SetGod(GridGod.UUID);
111 GridGod.homelookat = new LLVector3(-0.57343f, -0.819255f, 0f);
112 GridGod.homepos = new LLVector3(128f,128f,23f);
113
114 ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting HTTP process");
115 _httpd = new UserHTTPServer();
116 }
117 }
118
119 public class MServerConsole : ConsoleBase
120 {
121
122 private ConsoleType ConsType;
123 StreamWriter Log;
124 public conscmd_callback cmdparser;
125 public string componentname;
126
127 // STUPID HACK ALERT!!!! STUPID HACK ALERT!!!!!
128 // constype - the type of console to use (see enum ConsoleType)
129 // sparam - depending on the console type:
130 // TCP - the IP to bind to (127.0.0.1 if blank)
131 // Local - param ignored
132 // and for the iparam:
133 // TCP - the port to bind to
134 // Local - param ignored
135 // LogFile - duh
136 // componentname - which component of the OGS system? (user, asset etc)
137 // cmdparser - a reference to a conscmd_callback object
138
139 public MServerConsole(ConsoleType constype, string sparam, int iparam, string LogFile, string componentname, conscmd_callback cmdparser) {
140 ConsType = constype;
141 this.componentname = componentname;
142 this.cmdparser = cmdparser;
143 switch(constype) {
144 case ConsoleType.Local:
145 Console.WriteLine("ServerConsole.cs - creating new local console");
146 Console.WriteLine("Logs will be saved to current directory in " + LogFile);
147 Log=File.AppendText(LogFile);
148 Log.WriteLine("========================================================================");
149 Log.WriteLine(componentname + " Started at " + DateTime.Now.ToString());
150 break;
151
152 case ConsoleType.TCP:
153 break;
154
155 default:
156 Console.WriteLine("ServerConsole.cs - what are you smoking? that isn't a valid console type!");
157 break;
158 }
159 }
160
161 public override void Close() {
162 Log.WriteLine("Shutdown at " + DateTime.Now.ToString());
163 Log.Close();
164 }
165
166 // You know what ReadLine() and WriteLine() do, right? And Read() and Write()? Right, you do actually know C#, right? Are you actually a programmer? Do you know english? Do you find my sense of humour in comments irritating? Good, glad you're still here
167 public override void WriteLine(string Line) {
168 Log.WriteLine(Line);
169 Console.WriteLine(Line);
170 return;
171 }
172
173 public override string ReadLine() {
174 string TempStr=Console.ReadLine();
175 Log.WriteLine(TempStr);
176 return TempStr;
177 }
178
179 public override int Read() {
180 int TempInt= Console.Read();
181 Log.Write((char)TempInt);
182 return TempInt;
183 }
184
185 public override void Write(string Line) {
186 Console.Write(Line);
187 Log.Write(Line);
188 return;
189 }
190
191
192 // Displays a prompt and waits for the user to enter a string, then returns that string
193 // Done with no echo and suitable for passwords
194 public override string PasswdPrompt(string prompt) {
195 // FIXME: Needs to be better abstracted
196 Log.WriteLine(prompt);
197 this.Write(prompt);
198 ConsoleColor oldfg=Console.ForegroundColor;
199 Console.ForegroundColor=Console.BackgroundColor;
200 string temp=Console.ReadLine();
201 Console.ForegroundColor=oldfg;
202 return temp;
203 }
204
205 // Displays a command prompt and waits for the user to enter a string, then returns that string
206 public override string CmdPrompt(string prompt) {
207 this.Write(prompt);
208 return this.ReadLine();
209 }
210
211 // Displays a command prompt and returns a default value if the user simply presses enter
212 public override string CmdPrompt(string prompt, string defaultresponse) {
213 string temp=CmdPrompt(prompt);
214 if(temp=="") {
215 return defaultresponse;
216 } else {
217 return temp;
218 }
219 }
220
221 // Displays a command prompt and returns a default value, user may only enter 1 of 2 options
222 public override string CmdPrompt(string prompt, string defaultresponse, string OptionA, string OptionB) {
223 bool itisdone=false;
224 string temp=CmdPrompt(prompt,defaultresponse);
225 while(itisdone==false) {
226 if((temp==OptionA) || (temp==OptionB)) {
227 itisdone=true;
228 } else {
229 this.WriteLine("Valid options are " + OptionA + " or " + OptionB);
230 temp=CmdPrompt(prompt,defaultresponse);
231 }
232 }
233 return temp;
234 }
235
236 // Runs a command with a number of parameters
237 public override Object RunCmd(string Cmd, string[] cmdparams) {
238 cmdparser.RunCmd(Cmd, cmdparams);
239 return null;
240 }
241
242 // Shows data about something
243 public override void ShowCommands(string ShowWhat) {
244 cmdparser.Show(ShowWhat);
245 }
246
247 public override void MainConsolePrompt() {
248 string[] tempstrarray;
249 string tempstr = this.CmdPrompt(this.componentname + "# ");
250 tempstrarray = tempstr.Split(' ');
251 string cmd=tempstrarray[0];
252 Array.Reverse(tempstrarray);
253 Array.Resize<string>(ref tempstrarray,tempstrarray.Length-1);
254 Array.Reverse(tempstrarray);
255 string[] cmdparams=(string[])tempstrarray;
256 RunCmd(cmd,cmdparams);
257 }
258 }
259}
diff --git a/OpenGridServices.UserServer/OGS-UserServer.csproj b/OpenGridServices.UserServer/OGS-UserServer.csproj
new file mode 100644
index 0000000..f4fa8b6
--- /dev/null
+++ b/OpenGridServices.UserServer/OGS-UserServer.csproj
@@ -0,0 +1,63 @@
1<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2 <PropertyGroup>
3 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
4 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
5 <ProductVersion>8.0.50727</ProductVersion>
6 <SchemaVersion>2.0</SchemaVersion>
7 <ProjectGuid>{D45B6E48-5668-478D-B9CB-6D46E665FACF}</ProjectGuid>
8 <OutputType>Exe</OutputType>
9 <AppDesignerFolder>Properties</AppDesignerFolder>
10 <RootNamespace>OGS_UserServer</RootNamespace>
11 <AssemblyName>OGS-UserServer</AssemblyName>
12 <StartupObject>OpenGridServices.OpenUser_Main</StartupObject>
13 </PropertyGroup>
14 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
15 <DebugSymbols>true</DebugSymbols>
16 <DebugType>full</DebugType>
17 <Optimize>false</Optimize>
18 <OutputPath>bin\Debug\</OutputPath>
19 <DefineConstants>DEBUG;TRACE</DefineConstants>
20 <ErrorReport>prompt</ErrorReport>
21 <WarningLevel>4</WarningLevel>
22 </PropertyGroup>
23 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
24 <DebugType>pdbonly</DebugType>
25 <Optimize>true</Optimize>
26 <OutputPath>bin\Release\</OutputPath>
27 <DefineConstants>TRACE</DefineConstants>
28 <ErrorReport>prompt</ErrorReport>
29 <WarningLevel>4</WarningLevel>
30 </PropertyGroup>
31 <ItemGroup>
32 <Reference Include="libsecondlife, Version=0.9.0.0, Culture=neutral, processorArchitecture=MSIL">
33 <SpecificVersion>False</SpecificVersion>
34 <HintPath>..\..\common\bin\libsecondlife.dll</HintPath>
35 </Reference>
36 <Reference Include="System" />
37 <Reference Include="System.Data" />
38 <Reference Include="System.Xml" />
39 </ItemGroup>
40 <ItemGroup>
41 <Compile Include="..\..\common\src\OGS-Console.cs">
42 <Link>OGS-Console.cs</Link>
43 </Compile>
44 <Compile Include="..\..\common\VersionInfo\VersionInfo.cs">
45 <Link>VersionInfo.cs</Link>
46 </Compile>
47 <Compile Include="ConsoleCmds.cs" />
48 <Compile Include="Main.cs" />
49 <Compile Include="Properties\AssemblyInfo.cs" />
50 <Compile Include="UserHttp.cs" />
51 </ItemGroup>
52 <ItemGroup>
53 <ProjectReference Include="..\..\..\OpenSim.FrameWork\OpenSim.Framework.csproj">
54 <Project>{2E46A825-3168-492F-93BC-637126B5B72B}</Project>
55 <Name>OpenSim.Framework</Name>
56 </ProjectReference>
57 <ProjectReference Include="..\..\ServerConsole\ServerConsole.csproj">
58 <Project>{7667E6E2-F227-41A2-B1B2-315613E1BAFC}</Project>
59 <Name>ServerConsole</Name>
60 </ProjectReference>
61 </ItemGroup>
62 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
63</Project> \ No newline at end of file
diff --git a/OpenGridServices.UserServer/OGS-UserServer.csproj.user b/OpenGridServices.UserServer/OGS-UserServer.csproj.user
new file mode 100644
index 0000000..aa75a3d
--- /dev/null
+++ b/OpenGridServices.UserServer/OGS-UserServer.csproj.user
@@ -0,0 +1,8 @@
1<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2 <PropertyGroup>
3 <PublishUrlHistory>publish\</PublishUrlHistory>
4 <ApplicationRevision>0</ApplicationRevision>
5 <FallbackCulture>en-US</FallbackCulture>
6 <VerifyUploadedFiles>false</VerifyUploadedFiles>
7 </PropertyGroup>
8</Project> \ No newline at end of file
diff --git a/OpenGridServices.UserServer/OpenGridServices.UserServer.exe.build b/OpenGridServices.UserServer/OpenGridServices.UserServer.exe.build
new file mode 100644
index 0000000..710b01b
--- /dev/null
+++ b/OpenGridServices.UserServer/OpenGridServices.UserServer.exe.build
@@ -0,0 +1,48 @@
1<?xml version="1.0" ?>
2<project name="OpenGridServices.UserServer" 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="exe" debug="${build.debug}" unsafe="False" define="TRACE" output="${project::get-base-directory()}/${build.dir}/${project::get-name()}.exe">
11 <resources prefix="OpenGridServices.UserServer" dynamicprefix="true" >
12 </resources>
13 <sources failonempty="true">
14 <include name="ConsoleCmds.cs" />
15 <include name="Main.cs" />
16 <include name="UserHttp.cs" />
17 <include name="Properties/AssemblyInfo.cs" />
18 </sources>
19 <references basedir="${project::get-base-directory()}">
20 <lib>
21 <include name="${project::get-base-directory()}" />
22 <include name="${project::get-base-directory()}/${build.dir}" />
23 </lib>
24 <include name="System.dll" />
25 <include name="System.Data.dll" />
26 <include name="System.Xml.dll" />
27 <include name="../bin/OpenSim.Framework.dll" />
28 <include name="../bin/OpenSim.Framework.Console.dll" />
29 <include name="../bin/OpenGridServices.ServerConsole.dll" />
30 <include name="../bin/libsecondlife.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/OpenGridServices.UserServer/Properties/AssemblyInfo.cs b/OpenGridServices.UserServer/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..5d5ce8d
--- /dev/null
+++ b/OpenGridServices.UserServer/Properties/AssemblyInfo.cs
@@ -0,0 +1,33 @@
1using System.Reflection;
2using System.Runtime.CompilerServices;
3using System.Runtime.InteropServices;
4
5// General Information about an assembly is controlled through the following
6// set of attributes. Change these attribute values to modify the information
7// associated with an assembly.
8[assembly: AssemblyTitle("OGS-UserServer")]
9[assembly: AssemblyDescription("")]
10[assembly: AssemblyConfiguration("")]
11[assembly: AssemblyCompany("")]
12[assembly: AssemblyProduct("OGS-UserServer")]
13[assembly: AssemblyCopyright("Copyright © 2007")]
14[assembly: AssemblyTrademark("")]
15[assembly: AssemblyCulture("")]
16
17// Setting ComVisible to false makes the types in this assembly not visible
18// to COM components. If you need to access a type in this assembly from
19// COM, set the ComVisible attribute to true on that type.
20[assembly: ComVisible(false)]
21
22// The following GUID is for the ID of the typelib if this project is exposed to COM
23[assembly: Guid("e266513a-090b-4d38-80f6-8599eef68c8c")]
24
25// Version information for an assembly consists of the following four values:
26//
27// Major Version
28// Minor Version
29// Build Number
30// Revision
31//
32[assembly: AssemblyVersion("1.0.0.0")]
33[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/OpenGridServices.UserServer/UserHttp.cs b/OpenGridServices.UserServer/UserHttp.cs
new file mode 100644
index 0000000..ce3cfcd
--- /dev/null
+++ b/OpenGridServices.UserServer/UserHttp.cs
@@ -0,0 +1,146 @@
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 ServerConsole;
41using OpenSim.Framework.User;
42using OpenSim.Framework.Sims;
43using OpenSim.Framework.Inventory;
44
45namespace OpenGridServices
46{
47 public class UserHTTPServer {
48 public Thread HTTPD;
49 public HttpListener Listener;
50
51 public UserHTTPServer() {
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 ServerConsole.MainConsole.Instance.WriteLine("UserHttp.cs:StartHTTP() - Spawned main thread OK");
59 Listener = new HttpListener();
60
61 Listener.Prefixes.Add("http://+:8002/userserver/");
62 Listener.Prefixes.Add("http://+:8002/usersessions/");
63 Listener.Start();
64
65 HttpListenerContext context;
66 while(true) {
67 context = Listener.GetContext();
68 ThreadPool.QueueUserWorkItem(new WaitCallback(HandleRequest), context);
69 }
70 }
71
72 static string ParseXMLRPC(string requestBody) {
73 return OpenGridServices.OpenUser_Main.userserver._profilemanager.ParseXMLRPC(requestBody);
74 }
75
76 static string ParseREST(HttpListenerRequest www_req) {
77 Console.WriteLine("INCOMING REST - " + www_req.RawUrl);
78
79 char[] splitter = {'/'};
80 string[] rest_params = www_req.RawUrl.Split(splitter);
81 string req_type = rest_params[1]; // First part of the URL is the type of request - usersessions/userprofiles/inventory/blabla
82 switch(req_type) {
83 case "usersessions":
84 LLUUID sessionid = new LLUUID(rest_params[2]); // get usersessions/sessionid
85 if(www_req.HttpMethod=="DELETE") {
86 foreach (libsecondlife.LLUUID UUID in OpenUser_Main.userserver._profilemanager.UserProfiles.Keys) {
87 if(OpenUser_Main.userserver._profilemanager.UserProfiles[UUID].CurrentSessionID==sessionid) {
88 OpenUser_Main.userserver._profilemanager.UserProfiles[UUID].CurrentSessionID=null;
89 OpenUser_Main.userserver._profilemanager.UserProfiles[UUID].CurrentSecureSessionID=null;
90 OpenUser_Main.userserver._profilemanager.UserProfiles[UUID].Circuits.Clear();
91 }
92 }
93
94 }
95 return "OK";
96 break;
97 }
98
99 return "";
100 }
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 "text/plaintext":
130 responseString=ParseREST(request);
131 response.AddHeader("Content-type","text/plaintext");
132 break;
133 }
134
135
136 byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
137 System.IO.Stream output = response.OutputStream;
138 response.SendChunked=false;
139 response.ContentLength64=buffer.Length;
140 output.Write(buffer,0,buffer.Length);
141 output.Close();
142 }
143 }
144
145
146}