2004-08-09 Dan Williams <dcbw@redhat.com>
* dispatcher-daemon/NetworkManagerDispatcher.c: - Covert uses of dbus_message_iter_* over to dbus_message_get_args - Use constants for NetworkManager interface, service, and path git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@44 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
@@ -1,3 +1,9 @@
|
|||||||
|
2004-08-09 Dan Williams <dcbw@redhat.com>
|
||||||
|
|
||||||
|
* dispatcher-daemon/NetworkManagerDispatcher.c:
|
||||||
|
- Covert uses of dbus_message_iter_* over to dbus_message_get_args
|
||||||
|
- Use constants for NetworkManager interface, service, and path
|
||||||
|
|
||||||
2004-08-09 Dan Williams <dcbw@redhat.com>
|
2004-08-09 Dan Williams <dcbw@redhat.com>
|
||||||
|
|
||||||
* src/NetworkManagerDbus.c:
|
* src/NetworkManagerDbus.c:
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <dbus/dbus.h>
|
#include <dbus/dbus.h>
|
||||||
|
#include <dbus/dbus-glib-lowlevel.h>
|
||||||
#include <dbus/dbus-glib.h>
|
#include <dbus/dbus-glib.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@@ -33,6 +34,12 @@
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#define NM_DBUS_SERVICE "org.freedesktop.NetworkManager"
|
||||||
|
|
||||||
|
#define NM_DBUS_PATH "/org/freedesktop/NetworkManager"
|
||||||
|
#define NM_DBUS_INTERFACE "org.freedesktop.NetworkManager"
|
||||||
|
|
||||||
|
|
||||||
enum NMDAction
|
enum NMDAction
|
||||||
{
|
{
|
||||||
NMD_DEVICE_DONT_KNOW,
|
NMD_DEVICE_DONT_KNOW,
|
||||||
@@ -112,16 +119,10 @@ char * nmd_get_device_name (DBusConnection *connection, char *path)
|
|||||||
{
|
{
|
||||||
DBusMessage *message;
|
DBusMessage *message;
|
||||||
DBusMessage *reply;
|
DBusMessage *reply;
|
||||||
DBusMessageIter iter;
|
|
||||||
DBusError error;
|
DBusError error;
|
||||||
char *ret_string = NULL;
|
char *dev_name = NULL;
|
||||||
char *dbus_string;
|
|
||||||
|
|
||||||
message = dbus_message_new_method_call ("org.freedesktop.NetworkManager",
|
if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, path, NM_DBUS_INTERFACE, "getName")))
|
||||||
path,
|
|
||||||
"org.freedesktop.NetworkManager",
|
|
||||||
"getName");
|
|
||||||
if (message == NULL)
|
|
||||||
{
|
{
|
||||||
fprintf (stderr, "Couldn't allocate the dbus message\n");
|
fprintf (stderr, "Couldn't allocate the dbus message\n");
|
||||||
return (NULL);
|
return (NULL);
|
||||||
@@ -144,17 +145,17 @@ char * nmd_get_device_name (DBusConnection *connection, char *path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* now analyze reply */
|
/* now analyze reply */
|
||||||
dbus_message_iter_init (reply, &iter);
|
dbus_error_init (&error);
|
||||||
dbus_string = dbus_message_iter_get_string (&iter);
|
if (!dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &dev_name, DBUS_TYPE_INVALID))
|
||||||
ret_string = (dbus_string == NULL ? NULL : strdup (dbus_string));
|
{
|
||||||
if (!ret_string)
|
fprintf (stderr, "There was an error getting the device name from NetworkManager." );
|
||||||
fprintf (stderr, "NetworkManager returned a NULL device name" );
|
dev_name = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
dbus_free (dbus_string);
|
|
||||||
dbus_message_unref (reply);
|
dbus_message_unref (reply);
|
||||||
dbus_message_unref (message);
|
dbus_message_unref (message);
|
||||||
|
|
||||||
return (ret_string);
|
return (dev_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -167,15 +168,10 @@ guint32 nmd_get_device_ip4_address (DBusConnection *connection, char *path)
|
|||||||
{
|
{
|
||||||
DBusMessage *message;
|
DBusMessage *message;
|
||||||
DBusMessage *reply;
|
DBusMessage *reply;
|
||||||
DBusMessageIter iter;
|
|
||||||
DBusError error;
|
DBusError error;
|
||||||
guint32 ret_address;
|
guint32 address;
|
||||||
|
|
||||||
message = dbus_message_new_method_call ("org.freedesktop.NetworkManager",
|
if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, path, NM_DBUS_INTERFACE, "getIP4Address")))
|
||||||
path,
|
|
||||||
"org.freedesktop.NetworkManager",
|
|
||||||
"getIP4Address");
|
|
||||||
if (message == NULL)
|
|
||||||
{
|
{
|
||||||
fprintf (stderr, "Couldn't allocate the dbus message\n");
|
fprintf (stderr, "Couldn't allocate the dbus message\n");
|
||||||
return (0);
|
return (0);
|
||||||
@@ -198,12 +194,17 @@ guint32 nmd_get_device_ip4_address (DBusConnection *connection, char *path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* now analyze reply */
|
/* now analyze reply */
|
||||||
dbus_message_iter_init (reply, &iter);
|
dbus_error_init (&error);
|
||||||
ret_address = dbus_message_iter_get_uint32 (&iter);
|
if (!dbus_message_get_args (reply, &error, DBUS_TYPE_UINT32, &address, DBUS_TYPE_INVALID))
|
||||||
|
{
|
||||||
|
fprintf (stderr, "There was an error getting the device's IPv4 address from NetworkManager." );
|
||||||
|
address = 0;
|
||||||
|
}
|
||||||
|
|
||||||
dbus_message_unref (reply);
|
dbus_message_unref (reply);
|
||||||
dbus_message_unref (message);
|
dbus_message_unref (message);
|
||||||
|
|
||||||
return (ret_address);
|
return (address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -223,11 +224,11 @@ static DBusHandlerResult nmd_dbus_filter (DBusConnection *connection, DBusMessag
|
|||||||
dbus_error_init (&error);
|
dbus_error_init (&error);
|
||||||
object_path = dbus_message_get_path (message);
|
object_path = dbus_message_get_path (message);
|
||||||
|
|
||||||
if (dbus_message_is_signal (message, "org.freedesktop.NetworkManager", "DeviceIP4AddressChange"))
|
if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceIP4AddressChange"))
|
||||||
action = NMD_DEVICE_IP4_ADDRESS_CHANGE;
|
action = NMD_DEVICE_IP4_ADDRESS_CHANGE;
|
||||||
else if (dbus_message_is_signal (message, "org.freedesktop.NetworkManager", "DeviceNoLongerActive"))
|
else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceNoLongerActive"))
|
||||||
action = NMD_DEVICE_NOW_INACTIVE;
|
action = NMD_DEVICE_NOW_INACTIVE;
|
||||||
else if (dbus_message_is_signal (message, "org.freedesktop.NetworkManager", "DeviceNowActive"))
|
else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceNowActive"))
|
||||||
action = NMD_DEVICE_NOW_ACTIVE;
|
action = NMD_DEVICE_NOW_ACTIVE;
|
||||||
|
|
||||||
if (action != NMD_DEVICE_DONT_KNOW)
|
if (action != NMD_DEVICE_DONT_KNOW)
|
||||||
@@ -251,7 +252,7 @@ static DBusHandlerResult nmd_dbus_filter (DBusConnection *connection, DBusMessag
|
|||||||
|
|
||||||
nmd_execute_scripts (action, dev_iface_name, dev_ip4_address);
|
nmd_execute_scripts (action, dev_iface_name, dev_ip4_address);
|
||||||
|
|
||||||
free (dev_iface_name);
|
dbus_free (dev_iface_name);
|
||||||
dbus_free (dev_object_path);
|
dbus_free (dev_object_path);
|
||||||
|
|
||||||
handled = TRUE;
|
handled = TRUE;
|
||||||
@@ -289,9 +290,9 @@ static DBusConnection *nmd_dbus_init (void)
|
|||||||
|
|
||||||
dbus_bus_add_match (connection,
|
dbus_bus_add_match (connection,
|
||||||
"type='signal',"
|
"type='signal',"
|
||||||
"interface='org.freedesktop.NetworkManager',"
|
"interface='" NM_DBUS_INTERFACE "',"
|
||||||
"sender='org.freedesktop.NetworkManager',"
|
"sender='" NM_DBUS_SERVICE "',"
|
||||||
"path='/org/freedesktop/NetworkManager'", &error);
|
"path='" NM_DBUS_PATH "'", &error);
|
||||||
if (dbus_error_is_set (&error))
|
if (dbus_error_is_set (&error))
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user