22 #include <libssh/sftp.h>
23 #include "libavutil/avstring.h"
24 #include "libavutil/opt.h"
55 static const int verbosity = SSH_LOG_NOLOG;
57 char proto[10], path[
MAX_URL_SIZE], hostname[1024], credencials[1024];
58 int port = 22, access,
ret;
60 const char *user = NULL, *
pass = NULL;
65 credencials,
sizeof(credencials),
66 hostname,
sizeof(hostname),
71 if (port <= 0 || port > 65535)
74 if (!(s->
session = ssh_new())) {
80 ssh_options_set(s->
session, SSH_OPTIONS_HOST, hostname);
81 ssh_options_set(s->
session, SSH_OPTIONS_PORT, &port);
82 ssh_options_set(s->
session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
84 ssh_options_set(s->
session, SSH_OPTIONS_TIMEOUT_USEC, &timeout);
86 ssh_options_set(s->
session, SSH_OPTIONS_USER, user);
88 if (ssh_connect(s->
session) != SSH_OK) {
94 if (pass && ssh_userauth_password(s->
session, NULL, pass) != SSH_AUTH_SUCCESS) {
106 if (sftp_init(s->
sftp) != SSH_OK) {
113 access = O_CREAT | O_RDWR;
116 }
else if (flags & AVIO_FLAG_WRITE) {
117 access = O_CREAT | O_WRONLY;
124 if (!(s->
file = sftp_open(s->
sftp, path, access, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH))) {
130 if (!(stat = sftp_fstat(s->
file))) {
135 sftp_attributes_free(stat);
162 newpos = sftp_tell64(s->
file);
171 if (sftp_seek64(s->
file, newpos)) {
184 if ((bytes_read = sftp_read(s->
file, buf, size)) < 0) {
196 if ((bytes_written = sftp_write(s->
file, buf, size)) < 0) {
200 return bytes_written;
203 #define OFFSET(x) offsetof(LIBSSHContext, x)
204 #define D AV_OPT_FLAG_DECODING_PARAM
205 #define E AV_OPT_FLAG_ENCODING_PARAM
207 {
"timeout",
"set timeout of socket I/O operations",
OFFSET(rw_timeout),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
D|
E },
227 .priv_data_class = &libssh_context_class,
void av_url_split(char *proto, int proto_size, char *authorization, int authorization_size, char *hostname, int hostname_size, int *port_ptr, char *path, int path_size, const char *url)
Split a URL string into components.
#define URL_PROTOCOL_FLAG_NETWORK
static int libssh_write(URLContext *h, const unsigned char *buf, int size)
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
const char * av_default_item_name(void *ctx)
Return the context name.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static av_cold int end(AVCodecContext *avctx)
const OptionDef options[]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_always_inline av_const double trunc(double x)
static int libssh_close(URLContext *h)
static const AVClass libssh_context_class
static int64_t libssh_seek(URLContext *h, int64_t pos, int whence)
Describe the class of an AVClass context structure.
static int libssh_read(URLContext *h, unsigned char *buf, int size)
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok()...
static int libssh_open(URLContext *h, const char *url, int flags)
URLProtocol ff_libssh_protocol
unbuffered private I/O API