pax_global_header00006660000000000000000000000064115372575330014525gustar00rootroot0000000000000052 comment=9856279f3601fbd95c453f9ebebcd121f58716cc jsjac-1.3.4+dfsg/000077500000000000000000000000001153725753300135435ustar00rootroot00000000000000jsjac-1.3.4+dfsg/AUTHORS000066400000000000000000000001121153725753300146050ustar00rootroot00000000000000JSJaC has been developed by * Stefan Strigler jsjac-1.3.4+dfsg/COPYING000066400000000000000000000010461153725753300145770ustar00rootroot00000000000000JSJaC is licensed under the terms of the Mozilla Public License version 1.1 or, at your option, under the terms of the GNU General Public License version 2 or subsequent, or the terms of the GNU Lesser General Public License version 2.1 or subsequent. The complete text of each of these license can be found in the same directory as this file. See * MPL-1.1.txt - for version 1.1 of the Mozille Public License * gpl-2.0.txt - for version 2 of the GNU General Public License * lgpl-2.1.txt - for version 2.1 of the GNU Lesser General Public Licensejsjac-1.3.4+dfsg/ChangeLog000066400000000000000000000124351153725753300153220ustar00rootroot00000000000000JSJaC v1.3.4 ============ * JSJaCPacket: fix serious issues with xmlns and namespaces JSJaC v1.3.3 ============ * allow to set 'cookie_prefix' at Connection constructors * fixed event handler bubbling (wasn't able to stop) * JSJaCCookie: allow to set domain and path * JSJaC.bind: pass args correctly * XmlDocument.create: removed alert in case of error* * JSJaCConnection.prototyp.suspendFromData: added * JSJaCConnection.prototyp.resumeFromData: added ... lots more JSJaC v1.3.2 ============ * fixed compatibility issues with Firefox3 * fixed some little bugs JSJaC v1.3.1 ============ * changed licensing to Mozilla's tri-license model (MPL, GPL, LGPL) * some little bugfixes JSJaC v1.3 ========== * all handlers/callbacks now have their context set to the connection, thus you can refer to it using 'this'. * JSJaCConnection.unregisterHandler added * lots of bugfixes JSJaC v1.2.2 ============ * added mootools packer to generate a packed version of jsjac (make target 'pack') * json routines: don't extend Object * fixed internal polling going wild when reconnecting * JSJaCJID.prototype.clone and JSJaCJID.prototype.isEntity added * Copyright and legelases statements added for code from external resources JSJaC v1.2.1 ============ * fixed handlers for packets with empty childnodes (fixes #17) * updated docs JSJaC v1.2 ========== fixes: * JSJaCConnection.prototype.getChild: rewrite new: * JSJaCConstants.js: various XMPP Constants and error conditions * JSJaCPacket.prototype.errorReply: create an error reply to a packet * JSJaCIQ.prototype.reply: Create an iq reply with type 'result' * JSJaCConnection.prototype.registerHandler: allow to register tagnames, namespaces and packet types. make events bubble and allow handlers to cancel bubbling of the event. * JSJaCConnection.prototype.registerIQGet: here for your convenience * JSJaCConnection.prototype.registerIQSet: here for your convenience * JSJaCConnection.prototype.sendIQ: like send but with different callbacks for different types of iq replies ('error' & 'result') and default handlers stuff: * include JSDoc for your convenience JSJaC v1.1.1 ============ * fixed jsjac.js not having XmlDocument.create defined JSJaC v1.1 ========== * fixed bug with empty JID giving null pointer exception when using getters * use prototype property to declare member methods * static methods for cookie retrieval/erase for convenience * moved config vars to own file 'src/JSJaCConfig.js' * fixed make process of single include file to not compress config vars and place them on top of 'jsjac.js' JSJaC v1.0 ========== * support for pausing sessions as described in http://www.xmpp.org/extensions/xep-0124.html#inactive * bosh compliance v1.6 JSJaC v1.0beta1 =============== * JSJacJID.js: dedicated class for handling with JIDs * JSJaCPacket.js: getToJID(), getFromJID() return a JID object * JSJaCPacket.js: setTo and setFrom accept JID object too * jsextras.js: extends string with 'htmlEnc', extends Date with 'jabberDate', 'hrTime' (static) and 'jab2date' (static) * fixed all occurrences of 'for .. in' to be compliant with having prototypes of objects (arrays) extended (like prototype.js does e.g.). * buildNode: build nodes using script.aculo.us famous DOM builder * appendNode: append nodes to root node, may also be used with DOM builder syntax * ConsoleLogger: debug logger using firebug's or safari's console * getChild(name, ns): get child node with given name (and namespace) * getChildVal(name, ns): get value of child node with given name (and namespace) * new API documentation using jsdoc * new build system using jsmin to create single minimized file (jsjac.js) * new events: onresume, packet_in/out, presence_in/out, message_in/out, iq_in/out * new status: resuming JSJaC v0.6 ========== * Support for Opera, Konqueror and Safari. * Support for suspend/resume (makes it possible to save the state between page transitions. * Single include by JSJaC.js * Many bugfixes and improvements concerning reliability. * API change! Params to constructors and connect methods are now passed as JSON objects. * New event 'status_changed' to signal if sth going on with the status of the connection (like errors, retries and so on) * SASL Authentication (PLAIN, DIGEST-MD5, ANONYMOUS) JSJaC v0.5 ========== * lots of bug fixes and minor improvements * make use of asynchronous request wherever possible * fixed simpleclient * fixed API docs JSJaC v0.4 ========== * ... JSJaC v0.3.x ============ * Initial support for http binding (in polling mode though) * Initial support for safari (thanks to Matthew Hershberger) JSJaC v0.2 ========== * send always does asychronous send now as http polling doesn't support this. In detail: When sending a packet where we expect a reply to it http polling doesn't make sure that this reply is contained within the http body reply to the query sent. So we have to setup a callback that handles the reply once it has been delivered to us. * added a dedicated method syncedSend that sends in synchronous mode First read above, then understand that you can't expect any response to this call. It's there to make sure, sending is finished before windows get closed * added events 'onconnect', 'ondisconnect' and 'onerror'. see API for details. * removed method process() as polling is started at connect() now. jsjac-1.3.4+dfsg/MPL-1.1.txt000066400000000000000000000622331153725753300152370ustar00rootroot00000000000000 MOZILLA PUBLIC LICENSE Version 1.1 --------------- 1. Definitions. 1.0.1. "Commercial Use" means distribution or otherwise making the Covered Code available to a third party. 1.1. "Contributor" means each entity that creates or contributes to the creation of Modifications. 1.2. "Contributor Version" means the combination of the Original Code, prior Modifications used by a Contributor, and the Modifications made by that particular Contributor. 1.3. "Covered Code" means the Original Code or Modifications or the combination of the Original Code and Modifications, in each case including portions thereof. 1.4. "Electronic Distribution Mechanism" means a mechanism generally accepted in the software development community for the electronic transfer of data. 1.5. "Executable" means Covered Code in any form other than Source Code. 1.6. "Initial Developer" means the individual or entity identified as the Initial Developer in the Source Code notice required by Exhibit A. 1.7. "Larger Work" means a work which combines Covered Code or portions thereof with code not governed by the terms of this License. 1.8. "License" means this document. 1.8.1. "Licensable" means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently acquired, any and all of the rights conveyed herein. 1.9. "Modifications" means any addition to or deletion from the substance or structure of either the Original Code or any previous Modifications. When Covered Code is released as a series of files, a Modification is: A. Any addition to or deletion from the contents of a file containing Original Code or previous Modifications. B. Any new file that contains any part of the Original Code or previous Modifications. 1.10. "Original Code" means Source Code of computer software code which is described in the Source Code notice required by Exhibit A as Original Code, and which, at the time of its release under this License is not already Covered Code governed by this License. 1.10.1. "Patent Claims" means any patent claim(s), now owned or hereafter acquired, including without limitation, method, process, and apparatus claims, in any patent Licensable by grantor. 1.11. "Source Code" means the preferred form of the Covered Code for making modifications to it, including all modules it contains, plus any associated interface definition files, scripts used to control compilation and installation of an Executable, or source code differential comparisons against either the Original Code or another well known, available Covered Code of the Contributor's choice. The Source Code can be in a compressed or archival form, provided the appropriate decompression or de-archiving software is widely available for no charge. 1.12. "You" (or "Your") means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License or a future version of this License issued under Section 6.1. For legal entities, "You" includes any entity which controls, is controlled by, or is under common control with You. For purposes of this definition, "control" means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity. 2. Source Code License. 2.1. The Initial Developer Grant. The Initial Developer hereby grants You a world-wide, royalty-free, non-exclusive license, subject to third party intellectual property claims: (a) under intellectual property rights (other than patent or trademark) Licensable by Initial Developer to use, reproduce, modify, display, perform, sublicense and distribute the Original Code (or portions thereof) with or without Modifications, and/or as part of a Larger Work; and (b) under Patents Claims infringed by the making, using or selling of Original Code, to make, have made, use, practice, sell, and offer for sale, and/or otherwise dispose of the Original Code (or portions thereof). (c) the licenses granted in this Section 2.1(a) and (b) are effective on the date Initial Developer first distributes Original Code under the terms of this License. (d) Notwithstanding Section 2.1(b) above, no patent license is granted: 1) for code that You delete from the Original Code; 2) separate from the Original Code; or 3) for infringements caused by: i) the modification of the Original Code or ii) the combination of the Original Code with other software or devices. 2.2. Contributor Grant. Subject to third party intellectual property claims, each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license (a) under intellectual property rights (other than patent or trademark) Licensable by Contributor, to use, reproduce, modify, display, perform, sublicense and distribute the Modifications created by such Contributor (or portions thereof) either on an unmodified basis, with other Modifications, as Covered Code and/or as part of a Larger Work; and (b) under Patent Claims infringed by the making, using, or selling of Modifications made by that Contributor either alone and/or in combination with its Contributor Version (or portions of such combination), to make, use, sell, offer for sale, have made, and/or otherwise dispose of: 1) Modifications made by that Contributor (or portions thereof); and 2) the combination of Modifications made by that Contributor with its Contributor Version (or portions of such combination). (c) the licenses granted in Sections 2.2(a) and 2.2(b) are effective on the date Contributor first makes Commercial Use of the Covered Code. (d) Notwithstanding Section 2.2(b) above, no patent license is granted: 1) for any code that Contributor has deleted from the Contributor Version; 2) separate from the Contributor Version; 3) for infringements caused by: i) third party modifications of Contributor Version or ii) the combination of Modifications made by that Contributor with other software (except as part of the Contributor Version) or other devices; or 4) under Patent Claims infringed by Covered Code in the absence of Modifications made by that Contributor. 3. Distribution Obligations. 3.1. Application of License. The Modifications which You create or to which You contribute are governed by the terms of this License, including without limitation Section 2.2. The Source Code version of Covered Code may be distributed only under the terms of this License or a future version of this License released under Section 6.1, and You must include a copy of this License with every copy of the Source Code You distribute. You may not offer or impose any terms on any Source Code version that alters or restricts the applicable version of this License or the recipients' rights hereunder. However, You may include an additional document offering the additional rights described in Section 3.5. 3.2. Availability of Source Code. Any Modification which You create or to which You contribute must be made available in Source Code form under the terms of this License either on the same media as an Executable version or via an accepted Electronic Distribution Mechanism to anyone to whom you made an Executable version available; and if made available via Electronic Distribution Mechanism, must remain available for at least twelve (12) months after the date it initially became available, or at least six (6) months after a subsequent version of that particular Modification has been made available to such recipients. You are responsible for ensuring that the Source Code version remains available even if the Electronic Distribution Mechanism is maintained by a third party. 3.3. Description of Modifications. You must cause all Covered Code to which You contribute to contain a file documenting the changes You made to create that Covered Code and the date of any change. You must include a prominent statement that the Modification is derived, directly or indirectly, from Original Code provided by the Initial Developer and including the name of the Initial Developer in (a) the Source Code, and (b) in any notice in an Executable version or related documentation in which You describe the origin or ownership of the Covered Code. 3.4. Intellectual Property Matters (a) Third Party Claims. If Contributor has knowledge that a license under a third party's intellectual property rights is required to exercise the rights granted by such Contributor under Sections 2.1 or 2.2, Contributor must include a text file with the Source Code distribution titled "LEGAL" which describes the claim and the party making the claim in sufficient detail that a recipient will know whom to contact. If Contributor obtains such knowledge after the Modification is made available as described in Section 3.2, Contributor shall promptly modify the LEGAL file in all copies Contributor makes available thereafter and shall take other steps (such as notifying appropriate mailing lists or newsgroups) reasonably calculated to inform those who received the Covered Code that new knowledge has been obtained. (b) Contributor APIs. If Contributor's Modifications include an application programming interface and Contributor has knowledge of patent licenses which are reasonably necessary to implement that API, Contributor must also include this information in the LEGAL file. (c) Representations. Contributor represents that, except as disclosed pursuant to Section 3.4(a) above, Contributor believes that Contributor's Modifications are Contributor's original creation(s) and/or Contributor has sufficient rights to grant the rights conveyed by this License. 3.5. Required Notices. You must duplicate the notice in Exhibit A in each file of the Source Code. If it is not possible to put such notice in a particular Source Code file due to its structure, then You must include such notice in a location (such as a relevant directory) where a user would be likely to look for such a notice. If You created one or more Modification(s) You may add your name as a Contributor to the notice described in Exhibit A. You must also duplicate this License in any documentation for the Source Code where You describe recipients' rights or ownership rights relating to Covered Code. You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Code. However, You may do so only on Your own behalf, and not on behalf of the Initial Developer or any Contributor. You must make it absolutely clear than any such warranty, support, indemnity or liability obligation is offered by You alone, and You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of warranty, support, indemnity or liability terms You offer. 3.6. Distribution of Executable Versions. You may distribute Covered Code in Executable form only if the requirements of Section 3.1-3.5 have been met for that Covered Code, and if You include a notice stating that the Source Code version of the Covered Code is available under the terms of this License, including a description of how and where You have fulfilled the obligations of Section 3.2. The notice must be conspicuously included in any notice in an Executable version, related documentation or collateral in which You describe recipients' rights relating to the Covered Code. You may distribute the Executable version of Covered Code or ownership rights under a license of Your choice, which may contain terms different from this License, provided that You are in compliance with the terms of this License and that the license for the Executable version does not attempt to limit or alter the recipient's rights in the Source Code version from the rights set forth in this License. If You distribute the Executable version under a different license You must make it absolutely clear that any terms which differ from this License are offered by You alone, not by the Initial Developer or any Contributor. You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of any such terms You offer. 3.7. Larger Works. You may create a Larger Work by combining Covered Code with other code not governed by the terms of this License and distribute the Larger Work as a single product. In such a case, You must make sure the requirements of this License are fulfilled for the Covered Code. 4. Inability to Comply Due to Statute or Regulation. If it is impossible for You to comply with any of the terms of this License with respect to some or all of the Covered Code due to statute, judicial order, or regulation then You must: (a) comply with the terms of this License to the maximum extent possible; and (b) describe the limitations and the code they affect. Such description must be included in the LEGAL file described in Section 3.4 and must be included with all distributions of the Source Code. Except to the extent prohibited by statute or regulation, such description must be sufficiently detailed for a recipient of ordinary skill to be able to understand it. 5. Application of this License. This License applies to code to which the Initial Developer has attached the notice in Exhibit A and to related Covered Code. 6. Versions of the License. 6.1. New Versions. Netscape Communications Corporation ("Netscape") may publish revised and/or new versions of the License from time to time. Each version will be given a distinguishing version number. 6.2. Effect of New Versions. Once Covered Code has been published under a particular version of the License, You may always continue to use it under the terms of that version. You may also choose to use such Covered Code under the terms of any subsequent version of the License published by Netscape. No one other than Netscape has the right to modify the terms applicable to Covered Code created under this License. 6.3. Derivative Works. If You create or use a modified version of this License (which you may only do in order to apply it to code which is not already Covered Code governed by this License), You must (a) rename Your license so that the phrases "Mozilla", "MOZILLAPL", "MOZPL", "Netscape", "MPL", "NPL" or any confusingly similar phrase do not appear in your license (except to note that your license differs from this License) and (b) otherwise make it clear that Your version of the license contains terms which differ from the Mozilla Public License and Netscape Public License. (Filling in the name of the Initial Developer, Original Code or Contributor in the notice described in Exhibit A shall not of themselves be deemed to be modifications of this License.) 7. DISCLAIMER OF WARRANTY. COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER. 8. TERMINATION. 8.1. This License and the rights granted hereunder will terminate automatically if You fail to comply with terms herein and fail to cure such breach within 30 days of becoming aware of the breach. All sublicenses to the Covered Code which are properly granted shall survive any termination of this License. Provisions which, by their nature, must remain in effect beyond the termination of this License shall survive. 8.2. If You initiate litigation by asserting a patent infringement claim (excluding declatory judgment actions) against Initial Developer or a Contributor (the Initial Developer or Contributor against whom You file such action is referred to as "Participant") alleging that: (a) such Participant's Contributor Version directly or indirectly infringes any patent, then any and all rights granted by such Participant to You under Sections 2.1 and/or 2.2 of this License shall, upon 60 days notice from Participant terminate prospectively, unless if within 60 days after receipt of notice You either: (i) agree in writing to pay Participant a mutually agreeable reasonable royalty for Your past and future use of Modifications made by such Participant, or (ii) withdraw Your litigation claim with respect to the Contributor Version against such Participant. If within 60 days of notice, a reasonable royalty and payment arrangement are not mutually agreed upon in writing by the parties or the litigation claim is not withdrawn, the rights granted by Participant to You under Sections 2.1 and/or 2.2 automatically terminate at the expiration of the 60 day notice period specified above. (b) any software, hardware, or device, other than such Participant's Contributor Version, directly or indirectly infringes any patent, then any rights granted to You by such Participant under Sections 2.1(b) and 2.2(b) are revoked effective as of the date You first made, used, sold, distributed, or had made, Modifications made by that Participant. 8.3. If You assert a patent infringement claim against Participant alleging that such Participant's Contributor Version directly or indirectly infringes any patent where such claim is resolved (such as by license or settlement) prior to the initiation of patent infringement litigation, then the reasonable value of the licenses granted by such Participant under Sections 2.1 or 2.2 shall be taken into account in determining the amount or value of any payment or license. 8.4. In the event of termination under Sections 8.1 or 8.2 above, all end user license agreements (excluding distributors and resellers) which have been validly granted by You or any distributor hereunder prior to termination shall survive termination. 9. LIMITATION OF LIABILITY. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU. 10. U.S. GOVERNMENT END USERS. The Covered Code is a "commercial item," as that term is defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer software" and "commercial computer software documentation," as such terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all U.S. Government End Users acquire Covered Code with only those rights set forth herein. 11. MISCELLANEOUS. This License represents the complete agreement concerning subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. This License shall be governed by California law provisions (except to the extent applicable law, if any, provides otherwise), excluding its conflict-of-law provisions. With respect to disputes in which at least one party is a citizen of, or an entity chartered or registered to do business in the United States of America, any litigation relating to this License shall be subject to the jurisdiction of the Federal Courts of the Northern District of California, with venue lying in Santa Clara County, California, with the losing party responsible for costs, including without limitation, court costs and reasonable attorneys' fees and expenses. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not apply to this License. 12. RESPONSIBILITY FOR CLAIMS. As between Initial Developer and the Contributors, each party is responsible for claims and damages arising, directly or indirectly, out of its utilization of rights under this License and You agree to work with Initial Developer and Contributors to distribute such responsibility on an equitable basis. Nothing herein is intended or shall be deemed to constitute any admission of liability. 13. MULTIPLE-LICENSED CODE. Initial Developer may designate portions of the Covered Code as "Multiple-Licensed". "Multiple-Licensed" means that the Initial Developer permits you to utilize portions of the Covered Code under Your choice of the NPL or the alternative licenses, if any, specified by the Initial Developer in the file described in Exhibit A. EXHIBIT A -Mozilla Public License. ``The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is ______________________________________. The Initial Developer of the Original Code is ________________________. Portions created by ______________________ are Copyright (C) ______ _______________________. All Rights Reserved. Contributor(s): ______________________________________. Alternatively, the contents of this file may be used under the terms of the _____ license (the "[___] License"), in which case the provisions of [______] License are applicable instead of those above. If you wish to allow use of your version of this file only under the terms of the [____] License and not to allow others to use your version of this file under the MPL, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the [___] License. If you do not delete the provisions above, a recipient may use your version of this file under either the MPL or the [___] License." [NOTE: The text of this Exhibit A may differ slightly from the text of the notices in the Source Code files of the Original Code. You should use the text of this Exhibit A rather than the text found in the Original Code Source Code for Your Modifications.] jsjac-1.3.4+dfsg/Makefile000066400000000000000000000032131153725753300152020ustar00rootroot00000000000000OUTFILE=./jsjac.js PACKFILE=./jsjac.packed.js UNCOMPRESSED=./jsjac.uncompressed.js SRC=src/jsextras.js src/crypt.js src/JSJaCJSON.js src/xmlextras.js \ src/JSJaCBuilder.js src/JSJaCConstants.js \ src/JSJaCConsoleLogger.js src/JSJaCCookie.js src/JSJaCError.js \ src/JSJaCJID.js src/JSJaCKeys.js src/JSJaCPacket.js src/JSJaCConnection.js \ src/JSJaCHttpBindingConnection.js src/JSJaCHttpPollingConnection.js \ src/JSJaC.js all: clean utils install doc install: build uncompressed crunch @echo "done." build: @echo "building ..."; @for i in ${SRC}; do \ echo "\t$$i"; \ cat "$$i" >> $(OUTFILE); \ done crunch: @echo "crunching ..." @if [ -e $(OUTFILE) ]; then \ utils/jsmin < $(OUTFILE) > $(OUTFILE).tmp && \ cat src/header.js > $(OUTFILE) && \ cat src/JSJaCConfig.js >> $(OUTFILE) && \ cat $(OUTFILE).tmp >> $(OUTFILE) && \ rm $(OUTFILE).tmp; \ fi pack: clean utils build moo crunch doc moo: @echo "packing..." @if [ -e $(OUTFILE) ]; then \ php ./utils/packer/pack.php $(OUTFILE) $(PACKFILE).tmp && \ cat src/header.js > $(PACKFILE) && \ cat src/JSJaCConfig.js >> $(PACKFILE) && \ cat $(PACKFILE).tmp >> $(PACKFILE) && \ rm $(PACKFILE).tmp; \ else \ echo "$(OUTFILE) not found. build failed?"; \ fi doc: @utils/JSDoc/jsdoc.pl --project-name JSJaC -d doc src/ utils: @make -C utils clean: @rm -f $(OUTFILE) 2>/dev/null @rm -f $(PACKFILE) 2>/dev/null @rm -f $(UNCOMPRESSED) 2>/dev/null @rm -rf doc/ @make -C utils clean uncompressed: @if [ -e $(OUTFILE) ]; then \ cat src/header.js > $(UNCOMPRESSED) && \ cat src/JSJaCConfig.js >> $(UNCOMPRESSED) && \ cat $(OUTFILE) >> $(UNCOMPRESSED); \ fi .PHONY: doc utils jsjac-1.3.4+dfsg/README000066400000000000000000000052121153725753300144230ustar00rootroot00000000000000JSJaC - JavaScript Jabber Client Library ======================================== JSJaC is a jabber/XMPP client library written in JavaScript to ease implementation of web based jabber/XMPP clients. For communication with a jabber server it needs to support either [1]HTTP Polling or [2]XMPP Over BOSH (formerl known as HTTP Binding). JSJaC has an object oriented interface which should be quite easy to use. Communication is done by using the HTTPRequest object also refered to as AJAX technology. Your browser must support this. JSJaC is fully compatible with all major AJAX/JavaScript frameworks like prototype, mootools, jQuery, dojo and YUI!. License ======= JSJaC is licensed under the terms of the GNU Lesser General Public License (LGPL). Please refer to the file named 'COPYING' that came with this distribution for details. Hints on Usage ============== Service Address --------------- Due to security restrictions you may have to forward or proxy requests to your jabber server's service address. Let's say your JSJaC based web application is located at http://example.com. Your Jabber server is at jabber.example.com and it's HTTP Binding service is located at http://jabber.example.org:5280. As most browser don't allow scripts to connect to a different domain and/or port as they have been loaded from you'd have to find a way how to access this service at some URI hosted at http://example.com/. If you're using apache you could use mod_proxy and mod_rewrite to do this job for you: %<--- Servername example.com DocumentRoot /var/www AddDefaultCharset UTF-8 RewriteEngine On RewriteRule ^/http-bind/ http://jabber.example.com:5280/http-bind/ [P] %<--- With this you'd end up having access to the Jabber server's service at http://example.com/http-bind/ (the httpbase address). Debug Logger ------------ JSJaCConnection supports use of [3]JSDebugger which is available separately. JSJaC also ships with a class 'JSJaCConsoleLogger' which lets you log to Firebug's and Safari's console. Example ------- For an example on how to use this library within your web application please have to look at 'examples/simpleclient.html'. Supported Browsers and Platforms ================================ The following browsers are known to work. Let me know about others! Microsoft Internet Explorer 6/7/8/9 Firefox 2.0.x and newer (and probably most other Gecko based browsers) Opera 9 and newer Chrome/Safari (and probably mpst other Webkit based browsers) References: =========== [1] http://www.xmpp.org/extensions/xep-0025.html [2] http://www.xmpp.org/extensions/xep-0206.html [3] http://blog.jwchat.org/javascript-debug-logger/jsjac-1.3.4+dfsg/examples/000077500000000000000000000000001153725753300153615ustar00rootroot00000000000000jsjac-1.3.4+dfsg/examples/simpleclient.html000066400000000000000000000232221153725753300207400ustar00rootroot00000000000000 JSJaC Simple Client

JSJaC Simple Client

Login

Backend Type

 
jsjac-1.3.4+dfsg/gpl-2.0.txt000066400000000000000000000431031153725753300153640ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. jsjac-1.3.4+dfsg/lgpl-2.1.txt000066400000000000000000000635041153725753300155500ustar00rootroot00000000000000 GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! jsjac-1.3.4+dfsg/src/000077500000000000000000000000001153725753300143325ustar00rootroot00000000000000jsjac-1.3.4+dfsg/src/JSJaC.js000066400000000000000000000025261153725753300155670ustar00rootroot00000000000000/** * @fileoverview Magic dependency loading. Taken from script.aculo.us * and modified to break it. * @author Stefan Strigler steve@zeank.in-berlin.de * @version $Revision$ */ var JSJaC = { Version: '$Rev$', require: function(libraryName) { // inserting via DOM fails in Safari 2.0, so brute force approach document.write(''); }, load: function() { var includes = ['xmlextras', 'jsextras', 'crypt', 'JSJaCConfig', 'JSJaCConstants', 'JSJaCCookie', 'JSJaCJSON', 'JSJaCJID', 'JSJaCBuilder', 'JSJaCPacket', 'JSJaCError', 'JSJaCKeys', 'JSJaCConnection', 'JSJaCHttpPollingConnection', 'JSJaCHttpBindingConnection', 'JSJaCConsoleLogger' ]; var scripts = document.getElementsByTagName("script"); var path = './'; for (var i=0; i * The original parts of the code do have the following * copyright and license notice:
* Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, * http://mir.acu lo.us)
* script.aculo.us is freely distributable under the terms of an * MIT-style license.
* For details, see the script.aculo.us web site: * http://script.aculo.us/
*/ var JSJaCBuilder = { /** * @private */ buildNode: function(doc, elementName) { var element, ns = arguments[4]; // attributes (or text) if(arguments[2]) if(JSJaCBuilder._isStringOrNumber(arguments[2]) || (arguments[2] instanceof Array)) { element = this._createElement(doc, elementName, ns); JSJaCBuilder._children(doc, element, arguments[2]); } else { ns = arguments[2]['xmlns'] || ns; element = this._createElement(doc, elementName, ns); for(attr in arguments[2]) { if (arguments[2].hasOwnProperty(attr) && attr != 'xmlns') element.setAttribute(attr, arguments[2][attr]); } } else element = this._createElement(doc, elementName, ns); // text, or array of children if(arguments[3]) JSJaCBuilder._children(doc, element, arguments[3], ns); return element; }, _createElement: function(doc, elementName, ns) { try { if (ns) return doc.createElementNS(ns, elementName); } catch (ex) { } var el = doc.createElement(elementName); if (ns) el.setAttribute("xmlns", ns); return el; }, /** * @private */ _text: function(doc, text) { return doc.createTextNode(text); }, /** * @private */ _children: function(doc, element, children, ns) { if(typeof children=='object') { // array can hold nodes and text for (var i in children) { if (children.hasOwnProperty(i)) { var e = children[i]; if (typeof e=='object') { if (e instanceof Array) { var node = JSJaCBuilder.buildNode(doc, e[0], e[1], e[2], ns); element.appendChild(node); } else { element.appendChild(e); } } else { if(JSJaCBuilder._isStringOrNumber(e)) { element.appendChild(JSJaCBuilder._text(doc, e)); } } } } } else { if(JSJaCBuilder._isStringOrNumber(children)) { element.appendChild(JSJaCBuilder._text(doc, children)); } } }, _attributes: function(attributes) { var attrs = []; for(attribute in attributes) if (attributes.hasOwnProperty(attribute)) attrs.push(attribute + '="' + attributes[attribute].toString().htmlEnc() + '"'); return attrs.join(" "); }, _isStringOrNumber: function(param) { return(typeof param=='string' || typeof param=='number'); } }; jsjac-1.3.4+dfsg/src/JSJaCConfig.js000066400000000000000000000021631153725753300167120ustar00rootroot00000000000000 JSJAC_HAVEKEYS = true; // whether to use keys JSJAC_NKEYS = 16; // number of keys to generate JSJAC_INACTIVITY = 300; // qnd hack to make suspend/resume // work more smoothly with polling JSJAC_ERR_COUNT = 10; // number of retries in case of connection // errors JSJAC_ALLOW_PLAIN = true; // whether to allow plaintext logins JSJAC_CHECKQUEUEINTERVAL = 1; // msecs to poll send queue JSJAC_CHECKINQUEUEINTERVAL = 1; // msecs to poll incoming queue JSJAC_TIMERVAL = 2000; // default polling interval // Options specific to HTTP Binding (BOSH) JSJACHBC_MAX_HOLD = 1; // default for number of connctions held by // connection maanger JSJACHBC_MAX_WAIT = 300; // default 'wait' param - how long an idle connection // should be held by connection manager JSJACHBC_BOSH_VERSION = "1.6"; JSJACHBC_USE_BOSH_VER = true; JSJACHBC_MAXPAUSE = 120; // how long a suspend/resume cycle may take /*** END CONFIG ***/ jsjac-1.3.4+dfsg/src/JSJaCConnection.js000066400000000000000000001077011153725753300176100ustar00rootroot00000000000000/** * @fileoverview Contains all things in common for all subtypes of connections * supported. * @author Stefan Strigler steve@zeank.in-berlin.de * @version $Revision$ */ /** * Creates a new Jabber connection (a connection to a jabber server) * @class Somewhat abstract base class for jabber connections. Contains all * of the code in common for all jabber connections * @constructor * @param {JSON http://www.json.org/index} oArg JSON with properties:
* * httpbase the http base address of the service to be used for * connecting to jabber
* * oDbg (optional) a reference to a debugger interface */ function JSJaCConnection(oArg) { if (oArg && oArg.oDbg && oArg.oDbg.log) { /** * Reference to debugger interface * (needs to implement method log) * @type Debugger */ this.oDbg = oArg.oDbg; } else { this.oDbg = new Object(); // always initialise a debugger this.oDbg.log = function() { }; } if (oArg && oArg.timerval) this.setPollInterval(oArg.timerval); else this.setPollInterval(JSJAC_TIMERVAL); if (oArg && oArg.httpbase) /** * @private */ this._httpbase = oArg.httpbase; if (oArg &&oArg.allow_plain) /** * @private */ this.allow_plain = oArg.allow_plain; else this.allow_plain = JSJAC_ALLOW_PLAIN; if (oArg && oArg.cookie_prefix) /** * @private */ this._cookie_prefix = oArg.cookie_prefix; else this._cookie_prefix = ""; /** * @private */ this._connected = false; /** * @private */ this._events = new Array(); /** * @private */ this._keys = null; /** * @private */ this._ID = 0; /** * @private */ this._inQ = new Array(); /** * @private */ this._pQueue = new Array(); /** * @private */ this._regIDs = new Array(); /** * @private */ this._req = new Array(); /** * @private */ this._status = 'intialized'; /** * @private */ this._errcnt = 0; /** * @private */ this._inactivity = JSJAC_INACTIVITY; /** * @private */ this._sendRawCallbacks = new Array(); } JSJaCConnection.prototype.connect = function(oArg) { this._setStatus('connecting'); this.domain = oArg.domain || 'localhost'; this.username = oArg.username; this.resource = oArg.resource; this.pass = oArg.pass; this.register = oArg.register; this.authhost = oArg.authhost || this.domain; this.authtype = oArg.authtype || 'sasl'; if (oArg.xmllang && oArg.xmllang != '') this._xmllang = oArg.xmllang; this.host = oArg.host || this.domain; this.port = oArg.port || 5222; if (oArg.secure) this.secure = 'true'; else this.secure = 'false'; if (oArg.wait) this._wait = oArg.wait; this.jid = this.username + '@' + this.domain; this.fulljid = this.jid + '/' + this.resource; this._rid = Math.round( 100000.5 + ( ( (900000.49999) - (100000.5) ) * Math.random() ) ); // setupRequest must be done after rid is created but before first use in reqstr var slot = this._getFreeSlot(); this._req[slot] = this._setupRequest(true); var reqstr = this._getInitialRequestString(); this.oDbg.log(reqstr,4); this._req[slot].r.onreadystatechange = JSJaC.bind(function() { if (this._req[slot].r.readyState == 4) { this.oDbg.log("async recv: "+this._req[slot].r.responseText,4); this._handleInitialResponse(slot); // handle response } }, this); if (typeof(this._req[slot].r.onerror) != 'undefined') { this._req[slot].r.onerror = JSJaC.bind(function(e) { this.oDbg.log('XmlHttpRequest error',1); return false; }, this); } this._req[slot].r.send(reqstr); }; /** * Tells whether this connection is connected * @return true if this connections is connected, * false otherwise * @type boolean */ JSJaCConnection.prototype.connected = function() { return this._connected; }; /** * Disconnects from jabber server and terminates session (if applicable) */ JSJaCConnection.prototype.disconnect = function() { this._setStatus('disconnecting'); if (!this.connected()) return; this._connected = false; clearInterval(this._interval); clearInterval(this._inQto); if (this._timeout) clearTimeout(this._timeout); // remove timer var slot = this._getFreeSlot(); // Intentionally synchronous this._req[slot] = this._setupRequest(false); request = this._getRequestString(false, true); this.oDbg.log("Disconnecting: " + request,4); this._req[slot].r.send(request); try { JSJaCCookie.read(this._cookie_prefix+'JSJaC_State').erase(); } catch (e) {} this.oDbg.log("Disconnected: "+this._req[slot].r.responseText,2); this._handleEvent('ondisconnect'); }; /** * Gets current value of polling interval * @return Polling interval in milliseconds * @type int */ JSJaCConnection.prototype.getPollInterval = function() { return this._timerval; }; /** * Registers an event handler (callback) for this connection. *

Note: All of the packet handlers for specific packets (like * message_in, presence_in and iq_in) fire only if there's no * callback associated with the id.
*

Example:
* con.registerHandler('iq', 'query', 'jabber:iq:version', handleIqVersion); * @param {String} event One of *

    *
  • onConnect - connection has been established and authenticated
  • *
  • onDisconnect - connection has been disconnected
  • *
  • onResume - connection has been resumed
  • *
  • onStatusChanged - connection status has changed, current * status as being passed argument to handler. See {@link #status}.
  • *
  • onError - an error has occured, error node is supplied as * argument, like this:
    <error code='404' type='cancel'>
    * <item-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
    * </error>
  • *
  • packet_in - a packet has been received (argument: the * packet)
  • *
  • packet_out - a packet is to be sent(argument: the * packet)
  • *
  • message_in | message - a message has been received (argument: * the packet)
  • *
  • message_out - a message packet is to be sent (argument: the * packet)
  • *
  • presence_in | presence - a presence has been received * (argument: the packet)
  • *
  • presence_out - a presence packet is to be sent (argument: the * packet)
  • *
  • iq_in | iq - an iq has been received (argument: the packet)
  • *
  • iq_out - an iq is to be sent (argument: the packet)
  • *
* @param {String} childName A childnode's name that must occur within a * retrieved packet [optional] * @param {String} childNS A childnode's namespace that must occure within * a retrieved packet (works only if childName is given) [optional] * @param {String} type The type of the packet to handle (works only if childName and chidNS are given (both may be set to '*' in order to get skipped) [optional] * @param {Function} handler The handler to be called when event occurs. If your handler returns 'true' it cancels bubbling of the event. No other registered handlers for this event will be fired. */ JSJaCConnection.prototype.registerHandler = function(event) { event = event.toLowerCase(); // don't be case-sensitive here var eArg = {handler: arguments[arguments.length-1], childName: '*', childNS: '*', type: '*'}; if (arguments.length > 2) eArg.childName = arguments[1]; if (arguments.length > 3) eArg.childNS = arguments[2]; if (arguments.length > 4) eArg.type = arguments[3]; if (!this._events[event]) this._events[event] = new Array(eArg); else this._events[event] = this._events[event].concat(eArg); // sort events in order how specific they match criterias thus using // wildcard patterns puts them back in queue when it comes to // bubbling the event this._events[event] = this._events[event].sort(function(a,b) { var aRank = 0; var bRank = 0; with (a) { if (type == '*') aRank++; if (childNS == '*') aRank++; if (childName == '*') aRank++; } with (b) { if (type == '*') bRank++; if (childNS == '*') bRank++; if (childName == '*') bRank++; } if (aRank > bRank) return 1; if (aRank < bRank) return -1; return 0; }); this.oDbg.log("registered handler for event '"+event+"'",2); }; JSJaCConnection.prototype.unregisterHandler = function(event,handler) { event = event.toLowerCase(); // don't be case-sensitive here if (!this._events[event]) return; var arr = this._events[event], res = new Array(); for (var i=0; i *
  • 'initializing' ... well *
  • 'connecting' if connect() was called *
  • 'resuming' if resume() was called *
  • 'processing' if it's about to operate as normal *
  • 'onerror_fallback' if there was an error with the request object *
  • 'protoerror_fallback' if there was an error at the http binding protocol flow (most likely that's where you interested in) *
  • 'internal_server_error' in case of an internal server error *
  • 'suspending' if suspend() is being called *
  • 'aborted' if abort() was called *
  • 'disconnecting' if disconnect() has been called * * @type String */ JSJaCConnection.prototype.status = function() { return this._status; }; /** * Suspends this connection (saving state for later resume) * Saves state to cookie * @return Whether suspend (saving to cookie) was successful * @type boolean */ JSJaCConnection.prototype.suspend = function() { var data = this.suspendToData(); try { var c = new JSJaCCookie(this._cookie_prefix+'JSJaC_State', JSJaCJSON.toString(data)); this.oDbg.log("writing cookie: "+c.getValue()+"\n"+ "(length:"+c.getValue().length+")",2); c.write(); var c2 = JSJaCCookie.get(this._cookie_prefix+'JSJaC_State'); if (c.getValue() != c2) { this.oDbg.log("Suspend failed writing cookie.\nread: " + c2, 1); c.erase(); return false; } return true; } catch (e) { this.oDbg.log("Failed creating cookie '"+this._cookie_prefix+ "JSJaC_State': "+e.message,1); } return false; }; /** * Suspend connection and return serialized JSJaC connection state * @return JSJaC connection state object * @type Object */ JSJaCConnection.prototype.suspendToData = function() { // remove timers clearTimeout(this._timeout); clearInterval(this._interval); clearInterval(this._inQto); this._suspend(); var u = ('_connected,_keys,_ID,_inQ,_pQueue,_regIDs,_errcnt,_inactivity,domain,username,resource,jid,fulljid,_sid,_httpbase,_timerval,_is_polling').split(','); u = u.concat(this._getSuspendVars()); var s = new Object(); for (var i=0; i", this._doSASLAuthDone); } this.oDbg.log("SASL ANONYMOUS requested but not supported",1); } else { if (this.mechs['DIGEST-MD5']) { this.oDbg.log("SASL using mechanism 'DIGEST-MD5'",2); return this._sendRaw("", this._doSASLAuthDigestMd5S1); } else if (this.allow_plain && this.mechs['PLAIN']) { this.oDbg.log("SASL using mechanism 'PLAIN'",2); var authStr = this.username+'@'+ this.domain+String.fromCharCode(0)+ this.username+String.fromCharCode(0)+ this.pass; this.oDbg.log("authenticating with '"+authStr+"'",2); authStr = btoa(authStr); return this._sendRaw(""+authStr+"", this._doSASLAuthDone); } this.oDbg.log("No SASL mechanism applied",1); this.authtype = 'nonsasl'; // fallback } return false; }; /** * @private */ JSJaCConnection.prototype._doSASLAuthDigestMd5S1 = function(el) { if (el.nodeName != "challenge") { this.oDbg.log("challenge missing",1); this._handleEvent('onerror',JSJaCError('401','auth','not-authorized')); this.disconnect(); } else { var challenge = atob(el.firstChild.nodeValue); this.oDbg.log("got challenge: "+challenge,2); this._nonce = challenge.substring(challenge.indexOf("nonce=")+7); this._nonce = this._nonce.substring(0,this._nonce.indexOf("\"")); this.oDbg.log("nonce: "+this._nonce,2); if (this._nonce == '' || this._nonce.indexOf('\"') != -1) { this.oDbg.log("nonce not valid, aborting",1); this.disconnect(); return; } this._digest_uri = "xmpp/"; // if (typeof(this.host) != 'undefined' && this.host != '') { // this._digest-uri += this.host; // if (typeof(this.port) != 'undefined' && this.port) // this._digest-uri += ":" + this.port; // this._digest-uri += '/'; // } this._digest_uri += this.domain; this._cnonce = cnonce(14); this._nc = '00000001'; var A1 = str_md5(this.username+':'+this.domain+':'+this.pass)+ ':'+this._nonce+':'+this._cnonce; var A2 = 'AUTHENTICATE:'+this._digest_uri; var response = hex_md5(hex_md5(A1)+':'+this._nonce+':'+this._nc+':'+ this._cnonce+':auth:'+hex_md5(A2)); var rPlain = 'username="'+this.username+'",realm="'+this.domain+ '",nonce="'+this._nonce+'",cnonce="'+this._cnonce+'",nc="'+this._nc+ '",qop=auth,digest-uri="'+this._digest_uri+'",response="'+response+ '",charset="utf-8"'; this.oDbg.log("response: "+rPlain,2); this._sendRaw(""+ binb2b64(str2binb(rPlain))+"", this._doSASLAuthDigestMd5S2); } }; /** * @private */ JSJaCConnection.prototype._doSASLAuthDigestMd5S2 = function(el) { if (el.nodeName == 'failure') { if (el.xml) this.oDbg.log("auth error: "+el.xml,1); else this.oDbg.log("auth error",1); this._handleEvent('onerror',JSJaCError('401','auth','not-authorized')); this.disconnect(); return; } var response = atob(el.firstChild.nodeValue); this.oDbg.log("response: "+response,2); var rspauth = response.substring(response.indexOf("rspauth=")+8); this.oDbg.log("rspauth: "+rspauth,2); var A1 = str_md5(this.username+':'+this.domain+':'+this.pass)+ ':'+this._nonce+':'+this._cnonce; var A2 = ':'+this._digest_uri; var rsptest = hex_md5(hex_md5(A1)+':'+this._nonce+':'+this._nc+':'+ this._cnonce+':auth:'+hex_md5(A2)); this.oDbg.log("rsptest: "+rsptest,2); if (rsptest != rspauth) { this.oDbg.log("SASL Digest-MD5: server repsonse with wrong rspauth",1); this.disconnect(); return; } if (el.nodeName == 'success') this._reInitStream(this.domain, this._doStreamBind); else // some extra turn this._sendRaw("", this._doSASLAuthDone); }; /** * @private */ JSJaCConnection.prototype._doSASLAuthDone = function (el) { if (el.nodeName != 'success') { this.oDbg.log("auth failed",1); this._handleEvent('onerror',JSJaCError('401','auth','not-authorized')); this.disconnect(); } else this._reInitStream(this.domain, this._doStreamBind); }; /** * @private */ JSJaCConnection.prototype._doStreamBind = function() { var iq = new JSJaCIQ(); iq.setIQ(null,'set','bind_1'); iq.appendNode("bind", {xmlns: "urn:ietf:params:xml:ns:xmpp-bind"}, [["resource", this.resource]]); this.oDbg.log(iq.xml()); this.send(iq,this._doXMPPSess); }; /** * @private */ JSJaCConnection.prototype._doXMPPSess = function(iq) { if (iq.getType() != 'result' || iq.getType() == 'error') { // failed this.disconnect(); if (iq.getType() == 'error') this._handleEvent('onerror',iq.getChild('error')); return; } this.fulljid = iq.getChildVal("jid"); this.jid = this.fulljid.substring(0,this.fulljid.lastIndexOf('/')); iq = new JSJaCIQ(); iq.setIQ(this.domain,'set','sess_1'); iq.appendNode("session", {xmlns: "urn:ietf:params:xml:ns:xmpp-session"}, []); this.oDbg.log(iq.xml()); this.send(iq,this._doXMPPSessDone); }; /** * @private */ JSJaCConnection.prototype._doXMPPSessDone = function(iq) { if (iq.getType() != 'result' || iq.getType() == 'error') { // failed this.disconnect(); if (iq.getType() == 'error') this._handleEvent('onerror',iq.getChild('error')); return; } else this._handleEvent('onconnect'); }; /** * @private */ JSJaCConnection.prototype._handleEvent = function(event,arg) { event = event.toLowerCase(); // don't be case-sensitive here this.oDbg.log("incoming event '"+event+"'",3); if (!this._events[event]) return; this.oDbg.log("handling event '"+event+"'",2); for (var i=0;i match for handler "+aEvent.handler,3); } if (aEvent.handler(arg)) { // handled! break; } } else if (aEvent.handler()) { // handled! break; } } catch (e) { if (e.fileName&&e.lineNumber) { this.oDbg.log(aEvent.handler+"\n>>>"+e.name+": "+ e.message+' in '+e.fileName+' line '+e.lineNumber,1); } else { this.oDbg.log(aEvent.handler+"\n>>>"+e.name+": "+ e.message,1); } } } } }; /** * @private */ JSJaCConnection.prototype._handlePID = function(aJSJaCPacket) { if (!aJSJaCPacket.getID()) return false; for (var i in this._regIDs) { if (this._regIDs.hasOwnProperty(i) && this._regIDs[i] && i == aJSJaCPacket.getID()) { var pID = aJSJaCPacket.getID(); this.oDbg.log("handling "+pID,3); try { if (this._regIDs[i].cb.call(this, aJSJaCPacket, this._regIDs[i].arg) === false) { // don't unregister return false; } else { this._unregisterPID(pID); return true; } } catch (e) { // broken handler? this.oDbg.log(e.name+": "+ e.message, 1); this._unregisterPID(pID); return true; } } } return false; }; /** * @private */ JSJaCConnection.prototype._handleResponse = function(req) { var rootEl = this._parseResponse(req); if (!rootEl) return; for (var i=0; i JSJAC_ERR_COUNT) { // abort this._abort(); return false; } this._setStatus('onerror_fallback'); // schedule next tick setTimeout(JSJaC.bind(this._resume, this),this.getPollInterval()); return false; }, this); } catch(e) { } // well ... no onerror property available, maybe we // can catch the error somewhere else ... var reqstr = this._getRequestString(); if (typeof(this._rid) != 'undefined') // remember request id if any this._req[slot].rid = this._rid; this.oDbg.log("sending: " + reqstr,4); this._req[slot].r.send(reqstr); }; /** * @private */ JSJaCConnection.prototype._registerPID = function(pID,cb,arg) { if (!pID || !cb) return false; this._regIDs[pID] = new Object(); this._regIDs[pID].cb = cb; if (arg) this._regIDs[pID].arg = arg; this.oDbg.log("registered "+pID,3); return true; }; /** * send empty request * waiting for stream id to be able to proceed with authentication * @private */ JSJaCConnection.prototype._sendEmpty = function JSJaCSendEmpty() { var slot = this._getFreeSlot(); this._req[slot] = this._setupRequest(true); this._req[slot].r.onreadystatechange = JSJaC.bind(function() { if (this._req[slot].r.readyState == 4) { this.oDbg.log("async recv: "+this._req[slot].r.responseText,4); this._getStreamID(slot); // handle response } },this); if (typeof(this._req[slot].r.onerror) != 'undefined') { this._req[slot].r.onerror = JSJaC.bind(function(e) { this.oDbg.log('XmlHttpRequest error',1); return false; }, this); } var reqstr = this._getRequestString(); this.oDbg.log("sending: " + reqstr,4); this._req[slot].r.send(reqstr); }; /** * @private */ JSJaCConnection.prototype._sendRaw = function(xml,cb,arg) { if (cb) this._sendRawCallbacks.push({fn: cb, arg: arg}); this._pQueue.push(xml); this._process(); return true; }; /** * @private */ JSJaCConnection.prototype._setStatus = function(status) { if (!status || status == '') return; if (status != this._status) { // status changed! this._status = status; this._handleEvent('onstatuschanged', status); this._handleEvent('status_changed', status); } }; /** * @private */ JSJaCConnection.prototype._unregisterPID = function(pID) { if (!this._regIDs[pID]) return false; this._regIDs[pID] = null; this.oDbg.log("unregistered "+pID,3); return true; }; jsjac-1.3.4+dfsg/src/JSJaCConsoleLogger.js000066400000000000000000000041511153725753300202460ustar00rootroot00000000000000/** * @fileoverview Contains Debugger interface for Firebug and Safari * @class Implementation of the Debugger interface for {@link * http://www.getfirebug.com/ Firebug} and Safari * Creates a new debug logger to be passed to jsjac's connection * constructor. Of course you can use it for debugging in your code * too. * @constructor * @param {int} level The maximum level for debugging messages to be * displayed. Thus you can tweak the verbosity of the logger. A value * of 0 means very low traffic whilst a value of 4 makes logging very * verbose about what's going on. */ function JSJaCConsoleLogger(level) { /** * @private */ this.level = level || 4; /** * Empty function for API compatibility */ this.start = function() {}; /** * Logs a message to firebug's/safari's console * @param {String} msg The message to be logged. * @param {int} level The message's verbosity level. Importance is * from 0 (very important) to 4 (not so important). A value of 1 * denotes an error in the usual protocol flow. */ this.log = function(msg, level) { level = level || 0; if (level > this.level) return; if (typeof(console) == 'undefined') return; try { switch (level) { case 0: console.warn(msg); break; case 1: console.error(msg); break; case 2: console.info(msg); break; case 4: console.debug(msg); break; default: console.log(msg); break; } } catch(e) { try { console.log(msg) } catch(e) {} } }; /** * Sets verbosity level. * @param {int} level The maximum level for debugging messages to be * displayed. Thus you can tweak the verbosity of the logger. A * value of 0 means very low traffic whilst a value of 4 makes * logging very verbose about what's going on. * @return This debug logger * @type ConsoleLogger */ this.setLevel = function(level) { this.level = level; return this; }; /** * Gets verbosity level. * @return The level * @type int */ this.getLevel = function() { return this.level; }; } jsjac-1.3.4+dfsg/src/JSJaCConstants.js000066400000000000000000000100031153725753300174510ustar00rootroot00000000000000var NS_DISCO_ITEMS = "http://jabber.org/protocol/disco#items"; var NS_DISCO_INFO = "http://jabber.org/protocol/disco#info"; var NS_VCARD = "vcard-temp"; var NS_AUTH = "jabber:iq:auth"; var NS_AUTH_ERROR = "jabber:iq:auth:error"; var NS_REGISTER = "jabber:iq:register"; var NS_SEARCH = "jabber:iq:search"; var NS_ROSTER = "jabber:iq:roster"; var NS_PRIVACY = "jabber:iq:privacy"; var NS_PRIVATE = "jabber:iq:private"; var NS_VERSION = "jabber:iq:version"; var NS_TIME = "jabber:iq:time"; var NS_LAST = "jabber:iq:last"; var NS_XDATA = "jabber:x:data"; var NS_IQDATA = "jabber:iq:data"; var NS_DELAY = "jabber:x:delay"; var NS_EXPIRE = "jabber:x:expire"; var NS_EVENT = "jabber:x:event"; var NS_XCONFERENCE = "jabber:x:conference"; var NS_STATS = "http://jabber.org/protocol/stats"; var NS_MUC = "http://jabber.org/protocol/muc"; var NS_MUC_USER = "http://jabber.org/protocol/muc#user"; var NS_MUC_ADMIN = "http://jabber.org/protocol/muc#admin"; var NS_MUC_OWNER = "http://jabber.org/protocol/muc#owner"; var NS_PUBSUB = "http://jabber.org/protocol/pubsub"; var NS_PUBSUB_EVENT = "http://jabber.org/protocol/pubsub#event"; var NS_PUBSUB_OWNER = "http://jabber.org/protocol/pubsub#owner"; var NS_PUBSUB_NMI = "http://jabber.org/protocol/pubsub#node-meta-info"; var NS_COMMANDS = "http://jabber.org/protocol/commands"; var NS_STREAM = "http://etherx.jabber.org/streams"; var NS_STANZAS = "urn:ietf:params:xml:ns:xmpp-stanzas"; var NS_STREAMS = "urn:ietf:params:xml:ns:xmpp-streams"; var NS_TLS = "urn:ietf:params:xml:ns:xmpp-tls"; var NS_SASL = "urn:ietf:params:xml:ns:xmpp-sasl"; var NS_SESSION = "urn:ietf:params:xml:ns:xmpp-session"; var NS_BIND = "urn:ietf:params:xml:ns:xmpp-bind"; var NS_FEATURE_IQAUTH = "http://jabber.org/features/iq-auth"; var NS_FEATURE_IQREGISTER = "http://jabber.org/features/iq-register"; var NS_FEATURE_COMPRESS = "http://jabber.org/features/compress"; var NS_COMPRESS = "http://jabber.org/protocol/compress"; function STANZA_ERROR(code, type, cond) { if (window == this) return new STANZA_ERROR(code, type, cond); this.code = code; this.type = type; this.cond = cond; } var ERR_BAD_REQUEST = STANZA_ERROR("400", "modify", "bad-request"); var ERR_CONFLICT = STANZA_ERROR("409", "cancel", "conflict"); var ERR_FEATURE_NOT_IMPLEMENTED = STANZA_ERROR("501", "cancel", "feature-not-implemented"); var ERR_FORBIDDEN = STANZA_ERROR("403", "auth", "forbidden"); var ERR_GONE = STANZA_ERROR("302", "modify", "gone"); var ERR_INTERNAL_SERVER_ERROR = STANZA_ERROR("500", "wait", "internal-server-error"); var ERR_ITEM_NOT_FOUND = STANZA_ERROR("404", "cancel", "item-not-found"); var ERR_JID_MALFORMED = STANZA_ERROR("400", "modify", "jid-malformed"); var ERR_NOT_ACCEPTABLE = STANZA_ERROR("406", "modify", "not-acceptable"); var ERR_NOT_ALLOWED = STANZA_ERROR("405", "cancel", "not-allowed"); var ERR_NOT_AUTHORIZED = STANZA_ERROR("401", "auth", "not-authorized"); var ERR_PAYMENT_REQUIRED = STANZA_ERROR("402", "auth", "payment-required"); var ERR_RECIPIENT_UNAVAILABLE = STANZA_ERROR("404", "wait", "recipient-unavailable"); var ERR_REDIRECT = STANZA_ERROR("302", "modify", "redirect"); var ERR_REGISTRATION_REQUIRED = STANZA_ERROR("407", "auth", "registration-required"); var ERR_REMOTE_SERVER_NOT_FOUND = STANZA_ERROR("404", "cancel", "remote-server-not-found"); var ERR_REMOTE_SERVER_TIMEOUT = STANZA_ERROR("504", "wait", "remote-server-timeout"); var ERR_RESOURCE_CONSTRAINT = STANZA_ERROR("500", "wait", "resource-constraint"); var ERR_SERVICE_UNAVAILABLE = STANZA_ERROR("503", "cancel", "service-unavailable"); var ERR_SUBSCRIPTION_REQUIRED = STANZA_ERROR("407", "auth", "subscription-required"); var ERR_UNEXPECTED_REQUEST = STANZA_ERROR("400", "wait", "unexpected-request"); jsjac-1.3.4+dfsg/src/JSJaCCookie.js000066400000000000000000000120771153725753300167230ustar00rootroot00000000000000/* Copyright 2003-2006 Peter-Paul Koch * 2006-2008 Stefan Strigler */ /** * @fileoverview OO interface to handle cookies. * Taken from {@link http://www.quirksmode.org/js/cookies.html * http://www.quirksmode.org/js/cookies.html} * Regarding licensing of this code the author states: * * "You may copy, tweak, rewrite, sell or lease any code example on * this site, with one single exception." * * @author Stefan Strigler * @version $Revision$ */ /** * Creates a new Cookie * @class Class representing browser cookies for storing small amounts of data * @constructor * @param {String} name The name of the value to store * @param {String} value The value to store * @param {int} secs Number of seconds until cookie expires (may be empty) * @param {String} domain The domain for the cookie * @param {String} path The path of cookie */ function JSJaCCookie(name,value,secs,domain,path) { if (window == this) return new JSJaCCookie(name, value, secs, domain, path); /** * This cookie's name * @type String */ this.name = name; /** * This cookie's value * @type String */ this.value = value; /** * Time in seconds when cookie expires (thus being delete by * browser). A value of -1 denotes a session cookie which means that * stored data gets lost when browser is being closed. * @type int */ this.secs = secs; /** * The cookie's domain * @type string */ this.domain = domain; /** * The cookie's path * @type string */ this.path = path; /** * Stores this cookie */ this.write = function() { if (this.secs) { var date = new Date(); date.setTime(date.getTime()+(this.secs*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; var domain = this.domain?"; domain="+this.domain:""; var path = this.path?"; path="+this.path:"; path=/"; document.cookie = this.getName()+"="+JSJaCCookie._escape(this.getValue())+ expires+ domain+ path; }; /** * Deletes this cookie */ this.erase = function() { var c = new JSJaCCookie(this.getName(),"",-1); c.write(); }; /** * Gets the name of this cookie * @return The name * @type String */ this.getName = function() { return this.name; }; /** * Sets the name of this cookie * @param {String} name The name for this cookie * @return This cookie * @type Cookie */ this.setName = function(name) { this.name = name; return this; }; /** * Gets the value of this cookie * @return The value * @type String */ this.getValue = function() { return this.value; }; /** * Sets the value of this cookie * @param {String} value The value for this cookie * @return This cookie * @type Cookie */ this.setValue = function(value) { this.value = value; return this; }; /** * Sets the domain of this cookie * @param {String} domain The value for the domain of the cookie * @return This cookie * @type Cookie */ this.setDomain = function(domain) { this.domain = domain; return this; }; /** * Sets the path of this cookie * @param {String} path The value of the path of the cookie * @return This cookie * @type Cookie */ this.setPath = function(path) { this.path = path; return this; }; } /** * Reads the value for given name from cookies and return new * Cookie object * @param {String} name The name of the cookie to read * @return A cookie object of the given name * @type Cookie * @throws CookieException when cookie with given name could not be found */ JSJaCCookie.read = function(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return new JSJaCCookie( name, JSJaCCookie._unescape(c.substring(nameEQ.length,c.length))); } throw new JSJaCCookieException("Cookie not found"); }; /** * Reads the value for given name from cookies and returns * its valued new * @param {String} name The name of the cookie to read * @return The value of the cookie read * @type String * @throws CookieException when cookie with given name could not be found */ JSJaCCookie.get = function(name) { return JSJaCCookie.read(name).getValue(); }; /** * Deletes cookie with given name * @param {String} name The name of the cookie to delete * @throws CookieException when cookie with given name could not be found */ JSJaCCookie.remove = function(name) { JSJaCCookie.read(name).erase(); }; /** * @private */ JSJaCCookie._escape = function(str) { return str.replace(/;/g, "%3AB"); } /** * @private */ JSJaCCookie._unescape = function(str) { return str.replace(/%3AB/g, ";"); } /** * Some exception denoted to dealing with cookies * @constructor * @param {String} msg The message to pass to the exception */ function JSJaCCookieException(msg) { this.message = msg; this.name = "CookieException"; } jsjac-1.3.4+dfsg/src/JSJaCError.js000066400000000000000000000007211153725753300165740ustar00rootroot00000000000000 /** * an error packet for internal use * @private * @constructor */ function JSJaCError(code,type,condition) { var xmldoc = XmlDocument.create("error","jsjac"); xmldoc.documentElement.setAttribute('code',code); xmldoc.documentElement.setAttribute('type',type); if (condition) xmldoc.documentElement.appendChild(xmldoc.createElement(condition)). setAttribute('xmlns','urn:ietf:params:xml:ns:xmpp-stanzas'); return xmldoc.documentElement; } jsjac-1.3.4+dfsg/src/JSJaCHttpBindingConnection.js000066400000000000000000000354071153725753300217460ustar00rootroot00000000000000/** * @fileoverview All stuff related to HTTP Binding * @author Stefan Strigler steve@zeank.in-berlin.de * @version $Revision$ */ /** * Instantiates an HTTP Binding session * @class Implementation of {@link * http://www.xmpp.org/extensions/xep-0206.html XMPP Over BOSH} * formerly known as HTTP Binding. * @extends JSJaCConnection * @constructor */ function JSJaCHttpBindingConnection(oArg) { /** * @ignore */ this.base = JSJaCConnection; this.base(oArg); // member vars /** * @private */ this._hold = JSJACHBC_MAX_HOLD; /** * @private */ this._inactivity = 0; /** * @private */ this._last_requests = new Object(); // 'hash' storing hold+1 last requests /** * @private */ this._last_rid = 0; // I know what you did last summer /** * @private */ this._min_polling = 0; /** * @private */ this._pause = 0; /** * @private */ this._wait = JSJACHBC_MAX_WAIT; } JSJaCHttpBindingConnection.prototype = new JSJaCConnection(); /** * Inherit an instantiated HTTP Binding session */ JSJaCHttpBindingConnection.prototype.inherit = function(oArg) { if (oArg.jid) { var oJid = new JSJaCJID(oArg.jid); this.domain = oJid.getDomain(); this.username = oJid.getNode(); this.resource = oJid.getResource(); } else { this.domain = oArg.domain || 'localhost'; this.username = oArg.username; this.resource = oArg.resource; } this._sid = oArg.sid; this._rid = oArg.rid; this._min_polling = oArg.polling; this._inactivity = oArg.inactivity; this._setHold(oArg.requests-1); this.setPollInterval(this._timerval); if (oArg.wait) this._wait = oArg.wait; // for whatever reason this._connected = true; this._handleEvent('onconnect'); this._interval= setInterval(JSJaC.bind(this._checkQueue, this), JSJAC_CHECKQUEUEINTERVAL); this._inQto = setInterval(JSJaC.bind(this._checkInQ, this), JSJAC_CHECKINQUEUEINTERVAL); this._timeout = setTimeout(JSJaC.bind(this._process, this), this.getPollInterval()); }; /** * Sets poll interval * @param {int} timerval the interval in seconds */ JSJaCHttpBindingConnection.prototype.setPollInterval = function(timerval) { if (timerval && !isNaN(timerval)) { if (!this.isPolling()) this._timerval = 100; else if (this._min_polling && timerval < this._min_polling*1000) this._timerval = this._min_polling*1000; else if (this._inactivity && timerval > this._inactivity*1000) this._timerval = this._inactivity*1000; else this._timerval = timerval; } return this._timerval; }; /** * whether this session is in polling mode * @type boolean */ JSJaCHttpBindingConnection.prototype.isPolling = function() { return (this._hold == 0) }; /** * @private */ JSJaCHttpBindingConnection.prototype._getFreeSlot = function() { for (var i=0; i"; } else { reqstr += "/>"; } this._last_requests[this._rid] = new Object(); this._last_requests[this._rid].xml = reqstr; this._last_rid = this._rid; for (var i in this._last_requests) if (this._last_requests.hasOwnProperty(i) && i < this._rid-this._hold) delete(this._last_requests[i]); // truncate } return reqstr; }; /** * @private */ JSJaCHttpBindingConnection.prototype._getInitialRequestString = function() { var reqstr = " JSJAC_ERR_COUNT) { // abort this._abort(); return null; } if (this.connected()) { this.oDbg.log("repeating ("+this._errcnt+")",1); this._setStatus('proto_error_fallback'); // schedule next tick setTimeout(JSJaC.bind(this._resume, this), this.getPollInterval()); } return null; } } catch (e) { this.oDbg.log("XMLHttpRequest error: status not available", 1); this._errcnt++; if (this._errcnt > JSJAC_ERR_COUNT) { // abort this._abort(); } else { if (this.connected()) { this.oDbg.log("repeating ("+this._errcnt+")",1); this._setStatus('proto_error_fallback'); // schedule next tick setTimeout(JSJaC.bind(this._resume, this), this.getPollInterval()); } } return null; } var body = r.responseXML.documentElement; if (!body || body.tagName != 'body' || body.namespaceURI != 'http://jabber.org/protocol/httpbind') { this.oDbg.log("invalid response:\n" + r.responseText,1); clearTimeout(this._timeout); // remove timer clearInterval(this._interval); clearInterval(this._inQto); this._connected = false; this.oDbg.log("Disconnected.",1); this._handleEvent('ondisconnect'); this._setStatus('internal_server_error'); this._handleEvent('onerror', JSJaCError('500','wait','internal-server-error')); return null; } if (typeof(req.rid) != 'undefined' && this._last_requests[req.rid]) { if (this._last_requests[req.rid].handled) { this.oDbg.log("already handled "+req.rid,2); return null; } else this._last_requests[req.rid].handled = true; } // Check for errors from the server if (body.getAttribute("type") == "terminate") { this.oDbg.log("session terminated:\n" + r.responseText,1); clearTimeout(this._timeout); // remove timer clearInterval(this._interval); clearInterval(this._inQto); var condition = body.getAttribute('condition'); if (condition == "remote-stream-error") if (body.getElementsByTagName("conflict").length > 0) this._setStatus("session-terminate-conflict"); if (condition == null) condition = 'session-terminate'; this._handleEvent('onerror',JSJaCError('503','cancel',condition)); this._connected = false; this.oDbg.log("Disconnected.",1); this._handleEvent('ondisconnect'); return null; } // no error this._errcnt = 0; return r.responseXML.documentElement; }; /** * @private */ JSJaCHttpBindingConnection.prototype._reInitStream = function(to,cb,arg) { /* [TODO] we can't handle 'to' here as this is not (yet) supported * by the protocol */ // tell http binding to reinit stream with/before next request this._reinit = true; cb.call(this,arg); // proceed with next callback /* [TODO] make sure that we're checking for new stream features when * 'cb' finishes */ }; /** * @private */ JSJaCHttpBindingConnection.prototype._resume = function() { /* make sure to repeat last request as we can be sure that * it had failed (only if we're not using the 'pause' attribute */ if (this._pause == 0 && this._rid >= this._last_rid) this._rid = this._last_rid-1; this._process(); }; /** * @private */ JSJaCHttpBindingConnection.prototype._setHold = function(hold) { if (!hold || isNaN(hold) || hold < 0) hold = 0; else if (hold > JSJACHBC_MAX_HOLD) hold = JSJACHBC_MAX_HOLD; this._hold = hold; return this._hold; }; /** * @private */ JSJaCHttpBindingConnection.prototype._setupRequest = function(async) { var req = new Object(); var r = XmlHttp.create(); try { r.open("POST",this._httpbase,async); r.setRequestHeader('Content-Type','text/xml; charset=utf-8'); } catch(e) { this.oDbg.log(e,1); } req.r = r; this._rid++; req.rid = this._rid; return req; }; /** * @private */ JSJaCHttpBindingConnection.prototype._suspend = function() { if (this._pause == 0) return; // got nothing to do var slot = this._getFreeSlot(); // Intentionally synchronous this._req[slot] = this._setupRequest(false); var reqstr = "true if this is a polling connection, * false otherwise. * @type boolean */ JSJaCHttpPollingConnection.prototype.isPolling = function() { return true; }; /** * @private */ JSJaCHttpPollingConnection.prototype._getFreeSlot = function() { if (typeof(this._req[0]) == 'undefined' || typeof(this._req[0].r) == 'undefined' || this._req[0].r.readyState == 4) return 0; else return -1; }; /** * @private */ JSJaCHttpPollingConnection.prototype._getInitialRequestString = function() { var reqstr = "0"; if (JSJAC_HAVEKEYS) { this._keys = new JSJaCKeys(b64_sha1,this.oDbg); // generate first set of keys key = this._keys.getKey(); reqstr += ";"+key; } var streamto = this.domain; if (this.authhost) streamto = this.authhost; reqstr += ",\s*$/)) response += ''; doc = XmlDocument.create("doc"); doc.loadXML(response); if (!this._parseStreamFeatures(doc)) { this.authtype = 'nonsasl'; return; } } catch(e) { this.oDbg.log("loadXML: "+e.toString(),1); } this._connected = true; if (this.register) this._doInBandReg(); else this._doAuth(); this._process(this._timerval); // start polling }; /** * @private */ JSJaCHttpPollingConnection.prototype._getSuspendVars = function() { return new Array(); }; /** * @private */ JSJaCHttpPollingConnection.prototype._handleInitialResponse = function() { // extract session ID this.oDbg.log(this._req[0].r.getAllResponseHeaders(),4); var aPList = this._req[0].r.getResponseHeader('Set-Cookie'); aPList = aPList.split(";"); for (var i=0;i/,""); if (response.match(/"+response+""); if (!doc || doc.tagName == 'parsererror') { this.oDbg.log("parsererror",1); doc = JSJaCHttpPollingConnection._parseTree(""+req.responseText); if (doc && doc.tagName != 'parsererror') { this.oDbg.log("stream closed",1); if (doc.getElementsByTagName('conflict').length > 0) this._setStatus("session-terminate-conflict"); clearTimeout(this._timeout); // remove timer clearInterval(this._interval); clearInterval(this._inQto); this._handleEvent('onerror',JSJaCError('503','cancel','session-terminate')); this._connected = false; this.oDbg.log("Disconnected.",1); this._handleEvent('ondisconnect'); } else this.oDbg.log("parsererror:"+doc,1); return doc; } return doc; } catch (e) { this.oDbg.log("parse error:"+e.message,1); } return null;; }; /** * @private */ JSJaCHttpPollingConnection.prototype._reInitStream = function(to,cb,arg) { this._sendRaw("",cb,arg); }; /** * @private */ JSJaCHttpPollingConnection.prototype._resume = function() { this._process(this._timerval); }; /** * @private */ JSJaCHttpPollingConnection.prototype._setupRequest = function(async) { var r = XmlHttp.create(); try { r.open("POST",this._httpbase,async); if (r.overrideMimeType) r.overrideMimeType('text/plain; charset=utf-8'); r.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); } catch(e) { this.oDbg.log(e,1); } var req = new Object(); req.r = r; return req; }; /** * @private */ JSJaCHttpPollingConnection.prototype._suspend = function() {}; /*** [static] ***/ /** * @private */ JSJaCHttpPollingConnection._parseTree = function(s) { try { var r = XmlDocument.create("body","foo"); if (typeof(r.loadXML) != 'undefined') { r.loadXML(s); return r.documentElement; } else if (window.DOMParser) return (new DOMParser()).parseFromString(s, "text/xml").documentElement; } catch (e) { } return null; }; jsjac-1.3.4+dfsg/src/JSJaCJID.js000066400000000000000000000116061153725753300161150ustar00rootroot00000000000000/** * @fileoverview This file contains all things that make life easier when * dealing with JIDs * @author Stefan Strigler * @version $Revision$ */ /** * list of forbidden chars for nodenames * @private */ var JSJACJID_FORBIDDEN = ['"',' ','&','\'','/',':','<','>','@']; /** * Creates a new JSJaCJID object * @class JSJaCJID models xmpp jid objects * @constructor * @param {Object} jid jid may be either of type String or a JID represented * by JSON with fields 'node', 'domain' and 'resource' * @throws JSJaCJIDInvalidException Thrown if jid is not valid * @return a new JSJaCJID object */ function JSJaCJID(jid) { /** *@private */ this._node = ''; /** *@private */ this._domain = ''; /** *@private */ this._resource = ''; if (typeof(jid) == 'string') { if (jid.indexOf('@') != -1) { this.setNode(jid.substring(0,jid.indexOf('@'))); jid = jid.substring(jid.indexOf('@')+1); } if (jid.indexOf('/') != -1) { this.setResource(jid.substring(jid.indexOf('/')+1)); jid = jid.substring(0,jid.indexOf('/')); } this.setDomain(jid); } else { this.setNode(jid.node); this.setDomain(jid.domain); this.setResource(jid.resource); } } /** * Gets the node part of the jid * @return A string representing the node name * @type String */ JSJaCJID.prototype.getNode = function() { return this._node; }; /** * Gets the domain part of the jid * @return A string representing the domain name * @type String */ JSJaCJID.prototype.getDomain = function() { return this._domain; }; /** * Gets the resource part of the jid * @return A string representing the resource * @type String */ JSJaCJID.prototype.getResource = function() { return this._resource; }; /** * Sets the node part of the jid * @param {String} node Name of the node * @throws JSJaCJIDInvalidException Thrown if node name contains invalid chars * @return This object * @type JSJaCJID */ JSJaCJID.prototype.setNode = function(node) { JSJaCJID._checkNodeName(node); this._node = node || ''; return this; }; /** * Sets the domain part of the jid * @param {String} domain Name of the domain * @throws JSJaCJIDInvalidException Thrown if domain name contains invalid * chars or is empty * @return This object * @type JSJaCJID */ JSJaCJID.prototype.setDomain = function(domain) { if (!domain || domain == '') throw new JSJaCJIDInvalidException("domain name missing"); // chars forbidden for a node are not allowed in domain names // anyway, so let's check JSJaCJID._checkNodeName(domain); this._domain = domain; return this; }; /** * Sets the resource part of the jid * @param {String} resource Name of the resource * @return This object * @type JSJaCJID */ JSJaCJID.prototype.setResource = function(resource) { this._resource = resource || ''; return this; }; /** * The string representation of the full jid * @return A string representing the jid * @type String */ JSJaCJID.prototype.toString = function() { var jid = ''; if (this.getNode() && this.getNode() != '') jid = this.getNode() + '@'; jid += this.getDomain(); // we always have a domain if (this.getResource() && this.getResource() != "") jid += '/' + this.getResource(); return jid; }; /** * Removes the resource part of the jid * @return This object * @type JSJaCJID */ JSJaCJID.prototype.removeResource = function() { return this.setResource(); }; /** * creates a copy of this JSJaCJID object * @return A copy of this * @type JSJaCJID */ JSJaCJID.prototype.clone = function() { return new JSJaCJID(this.toString()); }; /** * Compares two jids if they belong to the same entity (i.e. w/o resource) * @param {String} jid a jid as string or JSJaCJID object * @return 'true' if jid is same entity as this * @type Boolean */ JSJaCJID.prototype.isEntity = function(jid) { if (typeof jid == 'string') jid = (new JSJaCJID(jid)); jid.removeResource(); return (this.clone().removeResource().toString() === jid.toString()); }; /** * Check if node name is valid * @private * @param {String} node A name for a node * @throws JSJaCJIDInvalidException Thrown if name for node is not allowed */ JSJaCJID._checkNodeName = function(nodeprep) { if (!nodeprep || nodeprep == '') return; for (var i=0; i< JSJACJID_FORBIDDEN.length; i++) { if (nodeprep.indexOf(JSJACJID_FORBIDDEN[i]) != -1) { throw new JSJaCJIDInvalidException("forbidden char in nodename: "+JSJACJID_FORBIDDEN[i]); } } }; /** * Creates a new Exception of type JSJaCJIDInvalidException * @class Exception to indicate invalid values for a jid * @constructor * @param {String} message The message associated with this Exception */ function JSJaCJIDInvalidException(message) { /** * The exceptions associated message * @type String */ this.message = message; /** * The name of the exception * @type String */ this.name = "JSJaCJIDInvalidException"; } jsjac-1.3.4+dfsg/src/JSJaCJSON.js000066400000000000000000000065431153725753300162640ustar00rootroot00000000000000/* Copyright (c) 2005-2007 Sam Stephenson * * 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 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. */ /* json.js taken from prototype.js, made static */ function JSJaCJSON() {} JSJaCJSON.toString = function (obj) { var m = { '\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"' : '\\"', '\\': '\\\\' }, s = { array: function (x) { var a = ['['], b, f, i, l = x.length, v; for (i = 0; i < l; i += 1) { v = x[i]; f = s[typeof v]; if (f) { try { v = f(v); if (typeof v == 'string') { if (b) { a[a.length] = ','; } a[a.length] = v; b = true; } } catch(e) { } } } a[a.length] = ']'; return a.join(''); }, 'boolean': function (x) { return String(x); }, 'null': function (x) { return "null"; }, number: function (x) { return isFinite(x) ? String(x) : 'null'; }, object: function (x) { if (x) { if (x instanceof Array) { return s.array(x); } var a = ['{'], b, f, i, v; for (i in x) { if (x.hasOwnProperty(i)) { v = x[i]; f = s[typeof v]; if (f) { try { v = f(v); if (typeof v == 'string') { if (b) { a[a.length] = ','; } a.push(s.string(i), ':', v); b = true; } } catch(e) { } } } } a[a.length] = '}'; return a.join(''); } return 'null'; }, string: function (x) { if (/["\\\x00-\x1f]/.test(x)) { x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) { var c = m[b]; if (c) { return c; } c = b.charCodeAt(); return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16); }); } return '"' + x + '"'; } }; switch (typeof(obj)) { case 'object': return s.object(obj); case 'array': return s.array(obj); } }; JSJaCJSON.parse = function (str) { try { return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test( str.replace(/"(\\.|[^"\\])*"/g, ''))) && eval('(' + str + ')'); } catch (e) { return false; } }; jsjac-1.3.4+dfsg/src/JSJaCKeys.js000066400000000000000000000026571153725753300164300ustar00rootroot00000000000000 /** * Creates a new set of hash keys * @class Reflects a set of sha1/md5 hash keys for securing sessions * @constructor * @param {Function} func The hash function to be used for creating the keys * @param {Debugger} oDbg Reference to debugger implementation [optional] */ function JSJaCKeys(func,oDbg) { var seed = Math.random(); /** * @private */ this._k = new Array(); this._k[0] = seed.toString(); if (oDbg) /** * Reference to Debugger * @type Debugger */ this.oDbg = oDbg; else { this.oDbg = {}; this.oDbg.log = function() {}; } if (func) { for (var i=1; itrue if there's only one key left, false otherwise * @type boolean */ this.lastKey = function() { return (this._indexAt == 0); }; /** * Returns number of overall/initial stack size * @return Number of keys created * @type int */ this.size = function() { return this._k.length; }; /** * @private */ this._getSuspendVars = function() { return ('_k,_indexAt').split(','); } } jsjac-1.3.4+dfsg/src/JSJaCPacket.js000066400000000000000000000500241153725753300167130ustar00rootroot00000000000000/** * @fileoverview Contains all Jabber/XMPP packet related classes. * @author Stefan Strigler steve@zeank.in-berlin.de * @version $Revision$ */ var JSJACPACKET_USE_XMLNS = true; /** * Creates a new packet with given root tag name (for internal use) * @class Somewhat abstract base class for all kinds of specialised packets * @param {String} name The root tag name of the packet * (i.e. one of 'message', 'iq' or 'presence') */ function JSJaCPacket(name) { /** * @private */ this.name = name; if (typeof(JSJACPACKET_USE_XMLNS) != 'undefined' && JSJACPACKET_USE_XMLNS) /** * @private */ this.doc = XmlDocument.create(name,'jabber:client'); else /** * @private */ this.doc = XmlDocument.create(name,''); } /** * Gets the type (name of root element) of this packet, i.e. one of * 'presence', 'message' or 'iq' * @return the top level tag name * @type String */ JSJaCPacket.prototype.pType = function() { return this.name; }; /** * Gets the associated Document for this packet. * @type {@link http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#i-Document Document} */ JSJaCPacket.prototype.getDoc = function() { return this.doc; }; /** * Gets the root node of this packet * @type {@link http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247 Node} */ JSJaCPacket.prototype.getNode = function() { if (this.getDoc() && this.getDoc().documentElement) return this.getDoc().documentElement; else return null; }; /** * Sets the 'to' attribute of the root node of this packet * @param {String} to * @type JSJaCPacket */ JSJaCPacket.prototype.setTo = function(to) { if (!to || to == '') this.getNode().removeAttribute('to'); else if (typeof(to) == 'string') this.getNode().setAttribute('to',to); else this.getNode().setAttribute('to',to.toString()); return this; }; /** * Sets the 'from' attribute of the root node of this * packet. Usually this is not needed as the server will take care * of this automatically. * @type JSJaCPacket */ JSJaCPacket.prototype.setFrom = function(from) { if (!from || from == '') this.getNode().removeAttribute('from'); else if (typeof(from) == 'string') this.getNode().setAttribute('from',from); else this.getNode().setAttribute('from',from.toString()); return this; }; /** * Sets 'id' attribute of the root node of this packet. * @param {String} id The id of the packet. * @type JSJaCPacket */ JSJaCPacket.prototype.setID = function(id) { if (!id || id == '') this.getNode().removeAttribute('id'); else this.getNode().setAttribute('id',id); return this; }; /** * Sets the 'type' attribute of the root node of this packet. * @param {String} type The type of the packet. * @type JSJaCPacket */ JSJaCPacket.prototype.setType = function(type) { if (!type || type == '') this.getNode().removeAttribute('type'); else this.getNode().setAttribute('type',type); return this; }; /** * Sets 'xml:lang' for this packet * @param {String} xmllang The xml:lang of the packet. * @type JSJaCPacket */ JSJaCPacket.prototype.setXMLLang = function(xmllang) { if (!xmllang || xmllang == '') this.getNode().removeAttribute('xml:lang'); else this.getNode().setAttribute('xml:lang',xmllang); return this; }; /** * Gets the 'to' attribute of this packet * @type String */ JSJaCPacket.prototype.getTo = function() { return this.getNode().getAttribute('to'); }; /** * Gets the 'from' attribute of this packet. * @type String */ JSJaCPacket.prototype.getFrom = function() { return this.getNode().getAttribute('from'); }; /** * Gets the 'to' attribute of this packet as a JSJaCJID object * @type JSJaCJID */ JSJaCPacket.prototype.getToJID = function() { return new JSJaCJID(this.getTo()); }; /** * Gets the 'from' attribute of this packet as a JSJaCJID object * @type JSJaCJID */ JSJaCPacket.prototype.getFromJID = function() { return new JSJaCJID(this.getFrom()); }; /** * Gets the 'id' of this packet * @type String */ JSJaCPacket.prototype.getID = function() { return this.getNode().getAttribute('id'); }; /** * Gets the 'type' of this packet * @type String */ JSJaCPacket.prototype.getType = function() { return this.getNode().getAttribute('type'); }; /** * Gets the 'xml:lang' of this packet * @type String */ JSJaCPacket.prototype.getXMLLang = function() { return this.getNode().getAttribute('xml:lang'); }; /** * Gets the 'xmlns' (xml namespace) of the root node of this packet * @type String */ JSJaCPacket.prototype.getXMLNS = function() { return this.getNode().namespaceURI || this.getNode().getAttribute('xmlns'); }; /** * Gets a child element of this packet. If no params given returns first child. * @param {String} name Tagname of child to retrieve. Use '*' to match any tag. [optional] * @param {String} ns Namespace of child. Use '*' to match any ns.[optional] * @return The child node, null if none found * @type {@link http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247 Node} */ JSJaCPacket.prototype.getChild = function(name, ns) { if (!this.getNode()) { return null; } name = name || '*'; ns = ns || '*'; if (this.getNode().getElementsByTagNameNS) { return this.getNode().getElementsByTagNameNS(ns, name).item(0); } // fallback var nodes = this.getNode().getElementsByTagName(name); if (ns != '*') { for (var i=0; i 0) for (var i = 0, il = node.attributes.length;i < il; i++) { var attr = node.attributes.item(i); if (attr.nodeName == 'xmlns' && newNode.getAttribute('xmlns') != null ) continue; if (newNode.setAttributeNS && attr.namespaceURI) { newNode.setAttributeNS(attr.namespaceURI, attr.nodeName, attr.nodeValue); } else { newNode.setAttribute(attr.nodeName, attr.nodeValue); } } /* are we going after children too, and does the node have any? */ if (allChildren && node.childNodes && node.childNodes.length > 0) { for (var i = 0, il = node.childNodes.length; i < il; i++) { newNode.appendChild(this._importNode(node.childNodes.item(i), allChildren)); } } return newNode; break; case document.TEXT_NODE: case document.CDATA_SECTION_NODE: case document.COMMENT_NODE: return this.getDoc().createTextNode(node.nodeValue); break; } }; /** * Set node value of a child node * @private */ JSJaCPacket.prototype._setChildNode = function(nodeName, nodeValue) { var aNode = this.getChild(nodeName); var tNode = this.getDoc().createTextNode(nodeValue); if (aNode) try { aNode.replaceChild(tNode,aNode.firstChild); } catch (e) { } else { try { aNode = this.getDoc().createElementNS(this.getNode().namespaceURI, nodeName); } catch (ex) { aNode = this.getDoc().createElement(nodeName) } this.getNode().appendChild(aNode); aNode.appendChild(tNode); } return aNode; }; /** * Builds a node using {@link * http://wiki.script.aculo.us/scriptaculous/show/Builder * script.aculo.us' Dom Builder} notation. * This code is taken from {@link * http://wiki.script.aculo.us/scriptaculous/show/Builder * script.aculo.us' Dom Builder} and has been modified to suit our * needs.
    * The original parts of the code do have the following copyright * and license notice:
    * Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, * http://mir.acu lo.us)
    * script.aculo.us is freely distributable under the terms of an * MIT-style licen se. // For details, see the script.aculo.us web * site: http://script.aculo.us/
    * @author Thomas Fuchs * @author Stefan Strigler * @return The newly created node * @type {@link http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247 Node} */ JSJaCPacket.prototype.buildNode = function(elementName) { return JSJaCBuilder.buildNode(this.getDoc(), elementName, arguments[1], arguments[2]); }; /** * Appends node created by buildNode to this packets parent node. * @param {@link http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247 Node} element The node to append or * @param {String} element A name plus an object hash with attributes (optional) plus an array of childnodes (optional) * @see #buildNode * @return This packet * @type JSJaCPacket */ JSJaCPacket.prototype.appendNode = function(element) { if (typeof element=='object') { // seems to be a prebuilt node return this.getNode().appendChild(element) } else { // build node return this.getNode().appendChild(this.buildNode(element, arguments[1], arguments[2], null, this.getNode().namespaceURI)); } }; /** * A jabber/XMPP presence packet * @class Models the XMPP notion of a 'presence' packet * @extends JSJaCPacket */ function JSJaCPresence() { /** * @ignore */ this.base = JSJaCPacket; this.base('presence'); } JSJaCPresence.prototype = new JSJaCPacket; /** * Sets the status message for current status. Usually this is set * to some human readable string indicating what the user is * doing/feel like currently. * @param {String} status A status message * @return this * @type JSJaCPacket */ JSJaCPresence.prototype.setStatus = function(status) { this._setChildNode("status", status); return this; }; /** * Sets the online status for this presence packet. * @param {String} show An XMPP complient status indicator. Must * be one of 'chat', 'away', 'xa', 'dnd' * @return this * @type JSJaCPacket */ JSJaCPresence.prototype.setShow = function(show) { if (show == 'chat' || show == 'away' || show == 'xa' || show == 'dnd') this._setChildNode("show",show); return this; }; /** * Sets the priority of the resource bind to with this connection * @param {int} prio The priority to set this resource to * @return this * @type JSJaCPacket */ JSJaCPresence.prototype.setPriority = function(prio) { this._setChildNode("priority", prio); return this; }; /** * Some combined method that allowes for setting show, status and * priority at once * @param {String} show A status message * @param {String} status A status indicator as defined by XMPP * @param {int} prio A priority for this resource * @return this * @type JSJaCPacket */ JSJaCPresence.prototype.setPresence = function(show,status,prio) { if (show) this.setShow(show); if (status) this.setStatus(status); if (prio) this.setPriority(prio); return this; }; /** * Gets the status message of this presence * @return The (human readable) status message * @type String */ JSJaCPresence.prototype.getStatus = function() { return this.getChildVal('status'); }; /** * Gets the status of this presence. * Either one of 'chat', 'away', 'xa' or 'dnd' or null. * @return The status indicator as defined by XMPP * @type String */ JSJaCPresence.prototype.getShow = function() { return this.getChildVal('show'); }; /** * Gets the priority of this status message * @return A resource priority * @type int */ JSJaCPresence.prototype.getPriority = function() { return this.getChildVal('priority'); }; /** * A jabber/XMPP iq packet * @class Models the XMPP notion of an 'iq' packet * @extends JSJaCPacket */ function JSJaCIQ() { /** * @ignore */ this.base = JSJaCPacket; this.base('iq'); } JSJaCIQ.prototype = new JSJaCPacket; /** * Some combined method to set 'to', 'type' and 'id' at once * @param {String} to the recepients JID * @param {String} type A XMPP compliant iq type (one of 'set', 'get', 'result' and 'error' * @param {String} id A packet ID * @return this * @type JSJaCIQ */ JSJaCIQ.prototype.setIQ = function(to,type,id) { if (to) this.setTo(to); if (type) this.setType(type); if (id) this.setID(id); return this; }; /** * Creates a 'query' child node with given XMLNS * @param {String} xmlns The namespace for the 'query' node * @return The query node * @type {@link http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247 Node} */ JSJaCIQ.prototype.setQuery = function(xmlns) { var query; try { query = this.getDoc().createElementNS(xmlns,'query'); } catch (e) { query = this.getDoc().createElement('query'); query.setAttribute('xmlns',xmlns); } this.getNode().appendChild(query); return query; }; /** * Gets the 'query' node of this packet * @return The query node * @type {@link http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247 Node} */ JSJaCIQ.prototype.getQuery = function() { return this.getNode().getElementsByTagName('query').item(0); }; /** * Gets the XMLNS of the query node contained within this packet * @return The namespace of the query node * @type String */ JSJaCIQ.prototype.getQueryXMLNS = function() { if (this.getQuery()) { return this.getQuery().namespaceURI || this.getQuery().getAttribute('xmlns'); } else { return null; } }; /** * Creates an IQ reply with type set to 'result'. If given appends payload to first child if IQ. Payload maybe XML as string or a DOM element (or an array of such elements as well). * @param {Element} payload A payload to be appended [optional] * @return An IQ reply packet * @type JSJaCIQ */ JSJaCIQ.prototype.reply = function(payload) { var rIQ = this.clone(); rIQ.setTo(this.getFrom()); rIQ.setFrom(); rIQ.setType('result'); if (payload) { if (typeof payload == 'string') rIQ.getChild().appendChild(rIQ.getDoc().loadXML(payload)); else if (payload.constructor == Array) { var node = rIQ.getChild(); for (var i=0; inull is being returned. * @type JSJaCPacket */ JSJaCPacket.wrapNode = function(node) { var oPacket = null; switch (node.nodeName.toLowerCase()) { case 'presence': oPacket = new JSJaCPresence(); break; case 'message': oPacket = new JSJaCMessage(); break; case 'iq': oPacket = new JSJaCIQ(); break; } if (oPacket) { oPacket.getDoc().replaceChild(oPacket._importNode(node, true), oPacket.getNode()); } return oPacket; }; jsjac-1.3.4+dfsg/src/Makefile000066400000000000000000000001061153725753300157670ustar00rootroot00000000000000 all: @cd .. && make && cd src pack: @cd .. && make pack && cd src jsjac-1.3.4+dfsg/src/crypt.js000066400000000000000000000510121153725753300160300ustar00rootroot00000000000000/* Copyright (c) 1998 - 2007, Paul Johnston & Contributors * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following * disclaimer. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the author nor the names of its contributors * may be used to endorse or promote products derived from this * software without specific prior written permission. * * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * */ /** * @fileoverview Collection of MD5 and SHA1 hashing and encoding * methods. * @author Stefan Strigler steve@zeank.in-berlin.de * @version $Revision$ */ /* * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined * in FIPS PUB 180-1 * Version 2.1a Copyright Paul Johnston 2000 - 2002. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet * Distributed under the BSD License * See http://pajhome.org.uk/crypt/md5 for details. */ /* * Configurable variables. You may need to tweak these to be compatible with * the server-side, but the defaults work in most cases. */ var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */ var b64pad = "="; /* base-64 pad character. "=" for strict RFC compliance */ var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */ /* * These are the functions you'll usually want to call * They take string arguments and return either hex or base-64 encoded strings */ function hex_sha1(s){return binb2hex(core_sha1(str2binb(s),s.length * chrsz));} function b64_sha1(s){return binb2b64(core_sha1(str2binb(s),s.length * chrsz));} function str_sha1(s){return binb2str(core_sha1(str2binb(s),s.length * chrsz));} function hex_hmac_sha1(key, data){ return binb2hex(core_hmac_sha1(key, data));} function b64_hmac_sha1(key, data){ return binb2b64(core_hmac_sha1(key, data));} function str_hmac_sha1(key, data){ return binb2str(core_hmac_sha1(key, data));} /* * Perform a simple self-test to see if the VM is working */ function sha1_vm_test() { return hex_sha1("abc") == "a9993e364706816aba3e25717850c26c9cd0d89d"; } /* * Calculate the SHA-1 of an array of big-endian words, and a bit length */ function core_sha1(x, len) { /* append padding */ x[len >> 5] |= 0x80 << (24 - len % 32); x[((len + 64 >> 9) << 4) + 15] = len; var w = Array(80); var a = 1732584193; var b = -271733879; var c = -1732584194; var d = 271733878; var e = -1009589776; for(var i = 0; i < x.length; i += 16) { var olda = a; var oldb = b; var oldc = c; var oldd = d; var olde = e; for(var j = 0; j < 80; j++) { if(j < 16) w[j] = x[i + j]; else w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1); var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)), safe_add(safe_add(e, w[j]), sha1_kt(j))); e = d; d = c; c = rol(b, 30); b = a; a = t; } a = safe_add(a, olda); b = safe_add(b, oldb); c = safe_add(c, oldc); d = safe_add(d, oldd); e = safe_add(e, olde); } return Array(a, b, c, d, e); } /* * Perform the appropriate triplet combination function for the current * iteration */ function sha1_ft(t, b, c, d) { if(t < 20) return (b & c) | ((~b) & d); if(t < 40) return b ^ c ^ d; if(t < 60) return (b & c) | (b & d) | (c & d); return b ^ c ^ d; } /* * Determine the appropriate additive constant for the current iteration */ function sha1_kt(t) { return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 : (t < 60) ? -1894007588 : -899497514; } /* * Calculate the HMAC-SHA1 of a key and some data */ function core_hmac_sha1(key, data) { var bkey = str2binb(key); if(bkey.length > 16) bkey = core_sha1(bkey, key.length * chrsz); var ipad = Array(16), opad = Array(16); for(var i = 0; i < 16; i++) { ipad[i] = bkey[i] ^ 0x36363636; opad[i] = bkey[i] ^ 0x5C5C5C5C; } var hash = core_sha1(ipad.concat(str2binb(data)), 512 + data.length * chrsz); return core_sha1(opad.concat(hash), 512 + 160); } /* * Bitwise rotate a 32-bit number to the left. */ function rol(num, cnt) { return (num << cnt) | (num >>> (32 - cnt)); } /* * Convert an 8-bit or 16-bit string to an array of big-endian words * In 8-bit function, characters >255 have their hi-byte silently ignored. */ function str2binb(str) { var bin = Array(); var mask = (1 << chrsz) - 1; for(var i = 0; i < str.length * chrsz; i += chrsz) bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (32 - chrsz - i%32); return bin; } /* * Convert an array of big-endian words to a string */ function binb2str(bin) { var str = ""; var mask = (1 << chrsz) - 1; for(var i = 0; i < bin.length * 32; i += chrsz) str += String.fromCharCode((bin[i>>5] >>> (32 - chrsz - i%32)) & mask); return str; } /* * Convert an array of big-endian words to a hex string. */ function binb2hex(binarray) { var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; var str = ""; for(var i = 0; i < binarray.length * 4; i++) { str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) + hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8 )) & 0xF); } return str; } /* * Convert an array of big-endian words to a base-64 string */ function binb2b64(binarray) { var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; var str = ""; for(var i = 0; i < binarray.length * 4; i += 3) { var triplet = (((binarray[i >> 2] >> 8 * (3 - i %4)) & 0xFF) << 16) | (((binarray[i+1 >> 2] >> 8 * (3 - (i+1)%4)) & 0xFF) << 8 ) | ((binarray[i+2 >> 2] >> 8 * (3 - (i+2)%4)) & 0xFF); for(var j = 0; j < 4; j++) { if(i * 8 + j * 6 > binarray.length * 32) str += b64pad; else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F); } } return str.replace(/AAA\=(\=*?)$/,'$1'); // cleans garbage chars at end of string } /* * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message * Digest Algorithm, as defined in RFC 1321. * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet * Distributed under the BSD License * See http://pajhome.org.uk/crypt/md5 for more info. */ /* * Configurable variables. You may need to tweak these to be compatible with * the server-side, but the defaults work in most cases. */ // var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */ // var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */ // var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */ /* * These are the functions you'll usually want to call * They take string arguments and return either hex or base-64 encoded strings */ function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));} function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));} function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));} function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); } function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); } function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); } /* * Perform a simple self-test to see if the VM is working */ function md5_vm_test() { return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72"; } /* * Calculate the MD5 of an array of little-endian words, and a bit length */ function core_md5(x, len) { /* append padding */ x[len >> 5] |= 0x80 << ((len) % 32); x[(((len + 64) >>> 9) << 4) + 14] = len; var a = 1732584193; var b = -271733879; var c = -1732584194; var d = 271733878; for(var i = 0; i < x.length; i += 16) { var olda = a; var oldb = b; var oldc = c; var oldd = d; a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936); d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586); c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819); b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330); a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897); d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426); c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341); b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983); a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416); d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417); c = md5_ff(c, d, a, b, x[i+10], 17, -42063); b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162); a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682); d = md5_ff(d, a, b, c, x[i+13], 12, -40341101); c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290); b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329); a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510); d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632); c = md5_gg(c, d, a, b, x[i+11], 14, 643717713); b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302); a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691); d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083); c = md5_gg(c, d, a, b, x[i+15], 14, -660478335); b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848); a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438); d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690); c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961); b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501); a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467); d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784); c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473); b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734); a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558); d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463); c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562); b = md5_hh(b, c, d, a, x[i+14], 23, -35309556); a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060); d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353); c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632); b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640); a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174); d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222); c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979); b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189); a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487); d = md5_hh(d, a, b, c, x[i+12], 11, -421815835); c = md5_hh(c, d, a, b, x[i+15], 16, 530742520); b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651); a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844); d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415); c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905); b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055); a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571); d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606); c = md5_ii(c, d, a, b, x[i+10], 15, -1051523); b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799); a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359); d = md5_ii(d, a, b, c, x[i+15], 10, -30611744); c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380); b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649); a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070); d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379); c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259); b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551); a = safe_add(a, olda); b = safe_add(b, oldb); c = safe_add(c, oldc); d = safe_add(d, oldd); } return Array(a, b, c, d); } /* * These functions implement the four basic operations the algorithm uses. */ function md5_cmn(q, a, b, x, s, t) { return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b); } function md5_ff(a, b, c, d, x, s, t) { return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t); } function md5_gg(a, b, c, d, x, s, t) { return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t); } function md5_hh(a, b, c, d, x, s, t) { return md5_cmn(b ^ c ^ d, a, b, x, s, t); } function md5_ii(a, b, c, d, x, s, t) { return md5_cmn(c ^ (b | (~d)), a, b, x, s, t); } /* * Calculate the HMAC-MD5, of a key and some data */ function core_hmac_md5(key, data) { var bkey = str2binl(key); if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz); var ipad = Array(16), opad = Array(16); for(var i = 0; i < 16; i++) { ipad[i] = bkey[i] ^ 0x36363636; opad[i] = bkey[i] ^ 0x5C5C5C5C; } var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz); return core_md5(opad.concat(hash), 512 + 128); } /* * Add integers, wrapping at 2^32. This uses 16-bit operations internally * to work around bugs in some JS interpreters. */ function safe_add(x, y) { var lsw = (x & 0xFFFF) + (y & 0xFFFF); var msw = (x >> 16) + (y >> 16) + (lsw >> 16); return (msw << 16) | (lsw & 0xFFFF); } /* * Bitwise rotate a 32-bit number to the left. */ function bit_rol(num, cnt) { return (num << cnt) | (num >>> (32 - cnt)); } /* * Convert a string to an array of little-endian words * If chrsz is ASCII, characters >255 have their hi-byte silently ignored. */ function str2binl(str) { var bin = Array(); var mask = (1 << chrsz) - 1; for(var i = 0; i < str.length * chrsz; i += chrsz) bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32); return bin; } /* * Convert an array of little-endian words to a string */ function binl2str(bin) { var str = ""; var mask = (1 << chrsz) - 1; for(var i = 0; i < bin.length * 32; i += chrsz) str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask); return str; } /* * Convert an array of little-endian words to a hex string. */ function binl2hex(binarray) { var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; var str = ""; for(var i = 0; i < binarray.length * 4; i++) { str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) + hex_tab.charAt((binarray[i>>2] >> ((i%4)*8 )) & 0xF); } return str; } /* * Convert an array of little-endian words to a base-64 string */ function binl2b64(binarray) { var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; var str = ""; for(var i = 0; i < binarray.length * 4; i += 3) { var triplet = (((binarray[i >> 2] >> 8 * ( i %4)) & 0xFF) << 16) | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 ) | ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF); for(var j = 0; j < 4; j++) { if(i * 8 + j * 6 > binarray.length * 32) str += b64pad; else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F); } } return str; } /* ############################################################################# UTF-8 Decoder and Encoder base64 Encoder and Decoder written by Tobias Kieslich, justdreams Contact: tobias@justdreams.de http://www.justdreams.de/ ############################################################################# */ // returns an array of byterepresenting dezimal numbers which represent the // plaintext in an UTF-8 encoded version. Expects a string. // This function includes an exception management for those nasty browsers like // NN401, which returns negative decimal numbers for chars>128. I hate it!! // This handling is unfortunately limited to the user's charset. Anyway, it works // in most of the cases! Special signs with an unicode>256 return numbers, which // can not be converted to the actual unicode and so not to the valid utf-8 // representation. Anyway, this function does always return values which can not // misinterpretd by RC4 or base64 en- or decoding, because every value is >0 and // <255!! // Arrays are faster and easier to handle in b64 encoding or encrypting.... function utf8t2d(t) { t = t.replace(/\r\n/g,"\n"); var d=new Array; var test=String.fromCharCode(237); if (test.charCodeAt(0) < 0) for(var n=0; n0) d[d.length]= c; else { d[d.length]= (((256+c)>>6)|192); d[d.length]= (((256+c)&63)|128);} } else for(var n=0; n 1byte if (c<128) d[d.length]= c; // all the signs between 127 and 2047 => 2byte else if((c>127) && (c<2048)) { d[d.length]= ((c>>6)|192); d[d.length]= ((c&63)|128);} // all the signs between 2048 and 66536 => 3byte else { d[d.length]= ((c>>12)|224); d[d.length]= (((c>>6)&63)|128); d[d.length]= ((c&63)|128);} } return d; } // returns plaintext from an array of bytesrepresenting dezimal numbers, which // represent an UTF-8 encoded text; browser which does not understand unicode // like NN401 will show "?"-signs instead // expects an array of byterepresenting decimals; returns a string function utf8d2t(d) { var r=new Array; var i=0; while(i191) && (d[i]<224)) { r[r.length]= String.fromCharCode(((d[i]&31)<<6) | (d[i+1]&63)); i+=2;} else { r[r.length]= String.fromCharCode(((d[i]&15)<<12) | ((d[i+1]&63)<<6) | (d[i+2]&63)); i+=3;} } return r.join(""); } // included in it creates two arrays which makes base64 // en- and decoding faster // this speed is noticeable especially when coding larger texts (>5k or so) function b64arrays() { var b64s='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; b64 = new Array();f64 =new Array(); for (var i=0; i>2]; r[r.length] = b64[((d[i]&3)<<4) | (d[i+1]>>4)]; r[r.length] = b64[((d[i+1]&15)<<2) | (d[i+2]>>6)]; r[r.length] = b64[d[i+2]&63]; i+=3; } // this is again for the padding if ((dl%3) == 1) r[r.length-1] = r[r.length-2] = "="; if ((dl%3) == 2) r[r.length-1] = "="; // we join the array to return a textstring var t=r.join(""); return t; } // returns array of byterepresenting numbers created of an base64 encoded text // it is still the slowest function in this modul; I hope I can make it faster // expects string; returns an array function b64t2d(t) { var d=new Array; var i=0; // here we fix this CRLF sequenz created by MS-OS; arrrgh!!! t=t.replace(/\n|\r/g,""); t=t.replace(/=/g,""); while (i>4); d[d.length] = (((f64[t.charAt(i+1)]&15)<<4) | (f64[t.charAt(i+2)]>>2)); d[d.length] = (((f64[t.charAt(i+2)]&3)<<6) | (f64[t.charAt(i+3)])); i+=4; } if (t.length%4 == 2) d = d.slice(0, d.length-2); if (t.length%4 == 3) d = d.slice(0, d.length-1); return d; } if (typeof(atob) == 'undefined' || typeof(btoa) == 'undefined') b64arrays(); if (typeof(atob) == 'undefined') { atob = function(s) { return utf8d2t(b64t2d(s)); } } if (typeof(btoa) == 'undefined') { btoa = function(s) { return b64d2t(utf8t2d(s)); } } function cnonce(size) { var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; var cnonce = ''; for (var i=0; i/g,">"); str = str.replace(/\"/g,"""); str = str.replace(/\n/g,"
    "); return str; }; /** * Converts from jabber timestamps to JavaScript Date objects * @addon * @param {String} ts A string representing a jabber datetime timestamp as * defined by {@link http://www.xmpp.org/extensions/xep-0082.html XEP-0082} * @return A javascript Date object corresponding to the jabber DateTime given * @type Date */ Date.jab2date = function(ts) { var date = new Date(Date.UTC(ts.substr(0,4),ts.substr(5,2)-1,ts.substr(8,2),ts.substr(11,2),ts.substr(14,2),ts.substr(17,2))); if (ts.substr(ts.length-6,1) != 'Z') { // there's an offset var offset = new Date(); offset.setTime(0); offset.setUTCHours(ts.substr(ts.length-5,2)); offset.setUTCMinutes(ts.substr(ts.length-2,2)); if (ts.substr(ts.length-6,1) == '+') date.setTime(date.getTime() - offset.getTime()); else if (ts.substr(ts.length-6,1) == '-') date.setTime(date.getTime() + offset.getTime()); } return date; }; /** * Takes a timestamp in the form of 2004-08-13T12:07:04+02:00 as argument * and converts it to some sort of humane readable format * @addon */ Date.hrTime = function(ts) { return Date.jab2date(ts).toLocaleString(); }; /** * somewhat opposit to {@link #hrTime} * expects a javascript Date object as parameter and returns a jabber * date string conforming to * {@link http://www.xmpp.org/extensions/xep-0082.html XEP-0082} * @see #hrTime * @return The corresponding jabber DateTime string * @type String */ Date.prototype.jabberDate = function() { var padZero = function(i) { if (i < 10) return "0" + i; return i; }; var jDate = this.getUTCFullYear() + "-"; jDate += padZero(this.getUTCMonth()+1) + "-"; jDate += padZero(this.getUTCDate()) + "T"; jDate += padZero(this.getUTCHours()) + ":"; jDate += padZero(this.getUTCMinutes()) + ":"; jDate += padZero(this.getUTCSeconds()) + "Z"; return jDate; }; /** * Determines the maximum of two given numbers * @addon * @param {Number} A a number * @param {Number} B another number * @return the maximum of A and B * @type Number */ Number.max = function(A, B) { return (A > B)? A : B; }; Number.min = function(A, B) { return (A < B)? A : B; };jsjac-1.3.4+dfsg/src/xmlextras.js000066400000000000000000000145141153725753300167240ustar00rootroot00000000000000 /* Copyright 2006 Erik Arvidsson * * Licensed under the Apache License, Version 2.0 (the "License"); you * may not use this file except in compliance with the License. You * may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * implied. See the License for the specific language governing * permissions and limitations under the License. */ /** * @fileoverview Wrapper to make working with XmlHttpRequest and the * DOM more convenient (cross browser compliance). * this code is taken from * http://webfx.eae.net/dhtml/xmlextras/xmlextras.html * @author Stefan Strigler steve@zeank.in-berlin.de * @version $Revision$ */ /** * XmlHttp factory * @private */ function XmlHttp() {} /** * creates a cross browser compliant XmlHttpRequest object */ XmlHttp.create = function () { try { if (window.XMLHttpRequest) { var req = new XMLHttpRequest(); // some versions of Moz do not support the readyState property // and the onreadystate event so we patch it! if (req.readyState == null) { req.readyState = 1; req.addEventListener("load", function () { req.readyState = 4; if (typeof req.onreadystatechange == "function") req.onreadystatechange(); }, false); } return req; } if (window.ActiveXObject) { return new ActiveXObject(XmlHttp.getPrefix() + ".XmlHttp"); } } catch (ex) {} // fell through throw new Error("Your browser does not support XmlHttp objects"); }; /** * used to find the Automation server name * @private */ XmlHttp.getPrefix = function() { if (XmlHttp.prefix) // I know what you did last summer return XmlHttp.prefix; var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"]; var o; for (var i = 0; i < prefixes.length; i++) { try { // try to create the objects o = new ActiveXObject(prefixes[i] + ".XmlHttp"); return XmlHttp.prefix = prefixes[i]; } catch (ex) {}; } throw new Error("Could not find an installed XML parser"); }; /** * XmlDocument factory * @private */ function XmlDocument() {} XmlDocument.create = function (name,ns) { name = name || 'foo'; ns = ns || ''; try { var doc; // DOM2 if (document.implementation && document.implementation.createDocument) { doc = document.implementation.createDocument(ns, name, null); // some versions of Moz do not support the readyState property // and the onreadystate event so we patch it! if (doc.readyState == null) { doc.readyState = 1; doc.addEventListener("load", function () { doc.readyState = 4; if (typeof doc.onreadystatechange == "function") doc.onreadystatechange(); }, false); } } else if (window.ActiveXObject) { doc = new ActiveXObject(XmlDocument.getPrefix() + ".DomDocument"); } if (!doc.documentElement || doc.documentElement.tagName != name || (doc.documentElement.namespaceURI && doc.documentElement.namespaceURI != ns)) { try { if (ns != '') doc.appendChild(doc.createElement(name)). setAttribute('xmlns',ns); else doc.appendChild(doc.createElement(name)); } catch (dex) { doc = document.implementation.createDocument(ns,name,null); if (doc.documentElement == null) doc.appendChild(doc.createElement(name)); // fix buggy opera 8.5x if (ns != '' && doc.documentElement.getAttribute('xmlns') != ns) { doc.documentElement.setAttribute('xmlns',ns); } } } return doc; } catch (ex) { } throw new Error("Your browser does not support XmlDocument objects"); }; /** * used to find the Automation server name * @private */ XmlDocument.getPrefix = function() { if (XmlDocument.prefix) return XmlDocument.prefix; var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"]; var o; for (var i = 0; i < prefixes.length; i++) { try { // try to create the objects o = new ActiveXObject(prefixes[i] + ".DomDocument"); return XmlDocument.prefix = prefixes[i]; } catch (ex) {}; } throw new Error("Could not find an installed XML parser"); }; // Create the loadXML method if (typeof(Document) != 'undefined' && window.DOMParser) { /** * XMLDocument did not extend the Document interface in some * versions of Mozilla. * @private */ Document.prototype.loadXML = function (s) { // parse the string to a new doc var doc2 = (new DOMParser()).parseFromString(s, "text/xml"); // remove all initial children while (this.hasChildNodes()) this.removeChild(this.lastChild); // insert and import nodes for (var i = 0; i < doc2.childNodes.length; i++) { this.appendChild(this.importNode(doc2.childNodes[i], true)); } }; } // Create xml getter for Mozilla if (window.XMLSerializer && window.Node && Node.prototype && Node.prototype.__defineGetter__) { /** * xml getter * * This serializes the DOM tree to an XML String * * Usage: var sXml = oNode.xml * @deprecated * @private */ // XMLDocument did not extend the Document interface in some versions // of Mozilla. Extend both! XMLDocument.prototype.__defineGetter__("xml", function () { return (new XMLSerializer()).serializeToString(this); }); /** * xml getter * * This serializes the DOM tree to an XML String * * Usage: var sXml = oNode.xml * @deprecated * @private */ Document.prototype.__defineGetter__("xml", function () { return (new XMLSerializer()).serializeToString(this); }); /** * xml getter * * This serializes the DOM tree to an XML String * * Usage: var sXml = oNode.xml * @deprecated * @private */ Node.prototype.__defineGetter__("xml", function () { return (new XMLSerializer()).serializeToString(this); }); } jsjac-1.3.4+dfsg/utils/000077500000000000000000000000001153725753300147035ustar00rootroot00000000000000jsjac-1.3.4+dfsg/utils/JSDoc/000077500000000000000000000000001153725753300156455ustar00rootroot00000000000000jsjac-1.3.4+dfsg/utils/JSDoc/.jsdoc_config000066400000000000000000000024751153725753300203050ustar00rootroot00000000000000# # Configuration file for JSDoc # # The following hashes are used for supplying user-defined @attribute tags # that will be parsed. Non-standard attributes (such as @subclass) can be # added into these hashes, along with a code reference. The return value # from the code reference will be included in the documentation. All # non-standard tags that are not in the below hashes will be ignored. # The code reference will receive a reference to an array of # values that were supplied with the @... tag # # Class attributes #eval { # $CLASS_ATTRS_MAP{subclass} = # # subclass is the name of the @... tag # sub { # # Body from which a string is returned # '
    Subclasses:
    -' . # join('
    -', # map ({"$_"} # map ( { s/\s*(\w+)\s*/$1/; $_} @{@_->[0]}) # ) # ) . '

    ' # }; # # $CLASS_ATTRS_MAP{with} = # sub { # 'This class has a \'@with\' attribute' # }; #}; # Method attributes # eval { # # Uncomment this to allow the filename to be displayed for # each function # # $METHOD_ATTRS_MAP{filename} = # sub { # '

    Filename: ' . $_[0] . '

    ' # }; # $CLASS_ATTRS_MAP{filename} = $METHOD_ATTRS_MAP{filename}; # # }; # jsjac-1.3.4+dfsg/utils/JSDoc/CHANGES000066400000000000000000000401271153725753300166440ustar00rootroot00000000000000JSDoc 1.10.2 ============ - Fixed broken links to non-existant classes JSDoc 1.10.1 ============ - Added support for @singleton tag, as supplied by Jeffrey To - Fixes to constants templates as supplied by Jeffrey To JSDoc 1.10 ========== - Added nested directory structure, as requested by Nitobi - Added @implements tag, as requested by Nitobi JSDoc 1.9.9.2 ============= - Fixed disappearing argument list for package-style class constructors JSDoc 1.9.9.1 ============= - Fixed bug in template dir designation that caused JSDoc to crash if run from an absolute path JSDoc 1.9.9 =========== - Added a commandline parameter for supplying a template directory - Adding sorting of class names on overview-summary-$filename.js (sf.net bug #1416564) - Fix for broken anchors from the overview-summary-$filename page to static methods (SF.net bug #1416543) JSDoc 1.9.8.1 ============= - Don't touch the file source (src) when processing the file overview data - Pick up functions as constructors of the @class tag is used JSDoc 1.9.8 =========== - Allow the @base tag to accept the form: @base ClassName URL (RFE 1114510) - Be more lenient with @param and @return types (RFE 1104728) - Corrected CSS error, changed "pts" to "pt" JSDoc 1.9.7 =========== - Added "--no-lexical-privates" option to ignore locally-defined values from within constructors - Fixed linking to static fields/methods JSDoc 1.9.6.2 ============= - Set correct permissions on files in packaging script - Fixed compile error on some versions of perl - Create distinct anchors for static methods and fields in HTML so that if there is a static and instance method of the same name, the links work correctly JSDoc 1.9.6.1 ============= - Updated unit tests for clearing of function contents - Removed collapsing of string literals; this was originally added for version 1.9.5.1 to avoid segfaults, but the decision has been made that it is up to the user to use a version of perl that doesn't segfault instead of trying to work around it in perl code. - Added (experimental) @exec tag for initialization blocks that should be 'run' JSDoc 1.9.6 =========== - Fix for incorrect return type and parameter types for static method listing in file overview - Clear out unused nested functions with the preprocessor to avoid problems JSDoc 1.9.5.8 ============= - Yet another fix for __defineGetter__ and __defineSetter__ JSDoc 1.9.5.7 ============= - Fixed bug in syntax highlighting for single-line inline comments - Fixed bug in preprocessing of __defineGetter__ and __defineSetter__ JSDoc 1.9.5.6 ============= - Fixed incorrect listing of private classes when --private not enabled JSDoc 1.9.5.4 ============= - Corrected bug with function assignment inside constructor JSDoc 1.9.5.3 ============= - Added ability to specify different file extensions on commandline JSDoc 1.9.5.2 ============= - Fixed formatted text munging for @class description - Added support for @package tag to be used with XMI export JSDoc 1.9.5.1 ============= - Added collapsing of string literals during preprocessing JSDoc 1.9.5 =========== - Added listing of global (static) methods to file overview summary, code submitted by Jeremy Gillick - Allow a global variable to be defined as a class from an anonymous function declaration JSDoc 1.9.4.2.1 =============== - Further fix for typed parameter names starting with a dollar sign JSDoc 1.9.4.2 ============= - Added ability to handle parameter names starting with a dollar sign JSDoc 1.9.4.1 ============= - Only use the first sentence for file and class summary on the overview pages - Add a non-breaking space in the overview summary tables when there is no appropriate value to display JSDoc 1.9.4 =========== - If there are multiple source files documented, the index page defaults to the overview summary for the main frame - Made JSDoc site link open in parent frame - Added overview and file summary tables (similar to package overview table in JavaDoc) JSDoc 1.9.3.1 ============= - Fixed duplicate class-tree output JSDoc 1.9.3 =========== - Added alpha release of XML and XMI output formats - Upgrade a function to a class if the @base tag is used - Fixed issue with sub-package nested classes requiring the @addon tag - Added the implicit "Object" class to the inheritance tree, as well as other classes that are referenced but not defined JSDoc 1.9.2.1 ============= - Added @addon tag, which is used when adding static methods to core classes or classes not defined within the files being documented - Fix for the base class of nested classes not being properly set - Fix for infinite recursion when all classes are private JSDoc 1.9.2 =========== - Removed unecessary table from overview-summary.tmpl - Added the @ignore tag to allow total hiding of functions - Fix for incorrect marking of methods as void when the return value is enclosed in parentheses - Fix so that methods with a @return tag but without a return statement are not marked as void - Fixed issue with not all files being listed in the file listing JSDoc 1.9.1.3 ============= - Fixed issue with backslashes in path - Fixed issue with

     tags and JavaScript code within fileoverview sections
    
    - Made documented versions of a method take precedence over a 
      non-documented version
    
    - Added support for prototype assignment without parentheses
    
    - Added new @return label {type typeLink} Description... syntax
    
    JSDoc 1.9.1.2
    =============
    
    - Further improvements to mark_void_method
    
    - Improved handling of dynamically-bound methods within functions
    
    - Improved handling of erroneous documenting of 'this'
    
    - Fixed quoting on error message
    
    - Added a few new unit tests for testing general behaviour
    
    JSDoc 1.9.1.1
    =============
    
    - Fix for embarrassing bug in mark_void_method
    
    JSDoc 1.9.1
    ===========
    
    - Fix for the incorrect void marking of methods that return a string literal
    
    - Fix to stop dynamic prototyping from adding non-dynamic classes
    
    - Added ability to add a link to parameter-type data, as follows:
        @param {TypeName http://my.link.com/} myParam Description of parameter
    
    JSDoc 1.9
    =========
    
    - Added support for a Constant Values page like in Javadoc
    
    - Added support for private classes (by marking the constructor with
      the @private attribute)
    
    - Added a "File" page with links to it in the navbar. The "File" page includes
      the file overview if one has been supplied, as well as the source view
      (unless jsdoc has been invoked with the --no-sources flag)
    
    - Added a --no-sources commandline option to not show the sourcecode for
      the JavaScript files 
    
    - Added --package-naming commandline option, which specifies that the path 
      leading to each source file will be preserved. This allows for the same 
      filename to be used in different directories. Using the same class name
      in different packages is _not_ supported (yet)
    
    - Added JSDoc link and creation time in the footer of each page
    
    - Added support for @member tag to explicitly mark a method as a member of
      a class
    
    JSDoc 1.8.4
    ===========
    
    - Added step in prepocessing to attempt to add missing @constructor tags where
      the 'new' operator is used in combination with a function name elsewhere
      in the source.
    
    - Only the first @extends marking (or assignment of an instance to a sub-
      class's prototype) will be used in determining the base class of a class.
    
    - Updated test.js to show off more features of JSDoc, as well as a general 
      clean-up.
        
    - Changed the parser to consider a method to be a class declaration if its
      documentation contains a @class tag (in addition to the @constructor tag)
    
    JSDoc 1.8.3.1
    =============
    
    - Some general code cleanup and refactoring. 
    
    - Properly fixed marking of void/non-void methods, and at the same time
      re-introduced recursive regexes (this time non-dynamic, as dynamic seem
      to be much too unstable)
    
    JSDoc 1.8.3
    ===========
    
    - Changed the handling for __defineGetter__ and __defineSetter__
      to define a property instead of a method in the documentation
    
    - Fixed bug in parse_jsdoc_comment that didn't allow for email addresses
      to be entered verbatim (instead, the domain of the address was parsed
      as a tag)
    
    - Re-did the @fileoverview parsing, now other tags and inner {@link...} 
      tags are included. Additionally, if only one file is processed and there
      is no project overview file included, the file's overview (if it exists)
      is used as the project overview. Thanks to Robert Flaherty for input
      and bug reports on this issue.
    
    JSDoc 1.8.2.1
    =============
    
    - Got rid of extra '*' with @fileoverview
    
    JSDoc 1.8.2
    =============
    
    - Fixed bug where other @tags were included as part of the @fileoverview
    
    - Added support for @version in method documentation
    
    - Partial fix for incorrect marking of void methods
    
    - Made field and return @type handling more robust and flexible
    
    JSDoc 1.8.1
    ===========
    
    - Added @extends as a synonym for @base
    
    - Fixed doubled-up 
      tags in hierarchy tree code (thanks to Robert Flaherty) - Fixed bug where a class's base class would not get recorded if there was a forward assignment of a static value to the class (thanks to Robert Flaherty) JSDoc 1.8 ========= - Remove the GLOBALS class if it is empty - Fixed case-sensitive sort in index - Added support for comments with long blocks of '*'s in the opening and closing of the doc string - Added sourcecode view - Fixed bug where named anonymous functions were not recognized as methods when assigned to prototypes - Allow for singletons to be declared with var - Allow for binding static properties to classes before they are defined - Added @overviewfile attribute for class documentation, inlines html or textfiles into the documentation - Added beginnings of unit testing - Don't add 'constructor' as an instance or class property - Added an @overviewfile tag which can be put in an independent jsdoc-comment block at the top of each file. This results in a project overview page for each file with an overview, similar to JavaDoc's package pages. - Added support for Mozilla's __defineGetter__ and __defineSetter__ - Return type for methods is now Object, and is displayed instead of the 'function' declaration. The 'void' type is shown if no return can be found in the function and no other type is defined. The defaulting to Object also goes for fields, and is shown instead of the 'var' declaration - Allow usage of the {@link url label} construct for the @type tag JSDoc 1.7.2.1 ============= - Fixed segfault problem in huge constructors with deconstruct_constructor selection regex JSDoc 1.7.2 =========== - Added a @class tag to constructors, for providing class-specific information - Added handling for Singleton classes - Added handler for @base tag to denote inheritance JSDoc 1.7.1.4 ============= - Fixed bug introduced by refactoring of &format_link JSDoc 1.7.1.3 ============= - Added workaround in &format_link for apparent bug in some builds of perl 5.8.0 - Fixed bug in handling of --recursive (was always recursive) JSDoc 1.7.1.2 ============= - Fixed problems with new preprocessor when confronted with nested classes JSDoc 1.7.1.1 ============= - Fixed bug where {@link}s inside of @params weren't processed JSDoc 1.7.1 =========== - Added --quiet switch and message to signify ending of successful execution - Fixed problem with perl segfaulting on big class prototype block definitions - Fixed incorrectly formatted {@link}s nested in other @attributes - Added preprocessor for handling private methods to replace bulky and buggy evaluate_constructor method JSDoc 1.7 ========= - Added usage of strict and warnings in JSDoc.pm - Added ability to set type information for method parameters (e.g. /** @param {String} userName The name of the current user */ ) - Added support for class prototype initialization blocks (finally!) JSDoc 1.6.3.1 ============= - Fixed bug where static fields initialized to 0 are not picked up JSDoc 1.6.3 =========== - Removed the constraint that a nested class constructor must be marked with the @constructor attribute - Allow @constructor attribute to mark nested class constructors which would otherwise be considered static methods - Allow newlines as well as semi-colon for line-endings - Allow a leading '$' for field names JSDoc 1.6.2.1 ============= - Fixed splicing error for nested classes, thanks again to jdber JSDoc 1.6.2 =========== - Carry over overridden method description attributes even if there is no text description to carry over - Improved HTML in main.tmpl - Fixed infinite loop and recognition for when static inner class construct is used (thanks to jdber for the patch) - Added a Nested Class Summary section to the output documentation to display inner classes JSDoc 1.6.1.1 ============= - Fixed bug in carrying over description of overridden methods JSDoc 1.6.1 =========== - Improved the format_link function in jsdoc.pl so that {@links} will not be made to non-existent resources, and parentheses are not placed after a field name (as opposed to a method name) - Carry over method documentation for overridden methods if no new documentation has been supplied for the method. This is in following with javadoc functionality - Fixed /* functionality(whatever) bug - Fixed remaining problems with comments inside of parameter lists JSDoc 1.6 ========= - Big cleanup in jsdoc.pl in terms of writing templates to file - Fixed bug where multi-line @params don't work - Added filename-scoped frame, as well as the name of the filename for each class - Improved the linking implementation for @link and @see to do a better job in terms of not building broken links JSDoc 1.5.2 =========== - Changed the name '[default context]' for non-class functions to be GLOBALS, also made this name configurable with command-line parameters - Made jsdoc easily runnable from anywhere on the filesystem, without requiring installing JSDoc.pm in the @INC JSDoc 1.5.1 =========== - Added support for @requires in methods - Generic '@' attributes now work for constructors, such as @see and @throws. Also added support for @return and @returns for constructors - Fixed the @link construct to allow custom labels - Added standard support for @author in methods as well as classes (Thanks for Rainer Eschen for bringing me to my senses) - Fixed spacing for @author attributes JSDoc 1.5 =========== - Fixed bug that would break HTML links within documentation - Fixed bug in path to logo in IMG tags - Added support for type information for both methods and fields - Added suppport for @private in instance fields - Fixed bug where private methods would show up in the inherited methods list in subclasses - Private class methods are now also supported - Method parameters details are displayed in the same order as the parameter list for a method - Moved more info into the 'vars' member of methods, and away from the parser - Added @final (with synonym @const) for class and instance properties - Fix in parser where string literals bound to classes in a constructor were not caught by the parser JSDoc 1.4 ========= - Added @attributes: @author, @deprecated, @see, @version, @requires, @throws - Updated pod (removed documentation for non-existant parse_jsdoc_source, added a small example) - Added function to reset the parser (reset_parser) - Fixed bug where the same property could be bound to a class's prototype more than once - Fixed bug where embedded // comments would break the parser - Added ability to set project name, page footer, logo and project summary (thanks to Jeff Conrad for code and suggestions) - Added overview summary (thanks to Jeff Conrad for code) - Split up loading/parsing of sources file to prevent crashes that were caused by overloading the regex engine - Added overview-tree (thanks to Jeff Conrad for the code contribution) - Fixed bug where some assignments of methods to instances in a constructor would get lost - Fix in doc-parsing where a line with only a star and a newline would get passed over - Added ability to 'hide' methods with @private JSDoc 1.3 ========= - When a function is marked with @constructor, it will always be dealt with as a class - Improved doc regex - Added recursive directory handling jsjac-1.3.4+dfsg/utils/JSDoc/COPYING000066400000000000000000000431271153725753300167070ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. jsjac-1.3.4+dfsg/utils/JSDoc/JSDoc.pm000066400000000000000000000774221153725753300171610ustar00rootroot00000000000000package JSDoc; =head1 NAME JSDoc - parse JavaScript source file for JSDoc comments =head1 SYNOPSIS Create JavaScript sourcefiles commented in a manner similar to javadoc (ie. with documentation starting with '/**' and then pass a list of references to JavaScript source to parse_code_tree: /** * This is a class for example purposes * @param name Name for the new object * @constructor */ function MyClass(name){ this.name = name; } $code_tree = parse_code_tree(@src_refs); A tree structure describing the code layout, inheritance and documentation is returned To clear the cache of classes and functions in the parser: reset_parser(); =head1 DESCRIPTION The C function requires a ref to a string holding the souce code of a javascript object file or files. It returns a data structure that describes the object hierarchy contained in the source file, as well as included documentation for all fields and methods. The resulting data structure has the following form (for each class): Class | +- classname | +- constructor_args | +- extends | +- constructor_detail | +- constructor_vars | +- class_methods | | | +- description | | | +- mapped_name | | | +- argument_list | | | +- vars | +- instance_methods | | | +- description | | | +- mapped_name | | | +- argument_list | | | +- vars | +- class_fields | | | +- field_description | | | +- field_name | | | +- field_value | | | +- field_vars | +- instance_fields | | | +- field_description | | | +- field_name | | | +- field_value | | | +- field_vars | +- inner_classes | | | +- class_name | +- inherits | +- Class | +- instance_fields | +- instance_methods There is also an additional entry under the key __FILES__ that contains keyed entries for each @tag that was defined in the first JSDoc comment block with a @fileoverview tag. Each entry under __FILES__ is keyed by filename, and is a hash reference. =head1 AUTHORS Gabriel Reid gab_reid@users.sourceforge.net, Michael Mathews michael@mathews.net =cut require 5.000; use strict; use warnings; use Exporter; # Recursion limit for recursive regexes use constant RECURSION => 10; use vars qw/ @ISA @EXPORT /; @ISA = qw(Exporter); @EXPORT = qw(parse_code_tree configure_parser reset_parser); # State use vars qw/ %CLASSES %FUNCTIONS %CONFIG $CTX_FILE /; # Regexes use vars qw/ $BAL_PAREN $BAL_BRACE $BAL_SQUAR $SQUOTE $DQUOTE $NONQUOTE $FUNC_DEF $RET_FUNC_DEF $ANON_FUNCTION $LITERAL $FUNC_CALL $JSDOC_COMMENT $MLINE_COMMENT $SLINE_COMMENT /; # This limits nested braces to 30 levels, but is much more # stable than using a dynamic regex $BAL_BRACE = qr/\{(?:[^\{\}])*\}/; $BAL_PAREN = qr/\((?:[^()])*\)/; $BAL_SQUAR = qr/\[(?:[^[\]])*\]/; for (1..RECURSION){ $BAL_BRACE = qr/\{(?:[^\{\}]|$BAL_BRACE)*\}/; $BAL_PAREN = qr/\((?:[^()]|$BAL_PAREN)*\)/; $BAL_SQUAR = qr/\[(?:[^[\]]|$BAL_SQUAR)*\]/; } $SQUOTE = qr{'[^'\\]*(?:\\.[^'\\]*)*'}; $DQUOTE = qr{"[^"\\]*(?:\\.[^"\\]*)*"}; $NONQUOTE = qr{[^"'/]}; $FUNC_DEF = qr/function\s+\w+(?:\.\w+)*\s*$BAL_PAREN\s*$BAL_BRACE/; $RET_FUNC_DEF = qr/function\s+(\w+(?:\.\w+)*)\s*($BAL_PAREN)\s*($BAL_BRACE)/; $ANON_FUNCTION = qr/function\s*$BAL_PAREN\s*$BAL_BRACE/; $LITERAL = qr/$DQUOTE|$SQUOTE|\d+/; $FUNC_CALL = qr/(?:new\s+)?\w+(?:\.\w+)*\s*$BAL_PAREN/; $JSDOC_COMMENT = qr{/\*\*[^*]*\*+(?:[^/*][^*]*\*+)*/}; $MLINE_COMMENT = qr{/\*[^*]*\*+(?:[^/*][^*]*\*+)*/}; $SLINE_COMMENT = qr{//[^\n]*}; # # Public function that returns a datastructure representing the JS classes # and their documentation # sub parse_code_tree { &initialize_parser; # # This (I mean the "<<$_>>") is pretty hacky, but I've made it this # way to maintain backwards compatibility with anyone who's automatically # expecting this to work when they throw an array of refs to it. If you're # using this for your own work, please don't expect to be able to # put the context file in like this in the future # for my $js_src (map { ref and ${$_} or "<<$_>>" } @_){ if ($js_src =~ /^<<(.+)>>$/){ $CTX_FILE = $1; next; } # perlify os line-endings $js_src =~ s/(\r\n|\r)/\n/g; &parse_file_info($js_src); $js_src = &preprocess_source($js_src); &fetch_funcs_and_classes($js_src); } &map_all_properties(); &build_class_hierarchy(); &set_class_constructors(); &filter_globals; while (my ($classname, $class) = each %CLASSES){ delete $class->{_class_properties}; delete $class->{_instance_properties}; $class->{classname} = $classname unless $classname eq '__FILES__'; } return \%CLASSES; } # # Parses up a a jsdoc comment into its component parts # PARAM: The document string to be parsed # sub parse_jsdoc_comment { my ($doc, $raw) = @_; # Remove excess '*' characters $doc =~ s/^[*\s]*([^*].*?)[*\s]*$/$1/s; $doc =~ s/^\s*\*//gm; my %parsed = (); # remember each part that is parsed # the first paragraph could be a summary statement # a paragraph may follow of variable defs (variable names start with "@") my ($summary, $variable_str) = $doc =~ /^\s* ( (?:[^{@]|(?:\{[^@]))* (?:\{\@ (?:[^{@]|(?:\{[^@]))*)* ) \s* (.*) $/xs; $summary =~ s/^\s*(\S.*?)\s*$/$1/s; $parsed{summary} = $summary; # two types of variable def can be dealt with here: # a @argument has a two-part value -- the arg name and a description # all other @ only have a single value each (although there may # be many variables with the same name) if($variable_str) { my %vars = (); while ($variable_str =~ / (?{$_} = [] for qw(instance_fields class_fields instance_methods class_methods inner_classes); } unless ($CLASSES{$class}->{extends}){ &set_base_class($class, $1) if $class_doc =~ /\@base\s+(\w+(?:\.\w+)*)/; } } # # Set the base class for a given class # sub set_base_class { my ($class, $base_class) = @_; &add_class($class); $CLASSES{$class}->{extends} = $base_class unless $CLASSES{$class}->{extends}; } # # Add a property, either a class or instance method or field # sub add_property { my ($doc, $class, $property, $value, $is_class_property) = @_; &add_class($class); return if $property eq 'constructor'; my $parsed_doc = &parse_jsdoc_comment($doc); $doc = $parsed_doc->{summary}; my $key = $is_class_property ? '_class_properties' : '_instance_properties'; for my $classref (@{$CLASSES{$class}->{$key}}){ if ($classref->{property_name} eq $property){ # Whine about rebinding functions to classes if ($FUNCTIONS{$value}){ warn "Already bound property '$property' to '$class'\n"; return; } # Only take on new attributes $classref->{property_doc} ||= $doc; $classref->{property_vars} ||= $parsed_doc->{vars}; return; } } push @{$CLASSES{$class}->{$key}}, { property_doc => $doc, property_name => $property, property_value => $value, property_vars => $parsed_doc->{vars} }; } # # Add a function and its documentation to the global FUNCTION hash # sub add_function { my ($doc, $function, $arg_list, $is_private) = @_; # clean remaining comments out of arg list # (all others are already gone) # Again, taken from Jeffrey Friedl's "Mastering Regular Expressions" { no warnings; $arg_list =~ s/ ($NONQUOTE+| $DQUOTE$NONQUOTE*| $SQUOTE$NONQUOTE*) |$MLINE_COMMENT|$SLINE_COMMENT/$1/gx; } if ($FUNCTIONS{$function}){ warn "Function '$function' already declared\n"; unless ($doc && !$FUNCTIONS{$function}->{documentation}->{summary}){ return 0; } } $FUNCTIONS{$function} = {}; my $func = $FUNCTIONS{$function}; $arg_list and $func->{argument_list} = join(" ", split("\\s+", $arg_list)) or $func->{argument_list} = "()"; my $documentation = parse_jsdoc_comment($doc); if ($documentation->{vars}->{member}){ my ($classname) = map { s/^\s*(\S*)\s*$/$1/; $_ } @{$documentation->{vars}->{member}}; &add_property($doc, $classname, $function, $function, 0) if $classname =~ /\w+/; } my $function_ref = $FUNCTIONS{$function}; $function_ref->{documentation} = $documentation; $function_ref->{description} = $documentation->{summary}; $function_ref->{vars} = $function_ref->{documentation}->{vars}; $function_ref->{vars}->{filename} = $CTX_FILE; $function_ref->{vars}->{private} = 1 if $is_private; 1; } # # Map all the class and instance properties to their implementation # sub map_all_properties { for my $type (qw(_class_properties _instance_properties)){ for my $class (keys %CLASSES){ &map_single_property( $class, $_->{property_name}, $_->{property_value}, $_->{property_doc}, $_->{property_vars}, $type eq '_class_properties') for @{$CLASSES{$class}->{$type}} } } # Map all the unattached functions my $classname = $CONFIG{GLOBALS_NAME} || 'GLOBALS'; &add_class($classname); for my $function (grep !($FUNCTIONS{$_}->{is_mapped} || $CLASSES{$_}), keys %FUNCTIONS){ &map_single_property( $classname, $function, $function, '', undef, 1); } # Map static inner classes for $classname (keys %CLASSES){ my $i = 0; my @to_remove; for my $cprop (@{$CLASSES{$classname}->{class_methods}}){ my $propname = $cprop->{mapped_name}; if ($CLASSES{"$classname.$propname"}){ push @to_remove, $i; push @{$CLASSES{$classname}->{inner_classes}}, {class_name => "$classname." . $cprop->{mapped_name}}; $FUNCTIONS{"$classname.$propname"} = delete $FUNCTIONS{"__$classname.$propname"}; } $i++; } splice(@{$CLASSES{$classname}->{class_methods}}, $_, 1) for reverse @to_remove; } } # # Map a single instance or class field or method # sub map_single_property { my ($class, $prop_name, $prop_val, $description, $vars, $is_class_prop) = @_; if (!$FUNCTIONS{$prop_val}){ push @{$CLASSES{$class}->{$is_class_prop ? 'class_fields' : 'instance_fields'}}, { field_name => $prop_name, field_description => $description, field_value => $prop_val, field_vars => $vars }; return; } my %method; my $function = $FUNCTIONS{$prop_val}; $function->{is_mapped} = 1; $method{mapped_name} = $prop_name; $method{$_} = $function->{$_} for qw/ argument_list description vars /; push @{$CLASSES{$class}->{$is_class_prop ? 'class_methods' : 'instance_methods'}}, \%method; } # # Build up the full hierarchy of classes, including figuring out # what methods are overridden by subclasses, etc # PARAM: The JS source code # sub build_class_hierarchy { # Find out what is inherited for my $class (map($CLASSES{$_}, sort keys %CLASSES)){ my $superclassname = $class->{extends}; !$superclassname and next; my $superclass = $CLASSES{$superclassname}; $class->{inherits} = {}; while ($superclass){ $class->{inherits}->{$superclassname} = {}; my @instance_fields; my @instance_methods; &handle_instance_methods($superclass, $superclassname, $class, \@instance_methods); &handle_instance_fields($superclass, $superclassname, $class, \@instance_fields); $superclassname = $superclass->{extends}; $superclass = $superclassname ? $CLASSES{$superclassname} : undef; } } } # # This is just a helper function for build_class_hierarchy # because that function was getting way oversized # sub handle_instance_methods { my ($superclass, $superclassname, $class, $instance_methods) = @_; if ($superclass->{instance_methods}){ INSTANCE_METHODS: for my $base_method (@{$superclass->{instance_methods}}){ for my $method (@{$class->{instance_methods}}){ if ($$base_method{mapped_name} eq $$method{mapped_name}){ # Carry over the description for overridden methods with # no description (to be javadoc compliant) if (($base_method->{description} or $base_method->{vars}) and not $method->{description}){ $method->{description} = $base_method->{description}; for my $varkey (keys(%{$base_method->{vars}})){ $method->{vars}->{$varkey} = $base_method->{vars}->{$varkey} unless $method->{vars}->{$varkey}; } } next INSTANCE_METHODS; } } for (keys %{$class->{inherits}}){ my $inherited = $class->{inherits}->{$_}; for my $method (@{$inherited->{instance_methods}}){ next INSTANCE_METHODS if $$base_method{mapped_name} eq $method; } } push @$instance_methods, $$base_method{mapped_name}; } $class->{inherits}->{$superclassname}->{instance_methods} = $instance_methods; } } # # This is just a helper function for build_class_hierarchy # because that function was getting way oversized # sub handle_instance_fields { my ($superclass, $superclassname, $class, $instance_fields) = @_; if ($superclass->{instance_fields}){ INSTANCE_FIELDS: for my $base_field (@{$superclass->{instance_fields}}){ for my $field (@{$class->{instance_fields}}){ next INSTANCE_FIELDS if $field eq $base_field; } push @$instance_fields, $base_field->{field_name}; } $class->{inherits}->{$superclassname}->{instance_fields} = $instance_fields; } } # # Set all the class constructors # sub set_class_constructors { for my $classname (keys %CLASSES){ my $constructor = $FUNCTIONS{$classname}; $CLASSES{$classname}->{constructor_args} = $constructor->{argument_list}; $CLASSES{$classname}->{constructor_detail} = $constructor->{description}; $CLASSES{$classname}->{constructor_vars} = $constructor->{vars} || {}; } } # # Clear out everything from the parsed classes and functions # sub reset_parser { %CLASSES = (); %FUNCTIONS = (); } # # Set global parameters for the parser # sub configure_parser { %CONFIG = @_; } # # Set the initial defaults for the parser # sub initialize_parser { $CONFIG{GLOBALS_NAME} ||= 'GLOBALS'; } # # Run through the source and convert 'confusing' JavaScript constructs # into ones that are understood by the parser, as well as stripping # out unwanted comment blocks. # # For example: # # Foo.prototype = { # bar: function(){ return "Eep!"; }, # baz: "Ha!" # } # # becomes # # Foo.prototype.bar = function(){ return "Eep!"; }; # Foo.prototype.baz = "Ha!"; # sub preprocess_source { my ($src) = @_; # Make all the @extends tags into @base tags $src =~ s/\@extends\b/\@base/g; # This had better not break anything! $src = &deconstruct_getset($src); # Convert: # /** @singleton */ # Foo = {...}; # to: # /** @singleton */ # Foo = function(){} # Foo.prototype = {...}; $src =~ s! ($JSDOC_COMMENT\s*) (?:var\s*)?(\w+(?:\.\w+)*?) \s*=\s*{ !index($1, '@singleton') == -1 ? "$1$2 = {" : "$1$2 = function(){}\n$2.prototype = {"!egx; # Convert: # /** @constructor */ # Foo.Bar = function(){...} # to: # /** @constroctor */ # Foo.Bar = function(){} # /** @constructor */ # function Foo.Bar(){...} # # Note that we have to keep the original declaration so that Foo.Bar # can be recognized as a nested class. Yes, I know it's bad... $src =~ s! ($JSDOC_COMMENT\s*) (?:var\s*)?(\w+(?:\.\w+)*?) \s*= (\s*function)(?=\s*($BAL_PAREN)\s*\{) !index($1, '@constructor') == -1 ? "$1$2 = $3" : "$1$2 = function$4 {};\n$1$3 $2"!egx; # remove all uninteresting comments, but only if they're not inside # of other comments # (adapted from Jeffrey Friedl's "Mastering Regular Expressions" { no warnings; $src =~ s/ ($NONQUOTE+| $JSDOC_COMMENT$NONQUOTE*| $DQUOTE$NONQUOTE*| $SQUOTE$NONQUOTE*) |$MLINE_COMMENT|$SLINE_COMMENT/$1/gx; 1 while $src =~ s/$JSDOC_COMMENT\s*($JSDOC_COMMENT)/$1/g; } # Alter the prototype-initialization blocks $src =~ s/ (\w+(?:\.\w+)*)\.prototype \s*=\s*($BAL_BRACE)/deconstruct_prototype($1, $2)/egx; # Mark all constructors based on 'new' statements my %seen; my @classnames = grep { not $seen{$_}++ } $src =~ /\bnew\s+(\w+(?:\.\w+)*)\s*\(/g; for my $cname (@classnames){ $src =~ s/($JSDOC_COMMENT?) (?=\s*function\s+\Q$cname\E\s*$BAL_PAREN \s*$BAL_BRACE) /&annotate_comment($1, '@constructor')/ex; } $src =~ s/ ($JSDOC_COMMENT?)\s* (function\s+\w+(?:\.\w+)*\s*$BAL_PAREN\s*) ($BAL_BRACE) /&deconstruct_constructor($1, "$2$3")/egx; $src =~ s! (?:var\s+)?(\w+(?:\.\w+)*) \s*=\s* new\s+ ($ANON_FUNCTION)!&deconstruct_singleton($1, $2)!egx; $src = &remove_dynamic_bindings($src); # Mark all void methods with "@type void" $src =~ s/($JSDOC_COMMENT?)\s* ((?: (?:function\s+\w+(?:\.\w+)*\s*$BAL_PAREN\s*) | (?:\w+(?:\.\w+)*\s*=\s*function\s*(?:\w+\s*)?$BAL_PAREN\s*) )$BAL_BRACE) /&mark_void_method($1, $2)/egx; # Clear nested functions (will save trouble later on) $src =~ s/($JSDOC_COMMENT?)\s* (\w+(?:\.\w+)*\s*=\s*)? (function(?:\s+\w+(?:\.\w+)*)?\s*$BAL_PAREN\s*) ($BAL_BRACE) /&clear_nested($1, $2, $3, $4)/egx; return $src; } sub clear_nested { my ($doc, $assign_to, $declaration, $funcbody) = @_; $assign_to ||= ''; if ($doc =~ /^(?=.*\@constructor|\@class)(?=.*\@exec)/){ warn "\@constructor or \@class can't be used together with \@exec\n"; } if ($doc !~ /\@(constructor|class|exec)/ or $assign_to =~ /^\w+\.prototype\./) { return "$doc\n$assign_to$declaration" . "{}\n"; } elsif ($doc =~ /\@(constructor|class)/) { return "$doc\n$assign_to$declaration$funcbody"; } else { my @visible_funcs = $funcbody =~ / ((?:$JSDOC_COMMENT)? (?:\w+\.\w+(?:\.\w+)*)\s*=\s* (?: $FUNC_DEF | $ANON_FUNCTION | $FUNC_CALL | \w+ )\s*;)/gx; return join("\n", @visible_funcs); } } # # Remove dynamic binding. # Change this: # # function MyFunc(class){ # var x = 2; # class.prototype.func = function(){}; # return x; # } # # to: # # function MyFunc(class){ # var x = 2; # # return x; # } # # and change this: # # function BindMethod(obj){ # obj.someFunc = function(){ return null; }; # return obj; # } # # to: # # function BindMethod(obj){ # # return obj; # } # sub remove_dynamic_bindings { my ($src) = @_; while ($src =~ /$RET_FUNC_DEF/g){ my ($fname, $params, $definition) = ($1, $2, $3); next unless $definition =~ /\bfunction\b|\w+\.prototype\./; my @params = split(/\s*,\s*/, substr($params, 1, length($params) - 2)); for my $param (@params){ $src =~ s/\b$param\.prototype\.[^;\n]*[;\n]//g; $src =~ s/\b$param\.\w+ = $ANON_FUNCTION//g; } } $src; } # # Annotate a method as being void if no @type can be found, and there is no # statement to return a value in the method itself. # sub mark_void_method { my ($doc, $funcdef) = @_; return "$doc\n$funcdef" if $doc =~ /\@(constructor|type|returns?)\b/; my ($fbody) = $funcdef =~ /^[^{]*($BAL_BRACE)/; $fbody =~ s/$FUNC_DEF/function x(){}/g; $fbody =~ s/$ANON_FUNCTION/function (){}/g; $doc = &annotate_comment($doc, '@type void') if $fbody !~ /\breturn\s+(?:(?:\w+)|(?:(["']).*?\1)|$BAL_PAREN)/; "$doc\n$funcdef"; } # # A helper to change singleton declarations like # # MySingleton = new function(){this.x=function(){}} # # into: # # function MySingleton(){} # MySingleton.prototype.x = function(){}; # sub deconstruct_singleton { my ($classname, $definition) = @_; $definition =~ s/function\s*$BAL_PAREN\s*\{(.*)\}\s*$/$1/s; $definition =~ s/\bthis\./$classname.prototype\./g; qq# function $classname(){} $definition; #; } # # A helper to preprocess_source, change prototype-initialization # blocks into multiple prototype-property assignments # sub deconstruct_prototype { my ($class, $src) = @_; $src =~ s/^\{(.*)\}$/$1/s; $src =~ s! (\w+) \s*:\s* ( $ANON_FUNCTION | $FUNC_DEF | $FUNC_CALL | $LITERAL | $BAL_SQUAR | $BAL_BRACE | [-\w.+]+ ) \s*,? !$class.prototype.$1 = $2;!gsx; $src; } # # Unpacks a constructor into separate calls # sub deconstruct_constructor { my ($doc, $func_def) = @_; return "$doc$func_def" unless $doc =~ /\@(constructor|class)/; my ($classname) = $func_def =~ /function\s+(\w+(?:\.\w+)*)/; $func_def =~ s/ (\{.*\})$ /&deconstruct_inner_constructor($classname, $1)/esx; "$doc$func_def"; } sub deconstruct_inner_constructor { my ($classname, $inner_src) = @_; $inner_src = substr($inner_src, 1, -1); my @doc_n_fnames = $inner_src =~ /($JSDOC_COMMENT?)\s*function\s+(\w+)/g; unless ($CONFIG{NO_LEXICAL_PRIVATES}){ $inner_src =~ s/ ($JSDOC_COMMENT)? \s* var \s+ (\w+)/&annotate_comment($1) . "\n$classname\.prototype\.$2"/egx; $inner_src =~ s/ ($JSDOC_COMMENT)?\s* ^\s* function \s+ (\w+) /&annotate_comment($1) . "\n$classname\.prototype\.$2 = function"/egmx; } { no warnings; $inner_src =~ s/ ($JSDOC_COMMENT\s*)? ^\s*this(?=\.) /$1$classname.prototype/gmx; } # Replace all bindings of private methods to public names for (my $i = 0; $i < @doc_n_fnames; $i += 2) { my ($doc, $fname) = @doc_n_fnames[$i, $i + 1]; $inner_src =~ s/ ($JSDOC_COMMENT\s* $classname\.prototype\.\w+) \s*=\s* $fname\s*[\n;] /$1 = function(){}/gx; $inner_src =~ s/ ($classname\.prototype\.\w+) \s*=\s* $fname\s*[\n;] /$doc\n$1 = function(){}/gx; } "{}\n$inner_src"; } # # Deconstruct mozilla's __defineGetter__ and __defineSetter__ # (Yes, I know this goes against my principles...) # sub deconstruct_getset { my ($src) = @_; # Crack open the assignments for define(Getter|Setter) my $crack = sub { my $code = shift; $code =~ s/^.(.*).$/$1/s; my ($name) = split ",", $code; $name = ($name =~ /.*?(['"])([^'"]+)\1/)[1]; $name; }; for my $prefix ('get', 'set'){ my $fname = "define\u${prefix}ter"; $src =~ s/ (\w+(?:\.\w+)* \.prototype) \.__${fname}__\s*($BAL_PAREN)/ my $name = $crack->($2); "$1.$name = null"/gex; } $src; } # # Add an annotation (@tag) to a documentation block. The block is assumed to # be a valid JSDoc documentation block ==> /^\/\*\*.*\*\/$/ # and no checking is done to verify this # sub annotate_comment { my $annotation = $_[1] || '@private'; return "\n/** $annotation */" unless $_[0]; substr($_[0], 0, -2) . " \n$annotation \n*/"; } # # This is here to stop perl from segfaulting from deep recursion in regexes # The first character in the text _should_ be open_token, as everything # before open_token will be discarded, unless there is no matching text # at all. # sub find_balanced_block { my ($open_token, $close_token, $text) = @_; my ($count, $open, $close) = (0, 0, 0); return ('', $text) unless $text =~ /\Q$open_token\E/; $text =~ s/^.*?(?=\Q$open_token\E)//s; for (split //, $text){ $count++; $open++ if $_ eq $open_token; $close++ if $_ eq $close_token; last unless ($open != $close); } warn "Unbalanced block\n" if ($open != $close); (substr($text, 0, $count), substr($text, $count)); } # # Remove the $CONFIG{GLOBALS_NAME} class if it doesn't contain anything # sub filter_globals { my $global = $CLASSES{$CONFIG{GLOBALS_NAME}}; delete $CLASSES{$CONFIG{GLOBALS_NAME}} if not (defined $global->{constructor_args} || defined $global->{constructor_detail}) && not (@{$global->{instance_methods}} || @{$global->{instance_fields}} || @{$global->{class_methods}} || @{$global->{class_fields}}); # Also get rid of extra info under the '__files__' key delete $CLASSES{__FILES__}->{$_} for qw(constructor_params constructor_args constructor_detail class_methods constructor_vars); } # # Try to grab the first block comment from the file that has a @fileoverview # tag in it, and get the file info from there # sub parse_file_info { my ($src) = @_; my %fileinfo = ( src => $src ); while ($src =~ /($JSDOC_COMMENT)/g){ local $_ = substr($1, 3, length($1) - 5); # Get the actual content if (/\@fileoverview\b/){ my $doc = parse_jsdoc_comment($_, 1); %fileinfo = (%{$doc->{vars}}, %fileinfo); last; } } $CLASSES{__FILES__}->{$CTX_FILE} = \%fileinfo if $CTX_FILE; } 1; jsjac-1.3.4+dfsg/utils/JSDoc/JSDoc/000077500000000000000000000000001153725753300166075ustar00rootroot00000000000000jsjac-1.3.4+dfsg/utils/JSDoc/JSDoc/XMI.pm000066400000000000000000000174401153725753300176100ustar00rootroot00000000000000package JSDoc::XMI; use strict; use warnings; use HTML::Template; use Data::Dumper; =head1 DESCRIPTION @packages @classes $classname $classid $classuuid $classvisibility (public|protected|private) @specializationids $specializationid $generalizationid @attributes $attributeid $attributeuuid $attributename $attributevisibility (public|protected|private) $ownerscope (instance|classifier) $classid $typeid @methods $methodid $methoduuid $methodname $methodvisibility (public|protected|private) $ownerscope (instance|classifier) $returnid $returnuuid $returntypeid @datatypes $datatypeid $datatypeuuid $datatypename @generalizations $generalizationid $generalizationuuid $generalizationchild $generalizationparent =cut sub new { my ($package, $location) = @_; bless { location => "${location}JSDoc/", idcounter => 2, types => {}, classes => {}, generalizations => {} }, $package; } sub output { my ($self, $classes) = @_; my $template = HTML::Template->new( filename => $self->{location} . 'xmi.tmpl', die_on_bad_params => 1); my @packages = $self->get_packages($classes); my @datatypes = $self->get_datatypes; my @generalizations = $self->get_generalizations; $template->param( packages => \@packages, datatypes => \@datatypes, generalizations => \@generalizations ); return $template->output; } sub get_id { 'xmi.' . shift->{idcounter}++; } sub get_uuid { my @chars = ('A'..'Z', 'a'..'z', 0..9); my @uuid; for (1..32){ push @uuid, $chars[rand(@chars)]; } join("", @uuid); } sub get_packages { my ($self, $classes) = @_; my %packages; push(@{$packages{$_->{package}}}, $_) for $self->get_classes($classes); map { name => $_, classes => $packages{$_}, packageid => $self->get_id, packageuuid => $self->get_uuid }, keys %packages; } sub get_classes { my ($self, $classes) = @_; my @classes; # Store all the class-ids before we start on anything else $self->add_class($_) for keys %$classes; for my $cname (keys %$classes){ my $class = { classname => $cname, classid => $self->add_class($cname), classuuid => $self->get_uuid, classvisibility => defined($classes->{$cname}->{constructor_vars}->{private}) ? 'private' : 'public' }; $class->{attributes} = $self->get_attributes( $class->{classid}, $classes->{$cname}); $class->{methods} = $self->get_methods( $class->{classid}, $classes->{$cname}); $class->{generalizationid} = $self->get_generalizationid($classes->{$cname}); $class->{package} = defined($classes->{$cname}->{constructor_vars}->{package}) ? $classes->{$cname}->{constructor_vars}->{package}->[0] : ''; push @classes, $class; } for my $class (@classes){ $class->{specializationids} = $self->get_specializationids($class); } @classes; } sub get_methods { my ($self, $classid, $class) = @_; my @methods; for my $k (qw(instance class)){ for my $method (@{$class->{"${k}_methods"}}){ my $type = defined($method->{vars}->{type}) ? $method->{vars}->{type}->[0] : 'Object'; my $meth = { methodid => $self->get_id, methoduuid => $self->get_uuid, methodname => $method->{mapped_name}, methodvisibility => defined($method->{vars}->{private}) ? 'private' : 'public', ownerscope => $k eq 'class' ? 'classifier' : 'instance', returnid => $self->get_id, returnuuid => $self->get_uuid, returntypeid => $self->add_type($type) }; push @methods, $meth; } } return \@methods; } sub get_attributes { my ($self, $classid, $class) = @_; my @attributes; for my $k (qw(instance class)){ for my $field (@{$class->{"${k}_fields"}}){ my $type = defined($field->{field_vars}->{type}) ? $field->{field_vars}->{type}->[0] : 'Object'; my $attr = { attributeid => $self->get_id, attributeuuid => $self->get_uuid, attributename => $field->{field_name}, attributevisibility => defined($field->{field_vars}->{private}) ? 'private' : 'public', ownerscope => $k eq 'class' ? 'classifier' : 'instance', classid => $classid, typeid => $self->add_type($type) }; push @attributes, $attr; } } \@attributes; } sub get_generalizationid { my ($self, $class) = @_; if ($class->{extends}){ return $self->add_generalization( $class->{classname}, $class->{extends}); } ''; } sub get_specializationids { my ($self, $class) = @_; my $cname = $class->{classname}; my $cid = $self->add_class($cname); my @specializationids; for my $id (keys %{$self->{generalizations}}){ my $generalization = $self->{generalizations}->{$id}; if ($generalization->{parent} eq $cid){ push @specializationids, { specializationid => $id }; } } \@specializationids; } sub get_datatypes { my ($self) = @_; my @datatypes; while (my ($type, $id) = each(%{$self->{types}})){ push @datatypes, { datatypeid => $id, datatypeuuid => $self->get_uuid, datatypename => $type }; } @datatypes; } sub get_generalizations { my ($self) = @_; my @generalizations; while (my ($id, $generalization) = each(%{$self->{generalizations}})){ push @generalizations, { generalizationid => $id, generalizationuuid => $self->get_uuid, generalizationchild => $generalization->{parent}, generalizationparent => $generalization->{child}}; } @generalizations; } sub add_type { my ($self, $type) = @_; $type =~ s/^\s*(\S+)\s*$/$1/; if (defined($self->{classes}->{$type})){ return $self->add_class($type); } elsif (defined($self->{types}->{$type})){ return $self->{types}->{$type}; } $self->{types}->{$type} = $self->get_id; } sub add_class { my ($self, $class) = @_; $class =~ s/^\s*(\S+)\s*$/$1/; if (defined($self->{classes}->{$class})){ return $self->{classes}->{$class}; } $self->{classes}->{$class} = $self->get_id; } sub add_generalization { my ($self, $subclassname, $superclassname) = @_; my $subclassid = $self->add_class($subclassname); my $superclassid = $self->add_class($superclassname); my $generalization = { child => $subclassid, parent => $superclassid }; my $generalizationid = $self->get_id; $self->{generalizations}->{$generalizationid} = $generalization; $generalizationid; } 1; jsjac-1.3.4+dfsg/utils/JSDoc/JSDoc/XML.pm000066400000000000000000000035431153725753300176120ustar00rootroot00000000000000package JSDoc::XML; use strict; use warnings; use HTML::Template; sub new { my ($package, $location) = @_; bless { location => "${location}JSDoc/" }, $package; } sub output { my ($self, $classes) = @_; my @classes = _preprocess( grep {defined($_->{classname})} values %$classes); my $template = HTML::Template->new( filename => $self->{location} . 'xml.tmpl', die_on_bad_params => 1); $template->param(classes => \@classes); return $template->output; } sub _preprocess { my @classes = @_; for (@classes){ $_->{inherits} = _preprocess_inherits($_->{inherits}); $_->{constructor_vars} = _preprocess_vars($_->{constructor_vars}); for my $method (@{$_->{instance_methods}}, @{$_->{class_methods}}){ $method->{vars} = _preprocess_vars($method->{vars}); } for my $field (@{$_->{instance_fields}}, @{$_->{class_fields}}){ $field->{field_vars} = _preprocess_vars($field->{field_vars}); } } @classes; } sub _preprocess_inherits { my ($inherits) = @_; my @inherits; for my $class (keys %$inherits){ my $inherit = { class => $class, methods => [map { name => $_ }, @{$inherits->{$class}->{instance_methods}}]}; push @inherits, $inherit; } \@inherits; } sub _preprocess_vars { my ($vars) = @_; return $vars if ref($vars) eq 'ARRAY'; my @vars; for my $key (keys %$vars){ my $var; if (ref($vars->{$key}) eq 'ARRAY'){ $var = { '@name' => $key, values => [map { val => $_ }, @{$vars->{$key}}] }; } else { $var = { '@name' => $key, values => [ { val => $vars->{$key} } ] }; } push @vars, $var; } \@vars; } 1; jsjac-1.3.4+dfsg/utils/JSDoc/JSDoc/xmi.tmpl000066400000000000000000000313271153725753300203100ustar00rootroot00000000000000 JSDoc XMI Export 0.1 JSDoc " xmi.uuid=""> return jsjac-1.3.4+dfsg/utils/JSDoc/JSDoc/xml.tmpl000066400000000000000000000121041153725753300203030ustar00rootroot00000000000000 " extends="" > ]]> ]]> ]]> ]]> ]]> ]]> ]]> ]]> ]]> ]]> ]]> ]]> jsjac-1.3.4+dfsg/utils/JSDoc/JavaScript/000077500000000000000000000000001153725753300177135ustar00rootroot00000000000000jsjac-1.3.4+dfsg/utils/JSDoc/JavaScript/Syntax/000077500000000000000000000000001153725753300212015ustar00rootroot00000000000000jsjac-1.3.4+dfsg/utils/JSDoc/JavaScript/Syntax/HTML.pm000066400000000000000000000041101153725753300222770ustar00rootroot00000000000000package JavaScript::Syntax::HTML; =head1 NAME JavaScript::Syntax::HTML - Convert JavaScript sourcecode to HTML =head1 SYNOPSIS use JavaScript::Syntax::HTML qw(to_html to_html_document); my $html_fragment = to_html($js_src); my $html_doc = output_html_document($js_src); =head1 DESCRIPTION JavaScript::Syntax::HTML processes JavaScript code and outputs HTML with all reserved words marked up. The to_html method only outputs an HTML fragment (no or tags), and only marks up the reserved words with CSS styles. The to_html_document method outputs a full HTML document, and does include style information for the reserved words markup. The style classes that can be defined for use with to_html are C, C, and C. =head1 AUTHOR Gabriel Reid gab_reid@users.sourceforge.net =cut use warnings; use strict; use Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw(to_html to_html_document); sub to_html { local $_ = shift; s/\&/&/g; s//>/g; s/ ((?:\/\*.*?\*\/) | (?:\/\/[^\n]*$)) | ('[^']*'|"[^"]*") | \b(function|for|if|while|return|else|prototype|this)\b / get_substitution($1, $2, $3) /egsxm; $_; } sub get_substitution { my ($comment, $stringliteral, $resword) = @_; my $content; if ($comment){ $comment =~ s/(\@\w+)\b/get_span('attrib', $1)/eg; return get_span('comment', $comment); } elsif ($stringliteral){ return get_span('literal', $stringliteral); } elsif ($resword){ return get_span('reserved', $resword); } } sub get_span { my ($class, $inner) = @_; qq($inner); } sub to_html_document { my ($src) = @_; $src = &to_html($src); qq(
      $src
      	
      ); } jsjac-1.3.4+dfsg/utils/JSDoc/README000066400000000000000000000022511153725753300165250ustar00rootroot00000000000000README for jsdoc.pl jsdoc.pl is a script that produces javadoc-style documentation from well-formed JavaScript sourcefiles. At the moment, this means it supports sourcefiles where all functions are mapped to a class using prototype-based inheritance. Anonymous function definitions (e.g. Circle.prototype.getRadius = function(){ ...} ) are supported. This application requires Perl5, as well as one non-standard addon module: - HTML::Template, which is available from CPAN (cpan.org) Invocation is simple: Just run the application, giving one or more well-formed OO JavaScript sourcefilename(s) as arguments. A sample JS sourcefile, test.js, is given along with this application. An example of running the application is shown below: $ ./jsdoc.pl test.js OR perl jsdoc.pl test.js Further information about using JsDoc can be found at http://jsdoc.sourceforge.net If there are any questions, comments, problems or anything else, please mail the jsdoc-user mailing list; more information can be found at http://sourceforge.net/mail/?group_id=30801. This application has been successfully tested on Linux (Debian and Redhat), and Windows 2000 with ActivePerl. jsjac-1.3.4+dfsg/utils/JSDoc/TODO000066400000000000000000000024571153725753300163450ustar00rootroot00000000000000TODO for JSDoc - XML / XMI export - Improve the --package-naming option so that there are separate namespaces for each package (so that you can have the same class name defined in different packages) - Fix some spacing/table issues in the navbar in the templates (use a td border in the stylesheet to debug) - Introduce a more generalized system for generating the navbar - Handle additional information (such as @see) for fields - Uncallable methods/functions should be marked as private, or show the scope from which they can be called - Dynamic handling of assignment of prototype to a temp variable (preprocessor) - Add support for interfaces, but first this has to be better defined - Top-level var documenting (maybe add a '@global' tag to force toplevel vars to be documented - Add an FAQ, more and better documentation - Java port (someday...) - Make a more polished API for using other doclets, like javadoc - Add a deprecated page, make deprecated support more like javadoc - Add support for js files without .js extension - Support for a time stamp - Some of the ->{vars} are set to undef, should always be an empty map - Add command line params --dump-tree, --dump-xml - Add command line param --stylesheet - Make navbar links selective so they are never broken - Update the help doc jsjac-1.3.4+dfsg/utils/JSDoc/TestJSDoc.pl000066400000000000000000000436431153725753300200160ustar00rootroot00000000000000#!/usr/bin/perl package JSDoc; # # Unit testing of JSDoc # # Run with 'perl TestJSDoc.pl' or './TestJSDoc.pl' # use strict; use warnings; use JSDoc; use Data::Dumper; use Test::More qw(no_plan); $|++; # parse_jsdoc_comment diag("Testing parse_jsdoc_comment"); is_deeply(parse_jsdoc_comment(''), {summary => ''}, "Ensure only summary is filled in"); is(parse_jsdoc_comment('')->{summary}, '', 'Empty comment value'); is(parse_jsdoc_comment( '************************* test *************')->{summary}, 'test', 'long leading and trailing stars'); # annotate_comment diag("Testing annotate_comment"); is(annotate_comment, "\n/** \@private */", 'annotate_comment w/o arg'); like(annotate_comment("/** This is a test */"), qr#^/\s*\*\*\s*This is a test\s+\@private\s*\*/\s*$#, 'annotate_comment w/ arg'); like(annotate_comment("/** This is a test */", '@testtag value'), qr#^/\s*\*\*\s*This is a test\s+\@testtag\svalue\s*\*/\s*$#, 'annotate_comment w/ tag argument'); # find_balanced_block diag("Testing find_balanced_block"); my @blocks = ( # basic simple input ['{', '}', '{ this is in the braces } {this is after}{{', ['{ this is in the braces }', ' {this is after}{{'] , 'basic input'], # discard leading chars before opening char ['{', '}', 'discard {inner} after', ['{inner}', ' after'], 'discard leading chars'], # empty input string ['{', '}', '', ['', ''], 'empty input string'], # nothing to match at all ['{', '}', 'there is nothing to match', ['', 'there is nothing to match'], 'nothing to match'], ); for my $test (@blocks){ my @args = @{$test}[0..2]; my ($expect, $explain) = @{$test}[3,4]; is_deeply([find_balanced_block(@args)], $expect, $explain); } # # Test the @member tag # diag('Testing the @member tag'); reset_parser(); my $src = q# /** @constructor */ function Foo(){ this.x = function(){return null;}; } /** Unrelated */ function myfunc(){return null;} #; my $classes = parse_code_tree(\$src); my %method_names = map { $_->{mapped_name} => 1 } @{$classes->{Foo}->{instance_methods}}; ok(not(defined($method_names{myfunc})), 'Unrelated method is not added to class without @member tag'); reset_parser(); $src = q# /** @constructor */ function Foo(){ this.x = function(){return null;}; } /** * @member Foo */ function myfunc(){return null;} #; $classes = parse_code_tree(\$src); %method_names = map { $_->{mapped_name} => 1 } @{$classes->{Foo}->{instance_methods}}; ok(defined($method_names{myfunc}), 'Add method marked with @member to class'); reset_parser(); # # preprocess_source # diag("Testing preprocess_source"); # Make sure that: # # Foo.prototype = { # bar: function(){ return "Eep!"; }, # baz: "Ha!" # } # # becomes: # # Foo.prototype.bar = function(){ return "Eep!"; }; # Foo.prototype.baz = "Ha!"; my $before = q/ Foo.prototype = { bar: function(){ return "Eep!"; }, baz: "Ha!" } /; my $after_re = qr/^\s*(?:$JSDOC_COMMENT)?\s*Foo.prototype.bar \s*=\s* function\(\s*\)\s*\{[^\}]*}\s*;\s* Foo\.prototype\.baz\s*=\s*"[^"]+"\s*;\s*$/x; like(preprocess_source($before), $after_re, 'Unpack prototype block assignment'); # # Make sure that: # # /** @constructor */ # Foo.Bar = function(){this.x = 2;var y = 3;} # becomes: # /** @constructor */ # Foo.Bar = function(){}; # # /** @constructor */ # function Foo.Bar(){} # # Foo.Bar.prototype.x = 2; # # /** @private */ # Foo.Bar.prototype.y = 3; # $before = q# /** @constructor */ Foo.Bar = function(){this.x = 2; var y = 3; }#; $after_re = qr{ ^\s*/\*\*\s*\@constructor\s*\*/\s* Foo\.Bar\s*=\s*function\s*\(\s*\)\s*\{\s*\}\s*;\s* /\*\*\s*\@constructor\s*\*/\s* function\s+Foo\.Bar\s*\(\s*\)\s*\{\s*\} \s* Foo\.Bar\.prototype\.x\s*=\s*2\s*;\s* /\*\*\s*\@private\s*\*/\s* Foo\.Bar\.prototype\.y\s*=\s*3\s*;\s*$ }x; like(preprocess_source($before), $after_re, 'Unpack nested class'); # # Make sure that: # MySingleton = new function(){this.x=function(){}} # and # var MySingleton = new function(){this.x=function(){}} # become: # function MySingleton(){} # MySingleton.prototype.x = function(){}; # $before = q# MySingleton = new function(){this.x=function(){}} #; $after_re = qr{ ^\s*(?:$JSDOC_COMMENT)? \s*function\s*MySingleton\s*\(\)\s*\{\s*\}\s* (?:$JSDOC_COMMENT)?\s* MySingleton\.prototype\.x\s*=\s*function\s*\(\s*\)\s*\{\s*\}\s*;\s*$}x; like(preprocess_source($before), $after_re, 'Unpack singleton'); # Same thing, but with var before the declaration $before = q#var MySingleton = new function(){this.x=function(){}} #; like(preprocess_source($before), $after_re, "Unpack var'd singleton"); # # Test unpacking a constructor into a bunch of # prototype-based declarations # $before = q# /** * @constructor */ function MyClass(){ /** Private variable 'x' */ var x = 3; /** * This is my function */ this.myFunction = function(){ return null; }; /** * This is a private function */ function myPrivateFunction(x){ return null; } } #; $after_re = qr{ /\*\*\s* \*\s*\@constructor\s* \*/\s* function\s+MyClass\s*\(\s*\)\s*\{\s*\}\s* /\*\*\s*Private\svariable\s'x'\s* \@private\s*\*/\s* MyClass\.prototype\.x\s*=\s*3\s*;\s* /\*\*\s* \*\s*This\sis\smy\sfunction\s*\*/\s* MyClass\.prototype\.myFunction\s*=\s*function\s*\(\s*\)\s*\{ [^\}]*\}\s*;\s* /\*\*\s* \*\s*This\sis\sa\sprivate\sfunction\s* \@private\s*\*/\s* MyClass\.prototype\.myPrivateFunction\s*=\s*function\(\s*x\s*\)\s* \{[^\}]*\}\s*$ }x; like(preprocess_source($before), $after_re, 'Testing unpacking a constructor into prototype-based assignments'); # # Test the marking of void methods # $before = q'function MyFunc(){}'; $after_re = qr{/\*\*\s*\@type\s+void\s*\*/\s*function\s+MyFunc\s*\(\)\{\}}; like(preprocess_source($before), $after_re, "Testing basic marking of void method without a docstring"); $before = q' /** Method */ function MyFunc(){} '; $after_re = qr{/\*\*\s*Method\s+\@type\s+void\s*\*/\s* function\s+MyFunc\(\)\{\}}x; like(preprocess_source($before), $after_re, "Testing basic marking of void methods"); $before = '/** Method */ Shape.prototype.MyFunc = function(){}'; $after_re = qr{ /\*\*\s* Method\s+ \@type\s+void\s* \*/\s*Shape\.prototype\.MyFunc\s*=\s*function\(\)\{\}}x; like(preprocess_source($before), $after_re, "Testing marking of void anonymous method"); $before = 'Shape.prototype.MyFunc = function(){return null;}'; $after_re = qr{^\s*Shape\.prototype\.MyFunc\s*= \s*function\(\)\{[^\}]*\}}x; like(preprocess_source($before), $after_re, "Testing marking of void anonymous method"); $before = "function x(){return null;}"; $after_re = qr{\s*function\sx\(\)\s*\{[^\}]*\}\s*$}; like(preprocess_source($before), $after_re, "Leave non-void methods without docstrings alone"); $before = "/** My test function */\nfunction x(){return null;}"; $after_re = qr{\s*/\*\*\s*My\stest\sfunction\s*\*/\s* function\sx\(\)\s*\{[^\}]*\}\s*$}x; like(preprocess_source($before), $after_re, "Leave non-void methods with docstrings alone"); reset_parser(); $src = q# /** * @constructor */ function MyClass(){ this.af = afunc; this.bf = bfunc; this.cf = cfunc; function afunc(){} function bfunc(){} function cfunc(){} } #; $classes = parse_code_tree(\$src); ok(eq_set( [ map { $_->{mapped_name} } @{$classes->{MyClass}->{instance_methods}}], ['af', 'bf', 'cf', 'afunc', 'bfunc', 'cfunc']), "Ensure instance methods in constructor are correctly assigned"); reset_parser(); $src = 'function MyFunction(){ return ""; }'; $classes = parse_code_tree(\$src); ok(!defined($classes->{GLOBALS}->{class_methods}->[0]->{vars}->{type}), "Ensure a function returning an empty string is not marked as void"); reset_parser(); $src = 'function A(){ var x = "x"; }'; $classes = parse_code_tree(\$src); ok($classes->{GLOBALS}->{class_methods}->[0]->{vars}->{type}->[0] eq 'void', "Ensure a global void is void"); reset_parser(); $src = 'function A(c){ c.someFunc = function(){ return 2; }; }'; $classes = parse_code_tree(\$src); ok($classes->{GLOBALS}->{class_methods}->[0]->{vars}->{type}->[0] eq 'void', "Ensure inner function definitions don't affect the return type"); reset_parser(); $src = 'function A(c){ c.someFunc = function(){ return 2; }; return ""; }'; $classes = parse_code_tree(\$src); ok(!defined($classes->{GLOBALS}->{class_methods}->[0]->{vars}->{type}->[0]), "Ensure inner-function measures don't affect non-void functions"); reset_parser(); $src = '/** @return {int} Description */function f(){}'; $classes = parse_code_tree(\$src); ok(!defined($classes->{GLOBALS}->{class_methods}->[0]->{vars}->{type}->[0]), 'Methods with a @return tag but no return statement are not marked void'); reset_parser(); $src = 'function f(){ return (true ? "t" : "f");}'; $classes = parse_code_tree(\$src); ok(!defined($classes->{GLOBALS}->{class_methods}->[0]->{vars}->{type}->[0]), "Non-void with non-trivial return statement is not marked as void"); # # Try huge constructor input # my @testsrc = (q# /** * @class This is class information * @constructor */ function MyClass(){ #); for (1..30){ push @testsrc, " /** This is a private method */ function f$_(){ return null; } /** * THis is function number $_ * \@return Nothing */ this.func$_ = function(){if(true){if(false){return null;}}} ;\n"; } push @testsrc, "\n}\n"; my $testsrc = join("\n", @testsrc); # This could crash everything preprocess_source($testsrc); pass("Process huge constructor with preprocess_source"); # # Huge constructor with unbalanced input # @testsrc = (q# /** * @class This is class information * @constructor */ function MyClass(){ #); for (1..100){ push @testsrc, " /** * THis is function number $_ * \@return Nothing */ this.func$_ = function(){if(true){if(false){return null;}};\n"; } push @testsrc, "\n}\n"; $testsrc = join("\n", @testsrc); # This could crash everything preprocess_source($testsrc); pass("Process huge unbalanced constructor with preprocess_source"); # # deconstruct_mozilla_getset # $before = 'MyClass.prototype.__defineGetter__("myProp", function(){return null;});'; $after_re = qr{ ^\s*MyClass\.prototype\.myProp\s*=\s*null\s*;\s*$}x; #\s*function\s*\(\s*\)\s*\{\s*return\s+null\s*;\s*\}\s*;\s*$}x; like(deconstruct_getset($before), $after_re, "Testing behaviour of __defineGetter__"); like(preprocess_source($before), $after_re, "Testing behaviour of __defineGetter__ in preprocess_source"); $before = 'MyClass.prototype.__defineSetter__("myProp", function(){return null;});'; $after_re = qr{ ^\s*MyClass\.prototype\.myProp\s*=\s*null\s*;\s*$}x; like(deconstruct_getset($before), $after_re, "Testing behaviour of __defineSetter__"); like(preprocess_source($before), $after_re, "Testing behaviour of __defineSetter__ in preprocess_source"); reset_parser(); $src = " function MyFunc(theclass){ var x = 2; theclass.prototype.f = function(){}; return x; } MyClass.prototype.f = function(){}; "; $classes = parse_code_tree(\$src); ok(not(defined($classes->{theclass})), "Ensure that dynamic prototyping doesn't add classes"); ok(defined($classes->{MyClass}), "Ensure that normal classes are added with static prototyping"); # Test @singleton handling reset_parser(); $src = q# /** @singleton */ var SingletonClass = { funcA: function(){}, funcB: function(){} }; #; $classes = parse_code_tree(\$src); ok(defined($classes->{SingletonClass})); my @fnames = sort map { $_->{mapped_name}} @{$classes->{SingletonClass}->{instance_methods}}; is(scalar(@fnames), 2); ok(eq_array(\@fnames, ["funcA", "funcB"])); # # miscellaneous tests # diag("Miscellaneous tests"); reset_parser(); $src = " /** \@constructor */ function A(){} /** \@constructor */ function C(){} /** \@constructor \@extends A */ function B(){} B.prototype = new C();"; $classes = parse_code_tree(\$src); is($classes->{B}->{extends}, 'A', "Test that the first extends marking is the good one, others are ignored"); reset_parser(); $src = "function A(){ this.n = function(){return 2};} var a = new A(); "; $classes = parse_code_tree(\$src); ok(defined($classes->{A}), "Functions are later used with 'new' must be treated as a constructor"); ok(!defined($classes->{this}), "'this' cannot be added as a class"); # # Ensure using the @base tag automatically qualifies a function as a class, # even if the base class isn't defined # reset_parser(); $src = '/** @base SomeOtherClass */ function MyClass(){}'; $classes = parse_code_tree(\$src); ok(defined($classes->{MyClass}), 'A function must be upgraded to a class if the @base tag is used'); # # Allow an anonymous function to be assigned to a global variable, # resulting in a new class # reset_parser(); $src = ' /** * Some function * @constructor */ var SomeClass = function(){ this.x = 2; } '; $classes = parse_code_tree(\$src); ok(defined($classes->{SomeClass}), "Allow anonymous function to be assigned to a global variable"); # # Make sure that dynamically binding methods to a object at a later time # do not affect the documentation # reset_parser(); $src = ' function AddCallback(obj){ obj.callback = function(){ return null; }; }'; $classes = parse_code_tree(\$src); ok(!defined($classes->{obj}), "Don't add passed-in objects as classes when doing dynamic binding"); reset_parser(); $src = ' /** @constructor */ function A(){} A.prototype.setup = A_Setup; A.prototype.tearDown = A_TearDown; function A_Setup(){ this.callback = function(){ return null; }; } function A_TearDown(){ this.tornDown = true; }'; $classes = parse_code_tree(\$src); ok(!defined($classes->{this}), "Don't add 'this' as a class when dynamically adding methods in a method"); # # Test block prototype assignment # diag("Test block prototype assignment"); reset_parser(); $src = ' SomeClass.prototype = { funcA: function(){ return null; }, valA: 3, funcB: function(){ return null; }, valB: "just testing", funcC: function(){} };'; $classes = parse_code_tree(\$src); ok(eq_set( [ map { $_->{mapped_name} } @{$classes->{SomeClass}->{instance_methods}}], ['funcA', 'funcB', 'funcC']), "Ensure instance methods are assigned in prototype definition block"); ok(eq_set( [ map { $_->{field_name} } @{$classes->{SomeClass}->{instance_fields}}], ['valA', 'valB']), "Ensure instance fields are assigned in prototype definition block"); # # Test prototype assignment # diag("Test prototype assignment"); reset_parser(); $src = ' function Base(){} function Sub(){} Sub.prototype = new Base(); '; $classes = parse_code_tree(\$src); ok($classes->{Sub}->{extends} eq 'Base', "Prototype assignment results in inheritance"); reset_parser(); $src = ' function Base(){} function Sub(){} Sub.prototype = new Base; '; $classes = parse_code_tree(\$src); ok($classes->{Sub}->{extends} eq 'Base', "Prototype assignment results in inheritance (2)"); # # Test the handling of methods defined more than once # reset_parser(); $src = ' function f(){} /** doc */ function f(){} '; $classes = parse_code_tree(\$src); ok($classes->{GLOBALS}->{class_methods}->[0]->{description} eq 'doc', "In case of double function definition, the one with most info wins"); reset_parser(); $src = ' /** doc */ function f(){} function f(){} '; $classes = parse_code_tree(\$src); ok($classes->{GLOBALS}->{class_methods}->[0]->{description} eq 'doc', "In case of double function definition, the one with most info wins (2)"); # # Make sure that extra JSDoc-style comment blocks are not viewed as source # reset_parser(); $src = ' /** @constructor */ function x(){} /** more doc function y(){} */ /** @constructor */ function z(){} '; $classes = parse_code_tree(\$src); ok(!defined($classes->{GLOBALS}->{class_methods}->[0]), "Ignore JSDoc in extra JSDoc-comment blocks"); # # Test the behaviour of the @ignore tag # reset_parser(); $src = ' /** This method is normal */ function Normal(){} /** @ignore */ function Hidden(){} '; $classes = parse_code_tree(\$src); my %fnames = map { $_->{mapped_name} => 1 } @{$classes->{GLOBALS}->{class_methods}}; ok(defined $fnames{Normal}, "A normal method is picked up and documented"); ok(!defined $fnames{Hidden}, 'An @ignored method is not picked up'); # # Test the behaviour of the @addon tag # reset_parser(); $src = ' /** * Should be ignored */ ClassOne.funcOne = function(){}; /** * Should not be ignored * @addon */ ClassTwo.funcOne = function(){}; ClassThree.prototype = new Object(); ClassThree.funcThree = function(){}'; $classes = parse_code_tree(\$src); ok(!defined($classes->{ClassOne}), 'Extensions to undefined classes/objects without @addon are ignored'); ok(defined($classes->{ClassTwo}), 'Extensions to undefined classes/objects with @addon are not ignored'); ok($classes->{ClassThree}->{class_methods}->[0]->{mapped_name} eq 'funcThree', 'Class methods without @addon work on pre-defined classes'); # # Ensure enclosing package-classes are still recognized without using @addon # reset_parser(); $src = ' /** * @constructor */ package.MyClass = function MyClass(){} package.MyClass.prototype.foo = function foo(){} '; $classes = parse_code_tree(\$src); ok(defined($classes->{package}), 'Super-package-classes must be recognized without the @addon tag'); ok(defined($classes->{'package.MyClass'}), 'Sub-package-classes must be recognized without the @addon tag'); jsjac-1.3.4+dfsg/utils/JSDoc/allclasses-frame.tmpl000066400000000000000000000016671153725753300217730ustar00rootroot00000000000000 <TMPL_VAR NAME="project_name"> <TMPL_VAR NAME="filename"> "/>


      " TARGET="classFrame">
      jsjac-1.3.4+dfsg/utils/JSDoc/allclasses-noframe.tmpl000066400000000000000000000016021153725753300223150ustar00rootroot00000000000000 <TMPL_VAR NAME="project_name"> All Classes "/>

      All Classes
      " >
      jsjac-1.3.4+dfsg/utils/JSDoc/constant-values.tmpl000066400000000000000000000126521153725753300216770ustar00rootroot00000000000000 <TMPL_VAR NAME="project_name"> Constant Values

      Constant Field Values



      "> .!s!">
      .html">
      .html#">



      Documentation generated by JSDoc on
      jsjac-1.3.4+dfsg/utils/JSDoc/help-doc.tmpl000066400000000000000000000144111153725753300202370ustar00rootroot00000000000000 <TMPL_VAR NAME="project_name"> API Help

      How This API Document Is Organized

      This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.

      Class

      Each class has its own separate page. Each of these pages has three sections consisting of a class description, summary tables, and detailed member descriptions:

      • Class inheritance diagram
      • Direct Subclasses
      • Class declaration
      • Class description

      • Field Summary
      • Constructor Summary
      • Method Summary

      • Field Detail
      • Constructor Detail
      • Method Detail
      Each summary entry contains the first sentence from the detailed description for that item.

      Index

      The Index contains an alphabetic list of all classes, constructors, methods, and fields.

      Prev/Next

      These links take you to the next or previous class, interface, package, or related page.

      Frames/No Frames

      These links show and hide the HTML frames. All pages are available with or without frames.

      This help file applies to API documentation generated using the standard doclet.



      Documentation generated by JSDoc on
      jsjac-1.3.4+dfsg/utils/JSDoc/index-all.tmpl000066400000000000000000000122311153725753300204170ustar00rootroot00000000000000 Index ()
       __">
      __">

      #"> - class ">
       

       __">

      Documentation generated by JSDoc on
      jsjac-1.3.4+dfsg/utils/JSDoc/index.tmpl000066400000000000000000000014051153725753300176520ustar00rootroot00000000000000 Generated Javascript Documentation " name="classFrame"> <H2> Frame Alert</H2> <P> This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. <BR> Link to <A HREF="allclasses-frame.html">Non-frame version.</A> jsjac-1.3.4+dfsg/utils/JSDoc/jsdoc.pl000077500000000000000000001521441153725753300173160ustar00rootroot00000000000000#!/usr/bin/perl -w # # This program makes use of the JSDoc module to make a JavaDoc equivalent # for JavaScript. The template that is used is based on the JavaDoc # doclet. This program only needs to be invoked with one or more # JS OO sourcefiles as command-line args. # use strict; use HTML::Template; use File::Copy; use File::Basename; use File::Path; use Getopt::Long; use File::Find; use lib dirname($0); use JSDoc; use JSDoc::XML; use JSDoc::XMI; use JavaScript::Syntax::HTML qw(to_html); use constant LOCATION => dirname($0) . '/'; use constant MAIN_TMPL => "main.tmpl"; use constant ALLCLASSES_TMPL => 'allclasses-frame.tmpl'; use constant ALLCLASSES_NOFRAME_TMPL => 'allclasses-noframe.tmpl'; use constant OVERVIEW_FRAME_TMPL => 'overview-frame.tmpl'; use constant TREE_TMPL => 'overview-tree.tmpl'; use constant OVERVIEW_TMPL => 'overview-summary.tmpl'; use constant INDEX_TMPL => 'index.tmpl'; use constant DEFAULT_DEST_DIR => 'js_docs_out/'; use constant STYLESHEET => 'stylesheet.css'; use constant HELP_TMPL => 'help-doc.tmpl'; use constant INDEX_ALL_TMPL => 'index-all.tmpl'; use constant CONSTANTS_TMPL => 'constant-values.tmpl'; use vars qw/ $CLASSES $DEFAULT_CLASSNAME @CLASSNAMES @INDEX %TMPL_CACHE %CLASS_ATTRS_MAP %METHOD_ATTRS_MAP %FILE_ATTRS_MAP %OPTIONS @FILENAMES %FILE_OVERVIEWS $TIME $CURRENT_CLASS /; # # Begin main execution # &parse_cmdline; &initialize_param_maps; $TIME = localtime(); do '.jsdoc_config'; warn "Error parsing config file: $@\n" if $@; my @sources; mkdir($OPTIONS{OUTPUT}) or die "Can't create output directory $OPTIONS{OUTPUT}: $!\n" unless (-e $OPTIONS{OUTPUT} && -d $OPTIONS{OUTPUT}); if (@ARGV < 1 || $OPTIONS{HELP} || !(@sources = &load_sources())){ warn "No sourcefiles supplied\n" if !$OPTIONS{HELP}; &show_usage(); exit(1); } # Parse the code tree &configure_parser( GLOBALS_NAME => $OPTIONS{GLOBALS_NAME}, NO_LEXICAL_PRIVATES => $OPTIONS{NO_LEXICAL_PRIVATES}); $CLASSES = &parse_code_tree(@sources); %FILE_OVERVIEWS = %{delete $CLASSES->{__FILES__}}; &map_implementation_classes(); die "Nothing to document, exiting\n" unless keys %{$CLASSES}; if ($OPTIONS{FORMAT} eq 'html'){ &output_html; } elsif ($OPTIONS{FORMAT} eq 'xml') { &output_xml; } elsif ($OPTIONS{FORMAT} eq 'xmi'){ &output_xmi; } else { die "Unknown data format '$OPTIONS{FORMAT}'\n"; } &_log('Completed generating documentation'); # # End main execution # sub map_implementation_classes { my (%implementations, %implementors); for my $class (keys %$CLASSES){ my $implements = $CLASSES->{$class}->{constructor_vars}->{implements}; if ($implements){ for my $iname (map {strip($_)} @$implements){ push @{$implementations{$class}}, $iname; push @{$implementors{$iname}}, $class; } } } sub add_method_to_subclasses { my ($cname, $method, $subclasses_of) = @_; $subclasses_of ||= $cname; for my $subclass (keys %$CLASSES){ if (($CLASSES->{$subclass}->{extends} || '') eq $subclasses_of){ if (not has_method($subclass, $method)){ my $inherits_hash = $CLASSES->{$subclass}->{inherits}; push @{$inherits_hash->{$cname}->{instance_methods}}, $method; add_method_to_subclasses($cname, $method, $subclass); } } } } sub get_instance_method { my ($classname, $methodname) = @_; my $class = $CLASSES->{$classname} or return undef; for my $method (@{$class->{instance_methods}}){ if ($method->{mapped_name} eq $methodname){ return $method; } } return undef; } # Copy the methods to the implementor for my $class (keys %implementations){ for my $interface (map {$CLASSES->{$_}} @{$implementations{$class}}){ my @interface_methods = @{$interface->{instance_methods} || []}; for my $superclass (keys %{$interface->{inherits} || {}}){ push @interface_methods, map { get_instance_method($superclass, $_) } @{$interface->{inherits}->{$superclass}-> {instance_methods}}; } for my $interface_method (@interface_methods){ if (not has_method($class, $interface_method->{mapped_name})){ push @{$CLASSES->{$class}->{instance_methods}}, $interface_method; add_method_to_subclasses($class, $interface_method->{mapped_name}); } } } } # Put a flag on interfaces to say who they're implemented by for my $interface (keys %implementors){ my $interface_class = $CLASSES->{$interface}; push @{$interface_class->{constructor_vars}->{implemented_by}}, $_ for @{$implementors{$interface}}; } } # # Output a single template # sub output_template { my ($tmplname, $outname, $params, $relaxed) = (@_); $OPTIONS{TEMPLATEDIR} =~ s/(\S+)\/$/$1/; $tmplname = $OPTIONS{TEMPLATEDIR} . "/$tmplname"; die "Template file '$tmplname' not found" unless -e $tmplname; # Caching templates seems to improve performance quite a lot if (!$TMPL_CACHE{$tmplname}){ $TMPL_CACHE{$tmplname} = new HTML::Template( die_on_bad_params => !$relaxed, filename => $tmplname); } my $tmpl = $TMPL_CACHE{$tmplname}; $tmpl->param($params); $outname = sprintf('%s%s', $OPTIONS{OUTPUT}, $outname); &print_file($outname, $tmpl->output); } # # Output data to a file # sub print_file { my ($fname, $data) = @_; open FILE, ">$fname" or die "Couldn't open '$fname' to write: $!\n"; print FILE $data; close FILE; } # # Output HTML documentation in the output directory # sub output_html { &set_file_paths(); &output_class_templates(); &output_index_template(); &output_aux_templates(); &output_tree_template(); } # # Output XMI in the output directory # sub output_xmi { my $xmi = JSDoc::XMI->new(LOCATION); &print_file("$OPTIONS{OUTPUT}/jsdoc.xmi", $xmi->output($CLASSES)); } # # Output XML in the output directory # sub output_xml { my $xml = JSDoc::XML->new(LOCATION); &print_file("$OPTIONS{OUTPUT}/jsdoc.xml", $xml->output($CLASSES)); } sub set_file_paths { for my $classname (keys %$CLASSES){ my $class = $CLASSES->{$classname}; my $filepath = $classname; $filepath =~ s/\./\//g; $filepath = "$filepath.html"; my $dirpath = dirname($filepath); $class->{filepath} = $filepath; $class->{dirpath} = $dirpath; my $fullpath = "$OPTIONS{OUTPUT}$dirpath"; mkpath($fullpath) unless -e $fullpath; $class->{ispackage} = @{$class->{inner_classes}} && not (@{$class->{instance_methods} || []} or @{$class->{instance_fields} || []}); } } # # Gather information for each class and output its template # sub output_class_templates { # Note the class name for later, including classes that aren't defined # but are used for inheritance my %seen; @CLASSNAMES = sort { lc $a->{classname} cmp lc $b->{classname}} grep { !$seen{$_->{classname}}++ } (map {classname => $_, classlink => link_to_class($_) } , grep { not defined $CLASSES->{$_}->{constructor_vars}->{private} or $OPTIONS{PRIVATE} } keys %$CLASSES), (map { classname => $_ }, grep { !defined($$CLASSES{$_}) } map { $_->{extends} } grep { defined($_->{extends}) } values %$CLASSES); die "Nothing to document, exiting\n" unless @CLASSNAMES; @FILENAMES = map {filename => $_, mangledfilename => mangle($_)}, sort {lc($a) cmp lc($b)} grep {length $_} keys %FILE_OVERVIEWS; for (my $i = 0; $i < @CLASSNAMES; $i++){ my $classname = $CLASSNAMES[$i]->{classname}; $CURRENT_CLASS = $classname; next unless $$CLASSES{$classname}; # Template Parameters my ($class, $subclasses, $class_summary, $constructor_params, $next_class, $prev_class, $constructor_attrs, $constructor_detail, $constructor_args); $class= $$CLASSES{$classname}; next unless is_class_linkable($classname); &add_to_index($class, $classname); # Set up the constructor and class information &resolve_synonyms($class->{constructor_vars}); &format_vars($class->{constructor_vars}); ($constructor_params, $constructor_args) = &fetch_args($class->{constructor_vars}, $class->{constructor_args}); $constructor_attrs = &format_method_attributes($class->{constructor_vars}); $constructor_detail = &resolve_inner_links($class->{constructor_detail}); $class_summary = &format_class_attributes($class->{constructor_vars}); $class_summary = &resolve_inner_links($class_summary); # Navbar information $next_class = $i + 1 < @CLASSNAMES ? link_to_class($CLASSNAMES[$i + 1]->{classname}, $classname) : undef; $prev_class = $i > 0 ? link_to_class($CLASSNAMES[$i - 1]->{classname}, $classname) : undef; my $superclass = $class->{extends} || ''; if ($superclass && $$CLASSES{$superclass}){ $superclass = make_link($superclass, $classname) unless (!$OPTIONS{PRIVATE} && $$CLASSES{$superclass}->{constructor_vars}->{private}); } my $file_overview = $class->{constructor_vars}->{filename} ? sprintf('overview-summary-%s.html', mangle($class->{constructor_vars}->{filename})) : ''; my @inner_classes = map { classname => $_->{class_name}, classlink => link_to_class($_->{class_name}, $classname) }, @{$class->{inner_classes} || []}; &output_template(MAIN_TMPL, $class->{filepath}, { path_to_base => path_to_base($classname), next_class => $next_class, prev_class => $prev_class, file_overview => $file_overview, superclass => $superclass, constructor_args => $constructor_args, constructor_params => $constructor_params, constructor_attrs => $constructor_attrs, constructor_returns => $class->{constructor_vars}->{returns}[0], class_summary => $class_summary, class_attribs => $class->{constructor_vars}->{private} ? '<private>' : '', constructor_detail => $constructor_detail, constructor_summary => &get_summary($constructor_detail), classname => $classname, hierarchy_meta => get_class_hierarchy_metadata($classname), class_tree => &build_class_tree($classname, $CLASSES), fields => &map_fields($class), methods => &map_methods($class), method_inheritance => &map_method_inheritance($class), field_inheritance => &map_field_inheritance($class), inner_classes => \@inner_classes, project_name => $OPTIONS{PROJECT_NAME}, page_footer => $OPTIONS{PAGE_FOOTER}, ctime => $TIME }, 1); } } # # Handle cleaning up / resolving inner links in FILE_OVERVIEWS # sub process_file_overviews { for my $filename (map{$_->{filename}} @FILENAMES){ my $overview = $FILE_OVERVIEWS{$filename}; my $src = $overview->{src}; $overview->{src} = ''; format_vars($overview); $overview = resolve_inner_links($FILE_OVERVIEWS{$filename}); $overview->{src} = $src; $FILE_OVERVIEWS{$filename} = $overview; } } # # Output all the non-class template files # sub output_aux_templates(){ unless ($OPTIONS{LOGO} and -f $OPTIONS{LOGO} and -r $OPTIONS{LOGO}){ $OPTIONS{LOGO} and warn "Can't read $OPTIONS{LOGO}"; $OPTIONS{LOGO} = ''; } $OPTIONS{LOGO} and copy $OPTIONS{LOGO}, $OPTIONS{OUTPUT}; &process_file_overviews; $DEFAULT_CLASSNAME = (grep { is_class_linkable($_->{classname}) } @CLASSNAMES)[0]->{classname}; my $summary = &get_overall_summary; &output_classes_frames_templates; &output_multiple_files_templates if (@FILENAMES > 1 || $OPTIONS{PACKAGENAMING}); &output_index_and_help_templates($summary); &output_overview_summaries($summary); &output_const_summary(); my $stylesheet = LOCATION . STYLESHEET; if ($OPTIONS{TEMPLATEDIR} ne LOCATION){ $stylesheet = $OPTIONS{TEMPLATEDIR} . '/' . STYLESHEET; die "Stylesheet '$stylesheet' not found" unless -e $stylesheet; } copy ($stylesheet, $OPTIONS{OUTPUT} . STYLESHEET); } sub get_overall_summary { my $summary; if ($OPTIONS{PROJECT_SUMMARY}){ if (-f $OPTIONS{PROJECT_SUMMARY} and open SUMMARY, $OPTIONS{PROJECT_SUMMARY}){ local $/ = undef; $summary = ; close SUMMARY; } else { warn "Can't open $OPTIONS{PROJECT_SUMMARY}"; } } elsif (@FILENAMES == 1) { # If we only have one file and it has an overview, use that overview my $filename = $FILENAMES[0]->{filename}; if ($FILE_OVERVIEWS{$filename}->{fileoverview}){ $summary = $FILE_OVERVIEWS{$filename}->{fileoverview}[0]; $summary .= "

      "; while (my ($name, $val) = each %{$FILE_OVERVIEWS{$filename}}){ $summary .= &{$FILE_ATTRS_MAP{$name}}($val) if $FILE_ATTRS_MAP{$name}; } } } $summary; } # # Output the main (default) page and the help template # sub output_index_and_help_templates { my ($summary) = @_; my $numpackages = scalar(grep {$_->{ispackage}} values %$CLASSES); # Output the main index template &output_template(INDEX_TMPL, 'index.html', { DEFAULT_CLASSNAME => @FILENAMES > 1 ? 'overview-summary.html' : link_to_class($DEFAULT_CLASSNAME), multifile => (@FILENAMES > 1 || ($numpackages && $OPTIONS{PACKAGENAMING}))}); # Output the help document template &output_template(HELP_TMPL, 'help-doc.html', { page_footer => $OPTIONS{PAGE_FOOTER}, ctime => $TIME, project_name => $OPTIONS{PROJECT_NAME} }); } # # Output the frames listing all the classes # sub output_classes_frames_templates { my @classnames = grep { is_class_linkable($_->{classname}) } @CLASSNAMES; if ($OPTIONS{PACKAGENAMING}){ @classnames = grep { !($CLASSES->{$_->{classname}}->{ispackage}) } @classnames; } my $params = { filename => 'All Classes', fname_link => 'All Classes', CLASSNAMES => \@classnames }; if (@FILENAMES < 2 && !$OPTIONS{PACKAGENAMING}){ $params->{project_name} = $OPTIONS{PROJECT_NAME}; $params->{logo} = basename($OPTIONS{LOGO}); } &output_template(ALLCLASSES_TMPL, 'allclasses-frame.html', $params); &output_template(ALLCLASSES_NOFRAME_TMPL, 'allclasses-noframe.html', { CLASSNAMES => \@classnames, project_name => $OPTIONS{PROJECT_NAME}, logo => basename($OPTIONS{LOGO}) }); } # # Output the overview summary templates # sub output_overview_summaries { my ($summary) = @_; my @overviews = map { name => $_, link => &mangle("overview-summary-$_.html"), overview => get_summary( $FILE_OVERVIEWS{$_}{fileoverview}[0] || ' ') }, sort {lc($a) cmp lc($b)} keys(%FILE_OVERVIEWS); &output_template(OVERVIEW_TMPL, 'overview-summary.html', { generic => 1, project_name => $OPTIONS{PROJECT_NAME}, project_title => $OPTIONS{PROJECT_NAME}, page_footer => $OPTIONS{PAGE_FOOTER}, ctime => $TIME, project_summary => $summary, is_file_summary => 0, overviews => \@overviews }); for my $filename (keys %FILE_OVERVIEWS){ my @classes = grep { ($$CLASSES{$_}->{constructor_vars}->{filename} || '') eq $filename } keys %$CLASSES; my @class_overviews = sort { lc($a->{name}) cmp lc($b->{name}) } map { name => $_, link => link_to_class($_), overview => get_summary( $CLASSES->{$_}->{constructor_vars}->{class}[0] || ' ') }, grep { !$CLASSES->{$_}->{constructor_vars}->{private} || $OPTIONS{PRIVATE} } @classes; my %overview = %{$FILE_OVERVIEWS{$filename}}; my $src = delete $overview{src}; my $summary = $overview{fileoverview}[0] || "No overview generated for '$filename'"; $summary .= "

      "; while (my ($name, $val) = each %overview){ $summary .= &{$FILE_ATTRS_MAP{$name}}($val) if $FILE_ATTRS_MAP{$name}; } my @methods = map { is_private => $_->{is_private}, method_summary => $_->{method_summary}, is_class_method => $_->{is_class_method}, method_anchor => sprintf('%s%s', $_->{is_class_method} ? '!s!' : '', $_->{method_name}), method_arguments=> $_->{method_arguments}, method_name => $_->{method_name}, type => $_->{type}, file_link => $OPTIONS{GLOBALS_NAME} . ".html" }, @{&map_methods($$CLASSES{$OPTIONS{GLOBALS_NAME}}, $filename)}; &output_template(OVERVIEW_TMPL, "overview-summary-$filename.html", { generic => 0, sourcecode => $OPTIONS{NO_SRC} ? '' : &to_html($src), project_name => $OPTIONS{PROJECT_NAME}, project_title => $filename, page_footer => $OPTIONS{PAGE_FOOTER}, ctime => $TIME, project_summary => $summary, is_file_summary => 1, methods => \@methods, overviews => \@class_overviews }); } } # # Output a summary page about the 'static constant' field values for all # classes # sub output_const_summary { my @static_params; for my $classname (sort { uc($a) cmp uc($b) } keys %$CLASSES){ my $class = $CLASSES->{$classname}; my @statics = grep { $_->{field_value} =~ /^(?:\d+)|(?:(['"]).*\1)$/} grep { $_->{field_vars}->{final}} @{$class->{class_fields}}; if (@statics){ push @static_params, { classname => $classname, static_values => [map { name => $_->{field_name}, value => $_->{field_value}, classname => $classname}, @statics] }; } } &output_template(CONSTANTS_TMPL, 'constant-values.html', { project_name => $OPTIONS{PROJECT_NAME}, page_footer => $OPTIONS{PAGE_FOOTER}, ctime => $TIME, classnames => [map {name => $_->{classname}}, @static_params], static_finals => \@static_params } ) if @static_params; } # # Method to handle outputting file overview template if # more than one sourcefile is being processed # sub output_multiple_files_templates { my %params = ( logo => basename($OPTIONS{LOGO}), project_name => $OPTIONS{PROJECT_NAME}); if ($OPTIONS{PACKAGENAMING}){ my @packagenames = sort { $a->{filename} cmp $b->{filename} } map { filelink => "overview-$_->{classname}.html", filename => $_->{classname} }, grep { $_->{ispackage} } values %$CLASSES; $params{filenames} = \@packagenames; $params{heading} = "Packages"; } else { my @filenames = map { filelink => "overview-$_->{mangledfilename}.html", filename => $_->{filename} }, @FILENAMES; $params{filenames} = \@filenames; $params{heading} = "Files"; } &output_template(OVERVIEW_FRAME_TMPL, 'overview-frame.html', \%params); if (!$OPTIONS{PACKAGENAMING}){ for my $fname (map { $_->{filename}} @FILENAMES){ my @classes = grep { ($$CLASSES{$_}->{constructor_vars}->{filename} || '') eq $fname } keys %$CLASSES; #methods under GLOBAL (detached) class my @methods; for (my $i = 0; $i < @CLASSNAMES; $i++){ if($CLASSNAMES[$i]->{classname} eq $OPTIONS{GLOBALS_NAME}){ my $class = $$CLASSES{$CLASSNAMES[$i]->{classname}}; for my $method ( sort {lc $a->{mapped_name} cmp lc $b->{mapped_name} } @{$class->{class_methods}}){ if(defined($fname) && $fname eq $method->{vars}->{filename}){ $method->{filename} = $fname; push(@methods, $method); } } last; } } &output_template(ALLCLASSES_TMPL, sprintf('overview-%s.html', $fname), { filename => $fname, fname_link => $FILE_OVERVIEWS{$fname} ? sprintf( '%s', mangle($fname), $fname) : $fname, CLASSNAMES => [map { classname => $_, classlink => link_to_class($_) }, grep { !$$CLASSES{$_}->{constructor_vars}->{private} || $OPTIONS{PRIVATE} } sort @classes] }); } } if ($OPTIONS{PACKAGENAMING}){ my @packages = grep { $_->{ispackage} } values %$CLASSES; for my $package (@packages){ my $name = $package->{classname}; my %params = ( filename => $name, fname_link => sprintf( '%s', link_to_class($name), $name)); my @inner_classes = sort { $a->{classname} cmp $b->{classname}} map { classname => $_, classlink => link_to_class($_) }, map { $_->{class_name} } @{$package->{inner_classes}}; $params{CLASSNAMES} = \@inner_classes; output_template(ALLCLASSES_TMPL, "overview-$name.html", \%params); } } } # # Mangle a file path so that it can be used as a filename # sub mangle { my $input = shift; local $_ = $input; tr{/\\}{_}; die if $input ne $_; $_; } # # Build the tree representation of the inheritance # PARAM: Name of the class # sub build_class_tree { my $classname = shift; my $class = $$CLASSES{$classname}; my $tree = ""; my @family; push @family, $classname; while ($class->{extends} and $class->{extends} ne ""){ my $base = $class->{extends}; if ($$CLASSES{$base} and is_class_linkable($base)){ $base = sprintf("$base", link_to_class($base, $classname)) unless (!$OPTIONS{PRIVATE} && $$CLASSES{$base}->{constructor_vars}->{private}); } elsif ($class->{constructor_vars}->{base}){ if (my ($bcname, $url) = $class->{constructor_vars}->{base}->[0] =~ /^(\S+)\s(\S.*)$/){ $base = "$base"; } } push @family, $base; $class = $$CLASSES{$class->{extends}}; } push @family, "Object"; my $indent = 3; $tree = (pop @family) . "\n"; my $name = $_; while ($name = pop (@family)){ my $instr = " " x $indent; $tree .= sprintf "%s|\n%s+--%s%s%s\n", $instr, $instr, $name eq $classname ? "" : "", $name, $name eq $classname ? "" : ""; $indent += 6; } $tree; } # # Shown if no commandline args are given # sub show_usage(){ print qq{Usage: jsdoc [OPTIONS] + -h | --help Show this message and exit -r | --recursive Recurse through given directories -p | --private Show private methods and fields -d | --directory Specify output directory (defaults to js_docs_out) -q | --quiet Suppress normal output --page-footer Specify (html) footer string that will be added to all docs --project-name Specify project name for that will be added to docs --logo Specify a path to a logo to be used in the docs --project-summary Specify a path to a text file that contains an overview summary of the project --no-sources Don't include the source code view --extensions Provide a comma-separated list of file extensions to be considered as JavaScript source files --nested-file-naming Use package-style naming (i.e. keep directory names in the file path). This is useful if you have multiple files with the same name, but in different directories. This option is only useful if --recursive is also used. --globals-name Specify a 'class name' under which all unattached methods will be classified. The defaults to GLOBALS --format Set the output format. The options are html, xml and xmi, defaulting to html. The others are currently alpha software. --template-dir Provide another directory containing HTML templates --no-lexical-privates Ignore "private" variables and functions that are lexically defined within constructors --package-naming Use packages, with a package being defined as a class that only contains nested classes and possibly static members. \n}; } # # Take all the command line args as filenames and add them to @SOURCESFILES # sub load_sources(){ my (@filenames, @sources); my $ext_re = sprintf('%s', join '|', split /\s*,\s*/, $OPTIONS{EXTENSIONS}); for my $arg (@ARGV){ if (-d $arg) { $arg =~ s/(.*[^\/])$/$1\//; find( { wanted => sub { push @filenames, { name => $_, relname => $OPTIONS{NESTEDFILENAMING} ? substr($_, length($arg)) : (fileparse($_))[0] } if ((-f and -r and /.+\.$ext_re$/oi) && (/^\Q$arg\E[^\/]+$/ || $OPTIONS{RECURSIVE})) }, no_chdir => 1 }, $arg); } elsif (-f $arg){ my $relname = (fileparse($arg))[0]; push @filenames, { name => $arg, relname => $relname }; } } for (@filenames){ &_log(sprintf 'Loading sources from %s', $_->{name}); open SRC, '<', $_->{name} or (warn sprintf("Can't open %s, skipping: $!\n", $_->{name}) and next); local $/ = undef; push @sources, $_->{relname}; push @sources, \; close SRC; } @sources; } # # Once all sources have been parsed, finds all subclasses # of $classname # sub find_subclasses { my ($classname) = @_; my @subclasses; for my $class (keys %$CLASSES){ my $subclassname = $$CLASSES{$class}->{extends}; if ($$CLASSES{$class}->{extends} and $$CLASSES{$class}->{extends} eq $classname){ push @subclasses, $class; } } \@subclasses; } # # Make a summary of a description, cutting it off either at the first # double newline or the first period followed by whitespace. # PARAM: $description # sub get_summary { my ($description) = @_; my $summary; if ($description){ ($summary) = $description =~ /^(.*?(?:[?!.](?=\s)|\n\n)).*$/gs or $summary = $description; } else { $summary = ""; } $summary; } # # Set up all the instance and class methods for one template # PARAM: A reference to a class # PARAM: Optional filename, only maps methods for that file (used for GLOBAL) # sub map_methods{ my ($class, $fname) = @_; my @methods; for my $mtype (qw(instance_methods class_methods)){ next unless $class->{$mtype}; for my $method ( sort {lc $a->{mapped_name} cmp lc $b->{mapped_name} } @{$class->{$mtype}}){ next if $fname && $fname ne $method->{vars}->{filename}; &resolve_synonyms($method->{vars}); next if (!$OPTIONS{PRIVATE} && $method->{vars}->{private}); $method->{vars}->{returns}[0] = $method->{vars}->{returns}[0] || $method->{vars}->{return}; my ($args, $arglist) = &fetch_args($method->{vars}, $method->{argument_list}); $args = [map { &format_vars($_); $_ } @{$args}]; &format_vars($method->{vars}); my $desc = &resolve_inner_links($method->{description}); my $type = &map_return_type($method); my $ret = $method->{vars}->{returns}[0]; my $attrs = &format_method_attributes($method->{vars}); push @methods, { method_description => $desc, method_summary => &get_summary($desc), method_name => $method->{mapped_name}, method_arguments => $arglist, method_params => $args, method_returns => $ret, is_class_method => $mtype eq 'class_methods', is_private => defined($method->{vars}->{private}), attributes => $attrs, type => $type }; } } return \@methods; } # # Map a function return type # sub map_return_type { my ($method) = @_; #return 'Object' unless $method->{vars}->{type}[0]; my $name = 'Object'; my $link = ''; if (defined($method->{vars}->{type})){ $name = $method->{vars}->{type}[0]; } elsif (defined($method->{vars}->{returns}[0])){ if ($method->{vars}->{returns}[0] =~ s/\s*\{(\S+)(?:\s+([^}]+))?\}//){ $name = $1; $link = $2; } $method->{vars}->{type} = [$name]; } $name =~ s/^\s*(\S.*?)\s*$/$1/; if ($$CLASSES{$name} || $link){ $link ||= link_to_class($name, $CURRENT_CLASS); return qq|$name|; } $name; } # # Set up all the instance and class methods for one template # PARAM: A reference to a class # sub map_fields { my $class = shift; my @fields; # Set up the instance fields for my $type (qw(instance_fields class_fields)){ next unless $class->{$type}; for (sort {lc $a->{field_name} cmp lc $b->{field_name} } @{$class->{$type}}){ &resolve_synonyms($_->{field_vars}); next if (!$OPTIONS{PRIVATE} && $_->{field_vars}->{private}); my $description = &resolve_inner_links($_->{field_description}); my $const_link = ($_->{field_vars}->{final} && ($_->{field_value} =~ /^\-?\d+(\.\d+)?$/ || $_->{field_value} =~ /^(["']).*\1$/)) ? $class->{classname} : ''; push @fields, { field_name => $_->{field_name}, field_description => $description, field_summary => &get_summary($description), is_final => defined($_->{field_vars}->{final}), is_private => defined($_->{field_vars}->{private}), is_class_field => $type eq 'class_fields', type => &map_field_type($_), const_link => $const_link}; } } \@fields; } # # Map a field type # sub map_field_type { my ($field) = @_; return 'Object' unless $field->{field_vars}->{type}[0]; my $name = $field->{field_vars}->{type}[0]; $name =~ s/^\s*(\S.*?)\s*$/$1/; return sprintf('%s', link_to_class($name, $CURRENT_CLASS), $name) if $$CLASSES{$name}; $name; } # # Map all the inherited methods to a template parameter # PARAM: A reference to a class # sub map_method_inheritance { my $class = shift; my @method_inheritance; # Set up the inherited methods if ($class->{inherits}){ my $superclassname = $class->{extends}; my $superclass = $$CLASSES{$superclassname}; while ($superclass){ if (!$superclass->{constructor_vars}->{private} || $OPTIONS{PRIVATE}){ my $methods = $class->{inherits}->{$superclassname}->{instance_methods}; push @method_inheritance, { superclass_name => $superclassname, superclass_link => link_to_class( $superclassname, $class->{classname}), inherited_methods => join(', ', map(sprintf("%s", link_to_class( $superclassname, $class->{classname}), $_, $_), &filter_private_methods( $methods, $superclassname)))} if ($methods and @$methods); } $superclassname = $superclass->{extends}; $superclass = $superclassname ? $$CLASSES{$superclassname} : undef; } } \@method_inheritance; } # # Map all the inherited fields to a template parameter # PARAM: A reference to a class # sub map_field_inheritance { my $class = shift; my @field_inheritance; # Set up the inherited fields if ($class->{inherits}){ my $superclassname = $class->{extends}; my $superclass = $$CLASSES{$superclassname}; while ($superclass){ if (!$superclass->{constructor_vars}->{private} || $OPTIONS{PRIVATE}){ my $fields = $class->{inherits}->{$superclassname}->{instance_fields}; push @field_inheritance, { superclass_name => $superclassname, superclass_link => link_to_class( $superclassname, $class->{classname}), inherited_fields => join(', ', map(sprintf("%s", link_to_class( $superclassname, $class->{classname}), $_, $_), &filter_private_fields($fields, $superclassname)))} if ($fields and @$fields); } $superclassname = $superclass->{extends}; $superclass = $superclassname ? $$CLASSES{$superclassname} : undef; } } \@field_inheritance; } # # Filter out private inherited methods # sub filter_private_methods { my ($methods, $superclassname) = @_; my @visible_methods; for my $method(@$methods){ for my $super_method (@{$$CLASSES{$superclassname}->{instance_methods}}){ push @visible_methods, $method if $method eq $super_method->{mapped_name} and (!$super_method->{vars}->{private} || $OPTIONS{PRIVATE}); } } @visible_methods; } # # Filter out private inherited fields # sub filter_private_fields { my ($fields, $superclassname) = @_; my @visible_fields; for my $field (@$fields){ for my $super_field(@{$$CLASSES{$superclassname}->{instance_fields}}){ push @visible_fields, $field if $field eq $super_field->{field_name} and (!$super_field->{field_vars}->{private} || $OPTIONS{PRIVATE}); } } @visible_fields; } # # Builds up the listing of subclasses, implemented interfaces, and # who implements this interface # sub get_class_hierarchy_metadata { my ($classname) = @_; my $class = $CLASSES->{$classname}; my @meta; # Find all the direct subclasses my $subclasses = join(', ', map { make_link($_, $classname) } @{&find_subclasses($classname)}); if ($subclasses){ push @meta, { title => 'Direct Known Subclasses', data => $subclasses }; } my $implemented_interfaces = join(', ', map { make_link($_, $classname) } @{$class->{constructor_vars}->{implements} || []}); if ($implemented_interfaces){ push @meta, { title => 'All Implemented Interfaces', data => $implemented_interfaces }; } my $implemented_by = join(', ', map { make_link($_, $classname) } @{$class->{constructor_vars}->{implemented_by} || []}); if ($implemented_by){ push @meta, { title => 'All Known Implementing Classes', data => $implemented_by }; } return \@meta; } # # Adds a class's information to the global INDEX list # sub add_to_index { my ($class, $classname) = @_; push @INDEX, { name => $classname, class => $classname, classlink => link_to_class($classname), type => '', linkname => '' }; if (!$class->{constructor_args}){ $class->{constructor_args} = ''; } else { push @INDEX, { name => "$classname$class->{constructor_args}", class => $classname, classlink => link_to_class($classname), type => 'Constructor in ', linkname => 'constructor_detail' }; } for my $mtype (qw(class_methods instance_methods)){ my $type = sprintf('%s method in ', $mtype eq 'class_methods' ? 'Class' : 'Instance'); push @INDEX, { name => "$_->{mapped_name}$_->{argument_list}", class => $classname, classlink => link_to_class($classname), type => $type, linkname => $_->{mapped_name}} for grep { not($_->{vars}->{private} and not $OPTIONS{PRIVATE}) } @{$class->{$mtype}}; } for my $ftype (qw(class_fields instance_fields)){ my $type = sprintf('%s field in ', $ftype eq 'class_fields' ? 'Class' : 'Instance'); push @INDEX, { name => $_->{field_name}, class => $classname, classlink => link_to_class($classname), type => $type, linkname => $_->{field_name}} for grep { not($_->{field_vars}->{private} and not $OPTIONS{PRIVATE}) } @{$class->{$ftype}}; } } # # Outputs the index page # sub output_index_template { @INDEX = sort {lc $a->{name} cmp lc $b->{name}} @INDEX; my %letters; for my $item (@INDEX){ my $letter = uc(substr($item->{name}, 0, 1)); $letter = uc(substr($item->{class}, 0, 1)) if $letter eq ''; push @{$letters{$letter}}, $item; } my $letter_list = [map {letter_name => $_}, sort {lc $a cmp lc $b} keys %letters]; &output_template(INDEX_ALL_TMPL, 'index-all.html', { letters => $letter_list, project_name => $OPTIONS{PROJECT_NAME}, page_footer => $OPTIONS{PAGE_FOOTER}, ctime => $TIME, index_list => [map { letter => $_->{letter_name}, value => $letters{$_->{letter_name}} }, @{$letter_list}] }); } sub is_class_linkable { my ($cname) = @_; my $ret_val = defined($$CLASSES{$cname}) && $$CLASSES{$cname}->{filepath}; $ret_val ||= 0; return $ret_val; } # # Recursively builds up the overview tree # sub build_tree { my $parentclassname = shift || ''; my $ret = ""; for my $cname (map {$_->{classname}} @CLASSNAMES) { next if $cname eq $OPTIONS{GLOBALS_NAME}; my $class = $$CLASSES{$cname}; my $parent = $class->{extends} || '-'; if ((!$parentclassname && $parent eq '-') or ($parent eq $parentclassname)) { $ret .= is_class_linkable($cname) ? sprintf(qq{
    • %s
    • }, make_link($cname)) : qq{
    • $cname
    • }; my $childrentree .= &build_tree($cname); $ret = "$ret$childrentree" if $childrentree; } } $ret = "
        $ret
      " unless not $ret; if ($parentclassname eq ''){ $ret = qq{
      • Object
      • $ret
      }; } $ret; } # # Outputs the overview tree # sub output_tree_template { my $tree = &build_tree(); &output_template(TREE_TMPL, 'overview-tree.html', { classtrees => $tree, project_name => $OPTIONS{PROJECT_NAME}, page_footer => $OPTIONS{PAGE_FOOTER}, ctime => $TIME }, 1); } # # Formats additional non-standard attributes for methods according to user # configuration # sub format_method_attributes { my ($attrs) = shift; my $attributes = ''; while (my ($name, $val) = each %{$attrs}) { $attributes .= &{$METHOD_ATTRS_MAP{$name}}($val) if $METHOD_ATTRS_MAP{$name}; } $attributes; } # # Formats additional non-standard attributes for classes according to user # configuration # sub format_class_attributes { my ($attrs) = shift; my $attributes; if ($attrs->{class} && @{ $attrs->{class} }){ $attributes = sprintf('
      %s
      ', $attrs->{class}[0] || '') } while (my ($name, $val) = each %{$attrs}) { $attributes .= &{$CLASS_ATTRS_MAP{$name}}($val) if $CLASS_ATTRS_MAP{$name}; } $attributes; } # # Parses the command line options # sub parse_cmdline { $OPTIONS{OUTPUT} = DEFAULT_DEST_DIR; $OPTIONS{PROJECT_NAME} = ''; $OPTIONS{COPYRIGHT} = ''; $OPTIONS{PROJECT_SUMMARY} = ''; $OPTIONS{LOGO} = ''; $OPTIONS{GLOBALS_NAME} = 'GLOBALS'; $OPTIONS{FORMAT} = 'html'; $OPTIONS{EXTENSIONS} = 'js'; $OPTIONS{TEMPLATEDIR} = LOCATION; GetOptions( 'private|p' => \$OPTIONS{PRIVATE}, 'directory|d=s' => \$OPTIONS{OUTPUT}, 'help|h' => \$OPTIONS{HELP}, 'recursive|r' => \$OPTIONS{RECURSIVE}, 'page-footer=s' => \$OPTIONS{PAGE_FOOTER}, 'project-name=s' => \$OPTIONS{PROJECT_NAME}, 'project-summary=s' => \$OPTIONS{PROJECT_SUMMARY}, 'logo=s' => \$OPTIONS{LOGO}, 'globals-name=s' => \$OPTIONS{GLOBALS_NAME}, 'quiet|q' => \$OPTIONS{QUIET}, 'no-sources' => \$OPTIONS{NO_SRC}, 'nested-file-naming' => \$OPTIONS{NESTEDFILENAMING}, 'format=s' => \$OPTIONS{FORMAT}, 'extensions=s' => \$OPTIONS{EXTENSIONS}, 'no-lexical-privates' => \$OPTIONS{NO_LEXICAL_PRIVATES}, 'template-dir=s' => \$OPTIONS{TEMPLATEDIR}, 'package-naming' => \$OPTIONS{PACKAGENAMING}); $OPTIONS{OUTPUT} =~ s/([^\/])$/$1\//; } # # Resolves links for {@link } items # sub resolve_inner_links { my $doc = shift; $doc =~ s{\{\@link\s+([^\}]+)\}}{&format_link($1)}eg if $doc; return $doc; } sub link_to_class { my ($toclass, $fromclass) = @_; $fromclass ||= ''; $toclass = strip($toclass); $fromclass = strip($fromclass); $toclass = $CLASSES->{$toclass}->{filepath}; $fromclass = $CLASSES->{$fromclass}->{filepath} if $fromclass; my $fromslashes = ($fromclass =~ tr/\///); my $link = ('../' x $fromslashes); $link .= $toclass if $toclass; return $link; } sub make_link { my ($toclass, $fromclass) = @_; if (is_class_linkable($toclass)){ my $link = link_to_class($toclass, $fromclass); return "$toclass"; } return $toclass; } sub path_to_base { my ($fromclass) = @_; $fromclass = $CLASSES->{$fromclass}->{filepath}; my $fromslashes = ($fromclass =~ tr/\///); my $path = '../' x $fromslashes; return $path; } # # Formats a {@link } item # sub format_link { my ($link) = shift; die unless $CURRENT_CLASS; $link = strip($link); $link =~ s/<[^>]*>//g; my ($class, $method, $label, $url); my $class_re = qr/\w+(?:\.\w+)*/; unless ((($class, $method, $label) = $link =~ /^($class_re)?#($class_re)\s*(.*)$/) or (($class, $label) = $link =~ /^($class_re)(?:\s+(.*))?$/)){ if (($url, $label) = $link =~ /^(https?:\/\/\S+)\s+(.*?)\s*$/){ return "$label"; } else { return $link; } } if ($class){ unless ($$CLASSES{$class}){ warn "\@link can't find reference $class\n"; return $link; } } my $classlink = ($class && defined($$CLASSES{$class})) ? link_to_class($class, $CURRENT_CLASS) : ''; if (!$method){ $label = $class unless $label; qq{$label}; } else { my $clss = $CLASSES->{$class || $CURRENT_CLASS}; my @methods = (@{$clss->{instance_methods}}, @{$clss->{class_methods}}); my @fields = (@{$clss->{instance_fields}}, @{$clss->{class_fields}}); my @statics = (@{$clss->{class_methods}}, @{$clss->{class_fields}}); my $ismethod = grep { $_->{mapped_name} eq $method } @methods; my $isfield = grep { $_->{field_name} eq $method } @fields unless $ismethod; my $isstatic = grep { ($_->{field_name} || $_->{mapped_name}) eq $method } @statics; if ($class){ $label = "$class.$method" . ($ismethod ? '()' : '') unless $label; if ($ismethod or $isfield){ $method = ($isstatic ? "!s!" : "") . $method; return qq{$label}; } else { warn "\@link can't find reference $method in $class\n"; return $link; } } else { $label = $method . ($ismethod ? "()" : "") unless $label; $method = ($isstatic ? "!s!" : "") . $method; return qq{$label}; } } } # # Initializes the customizable maps for @attributes # sub initialize_param_maps { %CLASS_ATTRS_MAP = ( author => sub { 'Author: ' . join(', ', @{$_[0]}) . "
      " }, deprecated => sub { 'Deprecated ' . ($_[0] ? $_[0]->[0] : '') . "

      "; }, see => sub { 'See:
        - ' . join('
        - ', map {&format_link($_)} @{$_[0]}) . "
      " }, version => sub { 'Version: ' . join(', ', @{$_[0]}) . '

      ' }, requires => sub { 'Requires:
        - ' . join('
        - ', map {&format_link($_)} @{$_[0]}) . "
      " }, filename => sub { sprintf 'Defined in %s

      ', sprintf("%s", path_to_base($CURRENT_CLASS),mangle($_[0]), $_[0]); }, overviewfile => sub { my ($content, $fh) = ""; my $fname = $_[0][0] or return ''; unless(open $fh, "$fname"){ warn "Can't open overview file '$fname' : $!\n"; return ''; } { local $/ = undef; $content .= <$fh> } close $fh or warn "Couldn't close overview file '$fname'\n"; # Crude manner to strip out extra HTML $content =~ s/(.*)<\/body>/$1/si; "$content
      "; } ); %METHOD_ATTRS_MAP = ( throws => sub { "Throws:
        - " . join("
        - ", @{$_[0]}) . "
      " }, ); $METHOD_ATTRS_MAP{exception} = $METHOD_ATTRS_MAP{throws}; $METHOD_ATTRS_MAP{$_} = $CLASS_ATTRS_MAP{$_} for qw(author version deprecated see requires); $FILE_ATTRS_MAP{$_} = $CLASS_ATTRS_MAP{$_} for qw(author version see requires); } # # Parse the @param or @argument values into name/value pairs and # return the list of them # sub fetch_args { my ($vars, $arg_list) = @_; return ([], $arg_list) unless $vars and $arg_list; my (@args, %used); for my $arg (split /\W+(?{param}}){ my ($type, $link, $name, $value) = /(?: \{\s* (\S+) # type name (?:\s+(\S+)\s*)? # optional link \})? \s* (\$?\w+) # parameter name (.*) # description /x; next unless $name eq $arg; $used{$name} = 1; $type ||= ''; if ($$CLASSES{$type} || $link){ $link ||= $type; if ($CLASSES->{$link}){ $type = sprintf('%s', link_to_class($link, $CURRENT_CLASS), $type); } else { $type = sprintf('%s', "$link.html", $type); } } my $type_regex = qr{\Q$arg\E\b}; $arg_list =~ s/(? $name, vardescrip => $value}; } } for (@{$vars->{param}}){ my ($type, $link, $name, $value) = /(?:\{\s*(\S+)(?:\s+(\S+)\s*)?\})?\s*(\$?\w+)(.*)/; next if $used{$name}; push @args, { varname => $name, vardescrip => $value }; } return (\@args, $arg_list); } sub resolve_synonyms { my ($item) = @_; $item->{param} = $item->{param} || $item->{argument}; $item->{returns} = $item->{return} || $item->{returns}; $item->{final} = $item->{final} || $item->{const}; } # # Log a message to STDOUT if the --quiet switch is not used # sub _log { print $_[0], "\n" unless $OPTIONS{QUIET}; } # # Takes a vars hash and resolves {@link}s within it # sub format_vars { my ($vars) = @_; for my $key (keys %$vars){ if (ref($vars->{$key}) eq 'ARRAY'){ for (0..$#{$vars->{$key}}){ $vars->{$key}->[$_] = &resolve_inner_links($vars->{$key}->[$_]); } } else { $vars->{$key} = &resolve_inner_links($vars->{$key}); } } } # # Util methods # sub strip { my ($value) = @_; return $value unless $value; $value =~ s/^\s*(.*?)\s*$/$1/; return $value; } sub has_method { my ($classname, $mname) = @_; my $class = $CLASSES->{$classname}; for my $method (@{$class->{instance_methods}}){ if ($method->{mapped_name} eq $mname){ return 1; } } return 0; } jsjac-1.3.4+dfsg/utils/JSDoc/main.tmpl000066400000000000000000000402301153725753300174660ustar00rootroot00000000000000 <TMPL_VAR name="classname"> stylesheet.css" TITLE="Style">

      Class

      :

       class
      extends


      Nested Class Summary
      <static class> ">
       
      Field Summary
      <private> <static>  <final>  !s!">
                
       
       
      Fields inherited from class ">
       
      Constructor Summary
      ()">
                 
       
      Method Summary
      <static> <private>   !s!">
                
       
      Methods inherited from class ">
       

      Field Detail
      !s!
      ">

      <private> <static> <final>  

      Constructor Detail
      ()">

        Parameters:
          -
        Returns:

      Method Detail
      !s!
      ">

      <static>  <private>  
        Parameters:
          -
        Returns:


      Documentation generated by JSDoc on
      jsjac-1.3.4+dfsg/utils/JSDoc/overview-frame.tmpl000066400000000000000000000017761153725753300215140ustar00rootroot00000000000000 Overview () "/>

      All Classes


      " TARGET="packageFrame">

        jsjac-1.3.4+dfsg/utils/JSDoc/overview-summary.tmpl000066400000000000000000000162541153725753300221140ustar00rootroot00000000000000 <tmpl_var name="project_name"> Overview


      JSDoc Documentation

      This document is the API Specification for .

      Summary

      No summary generated for these documents.


      Class Summary File Summary
      ">

      Method Summary
      static private   #">
                



      Documentation generated by JSDoc on
      jsjac-1.3.4+dfsg/utils/JSDoc/overview-tree.tmpl000066400000000000000000000105401153725753300213460ustar00rootroot00000000000000 <TMPL_VAR name="project_name"> Class Hierarchy

      Class Hierarchy



      Documentation generated by JSDoc on
      jsjac-1.3.4+dfsg/utils/JSDoc/stylesheet.css000066400000000000000000000030571153725753300205550ustar00rootroot00000000000000/* JSDoc style sheet */ /* Define colors, fonts and other style attributes here to override the defaults */ /* Page background color */ body { background-color: #FFFFFF } /* Table colors */ .TableHeadingColor { background: #CCCCFF } /* Dark mauve */ .TableSubHeadingColor { background: #EEEEFF } /* Light mauve */ .TableRowColor { background: #FFFFFF } /* White */ /* Font used in left-hand frame lists */ .FrameTitleFont { font-size: 10pt; font-family: Helvetica, Arial, san-serif } .FrameHeadingFont { font-size: 10pt; font-family: Helvetica, Arial, san-serif } .FrameItemFont { font-size: 10pt; font-family: Helvetica, Arial, san-serif } /* Example of smaller, sans-serif font in frames */ /* .FrameItemFont { font-size: 10pt; font-family: Helvetica, Arial, sans-serif } */ /* Navigation bar fonts and colors */ .NavBarCell1 { background-color:#EEEEFF;}/* Light mauve */ .NavBarCell1Rev { background-color:#00008B;}/* Dark Blue */ .NavBarFont1 { font-family: Arial, Helvetica, sans-serif; color:#000000;} .NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; color:#FFFFFF;} .NavBarCell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;} .NavBarCell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;} .jsdoc_ctime { font-family: Arial, Helvetica, sans-serif; font-size: 9pt; text-align: right } /* Sourcecode view */ .sourceview { background: #FFFFFF } .attrib { color: #DD7777 } .comment { color: #55AA55 } .reserved { color: #FF5555 } .literal { color: #5555FF } jsjac-1.3.4+dfsg/utils/JSDoc/test.js000066400000000000000000000250541153725753300171700ustar00rootroot00000000000000/** * @fileoverview This file is to be used for testing the JSDoc parser * It is not intended to be an example of good JavaScript OO-programming, * nor is it intended to fulfill any specific purpose apart from * demonstrating the functionality of the * {@link http://sourceforge.net/projects/jsdoc JSDoc} parser * * @author Gabriel Reid gab_reid@users.sourceforge.net * @version 0.1 */ /** * Construct a new Shape object. * @class This is the basic Shape class. * It can be considered an abstract class, even though no such thing * really existing in JavaScript * @constructor * @throws MemoryException if there is no more memory * @throws GeneralShapeException rarely (if ever) * @return A new shape */ function Shape(){ /** * This is an example of a function that is not given as a property * of a prototype, but instead it is assigned within a constructor. * For inner functions like this to be picked up by the parser, the * function that acts as a constructor must be denoted with * the @constructor tag in its comment. * @type String */ this.getClassName = function(){ return "Shape"; } /** * This is a private method, just used here as an example */ function addReference(){ // Do nothing... } } /** * Create a new Hexagon instance. * @extends Shape * @class Hexagon is a class that is a logical sublcass of * {@link Shape} (thanks to the @extends tag), but in * reality it is completely unrelated to Shape. * @param {int} sideLength The length of one side for the new Hexagon */ function Hexagon(sideLength) { } /** * This is an unattached (static) function that adds two integers together. * @param {int} One The first number to add * @param {int http://jsdoc.sourceforge.net/} Two The second number to add * @author Gabriel Reid * @deprecated So you shouldn't use it anymore! */ function Add(One, Two){ return One + Two; } /** * The color of this shape * @type Color */ Shape.prototype.color = null; /** * The border of this shape. * @type int */ Shape.prototype.border = null; /* * The assignment of function implementations for Shape, documentation will * be taken over from the method declaration. */ Shape.prototype.getCoords = Shape_GetCoords; Shape.prototype.getColor = Shape_GetColor; Shape.prototype.setCoords = Shape_SetCoords; Shape.prototype.setColor = Shape_SetColor; /* * These are all the instance method implementations for Shape */ /** * Get the coordinates of this shape. It is assumed that we're always talking * about shapes in a 2D location here. * @requires Shape The shape class * @returns A Coordinate object representing the location of this Shape * @type Coordinate */ function Shape_GetCoords(){ return this.coords; } /** * Get the color of this shape. * @see #setColor * @type Color */ function Shape_GetColor(){ return this.color; } /** * Set the coordinates for this Shape * @param {Coordinate} coordinates The coordinates to set for this Shape */ function Shape_SetCoords(coordinates){ this.coords = coordinates; } /** * Set the color for this Shape * @param {Color} color The color to set for this Shape * @param other There is no other param, but it can still be documented if * optional parameters are used * @throws NonExistantColorException (no, not really!) * @see #getColor */ function Shape_SetColor(color){ this.color = color; } /** * Clone this shape * @returns A copy of this shape * @type Shape * @author Gabriel Reid */ Shape.prototype.clone = function(){ return new Shape(); } /** * Create a new Rectangle instance. * @class A basic rectangle class, inherits from Shape. * This class could be considered a concrete implementation class * @constructor * @param {int} width The optional width for this Rectangle * @param {int} height Thie optional height for this Rectangle * @author Gabriel Reid * @see Shape Shape is the base class for this */ function Rectangle(width, // This is the width height // This is the height ){ if (width){ this.width = width; if (height){ this.height = height; } } } /* Inherit from Shape */ Rectangle.prototype = new Shape(); /** * Value to represent the width of the Rectangle. *
      Text in bold and italic and a * link to SourceForge * @private * @type int */ Rectangle.prototype.width = 0; /** * Value to represent the height of the Rectangle * @private * @type int */ Rectangle.prototype.height = 0; /** * Get the type of this object. * @type String */ Rectangle.prototype.getClassName= function(){ return "Rectangle"; } /* * These are all the instance method implementations for Rectangle */ Rectangle.prototype.getWidth = Rectangle_GetWidth; Rectangle.prototype.getHeight = Rectangle_GetHeight; Rectangle.prototype.setWidth = Rectangle_SetWidth; Rectangle.prototype.setHeight = Rectangle_SetHeight; Rectangle.prototype.getArea = Rectangle_GetArea; /** * Get the value of the width for the Rectangle * @type int * @see #setWidth */ function Rectangle_GetWidth(){ return this.width; } /** * Get the value of the height for the Rectangle. * Another getter is the {@link Shape#getColor} method in the * {@link Shape base Shape class}. * @return The height of this Rectangle * @type int * @see #setHeight */ function Rectangle_GetHeight(){ return this.height; } /** * Set the width value for this Rectangle. * @param {int} width The width value to be set * @see #getWidth */ function Rectangle_SetWidth(width){ this.width = width; } /** * Set the height value for this Rectangle. * @param {int} height The height value to be set * @see #getHeight */ function Rectangle_SetHeight(height){ this.height = height; } /** * Get the value for the total area of this Rectangle * @return total area of this Rectangle * @type int */ function Rectangle_GetArea(){ return width * height; } /** * Create a new Square instance. * @class A Square is a subclass of {@link Rectangle} * @param {int} width The optional width for this Rectangle * @param {int} height The optional height for this Rectangle */ function Square(width, height){ if (width){ this.width = width; if (height){ this.height = height; } } } /* Square is a subclass of Rectangle */ Square.prototype = new Rectangle(); /* * The assignment of function implementation for Shape. */ Square.prototype.setWidth = Square_SetWidth; Square.prototype.setHeight = Square_SetHeight; /** * Set the width value for this Square. * @param {int} width The width value to be set * @see #getWidth */ function Square_SetWidth(width){ this.width = this.height = width; } /** * Set the height value for this Square * Sets the {@link Rectangle#height height} attribute in the Rectangle. * @param {int} height The height value to be set */ function Square_SetHeight(height){ this.height = this.width = height; } /** * Create a new Circle instance based on a radius. * @class Circle class is another subclass of Shape * @param {int} radius The optional radius of this Circle */ function Circle(radius){ if (radius){ this.radius = radius; } } /* Circle inherits from Shape */ Circle.prototype = new Shape(); /** * The radius value for this Circle * @private * @type int */ Circle.prototype.radius = 0; /** * A very simple class (static) field that is also a constant * @final * @type float */ Circle.PI = 3.14; Circle.createCircle = Circle_CreateCircle; Circle.prototype.getRadius = Circle_GetRadius; Circle.prototype.setRadius = Circle_SetRadius; /** * Get the radius value for this Circle * @type int * @see #setRadius */ function Circle_GetRadius(){ return this.radius; } /** * Set the radius value for this Circle * @param {int} radius The radius value to set * @see #getRadius */ function Circle_SetRadius(radius){ this.radius = radius; } /** * An example of a class (static) method that acts as a factory for Circle * objects. Given a radius value, this method creates a new Circle. * @param {int} radius The radius value to use for the new Circle. * @type Circle */ function Circle_CreateCircle(radius){ return new Circle(radius); } /** * Create a new Coordinate instance based on x and y grid data. * @class Coordinate is a class that can encapsulate location information. * @param {int} x The optional x portion of the Coordinate * @param {int} y The optinal y portion of the Coordinate */ function Coordinate(x, y){ if (x){ this.x = x; if (y){ this.y = y; } } } /** * The x portion of the Coordinate * @type int * @see #getX * @see #setX */ Coordinate.prototype.x = 0; /** * The y portion of the Coordinate * @type int * @see #getY * @see #setY */ Coordinate.prototype.y = 0; Coordinate.prototype.getX = Coordinate_GetX; Coordinate.prototype.getY = Coordinate_GetY; Coordinate.prototype.setX = Coordinate_SetX; Coordinate.prototype.setY = Coordinate_SetY; /** * Gets the x portion of the Coordinate. * @type int * @see #setX */ function Coordinate_GetX(){ return this.x; } /** * Get the y portion of the Coordinate. * @type int * @see #setY */ function Coordinate_GetY(){ return this.y; } /** * Sets the x portion of the Coordinate. * @param {int} x The x value to set * @see #getX */ function Coordinate_SetX(x){ this.x = x; } /** * Sets the y portion of the Coordinate. * @param {int} y The y value to set * @see #getY */ function Coordinate_SetY(y){ this.y = y; } /** * @class This class exists to demonstrate the assignment of a class prototype * as an anonymous block. */ function ShapeFactory(){ } ShapeFactory.prototype = { /** * Creates a new {@link Shape} instance. * @return A new {@link Shape} * @type Shape */ createShape: function(){ return new Shape(); } } /** * An example of a singleton class */ MySingletonShapeFactory = new function(){ /** * Get the next {@link Shape} * @type Shape * @return A new {@link Shape} */ this.getShape = function(){ return null; } } /** * Create a new Foo instance. * @class This is the Foo class. It exists to demonstrate 'nested' classes. * @constructor * @see Foo.Bar */ function Foo(){} /** * Creates a new instance of Bar. * @class This class exists to demonstrate 'nested' classes. * @constructor * @see Foo.Bar */ function Bar(){} /** * Nested class * @constructor */ Foo.Bar = function(){this.x = 2;} Foo.Bar.prototype = new Bar(); Foo.Bar.prototype.y = '3'; jsjac-1.3.4+dfsg/utils/packer/000077500000000000000000000000001153725753300161505ustar00rootroot00000000000000jsjac-1.3.4+dfsg/utils/packer/class.JavaScriptPacker.php000066400000000000000000000556751153725753300232030ustar00rootroot00000000000000pack(); * * or * * $myPacker = new JavaScriptPacker($script, 'Normal', true, false); * $packed = $myPacker->pack(); * * or (default values) * * $myPacker = new JavaScriptPacker($script); * $packed = $myPacker->pack(); * * * params of the constructor : * $script: the JavaScript to pack, string. * $encoding: level of encoding, int or string : * 0,10,62,95 or 'None', 'Numeric', 'Normal', 'High ASCII'. * default: 62. * $fastDecode: include the fast decoder in the packed result, boolean. * default : true. * $specialChars: if you are flagged your private and local variables * in the script, boolean. * default: false. * * The pack() method return the compressed JavasScript, as a string. * * see http://dean.edwards.name/packer/usage/ for more information. * * Notes : * # need PHP 5 . Tested with PHP 5.1.2 * * # The packed result may be different than with the Dean Edwards * version, but with the same length. The reason is that the PHP * function usort to sort array don't necessarily preserve the * original order of two equal member. The Javascript sort function * in fact preserve this order (but that's not require by the * ECMAScript standard). So the encoded keywords order can be * different in the two results. * * # Be careful with the 'High ASCII' Level encoding if you use * UTF-8 in your files... */ class JavaScriptPacker { // constants const IGNORE = '$1'; // validate parameters private $_script = ''; private $_encoding = 62; private $_fastDecode = true; private $_specialChars = false; private $LITERAL_ENCODING = array( 'None' => 0, 'Numeric' => 10, 'Normal' => 62, 'High ASCII' => 95 ); public function __construct($_script, $_encoding = 62, $_fastDecode = true, $_specialChars = false) { $this->_script = $_script . "\n"; if (array_key_exists($_encoding, $this->LITERAL_ENCODING)) $_encoding = $this->LITERAL_ENCODING[$_encoding]; $this->_encoding = min((int)$_encoding, 95); $this->_fastDecode = $_fastDecode; $this->_specialChars = $_specialChars; } public function pack() { $this->_addParser('_basicCompression'); if ($this->_specialChars) $this->_addParser('_encodeSpecialChars'); if ($this->_encoding) $this->_addParser('_encodeKeywords'); // go! return $this->_pack($this->_script); } // apply all parsing routines private function _pack($script) { for ($i = 0; isset($this->_parsers[$i]); $i++) { $script = call_user_func(array(&$this,$this->_parsers[$i]), $script); } return $script; } // keep a list of parsing functions, they'll be executed all at once private $_parsers = array(); private function _addParser($parser) { $this->_parsers[] = $parser; } // zero encoding - just removal of white space and comments private function _basicCompression($script) { $parser = new ParseMaster(); // make safe $parser->escapeChar = '\\'; // protect strings $parser->add('/\'[^\'\\n\\r]*\'/', self::IGNORE); $parser->add('/"[^"\\n\\r]*"/', self::IGNORE); // remove comments $parser->add('/\\/\\/[^\\n\\r]*[\\n\\r]/', ' '); $parser->add('/\\/\\*[^*]*\\*+([^\\/][^*]*\\*+)*\\//', ' '); // protect regular expressions $parser->add('/\\s+(\\/[^\\/\\n\\r\\*][^\\/\\n\\r]*\\/g?i?)/', '$2'); // IGNORE $parser->add('/[^\\w\\x24\\/\'"*)\\?:]\\/[^\\/\\n\\r\\*][^\\/\\n\\r]*\\/g?i?/', self::IGNORE); // remove: ;;; doSomething(); if ($this->_specialChars) $parser->add('/;;;[^\\n\\r]+[\\n\\r]/'); // remove redundant semi-colons $parser->add('/\\(;;\\)/', self::IGNORE); // protect for (;;) loops $parser->add('/;+\\s*([};])/', '$2'); // apply the above $script = $parser->exec($script); // remove white-space $parser->add('/(\\b|\\x24)\\s+(\\b|\\x24)/', '$2 $3'); $parser->add('/([+\\-])\\s+([+\\-])/', '$2 $3'); $parser->add('/\\s+/', ''); // done return $parser->exec($script); } private function _encodeSpecialChars($script) { $parser = new ParseMaster(); // replace: $name -> n, $$name -> na $parser->add('/((\\x24+)([a-zA-Z$_]+))(\\d*)/', array('fn' => '_replace_name') ); // replace: _name -> _0, double-underscore (__name) is ignored $regexp = '/\\b_[A-Za-z\\d]\\w*/'; // build the word list $keywords = $this->_analyze($script, $regexp, '_encodePrivate'); // quick ref $encoded = $keywords['encoded']; $parser->add($regexp, array( 'fn' => '_replace_encoded', 'data' => $encoded ) ); return $parser->exec($script); } private function _encodeKeywords($script) { // escape high-ascii values already in the script (i.e. in strings) if ($this->_encoding > 62) $script = $this->_escape95($script); // create the parser $parser = new ParseMaster(); $encode = $this->_getEncoder($this->_encoding); // for high-ascii, don't encode single character low-ascii $regexp = ($this->_encoding > 62) ? '/\\w\\w+/' : '/\\w+/'; // build the word list $keywords = $this->_analyze($script, $regexp, $encode); $encoded = $keywords['encoded']; // encode $parser->add($regexp, array( 'fn' => '_replace_encoded', 'data' => $encoded ) ); if (empty($script)) return $script; else { //$res = $parser->exec($script); //$res = $this->_bootStrap($res, $keywords); //return $res; return $this->_bootStrap($parser->exec($script), $keywords); } } private function _analyze($script, $regexp, $encode) { // analyse // retreive all words in the script $all = array(); preg_match_all($regexp, $script, $all); $_sorted = array(); // list of words sorted by frequency $_encoded = array(); // dictionary of word->encoding $_protected = array(); // instances of "protected" words $all = $all[0]; // simulate the javascript comportement of global match if (!empty($all)) { $unsorted = array(); // same list, not sorted $protected = array(); // "protected" words (dictionary of word->"word") $value = array(); // dictionary of charCode->encoding (eg. 256->ff) $this->_count = array(); // word->count $i = count($all); $j = 0; //$word = null; // count the occurrences - used for sorting later do { --$i; $word = '$' . $all[$i]; if (!isset($this->_count[$word])) { $this->_count[$word] = 0; $unsorted[$j] = $word; // make a dictionary of all of the protected words in this script // these are words that might be mistaken for encoding //if (is_string($encode) && method_exists($this, $encode)) $values[$j] = call_user_func(array(&$this, $encode), $j); $protected['$' . $values[$j]] = $j++; } // increment the word counter $this->_count[$word]++; } while ($i > 0); // prepare to sort the word list, first we must protect // words that are also used as codes. we assign them a code // equivalent to the word itself. // e.g. if "do" falls within our encoding range // then we store keywords["do"] = "do"; // this avoids problems when decoding $i = count($unsorted); do { $word = $unsorted[--$i]; if (isset($protected[$word]) /*!= null*/) { $_sorted[$protected[$word]] = substr($word, 1); $_protected[$protected[$word]] = true; $this->_count[$word] = 0; } } while ($i); // sort the words by frequency // Note: the javascript and php version of sort can be different : // in php manual, usort : // " If two members compare as equal, // their order in the sorted array is undefined." // so the final packed script is different of the Dean's javascript version // but equivalent. // the ECMAscript standard does not guarantee this behaviour, // and thus not all browsers (e.g. Mozilla versions dating back to at // least 2003) respect this. usort($unsorted, array(&$this, '_sortWords')); $j = 0; // because there are "protected" words in the list // we must add the sorted words around them do { if (!isset($_sorted[$i])) $_sorted[$i] = substr($unsorted[$j++], 1); $_encoded[$_sorted[$i]] = $values[$i]; } while (++$i < count($unsorted)); } return array( 'sorted' => $_sorted, 'encoded' => $_encoded, 'protected' => $_protected); } private $_count = array(); private function _sortWords($match1, $match2) { return $this->_count[$match2] - $this->_count[$match1]; } // build the boot function used for loading and decoding private function _bootStrap($packed, $keywords) { $ENCODE = $this->_safeRegExp('$encode\\($count\\)'); // $packed: the packed script $packed = "'" . $this->_escape($packed) . "'"; // $ascii: base for encoding $ascii = min(count($keywords['sorted']), $this->_encoding); if ($ascii == 0) $ascii = 1; // $count: number of words contained in the script $count = count($keywords['sorted']); // $keywords: list of words contained in the script foreach ($keywords['protected'] as $i=>$value) { $keywords['sorted'][$i] = ''; } // convert from a string to an array ksort($keywords['sorted']); $keywords = "'" . implode('|',$keywords['sorted']) . "'.split('|')"; $encode = ($this->_encoding > 62) ? '_encode95' : $this->_getEncoder($ascii); $encode = $this->_getJSFunction($encode); $encode = preg_replace('/_encoding/','$ascii', $encode); $encode = preg_replace('/arguments\\.callee/','$encode', $encode); $inline = '\\$count' . ($ascii > 10 ? '.toString(\\$ascii)' : ''); // $decode: code snippet to speed up decoding if ($this->_fastDecode) { // create the decoder $decode = $this->_getJSFunction('_decodeBody'); if ($this->_encoding > 62) $decode = preg_replace('/\\\\w/', '[\\xa1-\\xff]', $decode); // perform the encoding inline for lower ascii values elseif ($ascii < 36) $decode = preg_replace($ENCODE, $inline, $decode); // special case: when $count==0 there are no keywords. I want to keep // the basic shape of the unpacking funcion so i'll frig the code... if ($count == 0) $decode = preg_replace($this->_safeRegExp('($count)\\s*=\\s*1'), '$1=0', $decode, 1); } // boot function $unpack = $this->_getJSFunction('_unpack'); if ($this->_fastDecode) { // insert the decoder $this->buffer = $decode; $unpack = preg_replace_callback('/\\{/', array(&$this, '_insertFastDecode'), $unpack, 1); } $unpack = preg_replace('/"/', "'", $unpack); if ($this->_encoding > 62) { // high-ascii // get rid of the word-boundaries for regexp matches $unpack = preg_replace('/\'\\\\\\\\b\'\s*\\+|\\+\s*\'\\\\\\\\b\'/', '', $unpack); } if ($ascii > 36 || $this->_encoding > 62 || $this->_fastDecode) { // insert the encode function $this->buffer = $encode; $unpack = preg_replace_callback('/\\{/', array(&$this, '_insertFastEncode'), $unpack, 1); } else { // perform the encoding inline $unpack = preg_replace($ENCODE, $inline, $unpack); } // pack the boot function too $unpackPacker = new JavaScriptPacker($unpack, 0, false, true); $unpack = $unpackPacker->pack(); // arguments $params = array($packed, $ascii, $count, $keywords); if ($this->_fastDecode) { $params[] = 0; $params[] = '{}'; } $params = implode(',', $params); // the whole thing return 'eval(' . $unpack . '(' . $params . "))\n"; } private $buffer; private function _insertFastDecode($match) { return '{' . $this->buffer . ';'; } private function _insertFastEncode($match) { return '{$encode=' . $this->buffer . ';'; } // mmm.. ..which one do i need ?? private function _getEncoder($ascii) { return $ascii > 10 ? $ascii > 36 ? $ascii > 62 ? '_encode95' : '_encode62' : '_encode36' : '_encode10'; } // zero encoding // characters: 0123456789 private function _encode10($charCode) { return $charCode; } // inherent base36 support // characters: 0123456789abcdefghijklmnopqrstuvwxyz private function _encode36($charCode) { return base_convert($charCode, 10, 36); } // hitch a ride on base36 and add the upper case alpha characters // characters: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ private function _encode62($charCode) { $res = ''; if ($charCode >= $this->_encoding) { $res = $this->_encode62((int)($charCode / $this->_encoding)); } $charCode = $charCode % $this->_encoding; if ($charCode > 35) return $res . chr($charCode + 29); else return $res . base_convert($charCode, 10, 36); } // use high-ascii values // characters: ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþ private function _encode95($charCode) { $res = ''; if ($charCode >= $this->_encoding) $res = $this->_encode95($charCode / $this->_encoding); return $res . chr(($charCode % $this->_encoding) + 161); } private function _safeRegExp($string) { return '/'.preg_replace('/\$/', '\\\$', $string).'/'; } private function _encodePrivate($charCode) { return "_" . $charCode; } // protect characters used by the parser private function _escape($script) { return preg_replace('/([\\\\\'])/', '\\\$1', $script); } // protect high-ascii characters already in the script private function _escape95($script) { return preg_replace_callback( '/[\\xa1-\\xff]/', array(&$this, '_escape95Bis'), $script ); } private function _escape95Bis($match) { return '\x'.((string)dechex(ord($match))); } private function _getJSFunction($aName) { if (defined('self::JSFUNCTION'.$aName)) return constant('self::JSFUNCTION'.$aName); else return ''; } // JavaScript Functions used. // Note : In Dean's version, these functions are converted // with 'String(aFunctionName);'. // This internal conversion complete the original code, ex : // 'while (aBool) anAction();' is converted to // 'while (aBool) { anAction(); }'. // The JavaScript functions below are corrected. // unpacking function - this is the boot strap function // data extracted from this packing routine is passed to // this function when decoded in the target // NOTE ! : without the ';' final. const JSFUNCTION_unpack = 'function($packed, $ascii, $count, $keywords, $encode, $decode) { while ($count--) { if ($keywords[$count]) { $packed = $packed.replace(new RegExp(\'\\\\b\' + $encode($count) + \'\\\\b\', \'g\'), $keywords[$count]); } } return $packed; }'; /* 'function($packed, $ascii, $count, $keywords, $encode, $decode) { while ($count--) if ($keywords[$count]) $packed = $packed.replace(new RegExp(\'\\\\b\' + $encode($count) + \'\\\\b\', \'g\'), $keywords[$count]); return $packed; }'; */ // code-snippet inserted into the unpacker to speed up decoding const JSFUNCTION_decodeBody = //_decode = function() { // does the browser support String.replace where the // replacement value is a function? ' if (!\'\'.replace(/^/, String)) { // decode all the values we need while ($count--) { $decode[$encode($count)] = $keywords[$count] || $encode($count); } // global replacement function $keywords = [function ($encoded) {return $decode[$encoded]}]; // generic match $encode = function () {return \'\\\\w+\'}; // reset the loop counter - we are now doing a global replace $count = 1; } '; //}; /* ' if (!\'\'.replace(/^/, String)) { // decode all the values we need while ($count--) $decode[$encode($count)] = $keywords[$count] || $encode($count); // global replacement function $keywords = [function ($encoded) {return $decode[$encoded]}]; // generic match $encode = function () {return\'\\\\w+\'}; // reset the loop counter - we are now doing a global replace $count = 1; }'; */ // zero encoding // characters: 0123456789 const JSFUNCTION_encode10 = 'function($charCode) { return $charCode; }';//;'; // inherent base36 support // characters: 0123456789abcdefghijklmnopqrstuvwxyz const JSFUNCTION_encode36 = 'function($charCode) { return $charCode.toString(36); }';//;'; // hitch a ride on base36 and add the upper case alpha characters // characters: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ const JSFUNCTION_encode62 = 'function($charCode) { return ($charCode < _encoding ? \'\' : arguments.callee(parseInt($charCode / _encoding))) + (($charCode = $charCode % _encoding) > 35 ? String.fromCharCode($charCode + 29) : $charCode.toString(36)); }'; // use high-ascii values // characters: ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþ const JSFUNCTION_encode95 = 'function($charCode) { return ($charCode < _encoding ? \'\' : arguments.callee($charCode / _encoding)) + String.fromCharCode($charCode % _encoding + 161); }'; } class ParseMaster { public $ignoreCase = false; public $escapeChar = ''; // constants const EXPRESSION = 0; const REPLACEMENT = 1; const LENGTH = 2; // used to determine nesting levels private $GROUPS = '/\\(/';//g private $SUB_REPLACE = '/\\$\\d/'; private $INDEXED = '/^\\$\\d+$/'; private $TRIM = '/([\'"])\\1\\.(.*)\\.\\1\\1$/'; private $ESCAPE = '/\\\./';//g private $QUOTE = '/\'/'; private $DELETED = '/\\x01[^\\x01]*\\x01/';//g public function add($expression, $replacement = '') { // count the number of sub-expressions // - add one because each pattern is itself a sub-expression $length = 1 + preg_match_all($this->GROUPS, $this->_internalEscape((string)$expression), $out); // treat only strings $replacement if (is_string($replacement)) { // does the pattern deal with sub-expressions? if (preg_match($this->SUB_REPLACE, $replacement)) { // a simple lookup? (e.g. "$2") if (preg_match($this->INDEXED, $replacement)) { // store the index (used for fast retrieval of matched strings) $replacement = (int)(substr($replacement, 1)) - 1; } else { // a complicated lookup (e.g. "Hello $2 $1") // build a function to do the lookup $quote = preg_match($this->QUOTE, $this->_internalEscape($replacement)) ? '"' : "'"; $replacement = array( 'fn' => '_backReferences', 'data' => array( 'replacement' => $replacement, 'length' => $length, 'quote' => $quote ) ); } } } // pass the modified arguments if (!empty($expression)) $this->_add($expression, $replacement, $length); else $this->_add('/^$/', $replacement, $length); } public function exec($string) { // execute the global replacement $this->_escaped = array(); // simulate the _patterns.toSTring of Dean $regexp = '/'; foreach ($this->_patterns as $reg) { $regexp .= '(' . substr($reg[self::EXPRESSION], 1, -1) . ')|'; } $regexp = substr($regexp, 0, -1) . '/'; $regexp .= ($this->ignoreCase) ? 'i' : ''; $string = $this->_escape($string, $this->escapeChar); $string = preg_replace_callback( $regexp, array( &$this, '_replacement' ), $string ); $string = $this->_unescape($string, $this->escapeChar); return preg_replace($this->DELETED, '', $string); } public function reset() { // clear the patterns collection so that this object may be re-used $this->_patterns = array(); } // private private $_escaped = array(); // escaped characters private $_patterns = array(); // patterns stored by index // create and add a new pattern to the patterns collection private function _add() { $arguments = func_get_args(); $this->_patterns[] = $arguments; } // this is the global replace function (it's quite complicated) private function _replacement($arguments) { if (empty($arguments)) return ''; $i = 1; $j = 0; // loop through the patterns while (isset($this->_patterns[$j])) { $pattern = $this->_patterns[$j++]; // do we have a result? if (isset($arguments[$i]) && ($arguments[$i] != '')) { $replacement = $pattern[self::REPLACEMENT]; if (is_array($replacement) && isset($replacement['fn'])) { if (isset($replacement['data'])) $this->buffer = $replacement['data']; return call_user_func(array(&$this, $replacement['fn']), $arguments, $i); } elseif (is_int($replacement)) { return $arguments[$replacement + $i]; } $delete = ($this->escapeChar == '' || strpos($arguments[$i], $this->escapeChar) === false) ? '' : "\x01" . $arguments[$i] . "\x01"; return $delete . $replacement; // skip over references to sub-expressions } else { $i += $pattern[self::LENGTH]; } } } private function _backReferences($match, $offset) { $replacement = $this->buffer['replacement']; $quote = $this->buffer['quote']; $i = $this->buffer['length']; while ($i) { $replacement = str_replace('$'.$i--, $match[$offset + $i], $replacement); } return $replacement; } private function _replace_name($match, $offset){ $length = strlen($match[$offset + 2]); $start = $length - max($length - strlen($match[$offset + 3]), 0); return substr($match[$offset + 1], $start, $length) . $match[$offset + 4]; } private function _replace_encoded($match, $offset) { return $this->buffer[$match[$offset]]; } // php : we cannot pass additional data to preg_replace_callback, // and we cannot use &$this in create_function, so let's go to lower level private $buffer; // encode escaped characters private function _escape($string, $escapeChar) { if ($escapeChar) { $this->buffer = $escapeChar; return preg_replace_callback( '/\\' . $escapeChar . '(.)' .'/', array(&$this, '_escapeBis'), $string ); } else { return $string; } } private function _escapeBis($match) { $this->_escaped[] = $match[1]; return $this->buffer; } // decode escaped characters private function _unescape($string, $escapeChar) { if ($escapeChar) { $regexp = '/'.'\\'.$escapeChar.'/'; $this->buffer = array('escapeChar'=> $escapeChar, 'i' => 0); return preg_replace_callback ( $regexp, array(&$this, '_unescapeBis'), $string ); } else { return $string; } } private function _unescapeBis() { if (!empty($this->_escaped[$this->buffer['i']])) { $temp = $this->_escaped[$this->buffer['i']]; } else { $temp = ''; } $this->buffer['i']++; return $this->buffer['escapeChar'] . $temp; } private function _internalEscape($string) { return preg_replace($this->ESCAPE, '', $string); } } ?> jsjac-1.3.4+dfsg/utils/packer/class.JavaScriptPacker.php4000066400000000000000000000551701153725753300232550ustar00rootroot00000000000000pack(); * * or * * $myPacker = new JavaScriptPacker($script, 'Normal', true, false); * $packed = $myPacker->pack(); * * or (default values) * * $myPacker = new JavaScriptPacker($script); * $packed = $myPacker->pack(); * * * params of the constructor : * $script: the JavaScript to pack, string. * $encoding: level of encoding, int or string : * 0,10,62,95 or 'None', 'Numeric', 'Normal', 'High ASCII'. * default: 62. * $fastDecode: include the fast decoder in the packed result, boolean. * default : true. * $specialChars: if you are flagged your private and local variables * in the script, boolean. * default: false. * * The pack() method return the compressed JavasScript, as a string. * * see http://dean.edwards.name/packer/usage/ for more information. * * Notes : * # [del]need PHP 5 . Tested with PHP 5.1.2[/del] * this is a modified version for PHP 4 * * # The packed result may be different than with the Dean Edwards * version, but with the same length. The reason is that the PHP * function usort to sort array don't necessarily preserve the * original order of two equal member. The Javascript sort function * in fact preserve this order (but that's not require by the * ECMAScript standard). So the encoded keywords order can be * different in the two results. * * # Be careful with the 'High ASCII' Level encoding if you use * UTF-8 in your files... */ /* * modified by Mark Fabrizio Jr. to work with php 4 */ class JavaScriptPacker { var $IGNORE = '$1'; // validate parameters var $_script = ''; var $_encoding = 62; var $_fastDecode = true; var $_specialChars = false; var $LITERAL_ENCODING = array( 'None' => 0, 'Numeric' => 10, 'Normal' => 62, 'High ASCII' => 95 ); function JavaScriptPacker($_script, $_encoding = 62, $_fastDecode = true, $_specialChars = false) { $this->_script = $_script . "\n"; if (array_key_exists($_encoding, $this->LITERAL_ENCODING)) $_encoding = $this->LITERAL_ENCODING[$_encoding]; $this->_encoding = min((int)$_encoding, 95); $this->_fastDecode = $_fastDecode; $this->_specialChars = $_specialChars; } function pack() { $this->_addParser('_basicCompression'); if ($this->_specialChars) $this->_addParser('_encodeSpecialChars'); if ($this->_encoding) $this->_addParser('_encodeKeywords'); // go! return $this->_pack($this->_script); } // apply all parsing routines function _pack($script) { for ($i = 0; isset($this->_parsers[$i]); $i++) { $script = call_user_func(array(&$this,$this->_parsers[$i]), $script); } return $script; } // keep a list of parsing functions, they'll be executed all at once var $_parsers = array(); function _addParser($parser) { $this->_parsers[] = $parser; } // zero encoding - just removal of white space and comments function _basicCompression($script) { $parser = new ParseMaster(); // make safe $parser->escapeChar = '\\'; // protect strings $parser->add('/\'[^\'\\n\\r]*\'/',$this->IGNORE); $parser->add('/"[^"\\n\\r]*"/', $this->IGNORE); // remove comments $parser->add('/\\/\\/[^\\n\\r]*[\\n\\r]/', ' '); $parser->add('/\\/\\*[^*]*\\*+([^\\/][^*]*\\*+)*\\//', ' '); // protect regular expressions $parser->add('/\\s+(\\/[^\\/\\n\\r\\*][^\\/\\n\\r]*\\/g?i?)/', '$2'); // IGNORE $parser->add('/[^\\w\\x24\\/\'"*)\\?:]\\/[^\\/\\n\\r\\*][^\\/\\n\\r]*\\/g?i?/', $this->IGNORE); // remove: ;;; doSomething(); if ($this->_specialChars) $parser->add('/;;;[^\\n\\r]+[\\n\\r]/'); // remove redundant semi-colons $parser->add('/\\(;;\\)/', $this->IGNORE); // protect for (;;) loops $parser->add('/;+\\s*([};])/', '$2'); // apply the above $script = $parser->exec($script); // remove white-space $parser->add('/(\\b|\\x24)\\s+(\\b|\\x24)/', '$2 $3'); $parser->add('/([+\\-])\\s+([+\\-])/', '$2 $3'); $parser->add('/\\s+/', ''); // done return $parser->exec($script); } function _encodeSpecialChars($script) { $parser = new ParseMaster(); // replace: $name -> n, $$name -> na $parser->add('/((\\x24+)([a-zA-Z$_]+))(\\d*)/', array('fn' => '_replace_name') ); // replace: _name -> _0, double-underscore (__name) is ignored $regexp = '/\\b_[A-Za-z\\d]\\w*/'; // build the word list $keywords = $this->_analyze($script, $regexp, '_encodePrivate'); // quick ref $encoded = $keywords['encoded']; $parser->add($regexp, array( 'fn' => '_replace_encoded', 'data' => $encoded ) ); return $parser->exec($script); } function _encodeKeywords($script) { // escape high-ascii values already in the script (i.e. in strings) if ($this->_encoding > 62) $script = $this->_escape95($script); // create the parser $parser = new ParseMaster(); $encode = $this->_getEncoder($this->_encoding); // for high-ascii, don't encode single character low-ascii $regexp = ($this->_encoding > 62) ? '/\\w\\w+/' : '/\\w+/'; // build the word list $keywords = $this->_analyze($script, $regexp, $encode); $encoded = $keywords['encoded']; // encode $parser->add($regexp, array( 'fn' => '_replace_encoded', 'data' => $encoded ) ); if (empty($script)) return $script; else { //$res = $parser->exec($script); //$res = $this->_bootStrap($res, $keywords); //return $res; return $this->_bootStrap($parser->exec($script), $keywords); } } function _analyze($script, $regexp, $encode) { // analyse // retreive all words in the script $all = array(); preg_match_all($regexp, $script, $all); $_sorted = array(); // list of words sorted by frequency $_encoded = array(); // dictionary of word->encoding $_protected = array(); // instances of "protected" words $all = $all[0]; // simulate the javascript comportement of global match if (!empty($all)) { $unsorted = array(); // same list, not sorted $protected = array(); // "protected" words (dictionary of word->"word") $value = array(); // dictionary of charCode->encoding (eg. 256->ff) $this->_count = array(); // word->count $i = count($all); $j = 0; //$word = null; // count the occurrences - used for sorting later do { --$i; $word = '$' . $all[$i]; if (!isset($this->_count[$word])) { $this->_count[$word] = 0; $unsorted[$j] = $word; // make a dictionary of all of the protected words in this script // these are words that might be mistaken for encoding //if (is_string($encode) && method_exists($this, $encode)) $values[$j] = call_user_func(array(&$this, $encode), $j); $protected['$' . $values[$j]] = $j++; } // increment the word counter $this->_count[$word]++; } while ($i > 0); // prepare to sort the word list, first we must protect // words that are also used as codes. we assign them a code // equivalent to the word itself. // e.g. if "do" falls within our encoding range // then we store keywords["do"] = "do"; // this avoids problems when decoding $i = count($unsorted); do { $word = $unsorted[--$i]; if (isset($protected[$word]) /*!= null*/) { $_sorted[$protected[$word]] = substr($word, 1); $_protected[$protected[$word]] = true; $this->_count[$word] = 0; } } while ($i); // sort the words by frequency // Note: the javascript and php version of sort can be different : // in php manual, usort : // " If two members compare as equal, // their order in the sorted array is undefined." // so the final packed script is different of the Dean's javascript version // but equivalent. // the ECMAscript standard does not guarantee this behaviour, // and thus not all browsers (e.g. Mozilla versions dating back to at // least 2003) respect this. usort($unsorted, array(&$this, '_sortWords')); $j = 0; // because there are "protected" words in the list // we must add the sorted words around them do { if (!isset($_sorted[$i])) $_sorted[$i] = substr($unsorted[$j++], 1); $_encoded[$_sorted[$i]] = $values[$i]; } while (++$i < count($unsorted)); } return array( 'sorted' => $_sorted, 'encoded' => $_encoded, 'protected' => $_protected); } var $_count = array(); function _sortWords($match1, $match2) { return $this->_count[$match2] - $this->_count[$match1]; } // build the boot function used for loading and decoding function _bootStrap($packed, $keywords) { $ENCODE = $this->_safeRegExp('$encode\\($count\\)'); // $packed: the packed script $packed = "'" . $this->_escape($packed) . "'"; // $ascii: base for encoding $ascii = min(count($keywords['sorted']), $this->_encoding); if ($ascii == 0) $ascii = 1; // $count: number of words contained in the script $count = count($keywords['sorted']); // $keywords: list of words contained in the script foreach ($keywords['protected'] as $i=>$value) { $keywords['sorted'][$i] = ''; } // convert from a string to an array ksort($keywords['sorted']); $keywords = "'" . implode('|',$keywords['sorted']) . "'.split('|')"; $encode = ($this->_encoding > 62) ? '_encode95' : $this->_getEncoder($ascii); $encode = $this->_getJSFunction($encode); $encode = preg_replace('/_encoding/','$ascii', $encode); $encode = preg_replace('/arguments\\.callee/','$encode', $encode); $inline = '\\$count' . ($ascii > 10 ? '.toString(\\$ascii)' : ''); // $decode: code snippet to speed up decoding if ($this->_fastDecode) { // create the decoder $decode = $this->_getJSFunction('_decodeBody'); if ($this->_encoding > 62) $decode = preg_replace('/\\\\w/', '[\\xa1-\\xff]', $decode); // perform the encoding inline for lower ascii values elseif ($ascii < 36) $decode = preg_replace($ENCODE, $inline, $decode); // special case: when $count==0 there are no keywords. I want to keep // the basic shape of the unpacking funcion so i'll frig the code... if ($count == 0) $decode = preg_replace($this->_safeRegExp('($count)\\s*=\\s*1'), '$1=0', $decode, 1); } // boot function $unpack = $this->_getJSFunction('_unpack'); if ($this->_fastDecode) { // insert the decoder $this->buffer = $decode; $unpack = preg_replace_callback('/\\{/', array(&$this, '_insertFastDecode'), $unpack, 1); } $unpack = preg_replace('/"/', "'", $unpack); if ($this->_encoding > 62) { // high-ascii // get rid of the word-boundaries for regexp matches $unpack = preg_replace('/\'\\\\\\\\b\'\s*\\+|\\+\s*\'\\\\\\\\b\'/', '', $unpack); } if ($ascii > 36 || $this->_encoding > 62 || $this->_fastDecode) { // insert the encode function $this->buffer = $encode; $unpack = preg_replace_callback('/\\{/', array(&$this, '_insertFastEncode'), $unpack, 1); } else { // perform the encoding inline $unpack = preg_replace($ENCODE, $inline, $unpack); } // pack the boot function too $unpackPacker = new JavaScriptPacker($unpack, 0, false, true); $unpack = $unpackPacker->pack(); // arguments $params = array($packed, $ascii, $count, $keywords); if ($this->_fastDecode) { $params[] = 0; $params[] = '{}'; } $params = implode(',', $params); // the whole thing return 'eval(' . $unpack . '(' . $params . "))\n"; } var $buffer; function _insertFastDecode($match) { return '{' . $this->buffer . ';'; } function _insertFastEncode($match) { return '{$encode=' . $this->buffer . ';'; } // mmm.. ..which one do i need ?? function _getEncoder($ascii) { return $ascii > 10 ? $ascii > 36 ? $ascii > 62 ? '_encode95' : '_encode62' : '_encode36' : '_encode10'; } // zero encoding // characters: 0123456789 function _encode10($charCode) { return $charCode; } // inherent base36 support // characters: 0123456789abcdefghijklmnopqrstuvwxyz function _encode36($charCode) { return base_convert($charCode, 10, 36); } // hitch a ride on base36 and add the upper case alpha characters // characters: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ function _encode62($charCode) { $res = ''; if ($charCode >= $this->_encoding) { $res = $this->_encode62((int)($charCode / $this->_encoding)); } $charCode = $charCode % $this->_encoding; if ($charCode > 35) return $res . chr($charCode + 29); else return $res . base_convert($charCode, 10, 36); } // use high-ascii values // characters: ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿À?ÂÃÄÅÆÇÈÉÊËÌ?Î??ÑÒÓÔÕÖרÙÚÛÜ?Þßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþ function _encode95($charCode) { $res = ''; if ($charCode >= $this->_encoding) $res = $this->_encode95($charCode / $this->_encoding); return $res . chr(($charCode % $this->_encoding) + 161); } function _safeRegExp($string) { return '/'.preg_replace('/\$/', '\\\$', $string).'/'; } function _encodePrivate($charCode) { return "_" . $charCode; } // protect characters used by the parser function _escape($script) { return preg_replace('/([\\\\\'])/', '\\\$1', $script); } // protect high-ascii characters already in the script function _escape95($script) { return preg_replace_callback( '/[\\xa1-\\xff]/', array(&$this, '_escape95Bis'), $script ); } function _escape95Bis($match) { return '\x'.((string)dechex(ord($match))); } function _getJSFunction($aName) { $func = 'JSFUNCTION'.$aName; if (isset($this->$func)){ return $this->$func; } else return ''; } // JavaScript Functions used. // Note : In Dean's version, these functions are converted // with 'String(aFunctionName);'. // This internal conversion complete the original code, ex : // 'while (aBool) anAction();' is converted to // 'while (aBool) { anAction(); }'. // The JavaScript functions below are corrected. // unpacking function - this is the boot strap function // data extracted from this packing routine is passed to // this function when decoded in the target // NOTE ! : without the ';' final. var $JSFUNCTION_unpack = 'function($packed, $ascii, $count, $keywords, $encode, $decode) { while ($count--) { if ($keywords[$count]) { $packed = $packed.replace(new RegExp(\'\\\\b\' + $encode($count) + \'\\\\b\', \'g\'), $keywords[$count]); } } return $packed; }'; /* 'function($packed, $ascii, $count, $keywords, $encode, $decode) { while ($count--) if ($keywords[$count]) $packed = $packed.replace(new RegExp(\'\\\\b\' + $encode($count) + \'\\\\b\', \'g\'), $keywords[$count]); return $packed; }'; */ // code-snippet inserted into the unpacker to speed up decoding var $JSFUNCTION_decodeBody = ' if (!\'\'.replace(/^/, String)) { // decode all the values we need while ($count--) { $decode[$encode($count)] = $keywords[$count] || $encode($count); } // global replacement function $keywords = [function ($encoded) {return $decode[$encoded]}]; // generic match $encode = function () {return \'\\\\w+\'}; // reset the loop counter - we are now doing a global replace $count = 1; } '; //}; /* ' if (!\'\'.replace(/^/, String)) { // decode all the values we need while ($count--) $decode[$encode($count)] = $keywords[$count] || $encode($count); // global replacement function $keywords = [function ($encoded) {return $decode[$encoded]}]; // generic match $encode = function () {return\'\\\\w+\'}; // reset the loop counter - we are now doing a global replace $count = 1; }'; */ // zero encoding // characters: 0123456789 var $JSFUNCTION_encode10 = 'function($charCode) { return $charCode; }';//;'; // inherent base36 support // characters: 0123456789abcdefghijklmnopqrstuvwxyz var $JSFUNCTION_encode36 = 'function($charCode) { return $charCode.toString(36); }';//;'; // hitch a ride on base36 and add the upper case alpha characters // characters: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ var $JSFUNCTION_encode62 = 'function($charCode) { return ($charCode < _encoding ? \'\' : arguments.callee(parseInt($charCode / _encoding))) + (($charCode = $charCode % _encoding) > 35 ? String.fromCharCode($charCode + 29) : $charCode.toString(36)); }'; // use high-ascii values // characters: ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿À?ÂÃÄÅÆÇÈÉÊËÌ?Î??ÑÒÓÔÕÖרÙÚÛÜ?Þßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþ var $JSFUNCTION_encode95 = 'function($charCode) { return ($charCode < _encoding ? \'\' : arguments.callee($charCode / _encoding)) + String.fromCharCode($charCode % _encoding + 161); }'; } class ParseMaster { var $ignoreCase = false; var $escapeChar = ''; // constants var $EXPRESSION = 0; var $REPLACEMENT = 1; var $LENGTH = 2; // used to determine nesting levels var $GROUPS = '/\\(/';//g var $SUB_REPLACE = '/\\$\\d/'; var $INDEXED = '/^\\$\\d+$/'; var $TRIM = '/([\'"])\\1\\.(.*)\\.\\1\\1$/'; var $ESCAPE = '/\\\./';//g var $QUOTE = '/\'/'; var $DELETED = '/\\x01[^\\x01]*\\x01/';//g function add($expression, $replacement = '') { // count the number of sub-expressions // - add one because each pattern is itself a sub-expression $length = 1 + preg_match_all($this->GROUPS, $this->_internalEscape((string)$expression), $out); // treat only strings $replacement if (is_string($replacement)) { // does the pattern deal with sub-expressions? if (preg_match($this->SUB_REPLACE, $replacement)) { // a simple lookup? (e.g. "$2") if (preg_match($this->INDEXED, $replacement)) { // store the index (used for fast retrieval of matched strings) $replacement = (int)(substr($replacement, 1)) - 1; } else { // a complicated lookup (e.g. "Hello $2 $1") // build a function to do the lookup $quote = preg_match($this->QUOTE, $this->_internalEscape($replacement)) ? '"' : "'"; $replacement = array( 'fn' => '_backReferences', 'data' => array( 'replacement' => $replacement, 'length' => $length, 'quote' => $quote ) ); } } } // pass the modified arguments if (!empty($expression)) $this->_add($expression, $replacement, $length); else $this->_add('/^$/', $replacement, $length); } function exec($string) { // execute the global replacement $this->_escaped = array(); // simulate the _patterns.toSTring of Dean $regexp = '/'; foreach ($this->_patterns as $reg) { $regexp .= '(' . substr($reg[$this->EXPRESSION], 1, -1) . ')|'; } $regexp = substr($regexp, 0, -1) . '/'; $regexp .= ($this->ignoreCase) ? 'i' : ''; $string = $this->_escape($string, $this->escapeChar); $string = preg_replace_callback( $regexp, array( &$this, '_replacement' ), $string ); $string = $this->_unescape($string, $this->escapeChar); return preg_replace($this->DELETED, '', $string); } function reset() { // clear the patterns collection so that this object may be re-used $this->_patterns = array(); } // private var $_escaped = array(); // escaped characters var $_patterns = array(); // patterns stored by index // create and add a new pattern to the patterns collection function _add() { $arguments = func_get_args(); $this->_patterns[] = $arguments; } // this is the global replace function (it's quite complicated) function _replacement($arguments) { if (empty($arguments)) return ''; $i = 1; $j = 0; // loop through the patterns while (isset($this->_patterns[$j])) { $pattern = $this->_patterns[$j++]; // do we have a result? if (isset($arguments[$i]) && ($arguments[$i] != '')) { $replacement = $pattern[$this->REPLACEMENT]; if (is_array($replacement) && isset($replacement['fn'])) { if (isset($replacement['data'])) $this->buffer = $replacement['data']; return call_user_func(array(&$this, $replacement['fn']), $arguments, $i); } elseif (is_int($replacement)) { return $arguments[$replacement + $i]; } $delete = ($this->escapeChar == '' || strpos($arguments[$i], $this->escapeChar) === false) ? '' : "\x01" . $arguments[$i] . "\x01"; return $delete . $replacement; // skip over references to sub-expressions } else { $i += $pattern[$this->LENGTH]; } } } function _backReferences($match, $offset) { $replacement = $this->buffer['replacement']; $quote = $this->buffer['quote']; $i = $this->buffer['length']; while ($i) { $replacement = str_replace('$'.$i--, $match[$offset + $i], $replacement); } return $replacement; } function _replace_name($match, $offset){ $length = strlen($match[$offset + 2]); $start = $length - max($length - strlen($match[$offset + 3]), 0); return substr($match[$offset + 1], $start, $length) . $match[$offset + 4]; } function _replace_encoded($match, $offset) { return $this->buffer[$match[$offset]]; } // php : we cannot pass additional data to preg_replace_callback, // and we cannot use &$this in create_function, so let's go to lower level var $buffer; // encode escaped characters function _escape($string, $escapeChar) { if ($escapeChar) { $this->buffer = $escapeChar; return preg_replace_callback( '/\\' . $escapeChar . '(.)' .'/', array(&$this, '_escapeBis'), $string ); } else { return $string; } } function _escapeBis($match) { $this->_escaped[] = $match[1]; return $this->buffer; } // decode escaped characters function _unescape($string, $escapeChar) { if ($escapeChar) { $regexp = '/'.'\\'.$escapeChar.'/'; $this->buffer = array('escapeChar'=> $escapeChar, 'i' => 0); return preg_replace_callback ( $regexp, array(&$this, '_unescapeBis'), $string ); } else { return $string; } } function _unescapeBis() { if (!empty($this->_escaped[$this->buffer['i']])) { $temp = $this->_escaped[$this->buffer['i']]; } else { $temp = ''; } $this->buffer['i']++; return $this->buffer['escapeChar'] . $temp; } function _internalEscape($string) { return preg_replace($this->ESCAPE, '', $string); } } ?> jsjac-1.3.4+dfsg/utils/packer/example-inline.php000066400000000000000000000057331153725753300216000ustar00rootroot00000000000000pack(); $t2 = microtime(true); $originalLength = strlen($script); $packedLength = strlen($packed); $ratio = number_format($packedLength / $originalLength, 3); $time = sprintf('%.4f', ($t2 - $t1) ); $treat = true; } ?> JavaScript Packer in PHP

      script to pack:

      packed result:

      compression ratio:
      performed in s.

      jsjac-1.3.4+dfsg/utils/packer/myScript.js000066400000000000000000000000001153725753300203060ustar00rootroot00000000000000jsjac-1.3.4+dfsg/utils/packer/pack.php000077500000000000000000000012271153725753300176040ustar00rootroot00000000000000= 3) { $src = $argv[1]; $out = $argv[2]; } else { echo 'you must specify a source file and a result filename',"\n"; echo 'example :', "\n", 'php example-file.php myScript-src.js myPackedScript.js',"\n"; return; } require 'class.JavaScriptPacker.php'; $script = file_get_contents($src); $t1 = microtime(true); $packer = new JavaScriptPacker($script, 'Normal', true, false); $packed = $packer->pack(); $t2 = microtime(true); $time = sprintf('%.4f', ($t2 - $t1) ); echo 'script ', $src, ' packed in ' , $out, ', in ', $time, ' s.', "\n"; file_put_contents($out, $packed); ?> jsjac-1.3.4+dfsg/utils/packer/readme.txt000066400000000000000000000010141153725753300201420ustar00rootroot00000000000000PHP 5 : use class.JavaScriptPacker.php (Tested under PHP 5.1.2, 5.1.3 et 5.1.4.) - usage and comments in source. - there is 2 examples in this archive for PHP 5, 'example-file.php' and example-inline.php PHP 4 : use class.JavaScriptPacker.php4, it's an adaptation for PHP4. The examples in this archive will not work directly with PHP 4, they are writed in PHP5, you'll need to adapt them. If some functions are missing in PHP 4, you can find their equivalent here : http://pear.php.net/package/PHP_Compat