📄 httpd.lis
字号:
.module httpd.c
.area text(rom, con, rel)
0000 .dbfile D:\hexok项目\AVRNET项目\AVRNET光盘\AVRuIP\httpd.c
0000 .dbfunc e httpd_init _httpd_init fV
.even
0000 _httpd_init::
0000 .dbline -1
0000 .dbline 184
0000 ; /**
0000 ; * \addtogroup exampleapps
0000 ; * @{
0000 ; */
0000 ;
0000 ; /**
0000 ; * \defgroup httpd Web server
0000 ; * @{
0000 ; *
0000 ; * The uIP web server is a very simplistic implementation of an HTTP
0000 ; * server. It can serve web pages and files from a read-only ROM
0000 ; * filesystem, and provides a very small scripting language.
0000 ; *
0000 ; * The script language is very simple and works as follows. Each
0000 ; * script line starts with a command character, either "i", "t", "c",
0000 ; * "#" or ".". The "i" command tells the script interpreter to
0000 ; * "include" a file from the virtual file system and output it to the
0000 ; * web browser. The "t" command should be followed by a line of text
0000 ; * that is to be output to the browser. The "c" command is used to
0000 ; * call one of the C functions from the httpd-cgi.c file. A line that
0000 ; * starts with a "#" is ignored (i.e., the "#" denotes a comment), and
0000 ; * the "." denotes the last script line.
0000 ; *
0000 ; * The script that produces the file statistics page looks somewhat
0000 ; * like this:
0000 ; *
0000 ; \code
0000 ; i /header.html
0000 ; t <h1>File statistics</h1><br><table width="100%">
0000 ; t <tr><td><a href="/index.html">/index.html</a></td><td>
0000 ; c a /index.html
0000 ; t </td></tr> <tr><td><a href="/cgi/files">/cgi/files</a></td><td>
0000 ; c a /cgi/files
0000 ; t </td></tr> <tr><td><a href="/cgi/tcp">/cgi/tcp</a></td><td>
0000 ; c a /cgi/tcp
0000 ; t </td></tr> <tr><td><a href="/404.html">/404.html</a></td><td>
0000 ; c a /404.html
0000 ; t </td></tr></table>
0000 ; i /footer.plain
0000 ; .
0000 ; \endcode
0000 ; *
0000 ; */
0000 ;
0000 ;
0000 ; /**
0000 ; * \file
0000 ; * HTTP server.
0000 ; * \author Adam Dunkels <adam@dunkels.com>
0000 ; */
0000 ;
0000 ; /*
0000 ; * Copyright (c) 2001, Adam Dunkels.
0000 ; * All rights reserved.
0000 ; *
0000 ; * Redistribution and use in source and binary forms, with or without
0000 ; * modification, are permitted provided that the following conditions
0000 ; * are met:
0000 ; * 1. Redistributions of source code must retain the above copyright
0000 ; * notice, this list of conditions and the following disclaimer.
0000 ; * 2. Redistributions in binary form must reproduce the above copyright
0000 ; * notice, this list of conditions and the following disclaimer in the
0000 ; * documentation and/or other materials provided with the distribution.
0000 ; * 3. The name of the author may not be used to endorse or promote
0000 ; * products derived from this software without specific prior
0000 ; * written permission.
0000 ; *
0000 ; * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
0000 ; * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
0000 ; * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0000 ; * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
0000 ; * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0000 ; * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
0000 ; * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0000 ; * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
0000 ; * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
0000 ; * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
0000 ; * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0000 ; *
0000 ; * This file is part of the uIP TCP/IP stack.
0000 ; *
0000 ; * $Id: httpd.c,v 1.28.2.6 2003/10/07 13:22:27 adam Exp $
0000 ; *
0000 ; */
0000 ;
0000 ;
0000 ; #include "uip.h"
0000 ; #include "httpd.h"
0000 ; #include "fs.h"
0000 ; #include "fsdata.h"
0000 ; #include "cgi.h"
0000 ; #include "filelist.h"
0000 ; #include "compiler.h"
0000 ;
0000 ; #define NULL (void *)0
0000 ;
0000 ; /* The HTTP server states: */
0000 ; #define HTTP_NOGET 0
0000 ; #define HTTP_FILE 1
0000 ; #define HTTP_TEXT 2
0000 ; #define HTTP_FUNC 3
0000 ; #define HTTP_END 4
0000 ;
0000 ; #ifdef DEBUG
0000 ; #include <stdio.h>
0000 ; #define PRINT(x) printf("%s", x)
0000 ; #define PRINTLN(x) printf("%s\n", x)
0000 ; #else /* DEBUG */
0000 ; #define PRINT(x)
0000 ; #define PRINTLN(x)
0000 ; #endif /* DEBUG */
0000 ;
0000 ; struct httpd_state *hs;
0000 ;
0000 ; static void next_scriptline(void);
0000 ; static void next_scriptstate(void);
0000 ;
0000 ; #define ISO_H 0x48
0000 ; #define ISO_I 0x49
0000 ; #define ISO_J 0x4A
0000 ; #define ISO_K 0x4B
0000 ; #define ISO_L 0x4C
0000 ; #define ISO_M 0x4D
0000 ; #define ISO_N 0x4E
0000 ; #define ISO_O 0x4F
0000 ; #define ISO_P 0x50
0000 ; #define ISO_Q 0x51
0000 ; #define ISO_R 0x52
0000 ; #define ISO_S 0x53
0000 ;
0000 ; #define ISO_G 0x47
0000 ; #define ISO_E 0x45
0000 ; #define ISO_T 0x54
0000 ; #define ISO_slash 0x2f
0000 ; #define ISO_c 0x63
0000 ; #define ISO_g 0x67
0000 ; #define ISO_i 0x69
0000 ; #define ISO_space 0x20
0000 ; #define ISO_nl 0x0a
0000 ; #define ISO_cr 0x0d
0000 ; #define ISO_a 0x61
0000 ; #define ISO_b 0x62
0000 ; #define ISO_d 0x64
0000 ; #define ISO_e 0x65
0000 ; #define ISO_f 0x66
0000 ; #define ISO_h 0x68
0000 ; #define ISO_j 0x6A
0000 ; #define ISO_k 0x6B
0000 ; #define ISO_l 0x6C
0000 ; #define ISO_m 0x6D
0000 ; #define ISO_n 0x6E
0000 ; #define ISO_o 0x6F
0000 ; #define ISO_p 0x70
0000 ; #define ISO_q 0x71
0000 ; #define ISO_r 0x72
0000 ; #define ISO_s 0x73
0000 ; #define ISO_t 0x74
0000 ; #define ISO_u 0x75
0000 ; #define ISO_v 0x76
0000 ; #define ISO_w 0x77
0000 ; #define ISO_x 0x78
0000 ; #define ISO_y 0x79
0000 ; #define ISO_z 0x80
0000 ; #define ISO_hash 0x23
0000 ; #define ISO_period 0x2e
0000 ; #define ISO_dot 46
0000 ;
0000 ; #define LED1_ON PORTD&=0xEF
0000 ; #define LED2_ON PORTD&=0xDF
0000 ; #define LED1_OFF PORTD|=0x10
0000 ; #define LED2_OFF PORTD|=0x20
0000 ; #define LEDPORT PORTD
0000 ; #define LED1_FLASH PORTD^=0x10
0000 ;
0000 ; /*-----------------------------------------------------------------------------------*/
0000 ; /**
0000 ; * Initialize the web server.
0000 ; *
0000 ; * Starts to listen for incoming connection requests on TCP port 80.
0000 ; */
0000 ; /*-----------------------------------------------------------------------------------*/
0000 ; void
0000 ; httpd_init(void)
0000 ; {
0000 .dbline 185
0000 ; fs_init();
0000 0E940000 xcall _fs_init
0004 .dbline 188
0004 ;
0004 ; /* Listen to port 80. */
0004 ; uip_listen(HTONS(80));
0004 00E0 ldi R16,20480
0006 10E5 ldi R17,80
0008 0E940000 xcall _uip_listen
000C .dbline -2
000C L7:
000C .dbline 0 ; func end
000C 0895 ret
000E .dbend
000E .dbfunc e httpd_appcall _httpd_appcall fV
000E .dbstruct 0 4 fs_file
000E .dbfield 0 data pc
000E .dbfield 2 len I
000E .dbend
000E ; fsfile -> y+8
000E ; opfn -> y+0
000E ; i -> R10,R11
000E ; j -> R10,R11
000E ; post_data -> R12
.even
000E _httpd_appcall::
000E 0E940000 xcall push_gset4x
0012 2C97 sbiw R28,12
0014 .dbline -1
0014 .dbline 193
0014 ; }
0014 ; /*-----------------------------------------------------------------------------------*/
0014 ; void
0014 ; httpd_appcall(void)
0014 ; {
0014 .dbline 196
0014 ; struct fs_file fsfile;
0014 ; char opfn[8];
0014 ; char post_data=0;
0014 CC24 clr R12
0016 .dbline 197
0016 ; int j=0;
0016 AA24 clr R10
0018 BB24 clr R11
001A .dbline 201
001A E0910000 lds R30,_uip_conn
001E F0910100 lds R31,_uip_conn+1
0022 A480 ldd R10,z+4
0024 B580 ldd R11,z+5
0026 C501 movw R24,R10
0028 8030 cpi R24,0
002A E0E5 ldi R30,80
002C 9E07 cpc R25,R30
002E 09F0 breq L12
0030 76C2 xjmp L9
0032 X0:
0032 .dbline 201
0032 ;
0032 ; u16_t i;
0032 ;
0032 ; switch(uip_conn->lport) {
0032 L12:
0032 .dbline 205
0032 ; /* This is the web server: */
0032 ; case HTONS(80):
0032 ; /* Pick out the application state from the uip_conn structure. */
0032 ; hs = (struct httpd_state *)(uip_conn->appstate);
0032 80910000 lds R24,_uip_conn
0036 90910100 lds R25,_uip_conn+1
003A 4C96 adiw R24,28
003C 90930100 sts _hs+1,R25
0040 80930000 sts _hs,R24
0044 .dbline 214
0044 ;
0044 ; /* We use the uip_ test functions to deduce why we were
0044 ; called. If uip_connected() is non-zero, we were called
0044 ; because a remote host has connected to us. If
0044 ; uip_newdata() is non-zero, we were called because the
0044 ; remote host has sent us new data, and if uip_acked() is
0044 ; non-zero, the remote host has acknowledged the data we
0044 ; previously sent to it. */
0044 ; if(uip_connected()) {
0044 20900000 lds R2,_uip_flags
0048 26FE sbrs R2,6
004A 0BC0 rjmp L13
004C .dbline 214
004C .dbline 221
004C ; /* Since we have just been connected with the remote host, we
004C ; reset the state for this connection. The ->count variable
004C ; contains the amount of data that is yet to be sent to the
004C ; remote host, and the ->state is set to HTTP_NOGET to signal
004C ; that we haven't received any HTTP GET request for this
004C ; connection yet. */
004C ; hs->state = HTTP_NOGET;
004C 2224 clr R2
004E FC01 movw R30,R24
0050 2082 std z+0,R2
0052 .dbline 222
0052 ; hs->count = 0;
0052 3324 clr R3
0054 E0910000 lds R30,_hs
0058 F0910100 lds R31,_hs+1
005C 3282 std z+2,R3
005E 2182 std z+1,R2
0060 .dbline 223
0060 ; return;
0060 61C2 xjmp L8
0062 L13:
0062 .dbline 225
0062 ;
0062 ; } else if(uip_poll()) {
0062 20900000 lds R2,_uip_flags
0066 23FE sbrs R2,3
0068 16C0 rjmp L15
006A .dbline 225
006A .dbline 229
006A ; /* If we are polled ten times, we abort the connection. This is
006A ; because we don't want connections lingering indefinately in
006A ; the system. */
006A ; if(hs->count++ >= 10) {
006A 80910000 lds R24,_hs
006E 90910100 lds R25,_hs+1
0072 0196 adiw R24,1
0074 FC01 movw R30,R24
0076 4080 ldd R4,z+0
0078 5180 ldd R5,z+1
007A C201 movw R24,R4
007C 0196 adiw R24,1
007E 9183 std z+1,R25
0080 8083 std z+0,R24
0082 C201 movw R24,R4
0084 8A30 cpi R24,10
0086 E0E0 ldi R30,0
0088 9E07 cpc R25,R30
008A 08F4 brsh X5
008C 4BC2 xjmp L8
008E X5:
008E .dbline 229
008E .dbline 230
008E ; uip_abort();
008E 80E2 ldi R24,32
0090 80930000 sts _uip_flags,R24
0094 .dbline 231
0094 ; }
0094 .dbline 232
0094 ; return;
0094 47C2 xjmp L8
0096 L15:
0096 .dbline 233
0096 ; } else if(uip_newdata() && hs->state == HTTP_NOGET) {
0096 20900000 lds R2,_uip_flags
009A 21FE sbrs R2,1
009C A4C1 rjmp L19
009E E0910000 lds R30,_hs
00A2 F0910100 lds R31,_hs+1
00A6 2080 ldd R2,z+0
00A8 2220 tst R2
00AA 09F0 breq X6
00AC 9CC1 xjmp L19
00AE X6:
00AE .dbline 233
00AE .dbline 238
00AE ; /* This is the first data we receive, and it should contain a
00AE ; GET. */
00AE ;
00AE ; /* Check for GET. */
00AE ; if(uip_appdata[0] == ISO_G &&
00AE E0910000 lds R30,_uip_appdata
00B2 F0910100 lds R31,_uip_appdata+1
00B6 8081 ldd R24,z+0
00B8 8734 cpi R24,71
00BA 09F0 breq X7
00BC 90C0 xjmp L21
00BE X7:
00BE 8181 ldd R24,z+1
00C0 8534 cpi R24,69
00C2 09F0 breq X8
00C4 8CC0 xjmp L21
00C6 X8:
00C6 E0910000 lds R30,_uip_appdata
00CA F0910100 lds R31,_uip_appdata+1
00CE 8281 ldd R24,z+2
00D0 8435 cpi R24,84
00D2 09F0 breq X9
00D4 84C0 xjmp L21
00D6 X9:
00D6 E0910000 lds R30,_uip_appdata
00DA F0910100 lds R31,_uip_appdata+1
00DE 8381 ldd R24,z+3
00E0 8032 cpi R24,32
00E2 09F0 breq X10
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -