diff options
author | Mariusz SzczepaĆczyk <mszczepanczyk@gmail.com> | 2015-06-23 03:04:21 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2015-06-24 00:44:09 +0200 |
commit | b23d2bac0d709b5642895d1acdf0cfef689d1ba1 (patch) | |
tree | f924e1950f80fe504d21e161683e9f0050f3bdad | |
parent | 0cce94fb1037d0866dd6e5c2d980eacf0b15bcdc (diff) | |
download | ffmpeg-b23d2bac0d709b5642895d1acdf0cfef689d1ba1.tar.gz |
lavf/libssh: implement move and delete callbacks
Reviewed-by: Lukasz Marek <lukasz.m.luki2 at gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavformat/libssh.c | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/libavformat/libssh.c b/libavformat/libssh.c index ee429241c0..3c056f874a 100644 --- a/libavformat/libssh.c +++ b/libavformat/libssh.c @@ -392,6 +392,86 @@ static int libssh_close_dir(URLContext *h) return 0; } +static int libssh_delete(URLContext *h) +{ + int ret; + LIBSSHContext *libssh = h->priv_data; + sftp_attributes attr = NULL; + char path[MAX_URL_SIZE]; + + if ((ret = libssh_connect(h, h->filename, path, sizeof(path))) < 0) + goto cleanup; + + if (!(attr = sftp_stat(libssh->sftp, path))) { + ret = AVERROR(sftp_get_error(libssh->sftp)); + goto cleanup; + } + + if (attr->type == SSH_FILEXFER_TYPE_DIRECTORY) { + if (sftp_rmdir(libssh->sftp, path) < 0) { + ret = AVERROR(sftp_get_error(libssh->sftp)); + goto cleanup; + } + } else { + if (sftp_unlink(libssh->sftp, path) < 0) { + ret = AVERROR(sftp_get_error(libssh->sftp)); + goto cleanup; + } + } + + ret = 0; + +cleanup: + if (attr) + sftp_attributes_free(attr); + libssh_close(h); + return ret; +} + +static int libssh_move(URLContext *h_src, URLContext *h_dst) +{ + int ret; + LIBSSHContext *libssh = h_src->priv_data; + char path_src[MAX_URL_SIZE], path_dst[MAX_URL_SIZE]; + char hostname_src[1024], hostname_dst[1024]; + char credentials_src[1024], credentials_dst[1024]; + int port_src = 22, port_dst = 22; + + av_url_split(NULL, 0, + credentials_src, sizeof(credentials_src), + hostname_src, sizeof(hostname_src), + &port_src, + path_src, sizeof(path_src), + h_src->filename); + + av_url_split(NULL, 0, + credentials_dst, sizeof(credentials_dst), + hostname_dst, sizeof(hostname_dst), + &port_dst, + path_dst, sizeof(path_dst), + h_dst->filename); + + if (strcmp(credentials_src, credentials_dst) || + strcmp(hostname_src, hostname_dst) || + port_src != port_dst) { + return AVERROR(EINVAL); + } + + if ((ret = libssh_connect(h_src, h_src->filename, path_src, sizeof(path_src))) < 0) + goto cleanup; + + if (sftp_rename(libssh->sftp, path_src, path_dst) < 0) { + ret = AVERROR(sftp_get_error(libssh->sftp)); + goto cleanup; + } + + ret = 0; + +cleanup: + libssh_close(h_src); + return ret; +} + #define OFFSET(x) offsetof(LIBSSHContext, x) #define D AV_OPT_FLAG_DECODING_PARAM #define E AV_OPT_FLAG_ENCODING_PARAM @@ -416,6 +496,8 @@ URLProtocol ff_libssh_protocol = { .url_write = libssh_write, .url_seek = libssh_seek, .url_close = libssh_close, + .url_delete = libssh_delete, + .url_move = libssh_move, .url_open_dir = libssh_open_dir, .url_read_dir = libssh_read_dir, .url_close_dir = libssh_close_dir, |