discovery: Remove useless checks from discovery_learn_remote_peer_reflexive_candidate
[sipe-libnice.git] / agent / debug.c
blob802d444cc22fbc827bd29c8f90b0074fa8b10a93
1 /*
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
16 * License.
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.
23 * Contributors:
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.
37 #ifdef HAVE_CONFIG_H
38 # include <config.h>
39 #endif
41 #include "debug.h"
43 #include "stunagent.h"
44 #include "pseudotcp.h"
46 static int debug_enabled = 0;
48 #define NICE_DEBUG_STUN 1
49 #define NICE_DEBUG_NICE 2
50 #define NICE_DEBUG_PSEUDOTCP 4
51 #define NICE_DEBUG_PSEUDOTCP_VERBOSE 8
53 static const GDebugKey keys[] = {
54 { (gchar *)"stun", NICE_DEBUG_STUN },
55 { (gchar *)"nice", NICE_DEBUG_NICE },
56 { (gchar *)"pseudotcp", NICE_DEBUG_PSEUDOTCP },
57 { (gchar *)"pseudotcp-verbose", NICE_DEBUG_PSEUDOTCP_VERBOSE },
58 { NULL, 0},
62 void nice_debug_init ()
64 const gchar *flags_string;
65 guint flags;
67 flags_string = g_getenv ("NICE_DEBUG");
69 nice_debug_disable (TRUE);
71 if (flags_string != NULL) {
72 flags = g_parse_debug_string (flags_string, keys, 4);
74 if (flags & NICE_DEBUG_NICE)
75 nice_debug_enable (FALSE);
76 if (flags & NICE_DEBUG_STUN)
77 stun_debug_enable ();
79 /* Set verbose before normal so that if we use 'all', then only
80 normal debug is enabled, we'd need to set pseudotcp-verbose without the
81 pseudotcp flag in order to actually enable verbose pseudotcp */
82 if (flags & NICE_DEBUG_PSEUDOTCP_VERBOSE)
83 pseudo_tcp_set_debug_level (PSEUDO_TCP_DEBUG_VERBOSE);
84 if (flags & NICE_DEBUG_PSEUDOTCP)
85 pseudo_tcp_set_debug_level (PSEUDO_TCP_DEBUG_NORMAL);
90 void nice_debug_enable (gboolean with_stun)
92 debug_enabled = 1;
93 if (with_stun)
94 stun_debug_enable ();
96 void nice_debug_disable (gboolean with_stun)
98 debug_enabled = 0;
99 if (with_stun)
100 stun_debug_disable ();
103 void nice_debug (const char *fmt, ...)
105 va_list ap;
106 if (debug_enabled) {
107 va_start (ap, fmt);
108 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, fmt, ap);
109 va_end (ap);