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

📄 http_cgi.c

📁 web_based.rar
💻 C
📖 第 1 页 / 共 3 页
字号:
				/* Card Number to Modify */
				sscanf ((const S8 *)&var[8], "%x", &g_ulCardNo);
				for ( Cntr = 0; Cntr < USER_LIST_SIZE; Cntr++ )
				{
					if ( UserList[Cntr] == g_ulCardNo )
					{
						ReadConfig ( (PROFILE_START_PAGE + (Cntr/10)), ((Cntr%10) * sizeof(UserConfig)), (INT8U *)&UserConfig, sizeof(UserConfig) ); 
						UserConfig.ucStatus = 0xFF;
						WriteConfig ( (PROFILE_START_PAGE + (Cntr/10)), ((Cntr%10) * sizeof(UserConfig)), (INT8U *)&UserConfig, sizeof(UserConfig) ); 
						UserList[Cntr] = 0;
						USERCOUNT -= 1;
						break;
					}
				}
				if ( Cntr >= USER_LIST_SIZE )
					str_copy ( (U8 *)&ErrorMsg, "USER PROFILE NOT FOUND" );
			}
			}
   }while (qs);
   free_mem ((OS_FRAME *)var);
   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 ( (U8 *)&NtwkCfg.ucaPassword, passw);
		str_copy ( (U8 *)http_auth_passw, (U8 *)&NtwkCfg.ucaPassword );
      }
   }
	 // Set flag to indicate that the network parameters are changed
	 NtwkCfg.ucFlag = 0x00;
	 // Calcualte Network Config structure CRC
	 NtwkCfg.ulCRC = CalculateCRC32 ( (INT8U *)&NtwkCfg, ( sizeof(NtwkCfg) - CRC_LEN ), 0 );
	 // Write network configuration into spi flash memory
 	 WriteConfig ( CONFIG_PAGE_NO, CONFIG_PAGE_START, (INT8U *)&NtwkCfg, sizeof( NtwkCfg ) );
   /* Network parameters - file 'network.cgi' */
	 ReadConfig ( CONFIG_PAGE_NO, CONFIG_PAGE_START, (INT8U *)&NtwkCfg, sizeof(NtwkCfg) );
	 // Do a Page Rewrite to a pre-defined Page Number
	 PageRewrite( g_uiRewritePageNo );  

}


/*--------------------------- cgi_process_data ------------------------------*/

void cgi_process_data (U8 code, U8 *dat, U16 len) {
   /* This function is called by HTTP server to process the returned Data    */
   /* for the CGI Form POST method. It is called on SUBMIT from the browser. */
   
	U8 ucSigStatus;
//	U8 ucChksumRx;

   switch (code) {
      case 0:
         /* Url encoded form data received. */
         break;
      case 1:  
	  	   U0sendchar('A');
		   g_ucWebevent = 1;
	       g_uiTotaldatacnt = 0;
		   g_uiWrreminder = 0;

   	      if(g_uiAllEventsCount)
		{
			//Prompt for event download Exit
			   return;						
		}
		else    //no records to download
		{//Initialisation for file download		
		 g_uiPagenumber = 700;
		 g_uiPacketNo = 0;
		 ucPcnt = 0;
	//	 g_ucDndatPack = 1;	  //logon string verified
		 g_ucIapDnload = 0;
		 g_ucBload_Wd_Rst = 0;
		 g_ucChksum = 0;
		 U0sendchar('a');
		 g_ucSigFail = 0;
		 g_ucChksumFlag = 0;
		 	
		}	  
	      return;

      case 2:
         /* File content data received. Write data to a file. */
         /* This function will be called several times with   */
         /* code 2 when a big file is being uploaded.         */
		   U0sendchar('B');			  
		  //Check all errors
		   if(len == 0)
		   g_ucNoFile = 1;
		   if(g_ucSigFail || (g_uiAllEventsCount > 0))		   
		   return;		

		   g_uiDataCnt = len;
		   g_uiTotaldatacnt = g_uiTotaldatacnt + len;
		   ucPcnt++;		
		      
		if(ucPcnt==1)     // if its first packet
	    	{			  //check signature @ byte no 352			
			  ucSigStatus = CheckCMSSign(dat);		
		
			if(ucSigStatus == 1)
			{
			  g_ucSigFail = 1;			 
			  return;		  	  			
			}
         }
		//calculate checksum for next data packet
		 g_ucChksum = ChecksumCalc(dat,len,g_ucChksum); 		    
		 //	 U0sendchar(g_ucChksum);	  

		 while( g_uiDataCnt >= 512 ) {	
		   	
		   	 BufferWrite (1, g_uiWrreminder,(INT8U *)(dat) ,(512-g_uiWrreminder));
			 BuffToMMPageProg( 1, MM_BUILT_IN_ERASE, g_uiPagenumber );
		   				  		   	 	  		
			 g_uiDataCnt = g_uiDataCnt - (512 - g_uiWrreminder);
			 dat = dat + 512-g_uiWrreminder;
			 g_uiWrreminder = 0; 
			 g_uiPagenumber++;						   
	       }   
		 if(g_uiDataCnt > 0)
		   	{
		   	g_uiWrreminder = g_uiDataCnt;		  		   
	       	BufferWrite (1, 0,(dat), g_uiWrreminder );			
           	}
			
			 
			if(g_uiPagenumber == 974)
			{	U0sendchar('b');
			 U0sendchar('b');
				for(g_uiXloop = 0; g_uiXloop < g_uiWrreminder; g_uiXloop++ )
			{
		   		U0sendchar(*(dat + g_uiXloop));  
		 	}	
			  U0sendchar('c');
			 U0sendchar('c'); 
			 }

			
		 return;

      case 3:
	     
         U0sendchar('C'); 	
		 
		  if(g_ucSigFail || (g_uiAllEventsCount > 0))			    			 
			 return;
				  			  	 
		if (g_uiWrreminder>0)
		   {
			 BuffToMMPageProg( 1, MM_BUILT_IN_ERASE, g_uiPagenumber );			  				
			 U0sendchar('D');
			 U0sendchar(g_uiWrreminder);
			 g_uiPagenumber++;
		   } 
		   		
		 U0sendchar(g_ucChksum);
	
		if(g_ucChksum == 0)          	
			{	
		 g_ucChksumFlag = 1;
		 //g_ucWebevent = 0;

		 U0sendchar('Z');
		  U0sendchar(g_uiTotaldatacnt);
		 U0sendchar(g_uiTotaldatacnt >> 8);
		 U0sendchar(g_uiTotaldatacnt >> 16);
		 U0sendchar(g_uiTotaldatacnt >> 24);

		 g_uiPagenumber = g_uiPagenumber - 700;

		 g_uiPacketNo = g_uiPagenumber/2;

	   if( g_uiPagenumber%2)
		 g_uiPacketNo =g_uiPacketNo +1;

		 U0sendchar(g_uiPagenumber/256);
		 U0sendchar(g_uiPagenumber%256);

		 U0sendchar(g_uiPacketNo/256);
		 U0sendchar(g_uiPacketNo%256);

	/*	 MMPageRead((g_uiPagenumber - 1),0, ( INT8U * )g_ucaFlash_buf, g_uiWrreminder );
		for(g_uiXloop = 0; g_uiXloop < g_uiWrreminder; g_uiXloop++ )
		{
		   U0sendchar(g_ucaFlash_buf[g_uiXloop]);  
		 }	 		*/

		 // VICIntEnClr = 0xFFFFFFFF;    //Disable all interrupt
		  //IAP_download();	
		  				
			}	
		else
		{                
		 //prompt for wrong checksum + flush data + Exit
		 U0sendchar(g_uiTotaldatacnt);
		 U0sendchar(g_uiTotaldatacnt >> 8);
		 U0sendchar(g_uiTotaldatacnt >> 16);
		 U0sendchar(g_uiTotaldatacnt >> 24);		 
		   return;
		}					 																		
         return;
      default:
         return;
   }
  
}


/*--------------------------- 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       */
   U32 len = 0;
//   U8 id;

   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' */
				 ReadConfig ( CONFIG_PAGE_NO, CONFIG_PAGE_START, (INT8U *)&NtwkCfg, sizeof(NtwkCfg) );
         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;
            case 'h':
               /* Write the Host Name. */
               len = sprintf((S8 *)buf, (const S8 *)&env[4], lhost_name);
               break;
         }
         break;
	
	  case 'c':
			if ( MYBUF(pcgi)->xcnt == 0)
			{
				ProfCntr = 0;
				g_uiPageCounter = 0;
				g_uiListCounter = 0;
				g_ucListOver = 0;
			    g_uiPageNo = 0;
				g_uiPageAddr[g_uiPageNo] = ProfCntr;
				MYBUF(pcgi)->xcnt++;
				g_ucLineCntr = 0;
			}
			else
				ProfCntr = g_uiPageCounter;
         /* User List View - file 'usrview.cgi' */
         while ((len + 150) < buflen) {
				if ( USERCOUNT == 0 )
				{
					g_ucListOver = 1;
					break;
				}
				if ( UserList[ProfCntr] )
				{
					ReadConfig ( (PROFILE_START_PAGE + (ProfCntr/10)), ((ProfCntr%10) * sizeof(UserConfig)), (INT8U *)&UserConfig, sizeof(UserConfig) ); 
            		g_ucLineCntr++;
					g_uiListCounter++;
					GetExpiryDate ( (INT8U *)&UserConfig.ucExpiryDate, ucaTempDate ); 
            	/* 'sprintf' format string is defined here. */
            	len += sprintf((S8 *)(buf+len),"<tr align=\"center\">");
            	len += sprintf ((S8 *)(buf+len),
                           "<td>%d</td><td>%s</td><td>%s</td><td>%s</td>"
                           "<td>%x</td><td>%d</td><td>%d</td><td>%s</td></tr>\r\n",
                           g_uiListCounter, (INT8U *)&UserConfig.ucFname, (INT8U *)&UserConfig.ucLname,
                           (INT8U *)&UserConfig.ucDept, UserConfig.ulCardNo,
                           UserConfig.ucTimezone1, UserConfig.ucTimezone2,
                           ucaTempDate);
            	}
				ProfCntr++;
            /* Repeat for all User Profiles. */
            if (g_ucLineCntr >= 20) {
               break;
            	}
            if (g_ucLineCntr >= USERCOUNT) {
					g_ucListOver = 1;
               break;
            }
				if ( ProfCntr >= USER_LIST_SIZE ){
					g_ucListOver = 1;
					break;
				}
         }
			g_uiPageCounter = ProfCntr;

⌨️ 快捷键说明

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