1 /** 2 * Orthanc - A Lightweight, RESTful DICOM Store 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics 4 * Department, University Hospital of Liege, Belgium 5 * Copyright (C) 2017-2020 Osimis S.A., Belgium 6 * 7 * This program is free software: you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public License 9 * as published by the Free Software Foundation, either version 3 of 10 * the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, but 13 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this program. If not, see 19 * <http://www.gnu.org/licenses/>. 20 **/ 21 22 23 #pragma once 24 25 #if !defined(ORTHANC_ENABLE_PUGIXML) 26 # error The macro ORTHANC_ENABLE_PUGIXML must be defined 27 #endif 28 29 #if ORTHANC_ENABLE_PUGIXML != 1 30 # error XML support is required to use this file 31 #endif 32 33 #include "../Compatibility.h" 34 #include "../Enumerations.h" 35 36 #include <boost/date_time/posix_time/posix_time.hpp> 37 #include <boost/noncopyable.hpp> 38 #include <pugixml.hpp> 39 40 #include <list> 41 #include <set> 42 #include <stdint.h> 43 44 namespace Orthanc 45 { 46 class HttpOutput; 47 48 class IWebDavBucket : public boost::noncopyable 49 { 50 public: 51 class Resource : public boost::noncopyable 52 { 53 private: 54 std::string displayName_; 55 bool hasModificationTime_; 56 boost::posix_time::ptime creationTime_; 57 boost::posix_time::ptime modificationTime_; 58 59 public: 60 explicit Resource(const std::string& displayName); 61 ~Resource()62 virtual ~Resource() 63 { 64 } 65 66 void SetCreationTime(const boost::posix_time::ptime& t); 67 68 void SetModificationTime(const boost::posix_time::ptime& t); 69 GetDisplayName()70 const std::string& GetDisplayName() const 71 { 72 return displayName_; 73 } 74 GetCreationTime()75 const boost::posix_time::ptime& GetCreationTime() const 76 { 77 return creationTime_; 78 } 79 GetModificationTime()80 const boost::posix_time::ptime& GetModificationTime() const 81 { 82 return modificationTime_; 83 } 84 85 virtual void Format(pugi::xml_node& node, 86 const std::string& parentPath) const = 0; 87 }; 88 89 90 class File : public Resource 91 { 92 private: 93 uint64_t contentLength_; 94 MimeType mime_; 95 96 public: 97 explicit File(const std::string& displayName); 98 SetContentLength(uint64_t contentLength)99 void SetContentLength(uint64_t contentLength) 100 { 101 contentLength_ = contentLength; 102 } 103 SetMimeType(MimeType mime)104 void SetMimeType(MimeType mime) 105 { 106 mime_ = mime; 107 } 108 GetContentLength()109 uint64_t GetContentLength() const 110 { 111 return contentLength_; 112 } 113 GetMimeType()114 MimeType GetMimeType() const 115 { 116 return mime_; 117 } 118 119 void SetCreated(bool created); 120 121 virtual void Format(pugi::xml_node& node, 122 const std::string& parentPath) const ORTHANC_OVERRIDE; 123 }; 124 125 126 class Folder : public Resource 127 { 128 public: Folder(const std::string & displayName)129 explicit Folder(const std::string& displayName) : 130 Resource(displayName) 131 { 132 } 133 134 virtual void Format(pugi::xml_node& node, 135 const std::string& parentPath) const ORTHANC_OVERRIDE; 136 }; 137 138 139 class Collection : public boost::noncopyable 140 { 141 private: 142 std::list<Resource*> resources_; 143 144 public: 145 ~Collection(); 146 GetSize()147 size_t GetSize() const 148 { 149 return resources_.size(); 150 } 151 152 void ListDisplayNames(std::set<std::string>& target); 153 154 void AddResource(Resource* resource); // Takes ownership 155 156 void Format(std::string& target, 157 const std::string& parentPath) const; 158 }; 159 160 ~IWebDavBucket()161 virtual ~IWebDavBucket() 162 { 163 } 164 165 virtual bool IsExistingFolder(const std::vector<std::string>& path) = 0; 166 167 virtual bool ListCollection(Collection& collection, 168 const std::vector<std::string>& path) = 0; 169 170 virtual bool GetFileContent(MimeType& mime, 171 std::string& content, 172 boost::posix_time::ptime& modificationTime, 173 const std::vector<std::string>& path) = 0; 174 175 // "false" returns indicate a read-only target 176 virtual bool StoreFile(const std::string& content, 177 const std::vector<std::string>& path) = 0; 178 179 virtual bool CreateFolder(const std::vector<std::string>& path) = 0; 180 181 virtual bool DeleteItem(const std::vector<std::string>& path) = 0; 182 183 virtual void Start() = 0; 184 185 // During the shutdown of the Web server, give a chance to the 186 // bucket to end its pending operations 187 virtual void Stop() = 0; 188 189 190 static void AnswerFakedProppatch(HttpOutput& output, 191 const std::string& uri); 192 193 static void AnswerFakedLock(HttpOutput& output, 194 const std::string& uri); 195 196 static void AnswerFakedUnlock(HttpOutput& output); 197 }; 198 } 199