35#define CONTROL_BUFFER_SIZE 1024
36#define DIR_BUFFER_SIZE 4096
82#define OFFSET(x) offsetof(FTPContext, x)
83#define D AV_OPT_FLAG_DECODING_PARAM
84#define E AV_OPT_FLAG_ENCODING_PARAM
86 {
"timeout",
"set timeout of socket I/O operations",
OFFSET(rw_timeout),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
D|
E },
87 {
"ftp-write-seekable",
"control seekability of connection during encoding",
OFFSET(write_seekable),
AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1,
E },
88 {
"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 },
89 {
"ftp-user",
"user for FTP login. Overridden by whatever is in the URL.",
OFFSET(option_user),
AV_OPT_TYPE_STRING, { 0 }, 0, 0,
D|
E },
90 {
"ftp-password",
"password for FTP login. Overridden by whatever is in the URL.",
OFFSET(option_password),
AV_OPT_TYPE_STRING, { 0 }, 0, 0,
D|
E },
106 if (*
s < 0x20 || *
s == 0x7F || *
s == 0xFF)
116 if (
s->control_buf_ptr >=
s->control_buf_end) {
123 s->control_buf_ptr =
s->control_buffer;
124 s->control_buf_end =
s->control_buffer +
len;
127 return *
s->control_buf_ptr++;
142 if (q >
line && q[-1] ==
'\r')
147 if ((q -
line) < line_size - 1)
160 int err,
i, dash = 0, result = 0, code_found = 0, linesize;
162 AVBPrint line_buffer;
167 while (!code_found || dash) {
176 linesize = strlen(buf);
179 for (
i = 0;
i < 3; ++
i) {
180 if (buf[
i] <
'0' || buf[
i] >
'9') {
194 for (
i = 0; response_codes[
i]; ++
i) {
195 if (err == response_codes[
i]) {
206 if (!dash && buf[3] ==
'-')
208 else if (err == dash && buf[3] ==
' ')
220 const int response_codes[],
char **response)
229 if (!
s->conn_control)
238 if (response_codes) {
260 static const int user_codes[] = {331, 230, 0};
261 static const int pass_codes[] = {230, 0};
265 err =
snprintf(buf,
sizeof(buf),
"USER %s\r\n",
s->user);
266 if (err >=
sizeof(buf))
274 err =
snprintf(buf,
sizeof(buf),
"PASS %s\r\n",
s->password);
275 if (err >=
sizeof(buf))
292 static const char d =
'|';
293 static const char *
command =
"EPSV\r\n";
294 static const int epsv_codes[] = {229, 0};
299 for (
i = 0; res[
i]; ++
i) {
302 }
else if (res[
i] ==
')') {
311 if (strlen(start) < 5)
313 if (start[0] != d || start[1] != d || start[2] != d || end[-1] != d)
318 s->server_data_port = atoi(start);
319 ff_dlog(
s,
"Server data port: %d\n",
s->server_data_port);
326 s->server_data_port = -1;
334 static const char *
command =
"PASV\r\n";
335 static const int pasv_codes[] = {227, 0};
340 for (
i = 0; res[
i]; ++
i) {
343 }
else if (res[
i] ==
')') {
360 if (!start)
goto fail;
361 s->server_data_port = atoi(start) * 256;
363 if (!start)
goto fail;
364 s->server_data_port += atoi(start);
365 ff_dlog(
s,
"Server data port: %d\n",
s->server_data_port);
372 s->server_data_port = -1;
380 static const char *
command =
"PWD\r\n";
381 static const int pwd_codes[] = {257, 0};
386 for (
i = 0; res[
i]; ++
i) {
419 static const int size_codes[] = {213, 0};
426 s->filesize = strtoll(&res[4],
NULL, 10);
440 static const int retr_codes[] = {150, 125, 0};
448 if (resp_code != 125 && resp_code != 150)
459 static const int stor_codes[] = {150, 125, 0};
467 if (resp_code != 125 && resp_code != 150)
477 static const char *
command =
"TYPE I\r\n";
478 static const int type_codes[] = {200, 0};
489 static const int rest_codes[] = {350, 0};
500 static const int cwd_codes[] = {250, 550, 0};
515 static const char *
command =
"MLSD\r\n";
516 static const int mlsd_codes[] = {150, 500, 0};
520 s->listing_method =
MLSD;
526 static const char *
command =
"NLST\r\n";
527 static const int nlst_codes[] = {226, 425, 426, 451, 450, 550, 0};
531 s->listing_method =
NLST;
556 static const char *feat_command =
"FEAT\r\n";
557 static const char *enable_utf8_command =
"OPTS UTF8 ON\r\n";
558 static const int feat_codes[] = {211, 0};
559 static const int opts_codes[] = {200, 202, 451, 0};
568 if (ret == 200 || ret == 202)
581 static const int connect_codes[] = {220, 0};
583 if (!
s->conn_control) {
585 s->hostname,
s->server_control_port,
NULL);
586 if (
s->rw_timeout != -1) {
590 &
h->interrupt_callback, &
opts,
591 h->protocol_whitelist,
h->protocol_blacklist,
h);
605 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.");
640 if (
s->rw_timeout != -1) {
644 &
h->interrupt_callback, &
opts,
645 h->protocol_whitelist,
h->protocol_blacklist,
h);
660 static const char *
command =
"ABOR\r\n";
662 static const int abor_codes[] = {225, 226, 0};
699 const char *tok_user =
NULL, *tok_pass =
NULL;
700 char *newpath =
NULL;
711 credentials,
sizeof(credentials),
712 hostname,
sizeof(hostname),
713 &
s->server_control_port,
718 if (!
s->option_user) {
719 tok_user =
"anonymous";
720 tok_pass =
av_x_if_null(
s->anonymous_password,
"nopassword");
722 tok_user =
s->option_user;
723 tok_pass =
s->option_password;
728 char *pass = strchr(credentials,
':');
734 tok_pass =
s->option_password;
740 if (!
s->hostname || !
s->user || (tok_pass && !
s->password)) {
744 if (
s->server_control_port < 0 ||
s->server_control_port > 65535)
745 s->server_control_port = 21;
799 ff_dlog(
h,
"ftp protocol seek %"PRId64
" %d\n",
pos, whence);
808 new_pos =
s->position +
pos;
813 new_pos =
s->filesize +
pos;
827 if (new_pos !=
s->position) {
830 s->position = new_pos;
838 int read, err, retry_done = 0;
856 s->filesize =
FFMAX(
s->filesize,
s->position);
859 static const int retr_codes[] = {226, 250, 425, 426, 451, 0};
860 char *response =
NULL;
909 s->position += written;
910 s->filesize =
FFMAX(
s->filesize,
s->position);
939 ff_dlog(
h,
"ftp protocol get_file_handle\n");
951 ff_dlog(
h,
"ftp protocol shutdown\n");
973 if (!
s->dir_buffer) {
977 s->dir_buffer[0] = 0;
989 memset(&tv, 0,
sizeof(
struct tm));
991 return INT64_C(1000000) *
av_timegm(&tv);
1003 char *saveptr =
NULL, *p = mlsd;
1007 if (
fact[0] ==
' ') {
1044 switch (
s->listing_method) {
1058 char *start, *found;
1063 start =
s->dir_buffer +
s->dir_buffer_offset;
1064 while (!(found = strstr(start,
"\n"))) {
1067 s->dir_buffer_size -=
s->dir_buffer_offset;
1068 s->dir_buffer_offset = 0;
1069 if (
s->dir_buffer_size)
1070 memmove(
s->dir_buffer, start,
s->dir_buffer_size);
1078 s->dir_buffer_size += ret;
1079 s->dir_buffer[
s->dir_buffer_size] = 0;
1080 start =
s->dir_buffer;
1083 s->dir_buffer_offset += (found + 1 - start);
1085 if (found > start && found[-1] ==
'\r')
1091 (*next)->utf8 =
s->utf8;
1115 static const int del_codes[] = {250, 421, 450, 500, 501, 502, 530, 550, 0};
1116 static const int rmd_codes[] = {250, 421, 500, 501, 502, 530, 550, 0};
1153 static const int rnfr_codes[] = {350, 421, 450, 500, 501, 502, 503, 530, 0};
1154 static const int rnto_codes[] = {250, 421, 500, 501, 502, 503, 530, 532, 553, 0};
1211 .default_whitelist =
"tcp",
static double fact(double i)
static AVDictionary * opts
int ffurl_shutdown(URLContext *h, int flags)
Signal the URLContext that we are done reading or writing the stream.
int ffurl_open_whitelist(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char *blacklist, URLContext *parent)
Create an URLContext for accessing to the resource indicated by url, and open it.
int ffurl_closep(URLContext **hh)
Close the resource accessed by the URLContext h, and free the memory used by it.
void avio_free_directory_entry(AVIODirEntry **entry)
Free entry allocated by avio_read_dir().
int ffurl_get_file_handle(URLContext *h)
Return the file descriptor associated with this URL.
#define AVSEEK_SIZE
Passing this as the "whence" parameter to a seek function causes it to return the filesize without se...
#define AVIO_FLAG_WRITE
write-only
#define AVIO_FLAG_READ_WRITE
read-write pseudo flag
@ AVIO_ENTRY_SYMBOLIC_LINK
static uint32_t BS_FUNC read(BSCTX *bc, unsigned int n)
Return n bits from the buffer, n has to be in the 0-32 range.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define AV_BPRINT_SIZE_AUTOMATIC
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
static av_cold void cleanup(FlashSV2Context *s)
static int ftp_connect(URLContext *h, const char *url)
static const AVClass ftp_context_class
static int ftp_shutdown(URLContext *h, int flags)
static int ftp_read_dir(URLContext *h, AVIODirEntry **next)
static void ftp_close_data_connection(FTPContext *s)
static int ftp_store(FTPContext *s)
static int ftp_file_size(FTPContext *s)
static int ftp_set_dir(FTPContext *s)
static int ftp_close(URLContext *h)
static int ftp_connect_data_connection(URLContext *h)
static int ftp_getc(FTPContext *s)
static int ftp_get_file_handle(URLContext *h)
static int ftp_connect_control_connection(URLContext *h)
static int ftp_passive_mode_epsv(FTPContext *s)
static int ftp_passive_mode(FTPContext *s)
static int ftp_auth(FTPContext *s)
static int ftp_read(URLContext *h, unsigned char *buf, int size)
static int ftp_current_dir(FTPContext *s)
static int ftp_delete(URLContext *h)
static int ftp_status(FTPContext *s, char **line, const int response_codes[])
static int ftp_list(FTPContext *s)
static int ftp_list_nlst(FTPContext *s)
static int ftp_abort(URLContext *h)
static int ftp_type(FTPContext *s)
static int ftp_open(URLContext *h, const char *url, int flags)
static int ftp_get_line(FTPContext *s, char *line, int line_size)
static int ftp_write(URLContext *h, const unsigned char *buf, int size)
static int is_bad_string(const unsigned char *s)
static int ftp_parse_entry_nlst(char *line, AVIODirEntry *next)
#define CONTROL_BUFFER_SIZE
static int ftp_restart(FTPContext *s, int64_t pos)
static int ftp_parse_entry_mlsd(char *mlsd, AVIODirEntry *next)
static int ftp_list_mlsd(FTPContext *s)
static int64_t ftp_seek(URLContext *h, int64_t pos, int whence)
static int64_t ftp_parse_date(const char *date)
static int ftp_close_dir(URLContext *h)
static int ftp_move(URLContext *h_src, URLContext *h_dst)
static int ftp_parse_entry(URLContext *h, char *line, AVIODirEntry *next)
static int ftp_features(FTPContext *s)
static void ftp_close_both_connections(FTPContext *s)
static int ftp_retrieve(FTPContext *s)
static int ftp_has_feature(FTPContext *s, const char *feature_name)
static int ftp_open_dir(URLContext *h)
const URLProtocol ff_ftp_protocol
static int ftp_send_command(FTPContext *s, const char *command, const int response_codes[], char **response)
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
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.
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
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 AVERROR_EOF
End of file.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
char * av_stristr(const char *s1, const char *s2)
Locate the first case-independent occurrence in the string haystack of the string needle.
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().
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
char * av_append_path_component(const char *path, const char *component)
Append path component to the existing path.
#define LIBAVUTIL_VERSION_INT
common internal API header
Memory handling functions.
char * av_small_strptime(const char *p, const char *fmt, struct tm *dt)
Simplified version of strptime.
time_t av_timegm(struct tm *tm)
Convert the decomposed UTC time in tm to a time_t value.
Describe the class of an AVClass context structure.
Describes single entry of the directory.
int64_t user_id
User ID of owner, -1 if unknown.
int type
Type of the entry.
int64_t size
File size in bytes, -1 if unknown.
int64_t group_id
Group ID of owner, -1 if unknown.
int64_t modification_timestamp
Time of last modification in microseconds since unix epoch, -1 if unknown.
int64_t filemode
Unix file mode, -1 if unknown.
uint8_t control_buffer[CONTROL_BUFFER_SIZE]
Control connection buffer.
uint8_t * control_buf_ptr
int write_seekable
Control seekability, 0 = disable, 1 = enable.
const char * option_password
Password to be used if none given in the URL.
char * features
List of server's features represented as raw response.
int64_t filesize
Size of file on server, -1 on error.
FTPState state
State of data connection.
uint8_t * control_buf_end
char * password
Server user's password.
URLContext * conn_control
Control connection.
int rw_timeout
Network timeout.
int server_control_port
Control connection port, default is 21.
FTPListingMethod listing_method
Called listing method.
int64_t position
Current position, calculated.
int server_data_port
Data connection port opened by server, -1 on error.
const char * option_user
User to be used if none given in the URL.
char * hostname
Server address.
URLContext * conn_data
Data connection, NULL when not connected.
char * path
Path to resource on server.
const char * anonymous_password
Password to be used for anonymous user.
char * filename
specified URL
int ff_url_join(char *str, int size, const char *proto, const char *authorization, const char *hostname, int port, const char *fmt,...)
AVIODirEntry * ff_alloc_dir_entry(void)
Allocate directory entry with default values.
unbuffered private I/O API
static int ffurl_write(URLContext *h, const uint8_t *buf, int size)
Write size bytes from buf to the resource accessed by h.
static int ffurl_read(URLContext *h, uint8_t *buf, int size)
Read up to size bytes from the resource accessed by h, and store the read bytes in buf.
#define URL_PROTOCOL_FLAG_NETWORK
char * ff_urldecode(const char *url, int decode_plus_sign)
Decodes an URL from its percent-encoded form back into normal representation.
static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)