Example #1
0
int 
parser_option(int argc, char **argv)
{
	if(argc < 2){
		show_usage();
		return -1;
	}

	int ret;
	
	/**
	 * Here may be two suitations:
	 * 1. tview command
	 * 2. tview option
	 * */
	if(argc == 2)
	{
		if(compare_command(argv[1]))
		{
			ret = default_action(argv[1]);
			return ret;	
		}else if((ret = compare_option(argv[1])))
		{
			if(ret == 1)
				show_usage();
			else if(ret == 2)
				show_command();
		}else
		{
			/*error, just show the usage*/
			show_usage();
		}
	}
	
	/**
	 * Here may be some suitations
	 * 1. tview command directory
	 * 2. tview command pattern
	 * 
	 * * **/
	if(argc == 3)
	{
		if(compare_command(argv[1])) /*command with parameter*/
		{
			ret = default_action_third(argv[1]);
			return ret;
		}
	}


	if(argc == 4)
	{
		ret = IS_FIND;
		find_action_parse(argv[1]);
		return ret;
	}

	if(argc == 5)
	{
		ret = IS_FIND;
		find_type = FIND_FULL;
		return ret;
	}
	

	return -1;
}
Example #2
0
// main client handler procedure, runs in its own thread
void * thread_proc(void * param)
{
	CLIENT_INFO client_info;
	memset(&client_info, 0, sizeof(client_info));
	client_info.fd = (int)param;
	strcpy(client_info.dir, "/");

	send_code(client_info.fd, 220);

	while (1)
	{
		int result = client_read(client_info.fd, client_info.buf, &client_info.buffer_pos);
		if (result == -1) break;

		while (client_info.buffer_pos >= 4)
		{
			char line[BUFFER_SIZE] = { 0 };

			if (compare_command(client_info.buf, "USER")) command_user(&client_info);
			else if (compare_command(client_info.buf, "PASS")) command_pass(&client_info);
			else if (compare_command(client_info.buf, "PWD")) command_pwd(&client_info);
			else if (compare_command(client_info.buf, "PORT")) command_port(&client_info);
			else if (compare_command(client_info.buf, "PASV")) command_pasv(&client_info);
			else if (compare_command(client_info.buf, "LIST")) command_list(&client_info);
			else if (compare_command(client_info.buf, "CWD")) command_cwd(&client_info);
			else if (compare_command(client_info.buf, "RETR")) command_retr(&client_info);
			else if (compare_command(client_info.buf, "NOOP")) command_noop(&client_info);
			else if (compare_command(client_info.buf, "SYST")) command_syst(&client_info);
			else if (compare_command(client_info.buf, "TYPE")) command_type(&client_info);
			else if (compare_command(client_info.buf, "QUIT"))
			{
				get_line(client_info.fd, line, client_info.buf, &client_info.buffer_pos);
				send_code(client_info.fd, 221);
				close(client_info.fd);
				client_info.fd = 0;
				return NULL;
			}
			else
			{
				get_line(client_info.fd, line, client_info.buf, &client_info.buffer_pos);
				send_code(client_info.fd, 500);
			}
		}
	}

	if (client_info.fd != 0)
	{
		close(client_info.fd);
		client_info.fd = 0;
	}

	return NULL;
}