static int ftp_open(URLContext *h, const char *url, int flags)

{

    char proto[10], path[MAX_URL_SIZE];

    int err;

    FTPContext *s = h->priv_data;



    av_dlog(h, "ftp protocol open\n");



    s->state = DISCONNECTED;

    s->filesize = -1;

    s->position = 0;



    av_url_split(proto, sizeof(proto),

                 s->credencials, sizeof(s->credencials),

                 s->hostname, sizeof(s->hostname),

                 &s->server_control_port,

                 path, sizeof(path),

                 url);



    if (s->server_control_port < 0 || s->server_control_port > 65535)

        s->server_control_port = 21;



    if ((err = ftp_connect_control_connection(h)) < 0)

        goto fail;



    if ((err = ftp_current_dir(s)) < 0)

        goto fail;

    av_strlcat(s->path, path, sizeof(s->path));



    if (ftp_restart(s, 0) < 0) {

        h->is_streamed = 1;

    } else {

        if (ftp_file_size(s) < 0 && flags & AVIO_FLAG_READ)

            h->is_streamed = 1;

        if (s->write_seekable != 1 && flags & AVIO_FLAG_WRITE)

            h->is_streamed = 1;

    }



    return 0;



  fail:

    av_log(h, AV_LOG_ERROR, "FTP open failed\n");

    ffurl_closep(&s->conn_control);

    ffurl_closep(&s->conn_data);

    return err;

}

static int ftp_open(URLContext *h, const char *url, int flags)

{

    char proto[10], path[MAX_URL_SIZE];

    int err;

    FTPContext *s = h->priv_data;



    av_dlog(h, "ftp protocol open\n");



    s->state = DISCONNECTED;

    s->filesize = -1;

    s->position = 0;



    av_url_split(proto, sizeof(proto),

                 s->credencials, sizeof(s->credencials),

                 s->hostname, sizeof(s->hostname),

                 &s->server_control_port,

                 path, sizeof(path),

                 url);



    if (s->server_control_port < 0 || s->server_control_port > 65535)

        s->server_control_port = 21;



    if ((err = ftp_connect_control_connection(h)) < 0)

        goto fail;



    if ((err = ftp_current_dir(s)) < 0)

        goto fail;

    av_strlcat(s->path, path, sizeof(s->path));



    if (ftp_restart(s, 0) < 0) {

        h->is_streamed = 1;

    } else {

        if (ftp_file_size(s) < 0 && flags & AVIO_FLAG_READ)

            h->is_streamed = 1;

        if (s->write_seekable != 1 && flags & AVIO_FLAG_WRITE)

            h->is_streamed = 1;

    }



    return 0;



  fail:

    av_log(h, AV_LOG_ERROR, "FTP open failed\n");

    ffurl_closep(&s->conn_control);

    ffurl_closep(&s->conn_data);

    return err;

}

static int FUNC_0(URLContext *VAR_0, const char *VAR_1, int VAR_2)

{

    char VAR_3[10], path[MAX_URL_SIZE];

    int VAR_4;

    FTPContext *s = VAR_0->priv_data;



    av_dlog(VAR_0, "ftp protocol open\n");



    s->state = DISCONNECTED;

    s->filesize = -1;

    s->position = 0;



    av_url_split(VAR_3, sizeof(VAR_3),

                 s->credencials, sizeof(s->credencials),

                 s->hostname, sizeof(s->hostname),

                 &s->server_control_port,

                 path, sizeof(path),

                 VAR_1);



    if (s->server_control_port < 0 || s->server_control_port > 65535)

        s->server_control_port = 21;



    if ((VAR_4 = ftp_connect_control_connection(VAR_0)) < 0)

        goto fail;



    if ((VAR_4 = ftp_current_dir(s)) < 0)

        goto fail;

    av_strlcat(s->path, path, sizeof(s->path));



    if (ftp_restart(s, 0) < 0) {

        VAR_0->is_streamed = 1;

    } else {

        if (ftp_file_size(s) < 0 && VAR_2 & AVIO_FLAG_READ)

            VAR_0->is_streamed = 1;

        if (s->write_seekable != 1 && VAR_2 & AVIO_FLAG_WRITE)

            VAR_0->is_streamed = 1;

    }



    return 0;



  fail:

    av_log(VAR_0, AV_LOG_ERROR, "FTP open failed\n");

    ffurl_closep(&s->conn_control);

    ffurl_closep(&s->conn_data);

    return VAR_4;

}

static int FUNC_0(URLContext *VAR_0, const char *VAR_1, int VAR_2)
{ char VAR_3[10], path[MAX_URL_SIZE]; int VAR_4; FTPContext *s = VAR_0->priv_data; av_dlog(VAR_0, "ftp protocol open\n"); s->state = DISCONNECTED; s->filesize = -1; s->position = 0; av_url_split(VAR_3, sizeof(VAR_3),
s->credencials, sizeof(s->credencials),
s->hostname, sizeof(s->hostname),
&s->server_control_port,
path, sizeof(path),
VAR_1); if (s->server_control_port < 0 || s->server_control_port > 65535)
s->server_control_port = 21; if ((VAR_4 = ftp_connect_control_connection(VAR_0)) < 0)
goto fail; if ((VAR_4 = ftp_current_dir(s)) < 0)
goto fail; av_strlcat(s->path, path, sizeof(s->path)); if (ftp_restart(s, 0) < 0) { VAR_0->is_streamed = 1; } else { if (ftp_file_size(s) < 0 && VAR_2 & AVIO_FLAG_READ)
VAR_0->is_streamed = 1; if (s->write_seekable != 1 && VAR_2 & AVIO_FLAG_WRITE)
VAR_0->is_streamed = 1; } return 0; fail:
av_log(VAR_0, AV_LOG_ERROR, "FTP open failed\n"); ffurl_closep(&s->conn_control); ffurl_closep(&s->conn_data); return VAR_4; }