smartcard: Use generated parse for messages

The generated code handle possible endianess mismatch and check
for message format.
The copy back to "write_buf" allows to use that buffer to send
data back to device.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
This commit is contained in:
Frediano Ziglio 2019-10-05 21:35:31 +01:00
parent 5d2b204e48
commit bae2d1f00f
2 changed files with 4 additions and 4 deletions

View File

@ -274,17 +274,15 @@ bool smartcard_channel_client_handle_message(RedChannelClient *rcc,
uint32_t size,
void *message)
{
uint8_t *msg = message;
VSCMsgHeader* vheader = message;
SmartCardChannelClient *scc = SMARTCARD_CHANNEL_CLIENT(rcc);
if (type != SPICE_MSGC_SMARTCARD_DATA) {
/* Handles seamless migration protocol. Also handles ack's,
* spicy sends them while spicec does not */
return red_channel_client_handle_message(rcc, type, size, msg);
return red_channel_client_handle_message(rcc, type, size, message);
}
spice_assert(size == vheader->length + sizeof(VSCMsgHeader));
switch (vheader->type) {
case VSC_ReaderAdd:
smartcard_channel_client_add_reader(scc);
@ -315,7 +313,8 @@ bool smartcard_channel_client_handle_message(RedChannelClient *rcc,
vheader->reader_id, vheader->type, vheader->length);
return FALSE;
}
spice_assert(scc->priv->write_buf->buf == msg);
spice_assert(scc->priv->write_buf->buf_size >= size);
memcpy(scc->priv->write_buf->buf, message, size);
smartcard_channel_client_write_to_reader(scc);
return TRUE;

View File

@ -547,6 +547,7 @@ red_smartcard_channel_class_init(RedSmartcardChannelClass *klass)
object_class->constructed = red_smartcard_channel_constructed;
channel_class->parser = spice_get_client_channel_parser(SPICE_CHANNEL_SMARTCARD, NULL);
channel_class->handle_message = smartcard_channel_client_handle_message,
channel_class->send_item = smartcard_channel_send_item;