source: owl.h @ 34509d5

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