| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/Main/lib/CFtp.h $ |
| 21 | * $Revision: 1.3 $ |
| 22 | * $Date: 2004/02/09 04:14:51 $ |
| 23 | * $Author: kevinb $ |
| 24 | * |
| 25 | * FTP Client class (get only) |
| 26 | * |
| 27 | * $Log: CFtp.h,v $ |
| 28 | * Revision 1.3 2004/02/09 04:14:51 kevinb |
| 29 | * Added newlines to all headers to reduce number of warnings printed |
| 30 | * |
| 31 | * Made some small changes to get everything compiling. |
| 32 | * |
| 33 | * All Ready to merge the 1.5 tree. |
| 34 | * |
| 35 | * Revision 1.2 2000/06/03 14:30:33 icculus |
| 36 | * 1.4 code merge and pthread->SDL thread conversion. |
| 37 | * |
| 38 | * Revision 1.1.1.1 2000/04/18 00:00:38 icculus |
| 39 | * initial checkin |
| 40 | * |
| 41 | * |
| 42 | * 4 8/21/99 6:48a Jeff |
| 43 | * Linux port |
| 44 | * |
| 45 | * 3 7/31/98 11:40a Kevin |
| 46 | * |
| 47 | * 2 6/01/98 10:10a Kevin |
| 48 | * Added DLL connection interface and auto update DLL |
| 49 | * |
| 50 | * 1 5/27/98 9:54a Kevin |
| 51 | * |
| 52 | * 1 5/25/98 5:31p Kevin |
| 53 | * Initial version |
| 54 | * |
| 55 | * $NoKeywords: $ |
| 56 | */ |
| 57 | #ifndef _CFTP_HEADER_ |
| 58 | #define _CFTP_HEADER_ |
| 59 | |
| 60 | #include <cstdint> |
| 61 | |
| 62 | #define FTP_STATE_INTERNAL_ERROR 0 |
| 63 | #define FTP_STATE_SOCKET_ERROR 1 |
| 64 | #define FTP_STATE_URL_PARSING_ERROR 2 |
| 65 | #define FTP_STATE_CONNECTING 3 |
| 66 | #define FTP_STATE_HOST_NOT_FOUND 4 |
| 67 | #define FTP_STATE_CANT_CONNECT 5 |
| 68 | #define FTP_STATE_LOGGING_IN 6 |
| 69 | #define FTP_STATE_LOGIN_ERROR 7 |
| 70 | #define FTP_STATE_LOGGED_IN 8 |
| 71 | #define FTP_STATE_DIRECTORY_INVALID 9 |
| 72 | #define FTP_STATE_FILE_NOT_FOUND 10 |
| 73 | #define FTP_STATE_RECEIVING 11 |
| 74 | #define FTP_STATE_FILE_RECEIVED 12 |
| 75 | #define FTP_STATE_UNKNOWN_ERROR 13 |
| 76 | #define FTP_STATE_RECV_FAILED 14 |
| 77 | #define FTP_STATE_CANT_WRITE_FILE 15 |
| 78 | #define FTP_STATE_STARTUP 16 |
| 79 | |
| 80 | #if WIN32 |
| 81 | typedef UINT_PTR SOCKET; |
| 82 | #endif |
| 83 | |
| 84 | #if defined(POSIX) |
| 85 | extern int FTPObjThread(void *obj); |
| 86 | #else |
| 87 | extern void FTPObjThread(void *obj); |
| 88 | #endif |
| 89 | |
| 90 | class CFtpGet { |
| 91 | |
| 92 | public: |
| 93 | CFtpGet(char *URL, char *localfile, char *Username = NULL, char *Password = NULL); |
| 94 | ~CFtpGet(); |
| 95 | int GetStatus(); |
| 96 | uint32_t GetBytesIn(); |
| 97 | uint32_t GetTotalBytes(); |
| 98 | void AbortGet(); |
| 99 | |
| 100 | void WorkerThread(); |
| 101 | |
| 102 | protected: |
| 103 | int ConnectControlSocket(); |
| 104 | int LoginHost(); |
| 105 | uint32_t SendFTPCommand(char *command); |
| 106 | uint32_t ReadFTPServerReply(); |
| 107 | uint32_t GetFile(); |
| 108 | uint32_t IssuePort(); |
| 109 | uint32_t ReadDataChannel(); |
| 110 | void FlushControlChannel(); |
| 111 | |
| 112 | uint32_t m_iBytesIn; |
| 113 | uint32_t m_iBytesTotal; |
| 114 | uint32_t m_State; |
| 115 | |
| 116 | bool m_Aborting; |
| 117 | bool m_Aborted; |
| 118 | |
| 119 | char m_szUserName[100]; |
| 120 | char m_szPassword[100]; |
| 121 | char m_szHost[200]; |
| 122 | char m_szDir[200]; |
| 123 | char m_szFilename[100]; |
| 124 | |
| 125 | char recv_buffer[1000]; |
| 126 | |
| 127 | SOCKET m_ListenSock; |
| 128 | SOCKET m_DataSock; |
| 129 | SOCKET m_ControlSock; |
| 130 | |
| 131 | FILE *LOCALFILE; |
| 132 | }; |
| 133 | |
| 134 | #endif |