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; }
void TorrentGroup::load(bt::BDictNode* dn) { name = QString::fromLocal8Bit(dn->getByteArray("name")); setIconByName(QString::fromLocal8Bit(dn->getByteArray("icon"))); BListNode* ln = dn->getList("hashes"); if (!ln) return; path = "/all/custom/" + name; for (Uint32 i = 0; i < ln->getNumChildren(); i++) { QByteArray ba = ln->getByteArray(i); if (ba.size() != 20) continue; hashes.insert(SHA1Hash((const Uint8*)ba.data())); } BDictNode* gp = dn->getDict(QString("policy")); if (gp) { // load the group policy if (gp->getValue("default_save_location")) { policy.default_save_location = gp->getString("default_save_location", 0); if (policy.default_save_location.length() == 0) policy.default_save_location = QString(); // make sure that 0 length strings are loaded as null strings } if (gp->getValue("default_move_on_completion_location")) { policy.default_move_on_completion_location = gp->getString("default_move_on_completion_location", 0); if (policy.default_move_on_completion_location.length() == 0) policy.default_move_on_completion_location = QString(); // make sure that 0 length strings are loaded as null strings } if (gp->getValue("max_share_ratio")) policy.max_share_ratio = gp->getString("max_share_ratio", 0).toFloat(); if (gp->getValue("max_seed_time")) policy.max_seed_time = gp->getString("max_seed_time", 0).toFloat(); if (gp->getValue("max_upload_rate")) policy.max_upload_rate = gp->getInt("max_upload_rate"); if (gp->getValue("max_download_rate")) policy.max_download_rate = gp->getInt("max_download_rate"); if (gp->getValue("only_apply_on_new_torrents")) policy.only_apply_on_new_torrents = gp->getInt("only_apply_on_new_torrents"); } }