pax_global_header00006660000000000000000000000064113757717260014532gustar00rootroot0000000000000052 comment=203df5142e76ea9f2276262c655741905e0beb78 strophejs-1.0.1.dfsg/000077500000000000000000000000001137577172600144745ustar00rootroot00000000000000strophejs-1.0.1.dfsg/LICENSE.txt000066400000000000000000000020471137577172600163220ustar00rootroot00000000000000Copyright (c) 2006-2009 Collecta, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. strophejs-1.0.1.dfsg/README.txt000066400000000000000000000012761137577172600162000ustar00rootroot00000000000000Strophe.js is a JavaScript library for speaking XMPP via BOSH (XEP 124 and 206). It is licensed under the MIT license, except for the files base64.js and md5.js, which are licensed as public domain and BSD (see these files for details). It has been tested on Firefox 1.5, 2.x, and 3.x, IE 6, 7, and 8, Safari, Mobile Safari, Chrome, and it should also work on the mobile Opera browser as well as the desktop Opera browser. The homepage for Strophe is http://code.stanziq.com/strophe. The book Professional XMPP Programming with JavaScript and jQuery is also available, which covers Strophe in detail in the context of web applications. You can find more information at http://professionalxmpp.com. strophejs-1.0.1.dfsg/contrib/000077500000000000000000000000001137577172600161345ustar00rootroot00000000000000strophejs-1.0.1.dfsg/contrib/discojs/000077500000000000000000000000001137577172600175725ustar00rootroot00000000000000strophejs-1.0.1.dfsg/contrib/discojs/README.txt000066400000000000000000000024421137577172600212720ustar00rootroot00000000000000Disco Dancing with XMPP There are many things one can do via XMPP. The list is endlist. But one thing that some forget about is discovering services a XMPP entity or server provides. In most cases a human or user does not care about this information and should not care. But you may have a website or web application that needs this information in order to decide what options to show to your users. You can do this very easily with JQuery, Strophe, and Punjab. We start with Punjab or a BOSH connection manager. This is needed so we can connect to a XMPP server. First, lets download punjab. svn co https://code.stanziq.com/svn/punjab/trunk punjab After we have punjab go into the directory and install punjab. cd punjab python setup.py install Then create a .tac file to configure Punjab. See punjab.tac Next, we will need Strophe. Lets download thelatest version from svn too. cd /directory/where/you/configured/punjab/html svn co https://code.stanziq.com/svn/strophe/trunk/strophejs In your html directory you will then begin to create your disco browser. Version 1 we take the basic example and modify it to do disco. Version 2 we add anonymous login Version 3 we make it pretty Version 4 we add handlers for different services strophejs-1.0.1.dfsg/contrib/discojs/css/000077500000000000000000000000001137577172600203625ustar00rootroot00000000000000strophejs-1.0.1.dfsg/contrib/discojs/css/disco.css000066400000000000000000000002301137577172600221700ustar00rootroot00000000000000#login .leftinput { margin-bottom: .5em; } #login input { margin-bottom: 10px; } #log { width: 100%; height: 200px; overflow: auto; } strophejs-1.0.1.dfsg/contrib/discojs/index.html000066400000000000000000000027201137577172600215700ustar00rootroot00000000000000 XMPP Disco Dancing



Status Log :
strophejs-1.0.1.dfsg/contrib/discojs/punjab.tac000066400000000000000000000010441137577172600215410ustar00rootroot00000000000000# punjab tac file from twisted.web import server, resource, static from twisted.application import service, internet from punjab.httpb import Httpb, HttpbService root = static.File("./") # This needs to be the directory # where you will have your html # and javascript. b = resource.IResource(HttpbService(1)) # turn on debug with 1 root.putChild('bosh', b) site = server.Site(root) application = service.Application("punjab") internet.TCPServer(5280, site).setServiceParent(application) strophejs-1.0.1.dfsg/contrib/discojs/scripts/000077500000000000000000000000001137577172600212615ustar00rootroot00000000000000strophejs-1.0.1.dfsg/contrib/discojs/scripts/basic.js000066400000000000000000000040331137577172600227000ustar00rootroot00000000000000var BOSH_SERVICE = 'http://localhost:5280/bosh'; var connection = null; var browser = null; var show_log = true; function log(msg) { $('#log').append('
').append(document.createTextNode(msg)); } function rawInput(data) { log('RECV: ' + data); } function rawOutput(data) { log('SENT: ' + data); } function onConnect(status) { if (status == Strophe.Status.CONNECTING) { log('Strophe is connecting.'); } else if (status == Strophe.Status.CONNFAIL) { log('Strophe failed to connect.'); showConnect(); } else if (status == Strophe.Status.DISCONNECTING) { log('Strophe is disconnecting.'); } else if (status == Strophe.Status.DISCONNECTED) { log('Strophe is disconnected.'); showConnect(); } else if (status == Strophe.Status.CONNECTED) { log('Strophe is connected.'); // Start up disco browser browser.showBrowser(); } } function showConnect() { var jid = $('#jid'); var pass = $('#pass'); var button = $('#connect').get(0); browser.closeBrowser(); $('label').show(); jid.show(); pass.show(); $('#anon').show(); button.value = 'connect'; return false; } function showDisconnect() { var jid = $('#jid'); var pass = $('#pass'); var button = $('#connect').get(0); button.value = 'disconnect'; pass.hide(); jid.hide(); $('label').hide(); $('#anon').hide(); return false; } $(document).ready(function () { connection = new Strophe.Connection(BOSH_SERVICE); connection.rawInput = rawInput; connection.rawOutput = rawOutput; browser = new Disco(); $("#log_container").bind('click', function () { $("#log").toggle(); } ); $('#cred').bind('submit', function () { var button = $('#connect').get(0); var jid = $('#jid'); var pass = $('#pass'); if (button.value == 'connect') { showDisconnect(); connection.connect(jid.get(0).value, pass.get(0).value, onConnect); } else { connection.disconnect(); showConnect(); } return false; }); });strophejs-1.0.1.dfsg/contrib/discojs/scripts/disco.js000066400000000000000000000026421137577172600227240ustar00rootroot00000000000000 var NS_DISCO_INFO = 'http://jabber.org/protocol/disco#info'; var NS_DISCO_ITEM = 'http://jabber.org/protocol/disco#items'; // Disco stuff Disco = function () { // Class that does nothing }; Disco.prototype = { showBrowser: function() { // Browser Display var disco = $('#disco'); var jid = $('#jid'); var server = connection.jid.split('@')[1]; // display input box disco.append("
Server :
"); // add handler for search form $("#browse").bind('submit', function () { this.startBrowse($("#server").get(0).value); return false; }); this.startBrowse(server); }, closeBrowser: function() { var disco = $('#disco'); disco.empty(); }, startBrowse: function(server) { // build iq request var id = 'startBrowse'; var discoiq = $iq({'from':connection.jid+"/"+connection.resource, 'to':server, 'id':id, 'type':'get'} ) .c('query', {'xmlns': NS_DISCO_INFO}); connection.addHandler(this._cbBrowse, null, 'iq', 'result', id); connection.send(discoiq.tree()); }, _cbBrowse: function(e) { var elem = $(e); // make this Element a JQuery Element alert(e); return false; // return false to remove the handler }, }; strophejs-1.0.1.dfsg/doc/000077500000000000000000000000001137577172600152415ustar00rootroot00000000000000strophejs-1.0.1.dfsg/doc/files/000077500000000000000000000000001137577172600163435ustar00rootroot00000000000000strophejs-1.0.1.dfsg/doc/files/core-js.html000066400000000000000000003530161137577172600206030ustar00rootroot00000000000000 strophe.js

strophe.js

A JavaScript library for XMPP BOSH.

This is the JavaScript version of the Strophe library.  Since JavaScript has no facilities for persistent TCP connections, this library uses Bidirectional-streams Over Synchronous HTTP (BOSH) to emulate a persistent, stateful, two-way connection to an XMPP server.  More information on BOSH can be found in XEP 124.

Summary
strophe.jsA JavaScript library for XMPP BOSH.
Functions
$buildCreate a Strophe.Builder.
$msgCreate a Strophe.Builder with a <message/> element as the root.
$iqCreate a Strophe.Builder with an <iq/> element as the root.
$presCreate a Strophe.Builder with a <presence/> element as the root.
StropheAn object container for all Strophe library functions.
Constants
VERSIONThe version of the Strophe library.
XMPP Namespace ConstantsCommon namespace constants from the XMPP RFCs and XEPs.
Functions
addNamespaceThis function is used to extend the current namespaces in Strophe.NS.
Constants
Connection Status ConstantsConnection status constants for use by the connection handler callback.
Log Level ConstantsLogging level indicators.
Functions
forEachChildMap a function over some or all child elements of a given element.
isTagEqualCompare an element’s tag name with a string.
xmlElementCreate an XML DOM element.
xmlescapeExcapes invalid xml characters.
xmlTextNodeCreates an XML DOM text node.
getTextGet the concatenation of all text children of an element.
copyElementCopy an XML DOM element.
escapeNodeEscape the node part (also called local part) of a JID.
unescapeNodeUnescape a node part (also called local part) of a JID.
getNodeFromJidGet the node portion of a JID String.
getDomainFromJidGet the domain portion of a JID String.
getResourceFromJidGet the resource portion of a JID String.
getBareJidFromJidGet the bare JID from a JID String.
logUser overrideable logging function.
debugLog a message at the Strophe.LogLevel.DEBUG level.
infoLog a message at the Strophe.LogLevel.INFO level.
warnLog a message at the Strophe.LogLevel.WARN level.
errorLog a message at the Strophe.LogLevel.ERROR level.
fatalLog a message at the Strophe.LogLevel.FATAL level.
serializeRender a DOM element and all descendants to a String.
addConnectionPluginExtends the Strophe.Connection object with the given plugin.
Strophe.BuilderXML DOM builder.
Functions
Strophe.BuilderCreate a Strophe.Builder object.
treeReturn the DOM tree.
toStringSerialize the DOM tree to a String.
upMake the current parent element the new current element.
attrsAdd or modify attributes of the current element.
cAdd a child to the current element and make it the new current element.
cnodeAdd a child to the current element and make it the new current element.
tAdd a child text element.
Strophe.ConnectionXMPP Connection manager.
Functions
Strophe.ConnectionCreate and initialize a Strophe.Connection object.
resetReset the connection.
pausePause the request manager.
resumeResume the request manager.
getUniqueIdGenerate a unique ID for use in <iq/> elements.
connectStarts the connection process.
attachAttach to an already created and authenticated BOSH session.
xmlInputUser overrideable function that receives XML data coming into the connection.
xmlOutputUser overrideable function that receives XML data sent to the connection.
rawInputUser overrideable function that receives raw data coming into the connection.
rawOutputUser overrideable function that receives raw data sent to the connection.
sendSend a stanza.
flushImmediately send any pending outgoing data.
sendIQHelper function to send IQ stanzas.
addTimedHandlerAdd a timed handler to the connection.
deleteTimedHandlerDelete a timed handler for a connection.
addHandlerAdd a stanza handler for the connection.
deleteHandlerDelete a stanza handler for a connection.
disconnectStart the graceful disconnection process.

Functions

$build

function $build(name,
attrs)

Create a Strophe.Builder.  This is an alias for ‘new Strophe.Builder(name, attrs)’.

Parameters

(String) nameThe root element name.
(Object) attrsThe attributes for the root element in object notation.

Returns

A new Strophe.Builder object.

$msg

function $msg(attrs)

Create a Strophe.Builder with a <message/> element as the root.

Parmaeters

(Object) attrsThe <message/> element attributes in object notation.

Returns

A new Strophe.Builder object.

$iq

function $iq(attrs)

Create a Strophe.Builder with an <iq/> element as the root.

Parameters

(Object) attrsThe <iq/> element attributes in object notation.

Returns

A new Strophe.Builder object.

$pres

function $pres(attrs)

Create a Strophe.Builder with a <presence/> element as the root.

Parameters

(Object) attrsThe <presence/> element attributes in object notation.

Returns

A new Strophe.Builder object.

Strophe

An object container for all Strophe library functions.

This class is just a container for all the objects and constants used in the library.  It is not meant to be instantiated, but to provide a namespace for library objects, constants, and functions.

Summary
Constants
VERSIONThe version of the Strophe library.
XMPP Namespace ConstantsCommon namespace constants from the XMPP RFCs and XEPs.
Functions
addNamespaceThis function is used to extend the current namespaces in Strophe.NS.
Constants
Connection Status ConstantsConnection status constants for use by the connection handler callback.
Log Level ConstantsLogging level indicators.
Functions
forEachChildMap a function over some or all child elements of a given element.
isTagEqualCompare an element’s tag name with a string.
xmlElementCreate an XML DOM element.
xmlescapeExcapes invalid xml characters.
xmlTextNodeCreates an XML DOM text node.
getTextGet the concatenation of all text children of an element.
copyElementCopy an XML DOM element.
escapeNodeEscape the node part (also called local part) of a JID.
unescapeNodeUnescape a node part (also called local part) of a JID.
getNodeFromJidGet the node portion of a JID String.
getDomainFromJidGet the domain portion of a JID String.
getResourceFromJidGet the resource portion of a JID String.
getBareJidFromJidGet the bare JID from a JID String.
logUser overrideable logging function.
debugLog a message at the Strophe.LogLevel.DEBUG level.
infoLog a message at the Strophe.LogLevel.INFO level.
warnLog a message at the Strophe.LogLevel.WARN level.
errorLog a message at the Strophe.LogLevel.ERROR level.
fatalLog a message at the Strophe.LogLevel.FATAL level.
serializeRender a DOM element and all descendants to a String.
addConnectionPluginExtends the Strophe.Connection object with the given plugin.

Constants

VERSION

The version of the Strophe library.  Unreleased builds will have a version of head-HASH where HASH is a partial revision.

XMPP Namespace Constants

Common namespace constants from the XMPP RFCs and XEPs.

NS.HTTPBINDHTTP BIND namespace from XEP 124.
NS.BOSHBOSH namespace from XEP 206.
NS.CLIENTMain XMPP client namespace.
NS.AUTHLegacy authentication namespace.
NS.ROSTERRoster operations namespace.
NS.PROFILEProfile namespace.
NS.DISCO_INFOService discovery info namespace from XEP 30.
NS.DISCO_ITEMSService discovery items namespace from XEP 30.
NS.MUCMulti-User Chat namespace from XEP 45.
NS.SASLXMPP SASL namespace from RFC 3920.
NS.STREAMXMPP Streams namespace from RFC 3920.
NS.BINDXMPP Binding namespace from RFC 3920.
NS.SESSIONXMPP Session namespace from RFC 3920.

Functions

addNamespace

addNamespace: function (name,
value)

This function is used to extend the current namespaces in Strophe.NS.  It takes a key and a value with the key being the name of the new namespace, with its actual value.  For example: Strophe.addNamespace(‘PUBSUB’, “http://jabber.org/protocol/pubsub”);

Parameters

(String) nameThe name under which the namespace will be referenced under Strophe.NS
(String) valueThe actual namespace.

Constants

Connection Status Constants

Connection status constants for use by the connection handler callback.

Status.ERRORAn error has occurred
Status.CONNECTINGThe connection is currently being made
Status.CONNFAILThe connection attempt failed
Status.AUTHENTICATINGThe connection is authenticating
Status.AUTHFAILThe authentication attempt failed
Status.CONNECTEDThe connection has succeeded
Status.DISCONNECTEDThe connection has been terminated
Status.DISCONNECTINGThe connection is currently being terminated
Status.ATTACHEDThe connection has been attached

Log Level Constants

Logging level indicators.

LogLevel.DEBUGDebug output
LogLevel.INFOInformational output
LogLevel.WARNWarnings
LogLevel.ERRORErrors
LogLevel.FATALFatal errors

Functions

forEachChild

forEachChild: function (elem,
elemName,
func)

Map a function over some or all child elements of a given element.

This is a small convenience function for mapping a function over some or all of the children of an element.  If elemName is null, all children will be passed to the function, otherwise only children whose tag names match elemName will be passed.

Parameters

(XMLElement) elemThe element to operate on.
(String) elemNameThe child element tag name filter.
(Function) funcThe function to apply to each child.  This function should take a single argument, a DOM element.

isTagEqual

isTagEqual: function (el,
name)

Compare an element’s tag name with a string.

This function is case insensitive.

Parameters

(XMLElement) elA DOM element.
(String) nameThe element name.

Returns

true if the element’s tag name matches el, and false otherwise.

xmlElement

xmlElement: function (name)

Create an XML DOM element.

This function creates an XML DOM element correctly across all implementations.  Specifically the Microsoft implementation of document.createElement makes DOM elements with 43+ default attributes unless elements are created with the ActiveX object Microsoft.XMLDOM.

Most DOMs force element names to lowercase, so we use the _realname attribute on the created element to store the case sensitive name.  This is required to generate proper XML for things like vCard avatars (XEP 153).  This attribute is stripped out before being sent over the wire or serialized, but you may notice it during debugging.

Parameters

(String) nameThe name for the element.
(Array) attrsAn optional array of key/value pairs to use as element attributes in the following format [[‘key1’, ‘value1’], [‘key2’, ‘value2’]]
(String) textThe text child data for the element.

Returns

A new XML DOM element.

xmlescape

xmlescape: function(text)

Excapes invalid xml characters.

Parameters

(String) texttext to escape.

Returns

Escaped text.

xmlTextNode

xmlTextNode: function (text)

Creates an XML DOM text node.

Provides a cross implementation version of document.createTextNode.

Parameters

(String) textThe content of the text node.

Returns

A new XML DOM text node.

getText

getText: function (elem)

Get the concatenation of all text children of an element.

Parameters

(XMLElement) elemA DOM element.

Returns

A String with the concatenated text of all text element children.

copyElement

copyElement: function (elem)

Copy an XML DOM element.

This function copies a DOM element and all its descendants and returns the new copy.

Parameters

(XMLElement) elemA DOM element.

Returns

A new, copied DOM element tree.

escapeNode

escapeNode: function (node)

Escape the node part (also called local part) of a JID.

Parameters

(String) nodeA node (or local part).

Returns

An escaped node (or local part).

unescapeNode

unescapeNode: function (node)

Unescape a node part (also called local part) of a JID.

Parameters

(String) nodeA node (or local part).

Returns

An unescaped node (or local part).

getNodeFromJid

getNodeFromJid: function (jid)

Get the node portion of a JID String.

Parameters

(String) jidA JID.

Returns

A String containing the node.

getDomainFromJid

getDomainFromJid: function (jid)

Get the domain portion of a JID String.

Parameters

(String) jidA JID.

Returns

A String containing the domain.

getResourceFromJid

getResourceFromJid: function (jid)

Get the resource portion of a JID String.

Parameters

(String) jidA JID.

Returns

A String containing the resource.

getBareJidFromJid

getBareJidFromJid: function (jid)

Get the bare JID from a JID String.

Parameters

(String) jidA JID.

Returns

A String containing the bare JID.

log

log: function (level,
msg)

User overrideable logging function.

This function is called whenever the Strophe library calls any of the logging functions.  The default implementation of this function does nothing.  If client code wishes to handle the logging messages, it should override this with

Strophe.log = function (level, msg) {
  (user code here)
};

Please note that data sent and received over the wire is logged via Strophe.Connection.rawInput() and Strophe.Connection.rawOutput().

The different levels and their meanings are

DEBUGMessages useful for debugging purposes.
INFOInformational messages.  This is mostly information like ‘disconnect was called’ or ‘SASL auth succeeded’.
WARNWarnings about potential problems.  This is mostly used to report transient connection errors like request timeouts.
ERRORSome error occurred.
FATALA non-recoverable fatal error occurred.

Parameters

(Integer) levelThe log level of the log message.  This will be one of the values in Strophe.LogLevel.
(String) msgThe log message.

debug

debug: function(msg)

Log a message at the Strophe.LogLevel.DEBUG level.

Parameters

(String) msgThe log message.

info

info: function (msg)

Log a message at the Strophe.LogLevel.INFO level.

Parameters

(String) msgThe log message.

warn

warn: function (msg)

Log a message at the Strophe.LogLevel.WARN level.

Parameters

(String) msgThe log message.

error

error: function (msg)

Log a message at the Strophe.LogLevel.ERROR level.

Parameters

(String) msgThe log message.

fatal

fatal: function (msg)

Log a message at the Strophe.LogLevel.FATAL level.

Parameters

(String) msgThe log message.

serialize

serialize: function (elem)

Render a DOM element and all descendants to a String.

Parameters

(XMLElement) elemA DOM element.

Returns

The serialized element tree as a String.

addConnectionPlugin

addConnectionPlugin: function (name,
ptype)

Extends the Strophe.Connection object with the given plugin.

Paramaters

(String) nameThe name of the extension.
(Object) ptypeThe plugin’s prototype.

Strophe.Builder

XML DOM builder.

This object provides an interface similar to JQuery but for building DOM element easily and rapidly.  All the functions except for toString() and tree() return the object, so calls can be chained.  Here’s an example using the $iq() builder helper.

$iq({to: 'you': from: 'me': type: 'get', id: '1'})
    .c('query', {xmlns: 'strophe:example'})
    .c('example')
    .toString()

The above generates this XML fragment

<iq to='you' from='me' type='get' id='1'>
  <query xmlns='strophe:example'>
    <example/>
  </query>
</iq>

The corresponding DOM manipulations to get a similar fragment would be a lot more tedious and probably involve several helper variables.

Since adding children makes new operations operate on the child, up() is provided to traverse up the tree.  To add two children, do

builder.c('child1', ...).up().c('child2', ...)

The next operation on the Builder will be relative to the second child.

Summary
Functions
Strophe.BuilderCreate a Strophe.Builder object.
treeReturn the DOM tree.
toStringSerialize the DOM tree to a String.
upMake the current parent element the new current element.
attrsAdd or modify attributes of the current element.
cAdd a child to the current element and make it the new current element.
cnodeAdd a child to the current element and make it the new current element.
tAdd a child text element.

Functions

Strophe.Builder

Strophe.Builder = function (name,
attrs)

Create a Strophe.Builder object.

The attributes should be passed in object notation.  For example

var b = new Builder('message', {to: 'you', from: 'me'});

or

var b = new Builder('messsage', {'xml:lang': 'en'});

Parameters

(String) nameThe name of the root element.
(Object) attrsThe attributes for the root element in object notation.

Returns

A new Strophe.Builder.

tree

tree: function ()

Return the DOM tree.

This function returns the current DOM tree as an element object.  This is suitable for passing to functions like Strophe.Connection.send().

Returns

The DOM tree as a element object.

toString

toString: function ()

Serialize the DOM tree to a String.

This function returns a string serialization of the current DOM tree.  It is often used internally to pass data to a Strophe.Request object.

Returns

The serialized DOM tree in a String.

up

up: function ()

Make the current parent element the new current element.

This function is often used after c() to traverse back up the tree.  For example, to add two children to the same element

builder.c('child1', {}).up().c('child2', {});

Returns

The Stophe.Builder object.

attrs

attrs: function (moreattrs)

Add or modify attributes of the current element.

The attributes should be passed in object notation.  This function does not move the current element pointer.

Parameters

(Object) moreattrsThe attributes to add/modify in object notation.

Returns

The Strophe.Builder object.

c

c: function (name,
attrs)

Add a child to the current element and make it the new current element.

This function moves the current element pointer to the child.  If you need to add another child, it is necessary to use up() to go back to the parent in the tree.

Parameters

(String) nameThe name of the child.
(Object) attrsThe attributes of the child in object notation.

Returns

The Strophe.Builder object.

cnode

cnode: function (elem)

Add a child to the current element and make it the new current element.

This function is the same as c() except that instead of using a name and an attributes object to create the child it uses an existing DOM element object.

Parameters

(XMLElement) elemA DOM element.

Returns

The Strophe.Builder object.

t

t: function (text)

Add a child text element.

This does not make the child the new current element since there are no children of text elements.

Parameters

(String) textThe text data to append to the current element.

Returns

The Strophe.Builder object.

Strophe.Connection

XMPP Connection manager.

Thie class is the main part of Strophe.  It manages a BOSH connection to an XMPP server and dispatches events to the user callbacks as data arrives.  It supports SASL PLAIN, SASL DIGEST-MD5, and legacy authentication.

After creating a Strophe.Connection object, the user will typically call connect() with a user supplied callback to handle connection level events like authentication failure, disconnection, or connection complete.

The user will also have several event handlers defined by using addHandler() and addTimedHandler().  These will allow the user code to respond to interesting stanzas or do something periodically with the connection.  These handlers will be active once authentication is finished.

To send data to the connection, use send().

Summary
Functions
Strophe.ConnectionCreate and initialize a Strophe.Connection object.
resetReset the connection.
pausePause the request manager.
resumeResume the request manager.
getUniqueIdGenerate a unique ID for use in <iq/> elements.
connectStarts the connection process.
attachAttach to an already created and authenticated BOSH session.
xmlInputUser overrideable function that receives XML data coming into the connection.
xmlOutputUser overrideable function that receives XML data sent to the connection.
rawInputUser overrideable function that receives raw data coming into the connection.
rawOutputUser overrideable function that receives raw data sent to the connection.
sendSend a stanza.
flushImmediately send any pending outgoing data.
sendIQHelper function to send IQ stanzas.
addTimedHandlerAdd a timed handler to the connection.
deleteTimedHandlerDelete a timed handler for a connection.
addHandlerAdd a stanza handler for the connection.
deleteHandlerDelete a stanza handler for a connection.
disconnectStart the graceful disconnection process.

Functions

Strophe.Connection

Strophe.Connection = function (service)

Create and initialize a Strophe.Connection object.

Parameters

(String) serviceThe BOSH service URL.

Returns

A new Strophe.Connection object.

reset

reset: function ()

Reset the connection.

This function should be called after a connection is disconnected before that connection is reused.

pause

pause: function ()

Pause the request manager.

This will prevent Strophe from sending any more requests to the server.  This is very useful for temporarily pausing while a lot of send() calls are happening quickly.  This causes Strophe to send the data in a single request, saving many request trips.

resume

resume: function ()

Resume the request manager.

This resumes after pause() has been called.

getUniqueId

getUniqueId: function (suffix)

Generate a unique ID for use in <iq/> elements.

All <iq/> stanzas are required to have unique id attributes.  This function makes creating these easy.  Each connection instance has a counter which starts from zero, and the value of this counter plus a colon followed by the suffix becomes the unique id.  If no suffix is supplied, the counter is used as the unique id.

Suffixes are used to make debugging easier when reading the stream data, and their use is recommended.  The counter resets to 0 for every new connection for the same reason.  For connections to the same server that authenticate the same way, all the ids should be the same, which makes it easy to see changes.  This is useful for automated testing as well.

Parameters

(String) suffixA optional suffix to append to the id.

Returns

A unique string to be used for the id attribute.

connect

connect: function (jid,
pass,
callback,
wait,
hold)

Starts the connection process.

As the connection process proceeds, the user supplied callback will be triggered multiple times with status updates.  The callback should take two arguments - the status code and the error condition.

The status code will be one of the values in the Strophe.Status constants.  The error condition will be one of the conditions defined in RFC 3920 or the condition ‘strophe-parsererror’.

Please see XEP 124 for a more detailed explanation of the optional parameters below.

Parameters

(String) jidThe user’s JID.  This may be a bare JID, or a full JID.  If a node is not supplied, SASL ANONYMOUS authentication will be attempted.
(String) passThe user’s password.  (Function) callback The connect callback function.
(Integer) waitThe optional HTTPBIND wait value.  This is the time the server will wait before returning an empty result for a request.  The default setting of 60 seconds is recommended.  Other settings will require tweaks to the Strophe.TIMEOUT value.
(Integer) holdThe optional HTTPBIND hold value.  This is the number of connections the server will hold at one time.  This should almost always be set to 1 (the default).

attach

attach: function (jid,
sid,
rid,
callback,
wait,
hold,
wind)

Attach to an already created and authenticated BOSH session.

This function is provided to allow Strophe to attach to BOSH sessions which have been created externally, perhaps by a Web application.  This is often used to support auto-login type features without putting user credentials into the page.

Parameters

(String) jidThe full JID that is bound by the session.
(String) sidThe SID of the BOSH session.
(String) ridThe current RID of the BOSH session.  This RID will be used by the next request.  (Function) callback The connect callback function.
(Integer) waitThe optional HTTPBIND wait value.  This is the time the server will wait before returning an empty result for a request.  The default setting of 60 seconds is recommended.  Other settings will require tweaks to the Strophe.TIMEOUT value.
(Integer) holdThe optional HTTPBIND hold value.  This is the number of connections the server will hold at one time.  This should almost always be set to 1 (the default).
(Integer) windThe optional HTTBIND window value.  This is the allowed range of request ids that are valid.  The default is 5.

xmlInput

xmlInput: function (elem)

User overrideable function that receives XML data coming into the connection.

The default function does nothing.  User code can override this with

Strophe.Connection.xmlInput = function (elem) {
  (user code)
};

Parameters

(XMLElement) elemThe XML data received by the connection.

xmlOutput

xmlOutput: function (elem)

User overrideable function that receives XML data sent to the connection.

The default function does nothing.  User code can override this with

Strophe.Connection.xmlOutput = function (elem) {
  (user code)
};

Parameters

(XMLElement) elemThe XMLdata sent by the connection.

rawInput

rawInput: function (data)

User overrideable function that receives raw data coming into the connection.

The default function does nothing.  User code can override this with

Strophe.Connection.rawInput = function (data) {
  (user code)
};

Parameters

(String) dataThe data received by the connection.

rawOutput

rawOutput: function (data)

User overrideable function that receives raw data sent to the connection.

The default function does nothing.  User code can override this with

Strophe.Connection.rawOutput = function (data) {
  (user code)
};

Parameters

(String) dataThe data sent by the connection.

send

send: function (elem)

Send a stanza.

This function is called to push data onto the send queue to go out over the wire.  Whenever a request is sent to the BOSH server, all pending data is sent and the queue is flushed.

Parameters

(XMLElement | [XMLElement] | Strophe.Builder) elem - The stanza to send.

flush

flush: function ()

Immediately send any pending outgoing data.

Normally send() queues outgoing data until the next idle period (100ms), which optimizes network use in the common cases when several send()s are called in succession. flush() can be used to immediately send all pending data.

sendIQ

sendIQ: function(elem,
callback,
errback,
timeout)

Helper function to send IQ stanzas.

Parameters

(XMLElement) elemThe stanza to send.
(Function) callbackThe callback function for a successful request.
(Function) errbackThe callback function for a failed or timed out request.  On timeout, the stanza will be null.
(Integer) timeoutThe time specified in milliseconds for a timeout to occur.

Returns

The id used to send the IQ.

addTimedHandler

addTimedHandler: function (period,
handler)

Add a timed handler to the connection.

This function adds a timed handler.  The provided handler will be called every period milliseconds until it returns false, the connection is terminated, or the handler is removed.  Handlers that wish to continue being invoked should return true.

Because of method binding it is necessary to save the result of this function if you wish to remove a handler with deleteTimedHandler().

Note that user handlers are not active until authentication is successful.

Parameters

(Integer) periodThe period of the handler.
(Function) handlerThe callback function.

Returns

A reference to the handler that can be used to remove it.

deleteTimedHandler

deleteTimedHandler: function (handRef)

Delete a timed handler for a connection.

This function removes a timed handler from the connection.  The handRef parameter is not the function passed to addTimedHandler(), but is the reference returned from addTimedHandler().

Parameters

(Strophe.TimedHandler) handRefThe handler reference.

addHandler

addHandler: function (handler,
ns,
name,
type,
id,
from,
options)

Add a stanza handler for the connection.

This function adds a stanza handler to the connection.  The handler callback will be called for any stanza that matches the parameters.  Note that if multiple parameters are supplied, they must all match for the handler to be invoked.

The handler will receive the stanza that triggered it as its argument.  The handler should return true if it is to be invoked again; returning false will remove the handler after it returns.

As a convenience, the ns parameters applies to the top level element and also any of its immediate children.  This is primarily to make matching /iq/query elements easy.

The options argument contains handler matching flags that affect how matches are determined.  Currently the only flag is matchBare (a boolean).  When matchBare is true, the from parameter and the from attribute on the stanza will be matched as bare JIDs instead of full JIDs.  To use this, pass {matchBare: true} as the value of options.  The default value for matchBare is false.

The return value should be saved if you wish to remove the handler with deleteHandler().

Parameters

(Function) handlerThe user callback.
(String) nsThe namespace to match.
(String) nameThe stanza name to match.
(String) typeThe stanza type attribute to match.
(String) idThe stanza id attribute to match.
(String) fromThe stanza from attribute to match.
(String) optionsThe handler options

Returns

A reference to the handler that can be used to remove it.

deleteHandler

deleteHandler: function (handRef)

Delete a stanza handler for a connection.

This function removes a stanza handler from the connection.  The handRef parameter is not the function passed to addHandler(), but is the reference returned from addHandler().

Parameters

(Strophe.Handler) handRefThe handler reference.

disconnect

disconnect: function (reason)

Start the graceful disconnection process.

This function starts the disconnection process.  This process starts by sending unavailable presence and sending BOSH body of type terminate.  A timeout handler makes sure that disconnection happens even if the BOSH server does not respond.

The user supplied connection callback will be notified of the progress as this process happens.

Parameters

(String) reasonThe reason the disconnect is occuring.
function $build(name,
attrs)
Create a Strophe.Builder.
function $msg(attrs)
Create a Strophe.Builder with a message/ element as the root.
function $iq(attrs)
Create a Strophe.Builder with an iq/ element as the root.
function $pres(attrs)
Create a Strophe.Builder with a presence/ element as the root.
addNamespace: function (name,
value)
This function is used to extend the current namespaces in Strophe.NS.
forEachChild: function (elem,
elemName,
func)
Map a function over some or all child elements of a given element.
isTagEqual: function (el,
name)
Compare an element’s tag name with a string.
xmlElement: function (name)
Create an XML DOM element.
xmlescape: function(text)
Excapes invalid xml characters.
xmlTextNode: function (text)
Creates an XML DOM text node.
getText: function (elem)
Get the concatenation of all text children of an element.
copyElement: function (elem)
Copy an XML DOM element.
escapeNode: function (node)
Escape the node part (also called local part) of a JID.
unescapeNode: function (node)
Unescape a node part (also called local part) of a JID.
getNodeFromJid: function (jid)
Get the node portion of a JID String.
getDomainFromJid: function (jid)
Get the domain portion of a JID String.
getResourceFromJid: function (jid)
Get the resource portion of a JID String.
getBareJidFromJid: function (jid)
Get the bare JID from a JID String.
log: function (level,
msg)
User overrideable logging function.
debug: function(msg)
Log a message at the Strophe.LogLevel.DEBUG level.
info: function (msg)
Log a message at the Strophe.LogLevel.INFO level.
warn: function (msg)
Log a message at the Strophe.LogLevel.WARN level.
error: function (msg)
Log a message at the Strophe.LogLevel.ERROR level.
fatal: function (msg)
Log a message at the Strophe.LogLevel.FATAL level.
serialize: function (elem)
Render a DOM element and all descendants to a String.
addConnectionPlugin: function (name,
ptype)
Extends the Strophe.Connection object with the given plugin.
Strophe.Builder = function (name,
attrs)
Create a Strophe.Builder object.
tree: function ()
Return the DOM tree.
toString: function ()
Serialize the DOM tree to a String.
up: function ()
Make the current parent element the new current element.
attrs: function (moreattrs)
Add or modify attributes of the current element.
c: function (name,
attrs)
Add a child to the current element and make it the new current element.
cnode: function (elem)
Add a child to the current element and make it the new current element.
t: function (text)
Add a child text element.
Strophe.Connection = function (service)
Create and initialize a Strophe.Connection object.
reset: function ()
Reset the connection.
pause: function ()
Pause the request manager.
resume: function ()
Resume the request manager.
getUniqueId: function (suffix)
Generate a unique ID for use in iq/ elements.
connect: function (jid,
pass,
callback,
wait,
hold)
Starts the connection process.
attach: function (jid,
sid,
rid,
callback,
wait,
hold,
wind)
Attach to an already created and authenticated BOSH session.
xmlInput: function (elem)
User overrideable function that receives XML data coming into the connection.
xmlOutput: function (elem)
User overrideable function that receives XML data sent to the connection.
rawInput: function (data)
User overrideable function that receives raw data coming into the connection.
rawOutput: function (data)
User overrideable function that receives raw data sent to the connection.
send: function (elem)
Send a stanza.
flush: function ()
Immediately send any pending outgoing data.
sendIQ: function(elem,
callback,
errback,
timeout)
Helper function to send IQ stanzas.
addTimedHandler: function (period,
handler)
Add a timed handler to the connection.
deleteTimedHandler: function (handRef)
Delete a timed handler for a connection.
addHandler: function (handler,
ns,
name,
type,
id,
from,
options)
Add a stanza handler for the connection.
deleteHandler: function (handRef)
Delete a stanza handler for a connection.
disconnect: function (reason)
Start the graceful disconnection process.
Close
strophejs-1.0.1.dfsg/doc/index.html000066400000000000000000000001311137577172600172310ustar00rootroot00000000000000strophejs-1.0.1.dfsg/doc/index/000077500000000000000000000000001137577172600163505ustar00rootroot00000000000000strophejs-1.0.1.dfsg/doc/index/Classes.html000066400000000000000000000102011137577172600206250ustar00rootroot00000000000000 Class Index
Class Index
$#! · 0-9 · A · B · C · D · E · F · G · H · I · J · K · L · M · N · O · P · Q · R · S · T · U · V · W · X · Y · Z
S
 Strophe
 Strophe.Builder
 Strophe.Connection
An object container for all Strophe library functions.
XML DOM builder.
XMPP Connection manager.
Close
strophejs-1.0.1.dfsg/doc/index/Constants.html000066400000000000000000000410401137577172600212110ustar00rootroot00000000000000 Constant Index
Constant Index
$#! · 0-9 · A · B · C · D · E · F · G · H · I · J · K · L · M · N · O · P · Q · R · S · T · U · V · W · X · Y · Z
A
 ATTACHED, Strophe.Status
 AUTH, Strophe.NS
 AUTHENTICATING, Strophe.Status
 AUTHFAIL, Strophe.Status
B
 BIND, Strophe.NS
 BOSH, Strophe.NS
C
 CLIENT, Strophe.NS
 CONNECTED, Strophe.Status
 CONNECTING, Strophe.Status
 Connection Status Constants, Strophe
 CONNFAIL, Strophe.Status
D
 DEBUG, Strophe.LogLevel
 DISCO_INFO, Strophe.NS
 DISCO_ITEMS, Strophe.NS
 DISCONNECTED, Strophe.Status
 DISCONNECTING, Strophe.Status
E
 ERROR
F
 FATAL, Strophe.LogLevel
H
 HTTPBIND, Strophe.NS
I
 INFO, Strophe.LogLevel
L
 Log Level Constants, Strophe
M
 MUC, Strophe.NS
P
 PROFILE, Strophe.NS
R
 ROSTER, Strophe.NS
S
 SASL, Strophe.NS
 SESSION, Strophe.NS
 STREAM, Strophe.NS
V
 VERSION, Strophe
W
 WARN, Strophe.LogLevel
X
 XMPP Namespace Constants, Strophe
The connection has been attached
Legacy authentication namespace.
The connection is authenticating
The authentication attempt failed
XMPP Binding namespace from RFC 3920.
BOSH namespace from XEP 206.
Main XMPP client namespace.
The connection has succeeded
The connection is currently being made
Connection status constants for use by the connection handler callback.
The connection attempt failed
Debug output
Service discovery info namespace from XEP 30.
Service discovery items namespace from XEP 30.
The connection has been terminated
The connection is currently being terminated
Errors
An error has occurred
Fatal errors
HTTP BIND namespace from XEP 124.
Informational output
Logging level indicators.
Multi-User Chat namespace from XEP 45.
Profile namespace.
Roster operations namespace.
XMPP SASL namespace from RFC 3920.
XMPP Session namespace from RFC 3920.
XMPP Streams namespace from RFC 3920.
The version of the Strophe library.
Warnings
Common namespace constants from the XMPP RFCs and XEPs.
Close
strophejs-1.0.1.dfsg/doc/index/Files.html000066400000000000000000000067451137577172600203140ustar00rootroot00000000000000 File Index
File Index
$#! · 0-9 · A · B · C · D · E · F · G · H · I · J · K · L · M · N · O · P · Q · R · S · T · U · V · W · X · Y · Z
S
 strophe.js
A JavaScript library for XMPP BOSH.
Close
strophejs-1.0.1.dfsg/doc/index/Functions.html000066400000000000000000001237211137577172600212140ustar00rootroot00000000000000 Function Index
Function Index
$#! · 0-9 · A · B · C · D · E · F · G · H · I · J · K · L · M · N · O · P · Q · R · S · T · U · V · W · X · Y · Z
$#!
 $build
 $iq
 $msg
 $pres
A
 addConnectionPlugin, Strophe
 addHandler, Strophe.Connection
 addNamespace, Strophe
 addTimedHandler, Strophe.Connection
 attach, Strophe.Connection
 attrs, Strophe.Builder
B
 Builder, Strophe.Builder.Strophe
C
 c, Strophe.Builder
 cnode, Strophe.Builder
 connect, Strophe.Connection
 Connection, Strophe.Connection.Strophe
 copyElement, Strophe
D
 debug, Strophe
 deleteHandler, Strophe.Connection
 deleteTimedHandler, Strophe.Connection
 disconnect, Strophe.Connection
E
 error, Strophe
 escapeNode, Strophe
F
 fatal, Strophe
 flush, Strophe.Connection
 forEachChild, Strophe
G
 getBareJidFromJid, Strophe
 getDomainFromJid, Strophe
 getNodeFromJid, Strophe
 getResourceFromJid, Strophe
 getText, Strophe
 getUniqueId, Strophe.Connection
I
 info, Strophe
 isTagEqual, Strophe
L
 log, Strophe
P
 pause, Strophe.Connection
R
 rawInput, Strophe.Connection
 rawOutput, Strophe.Connection
 reset, Strophe.Connection
 resume, Strophe.Connection
S
 send, Strophe.Connection
 sendIQ, Strophe.Connection
 serialize, Strophe
T
 t, Strophe.Builder
 toString, Strophe.Builder
 tree, Strophe.Builder
U
 unescapeNode, Strophe
 up, Strophe.Builder
W
 warn, Strophe
X
 xmlElement, Strophe
 xmlescape, Strophe
 xmlInput, Strophe.Connection
 xmlOutput, Strophe.Connection
 xmlTextNode, Strophe
function $build(name,
attrs)
Create a Strophe.Builder.
function $iq(attrs)
Create a Strophe.Builder with an iq/ element as the root.
function $msg(attrs)
Create a Strophe.Builder with a message/ element as the root.
function $pres(attrs)
Create a Strophe.Builder with a presence/ element as the root.
addConnectionPlugin: function (name,
ptype)
Extends the Strophe.Connection object with the given plugin.
addHandler: function (handler,
ns,
name,
type,
id,
from,
options)
Add a stanza handler for the connection.
addNamespace: function (name,
value)
This function is used to extend the current namespaces in Strophe.NS.
addTimedHandler: function (period,
handler)
Add a timed handler to the connection.
attach: function (jid,
sid,
rid,
callback,
wait,
hold,
wind)
Attach to an already created and authenticated BOSH session.
attrs: function (moreattrs)
Add or modify attributes of the current element.
Strophe.Builder = function (name,
attrs)
Create a Strophe.Builder object.
c: function (name,
attrs)
Add a child to the current element and make it the new current element.
cnode: function (elem)
Add a child to the current element and make it the new current element.
connect: function (jid,
pass,
callback,
wait,
hold)
Starts the connection process.
Strophe.Connection = function (service)
Create and initialize a Strophe.Connection object.
copyElement: function (elem)
Copy an XML DOM element.
debug: function(msg)
Log a message at the Strophe.LogLevel.DEBUG level.
deleteHandler: function (handRef)
Delete a stanza handler for a connection.
deleteTimedHandler: function (handRef)
Delete a timed handler for a connection.
disconnect: function (reason)
Start the graceful disconnection process.
error: function (msg)
Log a message at the Strophe.LogLevel.ERROR level.
escapeNode: function (node)
Escape the node part (also called local part) of a JID.
fatal: function (msg)
Log a message at the Strophe.LogLevel.FATAL level.
flush: function ()
Immediately send any pending outgoing data.
forEachChild: function (elem,
elemName,
func)
Map a function over some or all child elements of a given element.
getBareJidFromJid: function (jid)
Get the bare JID from a JID String.
getDomainFromJid: function (jid)
Get the domain portion of a JID String.
getNodeFromJid: function (jid)
Get the node portion of a JID String.
getResourceFromJid: function (jid)
Get the resource portion of a JID String.
getText: function (elem)
Get the concatenation of all text children of an element.
getUniqueId: function (suffix)
Generate a unique ID for use in iq/ elements.
info: function (msg)
Log a message at the Strophe.LogLevel.INFO level.
isTagEqual: function (el,
name)
Compare an element’s tag name with a string.
log: function (level,
msg)
User overrideable logging function.
pause: function ()
Pause the request manager.
rawInput: function (data)
User overrideable function that receives raw data coming into the connection.
rawOutput: function (data)
User overrideable function that receives raw data sent to the connection.
reset: function ()
Reset the connection.
resume: function ()
Resume the request manager.
send: function (elem)
Send a stanza.
sendIQ: function(elem,
callback,
errback,
timeout)
Helper function to send IQ stanzas.
serialize: function (elem)
Render a DOM element and all descendants to a String.
t: function (text)
Add a child text element.
toString: function ()
Serialize the DOM tree to a String.
tree: function ()
Return the DOM tree.
unescapeNode: function (node)
Unescape a node part (also called local part) of a JID.
up: function ()
Make the current parent element the new current element.
warn: function (msg)
Log a message at the Strophe.LogLevel.WARN level.
xmlElement: function (name)
Create an XML DOM element.
xmlescape: function(text)
Excapes invalid xml characters.
xmlInput: function (elem)
User overrideable function that receives XML data coming into the connection.
xmlOutput: function (elem)
User overrideable function that receives XML data sent to the connection.
xmlTextNode: function (text)
Creates an XML DOM text node.
Close
strophejs-1.0.1.dfsg/doc/index/General.html000066400000000000000000001470641137577172600206270ustar00rootroot00000000000000 Index
Index
$#! · 0-9 · A · B · C · D · E · F · G · H · I · J · K · L · M · N · O · P · Q · R · S · T · U · V · W · X · Y · Z
$#!
 $build
 $iq
 $msg
 $pres
A
 addConnectionPlugin, Strophe
 addHandler, Strophe.Connection
 addNamespace, Strophe
 addTimedHandler, Strophe.Connection
 attach, Strophe.Connection
 ATTACHED, Strophe.Status
 attrs, Strophe.Builder
 AUTH, Strophe.NS
 AUTHENTICATING, Strophe.Status
 AUTHFAIL, Strophe.Status
B
 BIND, Strophe.NS
 BOSH, Strophe.NS
 Builder, Strophe.Builder.Strophe
C
 c, Strophe.Builder
 CLIENT, Strophe.NS
 cnode, Strophe.Builder
 connect, Strophe.Connection
 CONNECTED, Strophe.Status
 CONNECTING, Strophe.Status
 Connection, Strophe.Connection.Strophe
 Connection Status Constants, Strophe
 CONNFAIL, Strophe.Status
 Constants, Strophe
 copyElement, Strophe
D
 debug, Strophe
 DEBUG, Strophe.LogLevel
 deleteHandler, Strophe.Connection
 deleteTimedHandler, Strophe.Connection
 DISCO_INFO, Strophe.NS
 DISCO_ITEMS, Strophe.NS
 disconnect, Strophe.Connection
 DISCONNECTED, Strophe.Status
 DISCONNECTING, Strophe.Status
E
 error, Strophe
 ERROR
 escapeNode, Strophe
F
 fatal, Strophe
 FATAL, Strophe.LogLevel
 flush, Strophe.Connection
 forEachChild, Strophe
 Functions
G
 getBareJidFromJid, Strophe
 getDomainFromJid, Strophe
 getNodeFromJid, Strophe
 getResourceFromJid, Strophe
 getText, Strophe
 getUniqueId, Strophe.Connection
H
 HTTPBIND, Strophe.NS
I
 info, Strophe
 INFO, Strophe.LogLevel
 isTagEqual, Strophe
L
 log, Strophe
 Log Level Constants, Strophe
M
 MUC, Strophe.NS
P
 pause, Strophe.Connection
 PROFILE, Strophe.NS
R
 rawInput, Strophe.Connection
 rawOutput, Strophe.Connection
 reset, Strophe.Connection
 resume, Strophe.Connection
 ROSTER, Strophe.NS
S
 SASL, Strophe.NS
 send, Strophe.Connection
 sendIQ, Strophe.Connection
 serialize, Strophe
 SESSION, Strophe.NS
 STREAM, Strophe.NS
 Strophe
 Strophe.Builder
 Strophe.Connection
 strophe.js
T
 t, Strophe.Builder
 toString, Strophe.Builder
 tree, Strophe.Builder
U
 unescapeNode, Strophe
 up, Strophe.Builder
V
 VERSION, Strophe
W
 warn, Strophe
 WARN, Strophe.LogLevel
function $build(name,
attrs)
Create a Strophe.Builder.
function $iq(attrs)
Create a Strophe.Builder with an iq/ element as the root.
function $msg(attrs)
Create a Strophe.Builder with a message/ element as the root.
function $pres(attrs)
Create a Strophe.Builder with a presence/ element as the root.
addConnectionPlugin: function (name,
ptype)
Extends the Strophe.Connection object with the given plugin.
addHandler: function (handler,
ns,
name,
type,
id,
from,
options)
Add a stanza handler for the connection.
addNamespace: function (name,
value)
This function is used to extend the current namespaces in Strophe.NS.
addTimedHandler: function (period,
handler)
Add a timed handler to the connection.
attach: function (jid,
sid,
rid,
callback,
wait,
hold,
wind)
Attach to an already created and authenticated BOSH session.
The connection has been attached
attrs: function (moreattrs)
Add or modify attributes of the current element.
Legacy authentication namespace.
The connection is authenticating
The authentication attempt failed
XMPP Binding namespace from RFC 3920.
BOSH namespace from XEP 206.
Strophe.Builder = function (name,
attrs)
Create a Strophe.Builder object.
c: function (name,
attrs)
Add a child to the current element and make it the new current element.
Main XMPP client namespace.
cnode: function (elem)
Add a child to the current element and make it the new current element.
connect: function (jid,
pass,
callback,
wait,
hold)
Starts the connection process.
The connection has succeeded
The connection is currently being made
Strophe.Connection = function (service)
Create and initialize a Strophe.Connection object.
Connection status constants for use by the connection handler callback.
The connection attempt failed
copyElement: function (elem)
Copy an XML DOM element.
debug: function(msg)
Log a message at the Strophe.LogLevel.DEBUG level.
Debug output
deleteHandler: function (handRef)
Delete a stanza handler for a connection.
deleteTimedHandler: function (handRef)
Delete a timed handler for a connection.
Service discovery info namespace from XEP 30.
Service discovery items namespace from XEP 30.
disconnect: function (reason)
Start the graceful disconnection process.
The connection has been terminated
The connection is currently being terminated
error: function (msg)
Log a message at the Strophe.LogLevel.ERROR level.
Errors
An error has occurred
escapeNode: function (node)
Escape the node part (also called local part) of a JID.
fatal: function (msg)
Log a message at the Strophe.LogLevel.FATAL level.
Fatal errors
flush: function ()
Immediately send any pending outgoing data.
forEachChild: function (elem,
elemName,
func)
Map a function over some or all child elements of a given element.
getBareJidFromJid: function (jid)
Get the bare JID from a JID String.
getDomainFromJid: function (jid)
Get the domain portion of a JID String.
getNodeFromJid: function (jid)
Get the node portion of a JID String.
getResourceFromJid: function (jid)
Get the resource portion of a JID String.
getText: function (elem)
Get the concatenation of all text children of an element.
getUniqueId: function (suffix)
Generate a unique ID for use in iq/ elements.
HTTP BIND namespace from XEP 124.
info: function (msg)
Log a message at the Strophe.LogLevel.INFO level.
Informational output
isTagEqual: function (el,
name)
Compare an element’s tag name with a string.
log: function (level,
msg)
User overrideable logging function.
Logging level indicators.
Multi-User Chat namespace from XEP 45.
pause: function ()
Pause the request manager.
Profile namespace.
rawInput: function (data)
User overrideable function that receives raw data coming into the connection.
rawOutput: function (data)
User overrideable function that receives raw data sent to the connection.
reset: function ()
Reset the connection.
resume: function ()
Resume the request manager.
Roster operations namespace.
XMPP SASL namespace from RFC 3920.
send: function (elem)
Send a stanza.
sendIQ: function(elem,
callback,
errback,
timeout)
Helper function to send IQ stanzas.
serialize: function (elem)
Render a DOM element and all descendants to a String.
XMPP Session namespace from RFC 3920.
XMPP Streams namespace from RFC 3920.
An object container for all Strophe library functions.
XML DOM builder.
XMPP Connection manager.
A JavaScript library for XMPP BOSH.
t: function (text)
Add a child text element.
toString: function ()
Serialize the DOM tree to a String.
tree: function ()
Return the DOM tree.
unescapeNode: function (node)
Unescape a node part (also called local part) of a JID.
up: function ()
Make the current parent element the new current element.
The version of the Strophe library.
warn: function (msg)
Log a message at the Strophe.LogLevel.WARN level.
Warnings
Close
strophejs-1.0.1.dfsg/doc/index/General2.html000066400000000000000000000170361137577172600207040ustar00rootroot00000000000000 Index
Index
$#! · 0-9 · A · B · C · D · E · F · G · H · I · J · K · L · M · N · O · P · Q · R · S · T · U · V · W · X · Y · Z
X
 xmlElement, Strophe
 xmlescape, Strophe
 xmlInput, Strophe.Connection
 xmlOutput, Strophe.Connection
 xmlTextNode, Strophe
 XMPP Namespace Constants, Strophe
xmlElement: function (name)
Create an XML DOM element.
xmlescape: function(text)
Excapes invalid xml characters.
xmlInput: function (elem)
User overrideable function that receives XML data coming into the connection.
xmlOutput: function (elem)
User overrideable function that receives XML data sent to the connection.
xmlTextNode: function (text)
Creates an XML DOM text node.
Common namespace constants from the XMPP RFCs and XEPs.
Close
strophejs-1.0.1.dfsg/doc/javascript/000077500000000000000000000000001137577172600174075ustar00rootroot00000000000000strophejs-1.0.1.dfsg/doc/javascript/main.js000066400000000000000000000614021137577172600206740ustar00rootroot00000000000000// This file is part of Natural Docs, which is Copyright (C) 2003-2008 Greg Valure // Natural Docs is licensed under the GPL // // Browser Styles // ____________________________________________________________________________ var agt=navigator.userAgent.toLowerCase(); var browserType; var browserVer; if (agt.indexOf("opera") != -1) { browserType = "Opera"; if (agt.indexOf("opera 7") != -1 || agt.indexOf("opera/7") != -1) { browserVer = "Opera7"; } else if (agt.indexOf("opera 8") != -1 || agt.indexOf("opera/8") != -1) { browserVer = "Opera8"; } else if (agt.indexOf("opera 9") != -1 || agt.indexOf("opera/9") != -1) { browserVer = "Opera9"; } } else if (agt.indexOf("applewebkit") != -1) { browserType = "Safari"; if (agt.indexOf("version/3") != -1) { browserVer = "Safari3"; } else if (agt.indexOf("safari/4") != -1) { browserVer = "Safari2"; } } else if (agt.indexOf("khtml") != -1) { browserType = "Konqueror"; } else if (agt.indexOf("msie") != -1) { browserType = "IE"; if (agt.indexOf("msie 6") != -1) { browserVer = "IE6"; } else if (agt.indexOf("msie 7") != -1) { browserVer = "IE7"; } } else if (agt.indexOf("gecko") != -1) { browserType = "Firefox"; if (agt.indexOf("rv:1.7") != -1) { browserVer = "Firefox1"; } else if (agt.indexOf("rv:1.8)") != -1 || agt.indexOf("rv:1.8.0") != -1) { browserVer = "Firefox15"; } else if (agt.indexOf("rv:1.8.1") != -1) { browserVer = "Firefox2"; } } // // Support Functions // ____________________________________________________________________________ function GetXPosition(item) { var position = 0; if (item.offsetWidth != null) { while (item != document.body && item != null) { position += item.offsetLeft; item = item.offsetParent; }; }; return position; }; function GetYPosition(item) { var position = 0; if (item.offsetWidth != null) { while (item != document.body && item != null) { position += item.offsetTop; item = item.offsetParent; }; }; return position; }; function MoveToPosition(item, x, y) { // Opera 5 chokes on the px extension, so it can use the Microsoft one instead. if (item.style.left != null) { item.style.left = x + "px"; item.style.top = y + "px"; } else if (item.style.pixelLeft != null) { item.style.pixelLeft = x; item.style.pixelTop = y; }; }; // // Menu // ____________________________________________________________________________ function ToggleMenu(id) { if (!window.document.getElementById) { return; }; var display = window.document.getElementById(id).style.display; if (display == "none") { display = "block"; } else { display = "none"; } window.document.getElementById(id).style.display = display; } function HideAllBut(ids, max) { if (document.getElementById) { ids.sort( function(a,b) { return a - b; } ); var number = 1; while (number < max) { if (ids.length > 0 && number == ids[0]) { ids.shift(); } else { document.getElementById("MGroupContent" + number).style.display = "none"; }; number++; }; }; } // // Tooltips // ____________________________________________________________________________ var tooltipTimer = 0; function ShowTip(event, tooltipID, linkID) { if (tooltipTimer) { clearTimeout(tooltipTimer); }; var docX = event.clientX + window.pageXOffset; var docY = event.clientY + window.pageYOffset; var showCommand = "ReallyShowTip('" + tooltipID + "', '" + linkID + "', " + docX + ", " + docY + ")"; tooltipTimer = setTimeout(showCommand, 1000); } function ReallyShowTip(tooltipID, linkID, docX, docY) { tooltipTimer = 0; var tooltip; var link; if (document.getElementById) { tooltip = document.getElementById(tooltipID); link = document.getElementById(linkID); } /* else if (document.all) { tooltip = eval("document.all['" + tooltipID + "']"); link = eval("document.all['" + linkID + "']"); } */ if (tooltip) { var left = GetXPosition(link); var top = GetYPosition(link); top += link.offsetHeight; // The fallback method is to use the mouse X and Y relative to the document. We use a separate if and test if its a number // in case some browser snuck through the above if statement but didn't support everything. if (!isFinite(top) || top == 0) { left = docX; top = docY; } // Some spacing to get it out from under the cursor. top += 10; // Make sure the tooltip doesnt get smushed by being too close to the edge, or in some browsers, go off the edge of the // page. We do it here because Konqueror does get offsetWidth right even if it doesnt get the positioning right. if (tooltip.offsetWidth != null) { var width = tooltip.offsetWidth; var docWidth = document.body.clientWidth; if (left + width > docWidth) { left = docWidth - width - 1; } // If there's a horizontal scroll bar we could go past zero because it's using the page width, not the window width. if (left < 0) { left = 0; }; } MoveToPosition(tooltip, left, top); tooltip.style.visibility = "visible"; } } function HideTip(tooltipID) { if (tooltipTimer) { clearTimeout(tooltipTimer); tooltipTimer = 0; } var tooltip; if (document.getElementById) { tooltip = document.getElementById(tooltipID); } else if (document.all) { tooltip = eval("document.all['" + tooltipID + "']"); } if (tooltip) { tooltip.style.visibility = "hidden"; } } // // Blockquote fix for IE // ____________________________________________________________________________ function NDOnLoad() { if (browserVer == "IE6") { var scrollboxes = document.getElementsByTagName('blockquote'); if (scrollboxes.item(0)) { NDDoResize(); window.onresize=NDOnResize; }; }; }; var resizeTimer = 0; function NDOnResize() { if (resizeTimer != 0) { clearTimeout(resizeTimer); }; resizeTimer = setTimeout(NDDoResize, 250); }; function NDDoResize() { var scrollboxes = document.getElementsByTagName('blockquote'); var i; var item; i = 0; while (item = scrollboxes.item(i)) { item.style.width = 100; i++; }; i = 0; while (item = scrollboxes.item(i)) { item.style.width = item.parentNode.offsetWidth; i++; }; clearTimeout(resizeTimer); resizeTimer = 0; } /* ________________________________________________________________________________________________________ Class: SearchPanel ________________________________________________________________________________________________________ A class handling everything associated with the search panel. Parameters: name - The name of the global variable that will be storing this instance. Is needed to be able to set timeouts. mode - The mode the search is going to work in. Pass CommandLineOption()>, so the value will be something like "HTML" or "FramedHTML". ________________________________________________________________________________________________________ */ function SearchPanel(name, mode, resultsPath) { if (!name || !mode || !resultsPath) { alert("Incorrect parameters to SearchPanel."); }; // Group: Variables // ________________________________________________________________________ /* var: name The name of the global variable that will be storing this instance of the class. */ this.name = name; /* var: mode The mode the search is going to work in, such as "HTML" or "FramedHTML". */ this.mode = mode; /* var: resultsPath The relative path from the current HTML page to the results page directory. */ this.resultsPath = resultsPath; /* var: keyTimeout The timeout used between a keystroke and when a search is performed. */ this.keyTimeout = 0; /* var: keyTimeoutLength The length of in thousandths of a second. */ this.keyTimeoutLength = 500; /* var: lastSearchValue The last search string executed, or an empty string if none. */ this.lastSearchValue = ""; /* var: lastResultsPage The last results page. The value is only relevant if is set. */ this.lastResultsPage = ""; /* var: deactivateTimeout The timeout used between when a control is deactivated and when the entire panel is deactivated. Is necessary because a control may be deactivated in favor of another control in the same panel, in which case it should stay active. */ this.deactivateTimout = 0; /* var: deactivateTimeoutLength The length of in thousandths of a second. */ this.deactivateTimeoutLength = 200; // Group: DOM Elements // ________________________________________________________________________ // Function: DOMSearchField this.DOMSearchField = function() { return document.getElementById("MSearchField"); }; // Function: DOMSearchType this.DOMSearchType = function() { return document.getElementById("MSearchType"); }; // Function: DOMPopupSearchResults this.DOMPopupSearchResults = function() { return document.getElementById("MSearchResults"); }; // Function: DOMPopupSearchResultsWindow this.DOMPopupSearchResultsWindow = function() { return document.getElementById("MSearchResultsWindow"); }; // Function: DOMSearchPanel this.DOMSearchPanel = function() { return document.getElementById("MSearchPanel"); }; // Group: Event Handlers // ________________________________________________________________________ /* Function: OnSearchFieldFocus Called when focus is added or removed from the search field. */ this.OnSearchFieldFocus = function(isActive) { this.Activate(isActive); }; /* Function: OnSearchFieldChange Called when the content of the search field is changed. */ this.OnSearchFieldChange = function() { if (this.keyTimeout) { clearTimeout(this.keyTimeout); this.keyTimeout = 0; }; var searchValue = this.DOMSearchField().value.replace(/ +/g, ""); if (searchValue != this.lastSearchValue) { if (searchValue != "") { this.keyTimeout = setTimeout(this.name + ".Search()", this.keyTimeoutLength); } else { if (this.mode == "HTML") { this.DOMPopupSearchResultsWindow().style.display = "none"; }; this.lastSearchValue = ""; }; }; }; /* Function: OnSearchTypeFocus Called when focus is added or removed from the search type. */ this.OnSearchTypeFocus = function(isActive) { this.Activate(isActive); }; /* Function: OnSearchTypeChange Called when the search type is changed. */ this.OnSearchTypeChange = function() { var searchValue = this.DOMSearchField().value.replace(/ +/g, ""); if (searchValue != "") { this.Search(); }; }; // Group: Action Functions // ________________________________________________________________________ /* Function: CloseResultsWindow Closes the results window. */ this.CloseResultsWindow = function() { this.DOMPopupSearchResultsWindow().style.display = "none"; this.Activate(false, true); }; /* Function: Search Performs a search. */ this.Search = function() { this.keyTimeout = 0; var searchValue = this.DOMSearchField().value.replace(/^ +/, ""); var searchTopic = this.DOMSearchType().value; var pageExtension = searchValue.substr(0,1); if (pageExtension.match(/^[a-z]/i)) { pageExtension = pageExtension.toUpperCase(); } else if (pageExtension.match(/^[0-9]/)) { pageExtension = 'Numbers'; } else { pageExtension = "Symbols"; }; var resultsPage; var resultsPageWithSearch; var hasResultsPage; // indexSectionsWithContent is defined in searchdata.js if (indexSectionsWithContent[searchTopic][pageExtension] == true) { resultsPage = this.resultsPath + '/' + searchTopic + pageExtension + '.html'; resultsPageWithSearch = resultsPage+'?'+escape(searchValue); hasResultsPage = true; } else { resultsPage = this.resultsPath + '/NoResults.html'; resultsPageWithSearch = resultsPage; hasResultsPage = false; }; var resultsFrame; if (this.mode == "HTML") { resultsFrame = window.frames.MSearchResults; } else if (this.mode == "FramedHTML") { resultsFrame = window.top.frames['Content']; }; if (resultsPage != this.lastResultsPage || // Bug in IE. If everything becomes hidden in a run, none of them will be able to be reshown in the next for some // reason. It counts the right number of results, and you can even read the display as "block" after setting it, but it // just doesn't work in IE 6 or IE 7. So if we're on the right page but the previous search had no results, reload the // page anyway to get around the bug. (browserType == "IE" && hasResultsPage && (!resultsFrame.searchResults || resultsFrame.searchResults.lastMatchCount == 0)) ) { resultsFrame.location.href = resultsPageWithSearch; } // So if the results page is right and there's no IE bug, reperform the search on the existing page. We have to check if there // are results because NoResults.html doesn't have any JavaScript, and it would be useless to do anything on that page even // if it did. else if (hasResultsPage) { // We need to check if this exists in case the frame is present but didn't finish loading. if (resultsFrame.searchResults) { resultsFrame.searchResults.Search(searchValue); } // Otherwise just reload instead of waiting. else { resultsFrame.location.href = resultsPageWithSearch; }; }; var domPopupSearchResultsWindow = this.DOMPopupSearchResultsWindow(); if (this.mode == "HTML" && domPopupSearchResultsWindow.style.display != "block") { var domSearchType = this.DOMSearchType(); var left = GetXPosition(domSearchType); var top = GetYPosition(domSearchType) + domSearchType.offsetHeight; MoveToPosition(domPopupSearchResultsWindow, left, top); domPopupSearchResultsWindow.style.display = 'block'; }; this.lastSearchValue = searchValue; this.lastResultsPage = resultsPage; }; // Group: Activation Functions // Functions that handle whether the entire panel is active or not. // ________________________________________________________________________ /* Function: Activate Activates or deactivates the search panel, resetting things to their default values if necessary. You can call this on every control's OnBlur() and it will handle not deactivating the entire panel when focus is just switching between them transparently. Parameters: isActive - Whether you're activating or deactivating the panel. ignoreDeactivateDelay - Set if you're positive the action will deactivate the panel and thus want to skip the delay. */ this.Activate = function(isActive, ignoreDeactivateDelay) { // We want to ignore isActive being false while the results window is open. if (isActive || (this.mode == "HTML" && this.DOMPopupSearchResultsWindow().style.display == "block")) { if (this.inactivateTimeout) { clearTimeout(this.inactivateTimeout); this.inactivateTimeout = 0; }; this.DOMSearchPanel().className = 'MSearchPanelActive'; var searchField = this.DOMSearchField(); if (searchField.value == 'Search') { searchField.value = ""; } } else if (!ignoreDeactivateDelay) { this.inactivateTimeout = setTimeout(this.name + ".InactivateAfterTimeout()", this.inactivateTimeoutLength); } else { this.InactivateAfterTimeout(); }; }; /* Function: InactivateAfterTimeout Called by , which is set by . Inactivation occurs on a timeout because a control may receive OnBlur() when focus is really transferring to another control in the search panel. In this case we don't want to actually deactivate the panel because not only would that cause a visible flicker but it could also reset the search value. So by doing it on a timeout instead, there's a short period where the second control's OnFocus() can cancel the deactivation. */ this.InactivateAfterTimeout = function() { this.inactivateTimeout = 0; this.DOMSearchPanel().className = 'MSearchPanelInactive'; this.DOMSearchField().value = "Search"; this.lastSearchValue = ""; this.lastResultsPage = ""; }; }; /* ________________________________________________________________________________________________________ Class: SearchResults _________________________________________________________________________________________________________ The class that handles everything on the search results page. _________________________________________________________________________________________________________ */ function SearchResults(name, mode) { /* var: mode The mode the search is going to work in, such as "HTML" or "FramedHTML". */ this.mode = mode; /* var: lastMatchCount The number of matches from the last run of . */ this.lastMatchCount = 0; /* Function: Toggle Toggles the visibility of the passed element ID. */ this.Toggle = function(id) { if (this.mode == "FramedHTML") { return; }; var parentElement = document.getElementById(id); var element = parentElement.firstChild; while (element && element != parentElement) { if (element.nodeName == 'DIV' && element.className == 'ISubIndex') { if (element.style.display == 'block') { element.style.display = "none"; } else { element.style.display = 'block'; } }; if (element.nodeName == 'DIV' && element.hasChildNodes()) { element = element.firstChild; } else if (element.nextSibling) { element = element.nextSibling; } else { do { element = element.parentNode; } while (element && element != parentElement && !element.nextSibling); if (element && element != parentElement) { element = element.nextSibling; }; }; }; }; /* Function: Search Searches for the passed string. If there is no parameter, it takes it from the URL query. Always returns true, since other documents may try to call it and that may or may not be possible. */ this.Search = function(search) { if (!search) { search = window.location.search; search = search.substring(1); // Remove the leading ? search = unescape(search); }; search = search.replace(/^ +/, ""); search = search.replace(/ +$/, ""); search = search.toLowerCase(); if (search.match(/[^a-z0-9]/)) // Just a little speedup so it doesn't have to go through the below unnecessarily. { search = search.replace(/\_/g, "_und"); search = search.replace(/\ +/gi, "_spc"); search = search.replace(/\~/g, "_til"); search = search.replace(/\!/g, "_exc"); search = search.replace(/\@/g, "_att"); search = search.replace(/\#/g, "_num"); search = search.replace(/\$/g, "_dol"); search = search.replace(/\%/g, "_pct"); search = search.replace(/\^/g, "_car"); search = search.replace(/\&/g, "_amp"); search = search.replace(/\*/g, "_ast"); search = search.replace(/\(/g, "_lpa"); search = search.replace(/\)/g, "_rpa"); search = search.replace(/\-/g, "_min"); search = search.replace(/\+/g, "_plu"); search = search.replace(/\=/g, "_equ"); search = search.replace(/\{/g, "_lbc"); search = search.replace(/\}/g, "_rbc"); search = search.replace(/\[/g, "_lbk"); search = search.replace(/\]/g, "_rbk"); search = search.replace(/\:/g, "_col"); search = search.replace(/\;/g, "_sco"); search = search.replace(/\"/g, "_quo"); search = search.replace(/\'/g, "_apo"); search = search.replace(/\/g, "_ran"); search = search.replace(/\,/g, "_com"); search = search.replace(/\./g, "_per"); search = search.replace(/\?/g, "_que"); search = search.replace(/\//g, "_sla"); search = search.replace(/[^a-z0-9\_]i/gi, "_zzz"); }; var resultRows = document.getElementsByTagName("div"); var matches = 0; var i = 0; while (i < resultRows.length) { var row = resultRows.item(i); if (row.className == "SRResult") { var rowMatchName = row.id.toLowerCase(); rowMatchName = rowMatchName.replace(/^sr\d*_/, ''); if (search.length <= rowMatchName.length && rowMatchName.substr(0, search.length) == search) { row.style.display = "block"; matches++; } else { row.style.display = "none"; }; }; i++; }; document.getElementById("Searching").style.display="none"; if (matches == 0) { document.getElementById("NoMatches").style.display="block"; } else { document.getElementById("NoMatches").style.display="none"; } this.lastMatchCount = matches; return true; }; }; strophejs-1.0.1.dfsg/doc/javascript/searchdata.js000066400000000000000000000051731137577172600220520ustar00rootroot00000000000000var indexSectionsWithContent = { "General": { "Symbols": true, "Numbers": false, "A": true, "B": true, "C": true, "D": true, "E": true, "F": true, "G": true, "H": true, "I": true, "J": false, "K": false, "L": true, "M": true, "N": false, "O": false, "P": true, "Q": false, "R": true, "S": true, "T": true, "U": true, "V": true, "W": true, "X": true, "Y": false, "Z": false }, "Functions": { "Symbols": true, "Numbers": false, "A": true, "B": true, "C": true, "D": true, "E": true, "F": true, "G": true, "H": false, "I": true, "J": false, "K": false, "L": true, "M": false, "N": false, "O": false, "P": true, "Q": false, "R": true, "S": true, "T": true, "U": true, "V": false, "W": true, "X": true, "Y": false, "Z": false }, "Files": { "Symbols": false, "Numbers": false, "A": false, "B": false, "C": false, "D": false, "E": false, "F": false, "G": false, "H": false, "I": false, "J": false, "K": false, "L": false, "M": false, "N": false, "O": false, "P": false, "Q": false, "R": false, "S": true, "T": false, "U": false, "V": false, "W": false, "X": false, "Y": false, "Z": false }, "Constants": { "Symbols": false, "Numbers": false, "A": true, "B": true, "C": true, "D": true, "E": true, "F": true, "G": false, "H": true, "I": true, "J": false, "K": false, "L": true, "M": true, "N": false, "O": false, "P": true, "Q": false, "R": true, "S": true, "T": false, "U": false, "V": true, "W": true, "X": true, "Y": false, "Z": false }, "Classes": { "Symbols": false, "Numbers": false, "A": false, "B": false, "C": false, "D": false, "E": false, "F": false, "G": false, "H": false, "I": false, "J": false, "K": false, "L": false, "M": false, "N": false, "O": false, "P": false, "Q": false, "R": false, "S": true, "T": false, "U": false, "V": false, "W": false, "X": false, "Y": false, "Z": false } }strophejs-1.0.1.dfsg/doc/search/000077500000000000000000000000001137577172600165065ustar00rootroot00000000000000strophejs-1.0.1.dfsg/doc/search/ClassesS.html000066400000000000000000000033441137577172600211200ustar00rootroot00000000000000
Loading...
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/ConstantsA.html000066400000000000000000000040541137577172600214540ustar00rootroot00000000000000
Loading...
ATTACHED, Strophe.Status
AUTH, Strophe.NS
AUTHENTICATING, Strophe.Status
AUTHFAIL, Strophe.Status
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/ConstantsB.html000066400000000000000000000031351137577172600214540ustar00rootroot00000000000000
Loading...
BIND, Strophe.NS
BOSH, Strophe.NS
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/ConstantsC.html000066400000000000000000000044471137577172600214640ustar00rootroot00000000000000
Loading...
CLIENT, Strophe.NS
CONNECTED, Strophe.Status
CONNECTING, Strophe.Status
CONNFAIL, Strophe.Status
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/ConstantsD.html000066400000000000000000000044261137577172600214620ustar00rootroot00000000000000
Loading...
DEBUG, Strophe.LogLevel
DISCO_INFO, Strophe.NS
DISCO_ITEMS, Strophe.NS
DISCONNECTED, Strophe.Status
DISCONNECTING, Strophe.Status
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/ConstantsE.html000066400000000000000000000031471137577172600214620ustar00rootroot00000000000000
Loading...
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/ConstantsF.html000066400000000000000000000026701137577172600214630ustar00rootroot00000000000000
Loading...
FATAL, Strophe.LogLevel
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/ConstantsH.html000066400000000000000000000026601137577172600214640ustar00rootroot00000000000000
Loading...
HTTPBIND, Strophe.NS
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/ConstantsI.html000066400000000000000000000026651137577172600214720ustar00rootroot00000000000000
Loading...
INFO, Strophe.LogLevel
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/ConstantsL.html000066400000000000000000000027211137577172600214660ustar00rootroot00000000000000
Loading...
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/ConstantsM.html000066400000000000000000000026411137577172600214700ustar00rootroot00000000000000
Loading...
MUC, Strophe.NS
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/ConstantsP.html000066400000000000000000000026551137577172600215000ustar00rootroot00000000000000
Loading...
PROFILE, Strophe.NS
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/ConstantsR.html000066400000000000000000000026521137577172600214770ustar00rootroot00000000000000
Loading...
ROSTER, Strophe.NS
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/ConstantsS.html000066400000000000000000000034451137577172600215010ustar00rootroot00000000000000
Loading...
SASL, Strophe.NS
SESSION, Strophe.NS
STREAM, Strophe.NS
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/ConstantsV.html000066400000000000000000000026471137577172600215070ustar00rootroot00000000000000
Loading...
VERSION, Strophe
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/ConstantsW.html000066400000000000000000000026651137577172600215100ustar00rootroot00000000000000
Loading...
WARN, Strophe.LogLevel
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/ConstantsX.html000066400000000000000000000027401137577172600215030ustar00rootroot00000000000000
Loading...
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/FilesS.html000066400000000000000000000026071137577172600205660ustar00rootroot00000000000000
Loading...
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/FunctionsA.html000066400000000000000000000050041137577172600214440ustar00rootroot00000000000000
Loading...
addHandler, Strophe.Connection
addNamespace, Strophe
addTimedHandler, Strophe.Connection
attach, Strophe.Connection
attrs, Strophe.Builder
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/FunctionsB.html000066400000000000000000000027211137577172600214500ustar00rootroot00000000000000
Loading...
Builder, Strophe.Builder.Strophe
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/FunctionsC.html000066400000000000000000000044111137577172600214470ustar00rootroot00000000000000
Loading...
c, Strophe.Builder
cnode, Strophe.Builder
connect, Strophe.Connection
Connection, Strophe.Connection.Strophe
copyElement, Strophe
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/FunctionsD.html000066400000000000000000000041421137577172600214510ustar00rootroot00000000000000
Loading...
debug, Strophe
deleteHandler, Strophe.Connection
deleteTimedHandler, Strophe.Connection
disconnect, Strophe.Connection
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/FunctionsE.html000066400000000000000000000031461137577172600214550ustar00rootroot00000000000000
Loading...
error, Strophe
escapeNode, Strophe
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/FunctionsF.html000066400000000000000000000034751137577172600214630ustar00rootroot00000000000000
Loading...
fatal, Strophe
flush, Strophe.Connection
forEachChild, Strophe
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/FunctionsG.html000066400000000000000000000047511137577172600214620ustar00rootroot00000000000000
Loading...
getText, Strophe
getUniqueId, Strophe.Connection
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/FunctionsI.html000066400000000000000000000031431137577172600214560ustar00rootroot00000000000000
Loading...
info, Strophe
isTagEqual, Strophe
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/FunctionsL.html000066400000000000000000000026331137577172600214640ustar00rootroot00000000000000
Loading...
log, Strophe
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/FunctionsP.html000066400000000000000000000026741137577172600214750ustar00rootroot00000000000000
Loading...
pause, Strophe.Connection
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/FunctionsR.html000066400000000000000000000041071137577172600214700ustar00rootroot00000000000000
Loading...
rawInput, Strophe.Connection
rawOutput, Strophe.Connection
reset, Strophe.Connection
resume, Strophe.Connection
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/FunctionsS.html000066400000000000000000000035171137577172600214750ustar00rootroot00000000000000
Loading...
send, Strophe.Connection
sendIQ, Strophe.Connection
serialize, Strophe
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/FunctionsSymbols.html000066400000000000000000000034311137577172600227160ustar00rootroot00000000000000
Loading...
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/FunctionsT.html000066400000000000000000000035061137577172600214740ustar00rootroot00000000000000
Loading...
t, Strophe.Builder
toString, Strophe.Builder
tree, Strophe.Builder
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/FunctionsU.html000066400000000000000000000031701137577172600214720ustar00rootroot00000000000000
Loading...
unescapeNode, Strophe
up, Strophe.Builder
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/FunctionsW.html000066400000000000000000000026361137577172600215020ustar00rootroot00000000000000
Loading...
warn, Strophe
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/FunctionsX.html000066400000000000000000000043611137577172600215000ustar00rootroot00000000000000
Loading...
xmlElement, Strophe
xmlescape, Strophe
xmlInput, Strophe.Connection
xmlOutput, Strophe.Connection
xmlTextNode, Strophe
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/GeneralA.html000066400000000000000000000065051137577172600210600ustar00rootroot00000000000000
Loading...
addHandler, Strophe.Connection
addNamespace, Strophe
addTimedHandler, Strophe.Connection
attach, Strophe.Connection
ATTACHED, Strophe.Status
attrs, Strophe.Builder
AUTH, Strophe.NS
AUTHENTICATING, Strophe.Status
AUTHFAIL, Strophe.Status
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/GeneralB.html000066400000000000000000000035031137577172600210540ustar00rootroot00000000000000
Loading...
BIND, Strophe.NS
BOSH, Strophe.NS
Builder, Strophe.Builder.Strophe
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/GeneralC.html000066400000000000000000000070071137577172600210600ustar00rootroot00000000000000
Loading...
c, Strophe.Builder
CLIENT, Strophe.NS
cnode, Strophe.Builder
connect, Strophe.Connection
CONNECTED, Strophe.Status
CONNECTING, Strophe.Status
Connection, Strophe.Connection.Strophe
CONNFAIL, Strophe.Status
Constants, Strophe
copyElement, Strophe
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/GeneralD.html000066400000000000000000000062161137577172600210620ustar00rootroot00000000000000
Loading...
debug, Strophe
DEBUG, Strophe.LogLevel
deleteHandler, Strophe.Connection
deleteTimedHandler, Strophe.Connection
DISCO_INFO, Strophe.NS
DISCO_ITEMS, Strophe.NS
disconnect, Strophe.Connection
DISCONNECTED, Strophe.Status
DISCONNECTING, Strophe.Status
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/GeneralE.html000066400000000000000000000037441137577172600210660ustar00rootroot00000000000000
Loading...
error, Strophe
escapeNode, Strophe
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/GeneralF.html000066400000000000000000000051141137577172600210600ustar00rootroot00000000000000
Loading...
fatal, Strophe
FATAL, Strophe.LogLevel
flush, Strophe.Connection
forEachChild, Strophe
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/GeneralG.html000066400000000000000000000047511137577172600210670ustar00rootroot00000000000000
Loading...
getText, Strophe
getUniqueId, Strophe.Connection
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/GeneralH.html000066400000000000000000000026601137577172600210650ustar00rootroot00000000000000
Loading...
HTTPBIND, Strophe.NS
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/GeneralI.html000066400000000000000000000034561137577172600210720ustar00rootroot00000000000000
Loading...
info, Strophe
INFO, Strophe.LogLevel
isTagEqual, Strophe
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/GeneralL.html000066400000000000000000000032011137577172600210610ustar00rootroot00000000000000
Loading...
log, Strophe
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/GeneralM.html000066400000000000000000000026411137577172600210710ustar00rootroot00000000000000
Loading...
MUC, Strophe.NS
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/GeneralP.html000066400000000000000000000031761137577172600211000ustar00rootroot00000000000000
Loading...
pause, Strophe.Connection
PROFILE, Strophe.NS
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/GeneralR.html000066400000000000000000000044061137577172600210770ustar00rootroot00000000000000
Loading...
rawInput, Strophe.Connection
rawOutput, Strophe.Connection
reset, Strophe.Connection
resume, Strophe.Connection
ROSTER, Strophe.NS
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/GeneralS.html000066400000000000000000000060361137577172600211010ustar00rootroot00000000000000
Loading...
SASL, Strophe.NS
send, Strophe.Connection
sendIQ, Strophe.Connection
serialize, Strophe
SESSION, Strophe.NS
STREAM, Strophe.NS
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/GeneralSymbols.html000066400000000000000000000034311137577172600223230ustar00rootroot00000000000000
Loading...
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/GeneralT.html000066400000000000000000000035061137577172600211010ustar00rootroot00000000000000
Loading...
t, Strophe.Builder
toString, Strophe.Builder
tree, Strophe.Builder
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/GeneralU.html000066400000000000000000000031701137577172600210770ustar00rootroot00000000000000
Loading...
unescapeNode, Strophe
up, Strophe.Builder
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/GeneralV.html000066400000000000000000000026471137577172600211100ustar00rootroot00000000000000
Loading...
VERSION, Strophe
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/GeneralW.html000066400000000000000000000031511137577172600211000ustar00rootroot00000000000000
Loading...
warn, Strophe
WARN, Strophe.LogLevel
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/GeneralX.html000066400000000000000000000047461137577172600211140ustar00rootroot00000000000000
Loading...
xmlElement, Strophe
xmlescape, Strophe
xmlInput, Strophe.Connection
xmlOutput, Strophe.Connection
xmlTextNode, Strophe
Searching...
No Matches
strophejs-1.0.1.dfsg/doc/search/NoResults.html000066400000000000000000000015311137577172600213320ustar00rootroot00000000000000
No Matches
strophejs-1.0.1.dfsg/doc/styles/000077500000000000000000000000001137577172600165645ustar00rootroot00000000000000strophejs-1.0.1.dfsg/doc/styles/main.css000066400000000000000000000460031137577172600202250ustar00rootroot00000000000000/* IMPORTANT: If you're editing this file in the output directory of one of your projects, your changes will be overwritten the next time you run Natural Docs. Instead, copy this file to your project directory, make your changes, and you can use it with -s. Even better would be to make a CSS file in your project directory with only your changes, which you can then use with -s [original style] [your changes]. On the other hand, if you're editing this file in the Natural Docs styles directory, the changes will automatically be applied to all your projects that use this style the next time Natural Docs is run on them. This file is part of Natural Docs, which is Copyright (C) 2003-2008 Greg Valure Natural Docs is licensed under the GPL */ body { font: 10pt Verdana, Arial, sans-serif; color: #000000; margin: 0; padding: 0; } .ContentPage, .IndexPage, .FramedMenuPage { background-color: #E8E8E8; } .FramedContentPage, .FramedIndexPage, .FramedSearchResultsPage, .PopupSearchResultsPage { background-color: #FFFFFF; } a:link, a:visited { color: #900000; text-decoration: none } a:hover { color: #900000; text-decoration: underline } a:active { color: #FF0000; text-decoration: underline } td { vertical-align: top } img { border: 0; } /* Comment out this line to use web-style paragraphs (blank line between paragraphs, no indent) instead of print-style paragraphs (no blank line, indented.) */ p { text-indent: 5ex; margin: 0 } /* Opera doesn't break with just wbr, but will if you add this. */ .Opera wbr:after { content: "\00200B"; } /* Blockquotes are used as containers for things that may need to scroll. */ blockquote { padding: 0; margin: 0; overflow: auto; } .Firefox1 blockquote { padding-bottom: .5em; } /* Turn off scrolling when printing. */ @media print { blockquote { overflow: visible; } .IE blockquote { width: auto; } } #Menu { font-size: 9pt; padding: 10px 0 0 0; } .ContentPage #Menu, .IndexPage #Menu { position: absolute; top: 0; left: 0; width: 31ex; overflow: hidden; } .ContentPage .Firefox #Menu, .IndexPage .Firefox #Menu { width: 27ex; } .MTitle { font-size: 16pt; font-weight: bold; font-variant: small-caps; text-align: center; padding: 5px 10px 15px 10px; border-bottom: 1px dotted #000000; margin-bottom: 15px } .MSubTitle { font-size: 9pt; font-weight: normal; font-variant: normal; margin-top: 1ex; margin-bottom: 5px } .MEntry a:link, .MEntry a:hover, .MEntry a:visited { color: #606060; margin-right: 0 } .MEntry a:active { color: #A00000; margin-right: 0 } .MGroup { font-variant: small-caps; font-weight: bold; margin: 1em 0 1em 10px; } .MGroupContent { font-variant: normal; font-weight: normal } .MGroup a:link, .MGroup a:hover, .MGroup a:visited { color: #545454; margin-right: 10px } .MGroup a:active { color: #A00000; margin-right: 10px } .MFile, .MText, .MLink, .MIndex { padding: 1px 17px 2px 10px; margin: .25em 0 .25em 0; } .MText { font-size: 8pt; font-style: italic } .MLink { font-style: italic } #MSelected { color: #000000; background-color: #FFFFFF; /* Replace padding with border. */ padding: 0 10px 0 10px; border-width: 1px 2px 2px 0; border-style: solid; border-color: #000000; margin-right: 5px; } /* Close off the left side when its in a group. */ .MGroup #MSelected { padding-left: 9px; border-left-width: 1px } /* A treat for Mozilla users. Blatantly non-standard. Will be replaced with CSS 3 attributes when finalized/supported. */ .Firefox #MSelected { -moz-border-radius-topright: 10px; -moz-border-radius-bottomright: 10px } .Firefox .MGroup #MSelected { -moz-border-radius-topleft: 10px; -moz-border-radius-bottomleft: 10px } #MSearchPanel { padding: 0px 6px; margin: .25em 0; } #MSearchField { font: italic 9pt Verdana, sans-serif; color: #606060; background-color: #E8E8E8; border: none; padding: 2px 4px; width: 100%; } /* Only Opera gets it right. */ .Firefox #MSearchField, .IE #MSearchField, .Safari #MSearchField { width: 94%; } .Opera9 #MSearchField, .Konqueror #MSearchField { width: 97%; } .FramedMenuPage .Firefox #MSearchField, .FramedMenuPage .Safari #MSearchField, .FramedMenuPage .Konqueror #MSearchField { width: 98%; } /* Firefox doesn't do this right in frames without #MSearchPanel added on. It's presence doesn't hurt anything other browsers. */ #MSearchPanel.MSearchPanelInactive:hover #MSearchField { background-color: #FFFFFF; border: 1px solid #C0C0C0; padding: 1px 3px; } .MSearchPanelActive #MSearchField { background-color: #FFFFFF; border: 1px solid #C0C0C0; font-style: normal; padding: 1px 3px; } #MSearchType { visibility: hidden; font: 8pt Verdana, sans-serif; width: 98%; padding: 0; border: 1px solid #C0C0C0; } .MSearchPanelActive #MSearchType, /* As mentioned above, Firefox doesn't do this right in frames without #MSearchPanel added on. */ #MSearchPanel.MSearchPanelInactive:hover #MSearchType, #MSearchType:focus { visibility: visible; color: #606060; } #MSearchType option#MSearchEverything { font-weight: bold; } .Opera8 .MSearchPanelInactive:hover, .Opera8 .MSearchPanelActive { margin-left: -1px; } iframe#MSearchResults { width: 60ex; height: 15em; } #MSearchResultsWindow { display: none; position: absolute; left: 0; top: 0; border: 1px solid #000000; background-color: #E8E8E8; } #MSearchResultsWindowClose { font-weight: bold; font-size: 8pt; display: block; padding: 2px 5px; } #MSearchResultsWindowClose:link, #MSearchResultsWindowClose:visited { color: #000000; text-decoration: none; } #MSearchResultsWindowClose:active, #MSearchResultsWindowClose:hover { color: #800000; text-decoration: none; background-color: #F4F4F4; } #Content { padding-bottom: 15px; } .ContentPage #Content { border-width: 0 0 1px 1px; border-style: solid; border-color: #000000; background-color: #FFFFFF; font-size: 9pt; /* To make 31ex match the menu's 31ex. */ margin-left: 31ex; } .ContentPage .Firefox #Content { margin-left: 27ex; } .CTopic { font-size: 10pt; margin-bottom: 3em; } .CTitle { font-size: 12pt; font-weight: bold; border-width: 0 0 1px 0; border-style: solid; border-color: #A0A0A0; margin: 0 15px .5em 15px } .CGroup .CTitle { font-size: 16pt; font-variant: small-caps; padding-left: 15px; padding-right: 15px; border-width: 0 0 2px 0; border-color: #000000; margin-left: 0; margin-right: 0 } .CClass .CTitle, .CInterface .CTitle, .CDatabase .CTitle, .CDatabaseTable .CTitle, .CSection .CTitle { font-size: 18pt; color: #FFFFFF; background-color: #A0A0A0; padding: 10px 15px 10px 15px; border-width: 2px 0; border-color: #000000; margin-left: 0; margin-right: 0 } #MainTopic .CTitle { font-size: 20pt; color: #FFFFFF; background-color: #7070C0; padding: 10px 15px 10px 15px; border-width: 0 0 3px 0; border-color: #000000; margin-left: 0; margin-right: 0 } .CBody { margin-left: 15px; margin-right: 15px } .CToolTip { position: absolute; visibility: hidden; left: 0; top: 0; background-color: #FFFFE0; padding: 5px; border-width: 1px 2px 2px 1px; border-style: solid; border-color: #000000; font-size: 8pt; } .Opera .CToolTip { max-width: 98%; } /* Scrollbars would be useless. */ .CToolTip blockquote { overflow: hidden; } .IE6 .CToolTip blockquote { overflow: visible; } .CHeading { font-weight: bold; font-size: 10pt; margin: 1.5em 0 .5em 0; } .CBody pre { font: 10pt "Courier New", Courier, monospace; margin: 1em 0; } .CBody ul { /* I don't know why CBody's margin doesn't apply, but it's consistent across browsers so whatever. Reapply it here as padding. */ padding-left: 15px; padding-right: 15px; margin: .5em 5ex .5em 5ex; } .CDescriptionList { margin: .5em 5ex 0 5ex } .CDLEntry { font: 10pt "Courier New", Courier, monospace; color: #808080; padding-bottom: .25em; white-space: nowrap } .CDLDescription { font-size: 10pt; /* For browsers that don't inherit correctly, like Opera 5. */ padding-bottom: .5em; padding-left: 5ex } .CTopic img { text-align: center; display: block; margin: 1em auto; } .CImageCaption { font-variant: small-caps; font-size: 8pt; color: #808080; text-align: center; position: relative; top: 1em; } .CImageLink { color: #808080; font-style: italic; } a.CImageLink:link, a.CImageLink:visited, a.CImageLink:hover { color: #808080 } .Prototype { font: 10pt "Courier New", Courier, monospace; padding: 5px 3ex; border-width: 1px; border-style: solid; margin: 0 5ex 1.5em 5ex; } .Prototype td { font-size: 10pt; } .PDefaultValue, .PDefaultValuePrefix, .PTypePrefix { color: #8F8F8F; } .PTypePrefix { text-align: right; } .PAfterParameters { vertical-align: bottom; } .IE .Prototype table { padding: 0; } .CFunction .Prototype { background-color: #F4F4F4; border-color: #D0D0D0 } .CProperty .Prototype { background-color: #F4F4FF; border-color: #C0C0E8 } .CVariable .Prototype { background-color: #FFFFF0; border-color: #E0E0A0 } .CClass .Prototype { border-width: 1px 2px 2px 1px; border-style: solid; border-color: #A0A0A0; background-color: #F4F4F4; } .CInterface .Prototype { border-width: 1px 2px 2px 1px; border-style: solid; border-color: #A0A0D0; background-color: #F4F4FF; } .CDatabaseIndex .Prototype, .CConstant .Prototype { background-color: #D0D0D0; border-color: #000000 } .CType .Prototype, .CEnumeration .Prototype { background-color: #FAF0F0; border-color: #E0B0B0; } .CDatabaseTrigger .Prototype, .CEvent .Prototype, .CDelegate .Prototype { background-color: #F0FCF0; border-color: #B8E4B8 } .CToolTip .Prototype { margin: 0 0 .5em 0; white-space: nowrap; } .Summary { margin: 1.5em 5ex 0 5ex } .STitle { font-size: 12pt; font-weight: bold; margin-bottom: .5em } .SBorder { background-color: #FFFFF0; padding: 15px; border: 1px solid #C0C060 } /* In a frame IE 6 will make them too long unless you set the width to 100%. Without frames it will be correct without a width or slightly too long (but not enough to scroll) with a width. This arbitrary weirdness simply astounds me. IE 7 has the same problem with frames, haven't tested it without. */ .FramedContentPage .IE .SBorder { width: 100% } /* A treat for Mozilla users. Blatantly non-standard. Will be replaced with CSS 3 attributes when finalized/supported. */ .Firefox .SBorder { -moz-border-radius: 20px } .STable { font-size: 9pt; width: 100% } .SEntry { width: 30% } .SDescription { width: 70% } .SMarked { background-color: #F8F8D8 } .SDescription { padding-left: 2ex } .SIndent1 .SEntry { padding-left: 1.5ex } .SIndent1 .SDescription { padding-left: 3.5ex } .SIndent2 .SEntry { padding-left: 3.0ex } .SIndent2 .SDescription { padding-left: 5.0ex } .SIndent3 .SEntry { padding-left: 4.5ex } .SIndent3 .SDescription { padding-left: 6.5ex } .SIndent4 .SEntry { padding-left: 6.0ex } .SIndent4 .SDescription { padding-left: 8.0ex } .SIndent5 .SEntry { padding-left: 7.5ex } .SIndent5 .SDescription { padding-left: 9.5ex } .SDescription a { color: #800000} .SDescription a:active { color: #A00000 } .SGroup td { padding-top: .5em; padding-bottom: .25em } .SGroup .SEntry { font-weight: bold; font-variant: small-caps } .SGroup .SEntry a { color: #800000 } .SGroup .SEntry a:active { color: #F00000 } .SMain td, .SClass td, .SDatabase td, .SDatabaseTable td, .SSection td { font-size: 10pt; padding-bottom: .25em } .SClass td, .SDatabase td, .SDatabaseTable td, .SSection td { padding-top: 1em } .SMain .SEntry, .SClass .SEntry, .SDatabase .SEntry, .SDatabaseTable .SEntry, .SSection .SEntry { font-weight: bold; } .SMain .SEntry a, .SClass .SEntry a, .SDatabase .SEntry a, .SDatabaseTable .SEntry a, .SSection .SEntry a { color: #000000 } .SMain .SEntry a:active, .SClass .SEntry a:active, .SDatabase .SEntry a:active, .SDatabaseTable .SEntry a:active, .SSection .SEntry a:active { color: #A00000 } .ClassHierarchy { margin: 0 15px 1em 15px } .CHEntry { border-width: 1px 2px 2px 1px; border-style: solid; border-color: #A0A0A0; margin-bottom: 3px; padding: 2px 2ex; font-size: 10pt; background-color: #F4F4F4; color: #606060; } .Firefox .CHEntry { -moz-border-radius: 4px; } .CHCurrent .CHEntry { font-weight: bold; border-color: #000000; color: #000000; } .CHChildNote .CHEntry { font-style: italic; font-size: 8pt; } .CHIndent { margin-left: 3ex; } .CHEntry a:link, .CHEntry a:visited, .CHEntry a:hover { color: #606060; } .CHEntry a:active { color: #800000; } #Index { background-color: #FFFFFF; } /* As opposed to .PopupSearchResultsPage #Index */ .IndexPage #Index, .FramedIndexPage #Index, .FramedSearchResultsPage #Index { padding: 15px; } .IndexPage #Index { border-width: 0 0 1px 1px; border-style: solid; border-color: #000000; font-size: 9pt; /* To make 27ex match the menu's 27ex. */ margin-left: 27ex; } .IPageTitle { font-size: 20pt; font-weight: bold; color: #FFFFFF; background-color: #7070C0; padding: 10px 15px 10px 15px; border-width: 0 0 3px 0; border-color: #000000; border-style: solid; margin: -15px -15px 0 -15px } .FramedSearchResultsPage .IPageTitle { margin-bottom: 15px; } .INavigationBar { font-size: 10pt; text-align: center; background-color: #FFFFF0; padding: 5px; border-bottom: solid 1px black; margin: 0 -15px 15px -15px; } .INavigationBar a { font-weight: bold } .IHeading { font-size: 16pt; font-weight: bold; padding: 2.5em 0 .5em 0; text-align: center; width: 3.5ex; } #IFirstHeading { padding-top: 0; } .IEntry { font-size: 10pt; padding-left: 1ex; } .PopupSearchResultsPage .IEntry { font-size: 8pt; padding: 1px 5px; } .PopupSearchResultsPage .Opera9 .IEntry, .FramedSearchResultsPage .Opera9 .IEntry { text-align: left; } .FramedSearchResultsPage .IEntry { padding: 0; } .ISubIndex { padding-left: 3ex; padding-bottom: .5em } .PopupSearchResultsPage .ISubIndex { display: none; } /* While it may cause some entries to look like links when they aren't, I found it's much easier to read the index if everything's the same color. */ .ISymbol { font-weight: bold; color: #900000 } .IndexPage .ISymbolPrefix, .FramedIndexPage .ISymbolPrefix { font-size: 10pt; text-align: right; color: #C47C7C; background-color: #F8F8F8; border-right: 3px solid #E0E0E0; border-left: 1px solid #E0E0E0; padding: 0 1px 0 2px; } .PopupSearchResultsPage .ISymbolPrefix, .FramedSearchResultsPage .ISymbolPrefix { color: #900000; } .PopupSearchResultsPage .ISymbolPrefix { font-size: 8pt; } .IndexPage #IFirstSymbolPrefix, .FramedIndexPage #IFirstSymbolPrefix { border-top: 1px solid #E0E0E0; } .IndexPage #ILastSymbolPrefix, .FramedIndexPage #ILastSymbolPrefix { border-bottom: 1px solid #E0E0E0; } .IndexPage #IOnlySymbolPrefix, .FramedIndexPage #IOnlySymbolPrefix { border-top: 1px solid #E0E0E0; border-bottom: 1px solid #E0E0E0; } a.IParent, a.IFile { display: block; } .PopupSearchResultsPage .SRStatus { padding: 2px 5px; font-size: 8pt; font-style: italic; } .FramedSearchResultsPage .SRStatus { font-size: 10pt; font-style: italic; } .SRResult { display: none; } #Footer { font-size: 8pt; color: #989898; text-align: right; } #Footer p { text-indent: 0; margin-bottom: .5em; } .ContentPage #Footer, .IndexPage #Footer { text-align: right; margin: 2px; } .FramedMenuPage #Footer { text-align: center; margin: 5em 10px 10px 10px; padding-top: 1em; border-top: 1px solid #C8C8C8; } #Footer a:link, #Footer a:hover, #Footer a:visited { color: #989898 } #Footer a:active { color: #A00000 } strophejs-1.0.1.dfsg/examples/000077500000000000000000000000001137577172600163125ustar00rootroot00000000000000strophejs-1.0.1.dfsg/examples/attach/000077500000000000000000000000001137577172600175565ustar00rootroot00000000000000strophejs-1.0.1.dfsg/examples/attach/README000066400000000000000000000023171137577172600204410ustar00rootroot00000000000000This is an example of Strophe attaching to a pre-existing BOSH session that is created externally. This example requires a bit more than HTML and JavaScript. Specifically it contains a very simple Web application written in Django which creates a BOSH session before rendering the page. Requirements: * Django 1.0 (http://www.djangoproject.com) * Twisted 8.1.x (http://twistedmatrix.com) * Punjab 0.3 (http://code.stanziq.com/punjab) Note that Twisted and Punjab are only used for small functions related to JID and BOSH parsing. How It Works: The Django app contains one view which is tied to the root URL. This view uses the BOSHClient class to start a BOSH session using the settings from settings.py. Once the connection is established, Django passes the JID, SID, and RID for the BOSH session into the template engine and renders the page. The template assigns the JID, SID, and RID to global vars like so: var BOSH_JID = {{ jid }}; var BOSH_SID = {{ sid }}; var BOSH_RID = {{ rid }}; The connection is attached to Strophe by calling Strophe.Connection.attach() with this data and a connection callback handler. To show that the session is attached and works, a disco info ping is done to jabber.org. strophejs-1.0.1.dfsg/examples/attach/__init__.py000066400000000000000000000000001137577172600216550ustar00rootroot00000000000000strophejs-1.0.1.dfsg/examples/attach/attacher/000077500000000000000000000000001137577172600213515ustar00rootroot00000000000000strophejs-1.0.1.dfsg/examples/attach/attacher/__init__.py000066400000000000000000000000001137577172600234500ustar00rootroot00000000000000strophejs-1.0.1.dfsg/examples/attach/attacher/views.py000066400000000000000000000007331137577172600230630ustar00rootroot00000000000000from django.http import HttpResponse from django.template import Context, loader from attach.settings import BOSH_SERVICE, JABBERID, PASSWORD from attach.boshclient import BOSHClient def index(request): bc = BOSHClient(JABBERID, PASSWORD, BOSH_SERVICE) bc.startSessionAndAuth() t = loader.get_template("attacher/index.html") c = Context({ 'jid': bc.jabberid.full(), 'sid': bc.sid, 'rid': bc.rid, }) return HttpResponse(t.render(c)) strophejs-1.0.1.dfsg/examples/attach/boshclient.py000066400000000000000000000117541137577172600222720ustar00rootroot00000000000000import sys, os import httplib, urllib import random, binascii from urlparse import urlparse from punjab.httpb import HttpbParse from twisted.words.xish import domish from twisted.words.protocols.jabber import jid TLS_XMLNS = 'urn:ietf:params:xml:ns:xmpp-tls' SASL_XMLNS = 'urn:ietf:params:xml:ns:xmpp-sasl' BIND_XMLNS = 'urn:ietf:params:xml:ns:xmpp-bind' SESSION_XMLNS = 'urn:ietf:params:xml:ns:xmpp-session' class BOSHClient: def __init__(self, jabberid, password, bosh_service): self.rid = random.randint(0, 10000000) self.jabberid = jid.internJID(jabberid) self.password = password self.authid = None self.sid = None self.logged_in = False self.headers = {"Content-type": "text/xml", "Accept": "text/xml"} self.bosh_service = urlparse(bosh_service) def buildBody(self, child=None): """Build a BOSH body. """ body = domish.Element(("http://jabber.org/protocol/httpbind", "body")) body['content'] = 'text/xml; charset=utf-8' self.rid = self.rid + 1 body['rid'] = str(self.rid) body['sid'] = str(self.sid) body['xml:lang'] = 'en' if child is not None: body.addChild(child) return body def sendBody(self, body): """Send the body. """ parser = HttpbParse(True) # start new session conn = httplib.HTTPConnection(self.bosh_service.netloc) conn.request("POST", self.bosh_service.path, body.toXml(), self.headers) response = conn.getresponse() data = '' if response.status == 200: data = response.read() conn.close() return parser.parse(data) def startSessionAndAuth(self, hold='1', wait='70'): # Create a session # create body body = domish.Element(("http://jabber.org/protocol/httpbind", "body")) body['content'] = 'text/xml; charset=utf-8' body['hold'] = hold body['rid'] = str(self.rid) body['to'] = self.jabberid.host body['wait'] = wait body['window'] = '5' body['xml:lang'] = 'en' retb, elems = self.sendBody(body) if type(retb) != str and retb.hasAttribute('authid') and \ retb.hasAttribute('sid'): self.authid = retb['authid'] self.sid = retb['sid'] # go ahead and auth auth = domish.Element((SASL_XMLNS, 'auth')) auth['mechanism'] = 'PLAIN' # TODO: add authzid if auth['mechanism'] == 'PLAIN': auth_str = "" auth_str += "\000" auth_str += self.jabberid.user.encode('utf-8') auth_str += "\000" try: auth_str += self.password.encode('utf-8').strip() except UnicodeDecodeError: auth_str += self.password.decode('latin1') \ .encode('utf-8').strip() auth.addContent(binascii.b2a_base64(auth_str)) retb, elems = self.sendBody(self.buildBody(auth)) if len(elems) == 0: # poll for data retb, elems = self.sendBody(self.buildBody()) if len(elems) > 0: if elems[0].name == 'success': retb, elems = self.sendBody(self.buildBody()) if elems[0].firstChildElement().name == 'bind': iq = domish.Element(('jabber:client', 'iq')) iq['type'] = 'set' iq.addUniqueId() iq.addElement('bind') iq.bind['xmlns'] = BIND_XMLNS if self.jabberid.resource: iq.bind.addElement('resource') iq.bind.resource.addContent( self.jabberid.resource) retb, elems = self.sendBody(self.buildBody(iq)) if type(retb) != str and retb.name == 'body': # send session iq = domish.Element(('jabber:client', 'iq')) iq['type'] = 'set' iq.addUniqueId() iq.addElement('session') iq.session['xmlns'] = SESSION_XMLNS retb, elems = self.sendBody(self.buildBody(iq)) # did not bind, TODO - add a retry? if type(retb) != str and retb.name == 'body': self.logged_in = True # bump up the rid, punjab already # received self.rid self.rid += 1 if __name__ == '__main__': USERNAME = sys.argv[1] PASSWORD = sys.argv[2] SERVICE = sys.argv[3] c = BOSHClient(USERNAME, PASSWORD, SERVICE) c.startSessionAndAuth() print c.logged_in strophejs-1.0.1.dfsg/examples/attach/manage.py000077500000000000000000000010421137577172600213600ustar00rootroot00000000000000#!/usr/bin/env python from django.core.management import execute_manager try: import settings # Assumed to be in the same directory. except ImportError: import sys sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__) sys.exit(1) if __name__ == "__main__": execute_manager(settings) strophejs-1.0.1.dfsg/examples/attach/settings.py000066400000000000000000000055441137577172600220000ustar00rootroot00000000000000# Django settings for attach project. DEBUG = True TEMPLATE_DEBUG = DEBUG ADMINS = ( ('Some Body', 'romeo@example.com'), ) MANAGERS = ADMINS DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. DATABASE_NAME = '/path/to/attach.db' # Or path to database file if using sqlite3. DATABASE_USER = '' # Not used with sqlite3. DATABASE_PASSWORD = '' # Not used with sqlite3. DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3. DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3. # Local time zone for this installation. Choices can be found here: # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name # although not all choices may be available on all operating systems. # If running in a Windows environment this must be set to the same as your # system time zone. TIME_ZONE = 'America/Denver' # Language code for this installation. All choices can be found here: # http://www.i18nguy.com/unicode/language-identifiers.html LANGUAGE_CODE = 'en-us' SITE_ID = 1 # If you set this to False, Django will make some optimizations so as not # to load the internationalization machinery. USE_I18N = True # Absolute path to the directory that holds media. # Example: "/home/media/media.lawrence.com/" MEDIA_ROOT = '' # URL that handles the media served from MEDIA_ROOT. Make sure to use a # trailing slash if there is a path component (optional in other cases). # Examples: "http://media.lawrence.com", "http://example.com/media/" MEDIA_URL = '' # URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a # trailing slash. # Examples: "http://foo.com/media/", "/media/". ADMIN_MEDIA_PREFIX = '/media/' # Make this unique, and don't share it with anybody. SECRET_KEY = 'asdf' # List of callables that know how to import templates from various sources. TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.load_template_source', 'django.template.loaders.app_directories.load_template_source', # 'django.template.loaders.eggs.load_template_source', ) MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', ) ROOT_URLCONF = 'attach.urls' TEMPLATE_DIRS = ( # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. '/path/to/attach/templates', ) INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'attach.attacher', ) BOSH_SERVICE = 'http://example.com/xmpp-httpbind' JABBERID = 'romeo@example.com/bosh' PASSWORD = 'juliet.is.hawt' strophejs-1.0.1.dfsg/examples/attach/templates/000077500000000000000000000000001137577172600215545ustar00rootroot00000000000000strophejs-1.0.1.dfsg/examples/attach/templates/attacher/000077500000000000000000000000001137577172600233475ustar00rootroot00000000000000strophejs-1.0.1.dfsg/examples/attach/templates/attacher/index.html000066400000000000000000000054421137577172600253510ustar00rootroot00000000000000 Strophe Attach Example

Strophe Attach Example

This example shows how to attach to an existing BOSH session with Strophe.

Log

strophejs-1.0.1.dfsg/examples/attach/urls.py000066400000000000000000000011061137577172600211130ustar00rootroot00000000000000from django.conf.urls.defaults import * # Uncomment the next two lines to enable the admin: # from django.contrib import admin # admin.autodiscover() urlpatterns = patterns('', # Example: # (r'^attach/', include('attach.foo.urls')), # Uncomment the admin/doc line below and add 'django.contrib.admindocs' # to INSTALLED_APPS to enable admin documentation: # (r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: # (r'^admin/(.*)', admin.site.root), (r'^$', 'attach.attacher.views.index'), ) strophejs-1.0.1.dfsg/examples/basic.html000066400000000000000000000014571137577172600202700ustar00rootroot00000000000000 Strophe.js Basic Example

strophejs-1.0.1.dfsg/examples/basic.js000066400000000000000000000025071137577172600177350ustar00rootroot00000000000000var BOSH_SERVICE = '/xmpp-httpbind' var connection = null; function log(msg) { $('#log').append('
').append(document.createTextNode(msg)); } function rawInput(data) { log('RECV: ' + data); } function rawOutput(data) { log('SENT: ' + data); } function onConnect(status) { if (status == Strophe.Status.CONNECTING) { log('Strophe is connecting.'); } else if (status == Strophe.Status.CONNFAIL) { log('Strophe failed to connect.'); $('#connect').get(0).value = 'connect'; } else if (status == Strophe.Status.DISCONNECTING) { log('Strophe is disconnecting.'); } else if (status == Strophe.Status.DISCONNECTED) { log('Strophe is disconnected.'); $('#connect').get(0).value = 'connect'; } else if (status == Strophe.Status.CONNECTED) { log('Strophe is connected.'); connection.disconnect(); } } $(document).ready(function () { connection = new Strophe.Connection(BOSH_SERVICE); connection.rawInput = rawInput; connection.rawOutput = rawOutput; $('#connect').bind('click', function () { var button = $('#connect').get(0); if (button.value == 'connect') { button.value = 'disconnect'; connection.connect($('#jid').get(0).value, $('#pass').get(0).value, onConnect); } else { button.value = 'connect'; connection.disconnect(); } }); });strophejs-1.0.1.dfsg/examples/crossdomain.html000066400000000000000000000020041137577172600215150ustar00rootroot00000000000000 Strophe.js Basic Cross-Domain Example

strophejs-1.0.1.dfsg/examples/crossdomain.js000066400000000000000000000032611137577172600211730ustar00rootroot00000000000000// The BOSH_SERVICE here doesn't need to be on the same domain/port, but // it must have a /crossdomain.xml policy file that allows access from // wherever crossdomain.html lives. // // Most BOSH connection managers can serve static html files, so you should // be able to configure them to serve a /crossdomain.xml file to allow // access. var BOSH_SERVICE = 'http://localhost:5281/xmpp-httpbind' var connection = null; function log(msg) { $('#log').append('
').append(document.createTextNode(msg)); } function rawInput(data) { log('RECV: ' + data); } function rawOutput(data) { log('SENT: ' + data); } function onConnect(status) { if (status == Strophe.Status.CONNECTING) { log('Strophe is connecting.'); } else if (status == Strophe.Status.CONNFAIL) { log('Strophe failed to connect.'); $('#connect').get(0).value = 'connect'; } else if (status == Strophe.Status.DISCONNECTING) { log('Strophe is disconnecting.'); } else if (status == Strophe.Status.DISCONNECTED) { log('Strophe is disconnected.'); $('#connect').get(0).value = 'connect'; } else if (status == Strophe.Status.CONNECTED) { log('Strophe is connected.'); connection.disconnect(); } } $(document).ready(function () { connection = new Strophe.Connection(BOSH_SERVICE); connection.rawInput = rawInput; connection.rawOutput = rawOutput; $('#connect').bind('click', function () { var button = $('#connect').get(0); if (button.value == 'connect') { button.value = 'disconnect'; connection.connect($('#jid').get(0).value, $('#pass').get(0).value, onConnect); } else { button.value = 'connect'; connection.disconnect(); } }); });strophejs-1.0.1.dfsg/examples/crossdomain.xml000066400000000000000000000010121137577172600213470ustar00rootroot00000000000000 strophejs-1.0.1.dfsg/examples/dojo-ping.html000066400000000000000000000012401137577172600210630ustar00rootroot00000000000000 Strophe.js Dojo Ping Example

strophejs-1.0.1.dfsg/examples/dojo-ping.js000066400000000000000000000035041137577172600205400ustar00rootroot00000000000000var DojoPing = { BOSH_SERVICE: '/xmpp-httpbind', TARGET: 'jabber.org', connection: null }; dojo.addOnLoad(function () { dojo.connect(dojo.byId('connect'), "click", function (e) { var jid = dojo.attr(dojo.byId('jid'), 'value'); var pass_node = dojo.byId('pass'); var pass = dojo.attr(pass_node, 'value'); dojo.attr(pass_node, 'value', ''); DojoPing.connection = new Strophe.Connection(DojoPing.BOSH_SERVICE); dojo.place("

Connecting...

", "log"); DojoPing.connection.connect(jid, pass, function (status) { if (status === Strophe.Status.CONNECTED) { dojo.publish('connected'); } else if (status === Strophe.Status.DISCONNECTED) { dojo.publish('disconnected'); } }); }); dojo.subscribe('connected', function () { dojo.place("

Connected.

", "log"); var ping = $iq({to: DojoPing.TARGET, type: 'get'}) .c('query', {xmlns: Strophe.NS.DISCO_ITEMS}); var sent_stamp = new Date(); DojoPing.connection.sendIQ(ping, function (iq) { var elapsed = new Date() - sent_stamp; // use dojo.query on incoming stanza var items = dojo.query('items', iq); console.log(items); dojo.place("

Disco#items response received after " + elapsed + "ms." + DojoPing.TARGET + " reports " + "it has " + items + " disco items.

", "log"); DojoPing.connection.disconnect(); }); DojoPing.connection.send(ping); dojo.place("

Ping sent to " + DojoPing.TARGET + ".

", "log"); }); dojo.subscribe('disconnected', function () { dojo.place("

Disconnected.

", "log"); }); });strophejs-1.0.1.dfsg/examples/echobot.html000066400000000000000000000014631137577172600206270ustar00rootroot00000000000000 Strophe.js Echobot Example

strophejs-1.0.1.dfsg/examples/echobot.js000066400000000000000000000044751137577172600203050ustar00rootroot00000000000000var BOSH_SERVICE = '/xmpp-httpbind'; var connection = null; function log(msg) { $('#log').append('
').append(document.createTextNode(msg)); } function onConnect(status) { if (status == Strophe.Status.CONNECTING) { log('Strophe is connecting.'); } else if (status == Strophe.Status.CONNFAIL) { log('Strophe failed to connect.'); $('#connect').get(0).value = 'connect'; } else if (status == Strophe.Status.DISCONNECTING) { log('Strophe is disconnecting.'); } else if (status == Strophe.Status.DISCONNECTED) { log('Strophe is disconnected.'); $('#connect').get(0).value = 'connect'; } else if (status == Strophe.Status.CONNECTED) { log('Strophe is connected.'); log('ECHOBOT: Send a message to ' + connection.jid + ' to talk to me.'); connection.addHandler(onMessage, null, 'message', null, null, null); connection.send($pres().tree()); } } function onMessage(msg) { var to = msg.getAttribute('to'); var from = msg.getAttribute('from'); var type = msg.getAttribute('type'); var elems = msg.getElementsByTagName('body'); if (type == "chat" && elems.length > 0) { var body = elems[0]; log('ECHOBOT: I got a message from ' + from + ': ' + Strophe.getText(body)); var reply = $msg({to: from, from: to, type: 'chat'}) .cnode(Strophe.copyElement(body)); connection.send(reply.tree()); log('ECHOBOT: I sent ' + from + ': ' + Strophe.getText(body)); } // we must return true to keep the handler alive. // returning false would remove it after it finishes. return true; } $(document).ready(function () { connection = new Strophe.Connection(BOSH_SERVICE); // Uncomment the following lines to spy on the wire traffic. //connection.rawInput = function (data) { log('RECV: ' + data); }; //connection.rawOutput = function (data) { log('SEND: ' + data); }; // Uncomment the following line to see all the debug output. //Strophe.log = function (level, msg) { log('LOG: ' + msg); }; $('#connect').bind('click', function () { var button = $('#connect').get(0); if (button.value == 'connect') { button.value = 'disconnect'; connection.connect($('#jid').get(0).value, $('#pass').get(0).value, onConnect); } else { button.value = 'connect'; connection.disconnect(); } }); }); strophejs-1.0.1.dfsg/examples/prebind.html000066400000000000000000000021121137577172600206170ustar00rootroot00000000000000 Strophe.js Pre-Bind Example

strophejs-1.0.1.dfsg/examples/prebind.js000066400000000000000000000057151137577172600203030ustar00rootroot00000000000000// http-pre-bind example // This example works with mod_http_pre_bind found here: // http://github.com/thepug/Mod-Http-Pre-Bind // // It expects both /xmpp-httpbind to be proxied and /http-pre-bind // // If you want to test this out without setting it up, you can use Collecta's // at http://www.collecta.com/xmpp-httpbind and // http://www.collecta.com/http-pre-bind // Use a JID of 'guest.collecta.com' to test. var BOSH_SERVICE = '/xmpp-httpbind'; var PREBIND_SERVICE = '/http-pre-bind'; var connection = null; function log(msg) { $('#log').append('
').append(document.createTextNode(msg)); } function rawInput(data) { log('RECV: ' + data); } function rawOutput(data) { log('SENT: ' + data); } function onConnect(status) { if (status === Strophe.Status.CONNECTING) { log('Strophe is connecting.'); } else if (status === Strophe.Status.CONNFAIL) { log('Strophe failed to connect.'); $('#connect').get(0).value = 'connect'; } else if (status === Strophe.Status.DISCONNECTING) { log('Strophe is disconnecting.'); } else if (status === Strophe.Status.DISCONNECTED) { log('Strophe is disconnected.'); $('#connect').get(0).value = 'connect'; } else if (status === Strophe.Status.CONNECTED) { log('Strophe is connected.'); connection.disconnect(); } else if (status === Strophe.Status.ATTACHED) { log('Strophe is attached.'); connection.disconnect(); } } function normal_connect() { log('Prebind failed. Connecting normally...'); connection = new Strophe.Connection(BOSH_SERVICE); connection.rawInput = rawInput; connection.rawOutput = rawOutput; connection.connect($('#jid').val(), $('#pass').val(), onConnect); } function attach(data) { log('Prebind succeeded. Attaching...'); connection = new Strophe.Connection(BOSH_SERVICE); connection.rawInput = rawInput; connection.rawOutput = rawOutput; var $body = $(data.documentElement); connection.attach($body.find('jid').text(), $body.attr('sid'), parseInt($body.attr('rid'), 10) + 1, onConnect); } $(document).ready(function () { $('#connect').bind('click', function () { var button = $('#connect').get(0); if (button.value == 'connect') { button.value = 'disconnect'; // attempt prebind $.ajax({ type: 'POST', url: PREBIND_SERVICE, contentType: 'text/xml', processData: false, data: $build('body', { to: Strophe.getDomainFromJid($('#jid').val()), rid: '' + Math.floor(Math.random() * 4294967295), wait: '60', hold: '1'}).toString(), dataType: 'xml', error: normal_connect, success: attach}); } else { button.value = 'connect'; if (connection) { connection.disconnect(); } } }); });strophejs-1.0.1.dfsg/examples/prototype-ping.html000066400000000000000000000012601137577172600221770ustar00rootroot00000000000000 Strophe.js Prototype Ping Example

strophejs-1.0.1.dfsg/examples/prototype-ping.js000066400000000000000000000034101137577172600216460ustar00rootroot00000000000000var ProtoPing = { BOSH_SERVICE: '/xmpp-httpbind', TARGET: 'jabber.org', connection: null }; document.observe('dom:loaded', function () { var log = $('log'); $('connect').observe('click', function () { var jid = $F('jid'); var pass = $F('pass'); Form.Element.setValue('pass', ''); ProtoPing.connection = new Strophe.Connection(ProtoPing.BOSH_SERVICE); log.insert("

Connecting...

"); ProtoPing.connection.connect(jid, pass, function (status) { if (status === Strophe.Status.CONNECTED) { document.fire('strophe:connected'); } else if (status === Strophe.Status.DISCONNECTED) { document.fire('strophe:disconnected'); } }); }); document.observe('strophe:connected', function () { log.insert('

Connected.

'); var ping = $iq({to: ProtoPing.TARGET, type: 'get'}) .c('query', {xmlns: Strophe.NS.DISCO_ITEMS}); var sent_stamp = new Date(); ProtoPing.connection.sendIQ(ping, function (iq) { var elapsed = new Date() - sent_stamp; // use Prototype's selectors to access XMPP stanza var items = Selector.findChildElements(iq, ['item']); log.insert("

Disco#items response received after " + elapsed + "ms." + ProtoPing.TARGET + " reports " + "it has " + items + " disco items.

"); ProtoPing.connection.disconnect(); }); ProtoPing.connection.send(ping); log.insert("

Ping sent to " + ProtoPing.TARGET + ".

"); }); document.observe('strophe:disconnected', function () { log.insert('

Disconnected.

'); }); });strophejs-1.0.1.dfsg/examples/yui-ping.html000066400000000000000000000012241137577172600207400ustar00rootroot00000000000000 Strophe.js YUI3 Ping Example

strophejs-1.0.1.dfsg/examples/yui-ping.js000066400000000000000000000034751137577172600204220ustar00rootroot00000000000000YUI().use('node', function (Y) { var BOSH_SERVICE = '/xmpp-httpbind'; var connection = null; var log = Y.one('#log'); Y.augment(Strophe.Connection, Y.EventTarget); Y.one('#connect').on('click', function (e) { var jid = Y.one('#jid').get('value'); var pass_node = Y.one('#pass'); var pass = pass_node.get('value'); pass_node.set('value', ''); connection = new Strophe.Connection(BOSH_SERVICE); log.append('

Connecting...

'); connection.connect(jid, pass, function (status) { if (status === Strophe.Status.CONNECTED) { connection.fire('connected'); } else if (status === Strophe.Status.DISCONNECTED) { connection.fire('disconnected'); } }); connection.on('connected', function () { log.append('

Connected.

'); var ping = $iq({to: 'jabber.org', type: 'get'}) .c('query', {xmlns: Strophe.NS.DISCO_ITEMS}); var sent_stamp = new Date(); connection.sendIQ(ping, function (iq) { var elapsed = new Date() - sent_stamp; // convert incoming XMPP stanza to a Node var stanza = Y.Selector.query('item', iq, null, true); window['stanza'] = iq; window['Y'] = Y; console.log(stanza); log.append("

Disco#items response received after " + elapsed + "ms. Jabber.org reports it has " + items + " items.

"); connection.disconnect(); }); log.append('

Ping sent.

'); }); connection.on('disconnected', function () { log.append('

Disconnected.

'); }); }); });strophejs-1.0.1.dfsg/plugins/000077500000000000000000000000001137577172600161555ustar00rootroot00000000000000strophejs-1.0.1.dfsg/plugins/strophe.flxhr.js000066400000000000000000000017751137577172600213330ustar00rootroot00000000000000/* flXHR plugin ** ** This plugin implements cross-domain XmlHttpRequests via an invisible ** Flash plugin. ** ** In order for this to work, the BOSH service *must* serve a ** crossdomain.xml file that allows the client access. ** ** flXHR.js should be loaded before this plugin. */ Strophe.addConnectionPlugin('flxhr', { init: function () { // replace Strophe.Request._newXHR with new flXHR version // if flXHR is detected if (flensed && flensed.flXHR) { Strophe.Request.prototype._newXHR = function () { var xhr = new flensed.flXHR({ autoUpdatePlayer: true, instancePooling: true, noCacheHeader: false}); xhr.onreadystatechange = this.func.prependArg(this); return xhr; }; } else { Strophe.error("flXHR plugin loaded, but flXHR not found." + " Falling back to native XHR implementation."); } } }); strophejs-1.0.1.dfsg/plugins/strophe.pubsub.js000066400000000000000000000170561137577172600215070ustar00rootroot00000000000000/* Copyright 2008, Stanziq Inc. */ Strophe.addConnectionPlugin('pubsub', { /* Extend connection object to have plugin name 'pubsub'. */ _connection: null, //The plugin must have the init function. init: function(conn) { this._connection = conn; /* Function used to setup plugin. */ /* extend name space * NS.PUBSUB - XMPP Publish Subscribe namespace * from XEP 60. * * NS.PUBSUB_SUBSCRIBE_OPTIONS - XMPP pubsub * options namespace from XEP 60. */ Strophe.addNamespace('PUBSUB',"http://jabber.org/protocol/pubsub"); Strophe.addNamespace('PUBSUB_SUBSCRIBE_OPTIONS', Strophe.NS.PUBSUB+"#subscribe_options"); Strophe.addNamespace('PUBSUB_ERRORS',Strophe.NS.PUBSUB+"#errors"); Strophe.addNamespace('PUBSUB_EVENT',Strophe.NS.PUBSUB+"#event"); Strophe.addNamespace('PUBSUB_OWNER',Strophe.NS.PUBSUB+"#owner"); Strophe.addNamespace('PUBSUB_AUTO_CREATE', Strophe.NS.PUBSUB+"#auto-create"); Strophe.addNamespace('PUBSUB_PUBLISH_OPTIONS', Strophe.NS.PUBSUB+"#publish-options"); Strophe.addNamespace('PUBSUB_NODE_CONFIG', Strophe.NS.PUBSUB+"#node_config"); Strophe.addNamespace('PUBSUB_CREATE_AND_CONFIGURE', Strophe.NS.PUBSUB+"#create-and-configure"); Strophe.addNamespace('PUBSUB_SUBSCRIBE_AUTHORIZATION', Strophe.NS.PUBSUB+"#subscribe_authorization"); Strophe.addNamespace('PUBSUB_GET_PENDING', Strophe.NS.PUBSUB+"#get-pending"); Strophe.addNamespace('PUBSUB_MANAGE_SUBSCRIPTIONS', Strophe.NS.PUBSUB+"#manage-subscriptions"); Strophe.addNamespace('PUBSUB_META_DATA', Strophe.NS.PUBSUB+"#meta-data"); }, /***Function Create a pubsub node on the given service with the given node name. Parameters: (String) jid - The node owner's jid. (String) service - The name of the pubsub service. (String) node - The name of the pubsub node. (Dictionary) options - The configuration options for the node. (Function) call_back - Used to determine if node creation was sucessful. Returns: Iq id used to send subscription. */ createNode: function(jid,service,node,options, call_back) { var iqid = this._connection.getUniqueId("pubsubcreatenode"); var iq = $iq({from:jid, to:service, type:'set', id:iqid}); var c_options = Strophe.xmlElement("configure",[]); var x = Strophe.xmlElement("x",[["xmlns","jabber:x:data"]]); var form_field = Strophe.xmlElement("field",[["var","FORM_TYPE"], ["type","hidden"]]); var value = Strophe.xmlElement("value",[]); var text = Strophe.xmlTextNode(Strophe.NS.PUBSUB+"#node_config"); value.appendChild(text); form_field.appendChild(value); x.appendChild(form_field); for (var i in options) { var val = options[i]; x.appendChild(val); } if(options.length && options.length != 0) { c_options.appendChild(x); } iq.c('pubsub', {xmlns:Strophe.NS.PUBSUB}).c('create', {node:node}).up().cnode(c_options); this._connection.addHandler(call_back, null, 'iq', null, iqid, null); this._connection.send(iq.tree()); return iqid; }, /***Function Subscribe to a node in order to receive event items. Parameters: (String) jid - The node owner's jid. (String) service - The name of the pubsub service. (String) node - The name of the pubsub node. (Array) options - The configuration options for the node. (Function) event_cb - Used to recieve subscription events. (Function) call_back - Used to determine if node creation was sucessful. Returns: Iq id used to send subscription. */ subscribe: function(jid,service,node,options, event_cb, call_back) { var subid = this._connection.getUniqueId("subscribenode"); //create subscription options var sub_options = Strophe.xmlElement("options",[]); var x = Strophe.xmlElement("x",[["xmlns","jabber:x:data"]]); var form_field = Strophe.xmlElement("field",[["var","FORM_TYPE"], ["type","hidden"]]); var value = Strophe.xmlElement("value",[]); var text = Strophe.xmlTextNode(Strophe.NS.PUBSUB_SUBSCRIBE_OPTIONS); value.appendChild(text); form_field.appendChild(value); x.appendChild(form_field); var sub = $iq({from:jid, to:service, type:'set', id:subid}) if(options && options.length && options.length !== 0) { for (var i = 0; i < options.length; i++) { var val = options[i]; x.appendChild(val); } sub_options.appendChild(x); sub.c('pubsub', { xmlns:Strophe.NS.PUBSUB }).c('subscribe', {node:node,jid:jid}).up().cnode(sub_options); } else { sub.c('pubsub', { xmlns:Strophe.NS.PUBSUB }).c('subscribe', {node:node,jid:jid}); } this._connection.addHandler(call_back, null, 'iq', null, subid, null); //add the event handler to receive items this._connection.addHandler(event_cb, null, 'message', null, null, null); this._connection.send(sub.tree()); return subid; }, /***Function Unsubscribe from a node. Parameters: (String) jid - The node owner's jid. (String) service - The name of the pubsub service. (String) node - The name of the pubsub node. (Function) call_back - Used to determine if node creation was sucessful. */ unsubscribe: function(jid,service,node, call_back) { var subid = this._connection.getUniqueId("unsubscribenode"); var sub = $iq({from:jid, to:service, type:'set', id:subid}) sub.c('pubsub', { xmlns:Strophe.NS.PUBSUB }).c('unsubscribe', {node:node,jid:jid}); this._connection.addHandler(call_back, null, 'iq', null, subid, null); this._connection.send(sub.tree()); return subid; }, /***Function Publish and item to the given pubsub node. Parameters: (String) jid - The node owner's jid. (String) service - The name of the pubsub service. (String) node - The name of the pubsub node. (Array) items - The list of items to be published. (Function) call_back - Used to determine if node creation was sucessful. */ publish: function(jid, service, node, items, call_back) { var pubid = this._connection.getUniqueId("publishnode"); var publish_elem = Strophe.xmlElement("publish", [["node", node], ["jid", jid]]); for (var i in items) { var item = Strophe.xmlElement("item",[]); var entry = Strophe.xmlElement("entry",[]); var t = Strophe.xmlTextNode(items[i]); entry.appendChild(t); item.appendChild(entry); publish_elem.appendChild(item); } var pub = $iq({from:jid, to:service, type:'set', id:pubid}) pub.c('pubsub', { xmlns:Strophe.NS.PUBSUB }).cnode(publish_elem); this._connection.addHandler(call_back, null, 'iq', null, pubid, null); this._connection.send(pub.tree()); return pubid; }, /*Function: items Used to retrieve the persistent items from the pubsub node. */ items: function(jid,service,node,ok_callback,error_back) { var pub = $iq({from:jid, to:service, type:'get'}) //ask for all items pub.c('pubsub', { xmlns:Strophe.NS.PUBSUB }).c('items',{node:node}); return this._connection.sendIQ(pub.tree(),ok_callback,error_back); } }); strophejs-1.0.1.dfsg/strophe.js000066400000000000000000003464401137577172600165310ustar00rootroot00000000000000// This code was written by Tyler Akins and has been placed in the // public domain. It would be nice if you left this header intact. // Base64 code from Tyler Akins -- http://rumkin.com var Base64 = (function () { var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; var obj = { /** * Encodes a string in base64 * @param {String} input The string to encode in base64. */ encode: function (input) { var output = ""; var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; do { chr1 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++); chr3 = input.charCodeAt(i++); enc1 = chr1 >> 2; enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); enc4 = chr3 & 63; if (isNaN(chr2)) { enc3 = enc4 = 64; } else if (isNaN(chr3)) { enc4 = 64; } output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4); } while (i < input.length); return output; }, /** * Decodes a base64 string. * @param {String} input The string to decode. */ decode: function (input) { var output = ""; var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; // remove all characters that are not A-Z, a-z, 0-9, +, /, or = input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); do { enc1 = keyStr.indexOf(input.charAt(i++)); enc2 = keyStr.indexOf(input.charAt(i++)); enc3 = keyStr.indexOf(input.charAt(i++)); enc4 = keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; output = output + String.fromCharCode(chr1); if (enc3 != 64) { output = output + String.fromCharCode(chr2); } if (enc4 != 64) { output = output + String.fromCharCode(chr3); } } while (i < input.length); return output; } }; return obj; })(); /* * 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. */ var MD5 = (function () { /* * 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 */ /* * Add integers, wrapping at 2^32. This uses 16-bit operations internally * to work around bugs in some JS interpreters. */ var safe_add = function (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. */ var bit_rol = function (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. */ var str2binl = function (str) { var bin = []; 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 */ var binl2str = function (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. */ var binl2hex = function (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 */ var binl2b64 = function (binarray) { var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; var str = ""; var triplet, j; for(var i = 0; i < binarray.length * 4; i += 3) { 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(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; }; /* * These functions implement the four basic operations the algorithm uses. */ var md5_cmn = function (q, a, b, x, s, t) { return safe_add(bit_rol(safe_add(safe_add(a, q),safe_add(x, t)), s),b); }; var md5_ff = function (a, b, c, d, x, s, t) { return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t); }; var md5_gg = function (a, b, c, d, x, s, t) { return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t); }; var md5_hh = function (a, b, c, d, x, s, t) { return md5_cmn(b ^ c ^ d, a, b, x, s, t); }; var md5_ii = function (a, b, c, d, x, s, t) { return md5_cmn(c ^ (b | (~d)), a, b, x, s, t); }; /* * Calculate the MD5 of an array of little-endian words, and a bit length */ var core_md5 = function (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; var olda, oldb, oldc, oldd; for (var i = 0; i < x.length; i += 16) { olda = a; oldb = b; oldc = c; 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 [a, b, c, d]; }; /* * Calculate the HMAC-MD5, of a key and some data */ var core_hmac_md5 = function (key, data) { var bkey = str2binl(key); if(bkey.length > 16) { bkey = core_md5(bkey, key.length * chrsz); } var ipad = new Array(16), opad = new 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); }; var obj = { /* * These are the functions you'll usually want to call. * They take string arguments and return either hex or base-64 encoded * strings. */ hexdigest: function (s) { return binl2hex(core_md5(str2binl(s), s.length * chrsz)); }, b64digest: function (s) { return binl2b64(core_md5(str2binl(s), s.length * chrsz)); }, hash: function (s) { return binl2str(core_md5(str2binl(s), s.length * chrsz)); }, hmac_hexdigest: function (key, data) { return binl2hex(core_hmac_md5(key, data)); }, hmac_b64digest: function (key, data) { return binl2b64(core_hmac_md5(key, data)); }, hmac_hash: function (key, data) { return binl2str(core_hmac_md5(key, data)); }, /* * Perform a simple self-test to see if the VM is working */ test: function () { return MD5.hexdigest("abc") === "900150983cd24fb0d6963f7d28e17f72"; } }; return obj; })(); /* This program is distributed under the terms of the MIT license. Please see the LICENSE file for details. Copyright 2006-2008, OGG, LLC */ /* jslint configuration: */ /*global document, window, setTimeout, clearTimeout, console, XMLHttpRequest, ActiveXObject, Base64, MD5, Strophe, $build, $msg, $iq, $pres */ /** File: strophe.js * A JavaScript library for XMPP BOSH. * * This is the JavaScript version of the Strophe library. Since JavaScript * has no facilities for persistent TCP connections, this library uses * Bidirectional-streams Over Synchronous HTTP (BOSH) to emulate * a persistent, stateful, two-way connection to an XMPP server. More * information on BOSH can be found in XEP 124. */ /** PrivateFunction: Function.prototype.bind * Bind a function to an instance. * * This Function object extension method creates a bound method similar * to those in Python. This means that the 'this' object will point * to the instance you want. See * Bound Functions and Function Imports in JavaScript * for a complete explanation. * * This extension already exists in some browsers (namely, Firefox 3), but * we provide it to support those that don't. * * Parameters: * (Object) obj - The object that will become 'this' in the bound function. * * Returns: * The bound function. */ if (!Function.prototype.bind) { Function.prototype.bind = function (obj) { var func = this; return function () { return func.apply(obj, arguments); }; }; } /** PrivateFunction: Function.prototype.prependArg * Prepend an argument to a function. * * This Function object extension method returns a Function that will * invoke the original function with an argument prepended. This is useful * when some object has a callback that needs to get that same object as * an argument. The following fragment illustrates a simple case of this * > var obj = new Foo(this.someMethod); * * Foo's constructor can now use func.prependArg(this) to ensure the * passed in callback function gets the instance of Foo as an argument. * Doing this without prependArg would mean not setting the callback * from the constructor. * * This is used inside Strophe for passing the Strophe.Request object to * the onreadystatechange handler of XMLHttpRequests. * * Parameters: * arg - The argument to pass as the first parameter to the function. * * Returns: * A new Function which calls the original with the prepended argument. */ if (!Function.prototype.prependArg) { Function.prototype.prependArg = function (arg) { var func = this; return function () { var newargs = [arg]; for (var i = 0; i < arguments.length; i++) { newargs.push(arguments[i]); } return func.apply(this, newargs); }; }; } /** PrivateFunction: Array.prototype.indexOf * Return the index of an object in an array. * * This function is not supplied by some JavaScript implementations, so * we provide it if it is missing. This code is from: * http://developer.mozilla.org/En/Core_JavaScript_1.5_Reference:Objects:Array:indexOf * * Parameters: * (Object) elt - The object to look for. * (Integer) from - The index from which to start looking. (optional). * * Returns: * The index of elt in the array or -1 if not found. */ if (!Array.prototype.indexOf) { Array.prototype.indexOf = function(elt /*, from*/) { var len = this.length; var from = Number(arguments[1]) || 0; from = (from < 0) ? Math.ceil(from) : Math.floor(from); if (from < 0) { from += len; } for (; from < len; from++) { if (from in this && this[from] === elt) { return from; } } return -1; }; } /* All of the Strophe globals are defined in this special function below so * that references to the globals become closures. This will ensure that * on page reload, these references will still be available to callbacks * that are still executing. */ (function (callback) { var Strophe; /** Function: $build * Create a Strophe.Builder. * This is an alias for 'new Strophe.Builder(name, attrs)'. * * Parameters: * (String) name - The root element name. * (Object) attrs - The attributes for the root element in object notation. * * Returns: * A new Strophe.Builder object. */ function $build(name, attrs) { return new Strophe.Builder(name, attrs); } /** Function: $msg * Create a Strophe.Builder with a element as the root. * * Parmaeters: * (Object) attrs - The element attributes in object notation. * * Returns: * A new Strophe.Builder object. */ function $msg(attrs) { return new Strophe.Builder("message", attrs); } /** Function: $iq * Create a Strophe.Builder with an element as the root. * * Parameters: * (Object) attrs - The element attributes in object notation. * * Returns: * A new Strophe.Builder object. */ function $iq(attrs) { return new Strophe.Builder("iq", attrs); } /** Function: $pres * Create a Strophe.Builder with a element as the root. * * Parameters: * (Object) attrs - The element attributes in object notation. * * Returns: * A new Strophe.Builder object. */ function $pres(attrs) { return new Strophe.Builder("presence", attrs); } /** Class: Strophe * An object container for all Strophe library functions. * * This class is just a container for all the objects and constants * used in the library. It is not meant to be instantiated, but to * provide a namespace for library objects, constants, and functions. */ Strophe = { /** Constant: VERSION * The version of the Strophe library. Unreleased builds will have * a version of head-HASH where HASH is a partial revision. */ VERSION: "1.0.1", /** Constants: XMPP Namespace Constants * Common namespace constants from the XMPP RFCs and XEPs. * * NS.HTTPBIND - HTTP BIND namespace from XEP 124. * NS.BOSH - BOSH namespace from XEP 206. * NS.CLIENT - Main XMPP client namespace. * NS.AUTH - Legacy authentication namespace. * NS.ROSTER - Roster operations namespace. * NS.PROFILE - Profile namespace. * NS.DISCO_INFO - Service discovery info namespace from XEP 30. * NS.DISCO_ITEMS - Service discovery items namespace from XEP 30. * NS.MUC - Multi-User Chat namespace from XEP 45. * NS.SASL - XMPP SASL namespace from RFC 3920. * NS.STREAM - XMPP Streams namespace from RFC 3920. * NS.BIND - XMPP Binding namespace from RFC 3920. * NS.SESSION - XMPP Session namespace from RFC 3920. */ NS: { HTTPBIND: "http://jabber.org/protocol/httpbind", BOSH: "urn:xmpp:xbosh", CLIENT: "jabber:client", AUTH: "jabber:iq:auth", ROSTER: "jabber:iq:roster", PROFILE: "jabber:iq:profile", DISCO_INFO: "http://jabber.org/protocol/disco#info", DISCO_ITEMS: "http://jabber.org/protocol/disco#items", MUC: "http://jabber.org/protocol/muc", SASL: "urn:ietf:params:xml:ns:xmpp-sasl", STREAM: "http://etherx.jabber.org/streams", BIND: "urn:ietf:params:xml:ns:xmpp-bind", SESSION: "urn:ietf:params:xml:ns:xmpp-session", VERSION: "jabber:iq:version", STANZAS: "urn:ietf:params:xml:ns:xmpp-stanzas" }, /** Function: addNamespace * This function is used to extend the current namespaces in * Strophe.NS. It takes a key and a value with the key being the * name of the new namespace, with its actual value. * For example: * Strophe.addNamespace('PUBSUB', "http://jabber.org/protocol/pubsub"); * * Parameters: * (String) name - The name under which the namespace will be * referenced under Strophe.NS * (String) value - The actual namespace. */ addNamespace: function (name, value) { Strophe.NS[name] = value; }, /** Constants: Connection Status Constants * Connection status constants for use by the connection handler * callback. * * Status.ERROR - An error has occurred * Status.CONNECTING - The connection is currently being made * Status.CONNFAIL - The connection attempt failed * Status.AUTHENTICATING - The connection is authenticating * Status.AUTHFAIL - The authentication attempt failed * Status.CONNECTED - The connection has succeeded * Status.DISCONNECTED - The connection has been terminated * Status.DISCONNECTING - The connection is currently being terminated * Status.ATTACHED - The connection has been attached */ Status: { ERROR: 0, CONNECTING: 1, CONNFAIL: 2, AUTHENTICATING: 3, AUTHFAIL: 4, CONNECTED: 5, DISCONNECTED: 6, DISCONNECTING: 7, ATTACHED: 8 }, /** Constants: Log Level Constants * Logging level indicators. * * LogLevel.DEBUG - Debug output * LogLevel.INFO - Informational output * LogLevel.WARN - Warnings * LogLevel.ERROR - Errors * LogLevel.FATAL - Fatal errors */ LogLevel: { DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, FATAL: 4 }, /** PrivateConstants: DOM Element Type Constants * DOM element types. * * ElementType.NORMAL - Normal element. * ElementType.TEXT - Text data element. */ ElementType: { NORMAL: 1, TEXT: 3 }, /** PrivateConstants: Timeout Values * Timeout values for error states. These values are in seconds. * These should not be changed unless you know exactly what you are * doing. * * TIMEOUT - Timeout multiplier. A waiting request will be considered * failed after Math.floor(TIMEOUT * wait) seconds have elapsed. * This defaults to 1.1, and with default wait, 66 seconds. * SECONDARY_TIMEOUT - Secondary timeout multiplier. In cases where * Strophe can detect early failure, it will consider the request * failed if it doesn't return after * Math.floor(SECONDARY_TIMEOUT * wait) seconds have elapsed. * This defaults to 0.1, and with default wait, 6 seconds. */ TIMEOUT: 1.1, SECONDARY_TIMEOUT: 0.1, /** Function: forEachChild * Map a function over some or all child elements of a given element. * * This is a small convenience function for mapping a function over * some or all of the children of an element. If elemName is null, all * children will be passed to the function, otherwise only children * whose tag names match elemName will be passed. * * Parameters: * (XMLElement) elem - The element to operate on. * (String) elemName - The child element tag name filter. * (Function) func - The function to apply to each child. This * function should take a single argument, a DOM element. */ forEachChild: function (elem, elemName, func) { var i, childNode; for (i = 0; i < elem.childNodes.length; i++) { childNode = elem.childNodes[i]; if (childNode.nodeType == Strophe.ElementType.NORMAL && (!elemName || this.isTagEqual(childNode, elemName))) { func(childNode); } } }, /** Function: isTagEqual * Compare an element's tag name with a string. * * This function is case insensitive. * * Parameters: * (XMLElement) el - A DOM element. * (String) name - The element name. * * Returns: * true if the element's tag name matches _el_, and false * otherwise. */ isTagEqual: function (el, name) { return el.tagName.toLowerCase() == name.toLowerCase(); }, /** PrivateVariable: _xmlGenerator * _Private_ variable that caches a DOM document to * generate elements. */ _xmlGenerator: null, /** PrivateFunction: _makeGenerator * _Private_ function that creates a dummy XML DOM document to serve as * an element and text node generator. */ _makeGenerator: function () { var doc; if (window.ActiveXObject) { doc = new ActiveXObject("Microsoft.XMLDOM"); doc.appendChild(doc.createElement('strophe')); } else { doc = document.implementation .createDocument('jabber:client', 'strophe', null); } return doc; }, /** Function: xmlElement * Create an XML DOM element. * * This function creates an XML DOM element correctly across all * implementations. Specifically the Microsoft implementation of * document.createElement makes DOM elements with 43+ default attributes * unless elements are created with the ActiveX object Microsoft.XMLDOM. * * Most DOMs force element names to lowercase, so we use the * _realname attribute on the created element to store the case * sensitive name. This is required to generate proper XML for * things like vCard avatars (XEP 153). This attribute is stripped * out before being sent over the wire or serialized, but you may * notice it during debugging. * * Parameters: * (String) name - The name for the element. * (Array) attrs - An optional array of key/value pairs to use as * element attributes in the following format [['key1', 'value1'], * ['key2', 'value2']] * (String) text - The text child data for the element. * * Returns: * A new XML DOM element. */ xmlElement: function (name) { if (!name) { return null; } var node = null; if (!Strophe._xmlGenerator) { Strophe._xmlGenerator = Strophe._makeGenerator(); } node = Strophe._xmlGenerator.createElement(name); // FIXME: this should throw errors if args are the wrong type or // there are more than two optional args var a, i, k; for (a = 1; a < arguments.length; a++) { if (!arguments[a]) { continue; } if (typeof(arguments[a]) == "string" || typeof(arguments[a]) == "number") { node.appendChild(Strophe.xmlTextNode(arguments[a])); } else if (typeof(arguments[a]) == "object" && typeof(arguments[a].sort) == "function") { for (i = 0; i < arguments[a].length; i++) { if (typeof(arguments[a][i]) == "object" && typeof(arguments[a][i].sort) == "function") { node.setAttribute(arguments[a][i][0], arguments[a][i][1]); } } } else if (typeof(arguments[a]) == "object") { for (k in arguments[a]) { if (arguments[a].hasOwnProperty(k)) { node.setAttribute(k, arguments[a][k]); } } } } return node; }, /* Function: xmlescape * Excapes invalid xml characters. * * Parameters: * (String) text - text to escape. * * Returns: * Escaped text. */ xmlescape: function(text) { text = text.replace(/\&/g, "&"); text = text.replace(//g, ">"); return text; }, /** Function: xmlTextNode * Creates an XML DOM text node. * * Provides a cross implementation version of document.createTextNode. * * Parameters: * (String) text - The content of the text node. * * Returns: * A new XML DOM text node. */ xmlTextNode: function (text) { //ensure text is escaped text = Strophe.xmlescape(text); if (!Strophe._xmlGenerator) { Strophe._xmlGenerator = Strophe._makeGenerator(); } return Strophe._xmlGenerator.createTextNode(text); }, /** Function: getText * Get the concatenation of all text children of an element. * * Parameters: * (XMLElement) elem - A DOM element. * * Returns: * A String with the concatenated text of all text element children. */ getText: function (elem) { if (!elem) { return null; } var str = ""; if (elem.childNodes.length === 0 && elem.nodeType == Strophe.ElementType.TEXT) { str += elem.nodeValue; } for (var i = 0; i < elem.childNodes.length; i++) { if (elem.childNodes[i].nodeType == Strophe.ElementType.TEXT) { str += elem.childNodes[i].nodeValue; } } return str; }, /** Function: copyElement * Copy an XML DOM element. * * This function copies a DOM element and all its descendants and returns * the new copy. * * Parameters: * (XMLElement) elem - A DOM element. * * Returns: * A new, copied DOM element tree. */ copyElement: function (elem) { var i, el; if (elem.nodeType == Strophe.ElementType.NORMAL) { el = Strophe.xmlElement(elem.tagName); for (i = 0; i < elem.attributes.length; i++) { el.setAttribute(elem.attributes[i].nodeName.toLowerCase(), elem.attributes[i].value); } for (i = 0; i < elem.childNodes.length; i++) { el.appendChild(Strophe.copyElement(elem.childNodes[i])); } } else if (elem.nodeType == Strophe.ElementType.TEXT) { el = Strophe.xmlTextNode(elem.nodeValue); } return el; }, /** Function: escapeNode * Escape the node part (also called local part) of a JID. * * Parameters: * (String) node - A node (or local part). * * Returns: * An escaped node (or local part). */ escapeNode: function (node) { return node.replace(/^\s+|\s+$/g, '') .replace(/\\/g, "\\5c") .replace(/ /g, "\\20") .replace(/\"/g, "\\22") .replace(/\&/g, "\\26") .replace(/\'/g, "\\27") .replace(/\//g, "\\2f") .replace(/:/g, "\\3a") .replace(//g, "\\3e") .replace(/@/g, "\\40"); }, /** Function: unescapeNode * Unescape a node part (also called local part) of a JID. * * Parameters: * (String) node - A node (or local part). * * Returns: * An unescaped node (or local part). */ unescapeNode: function (node) { return node.replace(/\\20/g, " ") .replace(/\\22/g, '"') .replace(/\\26/g, "&") .replace(/\\27/g, "'") .replace(/\\2f/g, "/") .replace(/\\3a/g, ":") .replace(/\\3c/g, "<") .replace(/\\3e/g, ">") .replace(/\\40/g, "@") .replace(/\\5c/g, "\\"); }, /** Function: getNodeFromJid * Get the node portion of a JID String. * * Parameters: * (String) jid - A JID. * * Returns: * A String containing the node. */ getNodeFromJid: function (jid) { if (jid.indexOf("@") < 0) { return null; } return jid.split("@")[0]; }, /** Function: getDomainFromJid * Get the domain portion of a JID String. * * Parameters: * (String) jid - A JID. * * Returns: * A String containing the domain. */ getDomainFromJid: function (jid) { var bare = Strophe.getBareJidFromJid(jid); if (bare.indexOf("@") < 0) { return bare; } else { var parts = bare.split("@"); parts.splice(0, 1); return parts.join('@'); } }, /** Function: getResourceFromJid * Get the resource portion of a JID String. * * Parameters: * (String) jid - A JID. * * Returns: * A String containing the resource. */ getResourceFromJid: function (jid) { var s = jid.split("/"); if (s.length < 2) { return null; } s.splice(0, 1); return s.join('/'); }, /** Function: getBareJidFromJid * Get the bare JID from a JID String. * * Parameters: * (String) jid - A JID. * * Returns: * A String containing the bare JID. */ getBareJidFromJid: function (jid) { return jid.split("/")[0]; }, /** Function: log * User overrideable logging function. * * This function is called whenever the Strophe library calls any * of the logging functions. The default implementation of this * function does nothing. If client code wishes to handle the logging * messages, it should override this with * > Strophe.log = function (level, msg) { * > (user code here) * > }; * * Please note that data sent and received over the wire is logged * via Strophe.Connection.rawInput() and Strophe.Connection.rawOutput(). * * The different levels and their meanings are * * DEBUG - Messages useful for debugging purposes. * INFO - Informational messages. This is mostly information like * 'disconnect was called' or 'SASL auth succeeded'. * WARN - Warnings about potential problems. This is mostly used * to report transient connection errors like request timeouts. * ERROR - Some error occurred. * FATAL - A non-recoverable fatal error occurred. * * Parameters: * (Integer) level - The log level of the log message. This will * be one of the values in Strophe.LogLevel. * (String) msg - The log message. */ log: function (level, msg) { return; }, /** Function: debug * Log a message at the Strophe.LogLevel.DEBUG level. * * Parameters: * (String) msg - The log message. */ debug: function(msg) { this.log(this.LogLevel.DEBUG, msg); }, /** Function: info * Log a message at the Strophe.LogLevel.INFO level. * * Parameters: * (String) msg - The log message. */ info: function (msg) { this.log(this.LogLevel.INFO, msg); }, /** Function: warn * Log a message at the Strophe.LogLevel.WARN level. * * Parameters: * (String) msg - The log message. */ warn: function (msg) { this.log(this.LogLevel.WARN, msg); }, /** Function: error * Log a message at the Strophe.LogLevel.ERROR level. * * Parameters: * (String) msg - The log message. */ error: function (msg) { this.log(this.LogLevel.ERROR, msg); }, /** Function: fatal * Log a message at the Strophe.LogLevel.FATAL level. * * Parameters: * (String) msg - The log message. */ fatal: function (msg) { this.log(this.LogLevel.FATAL, msg); }, /** Function: serialize * Render a DOM element and all descendants to a String. * * Parameters: * (XMLElement) elem - A DOM element. * * Returns: * The serialized element tree as a String. */ serialize: function (elem) { var result; if (!elem) { return null; } if (typeof(elem.tree) === "function") { elem = elem.tree(); } var nodeName = elem.nodeName; var i, child; if (elem.getAttribute("_realname")) { nodeName = elem.getAttribute("_realname"); } result = "<" + nodeName; for (i = 0; i < elem.attributes.length; i++) { if(elem.attributes[i].nodeName != "_realname") { result += " " + elem.attributes[i].nodeName.toLowerCase() + "='" + elem.attributes[i].value .replace("&", "&") .replace("'", "'") .replace("<", "<") + "'"; } } if (elem.childNodes.length > 0) { result += ">"; for (i = 0; i < elem.childNodes.length; i++) { child = elem.childNodes[i]; if (child.nodeType == Strophe.ElementType.NORMAL) { // normal element, so recurse result += Strophe.serialize(child); } else if (child.nodeType == Strophe.ElementType.TEXT) { // text element result += child.nodeValue; } } result += ""; } else { result += "/>"; } return result; }, /** PrivateVariable: _requestId * _Private_ variable that keeps track of the request ids for * connections. */ _requestId: 0, /** PrivateVariable: Strophe.connectionPlugins * _Private_ variable Used to store plugin names that need * initialization on Strophe.Connection construction. */ _connectionPlugins: {}, /** Function: addConnectionPlugin * Extends the Strophe.Connection object with the given plugin. * * Paramaters: * (String) name - The name of the extension. * (Object) ptype - The plugin's prototype. */ addConnectionPlugin: function (name, ptype) { Strophe._connectionPlugins[name] = ptype; } }; /** Class: Strophe.Builder * XML DOM builder. * * This object provides an interface similar to JQuery but for building * DOM element easily and rapidly. All the functions except for toString() * and tree() return the object, so calls can be chained. Here's an * example using the $iq() builder helper. * > $iq({to: 'you': from: 'me': type: 'get', id: '1'}) * > .c('query', {xmlns: 'strophe:example'}) * > .c('example') * > .toString() * The above generates this XML fragment * > * > * > * > * > * The corresponding DOM manipulations to get a similar fragment would be * a lot more tedious and probably involve several helper variables. * * Since adding children makes new operations operate on the child, up() * is provided to traverse up the tree. To add two children, do * > builder.c('child1', ...).up().c('child2', ...) * The next operation on the Builder will be relative to the second child. */ /** Constructor: Strophe.Builder * Create a Strophe.Builder object. * * The attributes should be passed in object notation. For example * > var b = new Builder('message', {to: 'you', from: 'me'}); * or * > var b = new Builder('messsage', {'xml:lang': 'en'}); * * Parameters: * (String) name - The name of the root element. * (Object) attrs - The attributes for the root element in object notation. * * Returns: * A new Strophe.Builder. */ Strophe.Builder = function (name, attrs) { // Set correct namespace for jabber:client elements if (name == "presence" || name == "message" || name == "iq") { if (attrs && !attrs.xmlns) { attrs.xmlns = Strophe.NS.CLIENT; } else if (!attrs) { attrs = {xmlns: Strophe.NS.CLIENT}; } } // Holds the tree being built. this.nodeTree = Strophe.xmlElement(name, attrs); // Points to the current operation node. this.node = this.nodeTree; }; Strophe.Builder.prototype = { /** Function: tree * Return the DOM tree. * * This function returns the current DOM tree as an element object. This * is suitable for passing to functions like Strophe.Connection.send(). * * Returns: * The DOM tree as a element object. */ tree: function () { return this.nodeTree; }, /** Function: toString * Serialize the DOM tree to a String. * * This function returns a string serialization of the current DOM * tree. It is often used internally to pass data to a * Strophe.Request object. * * Returns: * The serialized DOM tree in a String. */ toString: function () { return Strophe.serialize(this.nodeTree); }, /** Function: up * Make the current parent element the new current element. * * This function is often used after c() to traverse back up the tree. * For example, to add two children to the same element * > builder.c('child1', {}).up().c('child2', {}); * * Returns: * The Stophe.Builder object. */ up: function () { this.node = this.node.parentNode; return this; }, /** Function: attrs * Add or modify attributes of the current element. * * The attributes should be passed in object notation. This function * does not move the current element pointer. * * Parameters: * (Object) moreattrs - The attributes to add/modify in object notation. * * Returns: * The Strophe.Builder object. */ attrs: function (moreattrs) { for (var k in moreattrs) { if (moreattrs.hasOwnProperty(k)) { this.node.setAttribute(k, moreattrs[k]); } } return this; }, /** Function: c * Add a child to the current element and make it the new current * element. * * This function moves the current element pointer to the child. If you * need to add another child, it is necessary to use up() to go back * to the parent in the tree. * * Parameters: * (String) name - The name of the child. * (Object) attrs - The attributes of the child in object notation. * * Returns: * The Strophe.Builder object. */ c: function (name, attrs) { var child = Strophe.xmlElement(name, attrs); this.node.appendChild(child); this.node = child; return this; }, /** Function: cnode * Add a child to the current element and make it the new current * element. * * This function is the same as c() except that instead of using a * name and an attributes object to create the child it uses an * existing DOM element object. * * Parameters: * (XMLElement) elem - A DOM element. * * Returns: * The Strophe.Builder object. */ cnode: function (elem) { this.node.appendChild(elem); this.node = elem; return this; }, /** Function: t * Add a child text element. * * This *does not* make the child the new current element since there * are no children of text elements. * * Parameters: * (String) text - The text data to append to the current element. * * Returns: * The Strophe.Builder object. */ t: function (text) { var child = Strophe.xmlTextNode(text); this.node.appendChild(child); return this; } }; /** PrivateClass: Strophe.Handler * _Private_ helper class for managing stanza handlers. * * A Strophe.Handler encapsulates a user provided callback function to be * executed when matching stanzas are received by the connection. * Handlers can be either one-off or persistant depending on their * return value. Returning true will cause a Handler to remain active, and * returning false will remove the Handler. * * Users will not use Strophe.Handler objects directly, but instead they * will use Strophe.Connection.addHandler() and * Strophe.Connection.deleteHandler(). */ /** PrivateConstructor: Strophe.Handler * Create and initialize a new Strophe.Handler. * * Parameters: * (Function) handler - A function to be executed when the handler is run. * (String) ns - The namespace to match. * (String) name - The element name to match. * (String) type - The element type to match. * (String) id - The element id attribute to match. * (String) from - The element from attribute to match. * (Object) options - Handler options * * Returns: * A new Strophe.Handler object. */ Strophe.Handler = function (handler, ns, name, type, id, from, options) { this.handler = handler; this.ns = ns; this.name = name; this.type = type; this.id = id; this.options = options || {matchbare: false}; // default matchBare to false if undefined if (!this.options.matchBare) { this.options.matchBare = false; } if (this.options.matchBare) { this.from = Strophe.getBareJidFromJid(from); } else { this.from = from; } // whether the handler is a user handler or a system handler this.user = true; }; Strophe.Handler.prototype = { /** PrivateFunction: isMatch * Tests if a stanza matches the Strophe.Handler. * * Parameters: * (XMLElement) elem - The XML element to test. * * Returns: * true if the stanza matches and false otherwise. */ isMatch: function (elem) { var nsMatch; var from = null; if (this.options.matchBare) { from = Strophe.getBareJidFromJid(elem.getAttribute('from')); } else { from = elem.getAttribute('from'); } nsMatch = false; if (!this.ns) { nsMatch = true; } else { var self = this; Strophe.forEachChild(elem, null, function (elem) { if (elem.getAttribute("xmlns") == self.ns) { nsMatch = true; } }); nsMatch = nsMatch || elem.getAttribute("xmlns") == this.ns; } if (nsMatch && (!this.name || Strophe.isTagEqual(elem, this.name)) && (!this.type || elem.getAttribute("type") === this.type) && (!this.id || elem.getAttribute("id") === this.id) && (!this.from || from === this.from)) { return true; } return false; }, /** PrivateFunction: run * Run the callback on a matching stanza. * * Parameters: * (XMLElement) elem - The DOM element that triggered the * Strophe.Handler. * * Returns: * A boolean indicating if the handler should remain active. */ run: function (elem) { var result = null; try { result = this.handler(elem); } catch (e) { if (e.sourceURL) { Strophe.fatal("error: " + this.handler + " " + e.sourceURL + ":" + e.line + " - " + e.name + ": " + e.message); } else if (e.fileName) { if (typeof(console) != "undefined") { console.trace(); console.error(this.handler, " - error - ", e, e.message); } Strophe.fatal("error: " + this.handler + " " + e.fileName + ":" + e.lineNumber + " - " + e.name + ": " + e.message); } else { Strophe.fatal("error: " + this.handler); } throw e; } return result; }, /** PrivateFunction: toString * Get a String representation of the Strophe.Handler object. * * Returns: * A String. */ toString: function () { return "{Handler: " + this.handler + "(" + this.name + "," + this.id + "," + this.ns + ")}"; } }; /** PrivateClass: Strophe.TimedHandler * _Private_ helper class for managing timed handlers. * * A Strophe.TimedHandler encapsulates a user provided callback that * should be called after a certain period of time or at regular * intervals. The return value of the callback determines whether the * Strophe.TimedHandler will continue to fire. * * Users will not use Strophe.TimedHandler objects directly, but instead * they will use Strophe.Connection.addTimedHandler() and * Strophe.Connection.deleteTimedHandler(). */ /** PrivateConstructor: Strophe.TimedHandler * Create and initialize a new Strophe.TimedHandler object. * * Parameters: * (Integer) period - The number of milliseconds to wait before the * handler is called. * (Function) handler - The callback to run when the handler fires. This * function should take no arguments. * * Returns: * A new Strophe.TimedHandler object. */ Strophe.TimedHandler = function (period, handler) { this.period = period; this.handler = handler; this.lastCalled = new Date().getTime(); this.user = true; }; Strophe.TimedHandler.prototype = { /** PrivateFunction: run * Run the callback for the Strophe.TimedHandler. * * Returns: * true if the Strophe.TimedHandler should be called again, and false * otherwise. */ run: function () { this.lastCalled = new Date().getTime(); return this.handler(); }, /** PrivateFunction: reset * Reset the last called time for the Strophe.TimedHandler. */ reset: function () { this.lastCalled = new Date().getTime(); }, /** PrivateFunction: toString * Get a string representation of the Strophe.TimedHandler object. * * Returns: * The string representation. */ toString: function () { return "{TimedHandler: " + this.handler + "(" + this.period +")}"; } }; /** PrivateClass: Strophe.Request * _Private_ helper class that provides a cross implementation abstraction * for a BOSH related XMLHttpRequest. * * The Strophe.Request class is used internally to encapsulate BOSH request * information. It is not meant to be used from user's code. */ /** PrivateConstructor: Strophe.Request * Create and initialize a new Strophe.Request object. * * Parameters: * (XMLElement) elem - The XML data to be sent in the request. * (Function) func - The function that will be called when the * XMLHttpRequest readyState changes. * (Integer) rid - The BOSH rid attribute associated with this request. * (Integer) sends - The number of times this same request has been * sent. */ Strophe.Request = function (elem, func, rid, sends) { this.id = ++Strophe._requestId; this.xmlData = elem; this.data = Strophe.serialize(elem); // save original function in case we need to make a new request // from this one. this.origFunc = func; this.func = func; this.rid = rid; this.date = NaN; this.sends = sends || 0; this.abort = false; this.dead = null; this.age = function () { if (!this.date) { return 0; } var now = new Date(); return (now - this.date) / 1000; }; this.timeDead = function () { if (!this.dead) { return 0; } var now = new Date(); return (now - this.dead) / 1000; }; this.xhr = this._newXHR(); }; Strophe.Request.prototype = { /** PrivateFunction: getResponse * Get a response from the underlying XMLHttpRequest. * * This function attempts to get a response from the request and checks * for errors. * * Throws: * "parsererror" - A parser error occured. * * Returns: * The DOM element tree of the response. */ getResponse: function () { var node = null; if (this.xhr.responseXML && this.xhr.responseXML.documentElement) { node = this.xhr.responseXML.documentElement; if (node.tagName == "parsererror") { Strophe.error("invalid response received"); Strophe.error("responseText: " + this.xhr.responseText); Strophe.error("responseXML: " + Strophe.serialize(this.xhr.responseXML)); throw "parsererror"; } } else if (this.xhr.responseText) { Strophe.error("invalid response received"); Strophe.error("responseText: " + this.xhr.responseText); Strophe.error("responseXML: " + Strophe.serialize(this.xhr.responseXML)); } return node; }, /** PrivateFunction: _newXHR * _Private_ helper function to create XMLHttpRequests. * * This function creates XMLHttpRequests across all implementations. * * Returns: * A new XMLHttpRequest. */ _newXHR: function () { var xhr = null; if (window.XMLHttpRequest) { xhr = new XMLHttpRequest(); if (xhr.overrideMimeType) { xhr.overrideMimeType("text/xml"); } } else if (window.ActiveXObject) { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } xhr.onreadystatechange = this.func.prependArg(this); return xhr; } }; /** Class: Strophe.Connection * XMPP Connection manager. * * Thie class is the main part of Strophe. It manages a BOSH connection * to an XMPP server and dispatches events to the user callbacks as * data arrives. It supports SASL PLAIN, SASL DIGEST-MD5, and legacy * authentication. * * After creating a Strophe.Connection object, the user will typically * call connect() with a user supplied callback to handle connection level * events like authentication failure, disconnection, or connection * complete. * * The user will also have several event handlers defined by using * addHandler() and addTimedHandler(). These will allow the user code to * respond to interesting stanzas or do something periodically with the * connection. These handlers will be active once authentication is * finished. * * To send data to the connection, use send(). */ /** Constructor: Strophe.Connection * Create and initialize a Strophe.Connection object. * * Parameters: * (String) service - The BOSH service URL. * * Returns: * A new Strophe.Connection object. */ Strophe.Connection = function (service) { /* The path to the httpbind service. */ this.service = service; /* The connected JID. */ this.jid = ""; /* request id for body tags */ this.rid = Math.floor(Math.random() * 4294967295); /* The current session ID. */ this.sid = null; this.streamId = null; // SASL this.do_session = false; this.do_bind = false; // handler lists this.timedHandlers = []; this.handlers = []; this.removeTimeds = []; this.removeHandlers = []; this.addTimeds = []; this.addHandlers = []; this._idleTimeout = null; this._disconnectTimeout = null; this.authenticated = false; this.disconnecting = false; this.connected = false; this.errors = 0; this.paused = false; // default BOSH values this.hold = 1; this.wait = 60; this.window = 5; this._data = []; this._requests = []; this._uniqueId = Math.round(Math.random() * 10000); this._sasl_success_handler = null; this._sasl_failure_handler = null; this._sasl_challenge_handler = null; // setup onIdle callback every 1/10th of a second this._idleTimeout = setTimeout(this._onIdle.bind(this), 100); // initialize plugins for (var k in Strophe._connectionPlugins) { if (Strophe._connectionPlugins.hasOwnProperty(k)) { var ptype = Strophe._connectionPlugins[k]; // jslint complaints about the below line, but this is fine var F = function () {}; F.prototype = ptype; this[k] = new F(); this[k].init(this); } } }; Strophe.Connection.prototype = { /** Function: reset * Reset the connection. * * This function should be called after a connection is disconnected * before that connection is reused. */ reset: function () { this.rid = Math.floor(Math.random() * 4294967295); this.sid = null; this.streamId = null; // SASL this.do_session = false; this.do_bind = false; // handler lists this.timedHandlers = []; this.handlers = []; this.removeTimeds = []; this.removeHandlers = []; this.addTimeds = []; this.addHandlers = []; this.authenticated = false; this.disconnecting = false; this.connected = false; this.errors = 0; this._requests = []; this._uniqueId = Math.round(Math.random()*10000); }, /** Function: pause * Pause the request manager. * * This will prevent Strophe from sending any more requests to the * server. This is very useful for temporarily pausing while a lot * of send() calls are happening quickly. This causes Strophe to * send the data in a single request, saving many request trips. */ pause: function () { this.paused = true; }, /** Function: resume * Resume the request manager. * * This resumes after pause() has been called. */ resume: function () { this.paused = false; }, /** Function: getUniqueId * Generate a unique ID for use in elements. * * All stanzas are required to have unique id attributes. This * function makes creating these easy. Each connection instance has * a counter which starts from zero, and the value of this counter * plus a colon followed by the suffix becomes the unique id. If no * suffix is supplied, the counter is used as the unique id. * * Suffixes are used to make debugging easier when reading the stream * data, and their use is recommended. The counter resets to 0 for * every new connection for the same reason. For connections to the * same server that authenticate the same way, all the ids should be * the same, which makes it easy to see changes. This is useful for * automated testing as well. * * Parameters: * (String) suffix - A optional suffix to append to the id. * * Returns: * A unique string to be used for the id attribute. */ getUniqueId: function (suffix) { if (typeof(suffix) == "string" || typeof(suffix) == "number") { return ++this._uniqueId + ":" + suffix; } else { return ++this._uniqueId + ""; } }, /** Function: connect * Starts the connection process. * * As the connection process proceeds, the user supplied callback will * be triggered multiple times with status updates. The callback * should take two arguments - the status code and the error condition. * * The status code will be one of the values in the Strophe.Status * constants. The error condition will be one of the conditions * defined in RFC 3920 or the condition 'strophe-parsererror'. * * Please see XEP 124 for a more detailed explanation of the optional * parameters below. * * Parameters: * (String) jid - The user's JID. This may be a bare JID, * or a full JID. If a node is not supplied, SASL ANONYMOUS * authentication will be attempted. * (String) pass - The user's password. * (Function) callback The connect callback function. * (Integer) wait - The optional HTTPBIND wait value. This is the * time the server will wait before returning an empty result for * a request. The default setting of 60 seconds is recommended. * Other settings will require tweaks to the Strophe.TIMEOUT value. * (Integer) hold - The optional HTTPBIND hold value. This is the * number of connections the server will hold at one time. This * should almost always be set to 1 (the default). */ connect: function (jid, pass, callback, wait, hold) { this.jid = jid; this.pass = pass; this.connect_callback = callback; this.disconnecting = false; this.connected = false; this.authenticated = false; this.errors = 0; this.wait = wait || this.wait; this.hold = hold || this.hold; // parse jid for domain and resource this.domain = Strophe.getDomainFromJid(this.jid); // build the body tag var body = this._buildBody().attrs({ to: this.domain, "xml:lang": "en", wait: this.wait, hold: this.hold, content: "text/xml; charset=utf-8", ver: "1.6", "xmpp:version": "1.0", "xmlns:xmpp": Strophe.NS.BOSH }); this._changeConnectStatus(Strophe.Status.CONNECTING, null); this._requests.push( new Strophe.Request(body.tree(), this._onRequestStateChange.bind(this) .prependArg(this._connect_cb.bind(this)), body.tree().getAttribute("rid"))); this._throttledRequestHandler(); }, /** Function: attach * Attach to an already created and authenticated BOSH session. * * This function is provided to allow Strophe to attach to BOSH * sessions which have been created externally, perhaps by a Web * application. This is often used to support auto-login type features * without putting user credentials into the page. * * Parameters: * (String) jid - The full JID that is bound by the session. * (String) sid - The SID of the BOSH session. * (String) rid - The current RID of the BOSH session. This RID * will be used by the next request. * (Function) callback The connect callback function. * (Integer) wait - The optional HTTPBIND wait value. This is the * time the server will wait before returning an empty result for * a request. The default setting of 60 seconds is recommended. * Other settings will require tweaks to the Strophe.TIMEOUT value. * (Integer) hold - The optional HTTPBIND hold value. This is the * number of connections the server will hold at one time. This * should almost always be set to 1 (the default). * (Integer) wind - The optional HTTBIND window value. This is the * allowed range of request ids that are valid. The default is 5. */ attach: function (jid, sid, rid, callback, wait, hold, wind) { this.jid = jid; this.sid = sid; this.rid = rid; this.connect_callback = callback; this.domain = Strophe.getDomainFromJid(this.jid); this.authenticated = true; this.connected = true; this.wait = wait || this.wait; this.hold = hold || this.hold; this.window = wind || this.window; this._changeConnectStatus(Strophe.Status.ATTACHED, null); }, /** Function: xmlInput * User overrideable function that receives XML data coming into the * connection. * * The default function does nothing. User code can override this with * > Strophe.Connection.xmlInput = function (elem) { * > (user code) * > }; * * Parameters: * (XMLElement) elem - The XML data received by the connection. */ xmlInput: function (elem) { return; }, /** Function: xmlOutput * User overrideable function that receives XML data sent to the * connection. * * The default function does nothing. User code can override this with * > Strophe.Connection.xmlOutput = function (elem) { * > (user code) * > }; * * Parameters: * (XMLElement) elem - The XMLdata sent by the connection. */ xmlOutput: function (elem) { return; }, /** Function: rawInput * User overrideable function that receives raw data coming into the * connection. * * The default function does nothing. User code can override this with * > Strophe.Connection.rawInput = function (data) { * > (user code) * > }; * * Parameters: * (String) data - The data received by the connection. */ rawInput: function (data) { return; }, /** Function: rawOutput * User overrideable function that receives raw data sent to the * connection. * * The default function does nothing. User code can override this with * > Strophe.Connection.rawOutput = function (data) { * > (user code) * > }; * * Parameters: * (String) data - The data sent by the connection. */ rawOutput: function (data) { return; }, /** Function: send * Send a stanza. * * This function is called to push data onto the send queue to * go out over the wire. Whenever a request is sent to the BOSH * server, all pending data is sent and the queue is flushed. * * Parameters: * (XMLElement | * [XMLElement] | * Strophe.Builder) elem - The stanza to send. */ send: function (elem) { if (elem === null) { return ; } if (typeof(elem.sort) === "function") { for (var i = 0; i < elem.length; i++) { this._queueData(elem[i]); } } else if (typeof(elem.tree) === "function") { this._queueData(elem.tree()); } else { this._queueData(elem); } this._throttledRequestHandler(); clearTimeout(this._idleTimeout); this._idleTimeout = setTimeout(this._onIdle.bind(this), 100); }, /** Function: flush * Immediately send any pending outgoing data. * * Normally send() queues outgoing data until the next idle period * (100ms), which optimizes network use in the common cases when * several send()s are called in succession. flush() can be used to * immediately send all pending data. */ flush: function () { // cancel the pending idle period and run the idle function // immediately clearTimeout(this._idleTimeout); this._onIdle(); }, /** Function: sendIQ * Helper function to send IQ stanzas. * * Parameters: * (XMLElement) elem - The stanza to send. * (Function) callback - The callback function for a successful request. * (Function) errback - The callback function for a failed or timed * out request. On timeout, the stanza will be null. * (Integer) timeout - The time specified in milliseconds for a * timeout to occur. * * Returns: * The id used to send the IQ. */ sendIQ: function(elem, callback, errback, timeout) { var timeoutHandler = null; var that = this; if (typeof(elem.tree) === "function") { elem = elem.tree(); } var id = elem.getAttribute('id'); // inject id if not found if (!id) { id = this.getUniqueId("sendIQ"); elem.setAttribute("id", id); } var handler = this.addHandler(function (stanza) { // remove timeout handler if there is one if (timeoutHandler) { that.deleteTimedHandler(timeoutHandler); } var iqtype = stanza.getAttribute('type'); if (iqtype === 'result') { if (callback) { callback(stanza); } } else if (iqtype === 'error') { if (errback) { errback(stanza); } } else { throw { name: "StropheError", message: "Got bad IQ type of " + iqtype }; } }, null, 'iq', null, id); // if timeout specified, setup timeout handler. if (timeout) { timeoutHandler = this.addTimedHandler(timeout, function () { // get rid of normal handler that.deleteHandler(handler); // call errback on timeout with null stanza if (errback) { errback(null); } return false; }); } this.send(elem); return id; }, /** PrivateFunction: _queueData * Queue outgoing data for later sending. Also ensures that the data * is a DOMElement. */ _queueData: function (element) { if (element === null || !element.tagName || !element.childNodes) { throw { name: "StropheError", message: "Cannot queue non-DOMElement." }; } this._data.push(element); }, /** PrivateFunction: _sendRestart * Send an xmpp:restart stanza. */ _sendRestart: function () { this._data.push("restart"); this._throttledRequestHandler(); clearTimeout(this._idleTimeout); this._idleTimeout = setTimeout(this._onIdle.bind(this), 100); }, /** Function: addTimedHandler * Add a timed handler to the connection. * * This function adds a timed handler. The provided handler will * be called every period milliseconds until it returns false, * the connection is terminated, or the handler is removed. Handlers * that wish to continue being invoked should return true. * * Because of method binding it is necessary to save the result of * this function if you wish to remove a handler with * deleteTimedHandler(). * * Note that user handlers are not active until authentication is * successful. * * Parameters: * (Integer) period - The period of the handler. * (Function) handler - The callback function. * * Returns: * A reference to the handler that can be used to remove it. */ addTimedHandler: function (period, handler) { var thand = new Strophe.TimedHandler(period, handler); this.addTimeds.push(thand); return thand; }, /** Function: deleteTimedHandler * Delete a timed handler for a connection. * * This function removes a timed handler from the connection. The * handRef parameter is *not* the function passed to addTimedHandler(), * but is the reference returned from addTimedHandler(). * * Parameters: * (Strophe.TimedHandler) handRef - The handler reference. */ deleteTimedHandler: function (handRef) { // this must be done in the Idle loop so that we don't change // the handlers during iteration this.removeTimeds.push(handRef); }, /** Function: addHandler * Add a stanza handler for the connection. * * This function adds a stanza handler to the connection. The * handler callback will be called for any stanza that matches * the parameters. Note that if multiple parameters are supplied, * they must all match for the handler to be invoked. * * The handler will receive the stanza that triggered it as its argument. * The handler should return true if it is to be invoked again; * returning false will remove the handler after it returns. * * As a convenience, the ns parameters applies to the top level element * and also any of its immediate children. This is primarily to make * matching /iq/query elements easy. * * The options argument contains handler matching flags that affect how * matches are determined. Currently the only flag is matchBare (a * boolean). When matchBare is true, the from parameter and the from * attribute on the stanza will be matched as bare JIDs instead of * full JIDs. To use this, pass {matchBare: true} as the value of * options. The default value for matchBare is false. * * The return value should be saved if you wish to remove the handler * with deleteHandler(). * * Parameters: * (Function) handler - The user callback. * (String) ns - The namespace to match. * (String) name - The stanza name to match. * (String) type - The stanza type attribute to match. * (String) id - The stanza id attribute to match. * (String) from - The stanza from attribute to match. * (String) options - The handler options * * Returns: * A reference to the handler that can be used to remove it. */ addHandler: function (handler, ns, name, type, id, from, options) { var hand = new Strophe.Handler(handler, ns, name, type, id, from, options); this.addHandlers.push(hand); return hand; }, /** Function: deleteHandler * Delete a stanza handler for a connection. * * This function removes a stanza handler from the connection. The * handRef parameter is *not* the function passed to addHandler(), * but is the reference returned from addHandler(). * * Parameters: * (Strophe.Handler) handRef - The handler reference. */ deleteHandler: function (handRef) { // this must be done in the Idle loop so that we don't change // the handlers during iteration this.removeHandlers.push(handRef); }, /** Function: disconnect * Start the graceful disconnection process. * * This function starts the disconnection process. This process starts * by sending unavailable presence and sending BOSH body of type * terminate. A timeout handler makes sure that disconnection happens * even if the BOSH server does not respond. * * The user supplied connection callback will be notified of the * progress as this process happens. * * Parameters: * (String) reason - The reason the disconnect is occuring. */ disconnect: function (reason) { this._changeConnectStatus(Strophe.Status.DISCONNECTING, reason); Strophe.info("Disconnect was called because: " + reason); if (this.connected) { // setup timeout handler this._disconnectTimeout = this._addSysTimedHandler( 3000, this._onDisconnectTimeout.bind(this)); this._sendTerminate(); } }, /** PrivateFunction: _changeConnectStatus * _Private_ helper function that makes sure plugins and the user's * callback are notified of connection status changes. * * Parameters: * (Integer) status - the new connection status, one of the values * in Strophe.Status * (String) condition - the error condition or null */ _changeConnectStatus: function (status, condition) { // notify all plugins listening for status changes for (var k in Strophe._connectionPlugins) { if (Strophe._connectionPlugins.hasOwnProperty(k)) { var plugin = this[k]; if (plugin.statusChanged) { try { plugin.statusChanged(status, condition); } catch (err) { Strophe.error("" + k + " plugin caused an exception " + "changing status: " + err); } } } } // notify the user's callback if (this.connect_callback) { try { this.connect_callback(status, condition); } catch (e) { Strophe.error("User connection callback caused an " + "exception: " + e); } } }, /** PrivateFunction: _buildBody * _Private_ helper function to generate the wrapper for BOSH. * * Returns: * A Strophe.Builder with a element. */ _buildBody: function () { var bodyWrap = $build('body', { rid: this.rid++, xmlns: Strophe.NS.HTTPBIND }); if (this.sid !== null) { bodyWrap.attrs({sid: this.sid}); } return bodyWrap; }, /** PrivateFunction: _removeRequest * _Private_ function to remove a request from the queue. * * Parameters: * (Strophe.Request) req - The request to remove. */ _removeRequest: function (req) { Strophe.debug("removing request"); var i; for (i = this._requests.length - 1; i >= 0; i--) { if (req == this._requests[i]) { this._requests.splice(i, 1); } } // IE6 fails on setting to null, so set to empty function req.xhr.onreadystatechange = function () {}; this._throttledRequestHandler(); }, /** PrivateFunction: _restartRequest * _Private_ function to restart a request that is presumed dead. * * Parameters: * (Integer) i - The index of the request in the queue. */ _restartRequest: function (i) { var req = this._requests[i]; if (req.dead === null) { req.dead = new Date(); } this._processRequest(i); }, /** PrivateFunction: _processRequest * _Private_ function to process a request in the queue. * * This function takes requests off the queue and sends them and * restarts dead requests. * * Parameters: * (Integer) i - The index of the request in the queue. */ _processRequest: function (i) { var req = this._requests[i]; var reqStatus = -1; try { if (req.xhr.readyState == 4) { reqStatus = req.xhr.status; } } catch (e) { Strophe.error("caught an error in _requests[" + i + "], reqStatus: " + reqStatus); } if (typeof(reqStatus) == "undefined") { reqStatus = -1; } var time_elapsed = req.age(); var primaryTimeout = (!isNaN(time_elapsed) && time_elapsed > Math.floor(Strophe.TIMEOUT * this.wait)); var secondaryTimeout = (req.dead !== null && req.timeDead() > Math.floor(Strophe.SECONDARY_TIMEOUT * this.wait)); var requestCompletedWithServerError = (req.xhr.readyState == 4 && (reqStatus < 1 || reqStatus >= 500)); if (primaryTimeout || secondaryTimeout || requestCompletedWithServerError) { if (secondaryTimeout) { Strophe.error("Request " + this._requests[i].id + " timed out (secondary), restarting"); } req.abort = true; req.xhr.abort(); // setting to null fails on IE6, so set to empty function req.xhr.onreadystatechange = function () {}; this._requests[i] = new Strophe.Request(req.xmlData, req.origFunc, req.rid, req.sends); req = this._requests[i]; } if (req.xhr.readyState === 0) { Strophe.debug("request id " + req.id + "." + req.sends + " posting"); req.date = new Date(); try { req.xhr.open("POST", this.service, true); } catch (e2) { Strophe.error("XHR open failed."); if (!this.connected) { this._changeConnectStatus(Strophe.Status.CONNFAIL, "bad-service"); } this.disconnect(); return; } // Fires the XHR request -- may be invoked immediately // or on a gradually expanding retry window for reconnects var sendFunc = function () { req.xhr.send(req.data); }; // Implement progressive backoff for reconnects -- // First retry (send == 1) should also be instantaneous if (req.sends > 1) { // Using a cube of the retry number creats a nicely // expanding retry window var backoff = Math.pow(req.sends, 3) * 1000; setTimeout(sendFunc, backoff); } else { sendFunc(); } req.sends++; this.xmlOutput(req.xmlData); this.rawOutput(req.data); } else { Strophe.debug("_processRequest: " + (i === 0 ? "first" : "second") + " request has readyState of " + req.xhr.readyState); } }, /** PrivateFunction: _throttledRequestHandler * _Private_ function to throttle requests to the connection window. * * This function makes sure we don't send requests so fast that the * request ids overflow the connection window in the case that one * request died. */ _throttledRequestHandler: function () { if (!this._requests) { Strophe.debug("_throttledRequestHandler called with " + "undefined requests"); } else { Strophe.debug("_throttledRequestHandler called with " + this._requests.length + " requests"); } if (!this._requests || this._requests.length === 0) { return; } if (this._requests.length > 0) { this._processRequest(0); } if (this._requests.length > 1 && Math.abs(this._requests[0].rid - this._requests[1].rid) < this.window - 1) { this._processRequest(1); } }, /** PrivateFunction: _onRequestStateChange * _Private_ handler for Strophe.Request state changes. * * This function is called when the XMLHttpRequest readyState changes. * It contains a lot of error handling logic for the many ways that * requests can fail, and calls the request callback when requests * succeed. * * Parameters: * (Function) func - The handler for the request. * (Strophe.Request) req - The request that is changing readyState. */ _onRequestStateChange: function (func, req) { Strophe.debug("request id " + req.id + "." + req.sends + " state changed to " + req.xhr.readyState); if (req.abort) { req.abort = false; return; } // request complete var reqStatus; if (req.xhr.readyState == 4) { reqStatus = 0; try { reqStatus = req.xhr.status; } catch (e) { // ignore errors from undefined status attribute. works // around a browser bug } if (typeof(reqStatus) == "undefined") { reqStatus = 0; } if (this.disconnecting) { if (reqStatus >= 400) { this._hitError(reqStatus); return; } } var reqIs0 = (this._requests[0] == req); var reqIs1 = (this._requests[1] == req); if ((reqStatus > 0 && reqStatus < 500) || req.sends > 5) { // remove from internal queue this._removeRequest(req); Strophe.debug("request id " + req.id + " should now be removed"); } // request succeeded if (reqStatus == 200) { // if request 1 finished, or request 0 finished and request // 1 is over Strophe.SECONDARY_TIMEOUT seconds old, we need to // restart the other - both will be in the first spot, as the // completed request has been removed from the queue already if (reqIs1 || (reqIs0 && this._requests.length > 0 && this._requests[0].age() > Math.floor(Strophe.SECONDARY_TIMEOUT * this.wait))) { this._restartRequest(0); } // call handler Strophe.debug("request id " + req.id + "." + req.sends + " got 200"); func(req); this.errors = 0; } else { Strophe.error("request id " + req.id + "." + req.sends + " error " + reqStatus + " happened"); if (reqStatus === 0 || (reqStatus >= 400 && reqStatus < 600) || reqStatus >= 12000) { this._hitError(reqStatus); if (reqStatus >= 400 && reqStatus < 500) { this._changeConnectStatus(Strophe.Status.DISCONNECTING, null); this._doDisconnect(); } } } if (!((reqStatus > 0 && reqStatus < 10000) || req.sends > 5)) { this._throttledRequestHandler(); } } }, /** PrivateFunction: _hitError * _Private_ function to handle the error count. * * Requests are resent automatically until their error count reaches * 5. Each time an error is encountered, this function is called to * increment the count and disconnect if the count is too high. * * Parameters: * (Integer) reqStatus - The request status. */ _hitError: function (reqStatus) { this.errors++; Strophe.warn("request errored, status: " + reqStatus + ", number of errors: " + this.errors); if (this.errors > 4) { this._onDisconnectTimeout(); } }, /** PrivateFunction: _doDisconnect * _Private_ function to disconnect. * * This is the last piece of the disconnection logic. This resets the * connection and alerts the user's connection callback. */ _doDisconnect: function () { Strophe.info("_doDisconnect was called"); this.authenticated = false; this.disconnecting = false; this.sid = null; this.streamId = null; this.rid = Math.floor(Math.random() * 4294967295); // tell the parent we disconnected if (this.connected) { this._changeConnectStatus(Strophe.Status.DISCONNECTED, null); this.connected = false; } // delete handlers this.handlers = []; this.timedHandlers = []; this.removeTimeds = []; this.removeHandlers = []; this.addTimeds = []; this.addHandlers = []; }, /** PrivateFunction: _dataRecv * _Private_ handler to processes incoming data from the the connection. * * Except for _connect_cb handling the initial connection request, * this function handles the incoming data for all requests. This * function also fires stanza handlers that match each incoming * stanza. * * Parameters: * (Strophe.Request) req - The request that has data ready. */ _dataRecv: function (req) { try { var elem = req.getResponse(); } catch (e) { if (e != "parsererror") { throw e; } this.disconnect("strophe-parsererror"); } if (elem === null) { return; } this.xmlInput(elem); this.rawInput(Strophe.serialize(elem)); // remove handlers scheduled for deletion var i, hand; while (this.removeHandlers.length > 0) { hand = this.removeHandlers.pop(); i = this.handlers.indexOf(hand); if (i >= 0) { this.handlers.splice(i, 1); } } // add handlers scheduled for addition while (this.addHandlers.length > 0) { this.handlers.push(this.addHandlers.pop()); } // handle graceful disconnect if (this.disconnecting && this._requests.length === 0) { this.deleteTimedHandler(this._disconnectTimeout); this._disconnectTimeout = null; this._doDisconnect(); return; } var typ = elem.getAttribute("type"); var cond, conflict; if (typ !== null && typ == "terminate") { // an error occurred cond = elem.getAttribute("condition"); conflict = elem.getElementsByTagName("conflict"); if (cond !== null) { if (cond == "remote-stream-error" && conflict.length > 0) { cond = "conflict"; } this._changeConnectStatus(Strophe.Status.CONNFAIL, cond); } else { this._changeConnectStatus(Strophe.Status.CONNFAIL, "unknown"); } this.disconnect(); return; } // send each incoming stanza through the handler chain var self = this; Strophe.forEachChild(elem, null, function (child) { var i, newList; // process handlers newList = self.handlers; self.handlers = []; for (i = 0; i < newList.length; i++) { var hand = newList[i]; if (hand.isMatch(child) && (self.authenticated || !hand.user)) { if (hand.run(child)) { self.handlers.push(hand); } } else { self.handlers.push(hand); } } }); }, /** PrivateFunction: _sendTerminate * _Private_ function to send initial disconnect sequence. * * This is the first step in a graceful disconnect. It sends * the BOSH server a terminate body and includes an unavailable * presence if authentication has completed. */ _sendTerminate: function () { Strophe.info("_sendTerminate was called"); var body = this._buildBody().attrs({type: "terminate"}); if (this.authenticated) { body.c('presence', { xmlns: Strophe.NS.CLIENT, type: 'unavailable' }); } this.disconnecting = true; var req = new Strophe.Request(body.tree(), this._onRequestStateChange.bind(this) .prependArg(this._dataRecv.bind(this)), body.tree().getAttribute("rid")); this._requests.push(req); this._throttledRequestHandler(); }, /** PrivateFunction: _connect_cb * _Private_ handler for initial connection request. * * This handler is used to process the initial connection request * response from the BOSH server. It is used to set up authentication * handlers and start the authentication process. * * SASL authentication will be attempted if available, otherwise * the code will fall back to legacy authentication. * * Parameters: * (Strophe.Request) req - The current request. */ _connect_cb: function (req) { Strophe.info("_connect_cb was called"); this.connected = true; var bodyWrap = req.getResponse(); if (!bodyWrap) { return; } this.xmlInput(bodyWrap); this.rawInput(Strophe.serialize(bodyWrap)); var typ = bodyWrap.getAttribute("type"); var cond, conflict; if (typ !== null && typ == "terminate") { // an error occurred cond = bodyWrap.getAttribute("condition"); conflict = bodyWrap.getElementsByTagName("conflict"); if (cond !== null) { if (cond == "remote-stream-error" && conflict.length > 0) { cond = "conflict"; } this._changeConnectStatus(Strophe.Status.CONNFAIL, cond); } else { this._changeConnectStatus(Strophe.Status.CONNFAIL, "unknown"); } return; } // check to make sure we don't overwrite these if _connect_cb is // called multiple times in the case of missing stream:features if (!this.sid) { this.sid = bodyWrap.getAttribute("sid"); } if (!this.stream_id) { this.stream_id = bodyWrap.getAttribute("authid"); } var wind = bodyWrap.getAttribute('requests'); if (wind) { this.window = parseInt(wind, 10); } var hold = bodyWrap.getAttribute('hold'); if (hold) { this.hold = parseInt(hold, 10); } var wait = bodyWrap.getAttribute('wait'); if (wait) { this.wait = parseInt(wait, 10); } var do_sasl_plain = false; var do_sasl_digest_md5 = false; var do_sasl_anonymous = false; var mechanisms = bodyWrap.getElementsByTagName("mechanism"); var i, mech, auth_str, hashed_auth_str; if (mechanisms.length > 0) { for (i = 0; i < mechanisms.length; i++) { mech = Strophe.getText(mechanisms[i]); if (mech == 'DIGEST-MD5') { do_sasl_digest_md5 = true; } else if (mech == 'PLAIN') { do_sasl_plain = true; } else if (mech == 'ANONYMOUS') { do_sasl_anonymous = true; } } } else { // we didn't get stream:features yet, so we need wait for it // by sending a blank poll request var body = this._buildBody(); this._requests.push( new Strophe.Request(body.tree(), this._onRequestStateChange.bind(this) .prependArg(this._connect_cb.bind(this)), body.tree().getAttribute("rid"))); this._throttledRequestHandler(); return; } if (Strophe.getNodeFromJid(this.jid) === null && do_sasl_anonymous) { this._changeConnectStatus(Strophe.Status.AUTHENTICATING, null); this._sasl_success_handler = this._addSysHandler( this._sasl_success_cb.bind(this), null, "success", null, null); this._sasl_failure_handler = this._addSysHandler( this._sasl_failure_cb.bind(this), null, "failure", null, null); this.send($build("auth", { xmlns: Strophe.NS.SASL, mechanism: "ANONYMOUS" }).tree()); } else if (Strophe.getNodeFromJid(this.jid) === null) { // we don't have a node, which is required for non-anonymous // client connections this._changeConnectStatus(Strophe.Status.CONNFAIL, 'x-strophe-bad-non-anon-jid'); this.disconnect(); } else if (do_sasl_digest_md5) { this._changeConnectStatus(Strophe.Status.AUTHENTICATING, null); this._sasl_challenge_handler = this._addSysHandler( this._sasl_challenge1_cb.bind(this), null, "challenge", null, null); this._sasl_failure_handler = this._addSysHandler( this._sasl_failure_cb.bind(this), null, "failure", null, null); this.send($build("auth", { xmlns: Strophe.NS.SASL, mechanism: "DIGEST-MD5" }).tree()); } else if (do_sasl_plain) { // Build the plain auth string (barejid null // username null password) and base 64 encoded. auth_str = Strophe.getBareJidFromJid(this.jid); auth_str = auth_str + "\u0000"; auth_str = auth_str + Strophe.getNodeFromJid(this.jid); auth_str = auth_str + "\u0000"; auth_str = auth_str + this.pass; this._changeConnectStatus(Strophe.Status.AUTHENTICATING, null); this._sasl_success_handler = this._addSysHandler( this._sasl_success_cb.bind(this), null, "success", null, null); this._sasl_failure_handler = this._addSysHandler( this._sasl_failure_cb.bind(this), null, "failure", null, null); hashed_auth_str = Base64.encode(auth_str); this.send($build("auth", { xmlns: Strophe.NS.SASL, mechanism: "PLAIN" }).t(hashed_auth_str).tree()); } else { this._changeConnectStatus(Strophe.Status.AUTHENTICATING, null); this._addSysHandler(this._auth1_cb.bind(this), null, null, null, "_auth_1"); this.send($iq({ type: "get", to: this.domain, id: "_auth_1" }).c("query", { xmlns: Strophe.NS.AUTH }).c("username", {}).t(Strophe.getNodeFromJid(this.jid)).tree()); } }, /** PrivateFunction: _sasl_challenge1_cb * _Private_ handler for DIGEST-MD5 SASL authentication. * * Parameters: * (XMLElement) elem - The challenge stanza. * * Returns: * false to remove the handler. */ _sasl_challenge1_cb: function (elem) { var attribMatch = /([a-z]+)=("[^"]+"|[^,"]+)(?:,|$)/; var challenge = Base64.decode(Strophe.getText(elem)); var cnonce = MD5.hexdigest(Math.random() * 1234567890); var realm = ""; var host = null; var nonce = ""; var qop = ""; var matches; // remove unneeded handlers this.deleteHandler(this._sasl_failure_handler); while (challenge.match(attribMatch)) { matches = challenge.match(attribMatch); challenge = challenge.replace(matches[0], ""); matches[2] = matches[2].replace(/^"(.+)"$/, "$1"); switch (matches[1]) { case "realm": realm = matches[2]; break; case "nonce": nonce = matches[2]; break; case "qop": qop = matches[2]; break; case "host": host = matches[2]; break; } } var digest_uri = "xmpp/" + this.domain; if (host !== null) { digest_uri = digest_uri + "/" + host; } var A1 = MD5.hash(Strophe.getNodeFromJid(this.jid) + ":" + realm + ":" + this.pass) + ":" + nonce + ":" + cnonce; var A2 = 'AUTHENTICATE:' + digest_uri; var responseText = ""; responseText += 'username=' + this._quote(Strophe.getNodeFromJid(this.jid)) + ','; responseText += 'realm=' + this._quote(realm) + ','; responseText += 'nonce=' + this._quote(nonce) + ','; responseText += 'cnonce=' + this._quote(cnonce) + ','; responseText += 'nc="00000001",'; responseText += 'qop="auth",'; responseText += 'digest-uri=' + this._quote(digest_uri) + ','; responseText += 'response=' + this._quote( MD5.hexdigest(MD5.hexdigest(A1) + ":" + nonce + ":00000001:" + cnonce + ":auth:" + MD5.hexdigest(A2))) + ','; responseText += 'charset="utf-8"'; this._sasl_challenge_handler = this._addSysHandler( this._sasl_challenge2_cb.bind(this), null, "challenge", null, null); this._sasl_success_handler = this._addSysHandler( this._sasl_success_cb.bind(this), null, "success", null, null); this._sasl_failure_handler = this._addSysHandler( this._sasl_failure_cb.bind(this), null, "failure", null, null); this.send($build('response', { xmlns: Strophe.NS.SASL }).t(Base64.encode(responseText)).tree()); return false; }, /** PrivateFunction: _quote * _Private_ utility function to backslash escape and quote strings. * * Parameters: * (String) str - The string to be quoted. * * Returns: * quoted string */ _quote: function (str) { return '"' + str.replace(/\\/g, "\\\\").replace(/"/g, '\\"') + '"'; //" end string workaround for emacs }, /** PrivateFunction: _sasl_challenge2_cb * _Private_ handler for second step of DIGEST-MD5 SASL authentication. * * Parameters: * (XMLElement) elem - The challenge stanza. * * Returns: * false to remove the handler. */ _sasl_challenge2_cb: function (elem) { // remove unneeded handlers this.deleteHandler(this._sasl_success_handler); this.deleteHandler(this._sasl_failure_handler); this._sasl_success_handler = this._addSysHandler( this._sasl_success_cb.bind(this), null, "success", null, null); this._sasl_failure_handler = this._addSysHandler( this._sasl_failure_cb.bind(this), null, "failure", null, null); this.send($build('response', {xmlns: Strophe.NS.SASL}).tree()); return false; }, /** PrivateFunction: _auth1_cb * _Private_ handler for legacy authentication. * * This handler is called in response to the initial * for legacy authentication. It builds an authentication and * sends it, creating a handler (calling back to _auth2_cb()) to * handle the result * * Parameters: * (XMLElement) elem - The stanza that triggered the callback. * * Returns: * false to remove the handler. */ _auth1_cb: function (elem) { // build plaintext auth iq var iq = $iq({type: "set", id: "_auth_2"}) .c('query', {xmlns: Strophe.NS.AUTH}) .c('username', {}).t(Strophe.getNodeFromJid(this.jid)) .up() .c('password').t(this.pass); if (!Strophe.getResourceFromJid(this.jid)) { // since the user has not supplied a resource, we pick // a default one here. unlike other auth methods, the server // cannot do this for us. this.jid = Strophe.getBareJidFromJid(this.jid) + '/strophe'; } iq.up().c('resource', {}).t(Strophe.getResourceFromJid(this.jid)); this._addSysHandler(this._auth2_cb.bind(this), null, null, null, "_auth_2"); this.send(iq.tree()); return false; }, /** PrivateFunction: _sasl_success_cb * _Private_ handler for succesful SASL authentication. * * Parameters: * (XMLElement) elem - The matching stanza. * * Returns: * false to remove the handler. */ _sasl_success_cb: function (elem) { Strophe.info("SASL authentication succeeded."); // remove old handlers this.deleteHandler(this._sasl_failure_handler); this._sasl_failure_handler = null; if (this._sasl_challenge_handler) { this.deleteHandler(this._sasl_challenge_handler); this._sasl_challenge_handler = null; } this._addSysHandler(this._sasl_auth1_cb.bind(this), null, "stream:features", null, null); // we must send an xmpp:restart now this._sendRestart(); return false; }, /** PrivateFunction: _sasl_auth1_cb * _Private_ handler to start stream binding. * * Parameters: * (XMLElement) elem - The matching stanza. * * Returns: * false to remove the handler. */ _sasl_auth1_cb: function (elem) { var i, child; for (i = 0; i < elem.childNodes.length; i++) { child = elem.childNodes[i]; if (child.nodeName == 'bind') { this.do_bind = true; } if (child.nodeName == 'session') { this.do_session = true; } } if (!this.do_bind) { this._changeConnectStatus(Strophe.Status.AUTHFAIL, null); return false; } else { this._addSysHandler(this._sasl_bind_cb.bind(this), null, null, null, "_bind_auth_2"); var resource = Strophe.getResourceFromJid(this.jid); if (resource) { this.send($iq({type: "set", id: "_bind_auth_2"}) .c('bind', {xmlns: Strophe.NS.BIND}) .c('resource', {}).t(resource).tree()); } else { this.send($iq({type: "set", id: "_bind_auth_2"}) .c('bind', {xmlns: Strophe.NS.BIND}) .tree()); } } return false; }, /** PrivateFunction: _sasl_bind_cb * _Private_ handler for binding result and session start. * * Parameters: * (XMLElement) elem - The matching stanza. * * Returns: * false to remove the handler. */ _sasl_bind_cb: function (elem) { if (elem.getAttribute("type") == "error") { Strophe.info("SASL binding failed."); this._changeConnectStatus(Strophe.Status.AUTHFAIL, null); return false; } // TODO - need to grab errors var bind = elem.getElementsByTagName("bind"); var jidNode; if (bind.length > 0) { // Grab jid jidNode = bind[0].getElementsByTagName("jid"); if (jidNode.length > 0) { this.jid = Strophe.getText(jidNode[0]); if (this.do_session) { this._addSysHandler(this._sasl_session_cb.bind(this), null, null, null, "_session_auth_2"); this.send($iq({type: "set", id: "_session_auth_2"}) .c('session', {xmlns: Strophe.NS.SESSION}) .tree()); } else { this.authenticated = true; this._changeConnectStatus(Strophe.Status.CONNECTED, null); } } } else { Strophe.info("SASL binding failed."); this._changeConnectStatus(Strophe.Status.AUTHFAIL, null); return false; } }, /** PrivateFunction: _sasl_session_cb * _Private_ handler to finish successful SASL connection. * * This sets Connection.authenticated to true on success, which * starts the processing of user handlers. * * Parameters: * (XMLElement) elem - The matching stanza. * * Returns: * false to remove the handler. */ _sasl_session_cb: function (elem) { if (elem.getAttribute("type") == "result") { this.authenticated = true; this._changeConnectStatus(Strophe.Status.CONNECTED, null); } else if (elem.getAttribute("type") == "error") { Strophe.info("Session creation failed."); this._changeConnectStatus(Strophe.Status.AUTHFAIL, null); return false; } return false; }, /** PrivateFunction: _sasl_failure_cb * _Private_ handler for SASL authentication failure. * * Parameters: * (XMLElement) elem - The matching stanza. * * Returns: * false to remove the handler. */ _sasl_failure_cb: function (elem) { // delete unneeded handlers if (this._sasl_success_handler) { this.deleteHandler(this._sasl_success_handler); this._sasl_success_handler = null; } if (this._sasl_challenge_handler) { this.deleteHandler(this._sasl_challenge_handler); this._sasl_challenge_handler = null; } this._changeConnectStatus(Strophe.Status.AUTHFAIL, null); return false; }, /** PrivateFunction: _auth2_cb * _Private_ handler to finish legacy authentication. * * This handler is called when the result from the jabber:iq:auth * stanza is returned. * * Parameters: * (XMLElement) elem - The stanza that triggered the callback. * * Returns: * false to remove the handler. */ _auth2_cb: function (elem) { if (elem.getAttribute("type") == "result") { this.authenticated = true; this._changeConnectStatus(Strophe.Status.CONNECTED, null); } else if (elem.getAttribute("type") == "error") { this._changeConnectStatus(Strophe.Status.AUTHFAIL, null); this.disconnect(); } return false; }, /** PrivateFunction: _addSysTimedHandler * _Private_ function to add a system level timed handler. * * This function is used to add a Strophe.TimedHandler for the * library code. System timed handlers are allowed to run before * authentication is complete. * * Parameters: * (Integer) period - The period of the handler. * (Function) handler - The callback function. */ _addSysTimedHandler: function (period, handler) { var thand = new Strophe.TimedHandler(period, handler); thand.user = false; this.addTimeds.push(thand); return thand; }, /** PrivateFunction: _addSysHandler * _Private_ function to add a system level stanza handler. * * This function is used to add a Strophe.Handler for the * library code. System stanza handlers are allowed to run before * authentication is complete. * * Parameters: * (Function) handler - The callback function. * (String) ns - The namespace to match. * (String) name - The stanza name to match. * (String) type - The stanza type attribute to match. * (String) id - The stanza id attribute to match. */ _addSysHandler: function (handler, ns, name, type, id) { var hand = new Strophe.Handler(handler, ns, name, type, id); hand.user = false; this.addHandlers.push(hand); return hand; }, /** PrivateFunction: _onDisconnectTimeout * _Private_ timeout handler for handling non-graceful disconnection. * * If the graceful disconnect process does not complete within the * time allotted, this handler finishes the disconnect anyway. * * Returns: * false to remove the handler. */ _onDisconnectTimeout: function () { Strophe.info("_onDisconnectTimeout was called"); // cancel all remaining requests and clear the queue var req; while (this._requests.length > 0) { req = this._requests.pop(); req.abort = true; req.xhr.abort(); // jslint complains, but this is fine. setting to empty func // is necessary for IE6 req.xhr.onreadystatechange = function () {}; } // actually disconnect this._doDisconnect(); return false; }, /** PrivateFunction: _onIdle * _Private_ handler to process events during idle cycle. * * This handler is called every 100ms to fire timed handlers that * are ready and keep poll requests going. */ _onIdle: function () { var i, thand, since, newList; // remove timed handlers that have been scheduled for deletion while (this.removeTimeds.length > 0) { thand = this.removeTimeds.pop(); i = this.timedHandlers.indexOf(thand); if (i >= 0) { this.timedHandlers.splice(i, 1); } } // add timed handlers scheduled for addition while (this.addTimeds.length > 0) { this.timedHandlers.push(this.addTimeds.pop()); } // call ready timed handlers var now = new Date().getTime(); newList = []; for (i = 0; i < this.timedHandlers.length; i++) { thand = this.timedHandlers[i]; if (this.authenticated || !thand.user) { since = thand.lastCalled + thand.period; if (since - now <= 0) { if (thand.run()) { newList.push(thand); } } else { newList.push(thand); } } } this.timedHandlers = newList; var body, time_elapsed; // if no requests are in progress, poll if (this.authenticated && this._requests.length === 0 && this._data.length === 0 && !this.disconnecting) { Strophe.info("no requests during idle cycle, sending " + "blank request"); this._data.push(null); } if (this._requests.length < 2 && this._data.length > 0 && !this.paused) { body = this._buildBody(); for (i = 0; i < this._data.length; i++) { if (this._data[i] !== null) { if (this._data[i] === "restart") { body.attrs({ to: this.domain, "xml:lang": "en", "xmpp:restart": "true", "xmlns:xmpp": Strophe.NS.BOSH }); } else { body.cnode(this._data[i]).up(); } } } delete this._data; this._data = []; this._requests.push( new Strophe.Request(body.tree(), this._onRequestStateChange.bind(this) .prependArg(this._dataRecv.bind(this)), body.tree().getAttribute("rid"))); this._processRequest(this._requests.length - 1); } if (this._requests.length > 0) { time_elapsed = this._requests[0].age(); if (this._requests[0].dead !== null) { if (this._requests[0].timeDead() > Math.floor(Strophe.SECONDARY_TIMEOUT * this.wait)) { this._throttledRequestHandler(); } } if (time_elapsed > Math.floor(Strophe.TIMEOUT * this.wait)) { Strophe.warn("Request " + this._requests[0].id + " timed out, over " + Math.floor(Strophe.TIMEOUT * this.wait) + " seconds since last activity"); this._throttledRequestHandler(); } } // reactivate the timer clearTimeout(this._idleTimeout); this._idleTimeout = setTimeout(this._onIdle.bind(this), 100); } }; if (callback) { callback(Strophe, $build, $msg, $iq, $pres); } })(function () { window.Strophe = arguments[0]; window.$build = arguments[1]; window.$msg = arguments[2]; window.$iq = arguments[3]; window.$pres = arguments[4]; }); strophejs-1.0.1.dfsg/tests/000077500000000000000000000000001137577172600156365ustar00rootroot00000000000000strophejs-1.0.1.dfsg/tests/jstests.js000066400000000000000000000124211137577172600176730ustar00rootroot00000000000000TestCase("JIDs", { testNormalJid: function () { var jid = "darcy@pemberley.lit/library"; assertEquals("Node should be 'darcy'", "darcy", Strophe.getNodeFromJid(jid)); assertEquals("Domain should be 'pemberley.lit'", "pemberley.lit", Strophe.getDomainFromJid(jid)); assertEquals("Resource should be 'library'", "library", Strophe.getResourceFromJid(jid)); assertEquals("Bare JID should be 'darcy@pemberley.lit'", "darcy@pemberley.lit", Strophe.getBareJidFromJid(jid)); }, testWeirdNode: function () { var jid = "darcy@netherfield.lit@pemberley.lit/library"; assertEquals("Node should be 'darcy'", "darcy", Strophe.getNodeFromJid(jid)); assertEquals("Domain should be 'netherfield.lit@pemberley.lit'", "netherfield.lit@pemberley.lit", Strophe.getDomainFromJid(jid)); assertEquals("Resource should be 'library'", "library", Strophe.getResourceFromJid(jid)); assertEquals("Bare JID should be 'darcy@netherfield.lit@pemberley.lit", "darcy@netherfield.lit@pemberley.lit", Strophe.getBareJidFromJid(jid)); } }); function foo() { var $ = function () {}; test("Weird node (escaped)", function () { var escapedNode = Strophe.escapeNode("darcy@netherfield.lit"); var jid = escapedNode + "@pemberley.lit/library"; equals(Strophe.getNodeFromJid(jid), "darcy\\40netherfield.lit", "Node should be 'darcy\\40netherfield.lit'"); equals(Strophe.getDomainFromJid(jid), "pemberley.lit", "Domain should be 'pemberley.lit'"); equals(Strophe.getResourceFromJid(jid), "library", "Resource should be 'library'"); equals(Strophe.getBareJidFromJid(jid), "darcy\\40netherfield.lit@pemberley.lit", "Bare JID should be 'darcy\\40netherfield.lit@pemberley.lit'"); }); test("Weird resource", function () { var jid = "books@chat.pemberley.lit/darcy@pemberley.lit/library"; equals(Strophe.getNodeFromJid(jid), "books", "Node should be 'books'"); equals(Strophe.getDomainFromJid(jid), "chat.pemberley.lit", "Domain should be 'chat.pemberley.lit'"); equals(Strophe.getResourceFromJid(jid), "darcy@pemberley.lit/library", "Resource should be 'darcy@pemberley.lit/library'"); equals(Strophe.getBareJidFromJid(jid), "books@chat.pemberley.lit", "Bare JID should be 'books@chat.pemberley.lit'"); }); module("Builder"); test("Correct namespace (#32)", function () { var stanzas = [new Strophe.Builder("message", {foo: "asdf"}).tree(), $build("iq", {}).tree(), $pres().tree()]; $.each(stanzas, function () { equals($(this).attr('xmlns'), Strophe.NS.CLIENT, "Namespace should be '" + Strophe.NS.CLIENT + "'"); }); }); test("send() accepts Builders (#27)", function () { var stanza = $pres(); var conn = new Strophe.Connection(""); // fake connection callback to avoid errors conn.connect_callback = function () {}; ok(conn._data.length === 0, "Output queue is clean"); try { conn.send(stanza); } catch (e) {} ok(conn._data.length === 1, "Output queue contains an element"); }); test("send() does not accept strings", function () { var stanza = ""; var conn = new Strophe.Connection(""); // fake connection callback to avoid errors conn.connect_callback = function () {}; expect(1); try { conn.send(stanza); } catch (e) { equals(e.name, "StropheError", "send() should throw exception"); } }); test("Builder with XML attribute escaping test", function () { var text = ""; var expected = ""; var pres = $pres({to: text}); equals(pres.toString(), expected, "< should be escaped"); text = "foo&bar"; expected = ""; pres = $pres({to: text}); equals(pres.toString(), expected, "& should be escaped"); }); module("XML"); test("XML escaping test", function () { var text = "s & p"; var textNode = Strophe.xmlTextNode(text); equals(Strophe.getText(textNode), "s & p", "should be escaped"); var text0 = "s < & > p"; var textNode0 = Strophe.xmlTextNode(text0); equals(Strophe.getText(textNode0), "s < & > p", "should be escaped"); }); test("XML element creation", function () { var elem = Strophe.xmlElement("message"); equals(elem.tagName, "message", "Element name should be the same"); }); module("Misc"); test("Quoting strings", function () { var input = '"beep \\40"'; var conn = new Strophe.Connection(); var output = conn._quote(input); equals(output, "\"\\\"beep \\\\40\\\"\"", "string should be quoted and escaped"); }); } strophejs-1.0.1.dfsg/tests/jsyuitests.js000066400000000000000000000017211137577172600204230ustar00rootroot00000000000000YUI.add('strophe.test', function (Y) { Y.namespace("strophe.test"); var R = Y.namespace("strophe.test.Runner"); R.add = function (suite) { for (var i = 0; i < suite.items.length; i++) { TestCase(suite.items[i].name, suite.items[i]); } }; }, '1.0', {requires: ['test']}); YUI().use("test", "strophe.test", function (Y) { var Assert = Y.Assert; var suite = new Y.Test.Suite("Strophe Tests"); suite.add(new Y.Test.Case({ name: "JIDs", testNormalJid: function () { var jid = "darcy@pemberley.lit/library"; Assert.areSame("darcy", Strophe.getNodeFromJid(jid)); Assert.areSame("pemberley.lit", Strophe.getDomainFromJid(jid)); Assert.areSame("library", Strophe.getResourceFromJid(jid)); Assert.areSame("darcy@pemberley.lit", Strophe.getBareJidFromJid(jid)); } })); Y.strophe.test.Runner.add(suite); }); strophejs-1.0.1.dfsg/tests/pubsub.html000066400000000000000000000016221137577172600200250ustar00rootroot00000000000000

QUnit tests for Strophe

    strophejs-1.0.1.dfsg/tests/pubsub.js000066400000000000000000000226351137577172600175040ustar00rootroot00000000000000 Strophe.Test = { BOSH_URL: "/xmpp-httpbind", XMPP_DOMAIN: 'localhost', PUBSUB_COMPONENT: "pubsub.localhost", _node_name: "", //node name created in connectCallback function connection: null, //connection object created in run function run: function() { $(document).ready(function(){ //Connect strophe, uses localhost to test Strophe.Test.connection = new Strophe.Connection(Strophe.Test.BOSH_URL); //connect anonymously to run most tests Strophe.Test.connection.connect(Strophe.Test.XMPP_DOMAIN, null, Strophe.Test.connectCallback); //set up the test client UI $("#disconnect").click(function() { Strophe.Test.connection.disconnect(); }); $("#run_tests").click(function() { test("Anonymous connection test.", function() { if(Strophe.Test.connection.connected) { ok( true, "all good"); } else { ok( false, "not connected anonymously"); } }); test("Create default node test.",function(){ var iqid = Strophe.Test.connection.pubsub .createNode(Strophe.Test.connection.jid, Strophe.Test.PUBSUB_COMPONENT, Strophe.Test._node_name, {}, function(stanza) { test("handled create node.", function() { var error = $(stanza).find("error"); if(error.length == 0) { ok(true, "returned"); } else { ok(false,"error creating node."); } }); }); ok(true,"sent create request. "+ iqid); }); test("subscribe to a node",function() { var iqid = Strophe.Test.connection.pubsub .subscribe(Strophe.Test.connection.jid, Strophe.Test.PUBSUB_COMPONENT, Strophe.Test._node_name, [], function(stanza) { test("items received", function() { console.log(stanza); if($(stanza).length > 0) { ok(true,"item received."); } else { ok(false,"no items."); } }); }, function(stanza) { var error = $(stanza).find("error"); test("handled subscribe", function() { if(error.length == 0) { ok(true,"subscribed"); } else { console.log(error.get(0)); ok(false, "not subscribed"); } }); }); if(iqid) ok(true, "subscribed to " + Strophe.Test._node_name); }); test("publish to a node",function() { var iqid = Strophe.Test.connection.pubsub .publish(Strophe.Test.connection.jid, Strophe.Test.PUBSUB_COMPONENT, Strophe.Test._node_name, {test:'test'}, function(stanza) { var error = $(stanza).find("error"); test("handled published item", function() { if(error.length == 0) { ok(true,"got item"); } else { ok(false, "no item"); } }); }); if(iqid) ok(true, "published to " + Strophe.Test._node_name); }); test("subscribe to a node with options",function() { var keyword_elem = Strophe.xmlElement("field", [["var", "http://stanziq.com/search#keyword"], ["type", 'text-single'], ["label", "keyword to match"]]); var value = Strophe.xmlElement("value",[]); var text = Strophe.xmlTextNode("crazy"); value.appendChild(text); keyword_elem.appendChild(value); var iqid = Strophe.Test.connection.pubsub .subscribe(Strophe.Test.connection.jid, Strophe.Test.PUBSUB_COMPONENT, Strophe.Test._node_name, [keyword_elem], function(stanza) {console.log(stanza);}, function(stanza) { var error = $(stanza).find("error"); test("handled subscribe with options", function() { if(error.length == 0) { ok(true,"search subscribed"); } else { console.log(error.get(0)); ok(false, "search not subscribed"); } }); }); if(iqid) ok(true, "subscribed to search"); }); test("unsubscribe to a node",function() { var iqid = Strophe.Test.connection.pubsub .unsubscribe(Strophe.Test.connection.jid, Strophe.Test.PUBSUB_COMPONENT, Strophe.Test._node_name, function(stanza) { var error = $(stanza).find("error"); test("handled unsubscribe", function() { if(error.length == 0) { ok(true,"unsubscribed"); } else { console.log(error.get(0)); ok(false, "unable to unsubscribed"); } }); }); if(iqid) ok(true, "unsubscribed from search with no options."); }); test("test items retrieval",function(){ var itemid = Strophe.Test.connection.pubsub .items(Strophe.Test.connection.jid, Strophe.Test.PUBSUB_COMPONENT, Strophe.Test._node_name, function(stanza) { ok(true,"item request successful."); }, function(stanza) { ok(false,"failed to send request."); }); if(itemid) { ok(true,"item request sent."); } }); test("test sendIQ interface.",function(){ var sendiq_good = false; //setup timeout for sendIQ for 3 seconds setTimeout(function() { test("Timeout check", function () { ok(sendiq_good, "The iq didn't timeout."); }); }, 3000); //send a pubsub subscribe stanza var sub = $iq({from:Strophe.Test.connection.jid, to:Strophe.Test.PUBSUB_COMPONENT, type:'set'}) .c('pubsub', { xmlns:Strophe.NS.PUBSUB }) .c('subscribe', {node:Strophe.Test._node_name, jid:Strophe.Test.connection.jid}); var stanza=sub.tree(); //call sendIQ with several call backs Strophe.Test.connection .sendIQ(stanza, function(stanza) { test("iq sent",function() { sendiq_good = true; ok(true,"iq sent succesfully."); }); }, function(stz) { test("iq fail",function() { if (stz) sendiq_good = true; console.log(stanza); ok(true,"failed to send iq."); }); }); }); test("test sendIQ failed.",function(){ var sub = $iq({from:Strophe.Test.connection.jid, to:Strophe.Test.PUBSUB_COMPONENT, type:'get'}); //call sendIQ with several call backs Strophe.Test.connection .sendIQ(sub.tree(), function(stanza) { console.log(stanza); test("iq sent",function() { ok(false, "iq sent succesfully when should have failed."); }); }, function(stanza) { test("iq fail",function() { ok(true, "success on failure test: failed to send iq."); }); }); }); }); }); }, connectCallback: function(status,cond) { var error_message = null; if(status == Strophe.Status.CONNECTED) { $('#run_tests').show(); $('#disconnect').show(); var bare_jid = Strophe.getBareJidFromJid(Strophe.Test.connection.jid).split("@")[0]; Strophe.Test._node_name = "/home/"+Strophe.Test.XMPP_DOMAIN+"/"+bare_jid; } else if (status == Strophe.Status.DISCONNECTED || status == Strophe.Status.DICONNECTING) { $('#run_tests').hide(); $('#disconnect').hide(); } else if ((status == 0) || (status == Strophe.Status.CONNFAIL)) { error_message = "Failed to connect to xmpp server."; } else if (status == Strophe.Status.AUTHFAIL) { error_message = "Failed to authenticate to xmpp server."; } if(error_message) { $('published_item').text(error_message); } } }; strophejs-1.0.1.dfsg/tests/strophe.html000066400000000000000000000013211137577172600202050ustar00rootroot00000000000000 Strophe.js Tests

    Strophe.js Tests

      strophejs-1.0.1.dfsg/tests/testrunner.js000066400000000000000000000502661137577172600204160ustar00rootroot00000000000000/* * QUnit - jQuery unit testrunner * * http://docs.jquery.com/QUnit * * Copyright (c) 2008 John Resig, Jörn Zaefferer * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * $Id$ */ (function($) { // Tests for equality any JavaScript type and structure without unexpected results. // Discussions and reference: http://philrathe.com/articles/equiv // Test suites: http://philrathe.com/tests/equiv // Author: Philippe Rathé var equiv = function () { var innerEquiv; // the real equiv function var callers = []; // stack to decide between skip/abort functions // Determine what is o. function hoozit(o) { if (typeof o === "string") { return "string"; } else if (typeof o === "boolean") { return "boolean"; } else if (typeof o === "number") { if (isNaN(o)) { return "nan"; } else { return "number"; } } else if (typeof o === "undefined") { return "undefined"; // consider: typeof null === object } else if (o === null) { return "null"; // consider: typeof [] === object } else if (o instanceof Array) { return "array"; // consider: typeof new Date() === object } else if (o instanceof Date) { return "date"; // consider: /./ instanceof Object; // /./ instanceof RegExp; // typeof /./ === "function"; // => false in IE and Opera, // true in FF and Safari } else if (o instanceof RegExp) { return "regexp"; } else if (typeof o === "object") { return "object"; } else if (o instanceof Function) { return "function"; } } // Call the o related callback with the given arguments. function bindCallbacks(o, callbacks, args) { var prop = hoozit(o); if (prop) { if (hoozit(callbacks[prop]) === "function") { return callbacks[prop].apply(callbacks, args); } else { return callbacks[prop]; // or undefined } } } var callbacks = function () { // for string, boolean, number and null function useStrictEquality(b, a) { return a === b; } return { "string": useStrictEquality, "boolean": useStrictEquality, "number": useStrictEquality, "null": useStrictEquality, "undefined": useStrictEquality, "nan": function (b) { return isNaN(b); }, "date": function (b, a) { return hoozit(b) === "date" && a.valueOf() === b.valueOf(); }, "regexp": function (b, a) { return hoozit(b) === "regexp" && a.source === b.source && // the regex itself a.global === b.global && // and its modifers (gmi) ... a.ignoreCase === b.ignoreCase && a.multiline === b.multiline; }, // - skip when the property is a method of an instance (OOP) // - abort otherwise, // initial === would have catch identical references anyway "function": function () { var caller = callers[callers.length - 1]; return caller !== Object && typeof caller !== "undefined"; }, "array": function (b, a) { var i; var len; // b could be an object literal here if ( ! (hoozit(b) === "array")) { return false; } len = a.length; if (len !== b.length) { // safe and faster return false; } for (i = 0; i < len; i++) { if( ! innerEquiv(a[i], b[i])) { return false; } } return true; }, "object": function (b, a) { var i; var eq = true; // unless we can proove it var aProperties = [], bProperties = []; // collection of strings // comparing constructors is more strict than using instanceof if ( a.constructor !== b.constructor) { return false; } // stack constructor before traversing properties callers.push(a.constructor); for (i in a) { // be strict: don't ensures hasOwnProperty and go deep aProperties.push(i); // collect a's properties if ( ! innerEquiv(a[i], b[i])) { eq = false; } } callers.pop(); // unstack, we are done for (i in b) { bProperties.push(i); // collect b's properties } // Ensures identical properties name return eq && innerEquiv(aProperties.sort(), bProperties.sort()); } }; }(); innerEquiv = function () { // can take multiple arguments var args = Array.prototype.slice.apply(arguments); if (args.length < 2) { return true; // end transition } return (function (a, b) { if (a === b) { return true; // catch the most you can } else if (typeof a !== typeof b || a === null || b === null || typeof a === "undefined" || typeof b === "undefined") { return false; // don't lose time with error prone cases } else { return bindCallbacks(a, callbacks, [b, a]); } // apply transition with (1..n) arguments })(args[0], args[1]) && arguments.callee.apply(this, args.splice(1, args.length -1)); }; return innerEquiv; }(); // equiv var config = { stats: { all: 0, bad: 0 }, queue: [], // block until document ready blocking: true, //restrict modules/tests by get parameters filters: location.search.length > 1 && $.map( location.search.slice(1).split('&'), decodeURIComponent ), isLocal: !!(window.location.protocol == 'file:') }; // public API as global methods $.extend(window, { test: test, module: module, expect: expect, ok: ok, equals: equals, start: start, stop: stop, reset: reset, isLocal: config.isLocal, same: function(a, b, message) { push(equiv(a, b), a, b, message); }, QUnit: { equiv: equiv }, // legacy methods below isSet: isSet, isObj: isObj, compare: function() { throw "compare is deprecated - use same() instead"; }, compare2: function() { throw "compare2 is deprecated - use same() instead"; }, serialArray: function() { throw "serialArray is deprecated - use jsDump.parse() instead"; }, q: q, t: t, url: url, triggerEvent: triggerEvent }); $(window).load(function() { $('#userAgent').html(navigator.userAgent); var head = $('
      ').insertAfter("#userAgent"); $('').attr("disabled", true).prependTo(head).click(function() { $('li.pass')[this.checked ? 'hide' : 'show'](); }); runTest(); }); function synchronize(callback) { config.queue.push(callback); if(!config.blocking) { process(); } } function process() { while(config.queue.length && !config.blocking) { config.queue.shift()(); } } function stop(timeout) { config.blocking = true; if (timeout) config.timeout = setTimeout(function() { ok( false, "Test timed out" ); start(); }, timeout); } function start() { // A slight delay, to avoid any current callbacks setTimeout(function() { if(config.timeout) clearTimeout(config.timeout); config.blocking = false; process(); }, 13); } function validTest( name ) { var filters = config.filters; if( !filters ) return true; var i = filters.length, run = false; while( i-- ){ var filter = filters[i], not = filter.charAt(0) == '!'; if( not ) filter = filter.slice(1); if( name.indexOf(filter) != -1 ) return !not; if( not ) run = true; } return run; } function runTest() { config.blocking = false; var started = +new Date; config.fixture = document.getElementById('main').innerHTML; config.ajaxSettings = $.ajaxSettings; synchronize(function() { $('

      ').html(['Tests completed in ', +new Date - started, ' milliseconds.
      ', '', config.stats.bad, ' tests of ', config.stats.all, ' failed.

      '] .join('')) .appendTo("body"); $("#banner").addClass(config.stats.bad ? "fail" : "pass"); }); } function test(name, callback) { if(config.currentModule) name = config.currentModule + " module: " + name; var lifecycle = $.extend({ setup: function() {}, teardown: function() {} }, config.moduleLifecycle); if ( !validTest(name) ) return; synchronize(function() { config.assertions = []; config.expected = null; try { lifecycle.setup(); callback(); lifecycle.teardown(); } catch(e) { if( typeof console != "undefined" && console.error && console.warn ) { console.error("Test " + name + " died, exception and test follows"); console.error(e); console.warn(callback.toString()); } config.assertions.push( { result: false, message: "Died on test #" + (config.assertions.length + 1) + ": " + e.message }); } }); synchronize(function() { try { reset(); } catch(e) { if( typeof console != "undefined" && console.error && console.warn ) { console.error("reset() failed, following Test " + name + ", exception and reset fn follows"); console.error(e); console.warn(reset.toString()); } } if(config.expected && config.expected != config.assertions.length) { config.assertions.push({ result: false, message: "Expected " + config.expected + " assertions, but " + config.assertions.length + " were run" }); } var good = 0, bad = 0; var ol = $("
        ").hide(); config.stats.all += config.assertions.length; for ( var i = 0; i < config.assertions.length; i++ ) { var assertion = config.assertions[i]; $("
      1. ").addClass(assertion.result ? "pass" : "fail").text(assertion.message || "(no message)").appendTo(ol); assertion.result ? good++ : bad++; } config.stats.bad += bad; var b = $("").html(name + " (" + bad + ", " + good + ", " + config.assertions.length + ")") .click(function(){ $(this).next().toggle(); }) .dblclick(function(event) { var target = $(event.target).filter("strong").clone(); if ( target.length ) { target.children().remove(); location.href = location.href.match(/^(.+?)(\?.*)?$/)[1] + "?" + encodeURIComponent($.trim(target.text())); } }); $("
      2. ").addClass(bad ? "fail" : "pass").append(b).append(ol).appendTo("#tests"); if(bad) { $("#filter").attr("disabled", null); } }); } // call on start of module test to prepend name to all tests function module(name, lifecycle) { config.currentModule = name; config.moduleLifecycle = lifecycle; } /** * Specify the number of expected assertions to gurantee that failed test (no assertions are run at all) don't slip through. */ function expect(asserts) { config.expected = asserts; } /** * Resets the test setup. Useful for tests that modify the DOM. */ function reset() { $("#main").html( config.fixture ); $.event.global = {}; $.ajaxSettings = $.extend({}, config.ajaxSettings); } /** * Asserts true. * @example ok( $("a").size() > 5, "There must be at least 5 anchors" ); */ function ok(a, msg) { config.assertions.push({ result: !!a, message: msg }); } /** * Asserts that two arrays are the same */ function isSet(a, b, msg) { function serialArray( a ) { var r = []; if ( a && a.length ) for ( var i = 0; i < a.length; i++ ) { var str = a[i].nodeName; if ( str ) { str = str.toLowerCase(); if ( a[i].id ) str += "#" + a[i].id; } else str = a[i]; r.push( str ); } return "[ " + r.join(", ") + " ]"; } var ret = true; if ( a && b && a.length != undefined && a.length == b.length ) { for ( var i = 0; i < a.length; i++ ) if ( a[i] != b[i] ) ret = false; } else ret = false; config.assertions.push({ result: ret, message: !ret ? (msg + " expected: " + serialArray(b) + " result: " + serialArray(a)) : msg }); } /** * Asserts that two objects are equivalent */ function isObj(a, b, msg) { var ret = true; if ( a && b ) { for ( var i in a ) if ( a[i] != b[i] ) ret = false; for ( i in b ) if ( a[i] != b[i] ) ret = false; } else ret = false; config.assertions.push({ result: ret, message: msg }); } /** * Returns an array of elements with the given IDs, eg. * @example q("main", "foo", "bar") * @result [
        , , ] */ function q() { var r = []; for ( var i = 0; i < arguments.length; i++ ) r.push( document.getElementById( arguments[i] ) ); return r; } /** * Asserts that a select matches the given IDs * @example t("Check for something", "//[a]", ["foo", "baar"]); * @result returns true if "//[a]" return two elements with the IDs 'foo' and 'baar' */ function t(a,b,c) { var f = $(b); var s = ""; for ( var i = 0; i < f.length; i++ ) s += (s && ",") + '"' + f[i].id + '"'; isSet(f, q.apply(q,c), a + " (" + b + ")"); } /** * Add random number to url to stop IE from caching * * @example url("data/test.html") * @result "data/test.html?10538358428943" * * @example url("data/test.php?foo=bar") * @result "data/test.php?foo=bar&10538358345554" */ function url(value) { return value + (/\?/.test(value) ? "&" : "?") + new Date().getTime() + "" + parseInt(Math.random()*100000); } /** * Checks that the first two arguments are equal, with an optional message. * Prints out both actual and expected values. * * Prefered to ok( actual == expected, message ) * * @example equals( $.format("Received {0} bytes.", 2), "Received 2 bytes." ); * * @param Object actual * @param Object expected * @param String message (optional) */ function equals(actual, expected, message) { push(expected == actual, actual, expected, message); } function push(result, actual, expected, message) { message = message || (result ? "okay" : "failed"); config.assertions.push({ result: result, message: result ? message + ": " + expected : message + ", expected: " + jsDump.parse(expected) + " result: " + jsDump.parse(actual) }); } /** * Trigger an event on an element. * * @example triggerEvent( document.body, "click" ); * * @param DOMElement elem * @param String type */ function triggerEvent( elem, type, event ) { if ( $.browser.mozilla || $.browser.opera ) { event = document.createEvent("MouseEvents"); event.initMouseEvent(type, true, true, elem.ownerDocument.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null); elem.dispatchEvent( event ); } else if ( $.browser.msie ) { elem.fireEvent("on"+type); } } })(jQuery); /** * jsDump * Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com * Licensed under BSD (http://www.opensource.org/licenses/bsd-license.php) * Date: 5/15/2008 * @projectDescription Advanced and extensible data dumping for Javascript. * @version 1.0.0 * @author Ariel Flesler * @link {http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html} */ (function(){ function quote( str ){ return '"' + str.toString().replace(/"/g, '\\"') + '"'; }; function literal( o ){ return o + ''; }; function join( pre, arr, post ){ var s = jsDump.separator(), base = jsDump.indent(); inner = jsDump.indent(1); if( arr.join ) arr = arr.join( ',' + s + inner ); if( !arr ) return pre + post; return [ pre, inner + arr, base + post ].join(s); }; function array( arr ){ var i = arr.length, ret = Array(i); this.up(); while( i-- ) ret[i] = this.parse( arr[i] ); this.down(); return join( '[', ret, ']' ); }; var reName = /^function (\w+)/; var jsDump = window.jsDump = { parse:function( obj, type ){//type is used mostly internally, you can fix a (custom)type in advance var parser = this.parsers[ type || this.typeOf(obj) ]; type = typeof parser; return type == 'function' ? parser.call( this, obj ) : type == 'string' ? parser : this.parsers.error; }, typeOf:function( obj ){ var type = typeof obj, f = 'function';//we'll use it 3 times, save it return type != 'object' && type != f ? type : !obj ? 'null' : obj.exec ? 'regexp' :// some browsers (FF) consider regexps functions obj.getHours ? 'date' : obj.scrollBy ? 'window' : obj.nodeName == '#document' ? 'document' : obj.nodeName ? 'node' : obj.item ? 'nodelist' : // Safari reports nodelists as functions obj.callee ? 'arguments' : obj.call || obj.constructor != Array && //an array would also fall on this hack (obj+'').indexOf(f) != -1 ? f : //IE reports functions like alert, as objects 'length' in obj ? 'array' : type; }, separator:function(){ return this.multiline ? this.HTML ? '
        ' : '\n' : this.HTML ? ' ' : ' '; }, indent:function( extra ){// extra can be a number, shortcut for increasing-calling-decreasing if( !this.multiline ) return ''; var chr = this.indentChar; if( this.HTML ) chr = chr.replace(/\t/g,' ').replace(/ /g,' '); return Array( this._depth_ + (extra||0) ).join(chr); }, up:function( a ){ this._depth_ += a || 1; }, down:function( a ){ this._depth_ -= a || 1; }, setParser:function( name, parser ){ this.parsers[name] = parser; }, // The next 3 are exposed so you can use them quote:quote, literal:literal, join:join, // _depth_: 1, // This is the list of parsers, to modify them, use jsDump.setParser parsers:{ window: '[Window]', document: '[Document]', error:'[ERROR]', //when no parser is found, shouldn't happen unknown: '[Unknown]', 'null':'null', undefined:'undefined', 'function':function( fn ){ var ret = 'function', name = 'name' in fn ? fn.name : (reName.exec(fn)||[])[1];//functions never have name in IE if( name ) ret += ' ' + name; ret += '('; ret = [ ret, this.parse( fn, 'functionArgs' ), '){'].join(''); return join( ret, this.parse(fn,'functionCode'), '}' ); }, array: array, nodelist: array, arguments: array, object:function( map ){ var ret = [ ]; this.up(); for( var key in map ) ret.push( this.parse(key,'key') + ': ' + this.parse(map[key]) ); this.down(); return join( '{', ret, '}' ); }, node:function( node ){ var open = this.HTML ? '<' : '<', close = this.HTML ? '>' : '>'; var tag = node.nodeName.toLowerCase(), ret = open + tag; for( var a in this.DOMAttrs ){ var val = node[this.DOMAttrs[a]]; if( val ) ret += ' ' + a + '=' + this.parse( val, 'attribute' ); } return ret + close + open + '/' + tag + close; }, functionArgs:function( fn ){//function calls it internally, it's the arguments part of the function var l = fn.length; if( !l ) return ''; var args = Array(l); while( l-- ) args[l] = String.fromCharCode(97+l);//97 is 'a' return ' ' + args.join(', ') + ' '; }, key:quote, //object calls it internally, the key part of an item in a map functionCode:'[code]', //function calls it internally, it's the content of the function attribute:quote, //node calls it internally, it's an html attribute value string:quote, date:quote, regexp:literal, //regex number:literal, 'boolean':literal }, DOMAttrs:{//attributes to dump from nodes, name=>realName id:'id', name:'name', 'class':'className' }, HTML:false,//if true, entities are escaped ( <, >, \t, space and \n ) indentChar:' ',//indentation unit multiline:true //if true, items in a collection, are separated by a \n, else just a space. }; })(); strophejs-1.0.1.dfsg/tests/tests.js000066400000000000000000000145641137577172600173500ustar00rootroot00000000000000$(document).ready(function () { module("JIDs"); test("Normal JID", function () { var jid = "darcy@pemberley.lit/library"; equals(Strophe.getNodeFromJid(jid), "darcy", "Node should be 'darcy'"); equals(Strophe.getDomainFromJid(jid), "pemberley.lit", "Domain should be 'pemberley.lit'"); equals(Strophe.getResourceFromJid(jid), "library", "Node should be 'library'"); equals(Strophe.getBareJidFromJid(jid), "darcy@pemberley.lit", "Bare JID should be 'darcy@pemberley.lit'"); }); test("Weird node (unescaped)", function () { var jid = "darcy@netherfield.lit@pemberley.lit/library"; equals(Strophe.getNodeFromJid(jid), "darcy", "Node should be 'darcy'"); equals(Strophe.getDomainFromJid(jid), "netherfield.lit@pemberley.lit", "Domain should be 'netherfield.lit@pemberley.lit'"); equals(Strophe.getResourceFromJid(jid), "library", "Resource should be 'library'"); equals(Strophe.getBareJidFromJid(jid), "darcy@netherfield.lit@pemberley.lit", "Bare JID should be 'darcy@netherfield.lit@pemberley.lit'"); }); test("Weird node (escaped)", function () { var escapedNode = Strophe.escapeNode("darcy@netherfield.lit"); var jid = escapedNode + "@pemberley.lit/library"; equals(Strophe.getNodeFromJid(jid), "darcy\\40netherfield.lit", "Node should be 'darcy\\40netherfield.lit'"); equals(Strophe.getDomainFromJid(jid), "pemberley.lit", "Domain should be 'pemberley.lit'"); equals(Strophe.getResourceFromJid(jid), "library", "Resource should be 'library'"); equals(Strophe.getBareJidFromJid(jid), "darcy\\40netherfield.lit@pemberley.lit", "Bare JID should be 'darcy\\40netherfield.lit@pemberley.lit'"); }); test("Weird resource", function () { var jid = "books@chat.pemberley.lit/darcy@pemberley.lit/library"; equals(Strophe.getNodeFromJid(jid), "books", "Node should be 'books'"); equals(Strophe.getDomainFromJid(jid), "chat.pemberley.lit", "Domain should be 'chat.pemberley.lit'"); equals(Strophe.getResourceFromJid(jid), "darcy@pemberley.lit/library", "Resource should be 'darcy@pemberley.lit/library'"); equals(Strophe.getBareJidFromJid(jid), "books@chat.pemberley.lit", "Bare JID should be 'books@chat.pemberley.lit'"); }); module("Builder"); test("Correct namespace (#32)", function () { var stanzas = [new Strophe.Builder("message", {foo: "asdf"}).tree(), $build("iq", {}).tree(), $pres().tree()]; $.each(stanzas, function () { equals($(this).attr('xmlns'), Strophe.NS.CLIENT, "Namespace should be '" + Strophe.NS.CLIENT + "'"); }); }); test("send() accepts Builders (#27)", function () { var stanza = $pres(); var conn = new Strophe.Connection(""); // fake connection callback to avoid errors conn.connect_callback = function () {}; ok(conn._data.length === 0, "Output queue is clean"); try { conn.send(stanza); } catch (e) {} ok(conn._data.length === 1, "Output queue contains an element"); }); test("send() does not accept strings", function () { var stanza = ""; var conn = new Strophe.Connection(""); // fake connection callback to avoid errors conn.connect_callback = function () {}; expect(1); try { conn.send(stanza); } catch (e) { equals(e.name, "StropheError", "send() should throw exception"); } }); test("Builder with XML attribute escaping test", function () { var text = ""; var expected = ""; var pres = $pres({to: text}); equals(pres.toString(), expected, "< should be escaped"); text = "foo&bar"; expected = ""; pres = $pres({to: text}); equals(pres.toString(), expected, "& should be escaped"); }); module("XML"); test("XML escaping test", function () { var text = "s & p"; var textNode = Strophe.xmlTextNode(text); equals(Strophe.getText(textNode), "s & p", "should be escaped"); var text0 = "s < & > p"; var textNode0 = Strophe.xmlTextNode(text0); equals(Strophe.getText(textNode0), "s < & > p", "should be escaped"); }); test("XML element creation", function () { var elem = Strophe.xmlElement("message"); equals(elem.tagName, "message", "Element name should be the same"); }); module("Handler"); test("Full JID matching", function () { var elem = $msg({from: 'darcy@pemberley.lit/library'}).tree(); var hand = new Strophe.Handler(null, null, null, null, null, 'darcy@pemberley.lit/library'); equals(hand.isMatch(elem), true, "Full JID should match"); hand = new Strophe.Handler(null, null, null, null, null, 'darcy@pemberley.lit') equals(hand.isMatch(elem), false, "Bare JID shouldn't match"); }); test("Bare JID matching", function () { var elem = $msg({from: 'darcy@pemberley.lit/library'}).tree(); var hand = new Strophe.Handler(null, null, null, null, null, 'darcy@pemberley.lit/library', {matchBare: true}); equals(hand.isMatch(elem), true, "Full JID should match"); hand = new Strophe.Handler(null, null, null, null, null, 'darcy@pemberley.lit', {matchBare: true}); equals(hand.isMatch(elem), true, "Bare JID should match"); }); module("Misc"); test("Quoting strings", function () { var input = '"beep \\40"'; var conn = new Strophe.Connection(); var output = conn._quote(input); equals(output, "\"\\\"beep \\\\40\\\"\"", "string should be quoted and escaped"); }); }); strophejs-1.0.1.dfsg/tests/testsuite.css000066400000000000000000000041721137577172600204050ustar00rootroot00000000000000body, div, h1 { font-family: 'trebuchet ms', verdana, arial; margin: 0; padding: 0 } body {font-size: 10pt; } h1 { padding: 15px; font-size: large; background-color: #06b; color: white; } h1 a { color: white; } h2 { padding: 10px; background-color: #eee; color: black; margin: 0; font-size: small; font-weight: normal } .pass { color: green; } .fail { color: red; } p.result { margin-left: 1em; } #banner { height: 2em; border-bottom: 1px solid white; } h2.pass { background-color: green; } h2.fail { background-color: red; } div.testrunner-toolbar { background: #eee; border-top: 1px solid black; padding: 10px; } ol#tests > li > strong { cursor:pointer; } div#fx-tests h4 { background: red; } div#fx-tests h4.pass { background: green; } div#fx-tests div.box { background: red url(data/cow.jpg) no-repeat; overflow: hidden; border: 2px solid #000; } div#fx-tests div.overflow { overflow: visible; } div.inline { display: inline; } div.autoheight { height: auto; } div.autowidth { width: auto; } div.autoopacity { opacity: auto; } div.largewidth { width: 100px; } div.largeheight { height: 100px; } div.largeopacity { filter: progid:DXImageTransform.Microsoft.Alpha(opacity=100); } div.medwidth { width: 50px; } div.medheight { height: 50px; } div.medopacity { opacity: 0.5; filter: progid:DXImageTransform.Microsoft.Alpha(opacity=50); } div.nowidth { width: 0px; } div.noheight { height: 0px; } div.noopacity { opacity: 0; filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0); } div.hidden { display: none; } div#fx-tests div.widewidth { background-repeat: repeat-x; } div#fx-tests div.wideheight { background-repeat: repeat-y; } div#fx-tests div.widewidth.wideheight { background-repeat: repeat; } div#fx-tests div.noback { background-image: none; } div.chain, div.chain div { width: 100px; height: 20px; position: relative; float: left; } div.chain div { position: absolute; top: 0px; left: 0px; } div.chain.test { background: red; } div.chain.test div { background: green; } div.chain.out { background: green; } div.chain.out div { background: red; display: none; } div#show-tests * { display: none; } strophejs-1.0.1.dfsg/tests/yuitests.html000066400000000000000000000011371137577172600204170ustar00rootroot00000000000000 Strophe Tests
        strophejs-1.0.1.dfsg/tests/yuitests.js000066400000000000000000000015721137577172600200720ustar00rootroot00000000000000YUI().use("test", "console", function (Y) { Y.namespace("strophe.test"); var Assert = Y.Assert; Y.strophe.test.JIDTestCase = new Y.Test.Case({ name: "JIDs", testNormalJid: function () { var jid = "darcy@pemberley.lit/library"; Assert.areSame("darcy", Strophe.getNodeFromJid(jid)); Assert.areSame("pemberley.lit", Strophe.getDomainFromJid(jid)); Assert.areSame("library", Strophe.getResourceFromJid(jid)); Assert.areSame("darcy@pemberley.lit", Strophe.getBareJidFromJid(jid)); } }); Y.strophe.test.StropheSuite = new Y.Test.Suite("Strophe Suite"); Y.strophe.test.StropheSuite.add(Y.strophe.test.JIDTestCase); new Y.Console({newestOnTop: false}).render('#console'); Y.Test.Runner.add(Y.strophe.test.StropheSuite); Y.Test.Runner.run(); });