From 4b288136e1893a7ac21f04370008e37feb3cfac9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 15 Jun 2016 15:29:10 +0200 Subject: [PATCH 1/5] shared: move shared files to subdirectory "shared/nm-utils/" The "shared" directory contains files that are possibly used by all components of NetworkManager repository. Some of these files are even copied as-is to other projects (VPN plugins, nm-applet) and used there without modification. Move those files to a separate directory. By moving them to a common directory, it is clearer that they belong together. Also, you can easier compare the copied versions to their original via $ diff -r ./shared/nm-utils/ /path/to/nm-vpn-plugin/shared/nm-utils/ --- callouts/tests/test-dispatcher-envp.c | 2 +- libnm-core/Makefile.libnm-core | 4 ++-- libnm-core/tests/test-compare.c | 2 +- libnm-core/tests/test-crypto.c | 2 +- libnm-core/tests/test-general.c | 2 +- libnm-core/tests/test-keyfile.c | 2 +- libnm-core/tests/test-secrets.c | 2 +- libnm-core/tests/test-setting-8021x.c | 2 +- libnm-core/tests/test-setting-bond.c | 2 +- libnm-core/tests/test-setting-dcb.c | 2 +- libnm-core/tests/test-settings-defaults.c | 2 +- libnm-util/Makefile.am | 4 ++-- libnm-util/tests/test-crypto.c | 2 +- libnm-util/tests/test-general.c | 2 +- libnm-util/tests/test-secrets.c | 2 +- libnm-util/tests/test-setting-8021x.c | 2 +- libnm-util/tests/test-setting-dcb.c | 2 +- libnm-util/tests/test-settings-defaults.c | 2 +- libnm/nm-vpn-service-plugin.c | 2 +- po/POTFILES.in | 2 +- po/POTFILES.skip | 2 +- shared/Makefile.am | 15 ++++++++------- shared/nm-default.h | 8 ++++---- shared/nm-test-libnm-utils.h | 2 +- shared/{ => nm-utils}/gsystem-local-alloc.h | 0 shared/{ => nm-utils}/nm-glib.h | 0 shared/{ => nm-utils}/nm-macros-internal.h | 0 shared/{ => nm-utils}/nm-shared-utils.c | 0 shared/{ => nm-utils}/nm-shared-utils.h | 0 shared/{ => nm-utils}/nm-test-utils.h | 0 shared/{ => nm-utils}/nm-vpn-editor-plugin-call.h | 0 src/nm-test-utils-core.h | 2 +- 32 files changed, 37 insertions(+), 36 deletions(-) rename shared/{ => nm-utils}/gsystem-local-alloc.h (100%) rename shared/{ => nm-utils}/nm-glib.h (100%) rename shared/{ => nm-utils}/nm-macros-internal.h (100%) rename shared/{ => nm-utils}/nm-shared-utils.c (100%) rename shared/{ => nm-utils}/nm-shared-utils.h (100%) rename shared/{ => nm-utils}/nm-test-utils.h (100%) rename shared/{ => nm-utils}/nm-vpn-editor-plugin-call.h (100%) diff --git a/callouts/tests/test-dispatcher-envp.c b/callouts/tests/test-dispatcher-envp.c index 9cdaa3b5c6..83e84d7472 100644 --- a/callouts/tests/test-dispatcher-envp.c +++ b/callouts/tests/test-dispatcher-envp.c @@ -28,7 +28,7 @@ #include "nm-dispatcher-utils.h" #include "nm-dispatcher-api.h" -#include "nm-test-utils.h" +#include "nm-utils/nm-test-utils.h" /*******************************************/ diff --git a/libnm-core/Makefile.libnm-core b/libnm-core/Makefile.libnm-core index 0038ce23d6..52c71da5b7 100644 --- a/libnm-core/Makefile.libnm-core +++ b/libnm-core/Makefile.libnm-core @@ -52,7 +52,7 @@ libnm_core_headers = \ $(core)/nm-vpn-plugin-info.h libnm_core_private_headers = \ - $(top_builddir)/shared/nm-shared-utils.h \ + $(top_builddir)/shared/nm-utils/nm-shared-utils.h \ $(core)/crypto.h \ $(core)/nm-connection-private.h \ $(core)/nm-core-internal.h \ @@ -64,7 +64,7 @@ libnm_core_private_headers = \ $(core)/nm-utils-private.h libnm_core_sources = \ - $(top_builddir)/shared/nm-shared-utils.c \ + $(top_builddir)/shared/nm-utils/nm-shared-utils.c \ $(core_build)/nm-core-enum-types.c \ $(core)/crypto.c \ $(core)/nm-connection.c \ diff --git a/libnm-core/tests/test-compare.c b/libnm-core/tests/test-compare.c index dca5c7d3d1..7f2ba98095 100644 --- a/libnm-core/tests/test-compare.c +++ b/libnm-core/tests/test-compare.c @@ -26,7 +26,7 @@ #include "nm-property-compare.h" -#include "nm-test-utils.h" +#include "nm-utils/nm-test-utils.h" static void compare_ints (void) diff --git a/libnm-core/tests/test-crypto.c b/libnm-core/tests/test-crypto.c index bd87c710ca..9bab985f72 100644 --- a/libnm-core/tests/test-crypto.c +++ b/libnm-core/tests/test-crypto.c @@ -33,7 +33,7 @@ #include "nm-errors.h" #include "nm-core-internal.h" -#include "nm-test-utils.h" +#include "nm-utils/nm-test-utils.h" #if 0 static const char *pem_rsa_key_begin = "-----BEGIN RSA PRIVATE KEY-----"; diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index 39e9c1aff3..9aaf82977d 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -62,7 +62,7 @@ #include "test-general-enums.h" -#include "nm-test-utils.h" +#include "nm-utils/nm-test-utils.h" /* When passing a "bool" typed argument to a variadic function that * expects a gboolean, the compiler will promote the integer type diff --git a/libnm-core/tests/test-keyfile.c b/libnm-core/tests/test-keyfile.c index 92b6c1f56c..ecb7cd5a67 100644 --- a/libnm-core/tests/test-keyfile.c +++ b/libnm-core/tests/test-keyfile.c @@ -28,7 +28,7 @@ #include "nm-setting-wired.h" #include "nm-setting-8021x.h" -#include "nm-test-utils.h" +#include "nm-utils/nm-test-utils.h" #define TEST_WIRED_TLS_CA_CERT TEST_CERT_DIR"/test-ca-cert.pem" diff --git a/libnm-core/tests/test-secrets.c b/libnm-core/tests/test-secrets.c index 7b37d09e92..0149348dbe 100644 --- a/libnm-core/tests/test-secrets.c +++ b/libnm-core/tests/test-secrets.c @@ -38,7 +38,7 @@ #include "nm-utils.h" #include "nm-core-internal.h" -#include "nm-test-utils.h" +#include "nm-utils/nm-test-utils.h" #define TEST_NEED_SECRETS_EAP_TLS_CA_CERT TEST_CERT_DIR "/test_ca_cert.pem" #define TEST_NEED_SECRETS_EAP_TLS_CLIENT_CERT TEST_CERT_DIR "/test_key_and_cert.pem" diff --git a/libnm-core/tests/test-setting-8021x.c b/libnm-core/tests/test-setting-8021x.c index 56563a6fb6..268a9f52d9 100644 --- a/libnm-core/tests/test-setting-8021x.c +++ b/libnm-core/tests/test-setting-8021x.c @@ -27,7 +27,7 @@ #include "nm-setting-connection.h" #include "nm-setting-8021x.h" -#include "nm-test-utils.h" +#include "nm-utils/nm-test-utils.h" static void compare_blob_data (const char *test, diff --git a/libnm-core/tests/test-setting-bond.c b/libnm-core/tests/test-setting-bond.c index a6afa1c865..91a8199719 100644 --- a/libnm-core/tests/test-setting-bond.c +++ b/libnm-core/tests/test-setting-bond.c @@ -26,7 +26,7 @@ #include "nm-setting-connection.h" #include "nm-errors.h" -#include "nm-test-utils.h" +#include "nm-utils/nm-test-utils.h" static void create_bond_connection (NMConnection **con, NMSettingBond **s_bond) diff --git a/libnm-core/tests/test-setting-dcb.c b/libnm-core/tests/test-setting-dcb.c index 09cf8d9837..55c1c5162c 100644 --- a/libnm-core/tests/test-setting-dcb.c +++ b/libnm-core/tests/test-setting-dcb.c @@ -28,7 +28,7 @@ #include "nm-connection.h" #include "nm-errors.h" -#include "nm-test-utils.h" +#include "nm-utils/nm-test-utils.h" #define DCB_FLAGS_ALL (NM_SETTING_DCB_FLAG_ENABLE | \ NM_SETTING_DCB_FLAG_ADVERTISE | \ diff --git a/libnm-core/tests/test-settings-defaults.c b/libnm-core/tests/test-settings-defaults.c index 366910ac2a..95570b0380 100644 --- a/libnm-core/tests/test-settings-defaults.c +++ b/libnm-core/tests/test-settings-defaults.c @@ -38,7 +38,7 @@ #include "nm-setting-wireless.h" #include "nm-setting-wireless-security.h" -#include "nm-test-utils.h" +#include "nm-utils/nm-test-utils.h" static void test_defaults (GType type, const char *name) diff --git a/libnm-util/Makefile.am b/libnm-util/Makefile.am index 0d5a0d46c1..466e475f23 100644 --- a/libnm-util/Makefile.am +++ b/libnm-util/Makefile.am @@ -62,7 +62,7 @@ nodist_libnm_util_include_HEADERS = \ nm-utils-enum-types.h libnm_util_la_private_headers = \ - $(top_builddir)/shared/nm-shared-utils.h \ + $(top_builddir)/shared/nm-utils/nm-shared-utils.h \ crypto.h \ nm-dbus-glib-types.h \ nm-gvaluearray-compat.h \ @@ -71,7 +71,7 @@ libnm_util_la_private_headers = \ nm-utils-private.h libnm_util_la_csources = \ - $(top_builddir)/shared/nm-shared-utils.c \ + $(top_builddir)/shared/nm-utils/nm-shared-utils.c \ crypto.c \ nm-connection.c \ nm-param-spec-specialized.c \ diff --git a/libnm-util/tests/test-crypto.c b/libnm-util/tests/test-crypto.c index a1c7648fce..643418d2fb 100644 --- a/libnm-util/tests/test-crypto.c +++ b/libnm-util/tests/test-crypto.c @@ -31,7 +31,7 @@ #include "crypto.h" #include "nm-utils.h" -#include "nm-test-utils.h" +#include "nm-utils/nm-test-utils.h" #if 0 static const char *pem_rsa_key_begin = "-----BEGIN RSA PRIVATE KEY-----"; diff --git a/libnm-util/tests/test-general.c b/libnm-util/tests/test-general.c index 10fed337f3..8373ae1197 100644 --- a/libnm-util/tests/test-general.c +++ b/libnm-util/tests/test-general.c @@ -47,7 +47,7 @@ #include "nm-utils.h" #include "nm-dbus-glib-types.h" -#include "nm-test-utils.h" +#include "nm-utils/nm-test-utils.h" static void vpn_check_func (const char *key, const char *value, gpointer user_data) diff --git a/libnm-util/tests/test-secrets.c b/libnm-util/tests/test-secrets.c index 0d451788e5..2631509cf3 100644 --- a/libnm-util/tests/test-secrets.c +++ b/libnm-util/tests/test-secrets.c @@ -37,7 +37,7 @@ #include "nm-setting-pppoe.h" #include "nm-setting-vpn.h" -#include "nm-test-utils.h" +#include "nm-utils/nm-test-utils.h" #define TEST_NEED_SECRETS_EAP_TLS_CA_CERT TEST_CERT_DIR "/test_ca_cert.pem" #define TEST_NEED_SECRETS_EAP_TLS_CLIENT_CERT TEST_CERT_DIR "/test_key_and_cert.pem" diff --git a/libnm-util/tests/test-setting-8021x.c b/libnm-util/tests/test-setting-8021x.c index e5bddf4cd9..a0219639c5 100644 --- a/libnm-util/tests/test-setting-8021x.c +++ b/libnm-util/tests/test-setting-8021x.c @@ -27,7 +27,7 @@ #include "nm-setting-connection.h" #include "nm-setting-8021x.h" -#include "nm-test-utils.h" +#include "nm-utils/nm-test-utils.h" static void compare_blob_data (const char *test, diff --git a/libnm-util/tests/test-setting-dcb.c b/libnm-util/tests/test-setting-dcb.c index fb44278b6c..ee0c997fb1 100644 --- a/libnm-util/tests/test-setting-dcb.c +++ b/libnm-util/tests/test-setting-dcb.c @@ -27,7 +27,7 @@ #include "nm-default.h" #include "nm-setting-dcb.h" -#include "nm-test-utils.h" +#include "nm-utils/nm-test-utils.h" #define DCB_FLAGS_ALL (NM_SETTING_DCB_FLAG_ENABLE | \ NM_SETTING_DCB_FLAG_ADVERTISE | \ diff --git a/libnm-util/tests/test-settings-defaults.c b/libnm-util/tests/test-settings-defaults.c index 95ff070955..0bd4feee58 100644 --- a/libnm-util/tests/test-settings-defaults.c +++ b/libnm-util/tests/test-settings-defaults.c @@ -38,7 +38,7 @@ #include "nm-setting-wireless.h" #include "nm-setting-wireless-security.h" -#include "nm-test-utils.h" +#include "nm-utils/nm-test-utils.h" static void test_defaults (GType type, const char *name) diff --git a/libnm/nm-vpn-service-plugin.c b/libnm/nm-vpn-service-plugin.c index df99eb28d9..6431629669 100644 --- a/libnm/nm-vpn-service-plugin.c +++ b/libnm/nm-vpn-service-plugin.c @@ -1312,5 +1312,5 @@ nm_vpn_service_plugin_initable_iface_init (GInitableIface *iface) /* this header is intended to be copied to users of nm_vpn_editor_plugin_call(), * to simplify invocation of generic functions. Include it here, to complile * the code. */ -#include "nm-vpn-editor-plugin-call.h" +#include "nm-utils/nm-vpn-editor-plugin-call.h" diff --git a/po/POTFILES.in b/po/POTFILES.in index ded6d5d549..7d1d1ba331 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -140,7 +140,7 @@ libnm/nm-remote-settings.c libnm/nm-vpn-plugin-old.c libnm/nm-vpn-service-plugin.c policy/org.freedesktop.NetworkManager.policy.in.in -shared/nm-shared-utils.c +shared/nm-utils/nm-shared-utils.c src/NetworkManagerUtils.c src/main.c src/main-utils.c diff --git a/po/POTFILES.skip b/po/POTFILES.skip index 842f22a568..7bf60bea5b 100644 --- a/po/POTFILES.skip +++ b/po/POTFILES.skip @@ -6,6 +6,6 @@ vpn-daemons/openvpn vpn-daemons/pptp vpn-daemons/vpnc contrib/fedora/rpm/ -shared/nm-vpn-editor-plugin-call.h +shared/nm-utils/nm-vpn-editor-plugin-call.h # https://bugs.launchpad.net/intltool/+bug/1117944 sub/policy/org.freedesktop.NetworkManager.policy.in diff --git a/shared/Makefile.am b/shared/Makefile.am index 01818d0cd1..41df29a32b 100644 --- a/shared/Makefile.am +++ b/shared/Makefile.am @@ -1,16 +1,17 @@ EXTRA_DIST = \ - gsystem-local-alloc.h \ + nm-utils/gsystem-local-alloc.h \ + nm-utils/nm-glib.h \ + nm-utils/nm-macros-internal.h \ + nm-utils/nm-shared-utils.c \ + nm-utils/nm-shared-utils.h \ + nm-utils/nm-test-utils.h \ + nm-utils/nm-vpn-editor-plugin-call.h \ nm-common-macros.h \ nm-dbus-compat.h \ nm-default.h \ - nm-glib.h \ - nm-macros-internal.h \ - nm-shared-utils.c \ - nm-shared-utils.h \ nm-test-libnm-utils.h \ - nm-test-utils.h \ nm-test-utils-impl.c \ nm-version-macros.h.in \ - nm-vpn-editor-plugin-call.h + $(NULL) CLEANFILES=nm-version.h diff --git a/shared/nm-default.h b/shared/nm-default.h index 5d7c8f141c..bcd3d420c2 100644 --- a/shared/nm-default.h +++ b/shared/nm-default.h @@ -98,11 +98,11 @@ _nm_g_return_if_fail_warning (const char *log_domain, /*****************************************************************************/ -#include "nm-glib.h" +#include "nm-utils/nm-glib.h" #include "nm-version.h" -#include "gsystem-local-alloc.h" -#include "nm-macros-internal.h" -#include "nm-shared-utils.h" +#include "nm-utils/gsystem-local-alloc.h" +#include "nm-utils/nm-macros-internal.h" +#include "nm-utils/nm-shared-utils.h" /*****************************************************************************/ diff --git a/shared/nm-test-libnm-utils.h b/shared/nm-test-libnm-utils.h index 8d111003aa..192c089e10 100644 --- a/shared/nm-test-libnm-utils.h +++ b/shared/nm-test-libnm-utils.h @@ -20,7 +20,7 @@ #include "NetworkManager.h" -#include "nm-test-utils.h" +#include "nm-utils/nm-test-utils.h" /*****************************************************************************/ diff --git a/shared/gsystem-local-alloc.h b/shared/nm-utils/gsystem-local-alloc.h similarity index 100% rename from shared/gsystem-local-alloc.h rename to shared/nm-utils/gsystem-local-alloc.h diff --git a/shared/nm-glib.h b/shared/nm-utils/nm-glib.h similarity index 100% rename from shared/nm-glib.h rename to shared/nm-utils/nm-glib.h diff --git a/shared/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h similarity index 100% rename from shared/nm-macros-internal.h rename to shared/nm-utils/nm-macros-internal.h diff --git a/shared/nm-shared-utils.c b/shared/nm-utils/nm-shared-utils.c similarity index 100% rename from shared/nm-shared-utils.c rename to shared/nm-utils/nm-shared-utils.c diff --git a/shared/nm-shared-utils.h b/shared/nm-utils/nm-shared-utils.h similarity index 100% rename from shared/nm-shared-utils.h rename to shared/nm-utils/nm-shared-utils.h diff --git a/shared/nm-test-utils.h b/shared/nm-utils/nm-test-utils.h similarity index 100% rename from shared/nm-test-utils.h rename to shared/nm-utils/nm-test-utils.h diff --git a/shared/nm-vpn-editor-plugin-call.h b/shared/nm-utils/nm-vpn-editor-plugin-call.h similarity index 100% rename from shared/nm-vpn-editor-plugin-call.h rename to shared/nm-utils/nm-vpn-editor-plugin-call.h diff --git a/src/nm-test-utils-core.h b/src/nm-test-utils-core.h index 8fd3be55ae..f5118398d3 100644 --- a/src/nm-test-utils-core.h +++ b/src/nm-test-utils-core.h @@ -26,7 +26,7 @@ #define _NMTST_INSIDE_CORE 1 -#include "nm-test-utils.h" +#include "nm-utils/nm-test-utils.h" /*****************************************************************************/ From 5d55492bac24677f706f048eab01af5ed84a761c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 15 Jun 2016 15:40:48 +0200 Subject: [PATCH 2/5] shared: add "nm-utils/nm-vpn-plugin-utils.h" This file is only used by plugins and copied between them. It's purpose is to contain general utility functions that are only relevant for implementing NetworkManager's VPN plugins. In principle the utility functions could be part of libnm, however, there are a few problems with that: - if they are part of libnm, adding and using a new utility function requires the plugin to bump the required libnm version. Since you usally can work around/reimplement utility functions, this results in not using the API from libnm, not adding the API to libnm, and reimplementing it over and over in the plugin. - plugins compile both against libnm and libnm-glib. Thus, either the utility function would also be needed in libnm-glib, or again, it is not usable by the plugin. We must avoid that the utility functions diverge and no local modifications to these files should be made in the plugin. Instead, one special location of the utility functions shall be extended and re-imported (copied) to the plugin as needed. Add the files to NetworkManager's repository. Although they are not needed for NetworkManager itself, they are a different API provided by NetworkManager. An API that is reused and shared by copying the files around. --- po/POTFILES.skip | 1 + shared/Makefile.am | 2 + shared/nm-utils/nm-vpn-plugin-utils.c | 130 ++++++++++++++++++++++++++ shared/nm-utils/nm-vpn-plugin-utils.h | 42 +++++++++ 4 files changed, 175 insertions(+) create mode 100644 shared/nm-utils/nm-vpn-plugin-utils.c create mode 100644 shared/nm-utils/nm-vpn-plugin-utils.h diff --git a/po/POTFILES.skip b/po/POTFILES.skip index 7bf60bea5b..1d7880e800 100644 --- a/po/POTFILES.skip +++ b/po/POTFILES.skip @@ -7,5 +7,6 @@ vpn-daemons/pptp vpn-daemons/vpnc contrib/fedora/rpm/ shared/nm-utils/nm-vpn-editor-plugin-call.h +shared/nm-utils/nm-vpn-plugin-utils.c # https://bugs.launchpad.net/intltool/+bug/1117944 sub/policy/org.freedesktop.NetworkManager.policy.in diff --git a/shared/Makefile.am b/shared/Makefile.am index 41df29a32b..be2f777ee6 100644 --- a/shared/Makefile.am +++ b/shared/Makefile.am @@ -6,6 +6,8 @@ EXTRA_DIST = \ nm-utils/nm-shared-utils.h \ nm-utils/nm-test-utils.h \ nm-utils/nm-vpn-editor-plugin-call.h \ + nm-utils/nm-vpn-plugin-utils.c \ + nm-utils/nm-vpn-plugin-utils.h \ nm-common-macros.h \ nm-dbus-compat.h \ nm-default.h \ diff --git a/shared/nm-utils/nm-vpn-plugin-utils.c b/shared/nm-utils/nm-vpn-plugin-utils.c new file mode 100644 index 0000000000..772aa39aea --- /dev/null +++ b/shared/nm-utils/nm-vpn-plugin-utils.c @@ -0,0 +1,130 @@ +/* -*- 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 2016 Red Hat, Inc. + */ + +#include "nm-default.h" + +#include "nm-vpn-plugin-utils.h" + +#include + +/*****************************************************************************/ + +NMVpnEditor * +nm_vpn_plugin_utils_load_editor (const char *module_name, + const char *factory_name, + NMVpnPluginUtilsEditorFactory editor_factory, + NMVpnEditorPlugin *editor_plugin, + NMConnection *connection, + gpointer user_data, + GError **error) + +{ + static struct { + gpointer factory; + void *dl_module; + char *module_name; + char *factory_name; + } cached = { 0 }; + NMVpnEditor *editor; + + g_return_val_if_fail (module_name && g_path_is_absolute (module_name), NULL); + g_return_val_if_fail (factory_name && factory_name[0], NULL); + g_return_val_if_fail (editor_factory, NULL); + g_return_val_if_fail (NM_IS_VPN_EDITOR_PLUGIN (editor_plugin), NULL); + g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); + g_return_val_if_fail (!error || !*error, NULL); + + /* we really expect this function to be called with unchanging @module_name + * and @factory_name. And we only want to load the module once, hence it would + * be more complicated to accept changing @module_name/@factory_name arguments. + * + * The reason for only loading once is that due to glib types, we cannot create a + * certain type-name more then once, so loading the same module or another version + * of the same module will fail horribly as both try to create a GType with the same + * name. + * + * Only support loading once, any future calls will reuse the handle. To simplify + * that, we enforce that the @factory_name and @module_name is the same. */ + if (cached.factory) { + g_return_val_if_fail (cached.dl_module, NULL); + g_return_val_if_fail (cached.factory_name && nm_streq0 (cached.factory_name, factory_name), NULL); + g_return_val_if_fail (cached.module_name && nm_streq0 (cached.module_name, module_name), NULL); + } else { + gpointer factory; + void *dl_module; + + dl_module = dlopen (module_name, RTLD_LAZY | RTLD_LOCAL); + if (!dl_module) { + if (!g_file_test (module_name, G_FILE_TEST_EXISTS)) { + g_set_error (error, + G_FILE_ERROR, + G_FILE_ERROR_NOENT, + _("missing plugin file \"%s\""), module_name); + return NULL; + } + g_set_error (error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_FAILED, + _("cannot load editor plugin: %s"), dlerror ()); + return NULL; + } + + factory = dlsym (dl_module, factory_name); + if (!factory) { + g_set_error (error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_FAILED, + _("cannot load factory %s from plugin: %s"), + factory_name, dlerror ()); + dlclose (dl_module); + return NULL; + } + + /* we cannot ever unload the module because it creates glib types, which + * cannot be unregistered. + * + * Thus we just leak the dl_module handle indefinitely. */ + cached.factory = factory; + cached.dl_module = dl_module; + cached.module_name = g_strdup (module_name); + cached.factory_name = g_strdup (factory_name); + } + + editor = editor_factory (cached.factory, + editor_plugin, + connection, + user_data, + error); + if (!editor) { + if (error && !*error ) { + g_set_error_literal (error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_FAILED, + _("unknown error creating editor instance")); + g_return_val_if_reached (NULL); + } + return NULL; + } + + g_return_val_if_fail (NM_IS_VPN_EDITOR (editor), NULL); + return editor; +} + diff --git a/shared/nm-utils/nm-vpn-plugin-utils.h b/shared/nm-utils/nm-vpn-plugin-utils.h new file mode 100644 index 0000000000..f3928d1eb1 --- /dev/null +++ b/shared/nm-utils/nm-vpn-plugin-utils.h @@ -0,0 +1,42 @@ +/* -*- 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 2016 Red Hat, Inc. + */ + +#ifndef __NM_VPN_PLUGIN_UTILS_H__ +#define __NM_VPN_PLUGIN_UTILS_H__ + +#include + +typedef NMVpnEditor *(NMVpnPluginUtilsEditorFactory) (gpointer factory, + NMVpnEditorPlugin *editor_plugin, + NMConnection *connection, + gpointer user_data, + GError **error); + +NMVpnEditor *nm_vpn_plugin_utils_load_editor (const char *module_name, + const char *factory_name, + NMVpnPluginUtilsEditorFactory editor_factory, + NMVpnEditorPlugin *editor_plugin, + NMConnection *connection, + gpointer user_data, + GError **error); + +#endif /* __NM_VPN_PLUGIN_UTILS_H__ */ + From 037462e90273ce25335d0a0a461748d3503ce13d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 15 Jun 2016 16:07:53 +0200 Subject: [PATCH 3/5] shared: include "gsystem-local-alloc.h" from "nm-glib.h" "nm-glib.h" is the most basic header, the one we cannot do without. ("nm-default.h", is already more generic, the one which every common source file in NetworkManager repository should include). Let "gsystem-local-alloc.h" be included by "nm-glib.h" and nowhere else. --- shared/nm-default.h | 1 - shared/nm-utils/nm-glib.h | 2 ++ shared/nm-utils/nm-vpn-editor-plugin-call.h | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/nm-default.h b/shared/nm-default.h index bcd3d420c2..6ff34aca52 100644 --- a/shared/nm-default.h +++ b/shared/nm-default.h @@ -100,7 +100,6 @@ _nm_g_return_if_fail_warning (const char *log_domain, #include "nm-utils/nm-glib.h" #include "nm-version.h" -#include "nm-utils/gsystem-local-alloc.h" #include "nm-utils/nm-macros-internal.h" #include "nm-utils/nm-shared-utils.h" diff --git a/shared/nm-utils/nm-glib.h b/shared/nm-utils/nm-glib.h index 5f8ebc7fdc..46a8bb2d9a 100644 --- a/shared/nm-utils/nm-glib.h +++ b/shared/nm-utils/nm-glib.h @@ -24,6 +24,8 @@ #include #include +#include "gsystem-local-alloc.h" + #ifdef __clang__ #undef G_GNUC_BEGIN_IGNORE_DEPRECATIONS diff --git a/shared/nm-utils/nm-vpn-editor-plugin-call.h b/shared/nm-utils/nm-vpn-editor-plugin-call.h index c6b7ee76ab..78d041dff3 100644 --- a/shared/nm-utils/nm-vpn-editor-plugin-call.h +++ b/shared/nm-utils/nm-vpn-editor-plugin-call.h @@ -32,7 +32,6 @@ #include /* we make use of other internal header files, you need those too. */ -#include "gsystem-local-alloc.h" #include "nm-macros-internal.h" /*****************************************************************************/ From 3bcec4067fb0fb1c4eaa3de0b7c2802f689702a5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 15 Jun 2016 16:09:22 +0200 Subject: [PATCH 4/5] shared: include "nm-glib.h" from "nm-macros-internal.h" "nm-glib.h" is our most basic header. "nm-macros-internal.h" extends on that. Thus, let "nm-macros-internal.h" include "nm-glib.h". --- shared/nm-default.h | 3 +-- shared/nm-utils/nm-macros-internal.h | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/shared/nm-default.h b/shared/nm-default.h index 6ff34aca52..547ee57c98 100644 --- a/shared/nm-default.h +++ b/shared/nm-default.h @@ -98,9 +98,8 @@ _nm_g_return_if_fail_warning (const char *log_domain, /*****************************************************************************/ -#include "nm-utils/nm-glib.h" -#include "nm-version.h" #include "nm-utils/nm-macros-internal.h" +#include "nm-version.h" #include "nm-utils/nm-shared-utils.h" /*****************************************************************************/ diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h index 4622af9fd8..603689af01 100644 --- a/shared/nm-utils/nm-macros-internal.h +++ b/shared/nm-utils/nm-macros-internal.h @@ -24,6 +24,8 @@ #include +#include "nm-glib.h" + /********************************************************/ #define _nm_packed __attribute__ ((packed)) From 2c02f3a8cfe3616a1469ac9949833deecfea4698 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 15 Jun 2016 16:00:42 +0200 Subject: [PATCH 5/5] shared/tests: build "nm-utils/nm-vpn-plugin-utils.c" For testing, add a build target to build those files too. --- libnm/tests/Makefile.am | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/libnm/tests/Makefile.am b/libnm/tests/Makefile.am index d2944c4cad..1c65f72340 100644 --- a/libnm/tests/Makefile.am +++ b/libnm/tests/Makefile.am @@ -39,3 +39,27 @@ test_secret_agent_SOURCES = \ $(top_builddir)/shared/nm-test-libnm-utils.h \ test-secret-agent.c endif + +############################################################################### + +noinst_LTLIBRARIES = \ + libnm-vpn-plugin-utils-test.la + +libnm_vpn_plugin_utils_test_la_SOURCES = \ + $(top_srcdir)/shared/nm-utils/nm-vpn-plugin-utils.c \ + $(top_srcdir)/shared/nm-utils/nm-vpn-plugin-utils.h \ + $(NULL) + +libnm_vpn_plugin_utils_test_la_CFLAGS = \ + $(GLIB_CFLAGS) \ + -I$(top_srcdir)/shared \ + -I$(top_srcdir)/libnm-core \ + -I$(top_srcdir)/libnm \ + $(NULL) + +libnm_vpn_plugin_utils_test_la_LIBADD = \ + $(GLIB_LIBS) \ + $(NULL) + +############################################################################### +