static int qio_channel_websock_handshake_read(QIOChannelWebsock *ioc,

                                              Error **errp)

{

    char *handshake_end;

    ssize_t ret;

    /* Typical HTTP headers from novnc are 512 bytes, so limiting

     * total header size to 4096 is easily enough. */

    size_t want = 4096 - ioc->encinput.offset;

    buffer_reserve(&ioc->encinput, want);

    ret = qio_channel_read(ioc->master,

                           (char *)buffer_end(&ioc->encinput), want, errp);

    if (ret < 0) {

        return -1;

    }

    ioc->encinput.offset += ret;



    handshake_end = g_strstr_len((char *)ioc->encinput.buffer,

                                 ioc->encinput.offset,

                                 QIO_CHANNEL_WEBSOCK_HANDSHAKE_END);

    if (!handshake_end) {

        if (ioc->encinput.offset >= 4096) {

            error_setg(errp,

                       "End of headers not found in first 4096 bytes");

            return -1;

        } else {

            return 0;

        }

    }

    *handshake_end = '\0';



    if (qio_channel_websock_handshake_process(ioc,

                                              (char *)ioc->encinput.buffer,

                                              errp) < 0) {

        return -1;

    }



    buffer_advance(&ioc->encinput,

                   handshake_end - (char *)ioc->encinput.buffer +

                   strlen(QIO_CHANNEL_WEBSOCK_HANDSHAKE_END));

    return 1;

}

static int qio_channel_websock_handshake_read(QIOChannelWebsock *ioc,

                                              Error **errp)

{

    char *handshake_end;

    ssize_t ret;

    



    size_t want = 4096 - ioc->encinput.offset;

    buffer_reserve(&ioc->encinput, want);

    ret = qio_channel_read(ioc->master,

                           (char *)buffer_end(&ioc->encinput), want, errp);

    if (ret < 0) {

        return -1;

    }

    ioc->encinput.offset += ret;



    handshake_end = g_strstr_len((char *)ioc->encinput.buffer,

                                 ioc->encinput.offset,

                                 QIO_CHANNEL_WEBSOCK_HANDSHAKE_END);

    if (!handshake_end) {

        if (ioc->encinput.offset >= 4096) {

            error_setg(errp,

                       "End of headers not found in first 4096 bytes");

            return -1;

        } else {

            return 0;

        }

    }

    *handshake_end = '\0';



    if (qio_channel_websock_handshake_process(ioc,

                                              (char *)ioc->encinput.buffer,

                                              errp) < 0) {

        return -1;

    }



    buffer_advance(&ioc->encinput,

                   handshake_end - (char *)ioc->encinput.buffer +

                   strlen(QIO_CHANNEL_WEBSOCK_HANDSHAKE_END));

    return 1;

}

            return 0;             return 0;         return -1;         return -1;         return -1;         return -1;         return -1;         return -1;         return -1;         return -1;         return -1;         return -1;         return -1;         return -1;         return -1;             return -1;     if (qio_channel_websock_handshake_process(ioc,                                               (char *)ioc->encinput.buffer,                                               errp) < 0) {         return -1;
static int FUNC_0(QIOChannelWebsock *VAR_0,

                                              Error **VAR_1)

{

    char *VAR_2;

    ssize_t ret;

    



    size_t want = 4096 - VAR_0->encinput.offset;

    buffer_reserve(&VAR_0->encinput, want);

    ret = qio_channel_read(VAR_0->master,

                           (char *)buffer_end(&VAR_0->encinput), want, VAR_1);

    if (ret < 0) {

        return -1;

    }

    VAR_0->encinput.offset += ret;



    VAR_2 = g_strstr_len((char *)VAR_0->encinput.buffer,

                                 VAR_0->encinput.offset,

                                 QIO_CHANNEL_WEBSOCK_HANDSHAKE_END);

    if (!VAR_2) {

        if (VAR_0->encinput.offset >= 4096) {

            error_setg(VAR_1,

                       "End of headers not found in first 4096 bytes");

            return -1;

        } else {

            return 0;

        }

    }

    *VAR_2 = '\0';



    if (qio_channel_websock_handshake_process(VAR_0,

                                              (char *)VAR_0->encinput.buffer,

                                              VAR_1) < 0) {

        return -1;

    }



    buffer_advance(&VAR_0->encinput,

                   VAR_2 - (char *)VAR_0->encinput.buffer +

                   strlen(QIO_CHANNEL_WEBSOCK_HANDSHAKE_END));

    return 1;

}

static int FUNC_0(QIOChannelWebsock *VAR_0,
Error **VAR_1)
{ char *VAR_2; ssize_t ret; size_t want = 4096 - VAR_0->encinput.offset; buffer_reserve(&VAR_0->encinput, want); ret = qio_channel_read(VAR_0->master,
(char *)buffer_end(&VAR_0->encinput), want, VAR_1); if (ret < 0) { return -1; } VAR_0->encinput.offset += ret; VAR_2 = g_strstr_len((char *)VAR_0->encinput.buffer,
VAR_0->encinput.offset,
QIO_CHANNEL_WEBSOCK_HANDSHAKE_END); if (!VAR_2) { if (VAR_0->encinput.offset >= 4096) { error_setg(VAR_1,
"End of headers not found in first 4096 bytes"); return -1; } else { return 0; } } *VAR_2 = '\0'; if (qio_channel_websock_handshake_process(VAR_0,
(char *)VAR_0->encinput.buffer,
VAR_1) < 0) { return -1; } buffer_advance(&VAR_0->encinput,
VAR_2 - (char *)VAR_0->encinput.buffer +
strlen(QIO_CHANNEL_WEBSOCK_HANDSHAKE_END)); return 1; }