source: owl.h @ 5cbc929

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