#include "page1.h"
#include "p_h323.h"
#include "citron.h"

#ifdef CALL_H323

/*
13 c0 23 cd 06 00 08 91 4a 00 04 00 00 06 20 20
35 2e 38 34 01 00 d3 93 11 29 06 ba 01 40 0d 00
54 00 65 00 72 00 6d 00 69 00 6e 00 61 00 6c 00
20 00 61 00 6c 00 69 00 61 00 73 0a 00 45 00 54
00 4e 00 53 00 47 00 4b 24 00 31 00 30 00 33 00
34 00 34 00 30 00 30 00 30 00 39 00 30 00 38 00
34 00 33 00 37 00 5f 00 65 00 6e 00 64 00 70 0e
8a 03 40 01 2b 01 00 01 00 

2b 80 08 10 40 02 80 00 d3 9c b2 0b 06 b8 00 c7
00 00 06 30 31 31 36 34 30 14 00 c0 01 00 0b 80
01 f8 01 00 01 00 01 00 01 00 
*/

void eTalkHandleAdmCfm(PXCHAR pMsg)
{
	XCHAR pBuf[6];
	DSHORT iVal;

	iVal = p_atoi(pMsg, 10);
	iVal /= 60;
	p_itoa(iVal, pBuf, 10);
//	SdramPlayNumber(iVal);
	DisplayLine(pBuf, 1);
}

void eTalkHandleRegCfm(PXCHAR pMsg)
{
	PXCHAR_D pCur;
	pCur = pMsg;
	DisplayLine(pCur, 1);
	SdramPlayString(pCur);
}

PXCHAR _GetCreditBuf(PXCHAR pMsg, PCCHAR cKeywords, UCHAR iSeparator)
{
	DCHAR i, iLen, iCreditLen;
	PXCHAR_D pCur;
	PXCHAR_D pEnd;

	iLen = p_strlen_x(pMsg);
	iCreditLen = p_strlen_c(cKeywords);
	for (i = 0; i < iLen - iCreditLen; i ++)
	{
		pCur = (PXCHAR)(pMsg+i);
		if (!p_memcmp_c2x(pCur, cKeywords, iCreditLen))
		{
			pCur += iCreditLen;
			pEnd = p_strchr_x(pCur, iSeparator);
			if (pEnd)
			{
				pEnd[0] = 0;
			}
			return pCur;
		}
	}
	return (PXCHAR)0;
}

PXCHAR _DisplayCreditTime(PXCHAR pMsg, PCCHAR cKeywords, UCHAR iSeparator)
{
	PXCHAR_D pCur;
	DCHAR iLen;
	DLONG lTime;
	XCHAR pBuf[DISPLAY_MAX_CHAR+1];

	pCur = _GetCreditBuf(pMsg, cKeywords, iSeparator);
	if (pCur)
	{
		lTime = p_atol(pCur, 10);
//		DisplayLine(pCur, 0);
		GetTimeDisplay(lTime, (PUCHAR)pBuf);
		Display(pBuf, 0, 0, FALSE);
		iLen = p_strlen_x(pCur);
		pCur += iLen + 1;
	}
	return pCur;
}

PXCHAR _DisplayCreditAmount(PXCHAR pMsg, PCCHAR cKeywords, UCHAR iSeparator, BOOLEAN bPlay)
{
	PXCHAR_D pCur;
	DCHAR iLen;

	pCur = _GetCreditBuf(pMsg, cKeywords, iSeparator);
	if (pCur)
	{
		DisplayLine(pCur, 1);
		if (bPlay)
		{
			SdramPlayString(pCur);
		}
		iLen = p_strlen_x(pCur);
		pCur += iLen + 1;
	}
	return pCur;
}

/*
2b 80 38 40 40 05 00 40 db ee ec d2 4d bc 00 77
00 00 2e 68 33 32 33 2d 63 72 65 64 69 74 2d 61
6d 6f 75 6e 74 3d 31 39 2e 30 30 3b 68 33 32 33
2d 63 72 65 64 69 74 2d 74 69 6d 65 3d 37 35 35
39 14 00 c0 01 00 0b 80 01 f8 01 00 01 00 01 00
01 00
*/
 
static CCHAR _cBolH323CreditAmount[] = "h323-credit-amount=";
static CCHAR _cBolH323CreditTime[] = "h323-credit-time=";

void IpnHandleAdmCfm(PXCHAR pMsg)
{
	PXCHAR_D pCur;

	pCur = _DisplayCreditAmount(pMsg, _cBolH323CreditAmount, ';', FALSE);
	_DisplayCreditTime(pCur, _cBolH323CreditTime, ';');
}

void IpnHandleRegCfm(PXCHAR pMsg)
{
	_DisplayCreditAmount(pMsg, _cBolH323CreditAmount, ';', TRUE);
}

#ifdef SYS_ASIAINFO
/*
2b 80 0d be 40 05 00 40 c0 a8 01 ab 04 51 00 77
40 b5 00 08 08 2f 41 63 63 6f 75 6e 74 54 79 70
65 3d 30 3b 43 72 65 64 69 74 54 69 6d 65 3d 38
36 34 30 30 3b 41 63 63 6f 75 6e 74 42 61 6c 61
6e 63 65 3d 30 14 00 c0 01 00 0b 80 01 f8 01 00
01 00 01 00 01 00 
*/

static CCHAR _cAsiaInfoCreditAmount[] = "AccountBalance=";
static CCHAR _cAsiaInfoCreditTime[] = "CreditTime=";

void AsiainfoHandleAdmCfm(PXCHAR pMsg)
{
	PXCHAR_D pCur;

	pCur = _DisplayCreditTime(pMsg, _cAsiaInfoCreditTime, ';');
	_DisplayCreditAmount(pCur, _cAsiaInfoCreditAmount, ';', FALSE);
}
#endif

#endif
