1 // rTorrent - BitTorrent client
2 // Copyright (C) 2005-2011, Jari Sundell
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 //
18 // In addition, as a special exception, the copyright holders give
19 // permission to link the code of portions of this program with the
20 // OpenSSL library under certain conditions as described in each
21 // individual source file, and distribute linked combinations
22 // including the two.
23 //
24 // You must obey the GNU General Public License in all respects for
25 // all of the code used other than OpenSSL.  If you modify file(s)
26 // with this exception, you may extend this exception to your version
27 // of the file(s), but you are not obligated to do so.  If you do not
28 // wish to do so, delete this exception statement from your version.
29 // If you delete this exception statement from all source files in the
30 // program, then also delete it here.
31 //
32 // Contact:  Jari Sundell <jaris@ifi.uio.no>
33 //
34 //           Skomakerveien 33
35 //           3185 Skoppum, NORWAY
36 
37 #include "config.h"
38 
39 #include <functional>
40 #include <unistd.h>
41 #include <cstdio>
42 #include <rak/file_stat.h>
43 #include <rak/error_number.h>
44 #include <rak/path.h>
45 #include <rak/socket_address.h>
46 #include <rak/string_manip.h>
47 #include <rak/regex.h>
48 #include <torrent/rate.h>
49 #include <torrent/throttle.h>
50 #include <torrent/tracker.h>
51 #include <torrent/tracker_controller.h>
52 #include <torrent/tracker_list.h>
53 #include <torrent/connection_manager.h>
54 #include <torrent/data/download_data.h>
55 #include <torrent/data/file.h>
56 #include <torrent/data/file_list.h>
57 #include <torrent/download/resource_manager.h>
58 #include <torrent/peer/connection_list.h>
59 #include <torrent/peer/peer_list.h>
60 #include <torrent/utils/log.h>
61 #include <torrent/utils/option_strings.h>
62 
63 #include "core/download.h"
64 #include "core/download_store.h"
65 #include "core/manager.h"
66 #include "rpc/parse.h"
67 
68 #include "globals.h"
69 #include "control.h"
70 #include "command_helpers.h"
71 
72 std::string
retrieve_d_base_path(core::Download * download)73 retrieve_d_base_path(core::Download* download) {
74   if (download->file_list()->is_multi_file())
75     return download->file_list()->frozen_root_dir();
76   else
77     return download->file_list()->empty() ? std::string() : download->file_list()->at(0)->frozen_path();
78 }
79 
80 std::string
retrieve_d_base_filename(core::Download * download)81 retrieve_d_base_filename(core::Download* download) {
82   const std::string* base;
83 
84   if (download->file_list()->is_multi_file())
85     base = &download->file_list()->frozen_root_dir();
86   else
87     base = &download->file_list()->at(0)->frozen_path();
88 
89   std::string::size_type split = base->rfind('/');
90 
91   if (split == std::string::npos)
92     return *base;
93   else
94     return base->substr(split + 1);
95 }
96 
97 torrent::Object
apply_d_change_link(core::Download * download,const torrent::Object::list_type & args,int changeType)98 apply_d_change_link(core::Download* download, const torrent::Object::list_type& args, int changeType) {
99   if (args.size() != 3)
100     throw torrent::input_error("Wrong argument count.");
101 
102   torrent::Object::list_const_iterator itr = args.begin();
103 
104   const std::string& type    = (itr++)->as_string();
105   const std::string& prefix  = (itr++)->as_string();
106   const std::string& postfix = (itr++)->as_string();
107 
108   if (type.empty())
109     throw torrent::input_error("Invalid arguments.");
110 
111   std::string target;
112   std::string link;
113 
114   if (type == "base_path") {
115     target = rpc::call_command_string("d.base_path", rpc::make_target(download));
116     link = rak::path_expand(prefix + rpc::call_command_string("d.base_path", rpc::make_target(download)) + postfix);
117 
118   } else if (type == "base_filename") {
119     target = rpc::call_command_string("d.base_path", rpc::make_target(download));
120     link = rak::path_expand(prefix + rpc::call_command_string("d.base_filename", rpc::make_target(download)) + postfix);
121 
122 //   } else if (type == "directory_path") {
123 //     target = rpc::call_command_string("d.directory", rpc::make_target(download));
124 //     link = rak::path_expand(prefix + rpc::call_command_string("d.base_path", rpc::make_target(download)) + postfix);
125 
126   } else if (type == "tied") {
127     link = rak::path_expand(rpc::call_command_string("d.tied_to_file", rpc::make_target(download)));
128 
129     if (link.empty())
130       return torrent::Object();
131 
132     link = rak::path_expand(prefix + link + postfix);
133     target = rpc::call_command_string("d.base_path", rpc::make_target(download));
134 
135   } else {
136     throw torrent::input_error("Unknown type argument.");
137   }
138 
139   switch (changeType) {
140   case 0:
141     if (symlink(target.c_str(), link.c_str()) == -1){
142       lt_log_print(torrent::LOG_TORRENT_WARN, "create_link failed: %s",
143           rak::error_number::current().c_str());
144     }
145     break;
146 
147   case 1:
148   {
149     rak::file_stat fileStat;
150     rak::error_number::clear_global();
151 
152     if (!fileStat.update_link(link) || !fileStat.is_link() ||
153         unlink(link.c_str()) == -1){
154       lt_log_print(torrent::LOG_TORRENT_WARN, "delete_link failed: %s",
155           rak::error_number::current().c_str());
156     }
157     break;
158   }
159   default:
160     break;
161   }
162 
163   return torrent::Object();
164 }
165 
166 torrent::Object
apply_d_delete_tied(core::Download * download)167 apply_d_delete_tied(core::Download* download) {
168   const std::string& tie = rpc::call_command_string("d.tied_to_file", rpc::make_target(download));
169 
170   if (tie.empty())
171     return torrent::Object();
172 
173   if (::unlink(rak::path_expand(tie).c_str()) == -1)
174     control->core()->push_log_std("Could not unlink tied file: " + std::string(rak::error_number::current().c_str()));
175 
176   rpc::call_command("d.tied_to_file.set", std::string(), rpc::make_target(download));
177   return torrent::Object();
178 }
179 
180 void
apply_d_directory(core::Download * download,const std::string & name)181 apply_d_directory(core::Download* download, const std::string& name) {
182   if (!download->file_list()->is_multi_file())
183     download->set_root_directory(name);
184   else if (name.empty() || *name.rbegin() == '/')
185     download->set_root_directory(name + download->info()->name());
186   else
187     download->set_root_directory(name + "/" + download->info()->name());
188 }
189 
190 torrent::Object
apply_d_connection_type(core::Download * download,const std::string & name)191 apply_d_connection_type(core::Download* download, const std::string& name) {
192   torrent::Download::ConnectionType t =
193     (torrent::Download::ConnectionType)torrent::option_find_string(torrent::OPTION_CONNECTION_TYPE, name.c_str());
194 
195   download->download()->set_connection_type(t);
196   return torrent::Object();
197 }
198 
199 torrent::Object
apply_d_choke_heuristics(core::Download * download,const std::string & name,bool is_down)200 apply_d_choke_heuristics(core::Download* download, const std::string& name, bool is_down) {
201   torrent::Download::HeuristicType t =
202     (torrent::Download::HeuristicType)torrent::option_find_string(torrent::OPTION_CHOKE_HEURISTICS, name.c_str());
203 
204   if (is_down)
205     download->download()->set_download_choke_heuristic(t);
206   else
207     download->download()->set_upload_choke_heuristic(t);
208 
209   return torrent::Object();
210 }
211 
212 const char*
retrieve_d_priority_str(core::Download * download)213 retrieve_d_priority_str(core::Download* download) {
214   switch (download->priority()) {
215   case 0:
216     return "off";
217   case 1:
218     return "low";
219   case 2:
220     return "normal";
221   case 3:
222     return "high";
223   default:
224     throw torrent::input_error("Priority out of range.");
225   }
226 }
227 
228 torrent::Object
retrieve_d_ratio(core::Download * download)229 retrieve_d_ratio(core::Download* download) {
230   if (download->is_hash_checking())
231     return int64_t();
232 
233   int64_t bytesDone = download->download()->bytes_done();
234   int64_t upTotal   = download->info()->up_rate()->total();
235 
236   return bytesDone > 0 ? (1000 * upTotal) / bytesDone : 0;
237 }
238 
239 torrent::Object
apply_d_custom(core::Download * download,const torrent::Object::list_type & args)240 apply_d_custom(core::Download* download, const torrent::Object::list_type& args) {
241   torrent::Object::list_const_iterator itr = args.begin();
242 
243   if (itr == args.end())
244     throw torrent::bencode_error("Missing key argument.");
245 
246   const std::string& key = itr->as_string();
247 
248   if (++itr == args.end())
249     throw torrent::bencode_error("Missing value argument.");
250 
251   download->bencode()->get_key("rtorrent").
252                        insert_preserve_copy("custom", torrent::Object::create_map()).first->second.
253                        insert_key(key, itr->as_string());
254   return torrent::Object();
255 }
256 
257 torrent::Object
retrieve_d_custom(core::Download * download,const std::string & key)258 retrieve_d_custom(core::Download* download, const std::string& key) {
259   try {
260     return download->bencode()->get_key("rtorrent").get_key("custom").get_key_string(key);
261 
262   } catch (torrent::bencode_error& e) {
263     return std::string();
264   }
265 }
266 
267 torrent::Object
retrieve_d_custom_throw(core::Download * download,const std::string & key)268 retrieve_d_custom_throw(core::Download* download, const std::string& key) {
269   try {
270     return download->bencode()->get_key("rtorrent").get_key("custom").get_key_string(key);
271 
272   } catch (torrent::bencode_error& e) {
273     throw torrent::input_error("No such custom value.");
274   }
275 }
276 
277 torrent::Object
retrieve_d_custom_if_z(core::Download * download,const torrent::Object::list_type & args)278 retrieve_d_custom_if_z(core::Download* download, const torrent::Object::list_type& args) {
279   torrent::Object::list_const_iterator itr = args.begin();
280   if (itr == args.end())
281     throw torrent::bencode_error("d.custom.if_z: Missing key argument.");
282   const std::string& key = (itr++)->as_string();
283   if (key.empty())
284     throw torrent::bencode_error("d.custom.if_z: Empty key argument.");
285   if (itr == args.end())
286     throw torrent::bencode_error("d.custom.if_z: Missing default argument.");
287 
288   try {
289     const std::string& val = download->bencode()->get_key("rtorrent").get_key("custom").get_key_string(key);
290     return val.empty() ? itr->as_string() : val;
291   } catch (torrent::bencode_error& e) {
292     return itr->as_string();
293   }
294 }
295 
296 torrent::Object
retrieve_d_custom_map(core::Download * download,bool keys_only,const torrent::Object::list_type & args)297 retrieve_d_custom_map(core::Download* download, bool keys_only, const torrent::Object::list_type& args) {
298   if (args.begin() != args.end())
299     throw torrent::bencode_error("d.custom.keys/items takes no arguments.");
300 
301   torrent::Object result = keys_only ? torrent::Object::create_list() : torrent::Object::create_map();
302   torrent::Object::map_type& entries = download->bencode()->get_key("rtorrent").get_key("custom").as_map();
303 
304   for (torrent::Object::map_type::const_iterator itr = entries.begin(), last = entries.end(); itr != last; itr++) {
305     if (keys_only) result.as_list().push_back(itr->first);
306     else           result.as_map()[itr->first] = itr->second;
307   }
308 
309   return result;
310 }
311 
312 torrent::Object
retrieve_d_bitfield(core::Download * download)313 retrieve_d_bitfield(core::Download* download) {
314   const torrent::Bitfield* bitField = download->download()->file_list()->bitfield();
315 
316   if (bitField->empty())
317     return torrent::Object("");
318 
319   return torrent::Object(rak::transform_hex(bitField->begin(), bitField->end()));
320 }
321 
322 struct call_add_d_peer_t {
call_add_d_peer_tcall_add_d_peer_t323   call_add_d_peer_t(core::Download* d, int port) : m_download(d), m_port(port) { }
324 
operator ()call_add_d_peer_t325   void operator() (const sockaddr* sa, int err) {
326     if (sa == NULL) {
327       lt_log_print(torrent::LOG_CONNECTION_WARN, "Could not resolve hostname for added peer.");
328     } else {
329       m_download->download()->add_peer(sa, m_port);
330     }
331   }
332 
333   core::Download* m_download;
334   int m_port;
335 };
336 
337 void
apply_d_add_peer(core::Download * download,const std::string & arg)338 apply_d_add_peer(core::Download* download, const std::string& arg) {
339   int port, ret;
340   char dummy;
341   char host[1024];
342 
343   if (download->download()->info()->is_private())
344     throw torrent::input_error("Download is private.");
345 
346   ret = std::sscanf(arg.c_str(), "[%64[^]]]:%i%c", host, &port, &dummy);
347 
348   if (ret < 1)
349     ret = std::sscanf(arg.c_str(), "%1023[^:]:%i%c", host, &port, &dummy);
350 
351   if (ret == 1)
352     port = 6881;
353   else if (ret != 2)
354     throw torrent::input_error("Could not parse host.");
355 
356   if (port < 1 || port > 65535)
357     throw torrent::input_error("Invalid port number.");
358 
359   torrent::connection_manager()->resolver()(host, (int)rak::socket_address::pf_unspec, SOCK_STREAM, call_add_d_peer_t(download, port));
360 }
361 
362 torrent::Object
d_chunks_seen(core::Download * download)363 d_chunks_seen(core::Download* download) {
364   const uint8_t* seen = download->download()->chunks_seen();
365 
366   if (seen == NULL)
367     return std::string();
368 
369   uint32_t size = download->download()->file_list()->size_chunks();
370 
371   std::string result;
372   result.resize(size * 2);
373 
374   rak::transform_hex((const char*)seen, (const char*)seen + size, result.begin());
375   return result;
376 }
377 
378 torrent::Object
f_multicall(core::Download * download,const torrent::Object::list_type & args)379 f_multicall(core::Download* download, const torrent::Object::list_type& args) {
380   if (args.empty())
381     throw torrent::input_error("Too few arguments.");
382 
383   // We ignore the first arg for now, but it will be used for
384   // selecting what files to include.
385 
386   // Add some pre-parsing of the commands, so we don't spend time
387   // parsing and searching command map for every single call.
388   torrent::Object             resultRaw = torrent::Object::create_list();
389   torrent::Object::list_type& result = resultRaw.as_list();
390   std::vector<rak::regex>     regex_list;
391 
392   bool use_regex = true;
393 
394   if (args.front().is_list())
395     std::transform(args.front().as_list().begin(), args.front().as_list().end(),
396                    std::back_inserter(regex_list),
397                    std::bind(&torrent::Object::as_string_c, std::placeholders::_1));
398   else if (args.front().is_string() && !args.front().as_string().empty())
399     regex_list.push_back(args.front().as_string());
400   else
401     use_regex = false;
402 
403   for (torrent::FileList::const_iterator itr = download->file_list()->begin(), last = download->file_list()->end(); itr != last; itr++) {
404     if (use_regex &&
405         std::find_if(regex_list.begin(), regex_list.end(),
406                      std::bind(&rak::regex::operator(), std::placeholders::_1, (*itr)->path()->as_string())) == regex_list.end())
407       continue;
408 
409     torrent::Object::list_type& row = result.insert(result.end(), torrent::Object::create_list())->as_list();
410 
411     for (torrent::Object::list_const_iterator cItr = ++args.begin(); cItr != args.end(); cItr++) {
412       const std::string& cmd = cItr->as_string();
413       row.push_back(rpc::parse_command(rpc::make_target(*itr), cmd.c_str(), cmd.c_str() + cmd.size()).first);
414     }
415   }
416 
417   return resultRaw;
418 }
419 
420 torrent::Object
t_multicall(core::Download * download,const torrent::Object::list_type & args)421 t_multicall(core::Download* download, const torrent::Object::list_type& args) {
422   if (args.empty())
423     throw torrent::input_error("Too few arguments.");
424 
425   // We ignore the first arg for now, but it will be used for
426   // selecting what files to include.
427 
428   // Add some pre-parsing of the commands, so we don't spend time
429   // parsing and searching command map for every single call.
430   torrent::Object             resultRaw = torrent::Object::create_list();
431   torrent::Object::list_type& result = resultRaw.as_list();
432 
433   for (int itr = 0, last = download->tracker_list()->size(); itr != last; itr++) {
434     torrent::Object::list_type& row = result.insert(result.end(), torrent::Object::create_list())->as_list();
435 
436     for (torrent::Object::list_const_iterator cItr = ++args.begin(); cItr != args.end(); cItr++) {
437       const std::string& cmd = cItr->as_string();
438       torrent::Tracker* t = download->tracker_list()->at(itr);
439 
440       row.push_back(rpc::parse_command(rpc::make_target(t), cmd.c_str(), cmd.c_str() + cmd.size()).first);
441     }
442   }
443 
444   return resultRaw;
445 }
446 
447 torrent::Object
p_multicall(core::Download * download,const torrent::Object::list_type & args)448 p_multicall(core::Download* download, const torrent::Object::list_type& args) {
449   if (args.empty())
450     throw torrent::input_error("Too few arguments.");
451 
452   // We ignore the first arg for now, but it will be used for
453   // selecting what files to include.
454 
455   // Add some pre-parsing of the commands, so we don't spend time
456   // parsing and searching command map for every single call.
457   torrent::Object             resultRaw = torrent::Object::create_list();
458   torrent::Object::list_type& result = resultRaw.as_list();
459 
460   for (torrent::ConnectionList::const_iterator itr = download->connection_list()->begin(), last = download->connection_list()->end();
461        itr != last; itr++) {
462     torrent::Object::list_type& row = result.insert(result.end(), torrent::Object::create_list())->as_list();
463 
464     for (torrent::Object::list_const_iterator cItr = ++args.begin(); cItr != args.end(); cItr++) {
465       const std::string& cmd = cItr->as_string();
466 
467       row.push_back(rpc::parse_command(rpc::make_target(*itr), cmd.c_str(), cmd.c_str() + cmd.size()).first);
468     }
469   }
470 
471   return resultRaw;
472 }
473 
474 torrent::Object
p_call_target(const torrent::Object::list_type & args)475 p_call_target(const torrent::Object::list_type& args) {
476   if (args.empty() || args.begin() + 1 == args.end() || args.begin() + 2 == args.end())
477     throw torrent::input_error("Too few arguments.");
478 
479   // We ignore the first arg for now, but it will be used for
480   // selecting what files to include.
481 
482   // Add some pre-parsing of the commands, so we don't spend time
483   // parsing and searching command map for every single call.
484   torrent::Object::list_const_iterator itr = args.begin();
485 
486   core::Download* download = control->core()->download_list()->find_hex_ptr(itr++->as_string().c_str());
487   const std::string& peer_id = itr++->as_string();
488   const std::string& command_key = itr++->as_string();
489 
490   torrent::HashString hash;
491 
492   if (peer_id.size() != 40 ||
493       torrent::hash_string_from_hex_c_str(peer_id.c_str(), hash) == peer_id.c_str())
494     throw torrent::input_error("Not a hash string.");
495 
496   torrent::ConnectionList::iterator peerItr = download->connection_list()->find(hash.c_str());
497 
498   if (peerItr == download->connection_list()->end())
499     throw torrent::input_error("Could not find peer.");
500 
501   if (itr == args.end())
502     return rpc::commands.call(command_key.c_str());
503 
504   if (itr + 1 == args.end())
505     return rpc::commands.call(command_key.c_str(), *itr);
506 
507   return rpc::commands.call(command_key.c_str(), torrent::Object::create_list_range(itr, args.end()));
508 }
509 
510 torrent::Object
download_tracker_insert(core::Download * download,const torrent::Object::list_type & args)511 download_tracker_insert(core::Download* download, const torrent::Object::list_type& args) {
512   if (args.size() != 2)
513     throw torrent::input_error("Wrong argument count.");
514 
515   int64_t group;
516 
517   if (args.front().is_string())
518     rpc::parse_whole_value_nothrow(args.front().as_string().c_str(), &group);
519   else
520     group = args.front().as_value();
521 
522   if (group < 0 || group > 32)
523     throw torrent::input_error("Tracker group number invalid.");
524 
525   download->download()->tracker_list()->insert_url(group, args.back().as_string(), true);
526   return torrent::Object();
527 }
528 
529 //
530 // New download commands and macros:
531 //
532 
533 torrent::Object&
download_get_variable(core::Download * download,const char * first_key,const char * second_key=NULL)534 download_get_variable(core::Download* download, const char* first_key, const char* second_key = NULL) {
535   if (second_key == NULL)
536     return download->bencode()->get_key(first_key);
537 
538   return download->bencode()->get_key(first_key).get_key(second_key);
539 }
540 
541 torrent::Object
download_set_variable(core::Download * download,const torrent::Object & rawArgs,const char * first_key,const char * second_key=NULL)542 download_set_variable(core::Download* download, const torrent::Object& rawArgs, const char* first_key, const char* second_key = NULL) {
543   if (second_key == NULL)
544     return download->bencode()->get_key(first_key) = torrent::object_create_normal(rawArgs);
545 
546   return download->bencode()->get_key(first_key).get_key(second_key) = torrent::object_create_normal(rawArgs);
547 }
548 
549 torrent::Object
download_set_variable_value(core::Download * download,const torrent::Object::value_type & args,const char * first_key,const char * second_key=NULL)550 download_set_variable_value(core::Download* download, const torrent::Object::value_type& args,
551                             const char* first_key, const char* second_key = NULL) {
552   if (second_key == NULL)
553     return download->bencode()->get_key(first_key) = args;
554 
555   return download->bencode()->get_key(first_key).get_key(second_key) = args;
556 }
557 
558 torrent::Object
download_set_variable_value_ifz(core::Download * download,const torrent::Object::value_type & args,const char * first_key,const char * second_key=NULL)559 download_set_variable_value_ifz(core::Download* download, const torrent::Object::value_type& args,
560                                 const char* first_key, const char* second_key = NULL) {
561   torrent::Object& object = second_key == NULL ?
562     download->bencode()->get_key(first_key) :
563     download->bencode()->get_key(first_key).get_key(second_key);
564 
565   if (object.as_value() == 0)
566     object = args;
567 
568   return object;
569 }
570 
571 torrent::Object
download_set_variable_string(core::Download * download,const torrent::Object::string_type & args,const char * first_key,const char * second_key=NULL)572 download_set_variable_string(core::Download* download, const torrent::Object::string_type& args,
573                              const char* first_key, const char* second_key = NULL) {
574   if (second_key == NULL)
575     return download->bencode()->get_key(first_key) = args;
576 
577   return download->bencode()->get_key(first_key).get_key(second_key) = args;
578 }
579 
580 //
581 //
582 //
583 
584 torrent::Object
d_list_push_back(core::Download * download,const torrent::Object & rawArgs,const char * first_key,const char * second_key)585 d_list_push_back(core::Download* download, const torrent::Object& rawArgs, const char* first_key, const char* second_key) {
586   download_get_variable(download, first_key, second_key).as_list().push_back(rawArgs);
587 
588   return torrent::Object();
589 }
590 
591 torrent::Object
d_list_push_back_unique(core::Download * download,const torrent::Object & rawArgs,const char * first_key,const char * second_key)592 d_list_push_back_unique(core::Download* download, const torrent::Object& rawArgs, const char* first_key, const char* second_key) {
593   const torrent::Object& args = (rawArgs.is_list() && !rawArgs.as_list().empty()) ? rawArgs.as_list().front() : rawArgs;
594   torrent::Object::list_type& list = download_get_variable(download, first_key, second_key).as_list();
595 
596   if (std::find_if(list.begin(), list.end(),
597                    rak::bind1st(std::ptr_fun(&torrent::object_equal), args)) == list.end())
598     list.push_back(rawArgs);
599 
600   return torrent::Object();
601 }
602 
603 torrent::Object
d_list_has(core::Download * download,const torrent::Object & rawArgs,const char * first_key,const char * second_key)604 d_list_has(core::Download* download, const torrent::Object& rawArgs, const char* first_key, const char* second_key) {
605   const torrent::Object& args = (rawArgs.is_list() && !rawArgs.as_list().empty()) ? rawArgs.as_list().front() : rawArgs;
606   torrent::Object::list_type& list = download_get_variable(download, first_key, second_key).as_list();
607 
608   return (int64_t)(std::find_if(list.begin(), list.end(),
609                                 rak::bind1st(std::ptr_fun(&torrent::object_equal), args)) != list.end());
610 }
611 
612 torrent::Object
d_list_remove(core::Download * download,const torrent::Object & rawArgs,const char * first_key,const char * second_key)613 d_list_remove(core::Download* download, const torrent::Object& rawArgs, const char* first_key, const char* second_key) {
614   const torrent::Object& args = (rawArgs.is_list() && !rawArgs.as_list().empty()) ? rawArgs.as_list().front() : rawArgs;
615   torrent::Object::list_type& list = download_get_variable(download, first_key, second_key).as_list();
616 
617   list.erase(std::remove_if(list.begin(), list.end(), rak::bind1st(std::ptr_fun(&torrent::object_equal), args)), list.end());
618 
619   return torrent::Object();
620 }
621 
622 #define CMD2_ON_INFO(func) std::bind(&torrent::DownloadInfo::func, std::bind(&core::Download::info, std::placeholders::_1))
623 #define CMD2_ON_DATA(func) std::bind(&torrent::download_data::func, std::bind(&core::Download::data, std::placeholders::_1))
624 #define CMD2_ON_DL(func) std::bind(&torrent::Download::func, std::bind(&core::Download::download, std::placeholders::_1))
625 #define CMD2_ON_FL(func) std::bind(&torrent::FileList::func, std::bind(&core::Download::file_list, std::placeholders::_1))
626 
627 #define CMD2_BIND_DL std::bind(&core::Download::download, std::placeholders::_1)
628 #define CMD2_BIND_CL std::bind(&core::Download::connection_list, std::placeholders::_1)
629 #define CMD2_BIND_FL std::bind(&core::Download::file_list, std::placeholders::_1)
630 #define CMD2_BIND_PL std::bind(&core::Download::c_peer_list, std::placeholders::_1)
631 #define CMD2_BIND_TL std::bind(&core::Download::tracker_list, std::placeholders::_1)
632 #define CMD2_BIND_TC std::bind(&core::Download::tracker_controller, std::placeholders::_1)
633 
634 #define CMD2_BIND_INFO std::bind(&core::Download::info, std::placeholders::_1)
635 #define CMD2_BIND_DATA std::bind(&core::Download::data, std::placeholders::_1)
636 
637 #define CMD2_DL_VAR_VALUE(key, first_key, second_key)                   \
638   CMD2_DL(key, std::bind(&download_get_variable, std::placeholders::_1, first_key, second_key)); \
639   CMD2_DL_VALUE_P(key ".set", std::bind(&download_set_variable_value, \
640                                              std::placeholders::_1, std::placeholders::_2, \
641                                              first_key, second_key));
642 
643 #define CMD2_DL_VAR_VALUE_PUBLIC(key, first_key, second_key)            \
644   CMD2_DL(key, std::bind(&download_get_variable, std::placeholders::_1, first_key, second_key)); \
645   CMD2_DL_VALUE(key ".set", std::bind(&download_set_variable_value, \
646                                            std::placeholders::_1, std::placeholders::_2, \
647                                            first_key, second_key));
648 
649 #define CMD2_DL_TIMESTAMP(key, first_key, second_key)                   \
650   CMD2_DL(key, std::bind(&download_get_variable, std::placeholders::_1, first_key, second_key)); \
651   CMD2_DL_VALUE_P(key ".set", std::bind(&download_set_variable_value, \
652                                              std::placeholders::_1, std::placeholders::_2, \
653                                              first_key, second_key)); \
654   CMD2_DL_VALUE_P(key ".set_if_z", std::bind(&download_set_variable_value_ifz, \
655                                              std::placeholders::_1, std::placeholders::_2, \
656                                              first_key, second_key));   \
657 
658 #define CMD2_DL_VAR_STRING(key, first_key, second_key)                   \
659   CMD2_DL(key, std::bind(&download_get_variable, std::placeholders::_1, first_key, second_key)); \
660   CMD2_DL_STRING_P(key ".set", std::bind(&download_set_variable_string, \
661                                               std::placeholders::_1, std::placeholders::_2, \
662                                               first_key, second_key));
663 
664 #define CMD2_DL_VAR_STRING_PUBLIC(key, first_key, second_key)                   \
665   CMD2_DL(key, std::bind(&download_get_variable, std::placeholders::_1, first_key, second_key)); \
666   CMD2_DL_STRING(key ".set", std::bind(&download_set_variable_string, \
667                                             std::placeholders::_1, std::placeholders::_2, \
668                                             first_key, second_key));
669 
670 int64_t            cg_d_group(core::Download* download);
671 const std::string& cg_d_group_name(core::Download* download);
672 void               cg_d_group_set(core::Download* download, const torrent::Object& arg);
673 
674 void
initialize_command_download()675 initialize_command_download() {
676   CMD2_DL("d.hash",          std::bind(&rak::transform_hex_str<torrent::HashString>, CMD2_ON_INFO(hash)));
677   CMD2_DL("d.local_id",      std::bind(&rak::transform_hex_str<torrent::HashString>, CMD2_ON_INFO(local_id)));
678   CMD2_DL("d.local_id_html", std::bind(&rak::copy_escape_html_str<torrent::HashString>, CMD2_ON_INFO(local_id)));
679   CMD2_DL("d.bitfield",      std::bind(&retrieve_d_bitfield, std::placeholders::_1));
680   CMD2_DL("d.base_path",     std::bind(&retrieve_d_base_path, std::placeholders::_1));
681   CMD2_DL("d.base_filename", std::bind(&retrieve_d_base_filename, std::placeholders::_1));
682 
683   CMD2_DL("d.name",          CMD2_ON_INFO(name));
684   CMD2_DL("d.creation_date", CMD2_ON_INFO(creation_date));
685   CMD2_DL("d.load_date",     CMD2_ON_INFO(load_date));
686 
687   //
688   // Network related:
689   //
690 
691   CMD2_DL         ("d.up.rate",       std::bind(&torrent::Rate::rate,  CMD2_ON_INFO(up_rate)));
692   CMD2_DL         ("d.up.total",      std::bind(&torrent::Rate::total, CMD2_ON_INFO(up_rate)));
693   CMD2_DL         ("d.down.rate",     std::bind(&torrent::Rate::rate,  CMD2_ON_INFO(down_rate)));
694   CMD2_DL         ("d.down.total",    std::bind(&torrent::Rate::total, CMD2_ON_INFO(down_rate)));
695   CMD2_DL         ("d.skip.rate",     std::bind(&torrent::Rate::rate,  CMD2_ON_INFO(skip_rate)));
696   CMD2_DL         ("d.skip.total",    std::bind(&torrent::Rate::total, CMD2_ON_INFO(skip_rate)));
697 
698   CMD2_DL         ("d.peer_exchange",     CMD2_ON_INFO(is_pex_enabled));
699   CMD2_DL_VALUE_V ("d.peer_exchange.set", std::bind(&torrent::Download::set_pex_enabled, CMD2_BIND_DL, std::placeholders::_2));
700 
701   CMD2_DL_LIST    ("d.create_link", std::bind(&apply_d_change_link, std::placeholders::_1, std::placeholders::_2, 0));
702   CMD2_DL_LIST    ("d.delete_link", std::bind(&apply_d_change_link, std::placeholders::_1, std::placeholders::_2, 1));
703   CMD2_DL         ("d.delete_tied", std::bind(&apply_d_delete_tied, std::placeholders::_1));
704 
705   CMD2_FUNC_SINGLE("d.start",     "d.hashing_failed.set=0 ;view.set_visible=started");
706   CMD2_FUNC_SINGLE("d.stop",      "view.set_visible=stopped");
707   CMD2_FUNC_SINGLE("d.try_start", "branch=\"or={d.hashing_failed=,d.ignore_commands=}\",{},{view.set_visible=started}");
708   CMD2_FUNC_SINGLE("d.try_stop",  "branch=d.ignore_commands=, {}, {view.set_visible=stopped}");
709   CMD2_FUNC_SINGLE("d.try_close", "branch=d.ignore_commands=, {}, {view.set_visible=stopped, d.close=}");
710 
711   //
712   // Control functinos:
713   //
714 
715   CMD2_DL         ("d.is_open",               CMD2_ON_INFO(is_open));
716   CMD2_DL         ("d.is_active",             CMD2_ON_INFO(is_active));
717   CMD2_DL         ("d.is_hash_checked",       std::bind(&torrent::Download::is_hash_checked, CMD2_BIND_DL));
718   CMD2_DL         ("d.is_hash_checking",      std::bind(&torrent::Download::is_hash_checking, CMD2_BIND_DL));
719   CMD2_DL         ("d.is_multi_file",         std::bind(&torrent::FileList::is_multi_file, CMD2_BIND_FL));
720   CMD2_DL         ("d.is_private",            CMD2_ON_INFO(is_private));
721   CMD2_DL         ("d.is_pex_active",         CMD2_ON_INFO(is_pex_active));
722   CMD2_DL         ("d.is_partially_done",     CMD2_ON_DATA(is_partially_done));
723   CMD2_DL         ("d.is_not_partially_done", CMD2_ON_DATA(is_not_partially_done));
724   CMD2_DL         ("d.is_meta",               CMD2_ON_INFO(is_meta_download));
725 
726   CMD2_DL_V       ("d.resume",     std::bind(&core::DownloadList::resume_default, control->core()->download_list(), std::placeholders::_1));
727   CMD2_DL_V       ("d.pause",      std::bind(&core::DownloadList::pause_default, control->core()->download_list(), std::placeholders::_1));
728   CMD2_DL_V       ("d.open",       std::bind(&core::DownloadList::open_throw, control->core()->download_list(), std::placeholders::_1));
729   CMD2_DL_V       ("d.close",      std::bind(&core::DownloadList::close_throw, control->core()->download_list(), std::placeholders::_1));
730   CMD2_DL_V       ("d.close.directly", std::bind(&core::DownloadList::close_directly, control->core()->download_list(), std::placeholders::_1));
731   CMD2_DL_V       ("d.erase",      std::bind(&core::DownloadList::erase_ptr, control->core()->download_list(), std::placeholders::_1));
732   CMD2_DL_V       ("d.check_hash", std::bind(&core::DownloadList::check_hash, control->core()->download_list(), std::placeholders::_1));
733 
734   CMD2_DL         ("d.save_resume",       std::bind(&core::DownloadStore::save_resume, control->core()->download_store(), std::placeholders::_1));
735   CMD2_DL         ("d.save_full_session", std::bind(&core::DownloadStore::save_full, control->core()->download_store(), std::placeholders::_1));
736 
737   CMD2_DL_V       ("d.update_priorities", CMD2_ON_DL(update_priorities));
738 
739   CMD2_DL_STRING_V("add_peer",   std::bind(&apply_d_add_peer, std::placeholders::_1, std::placeholders::_2));
740 
741   //
742   // Custom settings:
743   //
744 
745   CMD2_DL_STRING("d.custom",       std::bind(&retrieve_d_custom, std::placeholders::_1, std::placeholders::_2));
746   CMD2_DL_STRING("d.custom_throw", std::bind(&retrieve_d_custom_throw, std::placeholders::_1, std::placeholders::_2));
747   CMD2_DL_LIST  ("d.custom.set",   std::bind(&apply_d_custom, std::placeholders::_1, std::placeholders::_2));
748   CMD2_DL_LIST  ("d.custom.if_z",  std::bind(&retrieve_d_custom_if_z, std::placeholders::_1, std::placeholders::_2));
749   CMD2_DL_LIST  ("d.custom.keys",  std::bind(&retrieve_d_custom_map, std::placeholders::_1, true, std::placeholders::_2));
750   CMD2_DL_LIST  ("d.custom.items", std::bind(&retrieve_d_custom_map, std::placeholders::_1, false, std::placeholders::_2));
751 
752   CMD2_DL_VAR_STRING_PUBLIC("d.custom1", "rtorrent", "custom1");
753   CMD2_DL_VAR_STRING_PUBLIC("d.custom2", "rtorrent", "custom2");
754   CMD2_DL_VAR_STRING_PUBLIC("d.custom3", "rtorrent", "custom3");
755   CMD2_DL_VAR_STRING_PUBLIC("d.custom4", "rtorrent", "custom4");
756   CMD2_DL_VAR_STRING_PUBLIC("d.custom5", "rtorrent", "custom5");
757 
758   // 0 - stopped
759   // 1 - started
760   CMD2_DL_VAR_VALUE("d.state",      "rtorrent", "state");
761   CMD2_DL_VAR_VALUE("d.complete",   "rtorrent", "complete");
762 
763   CMD2_FUNC_SINGLE ("d.incomplete", "not=(d.complete)");
764 
765   // 0 off
766   // 1 scheduled, being controlled by a download scheduler. Includes a priority.
767   // 3 forced off
768   // 2 forced on
769   CMD2_DL_VAR_VALUE("d.mode", "rtorrent", "mode");
770 
771   // 0 - Not hashing
772   // 1 - Normal hashing
773   // 2 - Download finished, hashing
774   // 3 - Rehashing
775   CMD2_DL_VAR_VALUE("d.hashing", "rtorrent", "hashing");
776 
777   // 'tied_to_file' is the file the download is associated with, and
778   // can be changed by the user.
779   //
780   // 'loaded_file' is the file this instance of the torrent was loaded
781   // from, and should not be changed.
782   CMD2_DL_VAR_STRING_PUBLIC("d.tied_to_file", "rtorrent", "tied_to_file");
783   CMD2_DL_VAR_STRING("d.loaded_file",  "rtorrent", "loaded_file");
784 
785   // The "state_changed" variable is required to be a valid unix time
786   // value, it indicates the last time the torrent changed its state,
787   // resume/pause.
788   CMD2_DL_VAR_VALUE("d.state_changed",          "rtorrent", "state_changed");
789   CMD2_DL_VAR_VALUE("d.state_counter",          "rtorrent", "state_counter");
790   CMD2_DL_VAR_VALUE_PUBLIC("d.ignore_commands", "rtorrent", "ignore_commands");
791 
792   CMD2_DL_TIMESTAMP("d.timestamp.started",      "rtorrent", "timestamp.started");
793   CMD2_DL_TIMESTAMP("d.timestamp.finished",     "rtorrent", "timestamp.finished");
794 
795   CMD2_DL       ("d.connection_current",     std::bind(&torrent::option_as_string, torrent::OPTION_CONNECTION_TYPE, CMD2_ON_DL(connection_type)));
796   CMD2_DL_STRING("d.connection_current.set", std::bind(&apply_d_connection_type, std::placeholders::_1, std::placeholders::_2));
797 
798   CMD2_DL_VAR_STRING("d.connection_leech",      "rtorrent", "connection_leech");
799   CMD2_DL_VAR_STRING("d.connection_seed",       "rtorrent", "connection_seed");
800 
801   CMD2_DL       ("d.up.choke_heuristics",       std::bind(&torrent::option_as_string, torrent::OPTION_CHOKE_HEURISTICS, CMD2_ON_DL(upload_choke_heuristic)));
802   CMD2_DL_STRING("d.up.choke_heuristics.set",   std::bind(&apply_d_choke_heuristics, std::placeholders::_1, std::placeholders::_2, false));
803   CMD2_DL       ("d.down.choke_heuristics",     std::bind(&torrent::option_as_string, torrent::OPTION_CHOKE_HEURISTICS, CMD2_ON_DL(download_choke_heuristic)));
804   CMD2_DL_STRING("d.down.choke_heuristics.set", std::bind(&apply_d_choke_heuristics, std::placeholders::_1, std::placeholders::_2, true));
805 
806   CMD2_DL_VAR_STRING("d.up.choke_heuristics.leech", "rtorrent", "choke_heuristics.up.leech");
807   CMD2_DL_VAR_STRING("d.up.choke_heuristics.seed",  "rtorrent", "choke_heuristics.up.seed");
808   CMD2_DL_VAR_STRING("d.down.choke_heuristics.leech", "rtorrent", "choke_heuristics.down.leech");
809   CMD2_DL_VAR_STRING("d.down.choke_heuristics.seed",  "rtorrent", "choke_heuristics.down.seed");
810 
811   CMD2_DL         ("d.hashing_failed",     std::bind(&core::Download::is_hash_failed, std::placeholders::_1));
812   CMD2_DL_VALUE_V ("d.hashing_failed.set", std::bind(&core::Download::set_hash_failed, std::placeholders::_1, std::placeholders::_2));
813 
814   CMD2_DL         ("d.views",                  std::bind(&download_get_variable, std::placeholders::_1, "rtorrent", "views"));
815   CMD2_DL         ("d.views.has",              std::bind(&d_list_has, std::placeholders::_1, std::placeholders::_2, "rtorrent", "views"));
816   CMD2_DL         ("d.views.remove",           std::bind(&d_list_remove, std::placeholders::_1, std::placeholders::_2, "rtorrent", "views"));
817   CMD2_DL         ("d.views.push_back",        std::bind(&d_list_push_back, std::placeholders::_1, std::placeholders::_2, "rtorrent", "views"));
818   CMD2_DL         ("d.views.push_back_unique", std::bind(&d_list_push_back_unique, std::placeholders::_1, std::placeholders::_2, "rtorrent", "views"));
819 
820   // This command really needs to be improved, so we have proper
821   // logging support.
822   CMD2_DL         ("d.message",     std::bind(&core::Download::message, std::placeholders::_1));
823   CMD2_DL_STRING_V("d.message.set", std::bind(&core::Download::set_message, std::placeholders::_1, std::placeholders::_2));
824 
825   CMD2_DL         ("d.max_file_size",       CMD2_ON_FL(max_file_size));
826   CMD2_DL_VALUE_V ("d.max_file_size.set",   std::bind(&torrent::FileList::set_max_file_size, CMD2_BIND_FL, std::placeholders::_2));
827 
828   CMD2_DL         ("d.peers_min",           std::bind(&torrent::ConnectionList::min_size, CMD2_BIND_CL));
829   CMD2_DL_VALUE_V ("d.peers_min.set",       std::bind(&torrent::ConnectionList::set_min_size, CMD2_BIND_CL, std::placeholders::_2));
830   CMD2_DL         ("d.peers_max",           std::bind(&torrent::ConnectionList::max_size, CMD2_BIND_CL));
831   CMD2_DL_VALUE_V ("d.peers_max.set",       std::bind(&torrent::ConnectionList::set_max_size, CMD2_BIND_CL, std::placeholders::_2));
832   CMD2_DL         ("d.uploads_max",         std::bind(&torrent::Download::uploads_max, CMD2_BIND_DL));
833   CMD2_DL_VALUE_V ("d.uploads_max.set",     std::bind(&torrent::Download::set_uploads_max, CMD2_BIND_DL, std::placeholders::_2));
834   CMD2_DL         ("d.uploads_min",         std::bind(&torrent::Download::uploads_min, CMD2_BIND_DL));
835   CMD2_DL_VALUE_V ("d.uploads_min.set",     std::bind(&torrent::Download::set_uploads_min, CMD2_BIND_DL, std::placeholders::_2));
836   CMD2_DL         ("d.downloads_max",         std::bind(&torrent::Download::downloads_max, CMD2_BIND_DL));
837   CMD2_DL_VALUE_V ("d.downloads_max.set",     std::bind(&torrent::Download::set_downloads_max, CMD2_BIND_DL, std::placeholders::_2));
838   CMD2_DL         ("d.downloads_min",         std::bind(&torrent::Download::downloads_min, CMD2_BIND_DL));
839   CMD2_DL_VALUE_V ("d.downloads_min.set",     std::bind(&torrent::Download::set_downloads_min, CMD2_BIND_DL, std::placeholders::_2));
840   CMD2_DL         ("d.peers_connected",     std::bind(&torrent::ConnectionList::size, CMD2_BIND_CL));
841   CMD2_DL         ("d.peers_not_connected", std::bind(&torrent::PeerList::available_list_size, CMD2_BIND_PL));
842 
843   CMD2_DL         ("d.peers_complete",      CMD2_ON_DL(peers_complete));
844   CMD2_DL         ("d.peers_accounted",     CMD2_ON_DL(peers_accounted));
845 
846   CMD2_DL_V       ("d.disconnect.seeders",        std::bind(&torrent::ConnectionList::erase_seeders, CMD2_BIND_CL));
847 
848   CMD2_DL         ("d.accepting_seeders",         CMD2_ON_INFO(is_accepting_seeders));
849   CMD2_DL_V       ("d.accepting_seeders.enable",  std::bind(&torrent::DownloadInfo::public_set_flags,   CMD2_BIND_INFO, torrent::DownloadInfo::flag_accepting_seeders));
850   CMD2_DL_V       ("d.accepting_seeders.disable", std::bind(&torrent::DownloadInfo::public_unset_flags, CMD2_BIND_INFO, torrent::DownloadInfo::flag_accepting_seeders));
851 
852   CMD2_DL         ("d.throttle_name",     std::bind(&download_get_variable, std::placeholders::_1, "rtorrent", "throttle_name"));
853   CMD2_DL_STRING_V("d.throttle_name.set", std::bind(&core::Download::set_throttle_name, std::placeholders::_1, std::placeholders::_2));
854 
855   CMD2_DL         ("d.bytes_done",     CMD2_ON_DL(bytes_done));
856   CMD2_DL         ("d.ratio",          std::bind(&retrieve_d_ratio, std::placeholders::_1));
857   CMD2_DL         ("d.chunks_hashed",  CMD2_ON_DL(chunks_hashed));
858   CMD2_DL         ("d.free_diskspace", CMD2_ON_FL(free_diskspace));
859 
860   CMD2_DL         ("d.size_files",     CMD2_ON_FL(size_files));
861   CMD2_DL         ("d.size_bytes",     CMD2_ON_FL(size_bytes));
862   CMD2_DL         ("d.size_chunks",    CMD2_ON_FL(size_chunks));
863   CMD2_DL         ("d.chunk_size",     CMD2_ON_FL(chunk_size));
864   CMD2_DL         ("d.size_pex",       CMD2_ON_DL(size_pex));
865   CMD2_DL         ("d.max_size_pex",   CMD2_ON_DL(max_size_pex));
866 
867   CMD2_DL         ("d.chunks_seen",      std::bind(&d_chunks_seen, std::placeholders::_1));
868 
869   CMD2_DL         ("d.completed_bytes",  CMD2_ON_FL(completed_bytes));
870   CMD2_DL         ("d.completed_chunks", CMD2_ON_FL(completed_chunks));
871   CMD2_DL         ("d.left_bytes",       CMD2_ON_FL(left_bytes));
872 
873   CMD2_DL         ("d.wanted_chunks",    CMD2_ON_DATA(wanted_chunks));
874 
875   CMD2_DL_V       ("d.tracker_announce",     std::bind(&torrent::Download::manual_request, CMD2_BIND_DL, false));
876   CMD2_DL_V       ("d.tracker_announce.force", std::bind(&torrent::Download::manual_request, CMD2_BIND_DL, true));
877   CMD2_DL         ("d.tracker_numwant",      std::bind(&torrent::TrackerList::numwant, CMD2_BIND_TL));
878   CMD2_DL_VALUE_V ("d.tracker_numwant.set",  std::bind(&torrent::TrackerList::set_numwant, CMD2_BIND_TL, std::placeholders::_2));
879   // TODO: Deprecate 'd.tracker_focus'.
880   CMD2_DL         ("d.tracker_focus",        std::bind(&core::Download::tracker_list_size, std::placeholders::_1));
881   CMD2_DL         ("d.tracker_size",         std::bind(&core::Download::tracker_list_size, std::placeholders::_1));
882 
883   CMD2_DL_LIST    ("d.tracker.insert",       std::bind(&download_tracker_insert, std::placeholders::_1, std::placeholders::_2));
884   CMD2_DL_VALUE_V ("d.tracker.send_scrape",  std::bind(&torrent::TrackerController::scrape_request, CMD2_BIND_TC, std::placeholders::_2));
885 
886   CMD2_DL         ("d.directory",          CMD2_ON_FL(root_dir));
887   CMD2_DL_STRING_V("d.directory.set",      std::bind(&apply_d_directory, std::placeholders::_1, std::placeholders::_2));
888   CMD2_DL         ("d.directory_base",     CMD2_ON_FL(root_dir));
889   CMD2_DL_STRING_V("d.directory_base.set", std::bind(&core::Download::set_root_directory, std::placeholders::_1, std::placeholders::_2));
890 
891   CMD2_DL         ("d.priority",     std::bind(&core::Download::priority, std::placeholders::_1));
892   CMD2_DL         ("d.priority_str", std::bind(&retrieve_d_priority_str, std::placeholders::_1));
893   CMD2_DL_VALUE_V ("d.priority.set", std::bind(&core::Download::set_priority, std::placeholders::_1, std::placeholders::_2));
894 
895   // CMD2_DL         ("d.group",     std::bind(&torrent::resource_manager_entry::group,
896   //                                           std::bind(&torrent::ResourceManager::entry_at, torrent::resource_manager(),
897   //                                                     std::bind(&core::Download::main, std::placeholders::_1))));
898 
899   // CMD2_DL_V       ("d.group.set", std::bind(&torrent::ResourceManager::set_group,
900   //                                           torrent::resource_manager(),
901   //                                           std::bind(&torrent::ResourceManager::find_throw, torrent::resource_manager(),
902   //                                                     std::bind(&core::Download::main, std::placeholders::_1)),
903   //                                           CG_GROUP_INDEX()));
904 
905   CMD2_DL         ("d.group",      std::bind(&cg_d_group, std::placeholders::_1));
906   CMD2_DL         ("d.group.name", std::bind(&cg_d_group, std::placeholders::_1));
907   CMD2_DL_V       ("d.group.set",  std::bind(&cg_d_group_set, std::placeholders::_1, std::placeholders::_2));
908 
909   CMD2_DL_LIST    ("f.multicall", std::bind(&f_multicall, std::placeholders::_1, std::placeholders::_2));
910   CMD2_DL_LIST    ("p.multicall", std::bind(&p_multicall, std::placeholders::_1, std::placeholders::_2));
911   CMD2_DL_LIST    ("t.multicall", std::bind(&t_multicall, std::placeholders::_1, std::placeholders::_2));
912 
913   CMD2_ANY_LIST   ("p.call_target", std::bind(&p_call_target, std::placeholders::_2));
914 }
915