source: global.c @ b343c2c

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