| 1 | /* Copyright (c) 2006-2011 The BarnOwl Developers. All rights reserved. |
|---|
| 2 | * Copyright (c) 2004 James Kretchmar. All rights reserved. |
|---|
| 3 | * |
|---|
| 4 | * This program is free software. You can redistribute it and/or |
|---|
| 5 | * modify under the terms of the Sleepycat License. See the COPYING |
|---|
| 6 | * file included with the distribution for more information. |
|---|
| 7 | */ |
|---|
| 8 | |
|---|
| 9 | #ifndef INC_BARNOWL_OWL_H |
|---|
| 10 | #define INC_BARNOWL_OWL_H |
|---|
| 11 | |
|---|
| 12 | #include <config.h> |
|---|
| 13 | |
|---|
| 14 | #include "compat/compat.h" |
|---|
| 15 | |
|---|
| 16 | #include <stdbool.h> |
|---|
| 17 | |
|---|
| 18 | #ifndef OWL_PERL |
|---|
| 19 | #define NCURSES_ENABLE_STDBOOL_H 1 |
|---|
| 20 | #include <ncursesw/curses.h> |
|---|
| 21 | #include <ncursesw/panel.h> |
|---|
| 22 | #endif |
|---|
| 23 | #include <sys/param.h> |
|---|
| 24 | #include <sys/types.h> |
|---|
| 25 | #include <ctype.h> |
|---|
| 26 | #include <errno.h> |
|---|
| 27 | #include <EXTERN.h> |
|---|
| 28 | #include <fcntl.h> |
|---|
| 29 | #include <netdb.h> |
|---|
| 30 | #include <regex.h> |
|---|
| 31 | #include <time.h> |
|---|
| 32 | #include <signal.h> |
|---|
| 33 | #include <stdlib.h> |
|---|
| 34 | #include <string.h> |
|---|
| 35 | #include <termios.h> |
|---|
| 36 | #include <unistd.h> |
|---|
| 37 | #include <wchar.h> |
|---|
| 38 | #include <glib.h> |
|---|
| 39 | #ifdef HAVE_LIBZEPHYR |
|---|
| 40 | #include <zephyr/zephyr.h> |
|---|
| 41 | #endif |
|---|
| 42 | #ifdef HAVE_COM_ERR_H |
|---|
| 43 | #include <com_err.h> |
|---|
| 44 | #endif |
|---|
| 45 | |
|---|
| 46 | /* Perl and curses don't play nice. */ |
|---|
| 47 | #ifdef OWL_PERL |
|---|
| 48 | typedef struct _owl_fake_WINDOW WINDOW; |
|---|
| 49 | typedef struct _owl_fake_PANEL PANEL; |
|---|
| 50 | /* logout is defined in FreeBSD. */ |
|---|
| 51 | #define logout logout_ |
|---|
| 52 | #define HAS_BOOL |
|---|
| 53 | #include <perl.h> |
|---|
| 54 | #include "owl_perl.h" |
|---|
| 55 | #undef logout |
|---|
| 56 | #include "XSUB.h" |
|---|
| 57 | #else |
|---|
| 58 | typedef struct _owl_fake_SV SV; |
|---|
| 59 | typedef struct _owl_fake_AV AV; |
|---|
| 60 | typedef struct _owl_fake_HV HV; |
|---|
| 61 | #endif |
|---|
| 62 | |
|---|
| 63 | #include "window.h" |
|---|
| 64 | |
|---|
| 65 | extern const char *version; |
|---|
| 66 | |
|---|
| 67 | /* Feature that is being tested to redirect stderr through a pipe. |
|---|
| 68 | * There may still be some portability problems with this. */ |
|---|
| 69 | #define OWL_STDERR_REDIR 1 |
|---|
| 70 | |
|---|
| 71 | #define OWL_DEBUG 0 |
|---|
| 72 | #define OWL_DEBUG_FILE "/var/tmp/barnowl-debug" |
|---|
| 73 | |
|---|
| 74 | #define OWL_CONFIG_DIR "/.owl" /* this is relative to the user's home directory */ |
|---|
| 75 | |
|---|
| 76 | #define OWL_FMTEXT_ATTR_NONE 0 |
|---|
| 77 | #define OWL_FMTEXT_ATTR_BOLD 1 |
|---|
| 78 | #define OWL_FMTEXT_ATTR_REVERSE 2 |
|---|
| 79 | #define OWL_FMTEXT_ATTR_UNDERLINE 4 |
|---|
| 80 | |
|---|
| 81 | #define OWL_FMTEXT_UC_BASE 0x100000 /* Unicode Plane 16 - Supplementary Private Use Area-B*/ |
|---|
| 82 | #define OWL_FMTEXT_UC_ATTR ( OWL_FMTEXT_UC_BASE | 0x800 ) |
|---|
| 83 | #define OWL_FMTEXT_UC_ATTR_MASK 0x7 |
|---|
| 84 | #define OWL_FMTEXT_UC_COLOR_BASE ( OWL_FMTEXT_UC_BASE | 0x400 ) |
|---|
| 85 | #define OWL_FMTEXT_UC_FGCOLOR OWL_FMTEXT_UC_COLOR_BASE |
|---|
| 86 | #define OWL_FMTEXT_UC_BGCOLOR ( OWL_FMTEXT_UC_COLOR_BASE | 0x200 ) |
|---|
| 87 | #define OWL_FMTEXT_UC_DEFAULT_COLOR 0x100 |
|---|
| 88 | #define OWL_FMTEXT_UC_FGDEFAULT ( OWL_FMTEXT_UC_FGCOLOR | OWL_FMTEXT_UC_DEFAULT_COLOR ) |
|---|
| 89 | #define OWL_FMTEXT_UC_BGDEFAULT ( OWL_FMTEXT_UC_BGCOLOR | OWL_FMTEXT_UC_DEFAULT_COLOR ) |
|---|
| 90 | #define OWL_FMTEXT_UC_COLOR_MASK 0xFF |
|---|
| 91 | #define OWL_FMTEXT_UC_ALLCOLOR_MASK ( OWL_FMTEXT_UC_COLOR_MASK | OWL_FMTEXT_UC_DEFAULT_COLOR | 0x200) |
|---|
| 92 | #define OWL_FMTEXT_UC_STARTBYTE_UTF8 '\xf4' |
|---|
| 93 | |
|---|
| 94 | #define OWL_COLOR_BLACK 0 |
|---|
| 95 | #define OWL_COLOR_RED 1 |
|---|
| 96 | #define OWL_COLOR_GREEN 2 |
|---|
| 97 | #define OWL_COLOR_YELLOW 3 |
|---|
| 98 | #define OWL_COLOR_BLUE 4 |
|---|
| 99 | #define OWL_COLOR_MAGENTA 5 |
|---|
| 100 | #define OWL_COLOR_CYAN 6 |
|---|
| 101 | #define OWL_COLOR_WHITE 7 |
|---|
| 102 | #define OWL_COLOR_DEFAULT -1 |
|---|
| 103 | #define OWL_COLOR_INVALID -2 |
|---|
| 104 | |
|---|
| 105 | #define OWL_TAB_WIDTH 8 |
|---|
| 106 | |
|---|
| 107 | #define OWL_EDITWIN_STYLE_MULTILINE 0 |
|---|
| 108 | #define OWL_EDITWIN_STYLE_ONELINE 1 |
|---|
| 109 | |
|---|
| 110 | #define OWL_MESSAGE_DIRECTION_NONE 0 |
|---|
| 111 | #define OWL_MESSAGE_DIRECTION_IN 1 |
|---|
| 112 | #define OWL_MESSAGE_DIRECTION_OUT 2 |
|---|
| 113 | |
|---|
| 114 | #define OWL_DIRECTION_NONE 0 |
|---|
| 115 | #define OWL_DIRECTION_DOWNWARDS 1 |
|---|
| 116 | #define OWL_DIRECTION_UPWARDS 2 |
|---|
| 117 | |
|---|
| 118 | #define OWL_LOGGING_DIRECTION_BOTH 0 |
|---|
| 119 | #define OWL_LOGGING_DIRECTION_IN 1 |
|---|
| 120 | #define OWL_LOGGING_DIRECTION_OUT 2 |
|---|
| 121 | |
|---|
| 122 | #define OWL_SCROLLMODE_NORMAL 0 |
|---|
| 123 | #define OWL_SCROLLMODE_TOP 1 |
|---|
| 124 | #define OWL_SCROLLMODE_NEARTOP 2 |
|---|
| 125 | #define OWL_SCROLLMODE_CENTER 3 |
|---|
| 126 | #define OWL_SCROLLMODE_PAGED 4 |
|---|
| 127 | #define OWL_SCROLLMODE_PAGEDCENTER 5 |
|---|
| 128 | |
|---|
| 129 | #define OWL_TAB 3 /* This *HAS* to be the size of TABSTR below */ |
|---|
| 130 | #define OWL_TABSTR " " |
|---|
| 131 | #define OWL_MSGTAB 7 |
|---|
| 132 | #define OWL_TYPWIN_SIZE 8 |
|---|
| 133 | #define OWL_HISTORYSIZE 50 |
|---|
| 134 | |
|---|
| 135 | /* Indicate current state, as well as what is allowed */ |
|---|
| 136 | #define OWL_CTX_ANY 0xffff |
|---|
| 137 | /* Only one of these may be active at a time... */ |
|---|
| 138 | #define OWL_CTX_MODE_BITS 0x000f |
|---|
| 139 | #define OWL_CTX_STARTUP 0x0001 |
|---|
| 140 | #define OWL_CTX_READCONFIG 0x0002 |
|---|
| 141 | #define OWL_CTX_INTERACTIVE 0x0004 |
|---|
| 142 | /* Only one of these may be active at a time... */ |
|---|
| 143 | #define OWL_CTX_ACTIVE_BITS 0xfff0 |
|---|
| 144 | #define OWL_CTX_POPWIN 0x00f0 |
|---|
| 145 | #define OWL_CTX_POPLESS 0x0010 |
|---|
| 146 | #define OWL_CTX_RECWIN 0x0f00 |
|---|
| 147 | #define OWL_CTX_RECV 0x0100 |
|---|
| 148 | #define OWL_CTX_TYPWIN 0xf000 |
|---|
| 149 | #define OWL_CTX_EDIT 0x7000 |
|---|
| 150 | #define OWL_CTX_EDITLINE 0x1000 |
|---|
| 151 | #define OWL_CTX_EDITMULTI 0x2000 |
|---|
| 152 | #define OWL_CTX_EDITRESPONSE 0x4000 |
|---|
| 153 | |
|---|
| 154 | #define OWL_VARIABLE_OTHER 0 |
|---|
| 155 | #define OWL_VARIABLE_INT 1 |
|---|
| 156 | #define OWL_VARIABLE_BOOL 2 |
|---|
| 157 | #define OWL_VARIABLE_STRING 3 |
|---|
| 158 | |
|---|
| 159 | #define OWL_OUTPUT_RETURN 0 |
|---|
| 160 | #define OWL_OUTPUT_POPUP 1 |
|---|
| 161 | #define OWL_OUTPUT_ADMINMSG 2 |
|---|
| 162 | |
|---|
| 163 | #define OWL_FILTER_MAX_DEPTH 300 |
|---|
| 164 | |
|---|
| 165 | #define OWL_KEYMAP_MAXSTACK 20 |
|---|
| 166 | |
|---|
| 167 | #define OWL_KEYBINDING_NOOP 0 /* dummy binding that does nothing */ |
|---|
| 168 | #define OWL_KEYBINDING_COMMAND 1 /* command string */ |
|---|
| 169 | #define OWL_KEYBINDING_FUNCTION 2 /* function taking no args */ |
|---|
| 170 | |
|---|
| 171 | #define OWL_DEFAULT_ZAWAYMSG "I'm sorry, but I am currently away from the terminal and am\nnot able to receive your message.\n" |
|---|
| 172 | |
|---|
| 173 | #define OWL_CMD_ALIAS_SUMMARY_PREFIX "command alias to: " |
|---|
| 174 | |
|---|
| 175 | #define OWL_WEBZEPHYR_PRINCIPAL "daemon/webzephyr.mit.edu" |
|---|
| 176 | #define OWL_WEBZEPHYR_CLASS "webzephyr" |
|---|
| 177 | #define OWL_WEBZEPHYR_OPCODE "webzephyr" |
|---|
| 178 | |
|---|
| 179 | #define OWL_ZEPHYR_NOSTRIP_HOST "host/" |
|---|
| 180 | #define OWL_ZEPHYR_NOSTRIP_RCMD "rcmd." |
|---|
| 181 | #define OWL_ZEPHYR_NOSTRIP_DAEMON5 "daemon/" |
|---|
| 182 | #define OWL_ZEPHYR_NOSTRIP_DAEMON4 "daemon." |
|---|
| 183 | |
|---|
| 184 | #define OWL_REGEX_QUOTECHARS "!+*.?[]^\\${}()|" |
|---|
| 185 | #define OWL_REGEX_QUOTEWITH "\\" |
|---|
| 186 | |
|---|
| 187 | #if defined(HAVE_DES_STRING_TO_KEY) && defined(HAVE_DES_KEY_SCHED) && defined(HAVE_DES_ECB_ENCRYPT) |
|---|
| 188 | #define OWL_ENABLE_ZCRYPT 1 |
|---|
| 189 | #endif |
|---|
| 190 | |
|---|
| 191 | /* Annotate functions in which the caller owns the return value and is |
|---|
| 192 | * responsible for ensuring it is freed. */ |
|---|
| 193 | #define CALLER_OWN G_GNUC_WARN_UNUSED_RESULT |
|---|
| 194 | |
|---|
| 195 | #define OWL_META(key) ((key)|010000) |
|---|
| 196 | /* OWL_CTRL is definied in kepress.c */ |
|---|
| 197 | |
|---|
| 198 | #ifdef HAVE_LIBZEPHYR |
|---|
| 199 | /* libzephyr doesn't use const, so we appease the type system with this kludge. |
|---|
| 200 | * This just casts const char * to char * in a way that doesn't yield a warning |
|---|
| 201 | * from gcc -Wcast-qual. */ |
|---|
| 202 | static inline char *zstr(const char *str) |
|---|
| 203 | { |
|---|
| 204 | union { char *rw; const char *ro; } u; |
|---|
| 205 | u.ro = str; |
|---|
| 206 | return u.rw; |
|---|
| 207 | } |
|---|
| 208 | #endif |
|---|
| 209 | |
|---|
| 210 | /* Convert char *const * into const char *const *. This conversion is safe, |
|---|
| 211 | * and implicit in C++ (conv.qual 4) but for some reason not in C. */ |
|---|
| 212 | static inline const char *const *strs(char *const *pstr) |
|---|
| 213 | { |
|---|
| 214 | return (const char *const *)pstr; |
|---|
| 215 | } |
|---|
| 216 | |
|---|
| 217 | typedef struct _owl_variable { |
|---|
| 218 | char *name; |
|---|
| 219 | int type; /* OWL_VARIABLE_* */ |
|---|
| 220 | char *default_str; /* the default value as a string */ |
|---|
| 221 | char *validsettings; /* documentation of valid settings */ |
|---|
| 222 | char *summary; /* summary of usage */ |
|---|
| 223 | char *description; /* detailed description */ |
|---|
| 224 | bool takes_on_off; /* allow passing on/off in argument-less set/unset */ |
|---|
| 225 | GClosure *set_fromstring_fn; |
|---|
| 226 | /* sets the variable to a value |
|---|
| 227 | * of the appropriate type. |
|---|
| 228 | * unless documented, this |
|---|
| 229 | * should make a copy. |
|---|
| 230 | * returns 0 on success. */ |
|---|
| 231 | GClosure *get_tostring_fn; |
|---|
| 232 | /* converts val to a string; |
|---|
| 233 | * caller must free the result */ |
|---|
| 234 | |
|---|
| 235 | /* These are only valid for OWL_VARIABLE_{INT,BOOL,STRING} */ |
|---|
| 236 | GValue val; /* current value, if default get_fn/set_fn */ |
|---|
| 237 | |
|---|
| 238 | GCallback get_fn; |
|---|
| 239 | /* returns a reference to the current value. |
|---|
| 240 | * WARNING: this approach is hard to make |
|---|
| 241 | * thread-safe... */ |
|---|
| 242 | GCallback validate_fn; |
|---|
| 243 | /* returns 1 if newval is valid */ |
|---|
| 244 | GCallback set_fn; |
|---|
| 245 | /* sets the variable to a value |
|---|
| 246 | * of the appropriate type. |
|---|
| 247 | * unless documented, this |
|---|
| 248 | * should make a copy. |
|---|
| 249 | * returns 0 on success. */ |
|---|
| 250 | } owl_variable; |
|---|
| 251 | |
|---|
| 252 | |
|---|
| 253 | typedef struct _owl_input { |
|---|
| 254 | int ch; |
|---|
| 255 | gunichar uch; |
|---|
| 256 | } owl_input; |
|---|
| 257 | |
|---|
| 258 | typedef struct _owl_fmtext { |
|---|
| 259 | GString *buff; |
|---|
| 260 | } owl_fmtext; |
|---|
| 261 | |
|---|
| 262 | typedef struct _owl_dict_el { |
|---|
| 263 | char *k; /* key */ |
|---|
| 264 | void *v; /* value */ |
|---|
| 265 | } owl_dict_el; |
|---|
| 266 | |
|---|
| 267 | typedef struct _owl_dict { |
|---|
| 268 | int size; |
|---|
| 269 | int avail; |
|---|
| 270 | owl_dict_el *els; /* invariant: sorted by k */ |
|---|
| 271 | } owl_dict; |
|---|
| 272 | typedef owl_dict owl_vardict; /* dict of variables */ |
|---|
| 273 | typedef owl_dict owl_cmddict; /* dict of commands */ |
|---|
| 274 | |
|---|
| 275 | typedef struct _owl_context { |
|---|
| 276 | int mode; |
|---|
| 277 | void *data; /* determined by mode */ |
|---|
| 278 | char *keymap; |
|---|
| 279 | owl_window *cursor; |
|---|
| 280 | void (*deactivate_cb)(struct _owl_context*); |
|---|
| 281 | void (*delete_cb)(struct _owl_context*); |
|---|
| 282 | void *cbdata; |
|---|
| 283 | } owl_context; |
|---|
| 284 | |
|---|
| 285 | typedef struct _owl_cmd { /* command */ |
|---|
| 286 | char *name; |
|---|
| 287 | |
|---|
| 288 | char *summary; /* one line summary of command */ |
|---|
| 289 | char *usage; /* usage synopsis */ |
|---|
| 290 | char *description; /* long description of command */ |
|---|
| 291 | |
|---|
| 292 | int validctx; /* bitmask of valid contexts */ |
|---|
| 293 | |
|---|
| 294 | /* we should probably have a type here that says which of |
|---|
| 295 | * the following is valid, and maybe make the below into a union... */ |
|---|
| 296 | |
|---|
| 297 | /* Only one of these may be non-NULL ... */ |
|---|
| 298 | |
|---|
| 299 | char *cmd_aliased_to; /* what this command is aliased to... */ |
|---|
| 300 | |
|---|
| 301 | /* These don't take any context */ |
|---|
| 302 | CALLER_OWN char *(*cmd_args_fn)(int argc, const char *const *argv, const char *buff); |
|---|
| 303 | /* takes argv and the full command as buff. |
|---|
| 304 | * caller must free return value if !NULL */ |
|---|
| 305 | void (*cmd_v_fn)(void); /* takes no args */ |
|---|
| 306 | void (*cmd_i_fn)(int i); /* takes an int as an arg */ |
|---|
| 307 | |
|---|
| 308 | /* The following also take the active context if it's valid */ |
|---|
| 309 | CALLER_OWN char *(*cmd_ctxargs_fn)(void *ctx, int argc, const char *const *argv, const char *buff); |
|---|
| 310 | /* takes argv and the full command as buff. |
|---|
| 311 | * caller must free return value if !NULL */ |
|---|
| 312 | void (*cmd_ctxv_fn)(void *ctx); /* takes no args */ |
|---|
| 313 | void (*cmd_ctxi_fn)(void *ctx, int i); /* takes an int as an arg */ |
|---|
| 314 | SV *cmd_perl; /* Perl closure that takes a list of args */ |
|---|
| 315 | } owl_cmd; |
|---|
| 316 | |
|---|
| 317 | |
|---|
| 318 | typedef struct _owl_zwrite { |
|---|
| 319 | char *cmd; |
|---|
| 320 | char *zwriteline; |
|---|
| 321 | char *class; |
|---|
| 322 | char *inst; |
|---|
| 323 | char *realm; |
|---|
| 324 | char *opcode; |
|---|
| 325 | char *zsig; |
|---|
| 326 | char *message; |
|---|
| 327 | GPtrArray *recips; |
|---|
| 328 | int cc; |
|---|
| 329 | int noping; |
|---|
| 330 | } owl_zwrite; |
|---|
| 331 | |
|---|
| 332 | typedef struct _owl_pair { |
|---|
| 333 | const char *key; |
|---|
| 334 | char *value; |
|---|
| 335 | } owl_pair; |
|---|
| 336 | |
|---|
| 337 | struct _owl_fmtext_cache; |
|---|
| 338 | |
|---|
| 339 | typedef struct _owl_message { |
|---|
| 340 | int id; |
|---|
| 341 | int direction; |
|---|
| 342 | #ifdef HAVE_LIBZEPHYR |
|---|
| 343 | bool has_notice; |
|---|
| 344 | ZNotice_t notice; |
|---|
| 345 | #endif |
|---|
| 346 | struct _owl_fmtext_cache * fmtext; |
|---|
| 347 | int delete; |
|---|
| 348 | const char *hostname; |
|---|
| 349 | GPtrArray *attributes; /* this is a list of pairs */ |
|---|
| 350 | char *timestr; |
|---|
| 351 | time_t time; |
|---|
| 352 | } owl_message; |
|---|
| 353 | |
|---|
| 354 | #define OWL_FMTEXT_CACHE_SIZE 1000 |
|---|
| 355 | /* We cache the saved fmtexts for the last bunch of messages we |
|---|
| 356 | rendered */ |
|---|
| 357 | typedef struct _owl_fmtext_cache { |
|---|
| 358 | owl_message * message; |
|---|
| 359 | owl_fmtext fmtext; |
|---|
| 360 | } owl_fmtext_cache; |
|---|
| 361 | |
|---|
| 362 | typedef struct _owl_style { |
|---|
| 363 | char *name; |
|---|
| 364 | SV *perlobj; |
|---|
| 365 | } owl_style; |
|---|
| 366 | |
|---|
| 367 | typedef struct _owl_mainwin { |
|---|
| 368 | int curtruncated; |
|---|
| 369 | int lasttruncated; |
|---|
| 370 | int lastdisplayed; |
|---|
| 371 | owl_window *window; |
|---|
| 372 | } owl_mainwin; |
|---|
| 373 | |
|---|
| 374 | typedef struct _owl_editwin owl_editwin; |
|---|
| 375 | typedef struct _owl_editwin_excursion owl_editwin_excursion; |
|---|
| 376 | |
|---|
| 377 | typedef struct _owl_viewwin { |
|---|
| 378 | owl_fmtext fmtext; |
|---|
| 379 | int textlines; |
|---|
| 380 | int topline; |
|---|
| 381 | int rightshift; |
|---|
| 382 | owl_window *window; |
|---|
| 383 | void (*onclose_hook) (struct _owl_viewwin *vwin, void *data); |
|---|
| 384 | void *onclose_hook_data; |
|---|
| 385 | |
|---|
| 386 | gulong sig_resize_id; |
|---|
| 387 | owl_window *content; |
|---|
| 388 | gulong sig_content_redraw_id; |
|---|
| 389 | owl_window *status; |
|---|
| 390 | gulong sig_status_redraw_id; |
|---|
| 391 | owl_window *cmdwin; |
|---|
| 392 | } owl_viewwin; |
|---|
| 393 | |
|---|
| 394 | typedef struct _owl_popwin { |
|---|
| 395 | owl_window *border; |
|---|
| 396 | owl_window *content; |
|---|
| 397 | gulong sig_redraw_id; |
|---|
| 398 | gulong sig_resize_id; |
|---|
| 399 | } owl_popwin; |
|---|
| 400 | |
|---|
| 401 | typedef struct _owl_msgwin { |
|---|
| 402 | char *msg; |
|---|
| 403 | owl_window *window; |
|---|
| 404 | gulong redraw_id; |
|---|
| 405 | } owl_msgwin; |
|---|
| 406 | |
|---|
| 407 | typedef struct _owl_messagelist { |
|---|
| 408 | GPtrArray *list; |
|---|
| 409 | } owl_messagelist; |
|---|
| 410 | |
|---|
| 411 | typedef struct _owl_regex { |
|---|
| 412 | int negate; |
|---|
| 413 | char *string; |
|---|
| 414 | regex_t re; |
|---|
| 415 | } owl_regex; |
|---|
| 416 | |
|---|
| 417 | typedef struct _owl_filterelement { |
|---|
| 418 | int (*match_message)(const struct _owl_filterelement *fe, const owl_message *m); |
|---|
| 419 | /* Append a string representation of the filterelement onto buf*/ |
|---|
| 420 | void (*print_elt)(const struct _owl_filterelement *fe, GString *buf); |
|---|
| 421 | /* Operands for and,or,not*/ |
|---|
| 422 | struct _owl_filterelement *left, *right; |
|---|
| 423 | /* For regex filters*/ |
|---|
| 424 | owl_regex re; |
|---|
| 425 | /* Used by regexes, filter references, and perl */ |
|---|
| 426 | char *field; |
|---|
| 427 | } owl_filterelement; |
|---|
| 428 | |
|---|
| 429 | typedef struct _owl_filter { |
|---|
| 430 | char *name; |
|---|
| 431 | owl_filterelement * root; |
|---|
| 432 | int fgcolor; |
|---|
| 433 | int bgcolor; |
|---|
| 434 | } owl_filter; |
|---|
| 435 | |
|---|
| 436 | typedef struct _owl_view { |
|---|
| 437 | char *name; |
|---|
| 438 | owl_filter *filter; |
|---|
| 439 | owl_messagelist *ml; |
|---|
| 440 | const owl_style *style; |
|---|
| 441 | int cachedmsgid; |
|---|
| 442 | } owl_view; |
|---|
| 443 | |
|---|
| 444 | typedef struct _owl_history { |
|---|
| 445 | GQueue hist; |
|---|
| 446 | GList *cur; |
|---|
| 447 | bool partial; |
|---|
| 448 | } owl_history; |
|---|
| 449 | |
|---|
| 450 | typedef struct _owl_mainpanel { |
|---|
| 451 | owl_window *panel; |
|---|
| 452 | owl_window *typwin; |
|---|
| 453 | owl_window *sepwin; |
|---|
| 454 | owl_window *msgwin; |
|---|
| 455 | owl_window *recwin; |
|---|
| 456 | int recwinlines; |
|---|
| 457 | } owl_mainpanel; |
|---|
| 458 | |
|---|
| 459 | typedef struct _owl_keybinding { |
|---|
| 460 | int *keys; /* keypress stack */ |
|---|
| 461 | int len; /* length of stack */ |
|---|
| 462 | int type; /* command or function? */ |
|---|
| 463 | char *desc; /* description (or "*user*") */ |
|---|
| 464 | char *command; /* command, if of type command */ |
|---|
| 465 | void (*function_fn)(void); /* function ptr, if of type function */ |
|---|
| 466 | } owl_keybinding; |
|---|
| 467 | |
|---|
| 468 | typedef struct _owl_keymap { |
|---|
| 469 | char *name; /* name of keymap */ |
|---|
| 470 | char *desc; /* description */ |
|---|
| 471 | GPtrArray *bindings; /* key bindings */ |
|---|
| 472 | const struct _owl_keymap *parent; /* parent */ |
|---|
| 473 | void (*default_fn)(owl_input j); /* default action (takes a keypress) */ |
|---|
| 474 | void (*prealways_fn)(owl_input j); /* always called before a keypress is received */ |
|---|
| 475 | void (*postalways_fn)(owl_input j); /* always called after keypress is processed */ |
|---|
| 476 | } owl_keymap; |
|---|
| 477 | |
|---|
| 478 | typedef struct _owl_keyhandler { |
|---|
| 479 | owl_dict keymaps; /* dictionary of keymaps */ |
|---|
| 480 | const owl_keymap *active; /* currently active keymap */ |
|---|
| 481 | int in_esc; /* escape pressed? */ |
|---|
| 482 | int kpstack[OWL_KEYMAP_MAXSTACK+1]; /* current stack of keypresses */ |
|---|
| 483 | int kpstackpos; /* location in stack (-1 = none) */ |
|---|
| 484 | } owl_keyhandler; |
|---|
| 485 | |
|---|
| 486 | typedef struct _owl_zbuddylist { |
|---|
| 487 | GPtrArray *zusers; |
|---|
| 488 | } owl_zbuddylist; |
|---|
| 489 | |
|---|
| 490 | typedef struct _owl_errqueue { |
|---|
| 491 | GPtrArray *errlist; |
|---|
| 492 | } owl_errqueue; |
|---|
| 493 | |
|---|
| 494 | typedef struct _owl_colorpair_mgr { |
|---|
| 495 | int next; |
|---|
| 496 | short **pairs; |
|---|
| 497 | bool overflow; |
|---|
| 498 | } owl_colorpair_mgr; |
|---|
| 499 | |
|---|
| 500 | typedef struct _owl_popexec { |
|---|
| 501 | int refcount; |
|---|
| 502 | owl_viewwin *vwin; |
|---|
| 503 | int winactive; |
|---|
| 504 | pid_t pid; /* or 0 if it has terminated */ |
|---|
| 505 | guint io_watch; |
|---|
| 506 | } owl_popexec; |
|---|
| 507 | |
|---|
| 508 | typedef struct _owl_global { |
|---|
| 509 | owl_mainwin *mw; |
|---|
| 510 | owl_popwin *pw; |
|---|
| 511 | owl_msgwin msgwin; |
|---|
| 512 | owl_history cmdhist; /* command history */ |
|---|
| 513 | owl_history msghist; /* outgoing message history */ |
|---|
| 514 | owl_keyhandler kh; |
|---|
| 515 | owl_dict filters; |
|---|
| 516 | GList *filterlist; |
|---|
| 517 | GPtrArray *puntlist; |
|---|
| 518 | owl_vardict vars; |
|---|
| 519 | owl_cmddict cmds; |
|---|
| 520 | GList *context_stack; |
|---|
| 521 | owl_errqueue errqueue; |
|---|
| 522 | int lines, cols; |
|---|
| 523 | int curmsg, topmsg; |
|---|
| 524 | int markedmsgid; /* for finding the marked message when it has moved. */ |
|---|
| 525 | int curmsg_vert_offset; |
|---|
| 526 | owl_view current_view; |
|---|
| 527 | owl_messagelist *msglist; |
|---|
| 528 | WINDOW *input_pad; |
|---|
| 529 | owl_mainpanel mainpanel; |
|---|
| 530 | gulong typwin_erase_id; |
|---|
| 531 | int rightshift; |
|---|
| 532 | bool resizepending; |
|---|
| 533 | char *homedir; |
|---|
| 534 | char *confdir; |
|---|
| 535 | char *startupfile; |
|---|
| 536 | int direction; |
|---|
| 537 | int haveconfig; |
|---|
| 538 | int config_format; |
|---|
| 539 | owl_editwin *tw; |
|---|
| 540 | owl_viewwin *vw; |
|---|
| 541 | void *perl; |
|---|
| 542 | int debug; |
|---|
| 543 | time_t starttime; |
|---|
| 544 | time_t lastinputtime; |
|---|
| 545 | time_t last_wakeup_time; |
|---|
| 546 | char *startupargs; |
|---|
| 547 | int nextmsgid; |
|---|
| 548 | owl_colorpair_mgr cpmgr; |
|---|
| 549 | pid_t newmsgproc_pid; |
|---|
| 550 | owl_regex search_re; |
|---|
| 551 | GQueue *messagequeue; /* for queueing up messages */ |
|---|
| 552 | owl_dict styledict; /* global dictionary of available styles */ |
|---|
| 553 | char *response; /* response to the last question asked */ |
|---|
| 554 | int havezephyr; |
|---|
| 555 | owl_zbuddylist zbuddies; |
|---|
| 556 | GList *zaldlist; |
|---|
| 557 | int pseudologin_notify; |
|---|
| 558 | struct termios startup_tio; |
|---|
| 559 | int load_initial_subs; |
|---|
| 560 | FILE *debug_file; |
|---|
| 561 | char *kill_buffer; |
|---|
| 562 | int interrupt_count; |
|---|
| 563 | #if GLIB_CHECK_VERSION(2, 31, 0) |
|---|
| 564 | GMutex interrupt_lock; |
|---|
| 565 | #else |
|---|
| 566 | GMutex *interrupt_lock; |
|---|
| 567 | #endif |
|---|
| 568 | } owl_global; |
|---|
| 569 | |
|---|
| 570 | /* globals */ |
|---|
| 571 | extern owl_global g; |
|---|
| 572 | |
|---|
| 573 | #include <owl_prototypes.h> |
|---|
| 574 | |
|---|
| 575 | /* These were missing from the Zephyr includes before Zephyr 3. */ |
|---|
| 576 | #if defined HAVE_LIBZEPHYR && defined ZCONST |
|---|
| 577 | int ZGetSubscriptions(ZSubscription_t *, int *); |
|---|
| 578 | int ZGetLocations(ZLocations_t *,int *); |
|---|
| 579 | #endif |
|---|
| 580 | |
|---|
| 581 | /* We have to dynamically bind these ourselves */ |
|---|
| 582 | extern gboolean (*gvalue_from_sv) (GValue * value, SV * sv); |
|---|
| 583 | extern SV * (*sv_from_gvalue) (const GValue * value); |
|---|
| 584 | extern GClosure * (*perl_closure_new) (SV * callback, SV * data, gboolean swap); |
|---|
| 585 | |
|---|
| 586 | |
|---|
| 587 | #endif /* INC_BARNOWL_OWL_H */ |
|---|