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

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

?? nedk_example_web_server.c

?? 包括基于Cyclone1C20芯片NiosII軟件開發的各種模塊的測試例子
?? C
?? 第 1 頁 / 共 2 頁
字號:
// file: nedk_web_server.c
//
// This is a very simple web server
// that can be modified to include
// several kinds of pages in a "wosfs"
// file directory. (File structure
// smashed into flash memory, immutable.)
//
// dvb@altera.com 2002
//
// ex:set tabstop=4:
//

#include "excalibur.h"
#include "plugs.h"
#include "wosfs.h"
#include "plugs_example_designs.h"


#define k_http_port 80
#define k_string_length 256

#define k_tcp_timeout 5000 // milliseconds

typedef struct
	{
	int tcp_plug_handle;
	int inquiry_number;
	int button_presses[4];

	long tcp_opened_time; // So we can time out the connection
	                      // in case of a dangled-open connect.
	} globals;

static globals g; // (starts life as zeroes of course)

// +---------------------------------
// | prototypes

static int r_handle_http_request(int plug_handle,unsigned char *message, int message_length);
static void r_get_cgi_param(char *url_and_args,char *parameter, char *value_out);
static void r_set_7_pattern(int control);
static void r_increment_button_counts(void);
static char *r_printable_string(char *s);
static int r_get_html_from_wosfs(char *url,char *html_out,int *html_length_out);
static int r_get_html_404(char *url,char *html_out);
static int r_substitute_string(char *fmt,char *s);
static int r_get_html_dynamically(char *url,char *url_and_args,char *html_out);

static int r_tcp_proc(int plug_handle,
		void *context,
		ns_plugs_packet *p,
		void *payload,
		int payload_length);

static int r_listen_proc(int plug_handle,
		void *context,
		host_32 remote_ip_address,
		host_16 remote_port);

static int r_start_listening(void);

// +---------------------------------
// | meat



int main(void)
	{
	int result;

	printf("[Xnedk_example_web_server] starting\n");

	// |
	// | Initialize the plugs library
	// |
	//
	result = nr_plugs_initialize
			(
			0, 0,
			__adapter__,
			__adapter_irq__,
			__adapter_struct_addr__
			);

	if(result)
		goto error_exit;

	// |
	// | Print the IP address we're using
	// |
		{
		ns_plugs_network_settings settings;

		result = nr_plugs_get_settings(0,&settings);

		printf("[nedk_example_web_server] IP address = ");
		nr_plugs_print_ip_address(settings.ip_address);
		printf("\n");
		}

	result = nr_plugs_create
			(
			&g.tcp_plug_handle, // | Plug to create
			ne_plugs_tcp,       // | Kind of plug (tcp connection)
			k_http_port,        // | Port to listen on
			r_tcp_proc,         // | To call with incoming data
			0,                  // | Context for plug callback
			0                   // | Flags for plug (none)
			);
	if(result)
		goto error_exit;

	// |
	// | Accept incoming connections
	// |

	result = r_start_listening();
	if(result)
		goto error_exit;
	
	// |
	// | Main loop: spin through here forever
	// | All this application does is serve
	// | web pages and blink the 7-segment
	// | display a little. If there were other tasks
	// | to do, like operating your factory
	// | equipment or something, you could
	// | have it running here in this main
	// | event loop (if timing weren't important),
	// | or as a timer task.
	// |

	while(1)
		{
		nr_plugs_idle();
		r_set_7_pattern(0);

		// |
		// | Check if tcp connection's been opened too long
		// |

		if( g.tcp_opened_time
				&& ((nr_timer_milliseconds() - g.tcp_opened_time) > k_tcp_timeout) )
			{
			char *s = "nedk_web_server: Connection timing out. Bye.\n";
			result = nr_plugs_send(g.tcp_plug_handle,s,strlen(s),0);
			result = r_start_listening();
			}
		}
	
	// |
	// | Only get here on an error condition...
	// |

error_exit:
	nr_plugs_print_error_message("[nedk_example_web_server]", result);
	return result;
	}

// +--------------------------------------
// | r_set_7_pattern
// |
// | Advance the little blinky-pattern that
// | moves around the 7-segment display
// |
// | Control Values
// |  0 advance tick
// |  1 all segments on
// |

#define k_7_time 80 // mSec between frames
static void r_set_7_pattern(int control)
	{
	long x;
	static long last_time = 0;
	static long current_step = 0;
	static long d_pattern[] =  // 8 steps in the pattern
		{
		0xffffffbf, 0xffffffdf, 0xffffffef, 0xfffffff7,  // outer edge
		0xfffff7ff, 0xfffffbff, 0xfffffdff, 0xffffbfff,
		};
	
	x = nr_timer_milliseconds();
	if(x - last_time > k_7_time)
		{
		// |
		// | Time enough to update the LED?
		// |

		last_time = x;

		current_step = (current_step + 1) & 7;
		}

	if(control == 1)
		x = 0;
	else
		x = d_pattern[current_step];

	na_seven_seg_pio->np_piodirection = 0xffff;
	na_seven_seg_pio->np_piodata = x;
	}


// +----------------------------------
// | r_start_listening
// |
// | This routine closes the current tcp
// | connection (if any) and starts listening
// | again.
// |

static int r_start_listening(void)
	{
	int result;

	printf("\nlistening on port %d at t = %8d\n",k_http_port,nr_timer_milliseconds() );

	result = nr_plugs_listen(g.tcp_plug_handle,r_listen_proc,0);
	g.tcp_opened_time = 0; // so it looks like we're "closed"

	return result;
	}


// +----------------------------------
// | r_listen_proc
// |
// | This is a plugs listener callback proc.
// | It gets called when a remote client
// | requests a connection. We always accept
// | the connection, but we do take the opportunity
// | to note the time of the connection. Then, in
// | the main loop, we see if the connection has
// | been left open too long, and maybe force it closed.

static int r_listen_proc(int plug_handle,
		void *context,
		host_32 remote_ip_address,
		host_16 remote_port)
	{

	g.tcp_opened_time = nr_timer_milliseconds();

	printf("[tcp_listen_proc] Accepted connection from ");
	nr_plugs_print_ip_address(nr_h2n32(remote_ip_address));
	printf(" port %d at t = %8d\n",remote_port,g.tcp_opened_time);

	return 0;
	}

// +----------------------------------
// | r_tcp_proc
// |
// | This is a plugs receive callback proc.
// | It gets called when a remote client connects
// | to our web server and sends a request. We
// | assume that the request arrives in a single
// | packet (or, at least, that the first line
// | of it, containing the URL, does).
// |
// | If the payload length is zero, this means
// | for a tcp_plug that the remote network device
// | has disconnected from us, and we listen for
// | the next connection.
// |


static int r_tcp_proc
		(
		int plug_handle,
		void *context,
		ns_plugs_packet *p,
		void *payload,
		int payload_length
		)
	{
	unsigned char *w;
	int i;
	int c;

	if(payload_length)
		{
		// |
		// | Incoming message, it must be a http request
		// | We let the http_server handle this request.
		// |
		
		r_handle_http_request(plug_handle,payload, payload_length);
		}
	else
		{
		// |
		// | Zero-length payload means "they disconnected",
		// | so, begin listening again on same port.
		// |

		r_start_listening();
		}

go_home:
	return 0;
	}

// +-------------------------------------------
// | r_handle_http_request(plug_handle, http_request, http_request_length)
// |
// | Actually, we just assume that the message
// | is, in fact, an HTTP request. An HTTP
// | request is of the form:
// |
// |    GET <url>[ <http-version>](CR)(LF)
// |
// | It may also continue with more information
// | on subsequent lines, each of the form:
// |
// |    <variable>: <value>
// |
// | And eventually ends with two CR-LF's.
// | But we ignore everything past the first
// | line here.
// |
// | To reply, we send a status line and 
// | a content-type, followed by to CRLF's and the HTML.
// |
// |    HTTP/1.1 200 OK
// |    Content-type: <content-type>
// |
// |    <HTML>
// |
// | The content type is either "text/html" or "image/gif".
// | We presume that if the content comes from WOSFS,
// | and the last letter of the filename is 'f', then it's
// | a GIF image.
// |

static int r_handle_http_request(int plug_handle,unsigned char *message, int message_length)
	{
	unsigned char *message_end;
	unsigned char *w;
	int i;
	int result = 0;
	char url_and_args[k_string_length];
	char url[k_string_length];
	int url_and_args_length;

	r_set_7_pattern(1); // | flash the 7-seg display

	++g.inquiry_number;

	message_end = message + message_length;
	w = message;

	// |
	// | Find the url_and_args portion of the packet, by looking for the
	// | first space (just after the word "GET").
	// |

	while(w < message_end && *w++ != ' ')
		;

	w = w + 1; // | omit the omnipresent leading slash
	url_and_args_length = 0;
	
	// |
	// | Copy the URL and any CGI arguments into url_and_args.
	// | look for the end of the URL and CGI parameters as a ' ' or crlf
	// |

	while(w < message_end && *w > ' ') // | break on blank or ctrl char
		url_and_args[url_and_args_length++] = *w++;

	url_and_args[url_and_args_length] = 0;  // | Terminate string

	// |
	// | Asking for the root of the server, "/", means
	// | they want "index.html".
	// |

	if(url_and_args_length == 0) // empty url?
		{
		strcpy(url_and_args,"index.html");
		url_and_args_length = strlen(url_and_args);
		}

	r_get_cgi_param(url_and_args,0,url); // null param = URL

printf("\n");
printf("[r_handle_http_request] url_and_args_length = %d\n", url_and_args_length);
printf("[r_handle_http_request] url_and_args = %s\n", url_and_args);
printf("[r_handle_http_request] url = \"%s\"\n",r_printable_string(url));

	// |
	// | We've extracted the url with arguments, and just the url
	// | by itself. We'll now look for a file, a dynamic page, or a 404 error.

		{
		char html_response[30000];
		int html_response_length = 0;
		char *http_result_code_and_message;
		char *http_content_type;
		int file_index;

		// |
		// | Default to 200 OK status, and check last char of URL for content type
		// |

		http_result_code_and_message = "200 OK";
		http_content_type = url[strlen(url) - 1] == 'f'
				? "image/gif" : "text/html";
		html_response[0] = 0;

		// |
		// | Try to get the file from wosfs
		// |

		result = r_get_html_from_wosfs(url,html_response,&html_response_length);

		// |
		// | If not wosfs, try dynamic
		// |

		if(result)
			result = r_get_html_dynamically(url,url_and_args,html_response);

		// |
		// | And if even that fails, call our
		// | error generation routine.
		// |
		
		if(result)
			{
			http_result_code_and_message = "404 File Not Found";
			http_content_type = "text/html";
			r_get_html_404(url,html_response);
			result = 0; // above routine not allowed to fail
			}


		// |
		// | If nobody filled out the html_response_length,
		// | get it as a string length.
		// |
		if(html_response_length == 0)
			html_response_length = strlen(html_response);

printf("[r_handle_http_request] sending %d bytes of html out.\n",html_response_length);
			

		// |
		// | Lastly, send the HTTP response.
		// | The plugs library will not automatically
		// | break up the packet into ethernet-legal
		// | chunks, so we do it here.
		// |

			{
			char http_intro[k_string_length];

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91国模大尺度私拍在线视频| 最新中文字幕一区二区三区 | 亚洲一区二区三区在线看| 久久夜色精品国产噜噜av| 日韩一级视频免费观看在线| 91麻豆精品国产91久久久使用方法| 中文字幕av在线一区二区三区| 欧美激情一区二区三区蜜桃视频| 91精品国产综合久久福利软件| 免费高清视频精品| 蜜臀99久久精品久久久久久软件| 天堂久久一区二区三区| 日本欧洲一区二区| 久久av中文字幕片| 成人三级伦理片| 91视频在线看| 欧美另类videos死尸| 91精品欧美综合在线观看最新| 91麻豆精品国产自产在线观看一区| 欧美一区二区三区不卡| 精品国产一区二区三区不卡| 国产日韩欧美亚洲| 亚洲精品国产一区二区精华液| 香蕉影视欧美成人| 精品中文字幕一区二区| 欧美亚洲一区二区三区四区| 91免费版在线| 精品一区二区三区在线播放| 日韩不卡一二三区| 国产九色精品成人porny| 99精品桃花视频在线观看| 欧美日韩精品专区| 久久女同精品一区二区| 亚洲欧美视频在线观看视频| 日韩高清不卡在线| 成人av影视在线观看| 欧美另类z0zxhd电影| 国产欧美视频一区二区三区| 午夜精品久久久久影视| 国产成人av福利| 在线一区二区观看| 久久综合网色—综合色88| 亚洲最新视频在线观看| 国产麻豆日韩欧美久久| 欧美亚洲综合一区| 国产精品免费丝袜| 麻豆精品久久久| 色爱区综合激月婷婷| 国产区在线观看成人精品 | 国产一区二三区| 欧美日韩激情一区二区三区| 亚洲欧洲国产专区| 韩国av一区二区| 51午夜精品国产| 一区二区免费看| 96av麻豆蜜桃一区二区| 久久久99精品免费观看| 丝袜美腿一区二区三区| 在线免费观看不卡av| 国产精品免费看片| 国产乱淫av一区二区三区| 日韩一区二区视频| 日本亚洲三级在线| 91精品国产91热久久久做人人 | 欧美精品视频www在线观看 | 久久97超碰色| 日韩欧美一区中文| 午夜一区二区三区在线观看| 色视频欧美一区二区三区| 中文字幕亚洲欧美在线不卡| 成人免费精品视频| 国产日韩精品一区二区三区| 国内精品伊人久久久久av影院| 欧美一级生活片| 美国欧美日韩国产在线播放| 欧美日韩一卡二卡| 亚洲欧美另类久久久精品 | 欧美天堂一区二区三区| 亚洲欧美成aⅴ人在线观看| 99精品国产一区二区三区不卡 | 在线欧美日韩精品| 一个色综合网站| 欧美狂野另类xxxxoooo| 日本不卡一二三区黄网| 日韩一级欧美一级| 精品系列免费在线观看| 国产人久久人人人人爽| caoporen国产精品视频| 亚洲一区欧美一区| 91精品国产色综合久久不卡蜜臀| 首页国产欧美日韩丝袜| 精品国产露脸精彩对白| 国产精品一区二区在线观看网站| 国产欧美精品一区二区色综合朱莉| 成人亚洲一区二区一| 亚洲综合成人在线| 欧美不卡123| 豆国产96在线|亚洲| 亚洲精品国产a| 日韩欧美亚洲国产另类| 国产乱国产乱300精品| 亚洲男人的天堂一区二区| 91精品国产综合久久久久久久久久 | 久久久青草青青国产亚洲免观| 国产suv精品一区二区三区| 亚洲欧美偷拍另类a∨色屁股| 欧美日韩在线播放三区四区| 国产一区在线视频| 亚洲免费观看高清在线观看| 日韩一级免费一区| 91网页版在线| 国产在线视频精品一区| 亚洲免费在线观看| 精品国产乱码久久久久久浪潮| 成人免费视频视频在线观看免费| 亚洲国产成人av好男人在线观看| 久久精品夜色噜噜亚洲aⅴ| 91精品福利在线| 国产成人aaaa| 久久精品理论片| 一区二区在线观看av| 久久久久久亚洲综合影院红桃| 在线看日韩精品电影| 国产精品一区二区免费不卡| 无吗不卡中文字幕| 成人欧美一区二区三区在线播放| 日韩欧美一二三区| 欧美三级资源在线| 91啪亚洲精品| 成人av午夜电影| 国产一区二区日韩精品| 欧美aaaaa成人免费观看视频| 一区二区三区波多野结衣在线观看| 久久精品视频在线免费观看| 日韩一区二区中文字幕| 欧美主播一区二区三区美女| 国产91清纯白嫩初高中在线观看 | 亚洲国产日韩av| 日韩美女啊v在线免费观看| 久久精品亚洲精品国产欧美| 日韩一区二区在线观看| 欧美精选一区二区| 欧美亚洲动漫精品| 欧美色爱综合网| 精品污污网站免费看| 欧美在线|欧美| 日本高清不卡aⅴ免费网站| 99精品热视频| av电影在线不卡| 成人福利视频在线| 成人免费视频播放| 99久久久免费精品国产一区二区| 成人在线视频一区| 波多野结衣中文字幕一区| 成人美女视频在线观看18| 国产91丝袜在线播放| 成人高清视频在线| 一本到高清视频免费精品| 色偷偷一区二区三区| 91网站在线播放| 在线观看亚洲成人| 911国产精品| 欧美成人vps| 中文字幕免费不卡| 一区二区在线看| 日韩黄色免费电影| 韩国午夜理伦三级不卡影院| 国产精品1区二区.| 在线亚洲一区二区| 日韩一本二本av| 国产亚洲欧美日韩俺去了| 综合激情网...| 三级亚洲高清视频| 国产精品123| 91国产丝袜在线播放| 91麻豆精品国产| 中文字幕av在线一区二区三区| 亚洲私人黄色宅男| 天堂av在线一区| 久久99国产精品久久99| 99久久精品国产毛片| 欧美日韩国产精品成人| 国产亚洲精品精华液| 亚洲自拍欧美精品| 国产一区二区三区在线观看免费视频| 成人免费看黄yyy456| 欧美剧情电影在线观看完整版免费励志电影 | 成人免费视频国产在线观看| 在线观看三级视频欧美| 精品国产欧美一区二区| 综合久久一区二区三区| 美女精品一区二区| 欧洲色大大久久| 久久久青草青青国产亚洲免观| 亚洲视频在线一区| 国产在线一区二区综合免费视频| 在线观看亚洲精品| 中文字幕乱码日本亚洲一区二区| 性久久久久久久| 99久久免费国产|