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.
This commit is contained in:
Dan Winship 2014-10-15 13:20:03 -04:00
parent 663a06b6d9
commit b1bcfa8fed
11 changed files with 142 additions and 85 deletions

View file

@ -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__ */

View file

@ -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 \

View file

@ -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-----"

View file

@ -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);

View file

@ -31,6 +31,7 @@
#include <gnutls/pkcs12.h>
#include "crypto.h"
#include "nm-errors.h"
#define SALT_LEN 8

View file

@ -37,6 +37,7 @@
#include <p12plcy.h>
#include "crypto.h"
#include "nm-errors.h"
static gboolean initialized = FALSE;

View file

@ -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;

View file

@ -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:
*

27
libnm-core/nm-errors.c Normal file
View file

@ -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)

93
libnm-core/nm-errors.h Normal file
View file

@ -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__ */

View file

@ -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;