source: owl.h @ 8232149

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 8232149 was 8232149, checked in by James M. Kretchmar <kretch@mit.edu>, 19 years ago
Turn off istrip. Restore initial terminal settings at problem exit. Version set to 2.1.10 in prep. for release.
  • Property mode set to 100644
File size: 16.7 KB
Line 
1/*  Copyright (c) 2004 James Kretchmar. All rights reserved.
2 *
3 *  Redistribution and use in source and binary forms, with or without
4 *  modification, are permitted provided that the following conditions are
5 *  met:
6 * 
7 *    * Redistributions of source code must retain the above copyright
8 *      notice, this list of conditions and the following disclaimer.
9 * 
10 *    * Redistributions in binary form must reproduce the above copyright
11 *      notice, this list of conditions and the following disclaimer in
12 *      the documentation and/or other materials provided with the
13 *      distribution.
14 * 
15 *    * Redistributions in any form must be accompanied by information on
16 *      how to obtain complete source code for the Owl software and any
17 *      accompanying software that uses the Owl software. The source code
18 *      must either be included in the distribution or be available for no
19 *      more than the cost of distribution plus a nominal fee, and must be
20 *      freely redistributable under reasonable conditions. For an
21 *      executable file, complete source code means the source code for
22 *      all modules it contains. It does not include source code for
23 *      modules or files that typically accompany the major components of
24 *      the operating system on which the executable file runs.
25 * 
26 *
27 *  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
28 *  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
29 *  WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
30 *  NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
31 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
34 *  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
35 *  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
36 *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
37 *  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 */
39
40#ifndef INC_OWL_H
41#define INC_OWL_H
42
43#include <curses.h>
44#include <sys/param.h>
45#include <EXTERN.h>
46#include <netdb.h>
47#include <regex.h>
48#include <time.h>
49#include <signal.h>
50#include <termios.h>
51#include <libfaim/aim.h>
52#include "config.h"
53#ifdef HAVE_LIBZEPHYR
54#include <zephyr/zephyr.h>
55#endif
56#ifdef HAVE_COM_ERR_H
57#include <com_err.h>
58#endif
59
60static const char owl_h_fileIdent[] = "$Id$";
61
62#define OWL_VERSION         2.1.10
63#define OWL_VERSION_STRING "2.1.10"
64
65/* Feature that is being tested to redirect stderr through a pipe.
66 * There may still be some portability problems with this. */
67#define OWL_STDERR_REDIR 1
68
69#define OWL_DEBUG 0
70#define OWL_DEBUG_FILE "/var/tmp/owldebug"
71
72#define OWL_CONFIG_DIR "/.owl"             /* this is relative to the user's home directory */
73#define OWL_STARTUP_FILE "/.owl/startup"   /* this is relative to the user's home directory */
74
75#define OWL_FMTEXT_ATTR_NONE      0
76#define OWL_FMTEXT_ATTR_BOLD      1
77#define OWL_FMTEXT_ATTR_REVERSE   2
78#define OWL_FMTEXT_ATTR_UNDERLINE 4
79
80#define OWL_COLOR_BLACK     0
81#define OWL_COLOR_RED       1
82#define OWL_COLOR_GREEN     2
83#define OWL_COLOR_YELLOW    3
84#define OWL_COLOR_BLUE      4
85#define OWL_COLOR_MAGENTA   5
86#define OWL_COLOR_CYAN      6
87#define OWL_COLOR_WHITE     7
88#define OWL_COLOR_DEFAULT   8
89
90#define OWL_EDITWIN_STYLE_MULTILINE 0
91#define OWL_EDITWIN_STYLE_ONELINE   1
92
93#define OWL_PROTOCOL_ZEPHYR         0
94#define OWL_PROTOCOL_AIM            1
95#define OWL_PROTOCOL_JABBER         2
96#define OWL_PROTOCOL_ICQ            3
97#define OWL_PROTOCOL_YAHOO          4
98#define OWL_PROTOCOL_MSN            5
99
100#define OWL_MESSAGE_TYPE_ADMIN      0
101#define OWL_MESSAGE_TYPE_GENERIC    1
102#define OWL_MESSAGE_TYPE_ZEPHYR     2
103#define OWL_MESSAGE_TYPE_AIM        3
104#define OWL_MESSAGE_TYPE_JABBER     4
105#define OWL_MESSAGE_TYPE_ICQ        5
106#define OWL_MESSAGE_TYPE_YAHOO      6
107#define OWL_MESSAGE_TYPE_MSN        7
108#define OWL_MESSAGE_TYPE_LOOPBACK   8
109
110#define OWL_MESSAGE_DIRECTION_NONE  0
111#define OWL_MESSAGE_DIRECTION_IN    1
112#define OWL_MESSAGE_DIRECTION_OUT   2
113
114#define OWL_MUX_READ   1
115#define OWL_MUX_WRITE  2
116#define OWL_MUX_EXCEPT 4
117
118#define OWL_DIRECTION_NONE      0
119#define OWL_DIRECTION_DOWNWARDS 1
120#define OWL_DIRECTION_UPWARDS   2
121
122#define OWL_LOGGING_DIRECTION_BOTH 0
123#define OWL_LOGGING_DIRECTION_IN   1
124#define OWL_LOGGING_DIRECTION_OUT  2
125
126#define OWL_SCROLLMODE_NORMAL      0
127#define OWL_SCROLLMODE_TOP         1
128#define OWL_SCROLLMODE_NEARTOP     2
129#define OWL_SCROLLMODE_CENTER      3
130#define OWL_SCROLLMODE_PAGED       4
131#define OWL_SCROLLMODE_PAGEDCENTER 5
132
133#define OWL_STYLE_TYPE_INTERNAL  0
134#define OWL_STYLE_TYPE_PERL      1
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_INCLUDE_REG_TESTS   1  /* whether to build in regression tests */
187
188#define OWL_CMD_ALIAS_SUMMARY_PREFIX "command alias to: "
189
190#define OWL_WEBZEPHYR_PRINCIPAL "daemon.webzephyr"
191#define OWL_WEBZEPHYR_CLASS     "webzephyr"
192#define OWL_WEBZEPHYR_OPCODE    "webzephyr"
193
194#define OWL_REGEX_QUOTECHARS    "+*.?[]^\\"
195#define OWL_REGEX_QUOTEWITH     "\\"
196
197#if defined(HAVE_DES_STRING_TO_KEY) && defined(HAVE_DES_KEY_SCHED) && defined(HAVE_DES_ECB_ENCRYPT)
198#define OWL_ENABLE_ZCRYPT 1
199#endif
200
201#define OWL_META(key) ((key)|0200)
202/* OWL_CTRL is definied in kepress.c */
203
204#define LINE 2048
205
206typedef struct _owl_variable {
207  char *name;
208  int   type;  /* OWL_VARIABLE_* */
209  void *pval_default;  /* for types other and string */
210  int   ival_default;  /* for types int and bool     */
211  char *validsettings;          /* documentation of valid settings */
212  char *summary;                /* summary of usage */
213  char *description;            /* detailed description */
214  void *val;                    /* current value */
215  int  (*validate_fn)(struct _owl_variable *v, void *newval);
216                                /* returns 1 if newval is valid */
217  int  (*set_fn)(struct _owl_variable *v, void *newval); 
218                                /* sets the variable to a value
219                                 * of the appropriate type.
220                                 * unless documented, this
221                                 * should make a copy.
222                                 * returns 0 on success. */
223  int  (*set_fromstring_fn)(struct _owl_variable *v, char *newval);
224                                /* sets the variable to a value
225                                 * of the appropriate type.
226                                 * unless documented, this
227                                 * should make a copy.
228                                 * returns 0 on success. */
229  void *(*get_fn)(struct _owl_variable *v);
230                                /* returns a reference to the current value.
231                                 * WARNING:  this approach is hard to make
232                                 * thread-safe... */
233  int  (*get_tostring_fn)(struct _owl_variable *v, 
234                          char *buf, int bufsize, void *val); 
235                                /* converts val to a string
236                                 * and puts into buf */
237  void  (*free_fn)(struct _owl_variable *v);
238                                /* frees val as needed */
239} owl_variable;
240
241typedef struct _owl_fmtext {
242  int textlen;
243  char *textbuff;
244  char *fmbuff;
245  char *colorbuff;
246} owl_fmtext;
247
248typedef struct _owl_list {
249  int size;
250  int avail;
251  void **list;
252} owl_list;
253
254typedef struct _owl_dict_el {
255  char *k;                      /* key   */
256  void *v;                      /* value */
257} owl_dict_el;
258
259typedef struct _owl_dict {
260  int size;
261  int avail;
262  owl_dict_el *els;             /* invariant: sorted by k */
263} owl_dict;
264typedef owl_dict owl_vardict;   /* dict of variables */
265typedef owl_dict owl_cmddict;   /* dict of commands */
266
267typedef struct _owl_context {
268  int   mode;
269  void *data;           /* determined by mode */
270} owl_context;
271
272typedef struct _owl_cmd {       /* command */
273  char *name;
274
275  char *summary;                /* one line summary of command */
276  char *usage;                  /* usage synopsis */
277  char *description;            /* long description of command */
278
279  int validctx;                 /* bitmask of valid contexts */
280
281  /* we should probably have a type here that says which of
282   * the following is valid, and maybe make the below into a union... */
283
284  /* Only one of these may be non-NULL ... */
285
286  char *cmd_aliased_to;         /* what this command is aliased to... */
287 
288  /* These don't take any context */
289  char *(*cmd_args_fn)(int argc, char **argv, char *buff); 
290                                /* takes argv and the full command as buff.
291                                 * caller must free return value if !NULL */
292  void (*cmd_v_fn)(void);       /* takes no args */
293  void (*cmd_i_fn)(int i);      /* takes an int as an arg */
294
295  /* The following also take the active context if it's valid */
296  char *(*cmd_ctxargs_fn)(void *ctx, int argc, char **argv, char *buff); 
297                                /* takes argv and the full command as buff.
298                                 * caller must free return value if !NULL */
299  void (*cmd_ctxv_fn)(void *ctx);               /* takes no args */
300  void (*cmd_ctxi_fn)(void *ctx, int i);        /* takes an int as an arg */
301} owl_cmd;
302
303
304typedef struct _owl_zwrite {
305  char *class;
306  char *inst;
307  char *realm;
308  char *opcode;
309  char *zsig;
310  char *message;
311  owl_list recips;
312  int cc;
313  int noping;
314} owl_zwrite;
315
316typedef struct _owl_pair {
317  void *key;
318  void *value;
319} owl_pair;
320
321typedef struct _owl_message {
322  int id;
323  int type;
324  int direction;
325#ifdef HAVE_LIBZEPHYR
326  ZNotice_t notice;
327#endif
328  owl_fmtext fmtext;              /* this is now only a CACHED copy */
329  int invalid_format;             /* indicates whether fmtext needs to be regenerated */
330  int delete;
331  char *hostname;
332  owl_list attributes;            /* this is a list of pairs */
333  char *timestr;
334  time_t time;
335  char *zwriteline;
336} owl_message;
337
338typedef struct _owl_style {
339  char *name;
340  char *description;
341  int type;
342  char *perlfuncname;
343  void (*formatfunc) (owl_fmtext *fm, owl_message *m);
344} owl_style;
345
346typedef struct _owl_mainwin {
347  int curtruncated;
348  int lasttruncated;
349  int lastdisplayed;
350} owl_mainwin;
351
352typedef struct _owl_viewwin {
353  owl_fmtext fmtext;
354  int textlines;
355  int topline;
356  int rightshift;
357  int winlines, wincols;
358  WINDOW *curswin;
359  void (*onclose_hook) (struct _owl_viewwin *vwin, void *data);
360  void *onclose_hook_data;
361} owl_viewwin;
362 
363typedef struct _owl_popwin {
364  WINDOW *borderwin;
365  WINDOW *popwin;
366  int lines;
367  int cols;
368  int active;
369  int needsfirstrefresh;
370  void (*handler) (int ch);
371} owl_popwin;
372
373typedef struct _owl_popexec {
374  int refcount;
375  owl_viewwin *vwin;
376  int winactive;
377  int pid;                      /* or 0 if it has terminated */
378  int rfd; 
379} owl_popexec;
380
381typedef struct _owl_messagelist {
382  owl_list list;
383} owl_messagelist;
384
385typedef struct _owl_regex {
386  int negate;
387  char *string;
388  regex_t re;
389} owl_regex;
390
391typedef struct _owl_filterelement {
392  int type;
393  char *field;
394  owl_regex re;
395  char *filtername;  /* for maching on another filter */
396} owl_filterelement;
397
398typedef struct _owl_filter {
399  char *name;
400  int polarity;
401  owl_list fes; /* filterelements */
402  int color;
403  int cachedmsgid;  /* cached msgid: should move into view eventually */
404} owl_filter;
405
406typedef struct _owl_view {
407  char *name;
408  owl_filter *filter;
409  owl_messagelist ml;
410  owl_style *style;
411} owl_view;
412
413typedef struct _owl_history {
414  owl_list hist;
415  int cur;
416  int touched;
417  int partial;
418  int repeats;
419} owl_history;
420
421typedef struct _owl_editwin {
422  char *buff;
423  owl_history *hist;
424  int bufflen;
425  int allocated;
426  int buffx, buffy;
427  int topline;
428  int winlines, wincols, fillcol, wrapcol;
429  WINDOW *curswin;
430  int style;
431  int lock;
432  int dotsend;
433  int echochar;
434} owl_editwin;
435
436typedef struct _owl_mux {
437  int handle;                   /* for referencing this */
438  int active;                   /* has this been deleted? */
439  int fd;                     
440  int eventmask;                /* bitmask of OWL_MUX_* */
441  void (*handler_fn)(int handle, int fd, int eventmask, void *data);
442  void *data;                   /* data reference to pass to callback */
443} owl_mux;
444typedef owl_list owl_muxevents;
445
446typedef struct _owl_keybinding {
447  int  *j;                      /* keypress stack (0-terminated) */ 
448  int   type;                   /* command or function? */
449  char *desc;                   /* description (or "*user*") */
450  char *command;                /* command, if of type command */
451  void (*function_fn)(void);    /* function ptr, if of type function */
452} owl_keybinding;
453
454typedef struct _owl_keymap {
455  char     *name;               /* name of keymap */
456  char     *desc;               /* description */
457  owl_list  bindings;           /* key bindings */
458  struct _owl_keymap *submap;   /* submap */
459  void (*default_fn)(int j);    /* default action (takes a keypress) */
460  void (*prealways_fn)(int j);  /* always called before a keypress is received */
461  void (*postalways_fn)(int j); /* always called after keypress is processed */
462} owl_keymap;
463
464typedef struct _owl_keyhandler {
465  owl_dict  keymaps;            /* dictionary of keymaps */
466  owl_keymap *active;           /* currently active keymap */
467  int       in_esc;             /* escape pressed? */
468  int       kpstack[OWL_KEYMAP_MAXSTACK+1]; /* current stack of keypresses */
469  int       kpstackpos;         /* location in stack (-1 = none) */
470} owl_keyhandler;
471
472typedef struct _owl_buddy {
473  int proto;
474  char *name;
475  int isidle;
476  int idlesince;
477} owl_buddy;
478
479typedef struct _owl_buddylist {
480  owl_list buddies;
481} owl_buddylist;
482
483typedef struct _owl_zbuddylist {
484  owl_list zusers;
485} owl_zbuddylist;
486
487typedef struct _owl_timer {
488  int direction;
489  time_t starttime;
490  int start;
491} owl_timer;
492
493typedef struct _owl_errqueue {
494  owl_list errlist;
495} owl_errqueue;
496
497typedef struct _owl_global {
498  owl_mainwin mw;
499  owl_popwin pw;
500  owl_history cmdhist;          /* command history */
501  owl_history msghist;          /* outgoing message history */
502  owl_keyhandler kh;
503  owl_list filterlist;
504  owl_list puntlist;
505  owl_muxevents muxevents;      /* fds to dispatch on */
506  owl_vardict vars;
507  owl_cmddict cmds;
508  owl_context ctx;
509  owl_errqueue errqueue;
510  int lines, cols;
511  int curmsg, topmsg;
512  int curmsg_vert_offset;
513  owl_view current_view;
514  owl_messagelist msglist;
515  WINDOW *recwin, *sepwin, *msgwin, *typwin;
516  int needrefresh;
517  int rightshift;
518  int resizepending;
519  int recwinlines;
520  int typwinactive;
521  char *thishost;
522  char *homedir;
523  int direction;
524  int zaway;
525  char *cur_zaway_msg;
526  int haveconfig;
527  int config_format;
528  char *buffercommand;
529  owl_editwin tw;
530  owl_viewwin vw;
531  void *perl;
532  int debug;
533  int starttime;
534  char *startupargs;
535  int userclue;
536  int nextmsgid;
537  int hascolors;
538  int colorpairs;
539  int searchactive;
540  int newmsgproc_pid;
541  int malloced, freed;
542  char *searchstring;
543  owl_filterelement fe_true;
544  owl_filterelement fe_false;
545  owl_filterelement fe_null;
546  aim_session_t aimsess;
547  aim_conn_t bosconn;
548  owl_timer aim_noop_timer;
549  owl_timer aim_ignorelogin_timer;
550  owl_timer aim_buddyinfo_timer;
551  int aim_loggedin;         /* true if currently logged into AIM */
552  int aim_doprocessing;     /* true if we should process AIM events (like pending login) */
553  char *aim_screenname;     /* currently logged in AIM screen name */
554  owl_buddylist buddylist;  /* list of logged in AIM buddies */
555  owl_list messagequeue;    /* for queueing up aim and other messages */
556  owl_dict styledict;       /* global dictionary of available styles */
557  char *response;           /* response to the last question asked */
558  int havezephyr;
559  int haveaim;
560  int got_err_signal;       /* 1 if we got an unexpected signal */
561  siginfo_t err_signal_info;
562  owl_zbuddylist zbuddies;
563  owl_timer zephyr_buddycheck_timer;
564  struct termios startup_tio;
565} owl_global;
566
567/* globals */
568extern owl_global g;
569
570#include "owl_prototypes.h"
571
572/* these are missing from the zephyr includes for some reason */
573#ifdef HAVE_LIBZEPHYR
574int ZGetSubscriptions(ZSubscription_t *, int *);
575int ZGetLocations(ZLocations_t *,int *);
576#endif
577
578#endif /* INC_OWL_H */
Note: See TracBrowser for help on using the repository browser.