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, with a name |
---|
27 | * with a trailing `_internal', and write a perl wrapper in |
---|
28 | * perlwrap.pm that munges the arguments as appropriate and |
---|
29 | * calls the 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 | ST(0) = owl_perlconfig_curmessage2hashref(); |
---|
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 | char * |
---|
81 | zephyr_getrealm() |
---|
82 | CODE: |
---|
83 | RETVAL = owl_zephyr_get_realm(); |
---|
84 | OUTPUT: |
---|
85 | RETVAL |
---|
86 | |
---|
87 | 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 | char *cmd |
---|
97 | 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 | 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 | 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 |
---|
144 | new_command_internal(name, func, summary, usage, description) |
---|
145 | char *name |
---|
146 | SV *func |
---|
147 | char *summary |
---|
148 | char *usage |
---|
149 | char *description |
---|
150 | PREINIT: |
---|
151 | owl_cmd cmd; |
---|
152 | CODE: |
---|
153 | { |
---|
154 | if(!SV_IS_CODEREF(func)) { |
---|
155 | croak("Command function must be a coderef!"); |
---|
156 | } |
---|
157 | SvREFCNT_inc(func); |
---|
158 | cmd.name = name; |
---|
159 | cmd.cmd_perl = func; |
---|
160 | cmd.summary = summary; |
---|
161 | cmd.usage = usage; |
---|
162 | cmd.description = description; |
---|
163 | cmd.validctx = OWL_CTX_ANY; |
---|
164 | cmd.cmd_aliased_to = NULL; |
---|
165 | cmd.cmd_args_fn = NULL; |
---|
166 | cmd.cmd_v_fn = NULL; |
---|
167 | cmd.cmd_i_fn = NULL; |
---|
168 | cmd.cmd_ctxargs_fn = NULL; |
---|
169 | cmd.cmd_ctxv_fn = NULL; |
---|
170 | cmd.cmd_ctxi_fn = NULL; |
---|
171 | owl_cmddict_add_cmd(owl_global_get_cmddict(&g), &cmd); |
---|
172 | } |
---|
173 | |
---|
174 | void queue_message(msg) |
---|
175 | SV *msg |
---|
176 | PREINIT: |
---|
177 | owl_message *m; |
---|
178 | CODE: |
---|
179 | { |
---|
180 | if(!SvROK(msg) || SvTYPE(SvRV(msg)) != SVt_PVHV) { |
---|
181 | croak("Usage: BarnOwl::queue_message($message)"); |
---|
182 | } |
---|
183 | |
---|
184 | m = owl_perlconfig_hashref2message(msg); |
---|
185 | |
---|
186 | owl_global_messagequeue_addmsg(&g, m); |
---|
187 | } |
---|
188 | |
---|
189 | void admin_message(header, body) |
---|
190 | char *header |
---|
191 | char *body |
---|
192 | CODE: |
---|
193 | { |
---|
194 | owl_function_adminmsg(header, body); |
---|
195 | } |
---|
196 | |
---|
197 | void start_question(line, callback) |
---|
198 | char *line |
---|
199 | SV *callback |
---|
200 | PREINIT: |
---|
201 | CODE: |
---|
202 | { |
---|
203 | if(!SV_IS_CODEREF(callback)) |
---|
204 | croak("Callback must be a subref"); |
---|
205 | |
---|
206 | owl_function_start_question(line); |
---|
207 | |
---|
208 | SvREFCNT_inc(callback); |
---|
209 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
210 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
211 | } |
---|
212 | |
---|
213 | void start_password(line, callback) |
---|
214 | char *line |
---|
215 | SV *callback |
---|
216 | PREINIT: |
---|
217 | CODE: |
---|
218 | { |
---|
219 | if(!SV_IS_CODEREF(callback)) |
---|
220 | croak("Callback must be a subref"); |
---|
221 | |
---|
222 | owl_function_start_password(line); |
---|
223 | |
---|
224 | SvREFCNT_inc(callback); |
---|
225 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
226 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
227 | } |
---|
228 | |
---|
229 | void start_edit_win(line, callback) |
---|
230 | char *line |
---|
231 | SV *callback |
---|
232 | PREINIT: |
---|
233 | owl_editwin * e; |
---|
234 | char buff[1024]; |
---|
235 | CODE: |
---|
236 | { |
---|
237 | if(!SV_IS_CODEREF(callback)) |
---|
238 | croak("Callback must be a subref"); |
---|
239 | |
---|
240 | e = owl_global_get_typwin(&g); |
---|
241 | owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE, |
---|
242 | owl_global_get_msg_history(&g)); |
---|
243 | owl_editwin_clear(e); |
---|
244 | owl_editwin_set_dotsend(e); |
---|
245 | snprintf(buff, 1023, "----> %s\n", line); |
---|
246 | owl_editwin_set_locktext(e, buff); |
---|
247 | |
---|
248 | owl_global_set_typwin_active(&g); |
---|
249 | |
---|
250 | SvREFCNT_inc(callback); |
---|
251 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
252 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
253 | } |
---|
254 | |
---|
255 | |
---|
256 | char * |
---|
257 | get_data_dir () |
---|
258 | CODE: |
---|
259 | RETVAL = (char *) owl_get_datadir(); |
---|
260 | OUTPUT: |
---|
261 | RETVAL |
---|
262 | |
---|
263 | char * |
---|
264 | get_config_dir () |
---|
265 | CODE: |
---|
266 | RETVAL = (char *) owl_global_get_confdir(&g); |
---|
267 | OUTPUT: |
---|
268 | RETVAL |
---|
269 | |
---|
270 | void |
---|
271 | popless_text(text) |
---|
272 | char *text |
---|
273 | CODE: |
---|
274 | { |
---|
275 | owl_function_popless_text(text); |
---|
276 | } |
---|
277 | |
---|
278 | void |
---|
279 | popless_ztext(text) |
---|
280 | char *text |
---|
281 | CODE: |
---|
282 | { |
---|
283 | owl_fmtext fm; |
---|
284 | owl_fmtext_init_null(&fm); |
---|
285 | owl_fmtext_append_ztext(&fm, text); |
---|
286 | owl_function_popless_fmtext(&fm); |
---|
287 | owl_fmtext_free(&fm); |
---|
288 | } |
---|
289 | |
---|
290 | void |
---|
291 | error(text) |
---|
292 | char *text |
---|
293 | CODE: |
---|
294 | { |
---|
295 | owl_function_error("%s", text); |
---|
296 | } |
---|
297 | |
---|
298 | void |
---|
299 | create_style(name, object) |
---|
300 | char *name |
---|
301 | SV *object |
---|
302 | PREINIT: |
---|
303 | owl_style *s; |
---|
304 | CODE: |
---|
305 | { |
---|
306 | s = owl_malloc(sizeof(owl_style)); |
---|
307 | owl_style_create_perl(s, name, object); |
---|
308 | owl_global_add_style(&g, s); |
---|
309 | } |
---|
310 | |
---|
311 | int |
---|
312 | getnumcolors() |
---|
313 | CODE: |
---|
314 | RETVAL = owl_function_get_color_count(); |
---|
315 | OUTPUT: |
---|
316 | RETVAL |
---|
317 | |
---|
318 | void |
---|
319 | _remove_filter(filterName) |
---|
320 | char *filterName |
---|
321 | CODE: |
---|
322 | { |
---|
323 | /* Don't delete the current view, or the 'all' filter */ |
---|
324 | if (strcmp(filterName, owl_view_get_filtname(owl_global_get_current_view(&g))) |
---|
325 | && strcmp(filterName, "all")) { |
---|
326 | owl_global_remove_filter(&g,filterName); |
---|
327 | } |
---|
328 | } |
---|
329 | |
---|
330 | char * |
---|
331 | wordwrap(in, cols) |
---|
332 | char *in |
---|
333 | int cols |
---|
334 | PREINIT: |
---|
335 | char *rv = NULL; |
---|
336 | CODE: |
---|
337 | rv = owl_text_wordwrap(in, cols); |
---|
338 | RETVAL = rv; |
---|
339 | OUTPUT: |
---|
340 | RETVAL |
---|
341 | CLEANUP: |
---|
342 | if (rv) owl_free(rv); |
---|
343 | |
---|
344 | void |
---|
345 | new_variable_string_internal(name, ival, summ, desc) |
---|
346 | char * name |
---|
347 | char * ival |
---|
348 | char * summ |
---|
349 | char * desc |
---|
350 | CODE: |
---|
351 | owl_variable_dict_newvar_string(owl_global_get_vardict(&g), |
---|
352 | name, |
---|
353 | summ, |
---|
354 | desc, |
---|
355 | ival); |
---|
356 | |
---|
357 | void |
---|
358 | new_variable_int_internal(name, ival, summ, desc) |
---|
359 | char * name |
---|
360 | int ival |
---|
361 | char * summ |
---|
362 | char * desc |
---|
363 | CODE: |
---|
364 | owl_variable_dict_newvar_int(owl_global_get_vardict(&g), |
---|
365 | name, |
---|
366 | summ, |
---|
367 | desc, |
---|
368 | ival); |
---|
369 | |
---|
370 | void |
---|
371 | new_variable_bool_internal(name, ival, summ, desc) |
---|
372 | char * name |
---|
373 | int ival |
---|
374 | char * summ |
---|
375 | char * desc |
---|
376 | CODE: |
---|
377 | owl_variable_dict_newvar_bool(owl_global_get_vardict(&g), |
---|
378 | name, |
---|
379 | summ, |
---|
380 | desc, |
---|
381 | ival); |
---|
382 | |
---|
383 | void |
---|
384 | add_dispatch(fd, cb) |
---|
385 | int fd |
---|
386 | SV * cb |
---|
387 | CODE: |
---|
388 | SvREFCNT_inc(cb); |
---|
389 | owl_select_add_perl_dispatch(fd, cb); |
---|
390 | |
---|
391 | void |
---|
392 | remove_dispatch(fd) |
---|
393 | int fd |
---|
394 | CODE: |
---|
395 | owl_select_remove_perl_dispatch(fd); |
---|