int
main (int argc, char **argv)
{
	MateVFSAsyncHandle *handle;

	if (argc < 2) {
		fprintf (stderr, "Usage: %s <uri>\n", argv[0]);
		return 1;
	}

	puts ("Initializing mate-vfs...");
	mate_vfs_init ();

	printf ("Starting open for `%s'...\n", argv[1]);
	mate_vfs_async_open_as_channel (&handle, argv[1],
					 MATE_VFS_OPEN_READ,
					 BUFFER_SIZE,
					 0,
					 open_callback,
					 "open_callback");

	puts ("GTK+ main loop running.");
	main_loop = g_main_loop_new (NULL, TRUE);
	g_main_loop_run (main_loop);
	g_main_loop_unref (main_loop);

	puts ("GTK+ main loop finished.");

	puts ("All done");

	while (1)
		;

	return 0;
}
Exemple #2
0
int
main (int argc, char **argv)
{
	MateVFSResult    result;
	MateVFSURI 	 *uri;
	gchar            *text_uri;

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

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

	uri = mate_vfs_uri_new (argv[1]);
	if (uri == NULL) {
		fprintf (stderr, "URI not valid.\n");
		return 1;
	}

        text_uri = mate_vfs_uri_to_string (uri, MATE_VFS_URI_HIDE_NONE);

	result = mate_vfs_unlink (text_uri);
	show_result (result, "unlink", text_uri);

	g_free (text_uri);

	return 0;
}
int
main (int argc, char **argv)
{
	MateVFSResult    result;
	gchar            *text_uri = "/tmp/";
	MateVFSMonitorHandle *handle;

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

	if (argc == 2) {
		text_uri = argv[1];
	}

	result = mate_vfs_monitor_add (&handle, text_uri,
			MATE_VFS_MONITOR_DIRECTORY, callback, "user data");
	printf ("handle is %p\n", handle);
	show_result (result, "monitor_add", text_uri);

	g_timeout_add (1000, timeout_cb, NULL);

	if (result == MATE_VFS_OK) {
		main_loop = g_main_loop_new (NULL, TRUE);
		g_main_loop_run (main_loop);
		g_main_loop_unref (main_loop);
	}

	g_free (text_uri);

	return 0;
}
/* Note that, while this initialized mate-vfs, it does
 * not guarentee that mate-vfs actually loads and initializes
 * the modules in question
 */ 
int
main (int argc, char **argv)
{
	int i;
	GModule *module;
	TestFunc test_func;
	gboolean result;
	gboolean running_result;

	make_asserts_break ("GLib");
	make_asserts_break ("MateVFS");

	/* Initialize the libraries we use. */
	mate_vfs_init ();

	running_result = TRUE;
	for (i=0 ; self_test_modules[i] != NULL ; i++) {
		char *module_path;
		char *dummy_uri_string;
		MateVFSURI *uri;
	
		printf ("Module self-test: '%s'\n", self_test_modules[i]);
		module_path = g_module_build_path (MODULES_PATH, self_test_modules[i]);
		module = g_module_open (module_path, G_MODULE_BIND_LAZY);
		g_free (module_path);
		module_path = NULL;

		if (module == NULL) {
			fprintf (stderr, "Couldn't load module '%s'\n", self_test_modules[i]);
			continue;
		}

		g_module_symbol (module, "vfs_module_self_test", (gpointer *) &test_func);

		if (test_func == NULL) {
			fprintf (stderr, "Module had no self-test func '%s'\n", self_test_modules[i]);
			continue;
		}

		dummy_uri_string = g_strdup_printf ("%s:///", self_test_modules[i]);

		/* force normal initializing of the module by creating a URI
		 * for that scheme
		 */
		uri = mate_vfs_uri_new (dummy_uri_string);
		mate_vfs_uri_unref (uri);

		g_free (dummy_uri_string);
		
		result = test_func();

		fprintf (stderr, "%s: %s\n", self_test_modules[i], result ? "PASS" : "FAIL");

		running_result = running_result && result;
	}

	exit (running_result ? 0 : -1);
}
int
main (int argc, char **argv)
{
	MateVFSResult    result;
	MateVFSHandle   *handle;
	gchar             buffer[1024];
	MateVFSFileSize  bytes_read;
	MateVFSURI 	 *uri;
	gchar            *text_uri;

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

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

	uri = mate_vfs_uri_new (argv[1]);
	if (uri == NULL) {
		fprintf (stderr, "URI not valid.\n");
		return 1;
	}

	text_uri = mate_vfs_uri_to_string (uri, MATE_VFS_URI_HIDE_NONE);

	result = mate_vfs_open_uri (&handle, uri, MATE_VFS_OPEN_WRITE);
	show_result (result, "open", text_uri);

	while( result==MATE_VFS_OK && !feof(stdin)) {
		MateVFSFileSize temp;

		bytes_read = fread(buffer, 1, sizeof buffer - 1, stdin);
		if(!bytes_read) break;
		buffer[bytes_read] = 0;
		result = mate_vfs_write (handle, buffer, bytes_read,
				 	&temp);
		show_result (result, "write", text_uri);
	
	}

	result = mate_vfs_close (handle);
	show_result (result, "close", text_uri);

	g_free (text_uri);

	return 0;
}
Exemple #6
0
int
main (int argc, char **argv)
{
	int completed, i;
	MateVFSAsyncHandle *handle;

	if (argc < 2) {
		fprintf (stderr, "Usage: %s <uri of text file>\n", argv[0]);
		return 1;
	}

	fprintf (stderr, "Initializing mate-vfs...\n");
	mate_vfs_init ();

	fprintf (stderr, "Creating async context...\n");

	fprintf (stderr, "Starting open for `%s'...\n", argv[1]);
	mate_vfs_async_open (&handle, argv[1], MATE_VFS_OPEN_READ,
			      MATE_VFS_PRIORITY_MIN,
			      open_callback, "open_callback");

	fprintf (stderr, "Main loop running.\n");
	main_loop = g_main_loop_new (NULL, TRUE);
	g_main_loop_run (main_loop);

	fprintf (stderr, "Main loop finished.\n");

	fprintf (stderr, "Test async queue efficiency ...");

	for (completed = i = 0; i < QUEUE_LENGTH; i++) {
		mate_vfs_async_open (&handle, argv [1], MATE_VFS_OPEN_READ, 0,
				      async_queue_callback, &completed);
	}

	while (completed < QUEUE_LENGTH)
		g_main_context_iteration (NULL, TRUE);

	fprintf (stderr, "Passed\n");

	g_main_loop_unref (main_loop);

	fprintf (stderr, "All done\n");

	mate_vfs_shutdown ();

	return 0;
}
int
main (int argc, char **argv)
{
	int i;
	GTimer *timer = g_timer_new ();

	g_type_init ();
	mate_vfs_init (); /* start threads */

	g_timer_start (timer);

	for (i = 0; i < 10; i++) {
		mate_vfs_mime_info_reload ();
	}

	fprintf (stderr, "mime parse took %g(ms)\n",
		 g_timer_elapsed (timer, NULL) * 100);

	return 0;
}
Exemple #8
0
int
main (int argc, char **argv)
{
	MateVFSResult    result;
	char  	         *from, *to;

	if (argc != 3) {
		fprintf (stderr, "Usage: %s <from> <to>\n", argv[0]);
		return 1;
	}

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

	command_line_authentication_init ();

	from = mate_vfs_make_uri_from_shell_arg (argv[1]);
	
	if (from == NULL) {
		fprintf (stderr, "Could not guess URI from %s\n", argv[1]);
		return 1;
	}

	to = mate_vfs_make_uri_from_shell_arg (argv[2]);

	if (to == NULL) {
		g_free (from);
		fprintf (stderr, "Could not guess URI from %s\n", argv[2]);
		return 1;
	}

	result = mate_vfs_move (from, to, TRUE);
	show_result (result, "move", from, to);

	g_free (from);
	g_free (to);

	return 0;
}
int
main (int argc, char **argv)
{
	MateVFSMimeApplication *application;
	GList *applications, *l;
	const char *type, *uri = NULL;

	mate_vfs_init ();
        if (argc < 2) {
               g_print ("Usage: %s mime_type\n", *argv);
               return 1;
	}

	type = argv[1];

	if (argc > 2) uri = argv[2];

	g_print ("----- MIME type -----\n\n");
	
	g_print ("Description: %s\n",
		 mate_vfs_mime_get_description (type));

	g_print ("Icon: %s\n",
		 mate_vfs_mime_get_icon (type));

	g_print ("Can be executable: %d\n",
		 mate_vfs_mime_can_be_executable (type));

	g_print ("----- Default application -----\n\n");

	if (uri) {
		application = mate_vfs_mime_get_default_application_for_uri (uri, type);
	} else {
		application = mate_vfs_mime_get_default_application (type);
	}

	if (application == NULL) {
		g_print ("No default application.\n");
	} else {	
		print_application_info (application);
		mate_vfs_mime_application_free (application);
	}

	g_print ("----- All applications -----\n\n");

	if (uri) {
		applications = mate_vfs_mime_get_all_applications_for_uri (uri, type);
	} else {
		applications = mate_vfs_mime_get_all_applications (type);
	}

	if (applications == NULL) {
		g_print ("No applications.\n");	
	}

	for (l = applications; l != NULL; l = l->next)
	{
		print_application_info (l->data);
		g_print ("-----------------------------\n");
	}
	mate_vfs_mime_application_list_free (applications);	

#ifdef TEXT_EXEC_MACRO_EXPANSION
	g_print ("Test exec macro expansion\n");
	test_exec_macro_expansion ();
#endif

	mate_vfs_shutdown ();
	return 0;
}
Exemple #10
0
int
main (int argc, char **argv)
{
	GList *list;
	MateVFSResult result;
	GTimer *timer;
	gchar *text_uri;

	GOptionContext *ctx = NULL;
	GError *error = NULL;

	ctx = g_option_context_new("test-directory");
	g_option_context_add_main_entries(ctx, options, NULL);

	if (!g_option_context_parse(ctx, &argc, &argv, &error)) {
		g_printerr("main: %s\n", error->message);

		g_error_free(error);
		g_option_context_free(ctx);
		return 1;
	}

	g_option_context_free(ctx);

	if (argc != 2 || argv[1] == NULL) {
		g_printerr("Usage: %s [<options>] <uri>\n", argv[0]);
		return 1;
	}

	text_uri = g_strdup(argv[1]);

	mate_vfs_init ();

	printf ("Loading directory...");
	fflush (stdout);

	if (measure_speed) {
		timer = g_timer_new ();
		g_timer_start (timer);
	} else {
		timer = NULL;
	}

	/* Load with without requesting any metadata.  */
	result = mate_vfs_directory_list_load
		(&list, text_uri,
		 (MATE_VFS_FILE_INFO_GET_MIME_TYPE
		  | MATE_VFS_FILE_INFO_FORCE_FAST_MIME_TYPE
		  | MATE_VFS_FILE_INFO_FOLLOW_LINKS));

	if (result == MATE_VFS_OK && measure_speed) {
		gdouble elapsed_seconds;
		guint num_entries;

		g_timer_stop (timer);
		elapsed_seconds = g_timer_elapsed (timer, NULL);
		num_entries = g_list_length (list);
		printf ("\n%.5f seconds for %d unsorted entries, %.5f entries/sec.\n",
			elapsed_seconds, num_entries,
			(double) num_entries / elapsed_seconds);
	}

	if (!measure_speed) {
		printf ("Ok\n");

		show_result (result, "load_directory", text_uri);

		printf ("Listing for `%s':\n", text_uri);
		print_list (list);
	}

	printf ("Destroying.\n");
	mate_vfs_file_info_list_free (list);

	printf ("Done.\n");

	g_free (text_uri);

	return 0;
}
int
main (int argc, char **argv)
{
	int exit = 0;
	char *buffer = g_new (char, 1024) ;
	GIOChannel *ioc;
	guint watch_id = 0;
	GOptionContext *ctx = NULL;
	GError *error = NULL;

	/* default to interactive on a terminal */
	interactive = isatty (0);

	ctx = g_option_context_new("test-vfs");
	g_option_context_add_main_entries(ctx, options, NULL);

	if (!g_option_context_parse(ctx, &argc, &argv, &error)) {
		g_printerr("main: %s\n", error->message);

		g_error_free(error);
		g_option_context_free(ctx);
		return 1;
	}

	g_option_context_free(ctx);

	files = g_hash_table_new (g_str_hash, g_str_equal);

	if (noninteractive)
		interactive = FALSE;

	if (interactive)
		vfserr = stderr;
	else
		vfserr = stdout;

	if (!mate_vfs_init ()) {
		fprintf (vfserr, "Cannot initialize mate-vfs.\n");
		return 1;
	}
	mate_vfs_module_callback_push
		(MATE_VFS_MODULE_CALLBACK_AUTHENTICATION,
		 authentication_callback, NULL, NULL);

	if (argc == 1)
		cur_dir = g_get_current_dir ();
	else
		cur_dir = g_strdup(argv[1]);

	if (cur_dir && !G_IS_DIR_SEPARATOR (cur_dir [strlen (cur_dir) - 1]))
		cur_dir = g_strconcat (cur_dir, G_DIR_SEPARATOR_S, NULL);

	if (interactive == TRUE) {
		main_loop = g_main_loop_new (NULL, TRUE);
		ioc = g_io_channel_unix_new (0 /* stdin */);
		g_io_channel_set_encoding (ioc, NULL, NULL);
		g_io_channel_set_buffered (ioc, FALSE);
		watch_id = g_io_add_watch (ioc,
					   G_IO_IN | G_IO_HUP | G_IO_ERR,
					   callback, buffer);
		g_io_channel_unref (ioc);
	}

	while (!exit) {
		char *ptr;

		if (interactive) {
			fprintf (stdout,"\n%s > ", cur_dir);
			fflush (stdout);

			strcpy (buffer, "");
			g_main_loop_run (main_loop);
		} else {
			/* In non-interactive mode we just do this evil
			 * thingie */
			buffer[0] = '\0';
			fgets (buffer, 1023, stdin);
			if (!buffer [0]) {
				exit = 1;
				continue;
			}
		}

		if (!buffer || buffer [0] == '#')
			continue;

		arg_data = g_strsplit (g_strchomp (buffer), delim, -1);
		arg_cur  = 0;
		if ((!arg_data || !arg_data[0]) && interactive) continue;
		if (!interactive)
			printf ("Command : '%s'\n", arg_data [0]);
		ptr = arg_data[arg_cur++];
		if (!ptr)
			continue;

		if (g_ascii_strcasecmp (ptr, "ls") == 0)
			do_ls ();
		else if (g_ascii_strcasecmp (ptr, "cd") == 0)
			do_cd ();
		else if (g_ascii_strcasecmp (ptr, "dump") == 0)
			do_dump ();
		else if (g_ascii_strcasecmp (ptr, "type") == 0 ||
			 g_ascii_strcasecmp (ptr, "cat") == 0)
			do_cat ();
		else if (g_ascii_strcasecmp (ptr, "cp") == 0)
			do_cp ();
		else if (g_ascii_strcasecmp (ptr, "rm") == 0)
			do_rm ();
		else if (g_ascii_strcasecmp (ptr, "mkdir") == 0)
			do_mkdir ();
		else if (g_ascii_strcasecmp (ptr, "rmdir") == 0)
			do_rmdir ();
		else if (g_ascii_strcasecmp (ptr, "mv") == 0)
			do_mv ();
		else if (g_ascii_strcasecmp (ptr, "info") == 0 ||
			 g_ascii_strcasecmp (ptr, "stat") == 0)
			do_info ();
		else if (g_ascii_strcasecmp (ptr, "findtrash") == 0)
			do_findtrash ();
		else if (g_ascii_strcasecmp (ptr, "ssl") == 0)
			do_ssl ();
		else if (g_ascii_strcasecmp (ptr, "sync") == 0)
			fprintf (vfserr, "a shell is like a boat, it lists or syncs (RMS)\n");
		else if (g_ascii_strcasecmp (ptr,"help") == 0 ||
			 g_ascii_strcasecmp (ptr,"?")    == 0 ||
			 g_ascii_strcasecmp (ptr,"info") == 0 ||
			 g_ascii_strcasecmp (ptr,"man")  == 0)
			list_commands ();
		else if (g_ascii_strcasecmp (ptr,"exit") == 0 ||
			 g_ascii_strcasecmp (ptr,"quit") == 0 ||
			 g_ascii_strcasecmp (ptr,"q")    == 0 ||
			 g_ascii_strcasecmp (ptr,"bye") == 0)
			exit = 1;

		/* File ops */
		else if (g_ascii_strcasecmp (ptr, "open") == 0)
			do_open ();
		else if (g_ascii_strcasecmp (ptr, "create") == 0)
			do_create ();
		else if (g_ascii_strcasecmp (ptr, "close") == 0)
			do_close ();
		else if (g_ascii_strcasecmp (ptr, "handleinfo") == 0)
			do_handleinfo ();
		else if (g_ascii_strcasecmp (ptr, "read") == 0)
			do_read ();
		else if (g_ascii_strcasecmp (ptr, "seek") == 0)
			do_seek ();
		
		else
			fprintf (vfserr, "Unknown command '%s'", ptr);

		g_strfreev (arg_data);
		arg_data = NULL;
	}

	if (interactive) {
		g_source_remove (watch_id);
		g_main_loop_unref (main_loop);
		main_loop = NULL;
	}

	g_free (buffer);
	g_free (cur_dir);

	close_files ();

	return 0;
}
Exemple #12
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;
}
int
main (int argc, char **argv)
{
	MateVFSAddress *v4_a;
	MateVFSAddress *v4_b;
	guint32          v4_numeric;
	gboolean         equal;
#ifdef ENABLE_IPV6
	MateVFSAddress *v6_a;
	MateVFSAddress *v6_b;
#endif
	fprintf (stderr, "Testing MateVFSAddress\n");
		
	mate_vfs_init ();

	/* v4 test cases */
	
	v4_a = mate_vfs_address_new_from_string ("127.3.2.1");

	/* generate a numeric 127.0.0.1 */
	v4_numeric = g_htonl (2130706433U);
	
	v4_b = mate_vfs_address_new_from_ipv4 (v4_numeric);
	
	g_assert (v4_a && v4_b);
	g_assert (mate_vfs_address_get_family_type (v4_a) == AF_INET);
	g_assert (mate_vfs_address_get_family_type (v4_b) == AF_INET);

	g_assert (mate_vfs_address_get_ipv4 (v4_b) == v4_numeric);
	
	/* compare the whole address for now */
	
	equal = mate_vfs_address_match (v4_a, v4_b, 32);
	g_assert (equal == FALSE);
	
	equal = mate_vfs_address_match (v4_a, v4_b, 24);
	g_assert (equal == FALSE);
	
	equal = mate_vfs_address_match (v4_a, v4_b, 16);
	g_assert (equal == FALSE);
	
	equal = mate_vfs_address_match (v4_a, v4_b, 8);
	g_assert (equal == TRUE);

	equal = mate_vfs_address_match (v4_a, v4_b, 0);
	g_assert (equal == FALSE);

	mate_vfs_address_free (v4_a);
	v4_a = mate_vfs_address_new_from_string ("127.0.0.1");

	equal = mate_vfs_address_match (v4_a, v4_b, 32);
	g_assert (equal == TRUE);

	mate_vfs_address_free (v4_b);
	v4_b = mate_vfs_address_dup (v4_a);

	equal = mate_vfs_address_equal (v4_a, v4_b);
	g_assert (equal == TRUE);
	
	equal = mate_vfs_address_match (v4_a, v4_b, 32);
	g_assert (equal == TRUE);

#ifdef INADDR_LOOPBACK
	v4_numeric = mate_vfs_address_get_ipv4 (v4_a);
	g_assert (INADDR_LOOPBACK == g_ntohl (v4_numeric));
#endif
	
#ifdef ENABLE_IPV6
	/* Mapped v4 test cases */

	v6_a = mate_vfs_address_new_from_string ("::ffff:127.0.0.1");

	g_assert (v6_a);
	g_assert (mate_vfs_address_get_family_type (v6_a) == AF_INET6);

	/* v4 mapped in v6 test (v4_a still is 127.0.0.1) */
	equal = mate_vfs_address_match (v4_a, v6_a, 32);
	g_assert (equal == TRUE);

	mate_vfs_address_free (v6_a);
	
	v6_a = mate_vfs_address_new_from_string ("fe80::dead:babe");
	v6_b = mate_vfs_address_new_from_string ("fe80::dead:beef");

	g_assert (v6_a && v6_b);
	g_assert (mate_vfs_address_get_family_type (v6_a) == AF_INET6);
	g_assert (mate_vfs_address_get_family_type (v6_b) == AF_INET6);

	equal = mate_vfs_address_match (v6_a, v6_b, 128);
	g_assert (equal == FALSE);

	/* fe80::dead:bx* */
	equal = mate_vfs_address_match (v6_a, v6_b, 120);
	g_assert (equal == FALSE);

	/* fe80::dead:b* */
	/* both address are equal from this mask on */
	equal = mate_vfs_address_match (v6_a, v6_b, 116);
	g_assert (equal == TRUE);

	/* fe80::dead:* */
	equal = mate_vfs_address_match (v6_a, v6_b, 112);
	g_assert (equal == TRUE);

	/* fe80::* */
	equal = mate_vfs_address_match (v6_a, v6_b, 64);
	g_assert (equal == TRUE);
	
	/* _dup test for v6 */	
	mate_vfs_address_free (v6_b);
	v6_b = mate_vfs_address_dup (v6_a);
	
	equal = mate_vfs_address_equal (v6_a, v6_b);
	g_assert (equal == TRUE);

	mate_vfs_address_free (v6_a);
	mate_vfs_address_free (v6_b);
	
#endif 	
	mate_vfs_address_free (v4_a);
	mate_vfs_address_free (v4_b);

	
	return 0;
}
Exemple #14
0
int
main (int argc, char **argv)
{
	MateVFSResult result;
	char *text_uri;
	MateVFSURI *src, *dest;
	MateVFSFileInfo *info;
	
	if (argc != 3) {
		printf ("Usage: %s <src> <dest>\n", argv[0]);
		return 1;
	}

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

	command_line_authentication_init ();
	
	text_uri = mate_vfs_make_uri_from_shell_arg (argv[1]);

	src = mate_vfs_uri_new (text_uri);
	g_free (text_uri);

	text_uri = mate_vfs_make_uri_from_shell_arg (argv[2]);
	
	dest = mate_vfs_uri_new (text_uri);
	g_free (text_uri);

	if (src == NULL || dest == NULL) {
		result = MATE_VFS_ERROR_INVALID_URI;
		goto out;
	}
	
	info   = mate_vfs_file_info_new ();
	result = mate_vfs_get_file_info_uri (dest, info,
					      MATE_VFS_FILE_INFO_DEFAULT);

	if (result != MATE_VFS_OK && result != MATE_VFS_ERROR_NOT_FOUND) {
		mate_vfs_file_info_unref (info);
		goto out;
	}

	/* If the target is a directory do not overwrite it but copy the
	   source into the directory! (This is like cp does it) */
	if (info->valid_fields & MATE_VFS_FILE_INFO_FIELDS_TYPE &&
	    info->type == MATE_VFS_FILE_TYPE_DIRECTORY) {
		char *name;
		MateVFSURI *new_dest;
		   
		name     = mate_vfs_uri_extract_short_path_name (src);
		new_dest = mate_vfs_uri_append_string (dest, name);
		mate_vfs_uri_unref (dest);
		g_free (name);
		dest = new_dest;
		   
	}

	mate_vfs_file_info_unref (info);
	
	result = mate_vfs_xfer_uri (src, dest,
				     MATE_VFS_XFER_RECURSIVE,
				     MATE_VFS_XFER_ERROR_MODE_ABORT,
				     MATE_VFS_XFER_OVERWRITE_MODE_REPLACE,
				     NULL, NULL);
	
out:
	if (src) {
		mate_vfs_uri_unref (src);
	}

	if (dest) {
		mate_vfs_uri_unref (dest);
	}
		
	if (result != MATE_VFS_OK) {
		fprintf (stderr, "Failed to copy %s to %s\nReason: %s\n",
			 argv[1], argv[2], mate_vfs_result_to_string (result));
		return 1;
	}

	return 0;
}