source: owl.h @ 6b0b4f4

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