33 #define CONTROL_BUFFER_SIZE 1024 34 #define DIR_BUFFER_SIZE 4096 80 #define OFFSET(x) offsetof(FTPContext, x) 81 #define D AV_OPT_FLAG_DECODING_PARAM 82 #define E AV_OPT_FLAG_ENCODING_PARAM 84 {
"timeout",
"set timeout of socket I/O operations",
OFFSET(rw_timeout),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
D|
E },
85 {
"ftp-write-seekable",
"control seekability of connection during encoding",
OFFSET(write_seekable),
AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1,
E },
86 {
"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 },
87 {
"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 },
88 {
"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 },
130 if (q > line && q[-1] ==
'\r')
135 if ((q - line) < line_size - 1)
148 int err,
i, dash = 0, result = 0, code_found = 0, linesize;
150 AVBPrint line_buffer;
155 while (!code_found || dash) {
164 linesize = strlen(buf);
167 for (i = 0; i < 3; ++
i) {
168 if (buf[i] <
'0' || buf[i] >
'9') {
182 for (i = 0; response_codes[
i]; ++
i) {
183 if (err == response_codes[i]) {
194 if (!dash && buf[3] ==
'-')
196 else if (err == dash && buf[3] ==
' ')
208 const int response_codes[],
char **response)
226 if (response_codes) {
227 return ftp_status(s, response, response_codes);
248 static const int user_codes[] = {331, 230, 0};
249 static const int pass_codes[] = {230, 0};
251 if (strpbrk(s->
user,
"\r\n"))
274 static const char d =
'|';
275 static const char *
command =
"EPSV\r\n";
276 static const int epsv_codes[] = {229, 0};
281 for (i = 0; res[
i]; ++
i) {
284 }
else if (res[i] ==
')') {
293 if (strlen(start) < 5)
295 if (start[0] != d || start[1] != d || start[2] != d || end[-1] != d)
316 static const char *
command =
"PASV\r\n";
317 static const int pasv_codes[] = {227, 0};
322 for (i = 0; res[
i]; ++
i) {
325 }
else if (res[i] ==
')') {
342 if (!start)
goto fail;
345 if (!start)
goto fail;
362 static const char *
command =
"PWD\r\n";
363 static const int pwd_codes[] = {257, 0};
368 for (i = 0; res[
i]; ++
i) {
400 static const int size_codes[] = {213, 0};
402 snprintf(command,
sizeof(command),
"SIZE %s\r\n", s->
path);
403 if (
ftp_send_command(s, command, size_codes, &res) == 213 && res && strlen(res) > 4) {
418 static const int retr_codes[] = {150, 125, 0};
421 snprintf(command,
sizeof(command),
"RETR %s\r\n", s->
path);
423 if (resp_code != 125 && resp_code != 150)
434 static const int stor_codes[] = {150, 125, 0};
437 snprintf(command,
sizeof(command),
"STOR %s\r\n", s->
path);
439 if (resp_code != 125 && resp_code != 150)
449 static const char *
command =
"TYPE I\r\n";
450 static const int type_codes[] = {200, 0};
461 static const int rest_codes[] = {350, 0};
463 snprintf(command,
sizeof(command),
"REST %"PRId64
"\r\n", pos);
472 static const int cwd_codes[] = {250, 550, 0};
475 snprintf(command,
sizeof(command),
"CWD %s\r\n", s->
path);
483 static const char *
command =
"MLSD\r\n";
484 static const int mlsd_codes[] = {150, 500, 0};
494 static const char *
command =
"NLST\r\n";
495 static const int nlst_codes[] = {226, 425, 426, 451, 450, 550, 0};
524 static const char *feat_command =
"FEAT\r\n";
525 static const char *enable_utf8_command =
"OPTS UTF8 ON\r\n";
526 static const int feat_codes[] = {211, 0};
527 static const int opts_codes[] = {200, 202, 451, 0};
536 if (ret == 200 || ret == 202)
549 static const int connect_codes[] = {220, 0};
573 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.");
628 static const char *
command =
"ABOR\r\n";
630 static const int abor_codes[] = {225, 226, 0};
667 const char *tok_user =
NULL, *tok_pass =
NULL;
668 char *newpath =
NULL;
679 credentials,
sizeof(credentials),
680 hostname,
sizeof(hostname),
687 tok_user =
"anonymous";
696 char *
pass = strchr(credentials,
':');
735 ff_dlog(h,
"ftp protocol open\n");
762 ff_dlog(h,
"ftp protocol seek %"PRId64
" %d\n", pos, whence);
801 int read, err, retry_done = 0;
803 ff_dlog(h,
"ftp protocol read %d bytes\n", size);
822 static const int retr_codes[] = {226, 250, 425, 426, 451, 0};
823 char *response =
NULL;
836 if (read <= 0 && !h->is_streamed) {
859 ff_dlog(h,
"ftp protocol write %d bytes\n", size);
886 ff_dlog(h,
"ftp protocol close\n");
902 ff_dlog(h,
"ftp protocol get_file_handle\n");
914 ff_dlog(h,
"ftp protocol shutdown\n");
952 memset(&tv, 0,
sizeof(
struct tm));
954 return INT64_C(1000000) *
av_timegm(&tv);
966 char *saveptr =
NULL, *p = mlsd;
968 while(fact =
av_strtok(p,
";", &saveptr)) {
970 if (fact[0] ==
' ') {
995 next->
size = strtoll(value,
NULL, 10);
1021 char *start, *found;
1027 while (!(found = strstr(start,
"\n"))) {
1048 if (found > start && found[-1] ==
'\r')
1054 (*next)->utf8 = s->
utf8;
1078 static const int del_codes[] = {250, 421, 450, 500, 501, 502, 530, 550, 0};
1079 static const int rmd_codes[] = {250, 421, 500, 501, 502, 530, 550, 0};
1085 snprintf(command,
sizeof(command),
"DELE %s\r\n", s->
path);
1091 snprintf(command,
sizeof(command),
"RMD %s\r\n", s->
path);
1106 static const int rnfr_codes[] = {350, 421, 450, 500, 501, 502, 503, 530, 0};
1107 static const int rnto_codes[] = {250, 421, 500, 501, 502, 503, 530, 532, 553, 0};
1113 snprintf(command,
sizeof(command),
"RNFR %s\r\n", s->
path);
1122 snprintf(command,
sizeof(command),
"RNTO %s\r\n", path);
1143 .priv_data_class = &ftp_context_class,
1150 .default_whitelist =
"tcp",
time_t av_timegm(struct tm *tm)
Convert the decomposed UTC time in tm to a time_t value.
const URLProtocol ff_ftp_protocol
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,...)
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. ...
#define URL_PROTOCOL_FLAG_NETWORK
static int ftp_get_line(FTPContext *s, char *line, int line_size)
char * password
Server user's password.
int64_t filemode
Unix file mode, -1 if unknown.
#define AV_LOG_WARNING
Something somehow does not look correct.
static int ftp_list(FTPContext *s)
static int ftp_move(URLContext *h_src, URLContext *h_dst)
#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
Describes single entry of the directory.
const char * av_default_item_name(void *ptr)
Return the context name.
static int ftp_connect(URLContext *h, const char *url)
#define AVIO_FLAG_WRITE
write-only
static int ftp_open(URLContext *h, const char *url, int flags)
uint8_t * control_buf_end
const char * option_password
Password to be used if none given in the URL.
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.
int64_t modification_timestamp
Time of last modification in microseconds since unix epoch, -1 if unknown.
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_read_dir(URLContext *h, AVIODirEntry **next)
static int ftp_connect_data_connection(URLContext *h)
static int ftp_set_dir(FTPContext *s)
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.
char * av_small_strptime(const char *p, const char *fmt, struct tm *dt)
Simplified version of strptime.
static int ftp_delete(URLContext *h)
static int ftp_connect_control_connection(URLContext *h)
#define AVERROR_EOF
End of file.
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.
FTPListingMethod listing_method
Called listing method.
char * ff_urldecode(const char *url, int decode_plus_sign)
Decodes an URL from its percent-encoded form back into normal representation.
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
#define i(width, name, range_min, range_max)
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.
const char * protocol_whitelist
static int ftp_abort(URLContext *h)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
const char * option_user
User to be used if none given in the URL.
#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)
void avio_free_directory_entry(AVIODirEntry **entry)
Free entry allocated by avio_read_dir().
int rw_timeout
Network timeout.
common internal API header
static int ftp_parse_entry_nlst(char *line, AVIODirEntry *next)
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.
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
static int ftp_auth(FTPContext *s)
int64_t position
Current position, calculated.
static int ftp_restart(FTPContext *s, int64_t pos)
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
char * features
List of server's features represented as raw response.
static int ftp_has_feature(FTPContext *s, const char *feature_name)
char * path
Path to resource on server.
int ffurl_get_file_handle(URLContext *h)
Return the file descriptor associated with this URL.
int64_t size
File size in bytes, -1 if unknown.
int ffurl_closep(URLContext **hh)
Close the resource accessed by the URLContext h, and free the memory used by it.
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 a string.
const char * protocol_blacklist
static int ftp_close_dir(URLContext *h)
int type
Type of the entry.
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.
int64_t group_id
Group ID of owner, -1 if unknown.
static void ftp_close_data_connection(FTPContext *s)
static int ftp_features(FTPContext *s)
static int ftp_parse_entry_mlsd(char *mlsd, AVIODirEntry *next)
#define CONTROL_BUFFER_SIZE
#define flags(name, subs,...)
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)
char * av_append_path_component(const char *path, const char *component)
Append path component to the existing path.
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...
AVIODirEntry * ff_alloc_dir_entry(void)
Allocate directory entry with default values.
char * filename
specified URL
#define AVSEEK_SIZE
ORing this as the "whence" parameter to a seek function causes it to return the filesize without seek...
char * hostname
Server address.
static int ftp_store(FTPContext *s)
static int ftp_type(FTPContext *s)
static int ftp_open_dir(URLContext *h)
int server_control_port
Control connection port, default is 21.
int64_t user_id
User ID of owner, -1 if unknown.
static int ftp_list_mlsd(FTPContext *s)
static const AVClass ftp_context_class
unbuffered private I/O API
static int64_t ftp_parse_date(const char *date)
static int ftp_parse_entry(URLContext *h, char *line, AVIODirEntry *next)
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...
static av_cold void cleanup(FlashSV2Context *s)
static int ftp_list_nlst(FTPContext *s)