about summary refs log tree commit diff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/add.c17
-rw-r--r--cli/list.c10
2 files changed, 21 insertions, 6 deletions
diff --git a/cli/add.c b/cli/add.c
index 53b4ac2..83af7df 100644
--- a/cli/add.c
+++ b/cli/add.c
@@ -40,10 +40,10 @@ void
 cmd_add(int argc, char **argv)
 {
     int ch, topdir = 0, start = 1, nfile, nloaded = 0;
-    size_t dirlen = 0;
-    char *dir = NULL, *name = NULL;
+    size_t dirlen = 0, labellen = 0;
+    char *dir = NULL, *name = NULL, *glabel = NULL, *label;
 
-    while ((ch = getopt_long(argc, argv, "NTd:n:", add_opts, NULL)) != -1) {
+    while ((ch = getopt_long(argc, argv, "NTd:l:n:", add_opts, NULL)) != -1) {
         switch (ch) {
         case 'N':
             start = 0;
@@ -56,6 +56,11 @@ cmd_add(int argc, char **argv)
             if ((dirlen = strlen(dir)) == 0)
                 diemsg("bad option value for -d.\n");
             break;
+        case 'l':
+            glabel = optarg;
+            if ((labellen = strlen(dir)) == 0)
+                diemsg("bad option value for -l.\n");
+            break;
         case 'n':
             name = optarg;
             break;
@@ -96,7 +101,11 @@ cmd_add(int argc, char **argv)
            iobuf_free(&iob);
            continue;
        }
-       code = btpd_add(ipc, mi, mi_size, dpath, name);
+       if(NULL == glabel)
+          label = benc_dget_str(mi, "announce", NULL);
+       else
+          label = glabel;
+       code = btpd_add(ipc, mi, mi_size, dpath, name, label);
        if ((code == IPC_OK) && start) {
            struct ipc_torrent tspec;
            tspec.by_hash = 1;
diff --git a/cli/list.c b/cli/list.c
index f8659f3..bc4edf0 100644
--- a/cli/list.c
+++ b/cli/list.c
@@ -28,7 +28,7 @@ usage_list(void)
 
 struct item {
     unsigned num, peers;
-    char *name, *dir;
+    char *name, *dir, *label;
     char hash[SHAHEXSIZE];
     char st;
     long long cgot, csize, totup, downloaded, uploaded, rate_up, rate_down;
@@ -79,6 +79,11 @@ list_cb(int obji, enum ipc_err objerr, struct ipc_get_res *res, void *arg)
     else
         asprintf(&itm->dir, "%.*s", (int)res[IPC_TVAL_DIR].v.str.l,
             res[IPC_TVAL_DIR].v.str.p);
+    if (res[IPC_TVAL_LABEL].type == IPC_TYPE_ERR)
+        asprintf(&itm->label, "%s", ipc_strerror(res[IPC_TVAL_LABEL].v.num));
+    else
+        asprintf(&itm->label, "%.*s", (int)res[IPC_TVAL_LABEL].v.str.l,
+            res[IPC_TVAL_LABEL].v.str.p);
     bin2hex(res[IPC_TVAL_IHASH].v.str.p, itm->hash, 20);
     itm->cgot           = res[IPC_TVAL_CGOT].v.num;
     itm->csize          = res[IPC_TVAL_CSIZE].v.num;
@@ -121,6 +126,7 @@ print_items(struct items* itms, char *format)
                             case 'd': printf("%s",   p->dir);            break;
                             case 'g': printf("%lld", p->cgot);           break;
                             case 'h': printf("%s",   p->hash);           break;
+                            case 'l': printf("%s",   p->label);          break;
                             case 'n': printf("%s",   p->name);           break;
                             case 'p': print_percent(p->cgot, p->csize);  break;
                             case 'r': print_ratio(p->totup, p->csize);   break;
@@ -170,7 +176,7 @@ cmd_list(int argc, char **argv)
            IPC_TVAL_TOTUP,   IPC_TVAL_CSIZE,  IPC_TVAL_CGOT,    IPC_TVAL_PCOUNT,
            IPC_TVAL_PCCOUNT, IPC_TVAL_PCSEEN, IPC_TVAL_PCGOT,   IPC_TVAL_SESSUP,
            IPC_TVAL_SESSDWN, IPC_TVAL_RATEUP, IPC_TVAL_RATEDWN, IPC_TVAL_IHASH,
-           IPC_TVAL_DIR };
+           IPC_TVAL_DIR, IPC_TVAL_LABEL };
     size_t nkeys = ARRAY_COUNT(keys);
     struct items itms;
     while ((ch = getopt_long(argc, argv, "aif:", list_opts, NULL)) != -1) {