Hi,
On Thu, 2013-08-22 at 00:36 +0200, Peter Meerwald wrote:
> Add __connman_config_get_string(), __connman_config_get_string_list(),
> __connman_config_get_bool() which wrap corresponding GLib g_key_file_get_*()
> functions
The why part is important here. Please add the (short) reason for these
functions to the commit message.
> Signed-off-by: Peter Meerwald <[email protected]>
> Cc: Patrik Flykt <[email protected]>
> Cc: Daniel Wagner <[email protected]>
> ---
> src/config.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
> src/connman.h | 10 ++++++++++
> 2 files changed, 59 insertions(+)
>
> diff --git a/src/config.c b/src/config.c
> index 148c67d..61e69fb 100644
> --- a/src/config.c
> +++ b/src/config.c
> @@ -906,6 +906,55 @@ void __connman_config_cleanup(void)
> cleanup = false;
> }
>
> +/* trims trailing whitespace */
> +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;
> +}
> +
> +/* accept "true", "1" with trailing whitespace */
> +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 a9dc127..b8a4ae8 100644
> --- a/src/connman.h
> +++ b/src/connman.h
> @@ -586,6 +586,16 @@ 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);
> +
> +/* accept "true", "1" with trailing whitespace */
> +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);
If (/since!) the reason of introducing these functions is documented in
the commit message, the comments in the code are unnecessary (and
generally tend to float away/become obsolete when the code changes).
Patrik
_______________________________________________
connman mailing list
[email protected]
https://lists.connman.net/mailman/listinfo/connman