Open Source Telephony
 help / color / mirror / Atom feed
From: Denis Kenzior <denkenz@gmail.com>
To: ofono@lists.linux.dev
Cc: Denis Kenzior <denkenz@gmail.com>
Subject: [PATCH 05/17] storage: Introduce storage_get_file_path()
Date: Tue, 30 Jan 2024 15:21:10 -0600	[thread overview]
Message-ID: <20240130212137.814082-5-denkenz@gmail.com> (raw)
In-Reply-To: <20240130212137.814082-1-denkenz@gmail.com>

There are multiple locations where the same steps are followed to
produce a file path for a given storage location.  Pull this logic into
a single function and expose it for potential use by other modules.
While here, convert use of GLib functions to ell.
---
 src/storage.c | 36 +++++++++++++++++-------------------
 src/storage.h |  1 +
 2 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/src/storage.c b/src/storage.c
index 05d9b88a0237..c7bbb1c6142a 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -171,45 +171,43 @@ error_create_dirs:
 	return r;
 }
 
-GKeyFile *storage_open(const char *imsi, const char *store)
+char *storage_get_file_path(const char *imsi, const char *store)
 {
-	GKeyFile *keyfile;
-	char *path;
-
 	if (store == NULL)
 		return NULL;
 
 	if (imsi)
-		path = g_strdup_printf(STORAGEDIR "/%s/%s", imsi, store);
+		return l_strdup_printf(STORAGEDIR "/%s/%s", imsi, store);
 	else
-		path = g_strdup_printf(STORAGEDIR "/%s", store);
+		return l_strdup_printf(STORAGEDIR "/%s", store);
+}
 
-	keyfile = g_key_file_new();
+GKeyFile *storage_open(const char *imsi, const char *store)
+{
+	GKeyFile *keyfile;
+	char *path = storage_get_file_path(imsi, store);
 
-	if (path) {
-		g_key_file_load_from_file(keyfile, path, 0, NULL);
-		g_free(path);
-	}
+	if (!path)
+		return NULL;
+
+	keyfile = g_key_file_new();
+	g_key_file_load_from_file(keyfile, path, 0, NULL);
+	l_free(path);
 
 	return keyfile;
 }
 
 void storage_sync(const char *imsi, const char *store, GKeyFile *keyfile)
 {
-	char *path;
+	char *path = storage_get_file_path(imsi, store);
 	char *data;
 	gsize length = 0;
 
-	if (imsi)
-		path = g_strdup_printf(STORAGEDIR "/%s/%s", imsi, store);
-	else
-		path = g_strdup_printf(STORAGEDIR "/%s", store);
-
 	if (path == NULL)
 		return;
 
 	if (create_dirs(path, S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
-		g_free(path);
+		l_free(path);
 		return;
 	}
 
@@ -218,7 +216,7 @@ void storage_sync(const char *imsi, const char *store, GKeyFile *keyfile)
 	g_file_set_contents(path, data, length, NULL);
 
 	g_free(data);
-	g_free(path);
+	l_free(path);
 }
 
 void storage_close(const char *imsi, const char *store, GKeyFile *keyfile,
diff --git a/src/storage.h b/src/storage.h
index 4dc792ccf7f9..3a1e64493546 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -32,6 +32,7 @@ ssize_t write_file(const unsigned char *buffer, size_t len, mode_t mode,
 			const char *path_fmt, ...)
 	__attribute__((format(printf, 4, 5)));
 
+char *storage_get_file_path(const char *imsi, const char *store);
 GKeyFile *storage_open(const char *imsi, const char *store);
 void storage_sync(const char *imsi, const char *store, GKeyFile *keyfile);
 void storage_close(const char *imsi, const char *store, GKeyFile *keyfile,
-- 
2.43.0


  parent reply	other threads:[~2024-01-30 21:22 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-30 21:21 [PATCH 01/17] umlrunner: Also mount /var/lib as tmpfs Denis Kenzior
2024-01-30 21:21 ` [PATCH 02/17] build: Only enable backtrace(3) in maintainer mode Denis Kenzior
2024-01-30 21:21 ` [PATCH 03/17] build: Bring in more ell classes Denis Kenzior
2024-01-30 21:21 ` [PATCH 04/17] provisiondb: Remove some duplicate MCCMNC entries Denis Kenzior
2024-01-30 21:21 ` Denis Kenzior [this message]
2024-01-30 21:21 ` [PATCH 06/17] storage: Convert g_strdup_* use to l_strdup_* Denis Kenzior
2024-01-30 21:21 ` [PATCH 07/17] common: Drop GLib use from gprs_auth_proto_to_string Denis Kenzior
2024-01-30 21:21 ` [PATCH 08/17] common: Drop GLib use from gprs_proto_to_string Denis Kenzior
2024-01-30 21:21 ` [PATCH 09/17] storage: Remove mode parameter Denis Kenzior
2024-01-30 21:21 ` [PATCH 10/17] storage: Use l_malloc Denis Kenzior
2024-01-30 21:21 ` [PATCH 11/17] storage: Remove mode argument Denis Kenzior
2024-01-30 21:21 ` [PATCH 12/17] storage: Use void * instead of unsigned char * Denis Kenzior
2024-01-30 21:21 ` [PATCH 13/17] storage: use l_file_set_contents Denis Kenzior
2024-01-30 21:21 ` [PATCH 14/17] lte: Refactor lte settings management Denis Kenzior
2024-01-30 21:21 ` [PATCH 15/17] lte: Add provisioning support Denis Kenzior
2024-01-30 21:21 ` [PATCH 16/17] phonesim: Add lte atom Denis Kenzior
2024-01-30 21:21 ` [PATCH 17/17] lte: Write provisioned info to disk Denis Kenzior
2024-02-02 23:30 ` [PATCH 01/17] umlrunner: Also mount /var/lib as tmpfs patchwork-bot+ofono

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=20240130212137.814082-5-denkenz@gmail.com \
    --to=denkenz@gmail.com \
    --cc=ofono@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