/*
 * This file is part of some an snmp query application.
 *
 * Copyright 1990 by the Massachusetts Institute of Technology.
 *
 * For copying and distribution information, please see the file
 * <mit-copyright.h>.
 *
 * Tom Coppeto
 * MIT Network Services
 * 15 April 1990
 *
 *    $Source: /afs/net.mit.edu/tools/src/simon/RCS/simon.h,v $
 *    $Author: tom $
 *    $Locker:  $
 *    $Header: /afs/net.mit.edu/tools/src/simon/RCS/simon.h,v 1.5 91/02/21 13:55:44 tom Exp $
 *    $Log:	simon.h,v $
 * Revision 1.5  91/02/21  13:55:44  tom
 * *** empty log message ***
 * 
 * Revision 1.4  90/07/25  10:32:31  tom
 * added symbolic display type (default)
 * added new string in variable for numeric representation
 * 
 * Revision 1.3  90/07/20  21:27:45  tom
 * I'm on a roll
 * 
 * Revision 1.2  90/07/20  21:26:14  tom
 * quotes file def
 * 
 * Revision 1.1  90/07/20  21:20:00  tom
 * Initial revision
 * 
 *
 */

#include <stdio.h>
#include <ctype.h>
#include <strings.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/time.h>
#include <signal.h>
#include <arpa/snmp/snmp_hs.h>
#include <arpa/snmp/varcvt.h>

/* 
 * some constants
 */

#define TRUE        1
#define SUCCESS     0
#define FALSE       0
#define ERROR      -1
#define MAYBE       23467805
#define UNKNOWN    -23467805
#define NONE        0

#define MAX_VAR     14

#define LABEL_SIZE  32
#define HOST_SIZE   32
#define NAME_SIZE   128
#define BUF_SIZE    1024

#define VERSION_STRING "0.2"  
#define INFO_DIR       "/afs/net/tools/lib/simon/info"
#define DFLT_PAGER     "/usr/ucb/more"
#define OUTFILE        "/tmp/simon.out"
#define DFLT_VARDEFS   "/afs/net/tools/lib/simon/vardefs"
#define DFLT_AGDEFS    "/afs/net/tools/lib/simon/agdefs"

/*
 * query codes
 */

#define SENT        1
#define SEND        2
#define REPLIED     3
#define PUNT        4

/*
 * display modes
 */

#define STANDARD    1
#define TRUNCATED   2
#define UNIQUE      4
#define SYMBOLIC    8
#define LABEL       16
#define COMMA       32
#define NEWLINE     64
#define EXCLUSIVE   7

/*
 * defaults
 */

#define DFLT_TIMEOUT     10
#define DFLT_RETRY       1
#define DFLT_INTERVAL    100
#define DFLT_SESSION_ID  "public"
#define DFLT_PREFIX      "_iso_org_dod_internet"
#define DFLT_DSPMODE     TRUNCATED | LABEL | COMMA | SYMBOLIC;

/*
 * the macro
 */

#define string_equiv(a, b, c)   (strncmp((a), (b), (c) < strlen((a)) \
                                        ? strlen((a)) : (c)) == 0)


/*
 * the queriable
 */

typedef struct _VARIABLE
{
  struct _VARIABLE *next;                  /* next in list */
  char   *variable;                        /* symbolic variable */
  char   *nvariable;                       /* numeric var string */
  char   *abbrev;                          /* what one may type in */
  char   *label;                           /* what can be displayed */
  int    ncmp;                             /* # components */
  short  itype;                            /* type of instance */
  short  mquery;                           /* if we should use get-next */
  int    checked;                          /* already tried to do sym conv */
} VARIABLE;


/*
 * the queriables
 */

typedef struct _CLASS
{
  struct _CLASS *next;
  int    table;                            /* whether to make a pretty table */
  char   *name;                            /* name of class */
  struct _VARIABLE *vars;                  /* list of variables in class */
} CLASS;


/*
 * the query
 */

typedef struct _REQUEST
{
  struct  _REQUEST *next;
  int     nvars;
  getreq  msg;
  int     reqid;
  int     ncmp;
  struct  _VARIABLE *vars[MAX_VAR];
} REQUEST;


/*
 * the queried
 */

typedef struct _AGENT
{
  struct  _AGENT *next;
  char    name[NAME_SIZE];
  struct  in_addr in;
  int     status;
  int     nreplies;
  getreq  *replies;
  struct  _REQUEST *requests;
  struct  _REQUEST *cur_req;
  struct  _REQUEST *last_req;
} AGENT;


/*
 * the querieds
 */

typedef struct _CLUSTER
{
  struct _CLUSTER *next;
  struct _AGENT   *agents;
  char   *name;
} CLUSTER;



/*
 * a popular subject line
 */

typedef struct _STUFF
{
  int    timeout;
  int    retry;
  int    interval;
  char   *session_id;
  char   *prefix;
  int    dispmode;
  struct _CLASS   *class;
  struct _CLUSTER *cluster;
} STUFF;


/*
 * DO NOT DELETE THIS LINE
 */

void cmd_change_agent();
void cmd_add_agent();
void cmd_delete_agent();
void cmd_create_cluster();
void cmd_delete_cluster();
void cmd_show_clusters();
void cmd_change_timeout();
void cmd_change_retry();
void cmd_set_logfile();
void cmd_tee_output();
void cmd_cancel_tee();
void cmd_read_vardefs();
void cmd_save_vardefs();
void cmd_read_agentdefs();
void cmd_save_agentdefs();
void cmd_change_class();
void cmd_change_cluster();
void cmd_change_timeout();
void cmd_change_retry();
void cmd_change_interval();
void cmd_change_prefix();
void cmd_change_dspmode();
void cmd_change_session_id();
void cmd_print_paramaters();
void cmd_reset_parameters();
void cmd_query_variable();
void cmd_qyery_class();
void cmd_create_class();
void cmd_delete_class();
void cmd_show_classes();
void cmd_add_variable();
void cmd_change_variable();
void cmd_delete_variable();
void cmd_clear();
void null();

void list_classes();
void list_class_variables();
void list_clusters();
void list_cluster_agents();

int      agent_list_length();
CLASS    *get_default_class();
CLASS    *get_class();
CLASS    *create_class();
CLASS    *prompt_for_class();
AGENT    *add_agent();
AGENT    *delete_agent();
CLUSTER  *get_default_cluster();
CLUSTER  *create_cluster();
CLUSTER  *get_cluster();
CLUSTER  *prompt_for_cluster();
VARIABLE *get_variable();

char *var_str();
char *prompt_string();
char *copy_string();
char *truncate();
char *numeric_suffix();
char *common_prefix();
char *find_abbrev_variable();
char *format_number();
char *numtostring();
char *symtonumstr();
char *numtostr();
char *numstrtosym();
char *get_instance();


void free_class();
void free_cluster();
void free_variable();

extern CLUSTER *ClusterList;
extern CLASS   *ClassList;
extern STUFF   stuff;

extern char    *argptr[100];
extern char    cmdbuf[BUF_SIZE];
extern char    *pname;
