From patchwork Wed Jun 29 19:27:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12900639 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 08D267A for ; Wed, 29 Jun 2022 19:29:17 +0000 (UTC) Received: by mail-pj1-f50.google.com with SMTP id cv13so16568036pjb.4 for ; Wed, 29 Jun 2022 12:29:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hGNIyz1SSJAjs9vNjEYg+XJJhw8sk8UkWWsSzCbZNt8=; b=MExaCisBmQjiSzqiKpoLcyhmO7fYeqk8f8hYHjP4PmMML2dNFrLXYKbC75kxgQgUwm iimo6qWVmgClhuXoVEEsNZ3FSOVtIfHhpuwZ1DSChggxezBg1uOikZY12pNCE/io1J91 Hs45MpDRnltmdfF+P7zAdFBYYzIIfxldjDKTpD6Ut3LIlcPd2ivDg+C6ZGcB3BFnLm3t Dx9aOmhNav2BfGAQ+E9cge9+MH7K80xi3Dy3I8VQBvTqjpoW2zBhdRya7kGVtg0V4DCE GMWipSWDwst47f4urmhGMXfT+2pa7XQYbRK1Rn2AqO5dD64vh2lRFQ/eP9JQbZKwGLwf yGKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hGNIyz1SSJAjs9vNjEYg+XJJhw8sk8UkWWsSzCbZNt8=; b=HN9LqF+CnCnICH+0aEQCPTNBPylEw4a0bevrrKCT/0eMruAMKfmag3XA7i/E8WWqr7 8tU7a6IxIGWUPZDhzEhsVg0S4j9hZwJsifGmHWYsheZSICoGaedp/v7M/x/xNKgjSY1n CGJO3pgWPk9+MJMVCBGi7Cdg2UVu5kqI4QRv4jk90nDXuGeVziBNtlApWI99kg91Rfav iwUCcsgqTuBspSSyTXw3jy25ANPxM91VJoWvbaLJpjSMuoFsk84CDJ0gUJmTwEehUdDs yOp98vh3yXpyP2Lx2Xd4Ju63vTr7yAKbn2UENdePPPXV+MbvFA6E7ZO9N8N87SUzsC+H w0ng== X-Gm-Message-State: AJIora+nYI/nthrigJpJPzMFjTJ6tF7PewPoqtb4TNph7W4pYDLud3xr dzQ5Y6lp/93lbt5LRsm4GGb3WmV0x/s= X-Google-Smtp-Source: AGRyM1tKFKI8wnk0DAxXud/IjBVSVWh/TWcC85ubGV2Mooug54EXgvYzV6DXqo8llWkV830P0KMObQ== X-Received: by 2002:a17:90b:3e89:b0:1ee:195e:abaf with SMTP id rj9-20020a17090b3e8900b001ee195eabafmr7665325pjb.112.1656530957131; Wed, 29 Jun 2022 12:29:17 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id i29-20020a63585d000000b00407e25d4527sm11497734pgm.22.2022.06.29.12.29.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jun 2022 12:29:16 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 1/2] client: support multi-line print for long values Date: Wed, 29 Jun 2022 12:27:08 -0700 Message-Id: <20220629192709.38743-1-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The generic proxy property display was limited to a width for names/value which makes the output look nice and uniform, but will cut off any values which are longer than this limit. This patch adds some logic to detect this, and continue displaying the value on the next line. The width arguments were also updated to be unsigned, which allows checking the length without a cast. --- client/dbus-proxy.c | 21 +++++++++++++++++++-- client/dbus-proxy.h | 3 ++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/client/dbus-proxy.c b/client/dbus-proxy.c index 624ce4aa..9f05c0e7 100644 --- a/client/dbus-proxy.c +++ b/client/dbus-proxy.c @@ -49,7 +49,8 @@ static struct l_queue *proxy_interface_types; void proxy_properties_display(const struct proxy_interface *proxy, const char *caption, const char *margin, - int name_column_width, int value_column_width) + unsigned int name_column_width, + unsigned int value_column_width) { const void *data; const struct proxy_interface_property *properties; @@ -67,14 +68,30 @@ void proxy_properties_display(const struct proxy_interface *proxy, properties = proxy->type->properties; for (i = 0; properties[i].name; i++) { + const char *str; + size_t len; + size_t j; + if (!properties[i].tostr) continue; + str = properties[i].tostr(data); + len = str ? strlen(str) : 0; + display("%s%*s %-*s%-.*s\n", margin, 8, properties[i].is_read_write ? COLOR_BOLDGRAY " *" COLOR_OFF : "", name_column_width, properties[i].name, - value_column_width, properties[i].tostr(data) ? : ""); + value_column_width, str ? : ""); + + if (len <= value_column_width) + continue; + + /* Display remaining data */ + for (j = value_column_width; j < len; j += value_column_width) + display("%s%*s %-*s%-.*s\n", margin, 8, "", + name_column_width, "", value_column_width, + str + j); } } diff --git a/client/dbus-proxy.h b/client/dbus-proxy.h index 1d6af5de..34917e82 100644 --- a/client/dbus-proxy.h +++ b/client/dbus-proxy.h @@ -89,7 +89,8 @@ bool proxy_interface_method_call(const struct proxy_interface *proxy, void proxy_properties_display(const struct proxy_interface *proxy, const char *caption, const char *margin, - int name_column_width, int value_column_width); + unsigned int name_column_width, + unsigned int value_column_width); char *proxy_property_str_completion(const struct proxy_interface_type *type, proxy_property_match_func_t function, From patchwork Wed Jun 29 19:27:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12900640 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B296F6AB4 for ; Wed, 29 Jun 2022 19:29:18 +0000 (UTC) Received: by mail-pf1-f170.google.com with SMTP id x4so16041779pfq.2 for ; Wed, 29 Jun 2022 12:29:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fdnFL5XnWt70hBI3QkLY123iL6CCK5NEa7rKhqjbxIs=; b=MTynJJckER3AWHtwjuUxrrDQfAp7h6H3NIKIMQa++UNFldbmRllpe2h6ricmYu63p2 wyzMICqfGl6n051ZeGeWfZxqjyUTZTXlUk0c1XwSOT0OhfQDiWqjj7QP8KH+Bq9flu+V 21yGM5eeX+xsNaQD+mPd8ymMOn40Usq+U4m7hDPnxSwVVtVVRV0Pv7fQAL534uGrgBIO Hd0CU0syrJdxkR1uM3TvqJOC2vlLjJ9VVP4W+SiIg4t7ESxHGVYZ77Q8XgVIJTv2xWfW X4nJjzlkjN5Gkn1me0jsACTQPxQXBZ9hDicvUVXXCA66LWbPmtCeZ6osOt9X7qaGLvES PWzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fdnFL5XnWt70hBI3QkLY123iL6CCK5NEa7rKhqjbxIs=; b=Q9MlsQCjh6OCX3RjLPsaSaAdwK5SQo2lCW7wrCsiwm43B1fXp7vRkIGpNfpXqfle2c EuNoW7b/FVmqzH/kBfZEGDMBz8ZbmlS5fJfZFzn3z66QZLWc+oZ+BXFhtt4xhX3jBHRQ AZsvc0OJ0KhGbctfNEXbqiTCysAQRyZAW1a97yleQCALGe/1w7LAHcGLhrsKugWIOWs5 KNvByXpOWVnQ16siXR7gnFsv55kIqPFZ0X1OMs2Xelz5rnCe+dMlpGgkPD27xS095q0n JAg2AO4RGjTcCfTe0Y97/PE93yuLcaatDDUzR63exRx03JAIsi4TIf7LcMTEQJ7Ev+G2 8EBA== X-Gm-Message-State: AJIora/Kcr0bWY9TfGQponIBmVlhYpZsiDLqQt4CsqKJFNyMwUASn6BI arendvr0DpbzjIQxScDRw/XnSMApnHc= X-Google-Smtp-Source: AGRyM1tkzYEyBRN8O0OuKX6ZeudQK7+WTxknS98B4oJBE+LHmH1oQU8bp9wp4f74bSoz7U/5aJN97A== X-Received: by 2002:a65:53c8:0:b0:40d:77fc:5f05 with SMTP id z8-20020a6553c8000000b0040d77fc5f05mr4064183pgr.263.1656530957971; Wed, 29 Jun 2022 12:29:17 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id i29-20020a63585d000000b00407e25d4527sm11497734pgm.22.2022.06.29.12.29.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jun 2022 12:29:17 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 2/2] client: add "dpp show" command Date: Wed, 29 Jun 2022 12:27:09 -0700 Message-Id: <20220629192709.38743-2-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220629192709.38743-1-prestwoj@gmail.com> References: <20220629192709.38743-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This will show the newly added DPP properties --- client/dpp.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/client/dpp.c b/client/dpp.c index 120dd9ee..af69d2c0 100644 --- a/client/dpp.c +++ b/client/dpp.c @@ -34,8 +34,111 @@ #include "client/device.h" #include "client/display.h" +struct dpp { + bool started; + char *role; + char *uri; +}; + +static void *dpp_create(void) +{ + return l_new(struct dpp, 1); +} + +static void dpp_destroy(void *data) +{ + struct dpp *dpp = data; + + if (dpp->role) + l_free(dpp->role); + if (dpp->uri) + l_free(dpp->uri); + + l_free(dpp); +} + +static void update_started(void *data, struct l_dbus_message_iter *variant) +{ + struct dpp *dpp = data; + bool value; + + if (!l_dbus_message_iter_get_variant(variant, "b", &value)) { + dpp->started = false; + return; + } + + dpp->started = value; +} + +static const char *started_tostr(const void *data) +{ + const struct dpp *dpp = data; + + return dpp->started ? "yes" : "no"; +} + +static void update_role(void *data, struct l_dbus_message_iter *variant) +{ + struct dpp *dpp = data; + const char *value; + + if (dpp->role) + l_free(dpp->role); + + if (!l_dbus_message_iter_get_variant(variant, "s", &value)) { + dpp->role = NULL; + return; + } + + dpp->role = l_strdup(value); +} + +static const char *role_tostr(const void *data) +{ + const struct dpp *dpp = data; + + return dpp->role; +} + +static void update_uri(void *data, struct l_dbus_message_iter *variant) +{ + struct dpp *dpp = data; + const char *value; + + if (dpp->uri) + l_free(dpp->uri); + + if (!l_dbus_message_iter_get_variant(variant, "s", &value)) { + dpp->uri = NULL; + return; + } + + dpp->uri = l_strdup(value); +} + +static const char *uri_tostr(const void *data) +{ + const struct dpp *dpp = data; + + return dpp->uri; +} + +static const struct proxy_interface_property dpp_properties[] = { + { "Started", "b", update_started, started_tostr }, + { "Role", "s", update_role, role_tostr }, + { "URI", "s", update_uri, uri_tostr }, + { } +}; + +static const struct proxy_interface_type_ops dpp_ops = { + .create = dpp_create, + .destroy = dpp_destroy, +}; + static struct proxy_interface_type dpp_interface_type = { .interface = IWD_DPP_INTERFACE, + .properties = dpp_properties, + .ops = &dpp_ops, }; static void check_errors_method_callback(struct l_dbus_message *message, @@ -174,6 +277,19 @@ static enum cmd_status cmd_stop(const char *device_name, return CMD_STATUS_TRIGGERED; } +static enum cmd_status cmd_show(const char *device_name, + char **argv, int argc) +{ + const struct proxy_interface *proxy = + device_proxy_find(device_name, IWD_DPP_INTERFACE); + char *caption = l_strdup_printf("%s: %s", "DPP", device_name); + + proxy_properties_display(proxy, caption, MARGIN, 20, 47); + l_free(caption); + + return CMD_STATUS_DONE; +} + static const struct command dpp_commands[] = { { NULL, "list", NULL, cmd_list, "List DPP-capable devices", true }, { "", "start-enrollee", NULL, cmd_start_enrollee, @@ -181,6 +297,7 @@ static const struct command dpp_commands[] = { { "", "start-configurator", NULL, cmd_start_configurator, "Starts a DPP Configurator" }, { "", "stop", NULL, cmd_stop, "Aborts DPP operations" }, + { "", "show", NULL, cmd_show, "Shows the DPP state" }, { } };