Wireless Daemon for Linux
 help / color / mirror / Atom feed
* [PATCH 1/5] storage: add storage_network_filename_from_path
@ 2020-10-30 16:34 James Prestwood
  2020-10-30 16:34 ` [PATCH 2/5] storage: add storage_get_ap_path James Prestwood
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: James Prestwood @ 2020-10-30 16:34 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 2833 bytes --]

This is to allow this API to be used simply to get the file name
without extension. AP will be storing provisioning files similarly
to the network format but the extension will not map to existing
security types. Some of the parsing code from
storage_network_ssid_from_path was reused for parsing the file name
and verification.
---
 src/storage.c | 40 ++++++++++++++++++++++++++++++++++------
 src/storage.h |  1 +
 2 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/src/storage.c b/src/storage.c
index 00d93933..60fb1bc3 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -287,13 +287,12 @@ char *storage_get_network_file_path(enum security type, const char *ssid)
 	return path;
 }
 
-const char *storage_network_ssid_from_path(const char *path,
-							enum security *type)
+static bool parse_file_path(const char *path, char *buf,
+				const char **ext_offset)
 {
 	const char *filename = strrchr(path, '/');
 	const char *c, *end;
 	char *decoded;
-	static char buf[67];
 
 	if (filename)
 		filename++;	/* Skip the / */
@@ -302,8 +301,8 @@ const char *storage_network_ssid_from_path(const char *path,
 
 	end = strchr(filename, '.');
 
-	if (!end || !security_from_str(end + 1, type))
-		return NULL;
+	if (!end)
+		return false;
 
 	if (filename[0] != '=') {
 		if (end == filename || end - filename > 32)
@@ -319,7 +318,7 @@ const char *storage_network_ssid_from_path(const char *path,
 		memcpy(buf, filename, end - filename);
 		buf[end - filename] = '\0';
 
-		return buf;
+		goto done;
 	}
 
 	if (end - filename <= 1 || end - filename > 65)
@@ -342,6 +341,35 @@ const char *storage_network_ssid_from_path(const char *path,
 	strcpy(buf, decoded);
 	l_free(decoded);
 
+done:
+	if (ext_offset)
+		*ext_offset = end;
+
+	return true;
+}
+
+const char *storage_network_filename_from_path(const char *path)
+{
+	static char buf[67];
+
+	if (!parse_file_path(path, buf, NULL))
+		return NULL;
+
+	return buf;
+}
+
+const char *storage_network_ssid_from_path(const char *path,
+							enum security *type)
+{
+	const char *end;
+	static char buf[67];
+
+	if (!parse_file_path(path, buf, &end))
+		return NULL;
+
+	if (!security_from_str(end + 1, type))
+		return NULL;
+
 	return buf;
 }
 
diff --git a/src/storage.h b/src/storage.h
index 80b63c53..d9b17c7f 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -37,6 +37,7 @@ void storage_cleanup_dirs(void);
 char *storage_get_path(const char *format, ...);
 char *storage_get_hotspot_path(const char *format, ...);
 
+const char *storage_network_filename_from_path(const char *path);
 const char *storage_network_ssid_from_path(const char *path,
 							enum security *type);
 char *storage_get_network_file_path(enum security type, const char *ssid);
-- 
2.26.2

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

end of thread, other threads:[~2020-10-30 18:48 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-30 16:34 [PATCH 1/5] storage: add storage_network_filename_from_path James Prestwood
2020-10-30 16:34 ` [PATCH 2/5] storage: add storage_get_ap_path James Prestwood
2020-10-30 18:41   ` Denis Kenzior
2020-10-30 18:48     ` James Prestwood
2020-10-30 16:34 ` [PATCH 3/5] ap: add provisioning file parsing James Prestwood
2020-10-30 16:34 ` [PATCH 4/5] ap: add StartWithConfig DBus method James Prestwood
2020-10-30 18:37   ` Denis Kenzior
2020-10-30 18:42     ` James Prestwood
2020-10-30 16:34 ` [PATCH 5/5] ap: allow DHCP settings in provisioning files James Prestwood

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox