/************************************************************************
 * This is the definitions header file for the configuration module.  It
 * includes the definitions of data structures, external declarations and
 * definitions, defitinitions of sybolic constants.
 *
 ************************************************************************/

#include <pthread.h>
#include <glib.h>

/* Number of configurations variables. */
#define VARS 86

#define SCOPE_GLOBAL 1
#define SCOPE_LOCAL 99

/* 
 * Define the length of a string to be 160 to cope with the 
 * copyright statement.
 *
 */
#define STRLENGTH 160

/*
	* Define the length of strings to cope with the values of 
 * various types of string variables.
	*/
#define STRLENGTH_S 40
#define STRLENGTH_M 80
#define STRLENGTH_L 160
#define STRLENGTH_XL 320


/**********************************************
 * Default values for the SOURCE variables		*
	*															*
 **********************************************/

 #define CA_DEFHOST "rowan"						
 #define CA_DEFPORT "4343"
 #define CA_DEFUSER "dbase"						
 #define CA_DEFPASSWORD "encrypt1"				
 #define CA_DEFDBNAME	"default-db"			
															


/**********************************************
 * Defintion of the dictionary structures.		*
	*															*
 **********************************************/

typedef struct dict_s	{
				char varName[STRLENGTH];
				char varSym[STRLENGTH];
				char varType[STRLENGTH];
				int varScope;
				int varNum;
} dict_t;

extern dict_t dictionary[];




/**********************************************
 * Definition of the values structures.			*
 *															*
	**********************************************/

typedef struct values_s	{
				char *strPtr;	/* Pointer to the string that contains the value. */
				void *valPtr;	/* Pointer to the actual value. */
} values_t;									

/*
 * "extern" definition of variables that are defined elsewhere.
 */


extern values_t globals[];
extern values_t locals[];

/*
 * "extern" definition of configuration variables, defined elsewhere.
 */
extern values_t confVars[];

/* Mutex lock; used for synchronising changes. */
pthread_mutex_t Lock;

/* 
	* New value of the bindport.
	* This must be a global variable.
	*/

char newPort[16];

/*
 * The following is needed for the SOURCE variable.  First,
 * we define the "database" structure.  Then, we define the
 * structure of an element of the linked list.  Lastly, we 
 * define the linked list itself.
 */

typedef struct ca_database_s	{

			char host[64];
			char port[16];
			char user[16];
			char password[9];
			char dbName[16];
		} ca_database_t;

extern ca_database_t ripe;
extern ca_database_t arin;
extern ca_database_t radb;

typedef struct ca_database_list_s		{
			char name[16];
			ca_database_t db;
		} ca_database_list_t;

extern ca_database_list_t ripeComponent;
extern ca_database_list_t arinComponent;
extern ca_database_list_t radbComponent;

typedef struct GSList {
		gpointer src;		/* This points to a ca_database_list_t varialbe */
		GSList *next;
		} ca_source_t;


/*************************************************************
 * Definition of the default values for the SOURCE variable.	*
 *																				*
 *************************************************************/

/*
 * char ca_defHost[64];
 * char ca_defPort[16];
 * char ca_defUser[16];
 * char ca_defPassword[9];
 * char ca_defdbName[16];
 */

/*
 * extern char ca_defPort[16];
 * extern char ca_defHost[64];
 * extern char ca_defUser[16];
 * extern char ca_defPassword[9];
 * extern char ca_defdbName[16];
 */

/*
 * The linked-list of sources.
 *
 */
extern GSList *sourceList;
extern ca_source_t *srcList;

/*
 * 20000609
 * Experiment:
 * define the variable mySrcList as type GSList;
 * use the extern modifier and put the "real" definition
 * of the variable elsewhere.
 *
 * extern GSList *mySrcList;
 */

/*
	* The test configuration file.
 * This is defined using a constant string, cf. Oualline, p.145.
 */
extern const char *testFile;
extern const char *tempFile;
extern const char *dictFile;
extern const char *confFile;

/* 
 * Value returned by ca_getStorageLocation if the symbol for
 * a configuration variable cannot be found.
 *
	* This value is also returned by ca_getType, if it cannot map 
 * the name of a configuration variable to a data type.
 *
 */
#define NOT_FOUND -1 	

/*
 * Symbolic constants defined to represent data types.

 * #define CA_INT 			11
 * #define CA_STRING 		12
 * #define CA_DIRLIST 	13
 * #define CA_BOOLEAN 	14
 * #define CA_SOURCETYPE		15
	*/


