static int ftp_passive_mode_epsv(FTPContext *s)

{

    char *res = NULL, *start = NULL, *end = NULL;

    int i;

    static const char d = '|';

    static const char *command = "EPSV\r\n";

    static const int epsv_codes[] = {229, 0};



    if (ftp_send_command(s, command, epsv_codes, &res) != 229 || !res)

        goto fail;



    for (i = 0; res[i]; ++i) {

        if (res[i] == '(') {

            start = res + i + 1;

        } else if (res[i] == ')') {

            end = res + i;

            break;

        }

    }

    if (!start || !end)

        goto fail;



    *end = '\0';

    if (strlen(start) < 5)

        goto fail;

    if (start[0] != d || start[1] != d || start[2] != d || end[-1] != d)

        goto fail;

    start += 3;

    end[-1] = '\0';



    s->server_data_port = atoi(start);

    av_dlog(s, "Server data port: %d\n", s->server_data_port);



    av_free(res);

    return 0;



  fail:

    av_free(res);

    s->server_data_port = -1;

    return AVERROR(ENOSYS);

}

static int ftp_passive_mode_epsv(FTPContext *s)

{

    char *res = NULL, *start = NULL, *end = NULL;

    int i;

    static const char d = '|';

    static const char *command = "EPSV\r\n";

    static const int epsv_codes[] = {229, 0};



    if (ftp_send_command(s, command, epsv_codes, &res) != 229 || !res)

        goto fail;



    for (i = 0; res[i]; ++i) {

        if (res[i] == '(') {

            start = res + i + 1;

        } else if (res[i] == ')') {

            end = res + i;

            break;

        }

    }

    if (!start || !end)

        goto fail;



    *end = '\0';

    if (strlen(start) < 5)

        goto fail;

    if (start[0] != d || start[1] != d || start[2] != d || end[-1] != d)

        goto fail;

    start += 3;

    end[-1] = '\0';



    s->server_data_port = atoi(start);

    av_dlog(s, "Server data port: %d\n", s->server_data_port);



    av_free(res);

    return 0;



  fail:

    av_free(res);

    s->server_data_port = -1;

    return AVERROR(ENOSYS);

}

static int FUNC_0(FTPContext *VAR_0)

{

    char *VAR_1 = NULL, *VAR_2 = NULL, *VAR_3 = NULL;

    int VAR_4;

    static const char VAR_5 = '|';

    static const char *VAR_6 = "EPSV\r\n";

    static const int VAR_7[] = {229, 0};



    if (ftp_send_command(VAR_0, VAR_6, VAR_7, &VAR_1) != 229 || !VAR_1)

        goto fail;



    for (VAR_4 = 0; VAR_1[VAR_4]; ++VAR_4) {

        if (VAR_1[VAR_4] == '(') {

            VAR_2 = VAR_1 + VAR_4 + 1;

        } else if (VAR_1[VAR_4] == ')') {

            VAR_3 = VAR_1 + VAR_4;

            break;

        }

    }

    if (!VAR_2 || !VAR_3)

        goto fail;



    *VAR_3 = '\0';

    if (strlen(VAR_2) < 5)

        goto fail;

    if (VAR_2[0] != VAR_5 || VAR_2[1] != VAR_5 || VAR_2[2] != VAR_5 || VAR_3[-1] != VAR_5)

        goto fail;

    VAR_2 += 3;

    VAR_3[-1] = '\0';



    VAR_0->server_data_port = atoi(VAR_2);

    av_dlog(VAR_0, "Server data port: %VAR_5\n", VAR_0->server_data_port);



    av_free(VAR_1);

    return 0;



  fail:

    av_free(VAR_1);

    VAR_0->server_data_port = -1;

    return AVERROR(ENOSYS);

}

static int FUNC_0(FTPContext *VAR_0)
{ char *VAR_1 = NULL, *VAR_2 = NULL, *VAR_3 = NULL; int VAR_4; static const char VAR_5 = '|'; static const char *VAR_6 = "EPSV\r\n"; static const int VAR_7[] = {229, 0}; if (ftp_send_command(VAR_0, VAR_6, VAR_7, &VAR_1) != 229 || !VAR_1)
goto fail; for (VAR_4 = 0; VAR_1[VAR_4]; ++VAR_4) { if (VAR_1[VAR_4] == '(') { VAR_2 = VAR_1 + VAR_4 + 1; } else if (VAR_1[VAR_4] == ')') { VAR_3 = VAR_1 + VAR_4; break; } } if (!VAR_2 || !VAR_3)
goto fail; *VAR_3 = '\0'; if (strlen(VAR_2) < 5)
goto fail; if (VAR_2[0] != VAR_5 || VAR_2[1] != VAR_5 || VAR_2[2] != VAR_5 || VAR_3[-1] != VAR_5)
goto fail; VAR_2 += 3; VAR_3[-1] = '\0'; VAR_0->server_data_port = atoi(VAR_2); av_dlog(VAR_0, "Server data port: %VAR_5\n", VAR_0->server_data_port); av_free(VAR_1); return 0; fail:
av_free(VAR_1); VAR_0->server_data_port = -1; return AVERROR(ENOSYS); }