source: owl.h @ 120291c

barnowl_perlaimdebianrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 120291c was 120291c, checked in by Nelson Elhage <nelhage@mit.edu>, 16 years ago
Clone owl_perl from the sqlite branch because I'm about to make use of it.
  • Property mode set to 100644
File size: 17.6 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/* logout is defined in FreeBSD. */
66#define logout logout_
67/* aim.h defines bool */
68#define HAS_BOOL
69#include <perl.h>
70#include "owl_perl.h"
71#undef logout
72#include "XSUB.h"
73#else
74typedef void SV;
75#endif
76
77static const char owl_h_fileIdent[] = "$Id$";
78
79#define BARNOWL_STRINGIFY(x) _STRINGIFY(x)
80#define _STRINGIFY(x) #x
81
82#ifndef OWL_SVN_REVNO
83#define OWL_SVN_REVNO ????
84#endif
85
86#define OWL_VERSION_STRING "r" BARNOWL_STRINGIFY(OWL_SVN_REVNO)
87
88
89/* Feature that is being tested to redirect stderr through a pipe.
90 * There may still be some portability problems with this. */
91#define OWL_STDERR_REDIR 1
92
93#define OWL_DEBUG 0
94#define OWL_DEBUG_FILE "/var/tmp/owldebug"
95
96#define OWL_CONFIG_DIR "/.owl"             /* this is relative to the user's home directory */
97#define OWL_STARTUP_FILE "/.owl/startup"   /* this is relative to the user's home directory */
98
99#define OWL_FMTEXT_ATTR_NONE      0
100#define OWL_FMTEXT_ATTR_BOLD      1
101#define OWL_FMTEXT_ATTR_REVERSE   2
102#define OWL_FMTEXT_ATTR_UNDERLINE 4
103
104#define OWL_COLOR_BLACK     0
105#define OWL_COLOR_RED       1
106#define OWL_COLOR_GREEN     2
107#define OWL_COLOR_YELLOW    3
108#define OWL_COLOR_BLUE      4
109#define OWL_COLOR_MAGENTA   5
110#define OWL_COLOR_CYAN      6
111#define OWL_COLOR_WHITE     7
112#define OWL_COLOR_DEFAULT   -1
113
114#define OWL_EDITWIN_STYLE_MULTILINE 0
115#define OWL_EDITWIN_STYLE_ONELINE   1
116
117#define OWL_PROTOCOL_ZEPHYR         0
118#define OWL_PROTOCOL_AIM            1
119#define OWL_PROTOCOL_JABBER         2
120#define OWL_PROTOCOL_ICQ            3
121#define OWL_PROTOCOL_YAHOO          4
122#define OWL_PROTOCOL_MSN            5
123
124#define OWL_MESSAGE_DIRECTION_NONE  0
125#define OWL_MESSAGE_DIRECTION_IN    1
126#define OWL_MESSAGE_DIRECTION_OUT   2
127
128#define OWL_MUX_READ   1
129#define OWL_MUX_WRITE  2
130#define OWL_MUX_EXCEPT 4
131
132#define OWL_DIRECTION_NONE      0
133#define OWL_DIRECTION_DOWNWARDS 1
134#define OWL_DIRECTION_UPWARDS   2
135
136#define OWL_LOGGING_DIRECTION_BOTH 0
137#define OWL_LOGGING_DIRECTION_IN   1
138#define OWL_LOGGING_DIRECTION_OUT  2
139
140#define OWL_SCROLLMODE_NORMAL      0
141#define OWL_SCROLLMODE_TOP         1
142#define OWL_SCROLLMODE_NEARTOP     2
143#define OWL_SCROLLMODE_CENTER      3
144#define OWL_SCROLLMODE_PAGED       4
145#define OWL_SCROLLMODE_PAGEDCENTER 5
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  int bufflen;
255  char *textbuff;
256  char *fmbuff;
257  short *fgcolorbuff;
258  short *bgcolorbuff;
259} owl_fmtext;
260
261typedef struct _owl_list {
262  int size;
263  int avail;
264  void **list;
265} owl_list;
266
267typedef struct _owl_dict_el {
268  char *k;                      /* key   */
269  void *v;                      /* value */
270} owl_dict_el;
271
272typedef struct _owl_dict {
273  int size;
274  int avail;
275  owl_dict_el *els;             /* invariant: sorted by k */
276} owl_dict;
277typedef owl_dict owl_vardict;   /* dict of variables */
278typedef owl_dict owl_cmddict;   /* dict of commands */
279
280typedef struct _owl_context {
281  int   mode;
282  void *data;           /* determined by mode */
283} owl_context;
284
285typedef struct _owl_cmd {       /* command */
286  char *name;
287
288  char *summary;                /* one line summary of command */
289  char *usage;                  /* usage synopsis */
290  char *description;            /* long description of command */
291
292  int validctx;                 /* bitmask of valid contexts */
293
294  /* we should probably have a type here that says which of
295   * the following is valid, and maybe make the below into a union... */
296
297  /* Only one of these may be non-NULL ... */
298
299  char *cmd_aliased_to;         /* what this command is aliased to... */
300 
301  /* These don't take any context */
302  char *(*cmd_args_fn)(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_v_fn)(void);       /* takes no args */
306  void (*cmd_i_fn)(int i);      /* takes an int as an arg */
307
308  /* The following also take the active context if it's valid */
309  char *(*cmd_ctxargs_fn)(void *ctx, int argc, char **argv, char *buff); 
310                                /* takes argv and the full command as buff.
311                                 * caller must free return value if !NULL */
312  void (*cmd_ctxv_fn)(void *ctx);               /* takes no args */
313  void (*cmd_ctxi_fn)(void *ctx, int i);        /* takes an int as an arg */
314  SV *cmd_perl;                                /* Perl closure that takes a list of args */
315} owl_cmd;
316
317
318typedef struct _owl_zwrite {
319  char *class;
320  char *inst;
321  char *realm;
322  char *opcode;
323  char *zsig;
324  char *message;
325  owl_list recips;
326  int cc;
327  int noping;
328} owl_zwrite;
329
330typedef struct _owl_pair {
331  void *key;
332  void *value;
333} owl_pair;
334
335struct _owl_fmtext_cache;
336
337typedef struct _owl_message {
338  int id;
339  int direction;
340#ifdef HAVE_LIBZEPHYR
341  ZNotice_t notice;
342#endif
343  struct _owl_fmtext_cache * fmtext;
344  int delete;
345  char *hostname;
346  owl_list attributes;            /* this is a list of pairs */
347  char *timestr;
348  time_t time;
349  char *zwriteline;
350} owl_message;
351
352#define OWL_FMTEXT_CACHE_SIZE 1000
353/* We cache the saved fmtexts for the last bunch of messages we
354   rendered */
355typedef struct _owl_fmtext_cache {
356    owl_message * message;
357    owl_fmtext fmtext;
358} owl_fmtext_cache;
359
360typedef struct _owl_style {
361  char *name;
362  SV *perlobj;
363} owl_style;
364
365typedef struct _owl_mainwin {
366  int curtruncated;
367  int lasttruncated;
368  int lastdisplayed;
369} owl_mainwin;
370
371typedef struct _owl_viewwin {
372  owl_fmtext fmtext;
373  int textlines;
374  int topline;
375  int rightshift;
376  int winlines, wincols;
377  WINDOW *curswin;
378  void (*onclose_hook) (struct _owl_viewwin *vwin, void *data);
379  void *onclose_hook_data;
380} owl_viewwin;
381 
382typedef struct _owl_popwin {
383  WINDOW *borderwin;
384  WINDOW *popwin;
385  int lines;
386  int cols;
387  int active;
388  int needsfirstrefresh;
389  void (*handler) (int ch);
390} owl_popwin;
391
392typedef struct _owl_popexec {
393  int refcount;
394  owl_viewwin *vwin;
395  int winactive;
396  int pid;                      /* or 0 if it has terminated */
397  int rfd; 
398} owl_popexec;
399
400typedef struct _owl_messagelist {
401  owl_list list;
402} owl_messagelist;
403
404typedef struct _owl_regex {
405  int negate;
406  char *string;
407  regex_t re;
408} owl_regex;
409
410typedef struct _owl_filterelement {
411  int (*match_message)(struct _owl_filterelement *fe, owl_message *m);
412  /* Append a string representation of the filterelement onto buf*/
413  void (*print_elt)(struct _owl_filterelement *fe, char * buf);
414  /* Operands for and,or,not*/
415  struct _owl_filterelement *left, *right;
416  /* For regex filters*/
417  owl_regex re;
418  /* Used by regexes, filter references, and perl */
419  char *field;
420} owl_filterelement;
421
422typedef struct _owl_filter {
423  char *name;
424  int polarity;
425  owl_filterelement * root;
426  int fgcolor;
427  int bgcolor;
428  int cachedmsgid;  /* cached msgid: should move into view eventually */
429} owl_filter;
430
431typedef struct _owl_view {
432  char *name;
433  owl_filter *filter;
434  owl_messagelist ml;
435  owl_style *style;
436} owl_view;
437
438typedef struct _owl_history {
439  owl_list hist;
440  int cur;
441  int touched;
442  int partial;
443  int repeats;
444} owl_history;
445
446typedef struct _owl_editwin {
447  char *buff;
448  owl_history *hist;
449  int bufflen;
450  int allocated;
451  int buffx, buffy;
452  int topline;
453  int winlines, wincols, fillcol, wrapcol;
454  WINDOW *curswin;
455  int style;
456  int lock;
457  int dotsend;
458  int echochar;
459
460  char *command;
461  void (*callback)(struct _owl_editwin*);
462  void *cbdata;
463} owl_editwin;
464
465typedef struct _owl_mux {
466  int handle;                   /* for referencing this */
467  int active;                   /* has this been deleted? */
468  int fd;                     
469  int eventmask;                /* bitmask of OWL_MUX_* */
470  void (*handler_fn)(int handle, int fd, int eventmask, void *data);
471  void *data;                   /* data reference to pass to callback */
472} owl_mux;
473typedef owl_list owl_muxevents;
474
475typedef struct _owl_keybinding {
476  int  *j;                      /* keypress stack (0-terminated) */ 
477  int   type;                   /* command or function? */
478  char *desc;                   /* description (or "*user*") */
479  char *command;                /* command, if of type command */
480  void (*function_fn)(void);    /* function ptr, if of type function */
481} owl_keybinding;
482
483typedef struct _owl_keymap {
484  char     *name;               /* name of keymap */
485  char     *desc;               /* description */
486  owl_list  bindings;           /* key bindings */
487  struct _owl_keymap *submap;   /* submap */
488  void (*default_fn)(int j);    /* default action (takes a keypress) */
489  void (*prealways_fn)(int j);  /* always called before a keypress is received */
490  void (*postalways_fn)(int j); /* always called after keypress is processed */
491} owl_keymap;
492
493typedef struct _owl_keyhandler {
494  owl_dict  keymaps;            /* dictionary of keymaps */
495  owl_keymap *active;           /* currently active keymap */
496  int       in_esc;             /* escape pressed? */
497  int       kpstack[OWL_KEYMAP_MAXSTACK+1]; /* current stack of keypresses */
498  int       kpstackpos;         /* location in stack (-1 = none) */
499} owl_keyhandler;
500
501typedef struct _owl_buddy {
502  int proto;
503  char *name;
504  int isidle;
505  int idlesince;
506} owl_buddy;
507
508typedef struct _owl_buddylist {
509  owl_list buddies;
510} owl_buddylist;
511
512typedef struct _owl_zbuddylist {
513  owl_list zusers;
514} owl_zbuddylist;
515
516typedef struct _owl_timer {
517  int direction;
518  time_t starttime;
519  int start;
520} owl_timer;
521
522typedef struct _owl_errqueue {
523  owl_list errlist;
524} owl_errqueue;
525
526typedef struct _owl_colorpair_mgr {
527  int next;
528  short **pairs;
529} owl_colorpair_mgr;
530
531typedef struct _owl_obarray {
532  owl_list strings;
533} owl_obarray;
534
535typedef struct _owl_dispatch {
536  int fd;           /* FD to watch for dispatch. */
537  void (*cfunc)();  /* C function to dispatch to. */
538  SV *pfunc;        /* Perl function to dispatch to. */
539} owl_dispatch;
540
541typedef struct _owl_global {
542  owl_mainwin mw;
543  owl_popwin pw;
544  owl_history cmdhist;          /* command history */
545  owl_history msghist;          /* outgoing message history */
546  owl_keyhandler kh;
547  owl_list filterlist;
548  owl_list puntlist;
549  owl_muxevents muxevents;      /* fds to dispatch on */
550  owl_vardict vars;
551  owl_cmddict cmds;
552  owl_context ctx;
553  owl_errqueue errqueue;
554  int lines, cols;
555  int curmsg, topmsg;
556  int curmsg_vert_offset;
557  owl_view current_view;
558  owl_messagelist msglist;
559  WINDOW *recwin, *sepwin, *msgwin, *typwin;
560  int needrefresh;
561  int rightshift;
562  int resizepending;
563  int recwinlines;
564  int typwinactive;
565  char *thishost;
566  char *homedir;
567  char *confdir;
568  char *startupfile;
569  int direction;
570  int zaway;
571  char *cur_zaway_msg;
572  int haveconfig;
573  int config_format;
574  void *buffercbdata;
575  owl_editwin tw;
576  owl_viewwin vw;
577  void *perl;
578  int debug;
579  time_t starttime;
580  time_t lastinputtime;
581  char *startupargs;
582  int userclue;
583  int nextmsgid;
584  int hascolors;
585  int colorpairs;
586  owl_colorpair_mgr cpmgr;
587  int searchactive;
588  int newmsgproc_pid;
589  int malloced, freed;
590  char *searchstring;
591  aim_session_t aimsess;
592  aim_conn_t bosconn;
593  owl_timer aim_noop_timer;
594  owl_timer aim_ignorelogin_timer;
595  owl_timer aim_buddyinfo_timer;
596  int aim_loggedin;         /* true if currently logged into AIM */
597  int aim_doprocessing;     /* true if we should process AIM events (like pending login) */
598  char *aim_screenname;     /* currently logged in AIM screen name */
599  owl_buddylist buddylist;  /* list of logged in AIM buddies */
600  owl_list messagequeue;    /* for queueing up aim and other messages */
601  owl_dict styledict;       /* global dictionary of available styles */
602  char *response;           /* response to the last question asked */
603  int havezephyr;
604  int haveaim;
605  int got_err_signal;       /* 1 if we got an unexpected signal */
606  siginfo_t err_signal_info;
607  owl_zbuddylist zbuddies;
608  owl_timer zephyr_buddycheck_timer;
609  struct termios startup_tio;
610  owl_obarray obarray;
611  owl_list dispatchlist;
612} owl_global;
613
614/* globals */
615extern owl_global g;
616
617#include "owl_prototypes.h"
618
619/* these are missing from the zephyr includes for some reason */
620#ifdef HAVE_LIBZEPHYR
621int ZGetSubscriptions(ZSubscription_t *, int *);
622int ZGetLocations(ZLocations_t *,int *);
623#endif
624
625#endif /* INC_OWL_H */
Note: See TracBrowser for help on using the repository browser.