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

📄 httpd.lst

📁 STC51系列的源码
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.02   HTTPD                                                                 10/28/2008 15:31:40 PAGE 1   


C51 COMPILER V8.02, COMPILATION OF MODULE HTTPD
OBJECT MODULE PLACED IN .\out\httpd.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE httpd.c LARGE OPTIMIZE(SIZE) BROWSE DEBUG OBJECTEXTEND PRINT(.\out\httpd.ls
                    -t) OBJECT(.\out\httpd.obj)

line level    source

   1          #include "../CPU/CPU.h"
   2          #include "../CFG/CFG.h"
   3          #include "../UART/UART.h"
   4          
   5          #include "uip.h"
   6          #include "httpd.h"
   7          #include "fs.h"
   8          #include "fsdata.h"
   9          #include "cgi.h"
  10          
  11          
  12          /* The HTTP server states: */
  13          #define HTTP_NOGET        0
  14          #define HTTP_FILE         1
  15          #define HTTP_TEXT         2
  16          #define HTTP_FUNC         3
  17          #define HTTP_END          4
  18          
  19          #define DEBUG 1
  20          
  21          #ifdef DEBUG
  22          #include <stdio.h>
  23          #define PRINT(x) UART_printf("%s", x)
  24          #define PRINTLN(x) UART_printf("%s\n", x)
  25          #else /* DEBUG */
              #define PRINT(x)
              #define PRINTLN(x)
              #endif /* DEBUG */
  29          
  30          struct httpd_state *hs;
  31          
  32          static void next_scriptline(void);
  33          static void next_scriptstate(void);
  34          
  35          #define ISO_G        0x47
  36          #define ISO_E        0x45
  37          #define ISO_T        0x54
  38          #define ISO_slash    0x2f    
  39          #define ISO_c        0x63
  40          #define ISO_g        0x67
  41          #define ISO_i        0x69
  42          #define ISO_space    0x20
  43          #define ISO_nl       0x0a
  44          #define ISO_cr       0x0d
  45          #define ISO_a        0x61
  46          #define ISO_t        0x74
  47          #define ISO_hash     0x23
  48          #define ISO_period   0x2e
  49          
  50          
  51          /*-----------------------------------------------------------------------------------*/
  52          /**
  53           * Initialize the web server.
  54           *
C51 COMPILER V8.02   HTTPD                                                                 10/28/2008 15:31:40 PAGE 2   

  55           * Starts to listen for incoming connection requests on TCP port 80.
  56           */
  57          /*-----------------------------------------------------------------------------------*/
  58          void
  59          httpd_init(void)
  60          {
  61   1        fs_init();
  62   1        
  63   1        /* Listen to port 80. */
  64   1        uip_listen(HTONS(80));
  65   1      }
  66          /*-----------------------------------------------------------------------------------*/
  67          void
  68          httpd_appcall(void)
  69          {   u8_t status=0x0;
  70   1          struct fs_file   fsfile;  
  71   1          
  72   1          u8_t   i;
  73   1          
  74   1          switch(uip_conn->lport) 
  75   1          {
  76   2          case HTONS(80):
  77   2              /* Pick out the application state from the uip_conn structure. */
  78   2              hs = (struct httpd_state *)(uip_conn->appstate);
  79   2              
  80   2              /* We use the uip_ test functions to deduce why we were
  81   2              called. If uip_connected() is non-zero, we were called
  82   2              because a remote host has connected to us. If
  83   2              uip_newdata() is non-zero, we were called because the
  84   2              remote host has sent us new data, and if uip_acked() is
  85   2              non-zero, the remote host has acknowledged the data we
  86   2              previously sent to it. */
  87   2              if(uip_connected()) 
  88   2              {
  89   3                  /* Since we have just been connected with the remote host, we
  90   3                  reset the state for this connection. The ->count variable
  91   3                  contains the amount of data that is yet to be sent to the
  92   3                  remote host, and the ->state is set to HTTP_NOGET to signal
  93   3                  that we haven't received any HTTP GET request for this
  94   3                  connection yet. */
  95   3                  hs->state = HTTP_NOGET;
  96   3                  hs->count = 0;
  97   3                  return;
  98   3              
  99   3              } 
 100   2              else if(uip_poll()) 
 101   2              {
 102   3                  /* If we are polled ten times, we abort the connection. This is
 103   3                  because we don't want connections lingering indefinately in
 104   3                  the system. */
 105   3                  if(hs->count++ >= 10) 
 106   3                  {
 107   4                          uip_abort();
 108   4                  }
 109   3                  return;
 110   3              } 
 111   2              else if(uip_newdata() && hs->state == HTTP_NOGET) 
 112   2              {
 113   3                  /* This is the first data we receive, and it should contain a GET. */
 114   3              
 115   3                  /* Check for GET. */
 116   3                  if(uip_appdata[0] != ISO_G ||
C51 COMPILER V8.02   HTTPD                                                                 10/28/2008 15:31:40 PAGE 3   

 117   3                      uip_appdata[1] != ISO_E ||
 118   3                      uip_appdata[2] != ISO_T ||
 119   3                      uip_appdata[3] != ISO_space) 
 120   3                      {
 121   4                          /* If it isn't a GET, we abort the connection. */
 122   4                          uip_abort();
 123   4                          return;
 124   4                  }
 125   3                       
 126   3                  /* Find the file we are looking for. */
 127   3                  for(i = 4; i < 40; ++i) 
 128   3                  {
 129   4                          if(uip_appdata[i] == ISO_space ||uip_appdata[i] == ISO_cr ||uip_appdata[i] == ISO_nl) 
 130   4                          {
 131   5                              uip_appdata[i] = 0;
 132   5                              break;
 133   5                          }
 134   4                  }
 135   3          
 136   3                  PRINT("request for file ");
 137   3                  PRINTLN(&uip_appdata[4]);
 138   3              
 139   3                  /* Check for a request for "/". */
 140   3                  if(uip_appdata[4] == ISO_slash &&uip_appdata[5] == 0) 
 141   3                  {   fs_open((*file_index_html).name, &fsfile);
 142   4                  } 
 143   3                  else 
 144   3                  {
 145   4                          if(!fs_open((const char *)&uip_appdata[4], &fsfile)) 
 146   4                          {
 147   5                              PRINTLN("couldn't open file");
 148   5                              fs_open((*file_404_html).name, &fsfile);
 149   5                          }
 150   4                  } 
 151   3          
 152   3          
 153   3                  if(uip_appdata[4] == ISO_slash &&uip_appdata[5] == ISO_c &&uip_appdata[6] == ISO_g &&uip_appda
             -ta[7] == ISO_i && uip_appdata[8] == ISO_slash)
 154   3                      {
 155   4                          /* If the request is for a file that starts with "/cgi/", we
 156   4                      prepare for invoking a script. */       
 157   4                          hs->script = fsfile.dat;
 158   4                          next_scriptstate();
 159   4                          
 160   4                  } 
 161   3                  else 
 162   3                  {
 163   4                          hs->script = NULL;
 164   4                          /* The web server is now no longer in the HTTP_NOGET state, but
 165   4                             in the HTTP_FILE state since is has now got the GET from
 166   4                             the client and will start transmitting the file. */
 167   4                          hs->state = HTTP_FILE;
 168   4                      
 169   4                          /* Point the file pointers in the connection state to point to
 170   4                             the first byte of the file. */
 171   4                          hs->dataptr = fsfile.dat;
 172   4                          hs->count = fsfile.len;     
 173   4                  }     

⌨️ 快捷键说明

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