summaryrefslogtreecommitdiffstats
path: root/network/manager.c
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2007-05-18 18:05:16 +0000
committerLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2007-05-18 18:05:16 +0000
commit00a7a482ac18b339a311c0afb89741d6b3978f0e (patch)
treea895be4c4da3b031572db4a2c76c96b783cf8acf /network/manager.c
parente11b4cced0f967a66ea81e3b6b92448e55d49624 (diff)
Revert changes of missing GSList functions.
Diffstat (limited to 'network/manager.c')
-rw-r--r--network/manager.c83
1 files changed, 22 insertions, 61 deletions
diff --git a/network/manager.c b/network/manager.c
index 81133b2e..c27d01c5 100644
--- a/network/manager.c
+++ b/network/manager.c
@@ -146,22 +146,15 @@ static const char * last_connection_used(DBusConnection *conn)
GSList *l;
int i;
- l = connection_paths;
for (i = g_slist_length (connection_paths) -1; i > -1; i--) {
- int n = i;
- while (n-- > 0 && l)
- l = l->next;
-
- path = l ? l->data : NULL;
- if (connection_is_connected (conn, path))
+ path = g_slist_nth_data (connection_paths, i);
+ if (connection_is_connected(conn, path))
break;
}
/* No connection connected fallback to last connection */
if (i == -1) {
- l = connection_paths;
- while (l->next)
- l = l->next;
+ l = g_slist_last(connection_paths);
path = l->data;
}
@@ -192,20 +185,12 @@ static DBusHandlerResult remove_path(DBusConnection *conn,
/* Remove references from the storage */
if (*list == connection_paths) {
- GSList *l_default;
- int n;
-
if (connection_has_pending(conn, path))
return err_failed(conn, msg, "Connection is Busy");
connection_remove_stored(conn, path);
-
/* Reset default connection */
- n = default_index;
- l_default = connection_paths;
- while (n-- > 0 && l_default)
- l_default = l_default->next;
- if (l == l_default) {
+ if (l == g_slist_nth(*list, default_index)) {
const char *dpath;
dpath = last_connection_used(conn);
@@ -677,8 +662,6 @@ static DBusHandlerResult default_connection(DBusConnection *conn,
{
const char *path;
DBusMessage *reply;
- GSList *link;
- int n;
if (connection_paths == NULL ||
g_slist_length (connection_paths) == 0) {
@@ -686,12 +669,7 @@ static DBusHandlerResult default_connection(DBusConnection *conn,
return DBUS_HANDLER_RESULT_HANDLED;
}
- link = connection_paths;
- n = default_index;
- while (n-- > 0 && link)
- link = link->next;
-
- path = link ? link->data : NULL;
+ path = g_slist_nth_data (connection_paths, default_index);
if (path == NULL) {
path = last_connection_used(conn);
@@ -708,22 +686,6 @@ static DBusHandlerResult default_connection(DBusConnection *conn,
return send_message_and_unref(conn, reply);
}
-static void default_position(GSList *link)
-{
- GSList *list;
- int i = 0;
-
- list = connection_paths;
- while (list) {
- if (list == link) {
- default_index = i;
- break;
- }
- i++;
- list = list->next;
- }
-}
-
static DBusHandlerResult change_default_connection(DBusConnection *conn,
DBusMessage *msg, void *data)
{
@@ -731,7 +693,7 @@ static DBusHandlerResult change_default_connection(DBusConnection *conn,
const char *pattern;
DBusMessage *reply;
DBusError derr;
- GSList *link;
+ GSList *list;
dbus_error_init(&derr);
if (!dbus_message_get_args(msg, &derr,
@@ -748,23 +710,24 @@ static DBusHandlerResult change_default_connection(DBusConnection *conn,
return DBUS_HANDLER_RESULT_HANDLED;
}
- link = g_slist_find_custom(connection_paths, pattern, (GCompareFunc) strcmp);
+ list = g_slist_find_custom(connection_paths, pattern, (GCompareFunc) strcmp);
/* Find object path via pattern */
- if (link == NULL) {
- link = find_connection_pattern(conn, pattern);
+ if (list == NULL) {
+ list = find_connection_pattern(conn, pattern);
- if (link == NULL) {
+ if (list == NULL) {
err_failed(conn, msg, "No such connection");
return DBUS_HANDLER_RESULT_HANDLED;
}
else
- path = link->data;
+ path = list->data;
}
else
- path = link->data;
+ path = list->data;
- default_position(link);
+ default_index = g_slist_position (connection_paths, list);
+ connection_store(connection, path, TRUE);
dbus_connection_emit_signal(connection, NETWORK_PATH,
NETWORK_MANAGER_INTERFACE,
@@ -873,7 +836,7 @@ static void register_connections_stored(const char *adapter)
char filename[PATH_MAX + 1];
char *pattern;
struct stat s;
- GSList *link;
+ GSList *list;
bdaddr_t src;
bdaddr_t default_src;
int dev_id;
@@ -891,17 +854,15 @@ static void register_connections_stored(const char *adapter)
textfile_foreach(filename, parse_stored_connection, &src);
pattern = textfile_get(filename, "default");
- link = find_connection_pattern(connection, pattern);
- if (link != NULL)
- default_position(link);
+ list = find_connection_pattern(connection, pattern);
+ if (list != NULL)
+ default_index = g_slist_position(connection_paths, list);
else if (bacmp(&src, &default_src) == 0) {
- link = connection_paths;
- while (link->next)
- link = link->next;
- if (link == NULL)
+ list = g_slist_last(connection_paths);
+ if (list == NULL)
return;
- default_position(link);
- connection_store(connection, link->data, TRUE);
+ default_index = g_slist_position(connection_paths, list);
+ connection_store(connection, list->data, TRUE);
}
}
}