/*
 * $Id: irrauth.h,v 1.4 1999/03/24 01:59:56 gerald Exp $
 */


#ifndef _IRR_AUTH_H
#define _IRR_AUTH_H

#include <pipeline_defs.h>

#define MAXLEN 2047

/* Max transaction log file size and seperator */
#define MAX_LOG_FILE_SIZE 4096000
#define TRANS_SEPERATOR "\n---\n"

/* macro's */

#define set_op_type(x,y) free_mem (x); x = strdup (y)

/* Used in maint_check ()
 * identify operation type.
 */
#define iDEL 0
#define iADD 1
#define iREPLACE 2

#define pgpargs 	"-o"
#define PUBKEYWORD	"pubring"
#define PUBRINGNM	"pubring.pkr"
#define SECKEYWORD	"secring"
#define SECRINGNM	"secring.skr"


#include <sys/types.h>
#include <regex.h>
#include "hdr_comm.h"
#include "irrd_ops.h"

enum AUTH_CODE {
  AUTH_FAIL_C     = 01, 
  AUTH_PASS_C     = 02, 
  OTHER_FAIL_C    = 04, 
  MNT_NO_EXIST_C  = 010,
  DEL_NO_EXIST_C  = 020, 
  NOOP_C          = 040,
  NEW_MNT_ERROR_C = 0100,
  BAD_OVERRIDE_C  = 0200
};

#define CLEAR_NOTIFY (MNT_NO_EXIST_C|DEL_NO_EXIST_C|NOOP_C|OTHER_FAIL_C|AUTH_FAIL_C|NEW_MNT_ERROR_C|BAD_OVERRIDE_C)
#define CLEAR_FORWARD (MNT_NO_EXIST_C|DEL_NO_EXIST_C|NOOP_C|OTHER_FAIL_C|AUTH_PASS_C|NEW_MNT_ERROR_C|BAD_OVERRIDE_C)

extern const char blankline[];
extern const char cookie[];
extern const char cookieins[];
extern const char mailfrom[];
extern const char mailreplyto[];
extern const char mailfromnc[];
extern const char messid[];
extern const char subj[];
extern const char date[];

extern const char pgpbegin[];
extern const char pgpend[];
extern const char pgpkeyid[];
extern const char pgpmailid[];
extern const char pgpgood[];
extern const char mntby[];
extern const char origin[];
extern const char dotstar[];
extern const char tmpfntmpl[];
extern const char password[];

extern char auth[16][256];
extern char msgid[];
extern char subjid[];
extern char dateid[];



typedef struct _rxlist {
  const regex_t *re;
  char *buf;
  int flags;
  int counter;
} rxlist;


typedef struct _obj_lookup_t {
  char *key;     /* object key; for route and person both keys */
  char *type;    /* object type, eg, aut-num, mntner, ... */
  char *source;  /* DB source */
  int state;     /* 0 means deleted, 1 means add/replace */
  long fpos;     /* starting file pos */
  FILE *fd;      /* file pointer */
  struct _obj_lookup_t *next;
} obj_lookup_t;

typedef struct _lookup_info_t {
  obj_lookup_t *first;
  obj_lookup_t *last;
} lookup_info_t;

/* Function prototypes */


int pgpdecodefile (FILE *file, char *, FILE *, char *, trace_t *tr);
int addmailcookies (trace_t *tr, int, char *infn, char *outfn);
int writecookietofile (char *infn, char *outfn);
int callsyntaxchk (trace_t *tr, char *, char *, char *);
int callnotify (trace_t *tr, char *, int, int, int, char *, int, 
		char *, FILE *);
int auth_check (trace_t *tr, char *, char *, char *, int, char *);

/* trans_lists.c */
void trans_list_update (trace_t *, lookup_info_t *, trans_info_t *, FILE *, long);
void free_trans_list (trace_t *, lookup_info_t *);
obj_lookup_t *find_trans_object (trace_t *, lookup_info_t *, char *, char *, char *);

/* util.c */
int noop_check (trace_t *, FILE *, long, FILE *, long);
char *myconcat (char *, char *);
int find_token (char **, char **);
char *free_mem (char *);
char *filter_duplicates (trace_t *, char *, char *);
void write_trans_obj (trace_t *, FILE *, long, FILE *, int, int);
char *cull_attribute (trace_t *, FILE *, long, u_int);
enum ATTR_ID find_attr (trace_t *, char *, int, u_int, char **);
FILE *myfopen (trace_t *, char *, char *, char *);
void log_roll (char *, char *, int);
void unlock_file (int);
int lock_file (int *, char *filename);

#endif /* _IRR_AUTH_H */
