/* ARISA - Main Includes File */
/* Copyright (C) 2003, 2004 Carl Ritson */

#define _ARISA_ARISA_H

/*********************
 * Core Includes
 *********************/

#define _GNU_SOURCE
#define _REENTRANT
#define _THREAD_SAFE

#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <time.h>

#include <sys/time.h> // for struct timeval
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

#include <assert.h>

#ifdef VERSION
#undef VERSION
#endif /* VERSION */

#include "../config.h"

#if defined(HAVE_STDINT_H)
#include <stdint.h>
#elif defined(HAVE_INTTYPES_H)
#include <inttypes.h>
#endif

/*********************
 * ARISA Headers
 *********************/

#define AVGSPEED 16
#define TIME_MAX 2147483647

#define ARISA_VERSION PACKAGE " " VERSION

/* Sun kindly define a queue_t already, but not the type we want. */
#ifdef HAVE_SUNOS
#define queue_t aqueue_t
#endif /* HAVE_SUNOS */

#include "threading.h"
#include "aresolv.h"
#include "typedefs.h"
#include "flags.h"
#include "nickhash.h"
#include "pqueue.h"
#include "dq.h"
#include "pack-cache.h"
#include "structs.h"
#include "globals.h"
#include "util.h"
#include "functions.h"
#include "validity-cache.h"
#include "value.h"
#include "settings.h"
#include "fixes.h"
#include "colours.h"

/*********************
 * ARISA Macros
 *********************/

/* Logging */
/* Log Levels */
#define L_ERR		"!!"		/* Error */
#define L_INF		"**"		/* Info */
#define L_ADM		"++"		/* Admin */
#define L_XDC		"##"		/* XDCC */
#define	L_INT		"^^"		/* Interface */
#define	L_UKN		"??"		/* Unknown */
#define L_IRC		"~~"		/* IRC */
/* Log Macros */
#define LOG_TITLE(...)		log_set_title(__VA_ARGS__)
#define LOG(fmt,...) \
		arisa_log(L_UKN " " fmt,##__VA_ARGS__)
#define LOGP(l,fmt,...) \
		arisa_log(l " " fmt,##__VA_ARGS__)
#define LOGT(fmt,...) \
		arisa_log(L_UKN " %s, " fmt,log_title(),##__VA_ARGS__)
#define LOGTP(l,fmt,...) \
		arisa_log(l " %s, " fmt,log_title(),##__VA_ARGS__)

/* Misc */
#define IS_PURGE_TIME(d,n)	((d) != 0 && ((d)+300) < (n))

/* Debug */
#ifdef DEBUG_MSGS
#define	D(fmt,...) \
	LOG("DEBUG(%s:%d[%s]) " fmt,__FILE__,__LINE__,__func__, ##__VA_ARGS__)
#else
#define D(...) do { } while(0)
#endif
	
#ifdef DEBUG_ERRORS
static inline void _E(const char *f, const int l, const int err) {
	char errbuf[96];
	LOG("%s:%d Error: %s",f,l,lstrerror_r((err),errbuf,sizeof(errbuf)));
}
#define E(x) _E(__FILE__,__LINE__,(x))
#else
#define E(x) do { } while(0)
#endif
