Tue, 06 Jan 2009 06:29:44 +0000
Apparently our use of va_list arguments in the perl signal callbacks doesn't
work on x86_64 (and other architectures where a va_list is not a pointer but
an array).
Pull an autoconf macro from Glib svn to check whether va_lists are arrays and
switch how we use them on that.
I'm not at all sure this is a complete fix but it seems to fix the issue as
currently reported.
Fixes #7404
| 6520 | 1 | #include "perl-common.h" |
| 2 | #include "perl-handlers.h" | |
| 3 | ||
| 4 | #include "debug.h" | |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
5 | #include "signals.h" |
| 6520 | 6 | |
| 12882 | 7 | extern PerlInterpreter *my_perl; |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
8 | static GSList *cmd_handlers = NULL; |
|
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
9 | static GSList *signal_handlers = NULL; |
|
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
10 | static GSList *timeout_handlers = NULL; |
|
23930
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
11 | static GSList *pref_handlers = NULL; |
| 6520 | 12 | |
|
12165
9f2d7e6b8707
[gaim-migrate @ 14466]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11170
diff
changeset
|
13 | /* perl < 5.8.0 doesn't define PERL_MAGIC_ext */ |
|
9f2d7e6b8707
[gaim-migrate @ 14466]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11170
diff
changeset
|
14 | #ifndef PERL_MAGIC_ext |
|
9f2d7e6b8707
[gaim-migrate @ 14466]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11170
diff
changeset
|
15 | #define PERL_MAGIC_ext '~' |
|
9f2d7e6b8707
[gaim-migrate @ 14466]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11170
diff
changeset
|
16 | #endif |
|
9f2d7e6b8707
[gaim-migrate @ 14466]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11170
diff
changeset
|
17 | |
| 12803 | 18 | void |
| 15884 | 19 | purple_perl_plugin_action_cb(PurplePluginAction *action) |
| 12803 | 20 | { |
| 12988 | 21 | SV **callback; |
| 22 | HV *hv = NULL; | |
| 23 | gchar *hvname; | |
| 15884 | 24 | PurplePlugin *plugin; |
| 25 | PurplePerlScript *gps; | |
| 12803 | 26 | dSP; |
| 12988 | 27 | |
| 28 | plugin = action->plugin; | |
| 15884 | 29 | gps = (PurplePerlScript *)plugin->info->extra_info; |
| 12988 | 30 | hvname = g_strdup_printf("%s::plugin_actions", gps->package); |
| 31 | hv = get_hv(hvname, FALSE); | |
| 32 | g_free(hvname); | |
| 33 | ||
| 34 | if (hv == NULL) | |
| 15884 | 35 | croak("No plugin_actions hash found in \"%s\" plugin.", purple_plugin_get_name(plugin)); |
| 12988 | 36 | |
| 12803 | 37 | ENTER; |
| 38 | SAVETMPS; | |
| 12988 | 39 | |
| 40 | callback = hv_fetch(hv, action->label, strlen(action->label), 0); | |
| 11170 | 41 | |
| 12988 | 42 | if (callback == NULL || *callback == NULL) |
| 15884 | 43 | croak("No plugin_action function named \"%s\" in \"%s\" plugin.", action->label, purple_plugin_get_name(plugin)); |
| 11170 | 44 | |
| 12988 | 45 | PUSHMARK(sp); |
| 15884 | 46 | XPUSHs(purple_perl_bless_object(gps->plugin, "Purple::Plugin")); |
| 12803 | 47 | PUTBACK; |
| 11170 | 48 | |
|
19336
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
49 | call_sv(*callback, G_EVAL | G_VOID | G_DISCARD); |
|
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
50 | |
| 12803 | 51 | SPAGAIN; |
| 11170 | 52 | |
|
19336
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
53 | if (SvTRUE(ERRSV)) { |
|
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
54 | purple_debug_error("perl", |
|
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
55 | "Perl plugin action function exited abnormally: %s\n", |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23931
diff
changeset
|
56 | SvPVutf8_nolen(ERRSV)); |
|
19336
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
57 | } |
|
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
58 | |
| 12803 | 59 | PUTBACK; |
| 60 | FREETMPS; | |
| 61 | LEAVE; | |
| 11170 | 62 | } |
| 63 | ||
| 12803 | 64 | GList * |
| 15884 | 65 | purple_perl_plugin_actions(PurplePlugin *plugin, gpointer context) |
| 12803 | 66 | { |
| 12988 | 67 | GList *l = NULL; |
| 15884 | 68 | PurplePerlScript *gps; |
| 12988 | 69 | int i = 0, count = 0; |
| 70 | dSP; | |
| 71 | ||
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
72 | gps = plugin->info->extra_info; |
| 12988 | 73 | |
| 74 | ENTER; | |
| 75 | SAVETMPS; | |
| 76 | ||
| 77 | PUSHMARK(SP); | |
| 15884 | 78 | XPUSHs(sv_2mortal(purple_perl_bless_object(plugin, "Purple::Plugin"))); |
| 12988 | 79 | /* XXX This *will* cease working correctly if context gets changed to |
| 15884 | 80 | * ever be able to hold anything other than a PurpleConnection */ |
| 12988 | 81 | if (context != NULL) |
| 15884 | 82 | XPUSHs(sv_2mortal(purple_perl_bless_object(context, |
| 83 | "Purple::Connection"))); | |
| 12988 | 84 | else |
| 85 | XPUSHs(&PL_sv_undef); | |
| 86 | PUTBACK; | |
| 87 | ||
|
19336
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
88 | count = call_pv(gps->plugin_action_sub, G_EVAL | G_ARRAY); |
| 11170 | 89 | |
| 12988 | 90 | SPAGAIN; |
| 91 | ||
|
19336
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
92 | if (SvTRUE(ERRSV)) { |
|
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
93 | purple_debug_error("perl", |
|
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
94 | "Perl plugin actions lookup exited abnormally: %s\n", |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23931
diff
changeset
|
95 | SvPVutf8_nolen(ERRSV)); |
|
19336
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
96 | } |
|
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
97 | |
| 12988 | 98 | if (count == 0) |
| 99 | croak("The plugin_actions sub didn't return anything.\n"); | |
| 100 | ||
| 101 | for (i = 0; i < count; i++) { | |
| 102 | SV *sv; | |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23931
diff
changeset
|
103 | PurplePluginAction *act; |
| 11170 | 104 | |
| 12988 | 105 | sv = POPs; |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23931
diff
changeset
|
106 | act = purple_plugin_action_new(SvPVutf8_nolen(sv), purple_perl_plugin_action_cb); |
| 13354 | 107 | l = g_list_prepend(l, act); |
| 12988 | 108 | } |
| 109 | ||
| 110 | PUTBACK; | |
| 111 | FREETMPS; | |
| 112 | LEAVE; | |
| 113 | ||
| 114 | return l; | |
| 11170 | 115 | } |
| 116 | ||
| 15884 | 117 | #ifdef PURPLE_GTKPERL |
| 12803 | 118 | GtkWidget * |
| 15884 | 119 | purple_perl_gtk_get_plugin_frame(PurplePlugin *plugin) |
| 12803 | 120 | { |
| 11170 | 121 | SV * sv; |
| 12874 | 122 | int count; |
| 11170 | 123 | MAGIC *mg; |
| 12874 | 124 | GtkWidget *ret; |
| 15884 | 125 | PurplePerlScript *gps; |
| 11170 | 126 | dSP; |
| 12874 | 127 | |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
128 | gps = plugin->info->extra_info; |
| 11170 | 129 | |
| 130 | ENTER; | |
| 131 | SAVETMPS; | |
| 132 | ||
|
19336
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
133 | count = call_pv(gps->gtk_prefs_sub, G_EVAL | G_SCALAR | G_NOARGS); |
| 11170 | 134 | if (count != 1) |
| 135 | croak("call_pv: Did not return the correct number of values.\n"); | |
| 12803 | 136 | |
| 11170 | 137 | /* the frame was created in a perl sub and is returned */ |
| 138 | SPAGAIN; | |
| 139 | ||
|
19336
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
140 | if (SvTRUE(ERRSV)) { |
|
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
141 | purple_debug_error("perl", |
|
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
142 | "Perl gtk plugin frame init exited abnormally: %s\n", |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23931
diff
changeset
|
143 | SvPVutf8_nolen(ERRSV)); |
|
19336
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
144 | } |
|
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
145 | |
| 11170 | 146 | /* We have a Gtk2::Frame on top of the stack */ |
| 12803 | 147 | sv = POPs; |
| 11170 | 148 | |
| 12874 | 149 | /* The magic field hides the pointer to the actual GtkWidget */ |
| 11170 | 150 | mg = mg_find(SvRV(sv), PERL_MAGIC_ext); |
| 151 | ret = (GtkWidget *)mg->mg_ptr; | |
| 152 | ||
| 153 | PUTBACK; | |
| 154 | FREETMPS; | |
| 12803 | 155 | LEAVE; |
| 156 | ||
| 11170 | 157 | return ret; |
| 158 | } | |
|
14426
8d4f164c4979
[gaim-migrate @ 17070]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
159 | #endif |
| 11170 | 160 | |
| 15884 | 161 | PurplePluginPrefFrame * |
| 162 | purple_perl_get_plugin_frame(PurplePlugin *plugin) | |
| 12803 | 163 | { |
| 164 | /* Sets up the Perl Stack for our call back into the script to run the | |
| 165 | * plugin_pref... sub */ | |
| 12872 | 166 | int count; |
| 15884 | 167 | PurplePerlScript *gps; |
| 168 | PurplePluginPrefFrame *ret_frame; | |
| 11123 | 169 | dSP; |
| 170 | ||
| 15884 | 171 | gps = (PurplePerlScript *)plugin->info->extra_info; |
| 12872 | 172 | |
| 11123 | 173 | ENTER; |
| 174 | SAVETMPS; | |
| 12803 | 175 | /* Some perl magic to run perl_plugin_pref_frame_SV perl sub and |
| 176 | * return the frame */ | |
| 11123 | 177 | PUSHMARK(SP); |
| 178 | PUTBACK; | |
| 179 | ||
|
19336
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
180 | count = call_pv(gps->prefs_sub, G_EVAL | G_SCALAR | G_NOARGS); |
| 11123 | 181 | |
| 182 | SPAGAIN; | |
| 183 | ||
|
19336
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
184 | if (SvTRUE(ERRSV)) { |
|
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
185 | purple_debug_error("perl", |
|
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
186 | "Perl plugin prefs frame init exited abnormally: %s\n", |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23931
diff
changeset
|
187 | SvPVutf8_nolen(ERRSV)); |
|
19336
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
188 | } |
|
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
189 | |
| 11123 | 190 | if (count != 1) |
| 191 | croak("call_pv: Did not return the correct number of values.\n"); | |
| 192 | /* the frame was created in a perl sub and is returned */ | |
| 15884 | 193 | ret_frame = (PurplePluginPrefFrame *)purple_perl_ref_object(POPs); |
| 11123 | 194 | |
| 195 | /* Tidy up the Perl stack */ | |
| 196 | PUTBACK; | |
| 197 | FREETMPS; | |
| 198 | LEAVE; | |
| 12871 | 199 | |
| 11123 | 200 | return ret_frame; |
| 201 | } | |
| 6520 | 202 | |
|
22845
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
203 | static gboolean |
| 15884 | 204 | destroy_timeout_handler(PurplePerlTimeoutHandler *handler) |
| 6520 | 205 | { |
|
22845
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
206 | gboolean ret = FALSE; |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
207 | |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
208 | timeout_handlers = g_slist_remove(timeout_handlers, handler); |
| 6520 | 209 | |
|
16140
362e0ca15d3a
Fix Bug #125 (Perl plugins using timeouts not having timeouts unregistered when plugin unloaded)
Daniel Atallah <datallah@pidgin.im>
parents:
15884
diff
changeset
|
210 | if (handler->iotag > 0) |
|
22845
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
211 | ret = purple_timeout_remove(handler->iotag); |
|
16140
362e0ca15d3a
Fix Bug #125 (Perl plugins using timeouts not having timeouts unregistered when plugin unloaded)
Daniel Atallah <datallah@pidgin.im>
parents:
15884
diff
changeset
|
212 | |
|
6568
5c8c70b63dc3
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
213 | if (handler->callback != NULL) |
|
5c8c70b63dc3
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
214 | SvREFCNT_dec(handler->callback); |
|
5c8c70b63dc3
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
215 | |
|
5c8c70b63dc3
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
216 | if (handler->data != NULL) |
|
5c8c70b63dc3
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
217 | SvREFCNT_dec(handler->data); |
|
5c8c70b63dc3
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
218 | |
| 6520 | 219 | g_free(handler); |
|
22845
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
220 | |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
221 | return ret; |
| 6520 | 222 | } |
| 223 | ||
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
224 | static void |
| 15884 | 225 | destroy_signal_handler(PurplePerlSignalHandler *handler) |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
226 | { |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
227 | signal_handlers = g_slist_remove(signal_handlers, handler); |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
228 | |
|
6567
761a1feb5561
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
229 | if (handler->callback != NULL) |
|
761a1feb5561
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
230 | SvREFCNT_dec(handler->callback); |
|
761a1feb5561
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
231 | |
|
761a1feb5561
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
232 | if (handler->data != NULL) |
|
761a1feb5561
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
233 | SvREFCNT_dec(handler->data); |
|
761a1feb5561
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
234 | |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
235 | g_free(handler->signal); |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
236 | g_free(handler); |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
237 | } |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
238 | |
|
16140
362e0ca15d3a
Fix Bug #125 (Perl plugins using timeouts not having timeouts unregistered when plugin unloaded)
Daniel Atallah <datallah@pidgin.im>
parents:
15884
diff
changeset
|
239 | static gboolean |
| 6520 | 240 | perl_timeout_cb(gpointer data) |
| 241 | { | |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
242 | PurplePerlTimeoutHandler *handler = data; |
|
18165
fb6f9d0130aa
Make timeout-callbacks behave like they would in C plugins (ie. the callback
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17570
diff
changeset
|
243 | gboolean ret = FALSE; |
| 6520 | 244 | |
| 245 | dSP; | |
| 246 | ENTER; | |
| 247 | SAVETMPS; | |
| 248 | PUSHMARK(sp); | |
|
6568
5c8c70b63dc3
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
249 | XPUSHs((SV *)handler->data); |
| 6520 | 250 | PUTBACK; |
|
6568
5c8c70b63dc3
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
251 | call_sv(handler->callback, G_EVAL | G_SCALAR); |
| 6520 | 252 | SPAGAIN; |
| 253 | ||
|
19336
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
254 | if (SvTRUE(ERRSV)) { |
|
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
255 | purple_debug_error("perl", |
|
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
256 | "Perl timeout function exited abnormally: %s\n", |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23931
diff
changeset
|
257 | SvPVutf8_nolen(ERRSV)); |
|
19336
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
258 | } |
|
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
259 | |
|
18165
fb6f9d0130aa
Make timeout-callbacks behave like they would in C plugins (ie. the callback
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17570
diff
changeset
|
260 | ret = POPi; |
|
fb6f9d0130aa
Make timeout-callbacks behave like they would in C plugins (ie. the callback
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17570
diff
changeset
|
261 | |
| 6520 | 262 | PUTBACK; |
| 263 | FREETMPS; | |
| 264 | LEAVE; | |
| 265 | ||
|
18165
fb6f9d0130aa
Make timeout-callbacks behave like they would in C plugins (ie. the callback
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17570
diff
changeset
|
266 | if (ret == FALSE) |
|
fb6f9d0130aa
Make timeout-callbacks behave like they would in C plugins (ie. the callback
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17570
diff
changeset
|
267 | destroy_timeout_handler(handler); |
|
16140
362e0ca15d3a
Fix Bug #125 (Perl plugins using timeouts not having timeouts unregistered when plugin unloaded)
Daniel Atallah <datallah@pidgin.im>
parents:
15884
diff
changeset
|
268 | |
|
18165
fb6f9d0130aa
Make timeout-callbacks behave like they would in C plugins (ie. the callback
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17570
diff
changeset
|
269 | return ret; |
| 6520 | 270 | } |
| 271 | ||
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
272 | typedef void *DATATYPE; |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
273 | |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
274 | static void * |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
275 | perl_signal_cb(va_list args, void *data) |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
276 | { |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
277 | PurplePerlSignalHandler *handler = data; |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
278 | void *ret_val = NULL; |
|
6566
61eb35202526
[gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents:
6554
diff
changeset
|
279 | int i; |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
280 | int count; |
|
6566
61eb35202526
[gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents:
6554
diff
changeset
|
281 | int value_count; |
| 15884 | 282 | PurpleValue *ret_value, **values; |
|
6919
2fd7ce2393f7
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
283 | SV **sv_args; |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
284 | DATATYPE **copy_args; |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
285 | |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
286 | dSP; |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
287 | ENTER; |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
288 | SAVETMPS; |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
289 | PUSHMARK(sp); |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
290 | |
| 15884 | 291 | purple_signal_get_values(handler->instance, handler->signal, |
|
25381
9a510397bf31
Apparently our use of va_list arguments in the perl signal callbacks doesn't
Etan Reisner <deryni@pidgin.im>
parents:
23980
diff
changeset
|
292 | &ret_value, &value_count, &values); |
|
6566
61eb35202526
[gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents:
6554
diff
changeset
|
293 | |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
294 | sv_args = g_new(SV *, value_count); |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
295 | copy_args = g_new(void **, value_count); |
|
6919
2fd7ce2393f7
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
296 | |
| 12803 | 297 | for (i = 0; i < value_count; i++) { |
| 15884 | 298 | sv_args[i] = purple_perl_sv_from_vargs(values[i], |
|
25381
9a510397bf31
Apparently our use of va_list arguments in the perl signal callbacks doesn't
Etan Reisner <deryni@pidgin.im>
parents:
23980
diff
changeset
|
299 | #ifdef VA_COPY_AS_ARRAY |
|
9a510397bf31
Apparently our use of va_list arguments in the perl signal callbacks doesn't
Etan Reisner <deryni@pidgin.im>
parents:
23980
diff
changeset
|
300 | args, |
|
9a510397bf31
Apparently our use of va_list arguments in the perl signal callbacks doesn't
Etan Reisner <deryni@pidgin.im>
parents:
23980
diff
changeset
|
301 | #else |
|
22845
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
302 | (va_list*)&args, |
|
25381
9a510397bf31
Apparently our use of va_list arguments in the perl signal callbacks doesn't
Etan Reisner <deryni@pidgin.im>
parents:
23980
diff
changeset
|
303 | #endif |
|
22845
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
304 | ©_args[i]); |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
305 | |
|
6920
4f4931b005cb
[gaim-migrate @ 7467]
Christian Hammond <chipx86@chipx86.com>
parents:
6919
diff
changeset
|
306 | XPUSHs(sv_args[i]); |
|
6566
61eb35202526
[gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents:
6554
diff
changeset
|
307 | } |
|
61eb35202526
[gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents:
6554
diff
changeset
|
308 | |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
309 | XPUSHs((SV *)handler->data); |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
310 | |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
311 | PUTBACK; |
|
6567
761a1feb5561
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
312 | |
| 12803 | 313 | if (ret_value != NULL) { |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
314 | count = call_sv(handler->callback, G_EVAL | G_SCALAR); |
|
6567
761a1feb5561
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
315 | |
|
761a1feb5561
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
316 | SPAGAIN; |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
317 | |
|
6567
761a1feb5561
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
318 | if (count != 1) |
|
761a1feb5561
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
319 | croak("Uh oh! call_sv returned %i != 1", i); |
|
761a1feb5561
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
320 | else |
| 15884 | 321 | ret_val = purple_perl_data_from_sv(ret_value, POPs); |
| 12803 | 322 | } else { |
|
19336
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
323 | call_sv(handler->callback, G_EVAL | G_SCALAR); |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
324 | |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
325 | SPAGAIN; |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
326 | } |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
327 | |
| 12803 | 328 | if (SvTRUE(ERRSV)) { |
| 15884 | 329 | purple_debug_error("perl", |
| 12803 | 330 | "Perl function exited abnormally: %s\n", |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23931
diff
changeset
|
331 | SvPVutf8_nolen(ERRSV)); |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
332 | } |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
333 | |
|
6919
2fd7ce2393f7
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
334 | /* See if any parameters changed. */ |
| 12803 | 335 | for (i = 0; i < value_count; i++) { |
| 15884 | 336 | if (purple_value_is_outgoing(values[i])) { |
| 337 | switch (purple_value_get_type(values[i])) { | |
| 338 | case PURPLE_TYPE_BOOLEAN: | |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
339 | *((gboolean *)copy_args[i]) = SvIV(sv_args[i]); |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
340 | break; |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
341 | |
| 15884 | 342 | case PURPLE_TYPE_INT: |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
343 | *((int *)copy_args[i]) = SvIV(sv_args[i]); |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
344 | break; |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
345 | |
| 15884 | 346 | case PURPLE_TYPE_UINT: |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
347 | *((unsigned int *)copy_args[i]) = SvUV(sv_args[i]); |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
348 | break; |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
349 | |
| 15884 | 350 | case PURPLE_TYPE_LONG: |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
351 | *((long *)copy_args[i]) = SvIV(sv_args[i]); |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
352 | break; |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
353 | |
| 15884 | 354 | case PURPLE_TYPE_ULONG: |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
355 | *((unsigned long *)copy_args[i]) = SvUV(sv_args[i]); |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
356 | break; |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
357 | |
| 15884 | 358 | case PURPLE_TYPE_INT64: |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
359 | *((gint64 *)copy_args[i]) = SvIV(sv_args[i]); |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
360 | break; |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
361 | |
| 15884 | 362 | case PURPLE_TYPE_UINT64: |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
363 | *((guint64 *)copy_args[i]) = SvUV(sv_args[i]); |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
364 | break; |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
365 | |
| 15884 | 366 | case PURPLE_TYPE_STRING: |
| 12803 | 367 | if (strcmp(*((char **)copy_args[i]), SvPVX(sv_args[i]))) { |
|
6925
ace22b159921
[gaim-migrate @ 7472]
Christian Hammond <chipx86@chipx86.com>
parents:
6924
diff
changeset
|
368 | g_free(*((char **)copy_args[i])); |
|
ace22b159921
[gaim-migrate @ 7472]
Christian Hammond <chipx86@chipx86.com>
parents:
6924
diff
changeset
|
369 | *((char **)copy_args[i]) = |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23931
diff
changeset
|
370 | g_strdup(SvPVutf8_nolen(sv_args[i])); |
|
6925
ace22b159921
[gaim-migrate @ 7472]
Christian Hammond <chipx86@chipx86.com>
parents:
6924
diff
changeset
|
371 | } |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23931
diff
changeset
|
372 | /* Clean up sv_args[i] - we're done with it */ |
|
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23931
diff
changeset
|
373 | sv_2mortal(sv_args[i]); |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
374 | break; |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
375 | |
| 15884 | 376 | case PURPLE_TYPE_POINTER: |
| 377 | case PURPLE_TYPE_BOXED: | |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
378 | *((void **)copy_args[i]) = (void *)SvIV(sv_args[i]); |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
379 | break; |
|
23182
e32645a28cad
applied changes from 2072edddff2333b97848681a9a464e9722b5f059
Daniel Atallah <datallah@pidgin.im>
parents:
22845
diff
changeset
|
380 | case PURPLE_TYPE_SUBTYPE: |
|
e32645a28cad
applied changes from 2072edddff2333b97848681a9a464e9722b5f059
Daniel Atallah <datallah@pidgin.im>
parents:
22845
diff
changeset
|
381 | *((void **)copy_args[i]) = purple_perl_ref_object(sv_args[i]); |
|
e32645a28cad
applied changes from 2072edddff2333b97848681a9a464e9722b5f059
Daniel Atallah <datallah@pidgin.im>
parents:
22845
diff
changeset
|
382 | break; |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
383 | |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
384 | default: |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
385 | break; |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
386 | } |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
387 | |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23931
diff
changeset
|
388 | |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
389 | #if 0 |
| 15884 | 390 | *((void **)copy_args[i]) = purple_perl_data_from_sv(values[i], |
|
6920
4f4931b005cb
[gaim-migrate @ 7467]
Christian Hammond <chipx86@chipx86.com>
parents:
6919
diff
changeset
|
391 | sv_args[i]); |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
392 | #endif |
|
6919
2fd7ce2393f7
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
393 | } |
|
2fd7ce2393f7
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
394 | } |
|
2fd7ce2393f7
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
395 | |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
396 | PUTBACK; |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
397 | FREETMPS; |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
398 | LEAVE; |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
399 | |
|
6919
2fd7ce2393f7
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
400 | g_free(sv_args); |
|
6920
4f4931b005cb
[gaim-migrate @ 7467]
Christian Hammond <chipx86@chipx86.com>
parents:
6919
diff
changeset
|
401 | g_free(copy_args); |
|
6919
2fd7ce2393f7
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
402 | |
| 15884 | 403 | purple_debug_misc("perl", "ret_val = %p\n", ret_val); |
|
6919
2fd7ce2393f7
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
404 | |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
405 | return ret_val; |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
406 | } |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
407 | |
| 15884 | 408 | static PurplePerlSignalHandler * |
| 409 | find_signal_handler(PurplePlugin *plugin, void *instance, const char *signal) | |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
410 | { |
| 15884 | 411 | PurplePerlSignalHandler *handler; |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
412 | GSList *l; |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
413 | |
| 12803 | 414 | for (l = signal_handlers; l != NULL; l = l->next) { |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
415 | handler = l->data; |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
416 | |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
417 | if (handler->plugin == plugin && |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
418 | handler->instance == instance && |
| 12803 | 419 | !strcmp(handler->signal, signal)) { |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
420 | return handler; |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
421 | } |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
422 | } |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
423 | |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
424 | return NULL; |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
425 | } |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
426 | |
|
22845
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
427 | guint |
| 15884 | 428 | purple_perl_timeout_add(PurplePlugin *plugin, int seconds, SV *callback, SV *data) |
| 6520 | 429 | { |
| 15884 | 430 | PurplePerlTimeoutHandler *handler; |
| 6520 | 431 | |
| 12803 | 432 | if (plugin == NULL) { |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
433 | croak("Invalid handle in adding perl timeout handler.\n"); |
|
22845
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
434 | return 0; |
| 6520 | 435 | } |
| 436 | ||
| 15884 | 437 | handler = g_new0(PurplePerlTimeoutHandler, 1); |
| 6520 | 438 | |
|
6568
5c8c70b63dc3
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
439 | handler->plugin = plugin; |
|
5c8c70b63dc3
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
440 | handler->callback = (callback != NULL && callback != &PL_sv_undef |
| 13017 | 441 | ? newSVsv(callback) : NULL); |
|
6568
5c8c70b63dc3
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
442 | handler->data = (data != NULL && data != &PL_sv_undef |
| 13017 | 443 | ? newSVsv(data) : NULL); |
| 6520 | 444 | |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
445 | timeout_handlers = g_slist_append(timeout_handlers, handler); |
|
6568
5c8c70b63dc3
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
446 | |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
447 | handler->iotag = purple_timeout_add_seconds(seconds, perl_timeout_cb, handler); |
|
22845
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
448 | |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
449 | return handler->iotag; |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
450 | } |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
451 | |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
452 | gboolean |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
453 | purple_perl_timeout_remove(guint handle) |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
454 | { |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
455 | PurplePerlTimeoutHandler *handler; |
|
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
456 | GSList *l, *l_next; |
|
22845
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
457 | |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
458 | for (l = timeout_handlers; l != NULL; l = l_next) { |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
459 | handler = l->data; |
|
22845
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
460 | l_next = l->next; |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
461 | |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
462 | if (handler->iotag == handle) |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
463 | return destroy_timeout_handler(handler); |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
464 | } |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
465 | |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
466 | purple_debug_info("perl", "No timeout handler found with handle %u.\n", |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
467 | handle); |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
468 | return FALSE; |
| 6520 | 469 | } |
| 470 | ||
| 471 | void | |
| 15884 | 472 | purple_perl_timeout_clear_for_plugin(PurplePlugin *plugin) |
| 6520 | 473 | { |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
474 | PurplePerlTimeoutHandler *handler; |
|
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
475 | GSList *l, *l_next; |
| 6520 | 476 | |
| 12803 | 477 | for (l = timeout_handlers; l != NULL; l = l_next) { |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
478 | handler = l->data; |
| 6520 | 479 | l_next = l->next; |
| 480 | ||
| 481 | if (handler->plugin == plugin) | |
| 482 | destroy_timeout_handler(handler); | |
| 483 | } | |
| 484 | } | |
| 485 | ||
| 486 | void | |
| 15884 | 487 | purple_perl_timeout_clear(void) |
| 6520 | 488 | { |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
489 | while (timeout_handlers != NULL) |
| 6520 | 490 | destroy_timeout_handler(timeout_handlers->data); |
| 491 | } | |
| 492 | ||
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
493 | void |
| 15884 | 494 | purple_perl_signal_connect(PurplePlugin *plugin, void *instance, |
| 13191 | 495 | const char *signal, SV *callback, SV *data, |
| 496 | int priority) | |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
497 | { |
| 15884 | 498 | PurplePerlSignalHandler *handler; |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
499 | |
| 15884 | 500 | handler = g_new0(PurplePerlSignalHandler, 1); |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
501 | handler->plugin = plugin; |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
502 | handler->instance = instance; |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
503 | handler->signal = g_strdup(signal); |
| 12803 | 504 | handler->callback = (callback != NULL && |
| 505 | callback != &PL_sv_undef ? newSVsv(callback) | |
| 506 | : NULL); | |
| 507 | handler->data = (data != NULL && | |
| 508 | data != &PL_sv_undef ? newSVsv(data) : NULL); | |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
509 | |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
510 | signal_handlers = g_slist_append(signal_handlers, handler); |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
511 | |
| 15884 | 512 | purple_signal_connect_priority_vargs(instance, signal, plugin, |
| 513 | PURPLE_CALLBACK(perl_signal_cb), | |
| 13191 | 514 | handler, priority); |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
515 | } |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
516 | |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
517 | void |
| 15884 | 518 | purple_perl_signal_disconnect(PurplePlugin *plugin, void *instance, |
| 12803 | 519 | const char *signal) |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
520 | { |
| 15884 | 521 | PurplePerlSignalHandler *handler; |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
522 | |
|
6567
761a1feb5561
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
523 | handler = find_signal_handler(plugin, instance, signal); |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
524 | |
| 12803 | 525 | if (handler == NULL) { |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
526 | croak("Invalid signal handler information in " |
| 12803 | 527 | "disconnecting a perl signal handler.\n"); |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
528 | return; |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
529 | } |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
530 | |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
531 | destroy_signal_handler(handler); |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
532 | } |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
533 | |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
534 | void |
| 15884 | 535 | purple_perl_signal_clear_for_plugin(PurplePlugin *plugin) |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
536 | { |
| 15884 | 537 | PurplePerlSignalHandler *handler; |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
538 | GSList *l, *l_next; |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
539 | |
| 12803 | 540 | for (l = signal_handlers; l != NULL; l = l_next) { |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
541 | l_next = l->next; |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
542 | handler = l->data; |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
543 | |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
544 | if (handler->plugin == plugin) |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
545 | destroy_signal_handler(handler); |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
546 | } |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
547 | } |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
548 | |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
549 | void |
| 15884 | 550 | purple_perl_signal_clear(void) |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
551 | { |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
552 | while (signal_handlers != NULL) |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
553 | destroy_signal_handler(signal_handlers->data); |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
554 | } |
| 12882 | 555 | |
| 15884 | 556 | static PurpleCmdRet |
| 557 | perl_cmd_cb(PurpleConversation *conv, const gchar *command, | |
| 12882 | 558 | gchar **args, gchar **error, void *data) |
| 559 | { | |
| 15884 | 560 | int i = 0, count, ret_value = PURPLE_CMD_RET_OK; |
| 12882 | 561 | SV *cmdSV, *tmpSV, *convSV; |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
562 | PurplePerlCmdHandler *handler = data; |
| 12882 | 563 | |
| 564 | dSP; | |
| 565 | ENTER; | |
| 566 | SAVETMPS; | |
| 567 | PUSHMARK(SP); | |
| 568 | ||
| 569 | /* Push the conversation onto the perl stack */ | |
| 15884 | 570 | convSV = sv_2mortal(purple_perl_bless_object(conv, "Purple::Conversation")); |
| 12882 | 571 | XPUSHs(convSV); |
| 572 | ||
| 573 | /* Push the command string onto the perl stack */ | |
| 574 | cmdSV = newSVpv(command, 0); | |
| 575 | cmdSV = sv_2mortal(cmdSV); | |
| 576 | XPUSHs(cmdSV); | |
| 577 | ||
| 578 | /* Push the data onto the perl stack */ | |
| 579 | XPUSHs((SV *)handler->data); | |
| 580 | ||
| 581 | /* Push any arguments we may have */ | |
| 582 | for (i = 0; args[i] != NULL; i++) { | |
| 583 | /* XXX The mortality of these created SV's should prevent | |
| 584 | * memory issues, if I read/understood everything correctly... | |
| 585 | */ | |
| 586 | tmpSV = newSVpv(args[i], 0); | |
| 587 | tmpSV = sv_2mortal(tmpSV); | |
| 588 | XPUSHs(tmpSV); | |
| 589 | } | |
| 590 | ||
| 591 | PUTBACK; | |
|
19336
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
592 | count = call_sv(handler->callback, G_EVAL | G_SCALAR); |
| 12882 | 593 | |
| 594 | if (count != 1) | |
| 595 | croak("call_sv: Did not return the correct number of values.\n"); | |
| 596 | ||
|
19336
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
597 | if (SvTRUE(ERRSV)) { |
|
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
598 | purple_debug_error("perl", |
|
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
599 | "Perl plugin command function exited abnormally: %s\n", |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23931
diff
changeset
|
600 | SvPVutf8_nolen(ERRSV)); |
|
19336
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
601 | } |
|
065a79d2d0e5
Make perl loader more robust - use G_EVAL flag on all calls so that if the perl function dies, it doesn't cause libpurple to quit.
Daniel Atallah <datallah@pidgin.im>
parents:
18165
diff
changeset
|
602 | |
| 12882 | 603 | SPAGAIN; |
| 604 | ||
| 605 | ret_value = POPi; | |
| 606 | ||
| 607 | PUTBACK; | |
| 608 | FREETMPS; | |
| 609 | LEAVE; | |
| 610 | ||
| 611 | return ret_value; | |
| 612 | } | |
| 613 | ||
| 15884 | 614 | PurpleCmdId |
| 615 | purple_perl_cmd_register(PurplePlugin *plugin, const gchar *command, | |
| 616 | const gchar *args, PurpleCmdPriority priority, | |
| 617 | PurpleCmdFlag flag, const gchar *prpl_id, SV *callback, | |
| 12882 | 618 | const gchar *helpstr, SV *data) |
| 619 | { | |
| 15884 | 620 | PurplePerlCmdHandler *handler; |
| 12882 | 621 | |
| 15884 | 622 | handler = g_new0(PurplePerlCmdHandler, 1); |
| 12882 | 623 | handler->plugin = plugin; |
| 624 | handler->cmd = g_strdup(command); | |
| 625 | handler->prpl_id = g_strdup(prpl_id); | |
| 626 | ||
| 627 | if (callback != NULL && callback != &PL_sv_undef) | |
| 628 | handler->callback = newSVsv(callback); | |
| 629 | else | |
| 630 | handler->callback = NULL; | |
| 631 | ||
| 632 | if (data != NULL && data != &PL_sv_undef) | |
| 633 | handler->data = newSVsv(data); | |
| 634 | else | |
| 635 | handler->data = NULL; | |
| 636 | ||
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
637 | cmd_handlers = g_slist_append(cmd_handlers, handler); |
| 12882 | 638 | |
| 15884 | 639 | handler->id = purple_cmd_register(command, args, priority, flag, prpl_id, |
| 640 | PURPLE_CMD_FUNC(perl_cmd_cb), helpstr, | |
| 12882 | 641 | handler); |
| 642 | ||
| 643 | return handler->id; | |
| 644 | } | |
| 645 | ||
| 646 | static void | |
| 15884 | 647 | destroy_cmd_handler(PurplePerlCmdHandler *handler) |
| 12882 | 648 | { |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
649 | cmd_handlers = g_slist_remove(cmd_handlers, handler); |
| 12882 | 650 | |
| 651 | if (handler->callback != NULL) | |
| 652 | SvREFCNT_dec(handler->callback); | |
| 653 | ||
| 654 | if (handler->data != NULL) | |
| 655 | SvREFCNT_dec(handler->data); | |
| 656 | ||
| 657 | g_free(handler->cmd); | |
| 658 | g_free(handler->prpl_id); | |
| 659 | g_free(handler); | |
| 660 | } | |
| 661 | ||
| 662 | void | |
| 15884 | 663 | purple_perl_cmd_clear_for_plugin(PurplePlugin *plugin) |
| 12882 | 664 | { |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
665 | PurplePerlCmdHandler *handler; |
|
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
666 | GSList *l, *l_next; |
| 12882 | 667 | |
| 668 | for (l = cmd_handlers; l != NULL; l = l_next) { | |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
669 | handler = l->data; |
| 12882 | 670 | l_next = l->next; |
| 671 | ||
| 672 | if (handler->plugin == plugin) | |
| 673 | destroy_cmd_handler(handler); | |
| 674 | } | |
| 675 | } | |
| 676 | ||
| 15884 | 677 | static PurplePerlCmdHandler * |
| 678 | find_cmd_handler(PurpleCmdId id) | |
| 12882 | 679 | { |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
680 | PurplePerlCmdHandler *handler; |
|
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
681 | GSList *l; |
| 12882 | 682 | |
| 683 | for (l = cmd_handlers; l != NULL; l = l->next) { | |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
684 | handler = (PurplePerlCmdHandler *)l->data; |
| 12882 | 685 | |
| 686 | if (handler->id == id) | |
| 687 | return handler; | |
| 688 | } | |
| 689 | ||
| 690 | return NULL; | |
| 691 | } | |
| 692 | ||
| 693 | void | |
| 15884 | 694 | purple_perl_cmd_unregister(PurpleCmdId id) |
| 12882 | 695 | { |
| 15884 | 696 | PurplePerlCmdHandler *handler; |
| 12882 | 697 | |
| 698 | handler = find_cmd_handler(id); | |
| 699 | ||
| 700 | if (handler == NULL) { | |
| 701 | croak("Invalid command id in removing a perl command handler.\n"); | |
| 702 | return; | |
| 703 | } | |
| 704 | ||
| 15884 | 705 | purple_cmd_unregister(id); |
| 12882 | 706 | destroy_cmd_handler(handler); |
| 707 | } | |
|
23930
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
708 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
709 | static void |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
710 | perl_pref_cb(const char *name, PurplePrefType type, gconstpointer value, |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
711 | gpointer data) |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
712 | { |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
713 | PurplePerlPrefsHandler *handler = data; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
714 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
715 | dSP; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
716 | ENTER; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
717 | SAVETMPS; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
718 | PUSHMARK(sp); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
719 | XPUSHs(sv_2mortal(newSVpv(name, 0))); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
720 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
721 | XPUSHs(sv_2mortal(newSViv(type))); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
722 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
723 | switch(type) { |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
724 | case PURPLE_PREF_INT: |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
725 | XPUSHs(sv_2mortal(newSViv(GPOINTER_TO_INT(value)))); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
726 | break; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
727 | case PURPLE_PREF_BOOLEAN: |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
728 | XPUSHs((GPOINTER_TO_INT(value) == FALSE) ? &PL_sv_no : &PL_sv_yes); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
729 | break; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
730 | case PURPLE_PREF_STRING: |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
731 | case PURPLE_PREF_PATH: |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
732 | XPUSHs(sv_2mortal(newSVGChar(value))); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
733 | break; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
734 | case PURPLE_PREF_STRING_LIST: |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
735 | case PURPLE_PREF_PATH_LIST: |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
736 | { |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
737 | AV* av = newAV(); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
738 | const GList *l = value; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
739 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
740 | /* Append stuff backward to preserve order */ |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
741 | while (l && l->next) l = l->next; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
742 | while (l) { |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
743 | av_push(av, sv_2mortal(newSVGChar(l->data))); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
744 | l = l->prev; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
745 | } |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
746 | XPUSHs(sv_2mortal(newRV_noinc((SV *) av))); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
747 | } break; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
748 | default: |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
749 | case PURPLE_PREF_NONE: |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
750 | XPUSHs(&PL_sv_undef); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
751 | break; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
752 | } |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
753 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
754 | XPUSHs((SV *)handler->data); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
755 | PUTBACK; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
756 | call_sv(handler->callback, G_EVAL | G_VOID | G_DISCARD); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
757 | SPAGAIN; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
758 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
759 | if (SvTRUE(ERRSV)) { |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
760 | purple_debug_error("perl", |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
761 | "Perl prefs callback function exited abnormally: %s\n", |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23931
diff
changeset
|
762 | SvPVutf8_nolen(ERRSV)); |
|
23930
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
763 | } |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
764 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
765 | PUTBACK; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
766 | FREETMPS; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
767 | LEAVE; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
768 | } |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
769 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
770 | guint |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
771 | purple_perl_prefs_connect_callback(PurplePlugin *plugin, const char *name, |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
772 | SV *callback, SV *data) |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
773 | { |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
774 | PurplePerlPrefsHandler *handler; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
775 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
776 | if (plugin == NULL) { |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
777 | croak("Invalid handle in adding perl prefs handler.\n"); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
778 | return 0; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
779 | } |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
780 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
781 | handler = g_new0(PurplePerlPrefsHandler, 1); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
782 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
783 | handler->plugin = plugin; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
784 | handler->callback = (callback != NULL && callback != &PL_sv_undef |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
785 | ? newSVsv(callback) : NULL); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
786 | handler->data = (data != NULL && data != &PL_sv_undef |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
787 | ? newSVsv(data) : NULL); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
788 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
789 | pref_handlers = g_slist_prepend(pref_handlers, handler); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
790 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
791 | handler->iotag = purple_prefs_connect_callback(plugin, name, perl_pref_cb, handler); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
792 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
793 | return handler->iotag; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
794 | } |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
795 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
796 | static void |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
797 | destroy_prefs_handler(PurplePerlPrefsHandler *handler) |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
798 | { |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
799 | pref_handlers = g_slist_remove(pref_handlers, handler); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
800 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
801 | if (handler->iotag > 0) |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
802 | purple_prefs_disconnect_callback(handler->iotag); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
803 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
804 | if (handler->callback != NULL) |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
805 | SvREFCNT_dec(handler->callback); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
806 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
807 | if (handler->data != NULL) |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
808 | SvREFCNT_dec(handler->data); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
809 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
810 | g_free(handler); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
811 | } |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
812 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
813 | void purple_perl_prefs_disconnect_callback(guint callback_id) |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
814 | { |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
815 | GSList *l, *l_next; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
816 | PurplePerlPrefsHandler *handler; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
817 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
818 | for (l = pref_handlers; l != NULL; l = l_next) { |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
819 | l_next = l->next; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
820 | handler = l->data; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
821 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
822 | if (handler->iotag == callback_id) { |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
823 | destroy_prefs_handler(handler); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
824 | return; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
825 | } |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
826 | } |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
827 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
828 | purple_debug_info("perl", "No prefs handler found with handle %u.\n", |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
829 | callback_id); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
830 | } |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
831 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
832 | void purple_perl_pref_cb_clear_for_plugin(PurplePlugin *plugin) |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
833 | { |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
834 | GSList *l, *l_next; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
835 | PurplePerlPrefsHandler *handler; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
836 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
837 | for (l = pref_handlers; l != NULL; l = l_next) { |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
838 | l_next = l->next; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
839 | handler = l->data; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
840 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
841 | if (handler->plugin == plugin) |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
842 | destroy_prefs_handler(handler); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
843 | } |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
844 | } |