#ifndef bool
# define bool   int
# define TRUE   1
# define FALSE  0
#endif /* ! bool */

#define NS_TYPE_ELT                     0x40 /* EDNS0 extended label type */
#define DNS_LABELTYPE_BITSTRING         0x41
#define CB_UNKNOWN			-1
#define CB_PASS				0
#define CB_REJECT			1
#define CB_TEMPFAIL			2
#define CB_SKIP				3
#define CB_GRACEFUL			4
#define MAXEMAIL			324
#define MAXIDENT			274
#define MAXLOGLINE			1023
#define MAXHOSTNAME			256
#define MAXPATH				2048

#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <arpa/inet.h>
#include <resolv.h>
#include <netdb.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sysexits.h>
#include <unistd.h>
#include <syslog.h>
#include <stdarg.h>
#include <libmilter/mfapi.h>
#include <time.h>
#include <pthread.h>

#ifdef WITH_SPF
#include <spf2/spf.h>
struct SPFHeap {
    SPF_server_t **SPFServerArr;
    pthread_mutex_t **SPFMutexArr;
};
#endif

struct mlfiPriv {
    char *mcfi_connectfrom;
    char *mcfi_helofrom;
    int	skipDirect;
    uint32_t relayIP;
    char relayPresIP[INET_ADDRSTRLEN];
    char envFrom[MAXEMAIL];
    int MXesThatReject;
    int MXesThatAccept;
    int MXesOutOfOrder;
    int MXesThatTempfail;
    int MXesNum;
    int reverseRes;
    int fakeRes;
    int whitelisted;
    int gracefulDNS;
    int killMeOnData;
    int prisoner;
    int cached;
    int cacheLockOwner;
    int pitLockOwner;
    char resolvedRelayIP[MAXHOSTNAME];
#ifdef WITH_PGSQL
    int SQLlogged;
#endif
#ifdef WITH_SPF
    int SPFResult;
#endif    
};

#ifdef WITH_PGSQL
#include "libpq-fe.h"
#endif

#ifdef WITH_DMALLOC
#include <dmalloc.h>
#endif

struct netList {
    struct in_addr *whiteNet;
    struct in_addr *whiteMask;
    int netCount;
};
struct mcCache {
    char relayPresIP[INET_ADDRSTRLEN];
    char *envFrom;
    time_t expiresAt;
    struct mcCache *nextNode;
    struct mcCache *prevNode;
    int action;
    int MXesThatReject;
    int MXesThatAccept;
    int MXesOutOfOrder;
    int MXesThatTempfail;
    int MXesNum;
    int reverseRes;
    int fakeRes;
    int whitelisted;
    int gracefulDNS;
    char resolvedRelayIP[MAXHOSTNAME];
#ifdef WITH_SPF
    SPF_result_t SPFResult;
#endif
};
struct mcCache mcCache;
struct mcCache *mcCacheStart;
pthread_mutex_t *mcCacheBusy;

struct mcCallbackPit {
    char relayPresIP[INET_ADDRSTRLEN];
    struct mcCallbackPit *nextNode;
    struct mcCallbackPit *prevNode;
};
struct mcCallbackPit mcPit;
struct mcCallbackPit *mcPitStart;
pthread_mutex_t *mcPitBusy;

#ifdef WITH_PGSQL
struct connList {
    PGconn **pgConnArr;
    PGresult **pgResArr;
    pthread_mutex_t **pgMutexArr;
};
#endif
