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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? http.c

?? 工業以太網測控用戶系統
?? 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一区二区三区免费野_久草精品视频
亚洲一卡二卡三卡四卡| 色婷婷综合久久久中文字幕| eeuss鲁片一区二区三区| 欧美日韩第一区日日骚| 国产午夜精品美女毛片视频| 亚洲不卡在线观看| 99精品1区2区| 中文字幕欧美三区| 精品午夜一区二区三区在线观看| 欧美午夜影院一区| 亚洲精品一二三| 99r国产精品| 欧美国产日本视频| 国产精品一级片| 久久综合九色综合97婷婷| 视频一区免费在线观看| 欧美亚洲自拍偷拍| 亚洲伦理在线免费看| 99久久精品免费观看| 国产精品美女一区二区| 大美女一区二区三区| 久久精品日韩一区二区三区| 久久99精品久久久| 精品国产乱码久久久久久1区2区| 日av在线不卡| 日韩精品中文字幕在线不卡尤物 | 欧美在线不卡一区| 国产精品白丝在线| 成人h动漫精品一区二| 国产色产综合色产在线视频| 国产99久久久精品| 国产色产综合产在线视频| 国产一区二区三区不卡在线观看 | 紧缚捆绑精品一区二区| 日韩一区二区三区观看| 免费观看久久久4p| 精品欧美乱码久久久久久| 久久99在线观看| 日韩欧美国产午夜精品| 国产美女主播视频一区| 欧美激情一区二区三区蜜桃视频| 成人av综合在线| 亚洲三级免费观看| 欧美三电影在线| 免费在线观看日韩欧美| 久久综合久久综合九色| eeuss鲁一区二区三区| 一区二区理论电影在线观看| 欧美日韩一区三区四区| 久久激情五月激情| 亚洲国产成人自拍| 欧美日韩在线三级| 久久99国产精品免费网站| 国产日韩欧美高清| 欧美在线制服丝袜| 久久精品国产网站| 亚洲欧洲成人精品av97| 欧美日韩在线播放三区| 韩国三级在线一区| 亚洲免费观看高清完整版在线观看熊 | 欧美日韩激情在线| 国产一区二区三区免费在线观看| 国产精品久久久久精k8 | 久久综合九色综合久久久精品综合| 国产二区国产一区在线观看| 亚洲精品视频一区| 日韩精品一区在线观看| 不卡电影一区二区三区| 日本亚洲最大的色成网站www| 日本一区二区三区在线不卡| 欧美三片在线视频观看| 国产一区二区三区精品欧美日韩一区二区三区 | 日韩欧美一区二区视频| 99国产一区二区三精品乱码| 裸体在线国模精品偷拍| 久久精品国产精品亚洲红杏| 国产日韩欧美综合在线| 欧美高清视频不卡网| 丁香婷婷深情五月亚洲| 日本亚洲欧美天堂免费| 中文字幕在线不卡一区二区三区| 欧美一区二区三区视频| 色哟哟国产精品| 国产激情精品久久久第一区二区| 亚洲成人tv网| 亚洲三级电影网站| 久久一留热品黄| 777久久久精品| 色老汉一区二区三区| 国产精品中文字幕欧美| 老汉av免费一区二区三区| 亚洲高清视频的网址| 亚洲人精品一区| 国产精品乱子久久久久| 国产亚洲午夜高清国产拍精品| 欧美日韩欧美一区二区| 色悠久久久久综合欧美99| 国产不卡一区视频| 国产一区福利在线| 精品一区二区精品| 奇米四色…亚洲| 一区二区三区欧美在线观看| 中文av一区二区| 国产视频一区在线观看| 日韩精品中文字幕一区 | 91成人在线精品| 99国产精品久久久久久久久久| 国产一区二区美女诱惑| 蜜桃视频在线一区| 久久99久久久欧美国产| 麻豆免费精品视频| 日产精品久久久久久久性色| 亚洲韩国一区二区三区| 亚洲国产视频网站| 性做久久久久久久久| 亚洲va国产天堂va久久en| 亚洲国产日韩一区二区| 亚洲高清一区二区三区| 五月天国产精品| 美女诱惑一区二区| 久久国产精品99久久人人澡| 国内精品国产成人| 国产99久久精品| 99国产精品99久久久久久| 一本色道久久综合精品竹菊| 欧美自拍偷拍午夜视频| 在线播放国产精品二区一二区四区| 欧美日韩一区二区在线观看| 欧美一区二区二区| 久久久www免费人成精品| 国产欧美日韩精品在线| 1区2区3区精品视频| 亚洲一二三四久久| 免费视频一区二区| 国产91富婆露脸刺激对白| 91在线无精精品入口| 欧美色手机在线观看| 欧美一区二区三区喷汁尤物| 久久久噜噜噜久久人人看| 亚洲色图另类专区| 日日摸夜夜添夜夜添精品视频| 精品一区二区三区免费视频| 成人影视亚洲图片在线| 欧美影院精品一区| 26uuu国产在线精品一区二区| 亚洲综合免费观看高清完整版 | 亚洲女与黑人做爰| 日韩国产在线观看| 成人免费视频国产在线观看| 91官网在线观看| 久久久久免费观看| 亚洲午夜久久久久久久久电影院| 奇米色777欧美一区二区| 成人免费高清视频| 欧美日韩免费视频| 欧美极品少妇xxxxⅹ高跟鞋| 午夜影院久久久| 国产成人午夜高潮毛片| 精品视频在线免费观看| 久久精品视频一区| 日韩精品国产精品| 97se狠狠狠综合亚洲狠狠| 欧美一区二区久久久| 一区精品在线播放| 国产一区二区三区蝌蚪| 欧美日本免费一区二区三区| 国产精品视频麻豆| 精品一区二区三区影院在线午夜| 色乱码一区二区三区88| 久久这里都是精品| 亚洲444eee在线观看| 成人av午夜电影| 精品国产乱码久久久久久老虎| 亚洲六月丁香色婷婷综合久久 | 久久se精品一区二区| 欧美在线一区二区三区| 中文字幕亚洲欧美在线不卡| 久久国产尿小便嘘嘘| 欧美色视频在线| 一区二区在线观看av| av在线一区二区三区| 国产亚洲综合av| 国内精品嫩模私拍在线| 日韩欧美中文一区二区| 亚洲欧美aⅴ...| 91蜜桃婷婷狠狠久久综合9色| 国产亚洲欧美激情| 国产精品资源在线看| 精品国产乱码久久久久久图片| 午夜精品一区在线观看| 91福利精品第一导航| 亚洲欧美偷拍三级| 91蜜桃免费观看视频| 国产精品美女久久久久久久久久久| 国产精品一区二区三区网站| 精品人伦一区二区色婷婷| 美女视频网站久久| 日韩欧美一区二区免费| 国产一区二区三区综合| 久久精品人人爽人人爽|