[patch] Dial Up Support.



Attached is working dial up support for NetworkManager that utilizes the
distribution's existing dial up infrastructure.

This is basically an implementation of the proposal I sent to the list
last week, entitled "[rfc] modems, isdn, and other relics of the stone
age."

It should support any general dial up device: modem, ISDN, etc.

It adds three interfaces to the backends:

        GSList * nm_system_get_dialup_config (void)
        Enumerates dial up devices on the system and returns a list
        NMDialUpConfig structures or NULL on failure.
        
        void nm_system_deactivate_all_dialup (GSList *list)
        Ensures that all dial up devices are down.
        
        gboolean nm_system_activate_dialup (GSList *list,
                                            const char *dialup)
        Activates a given dial up device.

It adds two DBUS methods:

        getDialup (void)
        Returns an array of strings of dial up interfaces.  The strings
        are simply human-readable unique identifiers, e.g. "Modem" or
        "CompuServe".
        
        activateDialUp (string)
        Request that the dial up device matching "string" be connected
        to.
        
The patch adds support for SUSE.  On a SUSE machine, NM should list and
allow connection to any modems.  See

	http://rlove.org/images/networkmanager-screenshot-20050801.png

I also added the stub functions for Red Hat, e.g. NM should compile and
continue to work.

The API should be general enough if we ever want to move toward a more
NM-esque solution for dial up in the future.  But, for me, for now, this
is sufficient.

Comments?  Questions?

	Robert Love

 NetworkManager.h                    |    1
 gnome/applet/applet-dbus-devices.c  |  121 +++++++++++++++++++++++++++++++++++-
 gnome/applet/applet-dbus-devices.h  |    2
 gnome/applet/applet-dbus.c          |    3
 gnome/applet/applet.c               |   65 +++++++++++++++++++
 gnome/applet/applet.h               |    2
 src/NetworkManager.c                |    7 +-
 src/NetworkManagerDialup.h          |   10 ++
 src/NetworkManagerMain.h            |    3
 src/NetworkManagerSystem.h          |    4 +
 src/backends/NetworkManagerRedHat.c |   14 ++++
 src/backends/NetworkManagerSuSE.c   |   95 ++++++++++++++++++++++++++++
 src/nm-dbus-nm.c                    |   88 ++++++++++++++++++++++++++
 src/nm-netlink-monitor.c            |    2
 14 files changed, 411 insertions(+), 6 deletions(-)

Index: NetworkManager.h
===================================================================
RCS file: /cvs/gnome/NetworkManager/NetworkManager.h,v
retrieving revision 1.16
diff -u -u -r1.16 NetworkManager.h
--- NetworkManager.h	17 Jun 2005 00:36:07 -0000	1.16
+++ NetworkManager.h	2 Aug 2005 19:43:29 -0000
@@ -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"
Index: gnome/applet/applet-dbus-devices.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/gnome/applet/applet-dbus-devices.c,v
retrieving revision 1.11
diff -u -u -r1.11 applet-dbus-devices.c
--- gnome/applet/applet-dbus-devices.c	27 Jul 2005 06:32:31 -0000	1.11
+++ gnome/applet/applet-dbus-devices.c	2 Aug 2005 19:43:29 -0000
@@ -827,7 +827,7 @@
 			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);
@@ -933,9 +933,100 @@
 
 
 /*
+ * 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,8 +1045,32 @@
 		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);
+	}
 }
 
 
Index: gnome/applet/applet-dbus-devices.h
===================================================================
RCS file: /cvs/gnome/NetworkManager/gnome/applet/applet-dbus-devices.h,v
retrieving revision 1.3
diff -u -u -r1.3 applet-dbus-devices.h
--- gnome/applet/applet-dbus-devices.h	3 May 2005 20:41:33 -0000	1.3
+++ gnome/applet/applet-dbus-devices.h	2 Aug 2005 19:43:29 -0000
@@ -37,6 +37,8 @@
 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);
 
Index: gnome/applet/applet-dbus.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/gnome/applet/applet-dbus.c,v
retrieving revision 1.7
diff -u -u -r1.7 applet-dbus.c
--- gnome/applet/applet-dbus.c	12 Jun 2005 14:35:58 -0000	1.7
+++ gnome/applet/applet-dbus.c	2 Aug 2005 19:43:29 -0000
@@ -461,6 +461,7 @@
 					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 @@
 			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 @@
 		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);
 	}
 
Index: gnome/applet/applet.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/gnome/applet/applet.c,v
retrieving revision 1.26
diff -u -u -r1.26 applet.c
--- gnome/applet/applet.c	25 Jul 2005 21:49:17 -0000	1.26
+++ gnome/applet/applet.c	2 Aug 2005 19:43:29 -0000
@@ -1336,6 +1336,28 @@
 
 
 /*
+ * 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
  *
  * Signal function called when user clicks "Configure VPN..."
@@ -1695,6 +1717,39 @@
 }
 
 
+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 @@
 		}
 	}
 
-	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 @@
 	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;
Index: gnome/applet/applet.h
===================================================================
RCS file: /cvs/gnome/NetworkManager/gnome/applet/applet.h,v
retrieving revision 1.11
diff -u -u -r1.11 applet.h
--- gnome/applet/applet.h	27 Jul 2005 06:32:31 -0000	1.11
+++ gnome/applet/applet.h	2 Aug 2005 19:43:29 -0000
@@ -100,6 +100,8 @@
 	GSList *			dbus_device_list;
 	NMState			dbus_nm_state;
 
+	GSList *			dialup_list;
+
 	GSList *			gui_vpn_connections;
 	VPNConnection *	gui_active_vpn;
 
Index: src/NetworkManager.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/src/NetworkManager.c,v
retrieving revision 1.81
diff -u -u -r1.81 NetworkManager.c
--- src/NetworkManager.c	30 Jul 2005 01:01:06 -0000	1.81
+++ src/NetworkManager.c	2 Aug 2005 19:43:29 -0000
@@ -417,13 +417,15 @@
 
 	/* 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);
@@ -964,6 +966,9 @@
 	/* Create watch functions that monitor cards for link status. */
 	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))
 	{
Index: src/NetworkManagerDialup.h
===================================================================
RCS file: src/NetworkManagerDialup.h
diff -N src/NetworkManagerDialup.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/NetworkManagerDialup.h	2 Aug 2005 19:43:29 -0000
@@ -0,0 +1,10 @@
+#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 */
Index: src/NetworkManagerMain.h
===================================================================
RCS file: /cvs/gnome/NetworkManager/src/NetworkManagerMain.h,v
retrieving revision 1.19
diff -u -u -r1.19 NetworkManagerMain.h
--- src/NetworkManagerMain.h	23 Jun 2005 12:20:32 -0000	1.19
+++ src/NetworkManagerMain.h	2 Aug 2005 19:43:30 -0000
@@ -84,6 +84,9 @@
 	gboolean				wireless_enabled;
 	gboolean				asleep;
 
+	GSList *				dialup_list;
+	GMutex *				dialup_list_mutex;
+
 	struct NMAccessPointList	*allowed_ap_list;
 	struct NMAccessPointList	*invalid_ap_list;
 } NMData;
Index: src/NetworkManagerSystem.h
===================================================================
RCS file: /cvs/gnome/NetworkManager/src/NetworkManagerSystem.h,v
retrieving revision 1.7
diff -u -u -r1.7 NetworkManagerSystem.h
--- src/NetworkManagerSystem.h	16 May 2005 12:57:08 -0000	1.7
+++ src/NetworkManagerSystem.h	2 Aug 2005 19:43:30 -0000
@@ -73,4 +73,8 @@
 
 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
Index: src/nm-dbus-nm.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/src/nm-dbus-nm.c,v
retrieving revision 1.15
diff -u -u -r1.15 nm-dbus-nm.c
--- src/nm-dbus-nm.c	27 Jul 2005 06:32:31 -0000	1.15
+++ src/nm-dbus-nm.c	2 Aug 2005 19:43:30 -0000
@@ -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_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 @@
 		}
 		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	*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);
Index: src/backends/NetworkManagerRedHat.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/src/backends/NetworkManagerRedHat.c,v
retrieving revision 1.31
diff -u -u -r1.31 NetworkManagerRedHat.c
--- src/backends/NetworkManagerRedHat.c	16 Jun 2005 01:00:26 -0000	1.31
+++ src/backends/NetworkManagerRedHat.c	2 Aug 2005 19:43:30 -0000
@@ -658,3 +658,17 @@
 	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;
+}
Index: src/backends/NetworkManagerSuSE.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/src/backends/NetworkManagerSuSE.c,v
retrieving revision 1.6
diff -u -u -r1.6 NetworkManagerSuSE.c
--- src/backends/NetworkManagerSuSE.c	26 Jul 2005 16:02:13 -0000	1.6
+++ src/backends/NetworkManagerSuSE.c	2 Aug 2005 19:43:30 -0000
@@ -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 @@
 	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;
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]