/// <summary> /// Returns DavLocationFolder folder if path corresponds to [DavLocation]. /// </summary> /// <param name="context">Instance of <see cref="DavContext"/></param> /// <param name="path">Encoded path relative to WebDAV root.</param> /// <returns>DavLocationFolder instance or null if physical folder not found in file system.</returns> public static DavLocationFolder GetDavLocationFolder(DavContext context, string path) { string davPath = DavLocationFolderPath; if (!path.Equals(davPath.Trim(new[] { '/' }), StringComparison.OrdinalIgnoreCase)) { return(null); } string folderPath = context.MapPath(davPath).TrimEnd(System.IO.Path.DirectorySeparatorChar); DirectoryInfo folder = new DirectoryInfo(folderPath); if (!folder.Exists) { throw new Exception(string.Format("Can not find folder that corresponds to '{0}' ([DavLocation] folder) in file system.", davPath)); } return(new DavLocationFolder(folder, context, davPath)); }
/// <summary> /// Returns file that corresponds to path. /// </summary> /// <param name="context">WebDAV Context.</param> /// <param name="path">Encoded path relative to WebDAV root folder.</param> /// <returns>File instance or null if physical file is not found in file system.</returns> public static async Task <DavFile> GetFileAsync(DavContext context, string path) { string filePath = context.MapPath(path); FileInfo file = new FileInfo(filePath); // This code blocks vulnerability when "%20" folder can be injected into path and file.Exists returns 'true'. if (!file.Exists || string.Compare(file.FullName.TrimEnd(System.IO.Path.DirectorySeparatorChar), filePath, StringComparison.OrdinalIgnoreCase) != 0) { return(null); } DavFile davFile = new DavFile(file, context, path); if (await file.HasExtendedAttributeAsync("SerialNumber")) { davFile.serialNumber = await file.GetExtendedAttributeAsync <int?>("SerialNumber") ?? 0; } return(davFile); }
/// <summary> /// Creates initial calendars for user as well as inbox and outbox folders. /// </summary> internal static async Task CreateCalendarFoldersAsync(DavContext context) { string physicalRepositoryPath = context.RepositoryPath; // Get path to user folder /calendars/[user_name]/ and check if it exists. string calendarsUserFolder = string.Format("{0}{1}", CalendarsRootFolder.CalendarsRootFolderPath.Replace('/', Path.DirectorySeparatorChar), context.UserName); string pathCalendarsUserFolder = Path.Combine(physicalRepositoryPath, calendarsUserFolder.TrimStart(Path.DirectorySeparatorChar)); if (!Directory.Exists(pathCalendarsUserFolder)) { Directory.CreateDirectory(pathCalendarsUserFolder); // Create user calendars, such as /calendars/[user_name]/Calendar/. string pathCalendar = Path.Combine(pathCalendarsUserFolder, "Calendar1"); Directory.CreateDirectory(pathCalendar); pathCalendar = Path.Combine(pathCalendarsUserFolder, "Home1"); Directory.CreateDirectory(pathCalendar); pathCalendar = Path.Combine(pathCalendarsUserFolder, "Work1"); Directory.CreateDirectory(pathCalendar); } }
/// <summary> /// Initializes a new instance of this class. /// </summary> /// <param name="file">Corresponding file in the file system.</param> /// <param name="context">WebDAV Context.</param> /// <param name="path">Encoded path relative to WebDAV root folder.</param> protected DavFile(FileInfo file, DavContext context, string path) : base(file, context, path) { this.fileInfo = file; }
/// <summary> /// Initializes a new instance of this class. /// </summary> /// <param name="directory">Corresponding folder in the file system.</param> /// <param name="context">WebDAV Context.</param> /// <param name="path">Encoded path relative to WebDAV root folder.</param> protected DavFolder(DirectoryInfo directory, DavContext context, string path) : base(directory, context, path.TrimEnd('/') + "/") { dirInfo = directory; }
/// <summary> /// Initializes a new instance of this class. /// </summary> /// <param name="directory">Instance of <see cref="DirectoryInfo"/> class with information about the folder in file system.</param> /// <param name="context">Instance of <see cref="DavContext"/>.</param> /// <param name="path">Relative to WebDAV root folder path.</param> private DavLocationFolder(DirectoryInfo directory, DavContext context, string path) : base(directory, context, path) { }
public Discovery(DavContext context) { this.context = context; }
protected LogicalFolder(DavContext context, string name, string path) : base(context) { this.Context = context; this.Name = name; this.Path = path; }
/// <summary> /// Initializes a new instance of this class. /// </summary> /// <param name="fileSystemInfo">Corresponding file or folder in the file system.</param> /// <param name="context">WebDAV Context.</param> /// <param name="path">Encoded path relative to WebDAV root folder.</param> protected DavHierarchyItem(FileSystemInfo fileSystemInfo, DavContext context, string path) : base(context) { this.fileSystemInfo = fileSystemInfo; this.context = context; this.Path = path; }