#include <glib.h>
#include <glib-object.h>
#include <gnome-keyring.h>
#include <stdlib.h>
#include <string.h>

extern const GnomeKeyringPasswordSchema* GNOME_KEYRING_NETWORK_PASSWORD;

/* A callback called when operation completes */
static void
stored_password (GnomeKeyringResult res, gpointer user_data)
{
    /* user_data will be the same as was passed to gnome_keyring_store_password() */
    if (res == GNOME_KEYRING_RESULT_OK)
        g_print ("password saved successfully!\n");
    else
        g_print ("couldn't save password: %s", gnome_keyring_result_to_message (res));
}

static void
save_my_password()
{
    gnome_keyring_store_password (GNOME_KEYRING_NETWORK_PASSWORD, /* The password type */
        GNOME_KEYRING_DEFAULT,          /* Where to save it */
        "My special password",       /* Password description, displayed to user */
        "the-password",                 /* The password itself */
        (GnomeKeyringOperationDoneCallback) stored_password,                /* A function called when complete */
        NULL, NULL,                     /* User data for callback, and destroy notify */

        /* These are the attributes */
        "user", "me", 
        "server", "gnome.org",

        NULL); /* Always end with NULL */
}

int 
main (int argc, char ** argv) 
{
	g_type_init ();
	save_my_password ();
	return 0;
}
