Пример #1
0
        /// <summary>
        /// Handle raw uploaded asset data.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="path"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public string uploaderCaps(byte[] data, string path, string param)
        {
            UUID   inv = inventoryItemID;
            string res = String.Empty;
            LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete();
            UUID assetID = UUID.Zero;

            handlerUpdateItem = OnUpLoad;
            if (handlerUpdateItem != null)
            {
                assetID = handlerUpdateItem(inv, data);
            }

            uploadComplete.new_asset          = assetID.ToString();
            uploadComplete.new_inventory_item = inv;
            uploadComplete.state = "complete";

            res = LLSDHelpers.SerialiseLLSDReply(uploadComplete);

            httpListener.RemoveStreamHandler("POST", uploaderPath);

            if (m_dumpAssetToFile)
            {
                SaveAssetToFile("updateditem" + Util.RandomClass.Next(1, 1000) + ".dat", data);
            }

            return(res);
        }
        private string SetEnvironmentSettings(string request, UUID agentID)
        {
            LLSDEnvironmentSetResponse setResponse = new LLSDEnvironmentSetResponse();

            m_log.WarnFormat("[{0}]: Environment POST handler for agentID {1}", Name, agentID);
            setResponse.regionID = regionID;
            setResponse.success  = false;

            if (!m_scene.Permissions.CanIssueEstateCommand(agentID, false))
            {
                setResponse.fail_reason = "Insufficient estate permissions, settings has not been saved.";
                return(LLSDHelpers.SerializeLLSDReply(setResponse));
            }

            try
            {
                m_scene.StorageManager.DataStore.StoreRegionEnvironmentString(regionID, request);
                setResponse.success = true;
                environString       = request;
                m_log.InfoFormat("[{0}]: Environment settings updated by user {1}", Name, agentID);
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[{0}]: Environment settings not been saved for user {1}, Exception: {2} - {3}",
                                  Name, agentID, e.Message, e.StackTrace);

                setResponse.success     = false;
                setResponse.fail_reason = String.Format("Environment settings for '{0}' could not be saved.", m_scene.RegionInfo.RegionName);
            }

            return(LLSDHelpers.SerializeLLSDReply(setResponse));
        }
Пример #3
0
        /// <summary>
        /// Handle raw uploaded baked texture data.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="path"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public string uploaderCaps(byte[] data, string path, string param)
        {
            Action <UUID, byte[]> handlerUpLoad = OnUpLoad;

            // Don't do this asynchronously, otherwise it's possible for the client to send set appearance information
            // on another thread which might send out avatar updates before the asset has been put into the asset
            // service.
            if (handlerUpLoad != null)
            {
                handlerUpLoad(newAssetID, data);
            }

            string res = String.Empty;
            LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete();

            uploadComplete.new_asset          = newAssetID.ToString();
            uploadComplete.new_inventory_item = UUID.Zero;
            uploadComplete.state = "complete";

            res = LLSDHelpers.SerialiseLLSDReply(uploadComplete);

            httpListener.RemoveStreamHandler("POST", uploaderPath);

            // m_log.DebugFormat("[BAKED TEXTURE UPLOADER]: baked texture upload completed for {0}", newAssetID);

            return(res);
        }
Пример #4
0
        /// <summary>
        /// Handle raw asset upload data via the capability.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="path"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public string uploaderCaps(byte[] data, string path, string param)
        {
            UUID   inv = inventoryItemID;
            string res = String.Empty;
            LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete();

            uploadComplete.new_asset          = newAssetID.ToString();
            uploadComplete.new_inventory_item = inv;
            uploadComplete.state = "complete";

            res = LLSDHelpers.SerialiseLLSDReply(uploadComplete);

            httpListener.RemoveStreamHandler("POST", uploaderPath);

            // TODO: probably make this a better set of extensions here
            string extension = ".jp2";

            if (m_invType != "image")
            {
                extension = ".dat";
            }

            if (m_dumpAssetsToFile)
            {
                SaveAssetToFile(m_assetName + extension, data);
            }
            handlerUpLoad = OnUpLoad;
            if (handlerUpLoad != null)
            {
                handlerUpLoad(m_assetName, m_assetDes, newAssetID, inv, parentFolder, data, m_invType, m_assetType);
            }

            return(res);
        }
Пример #5
0
        public string FetchInventoryRequest(string request, string path, string param, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
//            m_log.DebugFormat("[FETCH INVENTORY HANDLER]: Received FetchInventory capabilty request");

            OSDMap   requestmap     = (OSDMap)OSDParser.DeserializeLLSDXml(Utils.StringToBytes(request));
            OSDArray itemsRequested = (OSDArray)requestmap["items"];

            string             reply;
            LLSDFetchInventory llsdReply = new LLSDFetchInventory();

            foreach (OSDMap osdItemId in itemsRequested)
            {
                UUID itemId = osdItemId["item_id"].AsUUID();

                InventoryItemBase item = m_inventoryService.GetItem(new InventoryItemBase(itemId, m_agentID));

                if (item != null)
                {
                    // We don't know the agent that this request belongs to so we'll use the agent id of the item
                    // which will be the same for all items.
                    llsdReply.agent_id = item.Owner;

                    llsdReply.items.Array.Add(ConvertInventoryItem(item));
                }
            }

            reply = LLSDHelpers.SerialiseLLSDReply(llsdReply);

            return(reply);
        }
Пример #6
0
        /// <summary>
        /// Construct a client response detailing all the capabilities this server can provide.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="path"></param>
        /// <param name="param"></param>
        /// <param name="httpRequest">HTTP request header object</param>
        /// <param name="httpResponse">HTTP response header object</param>
        /// <returns></returns>
        public string SeedCapRequest(string request, string path, string param,
                                     IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
//            m_log.Debug("[CAPS]: Seed Caps Request in region: " + m_regionName);

            if (!m_Scene.CheckClient(m_HostCapsObj.AgentID, httpRequest.RemoteIPEndPoint))
            {
                m_log.DebugFormat(
                    "[CAPS]: Unauthorized CAPS client {0} from {1}",
                    m_HostCapsObj.AgentID, httpRequest.RemoteIPEndPoint);

                return(string.Empty);
            }

            Hashtable caps = m_HostCapsObj.CapsHandlers.GetCapsDetails(true);

            // Add the external too
            foreach (KeyValuePair <string, string> kvp in m_HostCapsObj.ExternalCapsHandlers)
            {
                caps[kvp.Key] = kvp.Value;
            }

            string result = LLSDHelpers.SerialiseLLSDReply(caps);

            //m_log.DebugFormat("[CAPS] CapsRequest {0}", result);

            return(result);
        }
        /// <summary>
        /// Handle raw uploaded baked texture data.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="path"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public void process(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, byte[] data)
        {
            m_timeout.Stop();
            m_httpListener.RemoveSimpleStreamHandler(m_uploaderPath);
            m_timeout.Dispose();

            if (!httpRequest.RemoteIPEndPoint.Address.Equals(m_remoteAddress))
            {
                httpResponse.StatusCode = (int)HttpStatusCode.Unauthorized;
                return;
            }

            // need to check if data is a baked
            try
            {
                UUID      newAssetID = UUID.Random();
                AssetBase asset      = new AssetBase(newAssetID, "Baked Texture", (sbyte)AssetType.Texture, m_agentID.ToString());
                asset.Data      = data;
                asset.Temporary = true;
                asset.Local     = true;
                //asset.Flags = AssetFlags.AvatarBake;
                m_assetCache.Cache(asset);

                LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete();
                uploadComplete.new_asset          = newAssetID.ToString();
                uploadComplete.new_inventory_item = UUID.Zero;
                uploadComplete.state = "complete";

                httpResponse.RawBuffer  = Util.UTF8NBGetbytes(LLSDHelpers.SerialiseLLSDReply(uploadComplete));
                httpResponse.StatusCode = (int)HttpStatusCode.OK;
                return;
            }
            catch { }
            httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
        }
        private string SetEnvironmentSettings(string request, string path, string param,
                                              UUID agentID, Caps caps)
        {
            //            m_log.DebugFormat("[{0}]: Environment SET handle from agentID {1} in region {2}",
            //                Name, agentID, caps.RegionName);

            setResponse.regionID = regionID;
            setResponse.success  = false;

            if (!m_scene.Permissions.CanIssueEstateCommand(agentID, false))
            {
                setResponse.fail_reason = "Insufficient estate permissions, settings has not been saved.";
                return(LLSDHelpers.SerialiseLLSDReply(setResponse));
            }

            try
            {
                m_scene.SimulationDataService.StoreRegionEnvironmentSettings(regionID, request);
                setResponse.success = true;

                m_log.InfoFormat("[{0}]: New Environment settings has been saved from agentID {1} in region {2}",
                                 Name, agentID, caps.RegionName);
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[{0}]: Environment settings has not been saved for region {1}, Exception: {2} - {3}",
                                  Name, caps.RegionName, e.Message, e.StackTrace);

                setResponse.success     = false;
                setResponse.fail_reason = String.Format("Environment Set for region {0} has failed, settings has not been saved.", caps.RegionName);
            }

            return(LLSDHelpers.SerialiseLLSDReply(setResponse));
        }
Пример #9
0
        /// <summary>
        ///     Callback for a client request for Voice Account Details
        /// </summary>
        /// <param name="scene">current scene object of the client</param>
        /// <param name="request"></param>
        /// <param name="path"></param>
        /// <param name="param"></param>
        /// <param name="agentID"></param>
        /// <param name="caps"></param>
        /// <returns></returns>
        public string ProvisionVoiceAccountRequest(Scene scene, string request, string path, string param, UUID agentID, Caps caps)
        {
            ScenePresence avatar = scene.GetScenePresence(agentID);

            if (avatar == null)
            {
                System.Threading.Thread.Sleep(2000);
                avatar = scene.GetScenePresence(agentID);

                if (avatar == null)
                {
                    return("<llsd>undef</llsd>");
                }
            }

            string avatarName = avatar.Name;

            try
            {
                m_log.DebugFormat("[Free Switch Voice][Provision Voice]: request: {0}, path: {1}, param: {2}", request, path, param);

                string agentname = "x" + Convert.ToBase64String(agentID.GetBytes());
                string password  = "******";//temp hack//new UUID(Guid.NewGuid()).ToString().Replace('-','Z').Substring(0,16);

                // we need to cache the voice credentials, as
                // FreeSwitch is later going to come and ask us for
                // those
                agentname = agentname.Replace('+', '-').Replace('/', '_');

                lock (m_UUIDName)
                {
                    if (m_UUIDName.ContainsKey(agentname))
                    {
                        m_UUIDName[agentname] = avatarName;
                    }
                    else
                    {
                        m_UUIDName.Add(agentname, avatarName);
                    }
                }

                LLSDVoiceAccountResponse voiceAccountResponse =
                    new LLSDVoiceAccountResponse(agentname, password, m_freeSwitchRealm,
                                                 String.Format("http://{0}:{1}{2}/", m_openSimWellKnownHTTPAddress, m_freeSwitchServicePort, m_freeSwitchAPIPrefix));

                string r = LLSDHelpers.SerialiseLLSDReply(voiceAccountResponse);

                m_log.DebugFormat("[Free Switch Voice][Provision Voice]: avatar \"{0}\": {1}", avatarName, r);

                return(r);
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[Free Switch Voice][Provision Voice]: avatar \"{0}\": {1}, retry later", avatarName, e.Message);
                m_log.DebugFormat("[Free Switch Voice][Provision Voice]: avatar \"{0}\": {1} failed", avatarName, e.ToString());

                return("<llsd>undef</llsd>");
            }
        }
Пример #10
0
        public string FetchInventoryRequest(string request, string path, string param, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            //m_log.DebugFormat("[FETCH INVENTORY HANDLER]: Received FetchInventory capability request {0}", request);

            OSDMap   requestmap     = (OSDMap)OSDParser.DeserializeLLSDXml(Utils.StringToBytes(request));
            OSDArray itemsRequested = (OSDArray)requestmap["items"];

            string             reply;
            LLSDFetchInventory llsdReply = new LLSDFetchInventory();

            UUID[] itemIDs = new UUID[itemsRequested.Count];
            int    i       = 0;

            foreach (OSDMap osdItemId in itemsRequested)
            {
                itemIDs[i++] = osdItemId["item_id"].AsUUID();
            }

            InventoryItemBase[] items = null;

            if (m_agentID != UUID.Zero)
            {
                items = m_inventoryService.GetMultipleItems(m_agentID, itemIDs);

                if (items == null)
                {
                    // OMG!!! One by one!!! This is fallback code, in case the backend isn't updated
                    m_log.WarnFormat("[FETCH INVENTORY HANDLER]: GetMultipleItems failed. Falling back to fetching inventory items one by one.");
                    items = new InventoryItemBase[itemsRequested.Count];
                    foreach (UUID id in itemIDs)
                    {
                        items[i++] = m_inventoryService.GetItem(m_agentID, id);
                    }
                }
            }
            else
            {
                items = new InventoryItemBase[itemsRequested.Count];
                foreach (UUID id in itemIDs)
                {
                    items[i++] = m_inventoryService.GetItem(UUID.Zero, id);
                }
            }

            foreach (InventoryItemBase item in items)
            {
                if (item != null)
                {
                    // We don't know the agent that this request belongs to so we'll use the agent id of the item
                    // which will be the same for all items.
                    llsdReply.agent_id = item.Owner;
                    llsdReply.items.Array.Add(ConvertInventoryItem(item));
                }
            }

            reply = LLSDHelpers.SerialiseLLSDReply(llsdReply);

            return(reply);
        }
Пример #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="data"></param>
        /// <param name="path"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public void process(IOSHttpRequest request, IOSHttpResponse response, byte[] data)
        {
            m_timeout.Stop();
            m_httpListener.RemoveSimpleStreamHandler(m_uploaderPath);
            m_timeout.Dispose();

            if (!request.RemoteIPEndPoint.Address.Equals(m_remoteAddress))
            {
                response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return;
            }

            if (OnUpLoad == null)
            {
                response.StatusCode = (int)HttpStatusCode.Gone;
                return;
            }

            if (!BunchOfCaps.ValidateAssetData((byte)AssetType.LSLText, data))
            {
                response.StatusCode = (int)HttpStatusCode.BadRequest;
                return;
            }

            response.StatusCode = (int)HttpStatusCode.OK;

            try
            {
                string res = String.Empty;
                LLSDTaskScriptUploadComplete uploadComplete = new LLSDTaskScriptUploadComplete();

                ArrayList errors = new ArrayList();
                OnUpLoad?.Invoke(m_inventoryItemID, m_primID, m_isScriptRunning, m_experienceKey, data, ref errors);

                uploadComplete.new_asset    = m_inventoryItemID;
                uploadComplete.compiled     = errors.Count > 0 ? false : true;
                uploadComplete.state        = "complete";
                uploadComplete.errors       = new OpenSim.Framework.Capabilities.OSDArray();
                uploadComplete.errors.Array = errors;

                res = LLSDHelpers.SerialiseLLSDReply(uploadComplete);

                if (m_dumpAssetToFile)
                {
                    Util.SaveAssetToFile("updatedtaskscript" + Util.RandomClass.Next(1, 1000) + ".dat", data);
                }

                // m_log.InfoFormat("[CAPS]: TaskInventoryScriptUpdater.uploaderCaps res: {0}", res);
                response.RawBuffer = Util.UTF8NBGetbytes(res);
            }
            catch
            {
                LLSDAssetUploadError error = new LLSDAssetUploadError();
                error.message      = "could not compile script";
                error.identifier   = UUID.Zero;
                response.RawBuffer = Util.UTF8NBGetbytes(LLSDHelpers.SerialiseLLSDReply(error));
                return;
            }
        }
Пример #12
0
        /// <summary>
        /// Called by the script task update handler.  Provides a URL to which the client can upload a new asset.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="path"></param>
        /// <param name="param"></param>
        /// <param name="httpRequest">HTTP request header object</param>
        /// <param name="httpResponse">HTTP response header object</param>
        /// <returns></returns>
        public string ScriptTaskInventory(string request, string path, string param,
                                          IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            try
            {
//                m_log.Debug("[CAPS]: ScriptTaskInventory Request in region: " + m_regionName);
                //m_log.DebugFormat("[CAPS]: request: {0}, path: {1}, param: {2}", request, path, param);

                Hashtable            hash = (Hashtable)LLSD.LLSDDeserialize(Utils.StringToBytes(request));
                LLSDTaskScriptUpdate llsdUpdateRequest = new LLSDTaskScriptUpdate();
                LLSDHelpers.DeserialiseOSDMap(hash, llsdUpdateRequest);

                string capsBase     = "/CAPS/" + m_HostCapsObj.CapsObjectPath;
                string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000");

                TaskInventoryScriptUpdater uploader =
                    new TaskInventoryScriptUpdater(
                        llsdUpdateRequest.item_id,
                        llsdUpdateRequest.task_id,
                        llsdUpdateRequest.is_script_running,
                        capsBase + uploaderPath,
                        m_HostCapsObj.HttpListener,
                        m_dumpAssetsToFile);
                uploader.OnUpLoad += TaskScriptUpdated;

                m_HostCapsObj.HttpListener.AddStreamHandler(
                    new BinaryStreamHandler(
                        "POST", capsBase + uploaderPath, uploader.uploaderCaps, "TaskInventoryScriptUpdater", null));

                string protocol = "http://";

                if (m_HostCapsObj.SSLCaps)
                {
                    protocol = "https://";
                }

                string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + capsBase +
                                     uploaderPath;

                LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse();
                uploadResponse.uploader = uploaderURL;
                uploadResponse.state    = "upload";

                //                m_log.InfoFormat("[CAPS]: " +
                //                                 "ScriptTaskInventory response: {0}",
                //                                 LLSDHelpers.SerialiseLLSDReply(uploadResponse)));

                return(LLSDHelpers.SerialiseLLSDReply(uploadResponse));
            }
            catch (Exception e)
            {
                m_log.Error("[CAPS]: " + e.ToString());
            }

            return(null);
        }
Пример #13
0
        /// <summary>
        ///     Callback for a client request for ParcelVoiceInfo
        /// </summary>
        /// <param name="scene">current scene object of the client</param>
        /// <param name="request"></param>
        /// <param name="path"></param>
        /// <param name="param"></param>
        /// <param name="agentID"></param>
        /// <param name="caps"></param>
        /// <returns></returns>
        public string ParcelVoiceInfoRequest(Scene scene, string request, string path, string param, UUID agentID, Caps caps)
        {
            ScenePresence avatar     = scene.GetScenePresence(agentID);
            string        avatarName = avatar.Name;

            // - check whether we have a region channel in our cache
            // - if not:
            //       create it and cache it
            // - send it to the client
            // - send channel_uri: as "sip:regionID@m_sipDomain"
            try
            {
                LLSDParcelVoiceInfoResponse parcelVoiceInfo;
                string channelUri;

                if (null == scene.LandChannel)
                {
                    throw new Exception(String.Format("retion \"{0}\": avatar \"{1}\": land data not yet available", scene.RegionInfo.Regionname, avatarName));
                }

                // get channel_uri: check first whether estate
                // settings allow voice, then whether parcel allows
                // voice, if all do retrieve or obtain the parcel
                // voice channel
                LandData land = scene.GetLandData(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);

                m_log.DebugFormat("[Free Switch Voice][Parcel Voice]: region \"{0}\": Parcel \"{1}\" ({2}): avatar \"{3}\": request: {4}, path: {5}, param: {6}", scene.RegionInfo.RegionName, land.Name, land.LocalID, avatarName, request, path, param);

                if ((land.Flags & (uint)Parcel.ParcelFlags.AllowVoiceChat) == 0)
                {
                    m_log.DebugFormat("[Free Switch Voice][Parcel Voice]: region \"{0}\": Parcel \"{1}\" ({2}): avatar \"{3}\": voice not enabled for parcel", scene.RegionInfo.RegionName, land.Name, land.LocalID, avatarName);
                    channelUri = String.Empty;
                }
                else
                {
                    channelUri = ChannelUri(scene, land);
                }

                // fill in our response to the client
                Hashtable creds = new Hashtable();
                creds["channel_uri"] = channelUri;

                parcelVoiceInfo = new LLSDParcelVoiceInfoResponse(scene.RegionInfo.RegionName, land.LocalID, creds);
                string r = LLSDHelpers.SerialiseLLSDReply(parcelVoiceInfo);

                m_log.DebugFormat("[Free Switch Voice][Parcel Voice]: region \"{0}\": Parcel \"{1}\" ({2}): avatar \"{3}\": {4}", scene.RegionInfo.RegionName, land.Name, land.LocalID, avatarName, r);
                return(r);
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[Free Switch Voice][Parcel Voice]: region \"{0}\": avatar \"{1}\": {2}, retry later", scene.RegionInfo.RegionName, avatarName, e.Message);
                m_log.DebugFormat("[Free Switch Voice][Parcel Voice]: region \"{0}\": avatar \"{1}\": {2} failed", scene.RegionInfo.RegionName, avatarName, e.ToString());

                return("<llsd>undef</llsd>");
            }
        }
Пример #14
0
        /// <summary>
        /// Handle raw uploaded asset data.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="path"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public void process(IOSHttpRequest request, IOSHttpResponse response, byte[] data)
        {
            m_timeout.Stop();
            m_httpListener.RemoveSimpleStreamHandler(m_uploaderPath);
            m_timeout.Dispose();

            if (!request.RemoteIPEndPoint.Address.Equals(m_remoteAdress))
            {
                response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return;
            }

            string res = String.Empty;

            if (OnUpLoad == null)
            {
                response.StatusCode = (int)HttpStatusCode.Gone;
                return;
            }

            if (!BunchOfCaps.ValidateAssetData(m_assetType, data))
            {
                response.StatusCode = (int)HttpStatusCode.BadRequest;
                return;
            }

            UUID assetID = OnUpLoad(m_inventoryItemID, m_objectID, data);

            if (assetID == UUID.Zero)
            {
                LLSDAssetUploadError uperror = new LLSDAssetUploadError();
                uperror.message    = "Failed to update inventory item asset";
                uperror.identifier = m_inventoryItemID;
                res = LLSDHelpers.SerialiseLLSDReply(uperror);
            }
            else
            {
                LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete();
                uploadComplete.new_asset          = assetID.ToString();
                uploadComplete.new_inventory_item = m_inventoryItemID;
                uploadComplete.state = "complete";
                res = LLSDHelpers.SerialiseLLSDReply(uploadComplete);
            }

            if (m_dumpAssetToFile)
            {
                Util.SaveAssetToFile("updateditem" + Util.RandomClass.Next(1, 1000) + ".dat", data);
            }

            response.StatusCode = (int)HttpStatusCode.OK;
            response.RawBuffer  = Util.UTF8NBGetbytes(res);
        }
Пример #15
0
            /// <summary>
            /// Construct a client response detailing all the capabilities this server can provide.
            /// </summary>
            /// <param name="request"></param>
            /// <param name="path"></param>
            /// <param name="param"></param>
            /// <param name="httpRequest">HTTP request header object</param>
            /// <param name="httpResponse">HTTP response header object</param>
            /// <returns></returns>
            public string SeedCapRequest(string request, string path, string param,
                                         OSHttpRequest httpRequest, OSHttpResponse httpResponse)
            {
                // m_log.DebugFormat("[CAPS]: Seed CAPS Request in region {0} = {1}", m_regionName, request);

                Hashtable capsDetails = m_Caps.CapsHandlers.GetCapsDetails(true);

                string result = LLSDHelpers.SerializeLLSDReply(capsDetails);

                // m_log.DebugFormat("[CAPS] CapsRequest {0}", result);

                return(result);
            }
        protected void ProcessRequest(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            if (httpRequest.HttpMethod != "GET")
            {
                httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
                return;
            }

            NameValueCollection query = httpRequest.QueryString;
            string names   = query.GetOne("names");
            string psize   = query.GetOne("page_size");
            string pnumber = query.GetOne("page");

            if (string.IsNullOrEmpty(names) || names.Length < 3)
            {
                httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
                return;
            }

            int page_size;
            int page_number;

            try
            {
                page_size   = (string.IsNullOrEmpty(psize) ? 500 : Int32.Parse(psize));
                page_number = (string.IsNullOrEmpty(pnumber) ? 1 : Int32.Parse(pnumber));
            }
            catch
            {
                httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
                return;
            }
            // Full content request
            List <UserData> users = m_People.GetUserData(names, page_size, page_number);

            LLSDAvatarPicker osdReply = new LLSDAvatarPicker();

            osdReply.next_page_url = httpRequest.RawUrl;
            foreach (UserData u in users)
            {
                osdReply.agents.Array.Add(ConvertUserData(u));
            }

            string reply = LLSDHelpers.SerialiseLLSDReply(osdReply);

            httpResponse.RawBuffer   = Util.UTF8.GetBytes(reply);
            httpResponse.StatusCode  = (int)HttpStatusCode.OK;
            httpResponse.ContentType = "application/llsd+xml";
        }
Пример #17
0
        /// <summary>
        /// Called by the notecard update handler.  Provides a URL to which the client can upload a new asset.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="path"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public string NoteCardAgentInventory(string request, string path, string param,
                                             IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            //m_log.Debug("[CAPS]: NoteCardAgentInventory Request in region: " + m_regionName + "\n" + request);
            //m_log.Debug("[CAPS]: NoteCardAgentInventory Request is: " + request);

            //OpenMetaverse.StructuredData.OSDMap hash = (OpenMetaverse.StructuredData.OSDMap)OpenMetaverse.StructuredData.LLSDParser.DeserializeBinary(Utils.StringToBytes(request));
            Hashtable      hash        = (Hashtable)LLSD.LLSDDeserialize(Utils.StringToBytes(request));
            LLSDItemUpdate llsdRequest = new LLSDItemUpdate();

            LLSDHelpers.DeserialiseOSDMap(hash, llsdRequest);

            string capsBase     = "/CAPS/" + m_HostCapsObj.CapsObjectPath;
            string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000");

            ItemUpdater uploader =
                new ItemUpdater(llsdRequest.item_id, capsBase + uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile);

            uploader.OnUpLoad += ItemUpdated;

            m_HostCapsObj.HttpListener.AddStreamHandler(
                new BinaryStreamHandler(
                    "POST", capsBase + uploaderPath, uploader.uploaderCaps, "NoteCardAgentInventory", null));

            string protocol = "http://";

            if (m_HostCapsObj.SSLCaps)
            {
                protocol = "https://";
            }

            string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + capsBase +
                                 uploaderPath;

            LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse();

            uploadResponse.uploader = uploaderURL;
            uploadResponse.state    = "upload";

            //            m_log.InfoFormat("[CAPS]: " +
            //                             "NoteCardAgentInventory response: {0}",
            //                             LLSDHelpers.SerialiseLLSDReply(uploadResponse)));

            return(LLSDHelpers.SerialiseLLSDReply(uploadResponse));
        }
Пример #18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="data"></param>
        /// <param name="path"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public string uploaderCaps(byte[] data, string path, string param)
        {
            try
            {
                //                    m_log.InfoFormat("[CAPS]: " +
                //                                     "TaskInventoryScriptUpdater received data: {0}, path: {1}, param: {2}",
                //                                     data, path, param));

                string res = String.Empty;
                LLSDTaskScriptUploadComplete uploadComplete = new LLSDTaskScriptUploadComplete();

                ArrayList errors = new ArrayList();
                handlerUpdateTaskScript = OnUpLoad;
                if (handlerUpdateTaskScript != null)
                {
                    handlerUpdateTaskScript(inventoryItemID, primID, isScriptRunning, data, ref errors);
                }

                uploadComplete.new_asset    = inventoryItemID;
                uploadComplete.compiled     = errors.Count > 0 ? false : true;
                uploadComplete.state        = "complete";
                uploadComplete.errors       = new OpenSim.Framework.Capabilities.OSDArray();
                uploadComplete.errors.Array = errors;

                res = LLSDHelpers.SerialiseLLSDReply(uploadComplete);

                httpListener.RemoveStreamHandler("POST", uploaderPath);

                if (m_dumpAssetToFile)
                {
                    SaveAssetToFile("updatedtaskscript" + Util.RandomClass.Next(1, 1000) + ".dat", data);
                }

                //                    m_log.InfoFormat("[CAPS]: TaskInventoryScriptUpdater.uploaderCaps res: {0}", res);

                return(res);
            }
            catch (Exception e)
            {
                m_log.Error("[CAPS]: " + e.ToString());
            }

            // XXX Maybe this should be some meaningful error packet
            return(null);
        }
Пример #19
0
        /// Callback for a client request for Voice Account Details.
        public string ProvisionVoiceAccountRequest(Scene scene, string request, string path, string param,
                                                   UUID agentID)
        {
            try
            {
                m_log.Debug("[MurmurVoice] Calling ProvisionVoiceAccountRequest...");

                if (scene == null)
                {
                    throw new Exception("[MurmurVoice] Invalid scene.");
                }

                // Wait for scene presence
                int           retry  = 0;
                ScenePresence avatar = scene.GetScenePresence(agentID);
                while (avatar == null)
                {
                    if (++retry > 100)
                    {
                        throw new Exception(String.Format("region \"{0}\": agent ID \"{1}\": wait for scene presence timed out",
                                                          scene.RegionInfo.RegionName, agentID));
                    }

                    Thread.Sleep(100);
                    avatar = scene.GetScenePresence(agentID);
                }

                Agent agent = new Agent(agentID, scene);

                LLSDVoiceAccountResponse voiceAccountResponse =
                    new LLSDVoiceAccountResponse(agent.name, agent.pass, m_murmurd_host,
                                                 String.Format("tcp://{0}:{1}", m_murmurd_host, m_murmurd_port)
                                                 );

                string r = LLSDHelpers.SerialiseLLSDReply(voiceAccountResponse);
                m_log.DebugFormat("[MurmurVoice] VoiceAccount: {0}", r);
                return(r);
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[MurmurVoice] {0} failed", e.ToString());
                return("<llsd><undef /></llsd>");
            }
        }
Пример #20
0
                /// <summary>
                /// Handle raw uploaded baked texture data.
                /// </summary>
                /// <param name="data"></param>
                /// <param name="path"></param>
                /// <param name="param"></param>
                /// <returns></returns>
                public string BakedTextureUploaded(byte[] data, string path, string param)
                {
                    String result;
                    bool   decodeFailed = false;
                    UUID   newAssetID   = UUID.Random();

                    if (data.Length <= 0)
                    {
                        m_log.ErrorFormat("[CAPS]: Invalid length {0} on UploadBakeRequestPut for {1}", data.Length, path);
                        decodeFailed = true;
                    }
                    else if (m_layerDecoder != null)
                    {
                        decodeFailed = (m_layerDecoder.Decode(newAssetID, data) == false);
                    }

                    if (decodeFailed)
                    {
                        Hashtable badReply = new Hashtable();
                        badReply["state"]     = "error";
                        badReply["new_asset"] = UUID.Zero;
                        result = LLSDHelpers.SerializeLLSDReply(badReply);
                    }
                    else
                    {
                        AssetBase asset = new AssetBase(newAssetID, "Baked Texture", (sbyte)AssetType.Texture, m_Caps.AgentID.ToString());
                        asset.Data = data;
                        //Persist baked textures as we will use them in the baked texture cache
                        //asset.Temporary = true;
                        asset.Local = true;
                        m_assetCache.AddAsset(asset, AssetRequestInfo.GenericNetRequest());

                        LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete();
                        uploadComplete.new_asset          = newAssetID.ToString();
                        uploadComplete.new_inventory_item = UUID.Zero;
                        uploadComplete.state = "complete";

                        result = LLSDHelpers.SerializeLLSDReply(uploadComplete);
                        // m_log.DebugFormat("[BAKED TEXTURE UPLOADER]: baked texture upload completed for {0}", newAssetID);
                    }

                    m_Caps.HttpListener.RemoveStreamHandler("POST", m_uploaderPath);
                    return(result);
                }
Пример #21
0
        public string OnDiscoveryAttempt(string request, string path, string param,
                                         IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            //Very static for now, flexible enough to add new formats
            LLSDDiscoveryResponse llsd_response = new LLSDDiscoveryResponse();

            llsd_response.snapshot_resources = new OSDArray();

            LLSDDiscoveryDataURL llsd_dataurl = new LLSDDiscoveryDataURL();

            llsd_dataurl.snapshot_format = "os-datasnapshot-v1";
            llsd_dataurl.snapshot_url    = "http://" + m_externalData.m_hostname + ":" + m_externalData.m_listener_port + "/?method=collector";

            llsd_response.snapshot_resources.Array.Add(llsd_dataurl);

            string response = LLSDHelpers.SerialiseLLSDReply(llsd_response);

            return(response);
        }
Пример #22
0
        protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            // Try to parse the texture ID from the request URL
            NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query);
            string names   = query.GetOne("names");
            string psize   = query.GetOne("page_size");
            string pnumber = query.GetOne("page");

            if (m_PeopleService == null)
            {
                return(FailureResponse(names, (int)System.Net.HttpStatusCode.InternalServerError, httpResponse));
            }

            if (string.IsNullOrEmpty(names) || names.Length < 3)
            {
                return(FailureResponse(names, (int)System.Net.HttpStatusCode.BadRequest, httpResponse));
            }

            m_log.DebugFormat("[AVATAR PICKER SEARCH]: search for {0}", names);

            int page_size   = (string.IsNullOrEmpty(psize) ? 500 : Int32.Parse(psize));
            int page_number = (string.IsNullOrEmpty(pnumber) ? 1 : Int32.Parse(pnumber));

            // Full content request
            httpResponse.StatusCode = (int)System.Net.HttpStatusCode.OK;
            //httpResponse.ContentLength = ??;
            httpResponse.ContentType = "application/llsd+xml";

            List <UserData> users = m_PeopleService.GetUserData(names, page_size, page_number);

            LLSDAvatarPicker osdReply = new LLSDAvatarPicker();

            osdReply.next_page_url = httpRequest.RawUrl;
            foreach (UserData u in users)
            {
                osdReply.agents.Array.Add(ConvertUserData(u));
            }

            string reply = LLSDHelpers.SerialiseLLSDReply(osdReply);

            return(System.Text.Encoding.UTF8.GetBytes(reply));
        }
Пример #23
0
        /// <summary>
        /// Handle a request from the client for a Uri to upload a baked texture.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="path"></param>
        /// <param name="param"></param>
        /// <param name="httpRequest"></param>
        /// <param name="httpResponse"></param>
        /// <returns>The upload response if the request is successful, null otherwise.</returns>
        public string UploadBakedTexture(
            string request, string path, string param, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            try
            {
                m_log.DebugFormat("[UploadBakedTextureHandler]: UploadBakedTexture(request: {0}, path: {1}, param: {2} ...)", request, path, param);
                string capsBase     = "/CAPS/" + m_HostCapsObj.CapsObjectPath;
                string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000");

                BakedTextureUploader uploader =
                    new BakedTextureUploader(capsBase + uploaderPath, m_HostCapsObj.HttpListener);
                uploader.OnUpLoad += BakedTextureUploaded;

                m_HostCapsObj.HttpListener.AddStreamHandler(
                    new BinaryStreamHandler(
                        "POST", capsBase + uploaderPath, uploader.uploaderCaps, "UploadBakedTexture", null));

                string protocol = "http://";

                if (m_HostCapsObj.SSLCaps)
                {
                    protocol = "https://";
                }

                string uploaderURL = protocol + m_HostCapsObj.HostName + ":" +
                                     m_HostCapsObj.Port.ToString() + capsBase + uploaderPath;

                LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse();
                uploadResponse.uploader = uploaderURL;
                uploadResponse.state    = "upload";

                return(LLSDHelpers.SerialiseLLSDReply(uploadResponse));
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[UploadBakedTextureHandler]: {0}{1}", e.Message, e.StackTrace);
            }

            return(null);
        }
        public void UploadBakedTexture(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, UUID agentID, Caps caps, IAssetCache cache)
        {
            if (httpRequest.HttpMethod != "POST")
            {
                httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
                return;
            }
            try
            {
                string capsBase    = "/" + UUID.Random() + "-BK";
                string protocol    = caps.SSLCaps ? "https://" : "http://";
                string uploaderURL = protocol + caps.HostName + ":" + caps.Port.ToString() + capsBase;

                LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse();
                uploadResponse.uploader = uploaderURL;
                uploadResponse.state    = "upload";

                BakedTextureUploader uploader =
                    new BakedTextureUploader(capsBase, caps.HttpListener, agentID, cache, httpRequest.RemoteIPEndPoint.Address);

                var uploaderHandler = new SimpleBinaryHandler("POST", capsBase, uploader.process);

                uploaderHandler.MaxDataSize = 6000000; // change per asset type?

                caps.HttpListener.AddSimpleStreamHandler(uploaderHandler);

                httpResponse.RawBuffer  = Util.UTF8NBGetbytes(LLSDHelpers.SerialiseLLSDReply(uploadResponse));
                httpResponse.StatusCode = (int)HttpStatusCode.OK;
                return;
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[UPLOAD BAKED TEXTURE HANDLER]: {0}{1}", e.Message, e.StackTrace);
            }
            httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
        }
Пример #25
0
            /// <summary>
            /// Handle a request from the client for a Uri to upload a baked texture.
            /// </summary>
            /// <param name="request"></param>
            /// <param name="path"></param>
            /// <param name="param"></param>
            /// <param name="httpRequest"></param>
            /// <param name="httpResponse"></param>
            /// <returns>The upload response if the request is successful, null otherwise.</returns>
            public string UploadBakedTexture(
                string request, string path, string param, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
            {
                try
                {
                    IAssetCache          assetCache   = m_Scene.CommsManager.AssetCache;
                    IJ2KDecoder          layerDecoder = m_Scene.RequestModuleInterface <IJ2KDecoder>();
                    String               uploaderPath = m_Caps.CapsBase + "/" + UUID.Random();
                    BakedTextureUploader uploader     = new BakedTextureUploader(m_Caps, uploaderPath, assetCache, layerDecoder);
                    m_Caps.HttpListener.AddStreamHandler(new BinaryStreamHandler("POST", uploaderPath, uploader.BakedTextureUploaded));

                    string uploaderURL = m_Caps.HttpListener.ServerURI + uploaderPath;
                    LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse();
                    uploadResponse.uploader = uploaderURL;
                    uploadResponse.state    = "upload";
                    return(LLSDHelpers.SerializeLLSDReply(uploadResponse));
                }
                catch (Exception e)
                {
                    m_log.ErrorFormat("[UPLOAD BAKED TEXTURE HANDLER]: {0}{1}", e.Message, e.StackTrace);
                }

                return(null);
            }
Пример #26
0
        private void UpdateInventoryItemAsset(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, OSDMap map, byte atype, bool taskSript = false)
        {
            m_log.Debug("[CAPS]: UpdateInventoryItemAsset Request in region: " + m_regionName + "\n");

            httpResponse.StatusCode = (int)HttpStatusCode.OK;

            UUID itemID   = UUID.Zero;
            UUID objectID = UUID.Zero;

            try
            {
                if (map.TryGetValue("item_id", out OSD itmp))
                {
                    itemID = itmp;
                }
                if (map.TryGetValue("task_id", out OSD tmp))
                {
                    objectID = tmp;
                }
            }
            catch { }

            if (itemID == UUID.Zero)
            {
                LLSDAssetUploadError error = new LLSDAssetUploadError();
                error.message          = "failed to recode request";
                error.identifier       = UUID.Zero;
                httpResponse.RawBuffer = Util.UTF8NBGetbytes(LLSDHelpers.SerialiseLLSDReply(error));
                return;
            }

            if (objectID != UUID.Zero)
            {
                SceneObjectPart sop = m_Scene.GetSceneObjectPart(objectID);
                if (sop == null)
                {
                    LLSDAssetUploadError error = new LLSDAssetUploadError();
                    error.message          = "object not found";
                    error.identifier       = UUID.Zero;
                    httpResponse.RawBuffer = Util.UTF8NBGetbytes(LLSDHelpers.SerialiseLLSDReply(error));
                    return;
                }

                if (!m_Scene.Permissions.CanEditObjectInventory(objectID, m_AgentID))
                {
                    LLSDAssetUploadError error = new LLSDAssetUploadError();
                    error.message          = "No permissions to edit objec";
                    error.identifier       = UUID.Zero;
                    httpResponse.RawBuffer = Util.UTF8NBGetbytes(LLSDHelpers.SerialiseLLSDReply(error));
                    return;
                }
            }

            string uploaderPath = GetNewCapPath();

            string protocol    = m_HostCapsObj.SSLCaps ? "https://" : "http://";
            string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + uploaderPath;
            LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse();

            uploadResponse.uploader = uploaderURL;
            uploadResponse.state    = "upload";

            ItemUpdater uploader = new ItemUpdater(itemID, objectID, atype, uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile);

            uploader.m_remoteAdress = httpRequest.RemoteIPEndPoint.Address;

            uploader.OnUpLoad += ItemUpdated;

            var uploaderHandler = new SimpleBinaryHandler("POST", uploaderPath, uploader.process);

            uploaderHandler.MaxDataSize = 10000000; // change per asset type?

            m_HostCapsObj.HttpListener.AddSimpleStreamHandler(uploaderHandler);

            // m_log.InfoFormat("[CAPS]: UpdateAgentInventoryAsset response: {0}",
            //                             LLSDHelpers.SerialiseLLSDReply(uploadResponse)));

            httpResponse.RawBuffer = Util.UTF8NBGetbytes(LLSDHelpers.SerialiseLLSDReply(uploadResponse));
        }
        private string FetchInventoryDescendentsRequest(ArrayList foldersrequested, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            //m_log.DebugFormat("[WEB FETCH INV DESC HANDLER]: Received request for {0} folders", foldersrequested.Count);

            string response             = "";
            string bad_folders_response = "";

            for (int i = 0; i < foldersrequested.Count; i++)
            {
                string    inventoryitemstr = "";
                Hashtable inventoryhash    = (Hashtable)foldersrequested[i];

                LLSDFetchInventoryDescendents llsdRequest = new LLSDFetchInventoryDescendents();

                try
                {
                    LLSDHelpers.DeserialiseOSDMap(inventoryhash, llsdRequest);
                }
                catch (Exception e)
                {
                    m_log.Debug("[WEB FETCH INV DESC HANDLER]: caught exception doing OSD deserialize" + e);
                }

                LLSDInventoryDescendents reply = FetchInventoryReply(llsdRequest);

                if (null == reply)
                {
                    bad_folders_response += "<uuid>" + llsdRequest.folder_id.ToString() + "</uuid>";
                }
                else
                {
                    inventoryitemstr = LLSDHelpers.SerialiseLLSDReply(reply);
                    inventoryitemstr = inventoryitemstr.Replace("<llsd><map><key>folders</key><array>", "");
                    inventoryitemstr = inventoryitemstr.Replace("</array></map></llsd>", "");
                }

                response += inventoryitemstr;
            }

            if (response.Length == 0)
            {
                /* Viewers expect a bad_folders array when not available */
                if (bad_folders_response.Length != 0)
                {
                    response = "<llsd><map><key>bad_folders</key><array>" + bad_folders_response + "</array></map></llsd>";
                }
                else
                {
                    response = "<llsd><map><key>folders</key><array /></map></llsd>";
                }
            }
            else
            {
                if (bad_folders_response.Length != 0)
                {
                    response = "<llsd><map><key>folders</key><array>" + response + "</array><key>bad_folders</key><array>" + bad_folders_response + "</array></map></llsd>";
                }
                else
                {
                    response = "<llsd><map><key>folders</key><array>" + response + "</array></map></llsd>";
                }
            }

            //                m_log.DebugFormat("[WEB FETCH INV DESC HANDLER]: Replying to CAPS fetch inventory request");
            //m_log.Debug("[WEB FETCH INV DESC HANDLER] "+response);

            return(response);

            //            }
        }
        public string FetchInventoryDescendentsRequest(string request, string path, string param, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            //m_log.DebugFormat("[XXX]: FetchInventoryDescendentsRequest in {0}, {1}", (m_Scene == null) ? "none" : m_Scene.Name, request);

            // nasty temporary hack here, the linden client falsely
            // identifies the uuid 00000000-0000-0000-0000-000000000000
            // as a string which breaks us
            //
            // correctly mark it as a uuid
            //
            request = request.Replace("<string>00000000-0000-0000-0000-000000000000</string>", "<uuid>00000000-0000-0000-0000-000000000000</uuid>");

            // another hack <integer>1</integer> results in a
            // System.ArgumentException: Object type System.Int32 cannot
            // be converted to target type: System.Boolean
            //
            request = request.Replace("<key>fetch_folders</key><integer>0</integer>", "<key>fetch_folders</key><boolean>0</boolean>");
            request = request.Replace("<key>fetch_folders</key><integer>1</integer>", "<key>fetch_folders</key><boolean>1</boolean>");

            Hashtable hash = new Hashtable();

            try
            {
                hash = (Hashtable)LLSD.LLSDDeserialize(Utils.StringToBytes(request));
            }
            catch (LLSD.LLSDParseException e)
            {
                m_log.ErrorFormat("[WEB FETCH INV DESC HANDLER]: Fetch error: {0}{1}" + e.Message, e.StackTrace);
                m_log.Error("Request: " + request);
            }

            ArrayList foldersrequested = (ArrayList)hash["folders"];

            string response             = "";
            string bad_folders_response = "";

            List <LLSDFetchInventoryDescendents> folders = new List <LLSDFetchInventoryDescendents>();

            for (int i = 0; i < foldersrequested.Count; i++)
            {
                Hashtable inventoryhash = (Hashtable)foldersrequested[i];

                LLSDFetchInventoryDescendents llsdRequest = new LLSDFetchInventoryDescendents();

                try
                {
                    LLSDHelpers.DeserialiseOSDMap(inventoryhash, llsdRequest);
                }
                catch (Exception e)
                {
                    m_log.Debug("[WEB FETCH INV DESC HANDLER]: caught exception doing OSD deserialize" + e);
                    continue;
                }

                // Filter duplicate folder ids that bad viewers may send
                if (folders.Find(f => f.folder_id == llsdRequest.folder_id) == null)
                {
                    folders.Add(llsdRequest);
                }
            }

            if (folders.Count > 0)
            {
                List <UUID> bad_folders = new List <UUID>();
                List <InventoryCollectionWithDescendents> invcollSet = Fetch(folders, bad_folders);
                //m_log.DebugFormat("[XXX]: Got {0} folders from a request of {1}", invcollSet.Count, folders.Count);

                if (invcollSet == null)
                {
                    m_log.DebugFormat("[WEB FETCH INV DESC HANDLER]: Multiple folder fetch failed. Trying old protocol.");
#pragma warning disable 0612
                    return(FetchInventoryDescendentsRequest(foldersrequested, httpRequest, httpResponse));

#pragma warning restore 0612
                }

                string inventoryitemstr = string.Empty;
                foreach (InventoryCollectionWithDescendents icoll in invcollSet)
                {
                    LLSDInventoryDescendents reply = ToLLSD(icoll.Collection, icoll.Descendents);

                    inventoryitemstr = LLSDHelpers.SerialiseLLSDReply(reply);
                    inventoryitemstr = inventoryitemstr.Replace("<llsd><map><key>folders</key><array>", "");
                    inventoryitemstr = inventoryitemstr.Replace("</array></map></llsd>", "");

                    response += inventoryitemstr;
                }

                //m_log.DebugFormat("[WEB FETCH INV DESC HANDLER]: Bad folders {0}", string.Join(", ", bad_folders));
                foreach (UUID bad in bad_folders)
                {
                    bad_folders_response += "<uuid>" + bad + "</uuid>";
                }
            }

            if (response.Length == 0)
            {
                /* Viewers expect a bad_folders array when not available */
                if (bad_folders_response.Length != 0)
                {
                    response = "<llsd><map><key>bad_folders</key><array>" + bad_folders_response + "</array></map></llsd>";
                }
                else
                {
                    response = "<llsd><map><key>folders</key><array /></map></llsd>";
                }
            }
            else
            {
                if (bad_folders_response.Length != 0)
                {
                    response = "<llsd><map><key>folders</key><array>" + response + "</array><key>bad_folders</key><array>" + bad_folders_response + "</array></map></llsd>";
                }
                else
                {
                    response = "<llsd><map><key>folders</key><array>" + response + "</array></map></llsd>";
                }
            }

            //m_log.DebugFormat("[WEB FETCH INV DESC HANDLER]: Replying to CAPS fetch inventory request for {0} folders. Item count {1}", folders.Count, item_count);
            //m_log.Debug("[WEB FETCH INV DESC HANDLER] " + response);

            return(response);
        }
Пример #29
0
        public string FetchInventoryDescendentsRequest(string request, string path, string param, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
//            lock (m_fetchLock)
//            {
//                m_log.DebugFormat("[WEB FETCH INV DESC HANDLER]: Received request {0}", request);

            // nasty temporary hack here, the linden client falsely
            // identifies the uuid 00000000-0000-0000-0000-000000000000
            // as a string which breaks us
            //
            // correctly mark it as a uuid
            //
            request = request.Replace("<string>00000000-0000-0000-0000-000000000000</string>", "<uuid>00000000-0000-0000-0000-000000000000</uuid>");

            // another hack <integer>1</integer> results in a
            // System.ArgumentException: Object type System.Int32 cannot
            // be converted to target type: System.Boolean
            //
            request = request.Replace("<key>fetch_folders</key><integer>0</integer>", "<key>fetch_folders</key><boolean>0</boolean>");
            request = request.Replace("<key>fetch_folders</key><integer>1</integer>", "<key>fetch_folders</key><boolean>1</boolean>");

            Hashtable hash = new Hashtable();

            try
            {
                hash = (Hashtable)LLSD.LLSDDeserialize(Utils.StringToBytes(request));
            }
            catch (LLSD.LLSDParseException e)
            {
                m_log.ErrorFormat("[WEB FETCH INV DESC HANDLER]: Fetch error: {0}{1}" + e.Message, e.StackTrace);
                m_log.Error("Request: " + request);
            }

            ArrayList foldersrequested = (ArrayList)hash["folders"];

            string response = "";

            for (int i = 0; i < foldersrequested.Count; i++)
            {
                string    inventoryitemstr = "";
                Hashtable inventoryhash    = (Hashtable)foldersrequested[i];

                LLSDFetchInventoryDescendents llsdRequest = new LLSDFetchInventoryDescendents();

                try
                {
                    LLSDHelpers.DeserialiseOSDMap(inventoryhash, llsdRequest);
                }
                catch (Exception e)
                {
                    m_log.Debug("[WEB FETCH INV DESC HANDLER]: caught exception doing OSD deserialize" + e);
                }
                LLSDInventoryDescendents reply = FetchInventoryReply(llsdRequest);

                inventoryitemstr = LLSDHelpers.SerialiseLLSDReply(reply);
                inventoryitemstr = inventoryitemstr.Replace("<llsd><map><key>folders</key><array>", "");
                inventoryitemstr = inventoryitemstr.Replace("</array></map></llsd>", "");

                response += inventoryitemstr;
            }

            if (response.Length == 0)
            {
                // Ter-guess: If requests fail a lot, the client seems to stop requesting descendants.
                // Therefore, I'm concluding that the client only has so many threads available to do requests
                // and when a thread stalls..   is stays stalled.
                // Therefore we need to return something valid
                response = "<llsd><map><key>folders</key><array /></map></llsd>";
            }
            else
            {
                response = "<llsd><map><key>folders</key><array>" + response + "</array></map></llsd>";
            }

//                m_log.DebugFormat("[WEB FETCH INV DESC HANDLER]: Replying to CAPS fetch inventory request");
            //m_log.Debug("[WEB FETCH INV DESC HANDLER] "+response);

            return(response);

//            }
        }
Пример #30
0
        /// <summary>
        /// Called by the script task update handler.  Provides a URL to which the client can upload a new asset.
        /// </summary>
        /// <param name="httpRequest">HTTP request header object</param>
        /// <param name="httpResponse">HTTP response header object</param>
        /// <returns></returns>
        public void UpdateScriptTaskInventory(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, OSDMap map)
        {
            httpResponse.StatusCode = (int)HttpStatusCode.OK;

            try
            {
                //m_log.Debug("[CAPS]: ScriptTaskInventory Request in region: " + m_regionName);
                //m_log.DebugFormat("[CAPS]: request: {0}, path: {1}, param: {2}", request, path, param);

                UUID itemID            = UUID.Zero;
                UUID objectID          = UUID.Zero;
                bool is_script_running = false;
                UUID experience_key    = UUID.Zero;
                OSD  tmp;
                try
                {
                    if (map.TryGetValue("item_id", out tmp))
                    {
                        itemID = tmp;
                    }
                    if (map.TryGetValue("task_id", out tmp))
                    {
                        objectID = tmp;
                    }
                    if (map.TryGetValue("is_script_running", out tmp))
                    {
                        is_script_running = tmp;
                    }
                    if (map.TryGetValue("experience", out tmp))
                    {
                        experience_key = tmp;
                    }
                }
                catch { }

                if (itemID == UUID.Zero || objectID == UUID.Zero)
                {
                    LLSDAssetUploadError error = new LLSDAssetUploadError();
                    error.message          = "failed to recode request";
                    error.identifier       = UUID.Zero;
                    httpResponse.RawBuffer = Util.UTF8NBGetbytes(LLSDHelpers.SerialiseLLSDReply(error));
                    return;
                }

                SceneObjectPart sop = m_Scene.GetSceneObjectPart(objectID);
                if (sop == null)
                {
                    LLSDAssetUploadError error = new LLSDAssetUploadError();
                    error.message          = "object not found";
                    error.identifier       = UUID.Zero;
                    httpResponse.RawBuffer = Util.UTF8NBGetbytes(LLSDHelpers.SerialiseLLSDReply(error));
                    return;
                }

                if (!m_Scene.Permissions.CanEditObjectInventory(objectID, m_AgentID))
                {
                    LLSDAssetUploadError error = new LLSDAssetUploadError();
                    error.message          = "No permissions to edit objec";
                    error.identifier       = UUID.Zero;
                    httpResponse.RawBuffer = Util.UTF8NBGetbytes(LLSDHelpers.SerialiseLLSDReply(error));
                    return;
                }

                if (!m_Scene.Permissions.CanEditScript(itemID, objectID, m_AgentID))
                {
                    LLSDAssetUploadError error = new LLSDAssetUploadError();
                    error.message          = "No permissions to edit script";
                    error.identifier       = UUID.Zero;
                    httpResponse.RawBuffer = Util.UTF8NBGetbytes(LLSDHelpers.SerialiseLLSDReply(error));
                    return;
                }

                string uploaderPath = GetNewCapPath();
                string protocol     = m_HostCapsObj.SSLCaps ? "https://" : "http://";
                string uploaderURL  = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + uploaderPath;
                LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse();
                uploadResponse.uploader = uploaderURL;
                uploadResponse.state    = "upload";

                TaskInventoryScriptUpdater uploader = new TaskInventoryScriptUpdater(itemID, objectID, is_script_running, experience_key,
                                                                                     uploaderPath, m_HostCapsObj.HttpListener, httpRequest.RemoteIPEndPoint.Address, m_dumpAssetsToFile);
                uploader.OnUpLoad += TaskScriptUpdated;

                var uploaderHandler = new SimpleBinaryHandler("POST", uploaderPath, uploader.process);

                uploaderHandler.MaxDataSize = 10000000; // change per asset type?

                m_HostCapsObj.HttpListener.AddSimpleStreamHandler(uploaderHandler);

                // m_log.InfoFormat("[CAPS]: " +
                //    "ScriptTaskInventory response: {0}",
                //       LLSDHelpers.SerialiseLLSDReply(uploadResponse)));

                httpResponse.RawBuffer = Util.UTF8NBGetbytes(LLSDHelpers.SerialiseLLSDReply(uploadResponse));
            }
            catch (Exception e)
            {
                m_log.Error("[UpdateScriptTaskInventory]: " + e.ToString());
            }
        }