28 #define CONTROL_BUFFER_SIZE 1024
58 #define OFFSET(x) offsetof(FTPContext, x)
59 #define D AV_OPT_FLAG_DECODING_PARAM
60 #define E AV_OPT_FLAG_ENCODING_PARAM
62 {
"timeout",
"set timeout of socket I/O operations",
OFFSET(rw_timeout),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
D|
E },
63 {
"ftp-write-seekable",
"control seekability of connection during encoding",
OFFSET(write_seekable),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1,
E },
64 {
"ftp-anonymous-password",
"password for anonymous login. E-mail address should be used.",
OFFSET(anonymous_password),
AV_OPT_TYPE_STRING, { 0 }, 0, 0,
D|
E },
106 if (q > line && q[-1] ==
'\r')
111 if ((q - line) < line_size - 1)
124 int err, i, dash = 0, result = 0, code_found = 0, linesize;
126 AVBPrint line_buffer;
131 while (!code_found || dash) {
140 linesize = strlen(buf);
143 for (i = 0; i < 3; ++i) {
144 if (buf[i] <
'0' || buf[i] >
'9') {
158 for (i = 0; response_codes[i]; ++i) {
159 if (err == response_codes[i]) {
170 if (!dash && buf[3] ==
'-')
172 else if (err == dash && buf[3] ==
' ')
184 const int response_codes[],
char **response)
197 if (response_codes) {
198 return ftp_status(s, response, response_codes);
220 static const int user_codes[] = {331, 230, 0};
221 static const int pass_codes[] = {230, 0};
242 static const char d =
'|';
243 static const char *
command =
"EPSV\r\n";
244 static const int epsv_codes[] = {229, 0};
249 for (i = 0; res[i]; ++i) {
252 }
else if (res[i] ==
')') {
261 if (strlen(start) < 5)
263 if (start[0] != d || start[1] != d || start[2] != d || end[-1] != d)
284 static const char *
command =
"PASV\r\n";
285 static const int pasv_codes[] = {227, 0};
290 for (i = 0; res[i]; ++i) {
293 }
else if (res[i] ==
')') {
303 if (!
av_strtok(start,
",", &end))
goto fail;
304 if (!
av_strtok(end,
",", &end))
goto fail;
305 if (!
av_strtok(end,
",", &end))
goto fail;
306 if (!
av_strtok(end,
",", &end))
goto fail;
310 if (!start)
goto fail;
313 if (!start)
goto fail;
330 static const char *
command =
"PWD\r\n";
331 static const int pwd_codes[] = {257, 0};
336 for (i = 0; res[i]; ++i) {
350 if (end > res && end[-1] ==
'/') {
371 static const int size_codes[] = {213, 0};
373 snprintf(command,
sizeof(command),
"SIZE %s\r\n", s->
path);
389 static const int retr_codes[] = {150, 0};
391 snprintf(command,
sizeof(command),
"RETR %s\r\n", s->
path);
403 static const int stor_codes[] = {150, 0};
405 snprintf(command,
sizeof(command),
"STOR %s\r\n", s->
path);
416 static const char *
command =
"TYPE I\r\n";
417 static const int type_codes[] = {200, 0};
428 static const int rest_codes[] = {350, 0};
430 snprintf(command,
sizeof(command),
"REST %"PRId64
"\r\n", pos);
439 static const char *feat_command =
"FEAT\r\n";
440 static const char *enable_utf8_command =
"OPTS UTF8 ON\r\n";
441 static const int feat_codes[] = {211, 0};
442 static const int opts_codes[] = {200, 451};
460 static const int connect_codes[] = {220, 0};
483 av_log(h,
AV_LOG_WARNING,
"Pure-FTPd server is used as an output protocol. It is known issue this implementation may produce incorrect content and it cannot be fixed at this moment.");
537 static const char *
command =
"ABOR\r\n";
539 static const int abor_codes[] = {225, 226, 0};
576 const char *tok_user =
NULL, *tok_pass =
NULL;
582 av_dlog(h,
"ftp protocol open\n");
589 credencials,
sizeof(credencials),
590 hostname,
sizeof(hostname),
595 tok_user =
av_strtok(credencials,
":", &end);
598 tok_user =
"anonymous";
617 pathlen = strlen(s->
path) + strlen(path) + 1;
643 int64_t new_pos, fake_pos;
645 av_dlog(h,
"ftp protocol seek %"PRId64
" %d\n", pos, whence);
685 int read, err, retry_done = 0;
687 av_dlog(h,
"ftp protocol read %d bytes\n", size);
717 if (read <= 0 && s->position < s->filesize && !h->
is_streamed) {
723 if ((err =
ftp_seek(h, pos, SEEK_SET)) < 0) {
745 av_dlog(h,
"ftp protocol write %d bytes\n", size);
772 av_dlog(h,
"ftp protocol close\n");
787 av_dlog(h,
"ftp protocol get_file_handle\n");
799 av_dlog(h,
"ftp protocol shutdown\n");
817 .priv_data_class = &ftp_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.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
#define URL_PROTOCOL_FLAG_NETWORK
static int ftp_get_line(FTPContext *s, char *line, int line_size)
char * password
Server user's password.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
static int ftp_file_size(FTPContext *s)
int ffurl_write(URLContext *h, const unsigned char *buf, int size)
Write size bytes from buf to the resource accessed by h.
char * av_stristr(const char *s1, const char *s2)
Locate the first case-independent occurrence in the string haystack of the string needle...
int is_streamed
true if streamed (no seek possible), default = false
AVIOInterruptCB interrupt_callback
#define AVIO_FLAG_READ
read-only
#define AVIO_FLAG_WRITE
write-only
static int ftp_open(URLContext *h, const char *url, int flags)
uint8_t * control_buf_end
static int ftp_status(FTPContext *s, char **line, const int response_codes[])
int write_seekable
Control seekability, 0 = disable, 1 = enable.
static int ftp_retrieve(FTPContext *s)
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
int ffurl_shutdown(URLContext *h, int flags)
Signal the URLContext that we are done reading or writing the stream.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
URLContext * conn_control
Control connection.
static int ftp_connect_data_connection(URLContext *h)
static int ftp_shutdown(URLContext *h, int flags)
static av_cold int end(AVCodecContext *avctx)
int64_t filesize
Size of file on server, -1 on error.
int av_reallocp(void *ptr, size_t size)
Allocate or reallocate a block of memory.
static int ftp_connect_control_connection(URLContext *h)
uint8_t control_buffer[CONTROL_BUFFER_SIZE]
Control connection buffer.
static int ftp_current_dir(FTPContext *s)
uint8_t * control_buf_ptr
static int ftp_passive_mode(FTPContext *s)
int server_data_port
Data connection port opened by server, -1 on error.
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
static int ftp_getc(FTPContext *s)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * anonymous_password
Password to be used for anonymous user.
static int ftp_abort(URLContext *h)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
static int ftp_send_command(FTPContext *s, const char *command, const int response_codes[], char **response)
static void ftp_close_both_connections(FTPContext *s)
static int ftp_passive_mode_epsv(FTPContext *s)
int rw_timeout
Network timeout.
static int ftp_read(URLContext *h, unsigned char *buf, int size)
static int ftp_close(URLContext *h)
URLContext * conn_data
Data connection, NULL when not connected.
static int ftp_auth(FTPContext *s)
int64_t position
Current position, calculated.
static int ftp_restart(FTPContext *s, int64_t pos)
char * path
Path to resource on server.
int ffurl_get_file_handle(URLContext *h)
Return the file descriptor associated with this URL.
int ffurl_closep(URLContext **hh)
Close the resource accessed by the URLContext h, and free the memory used by it.
#define av_dlog(pctx,...)
av_dlog macros
int ff_url_join(char *str, int size, const char *proto, const char *authorization, const char *hostname, int port, const char *fmt,...)
static int64_t ftp_seek(URLContext *h, int64_t pos, int whence)
#define AV_LOG_INFO
Standard information.
#define AV_BPRINT_SIZE_AUTOMATIC
char * av_strdup(const char *s)
Duplicate the string s.
static int ftp_get_file_handle(URLContext *h)
static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
static const AVOption options[]
#define AVIO_FLAG_READ_WRITE
read-write pseudo flag
FTPState state
State of data connection.
Describe the class of an AVClass context structure.
static void ftp_close_data_connection(FTPContext *s)
static int ftp_features(FTPContext *s)
#define CONTROL_BUFFER_SIZE
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes...
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 ftp_write(URLContext *h, const unsigned char *buf, int size)
int ffurl_open(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create an URLContext for accessing to the resource indicated by url, and open it. ...
URLProtocol ff_ftp_protocol
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set that converts the value to a string and stores it...
#define AVSEEK_SIZE
Passing this as the "whence" parameter to a seek function causes it to return the filesize without se...
char * hostname
Server address.
static int ftp_store(FTPContext *s)
static int ftp_type(FTPContext *s)
int server_control_port
Control connection port, default is 21.
static const AVClass ftp_context_class
unbuffered private I/O API
int ffurl_read(URLContext *h, unsigned char *buf, int size)
Read up to size bytes from the resource accessed by h, and store the read bytes in buf...