Changeset f97c1a6


Ignore:
Timestamp:
May 23, 2011, 9:09:44 PM (10 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.8, release-1.9
Children:
33b6431b
Parents:
4c7c21f (diff), 1d21d9f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:
Merge branch 'g_main_loop'

The logic in owl_select_prune_bad_fds still needs to be reimplemented.

Conflicts:
	configure.ac
	owl.c
	select.c
Files:
2 added
37 edited

Legend:

Unmodified
Added
Removed
  • Makefile.am

    rce35060 r3535a6e  
    4545     aim.c buddy.c buddylist.c style.c errqueue.c \
    4646     zbuddylist.c popexec.c select.c wcwidth.c \
    47      glib_compat.c mainpanel.c msgwin.c sepbar.c editcontext.c
     47     glib_compat.c mainpanel.c msgwin.c sepbar.c editcontext.c signal.c
    4848
    4949NORMAL_SRCS = filterproc.c window.c windowcb.c
  • aim.c

    r3472845 rdc1edbd  
    446446}
    447447
    448 int owl_aim_process_events(void)
    449 {
    450   aim_session_t *aimsess;
     448int owl_aim_process_events(aim_session_t *aimsess)
     449{
    451450  aim_conn_t *waitingconn = NULL;
    452451  struct timeval tv;
     
    454453  struct owlfaim_priv *priv;
    455454
    456   aimsess=owl_global_get_aimsess(&g);
    457455  priv = aimsess->aux_data;
    458456
     
    17951793}
    17961794
    1797 void owl_process_aim(void)
    1798 {
    1799   if (owl_global_is_doaimevents(&g)) {
    1800     owl_aim_process_events();
    1801   }
    1802 }
     1795typedef struct _owl_aim_event_source { /*noproto*/
     1796  GSource source;
     1797  aim_session_t *sess;
     1798  GPtrArray *fds;
     1799} owl_aim_event_source;
     1800
     1801static void truncate_pollfd_list(owl_aim_event_source *event_source, int len)
     1802{
     1803  GPollFD *fd;
     1804  int i;
     1805  if (len < event_source->fds->len)
     1806    owl_function_debugmsg("Truncating AIM PollFDs to %d, was %d", len, event_source->fds->len);
     1807  for (i = len; i < event_source->fds->len; i++) {
     1808    fd = event_source->fds->pdata[i];
     1809    g_source_remove_poll(&event_source->source, fd);
     1810    g_free(fd);
     1811  }
     1812  g_ptr_array_remove_range(event_source->fds, len, event_source->fds->len - len);
     1813}
     1814
     1815static gboolean owl_aim_event_source_prepare(GSource *source, int *timeout)
     1816{
     1817  owl_aim_event_source *event_source = (owl_aim_event_source*)source;
     1818  aim_conn_t *cur;
     1819  GPollFD *fd;
     1820  int i;
     1821
     1822  /* AIM HACK:
     1823   *
     1824   *  The problem - I'm not sure where to hook into the owl/faim
     1825   *  interface to keep track of when the AIM socket(s) open and
     1826   *  close. In particular, the bosconn thing throws me off. So,
     1827   *  rather than register particular dispatchers for AIM, I look up
     1828   *  the relevant FDs and add them to select's watch lists, then
     1829   *  check for them individually before moving on to the other
     1830   *  dispatchers. --asedeno
     1831   */
     1832  i = 0;
     1833  for (cur = event_source->sess->connlist; cur; cur = cur->next) {
     1834    if (cur->fd != -1) {
     1835      /* Add new GPollFDs as necessary. */
     1836      if (i == event_source->fds->len) {
     1837        fd = g_new0(GPollFD, 1);
     1838        g_ptr_array_add(event_source->fds, fd);
     1839        g_source_add_poll(source, fd);
     1840        owl_function_debugmsg("Allocated new AIM PollFD, len = %d", event_source->fds->len);
     1841      }
     1842      fd = event_source->fds->pdata[i];
     1843      fd->fd = cur->fd;
     1844      fd->events |= G_IO_IN | G_IO_HUP | G_IO_ERR;
     1845      if (cur->status & AIM_CONN_STATUS_INPROGRESS) {
     1846        /* Yes, we're checking writable sockets here. Without it, AIM
     1847           login is really slow. */
     1848        fd->events |= G_IO_OUT;
     1849      }
     1850      i++;
     1851    }
     1852  }
     1853  /* If the number of GPollFDs went down, clean up. */
     1854  truncate_pollfd_list(event_source, i);
     1855
     1856  *timeout = -1;
     1857  return FALSE;
     1858}
     1859
     1860static gboolean owl_aim_event_source_check(GSource *source)
     1861{
     1862  owl_aim_event_source *event_source = (owl_aim_event_source*)source;
     1863  int i;
     1864
     1865  for (i = 0; i < event_source->fds->len; i++) {
     1866    GPollFD *fd = event_source->fds->pdata[i];
     1867    if (fd->revents & fd->events)
     1868      return TRUE;
     1869  }
     1870  return FALSE;
     1871}
     1872
     1873static gboolean owl_aim_event_source_dispatch(GSource *source, GSourceFunc callback, gpointer user_data)
     1874{
     1875  owl_aim_event_source *event_source = (owl_aim_event_source*)source;
     1876  owl_aim_process_events(event_source->sess);
     1877  return TRUE;
     1878}
     1879
     1880static void owl_aim_event_source_finalize(GSource *source)
     1881{
     1882  owl_aim_event_source *event_source = (owl_aim_event_source*)source;
     1883  truncate_pollfd_list(event_source, 0);
     1884  g_ptr_array_free(event_source->fds, TRUE);
     1885}
     1886
     1887static GSourceFuncs aim_event_funcs = {
     1888  owl_aim_event_source_prepare,
     1889  owl_aim_event_source_check,
     1890  owl_aim_event_source_dispatch,
     1891  owl_aim_event_source_finalize,
     1892};
     1893
     1894GSource *owl_aim_event_source_new(aim_session_t *sess)
     1895{
     1896  GSource *source;
     1897  owl_aim_event_source *event_source;
     1898
     1899  source = g_source_new(&aim_event_funcs, sizeof(owl_aim_event_source));
     1900  event_source = (owl_aim_event_source *)source;
     1901  event_source->sess = sess;
     1902  /* TODO: When we depend on glib 2.22+, use g_ptr_array_new_with_free_func. */
     1903  event_source->fds = g_ptr_array_new();
     1904  return source;
     1905}
  • configure.ac

    r64c829a rf97c1a6  
    115115
    116116dnl Add CFLAGS and LIBS for glib-2.0
    117 PKG_CHECK_MODULES(GLIB,[glib-2.0 >= 2.12 gobject-2.0])
     117PKG_CHECK_MODULES(GLIB,[glib-2.0 >= 2.12 gobject-2.0 gthread-2.0])
    118118
    119119AC_MSG_NOTICE([Adding glib-2.0 CFLAGS ${GLIB_CFLAGS}])
  • filterproc.c

    rd564c3d re2cc848  
    1717  int err = 0;
    1818  struct pollfd fds[2];
    19   struct sigaction sig = {.sa_handler = SIG_IGN}, old;
    2019
    2120  fcntl(rfd, F_SETFL, O_NONBLOCK | fcntl(rfd, F_GETFL));
     
    2726  fds[1].events = POLLOUT;
    2827
    29   sigaction(SIGPIPE, &sig, &old);
    30  
    3128  while(1) {
    3229    if(out && *out) {
     
    6764
    6865  *in = g_string_free(str, err < 0);
    69   sigaction(SIGPIPE, &old, NULL);
    7066  return err;
    7167}
  • functions.c

    r3b8a563 rf97c1a6  
    29912991      i--;
    29922992    }
    2993     owl_function_mask_sigint(NULL);
    2994     if(owl_global_is_interrupted(&g)) {
    2995       owl_global_unset_interrupted(&g);
    2996       owl_function_unmask_sigint(NULL);
     2993    if (owl_global_take_interrupt(&g)) {
    29972994      owl_function_makemsg("Search interrupted!");
    29982995      owl_mainwin_redisplay(owl_global_get_mainwin(&g));
    29992996      return;
    30002997    }
    3001     owl_function_unmask_sigint(NULL);
    30022998  }
    30032999  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
     
    30823078          ret=ZLocateUser(zstr(user), &numlocs, ZAUTH);
    30833079
    3084           owl_function_mask_sigint(NULL);
    3085           if(owl_global_is_interrupted(&g)) {
     3080          if (owl_global_take_interrupt(&g)) {
    30863081            interrupted = 1;
    3087             owl_global_unset_interrupted(&g);
    3088             owl_function_unmask_sigint(NULL);
    30893082            owl_function_makemsg("Interrupted!");
    30903083            break;
    30913084          }
    3092 
    3093           owl_function_unmask_sigint(NULL);
    30943085
    30953086          if (ret!=ZERR_NONE) {
     
    34963487}
    34973488
    3498 void owl_function_mask_sigint(sigset_t *oldmask) {
    3499   sigset_t intr;
    3500 
    3501   sigemptyset(&intr);
    3502   sigaddset(&intr, SIGINT);
    3503   sigprocmask(SIG_BLOCK, &intr, oldmask);
    3504 }
    3505 
    3506 void owl_function_unmask_sigint(sigset_t *oldmask) {
    3507   sigset_t intr;
    3508 
    3509   sigemptyset(&intr);
    3510   sigaddset(&intr, SIGINT);
    3511   sigprocmask(SIG_UNBLOCK, &intr, oldmask);
    3512 }
    3513 
    35143489void _owl_function_mark_message(const owl_message *m)
    35153490{
  • global.c

    r351c535 rf97c1a6  
    1616
    1717  g_type_init();
     18  g_thread_init(NULL);
     19
     20  owl_select_init();
    1821
    1922  g->lines=LINES;
     
    9598
    9699  owl_errqueue_init(&(g->errqueue));
    97   g->got_err_signal=0;
    98100
    99101  owl_zbuddylist_create(&(g->zbuddies));
     
    104106  owl_message_init_fmtext_cache();
    105107  owl_list_create(&(g->io_dispatch_list));
    106   owl_list_create(&(g->psa_list));
    107108  g->timerlist = NULL;
    108   g->interrupted = FALSE;
    109109  g->kill_buffer = NULL;
     110
     111  g->interrupt_count = 0;
     112  g->interrupt_lock = g_mutex_new();
    110113}
    111114
     
    344347
    345348void owl_global_set_resize_pending(owl_global *g) {
    346   g->resizepending=1;
     349  g->resizepending = true;
    347350}
    348351
     
    444447  /* resize the screen.  If lines or cols is 0 use the terminal size */
    445448  if (!g->resizepending) return;
    446   g->resizepending = 0;
     449  g->resizepending = false;
    447450
    448451  owl_global_get_terminal_size(&g->lines, &g->cols);
     
    676679}
    677680
    678 int owl_global_is_doaimevents(const owl_global *g)
    679 {
    680   if (g->aim_doprocessing) return(1);
    681   return(0);
     681bool owl_global_is_doaimevents(const owl_global *g)
     682{
     683  return g->aim_event_source != NULL;
    682684}
    683685
    684686void owl_global_set_doaimevents(owl_global *g)
    685687{
    686   g->aim_doprocessing=1;
     688  if (g->aim_event_source)
     689    return;
     690  g->aim_event_source = owl_aim_event_source_new(owl_global_get_aimsess(g));
     691  g_source_attach(g->aim_event_source, NULL);
    687692}
    688693
    689694void owl_global_set_no_doaimevents(owl_global *g)
    690695{
    691   g->aim_doprocessing=0;
     696  if (!g->aim_event_source)
     697    return;
     698  g_source_destroy(g->aim_event_source);
     699  g_source_unref(g->aim_event_source);
     700  g->aim_event_source = NULL;
    692701}
    693702
     
    807816}
    808817
    809 void owl_global_set_errsignal(owl_global *g, int signum, siginfo_t *siginfo)
    810 {
    811   g->got_err_signal = signum;
    812   if (siginfo) {
    813     g->err_signal_info = *siginfo;
    814   } else {
    815     siginfo_t si;
    816     memset(&si, 0, sizeof(si));
    817     g->err_signal_info = si;
    818   }
    819 }
    820 
    821 int owl_global_get_errsignal_and_clear(owl_global *g, siginfo_t *siginfo)
    822 {
    823   int signum;
    824   if (siginfo && g->got_err_signal) {
    825     *siginfo = g->err_signal_info;
    826   }
    827   signum = g->got_err_signal;
    828   g->got_err_signal = 0;
    829   return signum;
    830 }
    831 
    832 
    833818owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
    834819{
     
    861846}
    862847
    863 owl_list *owl_global_get_psa_list(owl_global *g)
    864 {
    865   return &(g->psa_list);
    866 }
    867 
    868848GList **owl_global_get_timerlist(owl_global *g)
    869849{
    870850  return &(g->timerlist);
    871 }
    872 
    873 int owl_global_is_interrupted(const owl_global *g) {
    874   return g->interrupted;
    875 }
    876 
    877 void owl_global_set_interrupted(owl_global *g) {
    878   g->interrupted = 1;
    879 }
    880 
    881 void owl_global_unset_interrupted(owl_global *g) {
    882   g->interrupted = 0;
    883851}
    884852
     
    948916  g->kill_buffer = g_strndup(kill, len);
    949917}
     918
     919void owl_global_add_interrupt(owl_global *g) {
     920  /* TODO: This can almost certainly be done with atomic
     921   * operations. Whatever. */
     922  g_mutex_lock(g->interrupt_lock);
     923  g->interrupt_count++;
     924  g_mutex_unlock(g->interrupt_lock);
     925}
     926
     927bool owl_global_take_interrupt(owl_global *g) {
     928  bool ans = false;
     929  g_mutex_lock(g->interrupt_lock);
     930  if (g->interrupt_count > 0) {
     931    ans = true;
     932    g->interrupt_count--;
     933  }
     934  g_mutex_unlock(g->interrupt_lock);
     935  return ans;
     936}
  • owl.c

    r3b8a563 rf97c1a6  
    160160 * was ignored due to user settings or otherwise.
    161161 */
    162 int owl_process_message(owl_message *m) {
     162static int owl_process_message(owl_message *m) {
    163163  const owl_filter *f;
    164164  /* if this message it on the puntlist, nuke it and continue */
     
    245245}
    246246
     247static gboolean owl_process_messages_prepare(GSource *source, int *timeout) {
     248  *timeout = -1;
     249  return owl_global_messagequeue_pending(&g);
     250}
     251
     252static gboolean owl_process_messages_check(GSource *source) {
     253  return owl_global_messagequeue_pending(&g);
     254}
     255
    247256/*
    248257 * Process any new messages we have waiting in the message queue.
    249  * Returns 1 if any messages were added to the message list, and 0 otherwise.
    250258 */
    251 int owl_process_messages(owl_ps_action *d, void *p)
    252 {
     259static gboolean owl_process_messages_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) {
    253260  int newmsgs=0;
    254261  int followlast = owl_global_should_followlast(&g);
     
    274281    owl_mainwin_redisplay(owl_global_get_mainwin(&g));
    275282  }
    276   return newmsgs;
     283  return TRUE;
     284}
     285
     286static GSourceFuncs owl_process_messages_funcs = {
     287  owl_process_messages_prepare,
     288  owl_process_messages_check,
     289  owl_process_messages_dispatch,
     290  NULL
     291};
     292
     293void owl_process_input_char(owl_input j)
     294{
     295  int ret;
     296
     297  owl_global_set_lastinputtime(&g, time(NULL));
     298  ret = owl_keyhandler_process(owl_global_get_keyhandler(&g), j);
     299  if (ret!=0 && ret!=1) {
     300    owl_function_makemsg("Unable to handle keypress");
     301  }
    277302}
    278303
     
    334359}
    335360
    336 void sig_handler(int sig, siginfo_t *si, void *data)
    337 {
    338   if (sig==SIGWINCH) {
    339     /* we can't inturrupt a malloc here, so it just sets a flag
    340      * schedulding a resize for later
    341      */
     361static void sig_handler_main_thread(void *data) {
     362  int sig = GPOINTER_TO_INT(data);
     363
     364  owl_function_debugmsg("Got signal %d", sig);
     365  if (sig == SIGWINCH) {
    342366    owl_function_resize();
    343   } else if (sig==SIGPIPE || sig==SIGCHLD) {
    344     /* Set a flag and some info that we got the sigpipe
    345      * so we can record that we got it and why... */
    346     owl_global_set_errsignal(&g, sig, si);
    347   } else if (sig==SIGTERM || sig==SIGHUP) {
     367  } else if (sig == SIGTERM || sig == SIGHUP) {
    348368    owl_function_quit();
    349   }
    350 }
    351 
    352 void sigint_handler(int sig, siginfo_t *si, void *data)
    353 {
    354   owl_global_set_interrupted(&g);
    355 }
    356 
    357 static int owl_errsignal_pre_select_action(owl_ps_action *a, void *data)
    358 {
    359   siginfo_t si;
    360   int signum;
    361   if ((signum = owl_global_get_errsignal_and_clear(&g, &si)) > 0) {
    362     owl_function_error("Got unexpected signal: %d %s  (code: %d band: %ld  errno: %d)",
    363         signum, signum==SIGPIPE?"SIGPIPE":"SIG????",
    364         si.si_code, si.si_band, si.si_errno);
    365   }
    366   return 0;
    367 }
     369  } else if (sig == SIGINT && owl_global_take_interrupt(&g)) {
     370    owl_input in;
     371    in.ch = in.uch = owl_global_get_startup_tio(&g)->c_cc[VINTR];
     372    owl_process_input_char(in);
     373  }
     374}
     375
     376static void sig_handler(const siginfo_t *siginfo, void *data) {
     377  /* If it was an interrupt, set a flag so we can handle it earlier if
     378   * needbe. sig_handler_main_thread will check the flag to make sure
     379   * no one else took it. */
     380  if (siginfo->si_signo == SIGINT) {
     381    owl_global_add_interrupt(&g);
     382  }
     383  /* Send a message to the main thread. */
     384  owl_select_post_task(sig_handler_main_thread,
     385                       GINT_TO_POINTER(siginfo->si_signo), NULL);
     386}
     387
     388#define CHECK_RESULT(s, syscall) \
     389  G_STMT_START {                 \
     390    if ((syscall) != 0) {        \
     391      perror((s));               \
     392      exit(1);                   \
     393    }                            \
     394  } G_STMT_END
    368395
    369396void owl_register_signal_handlers(void) {
    370   struct sigaction sigact;
    371 
    372   /* signal handler */
    373   /*sigact.sa_handler=sig_handler;*/
    374   sigact.sa_sigaction=sig_handler;
    375   sigemptyset(&sigact.sa_mask);
    376   sigact.sa_flags=SA_SIGINFO;
    377   sigaction(SIGWINCH, &sigact, NULL);
    378   sigaction(SIGALRM, &sigact, NULL);
    379   sigaction(SIGPIPE, &sigact, NULL);
    380   sigaction(SIGTERM, &sigact, NULL);
    381   sigaction(SIGHUP, &sigact, NULL);
    382 
    383   sigact.sa_sigaction=sigint_handler;
    384   sigaction(SIGINT, &sigact, NULL);
     397  struct sigaction sig_ignore = { .sa_handler = SIG_IGN };
     398  struct sigaction sig_default = { .sa_handler = SIG_DFL };
     399  sigset_t sigset;
     400  int ret, i;
     401  const int signals[] = { SIGABRT, SIGBUS, SIGCHLD, SIGFPE, SIGHUP, SIGILL,
     402                          SIGINT, SIGQUIT, SIGSEGV, SIGTERM, SIGWINCH };
     403
     404  /* Sanitize our signals; the mask and dispositions from our parent
     405   * aren't really useful. Signal list taken from equivalent code in
     406   * Chromium. */
     407  CHECK_RESULT("sigemptyset", sigemptyset(&sigset));
     408  if ((ret = pthread_sigmask(SIG_SETMASK, &sigset, NULL)) != 0) {
     409    errno = ret;
     410    perror("pthread_sigmask");
     411  }
     412  for (i = 0; i < G_N_ELEMENTS(signals); i++) {
     413    CHECK_RESULT("sigaction", sigaction(signals[i], &sig_default, NULL));
     414  }
     415
     416  /* Turn off SIGPIPE; we check the return value of write. */
     417  CHECK_RESULT("sigaction", sigaction(SIGPIPE, &sig_ignore, NULL));
     418
     419  /* Register some signals with the signal thread. */
     420  CHECK_RESULT("sigaddset", sigaddset(&sigset, SIGWINCH));
     421  CHECK_RESULT("sigaddset", sigaddset(&sigset, SIGTERM));
     422  CHECK_RESULT("sigaddset", sigaddset(&sigset, SIGHUP));
     423  CHECK_RESULT("sigaddset", sigaddset(&sigset, SIGINT));
     424  owl_signal_init(&sigset, sig_handler, NULL);
    385425}
    386426
     
    436476#endif /* OWL_STDERR_REDIR */
    437477
    438 static int owl_refresh_pre_select_action(owl_ps_action *a, void *data)
    439 {
    440   owl_colorpair_mgr *cpmgr;
    441 
    442   /* if a resize has been scheduled, deal with it */
    443   owl_global_check_resize(&g);
    444   /* update the terminal if we need to */
    445   owl_window_redraw_scheduled();
    446   /* On colorpair shortage, reset and redraw /everything/. NOTE: if we
    447    * still overflow, this be useless work. With 8-colors, we get 64
    448    * pairs. With 256-colors, we get 32768 pairs with ext-colors
    449    * support and 256 otherwise. */
    450   cpmgr = owl_global_get_colorpair_mgr(&g);
    451   if (cpmgr->overflow) {
    452     owl_function_debugmsg("colorpairs: used all %d pairs; reset pairs and redraw.",
    453                           owl_util_get_colorpairs());
    454     owl_fmtext_reset_colorpairs(cpmgr);
    455     owl_function_full_redisplay();
    456     owl_window_redraw_scheduled();
    457   }
    458   return 0;
    459 }
    460 
    461 
    462478int main(int argc, char **argv, char **env)
    463479{
     
    468484  const char *dir;
    469485  owl_options opts;
     486  GSource *source;
    470487
    471488  if (!GLIB_CHECK_VERSION (2, 12, 0))
     
    482499  g.load_initial_subs = opts.load_initial_subs;
    483500
    484   owl_register_signal_handlers();
    485501  owl_start_curses();
    486502
     
    493509  g_strfreev(argv_copy);
    494510  owl_global_set_haveaim(&g);
     511
     512  owl_register_signal_handlers();
    495513
    496514  /* register STDIN dispatch; throw away return, we won't need it */
     
    585603  owl_global_push_context(&g, OWL_CTX_INTERACTIVE|OWL_CTX_RECV, NULL, "recv", NULL);
    586604
    587   owl_select_add_pre_select_action(owl_refresh_pre_select_action, NULL, NULL);
    588   owl_select_add_pre_select_action(owl_process_messages, NULL, NULL);
    589   owl_select_add_pre_select_action(owl_errsignal_pre_select_action, NULL, NULL);
     605  source = owl_window_redraw_source_new();
     606  g_source_attach(source, NULL);
     607  g_source_unref(source);
     608
     609  source = g_source_new(&owl_process_messages_funcs, sizeof(GSource));
     610  g_source_attach(source, NULL);
     611  g_source_unref(source);
    590612
    591613  owl_function_debugmsg("startup: entering main loop");
     
    594616  /* Shut down everything. */
    595617  owl_zephyr_shutdown();
     618  owl_signal_shutdown();
    596619  owl_shutdown_curses();
    597620  return 0;
  • owl.h

    rede073c rf97c1a6  
    552552  void (*destroy)(const struct _owl_io_dispatch *);  /* Destructor */
    553553  void *data;
     554  GPollFD pollfd;
    554555} owl_io_dispatch;
    555 
    556 typedef struct _owl_ps_action {
    557   int needs_gc;
    558   int (*callback)(struct _owl_ps_action *, void *);
    559   void (*destroy)(struct _owl_ps_action *);
    560   void *data;
    561 } owl_ps_action;
    562556
    563557typedef struct _owl_popexec {
     
    568562  const owl_io_dispatch *dispatch;
    569563} owl_popexec;
    570 
    571 typedef struct _OwlGlobalNotifier OwlGlobalNotifier;
    572564
    573565typedef struct _owl_global {
     
    595587  gulong typwin_erase_id;
    596588  int rightshift;
    597   volatile sig_atomic_t resizepending;
     589  bool resizepending;
    598590  char *homedir;
    599591  char *confdir;
     
    618610  aim_conn_t bosconn;
    619611  int aim_loggedin;         /* true if currently logged into AIM */
    620   int aim_doprocessing;     /* true if we should process AIM events (like pending login) */
     612  GSource *aim_event_source; /* where we get our AIM events from */
    621613  char *aim_screenname;     /* currently logged in AIM screen name */
    622614  char *aim_screenname_for_filters;     /* currently logged in AIM screen name */
     
    628620  int haveaim;
    629621  int ignoreaimlogin;
    630   volatile sig_atomic_t got_err_signal; /* 1 if we got an unexpected signal */
    631   volatile siginfo_t err_signal_info;
    632622  owl_zbuddylist zbuddies;
    633623  GList *zaldlist;
     
    635625  struct termios startup_tio;
    636626  owl_list io_dispatch_list;
    637   owl_list psa_list;
    638627  GList *timerlist;
    639628  owl_timer *aim_nop_timer;
    640629  int load_initial_subs;
    641   volatile sig_atomic_t interrupted;
    642630  FILE *debug_file;
    643631  char *kill_buffer;
     632  int interrupt_count;
     633  GMutex *interrupt_lock;
    644634} owl_global;
    645635
  • select.c

    rfb96152 rf97c1a6  
    11#include "owl.h"
    2 #include <sys/stat.h>
    3 
     2
     3static GMainLoop *loop = NULL;
     4static GMainContext *context;
    45static int dispatch_active = 0;
    5 static int psa_active = 0;
    6 static int loop_active = 0;
    7 
    8 int _owl_select_timer_cmp(const owl_timer *t1, const owl_timer *t2) {
     6
     7static GSource *owl_timer_source;
     8static GSource *owl_io_dispatch_source;
     9
     10static int _owl_select_timer_cmp(const owl_timer *t1, const owl_timer *t2) {
    911  return t1->time - t2->time;
    10 }
    11 
    12 int _owl_select_timer_eq(const owl_timer *t1, const owl_timer *t2) {
    13   return t1 == t2;
    1412}
    1513
     
    4442}
    4543
    46 void owl_select_process_timers(struct timespec *timeout)
    47 {
    48   time_t now = time(NULL);
    49   GList **timers = owl_global_get_timerlist(&g);
    50 
     44static gboolean owl_timer_prepare(GSource *source, int *timeout) {
     45  GList **timers = owl_global_get_timerlist(&g);
     46  GTimeVal now;
     47
     48  /* TODO: In the far /far/ future, g_source_get_time is what the cool
     49   * kids use to get system monotonic time. */
     50  g_source_get_current_time(source, &now);
     51
     52  /* FIXME: bother with millisecond accuracy now that we can? */
     53  if (*timers) {
     54    owl_timer *t = (*timers)->data;
     55    *timeout = t->time - now.tv_sec;
     56    if (*timeout <= 0) {
     57      *timeout = 0;
     58      return TRUE;
     59    }
     60    if (*timeout > 60 * 1000)
     61      *timeout = 60 * 1000;
     62  } else {
     63    *timeout = 60 * 1000;
     64  }
     65  return FALSE;
     66}
     67
     68static gboolean owl_timer_check(GSource *source) {
     69  GList **timers = owl_global_get_timerlist(&g);
     70  GTimeVal now;
     71
     72  /* TODO: In the far /far/ future, g_source_get_time is what the cool
     73   * kids use to get system monotonic time. */
     74  g_source_get_current_time(source, &now);
     75
     76  /* FIXME: bother with millisecond accuracy now that we can? */
     77  if (*timers) {
     78    owl_timer *t = (*timers)->data;
     79    return t->time >= now.tv_sec;
     80  }
     81  return FALSE;
     82}
     83
     84
     85static gboolean owl_timer_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) {
     86  GList **timers = owl_global_get_timerlist(&g);
     87  GTimeVal now;
     88
     89  /* TODO: In the far /far/ future, g_source_get_time is what the cool
     90   * kids use to get system monotonic time. */
     91  g_source_get_current_time(source, &now);
     92
     93  /* FIXME: bother with millisecond accuracy now that we can? */
    5194  while(*timers) {
    5295    owl_timer *t = (*timers)->data;
    5396    int remove = 0;
    5497
    55     if(t->time > now)
     98    if(t->time > now.tv_sec)
    5699      break;
    57100
    58101    /* Reschedule if appropriate */
    59102    if(t->interval > 0) {
    60       t->time = now + t->interval;
     103      t->time = now.tv_sec + t->interval;
    61104      *timers = g_list_remove(*timers, t);
    62105      *timers = g_list_insert_sorted(*timers, t,
     
    72115    }
    73116  }
    74 
    75   if(*timers) {
    76     owl_timer *t = (*timers)->data;
    77     timeout->tv_sec = t->time - now;
    78     if (timeout->tv_sec > 60)
    79       timeout->tv_sec = 60;
    80   } else {
    81     timeout->tv_sec = 60;
    82   }
    83 
    84   timeout->tv_nsec = 0;
    85 }
     117  return TRUE;
     118}
     119
     120static GSourceFuncs owl_timer_funcs = {
     121  owl_timer_prepare,
     122  owl_timer_check,
     123  owl_timer_dispatch,
     124  NULL
     125};
     126
    86127
    87128static const owl_io_dispatch *owl_select_find_io_dispatch_by_fd(const int fd)
     
    129170        if (d->destroy)
    130171          d->destroy(d);
     172        g_source_remove_poll(owl_io_dispatch_source, &d->pollfd);
    131173        g_free(d);
    132174      }
     
    135177}
    136178
    137 void owl_select_io_dispatch_gc(void)
     179static void owl_select_io_dispatch_gc(void)
    138180{
    139181  int i;
     
    170212  d->data = data;
    171213
     214  /* TODO: Allow changing fd and mode in the middle? Probably don't care... */
     215  d->pollfd.fd = fd;
     216  d->pollfd.events = 0;
     217  if (d->mode & OWL_IO_READ)
     218    d->pollfd.events |= G_IO_IN | G_IO_HUP | G_IO_ERR;
     219  if (d->mode & OWL_IO_WRITE)
     220    d->pollfd.events |= G_IO_OUT | G_IO_ERR;
     221  if (d->mode & OWL_IO_EXCEPT)
     222    d->pollfd.events |= G_IO_PRI | G_IO_ERR;
     223  g_source_add_poll(owl_io_dispatch_source, &d->pollfd);
     224
     225
    172226  owl_select_remove_io_dispatch(owl_select_find_io_dispatch_by_fd(fd));
    173227  owl_list_append_element(dl, d);
     
    176230}
    177231
    178 int owl_select_prepare_io_dispatch_fd_sets(fd_set *rfds, fd_set *wfds, fd_set *efds) {
    179   int i, len, max_fd;
    180   owl_io_dispatch *d;
    181   owl_list *dl = owl_global_get_io_dispatch_list(&g);
    182 
    183   max_fd = 0;
     232static gboolean owl_io_dispatch_prepare(GSource *source, int *timeout) {
     233  *timeout = -1;
     234  return FALSE;
     235}
     236
     237static gboolean owl_io_dispatch_check(GSource *source) {
     238  int i, len;
     239  const owl_list *dl;
     240
     241  dl = owl_global_get_io_dispatch_list(&g);
     242  len = owl_list_get_size(dl);
     243  for(i = 0; i < len; i++) {
     244    const owl_io_dispatch *d = owl_list_get_element(dl, i);
     245    if (d->pollfd.revents & d->pollfd.events)
     246      return TRUE;
     247  }
     248  return FALSE;
     249}
     250
     251static gboolean owl_io_dispatch_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) {
     252  int i, len;
     253  const owl_list *dl;
     254
     255  dispatch_active = 1;
     256  dl = owl_global_get_io_dispatch_list(&g);
    184257  len = owl_list_get_size(dl);
    185258  for (i = 0; i < len; i++) {
    186     d = owl_list_get_element(dl, i);
    187     if (d->mode & (OWL_IO_READ | OWL_IO_WRITE | OWL_IO_EXCEPT)) {
    188       if (max_fd < d->fd) max_fd = d->fd;
    189       if (d->mode & OWL_IO_READ) FD_SET(d->fd, rfds);
    190       if (d->mode & OWL_IO_WRITE) FD_SET(d->fd, wfds);
    191       if (d->mode & OWL_IO_EXCEPT) FD_SET(d->fd, efds);
    192     }
    193   }
    194   return max_fd + 1;
    195 }
    196 
    197 void owl_select_io_dispatch(const fd_set *rfds, const fd_set *wfds, const fd_set *efds, const int max_fd)
    198 {
    199   int i, len;
    200   owl_io_dispatch *d;
    201   owl_list *dl = owl_global_get_io_dispatch_list(&g);
    202 
    203   dispatch_active = 1;
    204   len = owl_list_get_size(dl);
    205   for (i = 0; i < len; i++) {
    206     d = owl_list_get_element(dl, i);
    207     if (d->fd < max_fd && d->callback != NULL &&
    208         ((d->mode & OWL_IO_READ && FD_ISSET(d->fd, rfds)) ||
    209          (d->mode & OWL_IO_WRITE && FD_ISSET(d->fd, wfds)) ||
    210          (d->mode & OWL_IO_EXCEPT && FD_ISSET(d->fd, efds)))) {
     259    owl_io_dispatch *d = owl_list_get_element(dl, i);
     260    if ((d->pollfd.revents & d->pollfd.events) && d->callback != NULL) {
    211261      d->callback(d, d->data);
    212262    }
     
    214264  dispatch_active = 0;
    215265  owl_select_io_dispatch_gc();
    216 }
     266
     267  return TRUE;
     268}
     269
     270static GSourceFuncs owl_io_dispatch_funcs = {
     271  owl_io_dispatch_prepare,
     272  owl_io_dispatch_check,
     273  owl_io_dispatch_dispatch,
     274  NULL
     275};
    217276
    218277int owl_select_add_perl_io_dispatch(int fd, int mode, SV *cb)
     
    238297}
    239298
    240 int owl_select_aim_hack(fd_set *rfds, fd_set *wfds)
    241 {
    242   aim_conn_t *cur;
    243   aim_session_t *sess;
    244   int max_fd;
    245 
    246   max_fd = 0;
    247   sess = owl_global_get_aimsess(&g);
    248   for (cur = sess->connlist; cur; cur = cur->next) {
    249     if (cur->fd != -1) {
    250       FD_SET(cur->fd, rfds);
    251       if (cur->status & AIM_CONN_STATUS_INPROGRESS) {
    252         /* Yes, we're checking writable sockets here. Without it, AIM
    253            login is really slow. */
    254         FD_SET(cur->fd, wfds);
    255       }
    256      
    257       if (cur->fd > max_fd)
    258         max_fd = cur->fd;
    259     }
    260   }
    261   return max_fd;
    262 }
    263 
    264 void owl_process_input_char(owl_input j)
    265 {
    266   int ret;
    267 
    268   owl_global_set_lastinputtime(&g, time(NULL));
    269   ret = owl_keyhandler_process(owl_global_get_keyhandler(&g), j);
    270   if (ret!=0 && ret!=1) {
    271     owl_function_makemsg("Unable to handle keypress");
    272   }
    273 }
    274 
    275 void owl_select_mask_signals(sigset_t *oldmask) {
    276   sigset_t set;
    277 
    278   sigemptyset(&set);
    279   sigaddset(&set, SIGWINCH);
    280   sigaddset(&set, SIGALRM);
    281   sigaddset(&set, SIGPIPE);
    282   sigaddset(&set, SIGTERM);
    283   sigaddset(&set, SIGHUP);
    284   sigaddset(&set, SIGINT);
    285   sigprocmask(SIG_BLOCK, &set, oldmask);
    286 }
    287 
    288 void owl_select_handle_intr(sigset_t *restore)
    289 {
    290   owl_input in;
    291 
    292   owl_global_unset_interrupted(&g);
    293 
    294   sigprocmask(SIG_SETMASK, restore, NULL);
    295 
    296   in.ch = in.uch = owl_global_get_startup_tio(&g)->c_cc[VINTR];
    297   owl_process_input_char(in);
    298 }
    299 
    300 owl_ps_action *owl_select_add_pre_select_action(int (*cb)(owl_ps_action *, void *), void (*destroy)(owl_ps_action *), void *data)
    301 {
    302   owl_ps_action *a = g_new(owl_ps_action, 1);
    303   owl_list *psa_list = owl_global_get_psa_list(&g);
    304   a->needs_gc = 0;
    305   a->callback = cb;
    306   a->destroy = destroy;
    307   a->data = data;
    308   owl_list_append_element(psa_list, a);
    309   return a;
    310 }
    311 
    312 void owl_select_psa_gc(void)
    313 {
    314   int i;
    315   owl_list *psa_list;
    316   owl_ps_action *a;
    317 
    318   psa_list = owl_global_get_psa_list(&g);
    319   for (i = owl_list_get_size(psa_list) - 1; i >= 0; i--) {
    320     a = owl_list_get_element(psa_list, i);
    321     if (a->needs_gc) {
    322       owl_list_remove_element(psa_list, i);
    323       if (a->destroy) {
    324         a->destroy(a);
    325       }
    326       g_free(a);
    327     }
    328   }
    329 }
    330 
    331 void owl_select_remove_pre_select_action(owl_ps_action *a)
    332 {
    333   a->needs_gc = 1;
    334   if (!psa_active)
    335     owl_select_psa_gc();
    336 }
    337 
    338 int owl_select_do_pre_select_actions(void)
    339 {
    340   int i, len, ret;
    341   owl_list *psa_list;
    342 
    343   psa_active = 1;
    344   ret = 0;
    345   psa_list = owl_global_get_psa_list(&g);
    346   len = owl_list_get_size(psa_list);
    347   for (i = 0; i < len; i++) {
    348     owl_ps_action *a = owl_list_get_element(psa_list, i);
    349     if (a->callback != NULL && a->callback(a, a->data)) {
    350       ret = 1;
    351     }
    352   }
    353   psa_active = 0;
    354   owl_select_psa_gc();
    355   return ret;
    356 }
    357 
     299void owl_select_init(void)
     300{
     301  owl_timer_source = g_source_new(&owl_timer_funcs, sizeof(GSource));
     302  g_source_attach(owl_timer_source, NULL);
     303
     304  owl_io_dispatch_source = g_source_new(&owl_io_dispatch_funcs, sizeof(GSource));
     305  g_source_attach(owl_io_dispatch_source, NULL);
     306}
     307
     308void owl_select_run_loop(void)
     309{
     310  context = g_main_context_default();
     311  loop = g_main_loop_new(context, FALSE);
     312  g_main_loop_run(loop);
     313}
     314
     315void owl_select_quit_loop(void)
     316{
     317  if (loop) {
     318    g_main_loop_quit(loop);
     319    loop = NULL;
     320  }
     321}
     322
     323#if 0
     324/* FIXME: Reimplement this check in the glib world. */
    358325static void owl_select_prune_bad_fds(void) {
    359326  owl_list *dl = owl_global_get_io_dispatch_list(&g);
     
    372339  owl_select_io_dispatch_gc();
    373340}
    374 
    375 void owl_select(void)
    376 {
    377   int i, max_fd, max_fd2, aim_done, ret;
    378   fd_set r;
    379   fd_set w;
    380   fd_set e;
    381   fd_set aim_rfds, aim_wfds;
    382   struct timespec timeout;
    383   sigset_t mask;
    384 
    385   owl_select_process_timers(&timeout);
    386 
    387   owl_select_mask_signals(&mask);
    388 
    389   if(owl_global_is_interrupted(&g)) {
    390     owl_select_handle_intr(&mask);
    391     return;
    392   }
    393   FD_ZERO(&r);
    394   FD_ZERO(&w);
    395   FD_ZERO(&e);
    396 
    397   max_fd = owl_select_prepare_io_dispatch_fd_sets(&r, &w, &e);
    398 
    399   /* AIM HACK:
    400    *
    401    *  The problem - I'm not sure where to hook into the owl/faim
    402    *  interface to keep track of when the AIM socket(s) open and
    403    *  close. In particular, the bosconn thing throws me off. So,
    404    *  rather than register particular dispatchers for AIM, I look up
    405    *  the relevant FDs and add them to select's watch lists, then
    406    *  check for them individually before moving on to the other
    407    *  dispatchers. --asedeno
    408    */
    409   aim_done = 1;
    410   FD_ZERO(&aim_rfds);
    411   FD_ZERO(&aim_wfds);
    412   if (owl_global_is_doaimevents(&g)) {
    413     aim_done = 0;
    414     max_fd2 = owl_select_aim_hack(&aim_rfds, &aim_wfds);
    415     if (max_fd < max_fd2) max_fd = max_fd2;
    416     for(i = 0; i <= max_fd2; i++) {
    417       if (FD_ISSET(i, &aim_rfds)) {
    418         FD_SET(i, &r);
    419         FD_SET(i, &e);
    420       }
    421       if (FD_ISSET(i, &aim_wfds)) {
    422         FD_SET(i, &w);
    423         FD_SET(i, &e);
    424       }
    425     }
    426   }
    427   /* END AIM HACK */
    428 
    429   if (owl_select_do_pre_select_actions()) {
    430     timeout.tv_sec = 0;
    431     timeout.tv_nsec = 0;
    432   }
    433 
    434   ret = pselect(max_fd+1, &r, &w, &e, &timeout, &mask);
    435 
    436   if(ret < 0) {
    437     if (errno == EINTR) {
    438       if(owl_global_is_interrupted(&g)) {
    439         owl_select_handle_intr(NULL);
    440       }
    441     } else if (errno == EBADF) {
    442       /* Perl must have closed an fd on us without removing it first. */
    443       owl_select_prune_bad_fds();
    444     }
    445     sigprocmask(SIG_SETMASK, &mask, NULL);
    446     return;
    447   }
    448 
    449   sigprocmask(SIG_SETMASK, &mask, NULL);
    450 
    451   if(ret > 0) {
    452     /* AIM HACK: process all AIM events at once. */
    453     for(i = 0; !aim_done && i <= max_fd; i++) {
    454       if (FD_ISSET(i, &r) || FD_ISSET(i, &w) || FD_ISSET(i, &e)) {
    455         if (FD_ISSET(i, &aim_rfds) || FD_ISSET(i, &aim_wfds)) {
    456           owl_process_aim();
    457           aim_done = 1;
    458         }
    459       }
    460     }
    461     owl_select_io_dispatch(&r, &w, &e, max_fd);
    462   }
    463 }
    464 
    465 void owl_select_run_loop(void)
    466 {
    467   loop_active = 1;
    468   while (loop_active) {
    469     owl_select();
    470   }
    471 }
    472 
    473 void owl_select_quit_loop(void)
    474 {
    475   loop_active = 0;
    476 }
     341#endif
     342
     343typedef struct _owl_task { /*noproto*/
     344  void (*cb)(void *);
     345  void *cbdata;
     346  void (*destroy_cbdata)(void *);
     347} owl_task;
     348
     349static gboolean _run_task(gpointer data)
     350{
     351  owl_task *t = data;
     352  if (t->cb)
     353    t->cb(t->cbdata);
     354  return FALSE;
     355}
     356
     357static void _destroy_task(void *data)
     358{
     359  owl_task *t = data;
     360  if (t->destroy_cbdata)
     361    t->destroy_cbdata(t->cbdata);
     362  g_free(t);
     363}
     364
     365void owl_select_post_task(void (*cb)(void*), void *cbdata, void (*destroy_cbdata)(void*))
     366{
     367  GSource *source = g_idle_source_new();
     368  owl_task *t = g_new0(owl_task, 1);
     369  t->cb = cb;
     370  t->cbdata = cbdata;
     371  t->destroy_cbdata = destroy_cbdata;
     372  g_source_set_priority(source, G_PRIORITY_DEFAULT);
     373  g_source_set_callback(source, _run_task, t, _destroy_task);
     374  g_source_attach(source, context);
     375  g_source_unref(source);
     376}
  • window.c

    rb31f1c9 rf97c1a6  
    524524  owl_window_set_position(w, nlines, ncols, w->begin_y, w->begin_x);
    525525}
     526
     527/** Redrawing main loop hooks **/
     528
     529static bool _owl_window_should_redraw(void) {
     530  return g.resizepending || owl_window_get_screen()->dirty_subtree;
     531}
     532
     533static gboolean _owl_window_redraw_prepare(GSource *source, int *timeout) {
     534  *timeout = -1;
     535  return _owl_window_should_redraw();
     536}
     537
     538static gboolean _owl_window_redraw_check(GSource *source) {
     539  return _owl_window_should_redraw();
     540}
     541
     542static gboolean _owl_window_redraw_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) {
     543  owl_colorpair_mgr *cpmgr;
     544
     545  /* if a resize has been scheduled, deal with it */
     546  owl_global_check_resize(&g);
     547  /* update the terminal if we need to */
     548  owl_window_redraw_scheduled();
     549  /* On colorpair shortage, reset and redraw /everything/. NOTE: if we
     550   * still overflow, this be useless work. With 8-colors, we get 64
     551   * pairs. With 256-colors, we get 32768 pairs with ext-colors
     552   * support and 256 otherwise. */
     553  cpmgr = owl_global_get_colorpair_mgr(&g);
     554  if (cpmgr->overflow) {
     555    owl_function_debugmsg("colorpairs: used all %d pairs; reset pairs and redraw.",
     556                          owl_util_get_colorpairs());
     557    owl_fmtext_reset_colorpairs(cpmgr);
     558    owl_function_full_redisplay();
     559    owl_window_redraw_scheduled();
     560  }
     561  return TRUE;
     562}
     563
     564static GSourceFuncs redraw_funcs = {
     565  _owl_window_redraw_prepare,
     566  _owl_window_redraw_check,
     567  _owl_window_redraw_dispatch,
     568  NULL
     569};
     570
     571GSource *owl_window_redraw_source_new(void) {
     572  GSource *source;
     573  source = g_source_new(&redraw_funcs, sizeof(GSource));
     574  /* TODO: priority?? */
     575  return source;
     576}
  • window.h

    r38e2250 r4cc49bc  
    7272void owl_window_resize(owl_window *w, int nlines, int ncols);
    7373
     74GSource *owl_window_redraw_source_new(void);
     75
    7476/* Standard callback functions in windowcb.c */
    7577
  • zephyr.c

    r3b8a563 rf97c1a6  
    77#include "owl.h"
    88
     9static GSource *owl_zephyr_event_source_new(int fd);
     10
     11static gboolean owl_zephyr_event_prepare(GSource *source, int *timeout);
     12static gboolean owl_zephyr_event_check(GSource *source);
     13static gboolean owl_zephyr_event_dispatch(GSource *source, GSourceFunc callback, gpointer user_data);
     14
    915#ifdef HAVE_LIBZEPHYR
    1016static GList *deferred_subs = NULL;
     
    1622
    1723Code_t ZResetAuthentication(void);
     24
     25static GSourceFuncs zephyr_event_funcs = {
     26  owl_zephyr_event_prepare,
     27  owl_zephyr_event_check,
     28  owl_zephyr_event_dispatch,
     29  NULL
     30};
    1831#endif
    1932
     
    8497  Code_t code;
    8598  char *perl;
     99  GSource *event_source;
    86100
    87101  owl_select_remove_io_dispatch(d);
     
    99113  }
    100114
    101   owl_select_add_io_dispatch(ZGetFD(), OWL_IO_READ|OWL_IO_EXCEPT, &owl_zephyr_process_events, NULL, NULL);
     115  event_source = owl_zephyr_event_source_new(ZGetFD());
     116  g_source_attach(event_source, NULL);
     117  g_source_unref(event_source);
    102118
    103119  owl_global_set_havezephyr(&g);
     
    127143  perl = owl_perlconfig_execute("BarnOwl::Zephyr::_zephyr_startup()");
    128144  g_free(perl);
    129 
    130   owl_select_add_pre_select_action(owl_zephyr_pre_select_action, NULL, NULL);
    131145}
    132146
     
    180194    if((code = ZPending()) < 0) {
    181195      owl_function_debugmsg("Error (%s) in ZPending()\n",
     196                            error_message(code));
     197      return 0;
     198    }
     199    return code;
     200  }
     201#endif
     202  return 0;
     203}
     204
     205int owl_zephyr_zqlength(void)
     206{
     207#ifdef HAVE_LIBZEPHYR
     208  Code_t code;
     209  if(owl_global_is_havezephyr(&g)) {
     210    if((code = ZQLength()) < 0) {
     211      owl_function_debugmsg("Error (%s) in ZQLength()\n",
    182212                            error_message(code));
    183213      return 0;
     
    14691499}
    14701500
    1471 void owl_zephyr_process_events(const owl_io_dispatch *d, void *data)
    1472 {
     1501typedef struct { /*noproto*/
     1502  GSource source;
     1503  GPollFD poll_fd;
     1504} owl_zephyr_event_source;
     1505
     1506static GSource *owl_zephyr_event_source_new(int fd) {
     1507  GSource *source;
     1508  owl_zephyr_event_source *event_source;
     1509
     1510  source = g_source_new(&zephyr_event_funcs, sizeof(owl_zephyr_event_source));
     1511  event_source = (owl_zephyr_event_source*) source;
     1512  event_source->poll_fd.fd = fd;
     1513  event_source->poll_fd.events = G_IO_IN | G_IO_HUP | G_IO_PRI | G_IO_ERR;
     1514  g_source_add_poll(source, &event_source->poll_fd);
     1515
     1516  return source;
     1517}
     1518
     1519static gboolean owl_zephyr_event_prepare(GSource *source, int *timeout) {
     1520  *timeout = -1;
     1521  return owl_zephyr_zqlength() > 0;
     1522}
     1523
     1524static gboolean owl_zephyr_event_check(GSource *source) {
     1525  owl_zephyr_event_source *event_source = (owl_zephyr_event_source*)source;
     1526  if (event_source->poll_fd.revents & event_source->poll_fd.events)
     1527    return owl_zephyr_zpending() > 0;
     1528  return FALSE;
     1529}
     1530
     1531static gboolean owl_zephyr_event_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) {
    14731532  _owl_zephyr_process_events();
    1474 }
    1475 
    1476 int owl_zephyr_pre_select_action(owl_ps_action *a, void *p)
    1477 {
    1478   return _owl_zephyr_process_events();
    1479 }
     1533  return TRUE;
     1534}
  • README

    raeadc74 r13ee8f2  
    1818BarnOwl currently requires the following perl modules off of CPAN:
    1919
     20AnyEvent
    2021PAR
    2122Net::DNS
     
    3031The IRC module requires:
    3132
    32 Net::IRC
     33AnyEvent::IRC
    3334Class::Accessor
    3435
  • cmd.c

    rf25df21 r4c7c21f  
    1212
    1313int owl_cmddict_setup(owl_cmddict *cd) {
    14   if (0 != owl_cmddict_init(cd)) return(-1);
     14  owl_cmddict_init(cd);
    1515  if (0 != owl_cmddict_add_from_list(cd, commands_to_init)) return(-1);
    1616  return(0);
    1717}
    1818
    19 int owl_cmddict_init(owl_cmddict *cd) {
    20   if (owl_dict_create(cd)) return(-1);
    21   return(0);
     19void owl_cmddict_init(owl_cmddict *cd) {
     20  owl_dict_create(cd);
    2221}
    2322
     
    9998
    10099char *owl_cmddict_execute_argv(const owl_cmddict *cd, const owl_context *ctx, const char *const *argv, int argc) {
    101   GString *buf = g_string_new("");
    102   int i;
    103   char *retval;
    104 
    105   /* We weren't given a command line, so fabricate a valid one. */
    106   for(i = 0; i < argc; i++) {
    107     if (i != 0)
    108       g_string_append_c(buf, ' ');
    109     owl_string_append_quoted_arg(buf, argv[i]);
    110   }
    111 
    112   retval = _owl_cmddict_execute(cd, ctx, argv, argc, buf->str);
    113 
    114   g_string_free(buf, true);
     100  char *buff;
     101  char *retval = NULL;
     102
     103  buff = g_strjoinv(" ", (char**)argv);
     104  retval = _owl_cmddict_execute(cd, ctx, argv, argc, buff);
     105  g_free(buff);
     106
    115107  return retval;
    116108}
     
    142134void owl_cmd_cleanup(owl_cmd *cmd)
    143135{
    144   if (cmd->name) g_free(cmd->name);
    145   if (cmd->summary) g_free(cmd->summary);
    146   if (cmd->usage) g_free(cmd->usage);
    147   if (cmd->description) g_free(cmd->description);
    148   if (cmd->cmd_aliased_to) g_free(cmd->cmd_aliased_to);
     136  g_free(cmd->name);
     137  g_free(cmd->summary);
     138  g_free(cmd->usage);
     139  g_free(cmd->description);
     140  g_free(cmd->cmd_aliased_to);
    149141  if (cmd->cmd_perl) owl_perlconfig_cmd_cleanup(cmd);
    150142}
  • commands.c

    rc809f5e r3b8a563  
    12881288  }
    12891289  owl_function_nextmsg_full(filter, skip_deleted, last_if_none);
    1290   if (filter) g_free(filter);
     1290  g_free(filter);
    12911291  return(NULL);
    12921292}
     
    13181318  }
    13191319  owl_function_prevmsg_full(filter, skip_deleted, first_if_none);
    1320   if (filter) g_free(filter);
     1320  g_free(filter);
    13211321  return(NULL);
    13221322}
     
    16911691  commands = g_strsplit_set(newbuff, ";", 0);
    16921692  for (i = 0; commands[i] != NULL; i++) {
    1693     if (lastrv) {
    1694       g_free(lastrv);
    1695     }
     1693    g_free(lastrv);
    16961694    lastrv = owl_function_command(commands[i]);
    16971695  }
  • dict.c

    rf25df21 r4c7c21f  
    1515#define GROWBY 3 / 2
    1616
    17 int owl_dict_create(owl_dict *d) {
     17void owl_dict_create(owl_dict *d) {
    1818  d->size=0;
    1919  d->els=g_new(owl_dict_el, INITSIZE);
    2020  d->avail=INITSIZE;
    21   if (d->els==NULL) return(-1);
    22   return(0);
    2321}
    2422
     
    6058/* Appends dictionary keys to a list.  Duplicates the keys,
    6159 * so they will need to be freed by the caller. */
    62 int owl_dict_get_keys(const owl_dict *d, owl_list *l) {
     60void owl_dict_get_keys(const owl_dict *d, owl_list *l) {
    6361  int i;
    64   char *dupk;
    6562  for (i=0; i<d->size; i++) {
    66     if ((dupk = g_strdup(d->els[i].k)) == NULL) return(-1);
    67     owl_list_append_element(l, dupk);
     63    owl_list_append_element(l, g_strdup(d->els[i].k));
    6864  }
    69   return(0);
    7065}
    7166
     
    8479{
    8580  int pos, found;
    86   char *dupk;
    8781  found = _owl_dict_find_pos(d, k, &pos);
    8882  if (found && delete_on_replace) {
     
    9993      if (d->els==NULL) return(-1);
    10094    }
    101     if ((dupk = g_strdup(k)) == NULL) return(-1);
    10295    if (pos!=d->size) {
    10396      /* shift forward to leave us a slot */
     
    10699    }
    107100    d->size++;
    108     d->els[pos].k = dupk;
     101    d->els[pos].k = g_strdup(k);
    109102    d->els[pos].v = v;   
    110103    return(0);
  • editwin.c

    r47e0a6a r3b8a563  
    317317  }
    318318
    319   if (locktext)
    320     g_free(locktext);
     319  g_free(locktext);
    321320
    322321  oe_set_index(e, lock);
  • fmtext.c

    r4479497 r7b4f3be  
    184184}
    185185
    186 static void _owl_fmtext_update_colorpair(short fg, short bg, short *pair)
    187 {
    188   if (owl_global_get_hascolors(&g)) {
    189     *pair = owl_fmtext_get_colorpair(fg, bg);
    190   }
    191 }
    192 
    193186static void _owl_fmtext_wcolor_set(WINDOW *w, short pair)
    194187{
    195   if (owl_global_get_hascolors(&g)) {
     188  if (has_colors()) {
    196189      wcolor_set(w,pair,NULL);
    197190      wbkgdset(w, COLOR_PAIR(pair));
     
    221214  bg = default_bgcolor;
    222215  _owl_fmtext_wattrset(w, attr);
    223   _owl_fmtext_update_colorpair(fg, bg, &pair);
     216  pair = owl_fmtext_get_colorpair(fg, bg);
    224217  _owl_fmtext_wcolor_set(w, pair);
    225218
     
    270263      if (bg == OWL_COLOR_DEFAULT) bg = default_bgcolor;
    271264      _owl_fmtext_wattrset(w, attr);
    272       _owl_fmtext_update_colorpair(fg, bg, &pair);
     265      pair = owl_fmtext_get_colorpair(fg, bg);
    273266      _owl_fmtext_wcolor_set(w, pair);
    274267
     
    662655           continue */
    663656      } else if (!strcasecmp(buff, "@color")
    664                  && owl_global_get_hascolors(&g)
    665657                 && owl_global_is_colorztext(&g)) {
    666658        g_free(buff);
     
    820812    }
    821813  }
    822   if (owl_global_get_hascolors(&g)) {
     814  if (has_colors()) {
    823815    for(i = 0; i < 8; i++) {
    824816      short fg, bg;
     
    835827  owl_colorpair_mgr *cpmgr;
    836828  short pair;
     829
     830  if (!has_colors())
     831    return 0;
    837832
    838833  /* Sanity (Bounds) Check */
     
    852847  if (!(pair != -1 && pair < cpmgr->next)) {
    853848    /* If we didn't find a pair, search for a free one to assign. */
    854     pair = (cpmgr->next < COLOR_PAIRS) ? cpmgr->next : -1;
     849    pair = (cpmgr->next < owl_util_get_colorpairs()) ? cpmgr->next : -1;
    855850    if (pair != -1) {
    856851      /* We found a free pair, initialize it. */
  • keybinding.c

    rd07af84 r3b8a563  
    6969void owl_keybinding_delete(owl_keybinding *kb)
    7070{
    71   if (kb->keys) g_free(kb->keys);
    72   if (kb->desc) g_free(kb->desc);
    73   if (kb->command) g_free(kb->command);
     71  g_free(kb->keys);
     72  g_free(kb->desc);
     73  g_free(kb->command);
    7474  g_free(kb);
    7575}
  • keymap.c

    r47e0a6a r4c7c21f  
    99{
    1010  if (!name || !desc) return(-1);
    11   if ((km->name = g_strdup(name)) == NULL) return(-1);
    12   if ((km->desc = g_strdup(desc)) == NULL) return(-1);
    13   if (0 != owl_list_create(&km->bindings)) return(-1);
     11  km->name = g_strdup(name);
     12  km->desc = g_strdup(desc);
     13  owl_list_create(&km->bindings);
    1414  km->parent = NULL;
    1515  km->default_fn = default_fn;
     
    179179/* NOTE: keyhandler has private access to the internals of keymap */
    180180
    181 int owl_keyhandler_init(owl_keyhandler *kh)
    182 {
    183   if (0 != owl_dict_create(&kh->keymaps)) return(-1);
     181void owl_keyhandler_init(owl_keyhandler *kh)
     182{
     183  owl_dict_create(&kh->keymaps);
    184184  kh->active = NULL;
    185185  owl_keyhandler_reset(kh);
    186   return(0);
    187186}
    188187
  • list.c

    rddbbcffa rfda61d3  
    55#define GROWBY 3 / 2
    66
    7 int owl_list_create(owl_list *l)
     7void owl_list_create(owl_list *l)
    88{
    99  l->size=0;
    1010  l->list=g_new(void *, INITSIZE);
    1111  l->avail=INITSIZE;
    12   if (l->list==NULL) return(-1);
    13   return(0);
    1412}
    1513
  • logging.c

    rfe3b017 r7865479  
    151151  } else if (owl_message_is_type_jabber(m)) {
    152152    to = g_strdup_printf("jabber:%s", owl_message_get_recipient(m));
    153     owl_text_tr(to, '/', '_');
     153    g_strdelimit(to, "/", '_');
    154154  } else if (owl_message_is_type_aim(m)) {
    155155    char *temp2;
  • perl/lib/BarnOwl.pm

    rb120bd3 rf2d71cfa  
    3838use BarnOwl::Completion;
    3939use BarnOwl::Help;
     40use BarnOwl::AnyEvent;
     41
     42unshift @AnyEvent::REGISTRY, [BarnOwl => BarnOwl::AnyEvent::];
     43require AnyEvent;
    4044
    4145use List::Util qw(max);
  • perl/modules/IRC/lib/BarnOwl/Message/IRC.pm

    re04b7a1 r60b49a7  
    6666sub action {shift->{action}}
    6767sub reason {shift->{reason}}
     68sub old_nick {shift->{old_nick}};
    6869
    6970# display
     
    8081}
    8182
    82 sub login_extra { 
     83sub login_extra {
    8384    my $self = shift;
    8485    if ($self->action eq "quit") {
    8586        return $self->reason;
     87    } elsif ($self->action eq 'nick change') {
     88        return "was: " . $self->old_nick;
    8689    } else {
    8790        return $self->channel;
  • perl/modules/IRC/lib/BarnOwl/Module/IRC.pm

    r9620c8d r5c6d661  
    2020use BarnOwl::Module::IRC::Completion;
    2121
    22 use Net::IRC;
     22use AnyEvent::IRC;
    2323use Getopt::Long;
    2424use Encode;
     
    3030# Hash alias -> BarnOwl::Module::IRC::Connection object
    3131our %ircnets;
    32 our %channels;
    33 our %reconnect;
    3432
    3533sub startup {
     
    7068
    7169    register_commands();
    72     register_handlers();
    7370    BarnOwl::filter(qw{irc type ^IRC$ or ( type ^admin$ and adminheader ^IRC$ )});
    7471}
     
    7673sub shutdown {
    7774    for my $conn (values %ircnets) {
    78         $conn->conn->disconnect();
     75        $conn->conn->disconnect('Quitting');
    7976    }
    8077}
     
    9895        $list .= "\n";
    9996
    100         for my $chan (keys %channels) {
    101             next unless grep $_ eq $conn, @{$channels{$chan}};
     97        for my $chan (keys %{$conn->conn->{channel_list}}) {
    10298            $list .= "  $chan\n";
    10399        }
     
    105101
    106102    return $list;
    107 }
    108 
    109 #sub mainloop_hook {
    110 #    return unless defined $irc;
    111 #    eval {
    112 #        $irc->do_one_loop();
    113 #    };
    114 #    return;
    115 #}
    116 
    117 sub OwlProcess {
    118     return unless defined $irc;
    119     eval {
    120         $irc->do_one_loop();
    121     };
    122     return;
    123 }
    124 
    125 
    126 sub register_handlers {
    127     if(!$irc) {
    128         $irc = Net::IRC->new;
    129         $irc->timeout(0);
    130     }
    131103}
    132104
     
    406378    }
    407379
    408     my $conn = BarnOwl::Module::IRC::Connection->new($irc, $alias,
    409         Nick      => $nick,
    410         Server    => $host,
    411         Port      => $port,
    412         Username  => $username,
    413         Ircname   => $ircname,
    414         Port      => $port,
    415         Password  => $password,
    416         SSL       => $ssl
    417        );
    418 
    419     if ($conn->conn->connected) {
    420         $conn->connected("Connected to $alias as $nick");
    421     } else {
    422         die("IRC::Connection->connect failed: $!");
    423     }
    424 
     380    my $conn = BarnOwl::Module::IRC::Connection->new($alias, $host, $port, {
     381        nick      => $nick,
     382        user      => $username,
     383        real      => $ircname,
     384        password  => $password,
     385        SSL       => $ssl,
     386        timeout   => sub {0}
     387       });
     388    $ircnets{$alias} = $conn;
    425389    return;
    426390}
     
    429393    my $cmd = shift;
    430394    my $conn = shift;
    431     if ($conn->conn->connected) {
    432         $conn->conn->disconnect;
    433     } elsif ($reconnect{$conn->alias}) {
     395    if ($conn->conn->{socket}) {
     396        $conn->did_quit(1);
     397        $conn->conn->disconnect("Goodbye!");
     398    } elsif ($conn->{reconnect_timer}) {
    434399        BarnOwl::admin_message('IRC',
    435400                               "[" . $conn->alias . "] Reconnect cancelled");
    436401        $conn->cancel_reconnect;
     402        delete $ircnets{$conn->alias};
    437403    }
    438404}
     
    463429    for my $body (@msgs) {
    464430        if ($body =~ /^\/me (.*)/) {
    465             $conn->conn->me($to, Encode::encode('utf-8', $1));
     431            $conn->me($to, Encode::encode('utf-8', $1));
    466432            $body = '* '.$conn->nick.' '.$1;
    467433        } else {
    468             $conn->conn->privmsg($to, Encode::encode('utf-8', $body));
     434            $conn->conn->send_msg('privmsg', $to, Encode::encode('utf-8', $body));
    469435        }
    470436        my $msg = BarnOwl::Message->new(
     
    491457    my $target = shift;
    492458    $target ||= shift;
    493     $conn->conn->mode($target, @_);
     459    $conn->conn->send_msg(mode => $target, @_);
    494460    return;
    495461}
     
    499465    my $conn = shift;
    500466    my $chan = shift or die("Usage: $cmd channel\n");
    501     $channels{$chan} ||= [];
    502     push @{$channels{$chan}}, $conn;
    503     $conn->conn->join($chan, @_);
     467    $conn->conn->send_msg(join => $chan, @_);
    504468    return;
    505469}
     
    509473    my $conn = shift;
    510474    my $chan = shift;
    511     $channels{$chan} = [grep {$_ ne $conn} @{$channels{$chan} || []}];
    512     $conn->conn->part($chan);
     475    $conn->conn->send_msg(part => $chan);
    513476    return;
    514477}
     
    518481    my $conn = shift;
    519482    my $nick = shift or die("Usage: $cmd <new nick>\n");
    520     $conn->conn->nick($nick);
     483    $conn->conn->send_msg(nick => $nick);
    521484    return;
    522485}
     
    527490    my $chan = shift;
    528491    $conn->names_tmp([]);
    529     $conn->conn->names($chan);
     492    $conn->conn->send_msg(names => $chan);
    530493    return;
    531494}
     
    535498    my $conn = shift;
    536499    my $who = shift || die("Usage: $cmd <user>\n");
    537     $conn->conn->whois($who);
     500    $conn->conn->send_msg(whois => $who);
    538501    return;
    539502}
     
    542505    my $cmd = shift;
    543506    my $conn = shift;
    544     $conn->conn->motd;
     507    $conn->conn->send_msg('motd');
    545508    return;
    546509}
     
    560523    my $conn = shift;
    561524    my $who = shift || die("Usage: $cmd <user>\n");
    562     BarnOwl::error("WHO $cmd $conn $who");
    563     $conn->conn->who($who);
     525    $conn->conn->send_msg(who => $who);
    564526    return;
    565527}
     
    569531    my $conn = shift;
    570532    my $type = shift || die("Usage: $cmd <chiklmouy> [server] \n");
    571     $conn->conn->stats($type, @_);
     533    $conn->conn->send_msg(stats => $type, @_);
    572534    return;
    573535}
     
    577539    my $conn = shift;
    578540    my $chan = shift;
    579     $conn->conn->topic($chan, @_ ? join(" ", @_) : undef);
     541    $conn->conn->send_msg(topic => $chan, @_ ? join(" ", @_) : undef);
    580542    return;
    581543}
     
    584546    my $cmd = shift;
    585547    my $conn = shift;
    586     $conn->conn->sl(join(" ", @_));
     548    $conn->conn->send_msg(@_);
    587549    return;
    588550}
     
    591553########################### Utilities/Helpers ##################################
    592554################################################################################
     555
     556sub find_channel {
     557    my $channel = shift;
     558    my @found;
     559    for my $conn (values %ircnets) {
     560        if($conn->conn->{channel_list}{lc $channel}) {
     561            push @found, $conn;
     562        }
     563    }
     564    return $found[0] if(scalar @found == 1);
     565}
    593566
    594567sub mk_irc_command {
     
    614587            $channel = $ARGV[0];
    615588            if(defined($channel) && $channel =~ /^#/) {
    616                 if($channels{$channel} && @{$channels{$channel}} == 1) {
     589                if(my $c = find_channel($channel)) {
    617590                    shift @ARGV;
    618                     $conn = $channels{$channel}[0] unless $conn;
     591                    $conn ||= $c;
    619592                }
    620593            } elsif ($m && $m->type eq 'IRC' && !$m->is_private) {
     
    654627    my $allow_disconnected = shift;
    655628
    656     return $ircnets{$key} if exists $ircnets{$key};
    657     return $reconnect{$key} if $allow_disconnected && exists $reconnect{$key};
    658     die("No such ircnet: $key\n")
     629    my $conn = $ircnets{$key};
     630    die("No such ircnet: $key\n") unless $conn;
     631    if ($conn->conn->{registered} || $allow_disconnected) {
     632        return $conn;
     633    }
     634    die("[@{[$conn->alias]}] Not currently connected.");
    659635}
    660636
  • perl/modules/IRC/lib/BarnOwl/Module/IRC/Completion.pm

    r955a36e rdace02a  
    1111sub complete_networks { keys %BarnOwl::Module::IRC::ircnets }
    1212sub complete_dests    { keys %users, complete_channels() }
    13 sub complete_channels { keys %BarnOwl::Module::IRC::channels }
     13sub complete_channels {
     14    my %channels;
     15    for my $conn (values %BarnOwl::Module::IRC::ircnets) {
     16        for my $chan (keys %{$conn->conn->{channel_list}}) {
     17            $channels{$chan} = 1;
     18        }
     19    }
     20    return keys %channels;
     21}
    1422sub complete_nicks    { keys %users }
    1523sub complete_servers  { keys %servers }
  • perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm

    rfb6e8e3 r13ee8f2  
    1111=head1 DESCRIPTION
    1212
    13 This module is a wrapper around Net::IRC::Connection for BarnOwl's IRC
     13This module is a wrapper around AnyEvent::IRC::Client for BarnOwl's IRC
    1414support
    1515
    1616=cut
    1717
    18 use Net::IRC::Connection;
    19 
    20 use base qw(Class::Accessor Exporter);
    21 __PACKAGE__->mk_accessors(qw(conn alias channels motd names_tmp whois_tmp));
    22 our @EXPORT_OK = qw(&is_private);
     18use AnyEvent::IRC::Client;
     19use AnyEvent::IRC::Util qw(split_prefix prefix_nick encode_ctcp);
     20
     21use base qw(Class::Accessor);
     22use Exporter 'import';
     23__PACKAGE__->mk_accessors(qw(conn alias motd names_tmp whois_tmp
     24                             server autoconnect_channels
     25                             connect_args backoff did_quit));
     26our @EXPORT_OK = qw(is_private);
    2327
    2428use BarnOwl;
    2529use Scalar::Util qw(weaken);
    2630
    27 BEGIN {
    28     no strict 'refs';
    29     my @delegate = qw(nick server);
    30     for my $meth (@delegate) {
    31         *{"BarnOwl::Module::IRC::Connection::$meth"} = sub {
    32             shift->conn->$meth(@_);
    33         }
    34     }
    35 };
    36 
    3731sub new {
    3832    my $class = shift;
    39     my $irc = shift;
    4033    my $alias = shift;
    41     my %args = (@_);
    42     my $conn = Net::IRC::Connection->new($irc, %args);
     34    my $host  = shift;
     35    my $port  = shift;
     36    my $args  = shift;
     37    my $nick = $args->{nick};
     38    my $conn = AnyEvent::IRC::Client->new();
    4339    my $self = bless({}, $class);
    4440    $self->conn($conn);
     41    $self->autoconnect_channels([]);
    4542    $self->alias($alias);
    46     $self->channels([]);
     43    $self->server($host);
    4744    $self->motd("");
    4845    $self->names_tmp(0);
     46    $self->backoff(0);
    4947    $self->whois_tmp("");
    50 
    51     $self->conn->add_default_handler(sub { shift; $self->on_event(@_) });
    52     $self->conn->add_handler(['msg', 'notice', 'public', 'caction'],
    53             sub { shift; $self->on_msg(@_) });
    54     $self->conn->add_handler(['welcome', 'yourhost', 'created',
    55                               'luserclient', 'luserop', 'luserchannels', 'luserme',
    56                               'error'],
    57             sub { shift; $self->on_admin_msg(@_) });
    58     $self->conn->add_handler(['myinfo', 'map', 'n_local', 'n_global',
    59             'luserconns'],
    60             sub { });
    61     $self->conn->add_handler(motdstart => sub { shift; $self->on_motdstart(@_) });
    62     $self->conn->add_handler(motd      => sub { shift; $self->on_motd(@_) });
    63     $self->conn->add_handler(endofmotd => sub { shift; $self->on_endofmotd(@_) });
    64     $self->conn->add_handler(join      => sub { shift; $self->on_join(@_) });
    65     $self->conn->add_handler(part      => sub { shift; $self->on_part(@_) });
    66     $self->conn->add_handler(quit      => sub { shift; $self->on_quit(@_) });
    67     $self->conn->add_handler(disconnect => sub { shift; $self->on_disconnect(@_) });
    68     $self->conn->add_handler(nicknameinuse => sub { shift; $self->on_nickinuse(@_) });
    69     $self->conn->add_handler(cping     => sub { shift; $self->on_ping(@_) });
    70     $self->conn->add_handler(topic     => sub { shift; $self->on_topic(@_) });
    71     $self->conn->add_handler(topicinfo => sub { shift; $self->on_topicinfo(@_) });
    72     $self->conn->add_handler(namreply  => sub { shift; $self->on_namreply(@_) });
    73     $self->conn->add_handler(endofnames=> sub { shift; $self->on_endofnames(@_) });
    74     $self->conn->add_handler(endofwhois=> sub { shift; $self->on_endofwhois(@_) });
    75     $self->conn->add_handler(mode      => sub { shift; $self->on_mode(@_) });
    76     $self->conn->add_handler(nosuchchannel => sub { shift; $self->on_nosuchchannel(@_) });
     48    $self->did_quit(0);
     49
     50    if(delete $args->{SSL}) {
     51        $conn->enable_ssl;
     52    }
     53    $self->connect_args([$host, $port, $args]);
     54    $conn->connect($host, $port, $args);
     55    $conn->{heap}{parent} = $self;
     56    weaken($conn->{heap}{parent});
     57
     58    sub on {
     59        my $meth = "on_" . shift;
     60        return sub {
     61            my $conn = shift;
     62            return unless $conn->{heap}{parent};
     63            $conn->{heap}{parent}->$meth(@_);
     64        }
     65    }
     66
     67    # $self->conn->add_default_handler(sub { shift; $self->on_event(@_) });
     68    $self->conn->reg_cb(registered => on("connect"),
     69                        connfail   => sub { BarnOwl::error("Connection to $host failed!") },
     70                        disconnect => on("disconnect"),
     71                        publicmsg  => on("msg"),
     72                        privatemsg => on("msg"),
     73                        irc_error  => on("error"));
     74    for my $m (qw(welcome yourhost created
     75                  luserclient luserop luserchannels luserme
     76                  error)) {
     77        $self->conn->reg_cb("irc_$m" => on("admin_msg"));
     78    }
     79    $self->conn->reg_cb(irc_375       => on("motdstart"),
     80                        irc_372       => on("motd"),
     81                        irc_376       => on("endofmotd"),
     82                        irc_join      => on("join"),
     83                        irc_part      => on("part"),
     84                        irc_quit      => on("quit"),
     85                        irc_433       => on("nickinuse"),
     86                        channel_topic => on("topic"),
     87                        irc_333       => on("topicinfo"),
     88                        irc_353       => on("namreply"),
     89                        irc_366       => on("endofnames"),
     90                        irc_311       => on("whois"),
     91                        irc_312       => on("whois"),
     92                        irc_319       => on("whois"),
     93                        irc_320       => on("whois"),
     94                        irc_318       => on("endofwhois"),
     95                        irc_mode      => on("mode"),
     96                        irc_401       => on("nosuch"),
     97                        irc_402       => on("nosuch"),
     98                        irc_403       => on("nosuch"),
     99                        nick_change   => on("nick"),
     100                        ctcp_action   => on("ctcp_action"),
     101                        'irc_*' => sub { BarnOwl::debug("IRC: " . $_[1]->{command} . " " .
     102                                                        join(" ", @{$_[1]->{params}})) });
    77103
    78104    return $self;
     105}
     106
     107sub nick {
     108    my $self = shift;
     109    return $self->conn->nick;
    79110}
    80111
     
    83114    my $self = shift;
    84115    return $self->conn->socket;
     116}
     117
     118sub me {
     119    my ($self, $to, $msg) = @_;
     120    $self->conn->send_msg('privmsg', $to,
     121                          encode_ctcp(['ACTION', $msg]))
    85122}
    86123
     
    92129    my $self = shift;
    93130    my $evt = shift;
    94     return BarnOwl::Message->new(
     131    my %args = (
    95132        type        => 'IRC',
    96133        server      => $self->server,
    97134        network     => $self->alias,
    98         sender      => $evt->nick,
    99         hostname    => $evt->host,
    100         from        => $evt->from,
    101135        @_
    102136       );
     137    if ($evt) {
     138        my ($nick, $user, $host) = split_prefix($evt);
     139        $args{sender}   ||= $nick;
     140        $args{hostname} ||= $host if defined($host);
     141        $args{from}     ||= $evt->{prefix};
     142        $args{params}   ||= join(' ', @{$evt->{params}})
     143    }
     144    return BarnOwl::Message->new(%args);
    103145}
    104146
    105147sub on_msg {
    106     my ($self, $evt) = @_;
    107     my ($recipient) = $evt->to;
    108     my $body = strip_irc_formatting([$evt->args]->[0]);
    109     my $nick = $self->nick;
    110     $body = '* '.$evt->nick.' '.$body if $evt->type eq 'caction';
     148    my ($self, $recipient, $evt) = @_;
     149    my $body = strip_irc_formatting($evt->{params}->[1]);
     150    $self->handle_message($recipient, $evt, $body);
     151}
     152
     153sub on_ctcp_action {
     154    my ($self, $src, $target, $msg) = @_;
     155    my $body = strip_irc_formatting($msg);
     156    my $evt = {
     157        params => [$src],
     158        type   => 'privmsg',
     159        prefix => $src
     160       };
     161    $self->handle_message($target, $evt, "* $body");
     162}
     163
     164sub handle_message {
     165    my ($self, $recipient, $evt, $body) = @_;
    111166    my $msg = $self->new_message($evt,
    112167        direction   => 'in',
    113168        recipient   => $recipient,
    114         body => $body,
    115         $evt->type eq 'notice' ?
     169        body        => $body,
     170        ($evt->{command}||'') eq 'notice' ?
    116171          (notice     => 'true') : (),
    117172        is_private($recipient) ?
    118173          (private  => 'true') : (channel => $recipient),
    119174        replycmd    => BarnOwl::quote('irc-msg', '-a', $self->alias,
    120           (is_private($recipient) ? $evt->nick : $recipient)),
    121         replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, $evt->nick),
     175           (is_private($recipient) ? prefix_nick($evt) : $recipient)),
     176        replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, prefix_nick($evt)),
    122177       );
    123178
     
    125180}
    126181
    127 sub on_ping {
    128     my ($self, $evt) = @_;
    129     $self->conn->ctcp_reply($evt->nick, join (' ', ($evt->args)));
    130 }
    131182
    132183sub on_admin_msg {
    133184    my ($self, $evt) = @_;
    134     return if BarnOwl::Module::IRC->skip_msg($evt->type);
    135     BarnOwl::admin_message("IRC",
    136             BarnOwl::Style::boldify('IRC ' . $evt->type . ' message from '
     185    return if BarnOwl::Module::IRC->skip_msg($evt->{command});
     186    BarnOwl::admin_message("IRC",
     187            BarnOwl::Style::boldify('IRC ' . $evt->{command} . ' message from '
    137188                . $self->alias) . "\n"
    138             . strip_irc_formatting(join ' ', cdr($evt->args)));
     189            . strip_irc_formatting(join ' ', cdr($evt->{params})));
    139190}
    140191
    141192sub on_motdstart {
    142193    my ($self, $evt) = @_;
    143     $self->motd(join "\n", cdr($evt->args));
     194    $self->motd(join "\n", cdr(@{$evt->{params}}));
    144195}
    145196
    146197sub on_motd {
    147198    my ($self, $evt) = @_;
    148     $self->motd(join "\n", $self->motd, cdr($evt->args));
     199    $self->motd(join "\n", $self->motd, cdr(@{$evt->{params}}));
    149200}
    150201
    151202sub on_endofmotd {
    152203    my ($self, $evt) = @_;
    153     $self->motd(join "\n", $self->motd, cdr($evt->args));
     204    $self->motd(join "\n", $self->motd, cdr(@{$evt->{params}}));
    154205    BarnOwl::admin_message("IRC",
    155206            BarnOwl::Style::boldify('MOTD for ' . $self->alias) . "\n"
     
    159210sub on_join {
    160211    my ($self, $evt) = @_;
     212    my $chan = $evt->{params}[0];
    161213    my $msg = $self->new_message($evt,
    162214        loginout   => 'login',
    163215        action     => 'join',
    164         channel    => $evt->to,
    165         replycmd   => BarnOwl::quote('irc-msg', '-a', $self->alias, $evt->to),
    166         replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, $evt->nick),
     216        channel    => $chan,
     217        replycmd   => BarnOwl::quote('irc-msg', '-a', $self->alias, $chan),
     218        replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, prefix_nick($evt)),
    167219        );
    168220    BarnOwl::queue_message($msg);
    169     push @{$self->channels}, $evt->to;
    170221}
    171222
    172223sub on_part {
    173224    my ($self, $evt) = @_;
     225    my $chan = $evt->{params}[0];
    174226    my $msg = $self->new_message($evt,
    175227        loginout   => 'logout',
    176228        action     => 'part',
    177         channel    => $evt->to,
    178         replycmd   => BarnOwl::quote('irc-msg', '-a', $self->alias, $evt->to),
    179         replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, $evt->nick),
     229        channel    => $chan,
     230        replycmd   => BarnOwl::quote('irc-msg', '-a', $self->alias, $chan),
     231        replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, prefix_nick($evt)),
    180232        );
    181233    BarnOwl::queue_message($msg);
    182     $self->channels([ grep {$_ ne $evt->to} @{$self->channels}]);
    183234}
    184235
     
    188239        loginout   => 'logout',
    189240        action     => 'quit',
    190         from       => $evt->to,
    191         reason     => [$evt->args]->[0],
    192         replycmd   => BarnOwl::quote('irc-msg', '-a', $self->alias, $evt->nick),
    193         replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, $evt->nick),
     241        from       => $evt->{prefix},
     242        reason     => $evt->{params}->[0],
     243        replycmd   => BarnOwl::quote('irc-msg', '-a', $self->alias, prefix_nick($evt)),
     244        replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, prefix_nick($evt)),
    194245        );
    195246    BarnOwl::queue_message($msg);
     
    198249sub disconnect {
    199250    my $self = shift;
    200     delete $BarnOwl::Module::IRC::ircnets{$self->alias};
    201     for my $k (keys %BarnOwl::Module::IRC::channels) {
    202         my @conns = grep {$_ ne $self} @{$BarnOwl::Module::IRC::channels{$k}};
    203         if(@conns) {
    204             $BarnOwl::Module::IRC::channels{$k} = \@conns;
    205         } else {
    206             delete $BarnOwl::Module::IRC::channels{$k};
    207         }
    208     }
    209     BarnOwl::remove_io_dispatch($self->{FD});
     251    $self->conn->disconnect;
     252}
     253
     254sub on_disconnect {
     255    my ($self, $why) = @_;
     256    BarnOwl::admin_message('IRC',
     257                           "[" . $self->alias . "] Disconnected from server: $why");
    210258    $self->motd("");
    211 }
    212 
    213 sub on_disconnect {
    214     my ($self, $evt) = @_;
    215     $self->disconnect;
    216     BarnOwl::admin_message('IRC',
    217                            "[" . $self->alias . "] Disconnected from server");
    218     if ($evt->format and $evt->format eq "error") {
     259    if (!$self->did_quit) {
    219260        $self->schedule_reconnect;
    220261    } else {
    221         $self->channels([]);
    222     }
     262        delete $BarnOwl::Module::IRC::ircnets{$self->alias};
     263    }
     264}
     265
     266sub on_error {
     267    my ($self, $evt) = @_;
     268    BarnOwl::admin_message('IRC',
     269                           "[" . $self->alias . "] " .
     270                           "Error: " . join(" ", @{$evt->{params}}));
    223271}
    224272
     
    227275    BarnOwl::admin_message("IRC",
    228276                           "[" . $self->alias . "] " .
    229                            [$evt->args]->[1] . ": Nick already in use");
    230     $self->disconnect unless $self->motd;
     277                           $evt->{params}->[1] . ": Nick already in use");
     278}
     279
     280sub on_nick {
     281    my ($self, $old_nick, $new_nick, $is_me) = @_;
     282    if ($is_me) {
     283        BarnOwl::admin_message("IRC",
     284                               "[" . $self->alias . "] " .
     285                               "You are now known as $new_nick");
     286    } else {
     287        my $msg = $self->new_message('',
     288            loginout   => 'login',
     289            action     => 'nick change',
     290            from       => $new_nick,
     291            sender     => $new_nick,
     292            replycmd   => BarnOwl::quote('irc-msg', '-a', $self->alias,
     293                                         $new_nick),
     294            replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias,
     295                                             $new_nick),
     296            old_nick   => $old_nick);
     297        BarnOwl::queue_message($msg);
     298    }
    231299}
    232300
    233301sub on_topic {
    234     my ($self, $evt) = @_;
    235     my @args = $evt->args;
    236     if (scalar @args > 1) {
     302    my ($self, $channel, $topic, $who) = @_;
     303    if ($channel) {
    237304        BarnOwl::admin_message("IRC",
    238                 "Topic for $args[1] on " . $self->alias . " is $args[2]");
     305                "Topic for $channel on " . $self->alias . " is $topic");
    239306    } else {
    240307        BarnOwl::admin_message("IRC",
    241                 "Topic changed to $args[0]");
     308                "Topic changed to $channel");
    242309    }
    243310}
     
    245312sub on_topicinfo {
    246313    my ($self, $evt) = @_;
    247     my @args = $evt->args;
     314    my @args = @{$evt->{params}};
    248315    BarnOwl::admin_message("IRC",
    249316        "Topic for $args[1] set by $args[2] at " . localtime($args[3]));
     
    257324    my ($self, $evt) = @_;
    258325    return unless $self->names_tmp;
    259     $self->names_tmp([@{$self->names_tmp}, split(' ', [$evt->args]->[3])]);
     326    $self->names_tmp([@{$self->names_tmp},
     327                      map {prefix_nick($_)} split(' ', $evt->{params}[3])]);
    260328}
    261329
     
    272340    my ($self, $evt) = @_;
    273341    return unless $self->names_tmp;
    274     my $names = BarnOwl::Style::boldify("Members of " . [$evt->args]->[1] . ":\n");
     342    my $names = BarnOwl::Style::boldify("Members of " . $evt->{params}->[1] . ":\n");
    275343    for my $name (sort {cmp_user($a, $b)} @{$self->names_tmp}) {
    276344        $names .= "  $name\n";
     
    282350sub on_whois {
    283351    my ($self, $evt) = @_;
     352    my %names = (
     353        311 => 'user',
     354        312 => 'server',
     355        319 => 'channels',
     356        330 => 'whowas',
     357       );
    284358    $self->whois_tmp(
    285       $self->whois_tmp . "\n" . $evt->type . ":\n  " .
    286       join("\n  ", cdr(cdr($evt->args))) . "\n"
    287     );
     359        $self->whois_tmp . "\n" . $names{$evt->{command}} . ":\n  " .
     360        join("\n  ", cdr(cdr(@{$evt->{params}}))) . "\n"
     361       );
    288362}
    289363
     
    291365    my ($self, $evt) = @_;
    292366    BarnOwl::popless_ztext(
    293         BarnOwl::Style::boldify("/whois for " . [$evt->args]->[1] . ":\n") .
     367        BarnOwl::Style::boldify("/whois for " . $evt->{params}->[1] . ":\n") .
    294368        $self->whois_tmp
    295369    );
     
    300374    my ($self, $evt) = @_;
    301375    BarnOwl::admin_message("IRC",
    302                            "[" . $self->alias . "] User " . ($evt->nick) . + " set mode " .
    303                            join(" ", $evt->args) . "on " . $evt->to->[0]
     376                           "[" . $self->alias . "] User " . (prefix_nick($evt)) . + " set mode " .
     377                           join(" ", cdr(@{$evt->{params}})) . " on " . $evt->{params}->[0]
    304378                          );
    305379}
    306380
    307 sub on_nosuchchannel {
    308     my ($self, $evt) = @_;
     381sub on_nosuch {
     382    my ($self, $evt) = @_;
     383    my %things = (401 => 'nick', 402 => 'server', 403 => 'channel');
    309384    BarnOwl::admin_message("IRC",
    310385                           "[" . $self->alias . "] " .
    311                            "No such channel: " . [$evt->args]->[1])
     386                           "No such @{[$things{$evt->{command}}]}: @{[$evt->{params}->[1]]}")
    312387}
    313388
     
    323398sub schedule_reconnect {
    324399    my $self = shift;
    325     my $interval = shift || 5;
    326     delete $BarnOwl::Module::IRC::ircnets{$self->alias};
    327     $BarnOwl::Module::IRC::reconnect{$self->alias} = $self;
     400    my $interval = $self->backoff;
     401    if ($interval) {
     402        $interval *= 2;
     403        $interval = 60*5 if $interval > 60*5;
     404    } else {
     405        $interval = 5;
     406    }
     407    $self->backoff($interval);
     408
    328409    my $weak = $self;
    329410    weaken($weak);
     
    343424sub cancel_reconnect {
    344425    my $self = shift;
    345     delete $BarnOwl::Module::IRC::reconnect{$self->alias};
     426
    346427    if (defined $self->{reconnect_timer}) {
    347428        $self->{reconnect_timer}->stop;
    348429    }
    349430    delete $self->{reconnect_timer};
     431}
     432
     433sub on_connect {
     434    my $self = shift;
     435    $self->connected("Connected to " . $self->alias . " as " . $self->nick)
    350436}
    351437
     
    355441    BarnOwl::admin_message("IRC", $msg);
    356442    $self->cancel_reconnect;
    357     $BarnOwl::Module::IRC::ircnets{$self->alias} = $self;
    358     my $fd = $self->getSocket()->fileno();
    359     BarnOwl::add_io_dispatch($fd, 'r', \&BarnOwl::Module::IRC::OwlProcess);
    360     $self->{FD} = $fd;
     443    if ($self->autoconnect_channels) {
     444        for my $c (@{$self->autoconnect_channels}) {
     445            $self->conn->send_msg(join => $c);
     446        }
     447        $self->autoconnect_channels([]);
     448    }
     449    $self->conn->enable_ping(60, sub {
     450                                 $self->on_disconnect("Connection timed out.");
     451                                 $self->schedule_reconnect;
     452                             });
     453    $self->backoff(0);
    361454}
    362455
    363456sub reconnect {
    364457    my $self = shift;
    365     my $backoff = shift;
    366 
    367     $self->conn->connect;
    368     if ($self->conn->connected) {
    369         $self->connected("Reconnected to ".$self->alias);
    370         my @channels = @{$self->channels};
    371         $self->channels([]);
    372         $self->conn->join($_) for @channels;
    373         return;
    374     }
    375 
    376     $backoff *= 2;
    377     $backoff = 60*5 if $backoff > 60*5;
    378     $self->schedule_reconnect( $backoff );
     458    my $backoff = $self->backoff;
     459
     460    $self->autoconnect_channels([keys(%{$self->{channel_list}})]);
     461    $self->conn->connect(@{$self->connect_args});
    379462}
    380463
  • perlconfig.c

    rf25df21 r3b8a563  
    403403  }
    404404
     405  sv_setpv(get_sv("BarnOwl::VERSION", TRUE), OWL_VERSION_STRING);
     406
    405407  /* Add the system lib path to @INC */
    406408  inc = get_av("INC", 0);
     
    465467                                           :"BarnOwl::_receive_msg_legacy_wrap", m);
    466468  }
    467   if (ptr) g_free(ptr);
     469  g_free(ptr);
    468470}
    469471
     
    476478                                           :"BarnOwl::Hooks::_new_msg", m);
    477479  }
    478   if (ptr) g_free(ptr);
     480  g_free(ptr);
    479481}
    480482
  • perlglue.xs

    rf25df21 r3b8a563  
    4343                        rv = owl_function_command(cmd);
    4444                } else {
    45                         argv = g_new(const char *, items + 1);
     45                        /* Ensure this is NULL-terminated. */
     46                        argv = g_new0(const char *, items + 1);
    4647                        argv[0] = cmd;
    4748                        for(i = 1; i < items; i++) {
     
    5657                RETVAL
    5758        CLEANUP:
    58                 if (rv) g_free(rv);
     59                g_free(rv);
    5960
    6061SV *
     
    113114                RETVAL
    114115        CLEANUP:
    115                 if (rv) g_free(rv);
     116                g_free(rv);
    116117
    117118const utf8 *
     
    140141                RETVAL
    141142    CLEANUP:
    142                 if (rv) g_free(rv);
     143                g_free(rv);
    143144
    144145void
     
    323324                RETVAL
    324325        CLEANUP:
    325                 if (rv)
    326                         g_free(rv);
     326                g_free(rv);
    327327
    328328void
  • tester.c

    rf25df21 r4c7c21f  
    233233
    234234  printf("# BEGIN testing owl_dict\n");
    235   FAIL_UNLESS("create", 0==owl_dict_create(&d));
     235  owl_dict_create(&d);
    236236  FAIL_UNLESS("insert b", 0==owl_dict_insert_element(&d, "b", bv, owl_dict_noop_delete));
    237237  FAIL_UNLESS("insert d", 0==owl_dict_insert_element(&d, "d", dv, owl_dict_noop_delete));
     
    249249  FAIL_UNLESS("get_size", 3==owl_dict_get_size(&d));
    250250  owl_list_create(&l);
    251   FAIL_UNLESS("get_keys", 0==owl_dict_get_keys(&d, &l));
     251  owl_dict_get_keys(&d, &l);
    252252  FAIL_UNLESS("get_keys result size", 3==owl_list_get_size(&l));
    253253 
  • text.c

    r42ee1be r7865479  
    275275  g_strfreev(split);
    276276  return out;
    277 }
    278 
    279 /* replace all instances of character a in buff with the character
    280  * b.  buff must be null terminated.
    281  */
    282 void owl_text_tr(char *buff, char a, char b)
    283 {
    284   int i;
    285 
    286   owl_function_debugmsg("In: %s", buff);
    287   for (i=0; buff[i]!='\0'; i++) {
    288     if (buff[i]==a) buff[i]=b;
    289   }
    290   owl_function_debugmsg("Out: %s", buff);
    291277}
    292278
  • util.c

    re56303f r9efa5bd  
    715715}
    716716
     717int owl_util_get_colorpairs(void) {
     718#ifndef NCURSES_EXT_COLORS
     719  /* Without ext-color support (an ABI change), ncurses only supports 256
     720   * different color pairs. However, it gives us a larger number even if your
     721   * ncurses is compiled without ext-color. */
     722  return MIN(COLOR_PAIRS, 256);
     723#else
     724  return COLOR_PAIRS;
     725#endif
     726}
     727
    717728gulong owl_dirty_window_on_signal(owl_window *w, gpointer sender, const gchar *detailed_signal)
    718729{
  • variable.c

    rf25df21 r4c7c21f  
    3030        NULL, NULL, NULL, NULL, NULL, NULL }
    3131
    32 #define OWLVAR_STRING_FULL(name,default,summary,description,validate,set,get) \
    33         { name, OWL_VARIABLE_STRING, default, 0, "<string>", summary,description, NULL, \
     32#define OWLVAR_STRING_FULL(name,default,validset,summary,description,validate,set,get) \
     33        { name, OWL_VARIABLE_STRING, default, 0, validset, summary,description, NULL, \
    3434        validate, set, NULL, get, NULL, NULL }
    3535
     
    266266                 "" ),
    267267
    268   OWLVAR_STRING_FULL( "tty" /* %OwlVarStub */, "", "tty name for zephyr location", "",
     268  OWLVAR_STRING_FULL( "tty" /* %OwlVarStub */, "", "<string>", "tty name for zephyr location", "",
    269269                      NULL, owl_variable_tty_set, NULL),
    270270
     
    370370               "delete a message right as it came in.\n" ),
    371371
     372  OWLVAR_STRING_FULL( "default_exposure" /* %OwlVarStub */, "",
     373                      "none,opstaff,realm-visible,realm-announced,net-visible,net-announced",
     374                      "controls the persistent value for exposure",
     375                      "The default exposure level corresponds to the Zephyr exposure value\n"
     376                      "in ~/.zephyr.vars.  Defaults to realm-visible if there is no value in\n"
     377                      "~/.zephyr.vars.\n"
     378                      "See the description of exposure for the values this can be.",
     379                      NULL, owl_variable_default_exposure_set, owl_variable_default_exposure_get ),
     380
     381  OWLVAR_STRING_FULL( "exposure" /* %OwlVarStub */, "",
     382                      "none,opstaff,realm-visible,realm-announced,net-visible,net-announced",
     383                      "controls who can zlocate you",
     384                      "The exposure level, defaulting to the value of default_exposure,\n"
     385                      "can be one of the following (from least exposure to widest exposure,\n"
     386                      "as listed in zctl(1)):\n"
     387                      "\n"
     388                      "   none            - This completely disables Zephyr for the user. \n"
     389                      "                     The user is not registered with Zephyr.  No user\n"
     390                      "                     location information is retained by Zephyr.  No\n"
     391                      "                     login or logout announcements will be sent.  No\n"
     392                      "                     subscriptions will be entered for the user, and\n"
     393                      "                     no notices will be displayed by zwgc(1).\n"
     394                      "   opstaff         - The user is registered with Zephyr.  No login or\n"
     395                      "                     logout announcements will be sent, and location\n"
     396                      "                     information will only be visible to Operations\n"
     397                      "                     staff.  Default subscriptions and any additional\n"
     398                      "                     personal subscriptions will be entered for the\n"
     399                      "                     user.\n"
     400                      "   realm-visible   - The user is registered with Zephyr.  User\n"
     401                      "                     location information is retained by Zephyr and\n"
     402                      "                     made available only to users within the user’s\n"
     403                      "                     Kerberos realm.  No login or logout\n"
     404                      "                     announcements will be sent.  This is the system\n"
     405                      "                     default.  Default subscriptions and any\n"
     406                      "                     additional personal subscriptions will be\n"
     407                      "                     entered for the user.\n"
     408                      "   realm-announced - The user is registered with Zephyr.  User\n"
     409                      "                     location information is retained by Zephyr and\n"
     410                      "                     made available only to users authenticated\n"
     411                      "                     within the user’s Kerberos realm.  Login and\n"
     412                      "                     logout announcements will be sent, but only to\n"
     413                      "                     users within the user’s Kerberos realm who have\n"
     414                      "                     explicitly requested such via subscriptions. \n"
     415                      "                     Default subscriptions and any additional\n"
     416                      "                     personal subscriptions will be entered for the\n"
     417                      "                     user.\n"
     418                      "   net-visible     - The user is registered with Zephyr.  User\n"
     419                      "                     location information is retained by Zephyr and\n"
     420                      "                     made available to any authenticated user who\n"
     421                      "                     requests such.  Login and logout announcements\n"
     422                      "                     will be sent only to users within the user’s\n"
     423                      "                     Kerberos realm who have explicitly requested\n"
     424                      "                     such via subscriptions.  Default subscriptions\n"
     425                      "                     and any additional personal subscriptions will\n"
     426                      "                     be entered for the user.\n"
     427                      "   net-announced   - The user is registered with Zephyr.  User\n"
     428                      "                     location information is retained by Zephyr and\n"
     429                      "                     made available to any authenticated user who\n"
     430                      "                     requests such.  Login and logout announcements\n"
     431                      "                     will be sent to any user has requested such. \n"
     432                      "                     Default subscriptions and any additional\n"
     433                      "                     personal subscriptions will be entered for the\n"
     434                      "                     user.\n",
     435                      NULL, owl_variable_exposure_set, NULL /* use default for get */ ),
     436
    372437  /* This MUST be last... */
    373438  { NULL, 0, NULL, 0, NULL, NULL, NULL, NULL,
     
    470535}
    471536
     537int owl_variable_default_exposure_set(owl_variable *v, const void *newval)
     538{
     539  return owl_zephyr_set_default_exposure(newval);
     540}
     541
     542const void *owl_variable_default_exposure_get(const owl_variable *v)
     543{
     544  return owl_zephyr_get_default_exposure();
     545}
     546
     547int owl_variable_exposure_set(owl_variable *v, const void *newval)
     548{
     549  int ret = owl_zephyr_set_exposure(newval);
     550  if (ret != 0)
     551    return ret;
     552  return owl_variable_string_set_default(v, owl_zephyr_normalize_exposure(newval));
     553}
    472554
    473555/**************************************************************************/
     
    477559int owl_variable_dict_setup(owl_vardict *vd) {
    478560  owl_variable *var, *cur;
    479   if (owl_dict_create(vd)) return(-1);
     561  owl_dict_create(vd);
    480562  for (var = variables_to_init; var->name != NULL; var++) {
    481563    cur = g_new(owl_variable, 1);
     
    559641
    560642void owl_variable_update(owl_variable *var, const char *summary, const char *desc) {
    561   if(var->summary) g_free(var->summary);
     643  g_free(var->summary);
    562644  var->summary = g_strdup(summary);
    563   if(var->description) g_free(var->description);
     645  g_free(var->description);
    564646  var->description = g_strdup(desc);
    565647}
     
    569651  if(old) {
    570652    owl_variable_update(old, summ, desc);
    571     if(old->pval_default) g_free(old->pval_default);
     653    g_free(old->pval_default);
    572654    old->pval_default = g_strdup(initval);
    573655  } else {
     
    688770  }
    689771  if (msg && v->get_tostring_fn) {
    690     tostring = v->get_tostring_fn(v, v->val);
     772    tostring = v->get_tostring_fn(v, v->get_fn(v));
    691773    owl_function_makemsg("%s = '%s'", name, tostring);
    692774    g_free(tostring);
     
    726808  v = owl_dict_find_element(d, name);
    727809  if (v == NULL || !v->get_tostring_fn) return NULL;
    728   return v->get_tostring_fn(v, v->val);
     810  return v->get_tostring_fn(v, v->get_fn(v));
    729811}
    730812
     
    862944void owl_variable_delete_default(owl_variable *v)
    863945{
    864   if (v->val) g_free(v->val);
     946  g_free(v->val);
    865947}
    866948
     
    9941076    if (!v->validate_fn(v, newval)) return(-1);
    9951077  }
    996   if (v->val) g_free(v->val);
     1078  g_free(v->val);
    9971079  v->val = g_strdup(newval);
    9981080  return(0);
  • view.c

    rd4927a7 r3b8a563  
    160160{
    161161  owl_list_cleanup(&v->ml.list, NULL);
    162   if (v->name) g_free(v->name);
     162  g_free(v->name);
    163163}
  • viewwin.c

    r237d02c r4fd211f  
    150150
    151151  if (!owl_viewwin_search(v, owl_global_get_search_re(&g), consider_current, direction))
    152     owl_function_error("No more matches");
     152    owl_function_makemsg("No more matches");
    153153  return NULL;
    154154}
     
    172172  if (!owl_viewwin_search(data->v, owl_global_get_search_re(&g),
    173173                          consider_current, data->direction))
    174     owl_function_error("No matches");
     174    owl_function_makemsg("No matches");
    175175}
    176176
  • zcrypt.c

    r1dd285b r3b8a563  
    476476
    477477  for(i = 0; i < MAX_SEARCH; i++) {
    478     if(varname[i] != NULL) {
    479       g_free(varname[i]);
    480     }
    481   }
    482 
    483   if(filename != NULL) {
    484     g_free(filename);
    485   }
     478    g_free(varname[i]);
     479  }
     480
     481  g_free(filename);
    486482
    487483  return keyfile;
     
    773769  err = call_filter("gpg", argv, in, &out, &status);
    774770  if(err || status) {
    775     if(out) g_free(out);
     771    g_free(out);
    776772    return FALSE;
    777773  }
     
    856852  err = call_filter("gpg", argv, in, &out, &status);
    857853  if(err || status) {
    858     if(out) g_free(out);
     854    g_free(out);
    859855    return FALSE;
    860856  }
  • zwrite.c

    r3f52e14 r3b8a563  
    185185void owl_zwrite_set_message_raw(owl_zwrite *z, const char *msg)
    186186{
    187   if (z->message) g_free(z->message);
     187  g_free(z->message);
    188188  z->message = owl_validate_utf8(msg);
    189189}
     
    195195  char *tmp = NULL, *tmp2;
    196196
    197   if (z->message) g_free(z->message);
     197  g_free(z->message);
    198198
    199199  j=owl_list_get_size(&(z->recips));
     
    289289void owl_zwrite_set_opcode(owl_zwrite *z, const char *opcode)
    290290{
    291   if (z->opcode) g_free(z->opcode);
     291  g_free(z->opcode);
    292292  z->opcode=owl_validate_utf8(opcode);
    293293}
     
    306306void owl_zwrite_set_zsig(owl_zwrite *z, const char *zsig)
    307307{
    308   if(z->zsig) g_free(z->zsig);
     308  g_free(z->zsig);
    309309  z->zsig = g_strdup(zsig);
    310310}
     
    353353{
    354354  owl_list_cleanup(&(z->recips), &g_free);
    355   if (z->cmd) g_free(z->cmd);
    356   if (z->zwriteline) g_free(z->zwriteline);
    357   if (z->class) g_free(z->class);
    358   if (z->inst) g_free(z->inst);
    359   if (z->opcode) g_free(z->opcode);
    360   if (z->realm) g_free(z->realm);
    361   if (z->message) g_free(z->message);
    362   if (z->zsig) g_free(z->zsig);
     355  g_free(z->cmd);
     356  g_free(z->zwriteline);
     357  g_free(z->class);
     358  g_free(z->inst);
     359  g_free(z->opcode);
     360  g_free(z->realm);
     361  g_free(z->message);
     362  g_free(z->zsig);
    363363}
    364364
Note: See TracChangeset for help on using the changeset viewer.