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);
            TRequest  llsdRequest = new TRequest();

            LLSDHelpers.DeserialiseOSDMap(hash, llsdRequest);

            TResponse response = m_method(llsdRequest);

            return(Util.UTF8NoBomEncoding.GetBytes(LLSDHelpers.SerialiseLLSDReply(response)));
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        private static void SerializeOSDType(XmlTextWriter writer, object obj)
        {
            Type myType = obj.GetType();

            LLSDType[] llsdattributes = (LLSDType[])myType.GetCustomAttributes(typeof(LLSDType), false);

            if (llsdattributes.Length > 0)
            {
                switch (llsdattributes[0].ObjectType)
                {
                case "MAP":
                    writer.WriteStartElement(String.Empty, "map", String.Empty);
                    FieldInfo[] fields = myType.GetFields();

                    for (int i = 0; i < fields.Length; i++)
                    {
                        if (fields[i] != null && fields[i].GetValue(obj) != null)
                        {
                            object     fieldValue      = fields[i].GetValue(obj);
                            LLSDType[] fieldAttributes = (LLSDType[])fieldValue.GetType().GetCustomAttributes(typeof(LLSDType), false);

                            if (fieldAttributes.Length > 0)
                            {
                                writer.WriteStartElement(String.Empty, "key", String.Empty);
                                string fieldName = fields[i].Name;
                                fieldName = fieldName.Replace("___", "-");
                                writer.WriteString(fieldName);
                                writer.WriteEndElement();
                                SerializeOSDType(writer, fieldValue);
                            }
                            else
                            {
                                writer.WriteStartElement(String.Empty, "key", String.Empty);
                                string fieldName = fields[i].Name;
                                fieldName = fieldName.Replace("___", "-");
                                writer.WriteString(fieldName);
                                writer.WriteEndElement();
                                LLSD.LLSDWriteOne(writer, fieldValue);
                            }
                        }
                        else
                        {
                            // TODO from ADAM: There is a nullref being caused by fields[i] being null
                            // on some computers. Unsure what is causing this, but would appreciate
                            // if sdague could take a look at this.
                        }
                    }
                    writer.WriteEndElement();
                    break;

                case "ARRAY":
                    ArrayList a = (ArrayList)obj.GetType().GetField("Array").GetValue(obj);

                    if (a != null)
                    {
                        writer.WriteStartElement(String.Empty, "array", String.Empty);

                        foreach (object item in a)
                        {
                            SerializeOSDType(writer, item);
                        }

                        writer.WriteEndElement();
                    }
                    break;
                }
            }
            else
            {
                LLSD.LLSDWriteOne(writer, obj);
            }
        }
Exemplo n.º 4
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);
        }