📄 httpd.s
字号:
.module httpd.c
.area text(rom, con, rel)
.dbfile D:\hexok项目\AVRNET项目\AVRNET光盘\AVRuIP\httpd.c
.dbfunc e httpd_init _httpd_init fV
.even
_httpd_init::
.dbline -1
.dbline 184
; /**
; * \addtogroup exampleapps
; * @{
; */
;
; /**
; * \defgroup httpd Web server
; * @{
; *
; * The uIP web server is a very simplistic implementation of an HTTP
; * server. It can serve web pages and files from a read-only ROM
; * filesystem, and provides a very small scripting language.
; *
; * The script language is very simple and works as follows. Each
; * script line starts with a command character, either "i", "t", "c",
; * "#" or ".". The "i" command tells the script interpreter to
; * "include" a file from the virtual file system and output it to the
; * web browser. The "t" command should be followed by a line of text
; * that is to be output to the browser. The "c" command is used to
; * call one of the C functions from the httpd-cgi.c file. A line that
; * starts with a "#" is ignored (i.e., the "#" denotes a comment), and
; * the "." denotes the last script line.
; *
; * The script that produces the file statistics page looks somewhat
; * like this:
; *
; \code
; i /header.html
; t <h1>File statistics</h1><br><table width="100%">
; t <tr><td><a href="/index.html">/index.html</a></td><td>
; c a /index.html
; t </td></tr> <tr><td><a href="/cgi/files">/cgi/files</a></td><td>
; c a /cgi/files
; t </td></tr> <tr><td><a href="/cgi/tcp">/cgi/tcp</a></td><td>
; c a /cgi/tcp
; t </td></tr> <tr><td><a href="/404.html">/404.html</a></td><td>
; c a /404.html
; t </td></tr></table>
; i /footer.plain
; .
; \endcode
; *
; */
;
;
; /**
; * \file
; * HTTP server.
; * \author Adam Dunkels <adam@dunkels.com>
; */
;
; /*
; * 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. 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: httpd.c,v 1.28.2.6 2003/10/07 13:22:27 adam Exp $
; *
; */
;
;
; #include "uip.h"
; #include "httpd.h"
; #include "fs.h"
; #include "fsdata.h"
; #include "cgi.h"
; #include "filelist.h"
; #include "compiler.h"
;
; #define NULL (void *)0
;
; /* The HTTP server states: */
; #define HTTP_NOGET 0
; #define HTTP_FILE 1
; #define HTTP_TEXT 2
; #define HTTP_FUNC 3
; #define HTTP_END 4
;
; #ifdef DEBUG
; #include <stdio.h>
; #define PRINT(x) printf("%s", x)
; #define PRINTLN(x) printf("%s\n", x)
; #else /* DEBUG */
; #define PRINT(x)
; #define PRINTLN(x)
; #endif /* DEBUG */
;
; struct httpd_state *hs;
;
; static void next_scriptline(void);
; static void next_scriptstate(void);
;
; #define ISO_H 0x48
; #define ISO_I 0x49
; #define ISO_J 0x4A
; #define ISO_K 0x4B
; #define ISO_L 0x4C
; #define ISO_M 0x4D
; #define ISO_N 0x4E
; #define ISO_O 0x4F
; #define ISO_P 0x50
; #define ISO_Q 0x51
; #define ISO_R 0x52
; #define ISO_S 0x53
;
; #define ISO_G 0x47
; #define ISO_E 0x45
; #define ISO_T 0x54
; #define ISO_slash 0x2f
; #define ISO_c 0x63
; #define ISO_g 0x67
; #define ISO_i 0x69
; #define ISO_space 0x20
; #define ISO_nl 0x0a
; #define ISO_cr 0x0d
; #define ISO_a 0x61
; #define ISO_b 0x62
; #define ISO_d 0x64
; #define ISO_e 0x65
; #define ISO_f 0x66
; #define ISO_h 0x68
; #define ISO_j 0x6A
; #define ISO_k 0x6B
; #define ISO_l 0x6C
; #define ISO_m 0x6D
; #define ISO_n 0x6E
; #define ISO_o 0x6F
; #define ISO_p 0x70
; #define ISO_q 0x71
; #define ISO_r 0x72
; #define ISO_s 0x73
; #define ISO_t 0x74
; #define ISO_u 0x75
; #define ISO_v 0x76
; #define ISO_w 0x77
; #define ISO_x 0x78
; #define ISO_y 0x79
; #define ISO_z 0x80
; #define ISO_hash 0x23
; #define ISO_period 0x2e
; #define ISO_dot 46
;
; #define LED1_ON PORTD&=0xEF
; #define LED2_ON PORTD&=0xDF
; #define LED1_OFF PORTD|=0x10
; #define LED2_OFF PORTD|=0x20
; #define LEDPORT PORTD
; #define LED1_FLASH PORTD^=0x10
;
; /*-----------------------------------------------------------------------------------*/
; /**
; * Initialize the web server.
; *
; * Starts to listen for incoming connection requests on TCP port 80.
; */
; /*-----------------------------------------------------------------------------------*/
; void
; httpd_init(void)
; {
.dbline 185
; fs_init();
xcall _fs_init
.dbline 188
;
; /* Listen to port 80. */
; uip_listen(HTONS(80));
ldi R16,20480
ldi R17,80
xcall _uip_listen
.dbline -2
L7:
.dbline 0 ; func end
ret
.dbend
.dbfunc e httpd_appcall _httpd_appcall fV
.dbstruct 0 4 fs_file
.dbfield 0 data pc
.dbfield 2 len I
.dbend
; fsfile -> y+8
; opfn -> y+0
; i -> R10,R11
; j -> R10,R11
; post_data -> R12
.even
_httpd_appcall::
xcall push_gset4x
sbiw R28,12
.dbline -1
.dbline 193
; }
; /*-----------------------------------------------------------------------------------*/
; void
; httpd_appcall(void)
; {
.dbline 196
; struct fs_file fsfile;
; char opfn[8];
; char post_data=0;
clr R12
.dbline 197
; int j=0;
clr R10
clr R11
.dbline 201
lds R30,_uip_conn
lds R31,_uip_conn+1
ldd R10,z+4
ldd R11,z+5
movw R24,R10
cpi R24,0
ldi R30,80
cpc R25,R30
breq L12
xjmp L9
X0:
.dbline 201
;
; u16_t i;
;
; switch(uip_conn->lport) {
L12:
.dbline 205
; /* This is the web server: */
; case HTONS(80):
; /* Pick out the application state from the uip_conn structure. */
; hs = (struct httpd_state *)(uip_conn->appstate);
lds R24,_uip_conn
lds R25,_uip_conn+1
adiw R24,28
sts _hs+1,R25
sts _hs,R24
.dbline 214
;
; /* We use the uip_ test functions to deduce why we were
; called. If uip_connected() is non-zero, we were called
; because a remote host has connected to us. If
; uip_newdata() is non-zero, we were called because the
; remote host has sent us new data, and if uip_acked() is
; non-zero, the remote host has acknowledged the data we
; previously sent to it. */
; if(uip_connected()) {
lds R2,_uip_flags
sbrs R2,6
rjmp L13
.dbline 214
.dbline 221
; /* Since we have just been connected with the remote host, we
; reset the state for this connection. The ->count variable
; contains the amount of data that is yet to be sent to the
; remote host, and the ->state is set to HTTP_NOGET to signal
; that we haven't received any HTTP GET request for this
; connection yet. */
; hs->state = HTTP_NOGET;
clr R2
movw R30,R24
std z+0,R2
.dbline 222
; hs->count = 0;
clr R3
lds R30,_hs
lds R31,_hs+1
std z+2,R3
std z+1,R2
.dbline 223
; return;
xjmp L8
L13:
.dbline 225
;
; } else if(uip_poll()) {
lds R2,_uip_flags
sbrs R2,3
rjmp L15
.dbline 225
.dbline 229
; /* If we are polled ten times, we abort the connection. This is
; because we don't want connections lingering indefinately in
; the system. */
; if(hs->count++ >= 10) {
lds R24,_hs
lds R25,_hs+1
adiw R24,1
movw R30,R24
ldd R4,z+0
ldd R5,z+1
movw R24,R4
adiw R24,1
std z+1,R25
std z+0,R24
movw R24,R4
cpi R24,10
ldi R30,0
cpc R25,R30
brsh X5
xjmp L8
X5:
.dbline 229
.dbline 230
; uip_abort();
ldi R24,32
sts _uip_flags,R24
.dbline 231
; }
.dbline 232
; return;
xjmp L8
L15:
.dbline 233
; } else if(uip_newdata() && hs->state == HTTP_NOGET) {
lds R2,_uip_flags
sbrs R2,1
rjmp L19
lds R30,_hs
lds R31,_hs+1
ldd R2,z+0
tst R2
breq X6
xjmp L19
X6:
.dbline 233
.dbline 238
; /* This is the first data we receive, and it should contain a
; GET. */
;
; /* Check for GET. */
; if(uip_appdata[0] == ISO_G &&
lds R30,_uip_appdata
lds R31,_uip_appdata+1
ldd R24,z+0
cpi R24,71
breq X7
xjmp L21
X7:
ldd R24,z+1
cpi R24,69
breq X8
xjmp L21
X8:
lds R30,_uip_appdata
lds R31,_uip_appdata+1
ldd R24,z+2
cpi R24,84
breq X9
xjmp L21
X9:
lds R30,_uip_appdata
lds R31,_uip_appdata+1
ldd R24,z+3
cpi R24,32
breq X10
xjmp L21
X10:
.dbline 242
; uip_appdata[1] == ISO_E &&
; uip_appdata[2] == ISO_T &&
; uip_appdata[3] == ISO_space)
; {
.dbline 244
; /* Find the file we are looking for. */
; for(i = 4; i < 40; ++i)
ldi R24,4
ldi R25,0
movw R10,R24
xjmp L26
L23:
.dbline 245
; {
.dbline 246
; if(uip_appdata[i]==ISO_space||uip_appdata[i] == ISO_cr||uip_appdata[i] == ISO_nl)
lds R2,_uip_appdata
lds R3,_uip_appdata+1
movw R4,R10
add R4,R2
adc R5,R3
movw R30,R4
ldd R24,z+0
cpi R24,32
breq L30
cpi R24,13
breq L30
cpi R24,10
brne L27
L30:
.dbline 247
; {
.dbline 248
; uip_appdata[i] = 0;
lds R2,_uip_appdata
lds R3,_uip_appdata+1
movw R30,R10
add R30,R2
adc R31,R3
clr R2
std z+0,R2
.dbline 249
; break;
xjmp L25
L27:
.dbline 251
L24:
.dbline 244
movw R24,R10
adiw R24,1
movw R10,R24
L26:
.dbline 244
movw R24,R10
cpi R24,40
ldi R30,0
cpc R25,R30
brlo L23
L25:
.dbline 254
; }
; }
;
; /* Check for a request for "/". */
; if(uip_appdata[4] == ISO_slash && uip_appdata[5] == 0)
lds R30,_uip_appdata
lds R31,_uip_appdata+1
ldd R24,z+4
cpi R24,47
brne L31
lds R30,_uip_appdata
lds R31,_uip_appdata+1
ldd R2,z+5
tst R2
brne L31
.dbline 255
; {
.dbline 257
; //load_web_page(index_html);
; fs_open(file_index_html.name, &fsfile);
movw R18,R28
subi R18,248 ; offset = 8
sbci R19,255
lds R16,_file_index_html+2
lds R17,_file_index_html+2+1
xcall _fs_open
.dbline 258
; }
xjmp L22
L31:
.dbline 260
; else
; {
.dbline 261
; i=5;
ldi R24,5
ldi R25,0
movw R10,R24
xjmp L35
L34:
.dbline 263
.dbline 264
lds R2,_uip_appdata
lds R3,_uip_appdata+1
movw R30,R10
add R30,R2
adc R31,R3
ldd R2,z+0
movw R24,R28
movw R30,R10
sbiw R30,5
add R30,R24
adc R31,R25
std z+0,R2
.dbline 265
movw R24,R10
adiw R24,1
movw R10,R24
.dbline 266
L35:
.dbline 262
; while((uip_appdata[i] != ISO_dot) && (uip_appdata[i] != ISO_space))
lds R2,_uip_appdata
lds R3,_uip_appdata+1
movw R4,R10
add R4,R2
adc R5,R3
movw R30,R4
ldd R24,z+0
cpi R24,46
breq L37
cpi R24,32
brne L34
L37:
.dbline 267
; {
; opfn[i-5]=uip_appdata[i];
; i++;
; }
; opfn[i-5]='\r';
movw R24,R28
movw R30,R10
sbiw R30,5
add R30,R24
adc R31,R25
ldi R24,13
std z+0,R24
.dbline 268
; fs_open(opfn, &fsfile);
movw R18,R28
subi R18,248 ; offset = 8
sbci R19,255
movw R16,R28
xcall _fs_open
.dbline 269
; if(!fs_open((char *)&uip_appdata[4], &fsfile))
movw R18,R28
subi R18,248 ; offset = 8
sbci R19,255
lds R16,_uip_appdata
lds R17,_uip_appdata+1
subi R16,252 ; offset = 4
sbci R17,255
xcall _fs_open
cpi R16,0
cpc R16,R17
breq X11
xjmp L22
X11:
X1:
.dbline 270
; {
.dbline 271
; PRINTLN("couldn't open file");
.dbline 273
; //fs_open(file_404_html.name, &fsfile);
; }
.dbline 275
;
; }
.dbline 276
; }
xjmp L22
L21:
.dbline 277
; else if(uip_appdata[0] == ISO_P &&
lds R30,_uip_appdata
lds R31,_uip_appdata+1
ldd R24,z+0
cpi R24,80
breq X12
xjmp L40
X12:
ldd R24,z+1
cpi R24,79
breq X13
xjmp L40
X13:
lds R30,_uip_appdata
lds R31,_uip_appdata+1
ldd R24,z+2
cpi R24,83
breq X14
xjmp L40
X14:
lds R30,_uip_appdata
lds R31,_uip_appdata+1
ldd R24,z+3
cpi R24,84
breq X15
xjmp L40
X15:
lds R30,_uip_appdata
lds R31,_uip_appdata+1
ldd R24,z+4
cpi R24,32
breq X16
xjmp L40
X16:
.dbline 282
; uip_appdata[1] == ISO_O &&
; uip_appdata[2] == ISO_S &&
; uip_appdata[3] == ISO_T &&
; uip_appdata[4] == ISO_space)
; {
.dbline 283
; for(i=0;i<1496;i++)
clr R10
clr R11
xjmp L45
L42:
.dbline 284
; {
.dbline 285
; if((uip_appdata[i]==ISO_cr)&&(uip_appdata[i+1]==ISO_nl)&&(uip_appdata[i+2]==ISO_cr)&&(uip_appdata[i+3]==ISO_nl))
lds R2,_uip_appdata
lds R3,_uip_appdata+1
movw R30,R10
add R30,R2
adc R31,R3
ldd R24,z+0
cpi R24,13
brne L46
movw R30,R10
adiw R30,1
add R30,R2
adc R31,R3
ldd R24,z+0
cpi R24,10
brne L46
movw R30,R10
adiw R30,2
add R30,R2
adc R31,R3
ldd R24,z+0
cpi R24,13
brne L46
movw R30,R10
adiw R30,3
add R30,R2
adc R31,R3
ldd R24,z+0
cpi R24,10
brne L46
.dbline 286
; {
.dbline 287
; post_data=uip_appdata[i+8];
movw R30,R10
adiw R30,8
add R30,R2
adc R31,R3
ldd R12,z+0
.dbline 288
; break;
xjmp L44
L46:
.dbline 290
L43:
.dbline 283
movw R24,R10
adiw R24,1
movw R10,R24
L45:
.dbline 283
movw R24,R10
cpi R24,216
ldi R30,5
cpc R25,R30
brsh X17
xjmp L42
X17:
L44:
.dbline 291
; }
; }
; if(post_data==0x31){LED1_ON;LED2_OFF;}
mov R24,R12
cpi R24,49
brne L48
.dbline 291
.dbline 291
in R24,0x12
andi R24,239
out 0x12,R24
.dbline 291
sbi 0x12,5
.dbline 291
xjmp L49
L48:
.dbline 292
; else if(post_data==0x32){LED2_ON;LED1_OFF;}
mov R24,R12
cpi R24,50
brne L50
.dbline 292
.dbline 292
in R24,0x12
andi R24,223
out 0x12,R24
.dbline 292
sbi 0x12,4
.dbline 292
xjmp L51
L50:
.dbline 293
; else{LED2_OFF;LED1_OFF;}
.dbline 293
sbi 0x12,5
.dbline 293
sbi 0x12,4
.dbline 293
L51:
L49:
.dbline 296
;
; /* Check for a request for "/". */
; if(uip_appdata[5] == ISO_slash && uip_appdata[6] == 0)
lds R30,_uip_appdata
lds R31,_uip_appdata+1
ldd R24,z+5
cpi R24,47
brne L52
lds R30,_uip_appdata
lds R31,_uip_appdata+1
ldd R2,z+6
tst R2
brne L52
.dbline 297
; {
.dbline 299
; //load_web_page(index_html);
; fs_open(file_index_html.name, &fsfile);
movw R18,R28
subi R18,248 ; offset = 8
sbci R19,255
lds R16,_file_index_html+2
lds R17,_file_index_html+2+1
xcall _fs_open
.dbline 300
; }
xjmp L41
L52:
.dbline 302
; else
; {
.dbline 303
; i=6;
ldi R24,6
ldi R25,0
movw R10,R24
xjmp L56
L55:
.dbline 305
.dbline 306
lds R2,_uip_appdata
lds R3,_uip_appdata+1
movw R30,R10
add R30,R2
adc R31,R3
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -