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 | MODULE = BarnOwl PACKAGE = BarnOwl |
---|
16 | |
---|
17 | char * |
---|
18 | command(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 | |
---|
30 | SV * |
---|
31 | getcurmsg() |
---|
32 | CODE: |
---|
33 | ST(0) = owl_perlconfig_curmessage2hashref(); |
---|
34 | |
---|
35 | int |
---|
36 | getnumcols() |
---|
37 | CODE: |
---|
38 | RETVAL = owl_global_get_cols(&g); |
---|
39 | OUTPUT: |
---|
40 | RETVAL |
---|
41 | |
---|
42 | time_t |
---|
43 | getidletime() |
---|
44 | CODE: |
---|
45 | RETVAL = owl_global_get_idletime(&g); |
---|
46 | OUTPUT: |
---|
47 | RETVAL |
---|
48 | |
---|
49 | char * |
---|
50 | zephyr_getrealm() |
---|
51 | CODE: |
---|
52 | RETVAL = owl_zephyr_get_realm(); |
---|
53 | OUTPUT: |
---|
54 | RETVAL |
---|
55 | |
---|
56 | char * |
---|
57 | zephyr_getsender() |
---|
58 | CODE: |
---|
59 | RETVAL = owl_zephyr_get_sender(); |
---|
60 | OUTPUT: |
---|
61 | RETVAL |
---|
62 | |
---|
63 | void |
---|
64 | zephyr_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 | |
---|
72 | char * |
---|
73 | ztext_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 | |
---|
85 | void |
---|
86 | new_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 | |
---|
116 | void queue_message(msg) |
---|
117 | SV *msg |
---|
118 | PREINIT: |
---|
119 | char * key; |
---|
120 | char * val; |
---|
121 | owl_message *m; |
---|
122 | HV * hash; |
---|
123 | HE * ent; |
---|
124 | I32 count; |
---|
125 | I32 len; |
---|
126 | CODE: |
---|
127 | { |
---|
128 | if(!SvROK(msg) || SvTYPE(SvRV(msg)) != SVt_PVHV) { |
---|
129 | croak("Usage: owl::queue_message($message)"); |
---|
130 | } |
---|
131 | |
---|
132 | hash = (HV*)SvRV(msg); |
---|
133 | m = owl_malloc(sizeof(owl_message)); |
---|
134 | owl_message_init(m); |
---|
135 | |
---|
136 | count = hv_iterinit(hash); |
---|
137 | while((ent = hv_iternext(hash))) { |
---|
138 | key = hv_iterkey(ent, &len); |
---|
139 | val = SvPV_nolen(hv_iterval(hash, ent)); |
---|
140 | if(!strcmp(key, "type")) { |
---|
141 | owl_message_set_type(m, owl_message_parse_type(val)); |
---|
142 | } else if(!strcmp(key, "direction")) { |
---|
143 | owl_message_set_direction(m, owl_message_parse_direction(val)); |
---|
144 | } else if(!strcmp(key, "private")) { |
---|
145 | SV * v = hv_iterval(hash, ent); |
---|
146 | if(SvTRUE(v)) { |
---|
147 | owl_message_set_isprivate(m); |
---|
148 | } |
---|
149 | } else if (!strcmp(key, "hostname")) { |
---|
150 | owl_message_set_hostname(m, val); |
---|
151 | } else if (!strcmp(key, "zwriteline")) { |
---|
152 | owl_message_set_zwriteline(m, val); |
---|
153 | } else if (!strcmp(key, "time")) { |
---|
154 | m->timestr = owl_strdup(val); |
---|
155 | struct tm tm; |
---|
156 | strptime(val, "%a %b %d %T %Y", &tm); |
---|
157 | m->time = mktime(&tm); |
---|
158 | } else { |
---|
159 | owl_message_set_attribute(m, key, val); |
---|
160 | } |
---|
161 | } |
---|
162 | if(owl_message_is_type_admin(m)) { |
---|
163 | if(!owl_message_get_attribute_value(m, "adminheader")) |
---|
164 | owl_message_set_attribute(m, "adminheader", ""); |
---|
165 | } |
---|
166 | |
---|
167 | owl_global_messagequeue_addmsg(&g, m); |
---|
168 | } |
---|
169 | |
---|
170 | void start_question(line, callback) |
---|
171 | char *line |
---|
172 | SV *callback |
---|
173 | PREINIT: |
---|
174 | CODE: |
---|
175 | { |
---|
176 | if(!SV_IS_CODEREF(callback)) |
---|
177 | croak("Callback must be a subref"); |
---|
178 | |
---|
179 | owl_function_start_question(line); |
---|
180 | |
---|
181 | SvREFCNT_inc(callback); |
---|
182 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
183 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
184 | } |
---|
185 | |
---|
186 | void start_password(line, callback) |
---|
187 | char *line |
---|
188 | SV *callback |
---|
189 | PREINIT: |
---|
190 | CODE: |
---|
191 | { |
---|
192 | if(!SV_IS_CODEREF(callback)) |
---|
193 | croak("Callback must be a subref"); |
---|
194 | |
---|
195 | owl_function_start_password(line); |
---|
196 | |
---|
197 | SvREFCNT_inc(callback); |
---|
198 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
199 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
200 | } |
---|
201 | |
---|
202 | void start_edit_win(line, callback) |
---|
203 | char *line |
---|
204 | SV *callback |
---|
205 | PREINIT: |
---|
206 | owl_editwin * e; |
---|
207 | char buff[1024]; |
---|
208 | CODE: |
---|
209 | { |
---|
210 | if(!SV_IS_CODEREF(callback)) |
---|
211 | croak("Callback must be a subref"); |
---|
212 | |
---|
213 | e = owl_global_get_typwin(&g); |
---|
214 | owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE, |
---|
215 | owl_global_get_msg_history(&g)); |
---|
216 | owl_editwin_clear(e); |
---|
217 | owl_editwin_set_dotsend(e); |
---|
218 | snprintf(buff, 1023, "----> %s\n", line); |
---|
219 | owl_editwin_set_locktext(e, buff); |
---|
220 | |
---|
221 | owl_global_set_typwin_active(&g); |
---|
222 | |
---|
223 | SvREFCNT_inc(callback); |
---|
224 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
225 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
226 | } |
---|
227 | |
---|
228 | |
---|
229 | char * |
---|
230 | get_data_dir () |
---|
231 | CODE: |
---|
232 | RETVAL = (char *) DATADIR; |
---|
233 | OUTPUT: |
---|
234 | RETVAL |
---|
235 | |
---|
236 | void |
---|
237 | popless_text(text) |
---|
238 | char *text |
---|
239 | CODE: |
---|
240 | { |
---|
241 | owl_function_popless_text(text); |
---|
242 | } |
---|
243 | |
---|
244 | void |
---|
245 | popless_ztext(text) |
---|
246 | char *text |
---|
247 | CODE: |
---|
248 | { |
---|
249 | owl_fmtext fm; |
---|
250 | owl_fmtext_init_null(&fm); |
---|
251 | owl_fmtext_append_ztext(&fm, text); |
---|
252 | owl_function_popless_fmtext(&fm); |
---|
253 | owl_fmtext_free(&fm); |
---|
254 | } |
---|