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

{

    static const int verbosity = SSH_LOG_NOLOG;

    LIBSSHContext *s = h->priv_data;

    char proto[10], path[MAX_URL_SIZE], hostname[1024], credencials[1024];

    int port = 22, access, ret;

    long timeout = s->rw_timeout * 1000;

    const char *user = NULL, *pass = NULL;

    char *end = NULL;

    sftp_attributes stat;



    av_url_split(proto, sizeof(proto),

                 credencials, sizeof(credencials),

                 hostname, sizeof(hostname),

                 &port,

                 path, sizeof(path),

                 url);



    if (port <= 0 || port > 65535)

        port = 22;



    if (!(s->session = ssh_new())) {

        ret = AVERROR(ENOMEM);

        goto fail;

    }

    user = av_strtok(credencials, ":", &end);

    pass = av_strtok(end, ":", &end);

    ssh_options_set(s->session, SSH_OPTIONS_HOST, hostname);

    ssh_options_set(s->session, SSH_OPTIONS_PORT, &port);

    ssh_options_set(s->session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);

    if (timeout > 0)

        ssh_options_set(s->session, SSH_OPTIONS_TIMEOUT_USEC, &timeout);

    if (user)

        ssh_options_set(s->session, SSH_OPTIONS_USER, user);



    if (ssh_connect(s->session) != SSH_OK) {

        av_log(h, AV_LOG_ERROR, "Connection failed. %s\n", ssh_get_error(s->session));

        ret = AVERROR(EIO);

        goto fail;

    }



    if (pass && ssh_userauth_password(s->session, NULL, pass) != SSH_AUTH_SUCCESS) {

        av_log(h, AV_LOG_ERROR, "Error authenticating with password: %s\n", ssh_get_error(s->session));

        ret = AVERROR(EACCES);

        goto fail;

    }



    if (!(s->sftp = sftp_new(s->session))) {

        av_log(h, AV_LOG_ERROR, "SFTP session creation failed: %s\n", ssh_get_error(s->session));

        ret = AVERROR(ENOMEM);

        goto fail;

    }



    if (sftp_init(s->sftp) != SSH_OK) {

        av_log(h, AV_LOG_ERROR, "Error initializing sftp session: %s\n", ssh_get_error(s->session));

        ret = AVERROR(EIO);

        goto fail;

    }



    if ((flags & AVIO_FLAG_WRITE) && (flags & AVIO_FLAG_READ)) {

        access = O_CREAT | O_RDWR;

        if (s->trunc)

            access |= O_TRUNC;

    } else if (flags & AVIO_FLAG_WRITE) {

        access = O_CREAT | O_WRONLY;

        if (s->trunc)

            access |= O_TRUNC;

    } else {

        access = O_RDONLY;

    }



    /* 0666 = -rw-rw-rw- = read+write for everyone, minus umask */

    if (!(s->file = sftp_open(s->sftp, path, access, 0666))) {

        av_log(h, AV_LOG_ERROR, "Error opening sftp file: %s\n", ssh_get_error(s->session));

        ret = AVERROR(EIO);

        goto fail;

    }



    if (!(stat = sftp_fstat(s->file))) {

        av_log(h, AV_LOG_WARNING, "Cannot stat remote file %s.\n", path);

        s->filesize = -1;

    } else {

        s->filesize = stat->size;

        sftp_attributes_free(stat);

    }



    return 0;



  fail:

    libssh_close(h);

    return ret;

}

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

{

    static const int verbosity = SSH_LOG_NOLOG;

    LIBSSHContext *s = h->priv_data;

    char proto[10], path[MAX_URL_SIZE], hostname[1024], credencials[1024];

    int port = 22, access, ret;

    long timeout = s->rw_timeout * 1000;

    const char *user = NULL, *pass = NULL;

    char *end = NULL;

    sftp_attributes stat;



    av_url_split(proto, sizeof(proto),

                 credencials, sizeof(credencials),

                 hostname, sizeof(hostname),

                 &port,

                 path, sizeof(path),

                 url);



    if (port <= 0 || port > 65535)

        port = 22;



    if (!(s->session = ssh_new())) {

        ret = AVERROR(ENOMEM);

        goto fail;

    }

    user = av_strtok(credencials, ":", &end);

    pass = av_strtok(end, ":", &end);

    ssh_options_set(s->session, SSH_OPTIONS_HOST, hostname);

    ssh_options_set(s->session, SSH_OPTIONS_PORT, &port);

    ssh_options_set(s->session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);

    if (timeout > 0)

        ssh_options_set(s->session, SSH_OPTIONS_TIMEOUT_USEC, &timeout);

    if (user)

        ssh_options_set(s->session, SSH_OPTIONS_USER, user);



    if (ssh_connect(s->session) != SSH_OK) {

        av_log(h, AV_LOG_ERROR, "Connection failed. %s\n", ssh_get_error(s->session));

        ret = AVERROR(EIO);

        goto fail;

    }



    if (pass && ssh_userauth_password(s->session, NULL, pass) != SSH_AUTH_SUCCESS) {

        av_log(h, AV_LOG_ERROR, "Error authenticating with password: %s\n", ssh_get_error(s->session));

        ret = AVERROR(EACCES);

        goto fail;

    }



    if (!(s->sftp = sftp_new(s->session))) {

        av_log(h, AV_LOG_ERROR, "SFTP session creation failed: %s\n", ssh_get_error(s->session));

        ret = AVERROR(ENOMEM);

        goto fail;

    }



    if (sftp_init(s->sftp) != SSH_OK) {

        av_log(h, AV_LOG_ERROR, "Error initializing sftp session: %s\n", ssh_get_error(s->session));

        ret = AVERROR(EIO);

        goto fail;

    }



    if ((flags & AVIO_FLAG_WRITE) && (flags & AVIO_FLAG_READ)) {

        access = O_CREAT | O_RDWR;

        if (s->trunc)

            access |= O_TRUNC;

    } else if (flags & AVIO_FLAG_WRITE) {

        access = O_CREAT | O_WRONLY;

        if (s->trunc)

            access |= O_TRUNC;

    } else {

        access = O_RDONLY;

    }



    

    if (!(s->file = sftp_open(s->sftp, path, access, 0666))) {

        av_log(h, AV_LOG_ERROR, "Error opening sftp file: %s\n", ssh_get_error(s->session));

        ret = AVERROR(EIO);

        goto fail;

    }



    if (!(stat = sftp_fstat(s->file))) {

        av_log(h, AV_LOG_WARNING, "Cannot stat remote file %s.\n", path);

        s->filesize = -1;

    } else {

        s->filesize = stat->size;

        sftp_attributes_free(stat);

    }



    return 0;



  fail:

    libssh_close(h);

    return ret;

}

    if (pass && ssh_userauth_password(s->session, NULL, pass) != SSH_AUTH_SUCCESS) {         av_log(h, AV_LOG_ERROR, "Error authenticating with password: %s\n", ssh_get_error(s->session));         ret = AVERROR(EACCES);         goto fail;
static int FUNC_0(URLContext *VAR_0, const char *VAR_1, int VAR_2)

{

    static const int VAR_3 = SSH_LOG_NOLOG;

    LIBSSHContext *s = VAR_0->priv_data;

    char VAR_4[10], path[MAX_URL_SIZE], hostname[1024], credencials[1024];

    int VAR_5 = 22, VAR_6, VAR_7;

    long VAR_8 = s->rw_timeout * 1000;

    const char *VAR_9 = NULL, *VAR_10 = NULL;

    char *VAR_11 = NULL;

    sftp_attributes stat;



    av_url_split(VAR_4, sizeof(VAR_4),

                 credencials, sizeof(credencials),

                 hostname, sizeof(hostname),

                 &VAR_5,

                 path, sizeof(path),

                 VAR_1);



    if (VAR_5 <= 0 || VAR_5 > 65535)

        VAR_5 = 22;



    if (!(s->session = ssh_new())) {

        VAR_7 = AVERROR(ENOMEM);

        goto fail;

    }

    VAR_9 = av_strtok(credencials, ":", &VAR_11);

    VAR_10 = av_strtok(VAR_11, ":", &VAR_11);

    ssh_options_set(s->session, SSH_OPTIONS_HOST, hostname);

    ssh_options_set(s->session, SSH_OPTIONS_PORT, &VAR_5);

    ssh_options_set(s->session, SSH_OPTIONS_LOG_VERBOSITY, &VAR_3);

    if (VAR_8 > 0)

        ssh_options_set(s->session, SSH_OPTIONS_TIMEOUT_USEC, &VAR_8);

    if (VAR_9)

        ssh_options_set(s->session, SSH_OPTIONS_USER, VAR_9);



    if (ssh_connect(s->session) != SSH_OK) {

        av_log(VAR_0, AV_LOG_ERROR, "Connection failed. %s\n", ssh_get_error(s->session));

        VAR_7 = AVERROR(EIO);

        goto fail;

    }



    if (VAR_10 && ssh_userauth_password(s->session, NULL, VAR_10) != SSH_AUTH_SUCCESS) {

        av_log(VAR_0, AV_LOG_ERROR, "Error authenticating with password: %s\n", ssh_get_error(s->session));

        VAR_7 = AVERROR(EACCES);

        goto fail;

    }



    if (!(s->sftp = sftp_new(s->session))) {

        av_log(VAR_0, AV_LOG_ERROR, "SFTP session creation failed: %s\n", ssh_get_error(s->session));

        VAR_7 = AVERROR(ENOMEM);

        goto fail;

    }



    if (sftp_init(s->sftp) != SSH_OK) {

        av_log(VAR_0, AV_LOG_ERROR, "Error initializing sftp session: %s\n", ssh_get_error(s->session));

        VAR_7 = AVERROR(EIO);

        goto fail;

    }



    if ((VAR_2 & AVIO_FLAG_WRITE) && (VAR_2 & AVIO_FLAG_READ)) {

        VAR_6 = O_CREAT | O_RDWR;

        if (s->trunc)

            VAR_6 |= O_TRUNC;

    } else if (VAR_2 & AVIO_FLAG_WRITE) {

        VAR_6 = O_CREAT | O_WRONLY;

        if (s->trunc)

            VAR_6 |= O_TRUNC;

    } else {

        VAR_6 = O_RDONLY;

    }



    

    if (!(s->file = sftp_open(s->sftp, path, VAR_6, 0666))) {

        av_log(VAR_0, AV_LOG_ERROR, "Error opening sftp file: %s\n", ssh_get_error(s->session));

        VAR_7 = AVERROR(EIO);

        goto fail;

    }



    if (!(stat = sftp_fstat(s->file))) {

        av_log(VAR_0, AV_LOG_WARNING, "Cannot stat remote file %s.\n", path);

        s->filesize = -1;

    } else {

        s->filesize = stat->size;

        sftp_attributes_free(stat);

    }



    return 0;



  fail:

    libssh_close(VAR_0);

    return VAR_7;

}

static int FUNC_0(URLContext *VAR_0, const char *VAR_1, int VAR_2)
{ static const int VAR_3 = SSH_LOG_NOLOG; LIBSSHContext *s = VAR_0->priv_data; char VAR_4[10], path[MAX_URL_SIZE], hostname[1024], credencials[1024]; int VAR_5 = 22, VAR_6, VAR_7; long VAR_8 = s->rw_timeout * 1000; const char *VAR_9 = NULL, *VAR_10 = NULL; char *VAR_11 = NULL; sftp_attributes stat; av_url_split(VAR_4, sizeof(VAR_4),
credencials, sizeof(credencials),
hostname, sizeof(hostname),
&VAR_5,
path, sizeof(path),
VAR_1); if (VAR_5 <= 0 || VAR_5 > 65535)
VAR_5 = 22; if (!(s->session = ssh_new())) { VAR_7 = AVERROR(ENOMEM); goto fail; } VAR_9 = av_strtok(credencials, ":", &VAR_11); VAR_10 = av_strtok(VAR_11, ":", &VAR_11); ssh_options_set(s->session, SSH_OPTIONS_HOST, hostname); ssh_options_set(s->session, SSH_OPTIONS_PORT, &VAR_5); ssh_options_set(s->session, SSH_OPTIONS_LOG_VERBOSITY, &VAR_3); if (VAR_8 > 0)
ssh_options_set(s->session, SSH_OPTIONS_TIMEOUT_USEC, &VAR_8); if (VAR_9)
ssh_options_set(s->session, SSH_OPTIONS_USER, VAR_9); if (ssh_connect(s->session) != SSH_OK) { av_log(VAR_0, AV_LOG_ERROR, "Connection failed. %s\n", ssh_get_error(s->session)); VAR_7 = AVERROR(EIO); goto fail; } if (VAR_10 && ssh_userauth_password(s->session, NULL, VAR_10) != SSH_AUTH_SUCCESS) { av_log(VAR_0, AV_LOG_ERROR, "Error authenticating with password: %s\n", ssh_get_error(s->session)); VAR_7 = AVERROR(EACCES); goto fail; } if (!(s->sftp = sftp_new(s->session))) { av_log(VAR_0, AV_LOG_ERROR, "SFTP session creation failed: %s\n", ssh_get_error(s->session)); VAR_7 = AVERROR(ENOMEM); goto fail; } if (sftp_init(s->sftp) != SSH_OK) { av_log(VAR_0, AV_LOG_ERROR, "Error initializing sftp session: %s\n", ssh_get_error(s->session)); VAR_7 = AVERROR(EIO); goto fail; } if ((VAR_2 & AVIO_FLAG_WRITE) && (VAR_2 & AVIO_FLAG_READ)) { VAR_6 = O_CREAT | O_RDWR; if (s->trunc)
VAR_6 |= O_TRUNC; } else if (VAR_2 & AVIO_FLAG_WRITE) { VAR_6 = O_CREAT | O_WRONLY; if (s->trunc)
VAR_6 |= O_TRUNC; } else { VAR_6 = O_RDONLY; } if (!(s->file = sftp_open(s->sftp, path, VAR_6, 0666))) { av_log(VAR_0, AV_LOG_ERROR, "Error opening sftp file: %s\n", ssh_get_error(s->session)); VAR_7 = AVERROR(EIO); goto fail; } if (!(stat = sftp_fstat(s->file))) { av_log(VAR_0, AV_LOG_WARNING, "Cannot stat remote file %s.\n", path); s->filesize = -1; } else { s->filesize = stat->size; sftp_attributes_free(stat); } return 0; fail:
libssh_close(VAR_0); return VAR_7; }