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 document 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 | CODE: |
---|
40 | rv = owl_function_command(cmd); |
---|
41 | RETVAL = rv; |
---|
42 | OUTPUT: |
---|
43 | RETVAL |
---|
44 | CLEANUP: |
---|
45 | if (rv) owl_free(rv); |
---|
46 | |
---|
47 | SV * |
---|
48 | getcurmsg() |
---|
49 | CODE: |
---|
50 | ST(0) = owl_perlconfig_curmessage2hashref(); |
---|
51 | |
---|
52 | int |
---|
53 | getnumcols() |
---|
54 | CODE: |
---|
55 | RETVAL = owl_global_get_cols(&g); |
---|
56 | OUTPUT: |
---|
57 | RETVAL |
---|
58 | |
---|
59 | time_t |
---|
60 | getidletime() |
---|
61 | CODE: |
---|
62 | RETVAL = owl_global_get_idletime(&g); |
---|
63 | OUTPUT: |
---|
64 | RETVAL |
---|
65 | |
---|
66 | char * |
---|
67 | zephyr_getrealm() |
---|
68 | CODE: |
---|
69 | RETVAL = owl_zephyr_get_realm(); |
---|
70 | OUTPUT: |
---|
71 | RETVAL |
---|
72 | |
---|
73 | char * |
---|
74 | zephyr_getsender() |
---|
75 | CODE: |
---|
76 | RETVAL = owl_zephyr_get_sender(); |
---|
77 | OUTPUT: |
---|
78 | RETVAL |
---|
79 | |
---|
80 | void |
---|
81 | zephyr_zwrite(cmd,msg) |
---|
82 | char *cmd |
---|
83 | char *msg |
---|
84 | PREINIT: |
---|
85 | int i; |
---|
86 | CODE: |
---|
87 | i = owl_zwrite_create_and_send_from_line(cmd, msg); |
---|
88 | |
---|
89 | char * |
---|
90 | ztext_stylestrip(ztext) |
---|
91 | char *ztext |
---|
92 | PREINIT: |
---|
93 | char *rv = NULL; |
---|
94 | CODE: |
---|
95 | rv = owl_function_ztext_stylestrip(ztext); |
---|
96 | RETVAL = rv; |
---|
97 | OUTPUT: |
---|
98 | RETVAL |
---|
99 | CLEANUP: |
---|
100 | if (rv) owl_free(rv); |
---|
101 | |
---|
102 | char * |
---|
103 | zephyr_getsubs() |
---|
104 | PREINIT: |
---|
105 | char *rv = NULL; |
---|
106 | CODE: |
---|
107 | rv = owl_zephyr_getsubs(); |
---|
108 | RETVAL = rv; |
---|
109 | OUTPUT: |
---|
110 | RETVAL |
---|
111 | CLEANUP: |
---|
112 | if (rv) owl_free(rv); |
---|
113 | |
---|
114 | void |
---|
115 | new_command_internal(name, func, summary, usage, description) |
---|
116 | char *name |
---|
117 | SV *func |
---|
118 | char *summary |
---|
119 | char *usage |
---|
120 | char *description |
---|
121 | PREINIT: |
---|
122 | owl_cmd cmd; |
---|
123 | CODE: |
---|
124 | { |
---|
125 | if(!SV_IS_CODEREF(func)) { |
---|
126 | croak("Command function must be a coderef!"); |
---|
127 | } |
---|
128 | SvREFCNT_inc(func); |
---|
129 | cmd.name = name; |
---|
130 | cmd.cmd_perl = func; |
---|
131 | cmd.summary = summary; |
---|
132 | cmd.usage = usage; |
---|
133 | cmd.description = description; |
---|
134 | cmd.validctx = OWL_CTX_ANY; |
---|
135 | cmd.cmd_aliased_to = NULL; |
---|
136 | cmd.cmd_args_fn = NULL; |
---|
137 | cmd.cmd_v_fn = NULL; |
---|
138 | cmd.cmd_i_fn = NULL; |
---|
139 | cmd.cmd_ctxargs_fn = NULL; |
---|
140 | cmd.cmd_ctxv_fn = NULL; |
---|
141 | cmd.cmd_ctxi_fn = NULL; |
---|
142 | owl_cmddict_add_cmd(owl_global_get_cmddict(&g), &cmd); |
---|
143 | } |
---|
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 | new_variable_string_internal(name, ival, summ, desc) |
---|
317 | char * name |
---|
318 | char * ival |
---|
319 | char * summ |
---|
320 | char * desc |
---|
321 | CODE: |
---|
322 | owl_variable_dict_newvar_string(owl_global_get_vardict(&g), |
---|
323 | name, |
---|
324 | summ, |
---|
325 | desc, |
---|
326 | ival); |
---|
327 | |
---|
328 | void |
---|
329 | new_variable_int_internal(name, ival, summ, desc) |
---|
330 | char * name |
---|
331 | int ival |
---|
332 | char * summ |
---|
333 | char * desc |
---|
334 | CODE: |
---|
335 | owl_variable_dict_newvar_int(owl_global_get_vardict(&g), |
---|
336 | name, |
---|
337 | summ, |
---|
338 | desc, |
---|
339 | ival); |
---|
340 | |
---|
341 | void |
---|
342 | new_variable_bool_internal(name, ival, summ, desc) |
---|
343 | char * name |
---|
344 | int ival |
---|
345 | char * summ |
---|
346 | char * desc |
---|
347 | CODE: |
---|
348 | owl_variable_dict_newvar_bool(owl_global_get_vardict(&g), |
---|
349 | name, |
---|
350 | summ, |
---|
351 | desc, |
---|
352 | ival); |
---|
353 | |
---|
354 | void |
---|
355 | add_dispatch(fd, cb) |
---|
356 | int fd |
---|
357 | SV * cb |
---|
358 | CODE: |
---|
359 | SvREFCNT_inc(cb); |
---|
360 | owl_select_add_perl_dispatch(fd, cb); |
---|
361 | |
---|
362 | void |
---|
363 | remove_dispatch(fd) |
---|
364 | int fd |
---|
365 | CODE: |
---|
366 | owl_select_remove_perl_dispatch(fd); |
---|