int CDAVFile::Stat(const CURL& url, struct __stat64* buffer) { CCurlFile dav; std::string strRequest = "PROPFIND"; dav.SetCustomRequest(strRequest); dav.SetRequestHeader("depth", 0); return dav.Stat(url, buffer); }
bool CDAVDirectory::Exists(const CURL& url) { CCurlFile dav; // Set the PROPFIND custom request else we may not find folders, depending // on the server's configuration std::string strRequest = "PROPFIND"; dav.SetCustomRequest(strRequest); dav.SetRequestHeader("depth", 0); return dav.Exists(url); }
bool CDAVDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items) { CCurlFile dav; CURL url(strPath); CStdString strRequest = "PROPFIND"; dav.SetCustomRequest(strRequest); dav.SetMimeType("text/xml; charset=\"utf-8\""); dav.SetRequestHeader("depth", 1); dav.SetPostData( "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" " <D:propfind xmlns:D=\"DAV:\">" " <D:prop>" " <D:resourcetype/>" " <D:getcontentlength/>" " <D:getlastmodified/>" " <D:creationdate/>" " <D:displayname/>" " </D:prop>" " </D:propfind>"); if (!dav.Open(url)) { CLog::Log(LOGERROR, "%s - Unable to get dav directory (%s)", __FUNCTION__, strPath.c_str()); return false; } CStdString strResponse; dav.ReadData(strResponse); CXBMCTinyXML davResponse; davResponse.Parse(strResponse.c_str()); if (!davResponse.Parse(strResponse)) { CLog::Log(LOGERROR, "%s - Unable to process dav directory (%s)", __FUNCTION__, strPath.c_str()); dav.Close(); return false; } TiXmlNode *pChild; // Iterate over all responses for (pChild = davResponse.RootElement()->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) { if (CDAVCommon::ValueWithoutNamespace(pChild, "response")) { CFileItem item; ParseResponse(pChild->ToElement(), item); CURL url2(strPath); CURL url3(item.GetPath()); CStdString itemPath(URIUtils::AddFileToFolder(url2.GetWithoutFilename(), url3.GetFileName())); if (item.GetLabel().IsEmpty()) { CStdString name(itemPath); URIUtils::RemoveSlashAtEnd(name); CURL::Decode(name); item.SetLabel(URIUtils::GetFileName(name)); } if (item.m_bIsFolder) URIUtils::AddSlashAtEnd(itemPath); // Add back protocol options if (!url2.GetProtocolOptions().IsEmpty()) itemPath += "|" + url2.GetProtocolOptions(); item.SetPath(itemPath); if (!item.GetPath().Equals(strPath)) { CFileItemPtr pItem(new CFileItem(item)); items.Add(pItem); } } } dav.Close(); return true; }