Re: [Spice-devel] Issues with Clipboard Grab/Release Callbacks

2022-06-21 Thread Nick Couchman
>
> Here's the section in the src/protocol/spice/client.c file that registers
>> the callbacks:
>>
>> /* Register clipboard handlers. */
>> g_signal_connect(channel, SPICE_SIGNAL_MAIN_CLIPBOARD_SELECTION,
>> G_CALLBACK(guac_spice_clipboard_selection_handler),
>> client);
>> g_signal_connect(channel,
>> SPICE_SIGNAL_MAIN_CLIPBOARD_SELECTION_GRAB,
>> G_CALLBACK(guac_spice_clipboard_selection_grab_handler),
>> client);
>> g_signal_connect(channel,
>> SPICE_SIGNAL_MAIN_CLIPBOARD_SELECTION_RELEASE,
>>
>> G_CALLBACK(guac_spice_clipboard_selection_release_handler), client);
>> g_signal_connect(channel,
>> SPICE_SIGNAL_MAIN_CLIPBOARD_SELECTION_REQUEST,
>>
>> G_CALLBACK(guac_spice_clipboard_selection_request_handler), client);
>>
>> link to the full function is here:
>>
>> https://github.com/necouchman/guacamole-server/blob/5e073802a0656e65b1bc8e7e6051831bea0d9508/src/protocols/spice/client.c#L236-L375
>>
>
> Try changing the callbacks to accept a pointer, e.g.:
> - void guac_spice_clipboard_selection_grab_handler(SpiceMainChannel
> channel,
> +void guac_spice_clipboard_selection_grab_handler(SpiceMainChannel*
> channel,
>
>
-Sigh- I knew it would be something simple. Yes, this was it - works
correctly after using pointers.

Thanks, Uri and Marc.

-Nick

>


Re: [Spice-devel] Issues with Clipboard Grab/Release Callbacks

2022-06-21 Thread Uri Lublin
Hi,

On Mon, Jun 20, 2022 at 10:00 PM Nick Couchman  wrote:

> On Mon, Jun 20, 2022 at 2:46 PM Marc-André Lureau <
> marcandre.lur...@gmail.com> wrote:
>
>> Hi
>>
>> On Mon, Jun 20, 2022 at 6:09 PM Nick Couchman  wrote:
>>
>>> Hello, everyone,
>>> I've posted here, before, with some questions during my journey of
>>> trying to add support for the SPICE protocol to the Guacamole project. The
>>> good news is that I've actually made measurable progress in the
>>> implementation - I can now connect to a SPICE server, and the basics work
>>> (mouse and keyboard - mostly anyway), so I'm moving on to the extra stuff -
>>> clipboard, audio, file transfer, etc.
>>>
>>> In working on the clipboard integration, I'm currently running into an
>>> issue with a couple of the callback functions, specifically the clipboard
>>> grab/release functions, where the number of arguments seems to be
>>> mismatched. According to the documentation, these callbacks should be
>>> called with the following arguments:
>>>
>>> gboolean
>>> user_function (SpiceMainChannel *main,
>>>guint selection,
>>>gpointer  types,
>>>guint ntypes,
>>>gpointer  user_data)
>>>
>>>
>> types is actually guint32*, but that's not the problem here.
>>
>
> Okay, I'll update that.
>
>
>>
>>
>>> void
>>> user_function (SpiceMainChannel *main,
>>>guint selection,
>>>gpointer  user_data)
>>>
>>> I've implemented the callbacks with those arguments, as follows:
>>>
>>> void guac_spice_clipboard_selection_grab_handler(SpiceMainChannel
>>> channel,
>>> guint selection, gpointer types, guint ntypes, guac_client*
>>> client)
>>>
>>> void guac_spice_clipboard_selection_release_handler(SpiceMainChannel
>>> channel,
>>> guint selection, guac_client* client)
>>>
>>
>> It looks correct. Can you point to your code connecting the signals with
>> the handlers?
>>
>
> Sure - source code is here:
> https://github.com/necouchman/guacamole-server/tree/working/spice-basic
>
> Here's the section in the src/protocol/spice/client.c file that registers
> the callbacks:
>
> /* Register clipboard handlers. */
> g_signal_connect(channel, SPICE_SIGNAL_MAIN_CLIPBOARD_SELECTION,
> G_CALLBACK(guac_spice_clipboard_selection_handler),
> client);
> g_signal_connect(channel,
> SPICE_SIGNAL_MAIN_CLIPBOARD_SELECTION_GRAB,
> G_CALLBACK(guac_spice_clipboard_selection_grab_handler),
> client);
> g_signal_connect(channel,
> SPICE_SIGNAL_MAIN_CLIPBOARD_SELECTION_RELEASE,
>
> G_CALLBACK(guac_spice_clipboard_selection_release_handler), client);
> g_signal_connect(channel,
> SPICE_SIGNAL_MAIN_CLIPBOARD_SELECTION_REQUEST,
>
> G_CALLBACK(guac_spice_clipboard_selection_request_handler), client);
>
> link to the full function is here:
>
> https://github.com/necouchman/guacamole-server/blob/5e073802a0656e65b1bc8e7e6051831bea0d9508/src/protocols/spice/client.c#L236-L375
>

Try changing the callbacks to accept a pointer, e.g.:
- void guac_spice_clipboard_selection_grab_handler(SpiceMainChannel channel,
+void guac_spice_clipboard_selection_grab_handler(SpiceMainChannel* channel,

 Regards,
Uri.


>
>>
>> and registered them appropriately. However, if I use them as implemented
>> above, when the callbacks are triggered, the application segfaults when I
>> try to access the "guac_client* client" data structure. I used GDB to try
>> to help track this down, and I noticed that the value of "client" was 0x1,
>> which looks less like a pointer to a memory location and more like the
>> number 1.
>>
>> So, I decided to add another argument to the callback functions, just
>> before the client argument:
>>
>> void guac_spice_clipboard_selection_grab_handler(SpiceMainChannel channel,
>> guint selection, gpointer types, guint ntypes, guint extra,
>> guac_client* client)
>>
>> void guac_spice_clipboard_selection_release_handler(SpiceMainChannel
>> channel,
>> guint selection, guint extra, guac_client* client)
>>
>> Strangely, this works - the client data structure can be referenced,
>> there are no segfaults (yet), etc. So, I decided to print the values that
>> are being passed for all of these parameters, and I get the following:
>>
>> guacd[100252]: DEBUG: Notifying client of clipboard grab in the guest.
>> guacd[100252]: DEBUG: Arg: channel: 0x
>> guacd[100252]: DEBUG: Arg: selection: 1275303536
>> guacd[100252]: DEBUG: Arg: types: 0x0001
>> guacd[100252]: DEBUG: Arg: ntypes: 1276022924
>> guacd[100252]: DEBUG: Arg: extra: 1
>>
>>
> Weird
>
>
>> I printed them in the format I thought they should be in based on what
>> the arguments are supposed to be - I probably should have just done all
>> hex. But, it seems like maybe the "extra" parameter being passed is in
>> front of the channel, since the channel is showing up as all zeros?
>>
>> I was trying to

Re: [Spice-devel] Issues with Clipboard Grab/Release Callbacks

2022-06-20 Thread Nick Couchman
On Mon, Jun 20, 2022 at 2:46 PM Marc-André Lureau <
marcandre.lur...@gmail.com> wrote:

> Hi
>
> On Mon, Jun 20, 2022 at 6:09 PM Nick Couchman  wrote:
>
>> Hello, everyone,
>> I've posted here, before, with some questions during my journey of trying
>> to add support for the SPICE protocol to the Guacamole project. The good
>> news is that I've actually made measurable progress in the implementation -
>> I can now connect to a SPICE server, and the basics work (mouse and
>> keyboard - mostly anyway), so I'm moving on to the extra stuff - clipboard,
>> audio, file transfer, etc.
>>
>> In working on the clipboard integration, I'm currently running into an
>> issue with a couple of the callback functions, specifically the clipboard
>> grab/release functions, where the number of arguments seems to be
>> mismatched. According to the documentation, these callbacks should be
>> called with the following arguments:
>>
>> gboolean
>> user_function (SpiceMainChannel *main,
>>guint selection,
>>gpointer  types,
>>guint ntypes,
>>gpointer  user_data)
>>
>>
> types is actually guint32*, but that's not the problem here.
>

Okay, I'll update that.


>
>
>> void
>> user_function (SpiceMainChannel *main,
>>guint selection,
>>gpointer  user_data)
>>
>> I've implemented the callbacks with those arguments, as follows:
>>
>> void guac_spice_clipboard_selection_grab_handler(SpiceMainChannel channel,
>> guint selection, gpointer types, guint ntypes, guac_client*
>> client)
>>
>> void guac_spice_clipboard_selection_release_handler(SpiceMainChannel
>> channel,
>> guint selection, guac_client* client)
>>
>
> It looks correct. Can you point to your code connecting the signals with
> the handlers?
>

Sure - source code is here:
https://github.com/necouchman/guacamole-server/tree/working/spice-basic

Here's the section in the src/protocol/spice/client.c file that registers
the callbacks:

/* Register clipboard handlers. */
g_signal_connect(channel, SPICE_SIGNAL_MAIN_CLIPBOARD_SELECTION,
G_CALLBACK(guac_spice_clipboard_selection_handler), client);
g_signal_connect(channel,
SPICE_SIGNAL_MAIN_CLIPBOARD_SELECTION_GRAB,
G_CALLBACK(guac_spice_clipboard_selection_grab_handler),
client);
g_signal_connect(channel,
SPICE_SIGNAL_MAIN_CLIPBOARD_SELECTION_RELEASE,
G_CALLBACK(guac_spice_clipboard_selection_release_handler),
client);
g_signal_connect(channel,
SPICE_SIGNAL_MAIN_CLIPBOARD_SELECTION_REQUEST,
G_CALLBACK(guac_spice_clipboard_selection_request_handler),
client);

link to the full function is here:
https://github.com/necouchman/guacamole-server/blob/5e073802a0656e65b1bc8e7e6051831bea0d9508/src/protocols/spice/client.c#L236-L375


>
>
>>
>> and registered them appropriately. However, if I use them as implemented
>> above, when the callbacks are triggered, the application segfaults when I
>> try to access the "guac_client* client" data structure. I used GDB to try
>> to help track this down, and I noticed that the value of "client" was 0x1,
>> which looks less like a pointer to a memory location and more like the
>> number 1.
>>
>> So, I decided to add another argument to the callback functions, just
>> before the client argument:
>>
>> void guac_spice_clipboard_selection_grab_handler(SpiceMainChannel channel,
>> guint selection, gpointer types, guint ntypes, guint extra,
>> guac_client* client)
>>
>> void guac_spice_clipboard_selection_release_handler(SpiceMainChannel
>> channel,
>> guint selection, guint extra, guac_client* client)
>>
>> Strangely, this works - the client data structure can be referenced,
>> there are no segfaults (yet), etc. So, I decided to print the values that
>> are being passed for all of these parameters, and I get the following:
>>
>> guacd[100252]: DEBUG: Notifying client of clipboard grab in the guest.
>> guacd[100252]: DEBUG: Arg: channel: 0x
>> guacd[100252]: DEBUG: Arg: selection: 1275303536
>> guacd[100252]: DEBUG: Arg: types: 0x0001
>> guacd[100252]: DEBUG: Arg: ntypes: 1276022924
>> guacd[100252]: DEBUG: Arg: extra: 1
>>
>>
> Weird
>
>
>> I printed them in the format I thought they should be in based on what
>> the arguments are supposed to be - I probably should have just done all
>> hex. But, it seems like maybe the "extra" parameter being passed is in
>> front of the channel, since the channel is showing up as all zeros?
>>
>> I was trying to find the code where the callbacks are actually called -
>> I'm guessing, since this is clipboard integration, it'll be in the vdagent
>> code somewhere - but I was having trouble tracking that down.
>>
>>
> The callbacks are not directly called, since those a GObject signals. The
> main channel will call g_signal_emit().
>
>
Okay.


>
>
>> If anyone has any ideas, I'd

Re: [Spice-devel] Issues with Clipboard Grab/Release Callbacks

2022-06-20 Thread Marc-André Lureau
Hi

On Mon, Jun 20, 2022 at 6:09 PM Nick Couchman  wrote:

> Hello, everyone,
> I've posted here, before, with some questions during my journey of trying
> to add support for the SPICE protocol to the Guacamole project. The good
> news is that I've actually made measurable progress in the implementation -
> I can now connect to a SPICE server, and the basics work (mouse and
> keyboard - mostly anyway), so I'm moving on to the extra stuff - clipboard,
> audio, file transfer, etc.
>
> In working on the clipboard integration, I'm currently running into an
> issue with a couple of the callback functions, specifically the clipboard
> grab/release functions, where the number of arguments seems to be
> mismatched. According to the documentation, these callbacks should be
> called with the following arguments:
>
> gboolean
> user_function (SpiceMainChannel *main,
>guint selection,
>gpointer  types,
>guint ntypes,
>gpointer  user_data)
>
>
types is actually guint32*, but that's not the problem here.


> void
> user_function (SpiceMainChannel *main,
>guint selection,
>gpointer  user_data)
>
> I've implemented the callbacks with those arguments, as follows:
>
> void guac_spice_clipboard_selection_grab_handler(SpiceMainChannel channel,
> guint selection, gpointer types, guint ntypes, guac_client* client)
>
> void guac_spice_clipboard_selection_release_handler(SpiceMainChannel
> channel,
> guint selection, guac_client* client)
>

It looks correct. Can you point to your code connecting the signals with
the handlers?


>
> and registered them appropriately. However, if I use them as implemented
> above, when the callbacks are triggered, the application segfaults when I
> try to access the "guac_client* client" data structure. I used GDB to try
> to help track this down, and I noticed that the value of "client" was 0x1,
> which looks less like a pointer to a memory location and more like the
> number 1.
>
> So, I decided to add another argument to the callback functions, just
> before the client argument:
>
> void guac_spice_clipboard_selection_grab_handler(SpiceMainChannel channel,
> guint selection, gpointer types, guint ntypes, guint extra,
> guac_client* client)
>
> void guac_spice_clipboard_selection_release_handler(SpiceMainChannel
> channel,
> guint selection, guint extra, guac_client* client)
>
> Strangely, this works - the client data structure can be referenced, there
> are no segfaults (yet), etc. So, I decided to print the values that are
> being passed for all of these parameters, and I get the following:
>
> guacd[100252]: DEBUG: Notifying client of clipboard grab in the guest.
> guacd[100252]: DEBUG: Arg: channel: 0x
> guacd[100252]: DEBUG: Arg: selection: 1275303536
> guacd[100252]: DEBUG: Arg: types: 0x0001
> guacd[100252]: DEBUG: Arg: ntypes: 1276022924
> guacd[100252]: DEBUG: Arg: extra: 1
>
>
Weird


> I printed them in the format I thought they should be in based on what the
> arguments are supposed to be - I probably should have just done all hex.
> But, it seems like maybe the "extra" parameter being passed is in front of
> the channel, since the channel is showing up as all zeros?
>
> I was trying to find the code where the callbacks are actually called -
> I'm guessing, since this is clipboard integration, it'll be in the vdagent
> code somewhere - but I was having trouble tracking that down.
>
>
The callbacks are not directly called, since those a GObject signals. The
main channel will call g_signal_emit().



> If anyone has any ideas, I'd appreciate the insight into this - I'm
> puzzled by this apparent mismatch in the number of arguments. Also, if it
> matters, I'm running CentOS 8 Stream, using Xspice to provide a test SPICE
> server, and running spice-vdagentd/spice-vdagent within my X session. Yes,
> I know Xspice is unmaintained, but I just needed something simple and that
> I didn't have to spend a bunch of time building in order to give me a spice
> server to point at, and, so far, this has been pretty reliable. Also, at
> its core, it appears to use the same spice-qxl X driver that x11spice uses,
> just with a simple Python wrapper script for generating an X config file
> and starting the X server/display. So, I think it's still pretty "safe" for
> attempting to develop this Guacamole integration - if for some reason you
> believe me to be wrong about that, please let me know.
>

Your testing environment shouldn't be a problem, it's really your
client-side code integration with spice-glib that looks broken.

-- 
Marc-André Lureau


[Spice-devel] Issues with Clipboard Grab/Release Callbacks

2022-06-20 Thread Nick Couchman
Hello, everyone,
I've posted here, before, with some questions during my journey of trying
to add support for the SPICE protocol to the Guacamole project. The good
news is that I've actually made measurable progress in the implementation -
I can now connect to a SPICE server, and the basics work (mouse and
keyboard - mostly anyway), so I'm moving on to the extra stuff - clipboard,
audio, file transfer, etc.

In working on the clipboard integration, I'm currently running into an
issue with a couple of the callback functions, specifically the clipboard
grab/release functions, where the number of arguments seems to be
mismatched. According to the documentation, these callbacks should be
called with the following arguments:

gboolean
user_function (SpiceMainChannel *main,
   guint selection,
   gpointer  types,
   guint ntypes,
   gpointer  user_data)

void
user_function (SpiceMainChannel *main,
   guint selection,
   gpointer  user_data)

I've implemented the callbacks with those arguments, as follows:

void guac_spice_clipboard_selection_grab_handler(SpiceMainChannel channel,
guint selection, gpointer types, guint ntypes, guac_client* client)

void guac_spice_clipboard_selection_release_handler(SpiceMainChannel
channel,
guint selection, guac_client* client)

and registered them appropriately. However, if I use them as implemented
above, when the callbacks are triggered, the application segfaults when I
try to access the "guac_client* client" data structure. I used GDB to try
to help track this down, and I noticed that the value of "client" was 0x1,
which looks less like a pointer to a memory location and more like the
number 1.

So, I decided to add another argument to the callback functions, just
before the client argument:

void guac_spice_clipboard_selection_grab_handler(SpiceMainChannel channel,
guint selection, gpointer types, guint ntypes, guint extra,
guac_client* client)

void guac_spice_clipboard_selection_release_handler(SpiceMainChannel
channel,
guint selection, guint extra, guac_client* client)

Strangely, this works - the client data structure can be referenced, there
are no segfaults (yet), etc. So, I decided to print the values that are
being passed for all of these parameters, and I get the following:

guacd[100252]: DEBUG: Notifying client of clipboard grab in the guest.
guacd[100252]: DEBUG: Arg: channel: 0x
guacd[100252]: DEBUG: Arg: selection: 1275303536
guacd[100252]: DEBUG: Arg: types: 0x0001
guacd[100252]: DEBUG: Arg: ntypes: 1276022924
guacd[100252]: DEBUG: Arg: extra: 1

I printed them in the format I thought they should be in based on what the
arguments are supposed to be - I probably should have just done all hex.
But, it seems like maybe the "extra" parameter being passed is in front of
the channel, since the channel is showing up as all zeros?

I was trying to find the code where the callbacks are actually called - I'm
guessing, since this is clipboard integration, it'll be in the vdagent code
somewhere - but I was having trouble tracking that down.

If anyone has any ideas, I'd appreciate the insight into this - I'm puzzled
by this apparent mismatch in the number of arguments. Also, if it matters,
I'm running CentOS 8 Stream, using Xspice to provide a test SPICE server,
and running spice-vdagentd/spice-vdagent within my X session. Yes, I know
Xspice is unmaintained, but I just needed something simple and that I
didn't have to spend a bunch of time building in order to give me a spice
server to point at, and, so far, this has been pretty reliable. Also, at
its core, it appears to use the same spice-qxl X driver that x11spice uses,
just with a simple Python wrapper script for generating an X config file
and starting the X server/display. So, I think it's still pretty "safe" for
attempting to develop this Guacamole integration - if for some reason you
believe me to be wrong about that, please let me know.

Thanks,
Nick