diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Environment/Modules/Scripting/XMLRPC/XMLRPCModule.cs (renamed from OpenSim/Region/Environment/Modules/XMLRPCModule.cs) | 1352 |
1 files changed, 672 insertions, 680 deletions
diff --git a/OpenSim/Region/Environment/Modules/XMLRPCModule.cs b/OpenSim/Region/Environment/Modules/Scripting/XMLRPC/XMLRPCModule.cs index e915fb8..1139b4b 100644 --- a/OpenSim/Region/Environment/Modules/XMLRPCModule.cs +++ b/OpenSim/Region/Environment/Modules/Scripting/XMLRPC/XMLRPCModule.cs | |||
@@ -1,680 +1,672 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Net; | 31 | using System.Net; |
32 | using System.Reflection; | 32 | using System.Reflection; |
33 | using System.Threading; | 33 | using System.Threading; |
34 | using libsecondlife; | 34 | using libsecondlife; |
35 | using log4net; | 35 | using log4net; |
36 | using Nini.Config; | 36 | using Nini.Config; |
37 | using Nwc.XmlRpc; | 37 | using Nwc.XmlRpc; |
38 | using OpenSim.Framework; | 38 | using OpenSim.Framework; |
39 | using OpenSim.Framework.Servers; | 39 | using OpenSim.Framework.Servers; |
40 | using OpenSim.Region.Environment.Interfaces; | 40 | using OpenSim.Region.Environment.Interfaces; |
41 | using OpenSim.Region.Environment.Scenes; | 41 | using OpenSim.Region.Environment.Scenes; |
42 | 42 | ||
43 | /***************************************************** | 43 | /***************************************************** |
44 | * | 44 | * |
45 | * XMLRPCModule | 45 | * XMLRPCModule |
46 | * | 46 | * |
47 | * Module for accepting incoming communications from | 47 | * Module for accepting incoming communications from |
48 | * external XMLRPC client and calling a remote data | 48 | * external XMLRPC client and calling a remote data |
49 | * procedure for a registered data channel/prim. | 49 | * procedure for a registered data channel/prim. |
50 | * | 50 | * |
51 | * | 51 | * |
52 | * 1. On module load, open a listener port | 52 | * 1. On module load, open a listener port |
53 | * 2. Attach an XMLRPC handler | 53 | * 2. Attach an XMLRPC handler |
54 | * 3. When a request is received: | 54 | * 3. When a request is received: |
55 | * 3.1 Parse into components: channel key, int, string | 55 | * 3.1 Parse into components: channel key, int, string |
56 | * 3.2 Look up registered channel listeners | 56 | * 3.2 Look up registered channel listeners |
57 | * 3.3 Call the channel (prim) remote data method | 57 | * 3.3 Call the channel (prim) remote data method |
58 | * 3.4 Capture the response (llRemoteDataReply) | 58 | * 3.4 Capture the response (llRemoteDataReply) |
59 | * 3.5 Return response to client caller | 59 | * 3.5 Return response to client caller |
60 | * 3.6 If no response from llRemoteDataReply within | 60 | * 3.6 If no response from llRemoteDataReply within |
61 | * RemoteReplyScriptTimeout, generate script timeout fault | 61 | * RemoteReplyScriptTimeout, generate script timeout fault |
62 | * | 62 | * |
63 | * Prims in script must: | 63 | * Prims in script must: |
64 | * 1. Open a remote data channel | 64 | * 1. Open a remote data channel |
65 | * 1.1 Generate a channel ID | 65 | * 1.1 Generate a channel ID |
66 | * 1.2 Register primid,channelid pair with module | 66 | * 1.2 Register primid,channelid pair with module |
67 | * 2. Implement the remote data procedure handler | 67 | * 2. Implement the remote data procedure handler |
68 | * | 68 | * |
69 | * llOpenRemoteDataChannel | 69 | * llOpenRemoteDataChannel |
70 | * llRemoteDataReply | 70 | * llRemoteDataReply |
71 | * remote_data(integer type, key channel, key messageid, string sender, integer ival, string sval) | 71 | * remote_data(integer type, key channel, key messageid, string sender, integer ival, string sval) |
72 | * llCloseRemoteDataChannel | 72 | * llCloseRemoteDataChannel |
73 | * | 73 | * |
74 | * **************************************************/ | 74 | * **************************************************/ |
75 | 75 | ||
76 | namespace OpenSim.Region.Environment.Modules | 76 | namespace OpenSim.Region.Environment.Modules.Scripting.XMLRPC |
77 | { | 77 | { |
78 | public class XMLRPCModule : IRegionModule, IXMLRPC | 78 | public class XMLRPCModule : IRegionModule, IXMLRPC |
79 | { | 79 | { |
80 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 80 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
81 | 81 | ||
82 | private object XMLRPCListLock = new object(); | 82 | private object XMLRPCListLock = new object(); |
83 | private string m_name = "XMLRPCModule"; | 83 | private string m_name = "XMLRPCModule"; |
84 | private int RemoteReplyScriptWait = 300; | 84 | private int RemoteReplyScriptWait = 300; |
85 | private int RemoteReplyScriptTimeout = 9000; | 85 | private int RemoteReplyScriptTimeout = 9000; |
86 | private int m_remoteDataPort = 0; | 86 | private int m_remoteDataPort = 0; |
87 | private List<Scene> m_scenes = new List<Scene>(); | 87 | private List<Scene> m_scenes = new List<Scene>(); |
88 | 88 | ||
89 | // <channel id, RPCChannelInfo> | 89 | // <channel id, RPCChannelInfo> |
90 | private Dictionary<LLUUID, RPCChannelInfo> m_openChannels; | 90 | private Dictionary<LLUUID, RPCChannelInfo> m_openChannels; |
91 | 91 | ||
92 | private Dictionary<LLUUID, RPCRequestInfo> m_rpcPending; | 92 | private Dictionary<LLUUID, RPCRequestInfo> m_rpcPending; |
93 | private Dictionary<LLUUID, RPCRequestInfo> m_rpcPendingResponses; | 93 | private Dictionary<LLUUID, RPCRequestInfo> m_rpcPendingResponses; |
94 | 94 | ||
95 | private Dictionary<LLUUID, SendRemoteDataRequest> m_pendingSRDResponses; | 95 | private Dictionary<LLUUID, SendRemoteDataRequest> m_pendingSRDResponses; |
96 | 96 | ||
97 | public void Initialise(Scene scene, IConfigSource config) | 97 | public void Initialise(Scene scene, IConfigSource config) |
98 | { | 98 | { |
99 | try | 99 | try |
100 | { | 100 | { |
101 | m_remoteDataPort = config.Configs["Network"].GetInt("remoteDataPort", m_remoteDataPort); | 101 | m_remoteDataPort = config.Configs["Network"].GetInt("remoteDataPort", m_remoteDataPort); |
102 | } | 102 | } |
103 | catch (Exception) | 103 | catch (Exception) |
104 | { | 104 | { |
105 | } | 105 | } |
106 | 106 | ||
107 | if (!m_scenes.Contains(scene)) | 107 | if (!m_scenes.Contains(scene)) |
108 | { | 108 | { |
109 | m_scenes.Add(scene); | 109 | m_scenes.Add(scene); |
110 | 110 | ||
111 | scene.RegisterModuleInterface<IXMLRPC>(this); | 111 | scene.RegisterModuleInterface<IXMLRPC>(this); |
112 | } | 112 | } |
113 | } | 113 | } |
114 | 114 | ||
115 | public void PostInitialise() | 115 | public void PostInitialise() |
116 | { | 116 | { |
117 | if (IsEnabled()) | 117 | if (IsEnabled()) |
118 | { | 118 | { |
119 | m_openChannels = new Dictionary<LLUUID, RPCChannelInfo>(); | 119 | m_openChannels = new Dictionary<LLUUID, RPCChannelInfo>(); |
120 | m_rpcPending = new Dictionary<LLUUID, RPCRequestInfo>(); | 120 | m_rpcPending = new Dictionary<LLUUID, RPCRequestInfo>(); |
121 | m_rpcPendingResponses = new Dictionary<LLUUID, RPCRequestInfo>(); | 121 | m_rpcPendingResponses = new Dictionary<LLUUID, RPCRequestInfo>(); |
122 | m_pendingSRDResponses = new Dictionary<LLUUID, SendRemoteDataRequest>(); | 122 | m_pendingSRDResponses = new Dictionary<LLUUID, SendRemoteDataRequest>(); |
123 | 123 | ||
124 | // Start http server | 124 | // Start http server |
125 | // Attach xmlrpc handlers | 125 | // Attach xmlrpc handlers |
126 | m_log.Info("[REMOTE_DATA]: " + | 126 | m_log.Info("[REMOTE_DATA]: " + |
127 | "Starting XMLRPC Server on port " + m_remoteDataPort + " for llRemoteData commands."); | 127 | "Starting XMLRPC Server on port " + m_remoteDataPort + " for llRemoteData commands."); |
128 | BaseHttpServer httpServer = new BaseHttpServer((uint)m_remoteDataPort); | 128 | BaseHttpServer httpServer = new BaseHttpServer((uint)m_remoteDataPort); |
129 | httpServer.AddXmlRPCHandler("llRemoteData", XmlRpcRemoteData); | 129 | httpServer.AddXmlRPCHandler("llRemoteData", XmlRpcRemoteData); |
130 | httpServer.Start(); | 130 | httpServer.Start(); |
131 | } | 131 | } |
132 | } | 132 | } |
133 | 133 | ||
134 | public void Close() | 134 | public void Close() |
135 | { | 135 | { |
136 | } | 136 | } |
137 | 137 | ||
138 | public string Name | 138 | public string Name |
139 | { | 139 | { |
140 | get { return m_name; } | 140 | get { return m_name; } |
141 | } | 141 | } |
142 | 142 | ||
143 | public bool IsSharedModule | 143 | public bool IsSharedModule |
144 | { | 144 | { |
145 | get { return true; } | 145 | get { return true; } |
146 | } | 146 | } |
147 | 147 | ||
148 | public bool IsEnabled() | 148 | public bool IsEnabled() |
149 | { | 149 | { |
150 | return (m_remoteDataPort > 0); | 150 | return (m_remoteDataPort > 0); |
151 | } | 151 | } |
152 | 152 | ||
153 | /********************************************** | 153 | /********************************************** |
154 | * OpenXMLRPCChannel | 154 | * OpenXMLRPCChannel |
155 | * | 155 | * |
156 | * Generate a LLUUID channel key and add it and | 156 | * Generate a LLUUID channel key and add it and |
157 | * the prim id to dictionary <channelUUID, primUUID> | 157 | * the prim id to dictionary <channelUUID, primUUID> |
158 | * | 158 | * |
159 | * First check if there is a channel assigned for | 159 | * First check if there is a channel assigned for |
160 | * this itemID. If there is, then someone called | 160 | * this itemID. If there is, then someone called |
161 | * llOpenRemoteDataChannel twice. Just return the | 161 | * llOpenRemoteDataChannel twice. Just return the |
162 | * original channel. Other option is to delete the | 162 | * original channel. Other option is to delete the |
163 | * current channel and assign a new one. | 163 | * current channel and assign a new one. |
164 | * | 164 | * |
165 | * ********************************************/ | 165 | * ********************************************/ |
166 | 166 | ||
167 | public LLUUID OpenXMLRPCChannel(uint localID, LLUUID itemID) | 167 | public LLUUID OpenXMLRPCChannel(uint localID, LLUUID itemID) |
168 | { | 168 | { |
169 | LLUUID channel = new LLUUID(); | 169 | LLUUID channel = new LLUUID(); |
170 | 170 | ||
171 | //Is a dupe? | 171 | //Is a dupe? |
172 | foreach (RPCChannelInfo ci in m_openChannels.Values) | 172 | foreach (RPCChannelInfo ci in m_openChannels.Values) |
173 | { | 173 | { |
174 | if (ci.GetItemID().Equals(itemID)) | 174 | if (ci.GetItemID().Equals(itemID)) |
175 | { | 175 | { |
176 | // return the original channel ID for this item | 176 | // return the original channel ID for this item |
177 | channel = ci.GetChannelID(); | 177 | channel = ci.GetChannelID(); |
178 | break; | 178 | break; |
179 | } | 179 | } |
180 | } | 180 | } |
181 | 181 | ||
182 | if (channel == LLUUID.Zero) | 182 | if (channel == LLUUID.Zero) |
183 | { | 183 | { |
184 | channel = LLUUID.Random(); | 184 | channel = LLUUID.Random(); |
185 | RPCChannelInfo rpcChanInfo = new RPCChannelInfo(localID, itemID, channel); | 185 | RPCChannelInfo rpcChanInfo = new RPCChannelInfo(localID, itemID, channel); |
186 | lock (XMLRPCListLock) | 186 | lock (XMLRPCListLock) |
187 | { | 187 | { |
188 | m_openChannels.Add(channel, rpcChanInfo); | 188 | m_openChannels.Add(channel, rpcChanInfo); |
189 | } | 189 | } |
190 | } | 190 | } |
191 | 191 | ||
192 | return channel; | 192 | return channel; |
193 | } | 193 | } |
194 | 194 | ||
195 | // Delete channels based on itemID | 195 | // Delete channels based on itemID |
196 | // for when a script is deleted | 196 | // for when a script is deleted |
197 | public void DeleteChannels(LLUUID itemID) | 197 | public void DeleteChannels(LLUUID itemID) |
198 | { | 198 | { |
199 | 199 | ||
200 | if (m_openChannels != null) | 200 | if (m_openChannels != null) |
201 | { | 201 | { |
202 | ArrayList tmp = new ArrayList(); | 202 | ArrayList tmp = new ArrayList(); |
203 | 203 | ||
204 | lock (XMLRPCListLock) | 204 | lock (XMLRPCListLock) |
205 | { | 205 | { |
206 | foreach (RPCChannelInfo li in m_openChannels.Values) | 206 | foreach (RPCChannelInfo li in m_openChannels.Values) |
207 | { | 207 | { |
208 | if (li.GetItemID().Equals(itemID)) | 208 | if (li.GetItemID().Equals(itemID)) |
209 | { | 209 | { |
210 | tmp.Add(itemID); | 210 | tmp.Add(itemID); |
211 | } | 211 | } |
212 | } | 212 | } |
213 | 213 | ||
214 | IEnumerator tmpEnumerator = tmp.GetEnumerator(); | 214 | IEnumerator tmpEnumerator = tmp.GetEnumerator(); |
215 | while ( tmpEnumerator.MoveNext() ) | 215 | while ( tmpEnumerator.MoveNext() ) |
216 | m_openChannels.Remove((LLUUID)tmpEnumerator.Current); | 216 | m_openChannels.Remove((LLUUID)tmpEnumerator.Current); |
217 | } | 217 | } |
218 | 218 | ||
219 | } | 219 | } |
220 | 220 | ||
221 | } | 221 | } |
222 | 222 | ||
223 | /********************************************** | 223 | /********************************************** |
224 | * Remote Data Reply | 224 | * Remote Data Reply |
225 | * | 225 | * |
226 | * Response to RPC message | 226 | * Response to RPC message |
227 | * | 227 | * |
228 | *********************************************/ | 228 | *********************************************/ |
229 | 229 | ||
230 | public void RemoteDataReply(string channel, string message_id, string sdata, int idata) | 230 | public void RemoteDataReply(string channel, string message_id, string sdata, int idata) |
231 | { | 231 | { |
232 | RPCRequestInfo rpcInfo; | 232 | RPCRequestInfo rpcInfo; |
233 | LLUUID message_key = new LLUUID(message_id); | 233 | LLUUID message_key = new LLUUID(message_id); |
234 | 234 | ||
235 | if (m_rpcPendingResponses.TryGetValue(message_key, out rpcInfo)) | 235 | if (m_rpcPendingResponses.TryGetValue(message_key, out rpcInfo)) |
236 | { | 236 | { |
237 | rpcInfo.SetStrRetval(sdata); | 237 | rpcInfo.SetStrRetval(sdata); |
238 | rpcInfo.SetIntRetval(idata); | 238 | rpcInfo.SetIntRetval(idata); |
239 | rpcInfo.SetProcessed(true); | 239 | rpcInfo.SetProcessed(true); |
240 | m_rpcPendingResponses.Remove(message_key); | 240 | m_rpcPendingResponses.Remove(message_key); |
241 | } | 241 | } |
242 | } | 242 | } |
243 | 243 | ||
244 | /********************************************** | 244 | /********************************************** |
245 | * CloseXMLRPCChannel | 245 | * CloseXMLRPCChannel |
246 | * | 246 | * |
247 | * Remove channel from dictionary | 247 | * Remove channel from dictionary |
248 | * | 248 | * |
249 | *********************************************/ | 249 | *********************************************/ |
250 | 250 | ||
251 | public void CloseXMLRPCChannel(LLUUID channelKey) | 251 | public void CloseXMLRPCChannel(LLUUID channelKey) |
252 | { | 252 | { |
253 | if (m_openChannels.ContainsKey(channelKey)) | 253 | if (m_openChannels.ContainsKey(channelKey)) |
254 | m_openChannels.Remove(channelKey); | 254 | m_openChannels.Remove(channelKey); |
255 | } | 255 | } |
256 | 256 | ||
257 | 257 | ||
258 | public XmlRpcResponse XmlRpcRemoteData(XmlRpcRequest request) | 258 | public XmlRpcResponse XmlRpcRemoteData(XmlRpcRequest request) |
259 | { | 259 | { |
260 | XmlRpcResponse response = new XmlRpcResponse(); | 260 | XmlRpcResponse response = new XmlRpcResponse(); |
261 | 261 | ||
262 | Hashtable requestData = (Hashtable)request.Params[0]; | 262 | Hashtable requestData = (Hashtable)request.Params[0]; |
263 | bool GoodXML = (requestData.Contains("Channel") && requestData.Contains("IntValue") && | 263 | bool GoodXML = (requestData.Contains("Channel") && requestData.Contains("IntValue") && |
264 | requestData.Contains("StringValue")); | 264 | requestData.Contains("StringValue")); |
265 | 265 | ||
266 | if (GoodXML) | 266 | if (GoodXML) |
267 | { | 267 | { |
268 | LLUUID channel = new LLUUID((string)requestData["Channel"]); | 268 | LLUUID channel = new LLUUID((string)requestData["Channel"]); |
269 | RPCChannelInfo rpcChanInfo; | 269 | RPCChannelInfo rpcChanInfo; |
270 | if (m_openChannels.TryGetValue(channel, out rpcChanInfo)) | 270 | if (m_openChannels.TryGetValue(channel, out rpcChanInfo)) |
271 | { | 271 | { |
272 | string intVal = (string)requestData["IntValue"]; | 272 | string intVal = (string)requestData["IntValue"]; |
273 | string strVal = (string)requestData["StringValue"]; | 273 | string strVal = (string)requestData["StringValue"]; |
274 | 274 | ||
275 | RPCRequestInfo rpcInfo; | 275 | RPCRequestInfo rpcInfo; |
276 | 276 | ||
277 | lock (XMLRPCListLock) | 277 | lock (XMLRPCListLock) |
278 | { | 278 | { |
279 | rpcInfo = | 279 | rpcInfo = |
280 | new RPCRequestInfo(rpcChanInfo.GetLocalID(), rpcChanInfo.GetItemID(), channel, strVal, | 280 | new RPCRequestInfo(rpcChanInfo.GetLocalID(), rpcChanInfo.GetItemID(), channel, strVal, |
281 | intVal); | 281 | intVal); |
282 | m_rpcPending.Add(rpcInfo.GetMessageID(), rpcInfo); | 282 | m_rpcPending.Add(rpcInfo.GetMessageID(), rpcInfo); |
283 | } | 283 | } |
284 | 284 | ||
285 | int timeoutCtr = 0; | 285 | int timeoutCtr = 0; |
286 | 286 | ||
287 | while (!rpcInfo.IsProcessed() && (timeoutCtr < RemoteReplyScriptTimeout)) | 287 | while (!rpcInfo.IsProcessed() && (timeoutCtr < RemoteReplyScriptTimeout)) |
288 | { | 288 | { |
289 | Thread.Sleep(RemoteReplyScriptWait); | 289 | Thread.Sleep(RemoteReplyScriptWait); |
290 | timeoutCtr += RemoteReplyScriptWait; | 290 | timeoutCtr += RemoteReplyScriptWait; |
291 | } | 291 | } |
292 | if (rpcInfo.IsProcessed()) | 292 | if (rpcInfo.IsProcessed()) |
293 | { | 293 | { |
294 | Hashtable param = new Hashtable(); | 294 | Hashtable param = new Hashtable(); |
295 | param["StringValue"] = rpcInfo.GetStrRetval(); | 295 | param["StringValue"] = rpcInfo.GetStrRetval(); |
296 | param["IntValue"] = Convert.ToString(rpcInfo.GetIntRetval()); | 296 | param["IntValue"] = Convert.ToString(rpcInfo.GetIntRetval()); |
297 | 297 | ||
298 | ArrayList parameters = new ArrayList(); | 298 | ArrayList parameters = new ArrayList(); |
299 | parameters.Add(param); | 299 | parameters.Add(param); |
300 | 300 | ||
301 | response.Value = parameters; | 301 | response.Value = parameters; |
302 | rpcInfo = null; | 302 | rpcInfo = null; |
303 | } | 303 | } |
304 | else | 304 | else |
305 | { | 305 | { |
306 | response.SetFault(-1, "Script timeout"); | 306 | response.SetFault(-1, "Script timeout"); |
307 | rpcInfo = null; | 307 | rpcInfo = null; |
308 | } | 308 | } |
309 | } | 309 | } |
310 | else | 310 | else |
311 | { | 311 | { |
312 | response.SetFault(-1, "Invalid channel"); | 312 | response.SetFault(-1, "Invalid channel"); |
313 | } | 313 | } |
314 | } | 314 | } |
315 | 315 | ||
316 | return response; | 316 | return response; |
317 | } | 317 | } |
318 | 318 | ||
319 | public bool hasRequests() | 319 | public bool hasRequests() |
320 | { | 320 | { |
321 | lock (XMLRPCListLock) | 321 | lock (XMLRPCListLock) |
322 | { | 322 | { |
323 | if (m_rpcPending != null) | 323 | if (m_rpcPending != null) |
324 | return (m_rpcPending.Count > 0); | 324 | return (m_rpcPending.Count > 0); |
325 | else | 325 | else |
326 | return false; | 326 | return false; |
327 | } | 327 | } |
328 | } | 328 | } |
329 | 329 | ||
330 | public RPCRequestInfo GetNextCompletedRequest() | 330 | public RPCRequestInfo GetNextCompletedRequest() |
331 | { | 331 | { |
332 | if (m_rpcPending != null) | 332 | if (m_rpcPending != null) |
333 | { | 333 | { |
334 | lock (XMLRPCListLock) | 334 | lock (XMLRPCListLock) |
335 | { | 335 | { |
336 | foreach (LLUUID luid in m_rpcPending.Keys) | 336 | foreach (LLUUID luid in m_rpcPending.Keys) |
337 | { | 337 | { |
338 | RPCRequestInfo tmpReq; | 338 | RPCRequestInfo tmpReq; |
339 | 339 | ||
340 | if (m_rpcPending.TryGetValue(luid, out tmpReq)) | 340 | if (m_rpcPending.TryGetValue(luid, out tmpReq)) |
341 | { | 341 | { |
342 | 342 | ||
343 | if (!tmpReq.IsProcessed()) return tmpReq; | 343 | if (!tmpReq.IsProcessed()) return tmpReq; |
344 | } | 344 | } |
345 | } | 345 | } |
346 | } | 346 | } |
347 | } | 347 | } |
348 | return null; | 348 | return null; |
349 | } | 349 | } |
350 | 350 | ||
351 | public void RemoveCompletedRequest(LLUUID id) | 351 | public void RemoveCompletedRequest(LLUUID id) |
352 | { | 352 | { |
353 | lock (XMLRPCListLock) | 353 | lock (XMLRPCListLock) |
354 | { | 354 | { |
355 | RPCRequestInfo tmp; | 355 | RPCRequestInfo tmp; |
356 | if (m_rpcPending.TryGetValue(id, out tmp)) | 356 | if (m_rpcPending.TryGetValue(id, out tmp)) |
357 | { | 357 | { |
358 | m_rpcPending.Remove(id); | 358 | m_rpcPending.Remove(id); |
359 | m_rpcPendingResponses.Add(id, tmp); | 359 | m_rpcPendingResponses.Add(id, tmp); |
360 | } | 360 | } |
361 | else | 361 | else |
362 | { | 362 | { |
363 | Console.WriteLine("UNABLE TO REMOVE COMPLETED REQUEST"); | 363 | Console.WriteLine("UNABLE TO REMOVE COMPLETED REQUEST"); |
364 | } | 364 | } |
365 | } | 365 | } |
366 | } | 366 | } |
367 | 367 | ||
368 | public LLUUID SendRemoteData(uint localID, LLUUID itemID, string channel, string dest, int idata, string sdata) | 368 | public LLUUID SendRemoteData(uint localID, LLUUID itemID, string channel, string dest, int idata, string sdata) |
369 | { | 369 | { |
370 | 370 | ||
371 | SendRemoteDataRequest req = new SendRemoteDataRequest( | 371 | SendRemoteDataRequest req = new SendRemoteDataRequest( |
372 | localID, itemID, channel, dest, idata, sdata | 372 | localID, itemID, channel, dest, idata, sdata |
373 | ); | 373 | ); |
374 | m_pendingSRDResponses.Add(req.GetReqID(), req); | 374 | m_pendingSRDResponses.Add(req.GetReqID(), req); |
375 | return req.process(); | 375 | return req.process(); |
376 | 376 | ||
377 | } | 377 | } |
378 | 378 | ||
379 | public SendRemoteDataRequest GetNextCompletedSRDRequest() | 379 | public SendRemoteDataRequest GetNextCompletedSRDRequest() |
380 | { | 380 | { |
381 | if (m_pendingSRDResponses != null) | 381 | if (m_pendingSRDResponses != null) |
382 | { | 382 | { |
383 | lock (XMLRPCListLock) | 383 | lock (XMLRPCListLock) |
384 | { | 384 | { |
385 | foreach (LLUUID luid in m_pendingSRDResponses.Keys) | 385 | foreach (LLUUID luid in m_pendingSRDResponses.Keys) |
386 | { | 386 | { |
387 | SendRemoteDataRequest tmpReq; | 387 | SendRemoteDataRequest tmpReq; |
388 | 388 | ||
389 | if (m_pendingSRDResponses.TryGetValue(luid, out tmpReq)) | 389 | if (m_pendingSRDResponses.TryGetValue(luid, out tmpReq)) |
390 | { | 390 | { |
391 | if (tmpReq.finished) | 391 | if (tmpReq.finished) |
392 | return tmpReq; | 392 | return tmpReq; |
393 | } | 393 | } |
394 | } | 394 | } |
395 | } | 395 | } |
396 | } | 396 | } |
397 | return null; | 397 | return null; |
398 | } | 398 | } |
399 | 399 | ||
400 | public void RemoveCompletedSRDRequest(LLUUID id) | 400 | public void RemoveCompletedSRDRequest(LLUUID id) |
401 | { | 401 | { |
402 | lock (XMLRPCListLock) | 402 | lock (XMLRPCListLock) |
403 | { | 403 | { |
404 | SendRemoteDataRequest tmpReq; | 404 | SendRemoteDataRequest tmpReq; |
405 | if (m_pendingSRDResponses.TryGetValue(id, out tmpReq)) | 405 | if (m_pendingSRDResponses.TryGetValue(id, out tmpReq)) |
406 | { | 406 | { |
407 | m_pendingSRDResponses.Remove(id); | 407 | m_pendingSRDResponses.Remove(id); |
408 | } | 408 | } |
409 | } | 409 | } |
410 | } | 410 | } |
411 | 411 | ||
412 | public void CancelSRDRequests(LLUUID itemID) | 412 | public void CancelSRDRequests(LLUUID itemID) |
413 | { | 413 | { |
414 | if (m_pendingSRDResponses != null) | 414 | if (m_pendingSRDResponses != null) |
415 | { | 415 | { |
416 | lock (XMLRPCListLock) | 416 | lock (XMLRPCListLock) |
417 | { | 417 | { |
418 | foreach (SendRemoteDataRequest li in m_pendingSRDResponses.Values) | 418 | foreach (SendRemoteDataRequest li in m_pendingSRDResponses.Values) |
419 | { | 419 | { |
420 | if (li.m_itemID.Equals(itemID)) | 420 | if (li.m_itemID.Equals(itemID)) |
421 | m_pendingSRDResponses.Remove(li.GetReqID()); | 421 | m_pendingSRDResponses.Remove(li.GetReqID()); |
422 | } | 422 | } |
423 | } | 423 | } |
424 | } | 424 | } |
425 | } | 425 | } |
426 | } | 426 | } |
427 | 427 | ||
428 | /************************************************************** | 428 | public class RPCRequestInfo |
429 | * | 429 | { |
430 | * Class RPCRequestInfo | 430 | private string m_StrVal; |
431 | * | 431 | private string m_IntVal; |
432 | * Holds details about incoming requests until they are picked | 432 | private bool m_processed; |
433 | * from the queue by LSLLongCmdHandler | 433 | private string m_respStr; |
434 | * ***********************************************************/ | 434 | private int m_respInt; |
435 | 435 | private uint m_localID; | |
436 | public class RPCRequestInfo | 436 | private LLUUID m_ItemID; |
437 | { | 437 | private LLUUID m_MessageID; |
438 | private string m_StrVal; | 438 | private LLUUID m_ChannelKey; |
439 | private string m_IntVal; | 439 | |
440 | private bool m_processed; | 440 | public RPCRequestInfo(uint localID, LLUUID itemID, LLUUID channelKey, string strVal, string intVal) |
441 | private string m_respStr; | 441 | { |
442 | private int m_respInt; | 442 | m_localID = localID; |
443 | private uint m_localID; | 443 | m_StrVal = strVal; |
444 | private LLUUID m_ItemID; | 444 | m_IntVal = intVal; |
445 | private LLUUID m_MessageID; | 445 | m_ItemID = itemID; |
446 | private LLUUID m_ChannelKey; | 446 | m_ChannelKey = channelKey; |
447 | 447 | m_MessageID = LLUUID.Random(); | |
448 | public RPCRequestInfo(uint localID, LLUUID itemID, LLUUID channelKey, string strVal, string intVal) | 448 | m_processed = false; |
449 | { | 449 | m_respStr = String.Empty; |
450 | m_localID = localID; | 450 | m_respInt = 0; |
451 | m_StrVal = strVal; | 451 | } |
452 | m_IntVal = intVal; | 452 | |
453 | m_ItemID = itemID; | 453 | public bool IsProcessed() |
454 | m_ChannelKey = channelKey; | 454 | { |
455 | m_MessageID = LLUUID.Random(); | 455 | return m_processed; |
456 | m_processed = false; | 456 | } |
457 | m_respStr = String.Empty; | 457 | |
458 | m_respInt = 0; | 458 | public LLUUID GetChannelKey() |
459 | } | 459 | { |
460 | 460 | return m_ChannelKey; | |
461 | public bool IsProcessed() | 461 | } |
462 | { | 462 | |
463 | return m_processed; | 463 | public void SetProcessed(bool processed) |
464 | } | 464 | { |
465 | 465 | m_processed = processed; | |
466 | public LLUUID GetChannelKey() | 466 | } |
467 | { | 467 | |
468 | return m_ChannelKey; | 468 | public void SetStrRetval(string resp) |
469 | } | 469 | { |
470 | 470 | m_respStr = resp; | |
471 | public void SetProcessed(bool processed) | 471 | } |
472 | { | 472 | |
473 | m_processed = processed; | 473 | public string GetStrRetval() |
474 | } | 474 | { |
475 | 475 | return m_respStr; | |
476 | public void SetStrRetval(string resp) | 476 | } |
477 | { | 477 | public void SetIntRetval(int resp) |
478 | m_respStr = resp; | 478 | { |
479 | } | 479 | m_respInt = resp; |
480 | 480 | } | |
481 | public string GetStrRetval() | 481 | |
482 | { | 482 | public int GetIntRetval() |
483 | return m_respStr; | 483 | { |
484 | } | 484 | return m_respInt; |
485 | public void SetIntRetval(int resp) | 485 | } |
486 | { | 486 | public uint GetLocalID() |
487 | m_respInt = resp; | 487 | { |
488 | } | 488 | return m_localID; |
489 | 489 | } | |
490 | public int GetIntRetval() | 490 | |
491 | { | 491 | public LLUUID GetItemID() |
492 | return m_respInt; | 492 | { |
493 | } | 493 | return m_ItemID; |
494 | public uint GetLocalID() | 494 | } |
495 | { | 495 | |
496 | return m_localID; | 496 | public string GetStrVal() |
497 | } | 497 | { |
498 | 498 | return m_StrVal; | |
499 | public LLUUID GetItemID() | 499 | } |
500 | { | 500 | |
501 | return m_ItemID; | 501 | public int GetIntValue() |
502 | } | 502 | { |
503 | 503 | return int.Parse(m_IntVal); | |
504 | public string GetStrVal() | 504 | } |
505 | { | 505 | |
506 | return m_StrVal; | 506 | public LLUUID GetMessageID() |
507 | } | 507 | { |
508 | 508 | return m_MessageID; | |
509 | public int GetIntValue() | 509 | } |
510 | { | 510 | } |
511 | return int.Parse(m_IntVal); | 511 | |
512 | } | 512 | public class RPCChannelInfo |
513 | 513 | { | |
514 | public LLUUID GetMessageID() | 514 | private LLUUID m_itemID; |
515 | { | 515 | private uint m_localID; |
516 | return m_MessageID; | 516 | private LLUUID m_ChannelKey; |
517 | } | 517 | |
518 | } | 518 | public RPCChannelInfo(uint localID, LLUUID itemID, LLUUID channelID) |
519 | 519 | { | |
520 | public class RPCChannelInfo | 520 | m_ChannelKey = channelID; |
521 | { | 521 | m_localID = localID; |
522 | private LLUUID m_itemID; | 522 | m_itemID = itemID; |
523 | private uint m_localID; | 523 | } |
524 | private LLUUID m_ChannelKey; | 524 | |
525 | 525 | public LLUUID GetItemID() | |
526 | public RPCChannelInfo(uint localID, LLUUID itemID, LLUUID channelID) | 526 | { |
527 | { | 527 | return m_itemID; |
528 | m_ChannelKey = channelID; | 528 | } |
529 | m_localID = localID; | 529 | |
530 | m_itemID = itemID; | 530 | public LLUUID GetChannelID() |
531 | } | 531 | { |
532 | 532 | return m_ChannelKey; | |
533 | public LLUUID GetItemID() | 533 | } |
534 | { | 534 | |
535 | return m_itemID; | 535 | public uint GetLocalID() |
536 | } | 536 | { |
537 | 537 | return m_localID; | |
538 | public LLUUID GetChannelID() | 538 | } |
539 | { | 539 | |
540 | return m_ChannelKey; | 540 | } |
541 | } | 541 | |
542 | 542 | public class SendRemoteDataRequest | |
543 | public uint GetLocalID() | 543 | { |
544 | { | 544 | |
545 | return m_localID; | 545 | public LLUUID reqID; |
546 | } | 546 | public string destURL; |
547 | 547 | public string channel; | |
548 | } | 548 | public string sdata; |
549 | 549 | public int idata; | |
550 | public class SendRemoteDataRequest | 550 | public bool finished; |
551 | { | 551 | public string response_sdata; |
552 | 552 | public int response_idata; | |
553 | public LLUUID reqID; | 553 | public XmlRpcRequest request; |
554 | public string destURL; | 554 | private Thread httpThread; |
555 | public string channel; | 555 | public LLUUID m_itemID; |
556 | public string sdata; | 556 | public uint m_localID; |
557 | public int idata; | 557 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
558 | public bool finished; | 558 | |
559 | public string response_sdata; | 559 | public SendRemoteDataRequest(uint localID, LLUUID itemID, string channel, string dest, int idata, string sdata) |
560 | public int response_idata; | 560 | { |
561 | public XmlRpcRequest request; | 561 | |
562 | private Thread httpThread; | 562 | this.channel = channel; |
563 | public LLUUID m_itemID; | 563 | this.destURL = dest; |
564 | public uint m_localID; | 564 | this.idata = idata; |
565 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 565 | this.sdata = sdata; |
566 | 566 | m_itemID = itemID; | |
567 | public SendRemoteDataRequest(uint localID, LLUUID itemID, string channel, string dest, int idata, string sdata) | 567 | m_localID = localID; |
568 | { | 568 | |
569 | 569 | reqID = LLUUID.Random(); | |
570 | this.channel = channel; | 570 | |
571 | this.destURL = dest; | 571 | } |
572 | this.idata = idata; | 572 | |
573 | this.sdata = sdata; | 573 | public LLUUID process() |
574 | m_itemID = itemID; | 574 | { |
575 | m_localID = localID; | 575 | httpThread = new Thread(SendRequest); |
576 | 576 | httpThread.Name = "HttpRequestThread"; | |
577 | reqID = LLUUID.Random(); | 577 | httpThread.Priority = ThreadPriority.BelowNormal; |
578 | 578 | httpThread.IsBackground = true; | |
579 | } | 579 | finished = false; |
580 | 580 | httpThread.Start(); | |
581 | public LLUUID process() | 581 | ThreadTracker.Add(httpThread); |
582 | { | 582 | |
583 | httpThread = new Thread(SendRequest); | 583 | return reqID; |
584 | httpThread.Name = "HttpRequestThread"; | 584 | |
585 | httpThread.Priority = ThreadPriority.BelowNormal; | 585 | } |
586 | httpThread.IsBackground = true; | 586 | |
587 | finished = false; | 587 | /* |
588 | httpThread.Start(); | 588 | * TODO: More work on the response codes. Right now |
589 | ThreadTracker.Add(httpThread); | 589 | * returning 200 for success or 499 for exception |
590 | 590 | */ | |
591 | return reqID; | 591 | |
592 | 592 | public void SendRequest() | |
593 | } | 593 | { |
594 | 594 | Hashtable param = new Hashtable(); | |
595 | /* | 595 | |
596 | * TODO: More work on the response codes. Right now | 596 | // Check if channel is an LLUUID |
597 | * returning 200 for success or 499 for exception | 597 | // if not, use as method name |
598 | */ | 598 | LLUUID parseUID; |
599 | 599 | string mName = "llRemoteData"; | |
600 | public void SendRequest() | 600 | if( (channel != null) && (channel != "") ) |
601 | { | 601 | if( !LLUUID.TryParse(channel, out parseUID) ) |
602 | Hashtable param = new Hashtable(); | 602 | mName = channel; |
603 | 603 | else | |
604 | // Check if channel is an LLUUID | 604 | param["Channel"] = channel; |
605 | // if not, use as method name | 605 | |
606 | LLUUID parseUID; | 606 | param["StringValue"] = sdata; |
607 | string mName = "llRemoteData"; | 607 | param["IntValue"] = Convert.ToString(idata); |
608 | if( (channel != null) && (channel != "") ) | 608 | |
609 | if( !LLUUID.TryParse(channel, out parseUID) ) | 609 | ArrayList parameters = new ArrayList(); |
610 | mName = channel; | 610 | parameters.Add(param); |
611 | else | 611 | XmlRpcRequest req = new XmlRpcRequest(mName, parameters); |
612 | param["Channel"] = channel; | 612 | try |
613 | 613 | { | |
614 | param["StringValue"] = sdata; | 614 | XmlRpcResponse resp = req.Send(destURL, 30000); |
615 | param["IntValue"] = Convert.ToString(idata); | 615 | if (resp != null) |
616 | 616 | { | |
617 | ArrayList parameters = new ArrayList(); | 617 | Hashtable respParms; |
618 | parameters.Add(param); | 618 | if(resp.Value.GetType().Equals(Type.GetType("System.Collections.Hashtable"))) { |
619 | XmlRpcRequest req = new XmlRpcRequest(mName, parameters); | 619 | respParms = (Hashtable)resp.Value; |
620 | try | 620 | } |
621 | { | 621 | else { |
622 | XmlRpcResponse resp = req.Send(destURL, 30000); | 622 | ArrayList respData = (ArrayList)resp.Value; |
623 | if (resp != null) | 623 | respParms = (Hashtable)respData[0]; |
624 | { | 624 | } |
625 | Hashtable respParms; | 625 | if (respParms != null) |
626 | if(resp.Value.GetType().Equals(Type.GetType("System.Collections.Hashtable"))) { | 626 | { |
627 | respParms = (Hashtable)resp.Value; | 627 | if (respParms.Contains("StringValue")) |
628 | } | 628 | { |
629 | else { | 629 | sdata = (string)respParms["StringValue"]; |
630 | ArrayList respData = (ArrayList)resp.Value; | 630 | } |
631 | respParms = (Hashtable)respData[0]; | 631 | if (respParms.Contains("IntValue")) |
632 | } | 632 | { |
633 | if (respParms != null) | 633 | idata = Convert.ToInt32((string)respParms["IntValue"]); |
634 | { | 634 | } |
635 | if (respParms.Contains("StringValue")) | 635 | if (respParms.Contains("faultString")) |
636 | { | 636 | { |
637 | sdata = (string)respParms["StringValue"]; | 637 | sdata = (string)respParms["faultString"]; |
638 | } | 638 | } |
639 | if (respParms.Contains("IntValue")) | 639 | if (respParms.Contains("faultCode")) |
640 | { | 640 | { |
641 | idata = Convert.ToInt32((string)respParms["IntValue"]); | 641 | idata = Convert.ToInt32(respParms["faultCode"]); |
642 | } | 642 | } |
643 | if (respParms.Contains("faultString")) | 643 | } |
644 | { | 644 | } |
645 | sdata = (string)respParms["faultString"]; | 645 | } |
646 | } | 646 | catch (WebException we) |
647 | if (respParms.Contains("faultCode")) | 647 | { |
648 | { | 648 | sdata = we.Message; |
649 | idata = Convert.ToInt32(respParms["faultCode"]); | 649 | m_log.Warn("[SendRemoteDataRequest]: Request failed"); |
650 | } | 650 | m_log.Warn(we.StackTrace); |
651 | } | 651 | } |
652 | } | 652 | |
653 | } | 653 | finished = true; |
654 | catch (WebException we) | 654 | } |
655 | { | 655 | |
656 | sdata = we.Message; | 656 | public void Stop() |
657 | m_log.Warn("[SendRemoteDataRequest]: Request failed"); | 657 | { |
658 | m_log.Warn(we.StackTrace); | 658 | try |
659 | } | 659 | { |
660 | 660 | httpThread.Abort(); | |
661 | finished = true; | 661 | } |
662 | } | 662 | catch (Exception) |
663 | 663 | { | |
664 | public void Stop() | 664 | } |
665 | { | 665 | } |
666 | try | 666 | |
667 | { | 667 | public LLUUID GetReqID() |
668 | httpThread.Abort(); | 668 | { |
669 | } | 669 | return reqID; |
670 | catch (Exception) | 670 | } |
671 | { | 671 | } |
672 | } | 672 | } \ No newline at end of file |
673 | } | ||
674 | |||
675 | public LLUUID GetReqID() | ||
676 | { | ||
677 | return reqID; | ||
678 | } | ||
679 | } | ||
680 | } | ||