annotate OrthancFramework/Sources/HttpServer/IWebDavBucket.cpp @ 5175:48005e522bd6

start fixing thread safety issues with DicomMap
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 24 Mar 2023 19:00:33 +0100
parents 43e613a7756b
children 0ea402b4d901
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4226
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
4870
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
4226
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * the License, or (at your option) any later version.
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * Lesser General Public License for more details.
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * License along with this program. If not, see
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * <http://www.gnu.org/licenses/>.
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "../PrecompiledHeaders.h"
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "IWebDavBucket.h"
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
4228
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
27 #include "HttpOutput.h"
4226
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include "../OrthancException.h"
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include "../Toolbox.h"
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 static boost::posix_time::ptime GetNow()
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 {
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 return boost::posix_time::second_clock::universal_time();
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 }
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 static std::string AddTrailingSlash(const std::string& s)
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 {
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 if (s.empty() ||
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 s[s.size() - 1] != '/')
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 return s + '/';
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 }
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 else
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 return s;
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 }
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 }
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 namespace Orthanc
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 {
4252
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
54 IWebDavBucket::Resource::Resource(const std::string& displayName) :
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
55 displayName_(displayName),
4226
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 hasModificationTime_(false),
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 creationTime_(GetNow()),
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 modificationTime_(GetNow())
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
4252
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
60 if (displayName.empty() ||
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
61 displayName.find('/') != std::string::npos ||
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
62 displayName.find('\\') != std::string::npos ||
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
63 displayName.find('\0') != std::string::npos)
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
64 {
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
65 throw OrthancException(ErrorCode_ParameterOutOfRange,
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
66 "Bad resource name for WebDAV: " + displayName);
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
67 }
4226
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 }
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 void IWebDavBucket::Resource::SetCreationTime(const boost::posix_time::ptime& t)
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 {
4246
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
73 if (t.is_special())
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
74 {
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
75 throw OrthancException(ErrorCode_ParameterOutOfRange, "Not a valid date-time");
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
76 }
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
77 else
4226
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 {
4246
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
79 creationTime_ = t;
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
80
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
81 if (!hasModificationTime_)
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
82 {
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
83 modificationTime_ = t;
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
84 }
4226
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 }
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 void IWebDavBucket::Resource::SetModificationTime(const boost::posix_time::ptime& t)
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 {
4246
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
91 if (t.is_special())
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
92 {
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
93 throw OrthancException(ErrorCode_ParameterOutOfRange, "Not a valid date-time");
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
94 }
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
95 else
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
96 {
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
97 modificationTime_ = t;
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
98 hasModificationTime_ = true;
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
99 }
4226
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
4246
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
103 static void FormatInternal(pugi::xml_node& node,
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
104 const std::string& href,
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
105 const std::string& displayName,
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
106 const boost::posix_time::ptime& creationTime,
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
107 const boost::posix_time::ptime& modificationTime)
4226
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 {
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 node.set_name("D:response");
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
4246
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
111 node.append_child("D:href").append_child(pugi::node_pcdata).set_value(href.c_str());
4226
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 pugi::xml_node propstat = node.append_child("D:propstat");
4228
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
114
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
115 static const HttpStatus status = HttpStatus_200_Ok;
4246
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
116 std::string s = ("HTTP/1.1 " + boost::lexical_cast<std::string>(status) + " " +
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
117 std::string(EnumerationToString(status)));
4228
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
118 propstat.append_child("D:status").append_child(pugi::node_pcdata).set_value(s.c_str());
4226
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 pugi::xml_node prop = propstat.append_child("D:prop");
4246
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
121 prop.append_child("D:displayname").append_child(pugi::node_pcdata).set_value(displayName.c_str());
4226
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
4247
112951171852 comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
123 // IMPORTANT: Adding the "Z" suffix is mandatory on Windows >= 7 (it indicates UTC)
112951171852 comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
124 assert(!creationTime.is_special());
4246
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
125 s = boost::posix_time::to_iso_extended_string(creationTime) + "Z";
4226
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 prop.append_child("D:creationdate").append_child(pugi::node_pcdata).set_value(s.c_str());
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
4247
112951171852 comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
128 assert(!modificationTime.is_special());
4246
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
129 s = boost::posix_time::to_iso_extended_string(modificationTime) + "Z";
4226
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 prop.append_child("D:getlastmodified").append_child(pugi::node_pcdata).set_value(s.c_str());
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 #if 0
4228
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
133 // Maybe used by davfs2
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
134 prop.append_child("D:quota-available-bytes");
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
135 prop.append_child("D:quota-used-bytes");
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
136 #endif
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
137
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
138 #if 0
4226
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 prop.append_child("D:lockdiscovery");
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 pugi::xml_node lock = prop.append_child("D:supportedlock");
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 pugi::xml_node lockentry = lock.append_child("D:lockentry");
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 lockentry.append_child("D:lockscope").append_child("D:exclusive");
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 lockentry.append_child("D:locktype").append_child("D:write");
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 lockentry = lock.append_child("D:lockentry");
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 lockentry.append_child("D:lockscope").append_child("D:shared");
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 lockentry.append_child("D:locktype").append_child("D:write");
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 #endif
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 }
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
4246
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
152
4252
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
153 IWebDavBucket::File::File(const std::string& displayName) :
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
154 Resource(displayName),
4226
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 contentLength_(0),
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 mime_(MimeType_Binary)
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 {
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 }
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
4232
688435755466 added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4230
diff changeset
160
4226
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 void IWebDavBucket::File::Format(pugi::xml_node& node,
4246
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
162 const std::string& parentPath) const
4226
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 {
4246
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
164 std::string href;
4252
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
165 Toolbox::UriEncode(href, AddTrailingSlash(parentPath) + GetDisplayName());
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
166 FormatInternal(node, href, GetDisplayName(), GetCreationTime(), GetModificationTime());
4226
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 pugi::xml_node prop = node.first_element_by_path("D:propstat/D:prop");
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 prop.append_child("D:resourcetype");
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 std::string s = boost::lexical_cast<std::string>(contentLength_);
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 prop.append_child("D:getcontentlength").append_child(pugi::node_pcdata).set_value(s.c_str());
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 s = EnumerationToString(mime_);
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 prop.append_child("D:getcontenttype").append_child(pugi::node_pcdata).set_value(s.c_str());
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 }
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 void IWebDavBucket::Folder::Format(pugi::xml_node& node,
4246
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
180 const std::string& parentPath) const
4226
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 {
4246
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
182 std::string href;
4252
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
183 Toolbox::UriEncode(href, AddTrailingSlash(parentPath) + GetDisplayName());
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
184 FormatInternal(node, href, GetDisplayName(), GetCreationTime(), GetModificationTime());
4226
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 pugi::xml_node prop = node.first_element_by_path("D:propstat/D:prop");
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 prop.append_child("D:resourcetype").append_child("D:collection");
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 //prop.append_child("D:getcontenttype").append_child(pugi::node_pcdata).set_value("httpd/unix-directory");
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 }
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 IWebDavBucket::Collection::~Collection()
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 {
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 for (std::list<Resource*>::iterator it = resources_.begin(); it != resources_.end(); ++it)
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 {
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 assert(*it != NULL);
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 delete(*it);
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 }
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 }
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 void IWebDavBucket::Collection::AddResource(Resource* resource) // Takes ownership
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 {
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 if (resource == NULL)
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 {
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 throw OrthancException(ErrorCode_NullPointer);
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 }
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 else
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 {
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 resources_.push_back(resource);
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 }
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 }
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215
4252
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
216 void IWebDavBucket::Collection::ListDisplayNames(std::set<std::string>& target)
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
217 {
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
218 for (std::list<Resource*>::iterator it = resources_.begin(); it != resources_.end(); ++it)
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
219 {
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
220 assert(*it != NULL);
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
221 target.insert((*it)->GetDisplayName());
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
222 }
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
223 }
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
224
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
225
4226
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 void IWebDavBucket::Collection::Format(std::string& target,
4246
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
227 const std::string& parentPath) const
4226
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 {
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 pugi::xml_document doc;
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 pugi::xml_node root = doc.append_child("D:multistatus");
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 root.append_attribute("xmlns:D").set_value("DAV:");
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233
4246
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
234 {
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
235 pugi::xml_node self = root.append_child();
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
236
4252
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
237 std::vector<std::string> tokens;
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
238 Toolbox::SplitUriComponents(tokens, parentPath);
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
239
4246
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
240 std::string folder;
4252
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
241 if (!tokens.empty())
4246
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
242 {
4252
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
243 folder = tokens.back();
4246
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
244 }
4252
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
245
4246
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
246 std::string href;
4252
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4247
diff changeset
247 Toolbox::UriEncode(href, Toolbox::FlattenUri(tokens) + "/");
4247
112951171852 comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
248
112951171852 comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
249 boost::posix_time::ptime now = GetNow();
112951171852 comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
250 FormatInternal(self, href, folder, now, now);
4246
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
251
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
252 pugi::xml_node prop = self.first_element_by_path("D:propstat/D:prop");
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
253 prop.append_child("D:resourcetype").append_child("D:collection");
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
254 }
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
255
4226
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 for (std::list<Resource*>::const_iterator
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 it = resources_.begin(); it != resources_.end(); ++it)
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 {
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 assert(*it != NULL);
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 pugi::xml_node n = root.append_child();
4246
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
261 (*it)->Format(n, parentPath);
4226
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 }
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 pugi::xml_node decl = doc.prepend_child(pugi::node_declaration);
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 decl.append_attribute("version").set_value("1.0");
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 decl.append_attribute("encoding").set_value("UTF-8");
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 Toolbox::XmlToString(target, doc);
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 }
4228
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
270
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
271
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
272 void IWebDavBucket::AnswerFakedProppatch(HttpOutput& output,
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
273 const std::string& uri)
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
274 {
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
275 /**
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
276 * This is a fake implementation. The goal is to make happy the
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
277 * WebDAV clients that set properties (such as Windows >= 7).
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
278 **/
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
279
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
280 pugi::xml_document doc;
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
281
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
282 pugi::xml_node root = doc.append_child("D:multistatus");
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
283 root.append_attribute("xmlns:D").set_value("DAV:");
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
284
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
285 pugi::xml_node response = root.append_child("D:response");
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
286 response.append_child("D:href").append_child(pugi::node_pcdata).set_value(uri.c_str());
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
287
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
288 response.append_child("D:propstat");
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
289
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
290 pugi::xml_node decl = doc.prepend_child(pugi::node_declaration);
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
291 decl.append_attribute("version").set_value("1.0");
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
292 decl.append_attribute("encoding").set_value("UTF-8");
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
293
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
294 std::string s;
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
295 Toolbox::XmlToString(s, doc);
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
296
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
297 output.AddHeader("Content-Type", "application/xml");
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
298 output.SendStatus(HttpStatus_207_MultiStatus, s);
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
299 }
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
300
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
301
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
302 void IWebDavBucket::AnswerFakedLock(HttpOutput& output,
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
303 const std::string& uri)
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
304 {
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
305 /**
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
306 * This is a fake implementation. No lock is actually
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
307 * created. The goal is to make happy the WebDAV clients
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
308 * that use locking (such as Windows >= 7).
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
309 **/
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
310
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
311 pugi::xml_document doc;
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
312
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
313 pugi::xml_node root = doc.append_child("D:prop");
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
314 root.append_attribute("xmlns:D").set_value("DAV:");
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
315
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
316 pugi::xml_node activelock = root.append_child("D:lockdiscovery").append_child("D:activelock");
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
317 activelock.append_child("D:locktype").append_child("D:write");
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
318 activelock.append_child("D:lockscope").append_child("D:exclusive");
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
319 activelock.append_child("D:depth").append_child(pugi::node_pcdata).set_value("0");
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
320 activelock.append_child("D:timeout").append_child(pugi::node_pcdata).set_value("Second-3599");
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
321
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
322 activelock.append_child("D:lockroot").append_child("D:href")
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
323 .append_child(pugi::node_pcdata).set_value(uri.c_str());
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
324 activelock.append_child("D:owner");
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
325
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
326 std::string token = Toolbox::GenerateUuid();
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
327 boost::erase_all(token, "-");
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
328 token = "opaquelocktoken:0x" + token;
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
329
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
330 activelock.append_child("D:locktoken").append_child("D:href").
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
331 append_child(pugi::node_pcdata).set_value(token.c_str());
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
332
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
333 pugi::xml_node decl = doc.prepend_child(pugi::node_declaration);
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
334 decl.append_attribute("version").set_value("1.0");
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
335 decl.append_attribute("encoding").set_value("UTF-8");
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
336
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
337 std::string s;
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
338 Toolbox::XmlToString(s, doc);
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
339
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
340 output.AddHeader("Lock-Token", token); // Necessary for davfs2
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
341 output.AddHeader("Content-Type", "application/xml");
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
342 output.SendStatus(HttpStatus_201_Created, s);
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
343 }
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
344
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
345
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
346 void IWebDavBucket::AnswerFakedUnlock(HttpOutput& output)
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
347 {
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
348 output.SendStatus(HttpStatus_204_NoContent);
c8c0bbaaace3 write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4226
diff changeset
349 }
4226
7bd5eab3ba25 prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 }