~ubuntu-branches/ubuntu/utopic/network-manager-openvpn/utopic

« back to all changes in this revision

Viewing changes to src/nm-utils.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2009-02-25 10:43:09 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090225104309-v4b2scsl68protyn
Tags: 0.7.0.97-1
* New upstream release.
* debian/patches/01_dbus_policy.patch
  - Removed, merged upstream.
* debian/control
  - Drop libgnomeui-dev from Build-Depends, no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* NetworkManager -- Network link manager
2
 
 *
3
 
 * Ray Strode <rstrode@redhat.com>
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or modify
6
 
 * it under the terms of the GNU General Public License as published by
7
 
 * the Free Software Foundation; either version 2 of the License, or
8
 
 * (at your option) any later version.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License
16
 
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
 
 *
19
 
 * (C) Copyright 2005 Red Hat, Inc.
20
 
 */
21
 
 
22
 
#ifndef NM_UTILS_H
23
 
#define NM_UTILS_H
24
 
 
25
 
#include <glib.h>
26
 
#include <execinfo.h>
27
 
 
28
 
#define nm_print_backtrace()                                            \
29
 
G_STMT_START                                                            \
30
 
{                                                                       \
31
 
        void *_call_stack[512];                                         \
32
 
        int  _call_stack_size;                                          \
33
 
        char **_symbols;                                                \
34
 
        _call_stack_size = backtrace (_call_stack,                      \
35
 
                                      G_N_ELEMENTS (_call_stack));      \
36
 
        _symbols = backtrace_symbols (_call_stack, _call_stack_size);   \
37
 
        if (_symbols != NULL)                                           \
38
 
        {                                                               \
39
 
                int _i;                                                 \
40
 
                _i = 0;                                                 \
41
 
                g_critical ("traceback:\n");                            \
42
 
                while (_i < _call_stack_size)                           \
43
 
                {                                                       \
44
 
                        g_critical ("\t%s\n", _symbols[_i]);            \
45
 
                        _i++;                                           \
46
 
                }                                                       \
47
 
                free (_symbols);                                        \
48
 
        }                                                               \
49
 
}                                                                       \
50
 
G_STMT_END
51
 
 
52
 
#define nm_get_timestamp(timestamp)                                     \
53
 
G_STMT_START                                                            \
54
 
{                                                                       \
55
 
        GTimeVal _tv;                                                   \
56
 
        g_get_current_time (&_tv);                                      \
57
 
        *timestamp = (_tv.tv_sec * (1.0 * G_USEC_PER_SEC) +             \
58
 
                      _tv.tv_usec) / G_USEC_PER_SEC;                    \
59
 
}                                                                       \
60
 
G_STMT_END
61
 
 
62
 
#define nm_info(fmt, args...)                                           \
63
 
G_STMT_START                                                            \
64
 
{                                                                       \
65
 
        g_message ("<information>\t" fmt "\n", ##args);                 \
66
 
} G_STMT_END
67
 
 
68
 
#define nm_info_str(fmt_str, args...)                                           \
69
 
G_STMT_START                                                            \
70
 
{                                                                       \
71
 
        g_message ("<information>\t%s\n", fmt_str, ##args);                     \
72
 
} G_STMT_END
73
 
 
74
 
#define nm_debug(fmt, args...)                                          \
75
 
G_STMT_START                                                            \
76
 
{                                                                       \
77
 
        gdouble _timestamp;                                             \
78
 
        nm_get_timestamp (&_timestamp);                                 \
79
 
        g_debug ("<debug info>\t[%f] %s (): " fmt "\n", _timestamp,     \
80
 
                 G_STRFUNC, ##args);                            \
81
 
} G_STMT_END
82
 
 
83
 
#define nm_debug_str(fmt_str, args...)                                          \
84
 
G_STMT_START                                                            \
85
 
{                                                                       \
86
 
        gdouble _timestamp;                                             \
87
 
        nm_get_timestamp (&_timestamp);                                 \
88
 
        g_debug ("<debug info>\t[%f] %s (): %s\n", _timestamp,  \
89
 
                 G_STRFUNC, fmt_str, ##args);                           \
90
 
} G_STMT_END
91
 
 
92
 
#define nm_warning(fmt, args...)                                        \
93
 
G_STMT_START                                                            \
94
 
{                                                                       \
95
 
        g_warning ("<WARNING>\t %s (): " fmt "\n",                      \
96
 
                   G_STRFUNC, ##args);                  \
97
 
} G_STMT_END
98
 
 
99
 
#define nm_warning_str(fmt_str, args...)                                        \
100
 
G_STMT_START                                                            \
101
 
{                                                                       \
102
 
        g_warning ("<WARNING>\t %s (): %s\n",                   \
103
 
                   G_STRFUNC, fmt_str, ##args);                 \
104
 
} G_STMT_END
105
 
 
106
 
#define nm_error(fmt, args...)                                          \
107
 
G_STMT_START                                                            \
108
 
{                                                                       \
109
 
        gdouble _timestamp;                                             \
110
 
        nm_get_timestamp (&_timestamp);                                 \
111
 
        g_critical ("<ERROR>\t[%f] %s (): " fmt "\n", _timestamp,       \
112
 
                    G_STRFUNC, ##args);                 \
113
 
        nm_print_backtrace ();                                          \
114
 
        G_BREAKPOINT ();                                                \
115
 
} G_STMT_END
116
 
 
117
 
#define nm_error_str(fmt_str, args...)                                          \
118
 
G_STMT_START                                                            \
119
 
{                                                                       \
120
 
        gdouble _timestamp;                                             \
121
 
        nm_get_timestamp (&_timestamp);                                 \
122
 
        g_critical ("<ERROR>\t[%f] %s (): %s\n", _timestamp,    \
123
 
                    G_STRFUNC, fmt_str, ##args);                        \
124
 
        nm_print_backtrace ();                                          \
125
 
        G_BREAKPOINT ();                                                \
126
 
} G_STMT_END
127
 
 
128
 
gchar *nm_dbus_escape_object_path (const gchar *utf8_string);
129
 
gchar *nm_dbus_unescape_object_path (const gchar *object_path);
130
 
 
131
 
static inline const char *nm_find_openvpn (void)
132
 
{
133
 
        static const char *openvpn_binary_paths[] =
134
 
        {
135
 
                "/usr/sbin/openvpn",
136
 
                "/sbin/openvpn",
137
 
                NULL
138
 
        };
139
 
 
140
 
        const char  **openvpn_binary = openvpn_binary_paths;
141
 
 
142
 
        while (*openvpn_binary != NULL) {
143
 
                if (g_file_test (*openvpn_binary, G_FILE_TEST_EXISTS))
144
 
                        break;
145
 
                openvpn_binary++;
146
 
        }
147
 
 
148
 
        return *openvpn_binary;
149
 
}
150
 
 
151
 
 
152
 
#endif /* NM_UTILS_H */