#include "PalmType.h"
#include "PalmChip.h"
#include "p_util.h"
#include "p_tcpip.h"
#include "p_http.h"

 CCHAR Http_cName[] = "HTTP/1.1";
 CCHAR Http_cUserAgent[] = "User-Agent";
 CCHAR Http_cCacheControl[] = "Cache-Control: ";
 CCHAR Http_cAcceptLanguage[] = "Accept-Language: en";
 CCHAR Http_cAcceptEncoding[] = "Accept-Encoding";
 CCHAR Http_cAccept[] = "Accept";
 CCHAR Http_cContentLength[] = "Content-Length: ";
 CCHAR Http_cContentType[] = "Content-Type: ";
 CCHAR Http_cConnection[] = "Connection: ";
 CCHAR Http_cWWWAuthenticate[] = "WWW-Authenticate: ";
 CCHAR Http_cProxyAuthenticate[] = "Proxy-Authenticate: ";
 CCHAR Http_cMethodGet[] = "GET ";
 CCHAR Http_cMethodPost[] = "POST ";

 USHORT HttpSendOK(USHORT iContentLen, UCHAR iContentType)
{
	p_line_start((PXCHAR)Adapter_pSendTcpData);

	p_line_add_c(Http_cName);
	p_line_add_c((PCCHAR)" 200 OK");
	p_line_add_newline();

	p_line_add_c(Http_cContentLength);
	p_line_add_val(iContentLen);
	p_line_add_newline();

	if (iContentType == HTTP_CT_IMAGE_GIF)
	{
		p_line_add_c(Http_cCacheControl);
		p_line_add_c((PCCHAR)"max-age=86400");
		p_line_add_newline();

		p_line_add_c(Http_cContentType);
		p_line_add_c((PCCHAR)"image/gif");
	}
	else
	{
		p_line_add_c(Http_cContentType);
		p_line_add_c((PCCHAR)"text/html");
	}
	p_line_add_newline();

	p_line_add_c(Http_cConnection);
	p_line_add_c((PCCHAR)"close");
	p_line_add_newline();
	p_line_add_newline();
	return p_line_get_len();
}

/*
USHORT HttpSendImageOK(USHORT iContentLen)
{
	p_line_start((PXCHAR)Adapter_pSendTcpData);

	p_line_add_c(Http_cName);
	p_line_add_c((PCCHAR)" 200 OK");
	p_line_add_newline();

	p_line_add_c(Http_cContentLength);
	p_line_add_val(iContentLen);
	p_line_add_newline();

	p_line_add_c(Http_cCacheControl);
	p_line_add_c((PCCHAR)"max-age=86400");
	p_line_add_newline();

	p_line_add_c(Http_cContentType);
	p_line_add_c((PCCHAR)"image/gif");
	p_line_add_newline();

	p_line_add_c(Http_cConnection);
	p_line_add_c((PCCHAR)"close");
	p_line_add_newline();
	p_line_add_newline();
	return p_line_get_len();
}
*/

UCHAR HttpSendError()
{
	p_line_start((PXCHAR)Adapter_pSendTcpData);
	p_line_add_c(Http_cName);
	p_line_add_c((PCCHAR)" 403 Forbidden");
	p_line_add_newline();
	p_line_add_newline();
	return (UCHAR)p_line_get_len();
}

