OBS: update support for CentOS & Scientific Linux 7
[siplcs.git] / src / purple / purple-debug.c
blob381fe756ce934fee03834ecb3745d1a1846b3f0d
1 /**
2 * @file purple-debug.c
4 * pidgin-sipe
6 * Copyright (C) 2010-2017 SIPE Project <http://sipe.sourceforge.net/>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <stdarg.h>
25 #include "glib.h"
26 #include "debug.h"
27 #include "version.h"
29 #include "sipe-backend.h"
31 #ifdef ADIUM
33 * libpurple uses g_print() and PurpleDebugUiOps->debug() when
34 * purple_debug_is_enabled() returns TRUE. Both are redirected
35 * by Adium to AILog(). To avoid duplicated log lines Adium
36 * therefore never calls purple_debug_set_enabled(TRUE).
38 gboolean AIDebugLoggingIsEnabled(void);
39 #define SIPE_PURPLE_DEBUG_IS_ENABLED AIDebugLoggingIsEnabled()
40 #define SIPE_PURPLE_DEBUG_IS_UNSAFE AIDebugLoggingIsEnabled()
41 #else
43 * The same problem happens when a client uses PurpleDebugUiOps->debug()
44 * to redirect it to stderr, e.g. bitlbee. Such a client will not call
45 * purple_debug_set_enabled(TRUE). Check also the other flags that were
46 * introduced in the 2.6.x API.
48 #define SIPE_PURPLE_DEBUG_IS_ENABLED (purple_debug_is_enabled() || \
49 purple_debug_is_verbose() || \
50 purple_debug_is_unsafe())
51 #define SIPE_PURPLE_DEBUG_IS_UNSAFE purple_debug_is_unsafe()
52 #endif
54 void sipe_backend_debug_literal(sipe_debug_level level,
55 const gchar *msg)
57 if ((level < SIPE_DEBUG_LEVEL_LOWEST) || SIPE_PURPLE_DEBUG_IS_ENABLED) {
59 /* purple_debug doesn't have a vprintf-like API call :-( */
60 switch (level) {
61 case SIPE_LOG_LEVEL_INFO:
62 case SIPE_DEBUG_LEVEL_INFO:
63 purple_debug_info("sipe", "%s\n", msg);
64 break;
65 case SIPE_LOG_LEVEL_WARNING:
66 case SIPE_DEBUG_LEVEL_WARNING:
67 purple_debug_warning("sipe", "%s\n", msg);
68 break;
69 case SIPE_LOG_LEVEL_ERROR:
70 case SIPE_DEBUG_LEVEL_ERROR:
71 purple_debug_error("sipe", "%s\n", msg);
72 break;
77 void sipe_backend_debug(sipe_debug_level level,
78 const gchar *format,
79 ...)
81 va_list ap;
83 va_start(ap, format);
85 if ((level < SIPE_DEBUG_LEVEL_LOWEST) || SIPE_PURPLE_DEBUG_IS_ENABLED) {
87 /* purple_debug doesn't have a vprintf-like API call :-( */
88 gchar *msg = g_strdup_vprintf(format, ap);
89 sipe_backend_debug_literal(level, msg);
90 g_free(msg);
93 va_end(ap);
96 gboolean sipe_backend_debug_enabled(void)
98 return SIPE_PURPLE_DEBUG_IS_UNSAFE;
102 Local Variables:
103 mode: c
104 c-file-style: "bsd"
105 indent-tabs-mode: t
106 tab-width: 8
107 End: