?? httpd.lst
字號:
C51 COMPILER V7.08 HTTPD 12/26/2003 07:27:15 PAGE 1
C51 COMPILER V7.08, COMPILATION OF MODULE HTTPD
OBJECT MODULE PLACED IN httpd.OBJ
COMPILER INVOKED BY: C:\Keil708\C51\BIN\C51.EXE httpd.c LARGE BROWSE DEBUG OBJECTEXTEND
line level source
1 /*
2 * Copyright (c) 2001, Adam Dunkels.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Adam Dunkels.
16 * 4. The name of the author may not be used to endorse or promote
17 * products derived from this software without specific prior
18 * written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
21 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
26 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 * This file is part of the uIP TCP/IP stack.
33 *
34 * $Id: httpd.c,v 1.1.1.1 2003/04/15 02:11:56 qs Exp $
35 *
36 */
37
38 #include "uip.h"
39 #include "httpd.h"
40 #include "fs.h"
41 #include "fsdata.h"
42 #include "cgi.h"
43
44 #define NULL (void *)0
45
46 /* The HTTP server states: */
47 #define HTTP_NOGET 0
48 #define HTTP_FILE 1
49 #define HTTP_TEXT 2
50 #define HTTP_FUNC 3
51 #define HTTP_END 4
52
53 //#define DEBUG
54
55 #ifdef DEBUG
C51 COMPILER V7.08 HTTPD 12/26/2003 07:27:15 PAGE 2
#include <stdio.h>
#define PRINT(x) printf("%s", x)
#define PRINTLN(x) printf("%s\n", x)
#else /* DEBUG */
60 #define PRINT(x)
61 #define PRINTLN(x)
62 #endif /* DEBUG */
63
64 struct httpd_state *hs;
65
66 extern code struct fsdata_file file_index_html;
67
68 static void next_scriptline(void);
69 static void next_scriptstate(void);
70
71 #define ISO_G 0x47
72 #define ISO_E 0x45
73 #define ISO_T 0x54
74 #define ISO_slash 0x2f
75 #define ISO_c 0x63
76 #define ISO_g 0x67
77 #define ISO_i 0x69
78 #define ISO_space 0x20
79 #define ISO_nl 0x0a
80 #define ISO_cr 0x0d
81 #define ISO_a 0x61
82 #define ISO_t 0x74
83 #define ISO_hash 0x23
84 #define ISO_period 0x2e
85
86
87 /*-----------------------------------------------------------------------------------*/
88 void
89 httpd_init(void)
90 {
91 1 fs_init();
92 1
93 1 /* Listen to port 80. */
94 1 uip_listen(80);
95 1 }
96 /*-----------------------------------------------------------------------------------*/
97 void
98 httpd(void)
99 {
100 1 struct fs_file fsfile;
101 1 u8_t i;
102 1
103 1 PRINTLN("httpd start ");
104 1 switch(uip_conn->lport)
105 1 {
106 2 /* This is the web server: */
107 2 case htons(80):
108 2 /* Pick out the application state from the uip_conn structure. */
109 2 hs = (struct httpd_state *)(uip_conn->appstate);
110 2
111 2 /* We use the uip_ test functions to deduce why we were
112 2 called. If uip_connected() is non-zero, we were called
113 2 because a remote host has connected to us. If
114 2 uip_newdata() is non-zero, we were called because the
115 2 remote host has sent us new data, and if uip_acked() is
116 2 non-zero, the remote host has acknowledged the data we
117 2 previously sent to it. */
C51 COMPILER V7.08 HTTPD 12/26/2003 07:27:15 PAGE 3
118 2 if(uip_connected())
119 2 {
120 3 /* Since we have just been connected with the remote host, we
121 3 reset the state for this connection. The ->count variable
122 3 contains the amount of data that is yet to be sent to the
123 3 remote host, and the ->state is set to HTTP_NOGET to signal
124 3 that we haven't received any HTTP GET request for this
125 3 connection yet. */
126 3 hs->state = HTTP_NOGET;
127 3 hs->count = 0;
128 3 /* Don't send any data in return; we wait for the HTTP request
129 3 instead. */
130 3 uip_send(uip_appdata, 0);
131 3 return;
132 3 } else if(uip_poll())
133 2 {
134 3 /* If we are polled ten times, we abort the connection. This is
135 3 because we don't want connections lingering indefinately in
136 3 the system. */
137 3 if(hs->count++ >= 10)
138 3 {
139 4 uip_abort();
140 4 }
141 3 return;
142 3 } else if(uip_newdata() && hs->state == HTTP_NOGET)
143 2 {
144 3 /* This is the first data we receive, and it should contain a
145 3 GET. */
146 3
147 3 /* Check for GET. */
148 3 if(uip_appdata[0] != ISO_G ||
149 3 uip_appdata[1] != ISO_E ||
150 3 uip_appdata[2] != ISO_T ||
151 3 uip_appdata[3] != ISO_space)
152 3 {
153 4 /* If it isn't a GET, we abort the connection. */
154 4 uip_abort();
155 4 return;
156 4 }
157 3
158 3 /* Find the file we are looking for. */
159 3 for(i = 4; i < 40; ++i)
160 3 {
161 4 if(uip_appdata[i] == ISO_space ||
162 4 uip_appdata[i] == ISO_cr ||
163 4 uip_appdata[i] == ISO_nl)
164 4 {
165 5 uip_appdata[i] = 0;
166 5 break;
167 5 }
168 4 }
169 3
170 3 PRINT("request for file ");
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -