summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2014-10-15 13:20:03 -0400
committerDan Winship <danw@gnome.org>2014-10-22 08:29:08 -0400
commitb1bcfa8fedc65a6d7e9eacbf1dbf736767126820 (patch)
treeb266e711a8a1fa35f0632433cc2961bf0da08b5c
parent663a06b6d9e7a45132ffadd1c41c98d86e43a5b9 (diff)
downloadNetworkManager-b1bcfa8fedc65a6d7e9eacbf1dbf736767126820.tar.gz
libnm-core: add nm-errors.[ch]
Add nm-errors.[ch], and move libnm-core's two error domains (NMConnectionError and NMCryptoError) there. NMCryptoError wasn't previously visible, but it can be returned from some public API, so it should be.
-rw-r--r--include/nm-glib-compat.h14
-rw-r--r--libnm-core/Makefile.libnm-core2
-rw-r--r--libnm-core/crypto.c12
-rw-r--r--libnm-core/crypto.h12
-rw-r--r--libnm-core/crypto_gnutls.c1
-rw-r--r--libnm-core/crypto_nss.c1
-rw-r--r--libnm-core/nm-connection.c17
-rw-r--r--libnm-core/nm-connection.h46
-rw-r--r--libnm-core/nm-errors.c27
-rw-r--r--libnm-core/nm-errors.h93
-rw-r--r--libnm/libnm.ver2
11 files changed, 142 insertions, 85 deletions
diff --git a/include/nm-glib-compat.h b/include/nm-glib-compat.h
index 397eabfaca..7a9bb3160a 100644
--- a/include/nm-glib-compat.h
+++ b/include/nm-glib-compat.h
@@ -150,4 +150,18 @@ __g_test_add_data_func_full (const char *testpath,
#define g_test_add_data_func_full __g_test_add_data_func_full
+#if !GLIB_CHECK_VERSION (2, 34, 0)
+#define G_DEFINE_QUARK(QN, q_n) \
+GQuark \
+q_n##_quark (void) \
+{ \
+ static GQuark q; \
+ \
+ if G_UNLIKELY (q == 0) \
+ q = g_quark_from_static_string (#QN); \
+ \
+ return q; \
+}
+#endif
+
#endif /* __NM_GLIB_COMPAT_H__ */
diff --git a/libnm-core/Makefile.libnm-core b/libnm-core/Makefile.libnm-core
index 22566e0638..c79665e9f5 100644
--- a/libnm-core/Makefile.libnm-core
+++ b/libnm-core/Makefile.libnm-core
@@ -10,6 +10,7 @@ libnm_core_headers = \
$(core_build)/nm-version.h \
$(core)/nm-connection.h \
$(core)/nm-dbus-interface.h \
+ $(core)/nm-errors.h \
$(core)/nm-setting-8021x.h \
$(core)/nm-setting-adsl.h \
$(core)/nm-setting-bluetooth.h \
@@ -52,6 +53,7 @@ libnm_core_sources = \
$(core_build)/nm-core-enum-types.c \
$(core)/crypto.c \
$(core)/nm-connection.c \
+ $(core)/nm-errors.c \
$(core)/nm-property-compare.c \
$(core)/nm-setting-8021x.c \
$(core)/nm-setting-adsl.c \
diff --git a/libnm-core/crypto.c b/libnm-core/crypto.c
index e28415705c..a695747109 100644
--- a/libnm-core/crypto.c
+++ b/libnm-core/crypto.c
@@ -31,17 +31,7 @@
#include <glib/gi18n.h>
#include "crypto.h"
-
-GQuark
-_nm_crypto_error_quark (void)
-{
- static GQuark quark;
-
- if (G_UNLIKELY (!quark))
- quark = g_quark_from_static_string ("nm-crypto-error-quark");
- return quark;
-}
-
+#include "nm-errors.h"
#define PEM_RSA_KEY_BEGIN "-----BEGIN RSA PRIVATE KEY-----"
#define PEM_RSA_KEY_END "-----END RSA PRIVATE KEY-----"
diff --git a/libnm-core/crypto.h b/libnm-core/crypto.h
index 67abbdade3..9173ba2203 100644
--- a/libnm-core/crypto.h
+++ b/libnm-core/crypto.h
@@ -31,15 +31,6 @@
#define CIPHER_DES_CBC "DES-CBC"
#define CIPHER_AES_CBC "AES-128-CBC"
-enum {
- NM_CRYPTO_ERROR_FAILED = 0,
- NM_CRYPTO_ERROR_INVALID_DATA,
- NM_CRYPTO_ERROR_INVALID_PASSWORD,
- NM_CRYPTO_ERROR_UNKNOWN_CIPHER,
- NM_CRYPTO_ERROR_DECRYPTION_FAILED,
- NM_CRYPTO_ERROR_ENCRYPTION_FAILED,
-};
-
typedef enum {
NM_CRYPTO_KEY_TYPE_UNKNOWN = 0,
NM_CRYPTO_KEY_TYPE_RSA,
@@ -53,9 +44,6 @@ typedef enum {
NM_CRYPTO_FILE_FORMAT_PKCS12
} NMCryptoFileFormat;
-#define NM_CRYPTO_ERROR _nm_crypto_error_quark ()
-GQuark _nm_crypto_error_quark (void);
-
gboolean crypto_init (GError **error);
void crypto_deinit (void);
diff --git a/libnm-core/crypto_gnutls.c b/libnm-core/crypto_gnutls.c
index 8114d28fbf..28d9bf79b8 100644
--- a/libnm-core/crypto_gnutls.c
+++ b/libnm-core/crypto_gnutls.c
@@ -31,6 +31,7 @@
#include <gnutls/pkcs12.h>
#include "crypto.h"
+#include "nm-errors.h"
#define SALT_LEN 8
diff --git a/libnm-core/crypto_nss.c b/libnm-core/crypto_nss.c
index e2fbd4fed4..b75fcf6662 100644
--- a/libnm-core/crypto_nss.c
+++ b/libnm-core/crypto_nss.c
@@ -37,6 +37,7 @@
#include <p12plcy.h>
#include "crypto.h"
+#include "nm-errors.h"
static gboolean initialized = FALSE;
diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c
index 0ccacace1c..b43f0c0377 100644
--- a/libnm-core/nm-connection.c
+++ b/libnm-core/nm-connection.c
@@ -72,23 +72,6 @@
*
*/
-/**
- * nm_connection_error_quark:
- *
- * Registers an error quark for #NMConnection if necessary.
- *
- * Returns: the error quark used for #NMConnection errors.
- **/
-GQuark
-nm_connection_error_quark (void)
-{
- static GQuark quark;
-
- if (G_UNLIKELY (!quark))
- quark = g_quark_from_static_string ("nm-connection-error-quark");
- return quark;
-}
-
typedef struct {
NMConnection *self;
diff --git a/libnm-core/nm-connection.h b/libnm-core/nm-connection.h
index d1cfff2ac4..28254c33fa 100644
--- a/libnm-core/nm-connection.h
+++ b/libnm-core/nm-connection.h
@@ -30,6 +30,7 @@
#include <glib.h>
#include <glib-object.h>
#include <nm-setting.h>
+#include <nm-errors.h>
#include <nm-setting-8021x.h>
#include <nm-setting-bluetooth.h>
@@ -70,48 +71,6 @@ G_BEGIN_DECLS
#define NM_CONNECTION_SECRETS_CLEARED "secrets-cleared"
#define NM_CONNECTION_CHANGED "changed"
-/**
- * NMConnectionError:
- * @NM_CONNECTION_ERROR_FAILED: unknown or unclassified error
- * @NM_CONNECTION_ERROR_SETTING_NOT_FOUND: the #NMConnection object
- * did not contain the specified #NMSetting object
- * @NM_CONNECTION_ERROR_PROPERTY_NOT_FOUND: the #NMConnection did not contain the
- * requested #NMSetting property
- * @NM_CONNECTION_ERROR_PROPERTY_NOT_SECRET: an operation which requires a secret
- * was attempted on a non-secret property
- * @NM_CONNECTION_ERROR_MISSING_SETTING: the #NMConnection object is missing an
- * #NMSetting which is required for its configuration. The error message will
- * always be prefixed with "<setting-name>: ", where "<setting-name>" is the
- * name of the setting that is missing.
- * @NM_CONNECTION_ERROR_INVALID_SETTING: the #NMConnection object contains an
- * invalid or inappropriate #NMSetting. The error message will always be
- * prefixed with "<setting-name>: ", where "<setting-name>" is the name of the
- * setting that is invalid.
- * @NM_CONNECTION_ERROR_MISSING_PROPERTY: the #NMConnection object is invalid
- * because it is missing a required property. The error message will always be
- * prefixed with "<setting-name>.<property-name>: ", where "<setting-name>" is
- * the name of the setting with the missing property, and "<property-name>" is
- * the property that is missing.
- * @NM_CONNECTION_ERROR_INVALID_PROPERTY: the #NMConnection object is invalid
- * because a property has an invalid value. The error message will always be
- * prefixed with "<setting-name>.<property-name>: ", where "<setting-name>" is
- * the name of the setting with the invalid property, and "<property-name>" is
- * the property that is invalid.
- *
- * Describes errors that may result from operations involving a #NMConnection
- * or its #NMSettings.
- */
-typedef enum {
- NM_CONNECTION_ERROR_FAILED = 0, /*< nick=Failed >*/
- NM_CONNECTION_ERROR_SETTING_NOT_FOUND, /*< nick=SettingNotFound >*/
- NM_CONNECTION_ERROR_PROPERTY_NOT_FOUND, /*< nick=PropertyNotFound >*/
- NM_CONNECTION_ERROR_PROPERTY_NOT_SECRET, /*< nick=PropertyNotSecret >*/
- NM_CONNECTION_ERROR_MISSING_SETTING, /*< nick=MissingSetting >*/
- NM_CONNECTION_ERROR_INVALID_SETTING, /*< nick=InvalidSetting >*/
- NM_CONNECTION_ERROR_MISSING_PROPERTY, /*< nick=MissingProperty >*/
- NM_CONNECTION_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
-} NMConnectionError;
-
/*
* NM_CONNECTION_NORMALIZE_PARAM_IP6_CONFIG_METHOD: overwrite the ip6 method
* when normalizing ip6 configuration. If omited, this defaults to
@@ -119,9 +78,6 @@ typedef enum {
*/
#define NM_CONNECTION_NORMALIZE_PARAM_IP6_CONFIG_METHOD "ip6-config-method"
-#define NM_CONNECTION_ERROR nm_connection_error_quark ()
-GQuark nm_connection_error_quark (void);
-
/**
* NMConnection:
*
diff --git a/libnm-core/nm-errors.c b/libnm-core/nm-errors.c
new file mode 100644
index 0000000000..99040419d7
--- /dev/null
+++ b/libnm-core/nm-errors.c
@@ -0,0 +1,27 @@
+/* -*- 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 2004 - 2014 Red Hat, Inc.
+ */
+
+#include <glib.h>
+
+#include "nm-errors.h"
+#include "nm-glib-compat.h"
+
+G_DEFINE_QUARK (nm-connection-error-quark, nm_connection_error)
+G_DEFINE_QUARK (nm-crypto-error-quark, nm_crypto_error)
diff --git a/libnm-core/nm-errors.h b/libnm-core/nm-errors.h
new file mode 100644
index 0000000000..7790854f52
--- /dev/null
+++ b/libnm-core/nm-errors.h
@@ -0,0 +1,93 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2004 - 2014 Red Hat, Inc.
+ */
+
+#ifndef __NM_ERRORS_H__
+#define __NM_ERRORS_H__
+
+/**
+ * NMConnectionError:
+ * @NM_CONNECTION_ERROR_FAILED: unknown or unclassified error
+ * @NM_CONNECTION_ERROR_SETTING_NOT_FOUND: the #NMConnection object
+ * did not contain the specified #NMSetting object
+ * @NM_CONNECTION_ERROR_PROPERTY_NOT_FOUND: the #NMConnection did not contain the
+ * requested #NMSetting property
+ * @NM_CONNECTION_ERROR_PROPERTY_NOT_SECRET: an operation which requires a secret
+ * was attempted on a non-secret property
+ * @NM_CONNECTION_ERROR_MISSING_SETTING: the #NMConnection object is missing an
+ * #NMSetting which is required for its configuration. The error message will
+ * always be prefixed with "<setting-name>: ", where "<setting-name>" is the
+ * name of the setting that is missing.
+ * @NM_CONNECTION_ERROR_INVALID_SETTING: the #NMConnection object contains an
+ * invalid or inappropriate #NMSetting. The error message will always be
+ * prefixed with "<setting-name>: ", where "<setting-name>" is the name of the
+ * setting that is invalid.
+ * @NM_CONNECTION_ERROR_MISSING_PROPERTY: the #NMConnection object is invalid
+ * because it is missing a required property. The error message will always be
+ * prefixed with "<setting-name>.<property-name>: ", where "<setting-name>" is
+ * the name of the setting with the missing property, and "<property-name>" is
+ * the property that is missing.
+ * @NM_CONNECTION_ERROR_INVALID_PROPERTY: the #NMConnection object is invalid
+ * because a property has an invalid value. The error message will always be
+ * prefixed with "<setting-name>.<property-name>: ", where "<setting-name>" is
+ * the name of the setting with the invalid property, and "<property-name>" is
+ * the property that is invalid.
+ *
+ * Describes errors that may result from operations involving a #NMConnection
+ * or its #NMSettings.
+ */
+typedef enum {
+ NM_CONNECTION_ERROR_FAILED = 0, /*< nick=Failed >*/
+ NM_CONNECTION_ERROR_SETTING_NOT_FOUND, /*< nick=SettingNotFound >*/
+ NM_CONNECTION_ERROR_PROPERTY_NOT_FOUND, /*< nick=PropertyNotFound >*/
+ NM_CONNECTION_ERROR_PROPERTY_NOT_SECRET, /*< nick=PropertyNotSecret >*/
+ NM_CONNECTION_ERROR_MISSING_SETTING, /*< nick=MissingSetting >*/
+ NM_CONNECTION_ERROR_INVALID_SETTING, /*< nick=InvalidSetting >*/
+ NM_CONNECTION_ERROR_MISSING_PROPERTY, /*< nick=MissingProperty >*/
+ NM_CONNECTION_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
+} NMConnectionError;
+
+#define NM_CONNECTION_ERROR nm_connection_error_quark ()
+GQuark nm_connection_error_quark (void);
+
+/**
+ * NMCryptoError:
+ * @NM_CRYPTO_ERROR_FAILED: generic failure
+ * @NM_CRYPTO_ERROR_INVALID_DATA: the certificate or key data provided
+ * was invalid
+ * @NM_CRYPTO_ERROR_INVALID_PASSWORD: the password was invalid
+ * @NM_CRYPTO_ERROR_UNKNOWN_CIPHER: the data uses an unknown cipher
+ * @NM_CRYPTO_ERROR_DECRYPTION_FAILED: decryption failed
+ * @NM_CRYPTO_ERROR_ENCRYPTION_FAILED: encryption failed
+ *
+ * Cryptography-related errors that can be returned from some nm-utils methods,
+ * and some #NMSetting8021x operations.
+ */
+typedef enum {
+ NM_CRYPTO_ERROR_FAILED = 0,
+ NM_CRYPTO_ERROR_INVALID_DATA,
+ NM_CRYPTO_ERROR_INVALID_PASSWORD,
+ NM_CRYPTO_ERROR_UNKNOWN_CIPHER,
+ NM_CRYPTO_ERROR_DECRYPTION_FAILED,
+ NM_CRYPTO_ERROR_ENCRYPTION_FAILED,
+} NMCryptoError;
+
+#define NM_CRYPTO_ERROR nm_crypto_error_quark ()
+GQuark nm_crypto_error_quark (void);
+
+#endif /* __NM_ERRORS_H__ */
diff --git a/libnm/libnm.ver b/libnm/libnm.ver
index db7140f20a..f48582a178 100644
--- a/libnm/libnm.ver
+++ b/libnm/libnm.ver
@@ -149,6 +149,8 @@ global:
nm_connection_update_secrets;
nm_connection_verify;
nm_connectivity_state_get_type;
+ nm_crypto_error_get_type;
+ nm_crypto_error_quark;
nm_device_adsl_error_get_type;
nm_device_adsl_error_quark;
nm_device_adsl_get_carrier;