diff options
Diffstat (limited to 'libnm-glib')
| -rw-r--r-- | libnm-glib/nm-access-point.c | 49 | ||||
| -rw-r--r-- | libnm-glib/nm-access-point.h | 4 | ||||
| -rw-r--r-- | libnm-glib/nm-active-connection.h | 4 | ||||
| -rw-r--r-- | libnm-glib/nm-client.h | 2 | ||||
| -rw-r--r-- | libnm-glib/nm-device.c | 95 | ||||
| -rw-r--r-- | libnm-glib/nm-dhcp4-config.c | 3 | ||||
| -rw-r--r-- | libnm-glib/nm-dhcp6-config.c | 3 | ||||
| -rw-r--r-- | libnm-glib/nm-ip4-config.c | 3 | ||||
| -rw-r--r-- | libnm-glib/nm-ip6-config.c | 3 | ||||
| -rw-r--r-- | libnm-glib/nm-object.c | 23 | ||||
| -rw-r--r-- | libnm-glib/nm-object.h | 2 | ||||
| -rw-r--r-- | libnm-glib/nm-remote-connection.c | 2 | ||||
| -rw-r--r-- | libnm-glib/nm-remote-connection.h | 2 | ||||
| -rw-r--r-- | libnm-glib/nm-remote-settings.c | 2 | ||||
| -rw-r--r-- | libnm-glib/nm-remote-settings.h | 4 | ||||
| -rw-r--r-- | libnm-glib/nm-secret-agent.c | 2 | ||||
| -rw-r--r-- | libnm-glib/nm-secret-agent.h | 2 | ||||
| -rw-r--r-- | libnm-glib/nm-types.h | 2 | ||||
| -rw-r--r-- | libnm-glib/nm-vpn-plugin-ui-interface.h | 2 | ||||
| -rw-r--r-- | libnm-glib/nm-vpn-plugin-utils.h | 2 | ||||
| -rw-r--r-- | libnm-glib/nm-vpn-plugin.c | 2 | ||||
| -rw-r--r-- | libnm-glib/nm-vpn-plugin.h | 4 | ||||
| -rw-r--r-- | libnm-glib/nm-wimax-nsp.h | 2 |
23 files changed, 106 insertions, 113 deletions
diff --git a/libnm-glib/nm-access-point.c b/libnm-glib/nm-access-point.c index 0aef3ee4..70b98f6d 100644 --- a/libnm-glib/nm-access-point.c +++ b/libnm-glib/nm-access-point.c @@ -24,11 +24,11 @@ #include <string.h> #include <netinet/ether.h> -#include <nm-connection.h> -#include <nm-setting-connection.h> -#include <nm-setting-wireless.h> -#include <nm-setting-wireless-security.h> -#include <nm-utils.h> +#include "nm-connection.h" +#include "nm-setting-connection.h" +#include "nm-setting-wireless.h" +#include "nm-setting-wireless-security.h" +#include "nm-utils.h" #include "nm-access-point.h" #include "NetworkManager.h" @@ -309,16 +309,17 @@ nm_access_point_connection_valid (NMAccessPoint *ap, NMConnection *connection) const GByteArray *setting_ssid; const GByteArray *ap_ssid; const GByteArray *setting_bssid; - struct ether_addr *ap_bssid; const char *setting_mode; NM80211Mode ap_mode; const char *setting_band; guint32 ap_freq, setting_chan, ap_chan; s_con = nm_connection_get_setting_connection (connection); - g_assert (s_con); + if (!s_con) + return FALSE; + ctype = nm_setting_connection_get_connection_type (s_con); - if (strcmp (ctype, NM_SETTING_WIRELESS_SETTING_NAME) != 0) + if (!ctype || !nm_streq (ctype, NM_SETTING_WIRELESS_SETTING_NAME)) return FALSE; s_wifi = nm_connection_get_setting_wireless (connection); @@ -327,30 +328,34 @@ nm_access_point_connection_valid (NMAccessPoint *ap, NMConnection *connection) /* SSID checks */ ap_ssid = nm_access_point_get_ssid (ap); - g_warn_if_fail (ap_ssid != NULL); - setting_ssid = nm_setting_wireless_get_ssid (s_wifi); - if (!setting_ssid || !ap_ssid || (setting_ssid->len != ap_ssid->len)) + if (!ap_ssid) return FALSE; - if (memcmp (setting_ssid->data, ap_ssid->data, ap_ssid->len) != 0) + setting_ssid = nm_setting_wireless_get_ssid (s_wifi); + if ( !setting_ssid + || setting_ssid->len != ap_ssid->len + || memcmp (setting_ssid->data, ap_ssid->data, ap_ssid->len) != 0) return FALSE; /* BSSID checks */ ap_bssid_str = nm_access_point_get_bssid (ap); - g_warn_if_fail (ap_bssid_str); + if (!ap_bssid_str) + return FALSE; setting_bssid = nm_setting_wireless_get_bssid (s_wifi); - if (setting_bssid && ap_bssid_str) { - g_assert (setting_bssid->len == ETH_ALEN); - ap_bssid = ether_aton (ap_bssid_str); - g_warn_if_fail (ap_bssid); - if (ap_bssid) { - if (memcmp (ap_bssid->ether_addr_octet, setting_bssid->data, ETH_ALEN) != 0) - return FALSE; - } + if (setting_bssid) { + struct ether_addr addr; + + g_return_val_if_fail (setting_bssid->len == ETH_ALEN, FALSE); + + if (!ether_aton_r (ap_bssid_str, &addr)) + return FALSE; + if (memcmp (addr.ether_addr_octet, setting_bssid->data, ETH_ALEN) != 0) + return FALSE; } /* Mode */ ap_mode = nm_access_point_get_mode (ap); - g_warn_if_fail (ap_mode != NM_802_11_MODE_UNKNOWN); + if (ap_mode == NM_802_11_MODE_UNKNOWN) + return FALSE; setting_mode = nm_setting_wireless_get_mode (s_wifi); if (setting_mode && ap_mode) { if (!strcmp (setting_mode, "infrastructure") && (ap_mode != NM_802_11_MODE_INFRA)) diff --git a/libnm-glib/nm-access-point.h b/libnm-glib/nm-access-point.h index 7ea8f812..5750c76c 100644 --- a/libnm-glib/nm-access-point.h +++ b/libnm-glib/nm-access-point.h @@ -24,8 +24,8 @@ #include <glib.h> #include <glib-object.h> -#include <NetworkManager.h> -#include <nm-connection.h> +#include "NetworkManager.h" +#include "nm-connection.h" #include "nm-object.h" G_BEGIN_DECLS diff --git a/libnm-glib/nm-active-connection.h b/libnm-glib/nm-active-connection.h index e2941564..cdf02a94 100644 --- a/libnm-glib/nm-active-connection.h +++ b/libnm-glib/nm-active-connection.h @@ -25,8 +25,8 @@ #include <glib.h> #include <glib-object.h> #include "nm-object.h" -#include <nm-connection.h> -#include <NetworkManager.h> +#include "nm-connection.h" +#include "NetworkManager.h" #include "nm-ip4-config.h" #include "nm-dhcp4-config.h" #include "nm-ip6-config.h" diff --git a/libnm-glib/nm-client.h b/libnm-glib/nm-client.h index f10b6e54..fbbc3d92 100644 --- a/libnm-glib/nm-client.h +++ b/libnm-glib/nm-client.h @@ -26,7 +26,7 @@ #include <glib-object.h> #include <gio/gio.h> #include <dbus/dbus-glib.h> -#include <NetworkManager.h> +#include "NetworkManager.h" #include "nm-object.h" #include "nm-device.h" #include "nm-active-connection.h" diff --git a/libnm-glib/nm-device.c b/libnm-glib/nm-device.c index 48ad8897..be86a246 100644 --- a/libnm-glib/nm-device.c +++ b/libnm-glib/nm-device.c @@ -22,9 +22,11 @@ #include "nm-default.h" #include <string.h> -#include <gudev/gudev.h> +#include <libudev.h> #include "NetworkManager.h" + +#include "nm-utils/nm-udev-utils.h" #include "nm-device-ethernet.h" #include "nm-device-adsl.h" #include "nm-device-wifi.h" @@ -92,7 +94,7 @@ typedef struct { NMActiveConnection *active_connection; GPtrArray *available_connections; - GUdevClient *client; + NMUdevClient *udev_client; char *product, *short_product; char *vendor, *short_vendor; char *description, *bus_name; @@ -374,9 +376,10 @@ dispose (GObject *object) g_clear_object (&priv->dhcp4_config); g_clear_object (&priv->ip6_config); g_clear_object (&priv->dhcp6_config); - g_clear_object (&priv->client); g_clear_object (&priv->active_connection); + priv->udev_client = nm_udev_client_unref (priv->udev_client); + if (priv->available_connections) { int i; @@ -519,7 +522,7 @@ set_property (GObject *object, switch (prop_id) { case PROP_DEVICE_TYPE: - /* Construct only */ + /* construct-only */ priv->device_type = g_value_get_uint (value); break; case PROP_MANAGED: @@ -1500,43 +1503,16 @@ nm_device_get_available_connections (NMDevice *device) return handle_ptr_array_return (NM_DEVICE_GET_PRIVATE (device)->available_connections); } -static char * -get_decoded_property (GUdevDevice *device, const char *property) -{ - const char *orig, *p; - char *unescaped, *n; - guint len; - - p = orig = g_udev_device_get_property (device, property); - if (!orig) - return NULL; - - len = strlen (orig); - n = unescaped = g_malloc0 (len + 1); - while (*p) { - if ((len >= 4) && (*p == '\\') && (*(p+1) == 'x')) { - *n++ = (char) nm_utils_hex2byte (p + 2); - p += 4; - len -= 4; - } else { - *n++ = *p++; - len--; - } - } - - return unescaped; -} - static gboolean ensure_udev_client (NMDevice *device) { - static const char *const subsys[3] = { "net", "tty", NULL }; NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device); - if (!priv->client) - priv->client = g_udev_client_new (subsys); - - return priv->client != NULL; + if (!priv->udev_client) { + priv->udev_client = nm_udev_client_new ((const char *[]) { "net", "tty", NULL }, + NULL, NULL); + } + return !!priv->udev_client; } static char * @@ -1545,7 +1521,7 @@ _get_udev_property (NMDevice *device, const char *db_prop) /* ID_XXX_FROM_DATABASE */ { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device); - GUdevDevice *udev_device = NULL, *tmpdev, *olddev; + struct udev_device *udev_device, *tmpdev; const char *ifname; guint32 count = 0; char *enc_value = NULL, *db_value = NULL; @@ -1557,39 +1533,25 @@ _get_udev_property (NMDevice *device, if (!ifname) return NULL; - udev_device = g_udev_client_query_by_subsystem_and_name (priv->client, "net", ifname); - if (!udev_device) - udev_device = g_udev_client_query_by_subsystem_and_name (priv->client, "tty", ifname); - if (!udev_device) - return NULL; - + udev_device = udev_device_new_from_subsystem_sysname (nm_udev_client_get_udev (priv->udev_client), "net", ifname); + if (!udev_device) { + udev_device = udev_device_new_from_subsystem_sysname (nm_udev_client_get_udev (priv->udev_client), "tty", ifname); + if (!udev_device) + return NULL; + } /* Walk up the chain of the device and its parents a few steps to grab * vendor and device ID information off it. */ - - /* Ref the device again because we have to unref it each iteration, - * as g_udev_device_get_parent() returns a ref-ed object. - */ - tmpdev = g_object_ref (udev_device); + tmpdev = udev_device; while ((count++ < 3) && tmpdev && !enc_value) { if (!enc_value) - enc_value = get_decoded_property (tmpdev, enc_prop); + enc_value = nm_udev_utils_property_decode_cp (udev_device_get_property_value (tmpdev, enc_prop)); if (!db_value) - db_value = g_strdup (g_udev_device_get_property (tmpdev, db_prop)); + db_value = g_strdup (udev_device_get_property_value (tmpdev, db_prop)); - olddev = tmpdev; - tmpdev = g_udev_device_get_parent (tmpdev); - g_object_unref (olddev); + tmpdev = udev_device_get_parent (tmpdev); } - - /* Unref the last device if we found what we needed before running out - * of parents. - */ - if (tmpdev) - g_object_unref (tmpdev); - - /* Balance the initial g_udev_client_query_by_subsystem_and_name() */ - g_object_unref (udev_device); + udev_device_unref (udev_device); /* Prefer the encoded value which comes directly from the device * over the hwdata database value. @@ -1930,7 +1892,7 @@ static const char * get_bus_name (NMDevice *device) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device); - GUdevDevice *udevice; + struct udev_device *udevice; const char *ifname, *bus; if (priv->bus_name) @@ -1943,13 +1905,13 @@ get_bus_name (NMDevice *device) if (!ifname) return NULL; - udevice = g_udev_client_query_by_subsystem_and_name (priv->client, "net", ifname); + udevice = udev_device_new_from_subsystem_sysname (nm_udev_client_get_udev (priv->udev_client), "net", ifname); if (!udevice) - udevice = g_udev_client_query_by_subsystem_and_name (priv->client, "tty", ifname); + udevice = udev_device_new_from_subsystem_sysname (nm_udev_client_get_udev (priv->udev_client), "tty", ifname); if (!udevice) return NULL; - bus = g_udev_device_get_property (udevice, "ID_BUS"); + bus = udev_device_get_property_value (udevice, "ID_BUS"); if (!g_strcmp0 (bus, "pci")) priv->bus_name = g_strdup (_("PCI")); else if (!g_strcmp0 (bus, "usb")) @@ -1960,6 +1922,7 @@ get_bus_name (NMDevice *device) */ priv->bus_name = g_strdup (""); } + udev_device_unref (udevice); out: if (*priv->bus_name) diff --git a/libnm-glib/nm-dhcp4-config.c b/libnm-glib/nm-dhcp4-config.c index fc3491c8..4acdeae7 100644 --- a/libnm-glib/nm-dhcp4-config.c +++ b/libnm-glib/nm-dhcp4-config.c @@ -174,6 +174,9 @@ nm_dhcp4_config_class_init (NMDHCP4ConfigClass *config_class) GObject * nm_dhcp4_config_new (DBusGConnection *connection, const char *object_path) { + g_return_val_if_fail (connection != NULL, NULL); + g_return_val_if_fail (object_path != NULL, NULL); + return (GObject *) g_object_new (NM_TYPE_DHCP4_CONFIG, NM_OBJECT_DBUS_CONNECTION, connection, NM_OBJECT_DBUS_PATH, object_path, diff --git a/libnm-glib/nm-dhcp6-config.c b/libnm-glib/nm-dhcp6-config.c index 43aee15c..aebea8df 100644 --- a/libnm-glib/nm-dhcp6-config.c +++ b/libnm-glib/nm-dhcp6-config.c @@ -174,6 +174,9 @@ nm_dhcp6_config_class_init (NMDHCP6ConfigClass *config_class) GObject * nm_dhcp6_config_new (DBusGConnection *connection, const char *object_path) { + g_return_val_if_fail (connection != NULL, NULL); + g_return_val_if_fail (object_path != NULL, NULL); + return (GObject *) g_object_new (NM_TYPE_DHCP6_CONFIG, NM_OBJECT_DBUS_CONNECTION, connection, NM_OBJECT_DBUS_PATH, object_path, diff --git a/libnm-glib/nm-ip4-config.c b/libnm-glib/nm-ip4-config.c index ae7448f9..9e0e2e2d 100644 --- a/libnm-glib/nm-ip4-config.c +++ b/libnm-glib/nm-ip4-config.c @@ -330,6 +330,9 @@ nm_ip4_config_class_init (NMIP4ConfigClass *config_class) GObject * nm_ip4_config_new (DBusGConnection *connection, const char *object_path) { + g_return_val_if_fail (connection != NULL, NULL); + g_return_val_if_fail (object_path != NULL, NULL); + return (GObject *) g_object_new (NM_TYPE_IP4_CONFIG, NM_OBJECT_DBUS_CONNECTION, connection, NM_OBJECT_DBUS_PATH, object_path, diff --git a/libnm-glib/nm-ip6-config.c b/libnm-glib/nm-ip6-config.c index 320f00f2..5ec02dae 100644 --- a/libnm-glib/nm-ip6-config.c +++ b/libnm-glib/nm-ip6-config.c @@ -69,6 +69,9 @@ enum { GObject * nm_ip6_config_new (DBusGConnection *connection, const char *object_path) { + g_return_val_if_fail (connection != NULL, NULL); + g_return_val_if_fail (object_path != NULL, NULL); + return (GObject *) g_object_new (NM_TYPE_IP6_CONFIG, NM_OBJECT_DBUS_CONNECTION, connection, NM_OBJECT_DBUS_PATH, object_path, diff --git a/libnm-glib/nm-object.c b/libnm-glib/nm-object.c index c7201cda..2e07ff6d 100644 --- a/libnm-glib/nm-object.c +++ b/libnm-glib/nm-object.c @@ -175,7 +175,22 @@ constructor (GType type, priv = NM_OBJECT_GET_PRIVATE (object); - if (priv->connection == NULL || priv->path == NULL) { + if (priv->connection == NULL) { + GError *error = NULL; + + priv->connection = _nm_dbus_new_connection (&error); + + if (priv->connection == NULL) { + g_warning ("Error connecting to system bus: %s", error->message); + g_clear_error (&error); + g_object_unref (object); + return NULL; + } + } + + g_assert (priv->connection != NULL); + + if (priv->path == NULL) { g_warn_if_reached (); g_object_unref (object); return NULL; @@ -354,13 +369,11 @@ set_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_DBUS_CONNECTION: - /* Construct only */ + /* construct-only */ priv->connection = g_value_dup_boxed (value); - if (!priv->connection) - priv->connection = _nm_dbus_new_connection (NULL); break; case PROP_DBUS_PATH: - /* Construct only */ + /* construct-only */ priv->path = g_value_dup_string (value); break; default: diff --git a/libnm-glib/nm-object.h b/libnm-glib/nm-object.h index 07348f24..73aa9de5 100644 --- a/libnm-glib/nm-object.h +++ b/libnm-glib/nm-object.h @@ -26,7 +26,7 @@ #include <glib-object.h> #include <dbus/dbus-glib.h> -#include <nm-version.h> +#include "nm-version.h" G_BEGIN_DECLS diff --git a/libnm-glib/nm-remote-connection.c b/libnm-glib/nm-remote-connection.c index 5c07f0ec..d147365b 100644 --- a/libnm-glib/nm-remote-connection.c +++ b/libnm-glib/nm-remote-connection.c @@ -796,7 +796,7 @@ set_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_BUS: case PROP_DBUS_CONNECTION: - /* Construct only */ + /* construct-only */ /* priv->bus is set from either of two properties so that it (a) remains * backwards compatible with the previous "bus" property, and that (b) * it can be created just like an NMObject using the "dbus-connection", diff --git a/libnm-glib/nm-remote-connection.h b/libnm-glib/nm-remote-connection.h index 8292c235..5b746a44 100644 --- a/libnm-glib/nm-remote-connection.h +++ b/libnm-glib/nm-remote-connection.h @@ -25,7 +25,7 @@ #include <glib-object.h> #include <dbus/dbus-glib.h> -#include <nm-connection.h> +#include "nm-connection.h" G_BEGIN_DECLS diff --git a/libnm-glib/nm-remote-settings.c b/libnm-glib/nm-remote-settings.c index 6e90db19..3f2c50f2 100644 --- a/libnm-glib/nm-remote-settings.c +++ b/libnm-glib/nm-remote-settings.c @@ -1429,7 +1429,7 @@ set_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_BUS: - /* Construct only */ + /* construct-only */ priv->bus = g_value_dup_boxed (value); if (!priv->bus) priv->bus = _nm_dbus_new_connection (NULL); diff --git a/libnm-glib/nm-remote-settings.h b/libnm-glib/nm-remote-settings.h index 92049ade..af6cc603 100644 --- a/libnm-glib/nm-remote-settings.h +++ b/libnm-glib/nm-remote-settings.h @@ -24,8 +24,8 @@ #include <gio/gio.h> #include <dbus/dbus-glib.h> -#include <nm-connection.h> -#include <nm-remote-connection.h> +#include "nm-connection.h" +#include "nm-remote-connection.h" G_BEGIN_DECLS diff --git a/libnm-glib/nm-secret-agent.c b/libnm-glib/nm-secret-agent.c index aeb7a208..75129e06 100644 --- a/libnm-glib/nm-secret-agent.c +++ b/libnm-glib/nm-secret-agent.c @@ -304,7 +304,7 @@ verify_request (NMSecretAgent *self, { NMConnection *connection = NULL; - g_return_val_if_fail (out_connection, FALSE); + g_return_val_if_fail (!connection_hash || out_connection, FALSE); if (!verify_sender (self, context, error)) return FALSE; diff --git a/libnm-glib/nm-secret-agent.h b/libnm-glib/nm-secret-agent.h index b7df8745..621e5e7b 100644 --- a/libnm-glib/nm-secret-agent.h +++ b/libnm-glib/nm-secret-agent.h @@ -21,7 +21,7 @@ #ifndef NM_SECRET_AGENT_H #define NM_SECRET_AGENT_H -#include <nm-connection.h> +#include "nm-connection.h" G_BEGIN_DECLS diff --git a/libnm-glib/nm-types.h b/libnm-glib/nm-types.h index 81bd299e..9b58cd81 100644 --- a/libnm-glib/nm-types.h +++ b/libnm-glib/nm-types.h @@ -24,7 +24,7 @@ #include <glib.h> #include <glib-object.h> -#include <nm-glib-enum-types.h> +#include "nm-glib-enum-types.h" G_BEGIN_DECLS diff --git a/libnm-glib/nm-vpn-plugin-ui-interface.h b/libnm-glib/nm-vpn-plugin-ui-interface.h index 37fde91f..b5ea2a7e 100644 --- a/libnm-glib/nm-vpn-plugin-ui-interface.h +++ b/libnm-glib/nm-vpn-plugin-ui-interface.h @@ -24,7 +24,7 @@ #include <glib.h> #include <glib-object.h> -#include <nm-connection.h> +#include "nm-connection.h" G_BEGIN_DECLS diff --git a/libnm-glib/nm-vpn-plugin-utils.h b/libnm-glib/nm-vpn-plugin-utils.h index d87ef16a..dfb621ca 100644 --- a/libnm-glib/nm-vpn-plugin-utils.h +++ b/libnm-glib/nm-vpn-plugin-utils.h @@ -22,7 +22,7 @@ #define NM_VPN_PLUGIN_UTILS_H #include <glib.h> -#include <nm-setting.h> +#include "nm-setting.h" G_BEGIN_DECLS diff --git a/libnm-glib/nm-vpn-plugin.c b/libnm-glib/nm-vpn-plugin.c index 0ea30b58..4c4c3161 100644 --- a/libnm-glib/nm-vpn-plugin.c +++ b/libnm-glib/nm-vpn-plugin.c @@ -799,7 +799,7 @@ set_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_DBUS_SERVICE_NAME: - /* Construct-only */ + /* construct-only */ priv->dbus_service_name = g_value_dup_string (value); break; case PROP_STATE: diff --git a/libnm-glib/nm-vpn-plugin.h b/libnm-glib/nm-vpn-plugin.h index 323017f0..a33349a1 100644 --- a/libnm-glib/nm-vpn-plugin.h +++ b/libnm-glib/nm-vpn-plugin.h @@ -25,8 +25,8 @@ #include <glib.h> #include <glib-object.h> #include <dbus/dbus-glib.h> -#include <NetworkManagerVPN.h> -#include <nm-connection.h> +#include "NetworkManagerVPN.h" +#include "nm-connection.h" G_BEGIN_DECLS diff --git a/libnm-glib/nm-wimax-nsp.h b/libnm-glib/nm-wimax-nsp.h index 74008d18..336f331d 100644 --- a/libnm-glib/nm-wimax-nsp.h +++ b/libnm-glib/nm-wimax-nsp.h @@ -24,7 +24,7 @@ #include <glib.h> #include <glib-object.h> -#include <NetworkManager.h> +#include "NetworkManager.h" #include "nm-object.h" G_BEGIN_DECLS |