Qore WebDavHandler Module Reference  1.0
AbstractWebDavHandler.qc.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 /* WebDavHandler module Copyright 2019 - 2022 Qore Technologies, s.r.o.
4 
5  Permission is hereby granted, free of charge, to any person obtaining a
6  copy of this software and associated documentation files (the "Software"),
7  to deal in the Software without restriction, including without limitation
8  the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  and/or sell copies of the Software, and to permit persons to whom the
10  Software is furnished to do so, subject to the following conditions:
11 
12  The above copyright notice and this permission notice shall be included in
13  all copies or substantial portions of the Software.
14 
15  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  DEALINGS IN THE SOFTWARE.
22 */
23 
24 
26 namespace WebDavHandler {
30  string action;
32  string ns;
34  string prop;
36  auto val;
37 }
38 
40 class AbstractWebDavHandler : public HttpServer::AbstractHttpRequestHandler {
41 
42 public:
44  const RequestMethods = ...;
45 
46 
48  const DestMethods = ...;
49 
50 
52  const AllowHeaderValue = RequestMethods.keys().join(",");
53 
55  const MethodList = keys RequestMethods;
56 
58  const PPA_Remove = "R";
59 
61  const PPA_Set = "S";
62 
63 protected:
66 
69 
71  Logger logger;
72 
73 public:
74 
76 
78  constructor(*AbstractAuthenticator auth) ;
79 
80 
82 
86  constructor(*AbstractAuthenticator auth, string virtual_relative_path_base)
87  ;
88 
89 
91 
96 constructor(*AbstractAuthenticator auth, AbstractWebDavPropertyHandler property_handler, string virtual_relative_path_base = '/') ;
97 
98 
100 
106 constructor(*AbstractAuthenticator auth, Logger logger, AbstractWebDavPropertyHandler property_handler = new InMemoryWebDavPropertyHandler(), string virtual_relative_path_base = '/') ;
107 
108 
110  list<string> getHttpMethods();
111 
112 
114  setLogger(Logger logger);
115 
116 
118 hash<HttpResponseInfo> handleRequest(HttpListenerInterface listener, Socket s, hash<auto> cx, hash<auto> hdr, *data body);
119 
120 
122 
127  string getRelativePath(string raw_path);
128 
129 
131  hash<HttpResponseInfo> response(int response_code = 200, data msg = 'OK');
132 
133 
135  hash<HttpResponseInfo> response(int response_code = 200, hash<auto> hdr);
136 
137 
139  hash<HttpResponseInfo> resp400(data msg = 'Bad Request');
140 
141 
143  hash<HttpResponseInfo> resp404();
144 
145 
147  hash<HttpResponseInfo> resp500(data msg = 'General Server Error');
148 
149 
151  hash<HttpResponseInfo> resp501();
152 
153 
155 protected:
156  init(Logger logger, AbstractWebDavPropertyHandler property_handler, string virtual_relative_path_base = '/');
157 public:
158 
159 
161 
163 protected:
164  string getRealPath(string raw_path);
165 public:
166 
167 
169 
171 protected:
172  *hash<HttpResponseInfo> checkAuth(string method, hash<auto> cx, hash<auto> hdr, *data body);
173 public:
174 
175 
177 protected:
178  copyProperties(string source_url, string target_url);
179 public:
180 
181 
183 protected:
184  moveProperties(string source_url, string target_url);
185 public:
186 
187 
189 protected:
190  deleteProperties(string source_url);
191 public:
192 
193 
195 protected:
196  hash<auto> preparePropFindXmlResponse(string local_path, string href, bool is_collection, hash<auto> base_props, bool all_props = False, *hash<string, hash<string, bool>> additional_props);
197 public:
198 
199 
200 protected:
201  hash<auto> propStatXmlHash(string href, *hash<auto> code_map);
202 public:
203 
204 
206 
208 protected:
209  string getStatusMessage(softstring http_code);
210 public:
211 
212 
214 
250  hash<HttpResponseInfo> handleOptions(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
251 
252 
254 
290  hash<HttpResponseInfo> handleGet(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
291 
292 
294 
330  hash<HttpResponseInfo> handleHead(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
331 
332 
334 
370  hash<HttpResponseInfo> handlePost(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
371 
372 
374 
410  hash<HttpResponseInfo> handlePut(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
411 
412 
414 
450  hash<HttpResponseInfo> handleDelete(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
451 
452 
454 
490  hash<HttpResponseInfo> handleCopy(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
491 
492 
494 
530  hash<HttpResponseInfo> handleMove(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
531 
532 
534 
570  hash<HttpResponseInfo> handleLock(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
571 
572 
574 
610  hash<HttpResponseInfo> handleUnlock(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
611 
612 
614 
650  hash<HttpResponseInfo> handleMkcol(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
651 
652 
654 
691  hash<HttpResponseInfo> handlePropfind(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
692 
693 
695 
732  hash<HttpResponseInfo> handleProppatch(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
733 
734 
736 
738  logInfo(string fmt);
739 
740 
742 
744  logError(string fmt);
745 
746 
748 
750  logDebug(string fmt);
751 
752 
754 protected:
755  hash<auto> getXml(string body);
756 public:
757 
758 
760 
794 protected:
795  hash<HttpResponseInfo> handleOptionsImpl(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
796 public:
797 
798 
800 
834 protected:
835  abstract hash<HttpResponseInfo> handleGetImpl(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
836 public:
837 
839 
873 protected:
874  abstract hash<HttpResponseInfo> handleHeadImpl(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
875 public:
876 
878 
912 protected:
913  abstract hash<HttpResponseInfo> handlePostImpl(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
914 public:
915 
917 
951 protected:
952  abstract hash<HttpResponseInfo> handlePutImpl(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
953 public:
954 
956 
990 protected:
991  abstract hash<HttpResponseInfo> handleDeleteImpl(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
992 public:
993 
995 
1029 protected:
1030  abstract hash<HttpResponseInfo> handleCopyImpl(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
1031 public:
1032 
1034 
1068 protected:
1069  abstract hash<HttpResponseInfo> handleMoveImpl(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
1070 public:
1071 
1073 
1107 protected:
1108  abstract hash<HttpResponseInfo> handleLockImpl(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
1109 public:
1110 
1112 
1146 protected:
1147  abstract hash<HttpResponseInfo> handleUnlockImpl(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
1148 public:
1149 
1151 
1185 protected:
1186  abstract hash<HttpResponseInfo> handleMkcolImpl(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
1187 public:
1188 
1190 
1225 protected:
1226  abstract hash<HttpResponseInfo> handlePropfindImpl(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
1227 public:
1228 
1230 
1240 private:
1241  abstract *hash<string, hash<string, hash<string, bool>>> handleProppatchImpl(reference<string> href, hash<auto> cx, hash<auto> hdr, *hash<auto> request_xml, *list<hash<PropPatchActionInfo>> actions); *hash<auto> fixDavPrefixes(string ns, hash<auto> h, *string pfx);
1242 public:
1243 
1244 
1246  static combineValue(reference<auto> h, auto v);
1247 
1249 private:
1250  string getNsPrefix(string ns);
1251 public:
1252 
1253 
1254 private:
1255  string getKey(string key, *string nsa);
1256 public:
1257 
1258 
1259 private:
1260  list<auto> fixDavPrefixes(string ns, list<auto> l, *string pfx);
1261 public:
1262 
1263 
1264 private:
1265  auto fixDavPrefixes(string ns, auto v, *string pfx);
1266 public:
1267 
1268 };
1269 }
1270 
1271 // unexperted namespace
1272 namespace Priv {
1273 // for namespace handling while parsing
1274 hashdecl NsInfo {
1275  // map of namespace abbreviations to namespace URIs
1276  hash<string, string> nsmap = {
1277  DavNs: DavNs,
1278  };
1279  // reverse of nsmap
1280  hash<string, string> nsrmap = {
1281  DavNs: DavNs,
1282  };
1283 }
1284 
1285 thread_local hash<NsInfo> nsinfo;
1286 }
Abstract WebDavHandler interface class.
Definition: AbstractWebDavHandler.qc.dox.h:40
string getNsPrefix(string ns)
Returns a new namespace prefix.
abstract hash< HttpResponseInfo > handlePutImpl(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles HTTP PUT requests for WebDavHandler resources.
hash< HttpResponseInfo > response(int response_code=200, data msg='OK')
Returns a hash that can be used as an HTTP response with the given HTTP response code and response me...
copyProperties(string source_url, string target_url)
Copies all properties from the given source URL to the target URL.
abstract *hash< string, hash< string, hash< string, bool > > > handleProppatchImpl(reference< string > href, hash< auto > cx, hash< auto > hdr, *hash< auto > request_xml, *list< hash< PropPatchActionInfo >> actions)
Internal method for handling PROPPATCH requests.
const RequestMethods
A hash of all supported WebDavHandler methods mapped to method names.
Definition: AbstractWebDavHandler.qc.dox.h:44
hash< HttpResponseInfo > resp500(data msg='General Server Error')
Returns a hash that can be used as an HTTP response with a 500 response code and response message.
abstract hash< HttpResponseInfo > handlePostImpl(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles HTTP POST requests for WebDavHandler resources.
hash< HttpResponseInfo > handleLock(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles WebDavHandler LOCK requests for WebDavHandler resources.
const AllowHeaderValue
List of WebDavHandler methods in a string suitable for use in HTTP responses.
Definition: AbstractWebDavHandler.qc.dox.h:52
abstract hash< HttpResponseInfo > handleCopyImpl(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles WebDavHandler COPY requests for WebDavHandler resources.
logInfo(string fmt)
This method is called with informational log messages.
hash< HttpResponseInfo > resp404()
Returns a hash that can be used as an HTTP response with a 404 response code and response message.
init(Logger logger, AbstractWebDavPropertyHandler property_handler, string virtual_relative_path_base='/')
Common constructor code.
constructor(*AbstractAuthenticator auth, string virtual_relative_path_base)
Creates the object with the given argument and an in-memory property handler.
hash< HttpResponseInfo > handleOptionsImpl(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles an HTTP/WebDavHandler OPTIONS request.
constructor(*AbstractAuthenticator auth)
Creates the object with an empty logger and an in-memory property handler.
abstract hash< HttpResponseInfo > handleHeadImpl(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles HTTP HEAD requests for WebDavHandler resources.
hash< auto > preparePropFindXmlResponse(string local_path, string href, bool is_collection, hash< auto > base_props, bool all_props=False, *hash< string, hash< string, bool >> additional_props)
Returns a hash that can be serialized to an XML string for a PROPFIND request.
hash< HttpResponseInfo > handleGet(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles HTTP GET requests for WebDavHandler resources.
abstract hash< HttpResponseInfo > handleDeleteImpl(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles HTTP DELETE requests for WebDavHandler resources.
const MethodList
List of WebDavHandler methods.
Definition: AbstractWebDavHandler.qc.dox.h:55
string getStatusMessage(softstring http_code)
Returns a status message for the given HTTP response code.
const DestMethods
A hash of methods that require a Destination header.
Definition: AbstractWebDavHandler.qc.dox.h:48
hash< HttpResponseInfo > handleHead(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles HTTP HEAD requests for WebDavHandler resources.
string getRealPath(string raw_path)
Converts a request path to a normalized real path on the filesystem in the root WebDavHandler directo...
hash< HttpResponseInfo > handlePut(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles HTTP PUT requests for WebDavHandler resources.
hash< HttpResponseInfo > handleUnlock(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles WebDavHandler UNLOCK requests for WebDavHandler resources.
abstract hash< HttpResponseInfo > handleUnlockImpl(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles WebDavHandler UNLOCK requests for WebDavHandler resources.
string getRelativePath(string raw_path)
Returns a relative path from an absolute path.
hash< auto > getXml(string body)
Parse incoming XML and handle namespaces.
logError(string fmt)
This method is called with error log messages.
*hash< HttpResponseInfo > checkAuth(string method, hash< auto > cx, hash< auto > hdr, *data body)
Checks if the request is authorized; if not, this method must return a value.
AbstractWebDavPropertyHandler property_handler
The property handler object.
Definition: AbstractWebDavHandler.qc.dox.h:65
hash< HttpResponseInfo > handleRequest(HttpListenerInterface listener, Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles HTTP/WebDavHandler requests and returns the response.
hash< HttpResponseInfo > handleMkcol(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles WebDavHandler MKCOL requests for WebDavHandler resources.
moveProperties(string source_url, string target_url)
Moves all properties from the given source URL to the target URL.
abstract hash< HttpResponseInfo > handleGetImpl(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles HTTP GET requests for WebDavHandler resources.
abstract hash< HttpResponseInfo > handleMoveImpl(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles WebDavHandler MOVE requests for WebDavHandler resources.
hash< HttpResponseInfo > response(int response_code=200, hash< auto > hdr)
Returns a hash that can be used as an HTTP response with the given HTTP response code and response he...
hash< HttpResponseInfo > handlePost(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles HTTP POST requests for WebDavHandler resources.
hash< HttpResponseInfo > handleCopy(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles WebDavHandler COPY requests for WebDavHandler resources.
setLogger(Logger logger)
Replace the logger.
constructor(*AbstractAuthenticator auth, AbstractWebDavPropertyHandler property_handler, string virtual_relative_path_base='/')
Creates the object with the given arguments.
hash< HttpResponseInfo > resp400(data msg='Bad Request')
Returns a hash that can be used as an HTTP response with a 400 response code and response message.
string virtual_base_path
The virtual base path for resources served by the WebDavHandler handler.
Definition: AbstractWebDavHandler.qc.dox.h:68
logDebug(string fmt)
This method is called with debug log messages.
deleteProperties(string source_url)
Deletes all properties from the given URL.
list< string > getHttpMethods()
Returnd a list of WebDavHandler methods.
hash< HttpResponseInfo > handleMove(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles WebDavHandler MOVE requests for WebDavHandler resources.
const PPA_Remove
PROPPATCH action: remove.
Definition: AbstractWebDavHandler.qc.dox.h:58
abstract hash< HttpResponseInfo > handlePropfindImpl(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles WebDavHandler PROPFIND requests for WebDavHandler resources; reetrieves properties from WebDa...
abstract hash< HttpResponseInfo > handleLockImpl(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles WebDavHandler LOCK requests for WebDavHandler resources.
static combineValue(reference< auto > h, auto v)
Combines values recursively.
abstract hash< HttpResponseInfo > handleMkcolImpl(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles WebDavHandler MKCOL requests for WebDavHandler resources.
hash< HttpResponseInfo > handleDelete(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles HTTP DELETE requests for WebDavHandler resources.
hash< HttpResponseInfo > resp501()
Returns a hash that can be used as an HTTP response with a 501 response code and response message.
hash< HttpResponseInfo > handlePropfind(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles WebDavHandler PROPFIND requests for WebDavHandler resources; reetrieves properties from WebDa...
hash< HttpResponseInfo > handleOptions(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles a WebDavHandler OPTIONS request.
const PPA_Set
PROPPATCH action: set.
Definition: AbstractWebDavHandler.qc.dox.h:61
constructor(*AbstractAuthenticator auth, Logger logger, AbstractWebDavPropertyHandler property_handler=new InMemoryWebDavPropertyHandler(), string virtual_relative_path_base='/')
Creates the object with the given arguments.
Logger logger
The Logger for this object.
Definition: AbstractWebDavHandler.qc.dox.h:71
hash< HttpResponseInfo > handleProppatch(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles WebDavHandler PROPPATCH requests for WebDavHandler resources; sets or removes properties on W...
The abstract WebDavHandler property handler class interface.
Definition: AbstractWebDavPropertyHandler.qc.dox.h:27
An in-memory property handler that stores and retrieves all properties in memory.
Definition: InMemoryWebDavPropertyHandler.qc.dox.h:27
Main public WebDavHandler namespace.
Definition: AbstractWebDavHandler.qc.dox.h:26
string prop
Property.
Definition: AbstractWebDavHandler.qc.dox.h:34
auto val
Value.
Definition: AbstractWebDavHandler.qc.dox.h:36
hashdecl PropPatchActionInfo
PROPPATCH action info.
Definition: AbstractWebDavHandler.qc.dox.h:28
const DavNs
WebDavHandler namespace value.
Definition: WebDavHandler.qm.dox.h:116
string ns
Namespace.
Definition: AbstractWebDavHandler.qc.dox.h:32