diff options
Diffstat (limited to 'OpenSim/Region/Environment/Modules/ScriptsHttpRequests.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/ScriptsHttpRequests.cs | 260 |
1 files changed, 127 insertions, 133 deletions
diff --git a/OpenSim/Region/Environment/Modules/ScriptsHttpRequests.cs b/OpenSim/Region/Environment/Modules/ScriptsHttpRequests.cs index d47004b..f8798dc 100644 --- a/OpenSim/Region/Environment/Modules/ScriptsHttpRequests.cs +++ b/OpenSim/Region/Environment/Modules/ScriptsHttpRequests.cs | |||
@@ -27,18 +27,15 @@ | |||
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | ||
30 | using System.IO; | 31 | using System.IO; |
31 | using System.Net; | 32 | using System.Net; |
32 | using System.Text; | 33 | using System.Text; |
33 | using OpenSim.Region.Environment.Interfaces; | ||
34 | using OpenSim.Region.Environment.Scenes; | ||
35 | using System.Collections; | ||
36 | using System.Collections.Generic; | ||
37 | using System.Threading; | 34 | using System.Threading; |
38 | using libsecondlife; | 35 | using libsecondlife; |
39 | using Nini.Config; | 36 | using Nini.Config; |
40 | using Nwc.XmlRpc; | 37 | using OpenSim.Region.Environment.Interfaces; |
41 | using OpenSim.Framework.Servers; | 38 | using OpenSim.Region.Environment.Scenes; |
42 | 39 | ||
43 | /***************************************************** | 40 | /***************************************************** |
44 | * | 41 | * |
@@ -85,120 +82,120 @@ using OpenSim.Framework.Servers; | |||
85 | 82 | ||
86 | namespace OpenSim.Region.Environment.Modules | 83 | namespace OpenSim.Region.Environment.Modules |
87 | { | 84 | { |
88 | public class ScriptHTTPRequests : IRegionModule, IHttpRequests | 85 | public class ScriptHTTPRequests : IRegionModule, IHttpRequests |
89 | { | 86 | { |
90 | private Scene m_scene; | 87 | private Scene m_scene; |
91 | private Queue<HttpRequestClass> rpcQueue = new Queue<HttpRequestClass>(); | 88 | private Queue<HttpRequestClass> rpcQueue = new Queue<HttpRequestClass>(); |
92 | private object HttpListLock = new object(); | 89 | private object HttpListLock = new object(); |
93 | private string m_name = "HttpScriptRequests"; | 90 | private string m_name = "HttpScriptRequests"; |
94 | private int httpTimeout = 300; | 91 | private int httpTimeout = 300; |
95 | 92 | ||
96 | // <request id, HttpRequestClass> | 93 | // <request id, HttpRequestClass> |
97 | private Dictionary<LLUUID, HttpRequestClass> m_pendingRequests; | 94 | private Dictionary<LLUUID, HttpRequestClass> m_pendingRequests; |
98 | 95 | ||
99 | public ScriptHTTPRequests() | 96 | public ScriptHTTPRequests() |
100 | { | 97 | { |
101 | } | 98 | } |
102 | 99 | ||
103 | public void Initialise(Scene scene, IConfigSource config) | 100 | public void Initialise(Scene scene, IConfigSource config) |
104 | { | 101 | { |
105 | m_scene = scene; | 102 | m_scene = scene; |
106 | 103 | ||
107 | m_scene.RegisterModuleInterface<IHttpRequests>(this); | 104 | m_scene.RegisterModuleInterface<IHttpRequests>(this); |
108 | 105 | ||
109 | m_pendingRequests = new Dictionary<LLUUID, HttpRequestClass>(); | 106 | m_pendingRequests = new Dictionary<LLUUID, HttpRequestClass>(); |
110 | } | 107 | } |
111 | 108 | ||
112 | public void PostInitialise() | 109 | public void PostInitialise() |
113 | { | 110 | { |
114 | } | 111 | } |
115 | 112 | ||
116 | public void Close() | 113 | public void Close() |
117 | { | 114 | { |
118 | } | 115 | } |
119 | 116 | ||
120 | public string Name | 117 | public string Name |
121 | { | 118 | { |
122 | get { return m_name; } | 119 | get { return m_name; } |
123 | } | 120 | } |
124 | 121 | ||
125 | public bool IsSharedModule | 122 | public bool IsSharedModule |
126 | { | 123 | { |
127 | get { return true; } | 124 | get { return true; } |
128 | } | 125 | } |
129 | 126 | ||
130 | public LLUUID MakeHttpRequest(string url, string parameters, string body) { | 127 | public LLUUID MakeHttpRequest(string url, string parameters, string body) |
131 | return LLUUID.Zero; | 128 | { |
132 | } | 129 | return LLUUID.Zero; |
133 | 130 | } | |
134 | public LLUUID StartHttpRequest(uint localID, LLUUID itemID, string url, List<string> parameters, string body) | 131 | |
135 | { | 132 | public LLUUID StartHttpRequest(uint localID, LLUUID itemID, string url, List<string> parameters, string body) |
136 | LLUUID reqID = LLUUID.Random(); | 133 | { |
137 | HttpRequestClass htc = new HttpRequestClass(); | 134 | LLUUID reqID = LLUUID.Random(); |
138 | 135 | HttpRequestClass htc = new HttpRequestClass(); | |
139 | // Parameters are expected in {key, value, ... , key, value} | 136 | |
140 | if( parameters != null ) | 137 | // Parameters are expected in {key, value, ... , key, value} |
141 | { | 138 | if (parameters != null) |
142 | string[] parms = parameters.ToArray(); | 139 | { |
143 | for (int i = 0; i < parms.Length / 2; i += 2) | 140 | string[] parms = parameters.ToArray(); |
141 | for (int i = 0; i < parms.Length/2; i += 2) | ||
144 | { | 142 | { |
145 | switch( Int32.Parse(parms[i]) ) | 143 | switch (Int32.Parse(parms[i])) |
146 | { | 144 | { |
147 | case HttpRequestClass.HTTP_METHOD: | 145 | case HttpRequestClass.HTTP_METHOD: |
148 | 146 | ||
149 | htc.httpMethod = parms[i + 1]; | 147 | htc.httpMethod = parms[i + 1]; |
150 | break; | 148 | break; |
151 | 149 | ||
152 | case HttpRequestClass.HTTP_MIMETYPE: | 150 | case HttpRequestClass.HTTP_MIMETYPE: |
153 | 151 | ||
154 | htc.httpMIMEType = parms[i + 1]; | 152 | htc.httpMIMEType = parms[i + 1]; |
155 | break; | 153 | break; |
156 | 154 | ||
157 | case HttpRequestClass.HTTP_BODY_MAXLENGTH: | 155 | case HttpRequestClass.HTTP_BODY_MAXLENGTH: |
158 | 156 | ||
159 | // TODO implement me | 157 | // TODO implement me |
160 | break; | 158 | break; |
161 | 159 | ||
162 | case HttpRequestClass.HTTP_VERIFY_CERT: | 160 | case HttpRequestClass.HTTP_VERIFY_CERT: |
163 | 161 | ||
164 | // TODO implement me | 162 | // TODO implement me |
165 | break; | 163 | break; |
166 | } | 164 | } |
167 | } | 165 | } |
168 | } | 166 | } |
169 | 167 | ||
170 | htc.localID = localID; | 168 | htc.localID = localID; |
171 | htc.itemID = itemID; | 169 | htc.itemID = itemID; |
172 | htc.url = url; | 170 | htc.url = url; |
173 | htc.reqID = reqID; | 171 | htc.reqID = reqID; |
174 | htc.httpTimeout = httpTimeout; | 172 | htc.httpTimeout = httpTimeout; |
175 | htc.outbound_body = body; | 173 | htc.outbound_body = body; |
176 | 174 | ||
177 | lock (HttpListLock) | 175 | lock (HttpListLock) |
178 | { | 176 | { |
179 | m_pendingRequests.Add(reqID, htc); | 177 | m_pendingRequests.Add(reqID, htc); |
180 | } | 178 | } |
181 | 179 | ||
182 | htc.process(); | 180 | htc.process(); |
183 | 181 | ||
184 | return reqID; | 182 | return reqID; |
185 | } | 183 | } |
186 | 184 | ||
187 | public void StopHttpRequest(uint m_localID, LLUUID m_itemID) | 185 | public void StopHttpRequest(uint m_localID, LLUUID m_itemID) |
188 | { | 186 | { |
189 | lock (HttpListLock) | 187 | lock (HttpListLock) |
190 | { | 188 | { |
191 | 189 | HttpRequestClass tmpReq; | |
192 | HttpRequestClass tmpReq; | 190 | if (m_pendingRequests.TryGetValue(m_itemID, out tmpReq)) |
193 | if (m_pendingRequests.TryGetValue(m_itemID, out tmpReq)) | 191 | { |
194 | { | 192 | tmpReq.Stop(); |
195 | tmpReq.Stop(); | 193 | m_pendingRequests.Remove(m_itemID); |
196 | m_pendingRequests.Remove(m_itemID); | 194 | } |
197 | } | 195 | } |
198 | } | 196 | } |
199 | } | 197 | |
200 | 198 | /* | |
201 | /* | ||
202 | * TODO | 199 | * TODO |
203 | * Not sure how important ordering is is here - the next first | 200 | * Not sure how important ordering is is here - the next first |
204 | * one completed in the list is returned, based soley on its list | 201 | * one completed in the list is returned, based soley on its list |
@@ -206,10 +203,11 @@ namespace OpenSim.Region.Environment.Modules | |||
206 | * finsihed. I thought about setting up a queue for this, but | 203 | * finsihed. I thought about setting up a queue for this, but |
207 | * it will need some refactoring and this works 'enough' right now | 204 | * it will need some refactoring and this works 'enough' right now |
208 | */ | 205 | */ |
209 | public HttpRequestClass GetNextCompletedRequest() | 206 | |
210 | { | 207 | public HttpRequestClass GetNextCompletedRequest() |
211 | lock (HttpListLock) | 208 | { |
212 | { | 209 | lock (HttpListLock) |
210 | { | ||
213 | foreach (LLUUID luid in m_pendingRequests.Keys) | 211 | foreach (LLUUID luid in m_pendingRequests.Keys) |
214 | { | 212 | { |
215 | HttpRequestClass tmpReq; | 213 | HttpRequestClass tmpReq; |
@@ -225,18 +223,16 @@ namespace OpenSim.Region.Environment.Modules | |||
225 | } | 223 | } |
226 | } | 224 | } |
227 | return null; | 225 | return null; |
228 | } | 226 | } |
229 | 227 | } | |
230 | |||
231 | } | ||
232 | 228 | ||
233 | // | 229 | // |
234 | // HTTP REAQUEST | 230 | // HTTP REAQUEST |
235 | // This class was originally in LSLLongCmdHandler | 231 | // This class was originally in LSLLongCmdHandler |
236 | // | 232 | // |
237 | // TODO: setter/getter methods, maybe pass some in | 233 | // TODO: setter/getter methods, maybe pass some in |
238 | // constructor | 234 | // constructor |
239 | // | 235 | // |
240 | 236 | ||
241 | public class HttpRequestClass | 237 | public class HttpRequestClass |
242 | { | 238 | { |
@@ -280,9 +276,9 @@ namespace OpenSim.Region.Environment.Modules | |||
280 | * TODO: More work on the response codes. Right now | 276 | * TODO: More work on the response codes. Right now |
281 | * returning 200 for success or 499 for exception | 277 | * returning 200 for success or 499 for exception |
282 | */ | 278 | */ |
279 | |||
283 | public void SendRequest() | 280 | public void SendRequest() |
284 | { | 281 | { |
285 | |||
286 | HttpWebResponse response = null; | 282 | HttpWebResponse response = null; |
287 | StringBuilder sb = new StringBuilder(); | 283 | StringBuilder sb = new StringBuilder(); |
288 | byte[] buf = new byte[8192]; | 284 | byte[] buf = new byte[8192]; |
@@ -292,14 +288,14 @@ namespace OpenSim.Region.Environment.Modules | |||
292 | try | 288 | try |
293 | { | 289 | { |
294 | request = (HttpWebRequest) | 290 | request = (HttpWebRequest) |
295 | WebRequest.Create(url); | 291 | WebRequest.Create(url); |
296 | request.Method = httpMethod; | 292 | request.Method = httpMethod; |
297 | request.ContentType = httpMIMEType; | 293 | request.ContentType = httpMIMEType; |
298 | 294 | ||
299 | request.Timeout = httpTimeout; | 295 | request.Timeout = httpTimeout; |
300 | // execute the request | 296 | // execute the request |
301 | response = (HttpWebResponse) | 297 | response = (HttpWebResponse) |
302 | request.GetResponse(); | 298 | request.GetResponse(); |
303 | 299 | ||
304 | Stream resStream = response.GetResponseStream(); | 300 | Stream resStream = response.GetResponseStream(); |
305 | 301 | ||
@@ -317,11 +313,9 @@ namespace OpenSim.Region.Environment.Modules | |||
317 | // continue building the string | 313 | // continue building the string |
318 | sb.Append(tempString); | 314 | sb.Append(tempString); |
319 | } | 315 | } |
320 | } | 316 | } while (count > 0); // any more data to read? |
321 | while (count > 0); // any more data to read? | ||
322 | 317 | ||
323 | response_body = sb.ToString(); | 318 | response_body = sb.ToString(); |
324 | |||
325 | } | 319 | } |
326 | catch (Exception e) | 320 | catch (Exception e) |
327 | { | 321 | { |
@@ -333,7 +327,6 @@ namespace OpenSim.Region.Environment.Modules | |||
333 | 327 | ||
334 | status = 200; | 328 | status = 200; |
335 | finished = true; | 329 | finished = true; |
336 | |||
337 | } | 330 | } |
338 | 331 | ||
339 | public void Stop() | 332 | public void Stop() |
@@ -342,8 +335,9 @@ namespace OpenSim.Region.Environment.Modules | |||
342 | { | 335 | { |
343 | httpThread.Abort(); | 336 | httpThread.Abort(); |
344 | } | 337 | } |
345 | catch (Exception) { } | 338 | catch (Exception) |
339 | { | ||
340 | } | ||
346 | } | 341 | } |
347 | } | 342 | } |
348 | 343 | } \ No newline at end of file | |
349 | } \ No newline at end of file | ||