diff options
author | Oren Hurvitz | 2014-06-01 17:39:11 +0300 |
---|---|---|
committer | Oren Hurvitz | 2014-07-21 08:30:03 +0100 |
commit | 99ac770abbe3a95887c4b10c82f3985aa878eeef (patch) | |
tree | 8c946dab083dd50a352f3861415eca43185d8d95 /OpenSim/Server/Handlers | |
parent | Set "[Terrain]SendTerrainUpdatesByViewDistance=true" by default. (diff) | |
download | opensim-SC_OLD-99ac770abbe3a95887c4b10c82f3985aa878eeef.zip opensim-SC_OLD-99ac770abbe3a95887c4b10c82f3985aa878eeef.tar.gz opensim-SC_OLD-99ac770abbe3a95887c4b10c82f3985aa878eeef.tar.bz2 opensim-SC_OLD-99ac770abbe3a95887c4b10c82f3985aa878eeef.tar.xz |
Close streams immediately when we finish using them
Diffstat (limited to 'OpenSim/Server/Handlers')
11 files changed, 65 insertions, 145 deletions
diff --git a/OpenSim/Server/Handlers/Authentication/AuthenticationServerPostHandler.cs b/OpenSim/Server/Handlers/Authentication/AuthenticationServerPostHandler.cs index 5d65f67..6ee98b3 100644 --- a/OpenSim/Server/Handlers/Authentication/AuthenticationServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Authentication/AuthenticationServerPostHandler.cs | |||
@@ -209,7 +209,7 @@ namespace OpenSim.Server.Handlers.Authentication | |||
209 | 209 | ||
210 | rootElement.AppendChild(result); | 210 | rootElement.AppendChild(result); |
211 | 211 | ||
212 | return DocToBytes(doc); | 212 | return Util.DocToBytes(doc); |
213 | } | 213 | } |
214 | 214 | ||
215 | byte[] GetAuthInfo(UUID principalID) | 215 | byte[] GetAuthInfo(UUID principalID) |
@@ -279,7 +279,7 @@ namespace OpenSim.Server.Handlers.Authentication | |||
279 | 279 | ||
280 | rootElement.AppendChild(result); | 280 | rootElement.AppendChild(result); |
281 | 281 | ||
282 | return DocToBytes(doc); | 282 | return Util.DocToBytes(doc); |
283 | } | 283 | } |
284 | 284 | ||
285 | private byte[] SuccessResult(string token) | 285 | private byte[] SuccessResult(string token) |
@@ -306,18 +306,7 @@ namespace OpenSim.Server.Handlers.Authentication | |||
306 | 306 | ||
307 | rootElement.AppendChild(t); | 307 | rootElement.AppendChild(t); |
308 | 308 | ||
309 | return DocToBytes(doc); | 309 | return Util.DocToBytes(doc); |
310 | } | ||
311 | |||
312 | private byte[] DocToBytes(XmlDocument doc) | ||
313 | { | ||
314 | MemoryStream ms = new MemoryStream(); | ||
315 | XmlTextWriter xw = new XmlTextWriter(ms, null); | ||
316 | xw.Formatting = Formatting.Indented; | ||
317 | doc.WriteTo(xw); | ||
318 | xw.Flush(); | ||
319 | |||
320 | return ms.GetBuffer(); | ||
321 | } | 310 | } |
322 | 311 | ||
323 | private byte[] ResultToBytes(Dictionary<string, object> result) | 312 | private byte[] ResultToBytes(Dictionary<string, object> result) |
diff --git a/OpenSim/Server/Handlers/Avatar/AvatarServerPostHandler.cs b/OpenSim/Server/Handlers/Avatar/AvatarServerPostHandler.cs index 59dbed4..ff8699f 100644 --- a/OpenSim/Server/Handlers/Avatar/AvatarServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Avatar/AvatarServerPostHandler.cs | |||
@@ -247,7 +247,7 @@ namespace OpenSim.Server.Handlers.Avatar | |||
247 | 247 | ||
248 | rootElement.AppendChild(result); | 248 | rootElement.AppendChild(result); |
249 | 249 | ||
250 | return DocToBytes(doc); | 250 | return Util.DocToBytes(doc); |
251 | } | 251 | } |
252 | 252 | ||
253 | private byte[] FailureResult() | 253 | private byte[] FailureResult() |
@@ -269,18 +269,7 @@ namespace OpenSim.Server.Handlers.Avatar | |||
269 | 269 | ||
270 | rootElement.AppendChild(result); | 270 | rootElement.AppendChild(result); |
271 | 271 | ||
272 | return DocToBytes(doc); | 272 | return Util.DocToBytes(doc); |
273 | } | ||
274 | |||
275 | private byte[] DocToBytes(XmlDocument doc) | ||
276 | { | ||
277 | MemoryStream ms = new MemoryStream(); | ||
278 | XmlTextWriter xw = new XmlTextWriter(ms, null); | ||
279 | xw.Formatting = Formatting.Indented; | ||
280 | doc.WriteTo(xw); | ||
281 | xw.Flush(); | ||
282 | |||
283 | return ms.ToArray(); | ||
284 | } | 273 | } |
285 | 274 | ||
286 | } | 275 | } |
diff --git a/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs b/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs index d442443..3aab30b 100644 --- a/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs | |||
@@ -229,7 +229,7 @@ namespace OpenSim.Server.Handlers.Friends | |||
229 | 229 | ||
230 | rootElement.AppendChild(result); | 230 | rootElement.AppendChild(result); |
231 | 231 | ||
232 | return DocToBytes(doc); | 232 | return Util.DocToBytes(doc); |
233 | } | 233 | } |
234 | 234 | ||
235 | private byte[] FailureResult() | 235 | private byte[] FailureResult() |
@@ -261,18 +261,7 @@ namespace OpenSim.Server.Handlers.Friends | |||
261 | 261 | ||
262 | rootElement.AppendChild(message); | 262 | rootElement.AppendChild(message); |
263 | 263 | ||
264 | return DocToBytes(doc); | 264 | return Util.DocToBytes(doc); |
265 | } | ||
266 | |||
267 | private byte[] DocToBytes(XmlDocument doc) | ||
268 | { | ||
269 | MemoryStream ms = new MemoryStream(); | ||
270 | XmlTextWriter xw = new XmlTextWriter(ms, null); | ||
271 | xw.Formatting = Formatting.Indented; | ||
272 | doc.WriteTo(xw); | ||
273 | xw.Flush(); | ||
274 | |||
275 | return ms.ToArray(); | ||
276 | } | 265 | } |
277 | 266 | ||
278 | void FromKeyValuePairs(Dictionary<string, object> kvp, out string principalID, out string friend, out int flags) | 267 | void FromKeyValuePairs(Dictionary<string, object> kvp, out string principalID, out string friend, out int flags) |
diff --git a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs index dda4756..d5a9d67 100644 --- a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs | |||
@@ -602,7 +602,7 @@ namespace OpenSim.Server.Handlers.Grid | |||
602 | 602 | ||
603 | rootElement.AppendChild(result); | 603 | rootElement.AppendChild(result); |
604 | 604 | ||
605 | return DocToBytes(doc); | 605 | return Util.DocToBytes(doc); |
606 | } | 606 | } |
607 | 607 | ||
608 | private byte[] FailureResult() | 608 | private byte[] FailureResult() |
@@ -634,18 +634,7 @@ namespace OpenSim.Server.Handlers.Grid | |||
634 | 634 | ||
635 | rootElement.AppendChild(message); | 635 | rootElement.AppendChild(message); |
636 | 636 | ||
637 | return DocToBytes(doc); | 637 | return Util.DocToBytes(doc); |
638 | } | ||
639 | |||
640 | private byte[] DocToBytes(XmlDocument doc) | ||
641 | { | ||
642 | MemoryStream ms = new MemoryStream(); | ||
643 | XmlTextWriter xw = new XmlTextWriter(ms, null); | ||
644 | xw.Formatting = Formatting.Indented; | ||
645 | doc.WriteTo(xw); | ||
646 | xw.Flush(); | ||
647 | |||
648 | return ms.ToArray(); | ||
649 | } | 638 | } |
650 | 639 | ||
651 | #endregion | 640 | #endregion |
diff --git a/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs b/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs index 006f6ab..9237c63 100644 --- a/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs +++ b/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs | |||
@@ -279,7 +279,7 @@ namespace OpenSim.Server.Handlers.GridUser | |||
279 | 279 | ||
280 | rootElement.AppendChild(result); | 280 | rootElement.AppendChild(result); |
281 | 281 | ||
282 | return DocToBytes(doc); | 282 | return Util.DocToBytes(doc); |
283 | } | 283 | } |
284 | 284 | ||
285 | private byte[] FailureResult() | 285 | private byte[] FailureResult() |
@@ -301,20 +301,8 @@ namespace OpenSim.Server.Handlers.GridUser | |||
301 | 301 | ||
302 | rootElement.AppendChild(result); | 302 | rootElement.AppendChild(result); |
303 | 303 | ||
304 | return DocToBytes(doc); | 304 | return Util.DocToBytes(doc); |
305 | } | 305 | } |
306 | 306 | ||
307 | private byte[] DocToBytes(XmlDocument doc) | ||
308 | { | ||
309 | MemoryStream ms = new MemoryStream(); | ||
310 | XmlTextWriter xw = new XmlTextWriter(ms, null); | ||
311 | xw.Formatting = Formatting.Indented; | ||
312 | doc.WriteTo(xw); | ||
313 | xw.Flush(); | ||
314 | |||
315 | return ms.ToArray(); | ||
316 | } | ||
317 | |||
318 | |||
319 | } | 307 | } |
320 | } | 308 | } |
diff --git a/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs b/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs index a2bdadb..37b47ed 100644 --- a/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs | |||
@@ -335,7 +335,7 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
335 | 335 | ||
336 | rootElement.AppendChild(result); | 336 | rootElement.AppendChild(result); |
337 | 337 | ||
338 | return DocToBytes(doc); | 338 | return Util.DocToBytes(doc); |
339 | } | 339 | } |
340 | 340 | ||
341 | private byte[] SuccessResult(string value) | 341 | private byte[] SuccessResult(string value) |
@@ -362,7 +362,7 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
362 | 362 | ||
363 | rootElement.AppendChild(message); | 363 | rootElement.AppendChild(message); |
364 | 364 | ||
365 | return DocToBytes(doc); | 365 | return Util.DocToBytes(doc); |
366 | } | 366 | } |
367 | 367 | ||
368 | 368 | ||
@@ -395,7 +395,7 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
395 | 395 | ||
396 | rootElement.AppendChild(message); | 396 | rootElement.AppendChild(message); |
397 | 397 | ||
398 | return DocToBytes(doc); | 398 | return Util.DocToBytes(doc); |
399 | } | 399 | } |
400 | 400 | ||
401 | private byte[] BoolResult(bool value) | 401 | private byte[] BoolResult(bool value) |
@@ -417,21 +417,9 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
417 | 417 | ||
418 | rootElement.AppendChild(result); | 418 | rootElement.AppendChild(result); |
419 | 419 | ||
420 | return DocToBytes(doc); | 420 | return Util.DocToBytes(doc); |
421 | } | 421 | } |
422 | 422 | ||
423 | private byte[] DocToBytes(XmlDocument doc) | ||
424 | { | ||
425 | MemoryStream ms = new MemoryStream(); | ||
426 | XmlTextWriter xw = new XmlTextWriter(ms, null); | ||
427 | xw.Formatting = Formatting.Indented; | ||
428 | doc.WriteTo(xw); | ||
429 | xw.Flush(); | ||
430 | |||
431 | return ms.ToArray(); | ||
432 | } | ||
433 | |||
434 | |||
435 | #endregion | 423 | #endregion |
436 | } | 424 | } |
437 | } | 425 | } |
diff --git a/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs b/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs index 7283237..0288fa6 100644 --- a/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs +++ b/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs | |||
@@ -191,18 +191,7 @@ namespace OpenSim.Server.Handlers.Asset | |||
191 | 191 | ||
192 | rootElement.AppendChild(result); | 192 | rootElement.AppendChild(result); |
193 | 193 | ||
194 | return DocToBytes(doc); | 194 | return Util.DocToBytes(doc); |
195 | } | ||
196 | |||
197 | private byte[] DocToBytes(XmlDocument doc) | ||
198 | { | ||
199 | MemoryStream ms = new MemoryStream(); | ||
200 | XmlTextWriter xw = new XmlTextWriter(ms, null); | ||
201 | xw.Formatting = Formatting.Indented; | ||
202 | doc.WriteTo(xw); | ||
203 | xw.Flush(); | ||
204 | |||
205 | return ms.ToArray(); | ||
206 | } | 195 | } |
207 | 196 | ||
208 | byte[] HandleCreateUserInventory(Dictionary<string,object> request) | 197 | byte[] HandleCreateUserInventory(Dictionary<string,object> request) |
diff --git a/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs b/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs index a896fdb..649a27e 100644 --- a/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs +++ b/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs | |||
@@ -188,7 +188,7 @@ namespace OpenSim.Server.Handlers.MapImage | |||
188 | 188 | ||
189 | rootElement.AppendChild(result); | 189 | rootElement.AppendChild(result); |
190 | 190 | ||
191 | return DocToBytes(doc); | 191 | return Util.DocToBytes(doc); |
192 | } | 192 | } |
193 | 193 | ||
194 | private byte[] FailureResult(string msg) | 194 | private byte[] FailureResult(string msg) |
@@ -215,18 +215,7 @@ namespace OpenSim.Server.Handlers.MapImage | |||
215 | 215 | ||
216 | rootElement.AppendChild(message); | 216 | rootElement.AppendChild(message); |
217 | 217 | ||
218 | return DocToBytes(doc); | 218 | return Util.DocToBytes(doc); |
219 | } | ||
220 | |||
221 | private byte[] DocToBytes(XmlDocument doc) | ||
222 | { | ||
223 | MemoryStream ms = new MemoryStream(); | ||
224 | XmlTextWriter xw = new XmlTextWriter(ms, null); | ||
225 | xw.Formatting = Formatting.Indented; | ||
226 | doc.WriteTo(xw); | ||
227 | xw.Flush(); | ||
228 | |||
229 | return ms.ToArray(); | ||
230 | } | 219 | } |
231 | 220 | ||
232 | private System.Net.IPAddress GetCallerIP(IOSHttpRequest request) | 221 | private System.Net.IPAddress GetCallerIP(IOSHttpRequest request) |
diff --git a/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs b/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs index 0b3b961..49dbcb5 100644 --- a/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs | |||
@@ -265,7 +265,7 @@ namespace OpenSim.Server.Handlers.Presence | |||
265 | 265 | ||
266 | rootElement.AppendChild(result); | 266 | rootElement.AppendChild(result); |
267 | 267 | ||
268 | return DocToBytes(doc); | 268 | return Util.DocToBytes(doc); |
269 | } | 269 | } |
270 | 270 | ||
271 | private byte[] FailureResult() | 271 | private byte[] FailureResult() |
@@ -287,18 +287,7 @@ namespace OpenSim.Server.Handlers.Presence | |||
287 | 287 | ||
288 | rootElement.AppendChild(result); | 288 | rootElement.AppendChild(result); |
289 | 289 | ||
290 | return DocToBytes(doc); | 290 | return Util.DocToBytes(doc); |
291 | } | ||
292 | |||
293 | private byte[] DocToBytes(XmlDocument doc) | ||
294 | { | ||
295 | MemoryStream ms = new MemoryStream(); | ||
296 | XmlTextWriter xw = new XmlTextWriter(ms, null); | ||
297 | xw.Formatting = Formatting.Indented; | ||
298 | doc.WriteTo(xw); | ||
299 | xw.Flush(); | ||
300 | |||
301 | return ms.ToArray(); | ||
302 | } | 291 | } |
303 | 292 | ||
304 | } | 293 | } |
diff --git a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs index 6d3a3a7..da2bfeb 100644 --- a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs +++ b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs | |||
@@ -250,14 +250,30 @@ namespace OpenSim.Server.Handlers.Simulation | |||
250 | return encoding.GetBytes("false"); | 250 | return encoding.GetBytes("false"); |
251 | } | 251 | } |
252 | 252 | ||
253 | string requestBody; | ||
254 | |||
253 | Stream inputStream = request; | 255 | Stream inputStream = request; |
254 | if ((httpRequest.ContentType == "application/x-gzip" || httpRequest.Headers["Content-Encoding"] == "gzip") || (httpRequest.Headers["X-Content-Encoding"] == "gzip")) | 256 | Stream innerStream = null; |
255 | inputStream = new GZipStream(inputStream, CompressionMode.Decompress); | 257 | try |
258 | { | ||
259 | if ((httpRequest.ContentType == "application/x-gzip" || httpRequest.Headers["Content-Encoding"] == "gzip") || (httpRequest.Headers["X-Content-Encoding"] == "gzip")) | ||
260 | { | ||
261 | innerStream = inputStream; | ||
262 | inputStream = new GZipStream(innerStream, CompressionMode.Decompress); | ||
263 | } | ||
256 | 264 | ||
257 | StreamReader reader = new StreamReader(inputStream, encoding); | 265 | using (StreamReader reader = new StreamReader(inputStream, encoding)) |
266 | { | ||
267 | requestBody = reader.ReadToEnd(); | ||
268 | } | ||
269 | } | ||
270 | finally | ||
271 | { | ||
272 | if (innerStream != null) | ||
273 | innerStream.Dispose(); | ||
274 | inputStream.Dispose(); | ||
275 | } | ||
258 | 276 | ||
259 | string requestBody = reader.ReadToEnd(); | ||
260 | reader.Close(); | ||
261 | keysvals.Add("body", requestBody); | 277 | keysvals.Add("body", requestBody); |
262 | 278 | ||
263 | Hashtable responsedata = new Hashtable(); | 279 | Hashtable responsedata = new Hashtable(); |
@@ -461,15 +477,31 @@ namespace OpenSim.Server.Handlers.Simulation | |||
461 | keysvals.Add("headers", headervals); | 477 | keysvals.Add("headers", headervals); |
462 | keysvals.Add("querystringkeys", querystringkeys); | 478 | keysvals.Add("querystringkeys", querystringkeys); |
463 | 479 | ||
480 | String requestBody; | ||
481 | Encoding encoding = Encoding.UTF8; | ||
482 | |||
464 | Stream inputStream = request; | 483 | Stream inputStream = request; |
465 | if ((httpRequest.ContentType == "application/x-gzip" || httpRequest.Headers["Content-Encoding"] == "gzip") || (httpRequest.Headers["X-Content-Encoding"] == "gzip")) | 484 | Stream innerStream = null; |
466 | inputStream = new GZipStream(inputStream, CompressionMode.Decompress); | 485 | try |
486 | { | ||
487 | if ((httpRequest.ContentType == "application/x-gzip" || httpRequest.Headers["Content-Encoding"] == "gzip") || (httpRequest.Headers["X-Content-Encoding"] == "gzip")) | ||
488 | { | ||
489 | innerStream = inputStream; | ||
490 | inputStream = new GZipStream(innerStream, CompressionMode.Decompress); | ||
491 | } | ||
467 | 492 | ||
468 | Encoding encoding = Encoding.UTF8; | 493 | using (StreamReader reader = new StreamReader(inputStream, encoding)) |
469 | StreamReader reader = new StreamReader(inputStream, encoding); | 494 | { |
495 | requestBody = reader.ReadToEnd(); | ||
496 | } | ||
497 | } | ||
498 | finally | ||
499 | { | ||
500 | if (innerStream != null) | ||
501 | innerStream.Dispose(); | ||
502 | inputStream.Dispose(); | ||
503 | } | ||
470 | 504 | ||
471 | string requestBody = reader.ReadToEnd(); | ||
472 | reader.Close(); | ||
473 | keysvals.Add("body", requestBody); | 505 | keysvals.Add("body", requestBody); |
474 | 506 | ||
475 | httpResponse.StatusCode = 200; | 507 | httpResponse.StatusCode = 200; |
diff --git a/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs index c87e022..a77d78e 100644 --- a/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs +++ b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs | |||
@@ -315,7 +315,7 @@ namespace OpenSim.Server.Handlers.UserAccounts | |||
315 | 315 | ||
316 | rootElement.AppendChild(result); | 316 | rootElement.AppendChild(result); |
317 | 317 | ||
318 | return DocToBytes(doc); | 318 | return Util.DocToBytes(doc); |
319 | } | 319 | } |
320 | 320 | ||
321 | private byte[] FailureResult() | 321 | private byte[] FailureResult() |
@@ -337,18 +337,7 @@ namespace OpenSim.Server.Handlers.UserAccounts | |||
337 | 337 | ||
338 | rootElement.AppendChild(result); | 338 | rootElement.AppendChild(result); |
339 | 339 | ||
340 | return DocToBytes(doc); | 340 | return Util.DocToBytes(doc); |
341 | } | ||
342 | |||
343 | private byte[] DocToBytes(XmlDocument doc) | ||
344 | { | ||
345 | MemoryStream ms = new MemoryStream(); | ||
346 | XmlTextWriter xw = new XmlTextWriter(ms, null); | ||
347 | xw.Formatting = Formatting.Indented; | ||
348 | doc.WriteTo(xw); | ||
349 | xw.Flush(); | ||
350 | |||
351 | return ms.ToArray(); | ||
352 | } | 341 | } |
353 | 342 | ||
354 | private byte[] ResultToBytes(Dictionary<string, object> result) | 343 | private byte[] ResultToBytes(Dictionary<string, object> result) |