source: global.c @ 8ee712e0

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