[FFmpeg-cvslog] lavf/libssh: implement move and delete callbacks

Mariusz Szczepańczyk git at videolan.org
Wed Jun 24 00:51:40 CEST 2015


ffmpeg | branch: master | Mariusz Szczepańczyk <mszczepanczyk at gmail.com> | Tue Jun 23 03:04:21 2015 +0200| [b23d2bac0d709b5642895d1acdf0cfef689d1ba1] | committer: Michael Niedermayer

lavf/libssh: implement move and delete callbacks

Reviewed-by: Lukasz Marek <lukasz.m.luki2 at gmail.com>
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b23d2bac0d709b5642895d1acdf0cfef689d1ba1
---

 libavformat/libssh.c |   82 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 82 insertions(+)

diff --git a/libavformat/libssh.c b/libavformat/libssh.c
index ee42924..3c056f8 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,



More information about the ffmpeg-cvslog mailing list