Wed, 18 Oct 2006 16:28:51 +0000
[gaim-migrate @ 17523]
accurate with the Offline Message send's Fault Code recognize and resend the OIM Get Message.
committed by MaYuan<mayuan2006@gmail.com>
committer: Ethan Blanton <elb@pidgin.im>
| 5205 | 1 | /* |
| 2 | * gaim | |
| 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 | |
| 5205 | 96 | #define PERL_PLUGIN_ID "core-perl" |
| 97 | ||
| 12872 | 98 | PerlInterpreter *my_perl = NULL; |
| 99 | ||
| 100 | static GaimPluginUiInfo ui_info = | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
101 | { |
| 12872 | 102 | gaim_perl_get_plugin_frame, |
| 103 | 0, /* page_num (Reserved) */ | |
| 104 | NULL /* frame (Reserved) */ | |
| 105 | }; | |
| 5205 | 106 | |
| 12872 | 107 | static GaimGtkPluginUiInfo gtk_ui_info = |
| 108 | { | |
| 109 | gaim_perl_gtk_get_plugin_frame, | |
| 110 | 0 /* page_num (Reserved) */ | |
| 111 | }; | |
| 5205 | 112 | |
| 113 | static void | |
| 114 | #ifdef OLD_PERL | |
| 115 | xs_init() | |
| 116 | #else | |
| 117 | xs_init(pTHX) | |
| 118 | #endif | |
| 119 | { | |
| 120 | char *file = __FILE__; | |
| 121 | ||
| 12873 | 122 | /* This one allows dynamic loading of perl modules in perl scripts by |
| 123 | * the 'use perlmod;' construction */ | |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
124 | newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); |
| 5205 | 125 | } |
| 126 | ||
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
127 | static void |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
128 | perl_init(void) |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
129 | { |
| 12873 | 130 | /* changed the name of the variable from load_file to perl_definitions |
| 131 | * since now it does much more than defining the load_file sub. | |
| 132 | * Moreover, deplaced the initialisation to the xs_init function. | |
| 133 | * (TheHobbit) */ | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
134 | char *perl_args[] = { "", "-e", "0", "-w" }; |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
135 | char perl_definitions[] = |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
136 | { |
| 12873 | 137 | /* We use to function one to load a file the other to execute |
| 138 | * the string obtained from the first and holding the file | |
| 139 | * contents. This allows to have a really local $/ without | |
| 140 | * introducing temp variables to hold the old value. Just a | |
| 141 | * question of style:) */ | |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
142 | "package Gaim::PerlLoader;" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
143 | "use Symbol;" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
144 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
145 | "sub load_file {" |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
146 | "my $f_name=shift;" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
147 | "local $/=undef;" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
148 | "open FH,$f_name or return \"__FAILED__\";" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
149 | "$_=<FH>;" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
150 | "close FH;" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
151 | "return $_;" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
152 | "}" |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
153 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
154 | "sub destroy_package {" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
155 | "eval { $_[0]->UNLOAD() if $_[0]->can('UNLOAD'); };" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
156 | "Symbol::delete_package($_[0]);" |
|
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 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
159 | "sub load_n_eval {" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
160 | "my ($f_name, $package) = @_;" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
161 | "destroy_package($package);" |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
162 | "my $strin=load_file($f_name);" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
163 | "return 2 if($strin eq \"__FAILED__\");" |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
164 | "my $eval = qq{package $package; $strin;};" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
165 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
166 | "{" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
167 | " eval $eval;" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
168 | "}" |
|
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 | "if($@) {" |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
171 | /*" #something went wrong\n"*/ |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
172 | "die(\"Errors loading file $f_name: $@\");" |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
173 | "}" |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
174 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
175 | "return 0;" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
176 | "}" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
177 | }; |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
178 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
179 | my_perl = perl_alloc(); |
| 12871 | 180 | PERL_SET_CONTEXT(my_perl); |
| 11290 | 181 | PL_perl_destruct_level = 1; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
182 | perl_construct(my_perl); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
183 | #ifdef DEBUG |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
184 | perl_parse(my_perl, xs_init, 4, perl_args, NULL); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
185 | #else |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
186 | perl_parse(my_perl, xs_init, 3, perl_args, NULL); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
187 | #endif |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
188 | #ifdef HAVE_PERL_EVAL_PV |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
189 | eval_pv(perl_definitions, TRUE); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
190 | #else |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
191 | perl_eval_pv(perl_definitions, TRUE); /* deprecated */ |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
192 | #endif |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
193 | perl_run(my_perl); |
| 5205 | 194 | } |
| 195 | ||
| 196 | static void | |
| 197 | perl_end(void) | |
| 198 | { | |
|
6520
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
199 | if (my_perl == NULL) |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
200 | return; |
| 12871 | 201 | |
| 11290 | 202 | PL_perl_destruct_level = 1; |
| 12873 | 203 | PERL_SET_CONTEXT(my_perl); |
|
6520
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
204 | perl_eval_pv( |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
205 | "foreach my $lib (@DynaLoader::dl_modules) {" |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
206 | "if ($lib =~ /^Gaim\\b/) {" |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
207 | "$lib .= '::deinit();';" |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
208 | "eval $lib;" |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
209 | "}" |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
210 | "}", |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
211 | TRUE); |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
212 | |
| 11290 | 213 | PL_perl_destruct_level = 1; |
| 12871 | 214 | PERL_SET_CONTEXT(my_perl); |
|
6520
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
215 | perl_destruct(my_perl); |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
216 | perl_free(my_perl); |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
217 | my_perl = NULL; |
| 5205 | 218 | } |
| 219 | ||
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
220 | void |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
221 | gaim_perl_callXS(void (*subaddr)(pTHX_ CV *cv), CV *cv, SV **mark) |
| 5205 | 222 | { |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
223 | dSP; |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
224 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
225 | PUSHMARK(mark); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
226 | (*subaddr)(aTHX_ cv); |
| 5205 | 227 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
228 | PUTBACK; |
| 5205 | 229 | } |
| 230 | ||
| 231 | static gboolean | |
| 232 | probe_perl_plugin(GaimPlugin *plugin) | |
| 233 | { | |
| 234 | /* XXX This would be much faster if I didn't create a new | |
| 235 | * PerlInterpreter every time I probed a plugin */ | |
| 12871 | 236 | |
| 5205 | 237 | PerlInterpreter *prober = perl_alloc(); |
| 238 | char *argv[] = {"", plugin->path }; | |
| 239 | gboolean status = TRUE; | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
240 | HV *plugin_info; |
| 12871 | 241 | PERL_SET_CONTEXT(prober); |
| 11290 | 242 | PL_perl_destruct_level = 1; |
| 5205 | 243 | perl_construct(prober); |
| 11290 | 244 | |
| 5922 | 245 | perl_parse(prober, xs_init, 2, argv, NULL); |
| 11290 | 246 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
247 | perl_run(prober); |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
248 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
249 | plugin_info = perl_get_hv("PLUGIN_INFO", FALSE); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
250 | |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
251 | if (plugin_info == NULL) |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
252 | status = FALSE; |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
253 | else if (!hv_exists(plugin_info, "perl_api_version", |
| 12871 | 254 | strlen("perl_api_version")) || |
| 255 | !hv_exists(plugin_info, "name", strlen("name")) || | |
| 256 | !hv_exists(plugin_info, "load", strlen("load"))) { | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
257 | /* Not a valid plugin. */ |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
258 | |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
259 | status = FALSE; |
| 12871 | 260 | } else { |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
261 | SV **key; |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
262 | int perl_api_ver; |
| 5205 | 263 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
264 | key = hv_fetch(plugin_info, "perl_api_version", |
| 12873 | 265 | strlen("perl_api_version"), 0); |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
266 | |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
267 | perl_api_ver = SvIV(*key); |
| 5205 | 268 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
269 | if (perl_api_ver != 2) |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
270 | status = FALSE; |
| 12871 | 271 | else { |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
272 | GaimPluginInfo *info; |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
273 | GaimPerlScript *gps; |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
274 | char *basename; |
|
6678
c633179afd00
[gaim-migrate @ 7203]
Christian Hammond <chipx86@chipx86.com>
parents:
6636
diff
changeset
|
275 | STRLEN len; |
| 5205 | 276 | |
| 12871 | 277 | gaim_debug(GAIM_DEBUG_INFO, "perl", |
| 278 | "Found plugin info\n"); | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
279 | |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
280 | info = g_new0(GaimPluginInfo, 1); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
281 | gps = g_new0(GaimPerlScript, 1); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
282 | |
| 9943 | 283 | info->magic = GAIM_PLUGIN_MAGIC; |
| 284 | info->major_version = GAIM_MAJOR_VERSION; | |
| 285 | info->minor_version = GAIM_MINOR_VERSION; | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
286 | info->type = GAIM_PLUGIN_STANDARD; |
| 5205 | 287 | |
| 288 | info->dependencies = g_list_append(info->dependencies, | |
| 12871 | 289 | PERL_PLUGIN_ID); |
| 5205 | 290 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
291 | gps->plugin = plugin; |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
292 | |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
293 | basename = g_path_get_basename(plugin->path); |
| 11170 | 294 | gaim_perl_normalize_script_name(basename); |
| 12871 | 295 | gps->package = g_strdup_printf("Gaim::Script::%s", |
| 296 | basename); | |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
297 | g_free(basename); |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
298 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
299 | /* We know this one exists. */ |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
300 | key = hv_fetch(plugin_info, "name", strlen("name"), 0); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
301 | info->name = g_strdup(SvPV(*key, len)); |
| 12984 | 302 | /* Set id here in case we don't find one later. */ |
| 303 | info->id = g_strdup(SvPV(*key, len)); | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
304 | |
| 12871 | 305 | if ((key = hv_fetch(plugin_info, "GTK_UI", |
| 306 | strlen("GTK_UI"), 0))) | |
| 11170 | 307 | info->ui_requirement = GAIM_GTK_PLUGIN_TYPE; |
| 308 | ||
| 12871 | 309 | if ((key = hv_fetch(plugin_info, "url", |
| 310 | strlen("url"), 0))) | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
311 | info->homepage = g_strdup(SvPV(*key, len)); |
| 12873 | 312 | |
| 12871 | 313 | if ((key = hv_fetch(plugin_info, "author", |
| 314 | strlen("author"), 0))) | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
315 | info->author = g_strdup(SvPV(*key, len)); |
| 5205 | 316 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
317 | if ((key = hv_fetch(plugin_info, "summary", |
| 12871 | 318 | strlen("summary"), 0))) |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
319 | info->summary = g_strdup(SvPV(*key, len)); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
320 | |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
321 | if ((key = hv_fetch(plugin_info, "description", |
| 12871 | 322 | strlen("description"), 0))) |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
323 | info->description = g_strdup(SvPV(*key, len)); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
324 | |
| 12871 | 325 | if ((key = hv_fetch(plugin_info, "version", |
| 326 | strlen("version"), 0))) | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
327 | info->version = g_strdup(SvPV(*key, len)); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
328 | |
| 12984 | 329 | /* We know this one exists. */ |
| 330 | key = hv_fetch(plugin_info, "load", strlen("load"), 0); | |
| 331 | gps->load_sub = g_strdup_printf("%s::%s", gps->package, | |
| 332 | SvPV(*key, len)); | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
333 | |
| 12871 | 334 | if ((key = hv_fetch(plugin_info, "unload", |
| 335 | strlen("unload"), 0))) | |
| 336 | gps->unload_sub = g_strdup_printf("%s::%s", | |
| 337 | gps->package, | |
| 338 | SvPV(*key, len)); | |
| 5205 | 339 | |
| 12984 | 340 | if ((key = hv_fetch(plugin_info, "id", |
| 341 | strlen("id"), 0))) { | |
| 342 | g_free(info->id); | |
| 343 | info->id = g_strdup_printf("perl-%s", | |
| 344 | SvPV(*key, len)); | |
| 345 | } | |
| 346 | ||
| 12871 | 347 | /********************************************************/ |
| 348 | /* Only one of the next two options should be present */ | |
| 349 | /* */ | |
| 350 | /* prefs_info - Uses non-GUI (read GTK) gaim API calls */ | |
| 351 | /* and creates a GaimPluginPrefInfo type. */ | |
| 352 | /* */ | |
| 353 | /* gtk_prefs_info - Requires gtk2-perl be installed by */ | |
| 12873 | 354 | /* the user and he must create a */ |
| 355 | /* GtkWidget the user and he must */ | |
| 356 | /* create a GtkWidget representing the */ | |
| 357 | /* plugin preferences page. */ | |
| 12871 | 358 | /********************************************************/ |
| 359 | if ((key = hv_fetch(plugin_info, "prefs_info", | |
| 360 | strlen("prefs_info"), 0))) { | |
| 361 | /* key now is the name of the Perl sub that | |
| 362 | * will create a frame for us */ | |
| 12872 | 363 | gps->prefs_sub = g_strdup_printf("%s::%s", |
| 364 | gps->package, | |
| 365 | SvPV(*key, len)); | |
| 366 | info->prefs_info = &ui_info; | |
| 11123 | 367 | } |
| 12890 | 368 | |
| 12871 | 369 | if ((key = hv_fetch(plugin_info, "gtk_prefs_info", |
| 370 | strlen("gtk_prefs_info"), 0))) { | |
| 371 | /* key now is the name of the Perl sub that | |
| 372 | * will create a frame for us */ | |
| 12872 | 373 | gps->gtk_prefs_sub = g_strdup_printf("%s::%s", |
| 374 | gps->package, | |
| 375 | SvPV(*key, len)); | |
| 376 | info->ui_info = >k_ui_info; | |
| 11170 | 377 | } |
| 378 | ||
| 12988 | 379 | if ((key = hv_fetch(plugin_info, "plugin_action_sub", |
| 380 | strlen("plugin_action_sub"), 0))) { | |
| 381 | gps->plugin_action_sub = g_strdup_printf("%s::%s", | |
| 382 | gps->package, | |
| 383 | SvPV(*key, len)); | |
| 384 | info->actions = gaim_perl_plugin_actions; | |
| 11170 | 385 | } |
| 11123 | 386 | |
| 5205 | 387 | plugin->info = info; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
388 | info->extra_info = gps; |
| 5205 | 389 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
390 | status = gaim_plugin_register(plugin); |
| 5205 | 391 | } |
| 392 | } | |
| 12871 | 393 | |
| 11290 | 394 | PL_perl_destruct_level = 1; |
| 12871 | 395 | PERL_SET_CONTEXT(prober); |
| 5205 | 396 | perl_destruct(prober); |
| 397 | perl_free(prober); | |
| 398 | return status; | |
| 399 | } | |
| 400 | ||
| 401 | static gboolean | |
| 402 | load_perl_plugin(GaimPlugin *plugin) | |
| 403 | { | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
404 | GaimPerlScript *gps = (GaimPerlScript *)plugin->info->extra_info; |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
405 | char *atmp[3] = { plugin->path, NULL, NULL }; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
406 | |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
407 | if (gps == NULL || gps->load_sub == NULL) |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
408 | return FALSE; |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
409 | |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
410 | gaim_debug(GAIM_DEBUG_INFO, "perl", "Loading perl script\n"); |
|
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 (my_perl == NULL) |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
413 | perl_init(); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
414 | |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
415 | plugin->handle = gps; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
416 | |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
417 | atmp[1] = gps->package; |
| 12871 | 418 | |
| 419 | PERL_SET_CONTEXT(my_perl); | |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
420 | execute_perl("Gaim::PerlLoader::load_n_eval", 2, atmp); |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
421 | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
422 | { |
|
11318
13fa1d5134f3
[gaim-migrate @ 13521]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11290
diff
changeset
|
423 | dSP; |
| 11290 | 424 | PERL_SET_CONTEXT(my_perl); |
|
11318
13fa1d5134f3
[gaim-migrate @ 13521]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11290
diff
changeset
|
425 | SPAGAIN; |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
426 | ENTER; |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
427 | SAVETMPS; |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
428 | PUSHMARK(sp); |
| 12871 | 429 | XPUSHs(sv_2mortal(gaim_perl_bless_object(plugin, |
| 430 | "Gaim::Plugin"))); | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
431 | PUTBACK; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
432 | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
433 | perl_call_pv(gps->load_sub, G_EVAL | G_SCALAR); |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
434 | SPAGAIN; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
435 | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
436 | if (SvTRUE(ERRSV)) { |
|
6678
c633179afd00
[gaim-migrate @ 7203]
Christian Hammond <chipx86@chipx86.com>
parents:
6636
diff
changeset
|
437 | STRLEN len; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
438 | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
439 | gaim_debug(GAIM_DEBUG_ERROR, "perl", |
| 12871 | 440 | "Perl function %s exited abnormally: %s\n", |
| 441 | gps->load_sub, SvPV(ERRSV, len)); | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
442 | } |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
443 | |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
444 | PUTBACK; |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
445 | FREETMPS; |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
446 | LEAVE; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
447 | } |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
448 | |
| 5205 | 449 | return TRUE; |
| 450 | } | |
| 451 | ||
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
452 | static void |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
453 | destroy_package(const char *package) |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
454 | { |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
455 | dSP; |
|
11318
13fa1d5134f3
[gaim-migrate @ 13521]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11290
diff
changeset
|
456 | PERL_SET_CONTEXT(my_perl); |
|
13fa1d5134f3
[gaim-migrate @ 13521]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11290
diff
changeset
|
457 | SPAGAIN; |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
458 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
459 | ENTER; |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
460 | SAVETMPS; |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
461 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
462 | PUSHMARK(SP); |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
463 | XPUSHs(sv_2mortal(newSVpv(package, strlen(package)))); |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
464 | PUTBACK; |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
465 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
466 | perl_call_pv("Gaim::PerlLoader::destroy_package", |
| 12871 | 467 | G_VOID | G_EVAL | G_DISCARD); |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
468 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
469 | SPAGAIN; |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
470 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
471 | PUTBACK; |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
472 | FREETMPS; |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
473 | LEAVE; |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
474 | } |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
475 | |
| 5205 | 476 | static gboolean |
| 477 | unload_perl_plugin(GaimPlugin *plugin) | |
| 478 | { | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
479 | GaimPerlScript *gps = (GaimPerlScript *)plugin->info->extra_info; |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
480 | |
|
9578
d02c3d247fb7
[gaim-migrate @ 10421]
Christian Hammond <chipx86@chipx86.com>
parents:
8993
diff
changeset
|
481 | if (gps == NULL) |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
482 | return FALSE; |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
483 | |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
484 | gaim_debug(GAIM_DEBUG_INFO, "perl", "Unloading perl script\n"); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
485 | |
| 12871 | 486 | if (gps->unload_sub != NULL) { |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
487 | dSP; |
|
11318
13fa1d5134f3
[gaim-migrate @ 13521]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11290
diff
changeset
|
488 | PERL_SET_CONTEXT(my_perl); |
|
13fa1d5134f3
[gaim-migrate @ 13521]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11290
diff
changeset
|
489 | SPAGAIN; |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
490 | ENTER; |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
491 | SAVETMPS; |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
492 | PUSHMARK(sp); |
| 12871 | 493 | XPUSHs(sv_2mortal(gaim_perl_bless_object(plugin, |
| 494 | "Gaim::Plugin"))); | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
495 | PUTBACK; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
496 | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
497 | perl_call_pv(gps->unload_sub, G_EVAL | G_SCALAR); |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
498 | SPAGAIN; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
499 | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
500 | if (SvTRUE(ERRSV)) { |
|
6678
c633179afd00
[gaim-migrate @ 7203]
Christian Hammond <chipx86@chipx86.com>
parents:
6636
diff
changeset
|
501 | STRLEN len; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
502 | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
503 | gaim_debug(GAIM_DEBUG_ERROR, "perl", |
| 12871 | 504 | "Perl function %s exited abnormally: %s\n", |
| 505 | gps->load_sub, SvPV(ERRSV, len)); | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
506 | } |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
507 | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
508 | PUTBACK; |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
509 | FREETMPS; |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
510 | LEAVE; |
|
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 | |
| 12882 | 513 | gaim_perl_cmd_clear_for_plugin(plugin); |
|
6549
8e6ba2a45698
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6536
diff
changeset
|
514 | gaim_perl_signal_clear_for_plugin(plugin); |
|
6522
e7d94240fc71
[gaim-migrate @ 7039]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
515 | gaim_perl_timeout_clear_for_plugin(plugin); |
| 5205 | 516 | |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
517 | destroy_package(gps->package); |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
518 | |
| 5205 | 519 | return TRUE; |
| 520 | } | |
| 521 | ||
| 522 | static void | |
| 523 | destroy_perl_plugin(GaimPlugin *plugin) | |
| 524 | { | |
| 12873 | 525 | if (plugin->info != NULL) { |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
526 | GaimPerlScript *gps; |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
527 | |
| 12871 | 528 | g_free(plugin->info->name); |
| 529 | g_free(plugin->info->version); | |
| 530 | g_free(plugin->info->summary); | |
| 531 | g_free(plugin->info->description); | |
| 532 | g_free(plugin->info->author); | |
| 533 | g_free(plugin->info->homepage); | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
534 | |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
535 | gps = (GaimPerlScript *)plugin->info->extra_info; |
| 12871 | 536 | if (gps != NULL) { |
| 537 | g_free(gps->load_sub); | |
| 538 | g_free(gps->unload_sub); | |
| 539 | g_free(gps->package); | |
| 12872 | 540 | g_free(gps->prefs_sub); |
| 541 | g_free(gps->gtk_prefs_sub); | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
542 | g_free(gps); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
543 | plugin->info->extra_info = NULL; |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
544 | } |
| 5205 | 545 | } |
| 546 | } | |
| 547 | ||
| 548 | static gboolean | |
| 11033 | 549 | plugin_load(GaimPlugin *plugin) |
| 550 | { | |
| 551 | return TRUE; | |
| 552 | } | |
| 553 | ||
| 554 | static gboolean | |
| 5205 | 555 | plugin_unload(GaimPlugin *plugin) |
| 556 | { | |
| 557 | perl_end(); | |
| 558 | ||
| 559 | return TRUE; | |
| 560 | } | |
| 561 | ||
| 562 | static GaimPluginLoaderInfo loader_info = | |
| 563 | { | |
| 564 | NULL, /**< exts */ | |
| 565 | probe_perl_plugin, /**< probe */ | |
| 566 | load_perl_plugin, /**< load */ | |
| 567 | unload_perl_plugin, /**< unload */ | |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
568 | destroy_perl_plugin /**< destroy */ |
| 5205 | 569 | }; |
| 570 | ||
| 571 | static GaimPluginInfo info = | |
| 572 | { | |
| 9943 | 573 | GAIM_PLUGIN_MAGIC, |
| 574 | GAIM_MAJOR_VERSION, | |
| 575 | GAIM_MINOR_VERSION, | |
| 5205 | 576 | GAIM_PLUGIN_LOADER, /**< type */ |
| 577 | NULL, /**< ui_requirement */ | |
| 578 | 0, /**< flags */ | |
| 579 | NULL, /**< dependencies */ | |
| 580 | GAIM_PRIORITY_DEFAULT, /**< priority */ | |
| 581 | ||
| 582 | PERL_PLUGIN_ID, /**< id */ | |
| 583 | N_("Perl Plugin Loader"), /**< name */ | |
| 584 | VERSION, /**< version */ | |
| 585 | N_("Provides support for loading perl plugins."), /**< summary */ | |
| 586 | N_("Provides support for loading perl plugins."), /**< description */ | |
| 587 | "Christian Hammond <chipx86@gnupdate.org>", /**< author */ | |
|
6371
e92b66ee5518
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6235
diff
changeset
|
588 | GAIM_WEBSITE, /**< homepage */ |
| 5205 | 589 | |
| 11033 | 590 | plugin_load, /**< load */ |
| 5205 | 591 | plugin_unload, /**< unload */ |
| 592 | NULL, /**< destroy */ | |
| 593 | ||
| 594 | NULL, /**< ui_info */ | |
| 8993 | 595 | &loader_info, /**< extra_info */ |
| 596 | NULL, | |
| 597 | NULL | |
| 5205 | 598 | }; |
| 599 | ||
| 600 | static void | |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
601 | init_plugin(GaimPlugin *plugin) |
| 5205 | 602 | { |
| 603 | loader_info.exts = g_list_append(loader_info.exts, "pl"); | |
| 604 | } | |
| 605 | ||
| 6063 | 606 | GAIM_INIT_PLUGIN(perl, init_plugin, info) |