source: owl.h @ 8ae2de9

release-1.10release-1.6release-1.7release-1.8release-1.9
Last change on this file since 8ae2de9 was 8ae2de9, checked in by David Benjamin <davidben@mit.edu>, 15 years ago
Attach PANELs to all of our WINDOWs We replace wnoutrefresh with update_panels (except in set cursor; there we have to guarantee that the window is empty.). The viewwin does not get a PANEL because it's weird and currently leeches onto someone else's WINDOW. Resizing is also rather fiddly because panel wants to know about window resizes. Not completely sure I got it right yet. The only library I know of that does something like with with ncurses (libgnt) and they endwin/refresh to resize the screen. Signed-off-by: David Benjamin <davidben@mit.edu>
  • Property mode set to 100644
File size: 17.7 KB
Line 
1/*  Copyright (c) 2006-2009 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_OWL_H
10#define INC_OWL_H
11
12#ifndef OWL_PERL
13#include <curses.h>
14#include <panel.h>
15#endif
16#include <sys/param.h>
17#include <EXTERN.h>
18#include <netdb.h>
19#include <regex.h>
20#include <time.h>
21#include <signal.h>
22#include <termios.h>
23#include "libfaim/aim.h"
24#include <wchar.h>
25#include "config.h"
26#include "glib.h"
27#ifdef HAVE_LIBZEPHYR
28#include <zephyr/zephyr.h>
29#endif
30#ifdef HAVE_COM_ERR_H
31#include <com_err.h>
32#endif
33
34/* Perl and curses don't play nice. */
35#ifdef OWL_PERL
36typedef void WINDOW;
37typedef void PANEL;
38/* logout is defined in FreeBSD. */
39#define logout logout_
40/* aim.h defines bool */
41#define HAS_BOOL
42#include <perl.h>
43#include "owl_perl.h"
44#undef logout
45#include "XSUB.h"
46#else
47typedef void SV;
48typedef void AV;
49typedef void HV;
50#endif
51
52#ifdef  GIT_VERSION
53#define stringify(x)       __stringify(x)
54#define __stringify(x)     #x
55#define OWL_VERSION_STRING stringify(GIT_VERSION)
56#else
57#define OWL_VERSION_STRING PACKAGE_VERSION
58#endif
59
60/* Feature that is being tested to redirect stderr through a pipe.
61 * There may still be some portability problems with this. */
62#define OWL_STDERR_REDIR 1
63
64#define OWL_DEBUG 0
65#define OWL_DEBUG_FILE "/var/tmp/owldebug"
66
67#define OWL_CONFIG_DIR "/.owl"             /* this is relative to the user's home directory */
68#define OWL_STARTUP_FILE "/.owl/startup"   /* this is relative to the user's home directory */
69
70#define OWL_FMTEXT_ATTR_NONE      0
71#define OWL_FMTEXT_ATTR_BOLD      1
72#define OWL_FMTEXT_ATTR_REVERSE   2
73#define OWL_FMTEXT_ATTR_UNDERLINE 4
74
75#define OWL_FMTEXT_UC_BASE 0x100000 /* Unicode Plane 16 - Supplementary Private Use Area-B*/
76#define OWL_FMTEXT_UC_ATTR ( OWL_FMTEXT_UC_BASE | 0x800 )
77#define OWL_FMTEXT_UC_ATTR_MASK 0x7
78#define OWL_FMTEXT_UC_COLOR_BASE ( OWL_FMTEXT_UC_BASE | 0x400 )
79#define OWL_FMTEXT_UC_FGCOLOR OWL_FMTEXT_UC_COLOR_BASE
80#define OWL_FMTEXT_UC_BGCOLOR ( OWL_FMTEXT_UC_COLOR_BASE | 0x200 )
81#define OWL_FMTEXT_UC_DEFAULT_COLOR 0x100
82#define OWL_FMTEXT_UC_FGDEFAULT ( OWL_FMTEXT_UC_FGCOLOR | OWL_FMTEXT_UC_DEFAULT_COLOR )
83#define OWL_FMTEXT_UC_BGDEFAULT ( OWL_FMTEXT_UC_BGCOLOR | OWL_FMTEXT_UC_DEFAULT_COLOR )
84#define OWL_FMTEXT_UC_COLOR_MASK 0xFF
85#define OWL_FMTEXT_UC_ALLCOLOR_MASK ( OWL_FMTEXT_UC_COLOR_MASK | OWL_FMTEXT_UC_DEFAULT_COLOR | 0x200)
86#define OWL_FMTEXT_UC_STARTBYTE_UTF8 '\xf4'
87
88#define OWL_FMTEXT_UTF8_ATTR_NONE "\xf4\x80\xa0\x80"
89#define OWL_FMTEXT_UTF8_FGDEFAULT "\xf4\x80\x94\x80"
90#define OWL_FMTEXT_UTF8_BGDEFAULT "\xf4\x80\x9C\x80"
91
92#define OWL_COLOR_BLACK     0
93#define OWL_COLOR_RED       1
94#define OWL_COLOR_GREEN     2
95#define OWL_COLOR_YELLOW    3
96#define OWL_COLOR_BLUE      4
97#define OWL_COLOR_MAGENTA   5
98#define OWL_COLOR_CYAN      6
99#define OWL_COLOR_WHITE     7
100#define OWL_COLOR_DEFAULT   -1
101#define OWL_COLOR_INVALID   -2
102
103#define OWL_EDITWIN_STYLE_MULTILINE 0
104#define OWL_EDITWIN_STYLE_ONELINE   1
105
106#define OWL_PROTOCOL_ZEPHYR         0
107#define OWL_PROTOCOL_AIM            1
108#define OWL_PROTOCOL_JABBER         2
109#define OWL_PROTOCOL_ICQ            3
110#define OWL_PROTOCOL_YAHOO          4
111#define OWL_PROTOCOL_MSN            5
112
113#define OWL_MESSAGE_DIRECTION_NONE  0
114#define OWL_MESSAGE_DIRECTION_IN    1
115#define OWL_MESSAGE_DIRECTION_OUT   2
116
117#define OWL_IO_READ   1
118#define OWL_IO_WRITE  2
119#define OWL_IO_EXCEPT 4
120
121#define OWL_DIRECTION_NONE      0
122#define OWL_DIRECTION_DOWNWARDS 1
123#define OWL_DIRECTION_UPWARDS   2
124
125#define OWL_LOGGING_DIRECTION_BOTH 0
126#define OWL_LOGGING_DIRECTION_IN   1
127#define OWL_LOGGING_DIRECTION_OUT  2
128
129#define OWL_SCROLLMODE_NORMAL      0
130#define OWL_SCROLLMODE_TOP         1
131#define OWL_SCROLLMODE_NEARTOP     2
132#define OWL_SCROLLMODE_CENTER      3
133#define OWL_SCROLLMODE_PAGED       4
134#define OWL_SCROLLMODE_PAGEDCENTER 5
135
136#define OWL_TAB               3  /* This *HAS* to be the size of TABSTR below */
137#define OWL_TABSTR        "   "
138#define OWL_MSGTAB            7
139#define OWL_TYPWIN_SIZE       8
140#define OWL_HISTORYSIZE       50
141
142/* Indicate current state, as well as what is allowed */
143#define OWL_CTX_ANY          0xffff
144/* Only one of these may be active at a time... */
145#define OWL_CTX_MODE_BITS    0x000f
146#define OWL_CTX_STARTUP      0x0001
147#define OWL_CTX_READCONFIG   0x0002
148#define OWL_CTX_INTERACTIVE  0x0004
149/* Only one of these may be active at a time... */
150#define OWL_CTX_ACTIVE_BITS  0xfff0
151#define OWL_CTX_POPWIN       0x00f0
152#define OWL_CTX_POPLESS      0x0010
153#define OWL_CTX_RECWIN       0x0f00
154#define OWL_CTX_RECV         0x0100
155#define OWL_CTX_TYPWIN       0xf000
156#define OWL_CTX_EDIT         0x7000
157#define OWL_CTX_EDITLINE     0x1000
158#define OWL_CTX_EDITMULTI    0x2000
159#define OWL_CTX_EDITRESPONSE 0x4000
160
161#define OWL_USERCLUE_NONE       0
162#define OWL_USERCLUE_CLASSES    1
163#define OWL_USERCLUE_FOOBAR     2
164#define OWL_USERCLUE_BAZ        4
165
166#define OWL_WEBBROWSER_NONE     0
167#define OWL_WEBBROWSER_NETSCAPE 1
168#define OWL_WEBBROWSER_GALEON   2
169#define OWL_WEBBROWSER_OPERA    3
170
171#define OWL_VARIABLE_OTHER      0
172#define OWL_VARIABLE_INT        1
173#define OWL_VARIABLE_BOOL       2
174#define OWL_VARIABLE_STRING     3
175
176#define OWL_FILTER_MAX_DEPTH    300
177
178#define OWL_KEYMAP_MAXSTACK     20
179
180#define OWL_KEYBINDING_COMMAND  1   /* command string */
181#define OWL_KEYBINDING_FUNCTION 2   /* function taking no args */
182
183#define OWL_DEFAULT_ZAWAYMSG    "I'm sorry, but I am currently away from the terminal and am\nnot able to receive your message.\n"
184#define OWL_DEFAULT_AAWAYMSG    "I'm sorry, but I am currently away from the terminal and am\nnot able to receive your message.\n"
185
186#define OWL_CMD_ALIAS_SUMMARY_PREFIX "command alias to: "
187
188#define OWL_WEBZEPHYR_PRINCIPAL "daemon.webzephyr"
189#define OWL_WEBZEPHYR_CLASS     "webzephyr"
190#define OWL_WEBZEPHYR_OPCODE    "webzephyr"
191
192#define OWL_REGEX_QUOTECHARS    "+*.?[]^\\${}()"
193#define OWL_REGEX_QUOTEWITH     "\\"
194
195#if defined(HAVE_DES_STRING_TO_KEY) && defined(HAVE_DES_KEY_SCHED) && defined(HAVE_DES_ECB_ENCRYPT)
196#define OWL_ENABLE_ZCRYPT 1
197#endif
198
199#define OWL_META(key) ((key)|010000)
200/* OWL_CTRL is definied in kepress.c */
201
202#define LINE 2048
203
204#ifdef HAVE_LIBZEPHYR
205/* libzephyr doesn't use const, so we appease the type system with this kludge.
206 * This just casts const char * to char * in a way that doesn't yield a warning
207 * from gcc -Wcast-qual. */
208static inline char *zstr(const char *str)
209{
210  union { char *rw; const char *ro; } u;
211  u.ro = str;
212  return u.rw;
213}
214#endif
215
216/* Convert char *const * into const char *const *.  This conversion is safe,
217 * and implicit in C++ (conv.qual 4) but for some reason not in C. */
218static inline const char *const *strs(char *const *pstr)
219{
220  return (const char *const *)pstr;
221}
222
223typedef struct _owl_variable {
224  char *name;
225  int   type;  /* OWL_VARIABLE_* */
226  void *pval_default;  /* for types other and string */
227  int   ival_default;  /* for types int and bool     */
228  char *validsettings;          /* documentation of valid settings */
229  char *summary;                /* summary of usage */
230  char *description;            /* detailed description */
231  void *val;                    /* current value */
232  int  (*validate_fn)(const struct _owl_variable *v, const void *newval);
233                                /* returns 1 if newval is valid */
234  int  (*set_fn)(struct _owl_variable *v, const void *newval); 
235                                /* sets the variable to a value
236                                 * of the appropriate type.
237                                 * unless documented, this
238                                 * should make a copy.
239                                 * returns 0 on success. */
240  int  (*set_fromstring_fn)(struct _owl_variable *v, const char *newval);
241                                /* sets the variable to a value
242                                 * of the appropriate type.
243                                 * unless documented, this
244                                 * should make a copy.
245                                 * returns 0 on success. */
246  const void *(*get_fn)(const struct _owl_variable *v);
247                                /* returns a reference to the current value.
248                                 * WARNING:  this approach is hard to make
249                                 * thread-safe... */
250  int  (*get_tostring_fn)(const struct _owl_variable *v, 
251                          char *buf, int bufsize, const void *val); 
252                                /* converts val to a string
253                                 * and puts into buf */
254  void  (*free_fn)(struct _owl_variable *v);
255                                /* frees val as needed */
256} owl_variable;
257
258typedef struct _owl_input {
259  int ch;
260  gunichar uch;
261} owl_input;
262
263typedef struct _owl_fmtext {
264  int textlen;
265  int bufflen;
266  char *textbuff;
267  char default_attrs;
268  short default_fgcolor;
269  short default_bgcolor;
270} owl_fmtext;
271
272typedef struct _owl_list {
273  int size;
274  int avail;
275  void **list;
276} owl_list;
277
278typedef struct _owl_dict_el {
279  char *k;                      /* key   */
280  void *v;                      /* value */
281} owl_dict_el;
282
283typedef struct _owl_dict {
284  int size;
285  int avail;
286  owl_dict_el *els;             /* invariant: sorted by k */
287} owl_dict;
288typedef owl_dict owl_vardict;   /* dict of variables */
289typedef owl_dict owl_cmddict;   /* dict of commands */
290
291typedef struct _owl_context {
292  int   mode;
293  void *data;           /* determined by mode */
294  char *keymap;
295} owl_context;
296
297typedef struct _owl_cmd {       /* command */
298  char *name;
299
300  char *summary;                /* one line summary of command */
301  char *usage;                  /* usage synopsis */
302  char *description;            /* long description of command */
303
304  int validctx;                 /* bitmask of valid contexts */
305
306  /* we should probably have a type here that says which of
307   * the following is valid, and maybe make the below into a union... */
308
309  /* Only one of these may be non-NULL ... */
310
311  char *cmd_aliased_to;         /* what this command is aliased to... */
312 
313  /* These don't take any context */
314  char *(*cmd_args_fn)(int argc, const char *const *argv, const char *buff); 
315                                /* takes argv and the full command as buff.
316                                 * caller must free return value if !NULL */
317  void (*cmd_v_fn)(void);       /* takes no args */
318  void (*cmd_i_fn)(int i);      /* takes an int as an arg */
319
320  /* The following also take the active context if it's valid */
321  char *(*cmd_ctxargs_fn)(void *ctx, int argc, const char *const *argv, const char *buff); 
322                                /* takes argv and the full command as buff.
323                                 * caller must free return value if !NULL */
324  void (*cmd_ctxv_fn)(void *ctx);               /* takes no args */
325  void (*cmd_ctxi_fn)(void *ctx, int i);        /* takes an int as an arg */
326  SV *cmd_perl;                                /* Perl closure that takes a list of args */
327} owl_cmd;
328
329
330typedef struct _owl_zwrite {
331  char *zwriteline;
332  char *class;
333  char *inst;
334  char *realm;
335  char *opcode;
336  char *zsig;
337  char *message;
338  owl_list recips;
339  int cc;
340  int noping;
341} owl_zwrite;
342
343typedef struct _owl_pair {
344  const char *key;
345  char *value;
346} owl_pair;
347
348struct _owl_fmtext_cache;
349
350typedef struct _owl_message {
351  int id;
352  int direction;
353#ifdef HAVE_LIBZEPHYR
354  ZNotice_t notice;
355#endif
356  struct _owl_fmtext_cache * fmtext;
357  int delete;
358  const char *hostname;
359  owl_list attributes;            /* this is a list of pairs */
360  char *timestr;
361  time_t time;
362} owl_message;
363
364#define OWL_FMTEXT_CACHE_SIZE 1000
365/* We cache the saved fmtexts for the last bunch of messages we
366   rendered */
367typedef struct _owl_fmtext_cache {
368    owl_message * message;
369    owl_fmtext fmtext;
370} owl_fmtext_cache;
371
372typedef struct _owl_style {
373  char *name;
374  SV *perlobj;
375} owl_style;
376
377typedef struct _owl_mainwin {
378  int curtruncated;
379  int lasttruncated;
380  int lastdisplayed;
381} owl_mainwin;
382
383typedef struct _owl_viewwin {
384  owl_fmtext fmtext;
385  int textlines;
386  int topline;
387  int rightshift;
388  int winlines, wincols;
389  WINDOW *curswin;
390  void (*onclose_hook) (struct _owl_viewwin *vwin, void *data);
391  void *onclose_hook_data;
392} owl_viewwin;
393 
394typedef struct _owl_popwin {
395  WINDOW *borderwin;
396  PANEL *borderpanel;
397  WINDOW *popwin;
398  PANEL *poppanel;
399  int lines;
400  int cols;
401  int active;
402  int needsfirstrefresh;
403} owl_popwin;
404
405typedef struct _owl_messagelist {
406  owl_list list;
407} owl_messagelist;
408
409typedef struct _owl_regex {
410  int negate;
411  char *string;
412  regex_t re;
413} owl_regex;
414
415typedef struct _owl_filterelement {
416  int (*match_message)(const struct _owl_filterelement *fe, const owl_message *m);
417  /* Append a string representation of the filterelement onto buf*/
418  void (*print_elt)(const struct _owl_filterelement *fe, GString *buf);
419  /* Operands for and,or,not*/
420  struct _owl_filterelement *left, *right;
421  /* For regex filters*/
422  owl_regex re;
423  /* Used by regexes, filter references, and perl */
424  char *field;
425} owl_filterelement;
426
427typedef struct _owl_filter {
428  char *name;
429  owl_filterelement * root;
430  int fgcolor;
431  int bgcolor;
432} owl_filter;
433
434typedef struct _owl_view {
435  char *name;
436  owl_filter *filter;
437  owl_messagelist ml;
438  const owl_style *style;
439  int cachedmsgid;
440} owl_view;
441
442typedef struct _owl_history {
443  owl_list hist;
444  int cur;
445  int touched;
446  int partial;
447  int repeats;
448} owl_history;
449
450typedef struct _owl_editwin owl_editwin;
451typedef struct _owl_editwin_excursion owl_editwin_excursion;
452
453typedef struct _owl_keybinding {
454  int  *keys;                   /* keypress stack */
455  int   len;                    /* length of stack */
456  int   type;                   /* command or function? */
457  char *desc;                   /* description (or "*user*") */
458  char *command;                /* command, if of type command */
459  void (*function_fn)(void);    /* function ptr, if of type function */
460} owl_keybinding;
461
462typedef struct _owl_keymap {
463  char     *name;               /* name of keymap */
464  char     *desc;               /* description */
465  owl_list  bindings;           /* key bindings */
466  const struct _owl_keymap *submap;     /* submap */
467  void (*default_fn)(owl_input j);      /* default action (takes a keypress) */
468  void (*prealways_fn)(owl_input  j);   /* always called before a keypress is received */
469  void (*postalways_fn)(owl_input  j);  /* always called after keypress is processed */
470} owl_keymap;
471
472typedef struct _owl_keyhandler {
473  owl_dict  keymaps;            /* dictionary of keymaps */
474  const owl_keymap *active;             /* currently active keymap */
475  int       in_esc;             /* escape pressed? */
476  int       kpstack[OWL_KEYMAP_MAXSTACK+1]; /* current stack of keypresses */
477  int       kpstackpos;         /* location in stack (-1 = none) */
478} owl_keyhandler;
479
480typedef struct _owl_buddy {
481  int proto;
482  char *name;
483  int isidle;
484  int idlesince;
485} owl_buddy;
486
487typedef struct _owl_buddylist {
488  owl_list buddies;
489} owl_buddylist;
490
491typedef struct _owl_zbuddylist {
492  owl_list zusers;
493} owl_zbuddylist;
494
495typedef struct _owl_timer {
496  time_t time;
497  int interval;
498  void (*callback)(struct _owl_timer *, void *);
499  void (*destroy)(struct _owl_timer *);
500  void *data;
501} owl_timer;
502
503typedef struct _owl_errqueue {
504  owl_list errlist;
505} owl_errqueue;
506
507typedef struct _owl_colorpair_mgr {
508  int next;
509  short **pairs;
510} owl_colorpair_mgr;
511
512typedef struct _owl_obarray {
513  owl_list strings;
514} owl_obarray;
515
516typedef struct _owl_io_dispatch {
517  int fd;                                     /* FD to watch for dispatch. */
518  int mode;
519  int needs_gc;
520  void (*callback)(const struct _owl_io_dispatch *, void *); /* C function to dispatch to. */
521  void (*destroy)(const struct _owl_io_dispatch *);  /* Destructor */
522  void *data;
523} owl_io_dispatch;
524
525typedef struct _owl_ps_action {
526  int needs_gc;
527  int (*callback)(struct _owl_ps_action *, void *);
528  void (*destroy)(struct _owl_ps_action *);
529  void *data;
530} owl_ps_action;
531
532typedef struct _owl_popexec {
533  int refcount;
534  owl_viewwin *vwin;
535  int winactive;
536  pid_t pid;                    /* or 0 if it has terminated */
537  const owl_io_dispatch *dispatch;
538} owl_popexec;
539
540typedef struct _owl_global {
541  owl_mainwin mw;
542  owl_popwin pw;
543  owl_history cmdhist;          /* command history */
544  owl_history msghist;          /* outgoing message history */
545  owl_keyhandler kh;
546  owl_dict filters;
547  GList *filterlist;
548  owl_list puntlist;
549  owl_vardict vars;
550  owl_cmddict cmds;
551  GList *context_stack;
552  owl_errqueue errqueue;
553  int lines, cols;
554  int curmsg, topmsg;
555  int markedmsgid;              /* for finding the marked message when it has moved. */
556  int curmsg_vert_offset;
557  owl_view current_view;
558  owl_messagelist msglist;
559  WINDOW *recwin, *sepwin, *msgwin, *typwin;
560  PANEL *recpan, *seppan, *msgpan, *typpan;
561  int needrefresh;
562  int rightshift;
563  int resizepending;
564  int recwinlines;
565  int typwinactive;
566  char *thishost;
567  char *homedir;
568  char *confdir;
569  char *startupfile;
570  int direction;
571  int zaway;
572  char *cur_zaway_msg;
573  int haveconfig;
574  int config_format;
575  void *buffercbdata;
576  owl_editwin *tw;
577  owl_viewwin vw;
578  void *perl;
579  int debug;
580  time_t starttime;
581  time_t lastinputtime;
582  char *startupargs;
583  int userclue;
584  int nextmsgid;
585  int hascolors;
586  int colorpairs;
587  owl_colorpair_mgr cpmgr;
588  pid_t newmsgproc_pid;
589  int malloced, freed;
590  owl_regex search_re;
591  aim_session_t aimsess;
592  aim_conn_t bosconn;
593  owl_timer aim_noop_timer;
594  owl_timer aim_ignorelogin_timer;
595  int aim_loggedin;         /* true if currently logged into AIM */
596  int aim_doprocessing;     /* true if we should process AIM events (like pending login) */
597  char *aim_screenname;     /* currently logged in AIM screen name */
598  char *aim_screenname_for_filters;     /* currently logged in AIM screen name */
599  owl_buddylist buddylist;  /* list of logged in AIM buddies */
600  owl_list messagequeue;    /* for queueing up aim and other messages */
601  owl_dict styledict;       /* global dictionary of available styles */
602  char *response;           /* response to the last question asked */
603  int havezephyr;
604  int haveaim;
605  int ignoreaimlogin;
606  int got_err_signal;       /* 1 if we got an unexpected signal */
607  siginfo_t err_signal_info;
608  owl_zbuddylist zbuddies;
609  owl_timer zephyr_buddycheck_timer;
610  struct termios startup_tio;
611  owl_obarray obarray;
612  owl_list io_dispatch_list;
613  owl_list psa_list;
614  GList *timerlist;
615  owl_timer *aim_nop_timer;
616  int load_initial_subs;
617  int interrupted;
618} owl_global;
619
620/* globals */
621extern owl_global g;
622
623#include "owl_prototypes.h"
624
625/* these are missing from the zephyr includes for some reason */
626#ifdef HAVE_LIBZEPHYR
627int ZGetSubscriptions(ZSubscription_t *, int *);
628int ZGetLocations(ZLocations_t *,int *);
629#endif
630
631#endif /* INC_OWL_H */
Note: See TracBrowser for help on using the repository browser.