/* Get devices of the active connection */
dev_str = g_string_new (NULL);
devices = nm_active_connection_get_devices (active);
- for (i = 0; devices && (i < devices->len); i++) {
+ for (i = 0; i < devices->len; i++) {
NMDevice *device = g_ptr_array_index (devices, i);
const char *dev_iface = nm_device_get_iface (device);
/* Is the connection active? */
con_path = nm_connection_get_path (connection);
- for (i = 0; active_cons && i < active_cons->len; i++) {
+ for (i = 0; i < active_cons->len; i++) {
NMActiveConnection *candidate = g_ptr_array_index (active_cons, i);
if (!g_strcmp0 (nm_active_connection_get_connection (candidate), con_path)) {
NMConnection *con;
NMActiveConnection *found = NULL;
- for (i = start; active_cons && (i < active_cons->len); i++) {
+ for (i = start; i < active_cons->len; i++) {
NMActiveConnection *candidate = g_ptr_array_index (active_cons, i);
path = nm_active_connection_get_connection (candidate);
/* Get devices of the active connection */
dev_str = g_string_new (NULL);
devices = nm_active_connection_get_devices (active);
- for (i = 0; devices && (i < devices->len); i++) {
+ for (i = 0; i < devices->len; i++) {
NMDevice *device = g_ptr_array_index (devices, i);
const char *dev_iface = nm_device_get_iface (device);
g_return_val_if_fail (*device == NULL, NULL);
connections = nm_client_get_active_connections (nmc->client);
- for (i = 0; connections && (i < connections->len); i++) {
+ for (i = 0; i < connections->len; i++) {
NMActiveConnection *candidate = g_ptr_array_index (connections, i);
const GPtrArray *devices;
devices = nm_active_connection_get_devices (candidate);
- if (!devices || !devices->len)
+ if (!devices->len)
continue;
if (nm_active_connection_get_default (candidate)) {
NMDevice *found_device = NULL;
const GPtrArray *devices = nm_client_get_devices (nmc->client);
- for (i = 0; devices && (i < devices->len) && !found_device; i++) {
+ for (i = 0; i < devices->len && !found_device; i++) {
NMDevice *dev = g_ptr_array_index (devices, i);
if (iface) {
const GPtrArray *aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (dev));
found_device = NULL; /* Mark as not found; set to the device again later, only if AP matches */
- for (j = 0; aps && (j < aps->len); j++) {
+ for (j = 0; j < aps->len; j++) {
NMAccessPoint *candidate_ap = g_ptr_array_index (aps, j);
const char *candidate_bssid = nm_access_point_get_bssid (candidate_ap);
const GPtrArray *nsps = nm_device_wimax_get_nsps (NM_DEVICE_WIMAX (dev));
found_device = NULL; /* Mark as not found; set to the device again later, only if NSP matches */
- for (j = 0; nsps && (j < nsps->len); j++) {
+ for (j = 0; j < nsps->len; j++) {
NMWimaxNsp *candidate_nsp = g_ptr_array_index (nsps, j);
const char *candidate_name = nm_wimax_nsp_get_name (candidate_nsp);
NMDevice *device;
devices = nm_active_connection_get_devices (active);
- device = devices && devices->len ? g_ptr_array_index (devices, 0) : NULL;
+ device = devices->len ? g_ptr_array_index (devices, 0) : NULL;
if ( device
&& ( NM_IS_DEVICE_BOND (device)
|| NM_IS_DEVICE_TEAM (device)
if (!device) {
/* device could be NULL for virtual devices. Fill it here. */
ac_devs = nm_active_connection_get_devices (active);
- info->device = device = ac_devs && ac_devs->len > 0 ? g_ptr_array_index (ac_devs, 0) : NULL;
+ info->device = device = ac_devs->len > 0 ? g_ptr_array_index (ac_devs, 0) : NULL;
}
if (nmc->nowait_flag || state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) {
char *ret;
devices = nm_client_get_devices (nmc_tab_completion.nmc->client);
- if (!devices || devices->len < 1)
+ if (devices->len == 0)
return NULL;
compatible_devices = g_new (const char *, devices->len + 1);
if (!error) {
if (!device) {
ac_devs = nm_active_connection_get_devices (active);
- device = ac_devs && ac_devs->len > 0 ? g_ptr_array_index (ac_devs, 0) : NULL;
+ device = ac_devs->len > 0 ? g_ptr_array_index (ac_devs, 0) : NULL;
}
if (device) {
monitor_ac_info = g_malloc0 (sizeof (AddConnectionInfo));
nmc->get_client (nmc);
devices = nm_client_get_devices (nmc->client);
- for (i = 0; devices && (i < devices->len); i++) {
+ for (i = 0; i < devices->len; i++) {
NMDevice *dev = g_ptr_array_index (devices, i);
if (NM_IS_DEVICE_ETHERNET (dev))
return nm_device_get_iface (dev);
NMDevice **sorted;
devs = nm_client_get_devices (client);
- if (!devs) {
- sorted = g_new (NMDevice *, 1);
- sorted[0] = NULL;
- return sorted;
- }
sorted = g_new (NMDevice *, devs->len + 1);
memcpy (sorted, devs->pdata, devs->len * sizeof (NMDevice *));
ac_uuid = nm_active_connection_get_uuid (ac);
avail_cons = nm_device_get_available_connections (device);
- for (i = 0; avail_cons && (i < avail_cons->len); i++) {
+ for (i = 0; i < avail_cons->len; i++) {
NMRemoteConnection *candidate = g_ptr_array_index (avail_cons, i);
const char *test_uuid = nm_connection_get_uuid (NM_CONNECTION (candidate));
info->active_bssid = active_bssid;
info->device = nm_device_get_iface (device);
aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (device));
- if (aps && aps->len)
- g_ptr_array_foreach ((GPtrArray *) aps, fill_output_access_point, (gpointer) info);
+ g_ptr_array_foreach ((GPtrArray *) aps, fill_output_access_point, (gpointer) info);
g_free (info);
print_data (nmc); /* Print all data */
was_output = TRUE;
g_ptr_array_add (nmc->output_data, arr);
nsps = nm_device_wimax_get_nsps (NM_DEVICE_WIMAX (device));
- for (g = 0; nsps && g < nsps->len; g++) {
+ for (g = 0; g < nsps->len; g++) {
NMWimaxNsp *nsp = g_ptr_array_index (nsps, g);
fill_output_wimax_nsp (nsp, nmc, device, idx++, NMC_OF_FLAG_SECTION_PREFIX);
bond_slaves_str = g_string_new (NULL);
slaves = nm_device_bond_get_slaves (NM_DEVICE_BOND (device));
- for (idx = 0; slaves && idx < slaves->len; idx++) {
+ for (idx = 0; idx < slaves->len; idx++) {
NMDevice *slave = g_ptr_array_index (slaves, idx);
const char *iface = nm_device_get_iface (slave);
/* available-connections */
avail_cons = nm_device_get_available_connections (device);
ac_paths_str = g_string_new (NULL);
- if (avail_cons && avail_cons->len) {
+ if (avail_cons->len) {
ac_arr = g_new (char *, avail_cons->len + 1);
ac_arr[avail_cons->len] = NULL;
}
- for (i = 0; avail_cons && (i < avail_cons->len); i++) {
+ for (i = 0; i < avail_cons->len; i++) {
NMRemoteConnection *avail_con = g_ptr_array_index (avail_cons, i);
const char *ac_path = nm_connection_get_path (NM_CONNECTION (avail_con));
const char *ac_id = nm_connection_get_id (NM_CONNECTION (avail_con));
} else {
g_assert (active);
devices = nm_active_connection_get_devices (active);
- if (!devices || devices->len == 0) {
+ if (devices->len == 0) {
g_string_printf (nmc->return_text, _("Error: Device activation failed: device was disconnected"));
nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION;
quit ();
info->active_bssid = active_bssid;
info->device = nm_device_get_iface (device);
aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (device));
- if (aps && aps->len)
- g_ptr_array_foreach ((GPtrArray *) aps, fill_output_access_point, (gpointer) info);
+ g_ptr_array_foreach ((GPtrArray *) aps, fill_output_access_point, (gpointer) info);
print_data (nmc); /* Print all data */
nmc_empty_output_fields (nmc);
if (bssid_user) {
/* Specific AP requested - list only that */
aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (device));
- for (j = 0; aps && (j < aps->len); j++) {
+ for (j = 0; j < aps->len; j++) {
char *bssid_up;
NMAccessPoint *candidate_ap = g_ptr_array_index (aps, j);
const char *candidate_bssid = nm_access_point_get_bssid (candidate_ap);
g_ptr_array_add (nmc->output_data, arr);
aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (dev));
- for (j = 0; aps && (j < aps->len); j++) {
+ for (j = 0; j < aps->len; j++) {
char *bssid_up;
NMAccessPoint *candidate_ap = g_ptr_array_index (aps, j);
const char *candidate_bssid = nm_access_point_get_bssid (candidate_ap);
NMDevice *device = NULL;
int i;
- for (i = *idx; devices && (i < devices->len); i++) {
+ for (i = *idx; i < devices->len; i++) {
NMDevice *candidate = g_ptr_array_index (devices, i);
const char *dev_iface = nm_device_get_iface (candidate);
g_return_val_if_fail ((bssid && !ssid) || (!bssid && ssid), NULL);
aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (device));
- for (i = 0; aps && (i < aps->len); i++) {
+ for (i = 0; i < aps->len; i++) {
NMAccessPoint *candidate_ap = g_ptr_array_index (aps, i);
if (ssid) {
g_ptr_array_add (nmc->output_data, arr);
nsps = nm_device_wimax_get_nsps (NM_DEVICE_WIMAX (device));
- for (i = 0; nsps && i < nsps->len; i++) {
+ for (i = 0; i < nsps->len; i++) {
NMWimaxNsp *nsp = g_ptr_array_index (nsps, i);
fill_output_wimax_nsp (nsp, nmc, device, idx++, 0);
devices = nm_client_get_devices (nmc->client);
if (ifname) {
/* Device specified - list only NSPs of this interface */
- for (i = 0; devices && (i < devices->len); i++) {
+ for (i = 0; i < devices->len; i++) {
NMDevice *candidate = g_ptr_array_index (devices, i);
const char *dev_iface = nm_device_get_iface (candidate);
if (nsp_user) {
/* Specific NSP requested - list only that */
nsps = nm_device_wimax_get_nsps (NM_DEVICE_WIMAX (device));
- for (j = 0, nsp = NULL; nsps && (j < nsps->len); j++) {
+ for (j = 0, nsp = NULL; j < nsps->len; j++) {
NMWimaxNsp *candidate_nsp = g_ptr_array_index (nsps, j);
const char *candidate_name = nm_wimax_nsp_get_name (candidate_nsp);
char *nsp_up;
/* List NSPs for all devices */
if (nsp_user) {
/* Specific NSP requested - list only that */
- for (i = 0; devices && (i < devices->len); i++) {
+ for (i = 0; i < devices->len; i++) {
NMDevice *dev = g_ptr_array_index (devices, i);
int idx = 1;
g_ptr_array_add (nmc->output_data, arr);
nsps = nm_device_wimax_get_nsps (NM_DEVICE_WIMAX (dev));
- for (j = 0, nsp = NULL; nsps && (j < nsps->len); j++) {
+ for (j = 0, nsp = NULL; j < nsps->len; j++) {
NMWimaxNsp *candidate_nsp = g_ptr_array_index (nsps, j);
const char *candidate_name = nm_wimax_nsp_get_name (candidate_nsp);
char *nsp_up;
goto error;
}
} else {
- for (i = 0; devices && (i < devices->len); i++) {
+ for (i = 0; i < devices->len; i++) {
NMDevice *dev = g_ptr_array_index (devices, i);
/* Main header name */
nm_cli.get_client (&nm_cli);
devices = nm_client_get_devices (nm_cli.client);
- if (!devices || devices->len < 1)
+ if (devices->len == 0)
return NULL;
ifnames = g_new (const char *, devices->len + 1);
int i;
aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (nmtdev->device));
- if (!aps)
+ if (!aps->len)
return;
seen_ssids = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
int i;
path = nm_connection_get_path (conn);
- for (i = 0; acs && i < acs->len; i++) {
+ for (i = 0; i < acs->len; i++) {
ac = acs->pdata[i];
ac_path = nm_active_connection_get_connection (ac);
connections = nm_remote_settings_list_connections (nm_settings);
nmt_devices = NULL;
- if (devices) {
- names = nm_device_disambiguate_names ((NMDevice **) devices->pdata, devices->len);
- nmt_devices = append_nmt_devices_for_devices (nmt_devices, devices, names, connections);
- g_strfreev (names);
- }
+
+ names = nm_device_disambiguate_names ((NMDevice **) devices->pdata, devices->len);
+ nmt_devices = append_nmt_devices_for_devices (nmt_devices, devices, names, connections);
+ g_strfreev (names);
+
nmt_devices = append_nmt_devices_for_virtual_devices (nmt_devices, connections);
nmt_devices = append_nmt_devices_for_vpns (nmt_devices, connections);
int i;
devices = nm_client_get_devices (nm_client);
- if (!devices)
- return NULL;
-
for (i = 0; i < devices->len && !device; i++) {
NMDevice *candidate = devices->pdata[i];
int i;
devices = nm_client_get_devices (nm_client);
- if (!devices)
- return NULL;
-
for (i = 0; i < devices->len && !device; i++) {
NMDevice *candidate = devices->pdata[i];
char *hwaddr;
aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (device));
/* Print AP details */
- for (i = 0; aps && (i < aps->len); i++) {
+ for (i = 0; i < aps->len; i++) {
NMAccessPoint *ap = g_ptr_array_index (aps, i);
show_access_point_info (ap);
}
devices = nm_client_get_devices (client);
/* Go through the array and process Wi-Fi devices */
- for (i = 0; devices && (i < devices->len); i++) {
+ for (i = 0; i < devices->len; i++) {
NMDevice *device = g_ptr_array_index (devices, i);
if (NM_IS_DEVICE_WIFI (device))
show_wifi_device_info (device);
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
- return handle_ptr_array_return (NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->devices);
+ return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->devices;
}
/**
{
g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
- return handle_ptr_array_return (NM_CLIENT_GET_PRIVATE (client)->devices);
+ return NM_CLIENT_GET_PRIVATE (client)->devices;
}
/**
ainfo = info;
}
- for (i = 0; active_connections && i < active_connections->len; i++) {
+ for (i = 0; i < active_connections->len; i++) {
NMActiveConnection *active = g_ptr_array_index (active_connections, i);
const char *active_path = nm_object_get_path (NM_OBJECT (active));
if (!nm_client_get_nm_running (client))
return NULL;
- return handle_ptr_array_return (priv->active_connections);
+ return priv->active_connections;
}
/**
{
g_return_val_if_fail (NM_IS_DEVICE_BOND (device), FALSE);
- return handle_ptr_array_return (NM_DEVICE_BOND_GET_PRIVATE (device)->slaves);
+ return NM_DEVICE_BOND_GET_PRIVATE (device)->slaves;
}
static gboolean
{
g_return_val_if_fail (NM_IS_DEVICE_BRIDGE (device), FALSE);
- return handle_ptr_array_return (NM_DEVICE_BRIDGE_GET_PRIVATE (device)->slaves);
+ return NM_DEVICE_BRIDGE_GET_PRIVATE (device)->slaves;
}
static gboolean
{
g_return_val_if_fail (NM_IS_DEVICE_TEAM (device), FALSE);
- return handle_ptr_array_return (NM_DEVICE_TEAM_GET_PRIVATE (device)->slaves);
+ return NM_DEVICE_TEAM_GET_PRIVATE (device)->slaves;
}
static const char *
{
g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), NULL);
- return handle_ptr_array_return (NM_DEVICE_WIFI_GET_PRIVATE (device)->aps);
+ return NM_DEVICE_WIFI_GET_PRIVATE (device)->aps;
}
/**
{
g_return_val_if_fail (NM_IS_DEVICE_WIMAX (wimax), NULL);
- return handle_ptr_array_return (NM_DEVICE_WIMAX_GET_PRIVATE (wimax)->nsps);
+ return NM_DEVICE_WIMAX_GET_PRIVATE (wimax)->nsps;
}
/**
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
- return handle_ptr_array_return (NM_DEVICE_GET_PRIVATE (device)->available_connections);
+ return NM_DEVICE_GET_PRIVATE (device)->available_connections;
}
static char *
const char *prop_name,
GValue *value);
-static inline const GPtrArray *
-handle_ptr_array_return (GPtrArray *array)
-{
- /* zero-length is special-case; return NULL */
- if (!array || !array->len)
- return NULL;
- return array;
-}
-
/* object demarshalling support */
typedef GType (*NMObjectTypeFunc) (DBusGConnection *, const char *);
typedef void (*NMObjectTypeCallbackFunc) (GType, gpointer);
client = test_client_new ();
devices = nm_client_get_devices (client);
- g_assert (devices == NULL);
+ g_assert (devices->len == 0);
/* Tell the test service to add a new device */
add_device ("AddWiredDevice", "eth0", NULL);
const GPtrArray *aps;
aps = nm_device_wifi_get_access_points (w);
- g_assert (aps == NULL);
+ g_assert (aps->len == 0);
info->notified = TRUE;
wifi_check_quit (info);
const GPtrArray *nsps;
nsps = nm_device_wimax_get_nsps (w);
- g_assert (nsps == NULL);
+ g_assert (nsps->len == 0);
info->notified = TRUE;
wimax_check_quit (info);