Hi Jukka,

> We need the list of provisioned services so that
> all the hidden ones can be scanned.
> ---
>  Makefile.am         |    2 +-
>  include/provision.h |   51 ++++++++++++++++++++++++++++++++++++++
>  src/config.c        |   68 
> +++++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 120 insertions(+), 1 deletion(-)
>  create mode 100644 include/provision.h
> 
> diff --git a/Makefile.am b/Makefile.am
> index 9d713ae..ca0cf0b 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -7,7 +7,7 @@ include_HEADERS = include/types.h include/log.h 
> include/plugin.h \
>                       include/notifier.h include/service.h \
>                       include/resolver.h include/ipconfig.h \
>                       include/device.h include/network.h include/inet.h \
> -                     include/storage.h
> +                     include/storage.h include/provision.h
>  
>  nodist_include_HEADERS = include/version.h
>  
> diff --git a/include/provision.h b/include/provision.h
> new file mode 100644
> index 0000000..5573eb4
> --- /dev/null
> +++ b/include/provision.h
> @@ -0,0 +1,51 @@
> +/*
> + *
> + *  Connection Manager
> + *
> + *  Copyright (C) 2012  Intel Corporation. All rights reserved.
> + *
> + *  This program is free software; you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License version 2 as
> + *  published by the Free Software Foundation.
> + *
> + *  This program is distributed in the hope that it will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + *  GNU General Public License for more details.
> + *
> + *  You should have received a copy of the GNU General Public License
> + *  along with this program; if not, write to the Free Software
> + *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  
> USA
> + *
> + */
> +
> +#ifndef __CONNMAN_PROVISION_H
> +#define __CONNMAN_PROVISION_H
> +
> +#include <connman/types.h>
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +/**
> + * SECTION:provision
> + * @title: Provisioned configuration premitives
> + * @short_description: Functions for provision configuration handling
> + */
> +
> +struct connman_config_item {
> +     char *ident;
> +     char *name;
> +     void *ssid;
> +     unsigned int ssid_len;
> +     connman_bool_t hidden;
> +};
> +
> +struct connman_config_item **connman_config_get_configs(void);

this needs to follow with an easy way to free the configs. You are open
coding the free at least twice.

In addition I would call this connman_config_get_entries and the
structure connman_config_entry.

If you wanna keep the _item, the call it at least get_items.

> +
> +#ifdef __cplusplus
> +}
> +#endif
> +
> +#endif /* __CONNMAN_PROVISION_H */
> diff --git a/src/config.c b/src/config.c
> index 5363dc3..3b66a73 100644
> --- a/src/config.c
> +++ b/src/config.c
> @@ -31,6 +31,7 @@
>  #include <sys/inotify.h>
>  #include <glib.h>
>  
> +#include <connman/provision.h>
>  #include "connman.h"
>  
>  struct connman_config_service {
> @@ -51,6 +52,7 @@ struct connman_config_service {
>       GSList *service_identifiers;
>       char *config_ident; /* file prefix */
>       char *config_entry; /* entry name */
> +     connman_bool_t hidden;
>  };
>  
>  struct connman_config {
> @@ -938,3 +940,69 @@ int __connman_config_provision_service_ident(struct 
> connman_service *service,
>  
>       return ret;
>  }
> +
> +struct connman_config_item **connman_config_get_configs(void)
> +{
> +     GHashTableIter iter_file, iter_config;
> +     gpointer value, key;
> +     struct connman_config_item **configs = NULL;
> +     int i, count = 0;
> +
> +     g_hash_table_iter_init(&iter_file, config_table);
> +     while (g_hash_table_iter_next(&iter_file, &key, &value) == TRUE) {
> +             struct connman_config *config_file = value;
> +
> +             g_hash_table_iter_init(&iter_config,
> +                                             config_file->service_table);
> +             while (g_hash_table_iter_next(&iter_config, &key,
> +                                                     &value) == TRUE) {
> +                     struct connman_config_service *config = value;
> +                     configs = g_try_realloc(configs, (count + 1) *
> +                                     sizeof(struct connman_config_item *));
> +                     if (configs == NULL)
> +                             return NULL;

Why are we doing this? We know the size of hash table. So allocate this
ahead of time,

> +
> +                     configs[count] =
> +                             g_try_new0(struct connman_config_item, 1);
> +                     if (configs[count] == NULL)
> +                             goto cleanup;

And why this? Is not something simple like

        g_try_new0(struct connman_config_item, count)

sufficient?

> +
> +                     configs[count]->ident = g_strdup(config->ident);
> +                     configs[count]->name = g_strdup(config->name);
> +                     configs[count]->ssid = g_malloc0(config->ssid_len + 1);
> +                     if (configs[count]->ssid == NULL)
> +                             goto cleanup;

g_malloc0 is not going to fail, and don't bother zeroing the value if
you copy it fully anyway.

> +
> +                     memcpy(configs[count]->ssid, config->ssid,
> +                                                     config->ssid_len);
> +                     configs[count]->ssid_len = config->ssid_len;
> +                     configs[count]->hidden = config->hidden;
> +
> +                     count++;
> +             }
> +     }
> +
> +     if (configs != NULL) {
> +             configs = g_try_realloc(configs, (count + 1) *
> +                                     sizeof(struct connman_config_item *));
> +             if (configs == NULL)
> +                     return NULL;
> +
> +             configs[count] = NULL;
> +
> +             DBG("%d provisioned AP found", count);
> +     }
> +
> +     return configs;
> +
> +cleanup:
> +     for (i = 0; i < count && configs && configs[i]; i++) {
> +             g_free(configs[i]->ident);
> +             g_free(configs[i]->name);
> +             g_free(configs[i]->ssid);
> +             g_free(configs[i]);
> +     }
> +
> +     g_free(configs);
> +     return NULL;
> +}

Regards

Marcel


_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to