Example #1
0
        bool IInventoryFolderContentServiceInterface.TryGetValue(UUID principalID, UUID folderID, out InventoryFolderContent inventoryFolderContent)
        {
            IValue         iv;
            HttpStatusCode statuscode;

            using (Stream s = new HttpClient.Get($"{m_CapabilityUri}category/{folderID}?depth=1")
            {
                TimeoutMs = TimeoutMs
            }.ExecuteStreamRequest(out statuscode))
            {
                if (statuscode != HttpStatusCode.OK)
                {
                    inventoryFolderContent = default(InventoryFolderContent);
                    return(false);
                }
                iv = LlsdXml.Deserialize(s);
            }

            var resmap = iv as Map;

            if (resmap == null)
            {
                throw new InvalidDataException();
            }

            inventoryFolderContent          = new InventoryFolderContent();
            inventoryFolderContent.FolderID = resmap["category_id"].AsUUID;
            inventoryFolderContent.Owner    = new UGUI(resmap["agent_id"].AsUUID);
            inventoryFolderContent.Folders  = ExtractFolders(resmap);
            inventoryFolderContent.Items    = ExtractItems(resmap);

            return(true);
        }
        private bool TryGetValue(string url, out InventoryFolder folder)
        {
            folder = default(InventoryFolder);
            IValue         iv;
            HttpStatusCode statuscode;

            using (Stream s = new HttpClient.Get(url + "?depth=0")
            {
                TimeoutMs = TimeoutMs
            }.ExecuteStreamRequest(out statuscode))
            {
                if (statuscode != HttpStatusCode.OK)
                {
                    return(false);
                }
                iv = LlsdXml.Deserialize(s);
            }
            var m = iv as Map;

            if (m == null)
            {
                throw new InvalidDataException();
            }
            folder                = new InventoryFolder(m["category_id"].AsUUID);
            folder.Name           = m["name"].ToString();
            folder.DefaultType    = (AssetType)m["type_default"].AsInt;
            folder.ParentFolderID = m["parent_id"].AsUUID;
            folder.Version        = m["version"].AsInt;
            folder.Owner.ID       = m["agent_id"].AsUUID;
            return(true);
        }
        List <InventoryItem> IInventoryFolderServiceInterface.GetItems(UUID principalID, UUID key)
        {
            IValue         iv;
            HttpStatusCode statuscode;

            using (Stream s = new HttpClient.Get($"{m_CapabilityUri}category/{key}/items")
            {
                TimeoutMs = TimeoutMs
            }.ExecuteStreamRequest(out statuscode))
            {
                if (statuscode != HttpStatusCode.OK)
                {
                    throw new InventoryFolderNotFoundException(key);
                }
                iv = LlsdXml.Deserialize(s);
            }

            var resmap = iv as Map;

            if (resmap == null)
            {
                throw new InvalidDataException();
            }
            return(ExtractItems(resmap));
        }
        public bool Run()
        {
            m_HttpServer.UriHandlers.Add("/test", HttpHandler);
            int NumberConnections = 1000;
            int numConns          = m_HttpServer.AcceptedConnectionsCount;

            m_Log.InfoFormat("Testing 1000 HTTP GET requests (no connection reuse)");
            for (int connidx = 0; connidx++ < NumberConnections;)
            {
                string res;
                var    headers = new Dictionary <string, string>();
                try
                {
                    res = new HttpClient.Get(m_HttpServer.ServerURI + "test")
                    {
                        TimeoutMs      = 60000,
                        ConnectionMode = HttpClient.ConnectionModeEnum.SingleRequest,
                        Headers        = headers
                    }.ExecuteRequest();
                }
                catch (Exception e)
                {
                    m_Log.ErrorFormat("Failed at connection {0}: {1}: {2}: {3}", connidx, e.GetType().FullName, e.Message, e.StackTrace);
                    return(false);
                }
                int resval;
                if (!int.TryParse(res, out resval) || connidx != resval)
                {
                    m_Log.InfoFormat("Wrong text response at connection {0}: {1}", connidx, res);
                    return(false);
                }
                string connval = GetConnectionValue(headers).Trim().ToLower();
                if (connval != "close")
                {
                    m_Log.ErrorFormat("Connection: field has wrong response: \"{0}\"", connval);
                    return(false);
                }
                string chunkval = GetTransferEncodingValue(headers).Trim().ToLower();
                if (chunkval != string.Empty)
                {
                    m_Log.ErrorFormat("Transfer-Encoding: field has wrong response: \"{0}\"", chunkval);
                    return(false);
                }
                string encodingval = GetContentEncodingValue(headers).Trim().ToLower();
                if (encodingval != "gzip")
                {
                    m_Log.ErrorFormat("Content-Encoding: field has wrong response: \"{0}\"", encodingval);
                    return(false);
                }
            }

            numConns = m_HttpServer.AcceptedConnectionsCount - numConns;
            if (numConns != NumberConnections)
            {
                m_Log.InfoFormat("HTTP client did not have the specified number of reconnections");
                return(false);
            }
            return(true);
        }
        bool IInventoryItemServiceInterface.TryGetValue(UUID key, out InventoryItem item)
        {
            item = default(InventoryItem);
            IValue         iv;
            HttpStatusCode statuscode;

            using (Stream s = new HttpClient.Get($"{m_CapabilityUri}item/{key}")
            {
                TimeoutMs = TimeoutMs
            }.ExecuteStreamRequest(out statuscode))
            {
                if (statuscode != HttpStatusCode.OK)
                {
                    return(false);
                }
                iv = LlsdXml.Deserialize(s);
            }
            var resmap = iv as Map;

            if (resmap == null)
            {
                throw new InvalidDataException("Wrong response received");
            }

            item = new InventoryItem(resmap["item_id"].AsUUID)
            {
                InventoryType = (InventoryType)resmap["inv_type"].AsInt,
                Description   = resmap["desc"].ToString(),
                Flags         = (InventoryFlags)resmap["flags"].AsUInt,
                CreationDate  = Date.UnixTimeToDateTime(resmap["created_at"].AsULong),
                AssetID       = resmap["asset_id"].AsUUID,
                AssetType     = (AssetType)resmap["type"].AsInt,
                Name          = resmap["name"].ToString()
            };
            var saleinfo = resmap["sale_info"] as Map;

            item.SaleInfo.Price = saleinfo["sale_price"].AsInt;
            item.SaleInfo.Type  = (InventoryItem.SaleInfoData.SaleType)saleinfo["sale_type"].AsInt;
            var perminfo = resmap["permissions"] as Map;

            item.Permissions.Base      = (InventoryPermissionsMask)perminfo["base_mask"].AsUInt;
            item.Permissions.Group     = (InventoryPermissionsMask)perminfo["group_mask"].AsUInt;
            item.LastOwner.ID          = perminfo["last_owner_id"].AsUUID;
            item.Owner.ID              = perminfo["owner_id"].AsUUID;
            item.Creator.ID            = perminfo["creator_id"].AsUUID;
            item.ParentFolderID        = resmap["parent_id"].AsUUID;
            item.Permissions.NextOwner = (InventoryPermissionsMask)perminfo["next_owner_mask"].AsUInt;
            item.Permissions.Current   = (InventoryPermissionsMask)perminfo["owner_mask"].AsUInt;
            item.Group.ID              = perminfo["group_id"].AsUUID;
            item.Permissions.EveryOne  = (InventoryPermissionsMask)perminfo["everyone_mask"].AsUInt;

            return(true);
        }
Example #6
0
        public bool Run()
        {
            m_HttpServer.UriHandlers.Add("/test", HttpHandler);
            int NumberConnections = 1000;
            int numConns          = m_HttpServer.AcceptedConnectionsCount;

            m_Log.InfoFormat("Testing 1000 HTTP/2 GET requests (keep-alive) - Upgrading via h2c");
            for (int connidx = 0; connidx++ < NumberConnections;)
            {
                string res;
                var    headers = new Dictionary <string, string>();
                try
                {
                    res = new HttpClient.Get(m_HttpServer.ServerURI + "test")
                    {
                        TimeoutMs      = 60000,
                        ConnectionMode = HttpClient.ConnectionModeEnum.UpgradeHttp2,
                        Headers        = headers
                    }.ExecuteRequest();
                }
                catch (Exception e)
                {
                    m_Log.ErrorFormat("Failed at connection {0}: {1}: {2}: {3}", connidx, e.GetType().FullName, e.Message, e.StackTrace);
                    return(false);
                }
                int resval;
                if (!int.TryParse(res, out resval) || connidx != resval)
                {
                    m_Log.InfoFormat("Wrong text response at connection {0}: {1} (len={2})", connidx, res, res.Length);
                    return(false);
                }
                string chunkval = GetTransferEncodingValue(headers).Trim().ToLower();
                if (chunkval != string.Empty)
                {
                    m_Log.ErrorFormat("Transfer-Encoding: field has wrong response: \"{0}\"", chunkval);
                    return(false);
                }
            }
            numConns = m_HttpServer.AcceptedConnectionsCount - numConns;
            if (numConns > 1)
            {
                m_Log.InfoFormat("HTTP client did not re-use connections (actual {0})", numConns);
                return(false);
            }
            return(true);
        }
Example #7
0
 public bool Run()
 {
     m_HttpServer.UriHandlers.Add("/test", HttpHandler);
     m_Log.InfoFormat("Testing HTTP GET error responses");
     for (m_SendStatusCode = HttpStatusCode.MultipleChoices; m_SendStatusCode < HttpStatusCode.HttpVersionNotSupported; ++m_SendStatusCode)
     {
         var headers = new Dictionary <string, string>();
         try
         {
             HttpStatusCode statuscode = new HttpClient.Get(m_HttpServer.ServerURI + "test")
             {
                 TimeoutMs         = 60000,
                 ConnectionMode    = HttpClient.ConnectionModeEnum.UpgradeHttp2,
                 Headers           = headers,
                 DisableExceptions = HttpClient.Request.DisableExceptionFlags.DisableConflict
             }.ExecuteStatusRequest();
             if (statuscode != m_SendStatusCode)
             {
                 m_Log.ErrorFormat("Got wrong status at connection {0}: {1}", m_SendStatusCode, statuscode);
                 return(false);
             }
         }
         catch (System.Web.HttpException e)
         {
             if (e.GetHttpCode() == (int)HttpStatusCode.NotFound || e.GetHttpCode() == (int)HttpStatusCode.Conflict)
             {
                 m_Log.ErrorFormat("Got exception at connection {0}: {1}: {2}: {3}", m_SendStatusCode, e.GetType().FullName, e.Message, e.StackTrace);
                 return(false);
             }
             else if (e.GetHttpCode() != (int)m_SendStatusCode)
             {
                 m_Log.ErrorFormat("Got wrong status at connection {0}: {1}: {2}: {3}", m_SendStatusCode, e.GetType().FullName, e.Message, e.StackTrace);
                 return(false);
             }
         }
         catch (Exception e)
         {
             m_Log.ErrorFormat("Failed at connection {0}: {1}: {2}: {3}", m_SendStatusCode, e.GetType().FullName, e.Message, e.StackTrace);
             return(false);
         }
     }
     return(true);
 }
Example #8
0
        public bool Run()
        {
            bool success    = true;
            int  count      = 0;
            int  successcnt = 0;

            foreach (KeyValuePair <UUID, string> file in Assets)
            {
                ++count;
                var tr = new TestRunner.TestResult
                {
                    Name    = "Asset " + file.Key + "(" + file.Value + ")",
                    Result  = false,
                    Message = string.Empty
                };
                int startTime = Environment.TickCount;
                m_Log.InfoFormat("Testing deserialization of {1} ({0})", file.Key, file.Value);

                try
                {
                    using (Stream s = new HttpClient.Get(file.Value).ExecuteStreamRequest())
                    {
                        ObjectXML.FromXml(s, UGUI.Unknown, XmlDeserializationOptions.ReadKeyframeMotion);
                    }
                    m_Log.InfoFormat("Deserialization of {1} ({0}) successful", file.Key, file.Value);
                    ++successcnt;
                    tr.Result = true;
                }
                catch (Exception e)
                {
                    m_Log.ErrorFormat("Compilation of {1} ({0}) failed: {2}", file.Key, file.Value, e.Message);
                    m_Log.WarnFormat("Stack Trace:\n{0}", e.StackTrace);
                    tr.Message = e.Message + "\n" + e.StackTrace;
                    success    = false;
                }
                tr.RunTime = Environment.TickCount - startTime;
                m_Runner.TestResults.Add(tr);
            }
            m_Log.InfoFormat("{0} of {1} compilations successful", successcnt, count);
            return(success);
        }
        private void RequestTextureHandler(object o)
        {
            UrlDownloadInfoRequest reqInfo = (UrlDownloadInfoRequest)o;

            try
            {
                try
                {
                    byte[] data = new HttpClient.Get($"{reqInfo.TextureUrl}?texture_id={reqInfo.TextureID}")
                    {
                        TimeoutMs = 20000
                    }.ExecuteBinaryRequest();

                    reqInfo.ViewerConn.PostEvent(new TextureReceivedEvent
                    {
                        Agent     = reqInfo.Agent,
                        TextureID = reqInfo.TextureID,
                        Success   = 1,
                        Data      = new ByteArrayApi.ByteArray(data)
                    });
                }
                catch (HttpException)
                {
                    reqInfo.ViewerConn.PostEvent(new TextureReceivedEvent
                    {
                        Agent     = reqInfo.Agent,
                        TextureID = reqInfo.TextureID,
                        Success   = 0,
                        Data      = new ByteArrayApi.ByteArray()
                    });
                }
            }
            catch
            {
                /* intentionally ignore */
            }
        }
Example #10
0
        public bool Run()
        {
            m_HttpServer.UriHandlers.Add("/test", HttpHandler);
            m_Log.InfoFormat("Testing HTTP GET error responses");
            for (m_SendStatusCode = HttpStatusCode.MultipleChoices; m_SendStatusCode < HttpStatusCode.HttpVersionNotSupported; ++m_SendStatusCode)
            {
                var headers = new Dictionary <string, string>();
                try
                {
                    HttpStatusCode statuscode = new HttpClient.Get(m_HttpServer.ServerURI + "test")
                    {
                        TimeoutMs         = 60000,
                        ConnectionMode    = m_SendStatusCode == HttpStatusCode.GatewayTimeout ? HttpClient.ConnectionModeEnum.Close : HttpClient.ConnectionModeEnum.Keepalive,
                        Headers           = headers,
                        DisableExceptions = HttpClient.Request.DisableExceptionFlags.Disable3XX |
                                            HttpClient.Request.DisableExceptionFlags.Disable5XX |
                                            HttpClient.Request.DisableExceptionFlags.DisableConflict |
                                            HttpClient.Request.DisableExceptionFlags.DisableForbidden |
                                            HttpClient.Request.DisableExceptionFlags.DisableGone |
                                            HttpClient.Request.DisableExceptionFlags.DisableUnauthorized
                    }.ExecuteStatusRequest();
                    if (statuscode != m_SendStatusCode)
                    {
                        m_Log.ErrorFormat("Got wrong status at connection {0}: {1}", m_SendStatusCode, statuscode);
                        return(false);
                    }
                }
                catch (System.Web.HttpException e)
                {
                    switch (e.GetHttpCode())
                    {
                    case (int)HttpStatusCode.Unauthorized:
                    case (int)HttpStatusCode.Forbidden:
                    case (int)HttpStatusCode.NotFound:
                    case (int)HttpStatusCode.Conflict:
                    case (int)HttpStatusCode.Gone:
                        m_Log.ErrorFormat("Got exception at connection {0}: {1}: {2}: {3}", m_SendStatusCode, e.GetType().FullName, e.Message, e.StackTrace);
                        return(false);

                    default:
                        if ((e.GetHttpCode() >= 300 && e.GetHttpCode() <= 399) ||
                            (e.GetHttpCode() >= 500 && e.GetHttpCode() <= 599))
                        {
                            m_Log.ErrorFormat("Got exception at connection {0}: {1}: {2}: {3}", m_SendStatusCode, e.GetType().FullName, e.Message, e.StackTrace);
                            return(false);
                        }
                        break;
                    }
                    if (e.GetHttpCode() != (int)m_SendStatusCode)
                    {
                        m_Log.ErrorFormat("Got wrong status at connection {0}: {1}: {2}: {3}", m_SendStatusCode, e.GetType().FullName, e.Message, e.StackTrace);
                        return(false);
                    }
                }
                catch (Exception e)
                {
                    m_Log.ErrorFormat("Failed at connection {0}: {1}: {2}: {3}", m_SendStatusCode, e.GetType().FullName, e.Message, e.StackTrace);
                    return(false);
                }
            }
            return(true);
        }