Fix Perl compile. This probably doesn't work. I just copy and pasted soc.2008.masterpassword

Sun, 06 Nov 2011 02:05:29 +0000

author
Elliott Sales de Andrade <qulogic@pidgin.im>
date
Sun, 06 Nov 2011 02:05:29 +0000
branch
soc.2008.masterpassword
changeset 34040
f5417957a1bc
parent 34039
52379a0a335d
child 34041
75204e58b8ca

Fix Perl compile. This probably doesn't work. I just copy and pasted
things. Someone should really check this stuff.

libpurple/plugins/perl/common/Account.xs file | annotate | diff | comparison | revisions
libpurple/plugins/perl/perl-handlers.c file | annotate | diff | comparison | revisions
libpurple/plugins/perl/perl-handlers.h file | annotate | diff | comparison | revisions
--- a/libpurple/plugins/perl/common/Account.xs	Tue Nov 01 04:58:05 2011 +0000
+++ b/libpurple/plugins/perl/common/Account.xs	Sun Nov 06 02:05:29 2011 +0000
@@ -1,4 +1,5 @@
 #include "module.h"
+#include "../perl-handlers.h"
 
 MODULE = Purple::Account  PACKAGE = Purple::Account  PREFIX = purple_account_
 PROTOTYPES: ENABLE
@@ -44,9 +45,13 @@
     const char * username
 
 void
-purple_account_set_password(account, password)
+purple_account_set_password(account, password, func, data = 0)
     Purple::Account account
     const char * password
+    SV *func
+    SV *data
+CODE:
+	purple_perl_account_set_password(account, password, func, data);
 
 void
 purple_account_set_alias(account, alias)
@@ -130,9 +135,13 @@
 purple_account_get_username(account)
     Purple::Account account
 
-const char *
-purple_account_get_password(account)
+void
+purple_account_get_password(account, func, data = 0)
     Purple::Account account
+    SV *func
+    SV *data
+CODE:
+	purple_perl_account_get_password(account, func, data);
 
 const char *
 purple_account_get_alias(account)
--- a/libpurple/plugins/perl/perl-handlers.c	Tue Nov 01 04:58:05 2011 +0000
+++ b/libpurple/plugins/perl/perl-handlers.c	Sun Nov 06 02:05:29 2011 +0000
@@ -845,3 +845,127 @@
 			destroy_prefs_handler(handler);
 	}
 }
+
+static void
+perl_account_save_cb(PurpleAccount *account, GError *error, gpointer data)
+{
+	int count;
+	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"));
+	XPUSHs(accountSV);
+
+	/* Push the error onto the perl stack */
+	errorSV = sv_2mortal(purple_perl_bless_object(account, "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");
+
+	if (SvTRUE(ERRSV)) {
+		purple_debug_error("perl",
+		                 "Perl plugin command function exited abnormally: %s\n",
+		                 SvPVutf8_nolen(ERRSV));
+	}
+
+	SPAGAIN;
+
+	PUTBACK;
+	FREETMPS;
+	LEAVE;
+
+	g_free(handler);
+}
+
+static void
+perl_account_read_cb(PurpleAccount *account, const gchar *password,
+                     GError *error, gpointer data)
+{
+	int count;
+	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"));
+	XPUSHs(accountSV);
+
+	/* Push the password onto the perl stack */
+	passwordSV = newSVpv(password, 0);
+	passwordSV = sv_2mortal(passwordSV);
+	XPUSHs(passwordSV);
+
+	/* Push the error onto the perl stack */
+	errorSV = sv_2mortal(purple_perl_bless_object(account, "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");
+
+	if (SvTRUE(ERRSV)) {
+		purple_debug_error("perl",
+		                 "Perl plugin command function exited abnormally: %s\n",
+		                 SvPVutf8_nolen(ERRSV));
+	}
+
+	SPAGAIN;
+
+	PUTBACK;
+	FREETMPS;
+	LEAVE;
+
+	g_free(handler);
+}
+
+void
+purple_perl_account_get_password(PurpleAccount *account, SV *func, SV *data)
+{
+	PurplePerlAccountPasswordHandler *handler;
+
+	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);
+
+	purple_account_get_password(account, perl_account_read_cb, data);
+}
+
+void
+purple_perl_account_set_password(PurpleAccount *account, const char *password,
+                                 SV *func, SV *data)
+{
+	PurplePerlAccountPasswordHandler *handler;
+
+	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);
+
+	purple_account_set_password(account, password, perl_account_save_cb, data);
+}
+
--- a/libpurple/plugins/perl/perl-handlers.h	Tue Nov 01 04:58:05 2011 +0000
+++ b/libpurple/plugins/perl/perl-handlers.h	Sun Nov 06 02:05:29 2011 +0000
@@ -48,6 +48,13 @@
 
 } 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);
 
@@ -82,4 +89,10 @@
 void purple_perl_prefs_disconnect_callback(guint callback_id);
 void purple_perl_pref_cb_clear_for_plugin(PurplePlugin *plugin);
 
+void
+purple_perl_account_get_password(PurpleAccount *account, SV *func, SV *data);
+void
+purple_perl_account_set_password(PurpleAccount *account, const char *password,
+                                 SV *func, SV *data);
+
 #endif /* _PURPLE_PERL_HANDLERS_H_ */

mercurial