Beispiel #1
0
void 
accept_request(int client){
	extern char *buffer2send;	/* extern from fileHandle.c */
	
	char buf[0x400];	
	char *path;	
	int numchars;	
	token query_string;	
	token request_token;
	struct stat st;

	#ifdef DEBUGME
	unsigned int k;
	#endif

	/* get the input from the client */
	numchars = get_line(client, buf, sizeof(buf));
	if(numchars >0){
		/* change the input string into several tokens */		
		get_token(&request_token, buf, " \n\r");
		
		#ifdef DEBUGME
		PRINT_TOKEN(k, request_token);
		#endif			
		
		/* check if the method is supported by our server */
		if (strcasecmp(request_token.token[0], "GET")){
			getHTML(http_501, "test.html");						
		}else{	/* if the method is a GET method */
			get_token(&query_string, request_token.token[1], "?");	
			
			#ifdef DEBUGME
			printf("query_string: %s\n",query_string.token[0]);
			#endif		
			
			path = setPath("./", query_string.token[0]);	
			if(stat(path, &st) == 0 ){
				if(!getHTML(http_200, path)){
					printf("file open error\n");
					close(client);
					return;	
				}
			}else{
				if(!getHTML(http_404, "notfound.html")){
					printf("file open error\n");
					close(client);
					return;	
				}
			}
			free(path);
			free_token(&query_string);
		}
		free_token(&request_token);		
		SENDBUFFER2SEND(client);
		/* free the malloc of the token */		
		
				
	}
}
Beispiel #2
0
/*
** 名字:Scanner::GetToken()
** 说明:从文件流中取Token
**
*/
Token* Scanner::GetToken()
{
	assert( m_bFileOpened ); 				// 断言文件已经打开
	Reset();								// 重设当前Token

	try 
	{ 
		m_pFSM->Run();						// 启动状态机识别	
	}							
	catch ( int e )
	{ 
		if ( e == EOF ) m_currentToken = new Token( Tag::ENDFILE ); 
	}	

	PRINT_TOKEN();

	return m_currentToken;					// 返回状态机处理完的Token
}