⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cgi.c

📁 基于uIP框架的8051tcpip源码
💻 C
字号:
/* * Copyright (c) 2001, Adam Dunkels. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *      This product includes software developed by Adam Dunkels. * 4. The name of the author may not be used to endorse or promote *    products derived from this software without specific prior *    written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of the uIP TCP/IP stack. * * $Id: cgi.c,v 1.21 2002/01/13 21:12:40 adam Exp $ * *//* * This file includes functions that are called by the web server * scripts. The functions takes no argument, and the return value is * interpreted as follows. A zero means that the function did not * complete and should be invoked for the next packet as well. A * non-zero value indicates that the function has completed and that * the web server should move along to the next script line. * */#include "uip.h"#include "cgi.h"#include "httpd.h"#include "fs.h"#include <8051io.h>static u8_t print_stats(void);static u8_t file_stats(void);static u8_t tcp_stats(void);static u8_t thermo_stats(void);u8_t * cgitab[] = {  &print_stats,   /* CGI function "a" */  &file_stats,    /* CGI function "b" */  &tcp_stats,      /* CGI function "c" */  &thermo_stats  /* CGI function "d" */};static const char closed[] =   /*  "CLOSED",*/{0x43, 0x4c, 0x4f, 0x53, 0x45, 0x44, 0};static const char syn_rcvd[] = /*  "SYN-RCVD",*/{0x53, 0x59, 0x4e, 0x2d, 0x52, 0x43, 0x56, 0x44,  0};static const char syn_sent[] = /*  "SYN-SENT",*/{0x53, 0x59, 0x4e, 0x2d, 0x53, 0x45, 0x4e, 0x54,  0};static const char established[] = /*  "ESTABLISHED",*/{0x45, 0x53, 0x54, 0x41, 0x42, 0x4c, 0x49, 0x53, 0x48, 0x45, 0x44, 0};static const char fin_wait_1[] = /*  "FIN-WAIT-1",*/{0x46, 0x49, 0x4e, 0x2d, 0x57, 0x41, 0x49, 0x54, 0x2d, 0x31, 0};static const char fin_wait_2[] = /*  "FIN-WAIT-2",*/{0x46, 0x49, 0x4e, 0x2d, 0x57, 0x41, 0x49, 0x54, 0x2d, 0x32, 0};static const char closing[] = /*  "CLOSING",*/{0x43, 0x4c, 0x4f, 0x53, 0x49, 0x4e, 0x47, 0};static const char time_wait[] = /*  "TIME-WAIT,"*/{0x54, 0x49, 0x4d, 0x45, 0x2d, 0x57, 0x41, 0x49, 0x54, 0};static const char last_ack[] = /*  "LAST-ACK"*/{0x4c, 0x41, 0x53, 0x54, 0x2d, 0x41, 0x43, 0x4b, 0};static const char *states[] = {  "CLOSED",  "SYN-RCVD",  "SYN-SENT",  "ESTABLISHED",  "FIN-WAIT-1",  "FIN-WAIT-2",  "CLOSING",  "TIME-WAIT",  "LAST-ACK"};/*-----------------------------------------------------------------------------------*//* print_stats: * * Prints out a part of the uIP statistics. The statistics data is * written into the uip_appdata buffer. It overwrites any incoming * packet. */static u8_tprint_stats(void){#if UIP_STATISTICS  if(uip_acked()) {      /* We have printed out all statistics, so we return 1 to	 indicate that we are done. */      return 1;  }  /* Write part of the statistics into the uip_appdata buffer. */    sprintf((char *)uip_appdata, "%5u\r\n%5u\r\n%5u\r\n%5u\r\n%5u\r\n%5u\r\n%5u\r\n%5u\r\n%5u\r\n%5u\r\n%5u\r\n%5u\r\n%5u\r\n%5u\r\n%5u\r\n%5u\r\n%5u\r\n%5u\r\n%5u\r\n%5u\r\n%5u\r\n%5u\r\n",            uip_stat.ip.drop,            uip_stat.ip.recv,            uip_stat.ip.sent,            uip_stat.ip.vhlerr,            uip_stat.ip.hblenerr,            uip_stat.ip.lblenerr,            uip_stat.ip.fragerr,            uip_stat.ip.ipchkerr,            uip_stat.ip.protoerr,            uip_stat.icmp.drop,            uip_stat.icmp.recv,            uip_stat.icmp.sent,            uip_stat.icmp.typeerr,            uip_stat.tcp.drop,            uip_stat.tcp.recv,            uip_stat.tcp.sent,            uip_stat.tcp.chkerr,			uip_stat.tcp.ackerr,            uip_stat.tcp.rst,            uip_stat.tcp.rexmit,			uip_stat.tcp.syndrop,            uip_stat.tcp.synrst);  /* Send the data. */  uip_send(uip_appdata, 7*22);  return 0;#else  return 1;#endif /* UIP_STATISTICS */}/*-----------------------------------------------------------------------------------*/static u8_tfile_stats(void){  /* We use sprintf() to print the number of file accesses to a     particular file (given as an argument to the function in the     script). We then use uip_send() to actually send the data. */  if(uip_acked()) {    return 1;  }  sprintf((char *)uip_appdata, "%5u", fs_count(&hs->script[4]));  uip_send(uip_appdata, strlen((char *)uip_appdata));  return 0;}/*-----------------------------------------------------------------------------------*/static u8_ttcp_stats(void){  struct uip_conn *conn;  if(uip_acked()) {    /* If the previously sent data has been acknowledged, we move       forward one connection. */    if(++hs->count == UIP_CONNS) {      /* If all connections has been printed out, we are done and	 return 1. */      return 1;    }  }  conn = uip_conns[hs->count];  if((conn->tcpstateflags & TS_MASK) == CLOSED) {	sprintf((char *)uip_appdata,				  "<tr align=\"center\"><td>-</td><td>-</td><td>%d</td><td>%d</td><td>%c %c</td></tr>\r\n",				  conn->nrtx,				  conn->timer,				  (conn->tcpstateflags & UIP_OUTSTANDING)? '*':' ',    			  (conn->tcpstateflags & UIP_STOPPED)? '!':' ');    uip_send(uip_appdata, strlen((char *)uip_appdata));  } else {	sprintf((char *)uip_appdata,				  "<tr align=\"center\"><td>%d.%d.%d.%d:%d</td><td>%s</td><td>%d</td><td>%d</td><td>%c %c</td></tr>\r\n",				  ntohs(conn->ripaddr[0]) >> 8,				  ntohs(conn->ripaddr[0]) & 0xff,				  ntohs(conn->ripaddr[1]) >> 8,				  ntohs(conn->ripaddr[1]) & 0xff,				  ntohs(conn->rport),				  states[conn->tcpstateflags & TS_MASK],				  conn->nrtx,				  conn->timer,				  (conn->tcpstateflags & UIP_OUTSTANDING)? '*':' ',    			  (conn->tcpstateflags & UIP_STOPPED)? '!':' ');    uip_send(uip_appdata, strlen((char *)uip_appdata));  }  return 0;}/*-----------------------------------------------------------------------------------*/static u8_t thermo_stats(void){	char tempC;	int  tempF;    if(uip_acked()) {     return 1;    }	tempC = (char)thermoread();	tempF = (9 * tempC + 160)/5;	sprintf((char *) uip_appdata,		    "<tr><th>%d</th><th>%d</th></tr>\r\n", tempC, tempF);	uip_send(uip_appdata, strlen((char *)uip_appdata));	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -