/*
 * Copyright 1990 by Baylor College of Medicine ALL RIGHTS RESERVED. 
 *
 * This program is subject to a license agreement between 
 * Baylor College of Medicine and MIT. Any use inconsistent with
 * said license and any use by persons other than the faculty, 
 * students and staff at MIT or any use on a computer not operated 
 * as part of the Athena Computing Environment (ACE) is expressly 
 * prohibited.
 */
/****************************************************************
 * File: dbsrv.h 
 * Date: 02/14/91
 *
 * Description:
 *
 * Revisions:
 ****************************************************************/
#ifndef __DBSRV__
#define __DBSRV__

/* dbsrv version numbers */
#define DBSRV_MAJOR   1
#define DBSRV_MINOR   1
#define DBSRV_RELEASE 0

#ifndef TRUE
#define TRUE  1
#endif

#ifndef FALSE
#define FALSE 0
#endif

typedef enum {OT_IMAGE,OT_TXT,OT_LINK,OT_ACTION_LINK} Object_Type;

typedef struct _dbDatabase *dbDatabase ;
typedef struct _dbNotebook *dbNotebook ;
typedef struct _dbPage *dbPage ;
typedef struct _dbObject *dbObject ;
typedef struct _LinkList *LinkList ;
typedef struct _Author *dbAuthor ;
typedef struct _Access_List *Access_List ;

struct _Author {
	int aid ;           /* auther id or user id */
	dbAuthor next ;     /* pointer to the next author */
} ;

struct _Access_List {
	dbAuthor author ;   /* author information */
	int access ;        /* access flag */
	Access_List next ;  /* ponter to next access list */
} ;

struct _LinkList {
	dbNotebook note ;   /* a link from this notebook */
	dbPage page ;       /* a link from this page */
	dbObject object ;   /* a link from these objects */
	LinkList next ;
} ;

struct _dbDatabase
{
	char *name ;            /* database name */
	dbDatabase next ;       /* pointer to the next database */
	dbNotebook notebooks ;  /* list of notebooks for database */
	int next_notebook_id ;  /* the next notebook id */
	dbAuthor authors ;      /* list of authors or user for notebooks */
} ;

struct _dbNotebook
{
	int nid ;               /* notebook id */
	char *title ;           /* title of notebook */
	dbAuthor author ;       /* author of the notebook */
	char *create_date ;     /* date of creation */
	char *modify_date ;     /* date last modified */
	dbPage pages ;          /* list of pages in notebook */
	dbNotebook next ;       /* poinyter to the next notebook */
	int home_page ;         /* home page id for notebook */
	int next_page_id ;      /* next page id */
	Access_List al ;        /* access list of authors */
} ;

struct _dbPage
{
	int pid ;               /* page id */
	char *title ;           /* title of page */
	dbAuthor author ;       /* author information for the page */
	char *create_date ;     /* creation date for the page */
	char *modify_date ;     /* date last modified */
	int width ;             /* width of the page window */
	int height ;            /* height of the page window */
	char *color ;           /* background color for the page */
	dbObject objects ;      /* list of objects for the page */
	dbPage next ;           /* pointer to the next page */
	LinkList link_list ;    /* list of links to this page */
	int next_object_id ;    /* next object id */
	int visited ;           /* visited flag (used for searching) */
} ;

typedef union
{
	struct {
		char *color ;            /* color of the text */
		char *font ;             /* font for the text */
		char *contents ;         /* text itself */
	} text ;
	struct {
		int create_colormap ;    /* colormap flag for iamge */
		int low_res_sw ;         /* low-res flag for image */
	} image ;
	struct {
		char *color ;            /* color for link label text */
		char *font ;             /* font for link label text */
		char *title ;            /* the link label text */
		dbNotebook dest_note ;   /* destination notebook for link */
		dbPage dest_page ;       /* destination page for link */
	} link ;
	struct {
		char *color ;            /* color for action link label text */
		char *font ;             /* font for action link label text */
		char *title ;            /* text for action link label */
		char *command ;          /* command executed by action link */
	} action_link ;
} Object_Specifics ;

struct _dbObject
{
	int oid ;                    /* object id */
	dbAuthor author ;            /* author of the object */
	char *create_date ;          /* date the object was created */
	char *modify_date ;          /* date last modified */
	int type ;                   /* the type of object */
	int x ;                      /* the x position for the object on page */
	int y ;                      /* the y position for the object on page */
	int width ;                  /* width of the object */
	int height ;                 /* height of the object */
	Object_Specifics data ;      /* object specific data */
	dbObject next ;              /* pointer to the next object */
} ;

/* Connection structure, 1 exists for every connection */
typedef struct _Connection *Connection ;

struct _Connection
{
	int conn_sock ;
	char buf[512] ;
	int lbuf ;
	enum {STATE_WAIT_INFO,STATE_REQ_OK} state ;
	dbDatabase db ;
	dbAuthor author ;
	Connection next ;
} ;

typedef struct
{
	Connection first ;
} Connection_List ;

/* Program context */
struct
{
	Connection_List cl ;      /* List of all active connections */
	int listen_sock ;         /* Listening socket */
	int port ;                /* port number */
	int interrupt_received ;  /* True if interrupt received */
	dbDatabase dbs ;          /* List of databases */
	char data_dir[256] ;      /* Database directory */
	int vns_uid;              /* the vns user id */
} pc ;

dbNotebook find_note_by_id() ;
dbPage find_page_by_id() ;
dbObject find_object_by_id() ;
dbNotebook find_note_by_name() ;
dbNotebook add_notebook() ;
dbPage add_page() ;
dbObject add_object() ;
dbAuthor find_author_by_id() ;
Access_List find_access() ;

#include "vns_proto.h"
#include "hash.h"
#endif
