#include <stdio.h>
#include <stdlib.h>

#define	RCACCT_CONF_PATH	"/user/service/etc/rcacct.conf"
int devide(char **val, char *str, char delim)
{
	char *p;
	int i, j;

	val[0] = (char *)malloc(512);
	memset(val[0], 0, 512);

	for (p=str, i=0, j=0; *p != '\0'; p++)
	{
		if (*p == delim)
		{
			*(val[i] + j) = '\0';
			j = 0;
			i++;
			val[i] = (char *)malloc(sizeof(char) * 2 + 1);
			memset(val[i], 0, sizeof(char)*2+1);
			continue;
		}
		//else if (*p == '\n')
		//{			
		//	continue;
		//}
		else
		{
			*(val[i] + j++) = *p;
		}
	}
	*(val[i] + j) = '\0';
	return (i+1);
}

int rcacctFind(char **param, char *ipString)
{
	FILE *acct_ifp = NULL;
	char delim = ':';
	char buff[1024];
	int num;

	acct_ifp = fopen(RCACCT_CONF_PATH, "r");
	if (acct_ifp == NULL)
	{
		fprintf(stderr, "cannot open rcacct file!\n");
		exit(1);
	}
	
	while(fgets(buff, 1024, acct_ifp) != NULL)
	{
		fprintf(stderr, "buff : %s", buff);
		/* extraction information */
		num = devide(param, buff, delim);
	
		fprintf(stderr, "param[0] : %s\n", param[4]);
		if (!strcmp(ipString, param[0]))
		{
			break;
		}
	}
	return num;
}

int main()
{
	char *param[512];
	int	param_num;

	param_num = rcacctFind(param, "rc105-test");
	exit(0);	
}
