HttpStatusCode PutHandler(IHttpRequest request, string path, string username) { try { byte[] assetData = request.GetBody(); string[] pathParts = path.Split('/'); string parentPath = String.Empty; for (int i = 0; i < pathParts.Length - 1; i++) { parentPath += pathParts[i]; parentPath += "/"; } string contentType = request.Headers["Content-type"]; int assetType = -1; //unknown if (contentType != null && contentType != String.Empty) { m_log.DebugFormat("[WORLDINVENTORY]: Found content-type {0} for put request to {1}", contentType, path); assetType = MimeTypeConverter.GetAssetTypeFromMimeType(contentType); } else { //missing content type m_log.WarnFormat("[WORLDINVENTORY]: Could not find content-type from request {0} headers. Trying to parse from file extension", path); string[] fileParts = pathParts[pathParts.Length - 1].Split('.'); if (fileParts.Length > 1) { string fileExtension = fileParts[fileParts.Length - 1]; assetType = MimeTypeConverter.GetAssetTypeFromFileExtension(fileExtension); } contentType = MimeTypeConverter.GetContentType(assetType); } AssetBase asset = new AssetBase(UUID.Random(), pathParts[pathParts.Length - 1], (sbyte)assetType, m_scenes[0].RegionInfo.EstateSettings.EstateOwner.ToString()); asset.Local = false; if (m_autoconvertJpgToJ2k && assetType == (int)AssetType.ImageJPEG) { System.IO.MemoryStream ms = new System.IO.MemoryStream(assetData); System.Drawing.Bitmap bitmap = (System.Drawing.Bitmap)System.Drawing.Image.FromStream(ms); assetData = OpenMetaverse.Imaging.OpenJPEG.EncodeFromImage(bitmap, false); asset.Type = (int)AssetType.Texture; asset.Name = ReplaceFileExtension(asset.Name, "jp2"); } asset.Data = assetData; m_scenes[0].AssetService.Store(asset); AssetFolder oldAsset = m_assetFolderStrg.GetItem(parentPath, asset.Name); if (oldAsset != null) { m_log.InfoFormat("[WORLDINVENTORY]: Replacing old asset {0} with new", oldAsset.Name); if (!m_assetFolderStrg.RemoveItem(oldAsset)) { return HttpStatusCode.Conflict; } } m_assetFolderStrg.Save(new AssetFolderItem(parentPath, asset.Name, asset.FullID)); IWebDAVResource oldProp = m_propertyMngr.GetResource(path); if (oldProp == null) { WebDAVFile prop = new WebDAVFile(path, contentType, asset.Data.Length, asset.Metadata.CreationDate, asset.Metadata.CreationDate, DateTime.Now, false, false); prop.AddProperty(new WebDAVProperty("AssetID", "http://www.realxtend.org/", asset.FullID.ToString())); m_propertyMngr.SaveResource(prop); } else { WebDAVProperty assetIdProp = null; foreach (WebDAVProperty prop in oldProp.CustomProperties) { if (prop.Name == "AssetID" && prop.Namespace == "http://www.realxtend.org/") assetIdProp = prop; } if (assetIdProp != null) oldProp.CustomProperties.Remove(assetIdProp); oldProp.AddProperty(new WebDAVProperty("AssetID", "http://www.realxtend.org/", asset.FullID.ToString())); m_propertyMngr.SaveResource(oldProp); } return HttpStatusCode.Created; } catch (Exception e) { m_log.ErrorFormat("[WORLDINVENTORY]: Failed to put resource to {0}. Exception {1} occurred.", path, e.ToString()); return HttpStatusCode.InternalServerError; } }
IList<IWebDAVResource> PropFindHandler(string username, string path, DepthHeader depth) { string[] pathParts = path.Split('/'); if (pathParts.Length >= 2 && pathParts[1] == "inventory") { List<IWebDAVResource> resources = new List<IWebDAVResource>(); if (depth == DepthHeader.Zero) { IWebDAVResource res = m_propertyMngr.GetResource(path); resources.Add(res); return resources; } else if (depth == DepthHeader.One) { IWebDAVResource res = m_propertyMngr.GetResource(path); resources.Add(res); IList<AssetFolder> folders = m_assetFolderStrg.GetSubItems(path); foreach (AssetFolder folder in folders) { if (!folder.ParentPath.EndsWith("/")) folder.ParentPath += "/"; string resourcePath = folder.ParentPath + folder.Name; if (!(folder is AssetFolderItem)) resourcePath += "/"; IWebDAVResource folderProps = m_propertyMngr.GetResource(resourcePath); if (folderProps != null) { resources.Add(folderProps); } else { //create new props, save them and add them to response if (folder is AssetFolderItem) { AssetFolderItem item = (AssetFolderItem)folder; AssetBase asset = m_scenes[0].AssetService.Get(item.AssetID.ToString()); string contentType = MimeTypeConverter.GetContentType((int)asset.Type); WebDAVFile file = new WebDAVFile(resourcePath, contentType, asset.Data.Length, asset.Metadata.CreationDate, DateTime.Now, DateTime.Now, false, false); //add asset id to custom properties file.AddProperty(new WebDAVProperty("AssetID", "http://www.realxtend.org/", item.AssetID.ToString())); m_propertyMngr.SaveResource(file); resources.Add(file); } else { WebDAVFolder resource = new WebDAVFolder(resourcePath, DateTime.Now, DateTime.Now, DateTime.Now, false); m_propertyMngr.SaveResource(resource); resources.Add(resource); } } } return resources; } else if (depth == DepthHeader.Infinity) { IWebDAVResource res = m_propertyMngr.GetResource(path); resources.Add(res); IList<AssetFolder> folders = m_assetFolderStrg.GetSubItems(path); //get subitems until found all foreach (AssetFolder folder in folders) { if (!folder.ParentPath.EndsWith("/")) folder.ParentPath += "/"; string resourcePath = folder.ParentPath + folder.Name; if (!(folder is AssetFolderItem)) resourcePath += "/"; IWebDAVResource folderProps = m_propertyMngr.GetResource(resourcePath); if (folderProps != null) { resources.Add(folderProps); } else { //create new props, save them and add them to response if (folder is AssetFolderItem) { AssetFolderItem item = (AssetFolderItem)folder; AssetBase asset = m_scenes[0].AssetService.Get(item.AssetID.ToString()); string contentType = MimeTypeConverter.GetContentType((int)asset.Type); WebDAVFile file = new WebDAVFile(resourcePath, contentType, asset.Data.Length, asset.Metadata.CreationDate, DateTime.Now, DateTime.Now, false, false); //add asset id to custom properties file.AddProperty(new WebDAVProperty("AssetID", "http://www.realxtend.org/", item.AssetID.ToString())); m_propertyMngr.SaveResource(file); resources.Add(file); } else { WebDAVFolder resource = new WebDAVFolder(resourcePath, DateTime.Now, DateTime.Now, DateTime.Now, false); m_propertyMngr.SaveResource(resource); resources.Add(resource); } } } return resources; } } return null; }