Changeset a006d475


Ignore:
Timestamp:
Jun 19, 2011, 12:04:19 AM (13 years ago)
Author:
GitHub Merge Button <merge-button@github.com>
Parents:
e93dd78 (diff), 28da2da (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 28da2daf4548256b44d1fd586200032e96462d57 into e93dd785a2e76aa0dc14ecd56fd2c61b3598bc96
Files:
2 added
42 edited

Legend:

Unmodified
Added
Removed
  • barnowl

    rde18326 r9b7b535  
    77EXE="$0.bin"
    88
    9 if ! test -x "$EXE"; then
     9if test ! -x "$EXE"; then
    1010    echo "Cannot find barnowl.bin" >&2
    1111    exit 1
    1212fi
    1313
    14 export BARNOWL_DATA_DIR="$SRCDIR/perl/"
    15 export BARNOWL_BIN_DIR="$SRCDIR/"
     14BARNOWL_DATA_DIR="$SRCDIR/perl/"
     15BARNOWL_BIN_DIR="$SRCDIR/"
     16export BARNOWL_DATA_DIR
     17export BARNOWL_BIN_DIR
    1618exec "$EXE" "$@"
  • configure.ac

    rf97c1a6 ra006d475  
    88
    99AC_PROG_CC
     10AC_PROG_CC_C99
    1011
    1112AC_ARG_WITH([stack-protector],
     
    8081AC_HEADER_STDC
    8182AC_HEADER_SYS_WAIT
    82 AC_HEADER_STDBOOL
    83 AC_CHECK_HEADERS(strings.h sys/ioctl.h sys/filio.h unistd.h)
     83AC_CHECK_HEADERS(stdbool.h strings.h sys/ioctl.h sys/filio.h unistd.h)
    8484
    8585dnl Add CFLAGS for embeded perl
     
    143143                                 test "$HAVE_DES_ECB_ENCRYPT"])
    144144
    145 AM_CFLAGS="$AM_CFLAGS -D_XOPEN_SOURCE=500"
     145AM_CFLAGS="$AM_CFLAGS -D_XOPEN_SOURCE=600"
    146146dnl Define _BSD_SOURCE because zephyr needs caddr_t.
    147147AM_CFLAGS="$AM_CFLAGS -D_BSD_SOURCE"
  • libfaim/aim.h

    r63de71c r28da2da  
    1818
    1919#include "config.h"
    20 #ifdef HAVE_STDBOOL_H
    2120#include <stdbool.h>
    22 #else
    23 #ifndef HAVE__BOOL
    24 #define _Bool signed char
    25 #endif
    26 #define bool _Bool
    27 #define false 0
    28 #define true 1
    29 #define __bool_true_false_are_defined 1
    30 #endif  /* HAVE_STDBOOL_H */
    3121
    3222#include <stdio.h>
  • owl.h

    r33b6431b ra006d475  
    1414#include "compat/compat.h"
    1515
    16 #ifdef HAVE_STDBOOL_H
    1716#include <stdbool.h>
    18 #else
    19 #ifndef HAVE__BOOL
    20 #define _Bool signed char
    21 #endif
    22 #define bool _Bool
    23 #define false 0
    24 #define true 1
    25 #define __bool_true_false_are_defined 1
    26 #endif  /* HAVE_STDBOOL_H */
    2717
    2818#ifndef OWL_PERL
     19#define NCURSES_ENABLE_STDBOOL_H 1
    2920#include <curses.h>
    3021#include <panel.h>
  • scripts/locker-build

    r0fd5bd5 rf216307  
    102102    esac
    103103
    104     CFLAGS="-I$BARNOWL/include" \
    105         LDFLAGS="-L$BARNOWL/lib $opt_rpath$BARNOWL/lib" \
     104    CPPFLAGS="-I$BARNOWL/include -I/usr/athena/include" \
     105        LDFLAGS="-L$BARNOWL/lib -L/usr/athena/lib $opt_rpath$BARNOWL/lib" \
    106106        ./configure --exec-prefix="/mit/barnowl/arch/$ATHENA_SYS" \
    107107        --prefix="/mit/barnowl/builds/barnowl-$VERS" --mandir=/mit/barnowl/man \
  • window.h

    r4cc49bc ra006d475  
    55#include <glib-object.h>
    66
    7 #ifdef HAVE_STDBOOL_H
    87#include <stdbool.h>
    9 #else
    10 #ifndef HAVE__BOOL
    11 #define _Bool signed char
    12 #endif
    13 #define bool _Bool
    14 #define false 0
    15 #define true 1
    16 #define __bool_true_false_are_defined 1
    17 #endif  /* HAVE_STDBOOL_H */
    188
    199G_BEGIN_DECLS
  • 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
  • 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
  • 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}
  • cmd.c

    r6a71113 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
     
    135134void owl_cmd_cleanup(owl_cmd *cmd)
    136135{
    137   if (cmd->name) g_free(cmd->name);
    138   if (cmd->summary) g_free(cmd->summary);
    139   if (cmd->usage) g_free(cmd->usage);
    140   if (cmd->description) g_free(cmd->description);
    141   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);
    142141  if (cmd->cmd_perl) owl_perlconfig_cmd_cleanup(cmd);
    143142}
  • commands.c

    rc809f5e r697221f  
    281281  OWLCMD_ARGS("punt", owl_command_punt, OWL_CTX_ANY,
    282282              "suppress an arbitrary filter",
    283               "punt <filter-text>",
    284               "punt <filter-text (multiple words)>\n"
     283              "punt <filter-name>\n"
     284              "punt <filter-text (multiple words)>",
    285285              "The punt command will suppress messages to the specified\n"
    286286              "filter\n\n"
     
    289289  OWLCMD_ARGS("unpunt", owl_command_unpunt, OWL_CTX_ANY,
    290290              "remove an entry from the punt list",
    291               "unpunt <filter-text>\n"
    292               "unpunt <filter-text>\n"
    293               "unpunt <number>\n",
     291              "unpunt <number>\n"
     292              "unpunt <filter-name>\n"
     293              "unpunt <filter-text (multiple words)>",
    294294              "The unpunt command will remove an entry from the puntlist.\n"
    295               "The first two forms correspond to the first two forms of the :punt\n"
    296               "command. The latter allows you to remove a specific entry from the\n"
     295              "The last two forms correspond to the two forms of the :punt\n"
     296              "command. The first allows you to remove a specific entry from\n"
    297297              "the list (see :show zpunts)\n\n"
    298298              "SEE ALSO:  punt, zpunt, zunpunt, show zpunts\n"),
     
    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  }
     
    24662464  owl_list * fl;
    24672465  owl_filter * f;
    2468   char * text;
    24692466  int i;
    24702467
     
    24822479        return;
    24832480      } else {
    2484         owl_function_error("No such filter number: %d", i+1);
     2481        owl_function_makemsg("No such filter number: %d.", i+1);
    24852482      }
    24862483    }
    2487     text = owl_string_build_quoted("filter %q", argv[1]);
    2488     owl_function_punt(text, unpunt);
    2489     g_free(text);
     2484    const char *filter[] = {"filter", argv[1]};
     2485    owl_function_punt(2, filter, unpunt);
    24902486  } else {
    2491     owl_function_punt(skiptokens(buff, 1), unpunt);
     2487    /* Pass in argv[1]..argv[argc-1]. */
     2488    owl_function_punt(argc - 1, argv + 1, unpunt);
    24922489  }
    24932490}
  • 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);
  • 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}
  • 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. */
  • functions.c

    r4fd211f r259e60a8  
    3232  char *rv;
    3333  rv=owl_function_command(cmdbuff);
    34   if (rv) g_free(rv);
     34  g_free(rv);
    3535}
    3636
     
    453453
    454454  if (rv || status) {
    455     if(cryptmsg) g_free(cryptmsg);
     455    g_free(cryptmsg);
    456456    g_free(old_msg);
    457457    owl_function_error("Error in zcrypt, possibly no key found.  Message not sent.");
     
    991991  /* execute the commands in shutdown */
    992992  ret = owl_perlconfig_execute("BarnOwl::Hooks::_shutdown();");
    993   if (ret) g_free(ret);
     993  g_free(ret);
    994994
    995995  /* signal our child process, if any */
     
    14081408#ifdef HAVE_LIBZEPHYR
    14091409    if (owl_message_is_direction_in(m)) {
    1410       char *ptr, tmpbuff[1024];
    1411       int i, j, fields, len;
     1410      char *tmpbuff;
     1411      int i, fields;
    14121412
    14131413      n=owl_message_get_notice(m);
     
    14531453        owl_fmtext_appendf_normal(&fm, "  Fields    : %i\n", fields);
    14541454
    1455         for (i=0; i<fields; i++) {
    1456           ptr=owl_zephyr_get_field_as_utf8(n, i+1);
    1457           len=strlen(ptr);
    1458           if (len<30) {
    1459             strncpy(tmpbuff, ptr, len);
    1460             tmpbuff[len]='\0';
    1461           } else {
    1462             strncpy(tmpbuff, ptr, 30);
    1463             tmpbuff[30]='\0';
    1464             strcat(tmpbuff, "...");
    1465           }
    1466           g_free(ptr);
    1467 
    1468           for (j=0; j<strlen(tmpbuff); j++) {
    1469             if (tmpbuff[j]=='\n') tmpbuff[j]='~';
    1470             if (tmpbuff[j]=='\r') tmpbuff[j]='!';
    1471           }
    1472 
    1473           owl_fmtext_appendf_normal(&fm, "  Field %i   : %s\n", i+1, tmpbuff);
     1455        for (i = 0; i < fields; i++) {
     1456          tmpbuff = owl_zephyr_get_field_as_utf8(n, i + 1);
     1457
     1458          g_strdelimit(tmpbuff, "\n", '~');
     1459          g_strdelimit(tmpbuff, "\r", '!');
     1460
     1461          owl_fmtext_appendf_normal(&fm, "  Field %i   : %s\n", i + 1, tmpbuff);
     1462          g_free(tmpbuff);
    14741463        }
    14751464        owl_fmtext_appendf_normal(&fm, "  Default Fm: %s\n", n->z_default_format);
     
    18171806          owl_global_get_cols(&g));
    18181807
    1819   if (owl_global_get_hascolors(&g)) {
     1808  if (has_colors()) {
    18201809    owl_fmtext_append_normal(&fm, "Color: Yes\n");
    1821     owl_fmtext_appendf_normal(&fm, "Number of color pairs: %i\n", owl_global_get_colorpairs(&g));
     1810    owl_fmtext_appendf_normal(&fm, "Number of color pairs: %i\n", owl_util_get_colorpairs());
    18221811    owl_fmtext_appendf_normal(&fm, "Can change colors: %s\n", can_change_color() ? "yes" : "no");
    18231812  } else {
     
    22262215    f = fl->data;
    22272216    owl_fmtext_append_normal(&fm, "   ");
    2228     if (owl_global_get_hascolors(&g)) {
    2229       owl_fmtext_append_normal_color(&fm, owl_filter_get_name(f), owl_filter_get_fgcolor(f), owl_filter_get_bgcolor(f));
    2230     } else {
    2231       owl_fmtext_append_normal(&fm, owl_filter_get_name(f));
    2232     }
     2217    owl_fmtext_append_normal_color(&fm, owl_filter_get_name(f),
     2218                                   owl_filter_get_fgcolor(f),
     2219                                   owl_filter_get_bgcolor(f));
    22332220    owl_fmtext_append_normal(&fm, "\n");
    22342221  }
     
    23602347done:
    23612348  g_free(class);
    2362   if (instance) {
    2363     g_free(instance);
    2364   }
     2349  g_free(instance);
    23652350  return(filtname);
    23662351}
     
    25232508
    25242509  filtname = g_strdup_printf("conversation-%s", ccs);
    2525   owl_text_tr(filtname, ' ', '-');
     2510  g_strdelimit(filtname, " ", '-');
    25262511
    25272512  if (owl_global_get_filter(&g, filtname)) {
     
    27852770void owl_function_zpunt(const char *class, const char *inst, const char *recip, int direction)
    27862771{
    2787   GString *buf;
     2772  GPtrArray *argv;
    27882773  char *quoted;
    27892774
    2790   buf = g_string_new("");
     2775  argv = g_ptr_array_new();
    27912776  if (!strcmp(class, "*")) {
    2792     g_string_append(buf, "class .*");
     2777    g_ptr_array_add(argv, g_strdup("class"));
     2778    g_ptr_array_add(argv, g_strdup(".*"));
    27932779  } else {
    27942780    quoted=owl_text_quote(class, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
    2795     owl_string_appendf_quoted(buf, "class ^(un)*%q(\\.d)*$", quoted);
     2781    g_ptr_array_add(argv, g_strdup("class"));
     2782    g_ptr_array_add(argv, g_strdup_printf("^(un)*%s(\\.d)*$", quoted));
    27962783    g_free(quoted);
    27972784  }
    27982785  if (!strcmp(inst, "*")) {
    2799     g_string_append(buf, " and instance .*");
     2786    g_ptr_array_add(argv, g_strdup("and"));
     2787    g_ptr_array_add(argv, g_strdup("instance"));
     2788    g_ptr_array_add(argv, g_strdup(".*"));
    28002789  } else {
    28012790    quoted=owl_text_quote(inst, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
    2802     owl_string_appendf_quoted(buf, " and instance ^(un)*%q(\\.d)*$", quoted);
     2791    g_ptr_array_add(argv, g_strdup("and"));
     2792    g_ptr_array_add(argv, g_strdup("instance"));
     2793    g_ptr_array_add(argv, g_strdup_printf("^(un)*%s(\\.d)*$", quoted));
    28032794    g_free(quoted);
    28042795  }
    28052796  if (!strcmp(recip, "*")) {
    2806     /* g_string_append(buf, ""); */
     2797    /* nothing */
    28072798  } else {
    28082799    if(!strcmp(recip, "%me%")) {
     
    28102801    }
    28112802    quoted=owl_text_quote(recip, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
    2812     owl_string_appendf_quoted(buf, " and recipient ^%q$", quoted);
     2803    g_ptr_array_add(argv, g_strdup("and"));
     2804    g_ptr_array_add(argv, g_strdup("recipient"));
     2805    g_ptr_array_add(argv, g_strdup_printf("^%s$", quoted));
    28132806    g_free(quoted);
    28142807  }
    28152808
    2816   owl_function_punt(buf->str, direction);
    2817   g_string_free(buf, true);
    2818 }
    2819 
    2820 void owl_function_punt(const char *filter, int direction)
     2809  owl_function_punt(argv->len, (const char *const*) argv->pdata, direction);
     2810  g_ptr_array_foreach(argv, (GFunc)g_free, NULL);
     2811  g_ptr_array_free(argv, true);
     2812}
     2813
     2814void owl_function_punt(int argc, const char *const *argv, int direction)
    28212815{
    28222816  owl_filter *f;
     
    28262820
    28272821  /* first, create the filter */
    2828   owl_function_debugmsg("About to filter %s", filter);
    2829   f = owl_filter_new_fromstring("punt-filter", filter);
     2822  f = owl_filter_new("punt-filter", argc, argv);
    28302823  if (f == NULL) {
    28312824    owl_function_error("Error creating filter for zpunt");
     
    28542847  }
    28552848
    2856   owl_function_debugmsg("punting");
    2857   /* If we're punting, add the filter to the global punt list */
    2858   if (direction==0) {
     2849  if (direction == 0) {
     2850    owl_function_debugmsg("punting");
     2851    /* If we're punting, add the filter to the global punt list */
    28592852    owl_list_append_element(fl, f);
    2860   }
     2853  } else if (direction == 1) {
     2854    owl_function_makemsg("No matching punt filter");
     2855 }
    28612856}
    28622857
     
    29952990      i--;
    29962991    }
    2997     owl_function_mask_sigint(NULL);
    2998     if(owl_global_is_interrupted(&g)) {
    2999       owl_global_unset_interrupted(&g);
    3000       owl_function_unmask_sigint(NULL);
     2992    if (owl_global_take_interrupt(&g)) {
    30012993      owl_function_makemsg("Search interrupted!");
    30022994      owl_mainwin_redisplay(owl_global_get_mainwin(&g));
    30032995      return;
    30042996    }
    3005     owl_function_unmask_sigint(NULL);
    30062997  }
    30072998  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
     
    30863077          ret=ZLocateUser(zstr(user), &numlocs, ZAUTH);
    30873078
    3088           owl_function_mask_sigint(NULL);
    3089           if(owl_global_is_interrupted(&g)) {
     3079          if (owl_global_take_interrupt(&g)) {
    30903080            interrupted = 1;
    3091             owl_global_unset_interrupted(&g);
    3092             owl_function_unmask_sigint(NULL);
    30933081            owl_function_makemsg("Interrupted!");
    30943082            break;
    30953083          }
    3096 
    3097           owl_function_unmask_sigint(NULL);
    30983084
    30993085          if (ret!=ZERR_NONE) {
     
    32563242  filename=owl_global_get_startupfile(&g);
    32573243
    3258   /* delete earlier copies */
    3259   owl_util_file_deleteline(filename, buff, 1);
     3244  /* delete earlier copies, if the file exists */
     3245  if (g_file_test(filename, G_FILE_TEST_EXISTS))
     3246    owl_util_file_deleteline(filename, buff, 1);
    32603247
    32613248  file=fopen(filename, "a");
     
    35003487}
    35013488
    3502 void owl_function_mask_sigint(sigset_t *oldmask) {
    3503   sigset_t intr;
    3504 
    3505   sigemptyset(&intr);
    3506   sigaddset(&intr, SIGINT);
    3507   sigprocmask(SIG_BLOCK, &intr, oldmask);
    3508 }
    3509 
    3510 void owl_function_unmask_sigint(sigset_t *oldmask) {
    3511   sigset_t intr;
    3512 
    3513   sigemptyset(&intr);
    3514   sigaddset(&intr, SIGINT);
    3515   sigprocmask(SIG_UNBLOCK, &intr, oldmask);
    3516 }
    3517 
    35183489void _owl_function_mark_message(const owl_message *m)
    35193490{
  • global.c

    r47e0a6a rf97c1a6  
    1616
    1717  g_type_init();
     18  g_thread_init(NULL);
     19
     20  owl_select_init();
    1821
    1922  g->lines=LINES;
     
    5154  g->direction=OWL_DIRECTION_DOWNWARDS;
    5255  g->zaway=0;
    53   if (has_colors()) {
    54     g->hascolors=1;
    55   }
    56   g->colorpairs=COLOR_PAIRS;
    5756  owl_fmtext_init_colorpair_mgr(&(g->cpmgr));
    5857  g->debug=OWL_DEBUG;
     
    9998
    10099  owl_errqueue_init(&(g->errqueue));
    101   g->got_err_signal=0;
    102100
    103101  owl_zbuddylist_create(&(g->zbuddies));
     
    108106  owl_message_init_fmtext_cache();
    109107  owl_list_create(&(g->io_dispatch_list));
    110   owl_list_create(&(g->psa_list));
    111108  g->timerlist = NULL;
    112   g->interrupted = FALSE;
    113109  g->kill_buffer = NULL;
     110
     111  g->interrupt_count = 0;
     112  g->interrupt_lock = g_mutex_new();
    114113}
    115114
     
    348347
    349348void owl_global_set_resize_pending(owl_global *g) {
    350   g->resizepending=1;
     349  g->resizepending = true;
    351350}
    352351
     
    448447  /* resize the screen.  If lines or cols is 0 use the terminal size */
    449448  if (!g->resizepending) return;
    450   g->resizepending = 0;
     449  g->resizepending = false;
    451450
    452451  owl_global_get_terminal_size(&g->lines, &g->cols);
     
    509508
    510509void owl_global_set_startupargs(owl_global *g, int argc, char **argv) {
    511   if (g->startupargs) g_free(g->startupargs);
     510  g_free(g->startupargs);
    512511  g->startupargs = g_strjoinv(" ", argv);
    513512}
     
    574573owl_view *owl_global_get_current_view(owl_global *g) {
    575574  return(&(g->current_view));
    576 }
    577 
    578 /* has colors */
    579 
    580 int owl_global_get_hascolors(const owl_global *g) {
    581   if (g->hascolors) return(1);
    582   return(0);
    583 }
    584 
    585 /* color pairs */
    586 
    587 int owl_global_get_colorpairs(const owl_global *g) {
    588   return(g->colorpairs);
    589575}
    590576
     
    693679}
    694680
    695 int owl_global_is_doaimevents(const owl_global *g)
    696 {
    697   if (g->aim_doprocessing) return(1);
    698   return(0);
     681bool owl_global_is_doaimevents(const owl_global *g)
     682{
     683  return g->aim_event_source != NULL;
    699684}
    700685
    701686void owl_global_set_doaimevents(owl_global *g)
    702687{
    703   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);
    704692}
    705693
    706694void owl_global_set_no_doaimevents(owl_global *g)
    707695{
    708   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;
    709701}
    710702
     
    764756}
    765757
    766 int owl_global_get_style_names(const owl_global *g, owl_list *l) {
    767   return owl_dict_get_keys(&(g->styledict), l);
     758void owl_global_get_style_names(const owl_global *g, owl_list *l) {
     759  owl_dict_get_keys(&(g->styledict), l);
    768760}
    769761
     
    824816}
    825817
    826 void owl_global_set_errsignal(owl_global *g, int signum, siginfo_t *siginfo)
    827 {
    828   g->got_err_signal = signum;
    829   if (siginfo) {
    830     g->err_signal_info = *siginfo;
    831   } else {
    832     siginfo_t si;
    833     memset(&si, 0, sizeof(si));
    834     g->err_signal_info = si;
    835   }
    836 }
    837 
    838 int owl_global_get_errsignal_and_clear(owl_global *g, siginfo_t *siginfo)
    839 {
    840   int signum;
    841   if (siginfo && g->got_err_signal) {
    842     *siginfo = g->err_signal_info;
    843   }
    844   signum = g->got_err_signal;
    845   g->got_err_signal = 0;
    846   return signum;
    847 }
    848 
    849 
    850818owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
    851819{
     
    878846}
    879847
    880 owl_list *owl_global_get_psa_list(owl_global *g)
    881 {
    882   return &(g->psa_list);
    883 }
    884 
    885848GList **owl_global_get_timerlist(owl_global *g)
    886849{
    887850  return &(g->timerlist);
    888 }
    889 
    890 int owl_global_is_interrupted(const owl_global *g) {
    891   return g->interrupted;
    892 }
    893 
    894 void owl_global_set_interrupted(owl_global *g) {
    895   g->interrupted = 1;
    896 }
    897 
    898 void owl_global_unset_interrupted(owl_global *g) {
    899   g->interrupted = 0;
    900851}
    901852
     
    965916  g->kill_buffer = g_strndup(kill, len);
    966917}
     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}
  • 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 rcc305b5  
    44#include <ctype.h>
    55#include <sys/param.h>
     6
     7typedef struct _owl_log_entry { /* noproto */
     8  char *filename;
     9  char *message;
     10} owl_log_entry;
     11
     12
     13static GMainContext *log_context;
     14static GMainLoop *log_loop;
     15static GThread *logging_thread;
    616
    717/* This is now the one function that should be called to log a
     
    7080}
    7181
    72 void owl_log_zephyr(const owl_message *m, FILE *file) {
    73     char *tmp;
    74     tmp=short_zuser(owl_message_get_sender(m));
    75     fprintf(file, "Class: %s Instance: %s", owl_message_get_class(m), owl_message_get_instance(m));
    76     if (strcmp(owl_message_get_opcode(m), "")) fprintf(file, " Opcode: %s", owl_message_get_opcode(m));
    77     fprintf(file, "\n");
    78     fprintf(file, "Time: %s Host: %s\n", owl_message_get_timestr(m), owl_message_get_hostname(m));
    79     fprintf(file, "From: %s <%s>\n\n", owl_message_get_zsig(m), tmp);
    80     fprintf(file, "%s\n\n", owl_message_get_body(m));
     82char *owl_log_zephyr(const owl_message *m) {
     83    char *tmp = NULL;
     84    GString *buffer = NULL;
     85    buffer = g_string_new("");
     86    tmp = short_zuser(owl_message_get_sender(m));
     87    g_string_append_printf(buffer, "Class: %s Instance: %s",
     88                           owl_message_get_class(m),
     89                           owl_message_get_instance(m));
     90    if (strcmp(owl_message_get_opcode(m), "")) {
     91      g_string_append_printf(buffer, " Opcode: %s",
     92                             owl_message_get_opcode(m));
     93    }
     94    g_string_append_printf(buffer, "\n");
     95    g_string_append_printf(buffer, "Time: %s Host: %s\n",
     96                           owl_message_get_timestr(m),
     97                           owl_message_get_hostname(m));
     98    g_string_append_printf(buffer, "From: %s <%s>\n\n",
     99                           owl_message_get_zsig(m), tmp);
     100    g_string_append_printf(buffer, "%s\n\n", owl_message_get_body(m));
    81101    g_free(tmp);
    82 }
    83 
    84 void owl_log_aim(const owl_message *m, FILE *file) {
    85     fprintf(file, "From: <%s> To: <%s>\n", owl_message_get_sender(m), owl_message_get_recipient(m));
    86     fprintf(file, "Time: %s\n\n", owl_message_get_timestr(m));
    87     if (owl_message_is_login(m))
    88         fprintf(file, "LOGIN\n\n");
    89     else if (owl_message_is_logout(m))
    90         fprintf(file, "LOGOUT\n\n");
    91     else
    92         fprintf(file, "%s\n\n", owl_message_get_body(m));
    93 }
    94 
    95 void owl_log_jabber(const owl_message *m, FILE *file) {
    96     fprintf(file, "From: <%s> To: <%s>\n",owl_message_get_sender(m), owl_message_get_recipient(m));
    97     fprintf(file, "Time: %s\n\n", owl_message_get_timestr(m));
    98     fprintf(file, "%s\n\n",owl_message_get_body(m));
    99 }
    100 
    101 void owl_log_generic(const owl_message *m, FILE *file) {
    102     fprintf(file, "From: <%s> To: <%s>\n", owl_message_get_sender(m), owl_message_get_recipient(m));
    103     fprintf(file, "Time: %s\n\n", owl_message_get_timestr(m));
    104     fprintf(file, "%s\n\n", owl_message_get_body(m));
     102    return g_string_free(buffer, FALSE);
     103}
     104
     105char *owl_log_aim(const owl_message *m) {
     106    GString *buffer = NULL;
     107    buffer = g_string_new("");
     108    g_string_append_printf(buffer, "From: <%s> To: <%s>\n",
     109                           owl_message_get_sender(m), owl_message_get_recipient(m));
     110    g_string_append_printf(buffer, "Time: %s\n\n",
     111                           owl_message_get_timestr(m));
     112    if (owl_message_is_login(m)) {
     113        g_string_append_printf(buffer, "LOGIN\n\n");
     114    } else if (owl_message_is_logout(m)) {
     115        g_string_append_printf(buffer, "LOGOUT\n\n");
     116    } else {
     117        g_string_append_printf(buffer, "%s\n\n", owl_message_get_body(m));
     118    }
     119    return g_string_free(buffer, FALSE);
     120}
     121
     122char *owl_log_jabber(const owl_message *m) {
     123    GString *buffer = NULL;
     124    buffer = g_string_new("");
     125    g_string_append_printf(buffer, "From: <%s> To: <%s>\n",
     126                           owl_message_get_sender(m),
     127                           owl_message_get_recipient(m));
     128    g_string_append_printf(buffer, "Time: %s\n\n",
     129                           owl_message_get_timestr(m));
     130    g_string_append_printf(buffer, "%s\n\n", owl_message_get_body(m));
     131    return g_string_free(buffer, FALSE);
     132}
     133
     134char *owl_log_generic(const owl_message *m) {
     135    GString *buffer;
     136    buffer = g_string_new("");
     137    g_string_append_printf(buffer, "From: <%s> To: <%s>\n",
     138                           owl_message_get_sender(m),
     139                           owl_message_get_recipient(m));
     140    g_string_append_printf(buffer, "Time: %s\n\n",
     141                           owl_message_get_timestr(m));
     142    g_string_append_printf(buffer, "%s\n\n",
     143                           owl_message_get_body(m));
     144    return g_string_free(buffer, FALSE);
     145}
     146
     147static void owl_log_error_main_thread(gpointer data)
     148{
     149  owl_function_error("%s", (const char*)data);
     150}
     151
     152static void owl_log_error(const char *message)
     153{
     154  char *data = g_strdup(message);
     155  owl_select_post_task(owl_log_error_main_thread,
     156                       data, g_free, g_main_context_default());
     157}
     158
     159static void owl_log_write_entry(gpointer data)
     160{
     161  owl_log_entry *msg = (owl_log_entry*)data;
     162  FILE *file = NULL;
     163  file = fopen(msg->filename, "a");
     164  if (!file) {
     165    owl_log_error("Unable to open file for logging");
     166    return;
     167  }
     168  fprintf(file, "%s", msg->message);
     169  fclose(file);
     170}
     171
     172static void owl_log_entry_free(void *data)
     173{
     174  owl_log_entry *msg = (owl_log_entry*)data;
     175  if (msg) {
     176    g_free(msg->message);
     177    g_free(msg->filename);
     178    g_free(msg);
     179  }
     180}
     181
     182void owl_log_enqueue_message(const char *buffer, const char *filename)
     183{
     184  owl_log_entry *log_msg = NULL;
     185  log_msg = g_new(owl_log_entry,1);
     186  log_msg->message = g_strdup(buffer);
     187  log_msg->filename = g_strdup(filename);
     188  owl_select_post_task(owl_log_write_entry, log_msg,
     189                       owl_log_entry_free, log_context);
    105190}
    106191
    107192void owl_log_append(const owl_message *m, const char *filename) {
    108     FILE *file;
    109     file=fopen(filename, "a");
    110     if (!file) {
    111         owl_function_error("Unable to open file for logging");
    112         return;
    113     }
    114     if (owl_message_is_type_zephyr(m)) {
    115         owl_log_zephyr(m, file);
    116     } else if (owl_message_is_type_jabber(m)) {
    117         owl_log_jabber(m, file);
    118     } else if (owl_message_is_type_aim(m)) {
    119         owl_log_aim(m, file);
    120     } else {
    121         owl_log_generic(m, file);
    122     }
    123     fclose(file);
     193  char *buffer = NULL;
     194  if (owl_message_is_type_zephyr(m)) {
     195    buffer = owl_log_zephyr(m);
     196  } else if (owl_message_is_type_jabber(m)) {
     197    buffer = owl_log_jabber(m);
     198  } else if (owl_message_is_type_aim(m)) {
     199    buffer = owl_log_aim(m);
     200  } else {
     201    buffer = owl_log_generic(m);
     202  }
     203  owl_log_enqueue_message(buffer, filename);
     204  g_free(buffer);
    124205}
    125206
     
    151232  } else if (owl_message_is_type_jabber(m)) {
    152233    to = g_strdup_printf("jabber:%s", owl_message_get_recipient(m));
    153     owl_text_tr(to, '/', '_');
     234    g_strdelimit(to, "/", '_');
    154235  } else if (owl_message_is_type_aim(m)) {
    155236    char *temp2;
     
    177258void owl_log_outgoing_zephyr_error(const owl_zwrite *zw, const char *text)
    178259{
    179   FILE *file;
    180260  char *filename, *logpath;
    181261  char *tobuff, *recip;
    182262  owl_message *m;
    183 
     263  GString *msgbuf;
    184264  /* create a present message so we can pass it to
    185265   * owl_log_shouldlog_message(void)
     
    201281  /* expand ~ in path names */
    202282  logpath = owl_util_makepath(owl_global_get_logpath(&g));
    203 
    204283  filename = g_strdup_printf("%s/%s", logpath, tobuff);
    205   file=fopen(filename, "a");
    206   g_free(filename);
    207   if (!file) {
    208     owl_function_error("Unable to open file for outgoing logging");
    209     g_free(logpath);
    210     g_free(tobuff);
    211     return;
    212   }
    213   fprintf(file, "ERROR (owl): %s\n%s\n", tobuff, text);
    214   if (text[strlen(text)-1]!='\n') {
    215     fprintf(file, "\n");
    216   }
    217   fclose(file);
     284  msgbuf = g_string_new("");
     285  g_string_printf(msgbuf, "ERROR (owl): %s\n%s\n", tobuff, text);
     286  if (text[strlen(text)-1] != '\n') {
     287    g_string_append_printf(msgbuf, "\n");
     288  }
     289  owl_log_enqueue_message(msgbuf->str, filename);
     290  g_string_free(msgbuf, TRUE);
    218291
    219292  filename = g_strdup_printf("%s/all", logpath);
    220293  g_free(logpath);
    221   file=fopen(filename, "a");
    222   g_free(filename);
    223   if (!file) {
    224     owl_function_error("Unable to open file for outgoing logging");
    225     g_free(tobuff);
    226     return;
    227   }
    228   fprintf(file, "ERROR (owl): %s\n%s\n", tobuff, text);
    229   if (text[strlen(text)-1]!='\n') {
    230     fprintf(file, "\n");
    231   }
    232   fclose(file);
     294  msgbuf = g_string_new("");
     295  g_string_printf(msgbuf, "ERROR (owl): %s\n%s\n", tobuff, text);
     296  if (text[strlen(text)-1] != '\n') {
     297    g_string_append_printf(msgbuf, "\n");
     298  }
     299  owl_log_enqueue_message(msgbuf->str, filename);
     300  g_string_free(msgbuf, TRUE);
    233301
    234302  g_free(tobuff);
     
    284352  } else if (owl_message_is_type_jabber(m)) {
    285353    if (personal) {
    286       from=frombuff=g_strdup_printf("jabber:%s",owl_message_get_sender(m));
    287     } else {
    288       from=frombuff=g_strdup_printf("jabber:%s",owl_message_get_recipient(m));
     354      from=frombuff=g_strdup_printf("jabber:%s",
     355                                    owl_message_get_sender(m));
     356    } else {
     357      from=frombuff=g_strdup_printf("jabber:%s",
     358                                    owl_message_get_recipient(m));
    289359    }
    290360  } else {
     
    355425  g_free(logpath);
    356426}
     427
     428static gpointer owl_log_thread_func(gpointer data)
     429{
     430  log_context = g_main_context_new();
     431  log_loop = g_main_loop_new(log_context, FALSE);
     432  g_main_loop_run(log_loop);
     433  return NULL;
     434}
     435
     436void owl_log_init(void)
     437{
     438  GError *error = NULL;
     439  logging_thread = g_thread_create(owl_log_thread_func,
     440                                   NULL,
     441                                   TRUE,
     442                                   &error);
     443  if (error) {
     444    endwin();
     445    fprintf(stderr, "Error spawning logging thread: %s\n", error->message);
     446    fflush(stderr);
     447    exit(1);
     448  }
     449 
     450}
     451
     452static void owl_log_quit_func(gpointer data)
     453{
     454  g_main_loop_quit(log_loop);
     455}
     456
     457void owl_log_shutdown(void)
     458{
     459  owl_select_post_task(owl_log_quit_func, NULL,
     460                       NULL, log_context);
     461  g_thread_join(logging_thread);
     462}
  • message.c

    r3a3863e r259e60a8  
    120120  int i, j;
    121121  owl_pair *p;
    122   char *buff;
     122  char *buff, *tmpbuff;
    123123
    124124  owl_fmtext_init_null(fm);
     
    127127  for (i=0; i<j; i++) {
    128128    p=owl_list_get_element(&(m->attributes), i);
    129     buff=g_strdup_printf("  %-15.15s: %-35.35s\n", owl_pair_get_key(p), owl_pair_get_value(p));
     129
     130    tmpbuff = g_strdup(owl_pair_get_value(p));
     131    g_strdelimit(tmpbuff, "\n", '~');
     132    g_strdelimit(tmpbuff, "\r", '!');
     133    buff = g_strdup_printf("  %-15.15s: %s\n", owl_pair_get_key(p), tmpbuff);
     134    g_free(tmpbuff);
     135
    130136    if(buff == NULL) {
    131       buff=g_strdup_printf("  %-15.15s: %-35.35s\n", owl_pair_get_key(p), "<error>");
     137      buff = g_strdup_printf("  %-15.15s: %s\n", owl_pair_get_key(p), "<error>");
    132138      if(buff == NULL)
    133139        buff=g_strdup("   <error>\n");
  • owl.c

    ra2a8833 rcc305b5  
    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),
     386                       NULL, g_main_context_default());
     387}
     388
     389#define CHECK_RESULT(s, syscall) \
     390  G_STMT_START {                 \
     391    if ((syscall) != 0) {        \
     392      perror((s));               \
     393      exit(1);                   \
     394    }                            \
     395  } G_STMT_END
    368396
    369397void 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);
     398  struct sigaction sig_ignore = { .sa_handler = SIG_IGN };
     399  struct sigaction sig_default = { .sa_handler = SIG_DFL };
     400  sigset_t sigset;
     401  int ret, i;
     402  const int signals[] = { SIGABRT, SIGBUS, SIGCHLD, SIGFPE, SIGHUP, SIGILL,
     403                          SIGINT, SIGQUIT, SIGSEGV, SIGTERM, SIGWINCH };
     404
     405  /* Sanitize our signals; the mask and dispositions from our parent
     406   * aren't really useful. Signal list taken from equivalent code in
     407   * Chromium. */
     408  CHECK_RESULT("sigemptyset", sigemptyset(&sigset));
     409  if ((ret = pthread_sigmask(SIG_SETMASK, &sigset, NULL)) != 0) {
     410    errno = ret;
     411    perror("pthread_sigmask");
     412  }
     413  for (i = 0; i < G_N_ELEMENTS(signals); i++) {
     414    CHECK_RESULT("sigaction", sigaction(signals[i], &sig_default, NULL));
     415  }
     416
     417  /* Turn off SIGPIPE; we check the return value of write. */
     418  CHECK_RESULT("sigaction", sigaction(SIGPIPE, &sig_ignore, NULL));
     419
     420  /* Register some signals with the signal thread. */
     421  CHECK_RESULT("sigaddset", sigaddset(&sigset, SIGWINCH));
     422  CHECK_RESULT("sigaddset", sigaddset(&sigset, SIGTERM));
     423  CHECK_RESULT("sigaddset", sigaddset(&sigset, SIGHUP));
     424  CHECK_RESULT("sigaddset", sigaddset(&sigset, SIGINT));
     425  owl_signal_init(&sigset, sig_handler, NULL);
    385426}
    386427
     
    424465  }
    425466  bread = read(rfd, buf, navail);
    426   if (buf[navail-1] != '\0') {
    427     buf[navail] = '\0';
    428   }
    429 
    430   err = g_strdup_printf("[stderr]\n%s", buf);
     467  if (bread == -1)
     468    return;
     469
     470  err = g_strdup_printf("[stderr]\n%.*s", bread, buf);
    431471
    432472  owl_function_log_err(err);
     
    435475
    436476#endif /* OWL_STDERR_REDIR */
    437 
    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
    447    * the current screen uses too many colorpairs, this draws
    448    * everything twice. But this is unlikely; COLOR_PAIRS is 64 with
    449    * 8+1 colors, and 256^2 with 256+1 colors. (+1 for default.) */
    450   cpmgr = owl_global_get_colorpair_mgr(&g);
    451   if (cpmgr->overflow) {
    452     owl_function_debugmsg("colorpairs: color shortage; reset pairs and redraw. COLOR_PAIRS = %d", COLOR_PAIRS);
    453     owl_fmtext_reset_colorpairs(cpmgr);
    454     owl_function_full_redisplay();
    455     owl_window_redraw_scheduled();
    456   }
    457   return 0;
    458 }
    459 
    460477
    461478int main(int argc, char **argv, char **env)
     
    467484  const char *dir;
    468485  owl_options opts;
     486  GSource *source;
    469487
    470488  if (!GLIB_CHECK_VERSION (2, 12, 0))
     
    481499  g.load_initial_subs = opts.load_initial_subs;
    482500
    483   owl_register_signal_handlers();
    484501  owl_start_curses();
    485502
     
    493510  owl_global_set_haveaim(&g);
    494511
     512  owl_register_signal_handlers();
     513
    495514  /* register STDIN dispatch; throw away return, we won't need it */
    496515  owl_select_add_io_dispatch(STDIN_FILENO, OWL_IO_READ, &owl_process_input, NULL, NULL);
     
    551570  owl_function_debugmsg("startup: executing perl startup, if applicable");
    552571  perlout = owl_perlconfig_execute("BarnOwl::Hooks::_startup();");
    553   if (perlout) g_free(perlout);
     572  g_free(perlout);
    554573
    555574  /* welcome message */
     
    584603  owl_global_push_context(&g, OWL_CTX_INTERACTIVE|OWL_CTX_RECV, NULL, "recv", NULL);
    585604
    586   owl_select_add_pre_select_action(owl_refresh_pre_select_action, NULL, NULL);
    587   owl_select_add_pre_select_action(owl_process_messages, NULL, NULL);
    588   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);
     612
     613  owl_log_init();
    589614
    590615  owl_function_debugmsg("startup: entering main loop");
     
    593618  /* Shut down everything. */
    594619  owl_zephyr_shutdown();
     620  owl_signal_shutdown();
    595621  owl_shutdown_curses();
     622  owl_log_shutdown();
    596623  return 0;
    597624}
  • 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
  • perl/modules/Jabber/lib/BarnOwl/Message/Jabber.pm

    rb401ef2 ra27acf7  
    161161    my ($recip, $account, $subject) = @_;
    162162    if (defined $recip) {
    163         my @cmd = ('jwrite', $recip, '-a', $account);
     163        my @cmd = ('jwrite', '-a', $account);
    164164        if (defined $subject) {
    165165            push @cmd, '-s', $subject;
    166166        }
     167        push @cmd, '--', $recip;
    167168        return BarnOwl::quote(@cmd);
    168169    } else {
  • perlconfig.c

    rf25df21 ra9237aa  
    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
     
    490492  PUTBACK;
    491493
    492   call_pv("BarnOwl::Hooks::_new_command", G_SCALAR|G_VOID|G_EVAL);
     494  call_pv("BarnOwl::Hooks::_new_command", G_VOID|G_EVAL);
    493495
    494496  SPAGAIN;
  • perlglue.xs

    r6a71113 r3b8a563  
    5757                RETVAL
    5858        CLEANUP:
    59                 if (rv) g_free(rv);
     59                g_free(rv);
    6060
    6161SV *
     
    114114                RETVAL
    115115        CLEANUP:
    116                 if (rv) g_free(rv);
     116                g_free(rv);
    117117
    118118const utf8 *
     
    141141                RETVAL
    142142    CLEANUP:
    143                 if (rv) g_free(rv);
     143                g_free(rv);
    144144
    145145void
     
    324324                RETVAL
    325325        CLEANUP:
    326                 if (rv)
    327                         g_free(rv);
     326                g_free(rv);
    328327
    329328void
  • select.c

    rd4927a7 rf0781ba  
    11#include "owl.h"
    22
     3static GMainLoop *loop = NULL;
     4static GMainContext *main_context;
    35static int dispatch_active = 0;
    4 static int psa_active = 0;
    5 static int loop_active = 0;
    6 
    7 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) {
    811  return t1->time - t2->time;
    9 }
    10 
    11 int _owl_select_timer_eq(const owl_timer *t1, const owl_timer *t2) {
    12   return t1 == t2;
    1312}
    1413
     
    4342}
    4443
    45 void owl_select_process_timers(struct timespec *timeout)
    46 {
    47   time_t now = time(NULL);
    48   GList **timers = owl_global_get_timerlist(&g);
    49 
     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? */
    5094  while(*timers) {
    5195    owl_timer *t = (*timers)->data;
    5296    int remove = 0;
    5397
    54     if(t->time > now)
     98    if(t->time > now.tv_sec)
    5599      break;
    56100
    57101    /* Reschedule if appropriate */
    58102    if(t->interval > 0) {
    59       t->time = now + t->interval;
     103      t->time = now.tv_sec + t->interval;
    60104      *timers = g_list_remove(*timers, t);
    61105      *timers = g_list_insert_sorted(*timers, t,
     
    71115    }
    72116  }
    73 
    74   if(*timers) {
    75     owl_timer *t = (*timers)->data;
    76     timeout->tv_sec = t->time - now;
    77     if (timeout->tv_sec > 60)
    78       timeout->tv_sec = 60;
    79   } else {
    80     timeout->tv_sec = 60;
    81   }
    82 
    83   timeout->tv_nsec = 0;
    84 }
    85 
    86 static const owl_io_dispatch *owl_select_find_io_dispatch_by_fd(const int fd)
     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
     127/* Returns the valid owl_io_dispatch for a given file descriptor. */
     128static owl_io_dispatch *owl_select_find_valid_io_dispatch_by_fd(const int fd)
    87129{
    88130  int i, len;
     
    93135  for(i = 0; i < len; i++) {
    94136    d = owl_list_get_element(dl, i);
    95     if (d->fd == fd) return d;
     137    if (d->fd == fd && d->valid) return d;
    96138  }
    97139  return NULL;
     
    112154  }
    113155  return -1;
     156}
     157
     158static void owl_select_invalidate_io_dispatch(owl_io_dispatch *d)
     159{
     160  if (d == NULL || !d->valid)
     161    return;
     162  d->valid = false;
     163  g_source_remove_poll(owl_io_dispatch_source, &d->pollfd);
    114164}
    115165
     
    125175        d->needs_gc = 1;
    126176      else {
     177        owl_select_invalidate_io_dispatch(d);
    127178        owl_list_remove_element(dl, elt);
    128179        if (d->destroy)
     
    134185}
    135186
    136 void owl_select_io_dispatch_gc(void)
     187static void owl_select_io_dispatch_gc(void)
    137188{
    138189  int i;
     
    152203}
    153204
    154 /* Each FD may have at most one dispatcher.
     205/* Each FD may have at most one valid dispatcher.
    155206 * If a new dispatch is added for an FD, the old one is removed.
    156207 * mode determines what types of events are watched for, and may be any combination of:
     
    161212  owl_io_dispatch *d = g_new(owl_io_dispatch, 1);
    162213  owl_list *dl = owl_global_get_io_dispatch_list(&g);
     214  owl_io_dispatch *other;
    163215
    164216  d->fd = fd;
     217  d->valid = true;
    165218  d->needs_gc = 0;
    166219  d->mode = mode;
     
    169222  d->data = data;
    170223
    171   owl_select_remove_io_dispatch(owl_select_find_io_dispatch_by_fd(fd));
     224  /* TODO: Allow changing fd and mode in the middle? Probably don't care... */
     225  d->pollfd.fd = fd;
     226  d->pollfd.events = 0;
     227  if (d->mode & OWL_IO_READ)
     228    d->pollfd.events |= G_IO_IN | G_IO_HUP | G_IO_ERR;
     229  if (d->mode & OWL_IO_WRITE)
     230    d->pollfd.events |= G_IO_OUT | G_IO_ERR;
     231  if (d->mode & OWL_IO_EXCEPT)
     232    d->pollfd.events |= G_IO_PRI | G_IO_ERR;
     233  g_source_add_poll(owl_io_dispatch_source, &d->pollfd);
     234
     235
     236  other = owl_select_find_valid_io_dispatch_by_fd(fd);
     237  if (other)
     238    owl_select_invalidate_io_dispatch(other);
    172239  owl_list_append_element(dl, d);
    173240
     
    175242}
    176243
    177 int owl_select_prepare_io_dispatch_fd_sets(fd_set *rfds, fd_set *wfds, fd_set *efds) {
    178   int i, len, max_fd;
    179   owl_io_dispatch *d;
    180   owl_list *dl = owl_global_get_io_dispatch_list(&g);
    181 
    182   max_fd = 0;
     244static gboolean owl_io_dispatch_prepare(GSource *source, int *timeout) {
     245  *timeout = -1;
     246  return FALSE;
     247}
     248
     249static gboolean owl_io_dispatch_check(GSource *source) {
     250  int i, len;
     251  const owl_list *dl;
     252
     253  dl = owl_global_get_io_dispatch_list(&g);
     254  len = owl_list_get_size(dl);
     255  for(i = 0; i < len; i++) {
     256    owl_io_dispatch *d = owl_list_get_element(dl, i);
     257    if (!d->valid) continue;
     258    if (d->pollfd.revents & G_IO_NVAL) {
     259      owl_function_debugmsg("Pruning defunct dispatch on fd %d.", d->fd);
     260      owl_select_invalidate_io_dispatch(d);
     261    }
     262    if (d->pollfd.revents & d->pollfd.events)
     263      return TRUE;
     264  }
     265  return FALSE;
     266}
     267
     268static gboolean owl_io_dispatch_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) {
     269  int i, len;
     270  const owl_list *dl;
     271
     272  dispatch_active = 1;
     273  dl = owl_global_get_io_dispatch_list(&g);
    183274  len = owl_list_get_size(dl);
    184275  for (i = 0; i < len; i++) {
    185     d = owl_list_get_element(dl, i);
    186     if (d->mode & (OWL_IO_READ | OWL_IO_WRITE | OWL_IO_EXCEPT)) {
    187       if (max_fd < d->fd) max_fd = d->fd;
    188       if (d->mode & OWL_IO_READ) FD_SET(d->fd, rfds);
    189       if (d->mode & OWL_IO_WRITE) FD_SET(d->fd, wfds);
    190       if (d->mode & OWL_IO_EXCEPT) FD_SET(d->fd, efds);
    191     }
    192   }
    193   return max_fd + 1;
    194 }
    195 
    196 void owl_select_io_dispatch(const fd_set *rfds, const fd_set *wfds, const fd_set *efds, const int max_fd)
    197 {
    198   int i, len;
    199   owl_io_dispatch *d;
    200   owl_list *dl = owl_global_get_io_dispatch_list(&g);
    201 
    202   dispatch_active = 1;
    203   len = owl_list_get_size(dl);
    204   for (i = 0; i < len; i++) {
    205     d = owl_list_get_element(dl, i);
    206     if (d->fd < max_fd && d->callback != NULL &&
    207         ((d->mode & OWL_IO_READ && FD_ISSET(d->fd, rfds)) ||
    208          (d->mode & OWL_IO_WRITE && FD_ISSET(d->fd, wfds)) ||
    209          (d->mode & OWL_IO_EXCEPT && FD_ISSET(d->fd, efds)))) {
     276    owl_io_dispatch *d = owl_list_get_element(dl, i);
     277    if (!d->valid) continue;
     278    if ((d->pollfd.revents & d->pollfd.events) && d->callback != NULL) {
    210279      d->callback(d, d->data);
    211280    }
     
    213282  dispatch_active = 0;
    214283  owl_select_io_dispatch_gc();
    215 }
     284
     285  return TRUE;
     286}
     287
     288static GSourceFuncs owl_io_dispatch_funcs = {
     289  owl_io_dispatch_prepare,
     290  owl_io_dispatch_check,
     291  owl_io_dispatch_dispatch,
     292  NULL
     293};
    216294
    217295int owl_select_add_perl_io_dispatch(int fd, int mode, SV *cb)
    218296{
    219   const owl_io_dispatch *d = owl_select_find_io_dispatch_by_fd(fd);
     297  const owl_io_dispatch *d = owl_select_find_valid_io_dispatch_by_fd(fd);
    220298  if (d != NULL && d->callback != owl_perlconfig_io_dispatch) {
    221299    /* Don't mess with non-perl dispatch functions from here. */
    222300    return 1;
    223301  }
     302  /* Also remove any invalidated perl dispatch functions that may have
     303   * stuck around. */
     304  owl_select_remove_perl_io_dispatch(fd);
    224305  owl_select_add_io_dispatch(fd, mode, owl_perlconfig_io_dispatch, owl_perlconfig_io_dispatch_destroy, cb);
    225306  return 0;
    226307}
    227308
     309static owl_io_dispatch *owl_select_find_perl_io_dispatch(int fd)
     310{
     311  int i, len;
     312  const owl_list *dl;
     313  owl_io_dispatch *d;
     314  dl = owl_global_get_io_dispatch_list(&g);
     315  len = owl_list_get_size(dl);
     316  for(i = 0; i < len; i++) {
     317    d = owl_list_get_element(dl, i);
     318    if (d->fd == fd && d->callback == owl_perlconfig_io_dispatch)
     319      return d;
     320  }
     321  return NULL;
     322}
     323
    228324int owl_select_remove_perl_io_dispatch(int fd)
    229325{
    230   const owl_io_dispatch *d = owl_select_find_io_dispatch_by_fd(fd);
    231   if (d != NULL && d->callback == owl_perlconfig_io_dispatch) {
     326  owl_io_dispatch *d = owl_select_find_perl_io_dispatch(fd);
     327  if (d != NULL) {
    232328    /* Only remove perl io dispatchers from here. */
    233329    owl_select_remove_io_dispatch(d);
     
    237333}
    238334
    239 int owl_select_aim_hack(fd_set *rfds, fd_set *wfds)
    240 {
    241   aim_conn_t *cur;
    242   aim_session_t *sess;
    243   int max_fd;
    244 
    245   max_fd = 0;
    246   sess = owl_global_get_aimsess(&g);
    247   for (cur = sess->connlist; cur; cur = cur->next) {
    248     if (cur->fd != -1) {
    249       FD_SET(cur->fd, rfds);
    250       if (cur->status & AIM_CONN_STATUS_INPROGRESS) {
    251         /* Yes, we're checking writable sockets here. Without it, AIM
    252            login is really slow. */
    253         FD_SET(cur->fd, wfds);
    254       }
    255      
    256       if (cur->fd > max_fd)
    257         max_fd = cur->fd;
    258     }
    259   }
    260   return max_fd;
    261 }
    262 
    263 void owl_process_input_char(owl_input j)
    264 {
    265   int ret;
    266 
    267   owl_global_set_lastinputtime(&g, time(NULL));
    268   ret = owl_keyhandler_process(owl_global_get_keyhandler(&g), j);
    269   if (ret!=0 && ret!=1) {
    270     owl_function_makemsg("Unable to handle keypress");
    271   }
    272 }
    273 
    274 void owl_select_mask_signals(sigset_t *oldmask) {
    275   sigset_t set;
    276 
    277   sigemptyset(&set);
    278   sigaddset(&set, SIGWINCH);
    279   sigaddset(&set, SIGALRM);
    280   sigaddset(&set, SIGPIPE);
    281   sigaddset(&set, SIGTERM);
    282   sigaddset(&set, SIGHUP);
    283   sigaddset(&set, SIGINT);
    284   sigprocmask(SIG_BLOCK, &set, oldmask);
    285 }
    286 
    287 void owl_select_handle_intr(sigset_t *restore)
    288 {
    289   owl_input in;
    290 
    291   owl_global_unset_interrupted(&g);
    292 
    293   sigprocmask(SIG_SETMASK, restore, NULL);
    294 
    295   in.ch = in.uch = owl_global_get_startup_tio(&g)->c_cc[VINTR];
    296   owl_process_input_char(in);
    297 }
    298 
    299 owl_ps_action *owl_select_add_pre_select_action(int (*cb)(owl_ps_action *, void *), void (*destroy)(owl_ps_action *), void *data)
    300 {
    301   owl_ps_action *a = g_new(owl_ps_action, 1);
    302   owl_list *psa_list = owl_global_get_psa_list(&g);
    303   a->needs_gc = 0;
    304   a->callback = cb;
    305   a->destroy = destroy;
    306   a->data = data;
    307   owl_list_append_element(psa_list, a);
    308   return a;
    309 }
    310 
    311 void owl_select_psa_gc(void)
    312 {
    313   int i;
    314   owl_list *psa_list;
    315   owl_ps_action *a;
    316 
    317   psa_list = owl_global_get_psa_list(&g);
    318   for (i = owl_list_get_size(psa_list) - 1; i >= 0; i--) {
    319     a = owl_list_get_element(psa_list, i);
    320     if (a->needs_gc) {
    321       owl_list_remove_element(psa_list, i);
    322       if (a->destroy) {
    323         a->destroy(a);
    324       }
    325       g_free(a);
    326     }
    327   }
    328 }
    329 
    330 void owl_select_remove_pre_select_action(owl_ps_action *a)
    331 {
    332   a->needs_gc = 1;
    333   if (!psa_active)
    334     owl_select_psa_gc();
    335 }
    336 
    337 int owl_select_do_pre_select_actions(void)
    338 {
    339   int i, len, ret;
    340   owl_list *psa_list;
    341 
    342   psa_active = 1;
    343   ret = 0;
    344   psa_list = owl_global_get_psa_list(&g);
    345   len = owl_list_get_size(psa_list);
    346   for (i = 0; i < len; i++) {
    347     owl_ps_action *a = owl_list_get_element(psa_list, i);
    348     if (a->callback != NULL && a->callback(a, a->data)) {
    349       ret = 1;
    350     }
    351   }
    352   psa_active = 0;
    353   owl_select_psa_gc();
    354   return ret;
    355 }
    356 
    357 void owl_select(void)
    358 {
    359   int i, max_fd, max_fd2, aim_done, ret;
    360   fd_set r;
    361   fd_set w;
    362   fd_set e;
    363   fd_set aim_rfds, aim_wfds;
    364   struct timespec timeout;
    365   sigset_t mask;
    366 
    367   owl_select_process_timers(&timeout);
    368 
    369   owl_select_mask_signals(&mask);
    370 
    371   if(owl_global_is_interrupted(&g)) {
    372     owl_select_handle_intr(&mask);
    373     return;
    374   }
    375   FD_ZERO(&r);
    376   FD_ZERO(&w);
    377   FD_ZERO(&e);
    378 
    379   max_fd = owl_select_prepare_io_dispatch_fd_sets(&r, &w, &e);
    380 
    381   /* AIM HACK:
    382    *
    383    *  The problem - I'm not sure where to hook into the owl/faim
    384    *  interface to keep track of when the AIM socket(s) open and
    385    *  close. In particular, the bosconn thing throws me off. So,
    386    *  rather than register particular dispatchers for AIM, I look up
    387    *  the relevant FDs and add them to select's watch lists, then
    388    *  check for them individually before moving on to the other
    389    *  dispatchers. --asedeno
    390    */
    391   aim_done = 1;
    392   FD_ZERO(&aim_rfds);
    393   FD_ZERO(&aim_wfds);
    394   if (owl_global_is_doaimevents(&g)) {
    395     aim_done = 0;
    396     max_fd2 = owl_select_aim_hack(&aim_rfds, &aim_wfds);
    397     if (max_fd < max_fd2) max_fd = max_fd2;
    398     for(i = 0; i <= max_fd2; i++) {
    399       if (FD_ISSET(i, &aim_rfds)) {
    400         FD_SET(i, &r);
    401         FD_SET(i, &e);
    402       }
    403       if (FD_ISSET(i, &aim_wfds)) {
    404         FD_SET(i, &w);
    405         FD_SET(i, &e);
    406       }
    407     }
    408   }
    409   /* END AIM HACK */
    410 
    411   if (owl_select_do_pre_select_actions()) {
    412     timeout.tv_sec = 0;
    413     timeout.tv_nsec = 0;
    414   }
    415 
    416   ret = pselect(max_fd+1, &r, &w, &e, &timeout, &mask);
    417 
    418   if(ret < 0 && errno == EINTR) {
    419     if(owl_global_is_interrupted(&g)) {
    420       owl_select_handle_intr(NULL);
    421     }
    422     sigprocmask(SIG_SETMASK, &mask, NULL);
    423     return;
    424   }
    425 
    426   sigprocmask(SIG_SETMASK, &mask, NULL);
    427 
    428   if(ret > 0) {
    429     /* AIM HACK: process all AIM events at once. */
    430     for(i = 0; !aim_done && i <= max_fd; i++) {
    431       if (FD_ISSET(i, &r) || FD_ISSET(i, &w) || FD_ISSET(i, &e)) {
    432         if (FD_ISSET(i, &aim_rfds) || FD_ISSET(i, &aim_wfds)) {
    433           owl_process_aim();
    434           aim_done = 1;
    435         }
    436       }
    437     }
    438     owl_select_io_dispatch(&r, &w, &e, max_fd);
    439   }
     335void owl_select_init(void)
     336{
     337  owl_timer_source = g_source_new(&owl_timer_funcs, sizeof(GSource));
     338  g_source_attach(owl_timer_source, NULL);
     339
     340  owl_io_dispatch_source = g_source_new(&owl_io_dispatch_funcs, sizeof(GSource));
     341  g_source_attach(owl_io_dispatch_source, NULL);
    440342}
    441343
    442344void owl_select_run_loop(void)
    443345{
    444   loop_active = 1;
    445   while (loop_active) {
    446     owl_select();
    447   }
     346  main_context = g_main_context_default();
     347  loop = g_main_loop_new(main_context, FALSE);
     348  g_main_loop_run(loop);
    448349}
    449350
    450351void owl_select_quit_loop(void)
    451352{
    452   loop_active = 0;
    453 }
     353  if (loop) {
     354    g_main_loop_quit(loop);
     355    g_main_loop_unref(loop);
     356    loop = NULL;
     357  }
     358}
     359
     360typedef struct _owl_task { /*noproto*/
     361  void (*cb)(void *);
     362  void *cbdata;
     363  void (*destroy_cbdata)(void *);
     364} owl_task;
     365
     366static gboolean _run_task(gpointer data)
     367{
     368  owl_task *t = data;
     369  if (t->cb)
     370    t->cb(t->cbdata);
     371  return FALSE;
     372}
     373
     374static void _destroy_task(void *data)
     375{
     376  owl_task *t = data;
     377  if (t->destroy_cbdata)
     378    t->destroy_cbdata(t->cbdata);
     379  g_free(t);
     380}
     381
     382void owl_select_post_task(void (*cb)(void*), void *cbdata, void (*destroy_cbdata)(void*), GMainContext *context)
     383{
     384  GSource *source = g_idle_source_new();
     385  owl_task *t = g_new0(owl_task, 1);
     386  t->cb = cb;
     387  t->cbdata = cbdata;
     388  t->destroy_cbdata = destroy_cbdata;
     389  g_source_set_priority(source, G_PRIORITY_DEFAULT);
     390  g_source_set_callback(source, _run_task, t, _destroy_task);
     391  g_source_attach(source, context);
     392  g_source_unref(source);
     393}
  • sepbar.c

    r044f19f r6eb3ed9  
    1616  int x, y, i;
    1717  const char *foo, *appendtosepbar;
     18  int cur_numlines, cur_totallines;
    1819
    1920  ml=owl_global_get_msglist(&g);
     
    5051      wattron(sepwin, A_REVERSE);
    5152
    52   if (owl_mainwin_is_curmsg_truncated(owl_global_get_mainwin(&g))) {
    53     getyx(sepwin, y, x);
    54     wmove(sepwin, y, x+2);
    55     wattron(sepwin, A_BOLD);
    56     waddstr(sepwin, " <truncated> ");
    57     wattroff(sepwin, A_BOLD);
    58   }
    59 
    6053  i=owl_mainwin_get_last_msg(owl_global_get_mainwin(&g));
    6154  if ((i != -1) &&
     
    9083  }
    9184
     85  if (owl_mainwin_is_curmsg_truncated(owl_global_get_mainwin(&g))) {
     86    getyx(sepwin, y, x);
     87    wmove(sepwin, y, x+2);
     88    wattron(sepwin, A_BOLD);
     89    cur_numlines = owl_global_get_curmsg_vert_offset(&g) + 1;
     90    cur_totallines = owl_message_get_numlines(owl_view_get_element(v, owl_global_get_curmsg(&g)));
     91    wprintw(sepwin, " <truncated: %d/%d> ", cur_numlines, cur_totallines);
     92    wattroff(sepwin, A_BOLD);
     93  }
     94
    9295  if (owl_global_get_curmsg_vert_offset(&g)) {
    9396    getyx(sepwin, y, x);
  • tester.c

    rf25df21 re93dd78  
    3232  char *perlerr;
    3333  int status = 0;
     34  SCREEN *screen;
    3435
    3536  if (argc <= 1) {
     
    4142  wnull = fopen("/dev/null", "w");
    4243  rnull = fopen("/dev/null", "r");
    43   newterm("xterm", wnull, rnull);
     44  screen = newterm("xterm", wnull, rnull);
    4445  /* initialize global structures */
    4546  owl_global_init(&g);
     
    9192  /* probably not necessary, but tear down the screen */
    9293  endwin();
     94  delscreen(screen);
    9395  fclose(rnull);
    9496  fclose(wnull);
     
    218220  owl_string_appendf_quoted(g, "%q foo %q%q %s %", "hello", "world is", "can't");
    219221  FAIL_UNLESS("owl_string_appendf",
    220               !strcmp(g_string_free(g, false),
    221                       "hello foo 'world is'\"can't\" %s %"));
     222              !strcmp(g->str, "hello foo 'world is'\"can't\" %s %"));
     223  g_string_free(g, true);
    222224
    223225  /* if (numfailed) printf("*** WARNING: failures encountered with owl_util\n"); */
     
    233235
    234236  printf("# BEGIN testing owl_dict\n");
    235   FAIL_UNLESS("create", 0==owl_dict_create(&d));
     237  owl_dict_create(&d);
    236238  FAIL_UNLESS("insert b", 0==owl_dict_insert_element(&d, "b", bv, owl_dict_noop_delete));
    237239  FAIL_UNLESS("insert d", 0==owl_dict_insert_element(&d, "d", dv, owl_dict_noop_delete));
     
    249251  FAIL_UNLESS("get_size", 3==owl_dict_get_size(&d));
    250252  owl_list_create(&l);
    251   FAIL_UNLESS("get_keys", 0==owl_dict_get_keys(&d, &l));
     253  owl_dict_get_keys(&d, &l);
    252254  FAIL_UNLESS("get_keys result size", 3==owl_list_get_size(&l));
    253255 
  • 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 r83a4af3  
    455455    g_free(newfile);
    456456    fclose(old);
    457     free(actual_filename);
     457    g_free(actual_filename);
    458458    return -1;
    459459  }
     
    466466    g_free(newfile);
    467467    fclose(old);
    468     free(actual_filename);
     468    g_free(actual_filename);
    469469    return -1;
    470470  }
     
    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

    rf203cad r4c7c21f  
    559559int owl_variable_dict_setup(owl_vardict *vd) {
    560560  owl_variable *var, *cur;
    561   if (owl_dict_create(vd)) return(-1);
     561  owl_dict_create(vd);
    562562  for (var = variables_to_init; var->name != NULL; var++) {
    563563    cur = g_new(owl_variable, 1);
     
    641641
    642642void owl_variable_update(owl_variable *var, const char *summary, const char *desc) {
    643   if(var->summary) g_free(var->summary);
     643  g_free(var->summary);
    644644  var->summary = g_strdup(summary);
    645   if(var->description) g_free(var->description);
     645  g_free(var->description);
    646646  var->description = g_strdup(desc);
    647647}
     
    651651  if(old) {
    652652    owl_variable_update(old, summ, desc);
    653     if(old->pval_default) g_free(old->pval_default);
     653    g_free(old->pval_default);
    654654    old->pval_default = g_strdup(initval);
    655655  } else {
     
    944944void owl_variable_delete_default(owl_variable *v)
    945945{
    946   if (v->val) g_free(v->val);
     946  g_free(v->val);
    947947}
    948948
     
    10761076    if (!v->validate_fn(v, newval)) return(-1);
    10771077  }
    1078   if (v->val) g_free(v->val);
     1078  g_free(v->val);
    10791079  v->val = g_strdup(newval);
    10801080  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}
  • 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}
  • zcrypt.c

    r1dd285b r5b197f7  
    1111#include <unistd.h>
    1212#include <sys/types.h>
    13 #include <zephyr/zephyr.h>
    1413#include <glib.h>
    1514#include <string.h>
     
    476475
    477476  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   }
     477    g_free(varname[i]);
     478  }
     479
     480  g_free(filename);
    486481
    487482  return keyfile;
     
    773768  err = call_filter("gpg", argv, in, &out, &status);
    774769  if(err || status) {
    775     if(out) g_free(out);
     770    g_free(out);
    776771    return FALSE;
    777772  }
     
    856851  err = call_filter("gpg", argv, in, &out, &status);
    857852  if(err || status) {
    858     if(out) g_free(out);
     853    g_free(out);
    859854    return FALSE;
    860855  }
  • zephyr.c

    rf203cad rb848e30  
    88
    99#ifdef HAVE_LIBZEPHYR
     10static GSource *owl_zephyr_event_source_new(int fd);
     11
     12static gboolean owl_zephyr_event_prepare(GSource *source, int *timeout);
     13static gboolean owl_zephyr_event_check(GSource *source);
     14static gboolean owl_zephyr_event_dispatch(GSource *source, GSourceFunc callback, gpointer user_data);
     15
    1016static GList *deferred_subs = NULL;
    1117
     
    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;
     
    417447    return 0;
    418448  }
    419   if (buffer)
    420     g_free(buffer);
     449  g_free(buffer);
    421450
    422451  return owl_zephyr_loadsubs_helper(subs, count);
     
    14221451#define OWL_MAX_ZEPHYRGRAMS_TO_PROCESS 20
    14231452
     1453#ifdef HAVE_LIBZEPHYR
    14241454static int _owl_zephyr_process_events(void)
    14251455{
    14261456  int zpendcount=0;
    1427 #ifdef HAVE_LIBZEPHYR
    14281457  ZNotice_t notice;
    14291458  Code_t code;
     
    14661495    }
    14671496  }
    1468 #endif
    14691497  return zpendcount;
    14701498}
    14711499
    1472 void owl_zephyr_process_events(const owl_io_dispatch *d, void *data)
    1473 {
     1500typedef struct { /*noproto*/
     1501  GSource source;
     1502  GPollFD poll_fd;
     1503} owl_zephyr_event_source;
     1504
     1505static GSource *owl_zephyr_event_source_new(int fd) {
     1506  GSource *source;
     1507  owl_zephyr_event_source *event_source;
     1508
     1509  source = g_source_new(&zephyr_event_funcs, sizeof(owl_zephyr_event_source));
     1510  event_source = (owl_zephyr_event_source*) source;
     1511  event_source->poll_fd.fd = fd;
     1512  event_source->poll_fd.events = G_IO_IN | G_IO_HUP | G_IO_PRI | G_IO_ERR;
     1513  g_source_add_poll(source, &event_source->poll_fd);
     1514
     1515  return source;
     1516}
     1517
     1518static gboolean owl_zephyr_event_prepare(GSource *source, int *timeout) {
     1519  *timeout = -1;
     1520  return owl_zephyr_zqlength() > 0;
     1521}
     1522
     1523static gboolean owl_zephyr_event_check(GSource *source) {
     1524  owl_zephyr_event_source *event_source = (owl_zephyr_event_source*)source;
     1525  if (event_source->poll_fd.revents & event_source->poll_fd.events)
     1526    return owl_zephyr_zpending() > 0;
     1527  return FALSE;
     1528}
     1529
     1530static gboolean owl_zephyr_event_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) {
    14741531  _owl_zephyr_process_events();
    1475 }
    1476 
    1477 int owl_zephyr_pre_select_action(owl_ps_action *a, void *p)
    1478 {
    1479   return _owl_zephyr_process_events();
    1480 }
     1532  return TRUE;
     1533}
     1534#endif
  • 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.