GCDWebDAVServer.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. Copyright (c) 2012-2015, Pierre-Olivier Latour
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. * The name of Pierre-Olivier Latour may not be used to endorse
  12. or promote products derived from this software without specific
  13. prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY
  18. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #import "GCDWebServer.h"
  26. @class GCDWebDAVServer;
  27. /**
  28. * Delegate methods for GCDWebDAVServer.
  29. *
  30. * @warning These methods are always called on the main thread in a serialized way.
  31. */
  32. @protocol GCDWebDAVServerDelegate <GCDWebServerDelegate>
  33. @optional
  34. /**
  35. * This method is called whenever a file has been downloaded.
  36. */
  37. - (void)davServer:(GCDWebDAVServer*)server didDownloadFileAtPath:(NSString*)path;
  38. /**
  39. * This method is called whenever a file has been uploaded.
  40. */
  41. - (void)davServer:(GCDWebDAVServer*)server didUploadFileAtPath:(NSString*)path;
  42. /**
  43. * This method is called whenever a file or directory has been moved.
  44. */
  45. - (void)davServer:(GCDWebDAVServer*)server didMoveItemFromPath:(NSString*)fromPath toPath:(NSString*)toPath;
  46. /**
  47. * This method is called whenever a file or directory has been copied.
  48. */
  49. - (void)davServer:(GCDWebDAVServer*)server didCopyItemFromPath:(NSString*)fromPath toPath:(NSString*)toPath;
  50. /**
  51. * This method is called whenever a file or directory has been deleted.
  52. */
  53. - (void)davServer:(GCDWebDAVServer*)server didDeleteItemAtPath:(NSString*)path;
  54. /**
  55. * This method is called whenever a directory has been created.
  56. */
  57. - (void)davServer:(GCDWebDAVServer*)server didCreateDirectoryAtPath:(NSString*)path;
  58. @end
  59. /**
  60. * The GCDWebDAVServer subclass of GCDWebServer implements a class 1 compliant
  61. * WebDAV server. It is also partially class 2 compliant but only when the
  62. * client is the OS X WebDAV implementation (so it can work with the OS X Finder).
  63. *
  64. * See the README.md file for more information about the features of GCDWebDAVServer.
  65. */
  66. @interface GCDWebDAVServer : GCDWebServer
  67. /**
  68. * Returns the upload directory as specified when the server was initialized.
  69. */
  70. @property(nonatomic, readonly) NSString* uploadDirectory;
  71. /**
  72. * Sets the delegate for the server.
  73. */
  74. @property(nonatomic, assign) id<GCDWebDAVServerDelegate> delegate;
  75. /**
  76. * Sets which files are allowed to be operated on depending on their extension.
  77. *
  78. * The default value is nil i.e. all file extensions are allowed.
  79. */
  80. @property(nonatomic, copy) NSArray* allowedFileExtensions;
  81. /**
  82. * Sets if files and directories whose name start with a period are allowed to
  83. * be operated on.
  84. *
  85. * The default value is NO.
  86. */
  87. @property(nonatomic) BOOL allowHiddenItems;
  88. /**
  89. * This method is the designated initializer for the class.
  90. */
  91. - (instancetype)initWithUploadDirectory:(NSString*)path;
  92. @end
  93. /**
  94. * Hooks to customize the behavior of GCDWebDAVServer.
  95. *
  96. * @warning These methods can be called on any GCD thread.
  97. */
  98. @interface GCDWebDAVServer (Subclassing)
  99. /**
  100. * This method is called to check if a file upload is allowed to complete.
  101. * The uploaded file is available for inspection at "tempPath".
  102. *
  103. * The default implementation returns YES.
  104. */
  105. - (BOOL)shouldUploadFileAtPath:(NSString*)path withTemporaryFile:(NSString*)tempPath;
  106. /**
  107. * This method is called to check if a file or directory is allowed to be moved.
  108. *
  109. * The default implementation returns YES.
  110. */
  111. - (BOOL)shouldMoveItemFromPath:(NSString*)fromPath toPath:(NSString*)toPath;
  112. /**
  113. * This method is called to check if a file or directory is allowed to be copied.
  114. *
  115. * The default implementation returns YES.
  116. */
  117. - (BOOL)shouldCopyItemFromPath:(NSString*)fromPath toPath:(NSString*)toPath;
  118. /**
  119. * This method is called to check if a file or directory is allowed to be deleted.
  120. *
  121. * The default implementation returns YES.
  122. */
  123. - (BOOL)shouldDeleteItemAtPath:(NSString*)path;
  124. /**
  125. * This method is called to check if a directory is allowed to be created.
  126. *
  127. * The default implementation returns YES.
  128. */
  129. - (BOOL)shouldCreateDirectoryAtPath:(NSString*)path;
  130. @end