/*
gcc xfertest.c -o xfertest -I/usr/include/gnome-vfs-2.0/ -I/usr/include/glib-2.0/ -I/usr/lib/glib-2.0/include/ -lglib-2.0 -lgnomevfs-2 -L/usr/lib
 */

#include <stdio.h>
#include <libgnomevfs/gnome-vfs.h>
#include <libgnomevfs/gnome-vfs-utils.h>

int print_error(GnomeVFSResult result, const char *uri_string)
{
    const char *error_string;
    /* get the string corresponding to this GnomeVFSResult value */
    error_string = gnome_vfs_result_to_string(result);
    printf ("Error %s occured opening location %s\n", error_string, uri_string);
    return 1;
}

int main(int argc, char **argv)
{
    const gchar* uri1 = "http://d134w4tst3t.s3.amazonaws.com:80/a?Signature=aNxGCZQ6s5Wr3WeCIDXvQrivjhA%3D&Expires=1217534131&AWSAccessKeyId=0EYZF4DV8A7WM0H73602";
    const gchar* target1 = "tmptestfile1";
    const gchar *from_string, *to_string;
    const GnomeVFSURI *from, *to;
    GnomeVFSResult result;

    if (!gnome_vfs_init ()) {
        printf ("Could not initialize GnomeVFS\n");
        return 1;
    }

    from_string = gnome_vfs_make_uri_from_input(uri1);
    to_string = gnome_vfs_make_uri_from_input(target1);

    from = gnome_vfs_uri_new(from_string);
    to = gnome_vfs_uri_new(to_string);

    /* open the input file for read access */
    result = gnome_vfs_xfer_uri(from, to, GNOME_VFS_XFER_DEFAULT,
                                GNOME_VFS_XFER_ERROR_MODE_ABORT,
                                GNOME_VFS_XFER_OVERWRITE_MODE_ABORT,
                                NULL, NULL);
    /* if the operation was not successful, print the error and abort */
    if (result != GNOME_VFS_OK) return print_error(result, from_string);

    g_free(from_string);
    g_free(to_string);

    return 0;
}
