aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Scripting/XMLRPC
diff options
context:
space:
mode:
authorJeff Ames2008-05-01 14:31:30 +0000
committerJeff Ames2008-05-01 14:31:30 +0000
commitd51ce47b2d7635b17f3dd429158e8f59b78b83aa (patch)
treed3595bd5194199184059aa398b91a51dc6c799cf /OpenSim/Region/Environment/Modules/Scripting/XMLRPC
parent* Looks like I had the bamboo build right in the first place - it was just th... (diff)
downloadopensim-SC-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.zip
opensim-SC-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.tar.gz
opensim-SC-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.tar.bz2
opensim-SC-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.tar.xz
Update svn properties. Minor formatting cleanup.
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Scripting/XMLRPC')
-rw-r--r--OpenSim/Region/Environment/Modules/Scripting/XMLRPC/XMLRPCModule.cs1342
1 files changed, 671 insertions, 671 deletions
diff --git a/OpenSim/Region/Environment/Modules/Scripting/XMLRPC/XMLRPCModule.cs b/OpenSim/Region/Environment/Modules/Scripting/XMLRPC/XMLRPCModule.cs
index 6ca8136..a039d42 100644
--- a/OpenSim/Region/Environment/Modules/Scripting/XMLRPC/XMLRPCModule.cs
+++ b/OpenSim/Region/Environment/Modules/Scripting/XMLRPC/XMLRPCModule.cs
@@ -1,672 +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
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Net; 31using System.Net;
32using System.Reflection; 32using System.Reflection;
33using System.Threading; 33using System.Threading;
34using libsecondlife; 34using libsecondlife;
35using log4net; 35using log4net;
36using Nini.Config; 36using Nini.Config;
37using Nwc.XmlRpc; 37using Nwc.XmlRpc;
38using OpenSim.Framework; 38using OpenSim.Framework;
39using OpenSim.Framework.Servers; 39using OpenSim.Framework.Servers;
40using OpenSim.Region.Environment.Interfaces; 40using OpenSim.Region.Environment.Interfaces;
41using OpenSim.Region.Environment.Scenes; 41using 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
76namespace OpenSim.Region.Environment.Modules.Scripting.XMLRPC 76namespace 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 string m_name = "XMLRPCModule"; 82 private string m_name = "XMLRPCModule";
83 83
84 // <channel id, RPCChannelInfo> 84 // <channel id, RPCChannelInfo>
85 private Dictionary<LLUUID, RPCChannelInfo> m_openChannels; 85 private Dictionary<LLUUID, RPCChannelInfo> m_openChannels;
86 private Dictionary<LLUUID, SendRemoteDataRequest> m_pendingSRDResponses; 86 private Dictionary<LLUUID, SendRemoteDataRequest> m_pendingSRDResponses;
87 private int m_remoteDataPort = 0; 87 private int m_remoteDataPort = 0;
88 88
89 private Dictionary<LLUUID, RPCRequestInfo> m_rpcPending; 89 private Dictionary<LLUUID, RPCRequestInfo> m_rpcPending;
90 private Dictionary<LLUUID, RPCRequestInfo> m_rpcPendingResponses; 90 private Dictionary<LLUUID, RPCRequestInfo> m_rpcPendingResponses;
91 private List<Scene> m_scenes = new List<Scene>(); 91 private List<Scene> m_scenes = new List<Scene>();
92 private int RemoteReplyScriptTimeout = 9000; 92 private int RemoteReplyScriptTimeout = 9000;
93 private int RemoteReplyScriptWait = 300; 93 private int RemoteReplyScriptWait = 300;
94 private object XMLRPCListLock = new object(); 94 private object XMLRPCListLock = new object();
95 95
96 #region IRegionModule Members 96 #region IRegionModule Members
97 97
98 public void Initialise(Scene scene, IConfigSource config) 98 public void Initialise(Scene scene, IConfigSource config)
99 { 99 {
100 try 100 try
101 { 101 {
102 m_remoteDataPort = config.Configs["Network"].GetInt("remoteDataPort", m_remoteDataPort); 102 m_remoteDataPort = config.Configs["Network"].GetInt("remoteDataPort", m_remoteDataPort);
103 } 103 }
104 catch (Exception) 104 catch (Exception)
105 { 105 {
106 } 106 }
107 107
108 if (!m_scenes.Contains(scene)) 108 if (!m_scenes.Contains(scene))
109 { 109 {
110 m_scenes.Add(scene); 110 m_scenes.Add(scene);
111 111
112 scene.RegisterModuleInterface<IXMLRPC>(this); 112 scene.RegisterModuleInterface<IXMLRPC>(this);
113 } 113 }
114 } 114 }
115 115
116 public void PostInitialise() 116 public void PostInitialise()
117 { 117 {
118 if (IsEnabled()) 118 if (IsEnabled())
119 { 119 {
120 m_openChannels = new Dictionary<LLUUID, RPCChannelInfo>(); 120 m_openChannels = new Dictionary<LLUUID, RPCChannelInfo>();
121 m_rpcPending = new Dictionary<LLUUID, RPCRequestInfo>(); 121 m_rpcPending = new Dictionary<LLUUID, RPCRequestInfo>();
122 m_rpcPendingResponses = new Dictionary<LLUUID, RPCRequestInfo>(); 122 m_rpcPendingResponses = new Dictionary<LLUUID, RPCRequestInfo>();
123 m_pendingSRDResponses = new Dictionary<LLUUID, SendRemoteDataRequest>(); 123 m_pendingSRDResponses = new Dictionary<LLUUID, SendRemoteDataRequest>();
124 124
125 // Start http server 125 // Start http server
126 // Attach xmlrpc handlers 126 // Attach xmlrpc handlers
127 m_log.Info("[REMOTE_DATA]: " + 127 m_log.Info("[REMOTE_DATA]: " +
128 "Starting XMLRPC Server on port " + m_remoteDataPort + " for llRemoteData commands."); 128 "Starting XMLRPC Server on port " + m_remoteDataPort + " for llRemoteData commands.");
129 BaseHttpServer httpServer = new BaseHttpServer((uint) m_remoteDataPort); 129 BaseHttpServer httpServer = new BaseHttpServer((uint) m_remoteDataPort);
130 httpServer.AddXmlRPCHandler("llRemoteData", XmlRpcRemoteData); 130 httpServer.AddXmlRPCHandler("llRemoteData", XmlRpcRemoteData);
131 httpServer.Start(); 131 httpServer.Start();
132 } 132 }
133 } 133 }
134 134
135 public void Close() 135 public void Close()
136 { 136 {
137 } 137 }
138 138
139 public string Name 139 public string Name
140 { 140 {
141 get { return m_name; } 141 get { return m_name; }
142 } 142 }
143 143
144 public bool IsSharedModule 144 public bool IsSharedModule
145 { 145 {
146 get { return true; } 146 get { return true; }
147 } 147 }
148 148
149 #endregion 149 #endregion
150 150
151 #region IXMLRPC Members 151 #region IXMLRPC Members
152 152
153 public bool IsEnabled() 153 public bool IsEnabled()
154 { 154 {
155 return (m_remoteDataPort > 0); 155 return (m_remoteDataPort > 0);
156 } 156 }
157 157
158 /********************************************** 158 /**********************************************
159 * OpenXMLRPCChannel 159 * OpenXMLRPCChannel
160 * 160 *
161 * Generate a LLUUID channel key and add it and 161 * Generate a LLUUID channel key and add it and
162 * the prim id to dictionary <channelUUID, primUUID> 162 * the prim id to dictionary <channelUUID, primUUID>
163 * 163 *
164 * First check if there is a channel assigned for 164 * First check if there is a channel assigned for
165 * this itemID. If there is, then someone called 165 * this itemID. If there is, then someone called
166 * llOpenRemoteDataChannel twice. Just return the 166 * llOpenRemoteDataChannel twice. Just return the
167 * original channel. Other option is to delete the 167 * original channel. Other option is to delete the
168 * current channel and assign a new one. 168 * current channel and assign a new one.
169 * 169 *
170 * ********************************************/ 170 * ********************************************/
171 171
172 public LLUUID OpenXMLRPCChannel(uint localID, LLUUID itemID) 172 public LLUUID OpenXMLRPCChannel(uint localID, LLUUID itemID)
173 { 173 {
174 LLUUID channel = new LLUUID(); 174 LLUUID channel = new LLUUID();
175 175
176 //Is a dupe? 176 //Is a dupe?
177 foreach (RPCChannelInfo ci in m_openChannels.Values) 177 foreach (RPCChannelInfo ci in m_openChannels.Values)
178 { 178 {
179 if (ci.GetItemID().Equals(itemID)) 179 if (ci.GetItemID().Equals(itemID))
180 { 180 {
181 // return the original channel ID for this item 181 // return the original channel ID for this item
182 channel = ci.GetChannelID(); 182 channel = ci.GetChannelID();
183 break; 183 break;
184 } 184 }
185 } 185 }
186 186
187 if (channel == LLUUID.Zero) 187 if (channel == LLUUID.Zero)
188 { 188 {
189 channel = LLUUID.Random(); 189 channel = LLUUID.Random();
190 RPCChannelInfo rpcChanInfo = new RPCChannelInfo(localID, itemID, channel); 190 RPCChannelInfo rpcChanInfo = new RPCChannelInfo(localID, itemID, channel);
191 lock (XMLRPCListLock) 191 lock (XMLRPCListLock)
192 { 192 {
193 m_openChannels.Add(channel, rpcChanInfo); 193 m_openChannels.Add(channel, rpcChanInfo);
194 } 194 }
195 } 195 }
196 196
197 return channel; 197 return channel;
198 } 198 }
199 199
200 // Delete channels based on itemID 200 // Delete channels based on itemID
201 // for when a script is deleted 201 // for when a script is deleted
202 public void DeleteChannels(LLUUID itemID) 202 public void DeleteChannels(LLUUID itemID)
203 { 203 {
204 if (m_openChannels != null) 204 if (m_openChannels != null)
205 { 205 {
206 ArrayList tmp = new ArrayList(); 206 ArrayList tmp = new ArrayList();
207 207
208 lock (XMLRPCListLock) 208 lock (XMLRPCListLock)
209 { 209 {
210 foreach (RPCChannelInfo li in m_openChannels.Values) 210 foreach (RPCChannelInfo li in m_openChannels.Values)
211 { 211 {
212 if (li.GetItemID().Equals(itemID)) 212 if (li.GetItemID().Equals(itemID))
213 { 213 {
214 tmp.Add(itemID); 214 tmp.Add(itemID);
215 } 215 }
216 } 216 }
217 217
218 IEnumerator tmpEnumerator = tmp.GetEnumerator(); 218 IEnumerator tmpEnumerator = tmp.GetEnumerator();
219 while (tmpEnumerator.MoveNext()) 219 while (tmpEnumerator.MoveNext())
220 m_openChannels.Remove((LLUUID) tmpEnumerator.Current); 220 m_openChannels.Remove((LLUUID) tmpEnumerator.Current);
221 } 221 }
222 } 222 }
223 } 223 }
224 224
225 /********************************************** 225 /**********************************************
226 * Remote Data Reply 226 * Remote Data Reply
227 * 227 *
228 * Response to RPC message 228 * Response to RPC message
229 * 229 *
230 *********************************************/ 230 *********************************************/
231 231
232 public void RemoteDataReply(string channel, string message_id, string sdata, int idata) 232 public void RemoteDataReply(string channel, string message_id, string sdata, int idata)
233 { 233 {
234 RPCRequestInfo rpcInfo; 234 RPCRequestInfo rpcInfo;
235 LLUUID message_key = new LLUUID(message_id); 235 LLUUID message_key = new LLUUID(message_id);
236 236
237 if (m_rpcPendingResponses.TryGetValue(message_key, out rpcInfo)) 237 if (m_rpcPendingResponses.TryGetValue(message_key, out rpcInfo))
238 { 238 {
239 rpcInfo.SetStrRetval(sdata); 239 rpcInfo.SetStrRetval(sdata);
240 rpcInfo.SetIntRetval(idata); 240 rpcInfo.SetIntRetval(idata);
241 rpcInfo.SetProcessed(true); 241 rpcInfo.SetProcessed(true);
242 m_rpcPendingResponses.Remove(message_key); 242 m_rpcPendingResponses.Remove(message_key);
243 } 243 }
244 } 244 }
245 245
246 /********************************************** 246 /**********************************************
247 * CloseXMLRPCChannel 247 * CloseXMLRPCChannel
248 * 248 *
249 * Remove channel from dictionary 249 * Remove channel from dictionary
250 * 250 *
251 *********************************************/ 251 *********************************************/
252 252
253 public void CloseXMLRPCChannel(LLUUID channelKey) 253 public void CloseXMLRPCChannel(LLUUID channelKey)
254 { 254 {
255 if (m_openChannels.ContainsKey(channelKey)) 255 if (m_openChannels.ContainsKey(channelKey))
256 m_openChannels.Remove(channelKey); 256 m_openChannels.Remove(channelKey);
257 } 257 }
258 258
259 259
260 public bool hasRequests() 260 public bool hasRequests()
261 { 261 {
262 lock (XMLRPCListLock) 262 lock (XMLRPCListLock)
263 { 263 {
264 if (m_rpcPending != null) 264 if (m_rpcPending != null)
265 return (m_rpcPending.Count > 0); 265 return (m_rpcPending.Count > 0);
266 else 266 else
267 return false; 267 return false;
268 } 268 }
269 } 269 }
270 270
271 public RPCRequestInfo GetNextCompletedRequest() 271 public RPCRequestInfo GetNextCompletedRequest()
272 { 272 {
273 if (m_rpcPending != null) 273 if (m_rpcPending != null)
274 { 274 {
275 lock (XMLRPCListLock) 275 lock (XMLRPCListLock)
276 { 276 {
277 foreach (LLUUID luid in m_rpcPending.Keys) 277 foreach (LLUUID luid in m_rpcPending.Keys)
278 { 278 {
279 RPCRequestInfo tmpReq; 279 RPCRequestInfo tmpReq;
280 280
281 if (m_rpcPending.TryGetValue(luid, out tmpReq)) 281 if (m_rpcPending.TryGetValue(luid, out tmpReq))
282 { 282 {
283 if (!tmpReq.IsProcessed()) return tmpReq; 283 if (!tmpReq.IsProcessed()) return tmpReq;
284 } 284 }
285 } 285 }
286 } 286 }
287 } 287 }
288 return null; 288 return null;
289 } 289 }
290 290
291 public void RemoveCompletedRequest(LLUUID id) 291 public void RemoveCompletedRequest(LLUUID id)
292 { 292 {
293 lock (XMLRPCListLock) 293 lock (XMLRPCListLock)
294 { 294 {
295 RPCRequestInfo tmp; 295 RPCRequestInfo tmp;
296 if (m_rpcPending.TryGetValue(id, out tmp)) 296 if (m_rpcPending.TryGetValue(id, out tmp))
297 { 297 {
298 m_rpcPending.Remove(id); 298 m_rpcPending.Remove(id);
299 m_rpcPendingResponses.Add(id, tmp); 299 m_rpcPendingResponses.Add(id, tmp);
300 } 300 }
301 else 301 else
302 { 302 {
303 Console.WriteLine("UNABLE TO REMOVE COMPLETED REQUEST"); 303 Console.WriteLine("UNABLE TO REMOVE COMPLETED REQUEST");
304 } 304 }
305 } 305 }
306 } 306 }
307 307
308 public LLUUID SendRemoteData(uint localID, LLUUID itemID, string channel, string dest, int idata, string sdata) 308 public LLUUID SendRemoteData(uint localID, LLUUID itemID, string channel, string dest, int idata, string sdata)
309 { 309 {
310 SendRemoteDataRequest req = new SendRemoteDataRequest( 310 SendRemoteDataRequest req = new SendRemoteDataRequest(
311 localID, itemID, channel, dest, idata, sdata 311 localID, itemID, channel, dest, idata, sdata
312 ); 312 );
313 m_pendingSRDResponses.Add(req.GetReqID(), req); 313 m_pendingSRDResponses.Add(req.GetReqID(), req);
314 return req.process(); 314 return req.process();
315 } 315 }
316 316
317 public SendRemoteDataRequest GetNextCompletedSRDRequest() 317 public SendRemoteDataRequest GetNextCompletedSRDRequest()
318 { 318 {
319 if (m_pendingSRDResponses != null) 319 if (m_pendingSRDResponses != null)
320 { 320 {
321 lock (XMLRPCListLock) 321 lock (XMLRPCListLock)
322 { 322 {
323 foreach (LLUUID luid in m_pendingSRDResponses.Keys) 323 foreach (LLUUID luid in m_pendingSRDResponses.Keys)
324 { 324 {
325 SendRemoteDataRequest tmpReq; 325 SendRemoteDataRequest tmpReq;
326 326
327 if (m_pendingSRDResponses.TryGetValue(luid, out tmpReq)) 327 if (m_pendingSRDResponses.TryGetValue(luid, out tmpReq))
328 { 328 {
329 if (tmpReq.finished) 329 if (tmpReq.finished)
330 return tmpReq; 330 return tmpReq;
331 } 331 }
332 } 332 }
333 } 333 }
334 } 334 }
335 return null; 335 return null;
336 } 336 }
337 337
338 public void RemoveCompletedSRDRequest(LLUUID id) 338 public void RemoveCompletedSRDRequest(LLUUID id)
339 { 339 {
340 lock (XMLRPCListLock) 340 lock (XMLRPCListLock)
341 { 341 {
342 SendRemoteDataRequest tmpReq; 342 SendRemoteDataRequest tmpReq;
343 if (m_pendingSRDResponses.TryGetValue(id, out tmpReq)) 343 if (m_pendingSRDResponses.TryGetValue(id, out tmpReq))
344 { 344 {
345 m_pendingSRDResponses.Remove(id); 345 m_pendingSRDResponses.Remove(id);
346 } 346 }
347 } 347 }
348 } 348 }
349 349
350 public void CancelSRDRequests(LLUUID itemID) 350 public void CancelSRDRequests(LLUUID itemID)
351 { 351 {
352 if (m_pendingSRDResponses != null) 352 if (m_pendingSRDResponses != null)
353 { 353 {
354 lock (XMLRPCListLock) 354 lock (XMLRPCListLock)
355 { 355 {
356 foreach (SendRemoteDataRequest li in m_pendingSRDResponses.Values) 356 foreach (SendRemoteDataRequest li in m_pendingSRDResponses.Values)
357 { 357 {
358 if (li.m_itemID.Equals(itemID)) 358 if (li.m_itemID.Equals(itemID))
359 m_pendingSRDResponses.Remove(li.GetReqID()); 359 m_pendingSRDResponses.Remove(li.GetReqID());
360 } 360 }
361 } 361 }
362 } 362 }
363 } 363 }
364 364
365 #endregion 365 #endregion
366 366
367 public XmlRpcResponse XmlRpcRemoteData(XmlRpcRequest request) 367 public XmlRpcResponse XmlRpcRemoteData(XmlRpcRequest request)
368 { 368 {
369 XmlRpcResponse response = new XmlRpcResponse(); 369 XmlRpcResponse response = new XmlRpcResponse();
370 370
371 Hashtable requestData = (Hashtable) request.Params[0]; 371 Hashtable requestData = (Hashtable) request.Params[0];
372 bool GoodXML = (requestData.Contains("Channel") && requestData.Contains("IntValue") && 372 bool GoodXML = (requestData.Contains("Channel") && requestData.Contains("IntValue") &&
373 requestData.Contains("StringValue")); 373 requestData.Contains("StringValue"));
374 374
375 if (GoodXML) 375 if (GoodXML)
376 { 376 {
377 LLUUID channel = new LLUUID((string) requestData["Channel"]); 377 LLUUID channel = new LLUUID((string) requestData["Channel"]);
378 RPCChannelInfo rpcChanInfo; 378 RPCChannelInfo rpcChanInfo;
379 if (m_openChannels.TryGetValue(channel, out rpcChanInfo)) 379 if (m_openChannels.TryGetValue(channel, out rpcChanInfo))
380 { 380 {
381 string intVal = (string) requestData["IntValue"]; 381 string intVal = (string) requestData["IntValue"];
382 string strVal = (string) requestData["StringValue"]; 382 string strVal = (string) requestData["StringValue"];
383 383
384 RPCRequestInfo rpcInfo; 384 RPCRequestInfo rpcInfo;
385 385
386 lock (XMLRPCListLock) 386 lock (XMLRPCListLock)
387 { 387 {
388 rpcInfo = 388 rpcInfo =
389 new RPCRequestInfo(rpcChanInfo.GetLocalID(), rpcChanInfo.GetItemID(), channel, strVal, 389 new RPCRequestInfo(rpcChanInfo.GetLocalID(), rpcChanInfo.GetItemID(), channel, strVal,
390 intVal); 390 intVal);
391 m_rpcPending.Add(rpcInfo.GetMessageID(), rpcInfo); 391 m_rpcPending.Add(rpcInfo.GetMessageID(), rpcInfo);
392 } 392 }
393 393
394 int timeoutCtr = 0; 394 int timeoutCtr = 0;
395 395
396 while (!rpcInfo.IsProcessed() && (timeoutCtr < RemoteReplyScriptTimeout)) 396 while (!rpcInfo.IsProcessed() && (timeoutCtr < RemoteReplyScriptTimeout))
397 { 397 {
398 Thread.Sleep(RemoteReplyScriptWait); 398 Thread.Sleep(RemoteReplyScriptWait);
399 timeoutCtr += RemoteReplyScriptWait; 399 timeoutCtr += RemoteReplyScriptWait;
400 } 400 }
401 if (rpcInfo.IsProcessed()) 401 if (rpcInfo.IsProcessed())
402 { 402 {
403 Hashtable param = new Hashtable(); 403 Hashtable param = new Hashtable();
404 param["StringValue"] = rpcInfo.GetStrRetval(); 404 param["StringValue"] = rpcInfo.GetStrRetval();
405 param["IntValue"] = Convert.ToString(rpcInfo.GetIntRetval()); 405 param["IntValue"] = Convert.ToString(rpcInfo.GetIntRetval());
406 406
407 ArrayList parameters = new ArrayList(); 407 ArrayList parameters = new ArrayList();
408 parameters.Add(param); 408 parameters.Add(param);
409 409
410 response.Value = parameters; 410 response.Value = parameters;
411 rpcInfo = null; 411 rpcInfo = null;
412 } 412 }
413 else 413 else
414 { 414 {
415 response.SetFault(-1, "Script timeout"); 415 response.SetFault(-1, "Script timeout");
416 rpcInfo = null; 416 rpcInfo = null;
417 } 417 }
418 } 418 }
419 else 419 else
420 { 420 {
421 response.SetFault(-1, "Invalid channel"); 421 response.SetFault(-1, "Invalid channel");
422 } 422 }
423 } 423 }
424 424
425 return response; 425 return response;
426 } 426 }
427 } 427 }
428 428
429 public class RPCRequestInfo 429 public class RPCRequestInfo
430 { 430 {
431 private LLUUID m_ChannelKey; 431 private LLUUID m_ChannelKey;
432 private string m_IntVal; 432 private string m_IntVal;
433 private LLUUID m_ItemID; 433 private LLUUID m_ItemID;
434 private uint m_localID; 434 private uint m_localID;
435 private LLUUID m_MessageID; 435 private LLUUID m_MessageID;
436 private bool m_processed; 436 private bool m_processed;
437 private int m_respInt; 437 private int m_respInt;
438 private string m_respStr; 438 private string m_respStr;
439 private string m_StrVal; 439 private string m_StrVal;
440 440
441 public RPCRequestInfo(uint localID, LLUUID itemID, LLUUID channelKey, string strVal, string intVal) 441 public RPCRequestInfo(uint localID, LLUUID itemID, LLUUID channelKey, string strVal, string intVal)
442 { 442 {
443 m_localID = localID; 443 m_localID = localID;
444 m_StrVal = strVal; 444 m_StrVal = strVal;
445 m_IntVal = intVal; 445 m_IntVal = intVal;
446 m_ItemID = itemID; 446 m_ItemID = itemID;
447 m_ChannelKey = channelKey; 447 m_ChannelKey = channelKey;
448 m_MessageID = LLUUID.Random(); 448 m_MessageID = LLUUID.Random();
449 m_processed = false; 449 m_processed = false;
450 m_respStr = String.Empty; 450 m_respStr = String.Empty;
451 m_respInt = 0; 451 m_respInt = 0;
452 } 452 }
453 453
454 public bool IsProcessed() 454 public bool IsProcessed()
455 { 455 {
456 return m_processed; 456 return m_processed;
457 } 457 }
458 458
459 public LLUUID GetChannelKey() 459 public LLUUID GetChannelKey()
460 { 460 {
461 return m_ChannelKey; 461 return m_ChannelKey;
462 } 462 }
463 463
464 public void SetProcessed(bool processed) 464 public void SetProcessed(bool processed)
465 { 465 {
466 m_processed = processed; 466 m_processed = processed;
467 } 467 }
468 468
469 public void SetStrRetval(string resp) 469 public void SetStrRetval(string resp)
470 { 470 {
471 m_respStr = resp; 471 m_respStr = resp;
472 } 472 }
473 473
474 public string GetStrRetval() 474 public string GetStrRetval()
475 { 475 {
476 return m_respStr; 476 return m_respStr;
477 } 477 }
478 478
479 public void SetIntRetval(int resp) 479 public void SetIntRetval(int resp)
480 { 480 {
481 m_respInt = resp; 481 m_respInt = resp;
482 } 482 }
483 483
484 public int GetIntRetval() 484 public int GetIntRetval()
485 { 485 {
486 return m_respInt; 486 return m_respInt;
487 } 487 }
488 488
489 public uint GetLocalID() 489 public uint GetLocalID()
490 { 490 {
491 return m_localID; 491 return m_localID;
492 } 492 }
493 493
494 public LLUUID GetItemID() 494 public LLUUID GetItemID()
495 { 495 {
496 return m_ItemID; 496 return m_ItemID;
497 } 497 }
498 498
499 public string GetStrVal() 499 public string GetStrVal()
500 { 500 {
501 return m_StrVal; 501 return m_StrVal;
502 } 502 }
503 503
504 public int GetIntValue() 504 public int GetIntValue()
505 { 505 {
506 return int.Parse(m_IntVal); 506 return int.Parse(m_IntVal);
507 } 507 }
508 508
509 public LLUUID GetMessageID() 509 public LLUUID GetMessageID()
510 { 510 {
511 return m_MessageID; 511 return m_MessageID;
512 } 512 }
513 } 513 }
514 514
515 public class RPCChannelInfo 515 public class RPCChannelInfo
516 { 516 {
517 private LLUUID m_ChannelKey; 517 private LLUUID m_ChannelKey;
518 private LLUUID m_itemID; 518 private LLUUID m_itemID;
519 private uint m_localID; 519 private uint m_localID;
520 520
521 public RPCChannelInfo(uint localID, LLUUID itemID, LLUUID channelID) 521 public RPCChannelInfo(uint localID, LLUUID itemID, LLUUID channelID)
522 { 522 {
523 m_ChannelKey = channelID; 523 m_ChannelKey = channelID;
524 m_localID = localID; 524 m_localID = localID;
525 m_itemID = itemID; 525 m_itemID = itemID;
526 } 526 }
527 527
528 public LLUUID GetItemID() 528 public LLUUID GetItemID()
529 { 529 {
530 return m_itemID; 530 return m_itemID;
531 } 531 }
532 532
533 public LLUUID GetChannelID() 533 public LLUUID GetChannelID()
534 { 534 {
535 return m_ChannelKey; 535 return m_ChannelKey;
536 } 536 }
537 537
538 public uint GetLocalID() 538 public uint GetLocalID()
539 { 539 {
540 return m_localID; 540 return m_localID;
541 } 541 }
542 } 542 }
543 543
544 public class SendRemoteDataRequest 544 public class SendRemoteDataRequest
545 { 545 {
546 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 546 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
547 public string channel; 547 public string channel;
548 public string destURL; 548 public string destURL;
549 public bool finished; 549 public bool finished;
550 private Thread httpThread; 550 private Thread httpThread;
551 public int idata; 551 public int idata;
552 public LLUUID m_itemID; 552 public LLUUID m_itemID;
553 public uint m_localID; 553 public uint m_localID;
554 public LLUUID reqID; 554 public LLUUID reqID;
555 public XmlRpcRequest request; 555 public XmlRpcRequest request;
556 public int response_idata; 556 public int response_idata;
557 public string response_sdata; 557 public string response_sdata;
558 public string sdata; 558 public string sdata;
559 559
560 public SendRemoteDataRequest(uint localID, LLUUID itemID, string channel, string dest, int idata, string sdata) 560 public SendRemoteDataRequest(uint localID, LLUUID itemID, string channel, string dest, int idata, string sdata)
561 { 561 {
562 this.channel = channel; 562 this.channel = channel;
563 destURL = dest; 563 destURL = dest;
564 this.idata = idata; 564 this.idata = idata;
565 this.sdata = sdata; 565 this.sdata = sdata;
566 m_itemID = itemID; 566 m_itemID = itemID;
567 m_localID = localID; 567 m_localID = localID;
568 568
569 reqID = LLUUID.Random(); 569 reqID = LLUUID.Random();
570 } 570 }
571 571
572 public LLUUID process() 572 public LLUUID process()
573 { 573 {
574 httpThread = new Thread(SendRequest); 574 httpThread = new Thread(SendRequest);
575 httpThread.Name = "HttpRequestThread"; 575 httpThread.Name = "HttpRequestThread";
576 httpThread.Priority = ThreadPriority.BelowNormal; 576 httpThread.Priority = ThreadPriority.BelowNormal;
577 httpThread.IsBackground = true; 577 httpThread.IsBackground = true;
578 finished = false; 578 finished = false;
579 httpThread.Start(); 579 httpThread.Start();
580 ThreadTracker.Add(httpThread); 580 ThreadTracker.Add(httpThread);
581 581
582 return reqID; 582 return reqID;
583 } 583 }
584 584
585 /* 585 /*
586 * TODO: More work on the response codes. Right now 586 * TODO: More work on the response codes. Right now
587 * returning 200 for success or 499 for exception 587 * returning 200 for success or 499 for exception
588 */ 588 */
589 589
590 public void SendRequest() 590 public void SendRequest()
591 { 591 {
592 Hashtable param = new Hashtable(); 592 Hashtable param = new Hashtable();
593 593
594 // Check if channel is an LLUUID 594 // Check if channel is an LLUUID
595 // if not, use as method name 595 // if not, use as method name
596 LLUUID parseUID; 596 LLUUID parseUID;
597 string mName = "llRemoteData"; 597 string mName = "llRemoteData";
598 if ((channel != null) && (channel != "")) 598 if ((channel != null) && (channel != ""))
599 if (!LLUUID.TryParse(channel, out parseUID)) 599 if (!LLUUID.TryParse(channel, out parseUID))
600 mName = channel; 600 mName = channel;
601 else 601 else
602 param["Channel"] = channel; 602 param["Channel"] = channel;
603 603
604 param["StringValue"] = sdata; 604 param["StringValue"] = sdata;
605 param["IntValue"] = Convert.ToString(idata); 605 param["IntValue"] = Convert.ToString(idata);
606 606
607 ArrayList parameters = new ArrayList(); 607 ArrayList parameters = new ArrayList();
608 parameters.Add(param); 608 parameters.Add(param);
609 XmlRpcRequest req = new XmlRpcRequest(mName, parameters); 609 XmlRpcRequest req = new XmlRpcRequest(mName, parameters);
610 try 610 try
611 { 611 {
612 XmlRpcResponse resp = req.Send(destURL, 30000); 612 XmlRpcResponse resp = req.Send(destURL, 30000);
613 if (resp != null) 613 if (resp != null)
614 { 614 {
615 Hashtable respParms; 615 Hashtable respParms;
616 if (resp.Value.GetType().Equals(Type.GetType("System.Collections.Hashtable"))) 616 if (resp.Value.GetType().Equals(Type.GetType("System.Collections.Hashtable")))
617 { 617 {
618 respParms = (Hashtable) resp.Value; 618 respParms = (Hashtable) resp.Value;
619 } 619 }
620 else 620 else
621 { 621 {
622 ArrayList respData = (ArrayList) resp.Value; 622 ArrayList respData = (ArrayList) resp.Value;
623 respParms = (Hashtable) respData[0]; 623 respParms = (Hashtable) respData[0];
624 } 624 }
625 if (respParms != null) 625 if (respParms != null)
626 { 626 {
627 if (respParms.Contains("StringValue")) 627 if (respParms.Contains("StringValue"))
628 { 628 {
629 sdata = (string) respParms["StringValue"]; 629 sdata = (string) respParms["StringValue"];
630 } 630 }
631 if (respParms.Contains("IntValue")) 631 if (respParms.Contains("IntValue"))
632 { 632 {
633 idata = Convert.ToInt32((string) respParms["IntValue"]); 633 idata = Convert.ToInt32((string) respParms["IntValue"]);
634 } 634 }
635 if (respParms.Contains("faultString")) 635 if (respParms.Contains("faultString"))
636 { 636 {
637 sdata = (string) respParms["faultString"]; 637 sdata = (string) respParms["faultString"];
638 } 638 }
639 if (respParms.Contains("faultCode")) 639 if (respParms.Contains("faultCode"))
640 { 640 {
641 idata = Convert.ToInt32(respParms["faultCode"]); 641 idata = Convert.ToInt32(respParms["faultCode"]);
642 } 642 }
643 } 643 }
644 } 644 }
645 } 645 }
646 catch (WebException we) 646 catch (WebException we)
647 { 647 {
648 sdata = we.Message; 648 sdata = we.Message;
649 m_log.Warn("[SendRemoteDataRequest]: Request failed"); 649 m_log.Warn("[SendRemoteDataRequest]: Request failed");
650 m_log.Warn(we.StackTrace); 650 m_log.Warn(we.StackTrace);
651 } 651 }
652 652
653 finished = true; 653 finished = true;
654 } 654 }
655 655
656 public void Stop() 656 public void Stop()
657 { 657 {
658 try 658 try
659 { 659 {
660 httpThread.Abort(); 660 httpThread.Abort();
661 } 661 }
662 catch (Exception) 662 catch (Exception)
663 { 663 {
664 } 664 }
665 } 665 }
666 666
667 public LLUUID GetReqID() 667 public LLUUID GetReqID()
668 { 668 {
669 return reqID; 669 return reqID;
670 } 670 }
671 } 671 }
672} \ No newline at end of file 672} \ No newline at end of file