aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs
diff options
context:
space:
mode:
authorMelanie Thielker2009-05-13 04:04:26 +0000
committerMelanie Thielker2009-05-13 04:04:26 +0000
commit1196f3eac7d7b72907fa42a6320c5263e3e46abe (patch)
tree2ae6ef21464b645defc26c85131bf3662db065a6 /OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs
parentPlumb request and return URL functions. (diff)
downloadopensim-SC_OLD-1196f3eac7d7b72907fa42a6320c5263e3e46abe.zip
opensim-SC_OLD-1196f3eac7d7b72907fa42a6320c5263e3e46abe.tar.gz
opensim-SC_OLD-1196f3eac7d7b72907fa42a6320c5263e3e46abe.tar.bz2
opensim-SC_OLD-1196f3eac7d7b72907fa42a6320c5263e3e46abe.tar.xz
Add most of the meat to the LSL HTTP server
Diffstat (limited to 'OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs')
-rw-r--r--OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs134
1 files changed, 123 insertions, 11 deletions
diff --git a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs
index a79975c..1fff71e 100644
--- a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs
@@ -26,11 +26,14 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Threading;
29using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Collections;
30using System.Reflection; 32using System.Reflection;
31using log4net; 33using log4net;
32using Nini.Config; 34using Nini.Config;
33using OpenMetaverse; 35using OpenMetaverse;
36using OpenSim.Framework.Servers.HttpServer;
34using OpenSim.Region.Framework.Interfaces; 37using OpenSim.Region.Framework.Interfaces;
35using OpenSim.Region.Framework.Scenes; 38using OpenSim.Region.Framework.Scenes;
36 39
@@ -40,17 +43,18 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
40 { 43 {
41 public UUID hostID; 44 public UUID hostID;
42 public UUID itemID; 45 public UUID itemID;
43 Scene scene; 46 public IScriptModule engine;
44 IScriptModule engine; 47 public string url;
45 string url; 48 public UUID urlcode;
46 Dictionary<UUID, RequestData> requests; 49 public Dictionary<UUID, RequestData> requests;
47 } 50 }
48 51
49 public class RequestData 52 public class RequestData
50 { 53 {
51 UUID requestID; 54 public UUID requestID;
52 Dictionary<string, string> headers; 55 public Dictionary<string, string> headers;
53 string body; 56 public string body;
57 public ManualResetEvent ev;
54 } 58 }
55 59
56 public class UrlModule : ISharedRegionModule, IUrlModule 60 public class UrlModule : ISharedRegionModule, IUrlModule
@@ -61,7 +65,9 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
61 private Dictionary<string, UrlData> m_UrlMap = 65 private Dictionary<string, UrlData> m_UrlMap =
62 new Dictionary<string, UrlData>(); 66 new Dictionary<string, UrlData>();
63 67
64 private int m_TotalUrls = 0; 68 private int m_TotalUrls = 100;
69
70 private IHttpServer m_HttpServer = null;
65 71
66 public string Name 72 public string Name
67 { 73 {
@@ -78,6 +84,12 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
78 84
79 public void AddRegion(Scene scene) 85 public void AddRegion(Scene scene)
80 { 86 {
87 if (m_HttpServer == null)
88 {
89 // There can only be one
90 //
91 m_HttpServer = scene.CommsManager.HttpServer;
92 }
81 } 93 }
82 94
83 public void RegionLoaded(Scene scene) 95 public void RegionLoaded(Scene scene)
@@ -94,16 +106,59 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
94 106
95 public UUID RequestURL(IScriptModule engine, SceneObjectPart host, UUID itemID) 107 public UUID RequestURL(IScriptModule engine, SceneObjectPart host, UUID itemID)
96 { 108 {
97 return UUID.Zero; 109 UUID urlcode = UUID.Random();
110
111 lock (m_UrlMap)
112 {
113 if (m_UrlMap.Count >= m_TotalUrls)
114 {
115 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
116 return urlcode;
117 }
118 string url = "http://"+System.Environment.MachineName+"/"+urlcode.ToString();
119
120 UrlData urlData = new UrlData();
121 urlData.hostID = host.UUID;
122 urlData.itemID = itemID;
123 urlData.engine = engine;
124 urlData.url = url;
125 urlData.urlcode = urlcode;
126 urlData.requests = new Dictionary<UUID, RequestData>();
127
128 m_UrlMap[url] = urlData;
129
130 m_HttpServer.AddHTTPHandler("/lslhttp/"+urlcode.ToString(), HttpRequestHandler);
131
132 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url });
133 }
134
135 return urlcode;
98 } 136 }
99 137
100 public UUID RequestSecureURL(IScriptModule engine, SceneObjectPart host, UUID itemID) 138 public UUID RequestSecureURL(IScriptModule engine, SceneObjectPart host, UUID itemID)
101 { 139 {
102 return UUID.Zero; 140 UUID urlcode = UUID.Random();
141
142 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
143
144 return urlcode;
103 } 145 }
104 146
105 public void ReleaseURL(string url) 147 public void ReleaseURL(string url)
106 { 148 {
149 lock (m_UrlMap)
150 {
151 UrlData data;
152
153 if (!m_UrlMap.TryGetValue(url, out data))
154 return;
155
156 foreach (UUID req in data.requests.Keys)
157 m_RequestMap.Remove(req);
158
159 RemoveUrl(data);
160 m_UrlMap.Remove(url);
161 }
107 } 162 }
108 163
109 public void HttpResponse(UUID request, int status, string body) 164 public void HttpResponse(UUID request, int status, string body)
@@ -117,7 +172,64 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
117 172
118 public int GetFreeUrls() 173 public int GetFreeUrls()
119 { 174 {
120 return 0; 175 return m_TotalUrls - m_UrlMap.Count;
176 }
177
178 public void ScriptRemoved(UUID itemID)
179 {
180 lock(m_UrlMap)
181 {
182 List<string> removeURLs = new List<string>();
183
184 foreach(KeyValuePair<string, UrlData> url in m_UrlMap)
185 {
186 if (url.Value.itemID == itemID)
187 {
188 RemoveUrl(url.Value);
189 removeURLs.Add(url.Key);
190 foreach (UUID req in url.Value.requests.Keys)
191 m_RequestMap.Remove(req);
192 }
193 }
194
195 foreach (string urlname in removeURLs)
196 m_UrlMap.Remove(urlname);
197 }
198 }
199
200 public void ObjectRemoved(UUID objectID)
201 {
202 lock(m_UrlMap)
203 {
204 List<string> removeURLs = new List<string>();
205
206 foreach(KeyValuePair<string, UrlData> url in m_UrlMap)
207 {
208 if (url.Value.hostID == objectID)
209 {
210 RemoveUrl(url.Value);
211 removeURLs.Add(url.Key);
212 foreach (UUID req in url.Value.requests.Keys)
213 m_RequestMap.Remove(req);
214 }
215 }
216
217 foreach (string urlname in removeURLs)
218 m_UrlMap.Remove(urlname);
219 }
220 }
221
222 private void RemoveUrl(UrlData data)
223 {
224 m_HttpServer.RemoveHTTPHandler("", "/lslhttp/"+data.urlcode.ToString());
225 }
226
227 private Hashtable HttpRequestHandler(Hashtable request)
228 {
229 Hashtable response = new Hashtable();
230 response["int_response_code"] = 404;
231
232 return response;
121 } 233 }
122 } 234 }
123} 235}