source: global.c @ 8eb6068

Last change on this file since 8eb6068 was 0af5f9d, checked in by David Benjamin <davidben@mit.edu>, 13 years ago
Add a GSource for AIM events This is somewhat less of a hack now.
  • Property mode set to 100644
File size: 21.8 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
699bool owl_global_is_doaimevents(const owl_global *g)
700{
701  return g->aim_event_source != NULL;
702}
703
704void owl_global_set_doaimevents(owl_global *g)
705{
706  if (g->aim_event_source)
707    return;
708  g->aim_event_source = owl_aim_event_source_new(owl_global_get_aimsess(g));
709  g_source_attach(g->aim_event_source, NULL);
710}
711
712void owl_global_set_no_doaimevents(owl_global *g)
713{
714  if (!g->aim_event_source)
715    return;
716  g_source_destroy(g->aim_event_source);
717  g_source_unref(g->aim_event_source);
718  g->aim_event_source = NULL;
719}
720
721aim_session_t *owl_global_get_aimsess(owl_global *g)
722{
723  return(&(g->aimsess));
724}
725
726aim_conn_t *owl_global_get_bosconn(owl_global *g)
727{
728  return(&(g->bosconn));
729}
730
731void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn)
732{
733  g->bosconn=*conn;
734}
735
736/* message queue */
737
738void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m)
739{
740  g_queue_push_tail(g->messagequeue, m);
741}
742
743/* pop off the first message and return it.  Return NULL if the queue
744 * is empty.  The caller should free the message after using it, if
745 * necessary.
746 */
747owl_message *owl_global_messagequeue_popmsg(owl_global *g)
748{
749  owl_message *out;
750
751  if (g_queue_is_empty(g->messagequeue))
752    return NULL;
753  out = g_queue_pop_head(g->messagequeue);
754  return out;
755}
756
757int owl_global_messagequeue_pending(owl_global *g)
758{
759  return !g_queue_is_empty(g->messagequeue);
760}
761
762owl_buddylist *owl_global_get_buddylist(owl_global *g)
763{
764  return(&(g->buddylist));
765}
766 
767/* style */
768
769/* Return the style with name 'name'.  If it does not exist return
770 * NULL */
771const owl_style *owl_global_get_style_by_name(const owl_global *g, const char *name)
772{
773  return owl_dict_find_element(&(g->styledict), name);
774}
775
776int owl_global_get_style_names(const owl_global *g, owl_list *l) {
777  return owl_dict_get_keys(&(g->styledict), l);
778}
779
780void owl_global_add_style(owl_global *g, owl_style *s)
781{
782  /*
783   * If we're redefining the current style, make sure to update
784   * pointers to it.
785   */
786  if(g->current_view.style
787     && !strcmp(owl_style_get_name(g->current_view.style),
788                owl_style_get_name(s)))
789    g->current_view.style = s;
790  owl_dict_insert_element(&(g->styledict), owl_style_get_name(s),
791                          s, (void (*)(void *))owl_style_delete);
792}
793
794void owl_global_set_haveaim(owl_global *g)
795{
796  g->haveaim=1;
797}
798
799int owl_global_is_haveaim(const owl_global *g)
800{
801  if (g->haveaim) return(1);
802  return(0);
803}
804
805void owl_global_set_ignore_aimlogin(owl_global *g)
806{
807    g->ignoreaimlogin = 1;
808}
809
810void owl_global_unset_ignore_aimlogin(owl_global *g)
811{
812    g->ignoreaimlogin = 0;
813}
814
815int owl_global_is_ignore_aimlogin(const owl_global *g)
816{
817    return g->ignoreaimlogin;
818}
819
820void owl_global_set_havezephyr(owl_global *g)
821{
822  g->havezephyr=1;
823}
824
825int owl_global_is_havezephyr(const owl_global *g)
826{
827  if (g->havezephyr) return(1);
828  return(0);
829}
830
831owl_errqueue *owl_global_get_errqueue(owl_global *g)
832{
833  return(&(g->errqueue));
834}
835
836owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
837{
838  return(&(g->zbuddies));
839}
840
841GList **owl_global_get_zaldlist(owl_global *g)
842{
843  return &(g->zaldlist);
844}
845
846int owl_global_get_pseudologin_notify(owl_global *g)
847{
848  return g->pseudologin_notify;
849}
850
851void owl_global_set_pseudologin_notify(owl_global *g, int notify)
852{
853  g->pseudologin_notify = notify;
854}
855
856struct termios *owl_global_get_startup_tio(owl_global *g)
857{
858  return(&(g->startup_tio));
859}
860
861owl_list *owl_global_get_io_dispatch_list(owl_global *g)
862{
863  return &(g->io_dispatch_list);
864}
865
866owl_list *owl_global_get_psa_list(owl_global *g)
867{
868  return &(g->psa_list);
869}
870
871GList **owl_global_get_timerlist(owl_global *g)
872{
873  return &(g->timerlist);
874}
875
876void owl_global_setup_default_filters(owl_global *g)
877{
878  int i;
879  static const struct {
880    const char *name;
881    const char *desc;
882  } filters[] = {
883    { "personal",
884      "isprivate ^true$ and ( not type ^zephyr$ or ( class ^message  ) )" },
885    { "trash",
886      "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )" },
887    { "wordwrap", "not ( type ^admin$ or type ^zephyr$ )" },
888    { "ping", "opcode ^ping$" },
889    { "auto", "opcode ^auto$" },
890    { "login", "not login ^none$" },
891    { "reply-lockout", "class ^noc or class ^mail$" },
892    { "out", "direction ^out$" },
893    { "aim", "type ^aim$" },
894    { "zephyr", "type ^zephyr$" },
895    { "none", "false" },
896    { "all", "true" },
897    { NULL, NULL }
898  };
899
900  owl_function_debugmsg("startup: creating default filters");
901
902  for (i = 0; filters[i].name != NULL; i++)
903    owl_global_add_filter(g, owl_filter_new_fromstring(filters[i].name,
904                                                       filters[i].desc));
905}
906
907FILE *owl_global_get_debug_file_handle(owl_global *g) {
908  static char *open_file = NULL;
909  const char *filename = owl_global_get_debug_file(g);
910  if (g->debug_file == NULL ||
911      (open_file && strcmp(filename, open_file) != 0)) {
912    char *path;
913    int fd;
914
915    if (g->debug_file)
916      fclose(g->debug_file);
917
918    g->debug_file = NULL;
919
920    path = g_strdup_printf("%s.%d", filename, getpid());
921    fd = open(path, O_CREAT|O_WRONLY|O_EXCL, 0600);
922    g_free(path);
923
924    if (fd >= 0)
925      g->debug_file = fdopen(fd, "a");
926
927    g_free(open_file);
928    open_file = g_strdup(filename);
929  }
930  return g->debug_file;
931}
932
933const char *owl_global_get_kill_buffer(owl_global *g) {
934  return g->kill_buffer;
935}
936
937void owl_global_set_kill_buffer(owl_global *g, const char *kill, int len) {
938  g_free(g->kill_buffer);
939  g->kill_buffer = g_strndup(kill, len);
940}
941
942void owl_global_add_interrupt(owl_global *g) {
943  /* TODO: This can almost certainly be done with atomic
944   * operations. Whatever. */
945  g_mutex_lock(g->interrupt_lock);
946  g->interrupt_count++;
947  g_mutex_unlock(g->interrupt_lock);
948}
949
950bool owl_global_take_interrupt(owl_global *g) {
951  bool ans = false;
952  g_mutex_lock(g->interrupt_lock);
953  if (g->interrupt_count > 0) {
954    ans = true;
955    g->interrupt_count--;
956  }
957  g_mutex_unlock(g->interrupt_lock);
958  return ans;
959}
Note: See TracBrowser for help on using the repository browser.