about summary refs log tree commit diff
path: root/cli
diff options
context:
space:
mode:
authorRichard Nyberg <rnyberg@murmeldjur.se>2006-10-06 15:02:35 +0000
committerRichard Nyberg <rnyberg@murmeldjur.se>2006-10-06 15:02:35 +0000
commitba9ae40fe714e7a4afa382aca08ee16336a8c50d (patch)
treef408db98c1694a00ff35d450680db0c2a9fd525b /cli
parent30601882e51026220c160a706929bcbdd223c246 (diff)
downloadbtpd-ba9ae40fe714e7a4afa382aca08ee16336a8c50d.tar.gz
btpd-ba9ae40fe714e7a4afa382aca08ee16336a8c50d.zip
Add command to stop all active torrents. The command is sent by
'btcli stop -a'.

Diffstat (limited to 'cli')
-rw-r--r--cli/stop.c39
1 files changed, 34 insertions, 5 deletions
diff --git a/cli/stop.c b/cli/stop.c
index 4d8258d..2377980 100644
--- a/cli/stop.c
+++ b/cli/stop.c
@@ -6,22 +6,51 @@ usage_stop(void)
     printf(
         "Stop torrents.\n"
         "\n"
-        "Usage: stop torrent ...\n"
+        "Usage: stop -a\n"
+        "       stop torrent ...\n"
+        "\n"
+        "Options:\n"
+        "-a\n"
+        "\tStop all active torrents.\n"
         "\n"
         );
     exit(1);
 }
 
+static struct option stop_opts [] = {
+    { "help", no_argument, NULL, 'H' },
+    {NULL, 0, NULL, 0}
+};
+
 void
 cmd_stop(int argc, char **argv)
 {
+    int ch, all = 0;
     struct ipc_torrent t;
 
-    if (argc < 2)
+    while ((ch = getopt_long(argc, argv, "a", stop_opts, NULL)) != -1) {
+        switch (ch) {
+        case 'a':
+            all = 1;
+            break;
+        default:
+            usage_stop();
+        }
+    }
+    argc -= optind;
+    argv += optind;
+
+    if ((argc == 0 && !all) || (all && argc != 0))
         usage_stop();
 
     btpd_connect();
-    for (int i = 1; i < argc; i++)
-        if (torrent_spec(argv[i], &t))
-            handle_ipc_res(btpd_stop(ipc, &t), "stop", argv[i]);
+    if (all) {
+        enum ipc_err code = btpd_stop_all(ipc);
+        if (code != IPC_OK)
+            errx(1, "%s", ipc_strerror(code));
+    } else {
+        for (int i = 0; i < argc; i++)
+            if (torrent_spec(argv[i], &t))
+                handle_ipc_res(btpd_stop(ipc, &t), "stop", argv[i]);
+    }
 }