source: owl.h @ d564c3d

release-1.10release-1.6release-1.7release-1.8release-1.9
Last change on this file since d564c3d was 03c5bdd, checked in by David Benjamin <davidben@mit.edu>, 15 years ago
Drop owl_popwin's first_refresh book-keeping b928b3a911f5fc1f205c12ca900557d21f47e7e2 removed all uses of the value.
  • Property mode set to 100644
File size: 17.6 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#include <stdbool.h>
13#ifndef OWL_PERL
14#include <curses.h>
15#include <panel.h>
16#endif
17#include <sys/param.h>
18#include <EXTERN.h>
19#include <netdb.h>
20#include <regex.h>
21#include <time.h>
22#include <signal.h>
23#include <termios.h>
24#include "libfaim/aim.h"
25#include <wchar.h>
26#include "config.h"
27#include "glib.h"
28#ifdef HAVE_LIBZEPHYR
29#include <zephyr/zephyr.h>
30#endif
31#ifdef HAVE_COM_ERR_H
32#include <com_err.h>
33#endif
34
35/* Perl and curses don't play nice. */
36#ifdef OWL_PERL
37typedef void WINDOW;
38typedef void PANEL;
39/* logout is defined in FreeBSD. */
40#define logout logout_
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 (*delete_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  PANEL *borderpanel;
396  PANEL *poppanel;
397  int lines;
398  int cols;
399  int active;
400} owl_popwin;
401
402typedef struct _owl_messagelist {
403  owl_list list;
404} owl_messagelist;
405
406typedef struct _owl_regex {
407  int negate;
408  char *string;
409  regex_t re;
410} owl_regex;
411
412typedef struct _owl_filterelement {
413  int (*match_message)(const struct _owl_filterelement *fe, const owl_message *m);
414  /* Append a string representation of the filterelement onto buf*/
415  void (*print_elt)(const struct _owl_filterelement *fe, GString *buf);
416  /* Operands for and,or,not*/
417  struct _owl_filterelement *left, *right;
418  /* For regex filters*/
419  owl_regex re;
420  /* Used by regexes, filter references, and perl */
421  char *field;
422} owl_filterelement;
423
424typedef struct _owl_filter {
425  char *name;
426  owl_filterelement * root;
427  int fgcolor;
428  int bgcolor;
429} owl_filter;
430
431typedef struct _owl_view {
432  char *name;
433  owl_filter *filter;
434  owl_messagelist ml;
435  const owl_style *style;
436  int cachedmsgid;
437} owl_view;
438
439typedef struct _owl_history {
440  owl_list hist;
441  int cur;
442  int touched;
443  int partial;
444  int repeats;
445} owl_history;
446
447typedef struct _owl_editwin owl_editwin;
448typedef struct _owl_editwin_excursion owl_editwin_excursion;
449
450typedef struct _owl_keybinding {
451  int  *keys;                   /* keypress stack */
452  int   len;                    /* length of stack */
453  int   type;                   /* command or function? */
454  char *desc;                   /* description (or "*user*") */
455  char *command;                /* command, if of type command */
456  void (*function_fn)(void);    /* function ptr, if of type function */
457} owl_keybinding;
458
459typedef struct _owl_keymap {
460  char     *name;               /* name of keymap */
461  char     *desc;               /* description */
462  owl_list  bindings;           /* key bindings */
463  const struct _owl_keymap *submap;     /* submap */
464  void (*default_fn)(owl_input j);      /* default action (takes a keypress) */
465  void (*prealways_fn)(owl_input  j);   /* always called before a keypress is received */
466  void (*postalways_fn)(owl_input  j);  /* always called after keypress is processed */
467} owl_keymap;
468
469typedef struct _owl_keyhandler {
470  owl_dict  keymaps;            /* dictionary of keymaps */
471  const owl_keymap *active;             /* currently active keymap */
472  int       in_esc;             /* escape pressed? */
473  int       kpstack[OWL_KEYMAP_MAXSTACK+1]; /* current stack of keypresses */
474  int       kpstackpos;         /* location in stack (-1 = none) */
475} owl_keyhandler;
476
477typedef struct _owl_buddy {
478  int proto;
479  char *name;
480  int isidle;
481  int idlesince;
482} owl_buddy;
483
484typedef struct _owl_buddylist {
485  owl_list buddies;
486} owl_buddylist;
487
488typedef struct _owl_zbuddylist {
489  owl_list zusers;
490} owl_zbuddylist;
491
492typedef struct _owl_timer {
493  time_t time;
494  int interval;
495  void (*callback)(struct _owl_timer *, void *);
496  void (*destroy)(struct _owl_timer *);
497  void *data;
498} owl_timer;
499
500typedef struct _owl_errqueue {
501  owl_list errlist;
502} owl_errqueue;
503
504typedef struct _owl_colorpair_mgr {
505  int next;
506  short **pairs;
507} owl_colorpair_mgr;
508
509typedef struct _owl_obarray {
510  owl_list strings;
511} owl_obarray;
512
513typedef struct _owl_io_dispatch {
514  int fd;                                     /* FD to watch for dispatch. */
515  int mode;
516  int needs_gc;
517  void (*callback)(const struct _owl_io_dispatch *, void *); /* C function to dispatch to. */
518  void (*destroy)(const struct _owl_io_dispatch *);  /* Destructor */
519  void *data;
520} owl_io_dispatch;
521
522typedef struct _owl_ps_action {
523  int needs_gc;
524  int (*callback)(struct _owl_ps_action *, void *);
525  void (*destroy)(struct _owl_ps_action *);
526  void *data;
527} owl_ps_action;
528
529typedef struct _owl_popexec {
530  int refcount;
531  owl_viewwin *vwin;
532  int winactive;
533  pid_t pid;                    /* or 0 if it has terminated */
534  const owl_io_dispatch *dispatch;
535} owl_popexec;
536
537typedef struct _owl_global {
538  owl_mainwin mw;
539  owl_popwin pw;
540  owl_history cmdhist;          /* command history */
541  owl_history msghist;          /* outgoing message history */
542  owl_keyhandler kh;
543  owl_dict filters;
544  GList *filterlist;
545  owl_list puntlist;
546  owl_vardict vars;
547  owl_cmddict cmds;
548  GList *context_stack;
549  owl_errqueue errqueue;
550  int lines, cols;
551  int curmsg, topmsg;
552  int markedmsgid;              /* for finding the marked message when it has moved. */
553  int curmsg_vert_offset;
554  owl_view current_view;
555  owl_messagelist msglist;
556  PANEL *recpan, *seppan, *msgpan, *typpan;
557  int needrefresh;
558  int rightshift;
559  int resizepending;
560  int recwinlines;
561  int typwinactive;
562  char *thishost;
563  char *homedir;
564  char *confdir;
565  char *startupfile;
566  int direction;
567  int zaway;
568  char *cur_zaway_msg;
569  int haveconfig;
570  int config_format;
571  void *buffercbdata;
572  owl_editwin *tw;
573  owl_viewwin vw;
574  void *perl;
575  int debug;
576  time_t starttime;
577  time_t lastinputtime;
578  char *startupargs;
579  int userclue;
580  int nextmsgid;
581  int hascolors;
582  int colorpairs;
583  owl_colorpair_mgr cpmgr;
584  pid_t newmsgproc_pid;
585  int malloced, freed;
586  owl_regex search_re;
587  aim_session_t aimsess;
588  aim_conn_t bosconn;
589  owl_timer aim_noop_timer;
590  owl_timer aim_ignorelogin_timer;
591  int aim_loggedin;         /* true if currently logged into AIM */
592  int aim_doprocessing;     /* true if we should process AIM events (like pending login) */
593  char *aim_screenname;     /* currently logged in AIM screen name */
594  char *aim_screenname_for_filters;     /* currently logged in AIM screen name */
595  owl_buddylist buddylist;  /* list of logged in AIM buddies */
596  owl_list messagequeue;    /* for queueing up aim and other messages */
597  owl_dict styledict;       /* global dictionary of available styles */
598  char *response;           /* response to the last question asked */
599  int havezephyr;
600  int haveaim;
601  int ignoreaimlogin;
602  int got_err_signal;       /* 1 if we got an unexpected signal */
603  siginfo_t err_signal_info;
604  owl_zbuddylist zbuddies;
605  owl_timer zephyr_buddycheck_timer;
606  struct termios startup_tio;
607  owl_obarray obarray;
608  owl_list io_dispatch_list;
609  owl_list psa_list;
610  GList *timerlist;
611  owl_timer *aim_nop_timer;
612  int load_initial_subs;
613  int interrupted;
614} owl_global;
615
616/* globals */
617extern owl_global g;
618
619#include "owl_prototypes.h"
620
621/* these are missing from the zephyr includes for some reason */
622#ifdef HAVE_LIBZEPHYR
623int ZGetSubscriptions(ZSubscription_t *, int *);
624int ZGetLocations(ZLocations_t *,int *);
625#endif
626
627#endif /* INC_OWL_H */
Note: See TracBrowser for help on using the repository browser.