Beispiel #1
0
int
server_data_cmd(int sock, char *cmd, char **buffer)
{
	char recv[RECV_BUFFER];
	int n, size, completed;

	log_debug("server_data_cmd: command '%s'", cmd);
	if (server_reply(sock, cmd) == -1)
	{
		log_error("server_data_cmd: server_reply failed");
		return -1;
	}

	n = read(sock, recv, sizeof recv);
	if (n == -1)
	{
		log_sys_error("server_data_cmd: read");
		return -1;
	}

	size = atoi(recv);
	if (size < 0 || size > MAX_BUFFER)
	{
		log_error("server_data_cmd: bad buffer size");
		return -1;
	}

	*buffer = (char *) malloc(size + 1);
	if (*buffer == NULL)
	{
		log_sys_error("server_data_cmd: malloc");
		return -1;
	}

	if (server_ok(sock))
	{
		log_error("server_data_cmd: server_ok failed");
		return -1;
	}

	for (completed = 0; size > completed; completed += n)
	{
		n = read(sock, *buffer + completed, size - completed);
		if (n == -1)
		{
			log_sys_error("server_data_cmd: read");
			return -1;
		}
	}

	(*buffer)[completed] = 0;

	if (server_check(sock))
	{
		log_error("server_data_cmd: server_check failed");
		return -1;
	}

	return 0;
}
Beispiel #2
0
static int
server_output(int sock, char *buffer, int size)
{
	int n;

	if (server_reply(sock, "%d", size) == -1)
	{
		log_error("server_output: server_reply failed");
		return -1;
	}

	if (server_check(sock))
	{
		log_error("server_output: server_check failed");
		return -1;
	}

	n = write(sock, buffer, size);
	if (n == -1)
	{
		log_sys_error("server_output: write");
		return -1;
	}

	return n;
}
Beispiel #3
0
void doit(void)
{
	server_check();
	reset_buffers();
	client_check();

	if (g_pcert) {
		gnutls_pcert_deinit(g_pcert);
		gnutls_free(g_pcert);
	}
	if (g_pkey) {
		gnutls_privkey_deinit(g_pkey);
	}
}
Beispiel #4
0
int
server_cmd(int sock, char *cmd)
{
	log_debug("server_cmd: command '%s'", cmd);
	if (server_reply(sock, cmd) == -1)
	{
		log_error("server_data_cmd: server_reply failed");
		return -1;
	}

	if (server_check(sock))
	{
		log_sys_error("server_data_cmd: server_check failed");
		return -1;
	}

	return 0;
}
Beispiel #5
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 #6
0
void doit(void)
{
	server_check();
	client_check();
}