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

📄 http_cgi.c

📁 NXP产品LPC23XX的开发板的源文件
💻 C
📖 第 1 页 / 共 2 页
字号:
		 }
      }
   }while (dat);
   free_mem ((OS_FRAME *)var);
   LED_out (P2);

   if (stpassw == 0x03) {
      len = strlen ((const S8 *)passw);
      if (mem_comp (passw, retyped, len) == __TRUE) {
         /* OK, both entered passwords the same, change it. */
         str_copy (http_auth_passw, passw);
      }
   }
}


/*--------------------------- cgi_func --------------------------------------*/

U16 cgi_func (U8 *env, U8 *buf, U16 buflen, U32 *pcgi) {
   /* This function is called by HTTP server script interpreter to make a    */
   /* formated output for 'stdout'. It returns the number of bytes written   */
   /* to the output buffer. Hi-bit of return value (len is or-ed with 0x8000)*/
   /* is a repeat flag for the system script interpreter. If this bit is set */
   /* to 1, the system will call the 'cgi_func()' again for the same script  */
   /* line with parameter 'pcgi' pointing to a 4-byte buffer. This buffer    */
   /* can be used for storing different status variables for this function.  */
   /* It is set to 0 by HTTP Server on first call and is not altered by      */
   /* HTTP server for repeated calls. This function should NEVER write more  */
   /* than 'buflen' bytes to the buffer.                                     */
   /* Parameters:                                                            */
   /*   env    - environment variable string                                 */
   /*   buf    - HTTP transmit buffer                                        */
   /*   buflen - length of this buffer (500-1400 bytes - depends on MSS)     */
   /*   pcgi   - pointer to session local buffer used for repeated loops     */
   /*            This is a U32 variable - size is 4 bytes. Value is:         */
   /*            - on 1st call = 0                                           */
   /*            - 2nd call    = as set by this function on first call       */
   TCP_INFO *tsoc;
   U32 len = 0;
   U8 id, *lang;

   switch (env[0]) {
      /* Analyze the environment string. It is the script 'c' line starting */
      /* at position 2. What you write to the script file is returned here. */
      case 'a' :
         /* Network parameters - file 'network.cgi' */
         switch (env[2]) {
            case 'i':
               /* Write the local IP address. The format string is included */
               /* in environment string of the script line.                 */
               len = sprintf((S8 *)buf,(const S8 *)&env[4],LocM.IpAdr[0],
                             LocM.IpAdr[1],LocM.IpAdr[2],LocM.IpAdr[3]);
               break;
            case 'm':
               /* Write local Net mask. */
               len = sprintf((S8 *)buf,(const S8 *)&env[4],LocM.NetMask[0],
                             LocM.NetMask[1],LocM.NetMask[2],LocM.NetMask[3]);
               break;
            case 'g':
               /* Write default gateway address. */
               len = sprintf((S8 *)buf,(const S8 *)&env[4],LocM.DefGW[0],
                             LocM.DefGW[1],LocM.DefGW[2],LocM.DefGW[3]);
               break;
            case 'p':
               /* Write primary DNS server address. */
               len = sprintf((S8 *)buf,(const S8 *)&env[4],LocM.PriDNS[0],
                             LocM.PriDNS[1],LocM.PriDNS[2],LocM.PriDNS[3]);
               break;
            case 's':
               /* Write secondary DNS server address. */
               len = sprintf((S8 *)buf,(const S8 *)&env[4],LocM.SecDNS[0],
                             LocM.SecDNS[1],LocM.SecDNS[2],LocM.SecDNS[3]);
               break;
         }
         break;

      case 'b':
         /* LED control - file 'led.cgi' */
         if (env[2] == 'c') {
            /* Select Control */
            len = sprintf((S8 *)buf,(const S8 *)&env[4],LEDrun ? "" : "selected",
                                                        LEDrun ? "selected" : "");
            break;
         }
         /* LED CheckBoxes */
         id = env[2] - '0';
         if (id > 7) {
            id = 0;
         }
         id = 1 << id;
         len = sprintf((S8 *)buf,(const S8 *)&env[4],(P2 & id) ? "checked" : "");
         break;

      case 'c':
         /* TCP status - file 'tcp.cgi' */
         while ((len + 150) < buflen) {
            tsoc = &tcp_socket[MYBUF(pcgi)->xcnt];
            MYBUF(pcgi)->xcnt++;
            /* 'sprintf' format string is defined here. */
            len += sprintf((S8 *)(buf+len),"<tr align=\"center\">");
            if (tsoc->State <= TCP_STATE_CLOSED) {
               len += sprintf ((S8 *)(buf+len),
                               "<td>%d</td><td>%s</td><td>-</td><td>-</td>"
                               "<td>-</td><td>-</td></tr>\r\n",
                               MYBUF(pcgi)->xcnt,state[tsoc->State]);
            }
            else if (tsoc->State == TCP_STATE_LISTEN) {
               len += sprintf ((S8 *)(buf+len),
                               "<td>%d</td><td>%s</td><td>-</td><td>-</td>"
                               "<td>%d</td><td>-</td></tr>\r\n",
                               MYBUF(pcgi)->xcnt,state[tsoc->State],tsoc->LocPort);
            }
            else {
               len += sprintf ((S8 *)(buf+len),
                               "<td>%d</td><td>%s</td><td>%d.%d.%d.%d</td>"
                               "<td>%d</td><td>%d</td><td>%d</td></tr>\r\n",
                               MYBUF(pcgi)->xcnt,state[tsoc->State],
                               tsoc->RemIpAdr[0],tsoc->RemIpAdr[1],
                               tsoc->RemIpAdr[2],tsoc->RemIpAdr[3],
                               tsoc->RemPort,tsoc->LocPort,tsoc->AliveTimer);
            }
            /* Repeat for all TCP Sockets. */
            if (MYBUF(pcgi)->xcnt == tcp_NumSocks) {
               break;
            }
         }
         if (MYBUF(pcgi)->xcnt < tcp_NumSocks) {
            /* Hi bit is a repeat flag. */
            len |= 0x8000;
         }
         break;

      case 'd':
         /* System password - file 'system.cgi' */
         switch (env[2]) {
            case '1':
               len = sprintf((S8 *)buf,(const S8 *)&env[4],
                             http_EnAuth ? "Enabled" : "Disabled");
               break;
            case '2':
               len = sprintf((S8 *)buf,(const S8 *)&env[4],http_auth_passw);
               break;
         }
         break;

      case 'e':
         /* Browser Language - file 'language.cgi' */
         lang = http_get_lang();
         if (strcmp ((const S8 *)lang, "en") == 0) {
            lang = "English";
         }
         else if (strcmp ((const S8 *)lang, "en-us") == 0) {
            lang = "English USA";
         }
         else if (strcmp ((const S8 *)lang, "en-gb") == 0) {
            lang = "English GB";
         }
         else if (strcmp ((const S8 *)lang, "de") == 0) {
            lang = "German";
         }
         else if (strcmp ((const S8 *)lang, "de-ch") == 0) {
            lang = "German CH";
         }
         else if (strcmp ((const S8 *)lang, "de-at") == 0) {
            lang = "German AT";
         }
         else if (strcmp ((const S8 *)lang, "fr") == 0) {
            lang = "French";
         }
         else if (strcmp ((const S8 *)lang, "sl") == 0) {
            lang = "Slovene";
         }
         else {
            lang = "Unknown";
         }
         len = sprintf((S8 *)buf,(const S8 *)&env[2],lang,http_get_lang());
         break;

      case 'f':
         /* LCD Module control - file 'lcd.cgi' */
         switch (env[2]) {
            case '1':
               len = sprintf((S8 *)buf,(const S8 *)&env[4],lcd_text[0]);
               break;
            case '2':
               len = sprintf((S8 *)buf,(const S8 *)&env[4],lcd_text[1]);
               break;
         }
         break;
	  case 'g':
	     /* USB Audio control - file 'audio.cgi' */
		 len = sprintf((S8 *)buf,(const S8 *)&env[4],AudioFlag ? "checked" : "");
		 if ( AudioFlag )
		 	AudioON = 1;
		 else
		 	AudioON = 0;
#if 0
	     switch (env[2]) {
            case '0':
               len = sprintf((S8 *)buf,(const S8 *)&env[4],AudioON ? "checked" : "");
			   break;
            case '1':
			   len = sprintf((S8 *)buf,(const S8 *)&env[4],VolumeHigh ? "checked" : "");
               break;
         }
#endif
         break;
   }
   return ((U16)len);
}

/*----------------------------------------------------------------------------
 * end of file
 *---------------------------------------------------------------------------*/

⌨️ 快捷键说明

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