diff options
60 files changed, 1609 insertions, 859 deletions
@@ -1,3 +1,28 @@ +2007-02-16 Tambet Ingo <tambet@ximian.com> + + * introspection/nm-ip4-config.xml: Implement. + + * libnm-glib/libnm-glib-test.c: Use new DBUS API in tests. + + * libnm-glib/nm-ip4-config.c: + * libnm-glib/nm-ip4-config.c: Implement. + + * src/nm-ap-security[-*]: Remove circular dependencies between APs and AP + securities. APs reference security. + + * src/nm-device-802-11-wireless.c: Implement missing properties that need to + be exported over DBUS. + + * src/nm-device-802-3-ethernet.c: Ditto. + + * src/NetworkManagerAP.c: + * src/NetworkManagerAP.h: + - Convert to GObject, export over DBUS. + + * src/nm-ip4-config.h: + * src/nm-ip4-config.h: + - Convert to GObject, export over DBUS. + 2007-02-12 Dan Williams <dcbw@redhat.com> Patch from Helmut Schaa <hschaa@suse.de> diff --git a/dispatcher-daemon/Makefile.am b/dispatcher-daemon/Makefile.am index 8c4c3051e7..980fd8f453 100644 --- a/dispatcher-daemon/Makefile.am +++ b/dispatcher-daemon/Makefile.am @@ -7,6 +7,7 @@ sbin_PROGRAMS = NetworkManagerDispatcher NetworkManagerDispatcher_CPPFLAGS = \ $(DBUS_CFLAGS) \ $(GTHREAD_CFLAGS) \ + -I$(top_builddir)/libnm-glib \ -Wall \ -DDBUS_API_SUBJECT_TO_CHANGE \ -DBINDIR=\"$(bindir)\" \ @@ -18,7 +19,8 @@ NetworkManagerDispatcher_CPPFLAGS = \ NetworkManagerDispatcher_SOURCES = NetworkManagerDispatcher.c NetworkManagerDispatcher_LDADD = \ - $(DBUS_LIBS) \ - $(GTHREAD_LIBS) \ - $(top_builddir)/utils/libnmutils.la + $(DBUS_LIBS) \ + $(GTHREAD_LIBS) \ + $(top_builddir)/utils/libnmutils.la \ + $(top_builddir)/libnm-glib/libnm-glib.la diff --git a/dispatcher-daemon/NetworkManagerDispatcher.c b/dispatcher-daemon/NetworkManagerDispatcher.c index 8f1d366398..f062dcb603 100644 --- a/dispatcher-daemon/NetworkManagerDispatcher.c +++ b/dispatcher-daemon/NetworkManagerDispatcher.c @@ -37,22 +37,14 @@ #include "NetworkManager.h" #include "nm-utils.h" - - -enum NMDAction -{ - NMD_DEVICE_DONT_KNOW, - NMD_DEVICE_NOW_INACTIVE, - NMD_DEVICE_NOW_ACTIVE, -}; -typedef enum NMDAction NMDAction; +#include "nm-client.h" #define NM_SCRIPT_DIR SYSCONFDIR"/NetworkManager/dispatcher.d" #define NMD_DEFAULT_PID_FILE LOCALSTATEDIR"/run/NetworkManagerDispatcher.pid" -static DBusConnection *nmd_dbus_init (void); +GHashTable *device_signals_hash; /* * nmd_permission_check @@ -66,7 +58,8 @@ static DBusConnection *nmd_dbus_init (void); * - Executable by the owner. * */ -static inline gboolean nmd_permission_check (struct stat *s) +static inline gboolean +nmd_permission_check (struct stat *s) { if (!S_ISREG (s->st_mode)) return FALSE; @@ -86,19 +79,22 @@ static inline gboolean nmd_permission_check (struct stat *s) * Call scripts in /etc/NetworkManager.d when devices go down or up * */ -static void nmd_execute_scripts (NMDAction action, char *iface_name) +static void +nmd_execute_scripts (NMDeviceState state, char *iface_name) { GDir * dir; const char * file_name; const char * char_act; - if (action == NMD_DEVICE_NOW_ACTIVE) + if (state == NM_DEVICE_STATE_ACTIVATED) char_act = "up"; - else if (action == NMD_DEVICE_NOW_INACTIVE) + else if (state == NM_DEVICE_STATE_DISCONNECTED) char_act = "down"; else return; + nm_info ("Device %s is now %s.", iface_name, char_act); + if (!(dir = g_dir_open (NM_SCRIPT_DIR, 0, NULL))) { nm_warning ("nmd_execute_scripts(): opendir() could not open '" NM_SCRIPT_DIR "'. errno = %d", errno); @@ -107,7 +103,7 @@ static void nmd_execute_scripts (NMDAction action, char *iface_name) while ((file_name = g_dir_read_name (dir))) { - char * file_path = g_strdup_printf (NM_SCRIPT_DIR"/%s", file_name); + char *file_path = g_build_filename (NM_SCRIPT_DIR, file_name, NULL); struct stat s; if ((file_name[0] != '.') && (stat (file_path, &s) == 0)) @@ -131,182 +127,56 @@ static void nmd_execute_scripts (NMDAction action, char *iface_name) g_dir_close (dir); } - -/* - * nmd_get_device_name - * - * Queries NetworkManager for the name of a device, specified by a device path - */ -static char * nmd_get_device_name (DBusConnection *connection, char *path) +static void +device_state_changed (NMDevice *device, NMDeviceState state, gpointer user_data) { - DBusMessage * message; - DBusMessage * reply; - DBusError error; - char * dbus_dev_name = NULL; - char * dev_name = NULL; + if (state == NM_DEVICE_STATE_ACTIVATED || state == NM_DEVICE_STATE_DISCONNECTED) { + char *iface; - if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, path, NM_DBUS_INTERFACE, "getName"))) - { - nm_warning ("Couldn't allocate the dbus message"); - return NULL; - } - - dbus_error_init (&error); - reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error); - dbus_message_unref (message); - if (dbus_error_is_set (&error)) - { - nm_warning ("%s raised: %s", error.name, error.message); - dbus_error_free (&error); - return NULL; - } - - /* now analyze reply */ - if (!dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &dbus_dev_name, DBUS_TYPE_INVALID)) - { - nm_warning ("There was an error getting the device name from NetworkManager." ); - dev_name = NULL; + iface = nm_device_get_iface (device); + nmd_execute_scripts (state, iface); + g_free (iface); } - else - dev_name = g_strdup (dbus_dev_name); - - dbus_message_unref (reply); - - return dev_name; } -/* - * nmd reinit_dbus - * - * Reconnect to the system message bus if the connection was dropped. - * - */ -static gboolean nmd_reinit_dbus (gpointer user_data) -{ - if (nmd_dbus_init ()) - { - nm_info ("Successfully reconnected to the system bus."); - return FALSE; - } - else - return TRUE; -} - -/* - * nmd_dbus_filter - * - * Handles dbus messages from NetworkManager, dispatches device active/not-active messages - */ -static DBusHandlerResult nmd_dbus_filter (DBusConnection *connection, DBusMessage *message, void *user_data) +static void +device_add_listener (NMClient *client, NMDevice *device, gpointer user_data) { - const char *object_path; - DBusError error; - char *dev_object_path = NULL; - gboolean handled = FALSE; - NMDAction action = NMD_DEVICE_DONT_KNOW; - - dbus_error_init (&error); - object_path = dbus_message_get_path (message); - - if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected")) - { - dbus_connection_unref (connection); - connection = NULL; - g_timeout_add (3000, nmd_reinit_dbus, NULL); - handled = TRUE; - } - - if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceNoLongerActive")) - action = NMD_DEVICE_NOW_INACTIVE; - else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceNowActive")) - action = NMD_DEVICE_NOW_ACTIVE; + guint id; - if (action != NMD_DEVICE_DONT_KNOW) - { - if (dbus_message_get_args (message, &error, DBUS_TYPE_OBJECT_PATH, &dev_object_path, DBUS_TYPE_INVALID)) - { - char * dev_iface_name = NULL; - - dev_object_path = nm_dbus_unescape_object_path (dev_object_path); - if (dev_object_path) - dev_iface_name = nmd_get_device_name (connection, dev_object_path); - - if (dev_object_path && dev_iface_name) - { - nm_info ("Device %s (%s) is now %s.", dev_object_path, dev_iface_name, - (action == NMD_DEVICE_NOW_INACTIVE ? "down" : - (action == NMD_DEVICE_NOW_ACTIVE ? "up" : "error"))); + if (!g_hash_table_lookup (device_signals_hash, device)) { + id = g_signal_connect (device, "state-changed", + G_CALLBACK (device_state_changed), + NULL); - nmd_execute_scripts (action, dev_iface_name); - } - - g_free (dev_object_path); - g_free (dev_iface_name); - - handled = TRUE; - } + g_hash_table_insert (device_signals_hash, g_object_ref (device), GUINT_TO_POINTER (id)); } - - return (handled ? DBUS_HANDLER_RESULT_HANDLED : DBUS_HANDLER_RESULT_NOT_YET_HANDLED); } -/* - * nmd_dbus_init - * - * Initialize a connection to NetworkManager - */ -static DBusConnection *nmd_dbus_init (void) +static void +device_remove_listener (NMClient *client, NMDevice *device, gpointer user_data) { - DBusConnection *connection = NULL; - DBusError error; + guint id; - /* connect to NetworkManager service on the system bus */ - dbus_error_init (&error); - connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error); - if (connection == NULL) - { - nm_warning ("nmd_dbus_init(): could not connect to the message bus. dbus says: '%s'", error.message); - dbus_error_free (&error); - return (NULL); + id = GPOINTER_TO_UINT (g_hash_table_lookup (device_signals_hash, device)); + if (id) { + g_signal_handler_disconnect (device, id); + g_hash_table_remove (device_signals_hash, device); } - - dbus_connection_set_exit_on_disconnect (connection, FALSE); - dbus_connection_setup_with_g_main (connection, NULL); - - if (!dbus_connection_add_filter (connection, nmd_dbus_filter, NULL, NULL)) - return (NULL); - - dbus_bus_add_match (connection, - "type='signal'," - "interface='" NM_DBUS_INTERFACE "'," - "sender='" NM_DBUS_SERVICE "'," - "path='" NM_DBUS_PATH "'", &error); - if (dbus_error_is_set (&error)) - return (NULL); - - return (connection); } -/* - * nmd_print_usage - * - * Prints program usage. - * - */ -static void nmd_print_usage (void) +static void +add_existing_device_listeners (NMClient *client) { - fprintf (stderr, "\n" "usage : NetworkManagerDispatcher [--no-daemon] [--pid-file=<file>] [--help]\n"); - fprintf (stderr, - "\n" - " --no-daemon Do not daemonize\n" - " --pid-file=<path> Specify the location of a PID file\n" - " --help Show this information and exit\n" - "\n" - "NetworkManagerDispatcher listens for device messages from NetworkManager\n" - "and runs scripts in " NM_SCRIPT_DIR "\n" - "\n"); -} + GSList *list, *iter; + list = nm_client_get_devices (client); + for (iter = list; iter; iter = iter->next) + device_add_listener (client, NM_DEVICE (iter->data), NULL); + + g_slist_foreach (list, (GFunc) g_object_unref, NULL); + g_slist_free (list); +} static void write_pidfile (const char *pidfile) @@ -331,88 +201,75 @@ write_pidfile (const char *pidfile) * main * */ -int main (int argc, char *argv[]) +int +main (int argc, char *argv[]) { - gboolean become_daemon = TRUE; - GMainLoop * loop = NULL; - DBusConnection *connection = NULL; - char * pidfile = NULL; - char * user_pidfile = NULL; - - /* Parse options */ - while (1) - { - int c; - int option_index = 0; - const char *opt; - - static struct option options[] = { - {"no-daemon", 0, NULL, 0}, - {"pid-file", 1, NULL, 0}, - {"help", 0, NULL, 0}, - {NULL, 0, NULL, 0} - }; - - c = getopt_long (argc, argv, "", options, &option_index); - if (c == -1) - break; - - switch (c) - { - case 0: - opt = options[option_index].name; - if (strcmp (opt, "help") == 0) - { - nmd_print_usage (); - return 0; - } - else if (strcmp (opt, "no-daemon") == 0) - become_daemon = FALSE; - else if (strcmp (opt, "pid-file") == 0) - user_pidfile = g_strdup (optarg); - else - { - nmd_print_usage (); - return 1; - } - break; - - default: - nmd_print_usage (); - return 1; - break; - } + GError *err = NULL; + GOptionContext *opt_ctx; + GMainLoop *loop; + int ret = EXIT_FAILURE; + NMClient *client; + gboolean no_daemon = FALSE; + char *pidfile = NMD_DEFAULT_PID_FILE; + + GOptionEntry entries[] = { + { "no-daemon", 0, 0, G_OPTION_ARG_NONE, &no_daemon, "Do not daemonize", NULL }, + { "pid-file", 0, 0, G_OPTION_ARG_FILENAME, &pidfile, "Specify the location of a PID file", "filename" }, + { NULL } + }; + + opt_ctx = g_option_context_new (NULL); + g_option_context_set_summary (opt_ctx, + "NetworkManagerDispatcher listens for device messages from NetworkManager\n" + "and runs scripts in " NM_SCRIPT_DIR); + g_option_context_add_main_entries (opt_ctx, entries, NULL); + + if (!g_option_context_parse (opt_ctx, &argc, &argv, &err)) { + g_print ("%s\n", err->message); + g_error_free (err); + goto out; } - openlog("NetworkManagerDispatcher", (become_daemon) ? LOG_CONS : LOG_CONS | LOG_PERROR, (become_daemon) ? LOG_DAEMON : LOG_USER); + openlog ("NetworkManagerDispatcher", + (no_daemon) ? LOG_CONS | LOG_PERROR : LOG_CONS, + (no_daemon) ? LOG_USER : LOG_DAEMON); - if (become_daemon) - { - if (daemon (FALSE, FALSE) < 0) - { - nm_warning ("NetworkManagerDispatcher could not daemonize: %s", strerror (errno)); - exit (1); + if (!no_daemon) { + if (daemon (FALSE, FALSE) < 0) { + nm_warning ("NetworkManagerDispatcher could not daemonize: %s", strerror (errno)); + goto out; } - pidfile = user_pidfile ? user_pidfile : NMD_DEFAULT_PID_FILE; write_pidfile (pidfile); } g_type_init (); - if (!g_thread_supported ()) - g_thread_init (NULL); - /* Connect to the NetworkManager dbus service and run the main loop */ - if ((connection = nmd_dbus_init ())) - { - loop = g_main_loop_new (NULL, FALSE); - g_main_loop_run (loop); - } + client = nm_client_new (); + if (!client) + goto out; + + device_signals_hash = g_hash_table_new_full (NULL, NULL, (GDestroyNotify) g_object_unref, NULL); + + g_signal_connect (client, "device-added", + G_CALLBACK (device_add_listener), NULL); + g_signal_connect (client, "device-removed", + G_CALLBACK (device_remove_listener), NULL); + + add_existing_device_listeners (client); + + loop = g_main_loop_new (NULL, FALSE); + g_main_loop_run (loop); + g_main_loop_unref (loop); + g_object_unref (client); + g_hash_table_destroy (device_signals_hash); + + ret = EXIT_SUCCESS; - /* Clean up pidfile */ - if (pidfile) - unlink (pidfile); - g_free (user_pidfile); + out: + g_option_context_free (opt_ctx); + closelog (); + unlink (pidfile); - return 0; + return ret; } diff --git a/introspection/nm-access-point.xml b/introspection/nm-access-point.xml index 357f1d7adf..131f37f784 100644 --- a/introspection/nm-access-point.xml +++ b/introspection/nm-access-point.xml @@ -3,13 +3,13 @@ <node name="/"> <interface name="org.freedesktop.NetworkManager.AccessPoint"> <property name="Address" type="s" access="read"/> - <property name="Capabilities" type="i" access="read"/> + <property name="Capabilities" type="u" access="read"/> <property name="Encrypted" type="b" access="read"/> <property name="Essid" type="s" access="read"/> <property name="Frequency" type="d" access="read"/> <property name="HWAddress" type="s" access="read"/> <property name="Mode" type="i" access="read"/> - <property name="Rate" type="i" access="read"/> + <property name="Rate" type="u" access="read"/> <property name="Strength" type="i" access="read"/> <signal name="StrengthChanged"> diff --git a/introspection/nm-device-802-11-wireless.xml b/introspection/nm-device-802-11-wireless.xml index 69f68f1a81..1cf8aa76b3 100644 --- a/introspection/nm-device-802-11-wireless.xml +++ b/introspection/nm-device-802-11-wireless.xml @@ -14,8 +14,9 @@ <arg name="networks" type="ao" direction="out"/> </method> - <property name="Address" type="s" access="read"/> + <property name="HwAddress" type="s" access="read"/> <property name="Mode" type="i" access="read"/> + <property name="Bitrate" type="i" access="read"/> <property name="ActiveNetwork" type="o" access="read"/> <signal name="NetworkAdded"> diff --git a/introspection/nm-device-802-3-ethernet.xml b/introspection/nm-device-802-3-ethernet.xml index 99d44a12b2..d4d4b1c189 100644 --- a/introspection/nm-device-802-3-ethernet.xml +++ b/introspection/nm-device-802-3-ethernet.xml @@ -4,7 +4,7 @@ <interface name="org.freedesktop.NetworkManager.Device.Wired"> <method name="Activate"> <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_802_3_ethernet_activate"/> - <arg name="user_requested" type="b"/> + <arg name="user_requested" type="b" direction="in"/> </method> <property name="HwAddress" type="s" access="read"/> diff --git a/introspection/nm-device.xml b/introspection/nm-device.xml index 20c033ed96..b385738566 100644 --- a/introspection/nm-device.xml +++ b/introspection/nm-device.xml @@ -12,6 +12,7 @@ <property name="Capabilities" type="i" access="read"/> <property name="Ip4Address" type="i" access="read"/> <property name="State" type="u" access="read"/> + <property name="Ip4Config" type="o" access="read"/> <!-- Ugh, but I see no other way of getting the type on the caller based on dbus object path only --> diff --git a/introspection/nm-ip4-config.xml b/introspection/nm-ip4-config.xml new file mode 100644 index 0000000000..d887068e47 --- /dev/null +++ b/introspection/nm-ip4-config.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<node name="/"> + <interface name="org.freedesktop.NetworkManager.IP4Config"> + <property name="Address" type="u" access="read"/> + <property name="Gateway" type="u" access="read"/> + <property name="Netmask" type="u" access="read"/> + <property name="Broadcast" type="u" access="read"/> + <property name="Hostname" type="s" access="read"/> + <property name="Nameservers" type="au" access="read"/> + <property name="Domains" type="as" access="read"/> + <property name="NisDomain" type="s" access="read"/> + <property name="NisServers" type="au" access="read"/> + </interface> +</node> + diff --git a/libnm-glib/Makefile.am b/libnm-glib/Makefile.am index 28f451a44a..7bb194462f 100644 --- a/libnm-glib/Makefile.am +++ b/libnm-glib/Makefile.am @@ -20,7 +20,8 @@ libnminclude_HEADERS = \ nm-device.h \ nm-device-802-3-ethernet.h \ nm-device-802-11-wireless.h \ - nm-access-point.h + nm-access-point.h \ + nm-ip4-config.h libnm_glib_la_SOURCES = \ nm-client.c \ @@ -29,6 +30,7 @@ libnm_glib_la_SOURCES = \ nm-device-802-3-ethernet.c \ nm-device-802-11-wireless.c \ nm-access-point.c \ + nm-ip4-config.c \ nm-utils.c \ nm-utils.h \ $(BUILT_SOURCES) diff --git a/libnm-glib/libnm-glib-test.c b/libnm-glib/libnm-glib-test.c index a03b3a2060..b3c67c7cbd 100644 --- a/libnm-glib/libnm-glib-test.c +++ b/libnm-glib/libnm-glib-test.c @@ -1,4 +1,9 @@ #include <stdlib.h> + +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> + #include "nm-client.h" #include "nm-device.h" #include "nm-device-802-3-ethernet.h" @@ -33,12 +38,150 @@ test_get_state (NMClient *client) return TRUE; } +static gchar * +ip4_address_as_string (guint32 ip) +{ + struct in_addr tmp_addr; + gchar *ip_string; + + tmp_addr.s_addr = ip; + ip_string = inet_ntoa (tmp_addr); + + return g_strdup (ip_string); +} + +static void +dump_ip4_config (NMIP4Config *cfg) +{ + char *tmp; + GArray *array; + char **ptr_array; + int i; + + tmp = ip4_address_as_string (nm_ip4_config_get_address (cfg)); + g_print ("IP4 address: %s\n", tmp); + g_free (tmp); + + tmp = ip4_address_as_string (nm_ip4_config_get_gateway (cfg)); + g_print ("IP4 gateway: %s\n", tmp); + g_free (tmp); + + tmp = ip4_address_as_string (nm_ip4_config_get_netmask (cfg)); + g_print ("IP4 netmask: %s\n", tmp); + g_free (tmp); + + tmp = ip4_address_as_string (nm_ip4_config_get_broadcast (cfg)); + g_print ("IP4 broadcast: %s\n", tmp); + g_free (tmp); + + tmp = nm_ip4_config_get_hostname (cfg); + g_print ("IP4 hostname: %s\n", tmp); + g_free (tmp); + + array = nm_ip4_config_get_nameservers (cfg); + if (array) { + g_print ("IP4 DNS:\n"); + for (i = 0; i < array->len; i++) { + tmp = ip4_address_as_string (g_array_index (array, guint32, i)); + g_print ("\t%s\n", tmp); + g_free (tmp); + } + + g_array_free (array, TRUE); + } + + ptr_array = nm_ip4_config_get_domains (cfg); + if (ptr_array) { + g_print ("IP4 domains:\n"); + for (i = 0; ptr_array[i]; i++) { + g_print ("\t%s\n", ptr_array[i]); + } + + g_strfreev (ptr_array); + } + + tmp = nm_ip4_config_get_nis_domain (cfg); + g_print ("IP4 NIS domain: %s\n", tmp); + g_free (tmp); + + array = nm_ip4_config_get_nis_servers (cfg); + if (array) { + g_print ("IP4 NIS servers:\n"); + for (i = 0; i < array->len; i++) { + tmp = ip4_address_as_string (g_array_index (array, guint32, i)); + g_print ("\t%s\n", tmp); + g_free (tmp); + } + + g_array_free (array, TRUE); + } +} + +static void +dump_wireless (NMDevice80211Wireless *device) +{ + char *str; + GSList *iter; + GSList *networks; + + g_print ("Mode: %d\n", nm_device_802_11_wireless_get_mode (device)); + g_print ("Bitrate: %d\n", nm_device_802_11_wireless_get_bitrate (device)); + + str = nm_device_802_11_wireless_get_hw_address (device); + g_print ("MAC: %s\n", str); + g_free (str); + + g_print ("Networks:\n"); + networks = nm_device_802_11_wireless_get_networks (device); + for (iter = networks; iter; iter = iter->next) { + NMAccessPoint *ap = NM_ACCESS_POINT (iter->data); + + str = nm_access_point_get_essid (ap); + g_print ("\tEssid: %s\n", str); + g_free (str); + + /* This is not provided by NM yet */ +#if 0 + str = nm_access_point_get_address (ap); + g_print ("\tAddress: %s\n", str); + g_free (str); + + str = nm_access_point_get_hw_address (ap); + g_print ("\tMAC Address: %s\n", str); + g_free (str); +#endif + + g_print ("\tCapabilities: %d\n", nm_access_point_get_capabilities (ap)); + g_print ("\tEncrypted: %d\n", nm_access_point_is_encrypted (ap)); + g_print ("\tFrequency: %f\n", nm_access_point_get_frequency (ap)); + + g_print ("\tMode: %d\n", nm_access_point_get_mode (ap)); + g_print ("\tRate: %d\n", nm_access_point_get_rate (ap)); + g_print ("\tStrength: %d\n", nm_access_point_get_strength (ap)); + + g_print ("\n"); + } + + g_slist_foreach (networks, (GFunc) g_object_unref, NULL); + g_slist_free (networks); +} + +static void +dump_wired (NMDevice8023Ethernet *device) +{ + char *str; + + g_print ("Speed: %d\n", nm_device_802_3_ethernet_get_speed (device)); + + str = nm_device_802_3_ethernet_get_hw_address (device); + g_print ("MAC: %s\n", str); + g_free (str); +} static void dump_device (NMDevice *device) { char *str; - gboolean b; guint32 u; NMDeviceState state; @@ -60,24 +203,16 @@ dump_device (NMDevice *device) state = nm_device_get_state (device); g_print ("State: %d\n", state); - if (NM_IS_DEVICE_802_3_ETHERNET (device)) { - int speed = nm_device_802_3_ethernet_get_speed (NM_DEVICE_802_3_ETHERNET (device)); - g_print ("Speed: %d\n", speed); - } else if (NM_IS_DEVICE_802_11_WIRELESS (device)) { - GSList *iter; - GSList *networks = nm_device_802_11_wireless_get_networks (NM_DEVICE_802_11_WIRELESS (device)); - - g_print ("Networks:\n"); - for (iter = networks; iter; iter = iter->next) { - NMAccessPoint *ap = NM_ACCESS_POINT (iter->data); - - str = nm_access_point_get_essid (ap); - g_print ("\tEssid: %s\n", str); - g_free (str); - } - g_slist_foreach (networks, (GFunc) g_object_unref, NULL); - g_slist_free (networks); + if (state == NM_DEVICE_STATE_ACTIVATED) { + NMIP4Config *cfg = nm_device_get_ip4_config (device); + dump_ip4_config (cfg); + g_object_unref (cfg); } + + if (NM_IS_DEVICE_802_3_ETHERNET (device)) + dump_wired (NM_DEVICE_802_3_ETHERNET (device)); + else if (NM_IS_DEVICE_802_11_WIRELESS (device)) + dump_wireless (NM_DEVICE_802_11_WIRELESS (device)); } static gboolean @@ -181,7 +316,7 @@ main (int argc, char *argv[]) exit (1); } - test_wireless_enabled (client); +/* test_wireless_enabled (client); */ test_get_state (client); test_devices (client); diff --git a/libnm-glib/nm-access-point.c b/libnm-glib/nm-access-point.c index 320b1121c6..0795162e66 100644 --- a/libnm-glib/nm-access-point.c +++ b/libnm-glib/nm-access-point.c @@ -1,5 +1,6 @@ #include "nm-access-point.h" #include "NetworkManager.h" +#include "nm-utils.h" #include "nm-access-point-bindings.h" @@ -43,11 +44,11 @@ nm_access_point_get_address (NMAccessPoint *ap) return address; } -int +guint32 nm_access_point_get_capabilities (NMAccessPoint *ap) { GValue value = {0,}; - int caps = 0; + guint32 caps = 0; g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), 0); @@ -55,7 +56,7 @@ nm_access_point_get_capabilities (NMAccessPoint *ap) NM_DBUS_INTERFACE_ACCESS_POINT, "Capabilities", &value)) - caps = g_value_get_int (&value); + caps = g_value_get_uint (&value); return caps; } @@ -94,9 +95,22 @@ nm_access_point_get_essid (NMAccessPoint *ap) return essid; } -double +gdouble nm_access_point_get_frequency (NMAccessPoint *ap) { + GValue value = {0,}; + double freq = 0.0; + + g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), freq); + + if (nm_dbus_get_property (DBUS_G_PROXY (ap), + NM_DBUS_INTERFACE_ACCESS_POINT, + "Frequency", + &value)) + freq = g_value_get_double (&value); + + return freq; + } char * @@ -133,11 +147,11 @@ nm_access_point_get_mode (NMAccessPoint *ap) return mode; } -int +guint32 nm_access_point_get_rate (NMAccessPoint *ap) { GValue value = {0,}; - int rate = 0; + guint32 rate = 0; g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), 0); @@ -145,7 +159,7 @@ nm_access_point_get_rate (NMAccessPoint *ap) NM_DBUS_INTERFACE_ACCESS_POINT, "Rate", &value)) - rate = g_value_get_int (&value); + rate = g_value_get_uint (&value); return rate; } diff --git a/libnm-glib/nm-access-point.h b/libnm-glib/nm-access-point.h index 13c626e4d6..9ff4c3b421 100644 --- a/libnm-glib/nm-access-point.h +++ b/libnm-glib/nm-access-point.h @@ -25,13 +25,13 @@ GType nm_access_point_get_type (void); NMAccessPoint *nm_access_point_new (DBusGConnection *connection, const char *path); char *nm_access_point_get_address (NMAccessPoint *ap); -int nm_access_point_get_capabilities (NMAccessPoint *ap); +guint32 nm_access_point_get_capabilities (NMAccessPoint *ap); gboolean nm_access_point_is_encrypted (NMAccessPoint *ap); char *nm_access_point_get_essid (NMAccessPoint *ap); -double nm_access_point_get_frequency (NMAccessPoint *ap); +gdouble nm_access_point_get_frequency (NMAccessPoint *ap); char *nm_access_point_get_hw_address (NMAccessPoint *ap); int nm_access_point_get_mode (NMAccessPoint *ap); -int nm_access_point_get_rate (NMAccessPoint *ap); +guint32 nm_access_point_get_rate (NMAccessPoint *ap); int nm_access_point_get_strength (NMAccessPoint *ap); #endif /* NM_ACCESS_POINT_H */ diff --git a/libnm-glib/nm-client.c b/libnm-glib/nm-client.c index 8a7bed2a92..cd6f55f213 100644 --- a/libnm-glib/nm-client.c +++ b/libnm-glib/nm-client.c @@ -75,7 +75,7 @@ nm_client_new (void) connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err); if (!connection) { - g_warning ("Couldn't connect to system bus: %d", err->message); + g_warning ("Couldn't connect to system bus: %s", err->message); g_error_free (err); return NULL; } diff --git a/libnm-glib/nm-device-802-11-wireless.c b/libnm-glib/nm-device-802-11-wireless.c index a8fbd71242..dcd8085eeb 100644 --- a/libnm-glib/nm-device-802-11-wireless.c +++ b/libnm-glib/nm-device-802-11-wireless.c @@ -1,5 +1,6 @@ #include "nm-device-802-11-wireless.h" #include "nm-device-private.h" +#include "nm-utils.h" #include "nm-device-802-11-wireless-bindings.h" @@ -30,7 +31,7 @@ nm_device_802_11_wireless_new (DBusGConnection *connection, const char *path) } char * -nm_device_802_11_wireless_get_address (NMDevice80211Wireless *device) +nm_device_802_11_wireless_get_hw_address (NMDevice80211Wireless *device) { GValue value = {0,}; char *address = NULL; @@ -39,7 +40,7 @@ nm_device_802_11_wireless_get_address (NMDevice80211Wireless *device) if (nm_dbus_get_property (DBUS_G_PROXY (device), NM_DBUS_INTERFACE_DEVICE_WIRELESS, - "Address", + "HwAddress", &value)) address = g_strdup (g_value_get_string (&value)); @@ -56,13 +57,30 @@ nm_device_802_11_wireless_get_mode (NMDevice80211Wireless *device) if (nm_dbus_get_property (DBUS_G_PROXY (device), NM_DBUS_INTERFACE_DEVICE_WIRELESS, - "Node", + "Mode", &value)) mode = g_value_get_int (&value); return mode; } +int +nm_device_802_11_wireless_get_bitrate (NMDevice80211Wireless *device) +{ + GValue value = {0,}; + int bitrate = 0; + + g_return_val_if_fail (NM_IS_DEVICE_802_11_WIRELESS (device), 0); + + if (nm_dbus_get_property (DBUS_G_PROXY (device), + NM_DBUS_INTERFACE_DEVICE_WIRELESS, + "Bitrate", + &value)) + bitrate = g_value_get_int (&value); + + return bitrate; +} + NMAccessPoint * nm_device_802_11_wireless_get_active_network (NMDevice80211Wireless *device) { diff --git a/libnm-glib/nm-device-802-11-wireless.h b/libnm-glib/nm-device-802-11-wireless.h index f87f966eda..0c36fb422a 100644 --- a/libnm-glib/nm-device-802-11-wireless.h +++ b/libnm-glib/nm-device-802-11-wireless.h @@ -23,10 +23,10 @@ GType nm_device_802_11_wireless_get_type (void); NMDevice80211Wireless *nm_device_802_11_wireless_new (DBusGConnection *connection, const char *path); -int nm_device_802_11_wireless_get_speed (NMDevice80211Wireless *device); -char *nm_device_802_11_wireless_get_address (NMDevice80211Wireless *device); +char *nm_device_802_11_wireless_get_hw_address (NMDevice80211Wireless *device); int nm_device_802_11_wireless_get_mode (NMDevice80211Wireless *device); +int nm_device_802_11_wireless_get_bitrate (NMDevice80211Wireless *device); NMAccessPoint *nm_device_802_11_wireless_get_active_network (NMDevice80211Wireless *device); GSList *nm_device_802_11_wireless_get_networks (NMDevice80211Wireless *device); diff --git a/libnm-glib/nm-device-802-3-ethernet.c b/libnm-glib/nm-device-802-3-ethernet.c index 5051b1aee2..a51402865f 100644 --- a/libnm-glib/nm-device-802-3-ethernet.c +++ b/libnm-glib/nm-device-802-3-ethernet.c @@ -1,5 +1,6 @@ #include "nm-device-802-3-ethernet.h" #include "nm-device-private.h" +#include "nm-utils.h" #include "nm-device-802-3-ethernet-bindings.h" @@ -47,7 +48,7 @@ nm_device_802_3_ethernet_get_speed (NMDevice8023Ethernet *device) } char * -nm_device_802_3_ethernet_get_address (NMDevice8023Ethernet *device) +nm_device_802_3_ethernet_get_hw_address (NMDevice8023Ethernet *device) { char *address = NULL; GValue value = {0,}; @@ -56,7 +57,7 @@ nm_device_802_3_ethernet_get_address (NMDevice8023Ethernet *device) if (nm_dbus_get_property (DBUS_G_PROXY (device), NM_DBUS_INTERFACE_DEVICE_WIRED, - "Address", + "HwAddress", &value)) address = g_strdup (g_value_get_string (&value)); diff --git a/libnm-glib/nm-device-802-3-ethernet.h b/libnm-glib/nm-device-802-3-ethernet.h index 7535820628..8eb58ce247 100644 --- a/libnm-glib/nm-device-802-3-ethernet.h +++ b/libnm-glib/nm-device-802-3-ethernet.h @@ -23,7 +23,7 @@ GType nm_device_802_3_ethernet_get_type (void); NMDevice8023Ethernet *nm_device_802_3_ethernet_new (DBusGConnection *connection, const char *path); int nm_device_802_3_ethernet_get_speed (NMDevice8023Ethernet *device); -char *nm_device_802_3_ethernet_get_address (NMDevice8023Ethernet *device); +char *nm_device_802_3_ethernet_get_hw_address (NMDevice8023Ethernet *device); void nm_device_802_3_ethernet_activate (NMDevice8023Ethernet *device, gboolean user_requested); diff --git a/libnm-glib/nm-device.c b/libnm-glib/nm-device.c index 6fd5e68927..6517ecb546 100644 --- a/libnm-glib/nm-device.c +++ b/libnm-glib/nm-device.c @@ -1,5 +1,6 @@ #include "nm-device.h" #include "nm-device-private.h" +#include "nm-utils.h" #include "nm-device-bindings.h" @@ -164,6 +165,30 @@ nm_device_get_ip4_address (NMDevice *device) return address; } +NMIP4Config * +nm_device_get_ip4_config (NMDevice *device) +{ + NMIP4Config *config = NULL; + GValue value = {0,}; + + g_return_val_if_fail (NM_IS_DEVICE (device), 0); + + if (nm_dbus_get_property (DBUS_G_PROXY (device), + NM_DBUS_INTERFACE_DEVICE, + "Ip4Config", + &value)) { + DBusGConnection *connection = NULL; + + g_assert (G_VALUE_TYPE (&value) == DBUS_TYPE_G_OBJECT_PATH); + + g_object_get (device, "connection", &connection, NULL); + + config = nm_ip4_config_new (connection, (const char *) g_value_get_boxed (&value)); + } + + return config; +} + NMDeviceState nm_device_get_state (NMDevice *device) { diff --git a/libnm-glib/nm-device.h b/libnm-glib/nm-device.h index dcdaf9a88c..0ca6845eaf 100644 --- a/libnm-glib/nm-device.h +++ b/libnm-glib/nm-device.h @@ -5,6 +5,7 @@ #include <glib-object.h> #include <dbus/dbus-glib.h> #include "NetworkManager.h" +#include "nm-ip4-config.h" #define NM_TYPE_DEVICE (nm_device_get_type ()) #define NM_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE, NMDevice)) @@ -34,6 +35,10 @@ char *nm_device_get_iface (NMDevice *device); char *nm_device_get_udi (NMDevice *device); char *nm_device_get_driver (NMDevice *device); guint32 nm_device_get_ip4_address (NMDevice *device); +NMIP4Config *nm_device_get_ip4_config (NMDevice *device); NMDeviceState nm_device_get_state (NMDevice *device); +NMDeviceType nm_device_type_for_path (DBusGConnection *connection, + const char *path); + #endif /* NM_DEVICE_H */ diff --git a/libnm-glib/nm-ip4-config.c b/libnm-glib/nm-ip4-config.c new file mode 100644 index 0000000000..68f99f6915 --- /dev/null +++ b/libnm-glib/nm-ip4-config.c @@ -0,0 +1,183 @@ +#include "nm-ip4-config.h" +#include "nm-device-private.h" +#include "nm-utils.h" + + +G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, DBUS_TYPE_G_PROXY) + +static void +nm_ip4_config_init (NMIP4Config *config) +{ +} + +static void +nm_ip4_config_class_init (NMIP4ConfigClass *config_class) +{ +} + +#define INTERFACE NM_DBUS_INTERFACE ".IP4Config" + +NMIP4Config * +nm_ip4_config_new (DBusGConnection *connection, const char *object_path) +{ + return (NMIP4Config *) g_object_new (NM_TYPE_IP4_CONFIG, + "name", NM_DBUS_SERVICE, + "path", object_path, + "interface", INTERFACE, + "connection", connection, + NULL); +} + +guint32 +nm_ip4_config_get_address (NMIP4Config *config) +{ + guint32 address = 0; + GValue value = {0,}; + + g_return_val_if_fail (NM_IS_IP4_CONFIG (config), 0); + + if (nm_dbus_get_property (DBUS_G_PROXY (config), + INTERFACE, + "Address", + &value)) + address = g_value_get_uint (&value); + + return address; +} + +guint32 +nm_ip4_config_get_gateway (NMIP4Config *config) +{ + guint32 gateway = 0; + GValue value = {0,}; + + g_return_val_if_fail (NM_IS_IP4_CONFIG (config), 0); + + if (nm_dbus_get_property (DBUS_G_PROXY (config), + INTERFACE, + "Gateway", + &value)) + gateway = g_value_get_uint (&value); + + return gateway; +} + +guint32 +nm_ip4_config_get_netmask (NMIP4Config *config) +{ + guint32 netmask = 0; + GValue value = {0,}; + + g_return_val_if_fail (NM_IS_IP4_CONFIG (config), 0); + + if (nm_dbus_get_property (DBUS_G_PROXY (config), + INTERFACE, + "Netmask", + &value)) + netmask = g_value_get_uint (&value); + + return netmask; +} + +guint32 +nm_ip4_config_get_broadcast (NMIP4Config *config) +{ + guint32 broadcast = 0; + GValue value = {0,}; + + g_return_val_if_fail (NM_IS_IP4_CONFIG (config), 0); + + if (nm_dbus_get_property (DBUS_G_PROXY (config), + INTERFACE, + "Broadcast", + &value)) + broadcast = g_value_get_uint (&value); + + return broadcast; +} + +char * +nm_ip4_config_get_hostname (NMIP4Config *config) +{ + char *address = NULL; + GValue value = {0,}; + + g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL); + + if (nm_dbus_get_property (DBUS_G_PROXY (config), + INTERFACE, + "Hostname", + &value)) + address = g_strdup (g_value_get_string (&value)); + + return address; +} + +GArray * +nm_ip4_config_get_nameservers (NMIP4Config *config) +{ + GArray *array = NULL; + GValue value = {0,}; + + g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL); + + if (nm_dbus_get_property (DBUS_G_PROXY (config), + INTERFACE, + "Nameservers", + &value)) + array = (GArray *) g_value_get_boxed (&value); + + return array; +} + + +char ** +nm_ip4_config_get_domains (NMIP4Config *config) +{ + char **array = NULL; + GValue value = {0,}; + + g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL); + + if (nm_dbus_get_property (DBUS_G_PROXY (config), + INTERFACE, + "Domains", + &value)) + array = (char **) g_value_get_boxed (&value); + + return array; +} + +char * +nm_ip4_config_get_nis_domain (NMIP4Config *config) +{ + char *address = NULL; + GValue value = {0,}; + + g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL); + + if (nm_dbus_get_property (DBUS_G_PROXY (config), + INTERFACE, + "NisDomain", + &value)) + address = g_strdup (g_value_get_string (&value)); + + return address; +} + +GArray * +nm_ip4_config_get_nis_servers (NMIP4Config *config) +{ + GArray *array = NULL; + GValue value = {0,}; + + g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL); + + if (nm_dbus_get_property (DBUS_G_PROXY (config), + INTERFACE, + "NisServers", + &value)) + array = (GArray *) g_value_get_boxed (&value); + + return array; +} diff --git a/libnm-glib/nm-ip4-config.h b/libnm-glib/nm-ip4-config.h new file mode 100644 index 0000000000..0c179f1e6e --- /dev/null +++ b/libnm-glib/nm-ip4-config.h @@ -0,0 +1,40 @@ +#ifndef NM_IP4_CONFIG_H +#define NM_IP4_CONFIG_H + +#include <glib/gtypes.h> +#include <glib-object.h> +#include <dbus/dbus-glib.h> +#include "NetworkManager.h" + +#define NM_TYPE_IP4_CONFIG (nm_ip4_config_get_type ()) +#define NM_IP4_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_IP4_CONFIG, NMIP4Config)) +#define NM_IP4_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_IP4_CONFIG, NMIP4ConfigClass)) +#define NM_IS_IP4_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_IP4_CONFIG)) +#define NM_IS_IP4_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_IP4_CONFIG)) +#define NM_IP4_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_IP4_CONFIG, NMIP4ConfigClass)) + +typedef struct { + DBusGProxy parent; +} NMIP4Config; + +typedef struct { + DBusGProxyClass parent; +} NMIP4ConfigClass; + +GType nm_ip4_config_get_type (void); + +NMIP4Config *nm_ip4_config_new (DBusGConnection *connection, + const char *object_path); + +guint32 nm_ip4_config_get_address (NMIP4Config *config); +guint32 nm_ip4_config_get_gateway (NMIP4Config *config); +guint32 nm_ip4_config_get_netmask (NMIP4Config *config); +guint32 nm_ip4_config_get_broadcast (NMIP4Config *config); +char *nm_ip4_config_get_hostname (NMIP4Config *config); +GArray *nm_ip4_config_get_nameservers (NMIP4Config *config); +char **nm_ip4_config_get_domains (NMIP4Config *config); +char *nm_ip4_config_get_nis_domain (NMIP4Config *config); +GArray *nm_ip4_config_get_nis_servers (NMIP4Config *config); + + +#endif /* NM_IP4_CONFIG_H */ diff --git a/src/Makefile.am b/src/Makefile.am index f1735a8443..96fec54ee5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -103,6 +103,9 @@ nm-device-802-3-ethernet-glue.h: $(top_srcdir)/introspection/nm-device-802-3-eth nm-device-802-11-wireless-glue.h: $(top_srcdir)/introspection/nm-device-802-11-wireless.xml dbus-binding-tool --prefix=nm_device_802_11_wireless --mode=glib-server --output=nm-device-802-11-wireless-glue.h $(top_srcdir)/introspection/nm-device-802-11-wireless.xml +nm-ip4-config-glue.h: $(top_srcdir)/introspection/nm-ip4-config.xml + dbus-binding-tool --prefix=nm_ip4_config --mode=glib-server --output=nm-ip4-config-glue.h $(top_srcdir)/introspection/nm-ip4-config.xml + built_sources = \ nm-marshal.h \ @@ -112,6 +115,7 @@ built_sources = \ nm-device-interface-glue.h \ nm-device-802-3-ethernet-glue.h \ nm-device-802-11-wireless-glue.h \ + nm-ip4-config-glue.h \ $(NULL) $(NetworkManager_OBJECTS): $(built_sources) diff --git a/src/NetworkManager.c b/src/NetworkManager.c index a5f61773ef..6523b239ee 100644 --- a/src/NetworkManager.c +++ b/src/NetworkManager.c @@ -154,7 +154,7 @@ nm_monitor_setup (NMData *data) * Create data structure used in callbacks from libhal. * */ -static NMData *nm_data_new (gboolean enable_test_devices) +static NMData *nm_data_new (void) { NMData * data; guint id; @@ -195,7 +195,6 @@ static NMData *nm_data_new (gboolean enable_test_devices) return NULL; } - data->enable_test_devices = enable_test_devices; data->wireless_enabled = TRUE; return data; } @@ -317,7 +316,6 @@ main (int argc, char *argv[]) { GOptionContext *opt_ctx = NULL; gboolean become_daemon = FALSE; - gboolean enable_test_devices = FALSE; gboolean show_usage = FALSE; char * pidfile = NULL; char * user_pidfile = NULL; @@ -331,8 +329,7 @@ main (int argc, char *argv[]) GOptionEntry options[] = { {"no-daemon", 0, 0, G_OPTION_ARG_NONE, &become_daemon, "Don't become a daemon", NULL}, - {"pid-file", 0, 0, G_OPTION_ARG_STRING, &user_pidfile, "Specify the location of a PID file", NULL}, - {"enable-test-devices", 0, 0, G_OPTION_ARG_NONE, &enable_test_devices, "Allow dummy devices to be created via DBUS methods [DEBUG]", NULL}, + {"pid-file", 0, 0, G_OPTION_ARG_FILENAME, &user_pidfile, "Specify the location of a PID file", "filename"}, {"info", 0, 0, G_OPTION_ARG_NONE, &show_usage, "Show application information", NULL}, {NULL} }; @@ -395,7 +392,7 @@ main (int argc, char *argv[]) nm_system_init(); /* Initialize our instance data */ - nm_data = nm_data_new (enable_test_devices); + nm_data = nm_data_new (); if (!nm_data) { nm_error ("Failed to initialize."); goto pidfile; diff --git a/src/NetworkManagerAP.c b/src/NetworkManagerAP.c index 6328b7675e..207fe03e7b 100644 --- a/src/NetworkManagerAP.c +++ b/src/NetworkManagerAP.c @@ -23,16 +23,29 @@ #include "NetworkManagerUtils.h" #include "nm-utils.h" #include "nm-ap-security.h" +#include "nm-dbus-manager.h" #include <wireless.h> +#include "wpa.h" +#include "nm-access-point-glue.h" + +/* This is a controlled list. Want to add to it? Stop. Ask first. */ +static const char * default_essid_list[] = +{ + "linksys", + "linksys-a", + "linksys-g", + "default", + "belkin54g", + "NETGEAR", + NULL +}; /* * Encapsulates Access Point information */ -struct NMAccessPoint +typedef struct { - guint refcount; - /* Scanned or cached values */ char * essid; char * orig_essid; @@ -60,37 +73,253 @@ struct NMAccessPoint NMAPSecurity * security; GTimeVal timestamp; GSList * user_addresses; +} NMAccessPointPrivate; + +#define NM_AP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_AP, NMAccessPointPrivate)) + +G_DEFINE_TYPE (NMAccessPoint, nm_ap, G_TYPE_OBJECT) + +enum { + STRENGTH_CHANGED, + + LAST_SIGNAL }; -/* This is a controlled list. Want to add to it? Stop. Ask first. */ -static const char * default_essid_list[] = -{ - "linksys", - "linksys-a", - "linksys-g", - "default", - "belkin54g", - "NETGEAR", - NULL +static guint signals[LAST_SIGNAL] = { 0 }; + +enum { + PROP_0, + PROP_ADDRESS, + PROP_CAPABILITIES, + PROP_ENCRYPTED, + PROP_ESSID, + PROP_FREQUENCY, + PROP_HWADDRESS, + PROP_MODE, + PROP_RATE, + PROP_STRENGTH, + + LAST_PROP }; +static void +nm_ap_init (NMAccessPoint *ap) +{ +} + +static void +finalize (GObject *object) +{ + NMAccessPointPrivate *priv = NM_AP_GET_PRIVATE (object); + + g_free (priv->essid); + g_free (priv->orig_essid); + g_slist_foreach (priv->user_addresses, (GFunc)g_free, NULL); + g_slist_free (priv->user_addresses); + + if (priv->security) + g_object_unref (G_OBJECT (priv->security)); + + G_OBJECT_CLASS (nm_ap_parent_class)->finalize (object); +} + +static void +set_property (GObject *object, guint prop_id, + const GValue *value, GParamSpec *pspec) +{ + NMAccessPointPrivate *priv = NM_AP_GET_PRIVATE (object); + const char *essid; + int mode; + + switch (prop_id) { + case PROP_CAPABILITIES: + priv->capabilities = g_value_get_uint (value); + break; + case PROP_ESSID: + essid = g_value_get_string (value); + + if (priv->essid) { + g_free (priv->essid); + g_free (priv->orig_essid); + priv->essid = NULL; + priv->orig_essid = NULL; + } + + if (essid) { + priv->orig_essid = g_strdup (essid); + priv->essid = nm_utils_essid_to_utf8 (essid); + } + + break; + case PROP_FREQUENCY: + priv->freq = g_value_get_double (value); + break; + case PROP_MODE: + mode = g_value_get_int (value); + + if (mode == IW_MODE_ADHOC || mode == IW_MODE_INFRA) + priv->mode = mode; + else + g_warning ("Invalid mode"); + break; + case PROP_RATE: + priv->rate = g_value_get_uint (value); + break; + case PROP_STRENGTH: + nm_ap_set_strength (NM_AP (object), g_value_get_int (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +get_property (GObject *object, guint prop_id, + GValue *value, GParamSpec *pspec) +{ + NMAccessPointPrivate *priv = NM_AP_GET_PRIVATE (object); + + switch (prop_id) { + case PROP_CAPABILITIES: + g_value_set_uint (value, priv->capabilities); + break; + case PROP_ENCRYPTED: + g_value_set_boolean (value, priv->capabilities & NM_802_11_CAP_PROTO_NONE); + break; + case PROP_ESSID: + g_value_set_string (value, priv->essid); + break; + case PROP_FREQUENCY: + g_value_set_double (value, priv->freq); + break; + case PROP_MODE: + g_value_set_int (value, priv->mode); + break; + case PROP_RATE: + g_value_set_uint (value, priv->rate); + break; + case PROP_STRENGTH: + g_value_set_int (value, priv->strength); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +nm_ap_class_init (NMAccessPointClass *ap_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (ap_class); + + g_type_class_add_private (ap_class, sizeof (NMAccessPointPrivate)); + + /* virtual methods */ + object_class->set_property = set_property; + object_class->get_property = get_property; + object_class->finalize = finalize; + + /* properties */ + + /* FIXME: address */ + + g_object_class_install_property + (object_class, PROP_CAPABILITIES, + g_param_spec_uint (NM_AP_CAPABILITIES, + "Capabilities", + "Capabilities", + NM_802_11_CAP_NONE, NM_802_11_CAP_CIPHER_CCMP, NM_802_11_CAP_PROTO_NONE, + G_PARAM_READWRITE)); + + g_object_class_install_property + (object_class, PROP_ENCRYPTED, + g_param_spec_boolean (NM_AP_ENCRYPTED, + "Encrypted", + "Is encrypted", + FALSE, + G_PARAM_READABLE)); + + g_object_class_install_property + (object_class, PROP_ESSID, + g_param_spec_string (NM_AP_ESSID, + "ESSID", + "ESSID", + NULL, + G_PARAM_READWRITE)); + + g_object_class_install_property + (object_class, PROP_FREQUENCY, + g_param_spec_double (NM_AP_FREQUENCY, + "Frequency", + "Frequency", + 0.0, 10000.0, 0.0, /* FIXME */ + G_PARAM_READWRITE)); + + /* FIXME: HWAddress */ + + g_object_class_install_property + (object_class, PROP_MODE, + g_param_spec_int (NM_AP_MODE, + "Mode", + "Mode", + IW_MODE_ADHOC, IW_MODE_INFRA, IW_MODE_INFRA, + G_PARAM_READWRITE)); + + g_object_class_install_property + (object_class, PROP_RATE, + g_param_spec_uint (NM_AP_RATE, + "Rate", + "Rate", + 0, G_MAXUINT16, 0, + G_PARAM_READWRITE)); + + g_object_class_install_property + (object_class, PROP_STRENGTH, + g_param_spec_int (NM_AP_STRENGTH, + "Strength", + "Strength", + G_MININT8, G_MAXINT8, 0, + G_PARAM_READWRITE)); + + /* Signals */ + signals[STRENGTH_CHANGED] = + g_signal_new ("strength_changed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMAccessPointClass, strength_changed), + NULL, NULL, + g_cclosure_marshal_VOID__CHAR, + G_TYPE_NONE, 1, + G_TYPE_CHAR); + + dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (ap_class), + &dbus_glib_nm_access_point_object_info); +} + /* * nm_ap_new * * Create a new, blank user access point info structure * */ -NMAccessPoint * nm_ap_new (void) +NMAccessPoint *nm_ap_new (void) { - NMAccessPoint *ap; - - ap = g_slice_new0 (NMAccessPoint); - ap->mode = IW_MODE_INFRA; - ap->refcount = 1; - ap->capabilities = NM_802_11_CAP_PROTO_NONE; - ap->broadcast = TRUE; + NMDBusManager *manager; + GObject *object; + char *path; + static guint32 counter = 0; - return ap; + object = g_object_new (NM_TYPE_AP, NULL); + + manager = nm_dbus_manager_get (); + + path = g_strdup_printf (NM_DBUS_PATH_ACCESS_POINT "/%d", counter++); + dbus_g_connection_register_g_object (nm_dbus_manager_get_connection (manager), + path, object); + g_free (path); + + return (NMAccessPoint *) object; } @@ -100,34 +329,40 @@ NMAccessPoint * nm_ap_new (void) * Create a new user access point info structure, duplicating an existing one * */ -NMAccessPoint * nm_ap_new_from_ap (NMAccessPoint *src_ap) +NMAccessPoint * +nm_ap_new_from_ap (NMAccessPoint *src_ap) { NMAccessPoint * new_ap; + NMAccessPointPrivate *src_priv; + NMAccessPointPrivate *new_priv; - g_return_val_if_fail (src_ap != NULL, NULL); + g_return_val_if_fail (NM_IS_AP (src_ap), NULL); - if (!(new_ap = nm_ap_new())) + if (!(new_ap = nm_ap_new ())) { nm_warning ("nm_ap_new_from_uap() could not allocate a new user access point structure. Not enough memory?"); - return (NULL); + return NULL; } - if (src_ap->essid && (strlen (src_ap->essid) > 0)) + src_priv = NM_AP_GET_PRIVATE (src_ap); + new_priv = NM_AP_GET_PRIVATE (new_ap); + + if (src_priv->essid && (strlen (src_priv->essid) > 0)) { - new_ap->essid = g_strdup (src_ap->essid); - new_ap->orig_essid = g_strdup (src_ap->orig_essid); + new_priv->essid = g_strdup (src_priv->essid); + new_priv->orig_essid = g_strdup (src_priv->orig_essid); } - memcpy (&new_ap->address, &src_ap->address, sizeof (struct ether_addr)); - new_ap->mode = src_ap->mode; - new_ap->strength = src_ap->strength; - new_ap->freq = src_ap->freq; - new_ap->rate = src_ap->rate; - new_ap->capabilities = src_ap->capabilities; - new_ap->artificial = src_ap->artificial; - new_ap->broadcast = src_ap->broadcast; - - if (src_ap->security) - new_ap->security = nm_ap_security_new_copy (src_ap->security); + memcpy (&new_priv->address, &src_priv->address, sizeof (struct ether_addr)); + new_priv->mode = src_priv->mode; + new_priv->strength = src_priv->strength; + new_priv->freq = src_priv->freq; + new_priv->rate = src_priv->rate; + new_priv->capabilities = src_priv->capabilities; + new_priv->artificial = src_priv->artificial; + new_priv->broadcast = src_priv->broadcast; + + if (src_priv->security) + new_priv->security = nm_ap_security_new_copy (src_priv->security); return new_ap; } @@ -137,7 +372,6 @@ NMAccessPoint * nm_ap_new_from_ap (NMAccessPoint *src_ap) #define IEEE80211_CAP_IBSS 0x0002 #define IEEE80211_CAP_PRIVACY 0x0010 - static void foreach_property_cb (gpointer key, gpointer value, gpointer user_data) { @@ -233,61 +467,33 @@ nm_ap_new_from_properties (GHashTable *properties) /* - * AP refcounting functions - */ -void nm_ap_ref (NMAccessPoint *ap) -{ - g_return_if_fail (ap != NULL); - - ap->refcount++; -} - -void nm_ap_unref (NMAccessPoint *ap) -{ - g_return_if_fail (ap != NULL); - g_return_if_fail (ap->refcount > 0); - - ap->refcount--; - if (ap->refcount == 0) - { - g_free (ap->essid); - g_free (ap->orig_essid); - g_slist_foreach (ap->user_addresses, (GFunc)g_free, NULL); - g_slist_free (ap->user_addresses); - - if (ap->security) - g_object_unref (G_OBJECT (ap->security)); - - memset (ap, 0, sizeof (NMAccessPoint)); - g_slice_free (NMAccessPoint, ap); - } -} - - -/* * Get/set functions for timestamp * */ const GTimeVal *nm_ap_get_timestamp (const NMAccessPoint *ap) { - g_return_val_if_fail (ap != NULL, 0); + g_return_val_if_fail (NM_IS_AP (ap), 0); - return (&ap->timestamp); + return (&NM_AP_GET_PRIVATE (ap)->timestamp); } void nm_ap_set_timestamp (NMAccessPoint *ap, glong sec, glong usec) { - g_return_if_fail (ap != NULL); + NMAccessPointPrivate *priv; + + g_return_if_fail (NM_IS_AP (ap)); - ap->timestamp.tv_sec = sec; - ap->timestamp.tv_usec = usec; + priv = NM_AP_GET_PRIVATE (ap); + + priv->timestamp.tv_sec = sec; + priv->timestamp.tv_usec = usec; } void nm_ap_set_timestamp_via_timestamp (NMAccessPoint *ap, const GTimeVal *timestamp) { - g_return_if_fail (ap != NULL); + g_return_if_fail (NM_IS_AP (ap)); - ap->timestamp = *timestamp; + NM_AP_GET_PRIVATE (ap)->timestamp = *timestamp; } /* @@ -296,51 +502,43 @@ void nm_ap_set_timestamp_via_timestamp (NMAccessPoint *ap, const GTimeVal *times */ const char * nm_ap_get_essid (const NMAccessPoint *ap) { - g_return_val_if_fail (ap != NULL, NULL); + g_return_val_if_fail (NM_IS_AP (ap), NULL); - return ap->essid; + return NM_AP_GET_PRIVATE (ap)->essid; } const char * nm_ap_get_orig_essid (const NMAccessPoint *ap) { - g_return_val_if_fail (ap != NULL, NULL); + g_return_val_if_fail (NM_IS_AP (ap), NULL); - return ap->orig_essid; + return NM_AP_GET_PRIVATE (ap)->orig_essid; } void nm_ap_set_essid (NMAccessPoint *ap, const char * essid) { - g_return_if_fail (ap != NULL); - - if (ap->essid) - { - g_free (ap->essid); - g_free (ap->orig_essid); - ap->essid = NULL; - ap->orig_essid = NULL; - } + g_return_if_fail (NM_IS_AP (ap)); - if (essid) - { - ap->orig_essid = g_strdup (essid); - ap->essid = nm_utils_essid_to_utf8 (essid); - } + g_object_set (ap, NM_AP_ESSID, essid, NULL); } guint32 nm_ap_get_capabilities (NMAccessPoint *ap) { - g_return_val_if_fail (ap != NULL, NM_802_11_CAP_NONE); + guint32 caps; - return ap->capabilities; + g_return_val_if_fail (NM_IS_AP (ap), NM_802_11_CAP_NONE); + + g_object_get (ap, NM_AP_CAPABILITIES, &caps, NULL); + + return caps; } void nm_ap_set_capabilities (NMAccessPoint *ap, guint32 capabilities) { - g_return_if_fail (ap != NULL); + g_return_if_fail (NM_IS_AP (ap)); - ap->capabilities = capabilities; + g_object_set (ap, NM_AP_CAPABILITIES, capabilities, NULL); } @@ -348,11 +546,15 @@ void nm_ap_set_capabilities (NMAccessPoint *ap, guint32 capabilities) * Accessor function for encrypted flag * */ -gboolean nm_ap_get_encrypted (const NMAccessPoint *ap) +gboolean nm_ap_get_encrypted (NMAccessPoint *ap) { - g_return_val_if_fail (ap != NULL, FALSE); + gboolean encrypted; - return (!(ap->capabilities & NM_802_11_CAP_PROTO_NONE)); + g_return_val_if_fail (NM_IS_AP (ap), FALSE); + + g_object_get (ap, NM_AP_ENCRYPTED, &encrypted, NULL); + + return encrypted; } @@ -362,23 +564,27 @@ gboolean nm_ap_get_encrypted (const NMAccessPoint *ap) */ NMAPSecurity * nm_ap_get_security (const NMAccessPoint *ap) { - g_return_val_if_fail (ap != NULL, NULL); + g_return_val_if_fail (NM_IS_AP (ap), NULL); - return ap->security; + return NM_AP_GET_PRIVATE (ap)->security; } void nm_ap_set_security (NMAccessPoint *ap, NMAPSecurity *security) { - g_return_if_fail (ap != NULL); + NMAccessPointPrivate *priv; + + g_return_if_fail (NM_IS_AP (ap)); + + priv = NM_AP_GET_PRIVATE (ap); - if (ap->security) + if (priv->security) { - g_object_unref (G_OBJECT (ap->security)); - ap->security = NULL; + g_object_unref (G_OBJECT (priv->security)); + priv->security = NULL; } if (security) - ap->security = nm_ap_security_new_copy (security); + priv->security = nm_ap_security_new_copy (security); } @@ -388,17 +594,17 @@ void nm_ap_set_security (NMAccessPoint *ap, NMAPSecurity *security) */ const struct ether_addr * nm_ap_get_address (const NMAccessPoint *ap) { - g_return_val_if_fail (ap != NULL, NULL); + g_return_val_if_fail (NM_IS_AP (ap), NULL); - return &ap->address; + return &NM_AP_GET_PRIVATE (ap)->address; } void nm_ap_set_address (NMAccessPoint *ap, const struct ether_addr * addr) { - g_return_if_fail (ap != NULL); + g_return_if_fail (NM_IS_AP (ap)); g_return_if_fail (addr != NULL); - memcpy (&ap->address, addr, sizeof (struct ether_addr)); + memcpy (&NM_AP_GET_PRIVATE (ap)->address, addr, sizeof (struct ether_addr)); } @@ -406,19 +612,22 @@ void nm_ap_set_address (NMAccessPoint *ap, const struct ether_addr * addr) * Get/set functions for mode (ie Ad-Hoc, Infrastructure, etc) * */ -int nm_ap_get_mode (const NMAccessPoint *ap) +int nm_ap_get_mode (NMAccessPoint *ap) { - g_return_val_if_fail (ap != NULL, -1); + int mode; - return ap->mode; + g_return_val_if_fail (NM_IS_AP (ap), -1); + + g_object_get (ap, NM_AP_MODE, &mode, NULL); + + return mode; } void nm_ap_set_mode (NMAccessPoint *ap, const int mode) { - g_return_if_fail (ap != NULL); - g_return_if_fail ((mode == IW_MODE_ADHOC) || (mode == IW_MODE_INFRA)); + g_return_if_fail (NM_IS_AP (ap)); - ap->mode = mode; + g_object_set (ap, NM_AP_MODE, mode, NULL); } @@ -426,18 +635,29 @@ void nm_ap_set_mode (NMAccessPoint *ap, const int mode) * Get/set functions for strength * */ -gint8 nm_ap_get_strength (const NMAccessPoint *ap) +gint8 nm_ap_get_strength (NMAccessPoint *ap) { - g_return_val_if_fail (ap != NULL, 0); + gint8 strength; + + g_return_val_if_fail (NM_IS_AP (ap), 0); - return (ap->strength); + g_object_get (ap, NM_AP_STRENGTH, &strength, NULL); + + return strength; } -void nm_ap_set_strength (NMAccessPoint *ap, const gint8 strength) +void nm_ap_set_strength (NMAccessPoint *ap, const gint8 strength) { - g_return_if_fail (ap != NULL); + NMAccessPointPrivate *priv; + + g_return_if_fail (NM_IS_AP (ap)); - ap->strength = strength; + priv = NM_AP_GET_PRIVATE (ap); + + if (priv->strength != strength) { + priv->strength = strength; + g_signal_emit (ap, signals[STRENGTH_CHANGED], 0, strength); + } } @@ -445,18 +665,22 @@ void nm_ap_set_strength (NMAccessPoint *ap, const gint8 strength) * Get/set functions for frequency * */ -double nm_ap_get_freq (const NMAccessPoint *ap) +double nm_ap_get_freq (NMAccessPoint *ap) { - g_return_val_if_fail (ap != NULL, 0); + double freq; - return (ap->freq); + g_return_val_if_fail (NM_IS_AP (ap), 0); + + g_object_get (ap, NM_AP_FREQUENCY, &freq, NULL); + + return freq; } void nm_ap_set_freq (NMAccessPoint *ap, const double freq) { - g_return_if_fail (ap != NULL); + g_return_if_fail (NM_IS_AP (ap)); - ap->freq = freq; + g_object_set (ap, NM_AP_FREQUENCY, freq, NULL); } @@ -464,18 +688,22 @@ void nm_ap_set_freq (NMAccessPoint *ap, const double freq) * Get/set functions for rate * */ -guint16 nm_ap_get_rate (const NMAccessPoint *ap) +guint16 nm_ap_get_rate (NMAccessPoint *ap) { - g_return_val_if_fail (ap != NULL, 0); + guint16 rate; + + g_return_val_if_fail (NM_IS_AP (ap), 0); - return (ap->rate); + g_object_get (ap, NM_AP_RATE, &rate, NULL); + + return rate; } void nm_ap_set_rate (NMAccessPoint *ap, guint16 rate) { - g_return_if_fail (ap != NULL); + g_return_if_fail (NM_IS_AP (ap)); - ap->rate = rate; + g_object_set (ap, NM_AP_RATE, rate, NULL); } @@ -487,16 +715,16 @@ void nm_ap_set_rate (NMAccessPoint *ap, guint16 rate) */ gboolean nm_ap_get_invalid (const NMAccessPoint *ap) { - g_return_val_if_fail (ap != NULL, TRUE); + g_return_val_if_fail (NM_IS_AP (ap), TRUE); - return (ap->invalid); + return NM_AP_GET_PRIVATE (ap)->invalid; } void nm_ap_set_invalid (NMAccessPoint *ap, gboolean invalid) { - g_return_if_fail (ap != NULL); + g_return_if_fail (NM_IS_AP (ap)); - ap->invalid = invalid; + NM_AP_GET_PRIVATE (ap)->invalid = invalid; } @@ -507,16 +735,16 @@ void nm_ap_set_invalid (NMAccessPoint *ap, gboolean invalid) */ gboolean nm_ap_get_fallback (const NMAccessPoint *ap) { - g_return_val_if_fail (ap != NULL, FALSE); + g_return_val_if_fail (NM_IS_AP (ap), FALSE); - return (ap->fallback); + return NM_AP_GET_PRIVATE (ap)->fallback; } void nm_ap_set_fallback (NMAccessPoint *ap, gboolean fallback) { - g_return_if_fail (ap != NULL); + g_return_if_fail (NM_IS_AP (ap)); - ap->fallback = fallback; + NM_AP_GET_PRIVATE (ap)->fallback = fallback; } @@ -528,16 +756,16 @@ void nm_ap_set_fallback (NMAccessPoint *ap, gboolean fallback) */ gboolean nm_ap_get_artificial (const NMAccessPoint *ap) { - g_return_val_if_fail (ap != NULL, FALSE); + g_return_val_if_fail (NM_IS_AP (ap), FALSE); - return (ap->artificial); + return NM_AP_GET_PRIVATE (ap)->artificial; } void nm_ap_set_artificial (NMAccessPoint *ap, gboolean artificial) { - g_return_if_fail (ap != NULL); + g_return_if_fail (NM_IS_AP (ap)); - ap->artificial = artificial; + NM_AP_GET_PRIVATE (ap)->artificial = artificial; } @@ -545,17 +773,19 @@ void nm_ap_set_artificial (NMAccessPoint *ap, gboolean artificial) * Get/Set functions to indicate whether an access point is broadcasting * (hidden). This is a superset of artificial. */ -gboolean nm_ap_get_broadcast (const NMAccessPoint *ap) +gboolean nm_ap_get_broadcast (NMAccessPoint *ap) { - g_return_val_if_fail (ap != NULL, TRUE); - return ap->broadcast; + g_return_val_if_fail (NM_IS_AP (ap), TRUE); + + return NM_AP_GET_PRIVATE (ap)->broadcast; } void nm_ap_set_broadcast (NMAccessPoint *ap, gboolean broadcast) { - g_return_if_fail (ap != NULL); - ap->broadcast = broadcast; + g_return_if_fail (NM_IS_AP (ap)); + + NM_AP_GET_PRIVATE (ap)->broadcast = broadcast; } @@ -566,16 +796,16 @@ void nm_ap_set_broadcast (NMAccessPoint *ap, gboolean broadcast) */ const GTimeVal *nm_ap_get_last_seen (const NMAccessPoint *ap) { - g_return_val_if_fail (ap != NULL, FALSE); + g_return_val_if_fail (NM_IS_AP (ap), FALSE); - return (&ap->last_seen); + return &NM_AP_GET_PRIVATE (ap)->last_seen; } void nm_ap_set_last_seen (NMAccessPoint *ap, const GTimeVal *last_seen) { - g_return_if_fail (ap != NULL); + g_return_if_fail (NM_IS_AP (ap)); - ap->last_seen = *last_seen; + NM_AP_GET_PRIVATE (ap)->last_seen = *last_seen; } @@ -588,16 +818,16 @@ void nm_ap_set_last_seen (NMAccessPoint *ap, const GTimeVal *last_seen) */ gboolean nm_ap_get_user_created (const NMAccessPoint *ap) { - g_return_val_if_fail (ap != NULL, FALSE); + g_return_val_if_fail (NM_IS_AP (ap), FALSE); - return (ap->user_created); + return NM_AP_GET_PRIVATE (ap)->user_created; } void nm_ap_set_user_created (NMAccessPoint *ap, gboolean user_created) { - g_return_if_fail (ap != NULL); + g_return_if_fail (NM_IS_AP (ap)); - ap->user_created = user_created; + NM_AP_GET_PRIVATE (ap)->user_created = user_created; } @@ -615,27 +845,30 @@ GSList *nm_ap_get_user_addresses (const NMAccessPoint *ap) GSList *new = NULL; GSList *elt = NULL; - g_return_val_if_fail (ap != NULL, NULL); + g_return_val_if_fail (NM_IS_AP (ap), NULL); - for (elt = ap->user_addresses; elt; elt = g_slist_next (elt)) + for (elt = NM_AP_GET_PRIVATE (ap)->user_addresses; elt; elt = g_slist_next (elt)) { if (elt->data) new = g_slist_append (new, g_strdup (elt->data)); } /* Return a _deep__copy_ of the address list */ - return (new); + return new; } void nm_ap_set_user_addresses (NMAccessPoint *ap, GSList *list) { + NMAccessPointPrivate *priv; GSList *elt = NULL; GSList *new = NULL; - g_return_if_fail (ap != NULL); + g_return_if_fail (NM_IS_AP (ap)); + + priv = NM_AP_GET_PRIVATE (ap); /* Free existing list */ - g_slist_foreach (ap->user_addresses, (GFunc) g_free, NULL); + g_slist_foreach (priv->user_addresses, (GFunc) g_free, NULL); /* Copy new list and set as our own */ for (elt = list; elt; elt = g_slist_next (elt)) @@ -644,7 +877,7 @@ void nm_ap_set_user_addresses (NMAccessPoint *ap, GSList *list) new = g_slist_append (new, g_strdup (elt->data)); } - ap->user_addresses = new; + priv->user_addresses = new; } @@ -653,8 +886,8 @@ gboolean nm_ap_has_manufacturer_default_essid (NMAccessPoint *ap) const char **default_essid = default_essid_list; const char *this_essid; - g_return_val_if_fail (ap != NULL, FALSE); - this_essid = ap->essid; + g_return_val_if_fail (NM_IS_AP (ap), FALSE); + this_essid = NM_AP_GET_PRIVATE (ap)->essid; while (*default_essid) { @@ -717,7 +950,7 @@ void nm_ap_add_capabilities_from_security (NMAccessPoint *ap, NMAPSecurity *secu guint32 caps; int cipher; - g_return_if_fail (ap != NULL); + g_return_if_fail (NM_IS_AP (ap)); g_return_if_fail (security != NULL); cipher = nm_ap_security_get_we_cipher (security); @@ -731,7 +964,7 @@ void nm_ap_add_capabilities_from_ie (NMAccessPoint *ap, const guint8 *wpa_ie, gu wpa_ie_data * cap_data; guint32 caps; - g_return_if_fail (ap != NULL); + g_return_if_fail (NM_IS_AP (ap)); if (!(cap_data = wpa_parse_wpa_ie (wpa_ie, length))) return; @@ -768,8 +1001,12 @@ void nm_ap_add_capabilities_from_ie (NMAccessPoint *ap, const guint8 *wpa_ie, gu void nm_ap_add_capabilities_for_wep (NMAccessPoint *ap) { - g_return_if_fail (ap != NULL); + NMAccessPointPrivate *priv; + + g_return_if_fail (NM_IS_AP (ap)); + + priv = NM_AP_GET_PRIVATE (ap); - ap->capabilities |= (NM_802_11_CAP_PROTO_WEP | NM_802_11_CAP_CIPHER_WEP40 | NM_802_11_CAP_CIPHER_WEP104); - ap->capabilities &= ~NM_802_11_CAP_PROTO_NONE; + priv->capabilities |= (NM_802_11_CAP_PROTO_WEP | NM_802_11_CAP_CIPHER_WEP40 | NM_802_11_CAP_CIPHER_WEP104); + priv->capabilities &= ~NM_802_11_CAP_PROTO_NONE; } diff --git a/src/NetworkManagerAP.h b/src/NetworkManagerAP.h index 7ba390d2f3..5b82ed8bf6 100644 --- a/src/NetworkManagerAP.h +++ b/src/NetworkManagerAP.h @@ -19,25 +19,50 @@ * (C) Copyright 2004 Red Hat, Inc. */ -#ifndef NETWORK_MANAGER_AP_H -#define NETWORK_MANAGER_AP_H +#ifndef NM_ACCESS_POINT_H +#define NM_ACCESS_POINT_H #include <glib.h> +#include <glib/gtypes.h> +#include <glib-object.h> #include <time.h> #include "NetworkManager.h" -#include "wpa.h" #include "nm-ap-security.h" -typedef struct NMAccessPoint NMAccessPoint; +#define NM_TYPE_AP (nm_ap_get_type ()) +#define NM_AP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_AP, NMAccessPoint)) +#define NM_AP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_AP, NMAccessPointClass)) +#define NM_IS_AP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_AP)) +#define NM_IS_AP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_AP)) +#define NM_AP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_AP, NMAccessPointClass)) +#define NM_AP_ADDRESS "address" +#define NM_AP_CAPABILITIES "capabilities" +#define NM_AP_ENCRYPTED "encrypted" +#define NM_AP_ESSID "essid" +#define NM_AP_FREQUENCY "frequency" +#define NM_AP_HWADDRESS "hwaddress" +#define NM_AP_MODE "mode" +#define NM_AP_RATE "rate" +#define NM_AP_STRENGTH "strength" + +typedef struct { + GObject parent; +} NMAccessPoint; + +typedef struct { + GObjectClass parent; + + /* Signals */ + void (*strength_changed) (NMAccessPoint *ap, gint8 strength); +} NMAccessPointClass; + +GType nm_ap_get_type (void); NMAccessPoint * nm_ap_new (void); NMAccessPoint * nm_ap_new_from_ap (NMAccessPoint *ap); NMAccessPoint * nm_ap_new_from_properties (GHashTable *properties); -void nm_ap_unref (NMAccessPoint *ap); -void nm_ap_ref (NMAccessPoint *ap); - const GTimeVal * nm_ap_get_timestamp (const NMAccessPoint *ap); void nm_ap_set_timestamp (NMAccessPoint *ap, glong sec, glong usec); void nm_ap_set_timestamp_via_timestamp (NMAccessPoint *ap, const GTimeVal *timestamp); @@ -50,7 +75,7 @@ const char * nm_ap_get_orig_essid (const NMAccessPoint *ap); guint32 nm_ap_get_capabilities (NMAccessPoint *ap); void nm_ap_set_capabilities (NMAccessPoint *ap, guint32 capabilities); -gboolean nm_ap_get_encrypted (const NMAccessPoint *ap); +gboolean nm_ap_get_encrypted (NMAccessPoint *ap); NMAPSecurity * nm_ap_get_security (const NMAccessPoint *ap); void nm_ap_set_security (NMAccessPoint *ap, NMAPSecurity *security); @@ -58,16 +83,16 @@ void nm_ap_set_security (NMAccessPoint *ap, NMAPSecurity *security); const struct ether_addr * nm_ap_get_address (const NMAccessPoint *ap); void nm_ap_set_address (NMAccessPoint *ap, const struct ether_addr *addr); -int nm_ap_get_mode (const NMAccessPoint *ap); +int nm_ap_get_mode (NMAccessPoint *ap); void nm_ap_set_mode (NMAccessPoint *ap, const int mode); -gint8 nm_ap_get_strength (const NMAccessPoint *ap); +gint8 nm_ap_get_strength (NMAccessPoint *ap); void nm_ap_set_strength (NMAccessPoint *ap, gint8 strength); -double nm_ap_get_freq (const NMAccessPoint *ap); +double nm_ap_get_freq (NMAccessPoint *ap); void nm_ap_set_freq (NMAccessPoint *ap, double freq); -guint16 nm_ap_get_rate (const NMAccessPoint *ap); +guint16 nm_ap_get_rate (NMAccessPoint *ap); void nm_ap_set_rate (NMAccessPoint *ap, guint16 rate); gboolean nm_ap_get_invalid (const NMAccessPoint *ap); @@ -79,7 +104,7 @@ void nm_ap_set_fallback (NMAccessPoint *ap, gboolean fallback); gboolean nm_ap_get_artificial (const NMAccessPoint *ap); void nm_ap_set_artificial (NMAccessPoint *ap, gboolean artificial); -gboolean nm_ap_get_broadcast (const NMAccessPoint *ap); +gboolean nm_ap_get_broadcast (NMAccessPoint *ap); void nm_ap_set_broadcast (NMAccessPoint *ap, gboolean broadcast); const GTimeVal * nm_ap_get_last_seen (const NMAccessPoint *ap); @@ -102,4 +127,4 @@ void nm_ap_add_capabilities_for_wep (NMAccessPoint *ap); */ gboolean nm_ap_has_manufacturer_default_essid (NMAccessPoint *ap); -#endif +#endif /* NM_ACCESS_POINT_H */ diff --git a/src/NetworkManagerAPList.c b/src/NetworkManagerAPList.c index c968fc4c3d..eb7e9ab16e 100644 --- a/src/NetworkManagerAPList.c +++ b/src/NetworkManagerAPList.c @@ -69,19 +69,6 @@ void nm_ap_list_ref (NMAccessPointList *list) /* - * nm_ap_list_element_free - * - * Frees each member of an access point list before the list is - * disposed of. - * - */ -static void nm_ap_list_element_free (void *element, void *user_data) -{ - nm_ap_unref (element); -} - - -/* * nm_ap_list_unref * * Decreases the refcount of the ap list, and if it reaches @@ -95,7 +82,7 @@ void nm_ap_list_unref (NMAccessPointList *list) list->refcount--; if (list->refcount <= 0) { - g_slist_foreach (list->ap_list, nm_ap_list_element_free, NULL); + g_slist_foreach (list->ap_list, (GFunc) g_object_unref, NULL); g_slist_free (list->ap_list); g_slice_free (NMAccessPointList, list); } @@ -140,8 +127,7 @@ void nm_ap_list_append_ap (NMAccessPointList *list, NMAccessPoint *ap) g_return_if_fail (list != NULL); g_return_if_fail (ap != NULL); - nm_ap_ref (ap); - list->ap_list = g_slist_append (list->ap_list, ap); + list->ap_list = g_slist_append (list->ap_list, g_object_ref (ap)); } @@ -163,7 +149,7 @@ void nm_ap_list_remove_ap (NMAccessPointList *list, NMAccessPoint *ap) if (list_ap == ap) { list->ap_list = g_slist_remove_link (list->ap_list, elt); - nm_ap_unref (list_ap); + g_object_unref (list_ap); g_slist_free (elt); break; } @@ -189,7 +175,7 @@ void nm_ap_list_remove_ap_by_essid (NMAccessPointList *list, const char *network if (nm_null_safe_strcmp (nm_ap_get_essid (list_ap), network) == 0) { list->ap_list = g_slist_remove_link (list->ap_list, elt); - nm_ap_unref (list_ap); + g_object_unref (list_ap); g_slist_free (elt); break; } diff --git a/src/NetworkManagerDbus.c b/src/NetworkManagerDbus.c index d0682b5492..f4b2833673 100644 --- a/src/NetworkManagerDbus.c +++ b/src/NetworkManagerDbus.c @@ -259,7 +259,7 @@ nm_dbus_signal_device_status_change (gpointer user_data) const char *essid = nm_ap_get_essid (cb_data->ap); if (essid) dbus_message_append_args (message, DBUS_TYPE_OBJECT_PATH, &dev_path, DBUS_TYPE_STRING, &essid, DBUS_TYPE_INVALID); - nm_ap_unref (cb_data->ap); + g_object_unref (cb_data->ap); } else { dbus_message_append_args (message, DBUS_TYPE_OBJECT_PATH, &dev_path, DBUS_TYPE_INVALID); } @@ -290,10 +290,9 @@ void nm_dbus_schedule_device_status_change_signal (NMData *data, NMDevice *dev, g_object_ref (G_OBJECT (dev)); cb_data->data = data; cb_data->dev = dev; - if (ap) { - nm_ap_ref (ap); - cb_data->ap = ap; - } + if (ap) + cb_data->ap = g_object_ref (ap); + cb_data->status = status; id = g_idle_add (nm_dbus_signal_device_status_change, cb_data); diff --git a/src/NetworkManagerMain.h b/src/NetworkManagerMain.h index efbc5348a9..d6fc8f6df6 100644 --- a/src/NetworkManagerMain.h +++ b/src/NetworkManagerMain.h @@ -49,7 +49,6 @@ typedef struct NMData guint32 nmi_sig_handler_id; GMainLoop * main_loop; - gboolean enable_test_devices; guint dev_change_check_idle_id; diff --git a/src/NetworkManagerPolicy.c b/src/NetworkManagerPolicy.c index db1425c55b..2bd29de36a 100644 --- a/src/NetworkManagerPolicy.c +++ b/src/NetworkManagerPolicy.c @@ -425,7 +425,7 @@ nm_policy_device_change_check (gpointer user_data) } if (ap) - nm_ap_unref (ap); + g_object_unref (ap); out: return FALSE; diff --git a/src/backends/NetworkManagerArch.c b/src/backends/NetworkManagerArch.c index dbfd00f7f2..8d156d92d6 100644 --- a/src/backends/NetworkManagerArch.c +++ b/src/backends/NetworkManagerArch.c @@ -629,7 +629,7 @@ void nm_system_device_free_system_config (NMDevice *dev, void *system_config_dat } if (sys_data->config) - nm_ip4_config_unref (sys_data->config); + g_object_unref (sys_data->config); } diff --git a/src/backends/NetworkManagerDebian.c b/src/backends/NetworkManagerDebian.c index d3cb58dc5f..c049ce90f0 100644 --- a/src/backends/NetworkManagerDebian.c +++ b/src/backends/NetworkManagerDebian.c @@ -327,7 +327,7 @@ out: { sys_data->use_dhcp = TRUE; /* Clear out the config */ - nm_ip4_config_unref (sys_data->config); + g_object_unref (sys_data->config); sys_data->config = NULL; } @@ -350,7 +350,7 @@ void nm_system_device_free_system_config (NMDevice *dev, void *system_config_dat return; if (sys_data->config) - nm_ip4_config_unref (sys_data->config); + g_object_unref (sys_data->config); } diff --git a/src/backends/NetworkManagerFrugalware.c b/src/backends/NetworkManagerFrugalware.c index 5ce281966f..a76e41440b 100644 --- a/src/backends/NetworkManagerFrugalware.c +++ b/src/backends/NetworkManagerFrugalware.c @@ -576,7 +576,7 @@ out: { sys_data->use_dhcp = TRUE; /* Clear out the config */ - nm_ip4_config_unref (sys_data->config); + g_object_unref (sys_data->config); sys_data->config = NULL; } diff --git a/src/backends/NetworkManagerGentoo.c b/src/backends/NetworkManagerGentoo.c index 0ecbe53c7b..c5fabd3cc1 100644 --- a/src/backends/NetworkManagerGentoo.c +++ b/src/backends/NetworkManagerGentoo.c @@ -425,7 +425,7 @@ void nm_system_device_free_system_config (NMDevice *dev, void *system_config_dat g_return_if_fail(sys_data != NULL); if (sys_data->config) - nm_ip4_config_unref (sys_data->config); + g_object_unref (sys_data->config); g_free (sys_data); } diff --git a/src/backends/NetworkManagerPaldo.c b/src/backends/NetworkManagerPaldo.c index 15dffdc353..9b7eed011b 100644 --- a/src/backends/NetworkManagerPaldo.c +++ b/src/backends/NetworkManagerPaldo.c @@ -356,7 +356,7 @@ static NMIP4Config *netdevice_file_get_ip4_config (GKeyFile *file) if (ipaddress == NULL) { - nm_ip4_config_unref (ip4_config); + g_object_unref (ip4_config); return NULL; } @@ -463,7 +463,7 @@ void nm_system_device_free_system_config (NMDevice *dev, void *system_config_dat return; if (sys_data->config) - nm_ip4_config_unref (sys_data->config); + g_object_unref (sys_data->config); } diff --git a/src/backends/NetworkManagerRedHat.c b/src/backends/NetworkManagerRedHat.c index 0acf3eee64..a0aa2b4fdb 100644 --- a/src/backends/NetworkManagerRedHat.c +++ b/src/backends/NetworkManagerRedHat.c @@ -461,7 +461,7 @@ out: { sys_data->use_dhcp = TRUE; /* Clear out the config */ - nm_ip4_config_unref (sys_data->config); + g_object_unref (sys_data->config); sys_data->config = NULL; } @@ -485,7 +485,7 @@ void nm_system_device_free_system_config (NMDevice *dev, void *system_config_dat return; if (sys_data->config) - nm_ip4_config_unref (sys_data->config); + g_object_unref (sys_data->config); } diff --git a/src/backends/NetworkManagerSuSE.c b/src/backends/NetworkManagerSuSE.c index cae800a87b..8c052411fd 100644 --- a/src/backends/NetworkManagerSuSE.c +++ b/src/backends/NetworkManagerSuSE.c @@ -409,7 +409,8 @@ found: cipher = cipher_wpa_psk_passphrase_new (); nm_ap_set_capabilities (ap, NM_802_11_CAP_PROTO_WPA); - security = nm_ap_security_wpa_psk_new_from_ap (ap, NM_AUTH_TYPE_WPA_PSK_AUTO); + security = nm_ap_security_wpa_psk_new (NM_802_11_CAP_PROTO_WPA, + NM_AUTH_TYPE_WPA_PSK_AUTO); hash = ieee_802_11_cipher_hash (cipher, buf, key); if (hash) { @@ -447,7 +448,7 @@ found: cipher = cipher_wep64_hex_new (); real_key = key; } - security = nm_ap_security_wep_new_from_ap (ap, IW_AUTH_CIPHER_WEP40); + security = nm_ap_security_wep_new (IW_AUTH_CIPHER_WEP40); } else { @@ -471,7 +472,7 @@ found: real_key = g_strjoinv (NULL, keyv); g_strfreev (keyv); } - security = nm_ap_security_wep_new_from_ap (ap, IW_AUTH_CIPHER_WEP104); + security = nm_ap_security_wep_new (IW_AUTH_CIPHER_WEP104); } hash = ieee_802_11_cipher_hash (cipher, buf, real_key); if (hash) @@ -489,7 +490,7 @@ found: { NMAPSecurity * security; - security = nm_ap_security_new (IW_AUTH_CIPHER_NONE); + security = nm_ap_security_new (NM_DEVICE_CAP_NONE, FALSE); nm_ap_set_security (ap, security); g_object_unref (G_OBJECT (security)); } @@ -506,7 +507,7 @@ found: /* New AP, just add it to the list */ nm_ap_list_append_ap (app_data->allowed_ap_list, ap); } - nm_ap_unref (ap); + g_object_unref (ap); nm_debug ("Adding '%s' to the list of trusted networks", buf); @@ -608,7 +609,7 @@ out: nm_debug ("error, enable dhcp"); sys_data->use_dhcp = TRUE; /* Clear out the config */ - nm_ip4_config_unref (sys_data->config); + g_object_unref (sys_data->config); sys_data->config = NULL; } @@ -665,7 +666,7 @@ void nm_system_device_free_system_config (NMDevice *dev, void *system_config_dat return; if (sys_data->config) - nm_ip4_config_unref (sys_data->config); + g_object_unref (sys_data->config); } diff --git a/src/named-manager/nm-named-manager.c b/src/named-manager/nm-named-manager.c index 3c6f793817..99c561abe8 100644 --- a/src/named-manager/nm-named-manager.c +++ b/src/named-manager/nm-named-manager.c @@ -622,8 +622,7 @@ nm_named_manager_add_ip4_config (NMNamedManager *mgr, NMIP4Config *config) add_all_ip4_configs_to_named (mgr); } - nm_ip4_config_ref (config); - mgr->priv->configs = g_slist_append (mgr->priv->configs, config); + mgr->priv->configs = g_slist_append (mgr->priv->configs, g_object_ref (config)); /* Activate the zone config */ if (mgr->priv->use_named) @@ -678,7 +677,7 @@ nm_named_manager_remove_ip4_config (NMNamedManager *mgr, NMIP4Config *config) remove_ip4_config_from_named (mgr, config); mgr->priv->configs = g_slist_remove (mgr->priv->configs, config); - nm_ip4_config_unref (config); + g_object_unref (config); /* Clear out and reload configs since we may need a new * default zone if the one we are removing was the old @@ -738,7 +737,7 @@ nm_named_manager_finalize (GObject *object) g_return_if_fail (mgr->priv != NULL); - g_slist_foreach (mgr->priv->configs, (GFunc) nm_ip4_config_unref, NULL); + g_slist_foreach (mgr->priv->configs, (GFunc) g_object_unref, NULL); g_slist_free (mgr->priv->configs); g_object_unref (mgr->priv->dbus_mgr); diff --git a/src/nm-activation-request.c b/src/nm-activation-request.c index ed702cdf42..f5fc876b52 100644 --- a/src/nm-activation-request.c +++ b/src/nm-activation-request.c @@ -61,11 +61,7 @@ NMActRequest * nm_act_request_new (NMData *data, NMDevice *dev, NMAccessPoint *a g_object_ref (G_OBJECT (dev)); req->dev = dev; - - if (ap) - nm_ap_ref (ap); - req->ap = ap; - + req->ap = ap ? g_object_ref (ap) : NULL; req->user_requested = user_requested; return req; @@ -87,7 +83,7 @@ void nm_act_request_unref (NMActRequest *req) if (req->refcount <= 0) { g_object_unref (G_OBJECT (req->dev)); if (req->ap) - nm_ap_unref (req->ap); + g_object_unref (req->ap); memset (req, 0, sizeof (NMActRequest)); g_free (req); @@ -139,14 +135,12 @@ void nm_act_request_set_ip4_config (NMActRequest *req, NMIP4Config *ip4_config) if (req->ip4_config) { - nm_ip4_config_unref (req->ip4_config); + g_object_unref (req->ip4_config); req->ip4_config = NULL; } + if (ip4_config) - { - nm_ip4_config_ref (ip4_config); - req->ip4_config = ip4_config; - } + req->ip4_config = g_object_ref (ip4_config); } NMActStage nm_act_request_get_stage (NMActRequest *req) diff --git a/src/nm-ap-security-leap.c b/src/nm-ap-security-leap.c index 795e6c033b..f9636381b2 100644 --- a/src/nm-ap-security-leap.c +++ b/src/nm-ap-security-leap.c @@ -71,11 +71,9 @@ out: NMAPSecurityLEAP * -nm_ap_security_leap_new_from_ap (NMAccessPoint *ap) +nm_ap_security_leap_new (void) { - NMAPSecurityLEAP * security = NULL; - - g_return_val_if_fail (ap != NULL, NULL); + NMAPSecurityLEAP *security; security = g_object_new (NM_TYPE_AP_SECURITY_LEAP, NULL); nm_ap_security_set_we_cipher (NM_AP_SECURITY (security), NM_AUTH_TYPE_LEAP); diff --git a/src/nm-ap-security-leap.h b/src/nm-ap-security-leap.h index 824e7a587f..4e5ebd12fa 100644 --- a/src/nm-ap-security-leap.h +++ b/src/nm-ap-security-leap.h @@ -54,8 +54,6 @@ struct _NMAPSecurityLEAPClass GType nm_ap_security_leap_get_type (void); NMAPSecurityLEAP * nm_ap_security_leap_new_deserialize (DBusMessageIter *iter); - -struct NMAccessPoint; -NMAPSecurityLEAP * nm_ap_security_leap_new_from_ap (struct NMAccessPoint *ap); +NMAPSecurityLEAP * nm_ap_security_leap_new (void); #endif /* NM_AP_SECURITY_LEAP_H */ diff --git a/src/nm-ap-security-wep.c b/src/nm-ap-security-wep.c index 12ce58c92b..30f5a0385b 100644 --- a/src/nm-ap-security-wep.c +++ b/src/nm-ap-security-wep.c @@ -83,11 +83,10 @@ out: } NMAPSecurityWEP * -nm_ap_security_wep_new_from_ap (NMAccessPoint *ap, int we_cipher) +nm_ap_security_wep_new (int we_cipher) { - NMAPSecurityWEP * security = NULL; + NMAPSecurityWEP *security; - g_return_val_if_fail (ap != NULL, NULL); g_return_val_if_fail ((we_cipher == IW_AUTH_CIPHER_WEP40) || (we_cipher == IW_AUTH_CIPHER_WEP104), NULL); security = g_object_new (NM_TYPE_AP_SECURITY_WEP, NULL); diff --git a/src/nm-ap-security-wep.h b/src/nm-ap-security-wep.h index 8cbdfc95bb..a0b103a799 100644 --- a/src/nm-ap-security-wep.h +++ b/src/nm-ap-security-wep.h @@ -54,8 +54,6 @@ struct _NMAPSecurityWEPClass GType nm_ap_security_wep_get_type (void); NMAPSecurityWEP * nm_ap_security_wep_new_deserialize (DBusMessageIter *iter, int we_cipher); - -struct NMAccessPoint; -NMAPSecurityWEP * nm_ap_security_wep_new_from_ap (struct NMAccessPoint *ap, int we_cipher); +NMAPSecurityWEP * nm_ap_security_wep_new (int we_cipher); #endif /* NM_AP_SECURITY_WEP_H */ diff --git a/src/nm-ap-security-wpa-eap.c b/src/nm-ap-security-wpa-eap.c index 7d13ffc448..2d5174ff2f 100644 --- a/src/nm-ap-security-wpa-eap.c +++ b/src/nm-ap-security-wpa-eap.c @@ -100,24 +100,17 @@ out: NMAPSecurityWPA_EAP * -nm_ap_security_wpa_eap_new_from_ap (NMAccessPoint *ap) +nm_ap_security_wpa_eap_new (guint32 capabilities) { - NMAPSecurityWPA_EAP * security = NULL; - guint32 caps; - - g_return_val_if_fail (ap != NULL, NULL); + NMAPSecurityWPA_EAP *security; security = g_object_new (NM_TYPE_AP_SECURITY_WPA_EAP, NULL); nm_ap_security_set_we_cipher (NM_AP_SECURITY (security), NM_AUTH_TYPE_WPA_EAP); - caps = nm_ap_get_capabilities (ap); - if (caps & NM_802_11_CAP_PROTO_WPA2) - { + if (capabilities & NM_802_11_CAP_PROTO_WPA2) { security->priv->wpa_version = IW_AUTH_WPA_VERSION_WPA2; nm_ap_security_set_description (NM_AP_SECURITY (security), _("WPA2 Enterprise")); - } - else - { + } else { security->priv->wpa_version = IW_AUTH_WPA_VERSION_WPA; nm_ap_security_set_description (NM_AP_SECURITY (security), _("WPA Enterprise")); } diff --git a/src/nm-ap-security-wpa-eap.h b/src/nm-ap-security-wpa-eap.h index 0fceb492df..8b8606f3ec 100644 --- a/src/nm-ap-security-wpa-eap.h +++ b/src/nm-ap-security-wpa-eap.h @@ -55,8 +55,6 @@ struct _NMAPSecurityWPA_EAPClass GType nm_ap_security_wpa_eap_get_type (void); NMAPSecurityWPA_EAP * nm_ap_security_wpa_eap_new_deserialize (DBusMessageIter *iter); - -struct NMAccessPoint; -NMAPSecurityWPA_EAP * nm_ap_security_wpa_eap_new_from_ap (struct NMAccessPoint *ap); +NMAPSecurityWPA_EAP * nm_ap_security_wpa_eap_new (guint32 capabilities); #endif /* NM_AP_SECURITY_WPA_EAP_H */ diff --git a/src/nm-ap-security-wpa-psk.c b/src/nm-ap-security-wpa-psk.c index 65680bb8aa..8b92c2c63d 100644 --- a/src/nm-ap-security-wpa-psk.c +++ b/src/nm-ap-security-wpa-psk.c @@ -95,21 +95,18 @@ out: } NMAPSecurityWPA_PSK * -nm_ap_security_wpa_psk_new_from_ap (NMAccessPoint *ap, int we_cipher) +nm_ap_security_wpa_psk_new (guint32 capabilities, int we_cipher) { - NMAPSecurityWPA_PSK * security = NULL; - guint32 caps; + NMAPSecurityWPA_PSK *security; - g_return_val_if_fail (ap != NULL, NULL); g_return_val_if_fail (we_cipher == NM_AUTH_TYPE_WPA_PSK_AUTO || we_cipher == IW_AUTH_CIPHER_TKIP || (we_cipher == IW_AUTH_CIPHER_CCMP), NULL); security = g_object_new (NM_TYPE_AP_SECURITY_WPA_PSK, NULL); nm_ap_security_set_we_cipher (NM_AP_SECURITY (security), we_cipher); - caps = nm_ap_get_capabilities (ap); - if (caps & NM_802_11_CAP_PROTO_WPA2) + if (capabilities & NM_802_11_CAP_PROTO_WPA2) security->priv->wpa_version = IW_AUTH_WPA_VERSION_WPA2; - else if (caps & NM_802_11_CAP_PROTO_WPA) + else if (capabilities & NM_802_11_CAP_PROTO_WPA) security->priv->wpa_version = IW_AUTH_WPA_VERSION_WPA; security->priv->key_mgt = IW_AUTH_KEY_MGMT_PSK; diff --git a/src/nm-ap-security-wpa-psk.h b/src/nm-ap-security-wpa-psk.h index 005d0ac6ad..95aa5f13cb 100644 --- a/src/nm-ap-security-wpa-psk.h +++ b/src/nm-ap-security-wpa-psk.h @@ -54,8 +54,6 @@ struct _NMAPSecurityWPA_PSKClass GType nm_ap_security_wpa_psk_get_type (void); NMAPSecurityWPA_PSK * nm_ap_security_wpa_psk_new_deserialize (DBusMessageIter *iter, int we_cipher); - -struct NMAccessPoint; -NMAPSecurityWPA_PSK * nm_ap_security_wpa_psk_new_from_ap (struct NMAccessPoint *ap, int we_cipher); +NMAPSecurityWPA_PSK * nm_ap_security_wpa_psk_new (guint32 capabilities, int we_cipher); #endif /* NM_AP_SECURITY_WPA_PSK_H */ diff --git a/src/nm-ap-security.c b/src/nm-ap-security.c index d7777e9d88..2fc21d514b 100644 --- a/src/nm-ap-security.c +++ b/src/nm-ap-security.c @@ -45,14 +45,40 @@ struct _NMAPSecurityPrivate gboolean dispose_has_run; }; +#define WPA2_CCMP_PSK (NM_802_11_CAP_PROTO_WPA2 | NM_802_11_CAP_CIPHER_CCMP | NM_802_11_CAP_KEY_MGMT_PSK) +#define WPA2_TKIP_PSK (NM_802_11_CAP_PROTO_WPA2 | NM_802_11_CAP_CIPHER_TKIP | NM_802_11_CAP_KEY_MGMT_PSK) +#define WPA2_EAP (NM_802_11_CAP_PROTO_WPA2 | NM_802_11_CAP_KEY_MGMT_802_1X) +#define WPA_CCMP_PSK (NM_802_11_CAP_PROTO_WPA | NM_802_11_CAP_CIPHER_CCMP | NM_802_11_CAP_KEY_MGMT_PSK) +#define WPA_TKIP_PSK (NM_802_11_CAP_PROTO_WPA | NM_802_11_CAP_CIPHER_TKIP | NM_802_11_CAP_KEY_MGMT_PSK) +#define WPA_EAP (NM_802_11_CAP_PROTO_WPA | NM_802_11_CAP_KEY_MGMT_802_1X) +#define WEP_WEP104 (NM_802_11_CAP_PROTO_WEP | NM_802_11_CAP_CIPHER_WEP104) +#define WEP_WEP40 (NM_802_11_CAP_PROTO_WEP | NM_802_11_CAP_CIPHER_WEP40) +#define LEAP (NM_802_11_CAP_KEY_MGMT_802_1X) + NMAPSecurity * -nm_ap_security_new (int we_cipher) +nm_ap_security_new (guint32 capabilities, gboolean encrypted) { - NMAPSecurity * security; + NMAPSecurity *security; + + /* Deteremine best encryption algorithm to use */ + if (((capabilities & WPA_CCMP_PSK) == WPA_CCMP_PSK) || ((capabilities & WPA2_CCMP_PSK) == WPA2_CCMP_PSK)) + security = NM_AP_SECURITY (nm_ap_security_wpa_psk_new (capabilities, IW_AUTH_CIPHER_CCMP)); + else if (((capabilities & WPA_TKIP_PSK) == WPA_TKIP_PSK) || ((capabilities & WPA2_TKIP_PSK) == WPA2_TKIP_PSK)) + security = NM_AP_SECURITY (nm_ap_security_wpa_psk_new (capabilities, IW_AUTH_CIPHER_TKIP)); + else if (((capabilities & WPA_EAP) == WPA_EAP) || ((capabilities & WPA2_EAP) == WPA2_EAP)) + security = NM_AP_SECURITY (nm_ap_security_wpa_eap_new (capabilities)); + else if ((capabilities & WEP_WEP104) == WEP_WEP104) + security = NM_AP_SECURITY (nm_ap_security_wep_new (IW_AUTH_CIPHER_WEP104)); + else if ((capabilities & WEP_WEP40) == WEP_WEP40) + security = NM_AP_SECURITY (nm_ap_security_wep_new (IW_AUTH_CIPHER_WEP40)); + else if ((capabilities & LEAP) == LEAP) + security = NM_AP_SECURITY (nm_ap_security_leap_new ()); + else if (!encrypted) { + security = g_object_new (NM_TYPE_AP_SECURITY, NULL); + security->priv->we_cipher = IW_AUTH_CIPHER_NONE; + security->priv->key = NULL; + } - security = g_object_new (NM_TYPE_AP_SECURITY, NULL); - security->priv->we_cipher = we_cipher; - security->priv->key = NULL; return security; } @@ -72,7 +98,7 @@ nm_ap_security_new_deserialize (DBusMessageIter *iter) dbus_message_iter_get_basic (iter, &we_cipher); if (we_cipher == IW_AUTH_CIPHER_NONE) - security = nm_ap_security_new (we_cipher); + security = nm_ap_security_new (NM_DEVICE_CAP_NONE, FALSE); else { /* Advance to start of cipher-dependent options */ @@ -111,44 +137,6 @@ out: } -#define WPA2_CCMP_PSK (NM_802_11_CAP_PROTO_WPA2 | NM_802_11_CAP_CIPHER_CCMP | NM_802_11_CAP_KEY_MGMT_PSK) -#define WPA2_TKIP_PSK (NM_802_11_CAP_PROTO_WPA2 | NM_802_11_CAP_CIPHER_TKIP | NM_802_11_CAP_KEY_MGMT_PSK) -#define WPA2_EAP (NM_802_11_CAP_PROTO_WPA2 | NM_802_11_CAP_KEY_MGMT_802_1X) -#define WPA_CCMP_PSK (NM_802_11_CAP_PROTO_WPA | NM_802_11_CAP_CIPHER_CCMP | NM_802_11_CAP_KEY_MGMT_PSK) -#define WPA_TKIP_PSK (NM_802_11_CAP_PROTO_WPA | NM_802_11_CAP_CIPHER_TKIP | NM_802_11_CAP_KEY_MGMT_PSK) -#define WPA_EAP (NM_802_11_CAP_PROTO_WPA | NM_802_11_CAP_KEY_MGMT_802_1X) -#define WEP_WEP104 (NM_802_11_CAP_PROTO_WEP | NM_802_11_CAP_CIPHER_WEP104) -#define WEP_WEP40 (NM_802_11_CAP_PROTO_WEP | NM_802_11_CAP_CIPHER_WEP40) -#define LEAP (NM_802_11_CAP_KEY_MGMT_802_1X) -NMAPSecurity * -nm_ap_security_new_from_ap (NMAccessPoint *ap) -{ - NMAPSecurity * security = NULL; - guint32 caps; - - g_return_val_if_fail (ap != NULL, NULL); - - /* Deteremine best encryption algorithm to use */ - caps = nm_ap_get_capabilities (ap); - if (((caps & WPA_CCMP_PSK) == WPA_CCMP_PSK) || ((caps & WPA2_CCMP_PSK) == WPA2_CCMP_PSK)) - security = NM_AP_SECURITY (nm_ap_security_wpa_psk_new_from_ap (ap, IW_AUTH_CIPHER_CCMP)); - else if (((caps & WPA_TKIP_PSK) == WPA_TKIP_PSK) || ((caps & WPA2_TKIP_PSK) == WPA2_TKIP_PSK)) - security = NM_AP_SECURITY (nm_ap_security_wpa_psk_new_from_ap (ap, IW_AUTH_CIPHER_TKIP)); - else if (((caps & WPA_EAP) == WPA_EAP) || ((caps & WPA2_EAP) == WPA2_EAP)) - security = NM_AP_SECURITY (nm_ap_security_wpa_eap_new_from_ap (ap)); - else if ((caps & WEP_WEP104) == WEP_WEP104) - security = NM_AP_SECURITY (nm_ap_security_wep_new_from_ap (ap, IW_AUTH_CIPHER_WEP104)); - else if ((caps & WEP_WEP40) == WEP_WEP40) - security = NM_AP_SECURITY (nm_ap_security_wep_new_from_ap (ap, IW_AUTH_CIPHER_WEP40)); - else if ((caps & LEAP) == LEAP) - security = NM_AP_SECURITY (nm_ap_security_leap_new_from_ap (ap)); - else if (!nm_ap_get_encrypted (ap)) - security = nm_ap_security_new (IW_AUTH_CIPHER_NONE); - - return security; -} - - guint32 nm_ap_security_get_default_capabilities (NMAPSecurity *self) { @@ -221,7 +209,11 @@ nm_ap_security_set_key (NMAPSecurity *self, const char *key, int key_len) static NMAPSecurity * real_copy_constructor (NMAPSecurity *self) { - NMAPSecurity * dst = nm_ap_security_new (self->priv->we_cipher); + NMAPSecurity *dst; + + dst = g_object_new (NM_TYPE_AP_SECURITY, NULL); + dst->priv->we_cipher = self->priv->we_cipher; + dst->priv->key = NULL; nm_ap_security_copy_properties (self, dst); return dst; diff --git a/src/nm-ap-security.h b/src/nm-ap-security.h index c16b717645..7ff9ee82f4 100644 --- a/src/nm-ap-security.h +++ b/src/nm-ap-security.h @@ -54,8 +54,6 @@ struct _NMAPSecurity NMAPSecurityPrivate *priv; }; -struct NMAccessPoint; - struct _NMAPSecurityClass { GObjectClass parent; @@ -79,12 +77,10 @@ GType nm_ap_security_get_type (void); NMAPSecurity * nm_ap_security_new_copy (NMAPSecurity *self); -NMAPSecurity * nm_ap_security_new (int we_cipher); +NMAPSecurity * nm_ap_security_new (guint32 capabilities, gboolean encrypted); NMAPSecurity * nm_ap_security_new_deserialize (DBusMessageIter *iter); -NMAPSecurity * nm_ap_security_new_from_ap (struct NMAccessPoint *ap); - int nm_ap_security_get_we_cipher (NMAPSecurity *self); const char * nm_ap_security_get_key (NMAPSecurity *self); diff --git a/src/nm-dbus-manager.c b/src/nm-dbus-manager.c index 285f0f27f8..3a241347db 100644 --- a/src/nm-dbus-manager.c +++ b/src/nm-dbus-manager.c @@ -109,16 +109,6 @@ nm_dbus_manager_init (NMDBusManager *self) } static void -cleanup_handler_data (gpointer item, gpointer user_data) -{ - MethodHandlerData * data = (MethodHandlerData *) item; - - nm_dbus_method_list_unref (data->list); - memset (data, 0, sizeof (MethodHandlerData)); - g_slice_free (MethodHandlerData, data); -} - -static void free_signal_handler_helper (gpointer item, gpointer user_data) { @@ -529,42 +519,6 @@ nm_dbus_manager_name_has_owner (NMDBusManager *self, return has_owner; } -static DBusHandlerResult -nm_dbus_manager_message_handler (DBusConnection *connection, - DBusMessage *message, - void *user_data) -{ - MethodHandlerData * data = (MethodHandlerData *) user_data; - NMDBusManager * self = data->self; - NMDbusMethodList * list = data->list; - DBusObjectPathMessageFunction custom_handler_func; - gboolean handled = FALSE; - DBusMessage * reply = NULL; - void * hdlr_user_data; - - g_return_val_if_fail (self != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); - g_return_val_if_fail (list != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); - - hdlr_user_data = nm_dbus_method_list_get_user_data (list); - - /* Try the method lists' custom handler first */ - custom_handler_func = nm_dbus_method_list_get_custom_handler_func (list); - if (custom_handler_func) { - handled = (*custom_handler_func) (connection, message, hdlr_user_data); - } else { - /* Generic handler for lists that don't specify a custom handler */ - handled = nm_dbus_method_list_dispatch (list, connection, message, - hdlr_user_data, &reply); - if (reply) { - dbus_connection_send (connection, reply, NULL); - dbus_message_unref (reply); - } - } - - return handled ? DBUS_HANDLER_RESULT_HANDLED - : DBUS_HANDLER_RESULT_NOT_YET_HANDLED; -} - static void proxy_name_owner_changed (DBusGProxy *proxy, const char *name, diff --git a/src/nm-dbus-nmi.c b/src/nm-dbus-nmi.c index 1814b688d1..942e5aef42 100644 --- a/src/nm-dbus-nmi.c +++ b/src/nm-dbus-nmi.c @@ -508,7 +508,7 @@ static void nm_dbus_get_network_data_cb (DBusPendingCall *pcall, void *user_data /* New AP, just add it to the list */ nm_ap_list_append_ap (cb_data->list, ap); } - nm_ap_unref (ap); + g_object_unref (ap); /* Ensure all devices get new information copied into their device lists */ nm_policy_schedule_device_ap_lists_update_from_allowed (cb_data->data); diff --git a/src/nm-device-802-11-wireless.c b/src/nm-device-802-11-wireless.c index d27eaf3c52..151a189d3f 100644 --- a/src/nm-device-802-11-wireless.c +++ b/src/nm-device-802-11-wireless.c @@ -66,6 +66,17 @@ G_DEFINE_TYPE (NMDevice80211Wireless, nm_device_802_11_wireless, NM_TYPE_DEVICE) #define NM_DEVICE_802_11_WIRELESS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_802_11_WIRELESS, NMDevice80211WirelessPrivate)) + +enum { + PROP_0, + PROP_HW_ADDRESS, + PROP_MODE, + PROP_BITRATE, + PROP_ACTIVE_NETWORK, + + LAST_PROP +}; + enum { NETWORK_ADDED, NETWORK_REMOVED, @@ -707,7 +718,7 @@ nm_device_802_11_wireless_copy_allowed_to_dev_list (NMDevice80211Wireless *self, NMAccessPoint * dst_ap = nm_ap_new_from_ap (src_ap); nm_ap_list_append_ap (dev_list, dst_ap); - nm_ap_unref (dst_ap); + g_object_unref (dst_ap); } nm_ap_list_iter_free (iter); } @@ -918,8 +929,7 @@ nm_device_802_11_wireless_get_best_ap (NMDevice80211Wireless *self) && !nm_ap_list_get_ap_by_essid (app_data->invalid_ap_list, essid) && nm_device_802_11_wireless_ap_list_get_ap_by_essid (self, essid)) { - nm_ap_ref (cur_ap); - return cur_ap; + return (NMAccessPoint *) g_object_ref (cur_ap); } } } @@ -961,7 +971,7 @@ nm_device_802_11_wireless_get_best_ap (NMDevice80211Wireless *self) best_ap = get_best_fallback_ap (self); if (best_ap) - nm_ap_ref (best_ap); + g_object_ref (best_ap); return best_ap; } @@ -1019,7 +1029,7 @@ nm_device_802_11_wireless_get_activation_ap (NMDevice80211Wireless *self, */ nm_ap_set_capabilities (ap, nm_ap_security_get_default_capabilities (security)); nm_ap_list_append_ap (dev_ap_list, ap); - nm_ap_unref (ap); + g_object_unref (ap); } else { @@ -1030,7 +1040,8 @@ nm_device_802_11_wireless_get_activation_ap (NMDevice80211Wireless *self, /* If we didn't get any security info, make some up. */ if (!security) - security = nm_ap_security_new_from_ap (ap); + security = nm_ap_security_new (nm_ap_get_capabilities (ap), + nm_ap_get_encrypted (ap)); } g_assert (security); nm_ap_set_security (ap, security); @@ -1171,8 +1182,11 @@ impl_device_get_active_networks (NMDevice80211Wireless *device, while ((ap = nm_ap_list_iter_next (list_iter))) { if (nm_ap_get_essid (ap)) { - g_ptr_array_add (*networks, - nm_dbus_get_object_path_for_network (NM_DEVICE (device), ap)); + /* FIXME: In theory, it should be possible to use something like: + g_ptr_array_add (*networks, ap); + and let dbus-glib get the already registered object path, but it crashes + NM currently. Figure it out. */ + g_ptr_array_add (*networks, g_strdup (g_object_get_data (ap, "dbus_glib_object_path"))); } } nm_ap_list_iter_free (list_iter); @@ -2042,7 +2056,8 @@ ap_need_key (NMDevice80211Wireless *self, * settings were changed. */ if (we_cipher != IW_AUTH_CIPHER_NONE) - nm_ap_set_security (ap, nm_ap_security_new_from_ap (ap)); + nm_ap_set_security (ap, nm_ap_security_new (nm_ap_get_capabilities (ap), + nm_ap_get_encrypted (ap))); } else { @@ -2380,7 +2395,7 @@ supplicant_iface_scanned_ap_cb (NMSupplicantInterface * iface, /* Remove outdated access points */ cull_scan_list (self); - nm_ap_unref (ap); + g_object_unref (ap); } @@ -3345,6 +3360,44 @@ nm_device_802_11_wireless_finalize (GObject *object) G_OBJECT_CLASS (parent_class)->finalize (object); } +static void +get_property (GObject *object, guint prop_id, + GValue *value, GParamSpec *pspec) +{ + NMDevice80211Wireless *device = NM_DEVICE_802_11_WIRELESS (object); + struct ether_addr hw_addr; + char hw_addr_buf[20]; + + switch (prop_id) { + case PROP_HW_ADDRESS: + memset (hw_addr_buf, 0, 20); + nm_device_802_11_wireless_get_address (device, &hw_addr); + iw_ether_ntop (&hw_addr, hw_addr_buf); + g_value_set_string (value, &hw_addr_buf[0]); + break; + case PROP_MODE: + g_value_set_int (value, nm_device_802_11_wireless_get_mode (device)); + break; + case PROP_BITRATE: + g_value_set_int (value, nm_device_802_11_wireless_get_bitrate (device)); + break; + case PROP_ACTIVE_NETWORK: + /* FIXME: */ +#if 0 + req = nm_device_get_act_request (NM_DEVICE (device)); + if (req && ap = nm_act_request_get_ap (req)) { + NMAccessPoint *tmp_ap; + + if ((tmp_ap = nm_device_802_11_wireless_ap_list_get_ap_by_essid (device, nm_ap_get_essid (ap)))) + g_value_set_object (value, tmp_ap); + } +#endif + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} static void nm_device_802_11_wireless_class_init (NMDevice80211WirelessClass *klass) @@ -3354,6 +3407,7 @@ nm_device_802_11_wireless_class_init (NMDevice80211WirelessClass *klass) g_type_class_add_private (object_class, sizeof (NMDevice80211WirelessPrivate)); + object_class->get_property = get_property; object_class->dispose = nm_device_802_11_wireless_dispose; object_class->finalize = nm_device_802_11_wireless_finalize; @@ -3374,6 +3428,36 @@ nm_device_802_11_wireless_class_init (NMDevice80211WirelessClass *klass) parent_class->activation_cancel_handler = real_activation_cancel_handler; + /* Properties */ + g_object_class_install_property + (object_class, PROP_HW_ADDRESS, + g_param_spec_string (NM_DEVICE_802_11_WIRELESS_HW_ADDRESS, + "MAC Address", + "Hardware MAC address", + NULL, + G_PARAM_READABLE)); + g_object_class_install_property + (object_class, PROP_MODE, + g_param_spec_int (NM_DEVICE_802_11_WIRELESS_MODE, + "Mode", + "Mode", + 0, G_MAXINT32, 0, + G_PARAM_READABLE)); + g_object_class_install_property + (object_class, PROP_BITRATE, + g_param_spec_int (NM_DEVICE_802_11_WIRELESS_BITRATE, + "Bitrate", + "Bitrate", + 0, G_MAXINT32, 0, + G_PARAM_READABLE)); + g_object_class_install_property + (object_class, PROP_ACTIVE_NETWORK, + g_param_spec_object (NM_DEVICE_802_11_WIRELESS_ACTIVE_NETWORK, + "Active network", + "Currently active network", + G_TYPE_OBJECT, + G_PARAM_READABLE)); + /* Signals */ signals[NETWORK_ADDED] = g_signal_new ("network-added", @@ -3381,9 +3465,9 @@ nm_device_802_11_wireless_class_init (NMDevice80211WirelessClass *klass) G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (NMDevice80211WirelessClass, network_added), NULL, NULL, - g_cclosure_marshal_VOID__POINTER, + g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, - G_TYPE_POINTER); + G_TYPE_OBJECT); signals[NETWORK_REMOVED] = g_signal_new ("network-removed", @@ -3391,9 +3475,9 @@ nm_device_802_11_wireless_class_init (NMDevice80211WirelessClass *klass) G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (NMDevice80211WirelessClass, network_removed), NULL, NULL, - g_cclosure_marshal_VOID__POINTER, + g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, - G_TYPE_POINTER); + G_TYPE_OBJECT); dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (klass), &dbus_glib_nm_device_802_11_wireless_object_info); diff --git a/src/nm-device-802-11-wireless.h b/src/nm-device-802-11-wireless.h index e748e0985c..b8e696dc0e 100644 --- a/src/nm-device-802-11-wireless.h +++ b/src/nm-device-802-11-wireless.h @@ -42,6 +42,12 @@ G_BEGIN_DECLS #define NM_IS_DEVICE_802_11_WIRELESS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_802_11_WIRELESS)) #define NM_DEVICE_802_11_WIRELESS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_802_11_WIRELESS, NMDevice80211WirelessClass)) + +#define NM_DEVICE_802_11_WIRELESS_HW_ADDRESS "hw-address" +#define NM_DEVICE_802_11_WIRELESS_MODE "mode" +#define NM_DEVICE_802_11_WIRELESS_BITRATE "bitrate" +#define NM_DEVICE_802_11_WIRELESS_ACTIVE_NETWORK "active-network" + typedef enum NMWirelessScanInterval { NM_WIRELESS_SCAN_INTERVAL_INIT = 0, diff --git a/src/nm-device-802-3-ethernet.c b/src/nm-device-802-3-ethernet.c index d546b56185..07f9bc0206 100644 --- a/src/nm-device-802-3-ethernet.c +++ b/src/nm-device-802-3-ethernet.c @@ -413,15 +413,19 @@ static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - /* FIXME: */ -/* NMDevice8023EthernetPrivate *priv = NM_DEVICE_802_3_ETHERNET_GET_PRIVATE (object); */ + NMDevice8023Ethernet *device = NM_DEVICE_802_3_ETHERNET (object); + struct ether_addr hw_addr; + char hw_addr_buf[20]; switch (prop_id) { -/* case PROP_HW_ADDRESS: */ -/* g_value_set_int (value, ); */ -/* break; */ + case PROP_HW_ADDRESS: + memset (hw_addr_buf, 0, 20); + nm_device_802_3_ethernet_get_address (device, &hw_addr); + iw_ether_ntop (&hw_addr, hw_addr_buf); + g_value_set_string (value, &hw_addr_buf[0]); + break; case PROP_SPEED: - g_value_set_int (value, nm_device_802_3_ethernet_get_speed (NM_DEVICE_802_3_ETHERNET (object))); + g_value_set_int (value, nm_device_802_3_ethernet_get_speed (device)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -453,19 +457,19 @@ nm_device_802_3_ethernet_class_init (NMDevice8023EthernetClass *klass) /* properties */ g_object_class_install_property (object_class, PROP_HW_ADDRESS, - g_param_spec_int (NM_DEVICE_802_3_ETHERNET_HW_ADDRESS, - "MAC Address", - "Hardware MAC address", - 0, G_MAXINT32, 0, - G_PARAM_READABLE)); + g_param_spec_string (NM_DEVICE_802_3_ETHERNET_HW_ADDRESS, + "MAC Address", + "Hardware MAC address", + NULL, + G_PARAM_READABLE)); g_object_class_install_property (object_class, PROP_SPEED, g_param_spec_int (NM_DEVICE_802_3_ETHERNET_SPEED, - "Speed", - "Speed", - 0, G_MAXINT32, 0, - G_PARAM_READABLE)); + "Speed", + "Speed", + 0, G_MAXINT32, 0, + G_PARAM_READABLE)); dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (klass), &dbus_glib_nm_device_802_3_ethernet_object_info); diff --git a/src/nm-device-interface.c b/src/nm-device-interface.c index 49eba4983b..fce46d3807 100644 --- a/src/nm-device-interface.c +++ b/src/nm-device-interface.c @@ -1,5 +1,6 @@ #include "nm-device-interface.h" +#include "nm-ip4-config.h" static gboolean impl_device_deactivate (NMDeviceInterface *device, GError **err); @@ -64,6 +65,14 @@ nm_device_interface_init (gpointer g_iface) g_object_interface_install_property (g_iface, + g_param_spec_object (NM_DEVICE_INTERFACE_IP4_CONFIG, + "IP4 Config", + "IP4 Config", + G_TYPE_OBJECT, + G_PARAM_READWRITE)); + + g_object_interface_install_property + (g_iface, g_param_spec_uint (NM_DEVICE_INTERFACE_STATE, "State", "State", diff --git a/src/nm-device-interface.h b/src/nm-device-interface.h index a4ba31647b..eefcb27eec 100644 --- a/src/nm-device-interface.h +++ b/src/nm-device-interface.h @@ -16,6 +16,7 @@ #define NM_DEVICE_INTERFACE_DRIVER "driver" #define NM_DEVICE_INTERFACE_CAPABILITIES "capabilities" #define NM_DEVICE_INTERFACE_IP4_ADDRESS "ip4_address" +#define NM_DEVICE_INTERFACE_IP4_CONFIG "ip4_config" #define NM_DEVICE_INTERFACE_STATE "state" #define NM_DEVICE_INTERFACE_APP_DATA "app_data" /* Ugh */ #define NM_DEVICE_INTERFACE_DEVICE_TYPE "device_type" /* ugh */ @@ -28,6 +29,7 @@ typedef enum { NM_DEVICE_INTERFACE_PROP_DRIVER, NM_DEVICE_INTERFACE_PROP_CAPABILITIES, NM_DEVICE_INTERFACE_PROP_IP4_ADDRESS, + NM_DEVICE_INTERFACE_PROP_IP4_CONFIG, NM_DEVICE_INTERFACE_PROP_STATE, NM_DEVICE_INTERFACE_PROP_APP_DATA, NM_DEVICE_INTERFACE_PROP_DEVICE_TYPE diff --git a/src/nm-device.c b/src/nm-device.c index d4b1043155..5af4a9ddc8 100644 --- a/src/nm-device.c +++ b/src/nm-device.c @@ -1396,16 +1396,17 @@ nm_device_get_ip4_config (NMDevice *self) void nm_device_set_ip4_config (NMDevice *self, NMIP4Config *config) { - NMIP4Config *old_config; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - g_return_if_fail (self != NULL); + g_return_if_fail (NM_IS_DEVICE (self)); + + if (priv->ip4_config) { + g_object_unref (priv->ip4_config); + priv->ip4_config = NULL; + } - old_config = self->priv->ip4_config; if (config) - nm_ip4_config_ref (config); - self->priv->ip4_config = config; - if (old_config) - nm_ip4_config_unref (old_config); + priv->ip4_config = g_object_ref (config); } @@ -1611,11 +1612,7 @@ nm_device_dispose (GObject *object) */ nm_system_device_free_system_config (self, self->priv->system_config_data); - if (self->priv->ip4_config) - { - nm_ip4_config_unref (self->priv->ip4_config); - self->priv->ip4_config = NULL; - } + nm_device_set_ip4_config (self, NULL); if (self->priv->act_request) { @@ -1703,6 +1700,9 @@ get_property (GObject *object, guint prop_id, case NM_DEVICE_INTERFACE_PROP_IP4_ADDRESS: g_value_set_uint (value, priv->ip4_address); break; + case NM_DEVICE_INTERFACE_PROP_IP4_CONFIG: + g_value_set_object (value, priv->ip4_config); + break; case NM_DEVICE_INTERFACE_PROP_STATE: g_value_set_uint (value, priv->state); break; @@ -1764,6 +1764,10 @@ nm_device_class_init (NMDeviceClass *klass) NM_DEVICE_INTERFACE_IP4_ADDRESS); g_object_class_override_property (object_class, + NM_DEVICE_INTERFACE_PROP_IP4_CONFIG, + NM_DEVICE_INTERFACE_IP4_CONFIG); + + g_object_class_override_property (object_class, NM_DEVICE_INTERFACE_PROP_STATE, NM_DEVICE_INTERFACE_STATE); diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index fe3df351a3..1fcae77f8f 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -23,18 +23,23 @@ #include <glib.h> #include <stdio.h> #include <string.h> +#include "nm-ip4-config.h" +#include "nm-dbus-manager.h" #include "NetworkManager.h" #include "NetworkManagerUtils.h" -#include "nm-ip4-config.h" #include <netlink/route/addr.h> #include <netlink/utils.h> #include <netinet/in.h> -struct NMIP4Config -{ - guint refcount; +#include "nm-ip4-config-glue.h" + +G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, G_TYPE_OBJECT) + +#define NM_IP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IP4_CONFIG, NMIP4ConfigPrivate)) + +typedef struct { guint32 ip4_address; guint32 ip4_ptp_address; guint32 ip4_gateway; @@ -44,48 +49,75 @@ struct NMIP4Config guint32 mtu; /* Maximum Transmission Unit of the interface */ guint32 mss; /* Maximum Segment Size of the route */ - GSList * nameservers; - GSList * domains; + GArray *nameservers; + GPtrArray *domains; gchar * hostname; gchar * nis_domain; - GSList * nis_servers; + GArray *nis_servers; /* If this is a VPN/etc config that requires * another device (like Ethernet) to already have * an IP4Config before it can be used. */ gboolean secondary; +} NMIP4ConfigPrivate; + + +enum { + PROP_0, + PROP_ADDRESS, + PROP_GATEWAY, + PROP_NETMASK, + PROP_BROADCAST, + PROP_HOSTNAME, + PROP_NAMESERVERS, + PROP_DOMAINS, + PROP_NIS_DOMAIN, + PROP_NIS_SERVERS, + + LAST_PROP }; -NMIP4Config *nm_ip4_config_new (void) +NMIP4Config * +nm_ip4_config_new (void) { - NMIP4Config *config = g_slice_new0 (NMIP4Config); + GObject *object; + DBusGConnection *connection; + char *path; + static guint32 counter = 0; + + object = g_object_new (NM_TYPE_IP4_CONFIG, NULL); - config->refcount = 1; + connection = nm_dbus_manager_get_connection (nm_dbus_manager_get ()); + path = g_strdup_printf (NM_DBUS_PATH "/IP4Config/%d", counter++); - return config; + dbus_g_connection_register_g_object (connection, path, object); + g_free (path); + + return (NMIP4Config *) object; } NMIP4Config *nm_ip4_config_copy (NMIP4Config *src_config) { - NMIP4Config * dst_config; - int i, len; - - g_return_val_if_fail (src_config != NULL, NULL); + NMIP4Config *dst_config; + NMIP4ConfigPrivate *priv; + int i; + int len; - dst_config = g_slice_new0 (NMIP4Config); - dst_config->refcount = 1; + g_return_val_if_fail (NM_IS_IP4_CONFIG (src_config), NULL); - dst_config->ip4_address = nm_ip4_config_get_address (src_config); - dst_config->ip4_ptp_address = nm_ip4_config_get_ptp_address (src_config); - dst_config->ip4_gateway = nm_ip4_config_get_gateway (src_config); - dst_config->ip4_netmask = nm_ip4_config_get_netmask (src_config); - dst_config->ip4_broadcast = nm_ip4_config_get_broadcast (src_config); + dst_config = nm_ip4_config_new (); + priv = NM_IP4_CONFIG_GET_PRIVATE (dst_config); - dst_config->hostname = g_strdup (nm_ip4_config_get_hostname (src_config)); - dst_config->nis_domain = g_strdup (nm_ip4_config_get_nis_domain (src_config)); + nm_ip4_config_set_address (dst_config, nm_ip4_config_get_address (src_config)); + nm_ip4_config_set_ptp_address (dst_config, nm_ip4_config_get_ptp_address (src_config)); + nm_ip4_config_set_gateway (dst_config, nm_ip4_config_get_gateway (src_config)); + nm_ip4_config_set_netmask (dst_config, nm_ip4_config_get_netmask (src_config)); + nm_ip4_config_set_broadcast (dst_config, nm_ip4_config_get_broadcast (src_config)); + nm_ip4_config_set_hostname (dst_config, nm_ip4_config_get_hostname (src_config)); + nm_ip4_config_set_nis_domain (dst_config, nm_ip4_config_get_nis_domain (src_config)); len = nm_ip4_config_get_num_nameservers (src_config); for (i = 0; i < len; i++) @@ -102,260 +134,219 @@ NMIP4Config *nm_ip4_config_copy (NMIP4Config *src_config) return dst_config; } -void nm_ip4_config_ref (NMIP4Config *config) -{ - g_return_if_fail (config != NULL); - - config->refcount++; -} - -void nm_ip4_config_unref (NMIP4Config *config) -{ - g_return_if_fail (config != NULL); - - config->refcount--; - if (config->refcount <= 0) - { - g_free (config->hostname); - g_free (config->nis_domain); - g_slist_free (config->nameservers); - g_slist_foreach (config->domains, (GFunc) g_free, NULL); - g_slist_free (config->domains); - g_slist_free (config->nis_servers); - - memset (config, 0, sizeof (NMIP4Config)); - g_slice_free (NMIP4Config, config); - } -} - gboolean nm_ip4_config_get_secondary (NMIP4Config *config) { - g_return_val_if_fail (config != NULL, FALSE); + g_return_val_if_fail (NM_IS_IP4_CONFIG (config), FALSE); - return config->secondary; + return NM_IP4_CONFIG_GET_PRIVATE (config)->secondary; } void nm_ip4_config_set_secondary (NMIP4Config *config, gboolean secondary) { - g_return_if_fail (config != NULL); + g_return_if_fail (NM_IS_IP4_CONFIG (config)); - config->secondary = secondary; + NM_IP4_CONFIG_GET_PRIVATE (config)->secondary = secondary; } guint32 nm_ip4_config_get_address (NMIP4Config *config) { - g_return_val_if_fail (config != NULL, 0); + g_return_val_if_fail (NM_IS_IP4_CONFIG (config), 0); - return config->ip4_address; + return NM_IP4_CONFIG_GET_PRIVATE (config)->ip4_address; } void nm_ip4_config_set_address (NMIP4Config *config, guint32 addr) { - g_return_if_fail (config != NULL); + g_return_if_fail (NM_IS_IP4_CONFIG (config)); - config->ip4_address = addr; + NM_IP4_CONFIG_GET_PRIVATE (config)->ip4_address = addr; } guint32 nm_ip4_config_get_ptp_address (NMIP4Config *config) { - g_return_val_if_fail (config != NULL, 0); + g_return_val_if_fail (NM_IS_IP4_CONFIG (config), 0); - return config->ip4_ptp_address; + return NM_IP4_CONFIG_GET_PRIVATE (config)->ip4_ptp_address; } void nm_ip4_config_set_ptp_address (NMIP4Config *config, guint32 ptp_addr) { - g_return_if_fail (config != NULL); + g_return_if_fail (NM_IS_IP4_CONFIG (config)); - config->ip4_ptp_address = ptp_addr; + NM_IP4_CONFIG_GET_PRIVATE (config)->ip4_ptp_address = ptp_addr; } guint32 nm_ip4_config_get_gateway (NMIP4Config *config) { - g_return_val_if_fail (config != NULL, 0); + g_return_val_if_fail (NM_IS_IP4_CONFIG (config), 0); - return config->ip4_gateway; + return NM_IP4_CONFIG_GET_PRIVATE (config)->ip4_gateway; } void nm_ip4_config_set_gateway (NMIP4Config *config, guint32 gateway) { - g_return_if_fail (config != NULL); + g_return_if_fail (NM_IS_IP4_CONFIG (config)); - config->ip4_gateway = gateway; + NM_IP4_CONFIG_GET_PRIVATE (config)->ip4_gateway = gateway; } guint32 nm_ip4_config_get_netmask (NMIP4Config *config) { - g_return_val_if_fail (config != NULL, 0); + g_return_val_if_fail (NM_IS_IP4_CONFIG (config), 0); - return config->ip4_netmask; + return NM_IP4_CONFIG_GET_PRIVATE (config)->ip4_netmask; } void nm_ip4_config_set_netmask (NMIP4Config *config, guint32 netmask) { - g_return_if_fail (config != NULL); + g_return_if_fail (NM_IS_IP4_CONFIG (config)); - config->ip4_netmask = netmask; + NM_IP4_CONFIG_GET_PRIVATE (config)->ip4_netmask = netmask; } guint32 nm_ip4_config_get_broadcast (NMIP4Config *config) { - g_return_val_if_fail (config != NULL, 0); + g_return_val_if_fail (NM_IS_IP4_CONFIG (config), 0); - return config->ip4_broadcast; + return NM_IP4_CONFIG_GET_PRIVATE (config)->ip4_broadcast; } void nm_ip4_config_set_broadcast (NMIP4Config *config, guint32 broadcast) { - g_return_if_fail (config != NULL); + g_return_if_fail (NM_IS_IP4_CONFIG (config)); - config->ip4_broadcast = broadcast; + NM_IP4_CONFIG_GET_PRIVATE (config)->ip4_broadcast = broadcast; } void nm_ip4_config_add_nameserver (NMIP4Config *config, guint32 nameserver) { - g_return_if_fail (config != NULL); + g_return_if_fail (NM_IS_IP4_CONFIG (config)); if (nameserver != 0) - config->nameservers = g_slist_append (config->nameservers, GINT_TO_POINTER (nameserver)); + g_array_append_val (NM_IP4_CONFIG_GET_PRIVATE (config)->nameservers, nameserver); } guint32 nm_ip4_config_get_nameserver (NMIP4Config *config, guint i) { - guint nameserver; - - g_return_val_if_fail (config != NULL, 0); - g_return_val_if_fail (i < g_slist_length (config->nameservers), 0); + g_return_val_if_fail (NM_IS_IP4_CONFIG (config), 0); - if ((nameserver = GPOINTER_TO_UINT (g_slist_nth_data (config->nameservers, i)))) - return nameserver; - return 0; + return g_array_index (NM_IP4_CONFIG_GET_PRIVATE (config)->nameservers, guint32, i); } guint32 nm_ip4_config_get_num_nameservers (NMIP4Config *config) { - g_return_val_if_fail (config != NULL, 0); + g_return_val_if_fail (NM_IS_IP4_CONFIG (config), 0); - return (g_slist_length (config->nameservers)); + return NM_IP4_CONFIG_GET_PRIVATE (config)->nameservers->len; } void nm_ip4_config_add_nis_server (NMIP4Config *config, guint32 nis_server) { - g_return_if_fail (config != NULL); + g_return_if_fail (NM_IS_IP4_CONFIG (config)); - config->nis_servers = g_slist_append (config->nis_servers, GINT_TO_POINTER (nis_server)); + g_array_append_val (NM_IP4_CONFIG_GET_PRIVATE (config)->nis_servers, nis_server); } guint32 nm_ip4_config_get_nis_server (NMIP4Config *config, guint i) { - guint nis_server; - - g_return_val_if_fail (config != NULL, 0); - g_return_val_if_fail (i < g_slist_length (config->nis_servers), 0); + g_return_val_if_fail (NM_IS_IP4_CONFIG (config), 0); - if ((nis_server = GPOINTER_TO_UINT (g_slist_nth_data (config->nis_servers, i)))) - return nis_server; - return 0; + return g_array_index (NM_IP4_CONFIG_GET_PRIVATE (config)->nis_servers, guint32, i); } guint32 nm_ip4_config_get_num_nis_servers (NMIP4Config *config) { - g_return_val_if_fail (config != NULL, 0); + g_return_val_if_fail (NM_IS_IP4_CONFIG (config), 0); - return (g_slist_length (config->nis_servers)); + return NM_IP4_CONFIG_GET_PRIVATE (config)->nis_servers->len; } void nm_ip4_config_add_domain (NMIP4Config *config, const char *domain) { - g_return_if_fail (config != NULL); + g_return_if_fail (NM_IS_IP4_CONFIG (config)); g_return_if_fail (domain != NULL); if (!strlen (domain)) return; - config->domains = g_slist_append (config->domains, g_strdup (domain)); + g_ptr_array_add (NM_IP4_CONFIG_GET_PRIVATE (config)->domains, g_strdup (domain)); } void nm_ip4_config_set_hostname (NMIP4Config *config, const char *hostname) { - g_return_if_fail (config != NULL); + g_return_if_fail (NM_IS_IP4_CONFIG (config)); g_return_if_fail (hostname != NULL); if (!strlen (hostname)) return; - config->hostname = g_strdup (hostname); + NM_IP4_CONFIG_GET_PRIVATE (config)->hostname = g_strdup (hostname); } const char *nm_ip4_config_get_hostname (NMIP4Config *config) { - g_return_val_if_fail (config != NULL, NULL); + g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL); - return config->hostname; + return NM_IP4_CONFIG_GET_PRIVATE (config)->hostname; } void nm_ip4_config_set_nis_domain (NMIP4Config *config, const char *domain) { - g_return_if_fail (config != NULL); + g_return_if_fail (NM_IS_IP4_CONFIG (config)); g_return_if_fail (domain != NULL); if (!strlen (domain)) return; - config->nis_domain = g_strdup (domain); + NM_IP4_CONFIG_GET_PRIVATE (config)->nis_domain = g_strdup (domain); } const char *nm_ip4_config_get_nis_domain (NMIP4Config *config) { - g_return_val_if_fail( config != NULL, NULL); - return config->nis_domain; + g_return_val_if_fail( NM_IS_IP4_CONFIG (config), NULL); + return NM_IP4_CONFIG_GET_PRIVATE (config)->nis_domain; } const char *nm_ip4_config_get_domain (NMIP4Config *config, guint i) { - const char *domain; + g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL); - g_return_val_if_fail (config != NULL, NULL); - g_return_val_if_fail (i < g_slist_length (config->domains), NULL); - - if ((domain = (const char *) g_slist_nth_data (config->domains, i))) - return domain; - return NULL; + return (const char *) g_ptr_array_index (NM_IP4_CONFIG_GET_PRIVATE (config)->domains, i); } guint32 nm_ip4_config_get_num_domains (NMIP4Config *config) { - g_return_val_if_fail (config != NULL, 0); + g_return_val_if_fail (NM_IS_IP4_CONFIG (config), 0); - return (g_slist_length (config->domains)); + return NM_IP4_CONFIG_GET_PRIVATE (config)->domains->len; } guint32 nm_ip4_config_get_mtu (NMIP4Config *config) { - g_return_val_if_fail (config != NULL, 0); + g_return_val_if_fail (NM_IS_IP4_CONFIG (config), 0); - return config->mtu; + return NM_IP4_CONFIG_GET_PRIVATE (config)->mtu; } void nm_ip4_config_set_mtu (NMIP4Config *config, guint32 mtu) { - g_return_if_fail (config != NULL); + g_return_if_fail (NM_IS_IP4_CONFIG (config)); - config->mtu = mtu; + NM_IP4_CONFIG_GET_PRIVATE (config)->mtu = mtu; } guint32 nm_ip4_config_get_mss (NMIP4Config *config) { - g_return_val_if_fail (config != NULL, 0); + g_return_val_if_fail (NM_IS_IP4_CONFIG (config), 0); - return config->mss; + return NM_IP4_CONFIG_GET_PRIVATE (config)->mss; } void nm_ip4_config_set_mss (NMIP4Config *config, guint32 mss) { - g_return_if_fail (config != NULL); + g_return_if_fail (NM_IS_IP4_CONFIG (config)); - config->mss = mss; + NM_IP4_CONFIG_GET_PRIVATE (config)->mss = mss; } /* libnl convenience/conversion functions */ @@ -412,25 +403,26 @@ static int ip4_addr_to_rtnl_broadcast (guint32 ip4_broadcast, struct rtnl_addr * struct rtnl_addr * nm_ip4_config_to_rtnl_addr (NMIP4Config *config, guint32 flags) { + NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config); struct rtnl_addr * addr = NULL; gboolean success = TRUE; - g_return_val_if_fail (config != NULL, NULL); + g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL); if (!(addr = rtnl_addr_alloc())) return NULL; if (flags & NM_RTNL_ADDR_ADDR) - success = (ip4_addr_to_rtnl_local (config->ip4_address, addr) >= 0); + success = (ip4_addr_to_rtnl_local (priv->ip4_address, addr) >= 0); if (flags & NM_RTNL_ADDR_PTP_ADDR) - success = (ip4_addr_to_rtnl_peer (config->ip4_ptp_address, addr) >= 0); + success = (ip4_addr_to_rtnl_peer (priv->ip4_ptp_address, addr) >= 0); if (flags & NM_RTNL_ADDR_NETMASK) - ip4_addr_to_rtnl_prefixlen (config->ip4_netmask, addr); + ip4_addr_to_rtnl_prefixlen (priv->ip4_netmask, addr); if (flags & NM_RTNL_ADDR_BROADCAST) - success = (ip4_addr_to_rtnl_broadcast (config->ip4_broadcast, addr) >= 0); + success = (ip4_addr_to_rtnl_broadcast (priv->ip4_broadcast, addr) >= 0); if (!success) { @@ -440,3 +432,145 @@ struct rtnl_addr * nm_ip4_config_to_rtnl_addr (NMIP4Config *config, guint32 flag return addr; } + +static void +nm_ip4_config_init (NMIP4Config *config) +{ + NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config); + + priv->nameservers = g_array_new (FALSE, TRUE, sizeof (guint32)); + priv->nis_servers = g_array_new (FALSE, TRUE, sizeof (guint32)); + priv->domains = g_ptr_array_new (); +} + +static void +finalize (GObject *object) +{ + NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object); + + g_free (priv->hostname); + g_free (priv->nis_domain); + g_array_free (priv->nameservers, TRUE); + g_ptr_array_free (priv->domains, TRUE); + g_array_free (priv->nis_servers, TRUE); +} + +static void +get_property (GObject *object, guint prop_id, + GValue *value, GParamSpec *pspec) +{ + NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object); + + switch (prop_id) { + case PROP_ADDRESS: + g_value_set_uint (value, priv->ip4_address); + break; + case PROP_GATEWAY: + g_value_set_uint (value, priv->ip4_gateway); + break; + case PROP_NETMASK: + g_value_set_uint (value, priv->ip4_netmask); + break; + case PROP_BROADCAST: + g_value_set_uint (value, priv->ip4_broadcast); + break; + case PROP_HOSTNAME: + g_value_set_string (value, priv->hostname); + break; + case PROP_NAMESERVERS: + g_value_set_boxed (value, priv->nameservers); + break; + case PROP_DOMAINS: + g_value_set_boxed (value, priv->domains); + break; + case PROP_NIS_DOMAIN: + g_value_set_string (value, priv->nis_domain); + break; + case PROP_NIS_SERVERS: + g_value_set_boxed (value, priv->nis_servers); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +nm_ip4_config_class_init (NMIP4ConfigClass *config_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (config_class); + + g_type_class_add_private (config_class, sizeof (NMIP4ConfigPrivate)); + + /* virtual methods */ + object_class->get_property = get_property; + object_class->finalize = finalize; + + /* properties */ + g_object_class_install_property + (object_class, PROP_ADDRESS, + g_param_spec_uint (NM_IP4_CONFIG_ADDRESS, + "Address", + "IP4 address", + 0, G_MAXUINT32, 0, + G_PARAM_READABLE)); + g_object_class_install_property + (object_class, PROP_GATEWAY, + g_param_spec_uint (NM_IP4_CONFIG_GATEWAY, + "Gateway", + "Gateway address", + 0, G_MAXUINT32, 0, + G_PARAM_READABLE)); + g_object_class_install_property + (object_class, PROP_NETMASK, + g_param_spec_uint (NM_IP4_CONFIG_NETMASK, + "Netmask", + "Netmask address", + 0, G_MAXUINT32, 0, + G_PARAM_READABLE)); + g_object_class_install_property + (object_class, PROP_BROADCAST, + g_param_spec_uint (NM_IP4_CONFIG_BROADCAST, + "Broadcast", + "Broadcast address", + 0, G_MAXUINT32, 0, + G_PARAM_READABLE)); + g_object_class_install_property + (object_class, PROP_HOSTNAME, + g_param_spec_string (NM_IP4_CONFIG_HOSTNAME, + "Hostname", + "Hostname", + NULL, + G_PARAM_READABLE)); + g_object_class_install_property + (object_class, PROP_NAMESERVERS, + g_param_spec_boxed (NM_IP4_CONFIG_NAMESERVERS, + "Nameservers", + "DNS list", + DBUS_TYPE_G_UINT_ARRAY, + G_PARAM_READABLE)); + g_object_class_install_property + (object_class, PROP_DOMAINS, + g_param_spec_boxed (NM_IP4_CONFIG_DOMAINS, + "Domains", + "Domains", + dbus_g_type_get_collection ("GPtrArray", G_TYPE_STRING), + G_PARAM_READABLE)); + g_object_class_install_property + (object_class, PROP_NIS_DOMAIN, + g_param_spec_string (NM_IP4_CONFIG_NIS_DOMAIN, + "NIS domain", + "NIS domain name", + NULL, + G_PARAM_READABLE)); + g_object_class_install_property + (object_class, PROP_NIS_SERVERS, + g_param_spec_boxed (NM_IP4_CONFIG_NIS_SERVERS, + "NIS servers", + "NIS servers", + DBUS_TYPE_G_UINT_ARRAY, + G_PARAM_READABLE)); + + dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (config_class), + &dbus_glib_nm_ip4_config_object_info); +} diff --git a/src/nm-ip4-config.h b/src/nm-ip4-config.h index 9bbd2231dc..d3e4f44d55 100644 --- a/src/nm-ip4-config.h +++ b/src/nm-ip4-config.h @@ -22,15 +22,39 @@ #ifndef NM_IP4_CONFIG_H #define NM_IP4_CONFIG_H -#include <glib.h> +#include <glib/gtypes.h> +#include <glib-object.h> -typedef struct NMIP4Config NMIP4Config; +#define NM_TYPE_IP4_CONFIG (nm_ip4_config_get_type ()) +#define NM_IP4_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_IP4_CONFIG, NMIP4Config)) +#define NM_IP4_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_IP4_CONFIG, NMIP4ConfigClass)) +#define NM_IS_IP4_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_IP4_CONFIG)) +#define NM_IS_IP4_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_IP4_CONFIG)) +#define NM_IP4_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_IP4_CONFIG, NMIP4ConfigClass)) + +typedef struct { + GObject parent; +} NMIP4Config; + +typedef struct { + GObjectClass parent; +} NMIP4ConfigClass; + +#define NM_IP4_CONFIG_ADDRESS "address" +#define NM_IP4_CONFIG_GATEWAY "gateway" +#define NM_IP4_CONFIG_NETMASK "netmask" +#define NM_IP4_CONFIG_BROADCAST "broadcast" +#define NM_IP4_CONFIG_HOSTNAME "hostname" +#define NM_IP4_CONFIG_NAMESERVERS "nameservers" +#define NM_IP4_CONFIG_DOMAINS "domains" +#define NM_IP4_CONFIG_NIS_DOMAIN "nis-domain" +#define NM_IP4_CONFIG_NIS_SERVERS "nis-servers" + +GType nm_ip4_config_get_type (void); NMIP4Config * nm_ip4_config_new (void); NMIP4Config * nm_ip4_config_copy (NMIP4Config *config); -void nm_ip4_config_ref (NMIP4Config *config); -void nm_ip4_config_unref (NMIP4Config *config); gboolean nm_ip4_config_get_secondary (NMIP4Config *config); void nm_ip4_config_set_secondary (NMIP4Config *config, gboolean secondary); @@ -86,5 +110,4 @@ void nm_ip4_config_set_mss (NMIP4Config *config, guint32 mss); struct rtnl_addr * nm_ip4_config_to_rtnl_addr (NMIP4Config *config, guint32 flags); - -#endif +#endif /* NM_IP4_CONFIG_H */ diff --git a/src/vpn-manager/nm-vpn-connection.c b/src/vpn-manager/nm-vpn-connection.c index 9afa6ca364..e3aa35a9e4 100644 --- a/src/vpn-manager/nm-vpn-connection.c +++ b/src/vpn-manager/nm-vpn-connection.c @@ -99,7 +99,7 @@ void nm_vpn_connection_unref (NMVPNConnection *connection) if (connection->parent_dev) g_object_unref (G_OBJECT (connection->parent_dev)); if (connection->ip4_config) - nm_ip4_config_unref (connection->ip4_config); + g_object_unref (connection->ip4_config); g_free (connection->vpn_iface); g_object_unref (connection->named_manager); @@ -231,15 +231,12 @@ static void nm_vpn_connection_set_ip4_config (NMVPNConnection *con, NMIP4Config if (con->ip4_config) { - nm_ip4_config_unref (con->ip4_config); + g_object_unref (con->ip4_config); con->ip4_config = NULL; } if (ip4_config) - { - nm_ip4_config_ref (ip4_config); - con->ip4_config = ip4_config; - } + con->ip4_config = g_object_ref (ip4_config); } static void nm_vpn_connection_set_parent_device (NMVPNConnection *con, NMDevice *parent_dev) diff --git a/src/vpn-manager/nm-vpn-service.c b/src/vpn-manager/nm-vpn-service.c index efa84572e6..ca892933e1 100644 --- a/src/vpn-manager/nm-vpn-service.c +++ b/src/vpn-manager/nm-vpn-service.c @@ -891,7 +891,7 @@ nm_vpn_service_stage4_ip4_config_get_old (NMVPNService *service, out: if (!success) { - nm_ip4_config_unref (config); + g_object_unref (config); nm_warning ("(VPN Service %s): did not receive valid IP config " "information.", service->service); @@ -1055,7 +1055,7 @@ out: if (login_banner) g_free (login_banner); if (!success) { if (config) - nm_ip4_config_unref (config); + g_object_unref (config); nm_warning ("(VPN Service %s): did not receive valid IP config " "information.", service->service); |