soc.2008.masterpassword: 09a9aeeb: Fixed syntax and types error. keyring.c ...

scrouaf at soc.pidgin.im scrouaf at soc.pidgin.im
Thu Jul 10 09:20:48 EDT 2008


-----------------------------------------------------------------
Revision: 09a9aeebffa52cbf6d585d7fe76a5c2e606f9725
Ancestor: 29b6363ef076e86fb20ee700a03072441c045bf3
Author: scrouaf at soc.pidgin.im
Date: 2008-07-10T13:14:44
Branch: im.pidgin.soc.2008.masterpassword
URL: http://d.pidgin.im/viewmtn/revision/info/09a9aeebffa52cbf6d585d7fe76a5c2e606f9725

Modified files:
        libpurple/keyring.c libpurple/keyring.h

ChangeLog: 

Fixed syntax and types error. keyring.c and keyring.h will now compile, but will issue warnings with -Wall

-------------- next part --------------
============================================================
--- libpurple/keyring.c	c0b60d5d05db166a3213b538f544d74304a0bdfd
+++ libpurple/keyring.c	581195a2d83908edcb07b7c4d090a181c06d0641
@@ -34,13 +34,11 @@
  *  - use accessors
  *  - compare header with this file
  *  - purple_keyring_init()
- *  - purple_keyring_set_inuse()
+ *  - purple_keyring_set_inuse() needs to be async for error checking an reversability.
  *
  * Questions :
  *  - use accessors internally
  *  - cleanup
- *  - public/opaque struct
- *  - wrapper for g_list_foreach ?
  */
 
 #include <glib.h>
@@ -73,9 +71,13 @@ struct _PurpleKeyringPasswordNode
 struct _PurpleKeyringPasswordNode
 {
 	PurpleAccount * account;
-	char * encryption;
-	char * mode;
-	char * data;
+	const char * encryption;
+	const char * mode;
+	const char * data;
+/**
+ * strings cannot be modified.
+ * all are static excpet data
+ */
 };
 
 
@@ -95,7 +97,6 @@ purple_keyring_get_keyringlist(void)
 
 const GList * 
 purple_keyring_get_keyringlist(void)
-/* XXX add some more abstraction so we can change from GList to anything ? */
 {
 	return purple_keyring_keyringlist;
 }
@@ -107,85 +108,96 @@ purple_keyring_get_inuse(void)
 }
 
 
-/* change keyring to use */
-struct keyringchangeloop
+//typedef void (*PurpleKeyringSaveCallback)(const PurpleAccount * account, GError ** error, gpointer data);
+void
+purple_keyring_set_inuse_check_error_cb(const PurpleAccount * account,
+					GError ** error,
+					gpointer data)
 {
-	/*FIXME : type*/ cb;
-	gpointer data;
-	PurpleKeyring * new;
-	PurpleKeyring * old;
-	GList * cur;	// the account we're playing with
-	char * pass;
-	GError * error;
-};
 
-void 
-purple_keyring_set_inuse_loop_read(struct keyringchangeloop * info)
-{
-	GList * cur;
-	PurpleAccount * account;
+	const char * name;
 
-	cur = info->cur;
+	name = purple_account_get_username(account);
 
-	if (cur == NULL) {
+	if ((error != NULL) && ((**error).domain == ERR_PIDGINKEYRING)) {
 
-		/* we are done, trigger callback */
-		cur->cb(cur->error,cur->data);
+		switch((**error).code) {
 
-	} else {
+			case ERR_NOPASSWD :
+				g_debug("No password found while changing keyring for account %s", name);
+				break;
 
-		account = cur->data;
+			case ERR_NOACCOUNT :
+				g_debug("No info on account %s found while changing keyring", name);
+				break;
 
-		info->pass
-		/* FIXME :
-			-read with callback purple_keyring_set_inuse_loop_save()
-		*/
+			case ERR_NOCHANNEL :
+				g_debug("Failed to communicate with backend while changing keyring for account %s", name);
+				break;
+				/* FIXME : this should somehow abort the whole procedure */
+
+			default :
+				g_debug("Unknown error while changing keyring for account %s", name);
+				break;
+		}
 	}
+
+	return;
 }
 
+//typedef void (*PurpleKeyringReadCallback)(const PurpleAccount * account, gchar * password, GError * error, gpointer data);
+void
+purple_keyring_set_inuse_got_pw_cb(const PurpleAccount * account, 
+			 gchar * password, 
+			 GError ** error, 
+			 gpointer data)
+{
+	PurpleKeyring * new;
 
+	new = (PurpleKeyring *)data;
+	/* XXX check for read error or just forward ? */
 
-/* FIXME : needs to be async !!! */
+	/* XXX change to use accessor */
+	new->save_password(account, password, error,
+		purple_keyring_set_inuse_check_error_cb, NULL);
+
+	return;
+}
+
+
 void 
 purple_keyring_set_inuse(PurpleKeyring * new,
-			 GError ** error,
-			 /*FIXME : type*/ cb,
-			 gpointer data);
+			 GError ** error)
 {
 
 	GList * cur;
-	PurpleKeyring * old;
-	char * password;
+	const PurpleKeyring * old;
 
-
 	if (purple_keyring_inuse != NULL) {
 
-		/* XXX use a wrapper for g_list_foreach ? */
-		/* PSEUDOCODE (FIXME):
-			for all accounts
-				read password from old safe
-				store it in new safe
-			close old safe
-		*/
 		old = purple_keyring_get_inuse();
 
 		for (cur = purple_accounts_get_all(); cur != NULL; cur = cur->next)
 		{
-// FIXME MOAR HERE	password = old->read(cur)
+			old->read_password(cur->data, NULL, purple_keyring_set_inuse_got_pw_cb, (void*)new);
+//typedef void (*PurpleKeyringRead)(const PurpleAccount * account, GError ** error, PurpleKeyringReadCallback cb, gpointer data);
 		}
 
-		old->close();
+		/* FIXME :
+		 * What happens if safe is closed before passwords have been successfully stored ? 
+		 */
+
+		old->close_keyring(error);	/* should automatically free all passwords */
 	}
 
-	purple_keyring_inuse = keyring;
+	purple_keyring_inuse = new;
 	return;
-
 }
 
 /* register a keyring plugin */
 /**
- * TODO : function to unregister a keyring ?
- *	  validate input ? add magix field ?
+ * XXX : function to unregister a keyring ?
+ *	 validate input ? add magix field ?
  */
 void 
 purple_plugin_keyring_register(PurpleKeyring * info)
@@ -203,11 +215,11 @@ purple_plugin_keyring_register(PurpleKey
 /** 
  * used by account.c while reading a password from xml
  * might not really need to be async.
- * TODO : use PurpleKeyringPasswordNode instead of xmlnode ?
+ * TODO : rewrite InternalKeyring as async
  */
 gboolean 
 purple_keyring_import_password(const PurpleKeyringPasswordNode * passwordnode,
-				GError ** error,			// FIXME : re-order arguments in header
+				GError ** error,
 				PurpleKeyringImportCallback cb,
 				gpointer data)
 {
@@ -229,7 +241,7 @@ purple_keyring_export_password(PurpleAcc
  */
 void
 purple_keyring_export_password(PurpleAccount * account,
-			       GError ** error,				// FIXME : re-order arguments in header
+			       GError ** error,
 			       PurpleKeyringImportCallback cb,
 			       gpointer data)
 {
@@ -237,11 +249,11 @@ purple_keyring_export_password(PurpleAcc
 
 		g_set_error(error, ERR_PIDGINKEYRING, ERR_NOKEYRING, 
 			"No Keyring configured.");
-		cb(NULL, error, data);
+		cb(error, data);
 
 	} else {
 		// FIXME : use accessor
-		purple_keyring_inuse->export_password(passwordnode, error, cb, data);
+		purple_keyring_inuse->export_password(account, error, cb, data);
 	}
 	return;
 }
@@ -266,7 +278,7 @@ purple_keyring_get_password(const Purple
 		cb(account, NULL, error, data);
 
 	} else {
-		purple_keyring_inuse->read(account, error, cb, data);
+		purple_keyring_inuse->read_password(account, error, cb, data);
 	}
 	return;
 }
@@ -285,7 +297,7 @@ purple_keyring_set_password(const Purple
 		cb(account, error, data);
 
 	} else {
-		purple_keyring_inuse->save(account, password, error, cb, data);
+		purple_keyring_inuse->save_password(account, password, error, cb, data);
 	}
 	return;
 }
@@ -293,49 +305,49 @@ const char *
 /* accessors for data structure fields */
 	/* PurpleKeyring */
 const char *
-purple_keyring_get_name(PurpleKeyring * info)
+purple_keyring_get_name(const PurpleKeyring * info)
 {
 	return info->name;
 }
 
-PurpleKeyringRead 
+const PurpleKeyringRead 
 purple_keyring_get_read_password(const PurpleKeyring * info)
 {
 	return info->read_password;
 }
 
-PurpleKeyringSave
+const PurpleKeyringSave
 purple_keyring_get_save_password(const PurpleKeyring * info)
 {
 	return info->save_password;
 }
 
-PurpleKeyringClose 
+const PurpleKeyringClose 
 purple_keyring_get_close_keyring(const PurpleKeyring * info)
 {
 	return info->close_keyring;
 }
 
-PurpleKeyringFree 
+const PurpleKeyringFree 
 purple_keyring_get_free_password(const PurpleKeyring * info)
 {
 	return info->free_password;
 }
 
-PurpleKeyringChangeMaster 
+const PurpleKeyringChangeMaster 
 purple_keyring_get_change_master(const PurpleKeyring * info)
 {
 	return info->change_master;
 }
 
-PurpleKeyringImportPassword
+const PurpleKeyringImportPassword
 purple_keyring_get_import_password(const PurpleKeyring * info)
 {
 	return info->import_password;
 }
 
-PurpleKeyringExportPassword 
-purple_keyring_get_export_password(constPurpleKeyring * info)
+const PurpleKeyringExportPassword 
+purple_keyring_get_export_password(const PurpleKeyring * info)
 {
 	return info->export_password;
 }
@@ -411,12 +423,12 @@ purple_keyring_password_node_free(Purple
 void 
 purple_keyring_password_node_free(PurpleKeyringPasswordNode * node)
 {
-	g_free(PurpleKeyringPasswordNode * node);
+	g_free(node);
 	return;
 }
 
-PurpleAccount * 
-purple_keyring_password_node_get_account(PurpleKeyringPasswordNode * info)
+const PurpleAccount * 
+purple_keyring_password_node_get_account(const PurpleKeyringPasswordNode * info)
 {
 	return info->account;
 }
@@ -434,7 +446,7 @@ const char * 
 }
 
 const char * 
-purple_keyring_password_node_get_data(PurpleKeyringPasswordNode * info);
+purple_keyring_password_node_get_data(PurpleKeyringPasswordNode * info)
 {
 	return info->data;
 }
@@ -472,6 +484,11 @@ purple_keyring_password_node_set_data(Pu
 	return;
 }
 
+GQuark
+purple_keyring_error_domain(void)
+{
+	return g_quark_from_static_string("Libpurple keyring");
+}
 
 /**
  * prepare stuff (called at startup)
============================================================
--- libpurple/keyring.h	1fdbcdc6c09632e5ebf5a84cfd3f71787a57f852
+++ libpurple/keyring.h	4b686b96125604d0fc0ec45bb5d1db72ef865eb1
@@ -40,15 +40,17 @@ typedef struct _PurpleKeyringPasswordNod
 
 	/* XXX maybe strip a couple GError* if they're not used */
 /* callbacks */
-typedef void (*PurpleKeyringReadCallback)(const PurpleAccount * account, gchar * password, GError * error, gpointer data);
-typedef void (*PurpleKeyringSaveCallback)(const PurpleAccount * account, GError * error, gpointer data);
-typedef void (*PurpleKeyringChangeMasterCallback)(int result, Gerror * error, gpointer data);
-typedef void (*PurpleKeyringImportCallback)(GError * error, gpointer data);	/* XXX add a gboolean result or just use error ? */
+typedef void (*PurpleKeyringReadCallback)(const PurpleAccount * account, gchar * password, GError ** error, gpointer data);
+typedef void (*PurpleKeyringSaveCallback)(const PurpleAccount * account, GError ** error, gpointer data);
+typedef void (*PurpleKeyringChangeMasterCallback)(int result, GError * error, gpointer data);
+typedef void (*PurpleKeyringImportCallback)(GError ** error, gpointer data);	/* XXX add a gboolean result or just use error ? */
 typedef void (*PurpleKeyringExportCallback)(PurpleKeyringPasswordNode * result, GError * error, gpointer data);
 
 //gboolean purple_keyring_import_password(const PurpleKeyringPasswordNode * passwordnode);
 
+
 /* pointers to the keyring's functions */
+// FIXME : only callback should care about errors
 typedef void (*PurpleKeyringRead)(const PurpleAccount * account, GError ** error, PurpleKeyringReadCallback cb, gpointer data);
 typedef void (*PurpleKeyringSave)(const PurpleAccount * account, gchar * password, GError ** error, PurpleKeyringSaveCallback cb, gpointer data);
 typedef void (*PurpleKeyringClose)(GError ** error);
@@ -61,23 +63,28 @@ typedef void (*PurpleKeyringFree)(gchar 
  *  - add callback, it needs to be async
  *  - typedefs for callbacks
  */
-typedef gboolean (*PurpleKeyringImportPassword)(PurpleKeyringPasswordNode * nodeinfo);
-typedef PurpleKeyringPasswordNode * (*PurpleKeyringExportPassword)(PurpleAccount * account);
+typedef gboolean (*PurpleKeyringImportPassword)(const PurpleKeyringPasswordNode * nodeinfo, GError ** error, PurpleKeyringImportCallback cb, gpointer data);
 
+typedef PurpleKeyringPasswordNode * (*PurpleKeyringExportPassword)(PurpleAccount * account,GError ** error, PurpleKeyringImportCallback cb,     gpointer data);
 
+
 /***************************************/
 /** @name Keyring plugin wrapper API   */
 /***************************************/
 
 /* manipulate keyring list, used by config interface */
 const GList * purple_keyring_get_keyringlist(void);
-const PurpleKeyringInfo * purple_keyring_get_inuse(void);
+const PurpleKeyring * purple_keyring_get_inuse(void);
 
-// FIXME : needs to be async
-void purple_keyring_set_inuse(PurpleKeyringInfo *);	/* changes keyring to use, lots of code involved */
+// FIXME : needs to be async so it can detect errors and undo changes
+void
+purple_keyring_set_inuse_got_pw_cb(const PurpleAccount * account, 
+			 gchar * password, 
+			 GError ** error, 
+			 gpointer data);
 
 /* register a keyring plugin */
-// TODO : function to unregister a keyring ?
+// XXX : function to unregister a keyring ?
 void purple_plugin_keyring_register(PurpleKeyring * info);
 
 /* used by account.c while reading a password from xml */
@@ -99,7 +106,6 @@ so these functions will call : */
 	purple_account_get_password()	<- TODO : rewrite these functions :)
 	purple_account_set_password()
 so these functions will call : */
-/* FIXME : callback of course */
 void purple_keyring_get_password(const PurpleAccount *account,
 				 GError ** error,
 				 PurpleKeyringReadCallback cb,
@@ -111,36 +117,38 @@ void purple_keyring_set_password(const P
 				 gpointer data);
 
 /* accessors for data structure fields */
-	/* PurpleKeyringInfo */
+	/* PurpleKeyring */
 /*
  * TODO : constructor/destructor
  *	  move it back as public. It would actually make much more sense
  * 	  since devs could build static structure
  */
-const char *  purple_keyring_get_name(PurpleKeyringInfo * info);
-const PurpleKeyringRead purple_keyring_get_read_password(PurpleKeyringInfo * info);
-const PurpleKeyringSave purple_keyring_get_save_password(PurpleKeyringInfo * info);
-const PurpleKeyringClose purple_keyring_get_close_keyring(PurpleKeyringInfo * info);
-const PurpleKeyringFree purple_keyring_get_free_password(PurpleKeyringInfo * info);
-const PurpleKeyringChangeMaster purple_keyring_get_change_master(PurpleKeyringInfo * info);
-const PurpleKeyringImportPassword purple_keyring_get_import_password(PurpleKeyringInfo * info);
-const PurpleKeyringExportPassword purple_keyring_get_export_password(PurpleKeyringInfo * info);
+const char * purple_keyring_get_name(const PurpleKeyring * info);
+const PurpleKeyringRead purple_keyring_get_read_password(const PurpleKeyring * info);
+const PurpleKeyringSave purple_keyring_get_save_password(const PurpleKeyring * info);
+const PurpleKeyringClose purple_keyring_get_close_keyring(const PurpleKeyring * info);
+const PurpleKeyringFree purple_keyring_get_free_password(const PurpleKeyring * info);
+const PurpleKeyringChangeMaster purple_keyring_get_change_master(const PurpleKeyring * info);
+const PurpleKeyringImportPassword purple_keyring_get_import_password(const PurpleKeyring * info);
+const PurpleKeyringExportPassword purple_keyring_get_export_password(const PurpleKeyring * info);
 
-void purple_keyring_set_name(PurpleKeyringInfo * info, char * name);		/* must be static, will not be auto-freed upon destruction */
-void purple_keyring_set_read_password(PurpleKeyringInfo * info, PurpleKeyringRead read);
-void purple_keyring_set_save_password(PurpleKeyringInfo * info, PurpleKeyringSave save);
-void purple_keyring_set_close_keyring(PurpleKeyringInfo * info, PurpleKeyringClose close);
-void purple_keyring_set_free_password(PurpleKeyringInfo * info, PurpleKeyringFree free);
-void purple_keyring_set_change_master(PurpleKeyringInfo * info, PurpleKeyringChangeMaster change_master);
-void purple_keyring_set_import_password(PurpleKeyringInfo * info, PurpleKeyringImportPassword import_password);
-void purple_keyring_set_export_password(PurpleKeyringInfo * info, PurpleKeyringExportPassword export_password);
+void purple_keyring_set_name(PurpleKeyring * info, char * name);		/* must be static, will not be auto-freed upon destruction */
+void purple_keyring_set_read_password(PurpleKeyring * info, PurpleKeyringRead read);
+void purple_keyring_set_save_password(PurpleKeyring * info, PurpleKeyringSave save);
+void purple_keyring_set_close_keyring(PurpleKeyring * info, PurpleKeyringClose close);
+void purple_keyring_set_free_password(PurpleKeyring * info, PurpleKeyringFree free);
+void purple_keyring_set_change_master(PurpleKeyring * info, PurpleKeyringChangeMaster change_master);
+void purple_keyring_set_import_password(PurpleKeyring * info, PurpleKeyringImportPassword import_password);
+void purple_keyring_set_export_password(PurpleKeyring * info, PurpleKeyringExportPassword export_password);
 
 	/* PurpleKeyringPasswordNode */
 
 PurpleKeyringPasswordNode * purple_keyring_password_node_new(void);
-void purple_keyring_password_node_new(PurpleKeyringPasswordNode * node);
+void purple_keyring_password_node_delete(PurpleKeyringPasswordNode * node);
 
-const PurpleAccount * purple_keyring_password_node_get_account(PurpleKeyringPasswordNode * info);
+const PurpleAccount * 
+purple_keyring_password_node_get_account(const PurpleKeyringPasswordNode * info);
+
 const char * purple_keyring_password_node_get_encryption(PurpleKeyringPasswordNode * info);		/* info to be kept must be copied */
 const char * purple_keyring_password_node_get_mode(PurpleKeyringPasswordNode * info);			/* strings will be freed after use*/
 const char * purple_keyring_password_node_get_data(PurpleKeyringPasswordNode * info);			/* (in most cases) */
@@ -157,18 +165,18 @@ void purple_keyring_init();
 /** @name Error Codes                  */
 /***************************************/
 
-#define ERR_PIDGINKEYRING	/* error domain FIXME: has to be a GQuark, not just a define
-				 * this should be done in void purple_keyring_init()
-                                 */
+#define ERR_PIDGINKEYRING 	purple_keyring_error_domain()
+GQuark purple_keyring_error_domain(void);
 
 enum
 {
-	ERR_OK = 0		/* no error */
+	ERR_OK = 0,		/* no error */
 	ERR_NOPASSWD = 1,	/* no stored password */
 	ERR_NOACCOUNT,		/* account not found */
 	ERR_WRONGPASS,		/* user submitted wrong password when prompted */
 	ERR_WRONGFORMAT,	/* data passed is not in suitable format*/
-	ERR_NOKEYRING		/* no keyring configured */
+	ERR_NOKEYRING,		/* no keyring configured */
+	ERR_NOCHANNEL
 } PurpleKeyringError;
 
 


More information about the Commits mailing list