annotate stream/stream_ftp.c @ 35396:6f03d15719a3

stream ftp: Set type to STREAMTYPE_STREAM Previously this was not set at all from within the stream_ftp module. This caused the run-time warning message "Streams need a type!". The actual behaviour should not be affected by this change.
author al
date Mon, 26 Nov 2012 23:38:11 +0000
parents e740eaf25f32
children 0c18f01f65a5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30426
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 30376
diff changeset
1 /*
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 30376
diff changeset
2 * This file is part of MPlayer.
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 30376
diff changeset
3 *
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 30376
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 30376
diff changeset
5 * it under the terms of the GNU General Public License as published by
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 30376
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 30376
diff changeset
7 * (at your option) any later version.
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 30376
diff changeset
8 *
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 30376
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 30376
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 30376
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 30376
diff changeset
12 * GNU General Public License for more details.
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 30376
diff changeset
13 *
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 30376
diff changeset
14 * You should have received a copy of the GNU General Public License along
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 30376
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 30376
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 30376
diff changeset
17 */
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
18
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
19 #include "config.h"
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
20
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
21 #include <stdlib.h>
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
22 #include <stdio.h>
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
23
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
24 #include <sys/types.h>
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
25 #include <sys/stat.h>
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
26 #include <fcntl.h>
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
27 #include <unistd.h>
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
28 #include <errno.h>
28402
c884d17bd005 Convert HAVE_WINSOCK2_H into a 0/1 definition.
diego
parents: 27473
diff changeset
29 #if !HAVE_WINSOCK2_H
27472
c0b233cd30ca Revert moving closesocket definition and network headers to network.h.
diego
parents: 27464
diff changeset
30 #include <sys/socket.h>
c0b233cd30ca Revert moving closesocket definition and network headers to network.h.
diego
parents: 27464
diff changeset
31 #else
c0b233cd30ca Revert moving closesocket definition and network headers to network.h.
diego
parents: 27464
diff changeset
32 #include <winsock2.h>
c0b233cd30ca Revert moving closesocket definition and network headers to network.h.
diego
parents: 27464
diff changeset
33 #endif
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
34
35333
701e78689c07 stream ftp: readline: Fix off-by-one error
al
parents: 32511
diff changeset
35 #include "libavutil/avutil.h"
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
36 #include "mp_msg.h"
27473
ae5da477539e Move '#define closesocket close' preprocessor directive to a common place
diego
parents: 27472
diff changeset
37 #include "network.h"
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
38 #include "stream.h"
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
39 #include "help_mp.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16761
diff changeset
40 #include "m_option.h"
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16761
diff changeset
41 #include "m_struct.h"
19335
2a9d669e5ff6 isolated tcp socket code from network.c to a dedicated file
ben
parents: 19271
diff changeset
42 #include "tcp.h"
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
43
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
44 static struct stream_priv_s {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
45 char* user;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
46 char* pass;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
47 char* host;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
48 int port;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
49 char* filename;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
50
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
51 char *cput,*cget;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
52 int handle;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
53 int cavail,cleft;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
54 char *buf;
35339
c7c59b8e3af8 stream ftp: Allocate command buffer on-heap
al
parents: 35338
diff changeset
55 char *cmd_buf;
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
56 } stream_priv_dflts = {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
57 "anonymous","no@spam",
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
58 NULL,
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
59 21,
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
60 NULL,
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
61 NULL,
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
62 NULL,
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
63
35336
9c334690f765 stream ftp: Revise file descriptor usage
al
parents: 35335
diff changeset
64 -1,
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
65 0,0,
35339
c7c59b8e3af8 stream ftp: Allocate command buffer on-heap
al
parents: 35338
diff changeset
66 NULL,
c7c59b8e3af8 stream ftp: Allocate command buffer on-heap
al
parents: 35338
diff changeset
67 NULL,
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
68 };
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
69
35340
d5476d0811f8 stream ftp: Increase command buffer size
al
parents: 35339
diff changeset
70 #define CMD_BUFSIZE 8192
35339
c7c59b8e3af8 stream ftp: Allocate command buffer on-heap
al
parents: 35338
diff changeset
71
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
72 #define BUFSIZE 2048
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
73
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
74 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f)
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
75 /// URL definition
25242
371a40dcc1cc stream_opts arrays should be const
reimar
parents: 25211
diff changeset
76 static const m_option_t stream_opts_fields[] = {
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
77 {"username", ST_OFF(user), CONF_TYPE_STRING, 0, 0 ,0, NULL},
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
78 {"password", ST_OFF(pass), CONF_TYPE_STRING, 0, 0 ,0, NULL},
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
79 {"hostname", ST_OFF(host), CONF_TYPE_STRING, 0, 0 ,0, NULL},
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
80 {"port", ST_OFF(port), CONF_TYPE_INT, 0, 0 ,65635, NULL},
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
81 {"filename", ST_OFF(filename), CONF_TYPE_STRING, 0, 0 ,0, NULL},
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
82 { NULL, NULL, 0, 0, 0, 0, NULL }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
83 };
25691
68015115f63a stream_opts should be const
reimar
parents: 25242
diff changeset
84 static const struct m_struct_st stream_opts = {
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
85 "ftp",
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
86 sizeof(struct stream_priv_s),
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
87 &stream_priv_dflts,
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
88 stream_opts_fields
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
89 };
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
90
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
91 #define TELNET_IAC 255 /* interpret as command: */
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
92 #define TELNET_IP 244 /* interrupt process--permanently */
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
93 #define TELNET_SYNCH 242 /* for telfunc calls */
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
94
17854
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
95 // Check if there is something to read on a fd. This avoid hanging
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
96 // forever if the network stop responding.
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
97 static int fd_can_read(int fd,int timeout) {
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
98 fd_set fds;
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
99 struct timeval tv;
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
100
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
101 FD_ZERO(&fds);
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
102 FD_SET(fd,&fds);
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
103 tv.tv_sec = timeout;
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
104 tv.tv_usec = 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
105
26756
c43ce7268677 cosmetics: Remove useless parentheses from return statements.
diego
parents: 25691
diff changeset
106 return select(fd+1, &fds, NULL, NULL, &tv) > 0;
17854
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
107 }
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
108
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
109 /*
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
110 * read a line of text
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
111 *
35335
85003f7fa621 stream ftp: readline: Always try to read complete lines
al
parents: 35334
diff changeset
112 * If the line is too long to fit in the buffer, provided via parameters
85003f7fa621 stream ftp: readline: Always try to read complete lines
al
parents: 35334
diff changeset
113 * buf and max, the remaining characters are skipped. So the next call to
85003f7fa621 stream ftp: readline: Always try to read complete lines
al
parents: 35334
diff changeset
114 * this function is synchronized to the start of the following response
85003f7fa621 stream ftp: readline: Always try to read complete lines
al
parents: 35334
diff changeset
115 * line.
85003f7fa621 stream ftp: readline: Always try to read complete lines
al
parents: 35334
diff changeset
116 *
35334
3397976a029b stream ftp: readline: Always initialize output parameter buf
al
parents: 35333
diff changeset
117 * The parameter buf will always be initialized as long as max is bigger
3397976a029b stream ftp: readline: Always initialize output parameter buf
al
parents: 35333
diff changeset
118 * then 1. If nothing is read it will contain an empty string.
3397976a029b stream ftp: readline: Always initialize output parameter buf
al
parents: 35333
diff changeset
119 *
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
120 * return -1 on error or bytecount
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
121 */
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
122 static int readline(char *buf,int max,struct stream_priv_s *ctl)
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
123 {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
124 int x,retval = 0;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
125 char *end,*bp=buf;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
126 int eof = 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
127
35334
3397976a029b stream ftp: readline: Always initialize output parameter buf
al
parents: 35333
diff changeset
128 if (max <= 0) {
3397976a029b stream ftp: readline: Always initialize output parameter buf
al
parents: 35333
diff changeset
129 return -1;
3397976a029b stream ftp: readline: Always initialize output parameter buf
al
parents: 35333
diff changeset
130 }
3397976a029b stream ftp: readline: Always initialize output parameter buf
al
parents: 35333
diff changeset
131 *bp = '\0';
3397976a029b stream ftp: readline: Always initialize output parameter buf
al
parents: 35333
diff changeset
132
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
133 do {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
134 if (ctl->cavail > 0) {
35333
701e78689c07 stream ftp: readline: Fix off-by-one error
al
parents: 32511
diff changeset
135 x = FFMIN(ctl->cavail, max-1);
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
136 end = memccpy(bp,ctl->cget,'\n',x);
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
137 if (end != NULL)
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
138 x = end - bp;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
139 retval += x;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
140 bp += x;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
141 *bp = '\0';
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
142 max -= x;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
143 ctl->cget += x;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
144 ctl->cavail -= x;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
145 if (end != NULL) {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
146 bp -= 2;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
147 if (strcmp(bp,"\r\n") == 0) {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
148 *bp++ = '\n';
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
149 *bp++ = '\0';
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
150 --retval;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
151 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
152 break;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
153 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
154 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
155 if (max == 1) {
35335
85003f7fa621 stream ftp: readline: Always try to read complete lines
al
parents: 35334
diff changeset
156 char *q = memchr(ctl->cget, '\n', ctl->cavail);
85003f7fa621 stream ftp: readline: Always try to read complete lines
al
parents: 35334
diff changeset
157
85003f7fa621 stream ftp: readline: Always try to read complete lines
al
parents: 35334
diff changeset
158 if (q) { // found EOL: update state and return
85003f7fa621 stream ftp: readline: Always try to read complete lines
al
parents: 35334
diff changeset
159 ++q;
85003f7fa621 stream ftp: readline: Always try to read complete lines
al
parents: 35334
diff changeset
160 ctl->cavail -= q - ctl->cget;
85003f7fa621 stream ftp: readline: Always try to read complete lines
al
parents: 35334
diff changeset
161 ctl->cget = q;
85003f7fa621 stream ftp: readline: Always try to read complete lines
al
parents: 35334
diff changeset
162
85003f7fa621 stream ftp: readline: Always try to read complete lines
al
parents: 35334
diff changeset
163 break;
85003f7fa621 stream ftp: readline: Always try to read complete lines
al
parents: 35334
diff changeset
164 }
85003f7fa621 stream ftp: readline: Always try to read complete lines
al
parents: 35334
diff changeset
165
85003f7fa621 stream ftp: readline: Always try to read complete lines
al
parents: 35334
diff changeset
166 // receive more data to find end of current line
85003f7fa621 stream ftp: readline: Always try to read complete lines
al
parents: 35334
diff changeset
167 ctl->cget = ctl->cput;
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
168 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
169 if (ctl->cput == ctl->cget) {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
170 ctl->cput = ctl->cget = ctl->buf;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
171 ctl->cavail = 0;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
172 ctl->cleft = BUFSIZE;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
173 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
174 if(eof) {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
175 if (retval == 0)
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
176 retval = -1;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
177 break;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
178 }
17854
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
179
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
180 if(!fd_can_read(ctl->handle, 15)) {
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
181 mp_msg(MSGT_OPEN,MSGL_ERR, "[ftp] read timed out\n");
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
182 retval = -1;
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
183 break;
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
184 }
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
185
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
186 if ((x = recv(ctl->handle,ctl->cput,ctl->cleft,0)) == -1) {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
187 mp_msg(MSGT_STREAM,MSGL_ERR, "[ftp] read error: %s\n",strerror(errno));
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
188 retval = -1;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
189 break;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
190 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
191 if (x == 0)
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
192 eof = 1;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
193 ctl->cleft -= x;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
194 ctl->cavail += x;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
195 ctl->cput += x;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
196 } while (1);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
197
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
198 return retval;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
199 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
200
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
201 /*
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
202 * read a response from the server
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
203 *
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
204 * return 0 if first char doesn't match
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
205 * return 1 if first char matches
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
206 */
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
207 static int readresp(struct stream_priv_s* ctl,char* rsp)
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
208 {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
209 static char response[256];
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
210 char match[5];
35334
3397976a029b stream ftp: readline: Always initialize output parameter buf
al
parents: 35333
diff changeset
211 int r, len;
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
212
35334
3397976a029b stream ftp: readline: Always initialize output parameter buf
al
parents: 35333
diff changeset
213 len = readline(response,256,ctl);
3397976a029b stream ftp: readline: Always initialize output parameter buf
al
parents: 35333
diff changeset
214 if (rsp) strcpy(rsp,response);
3397976a029b stream ftp: readline: Always initialize output parameter buf
al
parents: 35333
diff changeset
215 if (len == -1)
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
216 return 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
217
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
218 r = atoi(response)/100;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
219
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
220 mp_msg(MSGT_STREAM,MSGL_V, "[ftp] < %s",response);
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
221
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
222 if (response[3] == '-') {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
223 strncpy(match,response,3);
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
224 match[3] = ' ';
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
225 match[4] = '\0';
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
226 do {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
227 if (readline(response,256,ctl) == -1) {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
228 mp_msg(MSGT_OPEN,MSGL_ERR, "[ftp] Control socket read failed\n");
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
229 return 0;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
230 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
231 mp_msg(MSGT_OPEN,MSGL_V, "[ftp] < %s",response);
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
232 } while (strncmp(response,match,4));
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
233 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
234 return r;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
235 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
236
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
237
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
238 static int FtpSendCmd(const char *cmd, struct stream_priv_s *nControl,char* rsp)
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
239 {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
240 int l = strlen(cmd);
16761
1eeb10c3e534 Make FtpSendCmd() function more user friendly by making it append the necessary "\r\n" line break (instead of the caller)
gpoirier
parents: 16750
diff changeset
241 int hascrlf = cmd[l - 2] == '\r' && cmd[l - 1] == '\n';
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
242
17854
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
243 if(hascrlf && l == 2) mp_msg(MSGT_STREAM,MSGL_V, "\n");
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
244 else mp_msg(MSGT_STREAM,MSGL_V, "[ftp] > %s",cmd);
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
245 while(l > 0) {
31500
b01f807eb183 Use MSG_NOSIGNAL flag if available for send().
reimar
parents: 30426
diff changeset
246 int s = send(nControl->handle,cmd,l,DEFAULT_SEND_FLAGS);
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
247
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
248 if(s <= 0) {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
249 mp_msg(MSGT_OPEN,MSGL_ERR, "[ftp] write error: %s\n",strerror(errno));
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
250 return 0;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
251 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
252
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
253 cmd += s;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
254 l -= s;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
255 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
256
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
257 if (hascrlf)
16761
1eeb10c3e534 Make FtpSendCmd() function more user friendly by making it append the necessary "\r\n" line break (instead of the caller)
gpoirier
parents: 16750
diff changeset
258 return readresp(nControl,rsp);
1eeb10c3e534 Make FtpSendCmd() function more user friendly by making it append the necessary "\r\n" line break (instead of the caller)
gpoirier
parents: 16750
diff changeset
259 else
1eeb10c3e534 Make FtpSendCmd() function more user friendly by making it append the necessary "\r\n" line break (instead of the caller)
gpoirier
parents: 16750
diff changeset
260 return FtpSendCmd("\r\n", nControl, rsp);
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
261 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
262
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
263 static int FtpOpenPort(struct stream_priv_s* p) {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
264 int resp,fd;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
265 char rsp_txt[256];
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
266 char* par,str[128];
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
267 int num[6];
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
268
16761
1eeb10c3e534 Make FtpSendCmd() function more user friendly by making it append the necessary "\r\n" line break (instead of the caller)
gpoirier
parents: 16750
diff changeset
269 resp = FtpSendCmd("PASV",p,rsp_txt);
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
270 if(resp != 2) {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
271 mp_msg(MSGT_OPEN,MSGL_WARN, "[ftp] command 'PASV' failed: %s\n",rsp_txt);
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
272 return 0;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
273 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
274
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
275 par = strchr(rsp_txt,'(');
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
276
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
277 if(!par || !par[0] || !par[1]) {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
278 mp_msg(MSGT_OPEN,MSGL_ERR, "[ftp] invalid server response: %s ??\n",rsp_txt);
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
279 return 0;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
280 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
281
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
282 sscanf(par+1,"%u,%u,%u,%u,%u,%u",&num[0],&num[1],&num[2],
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
283 &num[3],&num[4],&num[5]);
35394
7bad316da87a stream ftp: Pass full buffer size to snprintf
al
parents: 35340
diff changeset
284 snprintf(str,sizeof(str),"%d.%d.%d.%d",num[0],num[1],num[2],num[3]);
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
285 fd = connect2Server(str,(num[4]<<8)+num[5],0);
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
286
17854
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
287 if(fd < 0)
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
288 mp_msg(MSGT_OPEN,MSGL_ERR, "[ftp] failed to create data connection\n");
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
289
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
290 return fd;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
291 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
292
30376
3365a4658320 Fix ftp support to properly support large files > 2GB.
reimar
parents: 29263
diff changeset
293 static int FtpOpenData(stream_t* s,off_t newpos) {
17854
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
294 struct stream_priv_s* p = s->priv;
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
295 int resp;
35339
c7c59b8e3af8 stream ftp: Allocate command buffer on-heap
al
parents: 35338
diff changeset
296 char rsp_txt[256];
17854
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
297
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
298 // Open a new connection
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
299 s->fd = FtpOpenPort(p);
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
300
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
301 if(s->fd < 0) return 0;
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
302
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
303 if(newpos > 0) {
35394
7bad316da87a stream ftp: Pass full buffer size to snprintf
al
parents: 35340
diff changeset
304 snprintf(p->cmd_buf,CMD_BUFSIZE,"REST %"PRId64, (int64_t)newpos);
17854
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
305
35339
c7c59b8e3af8 stream ftp: Allocate command buffer on-heap
al
parents: 35338
diff changeset
306 resp = FtpSendCmd(p->cmd_buf,p,rsp_txt);
17854
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
307 if(resp != 3) {
35339
c7c59b8e3af8 stream ftp: Allocate command buffer on-heap
al
parents: 35338
diff changeset
308 mp_msg(MSGT_OPEN,MSGL_WARN, "[ftp] command '%s' failed: %s\n",p->cmd_buf,rsp_txt);
17854
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
309 newpos = 0;
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
310 }
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
311 }
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
312
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
313 // Get the file
35394
7bad316da87a stream ftp: Pass full buffer size to snprintf
al
parents: 35340
diff changeset
314 snprintf(p->cmd_buf,CMD_BUFSIZE,"RETR %s",p->filename);
35339
c7c59b8e3af8 stream ftp: Allocate command buffer on-heap
al
parents: 35338
diff changeset
315 resp = FtpSendCmd(p->cmd_buf,p,rsp_txt);
17854
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
316
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
317 if(resp != 1) {
35339
c7c59b8e3af8 stream ftp: Allocate command buffer on-heap
al
parents: 35338
diff changeset
318 mp_msg(MSGT_OPEN,MSGL_ERR, "[ftp] command '%s' failed: %s\n",p->cmd_buf,rsp_txt);
17854
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
319 return 0;
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
320 }
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
321
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
322 s->pos = newpos;
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
323 return 1;
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
324 }
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
325
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
326 static int fill_buffer(stream_t *s, char* buffer, int max_len){
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
327 int r;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
328
17854
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
329 if(s->fd < 0 && !FtpOpenData(s,s->pos))
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
330 return -1;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
331
17854
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
332 if(!fd_can_read(s->fd, 15)) {
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
333 mp_msg(MSGT_OPEN,MSGL_ERR, "[ftp] read timed out\n");
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
334 return -1;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
335 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
336
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
337 r = recv(s->fd,buffer,max_len,0);
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
338 return (r <= 0) ? -1 : r;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
339 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
340
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
341 static int seek(stream_t *s,off_t newpos) {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
342 struct stream_priv_s* p = s->priv;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
343 int resp;
17854
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
344 char rsp_txt[256];
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
345
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
346 if(s->pos > s->end_pos) {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
347 s->eof=1;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
348 return 0;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
349 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
350
23873
49a433e2e78f cosmetics: misc typo fixes
diego
parents: 19335
diff changeset
351 // Check to see if the server did not already terminate the transfer
17854
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
352 if(fd_can_read(p->handle, 0)) {
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
353 if(readresp(p,rsp_txt) != 2)
23873
49a433e2e78f cosmetics: misc typo fixes
diego
parents: 19335
diff changeset
354 mp_msg(MSGT_OPEN,MSGL_WARN, "[ftp] Warning the server didn't finished the transfer correctly: %s\n",rsp_txt);
10627
f7df841c8b74 ftp support for mingw
faust3
parents: 10625
diff changeset
355 closesocket(s->fd);
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
356 s->fd = -1;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
357 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
358
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
359 // Close current download
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
360 if(s->fd >= 0) {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
361 static const char pre_cmd[]={TELNET_IAC,TELNET_IP,TELNET_IAC,TELNET_SYNCH};
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
362 //int fl;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
363
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
364 // First close the fd
10627
f7df841c8b74 ftp support for mingw
faust3
parents: 10625
diff changeset
365 closesocket(s->fd);
35336
9c334690f765 stream ftp: Revise file descriptor usage
al
parents: 35335
diff changeset
366 s->fd = -1;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
367
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
368 // Send send the telnet sequence needed to make the server react
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
369
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
370 // Dunno if this is really needed, lftp have it. I let
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
371 // it here in case it turn out to be needed on some other OS
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
372 //fl=fcntl(p->handle,F_GETFL);
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
373 //fcntl(p->handle,F_SETFL,fl&~O_NONBLOCK);
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
374
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
375 // send only first byte as OOB due to OOB braindamage in many unices
31500
b01f807eb183 Use MSG_NOSIGNAL flag if available for send().
reimar
parents: 30426
diff changeset
376 send(p->handle,pre_cmd,1,MSG_OOB|DEFAULT_SEND_FLAGS);
b01f807eb183 Use MSG_NOSIGNAL flag if available for send().
reimar
parents: 30426
diff changeset
377 send(p->handle,pre_cmd+1,sizeof(pre_cmd)-1,DEFAULT_SEND_FLAGS);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
378
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
379 //fcntl(p->handle,F_SETFL,fl);
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
380
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
381 // Get the 426 Transfer aborted
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
382 // Or the 226 Transfer complete
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
383 resp = readresp(p,rsp_txt);
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
384 if(resp != 4 && resp != 2) {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
385 mp_msg(MSGT_OPEN,MSGL_ERR, "[ftp] Server didn't abort correctly: %s\n",rsp_txt);
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
386 s->eof = 1;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
387 return 0;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
388 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
389 // Send the ABOR command
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
390 // Ignore the return code as sometimes it fail with "nothing to abort"
16761
1eeb10c3e534 Make FtpSendCmd() function more user friendly by making it append the necessary "\r\n" line break (instead of the caller)
gpoirier
parents: 16750
diff changeset
391 FtpSendCmd("ABOR",p,rsp_txt);
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
392 }
17854
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
393 return FtpOpenData(s,newpos);
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
394 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
395
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
396
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
397 static void close_f(stream_t *s) {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
398 struct stream_priv_s* p = s->priv;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
399
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
400 if(!p) return;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
401
35336
9c334690f765 stream ftp: Revise file descriptor usage
al
parents: 35335
diff changeset
402 if(s->fd >= 0) {
10627
f7df841c8b74 ftp support for mingw
faust3
parents: 10625
diff changeset
403 closesocket(s->fd);
35336
9c334690f765 stream ftp: Revise file descriptor usage
al
parents: 35335
diff changeset
404 s->fd = -1;
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
405 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
406
35337
6641819c8f45 stream ftp: Only send QUIT command if connected
al
parents: 35336
diff changeset
407 if (p->handle >= 0) {
6641819c8f45 stream ftp: Only send QUIT command if connected
al
parents: 35336
diff changeset
408 FtpSendCmd("QUIT", p, NULL);
6641819c8f45 stream ftp: Only send QUIT command if connected
al
parents: 35336
diff changeset
409 closesocket(p->handle);
6641819c8f45 stream ftp: Only send QUIT command if connected
al
parents: 35336
diff changeset
410 }
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
411
32511
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 31500
diff changeset
412 free(p->buf);
35339
c7c59b8e3af8 stream ftp: Allocate command buffer on-heap
al
parents: 35338
diff changeset
413 free(p->cmd_buf);
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
414
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
415 m_struct_free(&stream_opts,p);
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
416 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
417
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
418
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
419
35395
e740eaf25f32 stream ftp: open_f: Mark parameter file_format unused
al
parents: 35394
diff changeset
420 static int open_f(stream_t *stream,int mode, void* opts, av_unused int* file_format) {
30376
3365a4658320 Fix ftp support to properly support large files > 2GB.
reimar
parents: 29263
diff changeset
421 int resp;
3365a4658320 Fix ftp support to properly support large files > 2GB.
reimar
parents: 29263
diff changeset
422 int64_t len = 0;
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
423 struct stream_priv_s* p = (struct stream_priv_s*)opts;
35339
c7c59b8e3af8 stream ftp: Allocate command buffer on-heap
al
parents: 35338
diff changeset
424 char rsp_txt[256];
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
425
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
426 if(mode != STREAM_READ) {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
427 mp_msg(MSGT_OPEN,MSGL_ERR, "[ftp] Unknown open mode %d\n",mode);
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
428 m_struct_free(&stream_opts,opts);
24257
d261f5109660 cosmetics: typo fix UNSUPORTED --> UNSUPPORTED
diego
parents: 23873
diff changeset
429 return STREAM_UNSUPPORTED;
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
430 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
431
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
432 if(!p->filename || !p->host) {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
433 mp_msg(MSGT_OPEN,MSGL_ERR, "[ftp] Bad url\n");
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
434 m_struct_free(&stream_opts,opts);
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
435 return STREAM_ERROR;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
436 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
437
35338
4fe8922d6242 stream ftp: Create buffers before opening control connection
al
parents: 35337
diff changeset
438 // Allocate buffers
4fe8922d6242 stream ftp: Create buffers before opening control connection
al
parents: 35337
diff changeset
439 p->buf = malloc(BUFSIZE);
35339
c7c59b8e3af8 stream ftp: Allocate command buffer on-heap
al
parents: 35338
diff changeset
440 p->cmd_buf = malloc(CMD_BUFSIZE);
35338
4fe8922d6242 stream ftp: Create buffers before opening control connection
al
parents: 35337
diff changeset
441
35339
c7c59b8e3af8 stream ftp: Allocate command buffer on-heap
al
parents: 35338
diff changeset
442 if (!p->buf || !p->cmd_buf) {
35338
4fe8922d6242 stream ftp: Create buffers before opening control connection
al
parents: 35337
diff changeset
443 close_f(stream);
4fe8922d6242 stream ftp: Create buffers before opening control connection
al
parents: 35337
diff changeset
444 m_struct_free(&stream_opts,opts);
4fe8922d6242 stream ftp: Create buffers before opening control connection
al
parents: 35337
diff changeset
445 return STREAM_ERROR;
4fe8922d6242 stream ftp: Create buffers before opening control connection
al
parents: 35337
diff changeset
446 }
4fe8922d6242 stream ftp: Create buffers before opening control connection
al
parents: 35337
diff changeset
447
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
448 // Open the control connection
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
449 p->handle = connect2Server(p->host,p->port,1);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
450
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
451 if(p->handle < 0) {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
452 m_struct_free(&stream_opts,opts);
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
453 return STREAM_ERROR;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
454 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
455
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
456 // We got a connection, let's start serious things
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
457 stream->fd = -1;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
458 stream->priv = p;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
459
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
460 if (readresp(p, NULL) == 0) {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
461 close_f(stream);
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
462 m_struct_free(&stream_opts,opts);
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
463 return STREAM_ERROR;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
464 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
465
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
466 // Login
35394
7bad316da87a stream ftp: Pass full buffer size to snprintf
al
parents: 35340
diff changeset
467 snprintf(p->cmd_buf,CMD_BUFSIZE,"USER %s",p->user);
35339
c7c59b8e3af8 stream ftp: Allocate command buffer on-heap
al
parents: 35338
diff changeset
468 resp = FtpSendCmd(p->cmd_buf,p,rsp_txt);
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
469
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
470 // password needed
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
471 if(resp == 3) {
35394
7bad316da87a stream ftp: Pass full buffer size to snprintf
al
parents: 35340
diff changeset
472 snprintf(p->cmd_buf,CMD_BUFSIZE,"PASS %s",p->pass);
35339
c7c59b8e3af8 stream ftp: Allocate command buffer on-heap
al
parents: 35338
diff changeset
473 resp = FtpSendCmd(p->cmd_buf,p,rsp_txt);
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
474 if(resp != 2) {
35339
c7c59b8e3af8 stream ftp: Allocate command buffer on-heap
al
parents: 35338
diff changeset
475 mp_msg(MSGT_OPEN,MSGL_ERR, "[ftp] command '%s' failed: %s\n",p->cmd_buf,rsp_txt);
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
476 close_f(stream);
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
477 return STREAM_ERROR;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
478 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
479 } else if(resp != 2) {
35339
c7c59b8e3af8 stream ftp: Allocate command buffer on-heap
al
parents: 35338
diff changeset
480 mp_msg(MSGT_OPEN,MSGL_ERR, "[ftp] command '%s' failed: %s\n",p->cmd_buf,rsp_txt);
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
481 close_f(stream);
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
482 return STREAM_ERROR;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
483 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
484
23873
49a433e2e78f cosmetics: misc typo fixes
diego
parents: 19335
diff changeset
485 // Set the transfer type
16761
1eeb10c3e534 Make FtpSendCmd() function more user friendly by making it append the necessary "\r\n" line break (instead of the caller)
gpoirier
parents: 16750
diff changeset
486 resp = FtpSendCmd("TYPE I",p,rsp_txt);
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
487 if(resp != 2) {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
488 mp_msg(MSGT_OPEN,MSGL_WARN, "[ftp] command 'TYPE I' failed: %s\n",rsp_txt);
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
489 close_f(stream);
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
490 return STREAM_ERROR;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
491 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
492
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
493 // Get the filesize
35394
7bad316da87a stream ftp: Pass full buffer size to snprintf
al
parents: 35340
diff changeset
494 snprintf(p->cmd_buf,CMD_BUFSIZE,"SIZE %s",p->filename);
35339
c7c59b8e3af8 stream ftp: Allocate command buffer on-heap
al
parents: 35338
diff changeset
495 resp = FtpSendCmd(p->cmd_buf,p,rsp_txt);
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
496 if(resp != 2) {
35339
c7c59b8e3af8 stream ftp: Allocate command buffer on-heap
al
parents: 35338
diff changeset
497 mp_msg(MSGT_OPEN,MSGL_WARN, "[ftp] command '%s' failed: %s\n",p->cmd_buf,rsp_txt);
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
498 } else {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
499 int dummy;
30376
3365a4658320 Fix ftp support to properly support large files > 2GB.
reimar
parents: 29263
diff changeset
500 sscanf(rsp_txt,"%d %"SCNd64,&dummy,&len);
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
501 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
502
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
503 if(len > 0) {
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
504 stream->seek = seek;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
505 stream->end_pos = len;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
506 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
507
17854
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
508 // The data connection is really opened only at the first
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
509 // read/seek. This must be done when the cache is used
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
510 // because the connection would stay open in the main process,
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
511 // preventing correct abort with many servers.
a63fa57ecbd7 Fix seeking with cache enabled on systems using fork().
albeu
parents: 17012
diff changeset
512 stream->fd = -1;
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
513 stream->priv = p;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
514 stream->fill_buffer = fill_buffer;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
515 stream->close = close_f;
35396
6f03d15719a3 stream ftp: Set type to STREAMTYPE_STREAM
al
parents: 35395
diff changeset
516 stream->type = STREAMTYPE_STREAM;
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
517
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
518 return STREAM_OK;
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
519 }
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
520
25211
c1d17bd6683c Mark all stream_info_t as const
reimar
parents: 24257
diff changeset
521 const stream_info_t stream_info_ftp = {
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
522 "File Transfer Protocol",
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
523 "ftp",
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
524 "Albeu",
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
525 "reuse a bit of code from ftplib written by Thomas Pfau",
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
526 open_f,
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
527 { "ftp", NULL },
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
528 &stream_opts,
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
529 1 // Urls are an option string
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
diff changeset
530 };