using System.Collections.Generic;
using System.Security.Principal;
using System.Threading;
using WebDAVSharp.Server.Adapters;
using WebDAVSharp.Server.Exceptions;
using WebDAVSharp.Server.Stores;
namespace WebDAVSharp.Server.MethodHandlers
{
///
/// This class implements the PUT HTTP method for WebDAV#.
///
internal class WebDavUnlockMethodHandler : WebDavMethodHandlerBase
{
#region Properties
///
/// Gets the collection of the names of the HTTP methods handled by this instance.
///
///
/// The names.
///
public override IEnumerable Names => new[]
{
"UNLOCK"
};
#endregion
#region Functions
///
/// Processes the request.
///
/// The through which the request came in from the client.
///
/// The
/// object containing both the request and response
/// objects to use.
///
/// The that the is hosting.
public override void ProcessRequest(WebDavServer server, IHttpListenerContext context, IWebDavStore store)
{
/***************************************************************************************************
* Send the response
***************************************************************************************************/
IWebDavStoreCollection collection = GetParentCollection(server, store, context.Request.Url);
// Get the item from the collection
IWebDavStoreItem storeItem = GetItemFromCollection(collection, context.Request.Url);
if (storeItem == null)
throw new WebDavNotFoundException(context.Request.Url.ToString());
var userIdentity = (WindowsIdentity) Thread.GetData(Thread.GetNamedDataSlot(WebDavServer.HttpUser));
context.SendSimpleResponse(store.LockSystem.UnLock(storeItem, context.Request.GetLockTokenHeader(), userIdentity.Name));
}
#endregion
}
}