Mercurial > pidgin
comparison libpurple/plugins/perl/perl-handlers.c @ 15822:32c366eeeb99
sed -ie 's/gaim/purple/g'
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 19 Mar 2007 07:01:17 +0000 |
parents | 5fe8042783c1 |
children | ed2e53708b16 |
comparison
equal
deleted
inserted
replaced
15821:84b0f9b23ede | 15822:32c366eeeb99 |
---|---|
13 #ifndef PERL_MAGIC_ext | 13 #ifndef PERL_MAGIC_ext |
14 #define PERL_MAGIC_ext '~' | 14 #define PERL_MAGIC_ext '~' |
15 #endif | 15 #endif |
16 | 16 |
17 void | 17 void |
18 gaim_perl_plugin_action_cb(GaimPluginAction *action) | 18 purple_perl_plugin_action_cb(PurplePluginAction *action) |
19 { | 19 { |
20 SV **callback; | 20 SV **callback; |
21 HV *hv = NULL; | 21 HV *hv = NULL; |
22 gchar *hvname; | 22 gchar *hvname; |
23 GaimPlugin *plugin; | 23 PurplePlugin *plugin; |
24 GaimPerlScript *gps; | 24 PurplePerlScript *gps; |
25 dSP; | 25 dSP; |
26 | 26 |
27 plugin = action->plugin; | 27 plugin = action->plugin; |
28 gps = (GaimPerlScript *)plugin->info->extra_info; | 28 gps = (PurplePerlScript *)plugin->info->extra_info; |
29 hvname = g_strdup_printf("%s::plugin_actions", gps->package); | 29 hvname = g_strdup_printf("%s::plugin_actions", gps->package); |
30 hv = get_hv(hvname, FALSE); | 30 hv = get_hv(hvname, FALSE); |
31 g_free(hvname); | 31 g_free(hvname); |
32 | 32 |
33 if (hv == NULL) | 33 if (hv == NULL) |
34 croak("No plugin_actions hash found in \"%s\" plugin.", gaim_plugin_get_name(plugin)); | 34 croak("No plugin_actions hash found in \"%s\" plugin.", purple_plugin_get_name(plugin)); |
35 | 35 |
36 ENTER; | 36 ENTER; |
37 SAVETMPS; | 37 SAVETMPS; |
38 | 38 |
39 callback = hv_fetch(hv, action->label, strlen(action->label), 0); | 39 callback = hv_fetch(hv, action->label, strlen(action->label), 0); |
40 | 40 |
41 if (callback == NULL || *callback == NULL) | 41 if (callback == NULL || *callback == NULL) |
42 croak("No plugin_action function named \"%s\" in \"%s\" plugin.", action->label, gaim_plugin_get_name(plugin)); | 42 croak("No plugin_action function named \"%s\" in \"%s\" plugin.", action->label, purple_plugin_get_name(plugin)); |
43 | 43 |
44 PUSHMARK(sp); | 44 PUSHMARK(sp); |
45 XPUSHs(gaim_perl_bless_object(gps->plugin, "Gaim::Plugin")); | 45 XPUSHs(purple_perl_bless_object(gps->plugin, "Purple::Plugin")); |
46 PUTBACK; | 46 PUTBACK; |
47 | 47 |
48 call_sv(*callback, G_VOID | G_DISCARD); | 48 call_sv(*callback, G_VOID | G_DISCARD); |
49 SPAGAIN; | 49 SPAGAIN; |
50 | 50 |
52 FREETMPS; | 52 FREETMPS; |
53 LEAVE; | 53 LEAVE; |
54 } | 54 } |
55 | 55 |
56 GList * | 56 GList * |
57 gaim_perl_plugin_actions(GaimPlugin *plugin, gpointer context) | 57 purple_perl_plugin_actions(PurplePlugin *plugin, gpointer context) |
58 { | 58 { |
59 GList *l = NULL; | 59 GList *l = NULL; |
60 GaimPerlScript *gps; | 60 PurplePerlScript *gps; |
61 int i = 0, count = 0; | 61 int i = 0, count = 0; |
62 dSP; | 62 dSP; |
63 | 63 |
64 gps = (GaimPerlScript *)plugin->info->extra_info; | 64 gps = (PurplePerlScript *)plugin->info->extra_info; |
65 | 65 |
66 ENTER; | 66 ENTER; |
67 SAVETMPS; | 67 SAVETMPS; |
68 | 68 |
69 PUSHMARK(SP); | 69 PUSHMARK(SP); |
70 XPUSHs(sv_2mortal(gaim_perl_bless_object(plugin, "Gaim::Plugin"))); | 70 XPUSHs(sv_2mortal(purple_perl_bless_object(plugin, "Purple::Plugin"))); |
71 /* XXX This *will* cease working correctly if context gets changed to | 71 /* XXX This *will* cease working correctly if context gets changed to |
72 * ever be able to hold anything other than a GaimConnection */ | 72 * ever be able to hold anything other than a PurpleConnection */ |
73 if (context != NULL) | 73 if (context != NULL) |
74 XPUSHs(sv_2mortal(gaim_perl_bless_object(context, | 74 XPUSHs(sv_2mortal(purple_perl_bless_object(context, |
75 "Gaim::Connection"))); | 75 "Purple::Connection"))); |
76 else | 76 else |
77 XPUSHs(&PL_sv_undef); | 77 XPUSHs(&PL_sv_undef); |
78 PUTBACK; | 78 PUTBACK; |
79 | 79 |
80 count = call_pv(gps->plugin_action_sub, G_ARRAY); | 80 count = call_pv(gps->plugin_action_sub, G_ARRAY); |
85 croak("The plugin_actions sub didn't return anything.\n"); | 85 croak("The plugin_actions sub didn't return anything.\n"); |
86 | 86 |
87 for (i = 0; i < count; i++) { | 87 for (i = 0; i < count; i++) { |
88 SV *sv; | 88 SV *sv; |
89 gchar *label; | 89 gchar *label; |
90 GaimPluginAction *act = NULL; | 90 PurplePluginAction *act = NULL; |
91 | 91 |
92 sv = POPs; | 92 sv = POPs; |
93 label = SvPV_nolen(sv); | 93 label = SvPV_nolen(sv); |
94 /* XXX I think this leaks, but doing it without the strdup | 94 /* XXX I think this leaks, but doing it without the strdup |
95 * just showed garbage */ | 95 * just showed garbage */ |
96 act = gaim_plugin_action_new(g_strdup(label), gaim_perl_plugin_action_cb); | 96 act = purple_plugin_action_new(g_strdup(label), purple_perl_plugin_action_cb); |
97 l = g_list_prepend(l, act); | 97 l = g_list_prepend(l, act); |
98 } | 98 } |
99 | 99 |
100 PUTBACK; | 100 PUTBACK; |
101 FREETMPS; | 101 FREETMPS; |
102 LEAVE; | 102 LEAVE; |
103 | 103 |
104 return l; | 104 return l; |
105 } | 105 } |
106 | 106 |
107 #ifdef GAIM_GTKPERL | 107 #ifdef PURPLE_GTKPERL |
108 GtkWidget * | 108 GtkWidget * |
109 gaim_perl_gtk_get_plugin_frame(GaimPlugin *plugin) | 109 purple_perl_gtk_get_plugin_frame(PurplePlugin *plugin) |
110 { | 110 { |
111 SV * sv; | 111 SV * sv; |
112 int count; | 112 int count; |
113 MAGIC *mg; | 113 MAGIC *mg; |
114 GtkWidget *ret; | 114 GtkWidget *ret; |
115 GaimPerlScript *gps; | 115 PurplePerlScript *gps; |
116 dSP; | 116 dSP; |
117 | 117 |
118 gps = (GaimPerlScript *)plugin->info->extra_info; | 118 gps = (PurplePerlScript *)plugin->info->extra_info; |
119 | 119 |
120 ENTER; | 120 ENTER; |
121 SAVETMPS; | 121 SAVETMPS; |
122 | 122 |
123 count = call_pv(gps->gtk_prefs_sub, G_SCALAR | G_NOARGS); | 123 count = call_pv(gps->gtk_prefs_sub, G_SCALAR | G_NOARGS); |
140 | 140 |
141 return ret; | 141 return ret; |
142 } | 142 } |
143 #endif | 143 #endif |
144 | 144 |
145 GaimPluginPrefFrame * | 145 PurplePluginPrefFrame * |
146 gaim_perl_get_plugin_frame(GaimPlugin *plugin) | 146 purple_perl_get_plugin_frame(PurplePlugin *plugin) |
147 { | 147 { |
148 /* Sets up the Perl Stack for our call back into the script to run the | 148 /* Sets up the Perl Stack for our call back into the script to run the |
149 * plugin_pref... sub */ | 149 * plugin_pref... sub */ |
150 int count; | 150 int count; |
151 GaimPerlScript *gps; | 151 PurplePerlScript *gps; |
152 GaimPluginPrefFrame *ret_frame; | 152 PurplePluginPrefFrame *ret_frame; |
153 dSP; | 153 dSP; |
154 | 154 |
155 gps = (GaimPerlScript *)plugin->info->extra_info; | 155 gps = (PurplePerlScript *)plugin->info->extra_info; |
156 | 156 |
157 ENTER; | 157 ENTER; |
158 SAVETMPS; | 158 SAVETMPS; |
159 /* Some perl magic to run perl_plugin_pref_frame_SV perl sub and | 159 /* Some perl magic to run perl_plugin_pref_frame_SV perl sub and |
160 * return the frame */ | 160 * return the frame */ |
166 SPAGAIN; | 166 SPAGAIN; |
167 | 167 |
168 if (count != 1) | 168 if (count != 1) |
169 croak("call_pv: Did not return the correct number of values.\n"); | 169 croak("call_pv: Did not return the correct number of values.\n"); |
170 /* the frame was created in a perl sub and is returned */ | 170 /* the frame was created in a perl sub and is returned */ |
171 ret_frame = (GaimPluginPrefFrame *)gaim_perl_ref_object(POPs); | 171 ret_frame = (PurplePluginPrefFrame *)purple_perl_ref_object(POPs); |
172 | 172 |
173 /* Tidy up the Perl stack */ | 173 /* Tidy up the Perl stack */ |
174 PUTBACK; | 174 PUTBACK; |
175 FREETMPS; | 175 FREETMPS; |
176 LEAVE; | 176 LEAVE; |
177 | 177 |
178 return ret_frame; | 178 return ret_frame; |
179 } | 179 } |
180 | 180 |
181 static void | 181 static void |
182 destroy_timeout_handler(GaimPerlTimeoutHandler *handler) | 182 destroy_timeout_handler(PurplePerlTimeoutHandler *handler) |
183 { | 183 { |
184 timeout_handlers = g_list_remove(timeout_handlers, handler); | 184 timeout_handlers = g_list_remove(timeout_handlers, handler); |
185 | 185 |
186 if (handler->callback != NULL) | 186 if (handler->callback != NULL) |
187 SvREFCNT_dec(handler->callback); | 187 SvREFCNT_dec(handler->callback); |
191 | 191 |
192 g_free(handler); | 192 g_free(handler); |
193 } | 193 } |
194 | 194 |
195 static void | 195 static void |
196 destroy_signal_handler(GaimPerlSignalHandler *handler) | 196 destroy_signal_handler(PurplePerlSignalHandler *handler) |
197 { | 197 { |
198 signal_handlers = g_list_remove(signal_handlers, handler); | 198 signal_handlers = g_list_remove(signal_handlers, handler); |
199 | 199 |
200 if (handler->callback != NULL) | 200 if (handler->callback != NULL) |
201 SvREFCNT_dec(handler->callback); | 201 SvREFCNT_dec(handler->callback); |
208 } | 208 } |
209 | 209 |
210 static int | 210 static int |
211 perl_timeout_cb(gpointer data) | 211 perl_timeout_cb(gpointer data) |
212 { | 212 { |
213 GaimPerlTimeoutHandler *handler = (GaimPerlTimeoutHandler *)data; | 213 PurplePerlTimeoutHandler *handler = (PurplePerlTimeoutHandler *)data; |
214 | 214 |
215 dSP; | 215 dSP; |
216 ENTER; | 216 ENTER; |
217 SAVETMPS; | 217 SAVETMPS; |
218 PUSHMARK(sp); | 218 PUSHMARK(sp); |
233 typedef void *DATATYPE; | 233 typedef void *DATATYPE; |
234 | 234 |
235 static void * | 235 static void * |
236 perl_signal_cb(va_list args, void *data) | 236 perl_signal_cb(va_list args, void *data) |
237 { | 237 { |
238 GaimPerlSignalHandler *handler = (GaimPerlSignalHandler *)data; | 238 PurplePerlSignalHandler *handler = (PurplePerlSignalHandler *)data; |
239 void *ret_val = NULL; | 239 void *ret_val = NULL; |
240 int i; | 240 int i; |
241 int count; | 241 int count; |
242 int value_count; | 242 int value_count; |
243 GaimValue *ret_value, **values; | 243 PurpleValue *ret_value, **values; |
244 SV **sv_args; | 244 SV **sv_args; |
245 DATATYPE **copy_args; | 245 DATATYPE **copy_args; |
246 STRLEN na; | 246 STRLEN na; |
247 | 247 |
248 dSP; | 248 dSP; |
249 ENTER; | 249 ENTER; |
250 SAVETMPS; | 250 SAVETMPS; |
251 PUSHMARK(sp); | 251 PUSHMARK(sp); |
252 | 252 |
253 gaim_signal_get_values(handler->instance, handler->signal, | 253 purple_signal_get_values(handler->instance, handler->signal, |
254 &ret_value, &value_count, &values); | 254 &ret_value, &value_count, &values); |
255 | 255 |
256 sv_args = g_new(SV *, value_count); | 256 sv_args = g_new(SV *, value_count); |
257 copy_args = g_new(void **, value_count); | 257 copy_args = g_new(void **, value_count); |
258 | 258 |
259 for (i = 0; i < value_count; i++) { | 259 for (i = 0; i < value_count; i++) { |
260 sv_args[i] = gaim_perl_sv_from_vargs(values[i], | 260 sv_args[i] = purple_perl_sv_from_vargs(values[i], |
261 (va_list*)&args, | 261 (va_list*)&args, |
262 ©_args[i]); | 262 ©_args[i]); |
263 | 263 |
264 XPUSHs(sv_args[i]); | 264 XPUSHs(sv_args[i]); |
265 } | 265 } |
274 SPAGAIN; | 274 SPAGAIN; |
275 | 275 |
276 if (count != 1) | 276 if (count != 1) |
277 croak("Uh oh! call_sv returned %i != 1", i); | 277 croak("Uh oh! call_sv returned %i != 1", i); |
278 else | 278 else |
279 ret_val = gaim_perl_data_from_sv(ret_value, POPs); | 279 ret_val = purple_perl_data_from_sv(ret_value, POPs); |
280 } else { | 280 } else { |
281 call_sv(handler->callback, G_SCALAR); | 281 call_sv(handler->callback, G_SCALAR); |
282 | 282 |
283 SPAGAIN; | 283 SPAGAIN; |
284 } | 284 } |
285 | 285 |
286 if (SvTRUE(ERRSV)) { | 286 if (SvTRUE(ERRSV)) { |
287 gaim_debug_error("perl", | 287 purple_debug_error("perl", |
288 "Perl function exited abnormally: %s\n", | 288 "Perl function exited abnormally: %s\n", |
289 SvPV(ERRSV, na)); | 289 SvPV(ERRSV, na)); |
290 } | 290 } |
291 | 291 |
292 /* See if any parameters changed. */ | 292 /* See if any parameters changed. */ |
293 for (i = 0; i < value_count; i++) { | 293 for (i = 0; i < value_count; i++) { |
294 if (gaim_value_is_outgoing(values[i])) { | 294 if (purple_value_is_outgoing(values[i])) { |
295 switch (gaim_value_get_type(values[i])) { | 295 switch (purple_value_get_type(values[i])) { |
296 case GAIM_TYPE_BOOLEAN: | 296 case PURPLE_TYPE_BOOLEAN: |
297 *((gboolean *)copy_args[i]) = SvIV(sv_args[i]); | 297 *((gboolean *)copy_args[i]) = SvIV(sv_args[i]); |
298 break; | 298 break; |
299 | 299 |
300 case GAIM_TYPE_INT: | 300 case PURPLE_TYPE_INT: |
301 *((int *)copy_args[i]) = SvIV(sv_args[i]); | 301 *((int *)copy_args[i]) = SvIV(sv_args[i]); |
302 break; | 302 break; |
303 | 303 |
304 case GAIM_TYPE_UINT: | 304 case PURPLE_TYPE_UINT: |
305 *((unsigned int *)copy_args[i]) = SvUV(sv_args[i]); | 305 *((unsigned int *)copy_args[i]) = SvUV(sv_args[i]); |
306 break; | 306 break; |
307 | 307 |
308 case GAIM_TYPE_LONG: | 308 case PURPLE_TYPE_LONG: |
309 *((long *)copy_args[i]) = SvIV(sv_args[i]); | 309 *((long *)copy_args[i]) = SvIV(sv_args[i]); |
310 break; | 310 break; |
311 | 311 |
312 case GAIM_TYPE_ULONG: | 312 case PURPLE_TYPE_ULONG: |
313 *((unsigned long *)copy_args[i]) = SvUV(sv_args[i]); | 313 *((unsigned long *)copy_args[i]) = SvUV(sv_args[i]); |
314 break; | 314 break; |
315 | 315 |
316 case GAIM_TYPE_INT64: | 316 case PURPLE_TYPE_INT64: |
317 *((gint64 *)copy_args[i]) = SvIV(sv_args[i]); | 317 *((gint64 *)copy_args[i]) = SvIV(sv_args[i]); |
318 break; | 318 break; |
319 | 319 |
320 case GAIM_TYPE_UINT64: | 320 case PURPLE_TYPE_UINT64: |
321 *((guint64 *)copy_args[i]) = SvUV(sv_args[i]); | 321 *((guint64 *)copy_args[i]) = SvUV(sv_args[i]); |
322 break; | 322 break; |
323 | 323 |
324 case GAIM_TYPE_STRING: | 324 case PURPLE_TYPE_STRING: |
325 if (strcmp(*((char **)copy_args[i]), SvPVX(sv_args[i]))) { | 325 if (strcmp(*((char **)copy_args[i]), SvPVX(sv_args[i]))) { |
326 g_free(*((char **)copy_args[i])); | 326 g_free(*((char **)copy_args[i])); |
327 *((char **)copy_args[i]) = | 327 *((char **)copy_args[i]) = |
328 g_strdup(SvPV(sv_args[i], na)); | 328 g_strdup(SvPV(sv_args[i], na)); |
329 } | 329 } |
330 break; | 330 break; |
331 | 331 |
332 case GAIM_TYPE_POINTER: | 332 case PURPLE_TYPE_POINTER: |
333 *((void **)copy_args[i]) = (void *)SvIV(sv_args[i]); | 333 *((void **)copy_args[i]) = (void *)SvIV(sv_args[i]); |
334 break; | 334 break; |
335 | 335 |
336 case GAIM_TYPE_BOXED: | 336 case PURPLE_TYPE_BOXED: |
337 *((void **)copy_args[i]) = (void *)SvIV(sv_args[i]); | 337 *((void **)copy_args[i]) = (void *)SvIV(sv_args[i]); |
338 break; | 338 break; |
339 | 339 |
340 default: | 340 default: |
341 break; | 341 break; |
342 } | 342 } |
343 | 343 |
344 #if 0 | 344 #if 0 |
345 *((void **)copy_args[i]) = gaim_perl_data_from_sv(values[i], | 345 *((void **)copy_args[i]) = purple_perl_data_from_sv(values[i], |
346 sv_args[i]); | 346 sv_args[i]); |
347 #endif | 347 #endif |
348 } | 348 } |
349 } | 349 } |
350 | 350 |
353 LEAVE; | 353 LEAVE; |
354 | 354 |
355 g_free(sv_args); | 355 g_free(sv_args); |
356 g_free(copy_args); | 356 g_free(copy_args); |
357 | 357 |
358 gaim_debug_misc("perl", "ret_val = %p\n", ret_val); | 358 purple_debug_misc("perl", "ret_val = %p\n", ret_val); |
359 | 359 |
360 return ret_val; | 360 return ret_val; |
361 } | 361 } |
362 | 362 |
363 static GaimPerlSignalHandler * | 363 static PurplePerlSignalHandler * |
364 find_signal_handler(GaimPlugin *plugin, void *instance, const char *signal) | 364 find_signal_handler(PurplePlugin *plugin, void *instance, const char *signal) |
365 { | 365 { |
366 GaimPerlSignalHandler *handler; | 366 PurplePerlSignalHandler *handler; |
367 GList *l; | 367 GList *l; |
368 | 368 |
369 for (l = signal_handlers; l != NULL; l = l->next) { | 369 for (l = signal_handlers; l != NULL; l = l->next) { |
370 handler = (GaimPerlSignalHandler *)l->data; | 370 handler = (PurplePerlSignalHandler *)l->data; |
371 | 371 |
372 if (handler->plugin == plugin && | 372 if (handler->plugin == plugin && |
373 handler->instance == instance && | 373 handler->instance == instance && |
374 !strcmp(handler->signal, signal)) { | 374 !strcmp(handler->signal, signal)) { |
375 return handler; | 375 return handler; |
378 | 378 |
379 return NULL; | 379 return NULL; |
380 } | 380 } |
381 | 381 |
382 void | 382 void |
383 gaim_perl_timeout_add(GaimPlugin *plugin, int seconds, SV *callback, SV *data) | 383 purple_perl_timeout_add(PurplePlugin *plugin, int seconds, SV *callback, SV *data) |
384 { | 384 { |
385 GaimPerlTimeoutHandler *handler; | 385 PurplePerlTimeoutHandler *handler; |
386 | 386 |
387 if (plugin == NULL) { | 387 if (plugin == NULL) { |
388 croak("Invalid handle in adding perl timeout handler.\n"); | 388 croak("Invalid handle in adding perl timeout handler.\n"); |
389 return; | 389 return; |
390 } | 390 } |
391 | 391 |
392 handler = g_new0(GaimPerlTimeoutHandler, 1); | 392 handler = g_new0(PurplePerlTimeoutHandler, 1); |
393 | 393 |
394 handler->plugin = plugin; | 394 handler->plugin = plugin; |
395 handler->callback = (callback != NULL && callback != &PL_sv_undef | 395 handler->callback = (callback != NULL && callback != &PL_sv_undef |
396 ? newSVsv(callback) : NULL); | 396 ? newSVsv(callback) : NULL); |
397 handler->data = (data != NULL && data != &PL_sv_undef | 397 handler->data = (data != NULL && data != &PL_sv_undef |
401 | 401 |
402 handler->iotag = g_timeout_add(seconds * 1000, perl_timeout_cb, handler); | 402 handler->iotag = g_timeout_add(seconds * 1000, perl_timeout_cb, handler); |
403 } | 403 } |
404 | 404 |
405 void | 405 void |
406 gaim_perl_timeout_clear_for_plugin(GaimPlugin *plugin) | 406 purple_perl_timeout_clear_for_plugin(PurplePlugin *plugin) |
407 { | 407 { |
408 GaimPerlTimeoutHandler *handler; | 408 PurplePerlTimeoutHandler *handler; |
409 GList *l, *l_next; | 409 GList *l, *l_next; |
410 | 410 |
411 for (l = timeout_handlers; l != NULL; l = l_next) { | 411 for (l = timeout_handlers; l != NULL; l = l_next) { |
412 l_next = l->next; | 412 l_next = l->next; |
413 | 413 |
414 handler = (GaimPerlTimeoutHandler *)l->data; | 414 handler = (PurplePerlTimeoutHandler *)l->data; |
415 | 415 |
416 if (handler->plugin == plugin) | 416 if (handler->plugin == plugin) |
417 destroy_timeout_handler(handler); | 417 destroy_timeout_handler(handler); |
418 } | 418 } |
419 } | 419 } |
420 | 420 |
421 void | 421 void |
422 gaim_perl_timeout_clear(void) | 422 purple_perl_timeout_clear(void) |
423 { | 423 { |
424 while (timeout_handlers != NULL) | 424 while (timeout_handlers != NULL) |
425 destroy_timeout_handler(timeout_handlers->data); | 425 destroy_timeout_handler(timeout_handlers->data); |
426 } | 426 } |
427 | 427 |
428 void | 428 void |
429 gaim_perl_signal_connect(GaimPlugin *plugin, void *instance, | 429 purple_perl_signal_connect(PurplePlugin *plugin, void *instance, |
430 const char *signal, SV *callback, SV *data, | 430 const char *signal, SV *callback, SV *data, |
431 int priority) | 431 int priority) |
432 { | 432 { |
433 GaimPerlSignalHandler *handler; | 433 PurplePerlSignalHandler *handler; |
434 | 434 |
435 handler = g_new0(GaimPerlSignalHandler, 1); | 435 handler = g_new0(PurplePerlSignalHandler, 1); |
436 handler->plugin = plugin; | 436 handler->plugin = plugin; |
437 handler->instance = instance; | 437 handler->instance = instance; |
438 handler->signal = g_strdup(signal); | 438 handler->signal = g_strdup(signal); |
439 handler->callback = (callback != NULL && | 439 handler->callback = (callback != NULL && |
440 callback != &PL_sv_undef ? newSVsv(callback) | 440 callback != &PL_sv_undef ? newSVsv(callback) |
442 handler->data = (data != NULL && | 442 handler->data = (data != NULL && |
443 data != &PL_sv_undef ? newSVsv(data) : NULL); | 443 data != &PL_sv_undef ? newSVsv(data) : NULL); |
444 | 444 |
445 signal_handlers = g_list_append(signal_handlers, handler); | 445 signal_handlers = g_list_append(signal_handlers, handler); |
446 | 446 |
447 gaim_signal_connect_priority_vargs(instance, signal, plugin, | 447 purple_signal_connect_priority_vargs(instance, signal, plugin, |
448 GAIM_CALLBACK(perl_signal_cb), | 448 PURPLE_CALLBACK(perl_signal_cb), |
449 handler, priority); | 449 handler, priority); |
450 } | 450 } |
451 | 451 |
452 void | 452 void |
453 gaim_perl_signal_disconnect(GaimPlugin *plugin, void *instance, | 453 purple_perl_signal_disconnect(PurplePlugin *plugin, void *instance, |
454 const char *signal) | 454 const char *signal) |
455 { | 455 { |
456 GaimPerlSignalHandler *handler; | 456 PurplePerlSignalHandler *handler; |
457 | 457 |
458 handler = find_signal_handler(plugin, instance, signal); | 458 handler = find_signal_handler(plugin, instance, signal); |
459 | 459 |
460 if (handler == NULL) { | 460 if (handler == NULL) { |
461 croak("Invalid signal handler information in " | 461 croak("Invalid signal handler information in " |
465 | 465 |
466 destroy_signal_handler(handler); | 466 destroy_signal_handler(handler); |
467 } | 467 } |
468 | 468 |
469 void | 469 void |
470 gaim_perl_signal_clear_for_plugin(GaimPlugin *plugin) | 470 purple_perl_signal_clear_for_plugin(PurplePlugin *plugin) |
471 { | 471 { |
472 GaimPerlSignalHandler *handler; | 472 PurplePerlSignalHandler *handler; |
473 GList *l, *l_next; | 473 GList *l, *l_next; |
474 | 474 |
475 for (l = signal_handlers; l != NULL; l = l_next) { | 475 for (l = signal_handlers; l != NULL; l = l_next) { |
476 l_next = l->next; | 476 l_next = l->next; |
477 | 477 |
478 handler = (GaimPerlSignalHandler *)l->data; | 478 handler = (PurplePerlSignalHandler *)l->data; |
479 | 479 |
480 if (handler->plugin == plugin) | 480 if (handler->plugin == plugin) |
481 destroy_signal_handler(handler); | 481 destroy_signal_handler(handler); |
482 } | 482 } |
483 } | 483 } |
484 | 484 |
485 void | 485 void |
486 gaim_perl_signal_clear(void) | 486 purple_perl_signal_clear(void) |
487 { | 487 { |
488 while (signal_handlers != NULL) | 488 while (signal_handlers != NULL) |
489 destroy_signal_handler(signal_handlers->data); | 489 destroy_signal_handler(signal_handlers->data); |
490 } | 490 } |
491 | 491 |
492 static GaimCmdRet | 492 static PurpleCmdRet |
493 perl_cmd_cb(GaimConversation *conv, const gchar *command, | 493 perl_cmd_cb(PurpleConversation *conv, const gchar *command, |
494 gchar **args, gchar **error, void *data) | 494 gchar **args, gchar **error, void *data) |
495 { | 495 { |
496 int i = 0, count, ret_value = GAIM_CMD_RET_OK; | 496 int i = 0, count, ret_value = PURPLE_CMD_RET_OK; |
497 SV *cmdSV, *tmpSV, *convSV; | 497 SV *cmdSV, *tmpSV, *convSV; |
498 GaimPerlCmdHandler *handler = (GaimPerlCmdHandler *)data; | 498 PurplePerlCmdHandler *handler = (PurplePerlCmdHandler *)data; |
499 | 499 |
500 dSP; | 500 dSP; |
501 ENTER; | 501 ENTER; |
502 SAVETMPS; | 502 SAVETMPS; |
503 PUSHMARK(SP); | 503 PUSHMARK(SP); |
504 | 504 |
505 /* Push the conversation onto the perl stack */ | 505 /* Push the conversation onto the perl stack */ |
506 convSV = sv_2mortal(gaim_perl_bless_object(conv, "Gaim::Conversation")); | 506 convSV = sv_2mortal(purple_perl_bless_object(conv, "Purple::Conversation")); |
507 XPUSHs(convSV); | 507 XPUSHs(convSV); |
508 | 508 |
509 /* Push the command string onto the perl stack */ | 509 /* Push the command string onto the perl stack */ |
510 cmdSV = newSVpv(command, 0); | 510 cmdSV = newSVpv(command, 0); |
511 cmdSV = sv_2mortal(cmdSV); | 511 cmdSV = sv_2mortal(cmdSV); |
539 LEAVE; | 539 LEAVE; |
540 | 540 |
541 return ret_value; | 541 return ret_value; |
542 } | 542 } |
543 | 543 |
544 GaimCmdId | 544 PurpleCmdId |
545 gaim_perl_cmd_register(GaimPlugin *plugin, const gchar *command, | 545 purple_perl_cmd_register(PurplePlugin *plugin, const gchar *command, |
546 const gchar *args, GaimCmdPriority priority, | 546 const gchar *args, PurpleCmdPriority priority, |
547 GaimCmdFlag flag, const gchar *prpl_id, SV *callback, | 547 PurpleCmdFlag flag, const gchar *prpl_id, SV *callback, |
548 const gchar *helpstr, SV *data) | 548 const gchar *helpstr, SV *data) |
549 { | 549 { |
550 GaimPerlCmdHandler *handler; | 550 PurplePerlCmdHandler *handler; |
551 | 551 |
552 handler = g_new0(GaimPerlCmdHandler, 1); | 552 handler = g_new0(PurplePerlCmdHandler, 1); |
553 handler->plugin = plugin; | 553 handler->plugin = plugin; |
554 handler->cmd = g_strdup(command); | 554 handler->cmd = g_strdup(command); |
555 handler->prpl_id = g_strdup(prpl_id); | 555 handler->prpl_id = g_strdup(prpl_id); |
556 | 556 |
557 if (callback != NULL && callback != &PL_sv_undef) | 557 if (callback != NULL && callback != &PL_sv_undef) |
564 else | 564 else |
565 handler->data = NULL; | 565 handler->data = NULL; |
566 | 566 |
567 cmd_handlers = g_list_append(cmd_handlers, handler); | 567 cmd_handlers = g_list_append(cmd_handlers, handler); |
568 | 568 |
569 handler->id = gaim_cmd_register(command, args, priority, flag, prpl_id, | 569 handler->id = purple_cmd_register(command, args, priority, flag, prpl_id, |
570 GAIM_CMD_FUNC(perl_cmd_cb), helpstr, | 570 PURPLE_CMD_FUNC(perl_cmd_cb), helpstr, |
571 handler); | 571 handler); |
572 | 572 |
573 return handler->id; | 573 return handler->id; |
574 } | 574 } |
575 | 575 |
576 static void | 576 static void |
577 destroy_cmd_handler(GaimPerlCmdHandler *handler) | 577 destroy_cmd_handler(PurplePerlCmdHandler *handler) |
578 { | 578 { |
579 cmd_handlers = g_list_remove(cmd_handlers, handler); | 579 cmd_handlers = g_list_remove(cmd_handlers, handler); |
580 | 580 |
581 if (handler->callback != NULL) | 581 if (handler->callback != NULL) |
582 SvREFCNT_dec(handler->callback); | 582 SvREFCNT_dec(handler->callback); |
588 g_free(handler->prpl_id); | 588 g_free(handler->prpl_id); |
589 g_free(handler); | 589 g_free(handler); |
590 } | 590 } |
591 | 591 |
592 void | 592 void |
593 gaim_perl_cmd_clear_for_plugin(GaimPlugin *plugin) | 593 purple_perl_cmd_clear_for_plugin(PurplePlugin *plugin) |
594 { | 594 { |
595 GList *l, *l_next; | 595 GList *l, *l_next; |
596 | 596 |
597 for (l = cmd_handlers; l != NULL; l = l_next) { | 597 for (l = cmd_handlers; l != NULL; l = l_next) { |
598 GaimPerlCmdHandler *handler = (GaimPerlCmdHandler *)l->data; | 598 PurplePerlCmdHandler *handler = (PurplePerlCmdHandler *)l->data; |
599 | 599 |
600 l_next = l->next; | 600 l_next = l->next; |
601 | 601 |
602 if (handler->plugin == plugin) | 602 if (handler->plugin == plugin) |
603 destroy_cmd_handler(handler); | 603 destroy_cmd_handler(handler); |
604 } | 604 } |
605 } | 605 } |
606 | 606 |
607 static GaimPerlCmdHandler * | 607 static PurplePerlCmdHandler * |
608 find_cmd_handler(GaimCmdId id) | 608 find_cmd_handler(PurpleCmdId id) |
609 { | 609 { |
610 GList *l; | 610 GList *l; |
611 | 611 |
612 for (l = cmd_handlers; l != NULL; l = l->next) { | 612 for (l = cmd_handlers; l != NULL; l = l->next) { |
613 GaimPerlCmdHandler *handler = (GaimPerlCmdHandler *)l->data; | 613 PurplePerlCmdHandler *handler = (PurplePerlCmdHandler *)l->data; |
614 | 614 |
615 if (handler->id == id) | 615 if (handler->id == id) |
616 return handler; | 616 return handler; |
617 } | 617 } |
618 | 618 |
619 return NULL; | 619 return NULL; |
620 } | 620 } |
621 | 621 |
622 void | 622 void |
623 gaim_perl_cmd_unregister(GaimCmdId id) | 623 purple_perl_cmd_unregister(PurpleCmdId id) |
624 { | 624 { |
625 GaimPerlCmdHandler *handler; | 625 PurplePerlCmdHandler *handler; |
626 | 626 |
627 handler = find_cmd_handler(id); | 627 handler = find_cmd_handler(id); |
628 | 628 |
629 if (handler == NULL) { | 629 if (handler == NULL) { |
630 croak("Invalid command id in removing a perl command handler.\n"); | 630 croak("Invalid command id in removing a perl command handler.\n"); |
631 return; | 631 return; |
632 } | 632 } |
633 | 633 |
634 gaim_cmd_unregister(id); | 634 purple_cmd_unregister(id); |
635 destroy_cmd_handler(handler); | 635 destroy_cmd_handler(handler); |
636 } | 636 } |