about summary refs log tree commit diff
path: root/cli/add.c
diff options
context:
space:
mode:
authorMarq Schneider <queueRAM@gmail.com>2012-05-06 22:54:39 -0500
committerMarq Schneider <queueRAM@gmail.com>2012-05-06 22:54:39 -0500
commit2fd1f7c34e9ee85d5b995dc165fe8531fcb0ad31 (patch)
tree9ade107538be478fad7b53cc35bb4fe464d3a04e /cli/add.c
parentb0b8a2faec6609582e61e78cd8242e866fb31019 (diff)
downloadbtpd-2fd1f7c34e9ee85d5b995dc165fe8531fcb0ad31.tar.gz
btpd-2fd1f7c34e9ee85d5b995dc165fe8531fcb0ad31.zip
Add optional label to be associated with torrent.
If none given, use announce URL as label.
Torrents added with previous versions of btpd will show up as "bad torrent entry"

Closes GH-26
Diffstat (limited to 'cli/add.c')
-rw-r--r--cli/add.c17
1 files changed, 13 insertions, 4 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;