source: global.c @ e74c01c

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