Sat, 24 Oct 2009 17:46:30 +0000
Unregister commands registered by a perl-plugin when unloading it.
A perl plugin may not unregister a command, and that can cause a crash.
So the perl plugin loader will take care of unregistering the commands in
case the plugin itself leaves them behind.
| 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; |
|
27120
d7503d775939
Fix a couple of crashes in the perl plugin loader.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
25381
diff
changeset
|
287 | PERL_SET_CONTEXT(my_perl); |
|
d7503d775939
Fix a couple of crashes in the perl plugin loader.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
25381
diff
changeset
|
288 | SPAGAIN; |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
289 | ENTER; |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
290 | SAVETMPS; |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
291 | PUSHMARK(sp); |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
292 | |
| 15884 | 293 | 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
|
294 | &ret_value, &value_count, &values); |
|
6566
61eb35202526
[gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents:
6554
diff
changeset
|
295 | |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
296 | sv_args = g_new(SV *, value_count); |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
297 | copy_args = g_new(void **, value_count); |
|
6919
2fd7ce2393f7
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
298 | |
| 12803 | 299 | for (i = 0; i < value_count; i++) { |
| 15884 | 300 | 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
|
301 | #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
|
302 | 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
|
303 | #else |
|
22845
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
304 | (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
|
305 | #endif |
|
22845
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
306 | ©_args[i]); |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
307 | |
|
6920
4f4931b005cb
[gaim-migrate @ 7467]
Christian Hammond <chipx86@chipx86.com>
parents:
6919
diff
changeset
|
308 | XPUSHs(sv_args[i]); |
|
6566
61eb35202526
[gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents:
6554
diff
changeset
|
309 | } |
|
61eb35202526
[gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents:
6554
diff
changeset
|
310 | |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
311 | XPUSHs((SV *)handler->data); |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
312 | |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
313 | PUTBACK; |
|
6567
761a1feb5561
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
314 | |
| 12803 | 315 | if (ret_value != NULL) { |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
316 | count = call_sv(handler->callback, G_EVAL | G_SCALAR); |
|
6567
761a1feb5561
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
317 | |
|
761a1feb5561
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
318 | SPAGAIN; |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
319 | |
|
6567
761a1feb5561
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
320 | if (count != 1) |
|
761a1feb5561
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
321 | croak("Uh oh! call_sv returned %i != 1", i); |
|
761a1feb5561
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
322 | else |
| 15884 | 323 | ret_val = purple_perl_data_from_sv(ret_value, POPs); |
| 12803 | 324 | } 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
|
325 | call_sv(handler->callback, G_EVAL | G_SCALAR); |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
326 | |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
327 | SPAGAIN; |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
328 | } |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
329 | |
| 12803 | 330 | if (SvTRUE(ERRSV)) { |
| 15884 | 331 | purple_debug_error("perl", |
| 12803 | 332 | "Perl function exited abnormally: %s\n", |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23931
diff
changeset
|
333 | SvPVutf8_nolen(ERRSV)); |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
334 | } |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
335 | |
|
6919
2fd7ce2393f7
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
336 | /* See if any parameters changed. */ |
| 12803 | 337 | for (i = 0; i < value_count; i++) { |
| 15884 | 338 | if (purple_value_is_outgoing(values[i])) { |
| 339 | switch (purple_value_get_type(values[i])) { | |
| 340 | case PURPLE_TYPE_BOOLEAN: | |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
341 | *((gboolean *)copy_args[i]) = SvIV(sv_args[i]); |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
342 | break; |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
343 | |
| 15884 | 344 | case PURPLE_TYPE_INT: |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
345 | *((int *)copy_args[i]) = SvIV(sv_args[i]); |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
346 | break; |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
347 | |
| 15884 | 348 | case PURPLE_TYPE_UINT: |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
349 | *((unsigned int *)copy_args[i]) = SvUV(sv_args[i]); |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
350 | break; |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
351 | |
| 15884 | 352 | case PURPLE_TYPE_LONG: |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
353 | *((long *)copy_args[i]) = SvIV(sv_args[i]); |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
354 | break; |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
355 | |
| 15884 | 356 | case PURPLE_TYPE_ULONG: |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
357 | *((unsigned long *)copy_args[i]) = SvUV(sv_args[i]); |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
358 | break; |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
359 | |
| 15884 | 360 | case PURPLE_TYPE_INT64: |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
361 | *((gint64 *)copy_args[i]) = SvIV(sv_args[i]); |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
362 | break; |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
363 | |
| 15884 | 364 | case PURPLE_TYPE_UINT64: |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
365 | *((guint64 *)copy_args[i]) = SvUV(sv_args[i]); |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
366 | break; |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
367 | |
| 15884 | 368 | case PURPLE_TYPE_STRING: |
|
27120
d7503d775939
Fix a couple of crashes in the perl plugin loader.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
25381
diff
changeset
|
369 | if (!*((char **)copy_args[i]) || !SvPVX(sv_args[i]) || |
|
d7503d775939
Fix a couple of crashes in the perl plugin loader.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
25381
diff
changeset
|
370 | strcmp(*((char **)copy_args[i]), SvPVX(sv_args[i]))) { |
|
6925
ace22b159921
[gaim-migrate @ 7472]
Christian Hammond <chipx86@chipx86.com>
parents:
6924
diff
changeset
|
371 | g_free(*((char **)copy_args[i])); |
|
ace22b159921
[gaim-migrate @ 7472]
Christian Hammond <chipx86@chipx86.com>
parents:
6924
diff
changeset
|
372 | *((char **)copy_args[i]) = |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23931
diff
changeset
|
373 | g_strdup(SvPVutf8_nolen(sv_args[i])); |
|
6925
ace22b159921
[gaim-migrate @ 7472]
Christian Hammond <chipx86@chipx86.com>
parents:
6924
diff
changeset
|
374 | } |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23931
diff
changeset
|
375 | /* 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
|
376 | sv_2mortal(sv_args[i]); |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
377 | break; |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
378 | |
| 15884 | 379 | case PURPLE_TYPE_POINTER: |
| 380 | case PURPLE_TYPE_BOXED: | |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
381 | *((void **)copy_args[i]) = (void *)SvIV(sv_args[i]); |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
382 | break; |
|
23182
e32645a28cad
applied changes from 2072edddff2333b97848681a9a464e9722b5f059
Daniel Atallah <datallah@pidgin.im>
parents:
22845
diff
changeset
|
383 | case PURPLE_TYPE_SUBTYPE: |
|
e32645a28cad
applied changes from 2072edddff2333b97848681a9a464e9722b5f059
Daniel Atallah <datallah@pidgin.im>
parents:
22845
diff
changeset
|
384 | *((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
|
385 | break; |
|
6921
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 | default: |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
388 | break; |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
389 | } |
|
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
390 | |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23931
diff
changeset
|
391 | |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
392 | #if 0 |
| 15884 | 393 | *((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
|
394 | sv_args[i]); |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
395 | #endif |
|
6919
2fd7ce2393f7
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
396 | } |
|
2fd7ce2393f7
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
397 | } |
|
2fd7ce2393f7
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
398 | |
|
6921
3d49b89fc920
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
399 | PUTBACK; |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
400 | FREETMPS; |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
401 | LEAVE; |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
402 | |
|
6919
2fd7ce2393f7
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
403 | g_free(sv_args); |
|
6920
4f4931b005cb
[gaim-migrate @ 7467]
Christian Hammond <chipx86@chipx86.com>
parents:
6919
diff
changeset
|
404 | g_free(copy_args); |
|
6919
2fd7ce2393f7
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
405 | |
| 15884 | 406 | purple_debug_misc("perl", "ret_val = %p\n", ret_val); |
|
6919
2fd7ce2393f7
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
407 | |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
408 | return ret_val; |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
409 | } |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
410 | |
| 15884 | 411 | static PurplePerlSignalHandler * |
| 412 | find_signal_handler(PurplePlugin *plugin, void *instance, const char *signal) | |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
413 | { |
| 15884 | 414 | PurplePerlSignalHandler *handler; |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
415 | GSList *l; |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
416 | |
| 12803 | 417 | 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
|
418 | handler = l->data; |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
419 | |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
420 | if (handler->plugin == plugin && |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
421 | handler->instance == instance && |
| 12803 | 422 | !strcmp(handler->signal, signal)) { |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
423 | return handler; |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
424 | } |
|
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 | |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
427 | return NULL; |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
428 | } |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
429 | |
|
22845
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
430 | guint |
| 15884 | 431 | purple_perl_timeout_add(PurplePlugin *plugin, int seconds, SV *callback, SV *data) |
| 6520 | 432 | { |
| 15884 | 433 | PurplePerlTimeoutHandler *handler; |
| 6520 | 434 | |
| 12803 | 435 | if (plugin == NULL) { |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
436 | 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
|
437 | return 0; |
| 6520 | 438 | } |
| 439 | ||
| 15884 | 440 | handler = g_new0(PurplePerlTimeoutHandler, 1); |
| 6520 | 441 | |
|
6568
5c8c70b63dc3
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
442 | handler->plugin = plugin; |
|
5c8c70b63dc3
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
443 | handler->callback = (callback != NULL && callback != &PL_sv_undef |
| 13017 | 444 | ? newSVsv(callback) : NULL); |
|
6568
5c8c70b63dc3
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
445 | handler->data = (data != NULL && data != &PL_sv_undef |
| 13017 | 446 | ? newSVsv(data) : NULL); |
| 6520 | 447 | |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
448 | timeout_handlers = g_slist_append(timeout_handlers, handler); |
|
6568
5c8c70b63dc3
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
449 | |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
450 | 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
|
451 | |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
452 | return handler->iotag; |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
453 | } |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
454 | |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
455 | gboolean |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
456 | 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
|
457 | { |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
458 | PurplePerlTimeoutHandler *handler; |
|
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
459 | GSList *l, *l_next; |
|
22845
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
460 | |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
461 | 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
|
462 | handler = l->data; |
|
22845
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
463 | l_next = l->next; |
|
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 | if (handler->iotag == handle) |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
466 | return destroy_timeout_handler(handler); |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
467 | } |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
468 | |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
469 | 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
|
470 | handle); |
|
7ccb529edf3f
Add the recent perl callback changes to ChangeLog.API.
Etan Reisner <deryni@pidgin.im>
parents:
19336
diff
changeset
|
471 | return FALSE; |
| 6520 | 472 | } |
| 473 | ||
| 474 | void | |
| 15884 | 475 | purple_perl_timeout_clear_for_plugin(PurplePlugin *plugin) |
| 6520 | 476 | { |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
477 | PurplePerlTimeoutHandler *handler; |
|
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
478 | GSList *l, *l_next; |
| 6520 | 479 | |
| 12803 | 480 | 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
|
481 | handler = l->data; |
| 6520 | 482 | l_next = l->next; |
| 483 | ||
| 484 | if (handler->plugin == plugin) | |
| 485 | destroy_timeout_handler(handler); | |
| 486 | } | |
| 487 | } | |
| 488 | ||
| 489 | void | |
| 15884 | 490 | purple_perl_timeout_clear(void) |
| 6520 | 491 | { |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
492 | while (timeout_handlers != NULL) |
| 6520 | 493 | destroy_timeout_handler(timeout_handlers->data); |
| 494 | } | |
| 495 | ||
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
496 | void |
| 15884 | 497 | purple_perl_signal_connect(PurplePlugin *plugin, void *instance, |
| 13191 | 498 | const char *signal, SV *callback, SV *data, |
| 499 | int priority) | |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
500 | { |
| 15884 | 501 | PurplePerlSignalHandler *handler; |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
502 | |
| 15884 | 503 | handler = g_new0(PurplePerlSignalHandler, 1); |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
504 | handler->plugin = plugin; |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
505 | handler->instance = instance; |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
506 | handler->signal = g_strdup(signal); |
| 12803 | 507 | handler->callback = (callback != NULL && |
| 508 | callback != &PL_sv_undef ? newSVsv(callback) | |
| 509 | : NULL); | |
| 510 | handler->data = (data != NULL && | |
| 511 | data != &PL_sv_undef ? newSVsv(data) : NULL); | |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
512 | |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
513 | signal_handlers = g_slist_append(signal_handlers, handler); |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
514 | |
| 15884 | 515 | purple_signal_connect_priority_vargs(instance, signal, plugin, |
| 516 | PURPLE_CALLBACK(perl_signal_cb), | |
| 13191 | 517 | handler, priority); |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
518 | } |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
519 | |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
520 | void |
| 15884 | 521 | purple_perl_signal_disconnect(PurplePlugin *plugin, void *instance, |
| 12803 | 522 | const char *signal) |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
523 | { |
| 15884 | 524 | PurplePerlSignalHandler *handler; |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
525 | |
|
6567
761a1feb5561
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
526 | handler = find_signal_handler(plugin, instance, signal); |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
527 | |
| 12803 | 528 | if (handler == NULL) { |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
529 | croak("Invalid signal handler information in " |
| 12803 | 530 | "disconnecting a perl signal handler.\n"); |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
531 | return; |
|
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 | destroy_signal_handler(handler); |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
535 | } |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
536 | |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
537 | void |
| 15884 | 538 | purple_perl_signal_clear_for_plugin(PurplePlugin *plugin) |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
539 | { |
| 15884 | 540 | PurplePerlSignalHandler *handler; |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
541 | GSList *l, *l_next; |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
542 | |
| 12803 | 543 | for (l = signal_handlers; l != NULL; l = l_next) { |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
544 | l_next = l->next; |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
545 | handler = l->data; |
|
6549
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 | if (handler->plugin == plugin) |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
548 | destroy_signal_handler(handler); |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
549 | } |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
550 | } |
|
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 | void |
| 15884 | 553 | purple_perl_signal_clear(void) |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
554 | { |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
555 | while (signal_handlers != NULL) |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
556 | destroy_signal_handler(signal_handlers->data); |
|
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
557 | } |
| 12882 | 558 | |
| 15884 | 559 | static PurpleCmdRet |
| 560 | perl_cmd_cb(PurpleConversation *conv, const gchar *command, | |
| 12882 | 561 | gchar **args, gchar **error, void *data) |
| 562 | { | |
| 15884 | 563 | int i = 0, count, ret_value = PURPLE_CMD_RET_OK; |
| 12882 | 564 | SV *cmdSV, *tmpSV, *convSV; |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
565 | PurplePerlCmdHandler *handler = data; |
| 12882 | 566 | |
| 567 | dSP; | |
| 568 | ENTER; | |
| 569 | SAVETMPS; | |
| 570 | PUSHMARK(SP); | |
| 571 | ||
| 572 | /* Push the conversation onto the perl stack */ | |
| 15884 | 573 | convSV = sv_2mortal(purple_perl_bless_object(conv, "Purple::Conversation")); |
| 12882 | 574 | XPUSHs(convSV); |
| 575 | ||
| 576 | /* Push the command string onto the perl stack */ | |
| 577 | cmdSV = newSVpv(command, 0); | |
| 578 | cmdSV = sv_2mortal(cmdSV); | |
| 579 | XPUSHs(cmdSV); | |
| 580 | ||
| 581 | /* Push the data onto the perl stack */ | |
| 582 | XPUSHs((SV *)handler->data); | |
| 583 | ||
| 584 | /* Push any arguments we may have */ | |
| 585 | for (i = 0; args[i] != NULL; i++) { | |
| 586 | /* XXX The mortality of these created SV's should prevent | |
| 587 | * memory issues, if I read/understood everything correctly... | |
| 588 | */ | |
| 589 | tmpSV = newSVpv(args[i], 0); | |
| 590 | tmpSV = sv_2mortal(tmpSV); | |
| 591 | XPUSHs(tmpSV); | |
| 592 | } | |
| 593 | ||
| 594 | 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
|
595 | count = call_sv(handler->callback, G_EVAL | G_SCALAR); |
| 12882 | 596 | |
| 597 | if (count != 1) | |
| 598 | croak("call_sv: Did not return the correct number of values.\n"); | |
| 599 | ||
|
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
|
600 | 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
|
601 | 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
|
602 | "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
|
603 | 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
|
604 | } |
|
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
|
605 | |
| 12882 | 606 | SPAGAIN; |
| 607 | ||
| 608 | ret_value = POPi; | |
| 609 | ||
| 610 | PUTBACK; | |
| 611 | FREETMPS; | |
| 612 | LEAVE; | |
| 613 | ||
| 614 | return ret_value; | |
| 615 | } | |
| 616 | ||
| 15884 | 617 | PurpleCmdId |
| 618 | purple_perl_cmd_register(PurplePlugin *plugin, const gchar *command, | |
| 619 | const gchar *args, PurpleCmdPriority priority, | |
| 620 | PurpleCmdFlag flag, const gchar *prpl_id, SV *callback, | |
| 12882 | 621 | const gchar *helpstr, SV *data) |
| 622 | { | |
| 15884 | 623 | PurplePerlCmdHandler *handler; |
| 12882 | 624 | |
| 15884 | 625 | handler = g_new0(PurplePerlCmdHandler, 1); |
| 12882 | 626 | handler->plugin = plugin; |
| 627 | handler->cmd = g_strdup(command); | |
| 628 | handler->prpl_id = g_strdup(prpl_id); | |
| 629 | ||
| 630 | if (callback != NULL && callback != &PL_sv_undef) | |
| 631 | handler->callback = newSVsv(callback); | |
| 632 | else | |
| 633 | handler->callback = NULL; | |
| 634 | ||
| 635 | if (data != NULL && data != &PL_sv_undef) | |
| 636 | handler->data = newSVsv(data); | |
| 637 | else | |
| 638 | handler->data = NULL; | |
| 639 | ||
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
640 | cmd_handlers = g_slist_append(cmd_handlers, handler); |
| 12882 | 641 | |
| 15884 | 642 | handler->id = purple_cmd_register(command, args, priority, flag, prpl_id, |
| 643 | PURPLE_CMD_FUNC(perl_cmd_cb), helpstr, | |
| 12882 | 644 | handler); |
| 645 | ||
| 646 | return handler->id; | |
| 647 | } | |
| 648 | ||
| 649 | static void | |
| 15884 | 650 | destroy_cmd_handler(PurplePerlCmdHandler *handler) |
| 12882 | 651 | { |
|
28740
6861934437a3
Unregister commands registered by a perl-plugin when unloading it.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
27120
diff
changeset
|
652 | purple_cmd_unregister(handler->id); |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
653 | cmd_handlers = g_slist_remove(cmd_handlers, handler); |
| 12882 | 654 | |
| 655 | if (handler->callback != NULL) | |
| 656 | SvREFCNT_dec(handler->callback); | |
| 657 | ||
| 658 | if (handler->data != NULL) | |
| 659 | SvREFCNT_dec(handler->data); | |
| 660 | ||
| 661 | g_free(handler->cmd); | |
| 662 | g_free(handler->prpl_id); | |
| 663 | g_free(handler); | |
| 664 | } | |
| 665 | ||
| 666 | void | |
| 15884 | 667 | purple_perl_cmd_clear_for_plugin(PurplePlugin *plugin) |
| 12882 | 668 | { |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
669 | PurplePerlCmdHandler *handler; |
|
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
670 | GSList *l, *l_next; |
| 12882 | 671 | |
| 672 | 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
|
673 | handler = l->data; |
| 12882 | 674 | l_next = l->next; |
| 675 | ||
| 676 | if (handler->plugin == plugin) | |
| 677 | destroy_cmd_handler(handler); | |
| 678 | } | |
| 679 | } | |
| 680 | ||
| 15884 | 681 | static PurplePerlCmdHandler * |
| 682 | find_cmd_handler(PurpleCmdId id) | |
| 12882 | 683 | { |
|
23931
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
684 | PurplePerlCmdHandler *handler; |
|
8975bb78b51a
Cleanup unnecessary casts and etc.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
685 | GSList *l; |
| 12882 | 686 | |
| 687 | 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
|
688 | handler = (PurplePerlCmdHandler *)l->data; |
| 12882 | 689 | |
| 690 | if (handler->id == id) | |
| 691 | return handler; | |
| 692 | } | |
| 693 | ||
| 694 | return NULL; | |
| 695 | } | |
| 696 | ||
| 697 | void | |
| 15884 | 698 | purple_perl_cmd_unregister(PurpleCmdId id) |
| 12882 | 699 | { |
| 15884 | 700 | PurplePerlCmdHandler *handler; |
| 12882 | 701 | |
| 702 | handler = find_cmd_handler(id); | |
| 703 | ||
| 704 | if (handler == NULL) { | |
| 705 | croak("Invalid command id in removing a perl command handler.\n"); | |
| 706 | return; | |
| 707 | } | |
| 708 | ||
| 709 | destroy_cmd_handler(handler); | |
| 710 | } | |
|
23930
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
711 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
712 | static void |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
713 | 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
|
714 | gpointer data) |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
715 | { |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
716 | 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
|
717 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
718 | dSP; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
719 | ENTER; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
720 | SAVETMPS; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
721 | PUSHMARK(sp); |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
722 | 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
|
723 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
724 | 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
|
725 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
726 | switch(type) { |
|
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_INT: |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
728 | 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
|
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_BOOLEAN: |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
731 | 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
|
732 | break; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
733 | 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
|
734 | 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
|
735 | 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
|
736 | break; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
737 | 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
|
738 | 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
|
739 | { |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
740 | 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
|
741 | 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
|
742 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
743 | /* 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
|
744 | 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
|
745 | while (l) { |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
746 | 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
|
747 | 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
|
748 | } |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
749 | 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
|
750 | } break; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
751 | default: |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
752 | 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
|
753 | 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
|
754 | break; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
755 | } |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
756 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
757 | 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
|
758 | PUTBACK; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
759 | 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
|
760 | SPAGAIN; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
761 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
762 | 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
|
763 | 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
|
764 | "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
|
765 | 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
|
766 | } |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
767 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
768 | PUTBACK; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
769 | FREETMPS; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
770 | LEAVE; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
771 | } |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
772 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
773 | guint |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
774 | 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
|
775 | 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
|
776 | { |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
777 | PurplePerlPrefsHandler *handler; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
778 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
779 | 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
|
780 | 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
|
781 | return 0; |
|
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 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
784 | 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
|
785 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
786 | 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
|
787 | 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
|
788 | ? 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
|
789 | 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
|
790 | ? 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
|
791 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
792 | 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
|
793 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
794 | 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
|
795 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
796 | 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
|
797 | } |
|
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 | static void |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
800 | 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
|
801 | { |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
802 | 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
|
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->iotag > 0) |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
805 | 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
|
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->callback != 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->callback); |
|
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 | 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
|
811 | 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
|
812 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
813 | 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
|
814 | } |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
815 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
816 | 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
|
817 | { |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
818 | 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
|
819 | PurplePerlPrefsHandler *handler; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
820 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
821 | 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
|
822 | 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
|
823 | 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
|
824 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
825 | 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
|
826 | 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
|
827 | return; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
828 | } |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
829 | } |
|
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 | 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
|
832 | callback_id); |
|
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 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
835 | 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
|
836 | { |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
837 | 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
|
838 | PurplePerlPrefsHandler *handler; |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
839 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
840 | 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
|
841 | 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
|
842 | 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
|
843 | |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
844 | 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
|
845 | 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
|
846 | } |
|
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23182
diff
changeset
|
847 | } |