public void FetchInventorySimpleRequest(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, OSDMap requestmap, ExpiringKey <UUID> BadRequests) { //m_log.DebugFormat("[FETCH INVENTORY HANDLER]: Received FetchInventory capability request {0}", request); if (BadRequests == null) { httpResponse.StatusCode = (int)HttpStatusCode.NotFound; return; } OSDArray itemsRequested = (OSDArray)requestmap["items"]; UUID[] itemIDs = new UUID[itemsRequested.Count]; int i = 0; foreach (OSDMap osdItemId in itemsRequested) { UUID id = osdItemId["item_id"].AsUUID(); if (!BadRequests.ContainsKey(id)) { itemIDs[i++] = id; } } InventoryItemBase[] items = null; try { // badrequests still not filled items = m_inventoryService.GetMultipleItems(m_agentID, itemIDs); } catch { } StringBuilder lsl = LLSDxmlEncode.Start(4096); LLSDxmlEncode.AddMap(lsl); LLSDxmlEncode.AddElem("agent_id", m_agentID, lsl); if (items == null || items.Length == 0) { LLSDxmlEncode.AddEmptyArray("items", lsl); } else { LLSDxmlEncode.AddArray("items", lsl); foreach (InventoryItemBase item in items) { if (item != null) { item.ToLLSDxml(lsl, 0xff); } } LLSDxmlEncode.AddEndArray(lsl); } LLSDxmlEncode.AddEndMap(lsl); httpResponse.RawBuffer = Util.UTF8.GetBytes(LLSDxmlEncode.End(lsl)); httpResponse.StatusCode = (int)HttpStatusCode.OK; }
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; } StringBuilder sb = osStringBuilderCache.Acquire(); sb.Append("[WEB FETCH INV DESC HANDLER]: Unable to fetch folders owned by "); sb.Append("Unknown"); sb.Append(" :"); int limit = 5; int count = 0; foreach (UUID bad in bad_folders) { if (BadRequests.ContainsKey(bad)) { continue; } sb.Append(" "); sb.Append(bad.ToString()); ++count; if (--limit < 0) { break; } } if (count > 0) { if (limit < 0) { sb.Append(" ..."); } m_log.Warn(osStringBuilderCache.GetStringAndRelease(sb)); } else { osStringBuilderCache.Release(sb); } sb = osStringBuilderCache.Acquire(); sb.Append("<llsd><map><key>folders</key><array /></map><map><key>bad_folders</key><array>"); foreach (UUID bad in bad_folders) { sb.Append("<map><key>folder_id</key><uuid>"); sb.Append(bad.ToString()); sb.Append("</uuid><key>error</key><string>Unknown</string></map>"); } sb.Append("</array></map></llsd>"); httpResponse.RawBuffer = Util.UTF8NBGetbytes(osStringBuilderCache.GetStringAndRelease(sb)); 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); StringBuilder lastresponse = new StringBuilder(mem); lastresponse.Append("<llsd>"); if (invcollSetCount > 0) { lastresponse.Append("<map><key>folders</key><array>"); int i = 0; InventoryCollection thiscoll; for (i = 0; i < invcollSetCount; i++) { thiscoll = invcollSet[i]; invcollSet[i] = null; LLSDxmlEncode.AddMap(lastresponse); LLSDxmlEncode.AddElem("agent_id", thiscoll.OwnerID, lastresponse); LLSDxmlEncode.AddElem("descendents", thiscoll.Descendents, lastresponse); LLSDxmlEncode.AddElem("folder_id", thiscoll.FolderID, lastresponse); if (thiscoll.Folders == null || thiscoll.Folders.Count == 0) { LLSDxmlEncode.AddEmptyArray("categories", lastresponse); } else { LLSDxmlEncode.AddArray("categories", lastresponse); foreach (InventoryFolderBase invFolder in thiscoll.Folders) { LLSDxmlEncode.AddMap(lastresponse); LLSDxmlEncode.AddElem("folder_id", invFolder.ID, lastresponse); LLSDxmlEncode.AddElem("parent_id", invFolder.ParentID, lastresponse); LLSDxmlEncode.AddElem("name", invFolder.Name, lastresponse); LLSDxmlEncode.AddElem("type", invFolder.Type, lastresponse); LLSDxmlEncode.AddElem("preferred_type", (int)-1, lastresponse); LLSDxmlEncode.AddElem("version", invFolder.Version, lastresponse); LLSDxmlEncode.AddEndMap(lastresponse); } LLSDxmlEncode.AddEndArray(lastresponse); } if (thiscoll.Items == null || thiscoll.Items.Count == 0) { LLSDxmlEncode.AddEmptyArray("items", lastresponse); } else { LLSDxmlEncode.AddArray("items", lastresponse); foreach (InventoryItemBase invItem in thiscoll.Items) { invItem.ToLLSDxml(lastresponse); } LLSDxmlEncode.AddEndArray(lastresponse); } LLSDxmlEncode.AddElem("owner_id", thiscoll.OwnerID, lastresponse); LLSDxmlEncode.AddElem("version", thiscoll.Version, lastresponse); LLSDxmlEncode.AddEndMap(lastresponse); invcollSet[i] = null; } lastresponse.Append("</array></map>"); thiscoll = null; } else { lastresponse.Append("<map><key>folders</key><array /></map>"); } if (bad_folders.Count > 0) { lastresponse.Append("<map><key>bad_folders</key><array>"); foreach (UUID bad in bad_folders) { BadRequests.Add(bad); lastresponse.Append("<map><key>folder_id</key><uuid>"); lastresponse.Append(bad.ToString()); lastresponse.Append("</uuid><key>error</key><string>Unknown</string></map>"); } lastresponse.Append("</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)); } lastresponse.Append("</llsd>"); httpResponse.RawBuffer = Util.UTF8NBGetbytes(lastresponse.ToString()); }