[network-manager-pptp/jk/pppd-unit-bgo736485] all: add "unit" option for pppd to define ppp<n> name (bgo #736485)
- From: Jiří Klimeš <jklimes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-pptp/jk/pppd-unit-bgo736485] all: add "unit" option for pppd to define ppp<n> name (bgo #736485)
- Date: Fri, 6 Mar 2015 08:56:49 +0000 (UTC)
commit 02c8edabbb6724198b2e1cf7cbffede6e1505f5d
Author: Jiří Klimeš <jklimes redhat com>
Date: Fri Mar 6 09:47:56 2015 +0100
all: add "unit" option for pppd to define ppp<n> name (bgo #736485)
https://bugzilla.gnome.org/show_bug.cgi?id=736485
properties/advanced-dialog.c | 46 +++++++++++++++++++++++-
properties/nm-pptp-dialog.ui | 81 ++++++++++++++++++++++++++++++++++++++++++
src/nm-pptp-service.c | 34 +++++++++++++++--
src/nm-pptp-service.h | 1 +
4 files changed, 157 insertions(+), 5 deletions(-)
---
diff --git a/properties/advanced-dialog.c b/properties/advanced-dialog.c
index d601d20..b26416a 100644
--- a/properties/advanced-dialog.c
+++ b/properties/advanced-dialog.c
@@ -68,6 +68,7 @@ static const char *advanced_keys[] = {
NM_PPTP_KEY_NO_VJ_COMP,
NM_PPTP_KEY_LCP_ECHO_FAILURE,
NM_PPTP_KEY_LCP_ECHO_INTERVAL,
+ NM_PPTP_KEY_UNIT_NUM,
NULL
};
@@ -390,13 +391,21 @@ auth_methods_setup (GtkBuilder *builder, GHashTable *hash)
gtk_widget_set_sensitive (widget, TRUE);
}
+static void
+checkbox_toggled_update_widget_cb (GtkWidget *check, gpointer user_data)
+{
+ GtkWidget *widget = (GtkWidget*) user_data;
+
+ gtk_widget_set_sensitive (widget, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)));
+}
+
GtkWidget *
advanced_dialog_new (GHashTable *hash)
{
GtkBuilder *builder;
GtkWidget *dialog = NULL;
char *ui_file = NULL;
- GtkWidget *widget;
+ GtkWidget *widget, *spin;
const char *value;
gboolean mppe = FALSE;
GError *error = NULL;
@@ -483,6 +492,31 @@ advanced_dialog_new (GHashTable *hash)
handle_mppe_changed (widget, TRUE, builder);
g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (mppe_toggled_cb), builder);
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "ppp_unit_checkbutton"));
+ spin = GTK_WIDGET (gtk_builder_get_object (builder, "ppp_unit_spinbutton"));
+ g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (checkbox_toggled_update_widget_cb), spin);
+
+ value = g_hash_table_lookup (hash, NM_PPTP_KEY_UNIT_NUM);
+ if (value && *value) {
+ long int tmp;
+
+ errno = 0;
+ tmp = strtol (value, NULL, 10);
+ if (errno == 0 && tmp >= 0 && tmp < 65536) {
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
+
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "ppp_unit_spinbutton"));
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), (gdouble) tmp);
+ gtk_widget_set_sensitive (widget, TRUE);
+ }
+ } else {
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
+
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "ppp_unit_spinbutton"));
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), 0.0);
+ gtk_widget_set_sensitive (widget, FALSE);
+ }
+
out:
g_free (ui_file);
return dialog;
@@ -582,6 +616,16 @@ advanced_dialog_new_hash_from_dialog (GtkWidget *dialog, GError **error)
valid = gtk_tree_model_iter_next (model, &iter);
}
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "ppp_unit_checkbutton"));
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) {
+ int unit_num;
+
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "ppp_unit_spinbutton"));
+ unit_num = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
+ g_hash_table_insert (hash, g_strdup (NM_PPTP_KEY_UNIT_NUM),
+ g_strdup_printf ("%d", unit_num));
+ }
+
return hash;
}
diff --git a/properties/nm-pptp-dialog.ui b/properties/nm-pptp-dialog.ui
index 3e69701..e929277 100644
--- a/properties/nm-pptp-dialog.ui
+++ b/properties/nm-pptp-dialog.ui
@@ -2,6 +2,13 @@
<interface>
<!-- interface-requires gtk+ 2.6 -->
<!-- interface-naming-policy toplevel-contextual -->
+ <object class="GtkAdjustment" id="adjustment1">
+ <property name="lower">0</property>
+ <property name="upper">65535</property>
+ <property name="value">0</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">10</property>
+ </object>
<object class="GtkListStore" id="model1">
<columns>
<column type="gchararray"/>
@@ -599,6 +606,80 @@ config: lcp-echo-failure and lcp-echo-interval</property>
<property name="position">2</property>
</packing>
</child>
+ <child>
+ <object class="GtkVBox" id="vbox12">
+ <property name="visible">True</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkLabel" id="label32">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes"><b>Misc</b></property>
+ <property name="use_markup">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkAlignment" id="alignment6">
+ <property name="visible">True</property>
+ <property name="left_padding">12</property>
+ <child>
+ <object class="GtkHBox" id="hbox5">
+ <property name="orientation">horizontal</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkCheckButton" id="ppp_unit_checkbutton">
+ <property name="label" translatable="yes">Use custom _unit number:</property>
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="tooltip_text" translatable="yes">Enable custom index for
ppp<n> device name.
+config: unit <n></property>
+ <property name="use_underline">True</property>
+ <property name="xalign">0.5</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSpinButton" id="ppp_unit_spinbutton">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="tooltip_text" translatable="yes">Enable custom index for
ppp<n> device name.
+config: unit <n></property>
+ <property name="adjustment">adjustment1</property>
+ <property name="climb_rate">1</property>
+ <property name="numeric">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="position">1</property>
diff --git a/src/nm-pptp-service.c b/src/nm-pptp-service.c
index 4954c5f..f88532a 100644
--- a/src/nm-pptp-service.c
+++ b/src/nm-pptp-service.c
@@ -511,6 +511,7 @@ static ValidProperty valid_properties[] = {
{ NM_PPTP_KEY_NO_VJ_COMP, G_TYPE_BOOLEAN, FALSE },
{ NM_PPTP_KEY_LCP_ECHO_FAILURE, G_TYPE_UINT, FALSE },
{ NM_PPTP_KEY_LCP_ECHO_INTERVAL, G_TYPE_UINT, FALSE },
+ { NM_PPTP_KEY_UNIT_NUM, G_TYPE_UINT, FALSE },
{ NM_PPTP_KEY_PASSWORD"-flags", G_TYPE_UINT, FALSE },
{ NULL, G_TYPE_NONE, FALSE }
};
@@ -793,6 +794,23 @@ free_pppd_args (GPtrArray *args)
g_ptr_array_free (args, TRUE);
}
+static gboolean
+str_to_int (const char *str, long int *out)
+{
+ long int tmp_int;
+
+ if (!str)
+ return FALSE;
+
+ errno = 0;
+ tmp_int = strtol (str, NULL, 10);
+ if (errno == 0) {
+ *out = tmp_int;
+ return TRUE;
+ }
+ return FALSE;
+}
+
static GPtrArray *
construct_pppd_args (NMPptpPlugin *plugin,
NMSettingVPN *s_vpn,
@@ -932,15 +950,13 @@ construct_pppd_args (NMPptpPlugin *plugin,
}
value = nm_setting_vpn_get_data_item (s_vpn, NM_PPTP_KEY_LCP_ECHO_INTERVAL);
- if (value && strlen (value)) {
+ if (value && *value) {
long int tmp_int;
/* Convert to integer and then back to string for security's sake
* because strtol ignores some leading and trailing characters.
*/
- errno = 0;
- tmp_int = strtol (value, NULL, 10);
- if (errno == 0) {
+ if (str_to_int (value, &tmp_int)) {
g_ptr_array_add (args, (gpointer) g_strdup ("lcp-echo-interval"));
g_ptr_array_add (args, (gpointer) g_strdup_printf ("%ld", tmp_int));
} else {
@@ -951,6 +967,16 @@ construct_pppd_args (NMPptpPlugin *plugin,
g_ptr_array_add (args, (gpointer) g_strdup ("0"));
}
+ value = nm_setting_vpn_get_data_item (s_vpn, NM_PPTP_KEY_UNIT_NUM);
+ if (value && *value) {
+ long int tmp_int;
+ if (str_to_int (value, &tmp_int)) {
+ g_ptr_array_add (args, (gpointer) g_strdup ("unit"));
+ g_ptr_array_add (args, (gpointer) g_strdup_printf ("%ld", tmp_int));
+ } else
+ g_warning ("failed to convert unit value '%s'", value);
+ }
+
g_ptr_array_add (args, (gpointer) g_strdup ("plugin"));
g_ptr_array_add (args, (gpointer) g_strdup (NM_PPTP_PPPD_PLUGIN));
diff --git a/src/nm-pptp-service.h b/src/nm-pptp-service.h
index b9e0b8b..ee8a575 100644
--- a/src/nm-pptp-service.h
+++ b/src/nm-pptp-service.h
@@ -65,6 +65,7 @@
#define NM_PPTP_KEY_NO_VJ_COMP "no-vj-comp"
#define NM_PPTP_KEY_LCP_ECHO_FAILURE "lcp-echo-failure"
#define NM_PPTP_KEY_LCP_ECHO_INTERVAL "lcp-echo-interval"
+#define NM_PPTP_KEY_UNIT_NUM "unit"
typedef struct {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]