diff options
author | lbsa71 | 2007-04-11 20:07:58 +0000 |
---|---|---|
committer | lbsa71 | 2007-04-11 20:07:58 +0000 |
commit | 1a28ef6292a152a69d0f53803daacc7dad522cea (patch) | |
tree | 3d4e2eed288b208f1d0db7d37e8f1d9a1dfca1c5 /OpenGridServices.UserServer | |
parent | * cleaning (diff) | |
download | opensim-SC-1a28ef6292a152a69d0f53803daacc7dad522cea.zip opensim-SC-1a28ef6292a152a69d0f53803daacc7dad522cea.tar.gz opensim-SC-1a28ef6292a152a69d0f53803daacc7dad522cea.tar.bz2 opensim-SC-1a28ef6292a152a69d0f53803daacc7dad522cea.tar.xz |
* Replaced GridHTTPServer and UserHTTPServer with BaseHttpServer
* Now dumping default value in config.
*
Diffstat (limited to 'OpenGridServices.UserServer')
-rw-r--r-- | OpenGridServices.UserServer/Main.cs | 206 | ||||
-rw-r--r-- | OpenGridServices.UserServer/OpenGridServices.UserServer.csproj | 3 | ||||
-rw-r--r-- | OpenGridServices.UserServer/OpenGridServices.UserServer.exe.build | 1 | ||||
-rw-r--r-- | OpenGridServices.UserServer/UserHttp.cs | 154 |
4 files changed, 103 insertions, 261 deletions
diff --git a/OpenGridServices.UserServer/Main.cs b/OpenGridServices.UserServer/Main.cs index 9132a54..c348a74 100644 --- a/OpenGridServices.UserServer/Main.cs +++ b/OpenGridServices.UserServer/Main.cs | |||
@@ -39,126 +39,126 @@ using OpenSim.Framework.Sims; | |||
39 | using OpenSim.Framework.Inventory; | 39 | using OpenSim.Framework.Inventory; |
40 | using OpenSim.Framework.Interfaces; | 40 | using OpenSim.Framework.Interfaces; |
41 | using OpenSim.Framework.Console; | 41 | using OpenSim.Framework.Console; |
42 | using OpenSim.Servers; | ||
42 | 43 | ||
43 | namespace OpenGridServices.UserServer | 44 | namespace OpenGridServices.UserServer |
44 | { | 45 | { |
45 | /// <summary> | 46 | /// <summary> |
46 | /// </summary> | 47 | /// </summary> |
47 | public class OpenUser_Main : conscmd_callback | 48 | public class OpenUser_Main : BaseServer, conscmd_callback |
48 | { | 49 | { |
49 | private string ConfigDll = "OpenUser.Config.UserConfigDb4o.dll"; | 50 | private string ConfigDll = "OpenUser.Config.UserConfigDb4o.dll"; |
50 | private UserConfig Cfg; | 51 | private UserConfig Cfg; |
51 | 52 | ||
52 | public static OpenUser_Main userserver; | 53 | private UserProfileManager m_userProfileManager; |
53 | 54 | ||
54 | public UserHTTPServer _httpd; | 55 | public Dictionary<LLUUID, UserProfile> UserSessions = new Dictionary<LLUUID, UserProfile>(); |
55 | public UserProfileManager _profilemanager; | 56 | |
56 | 57 | ConsoleBase m_console; | |
57 | public Dictionary<LLUUID, UserProfile> UserSessions = new Dictionary<LLUUID, UserProfile>(); | 58 | |
58 | 59 | [STAThread] | |
59 | ConsoleBase m_console; | 60 | public static void Main(string[] args) |
60 | 61 | { | |
61 | [STAThread] | 62 | Console.WriteLine("Starting...\n"); |
62 | public static void Main( string[] args ) | 63 | |
63 | { | 64 | OpenUser_Main userserver = new OpenUser_Main(); |
64 | Console.WriteLine("Starting...\n"); | 65 | userserver.Startup(); |
65 | 66 | userserver.Work(); | |
66 | userserver = new OpenUser_Main(); | 67 | } |
67 | userserver.Startup(); | 68 | |
68 | 69 | private OpenUser_Main() | |
69 | userserver.Work(); | 70 | { |
70 | } | 71 | m_console = new ConsoleBase("opengrid-userserver-console.log", "OpenUser", this); |
71 | 72 | MainConsole.Instance = m_console; | |
72 | private OpenUser_Main() | 73 | } |
73 | { | 74 | |
74 | m_console = new ConsoleBase("opengrid-userserver-console.log", "OpenUser", this); | 75 | private void Work() |
75 | MainConsole.Instance = m_console; | 76 | { |
77 | m_console.WriteLine("\nEnter help for a list of commands\n"); | ||
78 | |||
79 | while (true) | ||
80 | { | ||
81 | m_console.MainConsolePrompt(); | ||
82 | } | ||
83 | } | ||
84 | |||
85 | public void Startup() | ||
86 | { | ||
87 | MainConsole.Instance.WriteLine("Main.cs:Startup() - Loading configuration"); | ||
88 | Cfg = this.LoadConfigDll(this.ConfigDll); | ||
89 | Cfg.InitConfig(); | ||
90 | |||
91 | MainConsole.Instance.WriteLine("Main.cs:Startup() - Creating user profile manager"); | ||
92 | m_userProfileManager = new UserProfileManager(); | ||
93 | m_userProfileManager.InitUserProfiles(); | ||
94 | m_userProfileManager.SetKeys(Cfg.GridSendKey, Cfg.GridRecvKey, Cfg.GridServerURL, Cfg.DefaultStartupMsg); | ||
95 | |||
96 | MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting HTTP process"); | ||
97 | BaseHttpServer httpServer = new BaseHttpServer(8002); | ||
98 | |||
99 | httpServer.AddXmlRPCHandler("login_to_simulator", m_userProfileManager.XmlRpcLoginMethod); | ||
100 | httpServer.AddRestHandler("DELETE", "/usersessions/", m_userProfileManager.RestDeleteUserSessionMethod); | ||
101 | |||
102 | // I guess that this was never used? | ||
103 | //Listener.Prefixes.Add("http://+:8002/userserver/"); | ||
104 | |||
105 | httpServer.Start(); | ||
106 | } | ||
107 | |||
108 | |||
109 | public void do_create(string what) | ||
110 | { | ||
111 | switch (what) | ||
112 | { | ||
113 | case "user": | ||
114 | m_console.WriteLine("Creating new user profile"); | ||
115 | string tempfirstname; | ||
116 | string templastname; | ||
117 | string tempMD5Passwd; | ||
118 | |||
119 | tempfirstname = m_console.CmdPrompt("First name"); | ||
120 | templastname = m_console.CmdPrompt("Last name"); | ||
121 | tempMD5Passwd = m_console.PasswdPrompt("Password"); | ||
122 | |||
123 | System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider(); | ||
124 | byte[] bs = System.Text.Encoding.UTF8.GetBytes(tempMD5Passwd); | ||
125 | bs = x.ComputeHash(bs); | ||
126 | System.Text.StringBuilder s = new System.Text.StringBuilder(); | ||
127 | foreach (byte b in bs) | ||
128 | { | ||
129 | s.Append(b.ToString("x2").ToLower()); | ||
130 | } | ||
131 | tempMD5Passwd = s.ToString(); | ||
132 | |||
133 | UserProfile newuser = m_userProfileManager.CreateNewProfile(tempfirstname, templastname, tempMD5Passwd); | ||
134 | newuser.homelookat = new LLVector3(-0.57343f, -0.819255f, 0f); | ||
135 | newuser.homepos = new LLVector3(128f, 128f, 23f); | ||
136 | m_userProfileManager.SaveUserProfiles(); | ||
137 | break; | ||
76 | } | 138 | } |
77 | 139 | } | |
78 | private void Work() | 140 | |
79 | { | ||
80 | m_console.WriteLine("\nEnter help for a list of commands\n"); | ||
81 | |||
82 | while (true) | ||
83 | { | ||
84 | m_console.MainConsolePrompt(); | ||
85 | } | ||
86 | } | ||
87 | |||
88 | public void Startup() { | ||
89 | MainConsole.Instance.WriteLine("Main.cs:Startup() - Loading configuration"); | ||
90 | Cfg = this.LoadConfigDll(this.ConfigDll); | ||
91 | Cfg.InitConfig(); | ||
92 | |||
93 | MainConsole.Instance.WriteLine("Main.cs:Startup() - Creating user profile manager"); | ||
94 | _profilemanager = new UserProfileManager(); | ||
95 | _profilemanager.InitUserProfiles(); | ||
96 | _profilemanager.SetKeys(Cfg.GridSendKey, Cfg.GridRecvKey, Cfg.GridServerURL, Cfg.DefaultStartupMsg); | ||
97 | |||
98 | MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting HTTP process"); | ||
99 | _httpd = new UserHTTPServer(); | ||
100 | |||
101 | _httpd.AddXmlRPCHandler("login_to_simulator", _profilemanager.XmlRpcLoginMethod); | ||
102 | _httpd.AddRestHandler( "DELETE", "/usersessions/", _profilemanager.RestDeleteUserSessionMethod ); | ||
103 | |||
104 | _httpd.Start(); | ||
105 | |||
106 | } | ||
107 | |||
108 | |||
109 | public void do_create(string what) | ||
110 | { | ||
111 | switch(what) | ||
112 | { | ||
113 | case "user": | ||
114 | m_console.WriteLine("Creating new user profile"); | ||
115 | string tempfirstname; | ||
116 | string templastname; | ||
117 | string tempMD5Passwd; | ||
118 | |||
119 | tempfirstname=m_console.CmdPrompt("First name: "); | ||
120 | templastname=m_console.CmdPrompt("Last name: "); | ||
121 | tempMD5Passwd=m_console.PasswdPrompt("Password: "); | ||
122 | |||
123 | System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider(); | ||
124 | byte[] bs = System.Text.Encoding.UTF8.GetBytes(tempMD5Passwd); | ||
125 | bs = x.ComputeHash(bs); | ||
126 | System.Text.StringBuilder s = new System.Text.StringBuilder(); | ||
127 | foreach (byte b in bs) | ||
128 | { | ||
129 | s.Append(b.ToString("x2").ToLower()); | ||
130 | } | ||
131 | tempMD5Passwd = s.ToString(); | ||
132 | |||
133 | UserProfile newuser=_profilemanager.CreateNewProfile(tempfirstname,templastname,tempMD5Passwd); | ||
134 | newuser.homelookat = new LLVector3(-0.57343f, -0.819255f, 0f); | ||
135 | newuser.homepos = new LLVector3(128f,128f,23f); | ||
136 | _profilemanager.SaveUserProfiles(); | ||
137 | break; | ||
138 | } | ||
139 | } | ||
140 | |||
141 | public void RunCmd(string cmd, string[] cmdparams) | 141 | public void RunCmd(string cmd, string[] cmdparams) |
142 | { | 142 | { |
143 | switch (cmd) | 143 | switch (cmd) |
144 | { | 144 | { |
145 | case "help": | 145 | case "help": |
146 | m_console.WriteLine("create user - create a new user"); | 146 | m_console.WriteLine("create user - create a new user"); |
147 | m_console.WriteLine("shutdown - shutdown the grid (USE CAUTION!)"); | 147 | m_console.WriteLine("shutdown - shutdown the grid (USE CAUTION!)"); |
148 | break; | 148 | break; |
149 | 149 | ||
150 | case "create": | 150 | case "create": |
151 | do_create(cmdparams[0]); | 151 | do_create(cmdparams[0]); |
152 | break; | 152 | break; |
153 | 153 | ||
154 | case "shutdown": | 154 | case "shutdown": |
155 | m_console.Close(); | 155 | m_console.Close(); |
156 | Environment.Exit(0); | 156 | Environment.Exit(0); |
157 | break; | 157 | break; |
158 | } | 158 | } |
159 | } | 159 | } |
160 | 160 | ||
161 | private UserConfig LoadConfigDll(string dllName) | 161 | private UserConfig LoadConfigDll(string dllName) |
162 | { | 162 | { |
163 | Assembly pluginAssembly = Assembly.LoadFrom(dllName); | 163 | Assembly pluginAssembly = Assembly.LoadFrom(dllName); |
164 | UserConfig config = null; | 164 | UserConfig config = null; |
@@ -185,9 +185,9 @@ namespace OpenGridServices.UserServer | |||
185 | pluginAssembly = null; | 185 | pluginAssembly = null; |
186 | return config; | 186 | return config; |
187 | } | 187 | } |
188 | 188 | ||
189 | public void Show(string ShowWhat) | 189 | public void Show(string ShowWhat) |
190 | { | 190 | { |
191 | } | 191 | } |
192 | } | 192 | } |
193 | } | 193 | } |
diff --git a/OpenGridServices.UserServer/OpenGridServices.UserServer.csproj b/OpenGridServices.UserServer/OpenGridServices.UserServer.csproj index a9b7185..fcf6362 100644 --- a/OpenGridServices.UserServer/OpenGridServices.UserServer.csproj +++ b/OpenGridServices.UserServer/OpenGridServices.UserServer.csproj | |||
@@ -103,9 +103,6 @@ | |||
103 | <Compile Include="Main.cs"> | 103 | <Compile Include="Main.cs"> |
104 | <SubType>Code</SubType> | 104 | <SubType>Code</SubType> |
105 | </Compile> | 105 | </Compile> |
106 | <Compile Include="UserHttp.cs"> | ||
107 | <SubType>Code</SubType> | ||
108 | </Compile> | ||
109 | <Compile Include="Properties\AssemblyInfo.cs"> | 106 | <Compile Include="Properties\AssemblyInfo.cs"> |
110 | <SubType>Code</SubType> | 107 | <SubType>Code</SubType> |
111 | </Compile> | 108 | </Compile> |
diff --git a/OpenGridServices.UserServer/OpenGridServices.UserServer.exe.build b/OpenGridServices.UserServer/OpenGridServices.UserServer.exe.build index a4bccb8..6319d9e 100644 --- a/OpenGridServices.UserServer/OpenGridServices.UserServer.exe.build +++ b/OpenGridServices.UserServer/OpenGridServices.UserServer.exe.build | |||
@@ -12,7 +12,6 @@ | |||
12 | </resources> | 12 | </resources> |
13 | <sources failonempty="true"> | 13 | <sources failonempty="true"> |
14 | <include name="Main.cs" /> | 14 | <include name="Main.cs" /> |
15 | <include name="UserHttp.cs" /> | ||
16 | <include name="Properties/AssemblyInfo.cs" /> | 15 | <include name="Properties/AssemblyInfo.cs" /> |
17 | </sources> | 16 | </sources> |
18 | <references basedir="${project::get-base-directory()}"> | 17 | <references basedir="${project::get-base-directory()}"> |
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 | /* | ||
2 | Copyright (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 | |||
30 | using System; | ||
31 | using System.Text; | ||
32 | using Nwc.XmlRpc; | ||
33 | using System.Threading; | ||
34 | using System.Text.RegularExpressions; | ||
35 | using System.Net; | ||
36 | using System.IO; | ||
37 | using System.Collections; | ||
38 | using System.Collections.Generic; | ||
39 | using libsecondlife; | ||
40 | using OpenSim.Framework.User; | ||
41 | using OpenSim.Framework.Sims; | ||
42 | using OpenSim.Framework.Inventory; | ||
43 | using OpenSim.Framework.Console; | ||
44 | using OpenSim.Servers; | ||
45 | |||
46 | namespace 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 | } | ||