source: owl.h @ 2401376

barnowl_perlaimdebianrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 2401376 was 2401376, checked in by Nelson Elhage <nelhage@mit.edu>, 16 years ago
1.0.0!
  • 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.0"
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
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_MUX_READ   1
118#define OWL_MUX_WRITE  2
119#define OWL_MUX_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_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)|010000)
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_input {
242  int ch;
243  gunichar uch;
244} owl_input;
245
246typedef struct _owl_fmtext {
247  int textlen;
248  int bufflen;
249  char *textbuff;
250  char default_attrs;
251  short default_fgcolor;
252  short default_bgcolor;
253} owl_fmtext;
254
255typedef struct _owl_list {
256  int size;
257  int avail;
258  void **list;
259} owl_list;
260
261typedef struct _owl_dict_el {
262  char *k;                      /* key   */
263  void *v;                      /* value */
264} owl_dict_el;
265
266typedef struct _owl_dict {
267  int size;
268  int avail;
269  owl_dict_el *els;             /* invariant: sorted by k */
270} owl_dict;
271typedef owl_dict owl_vardict;   /* dict of variables */
272typedef owl_dict owl_cmddict;   /* dict of commands */
273
274typedef struct _owl_context {
275  int   mode;
276  void *data;           /* determined by mode */
277} owl_context;
278
279typedef struct _owl_cmd {       /* command */
280  char *name;
281
282  char *summary;                /* one line summary of command */
283  char *usage;                  /* usage synopsis */
284  char *description;            /* long description of command */
285
286  int validctx;                 /* bitmask of valid contexts */
287
288  /* we should probably have a type here that says which of
289   * the following is valid, and maybe make the below into a union... */
290
291  /* Only one of these may be non-NULL ... */
292
293  char *cmd_aliased_to;         /* what this command is aliased to... */
294 
295  /* These don't take any context */
296  char *(*cmd_args_fn)(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_v_fn)(void);       /* takes no args */
300  void (*cmd_i_fn)(int i);      /* takes an int as an arg */
301
302  /* The following also take the active context if it's valid */
303  char *(*cmd_ctxargs_fn)(void *ctx, int argc, char **argv, char *buff); 
304                                /* takes argv and the full command as buff.
305                                 * caller must free return value if !NULL */
306  void (*cmd_ctxv_fn)(void *ctx);               /* takes no args */
307  void (*cmd_ctxi_fn)(void *ctx, int i);        /* takes an int as an arg */
308  SV *cmd_perl;                                /* Perl closure that takes a list of args */
309} owl_cmd;
310
311
312typedef struct _owl_zwrite {
313  char *class;
314  char *inst;
315  char *realm;
316  char *opcode;
317  char *zsig;
318  char *message;
319  owl_list recips;
320  int cc;
321  int noping;
322} owl_zwrite;
323
324typedef struct _owl_pair {
325  void *key;
326  void *value;
327} owl_pair;
328
329struct _owl_fmtext_cache;
330
331typedef struct _owl_message {
332  int id;
333  int direction;
334#ifdef HAVE_LIBZEPHYR
335  ZNotice_t notice;
336#endif
337  struct _owl_fmtext_cache * fmtext;
338  int delete;
339  char *hostname;
340  owl_list attributes;            /* this is a list of pairs */
341  char *timestr;
342  time_t time;
343  char *zwriteline;
344} owl_message;
345
346#define OWL_FMTEXT_CACHE_SIZE 1000
347/* We cache the saved fmtexts for the last bunch of messages we
348   rendered */
349typedef struct _owl_fmtext_cache {
350    owl_message * message;
351    owl_fmtext fmtext;
352} owl_fmtext_cache;
353
354typedef struct _owl_style {
355  char *name;
356  SV *perlobj;
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)(owl_input j);      /* default action (takes a keypress) */
483  void (*prealways_fn)(owl_input  j);   /* always called before a keypress is received */
484  void (*postalways_fn)(owl_input  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  int next;
522  short **pairs;
523} owl_colorpair_mgr;
524
525typedef struct _owl_obarray {
526  owl_list strings;
527} owl_obarray;
528
529typedef struct _owl_dispatch {
530  int fd;           /* FD to watch for dispatch. */
531  void (*cfunc)();  /* C function to dispatch to. */
532  SV *pfunc;        /* Perl function to dispatch to. */
533} owl_dispatch;
534
535typedef struct _owl_global {
536  owl_mainwin mw;
537  owl_popwin pw;
538  owl_history cmdhist;          /* command history */
539  owl_history msghist;          /* outgoing message history */
540  owl_keyhandler kh;
541  owl_list filterlist;
542  owl_list puntlist;
543  owl_muxevents muxevents;      /* fds to dispatch on */
544  owl_vardict vars;
545  owl_cmddict cmds;
546  owl_context ctx;
547  owl_errqueue errqueue;
548  int lines, cols;
549  int curmsg, topmsg;
550  int curmsg_vert_offset;
551  owl_view current_view;
552  owl_messagelist msglist;
553  WINDOW *recwin, *sepwin, *msgwin, *typwin;
554  int needrefresh;
555  int rightshift;
556  int resizepending;
557  int recwinlines;
558  int typwinactive;
559  char *thishost;
560  char *homedir;
561  char *confdir;
562  char *startupfile;
563  int direction;
564  int zaway;
565  char *cur_zaway_msg;
566  int haveconfig;
567  int config_format;
568  void *buffercbdata;
569  owl_editwin tw;
570  owl_viewwin vw;
571  void *perl;
572  int debug;
573  time_t starttime;
574  time_t lastinputtime;
575  char *startupargs;
576  int userclue;
577  int nextmsgid;
578  int hascolors;
579  int colorpairs;
580  owl_colorpair_mgr cpmgr;
581  int searchactive;
582  int newmsgproc_pid;
583  int malloced, freed;
584  char *searchstring;
585  aim_session_t aimsess;
586  aim_conn_t bosconn;
587  owl_timer aim_noop_timer;
588  owl_timer aim_ignorelogin_timer;
589  owl_timer aim_buddyinfo_timer;
590  int aim_loggedin;         /* true if currently logged into AIM */
591  int aim_doprocessing;     /* true if we should process AIM events (like pending login) */
592  char *aim_screenname;     /* currently logged in AIM screen name */
593  char *aim_screenname_for_filters;     /* currently logged in AIM screen name */
594  owl_buddylist buddylist;  /* list of logged in AIM buddies */
595  owl_list messagequeue;    /* for queueing up aim and other messages */
596  owl_dict styledict;       /* global dictionary of available styles */
597  char *response;           /* response to the last question asked */
598  int havezephyr;
599  int haveaim;
600  int got_err_signal;       /* 1 if we got an unexpected signal */
601  siginfo_t err_signal_info;
602  owl_zbuddylist zbuddies;
603  owl_timer zephyr_buddycheck_timer;
604  struct termios startup_tio;
605  owl_obarray obarray;
606  owl_list dispatchlist;
607} owl_global;
608
609/* globals */
610extern owl_global g;
611
612#include "owl_prototypes.h"
613
614/* these are missing from the zephyr includes for some reason */
615#ifdef HAVE_LIBZEPHYR
616int ZGetSubscriptions(ZSubscription_t *, int *);
617int ZGetLocations(ZLocations_t *,int *);
618#endif
619
620#endif /* INC_OWL_H */
Note: See TracBrowser for help on using the repository browser.