1/*
2 * Copyright (c) 2008 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License").  You may not use this file except in compliance with the
9 * License.  Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23#ifndef TRUE
24#define TRUE (1)
25#endif
26
27#ifndef FALSE
28#define FALSE (0)
29#endif
30
31#ifndef maximum
32#define	maximum(a, b) (((a)>(b))?(a):(b))
33#endif
34
35#ifndef minimum
36#define	minimum(a, b) (((a)<(b))?(a):(b))
37#endif
38
39#define CAST(T,x) (T)(uintptr_t)(x)
40
41#define str_to_buf(s, b) do { \
42	(b)->value = (s); (b)->length = strlen(s) + 1; \
43	} while (0)
44
45#define Fatal(fmt, ...) fatal("%s: %d: " fmt, __func__, __LINE__,## __VA_ARGS__)
46#define Debug(fmt, ...) gssd_log(ASL_LEVEL_DEBUG, "%s: %d: " fmt, __func__, __LINE__,## __VA_ARGS__)
47#define DEBUG(level, ...) do {\
48	if (get_debug_level() >= level) {\
49		Debug(__VA_ARGS__); \
50	}\
51} while (0)
52
53#define HEXDUMP(level, ...) do {\
54	if (get_debug_level() >= level) {\
55		HexDump(__VA_ARGS__); \
56	}\
57} while (0)
58
59#define Info(fmt, ...) do {\
60	if (get_debug_level() > 1) {\
61		gssd_log(ASL_LEVEL_INFO, "%s: %d: " fmt, __func__, __LINE__,## __VA_ARGS__); \
62	} else { \
63		gssd_log(ASL_LEVEL_INFO, "%s: " fmt, __func__,## __VA_ARGS__); \
64	}\
65} while (0)
66
67#define Notice(fmt, ...) do {\
68	if (get_debug_level() > 1) {\
69		gssd_log(ASL_LEVEL_NOTICE, "%s: %d: " fmt, __func__, __LINE__,## __VA_ARGS__); \
70	} else { \
71		gssd_log(ASL_LEVEL_NOTICE, fmt,## __VA_ARGS__); \
72	}\
73} while (0)
74
75#define Log(fmt, ...) do {\
76	if (get_debug_level()) {\
77		gssd_log(ASL_LEVEL_ERR, "%s: %d: " fmt, __func__, __LINE__,## __VA_ARGS__); \
78	} else { \
79		gssd_log(ASL_LEVEL_ERR, fmt,## __VA_ARGS__); \
80	}\
81} while (0)
82
83
84extern char *buf_to_str(gss_buffer_t);
85extern void gssd_enter(void *);
86extern void gssd_remove(void *);
87extern int gssd_check(void *);
88extern char *oid_name(gss_OID);
89extern char *gss_strerror(gss_OID, uint32_t, uint32_t);
90extern void __attribute__((noreturn)) fatal(const char *, ...);
91extern void gssd_log(int, const char *, ...);
92extern void HexDump(const char *, size_t);
93extern int traced(void);
94int in_foreground(int);
95extern void set_debug_level(int);
96extern void set_debug_level_init(void (*)(int));
97extern int get_debug_level(void);
98