/*    $Id: bcnu.h,v 1.6 1999/09/28 12:13:48 jap Exp $

 *    Copyright (c) 1998 John Phillips
 *
 *    You may distribute under the terms of the Artistic License
 *
 */

#ifndef __bcnu_h__
#define __bcnu_h__

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdio.h>
#include <netdb.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <setjmp.h>
#include <fcntl.h>
#include <time.h>
#include <errno.h>

#ifndef TRUE
#define TRUE (1==1)
#endif
#ifndef FALSE
#define FALSE (1==0)
#endif

#ifdef VERSION
#define BCNU_VER VERSION
#else
#define BCNU_VER "1.0"		/* Major version no       */
#endif

#ifdef LISTEN
#define BCNU_LISTEN LISTEN
#else
#define BCNU_LISTEN 5		/* listen queue length       */
#endif

#define BCNU_PORT 6666		/* Default port           */
#define BCNU_MESS 1024		/* Default Buffer */
#define BCNU_MAX_AGENTS 20	/* Max Number of agents   */
#define BCNU_INTERVAL 60	/* Time between updates   seconds */
#define BCNU_GAP 1		/* Gap between staring agents */
#define BCNU_HEARTBEAT 60	/* Log every 60*BCNU_INTERVAL     */
#define BCNU_ALERT 5		/* Create alert file if > this */
#define BCNU_NOLOG -1		/*  */
#define BCNU_PROTO 1		/* protocol version */

#define BCNUHOME "/usr/local/bcnu"

/* Message strings              */

#define BCNU_MSG_AGT_RELOAD	"reload"
#define BCNU_MSG_AGT_SEND	"send"
#define BCNU_MSG_AGT_SHOW	"show"
#define BCNU_MSG_AGT_GET	"get"
#define BCNU_MSG_AGT_NET	"net"
#define BCNU_MSG_AGT_HTTP	"http"

#define BCNU_MSG_ERROR_LOG	"error_log"
#define BCNU_MSG_ERROR_FILE	"error_file"

#define BCNU_MSG_STATUS_LOG 	"status_log"
#define BCNU_MSG_STATUS_FILE	"status_file"

#define BCNU_MSG_PING		"ping"
#define BCNU_MSG_WIN32ALERT	"win32alert"

/* Host types */

#define HOST_ANY 	0
#define HOST_UNIX 	1
#define HOST_NETWARE 	2
#define HOST_NT 	3
#define HOST_95 	4
#define HOST_ROUTER 	20
#define HOST_PRINTER 	30

/* Message structures           */

struct bcnu_msg_def
  {
    int proto_version;		/* version of the bcnu protocol */
    char msg_type[20];		/* Message as above             */
    int severity;		/* severity of message          */
    char host_for[80];		/* Hostname whos data it is     */
    int host_type;		/* type of host e.g. router     */
    char host_from[80];		/* Hostname from sending host   */
    char agent_from[80];	/* Generated by agent           */
    long time_logged;		/* Original time                */
    char log_info[80];		/* Info                         */
    char bcnud_host_from[80];	/* My view of host it is coming from */
    long bcnud_time_logged;	/* Time I logged it             */
    int bcnud_file;		/* 0 if no file 1 if file       */
    char bcnud_filename[80];	/* Filename                     */
  };


/* Agent Structures             */

struct bcnu_agent_def
  {
    char agent_type[80];	/* Agent directory                 */
    char agent_name[20];	/* agent name                   */
    char agent_param[256];	/* Agent description            */
    int status;			/* on or off */
    int hr_on;
    int hr_off;
    int min_on;
    int min_off;
    int minutes_run;		/* how often is it run i.e. every 15 mins */
    int next_run;		/* countdown to next run in minutes */
    int minutes_log;		/* how often to log normal */
    int next_log;		/* how often to log normal */
  };


/* Global definitions   */

int debug;
int reqcnt;
int verbose;

int hour, mins;

char *bcnuptr;
char *bcnuaname;
char bcnuhome[80];
char bcnuagent[80];
char bcnulog[80];
char bcnuetc[80];
char bcnucfg[80];
char bcnuerr[80];
char bcnumsg[80];
char bcnuflags[80];

int bcnu_agents_loaded;		/* No of agents loaded  */
int bcnu_agents_enabled;	/* no of agents enabled */

char workbuf[BCNU_MESS];	/* General work buffer  */
char myhostname[80];		/* holds this host's name */

char portmsg[BCNU_MESS];	/* special message */

int pipefd[2], bcnu_pipein, bcnu_pipeout;	/* Pipe fd's for commands */

/* Alarm handling stuff */

sigjmp_buf env;
int savemask;

void signal_handler ();
void ag_handler ();
void chld_handler ();

#endif /* __bcnu_h__ */
