123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
-
- using System;
- using System.IO;
- using System.IO.Compression;
- using System.Reflection;
- using OpenMetaverse;
- using OpenMetaverse.StructuredData;
- using OpenSim.Framework.Servers.HttpServer;
- using log4net;
- namespace OpenSim.Server.Handlers.Simulation
- {
- public class Utils
- {
- private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
-
-
-
-
-
-
- public static bool GetParams(string uri, out UUID uuid, out UUID regionID, out string action)
- {
- uuid = UUID.Zero;
- regionID = UUID.Zero;
- action = "";
- uri = uri.Trim(new char[] { '/' });
- string[] parts = uri.Split('/');
- if (parts.Length <= 1)
- {
- return false;
- }
- else
- {
- if (!UUID.TryParse(parts[1], out uuid))
- return false;
- if (parts.Length >= 3)
- UUID.TryParse(parts[2], out regionID);
- if (parts.Length >= 4)
- action = parts[3];
- return true;
- }
- }
- public static OSDMap GetOSDMap(string data)
- {
- OSDMap args = null;
- try
- {
- OSD buffer;
-
- buffer = OSDParser.DeserializeJson(data);
- if (buffer.Type == OSDType.Map)
- {
- args = (OSDMap)buffer;
- return args;
- }
- else
- {
-
- m_log.Debug(("[REST COMMS]: Got OSD of unexpected type " + buffer.Type.ToString()));
- return null;
- }
- }
- catch (Exception ex)
- {
- m_log.Debug("[REST COMMS]: exception on parse of REST message " + ex.Message);
- return null;
- }
- }
- public static OSDMap DeserializeOSMap(IOSHttpRequest httpRequest)
- {
- Stream inputStream = httpRequest.InputStream;
- Stream innerStream = null;
- try
- {
- if ((httpRequest.ContentType == "application/x-gzip" || httpRequest.Headers["Content-Encoding"] == "gzip") || (httpRequest.Headers["X-Content-Encoding"] == "gzip"))
- {
- innerStream = inputStream;
- inputStream = new GZipStream(innerStream, CompressionMode.Decompress);
- }
- return (OSDMap)OSDParser.DeserializeJson(inputStream);
- }
- catch
- {
- return null;
- }
- finally
- {
- if (innerStream != null)
- innerStream.Dispose();
- }
- }
- }
- }
|