mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-13 13:42:30 +00:00
* Proper fault handling for bad SCGI requests.
* Cleaned up duplicate code in 'xmlrpc.cc'. * Cleaned up 'parse_commands.h'. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@966 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
+1
-1
@@ -25,7 +25,7 @@ TORRENT_WITHOUT_NCURSESW()
|
||||
TORRENT_WITHOUT_STATVFS()
|
||||
TORRENT_WITHOUT_STATFS()
|
||||
|
||||
PKG_CHECK_MODULES(STUFF, sigc++-2.0 libcurl >= 7.12.0 libtorrent >= 0.11.6,
|
||||
PKG_CHECK_MODULES(STUFF, sigc++-2.0 libcurl >= 7.12.0 libtorrent >= 0.11.8,
|
||||
CXXFLAGS="$CXXFLAGS $STUFF_CFLAGS";
|
||||
LIBS="$LIBS $STUFF_LIBS")
|
||||
|
||||
|
||||
@@ -102,21 +102,21 @@ apply_d_change_link(int changeType, core::Download* download, const torrent::Obj
|
||||
std::string link;
|
||||
|
||||
if (type == "base_path") {
|
||||
target = rpc::call_command_d_string("d.get_base_path", download);
|
||||
link = rak::path_expand(prefix + rpc::call_command_d_string("d.get_base_path", download) + postfix);
|
||||
target = rpc::call_command_string("d.get_base_path", rpc::make_target(download));
|
||||
link = rak::path_expand(prefix + rpc::call_command_string("d.get_base_path", rpc::make_target(download)) + postfix);
|
||||
|
||||
} else if (type == "base_filename") {
|
||||
target = rpc::call_command_d_string("d.get_base_path", download);
|
||||
link = rak::path_expand(prefix + rpc::call_command_d_string("d.get_base_filename", download) + postfix);
|
||||
target = rpc::call_command_string("d.get_base_path", rpc::make_target(download));
|
||||
link = rak::path_expand(prefix + rpc::call_command_string("d.get_base_filename", rpc::make_target(download)) + postfix);
|
||||
|
||||
} else if (type == "tied") {
|
||||
link = rak::path_expand(rpc::call_command_d_string("d.get_tied_to_file", download));
|
||||
link = rak::path_expand(rpc::call_command_string("d.get_tied_to_file", rpc::make_target(download)));
|
||||
|
||||
if (link.empty())
|
||||
return torrent::Object();
|
||||
|
||||
link = rak::path_expand(prefix + link + postfix);
|
||||
target = rpc::call_command_d_string("d.get_base_path", download);
|
||||
target = rpc::call_command_string("d.get_base_path", rpc::make_target(download));
|
||||
|
||||
} else {
|
||||
throw torrent::input_error("Unknown type argument.");
|
||||
@@ -150,7 +150,7 @@ apply_d_change_link(int changeType, core::Download* download, const torrent::Obj
|
||||
|
||||
void
|
||||
apply_d_delete_tied(core::Download* download) {
|
||||
const std::string& tie = rpc::call_command_d_string("d.get_tied_to_file", download);
|
||||
const std::string& tie = rpc::call_command_string("d.get_tied_to_file", rpc::make_target(download));
|
||||
|
||||
if (tie.empty())
|
||||
return;
|
||||
@@ -158,7 +158,7 @@ apply_d_delete_tied(core::Download* download) {
|
||||
if (::unlink(rak::path_expand(tie).c_str()) == -1)
|
||||
control->core()->push_log_std("Could not unlink tied file: " + std::string(rak::error_number::current().c_str()));
|
||||
|
||||
rpc::call_command_d("d.set_tied_to_file", download, std::string());
|
||||
rpc::call_command("d.set_tied_to_file", std::string(), rpc::make_target(download));
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
+11
-11
@@ -105,7 +105,7 @@ apply_stop_on_ratio(const torrent::Object& rawArgs) {
|
||||
if ((totalUpload >= minUpload && totalUpload * 100 >= totalDone * minRatio) ||
|
||||
(maxRatio > 0 && totalUpload * 100 > totalDone * maxRatio)) {
|
||||
downloadList->stop_try(*itr);
|
||||
rpc::call_command_d("d.set_ignore_commands", *itr, (int64_t)1);
|
||||
rpc::call_command("d.set_ignore_commands", (int64_t)1, rpc::make_target(*itr));
|
||||
}
|
||||
|
||||
++itr;
|
||||
@@ -117,14 +117,14 @@ apply_stop_on_ratio(const torrent::Object& rawArgs) {
|
||||
torrent::Object
|
||||
apply_start_tied() {
|
||||
for (core::DownloadList::iterator itr = control->core()->download_list()->begin(); itr != control->core()->download_list()->end(); ++itr) {
|
||||
if (rpc::call_command_d_value("d.get_state", *itr) == 1)
|
||||
if (rpc::call_command_value("d.get_state", rpc::make_target(*itr)) == 1)
|
||||
continue;
|
||||
|
||||
rak::file_stat fs;
|
||||
const std::string& tiedToFile = rpc::call_command_d_string("d.get_tied_to_file", *itr);
|
||||
const std::string& tiedToFile = rpc::call_command_string("d.get_tied_to_file", rpc::make_target(*itr));
|
||||
|
||||
if (!tiedToFile.empty() && fs.update(rak::path_expand(tiedToFile)))
|
||||
control->core()->download_list()->start_try(*itr);
|
||||
control->core()->download_list()->start_normal(*itr);
|
||||
}
|
||||
|
||||
return torrent::Object();
|
||||
@@ -133,14 +133,14 @@ apply_start_tied() {
|
||||
torrent::Object
|
||||
apply_stop_untied() {
|
||||
for (core::DownloadList::iterator itr = control->core()->download_list()->begin(); itr != control->core()->download_list()->end(); ++itr) {
|
||||
if (rpc::call_command_d_value("d.get_state", *itr) == 0)
|
||||
if (rpc::call_command_value("d.get_state", rpc::make_target(*itr)) == 0)
|
||||
continue;
|
||||
|
||||
rak::file_stat fs;
|
||||
const std::string& tiedToFile = rpc::call_command_d_string("d.get_tied_to_file", *itr);
|
||||
const std::string& tiedToFile = rpc::call_command_string("d.get_tied_to_file", rpc::make_target(*itr));
|
||||
|
||||
if (!tiedToFile.empty() && !fs.update(rak::path_expand(tiedToFile)))
|
||||
control->core()->download_list()->stop_try(*itr);
|
||||
control->core()->download_list()->stop_normal(*itr);
|
||||
}
|
||||
|
||||
return torrent::Object();
|
||||
@@ -150,9 +150,9 @@ torrent::Object
|
||||
apply_close_untied() {
|
||||
for (core::DownloadList::iterator itr = control->core()->download_list()->begin(); itr != control->core()->download_list()->end(); ++itr) {
|
||||
rak::file_stat fs;
|
||||
const std::string& tiedToFile = rpc::call_command_d_string("d.get_tied_to_file", *itr);
|
||||
const std::string& tiedToFile = rpc::call_command_string("d.get_tied_to_file", rpc::make_target(*itr));
|
||||
|
||||
if (!tiedToFile.empty() && !fs.update(rak::path_expand(tiedToFile)) && control->core()->download_list()->stop_try(*itr))
|
||||
if (!tiedToFile.empty() && !fs.update(rak::path_expand(tiedToFile)))
|
||||
control->core()->download_list()->close(*itr);
|
||||
}
|
||||
|
||||
@@ -163,11 +163,11 @@ torrent::Object
|
||||
apply_remove_untied() {
|
||||
for (core::DownloadList::iterator itr = control->core()->download_list()->begin(); itr != control->core()->download_list()->end(); ) {
|
||||
rak::file_stat fs;
|
||||
const std::string& tiedToFile = rpc::call_command_d_string("d.get_tied_to_file", *itr);
|
||||
const std::string& tiedToFile = rpc::call_command_string("d.get_tied_to_file", rpc::make_target(*itr));
|
||||
|
||||
if (!tiedToFile.empty() && !fs.update(rak::path_expand(tiedToFile))) {
|
||||
// Need to clear tied_to_file so it doesn't try to delete it.
|
||||
rpc::call_command_d("d.set_tied_to_file", *itr, std::string());
|
||||
rpc::call_command("d.set_tied_to_file", std::string(), rpc::make_target(*itr));
|
||||
|
||||
itr = control->core()->download_list()->erase(itr);
|
||||
|
||||
|
||||
+2
-10
@@ -165,19 +165,11 @@ initialize_xmlrpc() {
|
||||
|
||||
unsigned int count = 0;
|
||||
|
||||
for (rpc::CommandMap::const_iterator itr = rpc::commands.begin(), last = rpc::commands.end(); itr != last; itr++) {
|
||||
for (rpc::CommandMap::const_iterator itr = rpc::commands.begin(), last = rpc::commands.end(); itr != last; itr++, count++) {
|
||||
if (!(itr->second.m_flags & rpc::CommandMap::flag_public_xmlrpc))
|
||||
continue;
|
||||
|
||||
switch (itr->second.m_target) {
|
||||
case rpc::CommandMap::target_generic: rpc::xmlrpc.insert_command(itr->first, itr->second.m_parm, itr->second.m_doc, rpc::XmlRpc::call_generic); break;
|
||||
case rpc::CommandMap::target_download: rpc::xmlrpc.insert_command(itr->first, itr->second.m_parm, itr->second.m_doc, rpc::XmlRpc::call_download); break;
|
||||
case rpc::CommandMap::target_file: rpc::xmlrpc.insert_command(itr->first, itr->second.m_parm, itr->second.m_doc, rpc::XmlRpc::call_file); break;
|
||||
case rpc::CommandMap::target_tracker: rpc::xmlrpc.insert_command(itr->first, itr->second.m_parm, itr->second.m_doc, rpc::XmlRpc::call_tracker); break;
|
||||
default: throw torrent::internal_error("XMLRPC: Bad entry.");
|
||||
}
|
||||
|
||||
count++;
|
||||
rpc::xmlrpc.insert_command(itr->first, itr->second.m_parm, itr->second.m_doc);
|
||||
}
|
||||
|
||||
char buffer[128];
|
||||
|
||||
@@ -191,27 +191,27 @@ DownloadFactory::receive_success() {
|
||||
if (!rtorrent->has_key_string("custom5")) rtorrent->insert_key("custom5", std::string());
|
||||
|
||||
// Move to 'rtorrent'.
|
||||
rpc::call_command_d("d.set_connection_leech", download, m_variables["connection_leech"]);
|
||||
rpc::call_command_d("d.set_connection_seed", download, m_variables["connection_seed"]);
|
||||
rpc::call_command("d.set_connection_leech", m_variables["connection_leech"], rpc::make_target(download));
|
||||
rpc::call_command("d.set_connection_seed", m_variables["connection_seed"], rpc::make_target(download));
|
||||
|
||||
rpc::call_command_d("d.set_max_uploads", download, rpc::call_command_void("get_max_uploads"));
|
||||
rpc::call_command_d("d.set_min_peers", download, rpc::call_command_void("get_min_peers"));
|
||||
rpc::call_command_d("d.set_max_peers", download, rpc::call_command_void("get_max_peers"));
|
||||
rpc::call_command_d("d.set_tracker_numwant", download, rpc::call_command_void("get_tracker_numwant"));
|
||||
rpc::call_command("d.set_max_uploads", rpc::call_command_void("get_max_uploads"), rpc::make_target(download));
|
||||
rpc::call_command("d.set_min_peers", rpc::call_command_void("get_min_peers"), rpc::make_target(download));
|
||||
rpc::call_command("d.set_max_peers", rpc::call_command_void("get_max_peers"), rpc::make_target(download));
|
||||
rpc::call_command("d.set_tracker_numwant", rpc::call_command_void("get_tracker_numwant"), rpc::make_target(download));
|
||||
|
||||
if (rpc::call_command_d_value("d.get_complete", download) != 0) {
|
||||
if (rpc::call_command_value("d.get_complete", rpc::make_target(download)) != 0) {
|
||||
if (rpc::call_command_value("get_min_peers_seed") >= 0)
|
||||
rpc::call_command_d("d.set_min_peers", download, rpc::call_command_void("get_min_peers_seed"));
|
||||
rpc::call_command("d.set_min_peers", rpc::call_command_void("get_min_peers_seed"), rpc::make_target(download));
|
||||
|
||||
if (rpc::call_command_value("get_max_peers_seed") >= 0)
|
||||
rpc::call_command_d("d.set_max_peers", download, rpc::call_command_void("get_max_peers_seed"));
|
||||
rpc::call_command("d.set_max_peers", rpc::call_command_void("get_max_peers_seed"), rpc::make_target(download));
|
||||
}
|
||||
|
||||
if (!rpc::call_command_value("get_use_udp_trackers"))
|
||||
download->enable_udp_trackers(false);
|
||||
|
||||
if (rpc::call_command_value("get_max_file_size") > 0)
|
||||
rpc::call_command_d("d.set_max_file_size", download, rpc::call_command_void("get_max_file_size"));
|
||||
rpc::call_command("d.set_max_file_size", rpc::call_command_void("get_max_file_size"), rpc::make_target(download));
|
||||
|
||||
// Check first if we already have these values set in the session
|
||||
// torrent, so that it is safe to change the values.
|
||||
@@ -223,12 +223,12 @@ DownloadFactory::receive_success() {
|
||||
rpc::call_command_string("split_suffix"));
|
||||
|
||||
if (!rtorrent->has_key_string("directory"))
|
||||
rpc::call_command_d("d.set_directory", download, m_variables["directory"]);
|
||||
rpc::call_command("d.set_directory", m_variables["directory"], rpc::make_target(download));
|
||||
else
|
||||
rpc::call_command_d("d.set_directory", download, rtorrent->get_key("directory"));
|
||||
rpc::call_command("d.set_directory", rtorrent->get_key("directory"), rpc::make_target(download));
|
||||
|
||||
if (!m_session && m_variables["tied_to_file"].as_value())
|
||||
rpc::call_command_d("d.set_tied_to_file", download, m_uri);
|
||||
rpc::call_command("d.set_tied_to_file", m_uri, rpc::make_target(download));
|
||||
|
||||
torrent::Object& resumeObject = root->has_key_map("libtorrent_resume")
|
||||
? root->get_key("libtorrent_resume")
|
||||
@@ -280,8 +280,8 @@ DownloadFactory::receive_success() {
|
||||
if (m_session) {
|
||||
// This torrent was queued for hashing or hashing when the session
|
||||
// file was saved. Or it was in a started state.
|
||||
if (rpc::call_command_d_value("d.get_hashing", download) != Download::variable_hashing_stopped ||
|
||||
rpc::call_command_d_value("d.get_state", download) != 0)
|
||||
if (rpc::call_command_value("d.get_hashing", rpc::make_target(download)) != Download::variable_hashing_stopped ||
|
||||
rpc::call_command_value("d.get_state", rpc::make_target(download)) != 0)
|
||||
m_manager->download_list()->resume(download);
|
||||
|
||||
} else {
|
||||
@@ -330,9 +330,9 @@ DownloadFactory::initialize_rtorrent(Download* download, torrent::Object* rtorre
|
||||
rtorrent->insert_key("tied_to_file", std::string());
|
||||
|
||||
if (rtorrent->has_key_value("priority"))
|
||||
rpc::call_command_d("d.set_priority", download, rtorrent->get_key_value("priority") % 4);
|
||||
rpc::call_command("d.set_priority", rtorrent->get_key_value("priority") % 4, rpc::make_target(download));
|
||||
else
|
||||
rpc::call_command_d("d.set_priority", download, (int64_t)2);
|
||||
rpc::call_command("d.set_priority", (int64_t)2, rpc::make_target(download));
|
||||
|
||||
if (rtorrent->has_key_value("key")) {
|
||||
download->tracker_list()->set_key(rtorrent->get_key_value("key"));
|
||||
|
||||
+31
-31
@@ -269,7 +269,7 @@ DownloadList::close_throw(Download* download) {
|
||||
|
||||
download->download()->close();
|
||||
|
||||
if (!download->is_hash_failed() && rpc::call_command_d_value("d.get_hashing", download) != Download::variable_hashing_stopped)
|
||||
if (!download->is_hash_failed() && rpc::call_command_value("d.get_hashing", rpc::make_target(download)) != Download::variable_hashing_stopped)
|
||||
throw torrent::internal_error("DownloadList::close_throw(...) called but we're going into a hashing loop.");
|
||||
|
||||
std::for_each(slot_map_hash_removed().begin(), slot_map_hash_removed().end(), download_list_call(download));
|
||||
@@ -283,7 +283,7 @@ DownloadList::start_normal(Download* download) {
|
||||
// Clear hash failed as we're doing a manual start and want to try
|
||||
// hashing again.
|
||||
download->set_hash_failed(false);
|
||||
rpc::call_command_d("d.set_state", download, (int64_t)1);
|
||||
rpc::call_command("d.set_state", (int64_t)1, rpc::make_target(download));
|
||||
|
||||
resume(download);
|
||||
}
|
||||
@@ -295,12 +295,12 @@ DownloadList::start_try(Download* download) {
|
||||
// Also don't start if the state is one of those that indicate we
|
||||
// were manually stopped?
|
||||
|
||||
if (download->is_hash_failed() || rpc::call_command_d_value("d.get_ignore_commands", download) != 0)
|
||||
if (download->is_hash_failed() || rpc::call_command_value("d.get_ignore_commands", rpc::make_target(download)) != 0)
|
||||
return false;
|
||||
|
||||
// Don't clear the hash failed as this function is used by scripts,
|
||||
// etc.
|
||||
rpc::call_command_d("d.set_state", download, (int64_t)1);
|
||||
rpc::call_command("d.set_state", (int64_t)1, rpc::make_target(download));
|
||||
|
||||
resume(download);
|
||||
return true;
|
||||
@@ -310,7 +310,7 @@ void
|
||||
DownloadList::stop_normal(Download* download) {
|
||||
check_contains(download);
|
||||
|
||||
rpc::call_command_d("d.set_state", download, (int64_t)0);
|
||||
rpc::call_command("d.set_state", (int64_t)0, rpc::make_target(download));
|
||||
|
||||
pause(download);
|
||||
}
|
||||
@@ -319,10 +319,10 @@ bool
|
||||
DownloadList::stop_try(Download* download) {
|
||||
check_contains(download);
|
||||
|
||||
if (rpc::call_command_d_value("d.get_ignore_commands", download) != 0)
|
||||
if (rpc::call_command_value("d.get_ignore_commands", rpc::make_target(download)) != 0)
|
||||
return false;
|
||||
|
||||
rpc::call_command_d("d.set_state", download, (int64_t)0);
|
||||
rpc::call_command("d.set_state", (int64_t)0, rpc::make_target(download));
|
||||
|
||||
pause(download);
|
||||
return true;
|
||||
@@ -353,8 +353,8 @@ DownloadList::resume(Download* download, int flags) {
|
||||
if (download->is_hash_failed())
|
||||
return;
|
||||
|
||||
if (rpc::call_command_d_value("d.get_hashing", download) == Download::variable_hashing_stopped)
|
||||
rpc::call_command_d("d.set_hashing", download, Download::variable_hashing_initial);
|
||||
if (rpc::call_command_value("d.get_hashing", rpc::make_target(download)) == Download::variable_hashing_stopped)
|
||||
rpc::call_command("d.set_hashing", Download::variable_hashing_initial, rpc::make_target(download));
|
||||
|
||||
std::for_each(slot_map_hash_queued().begin(), slot_map_hash_queued().end(), download_list_call(download));
|
||||
return;
|
||||
@@ -363,12 +363,12 @@ DownloadList::resume(Download* download, int flags) {
|
||||
// This will never actually do anything due to the above hash check.
|
||||
// open_throw(download);
|
||||
|
||||
rpc::call_command_d("d.set_state_changed", download, cachedTime.seconds());
|
||||
rpc::call_command("d.set_state_changed", cachedTime.seconds(), rpc::make_target(download));
|
||||
|
||||
if (download->is_done()) {
|
||||
rpc::call_command_d("d.set_connection_current", download, rpc::call_command_d_void("d.get_connection_seed", download));
|
||||
rpc::call_command("d.set_connection_current", rpc::call_command_void("d.get_connection_seed", rpc::make_target(download)), rpc::make_target(download));
|
||||
} else {
|
||||
rpc::call_command_d("d.set_connection_current", download, rpc::call_command_d_void("d.get_connection_leech", download));
|
||||
rpc::call_command("d.set_connection_current", rpc::call_command_void("d.get_connection_leech", rpc::make_target(download)), rpc::make_target(download));
|
||||
|
||||
// For the moment, clear the resume data so we force hash-check
|
||||
// on non-complete downloads after a crash. This shouldn't be
|
||||
@@ -401,9 +401,9 @@ DownloadList::pause(Download* download, int flags) {
|
||||
|
||||
// Always clear hashing on pause. When a hashing request is added,
|
||||
// it should have cleared the hash resume data.
|
||||
if (rpc::call_command_d_value("d.get_hashing", download) != Download::variable_hashing_stopped) {
|
||||
if (rpc::call_command_value("d.get_hashing", rpc::make_target(download)) != Download::variable_hashing_stopped) {
|
||||
download->download()->hash_stop();
|
||||
rpc::call_command_d_set_value("d.set_hashing", download, Download::variable_hashing_stopped);
|
||||
rpc::call_command_set_value("d.set_hashing", Download::variable_hashing_stopped, rpc::make_target(download));
|
||||
|
||||
std::for_each(slot_map_hash_removed().begin(), slot_map_hash_removed().end(), download_list_call(download));
|
||||
}
|
||||
@@ -416,7 +416,7 @@ DownloadList::pause(Download* download, int flags) {
|
||||
|
||||
std::for_each(slot_map_stop().begin(), slot_map_stop().end(), download_list_call(download));
|
||||
|
||||
rpc::call_command_d("d.set_state_changed", download, cachedTime.seconds());
|
||||
rpc::call_command("d.set_state_changed", cachedTime.seconds(), rpc::make_target(download));
|
||||
|
||||
// Save the state after all the slots, etc have been called so we
|
||||
// include the modifications they may make.
|
||||
@@ -433,7 +433,7 @@ DownloadList::check_hash(Download* download) {
|
||||
|
||||
try {
|
||||
|
||||
if (rpc::call_command_d_value("d.get_hashing", download) != Download::variable_hashing_stopped)
|
||||
if (rpc::call_command_value("d.get_hashing", rpc::make_target(download)) != Download::variable_hashing_stopped)
|
||||
return;
|
||||
|
||||
hash_queue(download, Download::variable_hashing_rehash);
|
||||
@@ -466,8 +466,8 @@ DownloadList::hash_done(Download* download) {
|
||||
// confirm all the data, avoiding large BW usage on f.ex. the
|
||||
// ReiserFS bug with >4GB files.
|
||||
|
||||
int64_t hashing = rpc::call_command_d_value("d.get_hashing", download);
|
||||
rpc::call_command_d_set_value("d.set_hashing", download, Download::variable_hashing_stopped);
|
||||
int64_t hashing = rpc::call_command_value("d.get_hashing", rpc::make_target(download));
|
||||
rpc::call_command_set_value("d.set_hashing", Download::variable_hashing_stopped, rpc::make_target(download));
|
||||
|
||||
switch (hashing) {
|
||||
case Download::variable_hashing_initial:
|
||||
@@ -476,17 +476,17 @@ DownloadList::hash_done(Download* download) {
|
||||
|
||||
// If the download was previously completed but the files were
|
||||
// f.ex deleted, then we clear the state and complete.
|
||||
if (rpc::call_command_d_value("d.get_complete", download) && !download->is_done()) {
|
||||
rpc::call_command_d("d.set_state", download, (int64_t)0);
|
||||
if (rpc::call_command_value("d.get_complete", rpc::make_target(download)) && !download->is_done()) {
|
||||
rpc::call_command("d.set_state", (int64_t)0, rpc::make_target(download));
|
||||
download->set_message("Download registered as completed, but hash check returned unfinished chunks.");
|
||||
}
|
||||
|
||||
// Save resume data so we update time-stamps and priorities if
|
||||
// they were invalid/changed while loading/hashing.
|
||||
rpc::call_command_d("d.set_complete", download, (int64_t)download->is_done());
|
||||
rpc::call_command("d.set_complete", (int64_t)download->is_done(), rpc::make_target(download));
|
||||
torrent::resume_save_progress(*download->download(), download->download()->bencode()->get_key("libtorrent_resume"));
|
||||
|
||||
if (rpc::call_command_d_value("d.get_state", download) == 1)
|
||||
if (rpc::call_command_value("d.get_state", rpc::make_target(download)) == 1)
|
||||
resume(download);
|
||||
|
||||
break;
|
||||
@@ -516,7 +516,7 @@ void
|
||||
DownloadList::hash_queue(Download* download, int type) {
|
||||
check_contains(download);
|
||||
|
||||
if (rpc::call_command_d_value("d.get_hashing", download) != Download::variable_hashing_stopped)
|
||||
if (rpc::call_command_value("d.get_hashing", rpc::make_target(download)) != Download::variable_hashing_stopped)
|
||||
throw torrent::internal_error("DownloadList::hash_queue(...) hashing already queued.");
|
||||
|
||||
// close_throw(download);
|
||||
@@ -531,7 +531,7 @@ DownloadList::hash_queue(Download* download, int type) {
|
||||
torrent::resume_clear_progress(*download->download(), download->download()->bencode()->get_key("libtorrent_resume"));
|
||||
|
||||
download->set_hash_failed(false);
|
||||
rpc::call_command_d_set_value("d.set_hashing", download, type);
|
||||
rpc::call_command_set_value("d.set_hashing", type, rpc::make_target(download));
|
||||
|
||||
if (download->is_open())
|
||||
throw torrent::internal_error("DownloadList::hash_clear(...) download still open.");
|
||||
@@ -560,16 +560,16 @@ void
|
||||
DownloadList::confirm_finished(Download* download) {
|
||||
check_contains(download);
|
||||
|
||||
rpc::call_command_d("d.set_complete", download, (int64_t)1);
|
||||
rpc::call_command("d.set_complete", (int64_t)1, rpc::make_target(download));
|
||||
|
||||
rpc::call_command_d("d.set_connection_current", download, rpc::call_command_d_void("d.get_connection_seed", download));
|
||||
rpc::call_command("d.set_connection_current", rpc::call_command_void("d.get_connection_seed", rpc::make_target(download)), rpc::make_target(download));
|
||||
download->set_priority(download->priority());
|
||||
|
||||
if (rpc::call_command_d_value("d.get_min_peers", download) == rpc::call_command_value("get_min_peers") && rpc::call_command_value("get_min_peers_seed") >= 0)
|
||||
rpc::call_command_d("d.set_min_peers", download, rpc::call_command_void("get_min_peers_seed"));
|
||||
if (rpc::call_command_value("d.get_min_peers", rpc::make_target(download)) == rpc::call_command_value("get_min_peers") && rpc::call_command_value("get_min_peers_seed") >= 0)
|
||||
rpc::call_command("d.set_min_peers", rpc::call_command_void("get_min_peers_seed"), rpc::make_target(download));
|
||||
|
||||
if (rpc::call_command_d_value("d.get_max_peers", download) == rpc::call_command_value("get_max_peers") && rpc::call_command_value("get_max_peers_seed") >= 0)
|
||||
rpc::call_command_d("d.set_max_peers", download, rpc::call_command_void("get_max_peers_seed"));
|
||||
if (rpc::call_command_value("d.get_max_peers", rpc::make_target(download)) == rpc::call_command_value("get_max_peers") && rpc::call_command_value("get_max_peers_seed") >= 0)
|
||||
rpc::call_command("d.set_max_peers", rpc::call_command_void("get_max_peers_seed"), rpc::make_target(download));
|
||||
|
||||
// Do this before the slots are called in case one of them closes
|
||||
// the download.
|
||||
@@ -599,7 +599,7 @@ DownloadList::confirm_finished(Download* download) {
|
||||
if (download->resume_flags() != ~uint32_t())
|
||||
throw torrent::internal_error("DownloadList::confirm_finished(...) download->resume_flags() != ~uint32_t().");
|
||||
|
||||
if (!download->is_active() && rpc::call_command_d_value("d.get_state", download) == 1)
|
||||
if (!download->is_active() && rpc::call_command_value("d.get_state", rpc::make_target(download)) == 1)
|
||||
resume(download, torrent::Download::start_skip_tracker | torrent::Download::start_keep_baseline);
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -465,7 +465,7 @@ path_expand(std::vector<std::string>* paths, const std::string& pattern) {
|
||||
|
||||
bool
|
||||
manager_equal_tied(const std::string& path, Download* download) {
|
||||
return path == rpc::call_command_d_string("d.get_tied_to_file", download);
|
||||
return path == rpc::call_command_string("d.get_tied_to_file", rpc::make_target(download));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -514,7 +514,7 @@ Manager::receive_hashing_changed() {
|
||||
continue;
|
||||
|
||||
bool tryQuick =
|
||||
rpc::call_command_d_value("d.get_hashing", *itr) == Download::variable_hashing_initial &&
|
||||
rpc::call_command_value("d.get_hashing", rpc::make_target(*itr)) == Download::variable_hashing_initial &&
|
||||
(*itr)->download()->file_list()->bitfield()->empty();
|
||||
|
||||
if (!tryQuick && foundHashing)
|
||||
@@ -537,7 +537,7 @@ Manager::receive_hashing_changed() {
|
||||
(*itr)->download()->hash_stop();
|
||||
|
||||
if (foundHashing) {
|
||||
rpc::call_command_d_set_value("d.set_hashing", *itr, Download::variable_hashing_rehash);
|
||||
rpc::call_command_set_value("d.set_hashing", Download::variable_hashing_rehash, rpc::make_target(*itr));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -548,7 +548,7 @@ Manager::receive_hashing_changed() {
|
||||
} catch (torrent::local_error& e) {
|
||||
if (tryQuick) {
|
||||
// Make sure we don't repeat the quick hashing.
|
||||
rpc::call_command_d_set_value("d.set_hashing", *itr, Download::variable_hashing_rehash);
|
||||
rpc::call_command_set_value("d.set_hashing", Download::variable_hashing_rehash, rpc::make_target(*itr));
|
||||
|
||||
} else {
|
||||
(*itr)->set_hash_failed(true);
|
||||
|
||||
@@ -73,8 +73,8 @@ public:
|
||||
|
||||
virtual bool operator () (Download* d1, Download* d2) const {
|
||||
return
|
||||
rpc::call_command_d_string(m_name, d1) == m_value &&
|
||||
rpc::call_command_d_string(m_name, d2) != m_value;
|
||||
rpc::call_command_string(m_name, rpc::make_target(d1)) == m_value &&
|
||||
rpc::call_command_string(m_name, rpc::make_target(d2)) != m_value;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -88,9 +88,9 @@ public:
|
||||
|
||||
virtual bool operator () (Download* d1, Download* d2) const {
|
||||
if (m_reverse)
|
||||
return rpc::call_command_d_value(m_name, d2) < rpc::call_command_d_value(m_name, d1);
|
||||
return rpc::call_command_value(m_name, rpc::make_target(d2)) < rpc::call_command_value(m_name, rpc::make_target(d1));
|
||||
else
|
||||
return rpc::call_command_d_value(m_name, d1) < rpc::call_command_d_value(m_name, d2);
|
||||
return rpc::call_command_value(m_name, rpc::make_target(d1)) < rpc::call_command_value(m_name, rpc::make_target(d2));
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -117,7 +117,7 @@ public:
|
||||
m_name(name), m_value(v), m_inverse(inverse) {}
|
||||
|
||||
virtual bool operator () (Download* d1) const {
|
||||
return (rpc::call_command_d_value(m_name, d1) == m_value) != m_inverse;
|
||||
return (rpc::call_command_value(m_name, rpc::make_target(d1)) == m_value) != m_inverse;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -92,9 +92,13 @@ te_string(Return (torrent::FileList::*fptr)() const, int flags = TextElementStri
|
||||
return text_element_string_slot(rak::on(std::mem_fun(&core::Download::file_list), std::mem_fun(fptr)), flags, attributes);
|
||||
}
|
||||
|
||||
// TMP HACK
|
||||
inline std::string te_call_command_d_string(const char* key, core::Download* download) { return rpc::commands.call_command(key, torrent::Object(), rpc::make_target(download)).as_string(); }
|
||||
inline int64_t te_call_command_d_value(const char* key, core::Download* download) { return rpc::commands.call_command(key, torrent::Object(), rpc::make_target(download)).as_value(); }
|
||||
|
||||
inline TextElementStringBase*
|
||||
te_variable_string(const char* variable, int flags = TextElementStringBase::flag_normal, int attributes = Attributes::a_invalid) {
|
||||
return text_element_string_slot(rak::bind1st(std::ptr_fun(&rpc::call_command_d_string), variable), flags, attributes);
|
||||
return text_element_string_slot(rak::bind1st(std::ptr_fun(&te_call_command_d_string), variable), flags, attributes);
|
||||
}
|
||||
|
||||
// Value stuff:
|
||||
@@ -119,7 +123,7 @@ te_value(Return (torrent::File::*fptr)() const, int flags = TextElementValueBase
|
||||
|
||||
inline TextElementValueBase*
|
||||
te_variable_value(const char* variable, int flags = TextElementValueBase::flag_normal, int attributes = Attributes::a_invalid) {
|
||||
return text_element_value_slot(rak::bind1st(std::ptr_fun(&rpc::call_command_d_value), variable), flags, attributes);
|
||||
return text_element_value_slot(rak::bind1st(std::ptr_fun(&te_call_command_d_value), variable), flags, attributes);
|
||||
}
|
||||
|
||||
template <typename Return>
|
||||
|
||||
@@ -160,12 +160,12 @@ print_download_info(char* first, char* last, core::Download* d) {
|
||||
}
|
||||
|
||||
first = print_buffer(first, last, " [%c%c R: %4.2f",
|
||||
rpc::call_command_d_string("d.get_tied_to_file", d).empty() ? ' ' : 'T',
|
||||
rpc::call_command_d_value("d.get_ignore_commands", d) == 0 ? ' ' : 'I',
|
||||
(double)rpc::call_command_d_value("d.get_ratio", d) / 1000.0);
|
||||
rpc::call_command_string("d.get_tied_to_file", rpc::make_target(d)).empty() ? ' ' : 'T',
|
||||
rpc::call_command_value("d.get_ignore_commands", rpc::make_target(d)) == 0 ? ' ' : 'I',
|
||||
(double)rpc::call_command_value("d.get_ratio", rpc::make_target(d)) / 1000.0);
|
||||
|
||||
if (d->priority() != 2)
|
||||
first = print_buffer(first, last, " %s]", rpc::call_command_d_string("d.get_priority_str", d).c_str());
|
||||
first = print_buffer(first, last, " %s]", rpc::call_command_string("d.get_priority_str", rpc::make_target(d)).c_str());
|
||||
else
|
||||
first = print_buffer(first, last, "]");
|
||||
|
||||
@@ -179,7 +179,7 @@ char*
|
||||
print_download_status(char* first, char* last, core::Download* d) {
|
||||
if (d->is_active())
|
||||
;
|
||||
else if (rpc::call_command_d_value("d.get_hashing", d) != 0)
|
||||
else if (rpc::call_command_value("d.get_hashing", rpc::make_target(d)) != 0)
|
||||
first = print_buffer(first, last, "Hashing: ");
|
||||
else if (!d->is_active())
|
||||
first = print_buffer(first, last, "Inactive: ");
|
||||
|
||||
@@ -144,4 +144,21 @@ CommandMap::call_command(key_type key, const mapped_type& arg, target_type targe
|
||||
}
|
||||
}
|
||||
|
||||
const CommandMap::mapped_type
|
||||
CommandMap::call_command(const_iterator itr, const mapped_type& arg, target_type target) {
|
||||
if ((itr->second.m_target != target.first && itr->second.m_target != target_generic) ||
|
||||
(itr->second.m_target != target_generic && target.second == NULL))
|
||||
throw torrent::input_error("Command type mis-match.");
|
||||
|
||||
// This _should_ be optimized int just two calls.
|
||||
switch (itr->second.m_target) {
|
||||
case target_generic: return itr->second.m_genericSlot(itr->second.m_variable, arg);
|
||||
case target_download: return itr->second.m_downloadSlot(itr->second.m_variable, (core::Download*)target.second, arg);
|
||||
case target_file: return itr->second.m_fileSlot(itr->second.m_variable, (torrent::File*)target.second, arg);
|
||||
case target_peer: return itr->second.m_peerSlot(itr->second.m_variable, (torrent::Peer*)target.second, arg);
|
||||
case target_tracker: return itr->second.m_trackerSlot(itr->second.m_variable, (torrent::Tracker*)target.second, arg);
|
||||
default: throw torrent::internal_error("CommandMap::call_command(...) Invalid target.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -73,6 +73,8 @@ struct command_map_data_type {
|
||||
command_map_data_type(Command* variable, int flags, const char* parm, const char* doc) :
|
||||
m_variable(variable), m_flags(flags), m_parm(parm), m_doc(doc) {}
|
||||
|
||||
int target() const { return m_target; }
|
||||
|
||||
Command* m_variable;
|
||||
|
||||
union {
|
||||
@@ -104,6 +106,7 @@ public:
|
||||
typedef mapped_type::value_type mapped_value_type;
|
||||
|
||||
using base_type::iterator;
|
||||
using base_type::const_iterator;
|
||||
using base_type::key_type;
|
||||
using base_type::value_type;
|
||||
|
||||
@@ -138,7 +141,9 @@ public:
|
||||
|
||||
void insert(key_type key, const command_map_data_type src);
|
||||
|
||||
const mapped_type call_command (key_type key, const mapped_type& arg, target_type target = target_type((int)target_generic, NULL));
|
||||
const mapped_type call_command (key_type key, const mapped_type& arg, target_type target = target_type((int)target_generic, NULL));
|
||||
const mapped_type call_command (const_iterator itr, const mapped_type& arg, target_type target = target_type((int)target_generic, NULL));
|
||||
|
||||
const mapped_type call_command_d(key_type key, core::Download* download, const mapped_type& arg) { return call_command(key, arg, target_type((int)target_download, download)); }
|
||||
const mapped_type call_command_f(key_type key, torrent::File* file, const mapped_type& arg) { return call_command(key, arg, target_type((int)target_file, file)); }
|
||||
const mapped_type call_command_p(key_type key, torrent::Peer* peer, const mapped_type& arg) { return call_command(key, arg, target_type((int)target_peer, peer)); }
|
||||
|
||||
+18
-19
@@ -50,26 +50,29 @@ namespace core {
|
||||
|
||||
namespace rpc {
|
||||
|
||||
typedef CommandMap::target_type target_type;
|
||||
|
||||
// Move to another file?
|
||||
extern CommandMap commands;
|
||||
extern XmlRpc xmlrpc;
|
||||
extern ExecFile execFile;
|
||||
|
||||
inline CommandMap::target_type make_target() { return CommandMap::target_type((int)CommandMap::target_generic, NULL); }
|
||||
inline CommandMap::target_type make_target(core::Download* target) { return CommandMap::target_type((int)CommandMap::target_download, target); }
|
||||
inline CommandMap::target_type make_target(torrent::File* target) { return CommandMap::target_type((int)CommandMap::target_file, target); }
|
||||
inline CommandMap::target_type make_target(torrent::Peer* target) { return CommandMap::target_type((int)CommandMap::target_peer, target); }
|
||||
inline CommandMap::target_type make_target(torrent::Tracker* target) { return CommandMap::target_type((int)CommandMap::target_tracker, target); }
|
||||
inline target_type make_target() { return target_type((int)CommandMap::target_generic, NULL); }
|
||||
inline target_type make_target(core::Download* target) { return target_type((int)CommandMap::target_download, target); }
|
||||
inline target_type make_target(torrent::File* target) { return target_type((int)CommandMap::target_file, target); }
|
||||
inline target_type make_target(torrent::Peer* target) { return target_type((int)CommandMap::target_peer, target); }
|
||||
inline target_type make_target(torrent::Tracker* target) { return target_type((int)CommandMap::target_tracker, target); }
|
||||
inline target_type make_target(int type, void* target) { return target_type(type, target); }
|
||||
|
||||
typedef std::pair<torrent::Object, const char*> parse_command_type;
|
||||
|
||||
// The generic parse command function, used by the rest. At some point
|
||||
// the 'download' parameter should be replaced by a more generic one.
|
||||
parse_command_type parse_command(CommandMap::target_type target, const char* first, const char* last);
|
||||
void parse_command_multiple(CommandMap::target_type target, const char* first, const char* last);
|
||||
parse_command_type parse_command(target_type target, const char* first, const char* last);
|
||||
void parse_command_multiple(target_type target, const char* first, const char* last);
|
||||
|
||||
inline void parse_command_single(CommandMap::target_type target, const char* first) { parse_command(target, first, first + std::strlen(first)); }
|
||||
inline void parse_command_multiple(CommandMap::target_type target, const char* first) { parse_command_multiple(target, first, first + std::strlen(first)); }
|
||||
inline void parse_command_single(target_type target, const char* first) { parse_command(target, first, first + std::strlen(first)); }
|
||||
inline void parse_command_multiple(target_type target, const char* first) { parse_command_multiple(target, first, first + std::strlen(first)); }
|
||||
|
||||
bool parse_command_file(const std::string& path);
|
||||
const char* parse_command_name(const char* first, const char* last, std::string* dest);
|
||||
@@ -94,22 +97,18 @@ parse_command_d_multiple_std(core::Download* download, const std::string& cmd) {
|
||||
parse_command_multiple(make_target(download), cmd.c_str(), cmd.c_str() + cmd.size());
|
||||
}
|
||||
|
||||
inline torrent::Object call_command(const char* key, const torrent::Object& obj) { return commands.call_command(key, obj); }
|
||||
inline torrent::Object call_command_void(const char* key) { return commands.call_command(key, torrent::Object()); }
|
||||
inline std::string call_command_string(const char* key) { return commands.call_command(key, torrent::Object()).as_string(); }
|
||||
inline int64_t call_command_value(const char* key) { return commands.call_command(key, torrent::Object()).as_value(); }
|
||||
// inline torrent::Object call_command(const char* key, const torrent::Object& obj, target_type target = target_type((int)CommandMap::target_generic, NULL)) { return commands.call_command(key, obj); }
|
||||
inline torrent::Object call_command (const char* key, const torrent::Object& obj, target_type target = make_target()) { return commands.call_command(key, obj, target); }
|
||||
inline torrent::Object call_command_void (const char* key, target_type target = make_target()) { return commands.call_command(key, torrent::Object(), target); }
|
||||
inline std::string call_command_string(const char* key, target_type target = make_target()) { return commands.call_command(key, torrent::Object(), target).as_string(); }
|
||||
inline int64_t call_command_value (const char* key, target_type target = make_target()) { return commands.call_command(key, torrent::Object(), target).as_value(); }
|
||||
|
||||
inline void call_command_set_string(const char* key, const std::string& arg) { commands.call_command(key, torrent::Object(arg)); }
|
||||
inline void call_command_set_std_string(const std::string& key, const std::string& arg) { commands.call_command(key.c_str(), torrent::Object(arg)); }
|
||||
|
||||
inline torrent::Object call_command_d(const char* key, core::Download* download, const torrent::Object& obj) { return commands.call_command_d(key, download, obj); }
|
||||
inline torrent::Object call_command_d_void(const char* key, core::Download* download) { return commands.call_command_d(key, download, torrent::Object()); }
|
||||
inline std::string call_command_d_string(const char* key, core::Download* download) { return commands.call_command_d(key, download, torrent::Object()).as_string(); }
|
||||
inline int64_t call_command_d_value(const char* key, core::Download* download) { return commands.call_command_d(key, download, torrent::Object()).as_value(); }
|
||||
|
||||
inline void call_command_d_v_void(const char* key, core::Download* download) { commands.call_command_d(key, download, torrent::Object()); }
|
||||
|
||||
inline void call_command_d_set_value(const char* key, core::Download* download, int64_t arg) { commands.call_command_d(key, download, torrent::Object(arg)); }
|
||||
inline void call_command_set_value(const char* key, int64_t arg, target_type target = make_target()) { commands.call_command(key, torrent::Object(arg), target); }
|
||||
inline void call_command_d_set_string(const char* key, core::Download* download, const std::string& arg) { commands.call_command_d(key, download, torrent::Object(arg)); }
|
||||
inline void call_command_d_set_std_string(const std::string& key, core::Download* download, const std::string& arg) { commands.call_command_d(key.c_str(), download, torrent::Object(arg)); }
|
||||
|
||||
|
||||
@@ -97,8 +97,8 @@ void
|
||||
SCgiTask::event_read() {
|
||||
int bytes = ::recv(m_fileDesc, m_position, m_bufferSize - (m_position - m_buffer), 0);
|
||||
|
||||
if (bytes == -1) {
|
||||
if (!rak::error_number::current().is_blocked_momentary())
|
||||
if (bytes <= 0) {
|
||||
if (bytes == 0 || !rak::error_number::current().is_blocked_momentary())
|
||||
close();
|
||||
|
||||
return;
|
||||
@@ -116,10 +116,12 @@ SCgiTask::event_read() {
|
||||
int contentSize;
|
||||
int headerSize = strtol(m_buffer, ¤t, 0);
|
||||
|
||||
if (current == m_buffer || current == m_position)
|
||||
if (current == m_position)
|
||||
return;
|
||||
|
||||
if (*current != ':' || headerSize < 17 || headerSize > max_header_size)
|
||||
// If the request doesn't start with an integer or if it didn't
|
||||
// end in ':', then close the connection.
|
||||
if (current == m_buffer || *current != ':' || headerSize < 17 || headerSize > max_header_size)
|
||||
goto event_read_failed;
|
||||
|
||||
if (std::distance(++current, m_position) < headerSize + 1)
|
||||
@@ -171,7 +173,8 @@ SCgiTask::event_read() {
|
||||
return;
|
||||
|
||||
event_read_failed:
|
||||
throw torrent::internal_error("SCgiTask::event_read() fault not handled.");
|
||||
// throw torrent::internal_error("SCgiTask::event_read() fault not handled.");
|
||||
close();
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ class SCgiTask : public torrent::Event {
|
||||
public:
|
||||
static const unsigned int default_buffer_size = 2047;
|
||||
static const int max_header_size = 2000;
|
||||
static const int max_content_size = (128 << 10);
|
||||
static const int max_content_size = (2 << 20);
|
||||
|
||||
SCgiTask() { m_fileDesc = -1; }
|
||||
|
||||
|
||||
+10
-61
@@ -373,64 +373,22 @@ object_to_xmlrpc(xmlrpc_env* env, const torrent::Object& object) {
|
||||
|
||||
xmlrpc_value*
|
||||
xmlrpc_call_command(xmlrpc_env* env, xmlrpc_value* args, void* voidServerInfo) {
|
||||
torrent::Object object = xmlrpc_to_object(env, args);
|
||||
CommandMap::const_iterator itr = commands.find((const char*)voidServerInfo);
|
||||
|
||||
if (env->fault_occurred)
|
||||
return NULL;
|
||||
|
||||
try {
|
||||
return object_to_xmlrpc(env, rpc::call_command((const char*)voidServerInfo, object));
|
||||
|
||||
} catch (torrent::local_error& e) {
|
||||
xmlrpc_env_set_fault(env, XMLRPC_PARSE_ERROR, e.what());
|
||||
if (itr == commands.end()) {
|
||||
xmlrpc_env_set_fault(env, XMLRPC_PARSE_ERROR, ("Command \"" + std::string((const char*)voidServerInfo) + "\" does not exist.").c_str());
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
xmlrpc_value*
|
||||
xmlrpc_call_command_d(xmlrpc_env* env, xmlrpc_value* args, void* voidServerInfo) {
|
||||
core::Download* download = NULL;
|
||||
torrent::Object object = xmlrpc_to_object_target(env, args, XmlRpc::call_download, (void**)&download);
|
||||
int type = itr->second.target();
|
||||
void* target = NULL;
|
||||
torrent::Object object = (type == 0) ? xmlrpc_to_object(env, args) : xmlrpc_to_object_target(env, args, type, &target);
|
||||
|
||||
if (env->fault_occurred)
|
||||
return NULL;
|
||||
|
||||
try {
|
||||
return object_to_xmlrpc(env, rpc::call_command_d((const char*)voidServerInfo, download, object));
|
||||
|
||||
} catch (torrent::local_error& e) {
|
||||
xmlrpc_env_set_fault(env, XMLRPC_PARSE_ERROR, e.what());
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
xmlrpc_value*
|
||||
xmlrpc_call_command_f(xmlrpc_env* env, xmlrpc_value* args, void* voidServerInfo) {
|
||||
torrent::File* file = NULL;
|
||||
torrent::Object object = xmlrpc_to_object_target(env, args, XmlRpc::call_file, (void**)&file);
|
||||
|
||||
if (env->fault_occurred)
|
||||
return NULL;
|
||||
|
||||
try {
|
||||
return object_to_xmlrpc(env, rpc::commands.call_command_f((const char*)voidServerInfo, file, object));
|
||||
|
||||
} catch (torrent::local_error& e) {
|
||||
xmlrpc_env_set_fault(env, XMLRPC_PARSE_ERROR, e.what());
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
xmlrpc_value*
|
||||
xmlrpc_call_command_t(xmlrpc_env* env, xmlrpc_value* args, void* voidServerInfo) {
|
||||
torrent::Tracker* tracker = NULL;
|
||||
torrent::Object object = xmlrpc_to_object_target(env, args, XmlRpc::call_tracker, (void**)&tracker);
|
||||
|
||||
if (env->fault_occurred)
|
||||
return NULL;
|
||||
|
||||
try {
|
||||
return object_to_xmlrpc(env, rpc::commands.call_command_t((const char*)voidServerInfo, tracker, object));
|
||||
return object_to_xmlrpc(env, rpc::commands.call_command(itr, object, rpc::make_target(type, target)));
|
||||
|
||||
} catch (torrent::local_error& e) {
|
||||
xmlrpc_env_set_fault(env, XMLRPC_PARSE_ERROR, e.what());
|
||||
@@ -476,21 +434,12 @@ XmlRpc::process(const char* inBuffer, uint32_t length, slot_write slotWrite) {
|
||||
}
|
||||
|
||||
void
|
||||
XmlRpc::insert_command(const char* name, const char* parm, const char* doc, int call) {
|
||||
XmlRpc::insert_command(const char* name, const char* parm, const char* doc) {
|
||||
xmlrpc_env localEnv;
|
||||
xmlrpc_env_init(&localEnv);
|
||||
|
||||
xmlrpc_value* (*callSlot)(xmlrpc_env*, xmlrpc_value*, void*);
|
||||
|
||||
switch (call) {
|
||||
case call_download: callSlot = &xmlrpc_call_command_d; break;
|
||||
case call_file: callSlot = &xmlrpc_call_command_f; break;
|
||||
case call_tracker: callSlot = &xmlrpc_call_command_t; break;
|
||||
default: callSlot = &xmlrpc_call_command; break;
|
||||
}
|
||||
|
||||
xmlrpc_registry_add_method_w_doc(&localEnv, (xmlrpc_registry*)m_registry, NULL, name,
|
||||
callSlot, const_cast<char*>(name), parm, doc);
|
||||
&xmlrpc_call_command, const_cast<char*>(name), parm, doc);
|
||||
|
||||
if (localEnv.fault_occurred)
|
||||
throw torrent::internal_error("Fault occured while inserting xmlrpc call.");
|
||||
@@ -539,7 +488,7 @@ XmlRpc::set_dialect(int dialect) {
|
||||
void XmlRpc::initialize() { throw torrent::resource_error("XMLRPC not supported."); }
|
||||
void XmlRpc::cleanup() {}
|
||||
|
||||
void XmlRpc::insert_command(__UNUSED const char* name, __UNUSED const char* parm, __UNUSED const char* doc, __UNUSED int call) {}
|
||||
void XmlRpc::insert_command(__UNUSED const char* name, __UNUSED const char* parm, __UNUSED const char* doc) {}
|
||||
void XmlRpc::set_dialect(__UNUSED int dialect) {}
|
||||
|
||||
bool XmlRpc::process(__UNUSED const char* inBuffer, __UNUSED uint32_t length, __UNUSED slot_write slotWrite) { return false; }
|
||||
|
||||
+2
-1
@@ -62,6 +62,7 @@ public:
|
||||
static const int dialect_i8 = 1;
|
||||
static const int dialect_apache = 2;
|
||||
|
||||
// These need to match CommandMap type values.
|
||||
static const int call_generic = 0;
|
||||
static const int call_download = 1;
|
||||
static const int call_file = 2;
|
||||
@@ -76,7 +77,7 @@ public:
|
||||
|
||||
bool process(const char* inBuffer, uint32_t length, slot_write slotWrite);
|
||||
|
||||
void insert_command(const char* name, const char* parm, const char* doc, int call);
|
||||
void insert_command(const char* name, const char* parm, const char* doc);
|
||||
|
||||
int dialect() { return m_dialect; }
|
||||
void set_dialect(int dialect);
|
||||
|
||||
@@ -292,8 +292,8 @@ DownloadList::receive_exit_input(Input type) {
|
||||
if (current_view()->focus() == current_view()->end_visible())
|
||||
throw torrent::input_error("No download in focus to change root directory.");
|
||||
|
||||
rpc::call_command_d("d.set_directory", *current_view()->focus(), rak::trim(input->str()));
|
||||
control->core()->push_log_std("New root directory \"" + rpc::call_command_d_string("d.get_directory", *current_view()->focus()) + "\" for torrent.");
|
||||
rpc::call_command("d.set_directory", rak::trim(input->str()), rpc::make_target(*current_view()->focus()));
|
||||
control->core()->push_log_std("New root directory \"" + rpc::call_command_string("d.get_directory", rpc::make_target(*current_view()->focus())) + "\" for torrent.");
|
||||
break;
|
||||
|
||||
case INPUT_COMMAND:
|
||||
|
||||
@@ -152,7 +152,7 @@ ElementDownloadList::receive_stop_download() {
|
||||
if (m_view->focus() == m_view->end_visible())
|
||||
return;
|
||||
|
||||
if (rpc::call_command_d_value("d.get_state", *m_view->focus()) == 1)
|
||||
if (rpc::call_command_value("d.get_state", rpc::make_target(*m_view->focus())) == 1)
|
||||
control->core()->download_list()->stop_normal(*m_view->focus());
|
||||
else
|
||||
control->core()->download_list()->erase_ptr(*m_view->focus());
|
||||
@@ -167,7 +167,7 @@ ElementDownloadList::receive_close_download() {
|
||||
|
||||
core::Download* download = *m_view->focus();
|
||||
|
||||
rpc::call_command_d("d.set_ignore_commands", download, (int64_t)1);
|
||||
rpc::call_command("d.set_ignore_commands", (int64_t)1, rpc::make_target(download));
|
||||
|
||||
control->core()->download_list()->stop_normal(download);
|
||||
control->core()->download_list()->close(download);
|
||||
@@ -206,11 +206,11 @@ ElementDownloadList::receive_ignore_ratio() {
|
||||
if (m_view->focus() == m_view->end_visible())
|
||||
return;
|
||||
|
||||
if (rpc::call_command_d_value("d.get_ignore_commands", *m_view->focus()) != 0) {
|
||||
rpc::call_command_d_set_value("d.set_ignore_commands", *m_view->focus(), (int64_t)0);
|
||||
if (rpc::call_command_value("d.get_ignore_commands", rpc::make_target(*m_view->focus())) != 0) {
|
||||
rpc::call_command_set_value("d.set_ignore_commands", (int64_t)0, rpc::make_target(*m_view->focus()));
|
||||
control->core()->push_log("Torrent set to heed commands.");
|
||||
} else {
|
||||
rpc::call_command_d_set_value("d.set_ignore_commands", *m_view->focus(), (int64_t)1);
|
||||
rpc::call_command_set_value("d.set_ignore_commands", (int64_t)1, rpc::make_target(*m_view->focus()));
|
||||
control->core()->push_log("Torrent set to ignore commands.");
|
||||
}
|
||||
}
|
||||
@@ -220,10 +220,10 @@ ElementDownloadList::receive_clear_tied() {
|
||||
if (m_view->focus() == m_view->end_visible())
|
||||
return;
|
||||
|
||||
const std::string& tiedFile = rpc::call_command_d_string("d.get_tied_to_file", *m_view->focus());
|
||||
const std::string& tiedFile = rpc::call_command_string("d.get_tied_to_file", rpc::make_target(*m_view->focus()));
|
||||
|
||||
if (!tiedFile.empty()) {
|
||||
rpc::call_command_d_void("d.delete_tied", *m_view->focus());
|
||||
rpc::call_command_void("d.delete_tied", rpc::make_target(*m_view->focus()));
|
||||
|
||||
control->core()->push_log("Cleared tied to file association for the selected download.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user