[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 | |
---|
[8203afd] | 15 | MODULE = BarnOwl PACKAGE = BarnOwl |
---|
[8ee73f8d] | 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 |
---|
[7f792c1] | 41 | |
---|
| 42 | time_t |
---|
| 43 | getidletime() |
---|
| 44 | CODE: |
---|
| 45 | RETVAL = owl_global_get_idletime(&g); |
---|
| 46 | OUTPUT: |
---|
| 47 | RETVAL |
---|
[f1e629d] | 48 | |
---|
| 49 | char * |
---|
| 50 | zephyr_getrealm() |
---|
| 51 | CODE: |
---|
[8a54409] | 52 | RETVAL = owl_zephyr_get_realm(); |
---|
[f1e629d] | 53 | OUTPUT: |
---|
| 54 | RETVAL |
---|
| 55 | |
---|
| 56 | char * |
---|
| 57 | zephyr_getsender() |
---|
| 58 | CODE: |
---|
[8a54409] | 59 | RETVAL = owl_zephyr_get_sender(); |
---|
[f1e629d] | 60 | OUTPUT: |
---|
| 61 | RETVAL |
---|
| 62 | |
---|
[e1c4636] | 63 | void |
---|
[f1e629d] | 64 | zephyr_zwrite(cmd,msg) |
---|
[e1c4636] | 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: |
---|
[1fd0b25] | 78 | rv = owl_function_ztext_stylestrip(ztext); |
---|
[e1c4636] | 79 | RETVAL = rv; |
---|
| 80 | OUTPUT: |
---|
| 81 | RETVAL |
---|
| 82 | CLEANUP: |
---|
| 83 | if (rv) owl_free(rv); |
---|
| 84 | |
---|
[6922edd] | 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: |
---|
[db8b00b] | 95 | { |
---|
| 96 | if(!SV_IS_CODEREF(func)) { |
---|
| 97 | croak("Command function must be a coderef!"); |
---|
| 98 | } |
---|
[6922edd] | 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); |
---|
[db8b00b] | 114 | } |
---|
[dd16bdd] | 115 | |
---|
[1b6b2f3] | 116 | void queue_message(msg) |
---|
[dd16bdd] | 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: |
---|
[1b6b2f3] | 127 | { |
---|
[dd16bdd] | 128 | if(!SvROK(msg) || SvTYPE(SvRV(msg)) != SVt_PVHV) { |
---|
| 129 | croak("Usage: owl::queue_message($message)"); |
---|
| 130 | } |
---|
[17eed9c] | 131 | |
---|
[dd16bdd] | 132 | hash = (HV*)SvRV(msg); |
---|
| 133 | m = owl_malloc(sizeof(owl_message)); |
---|
| 134 | owl_message_init(m); |
---|
[17eed9c] | 135 | |
---|
[dd16bdd] | 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)); |
---|
[17eed9c] | 144 | } else if(!strcmp(key, "private")) { |
---|
[3c9012b] | 145 | SV * v = hv_iterval(hash, ent); |
---|
| 146 | if(SvTRUE(v)) { |
---|
| 147 | owl_message_set_isprivate(m); |
---|
| 148 | } |
---|
[17eed9c] | 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); |
---|
[dd16bdd] | 158 | } else { |
---|
| 159 | owl_message_set_attribute(m, key, val); |
---|
| 160 | } |
---|
| 161 | } |
---|
[1b6b2f3] | 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 | } |
---|
[dd16bdd] | 166 | |
---|
| 167 | owl_global_messagequeue_addmsg(&g, m); |
---|
[1b6b2f3] | 168 | } |
---|
[db8b00b] | 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 | } |
---|
[6b3f797] | 227 | |
---|
| 228 | |
---|
| 229 | char * |
---|
| 230 | get_data_dir () |
---|
| 231 | CODE: |
---|
| 232 | RETVAL = (char *) DATADIR; |
---|
| 233 | OUTPUT: |
---|
| 234 | RETVAL |
---|
[b6a253c] | 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 | } |
---|