connman.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/1] Add support to get or remove known services via
@ 2023-06-01 14:11 Dembianny, Sven (GDE-EDSO)
  2023-06-01 14:11 ` [PATCH 1/1] Add connman get and remove known services methods Dembianny, Sven (GDE-EDSO)
  2023-06-01 14:36 ` [PATCH 0/1] Add support to get or remove known services via Michael Nazzareno Trimarchi
  0 siblings, 2 replies; 3+ messages in thread
From: Dembianny, Sven (GDE-EDSO) @ 2023-06-01 14:11 UTC (permalink / raw)
  To: wagi, connman; +Cc: Ryll, Jan (GDE-EDS9), Dembianny, Sven (GDE-EDSO)

Hi Daniel,

picked up a patch from Jan Ryll that was already provided to connman
mailing list 2020-05-27 and tried to insert all your remarks.

Unfortunately I can't find the mailing list entry to keep the old thread
alive.

This patch (without adaptions for your remarks) is now running in production
for years without issues.

Best regards, Sven

Dembianny, Sven (GED-EDSO) (1):
  Add connman get and remove known services methods

 client/commands.c   | 51 ++++++++++++++++++++++++++++++++
 doc/manager-api.txt |  9 ++++++
 src/connman.h       |  2 ++
 src/manager.c       | 56 +++++++++++++++++++++++++++++++++++
 src/service.c       | 70 ++++++++++++++++++++++++++++++++++++++++++++
 tools/manager-api.c | 71 +++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 259 insertions(+)

-- 
2.25.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/1] Add connman get and remove known services methods
  2023-06-01 14:11 [PATCH 0/1] Add support to get or remove known services via Dembianny, Sven (GDE-EDSO)
@ 2023-06-01 14:11 ` Dembianny, Sven (GDE-EDSO)
  2023-06-01 14:36 ` [PATCH 0/1] Add support to get or remove known services via Michael Nazzareno Trimarchi
  1 sibling, 0 replies; 3+ messages in thread
From: Dembianny, Sven (GDE-EDSO) @ 2023-06-01 14:11 UTC (permalink / raw)
  To: wagi, connman; +Cc: Ryll, Jan (GDE-EDS9), Dembianny, Sven (GDE-EDSO)

---
 client/commands.c   | 51 ++++++++++++++++++++++++++++++++
 doc/manager-api.txt |  9 ++++++
 src/connman.h       |  2 ++
 src/manager.c       | 56 +++++++++++++++++++++++++++++++++++
 src/service.c       | 70 ++++++++++++++++++++++++++++++++++++++++++++
 tools/manager-api.c | 71 +++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 259 insertions(+)

diff --git a/client/commands.c b/client/commands.c
index 53cc14c8..4b1212ca 100644
--- a/client/commands.c
+++ b/client/commands.c
@@ -420,6 +420,53 @@ static int cmd_services(char *args[], int num, struct connman_option *options)
 			object_properties, path, NULL, NULL);
 }
 
+static int cmd_known_services(char *args[], int num, struct connman_option *options)
+{
+	if (num > 1)
+		return -E2BIG;
+
+	return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE, CONNMAN_PATH,
+					"net.connman.Manager", "GetKnownServices",
+					services_list, NULL, NULL, NULL);
+}
+
+static int remove_known_service_return(DBusMessageIter *iter, const char *error,
+		void *user_data)
+{
+	char *path = user_data;
+
+	if (!error) {
+		char *str = strrchr(path, '/');
+		str++;
+		fprintf(stdout, "Removed %s\n", str);
+	} else
+		fprintf(stderr, "Error %s: %s\n", path, error);
+
+	g_free(user_data);
+
+	return 0;
+}
+
+static int cmd_remove_known_service(char *args[], int num, struct connman_option *options)
+{
+	char *path_of_service_to_remove;
+
+	if (num > 2)
+		return -E2BIG;
+
+	if (num < 2)
+		return -EINVAL;
+
+	if (check_dbus_name(args[1]) == false)
+		return -EINVAL;
+
+	path_of_service_to_remove = g_strdup_printf("%s", args[1]);
+
+	return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
+			CONNMAN_PATH, "net.connman.Manager", "RemoveKnownService",
+			remove_known_service_return, path_of_service_to_remove, NULL, NULL);
+}
+
 static int cmd_peers(char *args[], int num, struct connman_option *options)
 {
 	char *peer_name = NULL;
@@ -2808,6 +2855,10 @@ static const struct {
 	  "Display tethering clients", NULL },
 	{ "services",     "[<service>]",  service_options, cmd_services,
 	  "Display services", lookup_service_arg },
+	{ "known-services", NULL,         NULL,            cmd_known_services,
+	  "Display known services", NULL },
+	{ "remove-known-service", "<service>", NULL,       cmd_remove_known_service,
+	 "Remove known service", NULL },
 	{ "peers",        "[peer]",       NULL,            cmd_peers,
 	  "Display peers", lookup_peer_arg },
 	{ "scan",         "<technology>", NULL,            cmd_scan,
diff --git a/doc/manager-api.txt b/doc/manager-api.txt
index 6eaa0a38..9cc3fb17 100644
--- a/doc/manager-api.txt
+++ b/doc/manager-api.txt
@@ -80,6 +80,15 @@ Methods		dict GetProperties()
 
 			Remove a VPN specified by the object path.
 
+		array{object,dict} GetKnownServices()
+
+			Returns a sorted list of tuples with known service
+			object path and dictionary of service properties.
+
+		void RemoveKnownService(object path)
+
+			Remove a Known Service specified by the object path.
+
 		void RegisterAgent(object path)
 
 			Register new agent for handling user requests.
diff --git a/src/connman.h b/src/connman.h
index b955d98b..1ac6b5db 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -686,6 +686,7 @@ int __connman_service_move(struct connman_service *service,
 				struct connman_service *target, bool before);
 int __connman_service_load_modifiable(struct connman_service *service);
 
+void __connman_known_service_list_struct(DBusMessageIter *iter);
 void __connman_service_list_struct(DBusMessageIter *iter);
 
 int __connman_service_compare(const struct connman_service *a,
@@ -755,6 +756,7 @@ int __connman_service_disconnect(struct connman_service *service);
 void __connman_service_set_active_session(bool enable, GSList *list);
 void __connman_service_auto_connect(enum connman_service_connect_reason reason);
 bool __connman_service_remove(struct connman_service *service);
+bool __connman_service_remove_known_service(const char *path);
 bool __connman_service_is_provider_pending(struct connman_service *service);
 void __connman_service_set_provider_pending(struct connman_service *service,
 							DBusMessage *msg);
diff --git a/src/manager.c b/src/manager.c
index 892d3a42..ca4a01b5 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -175,6 +175,11 @@ static const struct connman_notifier technology_notifier = {
 	.idle_state	= idle_state,
 };
 
+static void append_known_service_structs(DBusMessageIter *iter, void *user_data)
+{
+	__connman_known_service_list_struct(iter);
+}
+
 static void append_service_structs(DBusMessageIter *iter, void *user_data)
 {
 	__connman_service_list_struct(iter);
@@ -195,6 +200,51 @@ static DBusMessage *get_services(DBusConnection *conn,
 	return reply;
 }
 
+static DBusMessage *get_known_services(DBusConnection *conn,
+				   DBusMessage *msg, void *data)
+{
+	DBusMessage *reply;
+
+	reply = dbus_message_new_method_return(msg);
+	if (!reply)
+		return NULL;
+
+	__connman_dbus_append_objpath_dict_array(reply,
+				 append_known_service_structs, NULL);
+
+	return reply;
+}
+
+static DBusMessage *remove_known_service(DBusConnection *conn,
+				   DBusMessage *msg, void *data)
+{
+	DBusMessage *reply;
+	const char *path;
+	int err;
+	char *str = strrchr(path, '/');
+
+	reply = dbus_message_new_method_return(msg);
+	if (!reply)
+		return NULL;
+
+	dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+							DBUS_TYPE_INVALID);
+
+	if(!str)
+		return __connman_error_failed(msg, -ENOENT);
+
+	str++;
+	if(!strlen(str) > 0)
+		return __connman_error_failed(msg, -ENOENT);
+
+	DBG("Service to remove [%s]", str);
+
+	if (!__connman_service_remove_known_service(str))
+		return __connman_error_failed(msg, -ENOENT);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
 static void append_peer_structs(DBusMessageIter *iter, void *user_data)
 {
 	__connman_peer_list_struct(iter);
@@ -534,6 +584,12 @@ static const GDBusMethodTable manager_methods[] = {
 	{ GDBUS_DEPRECATED_METHOD("RemoveProvider",
 			GDBUS_ARGS({ "provider", "o" }), NULL,
 			remove_provider) },
+	{ GDBUS_METHOD("GetKnownServices",
+			NULL, GDBUS_ARGS({"knownServices", "a(oa{sv})" }),
+			get_known_services) },
+	{ GDBUS_METHOD("RemoveKnownService",
+			GDBUS_ARGS({ "path", "o" }), NULL,
+			remove_known_service) },
 	{ GDBUS_METHOD("GetServices",
 			NULL, GDBUS_ARGS({ "services", "a(oa{sv})" }),
 			get_services) },
diff --git a/src/service.c b/src/service.c
index 06d02322..5ca7c307 100644
--- a/src/service.c
+++ b/src/service.c
@@ -2712,6 +2712,71 @@ static void append_struct(gpointer value, gpointer user_data)
 	append_struct_service(iter, append_dict_properties, service);
 }
 
+void __connman_known_service_list_struct(DBusMessageIter *iter)
+{
+	struct connman_service *service = NULL;
+	gchar **services = NULL;
+	gchar **serviceid_parts = NULL;
+	int i = 0;
+
+	DBG("");
+
+	services = connman_storage_get_services();
+	if (!services)
+		return;
+
+	for (i = 0; i < g_strv_length(services); i++) {
+		service = connman_service_create();
+
+		if (!service) {
+			connman_error("connman_service_create() allocation failed");
+			return ;
+		}
+
+		service->identifier = g_strdup(services[i]);
+		serviceid_parts = g_strsplit(services[i], "_", -1);
+
+		if (!serviceid_parts) {
+			g_free(service);
+			g_strfreev(services);
+			return
+		}
+
+		service->type = __connman_service_string2type(serviceid_parts[0]);
+		service->path =
+			g_strdup_printf("%s/service/%s", CONNMAN_PATH, service->identifier);
+
+		if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
+			service->security =
+				__connman_service_string2security(serviceid_parts[g_strv_length(serviceid_parts) - 1]);
+
+		if (service->path) {
+			if (find_service(service->path))
+				service->state = (find_service(service->path))->state;
+
+			if (service->type ==
+					CONNMAN_SERVICE_TYPE_ETHERNET &&
+				find_service(service->path))
+
+				service->name = (find_service(service->path))->name;
+
+			if (0 != service_load(service)) {
+				connman_error("service_load() returned error");
+				g_free(service);
+				g_strfreev(serviceid_parts);
+				g_strfreev(services);
+				return;
+			}
+
+			append_struct_service(iter, append_dict_properties, service);
+		}
+
+		g_strfreev(serviceid_parts);
+	}
+
+	g_strfreev(services);
+}
+
 void __connman_service_list_struct(DBusMessageIter *iter)
 {
 	g_list_foreach(service_list, append_struct, iter);
@@ -4686,6 +4751,11 @@ bool __connman_service_remove(struct connman_service *service)
 	return true;
 }
 
+bool __connman_service_remove_known_service(const char *path)
+{
+	return __connman_storage_remove_service(path);
+}
+
 static DBusMessage *remove_service(DBusConnection *conn,
 					DBusMessage *msg, void *user_data)
 {
diff --git a/tools/manager-api.c b/tools/manager-api.c
index e082962d..c62168bd 100644
--- a/tools/manager-api.c
+++ b/tools/manager-api.c
@@ -64,6 +64,77 @@ static DBusMessage *set_property(DBusConnection *connection,
 	return reply;
 }
 
+DBusMessage *manager_get_known_services(DBusConnection *connection)
+{
+	DBusMessage *message, *reply;
+	DBusError error;
+
+	message = dbus_message_new_method_call(CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
+						CONNMAN_MANAGER_INTERFACE, "GetKnownServices");
+
+	if (!message)
+		return NULL;
+
+	dbus_error_init(&error);
+
+	reply = dbus_connection_send_with_reply_and_block(connection,
+				  message, -1, &error);
+	if (!reply) {
+		if (dbus_error_is_set(&error)) {
+			LOG("%s", error.message);
+			dbus_error_free(&error);
+		}
+		else
+			LOG("Failed to get known services");
+
+		dbus_message_unref(message);
+		return NULL;
+	}
+
+	dbus_message_unref(message);
+
+	return reply;
+}
+
+DBusMessage *manager_remove_known_service(DBusConnection *connection,
+								const char *service_path)
+{
+	DBusMessage *message, *reply;
+	DBusError error;
+	DBusMessageIter array;
+
+	DBG("Service path to remove [%s]", service_path);
+
+	message = dbus_message_new_method_call(CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
+						CONNMAN_MANAGER_INTERFACE, "RemoveKnownService");
+
+	if (!message)
+		return NULL;
+
+	dbus_error_init(&error);
+	dbus_message_iter_init_append(message, &array);
+	dbus_message_iter_append_basic(&array, DBUS_TYPE_OBJECT_PATH,
+				&service_path);
+	reply = dbus_connection_send_with_reply_and_block(connection,
+				  message, -1, &error);
+
+	if (!reply) {
+		if (dbus_error_is_set(&error)) {
+			LOG("%s", error.message);
+			dbus_error_free(&error);
+		}
+		else
+			LOG("Failed to get known services");
+
+		dbus_message_unref(message);
+		return NULL;
+	}
+
+	dbus_message_unref(message);
+
+	return reply;
+}
+
 DBusMessage *manager_get_services(DBusConnection *connection)
 {
 	DBusMessage *message, *reply;
-- 
2.25.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 0/1] Add support to get or remove known services via
  2023-06-01 14:11 [PATCH 0/1] Add support to get or remove known services via Dembianny, Sven (GDE-EDSO)
  2023-06-01 14:11 ` [PATCH 1/1] Add connman get and remove known services methods Dembianny, Sven (GDE-EDSO)
@ 2023-06-01 14:36 ` Michael Nazzareno Trimarchi
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Nazzareno Trimarchi @ 2023-06-01 14:36 UTC (permalink / raw)
  To: Dembianny, Sven (GDE-EDSO); +Cc: wagi, connman, Ryll, Jan (GDE-EDS9)

Hi Sven

On Thu, Jun 1, 2023 at 4:12 PM Dembianny, Sven (GDE-EDSO)
<Sven.Dembianny@bshg.com> wrote:
>
> Hi Daniel,
>
> picked up a patch from Jan Ryll that was already provided to connman
> mailing list 2020-05-27 and tried to insert all your remarks.
>
> Unfortunately I can't find the mailing list entry to keep the old thread
> alive.
>
> This patch (without adaptions for your remarks) is now running in production
> for years without issues.
>
> Best regards, Sven
>
> Dembianny, Sven (GED-EDSO) (1):
>   Add connman get and remove known services methods
>
>  client/commands.c   | 51 ++++++++++++++++++++++++++++++++
>  doc/manager-api.txt |  9 ++++++
>  src/connman.h       |  2 ++
>  src/manager.c       | 56 +++++++++++++++++++++++++++++++++++
>  src/service.c       | 70 ++++++++++++++++++++++++++++++++++++++++++++
>  tools/manager-api.c | 71 +++++++++++++++++++++++++++++++++++++++++++++
>  6 files changed, 259 insertions(+)
>
> --

I think I sent it some months ago too.

Michael

> 2.25.1
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-06-01 14:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-01 14:11 [PATCH 0/1] Add support to get or remove known services via Dembianny, Sven (GDE-EDSO)
2023-06-01 14:11 ` [PATCH 1/1] Add connman get and remove known services methods Dembianny, Sven (GDE-EDSO)
2023-06-01 14:36 ` [PATCH 0/1] Add support to get or remove known services via Michael Nazzareno Trimarchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).