1/*
2 * Copyright (C) 2006 Tresys Technology, LLC
3 *
4 *  This library is free software; you can redistribute it and/or
5 *  modify it under the terms of the GNU Lesser General Public
6 *  License as published by the Free Software Foundation; either
7 *  version 2.1 of the License, or (at your option) any later version.
8 *
9 *  This library is distributed in the hope that it will be useful,
10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 *  Lesser General Public License for more details.
13 *
14 *  You should have received a copy of the GNU Lesser General Public
15 *  License along with this library; if not, write to the Free Software
16 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18
19#ifndef _SEPOL_INTERNAL_DEBUG_H_
20#define _SEPOL_INTERNAL_DEBUG_H_
21
22#include <stdio.h>
23#include <sepol/debug.h>
24#include "dso.h"
25#include "handle.h"
26
27#define STATUS_SUCCESS 0
28#define STATUS_ERR -1
29#define STATUS_NODATA 1
30
31/* FIXME: this needs to become a real function. Declaring variables
32 * in a macro is _evil_ as it can shadow other variables in local scope.
33 * The variable h has been renamed to _sepol_h to reduce this chance, but
34 * it is still wrong.
35 */
36#define msg_write(handle_arg, level_arg,			   \
37		  channel_arg, func_arg, ...) do {		   \
38		sepol_handle_t *_sepol_h = (handle_arg) ?: &sepol_compat_handle; \
39		if (_sepol_h->msg_callback) {			   \
40			_sepol_h->msg_fname = func_arg;		   \
41			_sepol_h->msg_channel = channel_arg;	   \
42			_sepol_h->msg_level = level_arg;	   \
43								   \
44			_sepol_h->msg_callback(			   \
45				_sepol_h->msg_callback_arg,	   \
46				_sepol_h, __VA_ARGS__);		   \
47		}                                                  \
48	} while(0)
49
50#define ERR(handle, ...) \
51	msg_write(handle, SEPOL_MSG_ERR, "libsepol", \
52	__FUNCTION__, __VA_ARGS__)
53
54#define INFO(handle, ...) \
55	msg_write(handle, SEPOL_MSG_INFO, "libsepol", \
56	__FUNCTION__, __VA_ARGS__)
57
58#define WARN(handle, ...) \
59	msg_write(handle, SEPOL_MSG_WARN, "libsepol", \
60	__FUNCTION__, __VA_ARGS__)
61
62#ifdef __GNUC__
63__attribute__ ((format(printf, 3, 4)))
64#endif
65extern void hidden sepol_msg_default_handler(void *varg,
66					     sepol_handle_t * msg,
67					     const char *fmt, ...);
68
69extern struct sepol_handle sepol_compat_handle;
70
71hidden_proto(sepol_msg_get_channel)
72    hidden_proto(sepol_msg_get_fname)
73    hidden_proto(sepol_msg_get_level)
74#endif
75