@@ -323,6 +323,30 @@ cmd_start(struct cli *cli, int argc, const char *args) | |||||
return write_code_buffer(cli, code); | return write_code_buffer(cli, code); | ||||
} | } | ||||
static int | |||||
cmd_start_all(struct cli *cli, int argc, const char *args) | |||||
{ | |||||
struct htbl_iter it; | |||||
struct tlib *tl; | |||||
enum ipc_err last_code, ret_code= IPC_OK; | |||||
if (btpd_is_stopping()) | |||||
return write_code_buffer(cli, IPC_ESHUTDOWN); | |||||
for (tl = tlib_iter_first(&it); tl != NULL; tl = tlib_iter_next(&it)) { | |||||
if (torrent_startable(tl)) { | |||||
if ((last_code = torrent_start(tl)) == IPC_OK) { | |||||
active_add(tl->hash); | |||||
} else { | |||||
btpd_err("torrent_start(%d) failed.\n", tl->num); | |||||
ret_code = last_code; | |||||
} | |||||
} | |||||
} | |||||
return write_code_buffer(cli, ret_code); | |||||
} | |||||
static int | static int | ||||
cmd_stop(struct cli *cli, int argc, const char *args) | cmd_stop(struct cli *cli, int argc, const char *args) | ||||
{ | { | ||||
@@ -355,6 +379,7 @@ cmd_stop_all(struct cli *cli, int argc, const char *args) | |||||
{ | { | ||||
struct torrent *tp, *next; | struct torrent *tp, *next; | ||||
int ret = write_code_buffer(cli, IPC_OK); | int ret = write_code_buffer(cli, IPC_OK); | ||||
active_clear(); | active_clear(); | ||||
BTPDQ_FOREACH_MUTABLE(tp, torrent_get_all(), entry, next) | BTPDQ_FOREACH_MUTABLE(tp, torrent_get_all(), entry, next) | ||||
torrent_stop(tp, 0); | torrent_stop(tp, 0); | ||||
@@ -381,6 +406,7 @@ static struct { | |||||
{ "del", 3, cmd_del }, | { "del", 3, cmd_del }, | ||||
{ "die", 3, cmd_die }, | { "die", 3, cmd_die }, | ||||
{ "start", 5, cmd_start }, | { "start", 5, cmd_start }, | ||||
{ "start-all", 9, cmd_start_all}, | |||||
{ "stop", 4, cmd_stop }, | { "stop", 4, cmd_stop }, | ||||
{ "stop-all", 8, cmd_stop_all}, | { "stop-all", 8, cmd_stop_all}, | ||||
{ "tget", 4, cmd_tget } | { "tget", 4, cmd_tget } | ||||
@@ -12,6 +12,10 @@ usage_start(void) | |||||
"torrent ...\n" | "torrent ...\n" | ||||
"\tThe torrents to activate.\n" | "\tThe torrents to activate.\n" | ||||
"\n" | "\n" | ||||
"Options:\n" | |||||
"-a\n" | |||||
"\tActivate all inactive torrents.\n" | |||||
"\n" | |||||
); | ); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
@@ -24,19 +28,32 @@ static struct option start_opts [] = { | |||||
void | void | ||||
cmd_start(int argc, char **argv) | cmd_start(int argc, char **argv) | ||||
{ | { | ||||
int ch; | |||||
int ch, all = 0; | |||||
struct ipc_torrent t; | struct ipc_torrent t; | ||||
while ((ch = getopt_long(argc, argv, "", start_opts, NULL)) != -1) | |||||
usage_start(); | |||||
while ((ch = getopt_long(argc, argv, "a", start_opts, NULL)) != -1) { | |||||
switch (ch) { | |||||
case 'a': | |||||
all = 1; | |||||
break; | |||||
default: | |||||
usage_start(); | |||||
} | |||||
} | |||||
argc -= optind; | argc -= optind; | ||||
argv += optind; | argv += optind; | ||||
if (argc < 1) | |||||
if ((argc == 0 && !all) || (all && argc != 0)) | |||||
usage_start(); | usage_start(); | ||||
btpd_connect(); | btpd_connect(); | ||||
for (int i = 0; i < argc; i++) | |||||
if (torrent_spec(argv[i], &t)) | |||||
handle_ipc_res(btpd_start(ipc, &t), "start", argv[i]); | |||||
if (all) { | |||||
enum ipc_err code = btpd_start_all(ipc); | |||||
if (code != IPC_OK) | |||||
diemsg("command failed (%s).\n", ipc_strerror(code)); | |||||
} else { | |||||
for (int i = 0; i < argc; i++) | |||||
if (torrent_spec(argv[i], &t)) | |||||
handle_ipc_res(btpd_start(ipc, &t), "start", argv[i]); | |||||
} | |||||
} | } |
@@ -302,6 +302,14 @@ btpd_start(struct ipc *ipc, struct ipc_torrent *tp) | |||||
return simple_treq(ipc, "start", tp); | return simple_treq(ipc, "start", tp); | ||||
} | } | ||||
enum ipc_err | |||||
btpd_start_all(struct ipc *ipc) | |||||
{ | |||||
struct iobuf iob = iobuf_init(16); | |||||
iobuf_swrite(&iob, "l9:start-alle"); | |||||
return ipc_buf_req_code(ipc, &iob); | |||||
} | |||||
enum ipc_err | enum ipc_err | ||||
btpd_stop(struct ipc *ipc, struct ipc_torrent *tp) | btpd_stop(struct ipc *ipc, struct ipc_torrent *tp) | ||||
{ | { | ||||
@@ -78,6 +78,7 @@ enum ipc_err btpd_add(struct ipc *ipc, const char *mi, size_t mi_size, | |||||
const char *content, const char *name); | const char *content, const char *name); | ||||
enum ipc_err btpd_del(struct ipc *ipc, struct ipc_torrent *tp); | enum ipc_err btpd_del(struct ipc *ipc, struct ipc_torrent *tp); | ||||
enum ipc_err btpd_start(struct ipc *ipc, struct ipc_torrent *tp); | enum ipc_err btpd_start(struct ipc *ipc, struct ipc_torrent *tp); | ||||
enum ipc_err btpd_start_all(struct ipc *ipc); | |||||
enum ipc_err btpd_stop(struct ipc *ipc, struct ipc_torrent *tp); | enum ipc_err btpd_stop(struct ipc *ipc, struct ipc_torrent *tp); | ||||
enum ipc_err btpd_stop_all(struct ipc *ipc); | enum ipc_err btpd_stop_all(struct ipc *ipc); | ||||
enum ipc_err btpd_die(struct ipc *ipc); | enum ipc_err btpd_die(struct ipc *ipc); | ||||