diff options
author | Dan Williams <dcbw@redhat.com> | 2004-07-27 16:15:36 +0000 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2004-07-27 16:15:36 +0000 |
commit | 814cfbc5fc81d517917f459b129de07191f0f7cb (patch) | |
tree | 03c22bb252bb8d2631d6224390502ab4a6e014d8 /info-daemon | |
parent | 4d6a840768cabe7c5763dd4e09052d7d600f06e4 (diff) | |
download | NetworkManager-814cfbc5fc81d517917f459b129de07191f0f7cb.tar.gz |
2004-07-27 Dan Williams <dcbw@redhat.com>
* src/NetworkManagerAPList.[ch]
src/Makefile.am
- Add. Deal with allowed network list additions, deletions, and updates
* dispatcher-daemon/NetworkManagerDispatcher.c
- Add missing <dbus/dbus.h> header
* info-daemon/NetworkManagerInfo.[ch]
- Add missing <dbus/dbus.h> header
- Implement the GConf notify callback to signal NetworkManager of an allowed
network change
- Better error checking
* info-daemon/NetworkManagerInfoDbus.[ch]
- Add missing <dbus/dbus.h> header
- Convert to using dbus_message_append_args/dbus_message_get_args
- Implement nmi_dbus_signal_update_allowed_network() to signal NetworkManager
that an allowed network changed. We don't want to signal on individual
keys _inside_ an allowed network really, just want NM to query the info
daemon for updated info on all keys.
- Better error checking
* src/NetworkManager.[ch]
- Add missing <dbus/dbus.h> header
- Move allowed_ap_list free functions to NetworkManagerAPList.[ch]
- Zero out NMData structure on free
- No longer use a thread for allowed_ap_list updating, instead its now done
through dbus queries against NetworkManagerInfo
- Populate allowed_ap_list initially before adding existing network devices
to the device list, so wireless devices can get their "best" AP
* src/NetworkManagerDbus.[ch]
- Convert to using dbus_message_append_args/dbus_message_get_args
- Better error checking
- Implement Allowed Network info functions to request allowed network
info from NetworkManagerInfo
- Implement the filter function to process signals from NetworkManagerInfo
about changing allowed networks
* src/NetworkManagerDevice.c
- Fix file descriptor leak in nm_device_update_ip4_address()
`CVS: Modified Files:
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@22 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
Diffstat (limited to 'info-daemon')
-rw-r--r-- | info-daemon/NetworkManagerInfo.c | 31 | ||||
-rw-r--r-- | info-daemon/NetworkManagerInfo.h | 2 | ||||
-rw-r--r-- | info-daemon/NetworkManagerInfoDbus.c | 133 | ||||
-rw-r--r-- | info-daemon/NetworkManagerInfoDbus.h | 9 |
4 files changed, 119 insertions, 56 deletions
diff --git a/info-daemon/NetworkManagerInfo.c b/info-daemon/NetworkManagerInfo.c index 7e9bf4bf5a..b36be0eec9 100644 --- a/info-daemon/NetworkManagerInfo.c +++ b/info-daemon/NetworkManagerInfo.c @@ -21,6 +21,7 @@ */ #include <glib.h> +#include <dbus/dbus.h> #include <dbus/dbus-glib.h> #include <getopt.h> #include <errno.h> @@ -221,8 +222,38 @@ static void nmi_interface_init (NMIAppInfo *info) void nmi_gconf_notify_callback (GConfClient *client, guint connection_id, GConfEntry *entry, gpointer user_data) { NMIAppInfo *info = (NMIAppInfo *)user_data; + const char *key = NULL; + g_return_if_fail (client != NULL); + g_return_if_fail (entry != NULL); g_return_if_fail (info != NULL); + + key = gconf_entry_get_key (entry); + if (key) + { + static int gconf_path_len = 0; + + if (!gconf_path_len) + gconf_path_len = strlen (NMI_GCONF_ALLOWED_NETWORKS_PATH) + 1; + + /* Extract the network name from the key */ + if (strncmp ( NMI_GCONF_ALLOWED_NETWORKS_PATH + "/", + key, gconf_path_len) == 0) + { + char *network = g_strdup ((key + gconf_path_len)); + char *slash_pos; + + /* If its a key under the network name, zero out the slash so we + * are left with only the network name. + */ + if ((slash_pos = strchr (network, '/'))) + *slash_pos = '\0'; + + nmi_dbus_signal_update_allowed_network (info->connection, network); + g_free (network); + } + } } diff --git a/info-daemon/NetworkManagerInfo.h b/info-daemon/NetworkManagerInfo.h index 4113851d65..7d1e69e03f 100644 --- a/info-daemon/NetworkManagerInfo.h +++ b/info-daemon/NetworkManagerInfo.h @@ -26,6 +26,7 @@ #include <gtk/gtk.h> #include <glade/glade.h> #include <glib.h> +#include <dbus/dbus.h> #include <dbus/dbus-glib.h> #include <gconf/gconf-client.h> @@ -39,6 +40,7 @@ typedef struct NMIAppInfo NMIAppInfo; #define NMI_GCONF_WIRELESS_NETWORKING_PATH "/system/networking/wireless" +#define NMI_GCONF_ALLOWED_NETWORKS_PATH "/system/networking/wireless/allowed_networks" void nmi_show_user_key_dialog (const char *device, const char *network, NMIAppInfo *info); diff --git a/info-daemon/NetworkManagerInfoDbus.c b/info-daemon/NetworkManagerInfoDbus.c index f73c6a8042..750d838168 100644 --- a/info-daemon/NetworkManagerInfoDbus.c +++ b/info-daemon/NetworkManagerInfoDbus.c @@ -21,6 +21,7 @@ */ #include <glib.h> +#include <dbus/dbus.h> #include <dbus/dbus-glib.h> #include <stdio.h> #include <string.h> @@ -65,30 +66,21 @@ static DBusMessage *nmi_dbus_create_error_message (DBusMessage *message, const c */ static void nmi_dbus_get_key_for_network (NMIAppInfo *info, DBusMessage *message) { - DBusMessageIter iter; - char *dbus_string; + DBusError error; char *device = NULL; char *network = NULL; - dbus_message_iter_init (message, &iter); - /* Grab device */ - dbus_string = dbus_message_iter_get_string (&iter); - device = (dbus_string == NULL ? NULL : strdup (dbus_string)); - dbus_free (dbus_string); - - /* Grab network to get key for */ - if (dbus_message_iter_next (&iter)) + dbus_error_init (&error); + if (dbus_message_get_args (message, &error, + DBUS_TYPE_STRING, &device, + DBUS_TYPE_STRING, &network, + DBUS_TYPE_INVALID)) { - dbus_string = dbus_message_iter_get_string (&iter); - network = (dbus_string == NULL ? NULL : strdup (dbus_string)); - dbus_free (dbus_string); - } - - if (device && network) nmi_show_user_key_dialog (device, network, info); - g_free (device); - g_free (network); + dbus_free (device); + dbus_free (network); + } } @@ -102,7 +94,6 @@ void nmi_dbus_return_user_key (DBusConnection *connection, const char *device, const char *network, const char *passphrase) { DBusMessage *message; - DBusMessageIter iter; g_return_if_fail (connection != NULL); g_return_if_fail (device != NULL); @@ -120,16 +111,48 @@ void nmi_dbus_return_user_key (DBusConnection *connection, const char *device, } /* Add network name and passphrase */ - dbus_message_iter_init (message, &iter); - dbus_message_iter_append_string (&iter, device); - dbus_message_iter_append_string (&iter, network); - dbus_message_iter_append_string (&iter, passphrase); + if (dbus_message_append_args (message, DBUS_TYPE_STRING, device, + DBUS_TYPE_STRING, network, + DBUS_TYPE_STRING, passphrase, + DBUS_TYPE_INVALID)) + { + if (!dbus_connection_send (connection, message, NULL)) + fprintf (stderr, "nmi_dbus_return_user_key(): dbus could not send the message\n"); + } - if (!dbus_connection_send (connection, message, NULL)) + dbus_message_unref (message); +} + + +/* + * nmi_dbus_signal_update_allowed_network + * + * Signal NetworkManager that it needs to update info associated with a particular + * allowed network. + * + */ +void nmi_dbus_signal_update_allowed_network (DBusConnection *connection, const char *network) +{ + DBusMessage *message; + + g_return_if_fail (connection != NULL); + g_return_if_fail (network != NULL); + +fprintf( stderr, "nmi_dbus_signal_update_allowed_network() signaling update for '%s'\n", network); + + message = dbus_message_new_signal ("/org/freedesktop/NetworkManagerInfo", "org.freedesktop.NetworkManagerInfo", + "AllowedNetworkUpdate"); + if (!message) { - fprintf (stderr, "nmi_dbus_return_user_key(): dbus could not send the message\n"); + fprintf (stderr, "nmi_dbus_signal_update_allowed_network(): Not enough memory for new dbus message!\n"); return; } + + dbus_message_append_args (message, DBUS_TYPE_STRING, network, DBUS_TYPE_INVALID); + if (!dbus_connection_send (connection, message, NULL)) + fprintf (stderr, "nmi_dbus_signal_update_allowed_network(): Could not raise the AllowedNetworkUpdate signal!\n"); + + dbus_message_unref (message); } @@ -147,12 +170,12 @@ static DBusMessage *nmi_dbus_get_allowed_networks (NMIAppInfo *info, DBusMessage DBusMessage *reply_message = NULL; DBusMessageIter iter; DBusMessageIter iter_array; - gchar *path = NULL; + + g_return_val_if_fail (info != NULL, NULL); + g_return_val_if_fail (message != NULL, NULL); /* List all allowed access points that gconf knows about */ - path = g_strdup_printf ("%s/allowed_networks", NMI_GCONF_WIRELESS_NETWORKING_PATH); - element = dir_list = gconf_client_all_dirs (info->gconf_client, path, NULL); - g_free (path); + element = dir_list = gconf_client_all_dirs (info->gconf_client, NMI_GCONF_ALLOWED_NETWORKS_PATH, NULL); reply_message = dbus_message_new_method_return (message); dbus_message_iter_init (reply_message, &iter); @@ -208,11 +231,13 @@ static DBusMessage *nmi_dbus_get_allowed_network_prio (NMIAppInfo *info, DBusMes gchar *key = NULL; char *network = NULL; GConfValue *value; - DBusMessageIter iter; + DBusError error; + + g_return_val_if_fail (info != NULL, NULL); + g_return_val_if_fail (message != NULL, NULL); - dbus_message_iter_init (message, &iter); - network = dbus_message_iter_get_string (&iter); - if (!network) + dbus_error_init (&error); + if (!dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &network, DBUS_TYPE_INVALID)) { reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_NMI_NAMESPACE, "InvalidNetwork", "NetworkManagerInfo::getAllowedNetworkPriority called with invalid network."); @@ -220,15 +245,14 @@ static DBusMessage *nmi_dbus_get_allowed_network_prio (NMIAppInfo *info, DBusMes } /* List all allowed access points that gconf knows about */ - key = g_strdup_printf ("%s/allowed_networks/%s/priority", NMI_GCONF_WIRELESS_NETWORKING_PATH, network); + key = g_strdup_printf ("%s/%s/priority", NMI_GCONF_ALLOWED_NETWORKS_PATH, network); value = gconf_client_get (info->gconf_client, key, NULL); g_free (key); if (value) { reply_message = dbus_message_new_method_return (message); - dbus_message_iter_init (reply_message, &iter); - dbus_message_iter_append_uint32 (&iter, gconf_value_get_int (value)); + dbus_message_append_args (reply_message, DBUS_TYPE_UINT32, gconf_value_get_int (value), DBUS_TYPE_INVALID); gconf_value_free (value); } else @@ -237,6 +261,7 @@ static DBusMessage *nmi_dbus_get_allowed_network_prio (NMIAppInfo *info, DBusMes "NetworkManagerInfo::getAllowedNetworkPriority could not access data for network '%s'", network); } + dbus_free (network); return (reply_message); } @@ -254,11 +279,13 @@ static DBusMessage *nmi_dbus_get_allowed_network_essid (NMIAppInfo *info, DBusMe gchar *key = NULL; char *network = NULL; GConfValue *value; - DBusMessageIter iter; + DBusError error; + + g_return_val_if_fail (info != NULL, NULL); + g_return_val_if_fail (message != NULL, NULL); - dbus_message_iter_init (message, &iter); - network = dbus_message_iter_get_string (&iter); - if (!network) + dbus_error_init (&error); + if (!dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &network, DBUS_TYPE_INVALID)) { reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_NMI_NAMESPACE, "InvalidNetwork", "NetworkManagerInfo::getAllowedNetworkEssid called with invalid network."); @@ -266,15 +293,14 @@ static DBusMessage *nmi_dbus_get_allowed_network_essid (NMIAppInfo *info, DBusMe } /* List all allowed access points that gconf knows about */ - key = g_strdup_printf ("%s/allowed_networks/%s/essid", NMI_GCONF_WIRELESS_NETWORKING_PATH, network); + key = g_strdup_printf ("%s/%s/essid", NMI_GCONF_ALLOWED_NETWORKS_PATH, network); value = gconf_client_get (info->gconf_client, key, NULL); g_free (key); if (value) { reply_message = dbus_message_new_method_return (message); - dbus_message_iter_init (reply_message, &iter); - dbus_message_iter_append_string (&iter, gconf_value_get_string (value)); + dbus_message_append_args (reply_message, DBUS_TYPE_STRING, gconf_value_get_string (value), DBUS_TYPE_INVALID); gconf_value_free (value); } else @@ -283,6 +309,7 @@ static DBusMessage *nmi_dbus_get_allowed_network_essid (NMIAppInfo *info, DBusMe "NetworkManagerInfo::getAllowedNetworkEssid could not access data for network '%s'", network); } + dbus_free (network); return (reply_message); } @@ -300,11 +327,13 @@ static DBusMessage *nmi_dbus_get_allowed_network_key (NMIAppInfo *info, DBusMess gchar *key = NULL; char *network = NULL; GConfValue *value; - DBusMessageIter iter; + DBusError error; + + g_return_val_if_fail (info != NULL, NULL); + g_return_val_if_fail (message != NULL, NULL); - dbus_message_iter_init (message, &iter); - network = dbus_message_iter_get_string (&iter); - if (!network) + dbus_error_init (&error); + if (!dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &network, DBUS_TYPE_INVALID)) { reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_NMI_NAMESPACE, "InvalidNetwork", "NetworkManagerInfo::getAllowedNetworkKey called with invalid network."); @@ -312,21 +341,19 @@ static DBusMessage *nmi_dbus_get_allowed_network_key (NMIAppInfo *info, DBusMess } /* List all allowed access points that gconf knows about */ - key = g_strdup_printf ("%s/allowed_networks/%s/key", NMI_GCONF_WIRELESS_NETWORKING_PATH, network); + key = g_strdup_printf ("%s/%s/key", NMI_GCONF_ALLOWED_NETWORKS_PATH, network); value = gconf_client_get (info->gconf_client, key, NULL); g_free (key); - /* In the case of the key, we don't error out if no key was found in gconf */ + /* We don't error out if no key was found in gconf, we return blank key */ reply_message = dbus_message_new_method_return (message); - dbus_message_iter_init (reply_message, &iter); - if (value) { - dbus_message_iter_append_string (&iter, gconf_value_get_string (value)); + dbus_message_append_args (reply_message, DBUS_TYPE_STRING, gconf_value_get_string (value), DBUS_TYPE_INVALID); gconf_value_free (value); } else - dbus_message_iter_append_string (&iter, ""); + dbus_message_append_args (reply_message, DBUS_TYPE_STRING, "", DBUS_TYPE_INVALID); return (reply_message); } diff --git a/info-daemon/NetworkManagerInfoDbus.h b/info-daemon/NetworkManagerInfoDbus.h index cbc64d7352..472419d93a 100644 --- a/info-daemon/NetworkManagerInfoDbus.h +++ b/info-daemon/NetworkManagerInfoDbus.h @@ -24,12 +24,15 @@ #define NETWORK_MANAGER_INFO_DBUS_SERVICE_H #include <glib.h> +#include <dbus/dbus.h> #include <dbus/dbus-glib.h> #include "NetworkManagerInfo.h" -int nmi_dbus_service_init (DBusConnection *dbus_connection, NMIAppInfo *info); +int nmi_dbus_service_init (DBusConnection *dbus_connection, NMIAppInfo *info); -void nmi_dbus_return_user_key (DBusConnection *connection, const char *device, - const char *network, const char *passphrase); +void nmi_dbus_return_user_key (DBusConnection *connection, const char *device, + const char *network, const char *passphrase); + +void nmi_dbus_signal_update_allowed_network (DBusConnection *connection, const char *network); #endif |