本文整理汇总了C++中XmlParser::GetRoot方法的典型用法代码示例。如果您正苦于以下问题:C++ XmlParser::GetRoot方法的具体用法?C++ XmlParser::GetRoot怎么用?C++ XmlParser::GetRoot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlParser
的用法示例。
在下文中一共展示了XmlParser::GetRoot方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetWorkUnit
/*!
@brief Retrieves a work unit from the controller.
@param wu Object to store the work unit in
@param alglist List of algorithms supported
@return True if a work unit was successfully retrieved, false if no work is available
*/
bool ControllerLink::GetWorkUnit(WorkUnit& wu, const vector<string>& alglist)
{
//Initialize default values
wu.m_bCracked.clear();
wu.m_hashvalues.clear();
wu.m_hashids.clear();
wu.m_collisions.clear();
//Generate algorithm list
string algs = "";
for(unsigned int i=0; i<alglist.size(); i++)
{
if(i != 0)
algs += ",";
algs += alglist[i];
}
//Format our request
string request = g_server + "agents/getwu?version=3.2&hostname=" + g_hostname + "&type=" + m_type + "&num=" + m_num + "&accept-algorithms=" + algs;
//Send to the server
string recvdata;
curl_easy_reset(m_pCurl);
curl_easy_setopt(m_pCurl, CURLOPT_NOPROGRESS, 1);
curl_easy_setopt(m_pCurl, CURLOPT_WRITEFUNCTION, curlwritecallback);
curl_easy_setopt(m_pCurl, CURLOPT_WRITEDATA, &recvdata);
curl_easy_setopt(m_pCurl, CURLOPT_URL, request.c_str());
curl_easy_setopt(m_pCurl, CURLOPT_SSL_VERIFYPEER, 0); //TODO: control this by command line arg
if(0 != curl_easy_perform(m_pCurl))
ThrowError("libcurl error");
//Parse XML
XmlParser* parser = NULL;
try
{
parser = new XmlParser(recvdata);
}
catch(std::string err)
{
cerr << "Failed to parse work unit! Expected well formed XML, got:" << endl;
string str = recvdata.substr(0, 256);
cerr << str.c_str() << endl;
return false;
}
//Process it
const XmlNode* pRoot = parser->GetRoot();
if(pRoot == NULL)
{
cerr << "Failed to parse work (no root node):" << endl;
string str = recvdata.substr(0, 256);
cerr << str.c_str() << endl;
return false;
}
if(pRoot->GetType() == "workunit")
{
//Work unit, process it
//TODO: Add more sanity checking (e.g. can only have one of each tag other than <hash> per work unit)
for(unsigned int i=0; i<pRoot->GetChildCount(); i++)
{
//Skip the node if it's not a tag
const XmlNode* pNode = pRoot->GetChildNode(i);
if(pNode->GetNodeType() != XmlNode::NODETYPE_TAG)
continue;
//Must have one and only one child
if(pNode->GetChildCount() != 1)
continue;
//Get the item
string type = pNode->GetType();
//Get the child and validate it
const XmlNode* pData = pNode->GetChildNode(0);
if(pData->GetNodeType() != XmlNode::NODETYPE_TEXT)
continue;
//Get the value
string txt = pData->GetBody();
//Process it
if(type == "id")
wu.m_id = txt;
else if(type == "algorithm")
wu.m_algorithm = txt;
else if(type == "charset")
{
//Decode the character set
wu.m_charset = "";
for(unsigned int j=0; j<txt.length(); j++)
{
char code = txt[j];
//.........这里部分代码省略.........