2005-03-07 Ray Strode <rstrode@redhat.com>
* info-daemon/NetworkManagerInfoDbus.c: * libnm_glib/libnm_glib.c: * panel-applet/NMWirelessAppletDbus.c: * src/NetworkManager.c: * src/NetworkManagerDbus.c: * src/NetworkManagerDevice.c: * src/NetworkManagerUtils.c: * src/nm-dbus-device.c: * src/nm-dbus-dhcp.c: * src/nm-dbus-net.c: * src/nm-dbus-nm.c: * test/nminfotest.c: First (unfinished, unworking) cut at porting to dbus 0.30 api. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@493 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
16
ChangeLog
16
ChangeLog
@@ -1,3 +1,19 @@
|
||||
2005-03-07 Ray Strode <rstrode@redhat.com>
|
||||
|
||||
* info-daemon/NetworkManagerInfoDbus.c:
|
||||
* libnm_glib/libnm_glib.c:
|
||||
* panel-applet/NMWirelessAppletDbus.c:
|
||||
* src/NetworkManager.c:
|
||||
* src/NetworkManagerDbus.c:
|
||||
* src/NetworkManagerDevice.c:
|
||||
* src/NetworkManagerUtils.c:
|
||||
* src/nm-dbus-device.c:
|
||||
* src/nm-dbus-dhcp.c:
|
||||
* src/nm-dbus-net.c:
|
||||
* src/nm-dbus-nm.c:
|
||||
* test/nminfotest.c:
|
||||
First (unfinished, unworking) cut at porting to dbus 0.30 api.
|
||||
|
||||
2005-03-04 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* configure.in
|
||||
|
@@ -27,6 +27,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "NetworkManagerInfo.h"
|
||||
#include "NetworkManagerInfoDbus.h"
|
||||
@@ -117,9 +118,6 @@ static void nmi_dbus_get_key_for_network (NMIAppInfo *info, DBusMessage *message
|
||||
DBUS_TYPE_INVALID))
|
||||
{
|
||||
nmi_passphrase_dialog_show (device, network, info);
|
||||
|
||||
dbus_free (device);
|
||||
dbus_free (network);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,12 +143,9 @@ static void nmi_dbus_get_vpn_userpass (NMIAppInfo *info, DBusMessage *message)
|
||||
DBUS_TYPE_INVALID))
|
||||
{
|
||||
if (username[0] == '\0') {
|
||||
dbus_free (username);
|
||||
username = NULL;
|
||||
}
|
||||
nmi_vpn_request_password (info, message, vpn, username, retry);
|
||||
dbus_free (vpn);
|
||||
dbus_free (username);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,10 +173,10 @@ void nmi_dbus_return_user_key (DBusConnection *connection, const char *device,
|
||||
}
|
||||
|
||||
/* Add network name and passphrase */
|
||||
if (dbus_message_append_args (message, DBUS_TYPE_STRING, device,
|
||||
DBUS_TYPE_STRING, network,
|
||||
DBUS_TYPE_STRING, passphrase,
|
||||
DBUS_TYPE_INT32, key_type,
|
||||
if (dbus_message_append_args (message, DBUS_TYPE_STRING, &device,
|
||||
DBUS_TYPE_STRING, &network,
|
||||
DBUS_TYPE_STRING, &passphrase,
|
||||
DBUS_TYPE_INT32, &key_type,
|
||||
DBUS_TYPE_INVALID))
|
||||
{
|
||||
if (!dbus_connection_send (connection, message, NULL))
|
||||
@@ -213,7 +208,7 @@ void nmi_dbus_return_vpn_password (DBusConnection *connection, DBusMessage *mess
|
||||
{
|
||||
reply = dbus_message_new_method_return (message);
|
||||
dbus_message_append_args (reply,
|
||||
DBUS_TYPE_STRING, password,
|
||||
DBUS_TYPE_STRING, &password,
|
||||
DBUS_TYPE_INVALID);
|
||||
}
|
||||
dbus_connection_send (connection, reply, NULL);
|
||||
@@ -245,7 +240,7 @@ void nmi_dbus_signal_update_network (DBusConnection *connection, const char *net
|
||||
return;
|
||||
}
|
||||
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, network, DBUS_TYPE_INVALID);
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, &network, DBUS_TYPE_INVALID);
|
||||
if (!dbus_connection_send (connection, message, NULL))
|
||||
syslog (LOG_WARNING, "nmi_dbus_signal_update_network(): Could not raise the 'WirelessNetworkUpdate' signal!");
|
||||
|
||||
@@ -294,8 +289,8 @@ static DBusMessage *nmi_dbus_get_networks (NMIAppInfo *info, DBusMessage *messag
|
||||
gboolean value_added = 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);
|
||||
dbus_message_iter_init_append (reply_message, &iter);
|
||||
dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &iter_array);
|
||||
|
||||
/* Append the essid of every allowed or ignored access point we know of
|
||||
* to a string array in the dbus message.
|
||||
@@ -309,7 +304,9 @@ static DBusMessage *nmi_dbus_get_networks (NMIAppInfo *info, DBusMessage *messag
|
||||
value = gconf_client_get (info->gconf_client, key, NULL);
|
||||
if (value && gconf_value_get_string (value))
|
||||
{
|
||||
dbus_message_iter_append_string (&iter_array, gconf_value_get_string (value));
|
||||
const gchar *essid;
|
||||
essid = gconf_value_get_string (value);
|
||||
dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_STRING, &essid);
|
||||
value_added = TRUE;
|
||||
gconf_value_free (value);
|
||||
}
|
||||
@@ -319,6 +316,8 @@ static DBusMessage *nmi_dbus_get_networks (NMIAppInfo *info, DBusMessage *messag
|
||||
}
|
||||
g_slist_free (dir_list);
|
||||
|
||||
dbus_message_iter_close_container (&iter, &iter_array);
|
||||
|
||||
if (!value_added)
|
||||
{
|
||||
dbus_message_unref (reply_message);
|
||||
@@ -450,8 +449,20 @@ static DBusMessage *nmi_dbus_get_network_properties (NMIAppInfo *info, DBusMessa
|
||||
}
|
||||
else
|
||||
{
|
||||
char **array = NULL;
|
||||
int num_items = 0;
|
||||
DBusMessageIter iter, array_iter;
|
||||
|
||||
reply = dbus_message_new_method_return (message);
|
||||
|
||||
dbus_message_iter_init_append (reply, &iter);
|
||||
|
||||
dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &essid);
|
||||
dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, ×tamp);
|
||||
dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &key);
|
||||
dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &key_type);
|
||||
dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &auth_method);
|
||||
dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &trusted);
|
||||
|
||||
dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &array_iter);
|
||||
|
||||
/* Add a string array of access point MAC addresses if the array is valid */
|
||||
if ( ap_addrs_value
|
||||
@@ -460,31 +471,16 @@ static DBusMessage *nmi_dbus_get_network_properties (NMIAppInfo *info, DBusMessa
|
||||
{
|
||||
GSList *list = gconf_value_get_list (ap_addrs_value);
|
||||
GSList *elt;
|
||||
int i;
|
||||
|
||||
num_items = g_slist_length (list);
|
||||
if (num_items > 0)
|
||||
array = g_malloc0 (sizeof (char *) * num_items);
|
||||
|
||||
for (elt = list, i = 0; elt; elt = g_slist_next (elt), i++)
|
||||
for (elt = list; elt; elt = g_slist_next (elt))
|
||||
{
|
||||
const char *string;
|
||||
if ((string = gconf_value_get_string ((GConfValue *)elt->data)))
|
||||
array[i] = g_strdup (string);
|
||||
dbus_message_iter_append_basic (&array_iter, DBUS_TYPE_STRING, &string);
|
||||
}
|
||||
}
|
||||
|
||||
reply = dbus_message_new_method_return (message);
|
||||
|
||||
/* Add general properties to dbus reply */
|
||||
dbus_message_append_args (reply, DBUS_TYPE_STRING, essid,
|
||||
DBUS_TYPE_INT32, timestamp,
|
||||
DBUS_TYPE_STRING, key,
|
||||
DBUS_TYPE_INT32, key_type,
|
||||
DBUS_TYPE_INT32, auth_method,
|
||||
DBUS_TYPE_BOOLEAN, trusted,
|
||||
DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, array, num_items,
|
||||
DBUS_TYPE_INVALID);
|
||||
dbus_message_iter_close_container (&iter, &array_iter);
|
||||
}
|
||||
gconf_value_free (ap_addrs_value);
|
||||
|
||||
@@ -492,7 +488,6 @@ static DBusMessage *nmi_dbus_get_network_properties (NMIAppInfo *info, DBusMessa
|
||||
g_free (key);
|
||||
|
||||
g_free (escaped_network);
|
||||
dbus_free (network);
|
||||
return (reply);
|
||||
}
|
||||
|
||||
@@ -633,7 +628,6 @@ static DBusMessage *nmi_dbus_add_network_address (NMIAppInfo *info, DBusMessage
|
||||
g_slist_foreach (new_mac_list, (GFunc)g_free, NULL);
|
||||
g_slist_free (new_mac_list);
|
||||
|
||||
dbus_free (addr);
|
||||
g_free (key);
|
||||
|
||||
return (NULL);
|
||||
@@ -776,8 +770,6 @@ static DBusHandlerResult nmi_dbus_filter (DBusConnection *connection, DBusMessag
|
||||
else if (dev)
|
||||
nmi_show_warning_dialog (TRUE, "Connection to the wired network failed.\n");
|
||||
|
||||
dbus_free (dev);
|
||||
dbus_free (net);
|
||||
}
|
||||
|
||||
return (handled ? DBUS_HANDLER_RESULT_HANDLED : DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
|
||||
@@ -797,7 +789,7 @@ static gboolean nmi_dbus_nm_is_running (DBusConnection *connection)
|
||||
g_return_val_if_fail (connection != NULL, FALSE);
|
||||
|
||||
dbus_error_init (&error);
|
||||
exists = dbus_bus_service_exists (connection, NM_DBUS_SERVICE, &error);
|
||||
exists = dbus_bus_name_has_owner (connection, NM_DBUS_SERVICE, &error);
|
||||
if (dbus_error_is_set (&error))
|
||||
dbus_error_free (&error);
|
||||
return (exists);
|
||||
@@ -817,8 +809,8 @@ int nmi_dbus_service_init (DBusConnection *dbus_connection, NMIAppInfo *info)
|
||||
int acquisition;
|
||||
|
||||
dbus_error_init (&dbus_error);
|
||||
acquisition = dbus_bus_acquire_service (dbus_connection, NMI_DBUS_SERVICE,
|
||||
DBUS_SERVICE_FLAG_PROHIBIT_REPLACEMENT,
|
||||
acquisition = dbus_bus_request_name (dbus_connection, NMI_DBUS_SERVICE,
|
||||
DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT,
|
||||
&dbus_error);
|
||||
if (dbus_error_is_set (&dbus_error))
|
||||
{
|
||||
@@ -826,7 +818,7 @@ int nmi_dbus_service_init (DBusConnection *dbus_connection, NMIAppInfo *info)
|
||||
dbus_error_free (&dbus_error);
|
||||
return (-1);
|
||||
}
|
||||
if (acquisition & DBUS_SERVICE_REPLY_SERVICE_EXISTS) {
|
||||
if (acquisition == DBUS_REQUEST_NAME_REPLY_EXISTS) {
|
||||
exit (0);
|
||||
}
|
||||
|
||||
@@ -858,8 +850,8 @@ int nmi_dbus_service_init (DBusConnection *dbus_connection, NMIAppInfo *info)
|
||||
|
||||
dbus_bus_add_match(dbus_connection,
|
||||
"type='signal',"
|
||||
"interface='" DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS "',"
|
||||
"sender='" DBUS_SERVICE_ORG_FREEDESKTOP_DBUS "'",
|
||||
"interface='" DBUS_INTERFACE_DBUS "',"
|
||||
"sender='" DBUS_SERVICE_DBUS "'",
|
||||
&dbus_error);
|
||||
if (dbus_error_is_set (&dbus_error))
|
||||
{
|
||||
@@ -869,3 +861,108 @@ int nmi_dbus_service_init (DBusConnection *dbus_connection, NMIAppInfo *info)
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
gchar *nm_dbus_escape_object_path (const gchar *utf8_string)
|
||||
{
|
||||
const gchar *p;
|
||||
gchar *object_path;
|
||||
GString *string;
|
||||
|
||||
g_return_val_if_fail (utf8_string != NULL, NULL);
|
||||
g_return_val_if_fail (g_utf8_validate (utf8_string, -1, NULL), NULL);
|
||||
|
||||
string = g_string_sized_new ((strlen (utf8_string) + 1) * 6);
|
||||
|
||||
for (p = utf8_string; *p != '\0'; p = g_utf8_next_char (p))
|
||||
{
|
||||
gunichar character;
|
||||
|
||||
character = g_utf8_get_char (p);
|
||||
|
||||
if (((character >= ((gunichar) 'a')) &&
|
||||
(character <= ((gunichar) 'z'))) ||
|
||||
((character >= ((gunichar) 'A')) &&
|
||||
(character <= ((gunichar) 'Z'))) ||
|
||||
((character >= ((gunichar) '0')) &&
|
||||
(character <= ((gunichar) '9'))) ||
|
||||
(character == ((gunichar) '/')))
|
||||
{
|
||||
g_string_append_c (string, (gchar) character);
|
||||
continue;
|
||||
}
|
||||
|
||||
g_string_append_printf (string, "_%x_", character);
|
||||
}
|
||||
|
||||
object_path = string->str;
|
||||
|
||||
g_string_free (string, FALSE);
|
||||
|
||||
return object_path;
|
||||
}
|
||||
|
||||
gchar *nm_dbus_unescape_object_path (const gchar *object_path)
|
||||
{
|
||||
const gchar *p;
|
||||
gchar *utf8_string;
|
||||
GString *string;
|
||||
|
||||
g_return_val_if_fail (object_path != NULL, NULL);
|
||||
|
||||
string = g_string_sized_new (strlen (object_path) + 1);
|
||||
|
||||
for (p = object_path; *p != '\0'; p++)
|
||||
{
|
||||
const gchar *q;
|
||||
gchar *hex_digits, *end, utf8_character[6] = { '\0' };
|
||||
gint utf8_character_size;
|
||||
gunichar character;
|
||||
gulong hex_value;
|
||||
|
||||
if (*p != '_')
|
||||
{
|
||||
g_string_append_c (string, *p);
|
||||
continue;
|
||||
}
|
||||
|
||||
q = strchr (p + 1, '_');
|
||||
|
||||
if ((q == NULL) || (q == p + 1))
|
||||
{
|
||||
g_string_free (string, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hex_digits = g_strndup (p + 1, (q - 1) - p);
|
||||
|
||||
hex_value = strtoul (hex_digits, &end, 16);
|
||||
|
||||
character = (gunichar) hex_value;
|
||||
|
||||
if (((hex_value == G_MAXLONG) && (errno == ERANGE)) ||
|
||||
(hex_value > G_MAXUINT32) ||
|
||||
(*end != '\0') ||
|
||||
(!g_unichar_validate (character)))
|
||||
{
|
||||
g_free (hex_digits);
|
||||
g_string_free (string, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
utf8_character_size =
|
||||
g_unichar_to_utf8 (character, utf8_character);
|
||||
|
||||
g_assert (utf8_character_size > 0);
|
||||
|
||||
g_string_append_len (string, utf8_character,
|
||||
utf8_character_size);
|
||||
|
||||
p = q;
|
||||
}
|
||||
|
||||
utf8_string = string->str;
|
||||
|
||||
g_string_free (string, FALSE);
|
||||
|
||||
return utf8_string;
|
||||
}
|
||||
|
@@ -189,7 +189,7 @@ static DBusHandlerResult libnm_glib_dbus_filter (DBusConnection *connection, DBu
|
||||
g_return_val_if_fail (message != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
|
||||
|
||||
dbus_error_init (&error);
|
||||
if (dbus_message_is_signal (message, DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL, "Disconnected"))
|
||||
if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected"))
|
||||
{
|
||||
/* Try to reactivate our connection to dbus on the next pass through the event loop */
|
||||
ctx->nm_status = LIBNM_NO_DBUS;
|
||||
@@ -197,7 +197,7 @@ static DBusHandlerResult libnm_glib_dbus_filter (DBusConnection *connection, DBu
|
||||
libnm_glib_schedule_dbus_watcher (ctx);
|
||||
}
|
||||
#if (DBUS_VERSION_MAJOR == 0 && DBUS_VERSION_MINOR == 22)
|
||||
else if (dbus_message_is_signal (message, DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS, "ServiceCreated"))
|
||||
else if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "ServiceCreated"))
|
||||
{
|
||||
char *service;
|
||||
|
||||
@@ -209,7 +209,7 @@ static DBusHandlerResult libnm_glib_dbus_filter (DBusConnection *connection, DBu
|
||||
g_free (status_string);
|
||||
}
|
||||
}
|
||||
else if (dbus_message_is_signal (message, DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS, "ServiceDeleted"))
|
||||
else if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "ServiceDeleted"))
|
||||
{
|
||||
char *service;
|
||||
|
||||
@@ -220,7 +220,7 @@ static DBusHandlerResult libnm_glib_dbus_filter (DBusConnection *connection, DBu
|
||||
}
|
||||
}
|
||||
#elif (DBUS_VERSION_MAJOR == 0 && DBUS_VERSION_MINOR == 23)
|
||||
else if (dbus_message_is_signal (message, DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS, "ServiceOwnerChanged"))
|
||||
else if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "ServiceOwnerChanged"))
|
||||
{
|
||||
/* New signal for dbus 0.23... */
|
||||
char *service;
|
||||
@@ -249,6 +249,37 @@ static DBusHandlerResult libnm_glib_dbus_filter (DBusConnection *connection, DBu
|
||||
}
|
||||
}
|
||||
}
|
||||
#elif ((DBUS_VERSION_MAJOR == 0) && ((DBUS_VERSION_MINOR == 30) || (DBUS_VERSION_MINOR == 31)))
|
||||
else if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged"))
|
||||
{
|
||||
/* New signal for dbus 0.23... */
|
||||
char *service;
|
||||
char *old_owner;
|
||||
char *new_owner;
|
||||
|
||||
if ( dbus_message_get_args (message, &error,
|
||||
DBUS_TYPE_STRING, &service,
|
||||
DBUS_TYPE_STRING, &old_owner,
|
||||
DBUS_TYPE_STRING, &new_owner,
|
||||
DBUS_TYPE_INVALID))
|
||||
{
|
||||
if (strcmp (service, NM_DBUS_SERVICE) == 0)
|
||||
{
|
||||
gboolean old_owner_good = (old_owner && (strlen (old_owner) > 0));
|
||||
gboolean new_owner_good = (new_owner && (strlen (new_owner) > 0));
|
||||
|
||||
if (!old_owner_good && new_owner_good) /* Equivalent to old ServiceCreated signal */
|
||||
{
|
||||
char *status_string = libnm_glib_get_nm_status (ctx->dbus_con);
|
||||
libnm_glib_update_status (ctx, status_string);
|
||||
g_free (status_string);
|
||||
}
|
||||
else if (old_owner_good && !new_owner_good) /* Equivalent to old ServiceDeleted signal */
|
||||
ctx->nm_status = LIBNM_NO_NETWORKMANAGER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
#error "Unrecognized version of DBUS."
|
||||
#endif
|
||||
@@ -312,8 +343,8 @@ static DBusConnection * libnm_glib_dbus_init (gpointer *user_data, GMainContext
|
||||
dbus_error_init (&error);
|
||||
dbus_bus_add_match(connection,
|
||||
"type='signal',"
|
||||
"interface='" DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS "',"
|
||||
"sender='" DBUS_SERVICE_ORG_FREEDESKTOP_DBUS "'",
|
||||
"interface='" DBUS_INTERFACE_DBUS "',"
|
||||
"sender='" DBUS_SERVICE_DBUS "'",
|
||||
&error);
|
||||
if (dbus_error_is_set (&error))
|
||||
dbus_error_free (&error);
|
||||
|
@@ -33,10 +33,8 @@
|
||||
#define DBUS_NO_SERVICE_ERROR "org.freedesktop.DBus.Error.ServiceDoesNotExist"
|
||||
|
||||
|
||||
/* dbus doesn't define a DBUS_TYPE_STRING_ARRAY so we fake one here for consistency */
|
||||
#define DBUS_TYPE_STRING_ARRAY ((int) '$')
|
||||
|
||||
|
||||
/*
|
||||
* nmwa_dbus_call_nm_method
|
||||
*
|
||||
@@ -150,6 +148,7 @@ static int nmwa_dbus_call_nm_method (DBusConnection *con, const char *path, cons
|
||||
case DBUS_TYPE_STRING_ARRAY:
|
||||
*((char ***)(arg)) = g_strdupv (dbus_string_array);
|
||||
*item_count = num_items;
|
||||
g_strfreev (dbus_string_array);
|
||||
break;
|
||||
case DBUS_TYPE_INT32:
|
||||
case DBUS_TYPE_UINT32:
|
||||
@@ -546,7 +545,7 @@ static char *nmwa_dbus_get_hal_device_string_property (DBusConnection *connectio
|
||||
return (NULL);
|
||||
|
||||
dbus_error_init (&error);
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, property_name, DBUS_TYPE_INVALID);
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, &property_name, DBUS_TYPE_INVALID);
|
||||
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
|
||||
dbus_message_unref (message);
|
||||
if (dbus_error_is_set (&error))
|
||||
@@ -590,6 +589,7 @@ static char *nmwa_dbus_get_hal_device_info (DBusConnection *connection, const ch
|
||||
DBusMessage *reply;
|
||||
gboolean exists = FALSE;
|
||||
char *info = NULL;
|
||||
const char *product;
|
||||
|
||||
g_return_val_if_fail (connection != NULL, NULL);
|
||||
g_return_val_if_fail (udi != NULL, NULL);
|
||||
@@ -599,7 +599,8 @@ static char *nmwa_dbus_get_hal_device_info (DBusConnection *connection, const ch
|
||||
return (NULL);
|
||||
|
||||
dbus_error_init (&error);
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, "info.product", DBUS_TYPE_INVALID);
|
||||
product = "info.product";
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, &product, DBUS_TYPE_INVALID);
|
||||
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
|
||||
dbus_message_unref (message);
|
||||
if (dbus_error_is_set (&error))
|
||||
@@ -652,16 +653,20 @@ void nmwa_dbus_set_device (DBusConnection *connection, const NetworkDevice *dev,
|
||||
if ((dev->type == DEVICE_TYPE_WIRELESS_ETHERNET) && network && network->essid)
|
||||
{
|
||||
fprintf (stderr, "Forcing device '%s' and network '%s' %s passphrase\n", dev->nm_device, network->essid, passphrase ? "with" : "without");
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, dev->nm_device,
|
||||
DBUS_TYPE_STRING, network->essid,
|
||||
DBUS_TYPE_STRING, (passphrase ? passphrase : ""),
|
||||
DBUS_TYPE_INT32, key_type,
|
||||
|
||||
if (passphrase == NULL)
|
||||
passphrase = "";
|
||||
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, &dev->nm_device,
|
||||
DBUS_TYPE_STRING, &network->essid,
|
||||
DBUS_TYPE_STRING, &passphrase,
|
||||
DBUS_TYPE_INT32, &key_type,
|
||||
DBUS_TYPE_INVALID);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (stderr, "Forcing device '%s'\n", dev->nm_device);
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, dev->nm_device, DBUS_TYPE_INVALID);
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, &dev->nm_device, DBUS_TYPE_INVALID);
|
||||
}
|
||||
dbus_connection_send (connection, message, NULL);
|
||||
}
|
||||
@@ -690,10 +695,12 @@ void nmwa_dbus_create_network (DBusConnection *connection, const NetworkDevice *
|
||||
if (network && network->essid)
|
||||
{
|
||||
fprintf (stderr, "Creating network '%s' %s passphrase on device '%s'.\n", network->essid, passphrase ? "with" : "without", dev->nm_device);
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, dev->nm_device,
|
||||
DBUS_TYPE_STRING, network->essid,
|
||||
DBUS_TYPE_STRING, (passphrase ? passphrase : ""),
|
||||
DBUS_TYPE_INT32, key_type,
|
||||
if (passphrase == NULL)
|
||||
passphrase = "";
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, &dev->nm_device,
|
||||
DBUS_TYPE_STRING, &network->essid,
|
||||
DBUS_TYPE_STRING, &passphrase,
|
||||
DBUS_TYPE_INT32, &key_type,
|
||||
DBUS_TYPE_INVALID);
|
||||
}
|
||||
dbus_connection_send (connection, message, NULL);
|
||||
@@ -718,7 +725,7 @@ void nmwa_dbus_enable_scanning (NMWirelessApplet *applet, gboolean enabled)
|
||||
|
||||
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "setScanningEnabled")))
|
||||
{
|
||||
dbus_message_append_args (message, DBUS_TYPE_BOOLEAN, enabled, DBUS_TYPE_INVALID);
|
||||
dbus_message_append_args (message, DBUS_TYPE_BOOLEAN, &enabled, DBUS_TYPE_INVALID);
|
||||
dbus_connection_send (applet->connection, message, NULL);
|
||||
applet->scanning_enabled = nmwa_dbus_get_scanning_enabled (applet);
|
||||
}
|
||||
@@ -740,7 +747,7 @@ void nmwa_dbus_enable_wireless (NMWirelessApplet *applet, gboolean enabled)
|
||||
|
||||
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "setWirelessEnabled")))
|
||||
{
|
||||
dbus_message_append_args (message, DBUS_TYPE_BOOLEAN, enabled, DBUS_TYPE_INVALID);
|
||||
dbus_message_append_args (message, DBUS_TYPE_BOOLEAN, &enabled, DBUS_TYPE_INVALID);
|
||||
dbus_connection_send (applet->connection, message, NULL);
|
||||
applet->wireless_enabled = nmwa_dbus_get_wireless_enabled (applet);
|
||||
}
|
||||
@@ -1475,33 +1482,9 @@ static DBusHandlerResult nmwa_dbus_filter (DBusConnection *connection, DBusMessa
|
||||
|
||||
dbus_error_init (&error);
|
||||
|
||||
#if (DBUS_VERSION_MAJOR == 0 && DBUS_VERSION_MINOR == 22)
|
||||
/* Old signal names for dbus <= 0.22 */
|
||||
if (dbus_message_is_signal (message, DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS, "ServiceCreated"))
|
||||
if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged"))
|
||||
{
|
||||
char *service;
|
||||
|
||||
if ( dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &service, DBUS_TYPE_INVALID)
|
||||
&& (strcmp (service, NM_DBUS_SERVICE) == 0) && (applet->applet_state == APPLET_STATE_NO_NM))
|
||||
applet->applet_state = APPLET_STATE_NO_CONNECTION;
|
||||
}
|
||||
else if (dbus_message_is_signal (message, DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS, "ServiceDeleted"))
|
||||
{
|
||||
char *service;
|
||||
|
||||
if (dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &service, DBUS_TYPE_INVALID))
|
||||
{
|
||||
if (strcmp (service, NM_DBUS_SERVICE) == 0)
|
||||
applet->applet_state = APPLET_STATE_NO_NM;
|
||||
else if (strcmp (service, NMI_DBUS_SERVICE) == 0)
|
||||
gtk_main_quit (); /* Just die if NetworkManagerInfo dies */
|
||||
}
|
||||
}
|
||||
#elif (DBUS_VERSION_MAJOR == 0 && DBUS_VERSION_MINOR == 23)
|
||||
if (dbus_message_is_signal (message, DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS, "ServiceOwnerChanged"))
|
||||
{
|
||||
/* New signal for dbus 0.23... */
|
||||
char *service;
|
||||
char *old_owner;
|
||||
char *new_owner;
|
||||
|
||||
@@ -1530,9 +1513,6 @@ static DBusHandlerResult nmwa_dbus_filter (DBusConnection *connection, DBusMessa
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
#error "Unrecognized version of DBUS."
|
||||
#endif
|
||||
else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "WirelessNetworkUpdate"))
|
||||
nmwa_dbus_device_update_one_network (applet, message);
|
||||
else if ( dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceNowActive")
|
||||
@@ -1567,7 +1547,7 @@ static gboolean nmwa_dbus_nm_is_running (DBusConnection *connection)
|
||||
g_return_val_if_fail (connection != NULL, FALSE);
|
||||
|
||||
dbus_error_init (&error);
|
||||
exists = dbus_bus_service_exists (connection, NM_DBUS_SERVICE, &error);
|
||||
exists = dbus_bus_name_has_owner (connection, NM_DBUS_SERVICE, &error);
|
||||
if (dbus_error_is_set (&error))
|
||||
dbus_error_free (&error);
|
||||
return (exists);
|
||||
@@ -1605,8 +1585,8 @@ static DBusConnection * nmwa_dbus_init (NMWirelessApplet *applet, GMainContext *
|
||||
|
||||
dbus_bus_add_match(connection,
|
||||
"type='signal',"
|
||||
"interface='" DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS "',"
|
||||
"sender='" DBUS_SERVICE_ORG_FREEDESKTOP_DBUS "'",
|
||||
"interface='" DBUS_INTERFACE_DBUS "',"
|
||||
"sender='" DBUS_SERVICE_DBUS "'",
|
||||
&error);
|
||||
if (dbus_error_is_set (&error))
|
||||
dbus_error_free (&error);
|
||||
|
@@ -66,19 +66,19 @@ static char *nm_get_device_interface_from_hal (LibHalContext *ctx, const char *u
|
||||
{
|
||||
char *iface = NULL;
|
||||
|
||||
if (hal_device_property_exists (ctx, udi, "net.interface"))
|
||||
if (libhal_device_property_exists (ctx, udi, "net.interface", NULL))
|
||||
{
|
||||
/* Only use Ethernet and Wireless devices at the moment */
|
||||
if (hal_device_property_exists (ctx, udi, "info.category"))
|
||||
if (libhal_device_property_exists (ctx, udi, "info.category", NULL))
|
||||
{
|
||||
char *category = hal_device_get_property_string (ctx, udi, "info.category");
|
||||
char *category = libhal_device_get_property_string (ctx, udi, "info.category", NULL);
|
||||
if (category && (!strcmp (category, "net.80203") || !strcmp (category, "net.80211")))
|
||||
{
|
||||
char *temp = hal_device_get_property_string (ctx, udi, "net.interface");
|
||||
char *temp = libhal_device_get_property_string (ctx, udi, "net.interface", NULL);
|
||||
iface = g_strdup (temp);
|
||||
hal_free_string (temp);
|
||||
libhal_free_string (temp);
|
||||
}
|
||||
hal_free_string (category);
|
||||
libhal_free_string (category);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ static void nm_hal_mainloop_integration (LibHalContext *ctx, DBusConnection * db
|
||||
*/
|
||||
static void nm_hal_device_added (LibHalContext *ctx, const char *udi)
|
||||
{
|
||||
NMData *data = (NMData *)hal_ctx_get_user_data (ctx);
|
||||
NMData *data = (NMData *)libhal_ctx_get_user_data (ctx);
|
||||
char *iface = NULL;
|
||||
|
||||
g_return_if_fail (data != NULL);
|
||||
@@ -244,7 +244,7 @@ static void nm_hal_device_added (LibHalContext *ctx, const char *udi)
|
||||
*/
|
||||
static void nm_hal_device_removed (LibHalContext *ctx, const char *udi)
|
||||
{
|
||||
NMData *data = (NMData *)hal_ctx_get_user_data (ctx);
|
||||
NMData *data = (NMData *)libhal_ctx_get_user_data (ctx);
|
||||
|
||||
g_return_if_fail (data != NULL);
|
||||
|
||||
@@ -260,7 +260,7 @@ static void nm_hal_device_removed (LibHalContext *ctx, const char *udi)
|
||||
*/
|
||||
static void nm_hal_device_new_capability (LibHalContext *ctx, const char *udi, const char *capability)
|
||||
{
|
||||
NMData *data = (NMData *)hal_ctx_get_user_data (ctx);
|
||||
NMData *data = (NMData *)libhal_ctx_get_user_data (ctx);
|
||||
|
||||
g_return_if_fail (data != NULL);
|
||||
|
||||
@@ -295,7 +295,7 @@ static void nm_hal_device_lost_capability (LibHalContext *ctx, const char *udi,
|
||||
*/
|
||||
static void nm_hal_device_property_modified (LibHalContext *ctx, const char *udi, const char *key, dbus_bool_t is_removed, dbus_bool_t is_added)
|
||||
{
|
||||
NMData *data = (NMData *)hal_ctx_get_user_data (ctx);
|
||||
NMData *data = (NMData *)libhal_ctx_get_user_data (ctx);
|
||||
gboolean link = FALSE;
|
||||
|
||||
g_return_if_fail (data != NULL);
|
||||
@@ -308,10 +308,10 @@ static void nm_hal_device_property_modified (LibHalContext *ctx, const char *udi
|
||||
if (is_removed || (strcmp (key, "net.80203.link") != 0))
|
||||
return;
|
||||
|
||||
if (!hal_device_property_exists (ctx, udi, "net.80203.link"))
|
||||
if (!libhal_device_property_exists (ctx, udi, "net.80203.link", NULL))
|
||||
return;
|
||||
|
||||
link = hal_device_get_property_bool (ctx, udi, "net.80203.link");
|
||||
link = libhal_device_get_property_bool (ctx, udi, "net.80203.link", NULL);
|
||||
|
||||
/* Attempt to acquire mutex for device link updating. If acquire fails ignore the event. */
|
||||
if (nm_try_acquire_mutex (data->dev_list_mutex, __FUNCTION__))
|
||||
@@ -358,10 +358,20 @@ static void nm_add_initial_devices (NMData *data)
|
||||
int num_net_devices;
|
||||
int i;
|
||||
|
||||
DBusError error;
|
||||
|
||||
g_return_if_fail (data != NULL);
|
||||
|
||||
dbus_error_init (&error);
|
||||
/* Grab a list of network devices */
|
||||
net_devices = hal_find_device_by_capability (data->hal_ctx, "net", &num_net_devices);
|
||||
net_devices = libhal_find_device_by_capability (data->hal_ctx, "net", &num_net_devices, &error);
|
||||
if (dbus_error_is_set (&error))
|
||||
{
|
||||
syslog (LOG_ERR, "nm_add_initial_devices() could not find existing"
|
||||
"networking devices: %s", error.message);
|
||||
dbus_error_free (&error);
|
||||
}
|
||||
|
||||
if (net_devices)
|
||||
{
|
||||
for (i = 0; i < num_net_devices; i++)
|
||||
@@ -376,7 +386,7 @@ static void nm_add_initial_devices (NMData *data)
|
||||
}
|
||||
}
|
||||
|
||||
hal_free_string_array (net_devices);
|
||||
libhal_free_string_array (net_devices);
|
||||
}
|
||||
|
||||
|
||||
@@ -473,22 +483,6 @@ gboolean nm_link_state_monitor (gpointer user_data)
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* libhal callback function structure
|
||||
*/
|
||||
static LibHalFunctions hal_functions =
|
||||
{
|
||||
nm_hal_mainloop_integration,
|
||||
nm_hal_device_added,
|
||||
nm_hal_device_removed,
|
||||
nm_hal_device_new_capability,
|
||||
nm_hal_device_lost_capability,
|
||||
nm_hal_device_property_modified,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* nm_data_new
|
||||
*
|
||||
@@ -642,6 +636,8 @@ int main( int argc, char *argv[] )
|
||||
gboolean become_daemon = TRUE;
|
||||
gboolean enable_test_devices = FALSE;
|
||||
GError *error = NULL;
|
||||
DBusError dbus_error;
|
||||
|
||||
|
||||
if ((int)getuid() != 0)
|
||||
{
|
||||
@@ -741,14 +737,46 @@ int main( int argc, char *argv[] )
|
||||
main_context = nm_data->main_context;
|
||||
|
||||
/* Initialize libhal. We get a connection to the hal daemon here. */
|
||||
if ((ctx = hal_initialize (&hal_functions, FALSE)) == NULL)
|
||||
if ((ctx = libhal_ctx_new()) == NULL)
|
||||
{
|
||||
syslog (LOG_CRIT, "hal_initialize() failed, exiting... Make sure the hal daemon is running?");
|
||||
syslog (LOG_CRIT, "libhal_ctx_new() failed, exiting...");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
nm_hal_mainloop_integration (ctx, nm_data->dbus_connection);
|
||||
|
||||
libhal_ctx_set_dbus_connection (ctx, nm_data->dbus_connection);
|
||||
|
||||
dbus_error_init (&dbus_error);
|
||||
if(!libhal_ctx_init (ctx, &dbus_error)) {
|
||||
syslog (LOG_CRIT, "libhal_ctx_init() failed, exiting... Make sure the hal daemon is running? - %s", dbus_error.message);
|
||||
|
||||
dbus_error_free (&dbus_error);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
nm_data->hal_ctx = ctx;
|
||||
hal_ctx_set_user_data (nm_data->hal_ctx, nm_data);
|
||||
hal_device_property_watch_all (nm_data->hal_ctx);
|
||||
libhal_ctx_set_user_data (nm_data->hal_ctx, nm_data);
|
||||
|
||||
libhal_ctx_set_device_added (ctx,
|
||||
nm_hal_device_added);
|
||||
libhal_ctx_set_device_removed (ctx,
|
||||
nm_hal_device_removed);
|
||||
libhal_ctx_set_device_new_capability (ctx,
|
||||
nm_hal_device_new_capability);
|
||||
libhal_ctx_set_device_lost_capability (ctx,
|
||||
nm_hal_device_lost_capability);
|
||||
libhal_ctx_set_device_property_modified (ctx,
|
||||
nm_hal_device_property_modified);
|
||||
|
||||
libhal_device_property_watch_all (nm_data->hal_ctx, &dbus_error);
|
||||
|
||||
if (dbus_error_is_set (&dbus_error))
|
||||
{
|
||||
syslog (LOG_CRIT, "libhal_device_property_watch_all(): %s", dbus_error.message);
|
||||
dbus_error_free (&dbus_error);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Grab network devices that are already present and add them to our list */
|
||||
nm_add_initial_devices (nm_data);
|
||||
@@ -779,8 +807,13 @@ int main( int argc, char *argv[] )
|
||||
g_source_remove (link_source_id);
|
||||
|
||||
/* Cleanup */
|
||||
if (hal_shutdown (nm_data->hal_ctx) != 0)
|
||||
syslog (LOG_NOTICE, "Error: libhal shutdown failed");
|
||||
if (libhal_ctx_shutdown (nm_data->hal_ctx, &dbus_error) != 0) {
|
||||
syslog (LOG_NOTICE, "Error: libhal shutdown failed - %s", dbus_error.message);
|
||||
|
||||
dbus_error_free (&dbus_error);
|
||||
}
|
||||
|
||||
libhal_ctx_free (nm_data->hal_ctx);
|
||||
|
||||
nm_data_free (nm_data);
|
||||
|
||||
|
@@ -156,7 +156,7 @@ static gboolean nm_dbus_send_network_not_found (gpointer user_data)
|
||||
goto out;
|
||||
}
|
||||
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, cb_data->net, DBUS_TYPE_INVALID);
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, &cb_data->net, DBUS_TYPE_INVALID);
|
||||
if (!dbus_connection_send (cb_data->app_data->dbus_connection, message, NULL))
|
||||
syslog (LOG_WARNING, "nm_dbus_send_network_not_found(): could not send dbus message");
|
||||
|
||||
@@ -251,7 +251,7 @@ void nm_dbus_signal_device_status_change (DBusConnection *connection, NMDevice *
|
||||
{
|
||||
DBusMessage *message;
|
||||
unsigned char *dev_path;
|
||||
unsigned char *signal = NULL;
|
||||
const char *signal = NULL;
|
||||
NMAccessPoint *ap = NULL;
|
||||
|
||||
g_return_if_fail (connection != NULL);
|
||||
@@ -295,10 +295,14 @@ void nm_dbus_signal_device_status_change (DBusConnection *connection, NMDevice *
|
||||
if ((status == DEVICE_ACTIVATION_FAILED) && nm_device_is_wireless (dev))
|
||||
ap = nm_device_get_best_ap (dev);
|
||||
/* If the device was wireless, attach the name of the wireless network that failed to activate */
|
||||
if (ap && nm_ap_get_essid (ap))
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, dev_path, DBUS_TYPE_STRING, nm_ap_get_essid (ap), DBUS_TYPE_INVALID);
|
||||
else
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, dev_path, DBUS_TYPE_INVALID);
|
||||
if (ap && nm_ap_get_essid (ap)) {
|
||||
const char *essid;
|
||||
essid = nm_ap_get_essid (ap);
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, &dev_path,
|
||||
DBUS_TYPE_STRING, &essid,
|
||||
DBUS_TYPE_INVALID);
|
||||
} else
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, &dev_path, DBUS_TYPE_INVALID);
|
||||
|
||||
if (ap)
|
||||
nm_ap_unref (ap);
|
||||
@@ -365,7 +369,7 @@ void nm_dbus_signal_network_status_change (DBusConnection *connection, NMData *d
|
||||
|
||||
if ((status = nm_dbus_network_status_from_data (data)))
|
||||
{
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, status, DBUS_TYPE_INVALID);
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, &status, DBUS_TYPE_INVALID);
|
||||
|
||||
if (!dbus_connection_send (connection, message, NULL))
|
||||
syslog (LOG_WARNING, "nm_dbus_signal_device_status_change(): Could not raise the signal!");
|
||||
@@ -401,7 +405,7 @@ void nm_dbus_signal_device_ip4_address_change (DBusConnection *connection, NMDev
|
||||
return;
|
||||
}
|
||||
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, dev_path, DBUS_TYPE_INVALID);
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, &dev_path, DBUS_TYPE_INVALID);
|
||||
g_free (dev_path);
|
||||
|
||||
if (!dbus_connection_send (connection, message, NULL))
|
||||
@@ -447,16 +451,16 @@ void nm_dbus_signal_wireless_network_change (DBusConnection *connection, NMDevic
|
||||
}
|
||||
|
||||
dbus_message_append_args (message,
|
||||
DBUS_TYPE_STRING, dev_path,
|
||||
DBUS_TYPE_STRING, ap_path,
|
||||
DBUS_TYPE_UINT32, status,
|
||||
DBUS_TYPE_STRING, &dev_path,
|
||||
DBUS_TYPE_STRING, &ap_path,
|
||||
DBUS_TYPE_UINT32, &status,
|
||||
DBUS_TYPE_INVALID);
|
||||
g_free (ap_path);
|
||||
g_free (dev_path);
|
||||
|
||||
/* Append signal-specific data */
|
||||
if (status == NETWORK_STATUS_STRENGTH_CHANGED)
|
||||
dbus_message_append_args (message, DBUS_TYPE_INT32, strength, DBUS_TYPE_INVALID);
|
||||
dbus_message_append_args (message, DBUS_TYPE_INT32, &strength, DBUS_TYPE_INVALID);
|
||||
|
||||
if (!dbus_connection_send (connection, message, NULL))
|
||||
syslog (LOG_WARNING, "nnm_dbus_signal_wireless_network_appeared(): Could not raise the WirelessNetworkAppeared signal!");
|
||||
@@ -474,6 +478,7 @@ void nm_dbus_signal_wireless_network_change (DBusConnection *connection, NMDevic
|
||||
void nm_dbus_get_user_key_for_network (DBusConnection *connection, NMDevice *dev, NMAccessPoint *ap, int attempt)
|
||||
{
|
||||
DBusMessage *message;
|
||||
const char *iface, *essid;
|
||||
|
||||
g_return_if_fail (connection != NULL);
|
||||
g_return_if_fail (dev != NULL);
|
||||
@@ -489,9 +494,11 @@ void nm_dbus_get_user_key_for_network (DBusConnection *connection, NMDevice *dev
|
||||
return;
|
||||
}
|
||||
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, nm_device_get_iface (dev),
|
||||
DBUS_TYPE_STRING, nm_ap_get_essid (ap),
|
||||
DBUS_TYPE_INT32, attempt,
|
||||
iface = nm_device_get_iface (dev);
|
||||
essid = nm_ap_get_essid (ap);
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, &iface,
|
||||
DBUS_TYPE_STRING, &essid,
|
||||
DBUS_TYPE_INT32, &attempt,
|
||||
DBUS_TYPE_INVALID);
|
||||
|
||||
if (!dbus_connection_send (connection, message, NULL))
|
||||
@@ -539,7 +546,6 @@ NMAccessPoint *nm_dbus_get_network_object (DBusConnection *connection, NMNetwork
|
||||
DBusMessage *message;
|
||||
DBusError error;
|
||||
DBusMessage *reply;
|
||||
gboolean success = FALSE;
|
||||
NMAccessPoint *ap = NULL;
|
||||
|
||||
char *essid = NULL;
|
||||
@@ -548,8 +554,8 @@ NMAccessPoint *nm_dbus_get_network_object (DBusConnection *connection, NMNetwork
|
||||
NMEncKeyType key_type = -1;
|
||||
gboolean trusted = FALSE;
|
||||
NMDeviceAuthMethod auth_method = NM_DEVICE_AUTH_METHOD_UNKNOWN;
|
||||
char **addrs = NULL;
|
||||
gint num_addr = -1;
|
||||
DBusMessageIter iter;
|
||||
dbus_int32_t type_as_int32;
|
||||
|
||||
g_return_val_if_fail (connection != NULL, NULL);
|
||||
g_return_val_if_fail (network != NULL, NULL);
|
||||
@@ -561,8 +567,9 @@ NMAccessPoint *nm_dbus_get_network_object (DBusConnection *connection, NMNetwork
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, network,
|
||||
DBUS_TYPE_INT32, (int)type,
|
||||
type_as_int32 = (dbus_int32_t) type;
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, &network,
|
||||
DBUS_TYPE_INT32, &type_as_int32,
|
||||
DBUS_TYPE_INVALID);
|
||||
|
||||
/* Send message and get properties back from NetworkManagerInfo */
|
||||
@@ -582,64 +589,58 @@ NMAccessPoint *nm_dbus_get_network_object (DBusConnection *connection, NMNetwork
|
||||
goto out;
|
||||
}
|
||||
|
||||
dbus_error_init (&error);
|
||||
success = dbus_message_get_args (reply, &error,
|
||||
DBUS_TYPE_STRING, &essid,
|
||||
DBUS_TYPE_INT32, ×tamp_secs,
|
||||
DBUS_TYPE_STRING, &key,
|
||||
DBUS_TYPE_INT32, &key_type,
|
||||
DBUS_TYPE_INT32, &auth_method,
|
||||
DBUS_TYPE_BOOLEAN, &trusted,
|
||||
DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &addrs, &num_addr,
|
||||
DBUS_TYPE_INVALID);
|
||||
if (success)
|
||||
dbus_message_iter_init (reply, &iter);
|
||||
dbus_message_iter_get_basic (&iter, &essid);
|
||||
dbus_message_iter_get_basic (&iter, ×tamp_secs);
|
||||
dbus_message_iter_get_basic (&iter, &key);
|
||||
dbus_message_iter_get_basic (&iter, &key_type);
|
||||
dbus_message_iter_get_basic (&iter, &auth_method);
|
||||
dbus_message_iter_get_basic (&iter, &trusted);
|
||||
|
||||
if (timestamp_secs > 0)
|
||||
{
|
||||
if (timestamp_secs > 0)
|
||||
GTimeVal *timestamp = g_new0 (GTimeVal, 1);
|
||||
|
||||
ap = nm_ap_new ();
|
||||
nm_ap_set_essid (ap, essid);
|
||||
|
||||
timestamp->tv_sec = timestamp_secs;
|
||||
timestamp->tv_usec = 0;
|
||||
nm_ap_set_timestamp (ap, timestamp);
|
||||
g_free (timestamp);
|
||||
|
||||
nm_ap_set_trusted (ap, trusted);
|
||||
|
||||
if (key && strlen (key))
|
||||
nm_ap_set_enc_key_source (ap, key, key_type);
|
||||
else
|
||||
nm_ap_set_enc_key_source (ap, NULL, NM_ENC_TYPE_UNKNOWN);
|
||||
nm_ap_set_auth_method (ap, auth_method);
|
||||
|
||||
/* Get user addresses, form into a GSList, and stuff into the AP */
|
||||
{
|
||||
GTimeVal *timestamp = g_new0 (GTimeVal, 1);
|
||||
GSList *addr_list = NULL;
|
||||
DBusMessageIter array_iter;
|
||||
|
||||
ap = nm_ap_new ();
|
||||
nm_ap_set_essid (ap, essid);
|
||||
dbus_message_iter_recurse (&iter, &array_iter);
|
||||
|
||||
timestamp->tv_sec = timestamp_secs;
|
||||
timestamp->tv_usec = 0;
|
||||
nm_ap_set_timestamp (ap, timestamp);
|
||||
g_free (timestamp);
|
||||
|
||||
nm_ap_set_trusted (ap, trusted);
|
||||
|
||||
if (key && strlen (key))
|
||||
nm_ap_set_enc_key_source (ap, key, key_type);
|
||||
else
|
||||
nm_ap_set_enc_key_source (ap, NULL, NM_ENC_TYPE_UNKNOWN);
|
||||
nm_ap_set_auth_method (ap, auth_method);
|
||||
|
||||
/* Get user addresses, form into a GSList, and stuff into the AP */
|
||||
while (dbus_message_iter_get_arg_type (&array_iter) == DBUS_TYPE_STRING)
|
||||
{
|
||||
GSList *addr_list = NULL;
|
||||
int i;
|
||||
gchar *addr;
|
||||
|
||||
if (!addrs)
|
||||
num_addr = 0;
|
||||
|
||||
for (i = 0; i < num_addr; i++)
|
||||
{
|
||||
if (addrs[i] && (strlen (addrs[i]) >= 11))
|
||||
addr_list = g_slist_append (addr_list, g_strdup (addrs[i]));
|
||||
}
|
||||
nm_ap_set_user_addresses (ap, addr_list);
|
||||
g_slist_foreach (addr_list, (GFunc)g_free, NULL);
|
||||
g_slist_free (addr_list);
|
||||
dbus_message_iter_get_basic (&array_iter, &addr);
|
||||
if (addr && (strlen (addr) >= 11))
|
||||
addr_list = g_slist_append (addr_list, g_strdup (addr));
|
||||
}
|
||||
|
||||
nm_ap_set_user_addresses (ap, addr_list);
|
||||
g_slist_foreach (addr_list, (GFunc)g_free, NULL);
|
||||
g_slist_free (addr_list);
|
||||
}
|
||||
dbus_free_string_array (addrs);
|
||||
g_free (essid);
|
||||
g_free (key);
|
||||
}
|
||||
else
|
||||
syslog (LOG_ERR, "nm_dbus_get_network_object(): bad data, %s raised %s", error.name, error.message);
|
||||
|
||||
out:
|
||||
|
||||
if (reply)
|
||||
dbus_message_unref (reply);
|
||||
|
||||
@@ -658,6 +659,7 @@ gboolean nm_dbus_update_network_auth_method (DBusConnection *connection, const c
|
||||
DBusMessage *message;
|
||||
DBusError error;
|
||||
gboolean success = FALSE;
|
||||
dbus_int32_t auth_method_as_int32;
|
||||
|
||||
g_return_val_if_fail (connection != NULL, FALSE);
|
||||
g_return_val_if_fail (network != NULL, FALSE);
|
||||
@@ -670,8 +672,9 @@ gboolean nm_dbus_update_network_auth_method (DBusConnection *connection, const c
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
auth_method_as_int32 = (dbus_int32_t) auth_method;
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, network,
|
||||
DBUS_TYPE_INT32, (int)auth_method,
|
||||
DBUS_TYPE_INT32, &auth_method,
|
||||
DBUS_TYPE_INVALID);
|
||||
|
||||
/* Send message and get trusted status back from NetworkManagerInfo */
|
||||
@@ -704,6 +707,7 @@ gboolean nm_dbus_add_network_address (DBusConnection *connection, NMNetworkType
|
||||
DBusError error;
|
||||
gboolean success = FALSE;
|
||||
char char_addr[20];
|
||||
dbus_int32_t type_as_int32;
|
||||
|
||||
g_return_val_if_fail (connection != NULL, FALSE);
|
||||
g_return_val_if_fail (network != NULL, FALSE);
|
||||
@@ -721,8 +725,9 @@ gboolean nm_dbus_add_network_address (DBusConnection *connection, NMNetworkType
|
||||
memset (char_addr, 0, 20);
|
||||
ether_ntoa_r (addr, &char_addr[0]);
|
||||
|
||||
type_as_int32 = (dbus_int32_t) type;
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, network,
|
||||
DBUS_TYPE_INT32, (int)type,
|
||||
DBUS_TYPE_INT32, &type_as_int32,
|
||||
DBUS_TYPE_STRING, &char_addr,
|
||||
DBUS_TYPE_INVALID);
|
||||
|
||||
@@ -755,6 +760,7 @@ char ** nm_dbus_get_networks (DBusConnection *connection, NMNetworkType type, in
|
||||
DBusError error;
|
||||
DBusMessage *reply;
|
||||
char **networks = NULL;
|
||||
dbus_int32_t type_as_int32;
|
||||
|
||||
*num_networks = 0;
|
||||
g_return_val_if_fail (connection != NULL, NULL);
|
||||
@@ -768,7 +774,8 @@ char ** nm_dbus_get_networks (DBusConnection *connection, NMNetworkType type, in
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
dbus_message_append_args (message, DBUS_TYPE_INT32, (int)type, DBUS_TYPE_INVALID);
|
||||
type_as_int32 = (dbus_int32_t) type;
|
||||
dbus_message_append_args (message, DBUS_TYPE_INT32, &type_as_int32, DBUS_TYPE_INVALID);
|
||||
|
||||
/* Send message and get essid back from NetworkManagerInfo */
|
||||
dbus_error_init (&error);
|
||||
@@ -780,11 +787,33 @@ char ** nm_dbus_get_networks (DBusConnection *connection, NMNetworkType type, in
|
||||
syslog (LOG_NOTICE, "nm_dbus_get_networks(): reply was NULL.");
|
||||
else
|
||||
{
|
||||
dbus_error_init (&error);
|
||||
dbus_message_get_args (reply, &error, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
|
||||
&networks, num_networks, DBUS_TYPE_INVALID);
|
||||
if (dbus_error_is_set (&error))
|
||||
dbus_error_free (&error);
|
||||
DBusMessageIter iter, array_iter;
|
||||
GArray *buffer;
|
||||
|
||||
dbus_message_iter_init (reply, &iter);
|
||||
dbus_message_iter_recurse (&iter, &array_iter);
|
||||
|
||||
buffer = g_array_new (TRUE, TRUE, sizeof (gchar *));
|
||||
|
||||
if (buffer == NULL)
|
||||
return NULL;
|
||||
|
||||
while (dbus_message_iter_get_arg_type (&array_iter) == DBUS_TYPE_STRING) {
|
||||
const char *value;
|
||||
char *str;
|
||||
|
||||
dbus_message_iter_get_basic (&array_iter, &value);
|
||||
str = g_strdup (value);
|
||||
|
||||
if (str == NULL)
|
||||
return NULL;
|
||||
|
||||
g_array_append_val (buffer, str);
|
||||
|
||||
dbus_message_iter_next(&array_iter);
|
||||
}
|
||||
networks = (gchar **)(buffer->data);
|
||||
g_array_free (buffer, FALSE);
|
||||
}
|
||||
|
||||
if (reply)
|
||||
@@ -808,7 +837,7 @@ gboolean nm_dbus_nmi_is_running (DBusConnection *connection)
|
||||
g_return_val_if_fail (connection != NULL, FALSE);
|
||||
|
||||
dbus_error_init (&error);
|
||||
exists = dbus_bus_service_exists (connection, NMI_DBUS_SERVICE, &error);
|
||||
exists = dbus_bus_name_has_owner (connection, NMI_DBUS_SERVICE, &error);
|
||||
if (dbus_error_is_set (&error))
|
||||
dbus_error_free (&error);
|
||||
return (exists);
|
||||
@@ -851,26 +880,11 @@ static DBusHandlerResult nm_dbus_nmi_filter (DBusConnection *connection, DBusMes
|
||||
/* Update a single wireless network's data */
|
||||
syslog (LOG_DEBUG, "NetworkManagerInfo triggered update of wireless network '%s'", network);
|
||||
nm_ap_list_update_network_from_nmi (data->allowed_ap_list, network, data);
|
||||
dbus_free (network);
|
||||
handled = TRUE;
|
||||
}
|
||||
}
|
||||
#if (DBUS_VERSION_MAJOR == 0 && DBUS_VERSION_MINOR == 22)
|
||||
else if (dbus_message_is_signal (message, DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS, "ServiceCreated"))
|
||||
else if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged"))
|
||||
{
|
||||
/* Only for dbus <= 0.22 */
|
||||
char *service;
|
||||
|
||||
if ( dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &service, DBUS_TYPE_INVALID)
|
||||
&& (strcmp (service, NMI_DBUS_SERVICE) == 0))
|
||||
{
|
||||
nm_policy_schedule_allowed_ap_list_update (data);
|
||||
}
|
||||
}
|
||||
#elif (DBUS_VERSION_MAJOR == 0 && DBUS_VERSION_MINOR == 23)
|
||||
else if (dbus_message_is_signal (message, DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS, "ServiceOwnerChanged"))
|
||||
{
|
||||
/* New signal for dbus 0.23... */
|
||||
char *service;
|
||||
char *old_owner;
|
||||
char *new_owner;
|
||||
@@ -885,16 +899,10 @@ static DBusHandlerResult nm_dbus_nmi_filter (DBusConnection *connection, DBusMes
|
||||
gboolean old_owner_good = (old_owner && (strlen (old_owner) > 0));
|
||||
gboolean new_owner_good = (new_owner && (strlen (new_owner) > 0));
|
||||
|
||||
/* Service didn't used to have an owner, now it does. Equivalent to
|
||||
* "ServiceCreated" signal in dbus <= 0.22
|
||||
*/
|
||||
if (!old_owner_good && new_owner_good)
|
||||
nm_policy_schedule_allowed_ap_list_update (data);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#error "Unrecognized version of DBUS."
|
||||
#endif
|
||||
|
||||
if (dbus_error_is_set (&error))
|
||||
dbus_error_free (&error);
|
||||
@@ -1035,7 +1043,7 @@ gboolean nm_dbus_is_info_daemon_running (DBusConnection *connection)
|
||||
g_return_val_if_fail (connection != NULL, FALSE);
|
||||
|
||||
dbus_error_init (&error);
|
||||
running = dbus_bus_service_exists (connection, NMI_DBUS_SERVICE, &error);
|
||||
running = dbus_bus_name_has_owner (connection, NMI_DBUS_SERVICE, &error);
|
||||
if (dbus_error_is_set (&error))
|
||||
dbus_error_free (&error);
|
||||
return (running);
|
||||
@@ -1101,12 +1109,12 @@ DBusConnection *nm_dbus_init (NMData *data)
|
||||
|
||||
dbus_bus_add_match(connection,
|
||||
"type='signal',"
|
||||
"interface='" DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS "',"
|
||||
"sender='" DBUS_SERVICE_ORG_FREEDESKTOP_DBUS "'",
|
||||
"interface='" DBUS_INTERFACE_DBUS "',"
|
||||
"sender='" DBUS_SERVICE_DBUS "'",
|
||||
NULL);
|
||||
|
||||
dbus_error_init (&error);
|
||||
dbus_bus_acquire_service (connection, NM_DBUS_SERVICE, 0, &error);
|
||||
dbus_bus_request_name (connection, NM_DBUS_SERVICE, 0, &error);
|
||||
if (dbus_error_is_set (&error))
|
||||
{
|
||||
syslog (LOG_ERR, "nm_dbus_init() could not acquire its service. dbus_bus_acquire_service() says: '%s'", error.message);
|
||||
|
@@ -791,8 +791,8 @@ static gboolean nm_device_wired_link_active (NMDevice *dev)
|
||||
else
|
||||
{
|
||||
/* Device has carrier detect, yay! */
|
||||
if (hal_device_property_exists (dev->app_data->hal_ctx, nm_device_get_udi (dev), "net.80203.link"))
|
||||
link = hal_device_get_property_bool (dev->app_data->hal_ctx, nm_device_get_udi (dev), "net.80203.link");
|
||||
if (libhal_device_property_exists (dev->app_data->hal_ctx, nm_device_get_udi (dev), "net.80203.link", NULL))
|
||||
link = libhal_device_get_property_bool (dev->app_data->hal_ctx, nm_device_get_udi (dev), "net.80203.link", NULL);
|
||||
}
|
||||
|
||||
return (link);
|
||||
|
@@ -292,9 +292,9 @@ char *nm_get_device_driver_name (LibHalContext *ctx, NMDevice *dev)
|
||||
g_return_val_if_fail (dev != NULL, NULL);
|
||||
|
||||
if ( (udi = nm_device_get_udi (dev))
|
||||
&& hal_device_property_exists (ctx, udi, "net.linux.driver"))
|
||||
&& libhal_device_property_exists (ctx, udi, "net.linux.driver", NULL))
|
||||
{
|
||||
driver_name = hal_device_get_property_string (ctx, udi, "net.linux.driver");
|
||||
driver_name = libhal_device_get_property_string (ctx, udi, "net.linux.driver", NULL);
|
||||
}
|
||||
|
||||
return (driver_name);
|
||||
@@ -374,10 +374,10 @@ NMDriverSupportLevel nm_get_wired_driver_support_level (LibHalContext *ctx, NMDe
|
||||
|
||||
/* Ignore Ethernet-over-USB devices too for the moment (Red Hat #135722) */
|
||||
udi = nm_device_get_udi (dev);
|
||||
if ( hal_device_property_exists (ctx, udi, "usb.interface.class")
|
||||
&& (usb_test = hal_device_get_property_string (ctx, udi, "usb.interface.class")))
|
||||
if ( libhal_device_property_exists (ctx, udi, "usb.interface.class", NULL)
|
||||
&& (usb_test = libhal_device_get_property_string (ctx, udi, "usb.interface.class", NULL)))
|
||||
{
|
||||
hal_free_string (usb_test);
|
||||
libhal_free_string (usb_test);
|
||||
level = NM_DRIVER_UNSUPPORTED;
|
||||
}
|
||||
|
||||
|
@@ -32,6 +32,9 @@
|
||||
#include "NetworkManagerPolicy.h"
|
||||
#include "nm-dbus-device.h"
|
||||
|
||||
static gchar *nm_dbus_unescape_object_path (const gchar *object_path);
|
||||
static gchar *nm_dbus_escape_object_path (const gchar *utf8_string);
|
||||
|
||||
static DBusMessage *nm_dbus_device_get_name (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
|
||||
{
|
||||
DBusMessage *reply = NULL;
|
||||
@@ -40,8 +43,11 @@ static DBusMessage *nm_dbus_device_get_name (DBusConnection *connection, DBusMes
|
||||
g_return_val_if_fail (data && data->data && data->dev && connection && message, NULL);
|
||||
|
||||
dev = data->dev;
|
||||
if ((reply = dbus_message_new_method_return (message)))
|
||||
dbus_message_append_args (reply, DBUS_TYPE_STRING, nm_device_get_iface (dev), DBUS_TYPE_INVALID);
|
||||
if ((reply = dbus_message_new_method_return (message))) {
|
||||
const char *iface;
|
||||
iface = nm_device_get_iface (dev);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_STRING, &iface, DBUS_TYPE_INVALID);
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
@@ -54,8 +60,11 @@ static DBusMessage *nm_dbus_device_get_type (DBusConnection *connection, DBusMes
|
||||
g_return_val_if_fail (data && data->data && data->dev && connection && message, NULL);
|
||||
|
||||
dev = data->dev;
|
||||
if ((reply = dbus_message_new_method_return (message)))
|
||||
dbus_message_append_args (reply, DBUS_TYPE_INT32, nm_device_get_type (dev), DBUS_TYPE_INVALID);
|
||||
if ((reply = dbus_message_new_method_return (message))) {
|
||||
dbus_int32_t type;
|
||||
type = nm_device_get_type (dev);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_INT32, &type, DBUS_TYPE_INVALID);
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
@@ -68,8 +77,11 @@ static DBusMessage *nm_dbus_device_get_hal_udi (DBusConnection *connection, DBus
|
||||
g_return_val_if_fail (data && data->data && data->dev && connection && message, NULL);
|
||||
|
||||
dev = data->dev;
|
||||
if ((reply = dbus_message_new_method_return (message)))
|
||||
dbus_message_append_args (reply, DBUS_TYPE_STRING, nm_device_get_udi (dev), DBUS_TYPE_INVALID);
|
||||
if ((reply = dbus_message_new_method_return (message))) {
|
||||
const char *udi;
|
||||
udi = nm_device_get_udi (dev);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_STRING, &udi, DBUS_TYPE_INVALID);
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
@@ -82,8 +94,12 @@ static DBusMessage *nm_dbus_device_get_ip4_address (DBusConnection *connection,
|
||||
g_return_val_if_fail (data && data->data && data->dev && connection && message, NULL);
|
||||
|
||||
dev = data->dev;
|
||||
if ((reply = dbus_message_new_method_return (message)))
|
||||
dbus_message_append_args (reply, DBUS_TYPE_UINT32, nm_device_get_ip4_address (dev), DBUS_TYPE_INVALID);
|
||||
if ((reply = dbus_message_new_method_return (message))) {
|
||||
dbus_uint32_t address;
|
||||
|
||||
address = nm_device_get_ip4_address (dev);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_UINT32, &address, DBUS_TYPE_INVALID);
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
@@ -96,8 +112,11 @@ static DBusMessage *nm_dbus_device_get_mode (DBusConnection *connection, DBusMes
|
||||
g_return_val_if_fail (data && data->data && data->dev && connection && message, NULL);
|
||||
|
||||
dev = data->dev;
|
||||
if ((reply = dbus_message_new_method_return (message)))
|
||||
dbus_message_append_args (reply, DBUS_TYPE_UINT32, nm_device_get_mode (dev), DBUS_TYPE_INVALID);
|
||||
if ((reply = dbus_message_new_method_return (message))) {
|
||||
dbus_uint32_t mode;
|
||||
mode = nm_device_get_mode (dev);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_UINT32, &mode, DBUS_TYPE_INVALID);
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
@@ -110,8 +129,12 @@ static DBusMessage *nm_dbus_device_get_link_active (DBusConnection *connection,
|
||||
g_return_val_if_fail (data && data->data && data->dev && connection && message, NULL);
|
||||
|
||||
dev = data->dev;
|
||||
if ((reply = dbus_message_new_method_return (message)))
|
||||
dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, nm_device_get_link_active (dev), DBUS_TYPE_INVALID);
|
||||
if ((reply = dbus_message_new_method_return (message))) {
|
||||
dbus_bool_t is_active;
|
||||
|
||||
is_active = nm_device_get_link_active (dev);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &is_active, DBUS_TYPE_INVALID);
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
@@ -130,8 +153,12 @@ static DBusMessage *nm_dbus_device_get_strength (DBusConnection *connection, DBu
|
||||
reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "DeviceNotWireless",
|
||||
"Wired devices cannot have signal strength.");
|
||||
}
|
||||
else if ((reply = dbus_message_new_method_return (message)))
|
||||
dbus_message_append_args (reply, DBUS_TYPE_INT32, nm_device_get_signal_strength (dev), DBUS_TYPE_INVALID);
|
||||
else if ((reply = dbus_message_new_method_return (message))) {
|
||||
dbus_int32_t strength;
|
||||
|
||||
strength = nm_device_get_signal_strength (dev);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_INT32, &strength, DBUS_TYPE_INVALID);
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
@@ -166,7 +193,7 @@ static DBusMessage *nm_dbus_device_get_active_network (DBusConnection *connectio
|
||||
if ( (tmp_ap = nm_device_ap_list_get_ap_by_essid (dev, nm_ap_get_essid (best_ap)))
|
||||
&& (object_path = nm_device_get_path_for_ap (dev, tmp_ap)))
|
||||
{
|
||||
dbus_message_append_args (reply, DBUS_TYPE_STRING, object_path, DBUS_TYPE_INVALID);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_STRING, &object_path, DBUS_TYPE_INVALID);
|
||||
success = TRUE;
|
||||
}
|
||||
nm_ap_unref (best_ap);
|
||||
@@ -205,10 +232,11 @@ static DBusMessage *nm_dbus_device_get_networks (DBusConnection *connection, DBu
|
||||
gboolean success = FALSE;
|
||||
NMAccessPointList *ap_list;
|
||||
NMAPListIter *list_iter;
|
||||
char *object_path;
|
||||
char *object_path,
|
||||
*escaped_object_path;
|
||||
|
||||
dbus_message_iter_init (reply, &iter);
|
||||
dbus_message_iter_append_array (&iter, &iter_array, DBUS_TYPE_STRING);
|
||||
dbus_message_iter_init_append (reply, &iter);
|
||||
dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &iter_array);
|
||||
|
||||
if ((ap_list = nm_device_ap_list_get (dev)))
|
||||
{
|
||||
@@ -220,8 +248,11 @@ static DBusMessage *nm_dbus_device_get_networks (DBusConnection *connection, DBu
|
||||
{
|
||||
object_path = g_strdup_printf ("%s/%s/Networks/%s", NM_DBUS_PATH_DEVICES,
|
||||
nm_device_get_iface (dev), nm_ap_get_essid (ap));
|
||||
dbus_message_iter_append_string (&iter_array, object_path);
|
||||
escaped_object_path = nm_dbus_escape_object_path (object_path);
|
||||
g_free (object_path);
|
||||
dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_OBJECT_PATH,
|
||||
&escaped_object_path);
|
||||
g_free (escaped_object_path);
|
||||
success = TRUE;
|
||||
}
|
||||
}
|
||||
@@ -229,6 +260,8 @@ static DBusMessage *nm_dbus_device_get_networks (DBusConnection *connection, DBu
|
||||
}
|
||||
}
|
||||
|
||||
dbus_message_iter_close_container (&iter, &iter_array);
|
||||
|
||||
if (!success)
|
||||
{
|
||||
dbus_message_unref (reply);
|
||||
@@ -254,8 +287,11 @@ static DBusMessage *nm_dbus_device_get_supports_carrier_detect (DBusConnection *
|
||||
reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "DeviceNotWired",
|
||||
"Carrier detection is only supported for wired devices.");
|
||||
}
|
||||
else if ((reply = dbus_message_new_method_return (message)))
|
||||
dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, nm_device_get_supports_carrier_detect (dev), DBUS_TYPE_INVALID);
|
||||
else if ((reply = dbus_message_new_method_return (message))) {
|
||||
dbus_bool_t supports_carrier_detect;
|
||||
supports_carrier_detect = nm_device_get_supports_carrier_detect (dev);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &supports_carrier_detect, DBUS_TYPE_INVALID);
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
@@ -316,3 +352,107 @@ NMDbusMethodList *nm_dbus_device_methods_setup (void)
|
||||
return (list);
|
||||
}
|
||||
|
||||
static gchar *nm_dbus_escape_object_path (const gchar *utf8_string)
|
||||
{
|
||||
const gchar *p;
|
||||
gchar *object_path;
|
||||
GString *string;
|
||||
|
||||
g_return_val_if_fail (utf8_string != NULL, NULL);
|
||||
g_return_val_if_fail (g_utf8_validate (utf8_string, -1, NULL), NULL);
|
||||
|
||||
string = g_string_sized_new ((strlen (utf8_string) + 1) * 6);
|
||||
|
||||
for (p = utf8_string; *p != '\0'; p = g_utf8_next_char (p))
|
||||
{
|
||||
gunichar character;
|
||||
|
||||
character = g_utf8_get_char (p);
|
||||
|
||||
if (((character >= ((gunichar) 'a')) &&
|
||||
(character <= ((gunichar) 'z'))) ||
|
||||
((character >= ((gunichar) 'A')) &&
|
||||
(character <= ((gunichar) 'Z'))) ||
|
||||
((character >= ((gunichar) '0')) &&
|
||||
(character <= ((gunichar) '9'))) ||
|
||||
(character == ((gunichar) '/')))
|
||||
{
|
||||
g_string_append_c (string, (gchar) character);
|
||||
continue;
|
||||
}
|
||||
|
||||
g_string_append_printf (string, "_%x_", character);
|
||||
}
|
||||
|
||||
object_path = string->str;
|
||||
|
||||
g_string_free (string, FALSE);
|
||||
|
||||
return object_path;
|
||||
}
|
||||
|
||||
static gchar *nm_dbus_unescape_object_path (const gchar *object_path)
|
||||
{
|
||||
const gchar *p;
|
||||
gchar *utf8_string;
|
||||
GString *string;
|
||||
|
||||
g_return_val_if_fail (object_path != NULL, NULL);
|
||||
|
||||
string = g_string_sized_new (strlen (object_path) + 1);
|
||||
|
||||
for (p = object_path; *p != '\0'; p++)
|
||||
{
|
||||
const gchar *q;
|
||||
gchar *hex_digits, *end, utf8_character[6] = { '\0' };
|
||||
gint utf8_character_size;
|
||||
gunichar character;
|
||||
gulong hex_value;
|
||||
|
||||
if (*p != '_')
|
||||
{
|
||||
g_string_append_c (string, *p);
|
||||
continue;
|
||||
}
|
||||
|
||||
q = strchr (p + 1, '_');
|
||||
|
||||
if ((q == NULL) || (q == p + 1))
|
||||
{
|
||||
g_string_free (string, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hex_digits = g_strndup (p + 1, (q - 1) - p);
|
||||
|
||||
hex_value = strtoul (hex_digits, &end, 16);
|
||||
|
||||
character = (gunichar) hex_value;
|
||||
|
||||
if (((hex_value == G_MAXLONG) && (errno == ERANGE)) ||
|
||||
(hex_value > G_MAXUINT32) ||
|
||||
(*end != '\0') ||
|
||||
(!g_unichar_validate (character)))
|
||||
{
|
||||
g_free (hex_digits);
|
||||
g_string_free (string, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
utf8_character_size =
|
||||
g_unichar_to_utf8 (character, utf8_character);
|
||||
|
||||
g_assert (utf8_character_size > 0);
|
||||
|
||||
g_string_append_len (string, utf8_character,
|
||||
utf8_character_size);
|
||||
|
||||
p = q;
|
||||
}
|
||||
|
||||
utf8_string = string->str;
|
||||
|
||||
g_string_free (string, FALSE);
|
||||
|
||||
return utf8_string;
|
||||
}
|
||||
|
@@ -66,7 +66,7 @@ static int nm_dbus_dhcp_record_type (int id)
|
||||
__DBUS_REPLY_BYTYPE_val = ((dbus_uint16_t *)__DBUS_REPLY_BYTYPE_blob)[0]; \
|
||||
else \
|
||||
__DBUS_REPLY_BYTYPE_val = ((dbus_uint32_t *)__DBUS_REPLY_BYTYPE_blob)[0]; \
|
||||
dbus_message_append_args (reply, Dtype, __DBUS_REPLY_BYTYPE_val, DBUS_TYPE_INVALID); \
|
||||
dbus_message_append_args (reply, Dtype, &__DBUS_REPLY_BYTYPE_val, DBUS_TYPE_INVALID); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
@@ -79,25 +79,12 @@ static int nm_dbus_dhcp_record_type (int id)
|
||||
{ \
|
||||
DBusMessageIter __DBUS_REPLY_BYTYPE_iter, __DBUS_REPLY_BYTYPE_sub; \
|
||||
void *__DBUS_REPLY_BYTYPE_blob; \
|
||||
int __DBUS_REPLY_BYTYPE_i, __DBUS_REPLY_BYTYPE_count; \
|
||||
int __DBUS_REPLY_BYTYPE_count; \
|
||||
\
|
||||
__DBUS_REPLY_BYTYPE_blob = dhcp_interface_option_payload (dhcp_iface, data->opt_id); \
|
||||
__DBUS_REPLY_BYTYPE_count = dhcp_interface_option_len (dhcp_iface, data->opt_id) / __DBUS_REPLY_BYTYPE_len; \
|
||||
dbus_message_iter_init (reply, &__DBUS_REPLY_BYTYPE_iter); \
|
||||
dbus_message_iter_append_array (&__DBUS_REPLY_BYTYPE_iter, &__DBUS_REPLY_BYTYPE_sub, Dtype); \
|
||||
for (__DBUS_REPLY_BYTYPE_i = 0; __DBUS_REPLY_BYTYPE_i < __DBUS_REPLY_BYTYPE_count; __DBUS_REPLY_BYTYPE_i++) \
|
||||
{ \
|
||||
Ctype __DBUS_REPLY_BYTYPE_val; \
|
||||
\
|
||||
if (__DBUS_REPLY_BYTYPE_len == 1) \
|
||||
__DBUS_REPLY_BYTYPE_val = ((unsigned char *)__DBUS_REPLY_BYTYPE_blob)[__DBUS_REPLY_BYTYPE_i]; \
|
||||
else if (__DBUS_REPLY_BYTYPE_len == 2) \
|
||||
__DBUS_REPLY_BYTYPE_val = ((dbus_uint16_t *)__DBUS_REPLY_BYTYPE_blob)[__DBUS_REPLY_BYTYPE_i]; \
|
||||
else \
|
||||
__DBUS_REPLY_BYTYPE_val = ((dbus_uint32_t *)__DBUS_REPLY_BYTYPE_blob)[__DBUS_REPLY_BYTYPE_i]; \
|
||||
/*dbus_message_iter_append_basic (&__DBUS_REPLY_BYTYPE_sub, Dtype, __DBUS_REPLY_BYTYPE_val);*/ \
|
||||
dbus_message_iter_append_ ## Dappend (&__DBUS_REPLY_BYTYPE_sub, __DBUS_REPLY_BYTYPE_val); \
|
||||
} \
|
||||
dbus_message_iter_init_append (reply, &__DBUS_REPLY_BYTYPE_iter); \
|
||||
dbus_message_iter_append_fixed_array (&__DBUS_REPLY_BYTYPE_iter, Dtype, __DBUS_REPLY_BYTYPE_blob, __DBUS_REPLY_BYTYPE_count); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
@@ -111,7 +98,7 @@ static int nm_dbus_dhcp_record_type (int id)
|
||||
Ctype __DBUS_REPLY_BYTYPE_val; \
|
||||
\
|
||||
__DBUS_REPLY_BYTYPE_val = (Ctype)dhcp_interface_option_payload (dhcp_iface, data->opt_id); \
|
||||
dbus_message_append_args (reply, Dtype, __DBUS_REPLY_BYTYPE_val, DBUS_TYPE_INVALID); \
|
||||
dbus_message_append_args (reply, Dtype, &__DBUS_REPLY_BYTYPE_val, DBUS_TYPE_INVALID); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
@@ -130,8 +117,11 @@ static DBusMessage *nm_dbus_dhcp_get_len (DBusConnection *connection, DBusMessag
|
||||
g_return_val_if_fail (data && data->data && (data->opt_id >= 0) && (data->dhcp_iface != NULL) && connection && message, NULL);
|
||||
dhcp_iface = data->dhcp_iface;
|
||||
|
||||
if ((reply = dbus_message_new_method_return (message)) != NULL)
|
||||
dbus_message_append_args (reply, DBUS_TYPE_UINT32, dhcp_interface_option_len (dhcp_iface, data->opt_id), DBUS_TYPE_INVALID);
|
||||
if ((reply = dbus_message_new_method_return (message)) != NULL) {
|
||||
dbus_int32_t len;
|
||||
len = dhcp_interface_option_len (dhcp_iface, data->opt_id);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_UINT32, &len, DBUS_TYPE_INVALID);
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
@@ -152,12 +142,17 @@ static DBusMessage *nm_dbus_dhcp_get_type (DBusConnection *connection, DBusMessa
|
||||
|
||||
if ((reply = dbus_message_new_method_return (message)) != NULL)
|
||||
{
|
||||
if (nm_dbus_dhcp_record_type (data->opt_id) == DBUS_TYPE_STRING)
|
||||
dbus_message_append_args (reply, DBUS_TYPE_UINT32, DBUS_TYPE_STRING, DBUS_TYPE_INVALID);
|
||||
else if (dhcp_interface_option_len (dhcp_iface, data->opt_id) != dhcp_option_record_len (data->opt_id))
|
||||
dbus_message_append_args (reply, DBUS_TYPE_UINT32, DBUS_TYPE_ARRAY, DBUS_TYPE_INVALID);
|
||||
else
|
||||
dbus_message_append_args (reply, DBUS_TYPE_UINT32, nm_dbus_dhcp_record_type (data->opt_id), DBUS_TYPE_INVALID);
|
||||
dbus_uint32_t type;
|
||||
|
||||
if (nm_dbus_dhcp_record_type (data->opt_id) == DBUS_TYPE_STRING) {
|
||||
type = DBUS_TYPE_STRING;
|
||||
} else if (dhcp_interface_option_len (dhcp_iface, data->opt_id) != dhcp_option_record_len (data->opt_id)) {
|
||||
type = DBUS_TYPE_ARRAY;
|
||||
} else {
|
||||
type = nm_dbus_dhcp_record_type (data->opt_id);
|
||||
}
|
||||
|
||||
dbus_message_append_args (reply, DBUS_TYPE_UINT32, &type, DBUS_TYPE_INVALID);
|
||||
}
|
||||
|
||||
return reply;
|
||||
@@ -178,8 +173,11 @@ static DBusMessage *nm_dbus_dhcp_get_record_type (DBusConnection *connection, DB
|
||||
g_return_val_if_fail (data && data->data && (data->opt_id >= 0) && (data->dhcp_iface != NULL) && connection && message, NULL);
|
||||
dhcp_iface = data->dhcp_iface;
|
||||
|
||||
if ((reply = dbus_message_new_method_return (message)) != NULL)
|
||||
dbus_message_append_args (reply, DBUS_TYPE_UINT32, nm_dbus_dhcp_record_type (data->opt_id), DBUS_TYPE_INVALID);
|
||||
if ((reply = dbus_message_new_method_return (message)) != NULL) {
|
||||
dbus_uint32_t type;
|
||||
type = nm_dbus_dhcp_record_type (data->opt_id);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_UINT32, &type, DBUS_TYPE_INVALID);
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
@@ -325,8 +323,11 @@ static DBusMessage *nm_dbus_dhcp_get_name (DBusConnection *connection, DBusMessa
|
||||
|
||||
g_return_val_if_fail (data && data->data && (data->opt_id >= 0) && (data->dhcp_iface != NULL) && connection && message, NULL);
|
||||
|
||||
if ((reply = dbus_message_new_method_return (message)) != NULL)
|
||||
dbus_message_append_args (reply, DBUS_TYPE_STRING, dhcp_option_name (data->opt_id), DBUS_TYPE_INVALID);
|
||||
if ((reply = dbus_message_new_method_return (message)) != NULL) {
|
||||
const char *name;
|
||||
name = dhcp_option_name (data->opt_id);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID);
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
@@ -88,8 +88,11 @@ static DBusMessage *nm_dbus_net_get_name (DBusConnection *connection, DBusMessag
|
||||
|
||||
g_return_val_if_fail (data && data->data && data->dev && data->ap && connection && message, NULL);
|
||||
|
||||
if ((reply = dbus_message_new_method_return (message)))
|
||||
dbus_message_append_args (reply, DBUS_TYPE_STRING, nm_ap_get_essid (data->ap), DBUS_TYPE_INVALID);
|
||||
if ((reply = dbus_message_new_method_return (message))) {
|
||||
const char *essid;
|
||||
essid = nm_ap_get_essid (data->ap);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_STRING, &essid, DBUS_TYPE_INVALID);
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
@@ -106,7 +109,7 @@ static DBusMessage *nm_dbus_net_get_address (DBusConnection *connection, DBusMes
|
||||
|
||||
memset (&buf[0], 0, 20);
|
||||
iw_ether_ntop((const struct ether_addr *) (nm_ap_get_address (data->ap)), &buf[0]);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_STRING, &buf[0], DBUS_TYPE_INVALID);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_STRING, &buf, DBUS_TYPE_INVALID);
|
||||
}
|
||||
|
||||
return reply;
|
||||
@@ -144,7 +147,7 @@ static DBusMessage *nm_dbus_net_get_strength (DBusConnection *connection, DBusMe
|
||||
nm_ap_list_iter_free (iter);
|
||||
|
||||
append:
|
||||
dbus_message_append_args (reply, DBUS_TYPE_INT32, best_strength, DBUS_TYPE_INVALID);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_INT32, &best_strength, DBUS_TYPE_INVALID);
|
||||
}
|
||||
|
||||
return reply;
|
||||
@@ -156,8 +159,11 @@ static DBusMessage *nm_dbus_net_get_frequency (DBusConnection *connection, DBusM
|
||||
|
||||
g_return_val_if_fail (data && data->data && data->dev && data->ap && connection && message, NULL);
|
||||
|
||||
if ((reply = dbus_message_new_method_return (message)))
|
||||
dbus_message_append_args (reply, DBUS_TYPE_DOUBLE, nm_ap_get_freq (data->ap), DBUS_TYPE_INVALID);
|
||||
if ((reply = dbus_message_new_method_return (message))) {
|
||||
double freq;
|
||||
freq = nm_ap_get_freq (data->ap);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_DOUBLE, &freq, DBUS_TYPE_INVALID);
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
@@ -168,8 +174,11 @@ static DBusMessage *nm_dbus_net_get_rate (DBusConnection *connection, DBusMessag
|
||||
|
||||
g_return_val_if_fail (data && data->data && data->dev && data->ap && connection && message, NULL);
|
||||
|
||||
if ((reply = dbus_message_new_method_return (message)))
|
||||
dbus_message_append_args (reply, DBUS_TYPE_INT32, nm_ap_get_rate (data->ap), DBUS_TYPE_INVALID);
|
||||
if ((reply = dbus_message_new_method_return (message))) {
|
||||
dbus_int32_t rate;
|
||||
rate = nm_ap_get_rate (data->ap);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_INT32, &rate, DBUS_TYPE_INVALID);
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
@@ -180,8 +189,11 @@ static DBusMessage *nm_dbus_net_get_encrypted (DBusConnection *connection, DBusM
|
||||
|
||||
g_return_val_if_fail (data && data->data && data->dev && data->ap && connection && message, NULL);
|
||||
|
||||
if ((reply = dbus_message_new_method_return (message)))
|
||||
dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, nm_ap_get_encrypted (data->ap), DBUS_TYPE_INVALID);
|
||||
if ((reply = dbus_message_new_method_return (message))) {
|
||||
dbus_bool_t is_encrypted;
|
||||
is_encrypted = nm_ap_get_encrypted (data->ap);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &is_encrypted, DBUS_TYPE_INVALID);
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
@@ -192,8 +204,11 @@ static DBusMessage *nm_dbus_net_get_mode (DBusConnection *connection, DBusMessag
|
||||
|
||||
g_return_val_if_fail (data && data->data && data->dev && data->ap && connection && message, NULL);
|
||||
|
||||
if ((reply = dbus_message_new_method_return (message)))
|
||||
dbus_message_append_args (reply, DBUS_TYPE_UINT32, nm_ap_get_mode (data->ap), DBUS_TYPE_INVALID);
|
||||
if ((reply = dbus_message_new_method_return (message))) {
|
||||
dbus_uint32_t mode;
|
||||
mode = nm_ap_get_mode (data->ap);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_UINT32, &mode, DBUS_TYPE_INVALID);
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
142
src/nm-dbus-nm.c
142
src/nm-dbus-nm.c
@@ -32,6 +32,9 @@
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "NetworkManagerPolicy.h"
|
||||
|
||||
static gchar *nm_dbus_escape_object_path (const gchar *utf8_string);
|
||||
static gchar *nm_dbus_unescape_object_path (const gchar *object_path);
|
||||
|
||||
|
||||
/*
|
||||
* nm_dbus_nm_get_active_device
|
||||
@@ -58,7 +61,7 @@ static DBusMessage *nm_dbus_nm_get_active_device (DBusConnection *connection, DB
|
||||
return (NULL);
|
||||
|
||||
object_path = g_strdup_printf ("%s/%s", NM_DBUS_PATH_DEVICES, nm_device_get_iface (data->data->active_device));
|
||||
dbus_message_append_args (reply, DBUS_TYPE_STRING, object_path, DBUS_TYPE_INVALID);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_STRING, &object_path, DBUS_TYPE_INVALID);
|
||||
g_free (object_path);
|
||||
}
|
||||
else
|
||||
@@ -97,24 +100,28 @@ static DBusMessage *nm_dbus_nm_get_devices (DBusConnection *connection, DBusMess
|
||||
if (!(reply = dbus_message_new_method_return (message)))
|
||||
return NULL;
|
||||
|
||||
dbus_message_iter_init (reply, &iter);
|
||||
dbus_message_iter_append_array (&iter, &iter_array, DBUS_TYPE_STRING);
|
||||
|
||||
dbus_message_iter_init_append (reply, &iter);
|
||||
/* Iterate over device list and grab index of "active device" */
|
||||
if (nm_try_acquire_mutex (data->data->dev_list_mutex, __FUNCTION__))
|
||||
{
|
||||
GSList *elt;
|
||||
gboolean appended = FALSE;
|
||||
|
||||
dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &iter_array);
|
||||
|
||||
for (elt = data->data->dev_list; elt; elt = g_slist_next (elt))
|
||||
{
|
||||
NMDevice *dev = (NMDevice *)(elt->data);
|
||||
|
||||
if (dev && (nm_device_get_driver_support_level (dev) != NM_DRIVER_UNSUPPORTED))
|
||||
{
|
||||
char *object_path = g_strdup_printf ("%s/%s", NM_DBUS_PATH_DEVICES, nm_device_get_iface (dev));
|
||||
dbus_message_iter_append_string (&iter_array, object_path);
|
||||
g_free (object_path);
|
||||
char *object_path, *escaped_object_path;
|
||||
|
||||
object_path = g_strdup_printf ("%s/%s", NM_DBUS_PATH_DEVICES, nm_device_get_iface (dev));
|
||||
escaped_object_path = nm_dbus_escape_object_path (object_path);
|
||||
g_free (object_path);
|
||||
dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_OBJECT_PATH, &escaped_object_path);
|
||||
g_free (escaped_object_path);
|
||||
appended = TRUE;
|
||||
}
|
||||
}
|
||||
@@ -125,10 +132,12 @@ static DBusMessage *nm_dbus_nm_get_devices (DBusConnection *connection, DBusMess
|
||||
if (!appended)
|
||||
g_assert ("Device list existed, but no devices were in it.");
|
||||
|
||||
dbus_message_iter_close_container (&iter, &iter_array);
|
||||
nm_unlock_mutex (data->data->dev_list_mutex, __FUNCTION__);
|
||||
}
|
||||
else
|
||||
{
|
||||
dbus_message_unref (reply);
|
||||
reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "Retry",
|
||||
"NetworkManager could not lock device list, try again.");
|
||||
}
|
||||
@@ -209,9 +218,6 @@ static DBusMessage *nm_dbus_nm_set_active_device (DBusConnection *connection, DB
|
||||
nm_device_schedule_force_use (dev, network, key, key_type);
|
||||
|
||||
out:
|
||||
dbus_free (dev_path);
|
||||
dbus_free (network);
|
||||
dbus_free (key);
|
||||
return (reply);
|
||||
}
|
||||
|
||||
@@ -290,8 +296,6 @@ static DBusMessage *nm_dbus_nm_create_wireless_network (DBusConnection *connecti
|
||||
nm_policy_schedule_device_switch (dev, data->data);
|
||||
|
||||
out:
|
||||
dbus_free (network);
|
||||
dbus_free (key);
|
||||
nm_device_unref (dev);
|
||||
return (reply);
|
||||
}
|
||||
@@ -319,7 +323,7 @@ static DBusMessage *nm_dbus_nm_create_test_device (DBusConnection *connection, D
|
||||
if ((reply = dbus_message_new_method_return (message)))
|
||||
{
|
||||
char *dev_path = g_strdup_printf ("%s/%s", NM_DBUS_PATH_DEVICES, nm_device_get_iface (dev));
|
||||
dbus_message_append_args (reply, DBUS_TYPE_STRING, dev_path, DBUS_TYPE_INVALID);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_STRING, &dev_path, DBUS_TYPE_INVALID);
|
||||
g_free (dev_path);
|
||||
}
|
||||
g_free (interface);
|
||||
@@ -404,9 +408,6 @@ static DBusMessage * nm_dbus_nm_set_user_key_for_network (DBusConnection *connec
|
||||
if ((dev = nm_get_device_by_iface (data->data, device)))
|
||||
nm_device_set_user_key_for_network (dev, data->data->invalid_ap_list, network, passphrase, key_type);
|
||||
|
||||
dbus_free (device);
|
||||
dbus_free (network);
|
||||
dbus_free (passphrase);
|
||||
}
|
||||
|
||||
return (NULL);
|
||||
@@ -434,7 +435,7 @@ static DBusMessage *nm_dbus_nm_get_scanning_enabled (DBusConnection *connection,
|
||||
g_return_val_if_fail (data && data->data && connection && message, NULL);
|
||||
|
||||
if ((reply = dbus_message_new_method_return (message)))
|
||||
dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, data->data->scanning_enabled, DBUS_TYPE_INVALID);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &data->data->scanning_enabled, DBUS_TYPE_INVALID);
|
||||
|
||||
return reply;
|
||||
}
|
||||
@@ -463,7 +464,7 @@ static DBusMessage *nm_dbus_nm_get_wireless_enabled (DBusConnection *connection,
|
||||
g_return_val_if_fail (data && data->data && connection && message, NULL);
|
||||
|
||||
if ((reply = dbus_message_new_method_return (message)))
|
||||
dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, data->data->wireless_enabled, DBUS_TYPE_INVALID);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &data->data->wireless_enabled, DBUS_TYPE_INVALID);
|
||||
|
||||
return reply;
|
||||
}
|
||||
@@ -477,7 +478,7 @@ static DBusMessage *nm_dbus_nm_get_status (DBusConnection *connection, DBusMessa
|
||||
|
||||
status = nm_dbus_network_status_from_data (data->data);
|
||||
if (status && (reply = dbus_message_new_method_return (message)))
|
||||
dbus_message_append_args (reply, DBUS_TYPE_STRING, status, DBUS_TYPE_INVALID);
|
||||
dbus_message_append_args (reply, DBUS_TYPE_STRING, &status, DBUS_TYPE_INVALID);
|
||||
g_free (status);
|
||||
|
||||
return reply;
|
||||
@@ -510,4 +511,107 @@ NMDbusMethodList *nm_dbus_nm_methods_setup (void)
|
||||
return (list);
|
||||
}
|
||||
|
||||
static gchar *nm_dbus_escape_object_path (const gchar *utf8_string)
|
||||
{
|
||||
const gchar *p;
|
||||
gchar *object_path;
|
||||
GString *string;
|
||||
|
||||
g_return_val_if_fail (utf8_string != NULL, NULL);
|
||||
g_return_val_if_fail (g_utf8_validate (utf8_string, -1, NULL), NULL);
|
||||
|
||||
string = g_string_sized_new ((strlen (utf8_string) + 1) * 6);
|
||||
|
||||
for (p = utf8_string; *p != '\0'; p = g_utf8_next_char (p))
|
||||
{
|
||||
gunichar character;
|
||||
|
||||
character = g_utf8_get_char (p);
|
||||
|
||||
if (((character >= ((gunichar) 'a')) &&
|
||||
(character <= ((gunichar) 'z'))) ||
|
||||
((character >= ((gunichar) 'A')) &&
|
||||
(character <= ((gunichar) 'Z'))) ||
|
||||
((character >= ((gunichar) '0')) &&
|
||||
(character <= ((gunichar) '9'))) ||
|
||||
(character == ((gunichar) '/')))
|
||||
{
|
||||
g_string_append_c (string, (gchar) character);
|
||||
continue;
|
||||
}
|
||||
|
||||
g_string_append_printf (string, "_%x_", character);
|
||||
}
|
||||
|
||||
object_path = string->str;
|
||||
|
||||
g_string_free (string, FALSE);
|
||||
|
||||
return object_path;
|
||||
}
|
||||
|
||||
static gchar *nm_dbus_unescape_object_path (const gchar *object_path)
|
||||
{
|
||||
const gchar *p;
|
||||
gchar *utf8_string;
|
||||
GString *string;
|
||||
|
||||
g_return_val_if_fail (object_path != NULL, NULL);
|
||||
|
||||
string = g_string_sized_new (strlen (object_path) + 1);
|
||||
|
||||
for (p = object_path; *p != '\0'; p++)
|
||||
{
|
||||
const gchar *q;
|
||||
gchar *hex_digits, *end, utf8_character[6] = { '\0' };
|
||||
gint utf8_character_size;
|
||||
gunichar character;
|
||||
gulong hex_value;
|
||||
|
||||
if (*p != '_')
|
||||
{
|
||||
g_string_append_c (string, *p);
|
||||
continue;
|
||||
}
|
||||
|
||||
q = strchr (p + 1, '_');
|
||||
|
||||
if ((q == NULL) || (q == p + 1))
|
||||
{
|
||||
g_string_free (string, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hex_digits = g_strndup (p + 1, (q - 1) - p);
|
||||
|
||||
hex_value = strtoul (hex_digits, &end, 16);
|
||||
|
||||
character = (gunichar) hex_value;
|
||||
|
||||
if (((hex_value == G_MAXLONG) && (errno == ERANGE)) ||
|
||||
(hex_value > G_MAXUINT32) ||
|
||||
(*end != '\0') ||
|
||||
(!g_unichar_validate (character)))
|
||||
{
|
||||
g_free (hex_digits);
|
||||
g_string_free (string, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
utf8_character_size =
|
||||
g_unichar_to_utf8 (character, utf8_character);
|
||||
|
||||
g_assert (utf8_character_size > 0);
|
||||
|
||||
g_string_append_len (string, utf8_character,
|
||||
utf8_character_size);
|
||||
|
||||
p = q;
|
||||
}
|
||||
|
||||
utf8_string = string->str;
|
||||
|
||||
g_string_free (string, FALSE);
|
||||
|
||||
return utf8_string;
|
||||
}
|
||||
|
@@ -301,10 +301,10 @@ int main( int argc, char *argv[] )
|
||||
|
||||
dbus_connection_setup_with_g_main (connection, NULL);
|
||||
dbus_error_init (&error);
|
||||
dbus_bus_acquire_service (connection, NM_DBUS_SERVICE, 0, &error);
|
||||
dbus_bus_request_name (connection, NM_DBUS_SERVICE, 0, &error);
|
||||
if (dbus_error_is_set (&error))
|
||||
{
|
||||
fprintf (stderr, "Could not acquire its service. dbus_bus_acquire_service() says: '%s'\n", error.message);
|
||||
fprintf (stderr, "Could not acquire its service. dbus_bus_request_name() says: '%s'\n", error.message);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user