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_getsubs() |
---|
118 | PREINIT: |
---|
119 | char *rv = NULL; |
---|
120 | CODE: |
---|
121 | rv = owl_zephyr_getsubs(); |
---|
122 | RETVAL = rv; |
---|
123 | OUTPUT: |
---|
124 | RETVAL |
---|
125 | CLEANUP: |
---|
126 | if (rv) owl_free(rv); |
---|
127 | |
---|
128 | void |
---|
129 | new_command_internal(name, func, summary, usage, description) |
---|
130 | char *name |
---|
131 | SV *func |
---|
132 | char *summary |
---|
133 | char *usage |
---|
134 | char *description |
---|
135 | PREINIT: |
---|
136 | owl_cmd cmd; |
---|
137 | CODE: |
---|
138 | { |
---|
139 | if(!SV_IS_CODEREF(func)) { |
---|
140 | croak("Command function must be a coderef!"); |
---|
141 | } |
---|
142 | SvREFCNT_inc(func); |
---|
143 | cmd.name = name; |
---|
144 | cmd.cmd_perl = func; |
---|
145 | cmd.summary = summary; |
---|
146 | cmd.usage = usage; |
---|
147 | cmd.description = description; |
---|
148 | cmd.validctx = OWL_CTX_ANY; |
---|
149 | cmd.cmd_aliased_to = NULL; |
---|
150 | cmd.cmd_args_fn = NULL; |
---|
151 | cmd.cmd_v_fn = NULL; |
---|
152 | cmd.cmd_i_fn = NULL; |
---|
153 | cmd.cmd_ctxargs_fn = NULL; |
---|
154 | cmd.cmd_ctxv_fn = NULL; |
---|
155 | cmd.cmd_ctxi_fn = NULL; |
---|
156 | owl_cmddict_add_cmd(owl_global_get_cmddict(&g), &cmd); |
---|
157 | } |
---|
158 | |
---|
159 | void queue_message(msg) |
---|
160 | SV *msg |
---|
161 | PREINIT: |
---|
162 | owl_message *m; |
---|
163 | CODE: |
---|
164 | { |
---|
165 | if(!SvROK(msg) || SvTYPE(SvRV(msg)) != SVt_PVHV) { |
---|
166 | croak("Usage: BarnOwl::queue_message($message)"); |
---|
167 | } |
---|
168 | |
---|
169 | m = owl_perlconfig_hashref2message(msg); |
---|
170 | |
---|
171 | owl_global_messagequeue_addmsg(&g, m); |
---|
172 | } |
---|
173 | |
---|
174 | void admin_message(header, body) |
---|
175 | char *header |
---|
176 | char *body |
---|
177 | CODE: |
---|
178 | { |
---|
179 | owl_function_adminmsg(header, body); |
---|
180 | } |
---|
181 | |
---|
182 | void start_question(line, callback) |
---|
183 | 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_question(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_password(line, callback) |
---|
199 | char *line |
---|
200 | SV *callback |
---|
201 | PREINIT: |
---|
202 | CODE: |
---|
203 | { |
---|
204 | if(!SV_IS_CODEREF(callback)) |
---|
205 | croak("Callback must be a subref"); |
---|
206 | |
---|
207 | owl_function_start_password(line); |
---|
208 | |
---|
209 | SvREFCNT_inc(callback); |
---|
210 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
211 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
212 | } |
---|
213 | |
---|
214 | void start_edit_win(line, callback) |
---|
215 | char *line |
---|
216 | SV *callback |
---|
217 | PREINIT: |
---|
218 | owl_editwin * e; |
---|
219 | char buff[1024]; |
---|
220 | CODE: |
---|
221 | { |
---|
222 | if(!SV_IS_CODEREF(callback)) |
---|
223 | croak("Callback must be a subref"); |
---|
224 | |
---|
225 | e = owl_global_get_typwin(&g); |
---|
226 | owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE, |
---|
227 | owl_global_get_msg_history(&g)); |
---|
228 | owl_editwin_clear(e); |
---|
229 | owl_editwin_set_dotsend(e); |
---|
230 | snprintf(buff, 1023, "----> %s\n", line); |
---|
231 | owl_editwin_set_locktext(e, buff); |
---|
232 | |
---|
233 | owl_global_set_typwin_active(&g); |
---|
234 | |
---|
235 | SvREFCNT_inc(callback); |
---|
236 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
237 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
238 | } |
---|
239 | |
---|
240 | |
---|
241 | char * |
---|
242 | get_data_dir () |
---|
243 | CODE: |
---|
244 | RETVAL = (char *) owl_get_datadir(); |
---|
245 | OUTPUT: |
---|
246 | RETVAL |
---|
247 | |
---|
248 | char * |
---|
249 | get_config_dir () |
---|
250 | CODE: |
---|
251 | RETVAL = (char *) owl_global_get_confdir(&g); |
---|
252 | OUTPUT: |
---|
253 | RETVAL |
---|
254 | |
---|
255 | void |
---|
256 | popless_text(text) |
---|
257 | char *text |
---|
258 | CODE: |
---|
259 | { |
---|
260 | owl_function_popless_text(text); |
---|
261 | } |
---|
262 | |
---|
263 | void |
---|
264 | popless_ztext(text) |
---|
265 | char *text |
---|
266 | CODE: |
---|
267 | { |
---|
268 | owl_fmtext fm; |
---|
269 | owl_fmtext_init_null(&fm); |
---|
270 | owl_fmtext_append_ztext(&fm, text); |
---|
271 | owl_function_popless_fmtext(&fm); |
---|
272 | owl_fmtext_free(&fm); |
---|
273 | } |
---|
274 | |
---|
275 | void |
---|
276 | error(text) |
---|
277 | char *text |
---|
278 | CODE: |
---|
279 | { |
---|
280 | owl_function_error("%s", text); |
---|
281 | } |
---|
282 | |
---|
283 | void |
---|
284 | create_style(name, object) |
---|
285 | 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 | 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 | 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 | new_variable_string_internal(name, ival, summ, desc) |
---|
331 | char * name |
---|
332 | char * ival |
---|
333 | char * summ |
---|
334 | char * desc |
---|
335 | CODE: |
---|
336 | owl_variable_dict_newvar_string(owl_global_get_vardict(&g), |
---|
337 | name, |
---|
338 | summ, |
---|
339 | desc, |
---|
340 | ival); |
---|
341 | |
---|
342 | void |
---|
343 | new_variable_int_internal(name, ival, summ, desc) |
---|
344 | char * name |
---|
345 | int ival |
---|
346 | char * summ |
---|
347 | char * desc |
---|
348 | CODE: |
---|
349 | owl_variable_dict_newvar_int(owl_global_get_vardict(&g), |
---|
350 | name, |
---|
351 | summ, |
---|
352 | desc, |
---|
353 | ival); |
---|
354 | |
---|
355 | void |
---|
356 | new_variable_bool_internal(name, ival, summ, desc) |
---|
357 | char * name |
---|
358 | int ival |
---|
359 | char * summ |
---|
360 | char * desc |
---|
361 | CODE: |
---|
362 | owl_variable_dict_newvar_bool(owl_global_get_vardict(&g), |
---|
363 | name, |
---|
364 | summ, |
---|
365 | desc, |
---|
366 | ival); |
---|
367 | |
---|
368 | void |
---|
369 | add_dispatch(fd, cb) |
---|
370 | int fd |
---|
371 | SV * cb |
---|
372 | CODE: |
---|
373 | SvREFCNT_inc(cb); |
---|
374 | owl_select_add_perl_dispatch(fd, cb); |
---|
375 | |
---|
376 | void |
---|
377 | remove_dispatch(fd) |
---|
378 | int fd |
---|
379 | CODE: |
---|
380 | owl_select_remove_perl_dispatch(fd); |
---|