Merge libguac project.

This commit is contained in:
Michael Jumper 2013-06-04 15:51:58 -07:00
commit 801338b06b
52 changed files with 9847 additions and 0 deletions

48
libguac/.gitignore vendored Normal file
View File

@ -0,0 +1,48 @@
# Object code
*.o
*.so
*.lo
*.la
# Test binaries
tests/test_*
!tests/test_*.[ch]
# gcov files
*.gcda
*.gcov
*.gcno
# Backup files
*~
# Release files
*.tar.gz
# Files currently being edited by vim or vi
*.swp
# automake/autoconf
.deps/
.libs/
Makefile
Makefile.in
aclocal.m4
autom4te.cache/
m4/*
!README
config.guess
config.log
config.status
config.sub
configure
depcomp
install-sh
libtool
ltmain.sh
missing
# Generated docs
doc/doxygen-output

1
libguac/AUTHORS Normal file
View File

@ -0,0 +1 @@
Michael Jumper <zhangmaike@users.sourceforge.net>

55
libguac/ChangeLog Normal file
View File

@ -0,0 +1,55 @@
2012-10-25 Michael Jumper <zhangmzike@users.sourceforge.net>
* Implement video instruction
* Implement chunked write versions of audio/video functions
2012-10-24 Michael Jumper <zhangmzike@users.sourceforge.net>
* Implement audio instruction
2012-10-22 Michael Jumper <zhangmzike@users.sourceforge.net>
* Implement protocol nesting (via "nest" instruction)
* Add size events
* Add guac_client_info structure to be populated during handshake
2012-07-23 Michael Jumper <zhangmaike@users.sourceforge.net>
* Add unit tests for Unicode in protocol
* Fix handling of Unicode (UTF-8) characters in protocol
2012-05-23 David Pham-Van <d.pham-van@ulteo.com>
* Corrected padding in base64 encoding
2012-05-04 Michael Jumper <zhangmaike@users.sourceforge.net>
* Buffer/layer allocation and pooling fixes
* Automatic PNG palletization
* Fix error reporting
* Add log handlers for guac_client_plugin_get_client()
* Add layer and drawing instructions
* Reorganized source
* Raster operations
* Cacheable cursors
2011-12-11 Michael Jumper <zhangmaike@users.sourceforge.net>
* Added functions for alloc/free of layers and buffers
* Added "clip" instruction
* New, more efficient instruction format
* Fixed guac_write_base64 to match docs
* Added guac_error for error reporting and logging
* Consistent naming conventions
* Migrated daemon-specific functionality to guacd
* Made private members of structs private (using double-underscore prefix)
2011-03-14 Michael Jumper <zhangmaike@users.sourceforge.net>
* Lag control ("sync" message)
* Automatic message handle frequency limiting
2011-02-28 Michael Jumper <zhangmaike@users.sourceforge.net>
* Initial release

470
libguac/LICENSE Normal file
View 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.]

43
libguac/Makefile.am Normal file
View File

@ -0,0 +1,43 @@
# ***** 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 libguac.
#
# 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 *****
AUTOMAKE_OPTIONS = foreign
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = src . tests
EXTRA_DIST = LICENSE doc/Doxyfile

79
libguac/README Normal file
View File

@ -0,0 +1,79 @@
------------------------------------------------------------
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 libguac?
------------------------------------------------------------
libguac is the core library for guacd (the Guacamole proxy) and any protocol
support plugins for guacd.
libguac provides efficient buffered I/O of text and base64 data, as well as
somewhat abstracted functions for sending Guacamole instructions.
------------------------------------------------------------
Compiling and installing libguac
------------------------------------------------------------
Please note that distribution-specific pre-compiled packages are available from
the files section of the main project site:
http://sourceforge.net/projects/guacamole/files/
libguac is built using the popular GNU Automake, and thus provides the standard
configure script.
1) Run configure
$ ./configure
Assuming all dependencies have been installed, this should succeed without
errors.
2) Run make
$ make
libguac will now compile.
3) Install (as root)
# make install
libguac will install to your /usr/local/lib directory by default. You can
change the install location by using the --prefix option for configure.
Several header files will also be installed to
/usr/local/include/guacamole.
You will need to run ldconfig (as root) so that the library can be found
when guacd is run:
# ldconfig
------------------------------------------------------------
Reporting problems
------------------------------------------------------------
Please report any bugs encountered by opening a new ticket at the Trac system
hosted at:
http://guac-dev.org/trac/

79
libguac/configure.in Normal file
View File

@ -0,0 +1,79 @@
# ***** 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 libguac.
#
# 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 *****
AC_INIT(src/client.c)
AM_INIT_AUTOMAKE(libguac, 0.7.0)
AC_CONFIG_MACRO_DIR([m4])
# Checks for programs.
AC_PROG_CC
AC_PROG_CC_C99
AC_PROG_LIBTOOL
# POSIX
AC_DEFINE(_POSIX_C_SOURCE, 199309L)
# BSD
AC_DEFINE(_BSD_SOURCE)
# Checks for libraries.
AC_CHECK_LIB([dl], [dlopen],, AC_MSG_ERROR("libdl is required for loading client plugins"))
AC_CHECK_LIB([png], [png_write_png],, AC_MSG_ERROR("libpng is required for writing png messages"))
AC_CHECK_LIB([cairo], [cairo_create],, AC_MSG_ERROR("cairo is required for drawing instructions"))
AC_CHECK_LIB([pthread], [pthread_create])
AC_CHECK_LIB([wsock32], [main])
# Checks for header files.
AC_CHECK_HEADERS([fcntl.h stdlib.h string.h sys/socket.h time.h sys/time.h syslog.h unistd.h cairo/cairo.h pngstruct.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_CHECK_FUNCS([clock_gettime gettimeofday memmove memset select strdup png_get_io_ptr nanosleep])
# Check for unit testing library
AC_CHECK_LIB([cunit], [CU_run_test], [CUNIT_LIBS=-lcunit])
AC_SUBST(CUNIT_LIBS)
AC_CONFIG_FILES([Makefile
src/Makefile
tests/Makefile])
AC_OUTPUT

1551
libguac/doc/Doxyfile Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,125 @@
/* ***** 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 libguac.
*
* 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 ***** */
#ifndef _GUAC_CLIENT_HANDLERS__H
#define _GUAC_CLIENT_HANDLERS__H
#include "client.h"
#include "instruction.h"
/**
* Provides initial handler functions and a lookup structure for automatically
* handling client instructions. This is used only internally within libguac,
* and is not installed along with the library.
*
* @file client-handlers.h
*/
/**
* Internal handler for Guacamole instructions.
*/
typedef int __guac_instruction_handler(guac_client* client, guac_instruction* copied);
/**
* Structure mapping an instruction opcode to an instruction handler.
*/
typedef struct __guac_instruction_handler_mapping {
/**
* The instruction opcode which maps to a specific handler.
*/
char* opcode;
/**
* The handler which maps to a specific opcode.
*/
__guac_instruction_handler* handler;
} __guac_instruction_handler_mapping;
/**
* Internal initial handler for the sync instruction. When a sync instruction
* is received, this handler will be called. Sync instructions are automatically
* handled, thus there is no client handler for sync instruction.
*/
int __guac_handle_sync(guac_client* client, guac_instruction* instruction);
/**
* Internal initial handler for the mouse instruction. When a mouse instruction
* is received, this handler will be called. The client's mouse handler will
* be invoked if defined.
*/
int __guac_handle_mouse(guac_client* client, guac_instruction* instruction);
/**
* Internal initial handler for the key instruction. When a key instruction
* is received, this handler will be called. The client's key handler will
* be invoked if defined.
*/
int __guac_handle_key(guac_client* client, guac_instruction* instruction);
/**
* Internal initial handler for the clipboard instruction. When a clipboard instruction
* is received, this handler will be called. The client's clipboard handler will
* be invoked if defined.
*/
int __guac_handle_clipboard(guac_client* client, guac_instruction* instruction);
/**
* Internal initial handler for the size instruction. When a size instruction
* is received, this handler will be called. The client's size handler will
* be invoked if defined.
*/
int __guac_handle_size(guac_client* client, guac_instruction* instruction);
/**
* Internal initial handler for the disconnect instruction. When a disconnect instruction
* is received, this handler will be called. Disconnect instructions are automatically
* handled, thus there is no client handler for disconnect instruction.
*/
int __guac_handle_disconnect(guac_client* client, guac_instruction* instruction);
/**
* Instruction handler mapping table. This is a NULL-terminated array of
* __guac_instruction_handler_mapping structures, each mapping an opcode
* to a __guac_instruction_handler. The end of the array must be marked
* with a __guac_instruction_handler_mapping with the opcode set to
* NULL (the NULL terminator).
*/
extern __guac_instruction_handler_mapping __guac_instruction_handler_map[];
#endif

597
libguac/include/client.h Normal file
View File

@ -0,0 +1,597 @@
/* ***** 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 libguac.
*
* 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 ***** */
#ifndef _GUAC_CLIENT_H
#define _GUAC_CLIENT_H
#include <stdarg.h>
#include "instruction.h"
#include "layer.h"
#include "pool.h"
#include "socket.h"
#include "stream.h"
#include "timestamp.h"
/**
* Provides functions and structures required for defining (and handling) a proxy client.
*
* @file client.h
*/
typedef struct guac_client guac_client;
/**
* Handler for server messages (where "server" refers to the server that
* the proxy client is connected to).
*/
typedef int guac_client_handle_messages(guac_client* client);
/**
* Handler for Guacamole mouse events.
*/
typedef int guac_client_mouse_handler(guac_client* client, int x, int y, int button_mask);
/**
* Handler for Guacamole key events.
*/
typedef int guac_client_key_handler(guac_client* client, int keysym, int pressed);
/**
* Handler for Guacamole clipboard events.
*/
typedef int guac_client_clipboard_handler(guac_client* client, char* copied);
/**
* Handler for Guacamole screen size events.
*/
typedef int guac_client_size_handler(guac_client* client,
int width, int height);
/**
* Handler for Guacamole audio format events.
*/
typedef int guac_client_audio_handler(guac_client* client, char* mimetype);
/**
* Handler for Guacamole video format events.
*/
typedef int guac_client_video_handler(guac_client* client, char* mimetype);
/**
* Handler for freeing up any extra data allocated by the client
* implementation.
*/
typedef int guac_client_free_handler(guac_client* client);
/**
* Handler for logging messages
*/
typedef void guac_client_log_handler(guac_client* client, const char* format, va_list args);
/**
* Handler which should initialize the given guac_client.
*/
typedef int guac_client_init_handler(guac_client* client, int argc, char** argv);
/**
* The flag set in the mouse button mask when the left mouse button is down.
*/
#define GUAC_CLIENT_MOUSE_LEFT 0x01
/**
* The flag set in the mouse button mask when the middle mouse button is down.
*/
#define GUAC_CLIENT_MOUSE_MIDDLE 0x02
/**
* The flag set in the mouse button mask when the right mouse button is down.
*/
#define GUAC_CLIENT_MOUSE_RIGHT 0x04
/**
* The flag set in the mouse button mask when the mouse scrollwheel is scrolled
* up. Note that mouse scrollwheels are actually sets of two buttons. One
* button is pressed and released for an upward scroll, and the other is
* pressed and released for a downward scroll. Some mice may actually implement
* these as separate buttons, not a wheel.
*/
#define GUAC_CLIENT_MOUSE_SCROLL_UP 0x08
/**
* The flag set in the mouse button mask when the mouse scrollwheel is scrolled
* down. Note that mouse scrollwheels are actually sets of two buttons. One
* button is pressed and released for an upward scroll, and the other is
* pressed and released for a downward scroll. Some mice may actually implement
* these as separate buttons, not a wheel.
*/
#define GUAC_CLIENT_MOUSE_SCROLL_DOWN 0x10
/**
* The minimum number of buffers to create before allowing free'd buffers to
* be reclaimed. In the case a protocol rapidly creates, uses, and destroys
* buffers, this can prevent unnecessary reuse of the same buffer (which
* would make draw operations unnecessarily synchronous).
*/
#define GUAC_BUFFER_POOL_INITIAL_SIZE 1024
/**
* Possible current states of the Guacamole client. Currently, the only
* two states are GUAC_CLIENT_RUNNING and GUAC_CLIENT_STOPPING.
*/
typedef enum guac_client_state {
/**
* The state of the client from when it has been allocated by the main
* daemon until it is killed or disconnected.
*/
GUAC_CLIENT_RUNNING,
/**
* The state of the client when a stop has been requested, signalling the
* I/O threads to shutdown.
*/
GUAC_CLIENT_STOPPING
} guac_client_state;
/**
* Information exposed by the remote client during the connection handshake
* which can be used by a client plugin.
*/
typedef struct guac_client_info {
/**
* The number of pixels the remote client requests for the display width.
* This need not be honored by a client plugin implementation, but if the
* underlying protocol of the client plugin supports dynamic sizing of the
* screen, honoring the display size request is recommended.
*/
int optimal_width;
/**
* The number of pixels the remote client requests for the display height.
* This need not be honored by a client plugin implementation, but if the
* underlying protocol of the client plugin supports dynamic sizing of the
* screen, honoring the display size request is recommended.
*/
int optimal_height;
/**
* NULL-terminated array of client-supported audio mimetypes. If the client
* does not support audio at all, this will be NULL.
*/
const char** audio_mimetypes;
/**
* NULL-terminated array of client-supported video mimetypes. If the client
* does not support video at all, this will be NULL.
*/
const char** video_mimetypes;
} guac_client_info;
/**
* Guacamole proxy client.
*
* Represents a Guacamole proxy client (the client which communicates to
* a server on behalf of Guacamole, on behalf of the web-client).
*/
struct guac_client {
/**
* The guac_socket structure to be used to communicate with the web-client.
* It is expected that the implementor of any Guacamole proxy client will
* provide their own mechanism of I/O for their protocol. The guac_socket
* structure is used only to communicate conveniently with the Guacamole
* web-client.
*/
guac_socket* socket;
/**
* The current state of the client. When the client is first allocated,
* this will be initialized to GUAC_CLIENT_RUNNING. It will remain at
* GUAC_CLIENT_RUNNING until an event occurs which requires the client to
* shutdown, at which point the state becomes GUAC_CLIENT_STOPPING.
*/
guac_client_state state;
/**
* The time (in milliseconds) of receipt of the last sync message from
* the client.
*/
guac_timestamp last_received_timestamp;
/**
* The time (in milliseconds) that the last sync message was sent to the
* client.
*/
guac_timestamp last_sent_timestamp;
/**
* Information structure containing properties exposed by the remote
* client during the initial handshake process.
*/
guac_client_info info;
/**
* Arbitrary reference to proxy client-specific data. Implementors of a
* Guacamole proxy client can store any data they want here, which can then
* be retrieved as necessary in the message handlers.
*/
void* data;
/**
* Handler for server messages. If set, this function will be called
* occasionally by the Guacamole proxy to give the client a chance to
* handle messages from whichever server it is connected to.
*
* Example:
* @code
* int handle_messages(guac_client* client);
*
* int guac_client_init(guac_client* client, int argc, char** argv) {
* client->handle_messages = handle_messages;
* }
* @endcode
*/
guac_client_handle_messages* handle_messages;
/**
* Handler for mouse events sent by the Gaucamole web-client.
*
* The handler takes the integer mouse X and Y coordinates, as well as
* a button mask containing the bitwise OR of all button values currently
* being pressed. Those values are:
*
* <table>
* <tr><th>Button</th> <th>Value</th></tr>
* <tr><td>Left</td> <td>1</td></tr>
* <tr><td>Middle</td> <td>2</td></tr>
* <tr><td>Right</td> <td>4</td></tr>
* <tr><td>Scrollwheel Up</td> <td>8</td></tr>
* <tr><td>Scrollwheel Down</td><td>16</td></tr>
* </table>
* Example:
* @code
* int mouse_handler(guac_client* client, int x, int y, int button_mask);
*
* int guac_client_init(guac_client* client, int argc, char** argv) {
* client->mouse_handler = mouse_handler;
* }
* @endcode
*/
guac_client_mouse_handler* mouse_handler;
/**
* Handler for key events sent by the Guacamole web-client.
*
* The handler takes the integer X11 keysym associated with the key
* being pressed/released, and an integer representing whether the key
* is being pressed (1) or released (0).
*
* Example:
* @code
* int key_handler(guac_client* client, int keysym, int pressed);
*
* int guac_client_init(guac_client* client, int argc, char** argv) {
* client->key_handler = key_handler;
* }
* @endcode
*/
guac_client_key_handler* key_handler;
/**
* Handler for clipboard events sent by the Guacamole web-client. This
* handler will be called whenever the web-client sets the data of the
* clipboard.
*
* This handler takes a single string which contains the text which
* has been set in the clipboard. This text is already unescaped from
* the Guacamole escaped version sent within the clipboard message
* in the protocol.
*
* Example:
* @code
* int clipboard_handler(guac_client* client, char* copied);
*
* int guac_client_init(guac_client* client, int argc, char** argv) {
* client->clipboard_handler = clipboard_handler;
* }
* @endcode
*/
guac_client_clipboard_handler* clipboard_handler;
/**
* Handler for size events sent by the Guacamole web-client.
*
* The handler takes an integer width and integer height, representing
* the current visible screen area of the client.
*
* Example:
* @code
* int size_handler(guac_client* client, int width, int height);
*
* int guac_client_init(guac_client* client, int argc, char** argv) {
* client->size_handler = size_handler;
* }
* @endcode
*/
guac_client_size_handler* size_handler;
/**
* Handler for freeing data when the client is being unloaded.
*
* This handler will be called when the client needs to be unloaded
* by the proxy, and any data allocated by the proxy client should be
* freed.
*
* Note that this handler will NOT be called if the client's
* guac_client_init() function fails.
*
* Implement this handler if you store data inside the client.
*
* Example:
* @code
* int free_handler(guac_client* client);
*
* int guac_client_init(guac_client* client, int argc, char** argv) {
* client->free_handler = free_handler;
* }
* @endcode
*/
guac_client_free_handler* free_handler;
/**
* Handler for logging informational messages. This handler will be called
* via guac_client_log_info() when the client needs to log information.
*
* In general, only programs loading the client should implement this
* handler, as those are the programs that would provide the logging
* facilities.
*
* Client implementations should expect these handlers to already be
* set.
*
* Example:
* @code
* void log_handler(guac_client* client, const char* format, va_list args);
*
* void function_of_daemon() {
*
* guac_client* client = [pass log_handler to guac_client_plugin_get_client()];
*
* }
* @endcode
*/
guac_client_log_handler* log_info_handler;
/**
* Handler for logging error messages. This handler will be called
* via guac_client_log_error() when the client needs to log an error.
*
* In general, only programs loading the client should implement this
* handler, as those are the programs that would provide the logging
* facilities.
*
* Client implementations should expect these handlers to already be
* set.
*
* Example:
* @code
* void log_handler(guac_client* client, const char* format, va_list args);
*
* void function_of_daemon() {
*
* guac_client* client = [pass log_handler to guac_client_plugin_get_client()];
*
* }
* @endcode
*/
guac_client_log_handler* log_error_handler;
/**
* Pool of buffer indices. Buffers are simply layers with negative indices.
* Note that because guac_pool always gives non-negative indices starting
* at 0, the output of this guac_pool will be adjusted.
*/
guac_pool* __buffer_pool;
/**
* Pool of layer indices. Note that because guac_pool always gives
* non-negative indices starting at 0, the output of this guac_pool will
* be adjusted.
*/
guac_pool* __layer_pool;
/**
* Pool of stream indices.
*/
guac_pool* __stream_pool;
};
/**
* Returns a new, barebones guac_client. This new guac_client has no handlers
* set, but is otherwise usable.
*
* @return A pointer to the new client.
*/
guac_client* guac_client_alloc();
/**
* Free all resources associated with the given client.
*
* @param client The proxy client to free all reasources of.
*/
void guac_client_free(guac_client* client);
/**
* Call the appropriate handler defined by the given client for the given
* instruction. A comparison is made between the instruction opcode and the
* initial handler lookup table defined in client-handlers.c. The intial
* handlers will in turn call the client's handler (if defined).
*
* @param client The proxy client whose handlers should be called.
* @param instruction The instruction to pass to the proxy client via the
* appropriate handler.
*/
int guac_client_handle_instruction(guac_client* client, guac_instruction* instruction);
/**
* Logs an informational message in the log used by the given client. The
* logger used will normally be defined by guacd (or whichever program loads
* the proxy client) by setting the logging handlers of the client when it is
* loaded.
*
* @param client The proxy client to log an informational message for.
* @param format A printf-style format string to log.
* @param ... Arguments to use when filling the format string for printing.
*/
void guac_client_log_info(guac_client* client, const char* format, ...);
/**
* Logs an error message in the log used by the given client. The logger
* used will normally be defined by guacd (or whichever program loads the
* proxy client) by setting the logging handlers of the client when it is
* loaded.
*
* @param client The proxy client to log an error for.
* @param format A printf-style format string to log.
* @param ... Arguments to use when filling the format string for printing.
*/
void guac_client_log_error(guac_client* client, const char* format, ...);
/**
* Logs an informational message in the log used by the given client. The
* logger used will normally be defined by guacd (or whichever program loads
* the proxy client) by setting the logging handlers of the client when it is
* loaded.
*
* @param client The proxy client to log an informational message for.
* @param format A printf-style format string to log.
* @param ap The va_list containing the arguments to be used when filling the
* format string for printing.
*/
void vguac_client_log_info(guac_client* client, const char* format, va_list ap);
/**
* Logs an error message in the log used by the given client. The logger
* used will normally be defined by guacd (or whichever program loads the
* proxy client) by setting the logging handlers of the client when it is
* loaded.
*
* @param client The proxy client to log an error for.
* @param format A printf-style format string to log.
* @param ap The va_list containing the arguments to be used when filling the
* format string for printing.
*/
void vguac_client_log_error(guac_client* client, const char* format, va_list ap);
/**
* Signals the given client to stop gracefully. This is a completely
* cooperative signal, and can be ignored by the client or the hosting
* daemon.
*
* @param client The proxy client to signal to stop.
*/
void guac_client_stop(guac_client* client);
/**
* Allocates a new buffer (invisible layer). An arbitrary index is
* automatically assigned if no existing buffer is available for use.
*
* @param client The proxy client to allocate the buffer for.
* @return The next available buffer, or a newly allocated buffer.
*/
guac_layer* guac_client_alloc_buffer(guac_client* client);
/**
* Allocates a new layer. An arbitrary index is automatically assigned
* if no existing layer is available for use.
*
* @param client The proxy client to allocate the layer buffer for.
* @return The next available layer, or a newly allocated layer.
*/
guac_layer* guac_client_alloc_layer(guac_client* client);
/**
* Returns the given buffer to the pool of available buffers, such that it
* can be reused by any subsequent call to guac_client_allow_buffer().
*
* @param client The proxy client to return the buffer to.
* @param layer The buffer to return to the pool of available buffers.
*/
void guac_client_free_buffer(guac_client* client, guac_layer* layer);
/**
* Returns the given layer to the pool of available layers, such that it
* can be reused by any subsequent call to guac_client_allow_layer().
*
* @param client The proxy client to return the layer to.
* @param layer The buffer to return to the pool of available layer.
*/
void guac_client_free_layer(guac_client* client, guac_layer* layer);
/**
* Allocates a new stream. An arbitrary index is automatically assigned
* if no previously-allocated stream is available for use.
*
* @param client The proxy client to allocate the layer buffer for.
* @return The next available stream, or a newly allocated stream.
*/
guac_stream* guac_client_alloc_stream(guac_client* client);
/**
* Returns the given stream to the pool of available streams, such that it
* can be reused by any subsequent call to guac_client_alloc_stream().
*
* @param client The proxy client to return the buffer to.
* @param stream The stream to return to the pool of available stream.
*/
void guac_client_free_stream(guac_client* client, guac_stream* stream);
/**
* The default Guacamole client layer, layer 0.
*/
extern const guac_layer* GUAC_DEFAULT_LAYER;
#endif

132
libguac/include/error.h Normal file
View File

@ -0,0 +1,132 @@
/* ***** 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 libguac.
*
* 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 ***** */
#ifndef _GUAC_ERROR_H
#define _GUAC_ERROR_H
/**
* Provides functions and structures required for handling return values and
* errors.
*
* @file error.h
*/
/**
* Return codes shared by all Guacamole functions which can fail.
*/
typedef enum guac_status {
/**
* No errors occurred and the operation was successful.
*/
GUAC_STATUS_SUCCESS = 0,
/**
* Insufficient memory to complete the operation.
*/
GUAC_STATUS_NO_MEMORY,
/**
* The end of the input stream associated with the operation
* has been reached.
*/
GUAC_STATUS_NO_INPUT,
/**
* A timeout occurred while reading from the input stream associated
* with the operation.
*/
GUAC_STATUS_INPUT_TIMEOUT,
/**
* An error occurred, and further information about the error is already
* stored in errno.
*/
GUAC_STATUS_SEE_ERRNO,
/**
* An error prevented the operation from writing to its associated
* output stream.
*/
GUAC_STATUS_OUTPUT_ERROR,
/**
* The operation could not be performed because an invalid argument was
* given.
*/
GUAC_STATUS_BAD_ARGUMENT,
/**
* The state of the associated system prevents an operation from being
* performed which would otherwise be allowed.
*/
GUAC_STATUS_BAD_STATE
} guac_status;
/**
* Returns a human-readable explanation of the status code given.
*/
const char* guac_status_string(guac_status status);
/**
* Returns the status code associated with the error which occurred during the
* last function call. This value will only be set by functions documented to
* use it (most libguac functions), and is undefined if no error occurred.
*
* The storage of this value is thread-local. Assignment of a status code to
* guac_error in one thread will not affect its value in another thread.
*/
#define guac_error (*__guac_error())
guac_status* __guac_error();
/**
* Returns a message describing the error which occurred during the last
* function call. If an error occurred, but no message is associated with it,
* NULL is returned. This value is undefined if no error occurred.
*
* The storage of this value is thread-local. Assignment of a message to
* guac_error_message in one thread will not affect its value in another
* thread.
*/
#define guac_error_message (*__guac_error_message())
const char** __guac_error_message();
#endif

76
libguac/include/hash.h Normal file
View File

@ -0,0 +1,76 @@
/* ***** 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 libguac.
*
* 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 ***** */
#ifndef _GUAC_HASH_H
#define _GUAC_HASH_H
#include <cairo/cairo.h>
/**
* Provides functions and structures for producing likely-to-be-unique hash
* values for images.
*
* @file hash.h
*/
/**
* Produces a 24-bit hash value from all pixels of the given surface. The
* surface provided must be RGB or ARGB with each pixel stored in 32 bits.
* The hashing algorithm used is a variant of the cyclic polynomial rolling
* hash.
*
* @param surface The Cairo surface to hash.
* @return An arbitrary 24-bit unsigned integer value intended to be well
* distributed across different images.
*/
unsigned int guac_hash_surface(cairo_surface_t* surface);
/**
* Given two Cairo surfaces, returns zero if the data contained within each
* is identical, and a positive or negative value if the value of the first
* is found to be lexically greater or less than the second respectively.
*
* @param a The first Cairo surface to compare.
* @param b The Cairo surface to compare the first surface against.
* @return Zero if the data contained within each is identical, and a positive
* or negative value if the value of the first is found to be lexically
* greater or less than the second respectively.
*/
int guac_surface_cmp(cairo_surface_t* a, cairo_surface_t* b);
#endif

View File

@ -0,0 +1,133 @@
/* ***** 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 libguac.
*
* 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 ***** */
#ifndef _GUAC_INSTRUCTION_H
#define _GUAC_INSTRUCTION_H
#include "socket.h"
/**
* Provides functions and structures for reading, writing, and manipulating
* Guacamole instructions.
*
* @file instruction.h
*/
/**
* Represents a single instruction within the Guacamole protocol.
*/
typedef struct guac_instruction {
/**
* The opcode of the instruction.
*/
char* opcode;
/**
* The number of arguments passed to this instruction.
*/
int argc;
/**
* Array of all arguments passed to this instruction.
*/
char** argv;
} guac_instruction;
/**
* Frees all memory allocated to the given instruction.
*
* @param instruction The instruction to free.
*/
void guac_instruction_free(guac_instruction* instruction);
/**
* Returns whether new instruction data is available on the given guac_socket
* connection for parsing.
*
* @param socket The guac_socket connection to use.
* @param usec_timeout The maximum number of microseconds to wait before
* giving up.
* @return A positive value if data is available, negative on error, or
* zero if no data is currently available.
*/
int guac_instruction_waiting(guac_socket* socket, int usec_timeout);
/**
* Reads a single instruction from the given guac_socket connection.
*
* If an error occurs reading the instruction, NULL is returned,
* and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param usec_timeout The maximum number of microseconds to wait before
* giving up.
* @return A new instruction if data was successfully read, NULL on
* error or if the instruction could not be read completely
* because the timeout elapsed, in which case guac_error will be
* set to GUAC_STATUS_INPUT_TIMEOUT and subsequent calls to
* guac_protocol_read_instruction() will return the parsed instruction
* once enough data is available.
*/
guac_instruction* guac_instruction_read(guac_socket* socket, int usec_timeout);
/**
* Reads a single instruction with the given opcode from the given guac_socket
* connection.
*
* If an error occurs reading the instruction, NULL is returned,
* and guac_error is set appropriately.
*
* If the instruction read is not the expected instruction, NULL is returned,
* and guac_error is set to GUAC_STATUS_BAD_STATE.
*
* @param socket The guac_socket connection to use.
* @param usec_timeout The maximum number of microseconds to wait before
* giving up.
* @param opcode The opcode of the instruction to read.
* @return A new instruction if an instruction with the given opcode was read,
* NULL otherwise. If an instruction was read, but the instruction had
* a different opcode, NULL is returned and guac_error is set to
* GUAC_STATUS_BAD_STATE.
*/
guac_instruction* guac_instruction_expect(guac_socket* socket,
int usec_timeout, const char* opcode);
#endif

62
libguac/include/layer.h Normal file
View File

@ -0,0 +1,62 @@
/* ***** 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 libguac.
*
* 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 ***** */
#ifndef _GUAC_LAYER_H
#define _GUAC_LAYER_H
/**
* Provides functions and structures required for allocating and using layers.
*
* @file layer.h
*/
typedef struct guac_layer guac_layer;
/**
* Represents a single layer within the Guacamole protocol.
*/
struct guac_layer {
/**
* The index of this layer.
*/
int index;
};
#endif

65
libguac/include/palette.h Normal file
View File

@ -0,0 +1,65 @@
/* ***** 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 libguac.
*
* 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 ***** */
#ifndef __GUAC_PALETTE_H
#define __GUAC_PALETTE_H
#include <png.h>
#include <cairo/cairo.h>
typedef struct guac_palette_entry {
int index;
int color;
} guac_palette_entry;
typedef struct guac_palette {
guac_palette_entry entries[0x1000];
png_color colors[256];
int size;
} guac_palette;
guac_palette* guac_palette_alloc(cairo_surface_t* surface);
int guac_palette_find(guac_palette* palette, int color);
void guac_palette_free(guac_palette* palette);
#endif

144
libguac/include/plugin.h Normal file
View File

@ -0,0 +1,144 @@
/* ***** 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 libguac.
*
* 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 ***** */
#ifndef _GUAC_PLUGIN_H
#define _GUAC_PLUGIN_H
#include "client.h"
/**
* Provides functions and structures required for handling a client plugin.
*
* @file plugin.h
*/
/**
* String prefix which begins the library filename of all client plugins.
*/
#define GUAC_PROTOCOL_LIBRARY_PREFIX "libguac-client-"
/**
* String suffix which ends the library filename of all client plugins.
*/
#define GUAC_PROTOCOL_LIBRARY_SUFFIX ".so"
/**
* The maximum number of characters (COUNTING NULL TERMINATOR) to allow
* for protocol names within the library filename of client plugins.
*/
#define GUAC_PROTOCOL_NAME_LIMIT 256
/**
* The maximum number of characters (INCLUDING NULL TERMINATOR) that a
* character array containing the concatenation of the library prefix,
* protocol name, and suffix can contain, assuming the protocol name is
* limited to GUAC_PROTOCOL_NAME_LIMIT characters.
*/
#define GUAC_PROTOCOL_LIBRARY_LIMIT ( \
\
sizeof(GUAC_PROTOCOL_LIBRARY_PREFIX) - 1 /* "libguac-client-" */ \
+ GUAC_PROTOCOL_NAME_LIMIT - 1 /* [up to 256 chars] */ \
+ sizeof(GUAC_PROTOCOL_LIBRARY_SUFFIX) - 1 /* ".so" */ \
+ 1 /* NULL terminator */ \
\
)
typedef struct guac_client_plugin guac_client_plugin;
/**
* A handle to a client plugin, containing enough information about the
* plugin to complete the initial protocol handshake and instantiate a new
* client supporting the protocol provided by the client plugin.
*/
struct guac_client_plugin {
/**
* Reference to dlopen'd client plugin.
*/
void* __client_plugin_handle;
/**
* Reference to the init handler of this client plugin. This
* function will be called when the client plugin is started.
*/
guac_client_init_handler* init_handler;
/**
* NULL-terminated array of all arguments accepted by this client
* plugin, in order. The values of these arguments will be passed
* to the init_handler if the client plugin is started.
*/
const char** args;
};
/**
* Open the plugin which provides support for the given protocol, if it
* exists.
*
* @param protocol The name of the protocol to retrieve the client plugin
* for.
* @return The client plugin supporting the given protocol, or NULL if
* an error occurs or no such plugin exists.
*/
guac_client_plugin* guac_client_plugin_open(const char* protocol);
/**
* Close the given plugin, releasing all associated resources. This function
* must be called after use of a client plugin is finished.
*
* @param plugin The client plugin to close.
* @return Zero on success, non-zero if an error occurred while releasing
* the resources associated with the plugin.
*/
int guac_client_plugin_close(guac_client_plugin* plugin);
/**
* Initializes the given guac_client using the initialization routine provided
* by the given guac_client_plugin.
*
* @param plugin The client plugin to use to initialize the new client.
* @param client The guac_client to initialize.
* @param argc The number of arguments being passed to the client.
* @param argv All arguments to be passed to the client.
* @return Zero if initialization was successful, non-zero otherwise.
*/
int guac_client_plugin_init_client(guac_client_plugin* plugin,
guac_client* client, int argc, char** argv);
#endif

140
libguac/include/pool.h Normal file
View File

@ -0,0 +1,140 @@
/* ***** 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 libguac.
*
* 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 ***** */
#ifndef _GUAC_POOL_H
#define _GUAC_POOL_H
/**
* Provides functions and structures for maintaining dynamically allocated and
* freed pools of integers.
*
* @file pool.h
*/
typedef struct guac_pool_int guac_pool_int;
/**
* A pool of integers. Integers can be removed from and later free'd back
* into the pool. New integers are returned when the pool is exhausted,
* or when the pool has not met some minimum size. Old, free'd integers
* are returned otherwise.
*/
typedef struct guac_pool {
/**
* The minimum number of integers which must have been returned by
* guac_pool_next_int before previously-used and freed integers are
* allowed to be returned.
*/
int min_size;
/**
* The next integer to be released (after no more integers remain in the
* pool.
*/
int __next_value;
/**
* The first integer in the pool, if any.
*/
guac_pool_int* __head;
/**
* The last integer in the pool, if any.
*/
guac_pool_int* __tail;
} guac_pool;
/**
* Represents a single integer within a larger pool of integers.
*/
struct guac_pool_int {
/**
* The integer value of this pool entry.
*/
int value;
/**
* The next available (unused) guac_pool_int in the list of
* allocated but free'd ints.
*/
guac_pool_int* __next;
};
/**
* Allocates a new guac_pool having the given minimum size.
*
* @param size The minimum number of integers which must have been returned by
* guac_pool_next_int before freed integers (previously used integers)
* are allowed to be returned.
* @return A new, empty guac_pool, having the given minimum size.
*/
guac_pool* guac_pool_alloc(int size);
/**
* Frees the given guac_pool.
*
* @param pool The guac_pool to free.
*/
void guac_pool_free(guac_pool* pool);
/**
* Returns the next available integer from the given guac_pool. All integers returned are
* non-negative, and are returned in sequences, starting from 0.
*
* @param pool The guac_pool to retrieve an integer from.
* @return The next available integer, which may be either an integer not yet returned
* by a call to guac_pool_next_int, or an integer which was previosly returned,
* but has since been freed.
*/
int guac_pool_next_int(guac_pool* pool);
/**
* Frees the given integer back into the given guac_pool. The integer given will be
* available for future calls to guac_pool_next_int.
*
* @param pool The guac_pool to free the given integer into.
* @param value The integer which should be readded to the given pool, such that it can
* be received by a future call to guac_pool_next_int.
*/
void guac_pool_free_int(guac_pool* pool, int value);
#endif

953
libguac/include/protocol.h Normal file
View File

@ -0,0 +1,953 @@
/* ***** 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 libguac.
*
* 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 ***** */
#ifndef _GUAC_PROTOCOL_H
#define _GUAC_PROTOCOL_H
#include <cairo/cairo.h>
#include "layer.h"
#include "socket.h"
#include "timestamp.h"
/**
* Provides functions and structures required for communicating using the
* Guacamole protocol over a guac_socket connection, such as that provided by
* guac_client objects.
*
* @file protocol.h
*/
/**
* Composite modes used by Guacamole draw instructions. Each
* composite mode maps to a unique channel mask integer.
*/
typedef enum guac_composite_mode {
/*
* A: Source where destination transparent = S n D'
* B: Source where destination opaque = S n D
* C: Destination where source transparent = D n S'
* D: Destination where source opaque = D n S
*
* 0 = Active, 1 = Inactive
*/
/* ABCD */
GUAC_COMP_ROUT = 0x2, /* 0010 - Clears destination where source opaque */
GUAC_COMP_ATOP = 0x6, /* 0110 - Fill where destination opaque only */
GUAC_COMP_XOR = 0xA, /* 1010 - XOR */
GUAC_COMP_ROVER = 0xB, /* 1011 - Fill where destination transparent only */
GUAC_COMP_OVER = 0xE, /* 1110 - Draw normally */
GUAC_COMP_PLUS = 0xF, /* 1111 - Add */
/* Unimplemented in client: */
/* NOT IMPLEMENTED: 0000 - Clear */
/* NOT IMPLEMENTED: 0011 - No operation */
/* NOT IMPLEMENTED: 0101 - Additive IN */
/* NOT IMPLEMENTED: 0111 - Additive ATOP */
/* NOT IMPLEMENTED: 1101 - Additive RATOP */
/* Buggy in webkit browsers, as they keep channel C on in all cases: */
GUAC_COMP_RIN = 0x1, /* 0001 */
GUAC_COMP_IN = 0x4, /* 0100 */
GUAC_COMP_OUT = 0x8, /* 1000 */
GUAC_COMP_RATOP = 0x9, /* 1001 */
GUAC_COMP_SRC = 0xC /* 1100 */
/* Bitwise composite operations (binary) */
/*
* A: S' & D'
* B: S' & D
* C: S & D'
* D: S & D
*
* 0 = Active, 1 = Inactive
*/
} guac_composite_mode;
/**
* Default transfer functions. There is no current facility in the
* Guacamole protocol to define custom transfer functions.
*/
typedef enum guac_transfer_function {
/* Constant functions */ /* ABCD */
GUAC_TRANSFER_BINARY_BLACK = 0x0, /* 0000 */
GUAC_TRANSFER_BINARY_WHITE = 0xF, /* 1111 */
/* Copy functions */
GUAC_TRANSFER_BINARY_SRC = 0x3, /* 0011 */
GUAC_TRANSFER_BINARY_DEST = 0x5, /* 0101 */
GUAC_TRANSFER_BINARY_NSRC = 0xC, /* 1100 */
GUAC_TRANSFER_BINARY_NDEST = 0xA, /* 1010 */
/* AND / NAND */
GUAC_TRANSFER_BINARY_AND = 0x1, /* 0001 */
GUAC_TRANSFER_BINARY_NAND = 0xE, /* 1110 */
/* OR / NOR */
GUAC_TRANSFER_BINARY_OR = 0x7, /* 0111 */
GUAC_TRANSFER_BINARY_NOR = 0x8, /* 1000 */
/* XOR / XNOR */
GUAC_TRANSFER_BINARY_XOR = 0x6, /* 0110 */
GUAC_TRANSFER_BINARY_XNOR = 0x9, /* 1001 */
/* AND / NAND with inverted source */
GUAC_TRANSFER_BINARY_NSRC_AND = 0x4, /* 0100 */
GUAC_TRANSFER_BINARY_NSRC_NAND = 0xB, /* 1011 */
/* OR / NOR with inverted source */
GUAC_TRANSFER_BINARY_NSRC_OR = 0xD, /* 1101 */
GUAC_TRANSFER_BINARY_NSRC_NOR = 0x2, /* 0010 */
/* AND / NAND with inverted destination */
GUAC_TRANSFER_BINARY_NDEST_AND = 0x2, /* 0010 */
GUAC_TRANSFER_BINARY_NDEST_NAND = 0xD, /* 1101 */
/* OR / NOR with inverted destination */
GUAC_TRANSFER_BINARY_NDEST_OR = 0xB, /* 1011 */
GUAC_TRANSFER_BINARY_NDEST_NOR = 0x4 /* 0100 */
} guac_transfer_function;
/**
* Supported line cap styles
*/
typedef enum guac_line_cap_style {
GUAC_LINE_CAP_BUTT = 0x0,
GUAC_LINE_CAP_ROUND = 0x1,
GUAC_LINE_CAP_SQUARE = 0x2
} guac_line_cap_style;
/**
* Supported line join styles
*/
typedef enum guac_line_join_style {
GUAC_LINE_JOIN_BEVEL = 0x0,
GUAC_LINE_JOIN_MITER = 0x1,
GUAC_LINE_JOIN_ROUND = 0x2
} guac_line_join_style;
/* CONTROL INSTRUCTIONS */
/**
* Sends an args instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param args The NULL-terminated array of argument names (strings).
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_args(guac_socket* socket, const char** args);
/**
* Sends a connect instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param args The NULL-terminated array of argument values (strings).
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_connect(guac_socket* socket, const char** args);
/**
* Sends a disconnect instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_disconnect(guac_socket* socket);
/**
* Sends an error instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param error The description associated with the error.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_error(guac_socket* socket, const char* error);
/**
* Sends a nest instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param index The integer index of the stram to send the protocol
* data over.
* @param data A string containing protocol data, which must be UTF-8
* encoded and null-terminated.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_nest(guac_socket* socket, int index,
const char* data);
/**
* Sends a set instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param layer The layer to set the parameter of.
* @param name The name of the parameter to set.
* @param value The value to set the parameter to.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_set(guac_socket* socket, const guac_layer* layer,
const char* name, const char* value);
/**
* Sends a select instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param protocol The protocol to request.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_select(guac_socket* socket, const char* protocol);
/**
* Sends a sync instruction over the given guac_socket connection. The
* current time in milliseconds should be passed in as the timestamp.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param timestamp The current timestamp (in milliseconds).
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_sync(guac_socket* socket, guac_timestamp timestamp);
/* MEDIA INSTRUCTIONS */
/**
* Sends an audio instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param channel The index of the audio channel the sound should play on.
* @param mimetype The mimetype of the data being sent.
* @param duration The duration of the sound being sent, in milliseconds.
* @param data The audio data to be sent.
* @param size The number of bytes of audio data to send.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_audio(guac_socket* socket, int channel,
const char* mimetype, double duration, void* data, int size);
/**
* Begins a audio instruction over the given guac_socket connection. Only the
* initial non-data part of the instruction and the length of the data part
* of the instruction are sent. The actual contents of the data must be
* sent with guac_protocol_send_audio_data(), and the instruction must be
* completed with guac_protocol_send_audio_end().
*
* Note that the size of the audio to be sent MUST be known ahead of time,
* even though the data of the audio may be sent in chunks.
*
* No further instruction data may be sent along the givven guac_socket
* except via guac_protocol_send_audio_data() until the audio instruction
* is completed with guac_protocol_send_audio_end().
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param channel The index of the audio channel the sound should play on.
* @param mimetype The mimetype of the data being sent.
* @param duration The duration of the audio being sent, in milliseconds.
* @param size The number of bytes of audio data to send.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_audio_header(guac_socket* socket,
int channel, const char* mimetype, double duration, int size);
/**
* Writes a block of audio data to the currently in-progress audio instruction
* which was started with guac_protocol_send_audio_header(). Exactly the
* number of requested bytes are written unless an error occurs. This function
* may be called multiple times per audio instruction for each chunk of audio
* data being written, allowing the potentially huge audio instruction to be
* split across multiple writes.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param data The audio data to write.
* @param count The number of bytes within the given buffer of audio data
* that must be written.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_audio_data(guac_socket* socket, void* data, int count);
/**
* Completes the audio instruction which was started with
* guac_protocol_send_audio_header(), and whose data has been written with
* guac_protocol_send_audio_data().
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_audio_end(guac_socket* socket);
/**
* Sends a file instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param name A name describing the file being sent.
* @param mimetype The mimetype of the data being sent.
* @param data The file data to be sent.
* @param size The number of bytes of file data to send.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_file(guac_socket* socket, const char* name,
const char* mimetype, void* data, int size);
/**
* Begins a file instruction over the given guac_socket connection. Only the
* initial non-data part of the instruction and the length of the data part
* of the instruction are sent. The actual contents of the data must be
* sent with guac_protocol_send_file_data(), and the instruction must be
* completed with guac_protocol_send_file_end().
*
* Note that the size of the file to be sent MUST be known ahead of time,
* even though the data of the file may be sent in chunks.
*
* No further instruction data may be sent along the givven guac_socket
* except via guac_protocol_send_file_data() until the file instruction
* is completed with guac_protocol_send_file_end().
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param name A name describing the file being sent.
* @param mimetype The mimetype of the data being sent.
* @param size The number of bytes of file data to send.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_file_header(guac_socket* socket, const char* name,
const char* mimetype, int size);
/**
* Writes a block of file data to the currently in-progress file instruction
* which was started with guac_protocol_send_file_header(). Exactly the
* number of requested bytes are written unless an error occurs. This function
* may be called multiple times per file instruction for each chunk of file
* data being written, allowing the potentially huge file instruction to be
* split across multiple writes.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param data The file data to write.
* @param count The number of bytes within the given buffer of file data
* that must be written.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_file_data(guac_socket* socket, void* data, int count);
/**
* Completes the file instruction which was started with
* guac_protocol_send_file_header(), and whose data has been written with
* guac_protocol_send_file_data().
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_file_end(guac_socket* socket);
/**
* Sends a video instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param layer The destination layer.
* @param mimetype The mimetype of the data being sent.
* @param duration The duration of the video being sent, in milliseconds.
* @param data The video data to be sent.
* @param size The number of bytes of video data to send.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_video(guac_socket* socket, const guac_layer* layer,
const char* mimetype, double duration, void* data, int size);
/**
* Begins a video instruction over the given guac_socket connection. Only the
* initial non-data part of the instruction and the length of the data part
* of the instruction are sent. The actual contents of the data must be
* sent with guac_protocol_send_video_data(), and the instruction must be
* completed with guac_protocol_send_video_end().
*
* Note that the size of the video to be sent MUST be known ahead of time,
* even though the data of the video may be sent in chunks.
*
* No further instruction data may be sent along the givven guac_socket
* except via guac_protocol_send_video_data() until the video instruction
* is completed with guac_protocol_send_video_end().
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param layer The destination layer.
* @param mimetype The mimetype of the data being sent.
* @param duration The duration of the video being sent, in milliseconds.
* @param size The number of bytes of video data to send.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_video_header(guac_socket* socket,
const guac_layer* layer, const char* mimetype, double duration, int size);
/**
* Writes a block of video data to the currently in-progress video instruction
* which was started with guac_protocol_send_video_header(). Exactly the
* number of requested bytes are written unless an error occurs. This function
* may be called multiple times per video instruction for each chunk of video
* data being written, allowing the potentially huge video instruction to be
* split across multiple writes.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param data The video data to write.
* @param count The number of bytes within the given buffer of video data
* that must be written.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_video_data(guac_socket* socket, void* data, int count);
/**
* Completes the video instruction which was started with
* guac_protocol_send_video_header(), and whose data has been written with
* guac_protocol_send_video_data().
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_video_end(guac_socket* socket);
/* DRAWING INSTRUCTIONS */
/**
* Sends an arc instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param layer The destination layer.
* @param x The X coordinate of the center of the circle containing the arc.
* @param y The Y coordinate of the center of the circle containing the arc.
* @param radius The radius of the circle containing the arc.
* @param startAngle The starting angle, in radians.
* @param endAngle The ending angle, in radians.
* @param negative Zero if the arc should be drawn in order of increasing
* angle, non-zero otherwise.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_arc(guac_socket* socket, const guac_layer* layer,
int x, int y, int radius, double startAngle, double endAngle,
int negative);
/**
* Sends a cfill instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param mode The composite mode to use.
* @param layer The destination layer.
* @param r The red component of the color of the rectangle.
* @param g The green component of the color of the rectangle.
* @param b The blue component of the color of the rectangle.
* @param a The alpha (transparency) component of the color of the rectangle.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_cfill(guac_socket* socket,
guac_composite_mode mode, const guac_layer* layer,
int r, int g, int b, int a);
/**
* Sends a clip instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param layer The layer to set the clipping region of.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_clip(guac_socket* socket, const guac_layer* layer);
/**
* Sends a close instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param layer The destination layer.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_close(guac_socket* socket, const guac_layer* layer);
/**
* Sends a copy instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param srcl The source layer.
* @param srcx The X coordinate of the source rectangle.
* @param srcy The Y coordinate of the source rectangle.
* @param w The width of the source rectangle.
* @param h The height of the source rectangle.
* @param mode The composite mode to use.
* @param dstl The destination layer.
* @param dstx The X coordinate of the destination, where the source rectangle
* should be copied.
* @param dsty The Y coordinate of the destination, where the source rectangle
* should be copied.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_copy(guac_socket* socket,
const guac_layer* srcl, int srcx, int srcy, int w, int h,
guac_composite_mode mode, const guac_layer* dstl, int dstx, int dsty);
/**
* Sends a cstroke instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param mode The composite mode to use.
* @param layer The destination layer.
* @param cap The style of line cap to use when drawing the stroke.
* @param join The style of line join to use when drawing the stroke.
* @param thickness The thickness of the stroke in pixels.
* @param r The red component of the color of the rectangle.
* @param g The green component of the color of the rectangle.
* @param b The blue component of the color of the rectangle.
* @param a The alpha (transparency) component of the color of the rectangle.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_cstroke(guac_socket* socket,
guac_composite_mode mode, const guac_layer* layer,
guac_line_cap_style cap, guac_line_join_style join, int thickness,
int r, int g, int b, int a);
/**
* Sends a cursor instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param x The X coordinate of the cursor hotspot.
* @param y The Y coordinate of the cursor hotspot.
* @param srcl The source layer.
* @param srcx The X coordinate of the source rectangle.
* @param srcy The Y coordinate of the source rectangle.
* @param w The width of the source rectangle.
* @param h The height of the source rectangle.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_cursor(guac_socket* socket, int x, int y,
const guac_layer* srcl, int srcx, int srcy, int w, int h);
/**
* Sends a curve instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param layer The destination layer.
* @param cp1x The X coordinate of the first control point.
* @param cp1y The Y coordinate of the first control point.
* @param cp2x The X coordinate of the second control point.
* @param cp2y The Y coordinate of the second control point.
* @param x The X coordinate of the endpoint of the curve.
* @param y The Y coordinate of the endpoint of the curve.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_curve(guac_socket* socket, const guac_layer* layer,
int cp1x, int cp1y, int cp2x, int cp2y, int x, int y);
/**
* Sends an identity instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param layer The destination layer.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_identity(guac_socket* socket, const guac_layer* layer);
/**
* Sends an lfill instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param mode The composite mode to use.
* @param layer The destination layer.
* @param srcl The source layer.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_lfill(guac_socket* socket,
guac_composite_mode mode, const guac_layer* layer,
const guac_layer* srcl);
/**
* Sends a line instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param layer The destination layer.
* @param x The X coordinate of the endpoint of the line.
* @param y The Y coordinate of the endpoint of the line.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_line(guac_socket* socket, const guac_layer* layer,
int x, int y);
/**
* Sends an lstroke instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param mode The composite mode to use.
* @param layer The destination layer.
* @param cap The style of line cap to use when drawing the stroke.
* @param join The style of line join to use when drawing the stroke.
* @param thickness The thickness of the stroke in pixels.
* @param srcl The source layer.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_lstroke(guac_socket* socket,
guac_composite_mode mode, const guac_layer* layer,
guac_line_cap_style cap, guac_line_join_style join, int thickness,
const guac_layer* srcl);
/**
* Sends a png instruction over the given guac_socket connection. The PNG image
* data given will be automatically base64-encoded for transmission.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param mode The composite mode to use.
* @param layer The destination layer.
* @param x The destination X coordinate.
* @param y The destination Y coordinate.
* @param surface A cairo surface containing the image data to send.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_png(guac_socket* socket, guac_composite_mode mode,
const guac_layer* layer, int x, int y, cairo_surface_t* surface);
/**
* Sends a pop instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param layer The layer to set the clipping region of.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_pop(guac_socket* socket, const guac_layer* layer);
/**
* Sends a push instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param layer The layer to set the clipping region of.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_push(guac_socket* socket, const guac_layer* layer);
/**
* Sends a rect instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param layer The destination layer.
* @param x The X coordinate of the rectangle.
* @param y The Y coordinate of the rectangle.
* @param width The width of the rectangle.
* @param height The height of the rectangle.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_rect(guac_socket* socket, const guac_layer* layer,
int x, int y, int width, int height);
/**
* Sends a reset instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param layer The layer to set the clipping region of.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_reset(guac_socket* socket, const guac_layer* layer);
/**
* Sends a start instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param layer The destination layer.
* @param x The X coordinate of the first point of the subpath.
* @param y The Y coordinate of the first point of the subpath.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_start(guac_socket* socket, const guac_layer* layer,
int x, int y);
/**
* Sends a transfer instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param srcl The source layer.
* @param srcx The X coordinate of the source rectangle.
* @param srcy The Y coordinate of the source rectangle.
* @param w The width of the source rectangle.
* @param h The height of the source rectangle.
* @param fn The transfer function to use.
* @param dstl The destination layer.
* @param dstx The X coordinate of the destination, where the source rectangle
* should be copied.
* @param dsty The Y coordinate of the destination, where the source rectangle
* should be copied.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_transfer(guac_socket* socket,
const guac_layer* srcl, int srcx, int srcy, int w, int h,
guac_transfer_function fn, const guac_layer* dstl, int dstx, int dsty);
/**
* Sends a transform instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param layer The layer to apply the given transform matrix to.
* @param a The first value of the affine transform matrix.
* @param b The second value of the affine transform matrix.
* @param c The third value of the affine transform matrix.
* @param d The fourth value of the affine transform matrix.
* @param e The fifth value of the affine transform matrix.
* @param f The sixth value of the affine transform matrix.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_transform(guac_socket* socket,
const guac_layer* layer,
double a, double b, double c,
double d, double e, double f);
/* LAYER INSTRUCTIONS */
/**
* Sends a dispose instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param layer The layer to dispose.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_dispose(guac_socket* socket, const guac_layer* layer);
/**
* Sends a distort instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param layer The layer to distort with the given transform matrix.
* @param a The first value of the affine transform matrix.
* @param b The second value of the affine transform matrix.
* @param c The third value of the affine transform matrix.
* @param d The fourth value of the affine transform matrix.
* @param e The fifth value of the affine transform matrix.
* @param f The sixth value of the affine transform matrix.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_distort(guac_socket* socket,
const guac_layer* layer,
double a, double b, double c,
double d, double e, double f);
/**
* Sends a move instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param layer The layer to move.
* @param parent The parent layer the specified layer will be positioned
* relative to.
* @param x The X coordinate of the layer.
* @param y The Y coordinate of the layer.
* @param z The Z index of the layer, relative to other layers in its parent.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_move(guac_socket* socket, const guac_layer* layer,
const guac_layer* parent, int x, int y, int z);
/**
* Sends a shade instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param layer The layer to shade.
* @param a The alpha value of the layer.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_shade(guac_socket* socket, const guac_layer* layer,
int a);
/**
* Sends a size instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param layer The layer to resize.
* @param w The new width of the layer.
* @param h The new height of the layer.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_size(guac_socket* socket, const guac_layer* layer,
int w, int h);
/* TEXT INSTRUCTIONS */
/**
* Sends a clipboard instruction over the given guac_socket connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @param data The clipboard data to send.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_clipboard(guac_socket* socket, const char* data);
/**
* Sends a name instruction over the given guac_socket connection.
*
* @param socket The guac_socket connection to use.
* @param name The name to send within the name instruction.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_name(guac_socket* socket, const char* name);
#endif

357
libguac/include/socket.h Normal file
View File

@ -0,0 +1,357 @@
/* ***** 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 libguac.
*
* 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 ***** */
#ifndef _GUAC_SOCKET_H
#define _GUAC_SOCKET_H
#include <stdint.h>
#include <unistd.h>
/**
* Defines the guac_socket object and functionss for using and manipulating it.
*
* @file socket.h
*/
typedef struct guac_socket guac_socket;
/**
* Generic read handler for socket read operations, modeled after the standard
* POSIX read() function. When set within a guac_socket, a handler of this type
* will be called when data needs to be read into the socket.
*
* @param socket The guac_socket being read from.
* @param buf The arbitrary buffer we must populate with data.
* @param count The maximum number of bytes to read into the buffer.
* @return The number of bytes read, or -1 if an error occurs.
*/
typedef ssize_t guac_socket_read_handler(guac_socket* socket,
void* buf, size_t count);
/**
* Generic write handler for socket write operations, modeled after the standard
* POSIX write() function. When set within a guac_socket, a handler of this type
* will be called when data needs to be write into the socket.
*
* @param socket The guac_socket being written to.
* @param buf The arbitrary buffer containing data to be written.
* @param count The maximum number of bytes to write from the buffer.
* @return The number of bytes written, or -1 if an error occurs.
*/
typedef ssize_t guac_socket_write_handler(guac_socket* socket,
void* buf, size_t count);
/**
* Generic handler for socket select operations, similar to the POSIX select()
* function. When guac_socket_select() is called on a guac_socket, its
* guac_socket_select_handler will be invoked, if defined.
*
* @param socket The guac_socket being selected.
* @param usec_timeout The maximum number of microseconds to wait for data, or
* -1 to potentially wait forever.
* @return Positive on success, zero if the timeout elapsed and no data is
* available, negative on error.
*/
typedef int guac_socket_select_handler(guac_socket* socket, int usec_timeout);
/**
* Generic handler for the closing of a socket, modeled after the standard
* POSIX close() function. When set within a guac_socket, a handler of this type
* will be called when the socket is closed.
*
* @param socket The guac_socket being closed.
* @return Zero on success, or -1 if an error occurs.
*/
typedef int guac_socket_free_handler(guac_socket* socket);
/**
* The core I/O object of Guacamole. guac_socket provides buffered input and
* output as well as convenience methods for efficiently writing base64 data.
*/
struct guac_socket {
/**
* Arbitrary socket-specific data.
*/
void* data;
/**
* Handler which will be called when data needs to be read from the socket.
*/
guac_socket_read_handler* read_handler;
/**
* Handler which will be called whenever data is written to this socket.
* Note that because guac_socket automatically buffers written data, this
* handler might only get called when the socket is flushed.
*/
guac_socket_write_handler* write_handler;
/**
* Handler which will be called whenever guac_socket_select is invoked
* on this socket.
*/
guac_socket_select_handler* select_handler;
/**
* Handler which will be called when the socket is free'd (closed).
*/
guac_socket_free_handler* free_handler;
/**
* The number of bytes present in the base64 "ready" buffer.
*/
int __ready;
/**
* The base64 "ready" buffer. Once this buffer is filled, base64 data is
* flushed to the main write buffer.
*/
int __ready_buf[3];
/**
* The number of bytes currently in the main write buffer.
*/
int __written;
/**
* The main write buffer. Bytes written go here before being flushed
* to the open file descriptor.
*/
char __out_buf[8192];
/**
* The current location of parsing within the instruction buffer.
*/
int __instructionbuf_parse_start;
/**
* The current size of the instruction buffer.
*/
int __instructionbuf_size;
/**
* The number of bytes currently in the instruction buffer.
*/
int __instructionbuf_used_length;
/**
* The instruction buffer. This is essentially the input buffer,
* provided as a convenience to be used to buffer instructions until
* those instructions are complete and ready to be parsed.
*/
char* __instructionbuf;
/**
* The number of elements parsed so far.
*/
int __instructionbuf_elementc;
/**
* Array of pointers into the instruction buffer, where each pointer
* points to the start of the corresponding element.
*/
char* __instructionbuf_elementv[64];
};
/**
* Allocates a new, completely blank guac_socket. This guac_socket will do
* absolutely nothing when used unless its handlers are defined.
*
* @returns A newly-allocated guac_socket, or NULL if the guac_socket could
* not be allocated.
*/
guac_socket* guac_socket_alloc();
/**
* Frees the given guac_socket and all associated resources.
*
* @param socket The guac_socket to free.
*/
void guac_socket_free(guac_socket* socket);
/**
* Allocates and initializes a new guac_socket object with the given open
* file descriptor.
*
* If an error occurs while allocating the guac_socket object, NULL is returned,
* and guac_error is set appropriately.
*
* @param fd An open file descriptor that this guac_socket object should manage.
* @return A newly allocated guac_socket object associated with the given
* file descriptor, or NULL if an error occurs while allocating
* the guac_socket object.
*/
guac_socket* guac_socket_open(int fd);
/**
* Allocates and initializes a new guac_socket which writes all data via
* nest instructions to the given existing, open guac_socket.
*
* If an error occurs while allocating the guac_socket object, NULL is returned,
* and guac_error is set appropriately.
*
* @param parent The guac_socket this new guac_socket should write nest
* instructions to.
* @param index The stream index to use for the written nest instructions.
* @return A newly allocated guac_socket object associated with the given
* guac_socket and stream index, or NULL if an error occurs while
* allocating the guac_socket object.
*/
guac_socket* guac_socket_nest(guac_socket* parent, int index);
/**
* Writes the given unsigned int to the given guac_socket object. The data
* written may be buffered until the buffer is flushed automatically or
* manually.
*
* If an error occurs while writing, a non-zero value is returned, and
* guac_error is set appropriately.
*
* @param socket The guac_socket object to write to.
* @param i The unsigned int to write.
* @return Zero on success, or non-zero if an error occurs while writing.
*/
ssize_t guac_socket_write_int(guac_socket* socket, int64_t i);
/**
* Writes the given string to the given guac_socket object. The data
* written may be buffered until the buffer is flushed automatically or
* manually. Note that if the string can contain characters used
* internally by the Guacamole protocol (commas, semicolons, or
* backslashes) it will need to be escaped.
*
* If an error occurs while writing, a non-zero value is returned, and
* guac_error is set appropriately.
*
* @param socket The guac_socket object to write to.
* @param str The string to write.
* @return Zero on success, or non-zero if an error occurs while writing.
*/
ssize_t guac_socket_write_string(guac_socket* socket, const char* str);
/**
* Writes the given binary data to the given guac_socket object as base64-
* encoded data. The data written may be buffered until the buffer is flushed
* automatically or manually. Beware that because base64 data is buffered
* on top of the write buffer already used, a call to guac_socket_flush_base64()
* must be made before non-base64 writes (or writes of an independent block of
* base64 data) can be made.
*
* If an error occurs while writing, a non-zero value is returned, and
* guac_error is set appropriately.
*
* @param socket The guac_socket object to write to.
* @param buf A buffer containing the data to write.
* @param count The number of bytes to write.
* @return Zero on success, or non-zero if an error occurs while writing.
*/
ssize_t guac_socket_write_base64(guac_socket* socket, const void* buf, size_t count);
/**
* Writes the given data to the specified socket. The data written may be
* buffered until the buffer is flushed automatically or manually.
*
* If an error occurs while writing, a non-zero value is returned, and
* guac_error is set appropriately.
*
* @param socket The guac_socket object to write to.
* @param buf A buffer containing the data to write.
* @param count The number of bytes to write.
* @return Zero on success, or non-zero if an error occurs while writing.
*/
ssize_t guac_socket_write(guac_socket* socket, const void* buf, size_t count);
/**
* Attempts to read data from the socket, filling up to the specified number
* of bytes in the given buffer.
*
* If an error occurs while writing, a non-zero value is returned, and
* guac_error is set appropriately.
*
* @param socket The guac_socket to read from.
* @param buf The buffer to read bytes into.
* @param count The maximum number of bytes to read.
* @return The number of bytes read, or non-zero if an error occurs while
* reading.
*/
ssize_t guac_socket_read(guac_socket* socket, void* buf, size_t count);
/**
* Flushes the base64 buffer, writing padding characters as necessary.
*
* If an error occurs while writing, a non-zero value is returned, and
* guac_error is set appropriately.
*
* @param socket The guac_socket object to flush
* @return Zero on success, or non-zero if an error occurs during flush.
*/
ssize_t guac_socket_flush_base64(guac_socket* socket);
/**
* Flushes the write buffer.
*
* If an error occurs while writing, a non-zero value is returned, and
* guac_error is set appropriately.
*
* @param socket The guac_socket object to flush
* @return Zero on success, or non-zero if an error occurs during flush.
*/
ssize_t guac_socket_flush(guac_socket* socket);
/**
* Waits for input to be available on the given guac_socket object until the
* specified timeout elapses.
*
* If an error occurs while waiting, a negative value is returned, and
* guac_error is set appropriately.
*
* If a timeout occurs while waiting, zero value is returned, and
* guac_error is set to GUAC_STATUS_INPUT_TIMEOUT.
*
* @param socket The guac_socket object to wait for.
* @param usec_timeout The maximum number of microseconds to wait for data, or
* -1 to potentially wait forever.
* @return Positive on success, zero if the timeout elapsed and no data is
* available, negative on error.
*/
int guac_socket_select(guac_socket* socket, int usec_timeout);
#endif

68
libguac/include/stream.h Normal file
View File

@ -0,0 +1,68 @@
/* ***** 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 libguac.
*
* 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 ***** */
#ifndef _GUAC_STREAM_H
#define _GUAC_STREAM_H
/**
* Provides functions and structures required for allocating and using nested
* streams.
*
* @file stream.h
*/
typedef struct guac_stream guac_stream;
/**
* Represents a single nested stream within the Guacamole protocol.
*/
struct guac_stream {
/**
* The index of this layer.
*/
int index;
/**
* A guac_socket which writes to this stream.
*/
guac_socket* socket;
};
#endif

View File

@ -0,0 +1,65 @@
/* ***** 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 libguac.
*
* 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 ***** */
#ifndef _GUAC_TIME_H
#define _GUAC_TIME_H
#include <stdint.h>
/**
* Provides functions and structures for creating timestamps.
*
* @file timestamp.h
*/
/**
* An arbitrary timestamp denoting a relative time value in milliseconds.
*/
typedef int64_t guac_timestamp;
/**
* Returns an arbitrary timestamp. The difference between return values of any
* two calls is equal to the amount of time in milliseconds between those
* calls. The return value from a single call will not have any useful
* (or defined) meaning.
*
* @return An arbitrary millisecond timestamp.
*/
guac_timestamp guac_timestamp_current();
#endif

68
libguac/include/unicode.h Normal file
View File

@ -0,0 +1,68 @@
/* ***** 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 libguac.
*
* 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 ***** */
#ifndef _GUAC_UNICODE_H
#define _GUAC_UNICODE_H
#include <stddef.h>
/**
* Provides functions for manipulating Unicode strings.
*
* @file unicode.h
*/
/**
* Given the initial byte of a single UTF-8 character, returns the overall
* byte size of the entire character.
*
* @param c The initial byte of the character to check.
* @return The number of bytes in the given character overall.
*/
size_t guac_utf8_charsize(unsigned char c);
/**
* Given a UTF-8-encoded string, returns the length of the string in characters
* (not bytes).
*
* @param str The UTF-8 string to calculate the length of.
* @return The length in characters of the given UTF-8 string.
*/
size_t guac_utf8_strlen(const char* str);
#endif

12
libguac/m4/README Normal file
View File

@ -0,0 +1,12 @@
This file exists such that the m4/ directory will be created when cloning the
git repository.
The m4/ directory is not directly used by this project, but libtoolize
populates this directory with files, recommending that the directory be
included in the macro search path for aclocal.
Because autoreconf runs aclocal before libtoolize, this directory will not
exist when autoreconf is run, triggering an error from aclocal.
Creating this directory (and keeping this file in it as a placeholder)
prevents this error.

78
libguac/src/Makefile.am Normal file
View File

@ -0,0 +1,78 @@
# ***** 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 libguac.
#
# 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 *****
AUTOMAKE_OPTIONS = foreign
ACLOCAL_AMFLAGS = -I m4
AM_CFLAGS = -Werror -Wall -pedantic -I../include
libguacincdir = $(includedir)/guacamole
libguacinc_HEADERS = \
../include/client.h \
../include/error.h \
../include/hash.h \
../include/instruction.h \
../include/layer.h \
../include/plugin.h \
../include/pool.h \
../include/protocol.h \
../include/socket.h \
../include/stream.h \
../include/timestamp.h
noinst_HEADERS = \
../include/client-handlers.h \
../include/palette.h \
../include/unicode.h
libguac_la_SOURCES = \
client.c \
client-handlers.c \
error.c \
hash.c \
instruction.c \
palette.c \
plugin.c \
pool.c \
protocol.c \
socket.c \
socket-fd.c \
socket-nest.c \
timestamp.c \
unicode.c
lib_LTLIBRARIES = libguac.la
libguac_la_LDFLAGS = -version-info 4:0:0

View File

@ -0,0 +1,133 @@
/* ***** 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 libguac.
*
* 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 ***** */
#include <stdlib.h>
#include <stdio.h>
#include "client.h"
#include "protocol.h"
#include "client-handlers.h"
/* Guacamole instruction handler map */
__guac_instruction_handler_mapping __guac_instruction_handler_map[] = {
{"sync", __guac_handle_sync},
{"mouse", __guac_handle_mouse},
{"key", __guac_handle_key},
{"clipboard", __guac_handle_clipboard},
{"disconnect", __guac_handle_disconnect},
{"size", __guac_handle_size},
{NULL, NULL}
};
int64_t __guac_parse_int(const char* str) {
int sign = 1;
int64_t num = 0;
for (; *str != '\0'; str++) {
if (*str == '-')
sign = -sign;
else
num = num * 10 + (*str - '0');
}
return num * sign;
}
/* Guacamole instruction handlers */
int __guac_handle_sync(guac_client* client, guac_instruction* instruction) {
guac_timestamp timestamp = __guac_parse_int(instruction->argv[0]);
/* Error if timestamp is in future */
if (timestamp > client->last_sent_timestamp)
return -1;
client->last_received_timestamp = timestamp;
return 0;
}
int __guac_handle_mouse(guac_client* client, guac_instruction* instruction) {
if (client->mouse_handler)
return client->mouse_handler(
client,
atoi(instruction->argv[0]), /* x */
atoi(instruction->argv[1]), /* y */
atoi(instruction->argv[2]) /* mask */
);
return 0;
}
int __guac_handle_key(guac_client* client, guac_instruction* instruction) {
if (client->key_handler)
return client->key_handler(
client,
atoi(instruction->argv[0]), /* keysym */
atoi(instruction->argv[1]) /* pressed */
);
return 0;
}
int __guac_handle_clipboard(guac_client* client, guac_instruction* instruction) {
if (client->clipboard_handler)
return client->clipboard_handler(
client,
instruction->argv[0] /* data */
);
return 0;
}
int __guac_handle_size(guac_client* client, guac_instruction* instruction) {
if (client->size_handler)
return client->size_handler(
client,
atoi(instruction->argv[0]), /* width */
atoi(instruction->argv[1]) /* height */
);
return 0;
}
int __guac_handle_disconnect(guac_client* client, guac_instruction* instruction) {
/* Return error code to force disconnect */
return -1;
}

236
libguac/src/client.c Normal file
View File

@ -0,0 +1,236 @@
/* ***** 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 libguac.
*
* 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 ***** */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "client.h"
#include "client-handlers.h"
#include "error.h"
#include "layer.h"
#include "plugin.h"
#include "pool.h"
#include "protocol.h"
#include "socket.h"
#include "time.h"
guac_layer __GUAC_DEFAULT_LAYER = {
.index = 0
};
const guac_layer* GUAC_DEFAULT_LAYER = &__GUAC_DEFAULT_LAYER;
guac_layer* guac_client_alloc_layer(guac_client* client) {
/* Init new layer */
guac_layer* allocd_layer = malloc(sizeof(guac_layer));
allocd_layer->index = guac_pool_next_int(client->__layer_pool)+1;
return allocd_layer;
}
guac_layer* guac_client_alloc_buffer(guac_client* client) {
/* Init new layer */
guac_layer* allocd_layer = malloc(sizeof(guac_layer));
allocd_layer->index = -guac_pool_next_int(client->__buffer_pool) - 1;
return allocd_layer;
}
void guac_client_free_buffer(guac_client* client, guac_layer* layer) {
/* Release index to pool */
guac_pool_free_int(client->__buffer_pool, -layer->index - 1);
/* Free layer */
free(layer);
}
void guac_client_free_layer(guac_client* client, guac_layer* layer) {
/* Release index to pool */
guac_pool_free_int(client->__layer_pool, layer->index);
/* Free layer */
free(layer);
}
guac_stream* guac_client_alloc_stream(guac_client* client) {
/* Init new stream */
guac_stream* allocd_stream = malloc(sizeof(guac_stream));
allocd_stream->index = guac_pool_next_int(client->__stream_pool);
/* Nest socket */
allocd_stream->socket = guac_socket_nest(
client->socket,
allocd_stream->index
);
return allocd_stream;
}
void guac_client_free_stream(guac_client* client, guac_stream* stream) {
/* Release index to pool */
guac_pool_free_int(client->__stream_pool, stream->index - 1);
/* Release socket */
guac_socket_free(stream->socket);
/* Free stream */
free(stream);
}
guac_client* guac_client_alloc() {
/* Allocate new client */
guac_client* client = malloc(sizeof(guac_client));
if (client == NULL) {
guac_error = GUAC_STATUS_NO_MEMORY;
guac_error_message = "Could not allocate memory for client";
return NULL;
}
/* Init new client */
memset(client, 0, sizeof(guac_client));
client->last_received_timestamp =
client->last_sent_timestamp = guac_timestamp_current();
client->state = GUAC_CLIENT_RUNNING;
/* Allocate buffer and layer pools */
client->__buffer_pool = guac_pool_alloc(GUAC_BUFFER_POOL_INITIAL_SIZE);
client->__layer_pool = guac_pool_alloc(GUAC_BUFFER_POOL_INITIAL_SIZE);
/* Allocate stream pool */
client->__stream_pool = guac_pool_alloc(0);
return client;
}
void guac_client_free(guac_client* client) {
if (client->free_handler) {
/* FIXME: Errors currently ignored... */
client->free_handler(client);
}
/* Free layer pools */
guac_pool_free(client->__buffer_pool);
guac_pool_free(client->__layer_pool);
/* Free stream pool */
guac_pool_free(client->__stream_pool);
free(client);
}
int guac_client_handle_instruction(guac_client* client, guac_instruction* instruction) {
/* For each defined instruction */
__guac_instruction_handler_mapping* current = __guac_instruction_handler_map;
while (current->opcode != NULL) {
/* If recognized, call handler */
if (strcmp(instruction->opcode, current->opcode) == 0)
return current->handler(client, instruction);
current++;
}
/* If unrecognized, ignore */
return 0;
}
void vguac_client_log_info(guac_client* client, const char* format,
va_list ap) {
/* Call handler if defined */
if (client->log_info_handler != NULL)
client->log_info_handler(client, format, ap);
}
void vguac_client_log_error(guac_client* client, const char* format,
va_list ap) {
/* Call handler if defined */
if (client->log_error_handler != NULL)
client->log_error_handler(client, format, ap);
}
void guac_client_log_info(guac_client* client, const char* format, ...) {
va_list args;
va_start(args, format);
vguac_client_log_info(client, format, args);
va_end(args);
}
void guac_client_log_error(guac_client* client, const char* format, ...) {
va_list args;
va_start(args, format);
vguac_client_log_error(client, format, args);
va_end(args);
}
void guac_client_stop(guac_client* client) {
client->state = GUAC_CLIENT_STOPPING;
}

197
libguac/src/error.c Normal file
View File

@ -0,0 +1,197 @@
/* ***** 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 libguac.
*
* 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 ***** */
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#ifdef HAVE_LIBPTHREAD
#include <pthread.h>
#endif
#include "error.h"
/* Error strings */
const char* __GUAC_STATUS_SUCCESS_STR = "Success";
const char* __GUAC_STATUS_NO_MEMORY_STR = "Insufficient memory";
const char* __GUAC_STATUS_NO_INPUT_STR = "End of input stream";
const char* __GUAC_STATUS_INPUT_TIMEOUT_STR = "Read timeout";
const char* __GUAC_STATUS_OUTPUT_ERROR_STR = "Output error";
const char* __GUAC_STATUS_BAD_ARGUMENT_STR = "Invalid argument";
const char* __GUAC_STATUS_BAD_STATE_STR = "Illegal state";
const char* __GUAC_STATUS_INVALID_STATUS_STR = "UNKNOWN STATUS CODE";
const char* guac_status_string(guac_status status) {
switch (status) {
/* No error */
case GUAC_STATUS_SUCCESS:
return __GUAC_STATUS_SUCCESS_STR;
/* Out of memory */
case GUAC_STATUS_NO_MEMORY:
return __GUAC_STATUS_NO_MEMORY_STR;
/* End of input */
case GUAC_STATUS_NO_INPUT:
return __GUAC_STATUS_NO_INPUT_STR;
/* Input timeout */
case GUAC_STATUS_INPUT_TIMEOUT:
return __GUAC_STATUS_INPUT_TIMEOUT_STR;
/* Further information in errno */
case GUAC_STATUS_SEE_ERRNO:
return strerror(errno);
/* Output error */
case GUAC_STATUS_OUTPUT_ERROR:
return __GUAC_STATUS_OUTPUT_ERROR_STR;
/* Invalid argument */
case GUAC_STATUS_BAD_ARGUMENT:
return __GUAC_STATUS_BAD_ARGUMENT_STR;
/* Illegal state */
case GUAC_STATUS_BAD_STATE:
return __GUAC_STATUS_BAD_STATE_STR;
default:
return __GUAC_STATUS_INVALID_STATUS_STR;
}
}
#ifdef HAVE_LIBPTHREAD
/* PThread implementation of __guac_error */
static pthread_key_t __guac_error_key;
static pthread_once_t __guac_error_key_init = PTHREAD_ONCE_INIT;
static pthread_key_t __guac_error_message_key;
static pthread_once_t __guac_error_message_key_init = PTHREAD_ONCE_INIT;
static void __guac_free_pointer(void* pointer) {
/* Free memory allocated to status variable */
free(pointer);
}
static void __guac_alloc_error_key() {
/* Create key, destroy any allocated variable on thread exit */
pthread_key_create(&__guac_error_key, __guac_free_pointer);
}
static void __guac_alloc_error_message_key() {
/* Create key, destroy any allocated variable on thread exit */
pthread_key_create(&__guac_error_message_key, __guac_free_pointer);
}
guac_status* __guac_error() {
/* Pointer for thread-local data */
guac_status* status;
/* Init error key, if not already initialized */
pthread_once(&__guac_error_key_init, __guac_alloc_error_key);
/* Retrieve thread-local status variable */
status = (guac_status*) pthread_getspecific(__guac_error_key);
/* Allocate thread-local status variable if not already allocated */
if (status == NULL) {
status = malloc(sizeof(guac_status));
pthread_setspecific(__guac_error_key, status);
}
return status;
}
const char** __guac_error_message() {
/* Pointer for thread-local data */
const char** message;
/* Init error message key, if not already initialized */
pthread_once(
&__guac_error_message_key_init,
__guac_alloc_error_message_key
);
/* Retrieve thread-local message variable */
message = (const char**) pthread_getspecific(__guac_error_message_key);
/* Allocate thread-local message variable if not already allocated */
if (message == NULL) {
message = malloc(sizeof(const char*));
pthread_setspecific(__guac_error_message_key, message);
}
return message;
}
#else
/* Default (not-threadsafe) implementation */
static guac_status __guac_error_unsafe_storage;
static const char** __guac_error_message_unsafe_storage;
guac_status* __guac_error() {
return &__guac_error_unsafe_storage;
}
const char** __guac_error_message() {
return &__guac_error_message_unsafe_storage;
}
/* Warn about threadsafety */
#warn No threadsafe implementation of __guac_error exists for your platform, so a default non-threadsafe implementation has been used instead. This may lead to incorrect status codes being reported for failures. Please consider adding support for your platform, or filing a bug report with the Guacamole project.
#endif

151
libguac/src/hash.c Normal file
View File

@ -0,0 +1,151 @@
/* ***** 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 libguac.
*
* 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 ***** */
#include <stdint.h>
#include <string.h>
#include <cairo/cairo.h>
/*
* Arbitrary hash function whhich maps ALL 32-bit numbers onto 24-bit numbers
* evenly, while guaranteeing that all 24-bit numbers are mapped onto
* themselves.
*/
unsigned int _guac_hash_32to24(unsigned int value) {
/* Grab highest-order byte */
unsigned int upper = value & 0xFF000000;
/* XOR upper with lower three bytes, truncate to 24-bit */
return
(value & 0xFFFFFF)
^ (upper >> 8)
^ (upper >> 16)
^ (upper >> 24);
}
/**
* Rotates a given 32-bit integer by N bits.
*
* NOTE: We probably should check for available bitops.h macros first.
*/
unsigned int _guac_rotate(unsigned int value, int amount) {
/* amount = amount % 32 */
amount &= 0x1F;
/* Return rotated amount */
return (value >> amount) | (value << (32 - amount));
}
unsigned int guac_hash_surface(cairo_surface_t* surface) {
/* Init to zero */
unsigned int hash_value = 0;
int x, y;
/* Get image data and metrics */
unsigned char* data = cairo_image_surface_get_data(surface);
int width = cairo_image_surface_get_width(surface);
int height = cairo_image_surface_get_height(surface);
int stride = cairo_image_surface_get_stride(surface);
for (y=0; y<height; y++) {
/* Get current row */
uint32_t* row = (uint32_t*) data;
data += stride;
for (x=0; x<width; x++) {
/* Get color at current pixel */
unsigned int color = *row;
row++;
/* Compute next hash */
hash_value =
_guac_rotate(hash_value, 1) ^ color ^ 0x1B872E69;
}
} /* end for each row */
/* Done */
return _guac_hash_32to24(hash_value);
}
int guac_surface_cmp(cairo_surface_t* a, cairo_surface_t* b) {
/* Surface A metrics */
unsigned char* data_a = cairo_image_surface_get_data(a);
int width_a = cairo_image_surface_get_width(a);
int height_a = cairo_image_surface_get_height(a);
int stride_a = cairo_image_surface_get_stride(a);
/* Surface B metrics */
unsigned char* data_b = cairo_image_surface_get_data(b);
int width_b = cairo_image_surface_get_width(b);
int height_b = cairo_image_surface_get_height(b);
int stride_b = cairo_image_surface_get_stride(b);
int y;
/* If core dimensions differ, just compare those. Done. */
if (width_a != width_b) return width_a - width_b;
if (height_a != height_b) return height_a - height_b;
for (y=0; y<height_a; y++) {
/* Compare row. If different, use that result. */
int cmp_result = memcmp(data_a, data_b, width_a * 4);
if (cmp_result != 0)
return cmp_result;
/* Next row */
data_a += stride_a;
data_b += stride_b;
}
/* Otherwise, same. */
return 0;
}

334
libguac/src/instruction.c Normal file
View File

@ -0,0 +1,334 @@
/* ***** 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 libguac.
*
* 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 ***** */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "error.h"
#include "instruction.h"
#include "protocol.h"
#include "socket.h"
#include "unicode.h"
int __guac_fill_instructionbuf(guac_socket* socket) {
int retval;
/* Attempt to fill buffer */
retval = guac_socket_read(
socket,
socket->__instructionbuf + socket->__instructionbuf_used_length,
socket->__instructionbuf_size - socket->__instructionbuf_used_length
);
/* Set guac_error if recv() unsuccessful */
if (retval < 0) {
guac_error = GUAC_STATUS_SEE_ERRNO;
guac_error_message = "Error filling instruction buffer";
return retval;
}
socket->__instructionbuf_used_length += retval;
/* Expand buffer if necessary */
if (socket->__instructionbuf_used_length >
socket->__instructionbuf_size / 2) {
socket->__instructionbuf_size *= 2;
socket->__instructionbuf = realloc(socket->__instructionbuf,
socket->__instructionbuf_size);
}
return retval;
}
/* Returns new instruction if one exists, or NULL if no more instructions. */
guac_instruction* guac_instruction_read(guac_socket* socket,
int usec_timeout) {
int retval;
/* Loop until a instruction is read */
for (;;) {
/* Length of element, in Unicode characters */
int element_length = 0;
/* Length of element, in bytes */
int element_byte_length = 0;
/* Current position within the element, in Unicode characters */
int current_unicode_length = 0;
/* Position within buffer */
int i = socket->__instructionbuf_parse_start;
/* Parse instruction in buffer */
while (i < socket->__instructionbuf_used_length) {
/* Read character from buffer */
char c = socket->__instructionbuf[i++];
/* If digit, calculate element length */
if (c >= '0' && c <= '9')
element_length = element_length * 10 + c - '0';
/* Otherwise, if end of length */
else if (c == '.') {
/* Calculate element byte length by walking buffer */
while (i + element_byte_length <
socket->__instructionbuf_used_length
&& current_unicode_length < element_length) {
/* Get next byte */
c = socket->__instructionbuf[i + element_byte_length];
/* Update byte and character lengths */
element_byte_length += guac_utf8_charsize((unsigned) c);
current_unicode_length++;
}
/* Verify element is fully read */
if (current_unicode_length == element_length) {
/* Get element value */
char* elementv = &(socket->__instructionbuf[i]);
/* Get terminator, set null terminator of elementv */
char terminator = elementv[element_byte_length];
elementv[element_byte_length] = '\0';
/* Move to char after terminator of element */
i += element_byte_length+1;
/* Reset element length */
element_length =
element_byte_length =
current_unicode_length = 0;
/* As element has been read successfully, update
* parse start */
socket->__instructionbuf_parse_start = i;
/* Save element */
socket->__instructionbuf_elementv[socket->__instructionbuf_elementc++] = elementv;
/* Finish parse if terminator is a semicolon */
if (terminator == ';') {
guac_instruction* parsed_instruction;
int j;
/* Allocate instruction */
parsed_instruction = malloc(sizeof(guac_instruction));
if (parsed_instruction == NULL) {
guac_error = GUAC_STATUS_NO_MEMORY;
guac_error_message = "Could not allocate memory for parsed instruction";
return NULL;
}
/* Init parsed instruction */
parsed_instruction->argc = socket->__instructionbuf_elementc - 1;
parsed_instruction->argv = malloc(sizeof(char*) * parsed_instruction->argc);
/* Fail if memory could not be alloc'd for argv */
if (parsed_instruction->argv == NULL) {
guac_error = GUAC_STATUS_NO_MEMORY;
guac_error_message = "Could not allocate memory for arguments of parsed instruction";
free(parsed_instruction);
return NULL;
}
/* Set opcode */
parsed_instruction->opcode = strdup(socket->__instructionbuf_elementv[0]);
/* Fail if memory could not be alloc'd for opcode */
if (parsed_instruction->opcode == NULL) {
guac_error = GUAC_STATUS_NO_MEMORY;
guac_error_message = "Could not allocate memory for opcode of parsed instruction";
free(parsed_instruction->argv);
free(parsed_instruction);
return NULL;
}
/* Copy element values to parsed instruction */
for (j=0; j<parsed_instruction->argc; j++) {
parsed_instruction->argv[j] = strdup(socket->__instructionbuf_elementv[j+1]);
/* Free memory and fail if out of mem */
if (parsed_instruction->argv[j] == NULL) {
guac_error = GUAC_STATUS_NO_MEMORY;
guac_error_message = "Could not allocate memory for single argument of parsed instruction";
/* Free all alloc'd argv values */
while (--j >= 0)
free(parsed_instruction->argv[j]);
free(parsed_instruction->opcode);
free(parsed_instruction->argv);
free(parsed_instruction);
return NULL;
}
}
/* Reset buffer */
memmove(socket->__instructionbuf, socket->__instructionbuf + i, socket->__instructionbuf_used_length - i);
socket->__instructionbuf_used_length -= i;
socket->__instructionbuf_parse_start = 0;
socket->__instructionbuf_elementc = 0;
/* Done */
return parsed_instruction;
} /* end if terminator */
/* Error if expected comma is not present */
else if (terminator != ',') {
guac_error = GUAC_STATUS_BAD_ARGUMENT;
guac_error_message = "Element terminator of instruction was not ';' nor ','";
return NULL;
}
} /* end if element fully read */
/* Otherwise, read more data */
else
break;
}
/* Error if length is non-numeric or does not end in a period */
else {
guac_error = GUAC_STATUS_BAD_ARGUMENT;
guac_error_message = "Non-numeric character in element length";
return NULL;
}
}
/* No instruction yet? Get more data ... */
retval = guac_socket_select(socket, usec_timeout);
if (retval <= 0)
return NULL;
/* If more data is available, fill into buffer */
retval = __guac_fill_instructionbuf(socket);
/* Error, guac_error already set */
if (retval < 0)
return NULL;
/* EOF */
if (retval == 0) {
guac_error = GUAC_STATUS_NO_INPUT;
guac_error_message = "End of stream reached while reading instruction";
return NULL;
}
}
}
guac_instruction* guac_instruction_expect(guac_socket* socket, int usec_timeout,
const char* opcode) {
guac_instruction* instruction;
/* Wait for data until timeout */
if (guac_instruction_waiting(socket, usec_timeout) <= 0)
return NULL;
/* Read available instruction */
instruction = guac_instruction_read(socket, usec_timeout);
if (instruction == NULL)
return NULL;
/* Validate instruction */
if (strcmp(instruction->opcode, opcode) != 0) {
guac_error = GUAC_STATUS_BAD_STATE;
guac_error_message = "Instruction read did not have expected opcode";
guac_instruction_free(instruction);
return NULL;
}
/* Return instruction if valid */
return instruction;
}
void guac_instruction_free(guac_instruction* instruction) {
int argc = instruction->argc;
/* Free opcode */
free(instruction->opcode);
/* Free argv if set (may be NULL of argc is 0) */
if (instruction->argv) {
/* All argument values */
while (argc > 0)
free(instruction->argv[--argc]);
/* Free actual array */
free(instruction->argv);
}
/* Free instruction */
free(instruction);
}
int guac_instruction_waiting(guac_socket* socket, int usec_timeout) {
if (socket->__instructionbuf_used_length > 0)
return 1;
return guac_socket_select(socket, usec_timeout);
}

153
libguac/src/palette.c Normal file
View File

@ -0,0 +1,153 @@
/* ***** 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 libguac.
*
* 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 ***** */
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <inttypes.h>
#include <cairo/cairo.h>
#include <sys/types.h>
#include "palette.h"
guac_palette* guac_palette_alloc(cairo_surface_t* surface) {
int x, y;
int width = cairo_image_surface_get_width(surface);
int height = cairo_image_surface_get_height(surface);
int stride = cairo_image_surface_get_stride(surface);
unsigned char* data = cairo_image_surface_get_data(surface);
/* Allocate palette */
guac_palette* palette = (guac_palette*) malloc(sizeof(guac_palette));
memset(palette, 0, sizeof(guac_palette));
for (y=0; y<height; y++) {
for (x=0; x<width; x++) {
/* Get pixel color */
int color = ((uint32_t*) data)[x] & 0xFFFFFF;
/* Calculate hash code */
int hash = ((color & 0xFFF000) >> 12) ^ (color & 0xFFF);
guac_palette_entry* entry;
/* Search for open palette entry */
for (;;) {
entry = &(palette->entries[hash]);
/* If we've found a free space, use it */
if (entry->index == 0) {
png_color* c;
/* Stop if already at capacity */
if (palette->size == 256) {
guac_palette_free(palette);
return NULL;
}
/* Store in palette */
c = &(palette->colors[palette->size]);
c->blue = (color ) & 0xFF;
c->green = (color >> 8 ) & 0xFF;
c->red = (color >> 16) & 0xFF;
/* Add color to map */
entry->index = ++palette->size;
entry->color = color;
break;
}
/* Otherwise, if already stored here, done */
if (entry->color == color)
break;
/* Otherwise, collision. Move on to another bucket */
hash = (hash+1) & 0xFFF;
}
}
/* Advance to next data row */
data += stride;
}
return palette;
}
int guac_palette_find(guac_palette* palette, int color) {
/* Calculate hash code */
int hash = ((color & 0xFFF000) >> 12) ^ (color & 0xFFF);
guac_palette_entry* entry;
/* Search for palette entry */
for (;;) {
entry = &(palette->entries[hash]);
/* If we've found a free space, color not stored. */
if (entry->index == 0)
return -1;
/* Otherwise, if color indeed stored here, done */
if (entry->color == color)
return entry->index - 1;
/* Otherwise, collision. Move on to another bucket */
hash = (hash+1) & 0xFFF;
}
}
void guac_palette_free(guac_palette* palette) {
free(palette);
}

141
libguac/src/plugin.c Normal file
View File

@ -0,0 +1,141 @@
/* ***** 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 libguac.
*
* 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 ***** */
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "client.h"
#include "client-handlers.h"
#include "error.h"
#include "plugin.h"
#include "protocol.h"
#include "socket.h"
#include "time.h"
guac_client_plugin* guac_client_plugin_open(const char* protocol) {
guac_client_plugin* plugin;
/* Reference to dlopen()'d plugin */
void* client_plugin_handle;
/* Client args description */
const char** client_args;
/* Pluggable client */
char protocol_lib[GUAC_PROTOCOL_LIBRARY_LIMIT] =
GUAC_PROTOCOL_LIBRARY_PREFIX;
union {
guac_client_init_handler* client_init;
void* obj;
} alias;
/* Add protocol and .so suffix to protocol_lib */
strncat(protocol_lib, protocol, GUAC_PROTOCOL_NAME_LIMIT-1);
strcat(protocol_lib, GUAC_PROTOCOL_LIBRARY_SUFFIX);
/* Load client plugin */
client_plugin_handle = dlopen(protocol_lib, RTLD_LAZY);
if (!client_plugin_handle) {
guac_error = GUAC_STATUS_BAD_ARGUMENT;
guac_error_message = dlerror();
return NULL;
}
dlerror(); /* Clear errors */
/* Get init function */
alias.obj = dlsym(client_plugin_handle, "guac_client_init");
/* Fail if cannot find guac_client_init */
if (dlerror() != NULL) {
guac_error = GUAC_STATUS_BAD_ARGUMENT;
guac_error_message = dlerror();
return NULL;
}
/* Get usage strig */
client_args = (const char**) dlsym(client_plugin_handle, "GUAC_CLIENT_ARGS");
/* Fail if cannot find GUAC_CLIENT_ARGS */
if (dlerror() != NULL) {
guac_error = GUAC_STATUS_BAD_ARGUMENT;
guac_error_message = dlerror();
return NULL;
}
/* Allocate plugin */
plugin = malloc(sizeof(guac_client_plugin));
if (plugin == NULL) {
guac_error = GUAC_STATUS_NO_MEMORY;
guac_error_message = "Could not allocate memory for client plugin";
return NULL;
}
/* Init and return plugin */
plugin->__client_plugin_handle = client_plugin_handle;
plugin->init_handler = alias.client_init;
plugin->args = client_args;
return plugin;
}
int guac_client_plugin_close(guac_client_plugin* plugin) {
/* Unload client plugin */
if (dlclose(plugin->__client_plugin_handle)) {
guac_error = GUAC_STATUS_BAD_STATE;
guac_error_message = dlerror();
return -1;
}
/* Free plugin handle */
free(plugin);
return 0;
}
int guac_client_plugin_init_client(guac_client_plugin* plugin,
guac_client* client, int argc, char** argv) {
return plugin->init_handler(client, argc, argv);
}

125
libguac/src/pool.c Normal file
View File

@ -0,0 +1,125 @@
/* ***** 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 libguac.
*
* 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 ***** */
#include <stdlib.h>
#include <string.h>
#include "pool.h"
guac_pool* guac_pool_alloc(int size) {
guac_pool* pool = malloc(sizeof(guac_pool));
/* If unable to allocate, just return NULL. */
if (pool == NULL)
return NULL;
/* Initialize empty pool */
pool->min_size = size;
pool->__next_value = 0;
pool->__head = NULL;
pool->__tail = NULL;
return pool;
}
void guac_pool_free(guac_pool* pool) {
/* Free all ints in pool */
guac_pool_int* current = pool->__head;
while (current != NULL) {
guac_pool_int* old = current;
current = current->__next;
free(old);
}
/* Free pool */
free(pool);
}
int guac_pool_next_int(guac_pool* pool) {
int value;
/* If more integers are needed, or we are out of integers, return a new one. */
if (pool->__head == NULL || pool->__next_value < pool->min_size)
return pool->__next_value++;
/* Otherwise, remove first integer. */
value = pool->__head->value;
/* If only one element exists, reset pool to empty. */
if (pool->__tail == pool->__head) {
free(pool->__head);
pool->__head = NULL;
pool->__tail = NULL;
}
/* Otherwise, advance head. */
else {
guac_pool_int* old_head = pool->__head;
pool->__head = old_head->__next;
free(old_head);
}
/* Return retrieved value. */
return value;
}
void guac_pool_free_int(guac_pool* pool, int value) {
/* Allocate and initialize new returned value */
guac_pool_int* pool_int = malloc(sizeof(guac_pool_int));
pool_int->value = value;
pool_int->__next = NULL;
/* If pool empty, store as sole entry. */
if (pool->__tail == NULL)
pool->__head = pool->__tail = pool_int;
/* Otherwise, append to end of pool. */
else {
pool->__tail->__next = pool_int;
pool->__tail = pool_int;
}
}

1053
libguac/src/protocol.c Normal file

File diff suppressed because it is too large Load Diff

163
libguac/src/socket-fd.c Normal file
View File

@ -0,0 +1,163 @@
/* ***** 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 libguac.
*
* 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):
* David PHAM-VAN <d.pham-van@ulteo.com> Ulteo SAS - http://www.ulteo.com
*
* 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 ***** */
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#ifdef __MINGW32__
#include <winsock2.h>
#else
#include <sys/select.h>
#endif
#include <time.h>
#include <sys/time.h>
#include "socket.h"
#include "error.h"
typedef struct __guac_socket_fd_data {
int fd;
} __guac_socket_fd_data;
ssize_t __guac_socket_fd_read_handler(guac_socket* socket,
void* buf, size_t count) {
__guac_socket_fd_data* data = (__guac_socket_fd_data*) socket->data;
/* Read from socket */
int retval = read(data->fd, buf, count);
/* Record errors in guac_error */
if (retval < 0) {
guac_error = GUAC_STATUS_SEE_ERRNO;
guac_error_message = "Error reading data from socket";
}
return retval;
}
ssize_t __guac_socket_fd_write_handler(guac_socket* socket,
void* buf, size_t count) {
__guac_socket_fd_data* data = (__guac_socket_fd_data*) socket->data;
int retval;
#ifdef __MINGW32__
/* MINGW32 WINSOCK only works with send() */
retval = send(data->fd, buf, count, 0);
#else
/* Use write() for all other platforms */
retval = write(data->fd, buf, count);
#endif
/* Record errors in guac_error */
if (retval < 0) {
guac_error = GUAC_STATUS_SEE_ERRNO;
guac_error_message = "Error writing data to socket";
}
return retval;
}
int __guac_socket_fd_select_handler(guac_socket* socket, int usec_timeout) {
__guac_socket_fd_data* data = (__guac_socket_fd_data*) socket->data;
fd_set fds;
struct timeval timeout;
int retval;
/* No timeout if usec_timeout is negative */
if (usec_timeout < 0)
retval = select(data->fd + 1, &fds, NULL, NULL, NULL);
/* Handle timeout if specified */
else {
timeout.tv_sec = usec_timeout/1000000;
timeout.tv_usec = usec_timeout%1000000;
FD_ZERO(&fds);
FD_SET(data->fd, &fds);
retval = select(data->fd + 1, &fds, NULL, NULL, &timeout);
}
/* Properly set guac_error */
if (retval < 0) {
guac_error = GUAC_STATUS_SEE_ERRNO;
guac_error_message = "Error while waiting for data on socket";
}
if (retval == 0) {
guac_error = GUAC_STATUS_INPUT_TIMEOUT;
guac_error_message = "Timeout while waiting for data on socket";
}
return retval;
}
guac_socket* guac_socket_open(int fd) {
/* Allocate socket and associated data */
guac_socket* socket = guac_socket_alloc();
__guac_socket_fd_data* data = malloc(sizeof(__guac_socket_fd_data));
/* Store file descriptor as socket data */
data->fd = fd;
socket->data = data;
/* Set read/write handlers */
socket->read_handler = __guac_socket_fd_read_handler;
socket->write_handler = __guac_socket_fd_write_handler;
socket->select_handler = __guac_socket_fd_select_handler;
return socket;
}

152
libguac/src/socket-nest.c Normal file
View File

@ -0,0 +1,152 @@
/* ***** 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 libguac.
*
* 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):
* David PHAM-VAN <d.pham-van@ulteo.com> Ulteo SAS - http://www.ulteo.com
*
* 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 ***** */
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#ifdef __MINGW32__
#include <winsock2.h>
#else
#include <sys/select.h>
#endif
#include <time.h>
#include <sys/time.h>
#include "socket.h"
#include "protocol.h"
#include "error.h"
#include "unicode.h"
#define GUAC_SOCKET_NEST_BUFFER_SIZE 8192
typedef struct __guac_socket_nest_data {
guac_socket* parent;
char buffer[GUAC_SOCKET_NEST_BUFFER_SIZE];
int index;
} __guac_socket_nest_data;
ssize_t __guac_socket_nest_write_handler(guac_socket* socket,
void* buf, size_t count) {
__guac_socket_nest_data* data = (__guac_socket_nest_data*) socket->data;
unsigned char* source = (unsigned char*) buf;
/* Current location in destination buffer during copy */
char* current = data->buffer;
/* Number of bytes remaining in source buffer */
int remaining = count;
/* If we can't actually store that many bytes, reduce number of bytes
* expected to be written */
if (remaining > GUAC_SOCKET_NEST_BUFFER_SIZE)
remaining = GUAC_SOCKET_NEST_BUFFER_SIZE;
/* Current offset within destination buffer */
int offset;
/* Number of characters before start of next character */
int skip = 0;
/* Copy UTF-8 characters into buffer */
for (offset = 0; offset < GUAC_SOCKET_NEST_BUFFER_SIZE; offset++) {
/* Get next byte */
unsigned char c = *source;
remaining--;
/* If skipping, then skip */
if (skip > 0) skip--;
/* Otherwise, determine next skip value, and increment length */
else {
/* Determine skip value (size in bytes of rest of character) */
skip = guac_utf8_charsize(c) - 1;
/* If not enough bytes to complete character, break */
if (skip > remaining)
break;
}
/* Store byte */
*current = c;
/* Advance to next character */
source++;
current++;
}
/* Append null-terminator */
*current = 0;
/* Send nest instruction containing read UTF-8 segment */
guac_protocol_send_nest(data->parent, data->index, data->buffer);
/* Return number of bytes actually written */
return offset;
}
guac_socket* guac_socket_nest(guac_socket* parent, int index) {
/* Allocate socket and associated data */
guac_socket* socket = guac_socket_alloc();
__guac_socket_nest_data* data = malloc(sizeof(__guac_socket_nest_data));
/* Store file descriptor as socket data */
data->parent = parent;
socket->data = data;
/* Set write handler */
socket->write_handler = __guac_socket_nest_write_handler;
return socket;
}

312
libguac/src/socket.c Normal file
View File

@ -0,0 +1,312 @@
/* ***** 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 libguac.
*
* 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):
* David PHAM-VAN <d.pham-van@ulteo.com> Ulteo SAS - http://www.ulteo.com
*
* 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 ***** */
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#ifdef __MINGW32__
#include <winsock2.h>
#else
#include <sys/select.h>
#endif
#include <time.h>
#include <sys/time.h>
#include "socket.h"
#include "error.h"
char __guac_socket_BASE64_CHARACTERS[64] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', '+', '/'
};
ssize_t __guac_socket_write(guac_socket* socket,
void* buf, size_t count) {
/* If handler defined, call it. */
if (socket->write_handler)
return socket->write_handler(socket, buf, count);
/* Otherwise, pretend everything was written. */
return count;
}
/* TODO: Implement guac_socket_write (buffered write) */
ssize_t guac_socket_read(guac_socket* socket, void* buf, size_t count) {
/* If handler defined, call it. */
if (socket->read_handler)
return socket->read_handler(socket, buf, count);
/* Otherwise, pretend nothing was read. */
return 0;
}
int guac_socket_select(guac_socket* socket, int usec_timeout) {
/* Call select handler if defined */
if (socket->select_handler)
return socket->select_handler(socket, usec_timeout);
/* Otherwise, assume ready. */
return 1;
}
guac_socket* guac_socket_alloc() {
guac_socket* socket = malloc(sizeof(guac_socket));
/* If no memory available, return with error */
if (socket == NULL) {
guac_error = GUAC_STATUS_NO_MEMORY;
guac_error_message = "Could not allocate memory for socket";
return NULL;
}
socket->__ready = 0;
socket->__written = 0;
socket->data = NULL;
/* Allocate instruction buffer */
socket->__instructionbuf_size = 1024;
socket->__instructionbuf = malloc(socket->__instructionbuf_size);
/* If no memory available, return with error */
if (socket->__instructionbuf == NULL) {
guac_error = GUAC_STATUS_NO_MEMORY;
guac_error_message = "Could not allocate memory for instruction buffer";
free(socket);
return NULL;
}
/* Init members */
socket->__instructionbuf_used_length = 0;
socket->__instructionbuf_parse_start = 0;
socket->__instructionbuf_elementc = 0;
/* No handlers yet */
socket->read_handler = NULL;
socket->write_handler = NULL;
socket->select_handler = NULL;
socket->free_handler = NULL;
return socket;
}
void guac_socket_free(guac_socket* socket) {
/* Call free handler if defined */
if (socket->free_handler)
socket->free_handler(socket);
guac_socket_flush(socket);
free(socket->__instructionbuf);
free(socket);
}
ssize_t guac_socket_write_int(guac_socket* socket, int64_t i) {
char buffer[128];
snprintf(buffer, sizeof(buffer), "%"PRIi64, i);
return guac_socket_write_string(socket, buffer);
}
ssize_t guac_socket_write_string(guac_socket* socket, const char* str) {
char* __out_buf = socket->__out_buf;
int retval;
for (; *str != '\0'; str++) {
__out_buf[socket->__written++] = *str;
/* Flush when necessary, return on error */
if (socket->__written > 8188 /* sizeof(__out_buf) - 4 */) {
retval = __guac_socket_write(socket, __out_buf, socket->__written);
if (retval < 0)
return retval;
socket->__written = 0;
}
}
return 0;
}
ssize_t __guac_socket_write_base64_triplet(guac_socket* socket, int a, int b, int c) {
char* __out_buf = socket->__out_buf;
int retval;
/* Byte 1 */
__out_buf[socket->__written++] = __guac_socket_BASE64_CHARACTERS[(a & 0xFC) >> 2]; /* [AAAAAA]AABBBB BBBBCC CCCCCC */
if (b >= 0) {
__out_buf[socket->__written++] = __guac_socket_BASE64_CHARACTERS[((a & 0x03) << 4) | ((b & 0xF0) >> 4)]; /* AAAAAA[AABBBB]BBBBCC CCCCCC */
if (c >= 0) {
__out_buf[socket->__written++] = __guac_socket_BASE64_CHARACTERS[((b & 0x0F) << 2) | ((c & 0xC0) >> 6)]; /* AAAAAA AABBBB[BBBBCC]CCCCCC */
__out_buf[socket->__written++] = __guac_socket_BASE64_CHARACTERS[c & 0x3F]; /* AAAAAA AABBBB BBBBCC[CCCCCC] */
}
else {
__out_buf[socket->__written++] = __guac_socket_BASE64_CHARACTERS[((b & 0x0F) << 2)]; /* AAAAAA AABBBB[BBBB--]------ */
__out_buf[socket->__written++] = '='; /* AAAAAA AABBBB BBBB--[------] */
}
}
else {
__out_buf[socket->__written++] = __guac_socket_BASE64_CHARACTERS[((a & 0x03) << 4)]; /* AAAAAA[AA----]------ ------ */
__out_buf[socket->__written++] = '='; /* AAAAAA AA----[------]------ */
__out_buf[socket->__written++] = '='; /* AAAAAA AA---- ------[------] */
}
/* At this point, 4 bytes have been socket->__written */
/* Flush when necessary, return on error */
if (socket->__written > 8188 /* sizeof(__out_buf) - 4 */) {
retval = __guac_socket_write(socket, __out_buf, socket->__written);
if (retval < 0)
return retval;
socket->__written = 0;
}
if (b < 0)
return 1;
if (c < 0)
return 2;
return 3;
}
ssize_t __guac_socket_write_base64_byte(guac_socket* socket, int buf) {
int* __ready_buf = socket->__ready_buf;
int retval;
__ready_buf[socket->__ready++] = buf;
/* Flush triplet */
if (socket->__ready == 3) {
retval = __guac_socket_write_base64_triplet(socket, __ready_buf[0], __ready_buf[1], __ready_buf[2]);
if (retval < 0)
return retval;
socket->__ready = 0;
}
return 1;
}
ssize_t guac_socket_write_base64(guac_socket* socket, const void* buf, size_t count) {
int retval;
const unsigned char* char_buf = (const unsigned char*) buf;
const unsigned char* end = char_buf + count;
while (char_buf < end) {
retval = __guac_socket_write_base64_byte(socket, *(char_buf++));
if (retval < 0)
return retval;
}
return 0;
}
ssize_t guac_socket_flush(guac_socket* socket) {
int retval;
/* Flush remaining bytes in buffer */
if (socket->__written > 0) {
retval = __guac_socket_write(socket,
socket->__out_buf, socket->__written);
if (retval < 0)
return retval;
socket->__written = 0;
}
return 0;
}
ssize_t guac_socket_flush_base64(guac_socket* socket) {
int retval;
/* Flush triplet to output buffer */
while (socket->__ready > 0) {
retval = __guac_socket_write_base64_byte(socket, -1);
if (retval < 0)
return retval;
}
return 0;
}

73
libguac/src/timestamp.c Normal file
View File

@ -0,0 +1,73 @@
/* ***** 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 libguac.
*
* 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 ***** */
#if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_NANOSLEEP)
#include <time.h>
#endif
#ifndef HAVE_CLOCK_GETTIME
#include <sys/time.h>
#endif
#include "timestamp.h"
guac_timestamp guac_timestamp_current() {
#ifdef HAVE_CLOCK_GETTIME
struct timespec current;
/* Get current time */
clock_gettime(CLOCK_REALTIME, &current);
/* Calculate milliseconds */
return (guac_timestamp) current.tv_sec * 1000 + current.tv_nsec / 1000000;
#else
struct timeval current;
/* Get current time */
gettimeofday(&current, NULL);
/* Calculate milliseconds */
return (guac_timestamp) current.tv_sec * 1000 + current.tv_usec / 1000;
#endif
}

87
libguac/src/unicode.c Normal file
View File

@ -0,0 +1,87 @@
/* ***** 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 libguac.
*
* 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 ***** */
#include <stddef.h>
#include "unicode.h"
size_t guac_utf8_charsize(unsigned char c) {
/* Determine size in bytes of character */
if ((c >>= 1) == 0x7E) return 6;
if ((c >>= 1) == 0x3E) return 5;
if ((c >>= 1) == 0x1E) return 4;
if ((c >>= 1) == 0x0E) return 3;
if ((c >>= 1) == 0x06) return 2;
/* Default to one character */
return 1;
}
size_t guac_utf8_strlen(const char* str) {
/* The current length of the string */
int length = 0;
/* Number of characters before start of next character */
int skip = 0;
while (*str != 0) {
/* If skipping, then skip */
if (skip > 0) skip--;
/* Otherwise, determine next skip value, and increment length */
else {
/* Get next character */
unsigned char c = (unsigned char) *str;
/* Determine skip value (size in bytes of rest of character) */
skip = guac_utf8_charsize(c) - 1;
length++;
}
str++;
}
return length;
}

62
libguac/tests/Makefile.am Normal file
View File

@ -0,0 +1,62 @@
# ***** 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 libguac.
#
# 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 *****
AUTOMAKE_OPTIONS = foreign
ACLOCAL_AMFLAGS = -I m4
AM_CFLAGS = -Werror -Wall -pedantic -I../include
TESTS = test_libguac
check_PROGRAMS = test_libguac
noinst_HEADERS = \
client/client_suite.h \
protocol/suite.h \
util/util_suite.h
test_libguac_SOURCES = \
test_libguac.c \
client/client_suite.c \
client/buffer_pool.c \
client/layer_pool.c \
protocol/suite.c \
protocol/instruction_read.c \
protocol/instruction_write.c \
protocol/nest_write.c \
util/util_suite.c \
util/guac_pool.c
test_libguac_LDADD = $(top_builddir)/src/libguac.la @CUNIT_LIBS@

View File

@ -0,0 +1,88 @@
/* ***** 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 libguac.
*
* 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 ***** */
#include <CUnit/Basic.h>
#include "client.h"
#include "client_suite.h"
void test_buffer_pool() {
guac_client* client;
int i;
int seen[GUAC_BUFFER_POOL_INITIAL_SIZE] = {0};
guac_layer* layer;
/* Get client */
client = guac_client_alloc();
CU_ASSERT_PTR_NOT_NULL_FATAL(client);
/* Fill pool */
for (i=0; i<GUAC_BUFFER_POOL_INITIAL_SIZE; i++) {
/* Allocate and throw away a layer (should not disturb buffer alloc) */
CU_ASSERT_PTR_NOT_NULL_FATAL(guac_client_alloc_layer(client));
layer = guac_client_alloc_buffer(client);
/* Index should be within pool size */
CU_ASSERT_PTR_NOT_NULL_FATAL(layer);
CU_ASSERT_FATAL(layer->index < 0);
CU_ASSERT_FATAL(layer->index >= -GUAC_BUFFER_POOL_INITIAL_SIZE);
/* This should be a layer we have not seen yet */
CU_ASSERT_FALSE(seen[-layer->index - 1]);
seen[-layer->index - 1] = 1;
guac_client_free_buffer(client, layer);
}
/* Now that pool is filled, we should get a previously seen layer */
layer = guac_client_alloc_buffer(client);
CU_ASSERT_FATAL(layer->index < 0);
CU_ASSERT_FATAL(layer->index >= -GUAC_BUFFER_POOL_INITIAL_SIZE);
CU_ASSERT_TRUE(seen[-layer->index - 1]);
/* Free client */
guac_client_free(client);
}

View File

@ -0,0 +1,72 @@
/* ***** 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 libguac.
*
* 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 ***** */
#include <CUnit/Basic.h>
#include "client_suite.h"
int client_suite_init() {
return 0;
}
int client_suite_cleanup() {
return 0;
}
int register_client_suite() {
/* Add client test suite */
CU_pSuite suite = CU_add_suite("client",
client_suite_init, client_suite_cleanup);
if (suite == NULL) {
CU_cleanup_registry();
return CU_get_error();
}
/* Add tests */
if (
CU_add_test(suite, "layer-pool", test_layer_pool) == NULL
|| CU_add_test(suite, "buffer-pool", test_buffer_pool) == NULL
) {
CU_cleanup_registry();
return CU_get_error();
}
return 0;
}

View File

@ -0,0 +1,47 @@
/* ***** 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 libguac.
*
* 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 ***** */
#ifndef _GUAC_TEST_CLIENT_SUITE_H
#define _GUAC_TEST_CLIENT_SUITE_H
int register_client_suite();
void test_layer_pool();
void test_buffer_pool();
#endif

View File

@ -0,0 +1,88 @@
/* ***** 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 libguac.
*
* 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 ***** */
#include <CUnit/Basic.h>
#include "client.h"
#include "client_suite.h"
void test_layer_pool() {
guac_client* client;
int i;
int seen[GUAC_BUFFER_POOL_INITIAL_SIZE] = {0};
guac_layer* layer;
/* Get client */
client = guac_client_alloc();
CU_ASSERT_PTR_NOT_NULL_FATAL(client);
/* Fill pool */
for (i=0; i<GUAC_BUFFER_POOL_INITIAL_SIZE; i++) {
/* Allocate and throw away a buffer (should not disturb layer alloc) */
CU_ASSERT_PTR_NOT_NULL_FATAL(guac_client_alloc_buffer(client));
layer = guac_client_alloc_layer(client);
/* Index should be within pool size */
CU_ASSERT_PTR_NOT_NULL_FATAL(layer);
CU_ASSERT_FATAL(layer->index > 0);
CU_ASSERT_FATAL(layer->index <= GUAC_BUFFER_POOL_INITIAL_SIZE);
/* This should be a layer we have not seen yet */
CU_ASSERT_FALSE(seen[layer->index - 1]);
seen[layer->index - 1] = 1;
guac_client_free_layer(client, layer);
}
/* Now that pool is filled, we should get a previously seen layer */
layer = guac_client_alloc_layer(client);
CU_ASSERT_FATAL(layer->index > 0);
CU_ASSERT_FATAL(layer->index <= GUAC_BUFFER_POOL_INITIAL_SIZE);
CU_ASSERT_TRUE(seen[layer->index - 1]);
/* Free client */
guac_client_free(client);
}

View File

@ -0,0 +1,122 @@
/* ***** 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 libguac.
*
* 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 ***** */
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <CUnit/Basic.h>
#include "error.h"
#include "instruction.h"
#include "protocol.h"
#include "socket.h"
#include "suite.h"
void test_instruction_read() {
int rfd, wfd;
int fd[2], childpid;
char test_string[] = "4.test,6.a" UTF8_4 "b,"
"5.12345,10.a" UTF8_8 "c;"
"5.test2,10.hellohello,15.worldworldworld;";
/* Create pipe */
CU_ASSERT_EQUAL_FATAL(pipe(fd), 0);
/* File descriptors */
rfd = fd[0];
wfd = fd[1];
/* Fork */
if ((childpid = fork()) == -1) {
/* ERROR */
perror("fork");
return;
}
/* Child (pipe writer) */
if (childpid != 0) {
close(rfd);
CU_ASSERT_EQUAL(
write(wfd, test_string, sizeof(test_string)),
sizeof(test_string)
);
exit(0);
}
/* Parent (unit test) */
else {
guac_socket* socket;
guac_instruction* instruction;
close(wfd);
/* Open guac socket */
socket = guac_socket_open(rfd);
CU_ASSERT_PTR_NOT_NULL_FATAL(socket);
/* Read instruction */
instruction = guac_instruction_read(socket, 1000000);
CU_ASSERT_PTR_NOT_NULL_FATAL(instruction);
/* Validate contents */
CU_ASSERT_STRING_EQUAL(instruction->opcode, "test");
CU_ASSERT_EQUAL_FATAL(instruction->argc, 3);
CU_ASSERT_STRING_EQUAL(instruction->argv[0], "a" UTF8_4 "b");
CU_ASSERT_STRING_EQUAL(instruction->argv[1], "12345");
CU_ASSERT_STRING_EQUAL(instruction->argv[2], "a" UTF8_8 "c");
/* Read another instruction */
guac_instruction_free(instruction);
instruction = guac_instruction_read(socket, 1000000);
/* Validate contents */
CU_ASSERT_STRING_EQUAL(instruction->opcode, "test2");
CU_ASSERT_EQUAL_FATAL(instruction->argc, 2);
CU_ASSERT_STRING_EQUAL(instruction->argv[0], "hellohello");
CU_ASSERT_STRING_EQUAL(instruction->argv[1], "worldworldworld");
guac_instruction_free(instruction);
guac_socket_free(socket);
}
}

View File

@ -0,0 +1,118 @@
/* ***** 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 libguac.
*
* 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 ***** */
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <CUnit/Basic.h>
#include "error.h"
#include "instruction.h"
#include "protocol.h"
#include "socket.h"
#include "suite.h"
void test_instruction_write() {
int rfd, wfd;
int fd[2], childpid;
/* Create pipe */
CU_ASSERT_EQUAL_FATAL(pipe(fd), 0);
/* File descriptors */
rfd = fd[0];
wfd = fd[1];
/* Fork */
if ((childpid = fork()) == -1) {
/* ERROR */
perror("fork");
return;
}
/* Child (pipe writer) */
if (childpid != 0) {
guac_socket* socket;
close(rfd);
/* Open guac socket */
socket = guac_socket_open(wfd);
/* Write instruction */
guac_protocol_send_clipboard(socket, "a" UTF8_4 "b" UTF8_4 "c");
guac_protocol_send_sync(socket, 12345);
guac_socket_flush(socket);
guac_socket_free(socket);
exit(0);
}
/* Parent (unit test) */
else {
char expected[] =
"9.clipboard,11.a" UTF8_4 "b" UTF8_4 "c;"
"4.sync,5.12345;";
int numread;
char buffer[1024];
int offset = 0;
close(wfd);
/* Read everything available into buffer */
while ((numread =
read(rfd,
&(buffer[offset]),
sizeof(buffer)-offset)) != 0) {
offset += numread;
}
/* Add NULL terminator */
buffer[offset] = '\0';
/* Read value should be equal to expected value */
CU_ASSERT_STRING_EQUAL(buffer, expected);
}
}

View File

@ -0,0 +1,126 @@
/* ***** 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 libguac.
*
* 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 ***** */
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <CUnit/Basic.h>
#include "error.h"
#include "instruction.h"
#include "protocol.h"
#include "socket.h"
#include "suite.h"
void test_nest_write() {
int rfd, wfd;
int fd[2], childpid;
/* Create pipe */
CU_ASSERT_EQUAL_FATAL(pipe(fd), 0);
/* File descriptors */
rfd = fd[0];
wfd = fd[1];
/* Fork */
if ((childpid = fork()) == -1) {
/* ERROR */
perror("fork");
return;
}
/* Child (pipe writer) */
if (childpid != 0) {
guac_socket* nested_socket;
guac_socket* socket;
close(rfd);
/* Open guac socket */
socket = guac_socket_open(wfd);
/* Nest socket */
nested_socket = guac_socket_nest(socket, 0);
/* Write instruction */
guac_protocol_send_clipboard(nested_socket, "a" UTF8_4 "b" UTF8_4 "c");
guac_protocol_send_sync(nested_socket, 12345);
guac_socket_flush(nested_socket);
guac_socket_flush(socket);
guac_socket_free(nested_socket);
guac_socket_free(socket);
exit(0);
}
/* Parent (unit test) */
else {
char expected[] =
"4.nest,1.0,42."
"9.clipboard,11.a" UTF8_4 "b" UTF8_4 "c;"
"4.sync,5.12345;"
";";
int numread;
char buffer[1024];
int offset = 0;
close(wfd);
/* Read everything available into buffer */
while ((numread =
read(rfd,
&(buffer[offset]),
sizeof(buffer)-offset)) != 0) {
offset += numread;
}
/* Add NULL terminator */
buffer[offset] = '\0';
/* Read value should be equal to expected value */
CU_ASSERT_STRING_EQUAL(buffer, expected);
}
}

View File

@ -0,0 +1,73 @@
/* ***** 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 libguac.
*
* 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 ***** */
#include <CUnit/Basic.h>
#include "suite.h"
int protocol_suite_init() {
return 0;
}
int protocol_suite_cleanup() {
return 0;
}
int register_protocol_suite() {
/* Add protocol test suite */
CU_pSuite suite = CU_add_suite("protocol",
protocol_suite_init, protocol_suite_cleanup);
if (suite == NULL) {
CU_cleanup_registry();
return CU_get_error();
}
/* Add tests */
if (
CU_add_test(suite, "instruction-read", test_instruction_read) == NULL
|| CU_add_test(suite, "instruction-write", test_instruction_write) == NULL
|| CU_add_test(suite, "nest-write", test_nest_write) == NULL
) {
CU_cleanup_registry();
return CU_get_error();
}
return 0;
}

View File

@ -0,0 +1,56 @@
/* ***** 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 libguac.
*
* 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 ***** */
#ifndef _GUAC_TEST_PROTOCOL_SUITE_H
#define _GUAC_TEST_PROTOCOL_SUITE_H
/* Unicode (UTF-8) strings */
#define UTF8_1 "\xe7\x8a\xac" /* One character */
#define UTF8_2 UTF8_1 "\xf0\x90\xac\x80" /* Two characters */
#define UTF8_3 UTF8_2 "z" /* Three characters */
#define UTF8_4 UTF8_3 "\xc3\xa1" /* Four characters */
#define UTF8_8 UTF8_4 UTF8_4 /* Eight characters */
int register_protocol_suite();
void test_instruction_read();
void test_instruction_write();
void test_nest_write();
#endif

View File

@ -0,0 +1,62 @@
/* ***** 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 libguac.
*
* 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 ***** */
#include <CUnit/Basic.h>
#include "protocol/suite.h"
#include "client/client_suite.h"
#include "util/util_suite.h"
int main() {
/* Init registry */
if (CU_initialize_registry() != CUE_SUCCESS)
return CU_get_error();
/* Register suites */
register_protocol_suite();
register_client_suite();
register_util_suite();
/* Run tests */
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests();
CU_cleanup_registry();
return CU_get_error();
}

View File

@ -0,0 +1,105 @@
/* ***** 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 libguac.
*
* 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 ***** */
#include <CUnit/Basic.h>
#include "pool.h"
#include "util_suite.h"
#define UNSEEN 0
#define SEEN_PHASE_1 1
#define SEEN_PHASE_2 2
#define POOL_SIZE 128
void test_guac_pool() {
guac_pool* pool;
int i;
int seen[POOL_SIZE] = {0};
int value;
/* Get pool */
pool = guac_pool_alloc(POOL_SIZE);
CU_ASSERT_PTR_NOT_NULL_FATAL(pool);
/* Fill pool */
for (i=0; i<POOL_SIZE; i++) {
/* Get value from pool */
value = guac_pool_next_int(pool);
/* Value should be within pool size */
CU_ASSERT_FATAL(value >= 0);
CU_ASSERT_FATAL(value < POOL_SIZE);
/* This should be an integer we have not seen yet */
CU_ASSERT_EQUAL(UNSEEN, seen[value]);
seen[value] = SEEN_PHASE_1;
/* Return value to pool */
guac_pool_free_int(pool, value);
}
/* Now that pool is filled, we should get ONLY previously seen integers */
for (i=0; i<POOL_SIZE; i++) {
/* Get value from pool */
value = guac_pool_next_int(pool);
/* Value should be within pool size */
CU_ASSERT_FATAL(value >= 0);
CU_ASSERT_FATAL(value < POOL_SIZE);
/* This should be an integer we have seen already */
CU_ASSERT_EQUAL(SEEN_PHASE_1, seen[value]);
seen[value] = SEEN_PHASE_2;
}
/* Pool is filled to minimum now. Next value should be equal to size. */
value = guac_pool_next_int(pool);
CU_ASSERT_EQUAL(POOL_SIZE, value);
/* Free pool */
guac_pool_free(pool);
}

View File

@ -0,0 +1,71 @@
/* ***** 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 libguac.
*
* 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 ***** */
#include <CUnit/Basic.h>
#include "util_suite.h"
int util_suite_init() {
return 0;
}
int util_suite_cleanup() {
return 0;
}
int register_util_suite() {
/* Add util test suite */
CU_pSuite suite = CU_add_suite("util",
util_suite_init, util_suite_cleanup);
if (suite == NULL) {
CU_cleanup_registry();
return CU_get_error();
}
/* Add tests */
if (
CU_add_test(suite, "guac-pool", test_guac_pool) == NULL
) {
CU_cleanup_registry();
return CU_get_error();
}
return 0;
}

View File

@ -0,0 +1,46 @@
/* ***** 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 libguac.
*
* 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 ***** */
#ifndef _GUAC_TEST_UTIL_SUITE_H
#define _GUAC_TEST_UTIL_SUITE_H
int register_util_suite();
void test_guac_pool();
#endif