add __connman_config_get_string(), __connman_config_get_string_list(),
__connman_config_get_bool() which wrap corresponding GLib g_key_file_get_*()
functions
GLib's functions trim leading, but not tailing whitespace
these function trim (*_string) or ignore (*_bool) trailing whitespace
of config values in order to mitigate hard to spot configuration errors
---
src/config.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
src/connman.h | 9 +++++++++
2 files changed, 56 insertions(+)
diff --git a/src/config.c b/src/config.c
index 148c67d..fee3ed1 100644
--- a/src/config.c
+++ b/src/config.c
@@ -906,6 +906,53 @@ void __connman_config_cleanup(void)
cleanup = false;
}
+char *__connman_config_get_string(GKeyFile *key_file,
+ const char *group_name, const char *key, GError **error)
+{
+ char *str = g_key_file_get_string(key_file, group_name, key, error);
+ if (!str)
+ return NULL;
+
+ return g_strchomp(str);
+}
+
+char **__connman_config_get_string_list(GKeyFile *key_file,
+ const char *group_name, const char *key, gsize *length, GError **error)
+{
+ char **p;
+ char **strlist = g_key_file_get_string_list(key_file, group_name, key,
+ length, error);
+ if (!strlist)
+ return NULL;
+
+ p = strlist;
+ while (*p) {
+ *p = g_strstrip(*p);
+ p++;
+ }
+
+ return strlist;
+}
+
+bool __connman_config_get_bool(GKeyFile *key_file,
+ const char *group_name, const char *key, GError **error)
+{
+ char *valstr;
+ bool val = false;
+
+ valstr = g_key_file_get_value(key_file, group_name, key, error);
+ if (!valstr)
+ return false;
+
+ valstr = g_strchomp(valstr);
+ if (strcmp(valstr, "true") == 0 || strcmp(valstr, "1") == 0)
+ val = true;
+
+ g_free(valstr);
+
+ return val;
+}
+
static char *config_pem_fsid(const char *pem_file)
{
struct statfs buf;
diff --git a/src/connman.h b/src/connman.h
index cd4d48d..38b59dd 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -586,6 +586,15 @@ int __connman_config_provision_service(struct
connman_service *service);
int __connman_config_provision_service_ident(struct connman_service *service,
const char *ident, const char *file, const char *entry);
+char *__connman_config_get_string(GKeyFile *key_file,
+ const char *group_name, const char *key, GError **error);
+
+char **__connman_config_get_string_list(GKeyFile *key_file,
+ const char *group_name, const char *key, gsize *length, GError **error);
+
+bool __connman_config_get_bool(GKeyFile *key_file,
+ const char *group_name, const char *key, GError **error);
+
int __connman_tethering_init(void);
void __connman_tethering_cleanup(void);
--
1.7.9.5
_______________________________________________
connman mailing list
[email protected]
https://lists.connman.net/mailman/listinfo/connman