source: owl.h @ 83a079a

release-1.10release-1.8release-1.9
Last change on this file since 83a079a was 9923144, checked in by Anders Kaseorg <andersk@mit.edu>, 13 years ago
history: Get rid of touched and associated bug This fixes the following bug: type a partial line, up, down, type the rest of the line, up, down; oops, we’re back to the first partial line. Signed-off-by: Anders Kaseorg <andersk@mit.edu>
  • Property mode set to 100644
File size: 17.1 KB
Line 
1/*  Copyright (c) 2006-2011 The BarnOwl Developers. All rights reserved.
2 *  Copyright (c) 2004 James Kretchmar. All rights reserved.
3 *
4 *  This program is free software. You can redistribute it and/or
5 *  modify under the terms of the Sleepycat License. See the COPYING
6 *  file included with the distribution for more information.
7 */
8
9#ifndef INC_BARNOWL_OWL_H
10#define INC_BARNOWL_OWL_H
11
12#include "config.h"
13
14#include "compat/compat.h"
15
16#include <stdbool.h>
17
18#ifndef OWL_PERL
19#define NCURSES_ENABLE_STDBOOL_H 1
20#include <curses.h>
21#include <panel.h>
22#endif
23#include <sys/param.h>
24#include <EXTERN.h>
25#include <netdb.h>
26#include <regex.h>
27#include <time.h>
28#include <signal.h>
29#include <termios.h>
30#include "libfaim/aim.h"
31#include <wchar.h>
32#include "glib.h"
33#ifdef HAVE_LIBZEPHYR
34#include <zephyr/zephyr.h>
35#endif
36#ifdef HAVE_COM_ERR_H
37#include <com_err.h>
38#endif
39
40/* Perl and curses don't play nice. */
41#ifdef OWL_PERL
42typedef void WINDOW;
43typedef void PANEL;
44/* logout is defined in FreeBSD. */
45#define logout logout_
46#define HAS_BOOL
47#include <perl.h>
48#include "owl_perl.h"
49#undef logout
50#include "XSUB.h"
51#else
52typedef void SV;
53typedef void AV;
54typedef void HV;
55#endif
56
57#include "window.h"
58
59#ifndef OWL_VERSION_STRING
60#ifdef  GIT_VERSION
61#define stringify(x)       __stringify(x)
62#define __stringify(x)     #x
63#define OWL_VERSION_STRING stringify(GIT_VERSION)
64#else
65#define OWL_VERSION_STRING PACKAGE_VERSION
66#endif
67#endif /* !OWL_VERSION_STRING */
68
69/* Feature that is being tested to redirect stderr through a pipe.
70 * There may still be some portability problems with this. */
71#define OWL_STDERR_REDIR 1
72
73#define OWL_DEBUG 0
74#define OWL_DEBUG_FILE "/var/tmp/barnowl-debug"
75
76#define OWL_CONFIG_DIR "/.owl"             /* this is relative to the user's home directory */
77#define OWL_STARTUP_FILE "/.owl/startup"   /* this is relative to the user's home directory */
78
79#define OWL_FMTEXT_ATTR_NONE      0
80#define OWL_FMTEXT_ATTR_BOLD      1
81#define OWL_FMTEXT_ATTR_REVERSE   2
82#define OWL_FMTEXT_ATTR_UNDERLINE 4
83
84#define OWL_FMTEXT_UC_BASE 0x100000 /* Unicode Plane 16 - Supplementary Private Use Area-B*/
85#define OWL_FMTEXT_UC_ATTR ( OWL_FMTEXT_UC_BASE | 0x800 )
86#define OWL_FMTEXT_UC_ATTR_MASK 0x7
87#define OWL_FMTEXT_UC_COLOR_BASE ( OWL_FMTEXT_UC_BASE | 0x400 )
88#define OWL_FMTEXT_UC_FGCOLOR OWL_FMTEXT_UC_COLOR_BASE
89#define OWL_FMTEXT_UC_BGCOLOR ( OWL_FMTEXT_UC_COLOR_BASE | 0x200 )
90#define OWL_FMTEXT_UC_DEFAULT_COLOR 0x100
91#define OWL_FMTEXT_UC_FGDEFAULT ( OWL_FMTEXT_UC_FGCOLOR | OWL_FMTEXT_UC_DEFAULT_COLOR )
92#define OWL_FMTEXT_UC_BGDEFAULT ( OWL_FMTEXT_UC_BGCOLOR | OWL_FMTEXT_UC_DEFAULT_COLOR )
93#define OWL_FMTEXT_UC_COLOR_MASK 0xFF
94#define OWL_FMTEXT_UC_ALLCOLOR_MASK ( OWL_FMTEXT_UC_COLOR_MASK | OWL_FMTEXT_UC_DEFAULT_COLOR | 0x200)
95#define OWL_FMTEXT_UC_STARTBYTE_UTF8 '\xf4'
96
97#define OWL_COLOR_BLACK     0
98#define OWL_COLOR_RED       1
99#define OWL_COLOR_GREEN     2
100#define OWL_COLOR_YELLOW    3
101#define OWL_COLOR_BLUE      4
102#define OWL_COLOR_MAGENTA   5
103#define OWL_COLOR_CYAN      6
104#define OWL_COLOR_WHITE     7
105#define OWL_COLOR_DEFAULT   -1
106#define OWL_COLOR_INVALID   -2
107
108#define OWL_TAB_WIDTH 8
109
110#define OWL_EDITWIN_STYLE_MULTILINE 0
111#define OWL_EDITWIN_STYLE_ONELINE   1
112
113#define OWL_PROTOCOL_ZEPHYR         0
114#define OWL_PROTOCOL_AIM            1
115#define OWL_PROTOCOL_JABBER         2
116#define OWL_PROTOCOL_ICQ            3
117#define OWL_PROTOCOL_YAHOO          4
118#define OWL_PROTOCOL_MSN            5
119
120#define OWL_MESSAGE_DIRECTION_NONE  0
121#define OWL_MESSAGE_DIRECTION_IN    1
122#define OWL_MESSAGE_DIRECTION_OUT   2
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_TAB               3  /* This *HAS* to be the size of TABSTR below */
140#define OWL_TABSTR        "   "
141#define OWL_MSGTAB            7
142#define OWL_TYPWIN_SIZE       8
143#define OWL_HISTORYSIZE       50
144
145/* Indicate current state, as well as what is allowed */
146#define OWL_CTX_ANY          0xffff
147/* Only one of these may be active at a time... */
148#define OWL_CTX_MODE_BITS    0x000f
149#define OWL_CTX_STARTUP      0x0001
150#define OWL_CTX_READCONFIG   0x0002
151#define OWL_CTX_INTERACTIVE  0x0004
152/* Only one of these may be active at a time... */
153#define OWL_CTX_ACTIVE_BITS  0xfff0
154#define OWL_CTX_POPWIN       0x00f0
155#define OWL_CTX_POPLESS      0x0010
156#define OWL_CTX_RECWIN       0x0f00
157#define OWL_CTX_RECV         0x0100
158#define OWL_CTX_TYPWIN       0xf000
159#define OWL_CTX_EDIT         0x7000
160#define OWL_CTX_EDITLINE     0x1000
161#define OWL_CTX_EDITMULTI    0x2000
162#define OWL_CTX_EDITRESPONSE 0x4000
163
164#define OWL_VARIABLE_OTHER      0
165#define OWL_VARIABLE_INT        1
166#define OWL_VARIABLE_BOOL       2
167#define OWL_VARIABLE_STRING     3
168
169#define OWL_OUTPUT_RETURN       0
170#define OWL_OUTPUT_POPUP        1
171#define OWL_OUTPUT_ADMINMSG     2
172
173#define OWL_FILTER_MAX_DEPTH    300
174
175#define OWL_KEYMAP_MAXSTACK     20
176
177#define OWL_KEYBINDING_NOOP     0   /* dummy binding that does nothing */
178#define OWL_KEYBINDING_COMMAND  1   /* command string */
179#define OWL_KEYBINDING_FUNCTION 2   /* function taking no args */
180
181#define OWL_DEFAULT_ZAWAYMSG    "I'm sorry, but I am currently away from the terminal and am\nnot able to receive your message.\n"
182#define OWL_DEFAULT_AAWAYMSG    "I'm sorry, but I am currently away from the terminal and am\nnot able to receive your message.\n"
183
184#define OWL_CMD_ALIAS_SUMMARY_PREFIX "command alias to: "
185
186#define OWL_WEBZEPHYR_PRINCIPAL "daemon/webzephyr.mit.edu"
187#define OWL_WEBZEPHYR_CLASS     "webzephyr"
188#define OWL_WEBZEPHYR_OPCODE    "webzephyr"
189
190#define OWL_ZEPHYR_NOSTRIP_HOST         "host/"
191#define OWL_ZEPHYR_NOSTRIP_RCMD         "rcmd."
192#define OWL_ZEPHYR_NOSTRIP_DAEMON5      "daemon/"
193#define OWL_ZEPHYR_NOSTRIP_DAEMON4      "daemon."
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)|010000)
203/* OWL_CTRL is definied in kepress.c */
204
205#define LINE 2048
206
207#ifdef HAVE_LIBZEPHYR
208/* libzephyr doesn't use const, so we appease the type system with this kludge.
209 * This just casts const char * to char * in a way that doesn't yield a warning
210 * from gcc -Wcast-qual. */
211static inline char *zstr(const char *str)
212{
213  union { char *rw; const char *ro; } u;
214  u.ro = str;
215  return u.rw;
216}
217#endif
218
219/* Convert char *const * into const char *const *.  This conversion is safe,
220 * and implicit in C++ (conv.qual 4) but for some reason not in C. */
221static inline const char *const *strs(char *const *pstr)
222{
223  return (const char *const *)pstr;
224}
225
226typedef struct _owl_variable {
227  char *name;
228  int   type;  /* OWL_VARIABLE_* */
229  void *pval_default;  /* for types other and string */
230  int   ival_default;  /* for types int and bool     */
231  const char *validsettings;    /* documentation of valid settings */
232  char *summary;                /* summary of usage */
233  char *description;            /* detailed description */
234  void *val;                    /* current value */
235  int  (*validate_fn)(const struct _owl_variable *v, const void *newval);
236                                /* returns 1 if newval is valid */
237  int  (*set_fn)(struct _owl_variable *v, const void *newval); 
238                                /* sets the variable to a value
239                                 * of the appropriate type.
240                                 * unless documented, this
241                                 * should make a copy.
242                                 * returns 0 on success. */
243  int  (*set_fromstring_fn)(struct _owl_variable *v, const char *newval);
244                                /* sets the variable to a value
245                                 * of the appropriate type.
246                                 * unless documented, this
247                                 * should make a copy.
248                                 * returns 0 on success. */
249  const void *(*get_fn)(const struct _owl_variable *v);
250                                /* returns a reference to the current value.
251                                 * WARNING:  this approach is hard to make
252                                 * thread-safe... */
253  char G_GNUC_WARN_UNUSED_RESULT *(*get_tostring_fn)(const struct _owl_variable *v, const void *val);
254                                /* converts val to a string;
255                                 * caller must free the result */
256  void (*delete_fn)(struct _owl_variable *v);
257                                /* frees val as needed */
258} owl_variable;
259
260typedef struct _owl_input {
261  int ch;
262  gunichar uch;
263} owl_input;
264
265typedef struct _owl_fmtext {
266  GString *buff;
267} owl_fmtext;
268
269typedef struct _owl_list {
270  int size;
271  int avail;
272  void **list;
273} owl_list;
274
275typedef struct _owl_dict_el {
276  char *k;                      /* key   */
277  void *v;                      /* value */
278} owl_dict_el;
279
280typedef struct _owl_dict {
281  int size;
282  int avail;
283  owl_dict_el *els;             /* invariant: sorted by k */
284} owl_dict;
285typedef owl_dict owl_vardict;   /* dict of variables */
286typedef owl_dict owl_cmddict;   /* dict of commands */
287
288typedef struct _owl_context {
289  int   mode;
290  void *data;           /* determined by mode */
291  char *keymap;
292  owl_window *cursor;
293  void (*deactivate_cb)(struct _owl_context*);
294  void (*delete_cb)(struct _owl_context*);
295  void *cbdata;
296} owl_context;
297
298typedef struct _owl_cmd {       /* command */
299  char *name;
300
301  char *summary;                /* one line summary of command */
302  char *usage;                  /* usage synopsis */
303  char *description;            /* long description of command */
304
305  int validctx;                 /* bitmask of valid contexts */
306
307  /* we should probably have a type here that says which of
308   * the following is valid, and maybe make the below into a union... */
309
310  /* Only one of these may be non-NULL ... */
311
312  char *cmd_aliased_to;         /* what this command is aliased to... */
313 
314  /* These don't take any context */
315  char G_GNUC_WARN_UNUSED_RESULT *(*cmd_args_fn)(int argc, const char *const *argv, const char *buff);
316                                /* takes argv and the full command as buff.
317                                 * caller must free return value if !NULL */
318  void (*cmd_v_fn)(void);       /* takes no args */
319  void (*cmd_i_fn)(int i);      /* takes an int as an arg */
320
321  /* The following also take the active context if it's valid */
322  char G_GNUC_WARN_UNUSED_RESULT *(*cmd_ctxargs_fn)(void *ctx, int argc, const char *const *argv, const char *buff);
323                                /* takes argv and the full command as buff.
324                                 * caller must free return value if !NULL */
325  void (*cmd_ctxv_fn)(void *ctx);               /* takes no args */
326  void (*cmd_ctxi_fn)(void *ctx, int i);        /* takes an int as an arg */
327  SV *cmd_perl;                                /* Perl closure that takes a list of args */
328} owl_cmd;
329
330
331typedef struct _owl_zwrite {
332  char *cmd;
333  char *zwriteline;
334  char *class;
335  char *inst;
336  char *realm;
337  char *opcode;
338  char *zsig;
339  char *message;
340  owl_list recips;
341  int cc;
342  int noping;
343} owl_zwrite;
344
345typedef struct _owl_pair {
346  const char *key;
347  char *value;
348} owl_pair;
349
350struct _owl_fmtext_cache;
351
352typedef struct _owl_message {
353  int id;
354  int direction;
355#ifdef HAVE_LIBZEPHYR
356  ZNotice_t notice;
357#endif
358  struct _owl_fmtext_cache * fmtext;
359  int delete;
360  const char *hostname;
361  owl_list attributes;            /* this is a list of pairs */
362  char *timestr;
363  time_t time;
364} owl_message;
365
366#define OWL_FMTEXT_CACHE_SIZE 1000
367/* We cache the saved fmtexts for the last bunch of messages we
368   rendered */
369typedef struct _owl_fmtext_cache {
370    owl_message * message;
371    owl_fmtext fmtext;
372} owl_fmtext_cache;
373
374typedef struct _owl_style {
375  char *name;
376  SV *perlobj;
377} owl_style;
378
379typedef struct _owl_mainwin {
380  int curtruncated;
381  int lasttruncated;
382  int lastdisplayed;
383  owl_window *window;
384} owl_mainwin;
385
386typedef struct _owl_editwin owl_editwin;
387typedef struct _owl_editwin_excursion owl_editwin_excursion;
388
389typedef struct _owl_viewwin {
390  owl_fmtext fmtext;
391  int textlines;
392  int topline;
393  int rightshift;
394  owl_window *window;
395  void (*onclose_hook) (struct _owl_viewwin *vwin, void *data);
396  void *onclose_hook_data;
397
398  gulong sig_resize_id;
399  owl_window *content;
400  gulong sig_content_redraw_id;
401  owl_window *status;
402  gulong sig_status_redraw_id;
403  owl_window *cmdwin;
404} owl_viewwin;
405 
406typedef struct _owl_popwin {
407  owl_window *border;
408  owl_window *content;
409  gulong sig_redraw_id;
410  gulong sig_resize_id;
411} owl_popwin;
412 
413typedef struct _owl_msgwin {
414  char *msg;
415  owl_window *window;
416  gulong redraw_id;
417} owl_msgwin;
418
419typedef struct _owl_messagelist {
420  owl_list list;
421} owl_messagelist;
422
423typedef struct _owl_regex {
424  int negate;
425  char *string;
426  regex_t re;
427} owl_regex;
428
429typedef struct _owl_filterelement {
430  int (*match_message)(const struct _owl_filterelement *fe, const owl_message *m);
431  /* Append a string representation of the filterelement onto buf*/
432  void (*print_elt)(const struct _owl_filterelement *fe, GString *buf);
433  /* Operands for and,or,not*/
434  struct _owl_filterelement *left, *right;
435  /* For regex filters*/
436  owl_regex re;
437  /* Used by regexes, filter references, and perl */
438  char *field;
439} owl_filterelement;
440
441typedef struct _owl_filter {
442  char *name;
443  owl_filterelement * root;
444  int fgcolor;
445  int bgcolor;
446} owl_filter;
447
448typedef struct _owl_view {
449  char *name;
450  owl_filter *filter;
451  owl_messagelist ml;
452  const owl_style *style;
453  int cachedmsgid;
454} owl_view;
455
456typedef struct _owl_history {
457  owl_list hist;
458  int cur;
459  int partial;
460} owl_history;
461
462typedef struct _owl_mainpanel {
463  owl_window *panel;
464  owl_window *typwin;
465  owl_window *sepwin;
466  owl_window *msgwin;
467  owl_window *recwin;
468  int recwinlines;
469} owl_mainpanel;
470
471typedef struct _owl_keybinding {
472  int  *keys;                   /* keypress stack */
473  int   len;                    /* length of stack */
474  int   type;                   /* command or function? */
475  char *desc;                   /* description (or "*user*") */
476  char *command;                /* command, if of type command */
477  void (*function_fn)(void);    /* function ptr, if of type function */
478} owl_keybinding;
479
480typedef struct _owl_keymap {
481  char     *name;               /* name of keymap */
482  char     *desc;               /* description */
483  owl_list  bindings;           /* key bindings */
484  const struct _owl_keymap *parent;     /* parent */
485  void (*default_fn)(owl_input j);      /* default action (takes a keypress) */
486  void (*prealways_fn)(owl_input  j);   /* always called before a keypress is received */
487  void (*postalways_fn)(owl_input  j);  /* always called after keypress is processed */
488} owl_keymap;
489
490typedef struct _owl_keyhandler {
491  owl_dict  keymaps;            /* dictionary of keymaps */
492  const owl_keymap *active;             /* currently active keymap */
493  int       in_esc;             /* escape pressed? */
494  int       kpstack[OWL_KEYMAP_MAXSTACK+1]; /* current stack of keypresses */
495  int       kpstackpos;         /* location in stack (-1 = none) */
496} owl_keyhandler;
497
498typedef struct _owl_buddy {
499  int proto;
500  char *name;
501  int isidle;
502  int idlesince;
503} owl_buddy;
504
505typedef struct _owl_buddylist {
506  owl_list buddies;
507} owl_buddylist;
508
509typedef struct _owl_zbuddylist {
510  owl_list zusers;
511} owl_zbuddylist;
512
513typedef struct _owl_errqueue {
514  owl_list errlist;
515} owl_errqueue;
516
517typedef struct _owl_colorpair_mgr {
518  int next;
519  short **pairs;
520  bool overflow;
521} owl_colorpair_mgr;
522
523typedef struct _owl_popexec {
524  int refcount;
525  owl_viewwin *vwin;
526  int winactive;
527  pid_t pid;                    /* or 0 if it has terminated */
528  guint io_watch;
529} owl_popexec;
530
531typedef struct _owl_global {
532  owl_mainwin mw;
533  owl_popwin *pw;
534  owl_msgwin msgwin;
535  owl_history cmdhist;          /* command history */
536  owl_history msghist;          /* outgoing message history */
537  owl_keyhandler kh;
538  owl_dict filters;
539  GList *filterlist;
540  owl_list puntlist;
541  owl_vardict vars;
542  owl_cmddict cmds;
543  GList *context_stack;
544  owl_errqueue errqueue;
545  int lines, cols;
546  int curmsg, topmsg;
547  int markedmsgid;              /* for finding the marked message when it has moved. */
548  int curmsg_vert_offset;
549  owl_view current_view;
550  owl_messagelist msglist;
551  WINDOW *input_pad;
552  owl_mainpanel mainpanel;
553  gulong typwin_erase_id;
554  int rightshift;
555  bool resizepending;
556  char *homedir;
557  char *confdir;
558  char *startupfile;
559  int direction;
560  int zaway;
561  char *cur_zaway_msg;
562  int haveconfig;
563  int config_format;
564  owl_editwin *tw;
565  owl_viewwin *vw;
566  void *perl;
567  int debug;
568  time_t starttime;
569  time_t lastinputtime;
570  char *startupargs;
571  int nextmsgid;
572  owl_colorpair_mgr cpmgr;
573  pid_t newmsgproc_pid;
574  owl_regex search_re;
575  aim_session_t aimsess;
576  aim_conn_t bosconn;
577  int aim_loggedin;         /* true if currently logged into AIM */
578  GSource *aim_event_source; /* where we get our AIM events from */
579  char *aim_screenname;     /* currently logged in AIM screen name */
580  char *aim_screenname_for_filters;     /* currently logged in AIM screen name */
581  owl_buddylist buddylist;  /* list of logged in AIM buddies */
582  GQueue *messagequeue;     /* for queueing up aim and other messages */
583  owl_dict styledict;       /* global dictionary of available styles */
584  char *response;           /* response to the last question asked */
585  int havezephyr;
586  int haveaim;
587  int ignoreaimlogin;
588  owl_zbuddylist zbuddies;
589  GList *zaldlist;
590  int pseudologin_notify;
591  struct termios startup_tio;
592  guint aim_nop_timer;
593  int load_initial_subs;
594  FILE *debug_file;
595  char *kill_buffer;
596  int interrupt_count;
597  GMutex *interrupt_lock;
598} owl_global;
599
600/* globals */
601extern owl_global g;
602
603#include "owl_prototypes.h"
604
605/* These were missing from the Zephyr includes before Zephyr 3. */
606#if defined HAVE_LIBZEPHYR && defined ZCONST
607int ZGetSubscriptions(ZSubscription_t *, int *);
608int ZGetLocations(ZLocations_t *,int *);
609#endif
610
611#endif /* INC_BARNOWL_OWL_H */
Note: See TracBrowser for help on using the repository browser.