libpurple/plugins/perl/perl-handlers.c

branch
soc.2008.masterpassword
changeset 34198
89549a1875e0
parent 34040
f5417957a1bc
child 34803
e0c884a4419a
--- a/libpurple/plugins/perl/perl-handlers.c	Tue May 14 01:43:55 2013 +0200
+++ b/libpurple/plugins/perl/perl-handlers.c	Tue May 14 13:07:06 2013 +0200
@@ -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 @@
 }
 
 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 @@
 
 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 @@
 {
 	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);
 }
-

mercurial