Mercurial > pidgin.yaz
annotate plugins/perl/perl.c @ 9943:f8e395a054e2
[gaim-migrate @ 10835]
this all seemed to work last night...hopefully no stray cosmic rays did anything to break it since then
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Fri, 03 Sep 2004 21:21:25 +0000 |
parents | 7cd7da72c872 |
children | 50224ac8184d |
rev | line source |
---|---|
5205 | 1 /* |
2 * gaim | |
3 * | |
6508
cbd24b37350d
[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 | 20 #ifdef HAVE_CONFIG_H |
21 #include <config.h> | |
8138
3e8592b95f68
[gaim-migrate @ 8844]
Christian Hammond <chipx86@chipx86.com>
parents:
8095
diff
changeset
|
22 # ifdef HAVE_LIMITS_H |
3e8592b95f68
[gaim-migrate @ 8844]
Christian Hammond <chipx86@chipx86.com>
parents:
8095
diff
changeset
|
23 # include <limits.h> |
3e8592b95f68
[gaim-migrate @ 8844]
Christian Hammond <chipx86@chipx86.com>
parents:
8095
diff
changeset
|
24 # ifndef NAME_MAX |
3e8592b95f68
[gaim-migrate @ 8844]
Christian Hammond <chipx86@chipx86.com>
parents:
8095
diff
changeset
|
25 # define NAME_MAX _POSIX_NAME_MAX |
3e8592b95f68
[gaim-migrate @ 8844]
Christian Hammond <chipx86@chipx86.com>
parents:
8095
diff
changeset
|
26 # endif |
3e8592b95f68
[gaim-migrate @ 8844]
Christian Hammond <chipx86@chipx86.com>
parents:
8095
diff
changeset
|
27 # endif |
6235 | 28 #endif |
29 | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
30 #ifdef DEBUG |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
31 # undef DEBUG |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
32 #endif |
5205 | 33 |
34 #undef PACKAGE | |
35 | |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
36 |
5205 | 37 #define group perl_group |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
38 |
5205 | 39 #ifdef _WIN32 |
40 /* This took me an age to figure out.. without this __declspec(dllimport) | |
41 * will be ignored. | |
42 */ | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
43 # define HASATTRIBUTE |
5205 | 44 #endif |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
45 |
5205 | 46 #include <EXTERN.h> |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
47 |
5205 | 48 #ifndef _SEM_SEMUN_UNDEFINED |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
49 # define HAS_UNION_SEMUN |
5205 | 50 #endif |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
51 |
5205 | 52 #include <perl.h> |
53 #include <XSUB.h> | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
54 |
5205 | 55 #ifndef _WIN32 |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
56 # include <sys/mman.h> |
5205 | 57 #endif |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
58 |
5205 | 59 #undef PACKAGE |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
60 |
5205 | 61 #ifndef _WIN32 |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
62 # include <dirent.h> |
5205 | 63 #else |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
64 /* We're using perl's win32 port of this */ |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
65 # define dirent direct |
5205 | 66 #endif |
67 | |
68 #undef group | |
69 | |
70 /* perl module support */ | |
71 #ifdef OLD_PERL | |
72 extern void boot_DynaLoader _((CV * cv)); | |
73 #else | |
74 extern void boot_DynaLoader _((pTHX_ CV * cv)); /* perl is so wacky */ | |
75 #endif | |
76 | |
77 #undef _ | |
78 #ifdef DEBUG | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
79 # undef DEBUG |
5205 | 80 #endif |
81 #ifdef _WIN32 | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
82 # undef pipe |
5205 | 83 #endif |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
84 |
6575
87a0fb97d3b9
[gaim-migrate @ 7097]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6549
diff
changeset
|
85 #ifdef _WIN32 |
87a0fb97d3b9
[gaim-migrate @ 7097]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6549
diff
changeset
|
86 #define _WIN32DEP_H_ |
87a0fb97d3b9
[gaim-migrate @ 7097]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6549
diff
changeset
|
87 #endif |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
88 #include "internal.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
89 #include "debug.h" |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
90 #include "plugin.h" |
6531
7c42b8ca3222
[gaim-migrate @ 7048]
Christian Hammond <chipx86@chipx86.com>
parents:
6527
diff
changeset
|
91 #include "signals.h" |
9943 | 92 #include "version.h" |
5205 | 93 |
6526
e162c765fe21
[gaim-migrate @ 7043]
Christian Hammond <chipx86@chipx86.com>
parents:
6525
diff
changeset
|
94 #include "perl-common.h" |
6522
0c5233faceb8
[gaim-migrate @ 7039]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
95 #include "perl-handlers.h" |
0c5233faceb8
[gaim-migrate @ 7039]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
96 |
5205 | 97 #define PERL_PLUGIN_ID "core-perl" |
98 | |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
99 typedef struct |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
100 { |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
101 GaimPlugin *plugin; |
6636
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
102 char *package; |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
103 char *load_sub; |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
104 char *unload_sub; |
5205 | 105 |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
106 } GaimPerlScript; |
5205 | 107 |
108 | |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
109 PerlInterpreter *my_perl = NULL; |
5205 | 110 |
111 static void | |
112 #ifdef OLD_PERL | |
113 xs_init() | |
114 #else | |
115 xs_init(pTHX) | |
116 #endif | |
117 { | |
118 char *file = __FILE__; | |
119 | |
120 /* This one allows dynamic loading of perl modules in perl | |
121 scripts by the 'use perlmod;' construction*/ | |
6636
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
122 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); |
5205 | 123 } |
124 | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
125 |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
126 static void |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
127 perl_init(void) |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
128 { |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
129 /* changed the name of the variable from load_file to |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
130 perl_definitions since now it does much more than defining |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
131 the load_file sub. Moreover, deplaced the initialisation to |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
132 the xs_init function. (TheHobbit)*/ |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
133 char *perl_args[] = { "", "-e", "0", "-w" }; |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
134 char perl_definitions[] = |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
135 { |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
136 /* We use to function one to load a file the other to |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
137 execute the string obtained from the first and holding |
8735
92cbf9713795
[gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents:
8138
diff
changeset
|
138 the file contents. This allows to have a really local $/ |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
139 without introducing temp variables to hold the old |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
140 value. Just a question of style:) */ |
6636
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
141 "package Gaim::PerlLoader;" |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
142 "use Symbol;" |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
143 |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
144 "sub load_file {" |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
145 "my $f_name=shift;" |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
146 "local $/=undef;" |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
147 "open FH,$f_name or return \"__FAILED__\";" |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
148 "$_=<FH>;" |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
149 "close FH;" |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
150 "return $_;" |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
151 "}" |
6636
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
152 |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
153 "sub destroy_package {" |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
154 "eval { $_[0]->UNLOAD() if $_[0]->can('UNLOAD'); };" |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
155 "Symbol::delete_package($_[0]);" |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
156 "}" |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
157 |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
158 "sub load_n_eval {" |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
159 "my ($f_name, $package) = @_;" |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
160 "destroy_package($package);" |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
161 "my $strin=load_file($f_name);" |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
162 "return 2 if($strin eq \"__FAILED__\");" |
6636
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
163 "my $eval = qq{package $package; $strin;};" |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
164 |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
165 "{" |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
166 " eval $eval;" |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
167 "}" |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
168 |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
169 "if($@) {" |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
170 /*" #something went wrong\n"*/ |
6636
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
171 "die(\"Errors loading file $f_name: $@\");" |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
172 "}" |
6636
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
173 |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
174 "return 0;" |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
175 "}" |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
176 }; |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
177 |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
178 my_perl = perl_alloc(); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
179 perl_construct(my_perl); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
180 #ifdef DEBUG |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
181 perl_parse(my_perl, xs_init, 4, perl_args, NULL); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
182 #else |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
183 perl_parse(my_perl, xs_init, 3, perl_args, NULL); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
184 #endif |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
185 #ifdef HAVE_PERL_EVAL_PV |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
186 eval_pv(perl_definitions, TRUE); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
187 #else |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
188 perl_eval_pv(perl_definitions, TRUE); /* deprecated */ |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
189 #endif |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
190 |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
191 perl_run(my_perl); |
5205 | 192 } |
193 | |
194 static void | |
195 perl_end(void) | |
196 { | |
6520
2e2593d95121
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
197 if (my_perl == NULL) |
2e2593d95121
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
198 return; |
2e2593d95121
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
199 |
2e2593d95121
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
200 perl_eval_pv( |
2e2593d95121
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
201 "foreach my $lib (@DynaLoader::dl_modules) {" |
2e2593d95121
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
202 "if ($lib =~ /^Gaim\\b/) {" |
2e2593d95121
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
203 "$lib .= '::deinit();';" |
2e2593d95121
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
204 "eval $lib;" |
2e2593d95121
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
205 "}" |
2e2593d95121
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
206 "}", |
2e2593d95121
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
207 TRUE); |
2e2593d95121
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
208 |
2e2593d95121
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
209 perl_destruct(my_perl); |
2e2593d95121
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
210 perl_free(my_perl); |
2e2593d95121
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
211 my_perl = NULL; |
5205 | 212 } |
213 | |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
214 void |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
215 gaim_perl_callXS(void (*subaddr)(pTHX_ CV *cv), CV *cv, SV **mark) |
5205 | 216 { |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
217 dSP; |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
218 |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
219 PUSHMARK(mark); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
220 (*subaddr)(aTHX_ cv); |
5205 | 221 |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
222 PUTBACK; |
5205 | 223 } |
224 | |
6636
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
225 static void |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
226 normalize_script_name(char *name) |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
227 { |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
228 char *c; |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
229 |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
230 c = strrchr(name, '.'); |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
231 |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
232 if (c != NULL) |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
233 *c = '\0'; |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
234 |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
235 for (c = name; *c != '\0'; c++) |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
236 { |
8095 | 237 if (*c != '_' && !g_ascii_isalnum(*c)) |
6636
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
238 *c = '_'; |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
239 } |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
240 } |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
241 |
5205 | 242 static gboolean |
243 probe_perl_plugin(GaimPlugin *plugin) | |
244 { | |
245 /* XXX This would be much faster if I didn't create a new | |
246 * PerlInterpreter every time I probed a plugin */ | |
247 PerlInterpreter *prober = perl_alloc(); | |
248 char *argv[] = {"", plugin->path }; | |
249 gboolean status = TRUE; | |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
250 HV *plugin_info; |
5205 | 251 |
252 perl_construct(prober); | |
5922 | 253 perl_parse(prober, xs_init, 2, argv, NULL); |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
254 perl_run(prober); |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
255 |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
256 plugin_info = perl_get_hv("PLUGIN_INFO", FALSE); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
257 |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
258 if (plugin_info == NULL) |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
259 status = FALSE; |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
260 else if (!hv_exists(plugin_info, "perl_api_version", |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
261 strlen("perl_api_version")) || |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
262 !hv_exists(plugin_info, "name", strlen("name")) || |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
263 !hv_exists(plugin_info, "load", strlen("load"))) |
5205 | 264 { |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
265 /* Not a valid plugin. */ |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
266 |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
267 status = FALSE; |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
268 } |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
269 else |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
270 { |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
271 SV **key; |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
272 int perl_api_ver; |
5205 | 273 |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
274 key = hv_fetch(plugin_info, "perl_api_version", |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
275 strlen("perl_api_version"), 0); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
276 |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
277 perl_api_ver = SvIV(*key); |
5205 | 278 |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
279 if (perl_api_ver != 2) |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
280 status = FALSE; |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
281 else |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
282 { |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
283 GaimPluginInfo *info; |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
284 GaimPerlScript *gps; |
6636
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
285 char *basename; |
6678
eb95f31fa4eb
[gaim-migrate @ 7203]
Christian Hammond <chipx86@chipx86.com>
parents:
6636
diff
changeset
|
286 STRLEN len; |
5205 | 287 |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
288 gaim_debug(GAIM_DEBUG_INFO, "perl", "Found plugin info\n"); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
289 |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
290 info = g_new0(GaimPluginInfo, 1); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
291 gps = g_new0(GaimPerlScript, 1); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
292 |
9943 | 293 info->magic = GAIM_PLUGIN_MAGIC; |
294 info->major_version = GAIM_MAJOR_VERSION; | |
295 info->minor_version = GAIM_MINOR_VERSION; | |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
296 info->type = GAIM_PLUGIN_STANDARD; |
5205 | 297 |
298 info->dependencies = g_list_append(info->dependencies, | |
299 PERL_PLUGIN_ID); | |
300 | |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
301 gps->plugin = plugin; |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
302 |
6636
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
303 basename = g_path_get_basename(plugin->path); |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
304 normalize_script_name(basename); |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
305 gps->package = g_strdup_printf("Gaim::Script::%s", basename); |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
306 g_free(basename); |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
307 |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
308 /* We know this one exists. */ |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
309 key = hv_fetch(plugin_info, "name", strlen("name"), 0); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
310 info->name = g_strdup(SvPV(*key, len)); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
311 |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
312 if ((key = hv_fetch(plugin_info, "url", strlen("url"), 0))) |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
313 info->homepage = g_strdup(SvPV(*key, len)); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
314 |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
315 if ((key = hv_fetch(plugin_info, "author", strlen("author"), 0))) |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
316 info->author = g_strdup(SvPV(*key, len)); |
5205 | 317 |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
318 if ((key = hv_fetch(plugin_info, "summary", |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
319 strlen("summary"), 0))) |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
320 info->summary = g_strdup(SvPV(*key, len)); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
321 |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
322 if ((key = hv_fetch(plugin_info, "description", |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
323 strlen("description"), 0))) |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
324 info->description = g_strdup(SvPV(*key, len)); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
325 |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
326 if ((key = hv_fetch(plugin_info, "version", strlen("version"), 0))) |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
327 info->version = g_strdup(SvPV(*key, len)); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
328 |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
329 if ((key = hv_fetch(plugin_info, "load", strlen("load"), 0))) |
6636
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
330 gps->load_sub = g_strdup_printf("%s::%s", gps->package, |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
331 SvPV(*key, len)); |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
332 |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
333 if ((key = hv_fetch(plugin_info, "unload", strlen("unload"), 0))) |
6636
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
334 gps->unload_sub = g_strdup_printf("%s::%s", gps->package, |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
335 SvPV(*key, len)); |
5205 | 336 |
337 plugin->info = info; | |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
338 info->extra_info = gps; |
5205 | 339 |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
340 status = gaim_plugin_register(plugin); |
5205 | 341 } |
342 } | |
343 | |
344 perl_destruct(prober); | |
345 perl_free(prober); | |
346 | |
347 return status; | |
348 } | |
349 | |
350 static gboolean | |
351 load_perl_plugin(GaimPlugin *plugin) | |
352 { | |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
353 GaimPerlScript *gps = (GaimPerlScript *)plugin->info->extra_info; |
6636
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
354 char *atmp[3] = { plugin->path, NULL, NULL }; |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
355 |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
356 if (gps == NULL || gps->load_sub == NULL) |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
357 return FALSE; |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
358 |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
359 gaim_debug(GAIM_DEBUG_INFO, "perl", "Loading perl script\n"); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
360 |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
361 if (my_perl == NULL) |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
362 perl_init(); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
363 |
6636
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
364 plugin->handle = gps; |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
365 |
6636
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
366 atmp[1] = gps->package; |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
367 |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
368 execute_perl("Gaim::PerlLoader::load_n_eval", 2, atmp); |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
369 |
6536
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
370 { |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
371 dSP; |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
372 ENTER; |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
373 SAVETMPS; |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
374 PUSHMARK(sp); |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
375 XPUSHs(sv_2mortal(gaim_perl_bless_object(plugin, "Gaim::Plugin"))); |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
376 PUTBACK; |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
377 |
6536
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
378 perl_call_pv(gps->load_sub, G_EVAL | G_SCALAR); |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
379 SPAGAIN; |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
380 |
6536
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
381 if (SvTRUE(ERRSV)) { |
6678
eb95f31fa4eb
[gaim-migrate @ 7203]
Christian Hammond <chipx86@chipx86.com>
parents:
6636
diff
changeset
|
382 STRLEN len; |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
383 |
6536
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
384 gaim_debug(GAIM_DEBUG_ERROR, "perl", |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
385 "Perl function %s exited abnormally: %s\n", |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
386 gps->load_sub, SvPV(ERRSV, len)); |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
387 } |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
388 |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
389 PUTBACK; |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
390 FREETMPS; |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
391 LEAVE; |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
392 } |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
393 |
5205 | 394 return TRUE; |
395 } | |
396 | |
6636
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
397 static void |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
398 destroy_package(const char *package) |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
399 { |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
400 dSP; |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
401 |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
402 ENTER; |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
403 SAVETMPS; |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
404 |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
405 PUSHMARK(SP); |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
406 XPUSHs(sv_2mortal(newSVpv(package, strlen(package)))); |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
407 PUTBACK; |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
408 |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
409 perl_call_pv("Gaim::PerlLoader::destroy_package", |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
410 G_VOID | G_EVAL | G_DISCARD); |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
411 |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
412 SPAGAIN; |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
413 |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
414 PUTBACK; |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
415 FREETMPS; |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
416 LEAVE; |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
417 } |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
418 |
5205 | 419 static gboolean |
420 unload_perl_plugin(GaimPlugin *plugin) | |
421 { | |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
422 GaimPerlScript *gps = (GaimPerlScript *)plugin->info->extra_info; |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
423 |
9578
7cd7da72c872
[gaim-migrate @ 10421]
Christian Hammond <chipx86@chipx86.com>
parents:
8993
diff
changeset
|
424 if (gps == NULL) |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
425 return FALSE; |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
426 |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
427 gaim_debug(GAIM_DEBUG_INFO, "perl", "Unloading perl script\n"); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
428 |
9578
7cd7da72c872
[gaim-migrate @ 10421]
Christian Hammond <chipx86@chipx86.com>
parents:
8993
diff
changeset
|
429 if (gps->unload_sub != NULL) |
6536
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
430 { |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
431 dSP; |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
432 ENTER; |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
433 SAVETMPS; |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
434 PUSHMARK(sp); |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
435 XPUSHs(sv_2mortal(gaim_perl_bless_object(plugin, "Gaim::Plugin"))); |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
436 PUTBACK; |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
437 |
6536
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
438 perl_call_pv(gps->unload_sub, G_EVAL | G_SCALAR); |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
439 SPAGAIN; |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
440 |
6536
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
441 if (SvTRUE(ERRSV)) { |
6678
eb95f31fa4eb
[gaim-migrate @ 7203]
Christian Hammond <chipx86@chipx86.com>
parents:
6636
diff
changeset
|
442 STRLEN len; |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
443 |
6536
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
444 gaim_debug(GAIM_DEBUG_ERROR, "perl", |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
445 "Perl function %s exited abnormally: %s\n", |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
446 gps->load_sub, SvPV(ERRSV, len)); |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
447 } |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
448 |
6536
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
449 PUTBACK; |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
450 FREETMPS; |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
451 LEAVE; |
9767117bc47e
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
452 } |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
453 |
6549
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6536
diff
changeset
|
454 gaim_perl_signal_clear_for_plugin(plugin); |
6522
0c5233faceb8
[gaim-migrate @ 7039]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
455 gaim_perl_timeout_clear_for_plugin(plugin); |
5205 | 456 |
6636
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
457 destroy_package(gps->package); |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
458 |
5205 | 459 return TRUE; |
460 } | |
461 | |
462 static void | |
463 destroy_perl_plugin(GaimPlugin *plugin) | |
464 { | |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
465 if (plugin->info != NULL) |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
466 { |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
467 GaimPerlScript *gps; |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
468 |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
469 if (plugin->info->name != NULL) |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
470 g_free(plugin->info->name); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
471 |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
472 if (plugin->info->version != NULL) |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
473 g_free(plugin->info->version); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
474 |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
475 if (plugin->info->summary != NULL) |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
476 g_free(plugin->info->summary); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
477 |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
478 if (plugin->info->description != NULL) |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
479 g_free(plugin->info->description); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
480 |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
481 if (plugin->info->author != NULL) |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
482 g_free(plugin->info->author); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
483 |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
484 if (plugin->info->homepage != NULL) |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
485 g_free(plugin->info->homepage); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
486 |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
487 gps = (GaimPerlScript *)plugin->info->extra_info; |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
488 |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
489 if (gps != NULL) |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
490 { |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
491 if (gps->load_sub != NULL) |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
492 g_free(gps->load_sub); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
493 |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
494 if (gps->unload_sub != NULL) |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
495 g_free(gps->unload_sub); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
496 |
6636
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
497 if (gps->package != NULL) |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
498 g_free(gps->package); |
452c62a92963
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
499 |
6508
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
500 g_free(gps); |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
501 plugin->info->extra_info = NULL; |
cbd24b37350d
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
502 } |
5205 | 503 } |
504 } | |
505 | |
506 static gboolean | |
507 plugin_unload(GaimPlugin *plugin) | |
508 { | |
509 perl_end(); | |
510 | |
511 return TRUE; | |
512 } | |
513 | |
514 static GaimPluginLoaderInfo loader_info = | |
515 { | |
516 NULL, /**< exts */ | |
517 probe_perl_plugin, /**< probe */ | |
518 load_perl_plugin, /**< load */ | |
519 unload_perl_plugin, /**< unload */ | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
520 destroy_perl_plugin /**< destroy */ |
5205 | 521 }; |
522 | |
523 static GaimPluginInfo info = | |
524 { | |
9943 | 525 GAIM_PLUGIN_MAGIC, |
526 GAIM_MAJOR_VERSION, | |
527 GAIM_MINOR_VERSION, | |
5205 | 528 GAIM_PLUGIN_LOADER, /**< type */ |
529 NULL, /**< ui_requirement */ | |
530 0, /**< flags */ | |
531 NULL, /**< dependencies */ | |
532 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
533 | |
534 PERL_PLUGIN_ID, /**< id */ | |
535 N_("Perl Plugin Loader"), /**< name */ | |
536 VERSION, /**< version */ | |
537 N_("Provides support for loading perl plugins."), /**< summary */ | |
538 N_("Provides support for loading perl plugins."), /**< description */ | |
539 "Christian Hammond <chipx86@gnupdate.org>", /**< author */ | |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6235
diff
changeset
|
540 GAIM_WEBSITE, /**< homepage */ |
5205 | 541 |
542 NULL, /**< load */ | |
543 plugin_unload, /**< unload */ | |
544 NULL, /**< destroy */ | |
545 | |
546 NULL, /**< ui_info */ | |
8993 | 547 &loader_info, /**< extra_info */ |
548 NULL, | |
549 NULL | |
5205 | 550 }; |
551 | |
552 static void | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
553 init_plugin(GaimPlugin *plugin) |
5205 | 554 { |
555 loader_info.exts = g_list_append(loader_info.exts, "pl"); | |
556 } | |
557 | |
6063 | 558 GAIM_INIT_PLUGIN(perl, init_plugin, info) |