예제 #1
0
        public void RestGetGridInfoMethod(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            httpResponse.KeepAlive = false;
            if (httpRequest.HttpMethod != "GET")
            {
                httpResponse.StatusCode = (int)HttpStatusCode.MethodNotAllowed;
                return;
            }

            osUTF8 osb = OSUTF8Cached.Acquire();

            osb.AppendASCII("<gridinfo>");
            foreach (string k in _info.Keys)
            {
                osb.AppendASCII('<');
                osb.AppendASCII(k);
                osb.AppendASCII('>');
                osb.AppendASCII(SecurityElement.Escape(_info[k].ToString()));
                osb.AppendASCII("</");
                osb.AppendASCII(k);
                osb.AppendASCII('>');
            }
            osb.AppendASCII("</gridinfo>");
            httpResponse.RawBuffer = OSUTF8Cached.GetArrayAndRelease(osb);
        }
예제 #2
0
        public static string SerializeJsonString(OSD osd, bool preserveDefaults)
        {
            osUTF8 sb = OSUTF8Cached.Acquire();

            SerializeJson(osd, sb, preserveDefaults);
            return(OSUTF8Cached.GetStringAndRelease(sb));
        }
예제 #3
0
        public static byte[] SerializeJsonToBytes(OSD osd)
        {
            osUTF8 sb = OSUTF8Cached.Acquire();

            SerializeJson(osd, sb, false);
            return(OSUTF8Cached.GetArrayAndRelease(sb));
        }
예제 #4
0
        public static string SerializeJsonString(OSD osd)
        {
            osUTF8 sb = OSUTF8Cached.Acquire();

            SerializeJson(osd, sb, false);
            return(OSUTF8Cached.GetStringAndRelease(sb));
        }
        public static byte[] SerializeInnerLLSDXmlToBytes(OSD data)
        {
            osUTF8 tmp = OSUTF8Cached.Acquire();

            SerializeLLSDXmlElement(tmp, data, false);

            return(OSUTF8Cached.GetArrayAndRelease(tmp));
        }
        public static byte[] SerializeLLSDXmlToBytes(OSD data)
        {
            osUTF8 tmp = OSUTF8Cached.Acquire();

            tmp.Append(osUTF8Const.XMLllsdStart);
            SerializeLLSDXmlElement(tmp, data, false);
            tmp.Append(osUTF8Const.XMLllsdEnd);

            return(OSUTF8Cached.GetArrayAndRelease(tmp));
        }
예제 #7
0
        public osUTF8 StartEvent(string eventName, int cap)
        {
            osUTF8 sb = OSUTF8Cached.Acquire(cap);

            LLSDxmlEncode2.AddMap(sb);
            LLSDxmlEncode2.AddElem("message", eventName, sb);
            LLSDxmlEncode2.AddMap("body", sb);

            return(sb);
        }
예제 #8
0
        public static osUTF8 Start(int size = OSUTF8Cached.MAXDATASIZE, bool addxmlversion = false)
        {
            osUTF8 sb = OSUTF8Cached.Acquire(size);

            if (addxmlversion)
            {
                sb.Append(osUTF8Const.XMLformalHeaderllsdstart); // legacy llsd xml name still valid
            }
            else
            {
                sb.Append(osUTF8Const.XMLllsdStart);
            }
            return(sb);
        }
        public static byte[] SerializeLLSDXmlToBytes(OSD data, bool formal = false)
        {
            osUTF8 tmp = OSUTF8Cached.Acquire();

            if (formal)
            {
                tmp.Append(osUTF8Const.XMLformalHeaderllsdstart);
            }
            else
            {
                tmp.Append(osUTF8Const.XMLllsdStart);
            }
            SerializeLLSDXmlElement(tmp, data, formal);
            tmp.Append(osUTF8Const.XMLllsdEnd);

            return(OSUTF8Cached.GetArrayAndRelease(tmp));
        }
예제 #10
0
        public void FetchInventoryDescendentsRequest(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, ExpiringKey <UUID> BadRequests)
        {
            //m_log.DebugFormat("[XXX]: FetchInventoryDescendentsRequest in {0}, {1}", (m_Scene == null) ? "none" : m_Scene.Name, request);

            List <LLSDFetchInventoryDescendents> folders = null;
            List <UUID> bad_folders = new List <UUID>();

            try
            {
                OSDArray foldersrequested = null;
                OSD      tmp = OSDParser.DeserializeLLSDXml(httpRequest.InputStream);
                httpRequest.InputStream.Dispose();

                OSDMap map = (OSDMap)tmp;
                if (map.TryGetValue("folders", out tmp) && tmp is OSDArray)
                {
                    foldersrequested = tmp as OSDArray;
                }

                if (foldersrequested == null || foldersrequested.Count == 0)
                {
                    httpResponse.RawBuffer = EmptyResponse;
                    return;
                }

                folders = new List <LLSDFetchInventoryDescendents>(foldersrequested.Count);
                for (int i = 0; i < foldersrequested.Count; i++)
                {
                    OSDMap mfolder = foldersrequested[i] as OSDMap;
                    UUID   id      = mfolder["folder_id"].AsUUID();
                    if (BadRequests.ContainsKey(id))
                    {
                        bad_folders.Add(id);
                    }
                    else
                    {
                        LLSDFetchInventoryDescendents llsdRequest = new LLSDFetchInventoryDescendents();
                        try
                        {
                            llsdRequest.folder_id     = id;
                            llsdRequest.owner_id      = mfolder["owner_id"].AsUUID();
                            llsdRequest.sort_order    = mfolder["sort_order"].AsInteger();
                            llsdRequest.fetch_folders = mfolder["fetch_folders"].AsBoolean();
                            llsdRequest.fetch_items   = mfolder["fetch_items"].AsBoolean();
                        }
                        catch (Exception e)
                        {
                            m_log.Debug("[WEB FETCH INV DESC HANDLER]: caught exception doing OSD deserialize" + e.Message);
                            continue;
                        }
                        folders.Add(llsdRequest);
                    }
                }
                foldersrequested = null;
                map.Clear();
                map = null;
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[FETCH INV DESC]: fail parsing request: {0}", e.Message);
                httpResponse.RawBuffer = EmptyResponse;
                return;
            }

            if (folders == null || folders.Count == 0)
            {
                if (bad_folders.Count == 0)
                {
                    httpResponse.RawBuffer = EmptyResponse;
                    return;
                }

                osUTF8 osu = OSUTF8Cached.Acquire();
                osu.AppendASCII("[WEB FETCH INV DESC HANDLER]: Unable to fetch folders owned by Unknown user:"******" ...");
                    }
                    m_log.Warn(osu.ToString());
                }

                osu.Clear();

                osu.AppendASCII("<llsd><map><key>folders</key><array /></map><map><key>bad_folders</key><array>");
                foreach (UUID bad in bad_folders)
                {
                    osu.AppendASCII("<map><key>folder_id</key><uuid>");
                    osu.AppendASCII(bad.ToString());
                    osu.AppendASCII("</uuid><key>error</key><string>Unknown</string></map>");
                }
                osu.AppendASCII("</array></map></llsd>");
                httpResponse.RawBuffer = OSUTF8Cached.GetArrayAndRelease(osu);
                return;
            }

            int total_folders = 0;
            int total_items   = 0;

            UUID requester = folders[0].owner_id;

            List <InventoryCollection> invcollSet = Fetch(folders, bad_folders, ref total_folders, ref total_items);
            //m_log.DebugFormat("[XXX]: Got {0} folders from a request of {1}", invcollSet.Count, folders.Count);

            int invcollSetCount = 0;

            if (invcollSet != null)
            {
                invcollSetCount = invcollSet.Count;
            }

            int mem = 8192 + ((256 * invcollSetCount +
                               384 * total_folders +
                               1024 * total_items +
                               128 * bad_folders.Count) & 0x7ffff000);

            osUTF8 lastresponse = LLSDxmlEncode2.Start(mem);

            if (invcollSetCount > 0)
            {
                lastresponse.AppendASCII("<map><key>folders</key><array>");
                int i = 0;
                InventoryCollection thiscoll;
                for (i = 0; i < invcollSetCount; i++)
                {
                    thiscoll      = invcollSet[i];
                    invcollSet[i] = null;

                    LLSDxmlEncode2.AddMap(lastresponse);
                    LLSDxmlEncode2.AddElem_agent_id(thiscoll.OwnerID, lastresponse);
                    LLSDxmlEncode2.AddElem("descendents", thiscoll.Descendents, lastresponse);
                    LLSDxmlEncode2.AddElem_folder_id(thiscoll.FolderID, lastresponse);

                    if (thiscoll.Folders == null || thiscoll.Folders.Count == 0)
                    {
                        LLSDxmlEncode2.AddEmptyArray("categories", lastresponse);
                    }
                    else
                    {
                        LLSDxmlEncode2.AddArray("categories", lastresponse);
                        foreach (InventoryFolderBase invFolder in thiscoll.Folders)
                        {
                            LLSDxmlEncode2.AddMap(lastresponse);

                            LLSDxmlEncode2.AddElem_folder_id(invFolder.ID, lastresponse);
                            LLSDxmlEncode2.AddElem_parent_id(invFolder.ParentID, lastresponse);
                            LLSDxmlEncode2.AddElem_name(invFolder.Name, lastresponse);
                            LLSDxmlEncode2.AddElem("type", invFolder.Type, lastresponse);
                            LLSDxmlEncode2.AddElem("preferred_type", (int)-1, lastresponse);
                            LLSDxmlEncode2.AddElem("version", invFolder.Version, lastresponse);

                            LLSDxmlEncode2.AddEndMap(lastresponse);
                        }
                        LLSDxmlEncode2.AddEndArray(lastresponse);
                    }

                    if (thiscoll.Items == null || thiscoll.Items.Count == 0)
                    {
                        LLSDxmlEncode2.AddEmptyArray("items", lastresponse);
                    }
                    else
                    {
                        LLSDxmlEncode2.AddArray("items", lastresponse);
                        foreach (InventoryItemBase invItem in thiscoll.Items)
                        {
                            invItem.ToLLSDxml(lastresponse);
                        }

                        LLSDxmlEncode2.AddEndArray(lastresponse);
                    }

                    LLSDxmlEncode2.AddElem_owner_id(thiscoll.OwnerID, lastresponse);
                    LLSDxmlEncode2.AddElem("version", thiscoll.Version, lastresponse);

                    LLSDxmlEncode2.AddEndMap(lastresponse);
                    invcollSet[i] = null;
                }
                LLSDxmlEncode2.AddEndArrayAndMap(lastresponse);
                thiscoll = null;
            }
            else
            {
                lastresponse.AppendASCII("<map><key>folders</key><array /></map>");
            }

            if (bad_folders.Count > 0)
            {
                lastresponse.AppendASCII("<map><key>bad_folders</key><array>");
                foreach (UUID bad in bad_folders)
                {
                    BadRequests.Add(bad);
                    lastresponse.AppendASCII("<map><key>folder_id</key><uuid>");
                    lastresponse.AppendASCII(bad.ToString());
                    lastresponse.AppendASCII("</uuid><key>error</key><string>Unknown</string></map>");
                }
                lastresponse.AppendASCII("</array></map>");

                StringBuilder sb = osStringBuilderCache.Acquire();
                sb.Append("[WEB FETCH INV DESC HANDLER]: Unable to fetch folders owned by ");
                sb.Append(requester.ToString());
                sb.Append(" :");
                int limit = 9;
                foreach (UUID bad in bad_folders)
                {
                    sb.Append(" ");
                    sb.Append(bad.ToString());
                    if (--limit < 0)
                    {
                        break;
                    }
                }
                if (limit < 0)
                {
                    sb.Append(" ...");
                }
                m_log.Warn(osStringBuilderCache.GetStringAndRelease(sb));
            }

            httpResponse.RawBuffer = LLSDxmlEncode2.EndToBytes(lastresponse);
        }