Beispiel #1
0
void deal(int conn_fd)
{
	char buf[32];
	char name[32];
	char passwd[32];
	char pathname[SIZE] = {"/home/qiong/userinfo/"};
	int  ret;
	int  flag;
	int  fd;
	int zan;


	my_recv(conn_fd, buf, sizeof(buf));
	printf("%c\n", buf[0]);
	if (buf[0] == 'l')
	{
		sys_log("进入用户登陆界面");
		server_check(conn_fd);
	}
	else if (buf[0] == 'r')
	{
		sys_log("进入用户注册界面");
		server_register(conn_fd);	
	}	
	else if (buf[0] == 'x')
	{
		chdir("/home/qiong/shujia/source/");
		server_browse(conn_fd, "../source/");
	}
	else if (buf[0] == 'q')
	{
		sys_log("浏览本地上传目录");
		chdir("/home/qiong/shujia/source/");
		server_look(conn_fd, "../source/");
	}
	else if (buf[0] == 'd')
	{
		sys_log("查找资源");
		sys_find(conn_fd);
		deal(conn_fd);
	}
}
Beispiel #2
0
//保存信息
void function(int sig){
	if(sig == SIGINT){
		printf("正在保存文件!\n");
		SaveList("./server_usr.txt");
		savedaliyList("./daily_usr.txt");
		sleep(2);
		printf("文件保存完毕!\n");
		Node *cur=head->next;
		clientinfo *cur1=ihead->next;
		sever_menu();
		while(1){
			int ch=0;
			scanf("%d",&ch);
			switch(ch){
				case 1:
					server_browse();
					break;
				case 2:
					while(cur!=head){
						cur->state=0;
						//printf("u:%d\n",cur->state);
						cur=cur->next;
					}
					while(cur1!=ihead){
						cur1->state=0;
						cur1=cur1->next;
					}
					DestrayList(head);
					DestraydailyList(dhead);
					DestrayinfoList(ihead);
					free(head);
					free(ihead);
					free(dhead);
					exit(0);
				
			}	
		}
	}	
}
Beispiel #3
0
void server_browse(int conn_fd,  char * pathname)
{
	int i = 0;
	int j = 0;
	char tmp[SIZE];
	char string[SIZE];
	char file_name[SIZE] = {"\n\n\t\t.\n\n\t\t..\n\n\t\t"};
	char info[SIZE];
	struct dirent * ptr;
	struct stat buf;
	DIR  * dir;
	char  lenght[SIZE];
	int len;
	char log[SIZE];

	stat(pathname, &buf);
	if (S_ISREG(buf.st_mode))
	{
		send_data(conn_fd, "b\n");
		my_recv(conn_fd, info, sizeof(info));
		if (info[0] == 'y')
		{
			sys_log("下载单个文件");
			sprintf(lenght, "%d", (int)buf.st_size);
			printf("%s\n", lenght);
			server_download(conn_fd, pathname, lenght);
		}
	}
	chdir(pathname);
	memset(string, '\0', sizeof(string));
	getcwd(string, sizeof(string));
	string[strlen(string)] = '/';
	string[strlen(string)+1] = '\0';

	strcpy(log, "浏览服务器目录:");
	strcat(log, string);
	sys_log(log);
	if (strcmp(string, "/home/qiong/") == 0)
	{
		send_data(conn_fd, "n\n");
		deal(conn_fd);
	}

	while (1)
	{
		if ((dir = opendir (string)) == NULL)
		{
			sys_log("打开目录失败");
			printf("%s\n", string);
			return ;
		}
		while ((ptr = readdir(dir)) != NULL)
		{
			if (strcmp(ptr->d_name, ".") && strcmp(ptr->d_name, ".."))
			{
				strcat(file_name, ptr->d_name);
				strcat(file_name, "\n\n\t\t");
			}
		}
		file_name[strlen(file_name)] = '\0';
		len = send(conn_fd, file_name, strlen(file_name), 0);
		memset(info, 0, sizeof(info));
		len = recv(conn_fd, info, sizeof(info), 0);
		info[strlen(info)] = '\0';
		j = 0;
		for (i =0; i < len; i++)
		{
			if (info[i] == ' '|| info[i] == ',')
			{
				j = 1;
				break;
			}
		}
		if (j == 1)
		{
			sys_log("进行批量下载操作");
			server_batch(conn_fd);            
			deal(conn_fd);
		}
		
		
		if (strncmp(info, "..", 2) == 0)
		{
			sys_log("返回上层目录");
			server_browse(conn_fd, "..");
		}
		else if (info[0] == '.')
		{
			;
		}
		else 
		{
			getcwd(string, sizeof(string));
			string[strlen(string)] = '/';
			string[strlen(string)+1] = '\0';
			strcat(string, info);
			string[strlen(string)] = '\0';
			server_browse(conn_fd, string);
		}
		
	}
}