source: global.c @ 37d188f

Last change on this file since 37d188f was 37d188f, checked in by David Benjamin <davidben@mit.edu>, 11 years ago
Allow interrupts to be taken at any point This way we can catch SIGINT in the middle of a search if we care. (Though ideally we wouldn't block the event loop when searching like this.)
  • Property mode set to 100644
File size: 21.6 KB
Line 
1#include <stdio.h>
2#include <unistd.h>
3#include <stdlib.h>
4#include <string.h>
5#include <netdb.h>
6#include <termios.h>
7#include <sys/ioctl.h>
8#include <time.h>
9#include "owl.h"
10
11static void _owl_global_init_windows(owl_global *g);
12
13void owl_global_init(owl_global *g) {
14  char *cd;
15  const char *homedir;
16
17  g_type_init();
18  g_thread_init(NULL);
19
20  owl_select_init();
21
22  g->lines=LINES;
23  g->cols=COLS;
24  /* We shouldn't need this if we initialize lines and cols before the first
25   * owl_window_get_screen, but to be safe, we synchronize. */
26  owl_window_resize(owl_window_get_screen(), g->lines, g->cols);
27
28  g->context_stack = NULL;
29  owl_global_push_context(g, OWL_CTX_STARTUP, NULL, NULL, NULL);
30
31  g->curmsg=0;
32  g->topmsg=0;
33  g->markedmsgid=-1;
34  g->startupargs=NULL;
35
36  owl_variable_dict_setup(&(g->vars));
37
38  g->rightshift=0;
39
40  g->pw = NULL;
41  g->vw = NULL;
42  g->tw = NULL;
43
44  owl_keyhandler_init(&g->kh);
45  owl_keys_setup_keymaps(&g->kh);
46
47  owl_dict_create(&(g->filters));
48  g->filterlist = NULL;
49  owl_list_create(&(g->puntlist));
50  g->messagequeue = g_queue_new();
51  owl_dict_create(&(g->styledict));
52  g->curmsg_vert_offset=0;
53  g->resizepending=0;
54  g->direction=OWL_DIRECTION_DOWNWARDS;
55  g->zaway=0;
56  if (has_colors()) {
57    g->hascolors=1;
58  }
59  g->colorpairs=COLOR_PAIRS;
60  owl_fmtext_init_colorpair_mgr(&(g->cpmgr));
61  g->debug=OWL_DEBUG;
62  owl_regex_init(&g->search_re);
63  g->starttime=time(NULL); /* assumes we call init only a start time */
64  g->lastinputtime=g->starttime;
65  g->newmsgproc_pid=0;
66 
67  owl_global_set_config_format(g, 0);
68  owl_global_set_no_have_config(g);
69  owl_history_init(&(g->msghist));
70  owl_history_init(&(g->cmdhist));
71  owl_history_set_norepeats(&(g->cmdhist));
72  g->nextmsgid=0;
73
74  /* Fill in some variables which don't have constant defaults */
75
76  /* glib's g_get_home_dir prefers passwd entries to $HOME, so we
77   * explicitly check getenv first. */
78  homedir = getenv("HOME");
79  if (!homedir)
80    homedir = g_get_home_dir();
81  g->homedir = g_strdup(homedir);
82
83  g->confdir = NULL;
84  g->startupfile = NULL;
85  cd = g_strdup_printf("%s/%s", g->homedir, OWL_CONFIG_DIR);
86  owl_global_set_confdir(g, cd);
87  g_free(cd);
88
89  owl_messagelist_create(&(g->msglist));
90
91  _owl_global_init_windows(g);
92
93  g->aim_screenname=NULL;
94  g->aim_screenname_for_filters=NULL;
95  g->aim_loggedin=0;
96  owl_buddylist_init(&(g->buddylist));
97
98  g->havezephyr=0;
99  g->haveaim=0;
100  g->ignoreaimlogin=0;
101  owl_global_set_no_doaimevents(g);
102
103  owl_errqueue_init(&(g->errqueue));
104
105  owl_zbuddylist_create(&(g->zbuddies));
106
107  g->zaldlist = NULL;
108  g->pseudologin_notify = 0;
109
110  owl_message_init_fmtext_cache();
111  owl_list_create(&(g->io_dispatch_list));
112  owl_list_create(&(g->psa_list));
113  g->timerlist = NULL;
114  g->kill_buffer = NULL;
115
116  g->interrupt_count = 0;
117  g->interrupt_lock = g_mutex_new();
118}
119
120static void _owl_global_init_windows(owl_global *g)
121{
122  /* Create the main window */
123  owl_mainpanel_init(&(g->mainpanel));
124
125  /* Create the widgets */
126  owl_mainwin_init(&(g->mw), g->mainpanel.recwin);
127  owl_msgwin_init(&(g->msgwin), g->mainpanel.msgwin);
128  owl_sepbar_init(g->mainpanel.sepwin);
129
130  owl_window_set_default_cursor(g->mainpanel.sepwin);
131
132  /* set up a pad for input */
133  g->input_pad = newpad(1, 1);
134  nodelay(g->input_pad, 1);
135  keypad(g->input_pad, 1);
136  meta(g->input_pad, 1);
137}
138
139void owl_global_sepbar_dirty(owl_global *g)
140{
141  owl_window_dirty(g->mainpanel.sepwin);
142}
143
144/* Called once perl has been initialized */
145void owl_global_complete_setup(owl_global *g)
146{
147  owl_cmddict_setup(&(g->cmds));
148}
149
150owl_context *owl_global_get_context(const owl_global *g) {
151  if (!g->context_stack)
152    return NULL;
153  return g->context_stack->data;
154}
155
156static void owl_global_activate_context(owl_global *g, owl_context *c) {
157  if (!c)
158    return;
159
160  if (c->keymap) {
161    if (!owl_keyhandler_activate(owl_global_get_keyhandler(g), c->keymap)) {
162      owl_function_error("Unable to activate keymap '%s'", c->keymap);
163    }
164  }
165  owl_window_set_cursor(c->cursor);
166}
167
168void owl_global_push_context(owl_global *g, int mode, void *data, const char *keymap, owl_window *cursor) {
169  owl_context *c;
170  c = owl_context_new(mode, data, keymap, cursor);
171  owl_global_push_context_obj(g, c);
172}
173
174void owl_global_push_context_obj(owl_global *g, owl_context *c)
175{
176  g->context_stack = g_list_prepend(g->context_stack, c);
177  owl_global_activate_context(g, owl_global_get_context(g));
178}
179
180/* Pops the current context from the context stack and returns it. Caller is
181 * responsible for freeing. */
182owl_context *owl_global_pop_context_no_delete(owl_global *g) {
183  owl_context *c;
184  if (!g->context_stack)
185    return NULL;
186  c = owl_global_get_context(g);
187  owl_context_deactivate(c);
188  g->context_stack = g_list_delete_link(g->context_stack,
189                                        g->context_stack);
190  owl_global_activate_context(g, owl_global_get_context(g));
191  return c;
192}
193
194/* Pops the current context from the context stack and deletes it. */
195void owl_global_pop_context(owl_global *g) {
196  owl_context *c;
197  c = owl_global_pop_context_no_delete(g);
198  if (c)
199    owl_context_delete(c);
200}
201
202int owl_global_get_lines(const owl_global *g) {
203  return(g->lines);
204}
205
206int owl_global_get_cols(const owl_global *g) {
207  return(g->cols);
208}
209
210int owl_global_get_recwin_lines(const owl_global *g) {
211  return g->mainpanel.recwinlines;
212}
213
214/* curmsg */
215
216int owl_global_get_curmsg(const owl_global *g) {
217  return(g->curmsg);
218}
219
220void owl_global_set_curmsg(owl_global *g, int i) {
221  g->curmsg=i;
222  /* we will reset the vertical offset from here */
223  /* we might want to move this out to the functions later */
224  owl_global_set_curmsg_vert_offset(g, 0);
225}
226
227/* topmsg */
228
229int owl_global_get_topmsg(const owl_global *g) {
230  return(g->topmsg);
231}
232
233void owl_global_set_topmsg(owl_global *g, int i) {
234  g->topmsg=i;
235}
236
237/* markedmsgid */
238
239int owl_global_get_markedmsgid(const owl_global *g) {
240  return(g->markedmsgid);
241}
242
243void owl_global_set_markedmsgid(owl_global *g, int i) {
244  g->markedmsgid=i;
245  /* i; index of message in the current view.
246  const owl_message *m;
247  owl_view *v;
248
249  v = owl_global_get_current_view(&g);
250  m = owl_view_get_element(v, i);
251  g->markedmsgid = m ? owl_message_get_id(m) : 0;
252  */
253}
254
255/* windows */
256
257owl_mainwin *owl_global_get_mainwin(owl_global *g) {
258  return(&(g->mw));
259}
260
261owl_popwin *owl_global_get_popwin(owl_global *g) {
262  return g->pw;
263}
264
265void owl_global_set_popwin(owl_global *g, owl_popwin *pw) {
266  g->pw = pw;
267}
268
269/* msglist */
270
271owl_messagelist *owl_global_get_msglist(owl_global *g) {
272  return(&(g->msglist));
273}
274
275/* keyhandler */
276
277owl_keyhandler *owl_global_get_keyhandler(owl_global *g) {
278  return(&(g->kh));
279}
280
281/* Gets the currently active typwin out of the current context. */
282owl_editwin *owl_global_current_typwin(const owl_global *g) {
283  owl_context *ctx = owl_global_get_context(g);
284  return owl_editcontext_get_editwin(ctx);
285}
286
287/* variable dictionary */
288
289owl_vardict *owl_global_get_vardict(owl_global *g) {
290  return &(g->vars);
291}
292
293/* command dictionary */
294
295owl_cmddict *owl_global_get_cmddict(owl_global *g) {
296  return &(g->cmds);
297}
298
299/* rightshift */
300
301void owl_global_set_rightshift(owl_global *g, int i) {
302  g->rightshift = i;
303  owl_mainwin_redisplay(owl_global_get_mainwin(g));
304}
305
306int owl_global_get_rightshift(const owl_global *g) {
307  return(g->rightshift);
308}
309
310/* typwin */
311
312owl_editwin *owl_global_set_typwin_active(owl_global *g, int style, owl_history *hist) {
313  int d;
314  d = owl_global_get_typewindelta(g);
315  if (d > 0 && style == OWL_EDITWIN_STYLE_MULTILINE)
316      owl_function_resize_typwin(owl_global_get_typwin_lines(g) + d);
317
318  if (g->typwin_erase_id) {
319    g_signal_handler_disconnect(g->mainpanel.typwin, g->typwin_erase_id);
320    g->typwin_erase_id = 0;
321  }
322
323  g->tw = owl_editwin_new(g->mainpanel.typwin,
324                          owl_global_get_typwin_lines(g),
325                          g->cols,
326                          style,
327                          hist);
328  return g->tw;
329}
330
331void owl_global_deactivate_editcontext(owl_context *ctx) {
332  owl_global *g = ctx->cbdata;
333  owl_global_set_typwin_inactive(g);
334}
335
336void owl_global_set_typwin_inactive(owl_global *g) {
337  int d = owl_global_get_typewindelta(g);
338  if (d > 0 && owl_editwin_get_style(g->tw) == OWL_EDITWIN_STYLE_MULTILINE)
339      owl_function_resize_typwin(owl_global_get_typwin_lines(g) - d);
340
341  if (!g->typwin_erase_id) {
342    g->typwin_erase_id =
343      g_signal_connect(g->mainpanel.typwin, "redraw", G_CALLBACK(owl_window_erase_cb), NULL);
344  }
345  owl_window_dirty(g->mainpanel.typwin);
346
347  owl_editwin_unref(g->tw);
348  g->tw = NULL;
349}
350
351/* resize */
352
353void owl_global_set_resize_pending(owl_global *g) {
354  g->resizepending=1;
355}
356
357const char *owl_global_get_homedir(const owl_global *g) {
358  if (g->homedir) return(g->homedir);
359  return("/");
360}
361
362const char *owl_global_get_confdir(const owl_global *g) {
363  if (g->confdir) return(g->confdir);
364  return("/");
365}
366
367/*
368 * Setting this also sets startupfile to confdir/startup
369 */
370void owl_global_set_confdir(owl_global *g, const char *cd) {
371  g_free(g->confdir);
372  g->confdir = g_strdup(cd);
373  g_free(g->startupfile);
374  g->startupfile = g_strdup_printf("%s/startup", cd);
375}
376
377const char *owl_global_get_startupfile(const owl_global *g) {
378  if(g->startupfile) return(g->startupfile);
379  return("/");
380}
381
382int owl_global_get_direction(const owl_global *g) {
383  return(g->direction);
384}
385
386void owl_global_set_direction_downwards(owl_global *g) {
387  g->direction=OWL_DIRECTION_DOWNWARDS;
388}
389
390void owl_global_set_direction_upwards(owl_global *g) {
391  g->direction=OWL_DIRECTION_UPWARDS;
392}
393
394/* perl stuff */
395
396void owl_global_set_perlinterp(owl_global *g, void *p) {
397  g->perl=p;
398}
399
400void *owl_global_get_perlinterp(const owl_global *g) {
401  return(g->perl);
402}
403
404int owl_global_is_config_format(const owl_global *g) {
405  if (g->config_format) return(1);
406  return(0);
407}
408
409void owl_global_set_config_format(owl_global *g, int state) {
410  if (state==1) {
411    g->config_format=1;
412  } else {
413    g->config_format=0;
414  }
415}
416
417void owl_global_set_have_config(owl_global *g) {
418  g->haveconfig=1;
419}
420
421void owl_global_set_no_have_config(owl_global *g) {
422  g->haveconfig=0;
423}
424
425int owl_global_have_config(owl_global *g) {
426  if (g->haveconfig) return(1);
427  return(0);
428}
429
430/*
431 * Compute the size of the terminal. Try a ioctl, fallback to other stuff on
432 * fail.
433 */
434void owl_global_get_terminal_size(int *lines, int *cols) {
435  struct winsize size;
436  /* get the new size */
437  ioctl(STDIN_FILENO, TIOCGWINSZ, &size);
438  if (size.ws_row) {
439    *lines = size.ws_row;
440  } else {
441    *lines = LINES;
442  }
443
444  if (size.ws_col) {
445    *cols = size.ws_col;
446  } else {
447    *cols = COLS;
448  }
449}
450
451void owl_global_check_resize(owl_global *g) {
452  /* resize the screen.  If lines or cols is 0 use the terminal size */
453  if (!g->resizepending) return;
454  g->resizepending = 0;
455
456  owl_global_get_terminal_size(&g->lines, &g->cols);
457  owl_window_resize(owl_window_get_screen(), g->lines, g->cols);
458
459  owl_function_debugmsg("New size is %i lines, %i cols.", g->lines, g->cols);
460}
461
462/* debug */
463
464int owl_global_is_debug_fast(const owl_global *g) {
465  if (g->debug) return(1);
466  return(0);
467}
468
469/* starttime */
470
471time_t owl_global_get_starttime(const owl_global *g) {
472  return(g->starttime);
473}
474
475time_t owl_global_get_runtime(const owl_global *g) {
476  return(time(NULL)-g->starttime);
477}
478
479time_t owl_global_get_lastinputtime(const owl_global *g) {
480  return(g->lastinputtime);
481}
482
483void owl_global_set_lastinputtime(owl_global *g, time_t time) {
484  g->lastinputtime = time;
485}
486
487time_t owl_global_get_idletime(const owl_global *g) {
488  return(time(NULL)-g->lastinputtime);
489}
490
491/* viewwin */
492
493owl_viewwin *owl_global_get_viewwin(owl_global *g) {
494  return g->vw;
495}
496
497void owl_global_set_viewwin(owl_global *g, owl_viewwin *vw) {
498  g->vw = vw;
499}
500
501
502/* vert offset */
503
504int owl_global_get_curmsg_vert_offset(const owl_global *g) {
505  return(g->curmsg_vert_offset);
506}
507
508void owl_global_set_curmsg_vert_offset(owl_global *g, int i) {
509  g->curmsg_vert_offset = i;
510}
511
512/* startup args */
513
514void owl_global_set_startupargs(owl_global *g, int argc, char **argv) {
515  if (g->startupargs) g_free(g->startupargs);
516  g->startupargs = g_strjoinv(" ", argv);
517}
518
519const char *owl_global_get_startupargs(const owl_global *g) {
520  if (g->startupargs) return(g->startupargs);
521  return("");
522}
523
524/* history */
525
526owl_history *owl_global_get_msg_history(owl_global *g) {
527  return(&(g->msghist));
528}
529
530owl_history *owl_global_get_cmd_history(owl_global *g) {
531  return(&(g->cmdhist));
532}
533
534/* filterlist */
535typedef struct _owl_global_filter_ent {         /* noproto */
536  owl_global *g;
537  owl_filter *f;
538} owl_global_filter_ent;
539
540owl_filter *owl_global_get_filter(const owl_global *g, const char *name) {
541  owl_global_filter_ent *e = owl_dict_find_element(&(g->filters), name);
542  if (e) return e->f;
543  return NULL;
544}
545
546static void owl_global_delete_filter_ent(void *data)
547{
548  owl_global_filter_ent *e = data;
549  e->g->filterlist = g_list_remove(e->g->filterlist, e->f);
550  owl_filter_delete(e->f);
551  g_free(e);
552}
553
554void owl_global_add_filter(owl_global *g, owl_filter *f) {
555  owl_global_filter_ent *e = g_new(owl_global_filter_ent, 1);
556  e->g = g;
557  e->f = f;
558
559  owl_dict_insert_element(&(g->filters), owl_filter_get_name(f),
560                          e, owl_global_delete_filter_ent);
561  g->filterlist = g_list_append(g->filterlist, f);
562}
563
564void owl_global_remove_filter(owl_global *g, const char *name) {
565  owl_global_filter_ent *e = owl_dict_remove_element(&(g->filters), name);
566  if (e)
567    owl_global_delete_filter_ent(e);
568}
569
570/* nextmsgid */
571
572int owl_global_get_nextmsgid(owl_global *g) {
573  return(g->nextmsgid++);
574}
575
576/* current view */
577
578owl_view *owl_global_get_current_view(owl_global *g) {
579  return(&(g->current_view));
580}
581
582/* has colors */
583
584int owl_global_get_hascolors(const owl_global *g) {
585  if (g->hascolors) return(1);
586  return(0);
587}
588
589/* color pairs */
590
591int owl_global_get_colorpairs(const owl_global *g) {
592  return(g->colorpairs);
593}
594
595owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) {
596  return(&(g->cpmgr));
597}
598
599/* puntlist */
600
601owl_list *owl_global_get_puntlist(owl_global *g) {
602  return(&(g->puntlist));
603}
604
605int owl_global_message_is_puntable(owl_global *g, const owl_message *m) {
606  const owl_list *pl;
607  int i, j;
608
609  pl=owl_global_get_puntlist(g);
610  j=owl_list_get_size(pl);
611  for (i=0; i<j; i++) {
612    if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1);
613  }
614  return(0);
615}
616
617int owl_global_should_followlast(owl_global *g) {
618  const owl_view *v;
619 
620  if (!owl_global_is__followlast(g)) return(0);
621 
622  v=owl_global_get_current_view(g);
623 
624  if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1);
625  return(0);
626}
627
628int owl_global_is_search_active(const owl_global *g) {
629  if (owl_regex_is_set(&g->search_re)) return(1);
630  return(0);
631}
632
633void owl_global_set_search_re(owl_global *g, const owl_regex *re) {
634  if (owl_regex_is_set(&g->search_re)) {
635    owl_regex_cleanup(&g->search_re);
636    owl_regex_init(&g->search_re);
637  }
638  if (re != NULL)
639    owl_regex_copy(re, &g->search_re);
640  /* TODO: Emit a signal so we don't depend on the viewwin and mainwin */
641  if (owl_global_get_viewwin(g))
642    owl_viewwin_dirty(owl_global_get_viewwin(g));
643  owl_mainwin_redisplay(owl_global_get_mainwin(g));
644}
645
646const owl_regex *owl_global_get_search_re(const owl_global *g) {
647  return &g->search_re;
648}
649
650void owl_global_set_newmsgproc_pid(owl_global *g, pid_t i) {
651  g->newmsgproc_pid=i;
652}
653
654pid_t owl_global_get_newmsgproc_pid(const owl_global *g) {
655  return(g->newmsgproc_pid);
656}
657
658/* AIM stuff */
659
660int owl_global_is_aimloggedin(const owl_global *g)
661{
662  if (g->aim_loggedin) return(1);
663  return(0);
664}
665
666const char *owl_global_get_aim_screenname(const owl_global *g)
667{
668  if (owl_global_is_aimloggedin(g)) {
669    return (g->aim_screenname);
670  }
671  return("");
672}
673
674const char *owl_global_get_aim_screenname_for_filters(const owl_global *g)
675{
676  if (owl_global_is_aimloggedin(g)) {
677    return (g->aim_screenname_for_filters);
678  }
679  return("");
680}
681
682void owl_global_set_aimloggedin(owl_global *g, const char *screenname)
683{
684  char *sn_escaped;
685  g->aim_loggedin=1;
686  if (g->aim_screenname) g_free(g->aim_screenname);
687  if (g->aim_screenname_for_filters) g_free(g->aim_screenname_for_filters);
688  g->aim_screenname=g_strdup(screenname);
689  sn_escaped = owl_text_quote(screenname, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
690  g->aim_screenname_for_filters = owl_arg_quote(sn_escaped);
691  g_free(sn_escaped);
692}
693
694void owl_global_set_aimnologgedin(owl_global *g)
695{
696  g->aim_loggedin=0;
697}
698
699int owl_global_is_doaimevents(const owl_global *g)
700{
701  if (g->aim_doprocessing) return(1);
702  return(0);
703}
704
705void owl_global_set_doaimevents(owl_global *g)
706{
707  g->aim_doprocessing=1;
708}
709
710void owl_global_set_no_doaimevents(owl_global *g)
711{
712  g->aim_doprocessing=0;
713}
714
715aim_session_t *owl_global_get_aimsess(owl_global *g)
716{
717  return(&(g->aimsess));
718}
719
720aim_conn_t *owl_global_get_bosconn(owl_global *g)
721{
722  return(&(g->bosconn));
723}
724
725void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn)
726{
727  g->bosconn=*conn;
728}
729
730/* message queue */
731
732void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m)
733{
734  g_queue_push_tail(g->messagequeue, m);
735}
736
737/* pop off the first message and return it.  Return NULL if the queue
738 * is empty.  The caller should free the message after using it, if
739 * necessary.
740 */
741owl_message *owl_global_messagequeue_popmsg(owl_global *g)
742{
743  owl_message *out;
744
745  if (g_queue_is_empty(g->messagequeue))
746    return NULL;
747  out = g_queue_pop_head(g->messagequeue);
748  return out;
749}
750
751int owl_global_messagequeue_pending(owl_global *g)
752{
753  return !g_queue_is_empty(g->messagequeue);
754}
755
756owl_buddylist *owl_global_get_buddylist(owl_global *g)
757{
758  return(&(g->buddylist));
759}
760 
761/* style */
762
763/* Return the style with name 'name'.  If it does not exist return
764 * NULL */
765const owl_style *owl_global_get_style_by_name(const owl_global *g, const char *name)
766{
767  return owl_dict_find_element(&(g->styledict), name);
768}
769
770int owl_global_get_style_names(const owl_global *g, owl_list *l) {
771  return owl_dict_get_keys(&(g->styledict), l);
772}
773
774void owl_global_add_style(owl_global *g, owl_style *s)
775{
776  /*
777   * If we're redefining the current style, make sure to update
778   * pointers to it.
779   */
780  if(g->current_view.style
781     && !strcmp(owl_style_get_name(g->current_view.style),
782                owl_style_get_name(s)))
783    g->current_view.style = s;
784  owl_dict_insert_element(&(g->styledict), owl_style_get_name(s),
785                          s, (void (*)(void *))owl_style_delete);
786}
787
788void owl_global_set_haveaim(owl_global *g)
789{
790  g->haveaim=1;
791}
792
793int owl_global_is_haveaim(const owl_global *g)
794{
795  if (g->haveaim) return(1);
796  return(0);
797}
798
799void owl_global_set_ignore_aimlogin(owl_global *g)
800{
801    g->ignoreaimlogin = 1;
802}
803
804void owl_global_unset_ignore_aimlogin(owl_global *g)
805{
806    g->ignoreaimlogin = 0;
807}
808
809int owl_global_is_ignore_aimlogin(const owl_global *g)
810{
811    return g->ignoreaimlogin;
812}
813
814void owl_global_set_havezephyr(owl_global *g)
815{
816  g->havezephyr=1;
817}
818
819int owl_global_is_havezephyr(const owl_global *g)
820{
821  if (g->havezephyr) return(1);
822  return(0);
823}
824
825owl_errqueue *owl_global_get_errqueue(owl_global *g)
826{
827  return(&(g->errqueue));
828}
829
830owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
831{
832  return(&(g->zbuddies));
833}
834
835GList **owl_global_get_zaldlist(owl_global *g)
836{
837  return &(g->zaldlist);
838}
839
840int owl_global_get_pseudologin_notify(owl_global *g)
841{
842  return g->pseudologin_notify;
843}
844
845void owl_global_set_pseudologin_notify(owl_global *g, int notify)
846{
847  g->pseudologin_notify = notify;
848}
849
850struct termios *owl_global_get_startup_tio(owl_global *g)
851{
852  return(&(g->startup_tio));
853}
854
855owl_list *owl_global_get_io_dispatch_list(owl_global *g)
856{
857  return &(g->io_dispatch_list);
858}
859
860owl_list *owl_global_get_psa_list(owl_global *g)
861{
862  return &(g->psa_list);
863}
864
865GList **owl_global_get_timerlist(owl_global *g)
866{
867  return &(g->timerlist);
868}
869
870void owl_global_setup_default_filters(owl_global *g)
871{
872  int i;
873  static const struct {
874    const char *name;
875    const char *desc;
876  } filters[] = {
877    { "personal",
878      "isprivate ^true$ and ( not type ^zephyr$ or ( class ^message  ) )" },
879    { "trash",
880      "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )" },
881    { "wordwrap", "not ( type ^admin$ or type ^zephyr$ )" },
882    { "ping", "opcode ^ping$" },
883    { "auto", "opcode ^auto$" },
884    { "login", "not login ^none$" },
885    { "reply-lockout", "class ^noc or class ^mail$" },
886    { "out", "direction ^out$" },
887    { "aim", "type ^aim$" },
888    { "zephyr", "type ^zephyr$" },
889    { "none", "false" },
890    { "all", "true" },
891    { NULL, NULL }
892  };
893
894  owl_function_debugmsg("startup: creating default filters");
895
896  for (i = 0; filters[i].name != NULL; i++)
897    owl_global_add_filter(g, owl_filter_new_fromstring(filters[i].name,
898                                                       filters[i].desc));
899}
900
901FILE *owl_global_get_debug_file_handle(owl_global *g) {
902  static char *open_file = NULL;
903  const char *filename = owl_global_get_debug_file(g);
904  if (g->debug_file == NULL ||
905      (open_file && strcmp(filename, open_file) != 0)) {
906    char *path;
907    int fd;
908
909    if (g->debug_file)
910      fclose(g->debug_file);
911
912    g->debug_file = NULL;
913
914    path = g_strdup_printf("%s.%d", filename, getpid());
915    fd = open(path, O_CREAT|O_WRONLY|O_EXCL, 0600);
916    g_free(path);
917
918    if (fd >= 0)
919      g->debug_file = fdopen(fd, "a");
920
921    g_free(open_file);
922    open_file = g_strdup(filename);
923  }
924  return g->debug_file;
925}
926
927const char *owl_global_get_kill_buffer(owl_global *g) {
928  return g->kill_buffer;
929}
930
931void owl_global_set_kill_buffer(owl_global *g, const char *kill, int len) {
932  g_free(g->kill_buffer);
933  g->kill_buffer = g_strndup(kill, len);
934}
935
936void owl_global_add_interrupt(owl_global *g) {
937  /* TODO: This can almost certainly be done with atomic
938   * operations. Whatever. */
939  g_mutex_lock(g->interrupt_lock);
940  g->interrupt_count++;
941  g_mutex_unlock(g->interrupt_lock);
942}
943
944bool owl_global_take_interrupt(owl_global *g) {
945  bool ans = false;
946  g_mutex_lock(g->interrupt_lock);
947  if (g->interrupt_count > 0) {
948    ans = true;
949    g->interrupt_count--;
950  }
951  g_mutex_unlock(g->interrupt_lock);
952  return ans;
953}
Note: See TracBrowser for help on using the repository browser.