From 71ea1e102a2976950af5add9426836f4c4d8d808 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Fri, 14 Sep 2018 02:48:20 -0500 Subject: [PATCH] client: Add device_proxy_find --- client/device.c | 41 +++++++++++++++++++++++++++++------------ client/device.h | 3 +++ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/client/device.c b/client/device.c index c580907c..729f0655 100644 --- a/client/device.c +++ b/client/device.c @@ -620,33 +620,50 @@ static const struct proxy_interface *device_get_default(void) return default_device; } -static const struct proxy_interface *get_device_proxy_by_name( - const char *device_name) +static const struct proxy_interface *device_proxy_find_by_name(const char *name) { struct l_queue *match; struct proxy_interface *proxy = NULL; - if (!device_name) + if (!name) return NULL; match = proxy_interface_find_all(device_interface_type.interface, - match_by_name, device_name); + match_by_name, name); if (l_queue_length(match)) proxy = l_queue_pop_head(match); else - display("Device %s not found.\n", device_name); + display("Device %s not found.\n", name); l_queue_destroy(match, NULL); return proxy; } +const struct proxy_interface *device_proxy_find(const char *device_name, + const char *interface) +{ + const struct proxy_interface *device_i = + device_proxy_find_by_name(device_name); + const struct proxy_interface *proxy; + + if (!device_i) + return NULL; + + proxy = proxy_interface_find(interface, + proxy_interface_get_path(device_i)); + if (!proxy) + return NULL; + + return proxy; +} + static enum cmd_status cmd_show(const char *device_name, char **argv, int argc) { const struct proxy_interface *proxy = - get_device_proxy_by_name(device_name); + device_proxy_find_by_name(device_name); if (!proxy) return CMD_STATUS_INVALID_ARGS; @@ -666,7 +683,7 @@ static enum cmd_status cmd_scan(const char *device_name, char **argv, int argc) { const struct proxy_interface *proxy = - get_device_proxy_by_name(device_name); + device_proxy_find_by_name(device_name); if (!proxy) return CMD_STATUS_INVALID_ARGS; @@ -681,7 +698,7 @@ static enum cmd_status cmd_disconnect(const char *device_name, char **argv, int argc) { const struct proxy_interface *proxy = - get_device_proxy_by_name(device_name); + device_proxy_find_by_name(device_name); if (!proxy) return CMD_STATUS_INVALID_ARGS; @@ -696,7 +713,7 @@ static enum cmd_status cmd_get_networks(const char *device_name, char **argv, int argc) { const struct proxy_interface *proxy = - get_device_proxy_by_name(device_name); + device_proxy_find_by_name(device_name); if (!proxy) return CMD_STATUS_INVALID_ARGS; @@ -733,7 +750,7 @@ static enum cmd_status cmd_set_property(const char *device_name, char **argv, int argc) { const struct proxy_interface *proxy = - get_device_proxy_by_name(device_name); + device_proxy_find_by_name(device_name); if (!proxy) return CMD_STATUS_INVALID_VALUE; @@ -755,7 +772,7 @@ static enum cmd_status cmd_connect(const char *device_name, struct l_queue *match; const struct proxy_interface *network_proxy; const struct proxy_interface *device_proxy = - get_device_proxy_by_name(device_name); + device_proxy_find_by_name(device_name); if (!device_proxy) return CMD_STATUS_INVALID_VALUE; @@ -795,7 +812,7 @@ static enum cmd_status cmd_connect_hidden_network(const char *device_name, int argc) { const struct proxy_interface *proxy = - get_device_proxy_by_name(device_name); + device_proxy_find_by_name(device_name); if (!proxy) return CMD_STATUS_INVALID_VALUE; diff --git a/client/device.h b/client/device.h index 3a0750d1..07ba922b 100644 --- a/client/device.h +++ b/client/device.h @@ -20,6 +20,7 @@ * */ +struct proxy_interface; const struct proxy_interface *device_wsc_get(const char *device_name); char *device_wsc_family_arg_completion(const char *text, int state); @@ -29,3 +30,5 @@ char *device_ap_family_arg_completion(const char *text, int state); const struct proxy_interface *device_ad_hoc_get(const char *device_name); char *device_ad_hoc_family_arg_completion(const char *text, int state); +const struct proxy_interface *device_proxy_find(const char *device_name, + const char *interface);