diff options
-rw-r--r-- | udscs.c | 20 | ||||
-rw-r--r-- | udscs.h | 10 | ||||
-rw-r--r-- | vdagent-x11.c | 29 | ||||
-rw-r--r-- | vdagentd-proto-strings.h | 34 | ||||
-rw-r--r-- | vdagentd.c | 57 |
5 files changed, 79 insertions, 71 deletions
@@ -306,17 +306,18 @@ void udscs_client_handle_fds(struct udscs_connection **connp, fd_set *readfds, udscs_do_write(connp); } -int udscs_write(struct udscs_connection *conn, - struct udscs_message_header *header, const uint8_t *data) +int udscs_write(struct udscs_connection *conn, uint32_t type, uint32_t opaque, + const uint8_t *data, uint32_t size) { struct udscs_buf *wbuf, *new_wbuf; + struct udscs_message_header header; new_wbuf = malloc(sizeof(*new_wbuf)); if (!new_wbuf) return -1; new_wbuf->pos = 0; - new_wbuf->size = sizeof(*header) + header->size; + new_wbuf->size = sizeof(header) + size; new_wbuf->next = NULL; new_wbuf->buf = malloc(new_wbuf->size); if (!new_wbuf->buf) { @@ -324,8 +325,12 @@ int udscs_write(struct udscs_connection *conn, return -1; } - memcpy(new_wbuf->buf, header, sizeof(*header)); - memcpy(new_wbuf->buf + sizeof(*header), data, header->size); + header.type = type; + header.opaque = opaque; + header.size = size; + + memcpy(new_wbuf->buf, &header, sizeof(header)); + memcpy(new_wbuf->buf + sizeof(header), data, size); if (!conn->write_buf) { conn->write_buf = new_wbuf; @@ -343,13 +348,14 @@ int udscs_write(struct udscs_connection *conn, } int udscs_server_write_all(struct udscs_server *server, - struct udscs_message_header *header, const uint8_t *data) + uint32_t type, uint32_t opaque, + const uint8_t *data, uint32_t size) { struct udscs_connection *conn; conn = server->connections_head.next; while (conn) { - if (udscs_write(conn, header, data)) + if (udscs_write(conn, type, opaque, data, size)) return -1; conn = conn->next; } @@ -91,16 +91,16 @@ void udscs_client_handle_fds(struct udscs_connection **connp, fd_set *readfds, fd_set *writefds); -/* Queue the message described by header and header->size bytes of additional - data bytes for delivery to the vdagent connected through conn. +/* Queue a message for delivery to the client connected through conn. Returns 0 on success -1 on error (only happens when malloc fails) */ -int udscs_write(struct udscs_connection *conn, - struct udscs_message_header *header, const uint8_t *data); +int udscs_write(struct udscs_connection *conn, uint32_t type, uint32_t opaque, + const uint8_t *data, uint32_t size); /* Like udscs_write, but then send the message to all clients connected to the server */ int udscs_server_write_all(struct udscs_server *server, - struct udscs_message_header *header, const uint8_t *data); + uint32_t type, uint32_t opaque, + const uint8_t *data, uint32_t size); #endif diff --git a/vdagent-x11.c b/vdagent-x11.c index 9ea9e7e..3de2b58 100644 --- a/vdagent-x11.c +++ b/vdagent-x11.c @@ -201,48 +201,33 @@ void vdagent_x11_do_read(struct vdagent_x11 *x11) static void vdagent_x11_send_daemon_guest_xorg_res(struct vdagent_x11 *x11) { struct vdagentd_guest_xorg_resolution res; - struct udscs_message_header header; - - header.type = VDAGENTD_GUEST_XORG_RESOLUTION; - header.opaque = 0; - header.size = sizeof(res); res.width = x11->width; res.height = x11->height; - udscs_write(x11->vdagentd, &header, (uint8_t *)&res); + udscs_write(x11->vdagentd, VDAGENTD_GUEST_XORG_RESOLUTION, 0, + (uint8_t *)&res, sizeof(res)); } static void vdagent_x11_send_daemon_clipboard_grab(struct vdagent_x11 *x11) { - struct udscs_message_header header; - - header.type = VDAGENTD_CLIPBOARD_GRAB; /* FIXME plenty, we need to request the selection with a type of TARGETS and then compare the TARGETS against our list of known UTF-8 targets. */ - header.opaque = VD_AGENT_CLIPBOARD_UTF8_TEXT; - header.size = 0; + uint32_t type = VD_AGENT_CLIPBOARD_UTF8_TEXT; - udscs_write(x11->vdagentd, &header, NULL); + udscs_write(x11->vdagentd, VDAGENTD_CLIPBOARD_GRAB, type, NULL, 0); if (x11->verbose) - fprintf(stderr, "Claimed clipboard ownership, type: %u\n", - header.opaque); + fprintf(stderr, "Claimed clipboard ownership, type: %u\n", type); } static void vdagent_x11_send_daemon_clipboard_data(struct vdagent_x11 *x11, uint32_t type, uint8_t *data, uint32_t size) { - struct udscs_message_header header; - - header.type = VDAGENTD_CLIPBOARD_DATA; - header.opaque = type; - header.size = size; - - udscs_write(x11->vdagentd, &header, data); + udscs_write(x11->vdagentd, VDAGENTD_CLIPBOARD_DATA, type, data, size); if (x11->verbose) fprintf(stderr, "Send clipboard data, type: %u, size: %u\n", - header.opaque, header.size); + type, size); } static void vdagent_x11_handle_selection_notify(struct vdagent_x11 *x11, diff --git a/vdagentd-proto-strings.h b/vdagentd-proto-strings.h new file mode 100644 index 0000000..02adf01 --- /dev/null +++ b/vdagentd-proto-strings.h @@ -0,0 +1,34 @@ +/* vdagentd-proto-strings.h header file + + Copyright 2010 Red Hat, Inc. + + Red Hat Authors: + Hans de Goede <hdegoede@redhat.com> + + 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/>. +*/ + +#ifndef __VDAGENTD_PROTO_STRINGS_H +#define __VDAGENTD_PROTO_STRINGS_H + +static const char * const vdagentd_messages[] = { + "guest xorg resolution", + "monitors config", + "clipboard grab", + "clipboard request", + "clipboard data", + "clipboard release", +}; + +#endif @@ -76,7 +76,6 @@ static void do_monitors(struct vdagent_virtio_port *port, int port_nr, VDAgentMessage *message_header, VDAgentMonitorsConfig *new_monitors) { VDAgentReply reply; - struct udscs_message_header udscs_header; uint32_t size; /* Store monitor config to send to agents when they connect */ @@ -99,10 +98,8 @@ static void do_monitors(struct vdagent_virtio_port *port, int port_nr, memcpy(mon_config, new_monitors, size); /* Send monitor config to currently connected agents */ - udscs_header.type = VDAGENTD_MONITORS_CONFIG; - udscs_header.opaque = 0; - udscs_header.size = size; - udscs_server_write_all(server, &udscs_header, (uint8_t *)mon_config); + udscs_server_write_all(server, VDAGENTD_MONITORS_CONFIG, 0, + (uint8_t *)mon_config, size); /* Acknowledge reception of monitors config to spice server / client */ reply.type = VD_AGENT_MONITORS_CONFIG; @@ -133,15 +130,14 @@ static void do_capabilities(struct vdagent_virtio_port *port, static void do_clipboard(struct vdagent_virtio_port *port, VDAgentMessage *message_header, uint8_t *message_data) { - struct udscs_message_header udscs_header; - uint8_t *udscs_data = NULL; + uint32_t type = 0, opaque = 0, size = 0; + uint8_t *data = NULL; switch (message_header->type) { case VD_AGENT_CLIPBOARD_GRAB: { VDAgentClipboardGrab *grab = (VDAgentClipboardGrab *)message_data; - udscs_header.type = VDAGENTD_CLIPBOARD_GRAB; - udscs_header.opaque = grab->type; - udscs_header.size = 0; + type = VDAGENTD_CLIPBOARD_GRAB; + opaque = grab->type; if (debug) fprintf(stderr, "Client claimed clipboard owner ship type %u\n", grab->type); @@ -149,9 +145,8 @@ static void do_clipboard(struct vdagent_virtio_port *port, } case VD_AGENT_CLIPBOARD_REQUEST: { VDAgentClipboardRequest *req = (VDAgentClipboardRequest *)message_data; - udscs_header.type = VDAGENTD_CLIPBOARD_REQUEST; - udscs_header.opaque = req->type; - udscs_header.size = 0; + type = VDAGENTD_CLIPBOARD_REQUEST; + opaque = req->type; if (debug) fprintf(stderr, "Client send clipboard request type %u\n", req->type); @@ -159,26 +154,24 @@ static void do_clipboard(struct vdagent_virtio_port *port, } case VD_AGENT_CLIPBOARD: { VDAgentClipboard *clipboard = (VDAgentClipboard *)message_data; - udscs_header.type = VDAGENTD_CLIPBOARD_DATA; - udscs_header.opaque = clipboard->type; - udscs_header.size = message_header->size - sizeof(VDAgentClipboard); - udscs_data = clipboard->data; + type = VDAGENTD_CLIPBOARD_DATA; + opaque = clipboard->type; + size = message_header->size - sizeof(VDAgentClipboard); + data = clipboard->data; if (debug) fprintf(stderr, "Client send clipboard data type %u\n", clipboard->type); break; } case VD_AGENT_CLIPBOARD_RELEASE: - udscs_header.type = VDAGENTD_CLIPBOARD_RELEASE; - udscs_header.opaque = 0; - udscs_header.size = 0; + type = VDAGENTD_CLIPBOARD_RELEASE; if (debug) fprintf(stderr, "Client released clipboard\n"); break; } /* FIXME send only to agent in active session */ - udscs_server_write_all(server, &udscs_header, udscs_data); + udscs_server_write_all(server, type, opaque, data, size); } int virtio_port_read_complete( @@ -312,31 +305,21 @@ void do_client_clipboard(struct udscs_connection *conn, error: if (header->type == VDAGENTD_CLIPBOARD_REQUEST) { /* Let the agent know no answer is coming */ - struct udscs_message_header udscs_header; - - udscs_header.type = VDAGENTD_CLIPBOARD_DATA; - udscs_header.opaque = VD_AGENT_CLIPBOARD_NONE; - udscs_header.size = 0; - - udscs_write(conn, &udscs_header, NULL); + udscs_write(conn, VDAGENTD_CLIPBOARD_DATA, + VD_AGENT_CLIPBOARD_NONE, NULL, 0); } } void client_connect(struct udscs_connection *conn) { - struct udscs_message_header udscs_header; - /* We don't create the tablet until we've gotten the xorg resolution from the vdagent client */ connection_count++; - if (mon_config) { - udscs_header.type = VDAGENTD_MONITORS_CONFIG; - udscs_header.opaque = 0; - udscs_header.size = sizeof(VDAgentMonitorsConfig) + - mon_config->num_of_monitors * sizeof(VDAgentMonConfig); - udscs_write(conn, &udscs_header, (uint8_t *)mon_config); - } + if (mon_config) + udscs_write(conn, VDAGENTD_MONITORS_CONFIG, 0, (uint8_t *)mon_config, + sizeof(VDAgentMonitorsConfig) + + mon_config->num_of_monitors * sizeof(VDAgentMonConfig)); } void client_disconnect(struct udscs_connection *conn) |