Commit 596e4223 authored by Paweł Wegner's avatar Paweł Wegner

WebDav: implemented getGeneralData.

parent a6b5757e
...@@ -153,6 +153,20 @@ IHttpRequest::Pointer WebDav::renameItemRequest(const IItem& item, ...@@ -153,6 +153,20 @@ IHttpRequest::Pointer WebDav::renameItemRequest(const IItem& item,
return request; return request;
} }
IHttpRequest::Pointer WebDav::getGeneralDataRequest(
std::ostream& stream) const {
auto request = http()->create(endpoint() + "/", "PROPFIND");
request->setHeaderParameter("Depth", "0");
request->setHeaderParameter("Content-Type", "text/xml");
stream << "<D:propfind xmlns:D=\"DAV:\">"
" <D:prop>"
" <D:quota-available-bytes/>"
" <D:quota-used-bytes/>"
" </D:prop>"
"</D:propfind>";
return request;
}
IItem::Pointer WebDav::uploadFileResponse(const IItem& item, IItem::Pointer WebDav::uploadFileResponse(const IItem& item,
const std::string& filename, const std::string& filename,
uint64_t size, std::istream&) const { uint64_t size, std::istream&) const {
...@@ -161,6 +175,33 @@ IItem::Pointer WebDav::uploadFileResponse(const IItem& item, ...@@ -161,6 +175,33 @@ IItem::Pointer WebDav::uploadFileResponse(const IItem& item,
IItem::FileType::Unknown); IItem::FileType::Unknown);
} }
GeneralData WebDav::getGeneralDataResponse(std::istream& stream) const {
std::stringstream sstream;
sstream << stream.rdbuf();
tinyxml2::XMLDocument document;
if (document.Parse(sstream.str().c_str(), sstream.str().size()) !=
tinyxml2::XML_SUCCESS)
throw std::logic_error("failed to parse xml");
auto response = document.RootElement()->FirstChildElement("d:response");
if (!response) throw std::logic_error("invalid xml");
auto propstat = response->FirstChildElement("d:propstat");
if (!propstat) throw std::logic_error("invalid xml");
auto prop = propstat->FirstChildElement("d:prop");
if (!prop) throw std::logic_error("invalid xml");
auto quota_used = prop->FirstChildElement("d:quota-used-bytes");
auto quota_available = prop->FirstChildElement("d:quota-available-bytes");
if (!quota_used || !quota_available) throw std::logic_error("invalid xml");
GeneralData data;
data.space_used_ = std::stoull(quota_used->GetText());
data.space_total_ = std::stoull(quota_available->GetText());
auto lock = auth_lock();
auto url = util::Url(webdav_url_);
data.username_ = url.protocol() + "://" + user_ + "@" + url.host() +
(url.path().empty() ? "" : "/" + url.path()) +
(url.query().empty() ? "" : "?" + url.query());
return data;
}
IItem::Pointer WebDav::getItemDataResponse(std::istream& stream) const { IItem::Pointer WebDav::getItemDataResponse(std::istream& stream) const {
std::stringstream sstream; std::stringstream sstream;
sstream << stream.rdbuf(); sstream << stream.rdbuf();
......
...@@ -72,6 +72,7 @@ class WebDav : public CloudProvider { ...@@ -72,6 +72,7 @@ class WebDav : public CloudProvider {
std::ostream&) const override; std::ostream&) const override;
IHttpRequest::Pointer renameItemRequest(const IItem&, const std::string& name, IHttpRequest::Pointer renameItemRequest(const IItem&, const std::string& name,
std::ostream&) const override; std::ostream&) const override;
IHttpRequest::Pointer getGeneralDataRequest(std::ostream&) const override;
IItem::Pointer getItemDataResponse(std::istream& response) const override; IItem::Pointer getItemDataResponse(std::istream& response) const override;
std::vector<IItem::Pointer> listDirectoryResponse( std::vector<IItem::Pointer> listDirectoryResponse(
...@@ -87,6 +88,7 @@ class WebDav : public CloudProvider { ...@@ -87,6 +88,7 @@ class WebDav : public CloudProvider {
IItem::Pointer uploadFileResponse(const IItem& parent, IItem::Pointer uploadFileResponse(const IItem& parent,
const std::string& filename, uint64_t, const std::string& filename, uint64_t,
std::istream& response) const override; std::istream& response) const override;
GeneralData getGeneralDataResponse(std::istream& response) const override;
IItem::Pointer toItem(const tinyxml2::XMLNode*) const; IItem::Pointer toItem(const tinyxml2::XMLNode*) const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment