source: global.c @ dab82f29

owl
Last change on this file since dab82f29 was dab82f29, checked in by James M. Kretchmar <kretch@mit.edu>, 16 years ago
Don't crash on mobile device AIM messages [BZ 20] Don't crash when sending to someone not on AIM buddy list [BZ 94] Fix overflow vulerability in zwrite.c and zcrypt.c Add stack protector and -D_FORTIFY_SOURCE=2 where possible Fix hang [barnowl 4c46dfdebc294ca24fef59924f01688b8ee07dee] Fix segfault on missing subs [barnowl 99dabeed7de6d19acb50f1e73aa0bfe5f9469c02] Fix zcrypt bufffer size bug [barnowl 559076cd86edc3a8317819814dd5877b8bc7c3cb] Fix double free [barnowl e97c4a306ae2c9d2147d83da29fee59918198e70] Memory leak fix [barnowl c0a90c2c7ab97b9465c9873757faf312faa0021e] Memory leak fix [barnowl 95caa16b2e9ba10770d87d0955198c14c2d0e16a] Memory leak fix [barnowl 1716fed8c2650e46892cf6571555eac937266c6e] Add getstyle command [barnowl 216c73421653e3ef0e957aa9a9804e208a77c80e] Binary search for msgid [barnowl 0c8ab5eadbb6ecc97a120c91b9a824b33538c764] File-handle leak [barnowl e78397d6ac5da0de31a4e269c0ba7f3d691857a3] Fix delay in jump from top to bottom [barnowl 801b7ac63b962640debbcfd422cb9a60da5fea31] Load subs in chunks [barnowl 93e883d60051b80bf6d35391f9d76fd7dfd198e3] Load subs in chunks [barnowl f6050ee9b0a171a5031f84409eb181062afacd18] Better zsig logging [barnowl d857b667a5a9b108b1a2a26b4a5513bef2b53f80] free() -> owlfree() [barnowl d524c838ac7c115628424b8ac171c3489622ea3a] Escape AIM users in smartfilters [barnowl af9b92e3e7ccb7de276a94b5c7e5861b24e71eff] Better regex escape chars [barnowl 80e54a7631f091be8c9762adb9746bad38104738] Deal with quotes in smart filters [barnowl 4099cf83702763fa8d1efc4f1582a605431bdb77] Deal with 0 length zephyr fields [barnowl 128171aaf7cefa91a4bb1eada93a19d8fd0c355c] Deal with 0 length zephyr fields [barnowl 50e29e35c64d64e223d378d350a7bc4f038d78f5] Deal with 0 length zephyr fields [barnowl 804ab8af8b6d00bcd7e2402df892db8fbd61a3ec] Leave curmsg on screen after resize [barnowl c0f9e3009bc03e80a44de64cd5f2b4033290236e] Rip out brower stuff [barnowl 8e5935d11c699a7ce5a3e6e9a47799564c696d6a] Rip out browser stuff [barnowl 4f15e8e9ceada0d4b2cc969ebf43b0a1fb3709ea] No passwords in command history [barnowl 6e400cc71aa59e041dce677aadf50dc1f25228e2] Format NOC mssages [barnowl a1bb1980e4bca23b8329cc0e7c0bd5027055ea0a] Expand ~ in loadsubs [barnowl 27d8d835dc6d58c08fae10e75aae306c49215143] Expand ~ in source [barnowl 10d67d57cb29221f63a43a30643c697fc7b38911] Only use resizeterm() if it's available Debian backports Change license to GPLv3
  • Property mode set to 100644
File size: 19.4 KB
Line 
1/* Copyright (c) 2002,2003,2004,2009 James M. Kretchmar
2 *
3 * This file is part of Owl.
4 *
5 * Owl is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * Owl is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with Owl.  If not, see <http://www.gnu.org/licenses/>.
17 *
18 * ---------------------------------------------------------------
19 *
20 * As of Owl version 2.1.12 there are patches contributed by
21 * developers of the the branched BarnOwl project, Copyright (c)
22 * 2006-2008 The BarnOwl Developers. All rights reserved.
23 */
24
25#include <stdio.h>
26#include <unistd.h>
27#include <stdlib.h>
28#include <string.h>
29#include <netdb.h>
30#include <termios.h>
31#include <sys/ioctl.h>
32#include <time.h>
33#include "owl.h"
34
35static const char fileIdent[] = "$Id$";
36
37#ifndef MAXHOSTNAMELEN
38#define MAXHOSTNAMELEN 256
39#endif
40
41void owl_global_init(owl_global *g) {
42  struct hostent *hent;
43  char hostname[MAXHOSTNAMELEN];
44
45  g->malloced=0;
46  g->freed=0;
47
48  gethostname(hostname, MAXHOSTNAMELEN);
49  hent=gethostbyname(hostname);
50  if (!hent) {
51    g->thishost=owl_strdup("localhost");
52  } else {
53    g->thishost=owl_strdup(hent->h_name);
54  }
55
56  owl_context_init(&g->ctx);
57  owl_context_set_startup(&g->ctx);
58  g->curmsg=0;
59  g->topmsg=0;
60  g->needrefresh=1;
61  g->startupargs=NULL;
62
63  owl_variable_dict_setup(&(g->vars));
64  owl_cmddict_setup(&(g->cmds));
65
66  g->lines=LINES;
67  g->cols=COLS;
68
69  g->rightshift=0;
70
71  owl_editwin_init(&(g->tw), NULL, owl_global_get_typwin_lines(g), g->cols, OWL_EDITWIN_STYLE_ONELINE, NULL);
72
73  owl_keyhandler_init(&g->kh);
74  owl_keys_setup_keymaps(&g->kh);
75
76  owl_list_create(&(g->filterlist));
77  owl_list_create(&(g->puntlist));
78  owl_list_create(&(g->messagequeue));
79  owl_dict_create(&(g->styledict));
80  g->curmsg_vert_offset=0;
81  g->resizepending=0;
82  g->typwinactive=0;
83  g->direction=OWL_DIRECTION_DOWNWARDS;
84  g->zaway=0;
85  if (has_colors()) {
86    g->hascolors=1;
87  }
88  g->colorpairs=COLOR_PAIRS;
89  g->debug=OWL_DEBUG;
90  g->searchactive=0;
91  g->searchstring=NULL;
92  g->starttime=time(NULL); /* assumes we call init only a start time */
93  g->buffercommand=NULL;
94  g->newmsgproc_pid=0;
95 
96  owl_global_set_config_format(g, 0);
97  owl_global_set_userclue(g, OWL_USERCLUE_NONE);
98  owl_global_set_no_have_config(g);
99  owl_history_init(&(g->msghist));
100  owl_history_init(&(g->cmdhist));
101  owl_history_set_norepeats(&(g->cmdhist));
102  g->nextmsgid=0;
103
104  owl_filterelement_create_true(&(g->fe_true));
105  owl_filterelement_create_false(&(g->fe_false));
106  owl_filterelement_create_null(&(g->fe_null));
107
108  _owl_global_setup_windows(g);
109
110  /* Fill in some variables which don't have constant defaults */
111  /* TODO: come back later and check passwd file first */
112  g->homedir=owl_strdup(getenv("HOME"));
113
114  owl_messagelist_create(&(g->msglist));
115  owl_mainwin_init(&(g->mw));
116  owl_popwin_init(&(g->pw));
117
118  g->aim_screenname=NULL;
119  g->aim_loggedin=0;
120  owl_timer_create_countdown(&(g->aim_noop_timer), 30);
121  owl_timer_create_countdown(&(g->aim_ignorelogin_timer), 0);
122  owl_timer_create_countdown(&(g->aim_buddyinfo_timer), 60);
123  owl_buddylist_init(&(g->buddylist));
124   
125  g->response=NULL;
126  g->havezephyr=0;
127  g->haveaim=0;
128  owl_global_set_no_doaimevents(g);
129
130  owl_errqueue_init(&(g->errqueue));
131  g->got_err_signal=0;
132
133  owl_zbuddylist_create(&(g->zbuddies));
134  owl_timer_create_countdown(&(g->zephyr_buddycheck_timer), 60*3);
135
136  owl_list_create(&(g->dispatchlist));
137}
138
139void _owl_global_setup_windows(owl_global *g) {
140  int cols, typwin_lines;
141
142  cols=g->cols;
143  typwin_lines=owl_global_get_typwin_lines(g);
144
145  /* set the new window sizes */
146  g->recwinlines=g->lines-(typwin_lines+2);
147  if (g->recwinlines<0) {
148    /* gotta deal with this */
149    g->recwinlines=0;
150  }
151
152  owl_function_debugmsg("_owl_global_setup_windows: about to call newwin(%i, %i, 0, 0)\n", g->recwinlines, cols);
153
154  /* create the new windows */
155  g->recwin=newwin(g->recwinlines, cols, 0, 0);
156  if (g->recwin==NULL) {
157    owl_function_debugmsg("_owl_global_setup_windows: newwin returned NULL\n", g->recwinlines, cols);
158    endwin();
159    exit(50);
160  }
161     
162  g->sepwin=newwin(1, cols, g->recwinlines, 0);
163  g->msgwin=newwin(1, cols, g->recwinlines+1, 0);
164  g->typwin=newwin(typwin_lines, cols, g->recwinlines+2, 0);
165
166  owl_editwin_set_curswin(&(g->tw), g->typwin, typwin_lines, g->cols);
167
168  idlok(g->typwin, FALSE);
169  idlok(g->recwin, FALSE);
170  idlok(g->sepwin, FALSE);
171  idlok(g->msgwin, FALSE);
172
173  nodelay(g->typwin, 1);
174  keypad(g->typwin, TRUE);
175  wmove(g->typwin, 0, 0);
176
177  meta(g->typwin, TRUE);
178}
179
180owl_context *owl_global_get_context(owl_global *g) {
181  return(&g->ctx);
182}
183                         
184int owl_global_get_lines(owl_global *g) {
185  return(g->lines);
186}
187
188int owl_global_get_cols(owl_global *g) {
189  return(g->cols);
190}
191
192int owl_global_get_recwin_lines(owl_global *g) {
193  return(g->recwinlines);
194}
195
196/* curmsg */
197
198int owl_global_get_curmsg(owl_global *g) {
199  return(g->curmsg);
200}
201
202void owl_global_set_curmsg(owl_global *g, int i) {
203  g->curmsg=i;
204  /* we will reset the vertical offset from here */
205  /* we might want to move this out to the functions later */
206  owl_global_set_curmsg_vert_offset(g, 0);
207}
208
209/* topmsg */
210
211int owl_global_get_topmsg(owl_global *g) {
212  return(g->topmsg);
213}
214
215void owl_global_set_topmsg(owl_global *g, int i) {
216  g->topmsg=i;
217}
218
219/* windows */
220
221owl_mainwin *owl_global_get_mainwin(owl_global *g) {
222  return(&(g->mw));
223}
224
225owl_popwin *owl_global_get_popwin(owl_global *g) {
226  return(&(g->pw));
227}
228
229/* msglist */
230
231owl_messagelist *owl_global_get_msglist(owl_global *g) {
232  return(&(g->msglist));
233}
234
235/* keyhandler */
236
237owl_keyhandler *owl_global_get_keyhandler(owl_global *g) {
238  return(&(g->kh));
239}
240
241/* curses windows */
242
243WINDOW *owl_global_get_curs_recwin(owl_global *g) {
244  return(g->recwin);
245}
246
247WINDOW *owl_global_get_curs_sepwin(owl_global *g) {
248  return(g->sepwin);
249}
250
251WINDOW *owl_global_get_curs_msgwin(owl_global *g) {
252  return(g->msgwin);
253}
254
255WINDOW *owl_global_get_curs_typwin(owl_global *g) {
256  return(g->typwin);
257}
258
259/* typwin */
260
261owl_editwin *owl_global_get_typwin(owl_global *g) {
262  return(&(g->tw));
263}
264
265/* buffercommand */
266
267void owl_global_set_buffercommand(owl_global *g, char *command) {
268  if (g->buffercommand) owl_free(g->buffercommand);
269  g->buffercommand=owl_strdup(command);
270}
271
272char *owl_global_get_buffercommand(owl_global *g) {
273  if (g->buffercommand) return(g->buffercommand);
274  return("");
275}
276
277/* refresh */
278
279int owl_global_is_needrefresh(owl_global *g) {
280  if (g->needrefresh==1) return(1);
281  return(0);
282}
283
284void owl_global_set_needrefresh(owl_global *g) {
285  g->needrefresh=1;
286}
287
288void owl_global_set_noneedrefresh(owl_global *g) {
289  g->needrefresh=0;
290}
291
292/* variable dictionary */
293
294owl_vardict *owl_global_get_vardict(owl_global *g) {
295  return &(g->vars);
296}
297
298/* command dictionary */
299
300owl_cmddict *owl_global_get_cmddict(owl_global *g) {
301  return &(g->cmds);
302}
303
304/* rightshift */
305
306void owl_global_set_rightshift(owl_global *g, int i) {
307  g->rightshift=i;
308}
309
310int owl_global_get_rightshift(owl_global *g) {
311  return(g->rightshift);
312}
313
314/* typwin */
315
316int owl_global_is_typwin_active(owl_global *g) {
317  if (g->typwinactive==1) return(1);
318  return(0);
319}
320
321void owl_global_set_typwin_active(owl_global *g) {
322  g->typwinactive=1;
323}
324
325void owl_global_set_typwin_inactive(owl_global *g) {
326  g->typwinactive=0;
327}
328
329/* resize */
330
331void owl_global_set_resize_pending(owl_global *g) {
332  g->resizepending=1;
333}
334
335char *owl_global_get_homedir(owl_global *g) {
336  if (g->homedir) return(g->homedir);
337  return("/");
338}
339
340int owl_global_get_direction(owl_global *g) {
341  return(g->direction);
342}
343
344void owl_global_set_direction_downwards(owl_global *g) {
345  g->direction=OWL_DIRECTION_DOWNWARDS;
346}
347
348void owl_global_set_direction_upwards(owl_global *g) {
349  g->direction=OWL_DIRECTION_UPWARDS;
350}
351
352/* perl stuff */
353
354void owl_global_set_perlinterp(owl_global *g, void *p) {
355  g->perl=p;
356}
357
358void *owl_global_get_perlinterp(owl_global *g) {
359  return(g->perl);
360}
361
362int owl_global_is_config_format(owl_global *g) {
363  if (g->config_format) return(1);
364  return(0);
365}
366
367void owl_global_set_config_format(owl_global *g, int state) {
368  if (state==1) {
369    g->config_format=1;
370  } else {
371    g->config_format=0;
372  }
373}
374
375void owl_global_set_have_config(owl_global *g) {
376  g->haveconfig=1;
377}
378
379void owl_global_set_no_have_config(owl_global *g) {
380  g->haveconfig=0;
381}
382
383int owl_global_have_config(owl_global *g) {
384  if (g->haveconfig) return(1);
385  return(0);
386}
387
388void owl_global_resize(owl_global *g, int x, int y) {
389  /* resize the screen.  If x or y is 0 use the terminal size */
390  struct winsize size;
391   
392  if (!g->resizepending) return;
393
394  /* delete the current windows */
395  delwin(g->recwin);
396  delwin(g->sepwin);
397  delwin(g->msgwin);
398  delwin(g->typwin);
399  if (!isendwin()) {
400    endwin();
401  }
402
403  refresh();
404
405  /* get the new size */
406  ioctl(STDIN_FILENO, TIOCGWINSZ, &size);
407  if (x==0) {
408    g->lines=size.ws_row;
409  } else {
410    g->lines=x;
411  }
412
413  if (y==0) {
414    g->cols=size.ws_col;
415  } else {
416    g->cols=y;
417  }
418
419#ifdef HAVE_RESIZETERM
420  resizeterm(size.ws_row, size.ws_col);
421#endif
422
423  /* re-initialize the windows */
424  _owl_global_setup_windows(g);
425
426  /* in case any styles rely on the current width */
427  owl_messagelist_invalidate_formats(owl_global_get_msglist(g));
428
429  /* recalculate the topmsg to make sure the current message is on
430   * screen */
431  owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
432
433  /* refresh stuff */
434  g->needrefresh=1;
435  owl_mainwin_redisplay(&(g->mw));
436  sepbar(NULL);
437
438  if (owl_global_is_typwin_active(g)) {
439    owl_editwin_redisplay(&(g->tw), 0);
440  }     
441  /* TODO: this should handle other forms of popwins */
442  if (owl_popwin_is_active(owl_global_get_popwin(g)) 
443      && owl_global_get_viewwin(g)) {
444    owl_popwin_refresh(owl_global_get_popwin(g));
445    owl_viewwin_redisplay(owl_global_get_viewwin(g), 0);
446  }
447
448  owl_function_debugmsg("New size is %i lines, %i cols.", size.ws_row, size.ws_col);
449  owl_function_makemsg("");
450  g->resizepending=0;
451}
452
453/* debug */
454
455int owl_global_is_debug_fast(owl_global *g) {
456  if (g->debug) return(1);
457  return(0);
458}
459
460/* starttime */
461
462time_t owl_global_get_starttime(owl_global *g) {
463  return(g->starttime);
464}
465
466time_t owl_global_get_runtime(owl_global *g) {
467  return(time(NULL)-g->starttime);
468}
469
470void owl_global_get_runtime_string(owl_global *g, char *buff) {
471  time_t diff;
472
473  diff=time(NULL)-owl_global_get_starttime(g);
474
475  /* print something nicer later */   
476  sprintf(buff, "%i seconds", (int) diff);
477}
478
479char *owl_global_get_hostname(owl_global *g) {
480  if (g->thishost) return(g->thishost);
481  return("");
482}
483
484/* userclue */
485
486void owl_global_set_userclue(owl_global *g, int clue) {
487  g->userclue=clue;
488}
489
490void owl_global_add_userclue(owl_global *g, int clue) {
491  g->userclue|=clue;
492}
493
494int owl_global_get_userclue(owl_global *g) {
495  return(g->userclue);
496}
497
498int owl_global_is_userclue(owl_global *g, int clue) {
499  if (g->userclue & clue) return(1);
500  return(0);
501}
502
503/* viewwin */
504
505owl_viewwin *owl_global_get_viewwin(owl_global *g) {
506  return(&(g->vw));
507}
508
509
510/* vert offset */
511
512int owl_global_get_curmsg_vert_offset(owl_global *g) {
513  return(g->curmsg_vert_offset);
514}
515
516void owl_global_set_curmsg_vert_offset(owl_global *g, int i) {
517  g->curmsg_vert_offset=i;
518}
519
520/* startup args */
521
522void owl_global_set_startupargs(owl_global *g, int argc, char **argv) {
523  int i, len;
524
525  if (g->startupargs) owl_free(g->startupargs);
526 
527  len=0;
528  for (i=0; i<argc; i++) {
529    len+=strlen(argv[i])+5;
530  }
531  g->startupargs=malloc(len+5);
532
533  strcpy(g->startupargs, "");
534  for (i=0; i<argc; i++) {
535    sprintf(g->startupargs, "%s%s ", g->startupargs, argv[i]);
536  }
537  g->startupargs[strlen(g->startupargs)-1]='\0';
538}
539
540char *owl_global_get_startupargs(owl_global *g) {
541  if (g->startupargs) return(g->startupargs);
542  return("");
543}
544
545/* history */
546
547owl_history *owl_global_get_msg_history(owl_global *g) {
548  return(&(g->msghist));
549}
550
551owl_history *owl_global_get_cmd_history(owl_global *g) {
552  return(&(g->cmdhist));
553}
554
555/* filterlist */
556
557owl_list *owl_global_get_filterlist(owl_global *g) {
558  return(&(g->filterlist));
559}
560
561owl_filter *owl_global_get_filter(owl_global *g, char *name) {
562  int i, j;
563  owl_filter *f;
564
565  j=owl_list_get_size(&(g->filterlist));
566  for (i=0; i<j; i++) {
567    f=owl_list_get_element(&(g->filterlist), i);
568    if (!strcmp(name, owl_filter_get_name(f))) {
569      return(f);
570    }
571  }
572  return(NULL);
573}
574
575void owl_global_add_filter(owl_global *g, owl_filter *f) {
576  owl_list_append_element(&(g->filterlist), f);
577}
578
579void owl_global_remove_filter(owl_global *g, char *name) {
580  int i, j;
581  owl_filter *f;
582
583  j=owl_list_get_size(&(g->filterlist));
584  for (i=0; i<j; i++) {
585    f=owl_list_get_element(&(g->filterlist), i);
586    if (!strcmp(name, owl_filter_get_name(f))) {
587      owl_filter_free(f);
588      owl_list_remove_element(&(g->filterlist), i);
589      break;
590    }
591  }
592}
593
594/* nextmsgid */
595
596int owl_global_get_nextmsgid(owl_global *g) {
597  return(g->nextmsgid++);
598}
599
600/* current view */
601
602owl_view *owl_global_get_current_view(owl_global *g) {
603  return(&(g->current_view));
604}
605
606owl_filterelement *owl_global_get_filterelement_true(owl_global *g) {
607  return(&(g->fe_true));
608}
609
610owl_filterelement *owl_global_get_filterelement_false(owl_global *g) {
611  return(&(g->fe_false));
612}
613
614owl_filterelement *owl_global_get_filterelement_null(owl_global *g) {
615  return(&(g->fe_null));
616}
617
618/* has colors */
619
620int owl_global_get_hascolors(owl_global *g) {
621  if (g->hascolors) return(1);
622  return(0);
623}
624
625/* color pairs */
626
627int owl_global_get_colorpairs(owl_global *g) {
628  return(g->colorpairs);
629}
630
631/* puntlist */
632
633owl_list *owl_global_get_puntlist(owl_global *g) {
634  return(&(g->puntlist));
635}
636
637int owl_global_message_is_puntable(owl_global *g, owl_message *m) {
638  owl_list *pl;
639  int i, j;
640
641  pl=owl_global_get_puntlist(g);
642  j=owl_list_get_size(pl);
643  for (i=0; i<j; i++) {
644    if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1);
645  }
646  return(0);
647}
648
649int owl_global_should_followlast(owl_global *g) {
650  owl_view *v;
651 
652  if (!owl_global_is__followlast(g)) return(0);
653 
654  v=owl_global_get_current_view(g);
655 
656  if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1);
657  return(0);
658}
659
660int owl_global_is_search_active(owl_global *g) {
661  if (g->searchactive) return(1);
662  return(0);
663}
664
665void owl_global_set_search_active(owl_global *g, char *string) {
666  g->searchactive=1;
667  if (g->searchstring != NULL) owl_free(g->searchstring);
668  g->searchstring=owl_strdup(string);
669}
670
671void owl_global_set_search_inactive(owl_global *g) {
672  g->searchactive=0;
673}
674
675char *owl_global_get_search_string(owl_global *g) {
676  if (g->searchstring==NULL) return("");
677  return(g->searchstring);
678}
679
680void owl_global_set_newmsgproc_pid(owl_global *g, int i) {
681  g->newmsgproc_pid=i;
682}
683
684int owl_global_get_newmsgproc_pid(owl_global *g) {
685  return(g->newmsgproc_pid);
686}
687
688void owl_global_add_to_malloced(owl_global *g, int i) {
689  g->malloced+=i;
690}
691
692void owl_global_add_to_freed(owl_global *g, int i) {
693  g->freed+=1;
694}
695
696int owl_global_get_malloced(owl_global *g) {
697  return(g->malloced);
698}
699
700int owl_global_get_freed(owl_global *g) {
701  return(g->freed);
702}
703
704int owl_global_get_meminuse(owl_global *g) {
705  return(g->malloced-g->freed);
706}
707
708/* AIM stuff */
709
710int owl_global_is_aimloggedin(owl_global *g)
711{
712  if (g->aim_loggedin) return(1);
713  return(0);
714}
715
716char *owl_global_get_aim_screenname(owl_global *g)
717{
718  if (owl_global_is_aimloggedin(g)) {
719    return (g->aim_screenname);
720  }
721  return("");
722}
723
724void owl_global_set_aimloggedin(owl_global *g, char *screenname)
725{
726  g->aim_loggedin=1;
727  if (g->aim_screenname) owl_free(g->aim_screenname);
728  g->aim_screenname=owl_strdup(screenname);
729}
730
731void owl_global_set_aimnologgedin(owl_global *g)
732{
733  g->aim_loggedin=0;
734}
735
736int owl_global_is_doaimevents(owl_global *g)
737{
738  if (g->aim_doprocessing) return(1);
739  return(0);
740}
741
742void owl_global_set_doaimevents(owl_global *g)
743{
744  g->aim_doprocessing=1;
745}
746
747void owl_global_set_no_doaimevents(owl_global *g)
748{
749  g->aim_doprocessing=0;
750}
751
752aim_session_t *owl_global_get_aimsess(owl_global *g)
753{
754  return(&(g->aimsess));
755}
756
757aim_conn_t *owl_global_get_bosconn(owl_global *g)
758{
759  return(&(g->bosconn));
760}
761
762void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn)
763{
764  g->bosconn=*conn;
765}
766
767int owl_global_is_aimnop_time(owl_global *g)
768{
769  if (owl_timer_is_expired(&(g->aim_noop_timer))) return(1);
770  return(0);
771}
772
773void owl_global_aimnop_sent(owl_global *g)
774{
775  owl_timer_reset(&(g->aim_noop_timer));
776}
777
778owl_timer *owl_global_get_aim_login_timer(owl_global *g)
779{
780  return(&(g->aim_ignorelogin_timer));
781}
782
783/* message queue */
784
785void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m)
786{
787  owl_list_append_element(&(g->messagequeue), m);
788}
789
790/* pop off the first message and return it.  Return NULL if the queue
791 * is empty.  The caller should free the message after using it, if
792 * necessary.
793 */
794owl_message *owl_global_messageuque_popmsg(owl_global *g)
795{
796  owl_message *out;
797
798  if (owl_list_get_size(&(g->messagequeue))==0) return(NULL);
799  out=owl_list_get_element(&(g->messagequeue), 0);
800  owl_list_remove_element(&(g->messagequeue), 0);
801  return(out);
802}
803
804int owl_global_messagequeue_pending(owl_global *g)
805{
806  if (owl_list_get_size(&(g->messagequeue))==0) return(0);
807  return(1);
808}
809
810owl_buddylist *owl_global_get_buddylist(owl_global *g)
811{
812  return(&(g->buddylist));
813}
814 
815/* style */
816
817/* Return the style with name 'name'.  If it does not exist return
818 * NULL */
819owl_style *owl_global_get_style_by_name(owl_global *g, char *name)
820{
821  return owl_dict_find_element(&(g->styledict), name);
822}
823
824/* creates a list and fills it in with keys.  duplicates the keys,
825 * so they will need to be freed by the caller. */
826int owl_global_get_style_names(owl_global *g, owl_list *l) {
827  return owl_dict_get_keys(&(g->styledict), l);
828}
829
830void owl_global_add_style(owl_global *g, owl_style *s)
831{
832  owl_dict_insert_element(&(g->styledict), owl_style_get_name(s), 
833                          s, (void(*)(void*))owl_style_free);
834}
835
836char *owl_global_get_response(owl_global *g)
837{
838  if (g->response==NULL) return("");
839  return(g->response);
840}
841
842void owl_global_set_response(owl_global *g, char *resp)
843{
844  if (g->response) owl_free(g->response);
845  g->response=owl_strdup(resp);
846}
847
848
849void owl_global_set_haveaim(owl_global *g)
850{
851  g->haveaim=1;
852}
853
854int owl_global_is_haveaim(owl_global *g)
855{
856  if (g->haveaim) return(1);
857  return(0);
858}
859
860void owl_global_set_havezephyr(owl_global *g)
861{
862  g->havezephyr=1;
863}
864
865int owl_global_is_havezephyr(owl_global *g)
866{
867  if (g->havezephyr) return(1);
868  return(0);
869}
870
871owl_timer *owl_global_get_aim_buddyinfo_timer(owl_global *g)
872{
873  return(&(g->aim_buddyinfo_timer));
874}
875
876owl_errqueue *owl_global_get_errqueue(owl_global *g)
877{
878  return(&(g->errqueue));
879}
880
881void owl_global_set_errsignal(owl_global *g, int signum, siginfo_t *siginfo)
882{
883  g->got_err_signal = signum;
884  if (siginfo) {
885    g->err_signal_info = *siginfo;
886  } else {
887    memset(&(g->err_signal_info), 0, sizeof(siginfo_t));
888  }
889}
890
891int owl_global_get_errsignal_and_clear(owl_global *g, siginfo_t *siginfo)
892{
893  int signum;
894  if (siginfo && g->got_err_signal) {
895    *siginfo = g->err_signal_info;
896  } 
897  signum = g->got_err_signal;
898  g->got_err_signal = 0;
899  return signum;
900}
901
902owl_timer *owl_global_get_zephyr_buddycheck_timer(owl_global *g)
903{
904  return(&(g->zephyr_buddycheck_timer));
905}
906
907owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
908{
909  return(&(g->zbuddies));
910}
911
912struct termios *owl_global_get_startup_tio(owl_global *g)
913{
914  return(&(g->startup_tio));
915}
916
917owl_list *owl_global_get_dispatchlist(owl_global *g)
918{
919  return &(g->dispatchlist);
920}
Note: See TracBrowser for help on using the repository browser.