⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httpd.lst

📁 58enc28j06protuesuip09.rar
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.16   HTTPD                                                                 03/16/2009 23:18:13 PAGE 1   


C51 COMPILER V8.16, COMPILATION OF MODULE HTTPD
OBJECT MODULE PLACED IN .\debug\httpd.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE httpd.c LARGE BROWSE DEBUG OBJECTEXTEND PRINT(.\debug\httpd.lst) OBJECT(.\d
                    -ebug\httpd.obj)

line level    source

   1          /**
   2           * \addtogroup exampleapps
   3           * @{
   4           */
   5          
   6          /**
   7           * \defgroup httpd Web server
   8           * @{
   9           *
  10           * The uIP web server is a very simplistic implementation of an HTTP
  11           * server. It can serve web pages and files from a read-only ROM
  12           * filesystem, and provides a very small scripting language.
  13           *
  14           * The script language is very simple and works as follows. Each
  15           * script line starts with a command character, either "i", "t", "c",
  16           * "#" or ".".  The "i" command tells the script interpreter to
  17           * "include" a file from the virtual file system and output it to the
  18           * web browser. The "t" command should be followed by a line of text
  19           * that is to be output to the browser. The "c" command is used to
  20           * call one of the C functions from the httpd-cgi.c file. A line that
  21           * starts with a "#" is ignored (i.e., the "#" denotes a comment), and
  22           * the "." denotes the last script line.
  23           *
  24           * The script that produces the file statistics page looks somewhat
  25           * like this:
  26           *
  27           \code
  28          i /header.html
  29          t <h1>File statistics</h1><br><table width="100%">
  30          t <tr><td><a href="/index.html">/index.html</a></td><td>
  31          c a /index.html
  32          t </td></tr> <tr><td><a href="/cgi/files">/cgi/files</a></td><td>
  33          c a /cgi/files
  34          t </td></tr> <tr><td><a href="/cgi/tcp">/cgi/tcp</a></td><td>
  35          c a /cgi/tcp
  36          t </td></tr> <tr><td><a href="/404.html">/404.html</a></td><td>
  37          c a /404.html
  38          t </td></tr></table>
  39          i /footer.plain
  40          .
  41           \endcode
  42           *
  43           */
  44          
  45          
  46          /**
  47           * \file
  48           * HTTP server.
  49           * \author Adam Dunkels <adam@dunkels.com>
  50           */
  51          
  52          /*
  53           * Copyright (c) 2001, Adam Dunkels.
  54           * All rights reserved. 
C51 COMPILER V8.16   HTTPD                                                                 03/16/2009 23:18:13 PAGE 2   

  55           *
  56           * Redistribution and use in source and binary forms, with or without 
  57           * modification, are permitted provided that the following conditions 
  58           * are met: 
  59           * 1. Redistributions of source code must retain the above copyright 
  60           *    notice, this list of conditions and the following disclaimer. 
  61           * 2. Redistributions in binary form must reproduce the above copyright 
  62           *    notice, this list of conditions and the following disclaimer in the 
  63           *    documentation and/or other materials provided with the distribution. 
  64           * 3. The name of the author may not be used to endorse or promote
  65           *    products derived from this software without specific prior
  66           *    written permission.  
  67           *
  68           * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
  69           * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  70           * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  71           * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  72           * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  73           * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  74           * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  75           * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  76           * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  77           * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  78           * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
  79           *
  80           * This file is part of the uIP TCP/IP stack.
  81           *
  82           * $Id: httpd.c,v 1.28.2.6 2003/10/07 13:22:27 adam Exp $
  83           *
  84           */
  85          
  86          
  87          #include "uip.h"
  88          #include "httpd.h"
  89          #include "fs.h"
  90          #include "fsdata.h"
  91          #include "cgi.h"
  92          
  93          #define NULL (void *)0
  94          
  95          /* The HTTP server states: */
  96          #define HTTP_NOGET        0
  97          #define HTTP_FILE         1
  98          #define HTTP_TEXT         2
  99          #define HTTP_FUNC         3
 100          #define HTTP_END          4
 101          
 102          #ifdef DEBUG
              #include <stdio.h>
              #define PRINT(x) printf("%s", x)
              #define PRINTLN(x) printf("%s\n", x)
              #else /* DEBUG */
 107          #define PRINT(x)
 108          #define PRINTLN(x)
 109          #endif /* DEBUG */
 110          
 111          struct httpd_state *hs;
 112          
 113          //extern const struct fsdata_file file_index_html;
 114          //extern const struct fsdata_file file_404_html;
 115          
 116          static void next_scriptline(void);
C51 COMPILER V8.16   HTTPD                                                                 03/16/2009 23:18:13 PAGE 3   

 117          static void next_scriptstate(void);
 118          
 119          #define ISO_G        0x47
 120          #define ISO_E        0x45
 121          #define ISO_T        0x54
 122          #define ISO_slash    0x2f    
 123          #define ISO_c        0x63
 124          #define ISO_g        0x67
 125          #define ISO_i        0x69
 126          #define ISO_space    0x20
 127          #define ISO_nl       0x0a
 128          #define ISO_cr       0x0d
 129          #define ISO_a        0x61
 130          #define ISO_t        0x74
 131          #define ISO_hash     0x23
 132          #define ISO_period   0x2e
 133          
 134          
 135          /*-----------------------------------------------------------------------------------*/
 136          /**
 137           * Initialize the web server.
 138           *
 139           * Starts to listen for incoming connection requests on TCP port 80.
 140           */
 141          /*-----------------------------------------------------------------------------------*/
 142          void
 143          httpd_init(void)
 144          {
 145   1        fs_init();
 146   1        
 147   1        /* Listen to port 80. */
 148   1        uip_listen(HTONS(80));
 149   1      }
 150          /*-----------------------------------------------------------------------------------*/
 151          void
 152          httpd_appcall(void)
 153          {
 154   1        struct fs_file fsfile;  
 155   1      
 156   1        u8_t i;
 157   1      
 158   1        switch(uip_conn->lport) {
 159   2          /* This is the web server: */
 160   2        case HTONS(80):
 161   2          /* Pick out the application state from the uip_conn structure. */
 162   2          hs = (struct httpd_state *)(uip_conn->appstate);
 163   2      
 164   2          /* We use the uip_ test functions to deduce why we were
 165   2             called. If uip_connected() is non-zero, we were called
 166   2             because a remote host has connected to us. If
 167   2             uip_newdata() is non-zero, we were called because the
 168   2             remote host has sent us new data, and if uip_acked() is
 169   2             non-zero, the remote host has acknowledged the data we
 170   2             previously sent to it. */
 171   2          if(uip_connected()) {
 172   3            /* Since we have just been connected with the remote host, we
 173   3               reset the state for this connection. The ->count variable
 174   3               contains the amount of data that is yet to be sent to the
 175   3               remote host, and the ->state is set to HTTP_NOGET to signal
 176   3               that we haven't received any HTTP GET request for this
 177   3               connection yet. */
 178   3            hs->state = HTTP_NOGET;
C51 COMPILER V8.16   HTTPD                                                                 03/16/2009 23:18:13 PAGE 4   

 179   3            hs->count = 0;
 180   3            return;
 181   3      
 182   3          } else if(uip_poll()) {
 183   3            /* If we are polled ten times, we abort the connection. This is
 184   3               because we don't want connections lingering indefinately in
 185   3               the system. */
 186   3            if(hs->count++ >= 10) {
 187   4              uip_abort();
 188   4            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -