mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 21:27:40 +00:00
Merge guacamole-common.
This commit is contained in:
10
guacamole-common/.gitignore
vendored
Normal file
10
guacamole-common/.gitignore
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
# Compiled code
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Backup files
|
||||||
|
*~
|
||||||
|
|
||||||
|
# Generated docs
|
||||||
|
doc/doxygen-output
|
||||||
|
|
45
guacamole-common/ChangeLog
Normal file
45
guacamole-common/ChangeLog
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
2012-10-24 Michael Jumper <zhangmaike@users.sourceforge.net>
|
||||||
|
|
||||||
|
* Implement audio/video/size preamble in handshake
|
||||||
|
|
||||||
|
2012-10-16 Michael Jumper <zhangmaike@users.sourceforge.net>
|
||||||
|
|
||||||
|
* Ignore data after tunnel UUID (part of fix for ticket #201)
|
||||||
|
|
||||||
|
2012-10-03 Michael Jumper <zhangmaike@users.sourceforge.net>
|
||||||
|
|
||||||
|
* Fix NPE in handshake if end-of-stream encountered (ticket #195)
|
||||||
|
|
||||||
|
2012-08-09 Michael Jumper <zhangmaike@users.sourceforge.net>
|
||||||
|
|
||||||
|
* Improve documentation
|
||||||
|
|
||||||
|
2012-07-24 Michael Jumper <zhangmaike@users.sourceforge.net>
|
||||||
|
|
||||||
|
* Fix Unicode bug
|
||||||
|
|
||||||
|
2012-05-04 Michael Jumper <zhangmaike@users.sourceforge.net>
|
||||||
|
|
||||||
|
* Improved logging and exception handling
|
||||||
|
* Removed minor dependency on Apache Commons
|
||||||
|
* Improved API usability
|
||||||
|
|
||||||
|
2011-12-11 Michael Jumper <zhangmaike@users.sourceforge.net>
|
||||||
|
|
||||||
|
* Implemented improved instruction format
|
||||||
|
* Fixed failed connections when using Konqueror
|
||||||
|
* Relicensed as Mozilla/LGPL/GPL
|
||||||
|
|
||||||
|
2011-07-13 Michael Jumper <zhangmaike@users.sourceforge.net>
|
||||||
|
|
||||||
|
* Fixed "no element found" errors
|
||||||
|
* Added timeouts
|
||||||
|
* Multiple tunnel support
|
||||||
|
* Better error handling
|
||||||
|
* Added JavaDoc
|
||||||
|
* Added logging
|
||||||
|
|
||||||
|
2011-03-02 Michael Jumper <zhangmaike@users.sourceforge.net>
|
||||||
|
|
||||||
|
* Initial release
|
||||||
|
|
470
guacamole-common/LICENSE
Normal file
470
guacamole-common/LICENSE
Normal file
@@ -0,0 +1,470 @@
|
|||||||
|
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.]
|
||||||
|
|
76
guacamole-common/README
Normal file
76
guacamole-common/README
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
|
||||||
|
------------------------------------------------------------
|
||||||
|
About this README
|
||||||
|
------------------------------------------------------------
|
||||||
|
|
||||||
|
This README is intended to provide quick and to-the-point documentation for
|
||||||
|
technical users intending to compile parts of Guacamole themselves.
|
||||||
|
|
||||||
|
Distribution-specific packages are available from the files section of the main
|
||||||
|
project page:
|
||||||
|
|
||||||
|
http://sourceforge.net/projects/guacamole/files/
|
||||||
|
|
||||||
|
Distribution-specific documentation is provided on the Guacamole wiki:
|
||||||
|
|
||||||
|
http://guac-dev.org/
|
||||||
|
|
||||||
|
|
||||||
|
------------------------------------------------------------
|
||||||
|
What is guacamole-common?
|
||||||
|
------------------------------------------------------------
|
||||||
|
|
||||||
|
guacamole-common is the core Java library used by the Guacamole web
|
||||||
|
application.
|
||||||
|
|
||||||
|
guacamole-common provides abstract means of connecting to guacd, interfacing
|
||||||
|
with the JavaScript client and tunnel provided by guacamole-common-js, and
|
||||||
|
reading configuration from a standard location (guacamole.properties).
|
||||||
|
|
||||||
|
|
||||||
|
------------------------------------------------------------
|
||||||
|
Compiling and installing guacamole-common
|
||||||
|
------------------------------------------------------------
|
||||||
|
|
||||||
|
guacamole-common is built using Maven. Building guacamole-common
|
||||||
|
compiles all classes and packages them into a redistributable .jar file. This
|
||||||
|
.jar file can be easily included in other Maven-based projects (like Guacamole).
|
||||||
|
|
||||||
|
Note that prebuilt versions of guacamole-common are available from the
|
||||||
|
main guac-dev.org Maven repository which is referenced in all Maven
|
||||||
|
projects in Guacamole. Unless you want to make changes to guacamole-common
|
||||||
|
or you want to use a newer, unreleased version (such as the unstable branch),
|
||||||
|
you do not need to build this manually. You can let Maven download it for
|
||||||
|
you when you build Guacamole.
|
||||||
|
|
||||||
|
1) Run mvn package
|
||||||
|
|
||||||
|
$ mvn package
|
||||||
|
|
||||||
|
Maven will download any needed dependencies for building the .jar file.
|
||||||
|
Once all dependencies have been downloaded, the .jar file will be
|
||||||
|
created in the target/ subdirectory of the current directory.
|
||||||
|
|
||||||
|
2) Run mvn install
|
||||||
|
|
||||||
|
$ mvn install
|
||||||
|
|
||||||
|
DO NOT RUN THIS AS ROOT!
|
||||||
|
|
||||||
|
Maven will install guacamole-common to your user's local Maven
|
||||||
|
repository where it can be used in future builds. It will not install
|
||||||
|
into a system-wide repository and does not require root privileges.
|
||||||
|
|
||||||
|
Once installed, building other Maven projects that depend on
|
||||||
|
guacamole-common (such as Guacamole) will be possible.
|
||||||
|
|
||||||
|
|
||||||
|
------------------------------------------------------------
|
||||||
|
Reporting problems
|
||||||
|
------------------------------------------------------------
|
||||||
|
|
||||||
|
Please report any bugs encountered by opening a new ticket at the Trac system
|
||||||
|
hosted at:
|
||||||
|
|
||||||
|
http://guac-dev.org/trac/
|
||||||
|
|
1551
guacamole-common/doc/Doxyfile
Normal file
1551
guacamole-common/doc/Doxyfile
Normal file
File diff suppressed because it is too large
Load Diff
49
guacamole-common/doc/example/ExampleTunnelServlet.java
Normal file
49
guacamole-common/doc/example/ExampleTunnelServlet.java
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
import net.sourceforge.guacamole.GuacamoleException;
|
||||||
|
import net.sourceforge.guacamole.properties.GuacamoleProperties;
|
||||||
|
import net.sourceforge.guacamole.net.GuacamoleSocket;
|
||||||
|
import net.sourceforge.guacamole.net.GuacamoleTunnel;
|
||||||
|
import net.sourceforge.guacamole.net.InetGuacamoleSocket;
|
||||||
|
import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
|
||||||
|
import net.sourceforge.guacamole.protocol.ConfiguredGuacamoleSocket;
|
||||||
|
import net.sourceforge.guacamole.servlet.GuacamoleSession;
|
||||||
|
import net.sourceforge.guacamole.servlet.GuacamoleHTTPTunnelServlet;
|
||||||
|
|
||||||
|
public class ExampleTunnelServlet extends GuacamoleHTTPTunnelServlet {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected GuacamoleTunnel doConnect(HttpServletRequest request)
|
||||||
|
throws GuacamoleException {
|
||||||
|
|
||||||
|
HttpSession httpSession = request.getSession(true);
|
||||||
|
|
||||||
|
String hostname = GuacamoleProperties.getProperty(
|
||||||
|
GuacamoleProperties.GUACD_HOSTNAME);
|
||||||
|
|
||||||
|
int port = GuacamoleProperties.getProperty(
|
||||||
|
GuacamoleProperties.GUACD_PORT);
|
||||||
|
|
||||||
|
GuacamoleConfiguration config = new GuacamoleConfiguration();
|
||||||
|
config.setProtocol("vnc");
|
||||||
|
config.setParameter("hostname", "localhost");
|
||||||
|
config.setParameter("port", "5901");
|
||||||
|
config.setParameter("password", "potato");
|
||||||
|
|
||||||
|
GuacamoleSocket socket = new ConfiguredGuacamoleSocket(
|
||||||
|
new InetGuacamoleSocket(hostname, port),
|
||||||
|
config
|
||||||
|
);
|
||||||
|
|
||||||
|
GuacamoleTunnel tunnel = new GuacamoleTunnel(socket);
|
||||||
|
|
||||||
|
// Attach tunnel
|
||||||
|
GuacamoleSession session = new GuacamoleSession(httpSession);
|
||||||
|
session.attachTunnel(tunnel);
|
||||||
|
|
||||||
|
return tunnel;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
48
guacamole-common/pom.xml
Normal file
48
guacamole-common/pom.xml
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>net.sourceforge.guacamole</groupId>
|
||||||
|
<artifactId>guacamole-common</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<version>0.8.0</version>
|
||||||
|
<name>guacamole-common</name>
|
||||||
|
<url>http://guac-dev.org/</url>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>1.6</source>
|
||||||
|
<target>1.6</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<!-- Java servlet API -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>servlet-api</artifactId>
|
||||||
|
<version>2.5</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- SLF4J - logging -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<version>1.6.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
@@ -0,0 +1,79 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.guacamole;
|
||||||
|
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* 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 guacamole-common.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is
|
||||||
|
* Michael Jumper.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A generic exception thrown when part of the Guacamole API encounters
|
||||||
|
* an error in the client's request. Such an error, if correctable, usually
|
||||||
|
* requires correction on the client side, not the server.
|
||||||
|
*
|
||||||
|
* @author Michael Jumper
|
||||||
|
*/
|
||||||
|
public class GuacamoleClientException extends GuacamoleException {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new GuacamoleException with the given message and cause.
|
||||||
|
*
|
||||||
|
* @param message A human readable description of the exception that
|
||||||
|
* occurred.
|
||||||
|
* @param cause The cause of this exception.
|
||||||
|
*/
|
||||||
|
public GuacamoleClientException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new GuacamoleException with the given message.
|
||||||
|
*
|
||||||
|
* @param message A human readable description of the exception that
|
||||||
|
* occurred.
|
||||||
|
*/
|
||||||
|
public GuacamoleClientException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new GuacamoleException with the given cause.
|
||||||
|
*
|
||||||
|
* @param cause The cause of this exception.
|
||||||
|
*/
|
||||||
|
public GuacamoleClientException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,78 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.guacamole;
|
||||||
|
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* 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 guacamole-common.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is
|
||||||
|
* Michael Jumper.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A generic exception thrown when parts of the Guacamole API encounter
|
||||||
|
* errors.
|
||||||
|
*
|
||||||
|
* @author Michael Jumper
|
||||||
|
*/
|
||||||
|
public class GuacamoleException extends Exception {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new GuacamoleException with the given message and cause.
|
||||||
|
*
|
||||||
|
* @param message A human readable description of the exception that
|
||||||
|
* occurred.
|
||||||
|
* @param cause The cause of this exception.
|
||||||
|
*/
|
||||||
|
public GuacamoleException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new GuacamoleException with the given message.
|
||||||
|
*
|
||||||
|
* @param message A human readable description of the exception that
|
||||||
|
* occurred.
|
||||||
|
*/
|
||||||
|
public GuacamoleException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new GuacamoleException with the given cause.
|
||||||
|
*
|
||||||
|
* @param cause The cause of this exception.
|
||||||
|
*/
|
||||||
|
public GuacamoleException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,79 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.guacamole;
|
||||||
|
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* 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 guacamole-common.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is
|
||||||
|
* Michael Jumper.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A generic exception thrown when part of the Guacamole API fails to find
|
||||||
|
* a requested resource, such as a configuration or tunnel.
|
||||||
|
*
|
||||||
|
* @author Michael Jumper
|
||||||
|
*/
|
||||||
|
public class GuacamoleResourceNotFoundException extends GuacamoleClientException {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new GuacamoleResourceNotFoundException with the given message
|
||||||
|
* and cause.
|
||||||
|
*
|
||||||
|
* @param message A human readable description of the exception that
|
||||||
|
* occurred.
|
||||||
|
* @param cause The cause of this exception.
|
||||||
|
*/
|
||||||
|
public GuacamoleResourceNotFoundException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new GuacamoleResourceNotFoundException with the given message.
|
||||||
|
*
|
||||||
|
* @param message A human readable description of the exception that
|
||||||
|
* occurred.
|
||||||
|
*/
|
||||||
|
public GuacamoleResourceNotFoundException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new GuacamoleResourceNotFoundException with the given cause.
|
||||||
|
*
|
||||||
|
* @param cause The cause of this exception.
|
||||||
|
*/
|
||||||
|
public GuacamoleResourceNotFoundException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,78 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.guacamole;
|
||||||
|
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* 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 guacamole-common.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is
|
||||||
|
* Michael Jumper.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A security-related exception thrown when parts of the Guacamole API is
|
||||||
|
* denying access to a resource.
|
||||||
|
*
|
||||||
|
* @author Michael Jumper
|
||||||
|
*/
|
||||||
|
public class GuacamoleSecurityException extends GuacamoleClientException {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new GuacamoleSecurityException with the given message and cause.
|
||||||
|
*
|
||||||
|
* @param message A human readable description of the exception that
|
||||||
|
* occurred.
|
||||||
|
* @param cause The cause of this exception.
|
||||||
|
*/
|
||||||
|
public GuacamoleSecurityException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new GuacamoleSecurityException with the given message.
|
||||||
|
*
|
||||||
|
* @param message A human readable description of the exception that
|
||||||
|
* occurred.
|
||||||
|
*/
|
||||||
|
public GuacamoleSecurityException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new GuacamoleSecurityException with the given cause.
|
||||||
|
*
|
||||||
|
* @param cause The cause of this exception.
|
||||||
|
*/
|
||||||
|
public GuacamoleSecurityException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,79 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.guacamole;
|
||||||
|
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* 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 guacamole-common.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is
|
||||||
|
* Michael Jumper.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A generic exception thrown when part of the Guacamole API encounters
|
||||||
|
* an unexpected, internal error. An internal error, if correctable, would
|
||||||
|
* require correction on the server side, not the client.
|
||||||
|
*
|
||||||
|
* @author Michael Jumper
|
||||||
|
*/
|
||||||
|
public class GuacamoleServerException extends GuacamoleException {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new GuacamoleException with the given message and cause.
|
||||||
|
*
|
||||||
|
* @param message A human readable description of the exception that
|
||||||
|
* occurred.
|
||||||
|
* @param cause The cause of this exception.
|
||||||
|
*/
|
||||||
|
public GuacamoleServerException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new GuacamoleException with the given message.
|
||||||
|
*
|
||||||
|
* @param message A human readable description of the exception that
|
||||||
|
* occurred.
|
||||||
|
*/
|
||||||
|
public GuacamoleServerException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new GuacamoleException with the given cause.
|
||||||
|
*
|
||||||
|
* @param cause The cause of this exception.
|
||||||
|
*/
|
||||||
|
public GuacamoleServerException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,89 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.guacamole.io;
|
||||||
|
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* 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 guacamole-common.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is
|
||||||
|
* Michael Jumper.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
import net.sourceforge.guacamole.GuacamoleException;
|
||||||
|
import net.sourceforge.guacamole.protocol.GuacamoleInstruction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides abstract and raw character read access to a stream of Guacamole
|
||||||
|
* instructions.
|
||||||
|
*
|
||||||
|
* @author Michael Jumper
|
||||||
|
*/
|
||||||
|
public interface GuacamoleReader {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether instruction data is available for reading. Note that
|
||||||
|
* this does not guarantee an entire instruction is available. If a full
|
||||||
|
* instruction is not available, this function can return true, and a call
|
||||||
|
* to read() will still block.
|
||||||
|
*
|
||||||
|
* @return true if instruction data is available for reading, false
|
||||||
|
* otherwise.
|
||||||
|
* @throws GuacamoleException If an error occurs while checking for
|
||||||
|
* available data.
|
||||||
|
*/
|
||||||
|
public boolean available() throws GuacamoleException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads at least one complete Guacamole instruction, returning a buffer
|
||||||
|
* containing one or more complete Guacamole instructions and no
|
||||||
|
* incomplete Guacamole instructions. This function will block until at
|
||||||
|
* least one complete instruction is available.
|
||||||
|
*
|
||||||
|
* @return A buffer containing at least one complete Guacamole instruction,
|
||||||
|
* or null if no more instructions are available for reading.
|
||||||
|
* @throws GuacamoleException If an error occurs while reading from the
|
||||||
|
* stream.
|
||||||
|
*/
|
||||||
|
public char[] read() throws GuacamoleException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads exactly one complete Guacamole instruction and returns the fully
|
||||||
|
* parsed instruction.
|
||||||
|
*
|
||||||
|
* @return The next complete instruction from the stream, fully parsed, or
|
||||||
|
* null if no more instructions are available for reading.
|
||||||
|
* @throws GuacamoleException If an error occurs while reading from the
|
||||||
|
* stream, or if the instruction cannot be
|
||||||
|
* parsed.
|
||||||
|
*/
|
||||||
|
public GuacamoleInstruction readInstruction() throws GuacamoleException;
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,85 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.guacamole.io;
|
||||||
|
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* 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 guacamole-common.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is
|
||||||
|
* Michael Jumper.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
import net.sourceforge.guacamole.GuacamoleException;
|
||||||
|
import net.sourceforge.guacamole.protocol.GuacamoleInstruction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides abstract and raw character write access to a stream of Guacamole
|
||||||
|
* instructions.
|
||||||
|
*
|
||||||
|
* @author Michael Jumper
|
||||||
|
*/
|
||||||
|
public interface GuacamoleWriter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes a portion of the given array of characters to the Guacamole
|
||||||
|
* instruction stream. The portion must contain only complete Guacamole
|
||||||
|
* instructions.
|
||||||
|
*
|
||||||
|
* @param chunk An array of characters containing Guacamole instructions.
|
||||||
|
* @param off The start offset of the portion of the array to write.
|
||||||
|
* @param len The length of the portion of the array to write.
|
||||||
|
* @throws GuacamoleException If an error occurred while writing the
|
||||||
|
* portion of the array specified.
|
||||||
|
*/
|
||||||
|
public void write(char[] chunk, int off, int len) throws GuacamoleException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes the entire given array of characters to the Guacamole instruction
|
||||||
|
* stream. The array must consist only of complete Guacamole instructions.
|
||||||
|
*
|
||||||
|
* @param chunk An array of characters consisting only of complete
|
||||||
|
* Guacamole instructions.
|
||||||
|
* @throws GuacamoleException If an error occurred while writing the
|
||||||
|
* the specified array.
|
||||||
|
*/
|
||||||
|
public void write(char[] chunk) throws GuacamoleException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes the given fully parsed instruction to the Guacamole instruction
|
||||||
|
* stream.
|
||||||
|
*
|
||||||
|
* @param instruction The Guacamole instruction to write.
|
||||||
|
* @throws GuacamoleException If an error occurred while writing the
|
||||||
|
* instruction.
|
||||||
|
*/
|
||||||
|
public void writeInstruction(GuacamoleInstruction instruction) throws GuacamoleException;
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,276 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.guacamole.io;
|
||||||
|
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* 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 guacamole-common.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is
|
||||||
|
* Michael Jumper.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.util.Deque;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import net.sourceforge.guacamole.GuacamoleException;
|
||||||
|
import net.sourceforge.guacamole.GuacamoleServerException;
|
||||||
|
import net.sourceforge.guacamole.protocol.GuacamoleInstruction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A GuacamoleReader which wraps a standard Java Reader, using that Reader as
|
||||||
|
* the Guacamole instruction stream.
|
||||||
|
*
|
||||||
|
* @author Michael Jumper
|
||||||
|
*/
|
||||||
|
public class ReaderGuacamoleReader implements GuacamoleReader {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapped Reader to be used for all input.
|
||||||
|
*/
|
||||||
|
private Reader input;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new ReaderGuacamoleReader which will use the given Reader as
|
||||||
|
* the Guacamole instruction stream.
|
||||||
|
*
|
||||||
|
* @param input The Reader to use as the Guacamole instruction stream.
|
||||||
|
*/
|
||||||
|
public ReaderGuacamoleReader(Reader input) {
|
||||||
|
this.input = input;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The location within the received data buffer that parsing should begin
|
||||||
|
* when more data is read.
|
||||||
|
*/
|
||||||
|
private int parseStart;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The buffer holding all received, unparsed data.
|
||||||
|
*/
|
||||||
|
private char[] buffer = new char[20480];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of characters currently used within the data buffer. All
|
||||||
|
* other characters within the buffer are free space available for
|
||||||
|
* future reads.
|
||||||
|
*/
|
||||||
|
private int usedLength = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean available() throws GuacamoleException {
|
||||||
|
try {
|
||||||
|
return input.ready() || usedLength != 0;
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new GuacamoleServerException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public char[] read() throws GuacamoleException {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
// While we're blocking, or input is available
|
||||||
|
for (;;) {
|
||||||
|
|
||||||
|
// Length of element
|
||||||
|
int elementLength = 0;
|
||||||
|
|
||||||
|
// Resume where we left off
|
||||||
|
int i = parseStart;
|
||||||
|
|
||||||
|
// Parse instruction in buffer
|
||||||
|
while (i < usedLength) {
|
||||||
|
|
||||||
|
// Read character
|
||||||
|
char readChar = buffer[i++];
|
||||||
|
|
||||||
|
// If digit, update length
|
||||||
|
if (readChar >= '0' && readChar <= '9')
|
||||||
|
elementLength = elementLength * 10 + readChar - '0';
|
||||||
|
|
||||||
|
// If not digit, check for end-of-length character
|
||||||
|
else if (readChar == '.') {
|
||||||
|
|
||||||
|
// Check if element present in buffer
|
||||||
|
if (i + elementLength < usedLength) {
|
||||||
|
|
||||||
|
// Get terminator
|
||||||
|
char terminator = buffer[i + elementLength];
|
||||||
|
|
||||||
|
// Move to character after terminator
|
||||||
|
i += elementLength + 1;
|
||||||
|
|
||||||
|
// Reset length
|
||||||
|
elementLength = 0;
|
||||||
|
|
||||||
|
// Continue here if necessary
|
||||||
|
parseStart = i;
|
||||||
|
|
||||||
|
// If terminator is semicolon, we have a full
|
||||||
|
// instruction.
|
||||||
|
if (terminator == ';') {
|
||||||
|
|
||||||
|
// Copy instruction data
|
||||||
|
char[] instruction = new char[i];
|
||||||
|
System.arraycopy(buffer, 0, instruction, 0, i);
|
||||||
|
|
||||||
|
// Update buffer
|
||||||
|
usedLength -= i;
|
||||||
|
parseStart = 0;
|
||||||
|
System.arraycopy(buffer, i, buffer, 0, usedLength);
|
||||||
|
|
||||||
|
return instruction;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle invalid terminator characters
|
||||||
|
else if (terminator != ',')
|
||||||
|
throw new GuacamoleServerException("Element terminator of instruction was not ';' nor ','");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, read more data
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, parse error
|
||||||
|
else
|
||||||
|
throw new GuacamoleServerException("Non-numeric character in element length.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// If past threshold, resize buffer before reading
|
||||||
|
if (usedLength > buffer.length/2) {
|
||||||
|
char[] biggerBuffer = new char[buffer.length*2];
|
||||||
|
System.arraycopy(buffer, 0, biggerBuffer, 0, usedLength);
|
||||||
|
buffer = biggerBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attempt to fill buffer
|
||||||
|
int numRead = input.read(buffer, usedLength, buffer.length - usedLength);
|
||||||
|
if (numRead == -1)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// Update used length
|
||||||
|
usedLength += numRead;
|
||||||
|
|
||||||
|
} // End read loop
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new GuacamoleServerException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GuacamoleInstruction readInstruction() throws GuacamoleException {
|
||||||
|
|
||||||
|
// Get instruction
|
||||||
|
char[] instructionBuffer = read();
|
||||||
|
|
||||||
|
// If EOF, return EOF
|
||||||
|
if (instructionBuffer == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// Start of element
|
||||||
|
int elementStart = 0;
|
||||||
|
|
||||||
|
// Build list of elements
|
||||||
|
Deque<String> elements = new LinkedList<String>();
|
||||||
|
while (elementStart < instructionBuffer.length) {
|
||||||
|
|
||||||
|
// Find end of length
|
||||||
|
int lengthEnd = -1;
|
||||||
|
for (int i=elementStart; i<instructionBuffer.length; i++) {
|
||||||
|
if (instructionBuffer[i] == '.') {
|
||||||
|
lengthEnd = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// read() is required to return a complete instruction. If it does
|
||||||
|
// not, this is a severe internal error.
|
||||||
|
if (lengthEnd == -1)
|
||||||
|
throw new GuacamoleServerException("Read returned incomplete instruction.");
|
||||||
|
|
||||||
|
// Parse length
|
||||||
|
int length = Integer.parseInt(new String(
|
||||||
|
instructionBuffer,
|
||||||
|
elementStart,
|
||||||
|
lengthEnd - elementStart
|
||||||
|
));
|
||||||
|
|
||||||
|
// Parse element from just after period
|
||||||
|
elementStart = lengthEnd + 1;
|
||||||
|
String element = new String(
|
||||||
|
instructionBuffer,
|
||||||
|
elementStart,
|
||||||
|
length
|
||||||
|
);
|
||||||
|
|
||||||
|
// Append element to list of elements
|
||||||
|
elements.addLast(element);
|
||||||
|
|
||||||
|
// Read terminator after element
|
||||||
|
elementStart += length;
|
||||||
|
char terminator = instructionBuffer[elementStart];
|
||||||
|
|
||||||
|
// Continue reading instructions after terminator
|
||||||
|
elementStart++;
|
||||||
|
|
||||||
|
// If we've reached the end of the instruction
|
||||||
|
if (terminator == ';')
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pull opcode off elements list
|
||||||
|
String opcode = elements.removeFirst();
|
||||||
|
|
||||||
|
// Create instruction
|
||||||
|
GuacamoleInstruction instruction = new GuacamoleInstruction(
|
||||||
|
opcode,
|
||||||
|
elements.toArray(new String[elements.size()])
|
||||||
|
);
|
||||||
|
|
||||||
|
// Return parsed instruction
|
||||||
|
return instruction;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,90 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.guacamole.io;
|
||||||
|
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* 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 guacamole-common.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is
|
||||||
|
* Michael Jumper.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Writer;
|
||||||
|
import net.sourceforge.guacamole.GuacamoleException;
|
||||||
|
import net.sourceforge.guacamole.GuacamoleServerException;
|
||||||
|
import net.sourceforge.guacamole.protocol.GuacamoleInstruction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A GuacamoleWriter which wraps a standard Java Writer, using that Writer as
|
||||||
|
* the Guacamole instruction stream.
|
||||||
|
*
|
||||||
|
* @author Michael Jumper
|
||||||
|
*/
|
||||||
|
public class WriterGuacamoleWriter implements GuacamoleWriter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapped Writer to be used for all output.
|
||||||
|
*/
|
||||||
|
private Writer output;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new WriterGuacamoleWriter which will use the given Writer as
|
||||||
|
* the Guacamole instruction stream.
|
||||||
|
*
|
||||||
|
* @param output The Writer to use as the Guacamole instruction stream.
|
||||||
|
*/
|
||||||
|
public WriterGuacamoleWriter(Writer output) {
|
||||||
|
this.output = output;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(char[] chunk, int off, int len) throws GuacamoleException {
|
||||||
|
try {
|
||||||
|
output.write(chunk, off, len);
|
||||||
|
output.flush();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new GuacamoleServerException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(char[] chunk) throws GuacamoleException {
|
||||||
|
write(chunk, 0, chunk.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeInstruction(GuacamoleInstruction instruction) throws GuacamoleException {
|
||||||
|
write(instruction.toString().toCharArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* All classes relating directly to data input or output.
|
||||||
|
*/
|
||||||
|
package net.sourceforge.guacamole.io;
|
||||||
|
|
@@ -0,0 +1,87 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.guacamole.net;
|
||||||
|
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* 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 guacamole-common.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is
|
||||||
|
* Michael Jumper.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
import net.sourceforge.guacamole.GuacamoleException;
|
||||||
|
import net.sourceforge.guacamole.io.GuacamoleReader;
|
||||||
|
import net.sourceforge.guacamole.io.GuacamoleWriter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides abstract socket-like access to a Guacamole connection.
|
||||||
|
*
|
||||||
|
* @author Michael Jumper
|
||||||
|
*/
|
||||||
|
public interface GuacamoleSocket {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a GuacamoleReader which can be used to read from the
|
||||||
|
* Guacamole instruction stream associated with the connection
|
||||||
|
* represented by this GuacamoleSocket.
|
||||||
|
*
|
||||||
|
* @return A GuacamoleReader which can be used to read from the
|
||||||
|
* Guacamole instruction stream.
|
||||||
|
*/
|
||||||
|
public GuacamoleReader getReader();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a GuacamoleWriter which can be used to write to the
|
||||||
|
* Guacamole instruction stream associated with the connection
|
||||||
|
* represented by this GuacamoleSocket.
|
||||||
|
*
|
||||||
|
* @return A GuacamoleWriter which can be used to write to the
|
||||||
|
* Guacamole instruction stream.
|
||||||
|
*/
|
||||||
|
public GuacamoleWriter getWriter();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Releases all resources in use by the connection represented by this
|
||||||
|
* GuacamoleSocket.
|
||||||
|
*
|
||||||
|
* @throws GuacamoleException If an error occurs while releasing resources.
|
||||||
|
*/
|
||||||
|
public void close() throws GuacamoleException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether this GuacamoleSocket is open and can be used for reading
|
||||||
|
* and writing.
|
||||||
|
*
|
||||||
|
* @return true if this GuacamoleSocket is open, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean isOpen();
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,195 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.guacamole.net;
|
||||||
|
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* 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 guacamole-common.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is
|
||||||
|
* Michael Jumper.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
import net.sourceforge.guacamole.GuacamoleException;
|
||||||
|
import net.sourceforge.guacamole.io.GuacamoleReader;
|
||||||
|
import net.sourceforge.guacamole.io.GuacamoleWriter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a unique identifier and synchronized access to the GuacamoleReader
|
||||||
|
* and GuacamoleWriter associated with a GuacamoleSocket.
|
||||||
|
*
|
||||||
|
* @author Michael Jumper
|
||||||
|
*/
|
||||||
|
public class GuacamoleTunnel {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The UUID associated with this tunnel. Every tunnel must have a
|
||||||
|
* corresponding UUID such that tunnel read/write requests can be
|
||||||
|
* directed to the proper tunnel.
|
||||||
|
*/
|
||||||
|
private UUID uuid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The GuacamoleSocket that tunnel should use for communication on
|
||||||
|
* behalf of the connecting user.
|
||||||
|
*/
|
||||||
|
private GuacamoleSocket socket;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lock acquired when a read operation is in progress.
|
||||||
|
*/
|
||||||
|
private ReentrantLock readerLock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lock acquired when a write operation is in progress.
|
||||||
|
*/
|
||||||
|
private ReentrantLock writerLock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new GuacamoleTunnel which synchronizes access to the
|
||||||
|
* Guacamole instruction stream associated with the given GuacamoleSocket.
|
||||||
|
*
|
||||||
|
* @param socket The GuacamoleSocket to provide synchronized access for.
|
||||||
|
*/
|
||||||
|
public GuacamoleTunnel(GuacamoleSocket socket) {
|
||||||
|
|
||||||
|
this.socket = socket;
|
||||||
|
uuid = UUID.randomUUID();
|
||||||
|
|
||||||
|
readerLock = new ReentrantLock();
|
||||||
|
writerLock = new ReentrantLock();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Acquires exclusive read access to the Guacamole instruction stream
|
||||||
|
* and returns a GuacamoleReader for reading from that stream.
|
||||||
|
*
|
||||||
|
* @return A GuacamoleReader for reading from the Guacamole instruction
|
||||||
|
* stream.
|
||||||
|
*/
|
||||||
|
public GuacamoleReader acquireReader() {
|
||||||
|
readerLock.lock();
|
||||||
|
return socket.getReader();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relinquishes exclusive read access to the Guacamole instruction
|
||||||
|
* stream. This function should be called whenever a thread finishes using
|
||||||
|
* a GuacamoleTunnel's GuacamoleReader.
|
||||||
|
*/
|
||||||
|
public void releaseReader() {
|
||||||
|
readerLock.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether there are threads waiting for read access to the
|
||||||
|
* Guacamole instruction stream.
|
||||||
|
*
|
||||||
|
* @return true if threads are waiting for read access the Guacamole
|
||||||
|
* instruction stream, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean hasQueuedReaderThreads() {
|
||||||
|
return readerLock.hasQueuedThreads();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Acquires exclusive write access to the Guacamole instruction stream
|
||||||
|
* and returns a GuacamoleWriter for writing to that stream.
|
||||||
|
*
|
||||||
|
* @return A GuacamoleWriter for writing to the Guacamole instruction
|
||||||
|
* stream.
|
||||||
|
*/
|
||||||
|
public GuacamoleWriter acquireWriter() {
|
||||||
|
writerLock.lock();
|
||||||
|
return socket.getWriter();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relinquishes exclusive write access to the Guacamole instruction
|
||||||
|
* stream. This function should be called whenever a thread finishes using
|
||||||
|
* a GuacamoleTunnel's GuacamoleWriter.
|
||||||
|
*/
|
||||||
|
public void releaseWriter() {
|
||||||
|
writerLock.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether there are threads waiting for write access to the
|
||||||
|
* Guacamole instruction stream.
|
||||||
|
*
|
||||||
|
* @return true if threads are waiting for write access the Guacamole
|
||||||
|
* instruction stream, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean hasQueuedWriterThreads() {
|
||||||
|
return writerLock.hasQueuedThreads();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the unique identifier associated with this GuacamoleTunnel.
|
||||||
|
*
|
||||||
|
* @return The unique identifier associated with this GuacamoleTunnel.
|
||||||
|
*/
|
||||||
|
public UUID getUUID() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the GuacamoleSocket used by this GuacamoleTunnel for reading
|
||||||
|
* and writing.
|
||||||
|
*
|
||||||
|
* @return The GuacamoleSocket used by this GuacamoleTunnel.
|
||||||
|
*/
|
||||||
|
public GuacamoleSocket getSocket() {
|
||||||
|
return socket;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Release all resources allocated to this GuacamoleTunnel.
|
||||||
|
*
|
||||||
|
* @throws GuacamoleException if an error occurs while releasing
|
||||||
|
* resources.
|
||||||
|
*/
|
||||||
|
public void close() throws GuacamoleException {
|
||||||
|
socket.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether this GuacamoleTunnel is open, or has been closed.
|
||||||
|
*
|
||||||
|
* @return true if this GuacamoleTunnel is open, false if it is closed.
|
||||||
|
*/
|
||||||
|
public boolean isOpen() {
|
||||||
|
return socket.isOpen();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,160 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.guacamole.net;
|
||||||
|
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* 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 guacamole-common.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is
|
||||||
|
* Michael Jumper.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
import net.sourceforge.guacamole.io.GuacamoleReader;
|
||||||
|
import net.sourceforge.guacamole.io.ReaderGuacamoleReader;
|
||||||
|
import net.sourceforge.guacamole.io.WriterGuacamoleWriter;
|
||||||
|
import net.sourceforge.guacamole.io.GuacamoleWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.Socket;
|
||||||
|
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.SocketAddress;
|
||||||
|
import net.sourceforge.guacamole.GuacamoleException;
|
||||||
|
import net.sourceforge.guacamole.GuacamoleServerException;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides abstract socket-like access to a Guacamole connection over a given
|
||||||
|
* hostname and port.
|
||||||
|
*
|
||||||
|
* @author Michael Jumper
|
||||||
|
*/
|
||||||
|
public class InetGuacamoleSocket implements GuacamoleSocket {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logger for this class.
|
||||||
|
*/
|
||||||
|
private Logger logger = LoggerFactory.getLogger(InetGuacamoleSocket.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The GuacamoleReader this socket should read from.
|
||||||
|
*/
|
||||||
|
private GuacamoleReader reader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The GuacamoleWriter this socket should write to.
|
||||||
|
*/
|
||||||
|
private GuacamoleWriter writer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of milliseconds to wait for data on the TCP socket before
|
||||||
|
* timing out.
|
||||||
|
*/
|
||||||
|
private static final int SOCKET_TIMEOUT = 15000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The TCP socket that the GuacamoleReader and GuacamoleWriter exposed
|
||||||
|
* by this class should affect.
|
||||||
|
*/
|
||||||
|
private Socket sock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new InetGuacamoleSocket which reads and writes instructions
|
||||||
|
* to the Guacamole instruction stream of the Guacamole proxy server
|
||||||
|
* running at the given hostname and port.
|
||||||
|
*
|
||||||
|
* @param hostname The hostname of the Guacamole proxy server to connect to.
|
||||||
|
* @param port The port of the Guacamole proxy server to connect to.
|
||||||
|
* @throws GuacamoleException If an error occurs while connecting to the
|
||||||
|
* Guacamole proxy server.
|
||||||
|
*/
|
||||||
|
public InetGuacamoleSocket(String hostname, int port) throws GuacamoleException {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
logger.debug("Connecting to guacd at {}:{}.", hostname, port);
|
||||||
|
|
||||||
|
// Get address
|
||||||
|
SocketAddress address = new InetSocketAddress(
|
||||||
|
InetAddress.getByName(hostname),
|
||||||
|
port
|
||||||
|
);
|
||||||
|
|
||||||
|
// Connect with timeout
|
||||||
|
sock = new Socket();
|
||||||
|
sock.connect(address, SOCKET_TIMEOUT);
|
||||||
|
|
||||||
|
// Set read timeout
|
||||||
|
sock.setSoTimeout(SOCKET_TIMEOUT);
|
||||||
|
|
||||||
|
// On successful connect, retrieve I/O streams
|
||||||
|
reader = new ReaderGuacamoleReader(new InputStreamReader(sock.getInputStream(), "UTF-8"));
|
||||||
|
writer = new WriterGuacamoleWriter(new OutputStreamWriter(sock.getOutputStream(), "UTF-8"));
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new GuacamoleServerException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws GuacamoleException {
|
||||||
|
try {
|
||||||
|
logger.debug("Closing socket to guacd.");
|
||||||
|
sock.close();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new GuacamoleServerException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GuacamoleReader getReader() {
|
||||||
|
return reader;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GuacamoleWriter getWriter() {
|
||||||
|
return writer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isOpen() {
|
||||||
|
return !sock.isClosed();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* Classes which apply to network-specific concepts, such as low-level sockets
|
||||||
|
* and tunnels.
|
||||||
|
*/
|
||||||
|
package net.sourceforge.guacamole.net;
|
||||||
|
|
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* All classes which apply generally across the Guacamole web application
|
||||||
|
* and all other web applications which use the API provided by the
|
||||||
|
* Guacamole project.
|
||||||
|
*/
|
||||||
|
package net.sourceforge.guacamole;
|
||||||
|
|
@@ -0,0 +1,206 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.guacamole.protocol;
|
||||||
|
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* 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 guacamole-common.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is
|
||||||
|
* Michael Jumper.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import net.sourceforge.guacamole.GuacamoleException;
|
||||||
|
import net.sourceforge.guacamole.GuacamoleServerException;
|
||||||
|
import net.sourceforge.guacamole.io.GuacamoleReader;
|
||||||
|
import net.sourceforge.guacamole.io.GuacamoleWriter;
|
||||||
|
import net.sourceforge.guacamole.net.GuacamoleSocket;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A GuacamoleSocket which pre-configures the connection based on a given
|
||||||
|
* GuacamoleConfiguration, completing the initial protocol handshake before
|
||||||
|
* accepting data for read or write.
|
||||||
|
*
|
||||||
|
* This is useful for forcing a connection to the Guacamole proxy server with
|
||||||
|
* a specific configuration while disallowing the client that will be using
|
||||||
|
* this GuacamoleSocket from manually controlling the initial protocol
|
||||||
|
* handshake.
|
||||||
|
*
|
||||||
|
* @author Michael Jumper
|
||||||
|
*/
|
||||||
|
public class ConfiguredGuacamoleSocket implements GuacamoleSocket {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The wrapped socket.
|
||||||
|
*/
|
||||||
|
private GuacamoleSocket socket;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The configuration to use when performing the Guacamole protocol
|
||||||
|
* handshake.
|
||||||
|
*/
|
||||||
|
private GuacamoleConfiguration config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new ConfiguredGuacamoleSocket which uses the given
|
||||||
|
* GuacamoleConfiguration to complete the initial protocol handshake over
|
||||||
|
* the given GuacamoleSocket. A default GuacamoleClientInformation object
|
||||||
|
* is used to provide basic client information.
|
||||||
|
*
|
||||||
|
* @param socket The GuacamoleSocket to wrap.
|
||||||
|
* @param config The GuacamoleConfiguration to use to complete the initial
|
||||||
|
* protocol handshake.
|
||||||
|
* @throws GuacamoleException If an error occurs while completing the
|
||||||
|
* initial protocol handshake.
|
||||||
|
*/
|
||||||
|
public ConfiguredGuacamoleSocket(GuacamoleSocket socket,
|
||||||
|
GuacamoleConfiguration config) throws GuacamoleException {
|
||||||
|
this(socket, config, new GuacamoleClientInformation());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new ConfiguredGuacamoleSocket which uses the given
|
||||||
|
* GuacamoleConfiguration and GuacamoleClientInformation to complete the
|
||||||
|
* initial protocol handshake over the given GuacamoleSocket.
|
||||||
|
*
|
||||||
|
* @param socket The GuacamoleSocket to wrap.
|
||||||
|
* @param config The GuacamoleConfiguration to use to complete the initial
|
||||||
|
* protocol handshake.
|
||||||
|
* @param info The GuacamoleClientInformation to use to complete the initial
|
||||||
|
* protocol handshake.
|
||||||
|
* @throws GuacamoleException If an error occurs while completing the
|
||||||
|
* initial protocol handshake.
|
||||||
|
*/
|
||||||
|
public ConfiguredGuacamoleSocket(GuacamoleSocket socket,
|
||||||
|
GuacamoleConfiguration config,
|
||||||
|
GuacamoleClientInformation info) throws GuacamoleException {
|
||||||
|
|
||||||
|
this.socket = socket;
|
||||||
|
this.config = config;
|
||||||
|
|
||||||
|
// Get reader and writer
|
||||||
|
GuacamoleReader reader = socket.getReader();
|
||||||
|
GuacamoleWriter writer = socket.getWriter();
|
||||||
|
|
||||||
|
// Send protocol
|
||||||
|
writer.writeInstruction(new GuacamoleInstruction("select", config.getProtocol()));
|
||||||
|
|
||||||
|
// Wait for server args
|
||||||
|
GuacamoleInstruction instruction;
|
||||||
|
do {
|
||||||
|
|
||||||
|
// Read instruction, fail if end-of-stream
|
||||||
|
instruction = reader.readInstruction();
|
||||||
|
if (instruction == null)
|
||||||
|
throw new GuacamoleServerException("End of stream during initial handshake.");
|
||||||
|
|
||||||
|
} while (!instruction.getOpcode().equals("args"));
|
||||||
|
|
||||||
|
// Build args list off provided names and config
|
||||||
|
List<String> arg_names = instruction.getArgs();
|
||||||
|
String[] arg_values = new String[arg_names.size()];
|
||||||
|
for (int i=0; i<arg_names.size(); i++) {
|
||||||
|
|
||||||
|
// Retrieve argument name
|
||||||
|
String arg_name = arg_names.get(i);
|
||||||
|
|
||||||
|
// Get defined value for name
|
||||||
|
String value = config.getParameter(arg_name);
|
||||||
|
|
||||||
|
// If value defined, set that value
|
||||||
|
if (value != null) arg_values[i] = value;
|
||||||
|
|
||||||
|
// Otherwise, leave value blank
|
||||||
|
else arg_values[i] = "";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send size
|
||||||
|
writer.writeInstruction(
|
||||||
|
new GuacamoleInstruction(
|
||||||
|
"size",
|
||||||
|
Integer.toString(info.getOptimalScreenWidth()),
|
||||||
|
Integer.toString(info.getOptimalScreenHeight())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Send supported audio formats
|
||||||
|
writer.writeInstruction(
|
||||||
|
new GuacamoleInstruction(
|
||||||
|
"audio",
|
||||||
|
info.getAudioMimetypes().toArray(new String[0])
|
||||||
|
));
|
||||||
|
|
||||||
|
// Send supported video formats
|
||||||
|
writer.writeInstruction(
|
||||||
|
new GuacamoleInstruction(
|
||||||
|
"video",
|
||||||
|
info.getVideoMimetypes().toArray(new String[0])
|
||||||
|
));
|
||||||
|
|
||||||
|
// Send args
|
||||||
|
writer.writeInstruction(new GuacamoleInstruction("connect", arg_values));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the GuacamoleConfiguration used to configure this
|
||||||
|
* ConfiguredGuacamoleSocket.
|
||||||
|
*
|
||||||
|
* @return The GuacamoleConfiguration used to configure this
|
||||||
|
* ConfiguredGuacamoleSocket.
|
||||||
|
*/
|
||||||
|
public GuacamoleConfiguration getConfiguration() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GuacamoleWriter getWriter() {
|
||||||
|
return socket.getWriter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GuacamoleReader getReader() {
|
||||||
|
return socket.getReader();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws GuacamoleException {
|
||||||
|
socket.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isOpen() {
|
||||||
|
return socket.isOpen();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,125 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.guacamole.protocol;
|
||||||
|
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* 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 guacamole-common.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is
|
||||||
|
* Michael Jumper.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An abstract representation of Guacamole client information, including all
|
||||||
|
* information required by the Guacamole protocol during the preamble.
|
||||||
|
*
|
||||||
|
* @author Michael Jumper
|
||||||
|
*/
|
||||||
|
public class GuacamoleClientInformation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The optimal screen width requested by the client, in pixels.
|
||||||
|
*/
|
||||||
|
private int optimalScreenWidth = 1024;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The optimal screen height requested by the client, in pixels.
|
||||||
|
*/
|
||||||
|
private int optimalScreenHeight = 768;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The list of audio mimetypes reported by the client to be supported.
|
||||||
|
*/
|
||||||
|
private List<String> audioMimetypes = new ArrayList<String>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The list of audio mimetypes reported by the client to be supported.
|
||||||
|
*/
|
||||||
|
private List<String> videoMimetypes = new ArrayList<String>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the optimal screen width requested by the client, in pixels.
|
||||||
|
* @return The optimal screen width requested by the client, in pixels.
|
||||||
|
*/
|
||||||
|
public int getOptimalScreenWidth() {
|
||||||
|
return optimalScreenWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the client's optimal screen width.
|
||||||
|
* @param optimalScreenWidth The optimal screen width of the client.
|
||||||
|
*/
|
||||||
|
public void setOptimalScreenWidth(int optimalScreenWidth) {
|
||||||
|
this.optimalScreenWidth = optimalScreenWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the optimal screen height requested by the client, in pixels.
|
||||||
|
* @return The optimal screen height requested by the client, in pixels.
|
||||||
|
*/
|
||||||
|
public int getOptimalScreenHeight() {
|
||||||
|
return optimalScreenHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the client's optimal screen height.
|
||||||
|
* @param optimalScreenHeight The optimal screen height of the client.
|
||||||
|
*/
|
||||||
|
public void setOptimalScreenHeight(int optimalScreenHeight) {
|
||||||
|
this.optimalScreenHeight = optimalScreenHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the list of audio mimetypes supported by the client. To add or
|
||||||
|
* removed supported mimetypes, the list returned by this function can be
|
||||||
|
* modified.
|
||||||
|
*
|
||||||
|
* @return The set of audio mimetypes supported by the client.
|
||||||
|
*/
|
||||||
|
public List<String> getAudioMimetypes() {
|
||||||
|
return audioMimetypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the list of video mimetypes supported by the client. To add or
|
||||||
|
* removed supported mimetypes, the list returned by this function can be
|
||||||
|
* modified.
|
||||||
|
*
|
||||||
|
* @return The set of video mimetypes supported by the client.
|
||||||
|
*/
|
||||||
|
public List<String> getVideoMimetypes() {
|
||||||
|
return videoMimetypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,125 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.guacamole.protocol;
|
||||||
|
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* 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 guacamole-common.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is
|
||||||
|
* Michael Jumper.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All information necessary to complete the initial protocol handshake of a
|
||||||
|
* Guacamole session.
|
||||||
|
*
|
||||||
|
* @author Michael Jumper
|
||||||
|
*/
|
||||||
|
public class GuacamoleConfiguration implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Identifier unique to this version of GuacamoleConfiguration.
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the protocol associated with this configuration.
|
||||||
|
*/
|
||||||
|
private String protocol;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map of all associated parameter values, indexed by parameter name.
|
||||||
|
*/
|
||||||
|
private Map<String, String> parameters = new HashMap<String, String>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of the protocol to be used.
|
||||||
|
* @return The name of the protocol to be used.
|
||||||
|
*/
|
||||||
|
public String getProtocol() {
|
||||||
|
return protocol;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the name of the protocol to be used.
|
||||||
|
* @param protocol The name of the protocol to be used.
|
||||||
|
*/
|
||||||
|
public void setProtocol(String protocol) {
|
||||||
|
this.protocol = protocol;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value set for the parameter with the given name, if any.
|
||||||
|
* @param name The name of the parameter to return the value for.
|
||||||
|
* @return The value of the parameter with the given name, or null if
|
||||||
|
* that parameter has not been set.
|
||||||
|
*/
|
||||||
|
public String getParameter(String name) {
|
||||||
|
return parameters.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value for the parameter with the given name.
|
||||||
|
*
|
||||||
|
* @param name The name of the parameter to set the value for.
|
||||||
|
* @param value The value to set for the parameter with the given name.
|
||||||
|
*/
|
||||||
|
public void setParameter(String name, String value) {
|
||||||
|
parameters.put(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the value set for the parameter with the given name.
|
||||||
|
*
|
||||||
|
* @param name The name of the parameter to remove the value of.
|
||||||
|
*/
|
||||||
|
public void unsetParameter(String name) {
|
||||||
|
parameters.remove(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a set of all currently defined parameter names. Each name
|
||||||
|
* corresponds to a parameter that has a value set on this
|
||||||
|
* GuacamoleConfiguration via setParameter().
|
||||||
|
*
|
||||||
|
* @return A set of all currently defined parameter names.
|
||||||
|
*/
|
||||||
|
public Set<String> getParameterNames() {
|
||||||
|
return Collections.unmodifiableSet(parameters.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,127 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.guacamole.protocol;
|
||||||
|
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* 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 guacamole-common.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is
|
||||||
|
* Michael Jumper.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An abstract representation of a Guacamole instruction, as defined by the
|
||||||
|
* Guacamole protocol.
|
||||||
|
*
|
||||||
|
* @author Michael Jumper
|
||||||
|
*/
|
||||||
|
public class GuacamoleInstruction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The opcode of this instruction.
|
||||||
|
*/
|
||||||
|
private String opcode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All arguments of this instruction, in order.
|
||||||
|
*/
|
||||||
|
private List<String> args;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new GuacamoleInstruction having the given Operation and
|
||||||
|
* list of arguments values.
|
||||||
|
*
|
||||||
|
* @param opcode The opcode of the instruction to create.
|
||||||
|
* @param args The list of argument values to provide in the new
|
||||||
|
* instruction if any.
|
||||||
|
*/
|
||||||
|
public GuacamoleInstruction(String opcode, String... args) {
|
||||||
|
this.opcode = opcode;
|
||||||
|
this.args = Collections.unmodifiableList(Arrays.asList(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the opcode associated with this GuacamoleInstruction.
|
||||||
|
* @return The opcode associated with this GuacamoleInstruction.
|
||||||
|
*/
|
||||||
|
public String getOpcode() {
|
||||||
|
return opcode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a List of all argument values specified for this
|
||||||
|
* GuacamoleInstruction. Note that the List returned is immutable.
|
||||||
|
* Attempts to modify the list will result in exceptions.
|
||||||
|
*
|
||||||
|
* @return A List of all argument values specified for this
|
||||||
|
* GuacamoleInstruction.
|
||||||
|
*/
|
||||||
|
public List<String> getArgs() {
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns this GuacamoleInstruction in the form it would be sent over the
|
||||||
|
* Guacamole protocol.
|
||||||
|
*
|
||||||
|
* @return This GuacamoleInstruction in the form it would be sent over the
|
||||||
|
* Guacamole protocol.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
|
||||||
|
StringBuilder buff = new StringBuilder();
|
||||||
|
|
||||||
|
// Write opcode
|
||||||
|
buff.append(opcode.length());
|
||||||
|
buff.append('.');
|
||||||
|
buff.append(opcode);
|
||||||
|
|
||||||
|
// Write argument values
|
||||||
|
for (String value : args) {
|
||||||
|
buff.append(',');
|
||||||
|
buff.append(value.length());
|
||||||
|
buff.append('.');
|
||||||
|
buff.append(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write terminator
|
||||||
|
buff.append(';');
|
||||||
|
|
||||||
|
return buff.toString();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* Classes relating directly to the Guacamole protocol.
|
||||||
|
*/
|
||||||
|
package net.sourceforge.guacamole.protocol;
|
||||||
|
|
@@ -0,0 +1,452 @@
|
|||||||
|
package net.sourceforge.guacamole.servlet;
|
||||||
|
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* 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 guacamole-common.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is
|
||||||
|
* Michael Jumper.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.io.Writer;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
import net.sourceforge.guacamole.GuacamoleClientException;
|
||||||
|
import net.sourceforge.guacamole.GuacamoleException;
|
||||||
|
import net.sourceforge.guacamole.GuacamoleResourceNotFoundException;
|
||||||
|
import net.sourceforge.guacamole.GuacamoleSecurityException;
|
||||||
|
import net.sourceforge.guacamole.GuacamoleServerException;
|
||||||
|
import net.sourceforge.guacamole.io.GuacamoleReader;
|
||||||
|
import net.sourceforge.guacamole.io.GuacamoleWriter;
|
||||||
|
import net.sourceforge.guacamole.net.GuacamoleTunnel;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A HttpServlet implementing and abstracting the operations required by the
|
||||||
|
* HTTP implementation of the JavaScript Guacamole client's tunnel.
|
||||||
|
*
|
||||||
|
* @author Michael Jumper
|
||||||
|
*/
|
||||||
|
public abstract class GuacamoleHTTPTunnelServlet extends HttpServlet {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logger for this class.
|
||||||
|
*/
|
||||||
|
private Logger logger = LoggerFactory.getLogger(GuacamoleHTTPTunnelServlet.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The prefix of the query string which denotes a tunnel read operation.
|
||||||
|
*/
|
||||||
|
private static final String READ_PREFIX = "read:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The prefix of the query string which denotes a tunnel write operation.
|
||||||
|
*/
|
||||||
|
private static final String WRITE_PREFIX = "write:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The length of the read prefix, in characters.
|
||||||
|
*/
|
||||||
|
private static final int READ_PREFIX_LENGTH = READ_PREFIX.length();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The length of the write prefix, in characters.
|
||||||
|
*/
|
||||||
|
private static final int WRITE_PREFIX_LENGTH = WRITE_PREFIX.length();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The length of every tunnel UUID, in characters.
|
||||||
|
*/
|
||||||
|
private static final int UUID_LENGTH = 36;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException {
|
||||||
|
handleTunnelRequest(request, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
|
||||||
|
handleTunnelRequest(request, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends an error on the given HTTP response with the given integer error
|
||||||
|
* code.
|
||||||
|
*
|
||||||
|
* @param response The HTTP response to use to send the error.
|
||||||
|
* @param code The HTTP status code of the error.
|
||||||
|
* @throws ServletException If an error prevents sending of the error
|
||||||
|
* code.
|
||||||
|
*/
|
||||||
|
private void sendError(HttpServletResponse response, int code) throws ServletException {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
// If response not committed, send error code
|
||||||
|
if (!response.isCommitted())
|
||||||
|
response.sendError(code);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (IOException ioe) {
|
||||||
|
|
||||||
|
// If unable to send error at all due to I/O problems,
|
||||||
|
// rethrow as servlet exception
|
||||||
|
throw new ServletException(ioe);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispatches every HTTP GET and POST request to the appropriate handler
|
||||||
|
* function based on the query string.
|
||||||
|
*
|
||||||
|
* @param request The HttpServletRequest associated with the GET or POST
|
||||||
|
* request received.
|
||||||
|
* @param response The HttpServletResponse associated with the GET or POST
|
||||||
|
* request received.
|
||||||
|
* @throws ServletException If an error occurs while servicing the request.
|
||||||
|
*/
|
||||||
|
protected void handleTunnelRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
String query = request.getQueryString();
|
||||||
|
if (query == null)
|
||||||
|
throw new GuacamoleClientException("No query string provided.");
|
||||||
|
|
||||||
|
// If connect operation, call doConnect() and return tunnel UUID
|
||||||
|
// in response.
|
||||||
|
if (query.equals("connect")) {
|
||||||
|
|
||||||
|
GuacamoleTunnel tunnel = doConnect(request);
|
||||||
|
if (tunnel != null) {
|
||||||
|
|
||||||
|
// Get session
|
||||||
|
HttpSession httpSession = request.getSession(true);
|
||||||
|
GuacamoleSession session = new GuacamoleSession(httpSession);
|
||||||
|
|
||||||
|
// Attach tunnel to session
|
||||||
|
session.attachTunnel(tunnel);
|
||||||
|
|
||||||
|
logger.info("Connection from {} succeeded.", request.getRemoteAddr());
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Ensure buggy browsers do not cache response
|
||||||
|
response.setHeader("Cache-Control", "no-cache");
|
||||||
|
|
||||||
|
// Send UUID to client
|
||||||
|
response.getWriter().print(tunnel.getUUID().toString());
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new GuacamoleServerException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Failed to connect
|
||||||
|
else {
|
||||||
|
logger.info("Connection from {} failed.", request.getRemoteAddr());
|
||||||
|
throw new GuacamoleResourceNotFoundException("No tunnel created.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// If read operation, call doRead() with tunnel UUID, ignoring any
|
||||||
|
// characters following the tunnel UUID.
|
||||||
|
else if(query.startsWith(READ_PREFIX))
|
||||||
|
doRead(request, response, query.substring(
|
||||||
|
READ_PREFIX_LENGTH,
|
||||||
|
READ_PREFIX_LENGTH + UUID_LENGTH));
|
||||||
|
|
||||||
|
// If write operation, call doWrite() with tunnel UUID, ignoring any
|
||||||
|
// characters following the tunnel UUID.
|
||||||
|
else if(query.startsWith(WRITE_PREFIX))
|
||||||
|
doWrite(request, response, query.substring(
|
||||||
|
WRITE_PREFIX_LENGTH,
|
||||||
|
WRITE_PREFIX_LENGTH + UUID_LENGTH));
|
||||||
|
|
||||||
|
// Otherwise, invalid operation
|
||||||
|
else
|
||||||
|
throw new GuacamoleClientException("Invalid tunnel operation: " + query);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Catch any thrown guacamole exception and attempt to pass within the
|
||||||
|
// HTTP response, logging each error appropriately.
|
||||||
|
catch (GuacamoleSecurityException e) {
|
||||||
|
logger.warn("Authorization failed.", e);
|
||||||
|
sendError(response, HttpServletResponse.SC_FORBIDDEN);
|
||||||
|
}
|
||||||
|
catch (GuacamoleResourceNotFoundException e) {
|
||||||
|
logger.debug("Resource not found.", e);
|
||||||
|
sendError(response, HttpServletResponse.SC_NOT_FOUND);
|
||||||
|
}
|
||||||
|
catch (GuacamoleClientException e) {
|
||||||
|
logger.warn("Error in client request.", e);
|
||||||
|
sendError(response, HttpServletResponse.SC_BAD_REQUEST);
|
||||||
|
}
|
||||||
|
catch (GuacamoleException e) {
|
||||||
|
logger.error("Server error in tunnel", e);
|
||||||
|
sendError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called whenever the JavaScript Guacamole client makes a connection
|
||||||
|
* request. It it up to the implementor of this function to define what
|
||||||
|
* conditions must be met for a tunnel to be configured and returned as a
|
||||||
|
* result of this connection request (whether some sort of credentials must
|
||||||
|
* be specified, for example).
|
||||||
|
*
|
||||||
|
* @param request The HttpServletRequest associated with the connection
|
||||||
|
* request received. Any parameters specified along with
|
||||||
|
* the connection request can be read from this object.
|
||||||
|
* @return A newly constructed GuacamoleTunnel if successful,
|
||||||
|
* null otherwise.
|
||||||
|
* @throws GuacamoleException If an error occurs while constructing the
|
||||||
|
* GuacamoleTunnel, or if the conditions
|
||||||
|
* required for connection are not met.
|
||||||
|
*/
|
||||||
|
protected abstract GuacamoleTunnel doConnect(HttpServletRequest request) throws GuacamoleException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called whenever the JavaScript Guacamole client makes a read request.
|
||||||
|
* This function should in general not be overridden, as it already
|
||||||
|
* contains a proper implementation of the read operation.
|
||||||
|
*
|
||||||
|
* @param request The HttpServletRequest associated with the read request
|
||||||
|
* received.
|
||||||
|
* @param response The HttpServletResponse associated with the write request
|
||||||
|
* received. Any data to be sent to the client in response
|
||||||
|
* to the write request should be written to the response
|
||||||
|
* body of this HttpServletResponse.
|
||||||
|
* @param tunnelUUID The UUID of the tunnel to read from, as specified in
|
||||||
|
* the write request. This tunnel must be attached to
|
||||||
|
* the Guacamole session.
|
||||||
|
* @throws GuacamoleException If an error occurs while handling the read
|
||||||
|
* request.
|
||||||
|
*/
|
||||||
|
protected void doRead(HttpServletRequest request, HttpServletResponse response, String tunnelUUID) throws GuacamoleException {
|
||||||
|
|
||||||
|
HttpSession httpSession = request.getSession(false);
|
||||||
|
GuacamoleSession session = new GuacamoleSession(httpSession);
|
||||||
|
|
||||||
|
// Get tunnel, ensure tunnel exists
|
||||||
|
GuacamoleTunnel tunnel = session.getTunnel(tunnelUUID);
|
||||||
|
if (tunnel == null)
|
||||||
|
throw new GuacamoleResourceNotFoundException("No such tunnel.");
|
||||||
|
|
||||||
|
// Ensure tunnel is open
|
||||||
|
if (!tunnel.isOpen())
|
||||||
|
throw new GuacamoleResourceNotFoundException("Tunnel is closed.");
|
||||||
|
|
||||||
|
// Obtain exclusive read access
|
||||||
|
GuacamoleReader reader = tunnel.acquireReader();
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Note that although we are sending text, Webkit browsers will
|
||||||
|
// buffer 1024 bytes before starting a normal stream if we use
|
||||||
|
// anything but application/octet-stream.
|
||||||
|
response.setContentType("application/octet-stream");
|
||||||
|
response.setHeader("Cache-Control", "no-cache");
|
||||||
|
|
||||||
|
// Get writer for response
|
||||||
|
Writer out = new BufferedWriter(new OutputStreamWriter(
|
||||||
|
response.getOutputStream(), "UTF-8"));
|
||||||
|
|
||||||
|
// Stream data to response, ensuring output stream is closed
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Detach tunnel and throw error if EOF (and we haven't sent any
|
||||||
|
// data yet.
|
||||||
|
char[] message = reader.read();
|
||||||
|
if (message == null)
|
||||||
|
throw new GuacamoleResourceNotFoundException("Tunnel reached end of stream.");
|
||||||
|
|
||||||
|
// For all messages, until another stream is ready (we send at least one message)
|
||||||
|
do {
|
||||||
|
|
||||||
|
// Get message output bytes
|
||||||
|
out.write(message, 0, message.length);
|
||||||
|
|
||||||
|
// Flush if we expect to wait
|
||||||
|
if (!reader.available()) {
|
||||||
|
out.flush();
|
||||||
|
response.flushBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
// No more messages another stream can take over
|
||||||
|
if (tunnel.hasQueuedReaderThreads())
|
||||||
|
break;
|
||||||
|
|
||||||
|
} while (tunnel.isOpen() && (message = reader.read()) != null);
|
||||||
|
|
||||||
|
// Close tunnel immediately upon EOF
|
||||||
|
if (message == null)
|
||||||
|
tunnel.close();
|
||||||
|
|
||||||
|
// End-of-instructions marker
|
||||||
|
out.write("0.;");
|
||||||
|
out.flush();
|
||||||
|
response.flushBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Always close output stream
|
||||||
|
finally {
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (GuacamoleException e) {
|
||||||
|
|
||||||
|
// Detach and close
|
||||||
|
session.detachTunnel(tunnel);
|
||||||
|
tunnel.close();
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
|
||||||
|
// Log typically frequent I/O error if desired
|
||||||
|
logger.debug("Error writing to servlet output stream", e);
|
||||||
|
|
||||||
|
// Detach and close
|
||||||
|
session.detachTunnel(tunnel);
|
||||||
|
tunnel.close();
|
||||||
|
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
tunnel.releaseReader();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called whenever the JavaScript Guacamole client makes a write request.
|
||||||
|
* This function should in general not be overridden, as it already
|
||||||
|
* contains a proper implementation of the write operation.
|
||||||
|
*
|
||||||
|
* @param request The HttpServletRequest associated with the write request
|
||||||
|
* received. Any data to be written will be specified within
|
||||||
|
* the body of this request.
|
||||||
|
* @param response The HttpServletResponse associated with the write request
|
||||||
|
* received.
|
||||||
|
* @param tunnelUUID The UUID of the tunnel to write to, as specified in
|
||||||
|
* the write request. This tunnel must be attached to
|
||||||
|
* the Guacamole session.
|
||||||
|
* @throws GuacamoleException If an error occurs while handling the write
|
||||||
|
* request.
|
||||||
|
*/
|
||||||
|
protected void doWrite(HttpServletRequest request, HttpServletResponse response, String tunnelUUID) throws GuacamoleException {
|
||||||
|
|
||||||
|
HttpSession httpSession = request.getSession(false);
|
||||||
|
GuacamoleSession session = new GuacamoleSession(httpSession);
|
||||||
|
|
||||||
|
GuacamoleTunnel tunnel = session.getTunnel(tunnelUUID);
|
||||||
|
if (tunnel == null)
|
||||||
|
throw new GuacamoleResourceNotFoundException("No such tunnel.");
|
||||||
|
|
||||||
|
// We still need to set the content type to avoid the default of
|
||||||
|
// text/html, as such a content type would cause some browsers to
|
||||||
|
// attempt to parse the result, even though the JavaScript client
|
||||||
|
// does not explicitly request such parsing.
|
||||||
|
response.setContentType("application/octet-stream");
|
||||||
|
response.setHeader("Cache-Control", "no-cache");
|
||||||
|
response.setContentLength(0);
|
||||||
|
|
||||||
|
// Send data
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Get writer from tunnel
|
||||||
|
GuacamoleWriter writer = tunnel.acquireWriter();
|
||||||
|
|
||||||
|
// Get input reader for HTTP stream
|
||||||
|
Reader input = new InputStreamReader(
|
||||||
|
request.getInputStream(), "UTF-8");
|
||||||
|
|
||||||
|
// Transfer data from input stream to tunnel output, ensuring
|
||||||
|
// input is always closed
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Buffer
|
||||||
|
int length;
|
||||||
|
char[] buffer = new char[8192];
|
||||||
|
|
||||||
|
// Transfer data using buffer
|
||||||
|
while (tunnel.isOpen() &&
|
||||||
|
(length = input.read(buffer, 0, buffer.length)) != -1)
|
||||||
|
writer.write(buffer, 0, length);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close input stream in all cases
|
||||||
|
finally {
|
||||||
|
input.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
|
||||||
|
// Detach and close
|
||||||
|
session.detachTunnel(tunnel);
|
||||||
|
tunnel.close();
|
||||||
|
|
||||||
|
throw new GuacamoleServerException("I/O Error sending data to server: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
tunnel.releaseWriter();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \example ExampleTunnelServlet.java
|
||||||
|
*
|
||||||
|
* A basic example demonstrating extending GuacamoleTunnelServlet and
|
||||||
|
* implementing doConnect() to configure the Guacamole connection as
|
||||||
|
* desired.
|
||||||
|
*/
|
||||||
|
|
@@ -0,0 +1,125 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.guacamole.servlet;
|
||||||
|
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* 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 guacamole-common.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is
|
||||||
|
* Michael Jumper.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
import net.sourceforge.guacamole.GuacamoleException;
|
||||||
|
import net.sourceforge.guacamole.GuacamoleSecurityException;
|
||||||
|
import net.sourceforge.guacamole.net.GuacamoleTunnel;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides abstract access to the tunnels associated with a Guacamole session.
|
||||||
|
*
|
||||||
|
* @author Michael Jumper
|
||||||
|
*/
|
||||||
|
public class GuacamoleSession {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logger for this class.
|
||||||
|
*/
|
||||||
|
private Logger logger = LoggerFactory.getLogger(GuacamoleSession.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map of all currently attached tunnels, indexed by tunnel UUID.
|
||||||
|
*/
|
||||||
|
private ConcurrentMap<String, GuacamoleTunnel> tunnels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new GuacamoleSession, storing and retrieving tunnels from the
|
||||||
|
* given HttpSession. Note that the true Guacamole session is tied to the
|
||||||
|
* HttpSession provided, thus creating a new GuacamoleSession does not
|
||||||
|
* create a new Guacamole session; it merely creates a new object for
|
||||||
|
* accessing the tunnels of an existing Guacamole session represented by
|
||||||
|
* the provided HttpSession.
|
||||||
|
*
|
||||||
|
* @param session The HttpSession to use as tunnel storage.
|
||||||
|
* @throws GuacamoleException If session is null.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public GuacamoleSession(HttpSession session) throws GuacamoleException {
|
||||||
|
|
||||||
|
if (session == null)
|
||||||
|
throw new GuacamoleSecurityException("User has no session.");
|
||||||
|
|
||||||
|
synchronized (session) {
|
||||||
|
|
||||||
|
tunnels = (ConcurrentMap<String, GuacamoleTunnel>) session.getAttribute("GUAC_TUNNELS");
|
||||||
|
if (tunnels == null) {
|
||||||
|
tunnels = new ConcurrentHashMap<String, GuacamoleTunnel>();
|
||||||
|
session.setAttribute("GUAC_TUNNELS", tunnels);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attaches the given tunnel to this GuacamoleSession.
|
||||||
|
* @param tunnel The tunnel to attach to this GucacamoleSession.
|
||||||
|
*/
|
||||||
|
public void attachTunnel(GuacamoleTunnel tunnel) {
|
||||||
|
tunnels.put(tunnel.getUUID().toString(), tunnel);
|
||||||
|
logger.debug("Attached tunnel {}.", tunnel.getUUID());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detaches the given tunnel to this GuacamoleSession.
|
||||||
|
* @param tunnel The tunnel to detach to this GucacamoleSession.
|
||||||
|
*/
|
||||||
|
public void detachTunnel(GuacamoleTunnel tunnel) {
|
||||||
|
tunnels.remove(tunnel.getUUID().toString());
|
||||||
|
logger.debug("Detached tunnel {}.", tunnel.getUUID());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the tunnel with the given UUID attached to this GuacamoleSession,
|
||||||
|
* if any.
|
||||||
|
*
|
||||||
|
* @param tunnelUUID The UUID of an attached tunnel.
|
||||||
|
* @return The tunnel corresponding to the given UUID, if attached, or null
|
||||||
|
* if no such tunnel is attached.
|
||||||
|
*/
|
||||||
|
public GuacamoleTunnel getTunnel(String tunnelUUID) {
|
||||||
|
return tunnels.get(tunnelUUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* Classes which build upon the Java Servlet API, providing an HTTP-based
|
||||||
|
* tunnel and session management.
|
||||||
|
*/
|
||||||
|
package net.sourceforge.guacamole.servlet;
|
||||||
|
|
Reference in New Issue
Block a user