int
ne__negotiate_ssl (ne_request *req)
{
	MateVFSSSL *ssl;
	MateVFSCancellation *cancellation;
	ne_session *sess;
	ne_socket  *sock;
	int fd;

	sess = ne_get_session (req);
	sock = sess->socket;
	
	if (!mate_vfs_ssl_enabled ()) {
		sock->last_error = MATE_VFS_ERROR_NOT_SUPPORTED;
		return NE_SOCK_ERROR;
	}
	
	peek_cancellation (cancellation);

	
	fd = mate_vfs_inet_connection_get_fd (sock->connection);

	sock->last_error = mate_vfs_ssl_create_from_fd (&ssl,
							 fd,
							 cancellation);

	if (sock->last_error != MATE_VFS_OK) {
		return NE_SOCK_ERROR;
	}

	mate_vfs_socket_free (sock->socket);
	sock->socket = mate_vfs_ssl_to_socket (ssl);

	mate_vfs_socket_buffer_flush (sock->socket_buffer,
				       cancellation);
	
	sock->last_error = mate_vfs_socket_buffer_destroy (sock->socket_buffer,
							    FALSE,
							    cancellation);

	mate_vfs_inet_connection_free (sock->connection, cancellation);
	
	sock->socket_buffer = mate_vfs_socket_buffer_new (sock->socket);

	return 0;
}
int
ne_sock_connect (ne_socket *sock, const ne_inet_addr *addr, 
		 unsigned int port)
{
	MateVFSCancellation *cancellation;
	MateVFSAddress *address = (MateVFSAddress *) addr;
	   
	peek_cancellation (cancellation);
	
	sock->last_error = mate_vfs_inet_connection_create_from_address (&(sock->connection),
									  address,
									  port,
									  cancellation);
	   
	check_error (sock->last_error, sock);

	if (sock->last_error == MATE_VFS_ERROR_EOF)
		return NE_SOCK_ERROR;
	  
	sock->socket = mate_vfs_inet_connection_to_socket (sock->connection);	
	sock->socket_buffer = mate_vfs_socket_buffer_new (sock->socket);
			 
	return 0;
}
Exemplo n.º 3
0
int
main (int argc, char **argv)
{
	MateVFSResult        result = MATE_VFS_OK;
	gchar                 buffer[1024];
	gchar		     *host;
	gint                  port;
	MateVFSFileSize      bytes_read;
	MateVFSSSL          *ssl = NULL;
	MateVFSSocket       *socket = NULL;
	MateVFSSocketBuffer *socketbuffer = NULL;

	if (argc != 3) {
		printf ("Usage: %s <host> <port>\n", argv[0]);
		return 1;
	}

	host = argv[1];
	port = atoi (argv[2]);

	if (port <= 0) {
		printf ("Invalid port\n");
		return 1;
	}

	if (! mate_vfs_init ()) {
		fprintf (stderr, "Cannot initialize mate-vfs.\n");
		return 1;
	}

	switch (abstraction) {
		case SOCKETBUFFER:
			g_print ("Testing MateVFSSocketBuffer");
		case SOCKET:
			g_print (" and MateVFSSocket");
		case SSL:
			g_print (" and MateVFSSSL");
	}
	g_print (".\n");

	result = mate_vfs_ssl_create (&ssl, host, port, NULL);

	show_result (result, "ssl_create", host, port);

	if (ssl == NULL) {
		fprintf (stderr, "couln't connect\n");
		return -1;
	}

	if (abstraction >= SOCKET) {
		socket = mate_vfs_ssl_to_socket (ssl);
		if (socket == NULL) {
			fprintf (stderr, "couldn't create socket object\n");
			return -1;
		}

		if (abstraction == SOCKETBUFFER) {
			socketbuffer = mate_vfs_socket_buffer_new (socket);
			if (socketbuffer == NULL) {
				fprintf (stderr, 
				       "couldn't create socketbuffer object\n");
				return -1;
			}
		}
	}

	switch (abstraction) {
		case SSL:
			result = mate_vfs_ssl_write (ssl, HTTP_REQUEST, 
						      strlen(HTTP_REQUEST), &bytes_read,
						      NULL);
			break;
		case SOCKET:
			result = mate_vfs_socket_write (socket, HTTP_REQUEST, 
							 strlen(HTTP_REQUEST), &bytes_read,
							 NULL);
			break;
		case SOCKETBUFFER:
			result = mate_vfs_socket_buffer_write (socketbuffer,
								HTTP_REQUEST, strlen(HTTP_REQUEST),
								&bytes_read,
								NULL);
			mate_vfs_socket_buffer_flush (socketbuffer, NULL);
			break;
	}

	show_result (result, "write", host, port);

	while( result==MATE_VFS_OK ) {
		switch (abstraction) {
			case SSL:
				result = mate_vfs_ssl_read (ssl, buffer, 
							     sizeof buffer - 1, &bytes_read,
							     NULL);
				break;
			case SOCKET:
				result = mate_vfs_socket_read (socket, buffer, 
								sizeof buffer - 1, &bytes_read,
								NULL);
				break;
			case SOCKETBUFFER:
				result = mate_vfs_socket_buffer_read (
						socketbuffer, buffer, 
						sizeof buffer - 1, &bytes_read,
						NULL);
				break;
		}
		show_result (result, "read", host, port);
	
		buffer[bytes_read] = 0;
		write (1,buffer,bytes_read);
		if(!bytes_read) break;
	}

	switch (abstraction) {
		case SSL:
			mate_vfs_ssl_destroy (ssl, NULL);
			break;
		case SOCKET:
			mate_vfs_socket_close (socket, NULL);
			break;
		case SOCKETBUFFER:
			mate_vfs_socket_buffer_destroy (socketbuffer, TRUE, NULL);
			break;
	}

	return 0;
}