?? http_cgi.c
字號(hào):
/*----------------------------------------------------------------------------
* R T L - T C P N E T
*----------------------------------------------------------------------------
* Name: HTTP_CGI.C
* Purpose: HTTP Server CGI Module
* Rev.: V3.20
*----------------------------------------------------------------------------
* This code is part of the RealView Run-Time Library.
* Copyright (c) 2004-2008 KEIL - An ARM Company. All rights reserved.
*---------------------------------------------------------------------------*/
#include <Net_Config.h>
#include <stdio.h>
#include <string.h>
/* ---------------------------------------------------------------------------
* The HTTP server provides a small scripting language.
*
* The script language is simple and works as follows. Each script line starts
* with a command character, either "i", "t", "c", "#" or ".".
* "i" - command tells the script interpreter to "include" a file from the
* virtual file system and output it to the web browser.
* "t" - command should be followed by a line of text that is to be output
* to the browser.
* "c" - command is used to call one of the C functions from the this file.
* It may be followed by the line of text. This text is passed to
* 'cgi_func()' as a pointer to environment variable.
* "#' - command is a comment line and is ignored (the "#" denotes a comment)
* "." - denotes the last script line.
*
* --------------------------------------------------------------------------*/
/* at_System.c */
extern LOCALM localm[];
#define LocM localm[NETIF_ETH]
/* Net_Config.c */
extern struct tcp_info tcp_socket[];
extern U8 const tcp_NumSocks;
extern U8 const http_EnAuth;
extern U8 http_auth_passw[20];
extern BOOL LEDrun;
extern void LED_out (U32 val);
extern BOOL LCDupdate;
extern U8 lcd_text[2][16+1];
/* Local variables. */
static U8 P2;
static char const state[][11] = {
"FREE",
"CLOSED",
"LISTEN",
"SYN_REC",
"SYN_SENT",
"FINW1",
"FINW2",
"CLOSING",
"LAST_ACK",
"TWAIT",
"CONNECT"};
/* My structure of CGI status U32 variable. This variable is private for */
/* each HTTP Session and is not altered by HTTP Server. It is only set to */
/* zero when the cgi_func() is called for the first time. */
typedef struct {
U16 xcnt;
U16 unused;
} MY_BUF;
#define MYBUF(p) ((MY_BUF *)p)
/*----------------------------------------------------------------------------
* HTTP Server Common Gateway Interface Functions
*---------------------------------------------------------------------------*/
/*--------------------------- cgi_process_var -------------------------------*/
void cgi_process_var (U8 *qs) {
/* This function is called by HTTP server to process the Querry_String */
/* for the CGI Form GET method. It is called on SUBMIT from the browser. */
/*.The Querry_String.is SPACE terminated. */
U8 *var;
int s[4];
var = (U8 *)alloc_mem (40);
do {
/* Loop through all the parameters. */
qs = http_get_var (qs, var, 40);
/* Check the returned string, 'qs' now points to the next. */
if (var[0] != 0) {
/* Returned string is non 0-length. */
if (str_scomp (var, "ip=") == __TRUE) {
/* My IP address parameter. */
sscanf ((const S8 *)&var[3], "%d.%d.%d.%d",&s[0],&s[1],&s[2],&s[3]);
LocM.IpAdr[0] = s[0];
LocM.IpAdr[1] = s[1];
LocM.IpAdr[2] = s[2];
LocM.IpAdr[3] = s[3];
}
else if (str_scomp (var, "msk=") == __TRUE) {
/* Net mask parameter. */
sscanf ((const S8 *)&var[4], "%d.%d.%d.%d",&s[0],&s[1],&s[2],&s[3]);
LocM.NetMask[0] = s[0];
LocM.NetMask[1] = s[1];
LocM.NetMask[2] = s[2];
LocM.NetMask[3] = s[3];
}
else if (str_scomp (var, "gw=") == __TRUE) {
/* Default gateway parameter. */
sscanf ((const S8 *)&var[3], "%d.%d.%d.%d",&s[0],&s[1],&s[2],&s[3]);
LocM.DefGW[0] = s[0];
LocM.DefGW[1] = s[1];
LocM.DefGW[2] = s[2];
LocM.DefGW[3] = s[3];
}
else if (str_scomp (var, "pdns=") == __TRUE) {
/* Default gateway parameter. */
sscanf ((const S8 *)&var[5], "%d.%d.%d.%d",&s[0],&s[1],&s[2],&s[3]);
LocM.PriDNS[0] = s[0];
LocM.PriDNS[1] = s[1];
LocM.PriDNS[2] = s[2];
LocM.PriDNS[3] = s[3];
}
else if (str_scomp (var, "sdns=") == __TRUE) {
/* Default gateway parameter. */
sscanf ((const S8 *)&var[5], "%d.%d.%d.%d",&s[0],&s[1],&s[2],&s[3]);
LocM.SecDNS[0] = s[0];
LocM.SecDNS[1] = s[1];
LocM.SecDNS[2] = s[2];
LocM.SecDNS[3] = s[3];
}
}
}while (qs);
free_mem ((OS_FRAME *)var);
}
/*--------------------------- cgi_process_data ------------------------------*/
void cgi_process_data (U8 *dat, U16 len) {
/* This function is called by HTTP server to process the returned Data */
/* for the CGI Form POST method. It is called on SUBMIT from the browser. */
U8 passw[12],retyped[12];
U8 *var,stpassw;
P2 = 0;
LEDrun = __TRUE;
if (len == 0) {
/* No data or all items (radio, checkbox) are off. */
LED_out (P2);
return;
}
stpassw = 0;
var = (U8 *)alloc_mem (40);
do {
/* Parse all returned parameters. */
dat = http_get_var (dat, var, 40);
if (var[0] != 0) {
/* Parameter found, returned string is non 0-length. */
if (str_scomp (var, "led0=on") == __TRUE) {
P2 |= 0x01;
}
else if (str_scomp (var, "led1=on") == __TRUE) {
P2 |= 0x02;
}
else if (str_scomp (var, "led2=on") == __TRUE) {
P2 |= 0x04;
}
else if (str_scomp (var, "led3=on") == __TRUE) {
P2 |= 0x08;
}
else if (str_scomp (var, "led4=on") == __TRUE) {
P2 |= 0x10;
}
else if (str_scomp (var, "led5=on") == __TRUE) {
P2 |= 0x20;
}
else if (str_scomp (var, "led6=on") == __TRUE) {
P2 |= 0x40;
}
else if (str_scomp (var, "led7=on") == __TRUE) {
P2 |= 0x80;
}
else if (str_scomp (var, "ctrl=Browser") == __TRUE) {
LEDrun = __FALSE;
}
else if (str_scomp (var, "pw=") == __TRUE) {
/* Change password. */
str_copy (passw, var+3);
stpassw |= 1;
}
else if (str_scomp (var, "pw2=") == __TRUE) {
/* Retyped password. */
str_copy (retyped, var+4);
stpassw |= 2;
}
else if (str_scomp (var, "lcd1=") == __TRUE) {
/* LCD Module Line 1 text. */
str_copy (lcd_text[0], var+5);
LCDupdate = __TRUE;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -