diff options
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs')
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs | 162 |
1 files changed, 113 insertions, 49 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs index 2359bd6..e996fe8 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs | |||
@@ -27,12 +27,15 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | ||
30 | using System.Reflection; | 31 | using System.Reflection; |
32 | using System.Threading; | ||
31 | using log4net; | 33 | using log4net; |
32 | using Nini.Config; | 34 | using Nini.Config; |
33 | using Mono.Addins; | 35 | using Mono.Addins; |
34 | using OpenMetaverse; | 36 | using OpenMetaverse; |
35 | using OpenSim.Framework; | 37 | using OpenSim.Framework; |
38 | using OpenSim.Framework.Servers; | ||
36 | using OpenSim.Framework.Servers.HttpServer; | 39 | using OpenSim.Framework.Servers.HttpServer; |
37 | using OpenSim.Region.Framework.Interfaces; | 40 | using OpenSim.Region.Framework.Interfaces; |
38 | using OpenSim.Region.Framework.Scenes; | 41 | using OpenSim.Region.Framework.Scenes; |
@@ -48,67 +51,49 @@ namespace OpenSim.Region.ClientStack.Linden | |||
48 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] | 51 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] |
49 | public class WebFetchInvDescModule : INonSharedRegionModule | 52 | public class WebFetchInvDescModule : INonSharedRegionModule |
50 | { | 53 | { |
51 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 54 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
52 | 55 | ||
53 | private Scene m_scene; | 56 | private Scene m_scene; |
54 | 57 | ||
55 | private IInventoryService m_InventoryService; | 58 | private IInventoryService m_InventoryService; |
56 | private ILibraryService m_LibraryService; | 59 | private ILibraryService m_LibraryService; |
57 | 60 | ||
58 | private bool m_Enabled; | 61 | private WebFetchInvDescHandler m_webFetchHandler; |
59 | 62 | ||
60 | private string m_fetchInventoryDescendents2Url; | 63 | private object m_lock = new object(); |
61 | private string m_webFetchInventoryDescendentsUrl; | ||
62 | 64 | ||
63 | private WebFetchInvDescHandler m_webFetchHandler; | 65 | private Dictionary<UUID, string> m_capsDict = new Dictionary<UUID, string>(); |
66 | private Dictionary<UUID, Hashtable> m_requests = new Dictionary<UUID, Hashtable>(); | ||
67 | bool m_busy = false; | ||
64 | 68 | ||
65 | #region ISharedRegionModule Members | 69 | #region ISharedRegionModule Members |
66 | 70 | ||
67 | public void Initialise(IConfigSource source) | 71 | public void Initialise(IConfigSource source) |
68 | { | 72 | { |
69 | IConfig config = source.Configs["ClientStack.LindenCaps"]; | ||
70 | if (config == null) | ||
71 | return; | ||
72 | |||
73 | m_fetchInventoryDescendents2Url = config.GetString("Cap_FetchInventoryDescendents2", string.Empty); | ||
74 | m_webFetchInventoryDescendentsUrl = config.GetString("Cap_WebFetchInventoryDescendents", string.Empty); | ||
75 | |||
76 | if (m_fetchInventoryDescendents2Url != string.Empty || m_webFetchInventoryDescendentsUrl != string.Empty) | ||
77 | { | ||
78 | m_Enabled = true; | ||
79 | } | ||
80 | } | 73 | } |
81 | 74 | ||
82 | public void AddRegion(Scene s) | 75 | public void AddRegion(Scene s) |
83 | { | 76 | { |
84 | if (!m_Enabled) | ||
85 | return; | ||
86 | |||
87 | m_scene = s; | 77 | m_scene = s; |
88 | } | 78 | } |
89 | 79 | ||
90 | public void RemoveRegion(Scene s) | 80 | public void RemoveRegion(Scene s) |
91 | { | 81 | { |
92 | if (!m_Enabled) | ||
93 | return; | ||
94 | |||
95 | m_scene.EventManager.OnRegisterCaps -= RegisterCaps; | 82 | m_scene.EventManager.OnRegisterCaps -= RegisterCaps; |
83 | m_scene.EventManager.OnDeregisterCaps -= DeregisterCaps; | ||
96 | m_scene = null; | 84 | m_scene = null; |
97 | } | 85 | } |
98 | 86 | ||
99 | public void RegionLoaded(Scene s) | 87 | public void RegionLoaded(Scene s) |
100 | { | 88 | { |
101 | if (!m_Enabled) | ||
102 | return; | ||
103 | |||
104 | m_InventoryService = m_scene.InventoryService; | 89 | m_InventoryService = m_scene.InventoryService; |
105 | m_LibraryService = m_scene.LibraryService; | 90 | m_LibraryService = m_scene.LibraryService; |
106 | 91 | ||
107 | // We'll reuse the same handler for all requests. | 92 | // We'll reuse the same handler for all requests. |
108 | if (m_fetchInventoryDescendents2Url == "localhost" || m_webFetchInventoryDescendentsUrl == "localhost") | 93 | m_webFetchHandler = new WebFetchInvDescHandler(m_InventoryService, m_LibraryService); |
109 | m_webFetchHandler = new WebFetchInvDescHandler(m_InventoryService, m_LibraryService); | ||
110 | 94 | ||
111 | m_scene.EventManager.OnRegisterCaps += RegisterCaps; | 95 | m_scene.EventManager.OnRegisterCaps += RegisterCaps; |
96 | m_scene.EventManager.OnDeregisterCaps += DeregisterCaps; | ||
112 | } | 97 | } |
113 | 98 | ||
114 | public void PostInitialise() | 99 | public void PostInitialise() |
@@ -128,41 +113,120 @@ namespace OpenSim.Region.ClientStack.Linden | |||
128 | 113 | ||
129 | private void RegisterCaps(UUID agentID, Caps caps) | 114 | private void RegisterCaps(UUID agentID, Caps caps) |
130 | { | 115 | { |
131 | if (m_webFetchInventoryDescendentsUrl != "") | 116 | string capUrl = "/CAPS/" + UUID.Random() + "/"; |
132 | RegisterFetchCap(agentID, caps, "WebFetchInventoryDescendents", m_webFetchInventoryDescendentsUrl); | 117 | |
118 | // Register this as a poll service | ||
119 | // absurd large timeout to tune later to make a bit less than viewer | ||
120 | PollServiceEventArgs args = new PollServiceEventArgs(HttpRequestHandler, HasEvents, GetEvents, NoEvents, agentID, 300000); | ||
121 | |||
122 | args.Type = PollServiceEventArgs.EventType.Inventory; | ||
123 | MainServer.Instance.AddPollServiceHTTPHandler(capUrl, args); | ||
124 | |||
125 | string hostName = m_scene.RegionInfo.ExternalHostName; | ||
126 | uint port = (MainServer.Instance == null) ? 0 : MainServer.Instance.Port; | ||
127 | string protocol = "http"; | ||
128 | |||
129 | if (MainServer.Instance.UseSSL) | ||
130 | { | ||
131 | hostName = MainServer.Instance.SSLCommonName; | ||
132 | port = MainServer.Instance.SSLPort; | ||
133 | protocol = "https"; | ||
134 | } | ||
135 | caps.RegisterHandler("FetchInventoryDescendents2", String.Format("{0}://{1}:{2}{3}", protocol, hostName, port, capUrl)); | ||
133 | 136 | ||
134 | if (m_fetchInventoryDescendents2Url != "") | 137 | m_capsDict[agentID] = capUrl; |
135 | RegisterFetchCap(agentID, caps, "FetchInventoryDescendents2", m_fetchInventoryDescendents2Url); | 138 | |
139 | m_busy = false; | ||
136 | } | 140 | } |
137 | 141 | ||
138 | private void RegisterFetchCap(UUID agentID, Caps caps, string capName, string url) | 142 | private void DeregisterCaps(UUID agentID, Caps caps) |
139 | { | 143 | { |
140 | string capUrl; | 144 | string capUrl; |
141 | 145 | ||
142 | if (url == "localhost") | 146 | if (m_capsDict.TryGetValue(agentID, out capUrl)) |
143 | { | 147 | { |
144 | capUrl = "/CAPS/" + UUID.Random(); | 148 | MainServer.Instance.RemoveHTTPHandler("", capUrl); |
149 | m_capsDict.Remove(agentID); | ||
150 | } | ||
151 | } | ||
145 | 152 | ||
146 | IRequestHandler reqHandler | 153 | public void HttpRequestHandler(UUID requestID, Hashtable request) |
147 | = new RestStreamHandler( | 154 | { |
148 | "POST", | 155 | // m_log.DebugFormat("[FETCH2]: Received request {0}", requestID); |
149 | capUrl, | 156 | lock(m_lock) |
150 | m_webFetchHandler.FetchInventoryDescendentsRequest, | 157 | m_requests[requestID] = request; |
151 | "FetchInventoryDescendents2", | 158 | } |
152 | agentID.ToString()); | ||
153 | 159 | ||
154 | caps.RegisterHandler(capName, reqHandler); | 160 | private bool HasEvents(UUID requestID, UUID sessionID) |
161 | { | ||
162 | lock (m_lock) | ||
163 | { | ||
164 | return !m_busy; | ||
155 | } | 165 | } |
156 | else | 166 | } |
167 | |||
168 | private Hashtable NoEvents(UUID requestID, UUID sessionID) | ||
169 | { | ||
170 | lock(m_lock) | ||
171 | m_requests.Remove(requestID); | ||
172 | |||
173 | Hashtable response = new Hashtable(); | ||
174 | |||
175 | response["int_response_code"] = 500; | ||
176 | response["str_response_string"] = "Script timeout"; | ||
177 | response["content_type"] = "text/plain"; | ||
178 | response["keepalive"] = false; | ||
179 | response["reusecontext"] = false; | ||
180 | |||
181 | lock (m_lock) | ||
182 | m_busy = false; | ||
183 | |||
184 | return response; | ||
185 | } | ||
186 | |||
187 | private Hashtable GetEvents(UUID requestID, UUID sessionID, string request) | ||
188 | { | ||
189 | lock (m_lock) | ||
190 | m_busy = true; | ||
191 | |||
192 | Hashtable response = new Hashtable(); | ||
193 | |||
194 | response["int_response_code"] = 500; | ||
195 | response["str_response_string"] = "Internal error"; | ||
196 | response["content_type"] = "text/plain"; | ||
197 | response["keepalive"] = false; | ||
198 | response["reusecontext"] = false; | ||
199 | |||
200 | try | ||
157 | { | 201 | { |
158 | capUrl = url; | ||
159 | 202 | ||
160 | caps.RegisterHandler(capName, capUrl); | 203 | Hashtable requestHash; |
204 | lock (m_lock) | ||
205 | { | ||
206 | if (!m_requests.TryGetValue(requestID, out requestHash)) | ||
207 | { | ||
208 | m_busy = false; | ||
209 | response["str_response_string"] = "Invalid request"; | ||
210 | return response; | ||
211 | } | ||
212 | m_requests.Remove(requestID); | ||
213 | } | ||
214 | |||
215 | // m_log.DebugFormat("[FETCH2]: Processed request {0}", requestID); | ||
216 | |||
217 | string reply = m_webFetchHandler.FetchInventoryDescendentsRequest(requestHash["body"].ToString(), String.Empty, String.Empty, null, null); | ||
218 | |||
219 | |||
220 | response["int_response_code"] = 200; | ||
221 | response["str_response_string"] = reply; | ||
222 | } | ||
223 | finally | ||
224 | { | ||
225 | lock (m_lock) | ||
226 | m_busy = false; | ||
161 | } | 227 | } |
162 | 228 | ||
163 | // m_log.DebugFormat( | 229 | return response; |
164 | // "[WEB FETCH INV DESC MODULE]: Registered capability {0} at {1} in region {2} for {3}", | ||
165 | // capName, capUrl, m_scene.RegionInfo.RegionName, agentID); | ||
166 | } | 230 | } |
167 | } | 231 | } |
168 | } \ No newline at end of file | 232 | } |