/*******************************************************************************/
/*                                                                             */
/*  Copyright 2005 Pascal Gloor <pascal.gloor@spale.com>                       */
/*                                                                             */
/*  Licensed under the Apache License, Version 2.0 (the "License");            */
/*  you may not use this file except in compliance with the License.           */
/*  You may obtain a copy of the License at                                    */
/*                                                                             */
/*     http://www.apache.org/licenses/LICENSE-2.0                              */
/*                                                                             */
/*  Unless required by applicable law or agreed to in writing, software        */
/*  distributed under the License is distributed on an "AS IS" BASIS,          */
/*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   */
/*  See the License for the specific language governing permissions and        */
/*  limitations under the License.                                             */
/*                                                                             */
/*******************************************************************************/

#include "defs.h"
#include "conf.h"


int load_ipcheck(char *file)
{
	FILE *fh;
	char *line;
	size_t len;
	int i = 0;

	fh = fopen(file,"r");
	if ( fh == NULL )
		return -1;

	while( ( line = fgetln(fh, &len) ) != NULL )
	{
		struct in_addr addr;


		if ( *(line+len-2) == '\r' )
			*(line+len-2) = '\0';
		else
			*(line+len-1) = '\0';

		inet_aton(line,&addr);

		iplist[i].ip = addr.s_addr;
		iplist[i].old = 0;
		iplist[i].new = 0;

		if ( iplist[i].ip != 0 )
			i++;
	}

	fclose(fh);

	iplist[i].ip  = 0;
	iplist[i].old = 0;
	iplist[i].new = 0;

	return 0;
}

int load_blcheck(char *file)
{
	FILE *fh;
	char *line;
	size_t len;
	int i = 0;

	fh = fopen(file,"r");
	if ( fh == NULL )
		return -1;

	while( ( line = fgetln(fh, &len) ) != NULL )
	{
		if ( len < 1 )
			continue;

		if ( *(line+len-2) == '\r' )
			*(line+len-2) = '\0';
		else
			*(line+len-1) = '\0';

		len = strlen(line);

		if ( len >= BLMAX )
			continue;

		memcpy(bllist[i], line, len+1);

		i++;
		if ( i+1 == BLMAX )
			break;
	}
	fclose(fh);

	bllist[i][0] = '\0';

	return 0;
}