source: owl.h @ 731dd1e

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