Skip to content

Commit

Permalink
Merge pull request #9 from amccarthy/master
Browse files Browse the repository at this point in the history
[connman] Add method to remove saved services when not in range.
  • Loading branch information
stskeeps committed Oct 30, 2013
2 parents d215119 + d46d1c7 commit 842f4ec
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions connman/include/service.h
Expand Up @@ -89,6 +89,7 @@ struct connman_service;
struct connman_network;

struct connman_service *connman_service_create(void);
int connman_service_remove(const char *identifier);

#define connman_service_ref(service) \
connman_service_ref_debug(service, __FILE__, __LINE__, __func__)
Expand Down
17 changes: 17 additions & 0 deletions connman/src/manager.c
Expand Up @@ -240,6 +240,20 @@ static DBusMessage *get_saved_services(DBusConnection *conn,
return reply;
}

static DBusMessage *remove_saved_service(DBusConnection *conn, DBusMessage *msg, void *data)
{
gchar *identifier;
int i;
struct connman_service *service;

dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &identifier, DBUS_TYPE_INVALID);

if (connman_service_remove(identifier) != TRUE)
return __connman_error_failed(msg, EINVAL);

return dbus_message_new_method_return(msg);
}

static DBusMessage *connect_provider(DBusConnection *conn,
DBusMessage *msg, void *data)
{
Expand Down Expand Up @@ -432,6 +446,9 @@ static const GDBusMethodTable manager_methods[] = {
{ GDBUS_METHOD("GetSavedServices",
NULL, GDBUS_ARGS({ "services", "a(oa{sv})" }),
get_saved_services) },
{ GDBUS_METHOD("RemoveSavedService",
GDBUS_ARGS({ "identifier", "s" }), NULL,
remove_saved_service) },
{ GDBUS_DEPRECATED_ASYNC_METHOD("ConnectProvider",
GDBUS_ARGS({ "provider", "a{sv}" }),
GDBUS_ARGS({ "path", "o" }),
Expand Down
57 changes: 57 additions & 0 deletions connman/src/service.c
Expand Up @@ -2391,6 +2391,63 @@ void __connman_saved_service_list_struct(DBusMessageIter *iter)
__connman_saved_service_list_struct_fn(iter, &append_dict_properties);
}

int connman_service_remove(const char *identifier)
{
gchar **services = connman_storage_get_services();
if (services == NULL)
return FALSE;

int i;
for (i = 0; services[i] != NULL; ++i) {
if (g_strcmp0(services[i], identifier) != 0)
continue;

GSequenceIter *iter = g_hash_table_lookup(service_hash, identifier);
if (iter != NULL) {
struct connman_service *service = g_sequence_get(iter);
if (service != NULL) {
__connman_service_remove(service);
return TRUE;
}
}

struct connman_service *service = connman_service_create();
if (service == NULL)
return FALSE;

service->identifier = g_strdup(services[i]);
service->path = g_strdup_printf("%s/service/%s", CONNMAN_PATH, service->identifier);
service->type = __connman_service_string2type(service->identifier);

int result = service_load(service);

g_free(service->passphrase);
service->passphrase = NULL;

g_free(service->agent_passphrase);
service->agent_passphrase = NULL;

g_free(service->identity);
service->identity = NULL;

g_free(service->agent_identity);
service->agent_identity = NULL;

g_free(service->eap);
service->eap = NULL;

service->favorite = FALSE;

result = service_save(service);

connman_service_unref(service);

return TRUE;
}

return FALSE;
}

connman_bool_t __connman_service_is_hidden(struct connman_service *service)
{
return service->hidden;
Expand Down

0 comments on commit 842f4ec

Please sign in to comment.