static int ftp_connect_control_connection(URLContext *h)

{

    char buf[CONTROL_BUFFER_SIZE], opts_format[20];

    int err;

    AVDictionary *opts = NULL;

    FTPContext *s = h->priv_data;

    const int connect_codes[] = {220, 0};



    s->conn_control_block_flag = 0;



    if (!s->conn_control) {

        ff_url_join(buf, sizeof(buf), "tcp", NULL,

                    s->hostname, s->server_control_port, NULL);

        if (s->rw_timeout != -1) {

            snprintf(opts_format, sizeof(opts_format), "%d", s->rw_timeout);

            av_dict_set(&opts, "timeout", opts_format, 0);

        } /* if option is not given, don't pass it and let tcp use its own default */

        err = ffurl_open(&s->conn_control, buf, AVIO_FLAG_READ_WRITE,

                         &s->conn_control_interrupt_cb, &opts);

        av_dict_free(&opts);

        if (err < 0) {

            av_log(h, AV_LOG_ERROR, "Cannot open control connection\n");

            return err;

        }



        /* consume all messages from server */

        if (!ftp_status(s, NULL, connect_codes)) {

            av_log(h, AV_LOG_ERROR, "FTP server not ready for new users\n");

            err = AVERROR(EACCES);

            return err;

        }



        if ((err = ftp_auth(s)) < 0) {

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

            return err;

        }



        if ((err = ftp_type(s)) < 0) {

            av_dlog(h, "Set content type failed\n");

            return err;

        }

    }

    return 0;

}

static int ftp_connect_control_connection(URLContext *h)

{

    char buf[CONTROL_BUFFER_SIZE], opts_format[20];

    int err;

    AVDictionary *opts = NULL;

    FTPContext *s = h->priv_data;

    const int connect_codes[] = {220, 0};



    s->conn_control_block_flag = 0;



    if (!s->conn_control) {

        ff_url_join(buf, sizeof(buf), "tcp", NULL,

                    s->hostname, s->server_control_port, NULL);

        if (s->rw_timeout != -1) {

            snprintf(opts_format, sizeof(opts_format), "%d", s->rw_timeout);

            av_dict_set(&opts, "timeout", opts_format, 0);

        } 

        err = ffurl_open(&s->conn_control, buf, AVIO_FLAG_READ_WRITE,

                         &s->conn_control_interrupt_cb, &opts);

        av_dict_free(&opts);

        if (err < 0) {

            av_log(h, AV_LOG_ERROR, "Cannot open control connection\n");

            return err;

        }



        

        if (!ftp_status(s, NULL, connect_codes)) {

            av_log(h, AV_LOG_ERROR, "FTP server not ready for new users\n");

            err = AVERROR(EACCES);

            return err;

        }



        if ((err = ftp_auth(s)) < 0) {

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

            return err;

        }



        if ((err = ftp_type(s)) < 0) {

            av_dlog(h, "Set content type failed\n");

            return err;

        }

    }

    return 0;

}

static int FUNC_0(URLContext *VAR_0)

{

    char VAR_1[CONTROL_BUFFER_SIZE], opts_format[20];

    int VAR_2;

    AVDictionary *opts = NULL;

    FTPContext *s = VAR_0->priv_data;

    const int VAR_3[] = {220, 0};



    s->conn_control_block_flag = 0;



    if (!s->conn_control) {

        ff_url_join(VAR_1, sizeof(VAR_1), "tcp", NULL,

                    s->hostname, s->server_control_port, NULL);

        if (s->rw_timeout != -1) {

            snprintf(opts_format, sizeof(opts_format), "%d", s->rw_timeout);

            av_dict_set(&opts, "timeout", opts_format, 0);

        } 

        VAR_2 = ffurl_open(&s->conn_control, VAR_1, AVIO_FLAG_READ_WRITE,

                         &s->conn_control_interrupt_cb, &opts);

        av_dict_free(&opts);

        if (VAR_2 < 0) {

            av_log(VAR_0, AV_LOG_ERROR, "Cannot open control connection\n");

            return VAR_2;

        }



        

        if (!ftp_status(s, NULL, VAR_3)) {

            av_log(VAR_0, AV_LOG_ERROR, "FTP server not ready for new users\n");

            VAR_2 = AVERROR(EACCES);

            return VAR_2;

        }



        if ((VAR_2 = ftp_auth(s)) < 0) {

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

            return VAR_2;

        }



        if ((VAR_2 = ftp_type(s)) < 0) {

            av_dlog(VAR_0, "Set content type failed\n");

            return VAR_2;

        }

    }

    return 0;

}

static int FUNC_0(URLContext *VAR_0)
{ char VAR_1[CONTROL_BUFFER_SIZE], opts_format[20]; int VAR_2; AVDictionary *opts = NULL; FTPContext *s = VAR_0->priv_data; const int VAR_3[] = {220, 0}; s->conn_control_block_flag = 0; if (!s->conn_control) { ff_url_join(VAR_1, sizeof(VAR_1), "tcp", NULL,
s->hostname, s->server_control_port, NULL); if (s->rw_timeout != -1) { snprintf(opts_format, sizeof(opts_format), "%d", s->rw_timeout); av_dict_set(&opts, "timeout", opts_format, 0); } VAR_2 = ffurl_open(&s->conn_control, VAR_1, AVIO_FLAG_READ_WRITE,
&s->conn_control_interrupt_cb, &opts); av_dict_free(&opts); if (VAR_2 < 0) { av_log(VAR_0, AV_LOG_ERROR, "Cannot open control connection\n"); return VAR_2; } if (!ftp_status(s, NULL, VAR_3)) { av_log(VAR_0, AV_LOG_ERROR, "FTP server not ready for new users\n"); VAR_2 = AVERROR(EACCES); return VAR_2; } if ((VAR_2 = ftp_auth(s)) < 0) { av_log(VAR_0, AV_LOG_ERROR, "FTP authentication failed\n"); return VAR_2; } if ((VAR_2 = ftp_type(s)) < 0) { av_dlog(VAR_0, "Set content type failed\n"); return VAR_2; } } return 0; }