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