int BIO_parse_hostserv(const char *hostserv, char **host, char **service,
                       enum BIO_hostserv_priorities hostserv_prio)
{
    const char *h = NULL; size_t hl = 0;
    const char *p = NULL; size_t pl = 0;
    if (*hostserv == '[') {
        if ((p = strchr(hostserv, ']')) == NULL)
            goto spec_err;
        h = hostserv + 1;
        hl = p - h;
        p++;
        if (*p == '\0')
            p = NULL;
        else if (*p != ':')
            goto spec_err;
        else {
            p++;
            pl = strlen(p);
        }
    } else {
        const char *p2 = strrchr(hostserv, ':');
        p = strchr(hostserv, ':');
        if (p != p2)
            goto amb_err;
        if (p != NULL) {
            h = hostserv;
            hl = p - h;
            p++;
            pl = strlen(p);
        } else if (hostserv_prio == BIO_PARSE_PRIO_HOST) {
            h = hostserv;
            hl = strlen(h);
        } else {
            p = hostserv;
            pl = strlen(p);
        }
    }
    if (strchr(p, ':'))
        goto spec_err;
    if (h != NULL && host != NULL) {
        if (hl == 0
            || (hl == 1 && h[0] == '*')) {
            *host = NULL;
        } else {
            *host = OPENSSL_strndup(h, hl);
            if (*host == NULL)
                goto memerr;
        }
    }
    if (p != NULL && service != NULL) {
        if (pl == 0
            || (pl == 1 && p[0] == '*')) {
            *service = NULL;
        } else {
            *service = OPENSSL_strndup(p, pl);
            if (*service == NULL)
                goto memerr;
        }
    }
    return 1;
 amb_err:
    BIOerr(BIO_F_BIO_PARSE_HOSTSERV, BIO_R_AMBIGUOUS_HOST_OR_SERVICE);
    return 0;
 spec_err:
    BIOerr(BIO_F_BIO_PARSE_HOSTSERV, BIO_R_MALFORMED_HOST_OR_SERVICE);
    return 0;
 memerr:
    BIOerr(BIO_F_BIO_PARSE_HOSTSERV, ERR_R_MALLOC_FAILURE);
    return 0;
}
["int BIO_parse_hostserv(const char *hostserv, char **host, char **service,\n                       enum BIO_hostserv_priorities hostserv_prio)\n{\n    const char *h = NULL; size_t hl = 0;\n    const char *p = NULL; size_t pl = 0;\n    if (*hostserv == '[') {\n        if ((p = strchr(hostserv, ']')) == NULL)\n            goto spec_err;\n        h = hostserv + 1;\n        hl = p - h;\n        p++;\n        if (*p == '\\0')\n            p = NULL;\n        else if (*p != ':')\n            goto spec_err;\n        else {\n            p++;\n            pl = strlen(p);\n        }\n    } else {\n        const char *p2 = strrchr(hostserv, ':');\n        p = strchr(hostserv, ':');\n        if (p != p2)\n            goto amb_err;\n        if (p != NULL) {\n            h = hostserv;\n            hl = p - h;\n            p++;\n            pl = strlen(p);\n        } else if (hostserv_prio == BIO_PARSE_PRIO_HOST) {\n            h = hostserv;\n            hl = strlen(h);\n        } else {\n            p = hostserv;\n            pl = strlen(p);\n        }\n    }\n    if (strchr(p, ':'))\n        goto spec_err;\n    if (h != NULL && host != NULL) {\n        if (hl == 0\n            || (hl == 1 && h[0] == '*')) {\n            *host = NULL;\n        } else {\n            *host = OPENSSL_strndup(h, hl);\n            if (*host == NULL)\n                goto memerr;\n        }\n    }\n    if (p != NULL && service != NULL) {\n        if (pl == 0\n            || (pl == 1 && p[0] == '*')) {\n            *service = NULL;\n        } else {\n            *service = OPENSSL_strndup(p, pl);\n            if (*service == NULL)\n                goto memerr;\n        }\n    }\n    return 1;\n amb_err:\n    BIOerr(BIO_F_BIO_PARSE_HOSTSERV, BIO_R_AMBIGUOUS_HOST_OR_SERVICE);\n    return 0;\n spec_err:\n    BIOerr(BIO_F_BIO_PARSE_HOSTSERV, BIO_R_MALFORMED_HOST_OR_SERVICE);\n    return 0;\n memerr:\n    BIOerr(BIO_F_BIO_PARSE_HOSTSERV, ERR_R_MALLOC_FAILURE);\n    return 0;\n}"]