source: owl.h @ 8d0796c0

owl
Last change on this file since 8d0796c0 was d1948ce, checked in by James M. Kretchmar <kretch@mit.edu>, 15 years ago
2.1.12 included a patch that breaks opaque resizing for some versions of ncurses on solaris. Reverting that part of the change to fix.
  • Property mode set to 100644
File size: 15.5 KB
RevLine 
[dab82f29]1/* Copyright (c) 2002,2003,2004,2009 James M. Kretchmar
[5ca5f8e]2 *
[dab82f29]3 * This file is part of Owl.
4 *
5 * Owl is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * Owl is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with Owl.  If not, see <http://www.gnu.org/licenses/>.
17 *
18 * ---------------------------------------------------------------
[5ca5f8e]19 *
[dab82f29]20 * As of Owl version 2.1.12 there are patches contributed by
[fa00c5c]21 * developers of the branched BarnOwl project, Copyright (c)
22 * 2006-2009 The BarnOwl Developers. All rights reserved.
[5ca5f8e]23 */
24
[7d4fbcd]25#ifndef INC_OWL_H
26#define INC_OWL_H
27
28#include <curses.h>
29#include <sys/param.h>
30#include <EXTERN.h>
31#include <netdb.h>
32#include <regex.h>
[d09e5a1]33#include <time.h>
[c9e72d1]34#include <signal.h>
[8232149]35#include <termios.h>
[3674002]36#include <glib.h>
[d09e5a1]37#include <libfaim/aim.h>
[7d4fbcd]38#include "config.h"
[be0a79f]39#ifdef HAVE_LIBZEPHYR
[373b7e7]40#include <zephyr/zephyr.h>
[be0a79f]41#endif
[e6449bc]42#ifdef HAVE_COM_ERR_H
43#include <com_err.h>
44#endif
45
[1aee7d9]46static const char owl_h_fileIdent[] = "$Id$";
47
[d1948ce]48#define OWL_VERSION         2.2.2
49#define OWL_VERSION_STRING "2.2.2"
[2a2bb60]50
51/* Feature that is being tested to redirect stderr through a pipe.
52 * There may still be some portability problems with this. */
53#define OWL_STDERR_REDIR 1
[7d4fbcd]54
55#define OWL_DEBUG 0
56#define OWL_DEBUG_FILE "/var/tmp/owldebug"
57
[bd3f232]58#define OWL_CONFIG_DIR "/.owl"             /* this is relative to the user's home directory */
[38cf544c]59#define OWL_STARTUP_FILE "/.owl/startup"   /* this is relative to the user's home directory */
60
[7d4fbcd]61#define OWL_FMTEXT_ATTR_NONE      0
62#define OWL_FMTEXT_ATTR_BOLD      1
63#define OWL_FMTEXT_ATTR_REVERSE   2
64#define OWL_FMTEXT_ATTR_UNDERLINE 4
65
66#define OWL_COLOR_BLACK     0
67#define OWL_COLOR_RED       1
68#define OWL_COLOR_GREEN     2
69#define OWL_COLOR_YELLOW    3
70#define OWL_COLOR_BLUE      4
71#define OWL_COLOR_MAGENTA   5
72#define OWL_COLOR_CYAN      6
73#define OWL_COLOR_WHITE     7
74#define OWL_COLOR_DEFAULT   8
75
76#define OWL_EDITWIN_STYLE_MULTILINE 0
77#define OWL_EDITWIN_STYLE_ONELINE   1
78
[f4d0975]79#define OWL_PROTOCOL_ZEPHYR         0
80#define OWL_PROTOCOL_AIM            1
81#define OWL_PROTOCOL_JABBER         2
82#define OWL_PROTOCOL_ICQ            3
83#define OWL_PROTOCOL_YAHOO          4
84#define OWL_PROTOCOL_MSN            5
85
[4b464a4]86#define OWL_MESSAGE_TYPE_ADMIN      0
87#define OWL_MESSAGE_TYPE_GENERIC    1
88#define OWL_MESSAGE_TYPE_ZEPHYR     2
[d0d65df]89#define OWL_MESSAGE_TYPE_AIM        3
90#define OWL_MESSAGE_TYPE_JABBER     4
91#define OWL_MESSAGE_TYPE_ICQ        5
92#define OWL_MESSAGE_TYPE_YAHOO      6
93#define OWL_MESSAGE_TYPE_MSN        7
[37eab7f]94#define OWL_MESSAGE_TYPE_LOOPBACK   8
[7d4fbcd]95
[4b464a4]96#define OWL_MESSAGE_DIRECTION_NONE  0
97#define OWL_MESSAGE_DIRECTION_IN    1
98#define OWL_MESSAGE_DIRECTION_OUT   2
[7d4fbcd]99
[afbf668]100#define OWL_MUX_READ   1
101#define OWL_MUX_WRITE  2
102#define OWL_MUX_EXCEPT 4
103
[7d4fbcd]104#define OWL_DIRECTION_NONE      0
105#define OWL_DIRECTION_DOWNWARDS 1
106#define OWL_DIRECTION_UPWARDS   2
107
[12c35df]108#define OWL_LOGGING_DIRECTION_BOTH 0
109#define OWL_LOGGING_DIRECTION_IN   1
110#define OWL_LOGGING_DIRECTION_OUT  2
111
[88736cb]112#define OWL_SCROLLMODE_NORMAL      0
113#define OWL_SCROLLMODE_TOP         1
114#define OWL_SCROLLMODE_NEARTOP     2
115#define OWL_SCROLLMODE_CENTER      3
116#define OWL_SCROLLMODE_PAGED       4
[aa2f33b3]117#define OWL_SCROLLMODE_PAGEDCENTER 5
118
[bd3f232]119#define OWL_STYLE_TYPE_INTERNAL  0
120#define OWL_STYLE_TYPE_PERL      1
121
[7d4fbcd]122#define OWL_TAB               3  /* This *HAS* to be the size of TABSTR below */
123#define OWL_TABSTR        "   "
124#define OWL_MSGTAB            7
125#define OWL_TYPWIN_SIZE       8
126#define OWL_HISTORYSIZE       50
127
128/* Indicate current state, as well as what is allowed */
129#define OWL_CTX_ANY          0xffff
130/* Only one of these may be active at a time... */
131#define OWL_CTX_MODE_BITS    0x000f
132#define OWL_CTX_STARTUP      0x0001
133#define OWL_CTX_READCONFIG   0x0002
134#define OWL_CTX_INTERACTIVE  0x0004
135/* Only one of these may be active at a time... */
136#define OWL_CTX_ACTIVE_BITS  0xfff0
137#define OWL_CTX_POPWIN       0x00f0
138#define OWL_CTX_POPLESS      0x0010
139#define OWL_CTX_RECWIN       0x0f00
140#define OWL_CTX_RECV         0x0100
141#define OWL_CTX_TYPWIN       0xf000
[cf83b7a]142#define OWL_CTX_EDIT         0x7000
[7d4fbcd]143#define OWL_CTX_EDITLINE     0x1000
144#define OWL_CTX_EDITMULTI    0x2000
[cf83b7a]145#define OWL_CTX_EDITRESPONSE 0x4000
[7d4fbcd]146
147#define OWL_USERCLUE_NONE       0
148#define OWL_USERCLUE_CLASSES    1
149#define OWL_USERCLUE_FOOBAR     2
150#define OWL_USERCLUE_BAZ        4
151
152#define OWL_WEBBROWSER_NONE     0
153#define OWL_WEBBROWSER_NETSCAPE 1
154#define OWL_WEBBROWSER_GALEON   2
[ae9e6be]155#define OWL_WEBBROWSER_OPERA    3
[7d4fbcd]156
157#define OWL_VARIABLE_OTHER      0
158#define OWL_VARIABLE_INT        1
159#define OWL_VARIABLE_BOOL       2
160#define OWL_VARIABLE_STRING     3
161
162#define OWL_FILTER_MAX_DEPTH    300
163
[4b464a4]164#define OWL_KEYMAP_MAXSTACK     20
[7d4fbcd]165
[4b464a4]166#define OWL_KEYBINDING_COMMAND  1   /* command string */
167#define OWL_KEYBINDING_FUNCTION 2   /* function taking no args */
[7d4fbcd]168
[4b464a4]169#define OWL_DEFAULT_ZAWAYMSG    "I'm sorry, but I am currently away from the terminal and am\nnot able to receive your message.\n"
[4b660cc]170#define OWL_DEFAULT_AAWAYMSG    "I'm sorry, but I am currently away from the terminal and am\nnot able to receive your message.\n"
[7d4fbcd]171
[4b464a4]172#define OWL_INCLUDE_REG_TESTS   1  /* whether to build in regression tests */
[7d4fbcd]173
[1c7a4e0]174#define OWL_CMD_ALIAS_SUMMARY_PREFIX "command alias to: "
[7d4fbcd]175
[e7cc1c3]176#define OWL_WEBZEPHYR_PRINCIPAL "daemon.webzephyr"
[1d3e925]177#define OWL_WEBZEPHYR_CLASS     "webzephyr"
178#define OWL_WEBZEPHYR_OPCODE    "webzephyr"
[e7cc1c3]179
[dab82f29]180#define OWL_REGEX_QUOTECHARS    "+*.?[]^\\${}()"
[bc08664]181#define OWL_REGEX_QUOTEWITH     "\\"
182
[0435c7d]183#if defined(HAVE_DES_STRING_TO_KEY) && defined(HAVE_DES_KEY_SCHED) && defined(HAVE_DES_ECB_ENCRYPT)
[c86a35c]184#define OWL_ENABLE_ZCRYPT 1
[c269e22]185#endif
186
[f87c490]187#define OWL_META(key) ((key)|0200)
188/* OWL_CTRL is definied in kepress.c */
[7d4fbcd]189
190#define LINE 2048
191
192typedef struct _owl_variable {
193  char *name;
194  int   type;  /* OWL_VARIABLE_* */
195  void *pval_default;  /* for types other and string */
196  int   ival_default;  /* for types int and bool     */
197  char *validsettings;          /* documentation of valid settings */
[aa2f33b3]198  char *summary;                /* summary of usage */
199  char *description;            /* detailed description */
[7d4fbcd]200  void *val;                    /* current value */
201  int  (*validate_fn)(struct _owl_variable *v, void *newval);
202                                /* returns 1 if newval is valid */
203  int  (*set_fn)(struct _owl_variable *v, void *newval); 
204                                /* sets the variable to a value
205                                 * of the appropriate type.
206                                 * unless documented, this
207                                 * should make a copy.
208                                 * returns 0 on success. */
209  int  (*set_fromstring_fn)(struct _owl_variable *v, char *newval);
210                                /* sets the variable to a value
211                                 * of the appropriate type.
212                                 * unless documented, this
213                                 * should make a copy.
214                                 * returns 0 on success. */
215  void *(*get_fn)(struct _owl_variable *v);
216                                /* returns a reference to the current value.
217                                 * WARNING:  this approach is hard to make
218                                 * thread-safe... */
219  int  (*get_tostring_fn)(struct _owl_variable *v, 
220                          char *buf, int bufsize, void *val); 
221                                /* converts val to a string
222                                 * and puts into buf */
223  void  (*free_fn)(struct _owl_variable *v);
224                                /* frees val as needed */
225} owl_variable;
226
227typedef struct _owl_fmtext {
228  int textlen;
229  char *textbuff;
230  char *fmbuff;
231  char *colorbuff;
232} owl_fmtext;
233
234typedef struct _owl_list {
235  int size;
236  int avail;
237  void **list;
238} owl_list;
239
240typedef struct _owl_dict_el {
241  char *k;                      /* key   */
242  void *v;                      /* value */
243} owl_dict_el;
244
245typedef struct _owl_dict {
246  int size;
247  int avail;
248  owl_dict_el *els;             /* invariant: sorted by k */
249} owl_dict;
250typedef owl_dict owl_vardict;   /* dict of variables */
251typedef owl_dict owl_cmddict;   /* dict of commands */
252
253typedef struct _owl_context {
254  int   mode;
255  void *data;           /* determined by mode */
256} owl_context;
257
258typedef struct _owl_cmd {       /* command */
259  char *name;
260
261  char *summary;                /* one line summary of command */
262  char *usage;                  /* usage synopsis */
263  char *description;            /* long description of command */
264
265  int validctx;                 /* bitmask of valid contexts */
266
267  /* we should probably have a type here that says which of
268   * the following is valid, and maybe make the below into a union... */
269
270  /* Only one of these may be non-NULL ... */
271
272  char *cmd_aliased_to;         /* what this command is aliased to... */
273 
274  /* These don't take any context */
275  char *(*cmd_args_fn)(int argc, char **argv, char *buff); 
276                                /* takes argv and the full command as buff.
277                                 * caller must free return value if !NULL */
278  void (*cmd_v_fn)(void);       /* takes no args */
279  void (*cmd_i_fn)(int i);      /* takes an int as an arg */
280
281  /* The following also take the active context if it's valid */
282  char *(*cmd_ctxargs_fn)(void *ctx, int argc, char **argv, char *buff); 
283                                /* takes argv and the full command as buff.
284                                 * caller must free return value if !NULL */
285  void (*cmd_ctxv_fn)(void *ctx);               /* takes no args */
286  void (*cmd_ctxi_fn)(void *ctx, int i);        /* takes an int as an arg */
287} owl_cmd;
288
289
290typedef struct _owl_zwrite {
[ce7db4d]291  char *class;
292  char *inst;
293  char *realm;
294  char *opcode;
[56330ff]295  char *zsig;
[ce7db4d]296  char *message;
[7d4fbcd]297  owl_list recips;
298  int cc;
299  int noping;
300} owl_zwrite;
301
[d0d65df]302typedef struct _owl_pair {
303  void *key;
304  void *value;
305} owl_pair;
306
[7d4fbcd]307typedef struct _owl_message {
308  int id;
309  int type;
[4b464a4]310  int direction;
[be0a79f]311#ifdef HAVE_LIBZEPHYR
[7d4fbcd]312  ZNotice_t notice;
[be0a79f]313#endif
[bd3f232]314  owl_fmtext fmtext;              /* this is now only a CACHED copy */
315  int invalid_format;             /* indicates whether fmtext needs to be regenerated */
[7d4fbcd]316  int delete;
[8298425]317  char *hostname;
[65ad073]318  owl_list attributes;            /* this is a list of pairs */
[25dd31a]319  char *timestr;
320  time_t time;
[7d4fbcd]321  char *zwriteline;
322} owl_message;
323
[bd3f232]324typedef struct _owl_style {
325  char *name;
[f1e629d]326  char *description;
[bd3f232]327  int type;
328  char *perlfuncname;
329  void (*formatfunc) (owl_fmtext *fm, owl_message *m);
330} owl_style;
331
[7d4fbcd]332typedef struct _owl_mainwin {
333  int curtruncated;
[f2e36b5]334  int lasttruncated;
[7d4fbcd]335  int lastdisplayed;
336} owl_mainwin;
337
338typedef struct _owl_viewwin {
339  owl_fmtext fmtext;
340  int textlines;
341  int topline;
342  int rightshift;
343  int winlines, wincols;
344  WINDOW *curswin;
[afbf668]345  void (*onclose_hook) (struct _owl_viewwin *vwin, void *data);
346  void *onclose_hook_data;
[7d4fbcd]347} owl_viewwin;
348 
349typedef struct _owl_popwin {
350  WINDOW *borderwin;
351  WINDOW *popwin;
352  int lines;
353  int cols;
354  int active;
355  int needsfirstrefresh;
356  void (*handler) (int ch);
357} owl_popwin;
358
[dab82f29]359typedef struct _owl_dispatch {
360  int fd;                                 /* FD to watch for dispatch. */
361  int needs_gc;
362  void (*cfunc)(struct _owl_dispatch*);   /* C function to dispatch to. */
363  void (*destroy)(struct _owl_dispatch*); /* Destructor */
364  void *data;
365} owl_dispatch;
366
[afbf668]367typedef struct _owl_popexec {
368  int refcount;
369  owl_viewwin *vwin;
370  int winactive;
371  int pid;                      /* or 0 if it has terminated */
[dab82f29]372  owl_dispatch dispatch;
[afbf668]373} owl_popexec;
374
[7d4fbcd]375typedef struct _owl_messagelist {
376  owl_list list;
377} owl_messagelist;
378
379typedef struct _owl_regex {
380  int negate;
381  char *string;
382  regex_t re;
383} owl_regex;
384
385typedef struct _owl_filterelement {
386  int type;
387  char *field;
388  owl_regex re;
[40458b9]389  char *filtername;  /* for maching on another filter */
[7d4fbcd]390} owl_filterelement;
391
392typedef struct _owl_filter {
393  char *name;
394  int polarity;
395  owl_list fes; /* filterelements */
396  int color;
[59cf91c]397  int cachedmsgid;  /* cached msgid: should move into view eventually */
[7d4fbcd]398} owl_filter;
399
400typedef struct _owl_view {
[c3ab155]401  char *name;
[7d4fbcd]402  owl_filter *filter;
403  owl_messagelist ml;
[c3ab155]404  owl_style *style;
[7d4fbcd]405} owl_view;
406
407typedef struct _owl_history {
408  owl_list hist;
409  int cur;
410  int touched;
411  int partial;
[12c35df]412  int repeats;
[7d4fbcd]413} owl_history;
414
[10b866d]415typedef struct _owl_editwin {
416  char *buff;
417  owl_history *hist;
418  int bufflen;
419  int allocated;
420  int buffx, buffy;
421  int topline;
422  int winlines, wincols, fillcol, wrapcol;
423  WINDOW *curswin;
424  int style;
425  int lock;
426  int dotsend;
[c9334b1]427  int echochar;
[10b866d]428} owl_editwin;
429
[7d4fbcd]430typedef struct _owl_keybinding {
431  int  *j;                      /* keypress stack (0-terminated) */ 
432  int   type;                   /* command or function? */
433  char *desc;                   /* description (or "*user*") */
434  char *command;                /* command, if of type command */
435  void (*function_fn)(void);    /* function ptr, if of type function */
436} owl_keybinding;
437
438typedef struct _owl_keymap {
439  char     *name;               /* name of keymap */
440  char     *desc;               /* description */
441  owl_list  bindings;           /* key bindings */
442  struct _owl_keymap *submap;   /* submap */
443  void (*default_fn)(int j);    /* default action (takes a keypress) */
444  void (*prealways_fn)(int j);  /* always called before a keypress is received */
445  void (*postalways_fn)(int j); /* always called after keypress is processed */
446} owl_keymap;
447
448typedef struct _owl_keyhandler {
449  owl_dict  keymaps;            /* dictionary of keymaps */
450  owl_keymap *active;           /* currently active keymap */
451  int       in_esc;             /* escape pressed? */
452  int       kpstack[OWL_KEYMAP_MAXSTACK+1]; /* current stack of keypresses */
453  int       kpstackpos;         /* location in stack (-1 = none) */
454} owl_keyhandler;
455
[f4d0975]456typedef struct _owl_buddy {
457  int proto;
458  char *name;
459  int isidle;
460  int idlesince;
461} owl_buddy;
462
[aa5f725]463typedef struct _owl_buddylist {
464  owl_list buddies;
465} owl_buddylist;
466
[5a95b69]467typedef struct _owl_zbuddylist {
468  owl_list zusers;
469} owl_zbuddylist;
470
[6a415e9]471typedef struct _owl_timer {
472  int direction;
473  time_t starttime;
474  int start;
475} owl_timer;
[aa5f725]476
[ec6ff52]477typedef struct _owl_errqueue {
478  owl_list errlist;
479} owl_errqueue;
480
[7d4fbcd]481typedef struct _owl_global {
482  owl_mainwin mw;
483  owl_popwin pw;
[10b866d]484  owl_history cmdhist;          /* command history */
485  owl_history msghist;          /* outgoing message history */
[7d4fbcd]486  owl_keyhandler kh;
487  owl_list filterlist;
488  owl_list puntlist;
489  owl_vardict vars;
490  owl_cmddict cmds;
491  owl_context ctx;
[ec6ff52]492  owl_errqueue errqueue;
[7d4fbcd]493  int lines, cols;
494  int curmsg, topmsg;
495  int curmsg_vert_offset;
496  owl_view current_view;
497  owl_messagelist msglist;
498  WINDOW *recwin, *sepwin, *msgwin, *typwin;
499  int needrefresh;
500  int rightshift;
501  int resizepending;
502  int recwinlines;
503  int typwinactive;
[a8938c7]504  char *thishost;
505  char *homedir;
[7d4fbcd]506  int direction;
507  int zaway;
508  char *cur_zaway_msg;
509  int haveconfig;
510  int config_format;
[a8938c7]511  char *buffercommand;
[7d4fbcd]512  owl_editwin tw;
513  owl_viewwin vw;
514  void *perl;
515  int debug;
516  int starttime;
[a8938c7]517  char *startupargs;
[7d4fbcd]518  int userclue;
519  int nextmsgid;
520  int hascolors;
521  int colorpairs;
[1fd0b25]522  int searchactive;
[700c712]523  int newmsgproc_pid;
[8262340]524  int malloced, freed;
[1fd0b25]525  char *searchstring;
[7d4fbcd]526  owl_filterelement fe_true;
527  owl_filterelement fe_false;
528  owl_filterelement fe_null;
[d09e5a1]529  aim_session_t aimsess;
[c15bbfb]530  aim_conn_t bosconn;
[6a415e9]531  owl_timer aim_noop_timer;
532  owl_timer aim_ignorelogin_timer;
[de03334]533  owl_timer aim_buddyinfo_timer;
[bd3f232]534  int aim_loggedin;         /* true if currently logged into AIM */
[a352335c]535  int aim_doprocessing;     /* true if we should process AIM events (like pending login) */
[bd3f232]536  char *aim_screenname;     /* currently logged in AIM screen name */
537  owl_buddylist buddylist;  /* list of logged in AIM buddies */
538  owl_list messagequeue;    /* for queueing up aim and other messages */
[f1e629d]539  owl_dict styledict;       /* global dictionary of available styles */
[cf83b7a]540  char *response;           /* response to the last question asked */
[09489b89]541  int havezephyr;
542  int haveaim;
[c9e72d1]543  int got_err_signal;       /* 1 if we got an unexpected signal */
[5a95b69]544  siginfo_t err_signal_info;
545  owl_zbuddylist zbuddies;
546  owl_timer zephyr_buddycheck_timer;
[8232149]547  struct termios startup_tio;
[dab82f29]548  owl_list dispatchlist;
[7d4fbcd]549} owl_global;
550
551/* globals */
[b2b0773]552extern owl_global g;
[7d4fbcd]553
554#include "owl_prototypes.h"
555
556/* these are missing from the zephyr includes for some reason */
[be0a79f]557#ifdef HAVE_LIBZEPHYR
[7d4fbcd]558int ZGetSubscriptions(ZSubscription_t *, int *);
559int ZGetLocations(ZLocations_t *,int *);
[be0a79f]560#endif
[7d4fbcd]561
562#endif /* INC_OWL_H */
Note: See TracBrowser for help on using the repository browser.