#ifndef _IRRD_OPS_H
#define _IRRD_OPS_H

/* Do not change the ATTR_ID values */
enum ATTR_ID {
  X_ATTR       = 0,
  NOTIFY_ATTR  = 01, 
  MNT_BY_ATTR  = 02, 
  UPD_TO_ATTR  = 04, 
  MNT_NFY_ATTR = 010,
  MNTNER_ATTR  = 020, 
  AUTH_ATTR    = 040
};

#define is_upd_to(p) (!strncmp (p, "*dt:", 4) || !strncmp (p, "upd-to:", 7))
#define is_mnt_nfy(p) (!strncmp (p, "*mn:", 4) || !strncmp (p, "mnt-nfy:", 8))
#define is_mnt_by(p) (!strncmp (p, "*mb:", 4) || !strncmp (p, "mnt-by:", 7))
#define is_notify(p) (!strncmp (p, "*ny:", 4) || !strncmp (p, "notify:", 7))
#define is_mntner(p) (!strncmp (p, "*mt:", 4) || !strncmp (p, "mntner:", 7))
#define is_auth(p) (!strncmp (p, "*at:", 4) || !strncmp (p, "auth:", 5))
#define is_changed(p) (!strncmp (p, "*ch:", 4) || !strncmp (p, "changed:", 8))
#define is_source(p) (!strncmp (p, "*so:", 4) || !strncmp (p, "source:", 7))

/* Transaction types */
#define ADD_OP     "ADD"
#define DEL_OP     "DEL"
#define REPLACE_OP "REPLACE"
#define NOOP_OP    "NOOP"

/* maximum line size on reads */
/* #define MAXLINE 1024*/

/* Used by read_socket_obj (), SHORT_OBJECT
 * will get auth, upd-to, mnt-nfy, and notify
 * fields only.
 */
#define FULL_OBJECT  0
#define SHORT_OBJECT 1

#define newline_remove(p) if (*((p) + strlen ((p)) - 1) == '\n') \
                           *((p) + strlen ((p)) - 1) = '\0'

#define SNIP_MSG "[snip... Object abbreviated for readability]\n"

/* function prototypes */
char *irrd_transaction (trace_t *tr, char *warn_tag, int *socketfd, FILE *fin, 
			char *op, char *source, int num_trans, int *open_conn,
			char *IRRd_HOST, int IRRd_PORT);
FILE *IRRd_fetch_obj (trace_t *tr, char *fname, int *num_trans, int *sockfd,
		      int obj_size, char *obj_type, char *obj_key, char *source,
		      int max_obj_line_size, char *IRRd_HOST, int IRRd_PORT);
int close_connection (int);
char *end_irrd_session (trace_t *tr, int);
int read_socket_line (trace_t *tr, int sockfd, char buf[], int bufsize);

#endif /* _IRRD_OPS_H */
