本文整理汇总了C++中BNode::getType方法的典型用法代码示例。如果您正苦于以下问题:C++ BNode::getType方法的具体用法?C++ BNode::getType怎么用?C++ BNode::getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BNode
的用法示例。
在下文中一共展示了BNode::getType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handlePexPacket
void UTPex::handlePexPacket(const Uint8* packet,Uint32 size)
{
if (size <= 2 || packet[1] != 1)
return;
QByteArray tmp;
tmp.setRawData((const char*)packet,size);
BNode* node = 0;
try
{
BDecoder dec(tmp,false,2);
node = dec.decode();
if (node && node->getType() == BNode::DICT)
{
BDictNode* dict = (BDictNode*)node;
// ut_pex packet, emit signal to notify PeerManager
BValueNode* val = dict->getValue("added");
if (val)
{
QByteArray data = val->data().toByteArray();
peer->emitPex(data);
}
}
}
catch (...)
{
// just ignore invalid packets
Out(SYS_CON|LOG_DEBUG) << "Invalid extended packet" << endl;
}
delete node;
tmp.resetRawData((const char*)packet,size);
}
示例2: onScrapeResult
void HTTPTracker::onScrapeResult(KJob* j)
{
if (j->error())
{
Out(SYS_TRK | LOG_IMPORTANT) << "Scrape failed : " << j->errorString() << endl;
return;
}
KIO::StoredTransferJob* st = (KIO::StoredTransferJob*)j;
BDecoder dec(st->data(), false, 0);
BNode* n = 0;
try
{
n = dec.decode();
}
catch (bt::Error & err)
{
Out(SYS_TRK | LOG_IMPORTANT) << "Invalid scrape data " << err.toString() << endl;
return;
}
if (n && n->getType() == BNode::DICT)
{
BDictNode* d = (BDictNode*)n;
d = d->getDict(QString("files"));
if (d)
{
d = d->getDict(tds->infoHash().toByteArray());
if (d)
{
try
{
seeders = d->getInt("complete");
leechers = d->getInt("incomplete");
total_downloaded = d->getInt("downloaded");
supports_partial_seed_extension = d->getValue("downloaders") != 0;
Out(SYS_TRK | LOG_DEBUG) << "Scrape : leechers = " << leechers
<< ", seeders = " << seeders << ", downloaded = " << total_downloaded << endl;
}
catch (...)
{}
scrapeDone();
if (status == bt::TRACKER_ERROR)
{
status = bt::TRACKER_OK;
failures = 0;
}
}
}
}
delete n;
}
示例3: onScrapeResult
void HTTPTracker::onScrapeResult(KIO::Job* j)
{
if (j->error())
{
Out(SYS_TRK|LOG_IMPORTANT) << "Scrape failed : " << j->errorString() << endl;
return;
}
KIO::StoredTransferJob* st = (KIO::StoredTransferJob*)j;
BDecoder dec(st->data(),false,0);
BNode* n = 0;
try
{
n = dec.decode();
}
catch (bt::Error & err)
{
Out(SYS_TRK|LOG_IMPORTANT) << "Invalid scrape data " << err.toString() << endl;
return;
}
if (n && n->getType() == BNode::DICT)
{
BDictNode* d = (BDictNode*)n;
d = d->getDict("files");
if (d)
{
d = d->getDict(tor->getInfoHash().toByteArray());
if (d)
{
BValueNode* vn = d->getValue("complete");
if (vn && vn->data().getType() == Value::INT)
{
seeders = vn->data().toInt();
}
vn = d->getValue("incomplete");
if (vn && vn->data().getType() == Value::INT)
{
leechers = vn->data().toInt();
}
Out(SYS_TRK|LOG_DEBUG) << "Scrape : leechers = " << leechers
<< ", seeders = " << seeders << endl;
}
}
}
delete n;
}
示例4: loadFilters
void FilterList::loadFilters(const QString& file)
{
QFile fptr(file);
if (!fptr.open(QIODevice::ReadOnly))
{
Out(SYS_SYN | LOG_DEBUG) << "Failed to open " << file << " : " << fptr.errorString() << endl;
return;
}
QByteArray data = fptr.readAll();
BDecoder dec(data, false);
BNode* n = 0;
try
{
n = dec.decode();
if (!n || n->getType() != BNode::LIST)
{
delete n;
return;
}
BListNode* ln = (BListNode*)n;
for (Uint32 i = 0; i < ln->getNumChildren(); i++)
{
BDictNode* dict = ln->getDict(i);
if (dict)
{
Filter* filter = new Filter();
if (filter->load(dict))
addFilter(filter);
else
delete filter;
}
}
}
catch (bt::Error& err)
{
Out(SYS_SYN | LOG_DEBUG) << "Failed to parse " << file << " : " << err.toString() << endl;
}
delete n;
}
示例5: load
void ShutdownRuleSet::load(const QString& file)
{
QFile fptr(file);
if (!fptr.open(QIODevice::ReadOnly))
{
Out(SYS_GEN|LOG_DEBUG) << "Failed to open file " << file << " : " << fptr.errorString() << endl;
return;
}
QByteArray data = fptr.readAll();
BDecoder dec(data,false);
BNode* node = 0;
try
{
clear();
node = dec.decode();
if (!node || node->getType() != BNode::LIST)
throw bt::Error("Toplevel node not a list");
BListNode* const l = (BListNode*)node;
Uint32 i = 0;
for (;i < l->getNumChildren();++i)
{
if (l->getChild(i)->getType() != BNode::DICT)
break;
BDictNode* const d = l->getDict(i);
if (!d)
continue;
ShutdownRule rule;
rule.action = (Action)d->getInt("Action");
rule.target = (Target)d->getInt("Target");
rule.trigger = (Trigger)d->getInt("Trigger");
rule.hit = d->keys().contains("hit") && d->getInt("hit") == 1;
rule.tc = 0;
if (d->getValue("Torrent"))
{
const QByteArray hash = d->getByteArray("Torrent");
bt::TorrentInterface* const tc = torrentForHash(hash);
if (tc)
rule.tc = tc;
else
continue; // no valid torrent found so skip this rule
}
rules.append(rule);
}
on = (l->getInt(i++) == 1);
if (i < l->getNumChildren())
all_rules_must_be_hit = (l->getInt(i) == 1);
else
all_rules_must_be_hit = false;
}
catch (bt::Error & err)
{
Out(SYS_GEN|LOG_DEBUG) << "Failed to parse " << file << " : " << err.toString() << endl;
}
delete node;
}
示例6: updateData
bool HTTPTracker::updateData(const QByteArray & data)
{
//#define DEBUG_PRINT_RESPONSE
#ifdef DEBUG_PRINT_RESPONSE
Out() << "Data : " << endl;
Out() << QString(data) << endl;
#endif
// search for dictionary, there might be random garbage infront of the data
Uint32 i = 0;
while (i < data.size())
{
if (data[i] == 'd')
break;
i++;
}
if (i == data.size())
{
failures++;
requestFailed(i18n("Invalid response from tracker"));
return false;
}
BDecoder dec(data,false,i);
BNode* n = 0;
try
{
n = dec.decode();
}
catch (...)
{
failures++;
requestFailed(i18n("Invalid data from tracker"));
return false;
}
if (!n || n->getType() != BNode::DICT)
{
failures++;
requestFailed(i18n("Invalid response from tracker"));
return false;
}
BDictNode* dict = (BDictNode*)n;
if (dict->getData("failure reason"))
{
BValueNode* vn = dict->getValue("failure reason");
QString msg = vn->data().toString();
delete n;
failures++;
requestFailed(msg);
return false;
}
BValueNode* vn = dict->getValue("interval");
// if no interval is specified, use 5 minutes
if (vn)
interval = vn->data().toInt();
else
interval = 5 * 60;
vn = dict->getValue("incomplete");
if (vn)
leechers = vn->data().toInt();
vn = dict->getValue("complete");
if (vn)
seeders = vn->data().toInt();
BListNode* ln = dict->getList("peers");
if (!ln)
{
// no list, it might however be a compact response
vn = dict->getValue("peers");
if (!vn)
{
delete n;
failures++;
requestFailed(i18n("Invalid response from tracker"));
return false;
}
QByteArray arr = vn->data().toByteArray();
for (Uint32 i = 0; i < arr.size(); i+=6)
{
Uint8 buf[6];
for (int j = 0; j < 6; j++)
buf[j] = arr[i + j];
addPeer(QHostAddress(ReadUint32(buf,0)).toString(),ReadUint16(buf,4));
}
}
else
{
for (Uint32 i = 0; i < ln->getNumChildren(); i++)
{
BDictNode* dict = dynamic_cast<BDictNode*>(ln->getChild(i));
if (!dict)
//.........这里部分代码省略.........
示例7: updateData
bool HTTPTracker::updateData(const QByteArray & data)
{
//#define DEBUG_PRINT_RESPONSE
#ifdef DEBUG_PRINT_RESPONSE
Out(SYS_TRK | LOG_DEBUG) << "Data : " << endl;
Out(SYS_TRK | LOG_DEBUG) << QString(data) << endl;
#endif
// search for dictionary, there might be random garbage infront of the data
int i = 0;
while (i < data.size())
{
if (data[i] == 'd')
break;
i++;
}
if (i == data.size())
{
failures++;
failed(i18n("Invalid response from tracker"));
return false;
}
BDecoder dec(data, false, i);
BNode* n = 0;
try
{
n = dec.decode();
}
catch (...)
{
failures++;
failed(i18n("Invalid data from tracker"));
return false;
}
if (!n || n->getType() != BNode::DICT)
{
failures++;
failed(i18n("Invalid response from tracker"));
return false;
}
BDictNode* dict = (BDictNode*)n;
if (dict->getData("failure reason"))
{
BValueNode* vn = dict->getValue("failure reason");
error = vn->data().toString();
delete n;
failures++;
failed(error);
return false;
}
if (dict->getData("warning message"))
{
BValueNode* vn = dict->getValue("warning message");
warning = vn->data().toString();
}
else
warning.clear();
BValueNode* vn = dict->getValue("interval");
// if no interval is specified, use 5 minutes
if (vn)
interval = vn->data().toInt();
else
interval = 5 * 60;
vn = dict->getValue("incomplete");
if (vn)
leechers = vn->data().toInt();
vn = dict->getValue("complete");
if (vn)
seeders = vn->data().toInt();
BListNode* ln = dict->getList("peers");
if (!ln)
{
// no list, it might however be a compact response
vn = dict->getValue("peers");
if (vn && vn->data().getType() == Value::STRING)
{
QByteArray arr = vn->data().toByteArray();
for (int i = 0;i < arr.size();i += 6)
{
Uint8 buf[6];
for (int j = 0;j < 6;j++)
buf[j] = arr[i + j];
Uint32 ip = ReadUint32(buf, 0);
addPeer(net::Address(ip, ReadUint16(buf, 4)), false);
}
}
}
else
{
for (Uint32 i = 0;i < ln->getNumChildren();i++)
//.........这里部分代码省略.........