2005-12-17 Dan Williams <dcbw@redhat.com>

* gnome/applet/*
		- More applet cleanups
		- Use the dbus-method-dispatcher

	* libnm-util/dbus-method-dispatcher.[ch]
		- Generalize the implementation from NM in
			NetworkManagerUtils.c


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1210 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Dan Williams
2005-12-17 21:10:37 +00:00
parent df7ce03bd4
commit a601e80848
14 changed files with 517 additions and 303 deletions

View File

@@ -1,3 +1,13 @@
2005-12-17 Dan Williams <dcbw@redhat.com>
* gnome/applet/*
- More applet cleanups
- Use the dbus-method-dispatcher
* libnm-util/dbus-method-dispatcher.[ch]
- Generalize the implementation from NM in
NetworkManagerUtils.c
2005-12-16 Dan Williams <dcbw@redhat.com> 2005-12-16 Dan Williams <dcbw@redhat.com>
* gnome/applet/* * gnome/applet/*

View File

@@ -39,6 +39,23 @@
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-gconf-wso.h" #include "nm-gconf-wso.h"
#include "gconf-helpers.h" #include "gconf-helpers.h"
#include "dbus-method-dispatcher.h"
#include "dbus-helpers.h"
static DBusMessage * new_invalid_args_error (DBusMessage *message, const char *func)
{
char * msg;
DBusMessage * reply;
g_return_val_if_fail (message != NULL, NULL);
g_return_val_if_fail (func != NULL, NULL);
return nmu_create_dbus_error_message (message,
"InvalidArguments",
"NetworkManager::%s called with invalid arguments.",
func);
}
/* /*
@@ -123,15 +140,13 @@ static void nmi_dbus_get_network_key_callback (GnomeKeyringResult result,
GnomeKeyringFound * found; GnomeKeyringFound * found;
NMGConfWSO * gconf_wso; NMGConfWSO * gconf_wso;
found = found_list->data;
key = g_strdup (found->secret);
escaped_network = gconf_escape_key (essid, strlen (essid)); escaped_network = gconf_escape_key (essid, strlen (essid));
gconf_wso = nm_gconf_wso_new_deserialize_gconf (applet->gconf_client, escaped_network); gconf_wso = nm_gconf_wso_new_deserialize_gconf (applet->gconf_client, escaped_network);
g_free (escaped_network); g_free (escaped_network);
found = found_list->data;
nm_gconf_wso_set_key (gconf_wso, found->secret, strlen (found->secret));
nmi_dbus_return_user_key (applet->connection, message, gconf_wso); nmi_dbus_return_user_key (applet->connection, message, gconf_wso);
g_free (key);
} }
else else
{ {
@@ -150,28 +165,34 @@ static void nmi_dbus_get_network_key_callback (GnomeKeyringResult result,
* Throw up the user key dialog * Throw up the user key dialog
* *
*/ */
static DBusMessage * nmi_dbus_get_key_for_network (NMWirelessApplet *applet, DBusMessage *message) static DBusMessage *
nmi_dbus_get_key_for_network (DBusConnection *connection,
DBusMessage *message,
void *user_data)
{ {
NMWirelessApplet * applet = (NMWirelessApplet *) user_data;
char * dev_path = NULL; char * dev_path = NULL;
char * net_path = NULL; char * net_path = NULL;
char * essid = NULL; char * essid = NULL;
int attempt = 0; int attempt = 0;
gboolean new_key = FALSE; gboolean new_key = FALSE;
gboolean success = FALSE; NetworkDevice * dev = NULL;
WirelessNetwork * net = NULL;
if (dbus_message_get_args (message, NULL, g_return_val_if_fail (applet != NULL, NULL);
g_return_val_if_fail (message != NULL, NULL);
if (!dbus_message_get_args (message, NULL,
DBUS_TYPE_OBJECT_PATH, &dev_path, DBUS_TYPE_OBJECT_PATH, &dev_path,
DBUS_TYPE_OBJECT_PATH, &net_path, DBUS_TYPE_OBJECT_PATH, &net_path,
DBUS_TYPE_STRING, &essid, DBUS_TYPE_STRING, &essid,
DBUS_TYPE_INT32, &attempt, DBUS_TYPE_INT32, &attempt,
DBUS_TYPE_BOOLEAN, &new_key, DBUS_TYPE_BOOLEAN, &new_key,
DBUS_TYPE_INVALID)) DBUS_TYPE_INVALID))
{ return NULL;
NetworkDevice *dev = NULL;
if ((dev = nmwa_get_device_for_nm_path (applet->device_list, dev_path))) if (!(dev = nmwa_get_device_for_nm_path (applet->device_list, dev_path)))
{ return NULL;
WirelessNetwork *net = NULL;
/* It's not a new key, so try to get the key from the keyring. */ /* It's not a new key, so try to get the key from the keyring. */
if (!new_key) if (!new_key)
@@ -214,19 +235,14 @@ static DBusMessage * nmi_dbus_get_key_for_network (NMWirelessApplet *applet, DBu
*/ */
if (new_key && (net = network_device_get_wireless_network_by_nm_path (dev, net_path))) if (new_key && (net = network_device_get_wireless_network_by_nm_path (dev, net_path)))
{ {
success = nmi_passphrase_dialog_schedule_show (dev, net, message, applet); gboolean success;
if (!success) if (!(success = nmi_passphrase_dialog_schedule_show (dev, net, message, applet)))
{ {
DBusMessage *error_message; return nmi_dbus_create_error_message (message,
char *error_message_str; NMI_DBUS_INTERFACE,
"GetKeyError",
error_message_str = g_strdup_printf ("Could not get user key for network '%s'.", essid); "Could not get user key for network '%s'.",
error_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "GetKeyError", error_message_str); essid);
g_free (error_message_str);
return error_message;
}
}
} }
} }
} }
@@ -250,14 +266,10 @@ nmi_dbus_return_user_key (DBusConnection *connection,
DBusMessageIter iter; DBusMessageIter iter;
g_return_if_fail (connection != NULL); g_return_if_fail (connection != NULL);
g_return_if_fail (message != NULL);
g_return_if_fail (gconf_wso != NULL); g_return_if_fail (gconf_wso != NULL);
if (!(reply = dbus_message_new_method_return (message))) reply = dbus_message_new_method_return (message);
{
nm_warning ("nmi_dbus_return_user_key(): Couldn't allocate the dbus message");
return;
}
dbus_message_iter_init_append (reply, &iter); dbus_message_iter_init_append (reply, &iter);
if (nm_gconf_wso_serialize_dbus (gconf_wso, &iter)) if (nm_gconf_wso_serialize_dbus (gconf_wso, &iter))
dbus_connection_send (connection, reply, NULL); dbus_connection_send (connection, reply, NULL);
@@ -284,12 +296,7 @@ void nmi_dbus_signal_update_network (DBusConnection *connection, const char *net
if (type != NETWORK_TYPE_ALLOWED) if (type != NETWORK_TYPE_ALLOWED)
return; return;
if (!(message = dbus_message_new_signal (NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "WirelessNetworkUpdate"))) message = dbus_message_new_signal (NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "WirelessNetworkUpdate");
{
nm_warning ("nmi_dbus_signal_update_network(): Not enough memory for new dbus message!");
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)) if (!dbus_connection_send (connection, message, NULL))
nm_warning ("nmi_dbus_signal_update_network(): Could not raise the 'WirelessNetworkUpdate' signal!"); nm_warning ("nmi_dbus_signal_update_network(): Could not raise the 'WirelessNetworkUpdate' signal!");
@@ -305,8 +312,14 @@ void nmi_dbus_signal_update_network (DBusConnection *connection, const char *net
* of a string array in a dbus message. * of a string array in a dbus message.
* *
*/ */
static DBusMessage *nmi_dbus_get_networks (NMWirelessApplet *applet, DBusMessage *message) static DBusMessage *
nmi_dbus_get_networks (DBusConnection *connection,
DBusMessage *message,
void *user_data)
{ {
const char * NO_NET_ERROR = "NoNetworks";
const char * NO_NET_ERROR_MSG = "There are no wireless networks stored.";
NMWirelessApplet * applet = (NMWirelessApplet *) user_data;
GSList * dir_list = NULL; GSList * dir_list = NULL;
GSList * elt; GSList * elt;
DBusMessage * reply = NULL; DBusMessage * reply = NULL;
@@ -320,19 +333,11 @@ static DBusMessage *nmi_dbus_get_networks (NMWirelessApplet *applet, DBusMessage
if ( !dbus_message_get_args (message, NULL, DBUS_TYPE_INT32, &type, DBUS_TYPE_INVALID) if ( !dbus_message_get_args (message, NULL, DBUS_TYPE_INT32, &type, DBUS_TYPE_INVALID)
|| !nmi_network_type_valid (type)) || !nmi_network_type_valid (type))
{ return new_invalid_args_error (message, __func__);
reply = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments",
"NetworkManagerInfo::getNetworks called with invalid arguments.");
goto out;
}
/* List all allowed access points that gconf knows about */ /* List all allowed access points that gconf knows about */
if (!(dir_list = gconf_client_all_dirs (applet->gconf_client, GCONF_PATH_WIRELESS_NETWORKS, NULL))) if (!(dir_list = gconf_client_all_dirs (applet->gconf_client, GCONF_PATH_WIRELESS_NETWORKS, NULL)))
{ return nmu_create_dbus_error_message (message, NO_NET_ERROR, NO_NET_ERROR_MSG);
reply = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "NoNetworks",
"There are no wireless networks stored.");
goto out;
}
reply = dbus_message_new_method_return (message); reply = dbus_message_new_method_return (message);
dbus_message_iter_init_append (reply, &iter); dbus_message_iter_init_append (reply, &iter);
@@ -367,8 +372,7 @@ static DBusMessage *nmi_dbus_get_networks (NMWirelessApplet *applet, DBusMessage
if (!value_added) if (!value_added)
{ {
dbus_message_unref (reply); dbus_message_unref (reply);
reply = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "NoNetworks", reply = nmu_create_dbus_error_message (message, NO_NET_ERROR, NO_NET_ERROR_MSG);
"There are no wireless networks stored.");
} }
out: out:
@@ -388,8 +392,12 @@ static void addr_list_append_helper (GConfValue *value, DBusMessageIter *iter)
* Returns the properties of a specific wireless network from gconf * Returns the properties of a specific wireless network from gconf
* *
*/ */
static DBusMessage *nmi_dbus_get_network_properties (NMWirelessApplet *applet, DBusMessage *message) static DBusMessage *
nmi_dbus_get_network_properties (DBusConnection *connection,
DBusMessage *message,
void *user_data)
{ {
NMWirelessApplet * applet = (NMWirelessApplet *) user_data;
DBusMessage * reply = NULL; DBusMessage * reply = NULL;
gchar * gconf_key = NULL; gchar * gconf_key = NULL;
char * network = NULL; char * network = NULL;
@@ -408,12 +416,11 @@ static DBusMessage *nmi_dbus_get_network_properties (NMWirelessApplet *applet, D
client = applet->gconf_client; client = applet->gconf_client;
if ( !dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &network, DBUS_TYPE_INT32, &type, DBUS_TYPE_INVALID) if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &network, DBUS_TYPE_INT32, &type, DBUS_TYPE_INVALID))
|| !nmi_network_type_valid (type) goto out;
|| (strlen (network) <= 0))
{ if (!nmi_network_type_valid (type) || (strlen (network) <= 0))
goto out; goto out;
}
if (!(escaped_network = gconf_escape_key (network, strlen (network)))) if (!(escaped_network = gconf_escape_key (network, strlen (network))))
goto out; goto out;
@@ -471,10 +478,7 @@ out:
g_free (escaped_network); g_free (escaped_network);
if (!reply) if (!reply)
{ reply = new_invalid_args_error (message, __func__);
reply = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments",
"NetworkManagerInfo::getNetworkProperties called with invalid arguments.");
}
return reply; return reply;
} }
@@ -494,12 +498,7 @@ void nmi_dbus_signal_update_vpn_connection (DBusConnection *connection, const ch
g_return_if_fail (connection != NULL); g_return_if_fail (connection != NULL);
g_return_if_fail (name != NULL); g_return_if_fail (name != NULL);
if (!(message = dbus_message_new_signal (NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "VPNConnectionUpdate"))) message = dbus_message_new_signal (NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "VPNConnectionUpdate");
{
nm_warning ("nmi_dbus_signal_update_vpn_connection(): Not enough memory for new dbus message!");
return;
}
dbus_message_append_args (message, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID); dbus_message_append_args (message, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID);
if (!dbus_connection_send (connection, message, NULL)) if (!dbus_connection_send (connection, message, NULL))
nm_warning ("nmi_dbus_signal_update_vpn_connection(): Could not raise the 'VPNConnectionUpdate' signal!"); nm_warning ("nmi_dbus_signal_update_vpn_connection(): Could not raise the 'VPNConnectionUpdate' signal!");
@@ -515,8 +514,12 @@ void nmi_dbus_signal_update_vpn_connection (DBusConnection *connection, const ch
* of a string array in a dbus message. * of a string array in a dbus message.
* *
*/ */
static DBusMessage *nmi_dbus_get_vpn_connections (NMWirelessApplet *applet, DBusMessage *message) static DBusMessage *
nmi_dbus_get_vpn_connections (DBusConnection *connection,
DBusMessage *message,
void *user_data)
{ {
NMWirelessApplet * applet = (NMWirelessApplet *) user_data;
GSList * dir_list = NULL; GSList * dir_list = NULL;
GSList * elt = NULL; GSList * elt = NULL;
DBusMessage * reply = NULL; DBusMessage * reply = NULL;
@@ -530,7 +533,7 @@ static DBusMessage *nmi_dbus_get_vpn_connections (NMWirelessApplet *applet, DBus
/* List all VPN connections that gconf knows about */ /* List all VPN connections that gconf knows about */
if (!(dir_list = gconf_client_all_dirs (applet->gconf_client, GCONF_PATH_VPN_CONNECTIONS, NULL))) if (!(dir_list = gconf_client_all_dirs (applet->gconf_client, GCONF_PATH_VPN_CONNECTIONS, NULL)))
{ {
reply = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "NoVPNConnections", reply = nmu_create_dbus_error_message (message, "NoVPNConnections",
"There are no VPN connections stored."); "There are no VPN connections stored.");
goto out; goto out;
} }
@@ -567,7 +570,7 @@ static DBusMessage *nmi_dbus_get_vpn_connections (NMWirelessApplet *applet, DBus
if (!value_added) if (!value_added)
{ {
dbus_message_unref (reply); dbus_message_unref (reply);
reply = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "NoVPNConnections", reply = nmu_create_dbus_error_message (message, "NoVPNConnections",
"There are no VPN connections stored."); "There are no VPN connections stored.");
} }
@@ -582,8 +585,12 @@ out:
* Returns the properties of a specific VPN connection from gconf * Returns the properties of a specific VPN connection from gconf
* *
*/ */
static DBusMessage *nmi_dbus_get_vpn_connection_properties (NMWirelessApplet *applet, DBusMessage *message) static DBusMessage *
nmi_dbus_get_vpn_connection_properties (DBusConnection *connection,
DBusMessage *message,
void *user_data)
{ {
NMWirelessApplet * applet = (NMWirelessApplet *) user_data;
DBusMessage * reply = NULL; DBusMessage * reply = NULL;
gchar * gconf_key = NULL; gchar * gconf_key = NULL;
char * vpn_connection = NULL; char * vpn_connection = NULL;
@@ -603,9 +610,7 @@ static DBusMessage *nmi_dbus_get_vpn_connection_properties (NMWirelessApplet *ap
if ( !dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &vpn_connection, DBUS_TYPE_INVALID) if ( !dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &vpn_connection, DBUS_TYPE_INVALID)
|| (strlen (vpn_connection) <= 0)) || (strlen (vpn_connection) <= 0))
{ {
reply = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments", return new_invalid_args_error (message, __func__);
"NetworkManagerInfo::getVPNConnectionProperties called with invalid arguments.");
goto out;
} }
escaped_name = gconf_escape_key (vpn_connection, strlen (vpn_connection)); escaped_name = gconf_escape_key (vpn_connection, strlen (vpn_connection));
@@ -642,29 +647,26 @@ out:
* Returns vpn-daemon specific properties for a particular VPN connection. * Returns vpn-daemon specific properties for a particular VPN connection.
* *
*/ */
static DBusMessage *nmi_dbus_get_vpn_connection_vpn_data (NMWirelessApplet *applet, DBusMessage *message) static DBusMessage *
nmi_dbus_get_vpn_connection_vpn_data (DBusConnection *connection,
DBusMessage *message,
void *user_data)
{ {
DBusMessage *reply = NULL; NMWirelessApplet * applet = (NMWirelessApplet *) user_data;
gchar *gconf_key = NULL; DBusMessage * reply = NULL;
char *name = NULL; gchar * gconf_key = NULL;
GConfValue *vpn_data_value = NULL; char * name = NULL;
GConfValue *value = NULL; GConfValue * vpn_data_value = NULL;
DBusError error; GConfValue * value = NULL;
char *escaped_name; char * escaped_name;
DBusMessageIter iter, array_iter; DBusMessageIter iter, array_iter;
GSList *elt; GSList * elt;
g_return_val_if_fail (applet != NULL, NULL); g_return_val_if_fail (applet != NULL, NULL);
g_return_val_if_fail (message != NULL, NULL); g_return_val_if_fail (message != NULL, NULL);
dbus_error_init (&error); if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID) || (strlen (name) <= 0))
if ( !dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID) return new_invalid_args_error (message, __func__);
|| (strlen (name) <= 0))
{
reply = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments",
"NetworkManagerInfo::getVPNConnectionVPNData called with invalid arguments.");
return reply;
}
escaped_name = gconf_escape_key (name, strlen (name)); escaped_name = gconf_escape_key (name, strlen (name));
@@ -672,7 +674,7 @@ static DBusMessage *nmi_dbus_get_vpn_connection_vpn_data (NMWirelessApplet *appl
gconf_key = g_strdup_printf ("%s/%s/name", GCONF_PATH_VPN_CONNECTIONS, escaped_name); gconf_key = g_strdup_printf ("%s/%s/name", GCONF_PATH_VPN_CONNECTIONS, escaped_name);
if (!(value = gconf_client_get (applet->gconf_client, gconf_key, NULL))) if (!(value = gconf_client_get (applet->gconf_client, gconf_key, NULL)))
{ {
reply = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadVPNConnectionData", reply = nmu_create_dbus_error_message (message, "BadVPNConnectionData",
"NetworkManagerInfo::getVPNConnectionVPNData could not access the name for connection '%s'", name); "NetworkManagerInfo::getVPNConnectionVPNData could not access the name for connection '%s'", name);
return reply; return reply;
} }
@@ -685,7 +687,7 @@ static DBusMessage *nmi_dbus_get_vpn_connection_vpn_data (NMWirelessApplet *appl
|| !(vpn_data_value->type == GCONF_VALUE_LIST) || !(vpn_data_value->type == GCONF_VALUE_LIST)
|| !(gconf_value_get_list_type (vpn_data_value) == GCONF_VALUE_STRING)) || !(gconf_value_get_list_type (vpn_data_value) == GCONF_VALUE_STRING))
{ {
reply = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadVPNConnectionData", reply = nmu_create_dbus_error_message (message, "BadVPNConnectionData",
"NetworkManagerInfo::getVPNConnectionVPNData could not access the VPN data for connection '%s'", name); "NetworkManagerInfo::getVPNConnectionVPNData could not access the VPN data for connection '%s'", name);
if (vpn_data_value) if (vpn_data_value)
gconf_value_free (vpn_data_value); gconf_value_free (vpn_data_value);
@@ -709,7 +711,7 @@ static DBusMessage *nmi_dbus_get_vpn_connection_vpn_data (NMWirelessApplet *appl
gconf_value_free (vpn_data_value); gconf_value_free (vpn_data_value);
g_free (escaped_name); g_free (escaped_name);
return (reply); return reply;
} }
/* /*
@@ -718,29 +720,26 @@ static DBusMessage *nmi_dbus_get_vpn_connection_vpn_data (NMWirelessApplet *appl
* Returns routes for a particular VPN connection. * Returns routes for a particular VPN connection.
* *
*/ */
static DBusMessage *nmi_dbus_get_vpn_connection_routes (NMWirelessApplet *applet, DBusMessage *message) static DBusMessage *
nmi_dbus_get_vpn_connection_routes (DBusConnection *connection,
DBusMessage *message,
void *user_data)
{ {
DBusMessage *reply = NULL; NMWirelessApplet * applet = (NMWirelessApplet *) user_data;
gchar *gconf_key = NULL; DBusMessage * reply = NULL;
char *name = NULL; gchar * gconf_key = NULL;
GConfValue *routes_value = NULL; char * name = NULL;
GConfValue *value = NULL; GConfValue * routes_value = NULL;
DBusError error; GConfValue * value = NULL;
char *escaped_name; char * escaped_name;
DBusMessageIter iter, array_iter; DBusMessageIter iter, array_iter;
GSList *elt; GSList * elt;
g_return_val_if_fail (applet != NULL, NULL); g_return_val_if_fail (applet != NULL, NULL);
g_return_val_if_fail (message != NULL, NULL); g_return_val_if_fail (message != NULL, NULL);
dbus_error_init (&error); if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID) || (strlen (name) <= 0))
if ( !dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID) return new_invalid_args_error (message, __func__);
|| (strlen (name) <= 0))
{
reply = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments",
"NetworkManagerInfo::getVPNConnectionRoutes called with invalid arguments.");
return reply;
}
escaped_name = gconf_escape_key (name, strlen (name)); escaped_name = gconf_escape_key (name, strlen (name));
@@ -748,7 +747,7 @@ static DBusMessage *nmi_dbus_get_vpn_connection_routes (NMWirelessApplet *applet
gconf_key = g_strdup_printf ("%s/%s/name", GCONF_PATH_VPN_CONNECTIONS, escaped_name); gconf_key = g_strdup_printf ("%s/%s/name", GCONF_PATH_VPN_CONNECTIONS, escaped_name);
if (!(value = gconf_client_get (applet->gconf_client, gconf_key, NULL))) if (!(value = gconf_client_get (applet->gconf_client, gconf_key, NULL)))
{ {
reply = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadVPNConnectionData", reply = nmu_create_dbus_error_message (message, "BadVPNConnectionData",
"NetworkManagerInfo::getVPNConnectionRoutes could not access the name for connection '%s'", name); "NetworkManagerInfo::getVPNConnectionRoutes could not access the name for connection '%s'", name);
return reply; return reply;
} }
@@ -761,7 +760,7 @@ static DBusMessage *nmi_dbus_get_vpn_connection_routes (NMWirelessApplet *applet
|| !(routes_value->type == GCONF_VALUE_LIST) || !(routes_value->type == GCONF_VALUE_LIST)
|| !(gconf_value_get_list_type (routes_value) == GCONF_VALUE_STRING)) || !(gconf_value_get_list_type (routes_value) == GCONF_VALUE_STRING))
{ {
reply = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadVPNConnectionData", reply = nmu_create_dbus_error_message (message, "BadVPNConnectionData",
"NetworkManagerInfo::getVPNConnectionRoutes could not access the routes for connection '%s'", name); "NetworkManagerInfo::getVPNConnectionRoutes could not access the routes for connection '%s'", name);
if (routes_value) if (routes_value)
gconf_value_free (routes_value); gconf_value_free (routes_value);
@@ -785,7 +784,7 @@ static DBusMessage *nmi_dbus_get_vpn_connection_routes (NMWirelessApplet *applet
gconf_value_free (routes_value); gconf_value_free (routes_value);
g_free (escaped_name); g_free (escaped_name);
return (reply); return reply;
} }
@@ -880,32 +879,35 @@ static void nmi_save_network_info (NMWirelessApplet *applet, const char *essid,
* Update a network's authentication method and encryption key in gconf & the keyring * Update a network's authentication method and encryption key in gconf & the keyring
* *
*/ */
static void nmi_dbus_update_network_info (NMWirelessApplet *applet, DBusMessage *message) static DBusMessage *
nmi_dbus_update_network_info (DBusConnection *connection,
DBusMessage *message,
void *user_data)
{ {
NMWirelessApplet * applet = (NMWirelessApplet *) user_data;
char * network = NULL; char * network = NULL;
int auth_method = -1; int auth_method = -1;
char * enc_key_source = NULL; char * enc_key_source = NULL;
int enc_key_type = -1; int enc_key_type = -1;
gboolean user_requested; gboolean user_requested;
DBusError error;
dbus_bool_t args_good; dbus_bool_t args_good;
g_return_if_fail (applet != NULL); g_return_val_if_fail (applet != NULL, NULL);
g_return_if_fail (message != NULL); g_return_val_if_fail (message != NULL, NULL);
dbus_error_init (&error); args_good = dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &network,
args_good = dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &network,
DBUS_TYPE_STRING, &enc_key_source, DBUS_TYPE_STRING, &enc_key_source,
DBUS_TYPE_INT32, &enc_key_type, DBUS_TYPE_INT32, &enc_key_type,
DBUS_TYPE_INT32, &auth_method, DBUS_TYPE_INT32, &auth_method,
DBUS_TYPE_BOOLEAN, &user_requested, DBUS_TYPE_BOOLEAN, &user_requested,
DBUS_TYPE_INVALID); DBUS_TYPE_INVALID);
if (!args_good || (strlen (network) <= 0) || (auth_method == -1)) if (!args_good || (strlen (network) <= 0) || (auth_method == -1))
return; return NULL;
if (enc_key_source && strlen (enc_key_source) && ((enc_key_type == NM_ENC_TYPE_UNKNOWN) || (enc_key_type == NM_ENC_TYPE_NONE))) if (enc_key_source && strlen (enc_key_source) && ((enc_key_type == NM_ENC_TYPE_UNKNOWN) || (enc_key_type == NM_ENC_TYPE_NONE)))
return; return NULL;
nmi_save_network_info (applet, network, enc_key_source, (NMEncKeyType) enc_key_type, auth_method, user_requested); nmi_save_network_info (applet, network, enc_key_source, (NMEncKeyType) enc_key_type, auth_method, user_requested);
return NULL;
} }
@@ -915,33 +917,34 @@ static void nmi_dbus_update_network_info (NMWirelessApplet *applet, DBusMessage
* Add an AP's MAC address to a wireless network entry in gconf * Add an AP's MAC address to a wireless network entry in gconf
* *
*/ */
static DBusMessage *nmi_dbus_add_network_address (NMWirelessApplet *applet, DBusMessage *message) static DBusMessage *
nmi_dbus_add_network_address (DBusConnection *connection,
DBusMessage *message,
void *user_data)
{ {
DBusMessage *reply_message = NULL; NMWirelessApplet * applet = (NMWirelessApplet *) user_data;
char *network = NULL; DBusMessage * reply_message = NULL;
char * network = NULL;
NMNetworkType type; NMNetworkType type;
char *addr; char * addr;
char *key; char * key;
GConfValue *value; GConfValue * value;
DBusError error; char * escaped_network;
char *escaped_network; GSList * new_mac_list = NULL;
GSList *new_mac_list = NULL;
gboolean found = FALSE; gboolean found = FALSE;
g_return_val_if_fail (applet != NULL, NULL); g_return_val_if_fail (applet != NULL, NULL);
g_return_val_if_fail (message != NULL, NULL); g_return_val_if_fail (message != NULL, NULL);
dbus_error_init (&error); if (!dbus_message_get_args (message, NULL,
if ( !dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &network, DBUS_TYPE_INT32, &type, DBUS_TYPE_STRING, &addr, DBUS_TYPE_INVALID) DBUS_TYPE_STRING, &network,
|| !nmi_network_type_valid (type) DBUS_TYPE_INT32, &type,
|| (strlen (network) <= 0) DBUS_TYPE_STRING, &addr,
|| !addr DBUS_TYPE_INVALID))
|| (strlen (addr) < 11)) return new_invalid_args_error (message, __func__);
{
reply_message = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments", if (!nmi_network_type_valid (type) || (strlen (network) <= 0) || !addr || (strlen (addr) < 11))
"NetworkManagerInfo::addNetworkAddress called with invalid arguments."); return new_invalid_args_error (message, __func__);
return (reply_message);
}
/* Force-set the essid too so that we have a semi-complete network entry */ /* Force-set the essid too so that we have a semi-complete network entry */
escaped_network = gconf_escape_key (network, strlen (network)); escaped_network = gconf_escape_key (network, strlen (network));
@@ -963,28 +966,28 @@ static DBusMessage *nmi_dbus_add_network_address (NMWirelessApplet *applet, DBus
/* Get current list of access point MAC addresses for this AP from GConf */ /* Get current list of access point MAC addresses for this AP from GConf */
key = g_strdup_printf ("%s/%s/addresses", GCONF_PATH_WIRELESS_NETWORKS, escaped_network); key = g_strdup_printf ("%s/%s/addresses", GCONF_PATH_WIRELESS_NETWORKS, escaped_network);
value = gconf_client_get (applet->gconf_client, key, NULL); if ((value = gconf_client_get (applet->gconf_client, key, NULL)))
g_free (escaped_network);
if (value && (value->type == GCONF_VALUE_LIST) && (gconf_value_get_list_type (value) == GCONF_VALUE_STRING))
{ {
GSList *elem; if ((value->type == GCONF_VALUE_LIST) && (gconf_value_get_list_type (value) == GCONF_VALUE_STRING))
{
GSList * elt;
new_mac_list = gconf_client_get_list (applet->gconf_client, key, GCONF_VALUE_STRING, NULL); new_mac_list = gconf_client_get_list (applet->gconf_client, key, GCONF_VALUE_STRING, NULL);
gconf_value_free (value);
/* Ensure that the MAC isn't already in the list */ /* Ensure that the MAC isn't already in the list */
elem = new_mac_list; for (elt = new_mac_list; elt; elt = g_slist_next (elt))
while (elem)
{ {
if (elem->data && !strcmp (addr, elem->data)) if (elt->data && !strcmp (addr, elt->data))
{ {
found = TRUE; found = TRUE;
break; break;
} }
elem = g_slist_next (elem);
} }
} }
gconf_value_free (value);
}
g_free (escaped_network);
g_free (key);
/* Add the new MAC address to the end of the list */ /* Add the new MAC address to the end of the list */
if (!found) if (!found)
@@ -997,9 +1000,7 @@ static DBusMessage *nmi_dbus_add_network_address (NMWirelessApplet *applet, DBus
g_slist_foreach (new_mac_list, (GFunc)g_free, NULL); g_slist_foreach (new_mac_list, (GFunc)g_free, NULL);
g_slist_free (new_mac_list); g_slist_free (new_mac_list);
g_free (key); return NULL;
return (NULL);
} }
@@ -1011,41 +1012,17 @@ static DBusMessage *nmi_dbus_add_network_address (NMWirelessApplet *applet, DBus
*/ */
DBusHandlerResult nmi_dbus_info_message_handler (DBusConnection *connection, DBusMessage *message, void *user_data) DBusHandlerResult nmi_dbus_info_message_handler (DBusConnection *connection, DBusMessage *message, void *user_data)
{ {
const char *method; NMWirelessApplet * applet = (NMWirelessApplet *)user_data;
const char *path; DBusMessage * reply = NULL;
NMWirelessApplet *applet = (NMWirelessApplet *)user_data; gboolean handled;
DBusMessage *reply = NULL;
gboolean handled = TRUE;
g_return_val_if_fail (applet != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); g_return_val_if_fail (applet != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
method = dbus_message_get_member (message); handled = dbus_method_dispatcher_dispatch (applet->nmi_methods,
path = dbus_message_get_path (message); connection,
message,
/* nm_warning ("nmi_dbus_nmi_message_handler() got method %s for path %s", method, path); */ &reply,
applet);
if (strcmp ("getKeyForNetwork", method) == 0)
reply = nmi_dbus_get_key_for_network (applet, message);
else if (strcmp ("cancelGetKeyForNetwork", method) == 0)
nmi_passphrase_dialog_cancel (applet);
else if (strcmp ("getNetworks", method) == 0)
reply = nmi_dbus_get_networks (applet, message);
else if (strcmp ("getNetworkProperties", method) == 0)
reply = nmi_dbus_get_network_properties (applet, message);
else if (strcmp ("updateNetworkInfo", method) == 0)
nmi_dbus_update_network_info (applet, message);
else if (strcmp ("addNetworkAddress", method) == 0)
nmi_dbus_add_network_address (applet, message);
else if (strcmp ("getVPNConnections", method) == 0)
reply = nmi_dbus_get_vpn_connections (applet, message);
else if (strcmp ("getVPNConnectionProperties", method) == 0)
reply = nmi_dbus_get_vpn_connection_properties (applet, message);
else if (strcmp ("getVPNConnectionVPNData", method) == 0)
reply = nmi_dbus_get_vpn_connection_vpn_data (applet, message);
else if (strcmp ("getVPNConnectionRoutes", method) == 0)
reply = nmi_dbus_get_vpn_connection_routes (applet, message);
else
handled = FALSE;
if (reply) if (reply)
{ {
@@ -1074,3 +1051,27 @@ void nmi_dbus_signal_user_interface_activated (DBusConnection *connection)
dbus_message_unref (message); dbus_message_unref (message);
} }
/*
* nmi_dbus_nmi_methods_setup
*
* Register handlers for dbus methods on the org.freedesktop.NetworkManagerInfo object.
*
*/
DBusMethodDispatcher *nmi_dbus_nmi_methods_setup (void)
{
DBusMethodDispatcher * dispatcher = dbus_method_dispatcher_new (NULL);
dbus_method_dispatcher_register_method (dispatcher, "getKeyForNetwork", nmi_dbus_get_key_for_network);
dbus_method_dispatcher_register_method (dispatcher, "cancelGetKeyForNetwork", nmi_passphrase_dialog_cancel);
dbus_method_dispatcher_register_method (dispatcher, "getNetworks", nmi_dbus_get_networks);
dbus_method_dispatcher_register_method (dispatcher, "getNetworkProperties", nmi_dbus_get_network_properties);
dbus_method_dispatcher_register_method (dispatcher, "updateNetworkInfo", nmi_dbus_update_network_info);
dbus_method_dispatcher_register_method (dispatcher, "addNetworkAddress", nmi_dbus_add_network_address);
dbus_method_dispatcher_register_method (dispatcher, "getVPNConnections", nmi_dbus_get_vpn_connections);
dbus_method_dispatcher_register_method (dispatcher, "getVPNConnectionProperties",nmi_dbus_get_vpn_connection_properties);
dbus_method_dispatcher_register_method (dispatcher, "getVPNConnectionVPNData", nmi_dbus_get_vpn_connection_vpn_data);
dbus_method_dispatcher_register_method (dispatcher, "getVPNConnectionRoutes", nmi_dbus_get_vpn_connection_routes);
return dispatcher;
}

View File

@@ -39,4 +39,6 @@ void nmi_dbus_signal_update_vpn_connection (DBusConnection *connection, const
void nmi_dbus_signal_user_interface_activated (DBusConnection *connection); void nmi_dbus_signal_user_interface_activated (DBusConnection *connection);
DBusMethodDispatcher * nmi_dbus_nmi_methods_setup (void);
#endif #endif

View File

@@ -42,32 +42,6 @@
#define DBUS_NO_SERVICE_ERROR "org.freedesktop.DBus.Error.ServiceDoesNotExist" #define DBUS_NO_SERVICE_ERROR "org.freedesktop.DBus.Error.ServiceDoesNotExist"
/*
* nmi_dbus_create_error_message
*
* Convenience function to make a DBus error message
*
*/
DBusMessage *nmwa_dbus_create_error_message (DBusMessage *message, const char *exception_namespace, const char *exception, const char *format, ...)
{
char * exception_text;
DBusMessage * reply_message;
va_list args;
char error_text[512];
va_start (args, format);
vsnprintf (error_text, 512, format, args);
va_end (args);
exception_text = g_strdup_printf ("%s.%s", exception_namespace, exception);
reply_message = dbus_message_new_error (message, exception_text, error_text);
g_free (exception_text);
return (reply_message);
}
/* /*
* deal_with_dbus_error * deal_with_dbus_error
* *
@@ -155,7 +129,7 @@ static DBusHandlerResult nmwa_dbus_filter (DBusConnection *connection, DBusMessa
{ {
applet->nm_running = FALSE; applet->nm_running = FALSE;
applet->nm_state = NM_STATE_DISCONNECTED; applet->nm_state = NM_STATE_DISCONNECTED;
nmi_passphrase_dialog_cancel (applet); nmi_passphrase_dialog_cancel (NULL, NULL, applet);
} }
} }
} }
@@ -469,6 +443,7 @@ void nmwa_dbus_init_helper (NMWirelessApplet *applet)
dbus_g_thread_init (); dbus_g_thread_init ();
applet->connection = nmwa_dbus_init (applet); applet->connection = nmwa_dbus_init (applet);
applet->nmi_methods = nmi_dbus_nmi_methods_setup ();
timeout_source = g_timeout_source_new (2000); timeout_source = g_timeout_source_new (2000);
g_source_set_callback (timeout_source, nmwa_dbus_connection_watcher, applet, NULL); g_source_set_callback (timeout_source, nmwa_dbus_connection_watcher, applet, NULL);

View File

@@ -42,8 +42,6 @@ static inline gboolean message_is_error (DBusMessage *msg)
return (dbus_message_get_type (msg) == DBUS_MESSAGE_TYPE_ERROR); return (dbus_message_get_type (msg) == DBUS_MESSAGE_TYPE_ERROR);
} }
DBusMessage * nmwa_dbus_create_error_message (DBusMessage *message, const char *exception_namespace, const char *exception, const char *format, ...);
void nmwa_dbus_init_helper (NMWirelessApplet *applet); void nmwa_dbus_init_helper (NMWirelessApplet *applet);
void nmwa_dbus_enable_scanning (NMWirelessApplet *applet, gboolean enabled); void nmwa_dbus_enable_scanning (NMWirelessApplet *applet, gboolean enabled);

View File

@@ -54,6 +54,7 @@
#include "vpn-password-dialog.h" #include "vpn-password-dialog.h"
#include "vpn-connection.h" #include "vpn-connection.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "dbus-method-dispatcher.h"
/* Compat for GTK 2.4 and lower... */ /* Compat for GTK 2.4 and lower... */
#if (GTK_MAJOR_VERSION <= 2 && GTK_MINOR_VERSION < 6) #if (GTK_MAJOR_VERSION <= 2 && GTK_MINOR_VERSION < 6)
@@ -2332,6 +2333,8 @@ static void nmwa_destroy (NMWirelessApplet *applet, gpointer user_data)
gconf_client_notify_remove (applet->gconf_client, applet->gconf_vpn_notify_id); gconf_client_notify_remove (applet->gconf_client, applet->gconf_vpn_notify_id);
g_object_unref (G_OBJECT (applet->gconf_client)); g_object_unref (G_OBJECT (applet->gconf_client));
dbus_method_dispatcher_unref (applet->nmi_methods);
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
} }

View File

@@ -31,6 +31,7 @@
#include "nm-device.h" #include "nm-device.h"
#include "wireless-network.h" #include "wireless-network.h"
#include "dbus-method-dispatcher.h"
/* /*
@@ -75,6 +76,7 @@ typedef struct
EggTrayIcon parent; EggTrayIcon parent;
DBusConnection * connection; DBusConnection * connection;
DBusMethodDispatcher * nmi_methods;
GConfClient * gconf_client; GConfClient * gconf_client;
guint gconf_prefs_notify_id; guint gconf_prefs_notify_id;
guint gconf_vpn_notify_id; guint gconf_vpn_notify_id;

View File

@@ -310,15 +310,20 @@ gboolean nmi_passphrase_dialog_schedule_show (NetworkDevice *dev, WirelessNetwor
* Cancel and hide any user key dialog that might be up * Cancel and hide any user key dialog that might be up
* *
*/ */
void nmi_passphrase_dialog_cancel (NMWirelessApplet *applet) DBusMessage *
nmi_passphrase_dialog_cancel (DBusConnection *connection,
DBusMessage *message,
void *user_data)
{ {
NMWirelessApplet *applet = (NMWirelessApplet *) user_data;
GtkWidget *dialog; GtkWidget *dialog;
g_return_if_fail (applet != NULL); g_return_val_if_fail (applet != NULL, NULL);
dialog = applet->passphrase_dialog; dialog = applet->passphrase_dialog;
if (GTK_WIDGET_VISIBLE (dialog)) if (GTK_WIDGET_VISIBLE (dialog))
nmi_passphrase_dialog_clear (dialog); nmi_passphrase_dialog_clear (dialog);
return NULL;
} }

View File

@@ -32,6 +32,8 @@ void nmi_passphrase_dialog_destroy (GtkWidget *dialog);
gboolean nmi_passphrase_dialog_schedule_show (NetworkDevice *dev, WirelessNetwork *net, DBusMessage *message, NMWirelessApplet *applet); gboolean nmi_passphrase_dialog_schedule_show (NetworkDevice *dev, WirelessNetwork *net, DBusMessage *message, NMWirelessApplet *applet);
void nmi_passphrase_dialog_cancel (NMWirelessApplet *applet); DBusMessage * nmi_passphrase_dialog_cancel (DBusConnection *connection, DBusMessage *message, void *user_data);
#endif /* PASSPHRASE_DIALOG_H */
#endif

View File

@@ -34,7 +34,9 @@ libnm_util_la_SOURCES= \
dbus-helpers.c \ dbus-helpers.c \
dbus-helpers.h \ dbus-helpers.h \
sha1.c \ sha1.c \
sha1.h sha1.h \
dbus-method-dispatcher.c \
dbus-method-dispatcher.h
if !WITH_GCRYPT if !WITH_GCRYPT
libnm_util_la_SOURCES += gnome-keyring-md5.c gnome-keyring-md5.h libnm_util_la_SOURCES += gnome-keyring-md5.c gnome-keyring-md5.h
@@ -55,7 +57,8 @@ libnm_util_include_HEADERS = \
cipher-wep-ascii.h \ cipher-wep-ascii.h \
cipher-wpa-psk-hex.h \ cipher-wpa-psk-hex.h \
cipher-wpa-psk-passphrase.h \ cipher-wpa-psk-passphrase.h \
dbus-helpers.h dbus-helpers.h \
dbus-method-dispatcher.h
pkgconfigdir = $(libdir)/pkgconfig pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libnm-util.pc pkgconfig_DATA = libnm-util.pc

View File

@@ -247,3 +247,32 @@ nmu_security_serialize_wpa_psk_with_cipher (DBusMessage *message,
return result; return result;
} }
/*
* nmu_create_dbus_error_message
*
* Make a pretty DBus error message
*
*/
DBusMessage *
nmu_create_dbus_error_message (DBusMessage *message,
const char *exception,
const char *format,
...)
{
DBusMessage * reply;
va_list args;
char * errmsg;
errmsg = g_malloc0 (513);
va_start (args, format);
vsnprintf (errmsg, 512, format, args);
va_end (args);
reply = dbus_message_new_error (message, exception, errmsg);
g_free (errmsg);
return reply;
}

View File

@@ -59,5 +59,9 @@ dbus_bool_t nmu_security_serialize_wpa_psk_with_cipher (DBusMessage *message,
int wpa_version, int wpa_version,
int key_mgt); int key_mgt);
DBusMessage * nmu_create_dbus_error_message (DBusMessage *message,
const char *exception,
const char *format,
...);
#endif /* DBUS_HELPERS_H */ #endif /* DBUS_HELPERS_H */

View File

@@ -0,0 +1,129 @@
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* (C) Copyright 2005 Red Hat, Inc.
*/
#include <glib.h>
#include <string.h>
#include "dbus-method-dispatcher.h"
struct DBusMethodDispatcher
{
int refcount;
DBusMethodCallback validate_method;
GHashTable * methods;
};
DBusMethodDispatcher *
dbus_method_dispatcher_new (DBusMethodCallback validate_method)
{
DBusMethodDispatcher * dispatcher = g_malloc0 (sizeof (DBusMethodDispatcher));
dispatcher->refcount = 1;
dispatcher->validate_method = validate_method;
dispatcher->methods = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
return dispatcher;
}
void
dbus_method_dispatcher_ref (DBusMethodDispatcher *dispatcher)
{
g_return_if_fail (dispatcher != NULL);
g_return_if_fail (dispatcher->refcount >= 1);
dispatcher->refcount++;
}
void
dbus_method_dispatcher_unref (DBusMethodDispatcher *dispatcher)
{
g_return_if_fail (dispatcher != NULL);
g_return_if_fail (dispatcher->refcount >= 1);
dispatcher->refcount--;
if (dispatcher->refcount <= 0)
{
g_hash_table_destroy (dispatcher->methods);
memset (dispatcher, 0, sizeof (DBusMethodDispatcher));
g_free (dispatcher);
}
}
void
dbus_method_dispatcher_register_method (DBusMethodDispatcher *dispatcher,
const char *method,
DBusMethodCallback callback)
{
g_return_if_fail (dispatcher != NULL);
g_return_if_fail (dispatcher->refcount >= 1);
g_return_if_fail (method != NULL);
g_return_if_fail (callback != NULL);
g_assert (dispatcher->methods);
g_hash_table_insert (dispatcher->methods, g_strdup (method), callback);
}
dbus_bool_t
dbus_method_dispatcher_dispatch (DBusMethodDispatcher *dispatcher,
DBusConnection *connection,
DBusMessage *message,
DBusMessage **reply,
void * user_data)
{
DBusMethodCallback callback = NULL;
const char * method;
DBusMessage * temp_reply = NULL;
g_return_val_if_fail (dispatcher != NULL, FALSE);
g_return_val_if_fail (dispatcher->refcount >= 1, FALSE);
g_return_val_if_fail (connection != NULL, FALSE);
g_return_val_if_fail (message != NULL, FALSE);
g_assert (dispatcher->methods);
if (reply)
g_return_val_if_fail (*reply == NULL, FALSE);
if (!(method = dbus_message_get_member (message)))
return FALSE;
if (!(callback = g_hash_table_lookup (dispatcher->methods, method)))
return FALSE;
/* Call the optional validate method first, if it returns NULL then we
* actually dispatch the call.
*/
if (dispatcher->validate_method)
temp_reply = (*(dispatcher->validate_method)) (connection, message, user_data);
if (!temp_reply)
temp_reply = (*callback) (connection, message, user_data);
if (reply)
*reply = temp_reply;
return TRUE;
}

View File

@@ -0,0 +1,51 @@
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* (C) Copyright 2005 Red Hat, Inc.
*/
#ifndef DBUS_METHOD_DISPATCHER_H
#define DBUS_METHOD_DISPATCHER_H
#include <dbus/dbus.h>
/* Type of method callback functions */
typedef DBusMessage* (*DBusMethodCallback) (DBusConnection *, DBusMessage *, void *);
typedef struct DBusMethodDispatcher DBusMethodDispatcher;
DBusMethodDispatcher * dbus_method_dispatcher_new (DBusMethodCallback validate_method);
void dbus_method_dispatcher_ref (DBusMethodDispatcher *dispatcher);
void dbus_method_dispatcher_unref (DBusMethodDispatcher *dispatcher);
void dbus_method_dispatcher_register_method (DBusMethodDispatcher *dispatcher,
const char *method,
DBusMethodCallback callback);
dbus_bool_t dbus_method_dispatcher_dispatch (DBusMethodDispatcher *dispatcher,
DBusConnection *connection,
DBusMessage *message,
DBusMessage **reply,
void * user_data);
#endif /* DBUS_METHOD_DISPATCHER_H */