summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2004-07-25 02:40:19 +0000
committerDan Williams <dcbw@redhat.com>2004-07-25 02:40:19 +0000
commit8ae95bf5942d748269cd86467ba8d16db3acc6d7 (patch)
treef9c401e22ffec905e1b8fa9e78659fc7bbb31873 /src
parent846858e4872455ff54f73be5dc0afff0e38d81d7 (diff)
downloadNetworkManager-8ae95bf5942d748269cd86467ba8d16db3acc6d7.tar.gz
2004-07-24 Dan Williams <dcbw@redhat.com>
* src/NetworkManager.[ch] src/NetworkManagerDbus.[ch] src/NetworkManagerDevice.[ch] src/NetworkManagerPolicy.c src/NetworkManagerWireless.[ch] - Add many more g_return_if_fail()/g_return_val_if_fail() checks - Pass the NMData application data structure through all calls that need it so we can get rid of nm_get_global_data() - Change deallocation of the allowed_ap_list GSList in preparation for not completely clearing it every time we get an update, but instead getting incremental updates via GConf/dbus git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@20 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
Diffstat (limited to 'src')
-rw-r--r--src/NetworkManager.c71
-rw-r--r--src/NetworkManager.h4
-rw-r--r--src/NetworkManagerDbus.c176
-rw-r--r--src/NetworkManagerDbus.h2
-rw-r--r--src/NetworkManagerDevice.c60
-rw-r--r--src/NetworkManagerDevice.h2
-rw-r--r--src/NetworkManagerPolicy.c2
-rw-r--r--src/NetworkManagerWireless.c5
-rw-r--r--src/NetworkManagerWireless.h2
9 files changed, 172 insertions, 152 deletions
diff --git a/src/NetworkManager.c b/src/NetworkManager.c
index c17147be49..4933f49591 100644
--- a/src/NetworkManager.c
+++ b/src/NetworkManager.c
@@ -78,7 +78,7 @@ NMDevice * nm_create_device_and_add_to_list (NMData *data, const char *udi)
return (NULL);
}
- dev = nm_device_new (iface_name);
+ dev = nm_device_new (iface_name, data);
if (dev)
{
@@ -287,7 +287,7 @@ static void nm_add_current_devices (NMData *data)
gboolean nm_link_state_monitor (gpointer user_data)
{
NMData *data = (NMData *)user_data;
- GSList *element;
+ GSList *element;
g_return_val_if_fail (data != NULL, TRUE);
@@ -350,38 +350,6 @@ gboolean nm_link_state_monitor (gpointer user_data)
/*
- * nm_data_allowed_ap_list_free
- *
- * Frees the allowed access point list
- *
- */
-void nm_data_allowed_ap_list_free (NMData *data)
-{
- GSList *element;
-
- g_return_if_fail (data != NULL);
-
- if (!data->allowed_ap_list)
- return;
-
- element = data->allowed_ap_list;
- while (element)
- {
- if (element->data)
- {
- nm_ap_unref (element->data);
- element->data = NULL;
- }
-
- element = g_slist_next (element);
- }
-
- g_slist_free (data->allowed_ap_list);
- data->allowed_ap_list = NULL;
-}
-
-
-/*
* libhal callback function structure
*/
static LibHalFunctions hal_functions =
@@ -447,6 +415,19 @@ static NMData *nm_data_new (void)
/*
+ * nm_data_allowed_ap_list_element_free
+ *
+ * Frees each member of the allowed access point list before the list is
+ * disposed of.
+ *
+ */
+static void nm_data_allowed_ap_list_element_free (void *element, void *user_data)
+{
+ nm_ap_unref (element);
+}
+
+
+/*
* nm_data_dev_list_element_free
*
* Frees each member of the device list before the list is
@@ -469,28 +450,20 @@ static void nm_data_free (NMData *data)
{
g_return_if_fail (data != NULL);
+ nm_device_unref (data->active_device);
+ nm_device_unref (data->pending_device);
+
g_slist_foreach (data->dev_list, nm_data_dev_list_element_free, NULL);
g_slist_free (data->dev_list);
g_mutex_free (data->dev_list_mutex);
- nm_device_unref (data->active_device);
- nm_device_unref (data->pending_device);
- nm_data_allowed_ap_list_free (data);
+ g_slist_foreach (data->allowed_ap_list, nm_data_allowed_ap_list_element_free, NULL);
+ g_slist_free (data->allowed_ap_list);
+ g_mutex_free (data->allowed_ap_list_mutex);
}
/*
- * nm_get_global_data
- *
- * Return the global data structure
- *
- */
-NMData * nm_get_global_data (void)
-{
- return (nm_data);
-}
-
-/*
* nm_data_set_state_modified
*
* Locked function to protect state modification changes.
@@ -645,7 +618,7 @@ int main( int argc, char *argv[] )
allowed_ap_thread = g_thread_create (nm_policy_allowed_ap_refresh_worker, nm_data, FALSE, NULL);
/* Create our dbus service */
- nm_data->dbus_connection = nm_dbus_init ();
+ nm_data->dbus_connection = nm_dbus_init (nm_data);
if (nm_data->dbus_connection)
{
/* Create a watch function that monitors cards for link status (hal doesn't do
diff --git a/src/NetworkManager.h b/src/NetworkManager.h
index 984cf626dd..85f0f3e32a 100644
--- a/src/NetworkManager.h
+++ b/src/NetworkManager.h
@@ -45,8 +45,4 @@ typedef struct NMData NMData;
void nm_data_set_state_modified (NMData *data, gboolean modified);
-void nm_data_allowed_ap_list_free (NMData *data);
-
-NMData *nm_get_global_data (void);
-
#endif
diff --git a/src/NetworkManagerDbus.c b/src/NetworkManagerDbus.c
index 9612a8a157..b689a9a798 100644
--- a/src/NetworkManagerDbus.c
+++ b/src/NetworkManagerDbus.c
@@ -83,9 +83,8 @@ void nm_dbus_get_object_path_from_device (NMDevice *dev, unsigned char *buf, uns
* Returns the device associated with a dbus object path
*
*/
-NMDevice *nm_dbus_get_device_from_object_path (const char *path)
+NMDevice *nm_dbus_get_device_from_object_path (NMData *data, const char *path)
{
- NMData *data = nm_get_global_data ();
NMDevice *dev = NULL;
g_return_val_if_fail (path != NULL, NULL);
@@ -136,6 +135,7 @@ NMAccessPoint *nm_dbus_get_network_from_object_path (const char *path, NMDevice
char compare_path[100];
g_return_val_if_fail (path != NULL, NULL);
+ g_return_val_if_fail (dev != NULL, NULL);
while ((ap = nm_device_ap_list_get_ap_by_index (dev, i)) != NULL)
{
@@ -157,21 +157,19 @@ NMAccessPoint *nm_dbus_get_network_from_object_path (const char *path, NMDevice
* Returns the object path of the currently active device
*
*/
-static DBusMessage *nm_dbus_nm_get_active_device (DBusConnection *connection, DBusMessage *message)
+static DBusMessage *nm_dbus_nm_get_active_device (DBusConnection *connection, DBusMessage *message, NMData *data)
{
DBusMessage *reply_message = NULL;
DBusMessageIter iter;
- NMData *data = nm_get_global_data ();
- if (!data)
- {
- /* If we can't get our global data, something is really wrong... */
- reply_message = nm_dbus_create_error_message (message, NM_DBUS_NM_NAMESPACE, "NoGlobalData",
- "NetworkManager couldn't get its global data.");
- return (reply_message);
- }
+ g_return_val_if_fail (data != NULL, NULL);
+ g_return_val_if_fail (connection != NULL, NULL);
+ g_return_val_if_fail (message != NULL, NULL);
reply_message = dbus_message_new_method_return (message);
+ if (!reply_message)
+ return (NULL);
+
dbus_message_iter_init (reply_message, &iter);
/* Construct object path of "active" device and return it */
@@ -195,30 +193,27 @@ static DBusMessage *nm_dbus_nm_get_active_device (DBusConnection *connection, DB
* devices in the device list.
*
*/
-static DBusMessage *nm_dbus_nm_get_devices (DBusConnection *connection, DBusMessage *message)
+static DBusMessage *nm_dbus_nm_get_devices (DBusConnection *connection, DBusMessage *message, NMData *data)
{
DBusMessage *reply_message = NULL;
DBusMessageIter iter;
DBusMessageIter iter_array;
- NMData *data;
- data = nm_get_global_data ();
- if (!data)
- {
- /* If we can't get our global data, something is really wrong... */
- reply_message = nm_dbus_create_error_message (message, NM_DBUS_NM_NAMESPACE, "NoGlobalData",
- "NetworkManager couldn't get its global data.");
- goto end;
- }
+ g_return_val_if_fail (data != NULL, NULL);
+ g_return_val_if_fail (connection != NULL, NULL);
+ g_return_val_if_fail (message != NULL, NULL);
+
+ reply_message = dbus_message_new_method_return (message);
+ if (!reply_message)
+ return (NULL);
+
+ dbus_message_iter_init (reply_message, &iter);
+ dbus_message_iter_append_array (&iter, &iter_array, DBUS_TYPE_STRING);
/* Check for no devices */
if (!data->dev_list)
{
- reply_message = dbus_message_new_method_return (message);
- dbus_message_iter_init (reply_message, &iter);
- dbus_message_iter_append_array (&iter, &iter_array, DBUS_TYPE_STRING);
dbus_message_iter_append_string (&iter_array, "");
-
goto end;
}
@@ -228,10 +223,6 @@ static DBusMessage *nm_dbus_nm_get_devices (DBusConnection *connection, DBusMess
GSList *element = data->dev_list;
gboolean appended = FALSE;
- reply_message = dbus_message_new_method_return (message);
- dbus_message_iter_init (reply_message, &iter);
- dbus_message_iter_append_array (&iter, &iter_array, DBUS_TYPE_STRING);
-
while (element)
{
NMDevice *dev = (NMDevice *)(element->data);
@@ -282,6 +273,8 @@ void nm_dbus_signal_device_no_longer_active (DBusConnection *connection, NMDevic
DBusMessage *message;
unsigned char *object_path = g_new0 (unsigned char, 100);
+ g_return_if_fail (connection != NULL);
+ g_return_if_fail (dev != NULL);
g_return_if_fail (object_path != NULL);
message = dbus_message_new_signal (NM_DBUS_NM_OBJECT_PATH_PREFIX, NM_DBUS_NM_NAMESPACE, "DeviceNoLongerActive");
@@ -313,6 +306,9 @@ void nm_dbus_signal_device_now_active (DBusConnection *connection, NMDevice *dev
DBusMessage *message;
unsigned char *object_path = g_new0 (unsigned char, 100);
+ g_return_if_fail (connection != NULL);
+ g_return_if_fail (dev != NULL);
+
message = dbus_message_new_signal (NM_DBUS_NM_OBJECT_PATH_PREFIX, NM_DBUS_NM_NAMESPACE, "DeviceNowActive");
if (!message)
{
@@ -342,6 +338,9 @@ void nm_dbus_signal_device_ip4_address_change (DBusConnection *connection, NMDev
DBusMessage *message;
unsigned char *object_path = g_new0 (unsigned char, 100);
+ g_return_if_fail (connection != NULL);
+ g_return_if_fail (dev != NULL);
+
message = dbus_message_new_signal (NM_DBUS_NM_OBJECT_PATH_PREFIX, NM_DBUS_NM_NAMESPACE, "DeviceIP4AddressChange");
if (!message)
{
@@ -415,6 +414,7 @@ void nm_dbus_get_user_key_for_network (DBusConnection *connection, NMDevice *dev
DBusMessage *message;
DBusMessageIter iter;
+ g_return_if_fail (connection != NULL);
g_return_if_fail (dev != NULL);
g_return_if_fail (ap != NULL);
g_return_if_fail (nm_ap_get_essid (ap) != NULL);
@@ -463,7 +463,7 @@ void nm_dbus_get_user_key_for_network (DBusConnection *connection, NMDevice *dev
* for a particular wireless AP/network
*
*/
-static void nm_dbus_set_user_key_for_network (DBusConnection *connection, DBusMessage *message)
+static void nm_dbus_set_user_key_for_network (DBusConnection *connection, DBusMessage *message, NMData *data)
{
DBusMessageIter iter;
char *device;
@@ -471,6 +471,10 @@ static void nm_dbus_set_user_key_for_network (DBusConnection *connection, DBusMe
char *passphrase;
char *dbus_string;
+ g_return_if_fail (data != NULL);
+ g_return_if_fail (connection != NULL);
+ g_return_if_fail (message != NULL);
+
dbus_message_iter_init (message, &iter);
/* Grab device */
@@ -490,10 +494,8 @@ static void nm_dbus_set_user_key_for_network (DBusConnection *connection, DBusMe
if (device && network && passphrase)
{
- NMData *data = nm_get_global_data();
- NMDevice *dev = nm_get_device_by_iface (data, device);
-
- if (dev)
+ NMDevice *dev;
+ if ((dev = nm_get_device_by_iface (data, device)))
nm_device_pending_action_set_user_key (dev, passphrase);
}
@@ -512,6 +514,8 @@ void nm_dbus_cancel_get_user_key_for_network (DBusConnection *connection)
{
DBusMessage *message;
+ g_return_if_fail (connection != NULL);
+
message = dbus_message_new_method_call ("org.freedesktop.NetworkManagerInfo",
"/org/freedesktop/NetworkManagerInfo",
"org.freedesktop.NetworkManagerInfo",
@@ -530,20 +534,44 @@ void nm_dbus_cancel_get_user_key_for_network (DBusConnection *connection)
/*
+ * nm_dbus_nmi_filter
+ *
+ * Respond to NetworkManagerInfo signals about changing Allowed Networks
+ *
+ */
+static DBusHandlerResult nm_dbus_nmi_filter (DBusConnection *connection, DBusMessage *message, void *user_data)
+{
+ NMData *data = (NMData *)user_data;
+
+ g_return_val_if_fail (data != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ g_return_val_if_fail (connection != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ g_return_val_if_fail (message != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+
+ return (DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+}
+
+
+/*
* nm_dbus_devices_handle_networks_request
*
* Converts a property request on a _network_ into a dbus message.
*
*/
static DBusMessage *nm_dbus_devices_handle_networks_request (DBusConnection *connection, DBusMessage *message,
- const char *path, const char *request, NMDevice *dev)
+ NMData *data, const char *path, const char *request, NMDevice *dev)
{
NMAccessPoint *ap;
DBusMessage *reply_message = NULL;
DBusMessageIter iter;
- ap = nm_dbus_get_network_from_object_path (path, dev);
- if (!ap)
+ g_return_val_if_fail (data != NULL, NULL);
+ g_return_val_if_fail (connection != NULL, NULL);
+ g_return_val_if_fail (message != NULL, NULL);
+ g_return_val_if_fail (path != NULL, NULL);
+ g_return_val_if_fail (request != NULL, NULL);
+ g_return_val_if_fail (dev != NULL, NULL);
+
+ if (!(ap = nm_dbus_get_network_from_object_path (path, dev)))
{
reply_message = nm_dbus_create_error_message (message, NM_DBUS_NM_NAMESPACE, "NetworkNotFound",
"The requested network does not exist for this device.");
@@ -551,6 +579,8 @@ static DBusMessage *nm_dbus_devices_handle_networks_request (DBusConnection *con
}
reply_message = dbus_message_new_method_return (message);
+ if (!reply_message)
+ return (NULL);
dbus_message_iter_init (reply_message, &iter);
if (strcmp ("getName", request) == 0)
@@ -590,14 +620,21 @@ static DBusMessage *nm_dbus_devices_handle_networks_request (DBusConnection *con
* Converts a property request into a dbus message.
*
*/
-static DBusMessage *nm_dbus_devices_handle_request (DBusConnection *connection, DBusMessage *message, const char *path, const char *request)
+static DBusMessage *nm_dbus_devices_handle_request (DBusConnection *connection, NMData *data, DBusMessage *message,
+ const char *path, const char *request)
{
NMDevice *dev;
DBusMessage *reply_message = NULL;
DBusMessageIter iter;
char *object_path;
- if (!(dev = nm_dbus_get_device_from_object_path (path)))
+ g_return_val_if_fail (data != NULL, NULL);
+ g_return_val_if_fail (connection != NULL, NULL);
+ g_return_val_if_fail (message != NULL, NULL);
+ g_return_val_if_fail (path != NULL, NULL);
+ g_return_val_if_fail (request != NULL, NULL);
+
+ if (!(dev = nm_dbus_get_device_from_object_path (data, path)))
{
reply_message = nm_dbus_create_error_message (message, NM_DBUS_NM_NAMESPACE, "DeviceNotFound",
"The requested network device does not exist.");
@@ -609,12 +646,14 @@ static DBusMessage *nm_dbus_devices_handle_request (DBusConnection *connection,
if (strncmp (path, object_path, strlen (object_path)) == 0)
{
free (object_path);
- reply_message = nm_dbus_devices_handle_networks_request (connection, message, path, request, dev);
+ reply_message = nm_dbus_devices_handle_networks_request (connection, message, data, path, request, dev);
return (reply_message);
}
free (object_path);
reply_message = dbus_message_new_method_return (message);
+ if (!reply_message)
+ return (NULL);
dbus_message_iter_init (reply_message, &iter);
if (strcmp ("getName", request) == 0)
@@ -625,9 +664,8 @@ static DBusMessage *nm_dbus_devices_handle_request (DBusConnection *connection,
dbus_message_iter_append_uint32 (&iter, nm_device_get_ip4_address (dev));
else if (strcmp ("getActiveNetwork", request) == 0)
{
- NMAccessPoint *ap = nm_device_ap_list_get_ap_by_essid (dev, nm_device_get_essid (dev));
-
- if (ap)
+ NMAccessPoint *ap;
+ if ((ap = nm_device_ap_list_get_ap_by_essid (dev, nm_device_get_essid (dev))))
{
object_path = g_strdup_printf ("%s/%s/Networks/%s", NM_DBUS_DEVICES_OBJECT_PATH_PREFIX,
nm_device_get_iface (dev), nm_ap_get_essid (ap));
@@ -673,22 +711,27 @@ static DBusMessage *nm_dbus_devices_handle_request (DBusConnection *connection,
*/
static DBusHandlerResult nm_dbus_nm_message_handler (DBusConnection *connection, DBusMessage *message, void *user_data)
{
+ NMData *data = (NMData *)user_data;
const char *method;
const char *path;
DBusMessage *reply_message = NULL;
gboolean handled = TRUE;
+ g_return_val_if_fail (data != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ g_return_val_if_fail (connection != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ g_return_val_if_fail (message != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+
method = dbus_message_get_member (message);
path = dbus_message_get_path (message);
NM_DEBUG_PRINT_2 ("nm_dbus_nm_message_handler() got method %s for path %s\n", method, path);
if (strcmp ("getActiveDevice", method) == 0)
- reply_message = nm_dbus_nm_get_active_device (connection, message);
+ reply_message = nm_dbus_nm_get_active_device (connection, message, data);
else if (strcmp ("getDevices", method) == 0)
- reply_message = nm_dbus_nm_get_devices (connection, message);
+ reply_message = nm_dbus_nm_get_devices (connection, message, data);
else if (strcmp ("setKeyForNetwork", method) == 0)
- nm_dbus_set_user_key_for_network (connection, message);
+ nm_dbus_set_user_key_for_network (connection, message, data);
else
handled = FALSE;
@@ -722,21 +765,27 @@ void nm_dbus_nm_unregister_handler (DBusConnection *connection, void *user_data)
*/
static DBusHandlerResult nm_dbus_devices_message_handler (DBusConnection *connection, DBusMessage *message, void *user_data)
{
+ NMData *data = (NMData *)user_data;
+ gboolean handled = FALSE;
const char *method;
const char *path;
DBusMessage *reply_message = NULL;
+ g_return_val_if_fail (data != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ g_return_val_if_fail (connection != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ g_return_val_if_fail (message != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+
method = dbus_message_get_member (message);
path = dbus_message_get_path (message);
- if ((reply_message = nm_dbus_devices_handle_request (connection, message, path, method)))
+ if ((reply_message = nm_dbus_devices_handle_request (connection, data, message, path, method)))
{
dbus_connection_send (connection, reply_message, NULL);
dbus_message_unref (reply_message);
- return (DBUS_HANDLER_RESULT_HANDLED);
+ handled = TRUE;
}
- return (DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ return (handled ? DBUS_HANDLER_RESULT_HANDLED : DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
}
@@ -758,11 +807,11 @@ void nm_dbus_devices_unregister_handler (DBusConnection *connection, void *user_
* Connect to the system messagebus and register ourselves as a service.
*
*/
-DBusConnection *nm_dbus_init (void)
+DBusConnection *nm_dbus_init (NMData *data)
{
DBusError dbus_error;
dbus_bool_t success;
- DBusConnection *dbus_connection;
+ DBusConnection *connection;
DBusObjectPathVTable nm_vtable = { &nm_dbus_nm_unregister_handler, &nm_dbus_nm_message_handler, NULL, NULL, NULL, NULL };
const char *nm_path[] = { "org", "freedesktop", "NetworkManager", NULL };
DBusObjectPathVTable devices_vtable = { &nm_dbus_devices_unregister_handler, &nm_dbus_devices_message_handler, NULL, NULL, NULL, NULL };
@@ -771,35 +820,44 @@ DBusConnection *nm_dbus_init (void)
dbus_connection_set_change_sigpipe (TRUE);
dbus_error_init (&dbus_error);
- dbus_connection = dbus_bus_get (DBUS_BUS_SYSTEM, &dbus_error);
- if (dbus_connection == NULL)
+ connection = dbus_bus_get (DBUS_BUS_SYSTEM, &dbus_error);
+ if (connection == NULL)
{
NM_DEBUG_PRINT ("nm_dbus_init() could not get the system bus. Make sure the message bus daemon is running?\n");
return (NULL);
}
- dbus_connection_set_exit_on_disconnect (dbus_connection, FALSE);
- dbus_connection_setup_with_g_main (dbus_connection, NULL);
- dbus_bus_acquire_service (dbus_connection, NM_DBUS_NM_NAMESPACE, 0, &dbus_error);
+ dbus_connection_set_exit_on_disconnect (connection, FALSE);
+ dbus_connection_setup_with_g_main (connection, NULL);
+ dbus_bus_acquire_service (connection, NM_DBUS_NM_NAMESPACE, 0, &dbus_error);
if (dbus_error_is_set (&dbus_error))
{
NM_DEBUG_PRINT_1 ("nm_dbus_init() could not acquire its service. dbus_bus_acquire_service() says: '%s'\n", dbus_error.message);
return (NULL);
}
- success = dbus_connection_register_object_path (dbus_connection, nm_path, &nm_vtable, NULL);
+ success = dbus_connection_register_object_path (connection, nm_path, &nm_vtable, data);
if (!success)
{
NM_DEBUG_PRINT ("nm_dbus_init() could not register a handler for NetworkManager. Not enough memory?\n");
return (NULL);
}
- success = dbus_connection_register_fallback (dbus_connection, devices_path, &devices_vtable, NULL);
+ success = dbus_connection_register_fallback (connection, devices_path, &devices_vtable, data);
if (!success)
{
NM_DEBUG_PRINT ("nm_dbus_init() could not register a handler for NetworkManager devices. Not enough memory?\n");
return (NULL);
}
- return (dbus_connection);
+ if (!dbus_connection_add_filter (connection, nm_dbus_nmi_filter, data, NULL))
+ return (NULL);
+
+ dbus_bus_add_match (connection,
+ "type='signal',"
+ "interface='org.freedesktop.NetworkManagerInfo',"
+ "sender='org.freedesktop.NetworkManagerInfo',"
+ "path='/org/freedesktop/NetworkManagerInfo'", &dbus_error);
+
+ return (connection);
}
diff --git a/src/NetworkManagerDbus.h b/src/NetworkManagerDbus.h
index 8717d4db47..f6f8ac08a5 100644
--- a/src/NetworkManagerDbus.h
+++ b/src/NetworkManagerDbus.h
@@ -32,7 +32,7 @@
#define NM_DBUS_DEVICES_NAMESPACE "org.freedesktop.NetworkManager.Devices"
-DBusConnection * nm_dbus_init (void);
+DBusConnection * nm_dbus_init (NMData *data);
void nm_dbus_signal_device_no_longer_active (DBusConnection *connection, NMDevice *dev);
diff --git a/src/NetworkManagerDevice.c b/src/NetworkManagerDevice.c
index 1f7707ac0e..89498ef54b 100644
--- a/src/NetworkManagerDevice.c
+++ b/src/NetworkManagerDevice.c
@@ -211,6 +211,7 @@ struct NMDevice
NMPendingAction pending_action;
NMPendingActionOptions pending_action_options;
guint32 ip4_address;
+ NMData *app_data;
/* FIXME: ipv6 address too */
NMDeviceOptions dev_options;
};
@@ -222,7 +223,7 @@ struct NMDevice
* Creates and initializes the structure representation of an NLM device.
*
*/
-NMDevice *nm_device_new (const char *iface)
+NMDevice *nm_device_new (const char *iface, NMData *app_data)
{
NMDevice *dev;
@@ -236,6 +237,7 @@ NMDevice *nm_device_new (const char *iface)
}
dev->refcount = 1;
+ dev->app_data = app_data;
dev->iface = g_strdup (iface);
dev->iface_type = nm_device_test_wireless_extensions (dev) ?
NM_IFACE_TYPE_WIRELESS_ETHERNET : NM_IFACE_TYPE_WIRED_ETHERNET;
@@ -397,6 +399,7 @@ void nm_device_update_link_active (NMDevice *dev, gboolean check_mii)
gboolean link_active = FALSE;
g_return_if_fail (dev != NULL);
+ g_return_if_fail (dev->app_data != NULL);
/* FIXME
* For wireless cards, the best indicator of a "link" at this time
@@ -428,8 +431,8 @@ void nm_device_update_link_active (NMDevice *dev, gboolean check_mii)
if (check_mii)
link_active = mii_get_link (dev);
else
- if (hal_device_property_exists (nm_get_global_data()->hal_ctx, nm_device_get_udi (dev), "net.ethernet.link"))
- link_active = hal_device_get_property_bool (nm_get_global_data()->hal_ctx, nm_device_get_udi (dev), "net.ethernet.link");
+ if (hal_device_property_exists (dev->app_data->hal_ctx, nm_device_get_udi (dev), "net.ethernet.link"))
+ link_active = hal_device_get_property_bool (dev->app_data->hal_ctx, nm_device_get_udi (dev), "net.ethernet.link");
break;
}
@@ -442,7 +445,7 @@ void nm_device_update_link_active (NMDevice *dev, gboolean check_mii)
if (link_active != nm_device_get_link_active (dev))
{
nm_device_set_link_active (dev, link_active);
- nm_data_set_state_modified (nm_get_global_data(), TRUE);
+ nm_data_set_state_modified (dev->app_data, TRUE);
}
}
@@ -634,13 +637,12 @@ guint32 nm_device_get_ip4_address(NMDevice *dev)
void nm_device_update_ip4_address (NMDevice *dev)
{
- NMData *data = nm_get_global_data ();
guint32 new_address;
struct ifreq req;
int socket;
- g_return_if_fail (data != NULL);
g_return_if_fail (dev != NULL);
+ g_return_if_fail (dev->app_data != NULL);
g_return_if_fail (nm_device_get_iface (dev) != NULL);
socket = nm_get_network_control_socket ();
@@ -656,7 +658,7 @@ void nm_device_update_ip4_address (NMDevice *dev)
/* If the new address is different, send an IP4AddressChanged signal on the bus */
if (new_address != nm_device_get_ip4_address (dev))
{
- nm_dbus_signal_device_ip4_address_change (data->dbus_connection, dev);
+ nm_dbus_signal_device_ip4_address_change (dev->app_data->dbus_connection, dev);
dev->ip4_address = new_address;
}
}
@@ -775,12 +777,11 @@ gboolean nm_device_activate (NMDevice *dev)
unsigned char *iface;
unsigned char hostname[100] = "\0";
int host_err;
- NMData *data = nm_get_global_data ();
int dhclient_err;
FILE *pidfile;
g_return_val_if_fail (dev != NULL, FALSE);
- g_return_val_if_fail (data != NULL, FALSE);
+ g_return_val_if_fail (dev->app_data != NULL, FALSE);
/* If its a wireless device, set the ESSID and WEP key */
if (nm_device_is_wireless (dev))
@@ -901,7 +902,7 @@ gboolean nm_device_activate (NMDevice *dev)
system (buf);
}
- nm_dbus_signal_device_now_active (data->dbus_connection, dev);
+ nm_dbus_signal_device_now_active (dev->app_data->dbus_connection, dev);
nm_device_update_ip4_address (dev);
return (success);
@@ -919,10 +920,9 @@ gboolean nm_device_deactivate (NMDevice *dev, gboolean just_added)
unsigned char buf[500];
unsigned char *iface;
gboolean success = FALSE;
- NMData *data = nm_get_global_data ();
g_return_val_if_fail (dev != NULL, FALSE);
- g_return_val_if_fail (data != NULL, FALSE);
+ g_return_val_if_fail (dev->app_data != NULL, FALSE);
iface = nm_device_get_iface (dev);
@@ -946,7 +946,7 @@ gboolean nm_device_deactivate (NMDevice *dev, gboolean just_added)
}
if (!just_added)
- nm_dbus_signal_device_no_longer_active (data->dbus_connection, dev);
+ nm_dbus_signal_device_no_longer_active (dev->app_data->dbus_connection, dev);
/* Clean up stuff, don't leave the card associated or up */
if (nm_device_is_wireless (dev))
@@ -983,10 +983,8 @@ gboolean nm_device_pending_action (NMDevice *dev)
*/
void nm_device_pending_action_get_user_key (NMDevice *dev, NMAccessPoint *ap)
{
- NMData *data = nm_get_global_data ();
-
- g_return_if_fail (data != NULL);
g_return_if_fail (dev != NULL);
+ g_return_if_fail (dev->app_data != NULL);
g_return_if_fail (nm_device_is_wireless (dev));
g_return_if_fail (ap != NULL);
g_return_if_fail (nm_ap_get_essid (ap) != NULL);
@@ -996,7 +994,7 @@ void nm_device_pending_action_get_user_key (NMDevice *dev, NMAccessPoint *ap)
dev->pending_action = NM_PENDING_ACTION_GET_USER_KEY;
dev->pending_action_options.user_key.essid = g_strdup (nm_ap_get_essid (ap));
- nm_dbus_get_user_key_for_network (data->dbus_connection, dev, ap, &(dev->pending_action_options.user_key.pending_call));
+ nm_dbus_get_user_key_for_network (dev->app_data->dbus_connection, dev, ap, &(dev->pending_action_options.user_key.pending_call));
}
@@ -1043,10 +1041,8 @@ void nm_device_pending_action_set_user_key (NMDevice *dev, unsigned char *key)
*/
void nm_device_pending_action_cancel (NMDevice *dev)
{
- NMData *data = nm_get_global_data ();
-
g_return_if_fail (dev != NULL);
- g_return_if_fail (data != NULL);
+ g_return_if_fail (dev->app_data != NULL);
if (dev->pending_action == NM_PENDING_ACTION_GET_USER_KEY)
{
@@ -1059,7 +1055,7 @@ void nm_device_pending_action_cancel (NMDevice *dev)
g_free (dev->pending_action_options.user_key.essid);
dev->pending_action_options.user_key.essid = NULL;
- nm_dbus_cancel_get_user_key_for_network (data->dbus_connection);
+ nm_dbus_cancel_get_user_key_for_network (dev->app_data->dbus_connection);
}
dev->pending_action = NM_PENDING_ACTION_NONE;
@@ -1253,6 +1249,7 @@ static void nm_device_do_normal_scan (NMDevice *dev)
int iwlib_socket;
g_return_if_fail (dev != NULL);
+ g_return_if_fail (dev->app_data != NULL);
/* Device must be up before we can scan */
if (!nm_device_is_up (dev))
@@ -1316,7 +1313,7 @@ static void nm_device_do_normal_scan (NMDevice *dev)
/* Add the AP to the device's AP list, no matter if its allowed or not */
nm_device_ap_list_add (dev, nm_ap);
- if (nm_wireless_is_most_prefered_ap (nm_ap, &highest_priority))
+ if (nm_wireless_is_most_prefered_ap (dev->app_data, nm_ap, &highest_priority))
{
if (highest_priority_ap)
nm_ap_unref (highest_priority_ap);
@@ -1337,7 +1334,7 @@ static void nm_device_do_normal_scan (NMDevice *dev)
&& (!nm_device_get_best_ap (dev) || (nm_null_safe_strcmp (nm_device_get_essid (dev), nm_ap_get_essid (highest_priority_ap)) != 0)))
{
nm_device_set_best_ap (dev, highest_priority_ap);
- nm_data_set_state_modified (nm_get_global_data (), TRUE);
+ nm_data_set_state_modified (dev->app_data, TRUE);
nm_ap_unref (highest_priority_ap);
}
@@ -1360,17 +1357,15 @@ static void nm_device_do_normal_scan (NMDevice *dev)
*/
static void nm_device_do_pseudo_scan (NMDevice *dev)
{
- NMData *data = nm_get_global_data ();
-
- g_return_if_fail (data != NULL);
g_return_if_fail (dev != NULL);
+ g_return_if_fail (dev->app_data != NULL);
nm_device_ref (dev);
/* Acquire allowed AP list mutex, silently fail if we cannot */
- if (nm_try_acquire_mutex (data->allowed_ap_list_mutex, __FUNCTION__))
+ if (nm_try_acquire_mutex (dev->app_data->allowed_ap_list_mutex, __FUNCTION__))
{
- GSList *element = data->allowed_ap_list;
+ GSList *element = dev->app_data->allowed_ap_list;
/* Turn off the essid so we can tell if its changed when
* we set it below.
@@ -1424,14 +1419,14 @@ static void nm_device_do_pseudo_scan (NMDevice *dev)
NM_DEBUG_PRINT_1 ("AP %s looks good, setting to desired\n", nm_ap_get_essid (ap));
nm_device_set_best_ap (dev, ap);
- nm_data_set_state_modified (nm_get_global_data (), TRUE);
+ nm_data_set_state_modified (dev->app_data, TRUE);
break;
}
}
element = g_slist_next (element);
}
- nm_unlock_mutex (data->allowed_ap_list_mutex, __FUNCTION__);
+ nm_unlock_mutex (dev->app_data->allowed_ap_list_mutex, __FUNCTION__);
}
nm_device_unref (dev);
@@ -1446,9 +1441,6 @@ static void nm_device_do_pseudo_scan (NMDevice *dev)
*/
void nm_device_do_wireless_scan (NMDevice *dev)
{
- NMData *data = nm_get_global_data ();
-
- g_return_if_fail (data != NULL);
g_return_if_fail (dev != NULL);
g_return_if_fail (nm_device_is_wireless (dev));
@@ -1464,7 +1456,7 @@ void nm_device_do_wireless_scan (NMDevice *dev)
*/
nm_device_get_ap_address (dev, &ap_addr);
if ( !nm_ethernet_address_is_valid (&ap_addr)
- || !nm_policy_essid_is_allowed (data, nm_device_get_essid (dev))
+ || !nm_policy_essid_is_allowed (dev->app_data, nm_device_get_essid (dev))
|| !nm_device_get_best_ap (dev))
{
nm_device_do_pseudo_scan (dev);
diff --git a/src/NetworkManagerDevice.h b/src/NetworkManagerDevice.h
index 4726da2eae..944739f038 100644
--- a/src/NetworkManagerDevice.h
+++ b/src/NetworkManagerDevice.h
@@ -39,7 +39,7 @@ typedef struct NMDevice NMDevice;
typedef enum NMIfaceType NMIfaceType;
-NMDevice * nm_device_new (const char *iface);
+NMDevice * nm_device_new (const char *iface, NMData *app_data);
void nm_device_ref (NMDevice *dev);
void nm_device_unref (NMDevice *dev);
diff --git a/src/NetworkManagerPolicy.c b/src/NetworkManagerPolicy.c
index a42020e5e6..b81f73a129 100644
--- a/src/NetworkManagerPolicy.c
+++ b/src/NetworkManagerPolicy.c
@@ -302,7 +302,7 @@ void nm_policy_update_allowed_access_points (NMData *data)
gchar wep_key[ 50 ];
/* Free the old list of allowed access points */
- nm_data_allowed_ap_list_free (data);
+// nm_data_allowed_ap_list_free (data);
while (fgets (line, 499, ap_file))
{
diff --git a/src/NetworkManagerWireless.c b/src/NetworkManagerWireless.c
index cf9ceab92b..19006fd3d7 100644
--- a/src/NetworkManagerWireless.c
+++ b/src/NetworkManagerWireless.c
@@ -37,13 +37,14 @@ extern gboolean debug;
* both allowed _and_ has a better priority than highest_priority.
*
*/
-gboolean nm_wireless_is_most_prefered_ap (NMAccessPoint *ap, int *highest_priority)
+gboolean nm_wireless_is_most_prefered_ap (NMData *data, NMAccessPoint *ap, int *highest_priority)
{
- NMData *data = nm_get_global_data ();
GSList *element;
gboolean is_most_preferred = FALSE;
+ g_return_val_if_fail (data != NULL, FALSE);
g_return_val_if_fail (ap != NULL, FALSE);
+ g_return_val_if_fail (highest_priority != NULL, FALSE);
/* Attempt to acquire mutex for device list iteration.
* If the acquire fails, just ignore the scan completely.
diff --git a/src/NetworkManagerWireless.h b/src/NetworkManagerWireless.h
index ccbbe88acf..398165522e 100644
--- a/src/NetworkManagerWireless.h
+++ b/src/NetworkManagerWireless.h
@@ -26,7 +26,7 @@
#include "NetworkManagerDevice.h"
-gboolean nm_wireless_is_most_prefered_ap (NMAccessPoint *ap, int *highest_priority);
+gboolean nm_wireless_is_most_prefered_ap (NMData *data, NMAccessPoint *ap, int *highest_priority);
gboolean nm_wireless_scan_monitor (gpointer user_data);