FFmpeg  4.4.9
ftp.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Lukasz Marek <lukasz.m.luki@gmail.com>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <string.h>
22 
23 #include "libavutil/avstring.h"
24 #include "libavutil/internal.h"
25 #include "libavutil/parseutils.h"
26 #include "avformat.h"
27 #include "internal.h"
28 #include "url.h"
29 #include "urldecode.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/bprint.h"
32 
33 #define CONTROL_BUFFER_SIZE 1024
34 #define DIR_BUFFER_SIZE 4096
35 
36 typedef enum {
44 } FTPState;
45 
46 typedef enum {
49  MLSD
51 
52 typedef struct {
53  const AVClass *class;
54  URLContext *conn_control; /**< Control connection */
55  URLContext *conn_data; /**< Data connection, NULL when not connected */
56  uint8_t control_buffer[CONTROL_BUFFER_SIZE]; /**< Control connection buffer */
57  uint8_t *control_buf_ptr, *control_buf_end;
58  int server_data_port; /**< Data connection port opened by server, -1 on error. */
59  int server_control_port; /**< Control connection port, default is 21 */
60  char *hostname; /**< Server address. */
61  char *user; /**< Server user */
62  char *password; /**< Server user's password */
63  char *path; /**< Path to resource on server. */
64  int64_t filesize; /**< Size of file on server, -1 on error. */
65  int64_t position; /**< Current position, calculated. */
66  int rw_timeout; /**< Network timeout. */
67  const char *anonymous_password; /**< Password to be used for anonymous user. An email should be used. */
68  int write_seekable; /**< Control seekability, 0 = disable, 1 = enable. */
69  FTPState state; /**< State of data connection */
70  FTPListingMethod listing_method; /**< Called listing method */
71  char *features; /**< List of server's features represented as raw response */
72  char *dir_buffer;
75  int utf8;
76  const char *option_user; /**< User to be used if none given in the URL */
77  const char *option_password; /**< Password to be used if none given in the URL */
78 } FTPContext;
79 
80 #define OFFSET(x) offsetof(FTPContext, x)
81 #define D AV_OPT_FLAG_DECODING_PARAM
82 #define E AV_OPT_FLAG_ENCODING_PARAM
83 static const AVOption options[] = {
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 },
89  {NULL}
90 };
91 
92 static const AVClass ftp_context_class = {
93  .class_name = "ftp",
94  .item_name = av_default_item_name,
95  .option = options,
96  .version = LIBAVUTIL_VERSION_INT,
97 };
98 
99 static int ftp_close(URLContext *h);
100 
101 static int is_bad_string(const unsigned char *s)
102 {
103  while(*s) {
104  if (*s < 0x20 || *s == 0x7F || *s == 0xFF)
105  return 1;
106  s++;
107  }
108  return 0;
109 }
110 
111 static int ftp_getc(FTPContext *s)
112 {
113  int len;
114  if (s->control_buf_ptr >= s->control_buf_end) {
115  len = ffurl_read(s->conn_control, s->control_buffer, CONTROL_BUFFER_SIZE);
116  if (len < 0) {
117  return len;
118  } else if (!len) {
119  return -1;
120  } else {
121  s->control_buf_ptr = s->control_buffer;
122  s->control_buf_end = s->control_buffer + len;
123  }
124  }
125  return *s->control_buf_ptr++;
126 }
127 
128 static int ftp_get_line(FTPContext *s, char *line, int line_size)
129 {
130  int ch;
131  char *q = line;
132 
133  for (;;) {
134  ch = ftp_getc(s);
135  if (ch < 0) {
136  return ch;
137  }
138  if (ch == '\n') {
139  /* process line */
140  if (q > line && q[-1] == '\r')
141  q--;
142  *q = '\0';
143  return 0;
144  } else {
145  if ((q - line) < line_size - 1)
146  *q++ = ch;
147  }
148  }
149 }
150 
151 /*
152  * This routine returns ftp server response code.
153  * Server may send more than one response for a certain command.
154  * First expected code is returned.
155  */
156 static int ftp_status(FTPContext *s, char **line, const int response_codes[])
157 {
158  int err, i, dash = 0, result = 0, code_found = 0, linesize;
159  char buf[CONTROL_BUFFER_SIZE];
160  AVBPrint line_buffer;
161 
162  if (line)
163  av_bprint_init(&line_buffer, 0, AV_BPRINT_SIZE_AUTOMATIC);
164 
165  while (!code_found || dash) {
166  if ((err = ftp_get_line(s, buf, sizeof(buf))) < 0) {
167  if (line)
168  av_bprint_finalize(&line_buffer, NULL);
169  return err;
170  }
171 
172  av_log(s, AV_LOG_DEBUG, "%s\n", buf);
173 
174  linesize = strlen(buf);
175  err = 0;
176  if (linesize >= 3) {
177  for (i = 0; i < 3; ++i) {
178  if (buf[i] < '0' || buf[i] > '9') {
179  err = 0;
180  break;
181  }
182  err *= 10;
183  err += buf[i] - '0';
184  }
185  }
186 
187  if (!code_found) {
188  if (err >= 500) {
189  code_found = 1;
190  result = err;
191  } else
192  for (i = 0; response_codes[i]; ++i) {
193  if (err == response_codes[i]) {
194  code_found = 1;
195  result = err;
196  break;
197  }
198  }
199  }
200  if (code_found) {
201  if (line)
202  av_bprintf(&line_buffer, "%s\r\n", buf);
203  if (linesize >= 4) {
204  if (!dash && buf[3] == '-')
205  dash = err;
206  else if (err == dash && buf[3] == ' ')
207  dash = 0;
208  }
209  }
210  }
211 
212  if (line)
213  av_bprint_finalize(&line_buffer, line);
214  return result;
215 }
216 
217 static int ftp_send_command(FTPContext *s, const char *command,
218  const int response_codes[], char **response)
219 {
220  int err;
221 
222  ff_dlog(s, "%s", command);
223 
224  if (response)
225  *response = NULL;
226 
227  if (!s->conn_control)
228  return AVERROR(EIO);
229 
230  if ((err = ffurl_write(s->conn_control, command, strlen(command))) < 0)
231  return err;
232  if (!err)
233  return -1;
234 
235  /* return status */
236  if (response_codes) {
237  return ftp_status(s, response, response_codes);
238  }
239  return 0;
240 }
241 
243 {
244  ffurl_closep(&s->conn_data);
245  s->state = DISCONNECTED;
246 }
247 
249 {
250  ffurl_closep(&s->conn_control);
252 }
253 
254 static int ftp_auth(FTPContext *s)
255 {
256  char buf[CONTROL_BUFFER_SIZE];
257  int err;
258  static const int user_codes[] = {331, 230, 0};
259  static const int pass_codes[] = {230, 0};
260 
261  if (is_bad_string(s->user))
262  return AVERROR(EINVAL);
263  err = snprintf(buf, sizeof(buf), "USER %s\r\n", s->user);
264  if (err >= sizeof(buf))
265  return AVERROR(ENOSYS);
266 
267  err = ftp_send_command(s, buf, user_codes, NULL);
268  if (err == 331) {
269  if (s->password) {
270  if (is_bad_string(s->password))
271  return AVERROR(EINVAL);
272  err = snprintf(buf, sizeof(buf), "PASS %s\r\n", s->password);
273  if (err >= sizeof(buf))
274  return AVERROR(ENOSYS);
275 
276  err = ftp_send_command(s, buf, pass_codes, NULL);
277  } else
278  return AVERROR(EACCES);
279  }
280  if (err != 230)
281  return AVERROR(EACCES);
282 
283  return 0;
284 }
285 
287 {
288  char *res = NULL, *start = NULL, *end = NULL;
289  int i;
290  static const char d = '|';
291  static const char *command = "EPSV\r\n";
292  static const int epsv_codes[] = {229, 0};
293 
294  if (ftp_send_command(s, command, epsv_codes, &res) != 229 || !res)
295  goto fail;
296 
297  for (i = 0; res[i]; ++i) {
298  if (res[i] == '(') {
299  start = res + i + 1;
300  } else if (res[i] == ')') {
301  end = res + i;
302  break;
303  }
304  }
305  if (!start || !end)
306  goto fail;
307 
308  *end = '\0';
309  if (strlen(start) < 5)
310  goto fail;
311  if (start[0] != d || start[1] != d || start[2] != d || end[-1] != d)
312  goto fail;
313  start += 3;
314  end[-1] = '\0';
315 
316  s->server_data_port = atoi(start);
317  ff_dlog(s, "Server data port: %d\n", s->server_data_port);
318 
319  av_free(res);
320  return 0;
321 
322  fail:
323  av_free(res);
324  s->server_data_port = -1;
325  return AVERROR(ENOSYS);
326 }
327 
329 {
330  char *res = NULL, *start = NULL, *end = NULL;
331  int i;
332  static const char *command = "PASV\r\n";
333  static const int pasv_codes[] = {227, 0};
334 
335  if (ftp_send_command(s, command, pasv_codes, &res) != 227 || !res)
336  goto fail;
337 
338  for (i = 0; res[i]; ++i) {
339  if (res[i] == '(') {
340  start = res + i + 1;
341  } else if (res[i] == ')') {
342  end = res + i;
343  break;
344  }
345  }
346  if (!start || !end)
347  goto fail;
348 
349  *end = '\0';
350  /* skip ip */
351  if (!av_strtok(start, ",", &end)) goto fail;
352  if (!av_strtok(NULL, ",", &end)) goto fail;
353  if (!av_strtok(NULL, ",", &end)) goto fail;
354  if (!av_strtok(NULL, ",", &end)) goto fail;
355 
356  /* parse port number */
357  start = av_strtok(NULL, ",", &end);
358  if (!start) goto fail;
359  s->server_data_port = atoi(start) * 256;
360  start = av_strtok(NULL, ",", &end);
361  if (!start) goto fail;
362  s->server_data_port += atoi(start);
363  ff_dlog(s, "Server data port: %d\n", s->server_data_port);
364 
365  av_free(res);
366  return 0;
367 
368  fail:
369  av_free(res);
370  s->server_data_port = -1;
371  return AVERROR(EIO);
372 }
373 
375 {
376  char *res = NULL, *start = NULL, *end = NULL;
377  int i;
378  static const char *command = "PWD\r\n";
379  static const int pwd_codes[] = {257, 0};
380 
381  if (ftp_send_command(s, command, pwd_codes, &res) != 257 || !res)
382  goto fail;
383 
384  for (i = 0; res[i]; ++i) {
385  if (res[i] == '"') {
386  if (!start) {
387  start = res + i + 1;
388  continue;
389  }
390  end = res + i;
391  break;
392  }
393  }
394 
395  if (!end)
396  goto fail;
397 
398  *end = '\0';
399  s->path = av_strdup(start);
400 
401  av_free(res);
402 
403  if (!s->path)
404  return AVERROR(ENOMEM);
405  return 0;
406 
407  fail:
408  av_free(res);
409  return AVERROR(EIO);
410 }
411 
413 {
415  char *res = NULL;
416  int ret;
417  static const int size_codes[] = {213, 0};
418 
419  ret = snprintf(command, sizeof(command), "SIZE %s\r\n", s->path);
420  if (ret >= sizeof(command))
421  return AVERROR(ENOSYS);
422 
423  if (ftp_send_command(s, command, size_codes, &res) == 213 && res && strlen(res) > 4) {
424  s->filesize = strtoll(&res[4], NULL, 10);
425  } else {
426  s->filesize = -1;
427  av_free(res);
428  return AVERROR(EIO);
429  }
430 
431  av_free(res);
432  return 0;
433 }
434 
436 {
438  static const int retr_codes[] = {150, 125, 0};
439  int resp_code, ret;
440 
441  ret = snprintf(command, sizeof(command), "RETR %s\r\n", s->path);
442  if (ret >= sizeof(command))
443  return AVERROR(ENOSYS);
444 
445  resp_code = ftp_send_command(s, command, retr_codes, NULL);
446  if (resp_code != 125 && resp_code != 150)
447  return AVERROR(EIO);
448 
449  s->state = DOWNLOADING;
450 
451  return 0;
452 }
453 
454 static int ftp_store(FTPContext *s)
455 {
457  static const int stor_codes[] = {150, 125, 0};
458  int resp_code, ret;
459 
460  ret = snprintf(command, sizeof(command), "STOR %s\r\n", s->path);
461  if (ret >= sizeof(command))
462  return AVERROR(ENOSYS);
463 
464  resp_code = ftp_send_command(s, command, stor_codes, NULL);
465  if (resp_code != 125 && resp_code != 150)
466  return AVERROR(EIO);
467 
468  s->state = UPLOADING;
469 
470  return 0;
471 }
472 
473 static int ftp_type(FTPContext *s)
474 {
475  static const char *command = "TYPE I\r\n";
476  static const int type_codes[] = {200, 0};
477 
478  if (ftp_send_command(s, command, type_codes, NULL) != 200)
479  return AVERROR(EIO);
480 
481  return 0;
482 }
483 
485 {
487  static const int rest_codes[] = {350, 0};
488 
489  snprintf(command, sizeof(command), "REST %"PRId64"\r\n", pos);
490  if (ftp_send_command(s, command, rest_codes, NULL) != 350)
491  return AVERROR(EIO);
492 
493  return 0;
494 }
495 
497 {
498  static const int cwd_codes[] = {250, 550, 0}; /* 550 is incorrect code */
499  char command[MAX_URL_SIZE];
500  int ret;
501 
502  ret = snprintf(command, sizeof(command), "CWD %s\r\n", s->path);
503  if (ret >= sizeof(command))
504  return AVERROR(ENOSYS);
505 
506  if (ftp_send_command(s, command, cwd_codes, NULL) != 250)
507  return AVERROR(EIO);
508  return 0;
509 }
510 
512 {
513  static const char *command = "MLSD\r\n";
514  static const int mlsd_codes[] = {150, 125, 500, 0}; /* 500 is incorrect code */
515  int resp_code = ftp_send_command(s, command, mlsd_codes, NULL);
516 
517  if (resp_code != 150 && resp_code != 125)
518  return AVERROR(ENOSYS);
519  s->listing_method = MLSD;
520  return 0;
521 }
522 
524 {
525  static const char *command = "NLST\r\n";
526  static const int nlst_codes[] = {226, 425, 426, 451, 450, 550, 0};
527 
528  if (ftp_send_command(s, command, nlst_codes, NULL) != 226)
529  return AVERROR(ENOSYS);
530  s->listing_method = NLST;
531  return 0;
532 }
533 
534 static int ftp_list(FTPContext *s)
535 {
536  int ret;
537  s->state = LISTING_DIR;
538 
539  if ((ret = ftp_list_mlsd(s)) < 0)
540  ret = ftp_list_nlst(s);
541 
542  return ret;
543 }
544 
545 static int ftp_has_feature(FTPContext *s, const char *feature_name)
546 {
547  if (!s->features)
548  return 0;
549 
550  return av_stristr(s->features, feature_name) != NULL;
551 }
552 
554 {
555  static const char *feat_command = "FEAT\r\n";
556  static const char *enable_utf8_command = "OPTS UTF8 ON\r\n";
557  static const int feat_codes[] = {211, 0};
558  static const int opts_codes[] = {200, 202, 451, 0};
559 
560  av_freep(&s->features);
561  if (ftp_send_command(s, feat_command, feat_codes, &s->features) != 211) {
562  av_freep(&s->features);
563  }
564 
565  if (ftp_has_feature(s, "UTF8")) {
566  int ret = ftp_send_command(s, enable_utf8_command, opts_codes, NULL);
567  if (ret == 200 || ret == 202)
568  s->utf8 = 1;
569  }
570 
571  return 0;
572 }
573 
575 {
576  char buf[CONTROL_BUFFER_SIZE], *response = NULL;
577  int err;
579  FTPContext *s = h->priv_data;
580  static const int connect_codes[] = {220, 0};
581 
582  if (!s->conn_control) {
583  ff_url_join(buf, sizeof(buf), "tcp", NULL,
584  s->hostname, s->server_control_port, NULL);
585  if (s->rw_timeout != -1) {
586  av_dict_set_int(&opts, "timeout", s->rw_timeout, 0);
587  } /* if option is not given, don't pass it and let tcp use its own default */
588  err = ffurl_open_whitelist(&s->conn_control, buf, AVIO_FLAG_READ_WRITE,
589  &h->interrupt_callback, &opts,
590  h->protocol_whitelist, h->protocol_blacklist, h);
591  av_dict_free(&opts);
592  if (err < 0) {
593  av_log(h, AV_LOG_ERROR, "Cannot open control connection\n");
594  return err;
595  }
596 
597  /* check if server is ready */
598  if (ftp_status(s, ((h->flags & AVIO_FLAG_WRITE) ? &response : NULL), connect_codes) != 220) {
599  av_log(h, AV_LOG_ERROR, "FTP server not ready for new users\n");
600  return AVERROR(EACCES);
601  }
602 
603  if ((h->flags & AVIO_FLAG_WRITE) && av_stristr(response, "pure-ftpd")) {
604  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.");
605  }
606  av_free(response);
607 
608  if ((err = ftp_auth(s)) < 0) {
609  av_log(h, AV_LOG_ERROR, "FTP authentication failed\n");
610  return err;
611  }
612 
613  if ((err = ftp_type(s)) < 0) {
614  av_log(h, AV_LOG_ERROR, "Set content type failed\n");
615  return err;
616  }
617 
618  ftp_features(s);
619  }
620  return 0;
621 }
622 
624 {
625  int err;
626  char buf[CONTROL_BUFFER_SIZE];
628  FTPContext *s = h->priv_data;
629 
630  if (!s->conn_data) {
631  /* Enter passive mode */
632  if (ftp_passive_mode_epsv(s) < 0) {
633  /* Use PASV as fallback */
634  if ((err = ftp_passive_mode(s)) < 0)
635  return err;
636  }
637  /* Open data connection */
638  ff_url_join(buf, sizeof(buf), "tcp", NULL, s->hostname, s->server_data_port, NULL);
639  if (s->rw_timeout != -1) {
640  av_dict_set_int(&opts, "timeout", s->rw_timeout, 0);
641  } /* if option is not given, don't pass it and let tcp use its own default */
642  err = ffurl_open_whitelist(&s->conn_data, buf, h->flags,
643  &h->interrupt_callback, &opts,
644  h->protocol_whitelist, h->protocol_blacklist, h);
645  av_dict_free(&opts);
646  if (err < 0)
647  return err;
648 
649  if (s->position)
650  if ((err = ftp_restart(s, s->position)) < 0)
651  return err;
652  }
653  s->state = READY;
654  return 0;
655 }
656 
657 static int ftp_abort(URLContext *h)
658 {
659  static const char *command = "ABOR\r\n";
660  int err;
661  static const int abor_codes[] = {225, 226, 0};
662  FTPContext *s = h->priv_data;
663 
664  /* According to RCF 959:
665  "ABOR command tells the server to abort the previous FTP
666  service command and any associated transfer of data."
667 
668  There are FTP server implementations that don't response
669  to any commands during data transfer in passive mode (including ABOR).
670 
671  This implementation closes data connection by force.
672  */
673 
674  if (ftp_send_command(s, command, NULL, NULL) < 0) {
676  if ((err = ftp_connect_control_connection(h)) < 0) {
677  av_log(h, AV_LOG_ERROR, "Reconnect failed.\n");
678  return err;
679  }
680  } else {
682  if (ftp_status(s, NULL, abor_codes) < 225) {
683  /* wu-ftpd also closes control connection after data connection closing */
684  ffurl_closep(&s->conn_control);
685  if ((err = ftp_connect_control_connection(h)) < 0) {
686  av_log(h, AV_LOG_ERROR, "Reconnect failed.\n");
687  return err;
688  }
689  }
690  }
691 
692  return 0;
693 }
694 
695 static int ftp_connect(URLContext *h, const char *url)
696 {
697  char proto[10], path[MAX_URL_SIZE], credentials[MAX_URL_SIZE], hostname[MAX_URL_SIZE];
698  const char *tok_user = NULL, *tok_pass = NULL;
699  char *newpath = NULL;
700  int err;
701  FTPContext *s = h->priv_data;
702 
703  s->state = DISCONNECTED;
704  s->listing_method = UNKNOWN_METHOD;
705  s->filesize = -1;
706  s->position = 0;
707  s->features = NULL;
708 
709  av_url_split(proto, sizeof(proto),
710  credentials, sizeof(credentials),
711  hostname, sizeof(hostname),
712  &s->server_control_port,
713  path, sizeof(path),
714  url);
715 
716  if (!*credentials) {
717  if (!s->option_user) {
718  tok_user = "anonymous";
719  tok_pass = av_x_if_null(s->anonymous_password, "nopassword");
720  } else {
721  tok_user = s->option_user;
722  tok_pass = s->option_password;
723  }
724  s->user = av_strdup(tok_user);
725  s->password = av_strdup(tok_pass);
726  } else {
727  char *pass = strchr(credentials, ':');
728  if (pass) {
729  *pass++ = '\0';
730  tok_pass = pass;
731  s->password = ff_urldecode(pass, 0);
732  } else {
733  tok_pass = s->option_password;
734  s->password = av_strdup(tok_pass);
735  }
736  s->user = ff_urldecode(credentials, 0);
737  }
738  s->hostname = av_strdup(hostname);
739  if (!s->hostname || !s->user || (tok_pass && !s->password)) {
740  return AVERROR(ENOMEM);
741  }
742 
743  if (s->server_control_port < 0 || s->server_control_port > 65535)
744  s->server_control_port = 21;
745 
746  if ((err = ftp_connect_control_connection(h)) < 0)
747  return err;
748 
749  if ((err = ftp_current_dir(s)) < 0)
750  return err;
751 
752  newpath = av_append_path_component(s->path, path);
753  if (!newpath)
754  return AVERROR(ENOMEM);
755  av_free(s->path);
756  s->path = newpath;
757 
758  if (is_bad_string(s->path)) {
759  av_log(h, AV_LOG_ERROR, "Path contains non-printable characters\n");
760  return AVERROR(EINVAL);
761  }
762 
763  return 0;
764 }
765 
766 static int ftp_open(URLContext *h, const char *url, int flags)
767 {
768  FTPContext *s = h->priv_data;
769  int err;
770 
771  ff_dlog(h, "ftp protocol open\n");
772 
773  if ((err = ftp_connect(h, url)) < 0)
774  goto fail;
775 
776  if (ftp_restart(s, 0) < 0) {
777  h->is_streamed = 1;
778  } else {
779  ftp_file_size(s);
780  if (s->write_seekable != 1 && flags & AVIO_FLAG_WRITE)
781  h->is_streamed = 1;
782  }
783 
784  return 0;
785 
786  fail:
787  av_log(h, AV_LOG_ERROR, "FTP open failed\n");
788  ftp_close(h);
789  return err;
790 }
791 
792 static int64_t ftp_seek(URLContext *h, int64_t pos, int whence)
793 {
794  FTPContext *s = h->priv_data;
795  int err;
796  int64_t new_pos;
797 
798  ff_dlog(h, "ftp protocol seek %"PRId64" %d\n", pos, whence);
799 
800  switch(whence) {
801  case AVSEEK_SIZE:
802  return s->filesize;
803  case SEEK_SET:
804  new_pos = pos;
805  break;
806  case SEEK_CUR:
807  new_pos = s->position + pos;
808  break;
809  case SEEK_END:
810  if (s->filesize < 0)
811  return AVERROR(EIO);
812  new_pos = s->filesize + pos;
813  break;
814  default:
815  return AVERROR(EINVAL);
816  }
817 
818  if (h->is_streamed)
819  return AVERROR(EIO);
820 
821  if (new_pos < 0) {
822  av_log(h, AV_LOG_ERROR, "Seeking to nagative position.\n");
823  return AVERROR(EINVAL);
824  }
825 
826  if (new_pos != s->position) {
827  if ((err = ftp_abort(h)) < 0)
828  return err;
829  s->position = new_pos;
830  }
831  return new_pos;
832 }
833 
834 static int ftp_read(URLContext *h, unsigned char *buf, int size)
835 {
836  FTPContext *s = h->priv_data;
837  int read, err, retry_done = 0;
838 
839  ff_dlog(h, "ftp protocol read %d bytes\n", size);
840  retry:
841  if (s->state == ENDOFFILE)
842  return AVERROR_EOF;
843  if (s->state == DISCONNECTED) {
844  if ((err = ftp_connect_data_connection(h)) < 0)
845  return err;
846  }
847  if (s->state == READY) {
848  if ((err = ftp_retrieve(s)) < 0)
849  return err;
850  }
851  if (s->conn_data && s->state == DOWNLOADING) {
852  read = ffurl_read(s->conn_data, buf, size);
853  if (read >= 0) {
854  s->position += read;
855  s->filesize = FFMAX(s->filesize, s->position);
856  }
857  if (read == AVERROR_EOF) {
858  static const int retr_codes[] = {226, 250, 425, 426, 451, 0};
859  char *response = NULL;
860  err = ftp_status(s, &response, retr_codes);
861  if (err == 226) {
863  av_freep(&response);
864  s->state = ENDOFFILE;
865  return AVERROR_EOF;
866  }
867  /* 250 is not allowed, any other status means some kind of error */
868  av_log(h, AV_LOG_ERROR, "FTP transfer failed: %s\n", response ? response : (err < 0 ? av_err2str(err) : "?"));
869  av_freep(&response);
870  read = AVERROR(EIO);
871  }
872  if (read <= 0 && !h->is_streamed) {
873  /* Server closed connection. Probably due to inactivity */
874  av_log(h, AV_LOG_INFO, "Reconnect to FTP server.\n");
875  if ((err = ftp_abort(h)) < 0)
876  return err;
877  if (!retry_done) {
878  retry_done = 1;
879  goto retry;
880  }
881  }
882  return read;
883  }
884 
885  av_log(h, AV_LOG_DEBUG, "FTP read failed\n");
886  return AVERROR(EIO);
887 }
888 
889 static int ftp_write(URLContext *h, const unsigned char *buf, int size)
890 {
891  int err;
892  FTPContext *s = h->priv_data;
893  int written;
894 
895  ff_dlog(h, "ftp protocol write %d bytes\n", size);
896 
897  if (s->state == DISCONNECTED) {
898  if ((err = ftp_connect_data_connection(h)) < 0)
899  return err;
900  }
901  if (s->state == READY) {
902  if ((err = ftp_store(s)) < 0)
903  return err;
904  }
905  if (s->conn_data && s->state == UPLOADING) {
906  written = ffurl_write(s->conn_data, buf, size);
907  if (written > 0) {
908  s->position += written;
909  s->filesize = FFMAX(s->filesize, s->position);
910  }
911  return written;
912  }
913 
914  av_log(h, AV_LOG_ERROR, "FTP write failed\n");
915  return AVERROR(EIO);
916 }
917 
918 static int ftp_close(URLContext *h)
919 {
920  FTPContext *s = h->priv_data;
921 
922  ff_dlog(h, "ftp protocol close\n");
923 
925  av_freep(&s->user);
926  av_freep(&s->password);
927  av_freep(&s->hostname);
928  av_freep(&s->path);
929  av_freep(&s->features);
930 
931  return 0;
932 }
933 
935 {
936  FTPContext *s = h->priv_data;
937 
938  ff_dlog(h, "ftp protocol get_file_handle\n");
939 
940  if (s->conn_data)
941  return ffurl_get_file_handle(s->conn_data);
942 
943  return AVERROR(EIO);
944 }
945 
946 static int ftp_shutdown(URLContext *h, int flags)
947 {
948  FTPContext *s = h->priv_data;
949 
950  ff_dlog(h, "ftp protocol shutdown\n");
951 
952  if (s->conn_data)
953  return ffurl_shutdown(s->conn_data, flags);
954 
955  return AVERROR(EIO);
956 }
957 
959 {
960  FTPContext *s = h->priv_data;
961  int ret;
962 
963  if ((ret = ftp_connect(h, h->filename)) < 0)
964  goto fail;
965  if ((ret = ftp_set_dir(s)) < 0)
966  goto fail;
967  if ((ret = ftp_connect_data_connection(h)) < 0)
968  goto fail;
969  if ((ret = ftp_list(s)) < 0)
970  goto fail;
971  s->dir_buffer = av_malloc(DIR_BUFFER_SIZE);
972  if (!s->dir_buffer) {
973  ret = AVERROR(ENOMEM);
974  goto fail;
975  }
976  s->dir_buffer[0] = 0;
977  if (s->conn_data && s->state == LISTING_DIR)
978  return 0;
979  fail:
980  ffurl_closep(&s->conn_control);
981  ffurl_closep(&s->conn_data);
982  return ret;
983 }
984 
985 static int64_t ftp_parse_date(const char *date)
986 {
987  struct tm tv;
988  memset(&tv, 0, sizeof(struct tm));
989  av_small_strptime(date, "%Y%m%d%H%M%S", &tv);
990  return INT64_C(1000000) * av_timegm(&tv);
991 }
992 
993 static int ftp_parse_entry_nlst(char *line, AVIODirEntry *next)
994 {
995  next->name = av_strdup(line);
996  return next->name ? 0 : AVERROR(ENOMEM);
997 }
998 
999 static int ftp_parse_entry_mlsd(char *mlsd, AVIODirEntry *next)
1000 {
1001  char *fact, *value;
1002  char *saveptr = NULL, *p = mlsd;
1003  ff_dlog(NULL, "%s\n", mlsd);
1004  while(fact = av_strtok(p, ";", &saveptr)) {
1005  p = NULL;
1006  if (fact[0] == ' ') {
1007  if (!(next->name = av_strdup(&fact[1])))
1008  return AVERROR(ENOMEM);
1009  continue;
1010  }
1011  fact = av_strtok(fact, "=", &value);
1012  if (!fact)
1013  continue;
1014  if (!av_strcasecmp(fact, "type")) {
1015  if (!av_strcasecmp(value, "cdir") || !av_strcasecmp(value, "pdir"))
1016  return 1;
1017  if (!av_strcasecmp(value, "dir"))
1018  next->type = AVIO_ENTRY_DIRECTORY;
1019  else if (!av_strcasecmp(value, "file"))
1020  next->type = AVIO_ENTRY_FILE;
1021  else if (!av_strcasecmp(value, "OS.unix=slink:"))
1023  } else if (!av_strcasecmp(fact, "modify")) {
1025  } else if (!av_strcasecmp(fact, "UNIX.mode")) {
1026  next->filemode = strtoumax(value, NULL, 8);
1027  } else if (!av_strcasecmp(fact, "UNIX.uid") || !av_strcasecmp(fact, "UNIX.owner"))
1028  next->user_id = strtoumax(value, NULL, 10);
1029  else if (!av_strcasecmp(fact, "UNIX.gid") || !av_strcasecmp(fact, "UNIX.group"))
1030  next->group_id = strtoumax(value, NULL, 10);
1031  else if (!av_strcasecmp(fact, "size") || !av_strcasecmp(fact, "sizd"))
1032  next->size = strtoll(value, NULL, 10);
1033  }
1034  return 0;
1035 }
1036 
1037 /**
1038  * @return 0 on success, negative on error, positive on entry to discard.
1039  */
1040 static int ftp_parse_entry(URLContext *h, char *line, AVIODirEntry *next)
1041 {
1042  FTPContext *s = h->priv_data;
1043 
1044  switch (s->listing_method) {
1045  case MLSD:
1046  return ftp_parse_entry_mlsd(line, next);
1047  case NLST:
1048  return ftp_parse_entry_nlst(line, next);
1049  case UNKNOWN_METHOD:
1050  default:
1051  return -1;
1052  }
1053 }
1054 
1056 {
1057  FTPContext *s = h->priv_data;
1058  char *start, *found;
1059  int ret, retried;
1060 
1061  do {
1062  retried = 0;
1063  start = s->dir_buffer + s->dir_buffer_offset;
1064  while (!(found = strstr(start, "\n"))) {
1065  if (retried)
1066  return AVERROR(EIO);
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);
1071  ret = ffurl_read(s->conn_data, s->dir_buffer + s->dir_buffer_size, DIR_BUFFER_SIZE - (s->dir_buffer_size + 1));
1072  if (ret < 0 && ret != AVERROR_EOF)
1073  return ret;
1074  if (ret <= 0) {
1075  *next = NULL;
1076  return 0;
1077  }
1078  s->dir_buffer_size += ret;
1079  s->dir_buffer[s->dir_buffer_size] = 0;
1080  start = s->dir_buffer;
1081  retried = 1;
1082  }
1083  s->dir_buffer_offset += (found + 1 - start);
1084  found[0] = 0;
1085  if (found > start && found[-1] == '\r')
1086  found[-1] = 0;
1087 
1088  *next = ff_alloc_dir_entry();
1089  if (!*next)
1090  return AVERROR(ENOMEM);
1091  (*next)->utf8 = s->utf8;
1092  ret = ftp_parse_entry(h, start, *next);
1093  if (ret) {
1095  if (ret < 0)
1096  return ret;
1097  }
1098  } while (ret > 0);
1099  return 0;
1100 }
1101 
1103 {
1104  FTPContext *s = h->priv_data;
1105  av_freep(&s->dir_buffer);
1106  ffurl_closep(&s->conn_control);
1107  ffurl_closep(&s->conn_data);
1108  return 0;
1109 }
1110 
1112 {
1113  FTPContext *s = h->priv_data;
1114  char command[MAX_URL_SIZE];
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};
1117  int ret;
1118 
1119  if ((ret = ftp_connect(h, h->filename)) < 0)
1120  goto cleanup;
1121 
1122  ret = snprintf(command, sizeof(command), "DELE %s\r\n", s->path);
1123  if (ret >= sizeof(command)) {
1124  ret = AVERROR(ENOSYS);
1125  goto cleanup;
1126  }
1127 
1128  if (ftp_send_command(s, command, del_codes, NULL) == 250) {
1129  ret = 0;
1130  goto cleanup;
1131  }
1132 
1133  ret = snprintf(command, sizeof(command), "RMD %s\r\n", s->path);
1134  if (ret >= sizeof(command)) {
1135  ret = AVERROR(ENOSYS);
1136  goto cleanup;
1137  }
1138 
1139  if (ftp_send_command(s, command, rmd_codes, NULL) == 250)
1140  ret = 0;
1141  else
1142  ret = AVERROR(EIO);
1143 
1144 cleanup:
1145  ftp_close(h);
1146  return ret;
1147 }
1148 
1149 static int ftp_move(URLContext *h_src, URLContext *h_dst)
1150 {
1151  FTPContext *s = h_src->priv_data;
1152  char command[MAX_URL_SIZE], path[MAX_URL_SIZE];
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};
1155  int ret;
1156 
1157  if ((ret = ftp_connect(h_src, h_src->filename)) < 0)
1158  goto cleanup;
1159 
1160  ret = snprintf(command, sizeof(command), "RNFR %s\r\n", s->path);
1161  if (ret >= sizeof(command)) {
1162  ret = AVERROR(ENOSYS);
1163  goto cleanup;
1164  }
1165 
1166  if (ftp_send_command(s, command, rnfr_codes, NULL) != 350) {
1167  ret = AVERROR(EIO);
1168  goto cleanup;
1169  }
1170 
1171  av_url_split(0, 0, 0, 0, 0, 0, 0,
1172  path, sizeof(path),
1173  h_dst->filename);
1174  if (is_bad_string(path)) {
1175  ret = AVERROR(EINVAL);
1176  goto cleanup;
1177  }
1178  ret = snprintf(command, sizeof(command), "RNTO %s\r\n", path);
1179  if (ret >= sizeof(command)) {
1180  ret = AVERROR(ENOSYS);
1181  goto cleanup;
1182  }
1183 
1184  if (ftp_send_command(s, command, rnto_codes, NULL) == 250)
1185  ret = 0;
1186  else
1187  ret = AVERROR(EIO);
1188 
1189 cleanup:
1190  ftp_close(h_src);
1191  return ret;
1192 }
1193 
1195  .name = "ftp",
1196  .url_open = ftp_open,
1197  .url_read = ftp_read,
1198  .url_write = ftp_write,
1199  .url_seek = ftp_seek,
1200  .url_close = ftp_close,
1201  .url_get_file_handle = ftp_get_file_handle,
1202  .url_shutdown = ftp_shutdown,
1203  .priv_data_size = sizeof(FTPContext),
1204  .priv_data_class = &ftp_context_class,
1205  .url_open_dir = ftp_open_dir,
1206  .url_read_dir = ftp_read_dir,
1207  .url_close_dir = ftp_close_dir,
1208  .url_delete = ftp_delete,
1209  .url_move = ftp_move,
1211  .default_whitelist = "tcp",
1212 };
static double fact(double i)
Definition: af_aiir.c:952
uint8_t
Main libavformat public API header.
int ffurl_shutdown(URLContext *h, int flags)
Signal the URLContext that we are done reading or writing the stream.
Definition: avio.c:654
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.
Definition: avio.c:404
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.
Definition: avio.c:309
int ffurl_closep(URLContext **hh)
Close the resource accessed by the URLContext h, and free the memory used by it.
Definition: avio.c:441
void avio_free_directory_entry(AVIODirEntry **entry)
Free entry allocated by avio_read_dir().
Definition: avio.c:600
int ffurl_write(URLContext *h, const unsigned char *buf, int size)
Write size bytes from buf to the resource accessed by h.
Definition: avio.c:418
int ffurl_get_file_handle(URLContext *h)
Return the file descriptor associated with this URL.
Definition: avio.c:623
#define AVSEEK_SIZE
ORing this as the "whence" parameter to a seek function causes it to return the filesize without seek...
Definition: avio.h:531
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:675
#define AVIO_FLAG_READ_WRITE
read-write pseudo flag
Definition: avio.h:676
@ AVIO_ENTRY_SYMBOLIC_LINK
Definition: avio.h:72
@ AVIO_ENTRY_DIRECTORY
Definition: avio.h:70
@ AVIO_ENTRY_FILE
Definition: avio.h:74
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:94
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:245
#define AV_BPRINT_SIZE_AUTOMATIC
#define flags(name, subs,...)
Definition: cbs_av1.c:572
#define s(width, name)
Definition: cbs_vp9.c:257
#define fail()
Definition: checkasm.h:133
#define FFMAX(a, b)
Definition: common.h:103
#define NULL
Definition: coverity.c:32
long long int64_t
Definition: coverity.c:34
double value
Definition: eval.c:100
static av_cold void cleanup(FlashSV2Context *s)
Definition: flashsv2enc.c:127
static int ftp_connect(URLContext *h, const char *url)
Definition: ftp.c:695
static const AVClass ftp_context_class
Definition: ftp.c:92
#define E
Definition: ftp.c:82
static int ftp_shutdown(URLContext *h, int flags)
Definition: ftp.c:946
static int ftp_read_dir(URLContext *h, AVIODirEntry **next)
Definition: ftp.c:1055
static void ftp_close_data_connection(FTPContext *s)
Definition: ftp.c:242
static int ftp_store(FTPContext *s)
Definition: ftp.c:454
static int ftp_file_size(FTPContext *s)
Definition: ftp.c:412
static int ftp_set_dir(FTPContext *s)
Definition: ftp.c:496
static int ftp_close(URLContext *h)
Definition: ftp.c:918
static int ftp_connect_data_connection(URLContext *h)
Definition: ftp.c:623
static int ftp_getc(FTPContext *s)
Definition: ftp.c:111
static const AVOption options[]
Definition: ftp.c:83
static int ftp_get_file_handle(URLContext *h)
Definition: ftp.c:934
static int ftp_connect_control_connection(URLContext *h)
Definition: ftp.c:574
static int ftp_passive_mode_epsv(FTPContext *s)
Definition: ftp.c:286
static int ftp_passive_mode(FTPContext *s)
Definition: ftp.c:328
static int ftp_auth(FTPContext *s)
Definition: ftp.c:254
static int ftp_read(URLContext *h, unsigned char *buf, int size)
Definition: ftp.c:834
static int ftp_current_dir(FTPContext *s)
Definition: ftp.c:374
static int ftp_delete(URLContext *h)
Definition: ftp.c:1111
static int ftp_status(FTPContext *s, char **line, const int response_codes[])
Definition: ftp.c:156
static int ftp_list(FTPContext *s)
Definition: ftp.c:534
FTPListingMethod
Definition: ftp.c:46
@ NLST
Definition: ftp.c:48
@ UNKNOWN_METHOD
Definition: ftp.c:47
@ MLSD
Definition: ftp.c:49
static int ftp_list_nlst(FTPContext *s)
Definition: ftp.c:523
static int ftp_abort(URLContext *h)
Definition: ftp.c:657
static int ftp_type(FTPContext *s)
Definition: ftp.c:473
static int ftp_open(URLContext *h, const char *url, int flags)
Definition: ftp.c:766
static int ftp_get_line(FTPContext *s, char *line, int line_size)
Definition: ftp.c:128
static int ftp_write(URLContext *h, const unsigned char *buf, int size)
Definition: ftp.c:889
static int is_bad_string(const unsigned char *s)
Definition: ftp.c:101
static int ftp_parse_entry_nlst(char *line, AVIODirEntry *next)
Definition: ftp.c:993
#define CONTROL_BUFFER_SIZE
Definition: ftp.c:33
static int ftp_restart(FTPContext *s, int64_t pos)
Definition: ftp.c:484
#define DIR_BUFFER_SIZE
Definition: ftp.c:34
static int ftp_parse_entry_mlsd(char *mlsd, AVIODirEntry *next)
Definition: ftp.c:999
static int ftp_list_mlsd(FTPContext *s)
Definition: ftp.c:511
static int64_t ftp_seek(URLContext *h, int64_t pos, int whence)
Definition: ftp.c:792
static int64_t ftp_parse_date(const char *date)
Definition: ftp.c:985
static int ftp_close_dir(URLContext *h)
Definition: ftp.c:1102
#define OFFSET(x)
Definition: ftp.c:80
static int ftp_move(URLContext *h_src, URLContext *h_dst)
Definition: ftp.c:1149
static int ftp_parse_entry(URLContext *h, char *line, AVIODirEntry *next)
Definition: ftp.c:1040
static int ftp_features(FTPContext *s)
Definition: ftp.c:553
static void ftp_close_both_connections(FTPContext *s)
Definition: ftp.c:248
static int ftp_retrieve(FTPContext *s)
Definition: ftp.c:435
FTPState
Definition: ftp.c:36
@ UPLOADING
Definition: ftp.c:40
@ READY
Definition: ftp.c:38
@ UNKNOWN
Definition: ftp.c:37
@ LISTING_DIR
Definition: ftp.c:41
@ ENDOFFILE
Definition: ftp.c:43
@ DISCONNECTED
Definition: ftp.c:42
@ DOWNLOADING
Definition: ftp.c:39
static int ftp_has_feature(FTPContext *s, const char *feature_name)
Definition: ftp.c:545
#define D
Definition: ftp.c:81
static int ftp_open_dir(URLContext *h)
Definition: ftp.c:958
const URLProtocol ff_ftp_protocol
Definition: ftp.c:1194
static int ftp_send_command(FTPContext *s, const char *command, const int response_codes[], char **response)
Definition: ftp.c:217
@ AV_OPT_TYPE_INT
Definition: opt.h:225
@ AV_OPT_TYPE_BOOL
Definition: opt.h:242
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
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.
Definition: utils.c:4798
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:199
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.
Definition: dict.c:143
#define AVERROR_EOF
End of file.
Definition: error.h:55
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:119
#define AVERROR(e)
Definition: error.h:43
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:215
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
#define AV_LOG_INFO
Standard information.
Definition: log.h:205
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:253
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
Definition: avutil.h:308
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().
Definition: avstring.c:186
char * av_stristr(const char *s1, const char *s2)
Locate the first case-independent occurrence in the string haystack of the string needle.
Definition: avstring.c:56
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:215
char * av_append_path_component(const char *path, const char *component)
Append path component to the existing path.
Definition: avstring.c:307
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
int i
Definition: input.c:407
#define MAX_URL_SIZE
Definition: internal.h:30
common internal API header
AVOptions.
char * av_small_strptime(const char *p, const char *fmt, struct tm *dt)
Simplified version of strptime.
Definition: parseutils.c:489
time_t av_timegm(struct tm *tm)
Convert the decomposed UTC time in tm to a time_t value.
Definition: parseutils.c:568
misc parsing utilities
#define snprintf
Definition: snprintf.h:34
unsigned int pos
Definition: spdifenc.c:412
Describe the class of an AVClass context structure.
Definition: log.h:67
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
Describes single entry of the directory.
Definition: avio.h:86
int64_t user_id
User ID of owner, -1 if unknown.
Definition: avio.h:98
int type
Type of the entry.
Definition: avio.h:88
int64_t size
File size in bytes, -1 if unknown.
Definition: avio.h:91
int64_t group_id
Group ID of owner, -1 if unknown.
Definition: avio.h:99
char * name
Filename.
Definition: avio.h:87
int64_t modification_timestamp
Time of last modification in microseconds since unix epoch, -1 if unknown.
Definition: avio.h:92
int64_t filemode
Unix file mode, -1 if unknown.
Definition: avio.h:100
AVOption.
Definition: opt.h:248
Definition: ftp.c:52
int write_seekable
Control seekability, 0 = disable, 1 = enable.
Definition: ftp.c:68
int utf8
Definition: ftp.c:75
const char * option_password
Password to be used if none given in the URL.
Definition: ftp.c:77
char * features
List of server's features represented as raw response.
Definition: ftp.c:71
int64_t filesize
Size of file on server, -1 on error.
Definition: ftp.c:64
FTPState state
State of data connection.
Definition: ftp.c:69
uint8_t * control_buf_end
Definition: ftp.c:57
size_t dir_buffer_size
Definition: ftp.c:73
char * password
Server user's password.
Definition: ftp.c:62
URLContext * conn_control
Control connection.
Definition: ftp.c:54
size_t dir_buffer_offset
Definition: ftp.c:74
char * user
Server user.
Definition: ftp.c:61
int rw_timeout
Network timeout.
Definition: ftp.c:66
char * dir_buffer
Definition: ftp.c:72
int server_control_port
Control connection port, default is 21.
Definition: ftp.c:59
FTPListingMethod listing_method
Called listing method.
Definition: ftp.c:70
int64_t position
Current position, calculated.
Definition: ftp.c:65
int server_data_port
Data connection port opened by server, -1 on error.
Definition: ftp.c:58
const char * option_user
User to be used if none given in the URL.
Definition: ftp.c:76
char * hostname
Server address.
Definition: ftp.c:60
URLContext * conn_data
Data connection, NULL when not connected.
Definition: ftp.c:55
char * path
Path to resource on server.
Definition: ftp.c:63
const char * anonymous_password
Password to be used for anonymous user.
Definition: ftp.c:67
Definition: url.h:38
void * priv_data
Definition: url.h:41
char * filename
specified URL
Definition: url.h:42
const char * name
Definition: url.h:55
Definition: graph2dot.c:48
#define av_free(p)
#define ff_dlog(a,...)
#define av_freep(p)
#define av_malloc(s)
#define av_log(a,...)
AVDictionary * opts
Definition: movenc.c:50
int size
#define pass
Definition: tx_template.c:347
AVIODirEntry * ff_alloc_dir_entry(void)
Allocate directory entry with default values.
Definition: url.c:325
int ff_url_join(char *str, int size, const char *proto, const char *authorization, const char *hostname, int port, const char *fmt,...)
Definition: url.c:38
unbuffered private I/O API
#define URL_PROTOCOL_FLAG_NETWORK
Definition: url.h:34
char * ff_urldecode(const char *url, int decode_plus_sign)
Decodes an URL from its percent-encoded form back into normal representation.
Definition: urldecode.c:35
static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Definition: vf_drawtext.c:883
int len