ReactOS 0.4.17-dev-1196-gb6224c3
ftp.c
Go to the documentation of this file.
1#ifdef __REACTOS__
2#include "precomp.h"
3#else
4/*
5 * WININET - Ftp implementation
6 *
7 * Copyright 1999 Corel Corporation
8 * Copyright 2004 Mike McCormack for CodeWeavers
9 * Copyright 2004 Kevin Koltzau
10 * Copyright 2007 Hans Leidekker
11 *
12 * Ulrich Czekalla
13 * Noureddine Jemmali
14 *
15 * Copyright 2000 Andreas Mohr
16 * Copyright 2002 Jaco Greeff
17 *
18 * This library is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU Lesser General Public
20 * License as published by the Free Software Foundation; either
21 * version 2.1 of the License, or (at your option) any later version.
22 *
23 * This library is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 * Lesser General Public License for more details.
27 *
28 * You should have received a copy of the GNU Lesser General Public
29 * License along with this library; if not, write to the Free Software
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 */
32
33#include "ws2tcpip.h"
34
35#include <stdarg.h>
36#include <stdio.h>
37#include <stdlib.h>
38#include <string.h>
39#include <time.h>
40#include <assert.h>
41
42#include "windef.h"
43#include "winbase.h"
44#include "wingdi.h"
45#include "winuser.h"
46#include "wininet.h"
47#include "winnls.h"
48#include "winerror.h"
49#include "winreg.h"
50#include "winternl.h"
51#include "shlwapi.h"
52
53#include "wine/debug.h"
54#include "internet.h"
55#endif /* defined(__REACTOS__) */
56
58
59#define RESPONSE_TIMEOUT 30
60
62
63typedef struct
64{
72
74{
79 int pasvSocket; /* data socket connected by us in case of passive FTP */
87};
88
89typedef struct
90{
95 unsigned short permissions;
97
98typedef struct
99{
106
107#define DATA_PACKET_SIZE 0x2000
108#define szCRLF "\r\n"
109#define MAX_BACKLOG 5
110
111/* Testing shows that Windows only accepts dwFlags where the last
112 * 3 (yes 3) bits define FTP_TRANSFER_TYPE_UNKNOWN, FTP_TRANSFER_TYPE_ASCII or FTP_TRANSFER_TYPE_BINARY.
113 */
114#define FTP_CONDITION_MASK 0x0007
115
116typedef enum {
117 /* FTP commands with arguments. */
132
133 /* FTP commands without arguments. */
141
142static const CHAR *const szFtpCommands[] = {
143 "ACCT",
144 "CWD",
145 "DELE",
146 "MKD",
147 "PASS",
148 "PORT",
149 "RETR",
150 "RMD",
151 "RNFR",
152 "RNTO",
153 "STOR",
154 "TYPE",
155 "USER",
156 "SIZE",
157 "ABOR",
158 "LIST",
159 "NLST",
160 "PASV",
161 "PWD",
162 "QUIT",
163};
164
165static const CHAR szMonths[] = "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC";
166
167static BOOL FTP_SendCommand(INT nSocket, FTP_COMMAND ftpCmd, LPCWSTR lpszParam,
168 INTERNET_STATUS_CALLBACK lpfnStatusCB, object_header_t *hdr, DWORD_PTR dwContext);
169static BOOL FTP_SendStore(ftp_session_t*, LPCWSTR lpszRemoteFile, DWORD dwType);
170static BOOL FTP_GetDataSocket(ftp_session_t*, LPINT nDataSocket);
171static BOOL FTP_SendData(ftp_session_t*, INT nDataSocket, HANDLE hFile);
173static BOOL FTP_SendRetrieve(ftp_session_t*, LPCWSTR lpszRemoteFile, DWORD dwType);
179static BOOL FTP_SendType(ftp_session_t*, DWORD dwType);
183static BOOL FTP_ParsePermission(LPCSTR lpszPermission, LPFILEPROPERTIESW lpfp);
184static BOOL FTP_ParseNextFile(INT nSocket, LPCWSTR lpszSearchFile, LPFILEPROPERTIESW fileprop);
185static BOOL FTP_ParseDirectory(ftp_session_t*, INT nSocket, LPCWSTR lpszSearchFile,
186 LPFILEPROPERTIESW *lpafp, LPDWORD dwfp);
187static HINTERNET FTP_ReceiveFileList(ftp_session_t*, INT nSocket, LPCWSTR lpszSearchFile,
188 LPWIN32_FIND_DATAW lpFindFileData, DWORD_PTR dwContext);
189static DWORD FTP_SetResponseError(DWORD dwResponse);
191static BOOL FTP_FtpPutFileW(ftp_session_t*, LPCWSTR lpszLocalFile,
192 LPCWSTR lpszNewRemoteFile, DWORD dwFlags, DWORD_PTR dwContext);
194static BOOL FTP_FtpCreateDirectoryW(ftp_session_t*, LPCWSTR lpszDirectory);
196 LPCWSTR lpszSearchFile, LPWIN32_FIND_DATAW lpFindFileData, DWORD dwFlags, DWORD_PTR dwContext);
197static BOOL FTP_FtpGetCurrentDirectoryW(ftp_session_t*, LPWSTR lpszCurrentDirectory,
198 LPDWORD lpdwCurrentDirectory);
200static BOOL FTP_FtpRemoveDirectoryW(ftp_session_t*, LPCWSTR lpszDirectory);
201static BOOL FTP_FtpDeleteFileW(ftp_session_t*, LPCWSTR lpszFileName);
202static BOOL FTP_FtpGetFileW(ftp_session_t*, LPCWSTR lpszRemoteFile, LPCWSTR lpszNewFile,
203 BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags,
204 DWORD_PTR dwContext);
205
206/* A temporary helper until we get rid of INTERNET_GetLastError calls */
208{
209 if(res != ERROR_SUCCESS)
211 return res == ERROR_SUCCESS;
212}
213
214/***********************************************************************
215 * FtpPutFileA (WININET.@)
216 *
217 * Uploads a file to the FTP server
218 *
219 * RETURNS
220 * TRUE on success
221 * FALSE on failure
222 *
223 */
224BOOL WINAPI FtpPutFileA(HINTERNET hConnect, LPCSTR lpszLocalFile,
225 LPCSTR lpszNewRemoteFile, DWORD dwFlags, DWORD_PTR dwContext)
226{
227 LPWSTR lpwzLocalFile;
228 LPWSTR lpwzNewRemoteFile;
229 BOOL ret;
230
231 lpwzLocalFile = strdupAtoW(lpszLocalFile);
232 lpwzNewRemoteFile = strdupAtoW(lpszNewRemoteFile);
233 ret = FtpPutFileW(hConnect, lpwzLocalFile, lpwzNewRemoteFile,
234 dwFlags, dwContext);
235 free(lpwzLocalFile);
236 free(lpwzNewRemoteFile);
237 return ret;
238}
239
240typedef struct {
247
249{
252
253 TRACE("%p\n", session);
254
255 FTP_FtpPutFileW(session, task->local_file, task->remote_file,
256 task->flags, task->context);
257
258 free(task->local_file);
259 free(task->remote_file);
260}
261
262/***********************************************************************
263 * FtpPutFileW (WININET.@)
264 *
265 * Uploads a file to the FTP server
266 *
267 * RETURNS
268 * TRUE on success
269 * FALSE on failure
270 *
271 */
272BOOL WINAPI FtpPutFileW(HINTERNET hConnect, LPCWSTR lpszLocalFile,
273 LPCWSTR lpszNewRemoteFile, DWORD dwFlags, DWORD_PTR dwContext)
274{
275 ftp_session_t *lpwfs;
276 appinfo_t *hIC = NULL;
277 BOOL r = FALSE;
278
279 if (!lpszLocalFile || !lpszNewRemoteFile)
280 {
282 return FALSE;
283 }
284
285 lpwfs = (ftp_session_t*) get_handle_object( hConnect );
286 if (!lpwfs)
287 {
289 return FALSE;
290 }
291
292 if (WH_HFTPSESSION != lpwfs->hdr.htype)
293 {
295 goto lend;
296 }
297
298 if (lpwfs->download_in_progress != NULL)
299 {
301 goto lend;
302 }
303
305 {
307 goto lend;
308 }
309
310 hIC = lpwfs->lpAppInfo;
312 {
314
315 task->local_file = wcsdup(lpszLocalFile);
316 task->remote_file = wcsdup(lpszNewRemoteFile);
317 task->flags = dwFlags;
318 task->context = dwContext;
319
321 }
322 else
323 {
324 r = FTP_FtpPutFileW(lpwfs, lpszLocalFile,
325 lpszNewRemoteFile, dwFlags, dwContext);
326 }
327
328lend:
329 WININET_Release( &lpwfs->hdr );
330
331 return r;
332}
333
334/***********************************************************************
335 * FTP_FtpPutFileW (Internal)
336 *
337 * Uploads a file to the FTP server
338 *
339 * RETURNS
340 * TRUE on success
341 * FALSE on failure
342 *
343 */
344static BOOL FTP_FtpPutFileW(ftp_session_t *lpwfs, LPCWSTR lpszLocalFile,
345 LPCWSTR lpszNewRemoteFile, DWORD dwFlags, DWORD_PTR dwContext)
346{
348 BOOL bSuccess = FALSE;
349 appinfo_t *hIC = NULL;
350 INT nResCode;
351
352 TRACE(" lpszLocalFile(%s) lpszNewRemoteFile(%s)\n", debugstr_w(lpszLocalFile), debugstr_w(lpszNewRemoteFile));
353
354 /* Clear any error information */
356
357 /* Open file to be uploaded */
359 (hFile = CreateFileW(lpszLocalFile, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0)))
360 /* Let CreateFile set the appropriate error */
361 return FALSE;
362
363 hIC = lpwfs->lpAppInfo;
364
366
367 if (FTP_SendStore(lpwfs, lpszNewRemoteFile, dwFlags))
368 {
369 INT nDataSocket;
370
371 /* Get data socket to server */
372 if (FTP_GetDataSocket(lpwfs, &nDataSocket))
373 {
374 FTP_SendData(lpwfs, nDataSocket, hFile);
375 closesocket(nDataSocket);
376 nResCode = FTP_ReceiveResponse(lpwfs, dwContext);
377 if (nResCode)
378 {
379 if (nResCode == 226)
380 bSuccess = TRUE;
381 else
382 FTP_SetResponseError(nResCode);
383 }
384 }
385 }
386
387 if (lpwfs->lstnSocket != -1)
388 {
389 closesocket(lpwfs->lstnSocket);
390 lpwfs->lstnSocket = -1;
391 }
392
394 {
396
397 iar.dwResult = (DWORD)bSuccess;
398 iar.dwError = bSuccess ? ERROR_SUCCESS : INTERNET_GetLastError();
400 &iar, sizeof(INTERNET_ASYNC_RESULT));
401 }
402
404
405 return bSuccess;
406}
407
408
409/***********************************************************************
410 * FtpSetCurrentDirectoryA (WININET.@)
411 *
412 * Change the working directory on the FTP server
413 *
414 * RETURNS
415 * TRUE on success
416 * FALSE on failure
417 *
418 */
420{
421 LPWSTR lpwzDirectory;
422 BOOL ret;
423
424 lpwzDirectory = strdupAtoW(lpszDirectory);
425 ret = FtpSetCurrentDirectoryW(hConnect, lpwzDirectory);
426 free(lpwzDirectory);
427 return ret;
428}
429
430typedef struct {
434
436{
439
440 TRACE("%p\n", session);
441
443 free(task->directory);
444}
445
446/***********************************************************************
447 * FtpSetCurrentDirectoryW (WININET.@)
448 *
449 * Change the working directory on the FTP server
450 *
451 * RETURNS
452 * TRUE on success
453 * FALSE on failure
454 *
455 */
457{
458 ftp_session_t *lpwfs = NULL;
459 appinfo_t *hIC = NULL;
460 BOOL r = FALSE;
461
462 if (!lpszDirectory)
463 {
465 goto lend;
466 }
467
468 lpwfs = (ftp_session_t*) get_handle_object( hConnect );
469 if (NULL == lpwfs || WH_HFTPSESSION != lpwfs->hdr.htype)
470 {
472 goto lend;
473 }
474
475 if (lpwfs->download_in_progress != NULL)
476 {
478 goto lend;
479 }
480
481 TRACE("lpszDirectory(%s)\n", debugstr_w(lpszDirectory));
482
483 hIC = lpwfs->lpAppInfo;
485 {
487
489 task->directory = wcsdup(lpszDirectory);
490
492 }
493 else
494 {
495 r = FTP_FtpSetCurrentDirectoryW(lpwfs, lpszDirectory);
496 }
497
498lend:
499 if( lpwfs )
500 WININET_Release( &lpwfs->hdr );
501
502 return r;
503}
504
505
506/***********************************************************************
507 * FTP_FtpSetCurrentDirectoryW (Internal)
508 *
509 * Change the working directory on the FTP server
510 *
511 * RETURNS
512 * TRUE on success
513 * FALSE on failure
514 *
515 */
517{
518 INT nResCode;
519 appinfo_t *hIC = NULL;
520 BOOL bSuccess = FALSE;
521
522 TRACE("lpszDirectory(%s)\n", debugstr_w(lpszDirectory));
523
524 /* Clear any error information */
526
527 hIC = lpwfs->lpAppInfo;
528 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_CWD, lpszDirectory,
529 lpwfs->hdr.lpfnStatusCB, &lpwfs->hdr, lpwfs->hdr.dwContext))
530 goto lend;
531
532 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
533
534 if (nResCode)
535 {
536 if (nResCode == 250)
537 bSuccess = TRUE;
538 else
539 FTP_SetResponseError(nResCode);
540 }
541
542lend:
544 {
546
547 iar.dwResult = bSuccess;
550 &iar, sizeof(INTERNET_ASYNC_RESULT));
551 }
552 return bSuccess;
553}
554
555
556/***********************************************************************
557 * FtpCreateDirectoryA (WININET.@)
558 *
559 * Create new directory on the FTP server
560 *
561 * RETURNS
562 * TRUE on success
563 * FALSE on failure
564 *
565 */
567{
568 LPWSTR lpwzDirectory;
569 BOOL ret;
570
571 lpwzDirectory = strdupAtoW(lpszDirectory);
572 ret = FtpCreateDirectoryW(hConnect, lpwzDirectory);
573 free(lpwzDirectory);
574 return ret;
575}
576
577
579{
582
583 TRACE(" %p\n", session);
584
586 free(task->directory);
587}
588
589/***********************************************************************
590 * FtpCreateDirectoryW (WININET.@)
591 *
592 * Create new directory on the FTP server
593 *
594 * RETURNS
595 * TRUE on success
596 * FALSE on failure
597 *
598 */
600{
601 ftp_session_t *lpwfs;
602 appinfo_t *hIC = NULL;
603 BOOL r = FALSE;
604
605 lpwfs = (ftp_session_t*) get_handle_object( hConnect );
606 if (!lpwfs)
607 {
609 return FALSE;
610 }
611
612 if (WH_HFTPSESSION != lpwfs->hdr.htype)
613 {
615 goto lend;
616 }
617
618 if (lpwfs->download_in_progress != NULL)
619 {
621 goto lend;
622 }
623
624 if (!lpszDirectory)
625 {
627 goto lend;
628 }
629
630 hIC = lpwfs->lpAppInfo;
632 {
634
636 task->directory = wcsdup(lpszDirectory);
637
639 }
640 else
641 {
642 r = FTP_FtpCreateDirectoryW(lpwfs, lpszDirectory);
643 }
644lend:
645 WININET_Release( &lpwfs->hdr );
646
647 return r;
648}
649
650
651/***********************************************************************
652 * FTP_FtpCreateDirectoryW (Internal)
653 *
654 * Create new directory on the FTP server
655 *
656 * RETURNS
657 * TRUE on success
658 * FALSE on failure
659 *
660 */
662{
663 INT nResCode;
664 BOOL bSuccess = FALSE;
665 appinfo_t *hIC = NULL;
666
667 TRACE("lpszDirectory(%s)\n", debugstr_w(lpszDirectory));
668
669 /* Clear any error information */
671
672 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_MKD, lpszDirectory, 0, 0, 0))
673 goto lend;
674
675 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
676 if (nResCode)
677 {
678 if (nResCode == 257)
679 bSuccess = TRUE;
680 else
681 FTP_SetResponseError(nResCode);
682 }
683
684lend:
685 hIC = lpwfs->lpAppInfo;
687 {
689
690 iar.dwResult = (DWORD)bSuccess;
691 iar.dwError = bSuccess ? ERROR_SUCCESS : INTERNET_GetLastError();
693 &iar, sizeof(INTERNET_ASYNC_RESULT));
694 }
695
696 return bSuccess;
697}
698
699/***********************************************************************
700 * FtpFindFirstFileA (WININET.@)
701 *
702 * Search the specified directory
703 *
704 * RETURNS
705 * HINTERNET on success
706 * NULL on failure
707 *
708 */
710 LPCSTR lpszSearchFile, LPWIN32_FIND_DATAA lpFindFileData, DWORD dwFlags, DWORD_PTR dwContext)
711{
712 LPWSTR lpwzSearchFile;
714 LPWIN32_FIND_DATAW lpFindFileDataW;
716
717 lpwzSearchFile = strdupAtoW(lpszSearchFile);
718 lpFindFileDataW = lpFindFileData?&wfd:NULL;
719 ret = FtpFindFirstFileW(hConnect, lpwzSearchFile, lpFindFileDataW, dwFlags, dwContext);
720 free(lpwzSearchFile);
721
722 if (ret && lpFindFileData)
723 WININET_find_data_WtoA(lpFindFileDataW, lpFindFileData);
724
725 return ret;
726}
727
728typedef struct {
735
737{
740
741 TRACE("%p\n", session);
742
743 FTP_FtpFindFirstFileW(session, task->search_file, task->find_file_data, task->flags, task->context);
744 free(task->search_file);
745}
746
747/***********************************************************************
748 * FtpFindFirstFileW (WININET.@)
749 *
750 * Search the specified directory
751 *
752 * RETURNS
753 * HINTERNET on success
754 * NULL on failure
755 *
756 */
758 LPCWSTR lpszSearchFile, LPWIN32_FIND_DATAW lpFindFileData, DWORD dwFlags, DWORD_PTR dwContext)
759{
760 ftp_session_t *lpwfs;
761 appinfo_t *hIC = NULL;
762 HINTERNET r = NULL;
763
764 lpwfs = (ftp_session_t*) get_handle_object( hConnect );
765 if (NULL == lpwfs || WH_HFTPSESSION != lpwfs->hdr.htype)
766 {
768 goto lend;
769 }
770
771 if (lpwfs->download_in_progress != NULL)
772 {
774 goto lend;
775 }
776
777 hIC = lpwfs->lpAppInfo;
779 {
781
783 task->search_file = wcsdup(lpszSearchFile);
784 task->find_file_data = lpFindFileData;
785 task->flags = dwFlags;
786 task->context = dwContext;
787
789 r = NULL;
790 }
791 else
792 {
793 r = FTP_FtpFindFirstFileW(lpwfs, lpszSearchFile, lpFindFileData,
794 dwFlags, dwContext);
795 }
796lend:
797 if( lpwfs )
798 WININET_Release( &lpwfs->hdr );
799
800 return r;
801}
802
803
804/***********************************************************************
805 * FTP_FtpFindFirstFileW (Internal)
806 *
807 * Search the specified directory
808 *
809 * RETURNS
810 * HINTERNET on success
811 * NULL on failure
812 *
813 */
815 LPCWSTR lpszSearchFile, LPWIN32_FIND_DATAW lpFindFileData, DWORD dwFlags, DWORD_PTR dwContext)
816{
817 INT nResCode;
818 appinfo_t *hIC = NULL;
819 HINTERNET hFindNext = NULL;
820 LPWSTR lpszSearchPath = NULL;
821
822 TRACE("\n");
823
824 /* Clear any error information */
826
827 if (!FTP_InitListenSocket(lpwfs))
828 goto lend;
829
831 goto lend;
832
833 if (!FTP_SendPortOrPasv(lpwfs))
834 goto lend;
835
836 /* split search path into file and path */
837 if (lpszSearchFile)
838 {
839 LPCWSTR name = lpszSearchFile, p;
840 if ((p = wcsrchr( name, '\\' ))) name = p + 1;
841 if ((p = wcsrchr( name, '/' ))) name = p + 1;
842 if (name != lpszSearchFile)
843 {
844 lpszSearchPath = strndupW(lpszSearchFile, name - lpszSearchFile);
845 lpszSearchFile = name;
846 }
847 }
848
849 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_LIST, lpszSearchPath,
850 lpwfs->hdr.lpfnStatusCB, &lpwfs->hdr, lpwfs->hdr.dwContext))
851 goto lend;
852
853 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
854 if (nResCode)
855 {
856 if (nResCode == 125 || nResCode == 150)
857 {
858 INT nDataSocket;
859
860 /* Get data socket to server */
861 if (FTP_GetDataSocket(lpwfs, &nDataSocket))
862 {
863 hFindNext = FTP_ReceiveFileList(lpwfs, nDataSocket, lpszSearchFile, lpFindFileData, dwContext);
864 closesocket(nDataSocket);
865 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
866 if (nResCode != 226 && nResCode != 250)
868 }
869 }
870 else
871 FTP_SetResponseError(nResCode);
872 }
873
874lend:
875 free(lpszSearchPath);
876
877 if (lpwfs->lstnSocket != -1)
878 {
879 closesocket(lpwfs->lstnSocket);
880 lpwfs->lstnSocket = -1;
881 }
882
883 hIC = lpwfs->lpAppInfo;
885 {
887
888 if (hFindNext)
889 {
890 iar.dwResult = (DWORD_PTR)hFindNext;
893 &iar, sizeof(INTERNET_ASYNC_RESULT));
894 }
895
896 iar.dwResult = (DWORD_PTR)hFindNext;
897 iar.dwError = hFindNext ? ERROR_SUCCESS : INTERNET_GetLastError();
899 &iar, sizeof(INTERNET_ASYNC_RESULT));
900 }
901
902 return hFindNext;
903}
904
905
906/***********************************************************************
907 * FtpGetCurrentDirectoryA (WININET.@)
908 *
909 * Retrieves the current directory
910 *
911 * RETURNS
912 * TRUE on success
913 * FALSE on failure
914 *
915 */
916BOOL WINAPI FtpGetCurrentDirectoryA(HINTERNET hFtpSession, LPSTR lpszCurrentDirectory,
917 LPDWORD lpdwCurrentDirectory)
918{
919 WCHAR *dir = NULL;
920 DWORD len;
921 BOOL ret;
922
923 if(lpdwCurrentDirectory) {
924 len = *lpdwCurrentDirectory;
925 if(lpszCurrentDirectory)
926 {
927 dir = malloc(len * sizeof(WCHAR));
928 if (NULL == dir)
929 {
931 return FALSE;
932 }
933 }
934 }
935 ret = FtpGetCurrentDirectoryW(hFtpSession, lpszCurrentDirectory?dir:NULL, lpdwCurrentDirectory?&len:NULL);
936
937 if (ret && lpszCurrentDirectory)
938 WideCharToMultiByte(CP_ACP, 0, dir, -1, lpszCurrentDirectory, len, NULL, NULL);
939
940 if (lpdwCurrentDirectory) *lpdwCurrentDirectory = len;
941 free(dir);
942 return ret;
943}
944
945typedef struct {
950
952{
955
956 TRACE("%p\n", session);
957
958 FTP_FtpGetCurrentDirectoryW(session, task->directory, task->directory_len);
959}
960
961/***********************************************************************
962 * FtpGetCurrentDirectoryW (WININET.@)
963 *
964 * Retrieves the current directory
965 *
966 * RETURNS
967 * TRUE on success
968 * FALSE on failure
969 *
970 */
971BOOL WINAPI FtpGetCurrentDirectoryW(HINTERNET hFtpSession, LPWSTR lpszCurrentDirectory,
972 LPDWORD lpdwCurrentDirectory)
973{
974 ftp_session_t *lpwfs;
975 appinfo_t *hIC = NULL;
976 BOOL r = FALSE;
977
978 TRACE("%p %p %p\n", hFtpSession, lpszCurrentDirectory, lpdwCurrentDirectory);
979
980 lpwfs = (ftp_session_t*) get_handle_object( hFtpSession );
981 if (NULL == lpwfs)
982 {
984 goto lend;
985 }
986
987 if (WH_HFTPSESSION != lpwfs->hdr.htype)
988 {
990 goto lend;
991 }
992
993 if (!lpdwCurrentDirectory)
994 {
996 goto lend;
997 }
998
999 if (lpszCurrentDirectory == NULL)
1000 {
1002 goto lend;
1003 }
1004
1005 if (lpwfs->download_in_progress != NULL)
1006 {
1008 goto lend;
1009 }
1010
1011 hIC = lpwfs->lpAppInfo;
1012 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
1013 {
1015
1017 task->directory = lpszCurrentDirectory;
1018 task->directory_len = lpdwCurrentDirectory;
1019
1021 }
1022 else
1023 {
1024 r = FTP_FtpGetCurrentDirectoryW(lpwfs, lpszCurrentDirectory,
1025 lpdwCurrentDirectory);
1026 }
1027
1028lend:
1029 if( lpwfs )
1030 WININET_Release( &lpwfs->hdr );
1031
1032 return r;
1033}
1034
1035
1036/***********************************************************************
1037 * FTP_FtpGetCurrentDirectoryW (Internal)
1038 *
1039 * Retrieves the current directory
1040 *
1041 * RETURNS
1042 * TRUE on success
1043 * FALSE on failure
1044 *
1045 */
1046static BOOL FTP_FtpGetCurrentDirectoryW(ftp_session_t *lpwfs, LPWSTR lpszCurrentDirectory,
1047 LPDWORD lpdwCurrentDirectory)
1048{
1049 INT nResCode;
1050 appinfo_t *hIC = NULL;
1051 BOOL bSuccess = FALSE;
1052
1053 /* Clear any error information */
1055
1056 hIC = lpwfs->lpAppInfo;
1058 lpwfs->hdr.lpfnStatusCB, &lpwfs->hdr, lpwfs->hdr.dwContext))
1059 goto lend;
1060
1061 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
1062 if (nResCode)
1063 {
1064 if (nResCode == 257) /* Extract directory name */
1065 {
1066 DWORD firstpos, lastpos, len;
1067 WCHAR *lpszResponseBuffer = strdupAtoW(INTERNET_GetResponseBuffer());
1068
1069 for (firstpos = 0, lastpos = 0; lpszResponseBuffer[lastpos]; lastpos++)
1070 {
1071 if ('"' == lpszResponseBuffer[lastpos])
1072 {
1073 if (!firstpos)
1074 firstpos = lastpos;
1075 else
1076 break;
1077 }
1078 }
1079 len = lastpos - firstpos;
1080 if (*lpdwCurrentDirectory >= len)
1081 {
1082 memcpy(lpszCurrentDirectory, &lpszResponseBuffer[firstpos + 1], len * sizeof(WCHAR));
1083 lpszCurrentDirectory[len - 1] = 0;
1084 *lpdwCurrentDirectory = len;
1085 bSuccess = TRUE;
1086 }
1088
1089 free(lpszResponseBuffer);
1090 }
1091 else
1092 FTP_SetResponseError(nResCode);
1093 }
1094
1095lend:
1096 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
1097 {
1099
1100 iar.dwResult = bSuccess;
1103 &iar, sizeof(INTERNET_ASYNC_RESULT));
1104 }
1105
1106 return bSuccess;
1107}
1108
1109
1110/***********************************************************************
1111 * FTPFILE_Destroy(internal)
1112 *
1113 * Closes the file transfer handle. This also 'cleans' the data queue of
1114 * the 'transfer complete' message (this is a bit of a hack though :-/ )
1115 *
1116 */
1118{
1119 ftp_file_t *lpwh = (ftp_file_t*) hdr;
1120 ftp_session_t *lpwfs = lpwh->lpFtpSession;
1121 INT nResCode;
1122
1123 TRACE("\n");
1124
1127
1128 free(lpwh->cache_file);
1129
1130 if (!lpwh->session_deleted)
1131 lpwfs->download_in_progress = NULL;
1132
1133 if (lpwh->nDataSocket != -1)
1134 closesocket(lpwh->nDataSocket);
1135
1136 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
1137 if (nResCode > 0 && nResCode != 226) WARN("server reports failed transfer\n");
1138
1140}
1141
1143{
1144 switch(option) {
1146 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
1147
1148 if (*size < sizeof(ULONG))
1150
1151 *size = sizeof(DWORD);
1153 return ERROR_SUCCESS;
1155 {
1158
1159 TRACE("INTERNET_OPTION_DATAFILE_NAME\n");
1160
1161 if (!file->cache_file)
1162 {
1163 *size = 0;
1165 }
1166 if (unicode)
1167 {
1168 required = (lstrlenW(file->cache_file) + 1) * sizeof(WCHAR);
1169 if (*size < required)
1171
1172 *size = required;
1173 memcpy(buffer, file->cache_file, *size);
1174 return ERROR_SUCCESS;
1175 }
1176 else
1177 {
1178 required = WideCharToMultiByte(CP_ACP, 0, file->cache_file, -1, NULL, 0, NULL, NULL);
1179 if (required > *size)
1181
1182 *size = WideCharToMultiByte(CP_ACP, 0, file->cache_file, -1, buffer, *size, NULL, NULL);
1183 return ERROR_SUCCESS;
1184 }
1185 }
1186 }
1187 return INET_QueryOption(hdr, option, buffer, size, unicode);
1188}
1189
1192{
1194 int res;
1195 DWORD error;
1196
1197 if (file->nDataSocket == -1)
1199
1200 /* FIXME: FTP should use NETCON_ stuff */
1201 res = sock_recv(file->nDataSocket, buffer, size, MSG_WAITALL);
1202 *read = res>0 ? res : 0;
1203
1204 error = res >= 0 ? ERROR_SUCCESS : INTERNET_ERROR_BASE; /* FIXME */
1205 if (error == ERROR_SUCCESS && file->cache_file)
1206 {
1207 DWORD bytes_written;
1208
1209 if (!WriteFile(file->cache_file_handle, buffer, *read, &bytes_written, NULL))
1210 WARN("WriteFile failed: %lu\n", GetLastError());
1211 }
1212 return error;
1213}
1214
1216{
1217 ftp_file_t *lpwh = (ftp_file_t*) hdr;
1218 int res;
1219
1220 res = sock_send(lpwh->nDataSocket, buffer, size, 0);
1221
1222 *written = res>0 ? res : 0;
1223 return res >= 0 ? ERROR_SUCCESS : WSAGetLastError();
1224}
1225
1226static void FTP_ReceiveRequestData(ftp_file_t *file, BOOL first_notif)
1227{
1229 BYTE buffer[4096];
1230 int available;
1231
1232 TRACE("%p\n", file);
1233
1234 available = sock_recv(file->nDataSocket, buffer, sizeof(buffer), MSG_PEEK);
1235
1236 if(available != -1) {
1237 iar.dwResult = (DWORD_PTR)file->hdr.hInternet;
1238 iar.dwError = first_notif ? 0 : available;
1239 }else {
1240 iar.dwResult = 0;
1242 }
1243
1245 sizeof(INTERNET_ASYNC_RESULT));
1246}
1247
1249{
1250 ftp_file_t *file = (ftp_file_t*)task->hdr;
1251
1253}
1254
1256{
1258 ULONG unread = 0;
1259 int retval;
1260
1261 TRACE("(%p %p %lx %Ix)\n", file, available, flags, ctx);
1262
1263 retval = ioctlsocket(file->nDataSocket, FIONREAD, &unread);
1264 if (!retval)
1265 TRACE("%ld bytes of queued, but unread data\n", unread);
1266
1267 *available = unread;
1268
1269 if(!unread) {
1270 BYTE byte;
1271
1272 *available = 0;
1273
1274 retval = sock_recv(file->nDataSocket, &byte, 1, MSG_PEEK);
1275 if(retval > 0) {
1277
1280
1281 return ERROR_IO_PENDING;
1282 }
1283 }
1284
1285 return ERROR_SUCCESS;
1286}
1287
1289{
1291 FIXME("%p\n", file);
1292 return ERROR_NOT_SUPPORTED;
1293}
1294
1297 NULL,
1300 NULL,
1304 NULL,
1306};
1307
1308/***********************************************************************
1309 * FTP_FtpOpenFileW (Internal)
1310 *
1311 * Open a remote file for writing or reading
1312 *
1313 * RETURNS
1314 * HINTERNET handle on success
1315 * NULL on failure
1316 *
1317 */
1319 LPCWSTR lpszFileName, DWORD fdwAccess, DWORD dwFlags,
1320 DWORD_PTR dwContext)
1321{
1322 INT nDataSocket;
1323 BOOL bSuccess = FALSE;
1324 ftp_file_t *lpwh = NULL;
1325 appinfo_t *hIC = NULL;
1326
1327 TRACE("\n");
1328
1329 /* Clear any error information */
1331
1332 if (GENERIC_READ == fdwAccess)
1333 {
1334 /* Set up socket to retrieve data */
1335 bSuccess = FTP_SendRetrieve(lpwfs, lpszFileName, dwFlags);
1336 }
1337 else if (GENERIC_WRITE == fdwAccess)
1338 {
1339 /* Set up socket to send data */
1340 bSuccess = FTP_SendStore(lpwfs, lpszFileName, dwFlags);
1341 }
1342
1343 /* Get data socket to server */
1344 if (bSuccess && FTP_GetDataSocket(lpwfs, &nDataSocket))
1345 {
1346 lpwh = alloc_object(&lpwfs->hdr, &FTPFILEVtbl, sizeof(ftp_file_t));
1347 lpwh->hdr.htype = WH_HFILE;
1348 lpwh->hdr.dwFlags = dwFlags;
1349 lpwh->hdr.dwContext = dwContext;
1350 lpwh->nDataSocket = nDataSocket;
1351 lpwh->cache_file = NULL;
1353 lpwh->session_deleted = FALSE;
1354
1355 WININET_AddRef( &lpwfs->hdr );
1356 lpwh->lpFtpSession = lpwfs;
1357 list_add_head( &lpwfs->hdr.children, &lpwh->hdr.entry );
1358
1359 /* Indicate that a download is currently in progress */
1360 lpwfs->download_in_progress = lpwh;
1361 }
1362
1363 if (lpwfs->lstnSocket != -1)
1364 {
1365 closesocket(lpwfs->lstnSocket);
1366 lpwfs->lstnSocket = -1;
1367 }
1368
1369 if (bSuccess && fdwAccess == GENERIC_READ)
1370 {
1371 WCHAR filename[MAX_PATH + 1];
1372 URL_COMPONENTSW uc;
1373 DWORD len;
1374
1375 memset(&uc, 0, sizeof(uc));
1376 uc.dwStructSize = sizeof(uc);
1378 uc.lpszHostName = lpwfs->servername;
1379 uc.nPort = lpwfs->serverport;
1380 uc.lpszUserName = lpwfs->lpszUserName;
1381 uc.lpszUrlPath = wcsdup(lpszFileName);
1382
1384 {
1385 WCHAR *url = malloc(len * sizeof(WCHAR));
1386
1387 if (url && InternetCreateUrlW(&uc, 0, url, &len) && CreateUrlCacheEntryW(url, 0, NULL, filename, 0))
1388 {
1389 lpwh->cache_file = wcsdup(filename);
1393 {
1394 WARN("Could not create cache file: %lu\n", GetLastError());
1395 free(lpwh->cache_file);
1396 lpwh->cache_file = NULL;
1397 }
1398 }
1399 free(url);
1400 }
1401 free(uc.lpszUrlPath);
1402 }
1403
1404 hIC = lpwfs->lpAppInfo;
1405 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
1406 {
1408
1409 if (lpwh)
1410 {
1411 iar.dwResult = (DWORD_PTR)lpwh->hdr.hInternet;
1412 iar.dwError = ERROR_SUCCESS;
1414 &iar, sizeof(INTERNET_ASYNC_RESULT));
1415 }
1416
1417 if(bSuccess) {
1419 }else {
1420 iar.dwResult = 0;
1423 &iar, sizeof(INTERNET_ASYNC_RESULT));
1424 }
1425 }
1426
1427 if(!bSuccess)
1428 return FALSE;
1429
1430 return lpwh->hdr.hInternet;
1431}
1432
1433
1434/***********************************************************************
1435 * FtpOpenFileA (WININET.@)
1436 *
1437 * Open a remote file for writing or reading
1438 *
1439 * RETURNS
1440 * HINTERNET handle on success
1441 * NULL on failure
1442 *
1443 */
1445 LPCSTR lpszFileName, DWORD fdwAccess, DWORD dwFlags,
1446 DWORD_PTR dwContext)
1447{
1448 LPWSTR lpwzFileName;
1449 HINTERNET ret;
1450
1451 lpwzFileName = strdupAtoW(lpszFileName);
1452 ret = FtpOpenFileW(hFtpSession, lpwzFileName, fdwAccess, dwFlags, dwContext);
1453 free(lpwzFileName);
1454 return ret;
1455}
1456
1457typedef struct {
1464
1466{
1469
1470 TRACE("%p\n", session);
1471
1472 FTP_FtpOpenFileW(session, task->file_name, task->access, task->flags, task->context);
1473 free(task->file_name);
1474}
1475
1476/***********************************************************************
1477 * FtpOpenFileW (WININET.@)
1478 *
1479 * Open a remote file for writing or reading
1480 *
1481 * RETURNS
1482 * HINTERNET handle on success
1483 * NULL on failure
1484 *
1485 */
1487 LPCWSTR lpszFileName, DWORD fdwAccess, DWORD dwFlags,
1488 DWORD_PTR dwContext)
1489{
1490 ftp_session_t *lpwfs;
1491 appinfo_t *hIC = NULL;
1492 HINTERNET r = NULL;
1493
1494 TRACE("(%p,%s,0x%08lx,0x%08lx,0x%08Ix)\n", hFtpSession,
1495 debugstr_w(lpszFileName), fdwAccess, dwFlags, dwContext);
1496
1497 lpwfs = (ftp_session_t*) get_handle_object( hFtpSession );
1498 if (!lpwfs)
1499 {
1501 return FALSE;
1502 }
1503
1504 if (WH_HFTPSESSION != lpwfs->hdr.htype)
1505 {
1507 goto lend;
1508 }
1509
1510 if ((!lpszFileName) ||
1511 ((fdwAccess != GENERIC_READ) && (fdwAccess != GENERIC_WRITE)) ||
1513 {
1515 goto lend;
1516 }
1517
1518 if (lpwfs->download_in_progress != NULL)
1519 {
1521 goto lend;
1522 }
1523
1524 hIC = lpwfs->lpAppInfo;
1525 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
1526 {
1528
1529 task = alloc_async_task(&lpwfs->hdr, AsyncFtpOpenFileProc, sizeof(*task));
1530 task->file_name = wcsdup(lpszFileName);
1531 task->access = fdwAccess;
1532 task->flags = dwFlags;
1533 task->context = dwContext;
1534
1535 INTERNET_AsyncCall(&task->hdr);
1536 r = NULL;
1537 }
1538 else
1539 {
1540 r = FTP_FtpOpenFileW(lpwfs, lpszFileName, fdwAccess, dwFlags, dwContext);
1541 }
1542
1543lend:
1544 WININET_Release( &lpwfs->hdr );
1545
1546 return r;
1547}
1548
1549
1550/***********************************************************************
1551 * FtpGetFileA (WININET.@)
1552 *
1553 * Retrieve file from the FTP server
1554 *
1555 * RETURNS
1556 * TRUE on success
1557 * FALSE on failure
1558 *
1559 */
1560BOOL WINAPI FtpGetFileA(HINTERNET hInternet, LPCSTR lpszRemoteFile, LPCSTR lpszNewFile,
1561 BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags,
1562 DWORD_PTR dwContext)
1563{
1564 LPWSTR lpwzRemoteFile;
1565 LPWSTR lpwzNewFile;
1566 BOOL ret;
1567
1568 lpwzRemoteFile = strdupAtoW(lpszRemoteFile);
1569 lpwzNewFile = strdupAtoW(lpszNewFile);
1570 ret = FtpGetFileW(hInternet, lpwzRemoteFile, lpwzNewFile, fFailIfExists,
1571 dwLocalFlagsAttribute, dwInternetFlags, dwContext);
1572 free(lpwzRemoteFile);
1573 free(lpwzNewFile);
1574 return ret;
1575}
1576
1577typedef struct {
1586
1588{
1591
1592 TRACE("%p\n", session);
1593
1594 FTP_FtpGetFileW(session, task->remote_file, task->new_file, task->fail_if_exists,
1595 task->local_attr, task->flags, task->context);
1596 free(task->remote_file);
1597 free(task->new_file);
1598}
1599
1600
1601/***********************************************************************
1602 * FtpGetFileW (WININET.@)
1603 *
1604 * Retrieve file from the FTP server
1605 *
1606 * RETURNS
1607 * TRUE on success
1608 * FALSE on failure
1609 *
1610 */
1611BOOL WINAPI FtpGetFileW(HINTERNET hInternet, LPCWSTR lpszRemoteFile, LPCWSTR lpszNewFile,
1612 BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags,
1613 DWORD_PTR dwContext)
1614{
1615 ftp_session_t *lpwfs;
1616 appinfo_t *hIC = NULL;
1617 BOOL r = FALSE;
1618
1619 if (!lpszRemoteFile || !lpszNewFile)
1620 {
1622 return FALSE;
1623 }
1624
1625 lpwfs = (ftp_session_t*) get_handle_object( hInternet );
1626 if (!lpwfs)
1627 {
1629 return FALSE;
1630 }
1631
1632 if (WH_HFTPSESSION != lpwfs->hdr.htype)
1633 {
1635 goto lend;
1636 }
1637
1638 if ((dwInternetFlags & FTP_CONDITION_MASK) > FTP_TRANSFER_TYPE_BINARY)
1639 {
1641 goto lend;
1642 }
1643
1644 if (lpwfs->download_in_progress != NULL)
1645 {
1647 goto lend;
1648 }
1649
1650 hIC = lpwfs->lpAppInfo;
1651 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
1652 {
1654
1655 task = alloc_async_task(&lpwfs->hdr, AsyncFtpGetFileProc, sizeof(*task));
1656 task->remote_file = wcsdup(lpszRemoteFile);
1657 task->new_file = wcsdup(lpszNewFile);
1658 task->local_attr = dwLocalFlagsAttribute;
1659 task->fail_if_exists = fFailIfExists;
1660 task->flags = dwInternetFlags;
1661 task->context = dwContext;
1662
1664 }
1665 else
1666 {
1667 r = FTP_FtpGetFileW(lpwfs, lpszRemoteFile, lpszNewFile,
1668 fFailIfExists, dwLocalFlagsAttribute, dwInternetFlags, dwContext);
1669 }
1670
1671lend:
1672 WININET_Release( &lpwfs->hdr );
1673
1674 return r;
1675}
1676
1677
1678/***********************************************************************
1679 * FTP_FtpGetFileW (Internal)
1680 *
1681 * Retrieve file from the FTP server
1682 *
1683 * RETURNS
1684 * TRUE on success
1685 * FALSE on failure
1686 *
1687 */
1688static BOOL FTP_FtpGetFileW(ftp_session_t *lpwfs, LPCWSTR lpszRemoteFile, LPCWSTR lpszNewFile,
1689 BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags,
1690 DWORD_PTR dwContext)
1691{
1692 BOOL bSuccess = FALSE;
1693 HANDLE hFile;
1694 appinfo_t *hIC = NULL;
1695
1696 TRACE("lpszRemoteFile(%s) lpszNewFile(%s)\n", debugstr_w(lpszRemoteFile), debugstr_w(lpszNewFile));
1697
1698 /* Clear any error information */
1700
1701 /* Ensure we can write to lpszNewfile by opening it */
1702 hFile = CreateFileW(lpszNewFile, GENERIC_WRITE, 0, 0, fFailIfExists ?
1703 CREATE_NEW : CREATE_ALWAYS, dwLocalFlagsAttribute, 0);
1705 return FALSE;
1706
1707 /* Set up socket to retrieve data */
1708 if (FTP_SendRetrieve(lpwfs, lpszRemoteFile, dwInternetFlags))
1709 {
1710 INT nDataSocket;
1711
1712 /* Get data socket to server */
1713 if (FTP_GetDataSocket(lpwfs, &nDataSocket))
1714 {
1715 INT nResCode;
1716
1717 /* Receive data */
1718 FTP_RetrieveFileData(lpwfs, nDataSocket, hFile);
1719 closesocket(nDataSocket);
1720
1721 nResCode = FTP_ReceiveResponse(lpwfs, dwContext);
1722 if (nResCode)
1723 {
1724 if (nResCode == 226)
1725 bSuccess = TRUE;
1726 else
1727 FTP_SetResponseError(nResCode);
1728 }
1729 }
1730 }
1731
1732 if (lpwfs->lstnSocket != -1)
1733 {
1734 closesocket(lpwfs->lstnSocket);
1735 lpwfs->lstnSocket = -1;
1736 }
1737
1739
1740 hIC = lpwfs->lpAppInfo;
1741 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
1742 {
1744
1745 iar.dwResult = (DWORD)bSuccess;
1746 iar.dwError = bSuccess ? ERROR_SUCCESS : INTERNET_GetLastError();
1748 &iar, sizeof(INTERNET_ASYNC_RESULT));
1749 }
1750
1751 if (!bSuccess) DeleteFileW(lpszNewFile);
1752 return bSuccess;
1753}
1754
1755/***********************************************************************
1756 * FtpGetFileSize (WININET.@)
1757 */
1759{
1760 FIXME("(%p, %p)\n", hFile, lpdwFileSizeHigh);
1761
1762 if (lpdwFileSizeHigh)
1763 *lpdwFileSizeHigh = 0;
1764
1765 return 0;
1766}
1767
1768/***********************************************************************
1769 * FtpDeleteFileA (WININET.@)
1770 *
1771 * Delete a file on the ftp server
1772 *
1773 * RETURNS
1774 * TRUE on success
1775 * FALSE on failure
1776 *
1777 */
1778BOOL WINAPI FtpDeleteFileA(HINTERNET hFtpSession, LPCSTR lpszFileName)
1779{
1780 LPWSTR lpwzFileName;
1781 BOOL ret;
1782
1783 lpwzFileName = strdupAtoW(lpszFileName);
1784 ret = FtpDeleteFileW(hFtpSession, lpwzFileName);
1785 free(lpwzFileName);
1786 return ret;
1787}
1788
1789typedef struct {
1793
1795{
1798
1799 TRACE("%p\n", session);
1800
1801 FTP_FtpDeleteFileW(session, task->file_name);
1802 free(task->file_name);
1803}
1804
1805/***********************************************************************
1806 * FtpDeleteFileW (WININET.@)
1807 *
1808 * Delete a file on the ftp server
1809 *
1810 * RETURNS
1811 * TRUE on success
1812 * FALSE on failure
1813 *
1814 */
1815BOOL WINAPI FtpDeleteFileW(HINTERNET hFtpSession, LPCWSTR lpszFileName)
1816{
1817 ftp_session_t *lpwfs;
1818 appinfo_t *hIC = NULL;
1819 BOOL r = FALSE;
1820
1821 lpwfs = (ftp_session_t*) get_handle_object( hFtpSession );
1822 if (!lpwfs)
1823 {
1825 return FALSE;
1826 }
1827
1828 if (WH_HFTPSESSION != lpwfs->hdr.htype)
1829 {
1831 goto lend;
1832 }
1833
1834 if (lpwfs->download_in_progress != NULL)
1835 {
1837 goto lend;
1838 }
1839
1840 if (!lpszFileName)
1841 {
1843 goto lend;
1844 }
1845
1846 hIC = lpwfs->lpAppInfo;
1847 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
1848 {
1850
1851 task = alloc_async_task(&lpwfs->hdr, AsyncFtpDeleteFileProc, sizeof(*task));
1852 task->file_name = wcsdup(lpszFileName);
1853
1855 }
1856 else
1857 {
1858 r = FTP_FtpDeleteFileW(lpwfs, lpszFileName);
1859 }
1860
1861lend:
1862 WININET_Release( &lpwfs->hdr );
1863
1864 return r;
1865}
1866
1867/***********************************************************************
1868 * FTP_FtpDeleteFileW (Internal)
1869 *
1870 * Delete a file on the ftp server
1871 *
1872 * RETURNS
1873 * TRUE on success
1874 * FALSE on failure
1875 *
1876 */
1878{
1879 INT nResCode;
1880 BOOL bSuccess = FALSE;
1881 appinfo_t *hIC = NULL;
1882
1883 TRACE("%p\n", lpwfs);
1884
1885 /* Clear any error information */
1887
1888 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_DELE, lpszFileName, 0, 0, 0))
1889 goto lend;
1890
1891 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
1892 if (nResCode)
1893 {
1894 if (nResCode == 250)
1895 bSuccess = TRUE;
1896 else
1897 FTP_SetResponseError(nResCode);
1898 }
1899lend:
1900 hIC = lpwfs->lpAppInfo;
1901 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
1902 {
1904
1905 iar.dwResult = (DWORD)bSuccess;
1906 iar.dwError = bSuccess ? ERROR_SUCCESS : INTERNET_GetLastError();
1908 &iar, sizeof(INTERNET_ASYNC_RESULT));
1909 }
1910
1911 return bSuccess;
1912}
1913
1914
1915/***********************************************************************
1916 * FtpRemoveDirectoryA (WININET.@)
1917 *
1918 * Remove a directory on the ftp server
1919 *
1920 * RETURNS
1921 * TRUE on success
1922 * FALSE on failure
1923 *
1924 */
1926{
1927 LPWSTR lpwzDirectory;
1928 BOOL ret;
1929
1930 lpwzDirectory = strdupAtoW(lpszDirectory);
1931 ret = FtpRemoveDirectoryW(hFtpSession, lpwzDirectory);
1932 free(lpwzDirectory);
1933 return ret;
1934}
1935
1937{
1940
1941 TRACE("%p\n", session);
1942
1944 free(task->directory);
1945}
1946
1947/***********************************************************************
1948 * FtpRemoveDirectoryW (WININET.@)
1949 *
1950 * Remove a directory on the ftp server
1951 *
1952 * RETURNS
1953 * TRUE on success
1954 * FALSE on failure
1955 *
1956 */
1958{
1959 ftp_session_t *lpwfs;
1960 appinfo_t *hIC = NULL;
1961 BOOL r = FALSE;
1962
1963 lpwfs = (ftp_session_t*) get_handle_object( hFtpSession );
1964 if (!lpwfs)
1965 {
1967 return FALSE;
1968 }
1969
1970 if (WH_HFTPSESSION != lpwfs->hdr.htype)
1971 {
1973 goto lend;
1974 }
1975
1976 if (lpwfs->download_in_progress != NULL)
1977 {
1979 goto lend;
1980 }
1981
1982 if (!lpszDirectory)
1983 {
1985 goto lend;
1986 }
1987
1988 hIC = lpwfs->lpAppInfo;
1989 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
1990 {
1992
1994 task->directory = wcsdup(lpszDirectory);
1995
1997 }
1998 else
1999 {
2000 r = FTP_FtpRemoveDirectoryW(lpwfs, lpszDirectory);
2001 }
2002
2003lend:
2004 WININET_Release( &lpwfs->hdr );
2005
2006 return r;
2007}
2008
2009/***********************************************************************
2010 * FTP_FtpRemoveDirectoryW (Internal)
2011 *
2012 * Remove a directory on the ftp server
2013 *
2014 * RETURNS
2015 * TRUE on success
2016 * FALSE on failure
2017 *
2018 */
2020{
2021 INT nResCode;
2022 BOOL bSuccess = FALSE;
2023 appinfo_t *hIC = NULL;
2024
2025 TRACE("\n");
2026
2027 /* Clear any error information */
2029
2030 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_RMD, lpszDirectory, 0, 0, 0))
2031 goto lend;
2032
2033 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
2034 if (nResCode)
2035 {
2036 if (nResCode == 250)
2037 bSuccess = TRUE;
2038 else
2039 FTP_SetResponseError(nResCode);
2040 }
2041
2042lend:
2043 hIC = lpwfs->lpAppInfo;
2044 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
2045 {
2047
2048 iar.dwResult = (DWORD)bSuccess;
2049 iar.dwError = bSuccess ? ERROR_SUCCESS : INTERNET_GetLastError();
2051 &iar, sizeof(INTERNET_ASYNC_RESULT));
2052 }
2053
2054 return bSuccess;
2055}
2056
2057
2058/***********************************************************************
2059 * FtpRenameFileA (WININET.@)
2060 *
2061 * Rename a file on the ftp server
2062 *
2063 * RETURNS
2064 * TRUE on success
2065 * FALSE on failure
2066 *
2067 */
2069{
2070 LPWSTR lpwzSrc;
2071 LPWSTR lpwzDest;
2072 BOOL ret;
2073
2074 lpwzSrc = strdupAtoW(lpszSrc);
2075 lpwzDest = strdupAtoW(lpszDest);
2076 ret = FtpRenameFileW(hFtpSession, lpwzSrc, lpwzDest);
2077 free(lpwzSrc);
2078 free(lpwzDest);
2079 return ret;
2080}
2081
2082typedef struct {
2087
2089{
2092
2093 TRACE("%p\n", session);
2094
2095 FTP_FtpRenameFileW(session, task->src_file, task->dst_file);
2096 free(task->src_file);
2097 free(task->dst_file);
2098}
2099
2100/***********************************************************************
2101 * FtpRenameFileW (WININET.@)
2102 *
2103 * Rename a file on the ftp server
2104 *
2105 * RETURNS
2106 * TRUE on success
2107 * FALSE on failure
2108 *
2109 */
2111{
2112 ftp_session_t *lpwfs;
2113 appinfo_t *hIC = NULL;
2114 BOOL r = FALSE;
2115
2116 lpwfs = (ftp_session_t*) get_handle_object( hFtpSession );
2117 if (!lpwfs)
2118 {
2120 return FALSE;
2121 }
2122
2123 if (WH_HFTPSESSION != lpwfs->hdr.htype)
2124 {
2126 goto lend;
2127 }
2128
2129 if (lpwfs->download_in_progress != NULL)
2130 {
2132 goto lend;
2133 }
2134
2135 if (!lpszSrc || !lpszDest)
2136 {
2138 goto lend;
2139 }
2140
2141 hIC = lpwfs->lpAppInfo;
2142 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
2143 {
2145
2146 task = alloc_async_task(&lpwfs->hdr, AsyncFtpRenameFileProc, sizeof(*task));
2147 task->src_file = wcsdup(lpszSrc);
2148 task->dst_file = wcsdup(lpszDest);
2149
2151 }
2152 else
2153 {
2154 r = FTP_FtpRenameFileW(lpwfs, lpszSrc, lpszDest);
2155 }
2156
2157lend:
2158 WININET_Release( &lpwfs->hdr );
2159
2160 return r;
2161}
2162
2163/***********************************************************************
2164 * FTP_FtpRenameFileW (Internal)
2165 *
2166 * Rename a file on the ftp server
2167 *
2168 * RETURNS
2169 * TRUE on success
2170 * FALSE on failure
2171 *
2172 */
2174{
2175 INT nResCode;
2176 BOOL bSuccess = FALSE;
2177 appinfo_t *hIC = NULL;
2178
2179 TRACE("\n");
2180
2181 /* Clear any error information */
2183
2184 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_RNFR, lpszSrc, 0, 0, 0))
2185 goto lend;
2186
2187 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
2188 if (nResCode == 350)
2189 {
2190 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_RNTO, lpszDest, 0, 0, 0))
2191 goto lend;
2192
2193 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
2194 }
2195
2196 if (nResCode == 250)
2197 bSuccess = TRUE;
2198 else
2199 FTP_SetResponseError(nResCode);
2200
2201lend:
2202 hIC = lpwfs->lpAppInfo;
2203 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
2204 {
2206
2207 iar.dwResult = (DWORD)bSuccess;
2208 iar.dwError = bSuccess ? ERROR_SUCCESS : INTERNET_GetLastError();
2210 &iar, sizeof(INTERNET_ASYNC_RESULT));
2211 }
2212
2213 return bSuccess;
2214}
2215
2216/***********************************************************************
2217 * FtpCommandA (WININET.@)
2218 */
2219BOOL WINAPI FtpCommandA( HINTERNET hConnect, BOOL fExpectResponse, DWORD dwFlags,
2220 LPCSTR lpszCommand, DWORD_PTR dwContext, HINTERNET* phFtpCommand )
2221{
2222 BOOL r;
2223 WCHAR *cmdW;
2224
2225 TRACE("%p %d 0x%08lx %s 0x%08Ix %p\n", hConnect, fExpectResponse, dwFlags,
2226 debugstr_a(lpszCommand), dwContext, phFtpCommand);
2227
2228 if (fExpectResponse)
2229 {
2230 FIXME("data connection not supported\n");
2231 return FALSE;
2232 }
2233
2234 if (!lpszCommand || !lpszCommand[0])
2235 {
2237 return FALSE;
2238 }
2239
2240 if (!(cmdW = strdupAtoW(lpszCommand)))
2241 {
2243 return FALSE;
2244 }
2245
2246 r = FtpCommandW(hConnect, fExpectResponse, dwFlags, cmdW, dwContext, phFtpCommand);
2247
2248 free(cmdW);
2249 return r;
2250}
2251
2252/***********************************************************************
2253 * FtpCommandW (WININET.@)
2254 */
2255BOOL WINAPI FtpCommandW( HINTERNET hConnect, BOOL fExpectResponse, DWORD dwFlags,
2256 LPCWSTR lpszCommand, DWORD_PTR dwContext, HINTERNET* phFtpCommand )
2257{
2258 BOOL r = FALSE;
2259 ftp_session_t *lpwfs;
2260 LPSTR cmd = NULL;
2261 DWORD len, nBytesSent= 0;
2262 INT nResCode, nRC = 0;
2263
2264 TRACE("%p %d 0x%08lx %s 0x%08Ix %p\n", hConnect, fExpectResponse, dwFlags,
2265 debugstr_w(lpszCommand), dwContext, phFtpCommand);
2266
2267 if (!lpszCommand || !lpszCommand[0])
2268 {
2270 return FALSE;
2271 }
2272
2273 if (fExpectResponse)
2274 {
2275 FIXME("data connection not supported\n");
2276 return FALSE;
2277 }
2278
2279 lpwfs = (ftp_session_t*) get_handle_object( hConnect );
2280 if (!lpwfs)
2281 {
2283 return FALSE;
2284 }
2285
2286 if (WH_HFTPSESSION != lpwfs->hdr.htype)
2287 {
2289 goto lend;
2290 }
2291
2292 if (lpwfs->download_in_progress != NULL)
2293 {
2295 goto lend;
2296 }
2297
2298 len = WideCharToMultiByte(CP_ACP, 0, lpszCommand, -1, NULL, 0, NULL, NULL) + strlen(szCRLF);
2299 if ((cmd = malloc(len)))
2300 WideCharToMultiByte(CP_ACP, 0, lpszCommand, -1, cmd, len, NULL, NULL);
2301 else
2302 {
2304 goto lend;
2305 }
2306
2307 strcat(cmd, szCRLF);
2308 len--;
2309
2310 TRACE("Sending (%s) len(%ld)\n", debugstr_a(cmd), len);
2311 while ((nBytesSent < len) && (nRC != -1))
2312 {
2313 nRC = sock_send(lpwfs->sndSocket, cmd + nBytesSent, len - nBytesSent, 0);
2314 if (nRC != -1)
2315 {
2316 nBytesSent += nRC;
2317 TRACE("Sent %d bytes\n", nRC);
2318 }
2319 }
2320
2321 if (nBytesSent)
2322 {
2323 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
2324 if (nResCode > 0 && nResCode < 400)
2325 r = TRUE;
2326 else
2327 FTP_SetResponseError(nResCode);
2328 }
2329
2330lend:
2331 WININET_Release( &lpwfs->hdr );
2332 free(cmd);
2333 return r;
2334}
2335
2336
2337/***********************************************************************
2338 * FTPSESSION_Destroy (internal)
2339 *
2340 * Deallocate session handle
2341 */
2343{
2344 ftp_session_t *lpwfs = (ftp_session_t*) hdr;
2345
2346 TRACE("\n");
2347
2348 WININET_Release(&lpwfs->lpAppInfo->hdr);
2349
2350 free(lpwfs->lpszPassword);
2351 free(lpwfs->lpszUserName);
2352 free(lpwfs->servername);
2353}
2354
2356{
2357 ftp_session_t *lpwfs = (ftp_session_t*) hdr;
2358
2359 TRACE("\n");
2360
2361 INTERNET_SendCallback(&lpwfs->hdr, lpwfs->hdr.dwContext,
2363
2364 if (lpwfs->download_in_progress != NULL)
2366
2367 if (lpwfs->sndSocket != -1)
2368 closesocket(lpwfs->sndSocket);
2369
2370 if (lpwfs->lstnSocket != -1)
2371 closesocket(lpwfs->lstnSocket);
2372
2373 if (lpwfs->pasvSocket != -1)
2374 closesocket(lpwfs->pasvSocket);
2375
2376 INTERNET_SendCallback(&lpwfs->hdr, lpwfs->hdr.dwContext,
2378}
2379
2381{
2382 switch(option) {
2384 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
2385
2386 if (*size < sizeof(ULONG))
2388
2389 *size = sizeof(DWORD);
2391 return ERROR_SUCCESS;
2392 }
2393
2394 return INET_QueryOption(hdr, option, buffer, size, unicode);
2395}
2396
2402 NULL,
2403 NULL,
2404 NULL,
2405 NULL,
2406 NULL
2407};
2408
2409
2410/***********************************************************************
2411 * FTP_Connect (internal)
2412 *
2413 * Connect to a ftp server
2414 *
2415 * RETURNS
2416 * HINTERNET a session handle on success
2417 * NULL on failure
2418 *
2419 * NOTES:
2420 *
2421 * Windows uses 'anonymous' as the username, when given a NULL username
2422 * and a NULL password. The password is first looked up in:
2423 *
2424 * HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\EmailName
2425 *
2426 * If this entry is not present it uses the current username as the password.
2427 *
2428 */
2429
2431 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
2433 DWORD dwInternalFlags)
2434{
2435 struct sockaddr_in socketAddr;
2436 INT nsocket = -1;
2437 socklen_t sock_namelen;
2438 BOOL bSuccess = FALSE;
2439 ftp_session_t *lpwfs = NULL;
2440 char szaddr[INET6_ADDRSTRLEN];
2441
2442 TRACE("%p Server(%s) Port(%d) User(%s) Paswd(%s)\n",
2443 hIC, debugstr_w(lpszServerName),
2444 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword));
2445
2446 assert( hIC->hdr.htype == WH_HINIT );
2447
2448 if ((!lpszUserName || !*lpszUserName) && lpszPassword && *lpszPassword)
2449 {
2451 return NULL;
2452 }
2453
2454 lpwfs = alloc_object(&hIC->hdr, &FTPSESSIONVtbl, sizeof(ftp_session_t));
2455 if (NULL == lpwfs)
2456 {
2458 return NULL;
2459 }
2460
2461 if (nServerPort == INTERNET_INVALID_PORT_NUMBER)
2463 else
2464 lpwfs->serverport = nServerPort;
2465
2466 lpwfs->hdr.htype = WH_HFTPSESSION;
2467 lpwfs->hdr.dwFlags = dwFlags;
2468 lpwfs->hdr.dwContext = dwContext;
2469 lpwfs->hdr.dwInternalFlags |= dwInternalFlags;
2470 lpwfs->download_in_progress = NULL;
2471 lpwfs->sndSocket = -1;
2472 lpwfs->lstnSocket = -1;
2473 lpwfs->pasvSocket = -1;
2474
2475 WININET_AddRef( &hIC->hdr );
2476 lpwfs->lpAppInfo = hIC;
2477 list_add_head( &hIC->hdr.children, &lpwfs->hdr.entry );
2478
2479 if(hIC->proxy && hIC->accessType == INTERNET_OPEN_TYPE_PROXY) {
2480 if(wcschr(hIC->proxy, ' '))
2481 FIXME("Several proxies not implemented.\n");
2482 if(hIC->proxyBypass)
2483 FIXME("Proxy bypass is ignored.\n");
2484 }
2485 if (!lpszUserName || !lpszUserName[0]) {
2486 HKEY key;
2487 WCHAR szPassword[MAX_PATH];
2488 DWORD len = sizeof(szPassword);
2489
2490 lpwfs->lpszUserName = wcsdup(L"anonymous");
2491
2492 RegOpenKeyW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", &key);
2493 if (RegQueryValueExW(key, L"EmailName", NULL, NULL, (LPBYTE)szPassword, &len)) {
2494 /* Nothing in the registry, get the username and use that as the password */
2495 if (!GetUserNameW(szPassword, &len)) {
2496 /* Should never get here, but use an empty password as failsafe */
2497 lstrcpyW(szPassword, L"");
2498 }
2499 }
2501
2502 TRACE("Password used for anonymous ftp : (%s)\n", debugstr_w(szPassword));
2503 lpwfs->lpszPassword = wcsdup(szPassword);
2504 }
2505 else {
2506 lpwfs->lpszUserName = wcsdup(lpszUserName);
2508 }
2509 lpwfs->servername = wcsdup(lpszServerName);
2510
2511 /* Don't send a handle created callback if this handle was created with InternetOpenUrl */
2512 if (!(lpwfs->hdr.dwInternalFlags & INET_OPENURL))
2513 {
2515
2516 iar.dwResult = (DWORD_PTR)lpwfs->hdr.hInternet;
2517 iar.dwError = ERROR_SUCCESS;
2518
2519 INTERNET_SendCallback(&hIC->hdr, dwContext,
2521 sizeof(INTERNET_ASYNC_RESULT));
2522 }
2523
2525 (LPWSTR) lpszServerName, (lstrlenW(lpszServerName)+1) * sizeof(WCHAR));
2526
2527 sock_namelen = sizeof(socketAddr);
2528 if (!GetAddress(lpszServerName, lpwfs->serverport, (struct sockaddr *)&socketAddr, &sock_namelen, szaddr))
2529 {
2531 goto lerror;
2532 }
2533
2534 if (socketAddr.sin_family != AF_INET)
2535 {
2536 WARN("unsupported address family %d\n", socketAddr.sin_family);
2538 goto lerror;
2539 }
2540
2542 szaddr, strlen(szaddr)+1);
2543
2544 init_winsock();
2545 nsocket = socket(AF_INET,SOCK_STREAM,0);
2546 if (nsocket == -1)
2547 {
2549 goto lerror;
2550 }
2551
2553 szaddr, strlen(szaddr)+1);
2554
2555 if (connect(nsocket, (struct sockaddr *)&socketAddr, sock_namelen) < 0)
2556 {
2557 ERR("Unable to connect (%d)\n", WSAGetLastError());
2559 closesocket(nsocket);
2560 }
2561 else
2562 {
2563 TRACE("Connected to server\n");
2564 lpwfs->sndSocket = nsocket;
2566 szaddr, strlen(szaddr)+1);
2567
2568 sock_namelen = sizeof(lpwfs->socketAddress);
2569 getsockname(nsocket, (struct sockaddr *) &lpwfs->socketAddress, &sock_namelen);
2570
2571 if (FTP_ConnectToHost(lpwfs))
2572 {
2573 TRACE("Successfully logged into server\n");
2574 bSuccess = TRUE;
2575 }
2576 }
2577
2578lerror:
2579 if (!bSuccess)
2580 {
2581 WININET_Release(&lpwfs->hdr);
2582 return NULL;
2583 }
2584
2585 return lpwfs->hdr.hInternet;
2586}
2587
2588
2589/***********************************************************************
2590 * FTP_ConnectToHost (internal)
2591 *
2592 * Connect to a ftp server
2593 *
2594 * RETURNS
2595 * TRUE on success
2596 * NULL on failure
2597 *
2598 */
2600{
2601 INT nResCode;
2602 BOOL bSuccess = FALSE;
2603
2604 TRACE("\n");
2605 FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
2606
2607 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_USER, lpwfs->lpszUserName, 0, 0, 0))
2608 goto lend;
2609
2610 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
2611 if (nResCode)
2612 {
2613 /* Login successful... */
2614 if (nResCode == 230)
2615 bSuccess = TRUE;
2616 /* User name okay, need password... */
2617 else if (nResCode == 331)
2618 bSuccess = FTP_SendPassword(lpwfs);
2619 /* Need account for login... */
2620 else if (nResCode == 332)
2621 bSuccess = FTP_SendAccount(lpwfs);
2622 else
2623 FTP_SetResponseError(nResCode);
2624 }
2625
2626 TRACE("Returning %d\n", bSuccess);
2627lend:
2628 return bSuccess;
2629}
2630
2631/***********************************************************************
2632 * FTP_GetNextLine (internal)
2633 *
2634 * Parse next line in directory string listing
2635 *
2636 * RETURNS
2637 * Pointer to beginning of next line
2638 * NULL on failure
2639 *
2640 */
2641
2642static LPSTR FTP_GetNextLine(INT nSocket, LPDWORD dwLen)
2643{
2644 struct timeval tv = {RESPONSE_TIMEOUT,0};
2645 FD_SET set;
2646 INT nRecv = 0;
2647 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
2648
2649 TRACE("\n");
2650
2651 FD_ZERO(&set);
2652 FD_SET(nSocket, &set);
2653
2654 while (nRecv < MAX_REPLY_LEN)
2655 {
2656 if (select(nSocket+1, &set, NULL, NULL, &tv) > 0)
2657 {
2658 if (sock_recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
2659 {
2661 return NULL;
2662 }
2663
2664 if (lpszBuffer[nRecv] == '\n')
2665 {
2666 lpszBuffer[nRecv] = '\0';
2667 *dwLen = nRecv - 1;
2668 TRACE(":%d %s\n", nRecv, lpszBuffer);
2669 return lpszBuffer;
2670 }
2671 if (lpszBuffer[nRecv] != '\r')
2672 nRecv++;
2673 }
2674 else
2675 {
2677 return NULL;
2678 }
2679 }
2680
2681 return NULL;
2682}
2683
2684/***********************************************************************
2685 * FTP_SendCommandA (internal)
2686 *
2687 * Send command to server
2688 *
2689 * RETURNS
2690 * TRUE on success
2691 * NULL on failure
2692 *
2693 */
2694static BOOL FTP_SendCommandA(INT nSocket, FTP_COMMAND ftpCmd, LPCSTR lpszParam,
2695 INTERNET_STATUS_CALLBACK lpfnStatusCB, object_header_t *hdr, DWORD_PTR dwContext)
2696{
2697 DWORD len;
2698 CHAR *buf;
2699 DWORD nBytesSent = 0;
2700 int nRC = 0;
2701 DWORD dwParamLen;
2702
2703 TRACE("%d: (%s) %d\n", ftpCmd, debugstr_a(lpszParam), nSocket);
2704
2705 if (lpfnStatusCB)
2706 {
2707 lpfnStatusCB(hdr->hInternet, dwContext, INTERNET_STATUS_SENDING_REQUEST, NULL, 0);
2708 }
2709
2710 dwParamLen = lpszParam?strlen(lpszParam)+1:0;
2711 len = dwParamLen + strlen(szFtpCommands[ftpCmd]) + strlen(szCRLF);
2712 if (NULL == (buf = malloc(len + 1)))
2713 {
2715 return FALSE;
2716 }
2717 sprintf(buf, "%s%s%s%s", szFtpCommands[ftpCmd], dwParamLen ? " " : "",
2718 dwParamLen ? lpszParam : "", szCRLF);
2719
2720 TRACE("Sending (%s) len(%ld)\n", debugstr_a(buf), len);
2721 while((nBytesSent < len) && (nRC != -1))
2722 {
2723 nRC = sock_send(nSocket, buf+nBytesSent, len - nBytesSent, 0);
2724 nBytesSent += nRC;
2725 }
2726 free(buf);
2727
2728 if (lpfnStatusCB)
2729 {
2730 lpfnStatusCB(hdr->hInternet, dwContext, INTERNET_STATUS_REQUEST_SENT,
2731 &nBytesSent, sizeof(DWORD));
2732 }
2733
2734 TRACE("Sent %ld bytes\n", nBytesSent);
2735 return (nRC != -1);
2736}
2737
2738/***********************************************************************
2739 * FTP_SendCommand (internal)
2740 *
2741 * Send command to server
2742 *
2743 * RETURNS
2744 * TRUE on success
2745 * NULL on failure
2746 *
2747 */
2748static BOOL FTP_SendCommand(INT nSocket, FTP_COMMAND ftpCmd, LPCWSTR lpszParam,
2749 INTERNET_STATUS_CALLBACK lpfnStatusCB, object_header_t *hdr, DWORD_PTR dwContext)
2750{
2751 BOOL ret;
2752 char *lpszParamA = strdupWtoA(lpszParam);
2753 ret = FTP_SendCommandA(nSocket, ftpCmd, lpszParamA, lpfnStatusCB, hdr, dwContext);
2754 free(lpszParamA);
2755 return ret;
2756}
2757
2758/***********************************************************************
2759 * FTP_ReceiveResponse (internal)
2760 *
2761 * Receive response from server
2762 *
2763 * RETURNS
2764 * Reply code on success
2765 * 0 on failure
2766 *
2767 */
2769{
2770 LPSTR lpszResponse = INTERNET_GetResponseBuffer();
2771 DWORD nRecv;
2772 INT rc = 0;
2773 char firstprefix[5];
2774 BOOL multiline = FALSE;
2775
2776 TRACE("socket(%d)\n", lpwfs->sndSocket);
2777
2779
2780 while(1)
2781 {
2782 if (!FTP_GetNextLine(lpwfs->sndSocket, &nRecv))
2783 goto lerror;
2784
2785 if (nRecv >= 3)
2786 {
2787 if(!multiline)
2788 {
2789 if(lpszResponse[3] != '-')
2790 break;
2791 else
2792 { /* Start of multiline response. Loop until we get "nnn " */
2793 multiline = TRUE;
2794 memcpy(firstprefix, lpszResponse, 3);
2795 firstprefix[3] = ' ';
2796 firstprefix[4] = '\0';
2797 }
2798 }
2799 else
2800 {
2801 if(!memcmp(firstprefix, lpszResponse, 4))
2802 break;
2803 }
2804 }
2805 }
2806
2807 if (nRecv >= 3)
2808 {
2809 rc = atoi(lpszResponse);
2810
2812 &nRecv, sizeof(DWORD));
2813 }
2814
2815lerror:
2816 TRACE("return %d\n", rc);
2817 return rc;
2818}
2819
2820
2821/***********************************************************************
2822 * FTP_SendPassword (internal)
2823 *
2824 * Send password to ftp server
2825 *
2826 * RETURNS
2827 * TRUE on success
2828 * NULL on failure
2829 *
2830 */
2832{
2833 INT nResCode;
2834 BOOL bSuccess = FALSE;
2835
2836 TRACE("\n");
2837 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_PASS, lpwfs->lpszPassword, 0, 0, 0))
2838 goto lend;
2839
2840 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
2841 if (nResCode)
2842 {
2843 TRACE("Received reply code %d\n", nResCode);
2844 /* Login successful... */
2845 if (nResCode == 230)
2846 bSuccess = TRUE;
2847 /* Command not implemented, superfluous at the server site... */
2848 /* Need account for login... */
2849 else if (nResCode == 332)
2850 bSuccess = FTP_SendAccount(lpwfs);
2851 else
2852 FTP_SetResponseError(nResCode);
2853 }
2854
2855lend:
2856 TRACE("Returning %d\n", bSuccess);
2857 return bSuccess;
2858}
2859
2860
2861/***********************************************************************
2862 * FTP_SendAccount (internal)
2863 *
2864 *
2865 *
2866 * RETURNS
2867 * TRUE on success
2868 * FALSE on failure
2869 *
2870 */
2872{
2873 INT nResCode;
2874 BOOL bSuccess = FALSE;
2875
2876 TRACE("\n");
2877 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_ACCT, L"noaccount", 0, 0, 0))
2878 goto lend;
2879
2880 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
2881 if (nResCode)
2882 bSuccess = TRUE;
2883 else
2884 FTP_SetResponseError(nResCode);
2885
2886lend:
2887 return bSuccess;
2888}
2889
2890
2891/***********************************************************************
2892 * FTP_SendStore (internal)
2893 *
2894 * Send request to upload file to ftp server
2895 *
2896 * RETURNS
2897 * TRUE on success
2898 * FALSE on failure
2899 *
2900 */
2901static BOOL FTP_SendStore(ftp_session_t *lpwfs, LPCWSTR lpszRemoteFile, DWORD dwType)
2902{
2903 INT nResCode;
2904 BOOL bSuccess = FALSE;
2905
2906 TRACE("\n");
2907 if (!FTP_InitListenSocket(lpwfs))
2908 goto lend;
2909
2910 if (!FTP_SendType(lpwfs, dwType))
2911 goto lend;
2912
2913 if (!FTP_SendPortOrPasv(lpwfs))
2914 goto lend;
2915
2916 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_STOR, lpszRemoteFile, 0, 0, 0))
2917 goto lend;
2918 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
2919 if (nResCode)
2920 {
2921 if (nResCode == 150 || nResCode == 125)
2922 bSuccess = TRUE;
2923 else
2924 FTP_SetResponseError(nResCode);
2925 }
2926
2927lend:
2928 if (!bSuccess && lpwfs->lstnSocket != -1)
2929 {
2930 closesocket(lpwfs->lstnSocket);
2931 lpwfs->lstnSocket = -1;
2932 }
2933
2934 return bSuccess;
2935}
2936
2937
2938/***********************************************************************
2939 * FTP_InitListenSocket (internal)
2940 *
2941 * Create a socket to listen for server response
2942 *
2943 * RETURNS
2944 * TRUE on success
2945 * FALSE on failure
2946 *
2947 */
2949{
2950 BOOL bSuccess = FALSE;
2951 socklen_t namelen = sizeof(lpwfs->lstnSocketAddress);
2952
2953 TRACE("\n");
2954
2955 init_winsock();
2956 lpwfs->lstnSocket = socket(AF_INET, SOCK_STREAM, 0);
2957 if (lpwfs->lstnSocket == -1)
2958 {
2959 TRACE("Unable to create listening socket\n");
2960 goto lend;
2961 }
2962
2963 /* We obtain our ip addr from the name of the command channel socket */
2964 lpwfs->lstnSocketAddress = lpwfs->socketAddress;
2965
2966 /* and get the system to assign us a port */
2967 lpwfs->lstnSocketAddress.sin_port = htons(0);
2968
2969 if (bind(lpwfs->lstnSocket,(struct sockaddr *) &lpwfs->lstnSocketAddress, sizeof(lpwfs->lstnSocketAddress)) == -1)
2970 {
2971 TRACE("Unable to bind socket\n");
2972 goto lend;
2973 }
2974
2975 if (listen(lpwfs->lstnSocket, MAX_BACKLOG) == -1)
2976 {
2977 TRACE("listen failed\n");
2978 goto lend;
2979 }
2980
2981 if (getsockname(lpwfs->lstnSocket, (struct sockaddr *) &lpwfs->lstnSocketAddress, &namelen) != -1)
2982 bSuccess = TRUE;
2983
2984lend:
2985 if (!bSuccess && lpwfs->lstnSocket != -1)
2986 {
2987 closesocket(lpwfs->lstnSocket);
2988 lpwfs->lstnSocket = -1;
2989 }
2990
2991 return bSuccess;
2992}
2993
2994
2995/***********************************************************************
2996 * FTP_SendType (internal)
2997 *
2998 * Tell server type of data being transferred
2999 *
3000 * RETURNS
3001 * TRUE on success
3002 * FALSE on failure
3003 *
3004 * W98SE doesn't cache the type that's currently set
3005 * (i.e. it sends it always),
3006 * so we probably don't want to do that either.
3007 */
3008static BOOL FTP_SendType(ftp_session_t *lpwfs, DWORD dwType)
3009{
3010 INT nResCode;
3011 WCHAR type[] = L"I";
3012 BOOL bSuccess = FALSE;
3013
3014 TRACE("\n");
3015 if (dwType & INTERNET_FLAG_TRANSFER_ASCII)
3016 type[0] = 'A';
3017
3018 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_TYPE, type, 0, 0, 0))
3019 goto lend;
3020
3021 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext)/100;
3022 if (nResCode)
3023 {
3024 if (nResCode == 2)
3025 bSuccess = TRUE;
3026 else
3027 FTP_SetResponseError(nResCode);
3028 }
3029
3030lend:
3031 return bSuccess;
3032}
3033
3034
3035#if 0 /* FIXME: should probably be used for FtpGetFileSize */
3036/***********************************************************************
3037 * FTP_GetFileSize (internal)
3038 *
3039 * Retrieves from the server the size of the given file
3040 *
3041 * RETURNS
3042 * TRUE on success
3043 * FALSE on failure
3044 *
3045 */
3046static BOOL FTP_GetFileSize(ftp_session_t *lpwfs, LPCWSTR lpszRemoteFile, DWORD *dwSize)
3047{
3048 INT nResCode;
3049 BOOL bSuccess = FALSE;
3050
3051 TRACE("\n");
3052
3053 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_SIZE, lpszRemoteFile, 0, 0, 0))
3054 goto lend;
3055
3056 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
3057 if (nResCode)
3058 {
3059 if (nResCode == 213) {
3060 /* Now parses the output to get the actual file size */
3061 int i;
3062 LPSTR lpszResponseBuffer = INTERNET_GetResponseBuffer();
3063
3064 for (i = 0; (lpszResponseBuffer[i] != ' ') && (lpszResponseBuffer[i] != '\0'); i++) ;
3065 if (lpszResponseBuffer[i] == '\0') return FALSE;
3066 *dwSize = atol(&(lpszResponseBuffer[i + 1]));
3067
3068 bSuccess = TRUE;
3069 } else {
3070 FTP_SetResponseError(nResCode);
3071 }
3072 }
3073
3074lend:
3075 return bSuccess;
3076}
3077#endif
3078
3079
3080/***********************************************************************
3081 * FTP_SendPort (internal)
3082 *
3083 * Tell server which port to use
3084 *
3085 * RETURNS
3086 * TRUE on success
3087 * FALSE on failure
3088 *
3089 */
3091{
3092 INT nResCode;
3093 WCHAR szIPAddress[64];
3094 BOOL bSuccess = FALSE;
3095 TRACE("\n");
3096
3097 swprintf(szIPAddress, ARRAY_SIZE(szIPAddress), L"%d,%d,%d,%d,%d,%d",
3098 lpwfs->lstnSocketAddress.sin_addr.S_un.S_addr&0x000000FF,
3099 (lpwfs->lstnSocketAddress.sin_addr.S_un.S_addr&0x0000FF00)>>8,
3100 (lpwfs->lstnSocketAddress.sin_addr.S_un.S_addr&0x00FF0000)>>16,
3101 (lpwfs->lstnSocketAddress.sin_addr.S_un.S_addr&0xFF000000)>>24,
3102 lpwfs->lstnSocketAddress.sin_port & 0xFF,
3103 (lpwfs->lstnSocketAddress.sin_port & 0xFF00)>>8);
3104
3105 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_PORT, szIPAddress, 0, 0, 0))
3106 goto lend;
3107
3108 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
3109 if (nResCode)
3110 {
3111 if (nResCode == 200)
3112 bSuccess = TRUE;
3113 else
3114 FTP_SetResponseError(nResCode);
3115 }
3116
3117lend:
3118 return bSuccess;
3119}
3120
3121
3122/***********************************************************************
3123 * FTP_DoPassive (internal)
3124 *
3125 * Tell server that we want to do passive transfers
3126 * and connect data socket
3127 *
3128 * RETURNS
3129 * TRUE on success
3130 * FALSE on failure
3131 *
3132 */
3134{
3135 INT nResCode;
3136 BOOL bSuccess = FALSE;
3137
3138 TRACE("\n");
3139 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_PASV, NULL, 0, 0, 0))
3140 goto lend;
3141
3142 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
3143 if (nResCode)
3144 {
3145 if (nResCode == 227)
3146 {
3147 LPSTR lpszResponseBuffer = INTERNET_GetResponseBuffer();
3148 LPSTR p;
3149 int f[6];
3150 int i;
3151 char *pAddr, *pPort;
3152 INT nsocket = -1;
3153 struct sockaddr_in dataSocketAddress;
3154
3155 p = lpszResponseBuffer+4; /* skip status code */
3156 while (*p != '\0' && (*p < '0' || *p > '9')) p++;
3157
3158 if (*p == '\0')
3159 {
3160 ERR("no address found in response, aborting\n");
3161 goto lend;
3162 }
3163
3164 if (sscanf(p, "%d,%d,%d,%d,%d,%d", &f[0], &f[1], &f[2], &f[3],
3165 &f[4], &f[5]) != 6)
3166 {
3167 ERR("unknown response address format '%s', aborting\n", p);
3168 goto lend;
3169 }
3170 for (i=0; i < 6; i++)
3171 f[i] = f[i] & 0xff;
3172
3173 dataSocketAddress = lpwfs->socketAddress;
3174 pAddr = (char *)&(dataSocketAddress.sin_addr.S_un.S_addr);
3175 pPort = (char *)&(dataSocketAddress.sin_port);
3176 pAddr[0] = f[0];
3177 pAddr[1] = f[1];
3178 pAddr[2] = f[2];
3179 pAddr[3] = f[3];
3180 pPort[0] = f[4];
3181 pPort[1] = f[5];
3182
3183 nsocket = socket(AF_INET,SOCK_STREAM,0);
3184 if (nsocket == -1)
3185 goto lend;
3186
3187 if (connect(nsocket, (struct sockaddr *)&dataSocketAddress, sizeof(dataSocketAddress)))
3188 {
3189 ERR("can't connect passive FTP data port.\n");
3190 closesocket(nsocket);
3191 goto lend;
3192 }
3193 lpwfs->pasvSocket = nsocket;
3194 bSuccess = TRUE;
3195 }
3196 else
3197 FTP_SetResponseError(nResCode);
3198 }
3199
3200lend:
3201 return bSuccess;
3202}
3203
3204
3206{
3207 if (lpwfs->hdr.dwFlags & INTERNET_FLAG_PASSIVE)
3208 {
3209 if (!FTP_DoPassive(lpwfs))
3210 return FALSE;
3211 }
3212 else
3213 {
3214 if (!FTP_SendPort(lpwfs))
3215 return FALSE;
3216 }
3217 return TRUE;
3218}
3219
3220
3221/***********************************************************************
3222 * FTP_GetDataSocket (internal)
3223 *
3224 * Either accepts an incoming data socket connection from the server
3225 * or just returns the already opened socket after a PASV command
3226 * in case of passive FTP.
3227 *
3228 *
3229 * RETURNS
3230 * TRUE on success
3231 * FALSE on failure
3232 *
3233 */
3234static BOOL FTP_GetDataSocket(ftp_session_t *lpwfs, LPINT nDataSocket)
3235{
3236 struct sockaddr_in saddr;
3237 socklen_t addrlen = sizeof(saddr);
3238
3239 TRACE("\n");
3240 if (lpwfs->hdr.dwFlags & INTERNET_FLAG_PASSIVE)
3241 {
3242 *nDataSocket = lpwfs->pasvSocket;
3243 lpwfs->pasvSocket = -1;
3244 }
3245 else
3246 {
3247 *nDataSocket = accept(lpwfs->lstnSocket, (struct sockaddr *) &saddr, &addrlen);
3248 closesocket(lpwfs->lstnSocket);
3249 lpwfs->lstnSocket = -1;
3250 }
3251 return *nDataSocket != -1;
3252}
3253
3254
3255/***********************************************************************
3256 * FTP_SendData (internal)
3257 *
3258 * Send data to the server
3259 *
3260 * RETURNS
3261 * TRUE on success
3262 * FALSE on failure
3263 *
3264 */
3265static BOOL FTP_SendData(ftp_session_t *lpwfs, INT nDataSocket, HANDLE hFile)
3266{
3268 DWORD nBytesRead = 0;
3269 DWORD nBytesSent = 0;
3270 DWORD nTotalSent = 0;
3271 DWORD nBytesToSend, nLen;
3272 int nRC = 1;
3273 time_t s_long_time, e_long_time;
3274 LONG nSeconds;
3275 CHAR *lpszBuffer;
3276
3277 TRACE("\n");
3278 lpszBuffer = calloc(DATA_PACKET_SIZE, 1);
3279
3280 /* Get the size of the file. */
3282 time(&s_long_time);
3283
3284 do
3285 {
3286 nBytesToSend = nBytesRead - nBytesSent;
3287
3288 if (nBytesToSend <= 0)
3289 {
3290 /* Read data from file. */
3291 nBytesSent = 0;
3292 if (!ReadFile(hFile, lpszBuffer, DATA_PACKET_SIZE, &nBytesRead, 0))
3293 ERR("Failed reading from file\n");
3294
3295 if (nBytesRead > 0)
3296 nBytesToSend = nBytesRead;
3297 else
3298 break;
3299 }
3300
3301 nLen = DATA_PACKET_SIZE < nBytesToSend ?
3302 DATA_PACKET_SIZE : nBytesToSend;
3303 nRC = sock_send(nDataSocket, lpszBuffer, nLen, 0);
3304
3305 if (nRC != -1)
3306 {
3307 nBytesSent += nRC;
3308 nTotalSent += nRC;
3309 }
3310
3311 /* Do some computation to display the status. */
3312 time(&e_long_time);
3313 nSeconds = e_long_time - s_long_time;
3314 if( nSeconds / 60 > 0 )
3315 {
3316 TRACE( "%ld bytes of %ld bytes (%ld%%) in %ld min %ld sec estimated remaining time %ld sec\n",
3317 nTotalSent, fi.nFileSizeLow, nTotalSent*100/fi.nFileSizeLow, nSeconds / 60,
3318 nSeconds % 60, (fi.nFileSizeLow - nTotalSent) * nSeconds / nTotalSent );
3319 }
3320 else
3321 {
3322 TRACE( "%ld bytes of %ld bytes (%ld%%) in %ld sec estimated remaining time %ld sec\n",
3323 nTotalSent, fi.nFileSizeLow, nTotalSent*100/fi.nFileSizeLow, nSeconds,
3324 (fi.nFileSizeLow - nTotalSent) * nSeconds / nTotalSent);
3325 }
3326 } while (nRC != -1);
3327
3328 TRACE("file transfer complete!\n");
3329
3330 free(lpszBuffer);
3331 return nTotalSent;
3332}
3333
3334
3335/***********************************************************************
3336 * FTP_SendRetrieve (internal)
3337 *
3338 * Send request to retrieve a file
3339 *
3340 * RETURNS
3341 * Number of bytes to be received on success
3342 * 0 on failure
3343 *
3344 */
3345static BOOL FTP_SendRetrieve(ftp_session_t *lpwfs, LPCWSTR lpszRemoteFile, DWORD dwType)
3346{
3347 INT nResCode;
3348 BOOL ret;
3349
3350 TRACE("\n");
3351 if (!(ret = FTP_InitListenSocket(lpwfs)))
3352 goto lend;
3353
3354 if (!(ret = FTP_SendType(lpwfs, dwType)))
3355 goto lend;
3356
3357 if (!(ret = FTP_SendPortOrPasv(lpwfs)))
3358 goto lend;
3359
3360 if (!(ret = FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_RETR, lpszRemoteFile, 0, 0, 0)))
3361 goto lend;
3362
3363 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
3364 if ((nResCode != 125) && (nResCode != 150)) {
3365 /* That means that we got an error getting the file. */
3366 FTP_SetResponseError(nResCode);
3367 ret = FALSE;
3368 }
3369
3370lend:
3371 if (!ret && lpwfs->lstnSocket != -1)
3372 {
3373 closesocket(lpwfs->lstnSocket);
3374 lpwfs->lstnSocket = -1;
3375 }
3376
3377 return ret;
3378}
3379
3380
3381/***********************************************************************
3382 * FTP_RetrieveData (internal)
3383 *
3384 * Retrieve data from server
3385 *
3386 * RETURNS
3387 * TRUE on success
3388 * FALSE on failure
3389 *
3390 */
3392{
3393 DWORD nBytesWritten;
3394 INT nRC = 0;
3395 CHAR *lpszBuffer;
3396
3397 TRACE("\n");
3398
3399 lpszBuffer = calloc(DATA_PACKET_SIZE, 1);
3400 if (NULL == lpszBuffer)
3401 {
3403 return FALSE;
3404 }
3405
3406 while (nRC != -1)
3407 {
3408 nRC = sock_recv(nDataSocket, lpszBuffer, DATA_PACKET_SIZE, 0);
3409 if (nRC != -1)
3410 {
3411 /* other side closed socket. */
3412 if (nRC == 0)
3413 goto recv_end;
3414 WriteFile(hFile, lpszBuffer, nRC, &nBytesWritten, NULL);
3415 }
3416 }
3417
3418 TRACE("Data transfer complete\n");
3419
3420recv_end:
3421 free(lpszBuffer);
3422 return (nRC != -1);
3423}
3424
3425/***********************************************************************
3426 * FTPFINDNEXT_Destroy (internal)
3427 *
3428 * Deallocate session handle
3429 */
3431{
3433 DWORD i;
3434
3435 TRACE("\n");
3436
3438
3439 for (i = 0; i < lpwfn->size; i++)
3440 {
3441 free(lpwfn->lpafp[i].lpszName);
3442 }
3443 free(lpwfn->lpafp);
3444}
3445
3447{
3450
3451 TRACE("index(%ld) size(%ld)\n", find->index, find->size);
3452
3454
3455 if (find->index < find->size) {
3456 FTP_ConvertFileProp(&find->lpafp[find->index], find_data);
3457 find->index++;
3458
3459 TRACE("Name: %s\nSize: %ld\n", debugstr_w(find_data->cFileName), find_data->nFileSizeLow);
3460 }else {
3462 }
3463
3464 if (find->hdr.dwFlags & INTERNET_FLAG_ASYNC)
3465 {
3467
3468 iar.dwResult = (res == ERROR_SUCCESS);
3469 iar.dwError = res;
3470
3471 INTERNET_SendCallback(&find->hdr, find->hdr.dwContext,
3473 sizeof(INTERNET_ASYNC_RESULT));
3474 }
3475
3476 return res;
3477}
3478
3479typedef struct {
3483
3485{
3487
3489}
3490
3492{
3493 switch(option) {
3495 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
3496
3497 if (*size < sizeof(ULONG))
3499
3500 *size = sizeof(DWORD);
3502 return ERROR_SUCCESS;
3503 }
3504
3505 return INET_QueryOption(hdr, option, buffer, size, unicode);
3506}
3507
3509{
3511
3512 if (find->lpFtpSession->lpAppInfo->hdr.dwFlags & INTERNET_FLAG_ASYNC)
3513 {
3515
3517 task->find_data = data;
3518
3519 INTERNET_AsyncCall(&task->hdr);
3520 return ERROR_SUCCESS;
3521 }
3522
3524}
3525
3528 NULL,
3531 NULL,
3532 NULL,
3533 NULL,
3534 NULL,
3536};
3537
3538/***********************************************************************
3539 * FTP_ReceiveFileList (internal)
3540 *
3541 * Read file list from server
3542 *
3543 * RETURNS
3544 * Handle to file list on success
3545 * NULL on failure
3546 *
3547 */
3548static HINTERNET FTP_ReceiveFileList(ftp_session_t *lpwfs, INT nSocket, LPCWSTR lpszSearchFile,
3549 LPWIN32_FIND_DATAW lpFindFileData, DWORD_PTR dwContext)
3550{
3551 DWORD dwSize = 0;
3552 LPFILEPROPERTIESW lpafp = NULL;
3554
3555 TRACE("(%p,%d,%s,%p,%08Ix)\n", lpwfs, nSocket, debugstr_w(lpszSearchFile), lpFindFileData, dwContext);
3556
3557 if (FTP_ParseDirectory(lpwfs, nSocket, lpszSearchFile, &lpafp, &dwSize))
3558 {
3559 if(lpFindFileData)
3560 FTP_ConvertFileProp(lpafp, lpFindFileData);
3561
3562 lpwfn = alloc_object(&lpwfs->hdr, &FTPFINDNEXTVtbl, sizeof(WININETFTPFINDNEXTW));
3563 if (lpwfn)
3564 {
3565 lpwfn->hdr.htype = WH_HFTPFINDNEXT;
3566 lpwfn->hdr.dwContext = dwContext;
3567 lpwfn->index = 1; /* Next index is 1 since we return index 0 */
3568 lpwfn->size = dwSize;
3569 lpwfn->lpafp = lpafp;
3570
3571 WININET_AddRef( &lpwfs->hdr );
3572 lpwfn->lpFtpSession = lpwfs;
3573 list_add_head( &lpwfs->hdr.children, &lpwfn->hdr.entry );
3574 }
3575 }
3576
3577 TRACE("Matched %ld files\n", dwSize);
3578 return lpwfn ? lpwfn->hdr.hInternet : NULL;
3579}
3580
3581
3582/***********************************************************************
3583 * FTP_ConvertFileProp (internal)
3584 *
3585 * Converts FILEPROPERTIESW struct to WIN32_FIND_DATAA
3586 *
3587 * RETURNS
3588 * TRUE on success
3589 * FALSE on failure
3590 *
3591 */
3593{
3594 BOOL bSuccess = FALSE;
3595
3596 ZeroMemory(lpFindFileData, sizeof(WIN32_FIND_DATAW));
3597
3598 if (lpafp)
3599 {
3600 SystemTimeToFileTime( &lpafp->tmLastModified, &lpFindFileData->ftLastAccessTime );
3601 lpFindFileData->ftLastWriteTime = lpFindFileData->ftLastAccessTime;
3602 lpFindFileData->ftCreationTime = lpFindFileData->ftLastAccessTime;
3603
3604 /* Not all fields are filled in */
3605 lpFindFileData->nFileSizeHigh = 0; /* We do not handle files bigger than 0xFFFFFFFF bytes yet :-) */
3606 lpFindFileData->nFileSizeLow = lpafp->nSize;
3607
3608 if (lpafp->bIsDirectory)
3609 lpFindFileData->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
3610
3611 if (lpafp->lpszName)
3612 lstrcpynW(lpFindFileData->cFileName, lpafp->lpszName, MAX_PATH);
3613
3614 bSuccess = TRUE;
3615 }
3616
3617 return bSuccess;
3618}
3619
3620/***********************************************************************
3621 * FTP_ParseNextFile (internal)
3622 *
3623 * Parse the next line in file listing
3624 *
3625 * RETURNS
3626 * TRUE on success
3627 * FALSE on failure
3628 */
3629static BOOL FTP_ParseNextFile(INT nSocket, LPCWSTR lpszSearchFile, LPFILEPROPERTIESW lpfp)
3630{
3631 static const char szSpace[] = " \t";
3632 DWORD nBufLen;
3633 char *pszLine;
3634 char *pszToken;
3635 char *pszTmp;
3636 BOOL found = FALSE;
3637 int i;
3638
3639 lpfp->lpszName = NULL;
3640 do {
3641 if(!(pszLine = FTP_GetNextLine(nSocket, &nBufLen)))
3642 return FALSE;
3643
3644 pszToken = strtok(pszLine, szSpace);
3645 /* ls format
3646 * <Permissions> <NoLinks> <owner> <group> <size> <date> <time or year> <filename>
3647 *
3648 * For instance:
3649 * drwx--s--- 2 pcarrier ens 512 Sep 28 1995 pcarrier
3650 */
3651 if(!isdigit(pszToken[0]) && 10 == strlen(pszToken)) {
3652 if(!FTP_ParsePermission(pszToken, lpfp))
3653 lpfp->bIsDirectory = FALSE;
3654 for(i=0; i<=3; i++) {
3655 if(!(pszToken = strtok(NULL, szSpace)))
3656 break;
3657 }
3658 if(!pszToken) continue;
3659 if(lpfp->bIsDirectory) {
3660 TRACE("Is directory\n");
3661 lpfp->nSize = 0;
3662 }
3663 else {
3664 TRACE("Size: %s\n", pszToken);
3665 lpfp->nSize = atol(pszToken);
3666 }
3667
3668 lpfp->tmLastModified.wSecond = 0;
3669 lpfp->tmLastModified.wMinute = 0;
3670 lpfp->tmLastModified.wHour = 0;
3671 lpfp->tmLastModified.wDay = 0;
3672 lpfp->tmLastModified.wMonth = 0;
3673 lpfp->tmLastModified.wYear = 0;
3674
3675 /* Determine month */
3676 pszToken = strtok(NULL, szSpace);
3677 if(!pszToken) continue;
3678 if(strlen(pszToken) >= 3) {
3679 pszToken[3] = 0;
3680 if((pszTmp = StrStrIA(szMonths, pszToken)))
3681 lpfp->tmLastModified.wMonth = ((pszTmp - szMonths) / 3)+1;
3682 }
3683 /* Determine day */
3684 pszToken = strtok(NULL, szSpace);
3685 if(!pszToken) continue;
3686 lpfp->tmLastModified.wDay = atoi(pszToken);
3687 /* Determine time or year */
3688 pszToken = strtok(NULL, szSpace);
3689 if(!pszToken) continue;
3690 if((pszTmp = strchr(pszToken, ':'))) {
3691 SYSTEMTIME curr_time;
3692 *pszTmp = 0;
3693 pszTmp++;
3694 lpfp->tmLastModified.wMinute = atoi(pszTmp);
3695 lpfp->tmLastModified.wHour = atoi(pszToken);
3696 GetLocalTime( &curr_time );
3697 lpfp->tmLastModified.wYear = curr_time.wYear;
3698 }
3699 else {
3700 lpfp->tmLastModified.wYear = atoi(pszToken);
3701 lpfp->tmLastModified.wHour = 12;
3702 }
3703 TRACE("Mod time: %02d:%02d:%02d %04d/%02d/%02d\n",
3706
3707 pszToken = strtok(NULL, szSpace);
3708 if(!pszToken) continue;
3709 lpfp->lpszName = strdupAtoW(pszToken);
3710 TRACE("File: %s\n", debugstr_w(lpfp->lpszName));
3711 }
3712 /* NT way of parsing ... :
3713
3714 07-13-03 08:55PM <DIR> sakpatch
3715 05-09-03 06:02PM 12656686 2003-04-21bgm_cmd_e.rgz
3716 */
3717 else if(isdigit(pszToken[0]) && 8 == strlen(pszToken)) {
3718 int mon, mday, year, hour, min;
3719 lpfp->permissions = 0xFFFF; /* No idea, put full permission :-) */
3720
3721 sscanf(pszToken, "%d-%d-%d", &mon, &mday, &year);
3722 lpfp->tmLastModified.wDay = mday;
3723 lpfp->tmLastModified.wMonth = mon;
3724 lpfp->tmLastModified.wYear = year;
3725
3726 /* Hacky and bad Y2K protection :-) */
3727 if (lpfp->tmLastModified.wYear < 70) lpfp->tmLastModified.wYear += 2000;
3728
3729 pszToken = strtok(NULL, szSpace);
3730 if(!pszToken) continue;
3731 sscanf(pszToken, "%d:%d", &hour, &min);
3732 lpfp->tmLastModified.wHour = hour;
3733 lpfp->tmLastModified.wMinute = min;
3734 if((pszToken[5] == 'P') && (pszToken[6] == 'M')) {
3735 lpfp->tmLastModified.wHour += 12;
3736 }
3737 lpfp->tmLastModified.wSecond = 0;
3738
3739 TRACE("Mod time: %02d:%02d:%02d %04d/%02d/%02d\n",
3742
3743 pszToken = strtok(NULL, szSpace);
3744 if(!pszToken) continue;
3745 if(!stricmp(pszToken, "<DIR>")) {
3746 lpfp->bIsDirectory = TRUE;
3747 lpfp->nSize = 0;
3748 TRACE("Is directory\n");
3749 }
3750 else {
3751 lpfp->bIsDirectory = FALSE;
3752 lpfp->nSize = atol(pszToken);
3753 TRACE("Size: %ld\n", lpfp->nSize);
3754 }
3755
3756 pszToken = strtok(NULL, szSpace);
3757 if(!pszToken) continue;
3758 lpfp->lpszName = strdupAtoW(pszToken);
3759 TRACE("Name: %s\n", debugstr_w(lpfp->lpszName));
3760 }
3761 /* EPLF format - http://cr.yp.to/ftp/list/eplf.html */
3762 else if(pszToken[0] == '+') {
3763 FIXME("EPLF Format not implemented\n");
3764 }
3765
3766 if(lpfp->lpszName) {
3767 if((lpszSearchFile == NULL) ||
3768 (PathMatchSpecW(lpfp->lpszName, lpszSearchFile))) {
3769 found = TRUE;
3770 TRACE("Matched: %s\n", debugstr_w(lpfp->lpszName));
3771 }
3772 else {
3773 free(lpfp->lpszName);
3774 lpfp->lpszName = NULL;
3775 }
3776 }
3777 } while(!found);
3778 return TRUE;
3779}
3780
3781/***********************************************************************
3782 * FTP_ParseDirectory (internal)
3783 *
3784 * Parse string of directory information
3785 *
3786 * RETURNS
3787 * TRUE on success
3788 * FALSE on failure
3789 */
3790static BOOL FTP_ParseDirectory(ftp_session_t *lpwfs, INT nSocket, LPCWSTR lpszSearchFile,
3791 LPFILEPROPERTIESW *lpafp, LPDWORD dwfp)
3792{
3793 BOOL bSuccess = TRUE;
3794 INT sizeFilePropArray = 500;/*20; */
3795 INT indexFilePropArray = -1;
3796
3797 TRACE("\n");
3798
3799 /* Allocate initial file properties array */
3800 *lpafp = calloc(sizeFilePropArray, sizeof(FILEPROPERTIESW));
3801 if (!*lpafp)
3802 return FALSE;
3803
3804 do {
3805 if (indexFilePropArray+1 >= sizeFilePropArray)
3806 {
3807 LPFILEPROPERTIESW tmpafp;
3808
3809 tmpafp = realloc(*lpafp, sizeof(FILEPROPERTIESW) * sizeFilePropArray * 2);
3810 if (NULL == tmpafp)
3811 {
3812 bSuccess = FALSE;
3813 break;
3814 }
3815 memset(tmpafp + sizeFilePropArray, 0, sizeof(FILEPROPERTIESW) * sizeFilePropArray);
3816
3817 *lpafp = tmpafp;
3818 sizeFilePropArray *= 2;
3819 }
3820 indexFilePropArray++;
3821 } while (FTP_ParseNextFile(nSocket, lpszSearchFile, &(*lpafp)[indexFilePropArray]));
3822
3823 if (bSuccess && indexFilePropArray)
3824 {
3825 if (indexFilePropArray < sizeFilePropArray - 1)
3826 {
3827 LPFILEPROPERTIESW tmpafp;
3828
3829 tmpafp = realloc(*lpafp, sizeof(FILEPROPERTIESW) * indexFilePropArray);
3830 if (NULL != tmpafp)
3831 *lpafp = tmpafp;
3832 }
3833 *dwfp = indexFilePropArray;
3834 }
3835 else
3836 {
3837 free(*lpafp);
3839 bSuccess = FALSE;
3840 }
3841
3842 return bSuccess;
3843}
3844
3845
3846/***********************************************************************
3847 * FTP_ParsePermission (internal)
3848 *
3849 * Parse permission string of directory information
3850 *
3851 * RETURNS
3852 * TRUE on success
3853 * FALSE on failure
3854 *
3855 */
3857{
3858 BOOL bSuccess = TRUE;
3859 unsigned short nPermission = 0;
3860 INT nPos = 1;
3861 INT nLast = 9;
3862
3863 TRACE("\n");
3864 if ((*lpszPermission != 'd') && (*lpszPermission != '-') && (*lpszPermission != 'l'))
3865 {
3866 bSuccess = FALSE;
3867 return bSuccess;
3868 }
3869
3870 lpfp->bIsDirectory = (*lpszPermission == 'd');
3871 do
3872 {
3873 switch (nPos)
3874 {
3875 case 1:
3876 nPermission |= (*(lpszPermission+1) == 'r' ? 1 : 0) << 8;
3877 break;
3878 case 2:
3879 nPermission |= (*(lpszPermission+2) == 'w' ? 1 : 0) << 7;
3880 break;
3881 case 3:
3882 nPermission |= (*(lpszPermission+3) == 'x' ? 1 : 0) << 6;
3883 break;
3884 case 4:
3885 nPermission |= (*(lpszPermission+4) == 'r' ? 1 : 0) << 5;
3886 break;
3887 case 5:
3888 nPermission |= (*(lpszPermission+5) == 'w' ? 1 : 0) << 4;
3889 break;
3890 case 6:
3891 nPermission |= (*(lpszPermission+6) == 'x' ? 1 : 0) << 3;
3892 break;
3893 case 7:
3894 nPermission |= (*(lpszPermission+7) == 'r' ? 1 : 0) << 2;
3895 break;
3896 case 8:
3897 nPermission |= (*(lpszPermission+8) == 'w' ? 1 : 0) << 1;
3898 break;
3899 case 9:
3900 nPermission |= (*(lpszPermission+9) == 'x' ? 1 : 0);
3901 break;
3902 }
3903 nPos++;
3904 }while (nPos <= nLast);
3905
3906 lpfp->permissions = nPermission;
3907 return bSuccess;
3908}
3909
3910
3911/***********************************************************************
3912 * FTP_SetResponseError (internal)
3913 *
3914 * Set the appropriate error code for a given response from the server
3915 *
3916 * RETURNS
3917 *
3918 */
3920{
3921 DWORD dwCode = 0;
3922
3923 switch(dwResponse)
3924 {
3925 case 425: /* Cannot open data connection. */
3927 break;
3928
3929 case 426: /* Connection closed, transfer aborted. */
3931 break;
3932
3933 case 530: /* Not logged in. Login incorrect. */
3935 break;
3936
3937 case 421: /* Service not available - Server may be shutting down. */
3938 case 450: /* File action not taken. File may be busy. */
3939 case 451: /* Action aborted. Server error. */
3940 case 452: /* Action not taken. Insufficient storage space on server. */
3941 case 500: /* Syntax error. Command unrecognized. */
3942 case 501: /* Syntax error. Error in parameters or arguments. */
3943 case 502: /* Command not implemented. */
3944 case 503: /* Bad sequence of commands. */
3945 case 504: /* Command not implemented for that parameter. */
3946 case 532: /* Need account for storing files */
3947 case 550: /* File action not taken. File not found or no access. */
3948 case 551: /* Requested action aborted. Page type unknown */
3949 case 552: /* Action aborted. Exceeded storage allocation */
3950 case 553: /* Action not taken. File name not allowed. */
3951
3952 default:
3954 break;
3955 }
3956
3957 INTERNET_SetLastError(dwCode);
3958 return dwCode;
3959}
WCHAR lpszDest[260]
#define isdigit(c)
Definition: acclib.h:68
#define read
Definition: acwin.h:97
BOOL required
Definition: adapter_vk.c:1885
static char * strdupWtoA(const WCHAR *str)
unsigned int dir
Definition: maze.c:112
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define ARRAY_SIZE(A)
Definition: main.h:20
static void list_add_head(struct list_entry *head, struct list_entry *entry)
Definition: list.h:76
#define FIXME(fmt,...)
Definition: precomp.h:53
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERR(fmt,...)
Definition: precomp.h:57
#define RegCloseKey(hKey)
Definition: registry.h:49
Definition: _set.h:50
static TAGID TAGID find
Definition: db.cpp:156
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define ERROR_IO_PENDING
Definition: dderror.h:15
#define realloc
Definition: debug_ros.c:6
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
DWORD task
Definition: delayimp.cpp:484
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static int find_data(const struct Vector *v, const void *pData, int size)
Definition: filtermapper.c:423
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3268
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
BOOL WINAPI GetUserNameW(LPWSTR lpszName, LPDWORD lpSize)
Definition: misc.c:291
LPSTR WINAPI StrStrIA(LPCSTR lpszStr, LPCSTR lpszSearch)
Definition: string.c:351
static WCHAR available[MAX_STRING_RESOURCE_LEN]
Definition: object.c:2402
static WCHAR * strdupAtoW(const char *str)
Definition: main.c:61
#define CloseHandle
Definition: compat.h:739
#define wcschr
Definition: compat.h:17
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define wcsrchr
Definition: compat.h:16
#define CP_ACP
Definition: compat.h:109
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define stricmp(_String1, _String2)
Definition: compat.h:24
#define ERROR_NOT_SUPPORTED
Definition: compat.h:100
#define MAX_PATH
Definition: compat.h:34
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define lstrcpyW
Definition: compat.h:749
#define WideCharToMultiByte
Definition: compat.h:111
#define FILE_SHARE_READ
Definition: compat.h:136
#define lstrcpynW
Definition: compat.h:738
#define lstrlenW
Definition: compat.h:750
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL WINAPI GetFileInformationByHandle(HANDLE hFile, LPBY_HANDLE_FILE_INFORMATION lpFileInformation)
Definition: fileinfo.c:442
BOOL WINAPI WriteFile(_In_ HANDLE hFile, _In_reads_bytes_opt_(nNumberOfBytesToWrite) LPCVOID lpBuffer, _In_ DWORD nNumberOfBytesToWrite, _Out_opt_ LPDWORD lpNumberOfBytesWritten, _Inout_opt_ LPOVERLAPPED lpOverlapped)
Definition: rw.c:25
BOOL WINAPI SystemTimeToFileTime(IN CONST SYSTEMTIME *lpSystemTime, OUT LPFILETIME lpFileTime)
Definition: time.c:153
VOID WINAPI GetLocalTime(OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:272
BOOL WINAPI PathMatchSpecW(const WCHAR *path, const WCHAR *mask)
Definition: path.c:2497
#define assert(_expr)
Definition: assert.h:32
__time32_t time_t
Definition: corecrt.h:228
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2807
_ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl sscanf(const char *, const char *,...) __WINE_CRT_SCANF_ATTR(2
_ACRTIMP __msvcrt_long __cdecl atol(const char *)
Definition: string.c:1787
_ACRTIMP int __cdecl atoi(const char *)
Definition: string.c:1720
_ACRTIMP char *__cdecl strchr(const char *, int)
Definition: string.c:3291
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1597
_ACRTIMP char *__cdecl strtok(char *, const char *)
Definition: string.c:290
static wchar_t * wcsdup(const wchar_t *str)
Definition: string.h:94
static int sock_send(int fd, const void *msg, size_t len, WSAOVERLAPPED *ovr)
Definition: net.c:35
static int sock_recv(int fd, void *msg, size_t len, int flags)
Definition: net.c:73
static BOOL FTP_FtpGetCurrentDirectoryW(ftp_session_t *, LPWSTR lpszCurrentDirectory, LPDWORD lpdwCurrentDirectory)
Definition: ftp.c:1046
static BOOL FTP_GetDataSocket(ftp_session_t *, LPINT nDataSocket)
Definition: ftp.c:3234
static const object_vtbl_t FTPSESSIONVtbl
Definition: ftp.c:2397
BOOL WINAPI FtpRenameFileA(HINTERNET hFtpSession, LPCSTR lpszSrc, LPCSTR lpszDest)
Definition: ftp.c:2068
BOOL WINAPI FtpRemoveDirectoryW(HINTERNET hFtpSession, LPCWSTR lpszDirectory)
Definition: ftp.c:1957
static DWORD FTPFINDNEXT_FindNextFileProc(WININETFTPFINDNEXTW *find, LPVOID data)
Definition: ftp.c:3446
static void AsyncFtpRemoveDirectoryProc(task_header_t *hdr)
Definition: ftp.c:1936
DWORD WINAPI FtpGetFileSize(HINTERNET hFile, LPDWORD lpdwFileSizeHigh)
Definition: ftp.c:1758
BOOL WINAPI FtpRenameFileW(HINTERNET hFtpSession, LPCWSTR lpszSrc, LPCWSTR lpszDest)
Definition: ftp.c:2110
static BOOL FTP_ParseNextFile(INT nSocket, LPCWSTR lpszSearchFile, LPFILEPROPERTIESW fileprop)
Definition: ftp.c:3629
static const CHAR *const szFtpCommands[]
Definition: ftp.c:142
static const CHAR szMonths[]
Definition: ftp.c:165
BOOL WINAPI FtpCommandW(HINTERNET hConnect, BOOL fExpectResponse, DWORD dwFlags, LPCWSTR lpszCommand, DWORD_PTR dwContext, HINTERNET *phFtpCommand)
Definition: ftp.c:2255
static void AsyncFtpPutFileProc(task_header_t *hdr)
Definition: ftp.c:248
BOOL WINAPI FtpCreateDirectoryA(HINTERNET hConnect, LPCSTR lpszDirectory)
Definition: ftp.c:566
BOOL WINAPI FtpGetFileW(HINTERNET hInternet, LPCWSTR lpszRemoteFile, LPCWSTR lpszNewFile, BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags, DWORD_PTR dwContext)
Definition: ftp.c:1611
HINTERNET WINAPI FtpFindFirstFileA(HINTERNET hConnect, LPCSTR lpszSearchFile, LPWIN32_FIND_DATAA lpFindFileData, DWORD dwFlags, DWORD_PTR dwContext)
Definition: ftp.c:709
static BOOL FTP_SendPassword(ftp_session_t *)
Definition: ftp.c:2831
static DWORD FTP_SetResponseError(DWORD dwResponse)
Definition: ftp.c:3919
#define szCRLF
Definition: ftp.c:108
static BOOL FTP_DoPassive(ftp_session_t *)
Definition: ftp.c:3133
static void AsyncFtpGetFileProc(task_header_t *hdr)
Definition: ftp.c:1587
BOOL WINAPI FtpSetCurrentDirectoryA(HINTERNET hConnect, LPCSTR lpszDirectory)
Definition: ftp.c:419
HINTERNET WINAPI FtpOpenFileW(HINTERNET hFtpSession, LPCWSTR lpszFileName, DWORD fdwAccess, DWORD dwFlags, DWORD_PTR dwContext)
Definition: ftp.c:1486
static BOOL FTP_SendType(ftp_session_t *, DWORD dwType)
Definition: ftp.c:3008
HINTERNET WINAPI FtpOpenFileA(HINTERNET hFtpSession, LPCSTR lpszFileName, DWORD fdwAccess, DWORD dwFlags, DWORD_PTR dwContext)
Definition: ftp.c:1444
static BOOL FTP_ParsePermission(LPCSTR lpszPermission, LPFILEPROPERTIESW lpfp)
Definition: ftp.c:3856
static BOOL FTP_SendPort(ftp_session_t *)
Definition: ftp.c:3090
BOOL WINAPI FtpPutFileA(HINTERNET hConnect, LPCSTR lpszLocalFile, LPCSTR lpszNewRemoteFile, DWORD dwFlags, DWORD_PTR dwContext)
Definition: ftp.c:224
static DWORD FTPFILE_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
Definition: ftp.c:1142
BOOL WINAPI FtpCreateDirectoryW(HINTERNET hConnect, LPCWSTR lpszDirectory)
Definition: ftp.c:599
static LPSTR FTP_GetNextLine(INT nSocket, LPDWORD dwLen)
Definition: ftp.c:2642
static const object_vtbl_t FTPFINDNEXTVtbl
Definition: ftp.c:3526
static BOOL FTP_InitListenSocket(ftp_session_t *)
Definition: ftp.c:2948
static void AsyncFtpCreateDirectoryProc(task_header_t *hdr)
Definition: ftp.c:578
BOOL WINAPI FtpDeleteFileW(HINTERNET hFtpSession, LPCWSTR lpszFileName)
Definition: ftp.c:1815
static BOOL res_to_le(DWORD res)
Definition: ftp.c:207
BOOL WINAPI FtpSetCurrentDirectoryW(HINTERNET hConnect, LPCWSTR lpszDirectory)
Definition: ftp.c:456
static BOOL FTP_SendAccount(ftp_session_t *)
Definition: ftp.c:2871
static void FTP_ReceiveRequestData(ftp_file_t *file, BOOL first_notif)
Definition: ftp.c:1226
static DWORD FTPFINDNEXT_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
Definition: ftp.c:3491
static void AsyncFtpDeleteFileProc(task_header_t *hdr)
Definition: ftp.c:1794
static void AsyncFtpSetCurrentDirectoryProc(task_header_t *hdr)
Definition: ftp.c:435
static BOOL FTP_SendData(ftp_session_t *, INT nDataSocket, HANDLE hFile)
Definition: ftp.c:3265
static DWORD FTPFINDNEXT_FindNextFileW(object_header_t *hdr, void *data)
Definition: ftp.c:3508
static BOOL FTP_ParseDirectory(ftp_session_t *, INT nSocket, LPCWSTR lpszSearchFile, LPFILEPROPERTIESW *lpafp, LPDWORD dwfp)
Definition: ftp.c:3790
static HINTERNET FTP_FtpFindFirstFileW(ftp_session_t *, LPCWSTR lpszSearchFile, LPWIN32_FIND_DATAW lpFindFileData, DWORD dwFlags, DWORD_PTR dwContext)
Definition: ftp.c:814
static void AsyncFtpOpenFileProc(task_header_t *hdr)
Definition: ftp.c:1465
static DWORD FTPFILE_QueryDataAvailable(object_header_t *hdr, DWORD *available, DWORD flags, DWORD_PTR ctx)
Definition: ftp.c:1255
static DWORD FTPFILE_ReadFile(object_header_t *hdr, void *buffer, DWORD size, DWORD *read, DWORD flags, DWORD_PTR context)
Definition: ftp.c:1190
HINTERNET WINAPI FtpFindFirstFileW(HINTERNET hConnect, LPCWSTR lpszSearchFile, LPWIN32_FIND_DATAW lpFindFileData, DWORD dwFlags, DWORD_PTR dwContext)
Definition: ftp.c:757
static BOOL FTP_SendCommand(INT nSocket, FTP_COMMAND ftpCmd, LPCWSTR lpszParam, INTERNET_STATUS_CALLBACK lpfnStatusCB, object_header_t *hdr, DWORD_PTR dwContext)
Definition: ftp.c:2748
static BOOL FTP_FtpDeleteFileW(ftp_session_t *, LPCWSTR lpszFileName)
Definition: ftp.c:1877
static void AsyncFtpRenameFileProc(task_header_t *hdr)
Definition: ftp.c:2088
static HINTERNET FTP_ReceiveFileList(ftp_session_t *, INT nSocket, LPCWSTR lpszSearchFile, LPWIN32_FIND_DATAW lpFindFileData, DWORD_PTR dwContext)
Definition: ftp.c:3548
static HINTERNET FTP_FtpOpenFileW(ftp_session_t *lpwfs, LPCWSTR lpszFileName, DWORD fdwAccess, DWORD dwFlags, DWORD_PTR dwContext)
Definition: ftp.c:1318
static BOOL FTP_SendPortOrPasv(ftp_session_t *)
Definition: ftp.c:3205
BOOL WINAPI FtpRemoveDirectoryA(HINTERNET hFtpSession, LPCSTR lpszDirectory)
Definition: ftp.c:1925
static const object_vtbl_t FTPFILEVtbl
Definition: ftp.c:1295
HINTERNET FTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName, INTERNET_PORT nServerPort, LPCWSTR lpszUserName, LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext, DWORD dwInternalFlags)
Definition: ftp.c:2430
BOOL WINAPI FtpDeleteFileA(HINTERNET hFtpSession, LPCSTR lpszFileName)
Definition: ftp.c:1778
FTP_COMMAND
Definition: ftp.c:116
@ FTP_CMD_RETR
Definition: ftp.c:124
@ FTP_CMD_PORT
Definition: ftp.c:123
@ FTP_CMD_RNTO
Definition: ftp.c:127
@ FTP_CMD_LIST
Definition: ftp.c:135
@ FTP_CMD_SIZE
Definition: ftp.c:131
@ FTP_CMD_RNFR
Definition: ftp.c:126
@ FTP_CMD_PWD
Definition: ftp.c:138
@ FTP_CMD_MKD
Definition: ftp.c:121
@ FTP_CMD_RMD
Definition: ftp.c:125
@ FTP_CMD_QUIT
Definition: ftp.c:139
@ FTP_CMD_ABOR
Definition: ftp.c:134
@ FTP_CMD_CWD
Definition: ftp.c:119
@ FTP_CMD_PASS
Definition: ftp.c:122
@ FTP_CMD_DELE
Definition: ftp.c:120
@ FTP_CMD_TYPE
Definition: ftp.c:129
@ FTP_CMD_PASV
Definition: ftp.c:137
@ FTP_CMD_ACCT
Definition: ftp.c:118
@ FTP_CMD_STOR
Definition: ftp.c:128
@ FTP_CMD_NLST
Definition: ftp.c:136
@ FTP_CMD_USER
Definition: ftp.c:130
struct WININETFTPFINDNEXTW * LPWININETFTPFINDNEXTW
static BOOL FTP_FtpRenameFileW(ftp_session_t *, LPCWSTR lpszSrc, LPCWSTR lpszDest)
Definition: ftp.c:2173
#define DATA_PACKET_SIZE
Definition: ftp.c:107
static void FTPSESSION_Destroy(object_header_t *hdr)
Definition: ftp.c:2342
BOOL WINAPI FtpPutFileW(HINTERNET hConnect, LPCWSTR lpszLocalFile, LPCWSTR lpszNewRemoteFile, DWORD dwFlags, DWORD_PTR dwContext)
Definition: ftp.c:272
BOOL WINAPI FtpGetCurrentDirectoryW(HINTERNET hFtpSession, LPWSTR lpszCurrentDirectory, LPDWORD lpdwCurrentDirectory)
Definition: ftp.c:971
static BOOL FTP_FtpSetCurrentDirectoryW(ftp_session_t *, LPCWSTR lpszDirectory)
Definition: ftp.c:516
static BOOL FTP_FtpRemoveDirectoryW(ftp_session_t *, LPCWSTR lpszDirectory)
Definition: ftp.c:2019
static void FTPFILE_AsyncQueryDataAvailableProc(task_header_t *task)
Definition: ftp.c:1248
static BOOL FTP_SendCommandA(INT nSocket, FTP_COMMAND ftpCmd, LPCSTR lpszParam, INTERNET_STATUS_CALLBACK lpfnStatusCB, object_header_t *hdr, DWORD_PTR dwContext)
Definition: ftp.c:2694
static DWORD FTPFILE_LockRequestFile(object_header_t *hdr, req_file_t **ret)
Definition: ftp.c:1288
#define FTP_CONDITION_MASK
Definition: ftp.c:114
#define MAX_BACKLOG
Definition: ftp.c:109
static DWORD FTPFILE_WriteFile(object_header_t *hdr, const void *buffer, DWORD size, DWORD *written)
Definition: ftp.c:1215
static DWORD FTPSESSION_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
Definition: ftp.c:2380
BOOL WINAPI FtpGetCurrentDirectoryA(HINTERNET hFtpSession, LPSTR lpszCurrentDirectory, LPDWORD lpdwCurrentDirectory)
Definition: ftp.c:916
static void AsyncFtpFindFirstFileProc(task_header_t *hdr)
Definition: ftp.c:736
static BOOL FTP_FtpPutFileW(ftp_session_t *, LPCWSTR lpszLocalFile, LPCWSTR lpszNewRemoteFile, DWORD dwFlags, DWORD_PTR dwContext)
Definition: ftp.c:344
BOOL WINAPI FtpCommandA(HINTERNET hConnect, BOOL fExpectResponse, DWORD dwFlags, LPCSTR lpszCommand, DWORD_PTR dwContext, HINTERNET *phFtpCommand)
Definition: ftp.c:2219
static BOOL FTP_FtpGetFileW(ftp_session_t *, LPCWSTR lpszRemoteFile, LPCWSTR lpszNewFile, BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags, DWORD_PTR dwContext)
Definition: ftp.c:1688
static INT FTP_ReceiveResponse(ftp_session_t *, DWORD_PTR dwContext)
Definition: ftp.c:2768
static void FTPFILE_Destroy(object_header_t *hdr)
Definition: ftp.c:1117
static void FTPFINDNEXT_Destroy(object_header_t *hdr)
Definition: ftp.c:3430
#define RESPONSE_TIMEOUT
Definition: ftp.c:59
static BOOL FTP_SendStore(ftp_session_t *, LPCWSTR lpszRemoteFile, DWORD dwType)
Definition: ftp.c:2901
static BOOL FTP_ConvertFileProp(LPFILEPROPERTIESW lpafp, LPWIN32_FIND_DATAW lpFindFileData)
Definition: ftp.c:3592
static BOOL FTP_SendRetrieve(ftp_session_t *, LPCWSTR lpszRemoteFile, DWORD dwType)
Definition: ftp.c:3345
static void FTPFINDNEXT_AsyncFindNextFileProc(task_header_t *hdr)
Definition: ftp.c:3484
static BOOL FTP_RetrieveFileData(ftp_session_t *, INT nDataSocket, HANDLE hFile)
Definition: ftp.c:3391
static void AsyncFtpGetCurrentDirectoryProc(task_header_t *hdr)
Definition: ftp.c:951
BOOL WINAPI FtpGetFileA(HINTERNET hInternet, LPCSTR lpszRemoteFile, LPCSTR lpszNewFile, BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags, DWORD_PTR dwContext)
Definition: ftp.c:1560
static BOOL FTP_ConnectToHost(ftp_session_t *)
Definition: ftp.c:2599
static void FTPSESSION_CloseConnection(object_header_t *hdr)
Definition: ftp.c:2355
struct FILEPROPERTIESW * LPFILEPROPERTIESW
static BOOL FTP_FtpCreateDirectoryW(ftp_session_t *, LPCWSTR lpszDirectory)
Definition: ftp.c:661
BOOL WININET_Release(object_header_t *info)
Definition: internet.c:244
DWORD INTERNET_AsyncCall(task_header_t *task)
Definition: internet.c:4534
object_header_t * WININET_AddRef(object_header_t *info)
Definition: internet.c:202
DWORD INTERNET_GetLastError(void)
Definition: internet.c:4477
LPSTR INTERNET_GetResponseBuffer(void)
Definition: internet.c:4556
void INTERNET_SetLastError(DWORD dwError)
Definition: internet.c:4456
BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags, LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
Definition: internet.c:5050
DWORD INET_SetOption(object_header_t *hdr, DWORD option, void *buf, DWORD size)
Definition: internet.c:3309
void * alloc_async_task(object_header_t *hdr, async_task_proc_t proc, size_t size)
Definition: internet.c:4513
object_header_t * get_handle_object(HINTERNET hinternet)
Definition: internet.c:209
DWORD INET_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
Definition: internet.c:3159
void * alloc_object(object_header_t *parent, const object_vtbl_t *vtbl, size_t size)
Definition: internet.c:124
BOOL WINAPI CreateUrlCacheEntryW(LPCWSTR lpszUrlName, DWORD dwExpectedFileSize, LPCWSTR lpszFileExtension, LPWSTR lpszFileName, DWORD dwReserved)
Definition: urlcache.c:2808
INT WSAAPI select(IN INT s, IN OUT LPFD_SET readfds, IN OUT LPFD_SET writefds, IN OUT LPFD_SET exceptfds, IN CONST struct timeval *timeout)
Definition: select.c:41
void init_winsock(void)
Definition: dpnet_main.c:55
return ret
Definition: mutex.c:147
#define L(x)
Definition: resources.c:13
#define SOCK_STREAM
Definition: tcpip.h:118
#define AF_INET
Definition: tcpip.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
PWDF_CHILD_ADDRESS_DESCRIPTION_HEADER pAddr
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLuint buffer
Definition: glext.h:5915
GLuint res
Definition: glext.h:9613
GLsizeiptr size
Definition: glext.h:5919
GLint namelen
Definition: glext.h:7232
GLbitfield flags
Definition: glext.h:7161
GLfloat f
Definition: glext.h:7540
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
VOID INTERNET_SendCallback(object_header_t *hdr, DWORD_PTR dwContext, DWORD dwInternetStatus, LPVOID lpvStatusInfo, DWORD dwStatusInfoLength)
static void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW, LPWIN32_FIND_DATAA dataA)
Definition: internet.h:180
#define INET_OPENURL
Definition: internet.h:209
@ WH_HFILE
Definition: internet.h:204
@ WH_HFTPFINDNEXT
Definition: internet.h:205
@ WH_HFTPSESSION
Definition: internet.h:201
@ WH_HINIT
Definition: internet.h:200
BOOL GetAddress(const WCHAR *, INTERNET_PORT, SOCKADDR *, int *, char *)
Definition: utility.c:47
const char * filename
Definition: ioapi.h:137
char hdr[14]
Definition: iptest.cpp:33
#define debugstr_a
Definition: kernel32.h:31
#define debugstr_w
Definition: kernel32.h:32
#define ZeroMemory
Definition: minwinbase.h:31
int * LPINT
Definition: minwindef.h:151
__u16 time
Definition: mkdosfs.c:8
#define error(str)
Definition: mkdosfs.c:1605
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define htons(x)
Definition: module.h:215
#define CREATE_ALWAYS
Definition: disk.h:72
#define CREATE_NEW
Definition: disk.h:69
int socklen_t
Definition: tcp.c:35
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define sprintf
Definition: sprintf.c:45
static const WCHAR url[]
Definition: encode.c:1384
#define min(a, b)
Definition: monoChain.cc:55
_In_ HANDLE hFile
Definition: mswsock.h:90
#define ioctlsocket
Definition: ncftp.h:481
#define closesocket
Definition: ncftp.h:477
_In_ LPWSTR _In_ DWORD _In_ DWORD _In_ DWORD dwFlags
Definition: netsh.h:141
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define DWORD
Definition: nt_native.h:44
#define GENERIC_WRITE
Definition: nt_native.h:90
short WCHAR
Definition: pedump.c:58
long LONG
Definition: pedump.c:60
char CHAR
Definition: pedump.c:57
#define MAX_REPLY_LEN
Definition: request.c:2622
#define calloc
Definition: rosglue.h:14
strcat
Definition: string.h:92
#define memset(x, y, z)
Definition: compat.h:39
INT WSAAPI getsockname(IN SOCKET s, OUT LPSOCKADDR name, IN OUT INT FAR *namelen)
Definition: sockctrl.c:213
INT WSAAPI listen(IN SOCKET s, IN INT backlog)
Definition: sockctrl.c:123
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: socklife.c:36
SOCKET WSAAPI accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
Definition: socklife.c:23
#define TRACE(s)
Definition: solgame.cpp:4
LPWSTR lpszName
Definition: ftp.c:92
SYSTEMTIME tmLastModified
Definition: ftp.c:94
DWORD nSize
Definition: ftp.c:93
unsigned short permissions
Definition: ftp.c:95
BOOL bIsDirectory
Definition: ftp.c:91
DWORD_PTR dwResult
Definition: wininet.h:155
DWORD dwStructSize
Definition: wininet.h:211
LPWSTR lpszHostName
Definition: wininet.h:215
INTERNET_SCHEME nScheme
Definition: wininet.h:214
LPWSTR lpszUserName
Definition: wininet.h:218
LPWSTR lpszUrlPath
Definition: wininet.h:222
INTERNET_PORT nPort
Definition: wininet.h:217
ftp_session_t * lpFtpSession
Definition: ftp.c:101
object_header_t hdr
Definition: ftp.c:100
LPFILEPROPERTIESW lpafp
Definition: ftp.c:104
WORD wSecond
Definition: minwinbase.h:262
WORD wMinute
Definition: minwinbase.h:261
FILETIME ftLastWriteTime
Definition: minwinbase.h:286
_Field_z_ WCHAR cFileName[MAX_PATH]
Definition: minwinbase.h:291
DWORD dwFileAttributes
Definition: minwinbase.h:283
FILETIME ftLastAccessTime
Definition: minwinbase.h:285
FILETIME ftCreationTime
Definition: minwinbase.h:284
object_header_t hdr
Definition: ftp.c:75
ftp_file_t * download_in_progress
Definition: ftp.c:80
int lstnSocket
Definition: ftp.c:78
LPWSTR servername
Definition: ftp.c:83
INTERNET_PORT serverport
Definition: ftp.c:84
int pasvSocket
Definition: ftp.c:79
struct sockaddr_in lstnSocketAddress
Definition: ftp.c:82
appinfo_t * lpAppInfo
Definition: ftp.c:76
int sndSocket
Definition: ftp.c:77
LPWSTR lpszPassword
Definition: ftp.c:85
struct sockaddr_in socketAddress
Definition: ftp.c:81
LPWSTR lpszUserName
Definition: ftp.c:86
WH_TYPE htype
Definition: internet.h:240
HINTERNET hInternet
Definition: internet.h:242
DWORD dwInternalFlags
Definition: internet.h:253
struct list children
Definition: internet.h:258
struct list entry
Definition: internet.h:257
DWORD_PTR dwContext
Definition: internet.h:250
INTERNET_STATUS_CALLBACK lpfnStatusCB
Definition: internet.h:256
LPWSTR proxy
Definition: internet.h:265
LPWSTR proxyBypass
Definition: internet.h:266
DWORD accessType
Definition: internet.h:269
object_header_t hdr
Definition: internet.h:263
Definition: ftp_var.h:139
Definition: http.c:7783
WCHAR * file_name
Definition: ftp.c:1791
task_header_t hdr
Definition: ftp.c:1790
WCHAR * directory
Definition: ftp.c:432
task_header_t hdr
Definition: ftp.c:431
Definition: winsock.h:60
Definition: fci.c:123
task_header_t hdr
Definition: ftp.c:729
WIN32_FIND_DATAW * find_file_data
Definition: ftp.c:731
WCHAR * search_file
Definition: ftp.c:730
DWORD_PTR context
Definition: ftp.c:733
WIN32_FIND_DATAW * find_data
Definition: ftp.c:3481
task_header_t hdr
Definition: ftp.c:3480
Definition: ftp.c:64
WCHAR * cache_file
Definition: ftp.c:69
BOOL session_deleted
Definition: ftp.c:67
ftp_session_t * lpFtpSession
Definition: ftp.c:66
HANDLE cache_file_handle
Definition: ftp.c:70
int nDataSocket
Definition: ftp.c:68
object_header_t hdr
Definition: ftp.c:65
DWORD * directory_len
Definition: ftp.c:948
task_header_t hdr
Definition: ftp.c:946
WCHAR * directory
Definition: ftp.c:947
DWORD local_attr
Definition: ftp.c:1582
WCHAR * new_file
Definition: ftp.c:1580
task_header_t hdr
Definition: ftp.c:1578
DWORD_PTR context
Definition: ftp.c:1584
DWORD flags
Definition: ftp.c:1583
BOOL fail_if_exists
Definition: ftp.c:1581
WCHAR * remote_file
Definition: ftp.c:1579
Definition: copy.c:22
Definition: name.c:39
task_header_t hdr
Definition: ftp.c:1458
WCHAR * file_name
Definition: ftp.c:1459
DWORD_PTR context
Definition: ftp.c:1462
DWORD flags
Definition: ftp.c:1461
DWORD access
Definition: ftp.c:1460
Definition: getopt.h:109
task_header_t hdr
Definition: ftp.c:241
DWORD_PTR context
Definition: ftp.c:245
WCHAR * remote_file
Definition: ftp.c:243
WCHAR * local_file
Definition: ftp.c:242
DWORD flags
Definition: ftp.c:244
WCHAR * dst_file
Definition: ftp.c:2085
task_header_t hdr
Definition: ftp.c:2083
WCHAR * src_file
Definition: ftp.c:2084
struct in_addr sin_addr
Definition: winsock.h:506
short sin_family
Definition: winsock.h:504
u_short sin_port
Definition: winsock.h:505
#define byte(x, n)
Definition: tomcrypt.h:118
#define DWORD_PTR
Definition: treelist.c:76
const char * LPCSTR
Definition: typedefs.h:52
const uint16_t * LPCWSTR
Definition: typedefs.h:57
uint32_t DWORD_PTR
Definition: typedefs.h:65
unsigned char * LPBYTE
Definition: typedefs.h:53
uint16_t * LPWSTR
Definition: typedefs.h:56
uint32_t * LPDWORD
Definition: typedefs.h:59
char * LPSTR
Definition: typedefs.h:51
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
static WCHAR * strndupW(LPCWSTR str, int len)
Definition: urlmon_main.h:236
int retval
Definition: wcstombs.cpp:91
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_In_opt_ LPSTR _In_opt_ LPSTR lpszPassword
Definition: winbase.h:2442
#define WINAPI
Definition: msvc.h:6
#define swprintf
Definition: winemm.h:209
#define ERROR_NO_MORE_FILES
Definition: winerror.h:243
WORD INTERNET_PORT
Definition: winhttp.h:43
#define INTERNET_SCHEME_FTP
Definition: winhttp.h:49
#define INTERNET_DEFAULT_FTP_PORT
Definition: wininet.h:38
#define INTERNET_STATUS_RECEIVING_RESPONSE
Definition: wininet.h:889
#define ERROR_INTERNET_EXTENDED_ERROR
Definition: wininet.h:1992
#define INTERNET_STATUS_CONNECTION_CLOSED
Definition: wininet.h:894
#define INTERNET_ERROR_BASE
Definition: wininet.h:1988
#define INTERNET_FLAG_TRANSFER_ASCII
Definition: wininet.h:90
#define INTERNET_FLAG_ASYNC
Definition: wininet.h:64
#define INTERNET_STATUS_REQUEST_SENT
Definition: wininet.h:888
VOID(CALLBACK * INTERNET_STATUS_CALLBACK)(_In_ HINTERNET, _In_opt_ DWORD_PTR, _In_ DWORD, _In_opt_ LPVOID, _In_ DWORD)
Definition: wininet.h:859
#define ERROR_INTERNET_ITEM_NOT_FOUND
Definition: wininet.h:2017
#define INTERNET_FLAG_PASSIVE
Definition: wininet.h:65
#define FTP_TRANSFER_TYPE_BINARY
Definition: wininet.h:919
#define ERROR_INTERNET_TIMEOUT
Definition: wininet.h:1991
#define INTERNET_STATUS_SENDING_REQUEST
Definition: wininet.h:887
#define INTERNET_OPTION_DATAFILE_NAME
Definition: wininet.h:727
#define ERROR_INTERNET_DISCONNECTED
Definition: wininet.h:2072
#define ERROR_INTERNET_CONNECTION_ABORTED
Definition: wininet.h:2019
#define INTERNET_HANDLE_TYPE_FTP_FIND
Definition: wininet.h:806
#define INTERNET_STATUS_RESOLVING_NAME
Definition: wininet.h:883
#define ERROR_INTERNET_LOGIN_FAILURE
Definition: wininet.h:2004
#define INTERNET_STATUS_RESPONSE_RECEIVED
Definition: wininet.h:890
#define INTERNET_STATUS_REQUEST_COMPLETE
Definition: wininet.h:898
#define INTERNET_STATUS_CONNECTING_TO_SERVER
Definition: wininet.h:885
#define ERROR_FTP_TRANSFER_IN_PROGRESS
Definition: wininet.h:2046
#define INTERNET_OPEN_TYPE_PROXY
Definition: wininet.h:523
#define INTERNET_INVALID_PORT_NUMBER
Definition: wininet.h:36
#define INTERNET_STATUS_HANDLE_CREATED
Definition: wininet.h:895
#define ERROR_INTERNET_CANNOT_CONNECT
Definition: wininet.h:2018
#define INTERNET_HANDLE_TYPE_CONNECT_FTP
Definition: wininet.h:803
#define ERROR_INTERNET_NAME_NOT_RESOLVED
Definition: wininet.h:1996
#define INTERNET_STATUS_CONNECTED_TO_SERVER
Definition: wininet.h:886
#define INTERNET_STATUS_NAME_RESOLVED
Definition: wininet.h:884
#define INTERNET_OPTION_HANDLE_TYPE
Definition: wininet.h:710
#define INTERNET_HANDLE_TYPE_FTP_FILE
Definition: wininet.h:808
#define ERROR_INTERNET_INCORRECT_HANDLE_TYPE
Definition: wininet.h:2007
#define INTERNET_STATUS_CLOSING_CONNECTION
Definition: wininet.h:893
#define HKEY_CURRENT_USER
Definition: winreg.h:11
int PASCAL FAR WSAGetLastError(void)
Definition: dllmain.c:131
#define FD_ZERO(set)
Definition: winsock.h:90
#define MSG_PEEK
Definition: winsock.h:216
#define FIONREAD
Definition: winsock.h:241
#define FD_SET(fd, set)
Definition: winsock.h:83
#define INET6_ADDRSTRLEN
Definition: ws2ipdef.h:132
unsigned char BYTE
Definition: xxhash.c:193