source: owl.h @ 4211f50b

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