Mercurial > pidgin.yaz
annotate plugins/perl/perl-handlers.c @ 8669:06dd136238ab
[gaim-migrate @ 9421]
Make MSN not auto-reconnect if you sign on from elsewhere.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Fri, 16 Apr 2004 01:46:02 +0000 |
parents | 414c701ef1ff |
children | 4315bb5f427b |
rev | line source |
---|---|
6520 | 1 #include "perl-common.h" |
2 #include "perl-handlers.h" | |
3 | |
4 #include "debug.h" | |
6549
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
5 #include "signals.h" |
6520 | 6 |
7 static GList *timeout_handlers = NULL; | |
6549
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
8 static GList *signal_handlers = NULL; |
6520 | 9 |
10 extern PerlInterpreter *my_perl; | |
11 | |
12 static void | |
13 destroy_timeout_handler(GaimPerlTimeoutHandler *handler) | |
14 { | |
15 timeout_handlers = g_list_remove(timeout_handlers, handler); | |
16 | |
6568
33486b749aa9
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
17 if (handler->callback != NULL) |
33486b749aa9
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
18 SvREFCNT_dec(handler->callback); |
33486b749aa9
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
19 |
33486b749aa9
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
20 if (handler->data != NULL) |
33486b749aa9
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
21 SvREFCNT_dec(handler->data); |
33486b749aa9
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
22 |
6520 | 23 g_free(handler); |
24 } | |
25 | |
6549
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
26 static void |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
27 destroy_signal_handler(GaimPerlSignalHandler *handler) |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
28 { |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
29 signal_handlers = g_list_remove(signal_handlers, handler); |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
30 |
6567
6e25e1e08ffb
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
31 if (handler->callback != NULL) |
6e25e1e08ffb
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
32 SvREFCNT_dec(handler->callback); |
6e25e1e08ffb
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
33 |
6e25e1e08ffb
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
34 if (handler->data != NULL) |
6e25e1e08ffb
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
35 SvREFCNT_dec(handler->data); |
6e25e1e08ffb
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
36 |
6549
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
37 g_free(handler->signal); |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
38 g_free(handler); |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
39 } |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
40 |
6520 | 41 static int |
42 perl_timeout_cb(gpointer data) | |
43 { | |
44 GaimPerlTimeoutHandler *handler = (GaimPerlTimeoutHandler *)data; | |
45 | |
46 dSP; | |
47 ENTER; | |
48 SAVETMPS; | |
49 PUSHMARK(sp); | |
6568
33486b749aa9
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
50 XPUSHs((SV *)handler->data); |
6520 | 51 PUTBACK; |
6568
33486b749aa9
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
52 call_sv(handler->callback, G_EVAL | G_SCALAR); |
6520 | 53 SPAGAIN; |
54 | |
55 PUTBACK; | |
56 FREETMPS; | |
57 LEAVE; | |
58 | |
59 destroy_timeout_handler(handler); | |
60 | |
61 return 0; | |
62 } | |
63 | |
6921
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
64 typedef void *DATATYPE; |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
65 |
6549
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
66 static void * |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
67 perl_signal_cb(va_list args, void *data) |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
68 { |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
69 GaimPerlSignalHandler *handler = (GaimPerlSignalHandler *)data; |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
70 void *ret_val = NULL; |
6566
f6c2a7b5afa7
[gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents:
6554
diff
changeset
|
71 int i; |
6549
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
72 int count; |
6566
f6c2a7b5afa7
[gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents:
6554
diff
changeset
|
73 int value_count; |
f6c2a7b5afa7
[gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents:
6554
diff
changeset
|
74 GaimValue *ret_value, **values; |
6919
1aa771990188
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
75 SV **sv_args; |
6921
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
76 DATATYPE **copy_args; |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
77 STRLEN na; |
6549
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
78 |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
79 dSP; |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
80 ENTER; |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
81 SAVETMPS; |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
82 PUSHMARK(sp); |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
83 |
6566
f6c2a7b5afa7
[gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents:
6554
diff
changeset
|
84 gaim_signal_get_values(handler->instance, handler->signal, |
f6c2a7b5afa7
[gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents:
6554
diff
changeset
|
85 &ret_value, &value_count, &values); |
f6c2a7b5afa7
[gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents:
6554
diff
changeset
|
86 |
6921
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
87 sv_args = g_new(SV *, value_count); |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
88 copy_args = g_new(void **, value_count); |
6919
1aa771990188
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
89 |
6566
f6c2a7b5afa7
[gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents:
6554
diff
changeset
|
90 for (i = 0; i < value_count; i++) |
f6c2a7b5afa7
[gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents:
6554
diff
changeset
|
91 { |
6921
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
92 sv_args[i] = sv_2mortal(gaim_perl_sv_from_vargs(values[i], |
7386 | 93 (va_list*)&args, ©_args[i])); |
6549
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
94 |
6920
13f78c350cd3
[gaim-migrate @ 7467]
Christian Hammond <chipx86@chipx86.com>
parents:
6919
diff
changeset
|
95 XPUSHs(sv_args[i]); |
6566
f6c2a7b5afa7
[gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents:
6554
diff
changeset
|
96 } |
f6c2a7b5afa7
[gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents:
6554
diff
changeset
|
97 |
6549
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
98 XPUSHs((SV *)handler->data); |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
99 |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
100 PUTBACK; |
6567
6e25e1e08ffb
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
101 |
6e25e1e08ffb
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
102 if (ret_value != NULL) |
6e25e1e08ffb
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
103 { |
6921
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
104 count = call_sv(handler->callback, G_EVAL | G_SCALAR); |
6567
6e25e1e08ffb
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
105 |
6e25e1e08ffb
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
106 SPAGAIN; |
6549
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
107 |
6567
6e25e1e08ffb
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
108 if (count != 1) |
6e25e1e08ffb
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
109 croak("Uh oh! call_sv returned %i != 1", i); |
6e25e1e08ffb
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
110 else |
6920
13f78c350cd3
[gaim-migrate @ 7467]
Christian Hammond <chipx86@chipx86.com>
parents:
6919
diff
changeset
|
111 ret_val = gaim_perl_data_from_sv(ret_value, POPs); |
6567
6e25e1e08ffb
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
112 } |
6e25e1e08ffb
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
113 else |
6921
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
114 { |
6567
6e25e1e08ffb
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
115 call_sv(handler->callback, G_SCALAR); |
6549
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
116 |
6921
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
117 SPAGAIN; |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
118 } |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
119 |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
120 if (SvTRUE(ERRSV)) |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
121 { |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
122 gaim_debug_error("perl", "Perl function exited abnormally: %s\n", |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
123 SvPV(ERRSV, na)); |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
124 } |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
125 |
6919
1aa771990188
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
126 /* See if any parameters changed. */ |
1aa771990188
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
127 for (i = 0; i < value_count; i++) |
1aa771990188
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
128 { |
1aa771990188
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
129 if (gaim_value_is_outgoing(values[i])) |
1aa771990188
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
130 { |
6921
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
131 switch (gaim_value_get_type(values[i])) |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
132 { |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
133 case GAIM_TYPE_BOOLEAN: |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
134 *((gboolean *)copy_args[i]) = SvIV(sv_args[i]); |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
135 break; |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
136 |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
137 case GAIM_TYPE_INT: |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
138 *((int *)copy_args[i]) = SvIV(sv_args[i]); |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
139 break; |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
140 |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
141 case GAIM_TYPE_UINT: |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
142 *((unsigned int *)copy_args[i]) = SvUV(sv_args[i]); |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
143 break; |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
144 |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
145 case GAIM_TYPE_LONG: |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
146 *((long *)copy_args[i]) = SvIV(sv_args[i]); |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
147 break; |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
148 |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
149 case GAIM_TYPE_ULONG: |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
150 *((unsigned long *)copy_args[i]) = SvUV(sv_args[i]); |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
151 break; |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
152 |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
153 case GAIM_TYPE_INT64: |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
154 *((gint64 *)copy_args[i]) = SvIV(sv_args[i]); |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
155 break; |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
156 |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
157 case GAIM_TYPE_UINT64: |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
158 *((guint64 *)copy_args[i]) = SvUV(sv_args[i]); |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
159 break; |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
160 |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
161 case GAIM_TYPE_STRING: |
6925
3ec6aac0ff67
[gaim-migrate @ 7472]
Christian Hammond <chipx86@chipx86.com>
parents:
6924
diff
changeset
|
162 if (strcmp(*((char **)copy_args[i]), SvPVX(sv_args[i]))) |
3ec6aac0ff67
[gaim-migrate @ 7472]
Christian Hammond <chipx86@chipx86.com>
parents:
6924
diff
changeset
|
163 { |
3ec6aac0ff67
[gaim-migrate @ 7472]
Christian Hammond <chipx86@chipx86.com>
parents:
6924
diff
changeset
|
164 g_free(*((char **)copy_args[i])); |
3ec6aac0ff67
[gaim-migrate @ 7472]
Christian Hammond <chipx86@chipx86.com>
parents:
6924
diff
changeset
|
165 *((char **)copy_args[i]) = |
3ec6aac0ff67
[gaim-migrate @ 7472]
Christian Hammond <chipx86@chipx86.com>
parents:
6924
diff
changeset
|
166 g_strdup(SvPV(sv_args[i], na)); |
3ec6aac0ff67
[gaim-migrate @ 7472]
Christian Hammond <chipx86@chipx86.com>
parents:
6924
diff
changeset
|
167 } |
6921
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
168 break; |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
169 |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
170 case GAIM_TYPE_POINTER: |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
171 *((void **)copy_args[i]) = (void *)SvIV(sv_args[i]); |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
172 break; |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
173 |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
174 case GAIM_TYPE_BOXED: |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
175 *((void **)copy_args[i]) = (void *)SvIV(sv_args[i]); |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
176 break; |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
177 |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
178 default: |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
179 break; |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
180 } |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
181 |
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
182 #if 0 |
6920
13f78c350cd3
[gaim-migrate @ 7467]
Christian Hammond <chipx86@chipx86.com>
parents:
6919
diff
changeset
|
183 *((void **)copy_args[i]) = gaim_perl_data_from_sv(values[i], |
13f78c350cd3
[gaim-migrate @ 7467]
Christian Hammond <chipx86@chipx86.com>
parents:
6919
diff
changeset
|
184 sv_args[i]); |
6921
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
185 #endif |
6919
1aa771990188
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
186 } |
1aa771990188
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
187 } |
1aa771990188
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
188 |
6921
11d05ddf30a3
[gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents:
6920
diff
changeset
|
189 PUTBACK; |
6549
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
190 FREETMPS; |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
191 LEAVE; |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
192 |
6919
1aa771990188
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
193 g_free(sv_args); |
6920
13f78c350cd3
[gaim-migrate @ 7467]
Christian Hammond <chipx86@chipx86.com>
parents:
6919
diff
changeset
|
194 g_free(copy_args); |
6919
1aa771990188
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
195 |
1aa771990188
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
196 gaim_debug_misc("perl", "ret_val = %p\n", ret_val); |
1aa771990188
[gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents:
6568
diff
changeset
|
197 |
6549
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
198 return ret_val; |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
199 } |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
200 |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
201 static GaimPerlSignalHandler * |
6567
6e25e1e08ffb
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
202 find_signal_handler(GaimPlugin *plugin, void *instance, const char *signal) |
6549
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
203 { |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
204 GaimPerlSignalHandler *handler; |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
205 GList *l; |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
206 |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
207 for (l = signal_handlers; l != NULL; l = l->next) |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
208 { |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
209 handler = (GaimPerlSignalHandler *)l->data; |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
210 |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
211 if (handler->plugin == plugin && |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
212 handler->instance == instance && |
6567
6e25e1e08ffb
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
213 !strcmp(handler->signal, signal)) |
6549
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
214 { |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
215 return handler; |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
216 } |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
217 } |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
218 |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
219 return NULL; |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
220 } |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
221 |
6520 | 222 void |
6568
33486b749aa9
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
223 gaim_perl_timeout_add(GaimPlugin *plugin, int seconds, SV *callback, SV *data) |
6520 | 224 { |
225 GaimPerlTimeoutHandler *handler; | |
226 | |
227 if (plugin == NULL) | |
228 { | |
6549
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
229 croak("Invalid handle in adding perl timeout handler.\n"); |
6520 | 230 return; |
231 } | |
232 | |
233 handler = g_new0(GaimPerlTimeoutHandler, 1); | |
234 | |
6568
33486b749aa9
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
235 handler->plugin = plugin; |
33486b749aa9
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
236 handler->callback = (callback != NULL && callback != &PL_sv_undef |
33486b749aa9
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
237 ? newSVsv(callback) : NULL); |
33486b749aa9
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
238 handler->data = (data != NULL && data != &PL_sv_undef |
33486b749aa9
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
239 ? newSVsv(data) : NULL); |
6520 | 240 |
241 timeout_handlers = g_list_append(timeout_handlers, handler); | |
6568
33486b749aa9
[gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents:
6567
diff
changeset
|
242 |
6520 | 243 handler->iotag = g_timeout_add(seconds * 1000, perl_timeout_cb, handler); |
244 } | |
245 | |
246 void | |
247 gaim_perl_timeout_clear_for_plugin(GaimPlugin *plugin) | |
248 { | |
249 GaimPerlTimeoutHandler *handler; | |
250 GList *l, *l_next; | |
251 | |
252 for (l = timeout_handlers; l != NULL; l = l_next) | |
253 { | |
254 l_next = l->next; | |
255 | |
256 handler = (GaimPerlTimeoutHandler *)l->data; | |
257 | |
258 if (handler->plugin == plugin) | |
259 destroy_timeout_handler(handler); | |
260 } | |
261 } | |
262 | |
263 void | |
264 gaim_perl_timeout_clear(void) | |
265 { | |
6549
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
266 while (timeout_handlers != NULL) |
6520 | 267 destroy_timeout_handler(timeout_handlers->data); |
268 } | |
269 | |
6549
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
270 void |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
271 gaim_perl_signal_connect(GaimPlugin *plugin, void *instance, |
6567
6e25e1e08ffb
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
272 const char *signal, SV *callback, SV *data) |
6549
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
273 { |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
274 GaimPerlSignalHandler *handler; |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
275 |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
276 handler = g_new0(GaimPerlSignalHandler, 1); |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
277 handler->plugin = plugin; |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
278 handler->instance = instance; |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
279 handler->signal = g_strdup(signal); |
6567
6e25e1e08ffb
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
280 handler->callback = (callback != NULL && callback != &PL_sv_undef |
6e25e1e08ffb
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
281 ? newSVsv(callback) : NULL); |
6e25e1e08ffb
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
282 handler->data = (data != NULL && data != &PL_sv_undef |
6e25e1e08ffb
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
283 ? newSVsv(data) : NULL); |
6549
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
284 |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
285 signal_handlers = g_list_append(signal_handlers, handler); |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
286 |
6554
28b38803d0bb
[gaim-migrate @ 7076]
Christian Hammond <chipx86@chipx86.com>
parents:
6549
diff
changeset
|
287 gaim_signal_connect_vargs(instance, signal, |
28b38803d0bb
[gaim-migrate @ 7076]
Christian Hammond <chipx86@chipx86.com>
parents:
6549
diff
changeset
|
288 plugin, GAIM_CALLBACK(perl_signal_cb), handler); |
6549
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
289 } |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
290 |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
291 void |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
292 gaim_perl_signal_disconnect(GaimPlugin *plugin, void *instance, |
6567
6e25e1e08ffb
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
293 const char *signal) |
6549
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
294 { |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
295 GaimPerlSignalHandler *handler; |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
296 |
6567
6e25e1e08ffb
[gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents:
6566
diff
changeset
|
297 handler = find_signal_handler(plugin, instance, signal); |
6549
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
298 |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
299 if (handler == NULL) |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
300 { |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
301 croak("Invalid signal handler information in " |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
302 "disconnecting a perl signal handler.\n"); |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
303 return; |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
304 } |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
305 |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
306 destroy_signal_handler(handler); |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
307 } |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
308 |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
309 void |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
310 gaim_perl_signal_clear_for_plugin(GaimPlugin *plugin) |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
311 { |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
312 GaimPerlSignalHandler *handler; |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
313 GList *l, *l_next; |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
314 |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
315 for (l = signal_handlers; l != NULL; l = l_next) |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
316 { |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
317 l_next = l->next; |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
318 |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
319 handler = (GaimPerlSignalHandler *)l->data; |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
320 |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
321 if (handler->plugin == plugin) |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
322 destroy_signal_handler(handler); |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
323 } |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
324 } |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
325 |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
326 void |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
327 gaim_perl_signal_clear(void) |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
328 { |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
329 while (signal_handlers != NULL) |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
330 destroy_signal_handler(signal_handlers->data); |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
331 } |
ed796f756237
[gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents:
6520
diff
changeset
|
332 |