source: owl.h @ 6c81223

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