summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2014-10-24 09:39:33 -0400
committerDan Winship <danw@gnome.org>2014-10-24 09:39:33 -0400
commit8d315a185704b17d07106a5110b58464fc8c447a (patch)
tree6b80474657376883df9adcdfd08232eb7622a64a
parent0df86aebd83ac306d7c5323b7e2309265c695c67 (diff)
downloadNetworkManager-danw/vpnplugin-bgo739072.tar.gz
libnm: merge nm-vpn-plugin-utils into nm-vpn-plugin-olddanw/vpnplugin-bgo739072
The new VPN plugin API will hopefully simplify some the the tasks that are currently handled by nm-vpn-plugin-utils functions, so make those functions explicitly be part of the "old" API. (If we still want them in the new API we can just move them back out, and have the "_old_" versions just be wrappers around the undeprecated ones.)
-rw-r--r--libnm/Makefile.am2
-rw-r--r--libnm/libnm.ver4
-rw-r--r--libnm/nm-vpn-plugin-old.c165
-rw-r--r--libnm/nm-vpn-plugin-old.h10
-rw-r--r--libnm/nm-vpn-plugin-utils.c188
-rw-r--r--libnm/nm-vpn-plugin-utils.h43
6 files changed, 177 insertions, 235 deletions
diff --git a/libnm/Makefile.am b/libnm/Makefile.am
index 21390ece99..e14dc83a3f 100644
--- a/libnm/Makefile.am
+++ b/libnm/Makefile.am
@@ -54,7 +54,6 @@ libnminclude_hfiles = \
nm-types.h \
nm-vpn-connection.h \
nm-vpn-plugin-ui-interface.h \
- nm-vpn-plugin-utils.h \
nm-wimax-nsp.h
libnminclude_nointrospect_hfiles = \
@@ -106,7 +105,6 @@ libnm_la_csources = \
nm-vpn-connection.c \
nm-vpn-plugin-old.c \
nm-vpn-plugin-ui-interface.c \
- nm-vpn-plugin-utils.c \
nm-wimax-nsp.c
libnm_la_SOURCES = \
diff --git a/libnm/libnm.ver b/libnm/libnm.ver
index c8fd09065d..64a3b507df 100644
--- a/libnm/libnm.ver
+++ b/libnm/libnm.ver
@@ -862,8 +862,10 @@ global:
nm_vpn_plugin_old_disconnect;
nm_vpn_plugin_old_failure;
nm_vpn_plugin_old_get_connection;
+ nm_vpn_plugin_old_get_secret_flags;
nm_vpn_plugin_old_get_state;
nm_vpn_plugin_old_get_type;
+ nm_vpn_plugin_old_read_vpn_details;
nm_vpn_plugin_old_secrets_required;
nm_vpn_plugin_old_set_ip4_config;
nm_vpn_plugin_old_set_login_banner;
@@ -879,8 +881,6 @@ global:
nm_vpn_plugin_ui_widget_interface_get_type;
nm_vpn_plugin_ui_widget_interface_get_widget;
nm_vpn_plugin_ui_widget_interface_update_connection;
- nm_vpn_plugin_utils_get_secret_flags;
- nm_vpn_plugin_utils_read_vpn_details;
nm_vpn_service_state_get_type;
nm_wep_key_type_get_type;
nm_wimax_nsp_connection_valid;
diff --git a/libnm/nm-vpn-plugin-old.c b/libnm/nm-vpn-plugin-old.c
index dc5f82ef57..28e6b7a587 100644
--- a/libnm/nm-vpn-plugin-old.c
+++ b/libnm/nm-vpn-plugin-old.c
@@ -23,7 +23,9 @@
* will be a new "NMVpnPlugin" class to replace it.
*/
+#include <errno.h>
#include <signal.h>
+#include <stdlib.h>
#include <glib/gi18n.h>
#include <gio/gio.h>
@@ -34,6 +36,7 @@
#include "nm-utils.h"
#include "nm-connection.h"
#include "nm-dbus-helpers.h"
+#include "nm-core-internal.h"
#include "nmdbus-vpn-plugin.h"
@@ -609,6 +612,168 @@ nm_vpn_plugin_old_secrets_required (NMVpnPluginOld *plugin,
/***************************************************************/
+#define DATA_KEY_TAG "DATA_KEY="
+#define DATA_VAL_TAG "DATA_VAL="
+#define SECRET_KEY_TAG "SECRET_KEY="
+#define SECRET_VAL_TAG "SECRET_VAL="
+
+static void
+free_secret (gpointer data)
+{
+ char *secret = data;
+
+ memset (secret, 0, strlen (secret));
+ g_free (secret);
+}
+
+/**
+ * nm_vpn_plugin_old_read_vpn_details:
+ * @fd: file descriptor to read from, usually stdin (0)
+ * @out_data: (out) (transfer full): on successful return, a hash table
+ * (mapping char*:char*) containing the key/value pairs of VPN data items
+ * @out_secrets: (out) (transfer full): on successful return, a hash table
+ * (mapping char*:char*) containing the key/value pairsof VPN secrets
+ *
+ * Parses key/value pairs from a file descriptor (normally stdin) passed by
+ * an applet when the applet calls the authentication dialog of the VPN plugin.
+ *
+ * Returns: %TRUE if reading values was successful, %FALSE if not
+ **/
+gboolean
+nm_vpn_plugin_old_read_vpn_details (int fd,
+ GHashTable **out_data,
+ GHashTable **out_secrets)
+{
+ GHashTable *data, *secrets;
+ gboolean success = FALSE;
+ char *key = NULL, *val = NULL;
+ GString *line;
+ gchar c;
+
+ if (out_data)
+ g_return_val_if_fail (*out_data == NULL, FALSE);
+ if (out_secrets)
+ g_return_val_if_fail (*out_secrets == NULL, FALSE);
+
+ data = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ secrets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, free_secret);
+
+ line = g_string_new (NULL);
+
+ /* Read stdin for data and secret items until we get a DONE */
+ while (1) {
+ ssize_t nr;
+ GHashTable *hash = NULL;
+
+ errno = 0;
+ nr = read (fd, &c, 1);
+ if (nr == -1) {
+ if (errno == EAGAIN) {
+ g_usleep (100);
+ continue;
+ }
+ break;
+ }
+
+ if (c != '\n') {
+ g_string_append_c (line, c);
+ continue;
+ }
+
+ /* Check for the finish marker */
+ if (strcmp (line->str, "DONE") == 0)
+ break;
+
+ /* Otherwise it's a data/secret item */
+ if (strncmp (line->str, DATA_KEY_TAG, strlen (DATA_KEY_TAG)) == 0) {
+ hash = data;
+ key = g_strdup (line->str + strlen (DATA_KEY_TAG));
+ } else if (strncmp (line->str, DATA_VAL_TAG, strlen (DATA_VAL_TAG)) == 0) {
+ hash = data;
+ val = g_strdup (line->str + strlen (DATA_VAL_TAG));
+ } else if (strncmp (line->str, SECRET_KEY_TAG, strlen (SECRET_KEY_TAG)) == 0) {
+ hash = secrets;
+ key = g_strdup (line->str + strlen (SECRET_KEY_TAG));
+ } else if (strncmp (line->str, SECRET_VAL_TAG, strlen (SECRET_VAL_TAG)) == 0) {
+ hash = secrets;
+ val = g_strdup (line->str + strlen (SECRET_VAL_TAG));
+ }
+ g_string_truncate (line, 0);
+
+ if (key && val && hash) {
+ g_hash_table_insert (hash, key, val);
+ key = NULL;
+ val = NULL;
+ success = TRUE; /* Got at least one value */
+ }
+ }
+
+ if (success) {
+ if (out_data)
+ *out_data = data;
+ else
+ g_hash_table_destroy (data);
+
+ if (out_secrets)
+ *out_secrets = secrets;
+ else
+ g_hash_table_destroy (secrets);
+ } else {
+ g_hash_table_destroy (data);
+ g_hash_table_destroy (secrets);
+ }
+
+ g_string_free (line, TRUE);
+ return success;
+}
+
+/**
+ * nm_vpn_plugin_old_get_secret_flags:
+ * @data: hash table containing VPN key/value pair data items
+ * @secret_name: VPN secret key name for which to retrieve flags for
+ * @out_flags: (out): on success, the flags associated with @secret_name
+ *
+ * Given a VPN secret key name, attempts to find the corresponding flags data
+ * item in @data. If found, converts the flags data item to
+ * #NMSettingSecretFlags and returns it.
+ *
+ * Returns: %TRUE if the flag data item was found and successfully converted
+ * to flags, %FALSE if not
+ **/
+gboolean
+nm_vpn_plugin_old_get_secret_flags (GHashTable *data,
+ const char *secret_name,
+ NMSettingSecretFlags *out_flags)
+{
+ char *flag_name;
+ const char *val;
+ unsigned long tmp;
+ gboolean success = FALSE;
+
+ g_return_val_if_fail (data != NULL, FALSE);
+ g_return_val_if_fail (secret_name != NULL, FALSE);
+ g_return_val_if_fail (out_flags != NULL, FALSE);
+ g_return_val_if_fail (*out_flags == NM_SETTING_SECRET_FLAG_NONE, FALSE);
+
+ flag_name = g_strdup_printf ("%s-flags", secret_name);
+
+ /* Try new flags value first */
+ val = g_hash_table_lookup (data, flag_name);
+ if (val) {
+ errno = 0;
+ tmp = strtoul (val, NULL, 10);
+ if (errno == 0 && tmp <= NM_SETTING_SECRET_FLAGS_ALL) {
+ *out_flags = (NMSettingSecretFlags) tmp;
+ success = TRUE;
+ }
+ }
+
+ g_free (flag_name);
+ return success;
+}
+
+/***************************************************************/
+
static void
impl_vpn_plugin_old_disconnect (NMVpnPluginOld *plugin,
GDBusMethodInvocation *context,
diff --git a/libnm/nm-vpn-plugin-old.h b/libnm/nm-vpn-plugin-old.h
index c46d5c53a9..7fcc1c1c0a 100644
--- a/libnm/nm-vpn-plugin-old.h
+++ b/libnm/nm-vpn-plugin-old.h
@@ -121,6 +121,16 @@ void nm_vpn_plugin_old_set_ip6_config (NMVpnPluginOld *plugin,
gboolean nm_vpn_plugin_old_disconnect (NMVpnPluginOld *plugin,
GError **err);
+/* Utility functions */
+
+gboolean nm_vpn_plugin_old_read_vpn_details (int fd,
+ GHashTable **out_data,
+ GHashTable **out_secrets);
+
+gboolean nm_vpn_plugin_old_get_secret_flags (GHashTable *data,
+ const char *secret_name,
+ NMSettingSecretFlags *out_flags);
+
G_END_DECLS
#endif /* __NM_VPN_PLUGIN_OLD_H__ */
diff --git a/libnm/nm-vpn-plugin-utils.c b/libnm/nm-vpn-plugin-utils.c
deleted file mode 100644
index e82379c285..0000000000
--- a/libnm/nm-vpn-plugin-utils.c
+++ /dev/null
@@ -1,188 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
-/*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA.
- *
- * Copyright 2011 Red Hat, Inc.
- */
-
-#include <errno.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#include "nm-vpn-plugin-utils.h"
-#include "nm-vpn-plugin-old.h"
-#include "nm-core-internal.h"
-
-#define DATA_KEY_TAG "DATA_KEY="
-#define DATA_VAL_TAG "DATA_VAL="
-#define SECRET_KEY_TAG "SECRET_KEY="
-#define SECRET_VAL_TAG "SECRET_VAL="
-
-static void
-free_secret (gpointer data)
-{
- char *secret = data;
-
- memset (secret, 0, strlen (secret));
- g_free (secret);
-}
-
-/**
- * nm_vpn_plugin_utils_read_vpn_details:
- * @fd: file descriptor to read from, usually stdin (0)
- * @out_data: (out) (transfer full): on successful return, a hash table
- * (mapping char*:char*) containing the key/value pairs of VPN data items
- * @out_secrets: (out) (transfer full): on successful return, a hash table
- * (mapping char*:char*) containing the key/value pairsof VPN secrets
- *
- * Parses key/value pairs from a file descriptor (normally stdin) passed by
- * an applet when the applet calls the authentication dialog of the VPN plugin.
- *
- * Returns: %TRUE if reading values was successful, %FALSE if not
- **/
-gboolean
-nm_vpn_plugin_utils_read_vpn_details (int fd,
- GHashTable **out_data,
- GHashTable **out_secrets)
-{
- GHashTable *data, *secrets;
- gboolean success = FALSE;
- char *key = NULL, *val = NULL;
- GString *line;
- gchar c;
-
- if (out_data)
- g_return_val_if_fail (*out_data == NULL, FALSE);
- if (out_secrets)
- g_return_val_if_fail (*out_secrets == NULL, FALSE);
-
- data = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
- secrets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, free_secret);
-
- line = g_string_new (NULL);
-
- /* Read stdin for data and secret items until we get a DONE */
- while (1) {
- ssize_t nr;
- GHashTable *hash = NULL;
-
- errno = 0;
- nr = read (fd, &c, 1);
- if (nr == -1) {
- if (errno == EAGAIN) {
- g_usleep (100);
- continue;
- }
- break;
- }
-
- if (c != '\n') {
- g_string_append_c (line, c);
- continue;
- }
-
- /* Check for the finish marker */
- if (strcmp (line->str, "DONE") == 0)
- break;
-
- /* Otherwise it's a data/secret item */
- if (strncmp (line->str, DATA_KEY_TAG, strlen (DATA_KEY_TAG)) == 0) {
- hash = data;
- key = g_strdup (line->str + strlen (DATA_KEY_TAG));
- } else if (strncmp (line->str, DATA_VAL_TAG, strlen (DATA_VAL_TAG)) == 0) {
- hash = data;
- val = g_strdup (line->str + strlen (DATA_VAL_TAG));
- } else if (strncmp (line->str, SECRET_KEY_TAG, strlen (SECRET_KEY_TAG)) == 0) {
- hash = secrets;
- key = g_strdup (line->str + strlen (SECRET_KEY_TAG));
- } else if (strncmp (line->str, SECRET_VAL_TAG, strlen (SECRET_VAL_TAG)) == 0) {
- hash = secrets;
- val = g_strdup (line->str + strlen (SECRET_VAL_TAG));
- }
- g_string_truncate (line, 0);
-
- if (key && val && hash) {
- g_hash_table_insert (hash, key, val);
- key = NULL;
- val = NULL;
- success = TRUE; /* Got at least one value */
- }
- }
-
- if (success) {
- if (out_data)
- *out_data = data;
- else
- g_hash_table_destroy (data);
-
- if (out_secrets)
- *out_secrets = secrets;
- else
- g_hash_table_destroy (secrets);
- } else {
- g_hash_table_destroy (data);
- g_hash_table_destroy (secrets);
- }
-
- g_string_free (line, TRUE);
- return success;
-}
-
-/**
- * nm_vpn_plugin_utils_get_secret_flags:
- * @data: hash table containing VPN key/value pair data items
- * @secret_name: VPN secret key name for which to retrieve flags for
- * @out_flags: (out): on success, the flags associated with @secret_name
- *
- * Given a VPN secret key name, attempts to find the corresponding flags data
- * item in @data. If found, converts the flags data item to
- * #NMSettingSecretFlags and returns it.
- *
- * Returns: %TRUE if the flag data item was found and successfully converted
- * to flags, %FALSE if not
- **/
-gboolean
-nm_vpn_plugin_utils_get_secret_flags (GHashTable *data,
- const char *secret_name,
- NMSettingSecretFlags *out_flags)
-{
- char *flag_name;
- const char *val;
- unsigned long tmp;
- gboolean success = FALSE;
-
- g_return_val_if_fail (data != NULL, FALSE);
- g_return_val_if_fail (secret_name != NULL, FALSE);
- g_return_val_if_fail (out_flags != NULL, FALSE);
- g_return_val_if_fail (*out_flags == NM_SETTING_SECRET_FLAG_NONE, FALSE);
-
- flag_name = g_strdup_printf ("%s-flags", secret_name);
-
- /* Try new flags value first */
- val = g_hash_table_lookup (data, flag_name);
- if (val) {
- errno = 0;
- tmp = strtoul (val, NULL, 10);
- if (errno == 0 && tmp <= NM_SETTING_SECRET_FLAGS_ALL) {
- *out_flags = (NMSettingSecretFlags) tmp;
- success = TRUE;
- }
- }
-
- g_free (flag_name);
- return success;
-}
diff --git a/libnm/nm-vpn-plugin-utils.h b/libnm/nm-vpn-plugin-utils.h
deleted file mode 100644
index 5073d1ee0b..0000000000
--- a/libnm/nm-vpn-plugin-utils.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
-/*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA.
- *
- * Copyright 2011 Red Hat, Inc.
- */
-
-#ifndef __NM_VPN_PLUGIN_UTILS_H__
-#define __NM_VPN_PLUGIN_UTILS_H__
-
-#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION)
-#error "Only <NetworkManager.h> can be included directly."
-#endif
-
-#include <glib.h>
-#include <nm-setting.h>
-
-G_BEGIN_DECLS
-
-gboolean nm_vpn_plugin_utils_read_vpn_details (int fd,
- GHashTable **out_data,
- GHashTable **out_secrets);
-
-gboolean nm_vpn_plugin_utils_get_secret_flags (GHashTable *data,
- const char *secret_name,
- NMSettingSecretFlags *out_flags);
-
-G_END_DECLS
-
-#endif /* __NM_VPN_PLUGIN_UTILS_H__ */