Commit 600e027e authored by Robert Love's avatar Robert Love Committed by Robert Love
Browse files

2005-08-05 Robert Love <rml@novell.com>

        * NetworkManager.h,
          gnome/applet/applet-dbus-devices.c,
          gnome/applet/applet-dbus-devices.h,
          gnome/applet/applet-dbus.c,
          gnome/applet/applet.c,
          gnome/applet/applet.h,
          src/NetworkManager.c,
          src/NetworkManagerMain.h,
          src/NetworkManagerSystem.h,
          src/backends/NetworkManagerRedHat.c,
          src/backends/NetworkManagerSuSE.c,
          src/nm-dbus-nm.c: basic dialup support using distro infrastructure


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@821 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
parent 86ed3ac6
2005-08-05 Robert Love <rml@novell.com>
* NetworkManager.h,
gnome/applet/applet-dbus-devices.c,
gnome/applet/applet-dbus-devices.h,
gnome/applet/applet-dbus.c,
gnome/applet/applet.c,
gnome/applet/applet.h,
src/NetworkManager.c,
src/NetworkManagerMain.h,
src/NetworkManagerSystem.h,
src/backends/NetworkManagerRedHat.c,
src/backends/NetworkManagerSuSE.c,
src/nm-dbus-nm.c: basic dialup support using distro infrastructure
2005-08-05 Robert Love <rml@novell.com>
* gnome/applet/other-network-dialog.c: default the adhoc network to the
......
......@@ -45,6 +45,7 @@
* Some common errors
*/
#define NM_DBUS_NO_DEVICES_ERROR "org.freedesktop.NetworkManager.NoDevices"
#define NM_DBUS_NO_DIALUP_ERROR "org.freedesktop.NetworkManager.NoDialup"
#define NM_DBUS_NO_NETWORKS_ERROR "org.freedesktop.NetworkManager.NoNetworks"
#define NM_DBUS_NO_ACTIVE_DEVICE_ERROR "org.freedesktop.NetworkManager.NoActiveDevice"
#define NM_DBUS_NO_ACTIVE_NET_ERROR "org.freedesktop.NetworkManager.NoActiveNetwork"
......
......@@ -827,7 +827,7 @@ static void nmwa_dbus_device_properties_cb (DBusPendingCall *pcall, void *user_d
applet->dbus_device_list = g_slist_remove (applet->dbus_device_list, tmp_dev);
network_device_unref (tmp_dev);
}
applet->dbus_device_list = g_slist_append (applet->dbus_device_list, dev);
nmwa_dbus_update_device_info_from_hal (dev, applet);
......@@ -932,10 +932,101 @@ out:
}
/*
* nmwa_dbus_update_dialup_cb
*
* nmwa_dbus_update_dialup DBUS callback.
*
*/
static void nmwa_dbus_update_dialup_cb (DBusPendingCall *pcall, void *user_data)
{
DBusMessage *reply;
NMWirelessApplet *applet = (NMWirelessApplet *) user_data;
char **dialup_devices;
int num_devices;
g_return_if_fail (pcall != NULL);
g_return_if_fail (applet != NULL);
dbus_pending_call_ref (pcall);
if (!dbus_pending_call_get_completed (pcall))
goto out;
if (!(reply = dbus_pending_call_steal_reply (pcall)))
goto out;
if (dbus_message_is_error (reply, NM_DBUS_NO_DIALUP_ERROR))
{
dbus_message_unref (reply);
goto out;
}
if (dbus_message_get_args (reply, NULL, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &dialup_devices, &num_devices, DBUS_TYPE_INVALID))
{
char **item;
GSList *elt;
for (elt = applet->dialup_list; elt; elt = g_slist_next (elt))
g_free (elt->data);
if (applet->dialup_list)
{
g_slist_free (applet->dialup_list);
applet->dialup_list = NULL;
}
for (item = dialup_devices; *item; item++)
applet->dialup_list = g_slist_append (applet->dialup_list, g_strdup (*item));
dbus_free_string_array (dialup_devices);
}
dbus_message_unref (reply);
out:
dbus_pending_call_unref (pcall);
}
/*
* nmwa_dbus_dialup_activate_connection
*
* Tell NetworkManager to activate a particular dialup connection.
*
*/
void nmwa_dbus_dialup_activate_connection (NMWirelessApplet *applet, const char *name)
{
DBusMessage *message;
DBusMessageIter iter;
DBusMessageIter iter_array;
g_return_if_fail (name != NULL);
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "activateDialup")))
{
nm_info ("Activating dialup connection '%s'.", name);
#if 0
dbus_message_iter_init_append (message, &iter);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &name);
dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &iter_array);
for (i = passwords; i != NULL; i = g_slist_next (i)) {
dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_STRING, &(i->data));
}
dbus_message_iter_close_container (&iter, &iter_array);
#endif
dbus_message_append_args (message, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID);
if (!dbus_connection_send (applet->connection, message, NULL))
nm_warning ("nmwa_dbus_activate_dialup_connection(): Could not send activateDialup message!");
}
else
nm_warning ("nmwa_dbus_activate_dialup_connection(): Couldn't allocate the dbus message!");
}
/*
* nmwa_dbus_update_devices
*
* Do a full update of network devices and wireless networks.
* Do a full update of network devices, wireless networks, and dial up devices.
*
*/
void nmwa_dbus_update_devices (NMWirelessApplet *applet)
......@@ -954,11 +1045,35 @@ void nmwa_dbus_update_devices (NMWirelessApplet *applet)
if (pcall)
dbus_pending_call_set_notify (pcall, nmwa_dbus_update_devices_cb, applet, NULL);
}
nmwa_dbus_update_wireless_enabled (applet);
}
/*
* nmwa_dbus_update_dialup
*
* Do an update of dial up devices.
*
*/
void nmwa_dbus_update_dialup (NMWirelessApplet *applet)
{
DBusMessage *message;
DBusPendingCall *pcall;
g_return_if_fail (applet->data_mutex != NULL);
nmwa_free_dbus_data_model (applet);
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "getDialup")))
{
dbus_connection_send_with_reply (applet->connection, message, &pcall, -1);
dbus_message_unref (message);
if (pcall)
dbus_pending_call_set_notify (pcall, nmwa_dbus_update_dialup_cb, applet, NULL);
}
}
/*
* nmwa_dbus_device_remove_one_device
*
......
......@@ -37,6 +37,8 @@ gboolean nmwa_dbus_update_device_strength (NMWirelessApplet *applet);
void nmwa_dbus_update_nm_state (NMWirelessApplet *applet);
void nmwa_dbus_update_devices (NMWirelessApplet *applet);
void nmwa_dbus_update_dialup (NMWirelessApplet *applet);
void nmwa_dbus_dialup_activate_connection (NMWirelessApplet *applet, const char *name);
void nmwa_dbus_device_update_one_device (NMWirelessApplet *applet, const char *dev_path);
void nmwa_dbus_device_remove_one_device (NMWirelessApplet *applet, const char *dev_path);
......
......@@ -461,6 +461,7 @@ static DBusHandlerResult nmwa_dbus_filter (DBusConnection *connection, DBusMessa
applet->dbus_nm_state = NM_STATE_DISCONNECTED;
nmwa_dbus_update_nm_state (applet);
nmwa_dbus_update_devices (applet);
nmwa_dbus_update_dialup (applet);
nmwa_dbus_vpn_update_vpn_connections (applet);
}
else if (old_owner_good && !new_owner_good)
......@@ -743,6 +744,7 @@ static gboolean nmwa_dbus_connection_watcher (gpointer user_data)
applet->dbus_nm_state = NM_STATE_DISCONNECTED;
nmwa_dbus_update_nm_state (applet);
nmwa_dbus_update_devices (applet);
nmwa_dbus_update_dialup (applet);
nmwa_dbus_vpn_update_vpn_connections (applet);
}
}
......@@ -788,6 +790,7 @@ gpointer nmwa_dbus_worker (gpointer user_data)
applet->nm_running = TRUE;
nmwa_dbus_update_nm_state (applet);
nmwa_dbus_update_devices (applet);
nmwa_dbus_update_dialup (applet);
nmwa_dbus_vpn_update_vpn_connections (applet);
}
......
......@@ -1335,6 +1335,28 @@ static void nmwa_menu_vpn_item_activate (GtkMenuItem *item, gpointer user_data)
}
/*
* nmwa_menu_dialup_item_activate
*
* Signal function called when user clicks on a dialup menu item
*
*/
static void nmwa_menu_dialup_item_activate (GtkMenuItem *item, gpointer user_data)
{
NMWirelessApplet *applet = (NMWirelessApplet *) user_data;
const char *dialup;
g_return_if_fail (item != NULL);
g_return_if_fail (applet != NULL);
dialup = g_object_get_data (G_OBJECT (item), "dialup");
if (!dialup)
return;
nmwa_dbus_dialup_activate_connection (applet, dialup);
}
/*
* nmwa_menu_configure_vpn_item_activate
*
......@@ -1695,6 +1717,39 @@ static void nmwa_menu_add_vpn_menu (GtkWidget *menu, NMWirelessApplet *applet)
}
static void nmwa_menu_add_dialup_menu (GtkWidget *menu, NMWirelessApplet *applet)
{
GtkMenuItem *item;
GtkMenu *dialup_menu;
GtkMenuItem *other_item;
GSList *elt;
g_return_if_fail (menu != NULL);
g_return_if_fail (applet != NULL);
item = GTK_MENU_ITEM (gtk_menu_item_new_with_label (_("Dial Up")));
dialup_menu = GTK_MENU (gtk_menu_new ());
for (elt = applet->dialup_list; elt; elt = g_slist_next (elt))
{
GtkMenuItem *dialup_item;
char *name = elt->data;
const char *label;
label = g_strdup_printf ("Connect via %s...", name);
dialup_item = GTK_MENU_ITEM (gtk_menu_item_new_with_label (label));
g_object_set_data (G_OBJECT (dialup_item), "dialup", name);
g_signal_connect (G_OBJECT (dialup_item), "activate", G_CALLBACK (nmwa_menu_dialup_item_activate), applet);
gtk_menu_shell_append (GTK_MENU_SHELL (dialup_menu), GTK_WIDGET (dialup_item));
}
gtk_menu_item_set_submenu (item, GTK_WIDGET (dialup_menu));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), GTK_WIDGET (item));
gtk_widget_show_all (GTK_WIDGET (item));
}
/** Returns TRUE if, and only if, we have VPN support installed
*
* Algorithm: just check whether any .name files exist in
......@@ -1787,11 +1842,18 @@ static void nmwa_menu_add_devices (GtkWidget *menu, NMWirelessApplet *applet)
}
}
if (is_vpn_available ()) {
if (is_vpn_available ())
{
nmwa_menu_add_separator_item (menu);
nmwa_menu_add_vpn_menu (menu, applet);
}
if (applet->dialup_list)
{
nmwa_menu_add_separator_item (menu);
nmwa_menu_add_dialup_menu (menu, applet);
}
if (n_wireless_interfaces > 0)
{
/* Add the "Other wireless network..." entry */
......@@ -2354,6 +2416,7 @@ static GtkWidget * nmwa_get_instance (NMWirelessApplet *applet)
applet->gui_device_list = NULL;
applet->gui_active_vpn = NULL;
applet->gui_vpn_connections = NULL;
applet->dialup_list = NULL;
applet->gui_nm_state = NM_STATE_DISCONNECTED;
applet->tooltips = NULL;
applet->thread_context = NULL;
......
......@@ -100,6 +100,8 @@ typedef struct
GSList * dbus_device_list;
NMState dbus_nm_state;
GSList * dialup_list;
GSList * gui_vpn_connections;
VPNConnection * gui_active_vpn;
......
......@@ -417,13 +417,15 @@ static NMData *nm_data_new (gboolean enable_test_devices)
/* Initialize the device list mutex to protect additions/deletions to it. */
data->dev_list_mutex = g_mutex_new ();
if (!data->dev_list_mutex)
data->dialup_list_mutex = g_mutex_new ();
if (!data->dev_list_mutex || !data->dialup_list_mutex)
{
nm_data_free (data);
nm_warning ("could not initialize data structure locks.");
return (NULL);
}
nm_register_mutex_desc (data->dev_list_mutex, "Device List Mutex");
nm_register_mutex_desc (data->dialup_list_mutex, "DialUp List Mutex");
/* Initialize the access point lists */
data->allowed_ap_list = nm_ap_list_new (NETWORK_TYPE_ALLOWED);
......@@ -965,6 +967,9 @@ int main( int argc, char *argv[] )
nm_monitor_wireless_link_state (nm_data);
nm_monitor_wired_link_state (nm_data);
/* Get modems, ISDN, and so on's configuration from the system */
nm_data->dialup_list = nm_system_get_dialup_config ();
if (!nm_named_manager_start (nm_data->named_manager, &error))
{
nm_error ("couldn't initialize nameserver: %s",
......
#ifndef _NETWORK_MANAGER_DIALUP_H
#define _NETWORK_MANAGER_DIALUP_H
typedef struct NMDialUpConfig
{
char *name; /* user-readable name, unique */
void *data; /* backend internal data */
} NMDialUpConfig;
#endif /* _NETWORK_MANAGER_DIALUP_H */
......@@ -84,6 +84,9 @@ typedef struct NMData
gboolean wireless_enabled;
gboolean asleep;
GSList * dialup_list;
GMutex * dialup_list_mutex;
struct NMAccessPointList *allowed_ap_list;
struct NMAccessPointList *invalid_ap_list;
} NMData;
......
......@@ -73,4 +73,8 @@ gboolean nm_system_device_set_up_down_with_iface (NMDevice *dev, const char *i
gboolean nm_system_device_update_resolv_conf (void *data, int len, const char *domain_name);
GSList * nm_system_get_dialup_config (void);
void nm_system_deactivate_all_dialup (GSList *list);
gboolean nm_system_activate_dialup (GSList *list, const char *dialup);
#endif
......@@ -658,3 +658,17 @@ NMIP4Config *nm_system_device_new_ip4_system_config (NMDevice *dev)
return new_config;
}
void nm_system_deactivate_all_dialup (GSList *list)
{
}
gboolean nm_system_activate_dialup (GSList *list, const char *dialup)
{
return FALSE;
}
GSList * nm_system_get_dialup_config (void)
{
return NULL;
}
......@@ -32,6 +32,7 @@
#include "NetworkManagerSystem.h"
#include "NetworkManagerUtils.h"
#include "NetworkManagerDevice.h"
#include "NetworkManagerDialup.h"
#include "nm-utils.h"
#include "shvar.h"
......@@ -673,3 +674,97 @@ NMIP4Config *nm_system_device_new_ip4_system_config (NMDevice *dev)
return new_config;
}
void nm_system_deactivate_all_dialup (GSList *list)
{
GSList *elt;
for (elt = list; elt; elt = g_slist_next (elt))
{
NMDialUpConfig *config = (NMDialUpConfig *) elt->data;
char *cmd;
cmd = g_strdup_printf ("/sbin/ifdown %s", (char *) config->data);
nm_spawn_process (cmd);
g_free (cmd);
}
}
gboolean nm_system_activate_dialup (GSList *list, const char *dialup)
{
GSList *elt;
gboolean ret = FALSE;
for (elt = list; elt; elt = g_slist_next (elt))
{
NMDialUpConfig *config = (NMDialUpConfig *) elt->data;
if (strcmp (dialup, config->name) == 0)
{
char *cmd;
nm_info ("Activating dialup device %s (%s) ...", dialup, (char *) config->data);
cmd = g_strdup_printf ("/sbin/ifup %s", (char *) config->data);
nm_spawn_process (cmd);
g_free (cmd);
ret = TRUE;
break;
}
}
return ret;
}
/*
* nm_system_get_dialup_config
*
* Enumerate dial up options on this system, allocate NMDialUpConfig's,
* fill them out, and return.
*
*/
GSList * nm_system_get_dialup_config (void)
{
GSList *list = NULL;
const char *dentry;
unsigned int i = 0;
size_t len;
GError *err;
GDir *dir;
dir = g_dir_open (SYSCONFDIR "/sysconfig/network", 0, &err);
if (!dir)
{
nm_warning ("Could not open directory " SYSCONFDIR "/sysconfig/network: %s", err->message);
return NULL;
}
while ((dentry = g_dir_read_name (dir)))
{
NMDialUpConfig *config;
/* we only want modems */
if (!g_str_has_prefix (dentry, "ifcfg-modem"))
continue;
config = g_malloc (sizeof (NMDialUpConfig));
config->name = g_strdup_printf ("Modem (#%d)", i++);
config->data = g_strdup (dentry + 6); /* skip the "ifcfg-" prefix */
list = g_slist_append (list, config);
nm_info ("Found dial up configuration for %s: %s", config->name, (char *) config->data);
}
/* Hack: Go back and remove the "(#0)" if there is only one device */
if (i == 1)
{
NMDialUpConfig *config = (NMDialUpConfig *) list->data;
g_free (config->name);
config->name = g_strdup ("Modem");
}
g_dir_close (dir);
return list;
}
......@@ -31,6 +31,8 @@
#include "NetworkManagerDbusUtils.h"
#include "NetworkManagerUtils.h"
#include "NetworkManagerPolicy.h"
#include "NetworkManagerDialup.h"
#include "NetworkManagerSystem.h"
#include "NetworkManager.h"
......@@ -106,6 +108,86 @@ static DBusMessage *nm_dbus_nm_get_devices (DBusConnection *connection, DBusMess
}
static DBusMessage *nm_dbus_nm_get_dialup (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
{
DBusMessage *reply = NULL;
DBusMessageIter iter;
g_return_val_if_fail (data != NULL, NULL);
g_return_val_if_fail (data->data != NULL, NULL);
g_return_val_if_fail (connection != NULL, NULL);
g_return_val_if_fail (message != NULL, NULL);
/* Check for no dialup devices */
if (!data->data->dialup_list)
return (nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "NoDialup",
"There are no available dialup devices."));
reply = dbus_message_new_method_return (message);
if (!reply)
return NULL;
dbus_message_iter_init_append (reply, &iter);
if (nm_try_acquire_mutex (data->data->dialup_list_mutex, __FUNCTION__))
{
DBusMessageIter iter_array;
GSList *elt;
dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &iter_array);
for (elt = data->data->dialup_list; elt; elt = g_slist_next (elt))
{
NMDialUpConfig *config = (NMDialUpConfig *) elt->data;
dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_STRING, &config->name);
}
dbus_message_iter_close_container (&iter, &iter_array);
nm_unlock_mutex (data->data->dialup_list_mutex, __FUNCTION__);
}
else
{
dbus_message_unref (reply);
reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "Retry",
"NetworkManager could not lock dialup list, try again.");
}
return reply;
}
static DBusMessage *nm_dbus_nm_activate_dialup (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
{
DBusMessage *reply = NULL;
NMData *nm_data = (NMData *) data->data;
const char *dialup;
g_return_val_if_fail (data != NULL, NULL);
g_return_val_if_fail (data->data != NULL, NULL);
g_return_val_if_fail (connection != NULL, NULL);
g_return_val_if_fail (message != NULL, NULL);
reply = dbus_message_new_method_return (message);
if (!reply)
return NULL;
if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &dialup, DBUS_TYPE_INVALID))
{
reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "InvalidArguments",
"NetworkManager::activateDialup called with invalid arguments.");
goto out;
}
nm_lock_mutex (nm_data->dialup_list_mutex, __FUNCTION__);
if (!nm_system_activate_dialup (nm_data->dialup_list, dialup))
reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "ActivationFailed",
"Failed to activate the dialup device.");
nm_unlock_mutex (nm_data->dialup_list_mutex, __FUNCTION__);
out:
return reply;
}
/*
* nm_dbus_nm_set_active_device
*
......@@ -417,6 +499,10 @@ static DBusMessage *nm_dbus_nm_sleep (DBusConnection *connection, DBusMessage *m
}
nm_unlock_mutex (app_data->dev_list_mutex, __FUNCTION__);
nm_lock_mutex (app_data->dialup_list_mutex, __FUNCTION__);
nm_system_deactivate_all_dialup (app_data->dialup_list);
nm_unlock_mutex (app_data->dialup_list_mutex, __FUNCTION__);
nm_schedule_state_change_signal_broadcast (app_data);
nm_policy_schedule_device_change_check (data->data);
}
......@@ -480,6 +566,8 @@ NMDbusMethodList *nm_dbus_nm_methods_setup (void)
NMDbusMethodList *list = nm_dbus_method_list_new (NULL);
nm_dbus_method_list_add_method (list, "getDevices", nm_dbus_nm_get_devices);
nm_dbus_method_list_add_method (list, "getDialup", nm_dbus_nm_get_dialup);
nm_dbus_method_list_add_method (list, "activateDialup", nm_dbus_nm_activate_dialup);
nm_dbus_method_list_add_method (list, "setActiveDevice", nm_dbus_nm_set_active_device);
nm_dbus_method_list_add_method (list, "createWirelessNetwork", nm_dbus_nm_create_wireless_network);
nm_dbus_method_list_add_method (list, "getWirelessScanMethod", nm_dbus_nm_get_wireless_scan_method);
......