|
Packit Service |
d328f3 |
/* NetworkManager -- Network link manager
|
|
Packit Service |
d328f3 |
*
|
|
Packit Service |
d328f3 |
* This library is free software; you can redistribute it and/or
|
|
Packit Service |
d328f3 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
d328f3 |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
d328f3 |
* version 2 of the License, or (at your option) any later version.
|
|
Packit Service |
d328f3 |
*
|
|
Packit Service |
d328f3 |
* This library is distributed in the hope that it will be useful,
|
|
Packit Service |
d328f3 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
d328f3 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
d328f3 |
* Lesser General Public License for more details.
|
|
Packit Service |
d328f3 |
*
|
|
Packit Service |
d328f3 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
d328f3 |
* License along with this library; if not, write to the
|
|
Packit Service |
d328f3 |
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
Packit Service |
d328f3 |
* Boston, MA 02110-1301 USA.
|
|
Packit Service |
d328f3 |
*
|
|
Packit Service |
d328f3 |
* (C) Copyright 2016 Red Hat, Inc.
|
|
Packit Service |
d328f3 |
*/
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#ifndef __NM_SHARED_UTILS_H__
|
|
Packit Service |
d328f3 |
#define __NM_SHARED_UTILS_H__
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#include <netinet/in.h>
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
/*****************************************************************************/
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
static inline char
|
|
Packit Service |
d328f3 |
nm_utils_addr_family_to_char (int addr_family)
|
|
Packit Service |
d328f3 |
{
|
|
Packit Service |
d328f3 |
switch (addr_family) {
|
|
Packit Service |
d328f3 |
case AF_INET: return '4';
|
|
Packit Service |
d328f3 |
case AF_INET6: return '6';
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
g_return_val_if_reached ('?');
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
static inline gsize
|
|
Packit Service |
d328f3 |
nm_utils_addr_family_to_size (int addr_family)
|
|
Packit Service |
d328f3 |
{
|
|
Packit Service |
d328f3 |
switch (addr_family) {
|
|
Packit Service |
d328f3 |
case AF_INET: return sizeof (in_addr_t);
|
|
Packit Service |
d328f3 |
case AF_INET6: return sizeof (struct in6_addr);
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
g_return_val_if_reached (0);
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define nm_assert_addr_family(addr_family) \
|
|
Packit Service |
d328f3 |
nm_assert (NM_IN_SET ((addr_family), AF_INET, AF_INET6))
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
/*****************************************************************************/
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
typedef struct {
|
|
Packit Service |
d328f3 |
union {
|
|
Packit Service |
d328f3 |
guint8 addr_ptr[1];
|
|
Packit Service |
d328f3 |
in_addr_t addr4;
|
|
Packit Service |
d328f3 |
struct in6_addr addr6;
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
/* NMIPAddr is really a union for IP addresses.
|
|
Packit Service |
d328f3 |
* However, as ethernet addresses fit in here nicely, use
|
|
Packit Service |
d328f3 |
* it also for an ethernet MAC address. */
|
|
Packit Service |
d328f3 |
guint8 addr_eth[6 /*ETH_ALEN*/];
|
|
Packit Service |
d328f3 |
};
|
|
Packit Service |
d328f3 |
} NMIPAddr;
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
extern const NMIPAddr nm_ip_addr_zero;
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
static inline void
|
|
Packit Service |
d328f3 |
nm_ip_addr_set (int addr_family, gpointer dst, const NMIPAddr *src)
|
|
Packit Service |
d328f3 |
{
|
|
Packit Service |
d328f3 |
nm_assert_addr_family (addr_family);
|
|
Packit Service |
d328f3 |
nm_assert (dst);
|
|
Packit Service |
d328f3 |
nm_assert (src);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
if (addr_family != AF_INET6)
|
|
Packit Service |
d328f3 |
*((in_addr_t *) dst) = src->addr4;
|
|
Packit Service |
d328f3 |
else
|
|
Packit Service |
d328f3 |
*((struct in6_addr *) dst) = src->addr6;
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
/*****************************************************************************/
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define NM_CMP_RETURN(c) \
|
|
Packit Service |
d328f3 |
G_STMT_START { \
|
|
Packit Service |
d328f3 |
const int _cc = (c); \
|
|
Packit Service |
d328f3 |
if (_cc) \
|
|
Packit Service |
d328f3 |
return _cc < 0 ? -1 : 1; \
|
|
Packit Service |
d328f3 |
} G_STMT_END
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define NM_CMP_SELF(a, b) \
|
|
Packit Service |
d328f3 |
G_STMT_START { \
|
|
Packit Service |
d328f3 |
typeof (a) _a = (a); \
|
|
Packit Service |
d328f3 |
typeof (b) _b = (b); \
|
|
Packit Service |
d328f3 |
\
|
|
Packit Service |
d328f3 |
if (_a == _b) \
|
|
Packit Service |
d328f3 |
return 0; \
|
|
Packit Service |
d328f3 |
if (!_a) \
|
|
Packit Service |
d328f3 |
return -1; \
|
|
Packit Service |
d328f3 |
if (!_b) \
|
|
Packit Service |
d328f3 |
return 1; \
|
|
Packit Service |
d328f3 |
} G_STMT_END
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define NM_CMP_DIRECT(a, b) \
|
|
Packit Service |
d328f3 |
G_STMT_START { \
|
|
Packit Service |
d328f3 |
typeof (a) _a = (a); \
|
|
Packit Service |
d328f3 |
typeof (b) _b = (b); \
|
|
Packit Service |
d328f3 |
\
|
|
Packit Service |
d328f3 |
if (_a != _b) \
|
|
Packit Service |
d328f3 |
return (_a < _b) ? -1 : 1; \
|
|
Packit Service |
d328f3 |
} G_STMT_END
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define NM_CMP_DIRECT_MEMCMP(a, b, size) \
|
|
Packit Service |
d328f3 |
NM_CMP_RETURN (memcmp ((a), (b), (size)))
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define NM_CMP_DIRECT_IN6ADDR(a, b) \
|
|
Packit Service |
d328f3 |
G_STMT_START { \
|
|
Packit Service |
d328f3 |
const struct in6_addr *const _a = (a); \
|
|
Packit Service |
d328f3 |
const struct in6_addr *const _b = (b); \
|
|
Packit Service |
d328f3 |
NM_CMP_RETURN (memcmp (_a, _b, sizeof (struct in6_addr))); \
|
|
Packit Service |
d328f3 |
} G_STMT_END
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define NM_CMP_FIELD(a, b, field) \
|
|
Packit Service |
d328f3 |
NM_CMP_DIRECT (((a)->field), ((b)->field))
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define NM_CMP_FIELD_UNSAFE(a, b, field) \
|
|
Packit Service |
d328f3 |
G_STMT_START { \
|
|
Packit Service |
d328f3 |
/* it's unsafe, because it evaluates the arguments more then once.
|
|
Packit Service |
d328f3 |
* This is necessary for bitfields, for which typeof() doesn't work. */ \
|
|
Packit Service |
d328f3 |
if (((a)->field) != ((b)->field)) \
|
|
Packit Service |
d328f3 |
return ((a)->field < ((b)->field)) ? -1 : 1; \
|
|
Packit Service |
d328f3 |
} G_STMT_END
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define NM_CMP_FIELD_BOOL(a, b, field) \
|
|
Packit Service |
d328f3 |
NM_CMP_DIRECT (!!((a)->field), !!((b)->field))
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define NM_CMP_FIELD_STR(a, b, field) \
|
|
Packit Service |
d328f3 |
NM_CMP_RETURN (strcmp (((a)->field), ((b)->field)))
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define NM_CMP_FIELD_STR_INTERNED(a, b, field) \
|
|
Packit Service |
d328f3 |
G_STMT_START { \
|
|
Packit Service |
d328f3 |
const char *_a = ((a)->field); \
|
|
Packit Service |
d328f3 |
const char *_b = ((b)->field); \
|
|
Packit Service |
d328f3 |
\
|
|
Packit Service |
d328f3 |
if (_a != _b) { \
|
|
Packit Service |
d328f3 |
NM_CMP_RETURN (g_strcmp0 (_a, _b)); \
|
|
Packit Service |
d328f3 |
} \
|
|
Packit Service |
d328f3 |
} G_STMT_END
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define NM_CMP_FIELD_STR0(a, b, field) \
|
|
Packit Service |
d328f3 |
NM_CMP_RETURN (g_strcmp0 (((a)->field), ((b)->field)))
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define NM_CMP_FIELD_MEMCMP_LEN(a, b, field, len) \
|
|
Packit Service |
d328f3 |
NM_CMP_RETURN (memcmp (&((a)->field), &((b)->field), \
|
|
Packit Service |
d328f3 |
MIN (len, sizeof ((a)->field))))
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define NM_CMP_FIELD_MEMCMP(a, b, field) \
|
|
Packit Service |
d328f3 |
NM_CMP_RETURN (memcmp (&((a)->field), \
|
|
Packit Service |
d328f3 |
&((b)->field), \
|
|
Packit Service |
d328f3 |
sizeof ((a)->field)))
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define NM_CMP_FIELD_IN6ADDR(a, b, field) \
|
|
Packit Service |
d328f3 |
G_STMT_START { \
|
|
Packit Service |
d328f3 |
const struct in6_addr *const _a = &((a)->field); \
|
|
Packit Service |
d328f3 |
const struct in6_addr *const _b = &((b)->field); \
|
|
Packit Service |
d328f3 |
NM_CMP_RETURN (memcmp (_a, _b, sizeof (struct in6_addr))); \
|
|
Packit Service |
d328f3 |
} G_STMT_END
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
/*****************************************************************************/
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
extern const void *const _NM_PTRARRAY_EMPTY[1];
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define NM_PTRARRAY_EMPTY(type) ((type const*) _NM_PTRARRAY_EMPTY)
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
static inline void
|
|
Packit Service |
d328f3 |
_nm_utils_strbuf_init (char *buf, gsize len, char **p_buf_ptr, gsize *p_buf_len)
|
|
Packit Service |
d328f3 |
{
|
|
Packit Service |
d328f3 |
NM_SET_OUT (p_buf_len, len);
|
|
Packit Service |
d328f3 |
NM_SET_OUT (p_buf_ptr, buf);
|
|
Packit Service |
d328f3 |
buf[0] = '\0';
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define nm_utils_strbuf_init(buf, p_buf_ptr, p_buf_len) \
|
|
Packit Service |
d328f3 |
G_STMT_START { \
|
|
Packit Service |
d328f3 |
G_STATIC_ASSERT (G_N_ELEMENTS (buf) == sizeof (buf) && sizeof (buf) > sizeof (char *)); \
|
|
Packit Service |
d328f3 |
_nm_utils_strbuf_init ((buf), sizeof (buf), (p_buf_ptr), (p_buf_len)); \
|
|
Packit Service |
d328f3 |
} G_STMT_END
|
|
Packit Service |
d328f3 |
void nm_utils_strbuf_append (char **buf, gsize *len, const char *format, ...) _nm_printf (3, 4);
|
|
Packit Service |
d328f3 |
void nm_utils_strbuf_append_c (char **buf, gsize *len, char c);
|
|
Packit Service |
d328f3 |
void nm_utils_strbuf_append_str (char **buf, gsize *len, const char *str);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
const char *nm_strquote (char *buf, gsize buf_len, const char *str);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
/*****************************************************************************/
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
const char **nm_utils_strsplit_set (const char *str, const char *delimiters);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
gssize nm_utils_strv_find_first (char **list, gssize len, const char *needle);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
char **_nm_utils_strv_cleanup (char **strv,
|
|
Packit Service |
d328f3 |
gboolean strip_whitespace,
|
|
Packit Service |
d328f3 |
gboolean skip_empty,
|
|
Packit Service |
d328f3 |
gboolean skip_repeated);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
/*****************************************************************************/
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
guint32 _nm_utils_ip4_prefix_to_netmask (guint32 prefix);
|
|
Packit Service |
d328f3 |
guint32 _nm_utils_ip4_get_default_prefix (guint32 ip);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
gboolean nm_utils_ip_is_site_local (int addr_family,
|
|
Packit Service |
d328f3 |
const void *address);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
/*****************************************************************************/
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
gboolean nm_utils_parse_inaddr_bin (int addr_family,
|
|
Packit Service |
d328f3 |
const char *text,
|
|
Packit Service |
d328f3 |
gpointer out_addr);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
gboolean nm_utils_parse_inaddr (int addr_family,
|
|
Packit Service |
d328f3 |
const char *text,
|
|
Packit Service |
d328f3 |
char **out_addr);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
gboolean nm_utils_parse_inaddr_prefix_bin (int addr_family,
|
|
Packit Service |
d328f3 |
const char *text,
|
|
Packit Service |
d328f3 |
gpointer out_addr,
|
|
Packit Service |
d328f3 |
int *out_prefix);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
gboolean nm_utils_parse_inaddr_prefix (int addr_family,
|
|
Packit Service |
d328f3 |
const char *text,
|
|
Packit Service |
d328f3 |
char **out_addr,
|
|
Packit Service |
d328f3 |
int *out_prefix);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
gint64 _nm_utils_ascii_str_to_int64 (const char *str, guint base, gint64 min, gint64 max, gint64 fallback);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
gint _nm_utils_ascii_str_to_bool (const char *str,
|
|
Packit Service |
d328f3 |
gint default_value);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
/*****************************************************************************/
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
extern char _nm_utils_to_string_buffer[2096];
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
void nm_utils_to_string_buffer_init (char **buf, gsize *len);
|
|
Packit Service |
d328f3 |
gboolean nm_utils_to_string_buffer_init_null (gconstpointer obj, char **buf, gsize *len);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
/*****************************************************************************/
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
typedef struct {
|
|
Packit Service |
d328f3 |
unsigned flag;
|
|
Packit Service |
d328f3 |
const char *name;
|
|
Packit Service |
d328f3 |
} NMUtilsFlags2StrDesc;
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define NM_UTILS_FLAGS2STR(f, n) { .flag = f, .name = ""n, }
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define _NM_UTILS_FLAGS2STR_DEFINE(scope, fcn_name, flags_type, ...) \
|
|
Packit Service |
d328f3 |
scope const char * \
|
|
Packit Service |
d328f3 |
fcn_name (flags_type flags, char *buf, gsize len) \
|
|
Packit Service |
d328f3 |
{ \
|
|
Packit Service |
d328f3 |
static const NMUtilsFlags2StrDesc descs[] = { \
|
|
Packit Service |
d328f3 |
__VA_ARGS__ \
|
|
Packit Service |
d328f3 |
}; \
|
|
Packit Service |
d328f3 |
G_STATIC_ASSERT (sizeof (flags_type) <= sizeof (unsigned)); \
|
|
Packit Service |
d328f3 |
return nm_utils_flags2str (descs, G_N_ELEMENTS (descs), flags, buf, len); \
|
|
Packit Service |
d328f3 |
};
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define NM_UTILS_FLAGS2STR_DEFINE(fcn_name, flags_type, ...) \
|
|
Packit Service |
d328f3 |
_NM_UTILS_FLAGS2STR_DEFINE (, fcn_name, flags_type, __VA_ARGS__)
|
|
Packit Service |
d328f3 |
#define NM_UTILS_FLAGS2STR_DEFINE_STATIC(fcn_name, flags_type, ...) \
|
|
Packit Service |
d328f3 |
_NM_UTILS_FLAGS2STR_DEFINE (static, fcn_name, flags_type, __VA_ARGS__)
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
const char *nm_utils_flags2str (const NMUtilsFlags2StrDesc *descs,
|
|
Packit Service |
d328f3 |
gsize n_descs,
|
|
Packit Service |
d328f3 |
unsigned flags,
|
|
Packit Service |
d328f3 |
char *buf,
|
|
Packit Service |
d328f3 |
gsize len);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
/*****************************************************************************/
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define NM_UTILS_ENUM2STR(v, n) (void) 0; case v: s = ""n""; break; (void) 0
|
|
Packit Service |
d328f3 |
#define NM_UTILS_ENUM2STR_IGNORE(v) (void) 0; case v: break; (void) 0
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define _NM_UTILS_ENUM2STR_DEFINE(scope, fcn_name, lookup_type, int_fmt, ...) \
|
|
Packit Service |
d328f3 |
scope const char * \
|
|
Packit Service |
d328f3 |
fcn_name (lookup_type val, char *buf, gsize len) \
|
|
Packit Service |
d328f3 |
{ \
|
|
Packit Service |
d328f3 |
nm_utils_to_string_buffer_init (&buf, &len;; \
|
|
Packit Service |
d328f3 |
if (len) { \
|
|
Packit Service |
d328f3 |
const char *s = NULL; \
|
|
Packit Service |
d328f3 |
switch (val) { \
|
|
Packit Service |
d328f3 |
(void) 0, \
|
|
Packit Service |
d328f3 |
__VA_ARGS__ \
|
|
Packit Service |
d328f3 |
(void) 0; \
|
|
Packit Service |
d328f3 |
}; \
|
|
Packit Service |
d328f3 |
if (s) \
|
|
Packit Service |
d328f3 |
g_strlcpy (buf, s, len); \
|
|
Packit Service |
d328f3 |
else \
|
|
Packit Service |
d328f3 |
g_snprintf (buf, len, "(%"int_fmt")", val); \
|
|
Packit Service |
d328f3 |
} \
|
|
Packit Service |
d328f3 |
return buf; \
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define NM_UTILS_ENUM2STR_DEFINE(fcn_name, lookup_type, ...) \
|
|
Packit Service |
d328f3 |
_NM_UTILS_ENUM2STR_DEFINE (, fcn_name, lookup_type, "d", __VA_ARGS__)
|
|
Packit Service |
d328f3 |
#define NM_UTILS_ENUM2STR_DEFINE_STATIC(fcn_name, lookup_type, ...) \
|
|
Packit Service |
d328f3 |
_NM_UTILS_ENUM2STR_DEFINE (static, fcn_name, lookup_type, "d", __VA_ARGS__)
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
/*****************************************************************************/
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define _nm_g_slice_free_fcn_define(mem_size) \
|
|
Packit Service |
d328f3 |
static inline void \
|
|
Packit Service |
d328f3 |
_nm_g_slice_free_fcn_##mem_size (gpointer mem_block) \
|
|
Packit Service |
d328f3 |
{ \
|
|
Packit Service |
d328f3 |
g_slice_free1 (mem_size, mem_block); \
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
_nm_g_slice_free_fcn_define (1)
|
|
Packit Service |
d328f3 |
_nm_g_slice_free_fcn_define (2)
|
|
Packit Service |
d328f3 |
_nm_g_slice_free_fcn_define (4)
|
|
Packit Service |
d328f3 |
_nm_g_slice_free_fcn_define (8)
|
|
Packit Service |
d328f3 |
_nm_g_slice_free_fcn_define (12)
|
|
Packit Service |
d328f3 |
_nm_g_slice_free_fcn_define (16)
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define _nm_g_slice_free_fcn1(mem_size) \
|
|
Packit Service |
d328f3 |
({ \
|
|
Packit Service |
d328f3 |
void (*_fcn) (gpointer); \
|
|
Packit Service |
d328f3 |
\
|
|
Packit Service |
d328f3 |
/* If mem_size is a compile time constant, the compiler
|
|
Packit Service |
d328f3 |
* will be able to optimize this. Hence, you don't want
|
|
Packit Service |
d328f3 |
* to call this with a non-constant size argument. */ \
|
|
Packit Service |
d328f3 |
G_STATIC_ASSERT_EXPR ( ((mem_size) == 1) \
|
|
Packit Service |
d328f3 |
|| ((mem_size) == 2) \
|
|
Packit Service |
d328f3 |
|| ((mem_size) == 4) \
|
|
Packit Service |
d328f3 |
|| ((mem_size) == 8) \
|
|
Packit Service |
d328f3 |
|| ((mem_size) == 12) \
|
|
Packit Service |
d328f3 |
|| ((mem_size) == 16)); \
|
|
Packit Service |
d328f3 |
switch ((mem_size)) { \
|
|
Packit Service |
d328f3 |
case 1: _fcn = _nm_g_slice_free_fcn_1; break; \
|
|
Packit Service |
d328f3 |
case 2: _fcn = _nm_g_slice_free_fcn_2; break; \
|
|
Packit Service |
d328f3 |
case 4: _fcn = _nm_g_slice_free_fcn_4; break; \
|
|
Packit Service |
d328f3 |
case 8: _fcn = _nm_g_slice_free_fcn_8; break; \
|
|
Packit Service |
d328f3 |
case 12: _fcn = _nm_g_slice_free_fcn_12; break; \
|
|
Packit Service |
d328f3 |
case 16: _fcn = _nm_g_slice_free_fcn_16; break; \
|
|
Packit Service |
d328f3 |
default: g_assert_not_reached (); _fcn = NULL; break; \
|
|
Packit Service |
d328f3 |
} \
|
|
Packit Service |
d328f3 |
_fcn; \
|
|
Packit Service |
d328f3 |
})
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
/**
|
|
Packit Service |
d328f3 |
* nm_g_slice_free_fcn:
|
|
Packit Service |
d328f3 |
* @type: type argument for sizeof() operator that you would
|
|
Packit Service |
d328f3 |
* pass to g_slice_new().
|
|
Packit Service |
d328f3 |
*
|
|
Packit Service |
d328f3 |
* Returns: a function pointer with GDestroyNotify signature
|
|
Packit Service |
d328f3 |
* for g_slice_free(type,*).
|
|
Packit Service |
d328f3 |
*
|
|
Packit Service |
d328f3 |
* Only certain types are implemented. You'll get an assertion
|
|
Packit Service |
d328f3 |
* using the wrong type. */
|
|
Packit Service |
d328f3 |
#define nm_g_slice_free_fcn(type) (_nm_g_slice_free_fcn1 (sizeof (type)))
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define nm_g_slice_free_fcn_gint64 (nm_g_slice_free_fcn (gint64))
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
/*****************************************************************************/
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
/**
|
|
Packit Service |
d328f3 |
* NMUtilsError:
|
|
Packit Service |
d328f3 |
* @NM_UTILS_ERROR_UNKNOWN: unknown or unclassified error
|
|
Packit Service |
d328f3 |
* @NM_UTILS_ERROR_CANCELLED_DISPOSING: when disposing an object that has
|
|
Packit Service |
d328f3 |
* pending aynchronous operations, the operation is cancelled with this
|
|
Packit Service |
d328f3 |
* error reason. Depending on the usage, this might indicate a bug because
|
|
Packit Service |
d328f3 |
* usually the target object should stay alive as long as there are pending
|
|
Packit Service |
d328f3 |
* operations.
|
|
Packit Service |
d328f3 |
* @NM_UTILS_ERROR_INVALID_ARGUMENT: invalid argument.
|
|
Packit Service |
d328f3 |
*/
|
|
Packit Service |
d328f3 |
typedef enum {
|
|
Packit Service |
d328f3 |
NM_UTILS_ERROR_UNKNOWN = 0, /*< nick=Unknown >*/
|
|
Packit Service |
d328f3 |
NM_UTILS_ERROR_CANCELLED_DISPOSING, /*< nick=CancelledDisposing >*/
|
|
Packit Service |
d328f3 |
NM_UTILS_ERROR_INVALID_ARGUMENT, /*< nick=InvalidArgument >*/
|
|
Packit Service |
d328f3 |
} NMUtilsError;
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define NM_UTILS_ERROR (nm_utils_error_quark ())
|
|
Packit Service |
d328f3 |
GQuark nm_utils_error_quark (void);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
void nm_utils_error_set_cancelled (GError **error,
|
|
Packit Service |
d328f3 |
gboolean is_disposing,
|
|
Packit Service |
d328f3 |
const char *instance_name);
|
|
Packit Service |
d328f3 |
gboolean nm_utils_error_is_cancelled (GError *error,
|
|
Packit Service |
d328f3 |
gboolean consider_is_disposing);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
/*****************************************************************************/
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
gboolean nm_g_object_set_property (GObject *object,
|
|
Packit Service |
d328f3 |
const gchar *property_name,
|
|
Packit Service |
d328f3 |
const GValue *value,
|
|
Packit Service |
d328f3 |
GError **error);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
gboolean nm_g_object_set_property_boolean (GObject *object,
|
|
Packit Service |
d328f3 |
const gchar *property_name,
|
|
Packit Service |
d328f3 |
gboolean value,
|
|
Packit Service |
d328f3 |
GError **error);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
gboolean nm_g_object_set_property_uint (GObject *object,
|
|
Packit Service |
d328f3 |
const gchar *property_name,
|
|
Packit Service |
d328f3 |
guint value,
|
|
Packit Service |
d328f3 |
GError **error);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
GParamSpec *nm_g_object_class_find_property_from_gtype (GType gtype,
|
|
Packit Service |
d328f3 |
const char *property_name);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
/*****************************************************************************/
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
typedef enum {
|
|
Packit Service |
d328f3 |
NM_UTILS_STR_UTF8_SAFE_FLAG_NONE = 0,
|
|
Packit Service |
d328f3 |
NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL = 0x0001,
|
|
Packit Service |
d328f3 |
NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_NON_ASCII = 0x0002,
|
|
Packit Service |
d328f3 |
} NMUtilsStrUtf8SafeFlags;
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
const char *nm_utils_str_utf8safe_escape (const char *str, NMUtilsStrUtf8SafeFlags flags, char **to_free);
|
|
Packit Service |
d328f3 |
const char *nm_utils_str_utf8safe_unescape (const char *str, char **to_free);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
char *nm_utils_str_utf8safe_escape_cp (const char *str, NMUtilsStrUtf8SafeFlags flags);
|
|
Packit Service |
d328f3 |
char *nm_utils_str_utf8safe_unescape_cp (const char *str);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
char *nm_utils_str_utf8safe_escape_take (char *str, NMUtilsStrUtf8SafeFlags flags);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
/*****************************************************************************/
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
typedef struct {
|
|
Packit Service |
d328f3 |
const char *name;
|
|
Packit Service |
d328f3 |
} NMUtilsNamedEntry;
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
typedef struct {
|
|
Packit Service |
d328f3 |
union {
|
|
Packit Service |
d328f3 |
NMUtilsNamedEntry named_entry;
|
|
Packit Service |
d328f3 |
const char *name;
|
|
Packit Service |
d328f3 |
};
|
|
Packit Service |
d328f3 |
union {
|
|
Packit Service |
d328f3 |
const char *value_str;
|
|
Packit Service |
d328f3 |
gconstpointer value_ptr;
|
|
Packit Service |
d328f3 |
};
|
|
Packit Service |
d328f3 |
} NMUtilsNamedValue;
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define nm_utils_named_entry_cmp nm_strcmp_p
|
|
Packit Service |
d328f3 |
#define nm_utils_named_entry_cmp_with_data nm_strcmp_p_with_data
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
NMUtilsNamedValue *nm_utils_named_values_from_str_dict (GHashTable *hash, guint *out_len);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
const char **nm_utils_strdict_get_keys (const GHashTable *hash,
|
|
Packit Service |
d328f3 |
gboolean sorted,
|
|
Packit Service |
d328f3 |
guint *out_length);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
char **nm_utils_strv_make_deep_copied (const char **strv);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
static inline char **
|
|
Packit Service |
d328f3 |
nm_utils_strv_make_deep_copied_nonnull (const char **strv)
|
|
Packit Service |
d328f3 |
{
|
|
Packit Service |
d328f3 |
return nm_utils_strv_make_deep_copied (strv) ?: g_new0 (char *, 1);
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
/*****************************************************************************/
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define NM_UTILS_NS_PER_SECOND ((gint64) 1000000000)
|
|
Packit Service |
d328f3 |
#define NM_UTILS_NS_PER_MSEC ((gint64) 1000000)
|
|
Packit Service |
d328f3 |
#define NM_UTILS_NS_TO_MSEC_CEIL(nsec) (((nsec) + (NM_UTILS_NS_PER_MSEC - 1)) / NM_UTILS_NS_PER_MSEC)
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
/*****************************************************************************/
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
int nm_utils_fd_wait_for_event (int fd, int event, gint64 timeout_ns);
|
|
Packit Service |
d328f3 |
ssize_t nm_utils_fd_read_loop (int fd, void *buf, size_t nbytes, bool do_poll);
|
|
Packit Service |
d328f3 |
int nm_utils_fd_read_loop_exact (int fd, void *buf, size_t nbytes, bool do_poll);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
/*****************************************************************************/
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#endif /* __NM_SHARED_UTILS_H__ */
|