mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-04 00:11:05 +02:00
auth: embed private data NMAuthSubjectPrivate in NMAuthSubject struct
... and make the structs NMAuthSubject and NMAuthSubjectClass opaque types. I don't want to do this for all our types, only for a few prominent GObject instances that we create a lot and that are really not expected to ever be subclassed. NMAuthSubject is such a candidate. It is really a very simple object containing a few information bits about the authentication request. It is not ever expected to be extended/inherited or become more complex. No need to do a full-fledged private-data implementation.
This commit is contained in:
parent
7aac2c8a10
commit
b4095a5101
2 changed files with 34 additions and 22 deletions
|
|
@ -37,10 +37,6 @@
|
|||
#include "nm-enum-types.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
|
||||
G_DEFINE_TYPE (NMAuthSubject, nm_auth_subject, G_TYPE_OBJECT)
|
||||
|
||||
#define NM_AUTH_SUBJECT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_AUTH_SUBJECT, NMAuthSubjectPrivate))
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_SUBJECT_TYPE,
|
||||
|
|
@ -61,6 +57,30 @@ typedef struct {
|
|||
} unix_process;
|
||||
} NMAuthSubjectPrivate;
|
||||
|
||||
struct _NMAuthSubject {
|
||||
GObject parent;
|
||||
NMAuthSubjectPrivate _priv;
|
||||
};
|
||||
|
||||
struct _NMAuthSubjectClass {
|
||||
GObjectClass parent;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (NMAuthSubject, nm_auth_subject, G_TYPE_OBJECT)
|
||||
|
||||
#define NM_AUTH_SUBJECT_GET_PRIVATE(self) \
|
||||
({ \
|
||||
/* preserve the const-ness of self. Unfortunately, that
|
||||
* way, @self cannot be a void pointer */ \
|
||||
typeof (self) _self = (self); \
|
||||
\
|
||||
/* Get compiler error if variable is of wrong type */ \
|
||||
_nm_unused const NMAuthSubject *_self2 = (_self); \
|
||||
\
|
||||
nm_assert (NM_IS_AUTH_SUBJECT (_self)); \
|
||||
&_self->_priv; \
|
||||
})
|
||||
|
||||
/**************************************************************/
|
||||
|
||||
#define CHECK_SUBJECT(self, error_value) \
|
||||
|
|
@ -252,7 +272,7 @@ nm_auth_subject_new_internal (void)
|
|||
static void
|
||||
get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NMAuthSubjectPrivate *priv = NM_AUTH_SUBJECT_GET_PRIVATE (object);
|
||||
NMAuthSubjectPrivate *priv = NM_AUTH_SUBJECT_GET_PRIVATE ((NMAuthSubject *) object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_SUBJECT_TYPE:
|
||||
|
|
@ -276,7 +296,7 @@ get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
|||
static void
|
||||
set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NMAuthSubjectPrivate *priv = NM_AUTH_SUBJECT_GET_PRIVATE (object);
|
||||
NMAuthSubjectPrivate *priv = NM_AUTH_SUBJECT_GET_PRIVATE ((NMAuthSubject *) object);
|
||||
NMAuthSubjectType subject_type;
|
||||
const char *str;
|
||||
gulong id;
|
||||
|
|
@ -317,8 +337,10 @@ set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *p
|
|||
}
|
||||
|
||||
static void
|
||||
_clear_private (NMAuthSubjectPrivate *priv)
|
||||
_clear_private (NMAuthSubject *self)
|
||||
{
|
||||
NMAuthSubjectPrivate *priv = NM_AUTH_SUBJECT_GET_PRIVATE (self);
|
||||
|
||||
priv->subject_type = NM_AUTH_SUBJECT_TYPE_INVALID;
|
||||
priv->unix_process.pid = G_MAXULONG;
|
||||
priv->unix_process.uid = G_MAXULONG;
|
||||
|
|
@ -328,7 +350,7 @@ _clear_private (NMAuthSubjectPrivate *priv)
|
|||
static void
|
||||
nm_auth_subject_init (NMAuthSubject *self)
|
||||
{
|
||||
_clear_private (NM_AUTH_SUBJECT_GET_PRIVATE (self));
|
||||
_clear_private (self);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -363,7 +385,7 @@ constructed (GObject *object)
|
|||
/* Is the process already gone? Then fail creation of the auth subject
|
||||
* by clearing the type. */
|
||||
if (kill (priv->unix_process.pid, 0) != 0)
|
||||
_clear_private (priv);
|
||||
_clear_private (self);
|
||||
|
||||
/* Otherwise, although we didn't detect a start_time, the process is still around.
|
||||
* That could be due to procfs mounted with hidepid. So just accept the request.
|
||||
|
|
@ -378,16 +400,14 @@ constructed (GObject *object)
|
|||
break;
|
||||
}
|
||||
|
||||
_clear_private (priv);
|
||||
_clear_private (self);
|
||||
g_return_if_reached ();
|
||||
}
|
||||
|
||||
static void
|
||||
finalize (GObject *object)
|
||||
{
|
||||
NMAuthSubjectPrivate *priv = NM_AUTH_SUBJECT_GET_PRIVATE (object);
|
||||
|
||||
_clear_private (priv);
|
||||
_clear_private ((NMAuthSubject *) object);
|
||||
|
||||
G_OBJECT_CLASS (nm_auth_subject_parent_class)->finalize (object);
|
||||
}
|
||||
|
|
@ -397,8 +417,6 @@ nm_auth_subject_class_init (NMAuthSubjectClass *config_class)
|
|||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (config_class);
|
||||
|
||||
g_type_class_add_private (config_class, sizeof (NMAuthSubjectPrivate));
|
||||
|
||||
/* virtual methods */
|
||||
object_class->get_property = get_property;
|
||||
object_class->set_property = set_property;
|
||||
|
|
|
|||
|
|
@ -39,13 +39,7 @@ typedef enum {
|
|||
#define NM_AUTH_SUBJECT_UNIX_PROCESS_PID "unix-process-pid"
|
||||
#define NM_AUTH_SUBJECT_UNIX_PROCESS_UID "unix-process-uid"
|
||||
|
||||
struct _NMAuthSubject {
|
||||
GObject parent;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
GObjectClass parent;
|
||||
} NMAuthSubjectClass;
|
||||
typedef struct _NMAuthSubjectClass NMAuthSubjectClass;
|
||||
|
||||
GType nm_auth_subject_get_type (void);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue