soc.2008.masterpassword: b7bcba87: Fixed warnings
scrouaf at soc.pidgin.im
scrouaf at soc.pidgin.im
Fri Jul 11 18:31:00 EDT 2008
-----------------------------------------------------------------
Revision: b7bcba87086701ea048aeae49f4378f0716040b9
Ancestor: 09a9aeebffa52cbf6d585d7fe76a5c2e606f9725
Author: scrouaf at soc.pidgin.im
Date: 2008-07-10T19:08:26
Branch: im.pidgin.soc.2008.masterpassword
URL: http://d.pidgin.im/viewmtn/revision/info/b7bcba87086701ea048aeae49f4378f0716040b9
Modified files:
libpurple/keyring.c libpurple/keyring.h
libpurple/plugins/keyrings/internalkeyring.c
ChangeLog:
Fixed warnings
-------------- next part --------------
============================================================
--- libpurple/keyring.c 581195a2d83908edcb07b7c4d090a181c06d0641
+++ libpurple/keyring.c 241640ae8404938e9c56c7b9639a6a773e74199e
@@ -32,13 +32,13 @@
*
* TODO :
* - use accessors
- * - compare header with this file
* - purple_keyring_init()
* - purple_keyring_set_inuse() needs to be async for error checking an reversability.
*
* Questions :
- * - use accessors internally
* - cleanup
+ * - warning
+ * - breaking API
*/
#include <glib.h>
@@ -49,24 +49,6 @@
/* opaque structures */
/*******************************/
-/* information about a keyring */
-// FIXME : This should actually probably a public structure
-struct _PurpleKeyring
-{
- char * name;
- PurpleKeyringRead read_password;
- PurpleKeyringSave save_password;
- PurpleKeyringClose close_keyring;
- PurpleKeyringFree free_password;
- PurpleKeyringChangeMaster change_master;
- PurpleKeyringImportPassword import_password;
- PurpleKeyringExportPassword export_password;
- gpointer r1; /* RESERVED */
- gpointer r2; /* RESERVED */
- gpointer r3; /* RESERVED */
-};
-
-
/* used to import and export password info */
struct _PurpleKeyringPasswordNode
{
@@ -153,18 +135,22 @@ purple_keyring_set_inuse_got_pw_cb(const
gpointer data)
{
PurpleKeyring * new;
-
+ PurpleKeyringSave save;
new = (PurpleKeyring *)data;
/* XXX check for read error or just forward ? */
/* XXX change to use accessor */
- new->save_password(account, password, error,
- purple_keyring_set_inuse_check_error_cb, NULL);
+ //typedef void (*PurpleKeyringSave)(const PurpleAccount * account, gchar * password, GError ** error, PurpleKeyringSaveCallback cb, gpointer data);
+
+ save = purple_keyring_get_save_password(new);
+ save(account, password, error, purple_keyring_set_inuse_check_error_cb,
+ NULL);
+
return;
}
-
+/* FIXME : needs to be async and cancelable */
void
purple_keyring_set_inuse(PurpleKeyring * new,
GError ** error)
@@ -172,6 +158,8 @@ purple_keyring_set_inuse(PurpleKeyring *
GList * cur;
const PurpleKeyring * old;
+ PurpleKeyringClose close;
+ PurpleKeyringRead read;
if (purple_keyring_inuse != NULL) {
@@ -179,15 +167,16 @@ purple_keyring_set_inuse(PurpleKeyring *
for (cur = purple_accounts_get_all(); cur != NULL; cur = cur->next)
{
- 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);
+ read = purple_keyring_get_read_password(old);
+ read(cur->data, NULL, purple_keyring_set_inuse_got_pw_cb, (void*)new);
}
/* FIXME :
* What happens if safe is closed before passwords have been successfully stored ?
*/
- old->close_keyring(error); /* should automatically free all passwords */
+ close = purple_keyring_get_close_keyring(old);
+ close(error); /* should automatically free all passwords */
}
purple_keyring_inuse = new;
@@ -217,12 +206,14 @@ purple_plugin_keyring_register(PurpleKey
* might not really need to be async.
* TODO : rewrite InternalKeyring as async
*/
-gboolean
+void
purple_keyring_import_password(const PurpleKeyringPasswordNode * passwordnode,
GError ** error,
PurpleKeyringImportCallback cb,
gpointer data)
{
+ PurpleKeyringImportPassword import;
+
if (purple_keyring_inuse == NULL) {
g_set_error(error, ERR_PIDGINKEYRING, ERR_NOKEYRING,
@@ -230,7 +221,8 @@ purple_keyring_import_password(const Pur
cb(error, data);
} else {
- purple_keyring_inuse->import_password(passwordnode, error, cb, data);
+ import = purple_keyring_get_import_password(purple_keyring_inuse);
+ import(passwordnode, error, cb, data);
}
return;
}
@@ -245,6 +237,8 @@ purple_keyring_export_password(PurpleAcc
PurpleKeyringImportCallback cb,
gpointer data)
{
+ PurpleKeyringExportPassword export;
+
if (purple_keyring_inuse == NULL) {
g_set_error(error, ERR_PIDGINKEYRING, ERR_NOKEYRING,
@@ -252,8 +246,8 @@ purple_keyring_export_password(PurpleAcc
cb(error, data);
} else {
- // FIXME : use accessor
- purple_keyring_inuse->export_password(account, error, cb, data);
+ export = purple_keyring_get_export_password(purple_keyring_inuse);
+ export(account, error, cb, data);
}
return;
}
@@ -261,7 +255,7 @@ purple_keyring_export_password(PurpleAcc
/**
* functions called from the code to access passwords (account.h):
- * purple_account_get_password() <- TODO : rewrite these functions :)
+ * purple_account_get_password() <- TODO : rewrite these functions as asynch, as well as functions calling them. Will most likely break API compatibility.
* purple_account_set_password()
* so these functions will call :
*/
@@ -271,6 +265,8 @@ purple_keyring_get_password(const Purple
PurpleKeyringReadCallback cb,
gpointer data)
{
+ PurpleKeyringRead read;
+
if (purple_keyring_inuse == NULL) {
g_set_error(error, ERR_PIDGINKEYRING, ERR_NOKEYRING,
@@ -278,7 +274,10 @@ purple_keyring_get_password(const Purple
cb(account, NULL, error, data);
} else {
- purple_keyring_inuse->read_password(account, error, cb, data);
+
+ read = purple_keyring_get_read_password(purple_keyring_inuse);
+ read(account, error, cb, data);
+
}
return;
}
@@ -290,6 +289,8 @@ purple_keyring_set_password(const Purple
PurpleKeyringSaveCallback cb,
gpointer data)
{
+ PurpleKeyringSave save;
+
if (purple_keyring_inuse == NULL) {
g_set_error(error, ERR_PIDGINKEYRING, ERR_NOKEYRING,
@@ -297,7 +298,8 @@ purple_keyring_set_password(const Purple
cb(account, error, data);
} else {
- purple_keyring_inuse->save_password(account, password, error, cb, data);
+ save = purple_keyring_get_save_password(purple_keyring_inuse);
+ save(account, password, error, cb, data);
}
return;
}
@@ -310,43 +312,43 @@ purple_keyring_get_name(const PurpleKeyr
return info->name;
}
-const PurpleKeyringRead
+PurpleKeyringRead
purple_keyring_get_read_password(const PurpleKeyring * info)
{
return info->read_password;
}
-const PurpleKeyringSave
+PurpleKeyringSave
purple_keyring_get_save_password(const PurpleKeyring * info)
{
return info->save_password;
}
-const PurpleKeyringClose
+PurpleKeyringClose
purple_keyring_get_close_keyring(const PurpleKeyring * info)
{
return info->close_keyring;
}
-const PurpleKeyringFree
+PurpleKeyringFree
purple_keyring_get_free_password(const PurpleKeyring * info)
{
return info->free_password;
}
-const PurpleKeyringChangeMaster
+PurpleKeyringChangeMaster
purple_keyring_get_change_master(const PurpleKeyring * info)
{
return info->change_master;
}
-const PurpleKeyringImportPassword
+PurpleKeyringImportPassword
purple_keyring_get_import_password(const PurpleKeyring * info)
{
return info->import_password;
}
-const PurpleKeyringExportPassword
+PurpleKeyringExportPassword
purple_keyring_get_export_password(const PurpleKeyring * info)
{
return info->export_password;
============================================================
--- libpurple/keyring.h 4b686b96125604d0fc0ec45bb5d1db72ef865eb1
+++ libpurple/keyring.h ef4ae6b655e7f04f91149f61c9a0b56055b4d331
@@ -38,9 +38,18 @@ typedef struct _PurpleKeyringPasswordNod
typedef struct _PurpleKeyringPasswordNode PurpleKeyringPasswordNode; /* opaque struct */
- /* XXX maybe strip a couple GError* if they're not used */
+
+/**
+ * XXX maybe strip a couple GError* if they're not used
+ * since they should only be interresting for the callback
+ * --> ability to forward errors ?
+ */
+
/* callbacks */
-typedef void (*PurpleKeyringReadCallback)(const PurpleAccount * account, gchar * password, GError ** error, gpointer data);
+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 ? */
@@ -63,11 +72,29 @@ typedef void (*PurpleKeyringFree)(gchar
* - add callback, it needs to be async
* - typedefs for callbacks
*/
-typedef gboolean (*PurpleKeyringImportPassword)(const PurpleKeyringPasswordNode * nodeinfo, GError ** error, PurpleKeyringImportCallback cb, gpointer data);
+typedef void (*PurpleKeyringImportPassword)(const PurpleKeyringPasswordNode * nodeinfo, GError ** error, PurpleKeyringImportCallback cb, gpointer data);
typedef PurpleKeyringPasswordNode * (*PurpleKeyringExportPassword)(PurpleAccount * account,GError ** error, PurpleKeyringImportCallback cb, gpointer data);
+/* information about a keyring */
+struct _PurpleKeyring
+{
+ char * name;
+ PurpleKeyringRead read_password;
+ PurpleKeyringSave save_password;
+ PurpleKeyringClose close_keyring;
+ PurpleKeyringFree free_password;
+ PurpleKeyringChangeMaster change_master;
+ PurpleKeyringImportPassword import_password;
+ PurpleKeyringExportPassword export_password;
+ gpointer r1; /* RESERVED */
+ gpointer r2; /* RESERVED */
+ gpointer r3; /* RESERVED */
+};
+
+
+
/***************************************/
/** @name Keyring plugin wrapper API */
/***************************************/
@@ -124,13 +151,13 @@ const char * purple_keyring_get_name(con
* since devs could build static structure
*/
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);
+PurpleKeyringRead purple_keyring_get_read_password(const PurpleKeyring * info);
+PurpleKeyringSave purple_keyring_get_save_password(const PurpleKeyring * info);
+PurpleKeyringClose purple_keyring_get_close_keyring(const PurpleKeyring * info);
+PurpleKeyringFree purple_keyring_get_free_password(const PurpleKeyring * info);
+PurpleKeyringChangeMaster purple_keyring_get_change_master(const PurpleKeyring * info);
+PurpleKeyringImportPassword purple_keyring_get_import_password(const PurpleKeyring * info);
+PurpleKeyringExportPassword purple_keyring_get_export_password(const PurpleKeyring * info);
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);
============================================================
--- libpurple/plugins/keyrings/internalkeyring.c ef57cd56ba4aab0b880c168e52012fffad6cb22b
+++ libpurple/plugins/keyrings/internalkeyring.c b74d038b1fafbed915b1e5563c4b9b86806ff22f
@@ -8,6 +8,7 @@
#include <glib.h>
#include <string.h>
+#include "version.h"
#include "keyring.h"
#include "account.h"
@@ -15,26 +16,22 @@
/** Macros and constants */
/******************************/
+#define KEYRINGNAME "internalkeyring"
#define INTERNALKEYRING_VERSION "0.2a"
-#define INTERNALKEYRING_ID "???"
+#define INTERNALKEYRING_ID "core-scrouaf-internalkeyring"
#define INTERNALKEYRING_AUTHOR "Vivien Bernet-Rollande <vbernetr at etu.utc.fr>"
#define INTERNALKEYRING_DESCRIPTION \
"This keyring plugin offers a password storage backend compatible with the former storage system."
-#define IS_VALID_CLEARTEXT_INFO(nodeinfo) \
- (((nodeinfo->encryption == NULL) || (strcpy(nodeinfo->encryption, KEYRINGNAME) == 0)) \
- && ((nodeinfo->mode == NULL) || (strcpy(nodeinfo->mode, "cleartext") == 0)) \
- && (nodeinfo->data != NULL) && (nodeinfo->account != NULL))
-
/******************************/
/** Data Structures */
/******************************/
-typedef stuct _InternalKeyring_PasswordInfo InternalKeyring_PasswordInfo;
+typedef struct _InternalKeyring_PasswordInfo InternalKeyring_PasswordInfo;
struct _InternalKeyring_PasswordInfo {
- PurpleAccount * account;
+ const PurpleAccount * account;
gchar * password;
};
@@ -53,13 +50,14 @@ GList * InternalKeyring_passwordlist = N
* retrieve the InternalKeyring_PasswordInfo structure for an account
* TODO : rewrite this to use hashtables rather than GList
*/
-PasswordInfo * InternalKeyring_get_account_info(PurpleAccount * account)
+InternalKeyring_PasswordInfo *
+InternalKeyring_get_account_info(const PurpleAccount * account)
{
GList * p;
- InternalKeyring_PasswordInfo i;
+ InternalKeyring_PasswordInfo * i;
- for (p = InternalKeyring_passworlist; p != NULL; p = p->next) {
- i = (PasswordInfo)(p->data)
+ for (p = InternalKeyring_passwordlist; p != NULL; p = p->next) {
+ i = (InternalKeyring_PasswordInfo*)(p->data);
if (i->account == account)
return i;
}
@@ -68,8 +66,8 @@ PasswordInfo * InternalKeyring_get_accou
/**
* Free or create an InternalKeyring_PasswordInfo structure and all pointed data.
- * /!\ Update this when adding fields to InternalKeyring_PasswordInfo
- * TODO : rewrite this to use hashtables rather than GList
+ * XXX /!\ Update this when adding fields to InternalKeyring_PasswordInfo
+ * XXX : rewrite this to use hashtables rather than GList
* (fix InternalKeyring_Close() as well)
*/
void
@@ -83,12 +81,50 @@ InternalKeyring_free_passwordinfo(Intern
InternalKeyring_free_passwordinfo(InternalKeyring_PasswordInfo * info)
{
g_free(info->password);
- g_list_remove(InternalKeyring_passwordlist, info);
+ InternalKeyring_passwordlist = g_list_remove(InternalKeyring_passwordlist, info);
g_free(info);
return;
}
+/**
+ * wrapper so we can use it in close
+ * TODO : find a more elegant way
+ */
+void
+InternalKeyring_free_passwordinfo_from_g_list(gpointer info, gpointer data)
+{
+ InternalKeyring_free_passwordinfo((InternalKeyring_PasswordInfo*)info);
+ return;
+}
+
+gboolean
+InternalKeyring_is_valid_cleartext(PurpleKeyringPasswordNode * node)
+{
+ const char * enc;
+ const char * mode;
+ const char * data;
+ const PurpleAccount * account;
+
+ enc = purple_keyring_password_node_get_encryption(node);
+ mode = purple_keyring_password_node_get_mode(node);
+ data = purple_keyring_password_node_get_data(node);
+ account = purple_keyring_password_node_get_account(node);
+
+ if (((enc == NULL) || (strcmp(enc, KEYRINGNAME) == 0))
+ &&((mode == NULL) || (strcmp(mode, "cleartext") == 0))
+ &&(data != NULL)
+ &&(account != NULL)) {
+
+ return TRUE;
+
+ } else {
+
+ return FALSE;
+
+ }
+}
+
/******************************/
/** Keyring interface */
/******************************/
@@ -134,11 +170,11 @@ InternalKeyring_save(const PurpleAccount
void
InternalKeyring_save(const PurpleAccount * account,
gchar * password,
- GError ** error, import
+ GError ** error,
PurpleKeyringSaveCallback cb,
gpointer data)
{
- InternalKeyring_PasswordInfo info;
+ InternalKeyring_PasswordInfo * info;
info = InternalKeyring_get_account_info(account);
@@ -159,7 +195,7 @@ InternalKeyring_save(const PurpleAccount
} else { /* password != NULL */
- if ( info == null ) {
+ if ( info == NULL ) {
info = g_malloc0(sizeof (InternalKeyring_PasswordInfo));
InternalKeyring_add_passwordinfo(info);
}
@@ -184,8 +220,8 @@ InternalKeyring_Close(GError ** error)
void
InternalKeyring_Close(GError ** error)
{
- g_list_foreach(InternalKeyring_passwordlist, InternalKeyring_free_passwordinfo,
- NULL);
+ g_list_foreach(InternalKeyring_passwordlist,
+ InternalKeyring_free_passwordinfo_from_g_list, NULL);
return;
}
@@ -211,16 +247,18 @@ InternalKeyring_import_password(PurpleKe
InternalKeyring_import_password(PurpleKeyringPasswordNode * nodeinfo)
{
InternalKeyring_PasswordInfo * pwinfo;
+ const char * data;
- if (IS_VALID_CLEARTEXT_INFO(nodeinfo) {
+ if (InternalKeyring_is_valid_cleartext(nodeinfo)) {
pwinfo = g_malloc0(sizeof(InternalKeyring_PasswordInfo));
InternalKeyring_add_passwordinfo(pwinfo);
- pwinfo->password = g_malloc(strlen(nodeinfo->data) + 1);
- strcpy(pwinfo->password, nodeinfo->data);
+ data = purple_keyring_password_node_get_data(nodeinfo);
+ pwinfo->password = g_malloc(strlen(data) + 1);
+ strcpy(pwinfo->password, data);
- pwinfo->account = nodeinfo->account;
+ pwinfo->account = purple_keyring_password_node_get_account(nodeinfo);
return TRUE;
@@ -241,8 +279,8 @@ InternalKeyring_export_password(PurpleAc
PurpleKeyringPasswordNode *
InternalKeyring_export_password(PurpleAccount * account)
{
- PurpleKeyringPasswordNode * nodeinfo
- InternalKeyring_PasswordInfo pwinfo;
+ PurpleKeyringPasswordNode * nodeinfo;
+ InternalKeyring_PasswordInfo * pwinfo;
nodeinfo = purple_keyring_password_node_new();
pwinfo = InternalKeyring_get_account_info(account);
@@ -252,7 +290,7 @@ InternalKeyring_export_password(PurpleAc
else {
purple_keyring_password_node_set_encryption(nodeinfo, KEYRINGNAME);
purple_keyring_password_node_set_mode(nodeinfo, "cleartext");
- purple_keyring_password_node_set_data(nodeinfo, password);
+ purple_keyring_password_node_set_data(nodeinfo, pwinfo->password);
return nodeinfo;
}
@@ -266,7 +304,7 @@ InternalKeyring_load(PurplePlugin *plugi
gboolean
InternalKeyring_load(PurplePlugin *plugin)
{
- purple_plugin_keyring_register(InternalKeyring_KeyringInfo);
+// purple_plugin_keyring_register(InternalKeyring_KeyringInfo); /* FIXME : structure doesn't exist yet */
return TRUE;
}
More information about the Commits
mailing list