initial
This commit is contained in:
commit
f8f622157c
674
COPYING
Normal file
674
COPYING
Normal file
@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
165
COPYING.LESSER
Normal file
165
COPYING.LESSER
Normal file
@ -0,0 +1,165 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
51
README
Normal file
51
README
Normal file
@ -0,0 +1,51 @@
|
||||
Prototype Spice Javascript client
|
||||
|
||||
Instructions and status as of June 1, 2012.
|
||||
|
||||
Requirements:
|
||||
|
||||
1. Modern Firefox or Chrome
|
||||
|
||||
2. A WebSocket proxy
|
||||
|
||||
I've used websockify:
|
||||
https://github.com/kanaka/websockify
|
||||
works great.
|
||||
|
||||
|
||||
3. A spice server
|
||||
|
||||
At this point, I've tested with qemu hosting
|
||||
a Fedora image, a Vista image, and with Xspice.
|
||||
Vista was pretty bad; I recommend either Linux or Xspice.
|
||||
|
||||
** Xspice has a processing issue; see this email:
|
||||
http://lists.freedesktop.org/archives/spice-devel/2012-May/009020.html
|
||||
|
||||
|
||||
Optional:
|
||||
1. A web server
|
||||
|
||||
With firefox, you can just open file:///your-path-to-spice.html-here
|
||||
|
||||
With Chrome, you have to set a secret config flag to do that, or
|
||||
serve the files from a web server.
|
||||
|
||||
|
||||
Steps:
|
||||
|
||||
1. Start the spice server
|
||||
|
||||
2. Start websockify; my command line looks like this:
|
||||
./websockify 5959 localhost:5900
|
||||
|
||||
3. Fire up spice.html, set host + port + password, and click start
|
||||
|
||||
|
||||
Status:
|
||||
|
||||
The TODO file should be a fairly comprehensive list of tasks
|
||||
required to make this client more fully functional.
|
||||
|
||||
As of June 1, 2012, this client is a nifty proof of concept,
|
||||
but a long way from being a useful production tool.
|
90
TODO
Normal file
90
TODO
Normal file
@ -0,0 +1,90 @@
|
||||
Bugs:
|
||||
|
||||
. In my latest Xorg/fluxbox theme test, I get flickering of title
|
||||
windows, notably when you start up gimp. That seems new.
|
||||
|
||||
. In Chrome, I've gotten it to get the parsing out of sync.
|
||||
Not clear why or how to reproduce. I've added a javascript
|
||||
alert to hopefully make finding it more possible.
|
||||
A test case is really needed for it...
|
||||
|
||||
. Drawing with Gimp is slow (lack of stream support?)
|
||||
|
||||
. If using xspice, you can get two bugs; a complete stall
|
||||
(until you do something on the X server), or losing the mouse.
|
||||
Both are probably related to that the watch_add/watch_update_mask functionality
|
||||
in the qxl driver doesn't work. A patch for that has been submitted
|
||||
to spice-devel ('Actually process write watches in the wakeup handler').
|
||||
|
||||
|
||||
Medium Tasks:
|
||||
|
||||
. Get the mouse event code out of spicemsg (and make spicemsg
|
||||
*only* about messages)
|
||||
|
||||
. Change the message processing to be able to handle
|
||||
an array of ArrayBuffers so we don't have to
|
||||
use the combine function, which is presumed slow.
|
||||
|
||||
. Use the 'real' DataView if we have it
|
||||
|
||||
. Remove main() from quic.c and respin it
|
||||
- It's causing unneeded bloat and memory use.
|
||||
|
||||
. Consider passing a status change event back to the front end
|
||||
(e.g. indicators for numlock, connection status, all that jazz)
|
||||
|
||||
. Try to further Improve mouse position sends
|
||||
- We now discard motions when we're more than 2 * SPICE_INPUT_MOTION_ACK_BUNCH
|
||||
from an ack, just like the gtk client
|
||||
- Other idea 1: queue them and only send when idle, but collapse first?
|
||||
- Other idea 2: Time limit motion events
|
||||
|
||||
. The whole key code to scan code thing is awful and should be
|
||||
taken out and shot...or revamped
|
||||
|
||||
|
||||
Big Tasks:
|
||||
|
||||
. Generate messages + enums from spice.proto
|
||||
|
||||
. Video + Audio:
|
||||
- Need either ogg or webm codec
|
||||
- Probably need a codec other than celt 0.51
|
||||
- Need a way to feed stream into a media object
|
||||
* Javascript uri?
|
||||
* best would be Media Source Extensions draft, but only in Chrome so far
|
||||
* some trick with createObjectUrl? see:
|
||||
- http://dev.w3.org/2011/webrtc/editor/getusermedia.html
|
||||
|
||||
. Explore clipboard
|
||||
- Supporting it may require unpleasant hacks
|
||||
|
||||
. Fully flesh out image type support; plt, glz, and jpeg/alpha are likely
|
||||
to be real work
|
||||
|
||||
. Fix the many limitations of Draw operation support (clipping, masking,
|
||||
scaling, and so on)
|
||||
|
||||
. Implement direct websocket support for the spice server
|
||||
|
||||
. Profile the whole mess
|
||||
- Initial profiling suggests image decompression is the big hog
|
||||
|
||||
. Quic: faster implementations
|
||||
* current implementation is approximately 13x slower
|
||||
than equivalent C code. Should be able to do
|
||||
much better than that.
|
||||
|
||||
. Implement agent support
|
||||
|
||||
. Build a test suite for measuring performance
|
||||
- Latency, bandwidth, packet loss
|
||||
- But how to quantify 'feel'?
|
||||
- Suggestion: recordmydesktop to capture videos
|
||||
Use something like cxtest to create scripts
|
||||
Do this with varying latency/bandwidth, etc
|
||||
We can play videos side by side
|
||||
And potentially use tool like MSU Video Quality Measurement Tool
|
||||
(SSIM is the concept for measuring how much frames differ)
|
||||
- Key metric - how much cpu / memory / bandwidth per 'active' user
|
51
bitmap.js
Normal file
51
bitmap.js
Normal file
@ -0,0 +1,51 @@
|
||||
"use strict";
|
||||
/*
|
||||
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||
|
||||
This file is part of spice-html5.
|
||||
|
||||
spice-html5 is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
spice-html5 is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
** bitmap.js
|
||||
** Handle SPICE_IMAGE_TYPE_BITMAP
|
||||
**--------------------------------------------------------------------------*/
|
||||
function convert_spice_bitmap_to_web(context, spice_bitmap)
|
||||
{
|
||||
var ret;
|
||||
var offset, x;
|
||||
var u8 = new Uint8Array(spice_bitmap.data);
|
||||
if (spice_bitmap.format != SPICE_BITMAP_FMT_32BIT &&
|
||||
spice_bitmap.format != SPICE_BITMAP_FMT_RGBA)
|
||||
return undefined;
|
||||
|
||||
ret = context.createImageData(spice_bitmap.x, spice_bitmap.y);
|
||||
for (offset = 0; offset < (spice_bitmap.y * spice_bitmap.stride); )
|
||||
for (x = 0; x < spice_bitmap.x; x++, offset += 4)
|
||||
{
|
||||
ret.data[offset + 0 ] = u8[offset + 2];
|
||||
ret.data[offset + 1 ] = u8[offset + 1];
|
||||
ret.data[offset + 2 ] = u8[offset + 0];
|
||||
|
||||
// FIXME - We effectively treat all images as having SPICE_IMAGE_FLAGS_HIGH_BITS_SET
|
||||
if (spice_bitmap.format == SPICE_BITMAP_FMT_32BIT)
|
||||
ret.data[offset + 3] = 255;
|
||||
else
|
||||
ret.data[offset + 3] = u8[offset];
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
92
cursor.js
Normal file
92
cursor.js
Normal file
@ -0,0 +1,92 @@
|
||||
"use strict";
|
||||
/*
|
||||
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||
|
||||
This file is part of spice-html5.
|
||||
|
||||
spice-html5 is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
spice-html5 is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
** SpiceCursorConn
|
||||
** Drive the Spice Cursor Channel
|
||||
**--------------------------------------------------------------------------*/
|
||||
function SpiceCursorConn()
|
||||
{
|
||||
SpiceConn.apply(this, arguments);
|
||||
}
|
||||
|
||||
SpiceCursorConn.prototype = Object.create(SpiceConn.prototype);
|
||||
SpiceCursorConn.prototype.process_channel_message = function(msg)
|
||||
{
|
||||
if (msg.type == SPICE_MSG_CURSOR_INIT)
|
||||
{
|
||||
var cursor_init = new SpiceMsgCursorInit(msg.data);
|
||||
DEBUG > 1 && console.log("SpiceMsgCursorInit");
|
||||
if (this.parent && this.parent.inputs &&
|
||||
this.parent.inputs.mouse_mode == SPICE_MOUSE_MODE_SERVER)
|
||||
{
|
||||
// FIXME - this imagines that the server actually
|
||||
// provides the current cursor position,
|
||||
// instead of 0,0. As of May 11, 2012,
|
||||
// that assumption was false :-(.
|
||||
this.parent.inputs.mousex = cursor_init.position.x;
|
||||
this.parent.inputs.mousey = cursor_init.position.y;
|
||||
}
|
||||
// FIXME - We don't handle most of the parameters here...
|
||||
return true;
|
||||
}
|
||||
|
||||
if (msg.type == SPICE_MSG_CURSOR_SET)
|
||||
{
|
||||
var cursor_set = new SpiceMsgCursorSet(msg.data);
|
||||
DEBUG > 1 && console.log("SpiceMsgCursorSet");
|
||||
if (cursor_set.flags & SPICE_CURSOR_FLAGS_NONE)
|
||||
{
|
||||
document.getElementById(this.parent.screen_id).style.cursor = "none";
|
||||
return true;
|
||||
}
|
||||
|
||||
if (cursor_set.flags > 0)
|
||||
this.log_warn("FIXME: No support for cursor flags " + cursor_set.flags);
|
||||
|
||||
if (cursor_set.cursor.header.type != SPICE_CURSOR_TYPE_ALPHA)
|
||||
{
|
||||
this.log_warn("FIXME: No support for cursor type " + cursor_set.cursor.header.type);
|
||||
return false;
|
||||
}
|
||||
|
||||
this.set_cursor(cursor_set.cursor);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (msg.type == SPICE_MSG_CURSOR_HIDE)
|
||||
{
|
||||
DEBUG > 1 && console.log("SpiceMsgCursorHide");
|
||||
document.getElementById(this.parent.screen_id).style.cursor = "none";
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
SpiceCursorConn.prototype.set_cursor = function(cursor)
|
||||
{
|
||||
var pngstr = create_rgba_png(cursor.header.height, cursor.header.width, cursor.data);
|
||||
var curstr = 'url(data:image/png,' + pngstr + ') ' +
|
||||
cursor.header.hot_spot_x + ' ' + cursor.header.hot_spot_y + ", default";
|
||||
document.getElementById(this.parent.screen_id).style.cursor = curstr;
|
||||
}
|
673
display.js
Normal file
673
display.js
Normal file
@ -0,0 +1,673 @@
|
||||
"use strict";
|
||||
/*
|
||||
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||
|
||||
This file is part of spice-html5.
|
||||
|
||||
spice-html5 is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
spice-html5 is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
** FIXME: putImageData does not support Alpha blending
|
||||
** or compositing. So if we have data in an ImageData
|
||||
** format, we have to draw it onto a context,
|
||||
** and then use drawImage to put it onto the target,
|
||||
** as drawImage does alpha.
|
||||
**--------------------------------------------------------------------------*/
|
||||
function putImageDataWithAlpha(context, d, x, y)
|
||||
{
|
||||
var c = document.createElement("canvas");
|
||||
var t = c.getContext("2d");
|
||||
c.setAttribute('width', d.width);
|
||||
c.setAttribute('height', d.height);
|
||||
t.putImageData(d, 0, 0);
|
||||
context.drawImage(c, x, y, d.width, d.height);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
** FIXME: Spice will send an image with '0' alpha when it is intended to
|
||||
** go on a surface w/no alpha. So in that case, we have to strip
|
||||
** out the alpha. The test case for this was flux box; in a Xspice
|
||||
** server, right click on the desktop to get the menu; the top bar
|
||||
** doesn't paint/highlight correctly w/out this change.
|
||||
**--------------------------------------------------------------------------*/
|
||||
function stripAlpha(d)
|
||||
{
|
||||
var i;
|
||||
for (i = 0; i < (d.width * d.height * 4); i += 4)
|
||||
d.data[i + 3] = 255;
|
||||
}
|
||||
|
||||
// FIXME - this is a hack for quic.js, I should fix this...
|
||||
var global_ctx;
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
** SpiceDisplayConn
|
||||
** Drive the Spice Display Channel
|
||||
**--------------------------------------------------------------------------*/
|
||||
function SpiceDisplayConn()
|
||||
{
|
||||
SpiceConn.apply(this, arguments);
|
||||
}
|
||||
|
||||
SpiceDisplayConn.prototype = Object.create(SpiceConn.prototype);
|
||||
SpiceDisplayConn.prototype.process_channel_message = function(msg)
|
||||
{
|
||||
if (msg.type == SPICE_MSG_DISPLAY_MARK)
|
||||
{
|
||||
// FIXME - DISPLAY_MARK not implemented (may be hard or impossible)
|
||||
this.known_unimplemented(msg.type, "Display Mark");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (msg.type == SPICE_MSG_DISPLAY_RESET)
|
||||
{
|
||||
DEBUG > 2 && console.log("Display reset");
|
||||
this.surfaces[this.primary_surface].canvas.context.restore();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (msg.type == SPICE_MSG_DISPLAY_DRAW_COPY)
|
||||
{
|
||||
var draw_copy = new SpiceMsgDisplayDrawCopy(msg.data);
|
||||
|
||||
DEBUG > 1 && this.log_draw("DrawCopy", draw_copy);
|
||||
|
||||
if (! draw_copy.base.box.is_same_size(draw_copy.data.src_area))
|
||||
this.log_warn("FIXME: DrawCopy src_area is a different size than base.box; we do not handle that yet.");
|
||||
if (draw_copy.base.clip.type != SPICE_CLIP_TYPE_NONE)
|
||||
this.log_warn("FIXME: DrawCopy we don't handle clipping yet");
|
||||
if (draw_copy.data.rop_descriptor != SPICE_ROPD_OP_PUT)
|
||||
this.log_warn("FIXME: DrawCopy we don't handle ropd type: " + draw_copy.data.rop_descriptor);
|
||||
if (draw_copy.data.mask.flags)
|
||||
this.log_warn("FIXME: DrawCopy we don't handle mask flag: " + draw_copy.data.mask.flags);
|
||||
if (draw_copy.data.mask.bitmap)
|
||||
this.log_warn("FIXME: DrawCopy we don't handle mask");
|
||||
|
||||
if (draw_copy.data && draw_copy.data.src_bitmap)
|
||||
{
|
||||
if (draw_copy.data.src_bitmap.descriptor.flags &&
|
||||
draw_copy.data.src_bitmap.descriptor.flags != SPICE_IMAGE_FLAGS_CACHE_ME &&
|
||||
draw_copy.data.src_bitmap.descriptor.flags != SPICE_IMAGE_FLAGS_HIGH_BITS_SET)
|
||||
{
|
||||
this.log_warn("FIXME: DrawCopy unhandled image flags: " + draw_copy.data.src_bitmap.descriptor.flags);
|
||||
DEBUG <= 1 && this.log_draw("DrawCopy", draw_copy);
|
||||
}
|
||||
|
||||
if (draw_copy.data.src_bitmap.descriptor.type == SPICE_IMAGE_TYPE_QUIC)
|
||||
{
|
||||
if (! draw_copy.data.src_bitmap.quic)
|
||||
{
|
||||
this.log_warn("FIXME: DrawCopy could not handle this QUIC file.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.draw_copy_helper(
|
||||
{ base: draw_copy.base,
|
||||
src_area: draw_copy.data.src_area,
|
||||
image_data: draw_copy.data.src_bitmap.quic.imgData,
|
||||
tag: "copyquic." + draw_copy.data.src_bitmap.quic.type,
|
||||
has_alpha: (draw_copy.data.src_bitmap.quic.type == QUIC_IMAGE_TYPE_RGBA ? true : false) ,
|
||||
descriptor : draw_copy.data.src_bitmap.descriptor
|
||||
});
|
||||
}
|
||||
else if (draw_copy.data.src_bitmap.descriptor.type == SPICE_IMAGE_TYPE_FROM_CACHE ||
|
||||
draw_copy.data.src_bitmap.descriptor.type == SPICE_IMAGE_TYPE_FROM_CACHE_LOSSLESS)
|
||||
{
|
||||
if (! this.cache || ! this.cache[draw_copy.data.src_bitmap.descriptor.id])
|
||||
{
|
||||
this.log_warn("FIXME: DrawCopy did not find image id " + draw_copy.data.src_bitmap.descriptor.id + " in cache.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.draw_copy_helper(
|
||||
{ base: draw_copy.base,
|
||||
src_area: draw_copy.data.src_area,
|
||||
image_data: this.cache[draw_copy.data.src_bitmap.descriptor.id],
|
||||
tag: "copycache." + draw_copy.data.src_bitmap.descriptor.id,
|
||||
has_alpha: true, /* FIXME - may want this to be false... */
|
||||
descriptor : draw_copy.data.src_bitmap.descriptor
|
||||
});
|
||||
|
||||
/* FIXME - LOSSLESS CACHE ramifications not understood or handled */
|
||||
}
|
||||
else if (draw_copy.data.src_bitmap.descriptor.type == SPICE_IMAGE_TYPE_SURFACE)
|
||||
{
|
||||
var source_context = this.surfaces[draw_copy.data.src_bitmap.surface_id].canvas.context;
|
||||
var target_context = this.surfaces[draw_copy.base.surface_id].canvas.context;
|
||||
|
||||
var source_img = source_context.getImageData(
|
||||
draw_copy.data.src_area.left, draw_copy.data.src_area.top,
|
||||
draw_copy.data.src_area.right - draw_copy.data.src_area.left,
|
||||
draw_copy.data.src_area.bottom - draw_copy.data.src_area.top);
|
||||
var computed_src_area = new SpiceRect;
|
||||
computed_src_area.top = computed_src_area.left = 0;
|
||||
computed_src_area.right = source_img.width;
|
||||
computed_src_area.bottom = source_img.height;
|
||||
|
||||
/* FIXME - there is a potential optimization here.
|
||||
That is, if the surface is from 0,0, and
|
||||
both surfaces are alpha surfaces, you should
|
||||
be able to just do a drawImage, which should
|
||||
save time. */
|
||||
|
||||
return this.draw_copy_helper(
|
||||
{ base: draw_copy.base,
|
||||
src_area: computed_src_area,
|
||||
image_data: source_img,
|
||||
tag: "copysurf." + draw_copy.data.src_bitmap.surface_id,
|
||||
has_alpha: this.surfaces[draw_copy.data.src_bitmap.surface_id].format == SPICE_SURFACE_FMT_32_xRGB ? false : true,
|
||||
descriptor : draw_copy.data.src_bitmap.descriptor
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (draw_copy.data.src_bitmap.descriptor.type == SPICE_IMAGE_TYPE_JPEG)
|
||||
{
|
||||
if (! draw_copy.data.src_bitmap.jpeg)
|
||||
{
|
||||
this.log_warn("FIXME: DrawCopy could not handle this JPEG file.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// FIXME - how lame is this. Be have it in binary format, and we have
|
||||
// to put it into string to get it back into jpeg. Blech.
|
||||
var tmpstr = "data:image/jpeg,";
|
||||
var img = new Image;
|
||||
var i;
|
||||
var qdv = new Uint8Array(draw_copy.data.src_bitmap.jpeg.data);
|
||||
for (i = 0; i < qdv.length; i++)
|
||||
{
|
||||
tmpstr += '%';
|
||||
if (qdv[i] < 16)
|
||||
tmpstr += '0';
|
||||
tmpstr += qdv[i].toString(16);
|
||||
}
|
||||
|
||||
img.o =
|
||||
{ base: draw_copy.base,
|
||||
tag: "jpeg." + draw_copy.data.src_bitmap.surface_id,
|
||||
descriptor : draw_copy.data.src_bitmap.descriptor,
|
||||
sc : this,
|
||||
};
|
||||
img.onload = handle_draw_jpeg_onload;
|
||||
img.src = tmpstr;
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (draw_copy.data.src_bitmap.descriptor.type == SPICE_IMAGE_TYPE_BITMAP)
|
||||
{
|
||||
var canvas = this.surfaces[draw_copy.base.surface_id].canvas;
|
||||
if (! draw_copy.data.src_bitmap.bitmap)
|
||||
{
|
||||
this.log_err("null bitmap");
|
||||
return false;
|
||||
}
|
||||
|
||||
var source_img = convert_spice_bitmap_to_web(canvas.context,
|
||||
draw_copy.data.src_bitmap.bitmap);
|
||||
if (! source_img)
|
||||
{
|
||||
this.log_warn("FIXME: Unable to interpret bitmap of format: " +
|
||||
draw_copy.data.src_bitmap.bitmap.format);
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.draw_copy_helper(
|
||||
{ base: draw_copy.base,
|
||||
src_area: draw_copy.data.src_area,
|
||||
image_data: source_img,
|
||||
tag: "bitmap." + draw_copy.data.src_bitmap.bitmap.format,
|
||||
has_alpha: draw_copy.data.src_bitmap.bitmap == SPICE_BITMAP_FMT_32BIT ? false : true,
|
||||
descriptor : draw_copy.data.src_bitmap.descriptor
|
||||
});
|
||||
}
|
||||
else if (draw_copy.data.src_bitmap.descriptor.type == SPICE_IMAGE_TYPE_LZ_RGB)
|
||||
{
|
||||
var canvas = this.surfaces[draw_copy.base.surface_id].canvas;
|
||||
if (! draw_copy.data.src_bitmap.lz_rgb)
|
||||
{
|
||||
this.log_err("null lz_rgb ");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (draw_copy.data.src_bitmap.lz_rgb.top_down != 1)
|
||||
this.log_warn("FIXME: Implement non top down support for lz_rgb");
|
||||
|
||||
var source_img = convert_spice_lz_rgb_to_web(canvas.context,
|
||||
draw_copy.data.src_bitmap.lz_rgb);
|
||||
if (! source_img)
|
||||
{
|
||||
this.log_warn("FIXME: Unable to interpret bitmap of type: " +
|
||||
draw_copy.data.src_bitmap.lz_rgb.type);
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.draw_copy_helper(
|
||||
{ base: draw_copy.base,
|
||||
src_area: draw_copy.data.src_area,
|
||||
image_data: source_img,
|
||||
tag: "lz_rgb." + draw_copy.data.src_bitmap.lz_rgb.type,
|
||||
has_alpha: draw_copy.data.src_bitmap.lz_rgb.type == LZ_IMAGE_TYPE_RGBA ? true : false ,
|
||||
descriptor : draw_copy.data.src_bitmap.descriptor
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
this.log_warn("FIXME: DrawCopy unhandled image type: " + draw_copy.data.src_bitmap.descriptor.type);
|
||||
this.log_draw("DrawCopy", draw_copy);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
this.log_warn("FIXME: DrawCopy no src_bitmap.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (msg.type == SPICE_MSG_DISPLAY_DRAW_FILL)
|
||||
{
|
||||
var draw_fill = new SpiceMsgDisplayDrawFill(msg.data);
|
||||
|
||||
DEBUG > 1 && this.log_draw("DrawFill", draw_fill);
|
||||
|
||||
if (draw_fill.data.rop_descriptor != SPICE_ROPD_OP_PUT)
|
||||
this.log_warn("FIXME: DrawFill we don't handle ropd type: " + draw_fill.data.rop_descriptor);
|
||||
if (draw_fill.data.mask.flags)
|
||||
this.log_warn("FIXME: DrawFill we don't handle mask flag: " + draw_fill.data.mask.flags);
|
||||
if (draw_fill.data.mask.bitmap)
|
||||
this.log_warn("FIXME: DrawFill we don't handle mask");
|
||||
|
||||
if (draw_fill.data.brush.type == SPICE_BRUSH_TYPE_SOLID)
|
||||
{
|
||||
// FIXME - do brushes ever have alpha?
|
||||
var color = draw_fill.data.brush.color & 0xffffff;
|
||||
var color_str = "rgb(" + (color >> 16) + ", " + ((color >> 8) & 0xff) + ", " + (color & 0xff) + ")";
|
||||
this.surfaces[draw_fill.base.surface_id].canvas.context.fillStyle = color_str;
|
||||
|
||||
this.surfaces[draw_fill.base.surface_id].canvas.context.fillRect(
|
||||
draw_fill.base.box.left, draw_fill.base.box.top,
|
||||
draw_fill.base.box.right - draw_fill.base.box.left,
|
||||
draw_fill.base.box.bottom - draw_fill.base.box.top);
|
||||
|
||||
if (DUMP_DRAWS && this.parent.dump_id)
|
||||
{
|
||||
var debug_canvas = document.createElement("canvas");
|
||||
debug_canvas.setAttribute('width', this.surfaces[draw_fill.base.surface_id].canvas.width);
|
||||
debug_canvas.setAttribute('height', this.surfaces[draw_fill.base.surface_id].canvas.height);
|
||||
debug_canvas.setAttribute('id', "fillbrush." + draw_fill.base.surface_id + "." + this.surfaces[draw_fill.base.surface_id].draw_count);
|
||||
debug_canvas.getContext("2d").fillStyle = color_str;
|
||||
debug_canvas.getContext("2d").fillRect(
|
||||
draw_fill.base.box.left, draw_fill.base.box.top,
|
||||
draw_fill.base.box.right - draw_fill.base.box.left,
|
||||
draw_fill.base.box.bottom - draw_fill.base.box.top);
|
||||
document.getElementById(this.parent.dump_id).appendChild(debug_canvas);
|
||||
}
|
||||
|
||||
this.surfaces[draw_fill.base.surface_id].draw_count++;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
this.log_warn("FIXME: DrawFill can't handle brush type: " + draw_fill.data.brush.type);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (msg.type == SPICE_MSG_DISPLAY_COPY_BITS)
|
||||
{
|
||||
var copy_bits = new SpiceMsgDisplayCopyBits(msg.data);
|
||||
|
||||
DEBUG > 1 && this.log_draw("CopyBits", copy_bits);
|
||||
|
||||
var source_canvas = this.surfaces[copy_bits.base.surface_id].canvas;
|
||||
var source_context = source_canvas.context;
|
||||
|
||||
var width = source_canvas.width - copy_bits.src_pos.x;
|
||||
var height = source_canvas.height - copy_bits.src_pos.y;
|
||||
if (width > (copy_bits.base.box.right - copy_bits.base.box.left))
|
||||
width = copy_bits.base.box.right - copy_bits.base.box.left;
|
||||
if (height > (copy_bits.base.box.bottom - copy_bits.base.box.top))
|
||||
height = copy_bits.base.box.bottom - copy_bits.base.box.top;
|
||||
|
||||
var source_img = source_context.getImageData(
|
||||
copy_bits.src_pos.x, copy_bits.src_pos.y, width, height);
|
||||
//source_context.putImageData(source_img, copy_bits.base.box.left, copy_bits.base.box.top);
|
||||
putImageDataWithAlpha(source_context, source_img, copy_bits.base.box.left, copy_bits.base.box.top);
|
||||
|
||||
if (DUMP_DRAWS && this.parent.dump_id)
|
||||
{
|
||||
var debug_canvas = document.createElement("canvas");
|
||||
debug_canvas.setAttribute('width', width);
|
||||
debug_canvas.setAttribute('height', height);
|
||||
debug_canvas.setAttribute('id', "copybits" + copy_bits.base.surface_id + "." + this.surfaces[copy_bits.base.surface_id].draw_count);
|
||||
debug_canvas.getContext("2d").putImageData(source_img, 0, 0);
|
||||
document.getElementById(this.parent.dump_id).appendChild(debug_canvas);
|
||||
}
|
||||
|
||||
|
||||
this.surfaces[copy_bits.base.surface_id].draw_count++;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (msg.type == SPICE_MSG_DISPLAY_INVAL_ALL_PALETTES)
|
||||
{
|
||||
this.known_unimplemented(msg.type, "Inval All Palettes");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (msg.type == SPICE_MSG_DISPLAY_SURFACE_CREATE)
|
||||
{
|
||||
if (! ("surfaces" in this))
|
||||
this.surfaces = [];
|
||||
|
||||
var m = new SpiceMsgSurfaceCreate(msg.data);
|
||||
DEBUG > 1 && console.log(this.type + ": MsgSurfaceCreate id " + m.surface.surface_id
|
||||
+ "; " + m.surface.width + "x" + m.surface.height
|
||||
+ "; format " + m.surface.format
|
||||
+ "; flags " + m.surface.flags);
|
||||
if (m.surface.format != SPICE_SURFACE_FMT_32_xRGB &&
|
||||
m.surface.format != SPICE_SURFACE_FMT_32_ARGB)
|
||||
{
|
||||
this.log_warn("FIXME: cannot handle surface format " + m.surface.format + " yet.");
|
||||
return false;
|
||||
}
|
||||
|
||||
var canvas = document.createElement("canvas");
|
||||
canvas.setAttribute('width', m.surface.width);
|
||||
canvas.setAttribute('height', m.surface.height);
|
||||
canvas.setAttribute('id', "spice_surface_" + m.surface.surface_id);
|
||||
canvas.setAttribute('tabindex', m.surface.surface_id);
|
||||
canvas.context = canvas.getContext("2d");
|
||||
|
||||
if (DUMP_CANVASES && this.parent.dump_id)
|
||||
document.getElementById(this.parent.dump_id).appendChild(canvas);
|
||||
|
||||
m.surface.canvas = canvas;
|
||||
m.surface.draw_count = 0;
|
||||
this.surfaces[m.surface.surface_id] = m.surface;
|
||||
|
||||
if (m.surface.flags & SPICE_SURFACE_FLAGS_PRIMARY)
|
||||
{
|
||||
this.primary_surface = m.surface.surface_id;
|
||||
|
||||
/* This .save() is done entirely to enable SPICE_MSG_DISPLAY_RESET */
|
||||
canvas.context.save();
|
||||
global_ctx = canvas.context; // FIXME - this is a hack entirely for the emscripten quic.js
|
||||
document.getElementById(this.parent.screen_id).appendChild(canvas);
|
||||
document.getElementById(this.parent.screen_id).setAttribute('width', m.surface.width);
|
||||
document.getElementById(this.parent.screen_id).setAttribute('height', m.surface.height);
|
||||
this.hook_events();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (msg.type == SPICE_MSG_DISPLAY_SURFACE_DESTROY)
|
||||
{
|
||||
var m = new SpiceMsgSurfaceDestroy(msg.data);
|
||||
DEBUG > 1 && console.log(this.type + ": MsgSurfaceDestroy id " + m.surface_id);
|
||||
this.delete_surface(m.surface_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
SpiceDisplayConn.prototype.delete_surface = function(surface_id)
|
||||
{
|
||||
var canvas = document.getElementById("spice_surface_" + surface_id);
|
||||
if (DUMP_CANVASES && this.parent.dump_id)
|
||||
document.getElementById(this.parent.dump_id).removeChild(canvas);
|
||||
if (this.primary_surface == surface_id)
|
||||
{
|
||||
this.unhook_events();
|
||||
this.primary_surface = undefined;
|
||||
document.getElementById(this.parent.screen_id).removeChild(canvas);
|
||||
}
|
||||
|
||||
delete this.surfaces[surface_id];
|
||||
}
|
||||
|
||||
|
||||
SpiceDisplayConn.prototype.draw_copy_helper = function(o)
|
||||
{
|
||||
|
||||
var canvas = this.surfaces[o.base.surface_id].canvas;
|
||||
if (o.has_alpha)
|
||||
{
|
||||
/* FIXME - This is based on trial + error, not a serious thoughtful
|
||||
analysis of what Spice requires. See display.js for more. */
|
||||
if (this.surfaces[o.base.surface_id].format == SPICE_SURFACE_FMT_32_xRGB)
|
||||
{
|
||||
stripAlpha(o.image_data);
|
||||
canvas.context.putImageData(o.image_data, o.base.box.left, o.base.box.top);
|
||||
}
|
||||
else
|
||||
putImageDataWithAlpha(canvas.context, o.image_data,
|
||||
o.base.box.left, o.base.box.top);
|
||||
}
|
||||
else
|
||||
canvas.context.putImageData(o.image_data, o.base.box.left, o.base.box.top);
|
||||
|
||||
if (o.src_area.left > 0 || o.src_area.top > 0)
|
||||
{
|
||||
this.log_warn("FIXME: DrawCopy not shifting draw copies just yet...");
|
||||
}
|
||||
|
||||
if (o.descriptor && (o.descriptor.flags & SPICE_IMAGE_FLAGS_CACHE_ME))
|
||||
{
|
||||
if (! ("cache" in this))
|
||||
this.cache = [];
|
||||
this.cache[o.descriptor.id] = o.image_data;
|
||||
}
|
||||
|
||||
if (DUMP_DRAWS && this.parent.dump_id)
|
||||
{
|
||||
var debug_canvas = document.createElement("canvas");
|
||||
debug_canvas.setAttribute('width', o.image_data.width);
|
||||
debug_canvas.setAttribute('height', o.image_data.height);
|
||||
debug_canvas.setAttribute('id', o.tag + "." +
|
||||
this.surfaces[o.base.surface_id].draw_count + "." +
|
||||
o.base.surface_id + "@" + o.base.box.left + "x" + o.base.box.top);
|
||||
debug_canvas.getContext("2d").putImageData(o.image_data, 0, 0);
|
||||
document.getElementById(this.parent.dump_id).appendChild(debug_canvas);
|
||||
}
|
||||
|
||||
this.surfaces[o.base.surface_id].draw_count++;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
SpiceDisplayConn.prototype.log_draw = function(prefix, draw)
|
||||
{
|
||||
var str = prefix + "." + draw.base.surface_id + "." + this.surfaces[draw.base.surface_id].draw_count + ": ";
|
||||
str += "base.box " + draw.base.box.left + ", " + draw.base.box.top + " to " +
|
||||
draw.base.box.right + ", " + draw.base.box.bottom;
|
||||
str += "; clip.type " + draw.base.clip.type;
|
||||
|
||||
if (draw.data)
|
||||
{
|
||||
if (draw.data.src_area)
|
||||
str += "; src_area " + draw.data.src_area.left + ", " + draw.data.src_area.top + " to "
|
||||
+ draw.data.src_area.right + ", " + draw.data.src_area.bottom;
|
||||
|
||||
if (draw.data.src_bitmap && draw.data.src_bitmap != null)
|
||||
{
|
||||
str += "; src_bitmap id: " + draw.data.src_bitmap.descriptor.id;
|
||||
str += "; src_bitmap width " + draw.data.src_bitmap.descriptor.width + ", height " + draw.data.src_bitmap.descriptor.height;
|
||||
str += "; src_bitmap type " + draw.data.src_bitmap.descriptor.type + ", flags " + draw.data.src_bitmap.descriptor.flags;
|
||||
if (draw.data.src_bitmap.surface_id !== undefined)
|
||||
str += "; src_bitmap surface_id " + draw.data.src_bitmap.surface_id;
|
||||
if (draw.data.src_bitmap.quic)
|
||||
str += "; QUIC type " + draw.data.src_bitmap.quic.type +
|
||||
"; width " + draw.data.src_bitmap.quic.width +
|
||||
"; height " + draw.data.src_bitmap.quic.height ;
|
||||
if (draw.data.src_bitmap.lz_rgb)
|
||||
str += "; LZ_RGB length " + draw.data.src_bitmap.lz_rgb.length +
|
||||
"; magic " + draw.data.src_bitmap.lz_rgb.magic +
|
||||
"; version 0x" + draw.data.src_bitmap.lz_rgb.version.toString(16) +
|
||||
"; type " + draw.data.src_bitmap.lz_rgb.type +
|
||||
"; width " + draw.data.src_bitmap.lz_rgb.width +
|
||||
"; height " + draw.data.src_bitmap.lz_rgb.height +
|
||||
"; stride " + draw.data.src_bitmap.lz_rgb.stride +
|
||||
"; top down " + draw.data.src_bitmap.lz_rgb.top_down;
|
||||
}
|
||||
else
|
||||
str += "; src_bitmap is null";
|
||||
|
||||
if (draw.data.brush)
|
||||
{
|
||||
if (draw.data.brush.type == SPICE_BRUSH_TYPE_SOLID)
|
||||
str += "; brush.color 0x" + draw.data.brush.color.toString(16);
|
||||
if (draw.data.brush.type == SPICE_BRUSH_TYPE_PATTERN)
|
||||
{
|
||||
str += "; brush.pat ";
|
||||
if (draw.data.brush.pattern.pat != null)
|
||||
str += "[SpiceImage]";
|
||||
else
|
||||
str += "[null]";
|
||||
str += " at " + draw.data.brush.pattern.pos.x + ", " + draw.data.brush.pattern.pos.y;
|
||||
}
|
||||
}
|
||||
|
||||
str += "; rop_descriptor " + draw.data.rop_descriptor;
|
||||
if (draw.data.scale_mode !== undefined)
|
||||
str += "; scale_mode " + draw.data.scale_mode;
|
||||
str += "; mask.flags " + draw.data.mask.flags;
|
||||
str += "; mask.pos " + draw.data.mask.pos.x + ", " + draw.data.mask.pos.y;
|
||||
if (draw.data.mask.bitmap != null)
|
||||
{
|
||||
str += "; mask.bitmap width " + draw.data.mask.bitmap.descriptor.width + ", height " + draw.data.mask.bitmap.descriptor.height;
|
||||
str += "; mask.bitmap type " + draw.data.mask.bitmap.descriptor.type + ", flags " + draw.data.mask.bitmap.descriptor.flags;
|
||||
}
|
||||
else
|
||||
str += "; mask.bitmap is null";
|
||||
}
|
||||
|
||||
console.log(str);
|
||||
}
|
||||
|
||||
SpiceDisplayConn.prototype.hook_events = function()
|
||||
{
|
||||
if (this.primary_surface !== undefined)
|
||||
{
|
||||
var canvas = this.surfaces[this.primary_surface].canvas;
|
||||
canvas.sc = this.parent;
|
||||
canvas.addEventListener('mousemove', handle_mousemove);
|
||||
canvas.addEventListener('mousedown', handle_mousedown);
|
||||
canvas.addEventListener('contextmenu', handle_contextmenu);
|
||||
canvas.addEventListener('mouseup', handle_mouseup);
|
||||
canvas.addEventListener('keydown', handle_keydown);
|
||||
canvas.addEventListener('keyup', handle_keyup);
|
||||
canvas.addEventListener('mouseout', handle_mouseout);
|
||||
canvas.addEventListener('mouseover', handle_mouseover);
|
||||
canvas.addEventListener('mousewheel', handle_mousewheel);
|
||||
canvas.focus();
|
||||
}
|
||||
}
|
||||
|
||||
SpiceDisplayConn.prototype.unhook_events = function()
|
||||
{
|
||||
if (this.primary_surface !== undefined)
|
||||
{
|
||||
var canvas = this.surfaces[this.primary_surface].canvas;
|
||||
canvas.removeEventListener('mousemove', handle_mousemove);
|
||||
canvas.removeEventListener('mousedown', handle_mousedown);
|
||||
canvas.removeEventListener('contextmenu', handle_contextmenu);
|
||||
canvas.removeEventListener('mouseup', handle_mouseup);
|
||||
canvas.removeEventListener('keydown', handle_keydown);
|
||||
canvas.removeEventListener('keyup', handle_keyup);
|
||||
canvas.removeEventListener('mouseout', handle_mouseout);
|
||||
canvas.removeEventListener('mouseover', handle_mouseover);
|
||||
canvas.removeEventListener('mousewheel', handle_mousewheel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SpiceDisplayConn.prototype.destroy_surfaces = function()
|
||||
{
|
||||
for (var s in this.surfaces)
|
||||
{
|
||||
this.delete_surface(this.surfaces[s].surface_id);
|
||||
}
|
||||
|
||||
this.surfaces = undefined;
|
||||
}
|
||||
|
||||
|
||||
function handle_mouseover(e)
|
||||
{
|
||||
this.focus();
|
||||
}
|
||||
|
||||
function handle_mouseout(e)
|
||||
{
|
||||
this.blur();
|
||||
}
|
||||
|
||||
function handle_draw_jpeg_onload()
|
||||
{
|
||||
var temp_canvas = null;
|
||||
var context;
|
||||
|
||||
/*------------------------------------------------------------
|
||||
** FIXME:
|
||||
** The helper should be extended to be able to handle actual HtmlImageElements
|
||||
** ...and the cache should be modified to do so as well
|
||||
**----------------------------------------------------------*/
|
||||
if (this.o.sc.surfaces[this.o.base.surface_id] === undefined)
|
||||
{
|
||||
// This can happen; if the jpeg image loads after our surface
|
||||
// has been destroyed (e.g. open a menu, close it quickly),
|
||||
// we'll find we have no surface.
|
||||
DEBUG > 2 && this.o.sc.log_info("Discarding jpeg; presumed lost surface " + this.o.base.surface_id);
|
||||
temp_canvas = document.createElement("canvas");
|
||||
temp_canvas.setAttribute('width', this.o.base.box.right);
|
||||
temp_canvas.setAttribute('height', this.o.base.box.bottom);
|
||||
context = temp_canvas.getContext("2d");
|
||||
}
|
||||
else
|
||||
context = this.o.sc.surfaces[this.o.base.surface_id].canvas.context;
|
||||
|
||||
context.drawImage(this, this.o.base.box.left, this.o.base.box.top);
|
||||
|
||||
if (this.o.descriptor &&
|
||||
(this.o.descriptor.flags & SPICE_IMAGE_FLAGS_CACHE_ME))
|
||||
{
|
||||
if (! ("cache" in this.o.sc))
|
||||
this.o.sc.cache = [];
|
||||
|
||||
this.o.sc.cache[this.o.descriptor.id] =
|
||||
context.getImageData(this.o.base.box.left, this.o.base.box.top,
|
||||
this.o.base.box.right - this.o.base.box.left,
|
||||
this.o.base.box.bottom - this.o.base.box.top);
|
||||
}
|
||||
|
||||
if (temp_canvas == null)
|
||||
{
|
||||
if (DUMP_DRAWS && this.o.sc.parent.dump_id)
|
||||
{
|
||||
var debug_canvas = document.createElement("canvas");
|
||||
debug_canvas.setAttribute('id', this.o.tag + "." +
|
||||
this.o.sc.surfaces[this.o.base.surface_id].draw_count + "." +
|
||||
this.o.base.surface_id + "@" + this.o.base.box.left + "x" + this.o.base.box.top);
|
||||
debug_canvas.getContext("2d").drawImage(this, 0, 0);
|
||||
document.getElementById(this.o.sc.parent.dump_id).appendChild(debug_canvas);
|
||||
}
|
||||
|
||||
this.o.sc.surfaces[this.o.base.surface_id].draw_count++;
|
||||
}
|
||||
}
|
280
enums.js
Normal file
280
enums.js
Normal file
@ -0,0 +1,280 @@
|
||||
"use strict";
|
||||
/*
|
||||
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||
|
||||
This file is part of spice-html5.
|
||||
|
||||
spice-html5 is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
spice-html5 is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
** enums.js
|
||||
** 'constants' for Spice
|
||||
**--------------------------------------------------------------------------*/
|
||||
var SPICE_MAGIC = "REDQ";
|
||||
var SPICE_VERSION_MAJOR = 2;
|
||||
var SPICE_VERSION_MINOR = 2;
|
||||
|
||||
var SPICE_CONNECT_TIMEOUT = (30 * 1000);
|
||||
|
||||
var SPICE_COMMON_CAP_PROTOCOL_AUTH_SELECTION = 0;
|
||||
var SPICE_COMMON_CAP_AUTH_SPICE = 1;
|
||||
var SPICE_COMMON_CAP_AUTH_SASL = 2;
|
||||
var SPICE_COMMON_CAP_MINI_HEADER = 3;
|
||||
|
||||
var SPICE_TICKET_KEY_PAIR_LENGTH = 1024;
|
||||
var SPICE_TICKET_PUBKEY_BYTES = (SPICE_TICKET_KEY_PAIR_LENGTH / 8 + 34);
|
||||
|
||||
var SPICE_LINK_ERR_OK = 0,
|
||||
SPICE_LINK_ERR_ERROR = 1,
|
||||
SPICE_LINK_ERR_INVALID_MAGIC = 2,
|
||||
SPICE_LINK_ERR_INVALID_DATA = 3,
|
||||
SPICE_LINK_ERR_VERSION_MISMATCH = 4,
|
||||
SPICE_LINK_ERR_NEED_SECURED = 5,
|
||||
SPICE_LINK_ERR_NEED_UNSECURED = 6,
|
||||
SPICE_LINK_ERR_PERMISSION_DENIED = 7,
|
||||
SPICE_LINK_ERR_BAD_CONNECTION_ID = 8,
|
||||
SPICE_LINK_ERR_CHANNEL_NOT_AVAILABLE = 9;
|
||||
|
||||
var SPICE_MSG_MIGRATE = 1;
|
||||
var SPICE_MSG_MIGRATE_DATA = 2;
|
||||
var SPICE_MSG_SET_ACK = 3;
|
||||
var SPICE_MSG_PING = 4;
|
||||
var SPICE_MSG_WAIT_FOR_CHANNELS = 5;
|
||||
var SPICE_MSG_DISCONNECTING = 6;
|
||||
var SPICE_MSG_NOTIFY = 7;
|
||||
var SPICE_MSG_LIST = 8;
|
||||
|
||||
var SPICE_MSG_MAIN_MIGRATE_BEGIN = 101;
|
||||
var SPICE_MSG_MAIN_MIGRATE_CANCEL = 102;
|
||||
var SPICE_MSG_MAIN_INIT = 103;
|
||||
var SPICE_MSG_MAIN_CHANNELS_LIST = 104;
|
||||
var SPICE_MSG_MAIN_MOUSE_MODE = 105;
|
||||
var SPICE_MSG_MAIN_MULTI_MEDIA_TIME = 106;
|
||||
var SPICE_MSG_MAIN_AGENT_CONNECTED = 107;
|
||||
var SPICE_MSG_MAIN_AGENT_DISCONNECTED = 108;
|
||||
var SPICE_MSG_MAIN_AGENT_DATA = 109;
|
||||
var SPICE_MSG_MAIN_AGENT_TOKEN = 110;
|
||||
var SPICE_MSG_MAIN_MIGRATE_SWITCH_HOST = 111;
|
||||
var SPICE_MSG_MAIN_MIGRATE_END = 112;
|
||||
var SPICE_MSG_MAIN_NAME = 113;
|
||||
var SPICE_MSG_MAIN_UUID = 114;
|
||||
var SPICE_MSG_END_MAIN = 115;
|
||||
|
||||
|
||||
var SPICE_MSGC_ACK_SYNC = 1;
|
||||
var SPICE_MSGC_ACK = 2;
|
||||
var SPICE_MSGC_PONG = 3;
|
||||
var SPICE_MSGC_MIGRATE_FLUSH_MARK = 4;
|
||||
var SPICE_MSGC_MIGRATE_DATA = 5;
|
||||
var SPICE_MSGC_DISCONNECTING = 6;
|
||||
|
||||
|
||||
var SPICE_MSGC_MAIN_CLIENT_INFO = 101;
|
||||
var SPICE_MSGC_MAIN_MIGRATE_CONNECTED = 102;
|
||||
var SPICE_MSGC_MAIN_MIGRATE_CONNECT_ERROR = 103;
|
||||
var SPICE_MSGC_MAIN_ATTACH_CHANNELS = 104;
|
||||
var SPICE_MSGC_MAIN_MOUSE_MODE_REQUEST = 105;
|
||||
var SPICE_MSGC_MAIN_AGENT_START = 106;
|
||||
var SPICE_MSGC_MAIN_AGENT_DATA = 107;
|
||||
var SPICE_MSGC_MAIN_AGENT_TOKEN = 108;
|
||||
var SPICE_MSGC_MAIN_MIGRATE_END = 109;
|
||||
var SPICE_MSGC_END_MAIN = 110;
|
||||
|
||||
var SPICE_MSG_DISPLAY_MODE = 101;
|
||||
var SPICE_MSG_DISPLAY_MARK = 102;
|
||||
var SPICE_MSG_DISPLAY_RESET = 103;
|
||||
var SPICE_MSG_DISPLAY_COPY_BITS = 104;
|
||||
var SPICE_MSG_DISPLAY_INVAL_LIST = 105;
|
||||
var SPICE_MSG_DISPLAY_INVAL_ALL_PIXMAPS = 106;
|
||||
var SPICE_MSG_DISPLAY_INVAL_PALETTE = 107;
|
||||
var SPICE_MSG_DISPLAY_INVAL_ALL_PALETTES= 108;
|
||||
|
||||
var SPICE_MSG_DISPLAY_STREAM_CREATE = 122;
|
||||
var SPICE_MSG_DISPLAY_STREAM_DATA = 123;
|
||||
var SPICE_MSG_DISPLAY_STREAM_CLIP = 124;
|
||||
var SPICE_MSG_DISPLAY_STREAM_DESTROY = 125;
|
||||
var SPICE_MSG_DISPLAY_STREAM_DESTROY_ALL= 126;
|
||||
|
||||
var SPICE_MSG_DISPLAY_DRAW_FILL = 302;
|
||||
var SPICE_MSG_DISPLAY_DRAW_OPAQUE = 303;
|
||||
var SPICE_MSG_DISPLAY_DRAW_COPY = 304;
|
||||
var SPICE_MSG_DISPLAY_DRAW_BLEND = 305;
|
||||
var SPICE_MSG_DISPLAY_DRAW_BLACKNESS = 306;
|
||||
var SPICE_MSG_DISPLAY_DRAW_WHITENESS = 307;
|
||||
var SPICE_MSG_DISPLAY_DRAW_INVERS = 308;
|
||||
var SPICE_MSG_DISPLAY_DRAW_ROP3 = 309;
|
||||
var SPICE_MSG_DISPLAY_DRAW_STROKE = 310;
|
||||
var SPICE_MSG_DISPLAY_DRAW_TEXT = 311;
|
||||
var SPICE_MSG_DISPLAY_DRAW_TRANSPARENT = 312;
|
||||
var SPICE_MSG_DISPLAY_DRAW_ALPHA_BLEND = 313;
|
||||
var SPICE_MSG_DISPLAY_SURFACE_CREATE = 314;
|
||||
var SPICE_MSG_DISPLAY_SURFACE_DESTROY = 315;
|
||||
|
||||
var SPICE_MSGC_DISPLAY_INIT = 101;
|
||||
|
||||
var SPICE_MSG_INPUTS_INIT = 101;
|
||||
var SPICE_MSG_INPUTS_KEY_MODIFIERS = 102;
|
||||
|
||||
var SPICE_MSG_INPUTS_MOUSE_MOTION_ACK = 111;
|
||||
|
||||
var SPICE_MSGC_INPUTS_KEY_DOWN = 101;
|
||||
var SPICE_MSGC_INPUTS_KEY_UP = 102;
|
||||
var SPICE_MSGC_INPUTS_KEY_MODIFIERS = 103;
|
||||
|
||||
var SPICE_MSGC_INPUTS_MOUSE_MOTION = 111;
|
||||
var SPICE_MSGC_INPUTS_MOUSE_POSITION = 112;
|
||||
var SPICE_MSGC_INPUTS_MOUSE_PRESS = 113;
|
||||
var SPICE_MSGC_INPUTS_MOUSE_RELEASE = 114;
|
||||
|
||||
var SPICE_MSG_CURSOR_INIT = 101;
|
||||
var SPICE_MSG_CURSOR_RESET = 102;
|
||||
var SPICE_MSG_CURSOR_SET = 103;
|
||||
var SPICE_MSG_CURSOR_MOVE = 104;
|
||||
var SPICE_MSG_CURSOR_HIDE = 105;
|
||||
var SPICE_MSG_CURSOR_TRAIL = 106;
|
||||
var SPICE_MSG_CURSOR_INVAL_ONE = 107;
|
||||
var SPICE_MSG_CURSOR_INVAL_ALL = 108;
|
||||
|
||||
|
||||
var SPICE_CHANNEL_MAIN = 1;
|
||||
var SPICE_CHANNEL_DISPLAY = 2;
|
||||
var SPICE_CHANNEL_INPUTS = 3;
|
||||
var SPICE_CHANNEL_CURSOR = 4;
|
||||
var SPICE_CHANNEL_PLAYBACK = 5;
|
||||
var SPICE_CHANNEL_RECORD = 6;
|
||||
var SPICE_CHANNEL_TUNNEL = 7;
|
||||
var SPICE_CHANNEL_SMARTCARD = 8;
|
||||
var SPICE_CHANNEL_USBREDIR = 9;
|
||||
|
||||
var SPICE_SURFACE_FLAGS_PRIMARY = (1 << 0);
|
||||
|
||||
var SPICE_NOTIFY_SEVERITY_INFO = 0;
|
||||
var SPICE_NOTIFY_SEVERITY_WARN = 1;
|
||||
var SPICE_NOTIFY_SEVERITY_ERROR = 2;
|
||||
|
||||
var SPICE_MOUSE_MODE_SERVER = (1 << 0),
|
||||
SPICE_MOUSE_MODE_CLIENT = (1 << 1),
|
||||
SPICE_MOUSE_MODE_MASK = 0x3;
|
||||
|
||||
var SPICE_CLIP_TYPE_NONE = 0;
|
||||
var SPICE_CLIP_TYPE_RECTS = 1;
|
||||
|
||||
var SPICE_IMAGE_TYPE_BITMAP = 0;
|
||||
var SPICE_IMAGE_TYPE_QUIC = 1;
|
||||
var SPICE_IMAGE_TYPE_RESERVED = 2;
|
||||
var SPICE_IMAGE_TYPE_LZ_PLT = 100;
|
||||
var SPICE_IMAGE_TYPE_LZ_RGB = 101;
|
||||
var SPICE_IMAGE_TYPE_GLZ_RGB = 102;
|
||||
var SPICE_IMAGE_TYPE_FROM_CACHE = 103;
|
||||
var SPICE_IMAGE_TYPE_SURFACE = 104;
|
||||
var SPICE_IMAGE_TYPE_JPEG = 105;
|
||||
var SPICE_IMAGE_TYPE_FROM_CACHE_LOSSLESS = 106;
|
||||
var SPICE_IMAGE_TYPE_ZLIB_GLZ_RGB = 107;
|
||||
var SPICE_IMAGE_TYPE_JPEG_ALPHA = 108;
|
||||
|
||||
var SPICE_IMAGE_FLAGS_CACHE_ME = (1 << 0),
|
||||
SPICE_IMAGE_FLAGS_HIGH_BITS_SET = (1 << 1),
|
||||
SPICE_IMAGE_FLAGS_CACHE_REPLACE_ME = (1 << 2);
|
||||
|
||||
var SPICE_BITMAP_FLAGS_PAL_CACHE_ME = (1 << 0),
|
||||
SPICE_BITMAP_FLAGS_PAL_FROM_CACHE = (1 << 1),
|
||||
SPICE_BITMAP_FLAGS_TOP_DOWN = (1 << 2),
|
||||
SPICE_BITMAP_FLAGS_MASK = 0x7;
|
||||
|
||||
var SPICE_BITMAP_FMT_INVALID = 0,
|
||||
SPICE_BITMAP_FMT_1BIT_LE = 1,
|
||||
SPICE_BITMAP_FMT_1BIT_BE = 2,
|
||||
SPICE_BITMAP_FMT_4BIT_LE = 3,
|
||||
SPICE_BITMAP_FMT_4BIT_BE = 4,
|
||||
SPICE_BITMAP_FMT_8BIT = 5,
|
||||
SPICE_BITMAP_FMT_16BIT = 6,
|
||||
SPICE_BITMAP_FMT_24BIT = 7,
|
||||
SPICE_BITMAP_FMT_32BIT = 8,
|
||||
SPICE_BITMAP_FMT_RGBA = 9;
|
||||
|
||||
|
||||
var SPICE_CURSOR_FLAGS_NONE = (1 << 0),
|
||||
SPICE_CURSOR_FLAGS_CACHE_ME = (1 << 1),
|
||||
SPICE_CURSOR_FLAGS_FROM_CACHE = (1 << 2),
|
||||
SPICE_CURSOR_FLAGS_MASK = 0x7;
|
||||
|
||||
var SPICE_MOUSE_BUTTON_MASK_LEFT = (1 << 0),
|
||||
SPICE_MOUSE_BUTTON_MASK_MIDDLE = (1 << 1),
|
||||
SPICE_MOUSE_BUTTON_MASK_RIGHT = (1 << 2),
|
||||
SPICE_MOUSE_BUTTON_MASK_MASK = 0x7;
|
||||
|
||||
var SPICE_MOUSE_BUTTON_INVALID = 0;
|
||||
var SPICE_MOUSE_BUTTON_LEFT = 1;
|
||||
var SPICE_MOUSE_BUTTON_MIDDLE = 2;
|
||||
var SPICE_MOUSE_BUTTON_RIGHT = 3;
|
||||
var SPICE_MOUSE_BUTTON_UP = 4;
|
||||
var SPICE_MOUSE_BUTTON_DOWN = 5;
|
||||
|
||||
var SPICE_BRUSH_TYPE_NONE = 0,
|
||||
SPICE_BRUSH_TYPE_SOLID = 1,
|
||||
SPICE_BRUSH_TYPE_PATTERN = 2;
|
||||
|
||||
var SPICE_SURFACE_FMT_INVALID = 0,
|
||||
SPICE_SURFACE_FMT_1_A = 1,
|
||||
SPICE_SURFACE_FMT_8_A = 8,
|
||||
SPICE_SURFACE_FMT_16_555 = 16,
|
||||
SPICE_SURFACE_FMT_32_xRGB = 32,
|
||||
SPICE_SURFACE_FMT_16_565 = 80,
|
||||
SPICE_SURFACE_FMT_32_ARGB = 96;
|
||||
|
||||
var SPICE_ROPD_INVERS_SRC = (1 << 0),
|
||||
SPICE_ROPD_INVERS_BRUSH = (1 << 1),
|
||||
SPICE_ROPD_INVERS_DEST = (1 << 2),
|
||||
SPICE_ROPD_OP_PUT = (1 << 3),
|
||||
SPICE_ROPD_OP_OR = (1 << 4),
|
||||
SPICE_ROPD_OP_AND = (1 << 5),
|
||||
SPICE_ROPD_OP_XOR = (1 << 6),
|
||||
SPICE_ROPD_OP_BLACKNESS = (1 << 7),
|
||||
SPICE_ROPD_OP_WHITENESS = (1 << 8),
|
||||
SPICE_ROPD_OP_INVERS = (1 << 9),
|
||||
SPICE_ROPD_INVERS_RES = (1 << 10),
|
||||
SPICE_ROPD_MASK = 0x7ff;
|
||||
|
||||
var LZ_IMAGE_TYPE_INVALID = 0,
|
||||
LZ_IMAGE_TYPE_PLT1_LE = 1,
|
||||
LZ_IMAGE_TYPE_PLT1_BE = 2, // PLT stands for palette
|
||||
LZ_IMAGE_TYPE_PLT4_LE = 3,
|
||||
LZ_IMAGE_TYPE_PLT4_BE = 4,
|
||||
LZ_IMAGE_TYPE_PLT8 = 5,
|
||||
LZ_IMAGE_TYPE_RGB16 = 6,
|
||||
LZ_IMAGE_TYPE_RGB24 = 7,
|
||||
LZ_IMAGE_TYPE_RGB32 = 8,
|
||||
LZ_IMAGE_TYPE_RGBA = 9,
|
||||
LZ_IMAGE_TYPE_XXXA = 10;
|
||||
|
||||
|
||||
var QUIC_IMAGE_TYPE_INVALID = 0,
|
||||
QUIC_IMAGE_TYPE_GRAY = 1,
|
||||
QUIC_IMAGE_TYPE_RGB16 = 2,
|
||||
QUIC_IMAGE_TYPE_RGB24 = 3,
|
||||
QUIC_IMAGE_TYPE_RGB32 = 4,
|
||||
QUIC_IMAGE_TYPE_RGBA = 5;
|
||||
|
||||
var SPICE_INPUT_MOTION_ACK_BUNCH = 4;
|
||||
|
||||
|
||||
var SPICE_CURSOR_TYPE_ALPHA = 0,
|
||||
SPICE_CURSOR_TYPE_MONO = 1,
|
||||
SPICE_CURSOR_TYPE_COLOR4 = 2,
|
||||
SPICE_CURSOR_TYPE_COLOR8 = 3,
|
||||
SPICE_CURSOR_TYPE_COLOR16 = 4,
|
||||
SPICE_CURSOR_TYPE_COLOR24 = 5,
|
||||
SPICE_CURSOR_TYPE_COLOR32 = 6;
|
165
inputs.js
Normal file
165
inputs.js
Normal file
@ -0,0 +1,165 @@
|
||||
"use strict";
|
||||
/*
|
||||
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||
|
||||
This file is part of spice-html5.
|
||||
|
||||
spice-html5 is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
spice-html5 is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
** SpiceInputsConn
|
||||
** Drive the Spice Inputs channel (e.g. mouse + keyboard)
|
||||
**--------------------------------------------------------------------------*/
|
||||
function SpiceInputsConn()
|
||||
{
|
||||
SpiceConn.apply(this, arguments);
|
||||
|
||||
this.mousex = undefined;
|
||||
this.mousey = undefined;
|
||||
this.button_state = 0;
|
||||
this.waiting_for_ack = 0;
|
||||
}
|
||||
|
||||
SpiceInputsConn.prototype = Object.create(SpiceConn.prototype);
|
||||
SpiceInputsConn.prototype.process_channel_message = function(msg)
|
||||
{
|
||||
if (msg.type == SPICE_MSG_INPUTS_INIT)
|
||||
{
|
||||
var inputs_init = new SpiceMsgInputsInit(msg.data);
|
||||
this.keyboard_modifiers = inputs_init.keyboard_modifiers;
|
||||
DEBUG > 1 && console.log("MsgInputsInit - modifier " + this.keyboard_modifiers);
|
||||
// FIXME - We don't do anything with the keyboard modifiers...
|
||||
return true;
|
||||
}
|
||||
if (msg.type == SPICE_MSG_INPUTS_KEY_MODIFIERS)
|
||||
{
|
||||
var key = new SpiceMsgInputsKeyModifiers(msg.data);
|
||||
this.keyboard_modifiers = key.keyboard_modifiers;
|
||||
DEBUG > 1 && console.log("MsgInputsKeyModifiers - modifier " + this.keyboard_modifiers);
|
||||
// FIXME - We don't do anything with the keyboard modifiers...
|
||||
return true;
|
||||
}
|
||||
if (msg.type == SPICE_MSG_INPUTS_MOUSE_MOTION_ACK)
|
||||
{
|
||||
DEBUG > 1 && console.log("mouse motion ack");
|
||||
this.waiting_for_ack -= SPICE_INPUT_MOTION_ACK_BUNCH;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function handle_mousemove(e)
|
||||
{
|
||||
var msg = new SpiceMiniData();
|
||||
var move;
|
||||
if (this.sc.mouse_mode == SPICE_MOUSE_MODE_CLIENT)
|
||||
{
|
||||
move = new SpiceMsgcMousePosition(this.sc, e)
|
||||
msg.build_msg(SPICE_MSGC_INPUTS_MOUSE_POSITION, move);
|
||||
}
|
||||
else
|
||||
{
|
||||
move = new SpiceMsgcMouseMotion(this.sc, e)
|
||||
msg.build_msg(SPICE_MSGC_INPUTS_MOUSE_MOTION, move);
|
||||
}
|
||||
if (this.sc && this.sc.inputs)
|
||||
{
|
||||
if (this.sc.inputs.waiting_for_ack < (2 * SPICE_INPUT_MOTION_ACK_BUNCH))
|
||||
{
|
||||
this.sc.inputs.send_msg(msg);
|
||||
this.sc.inputs.waiting_for_ack++;
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG > 0 && this.sc.log_info("Discarding mouse motion");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handle_mousedown(e)
|
||||
{
|
||||
var press = new SpiceMsgcMousePress(this.sc, e)
|
||||
var msg = new SpiceMiniData();
|
||||
msg.build_msg(SPICE_MSGC_INPUTS_MOUSE_PRESS, press);
|
||||
if (this.sc && this.sc.inputs)
|
||||
this.sc.inputs.send_msg(msg);
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
function handle_contextmenu(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
return false;
|
||||
}
|
||||
|
||||
function handle_mouseup(e)
|
||||
{
|
||||
var release = new SpiceMsgcMouseRelease(this.sc, e)
|
||||
var msg = new SpiceMiniData();
|
||||
msg.build_msg(SPICE_MSGC_INPUTS_MOUSE_RELEASE, release);
|
||||
if (this.sc && this.sc.inputs)
|
||||
this.sc.inputs.send_msg(msg);
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
function handle_mousewheel(e)
|
||||
{
|
||||
var press = new SpiceMsgcMousePress;
|
||||
var release = new SpiceMsgcMouseRelease;
|
||||
if (e.wheelDelta > 0)
|
||||
press.button = release.button = SPICE_MOUSE_BUTTON_UP;
|
||||
else
|
||||
press.button = release.button = SPICE_MOUSE_BUTTON_DOWN;
|
||||
press.buttons_state = 0;
|
||||
release.buttons_state = 0;
|
||||
|
||||
var msg = new SpiceMiniData();
|
||||
msg.build_msg(SPICE_MSGC_INPUTS_MOUSE_PRESS, press);
|
||||
if (this.sc && this.sc.inputs)
|
||||
this.sc.inputs.send_msg(msg);
|
||||
|
||||
msg.build_msg(SPICE_MSGC_INPUTS_MOUSE_RELEASE, release);
|
||||
if (this.sc && this.sc.inputs)
|
||||
this.sc.inputs.send_msg(msg);
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
function handle_keydown(e)
|
||||
{
|
||||
var key = new SpiceMsgcKeyDown(e)
|
||||
var msg = new SpiceMiniData();
|
||||
msg.build_msg(SPICE_MSGC_INPUTS_KEY_DOWN, key);
|
||||
if (this.sc && this.sc.inputs)
|
||||
this.sc.inputs.send_msg(msg);
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
function handle_keyup(e)
|
||||
{
|
||||
var key = new SpiceMsgcKeyUp(e)
|
||||
var msg = new SpiceMiniData();
|
||||
msg.build_msg(SPICE_MSGC_INPUTS_KEY_UP, key);
|
||||
if (this.sc && this.sc.inputs)
|
||||
this.sc.inputs.send_msg(msg);
|
||||
|
||||
e.preventDefault();
|
||||
}
|
158
lz.js
Normal file
158
lz.js
Normal file
@ -0,0 +1,158 @@
|
||||
"use strict";
|
||||
/*
|
||||
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||
|
||||
This file is part of spice-html5.
|
||||
|
||||
spice-html5 is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
spice-html5 is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
** lz.js
|
||||
** Functions for handling SPICE_IMAGE_TYPE_LZ_RGB
|
||||
** Adapted from lz.c .
|
||||
**--------------------------------------------------------------------------*/
|
||||
function lz_rgb32_decompress(in_buf, at, out_buf, type, default_alpha)
|
||||
{
|
||||
var encoder = at;
|
||||
var op = 0;
|
||||
var ctrl;
|
||||
var ctr = 0;
|
||||
|
||||
for (ctrl = in_buf[encoder++]; (op * 4) < out_buf.length; ctrl = in_buf[encoder++])
|
||||
{
|
||||
var ref = op;
|
||||
var len = ctrl >> 5;
|
||||
var ofs = (ctrl & 31) << 8;
|
||||
|
||||
//if (type == LZ_IMAGE_TYPE_RGBA)
|
||||
//console.log(ctr++ + ": from " + (encoder + 28) + ", ctrl " + ctrl + ", len " + len + ", ofs " + ofs + ", op " + op);
|
||||
if (ctrl >= 32) {
|
||||
|
||||
var code;
|
||||
len--;
|
||||
|
||||
if (len == 7 - 1) {
|
||||
do {
|
||||
code = in_buf[encoder++];
|
||||
len += code;
|
||||
} while (code == 255);
|
||||
}
|
||||
code = in_buf[encoder++];
|
||||
ofs += code;
|
||||
|
||||
|
||||
if (code == 255) {
|
||||
if ((ofs - code) == (31 << 8)) {
|
||||
ofs = in_buf[encoder++] << 8;
|
||||
ofs += in_buf[encoder++];
|
||||
ofs += 8191;
|
||||
}
|
||||
}
|
||||
len += 1;
|
||||
if (type == LZ_IMAGE_TYPE_RGBA)
|
||||
len += 2;
|
||||
|
||||
ofs += 1;
|
||||
|
||||
ref -= ofs;
|
||||
if (ref == (op - 1)) {
|
||||
var b = ref;
|
||||
//if (type == LZ_IMAGE_TYPE_RGBA) console.log("alpha " + out_buf[(b*4)+3] + " dupped into pixel " + op + " through pixel " + (op + len));
|
||||
for (; len; --len) {
|
||||
if (type == LZ_IMAGE_TYPE_RGBA)
|
||||
{
|
||||
out_buf[(op*4) + 3] = out_buf[(b*4)+3];
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < 4; i++)
|
||||
out_buf[(op*4) + i] = out_buf[(b*4)+i];
|
||||
}
|
||||
op++;
|
||||
}
|
||||
} else {
|
||||
//if (type == LZ_IMAGE_TYPE_RGBA) console.log("alpha copied to pixel " + op + " through " + (op + len) + " from " + ref);
|
||||
for (; len; --len) {
|
||||
if (type == LZ_IMAGE_TYPE_RGBA)
|
||||
{
|
||||
out_buf[(op*4) + 3] = out_buf[(ref*4)+3];
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < 4; i++)
|
||||
out_buf[(op*4) + i] = out_buf[(ref*4)+i];
|
||||
}
|
||||
op++; ref++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ctrl++;
|
||||
|
||||
if (type == LZ_IMAGE_TYPE_RGBA)
|
||||
{
|
||||
//console.log("alpha " + in_buf[encoder] + " set into pixel " + op);
|
||||
out_buf[(op*4) + 3] = in_buf[encoder++];
|
||||
}
|
||||
else
|
||||
{
|
||||
out_buf[(op*4) + 0] = in_buf[encoder + 2];
|
||||
out_buf[(op*4) + 1] = in_buf[encoder + 1];
|
||||
out_buf[(op*4) + 2] = in_buf[encoder + 0];
|
||||
if (default_alpha)
|
||||
out_buf[(op*4) + 3] = 255;
|
||||
encoder += 3;
|
||||
}
|
||||
op++;
|
||||
|
||||
|
||||
for (--ctrl; ctrl; ctrl--) {
|
||||
if (type == LZ_IMAGE_TYPE_RGBA)
|
||||
{
|
||||
//console.log("alpha " + in_buf[encoder] + " set into pixel " + op);
|
||||
out_buf[(op*4) + 3] = in_buf[encoder++];
|
||||
}
|
||||
else
|
||||
{
|
||||
out_buf[(op*4) + 0] = in_buf[encoder + 2];
|
||||
out_buf[(op*4) + 1] = in_buf[encoder + 1];
|
||||
out_buf[(op*4) + 2] = in_buf[encoder + 0];
|
||||
if (default_alpha)
|
||||
out_buf[(op*4) + 3] = 255;
|
||||
encoder += 3;
|
||||
}
|
||||
op++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return encoder - 1;
|
||||
}
|
||||
|
||||
function convert_spice_lz_rgb_to_web(context, lz_rgb)
|
||||
{
|
||||
var u8 = new Uint8Array(lz_rgb.data);
|
||||
var at;
|
||||
if (lz_rgb.type != LZ_IMAGE_TYPE_RGB32 && lz_rgb.type != LZ_IMAGE_TYPE_RGBA)
|
||||
return undefined;
|
||||
|
||||
var ret = context.createImageData(lz_rgb.width, lz_rgb.height);
|
||||
|
||||
at = lz_rgb32_decompress(u8, 0, ret.data, LZ_IMAGE_TYPE_RGB32, lz_rgb.type != LZ_IMAGE_TYPE_RGBA);
|
||||
if (lz_rgb.type == LZ_IMAGE_TYPE_RGBA)
|
||||
lz_rgb32_decompress(u8, at, ret.data, LZ_IMAGE_TYPE_RGBA, false);
|
||||
|
||||
return ret;
|
||||
}
|
176
main.js
Normal file
176
main.js
Normal file
@ -0,0 +1,176 @@
|
||||
"use strict";
|
||||
/*
|
||||
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||
|
||||
This file is part of spice-html5.
|
||||
|
||||
spice-html5 is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
spice-html5 is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
** SpiceMainConn
|
||||
** This is the master Javascript class for establishing and
|
||||
** managing a connection to a Spice Server.
|
||||
**
|
||||
** Invocation: You must pass an object with properties as follows:
|
||||
** uri (required) Uri of a WebSocket listener that is
|
||||
** connected to a spice server.
|
||||
** password (required) Password to send to the spice server
|
||||
** message_id (optional) Identifier of an element in the DOM
|
||||
** where SpiceConn will write messages.
|
||||
** It will use classes spice-messages-x,
|
||||
** where x is one of info, warning, or error.
|
||||
** screen_id (optional) Identifier of an element in the DOM
|
||||
** where SpiceConn will create any new
|
||||
** client screens. This is the main UI.
|
||||
** dump_id (optional) If given, an element to use for
|
||||
** dumping every single image + canvas drawn.
|
||||
** Sometimes useful for debugging.
|
||||
** onerror (optional) If given, a function to receive async
|
||||
** errors. Note that you should also catch
|
||||
** errors for ones that occur inline
|
||||
**
|
||||
** Throws error if there are troubles. Requires a modern (by 2012 standards)
|
||||
** browser, including WebSocket and WebSocket.binaryType == arraybuffer
|
||||
**
|
||||
**--------------------------------------------------------------------------*/
|
||||
function SpiceMainConn()
|
||||
{
|
||||
if (typeof WebSocket === "undefined")
|
||||
throw new Error("WebSocket unavailable. You need to use a different browser.");
|
||||
|
||||
SpiceConn.apply(this, arguments);
|
||||
|
||||
}
|
||||
|
||||
SpiceMainConn.prototype = Object.create(SpiceConn.prototype);
|
||||
SpiceMainConn.prototype.process_channel_message = function(msg)
|
||||
{
|
||||
if (msg.type == SPICE_MSG_MAIN_INIT)
|
||||
{
|
||||
this.log_info("Connected to " + this.ws.url);
|
||||
this.main_init = new SpiceMsgMainInit(msg.data);
|
||||
this.connection_id = this.main_init.session_id;
|
||||
|
||||
if (DEBUG > 0)
|
||||
{
|
||||
// FIXME - there is a lot here we don't handle; mouse modes, agent,
|
||||
// ram_hint, multi_media_time
|
||||
this.log_info("session id " + this.main_init.session_id +
|
||||
" ; display_channels_hint " + this.main_init.display_channels_hint +
|
||||
" ; supported_mouse_modes " + this.main_init.supported_mouse_modes +
|
||||
" ; current_mouse_mode " + this.main_init.current_mouse_mode +
|
||||
" ; agent_connected " + this.main_init.agent_connected +
|
||||
" ; agent_tokens " + this.main_init.agent_tokens +
|
||||
" ; multi_media_time " + this.main_init.multi_media_time +
|
||||
" ; ram_hint " + this.main_init.ram_hint);
|
||||
}
|
||||
|
||||
this.mouse_mode = this.main_init.current_mouse_mode;
|
||||
if (this.main_init.current_mouse_mode != SPICE_MOUSE_MODE_CLIENT &&
|
||||
(this.main_init.supported_mouse_modes & SPICE_MOUSE_MODE_CLIENT))
|
||||
{
|
||||
var mode_request = new SpiceMsgcMainMouseModeRequest(SPICE_MOUSE_MODE_CLIENT);
|
||||
var mr = new SpiceMiniData();
|
||||
mr.build_msg(SPICE_MSGC_MAIN_MOUSE_MODE_REQUEST, mode_request);
|
||||
this.send_msg(mr);
|
||||
}
|
||||
|
||||
var attach = new SpiceMiniData;
|
||||
attach.type = SPICE_MSGC_MAIN_ATTACH_CHANNELS;
|
||||
attach.size = attach.buffer_size();
|
||||
this.send_msg(attach);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (msg.type == SPICE_MSG_MAIN_MOUSE_MODE)
|
||||
{
|
||||
var mode = new SpiceMsgMainMouseMode(msg.data);
|
||||
DEBUG > 0 && this.log_info("Mouse supported modes " + mode.supported_modes + "; current " + mode.current_mode);
|
||||
this.mouse_mode = mode.current_mode;
|
||||
if (this.inputs)
|
||||
this.inputs.mouse_mode = mode.current_mode;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (msg.type == SPICE_MSG_MAIN_CHANNELS_LIST)
|
||||
{
|
||||
var i;
|
||||
var chans;
|
||||
DEBUG > 0 && console.log("channels");
|
||||
chans = new SpiceMsgChannels(msg.data);
|
||||
for (i = 0; i < chans.channels.length; i++)
|
||||
{
|
||||
var conn = {
|
||||
uri: this.ws.url,
|
||||
parent: this,
|
||||
connection_id : this.connection_id,
|
||||
type : chans.channels[i].type,
|
||||
chan_id : chans.channels[i].id
|
||||
};
|
||||
if (chans.channels[i].type == SPICE_CHANNEL_DISPLAY)
|
||||
this.display = new SpiceDisplayConn(conn);
|
||||
else if (chans.channels[i].type == SPICE_CHANNEL_INPUTS)
|
||||
{
|
||||
this.inputs = new SpiceInputsConn(conn);
|
||||
this.inputs.mouse_mode = this.mouse_mode;
|
||||
}
|
||||
else if (chans.channels[i].type == SPICE_CHANNEL_CURSOR)
|
||||
this.cursor = new SpiceCursorConn(conn);
|
||||
else
|
||||
{
|
||||
this.log_err("Channel type " + chans.channels[i].type + " unknown.");
|
||||
if (! ("extra_channels" in this))
|
||||
this.extra_channels = [];
|
||||
this.extra_channels[i] = new SpiceConn(conn);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
SpiceMainConn.prototype.stop = function(msg)
|
||||
{
|
||||
this.state = "closing";
|
||||
|
||||
if (this.inputs)
|
||||
{
|
||||
this.inputs.cleanup();
|
||||
this.inputs = undefined;
|
||||
}
|
||||
|
||||
if (this.cursor)
|
||||
{
|
||||
this.cursor.cleanup();
|
||||
this.cursor = undefined;
|
||||
}
|
||||
|
||||
if (this.display)
|
||||
{
|
||||
this.display.cleanup();
|
||||
this.display.destroy_surfaces();
|
||||
this.display = undefined;
|
||||
}
|
||||
|
||||
this.cleanup();
|
||||
|
||||
if ("extra_channels" in this)
|
||||
for (var e in this.extra_channels)
|
||||
this.extra_channels[e].cleanup();
|
||||
this.extra_channels = undefined;
|
||||
}
|
8
makequic
Normal file
8
makequic
Normal file
@ -0,0 +1,8 @@
|
||||
./emcc -o quic.js --shell-file quic.shell quic.c
|
||||
echo Okay, quic.js is partly ready. Three things to do:
|
||||
echo 1. In function _quic_decode_js, after the call to simple_quic_decode,
|
||||
echo add the code as given by quic.shell
|
||||
echo 2. Delete the run() 3 line block near the bottom.
|
||||
echo 3. Add the getQuic() function to the bottom (see quic.shell)
|
||||
|
||||
|
256
png.js
Normal file
256
png.js
Normal file
@ -0,0 +1,256 @@
|
||||
"use strict";
|
||||
/*
|
||||
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||
|
||||
This file is part of spice-html5.
|
||||
|
||||
spice-html5 is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
spice-html5 is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
** crc logic from rfc2083 ported to Javascript
|
||||
**--------------------------------------------------------------------------*/
|
||||
|
||||
var rfc2083_crc_table = Array(256);
|
||||
var rfc2083_crc_table_computed = 0;
|
||||
/* Make the table for a fast CRC. */
|
||||
function rfc2083_make_crc_table()
|
||||
{
|
||||
var c;
|
||||
var n, k;
|
||||
for (n = 0; n < 256; n++)
|
||||
{
|
||||
c = n;
|
||||
for (k = 0; k < 8; k++)
|
||||
{
|
||||
if (c & 1)
|
||||
c = ((0xedb88320 ^ (c >>> 1)) >>> 0) & 0xffffffff;
|
||||
else
|
||||
c = c >>> 1;
|
||||
}
|
||||
rfc2083_crc_table[n] = c;
|
||||
}
|
||||
|
||||
rfc2083_crc_table_computed = 1;
|
||||
}
|
||||
|
||||
/* Update a running CRC with the bytes buf[0..len-1]--the CRC
|
||||
should be initialized to all 1's, and the transmitted value
|
||||
is the 1's complement of the final running CRC (see the
|
||||
crc() routine below)). */
|
||||
|
||||
function rfc2083_update_crc(crc, u8buf, at, len)
|
||||
{
|
||||
var c = crc;
|
||||
var n;
|
||||
|
||||
if (!rfc2083_crc_table_computed)
|
||||
rfc2083_make_crc_table();
|
||||
|
||||
for (n = 0; n < len; n++)
|
||||
{
|
||||
c = rfc2083_crc_table[(c ^ u8buf[at + n]) & 0xff] ^ (c >>> 8);
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
function rfc2083_crc(u8buf, at, len)
|
||||
{
|
||||
return rfc2083_update_crc(0xffffffff, u8buf, at, len) ^ 0xffffffff;
|
||||
}
|
||||
|
||||
function crc32(mb, at, len)
|
||||
{
|
||||
var u8 = new Uint8Array(mb);
|
||||
return rfc2083_crc(u8, at, len);
|
||||
}
|
||||
|
||||
function PngIHDR(width, height)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.depth = 8;
|
||||
this.type = 6;
|
||||
this.compression = 0;
|
||||
this.filter = 0;
|
||||
this.interlace = 0;
|
||||
}
|
||||
|
||||
PngIHDR.prototype =
|
||||
{
|
||||
to_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var orig = at;
|
||||
var dv = new SpiceDataView(a);
|
||||
dv.setUint32(at, this.buffer_size() - 12); at += 4;
|
||||
dv.setUint8(at, 'I'.charCodeAt(0)); at++;
|
||||
dv.setUint8(at, 'H'.charCodeAt(0)); at++;
|
||||
dv.setUint8(at, 'D'.charCodeAt(0)); at++;
|
||||
dv.setUint8(at, 'R'.charCodeAt(0)); at++;
|
||||
dv.setUint32(at, this.width); at += 4;
|
||||
dv.setUint32(at, this.height); at += 4;
|
||||
dv.setUint8(at, this.depth); at++;
|
||||
dv.setUint8(at, this.type); at++;
|
||||
dv.setUint8(at, this.compression); at++;
|
||||
dv.setUint8(at, this.filter); at++;
|
||||
dv.setUint8(at, this.interlace); at++;
|
||||
dv.setUint32(at, crc32(a, orig + 4, this.buffer_size() - 8)); at += 4;
|
||||
return at;
|
||||
},
|
||||
buffer_size: function()
|
||||
{
|
||||
return 12 + 13;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function adler()
|
||||
{
|
||||
this.s1 = 1;
|
||||
this.s2 = 0;
|
||||
}
|
||||
|
||||
adler.prototype.update = function(b)
|
||||
{
|
||||
this.s1 += b;
|
||||
this.s1 %= 65521;
|
||||
this.s2 += this.s1;
|
||||
this.s2 %= 65521;
|
||||
}
|
||||
|
||||
function PngIDAT(width, height, bytes)
|
||||
{
|
||||
if (bytes.byteLength > 65535)
|
||||
{
|
||||
throw new Error("Cannot handle more than 64K");
|
||||
}
|
||||
this.data = bytes;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
PngIDAT.prototype =
|
||||
{
|
||||
to_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var orig = at;
|
||||
var x, y, i, j;
|
||||
var dv = new SpiceDataView(a);
|
||||
var zsum = new adler();
|
||||
dv.setUint32(at, this.buffer_size() - 12); at += 4;
|
||||
dv.setUint8(at, 'I'.charCodeAt(0)); at++;
|
||||
dv.setUint8(at, 'D'.charCodeAt(0)); at++;
|
||||
dv.setUint8(at, 'A'.charCodeAt(0)); at++;
|
||||
dv.setUint8(at, 'T'.charCodeAt(0)); at++;
|
||||
|
||||
/* zlib header. */
|
||||
dv.setUint8(at, 0x78); at++;
|
||||
dv.setUint8(at, 0x01); at++;
|
||||
|
||||
/* Deflate header. Specifies uncompressed, final bit */
|
||||
dv.setUint8(at, 0x80); at++;
|
||||
dv.setUint16(at, this.data.byteLength + this.height); at += 2;
|
||||
dv.setUint16(at, ~(this.data.byteLength + this.height)); at += 2;
|
||||
var u8 = new Uint8Array(this.data);
|
||||
for (i = 0, y = 0; y < this.height; y++)
|
||||
{
|
||||
/* Filter type 0 - uncompressed */
|
||||
dv.setUint8(at, 0); at++;
|
||||
zsum.update(0);
|
||||
for (x = 0; x < this.width && i < this.data.byteLength; x++)
|
||||
{
|
||||
zsum.update(u8[i]);
|
||||
dv.setUint8(at, u8[i++]); at++;
|
||||
zsum.update(u8[i]);
|
||||
dv.setUint8(at, u8[i++]); at++;
|
||||
zsum.update(u8[i]);
|
||||
dv.setUint8(at, u8[i++]); at++;
|
||||
zsum.update(u8[i]);
|
||||
dv.setUint8(at, u8[i++]); at++;
|
||||
}
|
||||
}
|
||||
|
||||
/* zlib checksum. */
|
||||
dv.setUint16(at, zsum.s2); at+=2;
|
||||
dv.setUint16(at, zsum.s1); at+=2;
|
||||
|
||||
/* FIXME - something is not quite right with the zlib code;
|
||||
you get an error from libpng if you open the image in
|
||||
gimp. But it works, so it's good enough for now... */
|
||||
|
||||
dv.setUint32(at, crc32(a, orig + 4, this.buffer_size() - 8)); at += 4;
|
||||
return at;
|
||||
},
|
||||
buffer_size: function()
|
||||
{
|
||||
return 12 + this.data.byteLength + this.height + 4 + 2 + 1 + 2 + 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function PngIEND()
|
||||
{
|
||||
}
|
||||
|
||||
PngIEND.prototype =
|
||||
{
|
||||
to_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var orig = at;
|
||||
var i;
|
||||
var dv = new SpiceDataView(a);
|
||||
dv.setUint32(at, this.buffer_size() - 12); at += 4;
|
||||
dv.setUint8(at, 'I'.charCodeAt(0)); at++;
|
||||
dv.setUint8(at, 'E'.charCodeAt(0)); at++;
|
||||
dv.setUint8(at, 'N'.charCodeAt(0)); at++;
|
||||
dv.setUint8(at, 'D'.charCodeAt(0)); at++;
|
||||
dv.setUint32(at, crc32(a, orig + 4, this.buffer_size() - 8)); at += 4;
|
||||
return at;
|
||||
},
|
||||
buffer_size: function()
|
||||
{
|
||||
return 12;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function create_rgba_png(width, height, bytes)
|
||||
{
|
||||
var i;
|
||||
var ihdr = new PngIHDR(width, height);
|
||||
var idat = new PngIDAT(width, height, bytes);
|
||||
var iend = new PngIEND;
|
||||
|
||||
var mb = new ArrayBuffer(ihdr.buffer_size() + idat.buffer_size() + iend.buffer_size());
|
||||
var at = ihdr.to_buffer(mb);
|
||||
at = idat.to_buffer(mb, at);
|
||||
at = iend.to_buffer(mb, at);
|
||||
|
||||
var u8 = new Uint8Array(mb);
|
||||
var str = "";
|
||||
for (i = 0; i < at; i++)
|
||||
{
|
||||
str += "%";
|
||||
if (u8[i] < 16)
|
||||
str += "0";
|
||||
str += u8[i].toString(16);
|
||||
}
|
||||
|
||||
|
||||
return "%89PNG%0D%0A%1A%0A" + str;
|
||||
}
|
91
quic.shell
Normal file
91
quic.shell
Normal file
File diff suppressed because one or more lines are too long
116
spice.css
Normal file
116
spice.css
Normal file
@ -0,0 +1,116 @@
|
||||
body
|
||||
{
|
||||
background-color: #999999;
|
||||
color: #000000; margin: 0; padding: 0;
|
||||
font-family: "Lucida Grande", "Lucida Sans Unicode", "Helvetica Neue", Helvetica, Arial, Verdana, sans-serif;
|
||||
font-size: 12pt;
|
||||
line-height: 1.5em;
|
||||
}
|
||||
|
||||
* { margin: 0; }
|
||||
|
||||
#login
|
||||
{
|
||||
width: 790px;
|
||||
margin-top: 20px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
padding: 2px 10px 2px 20px;
|
||||
border: 1px solid #999999;
|
||||
background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#24414e));
|
||||
background: -moz-linear-gradient(top, #fff, #24414e);
|
||||
background-color: #24414e;
|
||||
-moz-border-radius: 10px;
|
||||
-webkit-border-radius: 10px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
#login span.logo
|
||||
{
|
||||
display: inline-block;
|
||||
margin-right: 5px;
|
||||
padding-right: 10px;
|
||||
border-right: 1px solid #999999;
|
||||
font-size: 20px;
|
||||
font-weight: bolder;
|
||||
text-shadow: #efefef 1px 1px 0px;
|
||||
}
|
||||
#login label { color: #ffffff; text-shadow: 1px 1px 0px rgba(175, 210, 220, 0.8); }
|
||||
#login input
|
||||
{
|
||||
padding: 5px;
|
||||
background-color: #fAfAfA;
|
||||
border: 1px inset #999999;
|
||||
outline: none;
|
||||
-moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px;
|
||||
box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
-webkit-box-sizing: border-box;
|
||||
}
|
||||
#login input#host { width: 200px; }
|
||||
#login input#port { width: 75px; }
|
||||
#login input#password { width: 100px; }
|
||||
#login button
|
||||
{
|
||||
padding: 5px 10px 5px 10px;
|
||||
margin-left: 5px;
|
||||
text-shadow: #efefef 1px 1px 0px;
|
||||
border: 1px outset #999999;
|
||||
cursor: pointer;
|
||||
-moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px;
|
||||
}
|
||||
#login button:hover
|
||||
{
|
||||
background-color: #666666;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
#spice-area
|
||||
{
|
||||
text-align: center;
|
||||
}
|
||||
.spice-screen
|
||||
{
|
||||
display: inline-block;
|
||||
padding: 10px;
|
||||
min-width: 800px;
|
||||
min-height: 600px;
|
||||
border: solid #222222 1px;
|
||||
background-color: #333333;
|
||||
-webkit-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.2);
|
||||
-moz-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.2);
|
||||
box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.2);
|
||||
-moz-border-radius: 10px;
|
||||
-webkit-border-radius: 10px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
.spice-message {
|
||||
width: 700px;
|
||||
height: 50px;
|
||||
overflow: auto;
|
||||
margin-top: 5px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
padding: 10px;
|
||||
background-color: #efefef;
|
||||
border: solid #c3c3c3 2px;
|
||||
font-size: 8pt;
|
||||
line-height: 1.1em;
|
||||
font-family: 'Andale Mono', monospace;
|
||||
-moz-border-radius: 10px;
|
||||
-webkit-border-radius: 10px;
|
||||
border-radius: 10px;
|
||||
-webkit-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.2);
|
||||
-moz-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.2);
|
||||
box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
.spice-message p {
|
||||
margin-bottom: 0em;
|
||||
margin-top: 0em;
|
||||
}
|
||||
.spice-message-warning {
|
||||
color: orange;
|
||||
}
|
||||
.spice-message-error {
|
||||
color: red;
|
||||
}
|
||||
|
134
spice.html
Normal file
134
spice.html
Normal file
@ -0,0 +1,134 @@
|
||||
<!--
|
||||
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||
|
||||
This file is part of spice-html5.
|
||||
|
||||
spice-html5 is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
spice-html5 is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
--------------------------------------------------
|
||||
Spice Javascript client template.
|
||||
Refer to main.js for more detailed information
|
||||
--------------------------------------------------
|
||||
|
||||
-->
|
||||
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
|
||||
<title>Spice Javascript client</title>
|
||||
<script src="enums.js"></script>
|
||||
<script src="utils.js"></script>
|
||||
<script src="png.js"></script>
|
||||
<script src="lz.js"></script>
|
||||
<script src="quic.js"></script>
|
||||
<script src="bitmap.js"></script>
|
||||
<script src="spicedataview.js"></script>
|
||||
<script src="spicetype.js"></script>
|
||||
<script src="spicemsg.js"></script>
|
||||
<script src="wire.js"></script>
|
||||
<script src="spiceconn.js"></script>
|
||||
<script src="display.js"></script>
|
||||
<script src="main.js"></script>
|
||||
<script src="inputs.js"></script>
|
||||
<script src="cursor.js"></script>
|
||||
<script src="thirdparty/jsbn.js"></script>
|
||||
<script src="thirdparty/rsa.js"></script>
|
||||
<script src="thirdparty/prng4.js"></script>
|
||||
<script src="thirdparty/rng.js"></script>
|
||||
<script src="thirdparty/sha1.js"></script>
|
||||
<script src="ticket.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="spice.css" />
|
||||
|
||||
<script>
|
||||
var host = null, port = null;
|
||||
var sc;
|
||||
|
||||
function spice_error(e)
|
||||
{
|
||||
disconnect();
|
||||
}
|
||||
|
||||
function connect()
|
||||
{
|
||||
var host, port, password, scheme = "ws://", uri;
|
||||
|
||||
host = document.getElementById("host").value;
|
||||
port = document.getElementById("port").value;
|
||||
password = document.getElementById("password").value;
|
||||
|
||||
|
||||
if ((!host) || (!port)) {
|
||||
console.log("must set host and port");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sc) {
|
||||
sc.stop();
|
||||
}
|
||||
|
||||
uri = scheme + host + ":" + port;
|
||||
|
||||
document.getElementById('connectButton').innerHTML = "Stop";
|
||||
document.getElementById('connectButton').onclick = disconnect;
|
||||
|
||||
try
|
||||
{
|
||||
sc = new SpiceMainConn({uri: uri, screen_id: "spice-screen", dump_id: "debug-div",
|
||||
message_id: "message-div", password: password, onerror: spice_error });
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
alert(e.toString());
|
||||
disconnect();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function disconnect()
|
||||
{
|
||||
console.log(">> disconnect");
|
||||
if (sc) {
|
||||
sc.stop();
|
||||
}
|
||||
document.getElementById('connectButton').innerHTML = "Start";
|
||||
document.getElementById('connectButton').onclick = connect;
|
||||
console.log("<< disconnect");
|
||||
}
|
||||
</script>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="login">
|
||||
<span class="logo">SPICE</span>
|
||||
<label for="host">Host:</label> <input type='text' id='host' value='localhost'> <!-- localhost -->
|
||||
<label for="port">Port:</label> <input type='text' id='port' value='5959'>
|
||||
<label for="password">Password:</label> <input type='password' id='password' value='spicy'>
|
||||
<button id="connectButton" onclick="connect();">Start</button>
|
||||
</div>
|
||||
|
||||
<div id="spice-area">
|
||||
<div id="spice-screen" class="spice-screen"></div>
|
||||
</div>
|
||||
|
||||
<div id="message-div" class="spice-message"></div>
|
||||
|
||||
<div id="debug-div">
|
||||
<!-- If DUMPXXX is turned on, dumped images will go here -->
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
447
spiceconn.js
Normal file
447
spiceconn.js
Normal file
@ -0,0 +1,447 @@
|
||||
"use strict";
|
||||
/*
|
||||
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||
|
||||
This file is part of spice-html5.
|
||||
|
||||
spice-html5 is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
spice-html5 is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
** SpiceConn
|
||||
** This is the base Javascript class for establishing and
|
||||
** managing a connection to a Spice Server.
|
||||
** It is used to provide core functionality to the Spice main,
|
||||
** display, inputs, and cursor channels. See main.js for
|
||||
** usage.
|
||||
**--------------------------------------------------------------------------*/
|
||||
function SpiceConn(o)
|
||||
{
|
||||
if (o === undefined || o.uri === undefined || ! o.uri)
|
||||
throw new Error("You must specify a uri");
|
||||
|
||||
this.ws = new WebSocket(o.uri, 'binary');
|
||||
|
||||
if (! this.ws.binaryType)
|
||||
throw new Error("WebSocket doesn't support binaryType. Try a different browser.");
|
||||
|
||||
this.connection_id = o.connection_id !== undefined ? o.connection_id : 0;
|
||||
this.type = o.type !== undefined ? o.type : SPICE_CHANNEL_MAIN;
|
||||
this.chan_id = o.chan_id !== undefined ? o.chan_id : 0;
|
||||
if (o.parent !== undefined)
|
||||
{
|
||||
this.parent = o.parent;
|
||||
this.message_id = o.parent.message_id;
|
||||
this.password = o.parent.password;
|
||||
}
|
||||
if (o.screen_id !== undefined)
|
||||
this.screen_id = o.screen_id;
|
||||
if (o.dump_id !== undefined)
|
||||
this.dump_id = o.dump_id;
|
||||
if (o.message_id !== undefined)
|
||||
this.message_id = o.message_id;
|
||||
if (o.password !== undefined)
|
||||
this.password = o.password;
|
||||
if (o.onerror !== undefined)
|
||||
this.onerror = o.onerror;
|
||||
|
||||
this.state = "connecting";
|
||||
this.ws.parent = this;
|
||||
this.wire_reader = new SpiceWireReader(this, this.process_inbound);
|
||||
this.messages_sent = 0;
|
||||
this.warnings = [];
|
||||
|
||||
this.ws.addEventListener('open', function(e) {
|
||||
DEBUG > 0 && console.log(">> WebSockets.onopen");
|
||||
DEBUG > 0 && console.log("id " + this.parent.connection_id +"; type " + this.parent.type);
|
||||
|
||||
/***********************************************************************
|
||||
** WHERE IT ALL REALLY BEGINS
|
||||
***********************************************************************/
|
||||
this.parent.send_hdr();
|
||||
this.parent.wire_reader.request(SpiceLinkHeader.prototype.buffer_size());
|
||||
this.parent.state = "start";
|
||||
});
|
||||
this.ws.addEventListener('error', function(e) {
|
||||
this.parent.log_err(">> WebSockets.onerror" + e.toString());
|
||||
this.parent.report_error(e);
|
||||
});
|
||||
this.ws.addEventListener('close', function(e) {
|
||||
DEBUG > 0 && console.log(">> WebSockets.onclose");
|
||||
DEBUG > 0 && console.log("id " + this.parent.connection_id +"; type " + this.parent.type);
|
||||
DEBUG > 0 && console.log(e);
|
||||
if (this.parent.state != "closing" && this.parent.state != "error" && this.parent.onerror !== undefined)
|
||||
{
|
||||
var e;
|
||||
if (this.parent.state == "connecting")
|
||||
e = new Error("Connection refused.");
|
||||
else if (this.parent.state == "start" || this.parent.state == "link")
|
||||
e = new Error("Unexpected protocol mismatch.");
|
||||
else if (this.parent.state == "ticket")
|
||||
e = new Error("Bad password.");
|
||||
else
|
||||
e = new Error("Unexpected close while " + this.parent.state);
|
||||
|
||||
this.parent.onerror(e);
|
||||
this.parent.log_err(e.toString());
|
||||
}
|
||||
});
|
||||
|
||||
if (this.ws.readyState == 2 || this.ws.readyState == 3)
|
||||
throw new Error("Unable to connect to " + o.uri);
|
||||
|
||||
this.timeout = window.setTimeout(spiceconn_timeout, SPICE_CONNECT_TIMEOUT, this);
|
||||
}
|
||||
|
||||
SpiceConn.prototype =
|
||||
{
|
||||
send_hdr : function ()
|
||||
{
|
||||
var hdr = new SpiceLinkHeader;
|
||||
var msg = new SpiceLinkMess;
|
||||
|
||||
msg.connection_id = this.connection_id;
|
||||
msg.channel_type = this.type;
|
||||
// FIXME - we're not setting a channel_id...
|
||||
msg.common_caps.push(
|
||||
(1 << SPICE_COMMON_CAP_PROTOCOL_AUTH_SELECTION) |
|
||||
(1 << SPICE_COMMON_CAP_MINI_HEADER)
|
||||
);
|
||||
|
||||
hdr.size = msg.buffer_size();
|
||||
|
||||
var mb = new ArrayBuffer(hdr.buffer_size() + msg.buffer_size());
|
||||
hdr.to_buffer(mb);
|
||||
msg.to_buffer(mb, hdr.buffer_size());
|
||||
|
||||
DEBUG > 1 && console.log("Sending header:");
|
||||
DEBUG > 2 && hexdump_buffer(mb);
|
||||
this.ws.send(mb);
|
||||
},
|
||||
|
||||
send_ticket: function(ticket)
|
||||
{
|
||||
var hdr = new SpiceLinkAuthTicket();
|
||||
hdr.auth_mechanism = SPICE_COMMON_CAP_AUTH_SPICE;
|
||||
// FIXME - we need to implement RSA to make this work right
|
||||
hdr.encrypted_data = ticket;
|
||||
var mb = new ArrayBuffer(hdr.buffer_size());
|
||||
|
||||
hdr.to_buffer(mb);
|
||||
DEBUG > 1 && console.log("Sending ticket:");
|
||||
DEBUG > 2 && hexdump_buffer(mb);
|
||||
this.ws.send(mb);
|
||||
},
|
||||
|
||||
send_msg: function(msg)
|
||||
{
|
||||
var mb = new ArrayBuffer(msg.buffer_size());
|
||||
msg.to_buffer(mb);
|
||||
this.messages_sent++;
|
||||
DEBUG > 0 && console.log(">> hdr " + this.channel_type() + " type " + msg.type + " size " + mb.byteLength);
|
||||
DEBUG > 2 && hexdump_buffer(mb);
|
||||
this.ws.send(mb);
|
||||
},
|
||||
|
||||
process_inbound: function(mb, saved_header)
|
||||
{
|
||||
DEBUG > 2 && console.log(this.type + ": processing message of size " + mb.byteLength + "; state is " + this.state);
|
||||
if (this.state == "ready")
|
||||
{
|
||||
if (saved_header == undefined)
|
||||
{
|
||||
var msg = new SpiceMiniData(mb);
|
||||
|
||||
if (msg.type > 500)
|
||||
{
|
||||
alert("Something has gone very wrong; we think we have message of type " + msg.type);
|
||||
debugger;
|
||||
}
|
||||
|
||||
if (msg.size == 0)
|
||||
{
|
||||
this.process_message(msg);
|
||||
this.wire_reader.request(SpiceMiniData.prototype.buffer_size());
|
||||
}
|
||||
else
|
||||
{
|
||||
this.wire_reader.request(msg.size);
|
||||
this.wire_reader.save_header(msg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
saved_header.data = mb;
|
||||
this.process_message(saved_header);
|
||||
this.wire_reader.request(SpiceMiniData.prototype.buffer_size());
|
||||
this.wire_reader.save_header(undefined);
|
||||
}
|
||||
}
|
||||
|
||||
else if (this.state == "start")
|
||||
{
|
||||
this.reply_hdr = new SpiceLinkHeader(mb);
|
||||
if (this.reply_hdr.magic != SPICE_MAGIC)
|
||||
{
|
||||
this.state = "error";
|
||||
var e = new Error('Error: magic mismatch: ' + this.reply_hdr.magic);
|
||||
this.report_error(e);
|
||||
}
|
||||
else
|
||||
{
|
||||
// FIXME - Determine major/minor version requirements
|
||||
this.wire_reader.request(this.reply_hdr.size);
|
||||
this.state = "link";
|
||||
}
|
||||
}
|
||||
|
||||
else if (this.state == "link")
|
||||
{
|
||||
this.reply_link = new SpiceLinkReply(mb);
|
||||
// FIXME - Screen the caps - require minihdr at least, right?
|
||||
if (this.reply_link.error)
|
||||
{
|
||||
this.state = "error";
|
||||
var e = new Error('Error: reply link error ' + this.reply_link.error);
|
||||
this.report_error(e);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.send_ticket(rsa_encrypt(this.reply_link.pub_key, this.password + String.fromCharCode(0)));
|
||||
this.state = "ticket";
|
||||
this.wire_reader.request(SpiceLinkAuthReply.prototype.buffer_size());
|
||||
}
|
||||
}
|
||||
|
||||
else if (this.state == "ticket")
|
||||
{
|
||||
this.auth_reply = new SpiceLinkAuthReply(mb);
|
||||
if (this.auth_reply.auth_code == SPICE_LINK_ERR_OK)
|
||||
{
|
||||
DEBUG > 0 && console.log(this.type + ': Connected');
|
||||
|
||||
if (this.type == SPICE_CHANNEL_DISPLAY)
|
||||
{
|
||||
// FIXME - pixmap and glz dictionary config info?
|
||||
var dinit = new SpiceMsgcDisplayInit();
|
||||
var reply = new SpiceMiniData();
|
||||
reply.build_msg(SPICE_MSGC_DISPLAY_INIT, dinit);
|
||||
DEBUG > 0 && console.log("Request display init");
|
||||
this.send_msg(reply);
|
||||
}
|
||||
this.state = "ready";
|
||||
this.wire_reader.request(SpiceMiniData.prototype.buffer_size());
|
||||
if (this.timeout)
|
||||
{
|
||||
window.clearTimeout(this.timeout);
|
||||
delete this.timeout;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.state = "error";
|
||||
if (this.auth_reply.auth_code == SPICE_LINK_ERR_PERMISSION_DENIED)
|
||||
{
|
||||
var e = new Error("Permission denied.");
|
||||
}
|
||||
else
|
||||
{
|
||||
var e = new Error("Unexpected link error " + this.auth_reply.auth_code);
|
||||
}
|
||||
this.report_error(e);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
process_common_messages : function(msg)
|
||||
{
|
||||
if (msg.type == SPICE_MSG_SET_ACK)
|
||||
{
|
||||
var ack = new SpiceMsgSetAck(msg.data);
|
||||
// FIXME - what to do with generation?
|
||||
this.ack_window = ack.window;
|
||||
DEBUG > 1 && console.log(this.type + ": set ack to " + ack.window);
|
||||
this.msgs_until_ack = this.ack_window;
|
||||
var ackack = new SpiceMsgcAckSync(ack);
|
||||
var reply = new SpiceMiniData();
|
||||
reply.build_msg(SPICE_MSGC_ACK_SYNC, ackack);
|
||||
this.send_msg(reply);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (msg.type == SPICE_MSG_PING)
|
||||
{
|
||||
DEBUG > 1 && console.log("ping!");
|
||||
var pong = new SpiceMiniData;
|
||||
pong.type = SPICE_MSGC_PONG;
|
||||
if (msg.data)
|
||||
{
|
||||
pong.data = msg.data.slice(0, 12);
|
||||
}
|
||||
pong.size = pong.buffer_size();
|
||||
this.send_msg(pong);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (msg.type == SPICE_MSG_NOTIFY)
|
||||
{
|
||||
// FIXME - Visibility + what
|
||||
var notify = new SpiceMsgNotify(msg.data);
|
||||
if (notify.severity == SPICE_NOTIFY_SEVERITY_ERROR)
|
||||
this.log_err(notify.message);
|
||||
else if (notify.severity == SPICE_NOTIFY_SEVERITY_WARN )
|
||||
this.log_warn(notify.message);
|
||||
else
|
||||
this.log_info(notify.message);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
},
|
||||
|
||||
process_message: function(msg)
|
||||
{
|
||||
var rc;
|
||||
DEBUG > 0 && console.log("<< hdr " + this.channel_type() + " type " + msg.type + " size " + (msg.data && msg.data.byteLength));
|
||||
rc = this.process_common_messages(msg);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
if (this.process_channel_message)
|
||||
rc = this.process_channel_message(msg);
|
||||
else
|
||||
{
|
||||
this.log_err(this.type + ": No message handlers for this channel; message " + msg.type);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! rc)
|
||||
this.log_warn(this.type + ": Unknown message type " + msg.type + "!");
|
||||
|
||||
if (this.msgs_until_ack !== undefined && this.ack_window)
|
||||
{
|
||||
this.msgs_until_ack--;
|
||||
if (this.msgs_until_ack <= 0)
|
||||
{
|
||||
this.msgs_until_ack = this.ack_window;
|
||||
var ack = new SpiceMiniData();
|
||||
ack.type = SPICE_MSGC_ACK;
|
||||
this.send_msg(ack);
|
||||
DEBUG > 1 && console.log(this.type + ": sent ack");
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
},
|
||||
|
||||
channel_type: function()
|
||||
{
|
||||
if (this.type == SPICE_CHANNEL_MAIN)
|
||||
return "main";
|
||||
else if (this.type == SPICE_CHANNEL_DISPLAY)
|
||||
return "display";
|
||||
else if (this.type == SPICE_CHANNEL_INPUTS)
|
||||
return "inputs";
|
||||
else if (this.type == SPICE_CHANNEL_CURSOR)
|
||||
return "cursor";
|
||||
return "unknown-" + this.type;
|
||||
|
||||
},
|
||||
|
||||
log_info: function()
|
||||
{
|
||||
var msg = Array.prototype.join.call(arguments, " ");
|
||||
console.log(msg);
|
||||
if (this.message_id)
|
||||
{
|
||||
var p = document.createElement("p");
|
||||
p.appendChild(document.createTextNode(msg));
|
||||
p.className += "spice-message-info";
|
||||
document.getElementById(this.message_id).appendChild(p);
|
||||
}
|
||||
},
|
||||
|
||||
log_warn: function()
|
||||
{
|
||||
var msg = Array.prototype.join.call(arguments, " ");
|
||||
console.log("WARNING: " + msg);
|
||||
if (this.message_id)
|
||||
{
|
||||
var p = document.createElement("p");
|
||||
p.appendChild(document.createTextNode(msg));
|
||||
p.className += "spice-message-warning";
|
||||
document.getElementById(this.message_id).appendChild(p);
|
||||
}
|
||||
},
|
||||
|
||||
log_err: function()
|
||||
{
|
||||
var msg = Array.prototype.join.call(arguments, " ");
|
||||
console.log("ERROR: " + msg);
|
||||
if (this.message_id)
|
||||
{
|
||||
var p = document.createElement("p");
|
||||
p.appendChild(document.createTextNode(msg));
|
||||
p.className += "spice-message-error";
|
||||
document.getElementById(this.message_id).appendChild(p);
|
||||
}
|
||||
},
|
||||
|
||||
known_unimplemented: function(type, msg)
|
||||
{
|
||||
if ( (!this.warnings[type]) || DEBUG > 1)
|
||||
{
|
||||
var str = "";
|
||||
if (DEBUG <= 1)
|
||||
str = " [ further notices suppressed ]";
|
||||
this.log_warn("Unimplemented function " + type + "(" + msg + ")" + str);
|
||||
this.warnings[type] = true;
|
||||
}
|
||||
},
|
||||
|
||||
report_error: function(e)
|
||||
{
|
||||
this.log_err(e.toString());
|
||||
if (this.onerror != undefined)
|
||||
this.onerror(e);
|
||||
else
|
||||
throw(e);
|
||||
},
|
||||
|
||||
cleanup: function()
|
||||
{
|
||||
if (this.timeout)
|
||||
{
|
||||
window.clearTimeout(this.timeout);
|
||||
delete this.timeout;
|
||||
}
|
||||
if (this.ws)
|
||||
{
|
||||
this.ws.close();
|
||||
this.ws = undefined;
|
||||
}
|
||||
},
|
||||
|
||||
handle_timeout: function()
|
||||
{
|
||||
var e = new Error("Connection timed out.");
|
||||
this.report_error(e);
|
||||
},
|
||||
}
|
||||
|
||||
function spiceconn_timeout(sc)
|
||||
{
|
||||
SpiceConn.prototype.handle_timeout.call(sc);
|
||||
}
|
96
spicedataview.js
Normal file
96
spicedataview.js
Normal file
@ -0,0 +1,96 @@
|
||||
"use strict";
|
||||
/*
|
||||
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||
|
||||
This file is part of spice-html5.
|
||||
|
||||
spice-html5 is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
spice-html5 is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
** SpiceDataView
|
||||
** FIXME FIXME
|
||||
** This is used because Firefox does not have DataView yet.
|
||||
** We should use DataView if we have it, because it *has* to
|
||||
** be faster than this code
|
||||
**--------------------------------------------------------------------------*/
|
||||
function SpiceDataView(buffer, byteOffset, byteLength)
|
||||
{
|
||||
if (byteOffset !== undefined)
|
||||
{
|
||||
if (byteLength !== undefined)
|
||||
this.u8 = new Uint8Array(buffer, byteOffset, byteLength);
|
||||
else
|
||||
this.u8 = new Uint8Array(buffer, byteOffset);
|
||||
}
|
||||
else
|
||||
this.u8 = new Uint8Array(buffer);
|
||||
};
|
||||
|
||||
SpiceDataView.prototype = {
|
||||
getUint8: function(byteOffset)
|
||||
{
|
||||
return this.u8[byteOffset];
|
||||
},
|
||||
getUint16: function(byteOffset, littleEndian)
|
||||
{
|
||||
var low = 1, high = 0;
|
||||
if (littleEndian)
|
||||
{
|
||||
low = 0;
|
||||
high = 1;
|
||||
}
|
||||
|
||||
return (this.u8[byteOffset + high] << 8) | this.u8[byteOffset + low];
|
||||
},
|
||||
getUint32: function(byteOffset, littleEndian)
|
||||
{
|
||||
var low = 2, high = 0;
|
||||
if (littleEndian)
|
||||
{
|
||||
low = 0;
|
||||
high = 2;
|
||||
}
|
||||
|
||||
return (this.getUint16(byteOffset + high, littleEndian) << 16) |
|
||||
this.getUint16(byteOffset + low, littleEndian);
|
||||
},
|
||||
setUint8: function(byteOffset, b)
|
||||
{
|
||||
this.u8[byteOffset] = (b & 0xff);
|
||||
},
|
||||
setUint16: function(byteOffset, i, littleEndian)
|
||||
{
|
||||
var low = 1, high = 0;
|
||||
if (littleEndian)
|
||||
{
|
||||
low = 0;
|
||||
high = 1;
|
||||
}
|
||||
this.u8[byteOffset + high] = (i & 0xffff) >> 8;
|
||||
this.u8[byteOffset + low] = (i & 0x00ff);
|
||||
},
|
||||
setUint32: function(byteOffset, w, littleEndian)
|
||||
{
|
||||
var low = 2, high = 0;
|
||||
if (littleEndian)
|
||||
{
|
||||
low = 0;
|
||||
high = 2;
|
||||
}
|
||||
|
||||
this.setUint16(byteOffset + high, (w & 0xffffffff) >> 16, littleEndian);
|
||||
this.setUint16(byteOffset + low, (w & 0x0000ffff), littleEndian);
|
||||
},
|
||||
}
|
791
spicemsg.js
Normal file
791
spicemsg.js
Normal file
@ -0,0 +1,791 @@
|
||||
"use strict";
|
||||
/*
|
||||
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||
|
||||
This file is part of spice-html5.
|
||||
|
||||
spice-html5 is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
spice-html5 is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
** Spice messages
|
||||
** This file contains classes for passing messages to and from
|
||||
** a spice server. This file should arguably be generated from
|
||||
** spice.proto, but it was instead put together by hand.
|
||||
**--------------------------------------------------------------------------*/
|
||||
function SpiceLinkHeader(a, at)
|
||||
{
|
||||
this.magic = SPICE_MAGIC;
|
||||
this.major_version = SPICE_VERSION_MAJOR;
|
||||
this.minor_version = SPICE_VERSION_MINOR;
|
||||
this.size = 0;
|
||||
if (a !== undefined)
|
||||
this.from_buffer(a, at);
|
||||
}
|
||||
|
||||
SpiceLinkHeader.prototype =
|
||||
{
|
||||
from_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var dv = new SpiceDataView(a);
|
||||
this.magic = "";
|
||||
for (var i = 0; i < 4; i++)
|
||||
this.magic += String.fromCharCode(dv.getUint8(at + i));
|
||||
at += 4;
|
||||
|
||||
this.major_version = dv.getUint32(at, true); at += 4;
|
||||
this.minor_version = dv.getUint32(at, true); at += 4;
|
||||
this.size = dv.getUint32(at, true); at += 4;
|
||||
},
|
||||
|
||||
to_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var dv = new SpiceDataView(a);
|
||||
for (var i = 0; i < 4; i++)
|
||||
dv.setUint8(at + i, this.magic.charCodeAt(i));
|
||||
at += 4;
|
||||
|
||||
dv.setUint32(at, this.major_version, true); at += 4;
|
||||
dv.setUint32(at, this.minor_version, true); at += 4;
|
||||
dv.setUint32(at, this.size, true); at += 4;
|
||||
},
|
||||
buffer_size: function()
|
||||
{
|
||||
return 16;
|
||||
},
|
||||
}
|
||||
|
||||
function SpiceLinkMess(a, at)
|
||||
{
|
||||
this.connection_id = 0;
|
||||
this.channel_type = 0;
|
||||
this.channel_id = 0;
|
||||
this.common_caps = [];
|
||||
this.channel_caps = [];
|
||||
|
||||
if (a !== undefined)
|
||||
this.from_buffer(a, at);
|
||||
}
|
||||
|
||||
SpiceLinkMess.prototype =
|
||||
{
|
||||
from_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var i;
|
||||
var orig_at = at;
|
||||
var dv = new SpiceDataView(a);
|
||||
this.connection_id = dv.getUint32(at, true); at += 4;
|
||||
this.channel_type = dv.getUint8(at, true); at++;
|
||||
this.channel_id = dv.getUint8(at, true); at++;
|
||||
var num_common_caps = dv.getUint32(at, true); at += 4;
|
||||
var num_channel_caps = dv.getUint32(at, true); at += 4;
|
||||
var caps_offset = dv.getUint32(at, true); at += 4;
|
||||
|
||||
at = orig_at + caps_offset;
|
||||
this.common_caps = [];
|
||||
for (i = 0; i < num_common_caps; i++)
|
||||
{
|
||||
this.common_caps.unshift(dv.getUint32(at, true)); at += 4;
|
||||
}
|
||||
|
||||
this.channel_caps = [];
|
||||
for (i = 0; i < num_channel_caps; i++)
|
||||
{
|
||||
this.channel_caps.unshift(dv.getUint32(at, true)); at += 4;
|
||||
}
|
||||
},
|
||||
|
||||
to_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var orig_at = at;
|
||||
var i;
|
||||
var dv = new SpiceDataView(a);
|
||||
dv.setUint32(at, this.connection_id, true); at += 4;
|
||||
dv.setUint8(at, this.channel_type, true); at++;
|
||||
dv.setUint8(at, this.channel_id, true); at++;
|
||||
dv.setUint32(at, this.common_caps.length, true); at += 4;
|
||||
dv.setUint32(at, this.channel_caps.length, true); at += 4;
|
||||
dv.setUint32(at, (at - orig_at) + 4, true); at += 4;
|
||||
|
||||
for (i = 0; i < this.common_caps.length; i++)
|
||||
{
|
||||
dv.setUint32(at, this.common_caps[i], true); at += 4;
|
||||
}
|
||||
|
||||
for (i = 0; i < this.channel_caps.length; i++)
|
||||
{
|
||||
dv.setUint32(at, this.channel_caps[i], true); at += 4;
|
||||
}
|
||||
},
|
||||
buffer_size: function()
|
||||
{
|
||||
return 18 + (4 * this.common_caps.length) + (4 * this.channel_caps.length);
|
||||
}
|
||||
}
|
||||
|
||||
function SpiceLinkReply(a, at)
|
||||
{
|
||||
this.error = 0;
|
||||
this.pub_key = undefined;
|
||||
this.common_caps = [];
|
||||
this.channel_caps = [];
|
||||
|
||||
if (a !== undefined)
|
||||
this.from_buffer(a, at);
|
||||
}
|
||||
|
||||
SpiceLinkReply.prototype =
|
||||
{
|
||||
from_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var i;
|
||||
var orig_at = at;
|
||||
var dv = new SpiceDataView(a);
|
||||
this.error = dv.getUint32(at, true); at += 4;
|
||||
|
||||
this.pub_key = create_rsa_from_mb(a, at);
|
||||
at += SPICE_TICKET_PUBKEY_BYTES;
|
||||
|
||||
var num_common_caps = dv.getUint32(at, true); at += 4;
|
||||
var num_channel_caps = dv.getUint32(at, true); at += 4;
|
||||
var caps_offset = dv.getUint32(at, true); at += 4;
|
||||
|
||||
at = orig_at + caps_offset;
|
||||
this.common_caps = [];
|
||||
for (i = 0; i < num_common_caps; i++)
|
||||
{
|
||||
this.common_caps.unshift(dv.getUint32(at, true)); at += 4;
|
||||
}
|
||||
|
||||
this.channel_caps = [];
|
||||
for (i = 0; i < num_channel_caps; i++)
|
||||
{
|
||||
this.channel_caps.unshift(dv.getUint32(at, true)); at += 4;
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
function SpiceLinkAuthTicket(a, at)
|
||||
{
|
||||
this.auth_mechanism = 0;
|
||||
this.encrypted_data = undefined;
|
||||
}
|
||||
|
||||
SpiceLinkAuthTicket.prototype =
|
||||
{
|
||||
to_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var i;
|
||||
var dv = new SpiceDataView(a);
|
||||
dv.setUint32(at, this.auth_mechanism, true); at += 4;
|
||||
for (i = 0; i < SPICE_TICKET_KEY_PAIR_LENGTH / 8; i++)
|
||||
{
|
||||
if (this.encrypted_data && i < this.encrypted_data.length)
|
||||
dv.setUint8(at, this.encrypted_data[i], true);
|
||||
else
|
||||
dv.setUint8(at, 0, true);
|
||||
at++;
|
||||
}
|
||||
},
|
||||
buffer_size: function()
|
||||
{
|
||||
return 4 + (SPICE_TICKET_KEY_PAIR_LENGTH / 8);
|
||||
}
|
||||
}
|
||||
|
||||
function SpiceLinkAuthReply(a, at)
|
||||
{
|
||||
this.auth_code = 0;
|
||||
if (a !== undefined)
|
||||
this.from_buffer(a, at);
|
||||
}
|
||||
|
||||
SpiceLinkAuthReply.prototype =
|
||||
{
|
||||
from_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var dv = new SpiceDataView(a);
|
||||
this.auth_code = dv.getUint32(at, true); at += 4;
|
||||
},
|
||||
buffer_size: function()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
function SpiceMiniData(a, at)
|
||||
{
|
||||
this.type = 0;
|
||||
this.size = 0;
|
||||
this.data = undefined;
|
||||
if (a !== undefined)
|
||||
this.from_buffer(a, at);
|
||||
}
|
||||
|
||||
SpiceMiniData.prototype =
|
||||
{
|
||||
from_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var i;
|
||||
var dv = new SpiceDataView(a);
|
||||
this.type = dv.getUint16(at, true); at += 2;
|
||||
this.size = dv.getUint32(at, true); at += 4;
|
||||
if (a.byteLength > at)
|
||||
{
|
||||
this.data = a.slice(at);
|
||||
at += this.data.byteLength;
|
||||
}
|
||||
},
|
||||
to_buffer : function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var i;
|
||||
var dv = new SpiceDataView(a);
|
||||
dv.setUint16(at, this.type, true); at += 2;
|
||||
dv.setUint32(at, this.data ? this.data.byteLength : 0, true); at += 4;
|
||||
if (this.data && this.data.byteLength > 0)
|
||||
{
|
||||
var u8arr = new Uint8Array(this.data);
|
||||
for (i = 0; i < u8arr.length; i++, at++)
|
||||
dv.setUint8(at, u8arr[i], true);
|
||||
}
|
||||
},
|
||||
build_msg : function(in_type, extra)
|
||||
{
|
||||
this.type = in_type;
|
||||
this.size = extra.buffer_size();
|
||||
this.data = new ArrayBuffer(this.size);
|
||||
extra.to_buffer(this.data);
|
||||
},
|
||||
buffer_size: function()
|
||||
{
|
||||
if (this.data)
|
||||
return 6 + this.data.byteLength;
|
||||
else
|
||||
return 6;
|
||||
},
|
||||
}
|
||||
|
||||
function SpiceMsgChannels(a, at)
|
||||
{
|
||||
this.num_of_channels = 0;
|
||||
this.channels = [];
|
||||
if (a !== undefined)
|
||||
this.from_buffer(a, at);
|
||||
}
|
||||
|
||||
SpiceMsgChannels.prototype =
|
||||
{
|
||||
from_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var i;
|
||||
var dv = new SpiceDataView(a);
|
||||
this.num_of_channels = dv.getUint32(at, true); at += 4;
|
||||
for (i = 0; i < this.num_of_channels; i++)
|
||||
{
|
||||
var chan = new SpiceChannelId();
|
||||
at = chan.from_dv(dv, at, a);
|
||||
this.channels.push(chan);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
function SpiceMsgMainInit(a, at)
|
||||
{
|
||||
this.from_buffer(a, at);
|
||||
}
|
||||
|
||||
SpiceMsgMainInit.prototype =
|
||||
{
|
||||
from_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var dv = new SpiceDataView(a);
|
||||
this.session_id = dv.getUint32(at, true); at += 4;
|
||||
this.display_channels_hint = dv.getUint32(at, true); at += 4;
|
||||
this.supported_mouse_modes = dv.getUint32(at, true); at += 4;
|
||||
this.current_mouse_mode = dv.getUint32(at, true); at += 4;
|
||||
this.agent_connected = dv.getUint32(at, true); at += 4;
|
||||
this.agent_tokens = dv.getUint32(at, true); at += 4;
|
||||
this.multi_media_time = dv.getUint32(at, true); at += 4;
|
||||
this.ram_hint = dv.getUint32(at, true); at += 4;
|
||||
},
|
||||
}
|
||||
|
||||
function SpiceMsgMainMouseMode(a, at)
|
||||
{
|
||||
this.from_buffer(a, at);
|
||||
}
|
||||
|
||||
SpiceMsgMainMouseMode.prototype =
|
||||
{
|
||||
from_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var dv = new SpiceDataView(a);
|
||||
this.supported_modes = dv.getUint16(at, true); at += 2;
|
||||
this.current_mode = dv.getUint16(at, true); at += 2;
|
||||
},
|
||||
}
|
||||
|
||||
function SpiceMsgSetAck(a, at)
|
||||
{
|
||||
this.from_buffer(a, at);
|
||||
}
|
||||
|
||||
SpiceMsgSetAck.prototype =
|
||||
{
|
||||
from_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var dv = new SpiceDataView(a);
|
||||
this.generation = dv.getUint32(at, true); at += 4;
|
||||
this.window = dv.getUint32(at, true); at += 4;
|
||||
},
|
||||
}
|
||||
|
||||
function SpiceMsgcAckSync(ack)
|
||||
{
|
||||
this.generation = ack.generation;
|
||||
}
|
||||
|
||||
SpiceMsgcAckSync.prototype =
|
||||
{
|
||||
to_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var dv = new SpiceDataView(a);
|
||||
dv.setUint32(at, this.generation, true); at += 4;
|
||||
},
|
||||
buffer_size: function()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
function SpiceMsgcMainMouseModeRequest(mode)
|
||||
{
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
SpiceMsgcMainMouseModeRequest.prototype =
|
||||
{
|
||||
to_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var dv = new SpiceDataView(a);
|
||||
dv.setUint16(at, this.mode, true); at += 2;
|
||||
},
|
||||
buffer_size: function()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
function SpiceMsgNotify(a, at)
|
||||
{
|
||||
this.from_buffer(a, at);
|
||||
}
|
||||
|
||||
SpiceMsgNotify.prototype =
|
||||
{
|
||||
from_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var i;
|
||||
var dv = new SpiceDataView(a);
|
||||
this.time_stamp = [];
|
||||
this.time_stamp[0] = dv.getUint32(at, true); at += 4;
|
||||
this.time_stamp[1] = dv.getUint32(at, true); at += 4;
|
||||
this.severity = dv.getUint32(at, true); at += 4;
|
||||
this.visibility = dv.getUint32(at, true); at += 4;
|
||||
this.what = dv.getUint32(at, true); at += 4;
|
||||
this.message_len = dv.getUint32(at, true); at += 4;
|
||||
this.message = "";
|
||||
for (i = 0; i < this.message_len; i++)
|
||||
{
|
||||
var c = dv.getUint8(at, true); at++;
|
||||
this.message += String.fromCharCode(c);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
function SpiceMsgcDisplayInit()
|
||||
{
|
||||
this.pixmap_cache_id = 1;
|
||||
this.glz_dictionary_id = 0;
|
||||
this.pixmap_cache_size = 10 * 1024 * 1024;
|
||||
this.glz_dictionary_window_size = 0;
|
||||
}
|
||||
|
||||
SpiceMsgcDisplayInit.prototype =
|
||||
{
|
||||
to_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var dv = new SpiceDataView(a);
|
||||
dv.setUint8(at, this.pixmap_cache_id, true); at++;
|
||||
dv.setUint32(at, 0, true); at += 4;
|
||||
dv.setUint32(at, this.pixmap_cache_size, true); at += 4;
|
||||
dv.setUint8(at, this.glz_dictionary_id, true); at++;
|
||||
dv.setUint32(at, this.glz_dictionary_window_size, true); at += 4;
|
||||
},
|
||||
buffer_size: function()
|
||||
{
|
||||
return 14;
|
||||
}
|
||||
}
|
||||
|
||||
function SpiceMsgDisplayBase()
|
||||
{
|
||||
}
|
||||
|
||||
SpiceMsgDisplayBase.prototype =
|
||||
{
|
||||
from_dv : function(dv, at, mb)
|
||||
{
|
||||
this.surface_id = dv.getUint32(at, true); at += 4;
|
||||
this.box = new SpiceRect;
|
||||
at = this.box.from_dv(dv, at, mb);
|
||||
this.clip = new SpiceClip;
|
||||
return this.clip.from_dv(dv, at, mb);
|
||||
},
|
||||
}
|
||||
|
||||
function SpiceMsgDisplayDrawCopy(a, at)
|
||||
{
|
||||
this.from_buffer(a, at);
|
||||
}
|
||||
|
||||
SpiceMsgDisplayDrawCopy.prototype =
|
||||
{
|
||||
from_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var dv = new SpiceDataView(a);
|
||||
this.base = new SpiceMsgDisplayBase;
|
||||
at = this.base.from_dv(dv, at, a);
|
||||
this.data = new SpiceCopy;
|
||||
return this.data.from_dv(dv, at, a);
|
||||
},
|
||||
}
|
||||
|
||||
function SpiceMsgDisplayDrawFill(a, at)
|
||||
{
|
||||
this.from_buffer(a, at);
|
||||
}
|
||||
|
||||
SpiceMsgDisplayDrawFill.prototype =
|
||||
{
|
||||
from_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var dv = new SpiceDataView(a);
|
||||
this.base = new SpiceMsgDisplayBase;
|
||||
at = this.base.from_dv(dv, at, a);
|
||||
this.data = new SpiceFill;
|
||||
return this.data.from_dv(dv, at, a);
|
||||
},
|
||||
}
|
||||
|
||||
function SpiceMsgDisplayCopyBits(a, at)
|
||||
{
|
||||
this.from_buffer(a, at);
|
||||
}
|
||||
|
||||
SpiceMsgDisplayCopyBits.prototype =
|
||||
{
|
||||
from_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var dv = new SpiceDataView(a);
|
||||
this.base = new SpiceMsgDisplayBase;
|
||||
at = this.base.from_dv(dv, at, a);
|
||||
this.src_pos = new SpicePoint;
|
||||
return this.src_pos.from_dv(dv, at, a);
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
function SpiceMsgSurfaceCreate(a, at)
|
||||
{
|
||||
this.from_buffer(a, at);
|
||||
}
|
||||
|
||||
SpiceMsgSurfaceCreate.prototype =
|
||||
{
|
||||
from_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var dv = new SpiceDataView(a);
|
||||
this.surface = new SpiceSurface;
|
||||
return this.surface.from_dv(dv, at, a);
|
||||
},
|
||||
}
|
||||
|
||||
function SpiceMsgSurfaceDestroy(a, at)
|
||||
{
|
||||
this.from_buffer(a, at);
|
||||
}
|
||||
|
||||
SpiceMsgSurfaceDestroy.prototype =
|
||||
{
|
||||
from_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var dv = new SpiceDataView(a);
|
||||
this.surface_id = dv.getUint32(at, true); at += 4;
|
||||
},
|
||||
}
|
||||
|
||||
function SpiceMsgInputsInit(a, at)
|
||||
{
|
||||
this.from_buffer(a, at);
|
||||
}
|
||||
|
||||
SpiceMsgInputsInit.prototype =
|
||||
{
|
||||
from_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var dv = new SpiceDataView(a);
|
||||
this.keyboard_modifiers = dv.getUint16(at, true); at += 2;
|
||||
return at;
|
||||
},
|
||||
}
|
||||
|
||||
function SpiceMsgInputsKeyModifiers(a, at)
|
||||
{
|
||||
this.from_buffer(a, at);
|
||||
}
|
||||
|
||||
SpiceMsgInputsKeyModifiers.prototype =
|
||||
{
|
||||
from_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var dv = new SpiceDataView(a);
|
||||
this.keyboard_modifiers = dv.getUint16(at, true); at += 2;
|
||||
return at;
|
||||
},
|
||||
}
|
||||
|
||||
function SpiceMsgCursorInit(a, at)
|
||||
{
|
||||
this.from_buffer(a, at);
|
||||
}
|
||||
|
||||
SpiceMsgCursorInit.prototype =
|
||||
{
|
||||
from_buffer: function(a, at, mb)
|
||||
{
|
||||
at = at || 0;
|
||||
var dv = new SpiceDataView(a);
|
||||
this.position = new SpicePoint16;
|
||||
at = this.position.from_dv(dv, at, mb);
|
||||
this.trail_length = dv.getUint16(at, true); at += 2;
|
||||
this.trail_frequency = dv.getUint16(at, true); at += 2;
|
||||
this.visible = dv.getUint8(at, true); at ++;
|
||||
this.cursor = new SpiceCursor;
|
||||
return this.cursor.from_dv(dv, at, a);
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
function SpiceMsgCursorSet(a, at)
|
||||
{
|
||||
this.from_buffer(a, at);
|
||||
}
|
||||
|
||||
SpiceMsgCursorSet.prototype =
|
||||
{
|
||||
from_buffer: function(a, at, mb)
|
||||
{
|
||||
at = at || 0;
|
||||
var dv = new SpiceDataView(a);
|
||||
this.position = new SpicePoint16;
|
||||
at = this.position.from_dv(dv, at, mb);
|
||||
this.visible = dv.getUint8(at, true); at ++;
|
||||
this.cursor = new SpiceCursor;
|
||||
return this.cursor.from_dv(dv, at, a);
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
function SpiceMsgcMousePosition(sc, e)
|
||||
{
|
||||
// FIXME - figure out how to correctly compute display_id
|
||||
this.display_id = 0;
|
||||
this.buttons_state = sc.buttons_state;
|
||||
if (e)
|
||||
{
|
||||
this.x = e.clientX - sc.display.surfaces[sc.display.primary_surface].canvas.offsetLeft;
|
||||
this.y = e.clientY - sc.display.surfaces[sc.display.primary_surface].canvas.offsetTop;
|
||||
sc.mousex = this.x;
|
||||
sc.mousey = this.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.x = this.y = this.buttons_state = 0;
|
||||
}
|
||||
}
|
||||
|
||||
SpiceMsgcMousePosition.prototype =
|
||||
{
|
||||
to_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var dv = new SpiceDataView(a);
|
||||
dv.setUint32(at, this.x, true); at += 4;
|
||||
dv.setUint32(at, this.y, true); at += 4;
|
||||
dv.setUint16(at, this.buttons_state, true); at += 2;
|
||||
dv.setUint8(at, this.display_id, true); at += 1;
|
||||
return at;
|
||||
},
|
||||
buffer_size: function()
|
||||
{
|
||||
return 11;
|
||||
}
|
||||
}
|
||||
|
||||
function SpiceMsgcMouseMotion(sc, e)
|
||||
{
|
||||
// FIXME - figure out how to correctly compute display_id
|
||||
this.display_id = 0;
|
||||
this.buttons_state = sc.buttons_state;
|
||||
if (e)
|
||||
{
|
||||
this.x = e.clientX - sc.display.surfaces[sc.display.primary_surface].canvas.offsetLeft;
|
||||
this.y = e.clientY - sc.display.surfaces[sc.display.primary_surface].canvas.offsetTop;
|
||||
|
||||
if (sc.mousex !== undefined)
|
||||
{
|
||||
this.x -= sc.mousex;
|
||||
this.y -= sc.mousey;
|
||||
}
|
||||
sc.mousex = e.clientX - sc.display.surfaces[sc.display.primary_surface].canvas.offsetLeft;
|
||||
sc.mousey = e.clientY - sc.display.surfaces[sc.display.primary_surface].canvas.offsetTop;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.x = this.y = this.buttons_state = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Use the same functions as for MousePosition */
|
||||
SpiceMsgcMouseMotion.prototype.to_buffer = SpiceMsgcMousePosition.prototype.to_buffer;
|
||||
SpiceMsgcMouseMotion.prototype.buffer_size = SpiceMsgcMousePosition.prototype.buffer_size;
|
||||
|
||||
function SpiceMsgcMousePress(sc, e)
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
this.button = e.button + 1;
|
||||
this.buttons_state = 1 << e.button;
|
||||
sc.buttons_state = this.buttons_state;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.button = SPICE_MOUSE_BUTTON_LEFT;
|
||||
this.buttons_state = SPICE_MOUSE_BUTTON_MASK_LEFT;
|
||||
}
|
||||
}
|
||||
|
||||
SpiceMsgcMousePress.prototype =
|
||||
{
|
||||
to_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var dv = new SpiceDataView(a);
|
||||
dv.setUint8(at, this.button, true); at ++;
|
||||
dv.setUint16(at, this.buttons_state, true); at += 2;
|
||||
return at;
|
||||
},
|
||||
buffer_size: function()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
function SpiceMsgcMouseRelease(sc, e)
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
this.button = e.button + 1;
|
||||
this.buttons_state = 0;
|
||||
sc.buttons_state = this.buttons_state;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.button = SPICE_MOUSE_BUTTON_LEFT;
|
||||
this.buttons_state = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Use the same functions as for MousePress */
|
||||
SpiceMsgcMouseRelease.prototype.to_buffer = SpiceMsgcMousePress.prototype.to_buffer;
|
||||
SpiceMsgcMouseRelease.prototype.buffer_size = SpiceMsgcMousePress.prototype.buffer_size;
|
||||
|
||||
|
||||
function SpiceMsgcKeyDown(e)
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
this.code = keycode_to_start_scan(e.keyCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.code = 0;
|
||||
}
|
||||
}
|
||||
|
||||
SpiceMsgcKeyDown.prototype =
|
||||
{
|
||||
to_buffer: function(a, at)
|
||||
{
|
||||
at = at || 0;
|
||||
var dv = new SpiceDataView(a);
|
||||
dv.setUint32(at, this.code, true); at += 4;
|
||||
return at;
|
||||
},
|
||||
buffer_size: function()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
function SpiceMsgcKeyUp(e)
|
||||
{
|
||||
if (e)
|
||||
{
|
||||
this.code = keycode_to_end_scan(e.keyCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.code = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Use the same functions as for KeyDown */
|
||||
SpiceMsgcKeyUp.prototype.to_buffer = SpiceMsgcKeyDown.prototype.to_buffer;
|
||||
SpiceMsgcKeyUp.prototype.buffer_size = SpiceMsgcKeyDown.prototype.buffer_size;
|
455
spicetype.js
Normal file
455
spicetype.js
Normal file
@ -0,0 +1,455 @@
|
||||
"use strict";
|
||||
/*
|
||||
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||
|
||||
This file is part of spice-html5.
|
||||
|
||||
spice-html5 is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
spice-html5 is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
** Spice types
|
||||
** This file contains classes for common spice types.
|
||||
** Generally, they are used as helpers in reading and writing messages
|
||||
** to and from the server.
|
||||
**--------------------------------------------------------------------------*/
|
||||
|
||||
function SpiceChannelId()
|
||||
{
|
||||
}
|
||||
SpiceChannelId.prototype =
|
||||
{
|
||||
from_dv: function(dv, at, mb)
|
||||
{
|
||||
this.type = dv.getUint8(at, true); at ++;
|
||||
this.id = dv.getUint8(at, true); at ++;
|
||||
return at;
|
||||
},
|
||||
}
|
||||
|
||||
function SpiceRect()
|
||||
{
|
||||
}
|
||||
|
||||
SpiceRect.prototype =
|
||||
{
|
||||
from_dv: function(dv, at, mb)
|
||||
{
|
||||
this.top = dv.getUint32(at, true); at += 4;
|
||||
this.left = dv.getUint32(at, true); at += 4;
|
||||
this.bottom = dv.getUint32(at, true); at += 4;
|
||||
this.right = dv.getUint32(at, true); at += 4;
|
||||
return at;
|
||||
},
|
||||
is_same_size : function(r)
|
||||
{
|
||||
if ((this.bottom - this.top) == (r.bottom - r.top) &&
|
||||
(this.right - this.left) == (r.right - r.left) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
},
|
||||
}
|
||||
|
||||
function SpiceClipRects()
|
||||
{
|
||||
}
|
||||
|
||||
SpiceClipRects.prototype =
|
||||
{
|
||||
from_dv: function(dv, at, mb)
|
||||
{
|
||||
var i;
|
||||
this.num_rects = dv.getUint32(at, true); at += 4;
|
||||
if (this.num_rects > 0)
|
||||
this.rects = [];
|
||||
for (i = 0; i < this.num_rects; i++)
|
||||
{
|
||||
this.rects[i] = new SpiceRect();
|
||||
at = this.rects[i].from_dv(dv, at, mb);
|
||||
}
|
||||
return at;
|
||||
},
|
||||
}
|
||||
|
||||
function SpiceClip()
|
||||
{
|
||||
}
|
||||
|
||||
SpiceClip.prototype =
|
||||
{
|
||||
from_dv: function(dv, at, mb)
|
||||
{
|
||||
this.type = dv.getUint8(at, true); at ++;
|
||||
if (this.type == SPICE_CLIP_TYPE_RECTS)
|
||||
{
|
||||
this.rects = new SpiceClipRects();
|
||||
at = this.rects.from_dv(dv, at, mb);
|
||||
}
|
||||
return at;
|
||||
},
|
||||
}
|
||||
|
||||
function SpiceImageDescriptor()
|
||||
{
|
||||
}
|
||||
|
||||
SpiceImageDescriptor.prototype =
|
||||
{
|
||||
from_dv: function(dv, at, mb)
|
||||
{
|
||||
this.id = dv.getUint32(at, true); at += 4;
|
||||
this.id += (dv.getUint32(at, true) << 32); at += 4;
|
||||
this.type = dv.getUint8(at, true); at ++;
|
||||
this.flags = dv.getUint8(at, true); at ++;
|
||||
this.width = dv.getUint32(at, true); at += 4;
|
||||
this.height= dv.getUint32(at, true); at += 4;
|
||||
return at;
|
||||
},
|
||||
}
|
||||
|
||||
function SpicePalette()
|
||||
{
|
||||
}
|
||||
|
||||
SpicePalette.prototype =
|
||||
{
|
||||
from_dv: function(dv, at, mb)
|
||||
{
|
||||
var i;
|
||||
this.unique = [];
|
||||
this.unique[0] = dv.getUint32(at, true); at += 4;
|
||||
this.unique[1] = dv.getUint32(at, true); at += 4;
|
||||
this.num_ents = dv.getUint16(at, true); at += 2;
|
||||
this.ents = [];
|
||||
for (i = 0; i < this.num_ents; i++)
|
||||
{
|
||||
this.ents[i] = dv.getUint32(at, true); at += 4;
|
||||
}
|
||||
return at;
|
||||
},
|
||||
}
|
||||
|
||||
function SpiceBitmap()
|
||||
{
|
||||
}
|
||||
|
||||
SpiceBitmap.prototype =
|
||||
{
|
||||
from_dv: function(dv, at, mb)
|
||||
{
|
||||
this.format = dv.getUint8(at, true); at++;
|
||||
this.flags = dv.getUint8(at, true); at++;
|
||||
this.x = dv.getUint32(at, true); at += 4;
|
||||
this.y = dv.getUint32(at, true); at += 4;
|
||||
this.stride = dv.getUint32(at, true); at += 4;
|
||||
if (this.flags & SPICE_BITMAP_FLAGS_PAL_FROM_CACHE)
|
||||
{
|
||||
this.palette_id = [];
|
||||
this.palette_id[0] = dv.getUint32(at, true); at += 4;
|
||||
this.palette_id[1] = dv.getUint32(at, true); at += 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
var offset = dv.getUint32(at, true); at += 4;
|
||||
if (offset == 0)
|
||||
this.palette = null;
|
||||
else
|
||||
{
|
||||
this.palette = new SpicePalette;
|
||||
this.palette.from_dv(dv, offset, mb);
|
||||
}
|
||||
}
|
||||
// FIXME - should probably constrain this to the offset
|
||||
// of palette, if non zero
|
||||
this.data = mb.slice(at);
|
||||
at += this.data.byteLength;
|
||||
return at;
|
||||
},
|
||||
}
|
||||
|
||||
function SpiceImage()
|
||||
{
|
||||
}
|
||||
|
||||
SpiceImage.prototype =
|
||||
{
|
||||
from_dv: function(dv, at, mb)
|
||||
{
|
||||
this.descriptor = new SpiceImageDescriptor;
|
||||
at = this.descriptor.from_dv(dv, at, mb);
|
||||
|
||||
if (this.descriptor.type == SPICE_IMAGE_TYPE_LZ_RGB)
|
||||
{
|
||||
this.lz_rgb = new Object();
|
||||
this.lz_rgb.length = dv.getUint32(at, true); at += 4;
|
||||
var initial_at = at;
|
||||
this.lz_rgb.magic = "";
|
||||
for (var i = 3; i >= 0; i--)
|
||||
this.lz_rgb.magic += String.fromCharCode(dv.getUint8(at + i));
|
||||
at += 4;
|
||||
|
||||
// NOTE: The endian change is *correct*
|
||||
this.lz_rgb.version = dv.getUint32(at); at += 4;
|
||||
this.lz_rgb.type = dv.getUint32(at); at += 4;
|
||||
this.lz_rgb.width = dv.getUint32(at); at += 4;
|
||||
this.lz_rgb.height = dv.getUint32(at); at += 4;
|
||||
this.lz_rgb.stride = dv.getUint32(at); at += 4;
|
||||
this.lz_rgb.top_down = dv.getUint32(at); at += 4;
|
||||
|
||||
var header_size = at - initial_at;
|
||||
|
||||
this.lz_rgb.data = mb.slice(at, this.lz_rgb.length + at - header_size);
|
||||
at += this.lz_rgb.data.byteLength;
|
||||
|
||||
}
|
||||
|
||||
if (this.descriptor.type == SPICE_IMAGE_TYPE_BITMAP)
|
||||
{
|
||||
this.bitmap = new SpiceBitmap;
|
||||
at = this.bitmap.from_dv(dv, at, mb);
|
||||
}
|
||||
|
||||
if (this.descriptor.type == SPICE_IMAGE_TYPE_SURFACE)
|
||||
{
|
||||
this.surface_id = dv.getUint32(at, true); at += 4;
|
||||
}
|
||||
|
||||
if (this.descriptor.type == SPICE_IMAGE_TYPE_JPEG)
|
||||
{
|
||||
this.jpeg = new Object;
|
||||
this.jpeg.data_size = dv.getUint32(at, true); at += 4;
|
||||
this.jpeg.data = mb.slice(at);
|
||||
at += this.jpeg.data.byteLength;
|
||||
}
|
||||
|
||||
if (this.descriptor.type == SPICE_IMAGE_TYPE_QUIC)
|
||||
{
|
||||
var tmparr = [];
|
||||
var i;
|
||||
this.quicr_length = dv.getUint32(at, true); at += 4;
|
||||
var qdv = new Uint8Array(mb.slice(at));
|
||||
for (i = 0; i < qdv.length; i++)
|
||||
tmparr[i] = qdv[i];
|
||||
this.quic = getQuic(tmparr);
|
||||
at += qdv.length;
|
||||
}
|
||||
return at;
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
function SpiceQMask()
|
||||
{
|
||||
}
|
||||
|
||||
SpiceQMask.prototype =
|
||||
{
|
||||
from_dv: function(dv, at, mb)
|
||||
{
|
||||
this.flags = dv.getUint8(at, true); at++;
|
||||
this.pos = new SpicePoint;
|
||||
at = this.pos.from_dv(dv, at, mb);
|
||||
var offset = dv.getUint32(at, true); at += 4;
|
||||
if (offset == 0)
|
||||
{
|
||||
this.bitmap = null;
|
||||
return at;
|
||||
}
|
||||
|
||||
this.bitmap = new SpiceImage;
|
||||
return this.bitmap.from_dv(dv, offset, mb);
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
function SpicePattern()
|
||||
{
|
||||
}
|
||||
|
||||
SpicePattern.prototype =
|
||||
{
|
||||
from_dv: function(dv, at, mb)
|
||||
{
|
||||
var offset = dv.getUint32(at, true); at += 4;
|
||||
if (offset == 0)
|
||||
{
|
||||
this.pat = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.pat = new SpiceImage;
|
||||
this.pat.from_dv(dv, offset, mb);
|
||||
}
|
||||
|
||||
this.pos = new SpicePoint;
|
||||
return this.pos.from_dv(dv, at, mb);
|
||||
}
|
||||
}
|
||||
|
||||
function SpiceBrush()
|
||||
{
|
||||
}
|
||||
|
||||
SpiceBrush.prototype =
|
||||
{
|
||||
from_dv: function(dv, at, mb)
|
||||
{
|
||||
this.type = dv.getUint8(at, true); at ++;
|
||||
if (this.type == SPICE_BRUSH_TYPE_SOLID)
|
||||
{
|
||||
this.color = dv.getUint32(at, true); at += 4;
|
||||
}
|
||||
else if (this.type == SPICE_BRUSH_TYPE_PATTERN)
|
||||
{
|
||||
this.pattern = new SpicePattern;
|
||||
at = this.pattern.from_dv(dv, at, mb);
|
||||
}
|
||||
return at;
|
||||
},
|
||||
}
|
||||
|
||||
function SpiceFill()
|
||||
{
|
||||
}
|
||||
|
||||
SpiceFill.prototype =
|
||||
{
|
||||
from_dv: function(dv, at, mb)
|
||||
{
|
||||
this.brush = new SpiceBrush;
|
||||
at = this.brush.from_dv(dv, at, mb);
|
||||
this.rop_descriptor = dv.getUint16(at, true); at += 2;
|
||||
this.mask = new SpiceQMask;
|
||||
return this.mask.from_dv(dv, at, mb);
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
function SpiceCopy()
|
||||
{
|
||||
}
|
||||
|
||||
SpiceCopy.prototype =
|
||||
{
|
||||
from_dv: function(dv, at, mb)
|
||||
{
|
||||
var offset = dv.getUint32(at, true); at += 4;
|
||||
if (offset == 0)
|
||||
{
|
||||
this.src_bitmap = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.src_bitmap = new SpiceImage;
|
||||
this.src_bitmap.from_dv(dv, offset, mb);
|
||||
}
|
||||
this.src_area = new SpiceRect;
|
||||
at = this.src_area.from_dv(dv, at, mb);
|
||||
this.rop_descriptor = dv.getUint16(at, true); at += 2;
|
||||
this.scale_mode = dv.getUint8(at, true); at ++;
|
||||
this.mask = new SpiceQMask;
|
||||
return this.mask.from_dv(dv, at, mb);
|
||||
},
|
||||
}
|
||||
|
||||
function SpicePoint16()
|
||||
{
|
||||
}
|
||||
|
||||
SpicePoint16.prototype =
|
||||
{
|
||||
from_dv: function(dv, at, mb)
|
||||
{
|
||||
this.x = dv.getUint16(at, true); at += 2;
|
||||
this.y = dv.getUint16(at, true); at += 2;
|
||||
return at;
|
||||
},
|
||||
}
|
||||
|
||||
function SpicePoint()
|
||||
{
|
||||
}
|
||||
|
||||
SpicePoint.prototype =
|
||||
{
|
||||
from_dv: function(dv, at, mb)
|
||||
{
|
||||
this.x = dv.getUint32(at, true); at += 4;
|
||||
this.y = dv.getUint32(at, true); at += 4;
|
||||
return at;
|
||||
},
|
||||
}
|
||||
|
||||
function SpiceCursorHeader()
|
||||
{
|
||||
}
|
||||
|
||||
SpiceCursorHeader.prototype =
|
||||
{
|
||||
from_dv: function(dv, at, mb)
|
||||
{
|
||||
this.unique = [];
|
||||
this.unique[0] = dv.getUint32(at, true); at += 4;
|
||||
this.unique[1] = dv.getUint32(at, true); at += 4;
|
||||
this.type = dv.getUint8(at, true); at ++;
|
||||
this.width = dv.getUint16(at, true); at += 2;
|
||||
this.height = dv.getUint16(at, true); at += 2;
|
||||
this.hot_spot_x = dv.getUint16(at, true); at += 2;
|
||||
this.hot_spot_y = dv.getUint16(at, true); at += 2;
|
||||
return at;
|
||||
},
|
||||
}
|
||||
|
||||
function SpiceCursor()
|
||||
{
|
||||
}
|
||||
|
||||
SpiceCursor.prototype =
|
||||
{
|
||||
from_dv: function(dv, at, mb)
|
||||
{
|
||||
this.flags = dv.getUint16(at, true); at += 2;
|
||||
if (this.flags & SPICE_CURSOR_FLAGS_NONE)
|
||||
this.header = null;
|
||||
else
|
||||
{
|
||||
this.header = new SpiceCursorHeader;
|
||||
at = this.header.from_dv(dv, at, mb);
|
||||
this.data = mb.slice(at);
|
||||
at += this.data.byteLength;
|
||||
}
|
||||
return at;
|
||||
},
|
||||
}
|
||||
|
||||
function SpiceSurface()
|
||||
{
|
||||
}
|
||||
|
||||
SpiceSurface.prototype =
|
||||
{
|
||||
from_dv: function(dv, at, mb)
|
||||
{
|
||||
this.surface_id = dv.getUint32(at, true); at += 4;
|
||||
this.width = dv.getUint32(at, true); at += 4;
|
||||
this.height = dv.getUint32(at, true); at += 4;
|
||||
this.format = dv.getUint32(at, true); at += 4;
|
||||
this.flags = dv.getUint32(at, true); at += 4;
|
||||
return at;
|
||||
},
|
||||
}
|
||||
|
||||
/* FIXME - SpiceImage types lz_plt, jpeg, zlib_glz, and jpeg_alpha are
|
||||
completely unimplemented */
|
589
thirdparty/jsbn.js
vendored
Normal file
589
thirdparty/jsbn.js
vendored
Normal file
@ -0,0 +1,589 @@
|
||||
// Downloaded from http://www-cs-students.stanford.edu/~tjw/jsbn/ by Jeremy White on 6/1/2012
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003-2005 Tom Wu
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
|
||||
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF
|
||||
* THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT
|
||||
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* In addition, the following condition applies:
|
||||
*
|
||||
* All redistributions must retain an intact copy of this copyright notice
|
||||
* and disclaimer.
|
||||
*/
|
||||
|
||||
|
||||
// Basic JavaScript BN library - subset useful for RSA encryption.
|
||||
|
||||
// Bits per digit
|
||||
var dbits;
|
||||
|
||||
// JavaScript engine analysis
|
||||
var canary = 0xdeadbeefcafe;
|
||||
var j_lm = ((canary&0xffffff)==0xefcafe);
|
||||
|
||||
// (public) Constructor
|
||||
function BigInteger(a,b,c) {
|
||||
if(a != null)
|
||||
if("number" == typeof a) this.fromNumber(a,b,c);
|
||||
else if(b == null && "string" != typeof a) this.fromString(a,256);
|
||||
else this.fromString(a,b);
|
||||
}
|
||||
|
||||
// return new, unset BigInteger
|
||||
function nbi() { return new BigInteger(null); }
|
||||
|
||||
// am: Compute w_j += (x*this_i), propagate carries,
|
||||
// c is initial carry, returns final carry.
|
||||
// c < 3*dvalue, x < 2*dvalue, this_i < dvalue
|
||||
// We need to select the fastest one that works in this environment.
|
||||
|
||||
// am1: use a single mult and divide to get the high bits,
|
||||
// max digit bits should be 26 because
|
||||
// max internal value = 2*dvalue^2-2*dvalue (< 2^53)
|
||||
function am1(i,x,w,j,c,n) {
|
||||
while(--n >= 0) {
|
||||
var v = x*this[i++]+w[j]+c;
|
||||
c = Math.floor(v/0x4000000);
|
||||
w[j++] = v&0x3ffffff;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
// am2 avoids a big mult-and-extract completely.
|
||||
// Max digit bits should be <= 30 because we do bitwise ops
|
||||
// on values up to 2*hdvalue^2-hdvalue-1 (< 2^31)
|
||||
function am2(i,x,w,j,c,n) {
|
||||
var xl = x&0x7fff, xh = x>>15;
|
||||
while(--n >= 0) {
|
||||
var l = this[i]&0x7fff;
|
||||
var h = this[i++]>>15;
|
||||
var m = xh*l+h*xl;
|
||||
l = xl*l+((m&0x7fff)<<15)+w[j]+(c&0x3fffffff);
|
||||
c = (l>>>30)+(m>>>15)+xh*h+(c>>>30);
|
||||
w[j++] = l&0x3fffffff;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
// Alternately, set max digit bits to 28 since some
|
||||
// browsers slow down when dealing with 32-bit numbers.
|
||||
function am3(i,x,w,j,c,n) {
|
||||
var xl = x&0x3fff, xh = x>>14;
|
||||
while(--n >= 0) {
|
||||
var l = this[i]&0x3fff;
|
||||
var h = this[i++]>>14;
|
||||
var m = xh*l+h*xl;
|
||||
l = xl*l+((m&0x3fff)<<14)+w[j]+c;
|
||||
c = (l>>28)+(m>>14)+xh*h;
|
||||
w[j++] = l&0xfffffff;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
if(j_lm && (navigator.appName == "Microsoft Internet Explorer")) {
|
||||
BigInteger.prototype.am = am2;
|
||||
dbits = 30;
|
||||
}
|
||||
else if(j_lm && (navigator.appName != "Netscape")) {
|
||||
BigInteger.prototype.am = am1;
|
||||
dbits = 26;
|
||||
}
|
||||
else { // Mozilla/Netscape seems to prefer am3
|
||||
BigInteger.prototype.am = am3;
|
||||
dbits = 28;
|
||||
}
|
||||
|
||||
BigInteger.prototype.DB = dbits;
|
||||
BigInteger.prototype.DM = ((1<<dbits)-1);
|
||||
BigInteger.prototype.DV = (1<<dbits);
|
||||
|
||||
var BI_FP = 52;
|
||||
BigInteger.prototype.FV = Math.pow(2,BI_FP);
|
||||
BigInteger.prototype.F1 = BI_FP-dbits;
|
||||
BigInteger.prototype.F2 = 2*dbits-BI_FP;
|
||||
|
||||
// Digit conversions
|
||||
var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
var BI_RC = new Array();
|
||||
var rr,vv;
|
||||
rr = "0".charCodeAt(0);
|
||||
for(vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv;
|
||||
rr = "a".charCodeAt(0);
|
||||
for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
|
||||
rr = "A".charCodeAt(0);
|
||||
for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
|
||||
|
||||
function int2char(n) { return BI_RM.charAt(n); }
|
||||
function intAt(s,i) {
|
||||
var c = BI_RC[s.charCodeAt(i)];
|
||||
return (c==null)?-1:c;
|
||||
}
|
||||
|
||||
// (protected) copy this to r
|
||||
function bnpCopyTo(r) {
|
||||
for(var i = this.t-1; i >= 0; --i) r[i] = this[i];
|
||||
r.t = this.t;
|
||||
r.s = this.s;
|
||||
}
|
||||
|
||||
// (protected) set from integer value x, -DV <= x < DV
|
||||
function bnpFromInt(x) {
|
||||
this.t = 1;
|
||||
this.s = (x<0)?-1:0;
|
||||
if(x > 0) this[0] = x;
|
||||
else if(x < -1) this[0] = x+DV;
|
||||
else this.t = 0;
|
||||
}
|
||||
|
||||
// return bigint initialized to value
|
||||
function nbv(i) { var r = nbi(); r.fromInt(i); return r; }
|
||||
|
||||
// (protected) set from string and radix
|
||||
function bnpFromString(s,b) {
|
||||
var k;
|
||||
if(b == 16) k = 4;
|
||||
else if(b == 8) k = 3;
|
||||
else if(b == 256) k = 8; // byte array
|
||||
else if(b == 2) k = 1;
|
||||
else if(b == 32) k = 5;
|
||||
else if(b == 4) k = 2;
|
||||
else { this.fromRadix(s,b); return; }
|
||||
this.t = 0;
|
||||
this.s = 0;
|
||||
var i = s.length, mi = false, sh = 0;
|
||||
while(--i >= 0) {
|
||||
var x = (k==8)?s[i]&0xff:intAt(s,i);
|
||||
if(x < 0) {
|
||||
if(s.charAt(i) == "-") mi = true;
|
||||
continue;
|
||||
}
|
||||
mi = false;
|
||||
if(sh == 0)
|
||||
this[this.t++] = x;
|
||||
else if(sh+k > this.DB) {
|
||||
this[this.t-1] |= (x&((1<<(this.DB-sh))-1))<<sh;
|
||||
this[this.t++] = (x>>(this.DB-sh));
|
||||
}
|
||||
else
|
||||
this[this.t-1] |= x<<sh;
|
||||
sh += k;
|
||||
if(sh >= this.DB) sh -= this.DB;
|
||||
}
|
||||
if(k == 8 && (s[0]&0x80) != 0) {
|
||||
this.s = -1;
|
||||
if(sh > 0) this[this.t-1] |= ((1<<(this.DB-sh))-1)<<sh;
|
||||
}
|
||||
this.clamp();
|
||||
if(mi) BigInteger.ZERO.subTo(this,this);
|
||||
}
|
||||
|
||||
// (protected) clamp off excess high words
|
||||
function bnpClamp() {
|
||||
var c = this.s&this.DM;
|
||||
while(this.t > 0 && this[this.t-1] == c) --this.t;
|
||||
}
|
||||
|
||||
// (public) return string representation in given radix
|
||||
function bnToString(b) {
|
||||
if(this.s < 0) return "-"+this.negate().toString(b);
|
||||
var k;
|
||||
if(b == 16) k = 4;
|
||||
else if(b == 8) k = 3;
|
||||
else if(b == 2) k = 1;
|
||||
else if(b == 32) k = 5;
|
||||
else if(b == 4) k = 2;
|
||||
else return this.toRadix(b);
|
||||
var km = (1<<k)-1, d, m = false, r = "", i = this.t;
|
||||
var p = this.DB-(i*this.DB)%k;
|
||||
if(i-- > 0) {
|
||||
if(p < this.DB && (d = this[i]>>p) > 0) { m = true; r = int2char(d); }
|
||||
while(i >= 0) {
|
||||
if(p < k) {
|
||||
d = (this[i]&((1<<p)-1))<<(k-p);
|
||||
d |= this[--i]>>(p+=this.DB-k);
|
||||
}
|
||||
else {
|
||||
d = (this[i]>>(p-=k))&km;
|
||||
if(p <= 0) { p += this.DB; --i; }
|
||||
}
|
||||
if(d > 0) m = true;
|
||||
if(m) r += int2char(d);
|
||||
}
|
||||
}
|
||||
return m?r:"0";
|
||||
}
|
||||
|
||||
// (public) -this
|
||||
function bnNegate() { var r = nbi(); BigInteger.ZERO.subTo(this,r); return r; }
|
||||
|
||||
// (public) |this|
|
||||
function bnAbs() { return (this.s<0)?this.negate():this; }
|
||||
|
||||
// (public) return + if this > a, - if this < a, 0 if equal
|
||||
function bnCompareTo(a) {
|
||||
var r = this.s-a.s;
|
||||
if(r != 0) return r;
|
||||
var i = this.t;
|
||||
r = i-a.t;
|
||||
if(r != 0) return r;
|
||||
while(--i >= 0) if((r=this[i]-a[i]) != 0) return r;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// returns bit length of the integer x
|
||||
function nbits(x) {
|
||||
var r = 1, t;
|
||||
if((t=x>>>16) != 0) { x = t; r += 16; }
|
||||
if((t=x>>8) != 0) { x = t; r += 8; }
|
||||
if((t=x>>4) != 0) { x = t; r += 4; }
|
||||
if((t=x>>2) != 0) { x = t; r += 2; }
|
||||
if((t=x>>1) != 0) { x = t; r += 1; }
|
||||
return r;
|
||||
}
|
||||
|
||||
// (public) return the number of bits in "this"
|
||||
function bnBitLength() {
|
||||
if(this.t <= 0) return 0;
|
||||
return this.DB*(this.t-1)+nbits(this[this.t-1]^(this.s&this.DM));
|
||||
}
|
||||
|
||||
// (protected) r = this << n*DB
|
||||
function bnpDLShiftTo(n,r) {
|
||||
var i;
|
||||
for(i = this.t-1; i >= 0; --i) r[i+n] = this[i];
|
||||
for(i = n-1; i >= 0; --i) r[i] = 0;
|
||||
r.t = this.t+n;
|
||||
r.s = this.s;
|
||||
}
|
||||
|
||||
// (protected) r = this >> n*DB
|
||||
function bnpDRShiftTo(n,r) {
|
||||
for(var i = n; i < this.t; ++i) r[i-n] = this[i];
|
||||
r.t = Math.max(this.t-n,0);
|
||||
r.s = this.s;
|
||||
}
|
||||
|
||||
// (protected) r = this << n
|
||||
function bnpLShiftTo(n,r) {
|
||||
var bs = n%this.DB;
|
||||
var cbs = this.DB-bs;
|
||||
var bm = (1<<cbs)-1;
|
||||
var ds = Math.floor(n/this.DB), c = (this.s<<bs)&this.DM, i;
|
||||
for(i = this.t-1; i >= 0; --i) {
|
||||
r[i+ds+1] = (this[i]>>cbs)|c;
|
||||
c = (this[i]&bm)<<bs;
|
||||
}
|
||||
for(i = ds-1; i >= 0; --i) r[i] = 0;
|
||||
r[ds] = c;
|
||||
r.t = this.t+ds+1;
|
||||
r.s = this.s;
|
||||
r.clamp();
|
||||
}
|
||||
|
||||
// (protected) r = this >> n
|
||||
function bnpRShiftTo(n,r) {
|
||||
r.s = this.s;
|
||||
var ds = Math.floor(n/this.DB);
|
||||
if(ds >= this.t) { r.t = 0; return; }
|
||||
var bs = n%this.DB;
|
||||
var cbs = this.DB-bs;
|
||||
var bm = (1<<bs)-1;
|
||||
r[0] = this[ds]>>bs;
|
||||
for(var i = ds+1; i < this.t; ++i) {
|
||||
r[i-ds-1] |= (this[i]&bm)<<cbs;
|
||||
r[i-ds] = this[i]>>bs;
|
||||
}
|
||||
if(bs > 0) r[this.t-ds-1] |= (this.s&bm)<<cbs;
|
||||
r.t = this.t-ds;
|
||||
r.clamp();
|
||||
}
|
||||
|
||||
// (protected) r = this - a
|
||||
function bnpSubTo(a,r) {
|
||||
var i = 0, c = 0, m = Math.min(a.t,this.t);
|
||||
while(i < m) {
|
||||
c += this[i]-a[i];
|
||||
r[i++] = c&this.DM;
|
||||
c >>= this.DB;
|
||||
}
|
||||
if(a.t < this.t) {
|
||||
c -= a.s;
|
||||
while(i < this.t) {
|
||||
c += this[i];
|
||||
r[i++] = c&this.DM;
|
||||
c >>= this.DB;
|
||||
}
|
||||
c += this.s;
|
||||
}
|
||||
else {
|
||||
c += this.s;
|
||||
while(i < a.t) {
|
||||
c -= a[i];
|
||||
r[i++] = c&this.DM;
|
||||
c >>= this.DB;
|
||||
}
|
||||
c -= a.s;
|
||||
}
|
||||
r.s = (c<0)?-1:0;
|
||||
if(c < -1) r[i++] = this.DV+c;
|
||||
else if(c > 0) r[i++] = c;
|
||||
r.t = i;
|
||||
r.clamp();
|
||||
}
|
||||
|
||||
// (protected) r = this * a, r != this,a (HAC 14.12)
|
||||
// "this" should be the larger one if appropriate.
|
||||
function bnpMultiplyTo(a,r) {
|
||||
var x = this.abs(), y = a.abs();
|
||||
var i = x.t;
|
||||
r.t = i+y.t;
|
||||
while(--i >= 0) r[i] = 0;
|
||||
for(i = 0; i < y.t; ++i) r[i+x.t] = x.am(0,y[i],r,i,0,x.t);
|
||||
r.s = 0;
|
||||
r.clamp();
|
||||
if(this.s != a.s) BigInteger.ZERO.subTo(r,r);
|
||||
}
|
||||
|
||||
// (protected) r = this^2, r != this (HAC 14.16)
|
||||
function bnpSquareTo(r) {
|
||||
var x = this.abs();
|
||||
var i = r.t = 2*x.t;
|
||||
while(--i >= 0) r[i] = 0;
|
||||
for(i = 0; i < x.t-1; ++i) {
|
||||
var c = x.am(i,x[i],r,2*i,0,1);
|
||||
if((r[i+x.t]+=x.am(i+1,2*x[i],r,2*i+1,c,x.t-i-1)) >= x.DV) {
|
||||
r[i+x.t] -= x.DV;
|
||||
r[i+x.t+1] = 1;
|
||||
}
|
||||
}
|
||||
if(r.t > 0) r[r.t-1] += x.am(i,x[i],r,2*i,0,1);
|
||||
r.s = 0;
|
||||
r.clamp();
|
||||
}
|
||||
|
||||
// (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
|
||||
// r != q, this != m. q or r may be null.
|
||||
function bnpDivRemTo(m,q,r) {
|
||||
var pm = m.abs();
|
||||
if(pm.t <= 0) return;
|
||||
var pt = this.abs();
|
||||
if(pt.t < pm.t) {
|
||||
if(q != null) q.fromInt(0);
|
||||
if(r != null) this.copyTo(r);
|
||||
return;
|
||||
}
|
||||
if(r == null) r = nbi();
|
||||
var y = nbi(), ts = this.s, ms = m.s;
|
||||
var nsh = this.DB-nbits(pm[pm.t-1]); // normalize modulus
|
||||
if(nsh > 0) { pm.lShiftTo(nsh,y); pt.lShiftTo(nsh,r); }
|
||||
else { pm.copyTo(y); pt.copyTo(r); }
|
||||
var ys = y.t;
|
||||
var y0 = y[ys-1];
|
||||
if(y0 == 0) return;
|
||||
var yt = y0*(1<<this.F1)+((ys>1)?y[ys-2]>>this.F2:0);
|
||||
var d1 = this.FV/yt, d2 = (1<<this.F1)/yt, e = 1<<this.F2;
|
||||
var i = r.t, j = i-ys, t = (q==null)?nbi():q;
|
||||
y.dlShiftTo(j,t);
|
||||
if(r.compareTo(t) >= 0) {
|
||||
r[r.t++] = 1;
|
||||
r.subTo(t,r);
|
||||
}
|
||||
BigInteger.ONE.dlShiftTo(ys,t);
|
||||
t.subTo(y,y); // "negative" y so we can replace sub with am later
|
||||
while(y.t < ys) y[y.t++] = 0;
|
||||
while(--j >= 0) {
|
||||
// Estimate quotient digit
|
||||
var qd = (r[--i]==y0)?this.DM:Math.floor(r[i]*d1+(r[i-1]+e)*d2);
|
||||
if((r[i]+=y.am(0,qd,r,j,0,ys)) < qd) { // Try it out
|
||||
y.dlShiftTo(j,t);
|
||||
r.subTo(t,r);
|
||||
while(r[i] < --qd) r.subTo(t,r);
|
||||
}
|
||||
}
|
||||
if(q != null) {
|
||||
r.drShiftTo(ys,q);
|
||||
if(ts != ms) BigInteger.ZERO.subTo(q,q);
|
||||
}
|
||||
r.t = ys;
|
||||
r.clamp();
|
||||
if(nsh > 0) r.rShiftTo(nsh,r); // Denormalize remainder
|
||||
if(ts < 0) BigInteger.ZERO.subTo(r,r);
|
||||
}
|
||||
|
||||
// (public) this mod a
|
||||
function bnMod(a) {
|
||||
var r = nbi();
|
||||
this.abs().divRemTo(a,null,r);
|
||||
if(this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a.subTo(r,r);
|
||||
return r;
|
||||
}
|
||||
|
||||
// Modular reduction using "classic" algorithm
|
||||
function Classic(m) { this.m = m; }
|
||||
function cConvert(x) {
|
||||
if(x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m);
|
||||
else return x;
|
||||
}
|
||||
function cRevert(x) { return x; }
|
||||
function cReduce(x) { x.divRemTo(this.m,null,x); }
|
||||
function cMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
|
||||
function cSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
|
||||
|
||||
Classic.prototype.convert = cConvert;
|
||||
Classic.prototype.revert = cRevert;
|
||||
Classic.prototype.reduce = cReduce;
|
||||
Classic.prototype.mulTo = cMulTo;
|
||||
Classic.prototype.sqrTo = cSqrTo;
|
||||
|
||||
// (protected) return "-1/this % 2^DB"; useful for Mont. reduction
|
||||
// justification:
|
||||
// xy == 1 (mod m)
|
||||
// xy = 1+km
|
||||
// xy(2-xy) = (1+km)(1-km)
|
||||
// x[y(2-xy)] = 1-k^2m^2
|
||||
// x[y(2-xy)] == 1 (mod m^2)
|
||||
// if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
|
||||
// should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
|
||||
// JS multiply "overflows" differently from C/C++, so care is needed here.
|
||||
function bnpInvDigit() {
|
||||
if(this.t < 1) return 0;
|
||||
var x = this[0];
|
||||
if((x&1) == 0) return 0;
|
||||
var y = x&3; // y == 1/x mod 2^2
|
||||
y = (y*(2-(x&0xf)*y))&0xf; // y == 1/x mod 2^4
|
||||
y = (y*(2-(x&0xff)*y))&0xff; // y == 1/x mod 2^8
|
||||
y = (y*(2-(((x&0xffff)*y)&0xffff)))&0xffff; // y == 1/x mod 2^16
|
||||
// last step - calculate inverse mod DV directly;
|
||||
// assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
|
||||
y = (y*(2-x*y%this.DV))%this.DV; // y == 1/x mod 2^dbits
|
||||
// we really want the negative inverse, and -DV < y < DV
|
||||
return (y>0)?this.DV-y:-y;
|
||||
}
|
||||
|
||||
// Montgomery reduction
|
||||
function Montgomery(m) {
|
||||
this.m = m;
|
||||
this.mp = m.invDigit();
|
||||
this.mpl = this.mp&0x7fff;
|
||||
this.mph = this.mp>>15;
|
||||
this.um = (1<<(m.DB-15))-1;
|
||||
this.mt2 = 2*m.t;
|
||||
}
|
||||
|
||||
// xR mod m
|
||||
function montConvert(x) {
|
||||
var r = nbi();
|
||||
x.abs().dlShiftTo(this.m.t,r);
|
||||
r.divRemTo(this.m,null,r);
|
||||
if(x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r,r);
|
||||
return r;
|
||||
}
|
||||
|
||||
// x/R mod m
|
||||
function montRevert(x) {
|
||||
var r = nbi();
|
||||
x.copyTo(r);
|
||||
this.reduce(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
// x = x/R mod m (HAC 14.32)
|
||||
function montReduce(x) {
|
||||
while(x.t <= this.mt2) // pad x so am has enough room later
|
||||
x[x.t++] = 0;
|
||||
for(var i = 0; i < this.m.t; ++i) {
|
||||
// faster way of calculating u0 = x[i]*mp mod DV
|
||||
var j = x[i]&0x7fff;
|
||||
var u0 = (j*this.mpl+(((j*this.mph+(x[i]>>15)*this.mpl)&this.um)<<15))&x.DM;
|
||||
// use am to combine the multiply-shift-add into one call
|
||||
j = i+this.m.t;
|
||||
x[j] += this.m.am(0,u0,x,i,0,this.m.t);
|
||||
// propagate carry
|
||||
while(x[j] >= x.DV) { x[j] -= x.DV; x[++j]++; }
|
||||
}
|
||||
x.clamp();
|
||||
x.drShiftTo(this.m.t,x);
|
||||
if(x.compareTo(this.m) >= 0) x.subTo(this.m,x);
|
||||
}
|
||||
|
||||
// r = "x^2/R mod m"; x != r
|
||||
function montSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
|
||||
|
||||
// r = "xy/R mod m"; x,y != r
|
||||
function montMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
|
||||
|
||||
Montgomery.prototype.convert = montConvert;
|
||||
Montgomery.prototype.revert = montRevert;
|
||||
Montgomery.prototype.reduce = montReduce;
|
||||
Montgomery.prototype.mulTo = montMulTo;
|
||||
Montgomery.prototype.sqrTo = montSqrTo;
|
||||
|
||||
// (protected) true iff this is even
|
||||
function bnpIsEven() { return ((this.t>0)?(this[0]&1):this.s) == 0; }
|
||||
|
||||
// (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
|
||||
function bnpExp(e,z) {
|
||||
if(e > 0xffffffff || e < 1) return BigInteger.ONE;
|
||||
var r = nbi(), r2 = nbi(), g = z.convert(this), i = nbits(e)-1;
|
||||
g.copyTo(r);
|
||||
while(--i >= 0) {
|
||||
z.sqrTo(r,r2);
|
||||
if((e&(1<<i)) > 0) z.mulTo(r2,g,r);
|
||||
else { var t = r; r = r2; r2 = t; }
|
||||
}
|
||||
return z.revert(r);
|
||||
}
|
||||
|
||||
// (public) this^e % m, 0 <= e < 2^32
|
||||
function bnModPowInt(e,m) {
|
||||
var z;
|
||||
if(e < 256 || m.isEven()) z = new Classic(m); else z = new Montgomery(m);
|
||||
return this.exp(e,z);
|
||||
}
|
||||
|
||||
// protected
|
||||
BigInteger.prototype.copyTo = bnpCopyTo;
|
||||
BigInteger.prototype.fromInt = bnpFromInt;
|
||||
BigInteger.prototype.fromString = bnpFromString;
|
||||
BigInteger.prototype.clamp = bnpClamp;
|
||||
BigInteger.prototype.dlShiftTo = bnpDLShiftTo;
|
||||
BigInteger.prototype.drShiftTo = bnpDRShiftTo;
|
||||
BigInteger.prototype.lShiftTo = bnpLShiftTo;
|
||||
BigInteger.prototype.rShiftTo = bnpRShiftTo;
|
||||
BigInteger.prototype.subTo = bnpSubTo;
|
||||
BigInteger.prototype.multiplyTo = bnpMultiplyTo;
|
||||
BigInteger.prototype.squareTo = bnpSquareTo;
|
||||
BigInteger.prototype.divRemTo = bnpDivRemTo;
|
||||
BigInteger.prototype.invDigit = bnpInvDigit;
|
||||
BigInteger.prototype.isEven = bnpIsEven;
|
||||
BigInteger.prototype.exp = bnpExp;
|
||||
|
||||
// public
|
||||
BigInteger.prototype.toString = bnToString;
|
||||
BigInteger.prototype.negate = bnNegate;
|
||||
BigInteger.prototype.abs = bnAbs;
|
||||
BigInteger.prototype.compareTo = bnCompareTo;
|
||||
BigInteger.prototype.bitLength = bnBitLength;
|
||||
BigInteger.prototype.mod = bnMod;
|
||||
BigInteger.prototype.modPowInt = bnModPowInt;
|
||||
|
||||
// "constants"
|
||||
BigInteger.ZERO = nbv(0);
|
||||
BigInteger.ONE = nbv(1);
|
79
thirdparty/prng4.js
vendored
Normal file
79
thirdparty/prng4.js
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
// Downloaded from http://www-cs-students.stanford.edu/~tjw/jsbn/ by Jeremy White on 6/1/2012
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003-2005 Tom Wu
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
|
||||
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF
|
||||
* THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT
|
||||
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* In addition, the following condition applies:
|
||||
*
|
||||
* All redistributions must retain an intact copy of this copyright notice
|
||||
* and disclaimer.
|
||||
*/
|
||||
|
||||
|
||||
// prng4.js - uses Arcfour as a PRNG
|
||||
|
||||
function Arcfour() {
|
||||
this.i = 0;
|
||||
this.j = 0;
|
||||
this.S = new Array();
|
||||
}
|
||||
|
||||
// Initialize arcfour context from key, an array of ints, each from [0..255]
|
||||
function ARC4init(key) {
|
||||
var i, j, t;
|
||||
for(i = 0; i < 256; ++i)
|
||||
this.S[i] = i;
|
||||
j = 0;
|
||||
for(i = 0; i < 256; ++i) {
|
||||
j = (j + this.S[i] + key[i % key.length]) & 255;
|
||||
t = this.S[i];
|
||||
this.S[i] = this.S[j];
|
||||
this.S[j] = t;
|
||||
}
|
||||
this.i = 0;
|
||||
this.j = 0;
|
||||
}
|
||||
|
||||
function ARC4next() {
|
||||
var t;
|
||||
this.i = (this.i + 1) & 255;
|
||||
this.j = (this.j + this.S[this.i]) & 255;
|
||||
t = this.S[this.i];
|
||||
this.S[this.i] = this.S[this.j];
|
||||
this.S[this.j] = t;
|
||||
return this.S[(t + this.S[this.i]) & 255];
|
||||
}
|
||||
|
||||
Arcfour.prototype.init = ARC4init;
|
||||
Arcfour.prototype.next = ARC4next;
|
||||
|
||||
// Plug in your RNG constructor here
|
||||
function prng_newstate() {
|
||||
return new Arcfour();
|
||||
}
|
||||
|
||||
// Pool size must be a multiple of 4 and greater than 32.
|
||||
// An array of bytes the size of the pool will be passed to init()
|
||||
var rng_psize = 256;
|
102
thirdparty/rng.js
vendored
Normal file
102
thirdparty/rng.js
vendored
Normal file
@ -0,0 +1,102 @@
|
||||
// Downloaded from http://www-cs-students.stanford.edu/~tjw/jsbn/ by Jeremy White on 6/1/2012
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003-2005 Tom Wu
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
|
||||
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF
|
||||
* THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT
|
||||
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* In addition, the following condition applies:
|
||||
*
|
||||
* All redistributions must retain an intact copy of this copyright notice
|
||||
* and disclaimer.
|
||||
*/
|
||||
|
||||
|
||||
// Random number generator - requires a PRNG backend, e.g. prng4.js
|
||||
|
||||
// For best results, put code like
|
||||
// <body onClick='rng_seed_time();' onKeyPress='rng_seed_time();'>
|
||||
// in your main HTML document.
|
||||
|
||||
var rng_state;
|
||||
var rng_pool;
|
||||
var rng_pptr;
|
||||
|
||||
// Mix in a 32-bit integer into the pool
|
||||
function rng_seed_int(x) {
|
||||
rng_pool[rng_pptr++] ^= x & 255;
|
||||
rng_pool[rng_pptr++] ^= (x >> 8) & 255;
|
||||
rng_pool[rng_pptr++] ^= (x >> 16) & 255;
|
||||
rng_pool[rng_pptr++] ^= (x >> 24) & 255;
|
||||
if(rng_pptr >= rng_psize) rng_pptr -= rng_psize;
|
||||
}
|
||||
|
||||
// Mix in the current time (w/milliseconds) into the pool
|
||||
function rng_seed_time() {
|
||||
rng_seed_int(new Date().getTime());
|
||||
}
|
||||
|
||||
// Initialize the pool with junk if needed.
|
||||
if(rng_pool == null) {
|
||||
rng_pool = new Array();
|
||||
rng_pptr = 0;
|
||||
var t;
|
||||
if(navigator.appName == "Netscape" && navigator.appVersion < "5" && window.crypto) {
|
||||
// Extract entropy (256 bits) from NS4 RNG if available
|
||||
var z = window.crypto.random(32);
|
||||
for(t = 0; t < z.length; ++t)
|
||||
rng_pool[rng_pptr++] = z.charCodeAt(t) & 255;
|
||||
}
|
||||
while(rng_pptr < rng_psize) { // extract some randomness from Math.random()
|
||||
t = Math.floor(65536 * Math.random());
|
||||
rng_pool[rng_pptr++] = t >>> 8;
|
||||
rng_pool[rng_pptr++] = t & 255;
|
||||
}
|
||||
rng_pptr = 0;
|
||||
rng_seed_time();
|
||||
//rng_seed_int(window.screenX);
|
||||
//rng_seed_int(window.screenY);
|
||||
}
|
||||
|
||||
function rng_get_byte() {
|
||||
if(rng_state == null) {
|
||||
rng_seed_time();
|
||||
rng_state = prng_newstate();
|
||||
rng_state.init(rng_pool);
|
||||
for(rng_pptr = 0; rng_pptr < rng_pool.length; ++rng_pptr)
|
||||
rng_pool[rng_pptr] = 0;
|
||||
rng_pptr = 0;
|
||||
//rng_pool = null;
|
||||
}
|
||||
// TODO: allow reseeding after first request
|
||||
return rng_state.next();
|
||||
}
|
||||
|
||||
function rng_get_bytes(ba) {
|
||||
var i;
|
||||
for(i = 0; i < ba.length; ++i) ba[i] = rng_get_byte();
|
||||
}
|
||||
|
||||
function SecureRandom() {}
|
||||
|
||||
SecureRandom.prototype.nextBytes = rng_get_bytes;
|
146
thirdparty/rsa.js
vendored
Normal file
146
thirdparty/rsa.js
vendored
Normal file
@ -0,0 +1,146 @@
|
||||
// Downloaded from http://www-cs-students.stanford.edu/~tjw/jsbn/ by Jeremy White on 6/1/2012
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003-2005 Tom Wu
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
|
||||
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF
|
||||
* THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT
|
||||
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* In addition, the following condition applies:
|
||||
*
|
||||
* All redistributions must retain an intact copy of this copyright notice
|
||||
* and disclaimer.
|
||||
*/
|
||||
|
||||
|
||||
// Depends on jsbn.js and rng.js
|
||||
|
||||
// Version 1.1: support utf-8 encoding in pkcs1pad2
|
||||
|
||||
// convert a (hex) string to a bignum object
|
||||
function parseBigInt(str,r) {
|
||||
return new BigInteger(str,r);
|
||||
}
|
||||
|
||||
function linebrk(s,n) {
|
||||
var ret = "";
|
||||
var i = 0;
|
||||
while(i + n < s.length) {
|
||||
ret += s.substring(i,i+n) + "\n";
|
||||
i += n;
|
||||
}
|
||||
return ret + s.substring(i,s.length);
|
||||
}
|
||||
|
||||
function byte2Hex(b) {
|
||||
if(b < 0x10)
|
||||
return "0" + b.toString(16);
|
||||
else
|
||||
return b.toString(16);
|
||||
}
|
||||
|
||||
// PKCS#1 (type 2, random) pad input string s to n bytes, and return a bigint
|
||||
function pkcs1pad2(s,n) {
|
||||
if(n < s.length + 11) { // TODO: fix for utf-8
|
||||
alert("Message too long for RSA");
|
||||
return null;
|
||||
}
|
||||
var ba = new Array();
|
||||
var i = s.length - 1;
|
||||
while(i >= 0 && n > 0) {
|
||||
var c = s.charCodeAt(i--);
|
||||
if(c < 128) { // encode using utf-8
|
||||
ba[--n] = c;
|
||||
}
|
||||
else if((c > 127) && (c < 2048)) {
|
||||
ba[--n] = (c & 63) | 128;
|
||||
ba[--n] = (c >> 6) | 192;
|
||||
}
|
||||
else {
|
||||
ba[--n] = (c & 63) | 128;
|
||||
ba[--n] = ((c >> 6) & 63) | 128;
|
||||
ba[--n] = (c >> 12) | 224;
|
||||
}
|
||||
}
|
||||
ba[--n] = 0;
|
||||
var rng = new SecureRandom();
|
||||
var x = new Array();
|
||||
while(n > 2) { // random non-zero pad
|
||||
x[0] = 0;
|
||||
while(x[0] == 0) rng.nextBytes(x);
|
||||
ba[--n] = x[0];
|
||||
}
|
||||
ba[--n] = 2;
|
||||
ba[--n] = 0;
|
||||
return new BigInteger(ba);
|
||||
}
|
||||
|
||||
// "empty" RSA key constructor
|
||||
function RSAKey() {
|
||||
this.n = null;
|
||||
this.e = 0;
|
||||
this.d = null;
|
||||
this.p = null;
|
||||
this.q = null;
|
||||
this.dmp1 = null;
|
||||
this.dmq1 = null;
|
||||
this.coeff = null;
|
||||
}
|
||||
|
||||
// Set the public key fields N and e from hex strings
|
||||
function RSASetPublic(N,E) {
|
||||
if(N != null && E != null && N.length > 0 && E.length > 0) {
|
||||
this.n = parseBigInt(N,16);
|
||||
this.e = parseInt(E,16);
|
||||
}
|
||||
else
|
||||
alert("Invalid RSA public key");
|
||||
}
|
||||
|
||||
// Perform raw public operation on "x": return x^e (mod n)
|
||||
function RSADoPublic(x) {
|
||||
return x.modPowInt(this.e, this.n);
|
||||
}
|
||||
|
||||
// Return the PKCS#1 RSA encryption of "text" as an even-length hex string
|
||||
function RSAEncrypt(text) {
|
||||
var m = pkcs1pad2(text,(this.n.bitLength()+7)>>3);
|
||||
if(m == null) return null;
|
||||
var c = this.doPublic(m);
|
||||
if(c == null) return null;
|
||||
var h = c.toString(16);
|
||||
if((h.length & 1) == 0) return h; else return "0" + h;
|
||||
}
|
||||
|
||||
// Return the PKCS#1 RSA encryption of "text" as a Base64-encoded string
|
||||
//function RSAEncryptB64(text) {
|
||||
// var h = this.encrypt(text);
|
||||
// if(h) return hex2b64(h); else return null;
|
||||
//}
|
||||
|
||||
// protected
|
||||
RSAKey.prototype.doPublic = RSADoPublic;
|
||||
|
||||
// public
|
||||
RSAKey.prototype.setPublic = RSASetPublic;
|
||||
RSAKey.prototype.encrypt = RSAEncrypt;
|
||||
//RSAKey.prototype.encrypt_b64 = RSAEncryptB64;
|
346
thirdparty/sha1.js
vendored
Normal file
346
thirdparty/sha1.js
vendored
Normal file
@ -0,0 +1,346 @@
|
||||
/*
|
||||
* A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
|
||||
* in FIPS 180-1
|
||||
* Version 2.2 Copyright Paul Johnston 2000 - 2009.
|
||||
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
|
||||
* Distributed under the BSD License
|
||||
* See http://pajhome.org.uk/crypt/md5 for details.
|
||||
*/
|
||||
|
||||
/* Downloaded 6/1/2012 from the above address by Jeremy White.
|
||||
License reproduce here for completeness:
|
||||
|
||||
Copyright (c) 1998 - 2009, Paul Johnston & Contributors
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
* Configurable variables. You may need to tweak these to be compatible with
|
||||
* the server-side, but the defaults work in most cases.
|
||||
*/
|
||||
var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
|
||||
var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
|
||||
|
||||
/*
|
||||
* These are the functions you'll usually want to call
|
||||
* They take string arguments and return either hex or base-64 encoded strings
|
||||
*/
|
||||
function hex_sha1(s) { return rstr2hex(rstr_sha1(str2rstr_utf8(s))); }
|
||||
function b64_sha1(s) { return rstr2b64(rstr_sha1(str2rstr_utf8(s))); }
|
||||
function any_sha1(s, e) { return rstr2any(rstr_sha1(str2rstr_utf8(s)), e); }
|
||||
function hex_hmac_sha1(k, d)
|
||||
{ return rstr2hex(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d))); }
|
||||
function b64_hmac_sha1(k, d)
|
||||
{ return rstr2b64(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d))); }
|
||||
function any_hmac_sha1(k, d, e)
|
||||
{ return rstr2any(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d)), e); }
|
||||
|
||||
/*
|
||||
* Perform a simple self-test to see if the VM is working
|
||||
*/
|
||||
function sha1_vm_test()
|
||||
{
|
||||
return hex_sha1("abc").toLowerCase() == "a9993e364706816aba3e25717850c26c9cd0d89d";
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the SHA1 of a raw string
|
||||
*/
|
||||
function rstr_sha1(s)
|
||||
{
|
||||
return binb2rstr(binb_sha1(rstr2binb(s), s.length * 8));
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the HMAC-SHA1 of a key and some data (raw strings)
|
||||
*/
|
||||
function rstr_hmac_sha1(key, data)
|
||||
{
|
||||
var bkey = rstr2binb(key);
|
||||
if(bkey.length > 16) bkey = binb_sha1(bkey, key.length * 8);
|
||||
|
||||
var ipad = Array(16), opad = Array(16);
|
||||
for(var i = 0; i < 16; i++)
|
||||
{
|
||||
ipad[i] = bkey[i] ^ 0x36363636;
|
||||
opad[i] = bkey[i] ^ 0x5C5C5C5C;
|
||||
}
|
||||
|
||||
var hash = binb_sha1(ipad.concat(rstr2binb(data)), 512 + data.length * 8);
|
||||
return binb2rstr(binb_sha1(opad.concat(hash), 512 + 160));
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a raw string to a hex string
|
||||
*/
|
||||
function rstr2hex(input)
|
||||
{
|
||||
try { hexcase } catch(e) { hexcase=0; }
|
||||
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
|
||||
var output = "";
|
||||
var x;
|
||||
for(var i = 0; i < input.length; i++)
|
||||
{
|
||||
x = input.charCodeAt(i);
|
||||
output += hex_tab.charAt((x >>> 4) & 0x0F)
|
||||
+ hex_tab.charAt( x & 0x0F);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a raw string to a base-64 string
|
||||
*/
|
||||
function rstr2b64(input)
|
||||
{
|
||||
try { b64pad } catch(e) { b64pad=''; }
|
||||
var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
var output = "";
|
||||
var len = input.length;
|
||||
for(var i = 0; i < len; i += 3)
|
||||
{
|
||||
var triplet = (input.charCodeAt(i) << 16)
|
||||
| (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)
|
||||
| (i + 2 < len ? input.charCodeAt(i+2) : 0);
|
||||
for(var j = 0; j < 4; j++)
|
||||
{
|
||||
if(i * 8 + j * 6 > input.length * 8) output += b64pad;
|
||||
else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a raw string to an arbitrary string encoding
|
||||
*/
|
||||
function rstr2any(input, encoding)
|
||||
{
|
||||
var divisor = encoding.length;
|
||||
var remainders = Array();
|
||||
var i, q, x, quotient;
|
||||
|
||||
/* Convert to an array of 16-bit big-endian values, forming the dividend */
|
||||
var dividend = Array(Math.ceil(input.length / 2));
|
||||
for(i = 0; i < dividend.length; i++)
|
||||
{
|
||||
dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Repeatedly perform a long division. The binary array forms the dividend,
|
||||
* the length of the encoding is the divisor. Once computed, the quotient
|
||||
* forms the dividend for the next step. We stop when the dividend is zero.
|
||||
* All remainders are stored for later use.
|
||||
*/
|
||||
while(dividend.length > 0)
|
||||
{
|
||||
quotient = Array();
|
||||
x = 0;
|
||||
for(i = 0; i < dividend.length; i++)
|
||||
{
|
||||
x = (x << 16) + dividend[i];
|
||||
q = Math.floor(x / divisor);
|
||||
x -= q * divisor;
|
||||
if(quotient.length > 0 || q > 0)
|
||||
quotient[quotient.length] = q;
|
||||
}
|
||||
remainders[remainders.length] = x;
|
||||
dividend = quotient;
|
||||
}
|
||||
|
||||
/* Convert the remainders to the output string */
|
||||
var output = "";
|
||||
for(i = remainders.length - 1; i >= 0; i--)
|
||||
output += encoding.charAt(remainders[i]);
|
||||
|
||||
/* Append leading zero equivalents */
|
||||
var full_length = Math.ceil(input.length * 8 /
|
||||
(Math.log(encoding.length) / Math.log(2)))
|
||||
for(i = output.length; i < full_length; i++)
|
||||
output = encoding[0] + output;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/*
|
||||
* Encode a string as utf-8.
|
||||
* For efficiency, this assumes the input is valid utf-16.
|
||||
*/
|
||||
function str2rstr_utf8(input)
|
||||
{
|
||||
var output = "";
|
||||
var i = -1;
|
||||
var x, y;
|
||||
|
||||
while(++i < input.length)
|
||||
{
|
||||
/* Decode utf-16 surrogate pairs */
|
||||
x = input.charCodeAt(i);
|
||||
y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;
|
||||
if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF)
|
||||
{
|
||||
x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
|
||||
i++;
|
||||
}
|
||||
|
||||
/* Encode output as utf-8 */
|
||||
if(x <= 0x7F)
|
||||
output += String.fromCharCode(x);
|
||||
else if(x <= 0x7FF)
|
||||
output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F),
|
||||
0x80 | ( x & 0x3F));
|
||||
else if(x <= 0xFFFF)
|
||||
output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),
|
||||
0x80 | ((x >>> 6 ) & 0x3F),
|
||||
0x80 | ( x & 0x3F));
|
||||
else if(x <= 0x1FFFFF)
|
||||
output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),
|
||||
0x80 | ((x >>> 12) & 0x3F),
|
||||
0x80 | ((x >>> 6 ) & 0x3F),
|
||||
0x80 | ( x & 0x3F));
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/*
|
||||
* Encode a string as utf-16
|
||||
*/
|
||||
function str2rstr_utf16le(input)
|
||||
{
|
||||
var output = "";
|
||||
for(var i = 0; i < input.length; i++)
|
||||
output += String.fromCharCode( input.charCodeAt(i) & 0xFF,
|
||||
(input.charCodeAt(i) >>> 8) & 0xFF);
|
||||
return output;
|
||||
}
|
||||
|
||||
function str2rstr_utf16be(input)
|
||||
{
|
||||
var output = "";
|
||||
for(var i = 0; i < input.length; i++)
|
||||
output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF,
|
||||
input.charCodeAt(i) & 0xFF);
|
||||
return output;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a raw string to an array of big-endian words
|
||||
* Characters >255 have their high-byte silently ignored.
|
||||
*/
|
||||
function rstr2binb(input)
|
||||
{
|
||||
var output = Array(input.length >> 2);
|
||||
for(var i = 0; i < output.length; i++)
|
||||
output[i] = 0;
|
||||
for(var i = 0; i < input.length * 8; i += 8)
|
||||
output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32);
|
||||
return output;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert an array of big-endian words to a string
|
||||
*/
|
||||
function binb2rstr(input)
|
||||
{
|
||||
var output = "";
|
||||
for(var i = 0; i < input.length * 32; i += 8)
|
||||
output += String.fromCharCode((input[i>>5] >>> (24 - i % 32)) & 0xFF);
|
||||
return output;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the SHA-1 of an array of big-endian words, and a bit length
|
||||
*/
|
||||
function binb_sha1(x, len)
|
||||
{
|
||||
/* append padding */
|
||||
x[len >> 5] |= 0x80 << (24 - len % 32);
|
||||
x[((len + 64 >> 9) << 4) + 15] = len;
|
||||
|
||||
var w = Array(80);
|
||||
var a = 1732584193;
|
||||
var b = -271733879;
|
||||
var c = -1732584194;
|
||||
var d = 271733878;
|
||||
var e = -1009589776;
|
||||
|
||||
for(var i = 0; i < x.length; i += 16)
|
||||
{
|
||||
var olda = a;
|
||||
var oldb = b;
|
||||
var oldc = c;
|
||||
var oldd = d;
|
||||
var olde = e;
|
||||
|
||||
for(var j = 0; j < 80; j++)
|
||||
{
|
||||
if(j < 16) w[j] = x[i + j];
|
||||
else w[j] = bit_rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
|
||||
var t = safe_add(safe_add(bit_rol(a, 5), sha1_ft(j, b, c, d)),
|
||||
safe_add(safe_add(e, w[j]), sha1_kt(j)));
|
||||
e = d;
|
||||
d = c;
|
||||
c = bit_rol(b, 30);
|
||||
b = a;
|
||||
a = t;
|
||||
}
|
||||
|
||||
a = safe_add(a, olda);
|
||||
b = safe_add(b, oldb);
|
||||
c = safe_add(c, oldc);
|
||||
d = safe_add(d, oldd);
|
||||
e = safe_add(e, olde);
|
||||
}
|
||||
return Array(a, b, c, d, e);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform the appropriate triplet combination function for the current
|
||||
* iteration
|
||||
*/
|
||||
function sha1_ft(t, b, c, d)
|
||||
{
|
||||
if(t < 20) return (b & c) | ((~b) & d);
|
||||
if(t < 40) return b ^ c ^ d;
|
||||
if(t < 60) return (b & c) | (b & d) | (c & d);
|
||||
return b ^ c ^ d;
|
||||
}
|
||||
|
||||
/*
|
||||
* Determine the appropriate additive constant for the current iteration
|
||||
*/
|
||||
function sha1_kt(t)
|
||||
{
|
||||
return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 :
|
||||
(t < 60) ? -1894007588 : -899497514;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
|
||||
* to work around bugs in some JS interpreters.
|
||||
*/
|
||||
function safe_add(x, y)
|
||||
{
|
||||
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
|
||||
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
||||
return (msw << 16) | (lsw & 0xFFFF);
|
||||
}
|
||||
|
||||
/*
|
||||
* Bitwise rotate a 32-bit number to the left.
|
||||
*/
|
||||
function bit_rol(num, cnt)
|
||||
{
|
||||
return (num << cnt) | (num >>> (32 - cnt));
|
||||
}
|
250
ticket.js
Normal file
250
ticket.js
Normal file
@ -0,0 +1,250 @@
|
||||
"use strict";
|
||||
/*
|
||||
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||
|
||||
This file is part of spice-html5.
|
||||
|
||||
spice-html5 is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
spice-html5 is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var SHA_DIGEST_LENGTH = 20;
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
** General ticket RSA encryption functions - just good enough to
|
||||
** support what we need to send back an encrypted ticket.
|
||||
**--------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
** OAEP padding functions. Inspired by the OpenSSL implementation.
|
||||
**--------------------------------------------------------------------------*/
|
||||
function MGF1(mask, seed)
|
||||
{
|
||||
var i, j, outlen;
|
||||
for (i = 0, outlen = 0; outlen < mask.length; i++)
|
||||
{
|
||||
var combo_buf = new String;
|
||||
|
||||
for (j = 0; j < seed.length; j++)
|
||||
combo_buf += String.fromCharCode(seed[j]);
|
||||
combo_buf += String.fromCharCode((i >> 24) & 255);
|
||||
combo_buf += String.fromCharCode((i >> 16) & 255);
|
||||
combo_buf += String.fromCharCode((i >> 8) & 255);
|
||||
combo_buf += String.fromCharCode((i) & 255);
|
||||
|
||||
var combo_hash = rstr_sha1(combo_buf);
|
||||
for (j = 0; j < combo_hash.length && outlen < mask.length; j++, outlen++)
|
||||
{
|
||||
mask[outlen] = combo_hash.charCodeAt(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function RSA_padding_add_PKCS1_OAEP(tolen, from, param)
|
||||
{
|
||||
var seed = new Array(SHA_DIGEST_LENGTH);
|
||||
var rand = new SecureRandom();
|
||||
rand.nextBytes(seed);
|
||||
|
||||
var dblen = tolen - 1 - seed.length;
|
||||
var db = new Array(dblen);
|
||||
var padlen = dblen - from.length - 1;
|
||||
var i;
|
||||
|
||||
if (param === undefined)
|
||||
param = "";
|
||||
|
||||
if (padlen < SHA_DIGEST_LENGTH)
|
||||
{
|
||||
console.log("Error - data too large for key size.");
|
||||
return null;
|
||||
}
|
||||
|
||||
for (i = 0; i < padlen; i++)
|
||||
db[i] = 0;
|
||||
|
||||
var param_hash = rstr_sha1(param);
|
||||
for (i = 0; i < param_hash.length; i++)
|
||||
db[i] = param_hash.charCodeAt(i);
|
||||
|
||||
db[padlen] = 1;
|
||||
for (i = 0; i < from.length; i++)
|
||||
db[i + padlen + 1] = from.charCodeAt(i);
|
||||
|
||||
var dbmask = new Array(dblen);
|
||||
if (MGF1(dbmask, seed) < 0)
|
||||
return null;
|
||||
|
||||
for (i = 0; i < dbmask.length; i++)
|
||||
db[i] ^= dbmask[i];
|
||||
|
||||
|
||||
var seedmask = Array(SHA_DIGEST_LENGTH);
|
||||
if (MGF1(seedmask, db) < 0)
|
||||
return null;
|
||||
|
||||
for (i = 0; i < seedmask.length; i++)
|
||||
seed[i] ^= seedmask[i];
|
||||
|
||||
var ret = new String;
|
||||
ret += String.fromCharCode(0);
|
||||
for (i = 0; i < seed.length; i++)
|
||||
ret += String.fromCharCode(seed[i]);
|
||||
for (i = 0; i < db.length; i++)
|
||||
ret += String.fromCharCode(db[i]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
function asn_get_length(u8, at)
|
||||
{
|
||||
var len = u8[at++];
|
||||
if (len > 0x80)
|
||||
{
|
||||
if (len != 0x81)
|
||||
{
|
||||
console.log("Error: we lazily don't support keys bigger than 255 bytes. It'd be easy to fix.");
|
||||
return null;
|
||||
}
|
||||
len = u8[at++];
|
||||
}
|
||||
|
||||
return [ at, len];
|
||||
}
|
||||
|
||||
function find_sequence(u8, at)
|
||||
{
|
||||
var lenblock;
|
||||
at = at || 0;
|
||||
if (u8[at++] != 0x30)
|
||||
{
|
||||
console.log("Error: public key should start with a sequence flag.");
|
||||
return null;
|
||||
}
|
||||
|
||||
lenblock = asn_get_length(u8, at);
|
||||
if (! lenblock)
|
||||
return null;
|
||||
return lenblock;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
** Extract an RSA key from a memory buffer
|
||||
**--------------------------------------------------------------------------*/
|
||||
function create_rsa_from_mb(mb, at)
|
||||
{
|
||||
var u8 = new Uint8Array(mb);
|
||||
var lenblock;
|
||||
var seq;
|
||||
var ba;
|
||||
var i;
|
||||
var ret;
|
||||
|
||||
/* We have a sequence which contains a sequence followed by a bit string */
|
||||
seq = find_sequence(u8, at);
|
||||
if (! seq)
|
||||
return null;
|
||||
|
||||
at = seq[0];
|
||||
seq = find_sequence(u8, at);
|
||||
if (! seq)
|
||||
return null;
|
||||
|
||||
/* Skip over the contained sequence */
|
||||
at = seq[0] + seq[1];
|
||||
if (u8[at++] != 0x3)
|
||||
{
|
||||
console.log("Error: expecting bit string next.");
|
||||
return null;
|
||||
}
|
||||
|
||||
/* Get the bit string, which is *itself* a sequence. Having fun yet? */
|
||||
lenblock = asn_get_length(u8, at);
|
||||
if (! lenblock)
|
||||
return null;
|
||||
|
||||
at = lenblock[0];
|
||||
if (u8[at] != 0 && u8[at + 1] != 0x30)
|
||||
{
|
||||
console.log("Error: unexpected values in bit string.");
|
||||
return null;
|
||||
}
|
||||
|
||||
/* Okay, now we have a sequence of two binary values, we hope. */
|
||||
seq = find_sequence(u8, at + 1);
|
||||
if (! seq)
|
||||
return null;
|
||||
|
||||
at = seq[0];
|
||||
if (u8[at++] != 0x02)
|
||||
{
|
||||
console.log("Error: expecting integer n next.");
|
||||
return null;
|
||||
}
|
||||
lenblock = asn_get_length(u8, at);
|
||||
if (! lenblock)
|
||||
return null;
|
||||
at = lenblock[0];
|
||||
|
||||
ba = new Array(lenblock[1]);
|
||||
for (i = 0; i < lenblock[1]; i++)
|
||||
ba[i] = u8[at + i];
|
||||
|
||||
ret = new RSAKey();
|
||||
ret.n = new BigInteger(ba);
|
||||
|
||||
at += lenblock[1];
|
||||
|
||||
if (u8[at++] != 0x02)
|
||||
{
|
||||
console.log("Error: expecting integer e next.");
|
||||
return null;
|
||||
}
|
||||
lenblock = asn_get_length(u8, at);
|
||||
if (! lenblock)
|
||||
return null;
|
||||
at = lenblock[0];
|
||||
|
||||
ret.e = u8[at++];
|
||||
for (i = 1; i < lenblock[1]; i++)
|
||||
{
|
||||
ret.e <<= 8;
|
||||
ret.e |= u8[at++];
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
function rsa_encrypt(rsa, str)
|
||||
{
|
||||
var i;
|
||||
var ret = [];
|
||||
var oaep = RSA_padding_add_PKCS1_OAEP((rsa.n.bitLength()+7)>>3, str);
|
||||
if (! oaep)
|
||||
return null;
|
||||
|
||||
var ba = new Array(oaep.length);
|
||||
|
||||
for (i = 0; i < oaep.length; i++)
|
||||
ba[i] = oaep.charCodeAt(i);
|
||||
var bigint = new BigInteger(ba);
|
||||
var enc = rsa.doPublic(bigint);
|
||||
var h = enc.toString(16);
|
||||
if ((h.length & 1) != 0)
|
||||
h = "0" + h;
|
||||
for (i = 0; i < h.length; i += 2)
|
||||
ret[i / 2] = parseInt(h.substring(i, i + 2), 16);
|
||||
return ret;
|
||||
}
|
239
utils.js
Normal file
239
utils.js
Normal file
@ -0,0 +1,239 @@
|
||||
"use strict";
|
||||
/*
|
||||
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||
|
||||
This file is part of spice-html5.
|
||||
|
||||
spice-html5 is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
spice-html5 is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
** Utility settings and functions for Spice
|
||||
**--------------------------------------------------------------------------*/
|
||||
var DEBUG = 0;
|
||||
var DUMP_DRAWS = false;
|
||||
var DUMP_CANVASES = false;
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
** combine_array_buffers
|
||||
** Combine two array buffers.
|
||||
** FIXME - this can't be optimal. See wire.js about eliminating the need.
|
||||
**--------------------------------------------------------------------------*/
|
||||
function combine_array_buffers(a1, a2)
|
||||
{
|
||||
var in1 = new Uint8Array(a1);
|
||||
var in2 = new Uint8Array(a2);
|
||||
var ret = new ArrayBuffer(a1.byteLength + a2.byteLength);
|
||||
var out = new Uint8Array(ret);
|
||||
var o = 0;
|
||||
var i;
|
||||
for (i = 0; i < in1.length; i++)
|
||||
out[o++] = in1[i];
|
||||
for (i = 0; i < in2.length; i++)
|
||||
out[o++] = in2[i];
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
** hexdump_buffer
|
||||
**--------------------------------------------------------------------------*/
|
||||
function hexdump_buffer(a)
|
||||
{
|
||||
var mg = new Uint8Array(a);
|
||||
var hex = "";
|
||||
var str = "";
|
||||
var last_zeros = 0;
|
||||
for (var i = 0; i < mg.length; i++)
|
||||
{
|
||||
var h = Number(mg[i]).toString(16);
|
||||
if (h.length == 1)
|
||||
hex += "0";
|
||||
hex += h + " ";
|
||||
|
||||
str += String.fromCharCode(mg[i]);
|
||||
|
||||
if ((i % 16 == 15) || (i == (mg.length - 1)))
|
||||
{
|
||||
while (i % 16 != 15)
|
||||
{
|
||||
hex += " ";
|
||||
i++;
|
||||
}
|
||||
|
||||
if (last_zeros == 0)
|
||||
console.log(hex + " | " + str);
|
||||
|
||||
if (hex == "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ")
|
||||
{
|
||||
if (last_zeros == 1)
|
||||
{
|
||||
console.log(".");
|
||||
last_zeros++;
|
||||
}
|
||||
else if (last_zeros == 0)
|
||||
last_zeros++;
|
||||
}
|
||||
else
|
||||
last_zeros = 0;
|
||||
|
||||
hex = str = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
** FIXME FIXME FIXME - web key code to scan code mapping
|
||||
** This is really atrocious code. At the end of the day, we need to
|
||||
** map keystrokes generated by the browser into the scan codes required
|
||||
** by spice. This table was literally built by me pressing keys on my keyboard
|
||||
** and typing the resulting value in by hand.
|
||||
** I'm sure Europeans will hate me, and the Chinese will likely *never*
|
||||
** talk to me.
|
||||
**--------------------------------------------------------------------------*/
|
||||
var scanmap = [];
|
||||
var codei = 1;
|
||||
scanmap[27] = codei++;
|
||||
scanmap['1'.charCodeAt(0)] = codei++;
|
||||
scanmap['2'.charCodeAt(0)] = codei++;
|
||||
scanmap['3'.charCodeAt(0)] = codei++;
|
||||
scanmap['4'.charCodeAt(0)] = codei++;
|
||||
scanmap['5'.charCodeAt(0)] = codei++;
|
||||
scanmap['6'.charCodeAt(0)] = codei++;
|
||||
scanmap['7'.charCodeAt(0)] = codei++;
|
||||
scanmap['8'.charCodeAt(0)] = codei++;
|
||||
scanmap['9'.charCodeAt(0)] = codei++;
|
||||
scanmap['0'.charCodeAt(0)] = codei++;
|
||||
scanmap[109] = codei++;
|
||||
scanmap['='.charCodeAt(0)] = codei++;
|
||||
scanmap[8] = codei++;
|
||||
scanmap[9] = codei++;
|
||||
scanmap['Q'.charCodeAt(0)] = codei++;
|
||||
scanmap['W'.charCodeAt(0)] = codei++;
|
||||
scanmap['E'.charCodeAt(0)] = codei++;
|
||||
scanmap['R'.charCodeAt(0)] = codei++;
|
||||
scanmap['T'.charCodeAt(0)] = codei++;
|
||||
scanmap['Y'.charCodeAt(0)] = codei++;
|
||||
scanmap['U'.charCodeAt(0)] = codei++;
|
||||
scanmap['I'.charCodeAt(0)] = codei++;
|
||||
scanmap['O'.charCodeAt(0)] = codei++;
|
||||
scanmap['P'.charCodeAt(0)] = codei++;
|
||||
scanmap[219] = codei++;
|
||||
scanmap[221] = codei++;
|
||||
scanmap[13] = codei++;
|
||||
scanmap[17] = codei++;
|
||||
scanmap['A'.charCodeAt(0)] = codei++;
|
||||
scanmap['S'.charCodeAt(0)] = codei++;
|
||||
scanmap['D'.charCodeAt(0)] = codei++;
|
||||
scanmap['F'.charCodeAt(0)] = codei++;
|
||||
scanmap['G'.charCodeAt(0)] = codei++;
|
||||
scanmap['H'.charCodeAt(0)] = codei++;
|
||||
scanmap['J'.charCodeAt(0)] = codei++;
|
||||
scanmap['K'.charCodeAt(0)] = codei++;
|
||||
scanmap['L'.charCodeAt(0)] = codei++;
|
||||
scanmap[';'.charCodeAt(0)] = codei++;
|
||||
scanmap[222] = codei++;
|
||||
scanmap[192] = codei++;
|
||||
scanmap[16] = codei++;
|
||||
scanmap[220] = codei++;
|
||||
scanmap['Z'.charCodeAt(0)] = codei++;
|
||||
scanmap['X'.charCodeAt(0)] = codei++;
|
||||
scanmap['C'.charCodeAt(0)] = codei++;
|
||||
scanmap['V'.charCodeAt(0)] = codei++;
|
||||
scanmap['B'.charCodeAt(0)] = codei++;
|
||||
scanmap['N'.charCodeAt(0)] = codei++;
|
||||
scanmap['M'.charCodeAt(0)] = codei++;
|
||||
scanmap[188] = codei++;
|
||||
scanmap[190] = codei++;
|
||||
scanmap[191] = codei++;
|
||||
codei++; // right shift seems to be same
|
||||
scanmap[106] = codei++;
|
||||
scanmap[18] = codei++;
|
||||
scanmap[' '.charCodeAt(0)] = codei++;
|
||||
scanmap[20] = codei++;
|
||||
scanmap[112] = codei++;
|
||||
scanmap[113] = codei++;
|
||||
scanmap[114] = codei++;
|
||||
scanmap[115] = codei++;
|
||||
scanmap[116] = codei++;
|
||||
scanmap[117] = codei++;
|
||||
scanmap[118] = codei++;
|
||||
scanmap[119] = codei++;
|
||||
scanmap[120] = codei++;
|
||||
scanmap[121] = codei++;
|
||||
scanmap[144] = codei++;
|
||||
scanmap[145] = codei++; // Scroll lock
|
||||
scanmap[103] = codei++;
|
||||
scanmap[104] = codei++;
|
||||
scanmap[105] = codei++;
|
||||
codei++;// skip minus;
|
||||
scanmap[100] = codei++;
|
||||
scanmap[101] = codei++;
|
||||
scanmap[102] = codei++;
|
||||
scanmap[107] = codei++;
|
||||
scanmap[97] = codei++;
|
||||
scanmap[98] = codei++;
|
||||
scanmap[99] = codei++;
|
||||
scanmap[96] = codei++;
|
||||
scanmap[110] = codei++;
|
||||
|
||||
// F11 + 12 go up at 87/88, after the less
|
||||
codei = 87;
|
||||
scanmap[122] = codei++;
|
||||
scanmap[123] = codei++;
|
||||
|
||||
codei = 99;
|
||||
scanmap[42] = codei++;
|
||||
codei++; // skip alt
|
||||
scanmap[19] = codei++; // break
|
||||
|
||||
scanmap[36] = codei++; // home
|
||||
scanmap[38] = codei++; // up
|
||||
scanmap[33] = codei++; // page up
|
||||
scanmap[37] = codei++; // left
|
||||
scanmap[39] = codei++; // right
|
||||
scanmap[35] = codei++; // end
|
||||
scanmap[40] = codei++; // down
|
||||
scanmap[34] = codei++; // page down
|
||||
scanmap[45] = codei++; // insert
|
||||
scanmap[46] = codei++; // delete
|
||||
|
||||
function keycode_to_start_scan(code)
|
||||
{
|
||||
if (scanmap[code] === undefined)
|
||||
{
|
||||
alert('no map for ' + code);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (scanmap[code] < 0x100) {
|
||||
return scanmap[code];
|
||||
} else {
|
||||
return 0xe0 | ((scanmap[code] - 0x100) << 8);
|
||||
}
|
||||
}
|
||||
|
||||
function keycode_to_end_scan(code)
|
||||
{
|
||||
if (scanmap[code] === undefined)
|
||||
return 0;
|
||||
|
||||
if (scanmap[code] < 0x100) {
|
||||
return scanmap[code] | 0x80;
|
||||
} else {
|
||||
return 0x80e0 | ((scanmap[code] - 0x100) << 8);
|
||||
}
|
||||
}
|
123
wire.js
Normal file
123
wire.js
Normal file
@ -0,0 +1,123 @@
|
||||
"use strict";
|
||||
/*
|
||||
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||
|
||||
This file is part of spice-html5.
|
||||
|
||||
spice-html5 is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
spice-html5 is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*--------------------------------------------------------------------------------------
|
||||
** SpiceWireReader
|
||||
** This class will receive messages from a WebSocket and relay it to a given
|
||||
** callback. It will optionally save and pass along a header, useful in processing
|
||||
** the mini message format.
|
||||
**--------------------------------------------------------------------------------------*/
|
||||
function SpiceWireReader(sc, callback)
|
||||
{
|
||||
this.sc = sc;
|
||||
this.callback = callback;
|
||||
this.needed = 0;
|
||||
|
||||
this.buffers = [];
|
||||
|
||||
this.sc.ws.wire_reader = this;
|
||||
this.sc.ws.binaryType = "arraybuffer";
|
||||
this.sc.ws.addEventListener('message', wire_blob_catcher);
|
||||
}
|
||||
|
||||
SpiceWireReader.prototype =
|
||||
{
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
** Process messages coming in from our WebSocket
|
||||
**----------------------------------------------------------------------*/
|
||||
inbound: function (mb)
|
||||
{
|
||||
var at;
|
||||
|
||||
/* Just buffer if we don't need anything yet */
|
||||
if (this.needed == 0)
|
||||
{
|
||||
this.buffers.push(mb);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Optimization - if we have just one inbound block, and it's
|
||||
suitable for our needs, just use it. */
|
||||
if (this.buffers.length == 0 && mb.byteLength >= this.needed)
|
||||
{
|
||||
if (mb.byteLength > this.needed)
|
||||
{
|
||||
this.buffers.push(mb.slice(this.needed));
|
||||
mb = mb.slice(0, this.needed);
|
||||
}
|
||||
this.callback.call(this.sc, mb,
|
||||
this.saved_msg_header || undefined);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.buffers.push(mb);
|
||||
}
|
||||
|
||||
|
||||
/* If we have fragments that add up to what we need, combine them */
|
||||
/* FIXME - it would be faster to revise the processing code to handle
|
||||
** multiple fragments directly. Essentially, we should be
|
||||
** able to do this without any slice() or combine_array_buffers() calls */
|
||||
while (this.buffers.length > 1 && this.buffers[0].byteLength < this.needed)
|
||||
{
|
||||
var mb1 = this.buffers.shift();
|
||||
var mb2 = this.buffers.shift();
|
||||
|
||||
this.buffers.unshift(combine_array_buffers(mb1, mb2));
|
||||
}
|
||||
|
||||
|
||||
while (this.buffers.length > 0 && this.buffers[0].byteLength >= this.needed)
|
||||
{
|
||||
mb = this.buffers.shift();
|
||||
if (mb.byteLength > this.needed)
|
||||
{
|
||||
this.buffers.unshift(mb.slice(this.needed));
|
||||
mb = mb.slice(0, this.needed);
|
||||
}
|
||||
this.callback.call(this.sc, mb,
|
||||
this.saved_msg_header || undefined);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
request: function(n)
|
||||
{
|
||||
this.needed = n;
|
||||
},
|
||||
|
||||
save_header: function(h)
|
||||
{
|
||||
this.saved_msg_header = h;
|
||||
},
|
||||
|
||||
clear_header: function()
|
||||
{
|
||||
this.saved_msg_header = undefined;
|
||||
},
|
||||
}
|
||||
|
||||
function wire_blob_catcher(e)
|
||||
{
|
||||
DEBUG > 1 && console.log(">> WebSockets.onmessage");
|
||||
DEBUG > 1 && console.log("id " + this.wire_reader.sc.connection_id +"; type " + this.wire_reader.sc.type);
|
||||
SpiceWireReader.prototype.inbound.call(this.wire_reader, e.data);
|
||||
}
|
Loading…
Reference in New Issue
Block a user