Line 18... |
Line 18... |
#endif
|
#endif
|
#include "rtos.h"
|
#include "rtos.h"
|
#include "tcpip.h"
|
#include "tcpip.h"
|
#ifdef WIN32
|
#ifdef WIN32
|
#define UartPrintf printf
|
#define UartPrintf printf
|
|
#define OS_MQueueCreate(A,B,C) 0
|
|
#define OS_MQueueGet(A,B,C) 0
|
|
#define OS_ThreadCreate(A,B,C,D,E) 0
|
#endif
|
#endif
|
|
|
const char pageGif[]=
|
const char pageGif[]=
|
{
|
{
|
"HTTP/1.0 200 OK\r\n"
|
"HTTP/1.0 200 OK\r\n"
|
|
"Content-Length: %d\r\n"
|
"Content-Type: binary/gif\r\n\r\n"
|
"Content-Type: binary/gif\r\n\r\n"
|
};
|
};
|
const char pageBinary[]=
|
const char pageBinary[]=
|
{
|
{
|
"HTTP/1.0 200 OK\r\n"
|
"HTTP/1.0 200 OK\r\n"
|
|
"Content-Length: %d\r\n"
|
"Content-Type: binary/binary\r\n\r\n"
|
"Content-Type: binary/binary\r\n\r\n"
|
};
|
};
|
const char pageHtml[]={
|
const char pageHtml[]={
|
"HTTP/1.0 200 OK\r\n"
|
"HTTP/1.0 200 OK\r\n"
|
|
"Content-Length: %d\r\n"
|
"Content-Type: text/html\r\n\r\n"
|
"Content-Type: text/html\r\n\r\n"
|
};
|
};
|
const char pageText[]={
|
const char pageText[]={
|
"HTTP/1.0 200 OK\r\n"
|
"HTTP/1.0 200 OK\r\n"
|
|
"Content-Length: %d\r\n"
|
"Content-Type: text/text\r\n\r\n"
|
"Content-Type: text/text\r\n\r\n"
|
};
|
};
|
const char pageEmpty[]=
|
const char pageEmpty[]=
|
{
|
{
|
"HTTP/1.0 404 OK\r\n"
|
"HTTP/1.0 404 OK\r\n"
|
|
"Content-Length: 0\r\n"
|
"Content-Type: text/html\r\n\r\n"
|
"Content-Type: text/html\r\n\r\n"
|
};
|
};
|
|
|
static const PageEntry_t *HtmlPages;
|
static const PageEntry_t *HtmlPages;
|
static int HtmlFiles;
|
static int HtmlFiles;
|
Line 54... |
Line 62... |
void HttpServerAction(IPSocket *socket)
|
void HttpServerAction(IPSocket *socket)
|
{
|
{
|
uint8 buf[600];
|
uint8 buf[600];
|
int bytes, i, length, len, needFooter;
|
int bytes, i, length, len, needFooter;
|
char *name=NULL, *page=NULL;
|
char *name=NULL, *page=NULL;
|
|
const char *header, *header2;
|
|
|
if(socket == NULL)
|
if(socket == NULL)
|
return;
|
return;
|
bytes = IPRead(socket, buf, sizeof(buf)-1);
|
bytes = IPRead(socket, buf, sizeof(buf)-1);
|
if(bytes)
|
if(bytes)
|
Line 104... |
Line 113... |
return;
|
return;
|
}
|
}
|
if(length == 0)
|
if(length == 0)
|
length = (int)strlen(page);
|
length = (int)strlen(page);
|
needFooter = 0;
|
needFooter = 0;
|
|
#if 0
|
if(strstr(name, ".html"))
|
if(strstr(name, ".html"))
|
IPWrite(socket, (uint8*)pageHtml, (int)strlen(pageHtml));
|
IPWrite(socket, (uint8*)pageHtml, (int)strlen(pageHtml));
|
else if(strstr(name, ".htm") || strcmp(name, "/ ") == 0)
|
else if(strstr(name, ".htm") || strcmp(name, "/ ") == 0)
|
{
|
{
|
IPWrite(socket, (uint8*)HtmlPages[0].page, (int)strlen(HtmlPages[0].page));
|
IPWrite(socket, (uint8*)HtmlPages[0].page, (int)strlen(HtmlPages[0].page));
|
Line 115... |
Line 125... |
}
|
}
|
else if(strstr(HtmlPages[i].name, ".gif"))
|
else if(strstr(HtmlPages[i].name, ".gif"))
|
IPWrite(socket, (uint8*)pageGif, (int)strlen(pageGif));
|
IPWrite(socket, (uint8*)pageGif, (int)strlen(pageGif));
|
else
|
else
|
IPWrite(socket, (uint8*)pageBinary, (int)strlen(pageBinary));
|
IPWrite(socket, (uint8*)pageBinary, (int)strlen(pageBinary));
|
|
#else
|
|
header2 = NULL;
|
|
if(strstr(name, ".html"))
|
|
header = pageHtml;
|
|
else if(strstr(name, ".htm") || strcmp(name, "/ ") == 0)
|
|
{
|
|
header = pageHtml;
|
|
header2 = HtmlPages[0].page;
|
|
needFooter = 1;
|
|
}
|
|
else if(strstr(HtmlPages[i].name, ".gif"))
|
|
header = pageGif;
|
|
else
|
|
header = pageBinary;
|
|
len = 0;
|
|
if(header2)
|
|
len += (int)strlen(header2) + (int)strlen(HtmlPages[1].page);
|
|
sprintf((char*)buf, header, length + len);
|
|
IPWrite(socket, buf, (int)strlen((char*)buf));
|
|
if(header2)
|
|
IPWrite(socket, (uint8*)header2, (int)strlen(header2));
|
|
#endif
|
IPWrite(socket, (uint8*)page, length);
|
IPWrite(socket, (uint8*)page, length);
|
if(needFooter)
|
if(needFooter)
|
IPWrite(socket, (uint8*)HtmlPages[1].page, (int)strlen(HtmlPages[1].page));
|
IPWrite(socket, (uint8*)HtmlPages[1].page, (int)strlen(HtmlPages[1].page));
|
#ifdef WIN32
|
#ifdef WIN32
|
if(page != HtmlPages[i].page)
|
if(page != HtmlPages[i].page)
|
Line 135... |
Line 167... |
}
|
}
|
|
|
|
|
void HttpThread(void *Arg)
|
void HttpThread(void *Arg)
|
{
|
{
|
IPSocket *socket;
|
IPSocket *socket=NULL;
|
(void)Arg;
|
(void)Arg;
|
for(;;)
|
for(;;)
|
{
|
{
|
OS_MQueueGet(HttpMQueue, &socket, OS_WAIT_FOREVER);
|
OS_MQueueGet(HttpMQueue, &socket, OS_WAIT_FOREVER);
|
HttpServerAction(socket);
|
HttpServerAction(socket);
|
Line 178... |
Line 210... |
IPWrite(socket, text, (int)strlen(text));
|
IPWrite(socket, text, (int)strlen(text));
|
IPClose(socket);
|
IPClose(socket);
|
}
|
}
|
static const PageEntry_t pageEntry[]=
|
static const PageEntry_t pageEntry[]=
|
{ //name, length, htmlText
|
{ //name, length, htmlText
|
{"/Header", 0, "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"
|
{"/Header", 0, "<HTML><HEAD><TITLE>Plasma CPU</TITLE></HEAD>\n<BODY>"},
|
"<HTML><HEAD><TITLE>Plasma CPU</TITLE></HEAD>\n<BODY>"},
|
|
{"/Footer", 0, "</BODY></HTML>"},
|
{"/Footer", 0, "</BODY></HTML>"},
|
{"/ ", 0, "<h2>Home Page</h2>Welcome! <a href='/other.htm'>Other</a>"
|
{"/ ", 0, "<h2>Home Page</h2>Welcome! <a href='/other.htm'>Other</a>"
|
" <a href='/cgi/myprog'>myprog</a>"},
|
" <a href='/cgi/myprog'>myprog</a>"},
|
{"/other.htm ", 0, "<h2>Other</h2>Other."},
|
{"/other.htm ", 0, "<h2>Other</h2>Other."},
|
//{"/binary/plasma.gif ", 1945, PlasmaGif},
|
//{"/binary/plasma.gif ", 1945, PlasmaGif},
|