source: owl.h @ 81001c0

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