diff --git a/ChangeLog b/ChangeLog index a8e85e8e1..fabc16b66 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-12-21 Dan Williams + + * Consolidate the info-daemon's "updateNetworkInfo" and + "addNetworkAddress" calls into just "updateNetworkInfo" + 2005-12-21 Dan Williams * Make connection after key retrieval work again diff --git a/gnome/applet/applet-dbus-info.c b/gnome/applet/applet-dbus-info.c index e941c32be..74c2d5ec6 100644 --- a/gnome/applet/applet-dbus-info.c +++ b/gnome/applet/applet-dbus-info.c @@ -834,6 +834,7 @@ static void nmi_save_network_info (NMWirelessApplet *applet, const char *essid, gboolean automatic, + const char *bssid, NMGConfWSO * gconf_wso) { GnomeKeyringAttributeList * attributes; @@ -897,6 +898,48 @@ nmi_save_network_info (NMWirelessApplet *applet, g_free (key); } + if (bssid && (strlen (bssid) >= 11)) + { + GConfValue * value; + GSList * new_bssid_list = NULL; + gboolean found = FALSE; + + /* Get current list of access point BSSIDs for this AP from GConf */ + key = g_strdup_printf ("%s/%s/bssids", GCONF_PATH_WIRELESS_NETWORKS, escaped_network); + if ((value = gconf_client_get (applet->gconf_client, key, NULL))) + { + if ((value->type == GCONF_VALUE_LIST) && (gconf_value_get_list_type (value) == GCONF_VALUE_STRING)) + { + GSList * elt; + + new_bssid_list = gconf_client_get_list (applet->gconf_client, key, GCONF_VALUE_STRING, NULL); + + /* Ensure that the MAC isn't already in the list */ + for (elt = new_bssid_list; elt; elt = g_slist_next (elt)) + { + if (elt->data && !strcmp (bssid, elt->data)) + { + found = TRUE; + break; + } + } + } + gconf_value_free (value); + } + g_free (key); + + /* Add the new MAC address to the end of the list */ + if (!found) + { + new_bssid_list = g_slist_append (new_bssid_list, g_strdup (bssid)); + gconf_client_set_list (applet->gconf_client, key, GCONF_VALUE_STRING, new_bssid_list, NULL); + } + + /* Free the list, since gconf_client_set_list deep-copies it */ + g_slist_foreach (new_bssid_list, (GFunc) g_free, NULL); + g_slist_free (new_bssid_list); + } + out: g_free (escaped_network); } @@ -920,6 +963,7 @@ nmi_dbus_update_network_info (DBusConnection *connection, dbus_bool_t args_good; NMGConfWSO * gconf_wso = NULL; DBusMessageIter iter; + char * bssid; g_return_val_if_fail (applet != NULL, NULL); g_return_val_if_fail (message != NULL, NULL); @@ -947,6 +991,14 @@ nmi_dbus_update_network_info (DBusConnection *connection, } dbus_message_iter_get_basic (&iter, &automatic); + /* Third argument: Access point's BSSID */ + if (!dbus_message_iter_next (&iter) || (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING)) + { + nm_warning ("%s:%d (%s): message argument 'bssid' was invalid.", __FILE__, __LINE__, __func__); + goto out; + } + dbus_message_iter_get_basic (&iter, &bssid); + /* Deserialize the sercurity option out of the message */ if (!dbus_message_iter_next (&iter)) goto out; @@ -957,106 +1009,13 @@ nmi_dbus_update_network_info (DBusConnection *connection, goto out; } - nmi_save_network_info (applet, essid, automatic, gconf_wso); + nmi_save_network_info (applet, essid, automatic, bssid, gconf_wso); out: return NULL; } -/* - * nmi_dbus_add_network_address - * - * Add an AP's MAC address to a wireless network entry in gconf - * - */ -static DBusMessage * -nmi_dbus_add_network_address (DBusConnection *connection, - DBusMessage *message, - void *user_data) -{ - NMWirelessApplet * applet = (NMWirelessApplet *) user_data; - DBusMessage * reply_message = NULL; - char * network = NULL; - NMNetworkType type; - char * addr; - char * key; - GConfValue * value; - char * escaped_network; - GSList * new_mac_list = NULL; - gboolean found = FALSE; - - 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_STRING, &network, - DBUS_TYPE_INT32, &type, - DBUS_TYPE_STRING, &addr, - DBUS_TYPE_INVALID)) - return new_invalid_args_error (message, __func__); - - if (!nmi_network_type_valid (type) || (strlen (network) <= 0) || !addr || (strlen (addr) < 11)) - return new_invalid_args_error (message, __func__); - - /* Force-set the essid too so that we have a semi-complete network entry */ - escaped_network = gconf_escape_key (network, strlen (network)); - key = g_strdup_printf ("%s/%s/essid", GCONF_PATH_WIRELESS_NETWORKS, escaped_network); - value = gconf_client_get (applet->gconf_client, key, NULL); - - /* If the network doesn't already exist in GConf, add it and set its timestamp to now. */ - if (!value || (!value && (value->type == GCONF_VALUE_STRING))) - { - /* Set the essid of the network. */ - gconf_client_set_string (applet->gconf_client, key, network, NULL); - g_free (key); - - /* Update timestamp on network */ - key = g_strdup_printf ("%s/%s/timestamp", GCONF_PATH_WIRELESS_NETWORKS, escaped_network); - gconf_client_set_int (applet->gconf_client, key, time (NULL), NULL); - } - g_free (key); - - /* 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); - if ((value = gconf_client_get (applet->gconf_client, key, NULL))) - { - 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); - - /* Ensure that the MAC isn't already in the list */ - for (elt = new_mac_list; elt; elt = g_slist_next (elt)) - { - if (elt->data && !strcmp (addr, elt->data)) - { - found = TRUE; - break; - } - } - } - gconf_value_free (value); - } - g_free (escaped_network); - g_free (key); - - /* Add the new MAC address to the end of the list */ - if (!found) - { - new_mac_list = g_slist_append (new_mac_list, g_strdup (addr)); - gconf_client_set_list (applet->gconf_client, key, GCONF_VALUE_STRING, new_mac_list, NULL); - } - - /* Free the list, since gconf_client_set_list deep-copies it */ - g_slist_foreach (new_mac_list, (GFunc)g_free, NULL); - g_slist_free (new_mac_list); - - return NULL; -} - - /* * nmi_dbus_info_message_handler * @@ -1120,7 +1079,6 @@ DBusMethodDispatcher *nmi_dbus_nmi_methods_setup (void) 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); diff --git a/src/NetworkManagerPolicy.c b/src/NetworkManagerPolicy.c index ff7ed50e7..374380b84 100644 --- a/src/NetworkManagerPolicy.c +++ b/src/NetworkManagerPolicy.c @@ -68,15 +68,12 @@ static gboolean nm_policy_activation_finish (NMActRequest *req) /* Cache details in the info-daemon since the connect was successful */ automatic = !nm_act_request_get_user_requested (req); - nm_dbus_update_network_info (data->dbus_connection, ap, automatic); nm_device_get_ap_address (dev, &addr); if (!nm_ap_get_address (ap) || !nm_ethernet_address_is_valid (nm_ap_get_address (ap))) nm_ap_set_address (ap, &addr); - /* Don't store MAC addresses for non-infrastructure networks */ - if ((nm_ap_get_mode (ap) == IW_MODE_INFRA) && nm_ethernet_address_is_valid (&addr)) - nm_dbus_add_network_address (data->dbus_connection, NETWORK_TYPE_ALLOWED, nm_ap_get_essid (ap), &addr); + nm_dbus_update_network_info (data->dbus_connection, ap, automatic); } nm_info ("Activation (%s) successful, device activated.", nm_device_get_iface (dev)); diff --git a/src/nm-dbus-nmi.c b/src/nm-dbus-nmi.c index 86ec37113..41a5312c7 100644 --- a/src/nm-dbus-nmi.c +++ b/src/nm-dbus-nmi.c @@ -24,6 +24,7 @@ #include "nm-activation-request.h" #include "NetworkManagerAPList.h" #include "NetworkManagerPolicy.h" +#include "NetworkManagerUtils.h" #include "nm-dbus-nmi.h" #include "nm-utils.h" @@ -221,7 +222,9 @@ gboolean nm_dbus_update_network_info (DBusConnection *connection, NMAccessPoint DBusMessage * message; gboolean success = FALSE; const char * essid; + gchar * char_bssid; NMAPSecurity * security; + const struct ether_addr *addr; DBusMessageIter iter; g_return_val_if_fail (connection != NULL, FALSE); @@ -243,6 +246,25 @@ gboolean nm_dbus_update_network_info (DBusConnection *connection, NMAccessPoint /* Second argument: Automatic (BOOLEAN) */ dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &automatic); + /* Third argument: Access point's BSSID */ + addr = nm_ap_get_address (ap); + if ((nm_ap_get_mode (ap) == IW_MODE_INFRA) && nm_ethernet_address_is_valid (addr)) + { + char_bssid = g_new0 (gchar, 20); + iw_ether_ntop (addr, char_bssid); + dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &char_bssid); + g_free (char_bssid); + } + else + { + /* Use an invalid BSSID for non-infrastructure networks, since + * the BSSID is usually randomly constructed by the driver and + * changed every time you activate the network. + */ + char_bssid = " "; + dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &char_bssid); + } + /* Serialize the AP's security info into the message */ security = nm_ap_get_security (ap); g_assert (security); @@ -262,51 +284,6 @@ out: } -/* - * nm_dbus_add_network_address - * - * Tell NetworkManagerInfo the MAC address of an AP - * - * Returns: FALSE on error - * TRUE on success - * - */ -gboolean nm_dbus_add_network_address (DBusConnection *connection, NMNetworkType type, const char *network, struct ether_addr *addr) -{ - DBusMessage * message; - gboolean success = FALSE; - gchar * char_addr; - dbus_int32_t type_as_int32 = (dbus_int32_t) type; - - g_return_val_if_fail (connection != NULL, FALSE); - g_return_val_if_fail (network != NULL, FALSE); - g_return_val_if_fail (type != NETWORK_TYPE_UNKNOWN, FALSE); - g_return_val_if_fail (addr != NULL, FALSE); - - if (!(message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "addNetworkAddress"))) - { - nm_warning ("nm_dbus_add_network_ap_mac_address(): Couldn't allocate the dbus message"); - return (FALSE); - } - - char_addr = g_new0 (gchar, 20); - iw_ether_ntop (addr, char_addr); - dbus_message_append_args (message, DBUS_TYPE_STRING, &network, - DBUS_TYPE_INT32, &type_as_int32, - DBUS_TYPE_STRING, &char_addr, - DBUS_TYPE_INVALID); - g_free (char_addr); - - if (!dbus_connection_send (connection, message, NULL)) - nm_warning ("nm_dbus_add_network_ap_mac_address(): failed to send dbus message."); - else - success = TRUE; - - dbus_message_unref (message); - return (success); -} - - typedef struct GetOneNetworkCBData { NMData * data; diff --git a/src/nm-dbus-nmi.h b/src/nm-dbus-nmi.h index abbb51e87..8d2173973 100644 --- a/src/nm-dbus-nmi.h +++ b/src/nm-dbus-nmi.h @@ -31,8 +31,6 @@ void nm_dbus_cancel_get_user_key_for_network (DBusConnection *connection, NMAc NMAccessPoint *nm_dbus_get_network_object (DBusConnection *connection, NMNetworkType type, const char *network); -gboolean nm_dbus_add_network_address (DBusConnection *connection, NMNetworkType type, const char *network, struct ether_addr *addr); - gboolean nm_dbus_update_network_info (DBusConnection *connection, NMAccessPoint *ap, const gboolean user_requested); void nm_dbus_update_one_allowed_network (DBusConnection *connection, const char *network, NMData *data);