[965] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[D-O-H] r952 - in branches/barnowl_unicode: . owl owl/perl/lib/BarnOwl owl/perl/modules/IRC/lib/BarnOwl/Module owl/perl/modules/IRC/lib/BarnOwl/Module/IRC owl/perl/modules/Jabber/lib/BarnOwl/Module owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber

daemon@ATHENA.MIT.EDU (asedeno@MIT.EDU)
Thu Oct 29 18:11:38 2009

Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
X-Original-To: nelhage@nelhage.com
To: dirty-owl-hackers@mit.edu
From: asedeno@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU
Date: Mon, 18 Feb 2008 21:07:24 -0500 (EST)

Author: asedeno
Date: 2008-02-18 21:07:22 -0500 (Mon, 18 Feb 2008)
New Revision: 952

Added:
   branches/barnowl_unicode/owl/select.c
Modified:
   branches/barnowl_unicode/
   branches/barnowl_unicode/owl/Makefile.in
   branches/barnowl_unicode/owl/functions.c
   branches/barnowl_unicode/owl/global.c
   branches/barnowl_unicode/owl/keys.c
   branches/barnowl_unicode/owl/owl.c
   branches/barnowl_unicode/owl/owl.h
   branches/barnowl_unicode/owl/perl/lib/BarnOwl/ModuleLoader.pm
   branches/barnowl_unicode/owl/perl/modules/IRC/lib/BarnOwl/Module/IRC.pm
   branches/barnowl_unicode/owl/perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm
   branches/barnowl_unicode/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm
   branches/barnowl_unicode/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber/Connection.pm
   branches/barnowl_unicode/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber/ConnectionManager.pm
   branches/barnowl_unicode/owl/perlconfig.c
   branches/barnowl_unicode/owl/perlglue.xs
   branches/barnowl_unicode/owl/zephyr.c
Log:
Merged revisions 928-950 via svnmerge from 
file:///afs/sipb.mit.edu/project/barnowl/src/svn/trunk

........
  r937 | nelhage | 2008-02-11 23:09:54 -0500 (Mon, 11 Feb 2008) | 2 lines
  
  Bind M-left and M-right by default in the editor
........
  r947 | nelhage | 2008-02-18 16:45:22 -0500 (Mon, 18 Feb 2008) | 2 lines
  
  We need to stick modules on the beginning of @INC, not the end
........
  r949 | asedeno | 2008-02-18 19:43:09 -0500 (Mon, 18 Feb 2008) | 1 line
  
  Merging in the select branch.
........
  r950 | asedeno | 2008-02-18 20:54:45 -0500 (Mon, 18 Feb 2008) | 1 line
  
  Merging in the select branch, part 2. select.c
........



Property changes on: branches/barnowl_unicode
___________________________________________________________________
Name: svnmerge-integrated
   - /trunk:1-927
   + /trunk:1-950

Modified: branches/barnowl_unicode/owl/Makefile.in
===================================================================
--- branches/barnowl_unicode/owl/Makefile.in	2008-02-19 01:57:58 UTC (rev 951)
+++ branches/barnowl_unicode/owl/Makefile.in	2008-02-19 02:07:22 UTC (rev 952)
@@ -25,7 +25,8 @@
      regex.c history.c view.c dict.c variable.c filterelement.c pair.c \
      keypress.c keymap.c keybinding.c cmd.c context.c zcrypt.c \
      aim.c buddy.c buddylist.c timer.c style.c stylefunc.c errqueue.c \
-     zbuddylist.c muxevents.c popexec.c obarray.c wcwidth.c glib_compat.c
+     zbuddylist.c muxevents.c popexec.c obarray.c select.c wcwidth.c \
+     glib_compat.c
 OWL_SRC = owl.c
 TESTER_SRC = tester.c
 

Modified: branches/barnowl_unicode/owl/functions.c
===================================================================
--- branches/barnowl_unicode/owl/functions.c	2008-02-19 01:57:58 UTC (rev 951)
+++ branches/barnowl_unicode/owl/functions.c	2008-02-19 02:07:22 UTC (rev 952)
@@ -797,7 +797,7 @@
     owl_global_set_topmsg(&g, curmsg+1);
     owl_global_set_curmsg(&g, curmsg+1);
   } 
-  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
+  /* owl_mainwin_redisplay(owl_global_get_mainwin(&g)); */
   owl_global_set_direction_downwards(&g);
 }
 

Modified: branches/barnowl_unicode/owl/global.c
===================================================================
--- branches/barnowl_unicode/owl/global.c	2008-02-19 01:57:58 UTC (rev 951)
+++ branches/barnowl_unicode/owl/global.c	2008-02-19 02:07:22 UTC (rev 952)
@@ -116,6 +116,7 @@
   owl_obarray_init(&(g->obarray));
 
   owl_message_init_fmtext_cache();
+  owl_list_create(&(g->dispatchlist));
 }
 
 void _owl_global_setup_windows(owl_global *g) {
@@ -931,3 +932,8 @@
 {
   return owl_obarray_insert(&(g->obarray), string);
 }
+
+owl_list *owl_global_get_dispatchlist(owl_global *g)
+{
+  return &(g->dispatchlist);
+}

Modified: branches/barnowl_unicode/owl/keys.c
===================================================================
--- branches/barnowl_unicode/owl/keys.c	2008-02-19 01:57:58 UTC (rev 951)
+++ branches/barnowl_unicode/owl/keys.c	2008-02-19 02:07:22 UTC (rev 952)
@@ -43,8 +43,10 @@
 
   BIND_CMD("M-f",         "edit:move-next-word", "");
   BIND_CMD("M-O 3 C",     "edit:move-next-word", "");
+  BIND_CMD("M-LEFT",      "edit:move-next-word", "");
   BIND_CMD("M-b",         "edit:move-prev-word", "");
   BIND_CMD("M-O 3 D",     "edit:move-prev-word", "");
+  BIND_CMD("M-RIGHT",     "edit:move-prev-word", "");
 
   BIND_CMD("LEFT",        "edit:move-left", "");
   BIND_CMD("C-b",         "edit:move-left", "");

Modified: branches/barnowl_unicode/owl/owl.c
===================================================================
--- branches/barnowl_unicode/owl/owl.c	2008-02-19 01:57:58 UTC (rev 951)
+++ branches/barnowl_unicode/owl/owl.c	2008-02-19 02:07:22 UTC (rev 952)
@@ -45,6 +45,7 @@
 #include <time.h>
 #include <sys/param.h>
 #include <sys/types.h>
+#include <sys/time.h>
 #include <termios.h>
 #include <sys/stat.h>
 #include <locale.h>
@@ -60,6 +61,8 @@
 int stderr_replace(void);
 #endif
 
+#define STDIN 0
+
 static const char fileIdent[] = "$Id$";
 
 owl_global g;
@@ -70,7 +73,6 @@
   owl_editwin *tw;
   owl_popwin *pw;
   int ret, initialsubs, debug, argcsave, followlast;
-  owl_input j;
   int newmsgs, nexttimediff;
   struct sigaction sigact;
   char *configfile, *tty, *perlout, *perlerr, **argvsave, buff[LINE], startupmsg[LINE];
@@ -213,11 +215,27 @@
   owl_global_set_startupargs(&g, argcsave, argvsave);
   owl_global_set_haveaim(&g);
 
+  /* prepare stdin dispatch */
+  {
+    owl_dispatch *d = owl_malloc(sizeof(owl_dispatch));
+    d->fd = STDIN;
+    d->cfunc = &owl_process_input;
+    d->pfunc = NULL;
+    owl_select_add_dispatch(d);
+  }
+  
 #ifdef HAVE_LIBZEPHYR
   /* zephyr init */
   ret=owl_zephyr_initialize();
-  if (!ret)
-      owl_global_set_havezephyr(&g);
+  if (!ret) {
+    owl_dispatch *d = owl_malloc(sizeof(owl_dispatch));
+    d->fd = ZGetFD();
+    d->cfunc = &owl_zephyr_process_events;
+    d->pfunc = NULL;
+    owl_select_add_dispatch(d);
+    owl_global_set_havezephyr(&g);
+  }
+
 #endif
 
 #if OWL_STDERR_REDIR
@@ -432,18 +450,6 @@
 
     followlast=owl_global_should_followlast(&g);
     
-    /* Do AIM stuff */
-    if (owl_global_is_doaimevents(&g)) {
-      owl_aim_process_events();
-
-      if (owl_global_is_aimloggedin(&g)) {
-	if (owl_timer_is_expired(owl_global_get_aim_buddyinfo_timer(&g))) {
-	  /* owl_buddylist_request_idletimes(owl_global_get_buddylist(&g)); */
-	  owl_timer_reset(owl_global_get_aim_buddyinfo_timer(&g));
-	}
-      }
-    }
-
     owl_perlconfig_mainloop();
 
     /* little hack */
@@ -461,8 +467,6 @@
       }
     }
 
-    owl_zephyr_process_events();
-    
     /* Grab incoming messages. */
     newmsgs=0;
     while(owl_global_messagequeue_pending(&g)) {
@@ -534,88 +538,9 @@
       owl_global_set_noneedrefresh(&g);
     }
 
-    /* Handle all keypresses.  If no key has been pressed, sleep for a
-     * little bit, but otherwise do not.  This lets input be grabbed
-     * as quickly as possbile */
-    j.ch = wgetch(typwin);
-    if (j.ch == ERR) {
-      usleep(10000);
-    } else {
-      j.uch = '\0';
-      if (j.ch >= KEY_MIN && j.ch <= KEY_MAX) {
-	/* This is a curses control character. */
-      }
-      else if (j.ch > 0x7f && j.ch < 0xfe) {
-	/* Pull in a full utf-8 character. */
-	int bytes, i;
-	char utf8buf[7];
-	memset(utf8buf, '\0', 7);
+    /* select on FDs we know about. */
+    owl_select();
 
-	utf8buf[0] = j.ch;
-
-	if ((j.ch & 0xc0) && (~j.ch & 0x20)) bytes = 2;
-	else if ((j.ch & 0xe0) && (~j.ch & 0x10)) bytes = 3;
-	else if ((j.ch & 0xf0) && (~j.ch & 0x08)) bytes = 4;
-	else if ((j.ch & 0xf8) && (~j.ch & 0x04)) bytes = 5;
-	else if ((j.ch & 0xfc) && (~j.ch & 0x02)) bytes = 6;
-	else bytes = 1;
-	
-	for (i = 1; i < bytes; i++) {
-          int tmp =  wgetch(typwin);
-          /* If what we got was not a byte, or not a continuation byte */
-          if (tmp > 0xff || !(tmp & 0x80 && ~tmp & 0x40)) {
-            /* ill-formed UTF-8 code unit subsequence, put back the
-               char we just got. */
-            ungetch(tmp);
-            j.ch = ERR;
-            break;
-          }
-	  utf8buf[i] = tmp;
-        }
-        
-	if (j.ch != ERR) {
-          if (g_utf8_validate(utf8buf, -1, NULL)) {
-            j.uch = g_utf8_get_char(utf8buf);
-          }
-          else {
-            j.ch = ERR;
-          }
-        }
-      }
-      else if (j.ch <= 0x7f) {
-	j.uch = j.ch;
-      }
-      
-      owl_global_set_lastinputtime(&g, now);
-      /* find and activate the current keymap.
-       * TODO: this should really get fixed by activating
-       * keymaps as we switch between windows... 
-       */
-      if (pw && owl_popwin_is_active(pw) && owl_global_get_viewwin(&g)) {
-	owl_context_set_popless(owl_global_get_context(&g), 
-				owl_global_get_viewwin(&g));
-	owl_function_activate_keymap("popless");
-      } else if (owl_global_is_typwin_active(&g) 
-		 && owl_editwin_get_style(tw)==OWL_EDITWIN_STYLE_ONELINE) {
-	/*
-	  owl_context_set_editline(owl_global_get_context(&g), tw);
-	  owl_function_activate_keymap("editline");
-	*/
-      } else if (owl_global_is_typwin_active(&g) 
-		 && owl_editwin_get_style(tw)==OWL_EDITWIN_STYLE_MULTILINE) {
-	owl_context_set_editmulti(owl_global_get_context(&g), tw);
-	owl_function_activate_keymap("editmulti");
-      } else {
-	owl_context_set_recv(owl_global_get_context(&g));
-	owl_function_activate_keymap("recv");
-      }
-      /* now actually handle the keypress */
-      ret = owl_keyhandler_process(owl_global_get_keyhandler(&g), j);
-      if (ret!=0 && ret!=1) {
-	owl_function_makemsg("Unable to handle keypress");
-      }
-    }
-
     /* Log any error signals */
     {
       siginfo_t si;
@@ -732,6 +657,111 @@
   return 1;
 }
 
+void owl_process_aim()
+{
+  if (owl_global_is_doaimevents(&g)) {
+    owl_aim_process_events();
+    
+    if (owl_global_is_aimloggedin(&g)) {
+      if (owl_timer_is_expired(owl_global_get_aim_buddyinfo_timer(&g))) {
+        /* owl_buddylist_request_idletimes(owl_global_get_buddylist(&g)); */
+        owl_timer_reset(owl_global_get_aim_buddyinfo_timer(&g));
+      }
+    }
+  }
+}
+
+void owl_process_input()
+{
+  int ret;
+  owl_input j;
+  owl_popwin *pw;
+  owl_editwin *tw;
+  WINDOW *typwin;
+
+  typwin = owl_global_get_curs_typwin(&g);
+  j.ch = wgetch(typwin);
+  if (j.ch == ERR) return;
+
+  owl_global_set_lastinputtime(&g, time(NULL));
+  pw=owl_global_get_popwin(&g);
+  tw=owl_global_get_typwin(&g);
+
+  j.uch = '\0';
+  if (j.ch >= KEY_MIN && j.ch <= KEY_MAX) {
+    /* This is a curses control character. */
+  }
+  else if (j.ch > 0x7f && j.ch < 0xfe) {
+    /* Pull in a full utf-8 character. */
+    int bytes, i;
+    char utf8buf[7];
+    memset(utf8buf, '\0', 7);
+
+    utf8buf[0] = j.ch;
+
+    if ((j.ch & 0xc0) && (~j.ch & 0x20)) bytes = 2;
+    else if ((j.ch & 0xe0) && (~j.ch & 0x10)) bytes = 3;
+    else if ((j.ch & 0xf0) && (~j.ch & 0x08)) bytes = 4;
+    else if ((j.ch & 0xf8) && (~j.ch & 0x04)) bytes = 5;
+    else if ((j.ch & 0xfc) && (~j.ch & 0x02)) bytes = 6;
+    else bytes = 1;
+
+    for (i = 1; i < bytes; i++) {
+      int tmp =  wgetch(typwin);
+      /* If what we got was not a byte, or not a continuation byte */
+      if (tmp > 0xff || !(tmp & 0x80 && ~tmp & 0x40)) {
+        /* ill-formed UTF-8 code unit subsequence, put back the
+           char we just got. */
+        ungetch(tmp);
+        j.ch = ERR;
+        break;
+      }
+      utf8buf[i] = tmp;
+    }
+    
+    if (j.ch != ERR) {
+      if (g_utf8_validate(utf8buf, -1, NULL)) {
+        j.uch = g_utf8_get_char(utf8buf);
+      }
+      else {
+        j.ch = ERR;
+      }
+    }
+  }
+  else if (j.ch <= 0x7f) {
+    j.uch = j.ch;
+  }
+      
+  owl_global_set_lastinputtime(&g, time(NULL));
+  /* find and activate the current keymap.
+   * TODO: this should really get fixed by activating
+   * keymaps as we switch between windows... 
+   */
+  if (pw && owl_popwin_is_active(pw) && owl_global_get_viewwin(&g)) {
+    owl_context_set_popless(owl_global_get_context(&g), 
+                            owl_global_get_viewwin(&g));
+    owl_function_activate_keymap("popless");
+  } else if (owl_global_is_typwin_active(&g) 
+             && owl_editwin_get_style(tw)==OWL_EDITWIN_STYLE_ONELINE) {
+    /*
+      owl_context_set_editline(owl_global_get_context(&g), tw);
+      owl_function_activate_keymap("editline");
+    */
+  } else if (owl_global_is_typwin_active(&g) 
+             && owl_editwin_get_style(tw)==OWL_EDITWIN_STYLE_MULTILINE) {
+    owl_context_set_editmulti(owl_global_get_context(&g), tw);
+    owl_function_activate_keymap("editmulti");
+  } else {
+    owl_context_set_recv(owl_global_get_context(&g));
+    owl_function_activate_keymap("recv");
+  }
+  /* now actually handle the keypress */
+  ret = owl_keyhandler_process(owl_global_get_keyhandler(&g), j);
+  if (ret!=0 && ret!=1) {
+    owl_function_makemsg("Unable to handle keypress");
+  }
+}
+
 void sig_handler(int sig, siginfo_t *si, void *data)
 {
   if (sig==SIGWINCH) {
@@ -746,7 +776,6 @@
   } else if (sig==SIGTERM || sig==SIGHUP) {
     owl_function_quit();
   }
-
 }
 
 void usage()

Modified: branches/barnowl_unicode/owl/owl.h
===================================================================
--- branches/barnowl_unicode/owl/owl.h	2008-02-19 01:57:58 UTC (rev 951)
+++ branches/barnowl_unicode/owl/owl.h	2008-02-19 02:07:22 UTC (rev 952)
@@ -561,6 +561,12 @@
   owl_list strings;
 } owl_obarray;
 
+typedef struct _owl_dispatch {
+  int fd;           /* FD to watch for dispatch. */
+  void (*cfunc)();  /* C function to dispatch to. */
+  SV *pfunc;        /* Perl function to dispatch to. */
+} owl_dispatch;
+
 typedef struct _owl_global {
   owl_mainwin mw;
   owl_popwin pw;
@@ -631,6 +637,7 @@
   owl_timer zephyr_buddycheck_timer;
   struct termios startup_tio;
   owl_obarray obarray;
+  owl_list dispatchlist;
 } owl_global;
 
 /* globals */

Modified: branches/barnowl_unicode/owl/perl/lib/BarnOwl/ModuleLoader.pm
===================================================================
--- branches/barnowl_unicode/owl/perl/lib/BarnOwl/ModuleLoader.pm	2008-02-19 01:57:58 UTC (rev 951)
+++ branches/barnowl_unicode/owl/perl/lib/BarnOwl/ModuleLoader.pm	2008-02-19 02:07:22 UTC (rev 952)
@@ -23,7 +23,7 @@
             if(-f "$dir/$f" && $f =~ /^(.+)\.par$/) {
                 $modules{$1} = 1;
             } elsif(-d "$dir/$f" && -d "$dir/$f/lib") {
-                push @INC, "$dir/$f/lib" unless grep m{^$dir/$f/lib$}, @INC;
+                unshift @INC, "$dir/$f/lib" unless grep m{^$dir/$f/lib$}, @INC;
                 $modules{$f} = 1;
             }
         }

Modified: branches/barnowl_unicode/owl/perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm
===================================================================
--- branches/barnowl_unicode/owl/perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm	2008-02-19 01:57:58 UTC (rev 951)
+++ branches/barnowl_unicode/owl/perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm	2008-02-19 02:07:22 UTC (rev 952)
@@ -68,6 +68,12 @@
     return $self;
 }
 
+sub getSocket
+{
+    my $self = shift;
+    return $self->conn->socket;
+}
+
 ################################################################################
 ############################### IRC callbacks ##################################
 ################################################################################
@@ -167,7 +173,7 @@
 sub on_disconnect {
     my $self = shift;
     delete $BarnOwl::Module::IRC::ircnets{$self->alias};
-
+    BarnOwl::remove_dispatch($self->{FD});
     BarnOwl::admin_message('IRC',
                            "[" . $self->alias . "] Disconnected from server");
 }

Modified: branches/barnowl_unicode/owl/perl/modules/IRC/lib/BarnOwl/Module/IRC.pm
===================================================================
--- branches/barnowl_unicode/owl/perl/modules/IRC/lib/BarnOwl/Module/IRC.pm	2008-02-19 01:57:58 UTC (rev 951)
+++ branches/barnowl_unicode/owl/perl/modules/IRC/lib/BarnOwl/Module/IRC.pm	2008-02-19 02:07:22 UTC (rev 952)
@@ -68,7 +68,15 @@
     }
 }
 
-sub mainloop_hook {
+#sub mainloop_hook {
+#    return unless defined $irc;
+#    eval {
+#        $irc->do_one_loop();
+#    };
+#    return;
+#}
+
+sub OwlProcess {
     return unless defined $irc;
     eval {
         $irc->do_one_loop();
@@ -76,6 +84,7 @@
     return;
 }
 
+
 sub register_handlers {
     if(!$irc) {
         $irc = Net::IRC->new;
@@ -108,7 +117,7 @@
 
 $BarnOwl::Hooks::startup->add(\&startup);
 $BarnOwl::Hooks::shutdown->add(\&shutdown);
-$BarnOwl::Hooks::mainLoop->add(\&mainloop_hook);
+#$BarnOwl::Hooks::mainLoop->add(\&mainloop_hook);
 
 ################################################################################
 ######################## Owl command handlers ##################################
@@ -164,6 +173,9 @@
     if ($conn->conn->connected) {
         BarnOwl::admin_message("IRC", "Connected to $alias as $nick");
         $ircnets{$alias} = $conn;
+        my $fd = $conn->getSocket()->fileno();
+        BarnOwl::add_dispatch($fd, \&OwlProcess);
+        $conn->{FD} = $fd;
     } else {
         die("IRC::Connection->connect failed: $!");
     }

Modified: branches/barnowl_unicode/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber/Connection.pm
===================================================================
--- branches/barnowl_unicode/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber/Connection.pm	2008-02-19 01:57:58 UTC (rev 951)
+++ branches/barnowl_unicode/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber/Connection.pm	2008-02-19 02:07:22 UTC (rev 952)
@@ -110,6 +110,45 @@
 }
 
 
+=head2 getSID
+
+Returns the StreamID for this connection.
+
+=cut
+
+sub getStreamID {
+    my $self = shift;
+    return $self->{SESSION}->{id} || "";
+}
+
+=head2 getSocket
+
+Returns the IO::Socket for this connection.
+
+=cut
+
+sub getSocket {
+    my $self = shift;
+    my $sid = getStreamID($self);
+    return $self->{STREAM}->GetSock($sid) || -1;
+}
+
+=head2 OwlProcess
+
+Non-blocking connection processing. For use in a select loop.
+
+=cut
+
+sub OwlProcess {
+    my $self = shift;
+    my $status = $self->Process(0);
+    if ( !defined($status) ) {
+        my $jid = $self->{SESSION}->{FULLJID};
+        BarnOwl::error("Jabber account $jid disconnected!");
+        BarnOwl::Module::Jabber::do_logout($jid);
+    }
+}
+
 =head1 SEE ALSO
 
 L<Net::Jabber::Client>, L<BarnOwl::Module::Jabber>

Modified: branches/barnowl_unicode/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber/ConnectionManager.pm
===================================================================
--- branches/barnowl_unicode/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber/ConnectionManager.pm	2008-02-19 01:57:58 UTC (rev 951)
+++ branches/barnowl_unicode/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber/ConnectionManager.pm	2008-02-19 02:07:22 UTC (rev 952)
@@ -36,6 +36,7 @@
     my $jidStr = shift;
     return 0 unless exists $self->{$jidStr};
 
+    BarnOwl::remove_dispatch($self->{$jidStr}->{Client}->{fileno}) if $self->{$jidStr}->{Client}->{fileno};
     $self->{$jidStr}->{Client}->Disconnect()
       if $self->{$jidStr}->{Client};
     delete $self->{$jidStr};
@@ -50,7 +51,7 @@
     return 0 unless exists $self->{$oldJidStr};
     return 0 if $oldJidStr eq $newJidStr;
 
-    $self->{$newJidStr} = $self->{$oldJidStr}; 
+    $self->{$newJidStr} = $self->{$oldJidStr};
     delete $self->{$oldJidStr};
     return 1;
 }

Modified: branches/barnowl_unicode/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm
===================================================================
--- branches/barnowl_unicode/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm	2008-02-19 01:57:58 UTC (rev 951)
+++ branches/barnowl_unicode/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm	2008-02-19 02:07:22 UTC (rev 952)
@@ -117,7 +117,7 @@
             $conn->removeConnection($jid);
             BarnOwl::error("Connection for $jid undefined -- error in reload?");
         }
-
+        # We keep this in the mainloop hook for keep-alives
         my $status = $client->Process(0);
         if ( !defined($status) ) {
             BarnOwl::error("Jabber account $jid disconnected!");
@@ -125,8 +125,9 @@
         }
         if ($::shutdown) {
             do_logout($jid);
-            return;
+            next;
         }
+
         if ($vars{status_changed}) {
             my $p = new Net::Jabber::Presence;
             $p->SetShow($vars{show}) if $vars{show};
@@ -388,6 +389,11 @@
 		my $fullJid = $client->{SESSION}->{FULLJID} || $jidStr;
 		$conn->renameConnection($jidStr, $fullJid);
                 queue_admin_msg("Connected to jabber as $fullJid");
+                # The remove_dispatch() method is called from the
+                # ConnectionManager's removeConnection() method.
+                $client->{fileno} = $client->getSocket()->fileno();
+                #queue_admin_msg("Connected to jabber as $fullJid ($client->{fileno})");
+                BarnOwl::add_dispatch($client->{fileno}, sub { $client->OwlProcess() });
             }
         }
     }

Modified: branches/barnowl_unicode/owl/perlconfig.c
===================================================================
--- branches/barnowl_unicode/owl/perlconfig.c	2008-02-19 01:57:58 UTC (rev 951)
+++ branches/barnowl_unicode/owl/perlconfig.c	2008-02-19 02:07:22 UTC (rev 952)
@@ -486,6 +486,11 @@
   SvREFCNT_dec(cmd->cmd_perl);
 }
 
+void owl_perlconfig_dispatch_free(owl_dispatch *d)
+{
+  SvREFCNT_dec(d->pfunc);
+}
+
 void owl_perlconfig_edit_callback(owl_editwin *e)
 {
   SV *cb = (SV*)(e->cbdata);
@@ -532,3 +537,28 @@
   }
   return;
 }
+
+void owl_perlconfig_do_dispatch(owl_dispatch *d)
+{
+  SV *cb = d->pfunc;
+  unsigned int n_a;
+  dSP;
+  if(cb == NULL) {
+    owl_function_error("Perl callback is NULL!");
+  }
+
+  ENTER;
+  SAVETMPS;
+
+  PUSHMARK(SP);
+  PUTBACK;
+  
+  call_sv(cb, G_DISCARD|G_KEEPERR|G_EVAL);
+
+  if(SvTRUE(ERRSV)) {
+    owl_function_error("%s", SvPV(ERRSV, n_a));
+  }
+
+  FREETMPS;
+  LEAVE;
+}

Modified: branches/barnowl_unicode/owl/perlglue.xs
===================================================================
--- branches/barnowl_unicode/owl/perlglue.xs	2008-02-19 01:57:58 UTC (rev 951)
+++ branches/barnowl_unicode/owl/perlglue.xs	2008-02-19 02:07:22 UTC (rev 952)
@@ -341,3 +341,17 @@
 				      summ,
 				      desc,
 				      ival);
+
+void
+add_dispatch(fd, cb)
+	int fd
+	SV * cb
+	CODE:
+        SvREFCNT_inc(cb);
+	owl_select_add_perl_dispatch(fd, cb);
+
+void
+remove_dispatch(fd)
+	int fd
+	CODE:
+	owl_select_remove_perl_dispatch(fd);

Copied: branches/barnowl_unicode/owl/select.c (from rev 950, trunk/owl/select.c)
===================================================================
--- branches/barnowl_unicode/owl/select.c	                        (rev 0)
+++ branches/barnowl_unicode/owl/select.c	2008-02-19 02:07:22 UTC (rev 952)
@@ -0,0 +1,242 @@
+#include "owl.h"
+
+static const char fileIdent[] = "$Id: select.c 894 2008-01-17 07:13:44Z asedeno $";
+
+/* Returns the index of the dispatch for the file descriptor. */
+int owl_select_find_dispatch(int fd)
+{
+  int i, len;
+  owl_list *dl;
+  owl_dispatch *d;
+  
+  dl = owl_global_get_dispatchlist(&g);
+  len = owl_list_get_size(dl);
+  for(i = 0; i < len; i++) {
+    d = (owl_dispatch*)owl_list_get_element(dl, i);
+    if (d->fd == fd) return i;
+  }
+  return -1;
+}
+
+/* Adds a new owl_dispatch to the list, replacing existing ones if needed. */
+void owl_select_add_dispatch(owl_dispatch *d)
+{
+  int elt;
+  owl_list *dl;
+
+  elt = owl_select_find_dispatch(d->fd);
+  dl = owl_global_get_dispatchlist(&g);
+  
+  if (elt != -1) {  /* If we have a dispatch for this FD */
+    owl_dispatch *d_old;
+    d_old = (owl_dispatch*)owl_list_get_element(dl, elt);
+    /* Ignore if we're adding the same dispatch again.  Otherwise
+       replace the old dispatch. */
+    if (d_old != d) {
+      owl_list_replace_element(dl, elt, d);
+      owl_free(d_old);
+    }
+  }
+  else {
+    owl_list_append_element(dl, d);
+  }
+}
+
+/* Removes an owl_dispatch to the list, based on it's file descriptor. */
+void owl_select_remove_dispatch(int fd)
+{
+  int elt;
+  owl_list *dl;
+
+  elt = owl_select_find_dispatch(fd);
+  dl = owl_global_get_dispatchlist(&g);
+  
+  if (elt != -1) {
+    owl_dispatch *d;
+    d = (owl_dispatch*)owl_list_get_element(dl, elt);
+    owl_list_remove_element(dl, elt);
+    if (d->pfunc) {
+      owl_perlconfig_dispatch_free(d);
+    }
+    owl_free(d);
+  }
+}
+
+int owl_select_dispatch_count()
+{
+  return owl_list_get_size(owl_global_get_dispatchlist(&g));
+}
+
+int owl_select_add_perl_dispatch(int fd, SV *cb)
+{
+  int elt;
+  owl_dispatch *d;
+  elt = owl_select_find_dispatch(fd);
+  if (elt != -1) {
+    d = (owl_dispatch*)owl_list_get_element(owl_global_get_dispatchlist(&g), elt);
+    if (d->pfunc == NULL) {
+      /* don't mess with non-perl dispatch functions from here. */
+      return 1;
+    }
+  }
+
+  d = malloc(sizeof(owl_dispatch));
+  d->fd = fd;
+  d->cfunc = NULL;
+  d->pfunc = cb;
+  owl_select_add_dispatch(d);
+  return 0;
+}
+
+int owl_select_remove_perl_dispatch(int fd)
+{
+  int elt;
+  owl_dispatch *d;
+  
+  elt = owl_select_find_dispatch(fd);
+  if (elt != -1) {
+    d = (owl_dispatch*)owl_list_get_element(owl_global_get_dispatchlist(&g), elt);
+    if (d->pfunc != NULL) {
+      owl_select_remove_dispatch(fd);
+      return 0;
+    }
+  }
+  return 1;
+}
+
+int owl_select_dispatch_prepare_fd_sets(fd_set *r, fd_set *w, fd_set *e)
+{
+  int i, len, max_fd;
+  owl_dispatch *d;
+  owl_list *dl;
+
+  dl = owl_global_get_dispatchlist(&g);
+  FD_ZERO(r);
+  FD_ZERO(e);
+  max_fd = 0;
+  len = owl_select_dispatch_count(g);
+  for(i = 0; i < len; i++) {
+    d = (owl_dispatch*)owl_list_get_element(dl, i);
+    FD_SET(d->fd, r);
+    FD_SET(d->fd, w);
+    FD_SET(d->fd, e);
+    if (max_fd < d->fd) max_fd = d->fd;
+  }
+  return max_fd + 1;
+}
+
+void owl_select_dispatch(fd_set *fds, int max_fd)
+{
+  int i, len;
+  owl_dispatch *d;
+  owl_list *dl;
+
+  dl = owl_global_get_dispatchlist(&g);
+  len = owl_select_dispatch_count();
+  for(i = 0; i < len; i++) {
+    d = (owl_dispatch*)owl_list_get_element(dl, i);
+    /* While d shouldn't normally be null, the list may be altered by
+     * functions we dispatch to. */
+    if (d != NULL && FD_ISSET(d->fd, fds)) {
+      if (d->cfunc != NULL) {
+        (d->cfunc)();
+      }
+      else if (d->pfunc != NULL) {
+        owl_perlconfig_do_dispatch(d);
+      }
+    }
+  }
+}
+
+int owl_select_aim_hack(fd_set *fds)
+{
+  aim_conn_t *cur;
+  aim_session_t *sess;
+  int max_fd;
+
+  FD_ZERO(fds);
+  max_fd = 0;
+  sess = owl_global_get_aimsess(&g);
+  for (cur = sess->connlist, max_fd = 0; cur; cur = cur->next) {
+    if (cur->fd != -1) {
+      FD_SET(cur->fd, fds);
+      if (cur->fd > max_fd)
+        max_fd = cur->fd;
+    }
+  }
+  cur = owl_global_get_bosconn(&g);
+  if (cur->fd != -1) {
+    FD_SET(cur->fd, fds);
+    if (cur->fd > max_fd)
+      max_fd = cur->fd;
+  }
+  
+  return max_fd;
+}
+
+void owl_select()
+{
+  int i, max_fd, aim_max_fd, aim_done;
+  fd_set r;
+  fd_set w;
+  fd_set e;
+  fd_set aim_fds;
+  struct timeval timeout;
+
+  timeout.tv_sec = 1;
+  timeout.tv_usec = 0;
+
+  max_fd = owl_select_dispatch_prepare_fd_sets(&r, &w, &e);
+
+  /* AIM HACK: 
+   *
+   *  The problem - I'm not sure where to hook into the owl/faim
+   *  interface to keep track of when the AIM socket(s) open and
+   *  close. In particular, the bosconn thing throws me off. So,
+   *  rather than register particular dispatchers for AIM, I look up
+   *  the relevant FDs and add them to select's watch lists, then
+   *  check for them individually before moving on to the other
+   *  dispatchers. --asedeno
+   */
+  aim_done = 1;
+  FD_ZERO(&aim_fds);
+  FD_ZERO(&w);
+  if (owl_global_is_doaimevents(&g)) {
+    aim_done = 0;
+    aim_max_fd = owl_select_aim_hack(&aim_fds);
+    if (max_fd < aim_max_fd) max_fd = aim_max_fd;
+    for(i = 0; i <= aim_max_fd; i++) {
+      if (FD_ISSET(i, &aim_fds)) {
+        FD_SET(i, &r);
+        FD_SET(i, &w); /* Yes, we're checking writable sockets
+                          here. Without it, AIM login is really
+                          slow. */
+        FD_SET(i, &e);
+      }
+    }
+  }
+  /* END AIM HACK */
+  
+  if ( select(max_fd, &r, &w, &e, &timeout) ) {
+    /* Merge fd_sets and clear AIM FDs. */
+    for(i = 0; i <= max_fd; i++) {
+      /* Merge all interesting FDs into one set, since we have a
+         single dispatch per FD. */
+      if (FD_ISSET(i, &r) || FD_ISSET(i, &w) || FD_ISSET(i, &e)) {
+        /* AIM HACK: no separate dispatch, just process here if
+           needed, and only once per run through. */
+        if (!aim_done && FD_ISSET(i, &aim_fds)) {
+          owl_process_aim();
+          aim_done = 1;
+        }
+        else {
+          FD_SET(i, &r);
+        }
+      }
+    }
+
+    /* NOTE: the same dispatch function is called for both exceptional
+       and read ready FDs. */
+    owl_select_dispatch(&r, max_fd);
+  }
+}

Modified: branches/barnowl_unicode/owl/zephyr.c
===================================================================
--- branches/barnowl_unicode/owl/zephyr.c	2008-02-19 01:57:58 UTC (rev 951)
+++ branches/barnowl_unicode/owl/zephyr.c	2008-02-19 02:07:22 UTC (rev 952)
@@ -29,7 +29,6 @@
   return(0);
 }
 
-
 int owl_zephyr_shutdown()
 {
 #ifdef HAVE_LIBZEPHYR


home help back first fref pref prev next nref lref last post