NetworkManager/libnm-util/nm-connection.c

419 lines
10 KiB
C
Raw Normal View History

#include <glib-object.h>
#include <dbus/dbus-glib.h>
2007-09-10 Dan Williams <dcbw@redhat.com> * include/NetworkManager.h - Kill NMNetworkType; AP types don't matter any more * src/NetworkManagerAPList.c src/NetworkManagerAPList.h src/Makefile.am - Kill; NMAccessPointList has outlived it's usefulness * src/NetworkManagerAP.c src/NetworkManagerAP.h - (match_cipher, security_compatible, nm_ap_check_compatible): new functions; check if an NMConnection object is compatible with the settings of this AP - (freq_to_channel, channel_to_freq): utility functions for channel <-> frequency conversion * src/nm-device.c src/nm-device.h - (nm_device_get_best_connection): pass the specific object around (which might be the object path of a specific AP to connect to). The get_best_connection() call should populate this on return if needed (wireless does). * src/nm-device-802-3-ethernet.c - (real_get_best_connection): handle specific_object argument * src/NetworkManager.c src/NetworkManagerMain.h - Remove unused includes * src/nm-device-802-11-wireless.c src/nm-device-802-11-wireless.h - Convert the ap_list into a GSList from an NMAccessPointList - No need for caching the 'activation_ap' since this is now determined from the specific_object of the activation request, which is populated from the get_best_connection() call or from a user request - (nm_device_802_11_wireless_update_bssid): fix warning - (get_wireless_capabilities): fix error message format arguments - (nm_device_802_11_wireless_copy_allowed_to_dev_list): remove, unused - (find_best_connection, real_get_best_connection): implement - (ap_list_get_ap_by_ssid, nm_device_802_11_wireless_ap_list_print): move here from NetworkManagerAPList - (ap_need_secrets): remove; moved to nm-connection.c where it belongs - (real_act_stage1_prepare): just ensure an AP exists, connection is already verified earlier - (real_act_stage2_config): use nm_connection_need_secrets() * src/NetworkManagerPolicy.c - (nm_policy_auto_get_best_device): handle specific objects - (create_connection): remove; automatic connection creation functionality is handled by the Connection objects - (nm_policy_device_change_check): handle specific_object * libnm-util/nm-connection.c - (wireless_sec_need_secrets, nm_connection_need_secrets): implement git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2778 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-09-10 19:11:40 +00:00
#include <string.h>
#include "nm-connection.h"
#include "nm-utils.h"
typedef struct {
GHashTable *settings;
} NMConnectionPrivate;
#define NM_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_CONNECTION, NMConnectionPrivate))
G_DEFINE_TYPE (NMConnection, nm_connection, G_TYPE_OBJECT)
2007-09-11 Dan Williams <dcbw@redhat.com> * libnm-util/nm-setting.c libnm-util/nm-setting.h - (nm_setting_update_secrets): new function; add a virtual function that subclasses can implement to update their secrets - (setting_wireless_security_update_secrets): implement that function for the 802-11-wireless-security subclass * libnm-util/nm-connection.c libnm-util/nm-connection.h - (nm_connection_update_secrets): update secrets for a Setting and emit a signal on success * src/nm-manager.c src/nm-manager.h src/nm-marshal.list - (connection_get_settings_cb): enable system settings bits - (nm_manager_get_connection_secrets, get_secrets_cb): add function to request secrets from the settings dbus service and to push those secrets to the NMConnection itself * src/nm-activation-request.c src/nm-activation-request.h - Attach to the 'secrets-updated' signal of the NMConnection that's currently being activated, and proxy that signal to other listeners. Goes through the activation request because the activation request is the thing that manages the lifetime of the NMConnection that's being activated. * src/nm-device-802-11-wireless.c - (real_connection_secrets_updated): implement the connection secrets updated notification and restart activation when secrets are received - (real_act_stage2_config): request secrets from the settings dbus service if secrets are needed * src/nm-device.c src/nm-device.h - (clear_act_request, nm_device_activation_cancel, nm_device_deactivate_quickly, nm_device_dispose): consolidate places where the activation request is cleared - (nm_device_activate, connection_secrets_updated_cb): attach to the updated secrets signal of activation request and add a function that subclasses can override to handle it easily git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2782 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-09-11 18:02:27 +00:00
enum {
SECRETS_UPDATED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
static GHashTable *registered_setting_creators = NULL;
static void
register_default_creators (void)
{
int i;
const struct {
const char *name;
NMSettingCreateFn fn;
} default_map[] = {
{ "connection", nm_setting_connection_new_from_hash },
{ "802-3-ethernet", nm_setting_wired_new_from_hash },
{ "802-11-wireless", nm_setting_wireless_new_from_hash },
{ "ipv4", nm_setting_ip4_config_new_from_hash },
{ "802-11-wireless-security", nm_setting_wireless_security_new_from_hash },
{ "ppp", nm_setting_ppp_new_from_hash },
{ NULL, NULL}
};
for (i = 0; default_map[i].name; i++)
nm_setting_parser_register (default_map[i].name, default_map[i].fn);
}
void
nm_setting_parser_register (const char *name, NMSettingCreateFn creator)
{
g_return_if_fail (name != NULL);
g_return_if_fail (creator != NULL);
if (!registered_setting_creators)
registered_setting_creators = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) g_free, NULL);
if (g_hash_table_lookup (registered_setting_creators, name))
g_warning ("Already have a creator function for '%s', overriding", name);
g_hash_table_insert (registered_setting_creators, g_strdup (name), creator);
}
void
nm_setting_parser_unregister (const char *name)
{
if (registered_setting_creators)
g_hash_table_remove (registered_setting_creators, name);
}
static void
parse_one_setting (gpointer key, gpointer value, gpointer user_data)
{
NMConnection *connection = (NMConnection *) user_data;
NMSettingCreateFn fn;
NMSetting *setting;
fn = (NMSettingCreateFn) g_hash_table_lookup (registered_setting_creators, key);
if (fn) {
setting = fn ((GHashTable *) value);
if (setting)
nm_connection_add_setting (connection, setting);
} else
g_warning ("Unknown setting '%s'", (char *) key);
}
void
nm_connection_add_setting (NMConnection *connection, NMSetting *setting)
{
NMConnectionPrivate *priv;
g_return_if_fail (NM_IS_CONNECTION (connection));
g_return_if_fail (setting != NULL);
priv = NM_CONNECTION_GET_PRIVATE (connection);
g_hash_table_insert (priv->settings, setting->name, setting);
}
NMSetting *
nm_connection_get_setting (NMConnection *connection, const char *setting_name)
{
NMConnectionPrivate *priv;
2007-09-10 Dan Williams <dcbw@redhat.com> * include/NetworkManager.h - Kill NMNetworkType; AP types don't matter any more * src/NetworkManagerAPList.c src/NetworkManagerAPList.h src/Makefile.am - Kill; NMAccessPointList has outlived it's usefulness * src/NetworkManagerAP.c src/NetworkManagerAP.h - (match_cipher, security_compatible, nm_ap_check_compatible): new functions; check if an NMConnection object is compatible with the settings of this AP - (freq_to_channel, channel_to_freq): utility functions for channel <-> frequency conversion * src/nm-device.c src/nm-device.h - (nm_device_get_best_connection): pass the specific object around (which might be the object path of a specific AP to connect to). The get_best_connection() call should populate this on return if needed (wireless does). * src/nm-device-802-3-ethernet.c - (real_get_best_connection): handle specific_object argument * src/NetworkManager.c src/NetworkManagerMain.h - Remove unused includes * src/nm-device-802-11-wireless.c src/nm-device-802-11-wireless.h - Convert the ap_list into a GSList from an NMAccessPointList - No need for caching the 'activation_ap' since this is now determined from the specific_object of the activation request, which is populated from the get_best_connection() call or from a user request - (nm_device_802_11_wireless_update_bssid): fix warning - (get_wireless_capabilities): fix error message format arguments - (nm_device_802_11_wireless_copy_allowed_to_dev_list): remove, unused - (find_best_connection, real_get_best_connection): implement - (ap_list_get_ap_by_ssid, nm_device_802_11_wireless_ap_list_print): move here from NetworkManagerAPList - (ap_need_secrets): remove; moved to nm-connection.c where it belongs - (real_act_stage1_prepare): just ensure an AP exists, connection is already verified earlier - (real_act_stage2_config): use nm_connection_need_secrets() * src/NetworkManagerPolicy.c - (nm_policy_auto_get_best_device): handle specific objects - (create_connection): remove; automatic connection creation functionality is handled by the Connection objects - (nm_policy_device_change_check): handle specific_object * libnm-util/nm-connection.c - (wireless_sec_need_secrets, nm_connection_need_secrets): implement git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2778 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-09-10 19:11:40 +00:00
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
g_return_val_if_fail (setting_name != NULL, NULL);
priv = NM_CONNECTION_GET_PRIVATE (connection);
return (NMSetting *) g_hash_table_lookup (priv->settings, setting_name);
}
2007-06-21 Tambet Ingo <tambet@ximian.com> * libnm-glib/Makefile.am: Add NMObject to build, remove nm-utils.[ch]. * nm-utils.[ch]: Remove. * libnm-glib/nm-object.c: Implement a base class for all libnm-glib dbus-aware objects for easy property access and dbus connection handling. * libnm-glib/nm-client.c: Derive from NMObject. * libnm-glib/nm-device.c: Ditto. * libnm-glib/nm-device-802-3-ethernet.c: Changes for being based on NMObject. * libnm-glib/nm-device-802-11-wireless.c: Ditto. * libnm-glib/nm-ip4-config.c: Ditto. * libnm-glib/nm-access-point.c: Ditto. * libnm-util/nm-connection.c (nm_connection_compare): Add a stub for connection comparision. Currently used by the device activation code to determine if the new activation is the same as the old one. * src/nm-dbus-nmi.c (nm_dbus_get_user_key_for_network): Don't use the obsolete and wrong way of getting the dbus path for AP. Fixes the issue where the applet isn't able to ask password for the AP. * src/nm-device.c (nm_device_activate): Change the logic here - instead of giving up if the device is already connected, tear down it's connection (if it isn't the same as new one) and start the activation. * src/nm-manager.c: Add the beginnings of NMConnection storage and signals. * src/NetworkManagerAP.c (nm_ap_init): Set the default values to AP memebers, fixes the issue where all APs are always listed as encrypted. * src/NetworkManagerDbus.c (nm_dbus_get_object_path_for_network): Remove. APs have their own registered paths. * test/nm-tool.c (detail_device): Don't try to get active network from wireless device if it's not connected - dbus-glib will happily crash trying to marshal NULL. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2615 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-06-22 15:09:02 +00:00
gboolean
nm_connection_compare (NMConnection *connection, NMConnection *other)
{
if (!connection && !other)
return TRUE;
if (!connection || !other)
return FALSE;
/* FIXME: Implement */
return FALSE;
}
2007-09-11 Dan Williams <dcbw@redhat.com> * libnm-util/nm-setting.c libnm-util/nm-setting.h - (nm_setting_update_secrets): new function; add a virtual function that subclasses can implement to update their secrets - (setting_wireless_security_update_secrets): implement that function for the 802-11-wireless-security subclass * libnm-util/nm-connection.c libnm-util/nm-connection.h - (nm_connection_update_secrets): update secrets for a Setting and emit a signal on success * src/nm-manager.c src/nm-manager.h src/nm-marshal.list - (connection_get_settings_cb): enable system settings bits - (nm_manager_get_connection_secrets, get_secrets_cb): add function to request secrets from the settings dbus service and to push those secrets to the NMConnection itself * src/nm-activation-request.c src/nm-activation-request.h - Attach to the 'secrets-updated' signal of the NMConnection that's currently being activated, and proxy that signal to other listeners. Goes through the activation request because the activation request is the thing that manages the lifetime of the NMConnection that's being activated. * src/nm-device-802-11-wireless.c - (real_connection_secrets_updated): implement the connection secrets updated notification and restart activation when secrets are received - (real_act_stage2_config): request secrets from the settings dbus service if secrets are needed * src/nm-device.c src/nm-device.h - (clear_act_request, nm_device_activation_cancel, nm_device_deactivate_quickly, nm_device_dispose): consolidate places where the activation request is cleared - (nm_device_activate, connection_secrets_updated_cb): attach to the updated secrets signal of activation request and add a function that subclasses can override to handle it easily git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2782 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-09-11 18:02:27 +00:00
void
nm_connection_update_secrets (NMConnection *connection,
const char *setting_name,
GHashTable *secrets)
{
NMSetting *setting;
g_return_if_fail (NM_IS_CONNECTION (connection));
g_return_if_fail (setting_name != NULL);
g_return_if_fail (secrets != NULL);
setting = nm_connection_get_setting (connection, setting_name);
if (!setting) {
g_warning ("Unhandled settings object for secrets update.");
return;
}
if (!nm_setting_update_secrets (setting, secrets)) {
g_warning ("Error updating secrets for setting '%s'", setting_name);
return;
}
g_signal_emit (connection, signals[SECRETS_UPDATED], 0, setting_name);
}
typedef struct NeedSecretsInfo {
GPtrArray * secrets;
char * setting_name;
} NeedSecretsInfo;
static void
need_secrets_check (gpointer key, gpointer data, gpointer user_data)
{
NMSetting *setting = (NMSetting *) data;
NeedSecretsInfo * info = (NeedSecretsInfo *) user_data;
// FIXME: allow more than one setting to say it needs secrets
if (info->secrets)
return;
info->secrets = nm_setting_need_secrets (setting);
if (info->secrets)
info->setting_name = key;
}
2007-09-10 Dan Williams <dcbw@redhat.com> * include/NetworkManager.h - Kill NMNetworkType; AP types don't matter any more * src/NetworkManagerAPList.c src/NetworkManagerAPList.h src/Makefile.am - Kill; NMAccessPointList has outlived it's usefulness * src/NetworkManagerAP.c src/NetworkManagerAP.h - (match_cipher, security_compatible, nm_ap_check_compatible): new functions; check if an NMConnection object is compatible with the settings of this AP - (freq_to_channel, channel_to_freq): utility functions for channel <-> frequency conversion * src/nm-device.c src/nm-device.h - (nm_device_get_best_connection): pass the specific object around (which might be the object path of a specific AP to connect to). The get_best_connection() call should populate this on return if needed (wireless does). * src/nm-device-802-3-ethernet.c - (real_get_best_connection): handle specific_object argument * src/NetworkManager.c src/NetworkManagerMain.h - Remove unused includes * src/nm-device-802-11-wireless.c src/nm-device-802-11-wireless.h - Convert the ap_list into a GSList from an NMAccessPointList - No need for caching the 'activation_ap' since this is now determined from the specific_object of the activation request, which is populated from the get_best_connection() call or from a user request - (nm_device_802_11_wireless_update_bssid): fix warning - (get_wireless_capabilities): fix error message format arguments - (nm_device_802_11_wireless_copy_allowed_to_dev_list): remove, unused - (find_best_connection, real_get_best_connection): implement - (ap_list_get_ap_by_ssid, nm_device_802_11_wireless_ap_list_print): move here from NetworkManagerAPList - (ap_need_secrets): remove; moved to nm-connection.c where it belongs - (real_act_stage1_prepare): just ensure an AP exists, connection is already verified earlier - (real_act_stage2_config): use nm_connection_need_secrets() * src/NetworkManagerPolicy.c - (nm_policy_auto_get_best_device): handle specific objects - (create_connection): remove; automatic connection creation functionality is handled by the Connection objects - (nm_policy_device_change_check): handle specific_object * libnm-util/nm-connection.c - (wireless_sec_need_secrets, nm_connection_need_secrets): implement git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2778 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-09-10 19:11:40 +00:00
const char *
2007-09-11 Dan Williams <dcbw@redhat.com> * libnm-util/nm-setting.c libnm-util/nm-setting.h - (nm_setting_update_secrets): new function; add a virtual function that subclasses can implement to update their secrets - (setting_wireless_security_update_secrets): implement that function for the 802-11-wireless-security subclass * libnm-util/nm-connection.c libnm-util/nm-connection.h - (nm_connection_update_secrets): update secrets for a Setting and emit a signal on success * src/nm-manager.c src/nm-manager.h src/nm-marshal.list - (connection_get_settings_cb): enable system settings bits - (nm_manager_get_connection_secrets, get_secrets_cb): add function to request secrets from the settings dbus service and to push those secrets to the NMConnection itself * src/nm-activation-request.c src/nm-activation-request.h - Attach to the 'secrets-updated' signal of the NMConnection that's currently being activated, and proxy that signal to other listeners. Goes through the activation request because the activation request is the thing that manages the lifetime of the NMConnection that's being activated. * src/nm-device-802-11-wireless.c - (real_connection_secrets_updated): implement the connection secrets updated notification and restart activation when secrets are received - (real_act_stage2_config): request secrets from the settings dbus service if secrets are needed * src/nm-device.c src/nm-device.h - (clear_act_request, nm_device_activation_cancel, nm_device_deactivate_quickly, nm_device_dispose): consolidate places where the activation request is cleared - (nm_device_activate, connection_secrets_updated_cb): attach to the updated secrets signal of activation request and add a function that subclasses can override to handle it easily git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2782 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-09-11 18:02:27 +00:00
nm_connection_need_secrets (NMConnection *connection)
2007-09-10 Dan Williams <dcbw@redhat.com> * include/NetworkManager.h - Kill NMNetworkType; AP types don't matter any more * src/NetworkManagerAPList.c src/NetworkManagerAPList.h src/Makefile.am - Kill; NMAccessPointList has outlived it's usefulness * src/NetworkManagerAP.c src/NetworkManagerAP.h - (match_cipher, security_compatible, nm_ap_check_compatible): new functions; check if an NMConnection object is compatible with the settings of this AP - (freq_to_channel, channel_to_freq): utility functions for channel <-> frequency conversion * src/nm-device.c src/nm-device.h - (nm_device_get_best_connection): pass the specific object around (which might be the object path of a specific AP to connect to). The get_best_connection() call should populate this on return if needed (wireless does). * src/nm-device-802-3-ethernet.c - (real_get_best_connection): handle specific_object argument * src/NetworkManager.c src/NetworkManagerMain.h - Remove unused includes * src/nm-device-802-11-wireless.c src/nm-device-802-11-wireless.h - Convert the ap_list into a GSList from an NMAccessPointList - No need for caching the 'activation_ap' since this is now determined from the specific_object of the activation request, which is populated from the get_best_connection() call or from a user request - (nm_device_802_11_wireless_update_bssid): fix warning - (get_wireless_capabilities): fix error message format arguments - (nm_device_802_11_wireless_copy_allowed_to_dev_list): remove, unused - (find_best_connection, real_get_best_connection): implement - (ap_list_get_ap_by_ssid, nm_device_802_11_wireless_ap_list_print): move here from NetworkManagerAPList - (ap_need_secrets): remove; moved to nm-connection.c where it belongs - (real_act_stage1_prepare): just ensure an AP exists, connection is already verified earlier - (real_act_stage2_config): use nm_connection_need_secrets() * src/NetworkManagerPolicy.c - (nm_policy_auto_get_best_device): handle specific objects - (create_connection): remove; automatic connection creation functionality is handled by the Connection objects - (nm_policy_device_change_check): handle specific_object * libnm-util/nm-connection.c - (wireless_sec_need_secrets, nm_connection_need_secrets): implement git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2778 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-09-10 19:11:40 +00:00
{
NMConnectionPrivate *priv;
2007-09-10 Dan Williams <dcbw@redhat.com> * include/NetworkManager.h - Kill NMNetworkType; AP types don't matter any more * src/NetworkManagerAPList.c src/NetworkManagerAPList.h src/Makefile.am - Kill; NMAccessPointList has outlived it's usefulness * src/NetworkManagerAP.c src/NetworkManagerAP.h - (match_cipher, security_compatible, nm_ap_check_compatible): new functions; check if an NMConnection object is compatible with the settings of this AP - (freq_to_channel, channel_to_freq): utility functions for channel <-> frequency conversion * src/nm-device.c src/nm-device.h - (nm_device_get_best_connection): pass the specific object around (which might be the object path of a specific AP to connect to). The get_best_connection() call should populate this on return if needed (wireless does). * src/nm-device-802-3-ethernet.c - (real_get_best_connection): handle specific_object argument * src/NetworkManager.c src/NetworkManagerMain.h - Remove unused includes * src/nm-device-802-11-wireless.c src/nm-device-802-11-wireless.h - Convert the ap_list into a GSList from an NMAccessPointList - No need for caching the 'activation_ap' since this is now determined from the specific_object of the activation request, which is populated from the get_best_connection() call or from a user request - (nm_device_802_11_wireless_update_bssid): fix warning - (get_wireless_capabilities): fix error message format arguments - (nm_device_802_11_wireless_copy_allowed_to_dev_list): remove, unused - (find_best_connection, real_get_best_connection): implement - (ap_list_get_ap_by_ssid, nm_device_802_11_wireless_ap_list_print): move here from NetworkManagerAPList - (ap_need_secrets): remove; moved to nm-connection.c where it belongs - (real_act_stage1_prepare): just ensure an AP exists, connection is already verified earlier - (real_act_stage2_config): use nm_connection_need_secrets() * src/NetworkManagerPolicy.c - (nm_policy_auto_get_best_device): handle specific objects - (create_connection): remove; automatic connection creation functionality is handled by the Connection objects - (nm_policy_device_change_check): handle specific_object * libnm-util/nm-connection.c - (wireless_sec_need_secrets, nm_connection_need_secrets): implement git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2778 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-09-10 19:11:40 +00:00
NMSettingConnection *s_connection;
NeedSecretsInfo info = { NULL, NULL };
2007-09-10 Dan Williams <dcbw@redhat.com> * include/NetworkManager.h - Kill NMNetworkType; AP types don't matter any more * src/NetworkManagerAPList.c src/NetworkManagerAPList.h src/Makefile.am - Kill; NMAccessPointList has outlived it's usefulness * src/NetworkManagerAP.c src/NetworkManagerAP.h - (match_cipher, security_compatible, nm_ap_check_compatible): new functions; check if an NMConnection object is compatible with the settings of this AP - (freq_to_channel, channel_to_freq): utility functions for channel <-> frequency conversion * src/nm-device.c src/nm-device.h - (nm_device_get_best_connection): pass the specific object around (which might be the object path of a specific AP to connect to). The get_best_connection() call should populate this on return if needed (wireless does). * src/nm-device-802-3-ethernet.c - (real_get_best_connection): handle specific_object argument * src/NetworkManager.c src/NetworkManagerMain.h - Remove unused includes * src/nm-device-802-11-wireless.c src/nm-device-802-11-wireless.h - Convert the ap_list into a GSList from an NMAccessPointList - No need for caching the 'activation_ap' since this is now determined from the specific_object of the activation request, which is populated from the get_best_connection() call or from a user request - (nm_device_802_11_wireless_update_bssid): fix warning - (get_wireless_capabilities): fix error message format arguments - (nm_device_802_11_wireless_copy_allowed_to_dev_list): remove, unused - (find_best_connection, real_get_best_connection): implement - (ap_list_get_ap_by_ssid, nm_device_802_11_wireless_ap_list_print): move here from NetworkManagerAPList - (ap_need_secrets): remove; moved to nm-connection.c where it belongs - (real_act_stage1_prepare): just ensure an AP exists, connection is already verified earlier - (real_act_stage2_config): use nm_connection_need_secrets() * src/NetworkManagerPolicy.c - (nm_policy_auto_get_best_device): handle specific objects - (create_connection): remove; automatic connection creation functionality is handled by the Connection objects - (nm_policy_device_change_check): handle specific_object * libnm-util/nm-connection.c - (wireless_sec_need_secrets, nm_connection_need_secrets): implement git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2778 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-09-10 19:11:40 +00:00
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
priv = NM_CONNECTION_GET_PRIVATE (connection);
g_hash_table_foreach (priv->settings, need_secrets_check, &info);
// FIXME: do something with requested secrets rather than asking for
// all of them. Maybe make info.secrets a hash table mapping
// settings name :: [list of secrets key names].
if (info.secrets) {
g_ptr_array_free (info.secrets, TRUE);
return info.setting_name;
2007-09-10 Dan Williams <dcbw@redhat.com> * include/NetworkManager.h - Kill NMNetworkType; AP types don't matter any more * src/NetworkManagerAPList.c src/NetworkManagerAPList.h src/Makefile.am - Kill; NMAccessPointList has outlived it's usefulness * src/NetworkManagerAP.c src/NetworkManagerAP.h - (match_cipher, security_compatible, nm_ap_check_compatible): new functions; check if an NMConnection object is compatible with the settings of this AP - (freq_to_channel, channel_to_freq): utility functions for channel <-> frequency conversion * src/nm-device.c src/nm-device.h - (nm_device_get_best_connection): pass the specific object around (which might be the object path of a specific AP to connect to). The get_best_connection() call should populate this on return if needed (wireless does). * src/nm-device-802-3-ethernet.c - (real_get_best_connection): handle specific_object argument * src/NetworkManager.c src/NetworkManagerMain.h - Remove unused includes * src/nm-device-802-11-wireless.c src/nm-device-802-11-wireless.h - Convert the ap_list into a GSList from an NMAccessPointList - No need for caching the 'activation_ap' since this is now determined from the specific_object of the activation request, which is populated from the get_best_connection() call or from a user request - (nm_device_802_11_wireless_update_bssid): fix warning - (get_wireless_capabilities): fix error message format arguments - (nm_device_802_11_wireless_copy_allowed_to_dev_list): remove, unused - (find_best_connection, real_get_best_connection): implement - (ap_list_get_ap_by_ssid, nm_device_802_11_wireless_ap_list_print): move here from NetworkManagerAPList - (ap_need_secrets): remove; moved to nm-connection.c where it belongs - (real_act_stage1_prepare): just ensure an AP exists, connection is already verified earlier - (real_act_stage2_config): use nm_connection_need_secrets() * src/NetworkManagerPolicy.c - (nm_policy_auto_get_best_device): handle specific objects - (create_connection): remove; automatic connection creation functionality is handled by the Connection objects - (nm_policy_device_change_check): handle specific_object * libnm-util/nm-connection.c - (wireless_sec_need_secrets, nm_connection_need_secrets): implement git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2778 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-09-10 19:11:40 +00:00
}
return NULL;
2007-08-28 Dan Williams <dcbw@redhat.com> Remove NMAPSecurity objects, they are replaced with flags on the APs for each AP's capabilities, and by NMConnection/NMSettings objects for user defined connections. * include/NetworkManager.h - Redefine 802.11 security properties. There are now device capabilities and AP flags and AP security flags. It was way to unclear before. * src/Makefile.am src/nm-ap-security-leap.h src/nm-ap-security-leap.c src/nm-ap-security-wpa-eap.c src/nm-ap-security-wpa-eap.h src/nm-ap-security-private.h src/nm-ap-security-wpa-psk.c src/nm-ap-security-wpa-psk.h src/nm-ap-security-wep.c src/nm-ap-security-wep.h src/nm-ap-security.c src/nm-ap-security.h - Removed, to be replaced with NMConnection/NMSettings objects * src/nm-dbus-nmi.c src/nm-dbus-nmi.h - Removed, to be replaced by code that talks to the new info daemon interface and gets NMConnection/NMSettings objects * src/backends/NetworkManagerSuSE.c - Remove usage of NMAPSecurity; should be replaced by a system-level info-daemon that does the same thing but talks the new info-daemon D-Bus interface * src/NetworkManagerAP.h src/NetworkManagerAP.c src/NetworkManagerAPList.c libnm-glib/libnm-glib-test.c - Remove usage of NMAPSecurity objects and adjust to new flags for WPA/RSN * libnm-glib/nm-access-point.c libnm-glib/nm-access-point.h introspection/nm-access-point.xml test/nm-tool.c - Adjust to new flags for AP security * utils/nm-utils.c utils/nm-utils.h src/vpn-manager/nm-dbus-vpn.c - Remove D-Bus pending call stuff from nm-utils and put it in the VPN stuff which is the only place it's used * src/nm-device-interface.c src/nm-device-interface.h introspection/nm-device.xml src/nm-activation-request.c src/nm-activation-request.h src/nm-device.c - Add a new 'specific_object' argument that hints to NM what actual AP or other device-specific thing the connection should apply to. NMConnection objects can apply to more than one actual device/AP. * libnm-util/nm-connection.c * libnm-util/nm-connection.h - Add 'have_secrets" call stubs * libnm-util/cipher.h - Move NM_AUTH_TYPE_* defines here for now * src/nm-device-802-11-wireless.c - Remove usage of NMAPSecurity, to be replaced with NMConnection/ NMSettings objects * src/NetworkManagerDbus.c * src/NetworkManagerPolicy.c - Remove usage of update_allowed_networks, should be pushing data in a different manner git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2738 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-08-28 14:47:31 +00:00
}
static void
add_one_setting_to_hash (gpointer key, gpointer data, gpointer user_data)
{
NMSetting *setting = (NMSetting *) data;
GHashTable *connection_hash = (GHashTable *) user_data;
GHashTable *setting_hash;
g_return_if_fail (setting != NULL);
g_return_if_fail (connection_hash != NULL);
setting_hash = nm_setting_to_hash (setting);
if (setting_hash)
g_hash_table_insert (connection_hash,
g_strdup (setting->name),
setting_hash);
}
GHashTable *
nm_connection_to_hash (NMConnection *connection)
{
NMConnectionPrivate *priv;
GHashTable *connection_hash;
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
connection_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) g_free,
(GDestroyNotify) g_hash_table_destroy);
priv = NM_CONNECTION_GET_PRIVATE (connection);
g_hash_table_foreach (priv->settings, add_one_setting_to_hash, connection_hash);
/* Don't send empty hashes */
if (g_hash_table_size (connection_hash) < 1) {
g_hash_table_destroy (connection_hash);
connection_hash = NULL;
}
return connection_hash;
}
static char *
gvalue_to_string (GValue *val)
{
char *ret;
GType type;
GString *str;
gboolean need_comma = FALSE;
type = G_VALUE_TYPE (val);
switch (type) {
case G_TYPE_STRING:
ret = g_strdup (g_value_get_string (val));
break;
case G_TYPE_INT:
ret = g_strdup_printf ("%d", g_value_get_int (val));
break;
case G_TYPE_UINT:
ret = g_strdup_printf ("%u", g_value_get_uint (val));
break;
case G_TYPE_BOOLEAN:
ret = g_strdup_printf ("%s", g_value_get_boolean (val) ? "True" : "False");
break;
case G_TYPE_UCHAR:
ret = g_strdup_printf ("%d", g_value_get_uchar (val));
break;
default:
/* These return dynamic values and thus can't be 'case's */
if (type == DBUS_TYPE_G_UCHAR_ARRAY)
2007-09-12 Tambet Ingo <tambet@gmail.com> * src/vpn-manager/nm-vpn-connection.[ch]: * src/vpn-manager/nm-vpn-manager.[ch]: * src/vpn-manager/nm-vpn-service.[ch]: Rewrite the vpn handling * code. Using dbus-glib, GObjects, signals etc. * libnm-glib/nm-vpn-manager.[ch]: * libnm-glib/nm-vpn-connection.[ch]: Now that the NM * implementation changed so much, rewrite these too. * libnm-glib/Makefile.am: Add new files to build, build new * binding files for the new introspection files. * libnm-glib/nm-client.[ch]: Remove all VPN related stuff from * here. * libnm-glib/nm-dbus-utils.[ch]: Renamed from nm-utils.[ch] that * was shadowing the header with the same name from libnm-utils. * libnm-glib/nm-vpn-plugin.[ch]: Implement. * libnm-util/Makefile.am: Add nm-utils.[ch] to build. * introspection/nm-vpn-plugin.xml: Implement. * introspection/nm-vpn-connection.xml: Implement. * introspection/nm-vpn-manager.xml: Implement. * src/NetworkManagerSystem.c * (nm_system_vpn_device_set_from_ip4_config): Remove the named manager argument, it can just as easily get it as the caller. (nm_system_vpn_device_unset_from_ip4_config): Ditto. * src/vpn-manager/nm-dbus-vpn.[ch]: Remove. * src/nm-dbus-manager.h: Fix up the name_owner signal signature. * src/dhcp-manager/nm-dhcp-manager.c (garray_to_string): Remove, * use one from libnm-utils. * libnm-util/nm-connection.c: Ditto. * src/NetworkManagerMain.h: Remove, it's finally empty. * configure.in: Remove utils/ from build. * include/NetworkManagerVPN.h: Add some more defines to reduce * the amount of hard-coded strings. * utils/: Move it over to libnm-util. * test/Makefile.am: Link against libnm-util now that util/ is * gone. * dispatcher-daemon/Makefile.am: Ditto. * src/Makefile.am: Ditto. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2798 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-09-12 16:23:53 +00:00
ret = nm_utils_garray_to_string ((GArray *) g_value_get_boxed (val));
else if (type == dbus_g_type_get_collection ("GSList", G_TYPE_STRING)) {
GSList *iter;
str = g_string_new ("[");
for (iter = g_value_get_boxed (val); iter; iter = iter->next) {
if (need_comma)
g_string_append (str, ", ");
else
need_comma = TRUE;
g_string_append (str, (char *) iter->data);
}
g_string_append (str, "]");
ret = g_string_free (str, FALSE);
} else if (type == dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_UCHAR_ARRAY)) {
/* Array of arrays of chars, like wireless seen-bssids for example */
int i;
GPtrArray *ptr_array;
str = g_string_new ("[");
ptr_array = (GPtrArray *) g_value_get_boxed (val);
for (i = 0; i < ptr_array->len; i++) {
2007-09-12 Tambet Ingo <tambet@gmail.com> * src/vpn-manager/nm-vpn-connection.[ch]: * src/vpn-manager/nm-vpn-manager.[ch]: * src/vpn-manager/nm-vpn-service.[ch]: Rewrite the vpn handling * code. Using dbus-glib, GObjects, signals etc. * libnm-glib/nm-vpn-manager.[ch]: * libnm-glib/nm-vpn-connection.[ch]: Now that the NM * implementation changed so much, rewrite these too. * libnm-glib/Makefile.am: Add new files to build, build new * binding files for the new introspection files. * libnm-glib/nm-client.[ch]: Remove all VPN related stuff from * here. * libnm-glib/nm-dbus-utils.[ch]: Renamed from nm-utils.[ch] that * was shadowing the header with the same name from libnm-utils. * libnm-glib/nm-vpn-plugin.[ch]: Implement. * libnm-util/Makefile.am: Add nm-utils.[ch] to build. * introspection/nm-vpn-plugin.xml: Implement. * introspection/nm-vpn-connection.xml: Implement. * introspection/nm-vpn-manager.xml: Implement. * src/NetworkManagerSystem.c * (nm_system_vpn_device_set_from_ip4_config): Remove the named manager argument, it can just as easily get it as the caller. (nm_system_vpn_device_unset_from_ip4_config): Ditto. * src/vpn-manager/nm-dbus-vpn.[ch]: Remove. * src/nm-dbus-manager.h: Fix up the name_owner signal signature. * src/dhcp-manager/nm-dhcp-manager.c (garray_to_string): Remove, * use one from libnm-utils. * libnm-util/nm-connection.c: Ditto. * src/NetworkManagerMain.h: Remove, it's finally empty. * configure.in: Remove utils/ from build. * include/NetworkManagerVPN.h: Add some more defines to reduce * the amount of hard-coded strings. * utils/: Move it over to libnm-util. * test/Makefile.am: Link against libnm-util now that util/ is * gone. * dispatcher-daemon/Makefile.am: Ditto. * src/Makefile.am: Ditto. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2798 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-09-12 16:23:53 +00:00
ret = nm_utils_garray_to_string ((GArray *) g_ptr_array_index (ptr_array, i));
if (need_comma)
g_string_append (str, ", ");
else
need_comma = TRUE;
g_string_append (str, ret);
g_free (ret);
}
g_string_append (str, "]");
ret = g_string_free (str, FALSE);
} else
ret = g_strdup_printf ("Value with type %s", g_type_name (type));
}
return ret;
}
static void
dump_setting_member (gpointer key, gpointer value, gpointer user_data)
{
char *val_as_str;
val_as_str = gvalue_to_string ((GValue *) value);
g_message ("\t%s : '%s'", (char *) key, val_as_str ? val_as_str : "(null)");
g_free (val_as_str);
}
static void
dump_setting (gpointer key, gpointer value, gpointer user_data)
{
g_message ("Setting '%s'", (char *) key);
g_hash_table_foreach ((GHashTable *) value, dump_setting_member, NULL);
g_message ("-------------------");
}
void
nm_connection_dump (NMConnection *connection)
{
GHashTable *hash;
g_return_if_fail (NM_IS_CONNECTION (connection));
/* Convert the connection to hash so that we can introspect it */
hash = nm_connection_to_hash (connection);
g_hash_table_foreach (hash, dump_setting, NULL);
g_hash_table_destroy (hash);
}
NMConnection *
nm_connection_new (void)
{
GObject *object;
if (!registered_setting_creators)
register_default_creators ();
object = g_object_new (NM_TYPE_CONNECTION, NULL);
return NM_CONNECTION (object);
}
NMConnection *
nm_connection_new_from_hash (GHashTable *hash)
{
NMConnection *connection;
NMConnectionPrivate *priv;
g_return_val_if_fail (hash != NULL, NULL);
connection = nm_connection_new ();
g_hash_table_foreach (hash, parse_one_setting, connection);
priv = NM_CONNECTION_GET_PRIVATE (connection);
if (g_hash_table_size (priv->settings) < 1) {
g_warning ("No settings found.");
g_object_unref (connection);
return NULL;
}
if (!nm_settings_verify (priv->settings)) {
g_object_unref (connection);
return NULL;
}
return connection;
}
static void
nm_connection_init (NMConnection *connection)
{
NMConnectionPrivate *priv = NM_CONNECTION_GET_PRIVATE (connection);
priv->settings = g_hash_table_new (g_str_hash, g_str_equal);
}
static void
finalize (GObject *object)
{
NMConnection *connection = NM_CONNECTION (object);
NMConnectionPrivate *priv = NM_CONNECTION_GET_PRIVATE (connection);
g_hash_table_destroy (priv->settings);
priv->settings = NULL;
G_OBJECT_CLASS (nm_connection_parent_class)->finalize (object);
}
static void
nm_connection_class_init (NMConnectionClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (NMConnectionPrivate));
/* virtual methods */
object_class->finalize = finalize;
2007-09-11 Dan Williams <dcbw@redhat.com> * libnm-util/nm-setting.c libnm-util/nm-setting.h - (nm_setting_update_secrets): new function; add a virtual function that subclasses can implement to update their secrets - (setting_wireless_security_update_secrets): implement that function for the 802-11-wireless-security subclass * libnm-util/nm-connection.c libnm-util/nm-connection.h - (nm_connection_update_secrets): update secrets for a Setting and emit a signal on success * src/nm-manager.c src/nm-manager.h src/nm-marshal.list - (connection_get_settings_cb): enable system settings bits - (nm_manager_get_connection_secrets, get_secrets_cb): add function to request secrets from the settings dbus service and to push those secrets to the NMConnection itself * src/nm-activation-request.c src/nm-activation-request.h - Attach to the 'secrets-updated' signal of the NMConnection that's currently being activated, and proxy that signal to other listeners. Goes through the activation request because the activation request is the thing that manages the lifetime of the NMConnection that's being activated. * src/nm-device-802-11-wireless.c - (real_connection_secrets_updated): implement the connection secrets updated notification and restart activation when secrets are received - (real_act_stage2_config): request secrets from the settings dbus service if secrets are needed * src/nm-device.c src/nm-device.h - (clear_act_request, nm_device_activation_cancel, nm_device_deactivate_quickly, nm_device_dispose): consolidate places where the activation request is cleared - (nm_device_activate, connection_secrets_updated_cb): attach to the updated secrets signal of activation request and add a function that subclasses can override to handle it easily git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2782 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-09-11 18:02:27 +00:00
/* Signals */
signals[SECRETS_UPDATED] =
g_signal_new ("secrets-updated",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMConnectionClass, secrets_updated),
NULL, NULL,
g_cclosure_marshal_VOID__STRING,
G_TYPE_NONE, 1,
G_TYPE_STRING);
}