diff --git a/src/command_download.cc b/src/command_download.cc index f5d578cd..d047cea9 100644 --- a/src/command_download.cc +++ b/src/command_download.cc @@ -257,11 +257,11 @@ f_multicall(core::Download* download, const torrent::Object& rawArgs) { // Add some pre-parsing of the commands, so we don't spend time // parsing and searching command map for every single call. - torrent::Object resultRaw(torrent::Object::TYPE_LIST); + torrent::Object resultRaw = torrent::Object::create_list(); torrent::Object::list_type& result = resultRaw.as_list(); for (torrent::FileList::const_iterator itr = download->file_list()->begin(), last = download->file_list()->end(); itr != last; itr++) { - torrent::Object::list_type& row = result.insert(result.end(), torrent::Object(torrent::Object::TYPE_LIST))->as_list(); + torrent::Object::list_type& row = result.insert(result.end(), torrent::Object::create_list())->as_list(); for (torrent::Object::list_const_iterator cItr = ++args.begin(), cLast = args.end(); cItr != args.end(); cItr++) { const std::string& cmd = cItr->as_string(); @@ -284,11 +284,11 @@ t_multicall(core::Download* download, const torrent::Object& rawArgs) { // Add some pre-parsing of the commands, so we don't spend time // parsing and searching command map for every single call. - torrent::Object resultRaw(torrent::Object::TYPE_LIST); + torrent::Object resultRaw = torrent::Object::create_list(); torrent::Object::list_type& result = resultRaw.as_list(); for (int itr = 0, last = download->tracker_list()->size(); itr != last; itr++) { - torrent::Object::list_type& row = result.insert(result.end(), torrent::Object(torrent::Object::TYPE_LIST))->as_list(); + torrent::Object::list_type& row = result.insert(result.end(), torrent::Object::create_list())->as_list(); for (torrent::Object::list_const_iterator cItr = ++args.begin(), cLast = args.end(); cItr != args.end(); cItr++) { const std::string& cmd = cItr->as_string(); @@ -313,11 +313,11 @@ p_multicall(core::Download* download, const torrent::Object& rawArgs) { // Add some pre-parsing of the commands, so we don't spend time // parsing and searching command map for every single call. - torrent::Object resultRaw(torrent::Object::TYPE_LIST); + torrent::Object resultRaw = torrent::Object::create_list(); torrent::Object::list_type& result = resultRaw.as_list(); for (torrent::ConnectionList::const_iterator itr = download->connection_list()->begin(), last = download->connection_list()->end(); itr != last; itr++) { - torrent::Object::list_type& row = result.insert(result.end(), torrent::Object(torrent::Object::TYPE_LIST))->as_list(); + torrent::Object::list_type& row = result.insert(result.end(), torrent::Object::create_list())->as_list(); for (torrent::Object::list_const_iterator cItr = ++args.begin(), cLast = args.end(); cItr != args.end(); cItr++) { const std::string& cmd = cItr->as_string(); @@ -462,8 +462,8 @@ initialize_command_download() { // // 'loaded_file' is the file this instance of the torrent was loaded // from, and should not be changed. - ADD_CD_VARIABLE_STRING("tied_to_file", "rtorrent", "tied_to_file"); - ADD_CD_VARIABLE_STRING("loaded_file", "rtorrent", "loaded_file"); + ADD_CD_VARIABLE_STRING_PUBLIC("tied_to_file", "rtorrent", "tied_to_file"); + ADD_CD_VARIABLE_STRING ("loaded_file", "rtorrent", "loaded_file"); // The "state_changed" variable is required to be a valid unix time // value, it indicates the last time the torrent changed its state, diff --git a/src/command_events.cc b/src/command_events.cc index f64917f1..776fc549 100644 --- a/src/command_events.cc +++ b/src/command_events.cc @@ -274,7 +274,7 @@ apply_download_list(const torrent::Object& rawArgs) { if (viewItr == viewManager->end()) throw torrent::input_error("Could not find view."); - torrent::Object result(torrent::Object::TYPE_LIST); + torrent::Object result = torrent::Object::create_list(); torrent::Object::list_type& resultList = result.as_list(); for (core::View::const_iterator itr = (*viewItr)->begin_visible(), last = (*viewItr)->end_visible(); itr != last; itr++) { @@ -317,11 +317,11 @@ d_multicall(const torrent::Object& rawArgs) { // Add some pre-parsing of the commands, so we don't spend time // parsing and searching command map for every single call. - torrent::Object resultRaw(torrent::Object::TYPE_LIST); + torrent::Object resultRaw = torrent::Object::create_list(); torrent::Object::list_type& result = resultRaw.as_list(); for (core::View::const_iterator vItr = (*viewItr)->begin_visible(), vLast = (*viewItr)->end_visible(); vItr != vLast; vItr++) { - torrent::Object::list_type& row = result.insert(result.end(), torrent::Object(torrent::Object::TYPE_LIST))->as_list(); + torrent::Object::list_type& row = result.insert(result.end(), torrent::Object::create_list())->as_list(); for (torrent::Object::list_const_iterator cItr = ++args.begin(), cLast = args.end(); cItr != args.end(); cItr++) { const std::string& cmd = cItr->as_string(); diff --git a/src/command_file.cc b/src/command_file.cc index ff88dffa..17acdf96 100644 --- a/src/command_file.cc +++ b/src/command_file.cc @@ -72,7 +72,7 @@ apply_f_path(torrent::File* file) { torrent::Object apply_f_path_components(torrent::File* file) { - torrent::Object resultRaw(torrent::Object::TYPE_LIST); + torrent::Object resultRaw = torrent::Object::create_list(); torrent::Object::list_type& result = resultRaw.as_list(); for (torrent::Path::const_iterator itr = file->path()->begin(), last = file->path()->end(); itr != last; itr++) diff --git a/src/command_ui.cc b/src/command_ui.cc index 33d5a4c6..1866062b 100644 --- a/src/command_ui.cc +++ b/src/command_ui.cc @@ -98,7 +98,7 @@ apply_view_sort(const torrent::Object& rawArgs) { torrent::Object apply_view_list(const torrent::Object&) { - torrent::Object rawResult(torrent::Object::TYPE_LIST); + torrent::Object rawResult = torrent::Object::create_list(); torrent::Object::list_type& result = rawResult.as_list(); for (core::ViewManager::const_iterator itr = control->view_manager()->begin(), last = control->view_manager()->end(); itr != last; itr++) @@ -227,6 +227,9 @@ apply_if(rpc::target_type target, const torrent::Object& rawArgs) { case torrent::Object::TYPE_VALUE: result = conditional->as_value(); break; + case torrent::Object::TYPE_NONE: + result = false; + break; default: throw torrent::input_error("Type not supported by 'if'."); }; diff --git a/src/core/dht_manager.cc b/src/core/dht_manager.cc index 4f35aa21..9a76a8fc 100644 --- a/src/core/dht_manager.cc +++ b/src/core/dht_manager.cc @@ -67,7 +67,7 @@ DhtManager::load_dht_cache() { if (m_start == dht_disable || !control->core()->download_store()->is_enabled()) return; - torrent::Object cache(torrent::Object::TYPE_MAP); + torrent::Object cache = torrent::Object::create_map(); std::fstream cache_file((control->core()->download_store()->path() + "rtorrent.dht_cache").c_str(), std::ios::in | std::ios::binary); if (cache_file.is_open()) { @@ -147,7 +147,7 @@ DhtManager::save_dht_cache() { if (!cache_file.is_open()) return; - torrent::Object cache(torrent::Object::TYPE_MAP); + torrent::Object cache = torrent::Object::create_map(); cache_file << *torrent::dht_manager()->store_cache(&cache); if (!cache_file.good()) @@ -279,7 +279,7 @@ DhtManager::log_statistics(bool force) { torrent::Object DhtManager::dht_statistics() { - torrent::Object dhtStats(torrent::Object::TYPE_MAP); + torrent::Object dhtStats = torrent::Object::create_map(); dhtStats.insert_key("dht", dht_settings[m_start]); dhtStats.insert_key("active", torrent::dht_manager()->is_active()); diff --git a/src/core/download_factory.cc b/src/core/download_factory.cc index fff3ed94..c9743cb0 100644 --- a/src/core/download_factory.cc +++ b/src/core/download_factory.cc @@ -136,9 +136,6 @@ DownloadFactory::receive_load() { } else { std::fstream* stream = new std::fstream(rak::path_expand(m_uri).c_str(), std::ios::in | std::ios::binary); m_stream = stream; - - // Since FileStatusCache checks file stats, it will automatically - // cull away invalid paths. m_isFile = true; if (!stream->is_open()) @@ -332,7 +329,9 @@ DownloadFactory::initialize_rtorrent(Download* download, torrent::Object* rtorre rtorrent->insert_preserve_value("complete", 0); rtorrent->insert_preserve_value("hashing", Download::variable_hashing_stopped); + rtorrent->insert_preserve_cstr("tied_to_file", ""); + rtorrent->insert_key("loaded_file", m_isFile ? m_uri : std::string()); if (rtorrent->has_key_value("priority")) rpc::call_command("d.set_priority", rtorrent->get_key_value("priority") % 4, rpc::make_target(download)); diff --git a/src/core/manager.cc b/src/core/manager.cc index 7ef73210..7f115b50 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -405,7 +405,7 @@ Manager::try_create_download(const std::string& uri, int flags, const command_li // If the path was attempted loaded before, skip it. if (!(flags & create_raw_data) && !is_network_uri(uri) && - !m_fileStatusCache->insert(uri, 0)) + !file_status_cache()->insert(uri, 0)) return; // Adding download. diff --git a/src/rpc/command_slot.cc b/src/rpc/command_slot.cc index 23d43bff..f17fd1a9 100644 --- a/src/rpc/command_slot.cc +++ b/src/rpc/command_slot.cc @@ -69,7 +69,7 @@ CommandSlot::call_list(Command* rawCommand, Target target, const torrent case torrent::Object::TYPE_STRING: case torrent::Object::TYPE_NONE: { - torrent::Object tmpList(torrent::Object::TYPE_LIST); + torrent::Object tmpList = torrent::Object::create_list(); tmpList.as_list().push_back(rawArgs); return command->m_slot(target, tmpList); @@ -91,7 +91,7 @@ CommandSlot::call_list(Command* rawCommand, const torrent::Object& rawArgs case torrent::Object::TYPE_STRING: case torrent::Object::TYPE_NONE: { - torrent::Object tmpList(torrent::Object::TYPE_LIST); + torrent::Object tmpList = torrent::Object::create_list(); tmpList.as_list().push_back(rawArgs); return command->m_slot(tmpList); @@ -114,7 +114,7 @@ CommandSlot::call_value_base(Command* rawCommand, Target target, const t case torrent::Object::TYPE_STRING: { - torrent::Object argValue(torrent::Object::TYPE_VALUE); + torrent::Object argValue = torrent::Object::create_value(); if (!parse_whole_value_nothrow(arg.as_string().c_str(), &argValue.as_value(), base, unit)) throw torrent::input_error("Not a value."); @@ -139,7 +139,7 @@ CommandSlot::call_value_base(Command* rawCommand, const torrent::Object& r case torrent::Object::TYPE_STRING: { - torrent::Object argValue(torrent::Object::TYPE_VALUE); + torrent::Object argValue = torrent::Object::create_value(); if (!parse_whole_value_nothrow(arg.as_string().c_str(), &argValue.as_value(), base, unit)) throw torrent::input_error("Not a value."); diff --git a/src/rpc/parse.cc b/src/rpc/parse.cc index 7d7855b2..71b815d4 100644 --- a/src/rpc/parse.cc +++ b/src/rpc/parse.cc @@ -170,7 +170,7 @@ parse_value_nothrow(const char* src, int64_t* value, int base, int unit) { const char* parse_object(const char* first, const char* last, torrent::Object* dest, bool (*delim)(const char)) { if (*first == '{') { - *dest = torrent::Object(torrent::Object::TYPE_LIST); + *dest = torrent::Object::create_list(); first = parse_list(first + 1, last, dest, &parse_is_delim_list); first = parse_skip_wspace(first, last); @@ -216,7 +216,7 @@ parse_whole_list(const char* first, const char* last, torrent::Object* dest) { first = parse_skip_wspace(first, last); if (first != last && parse_is_seperator(*first)) { - torrent::Object tmp = torrent::Object(torrent::Object::TYPE_LIST); + torrent::Object tmp = torrent::Object::create_list(); tmp.swap(*dest); dest->as_list().push_back(tmp); diff --git a/src/rpc/parse_commands.h b/src/rpc/parse_commands.h index 4e7f5fef..9dc90810 100644 --- a/src/rpc/parse_commands.h +++ b/src/rpc/parse_commands.h @@ -109,7 +109,7 @@ inline void call_command_d_set_std_string(const std::string& key, cor inline torrent::Object call_command_d_range(const char* key, core::Download* download, torrent::Object::list_const_iterator first, torrent::Object::list_const_iterator last) { // Change to using range ctor. - torrent::Object rawArgs(torrent::Object::TYPE_LIST); + torrent::Object rawArgs = torrent::Object::create_list(); torrent::Object::list_type& args = rawArgs.as_list(); while (first != last) diff --git a/src/rpc/xmlrpc.cc b/src/rpc/xmlrpc.cc index 57c08761..767b8187 100644 --- a/src/rpc/xmlrpc.cc +++ b/src/rpc/xmlrpc.cc @@ -106,7 +106,7 @@ xmlrpc_to_object(xmlrpc_env* env, xmlrpc_value* value) { case XMLRPC_TYPE_ARRAY: { - torrent::Object result(torrent::Object::TYPE_LIST); + torrent::Object result = torrent::Object::create_list(); torrent::Object::list_type& listRef = result.as_list(); unsigned int last = xmlrpc_array_size(env, value); @@ -292,7 +292,7 @@ xmlrpc_to_object_target(xmlrpc_env* env, xmlrpc_value* value, int callType, void torrent::Object result; if (current + 1 < last) { - result = torrent::Object(torrent::Object::TYPE_LIST); + result = torrent::Object::create_list(); torrent::Object::list_type& listRef = result.as_list(); // Move this into a helper function? diff --git a/src/ui/download.cc b/src/ui/download.cc index 1ab4ae77..f662d618 100644 --- a/src/ui/download.cc +++ b/src/ui/download.cc @@ -175,8 +175,8 @@ Download::create_info() { element->push_back(""); element->push_column("Connection type:", te_command("d.get_connection_current=")); element->push_column("Safe sync:", te_command("if=$get_safe_sync=,yes,no")); - element->push_column("Send buffer:", te_command("cat=$to_mb=$get_send_buffer_size=,\" KB\"")); - element->push_column("Receive buffer:", te_command("cat=$to_mb=$get_receive_buffer_size=,\" KB\"")); + element->push_column("Send buffer:", te_command("cat=$to_kb=$get_send_buffer_size=,\" KB\"")); + element->push_column("Receive buffer:", te_command("cat=$to_kb=$get_receive_buffer_size=,\" KB\"")); element->push_back(""); element->push_column("Upload:", te_command("cat=$to_kb=$d.get_up_rate=,\" KB / \",$to_xb=$d.get_up_total=")); diff --git a/src/utils/file_status_cache.h b/src/utils/file_status_cache.h index a2a33e8c..740b097a 100644 --- a/src/utils/file_status_cache.h +++ b/src/utils/file_status_cache.h @@ -67,6 +67,8 @@ public: using base_type::erase; + // static int flag_ + // Insert and return true if the entry does not exist or the new // file's mtime is more recent. bool insert(const std::string& path, int flags);