qsos-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qsos-commits] qsos/apps/xuleditor/chrome/content/jsjac API AU...


From: Raphaël Semeteys
Subject: [Qsos-commits] qsos/apps/xuleditor/chrome/content/jsjac API AU...
Date: Sat, 24 Feb 2007 23:02:06 +0000

CVSROOT:        /sources/qsos
Module name:    qsos
Changes by:     Raphaël Semeteys <rsemeteys>   07/02/24 23:02:06

Added files:
        apps/xuleditor/chrome/content/jsjac: API AUTHORS ChangeLog 
                                             COPYING crypt.js 
                                             JSJaCConnection.js 
                                             JSJaCHttpBindingConnection.js 
                                             JSJaCHttpPollingConnection.js 
                                             JSJaC.js JSJaCPacket.js 
                                             json.js qm_cookie.js README 
                                             semantic.cache xmlextras.js 

Log message:
        JSJaC library included to manage XMPP chat

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qsos/apps/xuleditor/chrome/content/jsjac/API?cvsroot=qsos&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/qsos/apps/xuleditor/chrome/content/jsjac/AUTHORS?cvsroot=qsos&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/qsos/apps/xuleditor/chrome/content/jsjac/ChangeLog?cvsroot=qsos&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/qsos/apps/xuleditor/chrome/content/jsjac/COPYING?cvsroot=qsos&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/qsos/apps/xuleditor/chrome/content/jsjac/crypt.js?cvsroot=qsos&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/qsos/apps/xuleditor/chrome/content/jsjac/JSJaCConnection.js?cvsroot=qsos&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/qsos/apps/xuleditor/chrome/content/jsjac/JSJaCHttpBindingConnection.js?cvsroot=qsos&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/qsos/apps/xuleditor/chrome/content/jsjac/JSJaCHttpPollingConnection.js?cvsroot=qsos&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/qsos/apps/xuleditor/chrome/content/jsjac/JSJaC.js?cvsroot=qsos&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/qsos/apps/xuleditor/chrome/content/jsjac/JSJaCPacket.js?cvsroot=qsos&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/qsos/apps/xuleditor/chrome/content/jsjac/json.js?cvsroot=qsos&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/qsos/apps/xuleditor/chrome/content/jsjac/qm_cookie.js?cvsroot=qsos&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/qsos/apps/xuleditor/chrome/content/jsjac/README?cvsroot=qsos&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/qsos/apps/xuleditor/chrome/content/jsjac/semantic.cache?cvsroot=qsos&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/qsos/apps/xuleditor/chrome/content/jsjac/xmlextras.js?cvsroot=qsos&rev=1.1

Patches:
Index: API
===================================================================
RCS file: API
diff -N API
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ API 24 Feb 2007 23:02:06 -0000      1.1
@@ -0,0 +1,256 @@
+
+JSJaCConnection (abstract)
+===============
+
+This is a somewhat abstract base class. You can't instantiate objects
+from it but it provides functionality common to all specific backends
+like JSJaCHttpPollingConnection.
+
+boolean: connected()
+       checks if connection is connected
+       RETURNS: boolean - true if connected, false otherwise
+
+boolean: isPolling()
+       whether this connection is using polling
+       RETURNS: true if polling is used (thus indicating it makes sense to use
+                setPollInterval)
+
+void: registerHandler(string: event, function: handler)
+       register a handler for event. if event happens handler is called.
+
+       PARAMS: event - known events so far: 'message','iq','presence',
+                        'ondisconnect', 'onconnect', 'onerror', 
'status_changed'
+
+               handler - the function to be called. for events 'message', 'iq'
+                         and 'presence' the handler gets passed an JSJaCPacket 
+                         as argument for processing. 
+                         'onerror' an error node is supplied, e.g.: 
+                         <error code='404' type='cancel'>
+                           <item-not-found 
xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
+                         </error>
+
+void: send(JSJaCPacket: aJSJaCPacket [, function: callback [, any: arg]])
+       appends aJSJaCPacket to send queue. registers callback if given
+
+       PARAMS: aJSJaCPacket - packet to send
+               callback - a callback to call when reply with same id comes in
+                          id is set automatically if none set
+               arg - optional arg to call callback 
+                     [callback is called with callback(aJSJaCPacket, arg)]
+
+int: setPollInterval(int: timeout_msec)
+       change polling interval to timeout_msec
+
+       PARAMS: timeout_msec
+       RETURNS: actual value the polling interval has been set to. 
+                -1 on failure.
+
+JSJaCHttpPollingConnection
+==========================
+Implements communication with an HTTP Polling Component.
+
+constructor: JSJaCHttpPollingConnection(oArgs[JSON notation!])
+
+       oArgs:= string: httpbase,    # http base address of service to be used
+          int:    timerval,     # initial poll interval in msec
+          object: oDbg         # typeof Debugger (optional)
+
+void: connect(oArgs[JSON notation!])
+
+       oArgs := string: domain,     # jabber domain
+           string: username,   # jabber username
+           string: resource,   # resource
+           string: pass,       # password
+
+           boolean: register,  # whether to register a new account
+                               # (using in-band registration of available) 
+                               # [optional]
+
+           string: authtype,   # one of 'sasl', 'saslanon' 
+                               # or 'nonsasl' 
+                               # [optional, default: sasl]
+
+           string: authtype    # hostname of auth service if different  
+                               # from xmpp domain
+                               # [optional]
+
+void: disconnect()
+       disconnects from server
+
+JSJaCHttpBindingConnection
+==========================
+Implements communication with an HTTP Binding Service (aka Connection Manager).
+
+constructor: JSJaCHttpBindingConnection(oArgs[JSON notation!])
+
+       oArgs:= string: httpbase,    # http base address of service to be used
+          int:    timerval,    # initial poll interval in msec
+          object: oDbg         # typeof Debugger (optional)
+
+void: connect(oArgs[JSON notation])
+
+       oArgs := string: domain,     # jabber domain
+           string: username,   # jabber username
+           string: resource,   # resource
+           string: pass,       # password
+
+           boolean: register,  # whether to register a new account
+                               # (using in-band registration of available) 
+                               # [optional, default: false]
+
+           string: host,       # connect host [optional, default: domain]
+
+           int: port,          # port of connect host 
+                               # [optional, default: 5222]
+
+           boolean: secure,    # whether to indicate that SSL should be 
+                               # used to connect to remote host 
+                               # [optional, default: false]
+
+           int: wait           # time in seconds the connection manager 
+                               # is allowed to hold an idle request 
+                               # [optional, default: 300]
+
+           string: authtype,   # one of 'sasl', 'saslanon' 
+                               # or 'nonsasl' 
+                               # [optional, default: sasl]
+
+           string: authtype    # hostname of auth service if different  
+                               # from xmpp domain
+                               # [optional]
+
+void: disconnect()
+       disconnects from server
+
+JSJaCPacket
+===========
+Abstract base class for jabber packets.
+
+string: pType()
+       returns type of top level node (either 'message', 'iq' or 'presence')
+
+JSJaCPacket: setTo(string: to)
+JSJaCPacket: setFrom(string: from)
+JSJaCPacket: setID(string: id)
+JSJaCPacket: setType(string: type)
+JSJaCPacket: setXMLLang(string: xmllang)
+JSJaCPacket: setXMLNS(string: xmlns)
+       setters for common attributes of top level nodes.
+
+       PARAMS: value to set attribute to
+       RETURNS: the packet itself again
+
+string: getTo()
+string: getFrom()
+string: getID()
+string: getType()
+string: getXMLLang()
+string: getXMLNS()
+       getters for common attributes of top level nodes
+
+string: xml()
+       returns string representation of DOM xml tree
+
+[IMPORTANT NOTE: Usage of getDoc().xml is DEPRECATED as it not
+support by browsers other than IE and Mozilla based ones]
+
+DOMDocument: getDoc()
+       Returns internal DOMDocument. This is where you can do your own
+       stuff like creating new childs and so on. Most notably you would
+       use it like follows:
+
+       var iq = new JSJaCIQ();
+       iq.setType('get');
+       iq.xml() => "<iq type='get'/>"
+
+       query = iq.setQuery('jabber:iq:private');
+       iq.xml() => "<iq type='get'><query xmlns='jabber:iq:private' /></iq>'
+
+       
query.appendChild(iq.getDoc().createElement('storage')).setAttribute('xmlns','storage:bookmarks');
+       iq.xml() => "<iq type='get'><query xmlns='jabber:iq:private'><storage 
xmlns='storage:bookmarks'></query></iq>'
+
+
+DOMElement: getNode()
+       returns top level node
+
+JSJaCNode: clone()
+  returns a (deep) copy of calling packet
+
+JSJaCIQ
+=======
+An IQ packet
+
+constructor: JSJaCIQ()
+
+JSJaCIQ: setIQ(to,from,type,id)
+       convenient method to set some attributes at once
+
+DOMElement: setQuery(string: xmlns)
+       creates new query child element. inserts it at top level node and 
returns it
+
+       PARAMS: xmlns - namespace attribute for query
+
+       RETURNS: DOMElement that has been created
+
+DOMElement: getQuery()
+       returns query element
+
+string: getQueryXMLNS()
+       returns xmlns attribute of query element
+
+JSJaCPresence
+=============
+A presence packet
+
+constructor: JSJaCPresence()
+
+JSJaCPresence: setShow(string: show)
+       creates 'show' child element and sets its CDATA to show (should be one 
of 'away','xa','dnd' or 'chat')
+
+JSJaCPresence: setStatus(string: status)
+       creates 'status' child element and sets its CDATA to status
+
+JSJaCPresence: setPriority(string: prio)
+       creates 'priority' child element and sets its CDATA to prio
+
+JSJaCPresence: setPresence(string: show, string: status, string: prio)
+       conveniant method to set some values at once
+
+string: getShow()
+string: getStatus()
+string: getPriority()
+       return value of corresponding element
+
+JSJaCMessage
+============
+A message packet
+
+JSJaCMessage: setBody(string: body)
+       creates 'body' element with value body
+JSJaCMessage: setSubject(string: subject)
+       creates 'subject' element with value subject
+
+string: getBody()
+string: getSubject()
+       return value of corresponding element
+
+
+
+'status_changed' Event
+======================
+
+Available states are
+'initializing' ... well
+'connecting' if connect() was called
+'processing' if it's about to operate as normal
+'onerror_fallback' if there was an error with the request object
+'protoerror_fallback' if there was an error at the http binding protocol
+flow (most likely that's where you interested in)
+'internal_server_error' in case of an internal server error
+'suspending' if suspend() is being called
+'aborted' if abort() was called
+'disconnecting' if disconnect() has been called
+
+Have a look at examples/simpleclient.html for a short example on how to
+use this.
+

Index: AUTHORS
===================================================================
RCS file: AUTHORS
diff -N AUTHORS
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ AUTHORS     24 Feb 2007 23:02:06 -0000      1.1
@@ -0,0 +1,3 @@
+JSJaC has been developed by
+
+* Stefan Strigler <address@hidden>

Index: ChangeLog
===================================================================
RCS file: ChangeLog
diff -N ChangeLog
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ ChangeLog   24 Feb 2007 23:02:06 -0000      1.1
@@ -0,0 +1,57 @@
+JSJaC v0.6
+==========
+
+* Support for Opera, Konqueror and Safari.
+* Support for suspend/resume (makes it possible to save the state between
+  page transitions.
+* Single include by JSJaC.js
+* Many bugfixes and improvements concerning reliability.
+* API change! Params to constructors and connect methods are now passed as
+  JSON objects.
+* New event 'status_changed' to signal if sth going on with the status of
+  the connection (like errors, retries and so on)
+* SASL Authentication (PLAIN, DIGEST-MD5, ANONYMOUS) 
+       
+JSJaC v0.5
+==========
+
+* lots of bug fixes and minor improvements
+* make use of asynchronous request wherever possible
+* fixed simpleclient
+* fixed API docs
+
+JSJaC v0.4
+==========
+
+* ...
+
+JSJaC v0.3.x
+============
+* Initial support for http binding (in polling mode though)
+
+* Initial support for safari (thanks to Matthew Hershberger)
+
+
+JSJaC v0.2
+==========
+
+* send always does asychronous send now as http polling doesn't
+  support this.
+
+  In detail: When sending a packet where we expect a reply to it
+  http polling doesn't make sure that this reply is contained
+  within the http body reply to the query sent. So we have to
+  setup a callback that handles the reply once it has been
+  delivered to us.
+
+* added a dedicated method syncedSend that sends in synchronous
+  mode
+
+  First read above, then understand that you can't expect any
+  response to this call. It's there to make sure, sending is
+  finished before windows get closed
+
+* added events 'onconnect', 'ondisconnect' and 'onerror'. see API
+  for details.
+
+* removed method process() as polling is started at connect() now.
\ No newline at end of file

Index: COPYING
===================================================================
RCS file: COPYING
diff -N COPYING
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ COPYING     24 Feb 2007 23:02:06 -0000      1.1
@@ -0,0 +1,504 @@
+                 GNU LESSER GENERAL PUBLIC LICENSE
+                      Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+     51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL.  It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+                           Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+  This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it.  You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+  When we speak of free software, we are referring to freedom of use,
+not price.  Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+  To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights.  These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+  For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you.  You must make sure that they, too, receive or can get the source
+code.  If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it.  And you must show them these terms so they know their rights.
+
+  We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+  To protect each distributor, we want to make it very clear that
+there is no warranty for the free library.  Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+  Finally, software patents pose a constant threat to the existence of
+any free program.  We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder.  Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+  Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License.  This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License.  We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+  When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library.  The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom.  The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+  We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License.  It also provides other free software developers Less
+of an advantage over competing non-free programs.  These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries.  However, the Lesser license provides advantages in certain
+special circumstances.
+
+  For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard.  To achieve this, non-free programs must be
+allowed to use the library.  A more frequent case is that a free
+library does the same job as widely used non-free libraries.  In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+  In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software.  For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+  Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.  Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library".  The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+                 GNU LESSER GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+  A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+  The "Library", below, refers to any such software library or work
+which has been distributed under these terms.  A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language.  (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+  "Source code" for a work means the preferred form of the work for
+making modifications to it.  For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+  Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it).  Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+  
+  1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+  You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+  2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) The modified work must itself be a software library.
+
+    b) You must cause the files modified to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    c) You must cause the whole of the work to be licensed at no
+    charge to all third parties under the terms of this License.
+
+    d) If a facility in the modified Library refers to a function or a
+    table of data to be supplied by an application program that uses
+    the facility, other than as an argument passed when the facility
+    is invoked, then you must make a good faith effort to ensure that,
+    in the event an application does not supply such function or
+    table, the facility still operates, and performs whatever part of
+    its purpose remains meaningful.
+
+    (For example, a function in a library to compute square roots has
+    a purpose that is entirely well-defined independent of the
+    application.  Therefore, Subsection 2d requires that any
+    application-supplied function or table used by this function must
+    be optional: if the application does not supply it, the square
+    root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library.  To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License.  (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.)  Do not make any other change in
+these notices.
+
+  Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+  This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+  4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+  If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library".  Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+  However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library".  The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+  When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library.  The
+threshold for this to be true is not precisely defined by law.
+
+  If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work.  (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+  Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+  6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+  You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License.  You must supply a copy of this License.  If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License.  Also, you must do one
+of these things:
+
+    a) Accompany the work with the complete corresponding
+    machine-readable source code for the Library including whatever
+    changes were used in the work (which must be distributed under
+    Sections 1 and 2 above); and, if the work is an executable linked
+    with the Library, with the complete machine-readable "work that
+    uses the Library", as object code and/or source code, so that the
+    user can modify the Library and then relink to produce a modified
+    executable containing the modified Library.  (It is understood
+    that the user who changes the contents of definitions files in the
+    Library will not necessarily be able to recompile the application
+    to use the modified definitions.)
+
+    b) Use a suitable shared library mechanism for linking with the
+    Library.  A suitable mechanism is one that (1) uses at run time a
+    copy of the library already present on the user's computer system,
+    rather than copying library functions into the executable, and (2)
+    will operate properly with a modified version of the library, if
+    the user installs one, as long as the modified version is
+    interface-compatible with the version that the work was made with.
+
+    c) Accompany the work with a written offer, valid for at
+    least three years, to give the same user the materials
+    specified in Subsection 6a, above, for a charge no more
+    than the cost of performing this distribution.
+
+    d) If distribution of the work is made by offering access to copy
+    from a designated place, offer equivalent access to copy the above
+    specified materials from the same place.
+
+    e) Verify that the user has already received a copy of these
+    materials or that you have already sent this user a copy.
+
+  For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it.  However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+  It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system.  Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+  7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+    a) Accompany the combined library with a copy of the same work
+    based on the Library, uncombined with any other library
+    facilities.  This must be distributed under the terms of the
+    Sections above.
+
+    b) Give prominent notice with the combined library of the fact
+    that part of it is a work based on the Library, and explaining
+    where to find the accompanying uncombined form of the same work.
+
+  8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License.  Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License.  However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+  9. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Library or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+  10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+  11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded.  In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+  13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation.  If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+  14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission.  For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this.  Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+                           NO WARRANTY
+
+  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+                    END OF TERMS AND CONDITIONS
+
+           How to Apply These Terms to Your New Libraries
+
+  If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change.  You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+  To apply these terms, attach the following notices to the library.  It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the library's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the
+  library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+  <signature of Ty Coon>, 1 April 1990
+  Ty Coon, President of Vice
+
+That's all there is to it!
+
+

Index: crypt.js
===================================================================
RCS file: crypt.js
diff -N crypt.js
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ crypt.js    24 Feb 2007 23:02:06 -0000      1.1
@@ -0,0 +1,618 @@
+/*
+ * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
+ * in FIPS PUB 180-1
+ * Version 2.1a Copyright Paul Johnston 2000 - 2002.
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
+ * Distributed under the BSD License
+ * See http://pajhome.org.uk/crypt/md5 for details.
+ */
+
+/*
+ * Configurable variables. You may need to tweak these to be compatible with
+ * the server-side, but the defaults work in most cases.
+ */
+var hexcase = 0;  /* hex output format. 0 - lowercase; 1 - uppercase        */
+var b64pad  = "="; /* base-64 pad character. "=" for strict RFC compliance   */
+var chrsz   = 8;  /* bits per input character. 8 - ASCII; 16 - Unicode      */
+
+/*
+ * These are the functions you'll usually want to call
+ * They take string arguments and return either hex or base-64 encoded strings
+ */
+function hex_sha1(s){return binb2hex(core_sha1(str2binb(s),s.length * chrsz));}
+function b64_sha1(s){return binb2b64(core_sha1(str2binb(s),s.length * chrsz));}
+function str_sha1(s){return binb2str(core_sha1(str2binb(s),s.length * chrsz));}
+function hex_hmac_sha1(key, data){ return binb2hex(core_hmac_sha1(key, data));}
+function b64_hmac_sha1(key, data){ return binb2b64(core_hmac_sha1(key, data));}
+function str_hmac_sha1(key, data){ return binb2str(core_hmac_sha1(key, data));}
+
+/*
+ * Perform a simple self-test to see if the VM is working
+ */
+function sha1_vm_test()
+{
+  return hex_sha1("abc") == "a9993e364706816aba3e25717850c26c9cd0d89d";
+}
+
+/*
+ * Calculate the SHA-1 of an array of big-endian words, and a bit length
+ */
+function core_sha1(x, len)
+{
+  /* append padding */
+  x[len >> 5] |= 0x80 << (24 - len % 32);
+  x[((len + 64 >> 9) << 4) + 15] = len;
+
+  var w = Array(80);
+  var a =  1732584193;
+  var b = -271733879;
+  var c = -1732584194;
+  var d =  271733878;
+  var e = -1009589776;
+
+  for(var i = 0; i < x.length; i += 16)
+    {
+      var olda = a;
+      var oldb = b;
+      var oldc = c;
+      var oldd = d;
+      var olde = e;
+
+      for(var j = 0; j < 80; j++)
+        {
+          if(j < 16) w[j] = x[i + j];
+          else w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
+          var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)),
+                           safe_add(safe_add(e, w[j]), sha1_kt(j)));
+          e = d;
+          d = c;
+          c = rol(b, 30);
+          b = a;
+          a = t;
+        }
+
+      a = safe_add(a, olda);
+      b = safe_add(b, oldb);
+      c = safe_add(c, oldc);
+      d = safe_add(d, oldd);
+      e = safe_add(e, olde);
+    }
+  return Array(a, b, c, d, e);
+
+}
+
+/*
+ * Perform the appropriate triplet combination function for the current
+ * iteration
+ */
+function sha1_ft(t, b, c, d)
+{
+  if(t < 20) return (b & c) | ((~b) & d);
+  if(t < 40) return b ^ c ^ d;
+  if(t < 60) return (b & c) | (b & d) | (c & d);
+  return b ^ c ^ d;
+}
+
+/*
+ * Determine the appropriate additive constant for the current iteration
+ */
+function sha1_kt(t)
+{
+  return (t < 20) ?  1518500249 : (t < 40) ?  1859775393 :
+    (t < 60) ? -1894007588 : -899497514;
+}
+
+/*
+ * Calculate the HMAC-SHA1 of a key and some data
+ */
+function core_hmac_sha1(key, data)
+{
+  var bkey = str2binb(key);
+  if(bkey.length > 16) bkey = core_sha1(bkey, key.length * chrsz);
+
+  var ipad = Array(16), opad = Array(16);
+  for(var i = 0; i < 16; i++)
+    {
+      ipad[i] = bkey[i] ^ 0x36363636;
+      opad[i] = bkey[i] ^ 0x5C5C5C5C;
+    }
+
+  var hash = core_sha1(ipad.concat(str2binb(data)), 512 + data.length * chrsz);
+  return core_sha1(opad.concat(hash), 512 + 160);
+}
+
+/*
+ * Add integers, wrapping at 2^32. This uses 16-bit operations internally
+ * to work around bugs in some JS interpreters.
+ */
+function safe_add(x, y)
+{
+  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
+  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
+  return (msw << 16) | (lsw & 0xFFFF);
+}
+
+/*
+ * Bitwise rotate a 32-bit number to the left.
+ */
+function rol(num, cnt)
+{
+  return (num << cnt) | (num >>> (32 - cnt));
+}
+
+/*
+ * Convert an 8-bit or 16-bit string to an array of big-endian words
+ * In 8-bit function, characters >255 have their hi-byte silently ignored.
+ */
+function str2binb(str)
+{
+  var bin = Array();
+  var mask = (1 << chrsz) - 1;
+  for(var i = 0; i < str.length * chrsz; i += chrsz)
+    bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (32 - chrsz - i%32);
+  return bin;
+}
+
+/*
+ * Convert an array of big-endian words to a string
+ */
+function binb2str(bin)
+{
+  var str = "";
+  var mask = (1 << chrsz) - 1;
+  for(var i = 0; i < bin.length * 32; i += chrsz)
+    str += String.fromCharCode((bin[i>>5] >>> (32 - chrsz - i%32)) & mask);
+  return str;
+}
+
+/*
+ * Convert an array of big-endian words to a hex string.
+ */
+function binb2hex(binarray)
+{
+  var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
+  var str = "";
+  for(var i = 0; i < binarray.length * 4; i++)
+    {
+      str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) +
+        hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8  )) & 0xF);
+    }
+  return str;
+}
+
+/*
+ * Convert an array of big-endian words to a base-64 string
+ */
+function binb2b64(binarray)
+{
+  var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+  var str = "";
+  for(var i = 0; i < binarray.length * 4; i += 3)
+    {
+      var triplet = (((binarray[i   >> 2] >> 8 * (3 -  i   %4)) & 0xFF) << 16)
+        | (((binarray[i+1 >> 2] >> 8 * (3 - (i+1)%4)) & 0xFF) << 8 )
+        |  ((binarray[i+2 >> 2] >> 8 * (3 - (i+2)%4)) & 0xFF);
+      for(var j = 0; j < 4; j++)
+        {
+          if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
+          else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
+        }
+    }
+  return str;
+}
+
+/*
+ * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
+ * Digest Algorithm, as defined in RFC 1321.
+ * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
+ * Distributed under the BSD License
+ * See http://pajhome.org.uk/crypt/md5 for more info.
+ */
+
+/*
+ * Configurable variables. You may need to tweak these to be compatible with
+ * the server-side, but the defaults work in most cases.
+ */
+// var hexcase = 0;  /* hex output format. 0 - lowercase; 1 - uppercase        
*/
+// var b64pad  = ""; /* base-64 pad character. "=" for strict RFC compliance   
*/
+// var chrsz   = 8;  /* bits per input character. 8 - ASCII; 16 - Unicode      
*/
+
+/*
+ * These are the functions you'll usually want to call
+ * They take string arguments and return either hex or base-64 encoded strings
+ */
+function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));}
+function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));}
+function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));}
+function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }
+function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }
+function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); }
+
+/*
+ * Perform a simple self-test to see if the VM is working
+ */
+function md5_vm_test()
+{
+  return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
+}
+
+/*
+ * Calculate the MD5 of an array of little-endian words, and a bit length
+ */
+function core_md5(x, len)
+{
+  /* append padding */
+  x[len >> 5] |= 0x80 << ((len) % 32);
+  x[(((len + 64) >>> 9) << 4) + 14] = len;
+
+  var a =  1732584193;
+  var b = -271733879;
+  var c = -1732584194;
+  var d =  271733878;
+
+  for(var i = 0; i < x.length; i += 16)
+  {
+    var olda = a;
+    var oldb = b;
+    var oldc = c;
+    var oldd = d;
+
+    a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
+    d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
+    c = md5_ff(c, d, a, b, x[i+ 2], 17,  606105819);
+    b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
+    a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
+    d = md5_ff(d, a, b, c, x[i+ 5], 12,  1200080426);
+    c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
+    b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
+    a = md5_ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
+    d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
+    c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
+    b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
+    a = md5_ff(a, b, c, d, x[i+12], 7 ,  1804603682);
+    d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
+    c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
+    b = md5_ff(b, c, d, a, x[i+15], 22,  1236535329);
+
+    a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
+    d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
+    c = md5_gg(c, d, a, b, x[i+11], 14,  643717713);
+    b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
+    a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
+    d = md5_gg(d, a, b, c, x[i+10], 9 ,  38016083);
+    c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
+    b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
+    a = md5_gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
+    d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
+    c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
+    b = md5_gg(b, c, d, a, x[i+ 8], 20,  1163531501);
+    a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
+    d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
+    c = md5_gg(c, d, a, b, x[i+ 7], 14,  1735328473);
+    b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
+
+    a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
+    d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
+    c = md5_hh(c, d, a, b, x[i+11], 16,  1839030562);
+    b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
+    a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
+    d = md5_hh(d, a, b, c, x[i+ 4], 11,  1272893353);
+    c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
+    b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
+    a = md5_hh(a, b, c, d, x[i+13], 4 ,  681279174);
+    d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
+    c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
+    b = md5_hh(b, c, d, a, x[i+ 6], 23,  76029189);
+    a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
+    d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
+    c = md5_hh(c, d, a, b, x[i+15], 16,  530742520);
+    b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
+
+    a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
+    d = md5_ii(d, a, b, c, x[i+ 7], 10,  1126891415);
+    c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
+    b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
+    a = md5_ii(a, b, c, d, x[i+12], 6 ,  1700485571);
+    d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
+    c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
+    b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
+    a = md5_ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
+    d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
+    c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
+    b = md5_ii(b, c, d, a, x[i+13], 21,  1309151649);
+    a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
+    d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
+    c = md5_ii(c, d, a, b, x[i+ 2], 15,  718787259);
+    b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
+
+    a = safe_add(a, olda);
+    b = safe_add(b, oldb);
+    c = safe_add(c, oldc);
+    d = safe_add(d, oldd);
+  }
+  return Array(a, b, c, d);
+
+}
+
+/*
+ * These functions implement the four basic operations the algorithm uses.
+ */
+function md5_cmn(q, a, b, x, s, t)
+{
+  return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
+}
+function md5_ff(a, b, c, d, x, s, t)
+{
+  return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
+}
+function md5_gg(a, b, c, d, x, s, t)
+{
+  return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
+}
+function md5_hh(a, b, c, d, x, s, t)
+{
+  return md5_cmn(b ^ c ^ d, a, b, x, s, t);
+}
+function md5_ii(a, b, c, d, x, s, t)
+{
+  return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
+}
+
+/*
+ * Calculate the HMAC-MD5, of a key and some data
+ */
+function core_hmac_md5(key, data)
+{
+  var bkey = str2binl(key);
+  if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);
+
+  var ipad = Array(16), opad = Array(16);
+  for(var i = 0; i < 16; i++)
+  {
+    ipad[i] = bkey[i] ^ 0x36363636;
+    opad[i] = bkey[i] ^ 0x5C5C5C5C;
+  }
+
+  var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
+  return core_md5(opad.concat(hash), 512 + 128);
+}
+
+/*
+ * Add integers, wrapping at 2^32. This uses 16-bit operations internally
+ * to work around bugs in some JS interpreters.
+ */
+function safe_add(x, y)
+{
+  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
+  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
+  return (msw << 16) | (lsw & 0xFFFF);
+}
+
+/*
+ * Bitwise rotate a 32-bit number to the left.
+ */
+function bit_rol(num, cnt)
+{
+  return (num << cnt) | (num >>> (32 - cnt));
+}
+
+/*
+ * Convert a string to an array of little-endian words
+ * If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
+ */
+function str2binl(str)
+{
+  var bin = Array();
+  var mask = (1 << chrsz) - 1;
+  for(var i = 0; i < str.length * chrsz; i += chrsz)
+    bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);
+  return bin;
+}
+
+/*
+ * Convert an array of little-endian words to a string
+ */
+function binl2str(bin)
+{
+  var str = "";
+  var mask = (1 << chrsz) - 1;
+  for(var i = 0; i < bin.length * 32; i += chrsz)
+    str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);
+  return str;
+}
+
+/*
+ * Convert an array of little-endian words to a hex string.
+ */
+function binl2hex(binarray)
+{
+  var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
+  var str = "";
+  for(var i = 0; i < binarray.length * 4; i++)
+  {
+    str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
+           hex_tab.charAt((binarray[i>>2] >> ((i%4)*8  )) & 0xF);
+  }
+  return str;
+}
+
+/*
+ * Convert an array of little-endian words to a base-64 string
+ */
+function binl2b64(binarray)
+{
+  var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+  var str = "";
+  for(var i = 0; i < binarray.length * 4; i += 3)
+  {
+    var triplet = (((binarray[i   >> 2] >> 8 * ( i   %4)) & 0xFF) << 16)
+                | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )
+                |  ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);
+    for(var j = 0; j < 4; j++)
+    {
+      if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
+      else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
+    }
+  }
+  return str;
+}
+
+/* 
#############################################################################
+   UTF-8 Decoder and Encoder
+   base64 Encoder and Decoder
+   written by Tobias Kieslich, justdreams
+   Contact: address@hidden                             
http://www.justdreams.de/
+   
############################################################################# */
+
+// returns an array of byterepresenting dezimal numbers which represent the
+// plaintext in an UTF-8 encoded version. Expects a string.
+// This function includes an exception management for those nasty browsers like
+// NN401, which returns negative decimal numbers for chars>128. I hate it!!
+// This handling is unfortunately limited to the user's charset. Anyway, it 
works
+// in most of the cases! Special signs with an unicode>256 return numbers, 
which
+// can not be converted to the actual unicode and so not to the valid utf-8
+// representation. Anyway, this function does always return values which can 
not
+// misinterpretd by RC4 or base64 en- or decoding, because every value is >0 
and
+// <255!!
+// Arrays are faster and easier to handle in b64 encoding or encrypting....
+function utf8t2d(t)
+{
+  t = t.replace(/\r\n/g,"\n");
+  var d=new Array; var test=String.fromCharCode(237);
+  if (test.charCodeAt(0) < 0) 
+    for(var n=0; n<t.length; n++)
+      {
+        var c=t.charCodeAt(n);
+        if (c>0)
+          d[d.length]= c;
+        else {
+          d[d.length]= (((256+c)>>6)|192);
+          d[d.length]= (((256+c)&63)|128);}
+      }
+  else
+    for(var n=0; n<t.length; n++)
+      {
+        var c=t.charCodeAt(n);
+        // all the signs of asci => 1byte
+        if (c<128)
+          d[d.length]= c;
+        // all the signs between 127 and 2047 => 2byte
+        else if((c>127) && (c<2048)) {
+          d[d.length]= ((c>>6)|192);
+          d[d.length]= ((c&63)|128);}
+        // all the signs between 2048 and 66536 => 3byte
+        else {
+          d[d.length]= ((c>>12)|224);
+          d[d.length]= (((c>>6)&63)|128);
+          d[d.length]= ((c&63)|128);}
+      }
+  return d;
+}
+               
+// returns plaintext from an array of bytesrepresenting dezimal numbers, which
+// represent an UTF-8 encoded text; browser which does not understand unicode
+// like NN401 will show "?"-signs instead
+// expects an array of byterepresenting decimals; returns a string
+function utf8d2t(d)
+{
+  var r=new Array; var i=0;
+  while(i<d.length)
+    {
+      if (d[i]<128) {
+        r[r.length]= String.fromCharCode(d[i]); i++;}
+      else if((d[i]>191) && (d[i]<224)) {
+        r[r.length]= String.fromCharCode(((d[i]&31)<<6) | (d[i+1]&63)); i+=2;}
+      else {
+        r[r.length]= String.fromCharCode(((d[i]&15)<<12) | ((d[i+1]&63)<<6) | 
(d[i+2]&63)); i+=3;}
+    }
+  return r.join("");
+}
+
+// included in <body onload="b64arrays"> it creates two arrays which makes 
base64
+// en- and decoding faster
+// this speed is noticeable especially when coding larger texts (>5k or so)
+function b64arrays() {
+  var b64s='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
+  b64 = new Array();f64 =new Array();
+  for (var i=0; i<b64s.length ;i++) {
+    b64[i] = b64s.charAt(i);
+    f64[b64s.charAt(i)] = i;
+  }
+}
+
+// creates a base64 encoded text out of an array of byerepresenting dezimals
+// it is really base64 :) this makes serversided handling easier
+// expects an array; returns a string
+function b64d2t(d) {
+  var r=new Array; var i=0; var dl=d.length;
+  // this is for the padding
+  if ((dl%3) == 1) {
+    d[d.length] = 0; d[d.length] = 0;}
+  if ((dl%3) == 2)
+    d[d.length] = 0;
+  // from here conversion
+  while (i<d.length)
+    {
+      r[r.length] = b64[d[i]>>2];
+      r[r.length] = b64[((d[i]&3)<<4) | (d[i+1]>>4)];
+      r[r.length] = b64[((d[i+1]&15)<<2) | (d[i+2]>>6)];
+      r[r.length] = b64[d[i+2]&63];
+      if ((i%57)==54)
+        r[r.length] = "\n";
+      i+=3;
+    }
+  // this is again for the padding
+  if ((dl%3) == 1)
+    r[r.length-1] = r[r.length-2] = "=";
+  if ((dl%3) == 2)
+    r[r.length-1] = "=";
+  // we join the array to return a textstring
+  var t=r.join("");
+  return t;
+}
+
+// returns array of byterepresenting numbers created of an base64 encoded text
+// it is still the slowest function in this modul; I hope I can make it faster
+// expects string; returns an array
+function b64t2d(t) {
+  var d=new Array; var i=0;
+  // here we fix this CRLF sequenz created by MS-OS; arrrgh!!!
+  t=t.replace(/\n|\r/g,""); t=t.replace(/=/g,"");
+  while (i<t.length)
+    {
+      d[d.length] = (f64[t.charAt(i)]<<2) | (f64[t.charAt(i+1)]>>4);
+      d[d.length] = (((f64[t.charAt(i+1)]&15)<<4) | (f64[t.charAt(i+2)]>>2));
+      d[d.length] = (((f64[t.charAt(i+2)]&3)<<6) | (f64[t.charAt(i+3)]));
+      i+=4;
+    }
+  if (t.length%4 == 2)
+    d = d.slice(0, d.length-2);
+  if (t.length%4 == 3)
+    d = d.slice(0, d.length-1);
+  return d;
+}
+
+if (typeof(atob) == 'undefined' || typeof(btoa) == 'undefined')
+  b64arrays();
+
+if (typeof(atob) == 'undefined') {
+  atob = function(s) {
+    return utf8d2t(b64t2d(s)); 
+  }
+}
+
+if (typeof(btoa) == 'undefined') {
+  btoa = function(s) { 
+    return b64d2t(utf8t2d(s));
+  }
+}
+
+function cnonce(size) {
+  var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+  var cnonce = '';
+  for (var i=0; i<size; i++) {
+    cnonce += tab.charAt(Math.round(Math.random(new 
Date().getTime())*(size-1)));
+  }
+  return cnonce;
+}

Index: JSJaCConnection.js
===================================================================
RCS file: JSJaCConnection.js
diff -N JSJaCConnection.js
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ JSJaCConnection.js  24 Feb 2007 23:02:06 -0000      1.1
@@ -0,0 +1,791 @@
+JSJaC_HAVEKEYS = true;  // whether to use keys
+JSJaC_NKEYS    = 16;    // number of keys to generate
+JSJAC_INACTIVITY = 300; // qnd hack to make suspend/resume work more smoothly 
with polling
+JSJAC_ERR_COUNT = 10;  // number of retries in case of connection errors
+
+JSJAC_ALLOW_PLAIN = true; // whether to allow plaintext logins
+
+JSJaC_CheckQueueInterval = 100; // msecs to poll send queue
+JSJaC_CheckInQueueInterval = 1; // msecs to poll in queue
+/* ******************************
+ * JabberConnection 
+ * somewhat abstract base class
+ */
+
+function JSJaCConnection(oArg) {
+  oCon = this; // remember reference to ourself
+  if (oArg && oArg.oDbg && oArg.oDbg.log)
+    this.oDbg = oArg.oDbg; 
+  else {
+    this.oDbg = new Object(); // always initialise a debugger
+    this.oDbg.log = function() { };
+  }
+
+  if (oArg && oArg.httpbase)
+    this._httpbase = oArg.httpbase;
+
+  if (oArg && typeof(oArg.allow_plain) != 'undefined')
+    this.allow_plain = oArg.allow_plain;
+  else 
+    this.allow_plain = JSJAC_ALLOW_PLAIN;
+
+  this._connected = false;
+  this._events = new Array();
+  this._keys = null;
+  this._ID = 0;
+  this._inQ = new Array();
+  this._pQueue = new Array();
+  this._regIDs = new Array();
+  this._req = new Array();
+  this._status = 'intialized';
+  this._errcnt = 0;
+  this._inactivity = JSJAC_INACTIVITY;
+
+  this.connected = function() { return this._connected; };
+  this.getPollInterval = function() { return this._timerval; };
+  this.registerHandler = function(event,handler) {
+    event = event.toLowerCase(); // don't be case-sensitive here
+    if (!this._events[event])
+      this._events[event] = new Array(handler);
+    else
+      this._events[event] = this._events[event].concat(handler);
+    this.oDbg.log("registered handler for event '"+event+"'",2);
+  };
+  this.resume = function() {
+    var s = readCookie('s');
+
+    if (!s)
+      return false;
+
+    this.oDbg.log('read cookie: '+s,4);
+
+    o = JSON.parse(s);
+
+    for (var i in o)
+      this[i] = o[i];
+
+    // copy keys - not being very generic here :-/
+    if (this._keys) {
+      this._keys2 = new JSJaCKeys();
+      var u = this._keys2._getSuspendVars();
+      for (var i=0; i<u.length; i++) 
+        this._keys2[u[i]] = this._keys[u[i]];
+      this._keys = this._keys2;
+    }
+
+    if (this._connected)
+      setTimeout("oCon._resume()",this.getPollInterval()); // don't poll too 
fast!
+    return this._connected;
+  }
+  this.send = JSJaCSend;
+  this.setPollInterval = function(timerval) {
+    if (!timerval || isNaN(timerval)) {
+      this.oDbg.log("Invalid timerval: " + timerval,1);
+      return -1;
+    }
+    this._timerval = timerval;
+    return this._timerval;
+  };
+  if (oArg && oArg.timerval)
+    this.setPollInterval(oArg.timerval);
+  this.status = function() { return this._status; }
+  this.suspend = function() {
+               
+    // remove timers
+    clearTimeout(this._timeout);
+    clearInterval(this._interval);
+    clearInterval(this._inQto);
+
+    var u = 
('_connected,_keys,_ID,_inQ,_pQueue,_regIDs,_errcnt,_inactivity,domain,username,resource,jid,fulljid,_sid,_httpbase,_timerval,_is_polling').split(',');
+    u = u.concat(this._getSuspendVars());
+    var s = new Object();
+
+    for (var i=0; i<u.length; i++) {
+      if (!this[u[i]]) continue; // hu? skip these!
+      if (this[u[i]]._getSuspendVars) {
+        var uo = this[u[i]]._getSuspendVars();
+        var o = new Object();
+        for (var j=0; j<uo.length; j++)
+          o[uo[j]] = this[u[i]][uo[j]];
+      } else
+        var o = this[u[i]];
+
+      s[u[i]] = o;
+    }
+               
+    createCookie('s',JSON.toString(s),this._inactivity)
+
+    this._connected = false;
+
+    this._setStatus('suspending');
+  }
+
+  this._abort       = JSJaCAbort;
+  this._checkInQ    = JSJaCCheckInQ;
+  this._checkQueue  = JSJaCHBCCheckQueue;
+
+  this._doAuth          = JSJaCAuth;
+
+  this._doInBandReg     = JSJaCInBandReg;
+  this._doInBandRegDone = JSJaCInBandRegDone;
+
+  this._doLegacyAuth    = JSJaCLegacyAuth;
+  this._doLegacyAuth2   = JSJaCLegacyAuth2;
+  this._doLegacyAuthDone= JSJaCLegacyAuthDone;
+
+  this._sendRaw         = JSJaCSendRaw;
+
+  this._doSASLAuth      = JSJaCSASLAuth;
+
+  this._doSASLAuthDigestMd5S1 = JSJaCSASLAuthDigestMd5S1;
+  this._doSASLAuthDigestMd5S2 = JSJaCSASLAuthDigestMd5S2;
+
+  this._doSASLAuthDone  = JSJaCSASLAuthDone;
+
+  this._doStreamBind    = JSJaCStreamBind;
+  this._doXMPPSess      = JSJaCXMPPSess;
+  this._doXMPPSessDone  = JSJaCXMPPSessDone;
+
+  this._handleEvent = function(event,arg) {
+    event = event.toLowerCase(); // don't be case-sensitive here
+    this.oDbg.log("incoming event '"+event+"'",3);
+    if (!this._events[event])
+      return;
+    this.oDbg.log("handling event '"+event+"'",2);
+    for (var i=0;i<this._events[event].length; i++) {
+      if (this._events[event][i]) {
+        try {
+          if (arg)
+            this._events[event][i](arg);
+          else
+            this._events[event][i]();
+        } catch (e) { this.oDbg.log(e.name+": "+ e.message); }
+      }
+    }
+  };
+  this._handlePID = function(aJSJaCPacket) {
+    if (!aJSJaCPacket.getID())
+      return false;
+    for (var i in this._regIDs) {
+      if (this._regIDs[i] && i == aJSJaCPacket.getID()) {
+        var pID = aJSJaCPacket.getID();
+        this.oDbg.log("handling "+pID,3);
+        try {
+          this._regIDs[i].cb(aJSJaCPacket,this._regIDs[i].arg);
+        } catch (e) { this.oDbg.log(e.name+": "+ e.message); }
+        this._unregisterPID(pID);
+        return true;
+      }
+    }
+    return false;
+  };
+  this._handleResponse = JSJaCHandleResponse;
+  this._parseStreamFeatures = JSJaCParseStreamFeatures;
+  this._process = JSJaCProcess;
+  this._registerPID = function(pID,cb,arg) {
+    if (!pID || !cb)
+      return false;
+    this._regIDs[pID] = new Object();
+    this._regIDs[pID].cb = cb;
+    if (arg)
+      this._regIDs[pID].arg = arg;
+    this.oDbg.log("registered "+pID,3);
+    return true;
+  };
+  this._sendEmpty = JSJaCSendEmpty;
+  this._setStatus = function(status) {
+    if (!status || status == '')
+      return;
+    if (status != this._status) { // status changed!
+      this._status = status;
+      this._handleEvent('status_changed', status);
+    }
+  }
+  this._unregisterPID = function(pID) {
+    if (!this._regIDs[pID])
+      return false;
+    this._regIDs[pID] = null;
+    this.oDbg.log("unregistered "+pID,3);
+    return true;
+  };
+
+}
+
+/*** *** *** START AUTH STUFF *** *** ***/
+
+function JSJaCParseStreamFeatures(doc) {
+  if (!doc || !doc.xml) {
+    this.oDbg.log("nothing to parse ... aborting",1);
+    return false;
+  }
+  this.oDbg.log(doc.xml,2);
+
+  this.mechs = new Object(); 
+  var lMec1 = doc.getElementsByTagName("mechanisms");
+  this.has_sasl = false;
+  for (var i=0; i<lMec1.length; i++)
+    if (lMec1.item(i).getAttribute("xmlns") == 
"urn:ietf:params:xml:ns:xmpp-sasl") {
+      this.has_sasl=true;
+      var lMec2 = lMec1.item(i).getElementsByTagName("mechanism");
+      for (var j=0; j<lMec2.length; j++)
+        this.mechs[lMec2.item(j).firstChild.nodeValue] = true;
+      break;
+    }
+  if (this.has_sasl)
+    this.oDbg.log("SASL detected",2);
+  else {
+    this.authtype = 'nonsasl';
+    this.oDbg.log("No support for SASL detected",2);
+  }
+
+  /* [TODO] 
+   * check if in-band registration available
+   * check for session and bind features
+   */
+}
+
+function JSJaCInBandReg() {
+  if (this.authtype == 'saslanon' || this.authtype == 'anonymous')
+    return; // bullshit - no need to register if anonymous
+
+  /* ***
+   * In-Band Registration see JEP-0077
+   */
+
+  var iq = new JSJaCIQ();
+  iq.setType('set');
+  iq.setID('reg1');
+  var query = iq.setQuery('jabber:iq:register');
+  
query.appendChild(iq.getDoc().createElement('username')).appendChild(iq.getDoc().createTextNode(this.username));
+  
query.appendChild(iq.getDoc().createElement('password')).appendChild(iq.getDoc().createTextNode(this.pass));
+
+  this.send(iq,this._doInBandRegDone);
+}
+
+function JSJaCInBandRegDone(iq) {
+  if (iq && iq.getType() == 'error') { // we failed to register
+    oCon.oDbg.log("registration failed for "+oCon.username,0);
+    
oCon._handleEvent('onerror',iq.getNode().getElementsByTagName('error').item(0));
+    return;
+  }
+
+  oCon.oDbg.log(oCon.username + " registered succesfully",0);
+
+  oCon._doAuth();
+}
+
+function JSJaCAuth() {
+  if (this.has_sasl && this.authtype == 'nonsasl')
+    this.oDbg.log("Warning: SASL present but not used", 1);
+
+  if (!this._doSASLAuth() && 
+      !this._doLegacyAuth()) {
+    this.oDbg.log("Auth failed for authtype "+this.authtype,1);
+    this.disconnect();
+    return false;
+  }
+  return true;
+}
+
+/*** *** *** LEGACY AUTH *** *** ***/
+
+function JSJaCLegacyAuth() {
+  if (this.authtype != 'nonsasl' && this.authtype != 'anonymous')
+    return false;
+
+  /* ***
+   * Non-SASL Authentication as described in JEP-0078
+   */
+  var iq = new JSJaCIQ();
+  iq.setIQ(oCon.server,null,'get','auth1');
+  var query = iq.setQuery('jabber:iq:auth');
+  
query.appendChild(iq.getDoc().createElement('username')).appendChild(iq.getDoc().createTextNode(oCon.username));
+
+  this.send(iq,this._doLegacyAuth2);
+  return true;
+}
+
+function JSJaCLegacyAuth2(iq) {
+  if (!iq || iq.getType() != 'result') {
+    if (iq.getType() == 'error') 
+      
oCon._handleEvent('onerror',iq.getNode().getElementsByTagName('error').item(0));
+    oCon.disconnect();
+    return;
+  } 
+
+  oCon.oDbg.log("got iq: " + iq.xml(),4);
+  var use_digest = false;
+  for (var aChild=iq.getNode().firstChild.firstChild; aChild!=null; 
aChild=aChild.nextSibling) {
+    if (aChild.nodeName == 'digest') {
+      use_digest = true;
+      break;
+    }
+  }
+
+  /* ***
+   * Send authentication
+   */
+  iq = new JSJaCIQ();
+  iq.setIQ(oCon.server,null,'set','auth2');
+  query = iq.setQuery('jabber:iq:auth');
+  
query.appendChild(iq.getDoc().createElement('username')).appendChild(iq.getDoc().createTextNode(oCon.username));
+  
query.appendChild(iq.getDoc().createElement('resource')).appendChild(iq.getDoc().createTextNode(oCon.resource));
+
+  if (use_digest) { // digest login
+    
query.appendChild(iq.getDoc().createElement('digest')).appendChild(iq.getDoc().createTextNode(hex_sha1(oCon.streamid
 + oCon.pass)));
+  } else if (oCon.allow_plain) { // use plaintext auth
+    
query.appendChild(iq.getDoc().createElement('password')).appendChild(iq.getDoc().createTextNode(oCon.pass));
+  } else {
+    oCon.oDbg.log("no valid login mechanism found",1);
+    oCon.disconnect();
+    return false;
+  }
+
+  oCon.send(iq,oCon._doLegacyAuthDone);
+}
+
+/* ***
+ * check if auth' was successful
+ */
+function JSJaCLegacyAuthDone(iq) {
+  if (iq.getType() != 'result') { // auth' failed
+    if (iq.getType() == 'error')
+      
oCon._handleEvent('onerror',iq.getNode().getElementsByTagName('error').item(0));
+    oCon.disconnect();
+  } else
+    oCon._handleEvent('onconnect');
+}
+
+/*** *** *** END LEGACY AUTH *** *** ***/
+
+/*** *** *** SASL AUTH *** *** ***/
+
+function JSJaCSASLAuth() {
+  if (this.authtype == 'nonsasl' || this.authtype == 'anonymous')
+    return false;
+
+  if (this.authtype == 'saslanon') {
+    if (this.mechs['ANONYMOUS']) {
+      this.oDbg.log("SASL using mechanism 'ANONYMOUS'",2);
+      return this._sendRaw("<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' 
mechanism='ANONYMOUS'/>",
+                           '_doSASLAuthDone');
+    }
+    this.oDbg.log("SASL ANONYMOUS requested but not supported",1);
+  } else {
+    if (this.mechs['DIGEST-MD5']) {
+      this.oDbg.log("SASL using mechanism 'DIGEST-MD5'",2);
+      return this._sendRaw("<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' 
mechanism='DIGEST-MD5'/>",
+                           '_doSASLAuthDigestMd5S1');
+    } else if (this.allow_plain && this.mechs['PLAIN']) {
+      this.oDbg.log("SASL using mechanism 'PLAIN'",2);
+      var authStr = this.username+'@'+
+        this.domain+String.fromCharCode(0)+
+        this.username+String.fromCharCode(0)+
+        this.pass;
+      this.oDbg.log("authenticating with '"+authStr+"'",2);
+      authStr = btoa(authStr);
+      return this._sendRaw("<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' 
mechanism='PLAIN'>"+authStr+"</auth>", 
+                           '_doSASLAuthDone');
+    }
+    this.oDbg.log("No SASL mechanism applied",1);
+    this.authtype = 'nonsasl'; // fallback
+  }
+  return false;
+}
+
+function JSJaCSASLAuthDigestMd5S1(req) {
+  this.oDbg.log(req.r.responseText,2);
+
+  var doc = oCon._prepareResponse(req);
+  if (!doc || doc.getElementsByTagName("challenge").length == 0) {
+    this.oDbg.log("challenge missing",1);
+    this.disconnect();
+  } else {
+    var challenge = atob(doc.getElementsByTagName("challenge")
+                         .item(0).firstChild.nodeValue);
+    this.oDbg.log("got challenge: "+challenge,2);
+    this._nonce = challenge.substring(challenge.indexOf("nonce=")+7);
+    this._nonce = this._nonce.substring(0,this._nonce.indexOf("\""));
+    this.oDbg.log("nonce: "+this._nonce,2);
+    if (this._nonce == '' || this._nonce.indexOf('\"') != -1) {
+      this.oDbg.log("nonce not valid, aborting",1);
+      this.disconnect();
+      return;
+    }
+
+    this._digest_uri = "xmpp/";
+//     if (typeof(this.host) != 'undefined' && this.host != '') {
+//       this._digest-uri += this.host;
+//       if (typeof(this.port) != 'undefined' && this.port)
+//         this._digest-uri += ":" + this.port;
+//       this._digest-uri += '/';
+//     }
+    this._digest_uri += this.domain;
+
+    this._cnonce = cnonce(14);
+
+    this._nc = '00000001';
+
+    var A1 = str_md5(this.username+':'+this.domain+':'+this.pass)+
+      ':'+this._nonce+':'+this._cnonce;
+
+    var A2 = 'AUTHENTICATE:'+this._digest_uri;
+
+    var response = hex_md5(hex_md5(A1)+':'+this._nonce+':'+this._nc+':'+
+                           this._cnonce+':auth:'+hex_md5(A2));
+
+    var rPlain = 'username="'+this.username+'",realm="'+this.domain+
+      '",nonce="'+this._nonce+'",cnonce="'+this._cnonce+'",nc="'+this._nc+
+      '",qop=auth,digest-uri="'+this._digest_uri+'",response="'+response+
+      '",charset=utf-8';
+    
+    this.oDbg.log("response: "+rPlain,2);
+
+    this._sendRaw("<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>"+
+                  binb2b64(str2binb(rPlain))+"</response>",
+                  '_doSASLAuthDigestMd5S2');
+  }
+}
+
+function JSJaCSASLAuthDigestMd5S2(req) {
+  this.oDbg.log(req.r.responseText,2);
+
+  var doc = this._prepareResponse(req);
+
+  if (doc.firstChild.nodeName == 'failure') {
+    this.oDbg.log("auth error: "+doc.firstChild.xml,1);
+    this.disconnect();
+  }
+
+  var response = atob(doc.firstChild.firstChild.nodeValue)
+  this.oDbg.log("response: "+response,2);
+
+  var rspauth = response.substring(response.indexOf("rspauth=")+8);
+  this.oDbg.log("rspauth: "+rspauth,2);
+
+  var A1 = str_md5(this.username+':'+this.domain+':'+this.pass)+
+    ':'+this._nonce+':'+this._cnonce;
+
+  var A2 = ':'+this._digest_uri;
+
+  var rsptest = hex_md5(hex_md5(A1)+':'+this._nonce+':'+this._nc+':'+
+                        this._cnonce+':auth:'+hex_md5(A2));
+  this.oDbg.log("rsptest: "+rsptest,2);
+
+  if (rsptest != rspauth) {
+    this.oDbg.log("SASL Digest-MD5: server repsonse with wrong rspauth",1);
+    this.disconnect();
+    return;
+  }
+
+  if (doc.firstChild.nodeName == 'success')
+    this._reInitStream(this.domain,'_doStreamBind');
+  else // some extra turn
+    this._sendRaw("<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>",
+                  '_doSASLAuthDone');
+}
+
+function JSJaCSASLAuthDone(req) {
+  var doc = this._prepareResponse(req);
+  if (doc.firstChild.nodeName != 'success') {
+    this.oDgb.log("auth failed",1);
+    this.disconnect();
+  } else
+    this._reInitStream(this.domain,'_doStreamBind');
+}
+
+function JSJaCStreamBind() {
+  iq = new JSJaCIQ();
+  iq.setIQ(this.domain,null,'set','bind_1');
+  var eBind = iq.getDoc().createElement("bind");
+  eBind.setAttribute("xmlns","urn:ietf:params:xml:ns:xmpp-bind");
+  eBind.appendChild(iq.getDoc().createElement("resource"))
+    .appendChild(iq.getDoc().createTextNode(this.resource));
+  iq.getNode().appendChild(eBind);
+  this.oDbg.log(iq.xml());
+  this.send(iq,this._doXMPPSess);
+}
+
+function JSJaCXMPPSess(iq) {
+  if (iq.getType() != 'result' || iq.getType() == 'error') { // failed
+    oCon.disconnect();
+    if (iq.getType() == 'error')
+      
oCon._handleEvent('onerror',iq.getNode().getElementsByTagName('error').item(0));
+    return;
+  }
+  
+  oCon.fulljid = 
iq.getDoc().firstChild.getElementsByTagName('jid').item(0).firstChild.nodeValue;
+  oCon.jid = oCon.fulljid.substring(0,oCon.fulljid.lastIndexOf('/'));
+  
+  iq = new JSJaCIQ();
+  iq.setIQ(this.domain,null,'set','sess_1');
+  var eSess = iq.getDoc().createElement("session");
+  eSess.setAttribute("xmlns","urn:ietf:params:xml:ns:xmpp-session");
+  iq.getNode().appendChild(eSess);
+  oCon.oDbg.log(iq.xml());
+  oCon.send(iq,oCon._doXMPPSessDone);
+}
+
+function JSJaCXMPPSessDone(iq) {
+  if (iq.getType() != 'result' || iq.getType() == 'error') { // failed
+    oCon.disconnect();
+    if (iq.getType() == 'error')
+      
oCon._handleEvent('onerror',iq.getNode().getElementsByTagName('error').item(0));
+    return;
+  } else
+    oCon._handleEvent('onconnect');
+}
+
+/*** *** *** END SASL AUTH *** *** ***/
+
+/*** *** *** END AUTH STUFF *** *** ***/
+
+function JSJaCSendRaw(xml,cb,arg) 
+{
+  var slot = this._getFreeSlot();
+  this._req[slot] = this._setupRequest(true);
+  
+  this._req[slot].r.onreadystatechange = function() {
+    if (typeof(oCon) == 'undefined' || !oCon || !oCon.connected())
+      return;
+    if (oCon._req[slot].r.readyState == 4) {
+      oCon.oDbg.log("async recv: "+oCon._req[slot].r.responseText,4);
+      if (typeof(cb) != 'undefined')
+        eval("oCon."+cb+"(oCon._req[slot],"+arg+")");
+    }
+  }
+  
+  if (typeof(this._req[slot].r.onerror) != 'undefined') {
+    this._req[slot].r.onerror = function(e) {
+      if (typeof(oCon) == 'undefined' || !oCon || !oCon.connected())
+        return;
+      oCon.oDbg.log('XmlHttpRequest error',1);
+      return false;
+    }
+  }
+  
+  var reqstr = this._getRequestString(xml);
+  this.oDbg.log("sending: " + reqstr,4);
+  this._req[slot].r.send(reqstr);
+  return true;
+}
+
+/* ***
+ * send a jsjac packet
+ * optional args: cb  - callback to be called when result is received)
+ *                arg - additional argument to be passed to callback
+ */
+function JSJaCSend(aJSJaCPacket,cb,arg) {
+  // remember id for response if callback present
+  if (aJSJaCPacket && cb) {
+    if (!aJSJaCPacket.getID())
+      aJSJaCPacket.setID('JSJaCID_'+this._ID++); // generate an ID
+
+    // register callback with id
+    this._registerPID(aJSJaCPacket.getID(),cb,arg);
+  }
+
+  if (aJSJaCPacket) {
+    try {
+      this._pQueue = this._pQueue.concat(aJSJaCPacket.xml());
+    } catch (e) {
+      this.oDbg.log(e.toString(),1);
+    }
+  }
+
+  return;
+}
+
+function JSJaCProcess(timerval) {
+  if (!this.connected()) {
+    this.oDbg.log("Connection lost ...",1);
+    if (this._interval)
+      clearInterval(this._interval);
+    return;
+  }
+
+  if (timerval)
+    this.setPollInterval(timerval);
+
+  if (this._timeout)
+    clearTimeout(this._timeout);
+
+  var slot = this._getFreeSlot();
+       
+  if (slot < 0)
+    return;
+
+  if (typeof(this._req[slot]) != 'undefined' && typeof(this._req[slot].r) != 
'undefined' && this._req[slot].r.readyState != 4) {
+    this.oDbg.log("Slot "+slot+" is not ready");
+    return;
+  }
+               
+  if (!this.isPolling() && this._pQueue.length == 0 && this._req[(slot+1)%2] 
&& this._req[(slot+1)%2].r.readyState != 4)
+    return;
+
+  if (!this.isPolling())
+    this.oDbg.log("Found working slot at "+slot,2);
+
+  this._req[slot] = this._setupRequest(true);
+
+  /* setup onload handler for async send */
+  this._req[slot].r.onreadystatechange = function() {
+    if (typeof(oCon) == 'undefined' || !oCon || !oCon.connected())
+      return;
+    oCon.oDbg.log("ready state changed for slot "+slot+" 
["+oCon._req[slot].r.readyState+"]",4);
+    if (oCon._req[slot].r.readyState == 4) {
+      oCon._setStatus('processing');
+      oCon.oDbg.log("async recv: "+oCon._req[slot].r.responseText,4);
+      oCon._handleResponse(oCon._req[slot]);
+      if (oCon._pQueue.length)
+        oCon._process();
+      else // schedule next tick
+        oCon._timeout = setTimeout("oCon._process()",oCon.getPollInterval());
+
+    }
+  };
+
+  if (typeof(this._req[slot].r.onerror) != 'undefined') {
+    this._req[slot].r.onerror = function(e) {
+      if (typeof(oCon) == 'undefined' || !oCon || !oCon.connected())
+        return;
+      oCon._errcnt++;
+      oCon.oDbg.log('XmlHttpRequest error ('+oCon._errcnt+')',1);
+      if (oCon._errcnt > JSJAC_ERR_COUNT) {
+
+        // abort
+        oCon._abort();
+        return false;
+      }
+
+      oCon._setStatus('onerror_fallback');
+                               
+      // schedule next tick
+      setTimeout("oCon._resume()",oCon.getPollInterval());
+      return false;
+    };
+  }
+
+  var reqstr = this._getRequestString();
+
+  if (typeof(this._rid) != 'undefined') // remember request id if any
+    this._req[slot].rid = this._rid;
+
+  this.oDbg.log("sending: " + reqstr,4);
+  this._req[slot].r.send(reqstr);
+}
+
+function JSJaCHBCCheckQueue() {
+  if (this._pQueue.length != 0)
+    this._process();
+  return true;
+}
+
+/* ***
+ * send empty request 
+ * waiting for stream id to be able to proceed with authentication 
+ */
+function JSJaCSendEmpty() {
+  var slot = this._getFreeSlot();
+  this._req[slot] = this._setupRequest(true);
+
+  this._req[slot].r.onreadystatechange = function() {
+    if (typeof(oCon) == 'undefined' || !oCon)
+      return;
+    if (oCon._req[slot].r.readyState == 4) {
+      oCon.oDbg.log("async recv: "+oCon._req[slot].r.responseText,4);
+      oCon._getStreamID(slot); // handle response
+    }
+  }
+
+  if (typeof(this._req[slot].r.onerror) != 'undefined') {
+    this._req[slot].r.onerror = function(e) {
+      if (typeof(oCon) == 'undefined' || !oCon || !oCon.connected())
+        return;
+      oCon.oDbg.log('XmlHttpRequest error',1);
+      return false;
+    };
+  }
+
+  var reqstr = this._getRequestString();
+  this.oDbg.log("sending: " + reqstr,4);
+  this._req[slot].r.send(reqstr);
+}
+
+function JSJaCHandleResponse(req) {
+  var rootEl = this._prepareResponse(req);
+
+  if (!rootEl)
+    return null;
+
+  this.oDbg.log("childNodes: "+rootEl.childNodes.length,3);
+  for (var i=0; i<rootEl.childNodes.length; i++) {
+    this.oDbg.log("rootEl.childNodes.item("+i+").nodeName: 
"+rootEl.childNodes.item(i).nodeName,3);
+    this._inQ = this._inQ.concat(rootEl.childNodes.item(i));
+  }
+  return null;
+}
+
+function JSJaCCheckInQ() {
+  for (var i=0; i<this._inQ.length && i<10; i++) {
+    var item = this._inQ[0];
+    this._inQ = this._inQ.slice(1,this._inQ.length);
+    var aJSJaCPacket = JSJaCPWrapNode(item);
+    if (typeof(aJSJaCPacket.pType) != 'undefined')
+      if (!this._handlePID(aJSJaCPacket))
+        this._handleEvent(aJSJaCPacket.pType(),aJSJaCPacket);
+  }
+  //   this._inQto = 
setTimeout("oCon._checkInQ();",JSJaC_CheckInQueueInterval);
+}
+
+function JSJaCAbort() {
+  clearTimeout(this._timeout); // remove timer
+  this._connected = false;
+
+  this._setStatus('aborted');
+
+  this.oDbg.log("Disconnected.",1);
+  this._handleEvent('ondisconnect');
+  
this._handleEvent('onerror',JSJaCError('500','cancel','service-unavailable'));
+}
+
+/* ***
+ * an error packet for internal use
+ */
+function JSJaCError(code,type,condition) {
+  var xmldoc = XmlDocument.create("error","jsjac");
+
+  xmldoc.documentElement.setAttribute('code',code);
+  xmldoc.documentElement.setAttribute('type',type);
+  
xmldoc.documentElement.appendChild(xmldoc.createElement(condition)).setAttribute('xmlns','urn:ietf:params:xml:ns:xmpp-stanzas');
+  return xmldoc.documentElement.cloneNode(true);
+}
+
+/* ***
+ * set of sha1 hash keys for securing sessions
+ */                                                                            
        
+function JSJaCKeys(func,oDbg) {
+  var seed = Math.random();
+
+  this._k = new Array();
+  this._k[0] = seed.toString();
+  this.oDbg = oDbg;
+
+  if (func) {
+    for (var i=1; i<JSJaC_NKEYS; i++) {
+      this._k[i] = func(this._k[i-1]);
+      oDbg.log(i+": "+this._k[i],4);
+    }
+  }
+
+  this._indexAt = JSJaC_NKEYS-1;
+  this.getKey = function() { 
+    return this._k[this._indexAt--]; 
+  };
+  this.lastKey = function() { return (this._indexAt == 0); };
+  this.size = function() { return this._k.length; };
+
+  this._getSuspendVars = function() {
+    return ('_k,_indexAt').split(',');
+  }
+}

Index: JSJaCHttpBindingConnection.js
===================================================================
RCS file: JSJaCHttpBindingConnection.js
diff -N JSJaCHttpBindingConnection.js
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ JSJaCHttpBindingConnection.js       24 Feb 2007 23:02:06 -0000      1.1
@@ -0,0 +1,457 @@
+var JSJaCHBC_MAX_HOLD = 1;
+var JSJACHBC_MAX_WAIT = 300; 
+
+function JSJaCHttpBindingConnection(oArg) {
+  this.base = JSJaCConnection;
+  this.base(oArg);
+
+  // member vars
+  this._hold = JSJaCHBC_MAX_HOLD;
+  this._inactivity = 0;
+  this._last_requests = new Object(); // 'hash' storing hold+1 last requests
+  this._last_rid = 0;                 // I know what you did last summer
+  this._min_polling = 0;
+  this._wait = JSJACHBC_MAX_WAIT;
+
+  // public methods
+  this.connect = JSJaCHBCConnect;
+  this.disconnect = JSJaCHBCDisconnect;
+  this.inherit = JSJaCHBCInherit;
+  this.isPolling = function() { return (this._hold == 0) }; 
+  this.setPollInterval = function(timerval) {
+    if (!timerval || isNaN(timerval)) {
+      this.oDbg.log("Invalid timerval: " + timerval,1);
+      return -1;
+    }
+    if (this._min_polling && timerval < this._min_polling*1000)
+      this._timerval = this._min_polling*1000;
+    else if (this._inactivity && timerval > this._inactivity*1000)
+      this._timerval = this._inactivity*1000;
+    else
+      this._timerval = timerval;
+    return this._timerval;
+  };
+
+  // private methods
+  this._getRequestString = JSJaCHBCGetRequestString;
+  this._getFreeSlot = function() {
+    for (var i=0; i<this._hold+1; i++)
+      if (typeof(this._req[i]) == 'undefined' || typeof(this._req[i].r) == 
'undefined' || this._req[i].r.readyState == 4)
+        return i;
+    return -1; // nothing found
+  }
+  this._getHold = function() { return this._hold; }
+  this._getStreamID = JSJaCHBCGetStreamID;
+  this._getSuspendVars = function() {
+    return 
('host,port,secure,_rid,_last_rid,_wait,_min_polling,_inactivity,_hold,_last_requests').split(',');
+  }
+  this._handleInitialResponse = JSJaCHBCHandleInitialResponse;
+  this._prepareResponse = JSJaCHBCPrepareResponse;
+  this._resume = function() { 
+    /* make sure to repeat last request as we can be sure that
+     * it had failed 
+     */
+    this._rid--; 
+    this._keys._indexAt++;
+    this._process();
+    this._inQto = setInterval("oCon._checkInQ();",JSJaC_CheckInQueueInterval);
+    this._interval= setInterval("oCon._checkQueue()",JSJaC_CheckQueueInterval);
+  }
+  this._setHold = function(hold)  {
+    if (!hold || isNaN(hold) || hold < 0)
+      hold = 0;
+    else if (hold > JSJaCHBC_MAX_HOLD)
+      hold = JSJaCHBC_MAX_HOLD;
+    this._hold = hold;
+    return this._hold;
+  };
+  this._setupRequest = JSJaCHBCSetupRequest;
+
+  this._reInitStream = JSJaCHBCReInitStream;
+}
+
+function JSJaCHBCConnect(oArg) {
+  // initial request to get sid and streamid
+
+  this._setStatus('connecting');
+
+  this.domain = oArg.domain || 'localhost';
+  this.username = oArg.username;
+  this.resource = oArg.resource;
+  this.pass = oArg.pass;
+  this.register = oArg.register;
+  this.oDbg.log("httpbase: " + this._httpbase + "\domain:" + this.domain,2);
+  this.host = oArg.host || this.domain;
+  this.port = oArg.port || 5222;
+  this.authhost = oArg.authhost || this.domain;
+  this.authtype = oArg.authtype || 'sasl';
+  if (oArg.secure) {
+    this.secure = 'true';
+//     if (!oArg.port)
+//       this.port = 5223;
+  } else 
+    this.secure = 'false';
+
+  this.jid = this.username + '@' + this.domain;
+  this.fulljid = this.jid + '/' + this.resource;
+
+  if (oArg.wait)
+    this._wait = oArg.wait;
+
+  if (oArg.xmllang && oArg.xmllang != '')
+    this._xmllang = oArg.xmllang;
+
+  this._rid  = Math.round( 100000.5 + ( ( (900000.49999) - (100000.5) ) * 
Math.random() ) );
+
+  // setupRequest must be done after rid is created but before first use in 
reqstr
+  var slot = this._getFreeSlot();
+  this._req[slot] = this._setupRequest(true); 
+  
+  var reqstr = "<body hold='"+this._hold+"' 
xmlns='http://jabber.org/protocol/httpbind' to='"+this.authhost+"' 
wait='"+this._wait+"' rid='"+this._rid+"'";
+  if (oArg.host || oArg.port)
+    reqstr += " route='xmpp:"+this.host+":"+this.port+"'";
+  if (oArg.secure)
+    reqstr += " secure='"+this.secure+"'";
+  if (JSJaC_HAVEKEYS) {
+    this._keys = new JSJaCKeys(hex_sha1,this.oDbg); // generate first set of 
keys
+    key = this._keys.getKey();
+    reqstr += " newkey='"+key+"'";
+  }
+  if (this._xmllang)
+    reqstr += " xml:lang='"+this._xmllang + "'";
+  reqstr += "/>";
+
+
+  this.oDbg.log(reqstr,4);
+
+  this._req[slot].r.onreadystatechange = function() {
+    if (typeof(oCon) == 'undefined' || !oCon)
+      return;
+    if (oCon._req[slot].r.readyState == 4) {
+      oCon.oDbg.log("async recv: "+oCon._req[slot].r.responseText,4);
+      oCon._handleInitialResponse(slot); // handle response
+    }
+  }
+
+  if (typeof(this._req[slot].r.onerror) != 'undefined') {
+    this._req[slot].r.onerror = function(e) {
+      if (typeof(oCon) == 'undefined' || !oCon || !oCon.connected())
+        return;
+      oCon.oDbg.log('XmlHttpRequest error',1);
+      return false;
+    };
+  }
+
+  this._req[slot].r.send(reqstr);
+}
+
+function JSJaCHBCHandleInitialResponse(slot) {
+  try {
+    // This will throw an error on Mozilla when the connection was refused
+    this.oDbg.log(this._req[slot].r.getAllResponseHeaders(),4);
+    this.oDbg.log(this._req[slot].r.responseText,4);
+  } catch(ex) {
+    this.oDbg.log("No response",4);
+  }
+
+  if (this._req[slot].r.status != 200 || !this._req[slot].r.responseXML) {
+    this.oDbg.log("initial response broken (status: 
"+this._req[slot].r.status+")",1);
+    
this._handleEvent('onerror',JSJaCError('503','cancel','service-unavailable'));
+    return;
+  }
+  var body = this._req[slot].r.responseXML.documentElement;
+
+  if (!body || body.tagName != 'body' || body.namespaceURI != 
'http://jabber.org/protocol/httpbind') {
+    this.oDbg.log("no body element or incorrect body in initial response",1);
+    
this._handleEvent("onerror",JSJaCError("500","wait","internal-service-error"));
+    return;
+  }
+
+  // Check for errors from the server
+  if (body.getAttribute("type") == "terminate") {
+    this.oDbg.log("invalid response:\n" + this._req[slot].r.responseText,1);
+    clearTimeout(this._timeout); // remove timer
+    this._connected = false;
+    this.oDbg.log("Disconnected.",1);
+    this._handleEvent('ondisconnect');
+    
this._handleEvent('onerror',JSJaCError('503','cancel','service-unavailable'));
+    return;
+  }
+
+  // get session ID
+  this._sid = body.getAttribute('sid');
+  this.oDbg.log("got sid: "+this._sid,2);
+
+  // get attributes from response body
+  if (body.getAttribute('polling'))
+    this._min_polling = body.getAttribute('polling');
+
+  if (body.getAttribute('inactivity'))
+    this._inactivity = body.getAttribute('inactivity');
+       
+  if (body.getAttribute('requests'))
+    this._setHold(body.getAttribute('requests')-1);
+  this.oDbg.log("set hold to " + this._getHold(),2);
+
+  // must be done after response attributes have been collected
+  this.setPollInterval(this._timerval);
+
+  /* start sending from queue for not polling connections */
+  this._connected = true;
+
+  this._inQto = setInterval("oCon._checkInQ();",JSJaC_CheckInQueueInterval);
+  this._interval= setInterval("oCon._checkQueue()",JSJaC_CheckQueueInterval);
+
+  /* wait for initial stream response to extract streamid needed
+   * for digest auth
+   */
+  this._getStreamID(slot);
+}
+
+function JSJaCHBCGetStreamID(slot) {
+
+  this.oDbg.log(this._req[slot].r.responseText,4);
+
+  if (!this._req[slot].r.responseXML || 
!this._req[slot].r.responseXML.documentElement) {
+    
this._handleEvent('onerror',JSJaCError('503','cancel','service-unavailable'));
+    return;
+  }
+  var body = this._req[slot].r.responseXML.documentElement;
+
+  // extract stream id used for non-SASL authentication
+  if (body.getAttribute('authid')) {
+    this.streamid = body.getAttribute('authid');
+    this.oDbg.log("got streamid: "+this.streamid,2);
+  } else {
+    this._timeout = setTimeout("oCon._sendEmpty()",this.getPollInterval());
+    return;
+  }
+
+  this._timeout = setTimeout("oCon._process()",this.getPollInterval());
+
+  this._parseStreamFeatures(body);
+       
+  if (this.register)
+    this._doInBandReg();
+  else
+    this._doAuth();
+}
+
+/* inherit an instantiated session */
+function JSJaCHBCInherit(oArg) {
+  this.domain = oArg.domain || 'localhost';
+  this.username = oArg.username;
+  this.resource = oArg.resource;
+  this._sid = oArg.sid;
+  this._rid = oArg.rid;
+  this._min_polling = oArg.polling;
+  this._inactivity = oArg.inactivity;
+  this._setHold(oArg.requests-1);
+  this.setPollInterval(this._timerval);
+  if (oArg.wait)
+    this._wait = oArg.wait; // for whatever reason
+
+  this._connected = true;
+
+  this._handleEvent('onconnect');
+
+  this._interval= setInterval("oCon._checkQueue()",JSJaC_CheckQueueInterval);
+  this._inQto = setInterval("oCon._checkInQ();",JSJaC_CheckInQueueInterval);
+  this._timeout = setTimeout("oCon._process()",this.getPollInterval());
+}
+
+function JSJaCHBCReInitStream(to,cb,arg) {
+  /* [TODO] we can't handle 'to' here as this is not (yet) supported
+   * by the protocol
+   */
+
+  // tell http binding to reinit stream with/before next request
+  oCon._reinit = true;
+  eval("oCon."+cb+"("+arg+")"); // proceed with next callback
+
+  /* [TODO] make sure that we're checking for new stream features when
+   * 'cb' finishes
+   */
+}
+
+function JSJaCHBCDisconnect() {
+       
+  this._setStatus('disconnecting');
+
+  if (!this.connected())
+    return;
+
+  clearInterval(this._interval);
+  clearInterval(this._inQto);
+
+  if (this._timeout)
+    clearTimeout(this._timeout); // remove timer
+
+  var slot = this._getFreeSlot();
+  // Intentionally synchronous
+  this._req[slot] = this._setupRequest(false);
+
+  var reqstr = "<body type='terminate' 
xmlns='http://jabber.org/protocol/httpbind' sid='"+this._sid+"' 
rid='"+this._rid+"'";
+  if (JSJaC_HAVEKEYS) {
+    reqstr += " key='"+this._keys.getKey()+"'";
+  }
+  reqstr += ">";
+
+  while (this._pQueue.length) {
+    var curNode = this._pQueue[0];
+    reqstr += curNode;
+    this._pQueue = this._pQueue.slice(1,this._pQueue.length);
+  }
+
+  //reqstr += "<presence type='unavailable' xmlns='jabber:client'/>";
+  reqstr += "</body>";
+
+  // Wait for response (for a limited time, 5s)
+  var abortTimerID = setTimeout("this._req[slot].abort();", 5000);
+  this.oDbg.log("Disconnecting: " + reqstr,4);
+  this._req[slot].r.send(reqstr);      
+  clearTimeout(abortTimerID);
+  eraseCookie('s');
+
+  oCon.oDbg.log("Disconnected: "+oCon._req[slot].r.responseText,2);
+  oCon._connected = false;
+  oCon._handleEvent('ondisconnect');
+}
+
+function JSJaCHBCSetupRequest(async) {
+  var req = new Object();
+  var r = XmlHttp.create();
+  try {
+    r.open("POST",this._httpbase,async);
+    r.setRequestHeader('Content-Type','text/xml; charset=utf-8');
+  } catch(e) { this.oDbg.log(e,1); }
+  req.r = r;
+  this._rid++;
+  req.rid = this._rid;
+  return req;
+}
+
+function JSJaCHBCGetRequestString(raw) {
+  raw = raw || '';
+  var xml = '';
+
+  // check if we're repeating a request
+
+  if (this._rid <= this._last_rid && typeof(this._last_requests[this._rid]) != 
'undefined') // repeat!
+    xml = this._last_requests[this._rid].xml;
+  else { // grab from queue
+    while (this._pQueue.length) {
+      var curNode = this._pQueue[0];
+      xml += curNode;
+      this._pQueue = this._pQueue.slice(1,this._pQueue.length);
+    }
+    this._last_requests[this._rid] = new Object();
+    this._last_requests[this._rid].xml = xml;
+    this._last_rid = this._rid;
+
+    for (var i in this._last_requests)
+      if (i < this._rid-this._hold)
+        delete(this._last_requests[i]); // truncate
+  }
+  var reqstr = "<body rid='"+this._rid+"' sid='"+this._sid+"' 
xmlns='http://jabber.org/protocol/httpbind' ";
+  if (JSJaC_HAVEKEYS) {
+    reqstr += "key='"+this._keys.getKey()+"' ";
+    if (this._keys.lastKey()) {
+      this._keys = new JSJaCKeys(hex_sha1,this.oDbg);
+      reqstr += "newkey='"+this._keys.getKey()+"' ";
+    }
+  }
+  if (this._reinit) {
+    reqstr += "xmpp:restart='true' ";
+    this._reinit = false;
+  }
+
+  if (xml != '' || raw != '') {
+    reqstr += ">" + raw + xml + "</body>";
+  } else {
+    reqstr += "/>"; 
+  }
+        
+  return reqstr;
+}
+
+function JSJaCHBCPrepareResponse(req) {
+  if (!this.connected())
+    return null;
+
+  var r = req.r; // the XmlHttpRequest
+
+  if (typeof(r) == 'undefined' || !r || typeof(r.status) == 'undefined')
+    return null;
+
+  /* handle error */
+       
+  if (r.status != 200 || !r.responseXML) {
+    this._errcnt++;
+    var errmsg = "invalid response ("+r.status+"):\n" + 
r.getAllResponseHeaders()+"\n"+r.responseText;
+    if (!r.responseXML)
+      errmsg += "\nResponse failed to parse!";
+    this.oDbg.log(errmsg,1);
+    if (this._errcnt > JSJAC_ERR_COUNT) {
+      // abort
+      oCon._abort();
+      return null;
+    }
+    this.oDbg.log("repeating ("+this._errcnt+")",1);
+
+    this._setStatus('proto_error_fallback');
+
+    // schedule next tick
+    setTimeout("oCon._resume()",oCon.getPollInterval());
+
+    return null;
+  } 
+
+  var body = r.responseXML.documentElement;
+  if (!body || body.tagName != 'body' || body.namespaceURI != 
'http://jabber.org/protocol/httpbind') {
+    this.oDbg.log("invalid response:\n" + r.responseText,1);
+
+    this._setStatus('internal_server_error');
+
+    clearTimeout(this._timeout); // remove timer
+    clearInterval(this._interval);
+    clearInterval(this._inQto);
+    
this._handleEvent('onerror',JSJaCError('500','wait','internal-server-error'));
+    this._connected = false;
+    this.oDbg.log("Disconnected.",1);
+    this._handleEvent('ondisconnect');
+    return null;
+
+  }
+
+  if (typeof(req.rid) != 'undefined' && this._last_requests[req.rid]) {
+    if (this._last_requests[req.rid].handled) {
+      this.oDbg.log("already handled "+req.rid,2);
+      return null;
+    } else 
+      this._last_requests[req.rid].handled = true;
+  }
+
+
+  // Check for errors from the server
+  if (body.getAttribute("type") == "terminate") {
+    this.oDbg.log("session terminated:\n" + r.responseText,1);
+
+    clearTimeout(this._timeout); // remove timer
+    clearInterval(this._interval);
+    clearInterval(this._inQto);
+
+    if (body.getAttribute("condition") == "remote-stream-error")
+      if (body.getElementsByTagName("conflict").length > 0)
+        this._setStatus("session-terminate-conflict");
+    
this._handleEvent('onerror',JSJaCError('503','cancel',body.getAttribute('condition')));
+    this._connected = false;
+    this.oDbg.log("Disconnected.",1);
+    this._handleEvent('ondisconnect');
+    return null;
+  }
+
+  // no error
+  this._errcnt = 0;
+  return r.responseXML.documentElement;
+}

Index: JSJaCHttpPollingConnection.js
===================================================================
RCS file: JSJaCHttpPollingConnection.js
diff -N JSJaCHttpPollingConnection.js
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ JSJaCHttpPollingConnection.js       24 Feb 2007 23:02:06 -0000      1.1
@@ -0,0 +1,285 @@
+function JSJaCHttpPollingConnection(oArg) {
+  this.base = JSJaCConnection;
+  this.base(oArg);
+
+  // give hint to JSJaCPacket that we're using HTTP Polling ...
+  JSJACPACKET_USE_XMLNS = false;
+
+  this.connect = JSJaCHPCConnect;
+  this.disconnect = JSJaCHPCDisconnect;
+  this.isPolling = function() { return true; };
+
+  this._getFreeSlot = function() {
+    if (typeof(this._req[0]) == 'undefined' || typeof(this._req[0].r) == 
'undefined' || this._req[0].r.readyState == 4)
+      return 0; 
+    else
+      return -1;
+  }
+  this._getRequestString = JSJaCHPCGetRequestString;
+  this._getStreamID = JSJaCHPCGetStream;
+  this._getSuspendVars = function() {
+    return new Array();
+  }
+  this._prepareResponse = JSJaCHPCPrepareResponse;
+  this._resume = function() { 
+    this._process(this._timerval);
+    this._interval= setInterval("oCon._checkQueue()",JSJaC_CheckQueueInterval);
+    this._inQto = setInterval("oCon._checkInQ();",JSJaC_CheckInQueueInterval);
+  }
+  this._setupRequest = JSJaCHPCSetupRequest;
+
+  this._reInitStream = JSJaCHPCReInitStream;
+}
+
+function JSJaCHPCSetupRequest(async) {
+  var r = XmlHttp.create();
+  try {
+    r.open("POST",this._httpbase,async);
+    r.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
+  } catch(e) { this.oDbg.log(e,1); }
+
+  var req = new Object();
+  req.r = r;
+  return req;
+}
+
+function JSJaCHPCGetRequestString(raw) {
+  var reqstr = this._sid;
+  if (JSJaC_HAVEKEYS) {
+    reqstr += ";"+this._keys.getKey();
+    if (this._keys.lastKey()) {
+      this._keys = new JSJaCKeys(b64_sha1,this.oDbg);
+      reqstr += ';'+this._keys.getKey();
+    }
+  }
+  reqstr += ',';
+  if (raw)
+    reqstr += raw;
+  while (this._pQueue.length) {
+    reqstr += this._pQueue[0];
+    this._pQueue = this._pQueue.slice(1,this._pQueue.length);
+  }
+  return reqstr;
+}
+
+function JSJaCHPCPrepareResponse(r) {
+  var req = r.r;
+  if (!this.connected())
+    return null;
+
+  /* handle error */
+  // proxy error (!)
+  if (req.status != 200) {
+    this.oDbg.log("invalid response ("+req.status+"):" + 
req.responseText+"\n"+req.getAllResponseHeaders(),1);
+
+    this._setStatus('internal_server_error');
+
+    clearTimeout(this._timeout); // remove timer
+    clearInterval(this._interval);
+    clearInterval(this._inQto);
+    this._connected = false;
+    this.oDbg.log("Disconnected.",1);
+    this._handleEvent('ondisconnect');
+    
this._handleEvent('onerror',JSJaCError('503','cancel','service-unavailable'));
+    return null;
+  } 
+
+  this.oDbg.log(req.getAllResponseHeaders(),4);
+  var aPList = req.getResponseHeader('Set-Cookie');
+  aPList = aPList.split(";");
+  var sid;
+  for (var i=0;i<aPList.length;i++) {
+    var aArg = aPList[i].split("=");
+    if (aArg[0] == 'ID')
+      sid = aArg[1];
+  }
+
+  // http polling component error
+  if (typeof(sid) != 'undefined' && sid.indexOf(':0') != -1) {
+    switch (sid.substring(0,sid.indexOf(':0'))) {
+    case '0':
+      this.oDbg.log("invalid response:" + req.responseText,1);
+      break;
+    case '-1':
+      this.oDbg.log("Internal Server Error",1);
+      break;
+    case '-2':
+      this.oDbg.log("Bad Request",1);
+      break;
+    case '-3':
+      this.oDbg.log("Key Sequence Error",1);
+      break;
+    }
+
+    this._setStatus('internal_server_error');
+
+    clearTimeout(this._timeout); // remove timer
+    clearInterval(this._interval);
+    clearInterval(this._inQto);
+    
this._handleEvent('onerror',JSJaCError('500','wait','internal-server-error'));
+    this._connected = false;
+    this.oDbg.log("Disconnected.",1);
+    this._handleEvent('ondisconnect');
+    return null;
+  }
+
+  if (!req.responseText || req.responseText == '')
+    return null;
+
+  try {
+               
+    var doc = _parseTree("<body>"+req.responseText+"</body>");
+
+    if (!doc || doc.tagName == 'parsererror') {
+      this.oDbg.log("parsererror",1);
+
+      doc = _parseTree("<stream:stream 
xmlns:stream='http://etherx.jabber.org/streams'>"+req.responseText);
+      if (doc && doc.tagName != 'parsererror') {
+        this.oDbg.log("stream closed",1);
+
+        if (doc.getElementsByTagName('conflict').length > 0)
+          this._setStatus("session-terminate-conflict");
+                               
+        clearTimeout(this._timeout); // remove timer
+        clearInterval(this._interval);
+        clearInterval(this._inQto);
+        
this._handleEvent('onerror',JSJaCError('503','cancel','session-terminate'));
+        this._connected = false;
+        this.oDbg.log("Disconnected.",1);
+        this._handleEvent('ondisconnect');
+      } else
+        this.oDbg.log("parsererror:"+doc,1);
+                       
+      return doc;
+    }
+
+    return doc;
+  } catch (e) {
+    this.oDbg.log("parse error:"+e.message,1);
+  }
+  return null;;
+}
+
+function _parseTree(s) {
+  try {
+    var r = XmlDocument.create("body","foo");
+    if (typeof(r.loadXML) != 'undefined') {
+      r.loadXML(s);
+      return r.documentElement;
+    } else if (window.DOMParser)
+      return (new DOMParser()).parseFromString(s, "text/xml").documentElement;
+  } catch (e) { }
+  return null;
+}
+
+function JSJaCHPCConnect(oArg) {
+  // initial request to get sid and streamid
+
+  this.domain = oArg.domain || 'localhost';
+  this.username = oArg.username;
+  this.resource = oArg.resource || 'jsjac';
+  this.pass = oArg.pass;
+  this.register = oArg.register;
+  this.authtype = oArg.authtype || 'sasl';
+
+  this.jid = this.username + '@' + this.domain;
+  this.fulljid = this.jid + this.resource;
+
+  this.authhost = oArg.authost || this.domain;
+
+  var reqstr = "0";
+  if (JSJaC_HAVEKEYS) {
+    this._keys = new JSJaCKeys(b64_sha1,this.oDbg); // generate first set of 
keys
+    key = this._keys.getKey();
+    reqstr += ";"+key;
+  }
+  var streamto = this.domain;
+  if (this.anonhost)
+    streamto = this.anonhost;
+  reqstr += ",<stream:stream to='"+streamto+"' xmlns='jabber:client' 
xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>";
+  this.oDbg.log(reqstr,4);
+
+  this._req[0] = this._setupRequest(false);    
+  this._req[0].r.send(reqstr);
+
+  // extract session ID
+  this.oDbg.log(this._req[0].r.getAllResponseHeaders(),4);
+  var aPList = this._req[0].r.getResponseHeader('Set-Cookie');
+  aPList = aPList.split(";");
+  for (var i=0;i<aPList.length;i++) {
+    aArg = aPList[i].split("=");
+    if (aArg[0] == 'ID')
+      this._sid = aArg[1];
+  }
+  this.oDbg.log("got sid: "+this._sid,2);
+
+  oCon = this;
+  this._interval= setInterval("oCon._checkQueue()",JSJaC_CheckQueueInterval);
+  this._inQto = setInterval("oCon._checkInQ();",JSJaC_CheckInQueueInterval);
+
+  /* wait for initial stream response to extract streamid needed
+   * for digest auth
+   */
+  this._getStreamID();
+}
+
+function JSJaCHPCGetStream() {
+
+  if (!this._req[0].r.responseXML || this._req[0].r.responseText == '') {
+    oCon = this;
+    this._timeout = setTimeout("oCon._sendEmpty()",1000);
+    return;
+  }
+
+  this.oDbg.log(this._req[0].r.responseText,4);
+
+  // extract stream id used for non-SASL authentication
+  if (this._req[0].r.responseText.match(/id=[\'\"]([^\'\"]+)[\'\"]/))
+    this.streamid = RegExp.$1;
+  this.oDbg.log("got streamid: "+this.streamid,2);
+
+  var doc;
+
+  try {
+    doc = XmlDocument.create("doc");
+    doc.loadXML(this._req[0].r.responseText+'</stream:stream>');
+    this._parseStreamFeatures(doc);
+  } catch(e) {
+    this.oDbg.log("loadXML: "+e.toString(),1);
+  }
+
+  if (this.register)
+    this._doInBandReg();
+  else 
+    this._doAuth();
+
+  this._connected = true;
+  this._process(this._timerval); // start polling
+}
+
+function JSJaCHPCReInitStream(to,cb,arg) {
+  oCon._sendRaw("<stream:stream 
xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' 
to='"+to+"' version='1.0'>",cb,arg);
+}
+
+function JSJaCHPCDisconnect() {
+  if (!this.connected())
+    return;
+
+  this._checkQueue();
+
+  clearInterval(this._interval);
+  clearInterval(this._inQto);
+
+  if (this._timeout)
+    clearTimeout(this._timeout); // remove timer
+
+  this._req[0] = this._setupRequest(false);
+       
+  if (JSJaC_HAVEKEYS)
+    this._req[0].r.send(this._sid+";"+this._keys.getKey()+",</stream:stream>");
+  else
+    this._req[0].r.send(this._sid+",</stream:stream>");
+  this.oDbg.log("Disconnected: "+this._req[0].r.responseText,2);
+  this._connected = false;
+  this._handleEvent('ondisconnect');
+}

Index: JSJaC.js
===================================================================
RCS file: JSJaC.js
diff -N JSJaC.js
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ JSJaC.js    24 Feb 2007 23:02:06 -0000      1.1
@@ -0,0 +1,24 @@
+// taken from script.aculo.us and modified to break it
+
+var JSJaC = {
+  Version: '0.6',
+  require: function(libraryName) {
+    // inserting via DOM fails in Safari 2.0, so brute force approach
+    document.write('<script type="text/javascript" 
src="'+libraryName+'"></script>');
+  },
+  load: function() {
+    var includes = 
['xmlextras','JSJaCPacket','crypt','json','qm_cookie','JSJaCConnection','JSJaCHttpPollingConnection','JSJaCHttpBindingConnection'];
+    var scripts = document.getElementsByTagName("script");
+    var path = './';
+    for (var i=0; i<scripts.length; i++) {
+      if (scripts.item(i).src && scripts.item(i).src.match(/JSJaC\.js$/)) {
+                               path = 
scripts.item(i).src.replace(/JSJaC.js$/,'');
+                               break;
+                       }
+               }
+    for (var i=0; i<includes.length; i++)
+      this.require(path+includes[i]+'.js');
+  }
+}
+
+JSJaC.load();

Index: JSJaCPacket.js
===================================================================
RCS file: JSJaCPacket.js
diff -N JSJaCPacket.js
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ JSJaCPacket.js      24 Feb 2007 23:02:06 -0000      1.1
@@ -0,0 +1,232 @@
+var JSJACPACKET_USE_XMLNS = true;
+
+function JSJaCPacket(name) {
+  this.name = name;
+
+  if (typeof(JSJACPACKET_USE_XMLNS) != 'undefined' && JSJACPACKET_USE_XMLNS)
+    this.doc = XmlDocument.create(name,'jabber:client');
+  else
+    this.doc = XmlDocument.create(name,'');
+
+  this.pType = function() { return this.name; };
+
+  this.getDoc = function() { return this.doc; };
+  this.getNode = function() { return this.getDoc().documentElement; };
+
+  this.setTo = function(to) {
+    if (!to || to == '')
+      this.getNode().removeAttribute('to');
+    else
+      this.getNode().setAttribute('to',to); 
+    return this; 
+  };
+  this.setFrom = function(from) {
+    if (!from || from == '')
+      this.getNode().removeAttribute('from');
+    else
+      this.getNode().setAttribute('from',from);
+    return this;
+  };
+  this.setID = function(id) { 
+    if (!id || id == '')
+      this.getNode().removeAttribute('id');
+    else
+      this.getNode().setAttribute('id',id); 
+    return this; 
+  };
+  this.setType = function(type) { 
+    if (!type || type == '')
+      this.getNode().removeAttribute('type');
+    else
+      this.getNode().setAttribute('type',type);
+    return this; 
+  };
+  this.setXMLLang = function(xmllang) {
+    if (!xmllang || xmllang == '')
+      this.getNode().removeAttribute('xml:lang');
+    else
+      this.getNode().setAttribute('xml:lang',xmllang);
+    return this;
+  };
+
+  this.getTo = function() { return this.getNode().getAttribute('to'); }
+  this.getFrom = function() { return this.getNode().getAttribute('from'); }
+  this.getID = function() { return this.getNode().getAttribute('id'); }
+  this.getType = function() { return this.getNode().getAttribute('type'); }
+  this.getXMLLang = function() { return 
this.getNode().getAttribute('xml:lang'); };
+  this.getXMLNS = function() { return this.getNode().namespaceURI; };
+
+  this.xml = function() { 
+    if (this.getDoc().xml)
+      return this.getDoc().xml;
+    var xml = (new XMLSerializer()).serializeToString(this.getNode()); // 
opera needs the node
+    if (typeof(xml) != 'undefined') 
+      return xml;
+    return (new XMLSerializer()).serializeToString(this.doc); // oldschool
+
+  };
+
+  this._childElVal = function(nodeName) {
+    var aNode = this._getChildNode(nodeName);
+    if (aNode && aNode.firstChild)
+      return aNode.firstChild.nodeValue;
+    return '';
+  }
+
+  this._getChildNode = function(nodeName) {
+    var children = this.getNode().childNodes;
+    for (var i=0; i<children.length; i++)
+      if (children.item(i).tagName == nodeName)
+        return children.item(i);
+    return null;
+  }
+
+  this._replaceNode = function(aNode) {
+    // copy attribs
+    for (var i=0; i<aNode.attributes.length; i++)
+      if (aNode.attributes.item(i).nodeName != 'xmlns')
+        
this.getNode().setAttribute(aNode.attributes.item(i).nodeName,aNode.attributes.item(i).nodeValue);
+
+    // copy children
+    for (var i=0; i<aNode.childNodes.length; i++)
+      if (this.getDoc().importNode)
+        
this.getNode().appendChild(this.getDoc().importNode(aNode.childNodes.item(i),true));
+      else
+        this.getNode().appendChild(aNode.childNodes.item(i).cloneNode(true));
+                               
+  };
+
+  this._setChildNode = function(nodeName, nodeValue) {
+    var aNode = this._getChildNode(nodeName);
+    var tNode = this.getDoc().createTextNode(nodeValue);
+    if (aNode)
+      try {
+        aNode.replaceChild(tNode,aNode.firstChild);
+      } catch (e) { }
+    else {
+      aNode = 
this.getNode().appendChild(this.getDoc().createElement(nodeName));
+      aNode.appendChild(tNode);
+    }
+    return aNode;
+  }
+
+  this.clone = function() { return JSJaCPWrapNode(this.getNode()); }
+} 
+
+function JSJaCPresence() {
+  this.base = JSJaCPacket;
+  this.base('presence');
+
+  this.setStatus = function(status) {
+    this._setChildNode("status", status);
+    return this; 
+  };
+  this.setShow = function(show) {
+    this._setChildNode("show",show);
+    return this; 
+  };
+  this.setPriority = function(prio) {
+    this._setChildNode("priority", prio);
+    return this; 
+  };
+  this.setPresence = function(show,status,prio) {
+    if (show)
+      this.setShow(show);
+    if (status)
+      this.setStatus(status);
+    if (prio)
+      this.setPriority(prio);
+    return this; 
+  };
+
+  this.getStatus = function() {        return this._childElVal('status');      
};
+  this.getShow = function() { return this._childElVal('show'); };
+  this.getPriority = function() { return this._childElVal('priority'); };
+}
+
+function JSJaCIQ() {
+  this.base = JSJaCPacket;
+  this.base('iq');
+
+  this.setIQ = function(to,from,type,id) {
+    if (to)
+      this.setTo(to);
+    if (type)
+      this.setType(type);
+    if (from)
+      this.setFrom(from);
+    if (id)
+      this.setID(id);
+    return this; 
+  };
+  this.setQuery = function(xmlns) {
+    var query;
+    try {
+      query = this.getDoc().createElementNS(xmlns,'query');
+    } catch (e) {
+      // fallback
+      query = this.getDoc().createElement('query');
+    }
+    if (query && query.getAttribute('xmlns') != xmlns) // fix opera 8.5x
+      query.setAttribute('xmlns',xmlns);
+    this.getNode().appendChild(query);
+    return query;
+  };
+
+  this.getQuery = function() {
+    return this.getNode().getElementsByTagName('query').item(0);
+  };
+  this.getQueryXMLNS = function() {
+    if (this.getQuery())
+      return this.getQuery().namespaceURI;
+    else
+      return null;
+  };
+}
+
+function JSJaCMessage() {
+  this.base = JSJaCPacket;
+  this.base('message');
+
+  this.setBody = function(body) {
+    this._setChildNode("body",body);
+    return this; 
+  };
+  this.setSubject = function(subject) {
+    this._setChildNode("subject",subject);
+    return this; 
+  };
+  this.setThread = function(thread) {
+    this._setChildNode("thread", thread);
+    return this; 
+  };
+  this.getThread = function() { return this._childElVal('thread'); };
+  this.getBody = function() { return this._childElVal('body'); };
+  this.getSubject = function() { return this._childElVal('subject') };
+}
+
+/* ***
+ * (static) JSJaCPWrapNode
+ * transforms node to JSJaC internal representation (JSJaCPacket type)
+ */
+function JSJaCPWrapNode(node) {
+  var aNode;
+  switch (node.nodeName.toLowerCase()) {
+  case 'presence':
+    aNode = new JSJaCPresence();
+    break;
+  case 'message':
+    aNode = new JSJaCMessage();
+    break;
+  case 'iq':
+    aNode = new JSJaCIQ();
+    break;
+  default : // unknown
+    return node;
+  }
+
+  aNode._replaceNode(node);
+
+  return aNode;
+}
+

Index: json.js
===================================================================
RCS file: json.js
diff -N json.js
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ json.js     24 Feb 2007 23:02:06 -0000      1.1
@@ -0,0 +1,121 @@
+/*
+  json.js
+  2006-04-28
+
+  This file adds these methods to JavaScript:
+
+  object.toJSONString()
+
+  This method produces a JSON text from an object. The
+  object must not contain any cyclical references.
+
+  array.toJSONString()
+
+  This method produces a JSON text from an array. The
+  array must not contain any cyclical references.
+
+  string.parseJSON()
+
+  This method parses a JSON text to produce an object or
+  array. It will return false if there is an error.
+*/
+function JSON() {}
+JSON.toString = function (obj) {
+  var m = {
+    '\b': '\\b',
+    '\t': '\\t',
+    '\n': '\\n',
+    '\f': '\\f',
+    '\r': '\\r',
+    '"' : '\\"',
+    '\\': '\\\\'
+  },
+  s = {
+    array: function (x) {
+      var a = ['['], b, f, i, l = x.length, v;
+      for (i = 0; i < l; i += 1) {
+        v = x[i];
+        f = s[typeof v];
+        if (f) {
+          v = f(v);
+          if (typeof v == 'string') {
+            if (b) {
+              a[a.length] = ',';
+            }
+            a[a.length] = v;
+            b = true;
+          }
+        }
+      }
+      a[a.length] = ']';
+      return a.join('');
+    },
+    'boolean': function (x) {
+      return String(x);
+    },
+    'null': function (x) {
+      return "null";
+    },
+    number: function (x) {
+      return isFinite(x) ? String(x) : 'null';
+    },
+    object: function (x) {
+      if (x) {
+        if (x instanceof Array) {
+          return s.array(x);
+        }
+        var a = ['{'], b, f, i, v;
+        for (i in x) {
+          v = x[i];
+          f = s[typeof v];
+          if (f) {
+            v = f(v);
+            if (typeof v == 'string') {
+              if (b) {
+                a[a.length] = ',';
+              }
+              a.push(s.string(i), ':', v);
+              b = true;
+            }
+          }
+        }
+        a[a.length] = '}';
+        return a.join('');
+      }
+      return 'null';
+    },
+    string: function (x) {
+      if (/["\\\x00-\x1f]/.test(x)) {
+                    x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) {
+          var c = m[b];
+          if (c) {
+            return c;
+          }
+          c = b.charCodeAt();
+          return '\\u00' +
+          Math.floor(c / 16).toString(16) +
+          (c % 16).toString(16);
+        });
+  }
+  return '"' + x + '"';
+}
+  };
+
+switch (typeof(obj)) {
+ case 'object':
+   return s.object(obj);
+ case 'array':
+   return s.array(obj);
+    
+ }
+};
+
+JSON.parse = function (str) {
+  try {
+    return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
+                                                       
str.replace(/"(\\.|[^"\\])*"/g, ''))) &&
+            eval('(' + str + ')');
+    } catch (e) {
+        return false;
+    }
+};

Index: qm_cookie.js
===================================================================
RCS file: qm_cookie.js
diff -N qm_cookie.js
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ qm_cookie.js        24 Feb 2007 23:02:06 -0000      1.1
@@ -0,0 +1,32 @@
+// taken from http://www.quirksmode.org/js/cookies.html
+// modified slightly
+
+function createCookie(name,value,secs)
+{
+  if (secs)
+    {
+      var date = new Date();
+      date.setTime(date.getTime()+(secs*1000));
+      var expires = "; expires="+date.toGMTString();
+    }
+  else var expires = "";
+  document.cookie = name+"="+value+expires+"; path=/";
+}
+
+function readCookie(name)
+{
+  var nameEQ = name + "=";
+  var ca = document.cookie.split(';');
+  for(var i=0;i < ca.length;i++)
+    {
+      var c = ca[i];
+      while (c.charAt(0)==' ') c = c.substring(1,c.length);
+      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
+    }
+  return null;
+}
+
+function eraseCookie(name)
+{
+  createCookie(name,"",-1);
+}

Index: README
===================================================================
RCS file: README
diff -N README
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ README      24 Feb 2007 23:02:06 -0000      1.1
@@ -0,0 +1,66 @@
+JSJaC - JavaScript Jabber Client Library
+========================================
+
+JSJaC is a jabber client library written in JavaScript to ease
+implementation of web based jabber clients. For communication with a
+jabber server it needs to support either [1]HTTP Polling or [2]HTTP
+Binding. JSJaC has an object oriented interface which should be quite
+easy to use. Communication is done by using the HTTPRequest
+object also refered to as AJAX technology. Your browser must support 
+this.
+
+License
+=======
+
+JSJaC is licensed under the terms of the GNU Lesser General Public 
+License (LGPL). Please refer to the file named 'COPYING' that came with 
+this distribution for details.
+
+Hints on Usage
+==============
+
+Due to security restrictions you will have to proxy requests like
+mod_proxy and mod_rewrite for apache web servers can do and add a
+RewriteRule for the domain which serves your web application so that
+request on a certain base address (which can be chosen by yourself)
+are redirect by use of apache's built in proxy module to the http base
+address of the HTTP Polling or HTTP Binding service. E.g.:
+
+%<---
+<VirtualHost *>
+  Servername jabber.mydomain.com
+  DocumentRoot /home/jabber/jwchat/htdocs
+  AddDefaultCharset UTF-8
+  RewriteEngine On
+  RewriteRule ^/http-poll/ http://jabber.mydomain.com:5280/http-poll/ [P]
+</VirtualHost>
+%<---
+
+For an example on how to use this library within your web application
+please have to look at 'examples/simpleclient.html'.
+
+Note: JSJaCConnection supports use of [3]Debugger which is available 
separately.
+
+Supported Browsers and Platforms
+================================
+
+Windows
+-------
+* Internet Explorer v5.0 or newer
+* Mozilla/Firefox and any other Gecko based browsers
+* Netscape v6.0 or newer
+
+Linux/UNI*X
+-----------
+* Mozilla/Firefox and any other Gecko based browsers
+* Netscape v6.0 or newer
+
+Macintosh
+---------
+* Mozilla/Firefox and any other Gecko based browsers
+* Safari (in development, please help out by submitting bug reports)
+
+
+[1] http://www.jabber.org/jeps/jep-0025.html
+[2] http://www.jabber.org/jeps/jep-0124.html
+[3] http://zeank.in-berlin.de/javascript-debug-logger/
\ No newline at end of file

Index: semantic.cache
===================================================================
RCS file: semantic.cache
diff -N semantic.cache
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ semantic.cache      24 Feb 2007 23:02:06 -0000      1.1
@@ -0,0 +1,14 @@
+;; Object semantic.cache
+;; SEMANTICDB Tags save file
+(semanticdb-project-database "semantic.cache"
+  :file "semantic.cache"
+  :tables (list 
+   (semanticdb-table "JSJaCHttpBindingConnection.js"
+    :file "JSJaCHttpBindingConnection.js"
+    :pointmax 10327
+    :major-mode 'c-mode
+    :tokens '((";" nil [26 27]) (";" nil [55 56]))
+    :unmatched-syntax 'nil
+    )
+   )
+  )

Index: xmlextras.js
===================================================================
RCS file: xmlextras.js
diff -N xmlextras.js
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ xmlextras.js        24 Feb 2007 23:02:06 -0000      1.1
@@ -0,0 +1,180 @@
+/* *** *** *** *** *** *** *** *** ***
+ * this code is taken from http://webfx.eae.net/dhtml/xmlextras/xmlextras.html 
+ * *** *** *** *** *** *** *** *** ***
+ */
+
+//<script>
+//////////////////
+// Helper Stuff //
+//////////////////
+
+// used to find the Automation server name
+function getDomDocumentPrefix() {
+  if (getDomDocumentPrefix.prefix)
+    return getDomDocumentPrefix.prefix;
+       
+  var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
+  var o;
+  for (var i = 0; i < prefixes.length; i++) {
+    try {
+      // try to create the objects
+      o = new ActiveXObject(prefixes[i] + ".DomDocument");
+      return getDomDocumentPrefix.prefix = prefixes[i];
+    }
+    catch (ex) {};
+  }
+  
+  throw new Error("Could not find an installed XML parser");
+}
+
+function getXmlHttpPrefix() {
+  if (getXmlHttpPrefix.prefix)
+    return getXmlHttpPrefix.prefix;
+  
+  var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
+  var o;
+  for (var i = 0; i < prefixes.length; i++) {
+    try {
+      // try to create the objects
+      o = new ActiveXObject(prefixes[i] + ".XmlHttp");
+      return getXmlHttpPrefix.prefix = prefixes[i];
+    }
+    catch (ex) {};
+  }
+  
+  throw new Error("Could not find an installed XML parser");
+}
+
+//////////////////////////
+// Start the Real stuff //
+//////////////////////////
+
+
+// XmlHttp factory
+function XmlHttp() {}
+
+XmlHttp.create = function () {
+  try {
+    if (window.XMLHttpRequest) {
+      var req = new XMLHttpRequest();
+      
+      // some versions of Moz do not support the readyState property
+      // and the onreadystate event so we patch it!
+      if (req.readyState == null) {
+       req.readyState = 1;
+       req.addEventListener("load", function () {
+                              req.readyState = 4;
+                              if (typeof req.onreadystatechange == "function")
+                                req.onreadystatechange();
+                            }, false);
+      }
+      
+      return req;
+    }
+    if (window.ActiveXObject) {
+      return new ActiveXObject(getXmlHttpPrefix() + ".XmlHttp");
+    }
+  }
+  catch (ex) {}
+  // fell through
+  throw new Error("Your browser does not support XmlHttp objects");
+};
+
+// XmlDocument factory
+function XmlDocument() {}
+
+XmlDocument.create = function (name,ns) {
+  name = name || 'foo';
+  ns = ns || '';
+  try {
+    var doc;
+    // DOM2
+    if (document.implementation && document.implementation.createDocument) {
+      doc = document.implementation.createDocument("", "", null);
+      // some versions of Moz do not support the readyState property
+      // and the onreadystate event so we patch it!
+      if (doc.readyState == null) {
+       doc.readyState = 1;
+       doc.addEventListener("load", function () {
+                              doc.readyState = 4;
+                              if (typeof doc.onreadystatechange == "function")
+                                doc.onreadystatechange();
+                            }, false);
+      }
+    }
+    if (window.ActiveXObject)
+      doc = new ActiveXObject(getDomDocumentPrefix() + ".DomDocument");
+    
+    try { 
+      if (ns != '')
+       doc.appendChild(doc.createElement(name)).setAttribute('xmlns',ns);
+      else
+       doc.appendChild(doc.createElement(name));
+    } catch (dex) { 
+      doc = document.implementation.createDocument(ns,name,null);
+      
+      if (doc.documentElement == null)
+       doc.appendChild(doc.createElement(name));
+      
+      if (ns != '' && 
+         doc.documentElement.getAttribute('xmlns') != ns) // fixes buggy opera 
8.5x
+       doc.documentElement.setAttribute('xmlns',ns);
+    }
+    
+    return doc;
+  }
+  catch (ex) { }
+  throw new Error("Your browser does not support XmlDocument objects");
+};
+
+// Create the loadXML method 
+if (typeof(Document) != 'undefined' && window.DOMParser) {
+
+  // XMLDocument did not extend the Document interface in some versions
+  // of Mozilla. Extend both!
+  //XMLDocument.prototype.loadXML = 
+  Document.prototype.loadXML = function (s) {
+               
+    // parse the string to a new doc   
+    var doc2 = (new DOMParser()).parseFromString(s, "text/xml");
+               
+    // remove all initial children
+    while (this.hasChildNodes())
+      this.removeChild(this.lastChild);
+                       
+    // insert and import nodes
+    for (var i = 0; i < doc2.childNodes.length; i++) {
+      this.appendChild(this.importNode(doc2.childNodes[i], true));
+    }
+  };
+ }
+
+// Create xml getter for Mozilla
+/* IMPORTANT NOTE
+ * Usage of this .xml getter method is deprecated 
+ */
+if (window.XMLSerializer &&
+    window.Node && Node.prototype && Node.prototype.__defineGetter__) {
+       
+  /*
+   * xml getter
+   *
+   * This serializes the DOM tree to an XML String
+   *
+   * Usage: var sXml = oNode.xml
+   *
+   */
+  // XMLDocument did not extend the Document interface in some versions
+  // of Mozilla. Extend both!
+  XMLDocument.prototype.__defineGetter__("xml", function () {
+                                           return (new 
XMLSerializer()).serializeToString(this);
+                                         });
+  Document.prototype.__defineGetter__("xml", function () {
+                                        return (new 
XMLSerializer()).serializeToString(this);
+                                      });
+       
+  /* doesn't work correctly in mozi, does it?  */
+  Node.prototype.__defineGetter__("xml", function () {
+                                    return (new 
XMLSerializer()).serializeToString(this);
+                                  });
+ }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]