source: owl.h @ 2afae56

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