diff --git a/clients/cli/common.c b/clients/cli/common.c index 7b6a9fc9f8..0a7541c976 100644 --- a/clients/cli/common.c +++ b/clients/cli/common.c @@ -993,7 +993,7 @@ nmc_team_check_config (const char *config, char **out_config, GError **error) /* * nmc_find_connection: - * @list: list of NMConnections to search in + * @connections: array of NMConnections to search in * @filter_type: "id", "uuid", "path" or %NULL * @filter_val: connection to find (connection name, UUID or path) * @start: where to start in @list. The location is updated so that the function @@ -1008,21 +1008,20 @@ nmc_team_check_config (const char *config, char **out_config, GError **error) * Returns: found connection, or %NULL */ NMConnection * -nmc_find_connection (GSList *list, +nmc_find_connection (const GPtrArray *connections, const char *filter_type, const char *filter_val, - GSList **start) + int *start) { NMConnection *connection; NMConnection *found = NULL; - GSList *iterator; + int i; const char *id; const char *uuid; const char *path, *path_num; - iterator = (start && *start) ? *start : list; - while (iterator) { - connection = NM_CONNECTION (iterator->data); + for (i = start ? *start : 0; i < connections->len; i++) { + connection = NM_CONNECTION (connections->pdata[i]); id = nm_connection_get_id (connection); uuid = nm_connection_get_uuid (connection); @@ -1043,17 +1042,15 @@ nmc_find_connection (GSList *list, if (!start) return connection; if (found) { - *start = iterator; + *start = i; return found; } found = connection; } - - iterator = g_slist_next (iterator); } if (start) - *start = NULL; + *start = 0; return found; } diff --git a/clients/cli/common.h b/clients/cli/common.h index a1a45e3ad3..4f43674793 100644 --- a/clients/cli/common.h +++ b/clients/cli/common.h @@ -46,10 +46,10 @@ nmc_vlan_parse_priority_maps (const char *priority_map, const char *nmc_bond_validate_mode (const char *mode, GError **error); gboolean nmc_team_check_config (const char *config, char **out_config, GError **error); -NMConnection *nmc_find_connection (GSList *list, +NMConnection *nmc_find_connection (const GPtrArray *connections, const char *filter_type, const char *filter_val, - GSList **start); + int *start); void nmc_cleanup_readline (void); char *nmc_readline (const char *prompt_fmt, ...) G_GNUC_PRINTF (1, 2); diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 5c239563bf..d9f5f295fa 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -683,7 +683,7 @@ nmc_connection_profile_details (NMConnection *connection, NmCli *nmc) static NMActiveConnection * find_active_connection (const GPtrArray *active_cons, - const GSList *cons, + const GPtrArray *cons, const char *filter_type, const char *filter_val, int *idx) @@ -905,19 +905,18 @@ static void fill_output_for_all_invisible (NmCli *nmc) { const GPtrArray *acons; - GSList *iter; - int i; + int a, c; g_return_if_fail (nmc != NULL); acons = nm_client_get_active_connections (nmc->client); - for (i = 0; i < acons->len; i++) { + for (a = 0; a < acons->len; a++) { gboolean found = FALSE; - NMActiveConnection *acon = g_ptr_array_index (acons, i); + NMActiveConnection *acon = g_ptr_array_index (acons, a); const char *a_uuid = nm_active_connection_get_uuid (acon); - for (iter = nmc->connections; iter; iter = g_slist_next (iter)) { - NMConnection *con = NM_CONNECTION (iter->data); + for (c = 0; c < nmc->connections->len; c++) { + NMConnection *con = g_ptr_array_index (nmc->connections, c); const char *c_uuid = nm_connection_get_uuid (con); if (strcmp (a_uuid, c_uuid) == 0) { @@ -1326,7 +1325,7 @@ do_connections_show (NmCli *nmc, gboolean active_only, int argc, char **argv) char *fields_common = NMC_FIELDS_CON_SHOW_COMMON; NmcOutputField *tmpl, *arr; size_t tmpl_len; - GSList *iter; + int i; if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0) fields_str = fields_common; @@ -1351,8 +1350,8 @@ do_connections_show (NmCli *nmc, gboolean active_only, int argc, char **argv) g_ptr_array_add (nmc->output_data, arr); /* Add values */ - for (iter = nmc->connections; iter; iter = g_slist_next (iter)) { - NMConnection *con = NM_CONNECTION (iter->data); + for (i = 0; i < nmc->connections->len; i++) { + NMConnection *con = NM_CONNECTION (nmc->connections->pdata[i]); fill_output_connection (con, nmc, active_only); } /* Some active connections may not be in connection list, show them here. */ @@ -1362,7 +1361,7 @@ do_connections_show (NmCli *nmc, gboolean active_only, int argc, char **argv) gboolean new_line = FALSE; gboolean without_fields = (nmc->required_fields == NULL); const GPtrArray *active_cons = nm_client_get_active_connections (nmc->client); - GSList *pos = NULL; + int pos = 0; /* multiline mode is default for 'connection show ' */ if (!nmc->mode_specified) @@ -2680,25 +2679,25 @@ add_ip6_address_to_connection (NMIP6Address *ip6addr, NMConnection *connection) } static char * -unique_master_iface_ifname (GSList *list, +unique_master_iface_ifname (const GPtrArray *connections, const char *try_name) { NMConnection *connection; char *new_name; unsigned int num = 1; - GSList *iterator = list; + int i = 0; const char *ifname = NULL; new_name = g_strdup (try_name); - while (iterator) { - connection = NM_CONNECTION (iterator->data); + while (i < connections->len) { + connection = NM_CONNECTION (connections->pdata[i]); ifname = nm_connection_get_interface_name (connection); if (g_strcmp0 (new_name, ifname) == 0) { g_free (new_name); new_name = g_strdup_printf ("%s%d", try_name, num++); - iterator = list; + i = 0; } else - iterator = g_slist_next (iterator); + i++; } return new_name; } @@ -2737,14 +2736,14 @@ _strip_master_prefix (const char *master, const char *(**func)(NMConnection *)) * Returns: identifier of master connection if found, %NULL otherwise */ static const char * -verify_master_for_slave (GSList *connections, +verify_master_for_slave (const GPtrArray *connections, const char *master, const char *type) { NMConnection *connection; NMSettingConnection *s_con; const char *con_type, *id, *uuid, *ifname; - GSList *iterator = connections; + int i; const char *found_by_id = NULL; const char *out_master = NULL; const char *(*func) (NMConnection *) = NULL; @@ -2753,15 +2752,13 @@ verify_master_for_slave (GSList *connections, return NULL; master = _strip_master_prefix (master, &func); - while (iterator) { - connection = NM_CONNECTION (iterator->data); + for (i = 0; i < connections->len; i++) { + connection = NM_CONNECTION (connections->pdata[i]); s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); con_type = nm_setting_connection_get_connection_type (s_con); - if (g_strcmp0 (con_type, type) != 0) { - iterator = g_slist_next (iterator); + if (g_strcmp0 (con_type, type) != 0) continue; - } if (func) { /* There was a prefix; only compare to that type. */ if (g_strcmp0 (master, func (connection)) == 0) { @@ -2783,8 +2780,6 @@ verify_master_for_slave (GSList *connections, if (!found_by_id && g_strcmp0 (master, id) == 0) found_by_id = uuid; } - - iterator = g_slist_next (iterator); } return out_master ? out_master : found_by_id; } @@ -3633,7 +3628,7 @@ do_questionnaire_ip (NMConnection *connection) static gboolean complete_connection_by_type (NMConnection *connection, const char *con_type, - GSList *all_connections, + const GPtrArray *all_connections, gboolean ask, int argc, char **argv, @@ -4917,25 +4912,25 @@ cleanup_olpc: } static char * -unique_connection_name (GSList *list, const char *try_name) +unique_connection_name (const GPtrArray *connections, const char *try_name) { NMConnection *connection; const char *name; char *new_name; unsigned int num = 1; - GSList *iterator = list; + int i = 0; new_name = g_strdup (try_name); - while (iterator) { - connection = NM_CONNECTION (iterator->data); + while (i < connections->len) { + connection = NM_CONNECTION (connections->pdata[i]); name = nm_connection_get_id (connection); if (g_strcmp0 (new_name, name) == 0) { g_free (new_name); new_name = g_strdup_printf ("%s-%d", try_name, num++); - iterator = list; - } - iterator = g_slist_next (iterator); + i = 0; + } else + i++; } return new_name; } @@ -5039,7 +5034,7 @@ gen_func_bond_mon_mode (const char *text, int state) static char * gen_func_master_ifnames (const char *text, int state) { - GSList *iter; + int i; GPtrArray *ifnames; char *ret; NMConnection *con; @@ -5053,8 +5048,8 @@ gen_func_master_ifnames (const char *text, int state) rl_completion_append_character = '\0'; ifnames = g_ptr_array_sized_new (20); - for (iter = nm_cli.connections; iter; iter = g_slist_next (iter)) { - con = NM_CONNECTION (iter->data); + for (i = 0; i < nm_cli.connections->len; i++) { + con = NM_CONNECTION (nm_cli.connections->pdata[i]); s_con = nm_connection_get_setting_connection (con); g_assert (s_con); con_type = nm_setting_connection_get_connection_type (s_con); @@ -5566,24 +5561,23 @@ gen_compat_devices (const char *text, int state) static char * gen_vpn_uuids (const char *text, int state) { - GSList *iter; - guint len; - int i = 0; + const GPtrArray *connections = nmc_tab_completion.nmc->connections; + int c, u = 0; const char **uuids; char *ret; - len = g_slist_length (nmc_tab_completion.nmc->connections); - if (len < 1) + if (connections->len < 1) return NULL; - uuids = g_new (const char *, len + 1); - for (iter = nmc_tab_completion.nmc->connections; iter; iter = g_slist_next (iter)) { - const char *type = nm_connection_get_connection_type (NM_CONNECTION (iter->data)); + uuids = g_new (const char *, connections->len + 1); + for (c = 0; c < connections->len; c++) { + NMConnection *connection = NM_CONNECTION (connections->pdata[c]); + const char *type = nm_connection_get_connection_type (connection); if (g_strcmp0 (type, NM_SETTING_VPN_SETTING_NAME) == 0) - uuids[i++] = nm_connection_get_uuid (NM_CONNECTION (iter->data)); + uuids[u++] = nm_connection_get_uuid (connection); } - uuids[i] = NULL; + uuids[u] = NULL; ret = nmc_rl_gen_func_basic (text, state, uuids); @@ -8235,7 +8229,7 @@ do_connection_delete (NmCli *nmc, int argc, char **argv) int arg_num = argc; GString *invalid_cons = NULL; gboolean del_info_free = FALSE; - GSList *pos = NULL; + int pos = 0; nmc->return_value = NMC_RESULT_SUCCESS; nmc->should_wait = FALSE; @@ -8421,17 +8415,16 @@ connection_editor_thread_func (gpointer data) static char * gen_func_connection_names (const char *text, int state) { - int i = 0; - GSList *iter; + int i; const char **connections; char *ret; - if (!nm_cli.connections) + if (nm_cli.connections->len == 0) return NULL; - connections = g_new (const char *, g_slist_length (nm_cli.connections) + 1); - for (iter = nm_cli.connections; iter; iter = g_slist_next (iter)) { - NMConnection *con = NM_CONNECTION (iter->data); + connections = g_new (const char *, nm_cli.connections->len + 1); + for (i = 0; i < nm_cli.connections->len; i++) { + NMConnection *con = NM_CONNECTION (nm_cli.connections->pdata[i]); const char *id = nm_connection_get_id (con); connections[i++] = id; } @@ -8500,7 +8493,7 @@ do_connections (NmCli *nmc, int argc, char **argv) return nmc->return_value; /* Get the connection list */ - nmc->connections = nm_client_list_connections (nmc->client); + nmc->connections = nm_client_get_connections (nmc->client); /* Now parse the command line and perform the required operation */ if (argc == 0) { diff --git a/clients/cli/nmcli.c b/clients/cli/nmcli.c index f6ca11e935..ca71abf936 100644 --- a/clients/cli/nmcli.c +++ b/clients/cli/nmcli.c @@ -524,8 +524,6 @@ nmc_cleanup (NmCli *nmc) g_string_free (nmc->return_text, TRUE); - g_slist_free (nmc->connections); - g_free (nmc->required_fields); nmc_empty_output_fields (nmc); g_ptr_array_unref (nmc->output_data); diff --git a/clients/cli/nmcli.h b/clients/cli/nmcli.h index 2d67320cbd..34beb92298 100644 --- a/clients/cli/nmcli.h +++ b/clients/cli/nmcli.h @@ -110,7 +110,7 @@ typedef struct _NmCli { int timeout; /* Operation timeout */ - GSList *connections; /* List of connections */ + const GPtrArray *connections; /* List of connections */ gboolean should_wait; /* Indication that nmcli should not end yet */ gboolean nowait_flag; /* '--nowait' option; used for passing to callbacks */ diff --git a/clients/tui/nm-editor-utils.c b/clients/tui/nm-editor-utils.c index e7b47e1a0d..a98278bc09 100644 --- a/clients/tui/nm-editor-utils.c +++ b/clients/tui/nm-editor-utils.c @@ -257,19 +257,19 @@ static char * get_available_connection_name (const char *format, NMClient *client) { - GSList *connections, *iter, *names = NULL; + const GPtrArray *conns; + GSList *names = NULL, *iter; char *cname = NULL; int i = 0; - connections = nm_client_list_connections (client); - for (iter = connections; iter; iter = iter->next) { + conns = nm_client_get_connections (client); + for (i = 0; i < conns->len; i++) { const char *id; - id = nm_connection_get_id (NM_CONNECTION (iter->data)); + id = nm_connection_get_id (NM_CONNECTION (conns->pdata[i])); g_assert (id); names = g_slist_append (names, (gpointer) id); } - g_slist_free (connections); /* Find the next available unique connection name */ while (!cname && (i++ < 10000)) { diff --git a/clients/tui/nmt-connect-connection-list.c b/clients/tui/nmt-connect-connection-list.c index 4b80a807ed..bd54af22cd 100644 --- a/clients/tui/nmt-connect-connection-list.c +++ b/clients/tui/nmt-connect-connection-list.c @@ -183,12 +183,12 @@ sort_connections (gconstpointer a, static void add_connections_for_device (NmtConnectDevice *nmtdev, - GSList *connections) + const GPtrArray *connections) { - GSList *iter; + int i; - for (iter = connections; iter; iter = iter->next) { - NMConnection *conn = iter->data; + for (i = 0; i < connections->len; i++) { + NMConnection *conn = connections->pdata[i]; NMSettingConnection *s_con; s_con = nm_connection_get_setting_connection (conn); @@ -257,7 +257,7 @@ hash_ap (NMAccessPoint *ap) static void add_connections_for_aps (NmtConnectDevice *nmtdev, - GSList *connections) + const GPtrArray *connections) { NmtConnectConnection *nmtconn; NMConnection *conn; @@ -266,8 +266,7 @@ add_connections_for_aps (NmtConnectDevice *nmtdev, GHashTable *seen_ssids; GBytes *ssid; char *ap_hash; - GSList *iter; - int i; + int i, c; aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (nmtdev->device)); if (!aps->len) @@ -296,8 +295,8 @@ add_connections_for_aps (NmtConnectDevice *nmtdev, nmtconn->ssid = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid)); - for (iter = connections; iter; iter = iter->next) { - conn = iter->data; + for (c = 0; c < connections->len; c++) { + conn = connections->pdata[c]; if ( nm_device_connection_valid (nmtdev->device, conn) && nm_access_point_connection_valid (ap, conn)) { nmtconn->name = nm_connection_get_id (conn); @@ -306,7 +305,7 @@ add_connections_for_aps (NmtConnectDevice *nmtdev, } } - if (!iter) + if (!nmtconn->name) nmtconn->name = nmtconn->ssid ? nmtconn->ssid : ""; nmtdev->conns = g_slist_prepend (nmtdev->conns, nmtconn); @@ -319,7 +318,7 @@ static GSList * append_nmt_devices_for_devices (GSList *nmt_devices, const GPtrArray *devices, char **names, - GSList *connections) + const GPtrArray *connections) { NmtConnectDevice *nmtdev; NMDevice *device; @@ -350,11 +349,11 @@ append_nmt_devices_for_devices (GSList *nmt_devices, } static GSList * -append_nmt_devices_for_virtual_devices (GSList *nmt_devices, - GSList *connections) +append_nmt_devices_for_virtual_devices (GSList *nmt_devices, + const GPtrArray *connections) { NmtConnectDevice *nmtdev = NULL; - GSList *iter; + int i; GHashTable *devices_by_name; char *name; NMConnection *conn; @@ -363,8 +362,8 @@ append_nmt_devices_for_virtual_devices (GSList *nmt_devices, devices_by_name = g_hash_table_new (g_str_hash, g_str_equal); - for (iter = connections; iter; iter = iter->next) { - conn = iter->data; + for (i = 0; i < connections->len; i++) { + conn = connections->pdata[i]; sort_order = get_sort_order_for_connection (conn); if (sort_order == -1) continue; @@ -395,11 +394,11 @@ append_nmt_devices_for_virtual_devices (GSList *nmt_devices, } static GSList * -append_nmt_devices_for_vpns (GSList *nmt_devices, - GSList *connections) +append_nmt_devices_for_vpns (GSList *nmt_devices, + const GPtrArray *connections) { NmtConnectDevice *nmtdev; - GSList *iter; + int i; NMConnection *conn; NmtConnectConnection *nmtconn; @@ -407,8 +406,8 @@ append_nmt_devices_for_vpns (GSList *nmt_devices, nmtdev->name = g_strdup (_("VPN")); nmtdev->sort_order = 100; - for (iter = connections; iter; iter = iter->next) { - conn = iter->data; + for (i = 0; i < connections->len; i++) { + conn = connections->pdata[i]; if (!nm_connection_is_type (conn, NM_SETTING_VPN_SETTING_NAME)) continue; @@ -464,11 +463,10 @@ nmt_connect_connection_list_rebuild (NmtConnectConnectionList *list) { NmtConnectConnectionListPrivate *priv = NMT_CONNECT_CONNECTION_LIST_GET_PRIVATE (list); NmtNewtListbox *listbox = NMT_NEWT_LISTBOX (list); - const GPtrArray *devices, *acs; + const GPtrArray *devices, *acs, *connections; int max_width; char **names, *row, active_col; const char *strength_col; - GSList *connections; GSList *nmt_devices, *diter, *citer; NmtConnectDevice *nmtdev; NmtConnectConnection *nmtconn; @@ -479,7 +477,7 @@ nmt_connect_connection_list_rebuild (NmtConnectConnectionList *list) devices = nm_client_get_devices (nm_client); acs = nm_client_get_active_connections (nm_client); - connections = nm_client_list_connections (nm_client); + connections = nm_client_get_connections (nm_client); nmt_devices = NULL; @@ -491,7 +489,6 @@ nmt_connect_connection_list_rebuild (NmtConnectConnectionList *list) nmt_devices = append_nmt_devices_for_vpns (nmt_devices, connections); nmt_devices = g_slist_sort (nmt_devices, sort_nmt_devices); - g_slist_free (connections); max_width = 0; for (diter = nmt_devices; diter; diter = diter->next) { diff --git a/clients/tui/nmt-edit-connection-list.c b/clients/tui/nmt-edit-connection-list.c index 9afe44164f..e1b982dde9 100644 --- a/clients/tui/nmt-edit-connection-list.c +++ b/clients/tui/nmt-edit-connection-list.c @@ -83,23 +83,6 @@ static void edit_clicked (NmtNewtButton *button, gpointer list); static void delete_clicked (NmtNewtButton *button, gpointer list); static void listbox_activated (NmtNewtWidget *listbox, gpointer list); -/** - * nmt_edit_connection_list_get_connections: - * @list: an #NmtEditConnectionList - * - * Gets the list's list of connections - * - * Returns: (transfer none) (element-type #NMConnection): the - * list of connections. - */ -GSList * -nmt_edit_connection_list_get_connections (NmtEditConnectionList *list) -{ - NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE (list); - - return priv->connections; -} - static void nmt_edit_connection_list_init (NmtEditConnectionList *list) { @@ -175,13 +158,15 @@ free_connections (NmtEditConnectionList *list) g_object_unref (conn); } g_slist_free (priv->connections); + priv->connections = NULL; } static void nmt_edit_connection_list_rebuild (NmtEditConnectionList *list) { NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE (list); - GSList *iter, *next; + const GPtrArray *connections; + GSList *iter; gboolean did_header = FALSE, did_vpn = FALSE; NMEditorConnectionTypeData **types; NMConnection *conn, *selected_conn; @@ -191,20 +176,17 @@ nmt_edit_connection_list_rebuild (NmtEditConnectionList *list) selected_conn = nmt_newt_listbox_get_active_key (priv->listbox); free_connections (list); - priv->connections = nm_client_list_connections (nm_client); - for (iter = priv->connections; iter; iter = next) { - conn = iter->data; - next = iter->next; + connections = nm_client_get_connections (nm_client); + for (i = 0; i < connections->len; i++) { + conn = connections->pdata[i]; if ( priv->connection_filter - && !priv->connection_filter (list, conn, priv->connection_filter_data)) { - priv->connections = g_slist_delete_link (priv->connections, iter); + && !priv->connection_filter (list, conn, priv->connection_filter_data)) continue; - } g_signal_connect (conn, NM_CONNECTION_CHANGED, G_CALLBACK (rebuild_on_connection_changed), list); - g_object_ref (iter->data); + priv->connections = g_slist_prepend (priv->connections, g_object_ref (conn)); } priv->connections = g_slist_sort (priv->connections, sort_by_timestamp); g_object_notify (G_OBJECT (list), "connections"); diff --git a/clients/tui/nmt-edit-connection-list.h b/clients/tui/nmt-edit-connection-list.h index a359170a1b..c31c0a8cb5 100644 --- a/clients/tui/nmt-edit-connection-list.h +++ b/clients/tui/nmt-edit-connection-list.h @@ -54,8 +54,6 @@ typedef gboolean (*NmtEditConnectionListFilter) (NmtEditConnectionList *list, NMConnection *connection, gpointer user_data); -GSList *nmt_edit_connection_list_get_connections (NmtEditConnectionList *list); - G_END_DECLS #endif /* NMT_EDIT_CONNECTION_LIST_H */ diff --git a/clients/tui/nmtui-edit.c b/clients/tui/nmtui-edit.c index d32da817cd..2cc6b773aa 100644 --- a/clients/tui/nmtui-edit.c +++ b/clients/tui/nmtui-edit.c @@ -72,7 +72,8 @@ edit_connection_list_filter (NmtEditConnectionList *list, NMSettingConnection *s_con; const char *master, *slave_type; const char *uuid, *ifname; - GSList *conns, *iter; + const GPtrArray *conns; + int i; gboolean found_master = FALSE; s_con = nm_connection_get_setting_connection (connection); @@ -87,16 +88,17 @@ edit_connection_list_filter (NmtEditConnectionList *list, && g_strcmp0 (slave_type, NM_SETTING_BRIDGE_SETTING_NAME) != 0) return TRUE; - conns = nm_client_list_connections (nm_client); - for (iter = conns; iter; iter = iter->next) { - uuid = nm_connection_get_uuid (iter->data); - ifname = nm_connection_get_interface_name (iter->data); + conns = nm_client_get_connections (nm_client); + for (i = 0; i < conns->len; i++) { + NMConnection *candidate = conns->pdata[i]; + + uuid = nm_connection_get_uuid (candidate); + ifname = nm_connection_get_interface_name (candidate); if (!g_strcmp0 (master, uuid) || !g_strcmp0 (master, ifname)) { found_master = TRUE; break; } } - g_slist_free (conns); return !found_master; } @@ -513,7 +515,8 @@ remove_one_connection (NMRemoteConnection *connection) void nmt_remove_connection (NMRemoteConnection *connection) { - GSList *conns, *iter; + const GPtrArray *conns; + int i; NMRemoteConnection *slave; NMSettingConnection *s_con; const char *uuid, *iface, *master; @@ -532,9 +535,9 @@ nmt_remove_connection (NMRemoteConnection *connection) uuid = nm_connection_get_uuid (NM_CONNECTION (connection)); iface = nm_connection_get_interface_name (NM_CONNECTION (connection)); - conns = nm_client_list_connections (nm_client); - for (iter = conns; iter; iter = iter->next) { - slave = iter->data; + conns = nm_client_get_connections (nm_client); + for (i = 0; i < conns->len; i++) { + slave = conns->pdata[i]; s_con = nm_connection_get_setting_connection (NM_CONNECTION (slave)); master = nm_setting_connection_get_master (s_con); if (master) { @@ -542,7 +545,6 @@ nmt_remove_connection (NMRemoteConnection *connection) remove_one_connection (slave); } } - g_slist_free (conns); g_object_unref (connection); } diff --git a/examples/C/glib/list-connections-libnm.c b/examples/C/glib/list-connections-libnm.c index f761bfd77f..f09c028b6b 100644 --- a/examples/C/glib/list-connections-libnm.c +++ b/examples/C/glib/list-connections-libnm.c @@ -34,9 +34,8 @@ /* Print details of connection */ static void -show_connection (gpointer data, gpointer user_data) +show_connection (NMConnection *connection) { - NMConnection *connection = (NMConnection *) data; NMSettingConnection *s_con; guint64 timestamp; char *timestamp_str; @@ -67,7 +66,8 @@ main (int argc, char *argv[]) { NMClient *client; GError *error = NULL; - GSList *connections; + const GPtrArray *connections; + int i; #if !GLIB_CHECK_VERSION (2, 35, 0) /* Initialize GType system */ @@ -86,13 +86,13 @@ main (int argc, char *argv[]) } /* Now the connections can be listed. */ - connections = nm_client_list_connections (client); + connections = nm_client_get_connections (client); printf ("Connections:\n===================\n"); - g_slist_foreach (connections, show_connection, NULL); + for (i = 0; i < connections->len; i++) + show_connection (connections->pdata[i]); - g_slist_free (connections); g_object_unref (client); return EXIT_SUCCESS; diff --git a/libnm/libnm.ver b/libnm/libnm.ver index bc08e7fd01..d735a30e38 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -54,6 +54,7 @@ global: nm_client_get_connection_by_id; nm_client_get_connection_by_path; nm_client_get_connection_by_uuid; + nm_client_get_connections; nm_client_get_connectivity; nm_client_get_device_by_iface; nm_client_get_device_by_path; @@ -66,7 +67,6 @@ global: nm_client_get_state; nm_client_get_type; nm_client_get_version; - nm_client_list_connections; nm_client_load_connections; nm_client_load_connections_async; nm_client_load_connections_finish; diff --git a/libnm/nm-access-point.c b/libnm/nm-access-point.c index 0bb2c21409..dfc7240192 100644 --- a/libnm/nm-access-point.c +++ b/libnm/nm-access-point.c @@ -323,39 +323,38 @@ nm_access_point_connection_valid (NMAccessPoint *ap, NMConnection *connection) /** * nm_access_point_filter_connections: * @ap: an #NMAccessPoint to filter connections for - * @connections: (element-type NMConnection): a list of - * #NMConnection objects to filter + * @connections: (element-type NMConnection): an array of #NMConnections to + * filter * - * Filters a given list of connections for a given #NMAccessPoint object and - * return connections which may be activated with the access point. Any + * Filters a given array of connections for a given #NMAccessPoint object and + * returns connections which may be activated with the access point. Any * returned connections will match the @ap's SSID and (if given) BSSID and * other attributes like security settings, channel, etc. * * To obtain the list of connections that are compatible with this access point, - * use nm_remote_settings_list_connections() and then filter the returned list - * for a given #NMDevice using nm_device_filter_connections() and finally - * filter that list with this function. + * use nm_client_get_connections() and then filter the returned list for a given + * #NMDevice using nm_device_filter_connections() and finally filter that list + * with this function. * - * Returns: (transfer container) (element-type NMConnection): a - * list of #NMConnection objects that could be activated with the given @ap. - * The elements of the list are owned by their creator and should not be freed - * by the caller, but the returned list itself is owned by the caller and should - * be freed with g_slist_free() when it is no longer required. + * Returns: (transfer container) (element-type NMConnection): an array of + * #NMConnections that could be activated with the given @ap. The array should + * be freed with g_ptr_array_unref() when it is no longer required. **/ -GSList * -nm_access_point_filter_connections (NMAccessPoint *ap, const GSList *connections) +GPtrArray * +nm_access_point_filter_connections (NMAccessPoint *ap, const GPtrArray *connections) { - GSList *filtered = NULL; - const GSList *iter; + GPtrArray *filtered; + int i; - for (iter = connections; iter; iter = g_slist_next (iter)) { - NMConnection *candidate = NM_CONNECTION (iter->data); + filtered = g_ptr_array_new_with_free_func (g_object_unref); + for (i = 0; i < connections->len; i++) { + NMConnection *candidate = connections->pdata[i]; if (nm_access_point_connection_valid (ap, candidate)) - filtered = g_slist_prepend (filtered, candidate); + g_ptr_array_add (filtered, g_object_ref (candidate)); } - return g_slist_reverse (filtered); + return filtered; } /************************************************************/ diff --git a/libnm/nm-access-point.h b/libnm/nm-access-point.h index 53935e5fa9..6991c19ac6 100644 --- a/libnm/nm-access-point.h +++ b/libnm/nm-access-point.h @@ -74,8 +74,8 @@ NM80211Mode nm_access_point_get_mode (NMAccessPoint *ap); guint32 nm_access_point_get_max_bitrate (NMAccessPoint *ap); guint8 nm_access_point_get_strength (NMAccessPoint *ap); -GSList * nm_access_point_filter_connections (NMAccessPoint *ap, - const GSList *connections); +GPtrArray * nm_access_point_filter_connections (NMAccessPoint *ap, + const GPtrArray *connections); gboolean nm_access_point_connection_valid (NMAccessPoint *ap, NMConnection *connection); diff --git a/libnm/nm-client.c b/libnm/nm-client.c index dad101b00b..f6a2256709 100644 --- a/libnm/nm-client.c +++ b/libnm/nm-client.c @@ -1150,22 +1150,19 @@ nm_client_deactivate_connection_finish (NMClient *client, /****************************************************************/ /** - * nm_client_list_connections: + * nm_client_get_connections: * @client: the %NMClient * - * Returns: (transfer container) (element-type NMRemoteConnection): a - * list containing all connections provided by the remote settings service. - * Each element of the returned list is a %NMRemoteConnection instance, which is - * owned by the %NMClient object and should not be freed by the caller. - * The returned list is, however, owned by the caller and should be freed - * using g_slist_free() when no longer required. + * Returns: (transfer none) (element-type NMRemoteConnection): an array + * containing all connections provided by the remote settings service. The + * returned array is owned by the #NMClient object and should not be modified. **/ -GSList * -nm_client_list_connections (NMClient *client) +const GPtrArray * +nm_client_get_connections (NMClient *client) { g_return_val_if_fail (NM_IS_CLIENT (client), NULL); - return nm_remote_settings_list_connections (NM_CLIENT_GET_PRIVATE (client)->settings); + return nm_remote_settings_get_connections (NM_CLIENT_GET_PRIVATE (client)->settings); } /** diff --git a/libnm/nm-client.h b/libnm/nm-client.h index 2f22289c1f..619ad8585f 100644 --- a/libnm/nm-client.h +++ b/libnm/nm-client.h @@ -294,7 +294,7 @@ gboolean nm_client_deactivate_connection_finish (NMClient *client, /* Connections */ -GSList *nm_client_list_connections (NMClient *client); +const GPtrArray *nm_client_get_connections (NMClient *client); NMRemoteConnection *nm_client_get_connection_by_id (NMClient *client, const char *id); NMRemoteConnection *nm_client_get_connection_by_path (NMClient *client, const char *path); diff --git a/libnm/nm-device.c b/libnm/nm-device.c index 90df14035f..5999ed23d2 100644 --- a/libnm/nm-device.c +++ b/libnm/nm-device.c @@ -2168,38 +2168,37 @@ nm_device_connection_compatible (NMDevice *device, NMConnection *connection, GEr /** * nm_device_filter_connections: * @device: an #NMDevice to filter connections for - * @connections: (element-type NMConnection): a list of #NMConnection objects to filter + * @connections: (element-type NMConnection): an array of #NMConnections to filter * - * Filters a given list of connections for a given #NMDevice object and return + * Filters a given array of connections for a given #NMDevice object and returns * connections which may be activated with the device. For example if @device - * is a Wi-Fi device that supports only WEP encryption, the returned list will + * is a Wi-Fi device that supports only WEP encryption, the returned array will * contain any Wi-Fi connections in @connections that allow connection to - * unencrypted or WEP-enabled SSIDs. The returned list will not contain + * unencrypted or WEP-enabled SSIDs. The returned array will not contain * Ethernet, Bluetooth, Wi-Fi WPA connections, or any other connection that is * incompatible with the device. To get the full list of connections see - * nm_remote_settings_list_connections(). + * nm_client_get_connections(). * - * Returns: (transfer container) (element-type NMConnection): a - * list of #NMConnection objects that could be activated with the given @device. - * The elements of the list are owned by their creator and should not be freed - * by the caller, but the returned list itself is owned by the caller and should - * be freed with g_slist_free() when it is no longer required. + * Returns: (transfer container) (element-type NMConnection): an array of + * #NMConnections that could be activated with the given @device. The array + * should be freed with g_ptr_array_unref() when it is no longer required. **/ -GSList * -nm_device_filter_connections (NMDevice *device, const GSList *connections) +GPtrArray * +nm_device_filter_connections (NMDevice *device, const GPtrArray *connections) { - GSList *filtered = NULL; - const GSList *iter; + GPtrArray *filtered; + int i; - for (iter = connections; iter; iter = g_slist_next (iter)) { - NMConnection *candidate = NM_CONNECTION (iter->data); + filtered = g_ptr_array_new_with_free_func (g_object_unref); + for (i = 0; i < connections->len; i++) { + NMConnection *candidate = connections->pdata[i]; /* Connection applies to this device */ if (nm_device_connection_valid (device, candidate)) - filtered = g_slist_prepend (filtered, candidate); + g_ptr_array_add (filtered, g_object_ref (candidate)); } - return g_slist_reverse (filtered); + return filtered; } /** diff --git a/libnm/nm-device.h b/libnm/nm-device.h index cbfe6d4309..412dff3f96 100644 --- a/libnm/nm-device.h +++ b/libnm/nm-device.h @@ -144,8 +144,8 @@ gboolean nm_device_delete_finish (NMDevice *device, GAsyncResult *result, GError **error); -GSList * nm_device_filter_connections (NMDevice *device, - const GSList *connections); +GPtrArray * nm_device_filter_connections (NMDevice *device, + const GPtrArray *connections); gboolean nm_device_connection_valid (NMDevice *device, NMConnection *connection); diff --git a/libnm/nm-remote-settings.c b/libnm/nm-remote-settings.c index 62a3853d69..351fbc1bd2 100644 --- a/libnm/nm-remote-settings.c +++ b/libnm/nm-remote-settings.c @@ -261,24 +261,12 @@ object_creation_failed (NMObject *object, const char *failed_path) } } -GSList * -nm_remote_settings_list_connections (NMRemoteSettings *settings) +const GPtrArray * +nm_remote_settings_get_connections (NMRemoteSettings *settings) { - NMRemoteSettingsPrivate *priv; - GSList *list = NULL; - int i; - g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), NULL); - priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); - - if (_nm_object_get_nm_running (NM_OBJECT (settings))) { - for (i = 0; i < priv->visible_connections->len; i++) - list = g_slist_prepend (list, priv->visible_connections->pdata[i]); - list = g_slist_reverse (list); - } - - return list; + return NM_REMOTE_SETTINGS_GET_PRIVATE (settings)->visible_connections; } static void diff --git a/libnm/nm-remote-settings.h b/libnm/nm-remote-settings.h index dbe39abe5e..1ffc0bf20b 100644 --- a/libnm/nm-remote-settings.h +++ b/libnm/nm-remote-settings.h @@ -62,13 +62,13 @@ struct _NMRemoteSettingsClass { GType nm_remote_settings_get_type (void); -GSList *nm_remote_settings_list_connections (NMRemoteSettings *settings); +const GPtrArray *nm_remote_settings_get_connections (NMRemoteSettings *settings); -NMRemoteConnection *nm_remote_settings_get_connection_by_id (NMRemoteSettings *settings, - const char *id); +NMRemoteConnection *nm_remote_settings_get_connection_by_id (NMRemoteSettings *settings, + const char *id); -NMRemoteConnection * nm_remote_settings_get_connection_by_path (NMRemoteSettings *settings, - const char *path); +NMRemoteConnection *nm_remote_settings_get_connection_by_path (NMRemoteSettings *settings, + const char *path); NMRemoteConnection *nm_remote_settings_get_connection_by_uuid (NMRemoteSettings *settings, const char *uuid); diff --git a/libnm/nm-wimax-nsp.c b/libnm/nm-wimax-nsp.c index 2387000569..9532b17627 100644 --- a/libnm/nm-wimax-nsp.c +++ b/libnm/nm-wimax-nsp.c @@ -145,33 +145,32 @@ nm_wimax_nsp_connection_valid (NMWimaxNsp *nsp, NMConnection *connection) /** * nm_wimax_nsp_filter_connections: * @nsp: an #NMWimaxNsp to filter connections for - * @connections: (element-type NMConnection): a list of - * #NMConnection objects to filter + * @connections: (element-type NMConnection): an array of #NMConnections to + * filter * - * Filters a given list of connections for a given #NMWimaxNsp object and - * return connections which may be activated with the access point. Any - * returned connections will match the @nsp's network name and other attributes. + * Filters a given array of connections for a given #NMWimaxNsp object and + * return connections which may be activated with the NSP. Any returned + * connections will match the @nsp's network name and other attributes. * - * Returns: (transfer container) (element-type NMConnection): a - * list of #NMConnection objects that could be activated with the given @nsp. - * The elements of the list are owned by their creator and should not be freed - * by the caller, but the returned list itself is owned by the caller and should - * be freed with g_slist_free() when it is no longer required. + * Returns: (transfer container) (element-type NMConnection): an array of + * #NMConnections that could be activated with the given @nsp. The array should + * be freed with g_ptr_array_unref() when it is no longer required. **/ -GSList * -nm_wimax_nsp_filter_connections (NMWimaxNsp *nsp, const GSList *connections) +GPtrArray * +nm_wimax_nsp_filter_connections (NMWimaxNsp *nsp, const GPtrArray *connections) { - GSList *filtered = NULL; - const GSList *iter; + GPtrArray *filtered; + int i; - for (iter = connections; iter; iter = g_slist_next (iter)) { - NMConnection *candidate = NM_CONNECTION (iter->data); + filtered = g_ptr_array_new_with_free_func (g_object_unref); + for (i = 0; i < connections->len; i++) { + NMConnection *candidate = connections->pdata[i]; if (nm_wimax_nsp_connection_valid (nsp, candidate)) - filtered = g_slist_prepend (filtered, candidate); + g_ptr_array_add (filtered, g_object_ref (candidate)); } - return g_slist_reverse (filtered); + return filtered; } /************************************************************/ diff --git a/libnm/nm-wimax-nsp.h b/libnm/nm-wimax-nsp.h index 710639e784..a8f9105268 100644 --- a/libnm/nm-wimax-nsp.h +++ b/libnm/nm-wimax-nsp.h @@ -65,8 +65,8 @@ const char * nm_wimax_nsp_get_name (NMWimaxNsp *nsp); guint32 nm_wimax_nsp_get_signal_quality (NMWimaxNsp *nsp); NMWimaxNspNetworkType nm_wimax_nsp_get_network_type (NMWimaxNsp *nsp); -GSList * nm_wimax_nsp_filter_connections (NMWimaxNsp *nsp, - const GSList *connections); +GPtrArray * nm_wimax_nsp_filter_connections (NMWimaxNsp *nsp, + const GPtrArray *connections); gboolean nm_wimax_nsp_connection_valid (NMWimaxNsp *nsp, NMConnection *connection); diff --git a/libnm/tests/test-remote-settings-client.c b/libnm/tests/test-remote-settings-client.c index f521dbc1c0..d3af020526 100644 --- a/libnm/tests/test-remote-settings-client.c +++ b/libnm/tests/test-remote-settings-client.c @@ -133,7 +133,8 @@ static void test_make_invisible (void) { time_t start, now; - GSList *list, *iter; + const GPtrArray *conns; + int i; GDBusProxy *proxy; gboolean visible_changed = FALSE, connection_removed = FALSE; gboolean has_settings = FALSE; @@ -177,9 +178,9 @@ test_make_invisible (void) g_signal_handlers_disconnect_by_func (client, G_CALLBACK (connection_removed_cb), &connection_removed); /* Ensure NMClient no longer has the connection */ - list = nm_client_list_connections (client); - for (iter = list; iter; iter = g_slist_next (iter)) { - NMConnection *candidate = NM_CONNECTION (iter->data); + conns = nm_client_get_connections (client); + for (i = 0; i < conns->len; i++) { + NMConnection *candidate = NM_CONNECTION (conns->pdata[i]); g_assert ((gpointer) remote != (gpointer) candidate); g_assert (strcmp (path, nm_connection_get_path (candidate)) != 0); @@ -210,7 +211,8 @@ static void test_make_visible (void) { time_t start, now; - GSList *list, *iter; + const GPtrArray *conns; + int i; GDBusProxy *proxy; gboolean found = FALSE; char *path; @@ -255,9 +257,9 @@ test_make_visible (void) g_signal_handlers_disconnect_by_func (client, G_CALLBACK (vis_new_connection_cb), &new); /* Ensure NMClient has the connection */ - list = nm_client_list_connections (client); - for (iter = list; iter; iter = g_slist_next (iter)) { - NMConnection *candidate = NM_CONNECTION (iter->data); + conns = nm_client_get_connections (client); + for (i = 0; i < conns->len; i++) { + NMConnection *candidate = NM_CONNECTION (conns->pdata[i]); if ((gpointer) remote == (gpointer) candidate) { g_assert_cmpstr (path, ==, nm_connection_get_path (candidate)); @@ -299,16 +301,17 @@ test_remove_connection (void) { NMRemoteConnection *connection; time_t start, now; - GSList *list, *iter; + const GPtrArray *conns; + int i; GDBusProxy *proxy; gboolean done = FALSE; char *path; /* Find a connection to delete */ - list = nm_client_list_connections (client); - g_assert_cmpint (g_slist_length (list), >, 0); + conns = nm_client_get_connections (client); + g_assert_cmpint (conns->len, >, 0); - connection = NM_REMOTE_CONNECTION (list->data); + connection = NM_REMOTE_CONNECTION (conns->pdata[0]); g_assert (connection); g_assert (remote == connection); path = g_strdup (nm_connection_get_path (NM_CONNECTION (connection))); @@ -342,9 +345,9 @@ test_remove_connection (void) g_assert (!remote); /* Ensure NMClient no longer has the connection */ - list = nm_client_list_connections (client); - for (iter = list; iter; iter = g_slist_next (iter)) { - NMConnection *candidate = NM_CONNECTION (iter->data); + conns = nm_client_get_connections (client); + for (i = 0; i < conns->len; i++) { + NMConnection *candidate = NM_CONNECTION (conns->pdata[i]); g_assert ((gpointer) connection != (gpointer) candidate); g_assert_cmpstr (path, ==, nm_connection_get_path (candidate));