public inbox for iwd@lists.linux.dev
 help / color / mirror / Atom feed
From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.linux.dev
Cc: James Prestwood <prestwoj@gmail.com>
Subject: [PATCH v3 12/13] client: refactor cmd_connect() and add find_network()
Date: Mon, 12 Aug 2024 08:46:12 -0700	[thread overview]
Message-ID: <20240812154613.126522-12-prestwoj@gmail.com> (raw)
In-Reply-To: <20240812154613.126522-1-prestwoj@gmail.com>

This will do all the lookup/searching needed to find a network
proxy object.
---
 client/station.c | 35 +++++++++++++++++++++++++----------
 1 file changed, 25 insertions(+), 10 deletions(-)

diff --git a/client/station.c b/client/station.c
index affb7f15..58aac29e 100644
--- a/client/station.c
+++ b/client/station.c
@@ -283,28 +283,26 @@ static char *connect_cmd_arg_completion(const char *text, int state,
 	return network_name_completion(device, text, state);
 }
 
-static enum cmd_status cmd_connect(const char *device_name,
-						char **argv, int argc)
+static const struct proxy_interface *find_network(const char *device_name,
+						const char *name,
+						const char *type)
 {
 	struct network_args network_args;
 	struct l_queue *match;
 	const struct proxy_interface *network_proxy;
 	const struct proxy_interface *device_proxy;
 
-	if (argc < 1)
-		return CMD_STATUS_INVALID_ARGS;
-
 	device_proxy = device_proxy_find_by_name(device_name);
 	if (!device_proxy)
-		return CMD_STATUS_INVALID_VALUE;
+		return NULL;
 
-	network_args.name = argv[0];
-	network_args.type = argc >= 2 ? argv[1] : NULL;
+	network_args.name = name;
+	network_args.type = type;
 
 	match = network_match_by_device_and_args(device_proxy, &network_args);
 	if (!match) {
 		display("Invalid network name '%s'\n", network_args.name);
-		return CMD_STATUS_INVALID_VALUE;
+		return NULL;
 	}
 
 	if (l_queue_length(match) > 1) {
@@ -315,11 +313,28 @@ static enum cmd_status cmd_connect(const char *device_name,
 
 		l_queue_destroy(match, NULL);
 
-		return CMD_STATUS_INVALID_VALUE;
+		return NULL;
 	}
 
 	network_proxy = l_queue_pop_head(match);
 	l_queue_destroy(match, NULL);
+
+	return network_proxy;
+}
+
+static enum cmd_status cmd_connect(const char *device_name,
+						char **argv, int argc)
+{
+	const struct proxy_interface *network_proxy;
+
+	if (argc < 1)
+		return CMD_STATUS_INVALID_ARGS;
+
+	network_proxy = find_network(device_name, argv[0],
+					argc >= 2 ? argv[1] : NULL);
+	if (!network_proxy)
+		return CMD_STATUS_INVALID_VALUE;
+
 	network_connect(network_proxy);
 
 	return CMD_STATUS_TRIGGERED;
-- 
2.34.1


  parent reply	other threads:[~2024-08-12 15:46 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-12 15:46 [PATCH v3 01/13] dbus: Add net.connman.iwd.BasicServiceSet interface James Prestwood
2024-08-12 15:46 ` [PATCH v3 02/13] network: Add BasicServiceSet object James Prestwood
2024-08-12 15:46 ` [PATCH v3 03/13] station: use network_bss_{start,stop}_update James Prestwood
2024-08-12 15:46 ` [PATCH v3 04/13] network: add ExtendedServiceSet DBus property James Prestwood
2024-08-12 15:46 ` [PATCH v3 05/13] network: remove network_bss_list_clear James Prestwood
2024-08-12 15:46 ` [PATCH v3 06/13] station: add ConnectedAccessPoint property James Prestwood
2024-08-12 15:46 ` [PATCH v3 07/13] doc: document BasicServiceSet API James Prestwood
2024-08-12 15:46 ` [PATCH v3 08/13] client: separate property header and values into two functions James Prestwood
2024-08-12 15:46 ` [PATCH v3 09/13] client: add net.connman.iwd.BasicServiceSet definition James Prestwood
2024-08-12 15:46 ` [PATCH v3 10/13] client: Add BasicServiceSets property to network James Prestwood
2024-08-12 15:46 ` [PATCH v3 11/13] client: add BasicServiceSet interface James Prestwood
2024-08-12 15:46 ` James Prestwood [this message]
2024-08-12 15:46 ` [PATCH v3 13/13] client: add station command "get-bsses" James Prestwood
2024-08-12 17:11 ` [PATCH v3 01/13] dbus: Add net.connman.iwd.BasicServiceSet interface Denis Kenzior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240812154613.126522-12-prestwoj@gmail.com \
    --to=prestwoj@gmail.com \
    --cc=iwd@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox