[tracker/miner-web-review: 4/10] libtracker-miner: Cleaned up example code for TrackerPasswordProvider



commit 010d8b08bc9740926eefbcc20e1f7684c4acaf3b
Author: Martyn Russell <martyn lanedo com>
Date:   Wed Mar 17 15:52:56 2010 +0000

    libtracker-miner: Cleaned up example code for TrackerPasswordProvider

 examples/libtracker-miner/password-provider-test.c |   58 ++++++++++++++------
 .../tracker-gnome-password-provider.c              |    4 +-
 .../tracker-keyfile-password-provider.c            |    2 +-
 src/libtracker-miner/tracker-password-provider.h   |    3 +-
 4 files changed, 46 insertions(+), 21 deletions(-)
---
diff --git a/examples/libtracker-miner/password-provider-test.c b/examples/libtracker-miner/password-provider-test.c
index 1417804..e373b1a 100644
--- a/examples/libtracker-miner/password-provider-test.c
+++ b/examples/libtracker-miner/password-provider-test.c
@@ -18,12 +18,19 @@
  */
 
 #include "config.h"
+
+#include <stdlib.h>
+
 #include <libtracker-miner/tracker-password-provider.h>
 
-#define SERVICE_NAME "TestService"
+#define SERVICE_NAME  "TestService"
+#define TEST_USERNAME "test-user"
+#define TEST_PASSWORD "s3cr3t"
 
-int main (int argc, char **argv)
+int 
+main (int argc, char **argv)
 {
+	TrackerPasswordProvider *provider;
 	gchar *username = NULL;
 	gchar *password = NULL;
 	GError *error = NULL;
@@ -31,20 +38,28 @@ int main (int argc, char **argv)
 	g_type_init ();
 	g_set_application_name ("PasswordBackendTest");
 
-	TrackerPasswordProvider *provider = tracker_password_provider_get ();
+	g_print ("Testing TrackerPasswordProvider...\n");
+
+	provider = tracker_password_provider_get ();
+
+	g_print ("Storing password '%s' for user '%s'\n",
+	         TEST_PASSWORD,
+	         TEST_USERNAME);
 
 	tracker_password_provider_store_password (provider,
 	                                          SERVICE_NAME,
 	                                          "This is the test service",
-	                                          "testUser",
-	                                          "testPass",
+	                                          TEST_USERNAME,
+	                                          TEST_PASSWORD,
 	                                          &error);
 
 	if (error) {
-		g_critical ("tracker_password_provider_store: %s", error->message);
+		g_printerr ("Calliung tracker_password_provider_store_password() failed, %s", 
+		            error->message);
 		g_error_free (error);
+		g_object_unref (provider);
 
-		return 1;
+		return EXIT_FAILURE;
 	}
 
 	password = tracker_password_provider_get_password (provider,
@@ -53,36 +68,45 @@ int main (int argc, char **argv)
 	                                                   &error);
 
 	if (error) {
-		g_critical ("tracker_password_provider_get: %s", error->message);
+		g_printerr ("Calling tracker_password_provider_get_password() failed, %s", 
+		            error->message);
 		g_error_free (error);
 		g_free (username);
 		g_free (password);
+		g_object_unref (provider);
 
-		return 1;
-	} else {
-		g_message ("Username: %s , Password:%s", username, password);
+		return EXIT_FAILURE;
 	}
 
+	g_print ("Found password is '%s' for username '%s'\n", 
+	         password,
+	         username);
+
 	g_free (username);
 	g_free (password);
 
-	// Also test without getting the username
+	/* Also test without getting the username */
 	password = tracker_password_provider_get_password (provider,
 	                                                   SERVICE_NAME,
 	                                                   NULL,
 	                                                   &error);
 
 	if (error) {
-		g_critical ("tracker_password_provider_get: %s", error->message);
+		g_printerr ("Calling tracker_password_provider_get_password() failed, %s", 
+		            error->message);
 		g_error_free (error);
 		g_free (password);
+		g_object_unref (provider);
 
-		return 1;
-	} else {
-		g_message ("Password:%s", password);
+		return EXIT_SUCCESS;
 	}
 
+	g_print ("Found password is '%s' for NULL username\n", password);
+
 	g_free (password);
 	g_object_unref (provider);
-	return 0;
+
+	g_print ("Done\n");
+
+	return EXIT_SUCCESS;
 }
diff --git a/src/libtracker-miner/tracker-gnome-password-provider.c b/src/libtracker-miner/tracker-gnome-password-provider.c
index c54a35e..2c18e22 100644
--- a/src/libtracker-miner/tracker-gnome-password-provider.c
+++ b/src/libtracker-miner/tracker-gnome-password-provider.c
@@ -238,7 +238,7 @@ password_provider_gnome_get (TrackerPasswordProvider  *provider,
 		return NULL;
 	}
 
-	found = (GnomeKeyringFound *)(found_items->data);
+	found = found_items->data;
 
 	/* Walk through all attributes and select the ones we're interested in */
 	for (i = 0 ; i < found->attributes->len ; ++i) {
@@ -273,7 +273,7 @@ password_provider_gnome_forget (TrackerPasswordProvider  *provider,
 	}
 }
 
-const TrackerPasswordProvider*
+TrackerPasswordProvider *
 tracker_password_provider_get (void)
 {
 	static TrackerPasswordProvider *instance = NULL;
diff --git a/src/libtracker-miner/tracker-keyfile-password-provider.c b/src/libtracker-miner/tracker-keyfile-password-provider.c
index 7b32ee3..f5f51ad 100644
--- a/src/libtracker-miner/tracker-keyfile-password-provider.c
+++ b/src/libtracker-miner/tracker-keyfile-password-provider.c
@@ -284,7 +284,7 @@ password_provider_keyfile_forget (TrackerPasswordProvider  *provider,
 	}
 }
 
-const TrackerPasswordProvider*
+TrackerPasswordProvider *
 tracker_password_provider_get (void)
 {
 	static TrackerPasswordProvider *instance = NULL;
diff --git a/src/libtracker-miner/tracker-password-provider.h b/src/libtracker-miner/tracker-password-provider.h
index 5f44f6e..5741edd 100644
--- a/src/libtracker-miner/tracker-password-provider.h
+++ b/src/libtracker-miner/tracker-password-provider.h
@@ -63,8 +63,9 @@ GType  tracker_password_provider_get_type        (void) G_GNUC_CONST;
 GQuark tracker_password_provider_error_quark     (void);
 
 gchar* tracker_password_provider_get_name        (TrackerPasswordProvider   *provider);
+
 /* Must be defined by the selected implementation */
-const TrackerPasswordProvider*
+TrackerPasswordProvider*
        tracker_password_provider_get             (void);
 void   tracker_password_provider_store_password  (TrackerPasswordProvider   *provider,
                                                   const gchar              *service,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]