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

📄 webserve.lst

📁 世纪民生公司的带网络功能的单片机CS6209开发http服务器的演示源代码。
💻 LST
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V7.50   WEBSERVE                                                              10/12/2006 15:31:42 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE WEBSERVE
OBJECT MODULE PLACED IN .\Release\Webserve.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ..\..\lib\httpserver\Webserve.c LARGE OPTIMIZE(9,SIZE) BROWSE ORDER MODDP2 
                    -INCDIR(..\..\inc\) DEBUG OBJECTEXTEND PRINT(.\Release\Webserve.lst) OBJECT(.\Release\Webserve.obj)

line level    source

   1          /*
   2           * 
   3           * webserve.c
   4           * 
   5           * Part of the Myson Century CS620X     demo program.
   6           *
   7           * Authors: LY Lin, WM Wang, IJ Chen, WH Lee
   8           *
   9           * webserve.c contains HTTP server routines.
  10           *
  11           * This program was developed using the Keil 8051 C uVision 2 system.
  12           * The Keil compiler MUST be used if working with Myson Century supplied
  13           * firmware.
  14           *
  15           *
  16           * This program must be linked with the 620xlib.LIB library 
  17           * supplied     by Myson Century in object module form.   
  18           *
  19          */
  20          #include <stdio.h>
  21          #include <ctype.h>
  22          #include <stdlib.h>
  23          #include <string.h>
  24          
  25          #include "hpserver.h"
  26          #include "timer.h"
  27          #include "ether.h"
  28          #include "netutil.h"
  29          #include "net.h"
  30          #include "ip.h"
  31          #include "tcp.h"
  32          #include "config.h"
  33          #include "http.h"
  34          #include "strutil.h"
  35          #include "hwi2c.h"
  36          #include "libif.h"
  37          
  38          /*MAX file path length.*/
  39          #define MAXPATH 128
  40          char filepath[MAXPATH+1];           /* Filename */
  41          char httpreq[HTTP_MAXLEN+1];        /* Buffer for first part of HTTP request */
  42          char egibuff[EGI_BUFFLEN+1];            /* Buffer for EGI */
  43          
  44          int webdebug=1;                       /* Web (HTTP) diagnostic display */
  45          /*File table in system.*/
  46          extern RAM_WEB_PAGE web_page_table [];
  47          
  48          
  49          
  50          
  51          /* Prototypes */
  52          int http_server(TSOCK *ts, CONN_STATE conn);
  53          void http_get(TSOCK *ts, char *fname);
  54          char http_data(TSOCK *ts);
C51 COMPILER V7.50   WEBSERVE                                                              10/12/2006 15:31:42 PAGE 2   

  55          WORD buff_infile(CBUFF *bp, APPDATA *adp);
  56          void Init_HTML_pages();
  57          void I2cmemcpy(unsigned char *dest,unsigned char * src,unsigned int len);
  58          void vfat_mem_cpy(unsigned char *dest,unsigned char * src,unsigned int len);
  59          int egi_execstr(TSOCK xdata *ts, char xdata *str);
  60          RAM_WEB_PAGE * search_get_web_page (unsigned char *p);
  61          
  62          
  63          /************************************************************************
  64          /*      Function Name : http_server                                                                                     *
  65          /*                                                                                                                                              *
  66          /*      Arguments :                                                                                                             *
  67          /*                      TSOCK *ts:Point to current socket.                                                      *
  68          /*                      CONN_STATE conn:the connect state of current socket                     *
  69          /*                                                                                                                                              *
  70          /*      Return :                                                                                                                        *
  71          /*                      Return 0 to force close current socket                                          *
  72          /*  Comment :                                                                                                                   *
  73          /*                      This function is a call back function for HTTP server.          *
  74          /*                **Don't call this function immediately.                                               *
  75          /*                                                                                                                                              *
  76          /************************************************************************/
  77          int http_server(TSOCK *ts, CONN_STATE conn)
  78          {
  79   1          WORD port,len;
  80   1          char *s, *name;
  81   1          APPDATA *adp;
  82   1          void *ptr;
  83   1          port = ts->loc.port;
  84   1          adp = &appdata[ts->index-1];
  85   1              ts->app=adp;
  86   1          if (conn == TCP_OPEN)
  87   1          {
  88   2              ptr = adp->vars;
  89   2              memset(adp, 0, sizeof(APPDATA));
  90   2              adp->vars = ptr;
  91   2          }
  92   1          else if (conn == TCP_DATA)
  93   1          {
  94   2      #if NO_SOCKET_RXB
                              /* search for the \n*/
                      if ((s = strtok(ts->rxb.b_data, "\n"))!=0) /* Got request? */
                              {
              #else
  99   2              if ((len = buff_chrlen(&ts->rxb, '\n'))!=0) /* Got request? */
 100   2              {
 101   3                      s = httpreq;
 102   3                  len = mini(len+1, HTTP_MAXLEN);         /* Truncate length */
 103   3                  buff_out(&ts->rxb, (BYTE *)httpreq, (WORD)len);
 104   3                  httpreq[len] = 0;
 105   3      #endif
 106   3                  if (webdebug)                           /* Display if debugging */
 107   3                      printf("%s\n", s);
 108   3                  s = strtok(s, " ");               /* Chop into tokens */
 109   3                  if (!strcmp(s, "GET"))                  /* 1st token is 'GET'? */
 110   3                  {
 111   4                              name = s+4; 
 112   4                      name = strtok(0, " \r\n");        /* 2nd token is filename */
 113   4                      http_get(ts, name);                 /* Process filename */
 114   4                  }
 115   3              }
 116   2          }
C51 COMPILER V7.50   WEBSERVE                                                              10/12/2006 15:31:42 PAGE 3   

 117   1          return ((int)http_data(ts));
 118   1      }
 119          
 120          /************************************************************************
 121          /*      Function Name : http_get                                                                                        *
 122          /*                                                                                                                                              *
 123          /*      Arguments :                                                                                                             *
 124          /*                      TSOCK *ts:Point to socket.                                                                      *
 125          /*                      char *fname:File name string.                                                           *
 126          /*                                                                                                                                              *
 127          /*      Return :                                                                                                                        *
 128          /*                      None.                                                                                                           *
 129          /*  Comment :                                                                                                                   *
 130          /*                      Process the filepath from an HTTP 'get' method.                         *
 131          /*                                                                                                                                              *
 132          /************************************************************************/
 133          void http_get(TSOCK *ts, char *fname)
 134          {
 135   1      #define DEFAULT_FILE_NAME "index.htm"
 136   1          APPDATA *adp;
 137   1          char *s=0, *p;
 138   1          RAM_WEB_PAGE * ptr_web_page;
 139   1      
 140   1          adp = (APPDATA *)ts->app;
 141   1          /*
 142   1               Search for the file name.  If name is found, set the adp structure.
 143   1              */
 144   1          if ((*fname==' ') || *fname == '/')   /* Copy filename without leading '/' */
 145   1              strcpy (filepath, fname+1);      
 146   1          /* If file name has the EGI extension.*/
 147   1          if (strstr(fname, EGI_EXT))
 148   1          {
 149   2                      /* Parse the name/value pairs in the HTTP GET Request.*/
 150   2              url_connvars(ts, fname);
 151   2              if (webdebug)
 152   2                 disp_connvars(ts);
 153   2                      /* Calls the EGI function the first time to get it ready.*/
 154   2              if (!egi_execstr(ts, s=get_connvar(ts, http_string_fname)))
 155   2              {
 156   3                  buff_instr(&ts->txb, HTTP_NOFILE );
 157   3                  buff_instr(&ts->txb, HTTP_TXT );
 158   3                  buff_instr(&ts->txb, HTTP_BLANK);
 159   3                  buff_instr(&ts->txb, http_string_no_egi_function);
 160   3                  close_tcp(ts);
 161   3              }
 162   2          }                                   
 163   1          else /* Not a file name with the EGI extension.*/
 164   1          {  
 165   2             if (strlen(fname) <= 1)/* If name is only a '/'.. */
 166   2             {                                   
 167   3                 strcpy (filepath, DEFAULT_FILE_NAME);      
 168   3             }
 169   2      
 170   2             buff_instr(&ts->txb, HTTP_OK);
 171   2      
 172   2             /* from the extension of file name determine the content type*/
 173   2             p = strchr (filepath, '.');
 174   2      
 175   2             if (strcmp (p+1, "htm") == 0)
 176   2                s = HTTP_HTM ;
 177   2             else
 178   2             if (strcmp (p+1, "txt") == 0)
C51 COMPILER V7.50   WEBSERVE                                                              10/12/2006 15:31:42 PAGE 4   

 179   2                s = HTTP_TXT ;
 180   2             else
 181   2             if (strcmp(p+1, "gif") == 0)
 182   2                s =  HTTP_GIF ;
 183   2             else
 184   2             if (strcmp(p+1, "jpg") == 0)
 185   2                s = HTTP_JPG ;
 186   2             else
 187   2             if (strcmp(p+1, "xbm") == 0)
 188   2                s = HTTP_XBM ;
 189   2             else s = "";
 190   2      
 191   2             buff_instr(&ts->txb, s);
 192   2             buff_instr(&ts->txb, HTTP_BLANK);
 193   2      
 194   2             ptr_web_page = search_get_web_page (filepath);
 195   2      
 196   2             adp->in = ptr_web_page->RAM_WEB_PAGE_DATA;
 197   2         
 198   2             adp->file_length = ptr_web_page->RAM_WEB_PAGE_LEN;
 199   2      
 200   2             adp->count = 0;
 201   2          }
 202   1              if (s=strchr(filepath,'?'))
 203   1              {
 204   2                      s[0]=0;
 205   2                      if (s=strchr(filepath,' '))
 206   2                              s[0]=0;
 207   2              }
 208   1      }
 209          
 210          /************************************************************************
 211          /*      Function Name : http_data                                                                                       *

⌨️ 快捷键说明

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