swanctl: Add possibility to query a specific pool by name
authorTobias Brunner <tobias@strongswan.org>
Wed, 9 Nov 2016 09:37:56 +0000 (10:37 +0100)
committerTobias Brunner <tobias@strongswan.org>
Thu, 16 Feb 2017 18:21:12 +0000 (19:21 +0100)
src/swanctl/commands/list_pools.c

index 429107e..a170ade 100644 (file)
@@ -1,6 +1,6 @@
 /*
 /*
- * Copyright (C) 2015 Tobias Brunner
- * Hochschule fuer Technik Rapperswil
+ * Copyright (C) 2015-2016 Tobias Brunner
+ * HSR Hochschule fuer Technik Rapperswil
  *
  * Copyright (C) 2014 Martin Willi
  * Copyright (C) 2014 revosec AG
  *
  * Copyright (C) 2014 Martin Willi
  * Copyright (C) 2014 revosec AG
@@ -58,7 +58,7 @@ static int list_pools(vici_conn_t *conn)
        vici_req_t *req;
        vici_res_t *res;
        command_format_options_t format = COMMAND_FORMAT_NONE;
        vici_req_t *req;
        vici_res_t *res;
        command_format_options_t format = COMMAND_FORMAT_NONE;
-       char *arg;
+       char *arg, *name = NULL;
        int ret = 0;
        bool leases = FALSE;
 
        int ret = 0;
        bool leases = FALSE;
 
@@ -77,6 +77,9 @@ static int list_pools(vici_conn_t *conn)
                        case 'l':
                                leases = TRUE;
                                continue;
                        case 'l':
                                leases = TRUE;
                                continue;
+                       case 'n':
+                               name = arg;
+                               continue;
                        case EOF:
                                break;
                        default:
                        case EOF:
                                break;
                        default:
@@ -90,6 +93,10 @@ static int list_pools(vici_conn_t *conn)
        {
                vici_add_key_valuef(req, "leases", "yes");
        }
        {
                vici_add_key_valuef(req, "leases", "yes");
        }
+       if (name)
+       {
+               vici_add_key_valuef(req, "name", "%s", name);
+       }
        res = vici_submit(req, conn);
        if (!res)
        {
        res = vici_submit(req, conn);
        if (!res)
        {
@@ -123,6 +130,7 @@ static void __attribute__ ((constructor))reg()
                        {"raw",                 'r', 0, "dump raw response message"},
                        {"pretty",              'P', 0, "dump raw response message in pretty print"},
                        {"leases",              'l', 0, "list leases of each pool"},
                        {"raw",                 'r', 0, "dump raw response message"},
                        {"pretty",              'P', 0, "dump raw response message in pretty print"},
                        {"leases",              'l', 0, "list leases of each pool"},
+                       {"name",                'n', 1, "filter pools by name"},
                }
        });
 }
                }
        });
 }