1 | /* -*- mode: c; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | #ifdef HAVE_LIBZEPHYR |
---|
3 | #include <zephyr/zephyr.h> |
---|
4 | #endif |
---|
5 | #include <EXTERN.h> |
---|
6 | |
---|
7 | #define OWL_PERL |
---|
8 | #include "owl.h" |
---|
9 | |
---|
10 | #define SV_IS_CODEREF(sv) (SvROK((sv)) && SvTYPE(SvRV((sv))) == SVt_PVCV) |
---|
11 | |
---|
12 | typedef char utf8; |
---|
13 | |
---|
14 | /************************************************************* |
---|
15 | * NOTE |
---|
16 | ************************************************************* |
---|
17 | * These functions, when they are intended to be user-visible, |
---|
18 | * are documented in perl/lib/BarnOwl.pm. If you add functions |
---|
19 | * to this file, add the appropriate documentation there! |
---|
20 | * |
---|
21 | * If the function is simple enough, we simply define its |
---|
22 | * entire functionality here in XS. If, however, it needs |
---|
23 | * complex argument processing or something, we define a |
---|
24 | * simple version here that takes arguments in as flat a |
---|
25 | * manner as possible, to simplify the XS code, put it in |
---|
26 | * BarnOwl::Internal::, and write a perl wrapper in BarnOwl.pm |
---|
27 | * that munges the arguments as appropriate and calls the |
---|
28 | * internal version. |
---|
29 | */ |
---|
30 | |
---|
31 | MODULE = BarnOwl PACKAGE = BarnOwl |
---|
32 | |
---|
33 | const utf8 * |
---|
34 | command(cmd, ...) |
---|
35 | const char *cmd |
---|
36 | PREINIT: |
---|
37 | char *rv = NULL; |
---|
38 | const char **argv; |
---|
39 | int i; |
---|
40 | CODE: |
---|
41 | { |
---|
42 | if (items == 1) { |
---|
43 | rv = owl_function_command(cmd); |
---|
44 | } else { |
---|
45 | argv = owl_malloc((items + 1) * sizeof *argv); |
---|
46 | argv[0] = cmd; |
---|
47 | for(i = 1; i < items; i++) { |
---|
48 | argv[i] = SvPV_nolen(ST(i)); |
---|
49 | } |
---|
50 | rv = owl_function_command_argv(argv, items); |
---|
51 | owl_free(argv); |
---|
52 | } |
---|
53 | RETVAL = rv; |
---|
54 | } |
---|
55 | OUTPUT: |
---|
56 | RETVAL |
---|
57 | CLEANUP: |
---|
58 | if (rv) owl_free(rv); |
---|
59 | |
---|
60 | SV * |
---|
61 | getcurmsg() |
---|
62 | CODE: |
---|
63 | RETVAL = owl_perlconfig_curmessage2hashref(); |
---|
64 | OUTPUT: |
---|
65 | RETVAL |
---|
66 | |
---|
67 | int |
---|
68 | getnumcols() |
---|
69 | CODE: |
---|
70 | RETVAL = owl_global_get_cols(&g); |
---|
71 | OUTPUT: |
---|
72 | RETVAL |
---|
73 | |
---|
74 | time_t |
---|
75 | getidletime() |
---|
76 | CODE: |
---|
77 | RETVAL = owl_global_get_idletime(&g); |
---|
78 | OUTPUT: |
---|
79 | RETVAL |
---|
80 | |
---|
81 | const utf8 * |
---|
82 | zephyr_getrealm() |
---|
83 | CODE: |
---|
84 | RETVAL = owl_zephyr_get_realm(); |
---|
85 | OUTPUT: |
---|
86 | RETVAL |
---|
87 | |
---|
88 | const utf8 * |
---|
89 | zephyr_getsender() |
---|
90 | CODE: |
---|
91 | RETVAL = owl_zephyr_get_sender(); |
---|
92 | OUTPUT: |
---|
93 | RETVAL |
---|
94 | |
---|
95 | void |
---|
96 | zephyr_zwrite(cmd,msg) |
---|
97 | const char *cmd |
---|
98 | const char *msg |
---|
99 | PREINIT: |
---|
100 | int i; |
---|
101 | CODE: |
---|
102 | i = owl_zwrite_create_and_send_from_line(cmd, msg); |
---|
103 | |
---|
104 | const utf8 * |
---|
105 | ztext_stylestrip(ztext) |
---|
106 | const char *ztext |
---|
107 | PREINIT: |
---|
108 | char *rv = NULL; |
---|
109 | CODE: |
---|
110 | rv = owl_function_ztext_stylestrip(ztext); |
---|
111 | RETVAL = rv; |
---|
112 | OUTPUT: |
---|
113 | RETVAL |
---|
114 | CLEANUP: |
---|
115 | if (rv) owl_free(rv); |
---|
116 | |
---|
117 | const utf8 * |
---|
118 | zephyr_smartstrip_user(in) |
---|
119 | const char *in |
---|
120 | PREINIT: |
---|
121 | char *rv = NULL; |
---|
122 | CODE: |
---|
123 | { |
---|
124 | rv = owl_zephyr_smartstripped_user(in); |
---|
125 | RETVAL = rv; |
---|
126 | } |
---|
127 | OUTPUT: |
---|
128 | RETVAL |
---|
129 | CLEANUP: |
---|
130 | owl_free(rv); |
---|
131 | |
---|
132 | const utf8 * |
---|
133 | zephyr_getsubs() |
---|
134 | PREINIT: |
---|
135 | char *rv = NULL; |
---|
136 | CODE: |
---|
137 | rv = owl_zephyr_getsubs(); |
---|
138 | RETVAL = rv; |
---|
139 | OUTPUT: |
---|
140 | RETVAL |
---|
141 | CLEANUP: |
---|
142 | if (rv) owl_free(rv); |
---|
143 | |
---|
144 | void |
---|
145 | queue_message(msg) |
---|
146 | SV *msg |
---|
147 | PREINIT: |
---|
148 | owl_message *m; |
---|
149 | CODE: |
---|
150 | { |
---|
151 | if(!SvROK(msg) || SvTYPE(SvRV(msg)) != SVt_PVHV) { |
---|
152 | croak("Usage: BarnOwl::queue_message($message)"); |
---|
153 | } |
---|
154 | |
---|
155 | m = owl_perlconfig_hashref2message(msg); |
---|
156 | |
---|
157 | owl_global_messagequeue_addmsg(&g, m); |
---|
158 | } |
---|
159 | |
---|
160 | void |
---|
161 | admin_message(header, body) |
---|
162 | const char *header |
---|
163 | const char *body |
---|
164 | CODE: |
---|
165 | { |
---|
166 | owl_function_adminmsg(header, body); |
---|
167 | } |
---|
168 | |
---|
169 | void |
---|
170 | start_question(line, callback) |
---|
171 | const char *line |
---|
172 | SV *callback |
---|
173 | PREINIT: |
---|
174 | CODE: |
---|
175 | { |
---|
176 | if(!SV_IS_CODEREF(callback)) |
---|
177 | croak("Callback must be a subref"); |
---|
178 | |
---|
179 | owl_function_start_question(line); |
---|
180 | |
---|
181 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), SvREFCNT_inc(callback)); |
---|
182 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
183 | } |
---|
184 | |
---|
185 | void |
---|
186 | start_password(line, callback) |
---|
187 | const char *line |
---|
188 | SV *callback |
---|
189 | PREINIT: |
---|
190 | CODE: |
---|
191 | { |
---|
192 | if(!SV_IS_CODEREF(callback)) |
---|
193 | croak("Callback must be a subref"); |
---|
194 | |
---|
195 | owl_function_start_password(line); |
---|
196 | |
---|
197 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), SvREFCNT_inc(callback)); |
---|
198 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
199 | } |
---|
200 | |
---|
201 | void |
---|
202 | start_edit_win(line, callback) |
---|
203 | const char *line |
---|
204 | SV *callback |
---|
205 | PREINIT: |
---|
206 | owl_editwin * e; |
---|
207 | char buff[1024]; |
---|
208 | CODE: |
---|
209 | { |
---|
210 | if(!SV_IS_CODEREF(callback)) |
---|
211 | croak("Callback must be a subref"); |
---|
212 | |
---|
213 | e = owl_global_get_typwin(&g); |
---|
214 | owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE, |
---|
215 | owl_global_get_msg_history(&g)); |
---|
216 | owl_editwin_clear(e); |
---|
217 | owl_editwin_set_dotsend(e); |
---|
218 | snprintf(buff, 1023, "----> %s\n", line); |
---|
219 | owl_editwin_set_locktext(e, buff); |
---|
220 | |
---|
221 | owl_global_set_typwin_active(&g); |
---|
222 | |
---|
223 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), SvREFCNT_inc(callback)); |
---|
224 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
225 | } |
---|
226 | |
---|
227 | |
---|
228 | const char * |
---|
229 | get_data_dir () |
---|
230 | CODE: |
---|
231 | RETVAL = owl_get_datadir(); |
---|
232 | OUTPUT: |
---|
233 | RETVAL |
---|
234 | |
---|
235 | const char * |
---|
236 | get_config_dir () |
---|
237 | CODE: |
---|
238 | RETVAL = owl_global_get_confdir(&g); |
---|
239 | OUTPUT: |
---|
240 | RETVAL |
---|
241 | |
---|
242 | void |
---|
243 | popless_text(text) |
---|
244 | const char *text |
---|
245 | CODE: |
---|
246 | { |
---|
247 | owl_function_popless_text(text); |
---|
248 | } |
---|
249 | |
---|
250 | void |
---|
251 | popless_ztext(text) |
---|
252 | const char *text |
---|
253 | CODE: |
---|
254 | { |
---|
255 | owl_fmtext fm; |
---|
256 | owl_fmtext_init_null(&fm); |
---|
257 | owl_fmtext_append_ztext(&fm, text); |
---|
258 | owl_function_popless_fmtext(&fm); |
---|
259 | owl_fmtext_free(&fm); |
---|
260 | } |
---|
261 | |
---|
262 | void |
---|
263 | error(text) |
---|
264 | const char *text |
---|
265 | CODE: |
---|
266 | { |
---|
267 | owl_function_error("%s", text); |
---|
268 | } |
---|
269 | |
---|
270 | void |
---|
271 | debug(text) |
---|
272 | const char *text |
---|
273 | CODE: |
---|
274 | { |
---|
275 | owl_function_debugmsg("%s", text); |
---|
276 | } |
---|
277 | |
---|
278 | void |
---|
279 | message(text) |
---|
280 | const char *text |
---|
281 | CODE: |
---|
282 | { |
---|
283 | owl_function_makemsg("%s", text); |
---|
284 | } |
---|
285 | |
---|
286 | void |
---|
287 | create_style(name, object) |
---|
288 | const char *name |
---|
289 | SV *object |
---|
290 | PREINIT: |
---|
291 | owl_style *s; |
---|
292 | CODE: |
---|
293 | { |
---|
294 | s = owl_malloc(sizeof(owl_style)); |
---|
295 | owl_style_create_perl(s, name, object); |
---|
296 | owl_global_add_style(&g, s); |
---|
297 | } |
---|
298 | |
---|
299 | int |
---|
300 | getnumcolors() |
---|
301 | CODE: |
---|
302 | RETVAL = owl_function_get_color_count(); |
---|
303 | OUTPUT: |
---|
304 | RETVAL |
---|
305 | |
---|
306 | void |
---|
307 | _remove_filter(filterName) |
---|
308 | const char *filterName |
---|
309 | CODE: |
---|
310 | { |
---|
311 | /* Don't delete the current view, or the 'all' filter */ |
---|
312 | if (strcmp(filterName, owl_view_get_filtname(owl_global_get_current_view(&g))) |
---|
313 | && strcmp(filterName, "all")) { |
---|
314 | owl_global_remove_filter(&g,filterName); |
---|
315 | } |
---|
316 | } |
---|
317 | |
---|
318 | const utf8 * |
---|
319 | wordwrap(in, cols) |
---|
320 | const char *in |
---|
321 | int cols |
---|
322 | PREINIT: |
---|
323 | char *rv = NULL; |
---|
324 | CODE: |
---|
325 | rv = owl_text_wordwrap(in, cols); |
---|
326 | RETVAL = rv; |
---|
327 | OUTPUT: |
---|
328 | RETVAL |
---|
329 | CLEANUP: |
---|
330 | if (rv) |
---|
331 | owl_free(rv); |
---|
332 | |
---|
333 | void |
---|
334 | add_dispatch(fd, cb) |
---|
335 | int fd |
---|
336 | SV * cb |
---|
337 | CODE: |
---|
338 | owl_select_add_perl_dispatch(fd, SvREFCNT_inc(cb)); |
---|
339 | |
---|
340 | void |
---|
341 | remove_dispatch(fd) |
---|
342 | int fd |
---|
343 | CODE: |
---|
344 | owl_select_remove_perl_dispatch(fd); |
---|
345 | |
---|
346 | |
---|
347 | AV* |
---|
348 | all_filters() |
---|
349 | PREINIT: |
---|
350 | AV *filters; |
---|
351 | const owl_list *fl; |
---|
352 | const owl_filter *f; |
---|
353 | int i; |
---|
354 | CODE: |
---|
355 | { |
---|
356 | fl = owl_global_get_filterlist(&g); |
---|
357 | filters = newAV(); |
---|
358 | for(i=0;i<owl_list_get_size(fl);i++) { |
---|
359 | f = owl_list_get_element(fl, i); |
---|
360 | av_push(filters, owl_new_sv(owl_filter_get_name(f))); |
---|
361 | } |
---|
362 | RETVAL = filters; |
---|
363 | sv_2mortal((SV*)RETVAL); |
---|
364 | } |
---|
365 | OUTPUT: |
---|
366 | RETVAL |
---|
367 | |
---|
368 | AV* |
---|
369 | all_styles() |
---|
370 | PREINIT: |
---|
371 | AV *styles; |
---|
372 | owl_list l; |
---|
373 | const char *name; |
---|
374 | int i; |
---|
375 | CODE: |
---|
376 | { |
---|
377 | owl_list_create(&l); |
---|
378 | owl_global_get_style_names(&g, &l); |
---|
379 | styles = newAV(); |
---|
380 | for(i=0;i<owl_list_get_size(&l);i++) { |
---|
381 | name = owl_list_get_element(&l, i); |
---|
382 | av_push(styles, owl_new_sv(name)); |
---|
383 | } |
---|
384 | RETVAL = styles; |
---|
385 | sv_2mortal((SV*)RETVAL); |
---|
386 | } |
---|
387 | OUTPUT: |
---|
388 | RETVAL |
---|
389 | CLEANUP: |
---|
390 | owl_list_free_all(&l, owl_free); |
---|
391 | |
---|
392 | |
---|
393 | AV* |
---|
394 | all_variables() |
---|
395 | PREINIT: |
---|
396 | AV *vars; |
---|
397 | owl_list l; |
---|
398 | const char *name; |
---|
399 | int i; |
---|
400 | CODE: |
---|
401 | { |
---|
402 | owl_list_create(&l); |
---|
403 | owl_dict_get_keys(owl_global_get_vardict(&g), &l); |
---|
404 | vars = newAV(); |
---|
405 | for(i=0;i<owl_list_get_size(&l);i++) { |
---|
406 | name = owl_list_get_element(&l, i); |
---|
407 | av_push(vars, owl_new_sv(name)); |
---|
408 | } |
---|
409 | RETVAL = vars; |
---|
410 | sv_2mortal((SV*)RETVAL); |
---|
411 | } |
---|
412 | OUTPUT: |
---|
413 | RETVAL |
---|
414 | CLEANUP: |
---|
415 | owl_list_free_all(&l, owl_free); |
---|
416 | |
---|
417 | void |
---|
418 | redisplay() |
---|
419 | CODE: |
---|
420 | { |
---|
421 | owl_messagelist_invalidate_formats(owl_global_get_msglist(&g)); |
---|
422 | owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS); |
---|
423 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
424 | } |
---|
425 | |
---|
426 | const char * |
---|
427 | get_zephyr_variable(name) |
---|
428 | const char *name; |
---|
429 | CODE: |
---|
430 | RETVAL = owl_zephyr_get_variable(name); |
---|
431 | OUTPUT: |
---|
432 | RETVAL |
---|
433 | |
---|
434 | const utf8 * |
---|
435 | skiptokens(str, n) |
---|
436 | const char *str; |
---|
437 | int n; |
---|
438 | CODE: |
---|
439 | RETVAL = skiptokens(str, n); |
---|
440 | OUTPUT: |
---|
441 | RETVAL |
---|
442 | |
---|
443 | |
---|
444 | |
---|
445 | MODULE = BarnOwl PACKAGE = BarnOwl::Internal |
---|
446 | |
---|
447 | |
---|
448 | void |
---|
449 | new_command(name, func, summary, usage, description) |
---|
450 | char *name |
---|
451 | SV *func |
---|
452 | char *summary |
---|
453 | char *usage |
---|
454 | char *description |
---|
455 | PREINIT: |
---|
456 | owl_cmd cmd; |
---|
457 | CODE: |
---|
458 | { |
---|
459 | if(!SV_IS_CODEREF(func)) { |
---|
460 | croak("Command function must be a coderef!"); |
---|
461 | } |
---|
462 | cmd.name = name; |
---|
463 | cmd.cmd_perl = SvREFCNT_inc(func); |
---|
464 | cmd.summary = summary; |
---|
465 | cmd.usage = usage; |
---|
466 | cmd.description = description; |
---|
467 | cmd.validctx = OWL_CTX_ANY; |
---|
468 | cmd.cmd_aliased_to = NULL; |
---|
469 | cmd.cmd_args_fn = NULL; |
---|
470 | cmd.cmd_v_fn = NULL; |
---|
471 | cmd.cmd_i_fn = NULL; |
---|
472 | cmd.cmd_ctxargs_fn = NULL; |
---|
473 | cmd.cmd_ctxv_fn = NULL; |
---|
474 | cmd.cmd_ctxi_fn = NULL; |
---|
475 | owl_cmddict_add_cmd(owl_global_get_cmddict(&g), &cmd); |
---|
476 | } |
---|
477 | |
---|
478 | void |
---|
479 | new_variable_string(name, ival, summ, desc) |
---|
480 | const char * name |
---|
481 | const char * ival |
---|
482 | const char * summ |
---|
483 | const char * desc |
---|
484 | CODE: |
---|
485 | owl_variable_dict_newvar_string(owl_global_get_vardict(&g), |
---|
486 | name, |
---|
487 | summ, |
---|
488 | desc, |
---|
489 | ival); |
---|
490 | |
---|
491 | void |
---|
492 | new_variable_int(name, ival, summ, desc) |
---|
493 | const char * name |
---|
494 | int ival |
---|
495 | const char * summ |
---|
496 | const char * desc |
---|
497 | CODE: |
---|
498 | owl_variable_dict_newvar_int(owl_global_get_vardict(&g), |
---|
499 | name, |
---|
500 | summ, |
---|
501 | desc, |
---|
502 | ival); |
---|
503 | |
---|
504 | void |
---|
505 | new_variable_bool(name, ival, summ, desc) |
---|
506 | const char * name |
---|
507 | int ival |
---|
508 | const char * summ |
---|
509 | const char * desc |
---|
510 | CODE: |
---|
511 | owl_variable_dict_newvar_bool(owl_global_get_vardict(&g), |
---|
512 | name, |
---|
513 | summ, |
---|
514 | desc, |
---|
515 | ival); |
---|
516 | |
---|
517 | IV |
---|
518 | add_timer(after, interval, cb) |
---|
519 | int after |
---|
520 | int interval |
---|
521 | SV *cb |
---|
522 | PREINIT: |
---|
523 | SV *ref; |
---|
524 | owl_timer *t; |
---|
525 | CODE: |
---|
526 | ref = sv_rvweaken(newSVsv(cb)); |
---|
527 | t = owl_select_add_timer(after, |
---|
528 | interval, |
---|
529 | owl_perlconfig_perl_timer, |
---|
530 | owl_perlconfig_perl_timer_destroy, |
---|
531 | ref); |
---|
532 | owl_function_debugmsg("Created timer %p", t); |
---|
533 | RETVAL = (IV)t; |
---|
534 | OUTPUT: |
---|
535 | RETVAL |
---|
536 | |
---|
537 | void |
---|
538 | remove_timer(timer) |
---|
539 | IV timer |
---|
540 | PREINIT: |
---|
541 | owl_timer *t; |
---|
542 | CODE: |
---|
543 | t = (owl_timer*)timer; |
---|
544 | owl_function_debugmsg("Freeing timer %p", t); |
---|
545 | owl_select_remove_timer(t); |
---|
546 | |
---|
547 | MODULE = BarnOwl PACKAGE = BarnOwl::Editwin |
---|
548 | |
---|
549 | int |
---|
550 | replace(count, string) |
---|
551 | int count; |
---|
552 | const char *string; |
---|
553 | CODE: |
---|
554 | RETVAL = owl_editwin_replace(owl_global_get_typwin(&g), count, string); |
---|
555 | OUTPUT: |
---|
556 | RETVAL |
---|
557 | |
---|
558 | int |
---|
559 | point_move(delta) |
---|
560 | int delta; |
---|
561 | CODE: |
---|
562 | RETVAL = owl_editwin_point_move(owl_global_get_typwin(&g), delta); |
---|
563 | OUTPUT: |
---|
564 | RETVAL |
---|
565 | |
---|
566 | int |
---|
567 | replace_region(string) |
---|
568 | const char *string; |
---|
569 | CODE: |
---|
570 | RETVAL = owl_editwin_replace_region(owl_global_get_typwin(&g), string); |
---|
571 | OUTPUT: |
---|
572 | RETVAL |
---|
573 | |
---|
574 | const utf8 * |
---|
575 | get_region() |
---|
576 | PREINIT: |
---|
577 | char *region; |
---|
578 | CODE: |
---|
579 | region = owl_editwin_get_region(owl_global_get_typwin(&g)); |
---|
580 | RETVAL = region; |
---|
581 | OUTPUT: |
---|
582 | RETVAL |
---|
583 | CLEANUP: |
---|
584 | owl_free(region); |
---|
585 | |
---|
586 | SV * |
---|
587 | save_excursion(sub) |
---|
588 | SV *sub; |
---|
589 | PROTOTYPE: & |
---|
590 | PREINIT: |
---|
591 | int count; |
---|
592 | owl_editwin_excursion *x; |
---|
593 | CODE: |
---|
594 | { |
---|
595 | x = owl_editwin_begin_excursion(owl_global_get_typwin(&g)); |
---|
596 | PUSHMARK(SP); |
---|
597 | count = call_sv(sub, G_SCALAR|G_EVAL|G_NOARGS); |
---|
598 | SPAGAIN; |
---|
599 | owl_editwin_end_excursion(owl_global_get_typwin(&g), x); |
---|
600 | |
---|
601 | if(SvTRUE(ERRSV)) { |
---|
602 | croak(NULL); |
---|
603 | } |
---|
604 | |
---|
605 | if(count == 1) |
---|
606 | RETVAL = SvREFCNT_inc(POPs); |
---|
607 | else |
---|
608 | XSRETURN_UNDEF; |
---|
609 | |
---|
610 | } |
---|
611 | OUTPUT: |
---|
612 | RETVAL |
---|
613 | |
---|
614 | int |
---|
615 | current_column() |
---|
616 | CODE: |
---|
617 | RETVAL = owl_editwin_current_column(owl_global_get_typwin(&g)); |
---|
618 | OUTPUT: |
---|
619 | RETVAL |
---|
620 | |
---|
621 | int |
---|
622 | point() |
---|
623 | CODE: |
---|
624 | RETVAL = owl_editwin_get_point(owl_global_get_typwin(&g)); |
---|
625 | OUTPUT: |
---|
626 | RETVAL |
---|
627 | |
---|
628 | int |
---|
629 | mark() |
---|
630 | CODE: |
---|
631 | RETVAL = owl_editwin_get_mark(owl_global_get_typwin(&g)); |
---|
632 | OUTPUT: |
---|
633 | RETVAL |
---|