/* *************************************************************
   RWhois Software

   Copyright (c) 1994 Scott Williamson and Mark Kosters
   Copyright (c) 1996-2000 Network Solutions, Inc.

   See the file LICENSE for conditions of use and distribution.
**************************************************************** */

#ifndef _RWHOIS_INTERNAL_H_
#define _RWHOIS_INTERNAL_H_

#include "common.h"

#define SERVICE         "rwhois"
#define PROTOCOL        "tcp"
#define NORMPORT        4321
#define MAXSERVERS      90
#define MAXBUFFER       1024
#define MAXINFOTEXT     5 * MAXBUFFER
#define MAXBUFF         256
#define MAXLINE         81
#define CONTROL(char)   (char ^ 0100)
#define ABORT_CHAR      CONTROL('G')
#define STATUS_CHAR     CONTROL('E')
#define CRLF            "\015\012"


#ifndef TRUE
#define TRUE            1
#endif
#ifndef FALSE
#define FALSE           0
#endif


#define GOOD            0
#define BAD             1

#define ON              1
#define OFF             0

#define NullCH          '\0'   /* the NULL Character */
#define TIMEOUT         -1

#define DEF_WAITTIME    5

#define CAP_LOAD        0x1
#define CAP_LIMIT       0x2
#define CAP_SCHEMA      0x4
#define CAP_XFER        0x8
#define CAP_QUIT        0x10
#define CAP_STATUS      0x20
#define CAP_CACHE       0x40
#define CAP_HOLDCONNECT 0x80
#define CAP_FORWARD     0x100
#define CAP_SOA         0x200
#define CAP_NOTIFY      0x400
#define CAP_REGISTER    0x800
#define CAP_OBJECT      0x1000
#define CAP_DEFINE      0x2000
#define CAP_PRIVATE     0x4000
#define CAP_X           0x8000
#define CAP_DIRECTIVE   0x10000
#define CAP_DISPLAY     0x20000
#define CAP_LANGUAGE    0x40000

/* this is for the state machine that reads a record after we've sent a    */
/* directive. These are kind of 1.0 and 1.5 oriented                       */
typedef enum {
  RW_STATE_ERROR,
  RW_STATE_INFO,
  RW_STATE_DECODE_LINE,
  RW_STATE_READ_LINE,
  RW_STATE_OK,
  RW_STATE_RWHOIS,
  RW_STATE_REFERRAL,
  RW_STATE_DIRECTIVE_SEP,
  RW_STATE_IN_DIRECTIVE,
  RW_STATE_SCHEMA_SEP,
  RW_STATE_IN_SCHEMA,
  RW_STATE_IN_DEFINE,
  RW_STATE_DEFINE_SEP,
  RW_STATE_IN_DISPLAY,
  RW_STATE_DISPLAY_SEP,
  RW_STATE_IN_OBJECT,
  RW_STATE_OBJECT_SEP,
  RW_STATE_IN_SOA,
  RW_STATE_SOA_SEP,
  RW_STATE_IN_STATUS,
  RW_STATE_STATUS_SEP,
  RW_STATE_IN_XFER,
  RW_STATE_XFER_SEP,
  RW_STATE_IN_CLASS,
  RW_STATE_CLASS_SEP,
  RW_STATE_IN_REGISTER,
  RW_STATE_IN_RECORD,
  RW_STATE_END_OF_RECORD,
  RW_STATE_FINISHED
} fetch_state_enum;


/* given a record, find the value of a given attribute name */
char *find_value_for_attribute(rw_record_struct *record,
                               char *attribute_name);

/* get the server version from the banner string */
rw_server_version_enum get_version(char *str);

/* Get the server capibilities by decoding the banner */
void get_capability(char *str, rw_server_cap_struct *cap);

/* identify the response line type */
fetch_state_enum decode_line(char *buffer, rw_server_version_enum type);

#endif
