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)); }
/// <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; }
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); }
/// <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 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); }
/// <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); }
/// <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); }
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); }
/// <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>"); } }
/// <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; } }
/// <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>"); } }
/// <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); }
/// <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); }
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"; }
/// <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); }
/// <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)); }
/// 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>"); } }
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); }
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)); }
/// <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; }
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); // } }
/// <summary> /// Called by the CopyInventoryFromNotecard caps handler. /// </summary> /// <param name="request"></param> /// <param name="path"></param> /// <param name="param"></param> public string CopyInventoryFromNotecard(string request, string path, string param, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { Hashtable response = new Hashtable(); response["int_response_code"] = 404; response["content_type"] = "text/plain"; response["keepalive"] = false; response["str_response_string"] = ""; try { OSDMap content = (OSDMap)OSDParser.DeserializeLLSDXml(request); UUID objectID = content["object-id"].AsUUID(); UUID notecardID = content["notecard-id"].AsUUID(); UUID folderID = content["folder-id"].AsUUID(); UUID itemID = content["item-id"].AsUUID(); // m_log.InfoFormat("[CAPS]: CopyInventoryFromNotecard, FolderID:{0}, ItemID:{1}, NotecardID:{2}, ObjectID:{3}", folderID, itemID, notecardID, objectID); if (objectID != UUID.Zero) { SceneObjectPart part = m_Scene.GetSceneObjectPart(objectID); if (part != null) { // TaskInventoryItem taskItem = part.Inventory.GetInventoryItem(notecardID); if (!m_Scene.Permissions.CanCopyObjectInventory(notecardID, objectID, m_HostCapsObj.AgentID)) { return(LLSDHelpers.SerialiseLLSDReply(response)); } } } InventoryItemBase item = null; InventoryItemBase copyItem = null; IClientAPI client = null; m_Scene.TryGetClient(m_HostCapsObj.AgentID, out client); item = m_Scene.InventoryService.GetItem(new InventoryItemBase(itemID)); if (item != null) { copyItem = m_Scene.GiveInventoryItem(m_HostCapsObj.AgentID, item.Owner, itemID, folderID); if (copyItem != null && client != null) { m_log.InfoFormat("[CAPS]: CopyInventoryFromNotecard, ItemID:{0}, FolderID:{1}", copyItem.ID, copyItem.Folder); client.SendBulkUpdateInventory(copyItem); } } else { m_log.ErrorFormat("[CAPS]: CopyInventoryFromNotecard - Failed to retrieve item {0} from notecard {1}", itemID, notecardID); if (client != null) { client.SendAlertMessage("Failed to retrieve item"); } } } catch (Exception e) { m_log.ErrorFormat("[CAPS]: CopyInventoryFromNotecard : {0}", e.ToString()); } response["int_response_code"] = 200; return(LLSDHelpers.SerialiseLLSDReply(response)); }
/// Callback for a client request for ParcelVoiceInfo public string ParcelVoiceInfoRequest(Scene scene, string request, string path, string param, UUID agentID) { m_log.Debug("[MurmurVoice] Calling ParcelVoiceInfoRequest..."); try { ScenePresence avatar = scene.GetScenePresence(agentID); string channel_uri = String.Empty; if (null == scene.LandChannel) { throw new Exception(String.Format("region \"{0}\": avatar \"{1}\": land data not yet available", scene.RegionInfo.RegionName, avatar.Name)); } // 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); if (null == land) { throw new Exception(String.Format("region \"{0}\": avatar \"{1}\": land data not yet available", scene.RegionInfo.RegionName, avatar.Name)); } m_log.DebugFormat("[MurmurVoice] region \"{0}\": Parcel \"{1}\" ({2}): avatar \"{3}\": request: {4}, path: {5}, param: {6}", scene.RegionInfo.RegionName, land.Name, land.LocalID, avatar.Name, request, path, param); if (((land.Flags & (uint)ParcelFlags.AllowVoiceChat) > 0) && scene.RegionInfo.EstateSettings.AllowVoice) { ServerManager manager = GetServerManager(scene); Agent agent = manager.Agent.GetOrCreate(agentID, scene); if (agent == null) { m_log.ErrorFormat("[MurmurVoice] Agent not connected {0}", agentID); return("<llsd><undef /></llsd>"); } agent.channel = manager.Channel.GetOrCreate(ChannelName(scene, land)); // Wait for session connect int retry = 0; while (agent.session < 0) { if (++retry > 50) { m_log.ErrorFormat("[MurmurVoice] Connecting failed {0} (uid {1}) identified by {2}", agent.uuid.ToString(), agent.userid, agent.pass); return("<llsd><undef /></llsd>"); } Thread.Sleep(200); } // Host/port pair for voice server channel_uri = String.Format("{0}:{1}", m_murmurd_host, m_murmurd_port); Murmur.User state = manager.Server.getState(agent.session); GetServerCallback(scene).AddUserToChan(state, agent.channel); m_log.DebugFormat("[MurmurVoice] {0}", channel_uri); } else { m_log.DebugFormat("[MurmurVoice] Voice not enabled."); } Hashtable creds = new Hashtable(); creds["channel_uri"] = channel_uri; LLSDParcelVoiceInfoResponse parcelVoiceInfo = new LLSDParcelVoiceInfoResponse(scene.RegionInfo.RegionName, land.LocalID, creds); string r = LLSDHelpers.SerialiseLLSDReply(parcelVoiceInfo); m_log.DebugFormat("[MurmurVoice] Parcel: {0}", r); return(r); } catch (Exception e) { m_log.ErrorFormat("[MurmurVoice] Exception: " + e.ToString()); return("<llsd><undef /></llsd>"); } }
private string FetchInventoryDescendentsRequest(ArrayList foldersrequested, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { //m_log.DebugFormat("[WEB FETCH INV DESC HANDLER]: Received request for {0} folders", foldersrequested.Count); StringBuilder tmpresponse = new StringBuilder(1024); StringBuilder tmpbadfolders = new StringBuilder(1024); 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) { tmpbadfolders.Append("<map><key>folder_id</key><uuid>"); tmpbadfolders.Append(llsdRequest.folder_id.ToString()); tmpbadfolders.Append("</uuid><key>error</key><string>Unknown</string></map>"); } else { inventoryitemstr = LLSDHelpers.SerialiseLLSDReply(reply); inventoryitemstr = inventoryitemstr.Replace("<llsd><map><key>folders</key><array>", ""); inventoryitemstr = inventoryitemstr.Replace("</array></map></llsd>", ""); } tmpresponse.Append(inventoryitemstr); } StringBuilder lastresponse = new StringBuilder(1024); lastresponse.Append("<llsd>"); if (tmpresponse.Length > 0) { lastresponse.Append("<map><key>folders</key><array>"); lastresponse.Append(tmpresponse.ToString()); lastresponse.Append("</array></map>"); } else { lastresponse.Append("<map><key>folders</key><array /></map>"); } if (tmpbadfolders.Length > 0) { lastresponse.Append("<map><key>bad_folders</key><array>"); lastresponse.Append(tmpbadfolders.ToString()); lastresponse.Append("</array></map>"); } lastresponse.Append("</llsd>"); return(lastresponse.ToString()); }
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); // } }
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)); }
public string FetchInventoryDescendentsRequest(string request, string path, string param, IOSHttpRequest httpRequest, IOSHttpResponse 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 e) { m_log.ErrorFormat("[WEB FETCH INV DESC HANDLER]: Fetch error: {0}{1}" + e.Message, e.StackTrace); m_log.Error("Request: " + request); throw; } ArrayList foldersrequested = (ArrayList)hash["folders"]; 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>"; } } 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); }
/// <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()); } }