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

📄 httpd.lst

📁 58enc28j06protuesuip09.rar
💻 LST
📖 第 1 页 / 共 2 页
字号:
 189   3            return;
 190   3          } else if(uip_newdata() && hs->state == HTTP_NOGET) {
 191   3            /* This is the first data we receive, and it should contain a
 192   3               GET. */
 193   3            
 194   3            /* Check for GET. */
 195   3            if(uip_appdata[0] != ISO_G ||
 196   3               uip_appdata[1] != ISO_E ||
 197   3               uip_appdata[2] != ISO_T ||
 198   3               uip_appdata[3] != ISO_space) {
 199   4              /* If it isn't a GET, we abort the connection. */
 200   4              uip_abort();
 201   4              return;
 202   4            }
 203   3                     
 204   3            /* Find the file we are looking for. */
 205   3            for(i = 4; i < 40; ++i) {
 206   4              if(uip_appdata[i] == ISO_space ||
 207   4                 uip_appdata[i] == ISO_cr ||
 208   4                 uip_appdata[i] == ISO_nl) {
 209   5                uip_appdata[i] = 0;
 210   5                break;
 211   5              }
 212   4            }
 213   3      
 214   3            PRINT("request for file ");
 215   3            PRINTLN(&uip_appdata[4]);
 216   3            
 217   3            /* Check for a request for "/". */
 218   3            if(uip_appdata[4] == ISO_slash &&
 219   3               uip_appdata[5] == 0) {
 220   4              fs_open(file_index_html->name, &fsfile);    
 221   4            } else {
 222   4              if(!fs_open((const char *)&uip_appdata[4], &fsfile)) {
 223   5                PRINTLN("couldn't open file");
 224   5                fs_open(file_404_html->name, &fsfile);
 225   5              }
 226   4            } 
 227   3      
 228   3      
 229   3            if(uip_appdata[4] == ISO_slash &&
 230   3               uip_appdata[5] == ISO_c &&
 231   3               uip_appdata[6] == ISO_g &&
 232   3               uip_appdata[7] == ISO_i &&
 233   3               uip_appdata[8] == ISO_slash) {
 234   4              /* If the request is for a file that starts with "/cgi/", we
 235   4                 prepare for invoking a script. */    
 236   4              hs->script = fsfile.dat;
 237   4              next_scriptstate();
 238   4            } else {
 239   4              hs->script = NULL;
 240   4              /* The web server is now no longer in the HTTP_NOGET state, but
C51 COMPILER V8.16   HTTPD                                                                 03/16/2009 23:18:13 PAGE 5   

 241   4                 in the HTTP_FILE state since is has now got the GET from
 242   4                 the client and will start transmitting the file. */
 243   4              hs->state = HTTP_FILE;
 244   4      
 245   4              /* Point the file pointers in the connection state to point to
 246   4                 the first byte of the file. */
 247   4              hs->dataptr = fsfile.dat;
 248   4              hs->count = fsfile.len; 
 249   4            }     
 250   3          }
 251   2      
 252   2          
 253   2          if(hs->state != HTTP_FUNC) {
 254   3            /* Check if the client (remote end) has acknowledged any data that
 255   3               we've previously sent. If so, we move the file pointer further
 256   3               into the file and send back more data. If we are out of data to
 257   3               send, we close the connection. */
 258   3            if(uip_acked()) {
 259   4              if(hs->count >= uip_conn->len) {
 260   5                hs->count -= uip_conn->len;
 261   5                hs->dataptr += uip_conn->len;
 262   5              } else {
 263   5                hs->count = 0;
 264   5              }
 265   4              
 266   4              if(hs->count == 0) {
 267   5                if(hs->script != NULL) {
 268   6                  next_scriptline();
 269   6                  next_scriptstate();
 270   6                } else {
 271   6                  uip_close();
 272   6                }
 273   5              }
 274   4            }         
 275   3          } else {
 276   3            /* Call the CGI function. */
 277   3            if(cgitab[hs->script[2] - ISO_a](uip_acked())) {
 278   4              /* If the function returns non-zero, we jump to the next line
 279   4                 in the script. */
 280   4              next_scriptline();
 281   4              next_scriptstate();
 282   4            }
 283   3          }
 284   2      
 285   2          if(hs->state != HTTP_FUNC && !uip_poll()) {
 286   3            /* Send a piece of data, but not more than the MSS of the
 287   3               connection. */
 288   3            uip_send(hs->dataptr, hs->count);
 289   3          }
 290   2      
 291   2          /* Finally, return to uIP. Our outgoing packet will soon be on its
 292   2             way... */
 293   2          return;
 294   2      
 295   2        default:
 296   2          /* Should never happen. */
 297   2          uip_abort();
 298   2          break;
 299   2        }  
 300   1      }
 301          /*-----------------------------------------------------------------------------------*/
 302          /* next_scriptline():
C51 COMPILER V8.16   HTTPD                                                                 03/16/2009 23:18:13 PAGE 6   

 303           *
 304           * Reads the script until it finds a newline. */
 305          static void
 306          next_scriptline(void)
 307          {
 308   1        /* Loop until we find a newline character. */
 309   1        do {
 310   2          ++(hs->script);
 311   2        } while(hs->script[0] != ISO_nl);
 312   1      
 313   1        /* Eat up the newline as well. */
 314   1        ++(hs->script);
 315   1      }
 316          /*-----------------------------------------------------------------------------------*/
 317          /* next_sciptstate:
 318           *
 319           * Reads one line of script and decides what to do next.
 320           */
 321          static void
 322          next_scriptstate(void)
 323          {
 324   1        struct fs_file fsfile;
 325   1        u8_t i;
 326   1      
 327   1       again:
 328   1        switch(hs->script[0]) {
 329   2        case ISO_t:
 330   2          /* Send a text string. */
 331   2          hs->state = HTTP_TEXT;
 332   2          hs->dataptr = &hs->script[2];
 333   2      
 334   2          /* Calculate length of string. */
 335   2          for(i = 0; hs->dataptr[i] != ISO_nl; ++i);
 336   2          hs->count = i;    
 337   2          break;
 338   2        case ISO_c:
 339   2          /* Call a function. */
 340   2          hs->state = HTTP_FUNC;
 341   2          hs->dataptr = NULL;
 342   2          hs->count = 0;
 343   2          cgitab[hs->script[2] - ISO_a](0);
 344   2          break;
 345   2        case ISO_i:   
 346   2          /* Include a file. */
 347   2          hs->state = HTTP_FILE;
 348   2          if(!fs_open(&hs->script[2], &fsfile)) {
 349   3            uip_abort();
 350   3          }
 351   2          hs->dataptr = fsfile.dat;
 352   2          hs->count = fsfile.len;
 353   2          break;
 354   2        case ISO_hash:
 355   2          /* Comment line. */
 356   2          next_scriptline();
 357   2          goto again;
 358   2          break;
 359   2        case ISO_period:
 360   2          /* End of script. */
 361   2          hs->state = HTTP_END;
 362   2          uip_close();
 363   2          break;
 364   2        default:
C51 COMPILER V8.16   HTTPD                                                                 03/16/2009 23:18:13 PAGE 7   

 365   2          uip_abort();
 366   2          break;
 367   2        }
 368   1      }
 369          /*-----------------------------------------------------------------------------------*/
 370          /** @} */
 371          /** @} */


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1523    ----
   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)

⌨️ 快捷键说明

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