static void vnc_connect(VncDisplay *vd, int csock,

                        bool skipauth, bool websocket)

{

    VncState *vs = g_malloc0(sizeof(VncState));

    int i;



    vs->csock = csock;

    vs->vd = vd;



    if (skipauth) {

	vs->auth = VNC_AUTH_NONE;

	vs->subauth = VNC_AUTH_INVALID;

    } else {

        if (websocket) {

            vs->auth = vd->ws_auth;

            vs->subauth = VNC_AUTH_INVALID;

        } else {

            vs->auth = vd->auth;

            vs->subauth = vd->subauth;

        }

    }

    VNC_DEBUG("Client sock=%d ws=%d auth=%d subauth=%d\n",

              csock, websocket, vs->auth, vs->subauth);



    vs->lossy_rect = g_malloc0(VNC_STAT_ROWS * sizeof (*vs->lossy_rect));

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

        vs->lossy_rect[i] = g_malloc0(VNC_STAT_COLS * sizeof (uint8_t));

    }



    VNC_DEBUG("New client on socket %d\n", csock);

    update_displaychangelistener(&vd->dcl, VNC_REFRESH_INTERVAL_BASE);

    qemu_set_nonblock(vs->csock);

#ifdef CONFIG_VNC_WS

    if (websocket) {

        vs->websocket = 1;

#ifdef CONFIG_VNC_TLS

        if (vd->ws_tls) {

            qemu_set_fd_handler(vs->csock, vncws_tls_handshake_io, NULL, vs);

        } else

#endif /* CONFIG_VNC_TLS */

        {

            qemu_set_fd_handler(vs->csock, vncws_handshake_read, NULL, vs);

        }

    } else

#endif /* CONFIG_VNC_WS */

    {

        qemu_set_fd_handler(vs->csock, vnc_client_read, NULL, vs);

    }



    vnc_client_cache_addr(vs);

    vnc_qmp_event(vs, QAPI_EVENT_VNC_CONNECTED);

    vnc_set_share_mode(vs, VNC_SHARE_MODE_CONNECTING);



#ifdef CONFIG_VNC_WS

    if (!vs->websocket)

#endif

    {

        vnc_init_state(vs);

    }



    if (vd->num_connecting > vd->connections_limit) {

        QTAILQ_FOREACH(vs, &vd->clients, next) {

            if (vs->share_mode == VNC_SHARE_MODE_CONNECTING) {

                vnc_disconnect_start(vs);

                return;

            }

        }

    }

}

static void vnc_connect(VncDisplay *vd, int csock,

                        bool skipauth, bool websocket)

{

    VncState *vs = g_malloc0(sizeof(VncState));

    int i;



    vs->csock = csock;

    vs->vd = vd;



    if (skipauth) {

	vs->auth = VNC_AUTH_NONE;

	vs->subauth = VNC_AUTH_INVALID;

    } else {

        if (websocket) {

            vs->auth = vd->ws_auth;

            vs->subauth = VNC_AUTH_INVALID;

        } else {

            vs->auth = vd->auth;

            vs->subauth = vd->subauth;

        }

    }

    VNC_DEBUG("Client sock=%d ws=%d auth=%d subauth=%d\n",

              csock, websocket, vs->auth, vs->subauth);



    vs->lossy_rect = g_malloc0(VNC_STAT_ROWS * sizeof (*vs->lossy_rect));

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

        vs->lossy_rect[i] = g_malloc0(VNC_STAT_COLS * sizeof (uint8_t));

    }



    VNC_DEBUG("New client on socket %d\n", csock);

    update_displaychangelistener(&vd->dcl, VNC_REFRESH_INTERVAL_BASE);

    qemu_set_nonblock(vs->csock);

#ifdef CONFIG_VNC_WS

    if (websocket) {

        vs->websocket = 1;

#ifdef CONFIG_VNC_TLS

        if (vd->ws_tls) {

            qemu_set_fd_handler(vs->csock, vncws_tls_handshake_io, NULL, vs);

        } else

#endif 

        {

            qemu_set_fd_handler(vs->csock, vncws_handshake_read, NULL, vs);

        }

    } else

#endif 

    {

        qemu_set_fd_handler(vs->csock, vnc_client_read, NULL, vs);

    }



    vnc_client_cache_addr(vs);

    vnc_qmp_event(vs, QAPI_EVENT_VNC_CONNECTED);

    vnc_set_share_mode(vs, VNC_SHARE_MODE_CONNECTING);



#ifdef CONFIG_VNC_WS

    if (!vs->websocket)

#endif

    {

        vnc_init_state(vs);

    }



    if (vd->num_connecting > vd->connections_limit) {

        QTAILQ_FOREACH(vs, &vd->clients, next) {

            if (vs->share_mode == VNC_SHARE_MODE_CONNECTING) {

                vnc_disconnect_start(vs);

                return;

            }

        }

    }

}

static void FUNC_0(VncDisplay *VAR_0, int VAR_1,

                        bool VAR_2, bool VAR_3)

{

    VncState *vs = g_malloc0(sizeof(VncState));

    int VAR_4;



    vs->VAR_1 = VAR_1;

    vs->VAR_0 = VAR_0;



    if (VAR_2) {

	vs->auth = VNC_AUTH_NONE;

	vs->subauth = VNC_AUTH_INVALID;

    } else {

        if (VAR_3) {

            vs->auth = VAR_0->ws_auth;

            vs->subauth = VNC_AUTH_INVALID;

        } else {

            vs->auth = VAR_0->auth;

            vs->subauth = VAR_0->subauth;

        }

    }

    VNC_DEBUG("Client sock=%d ws=%d auth=%d subauth=%d\n",

              VAR_1, VAR_3, vs->auth, vs->subauth);



    vs->lossy_rect = g_malloc0(VNC_STAT_ROWS * sizeof (*vs->lossy_rect));

    for (VAR_4 = 0; VAR_4 < VNC_STAT_ROWS; ++VAR_4) {

        vs->lossy_rect[VAR_4] = g_malloc0(VNC_STAT_COLS * sizeof (uint8_t));

    }



    VNC_DEBUG("New client on socket %d\n", VAR_1);

    update_displaychangelistener(&VAR_0->dcl, VNC_REFRESH_INTERVAL_BASE);

    qemu_set_nonblock(vs->VAR_1);

#ifdef CONFIG_VNC_WS

    if (VAR_3) {

        vs->VAR_3 = 1;

#ifdef CONFIG_VNC_TLS

        if (VAR_0->ws_tls) {

            qemu_set_fd_handler(vs->VAR_1, vncws_tls_handshake_io, NULL, vs);

        } else

#endif 

        {

            qemu_set_fd_handler(vs->VAR_1, vncws_handshake_read, NULL, vs);

        }

    } else

#endif 

    {

        qemu_set_fd_handler(vs->VAR_1, vnc_client_read, NULL, vs);

    }



    vnc_client_cache_addr(vs);

    vnc_qmp_event(vs, QAPI_EVENT_VNC_CONNECTED);

    vnc_set_share_mode(vs, VNC_SHARE_MODE_CONNECTING);



#ifdef CONFIG_VNC_WS

    if (!vs->VAR_3)

#endif

    {

        vnc_init_state(vs);

    }



    if (VAR_0->num_connecting > VAR_0->connections_limit) {

        QTAILQ_FOREACH(vs, &VAR_0->clients, next) {

            if (vs->share_mode == VNC_SHARE_MODE_CONNECTING) {

                vnc_disconnect_start(vs);

                return;

            }

        }

    }

}

static void FUNC_0(VncDisplay *VAR_0, int VAR_1,
bool VAR_2, bool VAR_3)
{ VncState *vs = g_malloc0(sizeof(VncState)); int VAR_4; vs->VAR_1 = VAR_1; vs->VAR_0 = VAR_0; if (VAR_2) { vs->auth = VNC_AUTH_NONE; vs->subauth = VNC_AUTH_INVALID; } else { if (VAR_3) { vs->auth = VAR_0->ws_auth; vs->subauth = VNC_AUTH_INVALID; } else { vs->auth = VAR_0->auth; vs->subauth = VAR_0->subauth; } } VNC_DEBUG("Client sock=%d ws=%d auth=%d subauth=%d\n",
VAR_1, VAR_3, vs->auth, vs->subauth); vs->lossy_rect = g_malloc0(VNC_STAT_ROWS * sizeof (*vs->lossy_rect)); for (VAR_4 = 0; VAR_4 < VNC_STAT_ROWS; ++VAR_4) { vs->lossy_rect[VAR_4] = g_malloc0(VNC_STAT_COLS * sizeof (uint8_t)); } VNC_DEBUG("New client on socket %d\n", VAR_1); update_displaychangelistener(&VAR_0->dcl, VNC_REFRESH_INTERVAL_BASE); qemu_set_nonblock(vs->VAR_1); #ifdef CONFIG_VNC_WS
if (VAR_3) { vs->VAR_3 = 1; #ifdef CONFIG_VNC_TLS
if (VAR_0->ws_tls) { qemu_set_fd_handler(vs->VAR_1, vncws_tls_handshake_io, NULL, vs); } else #endif
{ qemu_set_fd_handler(vs->VAR_1, vncws_handshake_read, NULL, vs); } } else #endif
{ qemu_set_fd_handler(vs->VAR_1, vnc_client_read, NULL, vs); } vnc_client_cache_addr(vs); vnc_qmp_event(vs, QAPI_EVENT_VNC_CONNECTED); vnc_set_share_mode(vs, VNC_SHARE_MODE_CONNECTING); #ifdef CONFIG_VNC_WS
if (!vs->VAR_3)
#endif
{ vnc_init_state(vs); } if (VAR_0->num_connecting > VAR_0->connections_limit) { QTAILQ_FOREACH(vs, &VAR_0->clients, next) { if (vs->share_mode == VNC_SHARE_MODE_CONNECTING) { vnc_disconnect_start(vs); return; } } } }