2007-09-20 Tambet Ingo <tambet@gmail.com>

* libnm-util/nm-connection.c (register_default_creators): Use
        * defined
        setting names. Register NMSettingVPN and NMSettingVPNProperties.

        * libnm-util/nm-setting.c: Define property name strings, use
        * them.
        Implement NMSettingVPN and NMSettingVPNProperties settings.
        Implement NM_S_TYPE_GVALUE_HASH.
        (nm_setting_populate_from_hash): Handle NM_S_TYPE_GVALUE_HASH.
        (setting_connection_verify): Rename 'devtype' property to
'type'.

        * introspection/nm-vpn-manager.xml: Use NMConnection for VPN
        * service
        properties.

        * src/vpn-manager/nm-vpn-service.c: Ditto.

        * src/vpn-manager/nm-vpn-connection.c: Ditto.

        * src/vpn-manager/nm-vpn-manager.c (nm_vpn_manager_connect):
        * Ditto.
        (nm_vpn_manager_new): Remove NMManager argument, it's easy
enough to get.

        * src/nm-device-802-11-wireless.c (find_best_connection): Use
        * defined setting
        names. NMSettingConnection->devtype got renamed to 'type'.

        * src/nm-device-802-3-ethernet.c (find_best_connection):
        (real_get_best_connection): Ditto.

        * src/NetworkManager.c (main): Update the vpn manager creation
        * arguments.

        * libnm-glib/nm-vpn-manager.[ch]: Update.



git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2826 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Tambet Ingo 2007-09-20 06:47:15 +00:00
parent d92897393e
commit 6746319495
16 changed files with 402 additions and 209 deletions

View file

@ -1,3 +1,34 @@
2007-09-20 Tambet Ingo <tambet@gmail.com>
* libnm-util/nm-connection.c (register_default_creators): Use defined
setting names. Register NMSettingVPN and NMSettingVPNProperties.
* libnm-util/nm-setting.c: Define property name strings, use them.
Implement NMSettingVPN and NMSettingVPNProperties settings.
Implement NM_S_TYPE_GVALUE_HASH.
(nm_setting_populate_from_hash): Handle NM_S_TYPE_GVALUE_HASH.
(setting_connection_verify): Rename 'devtype' property to 'type'.
* introspection/nm-vpn-manager.xml: Use NMConnection for VPN service
properties.
* src/vpn-manager/nm-vpn-service.c: Ditto.
* src/vpn-manager/nm-vpn-connection.c: Ditto.
* src/vpn-manager/nm-vpn-manager.c (nm_vpn_manager_connect): Ditto.
(nm_vpn_manager_new): Remove NMManager argument, it's easy enough to get.
* src/nm-device-802-11-wireless.c (find_best_connection): Use defined setting
names. NMSettingConnection->devtype got renamed to 'type'.
* src/nm-device-802-3-ethernet.c (find_best_connection):
(real_get_best_connection): Ditto.
* src/NetworkManager.c (main): Update the vpn manager creation arguments.
* libnm-glib/nm-vpn-manager.[ch]: Update.
2007-09-19 Dan Williams <dcbw@redhat.com>
* src/NetworkManagerAP.c

View file

@ -4,12 +4,10 @@
<interface name="org.freedesktop.NetworkManager.VPN.Manager">
<method name="Connect">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_vpn_manager_connect"/>
<arg name="type" type="s" direction="in"/>
<arg name="name" type="s" direction="in"/>
<arg name="properties" type="a{sv}" direction="in"/>
<arg name="connection_type" type="s" direction="in"/>
<arg name="connection" type="o" direction="in"/>
<arg name="device" type="o" direction="in"/>
<arg name="routes" type="as" direction="in"/>
<arg name="connection" type="o" direction="out"/>
<arg name="vpn_connection" type="o" direction="out"/>
</method>
<method name="ListConnections">

View file

@ -37,49 +37,30 @@ nm_vpn_manager_new (void)
NMVPNConnection *
nm_vpn_manager_connect (NMVPNManager *manager,
const char *type,
const char *name,
GHashTable *properties,
NMDevice *device,
GSList *routes)
const char *connection_type,
const char *connection_path,
NMDevice *device)
{
char *connection_path = NULL;
char *vpn_connection = NULL;
GError *err = NULL;
char **routes_array = NULL;
GSList *elt;
int i, size;
g_return_val_if_fail (NM_IS_VPN_MANAGER (manager), NULL);
g_return_val_if_fail (type != NULL, NULL);
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (properties != NULL, NULL);
g_return_val_if_fail (connection_type != NULL, NULL);
g_return_val_if_fail (connection_path, NULL);
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
size = sizeof (char *) * (g_slist_length (routes) + 1);
routes_array = g_slice_alloc0 (size);
if (!routes_array) {
g_warning ("Couldn't allocate string list.");
return NULL;
}
for (elt = routes, i = 0; elt; elt = g_slist_next (elt))
routes_array[i++] = elt->data;
if (!org_freedesktop_NetworkManager_VPN_Manager_connect (NM_VPN_MANAGER_GET_PRIVATE (manager)->manager_proxy,
type, name,
properties,
connection_type,
connection_path,
nm_object_get_path (NM_OBJECT (device)),
(const char **) routes_array,
&connection_path,
&vpn_connection,
&err)) {
g_warning ("Error in VPN Connect: %s", err->message);
g_error_free (err);
g_slice_free1 (size, routes_array);
return NULL;
}
g_slice_free1 (size, routes_array);
return nm_vpn_connection_new (nm_object_get_connection (NM_OBJECT (manager)), connection_path);
return nm_vpn_connection_new (nm_object_get_connection (NM_OBJECT (manager)), vpn_connection);
}
GSList *

View file

@ -10,6 +10,7 @@
#include <NetworkManagerVPN.h>
#include "nm-object.h"
#include "nm-device.h"
#include "nm-connection.h"
#include "nm-vpn-connection.h"
G_BEGIN_DECLS
@ -34,11 +35,9 @@ GType nm_vpn_manager_get_type (void);
NMVPNManager *nm_vpn_manager_new (void);
NMVPNConnection *nm_vpn_manager_connect (NMVPNManager *manager,
const char *type,
const char *name,
GHashTable *properties,
NMDevice *device,
GSList *routes);
const char *connection_type,
const char *connection_path,
NMDevice *device);
GSList *nm_vpn_manager_get_connections (NMVPNManager *manager);

View file

@ -30,12 +30,14 @@ register_default_creators (void)
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 },
{ NM_SETTING_CONNECTION, nm_setting_connection_new_from_hash },
{ NM_SETTING_WIRED, nm_setting_wired_new_from_hash },
{ NM_SETTING_WIRELESS, nm_setting_wireless_new_from_hash },
{ NM_SETTING_IP4_CONFIG, nm_setting_ip4_config_new_from_hash },
{ NM_SETTING_WIRELESS_SECURITY, nm_setting_wireless_security_new_from_hash },
{ NM_SETTING_PPP, nm_setting_ppp_new_from_hash },
{ NM_SETTING_VPN, nm_setting_vpn_new_from_hash },
{ NM_SETTING_VPN_PROPERTIES, nm_setting_vpn_properties_new_from_hash },
{ NULL, NULL}
};

View file

@ -5,6 +5,7 @@
#include <string.h>
#include "nm-setting.h"
#include "nm-utils.h"
static GHashTable * nm_setting_hash (NMSetting *setting);
@ -282,6 +283,12 @@ nm_setting_populate_from_hash (NMSetting *setting, GHashTable *table)
while (m->key) {
GValue *value;
if (m->type == NM_S_TYPE_GVALUE_HASH) {
GHashTable **val = (GHashTable **) G_STRUCT_MEMBER_P (setting, m->offset);
*val = nm_utils_gvalue_hash_dup (table);
break;
}
value = (GValue *) g_hash_table_lookup (table, m->key);
if (!value && m->required) {
g_warning ("Missing required value '%s'.", m->key);
@ -305,7 +312,7 @@ nm_setting_populate_from_hash (NMSetting *setting, GHashTable *table)
} else if ((m->type == NM_S_TYPE_STRING_ARRAY) && G_VALUE_HOLDS_BOXED (value)) {
GSList **val = (GSList **) G_STRUCT_MEMBER_P (setting, m->offset);
*val = convert_strv_to_slist ((char **) g_value_get_boxed (value));
}
}
next:
m++;
@ -366,8 +373,8 @@ setting_connection_verify (NMSetting *setting, GHashTable *all_settings)
{
NMSettingConnection *self = (NMSettingConnection *) setting;
/* Make sure the corresponding 'devtype' item is present */
if (!g_hash_table_lookup (all_settings, self->devtype))
/* Make sure the corresponding 'type' item is present */
if (!g_hash_table_lookup (all_settings, self->type))
return FALSE;
return TRUE;
@ -379,14 +386,14 @@ setting_connection_destroy (NMSetting *setting)
NMSettingConnection *self = (NMSettingConnection *) setting;
g_free (self->name);
g_free (self->devtype);
g_free (self->type);
g_slice_free (NMSettingConnection, self);
}
static SettingMember con_table[] = {
{ "name", NM_S_TYPE_STRING, G_STRUCT_OFFSET (NMSettingConnection, name), TRUE, FALSE },
{ "devtype", NM_S_TYPE_STRING, G_STRUCT_OFFSET (NMSettingConnection, devtype), TRUE, FALSE },
{ "type", NM_S_TYPE_STRING, G_STRUCT_OFFSET (NMSettingConnection, type), TRUE, FALSE },
{ "autoconnect", NM_S_TYPE_BOOL, G_STRUCT_OFFSET (NMSettingConnection, autoconnect), FALSE, FALSE },
{ NULL, 0, 0 },
};
@ -398,7 +405,7 @@ nm_setting_connection_new (void)
setting = (NMSetting *) g_slice_new0 (NMSettingConnection);
setting->name = g_strdup ("connection");
setting->name = g_strdup (NM_SETTING_CONNECTION);
setting->_members = con_table;
setting->verify_fn = setting_connection_verify;
setting->hash_fn = default_setting_hash;
@ -408,17 +415,14 @@ nm_setting_connection_new (void)
}
NMSetting *
nm_setting_connection_new_from_hash (GHashTable *settings)
nm_setting_connection_new_from_hash (GHashTable *hash)
{
NMSettingConnection *self;
NMSetting *setting;
g_return_val_if_fail (settings != NULL, NULL);
g_return_val_if_fail (hash != NULL, NULL);
setting = nm_setting_connection_new ();
self = (NMSettingConnection *) setting;
if (!nm_setting_populate_from_hash (setting, settings)) {
if (!nm_setting_populate_from_hash (setting, hash)) {
setting_connection_destroy (setting);
return NULL;
}
@ -469,7 +473,7 @@ nm_setting_ip4_config_new (void)
setting = (NMSetting *) g_slice_new0 (NMSettingIP4Config);
setting->name = g_strdup ("ipv4");
setting->name = g_strdup (NM_SETTING_IP4_CONFIG);
setting->_members = ip4_config_table;
setting->verify_fn = setting_ip4_config_verify;
setting->hash_fn = default_setting_hash;
@ -479,18 +483,14 @@ nm_setting_ip4_config_new (void)
}
NMSetting *
nm_setting_ip4_config_new_from_hash (GHashTable *settings)
nm_setting_ip4_config_new_from_hash (GHashTable *hash)
{
NMSettingIP4Config*self;
NMSetting *setting;
GValue *value;
g_return_val_if_fail (settings != NULL, NULL);
g_return_val_if_fail (hash != NULL, NULL);
setting = nm_setting_ip4_config_new ();
self = (NMSettingIP4Config *) setting;
if (!nm_setting_populate_from_hash (setting, settings)) {
if (!nm_setting_populate_from_hash (setting, hash)) {
setting_connection_destroy (setting);
return NULL;
}
@ -558,7 +558,7 @@ nm_setting_wired_new (void)
s_wired = g_slice_new0 (NMSettingWired);
setting = (NMSetting *) s_wired;
setting->name = g_strdup ("802-3-ethernet");
setting->name = g_strdup (NM_SETTING_WIRED);
setting->_members = wired_table;
setting->verify_fn = setting_wired_verify;
setting->hash_fn = default_setting_hash;
@ -570,17 +570,14 @@ nm_setting_wired_new (void)
}
NMSetting *
nm_setting_wired_new_from_hash (GHashTable *settings)
nm_setting_wired_new_from_hash (GHashTable *hash)
{
NMSettingWired *self;
NMSetting *setting;
g_return_val_if_fail (settings != NULL, NULL);
g_return_val_if_fail (hash != NULL, NULL);
setting = nm_setting_wired_new ();
self = (NMSettingWired *) setting;
if (!nm_setting_populate_from_hash (setting, settings)) {
if (!nm_setting_populate_from_hash (setting, hash)) {
setting_connection_destroy (setting);
return NULL;
}
@ -713,7 +710,7 @@ nm_setting_wireless_new (void)
setting = (NMSetting *) g_slice_new0 (NMSettingWireless);
setting->name = g_strdup ("802-11-wireless");
setting->name = g_strdup (NM_SETTING_WIRELESS);
setting->_members = wireless_table;
setting->verify_fn = setting_wireless_verify;
setting->hash_fn = default_setting_hash;
@ -723,17 +720,14 @@ nm_setting_wireless_new (void)
}
NMSetting *
nm_setting_wireless_new_from_hash (GHashTable *settings)
nm_setting_wireless_new_from_hash (GHashTable *hash)
{
NMSettingWireless *self;
NMSetting *setting;
g_return_val_if_fail (settings != NULL, NULL);
g_return_val_if_fail (hash != NULL, NULL);
setting = nm_setting_wireless_new ();
self = (NMSettingWireless *) setting;
if (!nm_setting_populate_from_hash (setting, settings)) {
if (!nm_setting_populate_from_hash (setting, hash)) {
setting_connection_destroy (setting);
return NULL;
}
@ -1056,7 +1050,7 @@ nm_setting_wireless_security_new (void)
setting = (NMSetting *) g_slice_new0 (NMSettingWirelessSecurity);
setting->name = g_strdup ("802-11-wireless-security");
setting->name = g_strdup (NM_SETTING_WIRELESS_SECURITY);
setting->_members = wireless_sec_table;
setting->verify_fn = setting_wireless_security_verify;
setting->hash_fn = default_setting_hash;
@ -1068,17 +1062,14 @@ nm_setting_wireless_security_new (void)
}
NMSetting *
nm_setting_wireless_security_new_from_hash (GHashTable *settings)
nm_setting_wireless_security_new_from_hash (GHashTable *hash)
{
NMSettingWirelessSecurity *self;
NMSetting *setting;
g_return_val_if_fail (settings != NULL, NULL);
g_return_val_if_fail (hash != NULL, NULL);
setting = nm_setting_wireless_security_new ();
self = (NMSettingWirelessSecurity *) setting;
if (!nm_setting_populate_from_hash (setting, settings)) {
if (!nm_setting_populate_from_hash (setting, hash)) {
setting_connection_destroy (setting);
return NULL;
}
@ -1131,7 +1122,7 @@ nm_setting_ppp_new (void)
setting = (NMSetting *) g_slice_new0 (NMSettingPPP);
setting->name = g_strdup ("ppp");
setting->name = g_strdup (NM_SETTING_PPP);
setting->_members = ppp_table;
setting->verify_fn = setting_ppp_verify;
setting->hash_fn = default_setting_hash;
@ -1141,21 +1132,149 @@ nm_setting_ppp_new (void)
}
NMSetting *
nm_setting_ppp_new_from_hash (GHashTable *settings)
nm_setting_ppp_new_from_hash (GHashTable *hash)
{
NMSettingPPP *self;
NMSetting *setting;
GValue *value;
g_return_val_if_fail (settings != NULL, NULL);
g_return_val_if_fail (hash != NULL, NULL);
setting = nm_setting_ppp_new ();
self = (NMSettingPPP *) setting;
if (!nm_setting_populate_from_hash (setting, settings)) {
if (!nm_setting_populate_from_hash (setting, hash)) {
setting_connection_destroy (setting);
return NULL;
}
return setting;
}
/* vpn setting */
static gboolean
setting_vpn_verify (NMSetting *setting, GHashTable *all_settings)
{
NMSettingVPN *self = (NMSettingVPN *) setting;
if (!self->service_type)
return FALSE;
return TRUE;
}
static void
setting_vpn_destroy (NMSetting *setting)
{
NMSettingVPN *self = (NMSettingVPN *) setting;
g_free (self->service_type);
g_slice_free (NMSettingVPN, self);
}
static SettingMember vpn_table[] = {
{ "service_type", NM_S_TYPE_STRING, G_STRUCT_OFFSET (NMSettingVPN, service_type), TRUE, FALSE },
{ "routes", NM_S_TYPE_STRING_ARRAY, G_STRUCT_OFFSET (NMSettingVPN, routes), FALSE, FALSE },
{ NULL, 0, 0 },
};
NMSetting *
nm_setting_vpn_new (void)
{
NMSetting *setting;
setting = (NMSetting *) g_slice_new0 (NMSettingVPN);
setting->name = g_strdup (NM_SETTING_VPN);
setting->_members = vpn_table;
setting->verify_fn = setting_vpn_verify;
setting->hash_fn = default_setting_hash;
setting->destroy_fn = setting_vpn_destroy;
return setting;
}
NMSetting *
nm_setting_vpn_new_from_hash (GHashTable *hash)
{
NMSetting *setting;
g_return_val_if_fail (hash != NULL, NULL);
setting = nm_setting_vpn_new ();
if (!nm_setting_populate_from_hash (setting, hash)) {
setting_vpn_destroy (setting);
return NULL;
}
return setting;
}
/* vpn-properties setting */
static gboolean
setting_vpn_properties_verify (NMSetting *setting, GHashTable *all_settings)
{
NMSettingVPNProperties *self = (NMSettingVPNProperties *) setting;
if (!self->data)
return FALSE;
/* FIXME: actually check the data as well */
return TRUE;
}
static GHashTable *
setting_vpn_properties_hash (NMSetting *setting)
{
NMSettingVPNProperties *self = (NMSettingVPNProperties *) setting;
g_return_val_if_fail (self->data != NULL, NULL);
return nm_utils_gvalue_hash_dup (self->data);
}
static void
setting_vpn_properties_destroy (NMSetting *setting)
{
NMSettingVPNProperties *self = (NMSettingVPNProperties *) setting;
g_hash_table_destroy (self->data);
g_slice_free (NMSettingVPNProperties, self);
}
static SettingMember vpn_properties_table[] = {
{ "data", NM_S_TYPE_GVALUE_HASH, G_STRUCT_OFFSET (NMSettingVPNProperties, data), TRUE, FALSE },
{ NULL, 0, 0 },
};
NMSetting *
nm_setting_vpn_properties_new (void)
{
NMSetting *setting;
setting = (NMSetting *) g_slice_new0 (NMSettingVPNProperties);
setting->name = g_strdup (NM_SETTING_VPN_PROPERTIES);
setting->_members = vpn_properties_table;
setting->verify_fn = setting_vpn_properties_verify;
setting->hash_fn = setting_vpn_properties_hash;
setting->destroy_fn = setting_vpn_properties_destroy;
return setting;
}
NMSetting *
nm_setting_vpn_properties_new_from_hash (GHashTable *hash)
{
NMSetting *setting;
g_return_val_if_fail (hash != NULL, NULL);
setting = nm_setting_vpn_properties_new ();
if (!nm_setting_populate_from_hash (setting, hash)) {
setting_vpn_destroy (setting);
return NULL;
}
return setting;
}

View file

@ -34,6 +34,7 @@ typedef void (*NMSettingValueIterFn) (NMSetting *setting,
#define NM_S_TYPE_BOOL 3
#define NM_S_TYPE_BYTE_ARRAY 4
#define NM_S_TYPE_STRING_ARRAY 5
#define NM_S_TYPE_GVALUE_HASH 6
typedef struct SettingMember {
const char *key;
@ -67,11 +68,13 @@ void nm_setting_enumerate_values (NMSetting *setting,
/* Connection */
#define NM_SETTING_CONNECTION "connection"
typedef struct {
NMSetting parent;
char *name;
char *devtype;
char *type;
gboolean autoconnect;
} NMSettingConnection;
@ -80,6 +83,8 @@ NMSetting *nm_setting_connection_new_from_hash (GHashTable *settings);
/* IP4 config */
#define NM_SETTING_IP4_CONFIG "ipv4"
typedef struct {
NMSetting parent;
@ -94,6 +99,8 @@ NMSetting *nm_setting_ip4_config_new_from_hash (GHashTable *settings);
/* Wired device */
#define NM_SETTING_WIRED "802-3-ethernet"
typedef struct {
NMSetting parent;
@ -110,6 +117,8 @@ NMSetting *nm_setting_wired_new_from_hash (GHashTable *settings);
/* Wireless device */
#define NM_SETTING_WIRELESS "802-11-wireless"
typedef struct {
NMSetting parent;
@ -131,6 +140,8 @@ NMSetting *nm_setting_wireless_new_from_hash (GHashTable *settings);
/* Wireless security */
#define NM_SETTING_WIRELESS_SECURITY "802-11-wireless-security"
typedef struct {
NMSetting parent;
@ -174,6 +185,8 @@ NMSetting *nm_setting_wireless_security_new_from_hash (GHashTable *settings);
/* PPP */
#define NM_SETTING_PPP "ppp"
typedef struct {
NMSetting parent;
@ -200,6 +213,33 @@ typedef struct {
NMSetting *nm_setting_ppp_new (void);
NMSetting *nm_setting_ppp_new_from_hash (GHashTable *settings);
/* VPN */
#define NM_SETTING_VPN "vpn"
typedef struct {
NMSetting parent;
char *service_type;
char **routes;
} NMSettingVPN;
NMSetting *nm_setting_vpn_new (void);
NMSetting *nm_setting_vpn_new_from_hash (GHashTable *hash);
/* VPN properties */
#define NM_SETTING_VPN_PROPERTIES "vpn-properties"
typedef struct {
NMSetting parent;
GHashTable *data;
} NMSettingVPNProperties;
NMSetting *nm_setting_vpn_properties_new (void);
NMSetting *nm_setting_vpn_properties_new_from_hash (GHashTable *hash);
G_END_DECLS
#endif /* NM_SETTING_H */

View file

@ -342,7 +342,7 @@ main (int argc, char *argv[])
goto done;
}
vpn_manager = nm_vpn_manager_new (manager);
vpn_manager = nm_vpn_manager_new ();
if (!vpn_manager) {
nm_warning ("Failed to start the VPN manager.");
goto done;

View file

@ -668,16 +668,16 @@ find_best_connection (gpointer data, gpointer user_data)
if (info->found)
return;
s_con = (NMSettingConnection *) nm_connection_get_setting (connection, "connection");
s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_SETTING_CONNECTION);
if (s_con == NULL)
return;
fprintf (stderr, "%s: looking at connection %s\n", __func__, s_con->name);
if (strcmp (s_con->devtype, "802-11-wireless"))
if (strcmp (s_con->type, NM_SETTING_WIRELESS))
return;
if (!s_con->autoconnect)
return;
s_wireless = (NMSettingWireless *) nm_connection_get_setting (connection, "802-11-wireless");
s_wireless = (NMSettingWireless *) nm_connection_get_setting (connection, NM_SETTING_WIRELESS);
if (s_wireless == NULL)
return;

View file

@ -349,15 +349,15 @@ find_best_connection (gpointer data, gpointer user_data)
if (info->found)
return;
s_con = (NMSettingConnection *) nm_connection_get_setting (connection, "connection");
s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_SETTING_CONNECTION);
if (s_con == NULL)
return;
if (strcmp (s_con->devtype, "802-3-ethernet"))
if (strcmp (s_con->type, NM_SETTING_WIRED))
return;
if (!s_con->autoconnect)
return;
s_wired = (NMSettingWired *) nm_connection_get_setting (connection, "802-3-ethernet");
s_wired = (NMSettingWired *) nm_connection_get_setting (connection, NM_SETTING_WIRED);
if (s_wired == NULL)
return;
@ -413,7 +413,7 @@ real_get_best_connection (NMDevice *dev,
scon = (NMSettingConnection *) nm_setting_connection_new ();
scon->name = g_strdup ("Auto");
scon->devtype = g_strdup (setting->name);
scon->type = g_strdup (setting->name);
nm_connection_add_setting (connection, (NMSetting *) scon);
find_info.found = connection;

View file

@ -41,10 +41,7 @@ static gboolean impl_vpn_connection_disconnect (NMVPNConnection *connection, GEr
G_DEFINE_TYPE (NMVPNConnection, nm_vpn_connection, G_TYPE_OBJECT)
typedef struct {
char *name;
char *dbus_service;
GHashTable *properties;
char **routes;
NMConnection *connection;
NMDevice *parent_dev;
char *object_path;
@ -103,34 +100,57 @@ device_state_changed (NMDevice *device, NMDeviceState state, gpointer user_data)
}
NMVPNConnection *
nm_vpn_connection_new (const char *name,
const char *dbus_service,
NMDevice *parent_device,
GHashTable *properties,
char **routes)
nm_vpn_connection_new (NMConnection *connection,
NMDevice *parent_device)
{
NMVPNConnection *connection;
NMVPNConnection *vpn_connection;
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
g_return_val_if_fail (NM_IS_DEVICE (parent_device), NULL);
g_return_val_if_fail (properties != NULL, NULL);
connection = (NMVPNConnection *) g_object_new (NM_TYPE_VPN_CONNECTION, NULL);
if (connection) {
NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection);
vpn_connection = (NMVPNConnection *) g_object_new (NM_TYPE_VPN_CONNECTION, NULL);
if (vpn_connection) {
NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (vpn_connection);
priv->name = g_strdup (name);
priv->dbus_service = g_strdup (dbus_service);
priv->connection = connection;
priv->parent_dev = g_object_ref (parent_device);
priv->properties = properties;
priv->routes = routes;
priv->device_monitor = g_signal_connect (parent_device, "state-changed",
G_CALLBACK (device_state_changed),
connection);
vpn_connection);
}
return connection;
return vpn_connection;
}
static char *
nm_vpn_connection_get_service (NMVPNConnection *connection)
{
NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection);
NMSettingVPN *setting;
setting = (NMSettingVPN *) nm_connection_get_setting (priv->connection, NM_SETTING_VPN);
return setting->service_type;
}
static char **
nm_vpn_connection_get_routes (NMVPNConnection *connection)
{
NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection);
NMSettingVPN *setting;
setting = (NMSettingVPN *) nm_connection_get_setting (priv->connection, NM_SETTING_VPN);
return setting->routes;
}
static GHashTable *
nm_vpn_connection_get_vpn_data (NMVPNConnection *connection)
{
NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection);
NMSettingVPNProperties *setting;
setting = (NMSettingVPNProperties *) nm_connection_get_setting (priv->connection, NM_SETTING_VPN_PROPERTIES);
return setting->data;
}
static void
@ -280,7 +300,7 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy,
if (nm_system_vpn_device_set_from_ip4_config (priv->parent_dev,
priv->tundev,
priv->ip4_config,
priv->routes)) {
nm_vpn_connection_get_routes (connection))) {
nm_info ("VPN connection '%s' (IP Config Get) complete.",
nm_vpn_connection_get_name (connection));
nm_vpn_connection_set_state (connection, NM_VPN_CONNECTION_STATE_ACTIVATED);
@ -346,7 +366,7 @@ nm_vpn_connection_activate (NMVPNConnection *connection)
dbus_mgr = nm_dbus_manager_get ();
priv->proxy = dbus_g_proxy_new_for_name (nm_dbus_manager_get_connection (dbus_mgr),
priv->dbus_service,
nm_vpn_connection_get_service (connection),
NM_VPN_DBUS_PLUGIN_PATH,
NM_VPN_DBUS_PLUGIN_INTERFACE);
g_object_unref (dbus_mgr);
@ -368,8 +388,8 @@ nm_vpn_connection_activate (NMVPNConnection *connection)
connection, NULL);
org_freedesktop_NetworkManager_VPN_Plugin_connect_async (priv->proxy,
priv->properties,
priv->routes,
nm_vpn_connection_get_vpn_data (connection),
nm_vpn_connection_get_routes (connection),
nm_vpn_connection_connect_cb,
connection);
@ -387,9 +407,15 @@ nm_vpn_connection_get_object_path (NMVPNConnection *connection)
const char *
nm_vpn_connection_get_name (NMVPNConnection *connection)
{
NMVPNConnectionPrivate *priv;
NMSettingConnection *setting;
g_return_val_if_fail (NM_IS_VPN_CONNECTION (connection), NULL);
return NM_VPN_CONNECTION_GET_PRIVATE (connection)->name;
priv = NM_VPN_CONNECTION_GET_PRIVATE (connection);
setting = (NMSettingConnection *) nm_connection_get_setting (priv->connection, NM_SETTING_CONNECTION);
return setting->name;
}
NMVPNConnectionState
@ -507,10 +533,8 @@ finalize (GObject *object)
if (priv->proxy)
g_object_unref (priv->proxy);
g_free (priv->name);
g_free (priv->dbus_service);
g_hash_table_unref (priv->properties);
g_strfreev (priv->routes);
g_object_unref (priv->connection);
g_free (priv->object_path);
G_OBJECT_CLASS (nm_vpn_connection_parent_class)->finalize (object);

View file

@ -51,11 +51,8 @@ typedef struct {
GType nm_vpn_connection_get_type (void);
NMVPNConnection *nm_vpn_connection_new (const char *name,
const char *dbus_service,
NMDevice *parent_device,
GHashTable *properties,
char **routes);
NMVPNConnection *nm_vpn_connection_new (NMConnection *connection,
NMDevice *parent_device);
void nm_vpn_connection_activate (NMVPNConnection *connection);
const char *nm_vpn_connection_get_object_path (NMVPNConnection *connection);

View file

@ -5,16 +5,15 @@
#include "nm-vpn-manager.h"
#include "nm-vpn-service.h"
#include "nm-vpn-connection.h"
#include "nm-manager.h"
#include "nm-dbus-manager.h"
#include "NetworkManagerVPN.h"
#include "nm-utils.h"
static gboolean impl_vpn_manager_connect (NMVPNManager *manager,
const char *type,
const char *name,
GHashTable *properties,
const char *connection_type,
const char *connection_path,
const char *device_path,
char **routes,
char **connection,
GError **err);
@ -27,7 +26,6 @@ static gboolean impl_vpn_manager_get_connections (NMVPNManager *manager,
G_DEFINE_TYPE (NMVPNManager, nm_vpn_manager, G_TYPE_OBJECT)
typedef struct {
NMManager *nm_mgr;
NMDBusManager *dbus_mgr;
GSList *services;
} NMVPNManagerPrivate;
@ -68,32 +66,32 @@ nm_vpn_manager_add_service (NMVPNManager *manager, NMVPNService *service)
NMVPNConnection *
nm_vpn_manager_connect (NMVPNManager *manager,
const char *type,
const char *name,
NMDevice *device,
GHashTable *properties,
char **routes)
NMConnection *connection,
NMDevice *device)
{
NMSettingVPN *vpn_setting;
NMVPNService *service;
g_return_val_if_fail (NM_IS_VPN_MANAGER (manager), NULL);
g_return_val_if_fail (type != NULL, NULL);
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
g_return_val_if_fail (properties != NULL, NULL);
if (nm_device_get_state (device) != NM_DEVICE_STATE_ACTIVATED)
return NULL;
service = nm_vpn_manager_get_service (manager, type);
vpn_setting = (NMSettingVPN *) nm_connection_get_setting (connection, NM_SETTING_VPN);
if (!vpn_setting)
return NULL;
service = nm_vpn_manager_get_service (manager, vpn_setting->service_type);
if (!service) {
service = nm_vpn_service_new (type);
service = nm_vpn_service_new (vpn_setting->service_type);
if (service)
nm_vpn_manager_add_service (manager, service);
}
if (service)
return nm_vpn_service_activate (service, name, device, properties, routes);
return nm_vpn_service_activate (service, connection, device);
return NULL;
}
@ -101,10 +99,14 @@ nm_vpn_manager_connect (NMVPNManager *manager,
static NMDevice *
find_device (NMVPNManager *manager, const char *device_path)
{
NMManager *nm_manager;
GSList *devices;
GSList *iter;
devices = nm_manager_get_devices (NM_VPN_MANAGER_GET_PRIVATE (manager)->nm_mgr);
nm_manager = nm_manager_get ();
devices = nm_manager_get_devices (nm_manager);
g_object_unref (nm_manager);
for (iter = devices; iter; iter = iter->next) {
NMDevice *device = NM_DEVICE (iter->data);
@ -117,39 +119,52 @@ find_device (NMVPNManager *manager, const char *device_path)
static gboolean
impl_vpn_manager_connect (NMVPNManager *manager,
const char *type,
const char *name,
GHashTable *properties,
const char *connection_type,
const char *connection_path,
const char *device_path,
char **routes,
char **connection_path,
char **vpn_connection_path,
GError **err)
{
NMManager *nm_manager;
NMDevice *device;
NMVPNConnection *connection;
GHashTable *properties_dup;
char **routes_dup;
NMConnection *connection;
NMVPNConnection *vpn_connection;
*vpn_connection_path = NULL;
device = find_device (manager, device_path);
if (!device)
return FALSE;
properties_dup = nm_utils_gvalue_hash_dup (properties);
routes_dup = g_strdupv (routes);
connection = nm_vpn_manager_connect (manager,
type, name,
device,
properties_dup,
routes_dup);
if (connection)
*connection_path = g_strdup (nm_vpn_connection_get_object_path (connection));
else {
g_hash_table_destroy (properties_dup);
g_strfreev (routes_dup);
if (!device) {
/* FIXME: set error */
goto out;
}
return *connection_path != NULL;
nm_manager = nm_manager_get ();
if (!strcmp (connection_type, NM_DBUS_SERVICE_USER_SETTINGS))
connection = nm_manager_get_connection_by_object_path (nm_manager,
NM_CONNECTION_TYPE_USER,
connection_path);
else if (!strcmp (connection_type, NM_DBUS_SERVICE_USER_SETTINGS))
connection = nm_manager_get_connection_by_object_path (nm_manager,
NM_CONNECTION_TYPE_SYSTEM,
connection_path);
g_object_unref (nm_manager);
if (connection == NULL) {
/* FIXME: set error */
goto out;
}
vpn_connection = nm_vpn_manager_connect (manager, connection, device);
if (vpn_connection)
*vpn_connection_path = g_strdup (nm_vpn_connection_get_object_path (vpn_connection));
else {
/* FIXME: set error */
g_object_unref (connection);
}
out:
return *vpn_connection_path != NULL;
}
static void
@ -192,15 +207,11 @@ impl_vpn_manager_get_connections (NMVPNManager *manager, GPtrArray **connections
}
NMVPNManager *
nm_vpn_manager_new (NMManager *nm_manager)
nm_vpn_manager_new (void)
{
NMVPNManager *manager;
g_return_val_if_fail (NM_IS_MANAGER (nm_manager), NULL);
manager = (NMVPNManager *) g_object_new (NM_TYPE_VPN_MANAGER, NULL);
if (manager)
NM_VPN_MANAGER_GET_PRIVATE (manager)->nm_mgr = g_object_ref (nm_manager);
return manager;
}
@ -225,7 +236,6 @@ finalize (GObject *object)
g_slist_foreach (priv->services, (GFunc) g_object_unref, NULL);
g_object_unref (priv->dbus_mgr);
g_object_unref (priv->nm_mgr);
G_OBJECT_CLASS (nm_vpn_manager_parent_class)->finalize (object);
}
@ -242,4 +252,5 @@ nm_vpn_manager_class_init (NMVPNManagerClass *manager_class)
dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (manager_class),
&dbus_glib_nm_vpn_manager_object_info);
}

View file

@ -6,7 +6,6 @@
#include <glib/gtypes.h>
#include <glib-object.h>
#include "nm-vpn-connection.h"
#include "nm-manager.h"
#define NM_TYPE_VPN_MANAGER (nm_vpn_manager_get_type ())
#define NM_VPN_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VPN_MANAGER, NMVPNManager))
@ -25,14 +24,11 @@ typedef struct {
GType nm_vpn_manager_get_type (void);
NMVPNManager *nm_vpn_manager_new (NMManager *nm_manager);
NMVPNManager *nm_vpn_manager_new (void);
NMVPNConnection *nm_vpn_manager_connect (NMVPNManager *manager,
const char *type,
const char *name,
NMDevice *device,
GHashTable *properties,
char **routes);
NMConnection *connection,
NMDevice *device);
GSList *nm_vpn_manager_get_connections (NMVPNManager *manager);

View file

@ -299,36 +299,33 @@ connection_state_changed (NMVPNConnection *connection, NMVPNConnectionState stat
NMVPNConnection *
nm_vpn_service_activate (NMVPNService *service,
const char *name,
NMDevice *device,
GHashTable *properties,
char **routes)
NMConnection *connection,
NMDevice *device)
{
NMVPNConnection *connection;
NMVPNConnection *vpn_connection;
NMVPNServicePrivate *priv;
g_return_val_if_fail (NM_IS_VPN_SERVICE (service), NULL);
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
g_return_val_if_fail (properties != NULL, NULL);
priv = NM_VPN_SERVICE_GET_PRIVATE (service);
connection = nm_vpn_connection_new (name, priv->dbus_service, device, properties, routes);
g_signal_connect (connection, "state-changed",
vpn_connection = nm_vpn_connection_new (connection, device);
g_signal_connect (vpn_connection, "state-changed",
G_CALLBACK (connection_state_changed),
service);
priv->connections = g_slist_prepend (priv->connections, connection);
priv->connections = g_slist_prepend (priv->connections, vpn_connection);
if (nm_dbus_manager_name_has_owner (priv->dbus_mgr, priv->dbus_service))
nm_vpn_connection_activate (connection);
nm_vpn_connection_activate (vpn_connection);
else if (priv->service_start_timeout == 0) {
nm_info ("VPN service '%s' exec scheduled...", nm_vpn_service_get_name (service));
g_idle_add (nm_vpn_service_daemon_exec, service);
}
return connection;
return vpn_connection;
}
GSList *

View file

@ -29,10 +29,8 @@ NMVPNService *nm_vpn_service_new (const char *service_name);
const char *nm_vpn_service_get_name (NMVPNService *service);
NMVPNConnection *nm_vpn_service_activate (NMVPNService *service,
const char *name,
NMDevice *device,
GHashTable *properties,
char **routes);
NMConnection *connection,
NMDevice *device);
GSList *nm_vpn_service_get_connections (NMVPNService *service);