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