private void Cap_MeshUploadFlag(HttpRequest httpreq)
 {
     if (httpreq.Method != "GET")
     {
         httpreq.ErrorResponse(HttpStatusCode.MethodNotAllowed, "Method not allowed");
     }
     else
     {
         using (var res = httpreq.BeginResponse())
         {
             res.ContentType = "application/llsd+xml";
             var m = new Map
             {
                 { "username", Agent.FirstName + "." + Agent.LastName },
                 { "display_name_next_update", new Date() },
                 { "legacy_first_name", Agent.FirstName },
                 { "mesh_upload_status", "valid" },
                 { "display_name", Agent.DisplayName },
                 { "legacy_last_name", Agent.LastName },
                 { "id", Agent.ID },
                 { "is_display_name_default", false }
             };
             using (var o = res.GetOutputStream())
             {
                 LlsdXml.Serialize(m, o);
             }
         }
     }
 }
Example #2
0
        private void Cap_UntrustedSimulatorMessage(HttpRequest httpreq)
        {
            if (httpreq.Method != "POST")
            {
                httpreq.ErrorResponse(HttpStatusCode.MethodNotAllowed, "Method not allowed");
                return;
            }

            Map    req;
            string message;
            IValue body;

            try
            {
                req     = (Map)LlsdXml.Deserialize(httpreq.Body);
                message = req["message"].ToString();
                body    = req["body"];

                Func <IValue, Message> mdel;
                if (m_UntrustedSimulatorMessageDecoder.EQGDecoders.TryGetValue(message, out mdel))
                {
                    HandleUntrustedSimulatorMessage(mdel(body));
                }
            }
            catch (Exception e)
            {
                m_Log.WarnFormat("Invalid LLSD_XML: {0} {1}", e.Message, e.StackTrace);
                httpreq.ErrorResponse(HttpStatusCode.BadRequest, "Bad Request");
                return;
            }

            httpreq.LlsdXmlResponse(new Map());
        }
        private void GetExperiencesResponse(ViewerAgent agent, AgentCircuit circuit, HttpRequest req)
        {
            Dictionary <UEI, bool> result = circuit.Scene.ExperienceService.Permissions[agent.Owner];
            var resdata = new Map();
            var allowed = new AnArray();
            var blocked = new AnArray();

            resdata.Add("experiences", allowed);
            resdata.Add("blocked", blocked);

            foreach (KeyValuePair <UEI, bool> kvp in result)
            {
                if (kvp.Value)
                {
                    allowed.Add(kvp.Key.ID);
                }
                else
                {
                    blocked.Add(kvp.Key.ID);
                }
            }

            using (var res = req.BeginResponse("application/llsd+xml"))
            {
                using (Stream s = res.GetOutputStream())
                {
                    LlsdXml.Serialize(resdata, s);
                }
            }
        }
        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);
        }
Example #5
0
        public void HandleParcelVoiceInfoRequest(ViewerAgent agent, AgentCircuit circuit, HttpRequest req)
        {
            if (req.CallerIP != circuit.RemoteIP)
            {
                req.ErrorResponse(HttpStatusCode.Forbidden, "Forbidden");
                return;
            }
            if (req.Method != "POST")
            {
                req.ErrorResponse(HttpStatusCode.MethodNotAllowed, "Method not allowed");
                return;
            }

            SceneInterface scene = circuit.Scene;
            ParcelInfo     pInfo;
            IValue         res;

            if (!scene.Parcels.TryGetValue(agent.GlobalPosition, out pInfo))
            {
                res = new Undef();
            }
            else if (scene.EstateAllowsVoice &&
                     ((pInfo.Flags & ParcelFlags.AllowVoiceChat) != 0 || scene.HasGroupPower(agent.Owner, pInfo.Group, GroupPowers.AllowVoiceChat)))
            {
                VoiceChannelInfo channelInfo;

                try
                {
                    if ((pInfo.Flags & ParcelFlags.UseEstateVoiceChan) != 0)
                    {
                        channelInfo = m_VoiceService.GetEstateChannel(scene.EstateService[scene.EstateService.RegionMap[scene.ID]]);
                    }
                    else
                    {
                        channelInfo = m_VoiceService.GetParcelChannel(scene, pInfo);
                    }
                    res = new Map {
                        { "channel_uri", channelInfo.ChannelSipUri }
                    };
                }
                catch
                {
                    res = new Map {
                        { "channel_uri", string.Empty }
                    };
                }
            }
            else
            {
                res = new Map {
                    { "channel_uri", string.Empty }
                };
            }

            using (HttpResponse resp = req.BeginResponse("application/llsd+xml"))
                using (Stream s = resp.GetOutputStream())
                {
                    LlsdXml.Serialize(res, s);
                }
        }
Example #6
0
        public Material(AssetData asset)
        {
            var m = LlsdXml.Deserialize(asset.InputStream) as Map;

            if (m == null)
            {
                throw new NotAMaterialFormatException();
            }

            MaterialID = asset.ID;

            AlphaMaskCutoff  = m["AlphaMaskCutoff"].AsInt;
            DiffuseAlphaMode = m["DiffuseAlphaMode"].AsInt;
            EnvIntensity     = m["EnvIntensity"].AsInt;
            NormMap          = m["NormMap"].AsUUID;
            NormOffsetX      = m["NormOffsetX"].AsInt;
            NormOffsetY      = m["NormOffsetY"].AsInt;
            NormRepeatX      = m["NormRepeatX"].AsInt;
            NormRepeatY      = m["NormRepeatY"].AsInt;
            NormRotation     = m["NormRotation"].AsInt;
            var a = (AnArray)m["SpecColor"];

            SpecColor.R_AsByte = (byte)a[0].AsUInt;
            SpecColor.G_AsByte = (byte)a[1].AsUInt;
            SpecColor.B_AsByte = (byte)a[2].AsUInt;
            SpecColor.A_AsByte = (byte)a[3].AsUInt;
            SpecExp            = m["SpecExp"].AsInt;
            SpecMap            = m["SpecMap"].AsUUID;
            SpecOffsetX        = m["SpecOffsetX"].AsInt;
            SpecOffsetY        = m["SpecOffsetY"].AsInt;
            SpecRepeatX        = m["SpecRepeatX"].AsInt;
            SpecRepeatY        = m["SpecRepeatY"].AsInt;
            SpecRotation       = m["SpecRotation"].AsInt;
        }
Example #7
0
 public void LlsdXmlResponse(IValue iv)
 {
     if (Method == "HEAD")
     {
         int cLength;
         using (var ms = new MemoryStream())
         {
             LlsdXml.Serialize(iv, ms);
             cLength = ms.ToArray().Length;
         }
         using (HttpResponse res = BeginResponse("application/llsd+xml"))
         {
             res.Headers["Content-Length"] = cLength.ToString();
         }
     }
     else
     {
         using (HttpResponse res = BeginResponse("application/llsd+xml"))
         {
             using (Stream s = res.GetOutputStream())
             {
                 LlsdXml.Serialize(iv, s);
             }
         }
     }
 }
            public void HttpRequestHandler(HttpRequest httpreq)
            {
                if (httpreq.Method != "GET")
                {
                    httpreq.ErrorResponse(HttpStatusCode.MethodNotAllowed, "Method not allowed");
                    return;
                }
                RegionInfo info = m_Scene.GetRegionInfo();

                var resdata = new AnArray
                {
                    new Map
                    {
                        { "description", VersionInfo.ProductName },
                        { "name", info.ProductName },
                        { "sku", VersionInfo.SimulatorVersion }
                    }
                };

                using (HttpResponse res = httpreq.BeginResponse("application/llsd+xml"))
                    using (Stream s = res.GetOutputStream())
                    {
                        LlsdXml.Serialize(resdata, s);
                    }
            }
Example #9
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);
        }
        public void HttpRequestHandler(HttpRequest httpreq)
        {
            if (httpreq.CallerIP != m_RemoteIP)
            {
                httpreq.ErrorResponse(HttpStatusCode.Forbidden, "Forbidden");
                return;
            }
            if (httpreq.Method != "POST")
            {
                httpreq.ErrorResponse(HttpStatusCode.MethodNotAllowed, "Method not allowed");
                return;
            }

            Map reqmap;

            try
            {
                reqmap = LlsdXml.Deserialize(httpreq.Body) as Map;
            }
            catch
            {
                httpreq.ErrorResponse(HttpStatusCode.UnsupportedMediaType, "Unsupported Media Type");
                return;
            }
            if (reqmap == null)
            {
                httpreq.ErrorResponse(HttpStatusCode.BadRequest, "Misformatted LLSD-XML");
                return;
            }

            int    cof_version = reqmap["cof_version"].AsInt;
            bool   success     = true;
            string reason      = string.Empty;

            try
            {
                m_Agent.RebakeAppearance();
            }
            catch (Exception e)
            {
                success = false;
                reason  = e.Message;
            }

            Map resmap = new Map
            {
                { "success", success },
                { "error", reason },
                { "agent_id", m_Agent.ID }
            };

            using (var httpres = httpreq.BeginResponse())
            {
                httpres.ContentType = "application/llsd+xml";
                using (Stream outStream = httpres.GetOutputStream())
                {
                    LlsdXml.Serialize(resmap, outStream);
                }
            }
        }
        public override void Add(InventoryFolder folder)
        {
            var reqmap = new Map
            {
                { "folder_id", folder.ID },
                { "parent_id", folder.ParentFolderID },
                { "type", (int)folder.DefaultType },
                { "name", folder.Name }
            };

            using (Stream s = new HttpClient.Post(m_CreateInventoryCategoryCap, "application/llsd+xml", (Stream reqstream) =>
            {
                LlsdXml.Serialize(reqmap, reqstream);
            })
            {
                TimeoutMs = TimeoutMs
            }.ExecuteStreamRequest())
            {
                Map resmap = (Map)LlsdXml.Deserialize(s);
                if (resmap["folder_id"] != reqmap["folder_id"] ||
                    resmap["parent_id"] != reqmap["folder_id"] ||
                    resmap["type"] != reqmap["type"])
                {
                    throw new InvalidOperationException();
                }
            }
        }
        public void SendExperienceLog(IAgent agent, ObjectGroup grp, ExperienceLogType permissions, UUID experienceID)
        {
            var gm = new GenericMessage
            {
                Method    = "ExperienceEvent",
                Invoice   = experienceID,
                SessionID = UUID.Zero,
                AgentID   = agent.ID
            };
            var llsd = new Map
            {
                { "OwnerID", grp.Owner.ID },
                { "Permission", (int)permissions },
                { "IsAttachment", grp.IsAttached }
            };

            using (var ms = new MemoryStream())
            {
                LlsdXml.Serialize(llsd, ms);
                gm.ParamList.Add(ms.ToArray());
            }
            gm.ParamList.Add((grp.Name + "\0").ToUTF8Bytes());
            ParcelInfo pInfo;

            if (!grp.IsAttached && Parcels.TryGetValue(grp.GlobalPosition, out pInfo))
            {
                gm.ParamList.Add((pInfo.Name + "\0").ToUTF8Bytes());
            }
            agent.SendMessageAlways(gm, ID);
        }
        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));
        }
        private void Cap_SimConsoleAsyncCap(HttpRequest httpreq)
        {
            IValue iv;

            if (httpreq.CallerIP != RemoteIP)
            {
                httpreq.ErrorResponse(HttpStatusCode.Forbidden, "Forbidden");
                return;
            }
            if (httpreq.Method != "POST")
            {
                httpreq.ErrorResponse(HttpStatusCode.MethodNotAllowed, "Method not allowed");
                return;
            }

            try
            {
                iv = LlsdXml.Deserialize(httpreq.Body);
            }
            catch (Exception e)
            {
                m_Log.WarnFormat("Invalid LLSD_XML: {0} {1}", e.Message, e.StackTrace);
                httpreq.ErrorResponse(HttpStatusCode.BadRequest, "Bad Request");
                return;
            }

            if (!(iv is AString))
            {
                httpreq.ErrorResponse(HttpStatusCode.BadRequest, "Bad Request");
                return;
            }

            var message = iv.ToString();
            var tty     = new SimConsoleAsyncTTY(this);

            if (!Scene.IsSimConsoleAllowed(Agent.Owner))
            {
                tty.WriteFormatted(this.GetLanguageString(Agent.CurrentCulture, "SimConsoleNotAllowedForAgent", "SimConsole not allowed") + "\n", Agent.NamedOwner.FirstName, Agent.NamedOwner.LastName);
            }
            else
            {
                m_Commands.ExecuteCommandString(message, tty, Scene.ID);
                if (!tty.HaveOutputSent)
                {
                    tty.Write("");
                }
            }

            using (var res = httpreq.BeginResponse(HttpStatusCode.OK, "OK"))
            {
                res.ContentType = "application/llsd+xml";
                using (var o = res.GetOutputStream())
                {
                    LlsdXml.Serialize(new BinaryData(new byte[1] {
                        0
                    }), o);
                }
            }
        }
        void IInventoryItemServiceInterface.Update(InventoryItem item)
        {
            Map m;

            if (item.AssetType == AssetType.Link || item.AssetType == AssetType.LinkFolder)
            {
                m = new Map
                {
                    { "name", item.Name },
                    { "desc", item.Description },
                    { "linked_id", item.AssetID }
                };
            }
            else
            {
                m = new Map
                {
                    { "name", item.Name },
                    { "desc", item.Description },
                    { "flags", (int)item.Flags },
                    { "asset_id", item.AssetID },
                    {
                        "sale_info", new Map
                        {
                            { "sale_price", item.SaleInfo.Price },
                            { "sale_type", (int)item.SaleInfo.Type }
                        }
                    },
                    {
                        "permissions", new Map
                        {
                            { "owner_mask", (int)item.Permissions.Current },
                            { "everyone_mask", (int)item.Permissions.EveryOne },
                            { "next_owner_mask", (int)item.Permissions.NextOwner },
                            { "group_mask", (int)item.Permissions.Group }
                        }
                    }
                };
            }

            byte[] reqdata;
            using (var ms = new MemoryStream())
            {
                LlsdXml.Serialize(m, ms);
                reqdata = ms.ToArray();
            }

            if (new HttpClient.Patch(
                    $"{m_CapabilityUri}item/{item.ID}",
                    "application/llsd+xml",
                    reqdata.Length,
                    (Stream s) => s.Write(reqdata, 0, reqdata.Length))
            {
                TimeoutMs = TimeoutMs
            }.ExecuteStatusRequest() == HttpStatusCode.NotFound)
            {
                throw new InventoryItemNotFoundException(item.ID);
            }
        }
Example #16
0
        public void HttpRequestHandler(HttpRequest httpreq)
        {
            if (httpreq.CallerIP != m_RemoteIP)
            {
                httpreq.ErrorResponse(HttpStatusCode.Forbidden, "Forbidden");
                return;
            }
            if (httpreq.Method != "POST")
            {
                httpreq.ErrorResponse(HttpStatusCode.MethodNotAllowed, "Method not allowed");
                return;
            }

            Map reqmap;

            try
            {
                reqmap = LlsdXml.Deserialize(httpreq.Body) as Map;
            }
            catch
            {
                httpreq.ErrorResponse(HttpStatusCode.UnsupportedMediaType, "Unsupported Media Type");
                return;
            }
            if (reqmap == null)
            {
                httpreq.ErrorResponse(HttpStatusCode.BadRequest, "Misformatted LLSD-XML");
                return;
            }

            AnArray objectlist;
            var     resdata = new Map();

            if (reqmap.TryGetValue("object_ids", out objectlist))
            {
                foreach (IValue iv in objectlist)
                {
                    UUID       id = iv.AsUUID;
                    ObjectPart part;
                    if (m_Scene.Primitives.TryGetValue(id, out part))
                    {
                        resdata.Add(id.ToString(), new Map
                        {
                            { "linked_set_resource_cost", part.ObjectGroup.LinkCost },
                            { "linked_set_physics_cost", part.ObjectGroup.PhysicsCost },
                            { "resource_cost", part.LinkCost },
                            { "physics_cost", part.PhysicsCost }
                        });
                    }
                }
            }

            using (HttpResponse res = httpreq.BeginResponse("application/llsd+xml"))
                using (Stream s = res.GetOutputStream())
                {
                    LlsdXml.Serialize(resdata, s);
                }
        }
        public void HttpRequestHandler(HttpRequest httpreq)
        {
            if (httpreq.CallerIP != m_RemoteIP)
            {
                httpreq.ErrorResponse(HttpStatusCode.Forbidden, "Forbidden");
                return;
            }
            if (httpreq.Method != "POST")
            {
                httpreq.ErrorResponse(HttpStatusCode.MethodNotAllowed, "Method not allowed");
                return;
            }

            Map reqmap;

            try
            {
                reqmap = LlsdXml.Deserialize(httpreq.Body) as Map;
            }
            catch
            {
                httpreq.ErrorResponse(HttpStatusCode.UnsupportedMediaType, "Unsupported Media Type");
                return;
            }
            if (reqmap == null)
            {
                httpreq.ErrorResponse(HttpStatusCode.BadRequest, "Misformatted LLSD-XML");
                return;
            }

            string method;

            if (!reqmap.TryGetValue("method", out method))
            {
                httpreq.ErrorResponse(HttpStatusCode.BadRequest, "Unknown method");
                return;
            }

            Func <ViewerAgent, AgentCircuit, HttpRequest, Map, Map> del;

            if (!ChatSessionRequestMethodHandlers.TryGetValue(method, out del))
            {
                httpreq.ErrorResponse(HttpStatusCode.BadRequest, "Unknown method");
                return;
            }

            Map resdata = del(m_Agent, m_Circuit, httpreq, reqmap);

            using (HttpResponse httpres = httpreq.BeginResponse())
            {
                httpres.ContentType = "application/llsd+xml";
                using (Stream outStream = httpres.GetOutputStream())
                {
                    LlsdXml.Serialize(resdata, outStream);
                }
            }
        }
Example #18
0
        private void HandleObjectMediaRequest(HttpRequest httpreq, Map reqmap)
        {
            UUID       objectID = reqmap["object_id"].AsUUID;
            ObjectPart part;

            try
            {
                part = m_Scene.Primitives[objectID];
            }
            catch
            {
                using (HttpResponse resp = httpreq.BeginResponse(HttpStatusCode.OK, "OK"))
                {
                    resp.ContentType = "text/plain";
                }
                return;
            }

            var res = new Map
            {
                ["object_id"] = objectID
            };
            var mediaList = part.Media;

            if (mediaList == null)
            {
                using (var resp = httpreq.BeginResponse(HttpStatusCode.OK, "OK"))
                {
                    resp.ContentType = "text/plain";
                }
                return;
            }
            var mediaData = new AnArray();

            foreach (var entry in part.Media)
            {
                if (entry != null)
                {
                    mediaData.Add((Map)entry);
                }
                else
                {
                    mediaData.Add(new Undef());
                }
            }
            res.Add("object_media_data", mediaData);
            res.Add("object_media_version", part.MediaURL);
            using (var resp = httpreq.BeginResponse(HttpStatusCode.OK, "OK"))
            {
                resp.ContentType = "application/llsd+xml";
                using (var o = resp.GetOutputStream())
                {
                    LlsdXml.Serialize(res, o);
                }
            }
        }
Example #19
0
        private void HandleDetailsReport(HttpRequest httpreq, UUID parcelID)
        {
            var parcels = new AnArray();

            ParcelInfo pinfo;

            if (m_Scene.Parcels.TryGetValue(parcelID, out pinfo))
            {
                var parcelobjects = new AnArray();
                var parcel        = new Map
                {
                    { "id", pinfo.ID },
                    { "local_id", pinfo.LocalID },
                    { "name", pinfo.Name },
                    { "owner_id", pinfo.Owner.ID },
                    { "objects", parcelobjects }
                };
                parcels.Add(parcel);

                foreach (ObjectGroup grp in m_Scene.ObjectGroups)
                {
                    Vector3 loc    = grp.GlobalPosition;
                    int     urls   = 0;
                    int     memory = 0;
                    if (!grp.IsAttached && pinfo.LandBitmap.ContainsLocation(loc))
                    {
                        parcelobjects.Add(new Map
                        {
                            { "id", grp.ID },
                            { "name", grp.Name },
                            { "owner_id", grp.Owner.ID },
                            { "owner_name", m_Scene.AvatarNameService.ResolveName(grp.Owner).FullName },
                            { "location", new Map
                              {
                                  { "x", loc.X },
                                  { "y", loc.Y },
                                  { "z", loc.Z }
                              } },
                            { "resources", new Map
                              {
                                  { "urls", urls },
                                  { "memory", memory }
                              } }
                        });
                    }
                }
            }

            using (HttpResponse res = httpreq.BeginResponse("applicaton/llsd+xml"))
                using (Stream s = res.GetOutputStream())
                {
                    LlsdXml.Serialize(new Map {
                        { "parcels", parcels }
                    }, s);
                }
        }
        private void HandleRegionExperiencesGet(ViewerAgent agent, AgentCircuit circuit, HttpRequest httpreq)
        {
            var allowed = new List <UEI>();
            var blocked = new List <UEI>();

            SceneInterface scene = circuit.Scene;

            if (scene == null)
            {
                httpreq.ErrorResponse(HttpStatusCode.InternalServerError, "Internal server error");
                return;
            }
            EstateServiceInterface estateService = scene.EstateService;

            foreach (EstateExperienceInfo info in estateService.Experiences[scene.ParentEstateID])
            {
                if (info.IsAllowed)
                {
                    allowed.Add(info.ExperienceID);
                }
                else
                {
                    blocked.Add(info.ExperienceID);
                }
            }
            List <UEI> trusted = estateService.TrustedExperiences[scene.ParentEstateID];

            Map     resdata = new Map();
            AnArray array   = new AnArray();

            foreach (UEI id in allowed)
            {
                array.Add(id.ID);
            }
            resdata.Add("allowed", array);
            array = new AnArray();
            foreach (UEI id in blocked)
            {
                array.Add(id.ID);
            }
            resdata.Add("blocked", array);
            array = new AnArray();
            foreach (UEI id in trusted)
            {
                array.Add(id.ID);
            }
            resdata.Add("trusted", array);

            using (HttpResponse res = httpreq.BeginResponse("application/llsd+xml"))
            {
                using (Stream o = res.GetOutputStream())
                {
                    LlsdXml.Serialize(resdata, o);
                }
            }
        }
Example #21
0
        public void Cap_UpdateAgentLanguage(HttpRequest httpreq)
        {
            IValue o;

            if (httpreq.CallerIP != RemoteIP)
            {
                httpreq.ErrorResponse(HttpStatusCode.Forbidden, "Forbidden");
                return;
            }
            if (httpreq.Method != "POST")
            {
                httpreq.ErrorResponse(HttpStatusCode.MethodNotAllowed, "Method not allowed");
                return;
            }

            try
            {
                o = LlsdXml.Deserialize(httpreq.Body);
            }
            catch (Exception e)
            {
                m_Log.WarnFormat("Invalid LLSD_XML: {0} {1}", e.Message, e.StackTrace);
                httpreq.ErrorResponse(HttpStatusCode.UnsupportedMediaType, "Unsupported Media Type");
                return;
            }

            var reqmap = o as Map;

            if (reqmap == null)
            {
                httpreq.ErrorResponse(HttpStatusCode.BadRequest, "Misformatted LLSD-XML");
                return;
            }

            string agentLanguage = reqmap["language"].ToString();
            bool   isPublic      = reqmap["language_is_public"].AsBoolean;

            Agent.AgentLanguage = isPublic ? agentLanguage : string.Empty;
            foreach (ObjectPart p in Scene.Primitives)
            {
                if (p.HaveMultipleLocalizations)
                {
                    ScheduleObjUpdate(new ForceObjectUpdateInfo(p.UpdateInfo));
                }
            }

            using (var res = httpreq.BeginResponse("application/llsd+xml"))
            {
                using (var stream = res.GetOutputStream())
                {
                    LlsdXml.Serialize(new Map(), stream);
                }
            }
        }
        private void HandleExperiencePreferencesPut(ViewerAgent agent, AgentCircuit circuit, HttpRequest httpreq)
        {
            Map reqdata;

            using (Stream input = httpreq.Body)
            {
                reqdata = LlsdXml.Deserialize(input) as Map;
            }

            if (reqdata == null)
            {
                httpreq.ErrorResponse(HttpStatusCode.BadRequest, "Bad request");
                return;
            }

            SceneInterface scene = circuit.Scene;

            if (scene == null)
            {
                httpreq.ErrorResponse(HttpStatusCode.NotFound, "Not Found");
                return;
            }

            ExperienceServiceInterface experienceService = scene.ExperienceService;

            if (experienceService == null)
            {
                httpreq.ErrorResponse(HttpStatusCode.NotFound, "Not Found");
                return;
            }

            foreach (KeyValuePair <string, IValue> kvp in reqdata)
            {
                Map    entry = kvp.Value as Map;
                IValue iv;
                UUID   experienceid;
                UEI    uei;
                if (!UUID.TryParse(kvp.Key, out experienceid) || entry == null || !entry.TryGetValue("permission", out iv) || !experienceService.TryGetValue(experienceid, out uei))
                {
                    continue;
                }

                switch (iv.ToString())
                {
                case "Allow":
                    experienceService.Permissions[uei, agent.Owner] = true;
                    break;

                case "Block":
                    experienceService.Permissions[uei, agent.Owner] = false;
                    break;
                }
            }
        }
Example #23
0
        public void HttpRequestHandler(HttpRequest httpreq)
        {
            if (httpreq.CallerIP != m_RemoteIP)
            {
                httpreq.ErrorResponse(HttpStatusCode.Forbidden, "Forbidden");
                return;
            }
            if (httpreq.Method != "POST")
            {
                httpreq.ErrorResponse(HttpStatusCode.MethodNotAllowed, "Method not allowed");
                return;
            }

            Map reqmap;

            try
            {
                reqmap = LlsdXml.Deserialize(httpreq.Body) as Map;
            }
            catch
            {
                httpreq.ErrorResponse(HttpStatusCode.UnsupportedMediaType, "Unsupported Media Type");
                return;
            }
            if (reqmap == null)
            {
                httpreq.ErrorResponse(HttpStatusCode.BadRequest, "Misformatted LLSD-XML");
                return;
            }

            if (reqmap.ContainsKey("hover_height"))
            {
                /* store hover height */
                m_Agent.HoverHeight = reqmap["hover_height"].AsReal;
            }

            if (reqmap.ContainsKey("default_object_perm_masks"))
            {
                var defobjectperms = reqmap["default_object_perm_masks"] as Map;
                if (defobjectperms != null)
                {
                    /* Group, Everyone, NextOwner fields need to be stored */
                }
            }

            using (HttpResponse httpres = httpreq.BeginResponse())
            {
                httpres.ContentType = "application/llsd+xml";
                using (Stream outStream = httpres.GetOutputStream())
                {
                    LlsdXml.Serialize(new Map(), outStream);
                }
            }
        }
        public void HandleIsExperienceAdminCapability(ViewerAgent agent, AgentCircuit circuit, HttpRequest httpreq)
        {
            if (httpreq.CallerIP != circuit.RemoteIP)
            {
                httpreq.ErrorResponse(HttpStatusCode.Forbidden, "Forbidden");
                return;
            }
            if (httpreq.Method != "GET")
            {
                httpreq.ErrorResponse(HttpStatusCode.MethodNotAllowed, "Method not allowed");
                return;
            }

            Dictionary <string, object> reqdata = REST.ParseRESTFromRawUrl(httpreq.RawUrl);
            UUID experienceid = UUID.Parse((string)reqdata["experience_id"]);

            SceneInterface scene = circuit.Scene;

            if (scene == null)
            {
                httpreq.ErrorResponse(HttpStatusCode.NotFound, "Not Found");
                return;
            }

            ExperienceServiceInterface experienceService = scene.ExperienceService;

            if (experienceService == null)
            {
                httpreq.ErrorResponse(HttpStatusCode.NotFound, "Not Found");
                return;
            }

            ExperienceInfo info;
            bool           isadmin = false;

            if (experienceService.TryGetValue(experienceid, out info))
            {
                isadmin = info.Owner.EqualsGrid(agent.Owner) || experienceService.Admins[info.ID, agent.Owner];
            }

            Map resdata = new Map
            {
                { "status", isadmin }
            };

            using (HttpResponse res = httpreq.BeginResponse("application/llsd+xml"))
            {
                using (Stream o = res.GetOutputStream())
                {
                    LlsdXml.Serialize(resdata, o);
                }
            }
        }
        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);
        }
        void IInventoryFolderServiceInterface.Add(InventoryFolder folder)
        {
            var m          = new Map();
            var categories = new AnArray();

            m.Add("categories", categories);
            var category = new Map();

            categories.Add(category);
            category.Add("name", folder.Name);
            category.Add("type_default", (int)folder.DefaultType);

            byte[] reqdata;
            using (var ms = new MemoryStream())
            {
                LlsdXml.Serialize(m, ms);
                reqdata = ms.ToArray();
            }

            IValue         res;
            HttpStatusCode statuscode;

            using (Stream sres = new HttpClient.Post(
                       $"{m_CapabilityUri}category/{folder.ParentFolderID}",
                       "application/llsd+xml",
                       reqdata.Length,
                       (Stream s) => s.Write(reqdata, 0, reqdata.Length))
            {
                TimeoutMs = TimeoutMs
            }.ExecuteStreamRequest(out statuscode))
            {
                if (statuscode != HttpStatusCode.Created)
                {
                    throw new InventoryFolderNotFoundException(folder.ParentFolderID);
                }
                res = LlsdXml.Deserialize(sres);
            }
            var resmap = res as Map;

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

            var created_items = resmap["_created_categories"] as AnArray;

            if (created_items == null)
            {
                throw new InvalidDataException();
            }
            folder.ID = created_items[0].AsUUID;
        }
Example #27
0
        public HashtableApi.Hashtable CapsUpdateTaskInventory(ScriptInstance instance, string uri, LSLKey objectid, LSLKey itemid, string contentType, ByteArrayApi.ByteArray assetData)
        {
            HashtableApi.Hashtable res = new HashtableApi.Hashtable();
            lock (instance)
            {
                Map result;
                using (Stream s = new HttpClient.Post(uri,
                                                      new HttpClient.LlsdXmlRequest(new Map
                {
                    { "task_id", objectid.AsUUID },
                    { "item_id", itemid.AsUUID },
                }))
                {
                    TimeoutMs = 20000
                }.ExecuteStreamRequest())
                {
                    result = (Map)LlsdXml.Deserialize(s);
                }

                res["result"] = result["state"].ToString();
                if (result["state"].ToString() == "upload")
                {
                    string uploader_uri = res["uploader"].ToString();

                    using (Stream s = new HttpClient.Post(
                               uploader_uri,
                               contentType,
                               assetData.Length, (Stream sd) => sd.Write(assetData.Data, 0, assetData.Length))
                    {
                        TimeoutMs = 20000
                    }.ExecuteStreamRequest())
                    {
                        result = (Map)LlsdXml.Deserialize(s);
                    }
                    res["result"] = result["state"].ToString();
                    if (result["state"].ToString() == "complete")
                    {
                        res["assetid"] = new LSLKey(result["new_asset"].AsUUID);
                    }
                    if (result.ContainsKey("compiled"))
                    {
                        res["compiled"] = ((bool)result["compiled"].AsBoolean).ToLSLBoolean();
                    }
                    if (result.ContainsKey("errors"))
                    {
                        res.Add("errors", (AnArray)result["errors"]);
                    }
                }
            }

            return(res);
        }
        protected void ProcessReadOfflineMsgs(UUID ownerID, HttpRequest req, OfflineIMServiceInterface offlineIMService)
        {
            if (req.Method != "GET")
            {
                req.ErrorResponse(HttpStatusCode.MethodNotAllowed, "Method not allowed");
                return;
            }

            var resmap = new Map();
            var msgs   = new AnArray();

            resmap.Add("messages", msgs);
            if (offlineIMService != null)
            {
                try
                {
                    foreach (GridInstantMessage gim in offlineIMService.GetOfflineIMs(ownerID))
                    {
                        msgs.Add(new Map
                        {
                            { "binary_bucket", new BinaryData(gim.BinaryBucket) },
                            { "parent_estate_id", gim.ParentEstateID },
                            { "from_agent_id", gim.FromAgent.ID },
                            { "from_group", gim.IsFromGroup },
                            { "dialog", (int)gim.Dialog },
                            { "session_id", gim.IMSessionID },
                            { "timestamp", gim.Timestamp.AsInt },
                            { "from_agent_name", gim.FromAgent.FullName },
                            { "message", gim.Message },
                            { "region_id", gim.RegionID },
                            { "local_x", gim.Position.X },
                            { "local_y", gim.Position.Y },
                            { "local_z", gim.Position.Z },
                            { "asset_id", gim.FromGroup.ID } /* probably this gets changed in feature */
                        });
                    }
                }
                catch
                {
                    /* do not pass exceptions to caller */
                }
            }
            using (HttpResponse res = req.BeginResponse("application/llsd+xml"))
            {
                using (Stream s = res.GetOutputStream())
                {
                    LlsdXml.Serialize(resmap, s);
                }
            }
        }
Example #29
0
        public void HttpRequestHandler(HttpRequest httpreq)
        {
            if (httpreq.CallerIP != m_RemoteIP)
            {
                httpreq.ErrorResponse(HttpStatusCode.Forbidden, "Forbidden");
                return;
            }
            if (httpreq.Method != "POST")
            {
                httpreq.ErrorResponse(HttpStatusCode.MethodNotAllowed, "Method not allowed");
                return;
            }

            Map reqmap;

            try
            {
                reqmap = LlsdXml.Deserialize(httpreq.Body) as Map;
            }
            catch
            {
                httpreq.ErrorResponse(HttpStatusCode.UnsupportedMediaType, "Unsupported Media Type");
                return;
            }
            if (reqmap == null)
            {
                httpreq.ErrorResponse(HttpStatusCode.BadRequest, "Misformatted LLSD-XML");
                return;
            }

            if (!reqmap.ContainsKey("verb"))
            {
                httpreq.ErrorResponse(HttpStatusCode.BadRequest, "Invalid request");
                return;
            }
            switch (reqmap["verb"].ToString())
            {
            case "GET":
                HandleObjectMediaRequest(httpreq, reqmap);
                break;

            case "UPDATE":
                HandleObjectMediaUpdate(httpreq, reqmap);
                break;

            default:
                httpreq.ErrorResponse(HttpStatusCode.BadRequest, "Invalid request");
                break;
            }
        }
        public void HandleGroupExperiencesCapability(ViewerAgent agent, AgentCircuit circuit, HttpRequest httpreq)
        {
            if (httpreq.CallerIP != circuit.RemoteIP)
            {
                httpreq.ErrorResponse(HttpStatusCode.Forbidden, "Forbidden");
                return;
            }
            if (httpreq.Method != "GET")
            {
                httpreq.ErrorResponse(HttpStatusCode.MethodNotAllowed, "Method not allowed");
                return;
            }

            SceneInterface scene = circuit.Scene;

            if (scene == null)
            {
                httpreq.ErrorResponse(HttpStatusCode.NotFound, "Not Found");
                return;
            }

            ExperienceServiceInterface experienceService = scene.ExperienceService;

            if (experienceService == null)
            {
                httpreq.ErrorResponse(HttpStatusCode.NotFound, "Not Found");
                return;
            }

            List <UEI> experienceids = experienceService.GetGroupExperiences(agent.Group);
            var        ids           = new AnArray();

            foreach (UEI id in experienceids)
            {
                ids.Add(id.ID);
            }
            var resdata = new Map
            {
                ["experience_ids"] = ids
            };

            using (HttpResponse res = httpreq.BeginResponse("application/llsd+xml"))
            {
                using (Stream o = res.GetOutputStream())
                {
                    LlsdXml.Serialize(resdata, o);
                }
            }
        }