2008-07-27 20:03:46 +00:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
2007-09-12 16:23:53 +00:00
|
|
|
/* NetworkManager -- Network link manager
|
|
|
|
*
|
|
|
|
* Ray Strode <rstrode@redhat.com>
|
2008-07-27 20:03:46 +00:00
|
|
|
* Dan Williams <dcbw@redhat.com>
|
|
|
|
* Tambet Ingo <tambet@gmail.com>
|
2007-09-12 16:23:53 +00:00
|
|
|
*
|
2008-07-27 20:03:46 +00:00
|
|
|
* 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.
|
2007-09-12 16:23:53 +00:00
|
|
|
*
|
2008-07-27 20:03:46 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2007-09-12 16:23:53 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-07-27 20:03:46 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2007-09-12 16:23:53 +00:00
|
|
|
*
|
2008-07-27 20:03:46 +00:00
|
|
|
* 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.
|
2007-09-12 16:23:53 +00:00
|
|
|
*
|
2008-07-27 20:03:46 +00:00
|
|
|
* (C) Copyright 2005 - 2008 Red Hat, Inc.
|
2007-09-12 16:23:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef NM_UTILS_H
|
|
|
|
#define NM_UTILS_H
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <execinfo.h>
|
|
|
|
|
2007-10-23 10:54:37 +00:00
|
|
|
#include "nm-connection.h"
|
|
|
|
|
2008-05-06 21:41:08 +00:00
|
|
|
/*********************************************************/
|
|
|
|
/* The API defined here is _NOT_ guaranteed in any way!! */
|
|
|
|
/*********************************************************/
|
|
|
|
|
2008-11-24 16:55:37 +00:00
|
|
|
/**
|
|
|
|
* nm_print_backtrace:
|
|
|
|
*
|
|
|
|
* Prints a backtrace of the calling process to the logging location.
|
|
|
|
*/
|
2007-09-12 16:23:53 +00:00
|
|
|
#define nm_print_backtrace() \
|
|
|
|
G_STMT_START \
|
|
|
|
{ \
|
|
|
|
void *_call_stack[512]; \
|
|
|
|
int _call_stack_size; \
|
|
|
|
char **_symbols; \
|
|
|
|
_call_stack_size = backtrace (_call_stack, \
|
|
|
|
G_N_ELEMENTS (_call_stack)); \
|
|
|
|
_symbols = backtrace_symbols (_call_stack, _call_stack_size); \
|
|
|
|
if (_symbols != NULL) \
|
|
|
|
{ \
|
|
|
|
int _i; \
|
|
|
|
_i = 0; \
|
|
|
|
g_critical ("traceback:\n"); \
|
|
|
|
while (_i < _call_stack_size) \
|
|
|
|
{ \
|
|
|
|
g_critical ("\t%s\n", _symbols[_i]); \
|
|
|
|
_i++; \
|
|
|
|
} \
|
|
|
|
free (_symbols); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
G_STMT_END
|
|
|
|
|
2008-11-24 16:55:37 +00:00
|
|
|
/**
|
|
|
|
* nm_get_timestamp:
|
|
|
|
* @timestamp: location in which to place the current timestamp
|
|
|
|
*
|
|
|
|
* For debugging only.
|
|
|
|
*/
|
2007-09-12 16:23:53 +00:00
|
|
|
#define nm_get_timestamp(timestamp) \
|
|
|
|
G_STMT_START \
|
|
|
|
{ \
|
|
|
|
GTimeVal _tv; \
|
|
|
|
g_get_current_time (&_tv); \
|
|
|
|
*timestamp = (_tv.tv_sec * (1.0 * G_USEC_PER_SEC) + \
|
|
|
|
_tv.tv_usec) / G_USEC_PER_SEC; \
|
|
|
|
} \
|
|
|
|
G_STMT_END
|
|
|
|
|
|
|
|
#define nm_info(fmt, args...) \
|
|
|
|
G_STMT_START \
|
|
|
|
{ \
|
|
|
|
g_message ("<info> " fmt "\n", ##args); \
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
|
|
#define nm_info_str(fmt_str, args...) \
|
|
|
|
G_STMT_START \
|
|
|
|
{ \
|
|
|
|
g_message ("<info> %s\n", fmt_str, ##args); \
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
|
|
#define nm_debug(fmt, args...) \
|
|
|
|
G_STMT_START \
|
|
|
|
{ \
|
|
|
|
gdouble _timestamp; \
|
|
|
|
nm_get_timestamp (&_timestamp); \
|
|
|
|
g_debug ("<debug> [%f] %s(): " fmt "\n", _timestamp, \
|
|
|
|
G_STRFUNC, ##args); \
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
|
|
#define nm_debug_str(fmt_str, args...) \
|
|
|
|
G_STMT_START \
|
|
|
|
{ \
|
|
|
|
gdouble _timestamp; \
|
|
|
|
nm_get_timestamp (&_timestamp); \
|
|
|
|
g_debug ("<debug> [%f] %s(): %s\n", _timestamp, \
|
|
|
|
G_STRFUNC, fmt_str, ##args); \
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
|
|
#define nm_warning(fmt, args...) \
|
|
|
|
G_STMT_START \
|
|
|
|
{ \
|
|
|
|
g_warning ("<WARN> %s(): " fmt "\n", \
|
|
|
|
G_STRFUNC, ##args); \
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
|
|
#define nm_warning_str(fmt_str, args...) \
|
|
|
|
G_STMT_START \
|
|
|
|
{ \
|
|
|
|
g_warning ("<WARN> %s(): %s\n", \
|
|
|
|
G_STRFUNC, fmt_str, ##args); \
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
|
|
#define nm_error(fmt, args...) \
|
|
|
|
G_STMT_START \
|
|
|
|
{ \
|
|
|
|
gdouble _timestamp; \
|
|
|
|
nm_get_timestamp (&_timestamp); \
|
|
|
|
g_critical ("<ERROR>\t[%f] %s (): " fmt "\n", _timestamp, \
|
|
|
|
G_STRFUNC, ##args); \
|
|
|
|
nm_print_backtrace (); \
|
|
|
|
G_BREAKPOINT (); \
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
|
|
#define nm_error_str(fmt_str, args...) \
|
|
|
|
G_STMT_START \
|
|
|
|
{ \
|
|
|
|
gdouble _timestamp; \
|
|
|
|
nm_get_timestamp (&_timestamp); \
|
|
|
|
g_critical ("<ERROR>\t[%f] %s (): %s\n", _timestamp, \
|
|
|
|
G_STRFUNC, fmt_str, ##args); \
|
|
|
|
nm_print_backtrace (); \
|
|
|
|
G_BREAKPOINT (); \
|
|
|
|
} G_STMT_END
|
|
|
|
|
2008-09-08 18:35:21 +00:00
|
|
|
/* init, deinit nm_utils */
|
|
|
|
gboolean nm_utils_init (GError **error);
|
|
|
|
void nm_utils_deinit (void);
|
|
|
|
|
2007-10-09 08:57:35 +00:00
|
|
|
/* SSID helpers */
|
2007-10-09 10:04:07 +00:00
|
|
|
gboolean nm_utils_is_empty_ssid (const guint8 * ssid, int len);
|
2007-10-09 08:57:35 +00:00
|
|
|
const char *nm_utils_escape_ssid (const guint8 *ssid, guint32 len);
|
|
|
|
gboolean nm_utils_same_ssid (const GByteArray * ssid1,
|
|
|
|
const GByteArray * ssid2,
|
|
|
|
gboolean ignore_trailing_null);
|
2007-09-12 16:23:53 +00:00
|
|
|
|
2007-10-09 10:04:07 +00:00
|
|
|
char *nm_utils_ssid_to_utf8 (const char *ssid, guint32 len);
|
|
|
|
|
2007-09-12 16:23:53 +00:00
|
|
|
GHashTable *nm_utils_gvalue_hash_dup (GHashTable *hash);
|
2008-07-17 17:15:38 +00:00
|
|
|
|
2007-11-07 16:06:43 +00:00
|
|
|
void nm_utils_slist_free (GSList *list,
|
|
|
|
GDestroyNotify elem_destroy_fn);
|
|
|
|
|
2007-10-17 21:40:17 +00:00
|
|
|
typedef enum {
|
|
|
|
NMU_SEC_INVALID = 0,
|
|
|
|
NMU_SEC_NONE,
|
|
|
|
NMU_SEC_STATIC_WEP,
|
|
|
|
NMU_SEC_LEAP,
|
|
|
|
NMU_SEC_DYNAMIC_WEP,
|
|
|
|
NMU_SEC_WPA_PSK,
|
|
|
|
NMU_SEC_WPA_ENTERPRISE,
|
|
|
|
NMU_SEC_WPA2_PSK,
|
2008-05-13 16:57:01 +00:00
|
|
|
NMU_SEC_WPA2_ENTERPRISE
|
2007-10-17 21:40:17 +00:00
|
|
|
} NMUtilsSecurityType;
|
|
|
|
|
|
|
|
gboolean nm_utils_security_valid (NMUtilsSecurityType type,
|
2008-11-20 21:07:03 +00:00
|
|
|
guint32 wifi_caps,
|
2007-10-17 21:40:17 +00:00
|
|
|
gboolean have_ap,
|
2007-12-27 07:17:50 +00:00
|
|
|
gboolean adhoc,
|
2007-10-17 21:40:17 +00:00
|
|
|
guint32 ap_flags,
|
|
|
|
guint32 ap_wpa,
|
|
|
|
guint32 ap_rsn);
|
|
|
|
|
2008-05-06 21:41:08 +00:00
|
|
|
GSList *nm_utils_ip4_addresses_from_gvalue (const GValue *value);
|
|
|
|
void nm_utils_ip4_addresses_to_gvalue (GSList *list, GValue *value);
|
|
|
|
|
2008-08-06 22:23:48 +00:00
|
|
|
GSList *nm_utils_ip4_routes_from_gvalue (const GValue *value);
|
|
|
|
void nm_utils_ip4_routes_to_gvalue (GSList *list, GValue *value);
|
|
|
|
|
2008-11-23 22:55:03 +00:00
|
|
|
guint32 nm_utils_ip4_netmask_to_prefix (guint32 netmask);
|
|
|
|
guint32 nm_utils_ip4_prefix_to_netmask (guint32 prefix);
|
2008-07-07 18:57:37 +00:00
|
|
|
|
2009-06-11 19:52:11 +00:00
|
|
|
GSList *nm_utils_ip6_addresses_from_gvalue (const GValue *value);
|
|
|
|
void nm_utils_ip6_addresses_to_gvalue (GSList *list, GValue *value);
|
|
|
|
|
|
|
|
GSList *nm_utils_ip6_routes_from_gvalue (const GValue *value);
|
|
|
|
void nm_utils_ip6_routes_to_gvalue (GSList *list, GValue *value);
|
|
|
|
|
|
|
|
GSList *nm_utils_ip6_dns_from_gvalue (const GValue *value);
|
|
|
|
void nm_utils_ip6_dns_to_gvalue (GSList *list, GValue *value);
|
|
|
|
|
2008-08-27 02:57:21 +00:00
|
|
|
char *nm_utils_uuid_generate (void);
|
|
|
|
char *nm_utils_uuid_generate_from_string (const char *s);
|
|
|
|
|
2007-09-12 16:23:53 +00:00
|
|
|
#endif /* NM_UTILS_H */
|