#define PORT	         9000
#define SERVER     "vongole.mit.edu"
#ifndef FALSE
#define FALSE           0
#endif
#ifndef TRUE
#define TRUE            1
#endif

#define NO              0
#define YES             1
#define NULL           0

#define CR      '\015'
#define LF      '\012'
#define DLM     ':'

#define BANNER_MSG  101
#define BANNER     "0:Test Server, version 1.0  .\n"
#define NAK_BANNER     "100: The Server is temporarily unavailable, please try again later.\n"

#define  TRANS_LOG	"trans.log"
#define  LOG_FILE        "log.file"
#define  MSG_FILE        "msg.file"
#define  PROV_LN_SZ	120
#define min(a, b)       ((a) < (b) ? (a) : (b))
#define do_free(var) if ((var) !=NULL) free((var))

/*++++++++  BELOW HERE SHOULD NOT NEED MODIFING +++++++++++++++++++*/

#define	CRLF		"\015\012"
#define	EOL		"\012"		/* End of Line */
#define	EOL_LEN		1
#define EOM		".\015\012"		/* End of Message */
#define EOM_LEN		3
#define EOLM		"\012.\015\012"	/* EOL + EOM */
#define EOLM_LEN	(EOL_LEN + EOM_LEN)

#define  MAX_TRANS      500   /* maximum # of trans per session */
#define  SRV_LN_SZ      256
#define  SRC_LN_SZ      256

#define  NOBODY  -1

typedef struct pending_sends TOSEND;
typedef struct pending_recvs TOREC;

struct pending_sends
{
  char *buf;  /* buffer to free when through */
  char *ptr;  /* pointer to start sending from */
  int  size;  /* how much left to send */
  int  sock;  /* socket to send to */
};

struct pending_recvs
{
  char *filename; /* the file name of the file being recvd */
  int  the_fd;    /* the file desc of the open file */
  int  sock;      /* the socket to receive from */
};

typedef struct connection	CONN;

struct connection {
	int	c_socket;
	char	*c_hostname;
	int	c_portnum;
	int	c_flags;
	char    *c_uid;
        char    *c_type;
	time_t	c_made;
	time_t	c_last;
	TOSEND  *c_ptr;
	TOREC   *c_recptr;
	int     c_output_fmt;      /* Added 8/12/92 ark */
	int     c_trans_cnt;      /* added 9/118/92 ST */
};

#define C_FULLFMT	0x1	/* Using full format output */
#define C_BUSY		0x2	/* connection is already being serviced */
#define C_TIMEOUT	0x4	/* Connection has timed out */
#define C_PROVIDER	0x8	/* Connection is a provider */


/*
 * Transaction codes.
 */

#define	T_ADDNODE	  'a'	/* add */
#define T_FIND            'b'	/* fnd, find */
#define	T_ENDPROVIDER	  'c'	/* epv, */
#define	T_DUMPWEB	  'd'	/* dmp, dump */
#define T_EXPAND          'e'	/* exp, expand */
#define	T_GETFILE	  'f'	/* fil, file, getfile  */
#define T_REORDER_BEFORE  'g'   /* reorder the child links */
#define T_SOURCE          'h'   /* test of valid source for an id */
#define T_RELOAD          'i'   /* reload the web from disk */
#define T_REORDER_AFTER   'j'   /* reorder the child links */
#define T_FINDKEY         'k'   /* find keyword */
#define	T_ADDLINK	  'l'	/* lnk, link */
#define	T_GET_SERVER_INFO 'm'   /* get info on other servers */
#define T_SRC_INFO        'n'   /* get full source info on a node */
#define	T_OUTPUTFMT	  'o'	/* fmt -- undocumented */
#define	T_TRYPROVIDER	  'p'	/* prv, provider */
#define T_QUIT            'q'   /* quit */
#define	T_REPLACENODE	  'r'	/* rpl, replace */
#define	T_SENDNODE	  's'	/* get, show? node? */
#define T_SENDFILE        't'	/* sfl, sendfile */
#define	T_RMLINK	  'u'	/* ulk, unlink */ 
#define T_VERSION         'v'   /* find current version */
#define T_TRAVERSE        'w'	/* trv, web? trav, traverse */
#define	T_RMNODE	  'x'	/* del, delete */
#define T_SAVEWEB         'y'   /* save the web to disk */
#define T_ADMIN           'z'	/* adm, admin */
#define T_CHG_SRC_INFO    'A'   /* change the info about a source 
				   format is A:<source_info_line> */
#define T_SHOW_CONN       'B'	/* show the current connections, an admin cmd*/
#define T_SHUTDOWN        'C'	/* shutdown the server, save web , dont 
				   accept connections, and shutdown when 
				   connections left have been inactive
				   for n minutes */
#define T_CHG_BANNER      'D'	/* change the banner msg */
#define T_SET_DATES       'E'	/* stat all files except those flagged
				 and set the last modified date (admin cmd)*/
#define T_HELP            'H'   /* send the help menu */
#define T_CHGD_SINCE      'I'   /* send the non-menu nodes which have changed
				 since a certain date*/
#define T_FULL_TXT_SEARCH 'J'   /* Perform full-text WAIS search */
#define T_SOURCE_SRCH     'K'   /* Return all nodes of a given source*/
#define T_NODE_FORMAT     'O'   /* Choose nodelist format */

/*
 * For/From netio.c
 */

/* Output codes necessitated by client bugs which crashed when a node's flags 
   field contained values it didn't like.  Thus the default output format 
   zeros out the flags field, while the new and better format sends the flags 
   across.  The format is changed with the 'O' transaction, which supposedly 
   only new clients will do, to request the new format & get the flags.   
   Added 8/12/92 ark */
#define NO_FLAGS_FORMAT          1        /* Zeros out flags field */
#define SEND_FLAGS_FORMAT        2        /* Sends flags unchanged */
#define TELNET_FORMAT            3        /* "Pretty printing" to make 
					     telnet readable */
#define NUM_FORMATS              3
#define DEFAULT_OUTPUT_FORMAT    NO_FLAGS_FORMAT


/*
 * NOTE: send & deliver reference specific variable names!  `cur_sock' is a
 * global in transact.c, _sendbuf & _sendbuf_pos are global to netio.c.
 * All three parameters are kludgedly meant to be over-ridden by local
 * variables of the same name if so desired.
 */


#define	send(str)	dosend(str, _sendbuf, &_sendbuf_pos)
#define	deliver()	dodeliver(_sendbuf, &_sendbuf_pos, cur_sock)

#define	send_eol()	send(EOL)
#define	send_eom()	send(EOM)
#define	send_eolm()	send(EOLM)
#define not_menu(node)  text_node(node) || flagset(node,N_IMAGE) || flagset(node,N_SERVER_NODE)

extern void send_msg(char *msgstr);
extern nio_rec_file(TOREC *ptr);
extern char	_sendbuf[];
extern char	*_sendbuf_pos;
