Commit Graph

142 Commits

Author SHA1 Message Date
Christophe Fergeau
3029eae630 codegen: Fix 'registred' typo
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-06-24 07:47:41 +01:00
Frediano Ziglio
57570953dc extend a comment for type attributes
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-06-21 12:52:25 +01:00
Frediano Ziglio
c5a61aaa30 add a check for negate cases on enumerations
Not supported by code so trigger an error to avoid invalid usages

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-06-21 12:52:18 +01:00
Christophe Fergeau
8f722db28e codegen: Remove unused write_message_marshaller argument
"is_server" is not used in this method
2016-06-20 15:05:34 +02:00
Frediano Ziglio
d3dd8bcea3 fix wrong assert check
The assert were never triggered as always True

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-06-02 08:34:19 +01:00
Marc-André Lureau
487f914a5d codegen: simplify FdType
This patch is a left-over from the fd passing commit 267391c8fd as
suggested by Frediano Ziglio during review.

Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>

(cherry picked from spice-protocol commit 47076559628d71c128e14e11147ce36b92677885)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2016-03-10 16:01:42 +01:00
Marc-Andre Lureau
c5ed374a32 protocol: learn to describe fd passing in messages
Add a new type, "unix_fd", used to describe file descriptor sharing via
socket ancillary data (these messages are local only).

The marshaller/demarshaller can't serialize this in memory (consume_fd
implementation is empty), so it is the responsability of the marshaller
user to handle sending and receiving the handles, which are appended at
the end of the message with an extra stream byte (because some Unix
requires sending at least a byte with ancillary data).

Even if there is no fd to send (or if the fd is invalid etc), the
receiver side expects an extra byte anyway.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>

(cherry-picked from spice-protocol commit 267391c8fd7c90c067b3e4845ff0227a2580e2e2)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2016-03-10 16:01:42 +01:00
Marc-André Lureau
1cd26b87c1 Revert "Remove files moved to spice-protocol"
This reverts commit 7665dcf1bb.

Also revert the related build-sys changes to fix the build.

codegen generated code depends on spice-common code (marshaller,
messages etc), it makes more sense to keep the generator along
this. Otherwise a newer protocol release will fail to build older
projects.

*.proto files are required as well, since it generates code that parent
modules depend on unconditionnaly.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2016-03-10 16:01:36 +01:00
Frediano Ziglio
7665dcf1bb Remove files moved to spice-protocol
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2015-08-11 10:26:06 +02:00
Uri Lublin
53f7f543f9 codegen: ptypes.py: keep attribute names in sets
This patch changes the type of 'valid_attributes' and
'attributes_with_arguments'.
Both of them are list of different strings and are kept in sets.

This was the intention of the original code, but this patch
use a specific set([ strings ]) format, instead of { strings }.

This fixes the build for me on RHEL-6 (python-2.6.6).
Build error is:

File "/home/ulublin/git/spice/spice-common/python_modules/ptypes.py",
line 67
      'end',
           ^
SyntaxError: invalid syntax
2015-08-04 20:10:22 +03:00
Frediano Ziglio
a1d1d396cd codegen: Allow to specify C type for index variable
This is to prepare to generate the wireshark dissector which uses
glib types instead of the newer C ones (for compatibility with some
compilers).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2015-07-23 11:22:11 +02:00
Frediano Ziglio
f717273002 codegen: Check we don't pop too many indexes 2015-07-23 11:22:11 +02:00
Frediano Ziglio
f0f578abee codegen: Remove old ptr32 attribute
This attribute is not used in code.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2015-07-23 11:22:11 +02:00
Frediano Ziglio
eff8b1a0e4 codegen: Do some checks on attributes
Verify that the attribute is known. This could help for instance to
avoid some future typo mistakes.
We also now have a list of attributes that we can comment for
documentation purpose.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2015-07-23 11:20:19 +02:00
Frediano Ziglio
179928fceb codegen: Reuse code to fix attribute from prototype file
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2015-07-23 11:11:47 +02:00
Frediano Ziglio
365866c4c9 codegen: Remove duplicate variable initialization
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2015-07-23 11:11:44 +02:00
Frediano Ziglio
0130e8dc39 codegen: Optimize code indentation and avoid a loop
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2015-07-23 11:11:18 +02:00
Frediano Ziglio
184feb541a codegen: Fix typo in variable name
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2015-07-23 11:11:16 +02:00
Frediano Ziglio
aa43c0d61e codegen: Simplify if/else blocks
Blocks were mainly the same, this reduces the amount of code.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2015-07-23 11:11:03 +02:00
Frediano Ziglio
86b0568055 codegen: Import six module before first use
The module is used in the initial try/except so make sure it is
already imported.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2015-07-23 11:10:57 +02:00
Christophe Fergeau
b216f66f10 codegen: Use six.PY3 rather than six.PY2
Older versions of python-six (at least 1.3.0) defined six.PY3 but not
six.PY2. six.PY2 is only used twice in straightforward tests so it's
easy to use six.PY3 instead.
2015-04-14 16:08:43 +02:00
Alexander Wauck
ba52c4cae2 Make spice_codegen.py work on both Python 2 and 3
This is a new version of my previous patch that does not include six.py.
It's still kind of big, but at least it's all spice-common changes now.
There are also a few other fixes that Christophe brought to my attention.
Note that six now needs to be installed on the system (python-six on
Fedora and Debian, six on PyPI).

This *should* be enough to make spice_codegen.py work on both Python 2
and Python 3.  The major changes are as follows:

 * cStringIO.StringIO -> io.StringIO
 * str vs. unicode updates (io.StringIO doesn't like str)
 * integer division
 * foo.has_key(bar) -> bar in foo
 * import internal_thing -> from . import internal_thing
 * removed from __future__ import with_statement
   (might break Python 2.5?)
 * changed some lambdas to list comprehensions (done by 2to3)
 * cast some_dict.keys() to list where needed (e.g. for sorting)
 * use normal type names with isinstance instead of types.WhateverType

Signed-off-by: Alexander Wauck <awauck@codeweavers.com>
2015-04-01 13:39:03 +02:00
Fabiano Fidêncio
840bcfe7a2 python: Fix -Wsign-compare
The return of the get_array_size() is used as a limit in a loop,
being compared with an unsigned index (indexes are always unsigned).
To avoid the -Wsign-compare warning, let's cast the return of the
get_array_size() to unsigned and make GCC happier.
2014-09-18 13:13:30 +02:00
Fabiano Fidêncio
9385db6875 python: Fix -Wunused-parameter
Although the most part of the parameters marked as unused are actually
being used for a few functions, a bunch of warnings can be seen when
the code is compiled with "-Wall -Wextra". As adding the unused attribute
means that the variable/parameter is meant to be *possibly* unused, we're
safe adding it in the generated code, even for used variables/parameters.
2014-09-18 13:13:27 +02:00
Marc-André Lureau
dd4a446f5d demarshal: prefix variable name with parent names
Avoid naming clash if parent structures have the same name

https://bugzilla.redhat.com/show_bug.cgi?id=1021995
2014-05-15 14:21:48 +02:00
Christophe Fergeau
b3a00f4411 marshaller: Use #include <> for headers in $srcdir/common
Since the (de)marshallers are now generated in $builddir and not in
$srcdir, when these generated files include a file located in
$srcdir/common, the compiler will find them thanks to a -I directive, so it
makes more sense to use <> rather than "" when including them.
2014-04-16 16:47:55 +02:00
Christophe Fergeau
90a1240f27 Use #include "common/..." in (de)marshallers
Now that they are created in $builddir, their includes will need to refer
to files in $srcdir, which can be different. It's cleaner to add
-I $(top_srcdir)/spice-common/ to modules using spice-common rather than
having -I $(top_srcdir)/spice-common/common which would could create header
collisions.
2014-04-16 16:47:55 +02:00
Jonathon Jongsma
31ef0c626d codegen: Add a --generate-wireshark-dissector option
The wireshark protocol dissector is a bit out-of-date. Several new channel types
and enums have been added.  It would be nice if these values (and the
translation between the value and the name) could be automatically generated so
that updating the dissector was a slightly less manual process.  This patch adds
a commandline switch which generates both the enums and value-name lists in the
format that wireshark expects.
2013-10-23 11:41:43 -05:00
Alon Levy
a976c16cf3 python_modules/ptypes.py/EnumBaseType.c_enumname: add missing return to fix broken enums generation
Fixes the resulting enums.h from the invocation of:
./spice_codegen.py --generate-enums spice.proto spice-protocol/spice/enums.h

Right now any enum will contain None as the enum members, with this fix
it will contain the real enum members, i.e. SPICE_FOO.
2012-06-14 13:53:46 +03:00
Christophe Fergeau
39fef7a5da demarshall: add missing parens in BE read_xxx functions
The missing parens causes build to fail on big-endian machines
2012-04-06 15:32:02 +02:00
Marc-André Lureau
c1e4e1be63 build-sys: make it a seperately buildable spice-common library
- autotoolize
- fix headers inclusion
- generate gitignores
- workaround serverSMARTCARD support with dirty hack...
2012-03-22 20:21:05 +01:00
Marc-André Lureau
bc4f5db323 codegen: ifdef/endif function declaration too
Compile out part that we are not supporting.  In the future, we might
want to declare a fake type and an empty function to keep API
compatibility
2012-03-21 13:24:17 +01:00
Marc-André Lureau
b6afcd632e codegen: include headers locally 2012-03-21 13:24:17 +01:00
Marc-André Lureau
2d4e0d2000 codegen: struct marshallers are not current function helper
This solves the issue of struct_marshallers being included within the
current ifdef/endif body, although they are independant functions.
2012-03-21 13:24:16 +01:00
Hans de Goede
69aecfc1bc spice_codegen: Always write a channels entry for an ifdef-ed channel
Before this patch, if a channel is defined conditionally in spice.proto
(because it depends on external headers like the smartcard channel),
spice_codegen would write an entry to the channels array in
spice_get_*_channel_parser which would only take up a place in the array
if the ifdef condition is true, thus moving up all other intializers
one place when it is not true. This was causing issues (crashes) when building
spice-gtk with the combination of usbredir support enabled and smartcard
support disabled.

This patch fixes this by adding #else { NULL, 0 }, to the generated code.

Thanks to coolper chen <lixin.chen@saicocch.com> for reporting this!

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2012-03-20 15:31:30 +01:00
Christophe Fergeau
a7cc3c6a56 handle @ifdef on messages and channels 2012-03-20 15:31:30 +01:00
Christophe Fergeau
7307fccb71 allow attributes on channel elements in .proto files
We want to be able to add an @ifdef annotation to optional messages
For example, we want to compile in the smartcard messages only if
libcacard is available
2012-03-20 15:31:30 +01:00
Christophe Fergeau
eb01d2fc46 add ifdef/endif methods to spice code generator
These methods will be needed to be able to make some fields optional
in spice.proto
2012-03-20 15:31:30 +01:00
Christophe Fergeau
51cf6fce72 fix copy & paste error in ptypes.py 2012-03-20 15:31:30 +01:00
Marc-André Lureau
71faf12d81 demarshal: fixed-size array are missing __nelements
A message with a fixed-size array, such as uint8 uuid[16] will
generate an invalid code, missing the __nelements variable. Make sure
that variable is defined.
2012-03-20 15:25:56 +01:00
Daniel P. Berrange
f83432a685 Remove trailing blank lines
Remove any blank lines at the end of all source files
2012-03-20 15:25:55 +01:00
Hans de Goede
9ef008e5c3 codegen: Fix enums.h generation
With the new usbredir code we have the new concept of the abstract /
generic spicevmc channel type (which just tunnels data from a qemu chardev),
and we've the usbredir channel, which is the only current user of this.

This was reflected in the protocols enum in spice-protocol.h by a manual
edit done by me, my bad. This patch teaches spice.proto about the relation
between the abstract spicevmc channel and the usbredir channel and
modifies codegen to deal with this.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2012-03-20 15:25:54 +01:00
Christophe Fergeau
e0a8d6625c add check for pyparsing
Check both in configure.ac (after checking if we need to rebuild
the marshalling files) and in the python script using pyparsing
(for people modifying .proto files in tarballs)
2012-03-20 15:25:53 +01:00
Marc-André Lureau
5ae49c0d5b python: remove c-ism trailing ; 2012-03-20 15:25:53 +01:00
Marc-André Lureau
7f9e2cb1f7 codegen: typedef the protocol enums
Commit 9d5ef9beeca722b2ceff7d15aaa3aaaaf07ecfbf in spice-protocol
introduced a typedef manually in the generated enums.h header.

This patch adds them automatically to all enums during enums.h generation.
2012-03-20 15:25:53 +01:00
Alon Levy
63703e4349 python_modules/codegen.py: fix indent error in an unused function 2012-03-20 15:25:51 +01:00
Alon Levy
01580185e9 demarshaller/marshaller fix gcc 4.6.0
python_modules/demarshal.py and marshal.py fixes for gcc 4.6.0
warning about set but unused variables. The fixes disable creating
of variables mem_size when they are not used (demarshall) and
declaring a src variable when the message doesn't use it (marshal).

You need to touch *.proto after applying this (should add a Makefile
dependency).
2012-03-20 15:25:50 +01:00
Alon Levy
67ace54dbc codegen: avoid creating out if not used (fix gcc 4.6.0 warning) 2012-03-20 15:25:50 +01:00
Alon Levy
a99c9149b6 mingw32 build: python_modules/marshal: use unsigned for for_loop index variable 2012-03-20 15:25:50 +01:00
Alon Levy
00a7b6ff3b spice codegen: fix copy-o, no such variable value 2012-03-20 15:25:50 +01:00
Alon Levy
c5e79b4215 support python 2.5.4+ for marshaller/demarshallers
Patch adds a "from __future__" import that doesn't affect newer python's but
allows python 2.5.4 to run the code (tested under scratchbox, n900 build environment)
2012-03-20 15:25:49 +01:00
Alexander Larsson
f5c2e64f82 demarshaller: Fix palette marshalling
It turns out that using base + sizeof(struct) is not a good way to
access an array at the end of a struct. For SpicePalette sizeof is 16, but
offset of ents is 12. Using this calculation in the demarshaller breaks
things badly, so now we use the actual array member.
2012-03-20 15:25:49 +01:00
Alexander Larsson
3f2739ebc9 Fix uninitialized variable warnings 2012-03-20 15:25:49 +01:00
Alexander Larsson
7897a338db Don't send CursorHeader if cursor_flags is NONE 2012-03-20 15:25:49 +01:00
Alexander Larsson
bcf9b8acf2 codegen: Allow @to_ptr to make inline structs demarshal as pointers 2012-03-20 15:25:49 +01:00
Alexander Larsson
bdcfb2c83d codegen: Various cleanups
Remove all uses of @end in the marshaller, instead just using
the C struct array-at-end-of-struct. To make this work we also remove
all use of @end for switches (making them C unions).

We drop the zero member of the notify message so that we can avoid this
use of @end for a primitive in the marshaller (plus its useless to send
over the wire).

We change the offsets and stuff in the migration messages to real pointers.
2012-03-20 15:25:48 +01:00
Alexander Larsson
bfffc11787 codegen: Pass member to SubMarshallingSource rather than name
This way we can check attributes on the member.
2012-03-20 15:25:48 +01:00
Alexander Larsson
be1c38df3e codegen: Remove unused methos has_pointer() 2012-03-20 15:25:48 +01:00
Alexander Larsson
1b8f3388b0 Make distcheck work 2012-03-20 15:25:48 +01:00
Alexander Larsson
24c2e3c85f Fix inclusion of common files, no need for common/ part 2012-03-20 15:25:48 +01:00
Alexander Larsson
199c710a08 codegen: No SPICE_ADDRESS types left, drop @c_ptr 2012-03-20 15:25:47 +01:00
Gerd Hoffmann
e37ce72809 Properly parse QXLImage to the new-world SpiceImage
SpiceImage now replaces RedImage and has all image types in it.
All image data are now chunked (and as such not copied when demarshalling).
2012-03-20 15:25:47 +01:00
Alexander Larsson
4b6605fc42 codegen: support @chunk on non-pointer arrays
This is similar to @as_ptr, but generates a single chunk of data.
2012-03-20 15:25:47 +01:00
Alexander Larsson
601d1be843 Add support for @chunk 2012-03-20 15:25:47 +01:00
Alexander Larsson
0df81d33f6 marshaller: Make get_nw_offset() handle deep member references 2012-03-20 15:25:47 +01:00
Alexander Larsson
09d9a18702 Convert SpicePath.segments to a pointer array 2012-03-20 15:25:47 +01:00
Alexander Larsson
bc8d26bfc0 Handle extra size for switch and array the right way
Even for is_extra_size() we should calculate the mem_size for
arrays, its just that the parent type (in this case switch) should
request mem_size if the type is_extra_size.
2012-03-20 15:25:47 +01:00
Alexander Larsson
8c2ff07518 marshaller: Add some docs describing the types of sizes 2012-03-20 15:25:47 +01:00
Alexander Larsson
ad7e75325d marshaller: Make @nonnull a propagated attribute
This cleans up some stuff
2012-03-20 15:25:47 +01:00
Alexander Larsson
71bf95171d marshaller: Make @c_ptr a propagated attribute
This simplifies some code
2012-03-20 15:25:47 +01:00
Alexander Larsson
1d5c7d1d79 marshaller: Add generic way to handle propagating attributes
Also switches @ptr_array to use this
2012-03-20 15:25:47 +01:00
Gerd Hoffmann
c5d06102b7 Properly parse and marshall SpiceString 2012-03-20 15:25:46 +01:00
Alexander Larsson
e3fadaef86 Fix 32bit failure in demarshaller
Due to a typo we always read offsets as pointers, never as SPICE_ADDRESS.
2012-03-20 15:25:46 +01:00
Alexander Larsson
bef8a0cf19 Simplify SpiceLineAttr by removing unsed stuff
Also in new protocol don't send style data if not needed.
2012-03-20 15:25:46 +01:00
Alexander Larsson
930458ea50 Support @marshall to automatically marshall pointers 2012-03-20 15:25:46 +01:00
Alexander Larsson
e6eb19e752 Store SpicePath segment count rather than size
Internally and in the network protocol (for the new version) we
now store the actual number of segments rather than the size of the
full segments array in bytes. This change consists of multiple changes
to handle this:

* Make the qxl parser calculate num_segments
* Make the canvas stroke code handle the new SpicePath layout.
* Fix up is_equal_path in red_worker.c for the new layout
* replace multiple calls to spice_marshall_PathSegment with a single
  spice_marshall_Path call
* Make the byte_size() array size handling do the conversion from
  network size to number of elements when marshalling/demarshalling.
* Update the current spice protocol to send the segment count rather than
  the size
* Update the old spice protocol to use the new byte_size functionallity
  to calculate the size sent and the number of elements recieved
2012-03-20 15:25:46 +01:00
Alexander Larsson
18a11d6be0 demarshaller: Support @c_ptr attributes for pointers
A @c_ptr pointer is stored in memory as a real pointer rather than a
SPICE_ADDRESS. This is a temporary thing that will be removed again
when all SPICE_ADDRESSes have been converted to real pointer.
2012-03-20 15:25:46 +01:00
Alexander Larsson
2feb07a7b8 demarshaller: Don't parse @zero members
These just write zeros at the right place in the network protocol
typically for old back-compat things. We don't want to read these
back in.
2012-03-20 15:25:46 +01:00
Alexander Larsson
a45758117b Fix build error due to member "SpiceMsgEmpty" same name as type 2012-03-20 15:25:45 +01:00
Alexander Larsson
13d9b32acc Make pointers 32bit in new protocol format 2012-03-20 15:25:45 +01:00
Alexander Larsson
8b5726ecfa marshaller: Correctly determine if switches are fixed size
Switches are fixed size only if all cases have the same size *and*
it has a default case or all the valid cases are listed.
2012-03-20 15:25:45 +01:00
Alexander Larsson
21c7a6d278 Fix handling of @ptr32 network size 2012-03-20 15:25:45 +01:00
Alexander Larsson
9e8883a1f8 Add support for @virtual markup in spice protocol
This means the member is not sent on the network at all.
Instead its initialized to the attribute argument when demarshalled.

This is useful for backwards compatibility support.
2012-03-20 15:25:44 +01:00
Alexander Larsson
7022f4d248 Make internal generated marshaller functions static 2012-03-20 15:25:44 +01:00
Alexander Larsson
bcc5cc0d91 Support extra prefix in code generators
This is require when we add a new spice.proto for the old (major 1)
protocol description.
2012-03-20 15:25:44 +01:00
Alexander Larsson
0349d2249d Support creating marshallers that are called indirectly
This is needed if we want to switch marshallers depending on what
major version the remote side has.
2012-03-20 15:25:44 +01:00
Alexander Larsson
eded86ec1e Add destructor for demarshalled messages
This is required because we don't want to free messages that just
refer to the unparsed message (like SpiceMsgData).

Also, in the future we might need it for more complex demarshalling.
2012-03-20 15:25:44 +01:00
Alexander Larsson
075087b180 Make generated marshallers build on win32 2012-03-20 15:25:44 +01:00
Alexander Larsson
53f8a1a7ba Support @as_ptr in demarshaller to avoid copying data unnecessary 2012-03-20 15:25:44 +01:00
Alexander Larsson
e83ff054d7 Add support for generating message and structure marshallers 2012-03-20 15:25:43 +01:00
Alexander Larsson
e9b33a194e Add python code to automake system 2012-03-20 15:25:43 +01:00
Alexander Larsson
522dc931e8 Initial import of spice protocol description and demarshall generator
The "spice.proto" file describes in detail the networking prototcol
that spice uses and spice_codegen.py can parse this and generate
demarshallers for such network messages.
2012-03-20 15:25:43 +01:00