#ifndef _SSL_DEBUG_H_
#define _SSL_DEBUG_H_
#include "sslBuildFlags.h"
#if SSL_DEBUG || ERROR_LOG_ENABLE
#define LOG_VIA_PRINTF 1
#include <stdio.h>
#include <stdlib.h>
#if !LOG_VIA_PRINTF
#error Hey, figure out a debug mechanism
#include <string.h>
#include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacTypes.h>
#include <TextUtils.h>
#ifdef __cplusplus
extern "C" {
#endif
extern void dblog0(char *str);
extern void dblog1(char *str, void * arg1);
extern void dblog2(char *str, void * arg1, void * arg2);
extern void dblog3(char *str, void * arg1, void * arg2, void * arg3);
extern void dblog4(char *str, void * arg1, void * arg2, void * arg3, void * arg4);
#ifdef __cplusplus
}
#endif
#else
#define dblog0(str) printf(str)
#define dblog1(str, arg1) printf(str, arg1)
#define dblog2(str, arg1, arg2) printf(str, arg1, arg2)
#define dblog3(str, arg1, arg2, arg3) printf(str, arg1, arg2, arg3)
#define dblog4(str, arg1, arg2, arg3, arg4) printf(str, arg1, arg2, arg3, arg4)
#endif
#else
#define dblog0(str)
#define dblog1(str, arg1)
#define dblog2(str, arg1, arg2)
#define dblog3(str, arg1, arg2, arg3)
#define dblog4(str, arg1, arg2, arg3, arg4)
#endif
#if SSL_DEBUG
#define dprintf0(str) dblog0(str)
#define dprintf1(str, arg1) dblog1(str, arg1)
#define dprintf2(str, arg1, arg2) dblog2(str, arg1, arg2)
#define dprintf3(str, arg1, arg2, arg3) dblog3(str, arg1, arg2, arg3)
#define dprintf4(str, arg1, arg2, arg3, arg4) dblog4(str, arg1, arg2, arg3, arg4)
#ifdef __cplusplus
extern "C" {
#endif
static inline volatile void sslPanic(const char *str)
{
printf(str);
exit(1);
}
#ifdef __cplusplus
}
#endif
#define CASSERT(expression) \
((expression) ? (void)0 : \
(dprintf1 ("Assertion failed: " #expression \
", file " __FILE__ ", line %d.\n", __LINE__), \
sslPanic("Assertion Failure")))
#else
#define dprintf0(str)
#define dprintf1(str, arg1)
#define dprintf2(str, arg1, arg2)
#define dprintf3(str, arg1, arg2, arg3)
#define dprintf4(str, arg1, arg2, arg3, arg4)
#define CASSERT(expression)
#define sslPanic(s)
#endif
#if ERROR_LOG_ENABLE
#define errorLog0(str) dblog0(str);
#define errorLog1(str, arg1) dblog1(str, arg1)
#define errorLog2(str, arg1, arg2) dblog2(str, arg1, arg2)
#define errorLog3(str, arg1, arg2, arg3) dblog3(str, arg1, arg2, arg3)
#define errorLog4(str, arg1, arg2, arg3, arg4) dblog4(str, arg1, arg2, arg3, arg4)
#else
#define errorLog0(str)
#define errorLog1(str, arg1)
#define errorLog2(str, arg1, arg2)
#define errorLog3(str, arg1, arg2, arg3)
#define errorLog4(str, arg1, arg2, arg3, arg4)
#endif
#define ERR(x) (x)
#define DUMP_BUFFER_NAME(name, buf)
#define DUMP_DATA_NAME(name, p, len)
#define ASSERTMSG(m) sslPanic(m)
#define DEBUGVAL1(str, arg) errorLog1(str, arg)
#ifndef _SSLCTX_H_
#include "sslctx.h"
#endif
#if SSL_DEBUG
#define LOG_HDSK_STATE 0
#define LOG_HDSK_MSG 0
#define LOG_NEGOTIATE 0
#define LOG_RX_PROTOCOL 0
#define LOG_RESUM_SESSION 0
#else
#define LOG_HDSK_STATE 0
#define LOG_HDSK_MSG 0
#define LOG_NEGOTIATE 0
#define LOG_RX_PROTOCOL 0
#define LOG_RESUM_SESSION 0
#endif
#if LOG_HDSK_STATE
extern void SSLChangeHdskState(SSLContext *ctx, SSLHandshakeState newState);
#else
#define SSLChangeHdskState(ctx, newState) { ctx->state=newState; }
#endif
#if LOG_HDSK_MSG
extern void SSLLogHdskMsg(SSLHandshakeType msg, char sent);
extern char *hdskStateToStr(SSLHandshakeState state);
#else
#define SSLLogHdskMsg(msg, sent)
#endif
#if LOG_RESUM_SESSION
#define SSLLogResumSess(m) printf(m)
#else
#define SSLLogResumSess(m)
#endif
#if SSL_DEBUG
extern void writeBufBlob(const SSLBuffer *blob,
const char *fileName);
#endif
#endif