-rw-r--r-- | noncore/net/ftplib/ftplib.c (renamed from noncore/net/opieftp/ftplib.c) | 1160 | ||||
-rw-r--r-- | noncore/net/ftplib/ftplib.control | 9 | ||||
-rw-r--r-- | noncore/net/ftplib/ftplib.h (renamed from noncore/net/opieftp/ftplib.h) | 0 | ||||
-rw-r--r-- | noncore/net/ftplib/ftplib.pro | 6 | ||||
-rw-r--r-- | noncore/net/opieftp/opieftp.control | 2 | ||||
-rw-r--r-- | noncore/net/opieftp/opieftp.cpp | 6 | ||||
-rw-r--r-- | noncore/net/opieftp/opieftp.h | 2 | ||||
-rw-r--r-- | noncore/net/opieftp/opieftp.pro | 4 |
8 files changed, 631 insertions, 558 deletions
diff --git a/noncore/net/opieftp/ftplib.c b/noncore/net/ftplib/ftplib.c index 5116170..421f855 100644 --- a/noncore/net/opieftp/ftplib.c +++ b/noncore/net/ftplib/ftplib.c | |||
@@ -19,33 +19,45 @@ | |||
19 | /* Boston, MA 02111-1307, USA. */ | 19 | /* Boston, MA 02111-1307, USA. */ |
20 | /* */ | 20 | /* */ |
21 | /***************************************************************************/ | 21 | /***************************************************************************/ |
22 | 22 | // changes made by Lorn Potter <llornkcor@handhelds.org> | |
23 | // | ||
23 | #if defined(__unix__) || defined(__VMS) | 24 | #if defined(__unix__) || defined(__VMS) |
24 | #include <unistd.h> | 25 | #include <unistd.h> |
25 | #endif | 26 | #endif |
26 | #if defined(_WIN32) | 27 | #if defined(_WIN32) |
27 | #include <windows.h> | 28 | #include <windows.h> |
28 | #endif | 29 | #endif |
30 | |||
29 | #include <stdio.h> | 31 | #include <stdio.h> |
30 | #include <stdlib.h> | 32 | #include <stdlib.h> |
31 | #include <string.h> | 33 | #include <string.h> |
32 | #include <errno.h> | 34 | #include <errno.h> |
33 | #include <ctype.h> | 35 | #include <ctype.h> |
36 | |||
34 | #if defined(__unix__) | 37 | #if defined(__unix__) |
38 | |||
39 | #include <sys/types.h> | ||
40 | #include <unistd.h> | ||
41 | #include <fcntl.h> | ||
35 | #include <sys/time.h> | 42 | #include <sys/time.h> |
36 | #include <sys/types.h> | 43 | #include <sys/types.h> |
37 | #include <sys/socket.h> | 44 | #include <sys/socket.h> |
38 | #include <netinet/in.h> | 45 | #include <netinet/in.h> |
39 | #include <netdb.h> | 46 | #include <netdb.h> |
40 | #include <arpa/inet.h> | 47 | #include <arpa/inet.h> |
48 | |||
41 | #elif defined(VMS) | 49 | #elif defined(VMS) |
50 | |||
42 | #include <types.h> | 51 | #include <types.h> |
43 | #include <socket.h> | 52 | #include <socket.h> |
44 | #include <in.h> | 53 | #include <in.h> |
45 | #include <netdb.h> | 54 | #include <netdb.h> |
46 | #include <inet.h> | 55 | #include <inet.h> |
56 | |||
47 | #elif defined(_WIN32) | 57 | #elif defined(_WIN32) |
58 | |||
48 | #include <winsock.h> | 59 | #include <winsock.h> |
60 | |||
49 | #endif | 61 | #endif |
50 | 62 | ||
51 | #define BUILDING_LIBRARY | 63 | #define BUILDING_LIBRARY |
@@ -58,7 +70,7 @@ | |||
58 | #endif | 70 | #endif |
59 | 71 | ||
60 | #define FTPLIB_BUFSIZ 8192 | 72 | #define FTPLIB_BUFSIZ 8192 |
61 | #define ACCEPT_TIMEOUT 15 | 73 | #define ACCEPT_TIMEOUT 10 |
62 | 74 | ||
63 | #define FTPLIB_CONTROL 0 | 75 | #define FTPLIB_CONTROL 0 |
64 | #define FTPLIB_READ 1 | 76 | #define FTPLIB_READ 1 |
@@ -87,7 +99,7 @@ struct NetBuf { | |||
87 | }; | 99 | }; |
88 | 100 | ||
89 | static char *version = | 101 | static char *version = |
90 | "ftplib Release 3.1-1 9/16/00, copyright 1996-2000 Thomas Pfau"; | 102 | "ftplib Release 3.1-1 9/16/00, copyright 1996-2000 Thomas Pfau"; |
91 | 103 | ||
92 | GLOBALDEF int ftplib_debug = 0; | 104 | GLOBALDEF int ftplib_debug = 0; |
93 | 105 | ||
@@ -112,13 +124,13 @@ void *memccpy(void *dest, const void *src, int c, size_t n) | |||
112 | unsigned char *op=dest; | 124 | unsigned char *op=dest; |
113 | 125 | ||
114 | while (i < n) | 126 | while (i < n) |
115 | { | 127 | { |
116 | if ((*op++ = *ip++) == c) | 128 | if ((*op++ = *ip++) == c) |
117 | break; | 129 | break; |
118 | i++; | 130 | i++; |
119 | } | 131 | } |
120 | if (i == n) | 132 | if (i == n) |
121 | return NULL; | 133 | return NULL; |
122 | return op; | 134 | return op; |
123 | } | 135 | } |
124 | #endif | 136 | #endif |
@@ -148,30 +160,30 @@ static int socket_wait(netbuf *ctl) | |||
148 | struct timeval tv; | 160 | struct timeval tv; |
149 | int rv = 0; | 161 | int rv = 0; |
150 | if ((ctl->dir == FTPLIB_CONTROL) || (ctl->idlecb == NULL)) | 162 | if ((ctl->dir == FTPLIB_CONTROL) || (ctl->idlecb == NULL)) |
151 | return 1; | 163 | return 1; |
152 | if (ctl->dir == FTPLIB_WRITE) | 164 | if (ctl->dir == FTPLIB_WRITE) |
153 | wfd = &fd; | 165 | wfd = &fd; |
154 | else | 166 | else |
155 | rfd = &fd; | 167 | rfd = &fd; |
156 | FD_ZERO(&fd); | 168 | FD_ZERO(&fd); |
157 | do | 169 | do |
158 | { | 170 | { |
159 | FD_SET(ctl->handle,&fd); | 171 | FD_SET(ctl->handle,&fd); |
160 | tv = ctl->idletime; | 172 | tv = ctl->idletime; |
161 | rv = select(ctl->handle+1, rfd, wfd, NULL, &tv); | 173 | rv = select(ctl->handle+1, rfd, wfd, NULL, &tv); |
162 | if (rv == -1) | 174 | if (rv == -1) |
163 | { | 175 | { |
164 | rv = 0; | 176 | rv = 0; |
165 | strncpy(ctl->ctrl->response, strerror(errno), | 177 | strncpy(ctl->ctrl->response, strerror(errno), |
166 | sizeof(ctl->ctrl->response)); | 178 | sizeof(ctl->ctrl->response)); |
167 | break; | 179 | break; |
168 | } | 180 | } |
169 | else if (rv > 0) | 181 | else if (rv > 0) |
170 | { | 182 | { |
171 | rv = 1; | 183 | rv = 1; |
172 | break; | 184 | break; |
173 | } | 185 | } |
174 | } | 186 | } |
175 | while ((rv = ctl->idlecb(ctl, ctl->xfered, ctl->idlearg))); | 187 | while ((rv = ctl->idlecb(ctl, ctl->xfered, ctl->idlearg))); |
176 | return rv; | 188 | return rv; |
177 | } | 189 | } |
@@ -188,66 +200,66 @@ static int readline(char *buf,int max,netbuf *ctl) | |||
188 | int eof = 0; | 200 | int eof = 0; |
189 | 201 | ||
190 | if ((ctl->dir != FTPLIB_CONTROL) && (ctl->dir != FTPLIB_READ)) | 202 | if ((ctl->dir != FTPLIB_CONTROL) && (ctl->dir != FTPLIB_READ)) |
191 | return -1; | 203 | return -1; |
192 | if (max == 0) | 204 | if (max == 0) |
193 | return 0; | 205 | return 0; |
194 | do | 206 | do |
195 | { | ||
196 | if (ctl->cavail > 0) | ||
197 | { | ||
198 | x = (max >= ctl->cavail) ? ctl->cavail : max-1; | ||
199 | end = memccpy(bp,ctl->cget,'\n',x); | ||
200 | if (end != NULL) | ||
201 | x = end - bp; | ||
202 | retval += x; | ||
203 | bp += x; | ||
204 | *bp = '\0'; | ||
205 | max -= x; | ||
206 | ctl->cget += x; | ||
207 | ctl->cavail -= x; | ||
208 | if (end != NULL) | ||
209 | { | ||
210 | bp -= 2; | ||
211 | if (strcmp(bp,"\r\n") == 0) | ||
212 | { | ||
213 | *bp++ = '\n'; | ||
214 | *bp++ = '\0'; | ||
215 | --retval; | ||
216 | } | ||
217 | break; | ||
218 | } | ||
219 | } | ||
220 | if (max == 1) | ||
221 | { | 207 | { |
222 | *buf = '\0'; | 208 | if (ctl->cavail > 0) |
223 | break; | 209 | { |
210 | x = (max >= ctl->cavail) ? ctl->cavail : max-1; | ||
211 | end = memccpy(bp,ctl->cget,'\n',x); | ||
212 | if (end != NULL) | ||
213 | x = end - bp; | ||
214 | retval += x; | ||
215 | bp += x; | ||
216 | *bp = '\0'; | ||
217 | max -= x; | ||
218 | ctl->cget += x; | ||
219 | ctl->cavail -= x; | ||
220 | if (end != NULL) | ||
221 | { | ||
222 | bp -= 2; | ||
223 | if (strcmp(bp,"\r\n") == 0) | ||
224 | { | ||
225 | *bp++ = '\n'; | ||
226 | *bp++ = '\0'; | ||
227 | --retval; | ||
228 | } | ||
229 | break; | ||
230 | } | ||
231 | } | ||
232 | if (max == 1) | ||
233 | { | ||
234 | *buf = '\0'; | ||
235 | break; | ||
236 | } | ||
237 | if (ctl->cput == ctl->cget) | ||
238 | { | ||
239 | ctl->cput = ctl->cget = ctl->buf; | ||
240 | ctl->cavail = 0; | ||
241 | ctl->cleft = FTPLIB_BUFSIZ; | ||
242 | } | ||
243 | if (eof) | ||
244 | { | ||
245 | if (retval == 0) | ||
246 | retval = -1; | ||
247 | break; | ||
248 | } | ||
249 | if (!socket_wait(ctl)) | ||
250 | return retval; | ||
251 | if ((x = net_read(ctl->handle,ctl->cput,ctl->cleft)) == -1) | ||
252 | { | ||
253 | perror("read"); | ||
254 | retval = -1; | ||
255 | break; | ||
256 | } | ||
257 | if (x == 0) | ||
258 | eof = 1; | ||
259 | ctl->cleft -= x; | ||
260 | ctl->cavail += x; | ||
261 | ctl->cput += x; | ||
224 | } | 262 | } |
225 | if (ctl->cput == ctl->cget) | ||
226 | { | ||
227 | ctl->cput = ctl->cget = ctl->buf; | ||
228 | ctl->cavail = 0; | ||
229 | ctl->cleft = FTPLIB_BUFSIZ; | ||
230 | } | ||
231 | if (eof) | ||
232 | { | ||
233 | if (retval == 0) | ||
234 | retval = -1; | ||
235 | break; | ||
236 | } | ||
237 | if (!socket_wait(ctl)) | ||
238 | return retval; | ||
239 | if ((x = net_read(ctl->handle,ctl->cput,ctl->cleft)) == -1) | ||
240 | { | ||
241 | perror("read"); | ||
242 | retval = -1; | ||
243 | break; | ||
244 | } | ||
245 | if (x == 0) | ||
246 | eof = 1; | ||
247 | ctl->cleft -= x; | ||
248 | ctl->cavail += x; | ||
249 | ctl->cput += x; | ||
250 | } | ||
251 | while (1); | 263 | while (1); |
252 | return retval; | 264 | return retval; |
253 | } | 265 | } |
@@ -264,51 +276,51 @@ static int writeline(char *buf, int len, netbuf *nData) | |||
264 | char lc=0; | 276 | char lc=0; |
265 | 277 | ||
266 | if (nData->dir != FTPLIB_WRITE) | 278 | if (nData->dir != FTPLIB_WRITE) |
267 | return -1; | 279 | return -1; |
268 | nbp = nData->buf; | 280 | nbp = nData->buf; |
269 | for (x=0; x < len; x++) | 281 | for (x=0; x < len; x++) |
270 | { | ||
271 | if ((*ubp == '\n') && (lc != '\r')) | ||
272 | { | ||
273 | if (nb == FTPLIB_BUFSIZ) | ||
274 | { | 282 | { |
275 | if (!socket_wait(nData)) | 283 | if ((*ubp == '\n') && (lc != '\r')) |
276 | return x; | 284 | { |
277 | w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ); | 285 | if (nb == FTPLIB_BUFSIZ) |
278 | if (w != FTPLIB_BUFSIZ) | 286 | { |
279 | { | 287 | if (!socket_wait(nData)) |
280 | printf("net_write(1) returned %d, errno = %d\n", w, errno); | 288 | return x; |
281 | return(-1); | 289 | w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ); |
282 | } | 290 | if (w != FTPLIB_BUFSIZ) |
283 | nb = 0; | 291 | { |
292 | printf("net_write(1) returned %d, errno = %d\n", w, errno); | ||
293 | return(-1); | ||
294 | } | ||
295 | nb = 0; | ||
296 | } | ||
297 | nbp[nb++] = '\r'; | ||
298 | } | ||
299 | if (nb == FTPLIB_BUFSIZ) | ||
300 | { | ||
301 | if (!socket_wait(nData)) | ||
302 | return x; | ||
303 | w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ); | ||
304 | if (w != FTPLIB_BUFSIZ) | ||
305 | { | ||
306 | printf("net_write(2) returned %d, errno = %d\n", w, errno); | ||
307 | return(-1); | ||
308 | } | ||
309 | nb = 0; | ||
310 | } | ||
311 | nbp[nb++] = lc = *ubp++; | ||
284 | } | 312 | } |
285 | nbp[nb++] = '\r'; | 313 | if (nb) |
286 | } | ||
287 | if (nb == FTPLIB_BUFSIZ) | ||
288 | { | ||
289 | if (!socket_wait(nData)) | ||
290 | return x; | ||
291 | w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ); | ||
292 | if (w != FTPLIB_BUFSIZ) | ||
293 | { | 314 | { |
294 | printf("net_write(2) returned %d, errno = %d\n", w, errno); | 315 | if (!socket_wait(nData)) |
295 | return(-1); | 316 | return x; |
317 | w = net_write(nData->handle, nbp, nb); | ||
318 | if (w != nb) | ||
319 | { | ||
320 | printf("net_write(3) returned %d, errno = %d\n", w, errno); | ||
321 | return(-1); | ||
322 | } | ||
296 | } | 323 | } |
297 | nb = 0; | ||
298 | } | ||
299 | nbp[nb++] = lc = *ubp++; | ||
300 | } | ||
301 | if (nb) | ||
302 | { | ||
303 | if (!socket_wait(nData)) | ||
304 | return x; | ||
305 | w = net_write(nData->handle, nbp, nb); | ||
306 | if (w != nb) | ||
307 | { | ||
308 | printf("net_write(3) returned %d, errno = %d\n", w, errno); | ||
309 | return(-1); | ||
310 | } | ||
311 | } | ||
312 | return len; | 324 | return len; |
313 | } | 325 | } |
314 | 326 | ||
@@ -322,31 +334,31 @@ static int readresp(char c, netbuf *nControl) | |||
322 | { | 334 | { |
323 | char match[5]; | 335 | char match[5]; |
324 | if (readline(nControl->response,256,nControl) == -1) | 336 | if (readline(nControl->response,256,nControl) == -1) |
325 | { | 337 | { |
326 | perror("Control socket read failed"); | 338 | perror("Control socket read failed"); |
327 | return 0; | 339 | return 0; |
328 | } | 340 | } |
329 | if (ftplib_debug > 1) | 341 | if (ftplib_debug > 1) |
330 | fprintf(stderr,"%s",nControl->response); | 342 | fprintf(stderr,"%s",nControl->response); |
331 | if (nControl->response[3] == '-') | 343 | if (nControl->response[3] == '-') |
332 | { | ||
333 | strncpy(match,nControl->response,3); | ||
334 | match[3] = ' '; | ||
335 | match[4] = '\0'; | ||
336 | do | ||
337 | { | ||
338 | if (readline(nControl->response,256,nControl) == -1) | ||
339 | { | 344 | { |
340 | perror("Control socket read failed"); | 345 | strncpy(match,nControl->response,3); |
341 | return 0; | 346 | match[3] = ' '; |
347 | match[4] = '\0'; | ||
348 | do | ||
349 | { | ||
350 | if (readline(nControl->response,256,nControl) == -1) | ||
351 | { | ||
352 | perror("Control socket read failed"); | ||
353 | return 0; | ||
354 | } | ||
355 | if (ftplib_debug > 1) | ||
356 | fprintf(stderr,"%s",nControl->response); | ||
357 | } | ||
358 | while (strncmp(nControl->response,match,4)); | ||
342 | } | 359 | } |
343 | if (ftplib_debug > 1) | ||
344 | fprintf(stderr,"%s",nControl->response); | ||
345 | } | ||
346 | while (strncmp(nControl->response,match,4)); | ||
347 | } | ||
348 | if (nControl->response[0] == c) | 360 | if (nControl->response[0] == c) |
349 | return 1; | 361 | return 1; |
350 | return 0; | 362 | return 0; |
351 | } | 363 | } |
352 | 364 | ||
@@ -361,7 +373,7 @@ GLOBALDEF void FtpInit(void) | |||
361 | int err; | 373 | int err; |
362 | wVersionRequested = MAKEWORD(1,1); | 374 | wVersionRequested = MAKEWORD(1,1); |
363 | if ((err = WSAStartup(wVersionRequested,&wsadata)) != 0) | 375 | if ((err = WSAStartup(wVersionRequested,&wsadata)) != 0) |
364 | fprintf(stderr,"Network failed to start: %d\n",err); | 376 | fprintf(stderr,"Network failed to start: %d\n",err); |
365 | #endif | 377 | #endif |
366 | } | 378 | } |
367 | 379 | ||
@@ -371,7 +383,7 @@ GLOBALDEF void FtpInit(void) | |||
371 | GLOBALDEF char *FtpLastResponse(netbuf *nControl) | 383 | GLOBALDEF char *FtpLastResponse(netbuf *nControl) |
372 | { | 384 | { |
373 | if ((nControl) && (nControl->dir == FTPLIB_CONTROL)) | 385 | if ((nControl) && (nControl->dir == FTPLIB_CONTROL)) |
374 | return nControl->response; | 386 | return nControl->response; |
375 | return NULL; | 387 | return NULL; |
376 | } | 388 | } |
377 | 389 | ||
@@ -382,7 +394,7 @@ GLOBALDEF char *FtpLastResponse(netbuf *nControl) | |||
382 | */ | 394 | */ |
383 | GLOBALDEF int FtpConnect(const char *host, netbuf **nControl) | 395 | GLOBALDEF int FtpConnect(const char *host, netbuf **nControl) |
384 | { | 396 | { |
385 | int sControl; | 397 | int sControl, stat, flags, oldflags; |
386 | struct sockaddr_in sin; | 398 | struct sockaddr_in sin; |
387 | struct hostent *phe; | 399 | struct hostent *phe; |
388 | struct servent *pse; | 400 | struct servent *pse; |
@@ -390,79 +402,118 @@ GLOBALDEF int FtpConnect(const char *host, netbuf **nControl) | |||
390 | netbuf *ctrl; | 402 | netbuf *ctrl; |
391 | char *lhost; | 403 | char *lhost; |
392 | char *pnum; | 404 | char *pnum; |
405 | struct timeval tv; | ||
406 | fd_set wr; | ||
393 | 407 | ||
394 | memset(&sin,0,sizeof(sin)); | 408 | memset(&sin,0,sizeof(sin)); |
395 | sin.sin_family = AF_INET; | 409 | sin.sin_family = AF_INET; |
396 | lhost = strdup(host); | 410 | lhost = strdup(host); |
397 | pnum = strchr(lhost,':'); | 411 | pnum = strchr(lhost,':'); |
398 | if (pnum == NULL) | 412 | if (pnum == NULL) |
399 | { | 413 | { |
400 | #if defined(VMS) | 414 | #if defined(VMS) |
401 | sin.sin_port = htons(21); | 415 | sin.sin_port = htons(21); |
402 | #else | 416 | #else |
403 | if ((pse = getservbyname("ftp","tcp")) == NULL) | 417 | if ((pse = getservbyname("ftp","tcp")) == NULL) |
404 | { | 418 | { |
405 | perror("getservbyname"); | 419 | perror("getservbyname"); |
406 | return 0; | 420 | return 0; |
407 | } | 421 | } |
408 | sin.sin_port = pse->s_port; | 422 | sin.sin_port = pse->s_port; |
409 | #endif | 423 | #endif |
410 | } | 424 | } |
411 | else | 425 | else |
412 | { | 426 | { |
413 | *pnum++ = '\0'; | 427 | *pnum++ = '\0'; |
414 | if (isdigit(*pnum)) | 428 | if (isdigit(*pnum)) |
415 | sin.sin_port = htons(atoi(pnum)); | 429 | sin.sin_port = htons(atoi(pnum)); |
416 | else | 430 | else |
417 | { | 431 | { |
418 | pse = getservbyname(pnum,"tcp"); | 432 | pse = getservbyname(pnum,"tcp"); |
419 | sin.sin_port = pse->s_port; | 433 | sin.sin_port = pse->s_port; |
420 | } | 434 | } |
421 | } | 435 | } |
422 | if ((sin.sin_addr.s_addr = inet_addr(lhost)) == -1) | 436 | if ((sin.sin_addr.s_addr = inet_addr(lhost)) == -1) |
423 | { | ||
424 | if ((phe = gethostbyname(lhost)) == NULL) | ||
425 | { | 437 | { |
426 | perror("gethostbyname"); | 438 | if ((phe = gethostbyname(lhost)) == NULL) |
427 | return 0; | 439 | { |
440 | perror("gethostbyname"); | ||
441 | return 0; | ||
442 | } | ||
443 | |||
444 | memcpy((char *)&sin.sin_addr, phe->h_addr, phe->h_length); | ||
445 | |||
428 | } | 446 | } |
429 | memcpy((char *)&sin.sin_addr, phe->h_addr, phe->h_length); | ||
430 | } | ||
431 | free(lhost); | 447 | free(lhost); |
448 | |||
432 | sControl = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); | 449 | sControl = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); |
433 | if (sControl == -1) | 450 | if (sControl == -1) |
434 | { | 451 | { |
435 | perror("socket"); | 452 | perror("socket"); |
436 | return 0; | 453 | return 0; |
437 | } | 454 | } |
438 | if (setsockopt(sControl,SOL_SOCKET,SO_REUSEADDR, | 455 | |
439 | SETSOCKOPT_OPTVAL_TYPE &on, sizeof(on)) == -1) | 456 | if ( setsockopt(sControl,SOL_SOCKET,SO_REUSEADDR, |
440 | { | 457 | SETSOCKOPT_OPTVAL_TYPE &on, sizeof(on)) == -1) |
441 | perror("setsockopt"); | 458 | { |
442 | net_close(sControl); | 459 | perror("setsockopt"); |
443 | return 0; | 460 | net_close(sControl); |
444 | } | 461 | return 0; |
445 | if (connect(sControl, (struct sockaddr *)&sin, sizeof(sin)) == -1) | 462 | } |
446 | { | 463 | |
447 | perror("connect"); | 464 | //set nonblocking for connection timeout |
448 | net_close(sControl); | 465 | flags = fcntl( sControl, F_GETFL,0); |
449 | return 0; | 466 | oldflags=flags; |
450 | } | 467 | fcntl( sControl, F_SETFL, O_NONBLOCK|flags); |
468 | |||
469 | stat=connect( sControl, (struct sockaddr *)&sin, sizeof(sin)); | ||
470 | if (stat < 0) | ||
471 | { | ||
472 | if (errno != EWOULDBLOCK && errno != EINPROGRESS) | ||
473 | { | ||
474 | perror("connect"); | ||
475 | net_close(sControl); | ||
476 | return 0; | ||
477 | } | ||
478 | } | ||
479 | |||
480 | FD_ZERO(&wr); | ||
481 | FD_SET( sControl, &wr); | ||
482 | |||
483 | tv.tv_sec = ACCEPT_TIMEOUT; | ||
484 | tv.tv_usec = 0; | ||
485 | |||
486 | stat = select(sControl+1, 0, &wr, 0, &tv); | ||
487 | |||
488 | if (stat < 1) | ||
489 | { | ||
490 | // time out has expired, | ||
491 | // or an error has ocurred | ||
492 | perror("timeout"); | ||
493 | net_close(sControl); | ||
494 | return 0; | ||
495 | } | ||
496 | |||
497 | printf("connected\n"); | ||
498 | |||
499 | //set original flags | ||
500 | fcntl( sControl, F_SETFL, oldflags); | ||
501 | |||
451 | ctrl = calloc(1,sizeof(netbuf)); | 502 | ctrl = calloc(1,sizeof(netbuf)); |
452 | if (ctrl == NULL) | 503 | if (ctrl == NULL) |
453 | { | 504 | { |
454 | perror("calloc"); | 505 | perror("calloc"); |
455 | net_close(sControl); | 506 | net_close(sControl); |
456 | return 0; | 507 | return 0; |
457 | } | 508 | } |
458 | ctrl->buf = malloc(FTPLIB_BUFSIZ); | 509 | ctrl->buf = malloc(FTPLIB_BUFSIZ); |
459 | if (ctrl->buf == NULL) | 510 | if (ctrl->buf == NULL) |
460 | { | 511 | { |
461 | perror("calloc"); | 512 | perror("calloc"); |
462 | net_close(sControl); | 513 | net_close(sControl); |
463 | free(ctrl); | 514 | free(ctrl); |
464 | return 0; | 515 | return 0; |
465 | } | 516 | } |
466 | ctrl->handle = sControl; | 517 | ctrl->handle = sControl; |
467 | ctrl->dir = FTPLIB_CONTROL; | 518 | ctrl->dir = FTPLIB_CONTROL; |
468 | ctrl->ctrl = NULL; | 519 | ctrl->ctrl = NULL; |
@@ -474,12 +525,12 @@ GLOBALDEF int FtpConnect(const char *host, netbuf **nControl) | |||
474 | ctrl->xfered1 = 0; | 525 | ctrl->xfered1 = 0; |
475 | ctrl->cbbytes = 0; | 526 | ctrl->cbbytes = 0; |
476 | if (readresp('2', ctrl) == 0) | 527 | if (readresp('2', ctrl) == 0) |
477 | { | 528 | { |
478 | net_close(sControl); | 529 | net_close(sControl); |
479 | free(ctrl->buf); | 530 | free(ctrl->buf); |
480 | free(ctrl); | 531 | free(ctrl); |
481 | return 0; | 532 | return 0; |
482 | } | 533 | } |
483 | *nControl = ctrl; | 534 | *nControl = ctrl; |
484 | return 1; | 535 | return 1; |
485 | } | 536 | } |
@@ -493,34 +544,34 @@ GLOBALDEF int FtpOptions(int opt, long val, netbuf *nControl) | |||
493 | { | 544 | { |
494 | int v,rv=0; | 545 | int v,rv=0; |
495 | switch (opt) | 546 | switch (opt) |
496 | { | 547 | { |
497 | case FTPLIB_CONNMODE: | 548 | case FTPLIB_CONNMODE: |
498 | v = (int) val; | 549 | v = (int) val; |
499 | if ((v == FTPLIB_PASSIVE) || (v == FTPLIB_PORT)) | 550 | if ((v == FTPLIB_PASSIVE) || (v == FTPLIB_PORT)) |
500 | { | 551 | { |
501 | nControl->cmode = v; | 552 | nControl->cmode = v; |
502 | rv = 1; | 553 | rv = 1; |
503 | } | 554 | } |
504 | break; | 555 | break; |
505 | case FTPLIB_CALLBACK: | 556 | case FTPLIB_CALLBACK: |
506 | nControl->idlecb = (FtpCallback) val; | 557 | nControl->idlecb = (FtpCallback) val; |
507 | rv = 1; | 558 | rv = 1; |
508 | break; | 559 | break; |
509 | case FTPLIB_IDLETIME: | 560 | case FTPLIB_IDLETIME: |
510 | v = (int) val; | 561 | v = (int) val; |
511 | rv = 1; | 562 | rv = 1; |
512 | nControl->idletime.tv_sec = v / 1000; | 563 | nControl->idletime.tv_sec = v / 1000; |
513 | nControl->idletime.tv_usec = (v % 1000) * 1000; | 564 | nControl->idletime.tv_usec = (v % 1000) * 1000; |
514 | break; | 565 | break; |
515 | case FTPLIB_CALLBACKARG: | 566 | case FTPLIB_CALLBACKARG: |
516 | rv = 1; | 567 | rv = 1; |
517 | nControl->idlearg = (void *) val; | 568 | nControl->idlearg = (void *) val; |
518 | break; | 569 | break; |
519 | case FTPLIB_CALLBACKBYTES: | 570 | case FTPLIB_CALLBACKBYTES: |
520 | rv = 1; | 571 | rv = 1; |
521 | nControl->cbbytes = (int) val; | 572 | nControl->cbbytes = (int) val; |
522 | break; | 573 | break; |
523 | } | 574 | } |
524 | return rv; | 575 | return rv; |
525 | } | 576 | } |
526 | 577 | ||
@@ -533,17 +584,17 @@ static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl) | |||
533 | { | 584 | { |
534 | char buf[256]; | 585 | char buf[256]; |
535 | if (nControl->dir != FTPLIB_CONTROL) | 586 | if (nControl->dir != FTPLIB_CONTROL) |
536 | return 0; | 587 | return 0; |
537 | if (ftplib_debug > 2) | 588 | if (ftplib_debug > 2) |
538 | fprintf(stderr,"%s\n",cmd); | 589 | fprintf(stderr,"%s\n",cmd); |
539 | if ((strlen(cmd) + 3) > sizeof(buf)) | 590 | if ((strlen(cmd) + 3) > sizeof(buf)) |
540 | return 0; | 591 | return 0; |
541 | sprintf(buf,"%s\r\n",cmd); | 592 | sprintf(buf,"%s\r\n",cmd); |
542 | if (net_write(nControl->handle,buf,strlen(buf)) <= 0) | 593 | if (net_write(nControl->handle,buf,strlen(buf)) <= 0) |
543 | { | 594 | { |
544 | perror("write"); | 595 | perror("write"); |
545 | return 0; | 596 | return 0; |
546 | } | 597 | } |
547 | return readresp(expresp, nControl); | 598 | return readresp(expresp, nControl); |
548 | } | 599 | } |
549 | 600 | ||
@@ -561,11 +612,11 @@ GLOBALDEF int FtpLogin(const char *user, const char *pass, netbuf *nControl) | |||
561 | return 0; | 612 | return 0; |
562 | sprintf(tempbuf,"USER %s",user); | 613 | sprintf(tempbuf,"USER %s",user); |
563 | if (!FtpSendCmd(tempbuf,'3',nControl)) | 614 | if (!FtpSendCmd(tempbuf,'3',nControl)) |
564 | { | 615 | { |
565 | if (nControl->response[0] == '2') | 616 | if (nControl->response[0] == '2') |
566 | return 1; | 617 | return 1; |
567 | return 0; | 618 | return 0; |
568 | } | 619 | } |
569 | sprintf(tempbuf,"PASS %s",pass); | 620 | sprintf(tempbuf,"PASS %s",pass); |
570 | return FtpSendCmd(tempbuf,'2',nControl); | 621 | return FtpSendCmd(tempbuf,'2',nControl); |
571 | } | 622 | } |
@@ -579,8 +630,8 @@ static int FtpOpenPort(netbuf *nControl, netbuf **nData, int mode, int dir) | |||
579 | { | 630 | { |
580 | int sData; | 631 | int sData; |
581 | union { | 632 | union { |
582 | struct sockaddr sa; | 633 | struct sockaddr sa; |
583 | struct sockaddr_in in; | 634 | struct sockaddr_in in; |
584 | } sin; | 635 | } sin; |
585 | struct linger lng = { 0, 0 }; | 636 | struct linger lng = { 0, 0 }; |
586 | unsigned int l; | 637 | unsigned int l; |
@@ -591,117 +642,117 @@ static int FtpOpenPort(netbuf *nControl, netbuf **nData, int mode, int dir) | |||
591 | char buf[256]; | 642 | char buf[256]; |
592 | 643 | ||
593 | if (nControl->dir != FTPLIB_CONTROL) | 644 | if (nControl->dir != FTPLIB_CONTROL) |
594 | return -1; | 645 | return -1; |
595 | if ((dir != FTPLIB_READ) && (dir != FTPLIB_WRITE)) | 646 | if ((dir != FTPLIB_READ) && (dir != FTPLIB_WRITE)) |
596 | { | 647 | { |
597 | sprintf(nControl->response, "Invalid direction %d\n", dir); | 648 | sprintf(nControl->response, "Invalid direction %d\n", dir); |
598 | return -1; | 649 | return -1; |
599 | } | 650 | } |
600 | if ((mode != FTPLIB_ASCII) && (mode != FTPLIB_IMAGE)) | 651 | if ((mode != FTPLIB_ASCII) && (mode != FTPLIB_IMAGE)) |
601 | { | 652 | { |
602 | sprintf(nControl->response, "Invalid mode %c\n", mode); | 653 | sprintf(nControl->response, "Invalid mode %c\n", mode); |
603 | return -1; | 654 | return -1; |
604 | } | 655 | } |
605 | l = sizeof(sin); | 656 | l = sizeof(sin); |
606 | if (nControl->cmode == FTPLIB_PASSIVE) | 657 | if (nControl->cmode == FTPLIB_PASSIVE) |
607 | { | 658 | { |
608 | memset(&sin, 0, l); | 659 | memset(&sin, 0, l); |
609 | sin.in.sin_family = AF_INET; | 660 | sin.in.sin_family = AF_INET; |
610 | if (!FtpSendCmd("PASV",'2',nControl)) | 661 | if (!FtpSendCmd("PASV",'2',nControl)) |
611 | return -1; | 662 | return -1; |
612 | cp = strchr(nControl->response,'('); | 663 | cp = strchr(nControl->response,'('); |
613 | if (cp == NULL) | 664 | if (cp == NULL) |
614 | return -1; | 665 | return -1; |
615 | cp++; | 666 | cp++; |
616 | sscanf(cp,"%u,%u,%u,%u,%u,%u",&v[2],&v[3],&v[4],&v[5],&v[0],&v[1]); | 667 | sscanf(cp,"%u,%u,%u,%u,%u,%u",&v[2],&v[3],&v[4],&v[5],&v[0],&v[1]); |
617 | sin.sa.sa_data[2] = v[2]; | 668 | sin.sa.sa_data[2] = v[2]; |
618 | sin.sa.sa_data[3] = v[3]; | 669 | sin.sa.sa_data[3] = v[3]; |
619 | sin.sa.sa_data[4] = v[4]; | 670 | sin.sa.sa_data[4] = v[4]; |
620 | sin.sa.sa_data[5] = v[5]; | 671 | sin.sa.sa_data[5] = v[5]; |
621 | sin.sa.sa_data[0] = v[0]; | 672 | sin.sa.sa_data[0] = v[0]; |
622 | sin.sa.sa_data[1] = v[1]; | 673 | sin.sa.sa_data[1] = v[1]; |
623 | } | 674 | } |
624 | else | 675 | else |
625 | { | 676 | { |
626 | if (getsockname(nControl->handle, &sin.sa, &l) < 0) | 677 | if (getsockname(nControl->handle, &sin.sa, &l) < 0) |
627 | { | 678 | { |
628 | perror("getsockname"); | 679 | perror("getsockname"); |
629 | return 0; | 680 | return 0; |
630 | } | 681 | } |
631 | } | 682 | } |
632 | sData = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP); | 683 | sData = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP); |
633 | if (sData == -1) | 684 | if (sData == -1) |
634 | { | 685 | { |
635 | perror("socket"); | 686 | perror("socket"); |
636 | return -1; | 687 | return -1; |
637 | } | 688 | } |
638 | if (setsockopt(sData,SOL_SOCKET,SO_REUSEADDR, | 689 | if (setsockopt(sData,SOL_SOCKET,SO_REUSEADDR, |
639 | SETSOCKOPT_OPTVAL_TYPE &on,sizeof(on)) == -1) | 690 | SETSOCKOPT_OPTVAL_TYPE &on,sizeof(on)) == -1) |
640 | { | 691 | { |
641 | perror("setsockopt"); | 692 | perror("setsockopt"); |
642 | net_close(sData); | 693 | net_close(sData); |
643 | return -1; | 694 | return -1; |
644 | } | 695 | } |
645 | if (setsockopt(sData,SOL_SOCKET,SO_LINGER, | 696 | if (setsockopt(sData,SOL_SOCKET,SO_LINGER, |
646 | SETSOCKOPT_OPTVAL_TYPE &lng,sizeof(lng)) == -1) | 697 | SETSOCKOPT_OPTVAL_TYPE &lng,sizeof(lng)) == -1) |
647 | { | 698 | { |
648 | perror("setsockopt"); | 699 | perror("setsockopt"); |
649 | net_close(sData); | 700 | net_close(sData); |
650 | return -1; | 701 | return -1; |
651 | } | 702 | } |
652 | if (nControl->cmode == FTPLIB_PASSIVE) | 703 | if (nControl->cmode == FTPLIB_PASSIVE) |
653 | { | 704 | { |
654 | if (connect(sData, &sin.sa, sizeof(sin.sa)) == -1) | 705 | if (connect(sData, &sin.sa, sizeof(sin.sa)) == -1) |
655 | { | 706 | { |
656 | perror("connect"); | 707 | perror("connect"); |
657 | net_close(sData); | 708 | net_close(sData); |
658 | return -1; | 709 | return -1; |
659 | } | 710 | } |
660 | } | 711 | } |
661 | else | 712 | else |
662 | { | 713 | { |
663 | sin.in.sin_port = 0; | 714 | sin.in.sin_port = 0; |
664 | if (bind(sData, &sin.sa, sizeof(sin)) == -1) | 715 | if (bind(sData, &sin.sa, sizeof(sin)) == -1) |
665 | { | 716 | { |
666 | perror("bind"); | 717 | perror("bind"); |
667 | net_close(sData); | 718 | net_close(sData); |
668 | return 0; | 719 | return 0; |
669 | } | 720 | } |
670 | if (listen(sData, 1) < 0) | 721 | if (listen(sData, 1) < 0) |
671 | { | 722 | { |
672 | perror("listen"); | 723 | perror("listen"); |
673 | net_close(sData); | 724 | net_close(sData); |
674 | return 0; | 725 | return 0; |
675 | } | 726 | } |
676 | if (getsockname(sData, &sin.sa, &l) < 0) | 727 | if (getsockname(sData, &sin.sa, &l) < 0) |
677 | return 0; | 728 | return 0; |
678 | sprintf(buf, "PORT %d,%d,%d,%d,%d,%d", | 729 | sprintf(buf, "PORT %d,%d,%d,%d,%d,%d", |
679 | (unsigned char) sin.sa.sa_data[2], | 730 | (unsigned char) sin.sa.sa_data[2], |
680 | (unsigned char) sin.sa.sa_data[3], | 731 | (unsigned char) sin.sa.sa_data[3], |
681 | (unsigned char) sin.sa.sa_data[4], | 732 | (unsigned char) sin.sa.sa_data[4], |
682 | (unsigned char) sin.sa.sa_data[5], | 733 | (unsigned char) sin.sa.sa_data[5], |
683 | (unsigned char) sin.sa.sa_data[0], | 734 | (unsigned char) sin.sa.sa_data[0], |
684 | (unsigned char) sin.sa.sa_data[1]); | 735 | (unsigned char) sin.sa.sa_data[1]); |
685 | if (!FtpSendCmd(buf,'2',nControl)) | 736 | if (!FtpSendCmd(buf,'2',nControl)) |
686 | { | 737 | { |
687 | net_close(sData); | 738 | net_close(sData); |
688 | return 0; | 739 | return 0; |
689 | } | 740 | } |
690 | } | 741 | } |
691 | ctrl = calloc(1,sizeof(netbuf)); | 742 | ctrl = calloc(1,sizeof(netbuf)); |
692 | if (ctrl == NULL) | 743 | if (ctrl == NULL) |
693 | { | 744 | { |
694 | perror("calloc"); | 745 | perror("calloc"); |
695 | net_close(sData); | 746 | net_close(sData); |
696 | return -1; | 747 | return -1; |
697 | } | 748 | } |
698 | if ((mode == 'A') && ((ctrl->buf = malloc(FTPLIB_BUFSIZ)) == NULL)) | 749 | if ((mode == 'A') && ((ctrl->buf = malloc(FTPLIB_BUFSIZ)) == NULL)) |
699 | { | 750 | { |
700 | perror("calloc"); | 751 | perror("calloc"); |
701 | net_close(sData); | 752 | net_close(sData); |
702 | free(ctrl); | 753 | free(ctrl); |
703 | return -1; | 754 | return -1; |
704 | } | 755 | } |
705 | ctrl->handle = sData; | 756 | ctrl->handle = sData; |
706 | ctrl->dir = dir; | 757 | ctrl->dir = dir; |
707 | ctrl->idletime = nControl->idletime; | 758 | ctrl->idletime = nControl->idletime; |
@@ -710,9 +761,9 @@ static int FtpOpenPort(netbuf *nControl, netbuf **nData, int mode, int dir) | |||
710 | ctrl->xfered1 = 0; | 761 | ctrl->xfered1 = 0; |
711 | ctrl->cbbytes = nControl->cbbytes; | 762 | ctrl->cbbytes = nControl->cbbytes; |
712 | if (ctrl->idletime.tv_sec || ctrl->idletime.tv_usec || ctrl->cbbytes) | 763 | if (ctrl->idletime.tv_sec || ctrl->idletime.tv_usec || ctrl->cbbytes) |
713 | ctrl->idlecb = nControl->idlecb; | 764 | ctrl->idlecb = nControl->idlecb; |
714 | else | 765 | else |
715 | ctrl->idlecb = NULL; | 766 | ctrl->idlecb = NULL; |
716 | *nData = ctrl; | 767 | *nData = ctrl; |
717 | return 1; | 768 | return 1; |
718 | } | 769 | } |
@@ -737,54 +788,55 @@ static int FtpAcceptConnection(netbuf *nData, netbuf *nControl) | |||
737 | FD_SET(nData->handle, &mask); | 788 | FD_SET(nData->handle, &mask); |
738 | tv.tv_usec = 0; | 789 | tv.tv_usec = 0; |
739 | tv.tv_sec = ACCEPT_TIMEOUT; | 790 | tv.tv_sec = ACCEPT_TIMEOUT; |
791 | printf("<<<<<<<<<<<<<<<<%d\n",ACCEPT_TIMEOUT); | ||
740 | i = nControl->handle; | 792 | i = nControl->handle; |
741 | if (i < nData->handle) | 793 | if (i < nData->handle) |
742 | i = nData->handle; | 794 | i = nData->handle; |
743 | i = select(i+1, &mask, NULL, NULL, &tv); | 795 | i = select(i+1, &mask, NULL, NULL, &tv); |
744 | if (i == -1) | 796 | if (i == -1) |
745 | { | 797 | { |
746 | strncpy(nControl->response, strerror(errno), | 798 | strncpy(nControl->response, strerror(errno), |
747 | sizeof(nControl->response)); | 799 | sizeof(nControl->response)); |
748 | net_close(nData->handle); | 800 | net_close(nData->handle); |
749 | nData->handle = 0; | 801 | nData->handle = 0; |
750 | rv = 0; | 802 | rv = 0; |
751 | } | 803 | } |
752 | else if (i == 0) | 804 | else if (i == 0) |
753 | { | ||
754 | strcpy(nControl->response, "timed out waiting for connection"); | ||
755 | net_close(nData->handle); | ||
756 | nData->handle = 0; | ||
757 | rv = 0; | ||
758 | } | ||
759 | else | ||
760 | { | ||
761 | if (FD_ISSET(nData->handle, &mask)) | ||
762 | { | ||
763 | l = sizeof(addr); | ||
764 | sData = accept(nData->handle, &addr, &l); | ||
765 | i = errno; | ||
766 | net_close(nData->handle); | ||
767 | if (sData > 0) | ||
768 | { | 805 | { |
769 | rv = 1; | 806 | strcpy(nControl->response, "timed out waiting for connection"); |
770 | nData->handle = sData; | 807 | net_close(nData->handle); |
808 | nData->handle = 0; | ||
809 | rv = 0; | ||
771 | } | 810 | } |
772 | else | 811 | else |
773 | { | 812 | { |
774 | strncpy(nControl->response, strerror(i), | 813 | if (FD_ISSET(nData->handle, &mask)) |
775 | sizeof(nControl->response)); | 814 | { |
776 | nData->handle = 0; | 815 | l = sizeof(addr); |
777 | rv = 0; | 816 | sData = accept(nData->handle, &addr, &l); |
817 | i = errno; | ||
818 | net_close(nData->handle); | ||
819 | if (sData > 0) | ||
820 | { | ||
821 | rv = 1; | ||
822 | nData->handle = sData; | ||
823 | } | ||
824 | else | ||
825 | { | ||
826 | strncpy(nControl->response, strerror(i), | ||
827 | sizeof(nControl->response)); | ||
828 | nData->handle = 0; | ||
829 | rv = 0; | ||
830 | } | ||
831 | } | ||
832 | else if (FD_ISSET(nControl->handle, &mask)) | ||
833 | { | ||
834 | net_close(nData->handle); | ||
835 | nData->handle = 0; | ||
836 | readresp('2', nControl); | ||
837 | rv = 0; | ||
838 | } | ||
778 | } | 839 | } |
779 | } | ||
780 | else if (FD_ISSET(nControl->handle, &mask)) | ||
781 | { | ||
782 | net_close(nData->handle); | ||
783 | nData->handle = 0; | ||
784 | readresp('2', nControl); | ||
785 | rv = 0; | ||
786 | } | ||
787 | } | ||
788 | return rv; | 840 | return rv; |
789 | } | 841 | } |
790 | 842 | ||
@@ -794,70 +846,70 @@ static int FtpAcceptConnection(netbuf *nData, netbuf *nControl) | |||
794 | * return 1 if successful, 0 otherwise | 846 | * return 1 if successful, 0 otherwise |
795 | */ | 847 | */ |
796 | GLOBALDEF int FtpAccess(const char *path, int typ, int mode, netbuf *nControl, | 848 | GLOBALDEF int FtpAccess(const char *path, int typ, int mode, netbuf *nControl, |
797 | netbuf **nData) | 849 | netbuf **nData) |
798 | { | 850 | { |
799 | char buf[256]; | 851 | char buf[256]; |
800 | int dir; | 852 | int dir; |
801 | if ((path == NULL) && | 853 | if ((path == NULL) && |
802 | ((typ == FTPLIB_FILE_WRITE) || (typ == FTPLIB_FILE_READ))) | 854 | ((typ == FTPLIB_FILE_WRITE) || (typ == FTPLIB_FILE_READ))) |
803 | { | 855 | { |
804 | sprintf(nControl->response, | 856 | sprintf(nControl->response, |
805 | "Missing path argument for file transfer\n"); | 857 | "Missing path argument for file transfer\n"); |
806 | return 0; | 858 | return 0; |
807 | } | 859 | } |
808 | sprintf(buf, "TYPE %c", mode); | 860 | sprintf(buf, "TYPE %c", mode); |
809 | if (!FtpSendCmd(buf, '2', nControl)) | 861 | if (!FtpSendCmd(buf, '2', nControl)) |
810 | return 0; | 862 | return 0; |
811 | switch (typ) | 863 | switch (typ) |
812 | { | 864 | { |
813 | case FTPLIB_DIR: | 865 | case FTPLIB_DIR: |
814 | strcpy(buf,"NLST"); | 866 | strcpy(buf,"NLST"); |
815 | dir = FTPLIB_READ; | 867 | dir = FTPLIB_READ; |
816 | break; | 868 | break; |
817 | case FTPLIB_DIR_VERBOSE: | 869 | case FTPLIB_DIR_VERBOSE: |
818 | strcpy(buf,"LIST"); | 870 | strcpy(buf,"LIST"); |
819 | dir = FTPLIB_READ; | 871 | dir = FTPLIB_READ; |
820 | break; | 872 | break; |
821 | case FTPLIB_FILE_READ: | 873 | case FTPLIB_FILE_READ: |
822 | strcpy(buf,"RETR"); | 874 | strcpy(buf,"RETR"); |
823 | dir = FTPLIB_READ; | 875 | dir = FTPLIB_READ; |
824 | break; | 876 | break; |
825 | case FTPLIB_FILE_WRITE: | 877 | case FTPLIB_FILE_WRITE: |
826 | strcpy(buf,"STOR"); | 878 | strcpy(buf,"STOR"); |
827 | dir = FTPLIB_WRITE; | 879 | dir = FTPLIB_WRITE; |
828 | break; | 880 | break; |
829 | default: | 881 | default: |
830 | sprintf(nControl->response, "Invalid open type %d\n", typ); | 882 | sprintf(nControl->response, "Invalid open type %d\n", typ); |
831 | return 0; | ||
832 | } | ||
833 | if (path != NULL) | ||
834 | { | ||
835 | int i = strlen(buf); | ||
836 | buf[i++] = ' '; | ||
837 | if ((strlen(path) + i) >= sizeof(buf)) | ||
838 | return 0; | 883 | return 0; |
839 | strcpy(&buf[i],path); | 884 | } |
840 | } | 885 | if (path != NULL) |
886 | { | ||
887 | int i = strlen(buf); | ||
888 | buf[i++] = ' '; | ||
889 | if ((strlen(path) + i) >= sizeof(buf)) | ||
890 | return 0; | ||
891 | strcpy(&buf[i],path); | ||
892 | } | ||
841 | if (FtpOpenPort(nControl, nData, mode, dir) == -1) | 893 | if (FtpOpenPort(nControl, nData, mode, dir) == -1) |
842 | return 0; | 894 | return 0; |
843 | if (!FtpSendCmd(buf, '1', nControl)) | 895 | if (!FtpSendCmd(buf, '1', nControl)) |
844 | { | 896 | { |
845 | FtpClose(*nData); | 897 | FtpClose(*nData); |
846 | *nData = NULL; | 898 | *nData = NULL; |
847 | return 0; | 899 | return 0; |
848 | } | 900 | } |
849 | (*nData)->ctrl = nControl; | 901 | (*nData)->ctrl = nControl; |
850 | nControl->data = *nData; | 902 | nControl->data = *nData; |
851 | if (nControl->cmode == FTPLIB_PORT) | 903 | if (nControl->cmode == FTPLIB_PORT) |
852 | { | 904 | { |
853 | if (!FtpAcceptConnection(*nData,nControl)) | 905 | if (!FtpAcceptConnection(*nData,nControl)) |
854 | { | 906 | { |
855 | FtpClose(*nData); | 907 | FtpClose(*nData); |
856 | *nData = NULL; | 908 | *nData = NULL; |
857 | nControl->data = NULL; | 909 | nControl->data = NULL; |
858 | return 0; | 910 | return 0; |
859 | } | 911 | } |
860 | } | 912 | } |
861 | return 1; | 913 | return 1; |
862 | } | 914 | } |
863 | 915 | ||
@@ -868,29 +920,29 @@ GLOBALDEF int FtpRead(void *buf, int max, netbuf *nData) | |||
868 | { | 920 | { |
869 | int i; | 921 | int i; |
870 | if (nData->dir != FTPLIB_READ) | 922 | if (nData->dir != FTPLIB_READ) |
871 | return 0; | 923 | return 0; |
872 | if (nData->buf) | 924 | if (nData->buf) |
873 | i = readline(buf, max, nData); | 925 | i = readline(buf, max, nData); |
874 | else | 926 | else |
875 | { | 927 | { |
876 | i = socket_wait(nData); | 928 | i = socket_wait(nData); |
877 | if (i != 1) | 929 | if (i != 1) |
878 | return 0; | 930 | return 0; |
879 | i = net_read(nData->handle, buf, max); | 931 | i = net_read(nData->handle, buf, max); |
880 | } | 932 | } |
881 | if (i == -1) | 933 | if (i == -1) |
882 | return 0; | 934 | return 0; |
883 | nData->xfered += i; | 935 | nData->xfered += i; |
884 | if (nData->idlecb && nData->cbbytes) | 936 | if (nData->idlecb && nData->cbbytes) |
885 | { | 937 | { |
886 | nData->xfered1 += i; | 938 | nData->xfered1 += i; |
887 | if (nData->xfered1 > nData->cbbytes) | 939 | if (nData->xfered1 > nData->cbbytes) |
888 | { | 940 | { |
889 | if (nData->idlecb(nData, nData->xfered, nData->idlearg) == 0) | 941 | if (nData->idlecb(nData, nData->xfered, nData->idlearg) == 0) |
890 | return 0; | 942 | return 0; |
891 | nData->xfered1 = 0; | 943 | nData->xfered1 = 0; |
892 | } | 944 | } |
893 | } | 945 | } |
894 | return i; | 946 | return i; |
895 | } | 947 | } |
896 | 948 | ||
@@ -901,26 +953,26 @@ GLOBALDEF int FtpWrite(void *buf, int len, netbuf *nData) | |||
901 | { | 953 | { |
902 | int i; | 954 | int i; |
903 | if (nData->dir != FTPLIB_WRITE) | 955 | if (nData->dir != FTPLIB_WRITE) |
904 | return 0; | 956 | return 0; |
905 | if (nData->buf) | 957 | if (nData->buf) |
906 | i = writeline(buf, len, nData); | 958 | i = writeline(buf, len, nData); |
907 | else | 959 | else |
908 | { | 960 | { |
909 | socket_wait(nData); | 961 | socket_wait(nData); |
910 | i = net_write(nData->handle, buf, len); | 962 | i = net_write(nData->handle, buf, len); |
911 | } | 963 | } |
912 | if (i == -1) | 964 | if (i == -1) |
913 | return 0; | 965 | return 0; |
914 | nData->xfered += i; | 966 | nData->xfered += i; |
915 | if (nData->idlecb && nData->cbbytes) | 967 | if (nData->idlecb && nData->cbbytes) |
916 | { | 968 | { |
917 | nData->xfered1 += i; | 969 | nData->xfered1 += i; |
918 | if (nData->xfered1 > nData->cbbytes) | 970 | if (nData->xfered1 > nData->cbbytes) |
919 | { | 971 | { |
920 | nData->idlecb(nData, nData->xfered, nData->idlearg); | 972 | nData->idlecb(nData, nData->xfered, nData->idlearg); |
921 | nData->xfered1 = 0; | 973 | nData->xfered1 = 0; |
922 | } | 974 | } |
923 | } | 975 | } |
924 | return i; | 976 | return i; |
925 | } | 977 | } |
926 | 978 | ||
@@ -931,34 +983,34 @@ GLOBALDEF int FtpClose(netbuf *nData) | |||
931 | { | 983 | { |
932 | netbuf *ctrl; | 984 | netbuf *ctrl; |
933 | switch (nData->dir) | 985 | switch (nData->dir) |
934 | { | 986 | { |
935 | case FTPLIB_WRITE: | 987 | case FTPLIB_WRITE: |
936 | /* potential problem - if buffer flush fails, how to notify user? */ | 988 | /* potential problem - if buffer flush fails, how to notify user? */ |
937 | if (nData->buf != NULL) | 989 | if (nData->buf != NULL) |
938 | writeline(NULL, 0, nData); | 990 | writeline(NULL, 0, nData); |
939 | case FTPLIB_READ: | 991 | case FTPLIB_READ: |
940 | if (nData->buf) | 992 | if (nData->buf) |
941 | free(nData->buf); | 993 | free(nData->buf); |
942 | shutdown(nData->handle,2); | 994 | shutdown(nData->handle,2); |
943 | net_close(nData->handle); | 995 | net_close(nData->handle); |
944 | ctrl = nData->ctrl; | 996 | ctrl = nData->ctrl; |
945 | free(nData); | 997 | free(nData); |
946 | if (ctrl) | 998 | if (ctrl) |
947 | { | 999 | { |
948 | ctrl->data = NULL; | 1000 | ctrl->data = NULL; |
949 | return(readresp('2', ctrl)); | 1001 | return(readresp('2', ctrl)); |
950 | } | 1002 | } |
951 | return 1; | 1003 | return 1; |
952 | case FTPLIB_CONTROL: | 1004 | case FTPLIB_CONTROL: |
953 | if (nData->data) | 1005 | if (nData->data) |
954 | { | 1006 | { |
955 | nData->ctrl = NULL; | 1007 | nData->ctrl = NULL; |
956 | FtpClose(nData); | 1008 | FtpClose(nData); |
957 | } | 1009 | } |
958 | net_close(nData->handle); | 1010 | net_close(nData->handle); |
959 | free(nData); | 1011 | free(nData); |
960 | return 0; | 1012 | return 0; |
961 | } | 1013 | } |
962 | return 1; | 1014 | return 1; |
963 | } | 1015 | } |
964 | 1016 | ||
@@ -975,7 +1027,7 @@ GLOBALDEF int FtpSite(const char *cmd, netbuf *nControl) | |||
975 | return 0; | 1027 | return 0; |
976 | sprintf(buf,"SITE %s",cmd); | 1028 | sprintf(buf,"SITE %s",cmd); |
977 | if (!FtpSendCmd(buf,'2',nControl)) | 1029 | if (!FtpSendCmd(buf,'2',nControl)) |
978 | return 0; | 1030 | return 0; |
979 | return 1; | 1031 | return 1; |
980 | } | 1032 | } |
981 | 1033 | ||
@@ -994,10 +1046,10 @@ GLOBALDEF int FtpSysType(char *buf, int max, netbuf *nControl) | |||
994 | char *b = buf; | 1046 | char *b = buf; |
995 | char *s; | 1047 | char *s; |
996 | if (!FtpSendCmd("SYST",'2',nControl)) | 1048 | if (!FtpSendCmd("SYST",'2',nControl)) |
997 | return 0; | 1049 | return 0; |
998 | s = &nControl->response[4]; | 1050 | s = &nControl->response[4]; |
999 | while ((--l) && (*s != ' ')) | 1051 | while ((--l) && (*s != ' ')) |
1000 | *b++ = *s++; | 1052 | *b++ = *s++; |
1001 | *b++ = '\0'; | 1053 | *b++ = '\0'; |
1002 | return 1; | 1054 | return 1; |
1003 | } | 1055 | } |
@@ -1015,7 +1067,7 @@ GLOBALDEF int FtpMkdir(const char *path, netbuf *nControl) | |||
1015 | return 0; | 1067 | return 0; |
1016 | sprintf(buf,"MKD %s",path); | 1068 | sprintf(buf,"MKD %s",path); |
1017 | if (!FtpSendCmd(buf,'2', nControl)) | 1069 | if (!FtpSendCmd(buf,'2', nControl)) |
1018 | return 0; | 1070 | return 0; |
1019 | return 1; | 1071 | return 1; |
1020 | } | 1072 | } |
1021 | 1073 | ||
@@ -1032,7 +1084,7 @@ GLOBALDEF int FtpChdir(const char *path, netbuf *nControl) | |||
1032 | return 0; | 1084 | return 0; |
1033 | sprintf(buf,"CWD %s",path); | 1085 | sprintf(buf,"CWD %s",path); |
1034 | if (!FtpSendCmd(buf,'2',nControl)) | 1086 | if (!FtpSendCmd(buf,'2',nControl)) |
1035 | return 0; | 1087 | return 0; |
1036 | return 1; | 1088 | return 1; |
1037 | } | 1089 | } |
1038 | 1090 | ||
@@ -1044,7 +1096,7 @@ GLOBALDEF int FtpChdir(const char *path, netbuf *nControl) | |||
1044 | GLOBALDEF int FtpCDUp(netbuf *nControl) | 1096 | GLOBALDEF int FtpCDUp(netbuf *nControl) |
1045 | { | 1097 | { |
1046 | if (!FtpSendCmd("CDUP",'2',nControl)) | 1098 | if (!FtpSendCmd("CDUP",'2',nControl)) |
1047 | return 0; | 1099 | return 0; |
1048 | return 1; | 1100 | return 1; |
1049 | } | 1101 | } |
1050 | 1102 | ||
@@ -1061,7 +1113,7 @@ GLOBALDEF int FtpRmdir(const char *path, netbuf *nControl) | |||
1061 | return 0; | 1113 | return 0; |
1062 | sprintf(buf,"RMD %s",path); | 1114 | sprintf(buf,"RMD %s",path); |
1063 | if (!FtpSendCmd(buf,'2',nControl)) | 1115 | if (!FtpSendCmd(buf,'2',nControl)) |
1064 | return 0; | 1116 | return 0; |
1065 | return 1; | 1117 | return 1; |
1066 | } | 1118 | } |
1067 | 1119 | ||
@@ -1076,13 +1128,13 @@ GLOBALDEF int FtpPwd(char *path, int max, netbuf *nControl) | |||
1076 | char *b = path; | 1128 | char *b = path; |
1077 | char *s; | 1129 | char *s; |
1078 | if (!FtpSendCmd("PWD",'2',nControl)) | 1130 | if (!FtpSendCmd("PWD",'2',nControl)) |
1079 | return 0; | 1131 | return 0; |
1080 | s = strchr(nControl->response, '"'); | 1132 | s = strchr(nControl->response, '"'); |
1081 | if (s == NULL) | 1133 | if (s == NULL) |
1082 | return 0; | 1134 | return 0; |
1083 | s++; | 1135 | s++; |
1084 | while ((--l) && (*s) && (*s != '"')) | 1136 | while ((--l) && (*s) && (*s != '"')) |
1085 | *b++ = *s++; | 1137 | *b++ = *s++; |
1086 | *b++ = '\0'; | 1138 | *b++ = '\0'; |
1087 | return 1; | 1139 | return 1; |
1088 | } | 1140 | } |
@@ -1093,7 +1145,7 @@ GLOBALDEF int FtpPwd(char *path, int max, netbuf *nControl) | |||
1093 | * return 1 if successful, 0 otherwise | 1145 | * return 1 if successful, 0 otherwise |
1094 | */ | 1146 | */ |
1095 | static int FtpXfer(const char *localfile, const char *path, | 1147 | static int FtpXfer(const char *localfile, const char *path, |
1096 | netbuf *nControl, int typ, int mode) | 1148 | netbuf *nControl, int typ, int mode) |
1097 | { | 1149 | { |
1098 | int l,c; | 1150 | int l,c; |
1099 | char *dbuf; | 1151 | char *dbuf; |
@@ -1102,49 +1154,49 @@ static int FtpXfer(const char *localfile, const char *path, | |||
1102 | int rv=1; | 1154 | int rv=1; |
1103 | 1155 | ||
1104 | if (localfile != NULL) | 1156 | if (localfile != NULL) |
1105 | { | 1157 | { |
1106 | char ac[4] = "w"; | 1158 | char ac[4] = "w"; |
1107 | if (typ == FTPLIB_FILE_WRITE) | 1159 | if (typ == FTPLIB_FILE_WRITE) |
1108 | ac[0] = 'r'; | 1160 | ac[0] = 'r'; |
1109 | if (mode == FTPLIB_IMAGE) | 1161 | if (mode == FTPLIB_IMAGE) |
1110 | ac[1] = 'b'; | 1162 | ac[1] = 'b'; |
1111 | local = fopen(localfile, ac); | 1163 | local = fopen(localfile, ac); |
1112 | if (local == NULL) | 1164 | if (local == NULL) |
1113 | { | 1165 | { |
1114 | strncpy(nControl->response, strerror(errno), | 1166 | strncpy(nControl->response, strerror(errno), |
1115 | sizeof(nControl->response)); | 1167 | sizeof(nControl->response)); |
1116 | return 0; | 1168 | return 0; |
1117 | } | 1169 | } |
1118 | } | 1170 | } |
1119 | if (local == NULL) | 1171 | if (local == NULL) |
1120 | local = (typ == FTPLIB_FILE_WRITE) ? stdin : stdout; | 1172 | local = (typ == FTPLIB_FILE_WRITE) ? stdin : stdout; |
1121 | if (!FtpAccess(path, typ, mode, nControl, &nData)) | 1173 | if (!FtpAccess(path, typ, mode, nControl, &nData)) |
1122 | return 0; | 1174 | return 0; |
1123 | dbuf = malloc(FTPLIB_BUFSIZ); | 1175 | dbuf = malloc(FTPLIB_BUFSIZ); |
1124 | if (typ == FTPLIB_FILE_WRITE) | 1176 | if (typ == FTPLIB_FILE_WRITE) |
1125 | { | ||
1126 | while ((l = fread(dbuf, 1, FTPLIB_BUFSIZ, local)) > 0) | ||
1127 | if ((c = FtpWrite(dbuf, l, nData)) < l) | ||
1128 | { | 1177 | { |
1129 | printf("short write: passed %d, wrote %d\n", l, c); | 1178 | while ((l = fread(dbuf, 1, FTPLIB_BUFSIZ, local)) > 0) |
1130 | rv = 0; | 1179 | if ((c = FtpWrite(dbuf, l, nData)) < l) |
1131 | break; | 1180 | { |
1181 | printf("short write: passed %d, wrote %d\n", l, c); | ||
1182 | rv = 0; | ||
1183 | break; | ||
1184 | } | ||
1132 | } | 1185 | } |
1133 | } | ||
1134 | else | 1186 | else |
1135 | { | ||
1136 | while ((l = FtpRead(dbuf, FTPLIB_BUFSIZ, nData)) > 0) | ||
1137 | if (fwrite(dbuf, 1, l, local) <= 0) | ||
1138 | { | 1187 | { |
1139 | perror("localfile write"); | 1188 | while ((l = FtpRead(dbuf, FTPLIB_BUFSIZ, nData)) > 0) |
1140 | rv = 0; | 1189 | if (fwrite(dbuf, 1, l, local) <= 0) |
1141 | break; | 1190 | { |
1191 | perror("localfile write"); | ||
1192 | rv = 0; | ||
1193 | break; | ||
1194 | } | ||
1142 | } | 1195 | } |
1143 | } | ||
1144 | free(dbuf); | 1196 | free(dbuf); |
1145 | fflush(local); | 1197 | fflush(local); |
1146 | if (localfile != NULL) | 1198 | if (localfile != NULL) |
1147 | fclose(local); | 1199 | fclose(local); |
1148 | FtpClose(nData); | 1200 | FtpClose(nData); |
1149 | return rv; | 1201 | return rv; |
1150 | } | 1202 | } |
@@ -1155,7 +1207,7 @@ static int FtpXfer(const char *localfile, const char *path, | |||
1155 | * return 1 if successful, 0 otherwise | 1207 | * return 1 if successful, 0 otherwise |
1156 | */ | 1208 | */ |
1157 | GLOBALDEF int FtpNlst(const char *outputfile, const char *path, | 1209 | GLOBALDEF int FtpNlst(const char *outputfile, const char *path, |
1158 | netbuf *nControl) | 1210 | netbuf *nControl) |
1159 | { | 1211 | { |
1160 | return FtpXfer(outputfile, path, nControl, FTPLIB_DIR, FTPLIB_ASCII); | 1212 | return FtpXfer(outputfile, path, nControl, FTPLIB_DIR, FTPLIB_ASCII); |
1161 | } | 1213 | } |
@@ -1184,17 +1236,17 @@ GLOBALDEF int FtpSize(const char *path, int *size, char mode, netbuf *nControl) | |||
1184 | return 0; | 1236 | return 0; |
1185 | sprintf(cmd, "TYPE %c", mode); | 1237 | sprintf(cmd, "TYPE %c", mode); |
1186 | if (!FtpSendCmd(cmd, '2', nControl)) | 1238 | if (!FtpSendCmd(cmd, '2', nControl)) |
1187 | return 0; | 1239 | return 0; |
1188 | sprintf(cmd,"SIZE %s",path); | 1240 | sprintf(cmd,"SIZE %s",path); |
1189 | if (!FtpSendCmd(cmd,'2',nControl)) | 1241 | if (!FtpSendCmd(cmd,'2',nControl)) |
1190 | rv = 0; | 1242 | rv = 0; |
1191 | else | 1243 | else |
1192 | { | 1244 | { |
1193 | if (sscanf(nControl->response, "%d %d", &resp, &sz) == 2) | 1245 | if (sscanf(nControl->response, "%d %d", &resp, &sz) == 2) |
1194 | *size = sz; | 1246 | *size = sz; |
1195 | else | 1247 | else |
1196 | rv = 0; | 1248 | rv = 0; |
1197 | } | 1249 | } |
1198 | return rv; | 1250 | return rv; |
1199 | } | 1251 | } |
1200 | 1252 | ||
@@ -1212,9 +1264,9 @@ GLOBALDEF int FtpModDate(const char *path, char *dt, int max, netbuf *nControl) | |||
1212 | return 0; | 1264 | return 0; |
1213 | sprintf(buf,"MDTM %s",path); | 1265 | sprintf(buf,"MDTM %s",path); |
1214 | if (!FtpSendCmd(buf,'2',nControl)) | 1266 | if (!FtpSendCmd(buf,'2',nControl)) |
1215 | rv = 0; | 1267 | rv = 0; |
1216 | else | 1268 | else |
1217 | strncpy(dt, &nControl->response[4], max); | 1269 | strncpy(dt, &nControl->response[4], max); |
1218 | return rv; | 1270 | return rv; |
1219 | } | 1271 | } |
1220 | 1272 | ||
@@ -1224,7 +1276,7 @@ GLOBALDEF int FtpModDate(const char *path, char *dt, int max, netbuf *nControl) | |||
1224 | * return 1 if successful, 0 otherwise | 1276 | * return 1 if successful, 0 otherwise |
1225 | */ | 1277 | */ |
1226 | GLOBALDEF int FtpGet(const char *outputfile, const char *path, | 1278 | GLOBALDEF int FtpGet(const char *outputfile, const char *path, |
1227 | char mode, netbuf *nControl) | 1279 | char mode, netbuf *nControl) |
1228 | { | 1280 | { |
1229 | return FtpXfer(outputfile, path, nControl, FTPLIB_FILE_READ, mode); | 1281 | return FtpXfer(outputfile, path, nControl, FTPLIB_FILE_READ, mode); |
1230 | } | 1282 | } |
@@ -1235,7 +1287,7 @@ GLOBALDEF int FtpGet(const char *outputfile, const char *path, | |||
1235 | * return 1 if successful, 0 otherwise | 1287 | * return 1 if successful, 0 otherwise |
1236 | */ | 1288 | */ |
1237 | GLOBALDEF int FtpPut(const char *inputfile, const char *path, char mode, | 1289 | GLOBALDEF int FtpPut(const char *inputfile, const char *path, char mode, |
1238 | netbuf *nControl) | 1290 | netbuf *nControl) |
1239 | { | 1291 | { |
1240 | return FtpXfer(inputfile, path, nControl, FTPLIB_FILE_WRITE, mode); | 1292 | return FtpXfer(inputfile, path, nControl, FTPLIB_FILE_WRITE, mode); |
1241 | } | 1293 | } |
@@ -1254,10 +1306,10 @@ GLOBALDEF int FtpRename(const char *src, const char *dst, netbuf *nControl) | |||
1254 | return 0; | 1306 | return 0; |
1255 | sprintf(cmd,"RNFR %s",src); | 1307 | sprintf(cmd,"RNFR %s",src); |
1256 | if (!FtpSendCmd(cmd,'3',nControl)) | 1308 | if (!FtpSendCmd(cmd,'3',nControl)) |
1257 | return 0; | 1309 | return 0; |
1258 | sprintf(cmd,"RNTO %s",dst); | 1310 | sprintf(cmd,"RNTO %s",dst); |
1259 | if (!FtpSendCmd(cmd,'2',nControl)) | 1311 | if (!FtpSendCmd(cmd,'2',nControl)) |
1260 | return 0; | 1312 | return 0; |
1261 | return 1; | 1313 | return 1; |
1262 | } | 1314 | } |
1263 | 1315 | ||
@@ -1274,7 +1326,7 @@ GLOBALDEF int FtpDelete(const char *fnm, netbuf *nControl) | |||
1274 | return 0; | 1326 | return 0; |
1275 | sprintf(cmd,"DELE %s",fnm); | 1327 | sprintf(cmd,"DELE %s",fnm); |
1276 | if (!FtpSendCmd(cmd,'2', nControl)) | 1328 | if (!FtpSendCmd(cmd,'2', nControl)) |
1277 | return 0; | 1329 | return 0; |
1278 | return 1; | 1330 | return 1; |
1279 | } | 1331 | } |
1280 | 1332 | ||
@@ -1286,7 +1338,7 @@ GLOBALDEF int FtpDelete(const char *fnm, netbuf *nControl) | |||
1286 | GLOBALDEF void FtpQuit(netbuf *nControl) | 1338 | GLOBALDEF void FtpQuit(netbuf *nControl) |
1287 | { | 1339 | { |
1288 | if (nControl->dir != FTPLIB_CONTROL) | 1340 | if (nControl->dir != FTPLIB_CONTROL) |
1289 | return; | 1341 | return; |
1290 | FtpSendCmd("QUIT",'2',nControl); | 1342 | FtpSendCmd("QUIT",'2',nControl); |
1291 | net_close(nControl->handle); | 1343 | net_close(nControl->handle); |
1292 | free(nControl->buf); | 1344 | free(nControl->buf); |
diff --git a/noncore/net/ftplib/ftplib.control b/noncore/net/ftplib/ftplib.control new file mode 100644 index 0000000..67765ad --- a/dev/null +++ b/noncore/net/ftplib/ftplib.control | |||
@@ -0,0 +1,9 @@ | |||
1 | Files: $QTDIR/lib/libftplib.* | ||
2 | Priority: optional | ||
3 | Section: Communications | ||
4 | Maintainer: L.J. Potter <ljp@llornkcor.com> | ||
5 | Architecture: arm | ||
6 | Version: $QPE_VERSION-$SUB_VERSION | ||
7 | Depends: opie-base ($QPE_VERSION) | ||
8 | Description: Libftp | ||
9 | The ftp library for the Opie environment. | ||
diff --git a/noncore/net/opieftp/ftplib.h b/noncore/net/ftplib/ftplib.h index 75a90ae..75a90ae 100644 --- a/noncore/net/opieftp/ftplib.h +++ b/noncore/net/ftplib/ftplib.h | |||
diff --git a/noncore/net/ftplib/ftplib.pro b/noncore/net/ftplib/ftplib.pro new file mode 100644 index 0000000..9ee3605 --- a/dev/null +++ b/noncore/net/ftplib/ftplib.pro | |||
@@ -0,0 +1,6 @@ | |||
1 | TEMPLATE = lib | ||
2 | CONFIG = qt warn_on release | ||
3 | HEADERS = ftplib.h | ||
4 | SOURCES = ftplib.c | ||
5 | DESTDIR = $(QTDIR)/lib$(PROJMAK) | ||
6 | INTERFACES = | ||
diff --git a/noncore/net/opieftp/opieftp.control b/noncore/net/opieftp/opieftp.control index 18ec80f..42590bd 100644 --- a/noncore/net/opieftp/opieftp.control +++ b/noncore/net/opieftp/opieftp.control | |||
@@ -4,6 +4,6 @@ Section: Communications | |||
4 | Maintainer: L.J. Potter <ljp@llornkcor.com> | 4 | Maintainer: L.J. Potter <ljp@llornkcor.com> |
5 | Architecture: arm | 5 | Architecture: arm |
6 | Version: $QPE_VERSION-$SUB_VERSION | 6 | Version: $QPE_VERSION-$SUB_VERSION |
7 | Depends: opie-base ($QPE_VERSION) | 7 | Depends: opie-base ($QPE_VERSION), ftplib |
8 | Description: OpieFtp | 8 | Description: OpieFtp |
9 | The ftp client for the Opie environment. | 9 | The ftp client for the Opie environment. |
diff --git a/noncore/net/opieftp/opieftp.cpp b/noncore/net/opieftp/opieftp.cpp index 292cc9d..7c83223 100644 --- a/noncore/net/opieftp/opieftp.cpp +++ b/noncore/net/opieftp/opieftp.cpp | |||
@@ -14,7 +14,7 @@ | |||
14 | #include "opieftp.h" | 14 | #include "opieftp.h" |
15 | 15 | ||
16 | extern "C" { | 16 | extern "C" { |
17 | #include "ftplib.h" | 17 | #include "../ftplib/ftplib.h" |
18 | } | 18 | } |
19 | 19 | ||
20 | #include "inputDialog.h" | 20 | #include "inputDialog.h" |
@@ -1510,3 +1510,7 @@ void OpieFtp::serverListClicked( const QString &item) { | |||
1510 | serverComboSelected(i-1); | 1510 | serverComboSelected(i-1); |
1511 | } | 1511 | } |
1512 | } | 1512 | } |
1513 | |||
1514 | void OpieFtp::timerOut() { | ||
1515 | |||
1516 | } | ||
diff --git a/noncore/net/opieftp/opieftp.h b/noncore/net/opieftp/opieftp.h index 2aa691a..109b5f8 100644 --- a/noncore/net/opieftp/opieftp.h +++ b/noncore/net/opieftp/opieftp.h | |||
@@ -39,6 +39,7 @@ class QPushButton; | |||
39 | class QToolButton; | 39 | class QToolButton; |
40 | class QStringList; | 40 | class QStringList; |
41 | class QListBox; | 41 | class QListBox; |
42 | class QTimer; | ||
42 | 43 | ||
43 | class OpieFtp : public QMainWindow | 44 | class OpieFtp : public QMainWindow |
44 | { | 45 | { |
@@ -67,6 +68,7 @@ public: | |||
67 | bool b; | 68 | bool b; |
68 | int currentServerConfig; | 69 | int currentServerConfig; |
69 | protected slots: | 70 | protected slots: |
71 | void timerOut(); | ||
70 | void upDir(); | 72 | void upDir(); |
71 | void homeButtonPushed(); | 73 | void homeButtonPushed(); |
72 | void docButtonPushed(); | 74 | void docButtonPushed(); |
diff --git a/noncore/net/opieftp/opieftp.pro b/noncore/net/opieftp/opieftp.pro index 6d88530..ae72ff3 100644 --- a/noncore/net/opieftp/opieftp.pro +++ b/noncore/net/opieftp/opieftp.pro | |||
@@ -1,12 +1,12 @@ | |||
1 | TEMPLATE = app | 1 | TEMPLATE = app |
2 | CONFIG += qt warn_on release | 2 | CONFIG += qt warn_on release |
3 | HEADERS = opieftp.h inputDialog.h ftplib.h | 3 | HEADERS = opieftp.h inputDialog.h ftplib.h |
4 | SOURCES = opieftp.cpp inputDialog.cpp ftplib.c main.cpp | 4 | SOURCES = opieftp.cpp inputDialog.cpp main.cpp |
5 | TARGET = opieftp | 5 | TARGET = opieftp |
6 | DESTDIR = $(OPIEDIR)/bin | 6 | DESTDIR = $(OPIEDIR)/bin |
7 | INCLUDEPATH += $(OPIEDIR)/include | 7 | INCLUDEPATH += $(OPIEDIR)/include |
8 | DEPENDPATH += $(OPIEDIR)/include | 8 | DEPENDPATH += $(OPIEDIR)/include |
9 | LIBS += -lqpe | 9 | LIBS += -lqpe -lftplib |
10 | 10 | ||
11 | TRANSLATIONS = ../../../i18n/de/opieftp.ts \ | 11 | TRANSLATIONS = ../../../i18n/de/opieftp.ts \ |
12 | ../../../i18n/en/opieftp.ts \ | 12 | ../../../i18n/en/opieftp.ts \ |