Tue, 06 May 2014 13:52:59 +0200
Backport warning fixes for perl from default
| 5205 | 1 | /* |
| 15884 | 2 | * purple |
| 5205 | 3 | * |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
4 | * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> |
| 5205 | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify | |
| 7 | * it under the terms of the GNU General Public License as published by | |
| 8 | * the Free Software Foundation; either version 2 of the License, or | |
| 9 | * (at your option) any later version. | |
| 10 | * | |
| 11 | * This program is distributed in the hope that it will be useful, | |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | * GNU General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the GNU General Public License | |
| 17 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
16786
diff
changeset
|
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 5205 | 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 | |
|
35981
e8c02ea0800b
Backport warning fixes for perl from default
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
28642
diff
changeset
|
51 | #define SILENT_NO_TAINT_SUPPORT 0 |
|
e8c02ea0800b
Backport warning fixes for perl from default
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
28642
diff
changeset
|
52 | #define NO_TAINT_SUPPORT 0 |
|
e8c02ea0800b
Backport warning fixes for perl from default
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
28642
diff
changeset
|
53 | |
| 5205 | 54 | #include <perl.h> |
| 55 | #include <XSUB.h> | |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
56 | |
| 5205 | 57 | #ifndef _WIN32 |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
58 | # include <sys/mman.h> |
| 5205 | 59 | #endif |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
60 | |
| 5205 | 61 | #undef PACKAGE |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
62 | |
| 5205 | 63 | #ifndef _WIN32 |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
64 | # include <dirent.h> |
| 5205 | 65 | #else |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
66 | /* We're using perl's win32 port of this */ |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
67 | # define dirent direct |
| 5205 | 68 | #endif |
| 69 | ||
| 70 | #undef group | |
| 71 | ||
| 72 | /* perl module support */ | |
|
23915
b62601fd6e7d
Update the Perl plugin loader to work with Perl 5.10.
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
73 | #ifdef _WIN32 |
|
b62601fd6e7d
Update the Perl plugin loader to work with Perl 5.10.
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
74 | EXTERN_C void boot_Win32CORE (pTHX_ CV* cv); |
|
b62601fd6e7d
Update the Perl plugin loader to work with Perl 5.10.
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
75 | #endif |
|
b62601fd6e7d
Update the Perl plugin loader to work with Perl 5.10.
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
76 | |
| 5205 | 77 | #ifdef OLD_PERL |
| 78 | extern void boot_DynaLoader _((CV * cv)); | |
| 79 | #else | |
| 80 | extern void boot_DynaLoader _((pTHX_ CV * cv)); /* perl is so wacky */ | |
| 81 | #endif | |
| 82 | ||
| 83 | #undef _ | |
| 84 | #ifdef DEBUG | |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
85 | # undef DEBUG |
| 5205 | 86 | #endif |
| 87 | #ifdef _WIN32 | |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
88 | # undef pipe |
| 5205 | 89 | #endif |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
90 | |
|
6575
fdb1928afdf9
[gaim-migrate @ 7097]
Herman Bloggs <herman@bluedigits.com>
parents:
6549
diff
changeset
|
91 | #ifdef _WIN32 |
|
fdb1928afdf9
[gaim-migrate @ 7097]
Herman Bloggs <herman@bluedigits.com>
parents:
6549
diff
changeset
|
92 | #define _WIN32DEP_H_ |
|
fdb1928afdf9
[gaim-migrate @ 7097]
Herman Bloggs <herman@bluedigits.com>
parents:
6549
diff
changeset
|
93 | #endif |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
94 | #include "internal.h" |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
95 | #include "debug.h" |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
96 | #include "plugin.h" |
|
6531
3fca41d7b411
[gaim-migrate @ 7048]
Christian Hammond <chipx86@chipx86.com>
parents:
6527
diff
changeset
|
97 | #include "signals.h" |
| 9943 | 98 | #include "version.h" |
| 5205 | 99 | |
|
6526
c6c3f10519ab
[gaim-migrate @ 7043]
Christian Hammond <chipx86@chipx86.com>
parents:
6525
diff
changeset
|
100 | #include "perl-common.h" |
|
6522
e7d94240fc71
[gaim-migrate @ 7039]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
101 | #include "perl-handlers.h" |
|
e7d94240fc71
[gaim-migrate @ 7039]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
102 | |
|
16529
1d0da9270ff9
This is mostly moving Purple::GtkUI:: -> Pidgin:: which has the side effect of
Etan Reisner <deryni@pidgin.im>
parents:
16528
diff
changeset
|
103 | #include <gmodule.h> |
|
1d0da9270ff9
This is mostly moving Purple::GtkUI:: -> Pidgin:: which has the side effect of
Etan Reisner <deryni@pidgin.im>
parents:
16528
diff
changeset
|
104 | |
| 5205 | 105 | #define PERL_PLUGIN_ID "core-perl" |
| 106 | ||
| 12872 | 107 | PerlInterpreter *my_perl = NULL; |
| 108 | ||
| 15884 | 109 | static PurplePluginUiInfo ui_info = |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
110 | { |
| 15884 | 111 | purple_perl_get_plugin_frame, |
| 12872 | 112 | 0, /* page_num (Reserved) */ |
|
16786
65c04c7e5c8a
Add padding to structs as necessary to silence compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16750
diff
changeset
|
113 | NULL, /* frame (Reserved) */ |
|
65c04c7e5c8a
Add padding to structs as necessary to silence compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16750
diff
changeset
|
114 | /* Padding */ |
|
65c04c7e5c8a
Add padding to structs as necessary to silence compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16750
diff
changeset
|
115 | NULL, |
|
65c04c7e5c8a
Add padding to structs as necessary to silence compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16750
diff
changeset
|
116 | NULL, |
|
65c04c7e5c8a
Add padding to structs as necessary to silence compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16750
diff
changeset
|
117 | NULL, |
|
65c04c7e5c8a
Add padding to structs as necessary to silence compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16750
diff
changeset
|
118 | NULL |
| 12872 | 119 | }; |
| 5205 | 120 | |
| 15884 | 121 | #ifdef PURPLE_GTKPERL |
| 122 | static PurpleGtkPluginUiInfo gtk_ui_info = | |
| 12872 | 123 | { |
| 15884 | 124 | purple_perl_gtk_get_plugin_frame, |
| 12872 | 125 | 0 /* page_num (Reserved) */ |
| 126 | }; | |
|
14426
8d4f164c4979
[gaim-migrate @ 17070]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
127 | #endif |
| 5205 | 128 | |
| 129 | static void | |
| 130 | #ifdef OLD_PERL | |
| 131 | xs_init() | |
| 132 | #else | |
| 133 | xs_init(pTHX) | |
| 134 | #endif | |
| 135 | { | |
| 136 | char *file = __FILE__; | |
|
27584
134e07aa6f64
Install the Purple and Pidgin perl modules under $libdir instead of in perl's
Etan Reisner <deryni@pidgin.im>
parents:
24241
diff
changeset
|
137 | GList *search_paths = purple_plugins_get_search_paths(); |
|
23915
b62601fd6e7d
Update the Perl plugin loader to work with Perl 5.10.
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
138 | dXSUB_SYS; |
| 5205 | 139 | |
| 12873 | 140 | /* This one allows dynamic loading of perl modules in perl scripts by |
| 141 | * the 'use perlmod;' construction */ | |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
142 | newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); |
|
23915
b62601fd6e7d
Update the Perl plugin loader to work with Perl 5.10.
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
143 | #ifdef _WIN32 |
|
b62601fd6e7d
Update the Perl plugin loader to work with Perl 5.10.
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
144 | newXS("Win32CORE::bootstrap", boot_Win32CORE, file); |
|
b62601fd6e7d
Update the Perl plugin loader to work with Perl 5.10.
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
145 | #endif |
|
27584
134e07aa6f64
Install the Purple and Pidgin perl modules under $libdir instead of in perl's
Etan Reisner <deryni@pidgin.im>
parents:
24241
diff
changeset
|
146 | |
|
134e07aa6f64
Install the Purple and Pidgin perl modules under $libdir instead of in perl's
Etan Reisner <deryni@pidgin.im>
parents:
24241
diff
changeset
|
147 | while (search_paths != NULL) { |
|
134e07aa6f64
Install the Purple and Pidgin perl modules under $libdir instead of in perl's
Etan Reisner <deryni@pidgin.im>
parents:
24241
diff
changeset
|
148 | gchar *uselib; |
|
134e07aa6f64
Install the Purple and Pidgin perl modules under $libdir instead of in perl's
Etan Reisner <deryni@pidgin.im>
parents:
24241
diff
changeset
|
149 | const gchar *search_path = search_paths->data; |
|
134e07aa6f64
Install the Purple and Pidgin perl modules under $libdir instead of in perl's
Etan Reisner <deryni@pidgin.im>
parents:
24241
diff
changeset
|
150 | search_paths = g_list_next(search_paths); |
|
134e07aa6f64
Install the Purple and Pidgin perl modules under $libdir instead of in perl's
Etan Reisner <deryni@pidgin.im>
parents:
24241
diff
changeset
|
151 | |
|
27664
f237942129f0
This seems to work better on Windows, what with the spaces in the path and the
Etan Reisner <deryni@pidgin.im>
parents:
27584
diff
changeset
|
152 | uselib = g_strdup_printf("unshift @INC, q(%s%sperl);", |
|
f237942129f0
This seems to work better on Windows, what with the spaces in the path and the
Etan Reisner <deryni@pidgin.im>
parents:
27584
diff
changeset
|
153 | search_path, G_DIR_SEPARATOR_S); |
|
27584
134e07aa6f64
Install the Purple and Pidgin perl modules under $libdir instead of in perl's
Etan Reisner <deryni@pidgin.im>
parents:
24241
diff
changeset
|
154 | eval_pv(uselib, TRUE); |
|
134e07aa6f64
Install the Purple and Pidgin perl modules under $libdir instead of in perl's
Etan Reisner <deryni@pidgin.im>
parents:
24241
diff
changeset
|
155 | g_free(uselib); |
|
134e07aa6f64
Install the Purple and Pidgin perl modules under $libdir instead of in perl's
Etan Reisner <deryni@pidgin.im>
parents:
24241
diff
changeset
|
156 | } |
| 5205 | 157 | } |
| 158 | ||
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
159 | static void |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
160 | perl_init(void) |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
161 | { |
| 12873 | 162 | /* changed the name of the variable from load_file to perl_definitions |
| 163 | * since now it does much more than defining the load_file sub. | |
| 164 | * Moreover, deplaced the initialisation to the xs_init function. | |
| 165 | * (TheHobbit) */ | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
166 | char *perl_args[] = { "", "-e", "0", "-w" }; |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
167 | char perl_definitions[] = |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
168 | { |
| 12873 | 169 | /* We use to function one to load a file the other to execute |
| 170 | * the string obtained from the first and holding the file | |
| 171 | * contents. This allows to have a really local $/ without | |
| 172 | * introducing temp variables to hold the old value. Just a | |
| 173 | * question of style:) */ | |
| 15884 | 174 | "package Purple::PerlLoader;" |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
175 | "use Symbol;" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
176 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
177 | "sub load_file {" |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
178 | "my $f_name=shift;" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
179 | "local $/=undef;" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
180 | "open FH,$f_name or return \"__FAILED__\";" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
181 | "$_=<FH>;" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
182 | "close FH;" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
183 | "return $_;" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
184 | "}" |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
185 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
186 | "sub destroy_package {" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
187 | "eval { $_[0]->UNLOAD() if $_[0]->can('UNLOAD'); };" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
188 | "Symbol::delete_package($_[0]);" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
189 | "}" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
190 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
191 | "sub load_n_eval {" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
192 | "my ($f_name, $package) = @_;" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
193 | "destroy_package($package);" |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
194 | "my $strin=load_file($f_name);" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
195 | "return 2 if($strin eq \"__FAILED__\");" |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
196 | "my $eval = qq{package $package; $strin;};" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
197 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
198 | "{" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
199 | " eval $eval;" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
200 | "}" |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
201 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
202 | "if($@) {" |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
203 | /*" #something went wrong\n"*/ |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
204 | "die(\"Errors loading file $f_name: $@\");" |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
205 | "}" |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
206 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
207 | "return 0;" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
208 | "}" |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
209 | }; |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
210 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
211 | my_perl = perl_alloc(); |
| 12871 | 212 | PERL_SET_CONTEXT(my_perl); |
| 11290 | 213 | PL_perl_destruct_level = 1; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
214 | perl_construct(my_perl); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
215 | #ifdef DEBUG |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
216 | perl_parse(my_perl, xs_init, 4, perl_args, NULL); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
217 | #else |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
218 | perl_parse(my_perl, xs_init, 3, perl_args, NULL); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
219 | #endif |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
220 | #ifdef HAVE_PERL_EVAL_PV |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
221 | eval_pv(perl_definitions, TRUE); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
222 | #else |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
223 | perl_eval_pv(perl_definitions, TRUE); /* deprecated */ |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
224 | #endif |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
225 | perl_run(my_perl); |
| 5205 | 226 | } |
| 227 | ||
| 228 | static void | |
| 229 | perl_end(void) | |
| 230 | { | |
|
6520
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
231 | if (my_perl == NULL) |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
232 | return; |
| 12871 | 233 | |
| 11290 | 234 | PL_perl_destruct_level = 1; |
| 12873 | 235 | PERL_SET_CONTEXT(my_perl); |
|
6520
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
236 | perl_eval_pv( |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
237 | "foreach my $lib (@DynaLoader::dl_modules) {" |
| 15884 | 238 | "if ($lib =~ /^Purple\\b/) {" |
|
6520
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
239 | "$lib .= '::deinit();';" |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
240 | "eval $lib;" |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
241 | "}" |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
242 | "}", |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
243 | TRUE); |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
244 | |
| 11290 | 245 | PL_perl_destruct_level = 1; |
| 12871 | 246 | PERL_SET_CONTEXT(my_perl); |
|
6520
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
247 | perl_destruct(my_perl); |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
248 | perl_free(my_perl); |
|
5386692555c9
[gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
6508
diff
changeset
|
249 | my_perl = NULL; |
| 5205 | 250 | } |
| 251 | ||
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
252 | void |
| 15884 | 253 | purple_perl_callXS(void (*subaddr)(pTHX_ CV *cv), CV *cv, SV **mark) |
| 5205 | 254 | { |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
255 | dSP; |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
256 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
257 | PUSHMARK(mark); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
258 | (*subaddr)(aTHX_ cv); |
| 5205 | 259 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
260 | PUTBACK; |
| 5205 | 261 | } |
| 262 | ||
| 263 | static gboolean | |
| 15884 | 264 | probe_perl_plugin(PurplePlugin *plugin) |
| 5205 | 265 | { |
| 12871 | 266 | |
|
23915
b62601fd6e7d
Update the Perl plugin loader to work with Perl 5.10.
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
267 | char *args[] = {"", plugin->path }; |
|
b62601fd6e7d
Update the Perl plugin loader to work with Perl 5.10.
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
268 | char **argv = args; |
|
23932
806fd6e850ed
Add error handling for visiblity to why Perl plugins fail to load.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
269 | int argc = 2, ret; |
|
23915
b62601fd6e7d
Update the Perl plugin loader to work with Perl 5.10.
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
270 | PerlInterpreter *prober; |
| 5205 | 271 | gboolean status = TRUE; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
272 | HV *plugin_info; |
|
23915
b62601fd6e7d
Update the Perl plugin loader to work with Perl 5.10.
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
273 | |
|
b62601fd6e7d
Update the Perl plugin loader to work with Perl 5.10.
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
274 | PERL_SYS_INIT(&argc, &argv); |
|
b62601fd6e7d
Update the Perl plugin loader to work with Perl 5.10.
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
275 | |
|
b62601fd6e7d
Update the Perl plugin loader to work with Perl 5.10.
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
276 | /* XXX This would be much faster if we didn't create a new |
|
b62601fd6e7d
Update the Perl plugin loader to work with Perl 5.10.
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
277 | * PerlInterpreter every time we probe a plugin */ |
|
b62601fd6e7d
Update the Perl plugin loader to work with Perl 5.10.
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
278 | prober = perl_alloc(); |
|
b62601fd6e7d
Update the Perl plugin loader to work with Perl 5.10.
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
279 | |
| 12871 | 280 | PERL_SET_CONTEXT(prober); |
|
23915
b62601fd6e7d
Update the Perl plugin loader to work with Perl 5.10.
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
281 | |
| 11290 | 282 | PL_perl_destruct_level = 1; |
| 5205 | 283 | perl_construct(prober); |
| 11290 | 284 | |
|
23917
8555374207d8
Fix output redirection for perl plugins on win32.
Daniel Atallah <datallah@pidgin.im>
parents:
23915
diff
changeset
|
285 | /* Fix IO redirection to match where pidgin's is going. |
|
8555374207d8
Fix output redirection for perl plugins on win32.
Daniel Atallah <datallah@pidgin.im>
parents:
23915
diff
changeset
|
286 | * Without this, we lose stdout/stderr unless we redirect to a file */ |
|
8555374207d8
Fix output redirection for perl plugins on win32.
Daniel Atallah <datallah@pidgin.im>
parents:
23915
diff
changeset
|
287 | #ifdef _WIN32 |
|
8555374207d8
Fix output redirection for perl plugins on win32.
Daniel Atallah <datallah@pidgin.im>
parents:
23915
diff
changeset
|
288 | { |
|
8555374207d8
Fix output redirection for perl plugins on win32.
Daniel Atallah <datallah@pidgin.im>
parents:
23915
diff
changeset
|
289 | PerlIO* newprlIO = PerlIO_open("CONOUT$", "w"); |
|
8555374207d8
Fix output redirection for perl plugins on win32.
Daniel Atallah <datallah@pidgin.im>
parents:
23915
diff
changeset
|
290 | if (newprlIO) { |
|
8555374207d8
Fix output redirection for perl plugins on win32.
Daniel Atallah <datallah@pidgin.im>
parents:
23915
diff
changeset
|
291 | int stdout_fd = PerlIO_fileno(PerlIO_stdout()); |
|
8555374207d8
Fix output redirection for perl plugins on win32.
Daniel Atallah <datallah@pidgin.im>
parents:
23915
diff
changeset
|
292 | int stderr_fd = PerlIO_fileno(PerlIO_stderr()); |
|
8555374207d8
Fix output redirection for perl plugins on win32.
Daniel Atallah <datallah@pidgin.im>
parents:
23915
diff
changeset
|
293 | PerlIO_close(PerlIO_stdout()); |
|
8555374207d8
Fix output redirection for perl plugins on win32.
Daniel Atallah <datallah@pidgin.im>
parents:
23915
diff
changeset
|
294 | PerlIO_close(PerlIO_stderr()); |
|
8555374207d8
Fix output redirection for perl plugins on win32.
Daniel Atallah <datallah@pidgin.im>
parents:
23915
diff
changeset
|
295 | PerlLIO_dup2(PerlIO_fileno(newprlIO), stdout_fd); |
|
8555374207d8
Fix output redirection for perl plugins on win32.
Daniel Atallah <datallah@pidgin.im>
parents:
23915
diff
changeset
|
296 | PerlLIO_dup2(PerlIO_fileno(newprlIO), stderr_fd); |
|
8555374207d8
Fix output redirection for perl plugins on win32.
Daniel Atallah <datallah@pidgin.im>
parents:
23915
diff
changeset
|
297 | |
|
8555374207d8
Fix output redirection for perl plugins on win32.
Daniel Atallah <datallah@pidgin.im>
parents:
23915
diff
changeset
|
298 | PerlIO_close(newprlIO); |
|
8555374207d8
Fix output redirection for perl plugins on win32.
Daniel Atallah <datallah@pidgin.im>
parents:
23915
diff
changeset
|
299 | } |
|
8555374207d8
Fix output redirection for perl plugins on win32.
Daniel Atallah <datallah@pidgin.im>
parents:
23915
diff
changeset
|
300 | } |
|
8555374207d8
Fix output redirection for perl plugins on win32.
Daniel Atallah <datallah@pidgin.im>
parents:
23915
diff
changeset
|
301 | #endif |
|
8555374207d8
Fix output redirection for perl plugins on win32.
Daniel Atallah <datallah@pidgin.im>
parents:
23915
diff
changeset
|
302 | |
|
23932
806fd6e850ed
Add error handling for visiblity to why Perl plugins fail to load.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
303 | ret = perl_parse(prober, xs_init, argc, argv, NULL); |
|
806fd6e850ed
Add error handling for visiblity to why Perl plugins fail to load.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
304 | |
|
806fd6e850ed
Add error handling for visiblity to why Perl plugins fail to load.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
305 | if (ret != 0) { |
|
806fd6e850ed
Add error handling for visiblity to why Perl plugins fail to load.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
306 | const char * errmsg = "Unknown error"; |
|
806fd6e850ed
Add error handling for visiblity to why Perl plugins fail to load.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
307 | if (SvTRUE(ERRSV)) |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23932
diff
changeset
|
308 | errmsg = SvPVutf8_nolen(ERRSV); |
|
23932
806fd6e850ed
Add error handling for visiblity to why Perl plugins fail to load.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
309 | purple_debug_error("perl", "Unable to parse plugin %s (%d:%s)\n", |
|
806fd6e850ed
Add error handling for visiblity to why Perl plugins fail to load.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
310 | plugin->path, ret, errmsg); |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23932
diff
changeset
|
311 | status = FALSE; |
|
23932
806fd6e850ed
Add error handling for visiblity to why Perl plugins fail to load.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
312 | goto cleanup; |
|
806fd6e850ed
Add error handling for visiblity to why Perl plugins fail to load.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
313 | } |
| 11290 | 314 | |
|
23932
806fd6e850ed
Add error handling for visiblity to why Perl plugins fail to load.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
315 | ret = perl_run(prober); |
|
806fd6e850ed
Add error handling for visiblity to why Perl plugins fail to load.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
316 | |
|
806fd6e850ed
Add error handling for visiblity to why Perl plugins fail to load.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
317 | if (ret != 0) { |
|
806fd6e850ed
Add error handling for visiblity to why Perl plugins fail to load.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
318 | const char * errmsg = "Unknown error"; |
|
806fd6e850ed
Add error handling for visiblity to why Perl plugins fail to load.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
319 | if (SvTRUE(ERRSV)) |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23932
diff
changeset
|
320 | errmsg = SvPVutf8_nolen(ERRSV); |
|
23932
806fd6e850ed
Add error handling for visiblity to why Perl plugins fail to load.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
321 | purple_debug_error("perl", "Unable to run perl interpreter on plugin %s (%d:%s)\n", |
|
806fd6e850ed
Add error handling for visiblity to why Perl plugins fail to load.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
322 | plugin->path, ret, errmsg); |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23932
diff
changeset
|
323 | status = FALSE; |
|
23932
806fd6e850ed
Add error handling for visiblity to why Perl plugins fail to load.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
324 | goto cleanup; |
|
806fd6e850ed
Add error handling for visiblity to why Perl plugins fail to load.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
325 | } |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
326 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
327 | plugin_info = perl_get_hv("PLUGIN_INFO", FALSE); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
328 | |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
329 | if (plugin_info == NULL) |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
330 | status = FALSE; |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
331 | else if (!hv_exists(plugin_info, "perl_api_version", |
| 12871 | 332 | strlen("perl_api_version")) || |
| 333 | !hv_exists(plugin_info, "name", strlen("name")) || | |
| 334 | !hv_exists(plugin_info, "load", strlen("load"))) { | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
335 | /* Not a valid plugin. */ |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
336 | |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
337 | status = FALSE; |
| 12871 | 338 | } else { |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
339 | SV **key; |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
340 | int perl_api_ver; |
| 5205 | 341 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
342 | key = hv_fetch(plugin_info, "perl_api_version", |
| 12873 | 343 | strlen("perl_api_version"), 0); |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
344 | |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
345 | perl_api_ver = SvIV(*key); |
| 5205 | 346 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
347 | if (perl_api_ver != 2) |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
348 | status = FALSE; |
| 12871 | 349 | else { |
| 15884 | 350 | PurplePluginInfo *info; |
| 351 | PurplePerlScript *gps; | |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
352 | char *basename; |
| 5205 | 353 | |
| 15884 | 354 | info = g_new0(PurplePluginInfo, 1); |
| 355 | gps = g_new0(PurplePerlScript, 1); | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
356 | |
| 15884 | 357 | info->magic = PURPLE_PLUGIN_MAGIC; |
| 358 | info->major_version = PURPLE_MAJOR_VERSION; | |
| 359 | info->minor_version = PURPLE_MINOR_VERSION; | |
| 360 | info->type = PURPLE_PLUGIN_STANDARD; | |
| 5205 | 361 | |
| 362 | info->dependencies = g_list_append(info->dependencies, | |
| 12871 | 363 | PERL_PLUGIN_ID); |
| 5205 | 364 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
365 | gps->plugin = plugin; |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
366 | |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
367 | basename = g_path_get_basename(plugin->path); |
| 15884 | 368 | purple_perl_normalize_script_name(basename); |
| 369 | gps->package = g_strdup_printf("Purple::Script::%s", | |
| 12871 | 370 | basename); |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
371 | g_free(basename); |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
372 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
373 | /* We know this one exists. */ |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
374 | key = hv_fetch(plugin_info, "name", strlen("name"), 0); |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23932
diff
changeset
|
375 | info->name = g_strdup(SvPVutf8_nolen(*key)); |
| 12984 | 376 | /* Set id here in case we don't find one later. */ |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23932
diff
changeset
|
377 | info->id = g_strdup(info->name); |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
378 | |
| 15884 | 379 | #ifdef PURPLE_GTKPERL |
| 12871 | 380 | if ((key = hv_fetch(plugin_info, "GTK_UI", |
| 381 | strlen("GTK_UI"), 0))) | |
| 15884 | 382 | info->ui_requirement = PURPLE_GTK_PLUGIN_TYPE; |
| 14434 | 383 | #endif |
| 11170 | 384 | |
| 12871 | 385 | if ((key = hv_fetch(plugin_info, "url", |
| 386 | strlen("url"), 0))) | |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23932
diff
changeset
|
387 | info->homepage = g_strdup(SvPVutf8_nolen(*key)); |
| 12873 | 388 | |
| 12871 | 389 | if ((key = hv_fetch(plugin_info, "author", |
| 390 | strlen("author"), 0))) | |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23932
diff
changeset
|
391 | info->author = g_strdup(SvPVutf8_nolen(*key)); |
| 5205 | 392 | |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
393 | if ((key = hv_fetch(plugin_info, "summary", |
| 12871 | 394 | strlen("summary"), 0))) |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23932
diff
changeset
|
395 | info->summary = g_strdup(SvPVutf8_nolen(*key)); |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
396 | |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
397 | if ((key = hv_fetch(plugin_info, "description", |
| 12871 | 398 | strlen("description"), 0))) |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23932
diff
changeset
|
399 | info->description = g_strdup(SvPVutf8_nolen(*key)); |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
400 | |
| 12871 | 401 | if ((key = hv_fetch(plugin_info, "version", |
| 402 | strlen("version"), 0))) | |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23932
diff
changeset
|
403 | info->version = g_strdup(SvPVutf8_nolen(*key)); |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
404 | |
| 12984 | 405 | /* We know this one exists. */ |
| 406 | key = hv_fetch(plugin_info, "load", strlen("load"), 0); | |
| 407 | gps->load_sub = g_strdup_printf("%s::%s", gps->package, | |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23932
diff
changeset
|
408 | SvPVutf8_nolen(*key)); |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
409 | |
| 12871 | 410 | if ((key = hv_fetch(plugin_info, "unload", |
| 411 | strlen("unload"), 0))) | |
| 412 | gps->unload_sub = g_strdup_printf("%s::%s", | |
| 413 | gps->package, | |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23932
diff
changeset
|
414 | SvPVutf8_nolen(*key)); |
| 5205 | 415 | |
| 12984 | 416 | if ((key = hv_fetch(plugin_info, "id", |
| 417 | strlen("id"), 0))) { | |
| 418 | g_free(info->id); | |
| 419 | info->id = g_strdup_printf("perl-%s", | |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23932
diff
changeset
|
420 | SvPVutf8_nolen(*key)); |
| 12984 | 421 | } |
| 422 | ||
| 12871 | 423 | /********************************************************/ |
| 424 | /* Only one of the next two options should be present */ | |
| 425 | /* */ | |
| 15884 | 426 | /* prefs_info - Uses non-GUI (read GTK) purple API calls */ |
| 427 | /* and creates a PurplePluginPrefInfo type. */ | |
| 12871 | 428 | /* */ |
| 429 | /* gtk_prefs_info - Requires gtk2-perl be installed by */ | |
| 12873 | 430 | /* the user and he must create a */ |
| 431 | /* GtkWidget the user and he must */ | |
| 432 | /* create a GtkWidget representing the */ | |
| 433 | /* plugin preferences page. */ | |
| 12871 | 434 | /********************************************************/ |
| 435 | if ((key = hv_fetch(plugin_info, "prefs_info", | |
| 436 | strlen("prefs_info"), 0))) { | |
| 437 | /* key now is the name of the Perl sub that | |
| 438 | * will create a frame for us */ | |
| 12872 | 439 | gps->prefs_sub = g_strdup_printf("%s::%s", |
| 440 | gps->package, | |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23932
diff
changeset
|
441 | SvPVutf8_nolen(*key)); |
| 12872 | 442 | info->prefs_info = &ui_info; |
| 11123 | 443 | } |
| 12890 | 444 | |
| 15884 | 445 | #ifdef PURPLE_GTKPERL |
| 12871 | 446 | if ((key = hv_fetch(plugin_info, "gtk_prefs_info", |
| 447 | strlen("gtk_prefs_info"), 0))) { | |
| 448 | /* key now is the name of the Perl sub that | |
| 449 | * will create a frame for us */ | |
| 12872 | 450 | gps->gtk_prefs_sub = g_strdup_printf("%s::%s", |
| 451 | gps->package, | |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23932
diff
changeset
|
452 | SvPVutf8_nolen(*key)); |
| 12872 | 453 | info->ui_info = >k_ui_info; |
| 11170 | 454 | } |
|
14426
8d4f164c4979
[gaim-migrate @ 17070]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
455 | #endif |
| 11170 | 456 | |
| 12988 | 457 | if ((key = hv_fetch(plugin_info, "plugin_action_sub", |
| 458 | strlen("plugin_action_sub"), 0))) { | |
| 459 | gps->plugin_action_sub = g_strdup_printf("%s::%s", | |
| 460 | gps->package, | |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23932
diff
changeset
|
461 | SvPVutf8_nolen(*key)); |
| 15884 | 462 | info->actions = purple_perl_plugin_actions; |
| 11170 | 463 | } |
| 11123 | 464 | |
| 5205 | 465 | plugin->info = info; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
466 | info->extra_info = gps; |
| 5205 | 467 | |
| 15884 | 468 | status = purple_plugin_register(plugin); |
| 5205 | 469 | } |
| 470 | } | |
| 12871 | 471 | |
|
23932
806fd6e850ed
Add error handling for visiblity to why Perl plugins fail to load.
Daniel Atallah <datallah@pidgin.im>
parents:
23930
diff
changeset
|
472 | cleanup: |
| 11290 | 473 | PL_perl_destruct_level = 1; |
| 12871 | 474 | PERL_SET_CONTEXT(prober); |
| 5205 | 475 | perl_destruct(prober); |
| 476 | perl_free(prober); | |
| 477 | return status; | |
| 478 | } | |
| 479 | ||
| 480 | static gboolean | |
| 15884 | 481 | load_perl_plugin(PurplePlugin *plugin) |
| 5205 | 482 | { |
| 15884 | 483 | PurplePerlScript *gps = (PurplePerlScript *)plugin->info->extra_info; |
|
24241
e6fc766f3e91
Return FALSE when a perl plugin cannot be loaded.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
23980
diff
changeset
|
484 | gboolean loaded = TRUE; |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
485 | char *atmp[3] = { plugin->path, NULL, NULL }; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
486 | |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
487 | if (gps == NULL || gps->load_sub == NULL) |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
488 | return FALSE; |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
489 | |
| 15884 | 490 | purple_debug(PURPLE_DEBUG_INFO, "perl", "Loading perl script\n"); |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
491 | |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
492 | if (my_perl == NULL) |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
493 | perl_init(); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
494 | |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
495 | plugin->handle = gps; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
496 | |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
497 | atmp[1] = gps->package; |
| 12871 | 498 | |
| 499 | PERL_SET_CONTEXT(my_perl); | |
| 15884 | 500 | execute_perl("Purple::PerlLoader::load_n_eval", 2, atmp); |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
501 | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
502 | { |
|
11318
13fa1d5134f3
[gaim-migrate @ 13521]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11290
diff
changeset
|
503 | dSP; |
| 11290 | 504 | PERL_SET_CONTEXT(my_perl); |
|
11318
13fa1d5134f3
[gaim-migrate @ 13521]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11290
diff
changeset
|
505 | SPAGAIN; |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
506 | ENTER; |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
507 | SAVETMPS; |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
508 | PUSHMARK(sp); |
| 15884 | 509 | XPUSHs(sv_2mortal(purple_perl_bless_object(plugin, |
| 510 | "Purple::Plugin"))); | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
511 | PUTBACK; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
512 | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
513 | perl_call_pv(gps->load_sub, G_EVAL | G_SCALAR); |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
514 | SPAGAIN; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
515 | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
516 | if (SvTRUE(ERRSV)) { |
| 15884 | 517 | purple_debug(PURPLE_DEBUG_ERROR, "perl", |
| 12871 | 518 | "Perl function %s exited abnormally: %s\n", |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23932
diff
changeset
|
519 | gps->load_sub, SvPVutf8_nolen(ERRSV)); |
|
24241
e6fc766f3e91
Return FALSE when a perl plugin cannot be loaded.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
23980
diff
changeset
|
520 | loaded = FALSE; |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
521 | } |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
522 | |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
523 | PUTBACK; |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
524 | FREETMPS; |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
525 | LEAVE; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
526 | } |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
527 | |
|
24241
e6fc766f3e91
Return FALSE when a perl plugin cannot be loaded.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
23980
diff
changeset
|
528 | return loaded; |
| 5205 | 529 | } |
| 530 | ||
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
531 | static void |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
532 | destroy_package(const char *package) |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
533 | { |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
534 | dSP; |
|
11318
13fa1d5134f3
[gaim-migrate @ 13521]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11290
diff
changeset
|
535 | PERL_SET_CONTEXT(my_perl); |
|
13fa1d5134f3
[gaim-migrate @ 13521]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11290
diff
changeset
|
536 | SPAGAIN; |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
537 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
538 | ENTER; |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
539 | SAVETMPS; |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
540 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
541 | PUSHMARK(SP); |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23932
diff
changeset
|
542 | XPUSHs(sv_2mortal(newSVpv(package, 0))); |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
543 | PUTBACK; |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
544 | |
| 15884 | 545 | perl_call_pv("Purple::PerlLoader::destroy_package", |
| 12871 | 546 | G_VOID | G_EVAL | G_DISCARD); |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
547 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
548 | SPAGAIN; |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
549 | |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
550 | PUTBACK; |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
551 | FREETMPS; |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
552 | LEAVE; |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
553 | } |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
554 | |
| 5205 | 555 | static gboolean |
| 15884 | 556 | unload_perl_plugin(PurplePlugin *plugin) |
| 5205 | 557 | { |
| 15884 | 558 | PurplePerlScript *gps = (PurplePerlScript *)plugin->info->extra_info; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
559 | |
|
9578
d02c3d247fb7
[gaim-migrate @ 10421]
Christian Hammond <chipx86@chipx86.com>
parents:
8993
diff
changeset
|
560 | if (gps == NULL) |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
561 | return FALSE; |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
562 | |
| 15884 | 563 | purple_debug(PURPLE_DEBUG_INFO, "perl", "Unloading perl script\n"); |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
564 | |
| 12871 | 565 | if (gps->unload_sub != NULL) { |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
566 | dSP; |
|
11318
13fa1d5134f3
[gaim-migrate @ 13521]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11290
diff
changeset
|
567 | PERL_SET_CONTEXT(my_perl); |
|
13fa1d5134f3
[gaim-migrate @ 13521]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11290
diff
changeset
|
568 | SPAGAIN; |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
569 | ENTER; |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
570 | SAVETMPS; |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
571 | PUSHMARK(sp); |
| 15884 | 572 | XPUSHs(sv_2mortal(purple_perl_bless_object(plugin, |
| 573 | "Purple::Plugin"))); | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
574 | PUTBACK; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
575 | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
576 | perl_call_pv(gps->unload_sub, G_EVAL | G_SCALAR); |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
577 | SPAGAIN; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
578 | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
579 | if (SvTRUE(ERRSV)) { |
| 15884 | 580 | purple_debug(PURPLE_DEBUG_ERROR, "perl", |
| 12871 | 581 | "Perl function %s exited abnormally: %s\n", |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23932
diff
changeset
|
582 | gps->unload_sub, SvPVutf8_nolen(ERRSV)); |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
583 | } |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
584 | |
|
6536
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
585 | PUTBACK; |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
586 | FREETMPS; |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
587 | LEAVE; |
|
b91ae5d45371
[gaim-migrate @ 7053]
Christian Hammond <chipx86@chipx86.com>
parents:
6531
diff
changeset
|
588 | } |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
589 | |
| 15884 | 590 | purple_perl_cmd_clear_for_plugin(plugin); |
| 591 | purple_perl_signal_clear_for_plugin(plugin); | |
| 592 | purple_perl_timeout_clear_for_plugin(plugin); | |
|
23930
c1c3d7cab338
Add support to the Perl plugin loader for listing for pref changes.
Daniel Atallah <datallah@pidgin.im>
parents:
23917
diff
changeset
|
593 | purple_perl_pref_cb_clear_for_plugin(plugin); |
| 5205 | 594 | |
|
6636
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
595 | destroy_package(gps->package); |
|
e906c663da5c
[gaim-migrate @ 7161]
Christian Hammond <chipx86@chipx86.com>
parents:
6575
diff
changeset
|
596 | |
| 5205 | 597 | return TRUE; |
| 598 | } | |
| 599 | ||
| 600 | static void | |
| 15884 | 601 | destroy_perl_plugin(PurplePlugin *plugin) |
| 5205 | 602 | { |
| 12873 | 603 | if (plugin->info != NULL) { |
| 15884 | 604 | PurplePerlScript *gps; |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
605 | |
| 12871 | 606 | g_free(plugin->info->name); |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23932
diff
changeset
|
607 | g_free(plugin->info->id); |
|
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23932
diff
changeset
|
608 | g_free(plugin->info->homepage); |
|
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23932
diff
changeset
|
609 | g_free(plugin->info->author); |
| 12871 | 610 | g_free(plugin->info->summary); |
| 611 | g_free(plugin->info->description); | |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23932
diff
changeset
|
612 | g_free(plugin->info->version); |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
613 | |
| 15884 | 614 | gps = (PurplePerlScript *)plugin->info->extra_info; |
| 12871 | 615 | if (gps != NULL) { |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23932
diff
changeset
|
616 | g_free(gps->package); |
| 12871 | 617 | g_free(gps->load_sub); |
| 618 | g_free(gps->unload_sub); | |
| 12872 | 619 | g_free(gps->prefs_sub); |
| 15884 | 620 | #ifdef PURPLE_GTKPERL |
| 12872 | 621 | g_free(gps->gtk_prefs_sub); |
|
14426
8d4f164c4979
[gaim-migrate @ 17070]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
622 | #endif |
|
23980
a38cbb35eecf
Some cleanup and a couple leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
23932
diff
changeset
|
623 | g_free(gps->plugin_action_sub); |
|
6508
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
624 | g_free(gps); |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
625 | plugin->info->extra_info = NULL; |
|
57d1df1ca3a0
[gaim-migrate @ 7025]
Christian Hammond <chipx86@chipx86.com>
parents:
6485
diff
changeset
|
626 | } |
|
28642
b23df5d1387e
Leak fix for perl plugins.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
27664
diff
changeset
|
627 | |
|
b23df5d1387e
Leak fix for perl plugins.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
27664
diff
changeset
|
628 | g_free(plugin->info); |
|
b23df5d1387e
Leak fix for perl plugins.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
27664
diff
changeset
|
629 | plugin->info = NULL; |
| 5205 | 630 | } |
| 631 | } | |
| 632 | ||
| 633 | static gboolean | |
| 15884 | 634 | plugin_load(PurplePlugin *plugin) |
| 11033 | 635 | { |
| 636 | return TRUE; | |
| 637 | } | |
| 638 | ||
| 639 | static gboolean | |
| 15884 | 640 | plugin_unload(PurplePlugin *plugin) |
| 5205 | 641 | { |
| 642 | perl_end(); | |
| 643 | ||
| 644 | return TRUE; | |
| 645 | } | |
| 646 | ||
| 15884 | 647 | static PurplePluginLoaderInfo loader_info = |
| 5205 | 648 | { |
| 649 | NULL, /**< exts */ | |
| 650 | probe_perl_plugin, /**< probe */ | |
| 651 | load_perl_plugin, /**< load */ | |
| 652 | unload_perl_plugin, /**< unload */ | |
|
16750
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
16529
diff
changeset
|
653 | destroy_perl_plugin, /**< destroy */ |
|
23915
b62601fd6e7d
Update the Perl plugin loader to work with Perl 5.10.
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
654 | |
|
16750
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
16529
diff
changeset
|
655 | /* padding */ |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
16529
diff
changeset
|
656 | NULL, |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
16529
diff
changeset
|
657 | NULL, |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
16529
diff
changeset
|
658 | NULL, |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
16529
diff
changeset
|
659 | NULL |
| 5205 | 660 | }; |
| 661 | ||
| 15884 | 662 | static PurplePluginInfo info = |
| 5205 | 663 | { |
| 15884 | 664 | PURPLE_PLUGIN_MAGIC, |
| 665 | PURPLE_MAJOR_VERSION, | |
| 666 | PURPLE_MINOR_VERSION, | |
|
16529
1d0da9270ff9
This is mostly moving Purple::GtkUI:: -> Pidgin:: which has the side effect of
Etan Reisner <deryni@pidgin.im>
parents:
16528
diff
changeset
|
667 | PURPLE_PLUGIN_LOADER, /**< type */ |
| 5205 | 668 | NULL, /**< ui_requirement */ |
| 669 | 0, /**< flags */ | |
| 670 | NULL, /**< dependencies */ | |
|
16529
1d0da9270ff9
This is mostly moving Purple::GtkUI:: -> Pidgin:: which has the side effect of
Etan Reisner <deryni@pidgin.im>
parents:
16528
diff
changeset
|
671 | PURPLE_PRIORITY_DEFAULT, /**< priority */ |
| 5205 | 672 | |
| 673 | PERL_PLUGIN_ID, /**< id */ | |
| 674 | N_("Perl Plugin Loader"), /**< name */ | |
|
20288
5ca925a094e2
applied changes from 03b709ec2a153e7e82719df0ba4635108bb1d3c6
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
675 | DISPLAY_VERSION, /**< version */ |
| 5205 | 676 | N_("Provides support for loading perl plugins."), /**< summary */ |
| 677 | N_("Provides support for loading perl plugins."), /**< description */ | |
| 678 | "Christian Hammond <chipx86@gnupdate.org>", /**< author */ | |
|
16529
1d0da9270ff9
This is mostly moving Purple::GtkUI:: -> Pidgin:: which has the side effect of
Etan Reisner <deryni@pidgin.im>
parents:
16528
diff
changeset
|
679 | PURPLE_WEBSITE, /**< homepage */ |
| 5205 | 680 | |
| 11033 | 681 | plugin_load, /**< load */ |
| 5205 | 682 | plugin_unload, /**< unload */ |
| 683 | NULL, /**< destroy */ | |
| 684 | ||
| 685 | NULL, /**< ui_info */ | |
| 8993 | 686 | &loader_info, /**< extra_info */ |
| 687 | NULL, | |
|
16750
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
16529
diff
changeset
|
688 | NULL, |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
16529
diff
changeset
|
689 | |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
16529
diff
changeset
|
690 | /* padding */ |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
16529
diff
changeset
|
691 | NULL, |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
16529
diff
changeset
|
692 | NULL, |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
16529
diff
changeset
|
693 | NULL, |
| 8993 | 694 | NULL |
| 5205 | 695 | }; |
| 696 | ||
| 697 | static void | |
| 15884 | 698 | init_plugin(PurplePlugin *plugin) |
| 5205 | 699 | { |
| 700 | loader_info.exts = g_list_append(loader_info.exts, "pl"); | |
| 701 | } | |
| 702 | ||
|
16528
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
703 | #ifdef __SUNPRO_C |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
704 | #pragma init (my_init) |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
705 | #else |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
706 | void __attribute__ ((constructor)) my_init(void); |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
707 | #endif |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
708 | |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
709 | void |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
710 | my_init(void) |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
711 | { |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
712 | /* Mostly evil hack... puts perl.so's symbols in the global table but |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
713 | * does not create a circular dependency because g_module_open will |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
714 | * only open the library once. */ |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
715 | /* Do we need to keep track of the returned GModule here so that we |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
716 | * can g_module_close it when this plugin gets unloaded? |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
717 | * At the moment I don't think this plugin can ever get unloaded but |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
718 | * in case that becomes possible this wants to get noted. */ |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
719 | g_module_open("perl.so", 0); |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
720 | } |
|
6cd4a90e0970
Kill the libpurpleperl hack library and move the init stuff to perl.so itself.
Etan Reisner <deryni@pidgin.im>
parents:
15884
diff
changeset
|
721 | |
| 15884 | 722 | PURPLE_INIT_PLUGIN(perl, init_plugin, info) |