/*
 *------------------------------------------------------------------
 * $Source: /afs/net.mit.edu/dev/project/techinfodev/src/srv_ti/RCS/network.h,v $
 * $Revision: 3.2 $
 * $Date: 93/02/03 11:26:40 $
 * $Author: thorne $
 *------------------------------------------------------------------
 */
/*
 * a header for Techinfo network stuff
 */
/* The top half of this file will need to be modified before compiling the 
   server for a new installation. Also there are other file locations 
   in glob.c */
/* 
 * NOTE:  By default clients do NOT see the a node's flags; in the default
 *  format a zero is sent in place of the flags.  To receive the flags, a 
 *  client must use the 'O' transaction (see below).
 */

#define PIPS_PORT	9000
#define PORT            "9000"
#define PIPS_SERVER     "tiserve.mit.edu"
#define TI_VERSION      "UNIX:3.1"
#define HELP_PHONE      "(617) 253-4101"
#define HELP_ID          10210
#define TI_SERVICE      "rcmd"
#define DEFAULT_DOMAIN  "mit.edu"

#define BANNER_MSG  101
#define BANNER     "0:TechInfo Server, version 3.3  .\n"
#define NAK_BANNER     "100: The TechInfo Server is temporarily unavailable, please try again later.\n"
#ifndef TEST
/* production locations */
#define  TRANS_LOG	"/var/ti/logs/pips.trans.log"
#define  NEXTID_FILE	"/var/ti/admin/pips.next.id"
#define  PROV_FILE	"/var/ti/admin/pips.providers"
#define  VER_FILE	"/var/ti/admin/pips.versions"
#define  AUTH_FILE      "/var/ti/admin/pips.auth"
#define  LOCAL_WEB_FILE "/var/ti/admin/pips.web"
#define  ACL_DIR        "/var/ti/admin/acl/"
#define  PROV_LN_SZ	220
#define  ADMIN_FILE	"/var/ti/admin/pips.admin"
#define  ADMIN_LN_SZ	300
#define  SERVER_FILE       "/var/ti/admin/pips.servers"
#define  SOURCE_FILE       "/var/ti/admin/pips.sources"
#define  SOURCE_FILE_BACKUP       "/var/ti/admin/pips.sources.bak"
#define  TMP_SOURCE_FILE   "/var/ti/admin/pips.sources.tmp"
#define EXCLUSION_FILE    "/var/ti/admin/pips.exl_file" /* dont allow nodes with these paths */
#define NODE_TYPES_FILE  "/var/ti/admin/pips.node.types"
#define	PIPS_LOCKER	"ti_data"
#define SERVER_UID       20061

#else
/* test locations */
#define  TRANS_LOG	"pips.trans.log"
#define  NEXTID_FILE	"pips.next.id"
#define  PROV_FILE	"pips.providers"
#define  VER_FILE	"pips.versions"
#define  AUTH_FILE      "pips.auth"
#define  LOCAL_WEB_FILE "pips.web"
#define  ACL_DIR        "acl/"
#define  PROV_LN_SZ	220
#define  ADMIN_FILE	"pips.admin"
#define  ADMIN_LN_SZ	300
#define  SERVER_FILE       "pips.servers"
#define  SOURCE_FILE       "pips.sources"
#define  SOURCE_FILE_BACKUP     "pips.sources.bak"
#define  TMP_SOURCE_FILE   "pips.sources.tmp"
/* #define	 PIPS_LOCKER	"dosathena" */
#define EXCLUSION_FILE    "pips.exl_file" /* dont allow nodes with these paths */
#define NODE_TYPES_FILE  "pips.node.types"
#define	 PIPS_LOCKER	"wade"
#define SERVER_UID       20061
#endif

/*++++++++  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  ADV_HELP_ID    22558     /*  old way -- not used */
#define  HELP_MENU_ID   25783     /*  old way -- not used */

#define  NOBODY  -1
#define LG_BUFSIZ 4096
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 */
#define T_KRB_AUTH        'P'   /* authenticate as provider using kerberos */
#define T_NEW_PROVIDER    'N'   /* add a new provider to provider table */
#define T_NODE_TYPES      'M'   /* send a list of node types */
/*
 * 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)

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



