source: global.c @ 7dfe886

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