[mw_shl_code=c,true]上面的大神的部分分析
if(s->inputbuf[1] == ISO_space) { //如果是空格符就把index_html作为输出页
strncpy(s->filename, http_index_html, sizeof(s->filename));
} else {
s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0; //否则将后面的字符作为输出页
strncpy(s->filename, &s->inputbuf[0], sizeof(s->filename));
} [/mw_shl_code]
以下是原子哥的部分 ,原子哥的把原有的更改了。我不是太懂,是如何把浏览器的数据处理的,又是如何,把我们的数据处理后返回的
[mw_shl_code=c,true]if(s->inputbuf[1] == ISO_space||s->inputbuf[1] == '?') //第二个数据是空格/问号
{
if(s->inputbuf[1]=='?'&&s->inputbuf[6]==0x31)//LED1
{
LED0=!LED0;
strx=strstr((const char*)(data_index_html+13),"LED0状态");
if(strx)//存在"LED0状态"这个字符串
{
strx=strstr((const char*)strx,"color:#");//找到"color:#"字符串
if(LED0)//LED0灭
{
strncpy(strx+7,"5B5B5B",6); //灰色
strncpy(strx+24,"灭",2); //灭
strx=strstr((const char*)strx,"http:");//找到"http:"字符串
strncpy(strx,(const char*)LED_OFF_PIC_ADDR,strlen((const char*)LED_OFF_PIC_ADDR));//LED0灭图片
}else
{
strncpy(strx+7,"FF0000",6); //红色
strncpy(strx+24,"亮",2); //"亮"
strx=strstr((const char*)strx,"http:");//找到"http:"字符串
strncpy(strx,(const char*)LED0_ON_PIC_ADDR,strlen((const char*)LED0_ON_PIC_ADDR));//LED0亮图片
}
}
}else if(s->inputbuf[1]=='?'&&s->inputbuf[6]==0x32)//LED2
{
LED1=!LED1;
strx=strstr((const char*)(data_index_html+13),"LED1状态");
if(strx)//存在"LED1状态"这个字符串
{
strx=strstr((const char*)strx,"color:#");//找到"color:#"字符串
if(LED1)//LED1灭
{
strncpy(strx+7,"5B5B5B",6); //灰色
strncpy(strx+24,"灭",2); //灭
strx=strstr((const char*)strx,"http:");//找到"http:"字符串
strncpy(strx,(const char*)LED_OFF_PIC_ADDR,strlen((const char*)LED_OFF_PIC_ADDR));//LED1灭图片
}else
{
strncpy(strx+7,"00FF00",6); //绿色
strncpy(strx+24,"亮",2); //"亮"
strx=strstr((const char*)strx,"http:");//找到"http:"字符串
strncpy(strx,(const char*)LED1_ON_PIC_ADDR,strlen((const char*)LED1_ON_PIC_ADDR));//LED1亮图片
}
}
}
strx=strstr((const char*)(data_index_html+13),"℃");//找到"℃"字符
if(strx)
{
get_temperature(dbuf); //得到温度
strncpy(strx-4,(const char*)dbuf,4); //更新温度
}
strx=strstr((const char*)strx,"RTC时间:");//找到"RTC时间:"字符
if(strx)
{
get_time(dbuf); //得到时间
strncpy(strx+33,(const char*)dbuf,16); //更新时间
}
strncpy(s->filename, http_index_html, sizeof(s->filename));
}else //如果不是' '/'?'
{
s->inputbuf[PSOCK_DATALEN(&s->sin)-1] = 0;
strncpy(s->filename,&s->inputbuf[0],sizeof(s->filename));
} [/mw_shl_code]
|