1 | /* -*- mode: c; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | static const char fileIdent[] = "$Id$"; |
---|
3 | |
---|
4 | #ifdef HAVE_LIBZEPHYR |
---|
5 | #include <zephyr/zephyr.h> |
---|
6 | #endif |
---|
7 | #include <EXTERN.h> |
---|
8 | |
---|
9 | #define OWL_PERL |
---|
10 | #include "owl.h" |
---|
11 | SV *owl_perlconfig_curmessage2hashref(void); |
---|
12 | |
---|
13 | #define SV_IS_CODEREF(sv) (SvROK((sv)) && SvTYPE(SvRV((sv))) == SVt_PVCV) |
---|
14 | |
---|
15 | /************************************************************* |
---|
16 | * NOTE |
---|
17 | ************************************************************* |
---|
18 | * These functions, when they are intended to be user-visible, |
---|
19 | * are documented in perlwrap.pm. If you add functions to this |
---|
20 | * file, add the appropriate documentation there! |
---|
21 | * |
---|
22 | * If the function is simple enough, we simply define its |
---|
23 | * entire functionality here in XS. If, however, it needs |
---|
24 | * complex argument processing or something, we define a |
---|
25 | * simple version here that takes arguments in as flat a |
---|
26 | * manner as possible, to simplify the XS code, put it in |
---|
27 | * BarnOwl::Intenal::, and write a perl wrapper in perlwrap.pm |
---|
28 | * that munges the arguments as appropriate and calls the |
---|
29 | * internal version. |
---|
30 | */ |
---|
31 | |
---|
32 | MODULE = BarnOwl PACKAGE = BarnOwl |
---|
33 | |
---|
34 | char * |
---|
35 | command(cmd, ...) |
---|
36 | char *cmd |
---|
37 | PREINIT: |
---|
38 | char *rv = NULL; |
---|
39 | char **argv; |
---|
40 | int i; |
---|
41 | CODE: |
---|
42 | { |
---|
43 | if (items == 1) { |
---|
44 | rv = owl_function_command(cmd); |
---|
45 | } else { |
---|
46 | argv = owl_malloc((items + 1) * sizeof *argv); |
---|
47 | argv[0] = cmd; |
---|
48 | for(i = 1; i < items; i++) { |
---|
49 | argv[i] = SvPV_nolen(ST(i)); |
---|
50 | } |
---|
51 | rv = owl_function_command_argv(argv, items); |
---|
52 | owl_free(argv); |
---|
53 | } |
---|
54 | RETVAL = rv; |
---|
55 | } |
---|
56 | OUTPUT: |
---|
57 | RETVAL |
---|
58 | CLEANUP: |
---|
59 | if (rv) owl_free(rv); |
---|
60 | |
---|
61 | SV * |
---|
62 | getcurmsg() |
---|
63 | CODE: |
---|
64 | RETVAL = owl_perlconfig_curmessage2hashref(); |
---|
65 | OUTPUT: |
---|
66 | RETVAL |
---|
67 | |
---|
68 | int |
---|
69 | getnumcols() |
---|
70 | CODE: |
---|
71 | RETVAL = owl_global_get_cols(&g); |
---|
72 | OUTPUT: |
---|
73 | RETVAL |
---|
74 | |
---|
75 | time_t |
---|
76 | getidletime() |
---|
77 | CODE: |
---|
78 | RETVAL = owl_global_get_idletime(&g); |
---|
79 | OUTPUT: |
---|
80 | RETVAL |
---|
81 | |
---|
82 | char * |
---|
83 | zephyr_getrealm() |
---|
84 | CODE: |
---|
85 | RETVAL = owl_zephyr_get_realm(); |
---|
86 | OUTPUT: |
---|
87 | RETVAL |
---|
88 | |
---|
89 | char * |
---|
90 | zephyr_getsender() |
---|
91 | CODE: |
---|
92 | RETVAL = owl_zephyr_get_sender(); |
---|
93 | OUTPUT: |
---|
94 | RETVAL |
---|
95 | |
---|
96 | void |
---|
97 | zephyr_zwrite(cmd,msg) |
---|
98 | char *cmd |
---|
99 | char *msg |
---|
100 | PREINIT: |
---|
101 | int i; |
---|
102 | CODE: |
---|
103 | i = owl_zwrite_create_and_send_from_line(cmd, msg); |
---|
104 | |
---|
105 | char * |
---|
106 | ztext_stylestrip(ztext) |
---|
107 | char *ztext |
---|
108 | PREINIT: |
---|
109 | char *rv = NULL; |
---|
110 | CODE: |
---|
111 | rv = owl_function_ztext_stylestrip(ztext); |
---|
112 | RETVAL = rv; |
---|
113 | OUTPUT: |
---|
114 | RETVAL |
---|
115 | CLEANUP: |
---|
116 | if (rv) owl_free(rv); |
---|
117 | |
---|
118 | char * |
---|
119 | zephyr_smartstrip_user(in) |
---|
120 | char *in |
---|
121 | PREINIT: |
---|
122 | char *rv = NULL; |
---|
123 | CODE: |
---|
124 | { |
---|
125 | rv = owl_zephyr_smartstripped_user(in); |
---|
126 | RETVAL = rv; |
---|
127 | } |
---|
128 | OUTPUT: |
---|
129 | RETVAL |
---|
130 | CLEANUP: |
---|
131 | owl_free(rv); |
---|
132 | |
---|
133 | char * |
---|
134 | zephyr_getsubs() |
---|
135 | PREINIT: |
---|
136 | char *rv = NULL; |
---|
137 | CODE: |
---|
138 | rv = owl_zephyr_getsubs(); |
---|
139 | RETVAL = rv; |
---|
140 | OUTPUT: |
---|
141 | RETVAL |
---|
142 | CLEANUP: |
---|
143 | if (rv) owl_free(rv); |
---|
144 | |
---|
145 | void 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 admin_message(header, body) |
---|
161 | char *header |
---|
162 | char *body |
---|
163 | CODE: |
---|
164 | { |
---|
165 | owl_function_adminmsg(header, body); |
---|
166 | } |
---|
167 | |
---|
168 | void start_question(line, callback) |
---|
169 | char *line |
---|
170 | SV *callback |
---|
171 | PREINIT: |
---|
172 | CODE: |
---|
173 | { |
---|
174 | if(!SV_IS_CODEREF(callback)) |
---|
175 | croak("Callback must be a subref"); |
---|
176 | |
---|
177 | owl_function_start_question(line); |
---|
178 | |
---|
179 | SvREFCNT_inc(callback); |
---|
180 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
181 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
182 | } |
---|
183 | |
---|
184 | void start_password(line, callback) |
---|
185 | char *line |
---|
186 | SV *callback |
---|
187 | PREINIT: |
---|
188 | CODE: |
---|
189 | { |
---|
190 | if(!SV_IS_CODEREF(callback)) |
---|
191 | croak("Callback must be a subref"); |
---|
192 | |
---|
193 | owl_function_start_password(line); |
---|
194 | |
---|
195 | SvREFCNT_inc(callback); |
---|
196 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
197 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
198 | } |
---|
199 | |
---|
200 | void start_edit_win(line, callback) |
---|
201 | char *line |
---|
202 | SV *callback |
---|
203 | PREINIT: |
---|
204 | owl_editwin * e; |
---|
205 | char buff[1024]; |
---|
206 | CODE: |
---|
207 | { |
---|
208 | if(!SV_IS_CODEREF(callback)) |
---|
209 | croak("Callback must be a subref"); |
---|
210 | |
---|
211 | e = owl_global_get_typwin(&g); |
---|
212 | owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE, |
---|
213 | owl_global_get_msg_history(&g)); |
---|
214 | owl_editwin_clear(e); |
---|
215 | owl_editwin_set_dotsend(e); |
---|
216 | snprintf(buff, 1023, "----> %s\n", line); |
---|
217 | owl_editwin_set_locktext(e, buff); |
---|
218 | |
---|
219 | owl_global_set_typwin_active(&g); |
---|
220 | |
---|
221 | SvREFCNT_inc(callback); |
---|
222 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
223 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
224 | } |
---|
225 | |
---|
226 | |
---|
227 | char * |
---|
228 | get_data_dir () |
---|
229 | CODE: |
---|
230 | RETVAL = (char *) owl_get_datadir(); |
---|
231 | OUTPUT: |
---|
232 | RETVAL |
---|
233 | |
---|
234 | char * |
---|
235 | get_config_dir () |
---|
236 | CODE: |
---|
237 | RETVAL = (char *) owl_global_get_confdir(&g); |
---|
238 | OUTPUT: |
---|
239 | RETVAL |
---|
240 | |
---|
241 | void |
---|
242 | popless_text(text) |
---|
243 | char *text |
---|
244 | CODE: |
---|
245 | { |
---|
246 | owl_function_popless_text(text); |
---|
247 | } |
---|
248 | |
---|
249 | void |
---|
250 | popless_ztext(text) |
---|
251 | char *text |
---|
252 | CODE: |
---|
253 | { |
---|
254 | owl_fmtext fm; |
---|
255 | owl_fmtext_init_null(&fm); |
---|
256 | owl_fmtext_append_ztext(&fm, text); |
---|
257 | owl_function_popless_fmtext(&fm); |
---|
258 | owl_fmtext_free(&fm); |
---|
259 | } |
---|
260 | |
---|
261 | void |
---|
262 | error(text) |
---|
263 | char *text |
---|
264 | CODE: |
---|
265 | { |
---|
266 | owl_function_error("%s", text); |
---|
267 | } |
---|
268 | |
---|
269 | void |
---|
270 | create_style(name, object) |
---|
271 | char *name |
---|
272 | SV *object |
---|
273 | PREINIT: |
---|
274 | owl_style *s; |
---|
275 | CODE: |
---|
276 | { |
---|
277 | s = owl_malloc(sizeof(owl_style)); |
---|
278 | owl_style_create_perl(s, name, object); |
---|
279 | owl_global_add_style(&g, s); |
---|
280 | } |
---|
281 | |
---|
282 | int |
---|
283 | getnumcolors() |
---|
284 | CODE: |
---|
285 | RETVAL = owl_function_get_color_count(); |
---|
286 | OUTPUT: |
---|
287 | RETVAL |
---|
288 | |
---|
289 | void |
---|
290 | _remove_filter(filterName) |
---|
291 | char *filterName |
---|
292 | CODE: |
---|
293 | { |
---|
294 | /* Don't delete the current view, or the 'all' filter */ |
---|
295 | if (strcmp(filterName, owl_view_get_filtname(owl_global_get_current_view(&g))) |
---|
296 | && strcmp(filterName, "all")) { |
---|
297 | owl_global_remove_filter(&g,filterName); |
---|
298 | } |
---|
299 | } |
---|
300 | |
---|
301 | char * |
---|
302 | wordwrap(in, cols) |
---|
303 | char *in |
---|
304 | int cols |
---|
305 | PREINIT: |
---|
306 | char *rv = NULL; |
---|
307 | CODE: |
---|
308 | rv = owl_text_wordwrap(in, cols); |
---|
309 | RETVAL = rv; |
---|
310 | OUTPUT: |
---|
311 | RETVAL |
---|
312 | CLEANUP: |
---|
313 | if (rv) owl_free(rv); |
---|
314 | |
---|
315 | void |
---|
316 | add_dispatch(fd, cb) |
---|
317 | int fd |
---|
318 | SV * cb |
---|
319 | CODE: |
---|
320 | SvREFCNT_inc(cb); |
---|
321 | owl_select_add_perl_dispatch(fd, cb); |
---|
322 | |
---|
323 | void |
---|
324 | remove_dispatch(fd) |
---|
325 | int fd |
---|
326 | CODE: |
---|
327 | owl_select_remove_perl_dispatch(fd); |
---|
328 | |
---|
329 | MODULE = BarnOwl PACKAGE = BarnOwl::Internal |
---|
330 | |
---|
331 | |
---|
332 | void |
---|
333 | new_command(name, func, summary, usage, description) |
---|
334 | char *name |
---|
335 | SV *func |
---|
336 | char *summary |
---|
337 | char *usage |
---|
338 | char *description |
---|
339 | PREINIT: |
---|
340 | owl_cmd cmd; |
---|
341 | CODE: |
---|
342 | { |
---|
343 | if(!SV_IS_CODEREF(func)) { |
---|
344 | croak("Command function must be a coderef!"); |
---|
345 | } |
---|
346 | SvREFCNT_inc(func); |
---|
347 | cmd.name = name; |
---|
348 | cmd.cmd_perl = func; |
---|
349 | cmd.summary = summary; |
---|
350 | cmd.usage = usage; |
---|
351 | cmd.description = description; |
---|
352 | cmd.validctx = OWL_CTX_ANY; |
---|
353 | cmd.cmd_aliased_to = NULL; |
---|
354 | cmd.cmd_args_fn = NULL; |
---|
355 | cmd.cmd_v_fn = NULL; |
---|
356 | cmd.cmd_i_fn = NULL; |
---|
357 | cmd.cmd_ctxargs_fn = NULL; |
---|
358 | cmd.cmd_ctxv_fn = NULL; |
---|
359 | cmd.cmd_ctxi_fn = NULL; |
---|
360 | owl_cmddict_add_cmd(owl_global_get_cmddict(&g), &cmd); |
---|
361 | } |
---|
362 | |
---|
363 | void |
---|
364 | new_variable_string(name, ival, summ, desc) |
---|
365 | char * name |
---|
366 | char * ival |
---|
367 | char * summ |
---|
368 | char * desc |
---|
369 | CODE: |
---|
370 | owl_variable_dict_newvar_string(owl_global_get_vardict(&g), |
---|
371 | name, |
---|
372 | summ, |
---|
373 | desc, |
---|
374 | ival); |
---|
375 | |
---|
376 | void |
---|
377 | new_variable_int(name, ival, summ, desc) |
---|
378 | char * name |
---|
379 | int ival |
---|
380 | char * summ |
---|
381 | char * desc |
---|
382 | CODE: |
---|
383 | owl_variable_dict_newvar_int(owl_global_get_vardict(&g), |
---|
384 | name, |
---|
385 | summ, |
---|
386 | desc, |
---|
387 | ival); |
---|
388 | |
---|
389 | void |
---|
390 | new_variable_bool(name, ival, summ, desc) |
---|
391 | char * name |
---|
392 | int ival |
---|
393 | char * summ |
---|
394 | char * desc |
---|
395 | CODE: |
---|
396 | owl_variable_dict_newvar_bool(owl_global_get_vardict(&g), |
---|
397 | name, |
---|
398 | summ, |
---|
399 | desc, |
---|
400 | ival); |
---|
401 | |
---|
402 | IV |
---|
403 | add_timer(after, interval, cb) |
---|
404 | int after |
---|
405 | int interval |
---|
406 | SV *cb |
---|
407 | PREINIT: |
---|
408 | SV *ref; |
---|
409 | owl_timer *t; |
---|
410 | CODE: |
---|
411 | ref = sv_rvweaken(newSVsv(cb)); |
---|
412 | t = owl_select_add_timer(after, |
---|
413 | interval, |
---|
414 | owl_perlconfig_perl_timer, |
---|
415 | owl_perlconfig_perl_timer_destroy, |
---|
416 | ref); |
---|
417 | owl_function_debugmsg("Created timer %p", t); |
---|
418 | RETVAL = (IV)t; |
---|
419 | OUTPUT: |
---|
420 | RETVAL |
---|
421 | |
---|
422 | void |
---|
423 | remove_timer(timer) |
---|
424 | IV timer |
---|
425 | PREINIT: |
---|
426 | owl_timer *t; |
---|
427 | CODE: |
---|
428 | t = (owl_timer*)timer; |
---|
429 | owl_function_debugmsg("Freeing timer %p", t); |
---|
430 | owl_select_remove_timer(t); |
---|