2022-08-16 06:03:27

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ 1/2] client: Move admin submenu

From: Luiz Augusto von Dentz <[email protected]>

This moves admin submenu to admin.c so it is not mixed up with other
submenus code.
---
client/admin.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++---
client/admin.h | 8 ++---
client/main.c | 82 ++----------------------------------------
3 files changed, 96 insertions(+), 91 deletions(-)

diff --git a/client/admin.c b/client/admin.c
index 863590172428..cd9af6f955da 100644
--- a/client/admin.c
+++ b/client/admin.c
@@ -31,20 +31,22 @@
#include "admin.h"
#define _GNU_SOURCE

+static DBusConnection *dbus_conn;
+static GList *admin_proxies;
static GDBusProxy *set_proxy;
static GDBusProxy *status_proxy;

-void admin_policy_set_set_proxy(GDBusProxy *proxy)
+static void admin_policy_set_set_proxy(GDBusProxy *proxy)
{
set_proxy = proxy;
}

-void admin_policy_set_status_proxy(GDBusProxy *proxy)
+static void admin_policy_set_status_proxy(GDBusProxy *proxy)
{
status_proxy = proxy;
}

-void admin_policy_read_service_allowlist(DBusConnection *dbus_conn)
+static void admin_policy_read_service_allowlist(DBusConnection *dbus_conn)
{
DBusMessageIter iter, subiter;
char *uuid = NULL;
@@ -111,8 +113,7 @@ static void set_service_reply(DBusMessage *message, void *user_data)
return bt_shell_noninteractive_quit(EXIT_FAILURE);
}

-void admin_policy_set_service_allowlist(DBusConnection *dbus_connd,
- int argc, char *argv[])
+static void admin_policy_set_service_allowlist(int argc, char *argv[])
{
struct uuid_list_data data;

@@ -131,3 +132,89 @@ void admin_policy_set_service_allowlist(DBusConnection *dbus_connd,
return bt_shell_noninteractive_quit(EXIT_FAILURE);
}
}
+
+static void cmd_admin_allow(int argc, char *argv[])
+{
+ if (argc <= 1) {
+ admin_policy_read_service_allowlist(dbus_conn);
+ return;
+ }
+
+ if (strcmp(argv[1], "clear") == 0)
+ argc--;
+
+ admin_policy_set_service_allowlist(argc - 1, argv + 1);
+}
+
+static const struct bt_shell_menu admin_menu = {
+ .name = "admin",
+ .desc = "Admin Policy Submenu",
+ .entries = {
+ { "allow", "[clear/uuid1 uuid2 ...]", cmd_admin_allow,
+ "Allow service UUIDs and block rest of them"},
+ {} },
+};
+
+static void admin_policy_status_added(GDBusProxy *proxy)
+{
+ admin_proxies = g_list_append(admin_proxies, proxy);
+ admin_policy_set_status_proxy(proxy);
+}
+
+static void proxy_added(GDBusProxy *proxy, void *user_data)
+{
+ const char *interface;
+
+ interface = g_dbus_proxy_get_interface(proxy);
+
+ if (!strcmp(interface, "org.bluez.AdminPolicySet1"))
+ admin_policy_set_set_proxy(proxy);
+ else if (!strcmp(interface, "org.bluez.AdminPolicyStatus1"))
+ admin_policy_status_added(proxy);
+}
+
+static void admin_policy_status_removed(GDBusProxy *proxy)
+{
+ admin_proxies = g_list_remove(admin_proxies, proxy);
+ admin_policy_set_status_proxy(NULL);
+}
+
+static void proxy_removed(GDBusProxy *proxy, void *user_data)
+{
+ const char *interface;
+
+ interface = g_dbus_proxy_get_interface(proxy);
+
+ if (!strcmp(interface, "org.bluez.AdminPolicySet1"))
+ admin_policy_set_set_proxy(NULL);
+ else if (!strcmp(interface, "org.bluez.AdminPolicyStatus1"))
+ admin_policy_status_removed(proxy);
+}
+
+static GDBusClient *client;
+
+static void disconnect_handler(DBusConnection *connection, void *user_data)
+{
+ g_list_free_full(admin_proxies, NULL);
+ admin_proxies = NULL;
+}
+
+void admin_add_submenu(void)
+{
+ bt_shell_add_submenu(&admin_menu);
+
+ dbus_conn = bt_shell_get_env("DBUS_CONNECTION");
+ if (!dbus_conn || client)
+ return;
+
+ client = g_dbus_client_new(dbus_conn, "org.bluez", "/org/bluez");
+ g_dbus_client_set_proxy_handlers(client, proxy_added, proxy_removed,
+ NULL, NULL);
+ g_dbus_client_set_disconnect_watch(client, disconnect_handler, NULL);
+}
+
+void admin_remove_submenu(void)
+{
+ g_dbus_client_unref(client);
+ client = NULL;
+}
diff --git a/client/admin.h b/client/admin.h
index 1c8c2152d59d..4da83e4e36ba 100644
--- a/client/admin.h
+++ b/client/admin.h
@@ -17,9 +17,5 @@
*
*/

-void admin_policy_set_set_proxy(GDBusProxy *proxy);
-void admin_policy_set_status_proxy(GDBusProxy *proxy);
-
-void admin_policy_read_service_allowlist(DBusConnection *dbus_conn);
-void admin_policy_set_service_allowlist(DBusConnection *dbus_conn,
- int argc, char *argv[]);
+void admin_add_submenu(void);
+void admin_remove_submenu(void);
diff --git a/client/main.c b/client/main.c
index 1df94f000cea..19139d15b38e 100644
--- a/client/main.c
+++ b/client/main.c
@@ -57,7 +57,6 @@ static GDBusProxy *default_dev;
static GDBusProxy *default_attr;
static GList *ctrl_list;
static GList *battery_proxies;
-static GList *admin_devices_proxies;

static const char *agent_arguments[] = {
"on",
@@ -563,26 +562,6 @@ static void admon_manager_added(GDBusProxy *proxy)
adv_monitor_register_app(dbus_conn);
}

-static void admin_policy_set_added(GDBusProxy *proxy)
-{
- admin_policy_set_set_proxy(proxy);
-}
-
-static void admin_policy_status_added(GDBusProxy *proxy)
-{
- struct adapter *adapter;
-
- adapter = find_ctrl(ctrl_list, g_dbus_proxy_get_path(proxy));
-
- if (!adapter) {
- admin_devices_proxies = g_list_append(admin_devices_proxies,
- proxy);
- return;
- }
-
- admin_policy_set_status_proxy(proxy);
-}
-
static void proxy_added(GDBusProxy *proxy, void *user_data)
{
const char *interface;
@@ -618,10 +597,6 @@ static void proxy_added(GDBusProxy *proxy, void *user_data)
} else if (!strcmp(interface,
"org.bluez.AdvertisementMonitorManager1")) {
admon_manager_added(proxy);
- } else if (!strcmp(interface, "org.bluez.AdminPolicySet1")) {
- admin_policy_set_added(proxy);
- } else if (!strcmp(interface, "org.bluez.AdminPolicyStatus1")) {
- admin_policy_status_added(proxy);
}
}

@@ -678,26 +653,6 @@ static void adapter_removed(GDBusProxy *proxy)
}
}

-static void admin_policy_set_removed(GDBusProxy *proxy)
-{
- admin_policy_set_set_proxy(NULL);
-}
-
-static void admin_policy_status_removed(GDBusProxy *proxy)
-{
- struct adapter *adapter;
-
- adapter = find_ctrl(ctrl_list, g_dbus_proxy_get_path(proxy));
-
- if (!adapter) {
- admin_devices_proxies = g_list_remove(admin_devices_proxies,
- proxy);
- return;
- }
-
- admin_policy_set_status_proxy(NULL);
-}
-
static void proxy_removed(GDBusProxy *proxy, void *user_data)
{
const char *interface;
@@ -738,10 +693,6 @@ static void proxy_removed(GDBusProxy *proxy, void *user_data)
} else if (!strcmp(interface,
"org.bluez.AdvertisementMonitorManager1")) {
adv_monitor_remove_manager(dbus_conn);
- } else if (!strcmp(interface, "org.bluez.AdminPolicySet1")) {
- admin_policy_set_removed(proxy);
- } else if (!strcmp(interface, "org.bluez.AdminPolicyStatus1")) {
- admin_policy_status_removed(proxy);
}
}

@@ -1772,7 +1723,6 @@ static struct GDBusProxy *find_device(int argc, char *argv[])
static void cmd_info(int argc, char *argv[])
{
GDBusProxy *proxy;
- GDBusProxy *admin_proxy;
GDBusProxy *battery_proxy;
DBusMessageIter iter;
const char *address;
@@ -1819,12 +1769,8 @@ static void cmd_info(int argc, char *argv[])

battery_proxy = find_proxies_by_path(battery_proxies,
g_dbus_proxy_get_path(proxy));
- admin_proxy = find_proxies_by_path(admin_devices_proxies,
- g_dbus_proxy_get_path(proxy));
print_property_with_label(battery_proxy, "Percentage",
"Battery Percentage");
- print_property_with_label(admin_proxy, "AffectedByPolicy",
- "Affected by Policy");

return bt_shell_noninteractive_quit(EXIT_SUCCESS);
}
@@ -2948,22 +2894,6 @@ static void cmd_adv_monitor_get_supported_info(int argc, char *argv[])
adv_monitor_get_supported_info();
}

-static void cmd_admin_allow(int argc, char *argv[])
-{
- if (check_default_ctrl() == FALSE)
- return bt_shell_noninteractive_quit(EXIT_FAILURE);
-
- if (argc <= 1) {
- admin_policy_read_service_allowlist(dbus_conn);
- return;
- }
-
- if (strcmp(argv[1], "clear") == 0)
- argc--;
-
- admin_policy_set_service_allowlist(dbus_conn, argc - 1, argv + 1);
-}
-
static const struct bt_shell_menu advertise_menu = {
.name = "advertise",
.desc = "Advertise Options Submenu",
@@ -3118,15 +3048,6 @@ static const struct bt_shell_menu gatt_menu = {
{ } },
};

-static const struct bt_shell_menu admin_menu = {
- .name = "admin",
- .desc = "Admin Policy Submenu",
- .entries = {
- { "allow", "[clear/uuid1 uuid2 ...]", cmd_admin_allow,
- "Allow service UUIDs and block rest of them"},
- {} },
-};
-
static const struct bt_shell_menu main_menu = {
.name = "main",
.entries = {
@@ -3225,7 +3146,6 @@ int main(int argc, char *argv[])
bt_shell_add_submenu(&advertise_monitor_menu);
bt_shell_add_submenu(&scan_menu);
bt_shell_add_submenu(&gatt_menu);
- bt_shell_add_submenu(&admin_menu);
bt_shell_set_prompt(PROMPT_OFF);

if (agent_option)
@@ -3238,6 +3158,7 @@ int main(int argc, char *argv[])

bt_shell_set_env("DBUS_CONNECTION", dbus_conn);

+ admin_add_submenu();
player_add_submenu();

client = g_dbus_client_new(dbus_conn, "org.bluez", "/org/bluez");
@@ -3253,6 +3174,7 @@ int main(int argc, char *argv[])

status = bt_shell_run();

+ admin_remove_submenu();
player_remove_submenu();

g_dbus_client_unref(client);
--
2.37.2


2022-08-16 09:15:44

by bluez.test.bot

[permalink] [raw]
Subject: RE: [BlueZ,1/2] client: Move admin submenu

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=667869

---Test result---

Test Summary:
CheckPatch FAIL 1.49 seconds
GitLint PASS 0.91 seconds
Prep - Setup ELL PASS 32.40 seconds
Build - Prep PASS 0.89 seconds
Build - Configure PASS 10.00 seconds
Build - Make PASS 1134.24 seconds
Make Check PASS 13.10 seconds
Make Check w/Valgrind PASS 343.48 seconds
Make Distcheck PASS 300.03 seconds
Build w/ext ELL - Configure PASS 10.97 seconds
Build w/ext ELL - Make PASS 108.11 seconds
Incremental Build w/ patches PASS 256.87 seconds
Scan Build PASS 673.96 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script with rule in .checkpatch.conf
Output:
[BlueZ,1/2] client: Move admin submenu
ERROR:SPACING: need consistent spacing around '*' (ctx:WxV)
#192: FILE: client/admin.c:194:
+static GDBusClient *client;
^

/github/workspace/src/12944326.patch total: 1 errors, 0 warnings, 290 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/12944326.patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.




---
Regards,
Linux Bluetooth

2022-08-16 23:30:41

by patchwork-bot+bluetooth

[permalink] [raw]
Subject: Re: [PATCH BlueZ 1/2] client: Move admin submenu

Hello:

This series was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <[email protected]>:

On Mon, 15 Aug 2022 16:26:30 -0700 you wrote:
> From: Luiz Augusto von Dentz <[email protected]>
>
> This moves admin submenu to admin.c so it is not mixed up with other
> submenus code.
> ---
> client/admin.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++---
> client/admin.h | 8 ++---
> client/main.c | 82 ++----------------------------------------
> 3 files changed, 96 insertions(+), 91 deletions(-)

Here is the summary with links:
- [BlueZ,1/2] client: Move admin submenu
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=64abbf7cee18
- [BlueZ,2/2] build: Enable admin plugin
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=fdc788f576cf

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html