all: add nm-core-internal.h header
authorThomas Haller <thaller@redhat.com>
Sun, 27 Jul 2014 18:35:17 +0000 (20:35 +0200)
committerThomas Haller <thaller@redhat.com>
Fri, 22 Aug 2014 13:22:16 +0000 (15:22 +0200)
Add a header file to expose private utility functions from libnm-core
that can be used by NetworkManager (core) and libnm.so. The header
is also used to give privileged access to libnm-core. Since NM links
statically, these functions are not exported and not part of public ABI.

This also removes the NM_UTILS_PRIVATE_CALL() macro and libnm.so no
longer exports nm_utils_get_private().

Before, this functionality was partly declared in nm-utils-private.h.
This was wrong because nm-utils-private.h is for functionality
entirely private to libnm-core.

Signed-off-by: Thomas Haller <thaller@redhat.com>
15 files changed:
callouts/tests/test-dispatcher-envp.c
clients/tui/nmt-route-table.c
docs/libnm/Makefile.am
libnm-core/Makefile.libnm-core
libnm-core/nm-core-internal.h [new file with mode: 0644]
libnm-core/nm-setting-ip4-config.c
libnm-core/nm-setting-private.h
libnm-core/nm-utils-private.h
libnm-core/nm-utils.c
libnm-core/tests/test-general.c
libnm/libnm.ver
src/nm-ip4-config.c
src/settings/plugins/ifcfg-rh/reader.c
src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
src/settings/plugins/ifcfg-rh/writer.c

index 1d9792f..9d9ee52 100644 (file)
@@ -31,7 +31,6 @@
 #include "nm-dbus-glib-types.h"
 #include "nm-dispatcher-api.h"
 #include "nm-utils.h"
-#include "nm-utils-private.h"
 
 /*******************************************/
 
index c5a7076..82eefb4 100644 (file)
@@ -33,7 +33,6 @@
 #include <glib/gi18n-lib.h>
 #include <dbus/dbus-glib.h>
 #include <NetworkManager.h>
-#include <nm-utils-private.h>
 
 #include "nmt-route-table.h"
 #include "nmt-route-entry.h"
index 9d745b1..c99e242 100644 (file)
@@ -32,6 +32,7 @@ CFILE_GLOB=$(top_srcdir)/libnm-core/*.c $(top_srcdir)/libnm/*.c
 IGNORE_HFILES= \
        crypto.h \
        nm-dbus-helpers-private.h \
+       nm-core-internal.h \
        nm-device-private.h \
        nm-object-cache.h \
        nm-object-private.h \
index 49af47d..b792484 100644 (file)
@@ -43,6 +43,7 @@ libnm_core_headers =                          \
 
 libnm_core_private_headers =                   \
        $(core)/crypto.h                        \
+       $(core)/nm-core-internal.h      \
        $(core)/nm-param-spec-specialized.h     \
        $(core)/nm-setting-private.h            \
        $(core)/nm-utils-private.h
diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h
new file mode 100644 (file)
index 0000000..41b51c2
--- /dev/null
@@ -0,0 +1,49 @@
+/* -*- 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.
+ *
+ * (C) Copyright 2014 Red Hat, Inc.
+ */
+
+#ifndef NM_CORE_NM_INTERNAL_H
+#define NM_CORE_NM_INTERNAL_H
+
+/* This header file contain functions that are provided as private API
+ * by libnm-core. It will contain functions to give privileged access to
+ * libnm-core. This can be useful for NetworkManager and libnm.so
+ * which both are special users of libnm-core.
+ * It also exposes some utility functions for reuse.
+ *
+ * These functions are not exported and are only available to components that link
+ * statically against libnm-core. This basically means libnm-core, libnm, NetworkManager
+ * and some test programs.
+ **/
+
+#include <glib.h>
+
+#include "nm-utils.h"
+
+#include "nm-setting-ip4-config.h"
+
+const char *_nm_setting_ip4_config_get_address_label      (NMSettingIP4Config *setting,
+                                                           guint32             i);
+gboolean    _nm_setting_ip4_config_add_address_with_label (NMSettingIP4Config *setting,
+                                                           NMIP4Address       *address,
+                                                           const char         *label);
+
+
+#endif
index f3de89e..aab5546 100644 (file)
@@ -30,6 +30,7 @@
 #include "nm-dbus-glib-types.h"
 #include "nm-glib-compat.h"
 #include "nm-setting-private.h"
+#include "nm-core-internal.h"
 
 
 /**
@@ -435,7 +436,7 @@ nm_setting_ip4_config_get_address (NMSettingIP4Config *setting, guint32 i)
 }
 
 const char *
-nm_setting_ip4_config_get_address_label (NMSettingIP4Config *setting, guint32 i)
+_nm_setting_ip4_config_get_address_label (NMSettingIP4Config *setting, guint32 i)
 {
        NMSettingIP4ConfigPrivate *priv;
 
@@ -462,13 +463,13 @@ gboolean
 nm_setting_ip4_config_add_address (NMSettingIP4Config *setting,
                                    NMIP4Address *address)
 {
-       return nm_setting_ip4_config_add_address_with_label (setting, address, NULL);
+       return _nm_setting_ip4_config_add_address_with_label (setting, address, NULL);
 }
 
 gboolean
-nm_setting_ip4_config_add_address_with_label (NMSettingIP4Config *setting,
-                                              NMIP4Address *address,
-                                              const char *label)
+_nm_setting_ip4_config_add_address_with_label (NMSettingIP4Config *setting,
+                                               NMIP4Address *address,
+                                               const char *label)
 {
        NMSettingIP4ConfigPrivate *priv;
        NMIP4Address *copy;
index 338364c..a31d0d7 100644 (file)
@@ -101,11 +101,6 @@ static void __attribute__((constructor)) register_setting (void) \
 
 NMSetting *nm_setting_find_in_list (GSList *settings_list, const char *setting_name);
 
-/* Private NMSettingIP4Config methods */
-#include "nm-setting-ip4-config.h"
-const char *nm_setting_ip4_config_get_address_label      (NMSettingIP4Config *setting, guint32 i);
-gboolean    nm_setting_ip4_config_add_address_with_label (NMSettingIP4Config *setting, NMIP4Address *address, const char *label);
-
 NMSettingVerifyResult _nm_setting_verify_deprecated_virtual_iface_name (const char *interface_name,
                                                                         gboolean allow_missing,
                                                                         const char *setting_name,
index c91652b..0e7be21 100644 (file)
@@ -34,30 +34,4 @@ gboolean    _nm_utils_gvalue_array_validate (GValueArray *elements,
 
 void        _nm_value_transforms_register (void);
 
-/***********************************************************/
-
-typedef struct NMUtilsPrivateData {
-       const char * (*nm_setting_ip4_config_get_address_label)      (NMSettingIP4Config *setting,
-                                                                     guint32             i);
-       gboolean     (*nm_setting_ip4_config_add_address_with_label) (NMSettingIP4Config *setting,
-                                                                     NMIP4Address       *address,
-                                                                     const char         *label);
-} NMUtilsPrivateData;
-
-const NMUtilsPrivateData *nm_utils_get_private (void);
-
-/**
- * NM_UTILS_PRIVATE_CALL:
- * @call: a call to a private libnm function
- *
- * Used to call private libnm functions. Eg, if there was a
- * private function called nm_foo_get_bar(), you could call it like:
- *
- *   bar = NM_UTILS_PRIVATE_CALL (nm_foo_get_bar (foo, x, y, z));
- *
- * This macro only exists inside the NetworkManager source tree and
- * is not part of the public API.
- */
-#define NM_UTILS_PRIVATE_CALL(call) (nm_utils_get_private ()->call)
-
 #endif
index 4304b5b..4f91c1e 100644 (file)
@@ -2479,23 +2479,4 @@ nm_utils_check_virtual_device_compatibility (GType virtual_type, GType other_typ
        }
 }
 
-/***********************************************************/
 
-static const NMUtilsPrivateData data = {
-       .nm_setting_ip4_config_get_address_label = nm_setting_ip4_config_get_address_label,
-       .nm_setting_ip4_config_add_address_with_label = nm_setting_ip4_config_add_address_with_label,
-};
-
-/**
- * nm_utils_get_private:
- *
- * Entry point for NetworkManager-internal API.  You should not use this
- * function for any reason.
- *
- * Returns: Who knows? It's a mystery.
- */
-const NMUtilsPrivateData *
-nm_utils_get_private (void)
-{
-       return &data;
-}
index 70effba..0c660d0 100644 (file)
@@ -39,7 +39,7 @@
 #include "nm-setting-vlan.h"
 #include "nm-setting-bond.h"
 #include "nm-utils.h"
-#include "nm-utils-private.h"
+#include "nm-core-internal.h"
 #include "nm-dbus-glib-types.h"
 
 #include "nm-test-utils.h"
@@ -330,7 +330,7 @@ test_setting_ip4_config_labels (void)
        nm_setting_verify (NM_SETTING (s_ip4), NULL, &error);
        g_assert_no_error (error);
 
-       label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 0));
+       label = _nm_setting_ip4_config_get_address_label (s_ip4, 0);
        g_assert_cmpstr (label, ==, NULL);
 
        /* addr 2 */
@@ -338,12 +338,12 @@ test_setting_ip4_config_labels (void)
        nm_ip4_address_set_address (addr, 0x02020202);
        nm_ip4_address_set_prefix (addr, 24);
 
-       NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_add_address_with_label (s_ip4, addr, "eth0:1"));
+       _nm_setting_ip4_config_add_address_with_label (s_ip4, addr, "eth0:1");
        nm_ip4_address_unref (addr);
        nm_setting_verify (NM_SETTING (s_ip4), NULL, &error);
        g_assert_no_error (error);
 
-       label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 1));
+       label = _nm_setting_ip4_config_get_address_label (s_ip4, 1);
        g_assert_cmpstr (label, ==, "eth0:1");
 
        /* addr 3 */
@@ -351,12 +351,12 @@ test_setting_ip4_config_labels (void)
        nm_ip4_address_set_address (addr, 0x03030303);
        nm_ip4_address_set_prefix (addr, 24);
 
-       NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_add_address_with_label (s_ip4, addr, NULL));
+       _nm_setting_ip4_config_add_address_with_label (s_ip4, addr, NULL);
        nm_ip4_address_unref (addr);
        nm_setting_verify (NM_SETTING (s_ip4), NULL, &error);
        g_assert_no_error (error);
 
-       label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 2));
+       label = _nm_setting_ip4_config_get_address_label (s_ip4, 2);
        g_assert_cmpstr (label, ==, NULL);
 
        /* Remove addr 1 and re-verify remaining addresses */
@@ -366,12 +366,12 @@ test_setting_ip4_config_labels (void)
 
        addr = nm_setting_ip4_config_get_address (s_ip4, 0);
        g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x02020202);
-       label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 0));
+       label = _nm_setting_ip4_config_get_address_label (s_ip4, 0);
        g_assert_cmpstr (label, ==, "eth0:1");
 
        addr = nm_setting_ip4_config_get_address (s_ip4, 1);
        g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x03030303);
-       label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 1));
+       label = _nm_setting_ip4_config_get_address_label (s_ip4, 1);
        g_assert_cmpstr (label, ==, NULL);
 
 
@@ -395,12 +395,12 @@ test_setting_ip4_config_labels (void)
 
        addr = nm_setting_ip4_config_get_address (s_ip4, 0);
        g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x02020202);
-       label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 0));
+       label = _nm_setting_ip4_config_get_address_label (s_ip4, 0);
        g_assert_cmpstr (label, ==, NULL);
 
        addr = nm_setting_ip4_config_get_address (s_ip4, 1);
        g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x03030303);
-       label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 1));
+       label = _nm_setting_ip4_config_get_address_label (s_ip4, 1);
        g_assert_cmpstr (label, ==, NULL);
 
        /* Setting labels now will leave addresses untouched */
@@ -414,12 +414,12 @@ test_setting_ip4_config_labels (void)
 
        addr = nm_setting_ip4_config_get_address (s_ip4, 0);
        g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x02020202);
-       label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 0));
+       label = _nm_setting_ip4_config_get_address_label (s_ip4, 0);
        g_assert_cmpstr (label, ==, "eth0:1");
 
        addr = nm_setting_ip4_config_get_address (s_ip4, 1);
        g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x03030303);
-       label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 1));
+       label = _nm_setting_ip4_config_get_address_label (s_ip4, 1);
        g_assert_cmpstr (label, ==, NULL);
 
        /* Setting labels to a value that's too short or too long will result in
index e994ed9..760bb42 100644 (file)
@@ -878,7 +878,6 @@ global:
        nm_utils_deinit;
        nm_utils_escape_ssid;
        nm_utils_file_is_pkcs12;
-       nm_utils_get_private;
        nm_utils_gvalue_hash_dup;
        nm_utils_hex2byte;
        nm_utils_hexstr2bin;
index b286edb..e1395ed 100644 (file)
@@ -29,7 +29,7 @@
 #include "nm-dbus-glib-types.h"
 #include "nm-ip4-config-glue.h"
 #include "NetworkManagerUtils.h"
-#include "nm-utils-private.h"
+#include "nm-core-internal.h"
 
 G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, G_TYPE_OBJECT)
 
@@ -328,7 +328,7 @@ nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIP4Config *setting, i
        /* Addresses */
        for (i = 0; i < naddresses; i++) {
                NMIP4Address *s_addr = nm_setting_ip4_config_get_address (setting, i);
-               const char *label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (setting, i));
+               const char *label = _nm_setting_ip4_config_get_address_label (setting, i);
                NMPlatformIP4Address address;
 
                memset (&address, 0, sizeof (address));
@@ -426,7 +426,7 @@ nm_ip4_config_create_setting (const NMIP4Config *config)
                        nm_ip4_address_set_gateway (s_addr, gateway);
 
                if (*address->label)
-                       NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_add_address_with_label (s_ip4, s_addr, address->label));
+                       _nm_setting_ip4_config_add_address_with_label (s_ip4, s_addr, address->label);
                else
                        nm_setting_ip4_config_add_address (s_ip4, s_addr);
                nm_ip4_address_unref (s_addr);
index ee8c620..c49d052 100644 (file)
@@ -48,7 +48,7 @@
 #include <nm-setting-bridge-port.h>
 #include <nm-setting-dcb.h>
 #include <nm-setting-generic.h>
-#include <nm-utils-private.h>
+#include "nm-core-internal.h"
 #include <nm-utils.h>
 
 #include "nm-platform.h"
@@ -1574,7 +1574,7 @@ read_aliases (NMSettingIP4Config *s_ip4, const char *filename, const char *netwo
                        ok = read_full_ip4_address (parsed, network_file, -1, addr, &err);
                        svCloseFile (parsed);
                        if (ok) {
-                               if (!NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_add_address_with_label (s_ip4, addr, device)))
+                               if (!_nm_setting_ip4_config_add_address_with_label (s_ip4, addr, device))
                                        PARSE_WARNING ("duplicate IP4 address in alias file %s", item);
                        } else {
                                PARSE_WARNING ("error reading IP4 address from alias file '%s': %s",
index 8de6977..4b9c7aa 100644 (file)
@@ -44,7 +44,7 @@
 #include <nm-setting-serial.h>
 #include <nm-setting-vlan.h>
 #include <nm-setting-dcb.h>
-#include <nm-utils-private.h>
+#include "nm-core-internal.h"
 
 #include "NetworkManagerUtils.h"
 
@@ -2986,7 +2986,7 @@ test_read_wired_aliases_good (void)
                        TEST_IFCFG_ALIASES_GOOD,
                        i);
 
-               ASSERT (g_strcmp0 (NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, i)), expected_label[j]) == 0,
+               ASSERT (g_strcmp0 (_nm_setting_ip4_config_get_address_label (s_ip4, i), expected_label[j]) == 0,
                        "aliases-good-verify-ip4", "failed to verify %s: unexpected IP4 address label #%d",
                        TEST_IFCFG_ALIASES_GOOD,
                        i);
@@ -3113,7 +3113,7 @@ test_read_wired_aliases_bad (const char *base, const char *expected_id)
                        "aliases-bad-verify-ip4", "failed to verify %s: unexpected IP4 address gateway",
                        base);
 
-       ASSERT (g_strcmp0 (NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 0)), expected_label) == 0,
+       ASSERT (g_strcmp0 (_nm_setting_ip4_config_get_address_label (s_ip4, 0), expected_label) == 0,
                        "aliases-bad-verify-ip4", "failed to verify %s: unexpected IP4 address label",
                        base);
 
@@ -8185,7 +8185,7 @@ test_write_wired_aliases (void)
                nm_ip4_address_set_address (addr, ip[i]);
                nm_ip4_address_set_prefix (addr, prefix);
                nm_ip4_address_set_gateway (addr, gw);
-               NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_add_address_with_label (s_ip4, addr, label[i]));
+               _nm_setting_ip4_config_add_address_with_label (s_ip4, addr, label[i]);
                nm_ip4_address_unref (addr);
        }
 
@@ -8293,7 +8293,7 @@ test_write_wired_aliases (void)
                        testfile,
                        i);
 
-               ASSERT (g_strcmp0 (NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, i)), label[j]) == 0,
+               ASSERT (g_strcmp0 (_nm_setting_ip4_config_get_address_label (s_ip4, i), label[j]) == 0,
                        "wired-aliases-write-verify-ip4", "failed to verify %s: unexpected IP4 address label #%d",
                        testfile,
                        i);
index ab12350..e1c8f36 100644 (file)
@@ -38,7 +38,7 @@
 #include <nm-setting-vlan.h>
 #include <nm-setting-team.h>
 #include <nm-setting-team-port.h>
-#include <nm-utils-private.h>
+#include "nm-core-internal.h"
 #include <nm-utils.h>
 
 #include "nm-logging.h"
@@ -1927,7 +1927,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
                NMIP4Address *addr;
                guint32 ip;
 
-               if (i > 0 && NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, i)))
+               if (i > 0 && _nm_setting_ip4_config_get_address_label (s_ip4, i))
                        continue;
 
                if (n == 0) {
@@ -2202,7 +2202,7 @@ write_ip4_aliases (NMConnection *connection, char *base_ifcfg_path)
                guint32 ip;
                shvarFile *ifcfg;
 
-               label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, i));
+               label = _nm_setting_ip4_config_get_address_label (s_ip4, i);
                if (!label)
                        continue;
                if (   strncmp (label, base_name, base_name_len) != 0