cf/largefile.m4: Fix build with autoconf-2.72
[heimdal.git] / lib / krb5 / log.c
blob306431a5ca7ec219211bb4eb480fe11494b20805
1 /*
2 * Copyright (c) 1997-2006 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
36 #include "krb5_locl.h"
37 #include <assert.h>
38 #include <vis.h>
40 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
41 krb5_initlog(krb5_context context,
42 const char *program,
43 krb5_log_facility **fac)
45 return heim_initlog(context->hcontext, program, fac);
48 struct krb5_addlog_func_wrapper {
49 krb5_context context;
50 krb5_log_log_func_t log_func;
51 krb5_log_close_func_t close_func;
52 void *data;
55 static void HEIM_CALLCONV
56 krb5_addlog_func_wrapper_log(heim_context hcontext,
57 const char *prefix,
58 const char *msg,
59 void *data)
61 struct krb5_addlog_func_wrapper *w = data;
63 w->log_func(w->context,
64 prefix,
65 msg,
66 w->data);
69 static void HEIM_CALLCONV
70 krb5_addlog_func_wrapper_close(void *data)
72 struct krb5_addlog_func_wrapper *w = data;
74 w->close_func(w->data);
75 free(w);
78 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
79 krb5_addlog_func(krb5_context context,
80 krb5_log_facility *fac,
81 int min,
82 int max,
83 krb5_log_log_func_t log_func,
84 krb5_log_close_func_t close_func,
85 void *data)
87 struct krb5_addlog_func_wrapper *w = NULL;
89 w = calloc(1, sizeof(*w));
90 if (w == NULL)
91 return krb5_enomem(context);
93 w->context = context;
94 w->log_func = log_func;
95 w->close_func = close_func;
96 w->data = data;
98 return heim_addlog_func(context->hcontext, fac, min, max,
99 krb5_addlog_func_wrapper_log,
100 krb5_addlog_func_wrapper_close,
104 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
105 krb5_addlog_dest(krb5_context context, krb5_log_facility *f, const char *orig)
107 return heim_addlog_dest(context->hcontext, f, orig);
111 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
112 krb5_openlog(krb5_context context,
113 const char *program,
114 krb5_log_facility **fac)
116 krb5_error_code ret;
117 char **p;
119 p = krb5_config_get_strings(context, NULL, "logging", program, NULL);
120 if (p == NULL)
121 p = krb5_config_get_strings(context, NULL, "logging", "default", NULL);
122 ret = heim_openlog(context->hcontext, program, (const char **)p, fac);
123 krb5_config_free_strings(p);
124 return ret;
127 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
128 krb5_closelog(krb5_context context,
129 krb5_log_facility *fac)
131 heim_closelog(context->hcontext, fac);
132 return 0;
135 #undef __attribute__
136 #define __attribute__(X)
138 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
139 krb5_vlog_msg(krb5_context context,
140 krb5_log_facility *fac,
141 char **reply,
142 int level,
143 const char *fmt,
144 va_list ap)
145 __attribute__ ((__format__ (__printf__, 5, 0)))
147 return heim_vlog_msg(context->hcontext, fac, reply, level, fmt, ap);
150 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
151 krb5_vlog(krb5_context context,
152 krb5_log_facility *fac,
153 int level,
154 const char *fmt,
155 va_list ap)
156 __attribute__ ((__format__ (__printf__, 4, 0)))
158 return heim_vlog_msg(context->hcontext, fac, NULL, level, fmt, ap);
161 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
162 krb5_log_msg(krb5_context context,
163 krb5_log_facility *fac,
164 int level,
165 char **reply,
166 const char *fmt,
167 ...)
168 __attribute__ ((__format__ (__printf__, 5, 6)))
170 va_list ap;
171 krb5_error_code ret;
173 va_start(ap, fmt);
174 ret = heim_vlog_msg(context->hcontext, fac, reply, level, fmt, ap);
175 va_end(ap);
176 return ret;
180 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
181 krb5_log(krb5_context context,
182 krb5_log_facility *fac,
183 int level,
184 const char *fmt,
185 ...)
186 __attribute__ ((__format__ (__printf__, 4, 5)))
188 va_list ap;
189 krb5_error_code ret;
191 va_start(ap, fmt);
192 ret = heim_vlog(context->hcontext, fac, level, fmt, ap);
193 va_end(ap);
194 return ret;
197 void KRB5_LIB_FUNCTION
198 _krb5_debug(krb5_context context,
199 int level,
200 const char *fmt,
201 ...)
202 __attribute__ ((__format__ (__printf__, 3, 4)))
204 va_list ap;
206 va_start(ap, fmt);
207 if (context && context->hcontext)
208 heim_vdebug(context->hcontext, level, fmt, ap);
209 va_end(ap);
212 void KRB5_LIB_FUNCTION
213 krb5_debug(krb5_context context,
214 int level,
215 const char *fmt,
216 ...)
217 __attribute__ ((__format__ (__printf__, 3, 4)))
219 va_list ap;
221 va_start(ap, fmt);
222 if (context && context->hcontext)
223 heim_vdebug(context->hcontext, level, fmt, ap);
224 va_end(ap);
227 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
228 _krb5_have_debug(krb5_context context, int level)
230 if (context == NULL || context->hcontext == NULL)
231 return 0;
232 return heim_have_debug(context->hcontext, level);
235 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
236 krb5_have_debug(krb5_context context, int level)
238 return _krb5_have_debug(context, level);
241 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
242 krb5_set_debug_dest(krb5_context context, const char *program,
243 const char *log_spec)
245 return heim_add_debug_dest(context->hcontext, program, log_spec);
248 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
249 krb5_set_log_dest(krb5_context context, krb5_log_facility *fac)
251 return heim_set_log_dest(context->hcontext, fac);