[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 | |
---|
[8ee73f8d] | 15 | MODULE = owl PACKAGE = owl |
---|
| 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 | |
---|
[f1e629d] | 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 | char * |
---|
| 43 | zephyr_getrealm() |
---|
| 44 | CODE: |
---|
[8a54409] | 45 | RETVAL = owl_zephyr_get_realm(); |
---|
[f1e629d] | 46 | OUTPUT: |
---|
| 47 | RETVAL |
---|
| 48 | |
---|
| 49 | char * |
---|
| 50 | zephyr_getsender() |
---|
| 51 | CODE: |
---|
[8a54409] | 52 | RETVAL = owl_zephyr_get_sender(); |
---|
[f1e629d] | 53 | OUTPUT: |
---|
| 54 | RETVAL |
---|
| 55 | |
---|
[e1c4636] | 56 | void |
---|
[f1e629d] | 57 | zephyr_zwrite(cmd,msg) |
---|
[e1c4636] | 58 | char *cmd |
---|
| 59 | char *msg |
---|
| 60 | PREINIT: |
---|
| 61 | int i; |
---|
| 62 | CODE: |
---|
| 63 | i = owl_zwrite_create_and_send_from_line(cmd, msg); |
---|
| 64 | |
---|
| 65 | char * |
---|
| 66 | ztext_stylestrip(ztext) |
---|
| 67 | char *ztext |
---|
| 68 | PREINIT: |
---|
| 69 | char *rv = NULL; |
---|
| 70 | CODE: |
---|
[1fd0b25] | 71 | rv = owl_function_ztext_stylestrip(ztext); |
---|
[e1c4636] | 72 | RETVAL = rv; |
---|
| 73 | OUTPUT: |
---|
| 74 | RETVAL |
---|
| 75 | CLEANUP: |
---|
| 76 | if (rv) owl_free(rv); |
---|
| 77 | |
---|
[6922edd] | 78 | void |
---|
| 79 | new_command_internal(name, func, summary, usage, description) |
---|
| 80 | char *name |
---|
| 81 | SV *func |
---|
| 82 | char *summary |
---|
| 83 | char *usage |
---|
| 84 | char *description |
---|
| 85 | PREINIT: |
---|
| 86 | owl_cmd cmd; |
---|
| 87 | CODE: |
---|
[db8b00b] | 88 | { |
---|
| 89 | if(!SV_IS_CODEREF(func)) { |
---|
| 90 | croak("Command function must be a coderef!"); |
---|
| 91 | } |
---|
[6922edd] | 92 | SvREFCNT_inc(func); |
---|
| 93 | cmd.name = name; |
---|
| 94 | cmd.cmd_perl = func; |
---|
| 95 | cmd.summary = summary; |
---|
| 96 | cmd.usage = usage; |
---|
| 97 | cmd.description = description; |
---|
| 98 | cmd.validctx = OWL_CTX_ANY; |
---|
| 99 | cmd.cmd_aliased_to = NULL; |
---|
| 100 | cmd.cmd_args_fn = NULL; |
---|
| 101 | cmd.cmd_v_fn = NULL; |
---|
| 102 | cmd.cmd_i_fn = NULL; |
---|
| 103 | cmd.cmd_ctxargs_fn = NULL; |
---|
| 104 | cmd.cmd_ctxv_fn = NULL; |
---|
| 105 | cmd.cmd_ctxi_fn = NULL; |
---|
| 106 | owl_cmddict_add_cmd(owl_global_get_cmddict(&g), &cmd); |
---|
[db8b00b] | 107 | } |
---|
[dd16bdd] | 108 | |
---|
[1b6b2f3] | 109 | void queue_message(msg) |
---|
[dd16bdd] | 110 | SV *msg |
---|
| 111 | PREINIT: |
---|
| 112 | char * key; |
---|
| 113 | char * val; |
---|
| 114 | owl_message *m; |
---|
| 115 | HV * hash; |
---|
| 116 | HE * ent; |
---|
| 117 | I32 count; |
---|
| 118 | I32 len; |
---|
| 119 | CODE: |
---|
[1b6b2f3] | 120 | { |
---|
[dd16bdd] | 121 | if(!SvROK(msg) || SvTYPE(SvRV(msg)) != SVt_PVHV) { |
---|
| 122 | croak("Usage: owl::queue_message($message)"); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | hash = (HV*)SvRV(msg); |
---|
| 126 | m = owl_malloc(sizeof(owl_message)); |
---|
| 127 | owl_message_init(m); |
---|
| 128 | |
---|
| 129 | count = hv_iterinit(hash); |
---|
| 130 | while((ent = hv_iternext(hash))) { |
---|
| 131 | key = hv_iterkey(ent, &len); |
---|
| 132 | val = SvPV_nolen(hv_iterval(hash, ent)); |
---|
| 133 | if(!strcmp(key, "type")) { |
---|
| 134 | owl_message_set_type(m, owl_message_parse_type(val)); |
---|
| 135 | } else if(!strcmp(key, "direction")) { |
---|
| 136 | owl_message_set_direction(m, owl_message_parse_direction(val)); |
---|
| 137 | } else { |
---|
| 138 | owl_message_set_attribute(m, key, val); |
---|
| 139 | } |
---|
| 140 | } |
---|
[1b6b2f3] | 141 | owl_message_set_isprivate(m); |
---|
| 142 | if(owl_message_is_type_admin(m)) { |
---|
| 143 | if(!owl_message_get_attribute_value(m, "adminheader")) |
---|
| 144 | owl_message_set_attribute(m, "adminheader", ""); |
---|
| 145 | } |
---|
[dd16bdd] | 146 | |
---|
| 147 | owl_global_messagequeue_addmsg(&g, m); |
---|
[1b6b2f3] | 148 | } |
---|
[db8b00b] | 149 | |
---|
| 150 | void start_question(line, callback) |
---|
| 151 | char *line |
---|
| 152 | SV *callback |
---|
| 153 | PREINIT: |
---|
| 154 | CODE: |
---|
| 155 | { |
---|
| 156 | if(!SV_IS_CODEREF(callback)) |
---|
| 157 | croak("Callback must be a subref"); |
---|
| 158 | |
---|
| 159 | owl_function_start_question(line); |
---|
| 160 | |
---|
| 161 | SvREFCNT_inc(callback); |
---|
| 162 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
| 163 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | void start_password(line, callback) |
---|
| 167 | char *line |
---|
| 168 | SV *callback |
---|
| 169 | PREINIT: |
---|
| 170 | CODE: |
---|
| 171 | { |
---|
| 172 | if(!SV_IS_CODEREF(callback)) |
---|
| 173 | croak("Callback must be a subref"); |
---|
| 174 | |
---|
| 175 | owl_function_start_password(line); |
---|
| 176 | |
---|
| 177 | SvREFCNT_inc(callback); |
---|
| 178 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
| 179 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | void start_edit_win(line, callback) |
---|
| 183 | char *line |
---|
| 184 | SV *callback |
---|
| 185 | PREINIT: |
---|
| 186 | owl_editwin * e; |
---|
| 187 | char buff[1024]; |
---|
| 188 | CODE: |
---|
| 189 | { |
---|
| 190 | if(!SV_IS_CODEREF(callback)) |
---|
| 191 | croak("Callback must be a subref"); |
---|
| 192 | |
---|
| 193 | e = owl_global_get_typwin(&g); |
---|
| 194 | owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE, |
---|
| 195 | owl_global_get_msg_history(&g)); |
---|
| 196 | owl_editwin_clear(e); |
---|
| 197 | owl_editwin_set_dotsend(e); |
---|
| 198 | snprintf(buff, 1023, "----> %s\n", line); |
---|
| 199 | owl_editwin_set_locktext(e, buff); |
---|
| 200 | |
---|
| 201 | owl_global_set_typwin_active(&g); |
---|
| 202 | |
---|
| 203 | SvREFCNT_inc(callback); |
---|
| 204 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
| 205 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
| 206 | } |
---|