source: perlglue.xs @ b3a40c7

barnowl_perlaimdebianrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since b3a40c7 was 3066d23, checked in by Alejandro R. Sedeño <asedeno@mit.edu>, 17 years ago
Fix outgoing jabber logging. Added two new perlglue functions: * log_message - takes a message hash, turns it into an owl message, and passes it to the logger. * add_and_log_message - combination off add_message and log_message. Takes a message hash, turns it into an owl message, logs it, and adds the same message to the message list if needed. This exists for convenience, so we don't have to convert the message hash twice. Also, took out an extraneous check from logging.c.
  • Property mode set to 100644
File size: 5.4 KB
Line 
1/* -*- mode: c; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2static 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"
11SV *owl_perlconfig_curmessage2hashref(void);
12
13#define SV_IS_CODEREF(sv) (SvROK((sv)) && SvTYPE(SvRV((sv))) == SVt_PVCV)
14
15MODULE = BarnOwl                PACKAGE = BarnOwl               
16
17char *
18command(cmd)
19        char *cmd
20        PREINIT:
21                char *rv = NULL;
22        CODE:
23                rv = owl_function_command(cmd);
24                RETVAL = rv;   
25        OUTPUT:
26                RETVAL
27        CLEANUP:
28                if (rv) owl_free(rv);
29
30SV *
31getcurmsg()
32        CODE:
33                ST(0) = owl_perlconfig_curmessage2hashref();
34
35int
36getnumcols()
37        CODE:
38                RETVAL = owl_global_get_cols(&g);
39        OUTPUT:
40                RETVAL
41               
42time_t
43getidletime()
44        CODE:
45                RETVAL = owl_global_get_idletime(&g);
46        OUTPUT:
47                RETVAL
48
49char *
50zephyr_getrealm()
51        CODE:
52                RETVAL = owl_zephyr_get_realm();
53        OUTPUT:
54                RETVAL
55
56char *
57zephyr_getsender()
58        CODE:
59                RETVAL = owl_zephyr_get_sender();
60        OUTPUT:
61                RETVAL
62
63void
64zephyr_zwrite(cmd,msg)
65        char *cmd
66        char *msg
67        PREINIT:
68                int i;
69        CODE:
70                i = owl_zwrite_create_and_send_from_line(cmd, msg);
71
72char *
73ztext_stylestrip(ztext)
74        char *ztext
75        PREINIT:
76                char *rv = NULL;
77        CODE:
78                rv = owl_function_ztext_stylestrip(ztext);
79                RETVAL = rv;
80        OUTPUT:
81                RETVAL
82        CLEANUP:
83                if (rv) owl_free(rv);
84
85void
86new_command_internal(name, func, summary, usage, description)
87        char *name
88        SV *func
89        char *summary
90        char *usage
91        char *description
92        PREINIT:
93                owl_cmd cmd;
94        CODE:
95        {
96                if(!SV_IS_CODEREF(func)) {
97                        croak("Command function must be a coderef!");
98                }
99                SvREFCNT_inc(func);
100                cmd.name = name;
101                cmd.cmd_perl = func;
102                cmd.summary = summary;
103                cmd.usage = usage;
104                cmd.description = description;
105                cmd.validctx = OWL_CTX_ANY;
106                cmd.cmd_aliased_to = NULL;
107                cmd.cmd_args_fn = NULL;
108                cmd.cmd_v_fn = NULL;
109                cmd.cmd_i_fn = NULL;
110                cmd.cmd_ctxargs_fn = NULL;
111                cmd.cmd_ctxv_fn = NULL;
112                cmd.cmd_ctxi_fn = NULL;
113                owl_cmddict_add_cmd(owl_global_get_cmddict(&g), &cmd);
114           }
115
116void queue_message(msg) 
117        SV *msg
118        PREINIT:
119                owl_message *m;
120        CODE:
121        {
122                if(!SvROK(msg) || SvTYPE(SvRV(msg)) != SVt_PVHV) {
123                        croak("Usage: BarnOwl::queue_message($message)");
124                }
125
126                m = owl_perlconfig_hashref2message(msg);
127
128                owl_global_messagequeue_addmsg(&g, m);
129        }
130
131void add_message(msg) 
132        SV *msg
133        PREINIT:
134                owl_message *m;
135        CODE:
136        {
137                if(!SvROK(msg) || SvTYPE(SvRV(msg)) != SVt_PVHV) {
138                        croak("Usage: BarnOwl::add_message($message)");
139                }
140
141                if (owl_global_is_displayoutgoing(&g)) {
142                        m = owl_perlconfig_hashref2message(msg);
143                        owl_function_add_message(m);
144                }
145        }
146
147void log_message(msg) 
148        SV *msg
149        PREINIT:
150                owl_message *m;
151        CODE:
152        {
153                if(!SvROK(msg) || SvTYPE(SvRV(msg)) != SVt_PVHV) {
154                        croak("Usage: BarnOwl::log_message($message)");
155                }
156
157                m = owl_perlconfig_hashref2message(msg);
158                owl_log_message(m);
159                owl_message_free(m);
160        }
161
162void add_and_log_message(msg) 
163        SV *msg
164        PREINIT:
165                owl_message *m;
166        CODE:
167        {
168                if(!SvROK(msg) || SvTYPE(SvRV(msg)) != SVt_PVHV) {
169                        croak("Usage: BarnOwl::add_and_log_message($message)");
170                }
171
172                m = owl_perlconfig_hashref2message(msg);
173                owl_log_message(m);
174                if (owl_global_is_displayoutgoing(&g)) {
175                        owl_function_add_message(m);
176                } else {
177                        owl_message_free(m);
178                }
179        }
180
181void admin_message(header, body) 
182        char *header
183        char *body
184        CODE:
185        {
186                owl_function_adminmsg(header, body);           
187        }
188
189void start_question(line, callback)
190        char *line
191        SV *callback
192        PREINIT:
193        CODE:
194        {
195                if(!SV_IS_CODEREF(callback))
196                        croak("Callback must be a subref");
197
198                owl_function_start_question(line);
199
200                SvREFCNT_inc(callback);
201                owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback);
202                owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback);
203        }
204
205void start_password(line, callback)
206        char *line
207        SV *callback
208        PREINIT:
209        CODE:
210        {
211                if(!SV_IS_CODEREF(callback))
212                        croak("Callback must be a subref");
213
214                owl_function_start_password(line);
215
216                SvREFCNT_inc(callback);
217                owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback);
218                owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback);
219        }
220
221void start_edit_win(line, callback)
222        char *line
223        SV *callback
224        PREINIT:
225                owl_editwin * e;
226                char buff[1024];
227        CODE:
228        {
229                if(!SV_IS_CODEREF(callback))
230                        croak("Callback must be a subref");
231
232                e = owl_global_get_typwin(&g);
233                owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE,
234                                      owl_global_get_msg_history(&g));
235                owl_editwin_clear(e);
236                owl_editwin_set_dotsend(e);
237                snprintf(buff, 1023, "----> %s\n", line);
238                owl_editwin_set_locktext(e, buff);
239
240                owl_global_set_typwin_active(&g);
241
242                SvREFCNT_inc(callback);
243                owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback);
244                owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback);
245        }
246
247
248char * 
249get_data_dir ()
250        CODE:
251                RETVAL = (char *) DATADIR;
252        OUTPUT:
253        RETVAL
254
255void
256popless_text(text) 
257        char *text
258        CODE:
259        {
260                owl_function_popless_text(text);
261        }
262
263void
264popless_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
275void
276error(text) 
277        char *text
278        CODE:
279        {
280                owl_function_error("%s", text);
281        }
282
283void
284_create_style(name, function, description)
285     char *name
286     char *function
287     char *description
288     PREINIT:
289                /* This is to allow us to bootstrap the default style before the
290                command architecture has been initialized */
291                owl_style *s;
292     CODE:
293        {
294                s = owl_malloc(sizeof(owl_style));
295                owl_style_create_perl(s, name, function, description);
296                owl_global_add_style(&g, s);
297        }
Note: See TracBrowser for help on using the repository browser.