#include "p_apps.h"
#include "p_sip.h"
#include "v_task.h"
#include "my_sip.h"

void SipGenAuth(UCHAR iMethod, UCHAR iUriIndex, UCHAR iAuthIndex, UCHAR iAuthType)
{
	DCHAR iLen;

	HttpAuthInit();

	iLen = SdramReadData((USHORT)(PROTOCOL_SDRAM_POS+iUriIndex));
	if (iLen)	HttpWriteData(HTTP_AUTH_URI, iLen);
	if (Sys_iServiceType == SIP_SERVICE_TYPE_TONLINE)
	{
		p_strcpy_x2x((PXCHAR)Sdram_pDataCache, Sys_pAccount);
		p_strcat_c2x((PXCHAR)Sdram_pDataCache, (PCCHAR)"@t-online.de");
		iLen = p_strlen_x((PXCHAR)Sdram_pDataCache);
		HttpWriteData(HTTP_AUTH_ACCOUNT, iLen);
	}
	else
	{
		HttpSaveString(HTTP_AUTH_ACCOUNT, Sys_pAccount);
	}
	HttpSaveString(HTTP_AUTH_PASSWORD, Sys_pPin);
	SdramReadString((USHORT)(PROTOCOL_SDRAM_POS+iAuthIndex));
	p_strcpy_x2x((PXCHAR)Sdram_pDataCache2, (PXCHAR)Sdram_pDataCache);
	HttpGenAuth((PXCHAR)Sdram_pDataCache2, _cMethod[iMethod], iAuthType);
}


void SipFillAuth()
{
	HttpFillAuth(HTTP_WWW_AUTH_RESP);
	HttpFillAuth(HTTP_PROXY_AUTH_RESP);
}

void SipCopyAuth(UCHAR iWWWAuth, UCHAR iProxyAuth)
{
	if (SdramReadString(PROTOCOL_SDRAM_POS+SIP_RECV_WWW_AUTHENTICATE))
	{
		SipCpySdram(iWWWAuth, SIP_RECV_WWW_AUTHENTICATE);
	}
	if (SdramReadString(PROTOCOL_SDRAM_POS+SIP_RECV_PROXY_AUTHENTICATE))
	{
		SipCpySdram(iProxyAuth, SIP_RECV_PROXY_AUTHENTICATE);
	}
}
