#include "RadiusClt1.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[])
{
	if(argc < 5)
	{
		printf("Usage:uniotpdemo username OTP[PIN] host secret port timeout\n");
		return -1;
	}
	int nport = 1812, ntmout = 5;
	if(argc > 5)
	{
		nport = atoi(argv[5]);	
	}
	if(argc > 6)
	{
		ntmout = atoi(argv[6]);	
	}
	/*
	RadiusClt radclt("192.168.1.225", "hello", 5);
	radclt.parase(argv[1], strlen(argv[1]), argv[2], strlen(argv[2]));
	int nChallenge, bValidChallenge;
	int nret = radclt.auth(nChallenge, bValidChallenge);
	if(RD_ERROR_SUCCESS == nret)
	{
		printf("authentication successfully!\n");
	}
	else if(RD_ERROR_CHALLENGENEED == nret)
	{
		printf("Challenge Number:%d\n", nChallenge);
	}
	else
	{
		printf("authentication failed!\n");
	}*/
	int nChallenge, bValidChallenge, nret;
	RadiusClt radclt;
	radclt.initrad(argv[3], argv[4], strlen(argv[4]), nport, ntmout);
	radclt.parase(argv[1], strlen(argv[1]), argv[2], strlen(argv[2]));
	nret = radclt.auth(nChallenge, bValidChallenge);
	if(RD_ERROR_SUCCESS == nret)
	{
		printf("Authentication successfully!\n");	
	}
	else if(RD_ERROR_CHALLENGENEED == nret && bValidChallenge)
	{
		printf("Challenge need!Challenge Code:%d\n", nChallenge);	
	}
	else
	{
		printf("Authentication failed!ErrorCode:%d\n", nret);
	}
	return 0;
}

