[FFmpeg-cvslog] lavf/libssh: factorize open_file function

Lukasz Marek git at videolan.org
Wed Jan 22 01:35:26 CET 2014


ffmpeg | branch: master | Lukasz Marek <lukasz.m.luki at gmail.com> | Mon Jan 20 23:53:47 2014 +0100| [8d3f14e11b34810fc48b1459ce22ee072c765814] | committer: Lukasz Marek

lavf/libssh: factorize open_file function

Signed-off-by: Lukasz Marek <lukasz.m.luki at gmail.com>

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

 libavformat/libssh.c |   44 ++++++++++++++++++++++++++------------------
 1 file changed, 26 insertions(+), 18 deletions(-)

diff --git a/libavformat/libssh.c b/libavformat/libssh.c
index fabc024..a425c24 100644
--- a/libavformat/libssh.c
+++ b/libavformat/libssh.c
@@ -84,6 +84,30 @@ static av_cold int libssh_authentication(LIBSSHContext *libssh, const char *user
     return 0;
 }
 
+static av_cold int libssh_open_file(LIBSSHContext *libssh, int flags, const char *file)
+{
+    int access;
+
+    if ((flags & AVIO_FLAG_WRITE) && (flags & AVIO_FLAG_READ)) {
+        access = O_CREAT | O_RDWR;
+        if (libssh->trunc)
+            access |= O_TRUNC;
+    } else if (flags & AVIO_FLAG_WRITE) {
+        access = O_CREAT | O_WRONLY;
+        if (libssh->trunc)
+            access |= O_TRUNC;
+    } else
+        access = O_RDONLY;
+
+    /* 0666 = -rw-rw-rw- = read+write for everyone, minus umask */
+    if (!(libssh->file = sftp_open(libssh->sftp, file, access, 0666))) {
+        av_log(libssh, AV_LOG_ERROR, "Error opening sftp file: %s\n", ssh_get_error(libssh->session));
+        return AVERROR(EIO);
+    }
+
+    return 0;
+}
+
 static int libssh_close(URLContext *h)
 {
     LIBSSHContext *s = h->priv_data;
@@ -103,7 +127,7 @@ 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;
+    int port = 22, ret;
     long timeout = s->rw_timeout * 1000;
     const char *user = NULL, *pass = NULL;
     char *end = NULL;
@@ -152,24 +176,8 @@ static int libssh_open(URLContext *h, const char *url, int flags)
         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);
+    if ((ret = libssh_open_file(s, flags, path)) < 0)
         goto fail;
-    }
 
     if (!(stat = sftp_fstat(s->file))) {
         av_log(h, AV_LOG_WARNING, "Cannot stat remote file %s.\n", path);



More information about the ffmpeg-cvslog mailing list