?? httpd.lst
字號(hào):
171 3 PRINTLN(&uip_appdata[4]);
172 3
173 3 if(!fs_open((char *)&uip_appdata[4], &fsfile))
174 3 {
175 4 PRINTLN("couldn't open file");
176 4 fs_open(file_index_html.name, &fsfile);
177 4 }
178 3
179 3 if(uip_appdata[4] == ISO_slash &&
C51 COMPILER V7.08 HTTPD 12/26/2003 07:27:15 PAGE 4
180 3 uip_appdata[5] == ISO_c &&
181 3 uip_appdata[6] == ISO_g &&
182 3 uip_appdata[7] == ISO_i &&
183 3 uip_appdata[8] == ISO_slash)
184 3 {
185 4 /* If the request is for a file that starts with "/cgi/", we
186 4 prepare for invoking a script. */
187 4 hs->script = fsfile.databuffer;
188 4 next_scriptstate();
189 4 } else
190 3 {
191 4 hs->script = NULL;
192 4 /* The web server is now no longer in the HTTP_NOGET state, but
193 4 in the HTTP_FILE state since is has now got the GET from
194 4 the client and will start transmitting the file. */
195 4 hs->state = HTTP_FILE;
196 4
197 4 /* Point the file pointers in the connection state to point to
198 4 the first byte of the file. */
199 4 hs->dataptr = fsfile.databuffer;
200 4 hs->count = fsfile.len;
201 4 }
202 3 }
203 2
204 2 if(hs->state != HTTP_FUNC)
205 2 {
206 3 /* Check if the client (remote end) has acknowledged any data that
207 3 we've previously sent. If so, we move the file pointer further
208 3 into the file and send back more data. If we are out of data to
209 3 send, we close the connection. */
210 3 if(uip_acked())
211 3 {
212 4 if(hs->count >= uip_mss())
213 4 {
214 5 hs->count -= uip_mss();
215 5 hs->dataptr += uip_mss();
216 5 } else
217 4 {
218 5 hs->count = 0;
219 5 }
220 4
221 4 if(hs->count == 0)
222 4 {
223 5 if(hs->script != NULL)
224 5 {
225 6 next_scriptline();
226 6 next_scriptstate();
227 6 } else
228 5 {
229 6 uip_close();
230 6 }
231 5 }
232 4 }
233 3 }
234 2
235 2 if(hs->state == HTTP_FUNC)
236 2 {
237 3 /* Call the CGI function. */
238 3 if(cgitab[hs->script[2] - ISO_a]())
239 3 {
240 4 /* If the function returns non-zero, we jump to the next line
241 4 in the script. */
C51 COMPILER V7.08 HTTPD 12/26/2003 07:27:15 PAGE 5
242 4 next_scriptline();
243 4 next_scriptstate();
244 4 }
245 3 }
246 2
247 2 if(hs->state != HTTP_FUNC && !uip_poll())
248 2 {
249 3 /* Send a piece of data, but not more than the MSS of the
250 3 connection. */
251 3 uip_send(hs->dataptr,
252 3 hs->count > uip_mss()? uip_mss(): hs->count);
253 3 }
254 2 /* Finally, return to uIP. Our outgoing packet will soon be on its
255 2 way... */
256 2 return;
257 2
258 2 default:
259 2 /* Should never happen. */
260 2 uip_abort();
261 2 break;
262 2 }
263 1 }
264 /*-----------------------------------------------------------------------------------*/
265 /* next_scriptline():
266 *
267 * Reads the script until it finds a newline. */
268 static void
269 next_scriptline(void)
270 {
271 1 /* Loop until we find a newline character. */
272 1 do {
273 2 ++(hs->script);
274 2 } while(hs->script[0] != ISO_nl);
275 1
276 1 /* Eat up the newline as well. */
277 1 ++(hs->script);
278 1 }
279 /*-----------------------------------------------------------------------------------*/
280 /* next_sciptstate:
281 *
282 * Reads one line of script and decides what to do next.
283 */
284 static void
285 next_scriptstate(void)
286 {
287 1 struct fs_file fsfile;
288 1 u8_t i;
289 1
290 1 again:
291 1 switch(hs->script[0]) {
292 2 case ISO_t:
293 2 /* Send a text string. */
294 2 hs->state = HTTP_TEXT;
295 2 hs->dataptr = &hs->script[2];
296 2
297 2 /* Calculate length of string. */
298 2 for(i = 0; hs->dataptr[i] != ISO_nl; ++i);
299 2 hs->count = i;
300 2 break;
301 2 case ISO_c:
302 2 /* Call a function. */
303 2 hs->state = HTTP_FUNC;
C51 COMPILER V7.08 HTTPD 12/26/2003 07:27:15 PAGE 6
304 2 hs->dataptr = NULL;
305 2 hs->count = 0;
306 2 uip_reset_acked();
307 2 break;
308 2 case ISO_i:
309 2 /* Include a file. */
310 2 hs->state = HTTP_FILE;
311 2 if(!fs_open(&hs->script[2], &fsfile)) {
312 3 uip_abort();
313 3 }
314 2 hs->dataptr = fsfile.databuffer;
315 2 hs->count = fsfile.len;
316 2 break;
317 2 case ISO_hash:
318 2 /* Comment line. */
319 2 next_scriptline();
320 2 goto again;
321 2 break;
322 2 case ISO_period:
323 2 /* End of script. */
324 2 hs->state = HTTP_END;
325 2 uip_close();
326 2 break;
327 2 default:
328 2 uip_abort();
329 2 break;
330 2 }
331 1 }
332 /*-----------------------------------------------------------------------------------*/
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1517 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 3 10
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -