Example #1
0
unsigned char search_file_rom(unsigned char *FileName, unsigned long *Address, unsigned long *Size)
{
	unsigned char fileidx = 1;

	ROM_DIR file;
	unsigned int addr = 0;

	while(1)
	{
		read_from_flashbuf((unsigned long)addr, (unsigned char*)&file.b, sizeof(file));

        if(file.b[0]==0xff && file.b[1]==0xff)
		{
			break;
		}
		
		//search file
		if(!strcmp((char*)FileName, file.f.name))
		{
			*Size = file.f.len;
			*Address = file.f.start;

			return fileidx;
		}
		addr += FILE_HEAD_SIZE;
		fileidx++;
		
	}
	
	fileidx = 0;
	
	return fileidx;
}
Example #2
0
void CGIProcessor(st_http_request *http_request, char* buf)
{
	uint32 file_len=0;
	uint32 content = 0;
	char *oldtmp=0, *newtmp=0;
	char sub[32], *subtmp=0;
	uint16 i;
	char* name=(char*)http_request->URI;
	if(strcmp(name,"/"))
		name++;

	/* Search the specified file in stored binaray html image */
	if(search_file_rom((unsigned char *)name, &content, &file_len))
	{
		if(file_len > 1024)// cgi파일은 최대 1024 Bytes 까지 제한
			return;

		read_from_flashbuf(content, (uint8*)buf, file_len);
		buf[file_len] = '\0';
                HTTPSend(NULL, buf, (char*)BUFPUB, file_len, 1);

		oldtmp=(char*)BUFPUB;
		newtmp=oldtmp;
		while((newtmp = strstr(oldtmp, "<?"))){
			mid(newtmp, "<?", "?>", sub);
			oldtmp = newtmp + strlen(sub) + 4;

			subtmp = strstr(sub, "SetValue");
			mid(subtmp, "(", ")", sub);

			for(i=0; i<MAX_CGI_CALLBACK; i++){
				if(!strcmp(sub, cgi_callback[i].tokken)){
					char *tmp;
					uint16 len;

					if(cgi_callback[i].set_func == NULL){
						i = MAX_CGI_CALLBACK;
						break;
					}

					tmp = (char*)get_http_param_value(http_request->param,cgi_callback[i].tokken);
					len = strlen(tmp);

					cgi_callback[i].set_func(tmp, &len);
					break;
				}
			}
			if(i==MAX_CGI_CALLBACK){
			}
		}
	}
}
Example #3
0
static void send_http_response_body(uint8_t s, uint8_t * uri_name, uint8_t * buf, uint32_t start_addr, uint32_t file_len)
{
	int8_t get_seqnum;
	uint32_t send_len;

	uint8_t flag_datasend_end = 0;

#ifdef _USE_SDCARD_
	uint16_t blocklen;
#endif
#ifdef _USE_FLASH_
	uint32_t addr = 0;
#endif

	if((get_seqnum = getHTTPSequenceNum(s)) == -1) return; // exception handling; invalid number

	// Send the HTTP Response 'body'; requested file
	if(!HTTPSock_Status[get_seqnum].file_len) // ### Send HTTP response body: First part ###
	{
		if (file_len > DATA_BUF_SIZE - 1)
		{
			HTTPSock_Status[get_seqnum].file_start = start_addr;
			HTTPSock_Status[get_seqnum].file_len = file_len;
			send_len = DATA_BUF_SIZE - 1;

/////////////////////////////////////////////////////////////////////////////////////////////////
// ## 20141219 Eric added, for 'File object structure' (fs) allocation reduced (8 -> 1)
			memset(HTTPSock_Status[get_seqnum].file_name, 0x00, MAX_CONTENT_NAME_LEN);
			strcpy((char *)HTTPSock_Status[get_seqnum].file_name, (char *)uri_name);
#ifdef _HTTPSERVER_DEBUG_
			printf("> HTTPSocket[%d] : HTTP Response body - file name [ %s ]\r\n", s, HTTPSock_Status[get_seqnum].file_name);
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////

#ifdef _HTTPSERVER_DEBUG_
			printf("> HTTPSocket[%d] : HTTP Response body - file len [ %ld ]byte\r\n", s, file_len);
#endif
		}
		else
		{
			// Send process end
			send_len = file_len;

#ifdef _HTTPSERVER_DEBUG_
			printf("> HTTPSocket[%d] : HTTP Response end - file len [ %ld ]byte\r\n", s, send_len);
#endif
		}
#ifdef _USE_FLASH_
		if(HTTPSock_Status[get_seqnum].storage_type == DATAFLASH) addr = start_addr;
#endif
	}
	else // remained parts
	{
#ifdef _USE_FLASH_
		if(HTTPSock_Status[get_seqnum].storage_type == DATAFLASH)
		{
			addr = HTTPSock_Status[get_seqnum].file_start + HTTPSock_Status[get_seqnum].file_offset;
		}
#endif
		send_len = HTTPSock_Status[get_seqnum].file_len - HTTPSock_Status[get_seqnum].file_offset;

		if(send_len > DATA_BUF_SIZE - 1)
		{
			send_len = DATA_BUF_SIZE - 1;
			//HTTPSock_Status[get_seqnum]->file_offset += send_len;
		}
		else
		{
#ifdef _HTTPSERVER_DEBUG_
			printf("> HTTPSocket[%d] : HTTP Response end - file len [ %ld ]byte\r\n", s, HTTPSock_Status[get_seqnum].file_len);
#endif
			// Send process end
			flag_datasend_end = 1;
		}
#ifdef _HTTPSERVER_DEBUG_
			printf("> HTTPSocket[%d] : HTTP Response body - send len [ %ld ]byte\r\n", s, send_len);
#endif
	}

/*****************************************************/
	//HTTPSock_Status[get_seqnum]->storage_type == NONE
	//HTTPSock_Status[get_seqnum]->storage_type == CODEFLASH
	//HTTPSock_Status[get_seqnum]->storage_type == SDCARD
	//HTTPSock_Status[get_seqnum]->storage_type == DATAFLASH
/*****************************************************/

	if(HTTPSock_Status[get_seqnum].storage_type == CODEFLASH)
	{
		if(HTTPSock_Status[get_seqnum].file_len) start_addr = HTTPSock_Status[get_seqnum].file_start;
		read_userReg_webContent(start_addr, &buf[0], HTTPSock_Status[get_seqnum].file_offset, send_len);
	}
#ifdef _USE_SDCARD_
	else if(HTTPSock_Status[get_seqnum].storage_type == SDCARD)
	{
		// Data read from SD Card
		fr = f_read(&fs, &buf[0], send_len, (void *)&blocklen);
		if(fr != FR_OK)
		{
			send_len = 0;
#ifdef _HTTPSERVER_DEBUG_
		printf("> HTTPSocket[%d] : [FatFs] Error code return: %d (File Read) / HTTP Send Failed - %s\r\n", s, fr, HTTPSock_Status[get_seqnum].file_name);
#endif
		}
		else
		{
			*(buf+send_len+1) = 0; // Insert '/0' for indicates the 'End of String' (null terminated)
		}
	}
#endif

#ifdef _USE_FLASH_
	else if(HTTPSock_Status[get_seqnum].storage_type == DATAFLASH)
	{
		// Data read from external data flash memory
		read_from_flashbuf(addr, &buf[0], send_len);
		*(buf+send_len+1) = 0; // Insert '/0' for indicates the 'End of String' (null terminated)
	}
#endif
	else
	{
		send_len = 0;
	}
	// Requested content send to HTTP client
#ifdef _HTTPSERVER_DEBUG_
	printf("> HTTPSocket[%d] : [Send] HTTP Response body [ %ld ]byte\r\n", s, send_len);
#endif

	if(send_len) send(s, buf, send_len);
	else flag_datasend_end = 1;

	if(flag_datasend_end)
	{
		HTTPSock_Status[get_seqnum].file_start = 0;
		HTTPSock_Status[get_seqnum].file_len = 0;
		HTTPSock_Status[get_seqnum].file_offset = 0;
		flag_datasend_end = 0;
	}
	else
	{
		HTTPSock_Status[get_seqnum].file_offset += send_len;
#ifdef _HTTPSERVER_DEBUG_
		printf("> HTTPSocket[%d] : HTTP Response body - offset [ %ld ]\r\n", s, HTTPSock_Status[get_seqnum].file_offset);
#endif
	}

// ## 20141219 Eric added, for 'File object structure' (fs) allocation reduced (8 -> 1)
#ifdef _USE_SDCARD_
	f_close(&fs);
#endif
// ## 20141219 added end
}
Example #4
0
void FILESend(uint8 s, st_http_request *http_request, char* buf)
{
	uint32 file_len=0, file_len_tmp=0;
	uint32 send_len=0, content_len=0;
	uint32 content = 0;
	char* name=(char*)http_request->URI;
	if(strcmp(name,"/"))
		name++;

	/* Search the specified file in stored binaray html image */
	if(!search_file_rom((unsigned char *)name, &content, &file_len))
	{
		memcpy(buf, ERROR_HTML_PAGE, sizeof(ERROR_HTML_PAGE));
		TCPSend(s, (int8*)buf, strlen((char const*)buf));
	}
	else
	{
		file_len_tmp = file_len;
		send_len=0;
		while(file_len_tmp)
		{
			if(file_len_tmp>1024)
			{
				read_from_flashbuf(content+send_len, (uint8*)buf, 1024);

				// Replace html's system environment value to real value and check size
				content_len += HTTPSend(NULL, buf, NULL, 1024, 2);

				send_len+=1024;
				file_len_tmp-=1024;
			}
			else
			{
				read_from_flashbuf(content+send_len, (uint8*)buf, file_len_tmp);
				buf[file_len_tmp] = '\0';

				// Replace html's system environment value to real value and check size
				content_len += HTTPSend(NULL, buf, NULL, file_len_tmp, 2);

				send_len+=file_len_tmp;
				file_len_tmp-=file_len_tmp;
			}
		}
		make_http_response_head((unsigned char*)buf, http_request->TYPE, content_len);
		TCPSend(s, (int8*)buf, strlen((char const*)buf));

		send_len=0;
		while(file_len)
		{
			if(file_len>1024)
			{
				read_from_flashbuf(content+send_len, (uint8*)buf, 1024);

				// Replace html's system environment value to real value and send
				if(HTTPSend(s, buf, NULL, 1024, 0)<0)
				{
					return;
				}

				send_len+=1024;
				file_len-=1024;
			}
			else
			{
				read_from_flashbuf(content+send_len, (uint8*)buf, file_len);
				buf[file_len] = '\0';

				// Replace html's system environment value to real value and send
				HTTPSend(s, buf, NULL, (uint16)file_len, 0);

				send_len+=file_len;
				file_len-=file_len;
			}
		}
	}
}