Lines Matching refs:vs
207 static inline uint32_t vnc_has_feature(VncState *vs, int feature) { in vnc_has_feature() argument
208 return (vs->features & (1 << feature)); in vnc_has_feature()
219 static void vnc_disconnect_start(VncState *vs);
220 static void vnc_disconnect_finish(VncState *vs);
222 static void vnc_colordepth(VncState *vs);
265 static void vnc_update(VncState *vs, int x, int y, int w, int h) in vnc_update() argument
267 struct VncSurface *s = &vs->guest; in vnc_update()
292 VncState *vs = vd->clients; in vnc_dpy_update() local
293 while (vs != NULL) { in vnc_dpy_update()
294 vnc_update(vs, x, y, w, h); in vnc_dpy_update()
295 vs = vs->next; in vnc_dpy_update()
299 static void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h, in vnc_framebuffer_update() argument
302 vnc_write_u16(vs, x); in vnc_framebuffer_update()
303 vnc_write_u16(vs, y); in vnc_framebuffer_update()
304 vnc_write_u16(vs, w); in vnc_framebuffer_update()
305 vnc_write_u16(vs, h); in vnc_framebuffer_update()
307 vnc_write_s32(vs, encoding); in vnc_framebuffer_update()
343 static void vnc_resize(VncState *vs) in vnc_resize() argument
345 DisplayState *ds = vs->ds; in vnc_resize()
349 if (!vs->guest.ds) in vnc_resize()
350 vs->guest.ds = qemu_mallocz(sizeof(*vs->guest.ds)); in vnc_resize()
351 if (ds_get_bytes_per_pixel(ds) != vs->guest.ds->pf.bytes_per_pixel) in vnc_resize()
353 vnc_colordepth(vs); in vnc_resize()
354 size_changed = ds_get_width(ds) != vs->guest.ds->width || in vnc_resize()
355 ds_get_height(ds) != vs->guest.ds->height; in vnc_resize()
356 *(vs->guest.ds) = *(ds->surface); in vnc_resize()
358 if (vs->csock != -1 && vnc_has_feature(vs, VNC_FEATURE_RESIZE)) { in vnc_resize()
359 vnc_write_u8(vs, 0); /* msg id */ in vnc_resize()
360 vnc_write_u8(vs, 0); in vnc_resize()
361 vnc_write_u16(vs, 1); /* number of rects */ in vnc_resize()
362 vnc_framebuffer_update(vs, 0, 0, ds_get_width(ds), ds_get_height(ds), in vnc_resize()
364 vnc_flush(vs); in vnc_resize()
367 memset(vs->guest.dirty, 0xFF, sizeof(vs->guest.dirty)); in vnc_resize()
370 if (!vs->server.ds) in vnc_resize()
371 vs->server.ds = qemu_mallocz(sizeof(*vs->server.ds)); in vnc_resize()
372 if (vs->server.ds->data) in vnc_resize()
373 qemu_free(vs->server.ds->data); in vnc_resize()
374 *(vs->server.ds) = *(ds->surface); in vnc_resize()
375 vs->server.ds->data = qemu_mallocz(vs->server.ds->linesize * in vnc_resize()
376 vs->server.ds->height); in vnc_resize()
377 memset(vs->server.dirty, 0xFF, sizeof(vs->guest.dirty)); in vnc_resize()
383 VncState *vs = vd->clients; in vnc_dpy_resize() local
384 while (vs != NULL) { in vnc_dpy_resize()
385 vnc_resize(vs); in vnc_dpy_resize()
386 vs = vs->next; in vnc_dpy_resize()
391 static void vnc_write_pixels_copy(VncState *vs, void *pixels, int size) in vnc_write_pixels_copy() argument
393 vnc_write(vs, pixels, size); in vnc_write_pixels_copy()
397 static void vnc_convert_pixel(VncState *vs, uint8_t *buf, uint32_t v) in vnc_convert_pixel() argument
401 r = ((((v & vs->server.ds->pf.rmask) >> vs->server.ds->pf.rshift) << vs->clientds.pf.rbits) >> in vnc_convert_pixel()
402 vs->server.ds->pf.rbits); in vnc_convert_pixel()
403 g = ((((v & vs->server.ds->pf.gmask) >> vs->server.ds->pf.gshift) << vs->clientds.pf.gbits) >> in vnc_convert_pixel()
404 vs->server.ds->pf.gbits); in vnc_convert_pixel()
405 b = ((((v & vs->server.ds->pf.bmask) >> vs->server.ds->pf.bshift) << vs->clientds.pf.bbits) >> in vnc_convert_pixel()
406 vs->server.ds->pf.bbits); in vnc_convert_pixel()
407 v = (r << vs->clientds.pf.rshift) | in vnc_convert_pixel()
408 (g << vs->clientds.pf.gshift) | in vnc_convert_pixel()
409 (b << vs->clientds.pf.bshift); in vnc_convert_pixel()
410 switch(vs->clientds.pf.bytes_per_pixel) { in vnc_convert_pixel()
415 if (vs->clientds.flags & QEMU_BIG_ENDIAN_FLAG) { in vnc_convert_pixel()
425 if (vs->clientds.flags & QEMU_BIG_ENDIAN_FLAG) { in vnc_convert_pixel()
440 static void vnc_write_pixels_generic(VncState *vs, void *pixels1, int size) in vnc_write_pixels_generic() argument
444 if (vs->server.ds->pf.bytes_per_pixel == 4) { in vnc_write_pixels_generic()
449 vnc_convert_pixel(vs, buf, pixels[i]); in vnc_write_pixels_generic()
450 vnc_write(vs, buf, vs->clientds.pf.bytes_per_pixel); in vnc_write_pixels_generic()
452 } else if (vs->server.ds->pf.bytes_per_pixel == 2) { in vnc_write_pixels_generic()
457 vnc_convert_pixel(vs, buf, pixels[i]); in vnc_write_pixels_generic()
458 vnc_write(vs, buf, vs->clientds.pf.bytes_per_pixel); in vnc_write_pixels_generic()
460 } else if (vs->server.ds->pf.bytes_per_pixel == 1) { in vnc_write_pixels_generic()
465 vnc_convert_pixel(vs, buf, pixels[i]); in vnc_write_pixels_generic()
466 vnc_write(vs, buf, vs->clientds.pf.bytes_per_pixel); in vnc_write_pixels_generic()
473 static void send_framebuffer_update_raw(VncState *vs, int x, int y, int w, int h) in send_framebuffer_update_raw() argument
478 row = vs->server.ds->data + y * ds_get_linesize(vs->ds) + x * ds_get_bytes_per_pixel(vs->ds); in send_framebuffer_update_raw()
480 vs->write_pixels(vs, row, w * ds_get_bytes_per_pixel(vs->ds)); in send_framebuffer_update_raw()
481 row += ds_get_linesize(vs->ds); in send_framebuffer_update_raw()
521 static void send_framebuffer_update_hextile(VncState *vs, int x, int y, int w, int h) in send_framebuffer_update_hextile() argument
527 last_fg = (uint8_t *) qemu_malloc(vs->server.ds->pf.bytes_per_pixel); in send_framebuffer_update_hextile()
528 last_bg = (uint8_t *) qemu_malloc(vs->server.ds->pf.bytes_per_pixel); in send_framebuffer_update_hextile()
532 vs->send_hextile_tile(vs, i, j, in send_framebuffer_update_hextile()
542 static void vnc_zlib_init(VncState *vs) in vnc_zlib_init() argument
545 for (i=0; i<(sizeof(vs->zlib_stream) / sizeof(z_stream)); i++) in vnc_zlib_init()
546 vs->zlib_stream[i].opaque = NULL; in vnc_zlib_init()
549 static void vnc_zlib_start(VncState *vs) in vnc_zlib_start() argument
551 buffer_reset(&vs->zlib); in vnc_zlib_start()
554 vs->zlib_tmp = vs->output; in vnc_zlib_start()
555 vs->output = vs->zlib; in vnc_zlib_start()
558 static int vnc_zlib_stop(VncState *vs, int stream_id) in vnc_zlib_stop() argument
560 z_streamp zstream = &vs->zlib_stream[stream_id]; in vnc_zlib_stop()
564 vs->zlib = vs->output; in vnc_zlib_stop()
565 vs->output = vs->zlib_tmp; in vnc_zlib_stop()
571 if (zstream->opaque != vs) { in vnc_zlib_stop()
575 VNC_DEBUG("VNC: opaque = %p | vs = %p\n", zstream->opaque, vs); in vnc_zlib_stop()
579 err = deflateInit2(zstream, vs->tight_compression, Z_DEFLATED, MAX_WBITS, in vnc_zlib_stop()
587 zstream->opaque = vs; in vnc_zlib_stop()
593 buffer_reserve(&vs->output, vs->zlib.offset + 64); in vnc_zlib_stop()
596 zstream->next_in = vs->zlib.buffer; in vnc_zlib_stop()
597 zstream->avail_in = vs->zlib.offset; in vnc_zlib_stop()
598 zstream->next_out = vs->output.buffer + vs->output.offset; in vnc_zlib_stop()
599 zstream->avail_out = vs->output.capacity - vs->output.offset; in vnc_zlib_stop()
609 vs->output.offset = vs->output.capacity - zstream->avail_out; in vnc_zlib_stop()
613 static void send_framebuffer_update_zlib(VncState *vs, int x, int y, int w, int h) in send_framebuffer_update_zlib() argument
617 vnc_framebuffer_update(vs, x, y, w, h, VNC_ENCODING_ZLIB); in send_framebuffer_update_zlib()
620 old_offset = vs->output.offset; in send_framebuffer_update_zlib()
621 vnc_write_s32(vs, 0); in send_framebuffer_update_zlib()
624 vnc_zlib_start(vs); in send_framebuffer_update_zlib()
625 send_framebuffer_update_raw(vs, x, y, w, h); in send_framebuffer_update_zlib()
626 bytes_written = vnc_zlib_stop(vs, 0); in send_framebuffer_update_zlib()
632 new_offset = vs->output.offset; in send_framebuffer_update_zlib()
633 vs->output.offset = old_offset; in send_framebuffer_update_zlib()
634 vnc_write_u32(vs, bytes_written); in send_framebuffer_update_zlib()
635 vs->output.offset = new_offset; in send_framebuffer_update_zlib()
638 static void send_framebuffer_update(VncState *vs, int x, int y, int w, int h) in send_framebuffer_update() argument
640 switch(vs->vnc_encoding) { in send_framebuffer_update()
642 send_framebuffer_update_zlib(vs, x, y, w, h); in send_framebuffer_update()
645 vnc_framebuffer_update(vs, x, y, w, h, VNC_ENCODING_HEXTILE); in send_framebuffer_update()
646 send_framebuffer_update_hextile(vs, x, y, w, h); in send_framebuffer_update()
649 vnc_framebuffer_update(vs, x, y, w, h, VNC_ENCODING_RAW); in send_framebuffer_update()
650 send_framebuffer_update_raw(vs, x, y, w, h); in send_framebuffer_update()
655 static void vnc_copy(VncState *vs, int src_x, int src_y, int dst_x, int dst_y, int w, int h) in vnc_copy() argument
657 vnc_write_u8(vs, 0); /* msg id */ in vnc_copy()
658 vnc_write_u8(vs, 0); in vnc_copy()
659 vnc_write_u16(vs, 1); /* number of rects */ in vnc_copy()
660 vnc_framebuffer_update(vs, dst_x, dst_y, w, h, VNC_ENCODING_COPYRECT); in vnc_copy()
661 vnc_write_u16(vs, src_x); in vnc_copy()
662 vnc_write_u16(vs, src_y); in vnc_copy()
663 vnc_flush(vs); in vnc_copy()
669 VncState *vs, *vn; in vnc_dpy_copy() local
671 for (vs = vd->clients; vs != NULL; vs = vn) { in vnc_dpy_copy()
672 vn = vs->next; in vnc_dpy_copy()
673 if (vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) { in vnc_dpy_copy()
674 vs->force_update = 1; in vnc_dpy_copy()
675 vnc_update_client(vs); in vnc_dpy_copy()
680 for (vs = vd->clients; vs != NULL; vs = vs->next) { in vnc_dpy_copy()
681 if (vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) in vnc_dpy_copy()
682 vnc_copy(vs, src_x, src_y, dst_x, dst_y, w, h); in vnc_dpy_copy()
684 vnc_update(vs, dst_x, dst_y, w, h); in vnc_dpy_copy()
706 VncState *vs = opaque; in vnc_update_client() local
707 if (vs->need_update && vs->csock != -1) { in vnc_update_client()
717 if (vs->output.offset && !vs->audio_cap && !vs->force_update) { in vnc_update_client()
719 qemu_mod_timer(vs->timer, qemu_get_clock(rt_clock) + VNC_REFRESH_INTERVAL); in vnc_update_client()
730 vnc_set_bits(width_mask, (ds_get_width(vs->ds) / 16), VNC_DIRTY_WORDS); in vnc_update_client()
731 cmp_bytes = 16 * ds_get_bytes_per_pixel(vs->ds); in vnc_update_client()
732 guest_row = vs->guest.ds->data; in vnc_update_client()
733 server_row = vs->server.ds->data; in vnc_update_client()
734 for (y = 0; y < vs->guest.ds->height; y++) { in vnc_update_client()
735 if (vnc_and_bits(vs->guest.dirty[y], width_mask, VNC_DIRTY_WORDS)) { in vnc_update_client()
743 for (x = 0; x < vs->guest.ds->width; in vnc_update_client()
745 if (!vnc_get_bit(vs->guest.dirty[y], (x / 16))) in vnc_update_client()
747 vnc_clear_bit(vs->guest.dirty[y], (x / 16)); in vnc_update_client()
751 vnc_set_bit(vs->server.dirty[y], (x / 16)); in vnc_update_client()
755 guest_row += ds_get_linesize(vs->ds); in vnc_update_client()
756 server_row += ds_get_linesize(vs->ds); in vnc_update_client()
759 if (!has_dirty && !vs->audio_cap && !vs->force_update) { in vnc_update_client()
760 qemu_mod_timer(vs->timer, qemu_get_clock(rt_clock) + VNC_REFRESH_INTERVAL); in vnc_update_client()
771 vnc_write_u8(vs, 0); /* msg id */ in vnc_update_client()
772 vnc_write_u8(vs, 0); in vnc_update_client()
773 saved_offset = vs->output.offset; in vnc_update_client()
774 vnc_write_u16(vs, 0); in vnc_update_client()
776 for (y = 0; y < vs->server.ds->height; y++) { in vnc_update_client()
779 for (x = 0; x < vs->server.ds->width / 16; x++) { in vnc_update_client()
780 if (vnc_get_bit(vs->server.dirty[y], x)) { in vnc_update_client()
784 vnc_clear_bit(vs->server.dirty[y], x); in vnc_update_client()
787 int h = find_and_clear_dirty_height(&vs->server, y, last_x, x); in vnc_update_client()
788 send_framebuffer_update(vs, last_x * 16, y, (x - last_x) * 16, h); in vnc_update_client()
795 int h = find_and_clear_dirty_height(&vs->server, y, last_x, x); in vnc_update_client()
796 send_framebuffer_update(vs, last_x * 16, y, (x - last_x) * 16, h); in vnc_update_client()
800 vs->output.buffer[saved_offset] = (n_rectangles >> 8) & 0xFF; in vnc_update_client()
801 vs->output.buffer[saved_offset + 1] = n_rectangles & 0xFF; in vnc_update_client()
802 vnc_flush(vs); in vnc_update_client()
803 vs->force_update = 0; in vnc_update_client()
807 if (vs->csock != -1) { in vnc_update_client()
808 qemu_mod_timer(vs->timer, qemu_get_clock(rt_clock) + VNC_REFRESH_INTERVAL); in vnc_update_client()
810 vnc_disconnect_finish(vs); in vnc_update_client()
818 VncState *vs = opaque; in audio_capture_notify() local
822 vnc_write_u8(vs, 255); in audio_capture_notify()
823 vnc_write_u8(vs, 1); in audio_capture_notify()
824 vnc_write_u16(vs, 0); in audio_capture_notify()
825 vnc_flush(vs); in audio_capture_notify()
829 vnc_write_u8(vs, 255); in audio_capture_notify()
830 vnc_write_u8(vs, 1); in audio_capture_notify()
831 vnc_write_u16(vs, 1); in audio_capture_notify()
832 vnc_flush(vs); in audio_capture_notify()
843 VncState *vs = opaque; in audio_capture() local
845 vnc_write_u8(vs, 255); in audio_capture()
846 vnc_write_u8(vs, 1); in audio_capture()
847 vnc_write_u16(vs, 2); in audio_capture()
848 vnc_write_u32(vs, size); in audio_capture()
849 vnc_write(vs, buf, size); in audio_capture()
850 vnc_flush(vs); in audio_capture()
853 static void audio_add(VncState *vs) in audio_add() argument
858 if (vs->audio_cap) { in audio_add()
867 vs->audio_cap = AUD_add_capture(&vs->as, &ops, vs); in audio_add()
868 if (!vs->audio_cap) { in audio_add()
873 static void audio_del(VncState *vs) in audio_del() argument
875 if (vs->audio_cap) { in audio_del()
876 AUD_del_capture(vs->audio_cap, vs); in audio_del()
877 vs->audio_cap = NULL; in audio_del()
881 static void vnc_disconnect_start(VncState *vs) in vnc_disconnect_start() argument
883 if (vs->csock == -1) in vnc_disconnect_start()
885 qemu_set_fd_handler2(vs->csock, NULL, NULL, NULL, NULL); in vnc_disconnect_start()
886 closesocket(vs->csock); in vnc_disconnect_start()
887 vs->csock = -1; in vnc_disconnect_start()
890 static void vnc_disconnect_finish(VncState *vs) in vnc_disconnect_finish() argument
892 qemu_del_timer(vs->timer); in vnc_disconnect_finish()
893 qemu_free_timer(vs->timer); in vnc_disconnect_finish()
894 if (vs->input.buffer) qemu_free(vs->input.buffer); in vnc_disconnect_finish()
895 if (vs->output.buffer) qemu_free(vs->output.buffer); in vnc_disconnect_finish()
897 vnc_tls_client_cleanup(vs); in vnc_disconnect_finish()
900 vnc_sasl_client_cleanup(vs); in vnc_disconnect_finish()
902 audio_del(vs); in vnc_disconnect_finish()
905 for (p = vs->vd->clients; p != NULL; p = p->next) { in vnc_disconnect_finish()
906 if (p == vs) { in vnc_disconnect_finish()
910 vs->vd->clients = p->next; in vnc_disconnect_finish()
915 if (!vs->vd->clients) in vnc_disconnect_finish()
918 qemu_free(vs->server.ds->data); in vnc_disconnect_finish()
919 qemu_free(vs->server.ds); in vnc_disconnect_finish()
920 qemu_free(vs->guest.ds); in vnc_disconnect_finish()
921 qemu_free(vs); in vnc_disconnect_finish()
924 int vnc_client_io_error(VncState *vs, int ret, int last_errno) in vnc_client_io_error() argument
942 vnc_disconnect_start(vs); in vnc_client_io_error()
950 void vnc_client_error(VncState *vs) in vnc_client_error() argument
953 vnc_disconnect_start(vs); in vnc_client_error()
972 long vnc_client_write_buf(VncState *vs, const uint8_t *data, size_t datalen) in vnc_client_write_buf() argument
976 if (vs->tls.session) { in vnc_client_write_buf()
977 ret = gnutls_write(vs->tls.session, data, datalen); in vnc_client_write_buf()
987 ret = send(vs->csock, (const void *)data, datalen, 0); in vnc_client_write_buf()
989 return vnc_client_io_error(vs, ret, socket_error()); in vnc_client_write_buf()
1003 static long vnc_client_write_plain(VncState *vs) in vnc_client_write_plain() argument
1009 vs->output.buffer, vs->output.capacity, vs->output.offset, in vnc_client_write_plain()
1010 vs->sasl.waitWriteSSF); in vnc_client_write_plain()
1012 if (vs->sasl.conn && in vnc_client_write_plain()
1013 vs->sasl.runSSF && in vnc_client_write_plain()
1014 vs->sasl.waitWriteSSF) { in vnc_client_write_plain()
1015 ret = vnc_client_write_buf(vs, vs->output.buffer, vs->sasl.waitWriteSSF); in vnc_client_write_plain()
1017 vs->sasl.waitWriteSSF -= ret; in vnc_client_write_plain()
1020 ret = vnc_client_write_buf(vs, vs->output.buffer, vs->output.offset); in vnc_client_write_plain()
1024 memmove(vs->output.buffer, vs->output.buffer + ret, (vs->output.offset - ret)); in vnc_client_write_plain()
1025 vs->output.offset -= ret; in vnc_client_write_plain()
1027 if (vs->output.offset == 0) { in vnc_client_write_plain()
1028 qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs); in vnc_client_write_plain()
1043 VncState *vs = opaque; in vnc_client_write() local
1046 if (vs->sasl.conn && in vnc_client_write()
1047 vs->sasl.runSSF && in vnc_client_write()
1048 !vs->sasl.waitWriteSSF) in vnc_client_write()
1049 ret = vnc_client_write_sasl(vs); in vnc_client_write()
1052 ret = vnc_client_write_plain(vs); in vnc_client_write()
1055 void vnc_read_when(VncState *vs, VncReadEvent *func, size_t expecting) in vnc_read_when() argument
1057 vs->read_handler = func; in vnc_read_when()
1058 vs->read_handler_expect = expecting; in vnc_read_when()
1077 long vnc_client_read_buf(VncState *vs, uint8_t *data, size_t datalen) in vnc_client_read_buf() argument
1081 if (vs->tls.session) { in vnc_client_read_buf()
1082 ret = gnutls_read(vs->tls.session, data, datalen); in vnc_client_read_buf()
1092 ret = recv(vs->csock, (void *)data, datalen, 0); in vnc_client_read_buf()
1094 return vnc_client_io_error(vs, ret, socket_error()); in vnc_client_read_buf()
1106 static long vnc_client_read_plain(VncState *vs) in vnc_client_read_plain() argument
1110 vs->input.buffer, vs->input.capacity, vs->input.offset); in vnc_client_read_plain()
1111 buffer_reserve(&vs->input, 4096); in vnc_client_read_plain()
1112 ret = vnc_client_read_buf(vs, buffer_end(&vs->input), 4096); in vnc_client_read_plain()
1115 vs->input.offset += ret; in vnc_client_read_plain()
1127 VncState *vs = opaque; in vnc_client_read() local
1131 if (vs->sasl.conn && vs->sasl.runSSF) in vnc_client_read()
1132 ret = vnc_client_read_sasl(vs); in vnc_client_read()
1135 ret = vnc_client_read_plain(vs); in vnc_client_read()
1137 if (vs->csock == -1) in vnc_client_read()
1138 vnc_disconnect_finish(vs); in vnc_client_read()
1142 while (vs->read_handler && vs->input.offset >= vs->read_handler_expect) { in vnc_client_read()
1143 size_t len = vs->read_handler_expect; in vnc_client_read()
1146 ret = vs->read_handler(vs, vs->input.buffer, len); in vnc_client_read()
1147 if (vs->csock == -1) { in vnc_client_read()
1148 vnc_disconnect_finish(vs); in vnc_client_read()
1153 memmove(vs->input.buffer, vs->input.buffer + len, (vs->input.offset - len)); in vnc_client_read()
1154 vs->input.offset -= len; in vnc_client_read()
1156 vs->read_handler_expect = ret; in vnc_client_read()
1161 void vnc_write(VncState *vs, const void *data, size_t len) in vnc_write() argument
1163 buffer_reserve(&vs->output, len); in vnc_write()
1165 if (vs->csock != -1 && buffer_empty(&vs->output)) { in vnc_write()
1166 qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, vnc_client_write, vs); in vnc_write()
1169 buffer_append(&vs->output, data, len); in vnc_write()
1172 void vnc_write_s32(VncState *vs, int32_t value) in vnc_write_s32() argument
1174 vnc_write_u32(vs, *(uint32_t *)&value); in vnc_write_s32()
1177 void vnc_write_u32(VncState *vs, uint32_t value) in vnc_write_u32() argument
1186 vnc_write(vs, buf, 4); in vnc_write_u32()
1189 void vnc_write_u16(VncState *vs, uint16_t value) in vnc_write_u16() argument
1196 vnc_write(vs, buf, 2); in vnc_write_u16()
1199 void vnc_write_u8(VncState *vs, uint8_t value) in vnc_write_u8() argument
1201 vnc_write(vs, (char *)&value, 1); in vnc_write_u8()
1204 void vnc_flush(VncState *vs) in vnc_flush() argument
1206 if (vs->csock != -1 && vs->output.offset) in vnc_flush()
1207 vnc_client_write(vs); in vnc_flush()
1232 static void client_cut_text(VncState *vs, size_t len, uint8_t *text) in client_cut_text() argument
1236 static void check_pointer_type_change(VncState *vs, int absolute) in check_pointer_type_change() argument
1238 if (vnc_has_feature(vs, VNC_FEATURE_POINTER_TYPE_CHANGE) && vs->absolute != absolute) { in check_pointer_type_change()
1239 vnc_write_u8(vs, 0); in check_pointer_type_change()
1240 vnc_write_u8(vs, 0); in check_pointer_type_change()
1241 vnc_write_u16(vs, 1); in check_pointer_type_change()
1242 vnc_framebuffer_update(vs, absolute, 0, in check_pointer_type_change()
1243 ds_get_width(vs->ds), ds_get_height(vs->ds), in check_pointer_type_change()
1245 vnc_flush(vs); in check_pointer_type_change()
1247 vs->absolute = absolute; in check_pointer_type_change()
1250 static void pointer_event(VncState *vs, int button_mask, int x, int y) in pointer_event() argument
1266 if (vs->absolute) { in pointer_event()
1267 kbd_mouse_event(x * 0x7FFF / (ds_get_width(vs->ds) - 1), in pointer_event()
1268 y * 0x7FFF / (ds_get_height(vs->ds) - 1), in pointer_event()
1270 } else if (vnc_has_feature(vs, VNC_FEATURE_POINTER_TYPE_CHANGE)) { in pointer_event()
1276 if (vs->last_x != -1) in pointer_event()
1277 kbd_mouse_event(x - vs->last_x, in pointer_event()
1278 y - vs->last_y, in pointer_event()
1280 vs->last_x = x; in pointer_event()
1281 vs->last_y = y; in pointer_event()
1284 check_pointer_type_change(vs, kbd_mouse_is_absolute()); in pointer_event()
1287 static void reset_keys(VncState *vs) in reset_keys() argument
1291 if (vs->modifiers_state[i]) { in reset_keys()
1295 vs->modifiers_state[i] = 0; in reset_keys()
1300 static void press_key(VncState *vs, int keysym) in press_key() argument
1302 kbd_put_keycode(keysym2scancode(vs->vd->kbd_layout, keysym) & 0x7f); in press_key()
1303 kbd_put_keycode(keysym2scancode(vs->vd->kbd_layout, keysym) | 0x80); in press_key()
1306 static void do_key_event(VncState *vs, int down, int keycode, int sym) in do_key_event() argument
1317 vs->modifiers_state[keycode] = 1; in do_key_event()
1319 vs->modifiers_state[keycode] = 0; in do_key_event()
1322 if (down && vs->modifiers_state[0x1d] && vs->modifiers_state[0x38]) { in do_key_event()
1324 reset_keys(vs); in do_key_event()
1332 vs->modifiers_state[keycode] ^= 1; in do_key_event()
1336 if (keycode_is_keypad(vs->vd->kbd_layout, keycode)) { in do_key_event()
1341 if (keysym_is_numlock(vs->vd->kbd_layout, sym & 0xFFFF)) { in do_key_event()
1342 if (!vs->modifiers_state[0x45]) { in do_key_event()
1343 vs->modifiers_state[0x45] = 1; in do_key_event()
1344 press_key(vs, 0xff7f); in do_key_event()
1347 if (vs->modifiers_state[0x45]) { in do_key_event()
1348 vs->modifiers_state[0x45] = 0; in do_key_event()
1349 press_key(vs, 0xff7f); in do_key_event()
1364 int numlock = vs->modifiers_state[0x45]; in do_key_event()
1459 static void key_event(VncState *vs, int down, uint32_t sym) in key_event() argument
1466 keycode = keysym2scancode(vs->vd->kbd_layout, sym & 0xFFFF); in key_event()
1467 do_key_event(vs, down, keycode, sym); in key_event()
1470 static void ext_key_event(VncState *vs, int down, in ext_key_event() argument
1475 key_event(vs, down, sym); in ext_key_event()
1477 do_key_event(vs, down, keycode, sym); in ext_key_event()
1480 static void framebuffer_update_request(VncState *vs, int incremental, in framebuffer_update_request() argument
1484 if (x_position > ds_get_width(vs->ds)) in framebuffer_update_request()
1485 x_position = ds_get_width(vs->ds); in framebuffer_update_request()
1486 if (y_position > ds_get_height(vs->ds)) in framebuffer_update_request()
1487 y_position = ds_get_height(vs->ds); in framebuffer_update_request()
1488 if (x_position + w >= ds_get_width(vs->ds)) in framebuffer_update_request()
1489 w = ds_get_width(vs->ds) - x_position; in framebuffer_update_request()
1490 if (y_position + h >= ds_get_height(vs->ds)) in framebuffer_update_request()
1491 h = ds_get_height(vs->ds) - y_position; in framebuffer_update_request()
1494 vs->need_update = 1; in framebuffer_update_request()
1496 vs->force_update = 1; in framebuffer_update_request()
1498 vnc_set_bits(vs->guest.dirty[y_position + i], in framebuffer_update_request()
1499 (ds_get_width(vs->ds) / 16), VNC_DIRTY_WORDS); in framebuffer_update_request()
1500 vnc_set_bits(vs->server.dirty[y_position + i], in framebuffer_update_request()
1501 (ds_get_width(vs->ds) / 16), VNC_DIRTY_WORDS); in framebuffer_update_request()
1506 static void send_ext_key_event_ack(VncState *vs) in send_ext_key_event_ack() argument
1508 vnc_write_u8(vs, 0); in send_ext_key_event_ack()
1509 vnc_write_u8(vs, 0); in send_ext_key_event_ack()
1510 vnc_write_u16(vs, 1); in send_ext_key_event_ack()
1511 vnc_framebuffer_update(vs, 0, 0, ds_get_width(vs->ds), ds_get_height(vs->ds), in send_ext_key_event_ack()
1513 vnc_flush(vs); in send_ext_key_event_ack()
1516 static void send_ext_audio_ack(VncState *vs) in send_ext_audio_ack() argument
1518 vnc_write_u8(vs, 0); in send_ext_audio_ack()
1519 vnc_write_u8(vs, 0); in send_ext_audio_ack()
1520 vnc_write_u16(vs, 1); in send_ext_audio_ack()
1521 vnc_framebuffer_update(vs, 0, 0, ds_get_width(vs->ds), ds_get_height(vs->ds), in send_ext_audio_ack()
1523 vnc_flush(vs); in send_ext_audio_ack()
1526 static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings) in set_encodings() argument
1531 vnc_zlib_init(vs); in set_encodings()
1532 vs->features = 0; in set_encodings()
1533 vs->vnc_encoding = 0; in set_encodings()
1534 vs->tight_compression = 9; in set_encodings()
1535 vs->tight_quality = 9; in set_encodings()
1536 vs->absolute = -1; in set_encodings()
1542 vs->vnc_encoding = enc; in set_encodings()
1545 vs->features |= VNC_FEATURE_COPYRECT_MASK; in set_encodings()
1548 vs->features |= VNC_FEATURE_HEXTILE_MASK; in set_encodings()
1549 vs->vnc_encoding = enc; in set_encodings()
1552 vs->features |= VNC_FEATURE_ZLIB_MASK; in set_encodings()
1553 vs->vnc_encoding = enc; in set_encodings()
1556 vs->features |= VNC_FEATURE_RESIZE_MASK; in set_encodings()
1559 vs->features |= VNC_FEATURE_POINTER_TYPE_CHANGE_MASK; in set_encodings()
1562 send_ext_key_event_ack(vs); in set_encodings()
1565 send_ext_audio_ack(vs); in set_encodings()
1568 vs->features |= VNC_FEATURE_WMVI_MASK; in set_encodings()
1571 vs->tight_compression = (enc & 0x0F); in set_encodings()
1574 vs->tight_quality = (enc & 0x0F); in set_encodings()
1582 check_pointer_type_change(vs, kbd_mouse_is_absolute()); in set_encodings()
1585 static void set_pixel_conversion(VncState *vs) in set_pixel_conversion() argument
1587 if ((vs->clientds.flags & QEMU_BIG_ENDIAN_FLAG) == in set_pixel_conversion()
1588 (vs->ds->surface->flags & QEMU_BIG_ENDIAN_FLAG) && in set_pixel_conversion()
1589 !memcmp(&(vs->clientds.pf), &(vs->ds->surface->pf), sizeof(PixelFormat))) { in set_pixel_conversion()
1590 vs->write_pixels = vnc_write_pixels_copy; in set_pixel_conversion()
1591 switch (vs->ds->surface->pf.bits_per_pixel) { in set_pixel_conversion()
1593 vs->send_hextile_tile = send_hextile_tile_8; in set_pixel_conversion()
1596 vs->send_hextile_tile = send_hextile_tile_16; in set_pixel_conversion()
1599 vs->send_hextile_tile = send_hextile_tile_32; in set_pixel_conversion()
1603 vs->write_pixels = vnc_write_pixels_generic; in set_pixel_conversion()
1604 switch (vs->ds->surface->pf.bits_per_pixel) { in set_pixel_conversion()
1606 vs->send_hextile_tile = send_hextile_tile_generic_8; in set_pixel_conversion()
1609 vs->send_hextile_tile = send_hextile_tile_generic_16; in set_pixel_conversion()
1612 vs->send_hextile_tile = send_hextile_tile_generic_32; in set_pixel_conversion()
1618 static void set_pixel_format(VncState *vs, in set_pixel_format() argument
1625 vnc_client_error(vs); in set_pixel_format()
1629 vs->clientds = *(vs->guest.ds); in set_pixel_format()
1630 vs->clientds.pf.rmax = red_max; in set_pixel_format()
1631 count_bits(vs->clientds.pf.rbits, red_max); in set_pixel_format()
1632 vs->clientds.pf.rshift = red_shift; in set_pixel_format()
1633 vs->clientds.pf.rmask = red_max << red_shift; in set_pixel_format()
1634 vs->clientds.pf.gmax = green_max; in set_pixel_format()
1635 count_bits(vs->clientds.pf.gbits, green_max); in set_pixel_format()
1636 vs->clientds.pf.gshift = green_shift; in set_pixel_format()
1637 vs->clientds.pf.gmask = green_max << green_shift; in set_pixel_format()
1638 vs->clientds.pf.bmax = blue_max; in set_pixel_format()
1639 count_bits(vs->clientds.pf.bbits, blue_max); in set_pixel_format()
1640 vs->clientds.pf.bshift = blue_shift; in set_pixel_format()
1641 vs->clientds.pf.bmask = blue_max << blue_shift; in set_pixel_format()
1642 vs->clientds.pf.bits_per_pixel = bits_per_pixel; in set_pixel_format()
1643 vs->clientds.pf.bytes_per_pixel = bits_per_pixel / 8; in set_pixel_format()
1644 vs->clientds.pf.depth = bits_per_pixel == 32 ? 24 : bits_per_pixel; in set_pixel_format()
1645 vs->clientds.flags = big_endian_flag ? QEMU_BIG_ENDIAN_FLAG : 0x00; in set_pixel_format()
1647 set_pixel_conversion(vs); in set_pixel_format()
1653 static void pixel_format_message (VncState *vs) { in pixel_format_message() argument
1656 vnc_write_u8(vs, vs->ds->surface->pf.bits_per_pixel); /* bits-per-pixel */ in pixel_format_message()
1657 vnc_write_u8(vs, vs->ds->surface->pf.depth); /* depth */ in pixel_format_message()
1660 vnc_write_u8(vs, 1); /* big-endian-flag */ in pixel_format_message()
1662 vnc_write_u8(vs, 0); /* big-endian-flag */ in pixel_format_message()
1664 vnc_write_u8(vs, 1); /* true-color-flag */ in pixel_format_message()
1665 vnc_write_u16(vs, vs->ds->surface->pf.rmax); /* red-max */ in pixel_format_message()
1666 vnc_write_u16(vs, vs->ds->surface->pf.gmax); /* green-max */ in pixel_format_message()
1667 vnc_write_u16(vs, vs->ds->surface->pf.bmax); /* blue-max */ in pixel_format_message()
1668 vnc_write_u8(vs, vs->ds->surface->pf.rshift); /* red-shift */ in pixel_format_message()
1669 vnc_write_u8(vs, vs->ds->surface->pf.gshift); /* green-shift */ in pixel_format_message()
1670 vnc_write_u8(vs, vs->ds->surface->pf.bshift); /* blue-shift */ in pixel_format_message()
1671 if (vs->ds->surface->pf.bits_per_pixel == 32) in pixel_format_message()
1672 vs->send_hextile_tile = send_hextile_tile_32; in pixel_format_message()
1673 else if (vs->ds->surface->pf.bits_per_pixel == 16) in pixel_format_message()
1674 vs->send_hextile_tile = send_hextile_tile_16; in pixel_format_message()
1675 else if (vs->ds->surface->pf.bits_per_pixel == 8) in pixel_format_message()
1676 vs->send_hextile_tile = send_hextile_tile_8; in pixel_format_message()
1677 vs->clientds = *(vs->ds->surface); in pixel_format_message()
1678 vs->clientds.flags &= ~QEMU_ALLOCATED_FLAG; in pixel_format_message()
1679 vs->write_pixels = vnc_write_pixels_copy; in pixel_format_message()
1681 vnc_write(vs, pad, 3); /* padding */ in pixel_format_message()
1689 static void vnc_colordepth(VncState *vs) in vnc_colordepth() argument
1691 if (vnc_has_feature(vs, VNC_FEATURE_WMVI)) { in vnc_colordepth()
1693 vnc_write_u8(vs, 0); /* msg id */ in vnc_colordepth()
1694 vnc_write_u8(vs, 0); in vnc_colordepth()
1695 vnc_write_u16(vs, 1); /* number of rects */ in vnc_colordepth()
1696 vnc_framebuffer_update(vs, 0, 0, ds_get_width(vs->ds), in vnc_colordepth()
1697 ds_get_height(vs->ds), VNC_ENCODING_WMVi); in vnc_colordepth()
1698 pixel_format_message(vs); in vnc_colordepth()
1699 vnc_flush(vs); in vnc_colordepth()
1701 set_pixel_conversion(vs); in vnc_colordepth()
1705 static int protocol_client_msg(VncState *vs, uint8_t *data, size_t len) in protocol_client_msg() argument
1715 set_pixel_format(vs, read_u8(data, 4), read_u8(data, 5), in protocol_client_msg()
1737 set_encodings(vs, (int32_t *)(data + 4), limit); in protocol_client_msg()
1743 framebuffer_update_request(vs, in protocol_client_msg()
1751 key_event(vs, read_u8(data, 1), read_u32(data, 4)); in protocol_client_msg()
1757 pointer_event(vs, read_u8(data, 1), read_u16(data, 2), read_u16(data, 4)); in protocol_client_msg()
1769 client_cut_text(vs, read_u32(data, 4), data + 8); in protocol_client_msg()
1780 ext_key_event(vs, read_u16(data, 2), in protocol_client_msg()
1789 audio_add(vs); in protocol_client_msg()
1792 audio_del(vs); in protocol_client_msg()
1798 case 0: vs->as.fmt = AUD_FMT_U8; break; in protocol_client_msg()
1799 case 1: vs->as.fmt = AUD_FMT_S8; break; in protocol_client_msg()
1800 case 2: vs->as.fmt = AUD_FMT_U16; break; in protocol_client_msg()
1801 case 3: vs->as.fmt = AUD_FMT_S16; break; in protocol_client_msg()
1802 case 4: vs->as.fmt = AUD_FMT_U32; break; in protocol_client_msg()
1803 case 5: vs->as.fmt = AUD_FMT_S32; break; in protocol_client_msg()
1806 vnc_client_error(vs); in protocol_client_msg()
1809 vs->as.nchannels = read_u8(data, 5); in protocol_client_msg()
1810 if (vs->as.nchannels != 1 && vs->as.nchannels != 2) { in protocol_client_msg()
1813 vnc_client_error(vs); in protocol_client_msg()
1816 vs->as.freq = read_u32(data, 6); in protocol_client_msg()
1820 vnc_client_error(vs); in protocol_client_msg()
1827 vnc_client_error(vs); in protocol_client_msg()
1833 vnc_client_error(vs); in protocol_client_msg()
1837 vnc_read_when(vs, protocol_client_msg, 1); in protocol_client_msg()
1841 static int protocol_client_init(VncState *vs, uint8_t *data, size_t len) in protocol_client_init() argument
1846 vnc_write_u16(vs, ds_get_width(vs->ds)); in protocol_client_init()
1847 vnc_write_u16(vs, ds_get_height(vs->ds)); in protocol_client_init()
1849 pixel_format_message(vs); in protocol_client_init()
1856 vnc_write_u32(vs, size); in protocol_client_init()
1857 vnc_write(vs, buf, size); in protocol_client_init()
1858 vnc_flush(vs); in protocol_client_init()
1860 vnc_read_when(vs, protocol_client_msg, 1); in protocol_client_init()
1865 void start_client_init(VncState *vs) in start_client_init() argument
1867 vnc_read_when(vs, protocol_client_init, 1); in start_client_init()
1870 static void make_challenge(VncState *vs) in make_challenge() argument
1876 for (i = 0 ; i < sizeof(vs->challenge) ; i++) in make_challenge()
1877 vs->challenge[i] = (int) (256.0*rand()/(RAND_MAX+1.0)); in make_challenge()
1880 static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len) in protocol_client_auth_vnc() argument
1886 if (!vs->vd->password || !vs->vd->password[0]) { in protocol_client_auth_vnc()
1888 vnc_write_u32(vs, 1); /* Reject auth */ in protocol_client_auth_vnc()
1889 if (vs->minor >= 8) { in protocol_client_auth_vnc()
1891 vnc_write_u32(vs, sizeof(err)); in protocol_client_auth_vnc()
1892 vnc_write(vs, err, sizeof(err)); in protocol_client_auth_vnc()
1894 vnc_flush(vs); in protocol_client_auth_vnc()
1895 vnc_client_error(vs); in protocol_client_auth_vnc()
1899 memcpy(response, vs->challenge, VNC_AUTH_CHALLENGE_SIZE); in protocol_client_auth_vnc()
1902 pwlen = strlen(vs->vd->password); in protocol_client_auth_vnc()
1904 key[i] = i<pwlen ? vs->vd->password[i] : 0; in protocol_client_auth_vnc()
1912 vnc_write_u32(vs, 1); /* Reject auth */ in protocol_client_auth_vnc()
1913 if (vs->minor >= 8) { in protocol_client_auth_vnc()
1915 vnc_write_u32(vs, sizeof(err)); in protocol_client_auth_vnc()
1916 vnc_write(vs, err, sizeof(err)); in protocol_client_auth_vnc()
1918 vnc_flush(vs); in protocol_client_auth_vnc()
1919 vnc_client_error(vs); in protocol_client_auth_vnc()
1922 vnc_write_u32(vs, 0); /* Accept auth */ in protocol_client_auth_vnc()
1923 vnc_flush(vs); in protocol_client_auth_vnc()
1925 start_client_init(vs); in protocol_client_auth_vnc()
1930 void start_auth_vnc(VncState *vs) in start_auth_vnc() argument
1932 make_challenge(vs); in start_auth_vnc()
1934 vnc_write(vs, vs->challenge, sizeof(vs->challenge)); in start_auth_vnc()
1935 vnc_flush(vs); in start_auth_vnc()
1937 vnc_read_when(vs, protocol_client_auth_vnc, sizeof(vs->challenge)); in start_auth_vnc()
1941 static int protocol_client_auth(VncState *vs, uint8_t *data, size_t len) in protocol_client_auth() argument
1945 if (data[0] != vs->vd->auth) { /* Reject auth */ in protocol_client_auth()
1947 vnc_write_u32(vs, 1); in protocol_client_auth()
1948 if (vs->minor >= 8) { in protocol_client_auth()
1950 vnc_write_u32(vs, sizeof(err)); in protocol_client_auth()
1951 vnc_write(vs, err, sizeof(err)); in protocol_client_auth()
1953 vnc_client_error(vs); in protocol_client_auth()
1956 switch (vs->vd->auth) { in protocol_client_auth()
1959 if (vs->minor >= 8) { in protocol_client_auth()
1960 vnc_write_u32(vs, 0); /* Accept auth completion */ in protocol_client_auth()
1961 vnc_flush(vs); in protocol_client_auth()
1963 start_client_init(vs); in protocol_client_auth()
1968 start_auth_vnc(vs); in protocol_client_auth()
1974 start_auth_vencrypt(vs); in protocol_client_auth()
1981 start_auth_sasl(vs); in protocol_client_auth()
1986 VNC_DEBUG("Reject auth %d server code bug\n", vs->vd->auth); in protocol_client_auth()
1987 vnc_write_u8(vs, 1); in protocol_client_auth()
1988 if (vs->minor >= 8) { in protocol_client_auth()
1990 vnc_write_u32(vs, sizeof(err)); in protocol_client_auth()
1991 vnc_write(vs, err, sizeof(err)); in protocol_client_auth()
1993 vnc_client_error(vs); in protocol_client_auth()
1999 static int protocol_version(VncState *vs, uint8_t *version, size_t len) in protocol_version() argument
2006 if (sscanf(local, "RFB %03d.%03d\n", &vs->major, &vs->minor) != 2) { in protocol_version()
2008 vnc_client_error(vs); in protocol_version()
2011 VNC_DEBUG("Client request protocol version %d.%d\n", vs->major, vs->minor); in protocol_version()
2012 if (vs->major != 3 || in protocol_version()
2013 (vs->minor != 3 && in protocol_version()
2014 vs->minor != 4 && in protocol_version()
2015 vs->minor != 5 && in protocol_version()
2016 vs->minor != 7 && in protocol_version()
2017 vs->minor != 8)) { in protocol_version()
2019 vnc_write_u32(vs, VNC_AUTH_INVALID); in protocol_version()
2020 vnc_flush(vs); in protocol_version()
2021 vnc_client_error(vs); in protocol_version()
2027 if (vs->minor == 4 || vs->minor == 5) in protocol_version()
2028 vs->minor = 3; in protocol_version()
2030 if (vs->minor == 3) { in protocol_version()
2031 if (vs->vd->auth == VNC_AUTH_NONE) { in protocol_version()
2033 vnc_write_u32(vs, vs->vd->auth); in protocol_version()
2034 vnc_flush(vs); in protocol_version()
2035 start_client_init(vs); in protocol_version()
2036 } else if (vs->vd->auth == VNC_AUTH_VNC) { in protocol_version()
2038 vnc_write_u32(vs, vs->vd->auth); in protocol_version()
2039 vnc_flush(vs); in protocol_version()
2040 start_auth_vnc(vs); in protocol_version()
2042 VNC_DEBUG("Unsupported auth %d for protocol 3.3\n", vs->vd->auth); in protocol_version()
2043 vnc_write_u32(vs, VNC_AUTH_INVALID); in protocol_version()
2044 vnc_flush(vs); in protocol_version()
2045 vnc_client_error(vs); in protocol_version()
2048 VNC_DEBUG("Telling client we support auth %d\n", vs->vd->auth); in protocol_version()
2049 vnc_write_u8(vs, 1); /* num auth */ in protocol_version()
2050 vnc_write_u8(vs, vs->vd->auth); in protocol_version()
2051 vnc_read_when(vs, protocol_client_auth, 1); in protocol_version()
2052 vnc_flush(vs); in protocol_version()
2060 VncState *vs = qemu_mallocz(sizeof(VncState)); in vnc_connect() local
2061 vs->csock = csock; in vnc_connect()
2065 socket_set_nonblock(vs->csock); in vnc_connect()
2066 qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs); in vnc_connect()
2068 vs->vd = vd; in vnc_connect()
2069 vs->ds = vd->ds; in vnc_connect()
2070 vs->timer = qemu_new_timer(rt_clock, vnc_update_client, vs); in vnc_connect()
2071 vs->last_x = -1; in vnc_connect()
2072 vs->last_y = -1; in vnc_connect()
2074 vs->as.freq = 44100; in vnc_connect()
2075 vs->as.nchannels = 2; in vnc_connect()
2076 vs->as.fmt = AUD_FMT_S16; in vnc_connect()
2077 vs->as.endianness = 0; in vnc_connect()
2079 vnc_resize(vs); in vnc_connect()
2080 vnc_write(vs, "RFB 003.008\n", 12); in vnc_connect()
2081 vnc_flush(vs); in vnc_connect()
2082 vnc_read_when(vs, protocol_version, 12); in vnc_connect()
2083 reset_keys(vs); in vnc_connect()
2085 vs->next = vd->clients; in vnc_connect()
2086 vd->clients = vs; in vnc_connect()
2088 vnc_update_client(vs); in vnc_connect()
2094 VncDisplay *vs = opaque; in vnc_listen_read() local
2101 int csock = accept(vs->lsock, (struct sockaddr *)&addr, &addrlen); in vnc_listen_read()
2103 vnc_connect(vs, csock); in vnc_listen_read()
2109 VncDisplay *vs = qemu_mallocz(sizeof(*vs)); in vnc_display_init() local
2113 ds->opaque = vs; in vnc_display_init()
2115 vnc_display = vs; in vnc_display_init()
2117 vs->lsock = -1; in vnc_display_init()
2119 vs->ds = ds; in vnc_display_init()
2122 vs->kbd_layout = init_keyboard_layout(name2keysym, keyboard_layout); in vnc_display_init()
2124 vs->kbd_layout = init_keyboard_layout(name2keysym, "en-us"); in vnc_display_init()
2126 if (!vs->kbd_layout) in vnc_display_init()
2139 VncDisplay *vs = ds ? (VncDisplay *)ds->opaque : vnc_display; in vnc_display_close() local
2141 if (!vs) in vnc_display_close()
2143 if (vs->display) { in vnc_display_close()
2144 qemu_free(vs->display); in vnc_display_close()
2145 vs->display = NULL; in vnc_display_close()
2147 if (vs->lsock != -1) { in vnc_display_close()
2148 qemu_set_fd_handler2(vs->lsock, NULL, NULL, NULL, NULL); in vnc_display_close()
2149 close(vs->lsock); in vnc_display_close()
2150 vs->lsock = -1; in vnc_display_close()
2152 vs->auth = VNC_AUTH_INVALID; in vnc_display_close()
2154 vs->subauth = VNC_AUTH_INVALID; in vnc_display_close()
2155 vs->tls.x509verify = 0; in vnc_display_close()
2161 VncDisplay *vs = ds ? (VncDisplay *)ds->opaque : vnc_display; in vnc_display_password() local
2163 if (vs->password) { in vnc_display_password()
2164 qemu_free(vs->password); in vnc_display_password()
2165 vs->password = NULL; in vnc_display_password()
2168 if (!(vs->password = qemu_strdup(password))) in vnc_display_password()
2177 VncDisplay *vs = ds ? (VncDisplay *)ds->opaque : vnc_display; in vnc_display_local_addr() local
2179 return vnc_socket_local_addr("%s:%s", vs->lsock); in vnc_display_local_addr()
2184 VncDisplay *vs = ds ? (VncDisplay *)ds->opaque : vnc_display; in vnc_display_open() local
2204 if (!(vs->display = strdup(display))) in vnc_display_open()
2227 vs->tls.x509verify = 1; /* ...and verify client certs */ in vnc_display_open()
2238 if (vnc_tls_set_x509_creds_dir(vs, path) < 0) { in vnc_display_open()
2241 qemu_free(vs->display); in vnc_display_open()
2242 vs->display = NULL; in vnc_display_open()
2248 qemu_free(vs->display); in vnc_display_open()
2249 vs->display = NULL; in vnc_display_open()
2259 if (acl && x509 && vs->tls.x509verify) { in vnc_display_open()
2260 if (!(vs->tls.acl = qemu_acl_init("vnc.x509dname"))) { in vnc_display_open()
2268 if (!(vs->sasl.acl = qemu_acl_init("vnc.username"))) { in vnc_display_open()
2294 vs->auth = VNC_AUTH_VENCRYPT; in vnc_display_open()
2297 vs->subauth = VNC_AUTH_VENCRYPT_X509VNC; in vnc_display_open()
2300 vs->subauth = VNC_AUTH_VENCRYPT_TLSVNC; in vnc_display_open()
2305 vs->auth = VNC_AUTH_VNC; in vnc_display_open()
2307 vs->subauth = VNC_AUTH_INVALID; in vnc_display_open()
2314 vs->auth = VNC_AUTH_VENCRYPT; in vnc_display_open()
2317 vs->subauth = VNC_AUTH_VENCRYPT_X509SASL; in vnc_display_open()
2320 vs->subauth = VNC_AUTH_VENCRYPT_TLSSASL; in vnc_display_open()
2325 vs->auth = VNC_AUTH_SASL; in vnc_display_open()
2327 vs->subauth = VNC_AUTH_INVALID; in vnc_display_open()
2334 vs->auth = VNC_AUTH_VENCRYPT; in vnc_display_open()
2337 vs->subauth = VNC_AUTH_VENCRYPT_X509NONE; in vnc_display_open()
2340 vs->subauth = VNC_AUTH_VENCRYPT_TLSNONE; in vnc_display_open()
2345 vs->auth = VNC_AUTH_NONE; in vnc_display_open()
2347 vs->subauth = VNC_AUTH_INVALID; in vnc_display_open()
2356 free(vs->display); in vnc_display_open()
2357 vs->display = NULL; in vnc_display_open()
2365 vs->lsock = unix_connect(display+5); in vnc_display_open()
2367 vs->lsock = inet_connect(display, SOCK_STREAM); in vnc_display_open()
2368 if (-1 == vs->lsock) { in vnc_display_open()
2369 free(vs->display); in vnc_display_open()
2370 vs->display = NULL; in vnc_display_open()
2373 int csock = vs->lsock; in vnc_display_open()
2374 vs->lsock = -1; in vnc_display_open()
2375 vnc_connect(vs, csock); in vnc_display_open()
2385 vs->lsock = unix_listen(display+5, dpy+5, 256-5); in vnc_display_open()
2387 vs->lsock = inet_listen(display, dpy, 256, SOCK_STREAM, 5900); in vnc_display_open()
2389 if (-1 == vs->lsock) { in vnc_display_open()
2393 free(vs->display); in vnc_display_open()
2394 vs->display = dpy; in vnc_display_open()
2397 return qemu_set_fd_handler2(vs->lsock, NULL, vnc_listen_read, NULL, vs); in vnc_display_open()