[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 |
---|
| 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 | } |
---|
[17eed9c] | 124 | |
---|
[dd16bdd] | 125 | hash = (HV*)SvRV(msg); |
---|
| 126 | m = owl_malloc(sizeof(owl_message)); |
---|
| 127 | owl_message_init(m); |
---|
[17eed9c] | 128 | |
---|
[dd16bdd] | 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)); |
---|
[17eed9c] | 137 | } else if(!strcmp(key, "private")) { |
---|
[3c9012b] | 138 | SV * v = hv_iterval(hash, ent); |
---|
| 139 | if(SvTRUE(v)) { |
---|
| 140 | owl_message_set_isprivate(m); |
---|
| 141 | } |
---|
[17eed9c] | 142 | } else if (!strcmp(key, "hostname")) { |
---|
| 143 | owl_message_set_hostname(m, val); |
---|
| 144 | } else if (!strcmp(key, "zwriteline")) { |
---|
| 145 | owl_message_set_zwriteline(m, val); |
---|
| 146 | } else if (!strcmp(key, "time")) { |
---|
| 147 | m->timestr = owl_strdup(val); |
---|
| 148 | struct tm tm; |
---|
| 149 | strptime(val, "%a %b %d %T %Y", &tm); |
---|
| 150 | m->time = mktime(&tm); |
---|
[dd16bdd] | 151 | } else { |
---|
| 152 | owl_message_set_attribute(m, key, val); |
---|
| 153 | } |
---|
| 154 | } |
---|
[1b6b2f3] | 155 | if(owl_message_is_type_admin(m)) { |
---|
| 156 | if(!owl_message_get_attribute_value(m, "adminheader")) |
---|
| 157 | owl_message_set_attribute(m, "adminheader", ""); |
---|
| 158 | } |
---|
[dd16bdd] | 159 | |
---|
| 160 | owl_global_messagequeue_addmsg(&g, m); |
---|
[1b6b2f3] | 161 | } |
---|
[db8b00b] | 162 | |
---|
| 163 | void start_question(line, callback) |
---|
| 164 | char *line |
---|
| 165 | SV *callback |
---|
| 166 | PREINIT: |
---|
| 167 | CODE: |
---|
| 168 | { |
---|
| 169 | if(!SV_IS_CODEREF(callback)) |
---|
| 170 | croak("Callback must be a subref"); |
---|
| 171 | |
---|
| 172 | owl_function_start_question(line); |
---|
| 173 | |
---|
| 174 | SvREFCNT_inc(callback); |
---|
| 175 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
| 176 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | void start_password(line, callback) |
---|
| 180 | char *line |
---|
| 181 | SV *callback |
---|
| 182 | PREINIT: |
---|
| 183 | CODE: |
---|
| 184 | { |
---|
| 185 | if(!SV_IS_CODEREF(callback)) |
---|
| 186 | croak("Callback must be a subref"); |
---|
| 187 | |
---|
| 188 | owl_function_start_password(line); |
---|
| 189 | |
---|
| 190 | SvREFCNT_inc(callback); |
---|
| 191 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
| 192 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | void start_edit_win(line, callback) |
---|
| 196 | char *line |
---|
| 197 | SV *callback |
---|
| 198 | PREINIT: |
---|
| 199 | owl_editwin * e; |
---|
| 200 | char buff[1024]; |
---|
| 201 | CODE: |
---|
| 202 | { |
---|
| 203 | if(!SV_IS_CODEREF(callback)) |
---|
| 204 | croak("Callback must be a subref"); |
---|
| 205 | |
---|
| 206 | e = owl_global_get_typwin(&g); |
---|
| 207 | owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE, |
---|
| 208 | owl_global_get_msg_history(&g)); |
---|
| 209 | owl_editwin_clear(e); |
---|
| 210 | owl_editwin_set_dotsend(e); |
---|
| 211 | snprintf(buff, 1023, "----> %s\n", line); |
---|
| 212 | owl_editwin_set_locktext(e, buff); |
---|
| 213 | |
---|
| 214 | owl_global_set_typwin_active(&g); |
---|
| 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 | } |
---|
[6b3f797] | 220 | |
---|
| 221 | |
---|
| 222 | char * |
---|
| 223 | get_data_dir () |
---|
| 224 | CODE: |
---|
| 225 | RETVAL = (char *) DATADIR; |
---|
| 226 | OUTPUT: |
---|
| 227 | RETVAL |
---|
[b6a253c] | 228 | |
---|
| 229 | void |
---|
| 230 | popless_text(text) |
---|
| 231 | char *text |
---|
| 232 | CODE: |
---|
| 233 | { |
---|
| 234 | owl_function_popless_text(text); |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | void |
---|
| 238 | popless_ztext(text) |
---|
| 239 | char *text |
---|
| 240 | CODE: |
---|
| 241 | { |
---|
| 242 | owl_fmtext fm; |
---|
| 243 | owl_fmtext_init_null(&fm); |
---|
| 244 | owl_fmtext_append_ztext(&fm, text); |
---|
| 245 | owl_function_popless_fmtext(&fm); |
---|
| 246 | owl_fmtext_free(&fm); |
---|
| 247 | } |
---|