Browse code

lavf/libssh: factorize create_sftp_session function

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

Lukasz Marek authored on 2014/01/22 08:00:21
Showing 1 changed files
... ...
@@ -108,6 +108,21 @@ static av_cold int libssh_authentication(LIBSSHContext *libssh, const char *user
108 108
     return 0;
109 109
 }
110 110
 
111
+static av_cold int libssh_create_sftp_session(LIBSSHContext *libssh)
112
+{
113
+    if (!(libssh->sftp = sftp_new(libssh->session))) {
114
+        av_log(libssh, AV_LOG_ERROR, "SFTP session creation failed: %s\n", ssh_get_error(libssh->session));
115
+        return AVERROR(ENOMEM);
116
+    }
117
+
118
+    if (sftp_init(libssh->sftp) != SSH_OK) {
119
+        av_log(libssh, AV_LOG_ERROR, "Error initializing sftp session: %s\n", ssh_get_error(libssh->session));
120
+        return AVERROR(EIO);
121
+    }
122
+
123
+    return 0;
124
+}
125
+
111 126
 static av_cold int libssh_open_file(LIBSSHContext *libssh, int flags, const char *file)
112 127
 {
113 128
     int access;
... ...
@@ -186,17 +201,8 @@ static int libssh_open(URLContext *h, const char *url, int flags)
186 186
     if ((ret = libssh_authentication(s, user, pass)) < 0)
187 187
         goto fail;
188 188
 
189
-    if (!(s->sftp = sftp_new(s->session))) {
190
-        av_log(h, AV_LOG_ERROR, "SFTP session creation failed: %s\n", ssh_get_error(s->session));
191
-        ret = AVERROR(ENOMEM);
189
+    if ((ret = libssh_create_sftp_session(s)) < 0)
192 190
         goto fail;
193
-    }
194
-
195
-    if (sftp_init(s->sftp) != SSH_OK) {
196
-        av_log(h, AV_LOG_ERROR, "Error initializing sftp session: %s\n", ssh_get_error(s->session));
197
-        ret = AVERROR(EIO);
198
-        goto fail;
199
-    }
200 191
 
201 192
     if ((ret = libssh_open_file(s, flags, path)) < 0)
202 193
         goto fail;