ConnMan network manager
 help / color / mirror / Atom feed
From: Grant Erickson <gerickson@nuovations.com>
To: connman@lists.linux.dev
Subject: [PATCH] Const-qualify 'service' arguments in name and time server  getters.
Date: Thu, 2 Nov 2023 10:03:28 -0700	[thread overview]
Message-ID: <70D6ACF5-703E-48D2-841A-24E63F889D9E@nuovations.com> (raw)

Const-qualify the 'service' arguments in name and time server getter
functions to make it clear to the compiler, static analyzers,
and human readers that there are no mutation side effects with
such arguments and that the returned results are immutable and must
be copied if mutation is desired.
---
 include/service.h |  6 +++---
 src/connman.h     |  2 +-
 src/service.c     | 10 +++++-----
 src/timeserver.c  | 14 +++++++-------
 4 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/include/service.h b/include/service.h
index e3cf3d36..e45d7b58 100644
--- a/include/service.h
+++ b/include/service.h
@@ -121,9 +121,9 @@ char *connman_service_get_interface(struct connman_service *service);
 const char *connman_service_get_identifier(const struct connman_service *service);
 const char *connman_service_get_domainname(const struct connman_service *service);
 const char *connman_service_get_dbuspath(const struct connman_service *service);
-char **connman_service_get_nameservers(struct connman_service *service);
-char **connman_service_get_timeservers_config(struct connman_service *service);
-char **connman_service_get_timeservers(struct connman_service *service);
+char **connman_service_get_nameservers(const struct connman_service *service);
+const char * const *connman_service_get_timeservers_config(const struct connman_service *service);
+const char * const *connman_service_get_timeservers(const struct connman_service *service);
 void connman_service_set_proxy_method(struct connman_service *service, enum connman_service_proxy_method method);
 enum connman_service_proxy_method connman_service_get_proxy_method(const struct connman_service *service);
 char **connman_service_get_proxy_servers(struct connman_service *service);
diff --git a/src/connman.h b/src/connman.h
index 74aa3453..0c2d27b5 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -450,7 +450,7 @@ char **__connman_timeserver_system_get();
 
 GSList *__connman_timeserver_add_list(GSList *server_list,
 		const char *timeserver);
-GSList *__connman_timeserver_get_all(struct connman_service *service);
+GSList *__connman_timeserver_get_all(const struct connman_service *service);
 void __connman_timeserver_sync(struct connman_service *service,
 				enum connman_timeserver_sync_reason reason);
 void __connman_timeserver_conf_update(struct connman_service *service);
diff --git a/src/service.c b/src/service.c
index c410ff4b..ea36f852 100644
--- a/src/service.c
+++ b/src/service.c
@@ -2818,7 +2818,7 @@ const char *connman_service_get_dbuspath(const struct connman_service *service)
 	return service->path;
 }
 
-char **connman_service_get_nameservers(struct connman_service *service)
+char **connman_service_get_nameservers(const struct connman_service *service)
 {
 	if (!service)
 		return NULL;
@@ -2852,20 +2852,20 @@ char **connman_service_get_nameservers(struct connman_service *service)
 	return g_strdupv(connman_setting_get_string_list("FallbackNameservers"));
 }
 
-char **connman_service_get_timeservers_config(struct connman_service *service)
+const char * const *connman_service_get_timeservers_config(const struct connman_service *service)
 {
 	if (!service)
 		return NULL;
 
-	return service->timeservers_config;
+	return (const char * const *)service->timeservers_config;
 }
 
-char **connman_service_get_timeservers(struct connman_service *service)
+const char * const *connman_service_get_timeservers(const struct connman_service *service)
 {
 	if (!service)
 		return NULL;
 
-	return service->timeservers;
+	return (const char * const *)service->timeservers;
 }
 
 void connman_service_set_proxy_method(struct connman_service *service,
diff --git a/src/timeserver.c b/src/timeserver.c
index 9c0d7aa5..3eb718aa 100644
--- a/src/timeserver.c
+++ b/src/timeserver.c
@@ -52,7 +52,7 @@ static GResolv *resolv = NULL;
 static int resolv_id = 0;
 
 static void sync_next(void);
-static void ts_set_nameservers(struct connman_service *service);
+static void ts_set_nameservers(const struct connman_service *service);
 
 static void resolv_debug(const char *str, void *data)
 {
@@ -234,13 +234,13 @@ GSList *__connman_timeserver_add_list(GSList *server_list,
  * list which will be used to determine NTP server for time corrections.
  * The service settings take priority over the global timeservers.
  */
-GSList *__connman_timeserver_get_all(struct connman_service *service)
+GSList *__connman_timeserver_get_all(const struct connman_service *service)
 {
 	GSList *list = NULL;
-	struct connman_network *network;
+	const struct connman_network *network;
 	char **timeservers;
-	char **service_ts;
-	char **service_ts_config;
+	const char * const *service_ts;
+	const char * const *service_ts_config;
 	const char *service_gw;
 	char **fallback_ts;
 	int index, i;
@@ -267,7 +267,7 @@ GSList *__connman_timeserver_get_all(struct connman_service *service)
 	 * configuration option is set to true.
 	 */
 	if (connman_setting_get_bool("UseGatewaysAsTimeservers")) {
-		network = __connman_service_get_network(service);
+		network = __connman_service_get_network((struct connman_service *)service);
 		if (network) {
 			index = connman_network_get_index(network);
 			service_gw = __connman_ipconfig_get_gateway_from_index(index,
@@ -379,7 +379,7 @@ static int ts_setup_resolv(struct connman_service *service)
 }
 
 
-static void ts_set_nameservers(struct connman_service *service)
+static void ts_set_nameservers(const struct connman_service *service)
 {
 	char **nameservers;
 	int i;
-- 
2.42.0



             reply	other threads:[~2023-11-02 17:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-02 17:03 Grant Erickson [this message]
2023-11-07 15:58 ` [PATCH] Const-qualify 'service' arguments in name and time server getters Marcel Holtmann
2023-11-07 19:38   ` Grant Erickson
2023-11-07 19:38 ` [PATCH v2] " Grant Erickson
2023-11-08 14:35   ` Marcel Holtmann

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=70D6ACF5-703E-48D2-841A-24E63F889D9E@nuovations.com \
    --to=gerickson@nuovations.com \
    --cc=connman@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).