[572] in BarnOwl Developers

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

[D-O-H] r689 - in trunk/owl: . perl/lib perl/lib/BarnOwl perl/lib/Module perl/lib/Module/Install perl/modules perl/modules/Jabber perl/modules/Jabber/inc perl/modules/Jabber/inc/Module perl/modules/Jabber/inc/Module/Install perl/modules/Jabber/lib perl/modules/Jabber/lib/BarnOwl perl/modules/Jabber/lib/BarnOwl/Message perl/modules/Jabber/lib/BarnOwl/Module perl/modules/Jabber/lib/BarnOwl

daemon@ATHENA.MIT.EDU (nelhage@MIT.EDU)
Thu Oct 29 18:07:33 2009

Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
To: dirty-owl-hackers@mit.edu
From: nelhage@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU
Date: Wed, 28 Mar 2007 21:32:17 -0400 (EDT)

Author: nelhage
Date: 2007-03-28 21:32:11 -0400 (Wed, 28 Mar 2007)
New Revision: 689

Added:
   trunk/owl/perl/lib/BarnOwl/
   trunk/owl/perl/lib/BarnOwl/ModuleLoader.pm
   trunk/owl/perl/lib/Module/
   trunk/owl/perl/lib/Module/Install/
   trunk/owl/perl/lib/Module/Install/BarnOwl.pm
   trunk/owl/perl/modules/Jabber/
   trunk/owl/perl/modules/Jabber/Makefile.PL
   trunk/owl/perl/modules/Jabber/inc/
   trunk/owl/perl/modules/Jabber/inc/Module/
   trunk/owl/perl/modules/Jabber/inc/Module/Install.pm
   trunk/owl/perl/modules/Jabber/inc/Module/Install/
   trunk/owl/perl/modules/Jabber/inc/Module/Install/BarnOwl.pm
   trunk/owl/perl/modules/Jabber/inc/Module/Install/Base.pm
   trunk/owl/perl/modules/Jabber/inc/Module/Install/Can.pm
   trunk/owl/perl/modules/Jabber/inc/Module/Install/Fetch.pm
   trunk/owl/perl/modules/Jabber/inc/Module/Install/Makefile.pm
   trunk/owl/perl/modules/Jabber/inc/Module/Install/Metadata.pm
   trunk/owl/perl/modules/Jabber/inc/Module/Install/Win32.pm
   trunk/owl/perl/modules/Jabber/inc/Module/Install/WriteAll.pm
   trunk/owl/perl/modules/Jabber/lib/
   trunk/owl/perl/modules/Jabber/lib/BarnOwl/
   trunk/owl/perl/modules/Jabber/lib/BarnOwl/Message/
   trunk/owl/perl/modules/Jabber/lib/BarnOwl/Message/Jabber.pm
   trunk/owl/perl/modules/Jabber/lib/BarnOwl/Module/
   trunk/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm
   trunk/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber/
   trunk/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber/Connection.pm
   trunk/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber/ConnectionManager.pm
   trunk/owl/perl/modules/Jabber/lib/Net/
   trunk/owl/perl/modules/Jabber/lib/XML/
Removed:
   trunk/owl/perl/lib/Net/
   trunk/owl/perl/lib/XML/
   trunk/owl/perl/modules/jabber.pl
Modified:
   trunk/owl/
   trunk/owl/BUGS
   trunk/owl/Makefile.in
   trunk/owl/fmtext.c
   trunk/owl/functions.c
   trunk/owl/global.c
   trunk/owl/message.c
   trunk/owl/owl.c
   trunk/owl/owl.h
   trunk/owl/perl/modules/Jabber/lib/Net/Jabber.pm
   trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Component.pm
   trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Data.pm
   trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Dialback.pm
   trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Dialback/Result.pm
   trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Dialback/Verify.pm
   trunk/owl/perl/modules/Jabber/lib/Net/Jabber/IQ.pm
   trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Key.pm
   trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Log.pm
   trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Message.pm
   trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Presence.pm
   trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Protocol.pm
   trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Server.pm
   trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Stanza.pm
   trunk/owl/perl/modules/Jabber/lib/Net/Jabber/XDB.pm
   trunk/owl/perl/modules/Jabber/lib/Net/XMPP.pm
   trunk/owl/perl/modules/Jabber/lib/Net/XMPP/Client.pm
   trunk/owl/perl/modules/Jabber/lib/Net/XMPP/Connection.pm
   trunk/owl/perl/modules/Jabber/lib/Net/XMPP/Debug.pm
   trunk/owl/perl/modules/Jabber/lib/Net/XMPP/IQ.pm
   trunk/owl/perl/modules/Jabber/lib/Net/XMPP/JID.pm
   trunk/owl/perl/modules/Jabber/lib/Net/XMPP/Message.pm
   trunk/owl/perl/modules/Jabber/lib/Net/XMPP/Presence.pm
   trunk/owl/perl/modules/Jabber/lib/Net/XMPP/Protocol.pm
   trunk/owl/perl/modules/Jabber/lib/Net/XMPP/Roster.pm
   trunk/owl/perl/modules/Jabber/lib/Net/XMPP/Stanza.pm
   trunk/owl/perl/modules/Jabber/lib/XML/Stream.pm
   trunk/owl/perlconfig.c
   trunk/owl/perlwrap.pm
Log:
Merging the PAR branch back to trunk.

r20272@phanatique (orig r665):  nelhage | 2007-03-14 19:25:05 -0400
 Branching for the PAR module rewrite.
 r20274@phanatique (orig r667):  nelhage | 2007-03-16 00:45:19 -0400
 First phase of the module rewrite. Internals now (IMO) somewhat
 cleaner.
 
  r19586@phanatique:  nelhage | 2007-03-14 20:35:39 -0400
  First pass at a cleaned up perlwrap.pm
  
  * Using a new hook style
  * Modules loaded by BarnOwl::ModuleLoader (not yet written)
  
  reload is unimplemented for now. If possible, I'd like it to live
  elsewhere.
  
  r19587@phanatique:  nelhage | 2007-03-14 20:36:58 -0400
  Switching to the new underscore internal hook names.
  r19592@phanatique:  nelhage | 2007-03-16 00:34:00 -0400
  Actually switch to _receive_msg
  
  r19593@phanatique:  nelhage | 2007-03-16 00:34:27 -0400
  Some minor cleanup of perlwrap.pm. Shoving fake entries into @INC.
  
  r19594@phanatique:  nelhage | 2007-03-16 00:34:47 -0400
  First revision of ModuleLoader.
  
 
 r20281@phanatique (orig r669):  nelhage | 2007-03-17 14:48:02 -0400
  r20279@phanatique:  nelhage | 2007-03-17 14:46:56 -0400
  For reasons I don't claim to understand, using the old-style new was
  throwing odd errors about undefined functions.
  
 
 r20286@phanatique (orig r670):  nelhage | 2007-03-18 16:28:23 -0400
  r20282@phanatique:  nelhage | 2007-03-17 14:48:22 -0400
  Report more errors when something goes wrong
  
 
 r20287@phanatique (orig r671):  nelhage | 2007-03-18 16:28:31 -0400
  r20285@phanatique:  nelhage | 2007-03-18 16:28:18 -0400
  Adding the new M::Iified jabber module. There isn't a target to build
  the PAR yet.
 
 r20291@phanatique (orig r672):  nelhage | 2007-03-18 19:14:04 -0400
  r20290@phanatique:  nelhage | 2007-03-18 19:13:57 -0400
  Adding a Module::Install plugin for building barnowl plugins. It needs
  a lot of improvement.
 
 r20309@phanatique (orig r673):  nelhage | 2007-03-19 14:14:23 -0400
  r20301@phanatique:  nelhage | 2007-03-19 13:31:07 -0400
  Changing the dependency on the par target, so we don't rebuild unless
  we need to.
 
 r20310@phanatique (orig r674):  nelhage | 2007-03-19 14:14:33 -0400
  r20303@phanatique:  nelhage | 2007-03-19 13:32:25 -0400
  Modifying the makefile to build and install perl modules
 
 r20643@phanatique (orig r677):  nelhage | 2007-03-23 15:09:45 -0400
  r20640@phanatique:  nelhage | 2007-03-23 15:09:38 -0400
  Implement loading of unpacked modules, and module reloading.
 
 r20645@phanatique (orig r678):  nelhage | 2007-03-23 15:11:05 -0400
  r20644@phanatique:  nelhage | 2007-03-23 15:10:57 -0400
  Tighten up the reloaded regex a little.
  
 
 r20649@phanatique (orig r679):  nelhage | 2007-03-23 16:18:44 -0400
  r20648@phanatique:  nelhage | 2007-03-23 16:18:25 -0400
  Correctly install modules on a clean install.
  
 
 r20655@phanatique (orig r680):  nelhage | 2007-03-25 12:53:07 -0400
  r20650@phanatique:  nelhage | 2007-03-23 17:01:20 -0400
  Still not sure why old-style new seems to be eiting us so much...
  
 
 r20656@phanatique (orig r681):  nelhage | 2007-03-25 12:53:11 -0400
  r20653@phanatique:  nelhage | 2007-03-25 12:52:38 -0400
  Let's not segfault if the user asks for a nonexistant style in .owl/startup
  
 
 r20657@phanatique (orig r682):  nelhage | 2007-03-25 12:53:16 -0400
  r20654@phanatique:  nelhage | 2007-03-25 12:52:59 -0400
  That line doesn't need to be there twice -- probably a mismerge
  
 
 r20706@phanatique (orig r683):  nelhage | 2007-03-26 21:04:43 -0400
  r20704@phanatique:  nelhage | 2007-03-26 20:00:24 -0400
  We don't need two package lines..
  
 
 r20707@phanatique (orig r684):  nelhage | 2007-03-26 21:04:54 -0400
  r20705@phanatique:  nelhage | 2007-03-26 21:04:37 -0400
  Getting rid of indirect object syntax new calls. Quoting perlobj:
  
  > But what if there are no arguments? In that case, Perl must guess what
  > you want. Even worse, it must make that guess *at compile time*. Usually
  > Perl gets it right, but when it doesn't you get a function call compiled
  > as a method, or vice versa. This can introduce subtle bugs that are hard
  > to detect.
  > 
  > For example, a call to a method "new" in indirect notation -- as C++
  > programmers are wont to make -- can be miscompiled into a subroutine
  > call if there's already a "new" function in scope. You'd end up calling
  > the current package's "new" as a subroutine, rather than the desired
  > class's method. The compiler tries to cheat by remembering bareword
  > "require"s, but the grief when it messes up just isn't worth the years
  > of debugging it will take you to track down such subtle bugs.
      
 
 r20710@phanatique (orig r685):  nelhage | 2007-03-26 21:14:41 -0400
  r20708@phanatique:  nelhage | 2007-03-26 21:11:34 -0400
  Adding a reload-modules command
  
 
 r20711@phanatique (orig r686):  nelhage | 2007-03-26 21:14:49 -0400
  r20709@phanatique:  nelhage | 2007-03-26 21:14:31 -0400
  Moving Net::Jabber into Jabber.par
 
 r20714@phanatique (orig r687):  nelhage | 2007-03-26 21:18:13 -0400
  r20713@phanatique:  nelhage | 2007-03-26 21:17:59 -0400
  Don't install .svn dirs
  
 
 r20720@phanatique (orig r688):  nelhage | 2007-03-27 22:04:10 -0400
  r20719@phanatique:  nelhage | 2007-03-27 22:04:03 -0400
  Implementing an LRU cache of the message list fmtexts. This reduces
  memory usage by roughly 1MB/kilo-zephyrs in steady state.
 

 r20272@phanatique (orig r665):  nelhage | 2007-03-14 19:25:05 -0400
 Branching for the PAR module rewrite.
 r20274@phanatique (orig r667):  nelhage | 2007-03-16 00:45:19 -0400
 First phase of the module rewrite. Internals now (IMO) somewhat
 cleaner.
 
  r19586@phanatique:  nelhage | 2007-03-14 20:35:39 -0400
  First pass at a cleaned up perlwrap.pm
  
  * Using a new hook style
  * Modules loaded by BarnOwl::ModuleLoader (not yet written)
  
  reload is unimplemented for now. If possible, I'd like it to live
  elsewhere.
  
  r19587@phanatique:  nelhage | 2007-03-14 20:36:58 -0400
  Switching to the new underscore internal hook names.
  r19592@phanatique:  nelhage | 2007-03-16 00:34:00 -0400
  Actually switch to _receive_msg
  
  r19593@phanatique:  nelhage | 2007-03-16 00:34:27 -0400
  Some minor cleanup of perlwrap.pm. Shoving fake entries into @INC.
  
  r19594@phanatique:  nelhage | 2007-03-16 00:34:47 -0400
  First revision of ModuleLoader.
  
 
 r20281@phanatique (orig r669):  nelhage | 2007-03-17 14:48:02 -0400
  r20279@phanatique:  nelhage | 2007-03-17 14:46:56 -0400
  For reasons I don't claim to understand, using the old-style new was
  throwing odd errors about undefined functions.
  
 
 r20286@phanatique (orig r670):  nelhage | 2007-03-18 16:28:23 -0400
  r20282@phanatique:  nelhage | 2007-03-17 14:48:22 -0400
  Report more errors when something goes wrong
  
 
 r20287@phanatique (orig r671):  nelhage | 2007-03-18 16:28:31 -0400
  r20285@phanatique:  nelhage | 2007-03-18 16:28:18 -0400
  Adding the new M::Iified jabber module. There isn't a target to build
  the PAR yet.
 
 r20291@phanatique (orig r672):  nelhage | 2007-03-18 19:14:04 -0400
  r20290@phanatique:  nelhage | 2007-03-18 19:13:57 -0400
  Adding a Module::Install plugin for building barnowl plugins. It needs
  a lot of improvement.
 
 r20309@phanatique (orig r673):  nelhage | 2007-03-19 14:14:23 -0400
  r20301@phanatique:  nelhage | 2007-03-19 13:31:07 -0400
  Changing the dependency on the par target, so we don't rebuild unless
  we need to.
 
 r20310@phanatique (orig r674):  nelhage | 2007-03-19 14:14:33 -0400
  r20303@phanatique:  nelhage | 2007-03-19 13:32:25 -0400
  Modifying the makefile to build and install perl modules
 
 r20643@phanatique (orig r677):  nelhage | 2007-03-23 15:09:45 -0400
  r20640@phanatique:  nelhage | 2007-03-23 15:09:38 -0400
  Implement loading of unpacked modules, and module reloading.
 
 r20645@phanatique (orig r678):  nelhage | 2007-03-23 15:11:05 -0400
  r20644@phanatique:  nelhage | 2007-03-23 15:10:57 -0400
  Tighten up the reloaded regex a little.
  
 
 r20649@phanatique (orig r679):  nelhage | 2007-03-23 16:18:44 -0400
  r20648@phanatique:  nelhage | 2007-03-23 16:18:25 -0400
  Correctly install modules on a clean install.
  
 
 r20655@phanatique (orig r680):  nelhage | 2007-03-25 12:53:07 -0400
  r20650@phanatique:  nelhage | 2007-03-23 17:01:20 -0400
  Still not sure why old-style new seems to be eiting us so much...
  
 
 r20656@phanatique (orig r681):  nelhage | 2007-03-25 12:53:11 -0400
  r20653@phanatique:  nelhage | 2007-03-25 12:52:38 -0400
  Let's not segfault if the user asks for a nonexistant style in .owl/startup
  
 
 r20657@phanatique (orig r682):  nelhage | 2007-03-25 12:53:16 -0400
  r20654@phanatique:  nelhage | 2007-03-25 12:52:59 -0400
  That line doesn't need to be there twice -- probably a mismerge
  
 
 r20706@phanatique (orig r683):  nelhage | 2007-03-26 21:04:43 -0400
  r20704@phanatique:  nelhage | 2007-03-26 20:00:24 -0400
  We don't need two package lines..
  
 
 r20707@phanatique (orig r684):  nelhage | 2007-03-26 21:04:54 -0400
  r20705@phanatique:  nelhage | 2007-03-26 21:04:37 -0400
  Getting rid of indirect object syntax new calls. Quoting perlobj:
  
  > But what if there are no arguments? In that case, Perl must guess what
  > you want. Even worse, it must make that guess *at compile time*. Usually
  > Perl gets it right, but when it doesn't you get a function call compiled
  > as a method, or vice versa. This can introduce subtle bugs that are hard
  > to detect.
  > 
  > For example, a call to a method "new" in indirect notation -- as C++
  > programmers are wont to make -- can be miscompiled into a subroutine
  > call if there's already a "new" function in scope. You'd end up calling
  > the current package's "new" as a subroutine, rather than the desired
  > class's method. The compiler tries to cheat by remembering bareword
  > "require"s, but the grief when it messes up just isn't worth the years
  > of debugging it will take you to track down such subtle bugs.
      
 
 r20710@phanatique (orig r685):  nelhage | 2007-03-26 21:14:41 -0400
  r20708@phanatique:  nelhage | 2007-03-26 21:11:34 -0400
  Adding a reload-modules command
  
 
 r20711@phanatique (orig r686):  nelhage | 2007-03-26 21:14:49 -0400
  r20709@phanatique:  nelhage | 2007-03-26 21:14:31 -0400
  Moving Net::Jabber into Jabber.par
 
 r20714@phanatique (orig r687):  nelhage | 2007-03-26 21:18:13 -0400
  r20713@phanatique:  nelhage | 2007-03-26 21:17:59 -0400
  Don't install .svn dirs
  
 
 r20720@phanatique (orig r688):  nelhage | 2007-03-27 22:04:10 -0400
  r20719@phanatique:  nelhage | 2007-03-27 22:04:03 -0400
  Implementing an LRU cache of the message list fmtexts. This reduces
  memory usage by roughly 1MB/kilo-zephyrs in steady state.
 



Property changes on: trunk/owl
___________________________________________________________________
Name: svk:merge
   - 06e3988a-d725-0410-af47-c5dd11e74598:/local/barnowl:1380
8baf6839-b125-0410-9df9-922793c80423:/local/barnowl:17717
8baf6839-b125-0410-9df9-922793c80423:/local/owl:15641
   + 06e3988a-d725-0410-af47-c5dd11e74598:/local/barnowl:1380
8baf6839-b125-0410-9df9-922793c80423:/local/barnowl:17717
8baf6839-b125-0410-9df9-922793c80423:/local/owl:15641
bb873fd7-8e23-0410-944a-99ec44c633eb:/local/d-o-h/branches/par:19594
fe09232e-8620-0410-8e36-e6b4839e121d:/branches/par:688

Modified: trunk/owl/BUGS
===================================================================
--- trunk/owl/BUGS	2007-03-28 02:04:10 UTC (rev 688)
+++ trunk/owl/BUGS	2007-03-29 01:32:11 UTC (rev 689)
@@ -4,4 +4,3 @@
   long JIDs [nelhage]
 * reply to resource names from ichat (foo's computer) fails badly [hartmans]
 * viewuser doesn't work with AIM or Jabber
-* jmuc join'ing a MUC you're already in has weird behavior [nelhage]

Modified: trunk/owl/Makefile.in
===================================================================
--- trunk/owl/Makefile.in	2007-03-28 02:04:10 UTC (rev 688)
+++ trunk/owl/Makefile.in	2007-03-29 01:32:11 UTC (rev 689)
@@ -30,6 +30,8 @@
 TESTER_SRC = tester.c
 
 EXE = barnowl
+PERL_MODULES = Jabber
+MODULE_DIRS = $(PERL_MODULES:%=perl/modules/%)
 
 BASE_OBJS = $(BASE_SRCS:.c=.o)
 
@@ -56,12 +58,26 @@
 test: tester
 	./tester reg
 
-clean: libfaimclean
+clean: libfaimclean modules_clean
 	$(RM) $(EXE) tester *.o $(AUTOGEN) owl_prototypes.h.new
 
 distclean: clean libfaimdistclean
 	$(RM) config.cache config.log config.status  Makefile config.h TAGS *~ core
 
+.PHONY: $(MODULE_DIRS)
+
+modules: $(MODULE_DIRS)
+modules_clean:
+	for i in $(MODULE_DIRS); do \
+		cd $$i; test ! -f Makefile || make clean; \
+	done
+
+$(MODULE_DIRS): %: %/Makefile
+	( cd $@ && make $(notdir $@).par )
+
+$(MODULE_DIRS:=/Makefile): %/Makefile: %/Makefile.PL
+	( cd $(dir $@) && perl -I../../lib Makefile.PL )
+
 proto: owl_prototypes.h
 
 perlglue.c: perlglue.xs Makefile 
@@ -103,12 +119,17 @@
 libfaimdistclean:
 	(cd libfaim; $(MAKE) distclean)
 
-all: $(EXE)
+all: $(EXE) $(MODULE_DIRS)
 
 install: all installdirs
 	${INSTALL_PROGRAM} $(EXE) ${DESTDIR}${bindir}/$(EXE)
 	${INSTALL_DATA} doc/owl.1 ${DESTDIR}${mandir}/man1/barnowl.1
-	tar -C perl -c . | tar -C ${DESTDIR}${datadir} -x
+	${INSTALL} -d ${DESTDIR}${datadir}/lib
+	${INSTALL} -d ${DESTDIR}${datadir}/modules
+	tar -C perl/lib --exclude .svn -c . | tar -C ${DESTDIR}${datadir}/lib -x
+	for i in $(PERL_MODULES); do \
+		${INSTALL_DATA} perl/modules/$$i/$$i.par ${DESTDIR}${datadir}/modules/$$i.par; \
+	done
 
 installdirs: mkinstalldirs
 	${srcdir}/mkinstalldirs ${DESTDIR}${bindir} ${DESTDIR}${mandir}/man1 ${DESTDIR}${datadir}

Modified: trunk/owl/fmtext.c
===================================================================
--- trunk/owl/fmtext.c	2007-03-28 02:04:10 UTC (rev 688)
+++ trunk/owl/fmtext.c	2007-03-29 01:32:11 UTC (rev 689)
@@ -8,15 +8,28 @@
 void owl_fmtext_init_null(owl_fmtext *f)
 {
   f->textlen=0;
-  f->textbuff=owl_strdup("");
+  f->bufflen=5;
+  f->textbuff=owl_malloc(5);
   f->fmbuff=owl_malloc(5);
   f->fgcolorbuff=owl_malloc(5);
   f->bgcolorbuff=owl_malloc(5);
+  f->textbuff[0]=0;
   f->fmbuff[0]=OWL_FMTEXT_ATTR_NONE;
   f->fgcolorbuff[0]=OWL_COLOR_DEFAULT;
   f->bgcolorbuff[0]=OWL_COLOR_DEFAULT;
 }
 
+/* Clear the data from an fmtext, but don't deallocate memory. This
+   fmtext can then be appended to again. */
+void owl_fmtext_clear(owl_fmtext *f)
+{
+    f->textlen = 0;
+    f->textbuff[0] = 0;
+    f->fmbuff[0]=OWL_FMTEXT_ATTR_NONE;
+    f->fgcolorbuff[0]=OWL_COLOR_DEFAULT;
+    f->bgcolorbuff[0]=OWL_COLOR_DEFAULT;
+}
+
 /* Internal function.  Set the attribute 'attr' from index 'first' to
  * index 'last'
  */
@@ -58,19 +71,26 @@
   }
 }
 
+void _owl_fmtext_realloc(owl_fmtext *f, int newlen) /*noproto*/
+{
+    if(newlen + 1 > f->bufflen) {
+      f->textbuff=owl_realloc(f->textbuff, newlen+1);
+      f->fmbuff=owl_realloc(f->fmbuff, newlen+1);
+      f->fgcolorbuff=owl_realloc(f->fgcolorbuff, newlen+1);
+      f->bgcolorbuff=owl_realloc(f->bgcolorbuff, newlen+1);
+      f->bufflen = newlen+1;
+  }
+}
+
 /* append text to the end of 'f' with attribute 'attr' and color
  * 'color'
  */
 void owl_fmtext_append_attr(owl_fmtext *f, char *text, int attr, int fgcolor, int bgcolor)
 {
   int newlen;
-
   newlen=strlen(f->textbuff)+strlen(text);
-  f->textbuff=owl_realloc(f->textbuff, newlen+2);
-  f->fmbuff=owl_realloc(f->fmbuff, newlen+2);
-  f->fgcolorbuff=owl_realloc(f->fgcolorbuff, newlen+2);
-  f->bgcolorbuff=owl_realloc(f->bgcolorbuff, newlen+2);
-
+  _owl_fmtext_realloc(f, newlen);
+  
   strcat(f->textbuff, text);
   _owl_fmtext_set_attr(f, attr, f->textlen, newlen);
   _owl_fmtext_set_fgcolor(f, fgcolor, f->textlen, newlen);
@@ -153,10 +173,7 @@
   int newlen, i;
 
   newlen=strlen(f->textbuff)+(stop-start+1);
-  f->textbuff=owl_realloc(f->textbuff, newlen+1);
-  f->fmbuff=owl_realloc(f->fmbuff, newlen+1);
-  f->fgcolorbuff=owl_realloc(f->fgcolorbuff, newlen+1);
-  f->bgcolorbuff=owl_realloc(f->bgcolorbuff, newlen+1);
+  _owl_fmtext_realloc(f, newlen);
 
   strncat(f->textbuff, in->textbuff+start, stop-start+1);
   f->textbuff[newlen]='\0';

Modified: trunk/owl/functions.c
===================================================================
--- trunk/owl/functions.c	2007-03-28 02:04:10 UTC (rev 688)
+++ trunk/owl/functions.c	2007-03-29 01:32:11 UTC (rev 689)
@@ -1034,7 +1034,7 @@
   }
 
   /* execute the commands in shutdown */
-  ret = owl_perlconfig_execute("BarnOwl::Hooks::shutdown();");
+  ret = owl_perlconfig_execute("BarnOwl::Hooks::_shutdown();");
   if (ret) owl_free(ret);
 
   /* signal our child process, if any */
@@ -3364,8 +3364,8 @@
 #endif
 
   if(aim && zephyr) {
-      if(owl_perlconfig_is_function("BarnOwl::Hooks::get_blist")) {
-          char * perlblist = owl_perlconfig_execute("BarnOwl::Hooks::get_blist()");
+      if(owl_perlconfig_is_function("BarnOwl::Hooks::_get_blist")) {
+          char * perlblist = owl_perlconfig_execute("BarnOwl::Hooks::_get_blist()");
           if(perlblist) {
               owl_fmtext_append_ztext(&fm, perlblist);
               owl_free(perlblist);

Modified: trunk/owl/global.c
===================================================================
--- trunk/owl/global.c	2007-03-28 02:04:10 UTC (rev 688)
+++ trunk/owl/global.c	2007-03-29 01:32:11 UTC (rev 689)
@@ -107,6 +107,8 @@
   owl_timer_create_countdown(&(g->zephyr_buddycheck_timer), 60*3);
 
   owl_obarray_init(&(g->obarray));
+
+  owl_message_init_fmtext_cache();
 }
 
 void _owl_global_setup_windows(owl_global *g) {

Modified: trunk/owl/message.c
===================================================================
--- trunk/owl/message.c	2007-03-28 02:04:10 UTC (rev 688)
+++ trunk/owl/message.c	2007-03-29 01:32:11 UTC (rev 689)
@@ -12,13 +12,36 @@
 
 static const char fileIdent[] = "$Id$";
 
+static owl_fmtext_cache fmtext_cache[OWL_FMTEXT_CACHE_SIZE];
+static owl_fmtext_cache * fmtext_cache_next = fmtext_cache;
+
+void owl_message_init_fmtext_cache ()
+{
+    int i;
+    for(i = 0; i < OWL_FMTEXT_CACHE_SIZE; i++) {
+        owl_fmtext_init_null(&(fmtext_cache[i].fmtext));
+        fmtext_cache[i].message = NULL;
+    }
+}
+
+owl_fmtext_cache * owl_message_next_fmtext() /*noproto*/
+{
+    if(fmtext_cache_next->message != NULL) {
+        owl_message_invalidate_format(fmtext_cache_next->message);
+    }
+    owl_fmtext_cache * f = fmtext_cache_next;
+    fmtext_cache_next++;
+    if(fmtext_cache_next - fmtext_cache == OWL_FMTEXT_CACHE_SIZE)
+        fmtext_cache_next = fmtext_cache;
+    return f;
+}
+
 void owl_message_init(owl_message *m)
 {
   m->id=owl_global_get_nextmsgid(&g);
   owl_message_set_direction_none(m);
   m->delete=0;
   m->zwriteline=NULL;
-  m->invalid_format=1;
 
   owl_message_set_hostname(m, "");
   owl_list_create(&(m->attributes));
@@ -28,8 +51,7 @@
   m->timestr=owl_strdup(ctime(&(m->time)));
   m->timestr[strlen(m->timestr)-1]='\0';
 
-  /* initialize the fmtext */
-  owl_fmtext_init_null(&(m->fmtext));
+  m->fmtext = NULL;
 }
 
 /* add the named attribute to the message.  If an attribute with the
@@ -105,13 +127,17 @@
 
 void owl_message_invalidate_format(owl_message *m)
 {
-  m->invalid_format=1;
+  if(m->fmtext) {
+    m->fmtext->message = NULL;
+    owl_fmtext_clear(&(m->fmtext->fmtext));
+    m->fmtext=NULL;
+  }
 }
 
 owl_fmtext *owl_message_get_fmtext(owl_message *m)
 {
   owl_message_format(m);
-  return(&(m->fmtext));
+  return(&(m->fmtext->fmtext));
 }
 
 void owl_message_format(owl_message *m)
@@ -119,15 +145,14 @@
   owl_style *s;
   owl_view *v;
 
-  if (m->invalid_format) {
+  if (!m->fmtext) {
+    m->fmtext = owl_message_next_fmtext();
+    m->fmtext->message = m;
     /* for now we assume there's just the one view and use that style */
     v=owl_global_get_current_view(&g);
     s=owl_view_get_style(v);
 
-    owl_fmtext_free(&(m->fmtext));
-    owl_fmtext_init_null(&(m->fmtext));
-    owl_style_get_formattext(s, &(m->fmtext), m);
-    m->invalid_format=0;
+    owl_style_get_formattext(s, &(m->fmtext->fmtext), m);
   }
 }
 
@@ -391,7 +416,7 @@
 
 char *owl_message_get_text(owl_message *m)
 {
-  return(owl_fmtext_get_text(&(m->fmtext)));
+  return(owl_fmtext_get_text(&(m->fmtext->fmtext)));
 }
 
 void owl_message_set_direction_in(owl_message *m)
@@ -436,7 +461,7 @@
 {
   if (m == NULL) return(0);
   owl_message_format(m);
-  return(owl_fmtext_num_lines(&(m->fmtext)));
+  return(owl_fmtext_num_lines(&(m->fmtext->fmtext)));
 }
 
 void owl_message_mark_delete(owl_message *m)
@@ -503,7 +528,7 @@
   owl_fmtext_init_null(&a);
   owl_fmtext_init_null(&b);
   
-  owl_fmtext_truncate_lines(&(m->fmtext), aline, bline-aline+1, &a);
+  owl_fmtext_truncate_lines(&(m->fmtext->fmtext), aline, bline-aline+1, &a);
   owl_fmtext_truncate_cols(&a, acol, bcol, &b);
   if (fgcolor!=OWL_COLOR_DEFAULT) {
     owl_fmtext_colorize(&b, fgcolor);
@@ -697,7 +722,7 @@
 
   owl_message_format(m); /* is this necessary? */
   
-  return (owl_fmtext_search(&(m->fmtext), string));
+  return (owl_fmtext_search(&(m->fmtext->fmtext), string));
 }
 
 
@@ -988,5 +1013,5 @@
 
   owl_list_free_simple(&(m->attributes));
  
-  owl_fmtext_free(&(m->fmtext));
+  owl_message_invalidate_format(m);
 }

Modified: trunk/owl/owl.c
===================================================================
--- trunk/owl/owl.c	2007-03-28 02:04:10 UTC (rev 688)
+++ trunk/owl/owl.c	2007-03-29 01:32:11 UTC (rev 689)
@@ -317,7 +317,7 @@
 
   /* execute the startup function in the configfile */
   owl_function_debugmsg("startup: executing perl startup, if applicable");
-  perlout = owl_perlconfig_execute("BarnOwl::Hooks::startup();");
+  perlout = owl_perlconfig_execute("BarnOwl::Hooks::_startup();");
   if (perlout) owl_free(perlout);
 
   /* hold on to the window names for convenience */
@@ -396,8 +396,11 @@
   }
 
   owl_function_debugmsg("startup: set style for the view: %s", owl_global_get_default_style(&g));
-  owl_view_set_style(owl_global_get_current_view(&g), 
-		     owl_global_get_style_by_name(&g, owl_global_get_default_style(&g)));   
+  s = owl_global_get_style_by_name(&g, owl_global_get_default_style(&g));
+  if(s)
+      owl_view_set_style(owl_global_get_current_view(&g), s);
+  else
+      owl_function_error("No such style: %s", owl_global_get_default_style(&g));
 
   owl_function_debugmsg("startup: setting context interactive");
   owl_context_set_interactive(owl_global_get_context(&g));

Modified: trunk/owl/owl.h
===================================================================
--- trunk/owl/owl.h	2007-03-28 02:04:10 UTC (rev 688)
+++ trunk/owl/owl.h	2007-03-29 01:32:11 UTC (rev 689)
@@ -248,6 +248,7 @@
 
 typedef struct _owl_fmtext {
   int textlen;
+  int bufflen;
   char *textbuff;
   char *fmbuff;
   char *fgcolorbuff;
@@ -328,14 +329,15 @@
   void *value;
 } owl_pair;
 
+struct _owl_fmtext_cache;
+
 typedef struct _owl_message {
   int id;
   int direction;
 #ifdef HAVE_LIBZEPHYR
   ZNotice_t notice;
 #endif
-  owl_fmtext fmtext;              /* this is now only a CACHED copy */
-  int invalid_format;             /* indicates whether fmtext needs to be regenerated */
+  struct _owl_fmtext_cache * fmtext;
   int delete;
   char *hostname;
   owl_list attributes;            /* this is a list of pairs */
@@ -344,6 +346,14 @@
   char *zwriteline;
 } owl_message;
 
+#define OWL_FMTEXT_CACHE_SIZE 1000
+/* We cache the saved fmtexts for the last bunch of messages we
+   rendered */
+typedef struct _owl_fmtext_cache {
+    owl_message * message;
+    owl_fmtext fmtext;
+} owl_fmtext_cache;
+
 typedef struct _owl_style {
   char *name;
   char *description;

Added: trunk/owl/perl/lib/BarnOwl/ModuleLoader.pm
===================================================================
--- trunk/owl/perl/lib/BarnOwl/ModuleLoader.pm	                        (rev 0)
+++ trunk/owl/perl/lib/BarnOwl/ModuleLoader.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -0,0 +1,72 @@
+use strict;
+use warnings;
+
+package BarnOwl::ModuleLoader;
+
+use lib (BarnOwl::get_data_dir() . "/modules/");
+use PAR (BarnOwl::get_data_dir() . "/modules/*.par");
+use PAR ($ENV{HOME} . "/.owl/modules/*.par");
+
+sub load_all {
+    my %modules;
+    my @modules;
+    
+    for my $dir ( BarnOwl::get_data_dir() . "/modules",
+                  $ENV{HOME} . "/.owl/modules" ) {
+        opendir(my $dh, $dir) or next;
+        while(defined(my $f = readdir($dh))) {
+            next if $f =~ /^\./;
+            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;
+                $modules{$f} = 1;
+            }
+        }
+        @modules = grep /\.par$/, readdir($dh);
+        closedir($dh);
+        for my $mod (@modules) {
+            my ($class) = ($mod =~ /^(.+)\.par$/);
+            $modules{$class} = 1;
+        }
+    }
+    for my $class (keys %modules) {
+        if(!defined eval "use BarnOwl::Module::$class") {
+            BarnOwl::error("Unable to load module $class: $!") if $!;
+            BarnOwl::error("Unable to load module $class: $@") if $@;
+        }
+    }
+
+    $BarnOwl::Hooks::startup->add(\&register_keybindings);
+}
+
+sub register_keybindings {
+    BarnOwl::new_command('reload-modules', sub {BarnOwl::ModuleLoader->reload}, {
+                           summary => 'Reload all modules',
+                           usage   => 'reload',
+                           description => q{Reloads all modules located in ~/.owl/modules and the system modules directory}
+                          });
+}
+
+sub reload {
+    my $class = shift;
+    for my $m (keys %INC) {
+        delete $INC{$m} if $m =~ m{^BarnOwl/};
+    }
+    # Restore core modules from perlwrap.pm
+    $INC{$_} = 1 for (qw(BarnOwl.pm BarnOwl/Hooks.pm
+                         BarnOwl/Message.pm BarnOwl/Style.pm));
+
+    $BarnOwl::Hooks::startup->clear;
+    local $SIG{__WARN__} = \&squelch_redefine;
+    $class->load_all;
+    $BarnOwl::Hooks::startup->run(1);
+    BarnOwl::startup() if *BarnOwl::startup{CODE};
+}
+
+sub squelch_redefine {
+    my $warning = shift;
+    warn $warning unless $warning =~ /^Subroutine .+ redefined at/;
+}
+
+1;

Added: trunk/owl/perl/lib/Module/Install/BarnOwl.pm
===================================================================
--- trunk/owl/perl/lib/Module/Install/BarnOwl.pm	                        (rev 0)
+++ trunk/owl/perl/lib/Module/Install/BarnOwl.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -0,0 +1,62 @@
+use warnings;
+use strict;
+
+=head1 NAME
+
+Module::Install::BarnOwl
+
+=head1 DESCRIPTION
+
+Module::Install::BarnOwl is a M::I module to help building barnowl
+modules,
+
+=head1 SYNOPSIS
+
+    use inc::Module::Install;
+    barnowl_module('Jabber');
+    WriteAll;
+
+This is roughly equivalent to:
+
+    use inc::Module::Install;
+
+    name('BarnOwl-Module-Jabber');
+    all_from('lib/BarnOwl/Module/Jabber.pm');
+    requires_external_bin('barnowl');
+
+    WriteAll;
+
+As well as make rules to generate Jabber.par, and to put some
+additional barnowl-specific information into META.yml
+
+=cut
+
+package Module::Install::BarnOwl;
+
+use base qw(Module::Install::Base);
+
+sub barnowl_module {
+    my $self = shift;
+    my $name = ucfirst shift;
+    my $class = ref $self;
+
+    $self->name("BarnOwl-Module-$name");
+    $self->all_from("lib/BarnOwl/Module/$name.pm");
+
+    $self->postamble(<<"END_MAKEFILE");
+
+# --- $class section:
+
+$name.par: pm_to_blib
+\tcd blib; zip ../$name.par -r arch lib
+
+END_MAKEFILE
+}
+
+=head1 SEE ALSO
+
+L<Module::Install>, L<BarnOwl>
+
+=cut
+
+1;

Added: trunk/owl/perl/modules/Jabber/Makefile.PL
===================================================================
--- trunk/owl/perl/modules/Jabber/Makefile.PL	                        (rev 0)
+++ trunk/owl/perl/modules/Jabber/Makefile.PL	2007-03-29 01:32:11 UTC (rev 689)
@@ -0,0 +1,8 @@
+use strict;
+use warnings;
+
+use inc::Module::Install;
+
+barnowl_module('Jabber');
+
+WriteAll;

Added: trunk/owl/perl/modules/Jabber/inc/Module/Install/BarnOwl.pm
===================================================================
--- trunk/owl/perl/modules/Jabber/inc/Module/Install/BarnOwl.pm	                        (rev 0)
+++ trunk/owl/perl/modules/Jabber/inc/Module/Install/BarnOwl.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -0,0 +1,31 @@
+#line 1
+use warnings;
+use strict;
+
+#line 32
+
+package Module::Install::BarnOwl;
+
+use base qw(Module::Install::Base);
+
+sub barnowl_module {
+    my $self = shift;
+    my $name = ucfirst shift;
+    my $class = ref $self;
+
+    $self->name("BarnOwl-Module-$name");
+    $self->all_from("lib/BarnOwl/Module/$name.pm");
+
+    $self->postamble(<<"END_MAKEFILE");
+
+# --- $class section:
+
+$name.par: pm_to_blib
+\tcd blib; zip ../$name.par -r arch lib
+
+END_MAKEFILE
+}
+
+#line 60
+
+1;

Added: trunk/owl/perl/modules/Jabber/inc/Module/Install/Base.pm
===================================================================
--- trunk/owl/perl/modules/Jabber/inc/Module/Install/Base.pm	                        (rev 0)
+++ trunk/owl/perl/modules/Jabber/inc/Module/Install/Base.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -0,0 +1,70 @@
+#line 1
+package Module::Install::Base;
+
+$VERSION = '0.65';
+
+# Suspend handler for "redefined" warnings
+BEGIN {
+	my $w = $SIG{__WARN__};
+	$SIG{__WARN__} = sub { $w };
+}
+
+### This is the ONLY module that shouldn't have strict on
+# use strict;
+
+#line 41
+
+sub new {
+    my ($class, %args) = @_;
+
+    foreach my $method ( qw(call load) ) {
+        *{"$class\::$method"} = sub {
+            shift()->_top->$method(@_);
+        } unless defined &{"$class\::$method"};
+    }
+
+    bless( \%args, $class );
+}
+
+#line 61
+
+sub AUTOLOAD {
+    my $self = shift;
+    local $@;
+    my $autoload = eval { $self->_top->autoload } or return;
+    goto &$autoload;
+}
+
+#line 76
+
+sub _top { $_[0]->{_top} }
+
+#line 89
+
+sub admin {
+    $_[0]->_top->{admin} or Module::Install::Base::FakeAdmin->new;
+}
+
+sub is_admin {
+    $_[0]->admin->VERSION;
+}
+
+sub DESTROY {}
+
+package Module::Install::Base::FakeAdmin;
+
+my $Fake;
+sub new { $Fake ||= bless(\@_, $_[0]) }
+
+sub AUTOLOAD {}
+
+sub DESTROY {}
+
+# Restore warning handler
+BEGIN {
+	$SIG{__WARN__} = $SIG{__WARN__}->();
+}
+
+1;
+
+#line 138

Added: trunk/owl/perl/modules/Jabber/inc/Module/Install/Can.pm
===================================================================
--- trunk/owl/perl/modules/Jabber/inc/Module/Install/Can.pm	                        (rev 0)
+++ trunk/owl/perl/modules/Jabber/inc/Module/Install/Can.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -0,0 +1,82 @@
+#line 1
+package Module::Install::Can;
+
+use strict;
+use Module::Install::Base;
+use Config ();
+### This adds a 5.005 Perl version dependency.
+### This is a bug and will be fixed.
+use File::Spec ();
+use ExtUtils::MakeMaker ();
+
+use vars qw{$VERSION $ISCORE @ISA};
+BEGIN {
+	$VERSION = '0.65';
+	$ISCORE  = 1;
+	@ISA     = qw{Module::Install::Base};
+}
+
+# check if we can load some module
+### Upgrade this to not have to load the module if possible
+sub can_use {
+	my ($self, $mod, $ver) = @_;
+	$mod =~ s{::|\\}{/}g;
+	$mod .= '.pm' unless $mod =~ /\.pm$/i;
+
+	my $pkg = $mod;
+	$pkg =~ s{/}{::}g;
+	$pkg =~ s{\.pm$}{}i;
+
+	local $@;
+	eval { require $mod; $pkg->VERSION($ver || 0); 1 };
+}
+
+# check if we can run some command
+sub can_run {
+	my ($self, $cmd) = @_;
+
+	my $_cmd = $cmd;
+	return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd));
+
+	for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
+		my $abs = File::Spec->catfile($dir, $_[1]);
+		return $abs if (-x $abs or $abs = MM->maybe_command($abs));
+	}
+
+	return;
+}
+
+# can we locate a (the) C compiler
+sub can_cc {
+	my $self   = shift;
+	my @chunks = split(/ /, $Config::Config{cc}) or return;
+
+	# $Config{cc} may contain args; try to find out the program part
+	while (@chunks) {
+		return $self->can_run("@chunks") || (pop(@chunks), next);
+	}
+
+	return;
+}
+
+# Fix Cygwin bug on maybe_command();
+if ( $^O eq 'cygwin' ) {
+	require ExtUtils::MM_Cygwin;
+	require ExtUtils::MM_Win32;
+	if ( ! defined(&ExtUtils::MM_Cygwin::maybe_command) ) {
+		*ExtUtils::MM_Cygwin::maybe_command = sub {
+			my ($self, $file) = @_;
+			if ($file =~ m{^/cygdrive/}i and ExtUtils::MM_Win32->can('maybe_command')) {
+				ExtUtils::MM_Win32->maybe_command($file);
+			} else {
+				ExtUtils::MM_Unix->maybe_command($file);
+			}
+		}
+	}
+}
+
+1;
+
+__END__
+
+#line 157

Added: trunk/owl/perl/modules/Jabber/inc/Module/Install/Fetch.pm
===================================================================
--- trunk/owl/perl/modules/Jabber/inc/Module/Install/Fetch.pm	                        (rev 0)
+++ trunk/owl/perl/modules/Jabber/inc/Module/Install/Fetch.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -0,0 +1,93 @@
+#line 1
+package Module::Install::Fetch;
+
+use strict;
+use Module::Install::Base;
+
+use vars qw{$VERSION $ISCORE @ISA};
+BEGIN {
+	$VERSION = '0.65';
+	$ISCORE  = 1;
+	@ISA     = qw{Module::Install::Base};
+}
+
+sub get_file {
+    my ($self, %args) = @_;
+    my ($scheme, $host, $path, $file) = 
+        $args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return;
+
+    if ( $scheme eq 'http' and ! eval { require LWP::Simple; 1 } ) {
+        $args{url} = $args{ftp_url}
+            or (warn("LWP support unavailable!\n"), return);
+        ($scheme, $host, $path, $file) = 
+            $args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return;
+    }
+
+    $|++;
+    print "Fetching '$file' from $host... ";
+
+    unless (eval { require Socket; Socket::inet_aton($host) }) {
+        warn "'$host' resolve failed!\n";
+        return;
+    }
+
+    return unless $scheme eq 'ftp' or $scheme eq 'http';
+
+    require Cwd;
+    my $dir = Cwd::getcwd();
+    chdir $args{local_dir} or return if exists $args{local_dir};
+
+    if (eval { require LWP::Simple; 1 }) {
+        LWP::Simple::mirror($args{url}, $file);
+    }
+    elsif (eval { require Net::FTP; 1 }) { eval {
+        # use Net::FTP to get past firewall
+        my $ftp = Net::FTP->new($host, Passive => 1, Timeout => 600);
+        $ftp->login("anonymous", 'anonymous@example.com');
+        $ftp->cwd($path);
+        $ftp->binary;
+        $ftp->get($file) or (warn("$!\n"), return);
+        $ftp->quit;
+    } }
+    elsif (my $ftp = $self->can_run('ftp')) { eval {
+        # no Net::FTP, fallback to ftp.exe
+        require FileHandle;
+        my $fh = FileHandle->new;
+
+        local $SIG{CHLD} = 'IGNORE';
+        unless ($fh->open("|$ftp -n")) {
+            warn "Couldn't open ftp: $!\n";
+            chdir $dir; return;
+        }
+
+        my @dialog = split(/\n/, <<"END_FTP");
+open $host
+user anonymous anonymous\@example.com
+cd $path
+binary
+get $file $file
+quit
+END_FTP
+        foreach (@dialog) { $fh->print("$_\n") }
+        $fh->close;
+    } }
+    else {
+        warn "No working 'ftp' program available!\n";
+        chdir $dir; return;
+    }
+
+    unless (-f $file) {
+        warn "Fetching failed: $@\n";
+        chdir $dir; return;
+    }
+
+    return if exists $args{size} and -s $file != $args{size};
+    system($args{run}) if exists $args{run};
+    unlink($file) if $args{remove};
+
+    print(((!exists $args{check_for} or -e $args{check_for})
+        ? "done!" : "failed! ($!)"), "\n");
+    chdir $dir; return !$?;
+}
+
+1;

Added: trunk/owl/perl/modules/Jabber/inc/Module/Install/Makefile.pm
===================================================================
--- trunk/owl/perl/modules/Jabber/inc/Module/Install/Makefile.pm	                        (rev 0)
+++ trunk/owl/perl/modules/Jabber/inc/Module/Install/Makefile.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -0,0 +1,212 @@
+#line 1
+package Module::Install::Makefile;
+
+use strict 'vars';
+use Module::Install::Base;
+use ExtUtils::MakeMaker ();
+
+use vars qw{$VERSION $ISCORE @ISA};
+BEGIN {
+	$VERSION = '0.65';
+	$ISCORE  = 1;
+	@ISA     = qw{Module::Install::Base};
+}
+
+sub Makefile { $_[0] }
+
+my %seen = ();
+
+sub prompt {
+    shift;
+
+    # Infinite loop protection
+    my @c = caller();
+    if ( ++$seen{"$c[1]|$c[2]|$_[0]"} > 3 ) {
+        die "Caught an potential prompt infinite loop ($c[1]|$c[2]|$_[0])";
+    }
+
+    # In automated testing, always use defaults
+    if ( $ENV{AUTOMATED_TESTING} and ! $ENV{PERL_MM_USE_DEFAULT} ) {
+        local $ENV{PERL_MM_USE_DEFAULT} = 1;
+        goto &ExtUtils::MakeMaker::prompt;
+    } else {
+        goto &ExtUtils::MakeMaker::prompt;
+    }
+}
+
+sub makemaker_args {
+    my $self = shift;
+    my $args = ($self->{makemaker_args} ||= {});
+    %$args = ( %$args, @_ ) if @_;
+    $args;
+}
+
+# For mm args that take multiple space-seperated args,
+# append an argument to the current list.
+sub makemaker_append {
+    my $self = shift;
+    my $name = shift;
+    my $args = $self->makemaker_args;
+    $args->{name} = defined $args->{$name}
+    	? join( ' ', $args->{name}, @_ )
+    	: join( ' ', @_ );
+}
+
+sub build_subdirs {
+    my $self    = shift;
+    my $subdirs = $self->makemaker_args->{DIR} ||= [];
+    for my $subdir (@_) {
+        push @$subdirs, $subdir;
+    }
+}
+
+sub clean_files {
+    my $self  = shift;
+    my $clean = $self->makemaker_args->{clean} ||= {};
+    %$clean = (
+        %$clean, 
+        FILES => join(' ', grep length, $clean->{FILES}, @_),
+    );
+}
+
+sub realclean_files {
+    my $self  = shift;
+    my $realclean = $self->makemaker_args->{realclean} ||= {};
+    %$realclean = (
+        %$realclean, 
+        FILES => join(' ', grep length, $realclean->{FILES}, @_),
+    );
+}
+
+sub libs {
+    my $self = shift;
+    my $libs = ref $_[0] ? shift : [ shift ];
+    $self->makemaker_args( LIBS => $libs );
+}
+
+sub inc {
+    my $self = shift;
+    $self->makemaker_args( INC => shift );
+}
+
+sub write {
+    my $self = shift;
+    die "&Makefile->write() takes no arguments\n" if @_;
+
+    my $args = $self->makemaker_args;
+    $args->{DISTNAME} = $self->name;
+    $args->{NAME}     = $self->module_name || $self->name || $self->determine_NAME($args);
+    $args->{VERSION}  = $self->version || $self->determine_VERSION($args);
+    $args->{NAME}     =~ s/-/::/g;
+    if ( $self->tests ) {
+        $args->{test} = { TESTS => $self->tests };
+    }
+    if ($] >= 5.005) {
+        $args->{ABSTRACT} = $self->abstract;
+        $args->{AUTHOR}   = $self->author;
+    }
+    if ( eval($ExtUtils::MakeMaker::VERSION) >= 6.10 ) {
+        $args->{NO_META} = 1;
+    }
+    if ( eval($ExtUtils::MakeMaker::VERSION) > 6.17 and $self->sign ) {
+        $args->{SIGN} = 1;
+    }
+    unless ( $self->is_admin ) {
+        delete $args->{SIGN};
+    }
+
+    # merge both kinds of requires into prereq_pm
+    my $prereq = ($args->{PREREQ_PM} ||= {});
+    %$prereq = ( %$prereq, map { @$_ } map { @$_ } grep $_,
+                 ($self->build_requires, $self->requires) );
+
+    # merge both kinds of requires into prereq_pm
+    my $subdirs = ($args->{DIR} ||= []);
+    if ($self->bundles) {
+        foreach my $bundle (@{ $self->bundles }) {
+            my ($file, $dir) = @$bundle;
+            push @$subdirs, $dir if -d $dir;
+            delete $prereq->{$file};
+        }
+    }
+
+    if ( my $perl_version = $self->perl_version ) {
+        eval "use $perl_version; 1"
+            or die "ERROR: perl: Version $] is installed, "
+                . "but we need version >= $perl_version";
+    }
+
+    $args->{INSTALLDIRS} = $self->installdirs;
+
+    my %args = map { ( $_ => $args->{$_} ) } grep {defined($args->{$_})} keys %$args;
+
+    my $user_preop = delete $args{dist}->{PREOP};
+    if (my $preop = $self->admin->preop($user_preop)) {
+        $args{dist} = $preop;
+    }
+
+    my $mm = ExtUtils::MakeMaker::WriteMakefile(%args);
+    $self->fix_up_makefile($mm->{FIRST_MAKEFILE} || 'Makefile');
+}
+
+sub fix_up_makefile {
+    my $self          = shift;
+    my $makefile_name = shift;
+    my $top_class     = ref($self->_top) || '';
+    my $top_version   = $self->_top->VERSION || '';
+
+    my $preamble = $self->preamble 
+        ? "# Preamble by $top_class $top_version\n"
+            . $self->preamble
+        : '';
+    my $postamble = "# Postamble by $top_class $top_version\n"
+        . ($self->postamble || '');
+
+    local *MAKEFILE;
+    open MAKEFILE, "< $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!";
+    my $makefile = do { local $/; <MAKEFILE> };
+    close MAKEFILE or die $!;
+
+    $makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /;
+    $makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g;
+    $makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g;
+    $makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m;
+    $makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m;
+
+    # Module::Install will never be used to build the Core Perl
+    # Sometimes PERL_LIB and PERL_ARCHLIB get written anyway, which breaks
+    # PREFIX/PERL5LIB, and thus, install_share. Blank them if they exist
+    $makefile =~ s/^PERL_LIB = .+/PERL_LIB =/m;
+    #$makefile =~ s/^PERL_ARCHLIB = .+/PERL_ARCHLIB =/m;
+
+    # Perl 5.005 mentions PERL_LIB explicitly, so we have to remove that as well.
+    $makefile =~ s/("?)-I\$\(PERL_LIB\)\1//g;
+
+    # XXX - This is currently unused; not sure if it breaks other MM-users
+    # $makefile =~ s/^pm_to_blib\s+:\s+/pm_to_blib :: /mg;
+
+    open  MAKEFILE, "> $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!";
+    print MAKEFILE  "$preamble$makefile$postamble" or die $!;
+    close MAKEFILE  or die $!;
+
+    1;
+}
+
+sub preamble {
+    my ($self, $text) = @_;
+    $self->{preamble} = $text . $self->{preamble} if defined $text;
+    $self->{preamble};
+}
+
+sub postamble {
+    my ($self, $text) = @_;
+    $self->{postamble} ||= $self->admin->postamble;
+    $self->{postamble} .= $text if defined $text;
+    $self->{postamble}
+}
+
+1;
+
+__END__
+
+#line 338

Added: trunk/owl/perl/modules/Jabber/inc/Module/Install/Metadata.pm
===================================================================
--- trunk/owl/perl/modules/Jabber/inc/Module/Install/Metadata.pm	                        (rev 0)
+++ trunk/owl/perl/modules/Jabber/inc/Module/Install/Metadata.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -0,0 +1,323 @@
+#line 1
+package Module::Install::Metadata;
+
+use strict 'vars';
+use Module::Install::Base;
+
+use vars qw{$VERSION $ISCORE @ISA};
+BEGIN {
+	$VERSION = '0.65';
+	$ISCORE  = 1;
+	@ISA     = qw{Module::Install::Base};
+}
+
+my @scalar_keys = qw{
+    name module_name abstract author version license
+    distribution_type perl_version tests installdirs
+};
+
+my @tuple_keys = qw{
+    build_requires requires recommends bundles
+};
+
+sub Meta            { shift        }
+sub Meta_ScalarKeys { @scalar_keys }
+sub Meta_TupleKeys  { @tuple_keys  }
+
+foreach my $key (@scalar_keys) {
+    *$key = sub {
+        my $self = shift;
+        return $self->{values}{$key} if defined wantarray and !@_;
+        $self->{values}{$key} = shift;
+        return $self;
+    };
+}
+
+foreach my $key (@tuple_keys) {
+    *$key = sub {
+        my $self = shift;
+        return $self->{values}{$key} unless @_;
+
+        my @rv;
+        while (@_) {
+            my $module = shift or last;
+            my $version = shift || 0;
+            if ( $module eq 'perl' ) {
+                $version =~ s{^(\d+)\.(\d+)\.(\d+)}
+                             {$1 + $2/1_000 + $3/1_000_000}e;
+                $self->perl_version($version);
+                next;
+            }
+            my $rv = [ $module, $version ];
+            push @rv, $rv;
+        }
+        push @{ $self->{values}{$key} }, @rv;
+        @rv;
+    };
+}
+
+sub install_as_core   { $_[0]->installdirs('perl')   }
+sub install_as_cpan   { $_[0]->installdirs('site')   }
+sub install_as_site   { $_[0]->installdirs('site')   }
+sub install_as_vendor { $_[0]->installdirs('vendor') }
+
+sub sign {
+    my $self = shift;
+    return $self->{'values'}{'sign'} if defined wantarray and !@_;
+    $self->{'values'}{'sign'} = ( @_ ? $_[0] : 1 );
+    return $self;
+}
+
+sub dynamic_config {
+	my $self = shift;
+	unless ( @_ ) {
+		warn "You MUST provide an explicit true/false value to dynamic_config, skipping\n";
+		return $self;
+	}
+	$self->{'values'}{'dynamic_config'} = $_[0] ? 1 : 0;
+	return $self;
+}
+
+sub all_from {
+    my ( $self, $file ) = @_;
+
+    unless ( defined($file) ) {
+        my $name = $self->name
+            or die "all_from called with no args without setting name() first";
+        $file = join('/', 'lib', split(/-/, $name)) . '.pm';
+        $file =~ s{.*/}{} unless -e $file;
+        die "all_from: cannot find $file from $name" unless -e $file;
+    }
+
+    $self->version_from($file)      unless $self->version;
+    $self->perl_version_from($file) unless $self->perl_version;
+
+    # The remaining probes read from POD sections; if the file
+    # has an accompanying .pod, use that instead
+    my $pod = $file;
+    if ( $pod =~ s/\.pm$/.pod/i and -e $pod ) {
+        $file = $pod;
+    }
+
+    $self->author_from($file)   unless $self->author;
+    $self->license_from($file)  unless $self->license;
+    $self->abstract_from($file) unless $self->abstract;
+}
+
+sub provides {
+    my $self     = shift;
+    my $provides = ( $self->{values}{provides} ||= {} );
+    %$provides = (%$provides, @_) if @_;
+    return $provides;
+}
+
+sub auto_provides {
+    my $self = shift;
+    return $self unless $self->is_admin;
+
+    unless (-e 'MANIFEST') {
+        warn "Cannot deduce auto_provides without a MANIFEST, skipping\n";
+        return $self;
+    }
+
+    # Avoid spurious warnings as we are not checking manifest here.
+
+    local $SIG{__WARN__} = sub {1};
+    require ExtUtils::Manifest;
+    local *ExtUtils::Manifest::manicheck = sub { return };
+
+    require Module::Build;
+    my $build = Module::Build->new(
+        dist_name    => $self->name,
+        dist_version => $self->version,
+        license      => $self->license,
+    );
+    $self->provides(%{ $build->find_dist_packages || {} });
+}
+
+sub feature {
+    my $self     = shift;
+    my $name     = shift;
+    my $features = ( $self->{values}{features} ||= [] );
+
+    my $mods;
+
+    if ( @_ == 1 and ref( $_[0] ) ) {
+        # The user used ->feature like ->features by passing in the second
+        # argument as a reference.  Accomodate for that.
+        $mods = $_[0];
+    } else {
+        $mods = \@_;
+    }
+
+    my $count = 0;
+    push @$features, (
+        $name => [
+            map {
+                ref($_) ? ( ref($_) eq 'HASH' ) ? %$_
+                                                : @$_
+                        : $_
+            } @$mods
+        ]
+    );
+
+    return @$features;
+}
+
+sub features {
+    my $self = shift;
+    while ( my ( $name, $mods ) = splice( @_, 0, 2 ) ) {
+        $self->feature( $name, @$mods );
+    }
+    return $self->{values}->{features}
+    	? @{ $self->{values}->{features} }
+    	: ();
+}
+
+sub no_index {
+    my $self = shift;
+    my $type = shift;
+    push @{ $self->{values}{no_index}{$type} }, @_ if $type;
+    return $self->{values}{no_index};
+}
+
+sub read {
+    my $self = shift;
+    $self->include_deps( 'YAML', 0 );
+
+    require YAML;
+    my $data = YAML::LoadFile('META.yml');
+
+    # Call methods explicitly in case user has already set some values.
+    while ( my ( $key, $value ) = each %$data ) {
+        next unless $self->can($key);
+        if ( ref $value eq 'HASH' ) {
+            while ( my ( $module, $version ) = each %$value ) {
+                $self->can($key)->($self, $module => $version );
+            }
+        }
+        else {
+            $self->can($key)->($self, $value);
+        }
+    }
+    return $self;
+}
+
+sub write {
+    my $self = shift;
+    return $self unless $self->is_admin;
+    $self->admin->write_meta;
+    return $self;
+}
+
+sub version_from {
+    my ( $self, $file ) = @_;
+    require ExtUtils::MM_Unix;
+    $self->version( ExtUtils::MM_Unix->parse_version($file) );
+}
+
+sub abstract_from {
+    my ( $self, $file ) = @_;
+    require ExtUtils::MM_Unix;
+    $self->abstract(
+        bless(
+            { DISTNAME => $self->name },
+            'ExtUtils::MM_Unix'
+        )->parse_abstract($file)
+     );
+}
+
+sub _slurp {
+    my ( $self, $file ) = @_;
+
+    local *FH;
+    open FH, "< $file" or die "Cannot open $file.pod: $!";
+    do { local $/; <FH> };
+}
+
+sub perl_version_from {
+    my ( $self, $file ) = @_;
+
+    if (
+        $self->_slurp($file) =~ m/
+        ^
+        use \s*
+        v?
+        ([\d_\.]+)
+        \s* ;
+    /ixms
+      )
+    {
+        my $v = $1;
+        $v =~ s{_}{}g;
+        $self->perl_version($1);
+    }
+    else {
+        warn "Cannot determine perl version info from $file\n";
+        return;
+    }
+}
+
+sub author_from {
+    my ( $self, $file ) = @_;
+    my $content = $self->_slurp($file);
+    if ($content =~ m/
+        =head \d \s+ (?:authors?)\b \s*
+        ([^\n]*)
+        |
+        =head \d \s+ (?:licen[cs]e|licensing|copyright|legal)\b \s*
+        .*? copyright .*? \d\d\d[\d.]+ \s* (?:\bby\b)? \s*
+        ([^\n]*)
+    /ixms) {
+        my $author = $1 || $2;
+        $author =~ s{E<lt>}{<}g;
+        $author =~ s{E<gt>}{>}g;
+        $self->author($author); 
+    }
+    else {
+        warn "Cannot determine author info from $file\n";
+    }
+}
+
+sub license_from {
+    my ( $self, $file ) = @_;
+
+    if (
+        $self->_slurp($file) =~ m/
+        (
+            =head \d \s+
+            (?:licen[cs]e|licensing|copyright|legal)\b
+            .*?
+        )
+        (=head\\d.*|=cut.*|)
+        \z
+    /ixms
+      )
+    {
+        my $license_text = $1;
+        my @phrases      = (
+            'under the same (?:terms|license) as perl itself' => 'perl',
+            'GNU public license'                              => 'gpl',
+            'GNU lesser public license'                       => 'gpl',
+            'BSD license'                                     => 'bsd',
+            'Artistic license'                                => 'artistic',
+            'GPL'                                             => 'gpl',
+            'LGPL'                                            => 'lgpl',
+            'BSD'                                             => 'bsd',
+            'Artistic'                                        => 'artistic',
+            'MIT'                                             => 'MIT',
+        );
+        while ( my ( $pattern, $license ) = splice( @phrases, 0, 2 ) ) {
+            $pattern =~ s{\s+}{\\s+}g;
+            if ( $license_text =~ /\b$pattern\b/i ) {
+                $self->license($license);
+                return 1;
+            }
+        }
+    }
+
+    warn "Cannot determine license info from $file\n";
+    return 'unknown';
+}
+
+1;

Added: trunk/owl/perl/modules/Jabber/inc/Module/Install/Win32.pm
===================================================================
--- trunk/owl/perl/modules/Jabber/inc/Module/Install/Win32.pm	                        (rev 0)
+++ trunk/owl/perl/modules/Jabber/inc/Module/Install/Win32.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -0,0 +1,65 @@
+#line 1
+package Module::Install::Win32;
+
+use strict;
+use Module::Install::Base;
+
+use vars qw{$VERSION $ISCORE @ISA};
+BEGIN {
+	$VERSION = '0.65';
+	$ISCORE  = 1;
+	@ISA     = qw{Module::Install::Base};
+}
+
+# determine if the user needs nmake, and download it if needed
+sub check_nmake {
+	my $self = shift;
+	$self->load('can_run');
+	$self->load('get_file');
+	
+	require Config;
+	return unless (
+		$^O eq 'MSWin32'                     and
+		$Config::Config{make}                and
+		$Config::Config{make} =~ /^nmake\b/i and
+		! $self->can_run('nmake')
+	);
+
+	print "The required 'nmake' executable not found, fetching it...\n";
+
+	require File::Basename;
+	my $rv = $self->get_file(
+		url       => 'http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe',
+		ftp_url   => 'ftp://ftp.microsoft.com/Softlib/MSLFILES/Nmake15.exe',
+		local_dir => File::Basename::dirname($^X),
+		size      => 51928,
+		run       => 'Nmake15.exe /o > nul',
+		check_for => 'Nmake.exe',
+		remove    => 1,
+	);
+
+	if (!$rv) {
+        die <<'END_MESSAGE';
+
+-------------------------------------------------------------------------------
+
+Since you are using Microsoft Windows, you will need the 'nmake' utility
+before installation. It's available at:
+
+  http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe
+      or
+  ftp://ftp.microsoft.com/Softlib/MSLFILES/Nmake15.exe
+
+Please download the file manually, save it to a directory in %PATH% (e.g.
+C:\WINDOWS\COMMAND\), then launch the MS-DOS command line shell, "cd" to
+that directory, and run "Nmake15.exe" from there; that will create the
+'nmake.exe' file needed by this module.
+
+You may then resume the installation process described in README.
+
+-------------------------------------------------------------------------------
+END_MESSAGE
+	}
+}
+
+1;

Added: trunk/owl/perl/modules/Jabber/inc/Module/Install/WriteAll.pm
===================================================================
--- trunk/owl/perl/modules/Jabber/inc/Module/Install/WriteAll.pm	                        (rev 0)
+++ trunk/owl/perl/modules/Jabber/inc/Module/Install/WriteAll.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -0,0 +1,43 @@
+#line 1
+package Module::Install::WriteAll;
+
+use strict;
+use Module::Install::Base;
+
+use vars qw{$VERSION $ISCORE @ISA};
+BEGIN {
+	$VERSION = '0.65';
+	$ISCORE  = 1;
+	@ISA     = qw{Module::Install::Base};
+}
+
+sub WriteAll {
+    my $self = shift;
+    my %args = (
+        meta        => 1,
+        sign        => 0,
+        inline      => 0,
+        check_nmake => 1,
+        @_
+    );
+
+    $self->sign(1)                if $args{sign};
+    $self->Meta->write            if $args{meta};
+    $self->admin->WriteAll(%args) if $self->is_admin;
+
+    if ( $0 =~ /Build.PL$/i ) {
+        $self->Build->write;
+    } else {
+        $self->check_nmake if $args{check_nmake};
+        unless ( $self->makemaker_args->{'PL_FILES'} ) {
+        	$self->makemaker_args( PL_FILES => {} );
+        }
+        if ($args{inline}) {
+            $self->Inline->write;
+        } else {
+            $self->Makefile->write;
+        }
+    }
+}
+
+1;

Added: trunk/owl/perl/modules/Jabber/inc/Module/Install.pm
===================================================================
--- trunk/owl/perl/modules/Jabber/inc/Module/Install.pm	                        (rev 0)
+++ trunk/owl/perl/modules/Jabber/inc/Module/Install.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -0,0 +1,281 @@
+#line 1
+package Module::Install;
+
+# For any maintainers:
+# The load order for Module::Install is a bit magic.
+# It goes something like this...
+#
+# IF ( host has Module::Install installed, creating author mode ) {
+#     1. Makefile.PL calls "use inc::Module::Install"
+#     2. $INC{inc/Module/Install.pm} set to installed version of inc::Module::Install
+#     3. The installed version of inc::Module::Install loads
+#     4. inc::Module::Install calls "require Module::Install"
+#     5. The ./inc/ version of Module::Install loads
+# } ELSE {
+#     1. Makefile.PL calls "use inc::Module::Install"
+#     2. $INC{inc/Module/Install.pm} set to ./inc/ version of Module::Install
+#     3. The ./inc/ version of Module::Install loads
+# }
+
+use 5.004;
+use strict 'vars';
+
+use vars qw{$VERSION};
+BEGIN {
+    # All Module::Install core packages now require synchronised versions.
+    # This will be used to ensure we don't accidentally load old or
+    # different versions of modules.
+    # This is not enforced yet, but will be some time in the next few
+    # releases once we can make sure it won't clash with custom
+    # Module::Install extensions.
+    $VERSION = '0.65';
+}
+
+# Whether or not inc::Module::Install is actually loaded, the
+# $INC{inc/Module/Install.pm} is what will still get set as long as
+# the caller loaded module this in the documented manner.
+# If not set, the caller may NOT have loaded the bundled version, and thus
+# they may not have a MI version that works with the Makefile.PL. This would
+# result in false errors or unexpected behaviour. And we don't want that.
+my $file = join( '/', 'inc', split /::/, __PACKAGE__ ) . '.pm';
+unless ( $INC{$file} ) {
+    die <<"END_DIE";
+Please invoke ${\__PACKAGE__} with:
+
+    use inc::${\__PACKAGE__};
+
+not:
+
+    use ${\__PACKAGE__};
+
+END_DIE
+}
+
+# If the script that is loading Module::Install is from the future,
+# then make will detect this and cause it to re-run over and over
+# again. This is bad. Rather than taking action to touch it (which
+# is unreliable on some platforms and requires write permissions)
+# for now we should catch this and refuse to run.
+if ( -f $0 and (stat($0))[9] > time ) {
+	die << "END_DIE";
+Your installer $0 has a modification time in the future.
+
+This is known to create infinite loops in make.
+
+Please correct this, then run $0 again.
+
+END_DIE
+}
+
+use Cwd        ();
+use File::Find ();
+use File::Path ();
+use FindBin;
+
+*inc::Module::Install::VERSION = *VERSION;
+@inc::Module::Install::ISA     = __PACKAGE__;
+
+sub autoload {
+    my $self = shift;
+    my $who  = $self->_caller;
+    my $cwd  = Cwd::cwd();
+    my $sym  = "${who}::AUTOLOAD";
+    $sym->{$cwd} = sub {
+        my $pwd = Cwd::cwd();
+        if ( my $code = $sym->{$pwd} ) {
+            # delegate back to parent dirs
+            goto &$code unless $cwd eq $pwd;
+        }
+        $$sym =~ /([^:]+)$/ or die "Cannot autoload $who - $sym";
+        unshift @_, ($self, $1);
+        goto &{$self->can('call')} unless uc($1) eq $1;
+    };
+}
+
+sub import {
+    my $class = shift;
+    my $self  = $class->new(@_);
+    my $who   = $self->_caller;
+
+    unless ( -f $self->{file} ) {
+        require "$self->{path}/$self->{dispatch}.pm";
+        File::Path::mkpath("$self->{prefix}/$self->{author}");
+        $self->{admin} = "$self->{name}::$self->{dispatch}"->new( _top => $self );
+        $self->{admin}->init;
+        @_ = ($class, _self => $self);
+        goto &{"$self->{name}::import"};
+    }
+
+    *{"${who}::AUTOLOAD"} = $self->autoload;
+    $self->preload;
+
+    # Unregister loader and worker packages so subdirs can use them again
+    delete $INC{"$self->{file}"};
+    delete $INC{"$self->{path}.pm"};
+}
+
+sub preload {
+    my ($self) = @_;
+
+    unless ( $self->{extensions} ) {
+        $self->load_extensions(
+            "$self->{prefix}/$self->{path}", $self
+        );
+    }
+
+    my @exts = @{$self->{extensions}};
+    unless ( @exts ) {
+        my $admin = $self->{admin};
+        @exts = $admin->load_all_extensions;
+    }
+
+    my %seen;
+    foreach my $obj ( @exts ) {
+        while (my ($method, $glob) = each %{ref($obj) . '::'}) {
+            next unless $obj->can($method);
+            next if $method =~ /^_/;
+            next if $method eq uc($method);
+            $seen{$method}++;
+        }
+    }
+
+    my $who = $self->_caller;
+    foreach my $name ( sort keys %seen ) {
+        *{"${who}::$name"} = sub {
+            ${"${who}::AUTOLOAD"} = "${who}::$name";
+            goto &{"${who}::AUTOLOAD"};
+        };
+    }
+}
+
+sub new {
+    my ($class, %args) = @_;
+
+    # ignore the prefix on extension modules built from top level.
+    my $base_path = Cwd::abs_path($FindBin::Bin);
+    unless ( Cwd::abs_path(Cwd::cwd()) eq $base_path ) {
+        delete $args{prefix};
+    }
+
+    return $args{_self} if $args{_self};
+
+    $args{dispatch} ||= 'Admin';
+    $args{prefix}   ||= 'inc';
+    $args{author}   ||= ($^O eq 'VMS' ? '_author' : '.author');
+    $args{bundle}   ||= 'inc/BUNDLES';
+    $args{base}     ||= $base_path;
+    $class =~ s/^\Q$args{prefix}\E:://;
+    $args{name}     ||= $class;
+    $args{version}  ||= $class->VERSION;
+    unless ( $args{path} ) {
+        $args{path}  = $args{name};
+        $args{path}  =~ s!::!/!g;
+    }
+    $args{file}     ||= "$args{base}/$args{prefix}/$args{path}.pm";
+
+    bless( \%args, $class );
+}
+
+sub call {
+	my ($self, $method) = @_;
+	my $obj = $self->load($method) or return;
+        splice(@_, 0, 2, $obj);
+	goto &{$obj->can($method)};
+}
+
+sub load {
+    my ($self, $method) = @_;
+
+    $self->load_extensions(
+        "$self->{prefix}/$self->{path}", $self
+    ) unless $self->{extensions};
+
+    foreach my $obj (@{$self->{extensions}}) {
+        return $obj if $obj->can($method);
+    }
+
+    my $admin = $self->{admin} or die <<"END_DIE";
+The '$method' method does not exist in the '$self->{prefix}' path!
+Please remove the '$self->{prefix}' directory and run $0 again to load it.
+END_DIE
+
+    my $obj = $admin->load($method, 1);
+    push @{$self->{extensions}}, $obj;
+
+    $obj;
+}
+
+sub load_extensions {
+    my ($self, $path, $top) = @_;
+
+    unless ( grep { lc $_ eq lc $self->{prefix} } @INC ) {
+        unshift @INC, $self->{prefix};
+    }
+
+    foreach my $rv ( $self->find_extensions($path) ) {
+        my ($file, $pkg) = @{$rv};
+        next if $self->{pathnames}{$pkg};
+
+        local $@;
+        my $new = eval { require $file; $pkg->can('new') };
+        unless ( $new ) {
+            warn $@ if $@;
+            next;
+        }
+        $self->{pathnames}{$pkg} = delete $INC{$file};
+        push @{$self->{extensions}}, &{$new}($pkg, _top => $top );
+    }
+
+    $self->{extensions} ||= [];
+}
+
+sub find_extensions {
+    my ($self, $path) = @_;
+
+    my @found;
+    File::Find::find( sub {
+        my $file = $File::Find::name;
+        return unless $file =~ m!^\Q$path\E/(.+)\.pm\Z!is;
+        my $subpath = $1;
+        return if lc($subpath) eq lc($self->{dispatch});
+
+        $file = "$self->{path}/$subpath.pm";
+        my $pkg = "$self->{name}::$subpath";
+        $pkg =~ s!/!::!g;
+
+        # If we have a mixed-case package name, assume case has been preserved
+        # correctly.  Otherwise, root through the file to locate the case-preserved
+        # version of the package name.
+        if ( $subpath eq lc($subpath) || $subpath eq uc($subpath) ) {
+            open PKGFILE, "<$subpath.pm" or die "find_extensions: Can't open $subpath.pm: $!";
+            my $in_pod = 0;
+            while ( <PKGFILE> ) {
+                $in_pod = 1 if /^=\w/;
+                $in_pod = 0 if /^=cut/;
+                next if ($in_pod || /^=cut/);  # skip pod text
+                next if /^\s*#/;               # and comments
+                if ( m/^\s*package\s+($pkg)\s*;/i ) {
+                    $pkg = $1;
+                    last;
+                }
+            }
+            close PKGFILE;
+        }
+
+        push @found, [ $file, $pkg ];
+    }, $path ) if -d $path;
+
+    @found;
+}
+
+sub _caller {
+    my $depth = 0;
+    my $call  = caller($depth);
+    while ( $call eq __PACKAGE__ ) {
+        $depth++;
+        $call = caller($depth);
+    }
+    return $call;
+}
+
+1;

Added: trunk/owl/perl/modules/Jabber/lib/BarnOwl/Message/Jabber.pm
===================================================================
--- trunk/owl/perl/modules/Jabber/lib/BarnOwl/Message/Jabber.pm	                        (rev 0)
+++ trunk/owl/perl/modules/Jabber/lib/BarnOwl/Message/Jabber.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -0,0 +1,89 @@
+use warnings;
+use strict;
+
+=head1 NAME
+
+BarnOwl::Message::Jabber
+
+=head1 DESCRIPTION
+
+A subclass of BarnOwl::Message for Jabber messages
+
+=cut
+
+package BarnOwl::Message::Jabber;
+
+use base qw( BarnOwl::Message );
+
+sub jtype { shift->{jtype} };
+sub from { shift->{from} };
+sub to { shift->{to} };
+sub room { shift->{room} };
+sub status { shift->{status} }
+
+sub login_extra {
+    my $self = shift;
+    my $show = $self->{show};
+    my $status = $self->status;
+    my $s = "";
+    $s .= $show if $show;
+    $s .= ", $status" if $status;
+    return $s;
+}
+
+sub long_sender {
+    my $self = shift;
+    return $self->from;
+}
+
+sub context {
+    return shift->room;
+}
+
+sub smartfilter {
+    my $self = shift;
+    my $inst = shift;
+
+    my ($filter, $ftext);
+
+    if($self->jtype eq 'chat') {
+        my $user;
+        if($self->direction eq 'in') {
+            $user = $self->from;
+        } else {
+            $user = $self->to;
+        }
+        return smartfilter_user($user, $inst);
+    } elsif ($self->jtype eq 'groupchat') {
+        my $room = $self->room;
+        $filter = "jabber-room-$room";
+        $ftext = qq{type ^jabber\$ and room ^$room\$};
+        BarnOwl::filter("$filter $ftext");
+        return $filter;
+    } elsif ($self->login ne 'none') {
+        return smartfilter_user($self->from, $inst);
+    }
+}
+
+sub smartfilter_user {
+    my $user = shift;
+    my $inst = shift;
+
+    $user   = Net::Jabber::JID->new($user)->GetJID( $inst ? 'full' : 'base' );
+    my $filter = "jabber-user-$user";
+    my $ftext  =
+        qq{type ^jabber\$ and ( ( direction ^in\$ and from ^$user ) }
+      . qq{or ( direction ^out\$ and to ^$user ) ) };
+    BarnOwl::filter("$filter $ftext");
+    return $filter;
+
+}
+
+
+=head1 SEE ALSO
+
+L<BarnOwl::Message>
+
+=cut
+
+1;

Added: trunk/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber/Connection.pm
===================================================================
--- trunk/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber/Connection.pm	                        (rev 0)
+++ trunk/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber/Connection.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -0,0 +1,112 @@
+use warnings;
+use strict;
+
+=head1 NAME
+
+BarnOwl::Module::Jabber::Connection
+
+=head1 DESCRIPTION
+
+A subclass of L<Net::Jabber::Client> used in the BarnOwl jabber module
+
+=cut
+
+package BarnOwl::Module::Jabber::Connection;
+
+use base qw(Net::Jabber::Client);
+
+use Net::Jabber;
+
+sub new {
+    my $class = shift;
+
+    my %args = ();
+    if(BarnOwl::getvar('debug') eq 'on') {
+        $args{debuglevel} = 1;
+        $args{debugfile} = 'jabber.log';
+    }
+    my $self = $class->SUPER::new(%args);
+    $self->{_BARNOWL_MUCS} = [];
+    return $self;
+}
+
+=head2 MUCJoin
+
+Extends MUCJoin to keep track of the MUCs we're joined to as
+Net::Jabber::MUC objects. Takes the same arguments as
+L<Net::Jabber::MUC/new> and L<Net::Jabber::MUC/Connect>
+
+=cut
+
+sub MUCJoin {
+    my $self = shift;
+    my $muc = Net::Jabber::MUC->new(connection => $self, @_);
+    $muc->Join(@_);
+    push @{$self->MUCs}, $muc;
+}
+
+=head2 MUCLeave ARGS
+
+Leave a MUC. The MUC is specified in the same form as L</FindMUC>
+
+=cut
+
+sub MUCLeave {
+    my $self = shift;
+    my $muc = $self->FindMUC(@_);
+    return unless $muc;
+
+    $muc->Leave();
+    $self->{_BARNOWL_MUCS} = [grep {$_->BaseJID ne $muc->BaseJID} $self->MUCs];
+}
+
+=head2 FindMUC ARGS
+
+Return the Net::Jabber::MUC object representing a specific MUC we're
+joined to, undef if it doesn't exists. ARGS can be either JID => $JID,
+or Room => $room, Server => $server.
+
+=cut
+
+sub FindMUC {
+    my $self = shift;
+
+    my %args;
+    while($#_ >= 0) { $args{ lc(pop(@_)) } = pop(@_); }
+
+    my $jid;
+    if($args{jid}) {
+        $jid = $args{jid};
+    } elsif($args{room} && $args{server}) {
+        $jid = Net::Jabber::JID->new(userid => $args{room},
+                                     server => $args{server});
+    }
+    $jid = $jid->GetJID('base') if UNIVERSAL::isa($jid, 'Net::XMPP::JID');
+
+    foreach my $muc ($self->MUCs) {
+        return $muc if $muc->BaseJID eq $jid;
+    }
+    return undef;
+}
+
+=head2 MUCs
+
+Returns a list (or arrayref in scalar context) of Net::Jabber::MUC
+objects we believe ourself to be connected to.
+
+=cut
+
+sub MUCs {
+    my $self = shift;
+    my $mucs = $self->{_BARNOWL_MUCS};
+    return wantarray ? @$mucs : $mucs;
+}
+
+
+=head1 SEE ALSO
+
+L<Net::Jabber::Client>, L<BarnOwl::Module::Jabber>
+
+=cut
+
+1;

Added: trunk/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber/ConnectionManager.pm
===================================================================
--- trunk/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber/ConnectionManager.pm	                        (rev 0)
+++ trunk/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber/ConnectionManager.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -0,0 +1,105 @@
+use warnings;
+use strict;
+
+=head1 NAME
+
+BarnOwl::Module::Jabber::ConnectionManager
+
+=head1 DESCRIPTION
+
+A class to keep track of all the active connection in the barnowl
+jabber module
+
+=cut
+
+package BarnOwl::Module::Jabber::ConnectionManager;
+
+sub new {
+    my $class = shift;
+    return bless { }, $class;
+}
+
+sub addConnection {
+    my $self = shift;
+    my $jidStr = shift;
+
+    my $client = BarnOwl::Module::Jabber::Connection->new;
+
+    $self->{$jidStr}->{Client} = $client;
+    $self->{$jidStr}->{Roster} = $client->Roster();
+    $self->{$jidStr}->{Status} = "available";
+    return $client;
+}
+
+sub removeConnection {
+    my $self = shift;
+    my $jidStr = shift;
+    return 0 unless exists $self->{$jidStr};
+
+    $self->{$jidStr}->{Client}->Disconnect()
+      if $self->{$jidStr}->{Client};
+    delete $self->{$jidStr};
+
+    return 1;
+}
+
+sub connected {
+    my $self = shift;
+    return scalar keys %{ $self };
+}
+
+sub getJIDs {
+    my $self = shift;
+    return keys %{ $self };
+}
+
+sub jidExists {
+    my $self = shift;
+    my $jidStr = shift;
+    return exists $self->{$jidStr};
+}
+
+sub sidExists {
+    my $self = shift;
+    my $sid = shift || "";
+    foreach my $c ( values %{ $self } ) {
+        return 1 if ($c->{Client}->{SESSION}->{id} eq $sid);
+    }
+    return 0;
+}
+
+sub getConnectionFromSid {
+    my $self = shift;
+    my $sid = shift;
+    foreach my $c (values %{ $self }) {
+        return $c->{Client} if $c->{Client}->{SESSION}->{id} eq $sid;
+    }
+    return undef;
+}
+
+sub getConnectionFromJID {
+    my $self = shift;
+    my $jid = shift;
+    $jid = $jid->GetJID('full') if UNIVERSAL::isa($jid, 'Net::XMPP::JID');
+    return $self->{$jid}->{Client} if exists $self->{$jid};
+}
+
+sub getRosterFromSid {
+    my $self = shift;
+    my $sid = shift;
+    foreach my $c (values %{ $self }) {
+        return $c->{Roster}
+          if $c->{Client}->{SESSION}->{id} eq $sid;
+    }
+    return undef;
+}
+
+sub getRosterFromJID {
+    my $self = shift;
+    my $jid = shift;
+    $jid = $jid->GetJID('full') if UNIVERSAL::isa($jid, 'Net::XMPP::JID');
+    return $self->{$jid}->{Roster} if exists $self->{$jid};
+}
+
+
+1;

Added: trunk/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm
===================================================================
--- trunk/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm	                        (rev 0)
+++ trunk/owl/perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -0,0 +1,1278 @@
+use strict;
+use warnings;
+
+package BarnOwl::Module::Jabber;
+
+=head1 NAME
+
+BarnOwl::Module::Jabber
+
+=head1 DESCRIPTION
+
+This module implements Jabber support for barnowl.
+
+=cut
+
+use BarnOwl;
+use BarnOwl::Hooks;
+use BarnOwl::Message::Jabber;
+use BarnOwl::Module::Jabber::Connection;
+use BarnOwl::Module::Jabber::ConnectionManager;
+
+use Authen::SASL qw(Perl);
+use Net::Jabber;
+use Net::Jabber::MUC;
+use Net::DNS;
+use Getopt::Long;
+
+our $VERSION = 0.1;
+
+BEGIN {
+    if(eval {require IO::Socket::SSL;}) {
+        if($IO::Socket::SSL::VERSION eq "0.97") {
+            BarnOwl::error("You are using IO::Socket:SSL 0.97, which \n" .
+                           "contains bugs causing it not to work with barnowl's jabber.pl. We \n" .
+                           "recommend updating to the latest IO::Socket::SSL from CPAN. \n");
+            die("Not loading jabber.pl\n");
+        }
+    }       
+}
+
+no warnings 'redefine';
+
+################################################################################
+# owl perl jabber support
+#
+# XXX Todo:
+# Rosters for MUCs
+# More user feedback
+#  * joining MUC
+#  * parting MUC
+#  * presence (Roster and MUC)
+# Implementing formatting and logging callbacks for C
+# Appropriate callbacks for presence subscription messages.
+#
+################################################################################
+
+our $conn = BarnOwl::Module::Jabber::ConnectionManager->new unless $conn;;
+our %vars;
+
+sub onStart {
+    if ( *BarnOwl::queue_message{CODE} ) {
+        register_owl_commands();
+        register_keybindings();
+        register_filters();
+        $BarnOwl::Hooks::mainLoop->add(\&onMainLoop);
+        $BarnOwl::Hooks::getBuddyList->add(\&onGetBuddyList);
+        $vars{show} = '';
+    } else {
+        # Our owl doesn't support queue_message. Unfortunately, this
+        # means it probably *also* doesn't support BarnOwl::error. So just
+        # give up silently.
+    }
+}
+
+$BarnOwl::Hooks::startup->add(\&onStart);
+
+sub onMainLoop {
+    return if ( !$conn->connected() );
+
+    $vars{status_changed} = 0;
+    my $idletime = BarnOwl::getidletime();
+    if ($idletime >= 900 && $vars{show} eq 'away') {
+        $vars{show} = 'xa';
+        $vars{status} = 'Auto extended-away after 15 minutes idle.';
+        $vars{status_changed} = 1;
+    } elsif ($idletime >= 300 && $vars{show} eq '') {
+        $vars{show} = 'away';
+        $vars{status} = 'Auto away after 5 minutes idle.';
+        $vars{status_changed} = 1;
+    } elsif ($idletime == 0 && $vars{show} ne '') {
+        $vars{show} = '';
+        $vars{status} = '';
+        $vars{status_changed} = 1;
+    }
+
+    foreach my $jid ( $conn->getJIDs() ) {
+        my $client = $conn->getConnectionFromJID($jid);
+
+        unless($client) {
+            $conn->removeConnection($jid);
+            BarnOwl::error("Connection for $jid undefined -- error in reload?");
+        }
+
+        my $status = $client->Process(0);
+        if ( !defined($status) ) {
+            BarnOwl::error("Jabber account $jid disconnected!");
+            do_logout($jid);
+        }
+        if ($::shutdown) {
+            do_logout($jid);
+            return;
+        }
+        if ($vars{status_changed}) {
+            my $p = new Net::Jabber::Presence;
+            $p->SetShow($vars{show}) if $vars{show};
+            $p->SetStatus($vars{status}) if $vars{status};
+            $client->Send($p);
+        }
+    }
+}
+
+sub blist_listBuddy {
+    my $roster = shift;
+    my $buddy  = shift;
+    my $blistStr .= "    ";
+    my %jq  = $roster->query($buddy);
+    my $res = $roster->resource($buddy);
+
+    my $name = $jq{name} || $buddy->GetUserID();
+
+    $blistStr .= sprintf '%-15s %s', $name, $buddy->GetJID();
+
+    if ($res) {
+        my %rq = $roster->resourceQuery( $buddy, $res );
+        $blistStr .= " [" . ( $rq{show} ? $rq{show} : 'online' ) . "]";
+        $blistStr .= " " . $rq{status} if $rq{status};
+        $blistStr = BarnOwl::Style::boldify($blistStr);
+    }
+    else {
+	if ($jq{ask}) {
+            $blistStr .= " [pending]";
+	}
+	elsif ($jq{subscription} eq 'none' || $jq{subscription} eq 'from') {
+	    $blistStr .= " [not subscribed]";
+	}
+	else {
+	    $blistStr .= " [offline]";
+	}
+    }
+    return $blistStr . "\n";
+}
+
+sub getSingleBuddyList {
+    my $jid = shift;
+    $jid = resolveConnectedJID($jid);
+    return "" unless $jid;
+    my $blist = "";
+    my $roster = $conn->getRosterFromJID($jid);
+    if ($roster) {
+        $blist .= "\n" . BarnOwl::Style::boldify("Jabber Roster for $jid\n");
+
+        foreach my $group ( $roster->groups() ) {
+            $blist .= "  Group: $group\n";
+            my @buddies = $roster->jids( 'group', $group );
+            foreach my $buddy ( @buddies ) {
+                $blist .= blist_listBuddy( $roster, $buddy );
+            }
+        }
+
+        my @unsorted = $roster->jids('nogroup');
+        if (@unsorted) {
+            $blist .= "  [unsorted]\n";
+            foreach my $buddy (@unsorted) {
+                $blist .= blist_listBuddy( $roster, $buddy );
+            }
+        }
+    }
+    return $blist;
+}
+
+sub onGetBuddyList {
+    my $blist = "";
+    foreach my $jid ($conn->getJIDs()) {
+        $blist .= getSingleBuddyList($jid);
+    }
+    return $blist;
+}
+
+################################################################################
+### Owl Commands
+sub register_owl_commands() {
+    BarnOwl::new_command(
+        jabberlogin => \&cmd_login,
+        { summary => "Log into jabber", },
+        { usage   => "jabberlogin JID [PASSWORD]" }
+    );
+    BarnOwl::new_command(
+        jabberlogout => \&cmd_logout,
+        { summary => "Log out of jabber" }
+    );
+    BarnOwl::new_command(
+        jwrite => \&cmd_jwrite,
+        {
+            summary => "Send a Jabber Message",
+            usage   => "jwrite JID [-t thread] [-s subject]"
+        }
+    );
+    BarnOwl::new_command(
+        jlist => \&cmd_jlist,
+        {
+            summary => "Show your Jabber roster.",
+            usage   => "jlist"
+        }
+    );
+    BarnOwl::new_command(
+        jmuc => \&cmd_jmuc,
+        {
+            summary     => "Jabber MUC related commands.",
+            description => "jmuc sends jabber commands related to muc.\n\n"
+              . "The following commands are available\n\n"
+              . "join <muc>  Join a muc.\n\n"
+              . "part <muc>  Part a muc.\n"
+              . "            The muc is taken from the current message if not supplied.\n\n"
+              . "invite <jid> <muc>\n"
+              . "            Invite <jid> to <muc>.\n"
+              . "            The muc is taken from the current message if not supplied.\n\n"
+              . "configure <muc>\n"
+              . "            Configures a MUC.\n"
+              . "            Necessary to initalize a new MUC.\n"
+              . "            At present, only the default configuration is supported.\n"
+              . "            The muc is taken from the current message if not supplied.\n\n"
+              . "presence <muc>\n"
+              . "            Shows the roster for <muc>.\n"
+              . "            The muc is taken from the current message if not supplied.\n\n"
+              . "presence -a\n"
+              . "            Shows rosters for all MUCs you're participating in.\n\n",
+            usage => "jmuc COMMAND ARGS"
+        }
+    );
+    BarnOwl::new_command(
+        jroster => \&cmd_jroster,
+        {
+            summary     => "Jabber Roster related commands.",
+            description => "jroster sends jabber commands related to rosters.\n\n"
+              . "The following commands are available\n\n"
+              . "sub <jid>     Subscribe to <jid>'s presence. (implicit add)\n\n"
+              . "add <jid>     Adds <jid> to your roster.\n\n"
+              . "unsub <jid>   Unsubscribe from <jid>'s presence.\n\n"
+              . "remove <jid>  Removes <jid> to your roster. (implicit unsub)\n\n"
+              . "auth <jid>    Authorizes <jid> to subscribe to your presence.\n\n"
+              . "deauth <jid>  De-authorizes <jid>'s subscription to your presence.\n\n"
+              . "The following arguments are supported for all commands\n\n"
+              . "-a <jid>      Specify which account to make the roster changes on.\n"
+              . "              Required if you're signed into more than one account.\n\n"
+              . "The following arguments only work with the add and sub commands.\n\n"
+              . "-g <group>    Add <jid> to group <group>.\n"
+              . "              May be specified more than once, will not remove <jid> from any groups.\n\n"
+              . "-p            Purge. Removes <jid> from all groups.\n"
+              . "              May be combined with -g completely alter <jid>'s groups.\n\n"
+              . "-n <name>     Sets <name> as <jid>'s short name.\n\n"
+              . "Note: Unless -n is used, you can specify multiple <jid> arguments.\n",
+            usage       => "jroster COMMAND ARGS"
+        }
+    );
+}
+
+sub register_keybindings {
+    BarnOwl::bindkey("recv j command start-command jwrite ");
+}
+
+sub register_filters {
+    BarnOwl::filter('jabber type ^jabber$');
+}
+
+sub cmd_login {
+    my $cmd = shift;
+    my $jid = new Net::Jabber::JID;
+    $jid->SetJID(shift);
+    my $password = '';
+    $password = shift if @_;
+
+    my $uid           = $jid->GetUserID();
+    my $componentname = $jid->GetServer();
+    my $resource      = $jid->GetResource() || 'owl';
+    $jid->SetResource($resource);
+    my $jidStr = $jid->GetJID('full');
+
+    if ( !$uid || !$componentname ) {
+        BarnOwl::error("usage: $cmd JID");
+        return;
+    }
+
+    if ( $conn->jidExists($jidStr) ) {
+        BarnOwl::error("Already logged in as $jidStr.");
+        return;
+    }
+
+    my ( $server, $port ) = getServerFromJID($jid);
+
+    $vars{jlogin_jid} = $jidStr;
+    $vars{jlogin_connhash} = {
+        hostname      => $server,
+        tls           => 1,
+        port          => $port,
+        componentname => $componentname
+    };
+    $vars{jlogin_authhash} =
+      { username => $uid,
+        resource => $resource,
+    };
+
+    return do_login($password);
+}
+
+sub do_login {
+    $vars{jlogin_password} = shift;
+    $vars{jlogin_authhash}->{password} = sub { return $vars{jlogin_password} || '' };
+    my $jidStr = $vars{jlogin_jid};
+    if ( !$jidStr && $vars{jlogin_havepass}) {
+        BarnOwl::error("Got password but have no jid!");
+    }
+    else
+    {
+        my $client = $conn->addConnection($jidStr);
+
+        #XXX Todo: Add more callbacks.
+        # * MUC presence handlers
+        # We use the anonymous subrefs in order to have the correct behavior
+        # when we reload
+        $client->SetMessageCallBacks(
+            chat      => sub { BarnOwl::Module::Jabber::process_incoming_chat_message(@_) },
+            error     => sub { BarnOwl::Module::Jabber::process_incoming_error_message(@_) },
+            groupchat => sub { BarnOwl::Module::Jabber::process_incoming_groupchat_message(@_) },
+            headline  => sub { BarnOwl::Module::Jabber::process_incoming_headline_message(@_) },
+            normal    => sub { BarnOwl::Module::Jabber::process_incoming_normal_message(@_) }
+        );
+        $client->SetPresenceCallBacks(
+            available    => sub { BarnOwl::Module::Jabber::process_presence_available(@_) },
+            unavailable  => sub { BarnOwl::Module::Jabber::process_presence_available(@_) },
+            subscribe    => sub { BarnOwl::Module::Jabber::process_presence_subscribe(@_) },
+            subscribed   => sub { BarnOwl::Module::Jabber::process_presence_subscribed(@_) },
+            unsubscribe  => sub { BarnOwl::Module::Jabber::process_presence_unsubscribe(@_) },
+            unsubscribed => sub { BarnOwl::Module::Jabber::process_presence_unsubscribed(@_) },
+            error        => sub { BarnOwl::Module::Jabber::process_presence_error(@_) });
+
+        my $status = $client->Connect( %{ $vars{jlogin_connhash} } );
+        if ( !$status ) {
+            $conn->removeConnection($jidStr);
+            BarnOwl::error("We failed to connect");
+        } else {
+            my @result = $client->AuthSend( %{ $vars{jlogin_authhash} } );
+
+            if ( !@result || $result[0] ne 'ok' ) {
+                if ( !$vars{jlogin_havepass} && ( !@result || $result[0] eq '401' ) ) {
+                    $vars{jlogin_havepass} = 1;
+                    $conn->removeConnection($jidStr);
+                    BarnOwl::start_password( "Password for $jidStr: ", \&do_login );
+                    return "";
+                }
+                $conn->removeConnection($jidStr);
+                BarnOwl::error( "Error in connect: " . join( " ", @result ) );
+            } else {
+                $conn->getRosterFromJID($jidStr)->fetch();
+                $client->PresenceSend( priority => 1 );
+                queue_admin_msg("Connected to jabber as $jidStr");
+            }
+        }
+
+    }
+    delete $vars{jlogin_jid};
+    $vars{jlogin_password} =~ tr/\0-\377/x/ if $vars{jlogin_password};
+    delete $vars{jlogin_password};
+    delete $vars{jlogin_havepass};
+    delete $vars{jlogin_connhash};
+    delete $vars{jlogin_authhash};
+    return "";
+}
+
+sub do_logout {
+    my $jid = shift;
+    my $disconnected = $conn->removeConnection($jid);
+    queue_admin_msg("Jabber disconnected ($jid).") if $disconnected;
+}
+
+sub cmd_logout {
+    # Logged into multiple accounts
+    if ( $conn->connected() > 1 ) {
+        # Logged into multiple accounts, no accout specified.
+        if ( !$_[1] ) {
+            my $errStr =
+              "You are logged into multiple accounts. Please specify an account to log out of.\n";
+            foreach my $jid ( $conn->getJIDs() ) {
+                $errStr .= "\t$jid\n";
+            }
+            queue_admin_msg($errStr);
+        }
+        # Logged into multiple accounts, account specified.
+        else {
+            if ( $_[1] eq '-a' )    #All accounts.
+            {
+                foreach my $jid ( $conn->getJIDs() ) {
+                    do_logout($jid);
+                }
+            }
+            else                    #One account.
+            {
+                my $jid = resolveConnectedJID( $_[1] );
+                do_logout($jid) if ( $jid ne '' );
+            }
+        }
+    }
+    else                            # Only one account logged in.
+    {
+        do_logout( ( $conn->getJIDs() )[0] );
+    }
+    return "";
+}
+
+sub cmd_jlist {
+    if ( !( scalar $conn->getJIDs() ) ) {
+        BarnOwl::error("You are not logged in to Jabber.");
+        return;
+    }
+    BarnOwl::popless_ztext( onGetBuddyList() );
+}
+
+sub cmd_jwrite {
+    if ( !$conn->connected() ) {
+        BarnOwl::error("You are not logged in to Jabber.");
+        return;
+    }
+
+    my $jwrite_to      = "";
+    my $jwrite_from    = "";
+    my $jwrite_sid     = "";
+    my $jwrite_thread  = "";
+    my $jwrite_subject = "";
+    my ($to, $from);
+    my $jwrite_type    = "chat";
+
+    my @args = @_;
+    shift;
+    local @ARGV = @_;
+    my $gc;
+    GetOptions(
+        'thread=s'  => \$jwrite_thread,
+        'subject=s' => \$jwrite_subject,
+        'account=s' => \$from,
+        'id=s'     =>  \$jwrite_sid,
+    );
+    $jwrite_type = 'groupchat' if $gc;
+
+    if ( scalar @ARGV != 1 ) {
+        BarnOwl::error(
+            "Usage: jwrite JID [-t thread] [-s 'subject'] [-a account]");
+        return;
+    }
+    else {
+        $to = shift @ARGV;
+    }
+
+    my @candidates = guess_jwrite($from, $to);
+
+    unless(scalar @candidates) {
+        die("Unable to resolve JID $to");
+    }
+
+    @candidates = grep {defined $_->[0]} @candidates;
+
+    unless(scalar @candidates) {
+        if(!$from) {
+            die("You must specify an account with -a");
+        } else {
+            die("Unable to resolve account $from");
+        }
+    }
+
+
+    ($jwrite_from, $jwrite_to, $jwrite_type) = @{$candidates[0]};
+
+    $vars{jwrite} = {
+        to      => $jwrite_to,
+        from    => $jwrite_from,
+        sid     => $jwrite_sid,
+        subject => $jwrite_subject,
+        thread  => $jwrite_thread,
+        type    => $jwrite_type
+    };
+
+    if(scalar @candidates > 1) {
+        BarnOwl::message(
+            "Warning: Guessing account and/or destination JID"
+           );
+    } else  {
+        BarnOwl::message(
+            "Type your message below.  End with a dot on a line by itself.  ^C will quit."
+           );
+    }
+
+    my $cmd = "jwrite $jwrite_to -a $jwrite_from";
+    $cmd .= " -t $jwrite_thread" if $jwrite_thread;
+    $cmd .= " -t $jwrite_subject" if $jwrite_subject;
+    BarnOwl::start_edit_win( $cmd, \&process_owl_jwrite );
+}
+
+sub cmd_jmuc {
+    die "You are not logged in to Jabber" unless $conn->connected();
+    my $ocmd = shift;
+    my $cmd  = shift;
+    if ( !$cmd ) {
+
+        #XXX TODO: Write general usage for jmuc command.
+        return;
+    }
+
+    my %jmuc_commands = (
+        join      => \&jmuc_join,
+        part      => \&jmuc_part,
+        invite    => \&jmuc_invite,
+        configure => \&jmuc_configure,
+        presence  => \&jmuc_presence
+    );
+    my $func = $jmuc_commands{$cmd};
+    if ( !$func ) {
+        BarnOwl::error("jmuc: Unknown command: $cmd");
+        return;
+    }
+
+    {
+        local @ARGV = @_;
+        my $jid;
+        my $muc;
+        my $m = BarnOwl::getcurmsg();
+        if ( $m && $m->is_jabber && $m->{jtype} eq 'groupchat' ) {
+            $muc = $m->{room};
+            $jid = $m->{to};
+        }
+
+        my $getopt = Getopt::Long::Parser->new;
+        $getopt->configure('pass_through');
+        $getopt->getoptions( 'account=s' => \$jid );
+        $jid ||= defaultJID();
+        if ($jid) {
+            $jid = resolveConnectedJID($jid);
+            return unless $jid;
+        }
+        else {
+            BarnOwl::error('You must specify an account with -a {jid}');
+        }
+        return $func->( $jid, $muc, @ARGV );
+    }
+}
+
+sub jmuc_join {
+    my ( $jid, $muc, @args ) = @_;
+    local @ARGV = @args;
+    my $password;
+    GetOptions( 'password=s' => \$password );
+
+    $muc = shift @ARGV
+      or die("Usage: jmuc join MUC [-p password] [-a account]");
+
+    $muc = Net::Jabber::JID->new($muc);
+    $jid = Net::Jabber::JID->new($jid);
+    $muc->SetResource($jid->GetJID('full')) unless length $muc->GetResource();
+
+    $conn->getConnectionFromJID($jid)->MUCJoin(JID      => $muc,
+                                                  Password => $password,
+                                                  History  => {
+                                                      MaxChars => 0
+                                                     });
+    return;
+}
+
+sub jmuc_part {
+    my ( $jid, $muc, @args ) = @_;
+
+    $muc = shift @args if scalar @args;
+    die("Usage: jmuc part MUC [-a account]") unless $muc;
+
+    $conn->getConnectionFromJID($jid)->MUCLeave(JID => $muc);
+    queue_admin_msg("$jid has left $muc.");
+}
+
+sub jmuc_invite {
+    my ( $jid, $muc, @args ) = @_;
+
+    my $invite_jid = shift @args;
+    $muc = shift @args if scalar @args;
+
+    die('Usage: jmuc invite JID [muc] [-a account]')
+      unless $muc && $invite_jid;
+
+    my $message = Net::Jabber::Message->new();
+    $message->SetTo($muc);
+    my $x = $message->NewChild('http://jabber.org/protocol/muc#user');
+    $x->AddInvite();
+    $x->GetInvite()->SetTo($invite_jid);
+    $conn->getConnectionFromJID($jid)->Send($message);
+    queue_admin_msg("$jid has invited $invite_jid to $muc.");
+}
+
+sub jmuc_configure {
+    my ( $jid, $muc, @args ) = @_;
+    $muc = shift @args if scalar @args;
+    die("Usage: jmuc configure [muc]") unless $muc;
+    my $iq = Net::Jabber::IQ->new();
+    $iq->SetTo($muc);
+    $iq->SetType('set');
+    my $query = $iq->NewQuery("http://jabber.org/protocol/muc#owner");
+    my $x     = $query->NewChild("jabber:x:data");
+    $x->SetType('submit');
+
+    $conn->getConnectionFromJID($jid)->Send($iq);
+    queue_admin_msg("Accepted default instant configuration for $muc");
+}
+
+sub jmuc_presence_single {
+    my $m = shift;
+    my @jids = $m->Presence();
+    return "JIDs present in " . $m->BaseJID . "\n\t"
+      . join("\n\t", map {$_->GetResource}@jids) . "\n";
+}
+
+sub jmuc_presence {
+    my ( $jid, $muc, @args ) = @_;
+
+    $muc = shift @args if scalar @args;
+    die("Usage: jmuc presence MUC") unless $muc;
+
+    if ($muc eq '-a') {
+        my $str = "";
+        foreach my $jid ($conn->getJIDs()) {
+            $str .= BarnOwl::Style::boldify("Conferences for $jid:\n");
+            my $connection = $conn->getConnectionFromJID($jid);
+            foreach my $muc ($connection->MUCs) {
+                $str .= jmuc_presence_single($muc)."\n";
+            }
+        }
+        BarnOwl::popless_ztext($str);
+    }
+    else {
+        my $m = $conn->getConnectionFromJID($jid)->FindMUC(jid => $muc);
+        die("No such muc: $muc") unless $m;
+        BarnOwl::popless_ztext(jmuc_presence_single($m));
+    }
+}
+
+
+#XXX TODO: Consider merging this with jmuc and selecting off the first two args.
+sub cmd_jroster {
+    die "You are not logged in to Jabber" unless $conn->connected();
+    my $ocmd = shift;
+    my $cmd  = shift;
+    if ( !$cmd ) {
+
+        #XXX TODO: Write general usage for jroster command.
+        return;
+    }
+
+    my %jroster_commands = (
+        sub      => \&jroster_sub,
+        unsub    => \&jroster_unsub,
+        add      => \&jroster_add,
+        remove   => \&jroster_remove,
+        auth     => \&jroster_auth,
+        deauth   => \&jroster_deauth
+    );
+    my $func = $jroster_commands{$cmd};
+    if ( !$func ) {
+        BarnOwl::error("jroster: Unknown command: $cmd");
+        return;
+    }
+
+    {
+        local @ARGV = @_;
+        my $jid;
+        my $name;
+        my @groups;
+        my $purgeGroups;
+        my $getopt = Getopt::Long::Parser->new;
+        $getopt->configure('pass_through');
+        $getopt->getoptions(
+            'account=s' => \$jid,
+            'group=s' => \@groups,
+            'purgegroups' => \$purgeGroups,
+            'name=s' => \$name
+        );
+        $jid ||= defaultJID();
+        if ($jid) {
+            $jid = resolveConnectedJID($jid);
+            return unless $jid;
+        }
+        else {
+            BarnOwl::error('You must specify an account with -a {jid}');
+        }
+        return $func->( $jid, $name, \@groups, $purgeGroups,  @ARGV );
+    }
+}
+
+sub jroster_sub {
+    my $jid = shift;
+    my $name = shift;
+    my @groups = @{ shift() };
+    my $purgeGroups = shift;
+    my $baseJID = baseJID($jid);
+
+    my $roster = $conn->getRosterFromJID($jid);
+
+    # Adding lots of users with the same name is a bad idea.
+    $name = "" unless (1 == scalar(@ARGV));
+
+    my $p = new Net::Jabber::Presence;
+    $p->SetType('subscribe');
+
+    foreach my $to (@ARGV) {
+        jroster_add($jid, $name, \@groups, $purgeGroups, ($to)) unless ($roster->exists($to));
+
+        $p->SetTo($to);
+        $conn->getConnectionFromJID($jid)->Send($p);
+        queue_admin_msg("You ($baseJID) have requested a subscription to ($to)'s presence.");
+    }
+}
+
+sub jroster_unsub {
+    my $jid = shift;
+    my $name = shift;
+    my @groups = @{ shift() };
+    my $purgeGroups = shift;
+    my $baseJID = baseJID($jid);
+
+    my $p = new Net::Jabber::Presence;
+    $p->SetType('unsubscribe');
+    foreach my $to (@ARGV) {
+        $p->SetTo($to);
+        $conn->getConnectionFromJID($jid)->Send($p);
+        queue_admin_msg("You ($baseJID) have unsubscribed from ($to)'s presence.");
+    }
+}
+
+sub jroster_add {
+    my $jid = shift;
+    my $name = shift;
+    my @groups = @{ shift() };
+    my $purgeGroups = shift;
+    my $baseJID = baseJID($jid);
+
+    my $roster = $conn->getRosterFromJID($jid);
+
+    # Adding lots of users with the same name is a bad idea.
+    $name = "" unless (1 == scalar(@ARGV));
+
+    foreach my $to (@ARGV) {
+        my %jq  = $roster->query($to);
+        my $iq = new Net::Jabber::IQ;
+        $iq->SetType('set');
+        my $item = new XML::Stream::Node('item');
+        $iq->NewChild('jabber:iq:roster')->AddChild($item);
+
+        my %allGroups = ();
+
+        foreach my $g (@groups) {
+            $allGroups{$g} = $g;
+        }
+
+        unless ($purgeGroups) {
+            foreach my $g (@{$jq{groups}}) {
+                $allGroups{$g} = $g;
+            }
+        }
+
+        foreach my $g (keys %allGroups) {
+            $item->add_child('group')->add_cdata($g);
+        }
+
+        $item->put_attrib(jid => $to);
+        $item->put_attrib(name => $name) if $name;
+        $conn->getConnectionFromJID($jid)->Send($iq);
+        my $msg = "$baseJID: "
+          . ($name ? "$name ($to)" : "($to)")
+          . " is on your roster in the following groups: { "
+          . join(" , ", keys %allGroups)
+          . " }";
+        queue_admin_msg($msg);
+    }
+}
+
+sub jroster_remove {
+    my $jid = shift;
+    my $name = shift;
+    my @groups = @{ shift() };
+    my $purgeGroups = shift;
+    my $baseJID = baseJID($jid);
+
+    my $iq = new Net::Jabber::IQ;
+    $iq->SetType('set');
+    my $item = new XML::Stream::Node('item');
+    $iq->NewChild('jabber:iq:roster')->AddChild($item);
+    $item->put_attrib(subscription=> 'remove');
+    foreach my $to (@ARGV) {
+        $item->put_attrib(jid => $to);
+        $conn->getConnectionFromJID($jid)->Send($iq);
+        queue_admin_msg("You ($baseJID) have removed ($to) from your roster.");
+    }
+}
+
+sub jroster_auth {
+    my $jid = shift;
+    my $name = shift;
+    my @groups = @{ shift() };
+    my $purgeGroups = shift;
+    my $baseJID = baseJID($jid);
+
+    my $p = new Net::Jabber::Presence;
+    $p->SetType('subscribed');
+    foreach my $to (@ARGV) {
+        $p->SetTo($to);
+        $conn->getConnectionFromJID($jid)->Send($p);
+        queue_admin_msg("($to) has been subscribed to your ($baseJID) presence.");
+    }
+}
+
+sub jroster_deauth {
+    my $jid = shift;
+    my $name = shift;
+    my @groups = @{ shift() };
+    my $purgeGroups = shift;
+    my $baseJID = baseJID($jid);
+
+    my $p = new Net::Jabber::Presence;
+    $p->SetType('unsubscribed');
+    foreach my $to (@ARGV) {
+        $p->SetTo($to);
+        $conn->getConnectionFromJID($jid)->Send($p);
+        queue_admin_msg("($to) has been unsubscribed from your ($baseJID) presence.");
+    }
+}
+
+################################################################################
+### Owl Callbacks
+sub process_owl_jwrite {
+    my $body = shift;
+
+    my $j = new Net::Jabber::Message;
+    $body =~ s/\n\z//;
+    $j->SetMessage(
+        to   => $vars{jwrite}{to},
+        from => $vars{jwrite}{from},
+        type => $vars{jwrite}{type},
+        body => $body
+    );
+
+    $j->SetThread( $vars{jwrite}{thread} )   if ( $vars{jwrite}{thread} );
+    $j->SetSubject( $vars{jwrite}{subject} ) if ( $vars{jwrite}{subject} );
+
+    my $m = j2o( $j, { direction => 'out' } );
+    if ( $vars{jwrite}{type} ne 'groupchat') {
+        BarnOwl::add_message($m);
+    }
+
+    $j->RemoveFrom(); # Kludge to get around gtalk's random bits after the resource.
+    if ($vars{jwrite}{sid} && $conn->sidExists( $vars{jwrite}{sid} )) {
+        $conn->getConnectionFromSid($vars{jwrite}{sid})->Send($j);
+    }
+    else {
+        $conn->getConnectionFromJID($vars{jwrite}{from})->Send($j);
+    }
+
+    delete $vars{jwrite};
+    BarnOwl::message("");   # Kludge to make the ``type your message...'' message go away
+}
+
+### XMPP Callbacks
+
+sub process_incoming_chat_message {
+    my ( $sid, $j ) = @_;
+    BarnOwl::queue_message( j2o( $j, { direction => 'in',
+                                   sid => $sid } ) );
+}
+
+sub process_incoming_error_message {
+    my ( $sid, $j ) = @_;
+    my %jhash = j2hash( $j, { direction => 'in',
+                              sid => $sid } );
+    $jhash{type} = 'admin';
+    BarnOwl::queue_message( BarnOwl::Message->new(%jhash) );
+}
+
+sub process_incoming_groupchat_message {
+    my ( $sid, $j ) = @_;
+
+    # HACK IN PROGRESS (ignoring delayed messages)
+    return if ( $j->DefinedX('jabber:x:delay') && $j->GetX('jabber:x:delay') );
+    BarnOwl::queue_message( j2o( $j, { direction => 'in',
+                                   sid => $sid } ) );
+}
+
+sub process_incoming_headline_message {
+    my ( $sid, $j ) = @_;
+    BarnOwl::queue_message( j2o( $j, { direction => 'in',
+                                   sid => $sid } ) );
+}
+
+sub process_incoming_normal_message {
+    my ( $sid, $j ) = @_;
+    my %jhash = j2hash( $j, { direction => 'in',
+                              sid => $sid } );
+
+    # XXX TODO: handle things such as MUC invites here.
+
+    #    if ($j->HasX('http://jabber.org/protocol/muc#user'))
+    #    {
+    #	my $x = $j->GetX('http://jabber.org/protocol/muc#user');
+    #	if ($x->HasChild('invite'))
+    #	{
+    #	    $props
+    #	}
+    #    }
+    #
+    BarnOwl::queue_message( BarnOwl::Message->new(%jhash) );
+}
+
+sub process_muc_presence {
+    my ( $sid, $p ) = @_;
+    return unless ( $p->HasX('http://jabber.org/protocol/muc#user') );
+}
+
+
+sub process_presence_available {
+    my ( $sid, $p ) = @_;
+    my $from = $p->GetFrom();
+    my $to = $p->GetTo();
+    my $type = $p->GetType();
+    my %props = (
+        to => $to,
+        from => $from,
+        recipient => $to,
+        sender => $from,
+        type => 'jabber',
+        jtype => $p->GetType(),
+        status => $p->GetStatus(),
+        show => $p->GetShow(),
+        xml => $p->GetXML(),
+        direction => 'in');
+
+    if ($type eq '' || $type eq 'available') {
+        $props{body} = "$from is now online. ";
+        $props{loginout} = 'login';
+    }
+    else {
+        $props{body} = "$from is now offline. ";
+        $props{loginout} = 'logout';
+    }
+    $props{replysendercmd} = $props{replycmd} = "jwrite $from -i $sid";
+    if(BarnOwl::getvar('debug') eq 'on') {
+        BarnOwl::queue_message(BarnOwl::Message->new(%props));
+    }
+}
+
+sub process_presence_subscribe {
+    my ( $sid, $p ) = @_;
+    my $from = $p->GetFrom();
+    my $to = $p->GetTo();
+    my %props = (
+        to => $to,
+        from => $from,
+        xml => $p->GetXML(),
+        type => 'admin',
+        adminheader => 'Jabber presence: subscribe',
+        direction => 'in');
+
+    $props{body} = "Allow user ($from) to subscribe to your ($to) presence?\n" .
+                   "(Answer with the `yes' or `no' commands)";
+    $props{yescommand} = "jroster auth $from -a $to";
+    $props{nocommand} = "jroster deauth $from -a $to";
+    $props{question} = "true";
+    BarnOwl::queue_message(BarnOwl::Message->new(%props));
+}
+
+sub process_presence_unsubscribe {
+    my ( $sid, $p ) = @_;
+    my $from = $p->GetFrom();
+    my $to = $p->GetTo();
+    my %props = (
+        to => $to,
+        from => $from,
+        xml => $p->GetXML(),
+        type => 'admin',
+        adminheader => 'Jabber presence: unsubscribe',
+        direction => 'in');
+
+    $props{body} = "The user ($from) has been unsubscribed from your ($to) presence.\n";
+    BarnOwl::queue_message(BarnOwl::Message->new(%props));
+
+    # Find a connection to reply with.
+    foreach my $jid ($conn->getJIDs()) {
+	my $cJID = new Net::Jabber::JID;
+	$cJID->SetJID($jid);
+	if ($to eq $cJID->GetJID('base') ||
+            $to eq $cJID->GetJID('full')) {
+	    my $reply = $p->Reply(type=>"unsubscribed");
+	    $conn->getConnectionFromJID($jid)->Send($reply);
+	    return;
+	}
+    }
+}
+
+sub process_presence_subscribed {
+    my ( $sid, $p ) = @_;
+    queue_admin_msg("ignoring:".$p->GetXML());
+    # RFC 3921 says we should respond to this with a "subscribe"
+    # but this causes a flood of sub/sub'd presence packets with
+    # some servers, so we won't. We may want to detect this condition
+    # later, and have per-server settings.
+    return;
+}
+
+sub process_presence_unsubscribed {
+    my ( $sid, $p ) = @_;
+    queue_admin_msg("ignoring:".$p->GetXML());
+    # RFC 3921 says we should respond to this with a "subscribe"
+    # but this causes a flood of unsub/unsub'd presence packets with
+    # some servers, so we won't. We may want to detect this condition
+    # later, and have per-server settings.
+    return;
+}
+
+sub process_presence_error {
+    my ( $sid, $p ) = @_;
+    my $code = $p->GetErrorCode();
+    my $error = $p->GetError();
+    BarnOwl::error("Jabber: $code $error");
+}
+
+
+### Helper functions
+
+sub j2hash {
+    my $j   = shift;
+    my %initProps = %{ shift() };
+
+    my $dir = 'none';
+    my %props = ( type => 'jabber' );
+
+    foreach my $k (keys %initProps) {
+        $dir = $initProps{$k} if ($k eq 'direction');
+        $props{$k} = $initProps{$k};
+    }
+
+    my $jtype = $props{jtype} = $j->GetType();
+    my $from = $j->GetFrom('jid');
+    my $to   = $j->GetTo('jid');
+
+    $props{from} = $from->GetJID('full');
+    $props{to}   = $to->GetJID('full');
+
+    $props{recipient}  = $to->GetJID('base');
+    $props{sender}     = $from->GetJID('base');
+    $props{subject}    = $j->GetSubject() if ( $j->DefinedSubject() );
+    $props{thread}     = $j->GetThread() if ( $j->DefinedThread() );
+    $props{body}       = $j->GetBody() if ( $j->DefinedBody() );
+    $props{error}      = $j->GetError() if ( $j->DefinedError() );
+    $props{error_code} = $j->GetErrorCode() if ( $j->DefinedErrorCode() );
+    $props{xml}        = $j->GetXML();
+
+    if ( $jtype eq 'chat' ) {
+        $props{replycmd} =
+          "jwrite " . ( ( $dir eq 'in' ) ? $props{from} : $props{to} );
+        $props{replycmd} .=
+          " -a " . ( ( $dir eq 'out' ) ? $props{from} : $props{to} );
+        $props{private} = 1;
+
+        my $connection;
+        if ($dir eq 'in') {
+            $connection = $conn->getConnectionFromSid($props{sid});
+        }
+        else {
+            $connection = $conn->getConnectionFromJID($props{from});
+        }
+
+        # Check to see if we're doing personals with someone in a muc.
+        # If we are, show the full jid because the base jid is the room.
+        if ($connection) {
+            $props{sender} = $props{from}
+              if ($connection->FindMUC(jid => $from));
+            $props{recipient} = $props{to}
+              if ($connection->FindMUC(jid => $to));
+        }
+    }
+    elsif ( $jtype eq 'groupchat' ) {
+        my $nick = $props{nick} = $from->GetResource();
+        my $room = $props{room} = $from->GetJID('base');
+        $props{replycmd} = "jwrite $room";
+        $props{replycmd} .=
+          " -a " . ( ( $dir eq 'out' ) ? $props{from} : $props{to} );
+
+        if ($dir eq 'out') {
+            $props{replysendercmd} = "jwrite ".$props{to}." -a ".$props{from};
+        }
+        else {
+            $props{replysendercmd} = "jwrite ".$props{from}." -a ".$props{to};
+        }
+
+        $props{sender} = $nick || $room;
+        $props{recipient} = $room;
+
+        if ( $props{subject} && !$props{body} ) {
+            $props{body} =
+              '[' . $nick . " has set the topic to: " . $props{subject} . "]";
+        }
+    }
+    elsif ( $jtype eq 'normal' ) {
+        $props{replycmd}  = undef;
+        $props{private} = 1;
+    }
+    elsif ( $jtype eq 'headline' ) {
+        $props{replycmd} = undef;
+    }
+    elsif ( $jtype eq 'error' ) {
+        $props{replycmd} = undef;
+        $props{body}     = "Error "
+          . $props{error_code}
+          . " sending to "
+          . $props{from} . "\n"
+          . $props{error};
+    }
+
+    $props{replysendercmd} = $props{replycmd} unless $props{replysendercmd};
+    return %props;
+}
+
+sub j2o {
+    return BarnOwl::Message->new( j2hash(@_) );
+}
+
+sub queue_admin_msg {
+    my $err = shift;
+    BarnOwl::admin_message("jabber.pl", $err);
+}
+
+sub getServerFromJID {
+    my $jid = shift;
+    my $res = new Net::DNS::Resolver;
+    my $packet =
+      $res->search( '_xmpp-client._tcp.' . $jid->GetServer(), 'srv' );
+
+    if ($packet)    # Got srv record.
+    {
+        my @answer = $packet->answer;
+        return $answer[0]{target}, $answer[0]{port};
+    }
+
+    return $jid->GetServer(), 5222;
+}
+
+sub defaultJID {
+    return ( $conn->getJIDs() )[0] if ( $conn->connected() == 1 );
+    return;
+}
+
+sub baseJID {
+    my $givenJIDStr = shift;
+    my $givenJID    = new Net::Jabber::JID;
+    $givenJID->SetJID($givenJIDStr);
+    return $givenJID->GetJID('base');
+}
+
+sub resolveConnectedJID {
+    my $givenJIDStr = shift;
+    my $givenJID    = new Net::Jabber::JID;
+    $givenJID->SetJID($givenJIDStr);
+
+    # Account fully specified.
+    if ( $givenJID->GetResource() ) {
+        # Specified account exists
+        return $givenJIDStr if ($conn->jidExists($givenJIDStr) );
+        die("Invalid account: $givenJIDStr");
+    }
+
+    # Disambiguate.
+    else {
+        my $matchingJID = "";
+        my $errStr =
+          "Ambiguous account reference. Please specify a resource.\n";
+        my $ambiguous = 0;
+
+        foreach my $jid ( $conn->getJIDs() ) {
+            my $cJID = new Net::Jabber::JID;
+            $cJID->SetJID($jid);
+            if ( $givenJIDStr eq $cJID->GetJID('base') ) {
+                $ambiguous = 1 if ( $matchingJID ne "" );
+                $matchingJID = $jid;
+                $errStr .= "\t$jid\n";
+            }
+        }
+
+        # Need further disambiguation.
+        if ($ambiguous) {
+            die($errStr);
+        }
+
+        # Not one of ours.
+        elsif ( $matchingJID eq "" ) {
+            die("Invalid account: $givenJIDStr");
+        }
+
+        # It's this one.
+        else {
+            return $matchingJID;
+        }
+    }
+    return "";
+}
+
+sub resolveDestJID {
+    my ($to, $from) = @_;
+    my $jid = Net::Jabber::JID->new($to);
+
+    my $roster = $conn->getRosterFromJID($from);
+    my @jids = $roster->jids('all');
+    for my $j (@jids) {
+        if(($roster->query($j, 'name') || $j->GetUserID()) eq $to) {
+            return $j->GetJID('full');
+        } elsif($j->GetJID('base') eq baseJID($to)) {
+            return $jid->GetJID('full');
+        }
+    }
+
+    # If we found nothing being clever, check to see if our input was
+    # sane enough to look like a jid with a UserID.
+    return $jid->GetJID('full') if $jid->GetUserID();
+    return undef;
+}
+
+sub resolveType {
+    my $to = shift;
+    my $from = shift;
+    return unless $from;
+    my @mucs = $conn->getConnectionFromJID($from)->MUCs;
+    if(grep {$_->BaseJID eq $to } @mucs) {
+        return 'groupchat';
+    } else {
+        return 'chat';
+    }
+}
+
+sub guess_jwrite {
+    # Heuristically guess what jids a jwrite was meant to be going to/from
+    my ($from, $to) = (@_);
+    my ($from_jid, $to_jid);
+    my @matches;
+    if($from) {
+        $from_jid = resolveConnectedJID($from);
+        die("Unable to resolve account $from") unless $from_jid;
+        $to_jid = resolveDestJID($to, $from_jid);
+        push @matches, [$from_jid, $to_jid] if $to_jid;
+    } else {
+        for my $f ($conn->getJIDs) {
+            $to_jid = resolveDestJID($to, $f);
+            if(defined($to_jid)) {
+                push @matches, [$f, $to_jid];
+            }
+        }
+        if($to =~ /@/) {
+            push @matches, [$_, $to]
+               for ($conn->getJIDs);
+        }
+    }
+
+    for my $m (@matches) {
+        my $type = resolveType($m->[1], $m->[0]);
+        push @$m, $type;
+    }
+
+    return @matches;
+}
+
+1;

Copied: trunk/owl/perl/modules/Jabber/lib/Net (from rev 664, trunk/owl/perl/lib/Net)

Modified: trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Component.pm
===================================================================
--- trunk/owl/perl/lib/Net/Jabber/Component.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Component.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -53,7 +53,7 @@
 
     use Net::Jabber;
 
-    $Con = new Net::Jabber::Component();
+    $Con = Net::Jabber::Component->new();
 
     $Con->Execute(hostname=>"jabber.org",
                   componentname=>"service.jabber.org",

Modified: trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Data.pm
===================================================================
--- trunk/owl/perl/lib/Net/Jabber/Data.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Data.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -55,7 +55,7 @@
   a Jabber <xdb/> you must pass it the XML::Stream hash from the
   Net::Jabber::Client module.
 
-    my $xdb = new Net::Jabber::XDB(%hash);
+    my $xdb = Net::Jabber::XDB->new(%hash);
 
   There has been a change from the old way of handling the callbacks.
   You no longer have to do the above yourself, a Net::Jabber::XDB
@@ -82,7 +82,7 @@
 
     use Net::Jabber;
 
-    my $xdb = new Net::Jabber::XDB();
+    my $xdb = Net::Jabber::XDB->new();
     $data = $xdb->NewData("jabber:iq:auth");
 
   Now you can call the creation functions for the Data as defined in the

Modified: trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Dialback/Result.pm
===================================================================
--- trunk/owl/perl/lib/Net/Jabber/Dialback/Result.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Dialback/Result.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -37,7 +37,7 @@
   To initialize the Result with a Jabber <db:*/> you must pass it
   the XML::Stream hash.  For example:
 
-    my $dialback = new Net::Jabber::Dialback::Result(%hash);
+    my $dialback = Net::Jabber::Dialback::Result->new(%hash);
 
   There has been a change from the old way of handling the callbacks.
   You no longer have to do the above yourself, a NJ::Dialback::Result
@@ -62,7 +62,7 @@
 
     use Net::Jabber qw(Server);
 
-    $Result = new Net::Jabber::Dialback::Result();
+    $Result = Net::Jabber::Dialback::Result->new();
 
   Now you can call the creation functions below to populate the tag before
   sending it.

Modified: trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Dialback/Verify.pm
===================================================================
--- trunk/owl/perl/lib/Net/Jabber/Dialback/Verify.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Dialback/Verify.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -37,7 +37,7 @@
   To initialize the Verify with a Jabber <db:*/> you must pass it
   the XML::Stream hash.  For example:
 
-    my $dialback = new Net::Jabber::Dialback::Verify(%hash);
+    my $dialback = Net::Jabber::Dialback::Verify->new(%hash);
 
   There has been a change from the old way of handling the callbacks.
   You no longer have to do the above yourself, a NJ::Dialback::Verify
@@ -62,7 +62,7 @@
 
     use Net::Jabber qw(Server);
 
-    $Verify = new Net::Jabber::Dialback::Verify();
+    $Verify = Net::Jabber::Dialback::Verify->new();
 
   Now you can call the creation functions below to populate the tag before
   sending it.

Modified: trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Dialback.pm
===================================================================
--- trunk/owl/perl/lib/Net/Jabber/Dialback.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Dialback.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -37,7 +37,7 @@
   To initialize the Dialback with a Jabber <db:*/> you must pass it
   the XML::Stream hash.  For example:
 
-    my $dialback = new Net::Jabber::Dialback(%hash);
+    my $dialback = Net::Jabber::Dialback->new(%hash);
 
   You now have access to all of the retrieval functions available.
 
@@ -45,8 +45,8 @@
 
     use Net::Jabber qw(Server);
 
-    $DB = new Net::Jabber::Dialback("verify");
-    $DB = new Net::Jabber::Dialback("result");
+    $DB = Net::Jabber::Dialback->new("verify");
+    $DB = Net::Jabber::Dialback->new("result");
 
   Please see the specific documentation for Net::Jabber::Dialback::Result
   and Net::Jabber::Dialback::Verify.
@@ -97,15 +97,15 @@
         else
         {
             my ($temp) = @_;
-            return new Net::Jabber::Dialback::Result()
+            return Net::Jabber::Dialback::Result->new()
                 if ($temp eq "result");
-            return new Net::Jabber::Dialback::Verify()
+            return Net::Jabber::Dialback::Verify->new()
                 if ($temp eq "verify");
 
             my @temp = @{$temp};
-            return new Net::Jabber::Dialback::Result(@temp)
+            return Net::Jabber::Dialback::Result->new(@temp)
                 if ($temp[0] eq "db:result");
-            return new Net::Jabber::Dialback::Verify(@temp)
+            return Net::Jabber::Dialback::Verify->new(@temp)
                 if ($temp[0] eq "db:verify");
         }
     }

Modified: trunk/owl/perl/modules/Jabber/lib/Net/Jabber/IQ.pm
===================================================================
--- trunk/owl/perl/lib/Net/Jabber/IQ.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/Net/Jabber/IQ.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -62,8 +62,8 @@
 sub AddX     { my $self = shift; $self->AddChild(@_);     } 
 sub RemoveX  { my $self = shift; $self->RemoveChild(@_);  }
 
-sub _new_jid    { my $self = shift; return new Net::Jabber::JID(@_);    }
-sub _new_packet { my $self = shift; return new Net::Jabber::Stanza(@_); }
-sub _iq         { my $self = shift; return new Net::Jabber::IQ(@_);     }
+sub _new_jid    { my $self = shift; return Net::Jabber::JID->new(@_);    }
+sub _new_packet { my $self = shift; return Net::Jabber::Stanza->new(@_); }
+sub _iq         { my $self = shift; return Net::Jabber::IQ->new(@_);     }
 
 1;

Modified: trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Key.pm
===================================================================
--- trunk/owl/perl/lib/Net/Jabber/Key.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Key.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -40,7 +40,7 @@
 
 =head2 Basic Functions
 
-    $Key = new Net::Jabber::Key();
+    $Key = Net::Jabber::Key->new();
 
     $key = $Key->Generate();
 
@@ -96,8 +96,8 @@
     my $proto = shift;
     my $self = { };
 
-    $self->{DEBUG} = new Net::Jabber::Debug(usedefault=>1,
-                      header=>"NJ::Key");
+    $self->{DEBUG} = Net::Jabber::Debug->new(usedefault=>1,
+                                             header=>"NJ::Key");
 
     $self->{VERSION} = $VERSION;
     

Modified: trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Log.pm
===================================================================
--- trunk/owl/perl/lib/Net/Jabber/Log.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Log.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -37,7 +37,7 @@
   To initialize the Log with a Jabber <log/> you must pass it the 
   XML::Parser Tree array.  For example:
 
-    my $log = new Net::Jabber::Log(@tree);
+    my $log = Net::Jabber::Log->new(@tree);
 
   There has been a change from the old way of handling the callbacks.
   You no longer have to do the above, a Net::Jabber::Log object is passed
@@ -58,7 +58,7 @@
 
     use Net::Jabber;
 
-    $Log = new Net::Jabber::Log();
+    $Log = Net::Jabber::Log->new();
 
   Now you can call the creation functions below to populate the tag before
   sending it.
@@ -175,8 +175,8 @@
 
     bless($self, $proto);
 
-    $self->{DEBUG} = new Net::Jabber::Debug(usedefault=>1,
-                                                    header=>"NJ::Log");
+    $self->{DEBUG} = Net::Jabber::Debug->new(usedefault=>1,
+                                             header=>"NJ::Log");
 
     if ("@_" ne (""))
     {

Modified: trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Message.pm
===================================================================
--- trunk/owl/perl/lib/Net/Jabber/Message.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Message.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -57,8 +57,8 @@
 sub AddX     { my $self = shift; $self->AddChild(@_);    } 
 sub RemoveX  { my $self = shift; $self->RemoveChild(@_); }
 
-sub _new_jid    { my $self = shift; return new Net::Jabber::JID(@_);     }
-sub _new_packet { my $self = shift; return new Net::Jabber::Stanza(@_);  }
-sub _message    { my $self = shift; return new Net::Jabber::Message(@_); }
+sub _new_jid    { my $self = shift; return Net::Jabber::JID->new(@_);     }
+sub _new_packet { my $self = shift; return Net::Jabber::Stanza->new(@_);  }
+sub _message    { my $self = shift; return Net::Jabber::Message->new(@_); }
 
 1;

Modified: trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Presence.pm
===================================================================
--- trunk/owl/perl/lib/Net/Jabber/Presence.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Presence.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -57,8 +57,8 @@
 sub AddX     { my $self = shift; $self->AddChild(@_);    } 
 sub RemoveX  { my $self = shift; $self->RemoveChild(@_); }
 
-sub _new_jid    { my $self = shift; return new Net::Jabber::JID(@_);      }
-sub _new_packet { my $self = shift; return new Net::Jabber::Stanza(@_);   }
-sub _presence   { my $self = shift; return new Net::Jabber::Presence(@_); }
+sub _new_jid    { my $self = shift; return Net::Jabber::JID->new(@_);      }
+sub _new_packet { my $self = shift; return Net::Jabber::Stanza->new(@_);   }
+sub _presence   { my $self = shift; return Net::Jabber::Presence->new(@_); }
 
 1;

Modified: trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Protocol.pm
===================================================================
--- trunk/owl/perl/lib/Net/Jabber/Protocol.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Protocol.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -77,13 +77,13 @@
 =head2 Basic Functions
 
     use Net::Jabber qw( Client );
-    $Con = new Net::Jabber::Client();                # From
+    $Con = Net::Jabber::Client->new();                # From
     $status = $Con->Connect(hostname=>"jabber.org"); # Net::Jabber::Client
 
       or
 
     use Net::Jabber qw( Component );
-    $Con = new Net::Jabber::Component();             #
+    $Con = Net::Jabber::Component->new();             #
     $status = $Con->Connect(hostname=>"jabber.org",  # From
                             secret=>"bob");          # Net::Jabber::Component
 
@@ -1659,7 +1659,7 @@
     $tag = $Net::Jabber::Query::TAGS{'http://jabber.org/protocol/feature-neg'}
         if exists($Net::Jabber::Query::TAGS{'http://jabber.org/protocol/feature-neg'});
     
-    my $query = new Net::Jabber::Query($tag);
+    my $query = Net::Jabber::Query->new($tag);
     $query->SetXMLNS("http://jabber.org/protocol/feature-neg");
     my $xdata = $query->NewX("jabber:x:data");
     
@@ -2182,7 +2182,7 @@
     my %args;
     while($#_ >= 0) { $args{ lc pop(@_) } = pop(@_); }
 
-    my $query = new Net::Jabber::Stanza("query");
+    my $query = Net::Jabber::Stanza->new("query");
     $query->SetXMLNS("jabber:iq:rpc");
 
     my $source;

Modified: trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Server.pm
===================================================================
--- trunk/owl/perl/lib/Net/Jabber/Server.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Server.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -53,7 +53,7 @@
 
     use Net::Jabber qw(Server);
 
-    $Server = new Net::Jabber::Server();
+    $Server = Net::Jabber::Server->new();
 
     $Server->Start();
     $Server->Start(jabberxml=>"custom_jabber.xml",
@@ -154,15 +154,15 @@
 
     bless($self, $proto);
 
-    $self->{KEY} = new Net::Jabber::Key();
+    $self->{KEY} = Net::Jabber::Key->new();
 
     $self->{DEBUG} =
-        new Net::Jabber::Debug(level=>exists($args{debuglevel}) ? $args{debuglevel} : -1,
-                               file=>exists($args{debugfile}) ? $args{debugfile} : "stdout",
-                               time=>exists($args{debugtime}) ? $args{debugtime} : 0,
-                               setdefault=>1,
-                               header=>"NJ::Server"
-                              );
+        Net::Jabber::Debug->new(level=>exists($args{debuglevel}) ? $args{debuglevel} : -1,
+                                file=>exists($args{debugfile}) ? $args{debugfile} : "stdout",
+                                time=>exists($args{debugtime}) ? $args{debugtime} : 0,
+                                setdefault=>1,
+                                header=>"NJ::Server"
+                               );
 
     $self->{SERVER} = { hostname => "localhost",
                         port => 5269,
@@ -328,7 +328,7 @@
 
     $self->{DEBUG}->Log2("dbresultHandler: dbresult(",$dbresult->GetXML(),")");
 
-    my $dbverify = new Net::Jabber::Dialback::Verify();
+    my $dbverify = Net::Jabber::Dialback::Verify->new();
     $dbverify->SetVerify(to=>$dbresult->GetFrom(),
                          from=>$dbresult->GetTo(),
                          id=>$self->{STREAM}->GetRoot($sid)->{id},

Modified: trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Stanza.pm
===================================================================
--- trunk/owl/perl/lib/Net/Jabber/Stanza.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/Net/Jabber/Stanza.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -1737,8 +1737,8 @@
 sub AddQuery     { my $self = shift; $self->AddChild(@_);     } 
 sub RemoveQuery  { my $self = shift; $self->RemoveChild(@_);  }
 
-sub _new_jid    { my $self = shift; return new Net::Jabber::JID(@_);    }
-sub _new_packet { my $self = shift; return new Net::Jabber::Stanza(@_); }
+sub _new_jid    { my $self = shift; return Net::Jabber::JID->new(@_);    }
+sub _new_packet { my $self = shift; return Net::Jabber::Stanza->new(@_); }
 
 
 sub _CustomSet_init

Modified: trunk/owl/perl/modules/Jabber/lib/Net/Jabber/XDB.pm
===================================================================
--- trunk/owl/perl/lib/Net/Jabber/XDB.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/Net/Jabber/XDB.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -43,7 +43,7 @@
   To initialize the XDB with a Jabber <xdb/> you must pass it the 
   XML::Parser Tree array.  For example:
 
-    my $xdb = new Net::Jabber::XDB(@tree);
+    my $xdb = Net::Jabber::XDB->new(@tree);
 
   There has been a change from the old way of handling the callbacks.
   You no longer have to do the above, a Net::Jabber::XDB object is passed
@@ -64,7 +64,7 @@
 
     use Net::Jabber;
 
-    $XDB = new Net::Jabber::XDB();
+    $XDB = Net::Jabber::XDB->new();
     $XDBType = $XDB->NewData( type );
     $XDBType->SetXXXXX("yyyyy");
 
@@ -417,7 +417,7 @@
     my %args;
     while($#_ >= 0) { $args{ lc pop(@_) } = pop(@_); }
 
-    my $reply = new Net::Jabber::XDB();
+    my $reply = Net::Jabber::XDB->new();
 
     $reply->SetID($self->GetID()) if ($self->GetID() ne "");
     $reply->SetType("result");

Modified: trunk/owl/perl/modules/Jabber/lib/Net/Jabber.pm
===================================================================
--- trunk/owl/perl/lib/Net/Jabber.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/Net/Jabber.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -60,11 +60,11 @@
 
     For a client:
       use Net::Jabber;
-      my $client = new Net::Jabber::Client();
+      my $client = Net::Jabber::Client->new();
 
     For a component:
       use Net::Jabber;
-      my $component = new Net::Jabber::Component();
+      my $component = Net::Jabber::Component->new();
 
 =head1 METHODS
 

Modified: trunk/owl/perl/modules/Jabber/lib/Net/XMPP/Client.pm
===================================================================
--- trunk/owl/perl/lib/Net/XMPP/Client.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/Net/XMPP/Client.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -53,7 +53,7 @@
 
     use Net::XMPP;
 
-    $Con = new Net::XMPP::Client();
+    $Con = Net::XMPP::Client->new();
 
     $Con->SetCallbacks(...);
 

Modified: trunk/owl/perl/modules/Jabber/lib/Net/XMPP/Connection.pm
===================================================================
--- trunk/owl/perl/lib/Net/XMPP/Connection.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/Net/XMPP/Connection.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -80,12 +80,12 @@
     while($#_ >= 0) { $self->{ARGS}->{ lc(pop(@_)) } = pop(@_); }
 
     $self->{DEBUG} =
-        new Net::XMPP::Debug(level      => $self->_arg("debuglevel",-1),
-                             file       => $self->_arg("debugfile","stdout"),
-                             time       => $self->_arg("debugtime",0),
-                             setdefault => 1,
-                             header     => "XMPP::Conn"
-                    );
+        Net::XMPP::Debug->new(level      => $self->_arg("debuglevel",-1),
+                              file       => $self->_arg("debugfile","stdout"),
+                              time       => $self->_arg("debugtime",0),
+                              setdefault => 1,
+                              header     => "XMPP::Conn"
+                             );
 
     $self->{SERVER} = {};
     $self->{SERVER}->{hostname} = "localhost";
@@ -97,11 +97,11 @@
     $self->{DISCONNECTED} = 0;
 
     $self->{STREAM} =
-        new XML::Stream(style      => "node",
-                        debugfh    => $self->{DEBUG}->GetHandle(),
-                        debuglevel => $self->{DEBUG}->GetLevel(),
-                        debugtime  => $self->{DEBUG}->GetTime(),
-                       );
+        XML::Stream->new(style      => "node",
+                         debugfh    => $self->{DEBUG}->GetHandle(),
+                         debuglevel => $self->{DEBUG}->GetLevel(),
+                         debugtime  => $self->{DEBUG}->GetTime(),
+                        );
     
     $self->{RCVDB}->{currentID} = 0;
 

Modified: trunk/owl/perl/modules/Jabber/lib/Net/XMPP/Debug.pm
===================================================================
--- trunk/owl/perl/lib/Net/XMPP/Debug.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/Net/XMPP/Debug.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -38,7 +38,7 @@
 
 =head2 Basic Functions
 
-    $Debug = new Net::XMPP::Debug();
+    $Debug = Net::XMPP::Debug->new();
 
     $Debug->Init(level=>2,
 	             file=>"stdout",
@@ -85,7 +85,7 @@
 
 =head1 EXAMPLE
 
-  $Debug = new Net::XMPP:Debug(level=>2,
+  $Debug = Net::XMPP:Debug->new(level=>2,
                                header=>"Example");
 
     $Debug->Log0("test");

Modified: trunk/owl/perl/modules/Jabber/lib/Net/XMPP/IQ.pm
===================================================================
--- trunk/owl/perl/lib/Net/XMPP/IQ.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/Net/XMPP/IQ.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -61,7 +61,7 @@
 
     use Net::XMPP;
 
-    $IQ = new Net::XMPP::IQ();
+    $IQ = Net::XMPP::IQ->new();
     $IQType = $IQ->NewChild( type );
     $IQType->SetXXXXX("yyyyy");
 
@@ -290,7 +290,7 @@
     return $self;
 }
 
-sub _iq { my $self = shift; return new Net::XMPP::IQ(); }
+sub _iq { my $self = shift; return Net::XMPP::IQ->new(); }
 
 $FUNCTIONS{Error}->{path} = 'error/text()';
 

Modified: trunk/owl/perl/modules/Jabber/lib/Net/XMPP/JID.pm
===================================================================
--- trunk/owl/perl/lib/Net/XMPP/JID.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/Net/XMPP/JID.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -41,9 +41,9 @@
     use Net::XMPP;
 
     sub foo {
-      my $foo = new Net::XMPP::Foo(@_);
+      my $foo = Net::XMPP::Foo->new(@_);
       my $from = $foo->GetFrom();
-      my $JID = new Net::XMPP::JID($from);
+      my $JID = Net::XMPP::JID->new($from);
       .
       .
       .
@@ -55,7 +55,7 @@
 
     use Net::XMPP;
 
-    $JID = new Net::XMPP::JID();
+    $JID = Net::XMPP::JID->new();
 
   Now you can call the creation functions below to populate the tag
   before sending it.

Modified: trunk/owl/perl/modules/Jabber/lib/Net/XMPP/Message.pm
===================================================================
--- trunk/owl/perl/lib/Net/XMPP/Message.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/Net/XMPP/Message.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -54,7 +54,7 @@
 
     use Net::XMPP;
 
-    $Mess = new Net::XMPP::Message();
+    $Mess = Net::XMPP::Message->new();
 
   Now you can call the creation functions below to populate the tag
   before sending it.
@@ -314,7 +314,7 @@
     return $self;
 }
 
-sub _message { my $self = shift; return new Net::XMPP::Message(); }
+sub _message { my $self = shift; return Net::XMPP::Message->new(); }
 
 
 $FUNCTIONS{Body}->{path}  = 'body/text()';

Modified: trunk/owl/perl/modules/Jabber/lib/Net/XMPP/Presence.pm
===================================================================
--- trunk/owl/perl/lib/Net/XMPP/Presence.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/Net/XMPP/Presence.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -54,7 +54,7 @@
 
     use Net::XMPP;
 
-    $Pres = new Net::XMPP::Presence();
+    $Pres = Net::XMPP::Presence->new();
 
   Now you can call the creation functions below to populate the tag
   before sending it.
@@ -269,7 +269,7 @@
     return $self;
 }
 
-sub _presence { my $self = shift; return new Net::XMPP::Presence(); }
+sub _presence { my $self = shift; return Net::XMPP::Presence->new(); }
 
 
 $FUNCTIONS{Error}->{path} = 'error/text()';

Modified: trunk/owl/perl/modules/Jabber/lib/Net/XMPP/Protocol.pm
===================================================================
--- trunk/owl/perl/lib/Net/XMPP/Protocol.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/Net/XMPP/Protocol.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -73,7 +73,7 @@
 =head2 Basic Functions
 
     use Net::XMPP qw( Client );
-    $Con = new Net::XMPP::Client();                  # From
+    $Con = Net::XMPP::Client->new();                  # From
     $status = $Con->Connect(hostname=>"jabber.org"); # Net::XMPP::Client
 
     $Con->SetCallBacks(send=>\&sendCallBack,
@@ -2048,7 +2048,7 @@
 {
     my $self = shift;
 
-    return new Net::XMPP::PrivacyLists(connection=>$self);
+    return Net::XMPP::PrivacyLists->new(connection=>$self);
 }
 
 
@@ -2371,7 +2371,7 @@
 {
     my $self = shift;
 
-    return new Net::XMPP::Roster(connection=>$self);
+    return Net::XMPP::Roster->new(connection=>$self);
 }
 
 

Modified: trunk/owl/perl/modules/Jabber/lib/Net/XMPP/Roster.pm
===================================================================
--- trunk/owl/perl/lib/Net/XMPP/Roster.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/Net/XMPP/Roster.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -40,9 +40,9 @@
   
 =head2 Basic Functions
 
-  my $Client = new Net::XMPP::Client(...);
+  my $Client = Net::XMPP::Client->new(...);
 
-  my $Roster = new Net::XMPP::Roster(connection=>$Client);
+  my $Roster = Net::XMPP::Roster->new(connection=>$Client);
     or
   my $Roster = $Client->Roster();
 
@@ -543,7 +543,7 @@
                      exists($self->{JIDS}->{$jid}->{groups}) &&
                      ($#{$self->{JIDS}->{$jid}->{groups}} > -1));
 
-            push(@jids,new Net::XMPP::JID($jid));
+            push(@jids, Net::XMPP::JID->new($jid));
         }
     }
     
@@ -554,7 +554,7 @@
         {
             foreach my $jid (keys(%{$self->{GROUPS}->{$group}}))
             {
-                push(@jids,new Net::XMPP::JID($jid));
+                push(@jids, Net::XMPP::JID->new($jid));
             }
         }
     }

Modified: trunk/owl/perl/modules/Jabber/lib/Net/XMPP/Stanza.pm
===================================================================
--- trunk/owl/perl/lib/Net/XMPP/Stanza.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/Net/XMPP/Stanza.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -215,8 +215,8 @@
 use Net::XMPP::Namespaces;
 use vars qw( $AUTOLOAD %FUNCTIONS $DEBUG );
 
-$DEBUG = new Net::XMPP::Debug(usedefault=>1,
-                              header=>"XMPP");
+$DEBUG = Net::XMPP::Debug->new(usedefault=>1,
+                               header=>"XMPP");
 
 # XXX need to look at evals and $@
 
@@ -1411,7 +1411,7 @@
 sub _new_jid
 {
     my $self = shift;
-    return new Net::XMPP::JID(@_);
+    return Net::XMPP::JID->new(@_);
 }
 
 
@@ -1423,7 +1423,7 @@
 sub _new_packet
 {
     my $self = shift;
-    return new Net::XMPP::Stanza(@_);
+    return Net::XMPP::Stanza->new(@_);
 }
 
 

Modified: trunk/owl/perl/modules/Jabber/lib/Net/XMPP.pm
===================================================================
--- trunk/owl/perl/lib/Net/XMPP.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/Net/XMPP.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -60,7 +60,7 @@
 =head1 EXAMPLES
 
       use Net::XMPP;
-      my $client = new Net::XMPP::Client();
+      my $client = Net::XMPP::Client->new();
 
 =head1 METHODS
 

Copied: trunk/owl/perl/modules/Jabber/lib/XML (from rev 664, trunk/owl/perl/lib/XML)

Modified: trunk/owl/perl/modules/Jabber/lib/XML/Stream.pm
===================================================================
--- trunk/owl/perl/lib/XML/Stream.pm	2007-03-14 23:11:46 UTC (rev 664)
+++ trunk/owl/perl/modules/Jabber/lib/XML/Stream.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -680,7 +680,7 @@
         $self->debug(1,"Connect: srv requested");
         if ($NETDNS)
         {
-            my $res = new Net::DNS::Resolver();
+            my $res = Net::DNS::Resolver->new();
             my $query = $res->query($self->{SIDS}->{newconnection}->{srv}.".".$self->{SIDS}->{newconnection}->{hostname},"SRV");
             
             if ($query)

Deleted: trunk/owl/perl/modules/jabber.pl
===================================================================
--- trunk/owl/perl/modules/jabber.pl	2007-03-28 02:04:10 UTC (rev 688)
+++ trunk/owl/perl/modules/jabber.pl	2007-03-29 01:32:11 UTC (rev 689)
@@ -1,1533 +0,0 @@
-# -*- mode: cperl; cperl-indent-level: 4; indent-tabs-mode: nil -*-
-use warnings;
-use strict;
-
-package BarnOwl::Jabber;
-
-use Authen::SASL qw(Perl);
-use Net::Jabber;
-use Net::Jabber::MUC;
-use Net::DNS;
-use Getopt::Long;
-
-BEGIN {
-    if(eval {require IO::Socket::SSL;}) {
-        if($IO::Socket::SSL::VERSION eq "0.97") {
-            BarnOwl::error("You are using IO::Socket:SSL 0.97, which \n" .
-                           "contains bugs causing it not to work with barnowl's jabber.pl. We \n" .
-                           "recommend updating to the latest IO::Socket::SSL from CPAN. \n");
-            die("Not loading jabber.pl\n");
-        }
-    }       
-}
-
-no warnings 'redefine';
-
-################################################################################
-# owl perl jabber support
-#
-# XXX Todo:
-# Rosters for MUCs
-# More user feedback
-#  * joining MUC
-#  * parting MUC
-#  * presence (Roster and MUC)
-# Implementing formatting and logging callbacks for C
-# Appropriate callbacks for presence subscription messages.
-#
-################################################################################
-
-
-################################################################################
-################################################################################
-package BarnOwl::Jabber::Connection;
-
-use base qw(Net::Jabber::Client);
-
-sub new {
-    my $class = shift;
-
-    my %args = ();
-    if(BarnOwl::getvar('debug') eq 'on') {
-        $args{debuglevel} = 1;
-        $args{debugfile} = 'jabber.log';
-    }
-    my $self = $class->SUPER::new(%args);
-    $self->{_BARNOWL_MUCS} = [];
-    return $self;
-}
-
-=head2 MUCJoin
-
-Extends MUCJoin to keep track of the MUCs we're joined to as
-Net::Jabber::MUC objects. Takes the same arguments as
-L<Net::Jabber::MUC/new> and L<Net::Jabber::MUC/Connect>
-
-=cut
-
-sub MUCJoin {
-    my $self = shift;
-    my $muc = Net::Jabber::MUC->new(connection => $self, @_);
-    $muc->Join(@_);
-
-    # Add MUC to list of MUCs, unless we're just changing nicks.
-    push @{$self->MUCs}, $muc unless grep {$_->BaseJID eq $muc->BaseJID} $self->MUCs;
-}
-
-=head2 MUCLeave ARGS
-
-Leave a MUC. The MUC is specified in the same form as L</FindMUC>
-
-=cut
-
-sub MUCLeave {
-    my $self = shift;
-    my $muc = $self->FindMUC(@_);
-    return unless $muc;
-
-    $muc->Leave();
-    $self->{_BARNOWL_MUCS} = [grep {$_->BaseJID ne $muc->BaseJID} $self->MUCs];
-}
-
-=head2 FindMUC ARGS
-
-Return the Net::Jabber::MUC object representing a specific MUC we're
-joined to, undef if it doesn't exists. ARGS can be either JID => $JID,
-or Room => $room, Server => $server.
-
-=cut
-
-sub FindMUC {
-    my $self = shift;
-
-    my %args;
-    while($#_ >= 0) { $args{ lc(pop(@_)) } = pop(@_); }
-
-    my $jid;
-    if($args{jid}) {
-        $jid = $args{jid};
-    } elsif($args{room} && $args{server}) {
-        $jid = Net::Jabber::JID->new(userid => $args{room},
-                                     server => $args{server});
-    }
-    $jid = $jid->GetJID('base') if UNIVERSAL::isa($jid, 'Net::XMPP::JID');
-
-    foreach my $muc ($self->MUCs) {
-        return $muc if $muc->BaseJID eq $jid;
-    }
-    return undef;
-}
-
-=head2 MUCs
-
-Returns a list (or arrayref in scalar context) of Net::Jabber::MUC
-objects we believe ourself to be connected to.
-
-=cut
-
-sub MUCs {
-    my $self = shift;
-    my $mucs = $self->{_BARNOWL_MUCS};
-    return wantarray ? @$mucs : $mucs;
-}
-
-################################################################################
-################################################################################
-package BarnOwl::Jabber::ConnectionManager;
-sub new {
-    my $class = shift;
-    return bless { }, $class;
-}
-
-sub addConnection {
-    my $self = shift;
-    my $jidStr = shift;
-
-    my $client = BarnOwl::Jabber::Connection->new;
-
-    $self->{$jidStr}->{Client} = $client;
-    $self->{$jidStr}->{Roster} = $client->Roster();
-    $self->{$jidStr}->{Status} = "available";
-    return $client;
-}
-
-sub removeConnection {
-    my $self = shift;
-    my $jidStr = shift;
-    return 0 unless exists $self->{$jidStr};
-
-    $self->{$jidStr}->{Client}->Disconnect()
-      if $self->{$jidStr}->{Client};
-    delete $self->{$jidStr};
-
-    return 1;
-}
-
-sub connected {
-    my $self = shift;
-    return scalar keys %{ $self };
-}
-
-sub getJIDs {
-    my $self = shift;
-    return keys %{ $self };
-}
-
-sub jidExists {
-    my $self = shift;
-    my $jidStr = shift;
-    return exists $self->{$jidStr};
-}
-
-sub sidExists {
-    my $self = shift;
-    my $sid = shift || "";
-    foreach my $c ( values %{ $self } ) {
-        return 1 if ($c->{Client}->{SESSION}->{id} eq $sid);
-    }
-    return 0;
-}
-
-sub getConnectionFromSid {
-    my $self = shift;
-    my $sid = shift;
-    foreach my $c (values %{ $self }) {
-        return $c->{Client} if $c->{Client}->{SESSION}->{id} eq $sid;
-    }
-    return undef;
-}
-
-sub getConnectionFromJID {
-    my $self = shift;
-    my $jid = shift;
-    $jid = $jid->GetJID('full') if UNIVERSAL::isa($jid, 'Net::XMPP::JID');
-    return $self->{$jid}->{Client} if exists $self->{$jid};
-}
-
-sub getRosterFromSid {
-    my $self = shift;
-    my $sid = shift;
-    foreach my $c (values %{ $self }) {
-        return $c->{Roster}
-          if $c->{Client}->{SESSION}->{id} eq $sid;
-    }
-    return undef;
-}
-
-sub getRosterFromJID {
-    my $self = shift;
-    my $jid = shift;
-    $jid = $jid->GetJID('full') if UNIVERSAL::isa($jid, 'Net::XMPP::JID');
-    return $self->{$jid}->{Roster} if exists $self->{$jid};
-}
-################################################################################
-
-package BarnOwl::Jabber;
-
-our $conn = new BarnOwl::Jabber::ConnectionManager unless $conn;;
-our %vars;
-
-sub onStart {
-    if ( *BarnOwl::queue_message{CODE} ) {
-        register_owl_commands();
-        register_keybindings() unless $BarnOwl::reload;
-        register_filters() unless $BarnOwl::reload;
-        push @::onMainLoop,     sub { BarnOwl::Jabber::onMainLoop(@_) };
-        push @::onGetBuddyList, sub { BarnOwl::Jabber::onGetBuddyList(@_) };
-        $vars{show} = '';
-    } else {
-        # Our owl doesn't support queue_message. Unfortunately, this
-        # means it probably *also* doesn't support BarnOwl::error. So just
-        # give up silently.
-    }
-}
-
-push @::onStartSubs, sub { BarnOwl::Jabber::onStart(@_) };
-
-sub onMainLoop {
-    return if ( !$conn->connected() );
-
-    $vars{status_changed} = 0;
-    my $idletime = BarnOwl::getidletime();
-    if ($idletime >= 900 && $vars{show} eq 'away') {
-        $vars{show} = 'xa';
-        $vars{status} = 'Auto extended-away after 15 minutes idle.';
-        $vars{status_changed} = 1;
-    } elsif ($idletime >= 300 && $vars{show} eq '') {
-        $vars{show} = 'away';
-        $vars{status} = 'Auto away after 5 minutes idle.';
-        $vars{status_changed} = 1;
-    } elsif ($idletime == 0 && $vars{show} ne '') {
-        $vars{show} = '';
-        $vars{status} = '';
-        $vars{status_changed} = 1;
-    }
-
-    foreach my $jid ( $conn->getJIDs() ) {
-        my $client = $conn->getConnectionFromJID($jid);
-
-        unless($client) {
-            $conn->removeConnection($jid);
-            BarnOwl::error("Connection for $jid undefined -- error in reload?");
-        }
-
-        my $status = $client->Process(0);
-        if ( !defined($status) ) {
-            BarnOwl::error("Jabber account $jid disconnected!");
-            do_logout($jid);
-        }
-        if ($::shutdown) {
-            do_logout($jid);
-            return;
-        }
-        if ($vars{status_changed}) {
-            my $p = new Net::Jabber::Presence;
-            $p->SetShow($vars{show}) if $vars{show};
-            $p->SetStatus($vars{status}) if $vars{status};
-            $client->Send($p);
-        }
-    }
-}
-
-sub blist_listBuddy {
-    my $roster = shift;
-    my $buddy  = shift;
-    my $blistStr .= "    ";
-    my %jq  = $roster->query($buddy);
-    my $res = $roster->resource($buddy);
-
-    my $name = $jq{name} || $buddy->GetUserID();
-
-    $blistStr .= sprintf '%-15s %s', $name, $buddy->GetJID();
-
-    if ($res) {
-        my %rq = $roster->resourceQuery( $buddy, $res );
-        $blistStr .= " [" . ( $rq{show} ? $rq{show} : 'online' ) . "]";
-        $blistStr .= " " . $rq{status} if $rq{status};
-        $blistStr = boldify($blistStr);
-    }
-    else {
-	if ($jq{ask}) {
-            $blistStr .= " [pending]";
-	}
-	elsif ($jq{subscription} eq 'none' || $jq{subscription} eq 'from') {
-	    $blistStr .= " [not subscribed]";
-	}
-	else {
-	    $blistStr .= " [offline]";
-	}
-    }
-    return $blistStr . "\n";
-}
-
-sub getSingleBuddyList {
-    my $jid = shift;
-    $jid = resolveConnectedJID($jid);
-    return "" unless $jid;
-    my $blist = "";
-    my $roster = $conn->getRosterFromJID($jid);
-    if ($roster) {
-        $blist .= "\n" . boldify("Jabber Roster for $jid\n");
-
-        foreach my $group ( $roster->groups() ) {
-            $blist .= "  Group: $group\n";
-            my @buddies = $roster->jids( 'group', $group );
-            foreach my $buddy ( @buddies ) {
-                $blist .= blist_listBuddy( $roster, $buddy );
-            }
-        }
-
-        my @unsorted = $roster->jids('nogroup');
-        if (@unsorted) {
-            $blist .= "  [unsorted]\n";
-            foreach my $buddy (@unsorted) {
-                $blist .= blist_listBuddy( $roster, $buddy );
-            }
-        }
-    }
-    return $blist;
-}
-
-sub onGetBuddyList {
-    my $blist = "";
-    foreach my $jid ($conn->getJIDs()) {
-        $blist .= getSingleBuddyList($jid);
-    }
-    return $blist;
-}
-
-################################################################################
-### Owl Commands
-sub register_owl_commands() {
-    BarnOwl::new_command(
-        jabberlogin => \&cmd_login,
-        { summary => "Log into jabber", },
-        { usage   => "jabberlogin JID [PASSWORD]" }
-    );
-    BarnOwl::new_command(
-        jabberlogout => \&cmd_logout,
-        { summary => "Log out of jabber" }
-    );
-    BarnOwl::new_command(
-        jwrite => \&cmd_jwrite,
-        {
-            summary => "Send a Jabber Message",
-            usage   => "jwrite JID [-t thread] [-s subject]"
-        }
-    );
-    BarnOwl::new_command(
-        jlist => \&cmd_jlist,
-        {
-            summary => "Show your Jabber roster.",
-            usage   => "jlist"
-        }
-    );
-    BarnOwl::new_command(
-        jmuc => \&cmd_jmuc,
-        {
-            summary     => "Jabber MUC related commands.",
-            description => "jmuc sends jabber commands related to muc.\n\n"
-              . "The following commands are available\n\n"
-              . "join <muc>  Join a muc.\n\n"
-              . "part <muc>  Part a muc.\n"
-              . "            The muc is taken from the current message if not supplied.\n\n"
-              . "invite <jid> <muc>\n"
-              . "            Invite <jid> to <muc>.\n"
-              . "            The muc is taken from the current message if not supplied.\n\n"
-              . "configure <muc>\n"
-              . "            Configures a MUC.\n"
-              . "            Necessary to initalize a new MUC.\n"
-              . "            At present, only the default configuration is supported.\n"
-              . "            The muc is taken from the current message if not supplied.\n\n"
-              . "presence <muc>\n"
-              . "            Shows the roster for <muc>.\n"
-              . "            The muc is taken from the current message if not supplied.\n\n"
-              . "presence -a\n"
-              . "            Shows rosters for all MUCs you're participating in.\n\n",
-            usage => "jmuc COMMAND ARGS"
-        }
-    );
-    BarnOwl::new_command(
-        jroster => \&cmd_jroster,
-        {
-            summary     => "Jabber Roster related commands.",
-            description => "jroster sends jabber commands related to rosters.\n\n"
-              . "The following commands are available\n\n"
-              . "sub <jid>     Subscribe to <jid>'s presence. (implicit add)\n\n"
-              . "add <jid>     Adds <jid> to your roster.\n\n"
-              . "unsub <jid>   Unsubscribe from <jid>'s presence.\n\n"
-              . "remove <jid>  Removes <jid> to your roster. (implicit unsub)\n\n"
-              . "auth <jid>    Authorizes <jid> to subscribe to your presence.\n\n"
-              . "deauth <jid>  De-authorizes <jid>'s subscription to your presence.\n\n"
-              . "The following arguments are supported for all commands\n\n"
-              . "-a <jid>      Specify which account to make the roster changes on.\n"
-              . "              Required if you're signed into more than one account.\n\n"
-              . "The following arguments only work with the add and sub commands.\n\n"
-              . "-g <group>    Add <jid> to group <group>.\n"
-              . "              May be specified more than once, will not remove <jid> from any groups.\n\n"
-              . "-p            Purge. Removes <jid> from all groups.\n"
-              . "              May be combined with -g completely alter <jid>'s groups.\n\n"
-              . "-n <name>     Sets <name> as <jid>'s short name.\n\n"
-              . "Note: Unless -n is used, you can specify multiple <jid> arguments.\n",
-            usage       => "jroster COMMAND ARGS"
-        }
-    );
-}
-
-sub register_keybindings {
-    BarnOwl::bindkey("recv j command start-command jwrite ");
-}
-
-sub register_filters {
-    BarnOwl::filter('jabber type ^jabber$');
-}
-
-sub cmd_login {
-    my $cmd = shift;
-    my $jid = new Net::Jabber::JID;
-    $jid->SetJID(shift);
-    my $password = '';
-    $password = shift if @_;
-
-    my $uid           = $jid->GetUserID();
-    my $componentname = $jid->GetServer();
-    my $resource      = $jid->GetResource() || 'owl';
-    $jid->SetResource($resource);
-    my $jidStr = $jid->GetJID('full');
-
-    if ( !$uid || !$componentname ) {
-        BarnOwl::error("usage: $cmd JID");
-        return;
-    }
-
-    if ( $conn->jidExists($jidStr) ) {
-        BarnOwl::error("Already logged in as $jidStr.");
-        return;
-    }
-
-    my ( $server, $port ) = getServerFromJID($jid);
-
-    $vars{jlogin_jid} = $jidStr;
-    $vars{jlogin_connhash} = {
-        hostname      => $server,
-        tls           => 1,
-        port          => $port,
-        componentname => $componentname
-    };
-    $vars{jlogin_authhash} =
-      { username => $uid,
-        resource => $resource,
-    };
-
-    return do_login($password);
-}
-
-sub do_login {
-    $vars{jlogin_password} = shift;
-    $vars{jlogin_authhash}->{password} = sub { return $vars{jlogin_password} || '' };
-    my $jidStr = $vars{jlogin_jid};
-    if ( !$jidStr && $vars{jlogin_havepass}) {
-        BarnOwl::error("Got password but have no jid!");
-    }
-    else
-    {
-        my $client = $conn->addConnection($jidStr);
-
-        #XXX Todo: Add more callbacks.
-        # * MUC presence handlers
-        # We use the anonymous subrefs in order to have the correct behavior
-        # when we reload
-        $client->SetMessageCallBacks(
-            chat      => sub { BarnOwl::Jabber::process_incoming_chat_message(@_) },
-            error     => sub { BarnOwl::Jabber::process_incoming_error_message(@_) },
-            groupchat => sub { BarnOwl::Jabber::process_incoming_groupchat_message(@_) },
-            headline  => sub { BarnOwl::Jabber::process_incoming_headline_message(@_) },
-            normal    => sub { BarnOwl::Jabber::process_incoming_normal_message(@_) }
-        );
-        $client->SetPresenceCallBacks(
-            available    => sub { BarnOwl::Jabber::process_presence_available(@_) },
-            unavailable  => sub { BarnOwl::Jabber::process_presence_available(@_) },
-            subscribe    => sub { BarnOwl::Jabber::process_presence_subscribe(@_) },
-            subscribed   => sub { BarnOwl::Jabber::process_presence_subscribed(@_) },
-            unsubscribe  => sub { BarnOwl::Jabber::process_presence_unsubscribe(@_) },
-            unsubscribed => sub { BarnOwl::Jabber::process_presence_unsubscribed(@_) },
-            error        => sub { BarnOwl::Jabber::process_presence_error(@_) });
-
-        my $status = $client->Connect( %{ $vars{jlogin_connhash} } );
-        if ( !$status ) {
-            $conn->removeConnection($jidStr);
-            BarnOwl::error("We failed to connect");
-        } else {
-            my @result = $client->AuthSend( %{ $vars{jlogin_authhash} } );
-
-            if ( !@result || $result[0] ne 'ok' ) {
-                if ( !$vars{jlogin_havepass} && ( !@result || $result[0] eq '401' ) ) {
-                    $vars{jlogin_havepass} = 1;
-                    $conn->removeConnection($jidStr);
-                    BarnOwl::start_password( "Password for $jidStr: ", \&do_login );
-                    return "";
-                }
-                $conn->removeConnection($jidStr);
-                BarnOwl::error( "Error in connect: " . join( " ", @result ) );
-            } else {
-                $conn->getRosterFromJID($jidStr)->fetch();
-                $client->PresenceSend( priority => 1 );
-                queue_admin_msg("Connected to jabber as $jidStr");
-            }
-        }
-
-    }
-    delete $vars{jlogin_jid};
-    $vars{jlogin_password} =~ tr/\0-\377/x/ if $vars{jlogin_password};
-    delete $vars{jlogin_password};
-    delete $vars{jlogin_havepass};
-    delete $vars{jlogin_connhash};
-    delete $vars{jlogin_authhash};
-    return "";
-}
-
-sub do_logout {
-    my $jid = shift;
-    my $disconnected = $conn->removeConnection($jid);
-    queue_admin_msg("Jabber disconnected ($jid).") if $disconnected;
-}
-
-sub cmd_logout {
-    # Logged into multiple accounts
-    if ( $conn->connected() > 1 ) {
-        # Logged into multiple accounts, no accout specified.
-        if ( !$_[1] ) {
-            my $errStr =
-              "You are logged into multiple accounts. Please specify an account to log out of.\n";
-            foreach my $jid ( $conn->getJIDs() ) {
-                $errStr .= "\t$jid\n";
-            }
-            queue_admin_msg($errStr);
-        }
-        # Logged into multiple accounts, account specified.
-        else {
-            if ( $_[1] eq '-a' )    #All accounts.
-            {
-                foreach my $jid ( $conn->getJIDs() ) {
-                    do_logout($jid);
-                }
-            }
-            else                    #One account.
-            {
-                my $jid = resolveConnectedJID( $_[1] );
-                do_logout($jid) if ( $jid ne '' );
-            }
-        }
-    }
-    else                            # Only one account logged in.
-    {
-        do_logout( ( $conn->getJIDs() )[0] );
-    }
-    return "";
-}
-
-sub cmd_jlist {
-    if ( !( scalar $conn->getJIDs() ) ) {
-        BarnOwl::error("You are not logged in to Jabber.");
-        return;
-    }
-    BarnOwl::popless_ztext( onGetBuddyList() );
-}
-
-sub cmd_jwrite {
-    if ( !$conn->connected() ) {
-        BarnOwl::error("You are not logged in to Jabber.");
-        return;
-    }
-
-    my $jwrite_to      = "";
-    my $jwrite_from    = "";
-    my $jwrite_sid     = "";
-    my $jwrite_thread  = "";
-    my $jwrite_subject = "";
-    my ($to, $from);
-    my $jwrite_type    = "chat";
-
-    my @args = @_;
-    shift;
-    local @ARGV = @_;
-    my $gc;
-    GetOptions(
-        'thread=s'  => \$jwrite_thread,
-        'subject=s' => \$jwrite_subject,
-        'account=s' => \$from,
-        'id=s'     =>  \$jwrite_sid,
-    );
-    $jwrite_type = 'groupchat' if $gc;
-
-    if ( scalar @ARGV != 1 ) {
-        BarnOwl::error(
-            "Usage: jwrite JID [-t thread] [-s 'subject'] [-a account]");
-        return;
-    }
-    else {
-        $to = shift @ARGV;
-    }
-
-    my @candidates = guess_jwrite($from, $to);
-
-    unless(scalar @candidates) {
-        die("Unable to resolve JID $to");
-    }
-
-    @candidates = grep {defined $_->[0]} @candidates;
-
-    unless(scalar @candidates) {
-        if(!$from) {
-            die("You must specify an account with -a");
-        } else {
-            die("Unable to resolve account $from");
-        }
-    }
-
-
-    ($jwrite_from, $jwrite_to, $jwrite_type) = @{$candidates[0]};
-
-    $vars{jwrite} = {
-        to      => $jwrite_to,
-        from    => $jwrite_from,
-        sid     => $jwrite_sid,
-        subject => $jwrite_subject,
-        thread  => $jwrite_thread,
-        type    => $jwrite_type
-    };
-
-    if(scalar @candidates > 1) {
-        BarnOwl::message(
-            "Warning: Guessing account and/or destination JID"
-           );
-    } else  {
-        BarnOwl::message(
-            "Type your message below.  End with a dot on a line by itself.  ^C will quit."
-           );
-    }
-
-    my $cmd = "jwrite $jwrite_to -a $jwrite_from";
-    $cmd .= " -t $jwrite_thread" if $jwrite_thread;
-    $cmd .= " -t $jwrite_subject" if $jwrite_subject;
-    BarnOwl::start_edit_win( $cmd, \&process_owl_jwrite );
-}
-
-sub cmd_jmuc {
-    die "You are not logged in to Jabber" unless $conn->connected();
-    my $ocmd = shift;
-    my $cmd  = shift;
-    if ( !$cmd ) {
-
-        #XXX TODO: Write general usage for jmuc command.
-        return;
-    }
-
-    my %jmuc_commands = (
-        join      => \&jmuc_join,
-        part      => \&jmuc_part,
-        invite    => \&jmuc_invite,
-        configure => \&jmuc_configure,
-        presence  => \&jmuc_presence
-    );
-    my $func = $jmuc_commands{$cmd};
-    if ( !$func ) {
-        BarnOwl::error("jmuc: Unknown command: $cmd");
-        return;
-    }
-
-    {
-        local @ARGV = @_;
-        my $jid;
-        my $muc;
-        my $m = BarnOwl::getcurmsg();
-        if ( $m && $m->is_jabber && $m->{jtype} eq 'groupchat' ) {
-            $muc = $m->{room};
-            $jid = $m->{to};
-        }
-
-        my $getopt = Getopt::Long::Parser->new;
-        $getopt->configure('pass_through');
-        $getopt->getoptions( 'account=s' => \$jid );
-        $jid ||= defaultJID();
-        if ($jid) {
-            $jid = resolveConnectedJID($jid);
-            return unless $jid;
-        }
-        else {
-            BarnOwl::error('You must specify an account with -a {jid}');
-        }
-        return $func->( $jid, $muc, @ARGV );
-    }
-}
-
-sub jmuc_join {
-    my ( $jid, $muc, @args ) = @_;
-    local @ARGV = @args;
-    my $password;
-    GetOptions( 'password=s' => \$password );
-
-    $muc = shift @ARGV
-      or die("Usage: jmuc join MUC [-p password] [-a account]");
-
-    $muc = Net::Jabber::JID->new($muc);
-    $jid = Net::Jabber::JID->new($jid);
-    $muc->SetResource($jid->GetJID('full')) unless length $muc->GetResource();
-
-    $conn->getConnectionFromJID($jid)->MUCJoin(JID      => $muc,
-                                                  Password => $password,
-                                                  History  => {
-                                                      MaxChars => 0
-                                                     });
-    return;
-}
-
-sub jmuc_part {
-    my ( $jid, $muc, @args ) = @_;
-
-    $muc = shift @args if scalar @args;
-    die("Usage: jmuc part MUC [-a account]") unless $muc;
-
-    $conn->getConnectionFromJID($jid)->MUCLeave(JID => $muc);
-    queue_admin_msg("$jid has left $muc.");
-}
-
-sub jmuc_invite {
-    my ( $jid, $muc, @args ) = @_;
-
-    my $invite_jid = shift @args;
-    $muc = shift @args if scalar @args;
-
-    die('Usage: jmuc invite JID [muc] [-a account]')
-      unless $muc && $invite_jid;
-
-    my $message = Net::Jabber::Message->new();
-    $message->SetTo($muc);
-    my $x = $message->NewChild('http://jabber.org/protocol/muc#user');
-    $x->AddInvite();
-    $x->GetInvite()->SetTo($invite_jid);
-    $conn->getConnectionFromJID($jid)->Send($message);
-    queue_admin_msg("$jid has invited $invite_jid to $muc.");
-}
-
-sub jmuc_configure {
-    my ( $jid, $muc, @args ) = @_;
-    $muc = shift @args if scalar @args;
-    die("Usage: jmuc configure [muc]") unless $muc;
-    my $iq = Net::Jabber::IQ->new();
-    $iq->SetTo($muc);
-    $iq->SetType('set');
-    my $query = $iq->NewQuery("http://jabber.org/protocol/muc#owner");
-    my $x     = $query->NewChild("jabber:x:data");
-    $x->SetType('submit');
-
-    $conn->getConnectionFromJID($jid)->Send($iq);
-    queue_admin_msg("Accepted default instant configuration for $muc");
-}
-
-sub jmuc_presence_single {
-    my $m = shift;
-    my @jids = $m->Presence();
-    return "JIDs present in " . $m->BaseJID . "\n\t"
-      . join("\n\t", map {$_->GetResource}@jids) . "\n";
-}
-
-sub jmuc_presence {
-    my ( $jid, $muc, @args ) = @_;
-
-    $muc = shift @args if scalar @args;
-    die("Usage: jmuc presence MUC") unless $muc;
-
-    if ($muc eq '-a') {
-        my $str = "";
-        foreach my $jid ($conn->getJIDs()) {
-            $str .= boldify("Conferences for $jid:\n");
-            my $connection = $conn->getConnectionFromJID($jid);
-            foreach my $muc ($connection->MUCs) {
-                $str .= jmuc_presence_single($muc)."\n";
-            }
-        }
-        BarnOwl::popless_ztext($str);
-    }
-    else {
-        my $m = $conn->getConnectionFromJID($jid)->FindMUC(jid => $muc);
-        die("No such muc: $muc") unless $m;
-        BarnOwl::popless_ztext(jmuc_presence_single($m));
-    }
-}
-
-
-#XXX TODO: Consider merging this with jmuc and selecting off the first two args.
-sub cmd_jroster {
-    die "You are not logged in to Jabber" unless $conn->connected();
-    my $ocmd = shift;
-    my $cmd  = shift;
-    if ( !$cmd ) {
-
-        #XXX TODO: Write general usage for jroster command.
-        return;
-    }
-
-    my %jroster_commands = (
-        sub      => \&jroster_sub,
-        unsub    => \&jroster_unsub,
-        add      => \&jroster_add,
-        remove   => \&jroster_remove,
-        auth     => \&jroster_auth,
-        deauth   => \&jroster_deauth
-    );
-    my $func = $jroster_commands{$cmd};
-    if ( !$func ) {
-        BarnOwl::error("jroster: Unknown command: $cmd");
-        return;
-    }
-
-    {
-        local @ARGV = @_;
-        my $jid;
-        my $name;
-        my @groups;
-        my $purgeGroups;
-        my $getopt = Getopt::Long::Parser->new;
-        $getopt->configure('pass_through');
-        $getopt->getoptions(
-            'account=s' => \$jid,
-            'group=s' => \@groups,
-            'purgegroups' => \$purgeGroups,
-            'name=s' => \$name
-        );
-        $jid ||= defaultJID();
-        if ($jid) {
-            $jid = resolveConnectedJID($jid);
-            return unless $jid;
-        }
-        else {
-            BarnOwl::error('You must specify an account with -a {jid}');
-        }
-        return $func->( $jid, $name, \@groups, $purgeGroups,  @ARGV );
-    }
-}
-
-sub jroster_sub {
-    my $jid = shift;
-    my $name = shift;
-    my @groups = @{ shift() };
-    my $purgeGroups = shift;
-    my $baseJID = baseJID($jid);
-
-    my $roster = $conn->getRosterFromJID($jid);
-
-    # Adding lots of users with the same name is a bad idea.
-    $name = "" unless (1 == scalar(@ARGV));
-
-    my $p = new Net::Jabber::Presence;
-    $p->SetType('subscribe');
-
-    foreach my $to (@ARGV) {
-        jroster_add($jid, $name, \@groups, $purgeGroups, ($to)) unless ($roster->exists($to));
-
-        $p->SetTo($to);
-        $conn->getConnectionFromJID($jid)->Send($p);
-        queue_admin_msg("You ($baseJID) have requested a subscription to ($to)'s presence.");
-    }
-}
-
-sub jroster_unsub {
-    my $jid = shift;
-    my $name = shift;
-    my @groups = @{ shift() };
-    my $purgeGroups = shift;
-    my $baseJID = baseJID($jid);
-
-    my $p = new Net::Jabber::Presence;
-    $p->SetType('unsubscribe');
-    foreach my $to (@ARGV) {
-        $p->SetTo($to);
-        $conn->getConnectionFromJID($jid)->Send($p);
-        queue_admin_msg("You ($baseJID) have unsubscribed from ($to)'s presence.");
-    }
-}
-
-sub jroster_add {
-    my $jid = shift;
-    my $name = shift;
-    my @groups = @{ shift() };
-    my $purgeGroups = shift;
-    my $baseJID = baseJID($jid);
-
-    my $roster = $conn->getRosterFromJID($jid);
-
-    # Adding lots of users with the same name is a bad idea.
-    $name = "" unless (1 == scalar(@ARGV));
-
-    foreach my $to (@ARGV) {
-        my %jq  = $roster->query($to);
-        my $iq = new Net::Jabber::IQ;
-        $iq->SetType('set');
-        my $item = new XML::Stream::Node('item');
-        $iq->NewChild('jabber:iq:roster')->AddChild($item);
-
-        my %allGroups = ();
-
-        foreach my $g (@groups) {
-            $allGroups{$g} = $g;
-        }
-
-        unless ($purgeGroups) {
-            foreach my $g (@{$jq{groups}}) {
-                $allGroups{$g} = $g;
-            }
-        }
-
-        foreach my $g (keys %allGroups) {
-            $item->add_child('group')->add_cdata($g);
-        }
-
-        $item->put_attrib(jid => $to);
-        $item->put_attrib(name => $name) if $name;
-        $conn->getConnectionFromJID($jid)->Send($iq);
-        my $msg = "$baseJID: "
-          . ($name ? "$name ($to)" : "($to)")
-          . " is on your roster in the following groups: { "
-          . join(" , ", keys %allGroups)
-          . " }";
-        queue_admin_msg($msg);
-    }
-}
-
-sub jroster_remove {
-    my $jid = shift;
-    my $name = shift;
-    my @groups = @{ shift() };
-    my $purgeGroups = shift;
-    my $baseJID = baseJID($jid);
-
-    my $iq = new Net::Jabber::IQ;
-    $iq->SetType('set');
-    my $item = new XML::Stream::Node('item');
-    $iq->NewChild('jabber:iq:roster')->AddChild($item);
-    $item->put_attrib(subscription=> 'remove');
-    foreach my $to (@ARGV) {
-        $item->put_attrib(jid => $to);
-        $conn->getConnectionFromJID($jid)->Send($iq);
-        queue_admin_msg("You ($baseJID) have removed ($to) from your roster.");
-    }
-}
-
-sub jroster_auth {
-    my $jid = shift;
-    my $name = shift;
-    my @groups = @{ shift() };
-    my $purgeGroups = shift;
-    my $baseJID = baseJID($jid);
-
-    my $p = new Net::Jabber::Presence;
-    $p->SetType('subscribed');
-    foreach my $to (@ARGV) {
-        $p->SetTo($to);
-        $conn->getConnectionFromJID($jid)->Send($p);
-        queue_admin_msg("($to) has been subscribed to your ($baseJID) presence.");
-    }
-}
-
-sub jroster_deauth {
-    my $jid = shift;
-    my $name = shift;
-    my @groups = @{ shift() };
-    my $purgeGroups = shift;
-    my $baseJID = baseJID($jid);
-
-    my $p = new Net::Jabber::Presence;
-    $p->SetType('unsubscribed');
-    foreach my $to (@ARGV) {
-        $p->SetTo($to);
-        $conn->getConnectionFromJID($jid)->Send($p);
-        queue_admin_msg("($to) has been unsubscribed from your ($baseJID) presence.");
-    }
-}
-
-################################################################################
-### Owl Callbacks
-sub process_owl_jwrite {
-    my $body = shift;
-
-    my $j = new Net::Jabber::Message;
-    $body =~ s/\n\z//;
-    $j->SetMessage(
-        to   => $vars{jwrite}{to},
-        from => $vars{jwrite}{from},
-        type => $vars{jwrite}{type},
-        body => $body
-    );
-
-    $j->SetThread( $vars{jwrite}{thread} )   if ( $vars{jwrite}{thread} );
-    $j->SetSubject( $vars{jwrite}{subject} ) if ( $vars{jwrite}{subject} );
-
-    my $m = j2o( $j, { direction => 'out' } );
-    if ( $vars{jwrite}{type} ne 'groupchat') {
-        BarnOwl::add_and_log_message($m);
-    }
-
-    $j->RemoveFrom(); # Kludge to get around gtalk's random bits after the resource.
-    if ($vars{jwrite}{sid} && $conn->sidExists( $vars{jwrite}{sid} )) {
-        $conn->getConnectionFromSid($vars{jwrite}{sid})->Send($j);
-    }
-    else {
-        $conn->getConnectionFromJID($vars{jwrite}{from})->Send($j);
-    }
-
-    delete $vars{jwrite};
-    BarnOwl::message("");   # Kludge to make the ``type your message...'' message go away
-}
-
-### XMPP Callbacks
-
-sub process_incoming_chat_message {
-    my ( $sid, $j ) = @_;
-    BarnOwl::queue_message( j2o( $j, { direction => 'in',
-                                   sid => $sid } ) );
-}
-
-sub process_incoming_error_message {
-    my ( $sid, $j ) = @_;
-    my %jhash = j2hash( $j, { direction => 'in',
-                              sid => $sid } );
-    $jhash{type} = 'admin';
-    BarnOwl::queue_message( BarnOwl::Message->new(%jhash) );
-}
-
-sub process_incoming_groupchat_message {
-    my ( $sid, $j ) = @_;
-
-    # HACK IN PROGRESS (ignoring delayed messages)
-    return if ( $j->DefinedX('jabber:x:delay') && $j->GetX('jabber:x:delay') );
-    BarnOwl::queue_message( j2o( $j, { direction => 'in',
-                                   sid => $sid } ) );
-}
-
-sub process_incoming_headline_message {
-    my ( $sid, $j ) = @_;
-    BarnOwl::queue_message( j2o( $j, { direction => 'in',
-                                   sid => $sid } ) );
-}
-
-sub process_incoming_normal_message {
-    my ( $sid, $j ) = @_;
-    my %jhash = j2hash( $j, { direction => 'in',
-                              sid => $sid } );
-
-    # XXX TODO: handle things such as MUC invites here.
-
-    #    if ($j->HasX('http://jabber.org/protocol/muc#user'))
-    #    {
-    #	my $x = $j->GetX('http://jabber.org/protocol/muc#user');
-    #	if ($x->HasChild('invite'))
-    #	{
-    #	    $props
-    #	}
-    #    }
-    #
-    BarnOwl::queue_message( BarnOwl::Message->new(%jhash) );
-}
-
-sub process_muc_presence {
-    my ( $sid, $p ) = @_;
-    return unless ( $p->HasX('http://jabber.org/protocol/muc#user') );
-}
-
-
-sub process_presence_available {
-    my ( $sid, $p ) = @_;
-    my $from = $p->GetFrom();
-    my $to = $p->GetTo();
-    my $type = $p->GetType();
-    my %props = (
-        to => $to,
-        from => $from,
-        recipient => $to,
-        sender => $from,
-        type => 'jabber',
-        jtype => $p->GetType(),
-        status => $p->GetStatus(),
-        show => $p->GetShow(),
-        xml => $p->GetXML(),
-        direction => 'in');
-
-    if ($type eq '' || $type eq 'available') {
-        $props{body} = "$from is now online. ";
-        $props{loginout} = 'login';
-    }
-    else {
-        $props{body} = "$from is now offline. ";
-        $props{loginout} = 'logout';
-    }
-    $props{replysendercmd} = $props{replycmd} = "jwrite $from -i $sid";
-    if(BarnOwl::getvar('debug') eq 'on') {
-        BarnOwl::queue_message(BarnOwl::Message->new(%props));
-    }
-}
-
-sub process_presence_subscribe {
-    my ( $sid, $p ) = @_;
-    my $from = $p->GetFrom();
-    my $to = $p->GetTo();
-    my %props = (
-        to => $to,
-        from => $from,
-        xml => $p->GetXML(),
-        type => 'admin',
-        adminheader => 'Jabber presence: subscribe',
-        direction => 'in');
-
-    $props{body} = "Allow user ($from) to subscribe to your ($to) presence?\n" .
-                   "(Answer with the `yes' or `no' commands)";
-    $props{yescommand} = "jroster auth $from -a $to";
-    $props{nocommand} = "jroster deauth $from -a $to";
-    $props{question} = "true";
-    BarnOwl::queue_message(BarnOwl::Message->new(%props));
-}
-
-sub process_presence_unsubscribe {
-    my ( $sid, $p ) = @_;
-    my $from = $p->GetFrom();
-    my $to = $p->GetTo();
-    my %props = (
-        to => $to,
-        from => $from,
-        xml => $p->GetXML(),
-        type => 'admin',
-        adminheader => 'Jabber presence: unsubscribe',
-        direction => 'in');
-
-    $props{body} = "The user ($from) has been unsubscribed from your ($to) presence.\n";
-    BarnOwl::queue_message(BarnOwl::Message->new(%props));
-
-    # Find a connection to reply with.
-    foreach my $jid ($conn->getJIDs()) {
-	my $cJID = new Net::Jabber::JID;
-	$cJID->SetJID($jid);
-	if ($to eq $cJID->GetJID('base') ||
-            $to eq $cJID->GetJID('full')) {
-	    my $reply = $p->Reply(type=>"unsubscribed");
-	    $conn->getConnectionFromJID($jid)->Send($reply);
-	    return;
-	}
-    }
-}
-
-sub process_presence_subscribed {
-    my ( $sid, $p ) = @_;
-    queue_admin_msg("ignoring:".$p->GetXML());
-    # RFC 3921 says we should respond to this with a "subscribe"
-    # but this causes a flood of sub/sub'd presence packets with
-    # some servers, so we won't. We may want to detect this condition
-    # later, and have per-server settings.
-    return;
-}
-
-sub process_presence_unsubscribed {
-    my ( $sid, $p ) = @_;
-    queue_admin_msg("ignoring:".$p->GetXML());
-    # RFC 3921 says we should respond to this with a "subscribe"
-    # but this causes a flood of unsub/unsub'd presence packets with
-    # some servers, so we won't. We may want to detect this condition
-    # later, and have per-server settings.
-    return;
-}
-
-sub process_presence_error {
-    my ( $sid, $p ) = @_;
-    my $code = $p->GetErrorCode();
-    my $error = $p->GetError();
-    BarnOwl::error("Jabber: $code $error");
-}
-
-
-### Helper functions
-
-sub j2hash {
-    my $j   = shift;
-    my %initProps = %{ shift() };
-
-    my $dir = 'none';
-    my %props = ( type => 'jabber' );
-
-    foreach my $k (keys %initProps) {
-        $dir = $initProps{$k} if ($k eq 'direction');
-        $props{$k} = $initProps{$k};
-    }
-
-    my $jtype = $props{jtype} = $j->GetType();
-    my $from = $j->GetFrom('jid');
-    my $to   = $j->GetTo('jid');
-
-    $props{from} = $from->GetJID('full');
-    $props{to}   = $to->GetJID('full');
-
-    $props{recipient}  = $to->GetJID('base');
-    $props{sender}     = $from->GetJID('base');
-    $props{subject}    = $j->GetSubject() if ( $j->DefinedSubject() );
-    $props{thread}     = $j->GetThread() if ( $j->DefinedThread() );
-    $props{body}       = $j->GetBody() if ( $j->DefinedBody() );
-    $props{error}      = $j->GetError() if ( $j->DefinedError() );
-    $props{error_code} = $j->GetErrorCode() if ( $j->DefinedErrorCode() );
-    $props{xml}        = $j->GetXML();
-
-    if ( $jtype eq 'chat' ) {
-        $props{replycmd} =
-          "jwrite " . ( ( $dir eq 'in' ) ? $props{from} : $props{to} );
-        $props{replycmd} .=
-          " -a " . ( ( $dir eq 'out' ) ? $props{from} : $props{to} );
-        $props{private} = 1;
-
-        my $connection;
-        if ($dir eq 'in') {
-            $connection = $conn->getConnectionFromSid($props{sid});
-        }
-        else {
-            $connection = $conn->getConnectionFromJID($props{from});
-        }
-
-        # Check to see if we're doing personals with someone in a muc.
-        # If we are, show the full jid because the base jid is the room.
-        if ($connection) {
-            $props{sender} = $props{from}
-              if ($connection->FindMUC(jid => $from));
-            $props{recipient} = $props{to}
-              if ($connection->FindMUC(jid => $to));
-        }
-    }
-    elsif ( $jtype eq 'groupchat' ) {
-        my $nick = $props{nick} = $from->GetResource();
-        my $room = $props{room} = $from->GetJID('base');
-        $props{replycmd} = "jwrite $room";
-        $props{replycmd} .=
-          " -a " . ( ( $dir eq 'out' ) ? $props{from} : $props{to} );
-
-        if ($dir eq 'out') {
-            $props{replysendercmd} = "jwrite ".$props{to}." -a ".$props{from};
-        }
-        else {
-            $props{replysendercmd} = "jwrite ".$props{from}." -a ".$props{to};
-        }
-
-        $props{sender} = $nick || $room;
-        $props{recipient} = $room;
-
-        if ( $props{subject} && !$props{body} ) {
-            $props{body} =
-              '[' . $nick . " has set the topic to: " . $props{subject} . "]";
-        }
-    }
-    elsif ( $jtype eq 'normal' ) {
-        $props{replycmd}  = undef;
-        $props{private} = 1;
-    }
-    elsif ( $jtype eq 'headline' ) {
-        $props{replycmd} = undef;
-    }
-    elsif ( $jtype eq 'error' ) {
-        $props{replycmd} = undef;
-        $props{body}     = "Error "
-          . $props{error_code}
-          . " sending to "
-          . $props{from} . "\n"
-          . $props{error};
-    }
-
-    $props{replysendercmd} = $props{replycmd} unless $props{replysendercmd};
-    return %props;
-}
-
-sub j2o {
-    return BarnOwl::Message->new( j2hash(@_) );
-}
-
-sub queue_admin_msg {
-    my $err = shift;
-    BarnOwl::admin_message("jabber.pl", $err);
-}
-
-sub boldify($) {
-    my $str = shift;
-
-    return '@b(' . $str . ')' if ( $str !~ /\)/ );
-    return '@b<' . $str . '>' if ( $str !~ /\>/ );
-    return '@b{' . $str . '}' if ( $str !~ /\}/ );
-    return '@b[' . $str . ']' if ( $str !~ /\]/ );
-
-    my $txt = "$str";
-    $txt =~ s{[)]}{)\@b[)]\@b(}g;
-    return '@b(' . $txt . ')';
-}
-
-sub getServerFromJID {
-    my $jid = shift;
-    my $res = new Net::DNS::Resolver;
-    my $packet =
-      $res->search( '_xmpp-client._tcp.' . $jid->GetServer(), 'srv' );
-
-    if ($packet)    # Got srv record.
-    {
-        my @answer = $packet->answer;
-        return $answer[0]{target}, $answer[0]{port};
-    }
-
-    return $jid->GetServer(), 5222;
-}
-
-sub defaultJID {
-    return ( $conn->getJIDs() )[0] if ( $conn->connected() == 1 );
-    return;
-}
-
-sub baseJID {
-    my $givenJIDStr = shift;
-    my $givenJID    = new Net::Jabber::JID;
-    $givenJID->SetJID($givenJIDStr);
-    return $givenJID->GetJID('base');
-}
-
-sub resolveConnectedJID {
-    my $givenJIDStr = shift;
-    my $givenJID    = new Net::Jabber::JID;
-    $givenJID->SetJID($givenJIDStr);
-
-    # Account fully specified.
-    if ( $givenJID->GetResource() ) {
-        # Specified account exists
-        return $givenJIDStr if ($conn->jidExists($givenJIDStr) );
-        die("Invalid account: $givenJIDStr");
-    }
-
-    # Disambiguate.
-    else {
-        my $matchingJID = "";
-        my $errStr =
-          "Ambiguous account reference. Please specify a resource.\n";
-        my $ambiguous = 0;
-
-        foreach my $jid ( $conn->getJIDs() ) {
-            my $cJID = new Net::Jabber::JID;
-            $cJID->SetJID($jid);
-            if ( $givenJIDStr eq $cJID->GetJID('base') ) {
-                $ambiguous = 1 if ( $matchingJID ne "" );
-                $matchingJID = $jid;
-                $errStr .= "\t$jid\n";
-            }
-        }
-
-        # Need further disambiguation.
-        if ($ambiguous) {
-            die($errStr);
-        }
-
-        # Not one of ours.
-        elsif ( $matchingJID eq "" ) {
-            die("Invalid account: $givenJIDStr");
-        }
-
-        # It's this one.
-        else {
-            return $matchingJID;
-        }
-    }
-    return "";
-}
-
-sub resolveDestJID {
-    my ($to, $from) = @_;
-    my $jid = Net::Jabber::JID->new($to);
-
-    my $roster = $conn->getRosterFromJID($from);
-    my @jids = $roster->jids('all');
-    for my $j (@jids) {
-        if(($roster->query($j, 'name') || $j->GetUserID()) eq $to) {
-            return $j->GetJID('full');
-        } elsif($j->GetJID('base') eq baseJID($to)) {
-            return $jid->GetJID('full');
-        }
-    }
-
-    # If we found nothing being clever, check to see if our input was
-    # sane enough to look like a jid with a UserID.
-    return $jid->GetJID('full') if $jid->GetUserID();
-    return undef;
-}
-
-sub resolveType {
-    my $to = shift;
-    my $from = shift;
-    return unless $from;
-    my @mucs = $conn->getConnectionFromJID($from)->MUCs;
-    if(grep {$_->BaseJID eq $to } @mucs) {
-        return 'groupchat';
-    } else {
-        return 'chat';
-    }
-}
-
-sub guess_jwrite {
-    # Heuristically guess what jids a jwrite was meant to be going to/from
-    my ($from, $to) = (@_);
-    my ($from_jid, $to_jid);
-    my @matches;
-    if($from) {
-        $from_jid = resolveConnectedJID($from);
-        die("Unable to resolve account $from") unless $from_jid;
-        $to_jid = resolveDestJID($to, $from_jid);
-        push @matches, [$from_jid, $to_jid] if $to_jid;
-    } else {
-        for my $f ($conn->getJIDs) {
-            $to_jid = resolveDestJID($to, $f);
-            if(defined($to_jid)) {
-                push @matches, [$f, $to_jid];
-            }
-        }
-        if($to =~ /@/) {
-            push @matches, [$_, $to]
-               for ($conn->getJIDs);
-        }
-    }
-
-    for my $m (@matches) {
-        my $type = resolveType($m->[1], $m->[0]);
-        push @$m, $type;
-    }
-
-    return @matches;
-}
-
-#####################################################################
-#####################################################################
-
-package BarnOwl::Message::Jabber;
-
-our @ISA = qw( BarnOwl::Message );
-
-sub jtype { shift->{jtype} };
-sub from { shift->{from} };
-sub to { shift->{to} };
-sub room { shift->{room} };
-sub status { shift->{status} }
-
-sub login_extra {
-    my $self = shift;
-    my $show = $self->{show};
-    my $status = $self->status;
-    my $s = "";
-    $s .= $show if $show;
-    $s .= ", $status" if $status;
-    return $s;
-}
-
-sub long_sender {
-    my $self = shift;
-    return $self->from;
-}
-
-sub context {
-    return shift->room;
-}
-
-sub smartfilter {
-    my $self = shift;
-    my $inst = shift;
-
-    my ($filter, $ftext);
-
-    if($self->jtype eq 'chat') {
-        my $user;
-        if($self->direction eq 'in') {
-            $user = $self->from;
-        } else {
-            $user = $self->to;
-        }
-        return smartfilter_user($user, $inst);
-    } elsif ($self->jtype eq 'groupchat') {
-        my $room = $self->room;
-        $filter = "jabber-room-$room";
-        $ftext = qq{type ^jabber\$ and room ^$room\$};
-        BarnOwl::filter("$filter $ftext");
-        return $filter;
-    } elsif ($self->login ne 'none') {
-        return smartfilter_user($self->from, $inst);
-    }
-}
-
-sub smartfilter_user {
-    my $user = shift;
-    my $inst = shift;
-
-    $user   = Net::Jabber::JID->new($user)->GetJID( $inst ? 'full' : 'base' );
-    my $filter = "jabber-user-$user";
-    my $ftext  =
-        qq{type ^jabber\$ and ( ( direction ^in\$ and from ^$user ) }
-      . qq{or ( direction ^out\$ and to ^$user ) ) };
-    BarnOwl::filter("$filter $ftext");
-    return $filter;
-
-}
-
-
-1;

Modified: trunk/owl/perlconfig.c
===================================================================
--- trunk/owl/perlconfig.c	2007-03-28 02:04:10 UTC (rev 688)
+++ trunk/owl/perlconfig.c	2007-03-29 01:32:11 UTC (rev 689)
@@ -421,7 +421,7 @@
     return ret;
   } else {
     char *ptr = NULL;
-    if (owl_perlconfig_is_function("BarnOwl::Hooks::receive_msg")) {
+    if (owl_perlconfig_is_function("BarnOwl::Hooks::_receive_msg")) {
       ptr = owl_perlconfig_call_with_message(subname?subname
 				       :"BarnOwl::_receive_msg_legacy_wrap", m);
     }
@@ -505,11 +505,11 @@
 
 void owl_perlconfig_mainloop()
 {
-  if (!owl_perlconfig_is_function("BarnOwl::Hooks::mainloop_hook"))
+  if (!owl_perlconfig_is_function("BarnOwl::Hooks::_mainloop_hook"))
     return;
   dSP ;
   PUSHMARK(SP) ;
-  call_pv("BarnOwl::Hooks::mainloop_hook", G_DISCARD|G_EVAL);
+  call_pv("BarnOwl::Hooks::_mainloop_hook", G_DISCARD|G_EVAL);
   if(SvTRUE(ERRSV)) {
     STRLEN n_a;
     owl_function_error("%s", SvPV(ERRSV, n_a));

Modified: trunk/owl/perlwrap.pm
===================================================================
--- trunk/owl/perlwrap.pm	2007-03-28 02:04:10 UTC (rev 688)
+++ trunk/owl/perlwrap.pm	2007-03-29 01:32:11 UTC (rev 689)
@@ -6,16 +6,14 @@
 #####################################################################
 # XXX NOTE: This file is sourced before almost any barnowl
 # architecture is loaded. This means, for example, that it cannot
-# execute any owl commands. Any code that needs to do so, should
-# create a function wrapping it and push it onto @onStartSubs
+# execute any owl commands. Any code that needs to do so should live
+# in BarnOwl::Hooks::_startup
 
-
 use strict;
 use warnings;
 
 package BarnOwl;
 
-
 BEGIN {
 # bootstrap in C bindings and glue
     *owl:: = \*BarnOwl::;
@@ -43,7 +41,7 @@
 sub _receive_msg_legacy_wrap {
     my ($m) = @_;
     $m->legacy_populate_global();
-    return &BarnOwl::Hooks::receive_msg($m);
+    return &BarnOwl::Hooks::_receive_msg($m);
 }
 
 # make BarnOwl::<command>("foo") be aliases to BarnOwl::command("<command> foo");
@@ -203,7 +201,7 @@
 }
 
 sub smartfilter {
-    die("smartfilter not supported for this message");
+    die("smartfilter not supported for this message\n");
 }
 
 # Display fields -- overridden by subclasses when needed
@@ -350,89 +348,51 @@
 #####################################################################
 #####################################################################
 ################################################################################
-package BarnOwl;
 
-################################################################################
-# Mainloop hook
-################################################################################
+package BarnOwl::Hook;
 
-our $shutdown;
-$shutdown = 0;
-our $reload;
-$reload = 0;
+sub new {
+    my $class = shift;
+    return bless [], $class;
+}
 
-#Run this on start and reload. Adds modules
-sub onStart
-{
-    _load_owlconf();
-    reload_init();
-    loadModules();
+sub run {
+    my $self = shift;
+    my @args = @_;
+    return map {$_->(@args)} @$self;
 }
-################################################################################
-# Reload Code, taken from /afs/sipb/user/jdaniel/project/owl/perl
-################################################################################
-sub reload_hook (@)
-{
-    BarnOwl::Hooks::startup();
-    return 1;
-}
 
-sub reload
-{
-    # Use $reload to tell modules that we're performing a reload.
-  {
-      local $reload = 1;
-      BarnOwl::mainloop_hook() if *BarnOwl::mainloop_hook{CODE};
-  }
-
-  @BarnOwl::Hooks::onMainLoop = ();
-  @BarnOwl::Hooks::onStartSubs = ();
-
-  # Do reload
-  package main;
-  if (-r $BarnOwl::configfile) {
-      undef $@;
-      do $BarnOwl::configfile;
-      BarnOwl::error("Error reloading $BarnOwl::configfile: $@") if $@;
-  }
-  BarnOwl::reload_hook(@_);
-  package BarnOwl;
+sub add {
+    my $self = shift;
+    my $func = shift;
+    die("Not a coderef!") unless ref($func) eq 'CODE';
+    push @$self, $func;
 }
 
-sub reload_init ()
-{
-    BarnOwl::command('alias reload perl BarnOwl::reload()');
-    BarnOwl::command('bindkey global "C-x C-r" command reload');
+sub clear {
+    my $self = shift;
+    @$self = ();
 }
 
-################################################################################
-# Loads modules from ~/.owl/modules and owl's data directory
-################################################################################
+package BarnOwl::Hooks;
 
-sub loadModules () {
-    my @modules;
-    my $rv;
-    foreach my $dir ( BarnOwl::get_data_dir() . "/modules",
-                      $ENV{HOME} . "/.owl/modules" )
-    {
-        opendir( MODULES, $dir );
+use Exporter;
 
-        # source ./modules/*.pl
-        @modules = sort grep( /\.pl$/, readdir(MODULES) );
+our @EXPORT_OK = qw($startup $shutdown
+                    $receiveMessage $mainLoop
+                    $getBuddyList);
 
-        foreach my $mod (@modules) {
-            unless ($rv = do "$dir/$mod") {
-                BarnOwl::error("Couldn't load $dir/$mod:\n $@") if $@;
-                BarnOwl::error("Couldn't run $dir/$mod:\n $!") unless defined $rv;
-            }
-        }
-        closedir(MODULES);
-    }
-}
+our %EXPORT_TAGS = (all => [@EXPORT_OK]);
 
+our $startup = BarnOwl::Hook->new;
+our $shutdown = BarnOwl::Hook->new;
+our $receiveMessage = BarnOwl::Hook->new;
+our $mainLoop = BarnOwl::Hook->new;
+our $getBuddyList = BarnOwl::Hook->new;
+
+# Internal startup/shutdown routines called by the C code
+
 sub _load_owlconf {
-    # Only do this the first time
-    return if $BarnOwl::reload;
     # load the config  file
     if ( -r $BarnOwl::configfile ) {
         undef $@;
@@ -450,86 +410,43 @@
     }
 }
 
-package BarnOwl::Hooks;
+sub _startup {
+    _load_owlconf();
 
-# Arrays of subrefs to be called at specific times.
-our @onStartSubs = ();
-our @onReceiveMsg = ();
-our @onMainLoop = ();
-our @onGetBuddyList = ();
-
-# Functions to call hook lists
-sub runHook($@)
-{
-    my $hook = shift;
-    my @args = @_;
-    $_->(@args) for (@$hook);
-}
-
-sub runHook_accumulate($@)
-{
-    my $hook = shift;
-    my @args = @_;
-    return join("\n", map {$_->(@args)} @$hook);
-}
-
-################################################################################
-# Startup and Shutdown code
-################################################################################
-sub startup
-{
-    # Modern versions of owl provides a great place to have startup stuff.
-    # Put things in ~/.owl/startup
-
-    #So that the user's .owlconf can have startsubs, we don't clear
-    #onStartSubs; reload does however
-    @onReceiveMsg = ();
-    @onMainLoop = ();
-    @onGetBuddyList = ();
-
-    BarnOwl::onStart();
-
-    runHook(\@onStartSubs);
-
+    if(eval {require BarnOwl::ModuleLoader}) {
+        eval {
+            BarnOwl::ModuleLoader->load_all;
+        };
+        BarnOwl::error("Error loading modules: $@") if $@;
+    } else {
+        BarnOwl::error("Can't load BarnOwl::ModuleLoader, loadable module support disabled:\n$@");
+    }
+    
+    $startup->run(0);
     BarnOwl::startup() if *BarnOwl::startup{CODE};
 }
 
-sub shutdown
-{
-# Modern versions of owl provides a great place to have shutdown stuff.
-# Put things in ~/.owl/shutdown
-
-    # use $shutdown to tell modules that that's what we're doing.
-    $BarnOwl::shutdown = 1;
-    BarnOwl::mainloop_hook() if *BarnOwl::mainloop_hook{CODE};
-
+sub _shutdown {
+    $shutdown->run;
+    
     BarnOwl::shutdown() if *BarnOwl::shutdown{CODE};
 }
 
-sub mainloop_hook
-{
-    runHook(\@onMainLoop);
-    BarnOwl::mainloop_hook() if *BarnOwl::mainloop_hook{CODE};
-}
-
-################################################################################
-# Hooks into receive_msg()
-################################################################################
-
-sub receive_msg
-{
+sub _receive_msg {
     my $m = shift;
-    runHook(\@onReceiveMsg, $m);
+
+    $receiveMessage->run($m);
+    
     BarnOwl::receive_msg($m) if *BarnOwl::receive_msg{CODE};
 }
 
-################################################################################
-# Hooks into get_blist()
-################################################################################
+sub _mainloop_hook {
+    $mainLoop->run;
+    BarnOwl::mainloop_hook() if *BarnOwl::mainloop_hook{CODE};
+}
 
-sub get_blist
-{
-    return runHook_accumulate(\@onGetBuddyList);
+sub _get_blist {
+    return join("\n", $getBuddyList->run);
 }
 
 ################################################################################
@@ -643,16 +560,11 @@
 
 # switch to package main when we're done
 package main;
-# alias the hooks
-{
-    no strict 'refs';
-    foreach my $hook  qw (onStartSubs
-                          onReceiveMsg
-                          onMainLoop
-                          onGetBuddyList ) {
-        *{"main::".$hook} = \*{"BarnOwl::Hooks::".$hook};
-        *{"owl::".$hook} = \*{"BarnOwl::Hooks::".$hook};
-    }
-}
 
+# Shove a bunch of fake entries into @INC so modules can use or
+# require them without choking
+$::INC{$_} = 1 for (qw(BarnOwl.pm BarnOwl/Hooks.pm
+                       BarnOwl/Message.pm BarnOwl/Style.pm));
+
 1;
+


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