| 188 | } |
| 189 | |
| 190 | static av_cold int libssh_connect(URLContext *h, const char *url, char *path, size_t path_size) |
| 191 | { |
| 192 | LIBSSHContext *libssh = h->priv_data; |
| 193 | char proto[10], hostname[1024], credentials[1024]; |
| 194 | int port = 22, ret; |
| 195 | const char *user = NULL, *pass = NULL; |
| 196 | char *end = NULL; |
| 197 | |
| 198 | av_url_split(proto, sizeof(proto), |
| 199 | credentials, sizeof(credentials), |
| 200 | hostname, sizeof(hostname), |
| 201 | &port, |
| 202 | path, path_size, |
| 203 | url); |
| 204 | |
| 205 | if (!(*path)) |
| 206 | av_strlcpy(path, "/", path_size); |
| 207 | |
| 208 | // a port of 0 will use a port from ~/.ssh/config or the default value 22 |
| 209 | if (port < 0 || port > 65535) |
| 210 | port = 0; |
| 211 | |
| 212 | if ((ret = libssh_create_ssh_session(libssh, hostname, port)) < 0) |
| 213 | return ret; |
| 214 | |
| 215 | user = av_strtok(credentials, ":", &end); |
| 216 | pass = av_strtok(end, ":", &end); |
| 217 | |
| 218 | if ((ret = libssh_authentication(libssh, user, pass)) < 0) |
| 219 | return ret; |
| 220 | |
| 221 | if ((ret = libssh_create_sftp_session(libssh)) < 0) |
| 222 | return ret; |
| 223 | |
| 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | static av_cold int libssh_open(URLContext *h, const char *url, int flags) |
| 228 | { |
no test coverage detected