static int protocol_client_msg(VncState *vs, char *data, size_t len)

{

    int i;

    uint16_t limit;



    switch (data[0]) {

    case 0:

	if (len == 1)

	    return 20;



	set_pixel_format(vs, read_u8(data, 4), read_u8(data, 5),

			 read_u8(data, 6), read_u8(data, 7),

			 read_u16(data, 8), read_u16(data, 10),

			 read_u16(data, 12), read_u8(data, 14),

			 read_u8(data, 15), read_u8(data, 16));

	break;

    case 2:

	if (len == 1)

	    return 4;



	if (len == 4)

	    return 4 + (read_u16(data, 2) * 4);



	limit = read_u16(data, 2);

	for (i = 0; i < limit; i++) {

	    int32_t val = read_s32(data, 4 + (i * 4));

	    memcpy(data + 4 + (i * 4), &val, sizeof(val));

	}



	set_encodings(vs, (int32_t *)(data + 4), limit);

	break;

    case 3:

	if (len == 1)

	    return 10;



	framebuffer_update_request(vs,

				   read_u8(data, 1), read_u16(data, 2), read_u16(data, 4),

				   read_u16(data, 6), read_u16(data, 8));

	break;

    case 4:

	if (len == 1)

	    return 8;



	key_event(vs, read_u8(data, 1), read_u32(data, 4));

	break;

    case 5:

	if (len == 1)

	    return 6;



	pointer_event(vs, read_u8(data, 1), read_u16(data, 2), read_u16(data, 4));

	break;

    case 6:

	if (len == 1)

	    return 8;



	if (len == 8)

	    return 8 + read_u32(data, 4);



	client_cut_text(vs, read_u32(data, 4), data + 8);

	break;

    default:

	printf("Msg: %d\n", data[0]);

	vnc_client_error(vs);

	break;

    }

	

    vnc_read_when(vs, protocol_client_msg, 1);

    return 0;

}

static int protocol_client_msg(VncState *vs, char *data, size_t len)

{

    int i;

    uint16_t limit;



    switch (data[0]) {

    case 0:

	if (len == 1)

	    return 20;



	set_pixel_format(vs, read_u8(data, 4), read_u8(data, 5),

			 read_u8(data, 6), read_u8(data, 7),

			 read_u16(data, 8), read_u16(data, 10),

			 read_u16(data, 12), read_u8(data, 14),

			 read_u8(data, 15), read_u8(data, 16));

	break;

    case 2:

	if (len == 1)

	    return 4;



	if (len == 4)

	    return 4 + (read_u16(data, 2) * 4);



	limit = read_u16(data, 2);

	for (i = 0; i < limit; i++) {

	    int32_t val = read_s32(data, 4 + (i * 4));

	    memcpy(data + 4 + (i * 4), &val, sizeof(val));

	}



	set_encodings(vs, (int32_t *)(data + 4), limit);

	break;

    case 3:

	if (len == 1)

	    return 10;



	framebuffer_update_request(vs,

				   read_u8(data, 1), read_u16(data, 2), read_u16(data, 4),

				   read_u16(data, 6), read_u16(data, 8));

	break;

    case 4:

	if (len == 1)

	    return 8;



	key_event(vs, read_u8(data, 1), read_u32(data, 4));

	break;

    case 5:

	if (len == 1)

	    return 6;



	pointer_event(vs, read_u8(data, 1), read_u16(data, 2), read_u16(data, 4));

	break;

    case 6:

	if (len == 1)

	    return 8;



	if (len == 8)

	    return 8 + read_u32(data, 4);



	client_cut_text(vs, read_u32(data, 4), data + 8);

	break;

    default:

	printf("Msg: %d\n", data[0]);

	vnc_client_error(vs);

	break;

    }

	

    vnc_read_when(vs, protocol_client_msg, 1);

    return 0;

}

static int FUNC_0(VncState *VAR_0, char *VAR_1, size_t VAR_2)

{

    int VAR_3;

    uint16_t limit;



    switch (VAR_1[0]) {

    case 0:

	if (VAR_2 == 1)

	    return 20;



	set_pixel_format(VAR_0, read_u8(VAR_1, 4), read_u8(VAR_1, 5),

			 read_u8(VAR_1, 6), read_u8(VAR_1, 7),

			 read_u16(VAR_1, 8), read_u16(VAR_1, 10),

			 read_u16(VAR_1, 12), read_u8(VAR_1, 14),

			 read_u8(VAR_1, 15), read_u8(VAR_1, 16));

	break;

    case 2:

	if (VAR_2 == 1)

	    return 4;



	if (VAR_2 == 4)

	    return 4 + (read_u16(VAR_1, 2) * 4);



	limit = read_u16(VAR_1, 2);

	for (VAR_3 = 0; VAR_3 < limit; VAR_3++) {

	    int32_t val = read_s32(VAR_1, 4 + (VAR_3 * 4));

	    memcpy(VAR_1 + 4 + (VAR_3 * 4), &val, sizeof(val));

	}



	set_encodings(VAR_0, (int32_t *)(VAR_1 + 4), limit);

	break;

    case 3:

	if (VAR_2 == 1)

	    return 10;



	framebuffer_update_request(VAR_0,

				   read_u8(VAR_1, 1), read_u16(VAR_1, 2), read_u16(VAR_1, 4),

				   read_u16(VAR_1, 6), read_u16(VAR_1, 8));

	break;

    case 4:

	if (VAR_2 == 1)

	    return 8;



	key_event(VAR_0, read_u8(VAR_1, 1), read_u32(VAR_1, 4));

	break;

    case 5:

	if (VAR_2 == 1)

	    return 6;



	pointer_event(VAR_0, read_u8(VAR_1, 1), read_u16(VAR_1, 2), read_u16(VAR_1, 4));

	break;

    case 6:

	if (VAR_2 == 1)

	    return 8;



	if (VAR_2 == 8)

	    return 8 + read_u32(VAR_1, 4);



	client_cut_text(VAR_0, read_u32(VAR_1, 4), VAR_1 + 8);

	break;

    default:

	printf("Msg: %d\n", VAR_1[0]);

	vnc_client_error(VAR_0);

	break;

    }

	

    vnc_read_when(VAR_0, FUNC_0, 1);

    return 0;

}

static int FUNC_0(VncState *VAR_0, char *VAR_1, size_t VAR_2)
{ int VAR_3; uint16_t limit; switch (VAR_1[0]) { case 0:
if (VAR_2 == 1)
return 20; set_pixel_format(VAR_0, read_u8(VAR_1, 4), read_u8(VAR_1, 5),
read_u8(VAR_1, 6), read_u8(VAR_1, 7),
read_u16(VAR_1, 8), read_u16(VAR_1, 10),
read_u16(VAR_1, 12), read_u8(VAR_1, 14),
read_u8(VAR_1, 15), read_u8(VAR_1, 16)); break; case 2:
if (VAR_2 == 1)
return 4; if (VAR_2 == 4)
return 4 + (read_u16(VAR_1, 2) * 4); limit = read_u16(VAR_1, 2); for (VAR_3 = 0; VAR_3 < limit; VAR_3++) { int32_t val = read_s32(VAR_1, 4 + (VAR_3 * 4)); memcpy(VAR_1 + 4 + (VAR_3 * 4), &val, sizeof(val)); } set_encodings(VAR_0, (int32_t *)(VAR_1 + 4), limit); break; case 3:
if (VAR_2 == 1)
return 10; framebuffer_update_request(VAR_0,
read_u8(VAR_1, 1), read_u16(VAR_1, 2), read_u16(VAR_1, 4),
read_u16(VAR_1, 6), read_u16(VAR_1, 8)); break; case 4:
if (VAR_2 == 1)
return 8; key_event(VAR_0, read_u8(VAR_1, 1), read_u32(VAR_1, 4)); break; case 5:
if (VAR_2 == 1)
return 6; pointer_event(VAR_0, read_u8(VAR_1, 1), read_u16(VAR_1, 2), read_u16(VAR_1, 4)); break; case 6:
if (VAR_2 == 1)
return 8; if (VAR_2 == 8)
return 8 + read_u32(VAR_1, 4); client_cut_text(VAR_0, read_u32(VAR_1, 4), VAR_1 + 8); break; default:
printf("Msg: %d\n", VAR_1[0]); vnc_client_error(VAR_0); break; } vnc_read_when(VAR_0, FUNC_0, 1); return 0; }