			/* ------------------------------------- */
			//										 //
			//  +-+-+-+-+-+-+ +-+-+-+-+-+ +-+-+-+-+  //
			//  |S|i|m|p|l|e| |P|r|o|x|y| |2|0|0|4|  //
			//  +-+-+-+-+-+-+ +-+-+-+-+-+ +-+-+-+-+  //
			//										 //
			//										 //
			//  AUTOR : Aymeric  //
			//  DATE  : May 2004					 //
			//  FILE  : readConfig.c				 //
			//  DESC  : function to read config file //
			//  									 //
			/* ------------------------------------- */


/************************************************************************/

#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

#include "proxy.h"

#define DELIMIT "=;"

/************************************************************************/
// FunctionName : readConfig
//
// Description  : read the config file and set information
//
// Parameters
// [in]
//			char *file			   : file name
//			struct sConfig *result : to set the values
//
// [out]
//			nothing
//
// Returns
//			bool : true if no problem
//
// Calls
//			nothing
//
// Globals
//			enum bool debug	 : if debug is true, we are in debug mode
//
/************************************************************************/

enum bool readConfig(char *file, struct sConfig *result)
{
	FILE *Fconfig;
	char *param;

	char line[512]="";

	/* we open the file in read-only */
	Fconfig=fopen(file,"r");

	if ( Fconfig == NULL )
	{
		printf("(%s) Config file not found.\n",file);
		return(false);
	}

	while(!feof(Fconfig))
	{
		if ( fgets(line, sizeof(line) - 1, Fconfig) == NULL ) break;

		if (line[0] != '#')
		{
			param=strtok(line,DELIMIT);
			if (strcmp(param,"port") == 0)
			{
				result->port=atoi(strtok(NULL,DELIMIT));
			}
			else if (strcmp(param,"host") == 0)
			{
				strncpy(result->host,strtok(NULL,DELIMIT),255);
			}
			else if (strcmp(param,"proxyserv") == 0)
			{
				result->proxyserv=atoi(strtok(NULL,DELIMIT));
			}
			else if (strcmp(param,"daemon") == 0)
			{
				result->daemon=atoi(strtok(NULL,DELIMIT));
			}
			else if (strcmp(param,"proxyhost") == 0)
			{
				strncpy(result->proxyhost,strtok(NULL,DELIMIT),255);
			}
			else if (strcmp(param,"proxyport") == 0)
			{
				result->proxyport=atoi(strtok(NULL,DELIMIT));
			}
			else if (strcmp(param,"cache") == 0)
			{
				result->cache=atoi(strtok(NULL,DELIMIT));
			}
		}
	}
	fclose(Fconfig);
	return(true);
}

