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