使用举例:
void cgi_process_data (U8 code, U8 *dat, U16 len) {
/* This function is called by HTTP server to process the returned Data */
/* for the CGI Form POST method. It is called on SUBMIT from the browser. */
/* Parameters: */
/* code - callback context code */
/* 0 = www-url-encoded form data */
/* 1 = filename for file upload (0-terminated string) */
/* 2 = file upload raw data */
/* 3 = end of file upload (file close requested) */
/* 4 = any xml encoded POST data (single or last stream) */
/* 5 = the same as 4, but with more xml data to follow */
/* Use http_get_content_type() to check the content type */
/* dat - pointer to POST received data */
/* len - received data length */
U8 *var;
switch (code) {
case 0:
/* Url encoded form data received. */
break;
case 1:
/* Filename for file upload received as encoded by the browser. */
/* It might contain an absolute path to a file from the sending */
/* host. Open a file for writing. */
return;
case 2:
/* File content data received. Write data to a file. */
/* This function will be called several times with */
/* code 2 when a big file is being uploaded. */
return;
case 3:
/* File upload finished. Close a file. */
return;
case 4:
/* XML encoded content type, last packet. */
// pType = http_get_content_type ();
/* check the content type for CGX file request. */
/* pType is a pointer to a 0-terminated string */
/* For example: text/xml; charset=utf-8 */
return;
case 5:
/* XML encoded as under 4, but with more to follow. */
return;
default:
/* Ignore all other codes. */
return;
}
if (len == 0) {
/* No data or all items (radio, checkbox) are off. */
return;
}
var = (U8 *)alloc_mem (40);
do {
/* Parse all returned parameters. */
dat = http_get_var (dat, var, 40);
if (var[0] != 0) {
if (str_scomp (var, "TICK1=") == __TRUE || str_scomp (var, "pg=") == __TRUE)
{
if (str_scomp (var, "pg=") == __TRUE)
{
LEDControl = 0;
}
if(*(var+9) =='1')
{
LEDControl |= 0x01;
}
else if(*(var+9) =='2')
{
LEDControl |= 0x02;
}
else if(*(var+9) =='3')
{
LEDControl |= 0x04;
}
}
}
}while (dat);
free_mem ((OS_FRAME *)var);
if(LEDControl & 0x01)
{
bsp_LedOn(1);
}
else
{
bsp_LedOff(1);
}
if(LEDControl & 0x02)
{
bsp_LedOn(2);
}
else
{
bsp_LedOff(2);
}
if(LEDControl & 0x04)
{
bsp_LedOn(3);
}
else
{
bsp_LedOff(3);
}
}