source: owl.h @ 1971b59

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