annotate OrthancFramework/Sources/HttpServer/IWebDavBucket.cpp @ 5640:f7adfb22e20e

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