[dd16bdd] | 1 | /* -*- mode: c; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
[83a9b63] | 2 | static const char fileIdent[] = "$Id$"; |
---|
| 3 | |
---|
[8a54409] | 4 | #ifdef HAVE_LIBZEPHYR |
---|
[f1e629d] | 5 | #include <zephyr/zephyr.h> |
---|
[8a54409] | 6 | #endif |
---|
[f1e629d] | 7 | #include <EXTERN.h> |
---|
[8ee73f8d] | 8 | |
---|
[1152d45] | 9 | #define OWL_PERL |
---|
| 10 | #include "owl.h" |
---|
| 11 | SV *owl_perlconfig_curmessage2hashref(void); |
---|
[8ee73f8d] | 12 | |
---|
[db8b00b] | 13 | #define SV_IS_CODEREF(sv) (SvROK((sv)) && SvTYPE(SvRV((sv))) == SVt_PVCV) |
---|
| 14 | |
---|
[74fc22a] | 15 | /************************************************************* |
---|
| 16 | * NOTE |
---|
| 17 | ************************************************************* |
---|
| 18 | * These functions, when they are intended to be user-visible, |
---|
[c4ba74d] | 19 | * are documented in perlwrap.pm. If you add functions to this |
---|
[74fc22a] | 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 |
---|
[25cccdc] | 26 | * manner as possible, to simplify the XS code, put it in |
---|
| 27 | * BarnOwl::Intenal::, and write a perl wrapper in perlwrap.pm |
---|
| 28 | * that munges the arguments as appropriate and calls the |
---|
| 29 | * internal version. |
---|
[74fc22a] | 30 | */ |
---|
[8ee73f8d] | 31 | |
---|
[65fea01] | 32 | MODULE = BarnOwl PACKAGE = BarnOwl |
---|
| 33 | |
---|
[8ee73f8d] | 34 | char * |
---|
[c4ba74d] | 35 | command(cmd, ...) |
---|
[8ee73f8d] | 36 | char *cmd |
---|
| 37 | PREINIT: |
---|
| 38 | char *rv = NULL; |
---|
[c4ba74d] | 39 | char **argv; |
---|
| 40 | int i; |
---|
[8ee73f8d] | 41 | CODE: |
---|
[c4ba74d] | 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 | } |
---|
[8ee73f8d] | 56 | OUTPUT: |
---|
| 57 | RETVAL |
---|
| 58 | CLEANUP: |
---|
| 59 | if (rv) owl_free(rv); |
---|
| 60 | |
---|
[f1e629d] | 61 | SV * |
---|
| 62 | getcurmsg() |
---|
| 63 | CODE: |
---|
[19bab8e] | 64 | RETVAL = owl_perlconfig_curmessage2hashref(); |
---|
| 65 | OUTPUT: |
---|
| 66 | RETVAL |
---|
[f1e629d] | 67 | |
---|
| 68 | int |
---|
| 69 | getnumcols() |
---|
| 70 | CODE: |
---|
| 71 | RETVAL = owl_global_get_cols(&g); |
---|
| 72 | OUTPUT: |
---|
| 73 | RETVAL |
---|
[7f792c1] | 74 | |
---|
| 75 | time_t |
---|
| 76 | getidletime() |
---|
| 77 | CODE: |
---|
| 78 | RETVAL = owl_global_get_idletime(&g); |
---|
| 79 | OUTPUT: |
---|
| 80 | RETVAL |
---|
[f1e629d] | 81 | |
---|
| 82 | char * |
---|
| 83 | zephyr_getrealm() |
---|
| 84 | CODE: |
---|
[8a54409] | 85 | RETVAL = owl_zephyr_get_realm(); |
---|
[f1e629d] | 86 | OUTPUT: |
---|
| 87 | RETVAL |
---|
| 88 | |
---|
| 89 | char * |
---|
| 90 | zephyr_getsender() |
---|
| 91 | CODE: |
---|
[8a54409] | 92 | RETVAL = owl_zephyr_get_sender(); |
---|
[f1e629d] | 93 | OUTPUT: |
---|
| 94 | RETVAL |
---|
| 95 | |
---|
[e1c4636] | 96 | void |
---|
[f1e629d] | 97 | zephyr_zwrite(cmd,msg) |
---|
[e1c4636] | 98 | char *cmd |
---|
| 99 | char *msg |
---|
| 100 | PREINIT: |
---|
| 101 | int i; |
---|
| 102 | CODE: |
---|
| 103 | i = owl_zwrite_create_and_send_from_line(cmd, msg); |
---|
| 104 | |
---|
| 105 | char * |
---|
| 106 | ztext_stylestrip(ztext) |
---|
| 107 | char *ztext |
---|
| 108 | PREINIT: |
---|
| 109 | char *rv = NULL; |
---|
| 110 | CODE: |
---|
[1fd0b25] | 111 | rv = owl_function_ztext_stylestrip(ztext); |
---|
[e1c4636] | 112 | RETVAL = rv; |
---|
| 113 | OUTPUT: |
---|
| 114 | RETVAL |
---|
| 115 | CLEANUP: |
---|
| 116 | if (rv) owl_free(rv); |
---|
| 117 | |
---|
[acb13bb] | 118 | char * |
---|
[740d5f7] | 119 | zephyr_smartstrip_user(in) |
---|
| 120 | char *in |
---|
| 121 | PREINIT: |
---|
| 122 | char *rv = NULL; |
---|
| 123 | CODE: |
---|
| 124 | { |
---|
| 125 | rv = owl_zephyr_smartstripped_user(in); |
---|
| 126 | RETVAL = rv; |
---|
| 127 | } |
---|
| 128 | OUTPUT: |
---|
| 129 | RETVAL |
---|
| 130 | CLEANUP: |
---|
| 131 | owl_free(rv); |
---|
| 132 | |
---|
| 133 | char * |
---|
[acb13bb] | 134 | zephyr_getsubs() |
---|
| 135 | PREINIT: |
---|
| 136 | char *rv = NULL; |
---|
| 137 | CODE: |
---|
| 138 | rv = owl_zephyr_getsubs(); |
---|
| 139 | RETVAL = rv; |
---|
| 140 | OUTPUT: |
---|
| 141 | RETVAL |
---|
| 142 | CLEANUP: |
---|
| 143 | if (rv) owl_free(rv); |
---|
| 144 | |
---|
[1b6b2f3] | 145 | void queue_message(msg) |
---|
[dd16bdd] | 146 | SV *msg |
---|
| 147 | PREINIT: |
---|
| 148 | owl_message *m; |
---|
| 149 | CODE: |
---|
[1b6b2f3] | 150 | { |
---|
[dd16bdd] | 151 | if(!SvROK(msg) || SvTYPE(SvRV(msg)) != SVt_PVHV) { |
---|
[3066d23] | 152 | croak("Usage: BarnOwl::queue_message($message)"); |
---|
[dd16bdd] | 153 | } |
---|
[17eed9c] | 154 | |
---|
[30678ae] | 155 | m = owl_perlconfig_hashref2message(msg); |
---|
[dd16bdd] | 156 | |
---|
| 157 | owl_global_messagequeue_addmsg(&g, m); |
---|
[1b6b2f3] | 158 | } |
---|
[db8b00b] | 159 | |
---|
[1c2e0b3] | 160 | void admin_message(header, body) |
---|
| 161 | char *header |
---|
| 162 | char *body |
---|
| 163 | CODE: |
---|
| 164 | { |
---|
| 165 | owl_function_adminmsg(header, body); |
---|
| 166 | } |
---|
| 167 | |
---|
[db8b00b] | 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 | } |
---|
[6b3f797] | 225 | |
---|
| 226 | |
---|
| 227 | char * |
---|
| 228 | get_data_dir () |
---|
| 229 | CODE: |
---|
[b363d83] | 230 | RETVAL = (char *) owl_get_datadir(); |
---|
[6b3f797] | 231 | OUTPUT: |
---|
| 232 | RETVAL |
---|
[b6a253c] | 233 | |
---|
[b363d83] | 234 | char * |
---|
| 235 | get_config_dir () |
---|
| 236 | CODE: |
---|
| 237 | RETVAL = (char *) owl_global_get_confdir(&g); |
---|
| 238 | OUTPUT: |
---|
| 239 | RETVAL |
---|
| 240 | |
---|
[b6a253c] | 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 | } |
---|
[0ff2528] | 260 | |
---|
| 261 | void |
---|
| 262 | error(text) |
---|
| 263 | char *text |
---|
| 264 | CODE: |
---|
| 265 | { |
---|
| 266 | owl_function_error("%s", text); |
---|
| 267 | } |
---|
[b6c067a] | 268 | |
---|
| 269 | void |
---|
[b67ab6b] | 270 | create_style(name, object) |
---|
[b6c067a] | 271 | char *name |
---|
[864ed35] | 272 | SV *object |
---|
[b6c067a] | 273 | PREINIT: |
---|
| 274 | owl_style *s; |
---|
| 275 | CODE: |
---|
| 276 | { |
---|
| 277 | s = owl_malloc(sizeof(owl_style)); |
---|
[864ed35] | 278 | owl_style_create_perl(s, name, object); |
---|
[b6c067a] | 279 | owl_global_add_style(&g, s); |
---|
| 280 | } |
---|
[c2c5c77] | 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 | } |
---|
[f6b319c] | 300 | |
---|
| 301 | char * |
---|
| 302 | wordwrap(in, cols) |
---|
| 303 | char *in |
---|
| 304 | int cols |
---|
| 305 | PREINIT: |
---|
| 306 | char *rv = NULL; |
---|
| 307 | CODE: |
---|
[a695a68] | 308 | rv = owl_text_wordwrap(in, cols); |
---|
[f6b319c] | 309 | RETVAL = rv; |
---|
| 310 | OUTPUT: |
---|
| 311 | RETVAL |
---|
| 312 | CLEANUP: |
---|
| 313 | if (rv) owl_free(rv); |
---|
[a695a68] | 314 | |
---|
| 315 | void |
---|
[25cccdc] | 316 | add_dispatch(fd, cb) |
---|
| 317 | int fd |
---|
| 318 | SV * cb |
---|
| 319 | CODE: |
---|
| 320 | SvREFCNT_inc(cb); |
---|
| 321 | owl_select_add_perl_dispatch(fd, cb); |
---|
| 322 | |
---|
| 323 | void |
---|
| 324 | remove_dispatch(fd) |
---|
| 325 | int fd |
---|
| 326 | CODE: |
---|
| 327 | owl_select_remove_perl_dispatch(fd); |
---|
| 328 | |
---|
| 329 | MODULE = BarnOwl PACKAGE = BarnOwl::Internal |
---|
| 330 | |
---|
| 331 | |
---|
| 332 | void |
---|
| 333 | new_command(name, func, summary, usage, description) |
---|
| 334 | char *name |
---|
| 335 | SV *func |
---|
| 336 | char *summary |
---|
| 337 | char *usage |
---|
| 338 | char *description |
---|
| 339 | PREINIT: |
---|
| 340 | owl_cmd cmd; |
---|
| 341 | CODE: |
---|
| 342 | { |
---|
| 343 | if(!SV_IS_CODEREF(func)) { |
---|
| 344 | croak("Command function must be a coderef!"); |
---|
| 345 | } |
---|
| 346 | SvREFCNT_inc(func); |
---|
| 347 | cmd.name = name; |
---|
| 348 | cmd.cmd_perl = func; |
---|
| 349 | cmd.summary = summary; |
---|
| 350 | cmd.usage = usage; |
---|
| 351 | cmd.description = description; |
---|
| 352 | cmd.validctx = OWL_CTX_ANY; |
---|
| 353 | cmd.cmd_aliased_to = NULL; |
---|
| 354 | cmd.cmd_args_fn = NULL; |
---|
| 355 | cmd.cmd_v_fn = NULL; |
---|
| 356 | cmd.cmd_i_fn = NULL; |
---|
| 357 | cmd.cmd_ctxargs_fn = NULL; |
---|
| 358 | cmd.cmd_ctxv_fn = NULL; |
---|
| 359 | cmd.cmd_ctxi_fn = NULL; |
---|
| 360 | owl_cmddict_add_cmd(owl_global_get_cmddict(&g), &cmd); |
---|
| 361 | } |
---|
| 362 | |
---|
| 363 | void |
---|
| 364 | new_variable_string(name, ival, summ, desc) |
---|
[a695a68] | 365 | char * name |
---|
| 366 | char * ival |
---|
| 367 | char * summ |
---|
| 368 | char * desc |
---|
| 369 | CODE: |
---|
| 370 | owl_variable_dict_newvar_string(owl_global_get_vardict(&g), |
---|
| 371 | name, |
---|
| 372 | summ, |
---|
| 373 | desc, |
---|
| 374 | ival); |
---|
| 375 | |
---|
| 376 | void |
---|
[25cccdc] | 377 | new_variable_int(name, ival, summ, desc) |
---|
[a695a68] | 378 | char * name |
---|
| 379 | int ival |
---|
| 380 | char * summ |
---|
| 381 | char * desc |
---|
| 382 | CODE: |
---|
| 383 | owl_variable_dict_newvar_int(owl_global_get_vardict(&g), |
---|
| 384 | name, |
---|
| 385 | summ, |
---|
| 386 | desc, |
---|
| 387 | ival); |
---|
| 388 | |
---|
| 389 | void |
---|
[25cccdc] | 390 | new_variable_bool(name, ival, summ, desc) |
---|
[a695a68] | 391 | char * name |
---|
| 392 | int ival |
---|
| 393 | char * summ |
---|
| 394 | char * desc |
---|
| 395 | CODE: |
---|
| 396 | owl_variable_dict_newvar_bool(owl_global_get_vardict(&g), |
---|
| 397 | name, |
---|
| 398 | summ, |
---|
| 399 | desc, |
---|
| 400 | ival); |
---|
[1631825] | 401 | |
---|
| 402 | IV |
---|
| 403 | add_timer(after, interval, cb) |
---|
| 404 | int after |
---|
| 405 | int interval |
---|
| 406 | SV *cb |
---|
| 407 | PREINIT: |
---|
| 408 | SV *ref; |
---|
| 409 | owl_timer *t; |
---|
| 410 | CODE: |
---|
| 411 | ref = sv_rvweaken(newSVsv(cb)); |
---|
| 412 | t = owl_select_add_timer(after, |
---|
| 413 | interval, |
---|
| 414 | owl_perlconfig_perl_timer, |
---|
| 415 | owl_perlconfig_perl_timer_destroy, |
---|
| 416 | ref); |
---|
| 417 | owl_function_debugmsg("Created timer %p", t); |
---|
| 418 | RETVAL = (IV)t; |
---|
| 419 | OUTPUT: |
---|
| 420 | RETVAL |
---|
| 421 | |
---|
| 422 | void |
---|
| 423 | remove_timer(timer) |
---|
| 424 | IV timer |
---|
| 425 | PREINIT: |
---|
| 426 | owl_timer *t; |
---|
| 427 | CODE: |
---|
| 428 | t = (owl_timer*)timer; |
---|
| 429 | owl_function_debugmsg("Freeing timer %p", t); |
---|
| 430 | owl_select_remove_timer(t); |
---|