1/*
2 * KerberosDebug.h
3 *
4 * $Header$
5 *
6 * Copyright 2004 Massachusetts Institute of Technology.
7 * All Rights Reserved.
8 *
9 * Export of this software from the United States of America may
10 * require a specific license from the United States Government.
11 * It is the responsibility of any person or organization contemplating
12 * export to obtain such a license before exporting.
13 *
14 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
15 * distribute this software and its documentation for any purpose and
16 * without fee is hereby granted, provided that the above copyright
17 * notice appear in all copies and that both that copyright notice and
18 * this permission notice appear in supporting documentation, and that
19 * the name of M.I.T. not be used in advertising or publicity pertaining
20 * to distribution of the software without specific, written prior
21 * permission.  Furthermore if you modify this software you must label
22 * your software as modified software and not distribute it in such a
23 * fashion that it might be confused with the original M.I.T. software.
24 * M.I.T. makes no representations about the suitability of
25 * this software for any purpose.  It is provided "as is" without express
26 * or implied warranty.
27 */
28
29#ifndef KERBEROSDEBUG_H
30#define KERBEROSDEBUG_H
31
32#include <stdarg.h>
33#include <sys/types.h>
34#include <mach/mach.h>
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40/*
41 * These symbols will be exported for use by Kerberos tools.
42 * Give them names that won't collide with other applications
43 * linking against the Kerberos framework.
44 */
45
46#define ddebuglevel       __KerberosDebugLogLevel
47#define dprintf           __KerberosDebugPrint
48#define dvprintf          __KerberosDebugVAPrint
49#define dprintmem         __KerberosDebugPrintMemory
50#define dprintsession     __KerberosDebugPrintSession
51
52int ddebuglevel (void);
53void dprintf (const char *in_format, ...) __attribute__ ((format (printf, 1, 2)));
54void dvprintf (const char *in_format, va_list in_args);
55void dprintmem (const void *in_data, size_t in_length);
56void dprintsession (void);
57
58#define SetSignalAction_(inAction)
59#ifdef __PowerPlant__
60#define GetSignalAction_() debugAction_Nothing
61#else
62#define GetSignalAction_() (0)
63#endif
64
65#ifdef __PowerPlant__
66#	undef SignalPStr_
67#	undef SignalCStr_
68#	undef SignalIf_
69#	undef SignalIfNot_
70#endif /* __PowerPlant */
71
72#define SignalPStr_(pstr)                                            \
73    do {                                                             \
74        dprintf ("%.*s in %s() (%s:%d)",                             \
75                 (pstr) [0], (pstr) + 1,                             \
76                 __FUNCTION__, __FILE__, __LINE__);                  \
77    } while (0)
78
79#define SignalCStr_(cstr)                                            \
80    do {                                                             \
81        dprintf ("%s in %s() (%s:%d)",                               \
82                 cstr, __FUNCTION__, __FILE__, __LINE__);            \
83    } while (0)
84
85#define SignalIf_(test)                                              \
86    do {                                                             \
87        if (test) SignalCStr_("Assertion " #test " failed");         \
88    } while (0)
89
90#define SignalIfNot_(test) SignalIf_(!(test))
91
92#define Assert_(test)      SignalIfNot_(test)
93
94enum { errUncaughtException = 666 };
95
96#define SafeTry_               try
97#define SafeCatch_             catch (...)
98#define SafeCatchOSErr_(error) catch (...) { SignalCStr_ ("Uncaught exception"); error = errUncaughtException; }
99
100#define DebugThrow_(e)                                               \
101    do {                                                             \
102        dprintf ("Exception thrown from %s() (%s:%d)",               \
103                 __FUNCTION__, __FILE__, __LINE__);                  \
104        throw (e);                                                   \
105    } while (0)
106
107#ifdef __cplusplus
108}
109#endif
110
111#endif /* KERBEROSDEBUG_H */
112