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