Changes in / [f97c1a6:1d21d9f]


Ignore:
Files:
1 deleted
33 edited

Legend:

Unmodified
Added
Removed
  • README

    r13ee8f2 raeadc74  
    1818BarnOwl currently requires the following perl modules off of CPAN:
    1919
    20 AnyEvent
    2120PAR
    2221Net::DNS
     
    3130The IRC module requires:
    3231
    33 AnyEvent::IRC
     32Net::IRC
    3433Class::Accessor
    3534
  • cmd.c

    r4c7c21f rf25df21  
    1212
    1313int owl_cmddict_setup(owl_cmddict *cd) {
    14   owl_cmddict_init(cd);
     14  if (0 != owl_cmddict_init(cd)) return(-1);
    1515  if (0 != owl_cmddict_add_from_list(cd, commands_to_init)) return(-1);
    1616  return(0);
    1717}
    1818
    19 void owl_cmddict_init(owl_cmddict *cd) {
    20   owl_dict_create(cd);
     19int owl_cmddict_init(owl_cmddict *cd) {
     20  if (owl_dict_create(cd)) return(-1);
     21  return(0);
    2122}
    2223
     
    9899
    99100char *owl_cmddict_execute_argv(const owl_cmddict *cd, const owl_context *ctx, const char *const *argv, int argc) {
    100   char *buff;
    101   char *retval = NULL;
    102 
    103   buff = g_strjoinv(" ", (char**)argv);
    104   retval = _owl_cmddict_execute(cd, ctx, argv, argc, buff);
    105   g_free(buff);
    106 
     101  GString *buf = g_string_new("");
     102  int i;
     103  char *retval;
     104
     105  /* We weren't given a command line, so fabricate a valid one. */
     106  for(i = 0; i < argc; i++) {
     107    if (i != 0)
     108      g_string_append_c(buf, ' ');
     109    owl_string_append_quoted_arg(buf, argv[i]);
     110  }
     111
     112  retval = _owl_cmddict_execute(cd, ctx, argv, argc, buf->str);
     113
     114  g_string_free(buf, true);
    107115  return retval;
    108116}
     
    134142void owl_cmd_cleanup(owl_cmd *cmd)
    135143{
    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);
     144  if (cmd->name) g_free(cmd->name);
     145  if (cmd->summary) g_free(cmd->summary);
     146  if (cmd->usage) g_free(cmd->usage);
     147  if (cmd->description) g_free(cmd->description);
     148  if (cmd->cmd_aliased_to) g_free(cmd->cmd_aliased_to);
    141149  if (cmd->cmd_perl) owl_perlconfig_cmd_cleanup(cmd);
    142150}
  • commands.c

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

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

    r4c7c21f rf25df21  
    1515#define GROWBY 3 / 2
    1616
    17 void owl_dict_create(owl_dict *d) {
     17int 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);
    2123}
    2224
     
    5860/* Appends dictionary keys to a list.  Duplicates the keys,
    5961 * so they will need to be freed by the caller. */
    60 void owl_dict_get_keys(const owl_dict *d, owl_list *l) {
     62int owl_dict_get_keys(const owl_dict *d, owl_list *l) {
    6163  int i;
     64  char *dupk;
    6265  for (i=0; i<d->size; i++) {
    63     owl_list_append_element(l, g_strdup(d->els[i].k));
     66    if ((dupk = g_strdup(d->els[i].k)) == NULL) return(-1);
     67    owl_list_append_element(l, dupk);
    6468  }
     69  return(0);
    6570}
    6671
     
    7984{
    8085  int pos, found;
     86  char *dupk;
    8187  found = _owl_dict_find_pos(d, k, &pos);
    8288  if (found && delete_on_replace) {
     
    9399      if (d->els==NULL) return(-1);
    94100    }
     101    if ((dupk = g_strdup(k)) == NULL) return(-1);
    95102    if (pos!=d->size) {
    96103      /* shift forward to leave us a slot */
     
    99106    }
    100107    d->size++;
    101     d->els[pos].k = g_strdup(k);
     108    d->els[pos].k = dupk;
    102109    d->els[pos].v = v;   
    103110    return(0);
  • editwin.c

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

    r7b4f3be r4479497  
    184184}
    185185
     186static 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
    186193static void _owl_fmtext_wcolor_set(WINDOW *w, short pair)
    187194{
    188   if (has_colors()) {
     195  if (owl_global_get_hascolors(&g)) {
    189196      wcolor_set(w,pair,NULL);
    190197      wbkgdset(w, COLOR_PAIR(pair));
     
    214221  bg = default_bgcolor;
    215222  _owl_fmtext_wattrset(w, attr);
    216   pair = owl_fmtext_get_colorpair(fg, bg);
     223  _owl_fmtext_update_colorpair(fg, bg, &pair);
    217224  _owl_fmtext_wcolor_set(w, pair);
    218225
     
    263270      if (bg == OWL_COLOR_DEFAULT) bg = default_bgcolor;
    264271      _owl_fmtext_wattrset(w, attr);
    265       pair = owl_fmtext_get_colorpair(fg, bg);
     272      _owl_fmtext_update_colorpair(fg, bg, &pair);
    266273      _owl_fmtext_wcolor_set(w, pair);
    267274
     
    655662           continue */
    656663      } else if (!strcasecmp(buff, "@color")
     664                 && owl_global_get_hascolors(&g)
    657665                 && owl_global_is_colorztext(&g)) {
    658666        g_free(buff);
     
    812820    }
    813821  }
    814   if (has_colors()) {
     822  if (owl_global_get_hascolors(&g)) {
    815823    for(i = 0; i < 8; i++) {
    816824      short fg, bg;
     
    827835  owl_colorpair_mgr *cpmgr;
    828836  short pair;
    829 
    830   if (!has_colors())
    831     return 0;
    832837
    833838  /* Sanity (Bounds) Check */
     
    847852  if (!(pair != -1 && pair < cpmgr->next)) {
    848853    /* If we didn't find a pair, search for a free one to assign. */
    849     pair = (cpmgr->next < owl_util_get_colorpairs()) ? cpmgr->next : -1;
     854    pair = (cpmgr->next < COLOR_PAIRS) ? cpmgr->next : -1;
    850855    if (pair != -1) {
    851856      /* We found a free pair, initialize it. */
  • functions.c

    r47128d9 r47128d9  
    3232  char *rv;
    3333  rv=owl_function_command(cmdbuff);
    34   g_free(rv);
     34  if (rv) g_free(rv);
    3535}
    3636
     
    453453
    454454  if (rv || status) {
    455     g_free(cryptmsg);
     455    if(cryptmsg) 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   g_free(ret);
     993  if (ret) g_free(ret);
    994994
    995995  /* signal our child process, if any */
     
    18171817          owl_global_get_cols(&g));
    18181818
    1819   if (has_colors()) {
     1819  if (owl_global_get_hascolors(&g)) {
    18201820    owl_fmtext_append_normal(&fm, "Color: Yes\n");
    1821     owl_fmtext_appendf_normal(&fm, "Number of color pairs: %i\n", owl_util_get_colorpairs());
     1821    owl_fmtext_appendf_normal(&fm, "Number of color pairs: %i\n", owl_global_get_colorpairs(&g));
    18221822    owl_fmtext_appendf_normal(&fm, "Can change colors: %s\n", can_change_color() ? "yes" : "no");
    18231823  } else {
     
    22262226    f = fl->data;
    22272227    owl_fmtext_append_normal(&fm, "   ");
    2228     owl_fmtext_append_normal_color(&fm, owl_filter_get_name(f),
    2229                                    owl_filter_get_fgcolor(f),
    2230                                    owl_filter_get_bgcolor(f));
     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    }
    22312233    owl_fmtext_append_normal(&fm, "\n");
    22322234  }
     
    23582360done:
    23592361  g_free(class);
    2360   g_free(instance);
     2362  if (instance) {
     2363    g_free(instance);
     2364  }
    23612365  return(filtname);
    23622366}
     
    25192523
    25202524  filtname = g_strdup_printf("conversation-%s", ccs);
    2521   g_strdelimit(filtname, " ", '-');
     2525  owl_text_tr(filtname, ' ', '-');
    25222526
    25232527  if (owl_global_get_filter(&g, filtname)) {
     
    29552959 
    29562960  if (viewsize==0) {
    2957     owl_function_makemsg("No messages present");
     2961    owl_function_error("No messages present");
    29582962    return;
    29592963  }
     
    29692973  /* bounds check */
    29702974  if (start>=viewsize || start<0) {
    2971     owl_function_makemsg("No further matches found");
     2975    owl_function_error("No further matches found");
    29722976    return;
    29732977  }
     
    29983002  }
    29993003  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
    3000   owl_function_makemsg("No matches found");
     3004  owl_function_error("No matches found");
    30013005}
    30023006
  • global.c

    rdc1edbd rdc1edbd  
    5454  g->direction=OWL_DIRECTION_DOWNWARDS;
    5555  g->zaway=0;
     56  if (has_colors()) {
     57    g->hascolors=1;
     58  }
     59  g->colorpairs=COLOR_PAIRS;
    5660  owl_fmtext_init_colorpair_mgr(&(g->cpmgr));
    5761  g->debug=OWL_DEBUG;
     
    508512
    509513void owl_global_set_startupargs(owl_global *g, int argc, char **argv) {
    510   g_free(g->startupargs);
     514  if (g->startupargs) g_free(g->startupargs);
    511515  g->startupargs = g_strjoinv(" ", argv);
    512516}
     
    573577owl_view *owl_global_get_current_view(owl_global *g) {
    574578  return(&(g->current_view));
     579}
     580
     581/* has colors */
     582
     583int owl_global_get_hascolors(const owl_global *g) {
     584  if (g->hascolors) return(1);
     585  return(0);
     586}
     587
     588/* color pairs */
     589
     590int owl_global_get_colorpairs(const owl_global *g) {
     591  return(g->colorpairs);
    575592}
    576593
     
    756773}
    757774
    758 void owl_global_get_style_names(const owl_global *g, owl_list *l) {
    759   owl_dict_get_keys(&(g->styledict), l);
     775int owl_global_get_style_names(const owl_global *g, owl_list *l) {
     776  return owl_dict_get_keys(&(g->styledict), l);
    760777}
    761778
  • keybinding.c

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

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

    rfda61d3 rddbbcffa  
    55#define GROWBY 3 / 2
    66
    7 void owl_list_create(owl_list *l)
     7int 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);
    1214}
    1315
  • logging.c

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

    r1d21d9f r1d21d9f  
    4141  char *confdir;
    4242  bool debug;
     43  bool rm_debug;
    4344} owl_options;
    4445
     
    4950  fprintf(stderr, "  -n,--no-subs        don't load zephyr subscriptions\n");
    5051  fprintf(stderr, "  -d,--debug          enable debugging\n");
     52  fprintf(stderr, "  -D,--remove-debug   enable debugging and delete previous debug file\n");
    5153  fprintf(stderr, "  -v,--version        print the Barnowl version number and exit\n");
    5254  fprintf(stderr, "  -h,--help           print this help message\n");
     
    6466    { "tty",             1, 0, 't' },
    6567    { "debug",           0, 0, 'd' },
     68    { "remove-debug",    0, 0, 'D' },
    6669    { "version",         0, 0, 'v' },
    6770    { "help",            0, 0, 'h' },
     
    8588      opts->tty = g_strdup(optarg);
    8689      break;
     90    case 'D':
     91      opts->rm_debug = 1;
     92      /* fallthrough */
    8793    case 'd':
    8894      opts->debug = 1;
     
    503509  /* owl global init */
    504510  owl_global_init(&g);
     511  if (opts.rm_debug) unlink(OWL_DEBUG_FILE);
    505512  if (opts.debug) owl_global_set_debug_on(&g);
    506513  if (opts.confdir) owl_global_set_confdir(&g, opts.confdir);
     
    570577  owl_function_debugmsg("startup: executing perl startup, if applicable");
    571578  perlout = owl_perlconfig_execute("BarnOwl::Hooks::_startup();");
    572   g_free(perlout);
     579  if (perlout) g_free(perlout);
    573580
    574581  /* welcome message */
  • owl.h

    rdc1edbd rdc1edbd  
    6666#include "window.h"
    6767
    68 #ifndef OWL_VERSION_STRING
    6968#ifdef  GIT_VERSION
    7069#define stringify(x)       __stringify(x)
     
    7473#define OWL_VERSION_STRING PACKAGE_VERSION
    7574#endif
    76 #endif /* !OWL_VERSION_STRING */
    7775
    7876/* Feature that is being tested to redirect stderr through a pipe.
     
    604602  char *startupargs;
    605603  int nextmsgid;
     604  int hascolors;
     605  int colorpairs;
    606606  owl_colorpair_mgr cpmgr;
    607607  pid_t newmsgproc_pid;
  • perl/lib/BarnOwl.pm

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

    r60b49a7 re04b7a1  
    6666sub action {shift->{action}}
    6767sub reason {shift->{reason}}
    68 sub old_nick {shift->{old_nick}};
    6968
    7069# display
     
    8180}
    8281
    83 sub login_extra {
     82sub login_extra { 
    8483    my $self = shift;
    8584    if ($self->action eq "quit") {
    8685        return $self->reason;
    87     } elsif ($self->action eq 'nick change') {
    88         return "was: " . $self->old_nick;
    8986    } else {
    9087        return $self->channel;
  • perl/modules/IRC/lib/BarnOwl/Module/IRC.pm

    r5c6d661 r9620c8d  
    2020use BarnOwl::Module::IRC::Completion;
    2121
    22 use AnyEvent::IRC;
     22use Net::IRC;
    2323use Getopt::Long;
    2424use Encode;
     
    3030# Hash alias -> BarnOwl::Module::IRC::Connection object
    3131our %ircnets;
     32our %channels;
     33our %reconnect;
    3234
    3335sub startup {
     
    6870
    6971    register_commands();
     72    register_handlers();
    7073    BarnOwl::filter(qw{irc type ^IRC$ or ( type ^admin$ and adminheader ^IRC$ )});
    7174}
     
    7376sub shutdown {
    7477    for my $conn (values %ircnets) {
    75         $conn->conn->disconnect('Quitting');
     78        $conn->conn->disconnect();
    7679    }
    7780}
     
    9598        $list .= "\n";
    9699
    97         for my $chan (keys %{$conn->conn->{channel_list}}) {
     100        for my $chan (keys %channels) {
     101            next unless grep $_ eq $conn, @{$channels{$chan}};
    98102            $list .= "  $chan\n";
    99103        }
     
    101105
    102106    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
     117sub OwlProcess {
     118    return unless defined $irc;
     119    eval {
     120        $irc->do_one_loop();
     121    };
     122    return;
     123}
     124
     125
     126sub register_handlers {
     127    if(!$irc) {
     128        $irc = Net::IRC->new;
     129        $irc->timeout(0);
     130    }
    103131}
    104132
     
    378406    }
    379407
    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;
     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
    389425    return;
    390426}
     
    393429    my $cmd = shift;
    394430    my $conn = shift;
    395     if ($conn->conn->{socket}) {
    396         $conn->did_quit(1);
    397         $conn->conn->disconnect("Goodbye!");
    398     } elsif ($conn->{reconnect_timer}) {
     431    if ($conn->conn->connected) {
     432        $conn->conn->disconnect;
     433    } elsif ($reconnect{$conn->alias}) {
    399434        BarnOwl::admin_message('IRC',
    400435                               "[" . $conn->alias . "] Reconnect cancelled");
    401436        $conn->cancel_reconnect;
    402         delete $ircnets{$conn->alias};
    403437    }
    404438}
     
    429463    for my $body (@msgs) {
    430464        if ($body =~ /^\/me (.*)/) {
    431             $conn->me($to, Encode::encode('utf-8', $1));
     465            $conn->conn->me($to, Encode::encode('utf-8', $1));
    432466            $body = '* '.$conn->nick.' '.$1;
    433467        } else {
    434             $conn->conn->send_msg('privmsg', $to, Encode::encode('utf-8', $body));
     468            $conn->conn->privmsg($to, Encode::encode('utf-8', $body));
    435469        }
    436470        my $msg = BarnOwl::Message->new(
     
    457491    my $target = shift;
    458492    $target ||= shift;
    459     $conn->conn->send_msg(mode => $target, @_);
     493    $conn->conn->mode($target, @_);
    460494    return;
    461495}
     
    465499    my $conn = shift;
    466500    my $chan = shift or die("Usage: $cmd channel\n");
    467     $conn->conn->send_msg(join => $chan, @_);
     501    $channels{$chan} ||= [];
     502    push @{$channels{$chan}}, $conn;
     503    $conn->conn->join($chan, @_);
    468504    return;
    469505}
     
    473509    my $conn = shift;
    474510    my $chan = shift;
    475     $conn->conn->send_msg(part => $chan);
     511    $channels{$chan} = [grep {$_ ne $conn} @{$channels{$chan} || []}];
     512    $conn->conn->part($chan);
    476513    return;
    477514}
     
    481518    my $conn = shift;
    482519    my $nick = shift or die("Usage: $cmd <new nick>\n");
    483     $conn->conn->send_msg(nick => $nick);
     520    $conn->conn->nick($nick);
    484521    return;
    485522}
     
    490527    my $chan = shift;
    491528    $conn->names_tmp([]);
    492     $conn->conn->send_msg(names => $chan);
     529    $conn->conn->names($chan);
    493530    return;
    494531}
     
    498535    my $conn = shift;
    499536    my $who = shift || die("Usage: $cmd <user>\n");
    500     $conn->conn->send_msg(whois => $who);
     537    $conn->conn->whois($who);
    501538    return;
    502539}
     
    505542    my $cmd = shift;
    506543    my $conn = shift;
    507     $conn->conn->send_msg('motd');
     544    $conn->conn->motd;
    508545    return;
    509546}
     
    523560    my $conn = shift;
    524561    my $who = shift || die("Usage: $cmd <user>\n");
    525     $conn->conn->send_msg(who => $who);
     562    BarnOwl::error("WHO $cmd $conn $who");
     563    $conn->conn->who($who);
    526564    return;
    527565}
     
    531569    my $conn = shift;
    532570    my $type = shift || die("Usage: $cmd <chiklmouy> [server] \n");
    533     $conn->conn->send_msg(stats => $type, @_);
     571    $conn->conn->stats($type, @_);
    534572    return;
    535573}
     
    539577    my $conn = shift;
    540578    my $chan = shift;
    541     $conn->conn->send_msg(topic => $chan, @_ ? join(" ", @_) : undef);
     579    $conn->conn->topic($chan, @_ ? join(" ", @_) : undef);
    542580    return;
    543581}
     
    546584    my $cmd = shift;
    547585    my $conn = shift;
    548     $conn->conn->send_msg(@_);
     586    $conn->conn->sl(join(" ", @_));
    549587    return;
    550588}
     
    553591########################### Utilities/Helpers ##################################
    554592################################################################################
    555 
    556 sub 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 }
    566593
    567594sub mk_irc_command {
     
    587614            $channel = $ARGV[0];
    588615            if(defined($channel) && $channel =~ /^#/) {
    589                 if(my $c = find_channel($channel)) {
     616                if($channels{$channel} && @{$channels{$channel}} == 1) {
    590617                    shift @ARGV;
    591                     $conn ||= $c;
     618                    $conn = $channels{$channel}[0] unless $conn;
    592619                }
    593620            } elsif ($m && $m->type eq 'IRC' && !$m->is_private) {
     
    627654    my $allow_disconnected = shift;
    628655
    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.");
     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")
    635659}
    636660
  • perl/modules/IRC/lib/BarnOwl/Module/IRC/Completion.pm

    rdace02a r955a36e  
    1111sub complete_networks { keys %BarnOwl::Module::IRC::ircnets }
    1212sub complete_dests    { keys %users, complete_channels() }
    13 sub 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 }
     13sub complete_channels { keys %BarnOwl::Module::IRC::channels }
    2214sub complete_nicks    { keys %users }
    2315sub complete_servers  { keys %servers }
  • perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm

    r13ee8f2 rfb6e8e3  
    1111=head1 DESCRIPTION
    1212
    13 This module is a wrapper around AnyEvent::IRC::Client for BarnOwl's IRC
     13This module is a wrapper around Net::IRC::Connection for BarnOwl's IRC
    1414support
    1515
    1616=cut
    1717
    18 use AnyEvent::IRC::Client;
    19 use AnyEvent::IRC::Util qw(split_prefix prefix_nick encode_ctcp);
    20 
    21 use base qw(Class::Accessor);
    22 use Exporter 'import';
    23 __PACKAGE__->mk_accessors(qw(conn alias motd names_tmp whois_tmp
    24                              server autoconnect_channels
    25                              connect_args backoff did_quit));
    26 our @EXPORT_OK = qw(is_private);
     18use Net::IRC::Connection;
     19
     20use base qw(Class::Accessor Exporter);
     21__PACKAGE__->mk_accessors(qw(conn alias channels motd names_tmp whois_tmp));
     22our @EXPORT_OK = qw(&is_private);
    2723
    2824use BarnOwl;
    2925use Scalar::Util qw(weaken);
    3026
     27BEGIN {
     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
    3137sub new {
    3238    my $class = shift;
     39    my $irc = shift;
    3340    my $alias = shift;
    34     my $host  = shift;
    35     my $port  = shift;
    36     my $args  = shift;
    37     my $nick = $args->{nick};
    38     my $conn = AnyEvent::IRC::Client->new();
     41    my %args = (@_);
     42    my $conn = Net::IRC::Connection->new($irc, %args);
    3943    my $self = bless({}, $class);
    4044    $self->conn($conn);
    41     $self->autoconnect_channels([]);
    4245    $self->alias($alias);
    43     $self->server($host);
     46    $self->channels([]);
    4447    $self->motd("");
    4548    $self->names_tmp(0);
    46     $self->backoff(0);
    4749    $self->whois_tmp("");
    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}})) });
     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(@_) });
    10377
    10478    return $self;
    105 }
    106 
    107 sub nick {
    108     my $self = shift;
    109     return $self->conn->nick;
    11079}
    11180
     
    11483    my $self = shift;
    11584    return $self->conn->socket;
    116 }
    117 
    118 sub me {
    119     my ($self, $to, $msg) = @_;
    120     $self->conn->send_msg('privmsg', $to,
    121                           encode_ctcp(['ACTION', $msg]))
    12285}
    12386
     
    12992    my $self = shift;
    13093    my $evt = shift;
    131     my %args = (
     94    return BarnOwl::Message->new(
    13295        type        => 'IRC',
    13396        server      => $self->server,
    13497        network     => $self->alias,
     98        sender      => $evt->nick,
     99        hostname    => $evt->host,
     100        from        => $evt->from,
    135101        @_
    136102       );
    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);
    145103}
    146104
    147105sub on_msg {
    148     my ($self, $recipient, $evt) = @_;
    149     my $body = strip_irc_formatting($evt->{params}->[1]);
    150     $self->handle_message($recipient, $evt, $body);
    151 }
    152 
    153 sub 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 
    164 sub handle_message {
    165     my ($self, $recipient, $evt, $body) = @_;
     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';
    166111    my $msg = $self->new_message($evt,
    167112        direction   => 'in',
    168113        recipient   => $recipient,
    169         body        => $body,
    170         ($evt->{command}||'') eq 'notice' ?
     114        body => $body,
     115        $evt->type eq 'notice' ?
    171116          (notice     => 'true') : (),
    172117        is_private($recipient) ?
    173118          (private  => 'true') : (channel => $recipient),
    174119        replycmd    => BarnOwl::quote('irc-msg', '-a', $self->alias,
    175            (is_private($recipient) ? prefix_nick($evt) : $recipient)),
    176         replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, prefix_nick($evt)),
     120          (is_private($recipient) ? $evt->nick : $recipient)),
     121        replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, $evt->nick),
    177122       );
    178123
     
    180125}
    181126
     127sub on_ping {
     128    my ($self, $evt) = @_;
     129    $self->conn->ctcp_reply($evt->nick, join (' ', ($evt->args)));
     130}
    182131
    183132sub on_admin_msg {
    184133    my ($self, $evt) = @_;
    185     return if BarnOwl::Module::IRC->skip_msg($evt->{command});
    186     BarnOwl::admin_message("IRC",
    187             BarnOwl::Style::boldify('IRC ' . $evt->{command} . ' message from '
     134    return if BarnOwl::Module::IRC->skip_msg($evt->type);
     135    BarnOwl::admin_message("IRC",
     136            BarnOwl::Style::boldify('IRC ' . $evt->type . ' message from '
    188137                . $self->alias) . "\n"
    189             . strip_irc_formatting(join ' ', cdr($evt->{params})));
     138            . strip_irc_formatting(join ' ', cdr($evt->args)));
    190139}
    191140
    192141sub on_motdstart {
    193142    my ($self, $evt) = @_;
    194     $self->motd(join "\n", cdr(@{$evt->{params}}));
     143    $self->motd(join "\n", cdr($evt->args));
    195144}
    196145
    197146sub on_motd {
    198147    my ($self, $evt) = @_;
    199     $self->motd(join "\n", $self->motd, cdr(@{$evt->{params}}));
     148    $self->motd(join "\n", $self->motd, cdr($evt->args));
    200149}
    201150
    202151sub on_endofmotd {
    203152    my ($self, $evt) = @_;
    204     $self->motd(join "\n", $self->motd, cdr(@{$evt->{params}}));
     153    $self->motd(join "\n", $self->motd, cdr($evt->args));
    205154    BarnOwl::admin_message("IRC",
    206155            BarnOwl::Style::boldify('MOTD for ' . $self->alias) . "\n"
     
    210159sub on_join {
    211160    my ($self, $evt) = @_;
    212     my $chan = $evt->{params}[0];
    213161    my $msg = $self->new_message($evt,
    214162        loginout   => 'login',
    215163        action     => 'join',
    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)),
     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),
    219167        );
    220168    BarnOwl::queue_message($msg);
     169    push @{$self->channels}, $evt->to;
    221170}
    222171
    223172sub on_part {
    224173    my ($self, $evt) = @_;
    225     my $chan = $evt->{params}[0];
    226174    my $msg = $self->new_message($evt,
    227175        loginout   => 'logout',
    228176        action     => 'part',
    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)),
     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),
    232180        );
    233181    BarnOwl::queue_message($msg);
     182    $self->channels([ grep {$_ ne $evt->to} @{$self->channels}]);
    234183}
    235184
     
    239188        loginout   => 'logout',
    240189        action     => 'quit',
    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)),
     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),
    245194        );
    246195    BarnOwl::queue_message($msg);
     
    249198sub disconnect {
    250199    my $self = shift;
    251     $self->conn->disconnect;
     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});
     210    $self->motd("");
    252211}
    253212
    254213sub on_disconnect {
    255     my ($self, $why) = @_;
     214    my ($self, $evt) = @_;
     215    $self->disconnect;
    256216    BarnOwl::admin_message('IRC',
    257                            "[" . $self->alias . "] Disconnected from server: $why");
    258     $self->motd("");
    259     if (!$self->did_quit) {
     217                           "[" . $self->alias . "] Disconnected from server");
     218    if ($evt->format and $evt->format eq "error") {
    260219        $self->schedule_reconnect;
    261220    } else {
    262         delete $BarnOwl::Module::IRC::ircnets{$self->alias};
    263     }
    264 }
    265 
    266 sub on_error {
    267     my ($self, $evt) = @_;
    268     BarnOwl::admin_message('IRC',
     221        $self->channels([]);
     222    }
     223}
     224
     225sub on_nickinuse {
     226    my ($self, $evt) = @_;
     227    BarnOwl::admin_message("IRC",
    269228                           "[" . $self->alias . "] " .
    270                            "Error: " . join(" ", @{$evt->{params}}));
    271 }
    272 
    273 sub on_nickinuse {
    274     my ($self, $evt) = @_;
    275     BarnOwl::admin_message("IRC",
    276                            "[" . $self->alias . "] " .
    277                            $evt->{params}->[1] . ": Nick already in use");
    278 }
    279 
    280 sub on_nick {
    281     my ($self, $old_nick, $new_nick, $is_me) = @_;
    282     if ($is_me) {
     229                           [$evt->args]->[1] . ": Nick already in use");
     230    $self->disconnect unless $self->motd;
     231}
     232
     233sub on_topic {
     234    my ($self, $evt) = @_;
     235    my @args = $evt->args;
     236    if (scalar @args > 1) {
    283237        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     }
    299 }
    300 
    301 sub on_topic {
    302     my ($self, $channel, $topic, $who) = @_;
    303     if ($channel) {
    304         BarnOwl::admin_message("IRC",
    305                 "Topic for $channel on " . $self->alias . " is $topic");
     238                "Topic for $args[1] on " . $self->alias . " is $args[2]");
    306239    } else {
    307240        BarnOwl::admin_message("IRC",
    308                 "Topic changed to $channel");
     241                "Topic changed to $args[0]");
    309242    }
    310243}
     
    312245sub on_topicinfo {
    313246    my ($self, $evt) = @_;
    314     my @args = @{$evt->{params}};
     247    my @args = $evt->args;
    315248    BarnOwl::admin_message("IRC",
    316249        "Topic for $args[1] set by $args[2] at " . localtime($args[3]));
     
    324257    my ($self, $evt) = @_;
    325258    return unless $self->names_tmp;
    326     $self->names_tmp([@{$self->names_tmp},
    327                       map {prefix_nick($_)} split(' ', $evt->{params}[3])]);
     259    $self->names_tmp([@{$self->names_tmp}, split(' ', [$evt->args]->[3])]);
    328260}
    329261
     
    340272    my ($self, $evt) = @_;
    341273    return unless $self->names_tmp;
    342     my $names = BarnOwl::Style::boldify("Members of " . $evt->{params}->[1] . ":\n");
     274    my $names = BarnOwl::Style::boldify("Members of " . [$evt->args]->[1] . ":\n");
    343275    for my $name (sort {cmp_user($a, $b)} @{$self->names_tmp}) {
    344276        $names .= "  $name\n";
     
    350282sub on_whois {
    351283    my ($self, $evt) = @_;
    352     my %names = (
    353         311 => 'user',
    354         312 => 'server',
    355         319 => 'channels',
    356         330 => 'whowas',
    357        );
    358284    $self->whois_tmp(
    359         $self->whois_tmp . "\n" . $names{$evt->{command}} . ":\n  " .
    360         join("\n  ", cdr(cdr(@{$evt->{params}}))) . "\n"
    361        );
     285      $self->whois_tmp . "\n" . $evt->type . ":\n  " .
     286      join("\n  ", cdr(cdr($evt->args))) . "\n"
     287    );
    362288}
    363289
     
    365291    my ($self, $evt) = @_;
    366292    BarnOwl::popless_ztext(
    367         BarnOwl::Style::boldify("/whois for " . $evt->{params}->[1] . ":\n") .
     293        BarnOwl::Style::boldify("/whois for " . [$evt->args]->[1] . ":\n") .
    368294        $self->whois_tmp
    369295    );
     
    374300    my ($self, $evt) = @_;
    375301    BarnOwl::admin_message("IRC",
    376                            "[" . $self->alias . "] User " . (prefix_nick($evt)) . + " set mode " .
    377                            join(" ", cdr(@{$evt->{params}})) . " on " . $evt->{params}->[0]
     302                           "[" . $self->alias . "] User " . ($evt->nick) . + " set mode " .
     303                           join(" ", $evt->args) . "on " . $evt->to->[0]
    378304                          );
    379305}
    380306
    381 sub on_nosuch {
    382     my ($self, $evt) = @_;
    383     my %things = (401 => 'nick', 402 => 'server', 403 => 'channel');
     307sub on_nosuchchannel {
     308    my ($self, $evt) = @_;
    384309    BarnOwl::admin_message("IRC",
    385310                           "[" . $self->alias . "] " .
    386                            "No such @{[$things{$evt->{command}}]}: @{[$evt->{params}->[1]]}")
     311                           "No such channel: " . [$evt->args]->[1])
    387312}
    388313
     
    398323sub schedule_reconnect {
    399324    my $self = shift;
    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 
     325    my $interval = shift || 5;
     326    delete $BarnOwl::Module::IRC::ircnets{$self->alias};
     327    $BarnOwl::Module::IRC::reconnect{$self->alias} = $self;
    409328    my $weak = $self;
    410329    weaken($weak);
     
    424343sub cancel_reconnect {
    425344    my $self = shift;
    426 
     345    delete $BarnOwl::Module::IRC::reconnect{$self->alias};
    427346    if (defined $self->{reconnect_timer}) {
    428347        $self->{reconnect_timer}->stop;
    429348    }
    430349    delete $self->{reconnect_timer};
    431 }
    432 
    433 sub on_connect {
    434     my $self = shift;
    435     $self->connected("Connected to " . $self->alias . " as " . $self->nick)
    436350}
    437351
     
    441355    BarnOwl::admin_message("IRC", $msg);
    442356    $self->cancel_reconnect;
    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);
     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;
    454361}
    455362
    456363sub reconnect {
    457364    my $self = shift;
    458     my $backoff = $self->backoff;
    459 
    460     $self->autoconnect_channels([keys(%{$self->{channel_list}})]);
    461     $self->conn->connect(@{$self->connect_args});
     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 );
    462379}
    463380
  • perlconfig.c

    r3b8a563 rf25df21  
    403403  }
    404404
    405   sv_setpv(get_sv("BarnOwl::VERSION", TRUE), OWL_VERSION_STRING);
    406 
    407405  /* Add the system lib path to @INC */
    408406  inc = get_av("INC", 0);
     
    467465                                           :"BarnOwl::_receive_msg_legacy_wrap", m);
    468466  }
    469   g_free(ptr);
     467  if (ptr) g_free(ptr);
    470468}
    471469
     
    478476                                           :"BarnOwl::Hooks::_new_msg", m);
    479477  }
    480   g_free(ptr);
     478  if (ptr) g_free(ptr);
    481479}
    482480
  • perlglue.xs

    r3b8a563 rf25df21  
    4343                        rv = owl_function_command(cmd);
    4444                } else {
    45                         /* Ensure this is NULL-terminated. */
    46                         argv = g_new0(const char *, items + 1);
     45                        argv = g_new(const char *, items + 1);
    4746                        argv[0] = cmd;
    4847                        for(i = 1; i < items; i++) {
     
    5756                RETVAL
    5857        CLEANUP:
    59                 g_free(rv);
     58                if (rv) g_free(rv);
    6059
    6160SV *
     
    114113                RETVAL
    115114        CLEANUP:
    116                 g_free(rv);
     115                if (rv) g_free(rv);
    117116
    118117const utf8 *
     
    141140                RETVAL
    142141    CLEANUP:
    143                 g_free(rv);
     142                if (rv) g_free(rv);
    144143
    145144void
     
    324323                RETVAL
    325324        CLEANUP:
    326                 g_free(rv);
     325                if (rv)
     326                        g_free(rv);
    327327
    328328void
  • select.c

    rba12b44 rba12b44  
    321321}
    322322
    323 #if 0
    324 /* FIXME: Reimplement this check in the glib world. */
    325 static void owl_select_prune_bad_fds(void) {
    326   owl_list *dl = owl_global_get_io_dispatch_list(&g);
    327   int len, i;
    328   struct stat st;
    329   owl_io_dispatch *d;
    330 
    331   len = owl_list_get_size(dl);
    332   for (i = 0; i < len; i++) {
    333     d = owl_list_get_element(dl, i);
    334     if (fstat(d->fd, &st) < 0 && errno == EBADF) {
    335       owl_function_debugmsg("Pruning defunct dispatch on fd %d.", d->fd);
    336       d->needs_gc = 1;
    337     }
    338   }
    339   owl_select_io_dispatch_gc();
    340 }
    341 #endif
    342 
    343323typedef struct _owl_task { /*noproto*/
    344324  void (*cb)(void *);
  • tester.c

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

    r7865479 r42ee1be  
    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 */
     282void 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);
    277291}
    278292
  • util.c

    r9efa5bd re56303f  
    715715}
    716716
    717 int 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 
    728717gulong owl_dirty_window_on_signal(owl_window *w, gpointer sender, const gchar *detailed_signal)
    729718{
  • variable.c

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

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

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

    r4cc49bc r4cc49bc  
    547547  /* update the terminal if we need to */
    548548  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. */
     549  /* On colorpair shortage, reset and redraw /everything/. NOTE: if
     550   * the current screen uses too many colorpairs, this draws
     551   * everything twice. But this is unlikely; COLOR_PAIRS is 64 with
     552   * 8+1 colors, and 256^2 with 256+1 colors. (+1 for default.) */
    553553  cpmgr = owl_global_get_colorpair_mgr(&g);
    554554  if (cpmgr->overflow) {
    555     owl_function_debugmsg("colorpairs: used all %d pairs; reset pairs and redraw.",
    556                           owl_util_get_colorpairs());
     555    owl_function_debugmsg("colorpairs: color shortage; reset pairs and redraw. COLOR_PAIRS = %d", COLOR_PAIRS);
    557556    owl_fmtext_reset_colorpairs(cpmgr);
    558557    owl_function_full_redisplay();
  • zcrypt.c

    r3b8a563 r1dd285b  
    476476
    477477  for(i = 0; i < MAX_SEARCH; i++) {
    478     g_free(varname[i]);
    479   }
    480 
    481   g_free(filename);
     478    if(varname[i] != NULL) {
     479      g_free(varname[i]);
     480    }
     481  }
     482
     483  if(filename != NULL) {
     484    g_free(filename);
     485  }
    482486
    483487  return keyfile;
     
    769773  err = call_filter("gpg", argv, in, &out, &status);
    770774  if(err || status) {
    771     g_free(out);
     775    if(out) g_free(out);
    772776    return FALSE;
    773777  }
     
    852856  err = call_filter("gpg", argv, in, &out, &status);
    853857  if(err || status) {
    854     g_free(out);
     858    if(out) g_free(out);
    855859    return FALSE;
    856860  }
  • zephyr.c

    r959cb85 r959cb85  
    447447    return 0;
    448448  }
    449   g_free(buffer);
     449  if (buffer)
     450    g_free(buffer);
    450451
    451452  return owl_zephyr_loadsubs_helper(subs, count);
     
    10481049{
    10491050#ifdef HAVE_LIBZEPHYR
     1051  char *exposure, *eset;
     1052  Code_t ret;
     1053
    10501054  ZResetAuthentication();
    10511055
    1052   /* ZSetLocation, and store the default value as the current value */
    1053   owl_global_set_exposure(&g, owl_global_get_default_exposure(&g));
     1056  eset = EXPOSE_REALMVIS;
     1057  exposure = ZGetVariable(zstr("exposure"));
     1058  if (exposure)
     1059    exposure = ZParseExposureLevel(exposure);
     1060  if (exposure)
     1061    eset = exposure;
     1062   
     1063  ret = ZSetLocation(eset);
     1064  if (ret != ZERR_NONE)
     1065    owl_function_error("Error setting location: %s", error_message(ret));
    10541066#endif
    10551067}
     
    11721184  ZInitLocationInfo(zstr(host), zstr(val));
    11731185#endif
    1174 }
    1175 
    1176 const char *owl_zephyr_normalize_exposure(const char *exposure)
    1177 {
    1178   if (exposure == NULL)
    1179     return NULL;
    1180 #ifdef HAVE_LIBZEPHYR
    1181   return ZParseExposureLevel(zstr(exposure));
    1182 #else
    1183   return exposure;
    1184 #endif
    1185 }
    1186 
    1187 int owl_zephyr_set_default_exposure(const char *exposure)
    1188 {
    1189 #ifdef HAVE_LIBZEPHYR
    1190   Code_t ret;
    1191   if (exposure == NULL)
    1192     return -1;
    1193   exposure = ZParseExposureLevel(zstr(exposure));
    1194   if (exposure == NULL)
    1195     return -1;
    1196   ret = ZSetVariable(zstr("exposure"), zstr(exposure)); /* ZSetVariable does file I/O */
    1197   if (ret != ZERR_NONE) {
    1198     owl_function_error("Unable to set default exposure location: %s", error_message(ret));
    1199     return -1;
    1200   }
    1201 #endif
    1202   return 0;
    1203 }
    1204 
    1205 const char *owl_zephyr_get_default_exposure(void)
    1206 {
    1207 #ifdef HAVE_LIBZEPHYR
    1208   const char *exposure = ZGetVariable(zstr("exposure")); /* ZGetVariable does file I/O */
    1209   if (exposure == NULL)
    1210     return EXPOSE_REALMVIS;
    1211   exposure = ZParseExposureLevel(zstr(exposure));
    1212   if (exposure == NULL) /* The user manually entered an invalid value in ~/.zephyr.vars, or something weird happened. */
    1213     return EXPOSE_REALMVIS;
    1214   return exposure;
    1215 #else
    1216   return "";
    1217 #endif
    1218 }
    1219 
    1220 int owl_zephyr_set_exposure(const char *exposure)
    1221 {
    1222 #ifdef HAVE_LIBZEPHYR
    1223   Code_t ret;
    1224   if (exposure == NULL)
    1225     return -1;
    1226   exposure = ZParseExposureLevel(zstr(exposure));
    1227   if (exposure == NULL)
    1228     return -1;
    1229   ret = ZSetLocation(zstr(exposure));
    1230   if (ret != ZERR_NONE) {
    1231     owl_function_error("Unable to set exposure level: %s.", error_message(ret));
    1232     return -1;
    1233   }
    1234 #endif
    1235   return 0;
    12361186}
    12371187 
  • zwrite.c

    r3b8a563 r3f52e14  
    185185void owl_zwrite_set_message_raw(owl_zwrite *z, const char *msg)
    186186{
    187   g_free(z->message);
     187  if (z->message) g_free(z->message);
    188188  z->message = owl_validate_utf8(msg);
    189189}
     
    195195  char *tmp = NULL, *tmp2;
    196196
    197   g_free(z->message);
     197  if (z->message) 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   g_free(z->opcode);
     291  if (z->opcode) 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   g_free(z->zsig);
     308  if(z->zsig) g_free(z->zsig);
    309309  z->zsig = g_strdup(zsig);
    310310}
     
    353353{
    354354  owl_list_cleanup(&(z->recips), &g_free);
    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);
     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);
    363363}
    364364
Note: See TracChangeset for help on using the changeset viewer.