From: Daniel Wagner <wagi@monom.org>
To: Michael Trimarchi <michael@amarulasolutions.com>
Cc: connman@lists.linux.dev, Jan.Ryll@bshg.com, Simon.Holesch@bshg.com
Subject: Re: [PATCH] Add GetKnownServices api to connaman
Date: Tue, 26 Oct 2021 09:04:13 +0200 [thread overview]
Message-ID: <20211026070413.fv5bbuwpch3qelab@beryllium.lan> (raw)
In-Reply-To: <20211025132643.4485-1-michael@amarulasolutions.com>
Hi Michael,
On Mon, Oct 25, 2021 at 01:26:43PM +0000, Michael Trimarchi wrote:
> Add a way to retrieve all the networks that were configured
> using connman and not all the ones visible
>
> Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
We don't do the SoB in this project.
> +void __connman_known_service_list_struct(DBusMessageIter *iter)
> +{
> + gchar **services = NULL;
> + gchar **service_id_parts = NULL;
> + guint i = 0;
> + struct connman_service *service = NULL;
All pre-initialization are not needed.
> +
> + DBG("listing known services");
Please remove the DBG(). We have way to many these kind of tracing DBGs
in the code which fill the log pretty unnecessary.
> +
> + services = connman_storage_get_services();
> + if (services == NULL)
if (!service)
> + return;
> +
> + for (i = 0; i < g_strv_length(services); i++) {
> + service = connman_service_create();
> + if (service == NULL) {
if (!service)
> + connman_error("connman_service_create() allocation failed");
> + return;
> + }
> +
> + service->identifier = g_strdup(services[i]);
> + service_id_parts = g_strsplit(services[i], "_", -1);
> +
> + if (service_id_parts == NULL) {
> + g_free(service);
> + continue;
> + }
IIRC, this check will always be false, as g_strsplit() will return a
valid array or call abort() if allocation fails.
> +
> + service->type = __connman_service_string2type(service_id_parts[0]);
> + service->path = g_strdup_printf("%s/service/%s", CONNMAN_PATH, service->identifier);
Do we really have to do this kind of path/identifier string generation
here. Prefixing the path I understand but for the rest I thought we had
do this in config.c/storage.c.
> + if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
> + service->security = __connman_service_string2security(service_id_parts[g_strv_length(service_id_parts) - 1]);
> +
This looks a bit wierd formatted. Maybe introduce a local variable for
the (...) bit and get it correctly indented.
> + if (service->path == NULL) {
> + g_strfreev(service_id_parts);
> + continue;
> + }
Same here, g_strdup_printf() will either succeed or call abort() in the
ENOMEM case.
> +
> + if (find_service(service->path) != NULL)
Just do a
if (find_service())
> + service->state = (find_service(service->path))->state;
> +
> + if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET &&
> + find_service(service->path) != NULL)
same here
> + service->name = (find_service(service->path))->name;
> +
> + if (0 != service_load(service)) {
Please the other way around, we don't do Misra or whatever standard this
recommends.
> + connman_error("service_load() returned error");
> + g_free(service);
> + g_strfreev(service_id_parts);
> + g_strfreev(services);
> + return;
> + }
> +
> + append_struct_service(iter, append_dict_properties, service);
> + g_strfreev(service_id_parts);
> + g_free(service);
> + }
> +
> + g_strfreev(services);
> +}
> +
> void __connman_service_list_struct(DBusMessageIter *iter)
> {
> g_list_foreach(service_list, append_struct, iter);
> diff --git a/tools/manager-api.c b/tools/manager-api.c
> index e082962d..99035988 100644
> --- a/tools/manager-api.c
> +++ b/tools/manager-api.c
> @@ -64,6 +64,39 @@ 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");
> + }
Drop these LOG() entries.
> + dbus_message_unref(message);
> + return NULL;
> + }
> +
> + dbus_message_unref(message);
> +
> + return reply;
> +}
> +
Please also update the documentation.
Thanks,
Daniel
next prev parent reply other threads:[~2021-10-26 7:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-25 13:26 [PATCH] Add GetKnownServices api to connaman Michael Trimarchi
2021-10-26 7:04 ` Daniel Wagner [this message]
2021-10-26 7:09 ` Michael Nazzareno Trimarchi
2021-10-26 7:37 ` Daniel Wagner
2021-10-26 7:42 ` Michael Nazzareno Trimarchi
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=20211026070413.fv5bbuwpch3qelab@beryllium.lan \
--to=wagi@monom.org \
--cc=Jan.Ryll@bshg.com \
--cc=Simon.Holesch@bshg.com \
--cc=connman@lists.linux.dev \
--cc=michael@amarulasolutions.com \
/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;
as well as URLs for NNTP newsgroup(s).