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

📄 connvar.lst

📁 世纪民生公司的带网络功能的单片机CS6209开发http服务器的演示源代码。
💻 LST
📖 第 1 页 / 共 2 页
字号:
 147   1          char *s=0, *end;
 148   1          adp = (APPDATA *)ts->app;
 149   1          end = &adp->vars[adp->vlen];
 150   1          n = strlen(name);
 151   1          if (n < http_max_eginame)
 152   1          {
 153   2              s = adp->vars;
 154   2              while (*s && strncmp(s+1, name, n) && (int)(end-s)>2)
 155   2              {
 156   3                  do {
 157   4                      s++;
 158   4                  } while (s<end-2 && !(*s & 0x80));
 159   3              }
 160   2          }
 161   1          return(*s & 0x80 ? s+1 : "");
 162   1      }
 163          
 164          /************************************************************************
 165          /*      Function Name : disp_connvars                                                                           *
 166          /*                                                                                                                                              *
 167          /*      Arguments :                                                                                                             *
 168          /*                      TSOCK xdata *ts: Point to TSOCK.                                                        *
 169          /*                                                                                                                                              *
 170          /*      Return :                                                                                                                        *
 171          /*                      None.                                                                                                           *
 172          /*  Comment :                                                                                                                   *
 173          /*                      Display all vars in the connection variable space, for          *
 174          /*                      debugging.                                                                                                      *
 175          /*                                                                                                                                              *
 176          /************************************************************************/
 177          void disp_connvars(TSOCK xdata *ts)
 178          {
C51 COMPILER V7.50   CONNVAR                                                               10/12/2006 15:31:41 PAGE 4   

 179   1          int len=0, n;
 180   1          APPDATA *adp;
 181   1      
 182   1          adp = (APPDATA *)ts->app;
 183   1          while (len < adp->vlen)
 184   1          {
 185   2              n = (int)adp->vars[len++] & 0x7f;
 186   2              printf("Var %s", &adp->vars[len]);
 187   2              len += n + 1;
 188   2              printf("=%s\n", &adp->vars[len]);
 189   2              len += strlen(&adp->vars[len]) + 1;
 190   2          }
 191   1      }
 192          
 193          
 194          /************************************************************************
 195          /*      Function Name : url_connvars                                                                            *
 196          /*                                                                                                                                              *
 197          /*      Arguments :                                                                                                             *
 198          /*                      TSOCK xdata *ts: Point to TSOCK.                                                        *
 199          /*                      char xdata *str :Point to string get from URL.                          *
 200          /*                                                                                                                                              *
 201          /*      Return :                                                                                                                        *
 202          /*                      None.                                                                                                           *
 203          /*  Comment :                                                                                                                   *
 204          /*                      Get connection variable values from URL and store in the        *
 205          /*                      connection space of 'ts'.                                                                       *
 206          /*                                                                                                                                              *
 207          /************************************************************************/
 208          void url_connvars(TSOCK xdata *ts, char xdata *str)
 209          {
 210   1          int nlen, vlen, n;
 211   1      
 212   1          if (*str == '/')
 213   1              str++;
 214   1      
 215   1          /* 
 216   1               Starting from the location pointed by str, 
 217   1           find the string length that is delimited by any character in " .?".
 218   1              */
 219   1      
 220   1          vlen = __strcspn(str, " .?");
 221   1          /*
 222   1               Put the first name/value pair in the connection variable space
 223   1           the name is "fname", and the value is the web page name in str.
 224   1              */
 225   1          put_connvarlen(ts, http_string_fname, http_string_fname_length, str, vlen);
 226   1          str += vlen;
 227   1          if (*str == '.')
 228   1          {
 229   2              str++;
 230   2              vlen = __strcspn(str, " ?");
 231   2              /* 
 232   2               If the web page name has an extension, put the second name/value
 233   2               pair in the connection variable space.
 234   2               This is the extention of the web page.
 235   2              */
 236   2              put_connvarlen(ts, http_string_fext, http_string_fext_length, str, vlen);
 237   2              str += vlen;
 238   2          }
 239   1          if (*str++ == '?')
 240   1          {
C51 COMPILER V7.50   CONNVAR                                                               10/12/2006 15:31:41 PAGE 5   

 241   2              /* Get the true name/value pairs in the HTTP GET request.*/
 242   2              while ((nlen=__strcspn(str, "="))!=0 && (vlen=__strcspn(str+nlen, "&"))!=0)
 243   2              {
 244   3                  n = url_decode(str+nlen+1, vlen-1);
 245   3                  put_connvarlen(ts, str, nlen, str+nlen+1, n);
 246   3                  str += nlen + vlen;
 247   3                  if (*str == '&')
 248   3                      str++;
 249   3              }
 250   2          }
 251   1      }
 252          /************************************************************************
 253          /*      Function Name : url_decode                                                                                      *
 254          /*                                                                                                                                              *
 255          /*      Arguments :                                                                                                             *
 256          /*                      char xdata *str :Point to URL string.                                           *
 257          /*                      int len :The length of 'str'.                                                           *
 258          /*                                                                                                                                              *
 259          /*      Return :                                                                                                                        *
 260          /*                      None.                                                                                                           *
 261          /*  Comment :                                                                                                                   *
 262          /*                      Decode a URL-encoded string (with length), return new           *
 263          /*                      length.                                                                                                         *
 264          /*                                                                                                                                              *
 265          /************************************************************************/
 266          int url_decode(char xdata *str, int len)
 267          {
 268   1          int n=0, d=0;
 269   1          char c, c2, *dest;
 270   1      
 271   1          dest = str;
 272   1          while (n < len)
 273   1          {
 274   2              if ((c = str[n++]) == '+')
 275   2                  c = ' ';
 276   2              else if (c=='%' && n+2<=len &&
 277   2                       isxdigit(c=str[n++]) && isxdigit(c2=str[n++]))
 278   2              {
 279   3                  c = c<='9' ? (c-'0')*16 : (toupper(c)-'A'+10)*16;
 280   3                  c += c2<='9' ? c2-'0' : toupper(c2)-'A'+10;
 281   3              }
 282   2              dest[d++] = c;
 283   2          }
 284   1          return(d);
 285   1      }
 286          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   2143    ----
   CONSTANT SIZE    =     24    ----
   XDATA SIZE       =   ----      80
   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 + -