aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs4
-rw-r--r--OpenSim/Framework/BlockingQueue.cs148
-rw-r--r--OpenSim/Framework/Console/RemoteConsole.cs3
-rw-r--r--OpenSim/Framework/InventoryItemBase.cs36
-rw-r--r--OpenSim/Framework/LLSDxmlEncode.cs725
-rw-r--r--OpenSim/Framework/MinHeap.cs150
-rw-r--r--OpenSim/Framework/Monitoring/JobEngine.cs4
-rw-r--r--OpenSim/Framework/Monitoring/Stats/Stat.cs4
-rw-r--r--OpenSim/Framework/NetworkServersInfo.cs4
-rw-r--r--OpenSim/Framework/PhysicsInertia.cs2
-rw-r--r--OpenSim/Framework/PrimitiveBaseShape.cs2
-rw-r--r--OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs4
-rw-r--r--OpenSim/Framework/Serialization/External/LandDataSerializer.cs1
-rw-r--r--OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs1
-rw-r--r--OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs2
-rw-r--r--OpenSim/Framework/Servers/BaseOpenSimServer.cs28
-rw-r--r--OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs252
-rw-r--r--OpenSim/Framework/Servers/HttpServer/Interfaces/IOSHttpResponse.cs2
-rw-r--r--OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs4
-rw-r--r--OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs5
-rw-r--r--OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs30
-rw-r--r--OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs188
-rw-r--r--OpenSim/Framework/Servers/HttpServer/RestDeserialiseHandler.cs2
-rw-r--r--OpenSim/Framework/Servers/HttpServer/RestSessionService.cs4
-rw-r--r--OpenSim/Framework/Servers/MainServer.cs16
-rw-r--r--OpenSim/Framework/Util.cs12
-rw-r--r--OpenSim/Framework/VersionInfo.cs4
27 files changed, 1227 insertions, 410 deletions
diff --git a/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs b/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs
index 097ad7d..efccc35 100644
--- a/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs
+++ b/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs
@@ -42,11 +42,13 @@ namespace OpenSim.Framework.AssetLoader.Filesystem
42 public class AssetLoaderFileSystem : IAssetLoader 42 public class AssetLoaderFileSystem : IAssetLoader
43 { 43 {
44 private static readonly UUID LIBRARY_OWNER_ID = new UUID("11111111-1111-0000-0000-000100bba000"); 44 private static readonly UUID LIBRARY_OWNER_ID = new UUID("11111111-1111-0000-0000-000100bba000");
45 private static readonly string LIBRARY_OWNER_IDstr = "11111111-1111-0000-0000-000100bba000";
46
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46 48
47 protected static AssetBase CreateAsset(string assetIdStr, string name, string path, sbyte type) 49 protected static AssetBase CreateAsset(string assetIdStr, string name, string path, sbyte type)
48 { 50 {
49 AssetBase asset = new AssetBase(new UUID(assetIdStr), name, type, LIBRARY_OWNER_ID.ToString()); 51 AssetBase asset = new AssetBase(new UUID(assetIdStr), name, type, LIBRARY_OWNER_IDstr);
50 52
51 if (!String.IsNullOrEmpty(path)) 53 if (!String.IsNullOrEmpty(path))
52 { 54 {
diff --git a/OpenSim/Framework/BlockingQueue.cs b/OpenSim/Framework/BlockingQueue.cs
deleted file mode 100644
index 2461049..0000000
--- a/OpenSim/Framework/BlockingQueue.cs
+++ /dev/null
@@ -1,148 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System.Collections.Generic;
29using System.Threading;
30
31namespace OpenSim.Framework
32{
33 public class BlockingQueue<T>
34 {
35 private readonly Queue<T> m_pqueue = new Queue<T>();
36 private readonly Queue<T> m_queue = new Queue<T>();
37 private readonly object m_queueSync = new object();
38
39 public void PriorityEnqueue(T value)
40 {
41 lock (m_queueSync)
42 {
43 m_pqueue.Enqueue(value);
44 Monitor.Pulse(m_queueSync);
45 }
46 }
47
48 public void Enqueue(T value)
49 {
50 lock (m_queueSync)
51 {
52 m_queue.Enqueue(value);
53 Monitor.Pulse(m_queueSync);
54 }
55 }
56
57 public T Dequeue()
58 {
59 lock (m_queueSync)
60 {
61 while (m_queue.Count < 1 && m_pqueue.Count < 1)
62 {
63 Monitor.Wait(m_queueSync);
64 }
65
66 if (m_pqueue.Count > 0)
67 return m_pqueue.Dequeue();
68
69 if (m_queue.Count > 0)
70 return m_queue.Dequeue();
71 return default(T);
72 }
73 }
74
75 public T Dequeue(int msTimeout)
76 {
77 lock (m_queueSync)
78 {
79 if (m_queue.Count < 1 && m_pqueue.Count < 1)
80 {
81 if(!Monitor.Wait(m_queueSync, msTimeout))
82 return default(T);
83 }
84
85 if (m_pqueue.Count > 0)
86 return m_pqueue.Dequeue();
87 if (m_queue.Count > 0)
88 return m_queue.Dequeue();
89 return default(T);
90 }
91 }
92
93 /// <summary>
94 /// Indicate whether this queue contains the given item.
95 /// </summary>
96 /// <remarks>
97 /// This method is not thread-safe. Do not rely on the result without consistent external locking.
98 /// </remarks>
99 public bool Contains(T item)
100 {
101 lock (m_queueSync)
102 {
103 if (m_queue.Count < 1 && m_pqueue.Count < 1)
104 return false;
105
106 if (m_pqueue.Contains(item))
107 return true;
108 return m_queue.Contains(item);
109 }
110 }
111
112 /// <summary>
113 /// Return a count of the number of requests on this queue.
114 /// </summary>
115 public int Count()
116 {
117 lock (m_queueSync)
118 return m_queue.Count + m_pqueue.Count;
119 }
120
121 /// <summary>
122 /// Return the array of items on this queue.
123 /// </summary>
124 /// <remarks>
125 /// This method is not thread-safe. Do not rely on the result without consistent external locking.
126 /// </remarks>
127 public T[] GetQueueArray()
128 {
129 lock (m_queueSync)
130 {
131 if (m_queue.Count < 1 && m_pqueue.Count < 1)
132 return new T[0];
133
134 return m_queue.ToArray();
135 }
136 }
137
138 public void Clear()
139 {
140 lock (m_queueSync)
141 {
142 m_pqueue.Clear();
143 m_queue.Clear();
144 Monitor.Pulse(m_queueSync);
145 }
146 }
147 }
148}
diff --git a/OpenSim/Framework/Console/RemoteConsole.cs b/OpenSim/Framework/Console/RemoteConsole.cs
index f59c902..24f01b0 100644
--- a/OpenSim/Framework/Console/RemoteConsole.cs
+++ b/OpenSim/Framework/Console/RemoteConsole.cs
@@ -403,7 +403,7 @@ namespace OpenSim.Framework.Console
403 string uri = "/ReadResponses/" + sessionID.ToString() + "/"; 403 string uri = "/ReadResponses/" + sessionID.ToString() + "/";
404 404
405 m_Server.AddPollServiceHTTPHandler( 405 m_Server.AddPollServiceHTTPHandler(
406 uri, new PollServiceEventArgs(null, uri, HasEvents, GetEvents, NoEvents, sessionID,25000)); // 25 secs timeout 406 uri, new PollServiceEventArgs(null, uri, HasEvents, GetEvents, NoEvents, null, sessionID,25000)); // 25 secs timeout
407 407
408 // Our reply is an XML document. 408 // Our reply is an XML document.
409 // TODO: Change this to Linq.Xml 409 // TODO: Change this to Linq.Xml
@@ -687,7 +687,6 @@ namespace OpenSim.Framework.Console
687 result["int_response_code"] = 200; 687 result["int_response_code"] = 200;
688 result["content_type"] = "application/xml"; 688 result["content_type"] = "application/xml";
689 result["keepalive"] = false; 689 result["keepalive"] = false;
690 result["reusecontext"] = false;
691 result = CheckOrigin(result); 690 result = CheckOrigin(result);
692 691
693 return result; 692 return result;
diff --git a/OpenSim/Framework/InventoryItemBase.cs b/OpenSim/Framework/InventoryItemBase.cs
index c359a0c..b7f27bd 100644
--- a/OpenSim/Framework/InventoryItemBase.cs
+++ b/OpenSim/Framework/InventoryItemBase.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Text;
29using OpenMetaverse; 30using OpenMetaverse;
30 31
31namespace OpenSim.Framework 32namespace OpenSim.Framework
@@ -415,5 +416,40 @@ namespace OpenSim.Framework
415 { 416 {
416 return MemberwiseClone(); 417 return MemberwiseClone();
417 } 418 }
419
420 public void ToLLSDxml(StringBuilder lsl)
421 {
422 LLSDxmlEncode.AddMap(lsl);
423 LLSDxmlEncode.AddElem("parent_id", Folder, lsl);
424 LLSDxmlEncode.AddElem("asset_id", AssetID, lsl);
425 LLSDxmlEncode.AddElem("item_id", ID, lsl);
426
427 LLSDxmlEncode.AddMap("permissions",lsl);
428 LLSDxmlEncode.AddElem("creator_id", CreatorIdAsUuid, lsl);
429 LLSDxmlEncode.AddElem("owner_id", Owner, lsl);
430 LLSDxmlEncode.AddElem("group_id", GroupID, lsl);
431 LLSDxmlEncode.AddElem("base_mask", (int)CurrentPermissions, lsl);
432 LLSDxmlEncode.AddElem("owner_mask", (int)CurrentPermissions, lsl);
433 LLSDxmlEncode.AddElem("group_mask", (int)GroupPermissions, lsl);
434 LLSDxmlEncode.AddElem("everyone_mask", (int)EveryOnePermissions, lsl);
435 LLSDxmlEncode.AddElem("next_owner_mask", (int)NextPermissions, lsl);
436 LLSDxmlEncode.AddElem("is_owner_group", GroupOwned, lsl);
437 LLSDxmlEncode.AddEndMap(lsl);
438
439 LLSDxmlEncode.AddElem("type", AssetType, lsl);
440 LLSDxmlEncode.AddElem("inv_type", InvType, lsl);
441 LLSDxmlEncode.AddElem("flags", ((int)Flags) & 0xff, lsl);
442
443 LLSDxmlEncode.AddMap("sale_info",lsl);
444 LLSDxmlEncode.AddElem("sale_price", SalePrice, lsl);
445 LLSDxmlEncode.AddElem("sale_type", SaleType, lsl);
446 LLSDxmlEncode.AddEndMap(lsl);
447
448 LLSDxmlEncode.AddElem("name", Name, lsl);
449 LLSDxmlEncode.AddElem("desc", Description, lsl);
450 LLSDxmlEncode.AddElem("created_at", CreationDate, lsl);
451
452 LLSDxmlEncode.AddEndMap(lsl);
453 }
418 } 454 }
419} 455}
diff --git a/OpenSim/Framework/LLSDxmlEncode.cs b/OpenSim/Framework/LLSDxmlEncode.cs
new file mode 100644
index 0000000..a740866
--- /dev/null
+++ b/OpenSim/Framework/LLSDxmlEncode.cs
@@ -0,0 +1,725 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28// a class for low level LLSD encoding into a provided StringBuilder
29// for cases where we already need to know the low level detail
30// and so using something like OSD or even protbuf is just a pure waste
31
32using System;
33using System.Globalization;
34using System.Text;
35using OpenMetaverse;
36
37namespace OpenSim.Framework
38{
39 public static class LLSDxmlEncode
40 {
41 static readonly DateTime depoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
42
43 public static void AddStart(StringBuilder sb, bool addxmlversion = false)
44 {
45 if(addxmlversion)
46 sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><llsd>"); // legacy llsd xml name still valid
47 else
48 sb.Append("<llsd>");
49 }
50
51 // got tired of creating a stringbuilder all the time;
52 public static StringBuilder Start(int size = 256, bool addxmlversion = false)
53 {
54 StringBuilder sb = new StringBuilder(size);
55 if(addxmlversion)
56 sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><llsd>"); // legacy llsd xml name still valid
57 else
58 sb.Append("<llsd>");
59 return sb;
60 }
61
62 public static void AddEnd(StringBuilder sb)
63 {
64 sb.Append("</llsd>");
65 }
66
67 public static string End(StringBuilder sb)
68 {
69 sb.Append("</llsd>");
70 return sb.ToString();
71 }
72
73 // map == a list of key value pairs
74 public static void AddMap(StringBuilder sb)
75 {
76 sb.Append("<map>");
77 }
78
79 public static void AddEndMap(StringBuilder sb)
80 {
81 sb.Append("</map>");
82 }
83
84 public static void AddEmptyMap(StringBuilder sb)
85 {
86 sb.Append("<map />");
87 }
88
89 // array == a list values
90 public static void AddArray(StringBuilder sb)
91 {
92 sb.Append("<array>");
93 }
94
95 public static void AddEndArray(StringBuilder sb)
96 {
97 sb.Append("</array>");
98 }
99
100 public static void AddEmptyArray(StringBuilder sb)
101 {
102 sb.Append("<array />");
103 }
104
105 // undefined or null
106 public static void AddUnknownElem(StringBuilder sb)
107 {
108 sb.Append("<undef />");
109 }
110
111 public static void AddElem(bool e, StringBuilder sb)
112 {
113 if(e)
114 sb.Append("<boolean>1</boolean>");
115 else
116 sb.Append("<boolean />");
117 }
118
119 public static void AddElem(byte e, StringBuilder sb)
120 {
121 if(e == 0)
122 sb.Append("<integer />");
123 else
124 {
125 sb.Append("<integer>");
126 sb.Append(e.ToString());
127 sb.Append("</integer>");
128 }
129 }
130
131 public static void AddElem(byte[] e, StringBuilder sb)
132 {
133 if(e == null || e.Length == 0)
134 sb.Append("binary />");
135 else
136 {
137 sb.Append("<binary>"); // encode64 is default
138 sb.Append(Convert.ToBase64String(e,Base64FormattingOptions.None));
139 sb.Append("</binary>");
140 }
141 }
142
143 public static void AddElem(int e, StringBuilder sb)
144 {
145 if(e == 0)
146 sb.Append("<integer />");
147 else
148 {
149 sb.Append("<integer>");
150 sb.Append(e.ToString());
151 sb.Append("</integer>");
152 }
153 }
154
155 public static void AddElem(float e, StringBuilder sb)
156 {
157 if(e == 0)
158 sb.Append("<real />");
159 else
160 {
161 sb.Append("<real>");
162 sb.Append(e.ToString(CultureInfo.InvariantCulture));
163 sb.Append("</real>");
164 }
165 }
166
167 public static void AddElem(Vector2 e, StringBuilder sb)
168 {
169 sb.Append("<map><key>x</key>");
170
171 if(e.X == 0)
172 sb.Append("<real /><key>y</key>");
173 else
174 {
175 sb.Append("<real>");
176 sb.Append(e.X.ToString(CultureInfo.InvariantCulture));
177 sb.Append("</real><key>y</key>");
178 }
179
180 if(e.Y == 0)
181 sb.Append("<real /></map>");
182 else
183 {
184 sb.Append("<real>");
185 sb.Append(e.Y.ToString(CultureInfo.InvariantCulture));
186 sb.Append("</real></map>");
187 }
188 }
189
190 public static void AddElem(Vector3 e, StringBuilder sb)
191 {
192 sb.Append("<map>key>x</key>");
193
194 if(e.X == 0)
195 sb.Append("<real /><key>y</key>");
196 else
197 {
198 sb.Append("<real>");
199 sb.Append(e.X.ToString(CultureInfo.InvariantCulture));
200 sb.Append("</real><key>y</key>");
201 }
202
203 if(e.Y == 0)
204 sb.Append("<real /><key>z</key>");
205 else
206 {
207 sb.Append("<real>");
208 sb.Append(e.Y.ToString(CultureInfo.InvariantCulture));
209 sb.Append("</real><key>z</key>");
210 }
211
212 if(e.Z == 0)
213 sb.Append("<real /></map>");
214 else
215 {
216 sb.Append("<real>");
217 sb.Append(e.Z.ToString(CultureInfo.InvariantCulture));
218 sb.Append("</real></map>");
219 }
220 }
221
222 public static void AddElem(Quaternion e, StringBuilder sb)
223 {
224 sb.Append("<map><key>x</key>");
225
226 if(e.X == 0)
227 sb.Append("<real /><key>y</key>");
228 else
229 {
230 sb.Append("<real>");
231 sb.Append(e.X.ToString(CultureInfo.InvariantCulture));
232 sb.Append("</real><key>y</key>");
233 }
234
235 if(e.Y == 0)
236 sb.Append("<real /><key>z</key>");
237 else
238 {
239 sb.Append("<real>");
240 sb.Append(e.Y.ToString(CultureInfo.InvariantCulture));
241 sb.Append("</real><key>z</key>");
242 }
243 if(e.Z == 0)
244 sb.Append("<real /><key>w</key>");
245 else
246 {
247 sb.Append("<real>");
248 sb.Append(e.Z.ToString(CultureInfo.InvariantCulture));
249 sb.Append("</real><key>w</key>");
250 }
251
252 if(e.W == 0)
253 sb.Append("<real /></map>");
254 else
255 {
256 sb.Append("<real>");
257 sb.Append(e.W.ToString(CultureInfo.InvariantCulture));
258 sb.Append("</real></map>");
259 }
260 }
261
262 public static void AddElem(double e, StringBuilder sb)
263 {
264 if(e == 0)
265 sb.Append("<real />");
266 else
267 {
268 sb.Append("<real>");
269 sb.Append(e.ToString(CultureInfo.InvariantCulture));
270 sb.Append("</real>");
271 }
272 }
273
274 public static void AddElem(UUID e, StringBuilder sb)
275 {
276 if(e == UUID.Zero)
277 sb.Append("<uuid />");
278 else
279 {
280 sb.Append("<uuid>");
281 EscapeToXML(e.ToString(), sb);
282 sb.Append("</uuid>");
283 }
284 }
285
286 public static void AddElem(string e, StringBuilder sb)
287 {
288 if(String.IsNullOrEmpty(e))
289 sb.Append("<string />");
290 else
291 {
292 sb.Append("<string>");
293 sb.Append(e.ToString());
294 sb.Append("</string>");
295 }
296 }
297
298 public static void AddRawElem(string e, StringBuilder sb)
299 {
300 if(String.IsNullOrEmpty(e))
301 sb.Append("<string />");
302 else
303 {
304 sb.Append("<string>");
305 sb.Append(e);
306 sb.Append("</string>");
307 }
308 }
309
310 public static void AddElem(Uri e, StringBuilder sb)
311 {
312 if(e == null)
313 {
314 sb.Append("<uri />");
315 return;
316 }
317
318 string s;
319 if (e.IsAbsoluteUri)
320 s = e.AbsoluteUri;
321 else
322 s = e.ToString();
323
324 if(String.IsNullOrEmpty(s))
325 sb.Append("<uri />");
326 else
327 {
328 sb.Append("<uri>");
329 sb.Append(s);
330 sb.Append("</uri>");
331 }
332 }
333
334 public static void AddElem(DateTime e, StringBuilder sb)
335 {
336 DateTime u = e.ToUniversalTime();
337 if(u == depoch)
338 {
339 sb.Append("<date />");
340 return;
341 }
342 string format;
343 if(u.Hour == 0 && u.Minute == 0 && u.Second == 0)
344 format = "yyyy-MM-dd";
345 else if (u.Millisecond > 0)
346 format = "yyyy-MM-ddTHH:mm:ss.ffZ";
347 else
348 format = "yyyy-MM-ddTHH:mm:ssZ";
349 sb.Append("<date>");
350 sb.Append(u.ToString(format,CultureInfo.InvariantCulture));
351 sb.Append("</date>");
352 }
353
354//************ key value *******************
355// assumes name is a valid llsd key
356
357 public static void AddMap(string name, StringBuilder sb)
358 {
359 sb.Append("<key>");
360 sb.Append(name);
361 sb.Append("</key><map>");
362 }
363
364 public static void AddEmptyMap(string name, StringBuilder sb)
365 {
366 sb.Append("<key>");
367 sb.Append(name);
368 sb.Append("</key><map />");
369 }
370
371 // array == a list values
372 public static void AddArray(string name, StringBuilder sb)
373 {
374 sb.Append("<key>");
375 sb.Append(name);
376 sb.Append("</key><array>");
377 }
378
379 public static void AddEmptyArray(string name, StringBuilder sb)
380 {
381 sb.Append("<key>");
382 sb.Append(name);
383 sb.Append("</key><array />");
384 }
385
386 // undefined or null
387 public static void AddUnknownElem(string name, StringBuilder sb)
388 {
389 sb.Append("<key>");
390 sb.Append(name);
391 sb.Append("</key><undef />");
392 }
393
394 public static void AddElem(string name, bool e, StringBuilder sb)
395 {
396 sb.Append("<key>");
397 sb.Append(name);
398 sb.Append("</key>");
399
400 if(e)
401 sb.Append("<boolean>1</boolean>");
402 else
403 sb.Append("<boolean />");
404 }
405
406 public static void AddElem(string name, byte e, StringBuilder sb)
407 {
408 sb.Append("<key>");
409 sb.Append(name);
410 sb.Append("</key>");
411
412 if(e == 0)
413 sb.Append("<integer />");
414 else
415 {
416 sb.Append("<integer>");
417 sb.Append(e.ToString());
418 sb.Append("</integer>");
419 }
420 }
421
422 public static void AddElem(string name, byte[] e, StringBuilder sb)
423 {
424 sb.Append("<key>");
425 sb.Append(name);
426 sb.Append("</key>");
427
428 if(e == null || e.Length == 0)
429 sb.Append("binary />");
430 else
431 {
432 sb.Append("<binary>"); // encode64 is default
433 sb.Append(Convert.ToBase64String(e,Base64FormattingOptions.None));
434 sb.Append("</binary>");
435 }
436 }
437
438 public static void AddElem(string name, int e, StringBuilder sb)
439 {
440 sb.Append("<key>");
441 sb.Append(name);
442 sb.Append("</key>");
443
444 if(e == 0)
445 sb.Append("<integer />");
446 else
447 {
448 sb.Append("<integer>");
449 sb.Append(e.ToString());
450 sb.Append("</integer>");
451 }
452 }
453
454 public static void AddElem(string name, float e, StringBuilder sb)
455 {
456 sb.Append("<key>");
457 sb.Append(name);
458 sb.Append("</key>");
459
460 if(e == 0)
461 sb.Append("<real />");
462 else
463 {
464 sb.Append("<real>");
465 sb.Append(e.ToString(CultureInfo.InvariantCulture));
466 sb.Append("</real>");
467 }
468 }
469
470 public static void AddElem(string name, Vector2 e, StringBuilder sb)
471 {
472 sb.Append("<key>");
473 sb.Append(name);
474 sb.Append("</key><map><key>x</key>");
475
476 if(e.X == 0)
477 sb.Append("<real /><key>y</key>");
478 else
479 {
480 sb.Append("<real>");
481 sb.Append(e.X.ToString(CultureInfo.InvariantCulture));
482 sb.Append("</real><key>y</key>");
483 }
484
485 if(e.Y == 0)
486 sb.Append("<real /></map>");
487 else
488 {
489 sb.Append("<real>");
490 sb.Append(e.Y.ToString(CultureInfo.InvariantCulture));
491 sb.Append("</real></map>");
492 }
493 }
494
495 public static void AddElem(string name, Vector3 e, StringBuilder sb)
496 {
497 sb.Append("<key>");
498 sb.Append(name);
499 sb.Append("</key><map>key>x</key>");
500
501 if(e.X == 0)
502 sb.Append("<real /><key>y</key>");
503 else
504 {
505 sb.Append("<real>");
506 sb.Append(e.X.ToString(CultureInfo.InvariantCulture));
507 sb.Append("</real><key>y</key>");
508 }
509
510 if(e.Y == 0)
511 sb.Append("<real /><key>z</key>");
512 else
513 {
514 sb.Append("<real>");
515 sb.Append(e.Y.ToString(CultureInfo.InvariantCulture));
516 sb.Append("</real><key>z</key>");
517 }
518
519 if(e.Z == 0)
520 sb.Append("<real /></map>");
521 else
522 {
523 sb.Append("<real>");
524 sb.Append(e.Z.ToString(CultureInfo.InvariantCulture));
525 sb.Append("</real></map>");
526 }
527 }
528
529 public static void AddElem(string name, Quaternion e, StringBuilder sb)
530 {
531 sb.Append("<key>");
532 sb.Append(name);
533 sb.Append("</key><map><key>x</key>");
534
535 if(e.X == 0)
536 sb.Append("<real /><key>y</key>");
537 else
538 {
539 sb.Append("<real>");
540 sb.Append(e.X.ToString(CultureInfo.InvariantCulture));
541 sb.Append("</real><key>y</key>");
542 }
543
544 if(e.Y == 0)
545 sb.Append("<real /><key>z</key>");
546 else
547 {
548 sb.Append("<real>");
549 sb.Append(e.Y.ToString(CultureInfo.InvariantCulture));
550 sb.Append("</real><key>z</key>");
551 }
552 if(e.Z == 0)
553 sb.Append("<real /><key>w</key>");
554 else
555 {
556 sb.Append("<real>");
557 sb.Append(e.Z.ToString(CultureInfo.InvariantCulture));
558 sb.Append("</real><key>w</key>");
559 }
560
561 if(e.W == 0)
562 sb.Append("<real /></map>");
563 else
564 {
565 sb.Append("<real>");
566 sb.Append(e.W.ToString(CultureInfo.InvariantCulture));
567 sb.Append("</real></map>");
568 }
569 }
570
571 public static void AddElem(string name, double e, StringBuilder sb)
572 {
573 sb.Append("<key>");
574 sb.Append(name);
575 sb.Append("</key>");
576
577 if(e == 0)
578 sb.Append("<real />");
579 else
580 {
581 sb.Append("<real>");
582 sb.Append(e.ToString(CultureInfo.InvariantCulture));
583 sb.Append("</real>");
584 }
585 }
586
587 public static void AddElem(string name, UUID e, StringBuilder sb)
588 {
589 sb.Append("<key>");
590 sb.Append(name);
591 sb.Append("</key>");
592
593 if(e == UUID.Zero)
594 sb.Append("<uuid />");
595 else
596 {
597 sb.Append("<uuid>");
598 EscapeToXML(e.ToString(), sb);
599 sb.Append("</uuid>");
600 }
601 }
602
603 public static void AddElem(string name, string e, StringBuilder sb)
604 {
605 sb.Append("<key>");
606 sb.Append(name);
607 sb.Append("</key>");
608
609 if(String.IsNullOrEmpty(e))
610 sb.Append("<string />");
611 else
612 {
613 sb.Append("<string>");
614 sb.Append(e.ToString());
615 sb.Append("</string>");
616 }
617 }
618
619 public static void AddRawElem(string name, string e, StringBuilder sb)
620 {
621 sb.Append("<key>");
622 sb.Append(name);
623 sb.Append("</key>");
624
625 if(String.IsNullOrEmpty(e))
626 sb.Append("<string />");
627 else
628 {
629 sb.Append("<string>");
630 sb.Append(e);
631 sb.Append("</string>");
632 }
633 }
634
635 public static void AddElem(string name, Uri e, StringBuilder sb)
636 {
637 sb.Append("<key>");
638 sb.Append(name);
639 sb.Append("</key>");
640
641 if(e == null)
642 {
643 sb.Append("<uri />");
644 return;
645 }
646
647 string s;
648 if (e.IsAbsoluteUri)
649 s = e.AbsoluteUri;
650 else
651 s = e.ToString();
652
653 if(String.IsNullOrEmpty(s))
654 sb.Append("<uri />");
655 else
656 {
657 sb.Append("<uri>");
658 sb.Append(s);
659 sb.Append("</uri>");
660 }
661 }
662
663 public static void AddElem(string name, DateTime e, StringBuilder sb)
664 {
665 sb.Append("<key>");
666 sb.Append(name);
667 sb.Append("</key>");
668
669 DateTime u = e.ToUniversalTime();
670 if(u == depoch)
671 {
672 sb.Append("<date />");
673 return;
674 }
675 string format;
676 if(u.Hour == 0 && u.Minute == 0 && u.Second == 0)
677 format = "yyyy-MM-dd";
678 else if (u.Millisecond > 0)
679 format = "yyyy-MM-ddTHH:mm:ss.ffZ";
680 else
681 format = "yyyy-MM-ddTHH:mm:ssZ";
682 sb.Append("<date>");
683 sb.Append(u.ToString(format,CultureInfo.InvariantCulture));
684 sb.Append("</date>");
685 }
686
687 public static void AddLLSD(string e, StringBuilder sb)
688 {
689 sb.Append(e);
690 }
691
692 public static void EscapeToXML(string s, StringBuilder sb)
693 {
694 int i;
695 char c;
696 int len = s.Length;
697
698 for (i = 0; i < len; i++)
699 {
700 c = s[i];
701 switch (c)
702 {
703 case '<':
704 sb.Append("&lt;");
705 break;
706 case '>':
707 sb.Append("&gt;");
708 break;
709 case '&':
710 sb.Append("&amp;");
711 break;
712 case '"':
713 sb.Append("&quot;");
714 break;
715 case '\\':
716 sb.Append("&apos;");
717 break;
718 default:
719 sb.Append(c);
720 break;
721 }
722 }
723 }
724 }
725}
diff --git a/OpenSim/Framework/MinHeap.cs b/OpenSim/Framework/MinHeap.cs
index 99ac25d..68f6668 100644
--- a/OpenSim/Framework/MinHeap.cs
+++ b/OpenSim/Framework/MinHeap.cs
@@ -45,8 +45,8 @@ namespace OpenSim.Framework
45 45
46 internal void Clear() 46 internal void Clear()
47 { 47 {
48 this.index = -1; 48 index = -1;
49 this.heap = null; 49 heap = null;
50 } 50 }
51 } 51 }
52 52
@@ -55,23 +55,26 @@ namespace OpenSim.Framework
55 internal T value; 55 internal T value;
56 internal Handle handle; 56 internal Handle handle;
57 57
58 internal HeapItem(T value, Handle handle) 58 internal HeapItem(T _value, Handle _handle)
59 { 59 {
60 this.value = value; 60 value = _value;
61 this.handle = handle; 61 handle = _handle;
62 } 62 }
63 63
64 internal void Clear() 64 internal void Clear()
65 { 65 {
66 if (this.handle != null) 66 if (handle != null)
67 this.handle.Clear(); 67 {
68 ClearRef(); 68 handle.Clear();
69 handle = null;
70 }
71 value = default(T);
69 } 72 }
70 73
71 internal void ClearRef() 74 internal void ClearRef()
72 { 75 {
73 this.value = default(T); 76 value = default(T);
74 this.handle = null; 77 handle = null;
75 } 78 }
76 } 79 }
77 80
@@ -81,6 +84,7 @@ namespace OpenSim.Framework
81 private int size; 84 private int size;
82 private object sync_root; 85 private object sync_root;
83 private int version; 86 private int version;
87 private int capacity;
84 88
85 private Comparison<T> comparison; 89 private Comparison<T> comparison;
86 90
@@ -90,14 +94,15 @@ namespace OpenSim.Framework
90 public MinHeap(int capacity, IComparer<T> comparer) : 94 public MinHeap(int capacity, IComparer<T> comparer) :
91 this(capacity, new Comparison<T>(comparer.Compare)) { } 95 this(capacity, new Comparison<T>(comparer.Compare)) { }
92 public MinHeap(Comparison<T> comparison) : this(DEFAULT_CAPACITY, comparison) { } 96 public MinHeap(Comparison<T> comparison) : this(DEFAULT_CAPACITY, comparison) { }
93 public MinHeap(int capacity, Comparison<T> comparison) 97 public MinHeap(int _capacity, Comparison<T> _comparison)
94 { 98 {
95 this.items = new HeapItem[capacity]; 99 capacity = _capacity;
96 this.comparison = comparison; 100 items = new HeapItem[capacity];
97 this.size = this.version = 0; 101 comparison = _comparison;
102 size = version = 0;
98 } 103 }
99 104
100 public int Count { get { return this.size; } } 105 public int Count { get { return size; } }
101 106
102 public bool IsReadOnly { get { return false; } } 107 public bool IsReadOnly { get { return false; } }
103 108
@@ -108,15 +113,16 @@ namespace OpenSim.Framework
108 get 113 get
109 { 114 {
110 Handle handle = ValidateThisHandle(key); 115 Handle handle = ValidateThisHandle(key);
111 return this.items[handle.index].value; 116 return items[handle.index].value;
112 } 117 }
113 118
114 set 119 set
115 { 120 {
116 Handle handle = ValidateThisHandle(key); 121 Handle handle = ValidateThisHandle(key);
117 this.items[handle.index].value = value; 122 int indx = handle.index;
118 if (!BubbleUp(handle.index)) 123 items[indx].value = value;
119 BubbleDown(handle.index); 124 if (!BubbleUp(indx))
125 BubbleDown(indx);
120 } 126 }
121 } 127 }
122 128
@@ -124,9 +130,9 @@ namespace OpenSim.Framework
124 { 130 {
125 get 131 get
126 { 132 {
127 if (this.sync_root == null) 133 if (sync_root == null)
128 Interlocked.CompareExchange<object>(ref this.sync_root, new object(), null); 134 Interlocked.CompareExchange<object>(ref sync_root, new object(), null);
129 return this.sync_root; 135 return sync_root;
130 } 136 }
131 } 137 }
132 138
@@ -152,27 +158,27 @@ namespace OpenSim.Framework
152 158
153 private void Set(HeapItem item, int index) 159 private void Set(HeapItem item, int index)
154 { 160 {
155 this.items[index] = item; 161 items[index] = item;
156 if (item.handle != null) 162 if (item.handle != null)
157 item.handle.index = index; 163 item.handle.index = index;
158 } 164 }
159 165
160 private bool BubbleUp(int index) 166 private bool BubbleUp(int index)
161 { 167 {
162 HeapItem item = this.items[index]; 168 HeapItem item = items[index];
163 int current, parent; 169 int current, parent;
164 170
165 for (current = index, parent = (current - 1) / 2; 171 for (current = index, parent = (current - 1) / 2;
166 (current > 0) && (this.comparison(this.items[parent].value, item.value)) > 0; 172 (current > 0) && (comparison(items[parent].value, item.value)) > 0;
167 current = parent, parent = (current - 1) / 2) 173 current = parent, parent = (current - 1) / 2)
168 { 174 {
169 Set(this.items[parent], current); 175 Set(items[parent], current);
170 } 176 }
171 177
172 if (current != index) 178 if (current != index)
173 { 179 {
174 Set(item, current); 180 Set(item, current);
175 ++this.version; 181 ++version;
176 return true; 182 return true;
177 } 183 }
178 return false; 184 return false;
@@ -180,24 +186,24 @@ namespace OpenSim.Framework
180 186
181 private void BubbleDown(int index) 187 private void BubbleDown(int index)
182 { 188 {
183 HeapItem item = this.items[index]; 189 HeapItem item = items[index];
184 int current, child; 190 int current, child;
185 191
186 for (current = index, child = (2 * current) + 1; 192 for (current = index, child = (2 * current) + 1;
187 current < this.size / 2; 193 current < size / 2;
188 current = child, child = (2 * current) + 1) 194 current = child, child = (2 * current) + 1)
189 { 195 {
190 if ((child < this.size - 1) && this.comparison(this.items[child].value, this.items[child + 1].value) > 0) 196 if ((child < size - 1) && comparison(items[child].value, items[child + 1].value) > 0)
191 ++child; 197 ++child;
192 if (this.comparison(this.items[child].value, item.value) >= 0) 198 if (comparison(items[child].value, item.value) >= 0)
193 break; 199 break;
194 Set(this.items[child], current); 200 Set(items[child], current);
195 } 201 }
196 202
197 if (current != index) 203 if (current != index)
198 { 204 {
199 Set(item, current); 205 Set(item, current);
200 ++this.version; 206 ++version;
201 } 207 }
202 } 208 }
203 209
@@ -206,7 +212,7 @@ namespace OpenSim.Framework
206 Handle handle = ValidateHandle(key); 212 Handle handle = ValidateHandle(key);
207 if (handle.index > -1) 213 if (handle.index > -1)
208 { 214 {
209 value = this.items[handle.index].value; 215 value = items[handle.index].value;
210 return true; 216 return true;
211 } 217 }
212 value = default(T); 218 value = default(T);
@@ -228,12 +234,12 @@ namespace OpenSim.Framework
228 234
229 public void Add(T value, IHandle ihandle) 235 public void Add(T value, IHandle ihandle)
230 { 236 {
231 if (this.size == this.items.Length) 237 if (size == items.Length)
232 { 238 {
233 int capacity = (int)((this.items.Length * 200L) / 100L); 239 int capacity = (int)((items.Length * 200L) / 100L);
234 if (capacity < (this.items.Length + DEFAULT_CAPACITY)) 240 if (capacity < (items.Length + DEFAULT_CAPACITY))
235 capacity = this.items.Length + DEFAULT_CAPACITY; 241 capacity = items.Length + DEFAULT_CAPACITY;
236 Array.Resize<HeapItem>(ref this.items, capacity); 242 Array.Resize<HeapItem>(ref items, capacity);
237 } 243 }
238 244
239 Handle handle = null; 245 Handle handle = null;
@@ -245,8 +251,8 @@ namespace OpenSim.Framework
245 251
246 HeapItem item = new MinHeap<T>.HeapItem(value, handle); 252 HeapItem item = new MinHeap<T>.HeapItem(value, handle);
247 253
248 Set(item, this.size); 254 Set(item, size);
249 BubbleUp(this.size++); 255 BubbleUp(size++);
250 } 256 }
251 257
252 public void Add(T value) 258 public void Add(T value)
@@ -256,50 +262,54 @@ namespace OpenSim.Framework
256 262
257 public T Min() 263 public T Min()
258 { 264 {
259 if (this.size == 0) 265 if (size == 0)
260 throw new InvalidOperationException("Heap is empty"); 266 throw new InvalidOperationException("Heap is empty");
261 267
262 return this.items[0].value; 268 return items[0].value;
263 } 269 }
264 270
265 public void Clear() 271 public void Clear()
266 { 272 {
267 for (int index = 0; index < this.size; ++index) 273 for (int index = 0; index < size; ++index)
268 this.items[index].Clear(); 274 items[index].Clear();
269 this.size = 0; 275 size = 0;
270 ++this.version; 276 if(items.Length > capacity)
277 items = new HeapItem[capacity];
278 ++version;
271 } 279 }
272 280
273 public void TrimExcess() 281 public void TrimExcess()
274 { 282 {
275 int length = (int)(this.items.Length * 0.9); 283 int length = (int)(items.Length * 0.9);
276 if (this.size < length) 284 if (size < length)
277 Array.Resize<HeapItem>(ref this.items, Math.Min(this.size, DEFAULT_CAPACITY)); 285 Array.Resize<HeapItem>(ref items, Math.Min(size, capacity));
278 } 286 }
279 287
280 private void RemoveAt(int index) 288 private void RemoveAt(int index)
281 { 289 {
282 if (this.size == 0) 290 if (size == 0)
283 throw new InvalidOperationException("Heap is empty"); 291 throw new InvalidOperationException("Heap is empty");
284 if (index >= this.size) 292 if (index >= size)
285 throw new ArgumentOutOfRangeException("index"); 293 throw new ArgumentOutOfRangeException("index");
286 294
287 this.items[index].Clear(); 295 items[index].Clear();
288 if (--this.size > 0 && index != this.size) 296 if (--size > 0 && index != size)
289 { 297 {
290 Set(this.items[this.size], index); 298 Set(items[size], index);
291 this.items[this.size].ClearRef(); 299 items[size].ClearRef();
292 if (!BubbleUp(index)) 300 if (!BubbleUp(index))
293 BubbleDown(index); 301 BubbleDown(index);
294 } 302 }
303 if(size == 0 && items.Length > 4 * capacity)
304 items = new HeapItem[capacity];
295 } 305 }
296 306
297 public T RemoveMin() 307 public T RemoveMin()
298 { 308 {
299 if (this.size == 0) 309 if (size == 0)
300 throw new InvalidOperationException("Heap is empty"); 310 throw new InvalidOperationException("Heap is empty");
301 311
302 HeapItem item = this.items[0]; 312 HeapItem item = items[0];
303 RemoveAt(0); 313 RemoveAt(0);
304 return item.value; 314 return item.value;
305 } 315 }
@@ -307,7 +317,7 @@ namespace OpenSim.Framework
307 public T Remove(IHandle ihandle) 317 public T Remove(IHandle ihandle)
308 { 318 {
309 Handle handle = ValidateThisHandle(ihandle); 319 Handle handle = ValidateThisHandle(ihandle);
310 HeapItem item = this.items[handle.index]; 320 HeapItem item = items[handle.index];
311 RemoveAt(handle.index); 321 RemoveAt(handle.index);
312 return item.value; 322 return item.value;
313 } 323 }
@@ -317,9 +327,9 @@ namespace OpenSim.Framework
317 EqualityComparer<T> comparer = EqualityComparer<T>.Default; 327 EqualityComparer<T> comparer = EqualityComparer<T>.Default;
318 int index; 328 int index;
319 329
320 for (index = 0; index < this.size; ++index) 330 for (index = 0; index < size; ++index)
321 { 331 {
322 if (comparer.Equals(this.items[index].value, value)) 332 if (comparer.Equals(items[index].value, value))
323 return index; 333 return index;
324 } 334 }
325 return -1; 335 return -1;
@@ -356,8 +366,8 @@ namespace OpenSim.Framework
356 if ((length - index) < this.size) 366 if ((length - index) < this.size)
357 throw new ArgumentException("Not enough space available in array starting at index"); 367 throw new ArgumentException("Not enough space available in array starting at index");
358 368
359 for (int i = 0; i < this.size; ++i) 369 for (int i = 0; i < size; ++i)
360 array[index + i] = this.items[i].value; 370 array[index + i] = items[i].value;
361 } 371 }
362 372
363 public void CopyTo(Array array, int index) 373 public void CopyTo(Array array, int index)
@@ -372,13 +382,13 @@ namespace OpenSim.Framework
372 int length = array.Length; 382 int length = array.Length;
373 if ((index < 0) || (index > length)) 383 if ((index < 0) || (index > length))
374 throw new ArgumentOutOfRangeException("index"); 384 throw new ArgumentOutOfRangeException("index");
375 if ((length - index) < this.size) 385 if ((length - index) < size)
376 throw new ArgumentException("Not enough space available in array starting at index"); 386 throw new ArgumentException("Not enough space available in array starting at index");
377 387
378 try 388 try
379 { 389 {
380 for (int i = 0; i < this.size; ++i) 390 for (int i = 0; i < size; ++i)
381 array.SetValue(this.items[i].value, index + i); 391 array.SetValue(items[i].value, index + i);
382 } 392 }
383 catch (ArrayTypeMismatchException) 393 catch (ArrayTypeMismatchException)
384 { 394 {
@@ -388,13 +398,13 @@ namespace OpenSim.Framework
388 398
389 public IEnumerator<T> GetEnumerator() 399 public IEnumerator<T> GetEnumerator()
390 { 400 {
391 int version = this.version; 401 int cversion = version;
392 402
393 for (int index = 0; index < this.size; ++index) 403 for (int index = 0; index < size; ++index)
394 { 404 {
395 if (version != this.version) 405 if (cversion != version)
396 throw new InvalidOperationException("Heap was modified while enumerating"); 406 throw new InvalidOperationException("Heap was modified while enumerating");
397 yield return this.items[index].value; 407 yield return items[index].value;
398 } 408 }
399 } 409 }
400 410
diff --git a/OpenSim/Framework/Monitoring/JobEngine.cs b/OpenSim/Framework/Monitoring/JobEngine.cs
index 115871e..6c388b3 100644
--- a/OpenSim/Framework/Monitoring/JobEngine.cs
+++ b/OpenSim/Framework/Monitoring/JobEngine.cs
@@ -79,7 +79,7 @@ namespace OpenSim.Framework.Monitoring
79 /// </remarks> 79 /// </remarks>
80 private bool m_warnOverMaxQueue = true; 80 private bool m_warnOverMaxQueue = true;
81 81
82 private BlockingCollection<Job> m_jobQueue = new BlockingCollection<Job>(new ConcurrentQueue<Job>(), 5000); 82 private BlockingCollection<Job> m_jobQueue = new BlockingCollection<Job>(5000);
83 83
84 private CancellationTokenSource m_cancelSource; 84 private CancellationTokenSource m_cancelSource;
85 85
@@ -238,7 +238,7 @@ namespace OpenSim.Framework.Monitoring
238 break; 238 break;
239 } 239 }
240 } 240 }
241 catch(ObjectDisposedException e) 241 catch(ObjectDisposedException)
242 { 242 {
243 m_log.DebugFormat("[JobEngine] {0} stopping ignoring {1} jobs in queue", 243 m_log.DebugFormat("[JobEngine] {0} stopping ignoring {1} jobs in queue",
244 Name,m_jobQueue.Count); 244 Name,m_jobQueue.Count);
diff --git a/OpenSim/Framework/Monitoring/Stats/Stat.cs b/OpenSim/Framework/Monitoring/Stats/Stat.cs
index 2402acd..4b1a229 100644
--- a/OpenSim/Framework/Monitoring/Stats/Stat.cs
+++ b/OpenSim/Framework/Monitoring/Stats/Stat.cs
@@ -242,11 +242,7 @@ namespace OpenSim.Framework.Monitoring
242 public virtual OSDMap ToBriefOSDMap() 242 public virtual OSDMap ToBriefOSDMap()
243 { 243 {
244 OSDMap ret = new OSDMap(); 244 OSDMap ret = new OSDMap();
245
246 ret.Add("Value", OSD.FromReal(Value)); 245 ret.Add("Value", OSD.FromReal(Value));
247
248 double lastChangeOverTime, averageChangeOverTime;
249
250 return ret; 246 return ret;
251 } 247 }
252 248
diff --git a/OpenSim/Framework/NetworkServersInfo.cs b/OpenSim/Framework/NetworkServersInfo.cs
index dfe9695..d79eb0d 100644
--- a/OpenSim/Framework/NetworkServersInfo.cs
+++ b/OpenSim/Framework/NetworkServersInfo.cs
@@ -37,6 +37,8 @@ namespace OpenSim.Framework
37 public bool isSandbox; 37 public bool isSandbox;
38 public bool HttpUsesSSL = false; 38 public bool HttpUsesSSL = false;
39 public string HttpSSLCN = ""; 39 public string HttpSSLCN = "";
40 public string HttpSSLCertPath = "";
41 public string HttpSSLCNCertPass = "";
40 public uint httpSSLPort = 9001; 42 public uint httpSSLPort = 9001;
41 43
42 // "Out of band" managemnt https 44 // "Out of band" managemnt https
@@ -62,6 +64,8 @@ namespace OpenSim.Framework
62 (uint)config.Configs["Network"].GetInt("http_listener_sslport", ((int)ConfigSettings.DefaultRegionHttpPort+1)); 64 (uint)config.Configs["Network"].GetInt("http_listener_sslport", ((int)ConfigSettings.DefaultRegionHttpPort+1));
63 HttpUsesSSL = config.Configs["Network"].GetBoolean("http_listener_ssl", false); 65 HttpUsesSSL = config.Configs["Network"].GetBoolean("http_listener_ssl", false);
64 HttpSSLCN = config.Configs["Network"].GetString("http_listener_cn", "localhost"); 66 HttpSSLCN = config.Configs["Network"].GetString("http_listener_cn", "localhost");
67 HttpSSLCertPath = config.Configs["Network"].GetString("http_listener_cert_path", HttpSSLCertPath);
68 HttpSSLCNCertPass = config.Configs["Network"].GetString("http_listener_cert_pass", HttpSSLCNCertPass);
65 69
66 // "Out of band management https" 70 // "Out of band management https"
67 ssl_listener = config.Configs["Network"].GetBoolean("https_listener",false); 71 ssl_listener = config.Configs["Network"].GetBoolean("https_listener",false);
diff --git a/OpenSim/Framework/PhysicsInertia.cs b/OpenSim/Framework/PhysicsInertia.cs
index fa83de8..5aae6d5 100644
--- a/OpenSim/Framework/PhysicsInertia.cs
+++ b/OpenSim/Framework/PhysicsInertia.cs
@@ -193,8 +193,6 @@ namespace OpenSim.Framework
193 using(MemoryStream ms = new MemoryStream(enc.GetBytes(text))) 193 using(MemoryStream ms = new MemoryStream(enc.GetBytes(text)))
194 using(XmlTextReader xreader = new XmlTextReader(ms)) 194 using(XmlTextReader xreader = new XmlTextReader(ms))
195 { 195 {
196 xreader.ProhibitDtd = true;
197
198 v = new PhysicsInertiaData(); 196 v = new PhysicsInertiaData();
199 v.FromXml2(xreader, out error); 197 v.FromXml2(xreader, out error);
200 } 198 }
diff --git a/OpenSim/Framework/PrimitiveBaseShape.cs b/OpenSim/Framework/PrimitiveBaseShape.cs
index 6e7a038..5056c04 100644
--- a/OpenSim/Framework/PrimitiveBaseShape.cs
+++ b/OpenSim/Framework/PrimitiveBaseShape.cs
@@ -1595,8 +1595,6 @@ namespace OpenSim.Framework
1595 { 1595 {
1596 using (XmlTextReader xtr = new XmlTextReader(sr)) 1596 using (XmlTextReader xtr = new XmlTextReader(sr))
1597 { 1597 {
1598 xtr.ProhibitDtd = true;
1599
1600 xtr.MoveToContent(); 1598 xtr.MoveToContent();
1601 1599
1602 string type = xtr.GetAttribute("type"); 1600 string type = xtr.GetAttribute("type");
diff --git a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs
index af130a5..238ebb1 100644
--- a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs
+++ b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs
@@ -156,7 +156,7 @@ namespace OpenSim.Framework.Serialization.External
156 return xml; 156 return xml;
157 157
158 XmlDocument doc = new XmlDocument(); 158 XmlDocument doc = new XmlDocument();
159 doc.XmlResolver=null; 159
160 doc.LoadXml(xml); 160 doc.LoadXml(xml);
161 XmlNodeList sops = doc.GetElementsByTagName("SceneObjectPart"); 161 XmlNodeList sops = doc.GetElementsByTagName("SceneObjectPart");
162 162
@@ -221,7 +221,7 @@ namespace OpenSim.Framework.Serialization.External
221 using (StringWriter sw = new StringWriter()) 221 using (StringWriter sw = new StringWriter())
222 using (XmlTextWriter writer = new XmlTextWriter(sw)) 222 using (XmlTextWriter writer = new XmlTextWriter(sw))
223 using (XmlTextReader wrappedReader = new XmlTextReader(xmlData, XmlNodeType.Element, null)) 223 using (XmlTextReader wrappedReader = new XmlTextReader(xmlData, XmlNodeType.Element, null))
224 using (XmlReader reader = XmlReader.Create(wrappedReader, new XmlReaderSettings() { IgnoreWhitespace = true, ConformanceLevel = ConformanceLevel.Fragment, ProhibitDtd = true})) 224 using (XmlReader reader = XmlReader.Create(wrappedReader, new XmlReaderSettings() { IgnoreWhitespace = true, ConformanceLevel = ConformanceLevel.Fragment}))
225 { 225 {
226 TransformXml(reader, writer, sceneName, homeURL, userService, scopeID); 226 TransformXml(reader, writer, sceneName, homeURL, userService, scopeID);
227 227
diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs
index 33ffd83..e42d56f 100644
--- a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs
+++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs
@@ -178,7 +178,6 @@ namespace OpenSim.Framework.Serialization.External
178 178
179 using (XmlTextReader reader = new XmlTextReader(new StringReader(serializedLandData))) 179 using (XmlTextReader reader = new XmlTextReader(new StringReader(serializedLandData)))
180 { 180 {
181 reader.ProhibitDtd = true;
182 reader.ReadStartElement("LandData"); 181 reader.ReadStartElement("LandData");
183 182
184 ExternalRepresentationUtils.ExecuteReadProcessors<LandData>(landData, m_ldProcessors, reader); 183 ExternalRepresentationUtils.ExecuteReadProcessors<LandData>(landData, m_ldProcessors, reader);
diff --git a/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs
index fd21f3e..617c451 100644
--- a/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs
+++ b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs
@@ -63,7 +63,6 @@ namespace OpenSim.Framework.Serialization.External
63 63
64 StringReader sr = new StringReader(serializedSettings); 64 StringReader sr = new StringReader(serializedSettings);
65 XmlTextReader xtr = new XmlTextReader(sr); 65 XmlTextReader xtr = new XmlTextReader(sr);
66 xtr.ProhibitDtd = true;
67 66
68 xtr.ReadStartElement("RegionSettings"); 67 xtr.ReadStartElement("RegionSettings");
69 68
diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs
index 12194ad..9b02553 100644
--- a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs
+++ b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs
@@ -202,8 +202,6 @@ namespace OpenSim.Framework.Serialization.External
202 202
203 using (XmlTextReader reader = new XmlTextReader(new StringReader(serialization))) 203 using (XmlTextReader reader = new XmlTextReader(new StringReader(serialization)))
204 { 204 {
205 reader.ProhibitDtd = true;
206
207 reader.ReadStartElement("InventoryItem"); 205 reader.ReadStartElement("InventoryItem");
208 206
209 ExternalRepresentationUtils.ExecuteReadProcessors<InventoryItemBase>( 207 ExternalRepresentationUtils.ExecuteReadProcessors<InventoryItemBase>(
diff --git a/OpenSim/Framework/Servers/BaseOpenSimServer.cs b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
index 81dd357..f832f81 100644
--- a/OpenSim/Framework/Servers/BaseOpenSimServer.cs
+++ b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
@@ -33,6 +33,9 @@ using System.Text;
33using System.Text.RegularExpressions; 33using System.Text.RegularExpressions;
34using System.Threading; 34using System.Threading;
35using System.Timers; 35using System.Timers;
36using System.Net;
37using System.Net.Security;
38using System.Security.Cryptography.X509Certificates;
36using log4net; 39using log4net;
37using log4net.Appender; 40using log4net.Appender;
38using log4net.Core; 41using log4net.Core;
@@ -86,6 +89,26 @@ namespace OpenSim.Framework.Servers
86 m_osSecret = UUID.Random().ToString(); 89 m_osSecret = UUID.Random().ToString();
87 } 90 }
88 91
92 private static bool m_NoVerifyCertChain = false;
93 private static bool m_NoVerifyCertHostname = false;
94
95 public static bool ValidateServerCertificate(
96 object sender,
97 X509Certificate certificate,
98 X509Chain chain,
99 SslPolicyErrors sslPolicyErrors)
100 {
101 if (m_NoVerifyCertChain)
102 sslPolicyErrors &= ~SslPolicyErrors.RemoteCertificateChainErrors;
103
104 if (m_NoVerifyCertHostname)
105 sslPolicyErrors &= ~SslPolicyErrors.RemoteCertificateNameMismatch;
106
107 if (sslPolicyErrors == SslPolicyErrors.None)
108 return true;
109
110 return false;
111 }
89 /// <summary> 112 /// <summary>
90 /// Must be overriden by child classes for their own server specific startup behaviour. 113 /// Must be overriden by child classes for their own server specific startup behaviour.
91 /// </summary> 114 /// </summary>
@@ -96,6 +119,11 @@ namespace OpenSim.Framework.Servers
96 RegisterCommonComponents(Config); 119 RegisterCommonComponents(Config);
97 120
98 IConfig startupConfig = Config.Configs["Startup"]; 121 IConfig startupConfig = Config.Configs["Startup"];
122
123 m_NoVerifyCertChain = startupConfig.GetBoolean("NoVerifyCertChain", m_NoVerifyCertChain);
124 m_NoVerifyCertHostname = startupConfig.GetBoolean("NoVerifyCertHostname", m_NoVerifyCertHostname);
125 ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;
126
99 int logShowStatsSeconds = startupConfig.GetInt("LogShowStatsSeconds", m_periodDiagnosticTimerMS / 1000); 127 int logShowStatsSeconds = startupConfig.GetInt("LogShowStatsSeconds", m_periodDiagnosticTimerMS / 1000);
100 m_periodDiagnosticTimerMS = logShowStatsSeconds * 1000; 128 m_periodDiagnosticTimerMS = logShowStatsSeconds * 1000;
101 m_periodicDiagnosticsTimer.Elapsed += new ElapsedEventHandler(LogDiagnostics); 129 m_periodicDiagnosticsTimer.Elapsed += new ElapsedEventHandler(LogDiagnostics);
diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
index f4ba02f..ca67d84 100644
--- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
+++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
@@ -32,6 +32,7 @@ using System.Collections.Specialized;
32using System.IO; 32using System.IO;
33using System.Net; 33using System.Net;
34using System.Net.Sockets; 34using System.Net.Sockets;
35using System.Net.Security;
35using System.Security.Cryptography.X509Certificates; 36using System.Security.Cryptography.X509Certificates;
36using System.Reflection; 37using System.Reflection;
37using System.Globalization; 38using System.Globalization;
@@ -43,10 +44,11 @@ using log4net;
43using Nwc.XmlRpc; 44using Nwc.XmlRpc;
44using OpenMetaverse.StructuredData; 45using OpenMetaverse.StructuredData;
45using CoolHTTPListener = HttpServer.HttpListener; 46using CoolHTTPListener = HttpServer.HttpListener;
46using HttpListener=System.Net.HttpListener; 47using HttpListener = System.Net.HttpListener;
47using LogPrio=HttpServer.LogPrio; 48using LogPrio = HttpServer.LogPrio;
48using OpenSim.Framework.Monitoring; 49using OpenSim.Framework.Monitoring;
49using System.IO.Compression; 50using System.IO.Compression;
51using System.Security.Cryptography;
50 52
51namespace OpenSim.Framework.Servers.HttpServer 53namespace OpenSim.Framework.Servers.HttpServer
52{ 54{
@@ -107,19 +109,26 @@ namespace OpenSim.Framework.Servers.HttpServer
107 new Dictionary<string, WebSocketRequestDelegate>(); 109 new Dictionary<string, WebSocketRequestDelegate>();
108 110
109 protected uint m_port; 111 protected uint m_port;
110 protected uint m_sslport;
111 protected bool m_ssl; 112 protected bool m_ssl;
112 private X509Certificate2 m_cert; 113 private X509Certificate2 m_cert;
113 protected bool m_firstcaps = true;
114 protected string m_SSLCommonName = ""; 114 protected string m_SSLCommonName = "";
115 protected List<string> m_certNames = new List<string>();
116 protected List<string> m_certIPs = new List<string>();
117 protected string m_certCN= "";
118 protected RemoteCertificateValidationCallback m_certificateValidationCallback = null;
115 119
116 protected IPAddress m_listenIPAddress = IPAddress.Any; 120 protected IPAddress m_listenIPAddress = IPAddress.Any;
117 121
118 public PollServiceRequestManager PollServiceRequestManager { get; private set; } 122 public PollServiceRequestManager PollServiceRequestManager { get; private set; }
119 123
124 public string Protocol
125 {
126 get { return m_ssl ? "https://" : "http://"; }
127 }
128
120 public uint SSLPort 129 public uint SSLPort
121 { 130 {
122 get { return m_sslport; } 131 get { return m_port; }
123 } 132 }
124 133
125 public string SSLCommonName 134 public string SSLCommonName
@@ -148,27 +157,166 @@ namespace OpenSim.Framework.Servers.HttpServer
148 m_port = port; 157 m_port = port;
149 } 158 }
150 159
151 public BaseHttpServer(uint port, bool ssl) : this (port) 160 private void load_cert(string CPath, string CPass)
152 { 161 {
153 m_ssl = ssl; 162 try
163 {
164 m_cert = new X509Certificate2(CPath, CPass);
165 X509Extension ext = m_cert.Extensions["2.5.29.17"];
166 if(ext != null)
167 {
168 AsnEncodedData asndata = new AsnEncodedData(ext.Oid, ext.RawData);
169 string datastr = asndata.Format(true);
170 string[] lines = datastr.Split(new char[] {'\n','\r'});
171 foreach(string s in lines)
172 {
173 if(String.IsNullOrEmpty(s))
174 continue;
175 string[] parts = s.Split(new char[] {'='});
176 if(String.IsNullOrEmpty(parts[0]))
177 continue;
178 string entryName = parts[0].Replace(" ","");
179 if(entryName == "DNSName")
180 m_certNames.Add(parts[1]);
181 else if(entryName == "IPAddress")
182 m_certIPs.Add(parts[1]);
183 else if(entryName == "Unknown(135)") // stupid mono
184 {
185 try
186 {
187 if(parts[1].Length == 8)
188 {
189 long tmp = long.Parse(parts[1], NumberStyles.AllowHexSpecifier);
190 tmp = IPAddress.HostToNetworkOrder(tmp);
191 tmp = (long)((ulong) tmp >> 32);
192 IPAddress ia = new IPAddress(tmp);
193 m_certIPs.Add(ia.ToString());
194 }
195 }
196 catch {}
197 }
198 }
199 }
200 m_certCN = m_cert.GetNameInfo(X509NameType.SimpleName, false);
201 }
202 catch
203 {
204 throw new Exception("SSL cert load error");
205 }
154 } 206 }
155 207
156 public BaseHttpServer(uint port, bool ssl, uint sslport, string CN) : this (port, ssl) 208 public BaseHttpServer(uint port, bool ssl, string CN, string CPath, string CPass)
157 { 209 {
158 if (m_ssl) 210 m_port = port;
211 if (ssl)
159 { 212 {
160 m_sslport = sslport; 213 if(string.IsNullOrEmpty(CPath))
214 throw new Exception("invalid main http server cert path");
215
216 if(Uri.CheckHostName(CN) == UriHostNameType.Unknown)
217 throw new Exception("invalid main http server CN (ExternalHostName)");
218
219 m_certNames.Clear();
220 m_certIPs.Clear();
221 m_certCN= "";
222
223 m_ssl = true;
224 load_cert(CPath, CPass);
225
226 if(!CheckSSLCertHost(CN))
227 throw new Exception("invalid main http server CN (ExternalHostName)");
228
229 m_SSLCommonName = CN;
230
231 if(m_cert.Issuer == m_cert.Subject )
232 m_log.Warn("Self signed certificate. Clients need to allow this (some viewers debug option NoVerifySSLcert must be set to true");
161 } 233 }
234 else
235 m_ssl = false;
162 } 236 }
163 237
164 public BaseHttpServer(uint port, bool ssl, string CPath, string CPass) : this (port, ssl) 238 public BaseHttpServer(uint port, bool ssl, string CPath, string CPass)
165 { 239 {
166 if (m_ssl) 240 m_port = port;
241 if (ssl)
167 { 242 {
168 m_cert = new X509Certificate2(CPath, CPass); 243 load_cert(CPath, CPass);
244 if(m_cert.Issuer == m_cert.Subject )
245 m_log.Warn("Self signed certificate. Http clients need to allow this");
246 m_ssl = true;
247 }
248 else
249 m_ssl = false;
250 }
251
252 static bool MatchDNS (string hostname, string dns)
253 {
254 int indx = dns.IndexOf ('*');
255 if (indx == -1)
256 return (String.Compare(hostname, dns, true, CultureInfo.InvariantCulture) == 0);
257
258 int dnslen = dns.Length;
259 dnslen--;
260 if(indx == dnslen)
261 return true; // just * ?
262
263 if(indx > dnslen - 2)
264 return false; // 2 short ?
265
266 if (dns[indx + 1] != '.')
267 return false;
268
269 int indx2 = dns.IndexOf ('*', indx + 1);
270 if (indx2 != -1)
271 return false; // there can only be one;
272
273 string end = dns.Substring(indx + 1);
274 int hostlen = hostname.Length;
275 int endlen = end.Length;
276 int length = hostlen - endlen;
277 if (length <= 0)
278 return false;
279
280 if (String.Compare(hostname, length, end, 0, endlen, true, CultureInfo.InvariantCulture) != 0)
281 return false;
282
283 if (indx == 0)
284 {
285 indx2 = hostname.IndexOf ('.');
286 return ((indx2 == -1) || (indx2 >= length));
287 }
288
289 string start = dns.Substring (0, indx);
290 return (String.Compare (hostname, 0, start, 0, start.Length, true, CultureInfo.InvariantCulture) == 0);
291 }
292
293 public bool CheckSSLCertHost(string hostname)
294 {
295 UriHostNameType htype = Uri.CheckHostName(hostname);
296
297 if(htype == UriHostNameType.Unknown || htype == UriHostNameType.Basic)
298 return false;
299 if(htype == UriHostNameType.Dns)
300 {
301 foreach(string name in m_certNames)
302 {
303 if(MatchDNS(hostname, name))
304 return true;
305 }
306 if(MatchDNS(hostname, m_certCN))
307 return true;
308 }
309 else
310 {
311 foreach(string ip in m_certIPs)
312 {
313 if (String.Compare(hostname, ip, true, CultureInfo.InvariantCulture) == 0)
314 return true;
315 }
169 } 316 }
170 }
171 317
318 return false;
319 }
172 /// <summary> 320 /// <summary>
173 /// Add a stream handler to the http server. If the handler already exists, then nothing happens. 321 /// Add a stream handler to the http server. If the handler already exists, then nothing happens.
174 /// </summary> 322 /// </summary>
@@ -396,12 +544,9 @@ namespace OpenSim.Framework.Servers.HttpServer
396 if (psEvArgs.Request != null) 544 if (psEvArgs.Request != null)
397 { 545 {
398 OSHttpRequest req = new OSHttpRequest(context, request); 546 OSHttpRequest req = new OSHttpRequest(context, request);
399
400 Stream requestStream = req.InputStream;
401
402 string requestBody; 547 string requestBody;
403 Encoding encoding = Encoding.UTF8; 548 Encoding encoding = Encoding.UTF8;
404 using(StreamReader reader = new StreamReader(requestStream, encoding)) 549 using(StreamReader reader = new StreamReader(req.InputStream, encoding))
405 requestBody = reader.ReadToEnd(); 550 requestBody = reader.ReadToEnd();
406 551
407 Hashtable keysvals = new Hashtable(); 552 Hashtable keysvals = new Hashtable();
@@ -460,7 +605,7 @@ namespace OpenSim.Framework.Servers.HttpServer
460 } 605 }
461 606
462 OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request),context); 607 OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request),context);
463 resp.ReuseContext = true; 608// resp.ReuseContext = true;
464// resp.ReuseContext = false; 609// resp.ReuseContext = false;
465 HandleRequest(req, resp); 610 HandleRequest(req, resp);
466 611
@@ -496,6 +641,8 @@ namespace OpenSim.Framework.Servers.HttpServer
496 byte[] buffer500 = SendHTML500(response); 641 byte[] buffer500 = SendHTML500(response);
497 response.OutputStream.Write(buffer500, 0, buffer500.Length); 642 response.OutputStream.Write(buffer500, 0, buffer500.Length);
498 response.Send(); 643 response.Send();
644 if(request.InputStream.CanRead)
645 request.InputStream.Close();
499 } 646 }
500 catch 647 catch
501 { 648 {
@@ -540,7 +687,6 @@ namespace OpenSim.Framework.Servers.HttpServer
540// } 687// }
541// } 688// }
542 689
543 //response.KeepAlive = true;
544 response.SendChunked = false; 690 response.SendChunked = false;
545 691
546 string path = request.RawUrl; 692 string path = request.RawUrl;
@@ -564,11 +710,10 @@ namespace OpenSim.Framework.Servers.HttpServer
564 { 710 {
565 //m_log.Debug("[BASE HTTP SERVER]: Found Caps based HTTP Handler"); 711 //m_log.Debug("[BASE HTTP SERVER]: Found Caps based HTTP Handler");
566 IGenericHTTPHandler HTTPRequestHandler = requestHandler as IGenericHTTPHandler; 712 IGenericHTTPHandler HTTPRequestHandler = requestHandler as IGenericHTTPHandler;
567 Stream requestStream = request.InputStream;
568 713
569 string requestBody; 714 string requestBody;
570 Encoding encoding = Encoding.UTF8; 715 Encoding encoding = Encoding.UTF8;
571 using(StreamReader reader = new StreamReader(requestStream, encoding)) 716 using(StreamReader reader = new StreamReader(request.InputStream, encoding))
572 requestBody = reader.ReadToEnd(); 717 requestBody = reader.ReadToEnd();
573 718
574 Hashtable keysvals = new Hashtable(); 719 Hashtable keysvals = new Hashtable();
@@ -609,7 +754,6 @@ namespace OpenSim.Framework.Servers.HttpServer
609 else 754 else
610 { 755 {
611 IStreamHandler streamHandler = (IStreamHandler)requestHandler; 756 IStreamHandler streamHandler = (IStreamHandler)requestHandler;
612
613 using (MemoryStream memoryStream = new MemoryStream()) 757 using (MemoryStream memoryStream = new MemoryStream())
614 { 758 {
615 streamHandler.Handle(path, request.InputStream, memoryStream, request, response); 759 streamHandler.Handle(path, request.InputStream, memoryStream, request, response);
@@ -720,10 +864,6 @@ namespace OpenSim.Framework.Servers.HttpServer
720 requestEndTick = Environment.TickCount; 864 requestEndTick = Environment.TickCount;
721 865
722 response.Send(); 866 response.Send();
723
724 //response.OutputStream.Close();
725
726 //response.FreeContext();
727 } 867 }
728 catch (SocketException e) 868 catch (SocketException e)
729 { 869 {
@@ -755,6 +895,9 @@ namespace OpenSim.Framework.Servers.HttpServer
755 } 895 }
756 finally 896 finally
757 { 897 {
898 if(request.InputStream.CanRead)
899 request.InputStream.Close();
900
758 // Every month or so this will wrap and give bad numbers, not really a problem 901 // Every month or so this will wrap and give bad numbers, not really a problem
759 // since its just for reporting 902 // since its just for reporting
760 int tickdiff = requestEndTick - requestStartTick; 903 int tickdiff = requestEndTick - requestStartTick;
@@ -1008,12 +1151,13 @@ namespace OpenSim.Framework.Servers.HttpServer
1008 using (StreamReader reader = new StreamReader(requestStream, Encoding.UTF8)) 1151 using (StreamReader reader = new StreamReader(requestStream, Encoding.UTF8))
1009 requestBody = reader.ReadToEnd(); 1152 requestBody = reader.ReadToEnd();
1010 1153
1011 } 1154 }
1012 finally 1155 finally
1013 { 1156 {
1014 if (innerStream != null) 1157 if (innerStream != null && innerStream.CanRead)
1015 innerStream.Dispose(); 1158 innerStream.Dispose();
1016 requestStream.Dispose(); 1159 if (requestStream.CanRead)
1160 requestStream.Dispose();
1017 } 1161 }
1018 1162
1019 //m_log.Debug(requestBody); 1163 //m_log.Debug(requestBody);
@@ -1094,6 +1238,17 @@ namespace OpenSim.Framework.Servers.HttpServer
1094 1238
1095 if (gridproxy) 1239 if (gridproxy)
1096 xmlRprcRequest.Params.Add("gridproxy"); // Param[4] 1240 xmlRprcRequest.Params.Add("gridproxy"); // Param[4]
1241
1242 // reserve this for
1243 // ... by Fumi.Iseki for DTLNSLMoneyServer
1244 // BUT make its presence possible to detect/parse
1245 string rcn = request.IHttpClientContext.SSLCommonName;
1246 if(!string.IsNullOrWhiteSpace(rcn))
1247 {
1248 rcn = "SSLCN:" + rcn;
1249 xmlRprcRequest.Params.Add(rcn); // Param[4] or Param[5]
1250 }
1251
1097 try 1252 try
1098 { 1253 {
1099 xmlRpcResponse = method(xmlRprcRequest, request.RemoteIPEndPoint); 1254 xmlRpcResponse = method(xmlRprcRequest, request.RemoteIPEndPoint);
@@ -1265,7 +1420,6 @@ namespace OpenSim.Framework.Servers.HttpServer
1265 requestBody= reader.ReadToEnd(); 1420 requestBody= reader.ReadToEnd();
1266 1421
1267 //m_log.DebugFormat("[OGP]: {0}:{1}", request.RawUrl, requestBody); 1422 //m_log.DebugFormat("[OGP]: {0}:{1}", request.RawUrl, requestBody);
1268 response.KeepAlive = true;
1269 1423
1270 OSD llsdRequest = null; 1424 OSD llsdRequest = null;
1271 OSD llsdResponse = null; 1425 OSD llsdResponse = null;
@@ -1781,20 +1935,13 @@ namespace OpenSim.Framework.Servers.HttpServer
1781 { 1935 {
1782 response.ProtocolVersion = (string)responsedata["http_protocol_version"]; 1936 response.ProtocolVersion = (string)responsedata["http_protocol_version"];
1783 } 1937 }
1784/* 1938
1785 if (responsedata.ContainsKey("keepalive")) 1939 if (responsedata.ContainsKey("keepalive"))
1786 { 1940 {
1787 bool keepalive = (bool)responsedata["keepalive"]; 1941 bool keepalive = (bool)responsedata["keepalive"];
1788 response.KeepAlive = keepalive; 1942 response.KeepAlive = keepalive;
1789 } 1943 }
1790 1944
1791 if (responsedata.ContainsKey("reusecontext"))
1792 response.ReuseContext = (bool) responsedata["reusecontext"];
1793*/
1794 // disable this things
1795 response.KeepAlive = false;
1796 response.ReuseContext = false;
1797
1798 // Cross-Origin Resource Sharing with simple requests 1945 // Cross-Origin Resource Sharing with simple requests
1799 if (responsedata.ContainsKey("access_control_allow_origin")) 1946 if (responsedata.ContainsKey("access_control_allow_origin"))
1800 response.AddHeader("Access-Control-Allow-Origin", (string)responsedata["access_control_allow_origin"]); 1947 response.AddHeader("Access-Control-Allow-Origin", (string)responsedata["access_control_allow_origin"]);
@@ -1807,11 +1954,8 @@ namespace OpenSim.Framework.Servers.HttpServer
1807 contentType = "text/html"; 1954 contentType = "text/html";
1808 } 1955 }
1809 1956
1810
1811
1812 // The client ignores anything but 200 here for web login, so ensure that this is 200 for that 1957 // The client ignores anything but 200 here for web login, so ensure that this is 200 for that
1813 1958
1814
1815 response.StatusCode = responsecode; 1959 response.StatusCode = responsecode;
1816 1960
1817 if (responsecode == (int)OSHttpStatusCode.RedirectMovedPermanently) 1961 if (responsecode == (int)OSHttpStatusCode.RedirectMovedPermanently)
@@ -1821,7 +1965,6 @@ namespace OpenSim.Framework.Servers.HttpServer
1821 } 1965 }
1822 1966
1823 response.AddHeader("Content-Type", contentType); 1967 response.AddHeader("Content-Type", contentType);
1824
1825 if (responsedata.ContainsKey("headers")) 1968 if (responsedata.ContainsKey("headers"))
1826 { 1969 {
1827 Hashtable headerdata = (Hashtable)responsedata["headers"]; 1970 Hashtable headerdata = (Hashtable)responsedata["headers"];
@@ -1895,7 +2038,7 @@ namespace OpenSim.Framework.Servers.HttpServer
1895 2038
1896 public void Start() 2039 public void Start()
1897 { 2040 {
1898 Start(true); 2041 Start(true,true);
1899 } 2042 }
1900 2043
1901 /// <summary> 2044 /// <summary>
@@ -1905,7 +2048,7 @@ namespace OpenSim.Framework.Servers.HttpServer
1905 /// If true then poll responses are performed asynchronsly. 2048 /// If true then poll responses are performed asynchronsly.
1906 /// Option exists to allow regression tests to perform processing synchronously. 2049 /// Option exists to allow regression tests to perform processing synchronously.
1907 /// </param> 2050 /// </param>
1908 public void Start(bool performPollResponsesAsync) 2051 public void Start(bool performPollResponsesAsync, bool runPool)
1909 { 2052 {
1910 m_log.InfoFormat( 2053 m_log.InfoFormat(
1911 "[BASE HTTP SERVER]: Starting {0} server on port {1}", UseSSL ? "HTTPS" : "HTTP", Port); 2054 "[BASE HTTP SERVER]: Starting {0} server on port {1}", UseSSL ? "HTTPS" : "HTTP", Port);
@@ -1934,6 +2077,8 @@ namespace OpenSim.Framework.Servers.HttpServer
1934 //m_httpListener.Prefixes.Add("https://+:" + (m_sslport) + "/"); 2077 //m_httpListener.Prefixes.Add("https://+:" + (m_sslport) + "/");
1935 //m_httpListener.Prefixes.Add("http://+:" + m_port + "/"); 2078 //m_httpListener.Prefixes.Add("http://+:" + m_port + "/");
1936 m_httpListener2 = CoolHTTPListener.Create(IPAddress.Any, (int)m_port, m_cert); 2079 m_httpListener2 = CoolHTTPListener.Create(IPAddress.Any, (int)m_port, m_cert);
2080 if(m_certificateValidationCallback != null)
2081 m_httpListener2.CertificateValidationCallback = m_certificateValidationCallback;
1937 m_httpListener2.ExceptionThrown += httpServerException; 2082 m_httpListener2.ExceptionThrown += httpServerException;
1938 m_httpListener2.LogWriter = httpserverlog; 2083 m_httpListener2.LogWriter = httpserverlog;
1939 } 2084 }
@@ -1943,9 +2088,11 @@ namespace OpenSim.Framework.Servers.HttpServer
1943 m_httpListener2.Start(64); 2088 m_httpListener2.Start(64);
1944 2089
1945 // Long Poll Service Manager with 3 worker threads a 25 second timeout for no events 2090 // Long Poll Service Manager with 3 worker threads a 25 second timeout for no events
1946 2091 if(runPool)
1947 PollServiceRequestManager = new PollServiceRequestManager(this, performPollResponsesAsync, 2, 25000); 2092 {
1948 PollServiceRequestManager.Start(); 2093 PollServiceRequestManager = new PollServiceRequestManager(this, performPollResponsesAsync, 2, 25000);
2094 PollServiceRequestManager.Start();
2095 }
1949 2096
1950 HTTPDRunning = true; 2097 HTTPDRunning = true;
1951 2098
@@ -1959,7 +2106,7 @@ namespace OpenSim.Framework.Servers.HttpServer
1959 catch (Exception e) 2106 catch (Exception e)
1960 { 2107 {
1961 m_log.Error("[BASE HTTP SERVER]: Error - " + e.Message); 2108 m_log.Error("[BASE HTTP SERVER]: Error - " + e.Message);
1962 m_log.Error("[BASE HTTP SERVER]: Tip: Do you have permission to listen on port " + m_port + ", " + m_sslport + "?"); 2109 m_log.Error("[BASE HTTP SERVER]: Tip: Do you have permission to listen on port " + m_port + "?");
1963 2110
1964 // We want this exception to halt the entire server since in current configurations we aren't too 2111 // We want this exception to halt the entire server since in current configurations we aren't too
1965 // useful without inbound HTTP. 2112 // useful without inbound HTTP.
@@ -2125,10 +2272,9 @@ namespace OpenSim.Framework.Servers.HttpServer
2125 string file = Path.Combine(".", "http_500.html"); 2272 string file = Path.Combine(".", "http_500.html");
2126 if (!File.Exists(file)) 2273 if (!File.Exists(file))
2127 return getDefaultHTTP500(); 2274 return getDefaultHTTP500();
2128 2275 string result;
2129 StreamReader sr = File.OpenText(file); 2276 using(StreamReader sr = File.OpenText(file))
2130 string result = sr.ReadToEnd(); 2277 result = sr.ReadToEnd();
2131 sr.Close();
2132 return result; 2278 return result;
2133 } 2279 }
2134 2280
diff --git a/OpenSim/Framework/Servers/HttpServer/Interfaces/IOSHttpResponse.cs b/OpenSim/Framework/Servers/HttpServer/Interfaces/IOSHttpResponse.cs
index f61b090..d26b68a 100644
--- a/OpenSim/Framework/Servers/HttpServer/Interfaces/IOSHttpResponse.cs
+++ b/OpenSim/Framework/Servers/HttpServer/Interfaces/IOSHttpResponse.cs
@@ -118,7 +118,7 @@ namespace OpenSim.Framework.Servers.HttpServer
118 /// </summary> 118 /// </summary>
119 string StatusDescription { get; set; } 119 string StatusDescription { get; set; }
120 120
121 bool ReuseContext { get; set; } 121// bool ReuseContext { get; set; }
122 122
123 /// <summary> 123 /// <summary>
124 /// Add a header field and content to the response. 124 /// Add a header field and content to the response.
diff --git a/OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs b/OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs
index d7744fc..8e1b545 100644
--- a/OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs
+++ b/OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs
@@ -256,7 +256,7 @@ namespace OpenSim.Framework.Servers.HttpServer
256 _httpResponse.Reason = value; 256 _httpResponse.Reason = value;
257 } 257 }
258 } 258 }
259 259/*
260 public bool ReuseContext 260 public bool ReuseContext
261 { 261 {
262 get 262 get
@@ -275,7 +275,7 @@ namespace OpenSim.Framework.Servers.HttpServer
275 } 275 }
276 } 276 }
277 } 277 }
278 278*/
279 protected IHttpResponse _httpResponse; 279 protected IHttpResponse _httpResponse;
280 private IHttpClientContext _httpClientContext; 280 private IHttpClientContext _httpClientContext;
281 281
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs
index 7150aad..7c7d08d 100644
--- a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs
+++ b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs
@@ -37,6 +37,7 @@ namespace OpenSim.Framework.Servers.HttpServer
37 public delegate Hashtable GetEventsMethod(UUID requestID, UUID pId); 37 public delegate Hashtable GetEventsMethod(UUID requestID, UUID pId);
38 38
39 public delegate Hashtable NoEventsMethod(UUID requestID, UUID pId); 39 public delegate Hashtable NoEventsMethod(UUID requestID, UUID pId);
40 public delegate void DropMethod(UUID requestID, UUID pId);
40 41
41 public class PollServiceEventArgs : EventArgs 42 public class PollServiceEventArgs : EventArgs
42 { 43 {
@@ -44,6 +45,7 @@ namespace OpenSim.Framework.Servers.HttpServer
44 public GetEventsMethod GetEvents; 45 public GetEventsMethod GetEvents;
45 public NoEventsMethod NoEvents; 46 public NoEventsMethod NoEvents;
46 public RequestMethod Request; 47 public RequestMethod Request;
48 public DropMethod Drop;
47 public UUID Id; 49 public UUID Id;
48 public int TimeOutms; 50 public int TimeOutms;
49 public EventType Type; 51 public EventType Type;
@@ -73,13 +75,14 @@ namespace OpenSim.Framework.Servers.HttpServer
73 RequestMethod pRequest, 75 RequestMethod pRequest,
74 string pUrl, 76 string pUrl,
75 HasEventsMethod pHasEvents, GetEventsMethod pGetEvents, NoEventsMethod pNoEvents, 77 HasEventsMethod pHasEvents, GetEventsMethod pGetEvents, NoEventsMethod pNoEvents,
76 UUID pId, int pTimeOutms) 78 DropMethod pDrop, UUID pId, int pTimeOutms)
77 { 79 {
78 Request = pRequest; 80 Request = pRequest;
79 Url = pUrl; 81 Url = pUrl;
80 HasEvents = pHasEvents; 82 HasEvents = pHasEvents;
81 GetEvents = pGetEvents; 83 GetEvents = pGetEvents;
82 NoEvents = pNoEvents; 84 NoEvents = pNoEvents;
85 Drop = pDrop;
83 Id = pId; 86 Id = pId;
84 TimeOutms = pTimeOutms; 87 TimeOutms = pTimeOutms;
85 Type = EventType.Poll; 88 Type = EventType.Poll;
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs
index fefcb20..d5c25b9 100644
--- a/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs
+++ b/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs
@@ -47,8 +47,10 @@ namespace OpenSim.Framework.Servers.HttpServer
47 public readonly UUID RequestID; 47 public readonly UUID RequestID;
48 public int contextHash; 48 public int contextHash;
49 49
50/*
50 private void GenContextHash() 51 private void GenContextHash()
51 { 52 {
53
52 Random rnd = new Random(); 54 Random rnd = new Random();
53 contextHash = 0; 55 contextHash = 0;
54 if (Request.Headers["remote_addr"] != null) 56 if (Request.Headers["remote_addr"] != null)
@@ -62,8 +64,9 @@ namespace OpenSim.Framework.Servers.HttpServer
62 } 64 }
63 else 65 else
64 contextHash += rnd.Next() & 0xffff; 66 contextHash += rnd.Next() & 0xffff;
65 }
66 67
68 }
69*/
67 public PollServiceHttpRequest( 70 public PollServiceHttpRequest(
68 PollServiceEventArgs pPollServiceArgs, IHttpClientContext pHttpContext, IHttpRequest pRequest) 71 PollServiceEventArgs pPollServiceArgs, IHttpClientContext pHttpContext, IHttpRequest pRequest)
69 { 72 {
@@ -72,7 +75,8 @@ namespace OpenSim.Framework.Servers.HttpServer
72 Request = pRequest; 75 Request = pRequest;
73 RequestTime = System.Environment.TickCount; 76 RequestTime = System.Environment.TickCount;
74 RequestID = UUID.Random(); 77 RequestID = UUID.Random();
75 GenContextHash(); 78// GenContextHash();
79 contextHash = HttpContext.contextID;
76 } 80 }
77 81
78 internal void DoHTTPGruntWork(BaseHttpServer server, Hashtable responsedata) 82 internal void DoHTTPGruntWork(BaseHttpServer server, Hashtable responsedata)
@@ -88,7 +92,7 @@ namespace OpenSim.Framework.Servers.HttpServer
88 response.SendChunked = false; 92 response.SendChunked = false;
89 response.ContentLength64 = buffer.Length; 93 response.ContentLength64 = buffer.Length;
90 response.ContentEncoding = Encoding.UTF8; 94 response.ContentEncoding = Encoding.UTF8;
91 response.ReuseContext = false; 95// response.ReuseContext = false;
92 96
93 try 97 try
94 { 98 {
@@ -116,7 +120,7 @@ namespace OpenSim.Framework.Servers.HttpServer
116 response.SendChunked = false; 120 response.SendChunked = false;
117 response.ContentLength64 = 0; 121 response.ContentLength64 = 0;
118 response.ContentEncoding = Encoding.UTF8; 122 response.ContentEncoding = Encoding.UTF8;
119 response.ReuseContext = false; 123// response.ReuseContext = false;
120 response.KeepAlive = false; 124 response.KeepAlive = false;
121 response.SendChunked = false; 125 response.SendChunked = false;
122 response.StatusCode = 503; 126 response.StatusCode = 503;
@@ -126,25 +130,9 @@ namespace OpenSim.Framework.Servers.HttpServer
126 response.OutputStream.Flush(); 130 response.OutputStream.Flush();
127 response.Send(); 131 response.Send();
128 } 132 }
129 catch (Exception e) 133 catch
130 { 134 {
131 } 135 }
132 } 136 }
133 } 137 }
134
135 class PollServiceHttpRequestComparer : IEqualityComparer<PollServiceHttpRequest>
136 {
137 public bool Equals(PollServiceHttpRequest b1, PollServiceHttpRequest b2)
138 {
139 if (b1.contextHash != b2.contextHash)
140 return false;
141 bool b = Object.ReferenceEquals(b1.HttpContext, b2.HttpContext);
142 return b;
143 }
144
145 public int GetHashCode(PollServiceHttpRequest b2)
146 {
147 return (int)b2.contextHash;
148 }
149 }
150} \ No newline at end of file 138} \ No newline at end of file
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
index c6a3e65..a2f6a11 100644
--- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
+++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
@@ -30,13 +30,10 @@ using System.Collections;
30using System.Threading; 30using System.Threading;
31using System.Reflection; 31using System.Reflection;
32using log4net; 32using log4net;
33using HttpServer;
34using OpenSim.Framework;
35using OpenSim.Framework.Monitoring; 33using OpenSim.Framework.Monitoring;
36using Amib.Threading; 34using Amib.Threading;
37using System.IO;
38using System.Text;
39using System.Collections.Generic; 35using System.Collections.Generic;
36using System.Collections.Concurrent;
40 37
41namespace OpenSim.Framework.Servers.HttpServer 38namespace OpenSim.Framework.Servers.HttpServer
42{ 39{
@@ -46,9 +43,9 @@ namespace OpenSim.Framework.Servers.HttpServer
46 43
47 private readonly BaseHttpServer m_server; 44 private readonly BaseHttpServer m_server;
48 45
49 private Dictionary<PollServiceHttpRequest, Queue<PollServiceHttpRequest>> m_bycontext; 46 private Dictionary<int, Queue<PollServiceHttpRequest>> m_bycontext;
50 private BlockingQueue<PollServiceHttpRequest> m_requests = new BlockingQueue<PollServiceHttpRequest>(); 47 private BlockingCollection<PollServiceHttpRequest> m_requests = new BlockingCollection<PollServiceHttpRequest>();
51 private static Queue<PollServiceHttpRequest> m_retryRequests = new Queue<PollServiceHttpRequest>(); 48 private static ConcurrentQueue<PollServiceHttpRequest> m_retryRequests = new ConcurrentQueue<PollServiceHttpRequest>();
52 49
53 private uint m_WorkerThreadCount = 0; 50 private uint m_WorkerThreadCount = 0;
54 private Thread[] m_workerThreads; 51 private Thread[] m_workerThreads;
@@ -65,8 +62,7 @@ namespace OpenSim.Framework.Servers.HttpServer
65 m_WorkerThreadCount = pWorkerThreadCount; 62 m_WorkerThreadCount = pWorkerThreadCount;
66 m_workerThreads = new Thread[m_WorkerThreadCount]; 63 m_workerThreads = new Thread[m_WorkerThreadCount];
67 64
68 PollServiceHttpRequestComparer preqCp = new PollServiceHttpRequestComparer(); 65 m_bycontext = new Dictionary<int, Queue<PollServiceHttpRequest>>(256);
69 m_bycontext = new Dictionary<PollServiceHttpRequest, Queue<PollServiceHttpRequest>>(preqCp);
70 66
71 STPStartInfo startInfo = new STPStartInfo(); 67 STPStartInfo startInfo = new STPStartInfo();
72 startInfo.IdleTimeout = 30000; 68 startInfo.IdleTimeout = 30000;
@@ -105,32 +101,28 @@ namespace OpenSim.Framework.Servers.HttpServer
105 true, 101 true,
106 null, 102 null,
107 1000 * 60 * 10); 103 1000 * 60 * 10);
108
109
110 } 104 }
111 105
112 private void ReQueueEvent(PollServiceHttpRequest req) 106 private void ReQueueEvent(PollServiceHttpRequest req)
113 { 107 {
114 if (m_running) 108 if (m_running)
115 { 109 m_retryRequests.Enqueue(req);
116 lock (m_retryRequests)
117 m_retryRequests.Enqueue(req);
118 }
119 } 110 }
120 111
121 public void Enqueue(PollServiceHttpRequest req) 112 public void Enqueue(PollServiceHttpRequest req)
122 { 113 {
114 Queue<PollServiceHttpRequest> ctxQeueue;
115 int rhash = req.contextHash;
123 lock (m_bycontext) 116 lock (m_bycontext)
124 { 117 {
125 Queue<PollServiceHttpRequest> ctxQeueue; 118 if (m_bycontext.TryGetValue(rhash, out ctxQeueue))
126 if (m_bycontext.TryGetValue(req, out ctxQeueue))
127 { 119 {
128 ctxQeueue.Enqueue(req); 120 ctxQeueue.Enqueue(req);
129 } 121 }
130 else 122 else
131 { 123 {
132 ctxQeueue = new Queue<PollServiceHttpRequest>(); 124 ctxQeueue = new Queue<PollServiceHttpRequest>();
133 m_bycontext[req] = ctxQeueue; 125 m_bycontext[rhash] = ctxQeueue;
134 EnqueueInt(req); 126 EnqueueInt(req);
135 } 127 }
136 } 128 }
@@ -139,9 +131,10 @@ namespace OpenSim.Framework.Servers.HttpServer
139 public void byContextDequeue(PollServiceHttpRequest req) 131 public void byContextDequeue(PollServiceHttpRequest req)
140 { 132 {
141 Queue<PollServiceHttpRequest> ctxQeueue; 133 Queue<PollServiceHttpRequest> ctxQeueue;
134 int rhash = req.contextHash;
142 lock (m_bycontext) 135 lock (m_bycontext)
143 { 136 {
144 if (m_bycontext.TryGetValue(req, out ctxQeueue)) 137 if (m_bycontext.TryGetValue(rhash, out ctxQeueue))
145 { 138 {
146 if (ctxQeueue.Count > 0) 139 if (ctxQeueue.Count > 0)
147 { 140 {
@@ -150,30 +143,41 @@ namespace OpenSim.Framework.Servers.HttpServer
150 } 143 }
151 else 144 else
152 { 145 {
153 m_bycontext.Remove(req); 146 m_bycontext.Remove(rhash);
154 } 147 }
155 } 148 }
156 } 149 }
157 } 150 }
158 151
152 public void DropByContext(PollServiceHttpRequest req)
153 {
154 Queue<PollServiceHttpRequest> ctxQeueue;
155 int rhash = req.contextHash;
156 lock (m_bycontext)
157 {
158 if (m_bycontext.TryGetValue(rhash, out ctxQeueue))
159 {
160 ctxQeueue.Clear();
161 m_bycontext.Remove(rhash);
162 }
163 }
164 }
165
159 public void EnqueueInt(PollServiceHttpRequest req) 166 public void EnqueueInt(PollServiceHttpRequest req)
160 { 167 {
161 if (m_running) 168 if (m_running)
162 m_requests.Enqueue(req); 169 m_requests.Add(req);
163 } 170 }
164 171
165 private void CheckRetries() 172 private void CheckRetries()
166 { 173 {
174 PollServiceHttpRequest preq;
167 while (m_running) 175 while (m_running)
168
169 { 176 {
170 Thread.Sleep(100); // let the world move .. back to faster rate 177 Thread.Sleep(100);
171 Watchdog.UpdateThread(); 178 Watchdog.UpdateThread();
172 lock (m_retryRequests) 179 while (m_running && m_retryRequests.TryDequeue(out preq))
173 { 180 m_requests.Add(preq);
174 while (m_retryRequests.Count > 0 && m_running)
175 m_requests.Enqueue(m_retryRequests.Dequeue());
176 }
177 } 181 }
178 } 182 }
179 183
@@ -194,103 +198,117 @@ namespace OpenSim.Framework.Servers.HttpServer
194 qu.Clear(); 198 qu.Clear();
195 m_bycontext.Clear(); 199 m_bycontext.Clear();
196 200
201 PollServiceHttpRequest req;
197 try 202 try
198 { 203 {
199 foreach (PollServiceHttpRequest req in m_retryRequests) 204 while(m_retryRequests.TryDequeue(out req))
200 {
201 req.DoHTTPstop(m_server); 205 req.DoHTTPstop(m_server);
202 }
203 } 206 }
204 catch 207 catch
205 { 208 {
206 } 209 }
207 210
208 PollServiceHttpRequest wreq; 211 try
209 212 {
210 m_retryRequests.Clear(); 213 while(m_requests.TryTake(out req, 0))
211 214 req.DoHTTPstop(m_server);
212 while (m_requests.Count() > 0) 215 }
216 catch
213 { 217 {
214 try
215 {
216 wreq = m_requests.Dequeue(0);
217 wreq.DoHTTPstop(m_server);
218 }
219 catch
220 {
221 }
222 } 218 }
223 219
224 m_requests.Clear(); 220 m_requests.Dispose();
221
225 } 222 }
226 223
227 // work threads 224 // work threads
228 225
229 private void PoolWorkerJob() 226 private void PoolWorkerJob()
230 { 227 {
228 PollServiceHttpRequest req;
231 while (m_running) 229 while (m_running)
232 { 230 {
233 PollServiceHttpRequest req = m_requests.Dequeue(4500); 231 req = null;
234 Watchdog.UpdateThread(); 232 if(!m_requests.TryTake(out req, 4500) || req == null)
235 if (req != null)
236 { 233 {
237 try 234 Watchdog.UpdateThread();
235 continue;
236 }
237
238 Watchdog.UpdateThread();
239
240 try
241 {
242 if(!req.HttpContext.CanSend())
238 { 243 {
239 if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id)) 244 req.PollServiceArgs.Drop(req.RequestID, req.PollServiceArgs.Id);
245 byContextDequeue(req);
246 continue;
247 }
248
249 if(req.HttpContext.IsSending())
250 {
251 if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms)
240 { 252 {
241 Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id); 253 req.PollServiceArgs.Drop(req.RequestID, req.PollServiceArgs.Id);
254 byContextDequeue(req);
255 }
256 else
257 ReQueueEvent(req);
258 continue;
259 }
242 260
261 if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id))
262 {
263 PollServiceHttpRequest nreq = req;
264 m_threadPool.QueueWorkItem(x =>
265 {
266 try
267 {
268 Hashtable responsedata = nreq.PollServiceArgs.GetEvents(nreq.RequestID, nreq.PollServiceArgs.Id);
269 nreq.DoHTTPGruntWork(m_server, responsedata);
270 }
271 catch (ObjectDisposedException) { }
272 finally
273 {
274 byContextDequeue(nreq);
275 nreq = null;
276 }
277 return null;
278 }, null);
279 }
280 else
281 {
282 if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms)
283 {
284 PollServiceHttpRequest nreq = req;
243 m_threadPool.QueueWorkItem(x => 285 m_threadPool.QueueWorkItem(x =>
244 { 286 {
245 try 287 try
246 { 288 {
247 req.DoHTTPGruntWork(m_server, responsedata); 289 nreq.DoHTTPGruntWork(m_server,
248 } 290 nreq.PollServiceArgs.NoEvents(nreq.RequestID, nreq.PollServiceArgs.Id));
249 catch (ObjectDisposedException)
250 {
251 } 291 }
292 catch (ObjectDisposedException) {}
252 finally 293 finally
253 { 294 {
254 byContextDequeue(req); 295 byContextDequeue(nreq);
296 nreq = null;
255 } 297 }
256 return null; 298 return null;
257 }, null); 299 }, null);
258 } 300 }
259 else 301 else
260 { 302 {
261 if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms) 303 ReQueueEvent(req);
262 {
263 m_threadPool.QueueWorkItem(x =>
264 {
265 try
266 {
267 req.DoHTTPGruntWork(m_server,
268 req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id));
269 }
270 catch (ObjectDisposedException)
271 {
272 // Ignore it, no need to reply
273 }
274 finally
275 {
276 byContextDequeue(req);
277 }
278 return null;
279 }, null);
280 }
281 else
282 {
283 ReQueueEvent(req);
284 }
285 } 304 }
286 } 305 }
287 catch (Exception e) 306 }
288 { 307 catch (Exception e)
289 m_log.ErrorFormat("Exception in poll service thread: " + e.ToString()); 308 {
290 } 309 m_log.ErrorFormat("Exception in poll service thread: " + e.ToString());
291 } 310 }
292 } 311 }
293 } 312 }
294
295 } 313 }
296} 314}
diff --git a/OpenSim/Framework/Servers/HttpServer/RestDeserialiseHandler.cs b/OpenSim/Framework/Servers/HttpServer/RestDeserialiseHandler.cs
index 67fc14e..bd55657 100644
--- a/OpenSim/Framework/Servers/HttpServer/RestDeserialiseHandler.cs
+++ b/OpenSim/Framework/Servers/HttpServer/RestDeserialiseHandler.cs
@@ -54,8 +54,6 @@ namespace OpenSim.Framework.Servers.HttpServer
54 TRequest deserial; 54 TRequest deserial;
55 using (XmlTextReader xmlReader = new XmlTextReader(request)) 55 using (XmlTextReader xmlReader = new XmlTextReader(request))
56 { 56 {
57 xmlReader.ProhibitDtd = true;
58
59 XmlSerializer deserializer = new XmlSerializer(typeof (TRequest)); 57 XmlSerializer deserializer = new XmlSerializer(typeof (TRequest));
60 deserial = (TRequest) deserializer.Deserialize(xmlReader); 58 deserial = (TRequest) deserializer.Deserialize(xmlReader);
61 } 59 }
diff --git a/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs b/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs
index 158befa..68073c1 100644
--- a/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs
+++ b/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs
@@ -210,8 +210,6 @@ namespace OpenSim.Framework.Servers.HttpServer
210 { 210 {
211 try 211 try
212 { 212 {
213 xmlReader.ProhibitDtd = true;
214
215 XmlSerializer deserializer = new XmlSerializer(typeof(RestSessionObject<TRequest>)); 213 XmlSerializer deserializer = new XmlSerializer(typeof(RestSessionObject<TRequest>));
216 deserial = (RestSessionObject<TRequest>)deserializer.Deserialize(xmlReader); 214 deserial = (RestSessionObject<TRequest>)deserializer.Deserialize(xmlReader);
217 } 215 }
@@ -271,8 +269,6 @@ namespace OpenSim.Framework.Servers.HttpServer
271 { 269 {
272 try 270 try
273 { 271 {
274 xmlReader.ProhibitDtd = true;
275
276 XmlSerializer deserializer = new XmlSerializer(typeof(TRequest)); 272 XmlSerializer deserializer = new XmlSerializer(typeof(TRequest));
277 deserial = (TRequest)deserializer.Deserialize(xmlReader); 273 deserial = (TRequest)deserializer.Deserialize(xmlReader);
278 } 274 }
diff --git a/OpenSim/Framework/Servers/MainServer.cs b/OpenSim/Framework/Servers/MainServer.cs
index 9b1d906..523ccba 100644
--- a/OpenSim/Framework/Servers/MainServer.cs
+++ b/OpenSim/Framework/Servers/MainServer.cs
@@ -42,6 +42,7 @@ namespace OpenSim.Framework.Servers
42// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 42// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43 43
44 private static BaseHttpServer instance = null; 44 private static BaseHttpServer instance = null;
45 private static BaseHttpServer unsecureinstance = null;
45 private static Dictionary<uint, BaseHttpServer> m_Servers = new Dictionary<uint, BaseHttpServer>(); 46 private static Dictionary<uint, BaseHttpServer> m_Servers = new Dictionary<uint, BaseHttpServer>();
46 47
47 /// <summary> 48 /// <summary>
@@ -93,6 +94,21 @@ namespace OpenSim.Framework.Servers
93 } 94 }
94 } 95 }
95 96
97
98 public static BaseHttpServer UnSecureInstance
99 {
100 get { return unsecureinstance; }
101
102 set
103 {
104 lock (m_Servers)
105 if (!m_Servers.ContainsValue(value))
106 throw new Exception("HTTP server must already have been registered to be set as the main instance");
107
108 unsecureinstance = value;
109 }
110 }
111
96 /// <summary> 112 /// <summary>
97 /// Get all the registered servers. 113 /// Get all the registered servers.
98 /// </summary> 114 /// </summary>
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 7093010..8e4a953 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -92,6 +92,7 @@ namespace OpenSim.Framework
92 // explicitly given 92 // explicitly given
93 All = 0x8e000, 93 All = 0x8e000,
94 AllAndExport = 0x9e000, 94 AllAndExport = 0x9e000,
95 AllAndExportNoMod = 0x9a000,
95 AllEffective = 0x9e000, 96 AllEffective = 0x9e000,
96 UnfoldedMask = 0x1e000 97 UnfoldedMask = 0x1e000
97 } 98 }
@@ -671,7 +672,7 @@ namespace OpenSim.Framework
671 public static string GetFormattedXml(string rawXml) 672 public static string GetFormattedXml(string rawXml)
672 { 673 {
673 XmlDocument xd = new XmlDocument(); 674 XmlDocument xd = new XmlDocument();
674 xd.XmlResolver=null; 675
675 xd.LoadXml(rawXml); 676 xd.LoadXml(rawXml);
676 677
677 StringBuilder sb = new StringBuilder(); 678 StringBuilder sb = new StringBuilder();
@@ -2675,7 +2676,7 @@ namespace OpenSim.Framework
2675 2676
2676 callback(o); 2677 callback(o);
2677 } 2678 }
2678 catch (ThreadAbortException e) 2679 catch (ThreadAbortException)
2679 { 2680 {
2680 } 2681 }
2681 catch (Exception e) 2682 catch (Exception e)
@@ -2858,6 +2859,12 @@ namespace OpenSim.Framework
2858 /// <returns>The stack trace, or null if failed to get it</returns> 2859 /// <returns>The stack trace, or null if failed to get it</returns>
2859 private static StackTrace GetStackTrace(Thread targetThread) 2860 private static StackTrace GetStackTrace(Thread targetThread)
2860 { 2861 {
2862
2863 return null;
2864/*
2865 not only this does not work on mono but it is not longer recomended on windows.
2866 can cause deadlocks etc.
2867
2861 if (IsPlatformMono) 2868 if (IsPlatformMono)
2862 { 2869 {
2863 // This doesn't work in Mono 2870 // This doesn't work in Mono
@@ -2920,6 +2927,7 @@ namespace OpenSim.Framework
2920 // Signal the fallack-thread to stop 2927 // Signal the fallack-thread to stop
2921 exitedSafely.Set(); 2928 exitedSafely.Set();
2922 } 2929 }
2930*/
2923 } 2931 }
2924#pragma warning restore 0618 2932#pragma warning restore 0618
2925 2933
diff --git a/OpenSim/Framework/VersionInfo.cs b/OpenSim/Framework/VersionInfo.cs
index 8426eb0..eac5aae 100644
--- a/OpenSim/Framework/VersionInfo.cs
+++ b/OpenSim/Framework/VersionInfo.cs
@@ -30,7 +30,7 @@ namespace OpenSim
30 public class VersionInfo 30 public class VersionInfo
31 { 31 {
32 public const string VersionNumber = "0.9.1.0"; 32 public const string VersionNumber = "0.9.1.0";
33 public const string AssemblyVersionNumber = "0.9.1.*"; 33 public const string AssemblyVersionNumber = "0.9.1.0";
34 34
35 public const Flavour VERSION_FLAVOUR = Flavour.Dev; 35 public const Flavour VERSION_FLAVOUR = Flavour.Dev;
36 36
@@ -53,7 +53,7 @@ namespace OpenSim
53 53
54 public static string GetVersionString(string versionNumber, Flavour flavour) 54 public static string GetVersionString(string versionNumber, Flavour flavour)
55 { 55 {
56 string versionString = "OpenSim " + versionNumber + " " + flavour; 56 string versionString = "OpenSim " + versionNumber + " Snail " + flavour;
57 return versionString.PadRight(VERSIONINFO_VERSION_LENGTH); 57 return versionString.PadRight(VERSIONINFO_VERSION_LENGTH);
58 } 58 }
59 59