Ejemplo n.º 1
0
        protected override byte[] ProcessRequest(string path, Stream request,
                                                 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            //Encoding encoding = Util.UTF8;
            //StreamReader streamReader = new StreamReader(request, false);

            //string requestBody = streamReader.ReadToEnd();
            //streamReader.Close();

            // OpenMetaverse.StructuredData.OSDMap hash = (OpenMetaverse.StructuredData.OSDMap)
            //    OpenMetaverse.StructuredData.LLSDParser.DeserializeXml(new XmlTextReader(request));

            Hashtable hash = (Hashtable)LLSD.LLSDDeserialize(request);

            if (hash == null)
            {
                return(new byte[0]);
            }

            TRequest llsdRequest = new TRequest();

            LLSDHelpers.DeserialiseOSDMap(hash, llsdRequest);

            TResponse response = m_method(llsdRequest);

            return(Util.UTF8NoBomEncoding.GetBytes(LLSDHelpers.SerialiseLLSDReply(response)));
        }
Ejemplo n.º 2
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, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            Hashtable      hash        = (Hashtable)LLSD.LLSDDeserialize(Utils.StringToBytes(request));
            LLSDItemUpdate llsdRequest = new LLSDItemUpdate();

            LLSDHelpers.DeserialiseOSDMap(hash, llsdRequest);

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

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

            uploader.OnUpLoad += ItemUpdated;

            m_httpListener.AddStreamHandler(new BinaryStreamHandler("POST", capsBase + uploaderPath, uploader.uploaderCaps));

            string protocol = "http://";

            if (m_httpListener.UseSSL)
            {
                protocol = "https://";
            }

            string uploaderURL = protocol + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + capsBase + uploaderPath;

            LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse();

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

            return(LLSDHelpers.SerialiseLLSDReply(uploadResponse));
        }
Ejemplo n.º 3
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)
            {
                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);
            }
Ejemplo n.º 4
0
        /// <summary>
        /// generates a empty llsd settings response for viewer
        /// </summary>
        /// <param name="messageID">the message UUID</param>
        /// <param name="regionID">the region UUID</param>
        public static string EmptySettings(UUID messageID, UUID regionID)
        {
            OSDArray arr = new OSDArray();
            LLSDEnvironmentRequest msg = new LLSDEnvironmentRequest();

            msg.messageID = messageID;
            msg.regionID  = regionID;
            arr.Array.Add(msg);
            return(LLSDHelpers.SerialiseLLSDReply(arr));
        }
Ejemplo n.º 5
0
        public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            Hashtable hash        = (Hashtable)LLSD.LLSDDeserialize(request);
            TRequest  llsdRequest = new TRequest();

            LLSDHelpers.DeserialiseOSDMap(hash, llsdRequest);
            TResponse response = m_method(llsdRequest);
            Encoding  encoding = new UTF8Encoding(false);

            return(encoding.GetBytes(LLSDHelpers.SerialiseLLSDReply(response)));
        }
Ejemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public string CreateEmptyEventResponse()
        {
            LLSDCapEvent eventItem = new LLSDCapEvent();

            eventItem.id = m_eventQueueCount;
            eventItem.events.Array.Add(new LLSDEmpty());
            string res = LLSDHelpers.SerialiseLLSDReply(eventItem);

            m_eventQueueCount++;
            return(res);
        }
Ejemplo n.º 7
0
        // FIXME: these all should probably go into the respective region
        // modules

        // multiple fetch-folder maps are allowed within the larger folders map.
        public string FetchInventoryRequest(string request, string path, string param)
        {
            m_log.Debug("[Caps]: Inventory Request in region: " + m_regionName);

            Hashtable hash = new Hashtable();

            try
            {
                hash = (Hashtable)LLSD.LLSDDeserialize(Utils.StringToBytes(request));
            }
            catch (LLSD.LLSDParseException pe)
            {
                m_log.Error("[Agent Inventory]: Fetch error: " + pe.Message);
                m_log.Error("Request: " + request.ToString());
            }

            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();
                LLSDHelpers.DeserialiseOSDMap(inventoryhash, llsdRequest);
                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>";
            }

            return(response);
        }
Ejemplo n.º 8
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 CapsRequest(string request, string path, string param, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            m_log.Debug("[Caps]: Seed Caps Request in region: " + m_regionName);

            if (!m_Scene.CheckClient(m_agentID, httpRequest.RemoteIPEndPoint))
            {
                m_log.DebugFormat("[Caps]: Unauthorized CAPS client");
                return(string.Empty);
            }

            string result = LLSDHelpers.SerialiseLLSDReply(m_capsHandlers.CapsDetails);

            return(result);
        }
Ejemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="caps"></param>
        /// <param name="ipAddressPort"></param>
        /// <returns></returns>
        public string CreateEstablishAgentComms(string caps, string ipAddressPort)
        {
            LLSDCapEvent eventItem = new LLSDCapEvent();

            eventItem.id = m_eventQueueCount;

            //should be creating a EstablishAgentComms item, but there isn't a class for it yet
            eventItem.events.Array.Add(new LLSDEmpty());
            string res = LLSDHelpers.SerialiseLLSDReply(eventItem);

            m_eventQueueCount++;

            m_capsEventQueue.Enqueue(res);
            return(res);
        }
Ejemplo n.º 10
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
                {
                    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 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);
                    }

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

                // Maybe this should be some meaningful error packet
                return(null);
            }
Ejemplo n.º 11
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, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            try
            {
                m_log.Debug("[Caps]: ScriptTaskInventory Request in region: " + m_regionName);
                Hashtable            hash = (Hashtable)LLSD.LLSDDeserialize(Utils.StringToBytes(request));
                LLSDTaskScriptUpdate llsdUpdateRequest = new LLSDTaskScriptUpdate();
                LLSDHelpers.DeserialiseOSDMap(hash, llsdUpdateRequest);

                string capsBase     = "/CAPS/" + m_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_httpListener, m_dumpAssetsToFile);
                uploader.OnUpLoad += TaskScriptUpdated;

                m_httpListener.AddStreamHandler(new BinaryStreamHandler("POST", capsBase + uploaderPath, uploader.uploaderCaps));

                string protocol = "http://";

                if (m_httpListener.UseSSL)
                {
                    protocol = "https://";
                }

                string uploaderURL = protocol + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + capsBase + uploaderPath;

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

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

            return(null);
        }
Ejemplo n.º 12
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)
            {
                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);

                handlerUpLoad = OnUpLoad;

                if (handlerUpLoad != null)
                {
                    handlerUpLoad(newAssetID, data);
                }

                return(res);
            }
Ejemplo n.º 13
0
        public override byte[] Handle(string path, Stream request,
                                      OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            //Encoding encoding = Util.UTF8;
            //StreamReader streamReader = new StreamReader(request, false);

            //string requestBody = streamReader.ReadToEnd();
            //streamReader.Close();

            // OpenMetaverse.StructuredData.OSDMap hash = (OpenMetaverse.StructuredData.OSDMap)
            //    OpenMetaverse.StructuredData.LLSDParser.DeserializeXml(new XmlTextReader(request));

            Hashtable hash        = (Hashtable)LLSD.LLSDDeserialize(request);
            TRequest  llsdRequest = new TRequest();

            LLSDHelpers.DeserialiseOSDMap(hash, llsdRequest);

            TResponse response = m_method(llsdRequest);

            Encoding encoding = new UTF8Encoding(false);

            return(encoding.GetBytes(LLSDHelpers.SerialiseLLSDReply(response)));
        }
Ejemplo n.º 14
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)
            {
                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);
            }
Ejemplo n.º 15
0
        public string UploadBakedTexture(string request, string path, string param, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            try
            {
                m_log.Debug("[Caps]: UploadBakedTexture Request in region: " + m_regionName);

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

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

                m_httpListener.AddStreamHandler(new BinaryStreamHandler("POST", capsBase + uploaderPath, uploader.uploaderCaps));

                string protocol = "http://";

                if (m_httpListener.UseSSL)
                {
                    protocol = "https://";
                }

                string uploaderURL = protocol + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + capsBase + uploaderPath;

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

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

            return(null);
        }
Ejemplo n.º 16
0
        public string FetchInventoryDescendentsRequest(string request, string path, string param, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            // 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 pe)
            {
                m_log.Error("[Agent Inventory]: Fetch error: " + pe.Message);
                m_log.Error("Request: " + request.ToString());
            }

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

            string response = "";

            lock (m_fetchLock)
            {
                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("[Caps]: 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>";
                }
            }

            return(response);
        }