亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? http.c

?? 這是新華龍(www.xhl.xom.xn)開發(fā)的
?? C
字號:
//-----------------------------------------------------------------------------
// Copyright (c) 2002 Jim Brady
// Do not use commercially without author's permission
// Last revised August 2002
// Net HTTP.C
//
// This module is the Web Server
// It currently serves a html text page and a jpeg image, or handles
// a POST message to turn an LED on or off.
// The HTTP protocol specification is at http://www.w3.org/Protocols/ 
//-----------------------------------------------------------------------------
#include <string.h>
#include <stdlib.h>
#include <ctype.h>		// toupper
#include "C8051f.h"
#include "net.h"
#include "serial.h"  
#include "cksum.h"
#include "analog.h"
#include "ip.h"
#include "tcp.h"
#include "http.h"


// These structures keep track of connection information
extern CONNECTION xdata conxn[];
 
extern ULONG code my_ipaddr;
extern char xdata text[];
extern UINT idata cpu_temperature;
extern UINT idata air_temperature;
extern UINT idata cpu_voltage;
extern char code html_header[];
extern char code web_page[];
extern char code jpeg_header[];
extern UCHAR code photo1_jpeg[];
extern UCHAR idata rcve_buf_allocated;
extern UCHAR idata debug;
bit CONTROL_LED;
void LightONOFF(bit b);

void init_http(void)
{
  CONTROL_LED = 0;
  LightONOFF(CONTROL_LED);
}



//------------------------------------------------------------------------
// This function is the standard string search. The Keil library
// does not provide it.  It looks for one string in another string
// and returns a pointer to it if found, otherwise returns NULL. 
//------------------------------------------------------------------------
char * strstr(char * haystack, char * needle)
{
	char *ptr1, *ptr2;
	
	// Protect against NULL pointer
	if (*needle == 0) return(haystack);
	for( ; *haystack; haystack++ )
	{
		// Look for needle in haystack.  If there is a
      // match then this will continue all the way
      // until ptr1 reaches the NULL at the end of needle 
		for(ptr1 = needle, ptr2 = haystack; *ptr1 && (*ptr1 == *ptr2); ++ptr1, ++ptr2);
							
		// If there is a match then return pointer to needle in haystack
		if(*ptr1 == 0) return(haystack);	
	}
	return NULL;			// no matching string found
}



//------------------------------------------------------------------------
// This sends an TCP segment to the ip layer.  The segment is 
// is normally either a web page or a graphic.
// See "TCP/IP Illustrated, Volume 1" Sect 17.3
//------------------------------------------------------------------------
void http_send(UCHAR xdata * outbuf, UINT len, UCHAR nr)
{
   TCP_HEADER xdata * tcp;
   IP_HEADER xdata * ip;
   ULONG idata sum;
   UINT idata result;
          
   // Fill in TCP segment header
   tcp = (TCP_HEADER xdata *)(outbuf + 34);
   ip = (IP_HEADER xdata *)(outbuf + 14);

   tcp->source_port = HTTP_PORT;
   tcp->dest_port = conxn[nr].port;
   tcp->sequence = conxn[nr].my_sequence;
   tcp->ack_number = conxn[nr].his_sequence;
      
	// Header is always 20 bytes long
   tcp->flags = 0x5000 | FLG_ACK | FLG_PSH;
   tcp->window = 1024;
   tcp->checksum = 0;
   tcp->urgent_ptr = 0;
   
   // Compute checksum including 12 bytes of pseudoheader
	// Must pre-fill 2 items in ip header to do this
	ip->dest_ipaddr = conxn[nr].ipaddr;
	ip->source_ipaddr = my_ipaddr;
		
	// Sum source_ipaddr, dest_ipaddr, and entire TCP message 
	sum = (ULONG)cksum(outbuf + 26, 8 + len);
				
	// Add in the rest of pseudoheader which is
	// protocol id and TCP segment length
	sum += (ULONG)0x0006;
	sum += (ULONG)len;

	// In case there was a carry, add it back around
	result = (UINT)(sum + (sum >> 16));
	tcp->checksum = ~result;
   
   if (debug) serial_send("TCP: Sending msg to IP layer\r");
	ip_send(outbuf, conxn[nr].ipaddr, TCP_TYPE, len);

   // (Re)start TCP retransmit timer
   conxn[nr].timer = TCP_TIMEOUT;
}



//------------------------------------------------------------------------
// This searches a web page looking for a specified tag.  If found,
// it replaces the tag with the text in * sub.  Tags are fixed length -
// The first 4 chars of the tag is always "TAG:" and the rest of it
// is always 4 chars for a total of 8 chars. 
//------------------------------------------------------------------------
void replace_tag(UCHAR xdata * start, char * tag, char * sub) 
{ 
   UCHAR idata i, flg;
   UCHAR xdata * ptr;
   
   // Find tag.  If not found - just return
   ptr = strstr(start, tag);
	if (ptr == NULL) return;
   
	flg = TRUE;

   // Replace the 8 char tag with the substitute text
	// Pad on the right with spaces
   for (i=0; i < 8; i++)
	{
   	if (sub[i] == 0) flg = FALSE;
   	if (flg) ptr[i] = sub[i]; else ptr[i] = SPACE;
	}
}



//------------------------------------------------------------------------
//	This serves up either a HTML page, a JPEG image, or controls an 
// LED,  depending what it gets from the browser.  The received header
// must contain the word "GET" or "POST" to be considered a valid request.
// With HTTP 1.1 where the connection is left open, the header I send
// should include content length. With HTTP 1.0 you can just close the
// connection after sending the page and the browser knows its done. 
//
// The HTTP protocol specification is at http://www.w3.org/Protocols/ 
//------------------------------------------------------------------------
UINT http_server(UCHAR xdata * inbuf, UINT header_len, UCHAR nr, UCHAR resend)
{
	UCHAR i;
	UINT idata body_len, hhdr_len, jhdr_len, page_len, jpeg_len;
	UINT idata sent, remaining;
	UCHAR xdata * outbuf;
	UCHAR xdata * ptr;
	UCHAR xdata * tcp_data;
	UCHAR idata request;
   static UCHAR idata post_flg = FALSE;
		    	
	// Make sure this is a valid connection
	if (nr == NO_CONNECTION) return 0;
	
	// Compute start of TCP data
   
   // Save first 20 chars and seq number just in case
   // we need to re-generate page
   // TODO: if post, then save switch state infomation
   if (!resend)
   {
      tcp_data = inbuf + 34 + header_len;
      memcpy(conxn[nr].query, tcp_data, 20);
      conxn[nr].old_sequence = conxn[nr].my_sequence;
   }
   // If this is a resend, set sequence number to what it was
   // the last time we sent this
   else
   {
      tcp_data = inbuf;
      conxn[nr].my_sequence = conxn[nr].old_sequence;   
   }
   
   // Start off with no request
   request = NONE;
      
	// TODO: Calling strstr() on a large buffer takes a lot of time
   // so perhaps we could speed things up by limiting the search
   // range to the portion of the buffer where the item is expected
   // to be found
	
	// If it is a POST, then set a flag to start looking for the post
	// data of interest, which is the string "switch=".  It may arrive
	// in a later segment (Netscape seems to split up the POST message)
   if (strstr(tcp_data, "POST") != NULL) post_flg = TRUE; 
	   
   // See if this is a GET message
   else if (strstr(tcp_data, "GET") != NULL)
   {
      post_flg = FALSE;
      if (strstr(tcp_data, "photo1") != NULL) request = GET_JPEG;
      else if (strstr(tcp_data, "index") != NULL) request = GET_PAGE;
      else if (strstr(tcp_data, "/ ") != NULL) request = GET_PAGE;
   }
   
   // If POST flag is "armed" then look for the "switch=" string
   // and if found, turn the LED on or off according to whether 
   // the browser is sending a 1 or a 0.
   if (post_flg)
   {
      ptr = strstr(tcp_data, "switch=");
      if (ptr != NULL)
      {
         // Move to space after equals sign
         // Set control indicator accordingly
         post_flg = FALSE;
         request = POST_PAGE;
         ptr += 7;
         if (*ptr == '1') {CONTROL_LED=0x0;}   
         else if (*ptr == '0') {CONTROL_LED=0x1;}
		 LightONOFF(CONTROL_LED);
      }
   }

   if ((request == GET_PAGE) || (request == POST_PAGE))
   {
      // Figure out sizes
      hhdr_len = strlen(html_header);
      page_len = strlen(web_page);
      body_len = hhdr_len + page_len;
      
      // Free memory holding received message.  The message from the
      // browser can be 500+ bytes long so this is a significant 
      // chunk out of the available malloc space of 1500 bytes
      if (!resend) {free(inbuf); rcve_buf_allocated = FALSE;}

      // Allocate memory for entire outgoing message including
      // 14 byte Ethernet + 20 byte IP + 20 byte TCP headers
      // Allow 1 byte for NULL char at the end
      outbuf = (UCHAR xdata *)malloc(54 + body_len + 1);
      if (outbuf == NULL)
      {
         if (debug) serial_send("TCP: Oops, out of memory\r");
         return 0;
      }
      
      // Copy page data.  This moves data from flash into RAM.  It is
      // an undesirable process, but must get data into RAM to replace
      // tags 
		memcpy(outbuf + 54, html_header, hhdr_len);
		memcpy(outbuf + 54 + hhdr_len, web_page, page_len);
   	   	   	
   	outbuf[54 + body_len] = 0;		// Append NULL 
   
      // Replace length tag with actual value
       itoa(page_len, text, 10);
		replace_tag(outbuf + 54, "TAG:LEN1", text);
		
		// Replace CPU temperature tag with actual value
		itoa(cpu_temperature/100, text, 10);
		i=strlen(text);
		text[i]='.';
		i++;
		itoa(cpu_temperature%100, text+i, 11);
		replace_tag(outbuf + 54, "TAG:TMP1", text);

		itoa(air_temperature/100, text, 10);
		i=strlen(text);
		text[i]='.';
		i++;
		itoa(air_temperature%100, text+i, 11);
		replace_tag(outbuf + 54, "TAG:TMP2", text);

		// Replace CPU voltage tag with actual value X 100
		// Insert decimal point between first and second digits
		itoa(cpu_voltage/100, text, 10);
		i=strlen(text);
		text[i]='.';
		i++;
		itoa(cpu_voltage%100, text+i, 11);
		replace_tag(outbuf + 54, "TAG:VOL1", text);
      
      // Insert the word CHECKED into the html so the browser will
		// check the correct LED state indicator box 
      if (CONTROL_LED == OFF) replace_tag(outbuf + 54, "TAG:CHK1", "CHECKED");
      else replace_tag(outbuf + 54, "TAG:CHK2", "CHECKED");
      
      // Segment length = body_len + 20
      http_send(outbuf, body_len + 20, nr);
      conxn[nr].my_sequence += body_len;
   }
   else if (request == GET_JPEG)
   {
      // Ths browser has requested the jpeg image.  First figure out
      // sizes - cannot use sizeof() for jpeg here because it is in
      // another module.  Just directly specify length of it
      jhdr_len = strlen(jpeg_header);
      jpeg_len = 5705;//6194;
      body_len = jhdr_len + jpeg_len;
      
      // Free memory holding received message.  The message from the
      // browser can be 500+ bytes long so this is a significant 
      // chunk out of the available malloc space of 1500 bytes
      if (!resend) {free(inbuf); rcve_buf_allocated = FALSE;}

      // First send the header and enough of the jpeg to make 1000 bytes.
      // The value of 1000 is arbitrary, but must be stay under 1500. 
      if (body_len < 1000) remaining = body_len; else remaining = 1000; 
      outbuf = (UCHAR xdata *)malloc(54 + remaining + 1);
      if (outbuf == NULL)
      {
         if (debug) serial_send("TCP: Oops, out of memory\r");
         return 0;
      }
      
      memcpy(outbuf + 54, jpeg_header, jhdr_len);
		memcpy(outbuf + 54 + jhdr_len, photo1_jpeg, remaining - jhdr_len);
                  
      outbuf[54 + remaining] = 0;		// Append NULL

      // Replace jpeg length tag with actual value
      itoa(jpeg_len, text, 10);
		replace_tag(outbuf + 54, "TAG:LEN2", text);

      http_send(outbuf, remaining + 20, nr);
      sent = remaining - jhdr_len;
      conxn[nr].my_sequence += remaining;
     
      // Send the rest of the jpeg file in 1000 byte chunks.  This sends about
      // 6 segments of 1000 bytes back to back, but we should actually process
      // acks from the other end to make sure we are not sending more than the
      // other end can receive.  Most systems can handle 6K
      while (sent < jpeg_len)
      {
         remaining = jpeg_len - sent;
         if (remaining > 1000) remaining = 1000;
         outbuf = (UCHAR xdata *)malloc(54 + remaining + 1);
         if (outbuf == NULL)
         {
            if (debug) serial_send("TCP: Oops, out of memory\r");
            return 0;
         }
         
         memcpy(outbuf + 54, photo1_jpeg + sent, remaining);
                           
         outbuf[54 + remaining] = 0;		// Append NULL
         http_send(outbuf, remaining + 20, nr);
         sent += remaining;
         conxn[nr].my_sequence += remaining;
      }
   }
   else
   {
      // The incoming HTTP message did not warrant a response
      if (debug) serial_send("HTTP: No response sent\r");
      return 0;
   }
   
   // Return number of bytes sent, not including TCP header
	return(body_len);
}





?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产一区不卡在线| 久久久久久久久久美女| 国产精品一区二区久久精品爱涩 | 九九精品一区二区| 中文字幕一区二区三| 91精品国产高清一区二区三区| 成人网男人的天堂| 日韩av电影免费观看高清完整版 | 99久久精品99国产精品| 免费精品视频在线| 亚洲国产美女搞黄色| 国产精品不卡视频| 26uuu国产日韩综合| 欧美日产在线观看| 91麻豆国产自产在线观看| 国产呦精品一区二区三区网站| 亚洲成人av中文| 亚洲免费在线观看| 国产精品国产精品国产专区不蜜 | 精品久久久久av影院 | 欧美丰满嫩嫩电影| 在线观看中文字幕不卡| jlzzjlzz亚洲日本少妇| 国产麻豆视频精品| 九九视频精品免费| 另类人妖一区二区av| 午夜精品福利久久久| 夜夜精品视频一区二区| 国产精品萝li| 中文字幕欧美三区| 国产日韩在线不卡| 久久精品日产第一区二区三区高清版| 日韩一级二级三级精品视频| 欧美久久一区二区| 6080午夜不卡| 日韩一区二区三区电影在线观看 | 欧美激情中文不卡| 久久午夜电影网| 久久婷婷成人综合色| 久久久亚洲综合| 久久毛片高清国产| 国产欧美日韩另类一区| 国产欧美日韩另类一区| 国产精品乱码人人做人人爱| 中文在线资源观看网站视频免费不卡| 日本一区二区三区国色天香| 久久精品亚洲一区二区三区浴池| 久久先锋资源网| 国产欧美精品一区| 亚洲婷婷综合色高清在线| 亚洲婷婷综合色高清在线| 亚洲理论在线观看| 亚洲午夜免费电影| 免费在线观看视频一区| 久久99热这里只有精品| 国产成人午夜精品影院观看视频| 欧美视频在线播放| 日韩午夜av电影| 久久视频一区二区| 一区视频在线播放| 一区二区三区日韩欧美| 日韩国产欧美一区二区三区| 久久99精品网久久| 99精品一区二区三区| 欧美日韩一区二区三区四区| 欧美一级xxx| 欧美激情在线一区二区| 中文字幕亚洲在| 天天做天天摸天天爽国产一区| 久久精品国产亚洲一区二区三区| 国产一区二区三区在线观看精品| 波多野结衣中文字幕一区| 欧美综合亚洲图片综合区| 91精品国产综合久久久久久漫画| 欧美精品一区二区蜜臀亚洲| 国产精品久久久久久久久久免费看 | 欧美成人猛片aaaaaaa| 欧美国产一区在线| 亚洲国产毛片aaaaa无费看| 韩国精品久久久| 色综合 综合色| 精品国产乱码久久久久久闺蜜| 国产精品另类一区| 青娱乐精品视频| av高清久久久| 欧美成人r级一区二区三区| 自拍偷拍欧美精品| 国产精品一区二区三区四区 | 国产激情视频一区二区在线观看| 91在线porny国产在线看| 日韩一区二区高清| 亚洲天天做日日做天天谢日日欢| 亚洲1区2区3区4区| 成人av网址在线| 欧美一级理论片| 亚洲激情中文1区| 国产一区二区精品久久91| 欧美日韩一区二区三区四区| 中文字幕第一区二区| 日韩福利电影在线| 91老师片黄在线观看| 精品va天堂亚洲国产| 亚洲va欧美va天堂v国产综合| 国产盗摄视频一区二区三区| 337p亚洲精品色噜噜| 日韩毛片精品高清免费| 国产精品一二三| 91精品国产福利在线观看| 一区二区久久久久久| 成人福利视频在线看| 精品国产一区二区三区久久影院| 亚洲午夜免费电影| 99精品视频中文字幕| 久久久久久久免费视频了| 日韩av中文字幕一区二区| 色久综合一二码| 国产精品久久久久久久久免费丝袜| 国内精品国产成人| 日韩欧美久久久| 日韩制服丝袜先锋影音| 欧美写真视频网站| 亚洲黄色av一区| 色综合久久综合网欧美综合网| 国产人久久人人人人爽| 国产剧情一区二区| 精品99一区二区| 狠狠色丁香婷婷综合久久片| 日韩欧美一级二级| 奇米影视在线99精品| 91精品国产手机| 日韩高清不卡在线| 欧美二区三区的天堂| 日韩精品每日更新| 91精品在线一区二区| 日本大胆欧美人术艺术动态| 欧美精品久久天天躁| 日韩精品一级二级| 91精品麻豆日日躁夜夜躁| 日日骚欧美日韩| 日韩一区二区三区电影在线观看| 日本不卡一二三区黄网| 日韩精品资源二区在线| 久草中文综合在线| 久久久www免费人成精品| 国产成人精品免费看| 国产精品久久久久久久久免费樱桃 | 在线不卡欧美精品一区二区三区| 亚洲超碰97人人做人人爱| 欧美精品视频www在线观看| 免费日韩伦理电影| 久久一日本道色综合| proumb性欧美在线观看| 一区二区国产视频| 911国产精品| 久久99久久精品| 国产女同性恋一区二区| 99re这里只有精品视频首页| 一区二区三区日韩欧美精品| 91精品国产综合久久久久久| 久久99国产精品尤物| 欧美韩日一区二区三区四区| 色中色一区二区| av电影天堂一区二区在线观看| 亚洲精品视频自拍| 91精品国产综合久久久久久久 | 色88888久久久久久影院野外| 亚洲综合一区二区三区| 欧美一区二区不卡视频| 国产一区在线精品| 亚洲人123区| 欧美一级高清片| 99综合影院在线| 日韩精品亚洲一区二区三区免费| 日韩欧美电影一二三| 9色porny自拍视频一区二区| 丝袜美腿亚洲一区二区图片| 国产婷婷一区二区| 91国偷自产一区二区使用方法| 久热成人在线视频| 亚洲丝袜精品丝袜在线| 欧美成人一区二区三区在线观看| 不卡视频一二三| 麻豆精品在线观看| 亚洲激情网站免费观看| 亚洲精品在线免费播放| 一本高清dvd不卡在线观看| 久久99精品久久久久久国产越南| 亚洲天堂2016| 精品国产一区a| 欧洲精品中文字幕| 国产成人午夜高潮毛片| 日本大胆欧美人术艺术动态| 亚洲婷婷综合色高清在线| 久久综合五月天婷婷伊人| 欧美视频精品在线| 成人动漫在线一区| 精久久久久久久久久久| 亚洲超碰精品一区二区| 亚洲欧洲av另类| 久久精品视频免费观看|