source: global.c @ 2c79eae

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