Mon, 30 Apr 2007 00:42:33 +0000
Updating the loaders since I missed them since I'm not building any of them right now
| 5205 | 1 | /* |
| 15884 | 2 | * purple |
| 5205 | 3 | * |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
4 | * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> |
| 5205 | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify | |
| 7 | * it under the terms of the GNU General Public License as published by | |
| 8 | * the Free Software Foundation; either version 2 of the License, or | |
| 9 | * (at your option) any later version. | |
| 10 | * | |
| 11 | * This program is distributed in the hope that it will be useful, | |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | * GNU General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the GNU General Public License | |
| 17 | * along with this program; if not, write to the Free Software | |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 19 | */ | |
|
6235
8293e7d4c050
[gaim-migrate @ 6728]
Mark Doliner <markdoliner@pidgin.im>
parents:
6100
diff
changeset
|
20 | #ifdef HAVE_CONFIG_H |
|
8293e7d4c050
[gaim-migrate @ 6728]
Mark Doliner <markdoliner@pidgin.im>
parents:
6100
diff
changeset
|
21 | #include <config.h> |
| 8138 | 22 | # ifdef HAVE_LIMITS_H |
| 23 | # include <limits.h> | |
| 24 | # ifndef NAME_MAX | |
| 25 | # define NAME_MAX _POSIX_NAME_MAX | |
| 26 | # endif | |
| 27 | # endif | |
|
6235
8293e7d4c050
[gaim-migrate @ 6728]
Mark Doliner <markdoliner@pidgin.im>
parents:
6100
diff
changeset
|
28 | #endif |
|
8293e7d4c050
[gaim-migrate @ 6728]
Mark Doliner <markdoliner@pidgin.im>
parents:
6100
diff
changeset
|
29 | |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
30 | #ifdef DEBUG |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
31 | # undef DEBUG |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
32 | #endif |
| 5205 | 33 | |
| 34 | #undef PACKAGE | |
| 35 | ||
| 36 | #define group perl_group | |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
37 | |
| 5205 | 38 | #ifdef _WIN32 |
| 39 | /* This took me an age to figure out.. without this __declspec(dllimport) | |
| 40 | * will be ignored. | |
| 41 | */ | |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
42 | # define HASATTRIBUTE |
| 5205 | 43 | #endif |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
44 | |
| 5205 | 45 | #include <EXTERN.h> |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
46 | |
| 5205 | 47 | #ifndef _SEM_SEMUN_UNDEFINED |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
48 | # define HAS_UNION_SEMUN |
| 5205 | 49 | #endif |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
50 | |
| 5205 | 51 | #include <perl.h> |
| 52 | #include <XSUB.h> | |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
53 | |
| 5205 | 54 | #ifndef _WIN32 |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
55 | # include <sys/mman.h> |
| 5205 | 56 | #endif |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
57 | |
| 5205 | 58 | #undef PACKAGE |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
59 | |
| 5205 | 60 | #ifndef _WIN32 |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
61 | # include <dirent.h> |
| 5205 | 62 | #else |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
63 | /* We're using perl's win32 port of this */ |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
64 | # define dirent direct |
| 5205 | 65 | #endif |
| 66 | ||
| 67 | #undef group | |
| 68 | ||
| 69 | /* perl module support */ | |
| 70 | #ifdef OLD_PERL | |
| 71 | extern void boot_DynaLoader _((CV * cv)); | |
| 72 | #else | |
| 73 | extern void boot_DynaLoader _((pTHX_ CV * cv)); /* perl is so wacky */ | |
| 74 | #endif | |
| 75 | ||
| 76 | #undef _ | |
| 77 | #ifdef DEBUG | |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
78 | # undef DEBUG |
| 5205 | 79 | #endif |
| 80 | #ifdef _WIN32 | |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
81 | # undef pipe |
| 5205 | 82 | #endif |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
83 | |
|
6575
fdb1928afdf9
[gaim-migrate @ 7097]
Herman Bloggs <herman@bluedigits.com>
parents:
6549
diff
changeset
|
84 | #ifdef _WIN32 |
|
fdb1928afdf9
[gaim-migrate @ 7097]
Herman Bloggs <herman@bluedigits.com>
parents:
6549
diff
changeset
|
85 | #define _WIN32DEP_H_ |
|
fdb1928afdf9
[gaim-migrate @ 7097]
Herman Bloggs <herman@bluedigits.com>
parents:
6549
diff
changeset
|
86 | #endif |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
87 | #include "internal.h" |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
88 | #include "debug.h" |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
89 | #include "plugin.h" |
|
6531
3fca41d7b411
[gaim-migrate @ 7048]
Christian Hammond <chipx86@chipx86.com>
parents:
6527
diff
changeset
|
90 | #include "signals.h" |
| 9943 | 91 | #include "version.h" |
| 5205 | 92 | |
|
6526
c6c3f10519ab
[gaim-migrate @ 7043]
Christian Hammond <chipx86@chipx86.com>
parents:
6525
diff
changeset
|
93 | #include "perl-common.h" |
|
6522
e7d94240fc71
[gaim-migrate @ 7039]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
94 | #include "perl-handlers.h" |
|
e7d94240fc71
[gaim-migrate @ 7039]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
95 | |
|
16529
1d0da9270ff9
This is mostly moving Purple::GtkUI:: -> Pidgin:: which has the side effect of
Etan Reisner <deryni@pidgin.im>
parents:
16528
diff
changeset
|
96 | #include <gmodule.h> |
|
1d0da9270ff9
This is mostly moving Purple::GtkUI:: -> Pidgin:: which has the side effect of
Etan Reisner <deryni@pidgin.im>
parents:
16528
diff
changeset
|
97 | |
| 5205 | 98 | #define PERL_PLUGIN_ID "core-perl" |
| 99 | ||
| 12872 | 100 | PerlInterpreter *my_perl = NULL; |
| 101 | ||
| 15884 | 102 | static PurplePluginUiInfo ui_info = |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
103 | { |
| 15884 | 104 | purple_perl_get_plugin_frame, |
| 12872 | 105 | 0, /* page_num (Reserved) */ |
| 106 | NULL /* frame (Reserved) */ | |
| 107 | }; | |
| 5205 | 108 | |
| 15884 | 109 | #ifdef PURPLE_GTKPERL |
| 110 | static PurpleGtkPluginUiInfo gtk_ui_info = | |
| 12872 | 111 | { |
| 15884 | 112 | purple_perl_gtk_get_plugin_frame, |
| 12872 | 113 | 0 /* page_num (Reserved) */ |
| 114 | }; | |
|
14426
8d4f164c4979
[gaim-migrate @ 17070]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
115 | #endif |
| 5205 | 116 | |
| 117 | static void | |
| 118 | #ifdef OLD_PERL | |
| 119 | xs_init() | |
| 120 | #else | |
| 121 | xs_init(pTHX) | |
| 122 | #endif | |
| 123 | { | |
| 124 | char *file = __FILE__; | |
| 125 | ||
| 12873 | 126 | /* This one allows dynamic loading of perl modules in perl scripts by |
| 127 | * the 'use perlmod;' construction */ | |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
128 | newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); |
| 5205 | 129 | } |
| 130 | ||
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
131 | static void |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
132 | perl_init(void) |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
133 | { |
| 12873 | 134 | /* changed the name of the variable from load_file to perl_definitions |
| 135 | * since now it does much more than defining the load_file sub. | |
| 136 | * Moreover, deplaced the initialisation to the xs_init function. | |
| 137 | * (TheHobbit) */ | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
138 | char *perl_args[] = { "", "-e", "0", "-w" }; |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
139 | char perl_definitions[] = |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
140 | { |
| 12873 | 141 | /* We use to function one to load a file the other to execute |
| 142 | * the string obtained from the first and holding the file | |
| 143 | * contents. This allows to have a really local $/ without | |
| 144 | * introducing temp variables to hold the old value. Just a | |
| 145 | * question of style:) */ | |
| 15884 | 146 | "package Purple::PerlLoader;" |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
147 | "use Symbol;" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
148 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
149 | "sub load_file {" |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
150 | "my $f_name=shift;" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
151 | "local $/=undef;" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
152 | "open FH,$f_name or return \"__FAILED__\";" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
153 | "$_=<FH>;" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
154 | "close FH;" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
155 | "return $_;" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
156 | "}" |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
157 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
158 | "sub destroy_package {" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
159 | "eval { $_[0]->UNLOAD() if $_[0]->can('UNLOAD'); };" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
160 | "Symbol::delete_package($_[0]);" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
161 | "}" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
162 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
163 | "sub load_n_eval {" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
164 | "my ($f_name, $package) = @_;" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
165 | "destroy_package($package);" |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
166 | "my $strin=load_file($f_name);" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
167 | "return 2 if($strin eq \"__FAILED__\");" |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
168 | "my $eval = qq{package $package; $strin;};" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
169 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
170 | "{" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
171 | " eval $eval;" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
172 | "}" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
173 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
174 | "if($@) {" |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
175 | /*" #something went wrong\n"*/ |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
176 | "die(\"Errors loading file $f_name: $@\");" |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
177 | "}" |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
178 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
179 | "return 0;" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
180 | "}" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
181 | }; |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
182 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
183 | my_perl = perl_alloc(); |
| 12871 | 184 | PERL_SET_CONTEXT(my_perl); |
| 11290 | 185 | PL_perl_destruct_level = 1; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
186 | perl_construct(my_perl); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
187 | #ifdef DEBUG |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
188 | perl_parse(my_perl, xs_init, 4, perl_args, NULL); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
189 | #else |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
190 | perl_parse(my_perl, xs_init, 3, perl_args, NULL); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
191 | #endif |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
192 | #ifdef HAVE_PERL_EVAL_PV |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
193 | eval_pv(perl_definitions, TRUE); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
194 | #else |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
195 | perl_eval_pv(perl_definitions, TRUE); /* deprecated */ |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
196 | #endif |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
197 | perl_run(my_perl); |
| 5205 | 198 | } |
| 199 | ||
| 200 | static void | |
| 201 | perl_end(void) | |
| 202 | { | |
|
6520
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
203 | if (my_perl == NULL) |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
204 | return; |
| 12871 | 205 | |
| 11290 | 206 | PL_perl_destruct_level = 1; |
| 12873 | 207 | PERL_SET_CONTEXT(my_perl); |
|
6520
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
208 | perl_eval_pv( |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
209 | "foreach my $lib (@DynaLoader::dl_modules) {" |
| 15884 | 210 | "if ($lib =~ /^Purple\\b/) {" |
|
6520
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
211 | "$lib .= '::deinit();';" |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
212 | "eval $lib;" |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
213 | "}" |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
214 | "}", |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
215 | TRUE); |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
216 | |
| 11290 | 217 | PL_perl_destruct_level = 1; |
| 12871 | 218 | PERL_SET_CONTEXT(my_perl); |
|
6520
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
219 | perl_destruct(my_perl); |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
220 | perl_free(my_perl); |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
221 | my_perl = NULL; |
| 5205 | 222 | } |
| 223 | ||
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
224 | void |
| 15884 | 225 | purple_perl_callXS(void (*subaddr)(pTHX_ CV *cv), CV *cv, SV **mark) |
| 5205 | 226 | { |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
227 | dSP; |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
228 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
229 | PUSHMARK(mark); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
230 | (*subaddr)(aTHX_ cv); |
| 5205 | 231 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
232 | PUTBACK; |
| 5205 | 233 | } |
| 234 | ||
| 235 | static gboolean | |
| 15884 | 236 | probe_perl_plugin(PurplePlugin *plugin) |
| 5205 | 237 | { |
| 238 | /* XXX This would be much faster if I didn't create a new | |
| 239 | * PerlInterpreter every time I probed a plugin */ | |
| 12871 | 240 | |
| 5205 | 241 | PerlInterpreter *prober = perl_alloc(); |
| 242 | char *argv[] = {"", plugin->path }; | |
| 243 | gboolean status = TRUE; | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
244 | HV *plugin_info; |
| 12871 | 245 | PERL_SET_CONTEXT(prober); |
| 11290 | 246 | PL_perl_destruct_level = 1; |
| 5205 | 247 | perl_construct(prober); |
| 11290 | 248 | |
| 5922 | 249 | perl_parse(prober, xs_init, 2, argv, NULL); |
| 11290 | 250 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
251 | perl_run(prober); |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
252 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
253 | plugin_info = perl_get_hv("PLUGIN_INFO", FALSE); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
254 | |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
255 | if (plugin_info == NULL) |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
256 | status = FALSE; |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
257 | else if (!hv_exists(plugin_info, "perl_api_version", |
| 12871 | 258 | strlen("perl_api_version")) || |
| 259 | !hv_exists(plugin_info, "name", strlen("name")) || | |
| 260 | !hv_exists(plugin_info, "load", strlen("load"))) { | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
261 | /* Not a valid plugin. */ |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
262 | |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
263 | status = FALSE; |
| 12871 | 264 | } else { |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
265 | SV **key; |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
266 | int perl_api_ver; |
| 5205 | 267 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
268 | key = hv_fetch(plugin_info, "perl_api_version", |
| 12873 | 269 | strlen("perl_api_version"), 0); |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
270 | |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
271 | perl_api_ver = SvIV(*key); |
| 5205 | 272 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
273 | if (perl_api_ver != 2) |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
274 | status = FALSE; |
| 12871 | 275 | else { |
| 15884 | 276 | PurplePluginInfo *info; |
| 277 | PurplePerlScript *gps; | |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
278 | char *basename; |
|
6678
c633179afd00
[gaim-migrate @ 7203]
Christian Hammond <chipx86@chipx86.com>
parents:
6636
diff
changeset
|
279 | STRLEN len; |
| 5205 | 280 | |
| 15884 | 281 | info = g_new0(PurplePluginInfo, 1); |
| 282 | gps = g_new0(PurplePerlScript, 1); | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
283 | |
| 15884 | 284 | info->magic = PURPLE_PLUGIN_MAGIC; |
| 285 | info->major_version = PURPLE_MAJOR_VERSION; | |
| 286 | info->minor_version = PURPLE_MINOR_VERSION; | |
| 287 | info->type = PURPLE_PLUGIN_STANDARD; | |
| 5205 | 288 | |
| 289 | info->dependencies = g_list_append(info->dependencies, | |
| 12871 | 290 | PERL_PLUGIN_ID); |
| 5205 | 291 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
292 | gps->plugin = plugin; |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
293 | |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
294 | basename = g_path_get_basename(plugin->path); |
| 15884 | 295 | purple_perl_normalize_script_name(basename); |
| 296 | gps->package = g_strdup_printf("Purple::Script::%s", | |
| 12871 | 297 | basename); |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
298 | g_free(basename); |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
299 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
300 | /* We know this one exists. */ |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
301 | key = hv_fetch(plugin_info, "name", strlen("name"), 0); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
302 | info->name = g_strdup(SvPV(*key, len)); |
| 12984 | 303 | /* Set id here in case we don't find one later. */ |
| 304 | info->id = g_strdup(SvPV(*key, len)); | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
305 | |
| 15884 | 306 | #ifdef PURPLE_GTKPERL |
| 12871 | 307 | if ((key = hv_fetch(plugin_info, "GTK_UI", |
| 308 | strlen("GTK_UI"), 0))) | |
| 15884 | 309 | info->ui_requirement = PURPLE_GTK_PLUGIN_TYPE; |
| 14434 | 310 | #endif |
| 11170 | 311 | |
| 12871 | 312 | if ((key = hv_fetch(plugin_info, "url", |
| 313 | strlen("url"), 0))) | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
314 | info->homepage = g_strdup(SvPV(*key, len)); |
| 12873 | 315 | |
| 12871 | 316 | if ((key = hv_fetch(plugin_info, "author", |
| 317 | strlen("author"), 0))) | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
318 | info->author = g_strdup(SvPV(*key, len)); |
| 5205 | 319 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
320 | if ((key = hv_fetch(plugin_info, "summary", |
| 12871 | 321 | strlen("summary"), 0))) |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
322 | info->summary = g_strdup(SvPV(*key, len)); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
323 | |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
324 | if ((key = hv_fetch(plugin_info, "description", |
| 12871 | 325 | strlen("description"), 0))) |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
326 | info->description = g_strdup(SvPV(*key, len)); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
327 | |
| 12871 | 328 | if ((key = hv_fetch(plugin_info, "version", |
| 329 | strlen("version"), 0))) | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
330 | info->version = g_strdup(SvPV(*key, len)); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
331 | |
| 12984 | 332 | /* We know this one exists. */ |
| 333 | key = hv_fetch(plugin_info, "load", strlen("load"), 0); | |
| 334 | gps->load_sub = g_strdup_printf("%s::%s", gps->package, | |
| 335 | SvPV(*key, len)); | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
336 | |
| 12871 | 337 | if ((key = hv_fetch(plugin_info, "unload", |
| 338 | strlen("unload"), 0))) | |
| 339 | gps->unload_sub = g_strdup_printf("%s::%s", | |
| 340 | gps->package, | |
| 341 | SvPV(*key, len)); | |
| 5205 | 342 | |
| 12984 | 343 | if ((key = hv_fetch(plugin_info, "id", |
| 344 | strlen("id"), 0))) { | |
| 345 | g_free(info->id); | |
| 346 | info->id = g_strdup_printf("perl-%s", | |
| 347 | SvPV(*key, len)); | |
| 348 | } | |
| 349 | ||
| 12871 | 350 | /********************************************************/ |
| 351 | /* Only one of the next two options should be present */ | |
| 352 | /* */ | |
| 15884 | 353 | /* prefs_info - Uses non-GUI (read GTK) purple API calls */ |
| 354 | /* and creates a PurplePluginPrefInfo type. */ | |
| 12871 | 355 | /* */ |
| 356 | /* gtk_prefs_info - Requires gtk2-perl be installed by */ | |
| 12873 | 357 | /* the user and he must create a */ |
| 358 | /* GtkWidget the user and he must */ | |
| 359 | /* create a GtkWidget representing the */ | |
| 360 | /* plugin preferences page. */ | |
| 12871 | 361 | /********************************************************/ |
| 362 | if ((key = hv_fetch(plugin_info, "prefs_info", | |
| 363 | strlen("prefs_info"), 0))) { | |
| 364 | /* key now is the name of the Perl sub that | |
| 365 | * will create a frame for us */ | |
| 12872 | 366 | gps->prefs_sub = g_strdup_printf("%s::%s", |
| 367 | gps->package, | |
| 368 | SvPV(*key, len)); | |
| 369 | info->prefs_info = &ui_info; | |
| 11123 | 370 | } |
| 12890 | 371 | |
| 15884 | 372 | #ifdef PURPLE_GTKPERL |
| 12871 | 373 | if ((key = hv_fetch(plugin_info, "gtk_prefs_info", |
| 374 | strlen("gtk_prefs_info"), 0))) { | |
| 375 | /* key now is the name of the Perl sub that | |
| 376 | * will create a frame for us */ | |
| 12872 | 377 | gps->gtk_prefs_sub = g_strdup_printf("%s::%s", |
| 378 | gps->package, | |
| 379 | SvPV(*key, len)); | |
| 380 | info->ui_info = >k_ui_info; | |
| 11170 | 381 | } |
|
14426
8d4f164c4979
[gaim-migrate @ 17070]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
382 | #endif |
| 11170 | 383 | |
| 12988 | 384 | if ((key = hv_fetch(plugin_info, "plugin_action_sub", |
| 385 | strlen("plugin_action_sub"), 0))) { | |
| 386 | gps->plugin_action_sub = g_strdup_printf("%s::%s", | |
| 387 | gps->package, | |
| 388 | SvPV(*key, len)); | |
| 15884 | 389 | info->actions = purple_perl_plugin_actions; |
| 11170 | 390 | } |
| 11123 | 391 | |
| 5205 | 392 | plugin->info = info; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
393 | info->extra_info = gps; |
| 5205 | 394 | |
| 15884 | 395 | status = purple_plugin_register(plugin); |
| 5205 | 396 | } |
| 397 | } | |
| 12871 | 398 | |
| 11290 | 399 | PL_perl_destruct_level = 1; |
| 12871 | 400 | PERL_SET_CONTEXT(prober); |
| 5205 | 401 | perl_destruct(prober); |
| 402 | perl_free(prober); | |
| 403 | return status; | |
| 404 | } | |
| 405 | ||
| 406 | static gboolean | |
| 15884 | 407 | load_perl_plugin(PurplePlugin *plugin) |
| 5205 | 408 | { |
| 15884 | 409 | PurplePerlScript *gps = (PurplePerlScript *)plugin->info->extra_info; |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
410 | char *atmp[3] = { plugin->path, NULL, NULL }; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
411 | |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
412 | if (gps == NULL || gps->load_sub == NULL) |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
413 | return FALSE; |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
414 | |
| 15884 | 415 | purple_debug(PURPLE_DEBUG_INFO, "perl", "Loading perl script\n"); |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
416 | |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
417 | if (my_perl == NULL) |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
418 | perl_init(); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
419 | |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
420 | plugin->handle = gps; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
421 | |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
422 | atmp[1] = gps->package; |
| 12871 | 423 | |
| 424 | PERL_SET_CONTEXT(my_perl); | |
| 15884 | 425 | execute_perl("Purple::PerlLoader::load_n_eval", 2, atmp); |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
426 | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
427 | { |
|
11318
13fa1d5134f3
[gaim-migrate @ 13521]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11290
diff
changeset
|
428 | dSP; |
| 11290 | 429 | PERL_SET_CONTEXT(my_perl); |
|
11318
13fa1d5134f3
[gaim-migrate @ 13521]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11290
diff
changeset
|
430 | SPAGAIN; |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
431 | ENTER; |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
432 | SAVETMPS; |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
433 | PUSHMARK(sp); |
| 15884 | 434 | XPUSHs(sv_2mortal(purple_perl_bless_object(plugin, |
| 435 | "Purple::Plugin"))); | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
436 | PUTBACK; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
437 | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
438 | perl_call_pv(gps->load_sub, G_EVAL | G_SCALAR); |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
439 | SPAGAIN; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
440 | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
441 | if (SvTRUE(ERRSV)) { |
|
6678
c633179afd00
[gaim-migrate @ 7203]
Christian Hammond <chipx86@chipx86.com>
parents:
6636
diff
changeset
|
442 | STRLEN len; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
443 | |
| 15884 | 444 | purple_debug(PURPLE_DEBUG_ERROR, "perl", |
| 12871 | 445 | "Perl function %s exited abnormally: %s\n", |
| 446 | gps->load_sub, SvPV(ERRSV, len)); | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
447 | } |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
448 | |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
449 | PUTBACK; |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
450 | FREETMPS; |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
451 | LEAVE; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
452 | } |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
453 | |
| 5205 | 454 | return TRUE; |
| 455 | } | |
| 456 | ||
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
457 | static void |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
458 | destroy_package(const char *package) |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
459 | { |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
460 | dSP; |
|
11318
13fa1d5134f3
[gaim-migrate @ 13521]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11290
diff
changeset
|
461 | PERL_SET_CONTEXT(my_perl); |
|
13fa1d5134f3
[gaim-migrate @ 13521]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11290
diff
changeset
|
462 | SPAGAIN; |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
463 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
464 | ENTER; |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
465 | SAVETMPS; |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
466 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
467 | PUSHMARK(SP); |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
468 | XPUSHs(sv_2mortal(newSVpv(package, strlen(package)))); |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
469 | PUTBACK; |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
470 | |
| 15884 | 471 | perl_call_pv("Purple::PerlLoader::destroy_package", |
| 12871 | 472 | G_VOID | G_EVAL | G_DISCARD); |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
473 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
474 | SPAGAIN; |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
475 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
476 | PUTBACK; |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
477 | FREETMPS; |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
478 | LEAVE; |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
479 | } |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
480 | |
| 5205 | 481 | static gboolean |
| 15884 | 482 | unload_perl_plugin(PurplePlugin *plugin) |
| 5205 | 483 | { |
| 15884 | 484 | PurplePerlScript *gps = (PurplePerlScript *)plugin->info->extra_info; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
485 | |
|
9578
d02c3d247fb7
[gaim-migrate @ 10421]
Christian Hammond <chipx86@chipx86.com>
parents:
8993
diff
changeset
|
486 | if (gps == NULL) |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
487 | return FALSE; |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
488 | |
| 15884 | 489 | purple_debug(PURPLE_DEBUG_INFO, "perl", "Unloading perl script\n"); |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
490 | |
| 12871 | 491 | if (gps->unload_sub != NULL) { |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
492 | dSP; |
|
11318
13fa1d5134f3
[gaim-migrate @ 13521]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11290
diff
changeset
|
493 | PERL_SET_CONTEXT(my_perl); |
|
13fa1d5134f3
[gaim-migrate @ 13521]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11290
diff
changeset
|
494 | SPAGAIN; |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
495 | ENTER; |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
496 | SAVETMPS; |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
497 | PUSHMARK(sp); |
| 15884 | 498 | XPUSHs(sv_2mortal(purple_perl_bless_object(plugin, |
| 499 | "Purple::Plugin"))); | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
500 | PUTBACK; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
501 | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
502 | perl_call_pv(gps->unload_sub, G_EVAL | G_SCALAR); |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
503 | SPAGAIN; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
504 | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
505 | if (SvTRUE(ERRSV)) { |
|
6678
c633179afd00
[gaim-migrate @ 7203]
Christian Hammond <chipx86@chipx86.com>
parents:
6636
diff
changeset
|
506 | STRLEN len; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
507 | |
| 15884 | 508 | purple_debug(PURPLE_DEBUG_ERROR, "perl", |
| 12871 | 509 | "Perl function %s exited abnormally: %s\n", |
| 510 | gps->load_sub, SvPV(ERRSV, len)); | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
511 | } |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
512 | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
513 | PUTBACK; |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
514 | FREETMPS; |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
515 | LEAVE; |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
516 | } |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
517 | |
| 15884 | 518 | purple_perl_cmd_clear_for_plugin(plugin); |
| 519 | purple_perl_signal_clear_for_plugin(plugin); | |
| 520 | purple_perl_timeout_clear_for_plugin(plugin); | |
| 5205 | 521 | |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
522 | destroy_package(gps->package); |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
523 | |
| 5205 | 524 | return TRUE; |
| 525 | } | |
| 526 | ||
| 527 | static void | |
| 15884 | 528 | destroy_perl_plugin(PurplePlugin *plugin) |
| 5205 | 529 | { |
| 12873 | 530 | if (plugin->info != NULL) { |
| 15884 | 531 | PurplePerlScript *gps; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
532 | |
| 12871 | 533 | g_free(plugin->info->name); |
| 534 | g_free(plugin->info->version); | |
| 535 | g_free(plugin->info->summary); | |
| 536 | g_free(plugin->info->description); | |
| 537 | g_free(plugin->info->author); | |
| 538 | g_free(plugin->info->homepage); | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
539 | |
| 15884 | 540 | gps = (PurplePerlScript *)plugin->info->extra_info; |
| 12871 | 541 | if (gps != NULL) { |
| 542 | g_free(gps->load_sub); | |
| 543 | g_free(gps->unload_sub); | |
| 544 | g_free(gps->package); | |
| 12872 | 545 | g_free(gps->prefs_sub); |
| 15884 | 546 | #ifdef PURPLE_GTKPERL |
| 12872 | 547 | g_free(gps->gtk_prefs_sub); |
|
14426
8d4f164c4979
[gaim-migrate @ 17070]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
548 | #endif |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
549 | g_free(gps); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
550 | plugin->info->extra_info = NULL; |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
551 | } |
| 5205 | 552 | } |
| 553 | } | |
| 554 | ||
| 555 | static gboolean | |
| 15884 | 556 | plugin_load(PurplePlugin *plugin) |
| 11033 | 557 | { |
| 558 | return TRUE; | |
| 559 | } | |
| 560 | ||
| 561 | static gboolean | |
| 15884 | 562 | plugin_unload(PurplePlugin *plugin) |
| 5205 | 563 | { |
| 564 | perl_end(); | |
| 565 | ||
| 566 | return TRUE; | |
| 567 | } | |
| 568 | ||
| 15884 | 569 | static PurplePluginLoaderInfo loader_info = |
| 5205 | 570 | { |
| 571 | NULL, /**< exts */ | |
| 572 | probe_perl_plugin, /**< probe */ | |
| 573 | load_perl_plugin, /**< load */ | |
| 574 | unload_perl_plugin, /**< unload */ | |
|
16750
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
16529
diff
changeset
|
575 | destroy_perl_plugin, /**< destroy */ |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
16529
diff
changeset
|
576 | |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
16529
diff
changeset
|
577 | /* padding */ |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
16529
diff
changeset
|
578 | NULL, |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
16529
diff
changeset
|
579 | NULL, |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
16529
diff
changeset
|
580 | NULL, |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
16529
diff
changeset
|
581 | NULL |
| 5205 | 582 | }; |
| 583 | ||
| 15884 | 584 | static PurplePluginInfo info = |
| 5205 | 585 | { |
| 15884 | 586 | PURPLE_PLUGIN_MAGIC, |
| 587 | PURPLE_MAJOR_VERSION, | |
| 588 | PURPLE_MINOR_VERSION, | |
|
16529
1d0da9270ff9
This is mostly moving Purple::GtkUI:: -> Pidgin:: which has the side effect of
Etan Reisner <deryni@pidgin.im>
parents:
16528
diff
changeset
|
589 | PURPLE_PLUGIN_LOADER, /**< type */ |
| 5205 | 590 | NULL, /**< ui_requirement */ |
| 591 | 0, /**< flags */ | |
| 592 | NULL, /**< dependencies */ | |
|
16529
1d0da9270ff9
This is mostly moving Purple::GtkUI:: -> Pidgin:: which has the side effect of
Etan Reisner <deryni@pidgin.im>
parents:
16528
diff
changeset
|
593 | PURPLE_PRIORITY_DEFAULT, /**< priority */ |
| 5205 | 594 | |
| 595 | PERL_PLUGIN_ID, /**< id */ | |
| 596 | N_("Perl Plugin Loader"), /**< name */ | |
| 597 | VERSION, /**< version */ | |
| 598 | N_("Provides support for loading perl plugins."), /**< summary */ | |
| 599 | N_("Provides support for loading perl plugins."), /**< description */ | |
| 600 | "Christian Hammond <chipx86@gnupdate.org>", /**< author */ | |
|
16529
1d0da9270ff9
This is mostly moving Purple::GtkUI:: -> Pidgin:: which has the side effect of
Etan Reisner <deryni@pidgin.im>
parents:
16528
diff
changeset
|
601 | PURPLE_WEBSITE, /**< homepage */ |
| 5205 | 602 | |
| 11033 | 603 | plugin_load, /**< load */ |
| 5205 | 604 | plugin_unload, /**< unload */ |
| 605 | NULL, /**< destroy */ | |
| 606 | ||
| 607 | NULL, /**< ui_info */ | |
| 8993 | 608 | &loader_info, /**< extra_info */ |
| 609 | NULL, | |
|
16750
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
16529
diff
changeset
|
610 | NULL, |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
16529
diff
changeset
|
611 | |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
16529
diff
changeset
|
612 | /* padding */ |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
16529
diff
changeset
|
613 | NULL, |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
16529
diff
changeset
|
614 | NULL, |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
16529
diff
changeset
|
615 | NULL, |
| 8993 | 616 | NULL |
| 5205 | 617 | }; |
| 618 | ||
| 619 | static void | |
| 15884 | 620 | init_plugin(PurplePlugin *plugin) |
| 5205 | 621 | { |
| 622 | loader_info.exts = g_list_append(loader_info.exts, "pl"); | |
| 623 | } | |
| 624 | ||
|
16528
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
625 | #ifdef __SUNPRO_C |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
626 | #pragma init (my_init) |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
627 | #else |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
628 | void __attribute__ ((constructor)) my_init(void); |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
629 | #endif |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
630 | |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
631 | void |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
632 | my_init(void) |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
633 | { |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
634 | /* Mostly evil hack... puts perl.so's symbols in the global table but |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
635 | * does not create a circular dependency because g_module_open will |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
636 | * only open the library once. */ |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
637 | /* Do we need to keep track of the returned GModule here so that we |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
638 | * can g_module_close it when this plugin gets unloaded? |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
639 | * At the moment I don't think this plugin can ever get unloaded but |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
640 | * in case that becomes possible this wants to get noted. */ |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
641 | g_module_open("perl.so", 0); |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
642 | } |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
643 | |
| 15884 | 644 | PURPLE_INIT_PLUGIN(perl, init_plugin, info) |