source: owl.h @ 124aebc

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