/* gs-struct.h */

#ifndef _h_struct
#define _h_struct


#define ADDRLEN         100
#define DATELEN          40
#define REQUESTLEN      400
#define DOMAINLEN	200
#define SHORTDATELEN     10
#define STFLEN            9
#define FTYPLEN           5

/* number of items in the "top 10" lists */
#define TOPNUM		 10


typedef struct treebranch {
    char *request;			/* last piece of file name path */
    char *fullreq;			/* complete file name path */

    int   nreqCU;			/* CU hits */
    int   nreq;				/* total hits */
    float nbytes;			/* number of bytes */

    int   hreqCU;			/* CU hits on html files */
    int   hreq;				/* total hits on html files */
    float hbytes;			/* number of bytes of html files */

    long  date;				/* date of most recent request */
    int   html;				/* true if this is an html file */
    int   printed, wantdomain, wantextract; /* flags */
    struct donode *dom;			/* domain tree */
    struct xtnode *xt;			/* extract file */
    struct ernode *er;			/* list of errors */
    struct treebranch *next,		/* sibling */
		      *sub;		/* list of sub-branches */
} treebranch;



typedef struct domainbranch {		/* *** DOMAINS *** */
    char *domain;
    char *fulldom;
    int   nreq;
    float nbytes;
    int   printed;			/* flag */
    struct domainbranch *next,		/* sibling */
			*sub;		/* list of sub-branches */
} domainbranch;



typedef struct donode {		/* DOMAIN INFO for one vhost:directory */
    char *dirnam;			/* e.g. "/cu/bulletin" */
    domainbranch *dom_root,		/* registered host names */
		 *numeric_host;		/* unresolved numeric addresses */
    domainbranch *dom_top[TOPNUM];	/* top 10 domains */
    int bottom_dom;			/* number of items on the list */
    int unique_hosts;			/* count unique host names */
    struct donode *next;
} donode;



typedef struct xtnode {		/* EXTRACT FILE for one vhost:directory */
    char *dirnam;			/* e.g. "/cu/bulletin" */
    FILE *mex;				/* write to this file */
    int level;				/* number of slashes in dir name */
    int nreq;				/* records written */
    int nbuff;				/* recs waiting to be written */
    char *outbuf;
    struct xtnode *next;
} xtnode;



typedef struct ernode {			/* ERRORS */
    char *url;
    int errcode;
    int errcount;
    long date1secs,
	 date2secs;
    char date1[DATELEN+1],		/* 01/Jan/1995:16:01 */
	 date2[DATELEN+1];
    struct ernode *next;
} ernode;



					/* *** VHOST *** */
/* keep a separate data structure for each virtual host */

typedef struct vhost {
    char proto   [DATELEN+1];		/* http://          */
    char hostname[ADDRLEN+1];		/* www.columbia.edu */
    char sername [ADDRLEN+1];		/* full server name */
    char iconurl [ADDRLEN+1];		/* image URL for reports */
    treebranch *tree_root;		/* count hits */
    treebranch *erro_root;		/* count errors */
    treebranch *redir_root;		/* count redirects */

    /* the dominfo array contains a list of directories
     *  initialized by the SET DOMROOT command
     */
    donode *dominfo;			/* list of domain db's */
    char doroot[ADDRLEN+1];		/* initialized by SET DOMROOT */


    /* the xtinfo array contains a list of directories
     *  initialized by the SET XTROOT command
     */
    xtnode *xtinfo;			/* info about one extract file */
    char xtroot[ADDRLEN+1];		/* initialized by SET XTROOT */
    int	xtfiles, xtcreated,		/* potential files, actual files */
	xtoverwrite,			/*  files overwritten */
	xtrecords, xtwrites,
	xtfilesopen;


    float bytecount;
    int printed,
	htmldocnum,
	gifdocnum,
	jpgdocnum,
	pdfdocnum,
	cginum, seccginum,
	otherdocnum,
	totaldocnum,
	red301, red302,
	fail400, fail401, fail402, fail403, fail404, fail405, fail406,
	fail407, fail408, fail409, fail410, fail411, fail412, fail413,
	fail500, fail501;

    treebranch *tree_topreq[TOPNUM];	/* top 10 files */
    int bottom_req;			/* number of items */
    struct vhost *next;
} vhost;


					/* *** LOGR *** */
typedef struct logr {			/* the fields of a log record */
    char address[ADDRLEN+1];		/* aaa.bbb.ccc */
    char ident  [ADDRLEN+1];		/* identity from identd */
    char user   [ADDRLEN+1];		/* username */
    char date   [DATELEN+1];		/* 01/Jan/1995:16:01:21 -0500 */
    char rprefix[STFLEN+1];		/* GET */
    char request[REQUESTLEN+1+15];	/* leave room for /index.html */
    char rsuffix[ADDRLEN+1];		/* HTTP/1.0 */
    char status [STFLEN+1];		/* 200 */
    char nbytstr[STFLEN+1];		/* 1342 */
    char referer[REQUESTLEN+1];
    char vhost  [ADDRLEN+1];
    char client [REQUESTLEN+1];

    float nbytes;
    char shortdate[SHORTDATELEN+1];	/* date string "mm/dd/yyyy" */
    char filtyp[FTYPLEN+1];		/* html, gif, jpg, etc. */
    long datesecs;			/* seconds since epoch */
    int localreq,			/* request from columbia.edu */
	html;				/* file type is {htm|html|shtml} */
    vhost *virthost;
} logr;


#endif
