Qore WebDavHandler Module Reference 1.0
Loading...
Searching...
No Matches
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
26namespace WebDavHandler {
30 string action;
32 string ns;
34 string prop;
36 auto val;
37}
38
40class AbstractWebDavHandler : public HttpServer::AbstractHttpRequestHandler {
41
42public:
44 const RequestMethods = ...;
45
46
48 const DestMethods = ...;
49
50
52 const AllowHeaderValue = RequestMethods.keys().join(",");
53
56
58 const PPA_Remove = "R";
59
61 const PPA_Set = "S";
62
63protected:
66
69
71 Logger logger;
72
73public:
74
76
78 constructor(*AbstractAuthenticator auth) ;
79
80
82
86 constructor(*AbstractAuthenticator auth, string virtual_relative_path_base) ;
87
88
90
95 constructor(*AbstractAuthenticator auth, AbstractWebDavPropertyHandler property_handler, string virtual_relative_path_base = '/') ;
96
97
99
105 constructor(*AbstractAuthenticator auth, Logger logger, AbstractWebDavPropertyHandler property_handler = new InMemoryWebDavPropertyHandler(), string virtual_relative_path_base = '/') ;
106
107
109 list<string> getHttpMethods();
110
111
114
115
117 hash<HttpResponseInfo> handleRequest(HttpListenerInterface listener, Socket s, hash<auto> cx, hash<auto> hdr, *data body);
118
119
121
126 string getRelativePath(string raw_path);
127
128
130 hash<HttpResponseInfo> response(int response_code = 200, data msg = 'OK');
131
132
134 hash<HttpResponseInfo> response(int response_code = 200, hash<auto> hdr);
135
136
138 hash<HttpResponseInfo> resp400(data msg = 'Bad Request');
139
140
142 hash<HttpResponseInfo> resp404();
143
144
146 hash<HttpResponseInfo> resp500(data msg = 'General Server Error');
147
148
150 hash<HttpResponseInfo> resp501();
151
152
154protected:
155 init(Logger logger, AbstractWebDavPropertyHandler property_handler, string virtual_relative_path_base = '/');
156public:
157
158
160
162protected:
163 string getRealPath(string raw_path);
164public:
165
166
168
170protected:
171 *hash<HttpResponseInfo> checkAuth(string method, hash<auto> cx, hash<auto> hdr, *data body);
172public:
173
174
176protected:
177 copyProperties(string source_url, string target_url);
178public:
179
180
182protected:
183 moveProperties(string source_url, string target_url);
184public:
185
186
188protected:
189 deleteProperties(string source_url);
190public:
191
192
194protected:
195 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);
196public:
197
198
199protected:
200 hash<auto> propStatXmlHash(string href, *hash<auto> code_map);
201public:
202
203
205
207protected:
208 string getStatusMessage(softstring http_code);
209public:
210
211
213
249 hash<HttpResponseInfo> handleOptions(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
250
251
253
289 hash<HttpResponseInfo> handleGet(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
290
291
293
329 hash<HttpResponseInfo> handleHead(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
330
331
333
369 hash<HttpResponseInfo> handlePost(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
370
371
373
409 hash<HttpResponseInfo> handlePut(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
410
411
413
449 hash<HttpResponseInfo> handleDelete(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
450
451
453
489 hash<HttpResponseInfo> handleCopy(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
490
491
493
529 hash<HttpResponseInfo> handleMove(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
530
531
533
569 hash<HttpResponseInfo> handleLock(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
570
571
573
609 hash<HttpResponseInfo> handleUnlock(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
610
611
613
649 hash<HttpResponseInfo> handleMkcol(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
650
651
653
690 hash<HttpResponseInfo> handlePropfind(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
691
692
694
731 hash<HttpResponseInfo> handleProppatch(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
732
733
735
737 logInfo(string fmt);
738
739
741
743 logError(string fmt);
744
745
747
749 logDebug(string fmt);
750
751
753protected:
754 hash<auto> getXml(string body);
755public:
756
757
759
793protected:
794 hash<HttpResponseInfo> handleOptionsImpl(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
795public:
796
797
799
833protected:
834 abstract hash<HttpResponseInfo> handleGetImpl(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
835public:
836
838
872protected:
873 abstract hash<HttpResponseInfo> handleHeadImpl(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
874public:
875
877
911protected:
912 abstract hash<HttpResponseInfo> handlePostImpl(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
913public:
914
916
950protected:
951 abstract hash<HttpResponseInfo> handlePutImpl(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
952public:
953
955
989protected:
990 abstract hash<HttpResponseInfo> handleDeleteImpl(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
991public:
992
994
1028protected:
1029 abstract hash<HttpResponseInfo> handleCopyImpl(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
1030public:
1031
1033
1067protected:
1068 abstract hash<HttpResponseInfo> handleMoveImpl(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
1069public:
1070
1072
1106protected:
1107 abstract hash<HttpResponseInfo> handleLockImpl(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
1108public:
1109
1111
1145protected:
1146 abstract hash<HttpResponseInfo> handleUnlockImpl(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
1147public:
1148
1150
1184protected:
1185 abstract hash<HttpResponseInfo> handleMkcolImpl(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
1186public:
1187
1189
1224protected:
1225 abstract hash<HttpResponseInfo> handlePropfindImpl(Socket s, hash<auto> cx, hash<auto> hdr, *data body);
1226public:
1227
1229
1239protected:
1240 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);
1241public:
1242
1243private:
1244 *hash<auto> fixDavPrefixes(string ns, hash<auto> h, *string pfx);
1245public:
1246
1247
1249 static combineValue(reference<auto> h, auto v);
1250
1252private:
1253 string getNsPrefix(string ns);
1254public:
1255
1256
1257private:
1258 string getKey(string key, *string nsa);
1259public:
1260
1261
1262private:
1263 list<auto> fixDavPrefixes(string ns, list<auto> l, *string pfx);
1264public:
1265
1266
1267private:
1268 auto fixDavPrefixes(string ns, auto v, *string pfx);
1269public:
1270
1271};
1272}
1273
1274// unexperted namespace
1275namespace Priv {
1276// for namespace handling while parsing
1277hashdecl NsInfo {
1278 // map of namespace abbreviations to namespace URIs
1279 hash<string, string> nsmap = {
1280 DavNs: DavNs,
1281 };
1282 // reverse of nsmap
1283 hash<string, string> nsrmap = {
1284 DavNs: DavNs,
1285 };
1286}
1287
1288thread_local hash<NsInfo> nsinfo;
1289}
Abstract WebDavHandler interface class.
Definition AbstractWebDavHandler.qc.dox.h:40
string getNsPrefix(string ns)
Returns a new namespace prefix.
hash< HttpResponseInfo > handleMove(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles WebDavHandler MOVE requests for WebDavHandler resources.
hash< HttpResponseInfo > handleHead(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles HTTP HEAD requests for WebDavHandler resources.
copyProperties(string source_url, string target_url)
Copies all properties from the given source URL to the target URL.
const RequestMethods
A hash of all supported WebDavHandler methods mapped to method names.
Definition AbstractWebDavHandler.qc.dox.h:44
hash< HttpResponseInfo > handleMkcol(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles WebDavHandler MKCOL 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...
abstract hash< HttpResponseInfo > handlePutImpl(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles HTTP PUT 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 > handleMkcolImpl(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles WebDavHandler MKCOL requests for WebDavHandler resources.
logInfo(string fmt)
This method is called with informational log messages.
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.
constructor(*AbstractAuthenticator auth)
Creates the object with an empty logger and an in-memory property handler.
hash< HttpResponseInfo > handlePut(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles HTTP PUT requests for WebDavHandler resources.
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...
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...
abstract hash< HttpResponseInfo > handleHeadImpl(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles HTTP HEAD 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.
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.
hash< HttpResponseInfo > handleDelete(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles HTTP DELETE requests for WebDavHandler resources.
const DestMethods
A hash of methods that require a Destination header.
Definition AbstractWebDavHandler.qc.dox.h:48
string getRealPath(string raw_path)
Converts a request path to a normalized real path on the filesystem in the root WebDavHandler directo...
abstract hash< HttpResponseInfo > handleUnlockImpl(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles WebDavHandler UNLOCK requests for WebDavHandler resources.
hash< HttpResponseInfo > handlePropfind(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles WebDavHandler PROPFIND requests for WebDavHandler resources; reetrieves properties from WebDa...
list< string > getHttpMethods()
Returnd a list of WebDavHandler methods.
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 > handleDeleteImpl(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles HTTP DELETE requests for WebDavHandler resources.
abstract hash< HttpResponseInfo > handleCopyImpl(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles WebDavHandler COPY requests for WebDavHandler resources.
hash< HttpResponseInfo > resp404()
Returns a hash that can be used as an HTTP response with a 404 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 > handleRequest(HttpListenerInterface listener, Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles HTTP/WebDavHandler requests and returns the response.
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.
AbstractWebDavPropertyHandler property_handler
The property handler object.
Definition AbstractWebDavHandler.qc.dox.h:65
hash< HttpResponseInfo > handleUnlock(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles WebDavHandler UNLOCK requests for WebDavHandler resources.
abstract hash< HttpResponseInfo > handleLockImpl(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles WebDavHandler LOCK 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.
moveProperties(string source_url, string target_url)
Moves all properties from the given source URL to the target URL.
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.
hash< HttpResponseInfo > handleOptionsImpl(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles an HTTP/WebDavHandler OPTIONS request.
hash< HttpResponseInfo > handleGet(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles HTTP GET requests for WebDavHandler resources.
hash< HttpResponseInfo > handleOptions(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles a WebDavHandler OPTIONS request.
hash< HttpResponseInfo > resp501()
Returns a hash that can be used as an HTTP response with a 501 response code and response message.
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.
abstract hash< HttpResponseInfo > handleGetImpl(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles HTTP GET requests for WebDavHandler resources.
constructor(*AbstractAuthenticator auth, AbstractWebDavPropertyHandler property_handler, string virtual_relative_path_base='/')
Creates the object with the given arguments.
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.
hash< HttpResponseInfo > handleLock(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles WebDavHandler LOCK requests for WebDavHandler resources.
const PPA_Remove
PROPPATCH action: remove.
Definition AbstractWebDavHandler.qc.dox.h:58
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.
static combineValue(reference< auto > h, auto v)
Combines values recursively.
*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.
abstract hash< HttpResponseInfo > handleMoveImpl(Socket s, hash< auto > cx, hash< auto > hdr, *data body)
Handles WebDavHandler MOVE requests for WebDavHandler resources.
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
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