2 * This file is part of the Nice GLib ICE library.
4 * (C) 2008 Collabora Ltd.
5 * Contact: Youness Alaoui
6 * (C) 2008 Nokia Corporation. All rights reserved.
8 * The contents of this file are subject to the Mozilla Public License Version
9 * 1.1 (the "License"); you may not use this file except in compliance with
10 * the License. You may obtain a copy of the License at
11 * http://www.mozilla.org/MPL/
13 * Software distributed under the License is distributed on an "AS IS" basis,
14 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
15 * for the specific language governing rights and limitations under the
18 * The Original Code is the Nice GLib ICE library.
20 * The Initial Developers of the Original Code are Collabora Ltd and Nokia
21 * Corporation. All Rights Reserved.
24 * Youness Alaoui, Collabora Ltd.
26 * Alternatively, the contents of this file may be used under the terms of the
27 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
28 * case the provisions of LGPL are applicable instead of those above. If you
29 * wish to allow use of your version of this file only under the terms of the
30 * LGPL and not to allow others to use your version of this file under the
31 * MPL, indicate your decision by deleting the provisions above and replace
32 * them with the notice and other provisions required by the LGPL. If you do
33 * not delete the provisions above, a recipient may use your version of this
34 * file under either the MPL or the LGPL.
45 #include "stunagent.h"
46 #include "pseudotcp.h"
48 #include "agent-priv.h"
50 static int debug_enabled = 0;
51 static int debug_verbose_enabled = 0;
53 #define NICE_DEBUG_STUN 1
54 #define NICE_DEBUG_NICE 2
55 #define NICE_DEBUG_PSEUDOTCP 4
56 #define NICE_DEBUG_PSEUDOTCP_VERBOSE 8
57 #define NICE_DEBUG_NICE_VERBOSE 16
59 static const GDebugKey keys[] = {
60 { (gchar *)"stun", NICE_DEBUG_STUN },
61 { (gchar *)"nice", NICE_DEBUG_NICE },
62 { (gchar *)"pseudotcp", NICE_DEBUG_PSEUDOTCP },
63 { (gchar *)"pseudotcp-verbose", NICE_DEBUG_PSEUDOTCP_VERBOSE },
64 { (gchar *)"nice-verbose", NICE_DEBUG_NICE_VERBOSE }
67 static const GDebugKey gkeys[] = {
68 { (gchar *)"libnice-stun", NICE_DEBUG_STUN },
69 { (gchar *)"libnice", NICE_DEBUG_NICE },
70 { (gchar *)"libnice-pseudotcp", NICE_DEBUG_PSEUDOTCP },
71 { (gchar *)"libnice-pseudotcp-verbose", NICE_DEBUG_PSEUDOTCP_VERBOSE },
72 { (gchar *)"libnice-verbose", NICE_DEBUG_NICE_VERBOSE }
76 stun_handler (const char *format, va_list ap) G_GNUC_PRINTF (1, 0);
79 stun_handler (const char *format, va_list ap)
81 g_logv ("libnice-stun", G_LOG_LEVEL_DEBUG, format, ap);
84 void nice_debug_init (void)
86 static gboolean debug_initialized = FALSE;
87 const gchar *flags_string;
88 const gchar *gflags_string;
91 if (!debug_initialized) {
92 debug_initialized = TRUE;
94 flags_string = g_getenv ("NICE_DEBUG");
95 gflags_string = g_getenv ("G_MESSAGES_DEBUG");
98 flags = g_parse_debug_string (flags_string, keys, G_N_ELEMENTS (keys));
100 flags |= g_parse_debug_string (gflags_string, gkeys, G_N_ELEMENTS (gkeys));
101 if (gflags_string && strstr (gflags_string, "libnice-pseudotcp-verbose"))
102 flags |= NICE_DEBUG_PSEUDOTCP_VERBOSE;
103 if (gflags_string && strstr (gflags_string, "libnice-verbose")) {
104 flags |= NICE_DEBUG_NICE_VERBOSE;
107 stun_set_debug_handler (stun_handler);
108 debug_enabled = !!(flags & NICE_DEBUG_NICE);
109 if (flags & NICE_DEBUG_STUN)
110 stun_debug_enable ();
112 stun_debug_disable ();
114 if (flags & NICE_DEBUG_NICE_VERBOSE)
115 debug_verbose_enabled = TRUE;
117 /* Set verbose before normal so that if we use 'all', then only
118 normal debug is enabled, we'd need to set pseudotcp-verbose without the
119 pseudotcp flag in order to actually enable verbose pseudotcp */
120 if (flags & NICE_DEBUG_PSEUDOTCP_VERBOSE)
121 pseudo_tcp_set_debug_level (PSEUDO_TCP_DEBUG_VERBOSE);
122 else if (flags & NICE_DEBUG_PSEUDOTCP)
123 pseudo_tcp_set_debug_level (PSEUDO_TCP_DEBUG_NORMAL);
128 gboolean nice_debug_is_enabled (void)
130 return debug_enabled;
132 gboolean nice_debug_is_verbose (void)
134 return debug_verbose_enabled;
137 /* Defined in agent-priv.h. */
140 void nice_debug_enable (gboolean with_stun)
145 stun_debug_enable ();
147 void nice_debug_disable (gboolean with_stun)
152 stun_debug_disable ();
156 void nice_debug (const char *fmt, ...)
161 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, fmt, ap);
165 void nice_debug_verbose (const char *fmt, ...)
168 if (debug_enabled && debug_verbose_enabled) {
170 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, fmt, ap);
175 /* Defined in agent-priv.h. */