source: owl.h @ 1bdffcb

barnowl_perlaimdebianrelease-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 1bdffcb was 1bdffcb, checked in by Alejandro R. Sedeño <asedeno@mit.edu>, 14 years ago
owl.h - moved curses.h back up so building on Solaris would work. configure - added test for resizeterm global.c - conditionally include resizeterm fmtext.c - remove tabs, rewrite parts of the colorpair manager
  • Property mode set to 100644
File size: 17.4 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#ifndef OWL_PERL
44#include <curses.h>
45#endif
46#include <sys/param.h>
47#include <EXTERN.h>
48#include <netdb.h>
49#include <regex.h>
50#include <time.h>
51#include <signal.h>
52#include <termios.h>
53#include <libfaim/aim.h>
54#include "config.h"
55#ifdef HAVE_LIBZEPHYR
56#include <zephyr/zephyr.h>
57#endif
58#ifdef HAVE_COM_ERR_H
59#include <com_err.h>
60#endif
61
62/* Perl and curses don't play nice. */
63#ifdef OWL_PERL
64typedef void WINDOW;
65#include <perl.h>
66#include "XSUB.h"
67#else
68typedef void SV;
69#endif
70
71static const char owl_h_fileIdent[] = "$Id$";
72
73#define OWL_VERSION         2.1.11
74#define OWL_VERSION_STRING "2.1.11-doh"
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/owldebug"
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_COLOR_BLACK     0
92#define OWL_COLOR_RED       1
93#define OWL_COLOR_GREEN     2
94#define OWL_COLOR_YELLOW    3
95#define OWL_COLOR_BLUE      4
96#define OWL_COLOR_MAGENTA   5
97#define OWL_COLOR_CYAN      6
98#define OWL_COLOR_WHITE     7
99#define OWL_COLOR_DEFAULT   8
100
101#define OWL_EDITWIN_STYLE_MULTILINE 0
102#define OWL_EDITWIN_STYLE_ONELINE   1
103
104#define OWL_PROTOCOL_ZEPHYR         0
105#define OWL_PROTOCOL_AIM            1
106#define OWL_PROTOCOL_JABBER         2
107#define OWL_PROTOCOL_ICQ            3
108#define OWL_PROTOCOL_YAHOO          4
109#define OWL_PROTOCOL_MSN            5
110
111#define OWL_MESSAGE_TYPE_ADMIN      0
112#define OWL_MESSAGE_TYPE_GENERIC    1
113#define OWL_MESSAGE_TYPE_ZEPHYR     2
114#define OWL_MESSAGE_TYPE_AIM        3
115#define OWL_MESSAGE_TYPE_JABBER     4
116#define OWL_MESSAGE_TYPE_ICQ        5
117#define OWL_MESSAGE_TYPE_YAHOO      6
118#define OWL_MESSAGE_TYPE_MSN        7
119#define OWL_MESSAGE_TYPE_LOOPBACK   8
120
121#define OWL_MESSAGE_DIRECTION_NONE  0
122#define OWL_MESSAGE_DIRECTION_IN    1
123#define OWL_MESSAGE_DIRECTION_OUT   2
124
125#define OWL_MUX_READ   1
126#define OWL_MUX_WRITE  2
127#define OWL_MUX_EXCEPT 4
128
129#define OWL_DIRECTION_NONE      0
130#define OWL_DIRECTION_DOWNWARDS 1
131#define OWL_DIRECTION_UPWARDS   2
132
133#define OWL_LOGGING_DIRECTION_BOTH 0
134#define OWL_LOGGING_DIRECTION_IN   1
135#define OWL_LOGGING_DIRECTION_OUT  2
136
137#define OWL_SCROLLMODE_NORMAL      0
138#define OWL_SCROLLMODE_TOP         1
139#define OWL_SCROLLMODE_NEARTOP     2
140#define OWL_SCROLLMODE_CENTER      3
141#define OWL_SCROLLMODE_PAGED       4
142#define OWL_SCROLLMODE_PAGEDCENTER 5
143
144#define OWL_STYLE_TYPE_INTERNAL  0
145#define OWL_STYLE_TYPE_PERL      1
146
147#define OWL_TAB               3  /* This *HAS* to be the size of TABSTR below */
148#define OWL_TABSTR        "   "
149#define OWL_MSGTAB            7
150#define OWL_TYPWIN_SIZE       8
151#define OWL_HISTORYSIZE       50
152
153/* Indicate current state, as well as what is allowed */
154#define OWL_CTX_ANY          0xffff
155/* Only one of these may be active at a time... */
156#define OWL_CTX_MODE_BITS    0x000f
157#define OWL_CTX_STARTUP      0x0001
158#define OWL_CTX_READCONFIG   0x0002
159#define OWL_CTX_INTERACTIVE  0x0004
160/* Only one of these may be active at a time... */
161#define OWL_CTX_ACTIVE_BITS  0xfff0
162#define OWL_CTX_POPWIN       0x00f0
163#define OWL_CTX_POPLESS      0x0010
164#define OWL_CTX_RECWIN       0x0f00
165#define OWL_CTX_RECV         0x0100
166#define OWL_CTX_TYPWIN       0xf000
167#define OWL_CTX_EDIT         0x7000
168#define OWL_CTX_EDITLINE     0x1000
169#define OWL_CTX_EDITMULTI    0x2000
170#define OWL_CTX_EDITRESPONSE 0x4000
171
172#define OWL_USERCLUE_NONE       0
173#define OWL_USERCLUE_CLASSES    1
174#define OWL_USERCLUE_FOOBAR     2
175#define OWL_USERCLUE_BAZ        4
176
177#define OWL_WEBBROWSER_NONE     0
178#define OWL_WEBBROWSER_NETSCAPE 1
179#define OWL_WEBBROWSER_GALEON   2
180#define OWL_WEBBROWSER_OPERA    3
181
182#define OWL_VARIABLE_OTHER      0
183#define OWL_VARIABLE_INT        1
184#define OWL_VARIABLE_BOOL       2
185#define OWL_VARIABLE_STRING     3
186
187#define OWL_FILTER_MAX_DEPTH    300
188
189#define OWL_KEYMAP_MAXSTACK     20
190
191#define OWL_KEYBINDING_COMMAND  1   /* command string */
192#define OWL_KEYBINDING_FUNCTION 2   /* function taking no args */
193
194#define OWL_DEFAULT_ZAWAYMSG    "I'm sorry, but I am currently away from the terminal and am\nnot able to receive your message.\n"
195#define OWL_DEFAULT_AAWAYMSG    "I'm sorry, but I am currently away from the terminal and am\nnot able to receive your message.\n"
196
197#define OWL_INCLUDE_REG_TESTS   1  /* whether to build in regression tests */
198
199#define OWL_CMD_ALIAS_SUMMARY_PREFIX "command alias to: "
200
201#define OWL_WEBZEPHYR_PRINCIPAL "daemon.webzephyr"
202#define OWL_WEBZEPHYR_CLASS     "webzephyr"
203#define OWL_WEBZEPHYR_OPCODE    "webzephyr"
204
205#define OWL_REGEX_QUOTECHARS    "+*.?[]^\\"
206#define OWL_REGEX_QUOTEWITH     "\\"
207
208#if defined(HAVE_DES_STRING_TO_KEY) && defined(HAVE_DES_KEY_SCHED) && defined(HAVE_DES_ECB_ENCRYPT)
209#define OWL_ENABLE_ZCRYPT 1
210#endif
211
212#define OWL_META(key) ((key)|0200)
213/* OWL_CTRL is definied in kepress.c */
214
215#define LINE 2048
216
217typedef struct _owl_variable {
218  char *name;
219  int   type;  /* OWL_VARIABLE_* */
220  void *pval_default;  /* for types other and string */
221  int   ival_default;  /* for types int and bool     */
222  char *validsettings;          /* documentation of valid settings */
223  char *summary;                /* summary of usage */
224  char *description;            /* detailed description */
225  void *val;                    /* current value */
226  int  (*validate_fn)(struct _owl_variable *v, void *newval);
227                                /* returns 1 if newval is valid */
228  int  (*set_fn)(struct _owl_variable *v, void *newval); 
229                                /* sets the variable to a value
230                                 * of the appropriate type.
231                                 * unless documented, this
232                                 * should make a copy.
233                                 * returns 0 on success. */
234  int  (*set_fromstring_fn)(struct _owl_variable *v, char *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  void *(*get_fn)(struct _owl_variable *v);
241                                /* returns a reference to the current value.
242                                 * WARNING:  this approach is hard to make
243                                 * thread-safe... */
244  int  (*get_tostring_fn)(struct _owl_variable *v, 
245                          char *buf, int bufsize, void *val); 
246                                /* converts val to a string
247                                 * and puts into buf */
248  void  (*free_fn)(struct _owl_variable *v);
249                                /* frees val as needed */
250} owl_variable;
251
252typedef struct _owl_fmtext {
253  int textlen;
254  char *textbuff;
255  char *fmbuff;
256  char *fgcolorbuff;
257  char *bgcolorbuff;
258} owl_fmtext;
259
260typedef struct _owl_list {
261  int size;
262  int avail;
263  void **list;
264} owl_list;
265
266typedef struct _owl_dict_el {
267  char *k;                      /* key   */
268  void *v;                      /* value */
269} owl_dict_el;
270
271typedef struct _owl_dict {
272  int size;
273  int avail;
274  owl_dict_el *els;             /* invariant: sorted by k */
275} owl_dict;
276typedef owl_dict owl_vardict;   /* dict of variables */
277typedef owl_dict owl_cmddict;   /* dict of commands */
278
279typedef struct _owl_context {
280  int   mode;
281  void *data;           /* determined by mode */
282} owl_context;
283
284typedef struct _owl_cmd {       /* command */
285  char *name;
286
287  char *summary;                /* one line summary of command */
288  char *usage;                  /* usage synopsis */
289  char *description;            /* long description of command */
290
291  int validctx;                 /* bitmask of valid contexts */
292
293  /* we should probably have a type here that says which of
294   * the following is valid, and maybe make the below into a union... */
295
296  /* Only one of these may be non-NULL ... */
297
298  char *cmd_aliased_to;         /* what this command is aliased to... */
299 
300  /* These don't take any context */
301  char *(*cmd_args_fn)(int argc, char **argv, char *buff); 
302                                /* takes argv and the full command as buff.
303                                 * caller must free return value if !NULL */
304  void (*cmd_v_fn)(void);       /* takes no args */
305  void (*cmd_i_fn)(int i);      /* takes an int as an arg */
306
307  /* The following also take the active context if it's valid */
308  char *(*cmd_ctxargs_fn)(void *ctx, int argc, char **argv, char *buff); 
309                                /* takes argv and the full command as buff.
310                                 * caller must free return value if !NULL */
311  void (*cmd_ctxv_fn)(void *ctx);               /* takes no args */
312  void (*cmd_ctxi_fn)(void *ctx, int i);        /* takes an int as an arg */
313  SV *cmd_perl;                                /* Perl closure that takes a list of args */
314} owl_cmd;
315
316
317typedef struct _owl_zwrite {
318  char *class;
319  char *inst;
320  char *realm;
321  char *opcode;
322  char *zsig;
323  char *message;
324  owl_list recips;
325  int cc;
326  int noping;
327} owl_zwrite;
328
329typedef struct _owl_pair {
330  void *key;
331  void *value;
332} owl_pair;
333
334typedef struct _owl_message {
335  int id;
336  int type;
337  int direction;
338#ifdef HAVE_LIBZEPHYR
339  ZNotice_t notice;
340#endif
341  owl_fmtext fmtext;              /* this is now only a CACHED copy */
342  int invalid_format;             /* indicates whether fmtext needs to be regenerated */
343  int delete;
344  char *hostname;
345  owl_list attributes;            /* this is a list of pairs */
346  char *timestr;
347  time_t time;
348  char *zwriteline;
349} owl_message;
350
351typedef struct _owl_style {
352  char *name;
353  char *description;
354  int type;
355  char *perlfuncname;
356  void (*formatfunc) (owl_fmtext *fm, owl_message *m);
357} owl_style;
358
359typedef struct _owl_mainwin {
360  int curtruncated;
361  int lasttruncated;
362  int lastdisplayed;
363} owl_mainwin;
364
365typedef struct _owl_viewwin {
366  owl_fmtext fmtext;
367  int textlines;
368  int topline;
369  int rightshift;
370  int winlines, wincols;
371  WINDOW *curswin;
372  void (*onclose_hook) (struct _owl_viewwin *vwin, void *data);
373  void *onclose_hook_data;
374} owl_viewwin;
375 
376typedef struct _owl_popwin {
377  WINDOW *borderwin;
378  WINDOW *popwin;
379  int lines;
380  int cols;
381  int active;
382  int needsfirstrefresh;
383  void (*handler) (int ch);
384} owl_popwin;
385
386typedef struct _owl_popexec {
387  int refcount;
388  owl_viewwin *vwin;
389  int winactive;
390  int pid;                      /* or 0 if it has terminated */
391  int rfd; 
392} owl_popexec;
393
394typedef struct _owl_messagelist {
395  owl_list list;
396} owl_messagelist;
397
398typedef struct _owl_regex {
399  int negate;
400  char *string;
401  regex_t re;
402} owl_regex;
403
404typedef struct _owl_filterelement {
405  int (*match_message)(struct _owl_filterelement *fe, owl_message *m);
406  /* Append a string representation of the filterelement onto buf*/
407  void (*print_elt)(struct _owl_filterelement *fe, char * buf);
408  /* Operands for and,or,not*/
409  struct _owl_filterelement *left, *right;
410  /* For regex filters*/
411  owl_regex re;
412  /* Used by regexes, filter references, and perl */
413  char *field;
414} owl_filterelement;
415
416typedef struct _owl_filter {
417  char *name;
418  int polarity;
419  owl_filterelement * root;
420  int fgcolor;
421  int bgcolor;
422  int cachedmsgid;  /* cached msgid: should move into view eventually */
423} owl_filter;
424
425typedef struct _owl_view {
426  char *name;
427  owl_filter *filter;
428  owl_messagelist ml;
429  owl_style *style;
430} owl_view;
431
432typedef struct _owl_history {
433  owl_list hist;
434  int cur;
435  int touched;
436  int partial;
437  int repeats;
438} owl_history;
439
440typedef struct _owl_editwin {
441  char *buff;
442  owl_history *hist;
443  int bufflen;
444  int allocated;
445  int buffx, buffy;
446  int topline;
447  int winlines, wincols, fillcol, wrapcol;
448  WINDOW *curswin;
449  int style;
450  int lock;
451  int dotsend;
452  int echochar;
453
454  char *command;
455  void (*callback)(struct _owl_editwin*);
456  void *cbdata;
457} owl_editwin;
458
459typedef struct _owl_mux {
460  int handle;                   /* for referencing this */
461  int active;                   /* has this been deleted? */
462  int fd;                     
463  int eventmask;                /* bitmask of OWL_MUX_* */
464  void (*handler_fn)(int handle, int fd, int eventmask, void *data);
465  void *data;                   /* data reference to pass to callback */
466} owl_mux;
467typedef owl_list owl_muxevents;
468
469typedef struct _owl_keybinding {
470  int  *j;                      /* keypress stack (0-terminated) */ 
471  int   type;                   /* command or function? */
472  char *desc;                   /* description (or "*user*") */
473  char *command;                /* command, if of type command */
474  void (*function_fn)(void);    /* function ptr, if of type function */
475} owl_keybinding;
476
477typedef struct _owl_keymap {
478  char     *name;               /* name of keymap */
479  char     *desc;               /* description */
480  owl_list  bindings;           /* key bindings */
481  struct _owl_keymap *submap;   /* submap */
482  void (*default_fn)(int j);    /* default action (takes a keypress) */
483  void (*prealways_fn)(int j);  /* always called before a keypress is received */
484  void (*postalways_fn)(int j); /* always called after keypress is processed */
485} owl_keymap;
486
487typedef struct _owl_keyhandler {
488  owl_dict  keymaps;            /* dictionary of keymaps */
489  owl_keymap *active;           /* currently active keymap */
490  int       in_esc;             /* escape pressed? */
491  int       kpstack[OWL_KEYMAP_MAXSTACK+1]; /* current stack of keypresses */
492  int       kpstackpos;         /* location in stack (-1 = none) */
493} owl_keyhandler;
494
495typedef struct _owl_buddy {
496  int proto;
497  char *name;
498  int isidle;
499  int idlesince;
500} owl_buddy;
501
502typedef struct _owl_buddylist {
503  owl_list buddies;
504} owl_buddylist;
505
506typedef struct _owl_zbuddylist {
507  owl_list zusers;
508} owl_zbuddylist;
509
510typedef struct _owl_timer {
511  int direction;
512  time_t starttime;
513  int start;
514} owl_timer;
515
516typedef struct _owl_errqueue {
517  owl_list errlist;
518} owl_errqueue;
519
520typedef struct _owl_colorpair_mgr {
521  char *used;
522  int **pairs;
523} owl_colorpair_mgr;
524
525typedef struct _owl_global {
526  owl_mainwin mw;
527  owl_popwin pw;
528  owl_history cmdhist;          /* command history */
529  owl_history msghist;          /* outgoing message history */
530  owl_keyhandler kh;
531  owl_list filterlist;
532  owl_list puntlist;
533  owl_muxevents muxevents;      /* fds to dispatch on */
534  owl_vardict vars;
535  owl_cmddict cmds;
536  owl_context ctx;
537  owl_errqueue errqueue;
538  int lines, cols;
539  int curmsg, topmsg;
540  int curmsg_vert_offset;
541  owl_view current_view;
542  owl_messagelist msglist;
543  WINDOW *recwin, *sepwin, *msgwin, *typwin;
544  int needrefresh;
545  int rightshift;
546  int resizepending;
547  int recwinlines;
548  int typwinactive;
549  char *thishost;
550  char *homedir;
551  int direction;
552  int zaway;
553  char *cur_zaway_msg;
554  int haveconfig;
555  int config_format;
556  void *buffercbdata;
557  owl_editwin tw;
558  owl_viewwin vw;
559  void *perl;
560  int debug;
561  time_t starttime;
562  time_t lastinputtime;
563  char *startupargs;
564  int userclue;
565  int nextmsgid;
566  int hascolors;
567  int colorpairs;
568  owl_colorpair_mgr cpmgr;
569  int searchactive;
570  int newmsgproc_pid;
571  int malloced, freed;
572  char *searchstring;
573  aim_session_t aimsess;
574  aim_conn_t bosconn;
575  owl_timer aim_noop_timer;
576  owl_timer aim_ignorelogin_timer;
577  owl_timer aim_buddyinfo_timer;
578  int aim_loggedin;         /* true if currently logged into AIM */
579  int aim_doprocessing;     /* true if we should process AIM events (like pending login) */
580  char *aim_screenname;     /* currently logged in AIM screen name */
581  owl_buddylist buddylist;  /* list of logged in AIM buddies */
582  owl_list messagequeue;    /* for queueing up aim and other messages */
583  owl_dict styledict;       /* global dictionary of available styles */
584  char *response;           /* response to the last question asked */
585  int havezephyr;
586  int haveaim;
587  int got_err_signal;       /* 1 if we got an unexpected signal */
588  siginfo_t err_signal_info;
589  owl_zbuddylist zbuddies;
590  owl_timer zephyr_buddycheck_timer;
591  struct termios startup_tio;
592} owl_global;
593
594/* globals */
595extern owl_global g;
596
597#include "owl_prototypes.h"
598
599/* these are missing from the zephyr includes for some reason */
600#ifdef HAVE_LIBZEPHYR
601int ZGetSubscriptions(ZSubscription_t *, int *);
602int ZGetLocations(ZLocations_t *,int *);
603#endif
604
605#endif /* INC_OWL_H */
Note: See TracBrowser for help on using the repository browser.