本文整理汇总了C++中CFileCurl::ReadString方法的典型用法代码示例。如果您正苦于以下问题:C++ CFileCurl::ReadString方法的具体用法?C++ CFileCurl::ReadString怎么用?C++ CFileCurl::ReadString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CFileCurl
的用法示例。
在下文中一共展示了CFileCurl::ReadString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetDirectory
bool CFTPDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
{
CFileCurl reader;
CURL url(strPath);
CStdString path = url.GetFileName();
if( !path.IsEmpty() && !path.Right(1).Equals("/") )
{
path += "/";
url.SetFileName(path);
}
if (!reader.Open(url))
return false;
char buffer[MAX_PATH + 1024];
while( reader.ReadString(buffer, sizeof(buffer)) )
{
CStdString strBuffer = buffer;
StringUtils::RemoveCRLF(strBuffer);
CFTPParse parse;
if (parse.FTPParse(strBuffer))
{
if( parse.getName().length() == 0 )
continue;
if( parse.getFlagtrycwd() == 0 && parse.getFlagtryretr() == 0 )
continue;
/* buffer name */
CStdString name;
name.assign(parse.getName());
if( name.Equals("..") || name.Equals(".") )
continue;
/* this should be conditional if we ever add */
/* support for the utf8 extension in ftp client */
g_charsetConverter.unknownToUTF8(name);
CFileItemPtr pItem(new CFileItem(name));
pItem->m_strPath = path + name;
pItem->m_bIsFolder = (bool)(parse.getFlagtrycwd() != 0);
if (pItem->m_bIsFolder)
CUtil::AddSlashAtEnd(pItem->m_strPath);
/* qualify the url with host and all */
url.SetFileName(pItem->m_strPath);
pItem->m_strPath = url.Get();
pItem->m_dwSize = parse.getSize();
pItem->m_dateTime=parse.getTime();
items.Add(pItem);
}
}
return true;
}
示例2: GetDirectory
bool CDAVDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
{
CFileCurl 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;
}
char buffer[MAX_PATH + 1024];
CStdString strResponse;
CStdString strHeader;
while (dav.ReadString(buffer, sizeof(buffer)))
{
if (strstr(buffer, "<D:response") != NULL)
{
// The header should contain the xml version/utf encoding line
// followed by the <multistatus> tag
if (strHeader.IsEmpty())
strHeader = strResponse;
strResponse = strHeader;
}
strResponse.append(buffer, strlen(buffer));
if (strstr(buffer, "</D:response") != NULL)
{
// Close the multistatus tag from the header
if (strHeader.Find("<D:multistatus"))
strResponse+="</D:multistatus>\n";
TiXmlDocument davResponse;
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 (ValueWithoutNamespace(pChild, "response"))
{
CFileItem item;
ParseResponse(pChild->ToElement(), item);
CURL url2(strPath);
CURL url3(item.m_strPath);
URIUtils::AddFileToFolder(url2.GetWithoutFilename(), url3.GetFileName(), item.m_strPath);
if (item.GetLabel().IsEmpty())
{
CStdString name(item.m_strPath);
URIUtils::RemoveSlashAtEnd(name);
CURL::Decode(name);
item.SetLabel(URIUtils::GetFileName(name));
}
if (item.m_bIsFolder)
URIUtils::AddSlashAtEnd(item.m_strPath);
// Add back protocol options
if (!url2.GetProtocolOptions().IsEmpty())
item.m_strPath += "|" + url2.GetProtocolOptions();
if (!item.m_strPath.Equals(strPath))
{
CFileItemPtr pItem(new CFileItem(item));
items.Add(pItem);
}
}
}
strResponse.clear();
}
}
dav.Close();
return true;
//.........这里部分代码省略.........
示例3: GetDirectory
bool CFTPDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
{
CFileCurl reader;
CURL url(strPath);
CStdString path = url.GetFileName();
if( !path.IsEmpty() && !path.Right(1).Equals("/") )
{
path += "/";
url.SetFileName(path);
}
if (!reader.Open(url))
return false;
char buffer[MAX_PATH + 1024];
while( reader.ReadString(buffer, sizeof(buffer)) )
{
CStdString strBuffer = buffer;
StringUtils::RemoveCRLF(strBuffer);
struct ftpparse lp = {};
if (ftpparse(&lp, (char*)strBuffer.c_str(), strBuffer.size()) == 1)
{
if( lp.namelen == 0 )
continue;
if( lp.flagtrycwd == 0 && lp.flagtryretr == 0 )
continue;
/* buffer name as it's not allways null terminated */
CStdString name;
name.assign(lp.name, lp.namelen);
if( name.Equals("..") || name.Equals(".") )
continue;
/* this should be conditional if we ever add */
/* support for the utf8 extension in ftp client */
g_charsetConverter.stringCharsetToUtf8(name);
CFileItemPtr pItem(new CFileItem(name));
pItem->m_strPath = path + name;
pItem->m_bIsFolder = (bool)(lp.flagtrycwd != 0);
if (pItem->m_bIsFolder)
if (!CUtil::HasSlashAtEnd(pItem->m_strPath)) pItem->m_strPath += "/";
/* qualify the url with host and all */
url.SetFileName(pItem->m_strPath);
url.GetURL(pItem->m_strPath);
pItem->m_dwSize = lp.size;
pItem->m_dateTime=lp.mtime;
items.Add(pItem);
}
}
return true;
}
示例4: GetDirectory
bool CHTTPDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
{
CFileCurl http;
CURL url(strPath);
CStdString strName, strLink;
CStdString strBasePath = url.GetFileName();
if(!http.Open(url, false))
{
CLog::Log(LOGERROR, "%s - Unable to get http directory", __FUNCTION__);
return false;
}
CRegExp reItem;
reItem.RegComp("<a href=\"(.*)\">(.*)</a>");
/* read response from server into string buffer */
char buffer[MAX_PATH + 1024];
while(http.ReadString(buffer, sizeof(buffer)-1))
{
CStdString strBuffer = buffer;
StringUtils::RemoveCRLF(strBuffer);
if (reItem.RegFind(strBuffer.c_str()) >= 0)
{
strLink = reItem.GetReplaceString("\\1");
strName = reItem.GetReplaceString("\\2");
if(strLink[0] == '/')
strLink = strLink.Mid(1);
CStdString strNameTemp = strName.Trim();
CStdString strLinkTemp = strLink;
CUtil::RemoveSlashAtEnd(strLinkTemp);
CUtil::RemoveSlashAtEnd(strNameTemp);
CUtil::UrlDecode(strLinkTemp);
if (strNameTemp == strLinkTemp)
{
g_charsetConverter.stringCharsetToUtf8(strName);
CUtil::RemoveSlashAtEnd(strName);
CFileItemPtr pItem(new CFileItem(strName));
pItem->m_strPath = strBasePath + strLink;
if(CUtil::HasSlashAtEnd(pItem->m_strPath))
pItem->m_bIsFolder = true;
url.SetFileName(pItem->m_strPath);
url.GetURL(pItem->m_strPath);
if (!pItem->m_bIsFolder && g_advancedSettings.m_bHTTPDirectoryStatFilesize)
{
CFileCurl file;
file.Open(url, false);
pItem->m_dwSize= file.GetLength();
file.Close();
}
if (!pItem->m_bIsFolder && pItem->m_dwSize == 0)
{
CRegExp reSize;
reSize.RegComp(">([0-9.]+)(K|M|G)</td>");
if (reSize.RegFind(strBuffer.c_str()) >= 0)
{
double Size = atof(reSize.GetReplaceString("\\1"));
CStdString strUnit = reSize.GetReplaceString("\\2");
if (strUnit == "M")
Size = Size * 1024;
else if (strUnit == "G")
Size = Size * 1000 * 1024;
pItem->m_dwSize = (__int64)(Size * 1024);
}
}
items.Add(pItem);
}
}
}
http.Close();
return true;
}