Explorar el Código

btcli add now starts the torrent if not told otherwise. Soem cleanup and

improved error output.
master
Richard Nyberg hace 18 años
padre
commit
311a05f613
Se han modificado 9 ficheros con 36 adiciones y 33 borrados
  1. +16
    -3
      cli/add.c
  2. +6
    -6
      cli/btcli.c
  3. +2
    -2
      cli/btcli.h
  4. +1
    -1
      cli/del.c
  5. +3
    -1
      cli/kill.c
  6. +4
    -16
      cli/list.c
  7. +1
    -1
      cli/start.c
  8. +2
    -2
      cli/stat.c
  9. +1
    -1
      cli/stop.c

+ 16
- 3
cli/add.c Ver fichero

@@ -27,6 +27,7 @@ usage_add(void)

static struct option add_opts [] = {
{ "help", no_argument, NULL, 'H' },
{ "nostart", no_argument, NULL, 'N'},
{ "topdir", no_argument, NULL, 'T'},
{NULL, 0, NULL, 0}
};
@@ -34,12 +35,15 @@ static struct option add_opts [] = {
void
cmd_add(int argc, char **argv)
{
int ch, topdir = 0;
int ch, topdir = 0, start = 1;
size_t dirlen = 0;
char *dir = NULL, *name = NULL;

while ((ch = getopt_long(argc, argv, "d:n:", add_opts, NULL)) != -1) {
while ((ch = getopt_long(argc, argv, "Nd:n:", add_opts, NULL)) != -1) {
switch (ch) {
case 'N':
start = 0;
break;
case 'T':
topdir = 1;
break;
@@ -64,6 +68,7 @@ cmd_add(int argc, char **argv)
btpd_connect();
char *mi;
size_t mi_size;
enum ipc_err code;
char dpath[PATH_MAX];
struct io_buffer iob;

@@ -82,6 +87,14 @@ cmd_add(int argc, char **argv)
buf_swrite(&iob, "");
if (realpath(iob.buf, dpath) == NULL)
err(1, "realpath '%s'", dpath);
handle_ipc_res(btpd_add(ipc, mi, mi_size, dpath, name), argv[0]);
code = btpd_add(ipc, mi, mi_size, dpath, name);
if (code == 0 && start) {
struct ipc_torrent tspec;
tspec.by_hash = 1;
mi_info_hash(mi, tspec.u.hash);
code = btpd_start(ipc, &tspec);
}
if (code != IPC_OK)
errx(1, "%s", ipc_strerror(code));
return;
}

+ 6
- 6
cli/btcli.c Ver fichero

@@ -11,15 +11,15 @@ btpd_connect(void)
}

enum ipc_err
handle_ipc_res(enum ipc_err code, const char *target)
handle_ipc_res(enum ipc_err code, const char *cmd, const char *target)
{
switch (code) {
case IPC_OK:
break;
case IPC_COMMERR:
errx(1, "fatal error in communication with btpd");
errx(1, "%s", ipc_strerror(code));
default:
warnx("btpd response for '%s': %s", target, ipc_strerror(code));
warnx("%s '%s': %s", cmd, target, ipc_strerror(code));
}
return code;
}
@@ -61,7 +61,7 @@ torrent_spec(char *arg, struct ipc_torrent *tp)
return 1;
}

struct {
static struct {
const char *name;
void (*fun)(int, char **);
void (*help)(void);
@@ -77,7 +77,7 @@ struct {

int ncmds = sizeof(cmd_table) / sizeof(cmd_table[0]);

void
static void
usage(void)
{
printf(
@@ -104,7 +104,7 @@ usage(void)
exit(1);
}

struct option base_opts [] = {
static struct option base_opts [] = {
{ "help", no_argument, NULL, 'H' },
{NULL, 0, NULL, 0}
};


+ 2
- 2
cli/btcli.h Ver fichero

@@ -21,8 +21,8 @@ extern const char *btpd_dir;
extern struct ipc *ipc;

void btpd_connect(void);
enum ipc_err handle_ipc_res(enum ipc_err err, const char *target);
enum ipc_err handle_ipc_res(enum ipc_err err, const char *cmd,
const char *target);
char tstate_char(enum ipc_tstate ts);
int torrent_spec(char *arg, struct ipc_torrent *tp);



+ 1
- 1
cli/del.c Ver fichero

@@ -26,5 +26,5 @@ cmd_del(int argc, char **argv)
btpd_connect();
for (int i = 1; i < argc; i++)
if (torrent_spec(argv[i], &t))
handle_ipc_res(btpd_del(ipc, &t), argv[i]);
handle_ipc_res(btpd_del(ipc, &t), "del", argv[i]);
}

+ 3
- 1
cli/kill.c Ver fichero

@@ -21,6 +21,7 @@ void
cmd_kill(int argc, char **argv)
{
int seconds = -1;
enum ipc_err code;
char *endptr;

if (argc == 2) {
@@ -31,5 +32,6 @@ cmd_kill(int argc, char **argv)
usage_kill();

btpd_connect();
handle_ipc_res(btpd_die(ipc, seconds), "kill");
if ((code = btpd_die(ipc, seconds)) != 0)
errx(1, "%s", ipc_strerror(code));
}

+ 4
- 16
cli/list.c Ver fichero

@@ -30,9 +30,6 @@ itm_insert(struct items *itms, struct item *itm)
struct item *p;
BTPDQ_FOREACH(p, &itms->hd, entry)
if (itm->num < p->num)
#if 0
if (strcmp(itm->name, p->name) < 0)
#endif
break;
if (p != NULL)
BTPDQ_INSERT_BEFORE(p, itm, entry);
@@ -54,17 +51,6 @@ list_cb(int obji, enum ipc_err objerr, struct ipc_get_res *res, void *arg)
asprintf(&itm->name, "%.*s", (int)res[IPC_TVAL_NAME].v.str.l,
res[IPC_TVAL_NAME].v.str.p);
itm_insert(itms, itm);
#if 0
int *count = arg;
(*count)++;
printf("%4u %c.", (unsigned)res[IPC_TVAL_NUM].v.num,
tstate_char(res[IPC_TVAL_STATE].v.num));
if (res[IPC_TVAL_NAME].type == IPC_TYPE_ERR)
printf(" %s\n", ipc_strerror(res[IPC_TVAL_NAME].v.num));
else
printf(" %.*s\n", (int)res[IPC_TVAL_NAME].v.str.l,
res[IPC_TVAL_NAME].v.str.p);
#endif
}

void
@@ -90,7 +76,8 @@ static struct option list_opts [] = {
void
cmd_list(int argc, char **argv)
{
int ch, /*count = 0,*/ inactive = 0, active = 0;
int ch, inactive = 0, active = 0;
enum ipc_err code;
enum ipc_twc twc;
enum ipc_tval keys[] = { IPC_TVAL_NUM, IPC_TVAL_STATE, IPC_TVAL_NAME };
struct items itms;
@@ -118,7 +105,8 @@ cmd_list(int argc, char **argv)
printf("NUM ST NAME\n");
itms.count = 0;
BTPDQ_INIT(&itms.hd);
handle_ipc_res(btpd_tget_wc(ipc, twc, keys, 3, list_cb, &itms), "tget");
if ((code = btpd_tget_wc(ipc, twc, keys, 3, list_cb, &itms)) != IPC_OK)
errx(1, "%s", ipc_strerror(code));
print_items(&itms);
printf("Listed %d torrent%s.\n", itms.count, itms.count == 1 ? "" : "s");
}

+ 1
- 1
cli/start.c Ver fichero

@@ -23,5 +23,5 @@ cmd_start(int argc, char **argv)
btpd_connect();
for (int i = 1; i < argc; i++)
if (torrent_spec(argv[i], &t))
handle_ipc_res(btpd_start(ipc, &t), argv[i]);
handle_ipc_res(btpd_start(ipc, &t), "start", argv[i]);
}

+ 2
- 2
cli/stat.c Ver fichero

@@ -162,8 +162,8 @@ again:
stat_cb, &cba);
else
err = btpd_tget(ipc, tps, ntps, stkeys, nstkeys, stat_cb, &cba);
if (handle_ipc_res(err, "stat") != IPC_OK)
exit(1);
if (err != IPC_OK)
errx(1, ipc_strerror(err));
if (names)
printf("-----\n");
if (individual)


+ 1
- 1
cli/stop.c Ver fichero

@@ -23,5 +23,5 @@ cmd_stop(int argc, char **argv)
btpd_connect();
for (int i = 1; i < argc; i++)
if (torrent_spec(argv[i], &t))
handle_ipc_res(btpd_stop(ipc, &t), argv[i]);
handle_ipc_res(btpd_stop(ipc, &t), "stop", argv[i]);
}

Cargando…
Cancelar
Guardar