本文整理汇总了C++中czeroconfbrowser::ZeroconfService::GetTxtRecords方法的典型用法代码示例。如果您正苦于以下问题:C++ ZeroconfService::GetTxtRecords方法的具体用法?C++ ZeroconfService::GetTxtRecords怎么用?C++ ZeroconfService::GetTxtRecords使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类czeroconfbrowser::ZeroconfService
的用法示例。
在下文中一共展示了ZeroconfService::GetTxtRecords方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetDirectoryFromTxtRecords
bool GetDirectoryFromTxtRecords(const CZeroconfBrowser::ZeroconfService& zeroconf_service, CURL& url, CFileItemList &items)
{
bool ret = false;
//get the txt-records from this service
CZeroconfBrowser::ZeroconfService::tTxtRecordMap txtRecords=zeroconf_service.GetTxtRecords();
//if we have some records
if(!txtRecords.empty())
{
std::string path;
std::string username;
std::string password;
//search for a path key entry
CZeroconfBrowser::ZeroconfService::tTxtRecordMap::iterator it = txtRecords.find(TXT_RECORD_PATH_KEY);
//if we found the key - be sure there is a value there
if( it != txtRecords.end() && !it->second.empty() )
{
//from now on we treat the value as a path - everything else would mean
//a missconfigured zeroconf server.
path=it->second;
}
//search for a username key entry
it = txtRecords.find(TXT_RECORD_USERNAME_KEY);
//if we found the key - be sure there is a value there
if( it != txtRecords.end() && !it->second.empty() )
{
username=it->second;
url.SetUserName(username);
}
//search for a password key entry
it = txtRecords.find(TXT_RECORD_PASSWORD_KEY);
//if we found the key - be sure there is a value there
if( it != txtRecords.end() && !it->second.empty() )
{
password=it->second;
url.SetPassword(password);
}
//if we got a path - add a item - else at least we maybe have set username and password to theurl
if( !path.empty())
{
CFileItemPtr item(new CFileItem("", true));
std::string urlStr(url.Get());
//if path has a leading slash (sure it should have one)
if( path.at(0) == '/' )
{
URIUtils::RemoveSlashAtEnd(urlStr);//we don't need the slash at and of url then
}
else//path doesn't start with slash -
{//this is some kind of missconfiguration - we fix it by adding a slash to the url
URIUtils::AddSlashAtEnd(urlStr);
}
//add slash at end of path since it has to be a folder
URIUtils::AddSlashAtEnd(path);
//this is the full path includeing remote stuff (e.x. nfs://ip/path
item->SetPath(urlStr + path);
//remove the slash at the end of the path or GetFileName will not give the last dir
URIUtils::RemoveSlashAtEnd(path);
//set the label to the last directory in path
if( !URIUtils::GetFileName(path).empty() )
item->SetLabel(URIUtils::GetFileName(path));
else
item->SetLabel("/");
item->SetLabelPreformated(true);
//just set the default folder icon
item->FillInDefaultIcon();
item->m_bIsShareOrDrive=true;
items.Add(item);
ret = true;
}
}
return ret;
}