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

📄 https_callbacks.c

📁 Embeded MCU Tcpip code.
💻 C
📖 第 1 页 / 共 2 页
字号:
INT16 https_loadbuffer (UINT8 ses, UINT8* buf, UINT16 buflen) {
	UINT16 i;
		
	if( https[ses].fstart == 0xFFFFFFFF )
	{
		/* Error site asked	*/
		
		for(i=0; i < (https[ses].flen - https[ses].fpoint); i++)
		{
			if(i >= buflen)
				break;
		
			*buf++ = https_not_found_page[https[ses].fpoint + i];
		
		}
		return(i);
	} 
	
	//==================index.html=================================
	if( https[ses].fstart == 0x00000001 )
	{	
	  for(i=0; i < (https[ses].flen - https[ses].fpoint); i++)
	  {
			if(i >= buflen)
				break;
		
			*buf++ = https_main_html[https[ses].fpoint + i];
		
	  }
	  
	  /* Increment counter for file stats */
	  return(i);
	}
		
	//==================style.css=================================
	if( https[ses].fstart == 0x00000003 )
	{
	
	  for(i=0; i < (https[ses].flen - https[ses].fpoint); i++)
	  {
		if(i >= buflen)
			break;
		
	    *buf++ = https_style_css[https[ses].fpoint + i];
		
	  }
	  return(i);
	}
	
	//==================logo.gif=================================
	if( https[ses].fstart == 0x00000005 )
	{
	  for(i=0; i < (https[ses].flen - https[ses].fpoint); i++)
	  {
		if(i >= buflen)
		{
		  break;
		}
		
		  *buf++ = https_logo_gif[https[ses].fpoint + i];
		 
	
	  }
	  return(i);
	}
		
	//==================fade.png=================================
	if( https[ses].fstart == 0x0000001E )
	{
	  for(i=0; i < (https[ses].flen - https[ses].fpoint); i++)
	  {
		if(i >= buflen)
		{
		  break;
		}
		
		  *buf++ = https_fade_png[https[ses].fpoint + i];
		 
	
	  }
	  return(i);
	}
	
	//==================stats.html=================================
	if( https[ses].fstart == 0x00000009 )
	{
	  /* tell the size of the content to the stack */
	  https[ses].flen = 12000;
	  
	  /* If not send yet, send header or html header */
	  if(https[ses].headersent == 0 || https[ses].headersent == 1 || https[ses].headersent == 2)
	  {
	    
	    /* Send the Content type of html document (State 0) */
	    if(https[ses].headersent == 0)
	    {
	      int headlength;
	      
	      headlength = https_generateheader(buf, 0, 0, 0, 12000);
	      https[ses].headersent = 1;
	      https[ses].fpoint += headlength;
	      
	      return(headlength);
	    }
	    
	    /* copy first part of html_header (State 1) */
	    if(https[ses].headersent == 1)
	    {
	      int headlength;
	      
	      https[ses].headersent = 2;
	      headlength = 450;
	      strncpy((char *)buf, https_header_html, headlength);
	      https[ses].fpoint += headlength;
	      
	      return(headlength);
	    }
	    
	    /* copy second part of html_header (State 2) */
	    if(https[ses].headersent == 2)
	    {	    
	      int headlength, htcont = 0;
	      
	      /* copy second part of html header */
	      https[ses].headersent = 3;
	      
	      /* Grab second part of html_header and... */
	      headlength = strlen(https_header_html) - 450;
	      if(headlength>450)
	        printf("ERROR, bad headlength!!!!");
	      
	      /* ...copy it to buffer */  
	      for(htcont=0;htcont<headlength;htcont++)
	      {
	        *buf++ = https_header_html[htcont+450];
	      }
	      
	      /* Store actual length in httpd structure */
	      https[ses].fpoint += headlength;
	      
	      return(headlength);
	      
	    }
	  }
	  
	  /* Generate data through function getNetStats() and copy it to buffer (State 3) */
	  if(https[ses].headersent == 3 && https[ses].bodysent == 0)
	  {
	    int bodylen;
	    
	    bodylen = getNetStats(1, (char *)buf, https[ses].unicount);
	    
	    if(https[ses].unicount < 4)
	    {
	      https[ses].unicount++;
	      return(bodylen);
	    }
	    else
	    {
	      https[ses].bodysent = 1;
	      return(bodylen);
	    }
	    
	  }
	  
	  /* Ok, now this is the end :) */
	  if(https[ses].headersent && https[ses].bodysent)
	  {
	    /* copy the FME footer into the output buffer */
	    https[ses].fpoint = 12000;
	    
	    return(strlen(strcpy((char *)buf, https_footer_html)));
	  }
	  
	  return(i);
	}
	
	//==================location-bg.gif=================================
	if( https[ses].fstart == 0x0000000A )
	{
	  for(i=0; i < (https[ses].flen - https[ses].fpoint); i++)
	  {
		if(i >= buflen)
			break;
		
	    *buf++ = https_location_bg_gif[https[ses].fpoint + i];
		
	  }
	  return(i);
	}
	
	//==================files.html=================================
	if( https[ses].fstart == 0x0000001F )
	{
	  /* tell the size of the content to the stack */
	  https[ses].flen = 12000;
	  
	  /* If not send yet, send header or html header */
	  if(https[ses].headersent == 0 || https[ses].headersent == 1 || https[ses].headersent == 2)
	  {
	    
	    /* Send the Content type of html document (State 0) */
	    if(https[ses].headersent == 0)
	    {
	      int headlength;
	      
	      headlength = https_generateheader(buf, 0, 0, 0, 12000);
	      https[ses].headersent = 1;
	      https[ses].fpoint += headlength;
	      
	      return(headlength);
	    }
	    
	    /* copy first part of html_header (State 1) */
	    if(https[ses].headersent == 1)
	    {
	      int headlength;
	      
	      https[ses].headersent = 2;
	      headlength = 492;
	      strncpy((char *)buf, https_header_html, headlength);
	      https[ses].fpoint += headlength;
	      
	      return(headlength);
	    }
	    
	    /* copy second part of html_header (State 2) */
	    if(https[ses].headersent == 2)
	    {	    
	      UINT16 headlength, htcont = 0;
	      
	      https[ses].headersent = 3;
	      
	      /* Grab second part of html_header and... */
	      headlength = strlen(https_header_html) - 492;
	      if(headlength>492)
	        printf("ERROR, bad headlength!!!!");
	      
	      /* ...copy it to buffer */  
	      for(htcont=0;htcont<headlength;htcont++)
	      {
	        *buf++ = https_header_html[htcont+492];
	      }
	      
	      https[ses].fpoint += headlength;
	      
	      return(headlength);
	    }
	  }
	  
	  /* Generate data through function getFileStats() and copy it to buffer (State 3) */
	  if(https[ses].headersent == 3 && https[ses].bodysent == 0)
	  {
	    UINT16 bodylen;
	    
	    bodylen = getFileStats(1,(char *)buf, https[ses].unicount);
	    
	    if(https[ses].unicount < 6)
	    {
	      https[ses].unicount++;
	      return(bodylen);
	    }
	    else
	    {
	      https[ses].bodysent = 1;
	      return(bodylen);
	    }
	    
	  }
	  
	  /* Ok, now this is the end :) */
	  if(https[ses].headersent && https[ses].bodysent)
	  {
	    /* copy the FME footer into the output buffer */
	    https[ses].fpoint = 12000;
	    
	    return(strlen(strcpy((char *)buf, https_footer_html)));
	  }
	  
	  return(i);
	}
	
	
	//==================mcustats.html=================================
	if( https[ses].fstart == 0x0000000D )
	{
	  
	  /* tell the size of the content to the stack */
	  https[ses].flen = 18000;
	  
	  /* If not send yet, send desc header or html header */
	  if(https[ses].headersent == 0 || https[ses].headersent == 1 || https[ses].headersent == 2)
	  {
	    if(https[ses].headersent == 0)
	    {
	      int headlength;
	      
	      headlength = https_generateheader(buf, 0, 0, 0, 14000);
	      https[ses].headersent = 1;
	      https[ses].fpoint += headlength;
	      
	      return(headlength);
	    }
	    
	    /* copy first part of html_header (State 1) */
	    if(https[ses].headersent == 1)
	    {
	      int headlength;
	      
	      https[ses].headersent = 2;
	      headlength = 492;
	      strncpy((char *)buf, https_header_html, headlength);
	      https[ses].fpoint += headlength;
	      
	      return(headlength);
	    }
	    
	    /* copy second part of html_header (State 2) */
	    if(https[ses].headersent == 2)
	    {	    
	      int headlength, htcont = 0;
	      
	      https[ses].headersent = 3;
	      headlength = strlen(https_header_html) - 492;
	      for(htcont=0;htcont<headlength;htcont++)
	      {
	        *buf++ = https_header_html[htcont+492];
	      }
	      
	      https[ses].fpoint += headlength;
	      
	      return(headlength);
	    }
	  }
	  
	  /* Generate data through function getPortPins() and copy it to buffer (State 3) */
	  if((https[ses].headersent == 3 && https[ses].bodysent == 0) || (https[ses].headersent == 4 && https[ses].bodysent == 0) || (https[ses].headersent == 5 && https[ses].bodysent == 0))
	  {
	    /* send start of html table */
	    if(https[ses].headersent == 3)
	    {
	      UINT16 sBitLength;
	      
	      sBitLength = strlen(strcpy((char *)buf, mcustatstabletemp));
	      
	      https[ses].fpoint += sBitLength;
	      https[ses].headersent = 4;
	      return(sBitLength);
	    }
	    
	    /* send port status html table indices */
	    if(https[ses].headersent == 4)
	    {
	      UINT16 portLength;
	      
	      /* split portstatus in 2 pieces */
	      if(https[ses].unicount < 8)
	      {
	         
	        switch(https[ses].portPin)
	        {
	          case 0:
	          {
	            portLength = getPortPins(https[ses].unicount, 1, (char *)buf);
	            https[ses].portPin = 1;
	            https[ses].fpoint += portLength;
	            return(portLength);
	          }
	          
	          case 1:
	          {
	            portLength = getPortPins(https[ses].unicount, 2, (char *)buf);
	            https[ses].unicount++;
	            https[ses].portPin = 0;
	            https[ses].fpoint += portLength;
	            return(portLength);
	          }
	        }
	        
	      }
	      else
	      {
	        https[ses].headersent = 5;
	      }
	    }
	    
	    /* send </table> */	    
	    if(https[ses].headersent == 5)
	    {
	      int sBitLength;
	      
	      sBitLength = strlen(strcpy((char *)buf, tablestop));
	      https[ses].fpoint += sBitLength;
	      https[ses].bodysent = 1;
	      https[ses].headersent = 6;
	      
	      return(sBitLength);
	    }
	  }
	  
	  
	  /* Ok, this is the end :) */
	  if((https[ses].headersent == 6) /*&& (https[ses].bodysent == 1)*/)
	  {
	    /* copy the FME footer into the output buffer */
	    https[ses].fpoint = 18000 - strlen(https_footer_html);
	    
	    return(strlen(strcpy((char *)buf, https_footer_html)));
	  }

	  return(0);
	}

    return(i);
}

⌨️ 快捷键说明

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