[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH RFC 4/6] qemu-xen-trad: sasl: compatibility with vnc.h
This change adjusts vnc.c for compatibility with the API defined in vnc.h. Signed-off-by: Simon Waterman <watermansrdev@xxxxxxxxx> --- vnc.c | 212 +++++++++--------------------------------------------------------- 1 file changed, 27 insertions(+), 185 deletions(-) diff --git a/vnc.c b/vnc.c index 0e61197..728efec 100644 --- a/vnc.c +++ b/vnc.c @@ -24,6 +24,7 @@ * THE SOFTWARE. */ +#include "vnc.h" #include "qemu-common.h" #include "console.h" #include "sysemu.h" @@ -50,8 +51,6 @@ minimised vncviewer reasonably quickly. */ #define VNC_MAX_UPDATE_INTERVAL 5000 -#include "vnc_keysym.h" -#include "keymaps.c" #include "d3des.h" #ifdef CONFIG_VNC_TLS @@ -59,21 +58,6 @@ #include <gnutls/x509.h> #endif /* CONFIG_VNC_TLS */ -// #define _VNC_DEBUG 1 - -#ifdef _VNC_DEBUG -#define VNC_DEBUG(fmt, ...) do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0) - -#if defined(CONFIG_VNC_TLS) && _VNC_DEBUG >= 2 -/* Very verbose, so only enabled for _VNC_DEBUG >= 2 */ -static void vnc_debug_gnutls_log(int level, const char* str) { - VNC_DEBUG("%d %s", level, str); -} -#endif /* CONFIG_VNC_TLS && _VNC_DEBUG */ -#else -#define VNC_DEBUG(fmt, ...) do { } while (0) -#endif - #define count_bits(c, v) { \ for (c = 0; v; v >>= 1) \ { \ @@ -81,157 +65,13 @@ static void vnc_debug_gnutls_log(int level, const char* str) { } \ } -typedef struct Buffer -{ - size_t capacity; - size_t offset; - uint8_t *buffer; -} Buffer; - -typedef struct VncState VncState; - -typedef int VncReadEvent(VncState *vs, uint8_t *data, size_t len); - -typedef void VncWritePixels(VncState *vs, void *data, int size); - -typedef void VncSendHextileTile(VncState *vs, - int x, int y, int w, int h, - void *last_bg, - void *last_fg, - int *has_bg, int *has_fg); - -#if 0 -#define VNC_MAX_WIDTH 2048 -#define VNC_MAX_HEIGHT 2048 -#define VNC_DIRTY_WORDS (VNC_MAX_WIDTH / (16 * 32)) -#endif - -#define VNC_AUTH_CHALLENGE_SIZE 16 - -enum { - VNC_AUTH_INVALID = 0, - VNC_AUTH_NONE = 1, - VNC_AUTH_VNC = 2, - VNC_AUTH_RA2 = 5, - VNC_AUTH_RA2NE = 6, - VNC_AUTH_TIGHT = 16, - VNC_AUTH_ULTRA = 17, - VNC_AUTH_TLS = 18, - VNC_AUTH_VENCRYPT = 19 -}; - #ifdef CONFIG_VNC_TLS enum { VNC_WIREMODE_CLEAR, VNC_WIREMODE_TLS, }; - -enum { - VNC_AUTH_VENCRYPT_PLAIN = 256, - VNC_AUTH_VENCRYPT_TLSNONE = 257, - VNC_AUTH_VENCRYPT_TLSVNC = 258, - VNC_AUTH_VENCRYPT_TLSPLAIN = 259, - VNC_AUTH_VENCRYPT_X509NONE = 260, - VNC_AUTH_VENCRYPT_X509VNC = 261, - VNC_AUTH_VENCRYPT_X509PLAIN = 262, -}; - -#define X509_CA_CERT_FILE "ca-cert.pem" -#define X509_CA_CRL_FILE "ca-crl.pem" -#define X509_SERVER_KEY_FILE "server-key.pem" -#define X509_SERVER_CERT_FILE "server-cert.pem" - #endif /* CONFIG_VNC_TLS */ -#define QUEUE_ALLOC_UNIT 10 - -typedef struct _QueueItem -{ - int x, y, w, h; - int32_t enc; - struct _QueueItem *next; -} QueueItem; - -typedef struct _Queue -{ - QueueItem *queue_start; - int start_count; - QueueItem *queue_end; - int end_count; -} Queue; - -struct VncState -{ - QEMUTimer *timer; - int timer_interval; - int64_t last_update_time; - int lsock; - int csock; - DisplayState *ds; - uint64_t *dirty_row; /* screen regions which are possibly dirty */ - int dirty_pixel_shift; - uint64_t *update_row; /* outstanding updates */ - int has_update; /* there's outstanding updates in the - * visible area */ - - int update_requested; /* the client requested an update */ - - uint8_t *old_data; - int has_resize; - int has_hextile; - int has_pointer_type_change; - int has_WMVi; - int absolute; - int last_x; - int last_y; - - int major; - int minor; - - char *display; - char *password; - int auth; -#ifdef CONFIG_VNC_TLS - int subauth; - int x509verify; - - char *x509cacert; - char *x509cacrl; - char *x509cert; - char *x509key; -#endif - char challenge[VNC_AUTH_CHALLENGE_SIZE]; - int switchbpp; - -#ifdef CONFIG_VNC_TLS - int wiremode; - gnutls_session_t tls_session; -#endif - - Buffer output; - Buffer input; - - Queue upqueue; - - kbd_layout_t *kbd_layout; - /* current output mode information */ - VncWritePixels *write_pixels; - VncSendHextileTile *send_hextile_tile; - DisplaySurface clientds, serverds; - - VncReadEvent *read_handler; - size_t read_handler_expect; - - int visible_x; - int visible_y; - int visible_w; - int visible_h; - - /* input */ - uint8_t modifiers_state[256]; -}; - -static VncState *vnc_state; /* needed for info vnc */ static DisplayChangeListener *dcl; #define DIRTY_PIXEL_BITS 64 @@ -263,15 +103,10 @@ void do_info_vnc(void) 3) resolutions > 1024 */ -static void vnc_write(VncState *vs, const void *data, size_t len); -static void vnc_write_u32(VncState *vs, uint32_t value); static void vnc_write_s32(VncState *vs, int32_t value); static void vnc_write_u16(VncState *vs, uint16_t value); -static void vnc_write_u8(VncState *vs, uint8_t value); -static void vnc_flush(VncState *vs); static void _vnc_update_client(void *opaque); static void vnc_update_client(void *opaque); -static void vnc_client_read(void *opaque); static void framebuffer_set_updated(VncState *vs, int x, int y, int w, int h); static void pixel_format_message (VncState *vs); static void enqueue_framebuffer_update(VncState *vs, int x, int y, int w, int h, int32_t encoding); @@ -781,7 +616,7 @@ static int vnc_listen_poll(void *opaque) return 0; } -static void buffer_reserve(Buffer *buffer, size_t len) +void buffer_reserve(Buffer *buffer, size_t len) { if ((buffer->capacity - buffer->offset) < len) { buffer->capacity += (len + 1024); @@ -808,12 +643,19 @@ static void buffer_reset(Buffer *buffer) buffer->offset = 0; } -static void buffer_append(Buffer *buffer, const void *data, size_t len) +void buffer_append(Buffer *buffer, const void *data, size_t len) { memcpy(buffer->buffer + buffer->offset, data, len); buffer->offset += len; } +static void buffer_advance(Buffer *buf, size_t len) +{ + memmove(buf->buffer, buf->buffer + len, + (buf->offset - len)); + buf->offset -= len; +} + static void enqueue_framebuffer_update(VncState *vs, int x, int y, int w, int h, int32_t encoding) { @@ -896,7 +738,7 @@ static void free_queue(VncState *vs) q->end_count = 0; } -static int vnc_client_io_error(VncState *vs, int ret, int last_errno) +int vnc_client_io_error(VncState *vs, int ret, int last_errno) { if (ret == 0 || ret == -1) { if (ret == -1) { @@ -933,7 +775,7 @@ static int vnc_client_io_error(VncState *vs, int ret, int last_errno) return ret; } -static void vnc_client_error(VncState *vs) +void vnc_client_error(VncState *vs) { vnc_client_io_error(vs, -1, EINVAL); } @@ -960,9 +802,7 @@ static void vnc_client_write(void *opaque) if (!ret) return; - memmove(vs->output.buffer, vs->output.buffer + ret, - vs->output.offset - ret); - vs->output.offset -= ret; + buffer_advance(&vs->output, ret); if (vs->output.offset == 0) qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs); @@ -974,7 +814,7 @@ static void vnc_read_when(VncState *vs, VncReadEvent *func, size_t expecting) vs->read_handler_expect = expecting; } -static void vnc_client_read(void *opaque) +void vnc_client_read(void *opaque) { VncState *vs = opaque; long ret; @@ -1009,9 +849,7 @@ static void vnc_client_read(void *opaque) return; if (!ret) { - memmove(vs->input.buffer, vs->input.buffer + len, - vs->input.offset - len); - vs->input.offset -= len; + buffer_advance(&vs->input, len); } else { assert(ret > vs->read_handler_expect); vs->read_handler_expect = ret; @@ -1019,7 +857,7 @@ static void vnc_client_read(void *opaque) } } -static void vnc_write(VncState *vs, const void *data, size_t len) +void vnc_write(VncState *vs, const void *data, size_t len) { buffer_reserve(&vs->output, len); @@ -1035,7 +873,7 @@ static void vnc_write_s32(VncState *vs, int32_t value) vnc_write_u32(vs, *(uint32_t *)&value); } -static void vnc_write_u32(VncState *vs, uint32_t value) +void vnc_write_u32(VncState *vs, uint32_t value) { uint8_t buf[4]; @@ -1057,12 +895,12 @@ static void vnc_write_u16(VncState *vs, uint16_t value) vnc_write(vs, buf, 2); } -static void vnc_write_u8(VncState *vs, uint8_t value) +void vnc_write_u8(VncState *vs, uint8_t value) { vnc_write(vs, &value, 1); } -static void vnc_flush(VncState *vs) +void vnc_flush(VncState *vs) { if (vs->output.offset) vnc_client_write(vs); @@ -1084,7 +922,7 @@ static int32_t read_s32(uint8_t *data, size_t offset) (data[offset + 2] << 8) | data[offset + 3]); } -static uint32_t read_u32(uint8_t *data, size_t offset) +uint32_t read_u32(uint8_t *data, size_t offset) { return ((data[offset] << 24) | (data[offset + 1] << 16) | (data[offset + 2] << 8) | data[offset + 3]); @@ -1788,6 +1626,10 @@ static int protocol_client_init(VncState *vs, uint8_t *data, size_t len) return 0; } +void start_client_init(VncState *vs) +{ + vnc_read_when(vs, protocol_client_init, 1); +} static void make_challenge(VncState *vs) { @@ -1844,7 +1686,7 @@ static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len) vnc_write_u32(vs, 0); /* Accept auth */ vnc_flush(vs); - vnc_read_when(vs, protocol_client_init, 1); + start_client_init(vs); } return 0; } @@ -2317,7 +2159,7 @@ static int protocol_client_auth(VncState *vs, uint8_t *data, size_t len) vnc_write_u32(vs, 0); /* Accept auth completion */ vnc_flush(vs); } - vnc_read_when(vs, protocol_client_init, 1); + start_client_init(vs); break; case VNC_AUTH_VNC: @@ -2380,7 +2222,7 @@ static int protocol_version(VncState *vs, uint8_t *version, size_t len) VNC_DEBUG("Tell client auth none\n"); vnc_write_u32(vs, vs->auth); vnc_flush(vs); - vnc_read_when(vs, protocol_client_init, 1); + start_client_init(vs); } else if (vs->auth == VNC_AUTH_VNC) { VNC_DEBUG("Tell client VNC auth\n"); vnc_write_u32(vs, vs->auth); -- 2.7.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |