WebDAVUnlockMethodHandler.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.Collections.Generic;
  2. using System.Security.Principal;
  3. using System.Threading;
  4. using WebDAVSharp.Server.Adapters;
  5. using WebDAVSharp.Server.Exceptions;
  6. using WebDAVSharp.Server.Stores;
  7. namespace WebDAVSharp.Server.MethodHandlers
  8. {
  9. /// <summary>
  10. /// This class implements the <c>PUT</c> HTTP method for WebDAV#.
  11. /// </summary>
  12. internal class WebDavUnlockMethodHandler : WebDavMethodHandlerBase
  13. {
  14. #region Properties
  15. /// <summary>
  16. /// Gets the collection of the names of the HTTP methods handled by this instance.
  17. /// </summary>
  18. /// <value>
  19. /// The names.
  20. /// </value>
  21. public override IEnumerable<string> Names => new[]
  22. {
  23. "UNLOCK"
  24. };
  25. #endregion
  26. #region Functions
  27. /// <summary>
  28. /// Processes the request.
  29. /// </summary>
  30. /// <param name="server">The <see cref="WebDavServer" /> through which the request came in from the client.</param>
  31. /// <param name="context">
  32. /// The
  33. /// <see cref="IHttpListenerContext" /> object containing both the request and response
  34. /// objects to use.
  35. /// </param>
  36. /// <param name="store">The <see cref="IWebDavStore" /> that the <see cref="WebDavServer" /> is hosting.</param>
  37. public override void ProcessRequest(WebDavServer server, IHttpListenerContext context, IWebDavStore store)
  38. {
  39. /***************************************************************************************************
  40. * Send the response
  41. ***************************************************************************************************/
  42. IWebDavStoreCollection collection = GetParentCollection(server, store, context.Request.Url);
  43. // Get the item from the collection
  44. IWebDavStoreItem storeItem = GetItemFromCollection(collection, context.Request.Url);
  45. if (storeItem == null)
  46. throw new WebDavNotFoundException(context.Request.Url.ToString());
  47. var userIdentity = (WindowsIdentity) Thread.GetData(Thread.GetNamedDataSlot(WebDavServer.HttpUser));
  48. context.SendSimpleResponse(store.LockSystem.UnLock(storeItem, context.Request.GetLockTokenHeader(), userIdentity.Name));
  49. }
  50. #endregion
  51. }
  52. }