aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Scripting/HttpRequest
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Scripting/HttpRequest')
-rw-r--r--OpenSim/Region/Environment/Modules/Scripting/HttpRequest/ScriptsHttpRequests.cs183
1 files changed, 100 insertions, 83 deletions
diff --git a/OpenSim/Region/Environment/Modules/Scripting/HttpRequest/ScriptsHttpRequests.cs b/OpenSim/Region/Environment/Modules/Scripting/HttpRequest/ScriptsHttpRequests.cs
index eb9b322..821c60e 100644
--- a/OpenSim/Region/Environment/Modules/Scripting/HttpRequest/ScriptsHttpRequests.cs
+++ b/OpenSim/Region/Environment/Modules/Scripting/HttpRequest/ScriptsHttpRequests.cs
@@ -35,8 +35,8 @@ using OpenMetaverse;
35using Nini.Config; 35using Nini.Config;
36using OpenSim.Framework; 36using OpenSim.Framework;
37using OpenSim.Framework.Servers; 37using OpenSim.Framework.Servers;
38using OpenSim.Region.Environment.Interfaces; 38using OpenSim.Region.Framework.Interfaces;
39using OpenSim.Region.Environment.Scenes; 39using OpenSim.Region.Framework.Scenes;
40using System.Collections; 40using System.Collections;
41 41
42/***************************************************** 42/*****************************************************
@@ -84,14 +84,14 @@ using System.Collections;
84 84
85namespace OpenSim.Region.Environment.Modules.Scripting.HttpRequest 85namespace OpenSim.Region.Environment.Modules.Scripting.HttpRequest
86{ 86{
87 public class HttpRequestModule : IRegionModule, IHttpRequests 87 public class HttpRequestModule : IRegionModule, IHttpRequestModule
88 { 88 {
89 private object HttpListLock = new object(); 89 private object HttpListLock = new object();
90 private int httpTimeout = 30000; 90 private int httpTimeout = 30000;
91 private string m_name = "HttpScriptRequests"; 91 private string m_name = "HttpScriptRequests";
92 92
93 private string m_proxyurl = ""; 93 private string m_proxyurl = "";
94 private string m_proxyexcepts = ""; 94 private string m_proxyexcepts = "";
95 95
96 // <request id, HttpRequestClass> 96 // <request id, HttpRequestClass>
97 private Dictionary<UUID, HttpRequestClass> m_pendingRequests; 97 private Dictionary<UUID, HttpRequestClass> m_pendingRequests;
@@ -102,7 +102,7 @@ namespace OpenSim.Region.Environment.Modules.Scripting.HttpRequest
102 { 102 {
103 } 103 }
104 104
105 #region IHttpRequests Members 105 #region IHttpRequestModule Members
106 106
107 public UUID MakeHttpRequest(string url, string parameters, string body) 107 public UUID MakeHttpRequest(string url, string parameters, string body)
108 { 108 {
@@ -125,22 +125,22 @@ namespace OpenSim.Region.Environment.Modules.Scripting.HttpRequest
125 { 125 {
126 switch (Int32.Parse(parms[i])) 126 switch (Int32.Parse(parms[i]))
127 { 127 {
128 case HttpRequestClass.HTTP_METHOD: 128 case (int)HttpRequestConstants.HTTP_METHOD:
129 129
130 htc.httpMethod = parms[i + 1]; 130 htc.HttpMethod = parms[i + 1];
131 break; 131 break;
132 132
133 case HttpRequestClass.HTTP_MIMETYPE: 133 case (int)HttpRequestConstants.HTTP_MIMETYPE:
134 134
135 htc.httpMIMEType = parms[i + 1]; 135 htc.HttpMIMEType = parms[i + 1];
136 break; 136 break;
137 137
138 case HttpRequestClass.HTTP_BODY_MAXLENGTH: 138 case (int)HttpRequestConstants.HTTP_BODY_MAXLENGTH:
139 139
140 // TODO implement me 140 // TODO implement me
141 break; 141 break;
142 142
143 case HttpRequestClass.HTTP_VERIFY_CERT: 143 case (int)HttpRequestConstants.HTTP_VERIFY_CERT:
144 144
145 // TODO implement me 145 // TODO implement me
146 break; 146 break;
@@ -148,22 +148,22 @@ namespace OpenSim.Region.Environment.Modules.Scripting.HttpRequest
148 } 148 }
149 } 149 }
150 150
151 htc.localID = localID; 151 htc.LocalID = localID;
152 htc.itemID = itemID; 152 htc.ItemID = itemID;
153 htc.url = url; 153 htc.Url = url;
154 htc.reqID = reqID; 154 htc.ReqID = reqID;
155 htc.httpTimeout = httpTimeout; 155 htc.HttpTimeout = httpTimeout;
156 htc.outbound_body = body; 156 htc.OutboundBody = body;
157 htc.response_headers = headers; 157 htc.ResponseHeaders = headers;
158 htc.proxyurl = m_proxyurl; 158 htc.proxyurl = m_proxyurl;
159 htc.proxyexcepts = m_proxyexcepts; 159 htc.proxyexcepts = m_proxyexcepts;
160 160
161 lock (HttpListLock) 161 lock (HttpListLock)
162 { 162 {
163 m_pendingRequests.Add(reqID, htc); 163 m_pendingRequests.Add(reqID, htc);
164 } 164 }
165 165
166 htc.process(); 166 htc.Process();
167 167
168 return reqID; 168 return reqID;
169 } 169 }
@@ -193,7 +193,7 @@ namespace OpenSim.Region.Environment.Modules.Scripting.HttpRequest
193 * it will need some refactoring and this works 'enough' right now 193 * it will need some refactoring and this works 'enough' right now
194 */ 194 */
195 195
196 public HttpRequestClass GetNextCompletedRequest() 196 public IServiceRequest GetNextCompletedRequest()
197 { 197 {
198 lock (HttpListLock) 198 lock (HttpListLock)
199 { 199 {
@@ -203,7 +203,7 @@ namespace OpenSim.Region.Environment.Modules.Scripting.HttpRequest
203 203
204 if (m_pendingRequests.TryGetValue(luid, out tmpReq)) 204 if (m_pendingRequests.TryGetValue(luid, out tmpReq))
205 { 205 {
206 if (tmpReq.finished) 206 if (tmpReq.Finished)
207 { 207 {
208 return tmpReq; 208 return tmpReq;
209 } 209 }
@@ -235,10 +235,10 @@ namespace OpenSim.Region.Environment.Modules.Scripting.HttpRequest
235 { 235 {
236 m_scene = scene; 236 m_scene = scene;
237 237
238 m_scene.RegisterModuleInterface<IHttpRequests>(this); 238 m_scene.RegisterModuleInterface<IHttpRequestModule>(this);
239 239
240 m_proxyurl = config.Configs["Startup"].GetString("HttpProxy"); 240 m_proxyurl = config.Configs["Startup"].GetString("HttpProxy");
241 m_proxyexcepts = config.Configs["Startup"].GetString("HttpProxyExceptions"); 241 m_proxyexcepts = config.Configs["Startup"].GetString("HttpProxyExceptions");
242 242
243 m_pendingRequests = new Dictionary<UUID, HttpRequestClass>(); 243 m_pendingRequests = new Dictionary<UUID, HttpRequestClass>();
244 } 244 }
@@ -264,45 +264,64 @@ namespace OpenSim.Region.Environment.Modules.Scripting.HttpRequest
264 #endregion 264 #endregion
265 } 265 }
266 266
267 public class HttpRequestClass 267 public class HttpRequestClass: IServiceRequest
268 { 268 {
269 // Constants for parameters 269 // Constants for parameters
270 public const int HTTP_BODY_MAXLENGTH = 2; 270 // public const int HTTP_BODY_MAXLENGTH = 2;
271 public const int HTTP_METHOD = 0; 271 // public const int HTTP_METHOD = 0;
272 public const int HTTP_MIMETYPE = 1; 272 // public const int HTTP_MIMETYPE = 1;
273 public const int HTTP_VERIFY_CERT = 3; 273 // public const int HTTP_VERIFY_CERT = 3;
274 public bool finished; 274 private bool _finished;
275 public int httpBodyMaxLen = 2048; // not implemented 275 public bool Finished
276 {
277 get { return _finished; }
278 }
279 // public int HttpBodyMaxLen = 2048; // not implemented
276 280
277 // Parameter members and default values 281 // Parameter members and default values
278 public string httpMethod = "GET"; 282 public string HttpMethod = "GET";
279 public string httpMIMEType = "text/plain;charset=utf-8"; 283 public string HttpMIMEType = "text/plain;charset=utf-8";
284 public int HttpTimeout;
285 // public bool HttpVerifyCert = true; // not implemented
280 private Thread httpThread; 286 private Thread httpThread;
281 public int httpTimeout;
282 public bool httpVerifyCert = true; // not implemented
283 287
284 // Request info 288 // Request info
285 public UUID itemID; 289 private UUID _itemID;
286 public uint localID; 290 public UUID ItemID
287 public DateTime next; 291 {
288 public string outbound_body; 292 get { return _itemID; }
289 public UUID reqID; 293 set { _itemID = value; }
290 public HttpWebRequest request; 294 }
291 public string response_body; 295 private uint _localID;
292 public List<string> response_metadata; 296 public uint LocalID
293 public Dictionary<string, string> response_headers; 297 {
294 public int status; 298 get { return _localID; }
295 public string url; 299 set { _localID = value; }
300 }
301 public DateTime Next;
296 public string proxyurl; 302 public string proxyurl;
297 public string proxyexcepts; 303 public string proxyexcepts;
298 304 public string OutboundBody;
299 public void process() 305 private UUID _reqID;
306 public UUID ReqID
307 {
308 get { return _reqID; }
309 set { _reqID = value; }
310 }
311 public HttpWebRequest Request;
312 public string ResponseBody;
313 public List<string> ResponseMetadata;
314 public Dictionary<string, string> ResponseHeaders;
315 public int Status;
316 public string Url;
317
318 public void Process()
300 { 319 {
301 httpThread = new Thread(SendRequest); 320 httpThread = new Thread(SendRequest);
302 httpThread.Name = "HttpRequestThread"; 321 httpThread.Name = "HttpRequestThread";
303 httpThread.Priority = ThreadPriority.BelowNormal; 322 httpThread.Priority = ThreadPriority.BelowNormal;
304 httpThread.IsBackground = true; 323 httpThread.IsBackground = true;
305 finished = false; 324 _finished = false;
306 httpThread.Start(); 325 httpThread.Start();
307 ThreadTracker.Add(httpThread); 326 ThreadTracker.Add(httpThread);
308 } 327 }
@@ -322,37 +341,35 @@ namespace OpenSim.Region.Environment.Modules.Scripting.HttpRequest
322 341
323 try 342 try
324 { 343 {
325 request = (HttpWebRequest) 344 Request = (HttpWebRequest) WebRequest.Create(Url);
326 WebRequest.Create(url); 345 Request.Method = HttpMethod;
327 request.Method = httpMethod; 346 Request.ContentType = HttpMIMEType;
328 request.ContentType = httpMIMEType; 347 if (proxyurl.Length > 0)
329 if (proxyurl.Length > 0) 348 {
330 { 349 if (proxyexcepts.Length > 0) {
331 if (proxyexcepts.Length > 0) { 350 string[] elist = proxyexcepts.Split(';');
332 string[] elist = proxyexcepts.Split(';'); 351 Request.Proxy = new WebProxy(proxyurl,true,elist);
333 request.Proxy = new WebProxy(proxyurl,true,elist); 352 } else {
334 } else { 353 Request.Proxy = new WebProxy(proxyurl,true);
335 request.Proxy = new WebProxy(proxyurl,true); 354 }
336 } 355 }
337 } 356
338 357 foreach (KeyValuePair<string, string> entry in ResponseHeaders)
339 foreach (KeyValuePair<string, string> entry in response_headers) 358 Request.Headers[entry.Key] = entry.Value;
340 request.Headers[entry.Key] = entry.Value;
341 359
342 // Encode outbound data 360 // Encode outbound data
343 if (outbound_body.Length > 0) { 361 if (OutboundBody.Length > 0) {
344 byte[] data = Encoding.UTF8.GetBytes(outbound_body); 362 byte[] data = Encoding.UTF8.GetBytes(OutboundBody);
345 363
346 request.ContentLength = data.Length; 364 Request.ContentLength = data.Length;
347 Stream bstream = request.GetRequestStream(); 365 Stream bstream = Request.GetRequestStream();
348 bstream.Write(data, 0, data.Length); 366 bstream.Write(data, 0, data.Length);
349 bstream.Close(); 367 bstream.Close();
350 } 368 }
351 369
352 request.Timeout = httpTimeout; 370 Request.Timeout = HttpTimeout;
353 // execute the request 371 // execute the request
354 response = (HttpWebResponse) 372 response = (HttpWebResponse) Request.GetResponse();
355 request.GetResponse();
356 373
357 Stream resStream = response.GetResponseStream(); 374 Stream resStream = response.GetResponseStream();
358 375
@@ -372,23 +389,23 @@ namespace OpenSim.Region.Environment.Modules.Scripting.HttpRequest
372 } 389 }
373 } while (count > 0); // any more data to read? 390 } while (count > 0); // any more data to read?
374 391
375 response_body = sb.ToString(); 392 ResponseBody = sb.ToString();
376 } 393 }
377 catch (Exception e) 394 catch (Exception e)
378 { 395 {
379 if (e is WebException && ((WebException)e).Status == WebExceptionStatus.ProtocolError) 396 if (e is WebException && ((WebException)e).Status == WebExceptionStatus.ProtocolError)
380 { 397 {
381 HttpWebResponse webRsp = (HttpWebResponse)((WebException)e).Response; 398 HttpWebResponse webRsp = (HttpWebResponse)((WebException)e).Response;
382 status = (int)webRsp.StatusCode; 399 Status = (int)webRsp.StatusCode;
383 response_body = webRsp.StatusDescription; 400 ResponseBody = webRsp.StatusDescription;
384 } 401 }
385 else 402 else
386 { 403 {
387 status = (int)OSHttpStatusCode.ClientErrorJoker; 404 Status = (int)OSHttpStatusCode.ClientErrorJoker;
388 response_body = e.Message; 405 ResponseBody = e.Message;
389 } 406 }
390 407
391 finished = true; 408 _finished = true;
392 return; 409 return;
393 } 410 }
394 finally 411 finally
@@ -397,8 +414,8 @@ namespace OpenSim.Region.Environment.Modules.Scripting.HttpRequest
397 response.Close(); 414 response.Close();
398 } 415 }
399 416
400 status = (int)OSHttpStatusCode.SuccessOk; 417 Status = (int)OSHttpStatusCode.SuccessOk;
401 finished = true; 418 _finished = true;
402 } 419 }
403 420
404 public void Stop() 421 public void Stop()