📄 web.c
字号:
/*=========================================================================
* Filename: web.c
* Function Description: Deal with WEB webpage data.
* Author: Gong Zhigang
* Date: 2004/03/10
* Email: zhigang@sunnorth.com.cn
*
*========================================================================*/
#include "config.h"
#include "httpd.h"
#include "web.h"
#include "fs.h"
char s_open[] = "@开";
char s_close[] = "@关";
u16_t status[3] = {0,0,0};
#define AIR 0
#define LIGHT 1
#define MUSIC 2
struct webdata *Web_Request(char *req)
{
struct fs_file file;
char *tempstr = req;
struct webdata *tempweb,*retweb;
u16_t cur_dev = 0,device;
u16_t opt,oprate;
if (!(strcmp(tempstr, "/index.html") && strcmp(tempstr, "/"))) //特殊页面,从一个静态页面转向动态
{
tempstr += strlen(tempstr) + 1; //并且要
if (!strcmp(tempstr,"PD"))
{
tempstr += strlen(tempstr)+1;
if (!strcmp(tempstr,"123456"))
{
fs_open("/opt.html", &file);
retweb = Web_Init(&file,1);
goto init0;
}
else
{
fs_open("/err.htm",&file);
retweb = Web_Init(&file,0);//初始化页面,不需要动态
}
return(retweb);
}
else if('H' == *tempstr) //HTTP
{
fs_open("/index.html",&file);
return(Web_Init(&file,0));
}
else
{
fs_open("/invalid.htm",&file);
return(Web_Init(&file,0));
}
}
else if(!strcmp(tempstr, "/opt.html")) //动态页面
{
fs_open("/opt.html", &file);
retweb = Web_Init(&file,1);
tempstr += strlen(tempstr)+1;
opt = StrToInt(tempstr);
if (opt%2) oprate = (u16_t)s_close[0];
else oprate = (u16_t)s_open[0];
switch (opt)
{
case 10: ;
case 11:device = AIR; break;
case 12: ;
case 13:device = LIGHT; break;
case 14: ;
case 15:device = MUSIC; break;
}
status[device] = oprate;
init0:
for(tempweb = retweb ; tempweb!=NULL; tempweb = tempweb->next)
{
if (tempweb->attr == DYNAMIC) //进入动态网页区域
{
if (status[cur_dev]!=0)
tempweb->payload[0] = status[cur_dev];
else tempweb->payload[0] = (u16_t)s_close[0];
tempweb->len = 2;
cur_dev++; // 记录第几块动态区域
}
}//end of for
return(retweb);
}
else
{
fs_open(tempstr,&file);
if( file.data == NULL)
fs_open("/404.html", &file);
return(Web_Init(&file,0));
}
return(NULL); //never be here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -