/cpw/tomkiewicz/masterpassword: 89549a1875e0: Fix perl handlers ...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Tue May 14 07:07:15 EDT 2013


Changeset: 89549a1875e01b441a207d82d8fce0244978fd2c
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2013-05-14 13:07 +0200
Branch:	 soc.2008.masterpassword
URL: https://hg.pidgin.im/cpw/tomkiewicz/masterpassword/rev/89549a1875e0

Description:

Fix perl handlers for password access routines

diffstat:

 libpurple/plugins/perl/common/Account.xs  |   4 +-
 libpurple/plugins/perl/perl-handlers.c    |  94 ++++++++++++++----------------
 libpurple/plugins/perl/perl-handlers.h    |   7 --
 libpurple/plugins/perl/scripts/account.pl |  33 ++++++++++
 4 files changed, 79 insertions(+), 59 deletions(-)

diffs (261 lines):

diff --git a/libpurple/plugins/perl/common/Account.xs b/libpurple/plugins/perl/common/Account.xs
--- a/libpurple/plugins/perl/common/Account.xs
+++ b/libpurple/plugins/perl/common/Account.xs
@@ -51,7 +51,7 @@ purple_account_set_password(account, pas
     SV *func
     SV *data
 CODE:
-	purple_perl_account_set_password(account, password, func, data);
+    purple_perl_account_set_password(account, password, func, data);
 
 void
 purple_account_set_alias(account, alias)
@@ -141,7 +141,7 @@ purple_account_get_password(account, fun
     SV *func
     SV *data
 CODE:
-	purple_perl_account_get_password(account, func, data);
+    purple_perl_account_get_password(account, func, data);
 
 const char *
 purple_account_get_alias(account)
diff --git a/libpurple/plugins/perl/perl-handlers.c b/libpurple/plugins/perl/perl-handlers.c
--- a/libpurple/plugins/perl/perl-handlers.c
+++ b/libpurple/plugins/perl/perl-handlers.c
@@ -4,6 +4,12 @@
 #include "debug.h"
 #include "signals.h"
 
+typedef struct
+{
+	SV *callback;
+	SV *data;
+} PurplePerlAccountPasswordHandler;
+
 extern PerlInterpreter *my_perl;
 static GSList *cmd_handlers = NULL;
 static GSList *signal_handlers = NULL;
@@ -847,42 +853,34 @@ void purple_perl_pref_cb_clear_for_plugi
 }
 
 static void
-perl_account_save_cb(PurpleAccount *account, GError *error, gpointer data)
+perl_account_save_cb(PurpleAccount *account, GError *error, gpointer _handler)
 {
-	int count;
+	PurplePerlAccountPasswordHandler *handler = _handler;
 	SV *accountSV, *errorSV;
-	PurplePerlAccountPasswordHandler *handler = data;
 
 	dSP;
 	ENTER;
 	SAVETMPS;
 	PUSHMARK(SP);
 
-	/* Push the account onto the perl stack */
-	accountSV = sv_2mortal(purple_perl_bless_object(account, "Purple::Account"));
+	accountSV = sv_2mortal(purple_perl_bless_object(account,
+		"Purple::Account"));
 	XPUSHs(accountSV);
 
-	/* Push the error onto the perl stack */
-	errorSV = sv_2mortal(purple_perl_bless_object(account, "GLib::Error"));
+	errorSV = sv_2mortal(purple_perl_bless_object(error, "GLib::Error"));
 	XPUSHs(errorSV);
 
-	/* Push the data onto the perl stack */
 	XPUSHs((SV *)handler->data);
 
 	PUTBACK;
-	count = call_sv(handler->callback, G_EVAL | G_SCALAR);
-
-	if (count != 0)
-		croak("call_sv: Did not return the correct number of values.\n");
+	call_sv(handler->callback, G_EVAL | G_SCALAR);
+	SPAGAIN;
 
 	if (SvTRUE(ERRSV)) {
-		purple_debug_error("perl",
-		                 "Perl plugin command function exited abnormally: %s\n",
-		                 SvPVutf8_nolen(ERRSV));
+		purple_debug_error("perl", "Perl plugin command function "
+			"exited abnormally: %s\n", SvPVutf8_nolen(ERRSV));
 	}
 
-	SPAGAIN;
-
 	PUTBACK;
 	FREETMPS;
 	LEAVE;
@@ -892,47 +890,37 @@ perl_account_save_cb(PurpleAccount *acco
 
 static void
 perl_account_read_cb(PurpleAccount *account, const gchar *password,
-                     GError *error, gpointer data)
+	GError *error, gpointer _handler)
 {
-	int count;
+	PurplePerlAccountPasswordHandler *handler = _handler;
 	SV *accountSV, *passwordSV, *errorSV;
-	PurplePerlAccountPasswordHandler *handler = data;
 
 	dSP;
 	ENTER;
 	SAVETMPS;
 	PUSHMARK(SP);
 
-	/* Push the account onto the perl stack */
-	accountSV = sv_2mortal(purple_perl_bless_object(account, "Purple::Account"));
+	accountSV = sv_2mortal(purple_perl_bless_object(account,
+		"Purple::Account"));
 	XPUSHs(accountSV);
 
-	/* Push the password onto the perl stack */
-	passwordSV = newSVpv(password, 0);
-	passwordSV = sv_2mortal(passwordSV);
+	passwordSV = sv_2mortal(newSVpv(password, 0));
 	XPUSHs(passwordSV);
 
-	/* Push the error onto the perl stack */
-	errorSV = sv_2mortal(purple_perl_bless_object(account, "GLib::Error"));
+	errorSV = sv_2mortal(purple_perl_bless_object(error, "GLib::Error"));
 	XPUSHs(errorSV);
 
-	/* Push the data onto the perl stack */
 	XPUSHs((SV *)handler->data);
 
 	PUTBACK;
-	count = call_sv(handler->callback, G_EVAL | G_SCALAR);
-
-	if (count != 0)
-		croak("call_sv: Did not return the correct number of values.\n");
+	call_sv(handler->callback, G_EVAL | G_SCALAR);
+	SPAGAIN;
 
 	if (SvTRUE(ERRSV)) {
-		purple_debug_error("perl",
-		                 "Perl plugin command function exited abnormally: %s\n",
-		                 SvPVutf8_nolen(ERRSV));
+		purple_debug_error("perl", "Perl plugin command function "
+			"exited abnormally: %s\n", SvPVutf8_nolen(ERRSV));
 	}
 
-	SPAGAIN;
-
 	PUTBACK;
 	FREETMPS;
 	LEAVE;
@@ -945,27 +933,33 @@ purple_perl_account_get_password(PurpleA
 {
 	PurplePerlAccountPasswordHandler *handler;
 
+	if (func == &PL_sv_undef)
+		func = NULL;
+	if (data == &PL_sv_undef)
+		data = NULL;
+
 	handler = g_new0(PurplePerlAccountPasswordHandler, 1);
-	handler->callback = (func != NULL &&
-	                     func != &PL_sv_undef ? newSVsv(func) : NULL);
-	handler->data     = (data != NULL &&
-	                     data != &PL_sv_undef ? newSVsv(data) : NULL);
+	handler->callback = (func != NULL ? newSVsv(func) : NULL);
+	handler->data = (data != NULL ? newSVsv(data) : NULL);
 
-	purple_account_get_password(account, perl_account_read_cb, data);
+	purple_account_get_password(account, perl_account_read_cb, handler);
 }
 
 void
-purple_perl_account_set_password(PurpleAccount *account, const char *password,
-                                 SV *func, SV *data)
+purple_perl_account_set_password(PurpleAccount *account, const gchar *password,
+	SV *func, SV *data)
 {
 	PurplePerlAccountPasswordHandler *handler;
 
+	if (func == &PL_sv_undef)
+		func = NULL;
+	if (data == &PL_sv_undef)
+		data = NULL;
+
 	handler = g_new0(PurplePerlAccountPasswordHandler, 1);
-	handler->callback = (func != NULL &&
-	                     func != &PL_sv_undef ? newSVsv(func) : NULL);
-	handler->data     = (data != NULL &&
-	                     data != &PL_sv_undef ? newSVsv(data) : NULL);
+	handler->callback = (func != NULL ? newSVsv(func) : NULL);
+	handler->data = (data != NULL ? newSVsv(data) : NULL);
 
-	purple_account_set_password(account, password, perl_account_save_cb, data);
+	purple_account_set_password(account, password, perl_account_save_cb,
+		handler);
 }
-
diff --git a/libpurple/plugins/perl/perl-handlers.h b/libpurple/plugins/perl/perl-handlers.h
--- a/libpurple/plugins/perl/perl-handlers.h
+++ b/libpurple/plugins/perl/perl-handlers.h
@@ -48,13 +48,6 @@ typedef struct
 
 } PurplePerlPrefsHandler;
 
-typedef struct
-{
-	SV *callback;
-	SV *data;
-
-} PurplePerlAccountPasswordHandler;
-
 void purple_perl_plugin_action_cb(PurplePluginAction * gpa);
 GList *purple_perl_plugin_actions(PurplePlugin *plugin, gpointer context);
 
diff --git a/libpurple/plugins/perl/scripts/account.pl b/libpurple/plugins/perl/scripts/account.pl
--- a/libpurple/plugins/perl/scripts/account.pl
+++ b/libpurple/plugins/perl/scripts/account.pl
@@ -34,6 +34,37 @@ sub plugin_init {
 	return %PLUGIN_INFO;
 }
 
+sub set_password_cb
+{
+	my $account = shift;
+	my $error = shift;
+	my $data = shift;
+
+	if ($error) {
+		Purple::Debug::warning($MODULE_NAME, "Failed to set password " .
+			"for $account\n");
+		return;
+	}
+
+	Purple::Debug::misc($MODULE_NAME, "Password for $account was set\n");
+}
+
+sub get_password_cb
+{
+	my $account = shift;
+	my $password = shift;
+	my $error = shift;
+	my $data = shift;
+
+	if ($error) {
+		Purple::Debug::warning($MODULE_NAME, "Failed to get password for $account\n");
+		return;
+	}
+
+	Purple::Debug::misc($MODULE_NAME, "Got password for $account\n");
+
+	$account->set_password($password, \&set_password_cb);
+}
 
 # This is the sub defined in %PLUGIN_INFO to be called when the plugin is loaded
 #	Note: The plugin has a reference to itself on top of the argument stack.
@@ -101,6 +132,8 @@ sub plugin_load {
 	$account->set_status("available", TRUE);
 	$account->connect();
 
+	$account->get_password(\&get_password_cb);
+
 	print "\n\n";
 	Purple::Debug::info($MODULE_NAME, "plugin_load() - Testing $MODULE_NAME Completed.\n");
 	print "\n\n" . "#" x 80 . "\n\n";



More information about the Commits mailing list