Mercurial > hg > orthanc
comparison OrthancFramework/Sources/HttpServer/IWebDavBucket.cpp @ 4252:f047e2734655
fix webdav
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 15 Oct 2020 17:13:35 +0200 |
parents | 112951171852 |
children | d9473bd5ed43 |
comparison
equal
deleted
inserted
replaced
4250:cbf9afa17415 | 4252:f047e2734655 |
---|---|
48 } | 48 } |
49 | 49 |
50 | 50 |
51 namespace Orthanc | 51 namespace Orthanc |
52 { | 52 { |
53 void IWebDavBucket::Resource::SetNameInternal(const std::string& name) | 53 IWebDavBucket::Resource::Resource(const std::string& displayName) : |
54 { | 54 displayName_(displayName), |
55 if (name.find('/') != std::string::npos || | |
56 name.find('\\') != std::string::npos || | |
57 name.find('\0') != std::string::npos) | |
58 { | |
59 throw OrthancException(ErrorCode_ParameterOutOfRange, | |
60 "Bad resource name for WebDAV: " + name); | |
61 } | |
62 | |
63 name_ = name; | |
64 } | |
65 | |
66 | |
67 IWebDavBucket::Resource::Resource() : | |
68 hasModificationTime_(false), | 55 hasModificationTime_(false), |
69 creationTime_(GetNow()), | 56 creationTime_(GetNow()), |
70 modificationTime_(GetNow()) | 57 modificationTime_(GetNow()) |
71 { | 58 { |
59 if (displayName.empty() || | |
60 displayName.find('/') != std::string::npos || | |
61 displayName.find('\\') != std::string::npos || | |
62 displayName.find('\0') != std::string::npos) | |
63 { | |
64 throw OrthancException(ErrorCode_ParameterOutOfRange, | |
65 "Bad resource name for WebDAV: " + displayName); | |
66 } | |
72 } | 67 } |
73 | 68 |
74 | 69 |
75 void IWebDavBucket::Resource::SetCreationTime(const boost::posix_time::ptime& t) | 70 void IWebDavBucket::Resource::SetCreationTime(const boost::posix_time::ptime& t) |
76 { | 71 { |
152 lockentry.append_child("D:locktype").append_child("D:write"); | 147 lockentry.append_child("D:locktype").append_child("D:write"); |
153 #endif | 148 #endif |
154 } | 149 } |
155 | 150 |
156 | 151 |
157 IWebDavBucket::File::File(const std::string& name) : | 152 IWebDavBucket::File::File(const std::string& displayName) : |
153 Resource(displayName), | |
158 contentLength_(0), | 154 contentLength_(0), |
159 mime_(MimeType_Binary) | 155 mime_(MimeType_Binary) |
160 { | 156 { |
161 if (name.empty()) | |
162 { | |
163 throw OrthancException(ErrorCode_ParameterOutOfRange, | |
164 "Cannot use an empty filename in WebDAV"); | |
165 } | |
166 | |
167 SetNameInternal(name); | |
168 } | 157 } |
169 | 158 |
170 | 159 |
171 void IWebDavBucket::File::Format(pugi::xml_node& node, | 160 void IWebDavBucket::File::Format(pugi::xml_node& node, |
172 const std::string& parentPath) const | 161 const std::string& parentPath) const |
173 { | 162 { |
174 std::string href; | 163 std::string href; |
175 Toolbox::UriEncode(href, AddTrailingSlash(parentPath) + GetName()); | 164 Toolbox::UriEncode(href, AddTrailingSlash(parentPath) + GetDisplayName()); |
176 FormatInternal(node, href, GetName(), GetCreationTime(), GetModificationTime()); | 165 FormatInternal(node, href, GetDisplayName(), GetCreationTime(), GetModificationTime()); |
177 | 166 |
178 pugi::xml_node prop = node.first_element_by_path("D:propstat/D:prop"); | 167 pugi::xml_node prop = node.first_element_by_path("D:propstat/D:prop"); |
179 prop.append_child("D:resourcetype"); | 168 prop.append_child("D:resourcetype"); |
180 | 169 |
181 std::string s = boost::lexical_cast<std::string>(contentLength_); | 170 std::string s = boost::lexical_cast<std::string>(contentLength_); |
188 | 177 |
189 void IWebDavBucket::Folder::Format(pugi::xml_node& node, | 178 void IWebDavBucket::Folder::Format(pugi::xml_node& node, |
190 const std::string& parentPath) const | 179 const std::string& parentPath) const |
191 { | 180 { |
192 std::string href; | 181 std::string href; |
193 Toolbox::UriEncode(href, AddTrailingSlash(parentPath) + GetName()); | 182 Toolbox::UriEncode(href, AddTrailingSlash(parentPath) + GetDisplayName()); |
194 FormatInternal(node, href, GetName(), GetCreationTime(), GetModificationTime()); | 183 FormatInternal(node, href, GetDisplayName(), GetCreationTime(), GetModificationTime()); |
195 | 184 |
196 pugi::xml_node prop = node.first_element_by_path("D:propstat/D:prop"); | 185 pugi::xml_node prop = node.first_element_by_path("D:propstat/D:prop"); |
197 prop.append_child("D:resourcetype").append_child("D:collection"); | 186 prop.append_child("D:resourcetype").append_child("D:collection"); |
198 | 187 |
199 //prop.append_child("D:getcontenttype").append_child(pugi::node_pcdata).set_value("httpd/unix-directory"); | 188 //prop.append_child("D:getcontenttype").append_child(pugi::node_pcdata).set_value("httpd/unix-directory"); |
221 resources_.push_back(resource); | 210 resources_.push_back(resource); |
222 } | 211 } |
223 } | 212 } |
224 | 213 |
225 | 214 |
215 void IWebDavBucket::Collection::ListDisplayNames(std::set<std::string>& target) | |
216 { | |
217 for (std::list<Resource*>::iterator it = resources_.begin(); it != resources_.end(); ++it) | |
218 { | |
219 assert(*it != NULL); | |
220 target.insert((*it)->GetDisplayName()); | |
221 } | |
222 } | |
223 | |
224 | |
226 void IWebDavBucket::Collection::Format(std::string& target, | 225 void IWebDavBucket::Collection::Format(std::string& target, |
227 const std::string& parentPath) const | 226 const std::string& parentPath) const |
228 { | 227 { |
229 pugi::xml_document doc; | 228 pugi::xml_document doc; |
230 | 229 |
232 root.append_attribute("xmlns:D").set_value("DAV:"); | 231 root.append_attribute("xmlns:D").set_value("DAV:"); |
233 | 232 |
234 { | 233 { |
235 pugi::xml_node self = root.append_child(); | 234 pugi::xml_node self = root.append_child(); |
236 | 235 |
236 std::vector<std::string> tokens; | |
237 Toolbox::SplitUriComponents(tokens, parentPath); | |
238 | |
237 std::string folder; | 239 std::string folder; |
238 size_t lastSlash = parentPath.rfind('/'); | 240 if (!tokens.empty()) |
239 if (lastSlash == std::string::npos) | |
240 { | 241 { |
241 folder = parentPath; | 242 folder = tokens.back(); |
242 } | 243 } |
243 else | 244 |
244 { | |
245 folder = parentPath.substr(lastSlash + 1); | |
246 } | |
247 | |
248 std::string href; | 245 std::string href; |
249 Toolbox::UriEncode(href, AddTrailingSlash(parentPath)); | 246 Toolbox::UriEncode(href, Toolbox::FlattenUri(tokens) + "/"); |
250 | 247 |
251 boost::posix_time::ptime now = GetNow(); | 248 boost::posix_time::ptime now = GetNow(); |
252 FormatInternal(self, href, folder, now, now); | 249 FormatInternal(self, href, folder, now, now); |
253 | 250 |
254 pugi::xml_node prop = self.first_element_by_path("D:propstat/D:prop"); | 251 pugi::xml_node prop = self.first_element_by_path("D:propstat/D:prop"); |