1 #include "module.h"
2 
3 /* This breaks on faceprint's amd64 box
4 void *
5 purple_request_action_varg(handle, title, primary, secondary, default_action, user_data, action_count, actions)
6 	void * handle
7 	const char *title
8 	const char *primary
9 	const char *secondary
10 	unsigned int default_action
11 	void *user_data
12 	size_t action_count
13 	va_list actions
14 	*/
15 
16 
17 typedef struct {
18 	SV *ok_fun;
19 	SV *cancel_fun;
20 } PurplePerlRequestData;
21 
22 static void
purple_perl_request_data_free(PurplePerlRequestData * ppr)23 purple_perl_request_data_free(PurplePerlRequestData *ppr)
24 {
25 	if (ppr->ok_fun)
26 		SvREFCNT_dec(ppr->ok_fun);
27 	if (ppr->cancel_fun)
28 		SvREFCNT_dec(ppr->cancel_fun);
29 	g_free(ppr);
30 }
31 
32 /********************************************************/
33 /*                                                      */
34 /* Callback function that calls a perl subroutine       */
35 /*                                                      */
36 /* The void * field data is being used as a way to hide */
37 /* the perl sub's name in a PurplePerlRequestData         */
38 /*                                                      */
39 /********************************************************/
40 static void
purple_perl_request_ok_cb(void * data,PurpleRequestFields * fields)41 purple_perl_request_ok_cb(void * data, PurpleRequestFields *fields)
42 {
43 	PurplePerlRequestData *gpr = (PurplePerlRequestData *)data;
44 
45 	dSP;
46 	ENTER;
47 	SAVETMPS;
48 	PUSHMARK(sp);
49 
50 	XPUSHs(sv_2mortal(purple_perl_bless_object(fields, "Purple::Request::Fields")));
51 	PUTBACK;
52 	call_sv(gpr->ok_fun, G_EVAL | G_SCALAR);
53 	SPAGAIN;
54 
55 	PUTBACK;
56 	FREETMPS;
57 	LEAVE;
58 
59 	purple_perl_request_data_free(gpr);
60 }
61 
62 static void
purple_perl_request_cancel_cb(void * data,PurpleRequestFields * fields)63 purple_perl_request_cancel_cb(void * data, PurpleRequestFields *fields)
64 {
65 	PurplePerlRequestData *gpr = (PurplePerlRequestData *)data;
66 
67 	dSP;
68 	ENTER;
69 	SAVETMPS;
70 	PUSHMARK(sp);
71 
72 	XPUSHs(sv_2mortal(purple_perl_bless_object(fields, "Purple::Request::Fields")));
73 	PUTBACK;
74 	call_sv(gpr->cancel_fun, G_EVAL | G_SCALAR);
75 	SPAGAIN;
76 
77 	PUTBACK;
78 	FREETMPS;
79 	LEAVE;
80 
81 	purple_perl_request_data_free(gpr);
82 }
83 
84 MODULE = Purple::Request  PACKAGE = Purple::Request  PREFIX = purple_request_
85 PROTOTYPES: ENABLE
86 
87 BOOT:
88 {
89 	HV *request_stash = gv_stashpv("Purple::RequestType", 1);
90 	HV *request_field_stash = gv_stashpv("Purple::RequestFieldType", 1);
91 
92 	static const constiv *civ, request_const_iv[] = {
93 #define const_iv(name) {#name, (IV)PURPLE_REQUEST_##name}
94 		const_iv(INPUT),
95 		const_iv(CHOICE),
96 		const_iv(ACTION),
97 		const_iv(FIELDS),
98 		const_iv(FILE),
99 		const_iv(FOLDER),
100 	};
101 	static const constiv request_field_const_iv[] = {
102 #undef const_iv
103 #define const_iv(name) {#name, (IV)PURPLE_REQUEST_FIELD_##name}
104 		const_iv(NONE),
105 		const_iv(STRING),
106 		const_iv(INTEGER),
107 		const_iv(BOOLEAN),
108 		const_iv(CHOICE),
109 		const_iv(LIST),
110 		const_iv(LABEL),
111 		const_iv(IMAGE),
112 		const_iv(ACCOUNT),
113 	};
114 
115 	for (civ = request_const_iv + sizeof(request_const_iv) / sizeof(request_const_iv[0]); civ-- > request_const_iv; )
116 		newCONSTSUB(request_stash, (char *)civ->name, newSViv(civ->iv));
117 
118 	for (civ = request_field_const_iv + sizeof(request_field_const_iv) / sizeof(request_field_const_iv[0]); civ-- > request_field_const_iv; )
119 		newCONSTSUB(request_field_stash, (char *)civ->name, newSViv(civ->iv));
120 }
121 
122 void *
123 purple_request_input(handle, title, primary, secondary, default_value, multiline, masked, hint, ok_text, ok_cb, cancel_text, cancel_cb)
124 	Purple::Plugin handle
125 	const char * title
126 	const char * primary
127 	const char * secondary
128 	const char * default_value
129 	gboolean multiline
130 	gboolean masked
131 	gchar * hint
132 	const char * ok_text
133 	SV * ok_cb
134 	const char * cancel_text
135 	SV * cancel_cb
136 CODE:
137 	PurplePerlRequestData *gpr;
138 	char *basename;
139 
140 	basename = g_path_get_basename(handle->path);
141 	purple_perl_normalize_script_name(basename);
142 	gpr = g_new(PurplePerlRequestData, 1);
143 	gpr->ok_fun = purple_perl_sv_from_fun(handle, ok_cb);
144 	gpr->cancel_fun = purple_perl_sv_from_fun(handle, cancel_cb);
145 	g_free(basename);
146 
147 	RETVAL = purple_request_input(handle, title, primary, secondary, default_value, multiline, masked, hint, ok_text, G_CALLBACK(purple_perl_request_ok_cb), cancel_text, G_CALLBACK(purple_perl_request_cancel_cb), NULL, NULL, NULL, gpr);
148 OUTPUT:
149 	RETVAL
150 
151 void *
152 purple_request_file(handle, title, filename, savedialog, ok_cb, cancel_cb)
153 	Purple::Plugin handle
154 	const char * title
155 	const char * filename
156 	gboolean savedialog
157 	SV * ok_cb
158 	SV * cancel_cb
159 CODE:
160 	PurplePerlRequestData *gpr;
161 	char *basename;
162 
163 	basename = g_path_get_basename(handle->path);
164 	purple_perl_normalize_script_name(basename);
165 	gpr = g_new(PurplePerlRequestData, 1);
166 	gpr->ok_fun = purple_perl_sv_from_fun(handle, ok_cb);
167 	gpr->cancel_fun = purple_perl_sv_from_fun(handle, cancel_cb);
168 	g_free(basename);
169 
170 	RETVAL = purple_request_file(handle, title, filename, savedialog, G_CALLBACK(purple_perl_request_ok_cb), G_CALLBACK(purple_perl_request_cancel_cb), NULL, NULL, NULL, gpr);
171 OUTPUT:
172 	RETVAL
173 
174 void *
175 purple_request_fields(handle, title, primary, secondary, fields, ok_text, ok_cb, cancel_text, cancel_cb)
176 	Purple::Plugin handle
177 	const char * title
178 	const char * primary
179 	const char * secondary
180 	Purple::Request::Fields fields
181 	const char * ok_text
182 	SV * ok_cb
183 	const char * cancel_text
184 	SV * cancel_cb
185 CODE:
186 	PurplePerlRequestData *gpr;
187 	char *basename;
188 
189 	basename = g_path_get_basename(handle->path);
190 	purple_perl_normalize_script_name(basename);
191 	gpr = g_new(PurplePerlRequestData, 1);
192 	gpr->ok_fun = purple_perl_sv_from_fun(handle, ok_cb);
193 	gpr->cancel_fun = purple_perl_sv_from_fun(handle, cancel_cb);
194 	g_free(basename);
195 
196 	RETVAL = purple_request_fields(handle, title, primary, secondary, fields, ok_text, G_CALLBACK(purple_perl_request_ok_cb), cancel_text, G_CALLBACK(purple_perl_request_cancel_cb), NULL, NULL, NULL, gpr);
197 OUTPUT:
198 	RETVAL
199 
200 void
201 purple_request_close(type, uihandle)
202 	Purple::RequestType type
203 	void * uihandle
204 
205 void
206 purple_request_close_with_handle(handle)
207 	void * handle
208 
209 
210 MODULE = Purple::Request  PACKAGE = Purple::Request::Field  PREFIX = purple_request_field_
211 PROTOTYPES: ENABLE
212 
213 Purple::Request::Field
214 purple_request_field_account_new(class, id, text, account = NULL)
215 	const char *id
216 	const char *text
217 	Purple::Account account
218 	C_ARGS: id, text, account
219 
220 Purple::Account
221 purple_request_field_account_get_default_value(field)
222 	Purple::Request::Field field
223 
224 IV
225 purple_request_field_account_get_filter(field)
226 	Purple::Request::Field field
227 CODE:
228 	RETVAL = PTR2IV(purple_request_field_account_get_filter(field));
229 OUTPUT:
230 	RETVAL
231 
232 gboolean
233 purple_request_field_account_get_show_all(field)
234 	Purple::Request::Field field
235 
236 Purple::Account
237 purple_request_field_account_get_value(field)
238 	Purple::Request::Field field
239 
240 void
241 purple_request_field_account_set_default_value(field, default_value)
242 	Purple::Request::Field field
243 	Purple::Account default_value
244 
245 void
246 purple_request_field_account_set_show_all(field, show_all)
247 	Purple::Request::Field field
248 	gboolean show_all
249 
250 void
251 purple_request_field_account_set_value(field, value)
252 	Purple::Request::Field field
253 	Purple::Account value
254 
255 MODULE = Purple::Request  PACKAGE = Purple::Request::Field  PREFIX = purple_request_field_
256 PROTOTYPES: ENABLE
257 
258 Purple::Request::Field
259 purple_request_field_bool_new(class, id, text, default_value = TRUE)
260 	const char *id
261 	const char *text
262 	gboolean default_value
263 	C_ARGS: id, text, default_value
264 
265 gboolean
266 purple_request_field_bool_get_default_value(field)
267 	Purple::Request::Field field
268 
269 gboolean
270 purple_request_field_bool_get_value(field)
271 	Purple::Request::Field field
272 
273 void
274 purple_request_field_bool_set_default_value(field, default_value)
275 	Purple::Request::Field field
276 	gboolean default_value
277 
278 void
279 purple_request_field_bool_set_value(field, value)
280 	Purple::Request::Field field
281 	gboolean value
282 
283 MODULE = Purple::Request  PACKAGE = Purple::Request::Field  PREFIX = purple_request_field_
284 PROTOTYPES: ENABLE
285 
286 Purple::Request::Field
287 purple_request_field_choice_new(class, id, text, default_value = 0)
288 	const char *id
289 	const char *text
290 	int default_value
291 	C_ARGS: id, text, default_value
292 
293 void
294 purple_request_field_choice_add(field, label)
295 	Purple::Request::Field field
296 	const char *label
297 
298 int
299 purple_request_field_choice_get_default_value(field)
300 	Purple::Request::Field field
301 
302 void
303 purple_request_field_choice_get_labels(field)
304 	Purple::Request::Field field
305 PREINIT:
306 	GList *l;
307 PPCODE:
308 	for (l = purple_request_field_choice_get_labels(field); l != NULL; l = l->next) {
309 		XPUSHs(sv_2mortal(newSVpv(l->data, 0)));
310 	}
311 
312 int
313 purple_request_field_choice_get_value(field)
314 	Purple::Request::Field field
315 
316 void
317 purple_request_field_choice_set_default_value(field, default_value)
318 	Purple::Request::Field field
319 	int default_value
320 
321 void
322 purple_request_field_choice_set_value(field, value)
323 	Purple::Request::Field field
324 	int value
325 
326 MODULE = Purple::Request  PACKAGE = Purple::Request::Field  PREFIX = purple_request_field_
327 PROTOTYPES: ENABLE
328 
329 Purple::Request::Field
330 purple_request_field_int_new(clas, id, text, default_value = 0)
331 	const char *id
332 	const char *text
333 	int default_value
334 	C_ARGS: id, text, default_value
335 
336 int
337 purple_request_field_int_get_default_value(field)
338 	Purple::Request::Field field
339 
340 int
341 purple_request_field_int_get_value(field)
342 	Purple::Request::Field field
343 
344 void
345 purple_request_field_int_set_default_value(field, default_value)
346 	Purple::Request::Field field
347 	int default_value
348 
349 void
350 purple_request_field_int_set_value(field, value)
351 	Purple::Request::Field field
352 	int value
353 
354 gboolean
355 purple_request_field_is_required(field)
356 	Purple::Request::Field field
357 
358 MODULE = Purple::Request  PACKAGE = Purple::Request::Field  PREFIX = purple_request_field_
359 PROTOTYPES: ENABLE
360 
361 Purple::Request::Field
362 purple_request_field_label_new(class, id, text)
363 	const char *id
364 	const char *text
365 	C_ARGS: id, text
366 
367 MODULE = Purple::Request  PACKAGE = Purple::Request::Field  PREFIX = purple_request_field_
368 PROTOTYPES: ENABLE
369 
370 Purple::Request::Field
371 purple_request_field_list_new(class, id, text)
372 	const char *id
373 	const char *text
374 	C_ARGS: id, text
375 
376 void
377 purple_request_field_list_add(field, item, data)
378 	Purple::Request::Field field
379 	const char *item
380 	void * data
381 
382 void
383 purple_request_field_list_add_icon(field, item, icon_path, data)
384 	Purple::Request::Field field
385 	const char *item
386 	const char *icon_path
387 	void * data
388 
389 void
390 purple_request_field_list_add_selected(field, item)
391 	Purple::Request::Field field
392 	const char *item
393 
394 void
395 purple_request_field_list_clear_selected(field)
396 	Purple::Request::Field field
397 
398 void *
399 purple_request_field_list_get_data(field, text)
400 	Purple::Request::Field field
401 	const char *text
402 
403 void
404 purple_request_field_list_get_items(field)
405 	Purple::Request::Field field
406 PREINIT:
407 	GList *l;
408 PPCODE:
409 	for (l = purple_request_field_list_get_items(field); l != NULL; l = l->next) {
410 		XPUSHs(sv_2mortal(newSVpv(l->data, 0)));
411 	}
412 
413 gboolean
414 purple_request_field_list_get_multi_select(field)
415 	Purple::Request::Field field
416 
417 void
418 purple_request_field_list_get_selected(field)
419 	Purple::Request::Field field
420 PREINIT:
421 	GList *l;
422 PPCODE:
423 	for (l = purple_request_field_list_get_selected(field); l != NULL; l = l->next) {
424 		XPUSHs(sv_2mortal(newSVpv(l->data, 0)));
425 	}
426 
427 gboolean
428 purple_request_field_list_is_selected(field, item)
429 	Purple::Request::Field field
430 	const char *item
431 
432 void
433 purple_request_field_list_set_multi_select(field, multi_select)
434 	Purple::Request::Field field
435 	gboolean multi_select
436 
437 MODULE = Purple::Request  PACKAGE = Purple::Request::Field  PREFIX = purple_request_field_
438 PROTOTYPES: ENABLE
439 
440 Purple::Request::Field
441 purple_request_field_new(class, id, text, type)
442 	const char *id
443 	const char *text
444 	Purple::RequestFieldType type
445 	C_ARGS: id, text, type
446 
447 void
448 purple_request_field_set_label(field, label)
449 	Purple::Request::Field field
450 	const char *label
451 
452 void
453 purple_request_field_set_required(field, required)
454 	Purple::Request::Field field
455 	gboolean required
456 
457 void
458 purple_request_field_set_type_hint(field, type_hint)
459 	Purple::Request::Field field
460 	const char *type_hint
461 
462 void
463 purple_request_field_set_visible(field, visible)
464 	Purple::Request::Field field
465 	gboolean visible
466 
467 MODULE = Purple::Request  PACKAGE = Purple::Request::Field  PREFIX = purple_request_field_
468 PROTOTYPES: ENABLE
469 
470 Purple::Request::Field
471 purple_request_field_string_new(class, id, text, default_value, multiline)
472 	const char *id
473 	const char *text
474 	const char *default_value
475 	gboolean multiline
476 	C_ARGS: id, text, default_value, multiline
477 
478 const char *
479 purple_request_field_string_get_default_value(field)
480 	Purple::Request::Field field
481 
482 const char *
483 purple_request_field_string_get_value(field)
484 	Purple::Request::Field field
485 
486 gboolean
487 purple_request_field_string_is_editable(field)
488 	Purple::Request::Field field
489 
490 gboolean
491 purple_request_field_string_is_masked(field)
492 	Purple::Request::Field field
493 
494 gboolean
495 purple_request_field_string_is_multiline(field)
496 	Purple::Request::Field field
497 
498 void
499 purple_request_field_string_set_default_value(field, default_value)
500 	Purple::Request::Field field
501 	const char *default_value
502 
503 void
504 purple_request_field_string_set_editable(field, editable)
505 	Purple::Request::Field field
506 	gboolean editable
507 
508 void
509 purple_request_field_string_set_masked(field, masked)
510 	Purple::Request::Field field
511 	gboolean masked
512 
513 void
514 purple_request_field_string_set_value(field, value)
515 	Purple::Request::Field field
516 	const char *value
517 
518 MODULE = Purple::Request  PACKAGE = Purple::Request::Field::Group  PREFIX = purple_request_field_group_
519 PROTOTYPES: ENABLE
520 
521 void
522 purple_request_field_group_add_field(group, field)
523 	Purple::Request::Field::Group group
524 	Purple::Request::Field field
525 
526 void
527 purple_request_field_group_destroy(group)
528 	Purple::Request::Field::Group group
529 
530 void
531 purple_request_field_group_get_fields(group)
532 	Purple::Request::Field::Group group
533 PREINIT:
534 	GList *l;
535 PPCODE:
536 	for (l = purple_request_field_group_get_fields(group); l != NULL; l = l->next) {
537 		XPUSHs(sv_2mortal(purple_perl_bless_object(l->data, "Purple::Request::Field")));
538 	}
539 
540 const char *
541 purple_request_field_group_get_title(group)
542 	Purple::Request::Field::Group group
543 
544 Purple::Request::Field::Group
545 purple_request_field_group_new(class, title)
546 	const char *title
547 	C_ARGS: title
548 
549 MODULE = Purple::Request  PACKAGE = Purple::Request::Field  PREFIX = purple_request_field_
550 PROTOTYPES: ENABLE
551 
552 void
553 purple_request_field_destroy(field)
554 	Purple::Request::Field field
555 
556 const char *
557 purple_request_field_get_id(field)
558 	Purple::Request::Field field
559 
560 const char *
561 purple_request_field_get_label(field)
562 	Purple::Request::Field field
563 
564 Purple::RequestFieldType
565 purple_request_field_get_type(field)
566 	Purple::Request::Field field
567 
568 const char *
569 purple_request_field_get_type_hint(field)
570 	Purple::Request::Field field
571 
572 gboolean
573 purple_request_field_is_visible(field)
574 	Purple::Request::Field field
575 
576 MODULE = Purple::Request  PACKAGE = Purple::Request::Fields  PREFIX = purple_request_fields_
577 PROTOTYPES: ENABLE
578 
579 Purple::Request::Fields
580 purple_request_fields_new(class)
581 	C_ARGS: /* void */
582 
583 void
584 purple_request_fields_add_group(fields, group)
585 	Purple::Request::Fields fields
586 	Purple::Request::Field::Group group
587 
588 gboolean
589 purple_request_fields_all_required_filled(fields)
590 	Purple::Request::Fields fields
591 
592 void
593 purple_request_fields_destroy(fields)
594 	Purple::Request::Fields fields
595 
596 gboolean
597 purple_request_fields_exists(fields, id)
598 	Purple::Request::Fields fields
599 	const char *id
600 
601 Purple::Account
602 purple_request_fields_get_account(fields, id)
603 	Purple::Request::Fields fields
604 	const char *id
605 
606 gboolean
607 purple_request_fields_get_bool(fields, id)
608 	Purple::Request::Fields fields
609 	const char *id
610 
611 int
612 purple_request_fields_get_choice(fields, id)
613 	Purple::Request::Fields fields
614 	const char *id
615 
616 Purple::Request::Field
617 purple_request_fields_get_field(fields, id)
618 	Purple::Request::Fields fields
619 	const char *id
620 
621 void
622 purple_request_fields_get_groups(fields)
623 	Purple::Request::Fields fields
624 PREINIT:
625 	GList *l;
626 PPCODE:
627 	for (l = purple_request_fields_get_groups(fields); l != NULL; l = l->next) {
628 		XPUSHs(sv_2mortal(purple_perl_bless_object(l->data, "Purple::Request::Field::Group")));
629 	}
630 
631 int
632 purple_request_fields_get_integer(fields, id)
633 	Purple::Request::Fields fields
634 	const char *id
635 
636 void
637 purple_request_fields_get_required(fields)
638 	Purple::Request::Fields fields
639 PREINIT:
640 	GList *l;
641 PPCODE:
642 	for (l = purple_request_fields_get_required(fields); l != NULL; l = l->next) {
643 		XPUSHs(sv_2mortal(purple_perl_bless_object(l->data, "Purple::Request::Field")));
644 	}
645 
646 const char *
647 purple_request_fields_get_string(fields, id)
648 	Purple::Request::Fields fields
649 	const char *id
650 
651 gboolean
652 purple_request_fields_is_field_required(fields, id)
653 	Purple::Request::Fields fields
654 	const char *id
655