static int vnc_display_get_addresses(QemuOpts *opts,

                                     bool reverse,

                                     SocketAddress ***retsaddr,

                                     size_t *retnsaddr,

                                     SocketAddress ***retwsaddr,

                                     size_t *retnwsaddr,

                                     Error **errp)

{

    SocketAddress *saddr = NULL;

    SocketAddress *wsaddr = NULL;

    QemuOptsIter addriter;

    const char *addr;

    int to = qemu_opt_get_number(opts, "to", 0);

    bool has_ipv4 = qemu_opt_get(opts, "ipv4");

    bool has_ipv6 = qemu_opt_get(opts, "ipv6");

    bool ipv4 = qemu_opt_get_bool(opts, "ipv4", false);

    bool ipv6 = qemu_opt_get_bool(opts, "ipv6", false);

    size_t i;

    int displaynum = -1;

    int ret = -1;



    *retsaddr = NULL;

    *retnsaddr = 0;

    *retwsaddr = NULL;

    *retnwsaddr = 0;



    addr = qemu_opt_get(opts, "vnc");

    if (addr == NULL || g_str_equal(addr, "none")) {

        ret = 0;

        goto cleanup;

    }

    if (qemu_opt_get(opts, "websocket") &&

        !qcrypto_hash_supports(QCRYPTO_HASH_ALG_SHA1)) {

        error_setg(errp,

                   "SHA1 hash support is required for websockets");

        goto cleanup;

    }



    qemu_opt_iter_init(&addriter, opts, "vnc");

    while ((addr = qemu_opt_iter_next(&addriter)) != NULL) {

        int rv;

        rv = vnc_display_get_address(addr, false, reverse, 0, to,

                                     has_ipv4, has_ipv6,

                                     ipv4, ipv6,

                                     &saddr, errp);

        if (rv < 0) {

            goto cleanup;

        }

        /* Historical compat - first listen address can be used

         * to set the default websocket port

         */

        if (displaynum == -1) {

            displaynum = rv;

        }

        *retsaddr = g_renew(SocketAddress *, *retsaddr, *retnsaddr + 1);

        (*retsaddr)[(*retnsaddr)++] = saddr;

    }



    /* If we had multiple primary displays, we don't do defaults

     * for websocket, and require explicit config instead. */

    if (*retnsaddr > 1) {

        displaynum = -1;

    }



    qemu_opt_iter_init(&addriter, opts, "websocket");

    while ((addr = qemu_opt_iter_next(&addriter)) != NULL) {

        if (vnc_display_get_address(addr, true, reverse, displaynum, to,

                                    has_ipv4, has_ipv6,

                                    ipv4, ipv6,

                                    &wsaddr, errp) < 0) {

            goto cleanup;

        }



        /* Historical compat - if only a single listen address was

         * provided, then this is used to set the default listen

         * address for websocket too

         */

        if (*retnsaddr == 1 &&

            (*retsaddr)[0]->type == SOCKET_ADDRESS_TYPE_INET &&

            wsaddr->type == SOCKET_ADDRESS_TYPE_INET &&

            g_str_equal(wsaddr->u.inet.host, "") &&

            !g_str_equal((*retsaddr)[0]->u.inet.host, "")) {

            g_free(wsaddr->u.inet.host);

            wsaddr->u.inet.host = g_strdup((*retsaddr)[0]->u.inet.host);

        }



        *retwsaddr = g_renew(SocketAddress *, *retwsaddr, *retnwsaddr + 1);

        (*retwsaddr)[(*retnwsaddr)++] = wsaddr;

    }



    ret = 0;

 cleanup:

    if (ret < 0) {

        for (i = 0; i < *retnsaddr; i++) {

            qapi_free_SocketAddress((*retsaddr)[i]);

        }

        g_free(*retsaddr);

        for (i = 0; i < *retnwsaddr; i++) {

            qapi_free_SocketAddress((*retwsaddr)[i]);

        }

        g_free(*retwsaddr);

        *retsaddr = *retwsaddr = NULL;

        *retnsaddr = *retnwsaddr = 0;

    }

    return ret;

}

static int vnc_display_get_addresses(QemuOpts *opts,

                                     bool reverse,

                                     SocketAddress ***retsaddr,

                                     size_t *retnsaddr,

                                     SocketAddress ***retwsaddr,

                                     size_t *retnwsaddr,

                                     Error **errp)

{

    SocketAddress *saddr = NULL;

    SocketAddress *wsaddr = NULL;

    QemuOptsIter addriter;

    const char *addr;

    int to = qemu_opt_get_number(opts, "to", 0);

    bool has_ipv4 = qemu_opt_get(opts, "ipv4");

    bool has_ipv6 = qemu_opt_get(opts, "ipv6");

    bool ipv4 = qemu_opt_get_bool(opts, "ipv4", false);

    bool ipv6 = qemu_opt_get_bool(opts, "ipv6", false);

    size_t i;

    int displaynum = -1;

    int ret = -1;



    *retsaddr = NULL;

    *retnsaddr = 0;

    *retwsaddr = NULL;

    *retnwsaddr = 0;



    addr = qemu_opt_get(opts, "vnc");

    if (addr == NULL || g_str_equal(addr, "none")) {

        ret = 0;

        goto cleanup;

    }

    if (qemu_opt_get(opts, "websocket") &&

        !qcrypto_hash_supports(QCRYPTO_HASH_ALG_SHA1)) {

        error_setg(errp,

                   "SHA1 hash support is required for websockets");

        goto cleanup;

    }



    qemu_opt_iter_init(&addriter, opts, "vnc");

    while ((addr = qemu_opt_iter_next(&addriter)) != NULL) {

        int rv;

        rv = vnc_display_get_address(addr, false, reverse, 0, to,

                                     has_ipv4, has_ipv6,

                                     ipv4, ipv6,

                                     &saddr, errp);

        if (rv < 0) {

            goto cleanup;

        }

        





        if (displaynum == -1) {

            displaynum = rv;

        }

        *retsaddr = g_renew(SocketAddress *, *retsaddr, *retnsaddr + 1);

        (*retsaddr)[(*retnsaddr)++] = saddr;

    }



    



    if (*retnsaddr > 1) {

        displaynum = -1;

    }



    qemu_opt_iter_init(&addriter, opts, "websocket");

    while ((addr = qemu_opt_iter_next(&addriter)) != NULL) {

        if (vnc_display_get_address(addr, true, reverse, displaynum, to,

                                    has_ipv4, has_ipv6,

                                    ipv4, ipv6,

                                    &wsaddr, errp) < 0) {

            goto cleanup;

        }



        







        if (*retnsaddr == 1 &&

            (*retsaddr)[0]->type == SOCKET_ADDRESS_TYPE_INET &&

            wsaddr->type == SOCKET_ADDRESS_TYPE_INET &&

            g_str_equal(wsaddr->u.inet.host, "") &&

            !g_str_equal((*retsaddr)[0]->u.inet.host, "")) {

            g_free(wsaddr->u.inet.host);

            wsaddr->u.inet.host = g_strdup((*retsaddr)[0]->u.inet.host);

        }



        *retwsaddr = g_renew(SocketAddress *, *retwsaddr, *retnwsaddr + 1);

        (*retwsaddr)[(*retnwsaddr)++] = wsaddr;

    }



    ret = 0;

 cleanup:

    if (ret < 0) {

        for (i = 0; i < *retnsaddr; i++) {

            qapi_free_SocketAddress((*retsaddr)[i]);

        }

        g_free(*retsaddr);

        for (i = 0; i < *retnwsaddr; i++) {

            qapi_free_SocketAddress((*retwsaddr)[i]);

        }

        g_free(*retwsaddr);

        *retsaddr = *retwsaddr = NULL;

        *retnsaddr = *retnwsaddr = 0;

    }

    return ret;

}

    size_t i;         for (i = 0; i < *retnsaddr; i++) {             qapi_free_SocketAddress((*retsaddr)[i]);         g_free(*retsaddr);         for (i = 0; i < *retnwsaddr; i++) {             qapi_free_SocketAddress((*retwsaddr)[i]);         g_free(*retwsaddr);         *retsaddr = *retwsaddr = NULL;         *retnsaddr = *retnwsaddr = 0;     size_t i;
static int FUNC_0(QemuOpts *VAR_0,

                                     bool VAR_1,

                                     SocketAddress ***VAR_2,

                                     size_t *VAR_3,

                                     SocketAddress ***VAR_4,

                                     size_t *VAR_5,

                                     Error **VAR_6)

{

    SocketAddress *saddr = NULL;

    SocketAddress *wsaddr = NULL;

    QemuOptsIter addriter;

    const char *VAR_7;

    int VAR_8 = qemu_opt_get_number(VAR_0, "VAR_8", 0);

    bool has_ipv4 = qemu_opt_get(VAR_0, "ipv4");

    bool has_ipv6 = qemu_opt_get(VAR_0, "ipv6");

    bool ipv4 = qemu_opt_get_bool(VAR_0, "ipv4", false);

    bool ipv6 = qemu_opt_get_bool(VAR_0, "ipv6", false);

    size_t i;

    int VAR_9 = -1;

    int VAR_10 = -1;



    *VAR_2 = NULL;

    *VAR_3 = 0;

    *VAR_4 = NULL;

    *VAR_5 = 0;



    VAR_7 = qemu_opt_get(VAR_0, "vnc");

    if (VAR_7 == NULL || g_str_equal(VAR_7, "none")) {

        VAR_10 = 0;

        goto cleanup;

    }

    if (qemu_opt_get(VAR_0, "websocket") &&

        !qcrypto_hash_supports(QCRYPTO_HASH_ALG_SHA1)) {

        error_setg(VAR_6,

                   "SHA1 hash support is required for websockets");

        goto cleanup;

    }



    qemu_opt_iter_init(&addriter, VAR_0, "vnc");

    while ((VAR_7 = qemu_opt_iter_next(&addriter)) != NULL) {

        int VAR_11;

        VAR_11 = vnc_display_get_address(VAR_7, false, VAR_1, 0, VAR_8,

                                     has_ipv4, has_ipv6,

                                     ipv4, ipv6,

                                     &saddr, VAR_6);

        if (VAR_11 < 0) {

            goto cleanup;

        }

        





        if (VAR_9 == -1) {

            VAR_9 = VAR_11;

        }

        *VAR_2 = g_renew(SocketAddress *, *VAR_2, *VAR_3 + 1);

        (*VAR_2)[(*VAR_3)++] = saddr;

    }



    



    if (*VAR_3 > 1) {

        VAR_9 = -1;

    }



    qemu_opt_iter_init(&addriter, VAR_0, "websocket");

    while ((VAR_7 = qemu_opt_iter_next(&addriter)) != NULL) {

        if (vnc_display_get_address(VAR_7, true, VAR_1, VAR_9, VAR_8,

                                    has_ipv4, has_ipv6,

                                    ipv4, ipv6,

                                    &wsaddr, VAR_6) < 0) {

            goto cleanup;

        }



        







        if (*VAR_3 == 1 &&

            (*VAR_2)[0]->type == SOCKET_ADDRESS_TYPE_INET &&

            wsaddr->type == SOCKET_ADDRESS_TYPE_INET &&

            g_str_equal(wsaddr->u.inet.host, "") &&

            !g_str_equal((*VAR_2)[0]->u.inet.host, "")) {

            g_free(wsaddr->u.inet.host);

            wsaddr->u.inet.host = g_strdup((*VAR_2)[0]->u.inet.host);

        }



        *VAR_4 = g_renew(SocketAddress *, *VAR_4, *VAR_5 + 1);

        (*VAR_4)[(*VAR_5)++] = wsaddr;

    }



    VAR_10 = 0;

 cleanup:

    if (VAR_10 < 0) {

        for (i = 0; i < *VAR_3; i++) {

            qapi_free_SocketAddress((*VAR_2)[i]);

        }

        g_free(*VAR_2);

        for (i = 0; i < *VAR_5; i++) {

            qapi_free_SocketAddress((*VAR_4)[i]);

        }

        g_free(*VAR_4);

        *VAR_2 = *VAR_4 = NULL;

        *VAR_3 = *VAR_5 = 0;

    }

    return VAR_10;

}

static int FUNC_0(QemuOpts *VAR_0,
bool VAR_1,
SocketAddress ***VAR_2,
size_t *VAR_3,
SocketAddress ***VAR_4,
size_t *VAR_5,
Error **VAR_6)
{ SocketAddress *saddr = NULL; SocketAddress *wsaddr = NULL; QemuOptsIter addriter; const char *VAR_7; int VAR_8 = qemu_opt_get_number(VAR_0, "VAR_8", 0); bool has_ipv4 = qemu_opt_get(VAR_0, "ipv4"); bool has_ipv6 = qemu_opt_get(VAR_0, "ipv6"); bool ipv4 = qemu_opt_get_bool(VAR_0, "ipv4", false); bool ipv6 = qemu_opt_get_bool(VAR_0, "ipv6", false); size_t i; int VAR_9 = -1; int VAR_10 = -1; *VAR_2 = NULL; *VAR_3 = 0; *VAR_4 = NULL; *VAR_5 = 0; VAR_7 = qemu_opt_get(VAR_0, "vnc"); if (VAR_7 == NULL || g_str_equal(VAR_7, "none")) { VAR_10 = 0; goto cleanup; } if (qemu_opt_get(VAR_0, "websocket") &&
!qcrypto_hash_supports(QCRYPTO_HASH_ALG_SHA1)) { error_setg(VAR_6,
"SHA1 hash support is required for websockets"); goto cleanup; } qemu_opt_iter_init(&addriter, VAR_0, "vnc"); while ((VAR_7 = qemu_opt_iter_next(&addriter)) != NULL) { int VAR_11; VAR_11 = vnc_display_get_address(VAR_7, false, VAR_1, 0, VAR_8,
has_ipv4, has_ipv6,
ipv4, ipv6,
&saddr, VAR_6); if (VAR_11 < 0) { goto cleanup; } if (VAR_9 == -1) { VAR_9 = VAR_11; } *VAR_2 = g_renew(SocketAddress *, *VAR_2, *VAR_3 + 1); (*VAR_2)[(*VAR_3)++] = saddr; } if (*VAR_3 > 1) { VAR_9 = -1; } qemu_opt_iter_init(&addriter, VAR_0, "websocket"); while ((VAR_7 = qemu_opt_iter_next(&addriter)) != NULL) { if (vnc_display_get_address(VAR_7, true, VAR_1, VAR_9, VAR_8,
has_ipv4, has_ipv6,
ipv4, ipv6,
&wsaddr, VAR_6) < 0) { goto cleanup; } if (*VAR_3 == 1 &&
(*VAR_2)[0]->type == SOCKET_ADDRESS_TYPE_INET &&
wsaddr->type == SOCKET_ADDRESS_TYPE_INET &&
g_str_equal(wsaddr->u.inet.host, "") &&
!g_str_equal((*VAR_2)[0]->u.inet.host, "")) { g_free(wsaddr->u.inet.host); wsaddr->u.inet.host = g_strdup((*VAR_2)[0]->u.inet.host); } *VAR_4 = g_renew(SocketAddress *, *VAR_4, *VAR_5 + 1); (*VAR_4)[(*VAR_5)++] = wsaddr; } VAR_10 = 0; cleanup:
if (VAR_10 < 0) { for (i = 0; i < *VAR_3; i++) { qapi_free_SocketAddress((*VAR_2)[i]); } g_free(*VAR_2); for (i = 0; i < *VAR_5; i++) { qapi_free_SocketAddress((*VAR_4)[i]); } g_free(*VAR_4); *VAR_2 = *VAR_4 = NULL; *VAR_3 = *VAR_5 = 0; } return VAR_10; }