Debian Codegraph @

netcon/inetfile/inetgetfile.cpp

raw symbols SCIP
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/inetfile/inetgetfile.cpp $
21 * $Revision: 1.2 $
22 * $Date: 2000/06/03 14:33:51 $
23 * $Author: icculus $
24 *
25 * InternetGetFile Class
26 *
27 * $Log: inetgetfile.cpp,v $
28 * Revision 1.2 2000/06/03 14:33:51 icculus
29 * Merge with Outrage 1.4 tree...
30 *
31 * Revision 1.1.1.1 2000/04/18 00:00:38 icculus
32 * initial checkin
33 *
34 *
35 * 10 10/21/99 9:28p Jeff
36 * B.A. Macintosh code merge
37 *
38 * 9 9/08/99 6:37p Jeff
39 * fixed http/ftp downloading for Linux, should all work fine now.
40 *
41 * 8 8/23/99 5:12p Kevin
42 * Proxy support for http
43 *
44 * 7 8/21/99 6:48a Jeff
45 * Linux port
46 *
47 * 6 4/14/99 1:20a Jeff
48 * fixed case mismatched #includes
49 *
50 * 5 7/31/98 11:57a Kevin
51 * Added new functions for getting state
52 *
53 * 4 7/31/98 11:40a Kevin
54 *
55 * 3 7/31/98 11:17a Nate
56 * Fixed memory leak and added memory alloc checking.
57 *
58 * 2 6/01/98 10:10a Kevin
59 * Added DLL connection interface and auto update DLL
60 *
61 * 1 5/27/98 9:52a Kevin
62 *
63 * 1 5/25/98 5:31p Kevin
64 * Initial version
65 *
66 * $NoKeywords: $
67 */
68
69 #if defined(WIN32)
70 #include <windows.h>
71 #endif
72
73 #include <stdio.h>
74 #include <stdlib.h>
75 #include <string.h>
76
77
78 // include inetgetfile.h before CFtp.h and Chttpget.h because it has some winsock defines
79 // to make Linux happy
80 #include "inetgetfile.h"cxx . . $ `<file>/netcon/includes/inetgetfile.h`/
81 #include "CFtp.h"cxx . . $ `<file>/netcon/includes/CFtp.h`/
82 #include "Chttpget.h"cxx . . $ `<file>/netcon/includes/Chttpget.h`/
83
84 extern char *Proxy_servercxx . . $ Proxy_server.;
85 extern int16_t Proxy_portcxx . . $ Proxy_port.;
86
87 #if defined(POSIXcxx . . $ `<built-in>:478:9`!)
88 /* ryan sez: use SDL.
89 pthread_create_fp df_pthread_create = NULL;
90 pthread_exit_fp df_pthread_exit = NULL;
91 pthread_detach_fp df_pthread_detach = NULL;
92 pthread_self_fp df_pthread_self = NULL;
93 */
94 bool inet_LoadThreadLibcxx . . $ inet_LoadThreadLib(c9857a73d68e59ba).(void) {
95 return true;
96 /*
97 if(df_pthread_create)
98 return true;
99
100 void *lib;
101
102 lib = dlopen("libpthread.so",RTLD_GLOBAL|RTLD_NOW);
103 if(!lib)
104 {
105 return false;
106 }
107
108 df_pthread_create = (pthread_create_fp)dlsym(lib,"pthread_create");
109 df_pthread_detach = (pthread_detach_fp)dlsym(lib,"pthread_detach");
110 df_pthread_self = (pthread_self_fp)dlsym(lib,"pthread_self");
111
112 if(!df_pthread_create || !df_pthread_detach || !df_pthread_self)
113 {
114 df_pthread_create = NULL; //this variable I use to see if the library is loaded
115 return false;
116 }
117
118 // don't close the library...we need it open for future use
119 // and we can't close it on atexit() because linux will segfault for some stupid reason
120 return true;
121 */
122 }
123 #endif
124
125 void InetGetFilecxx . . $ InetGetFile#::AbortGetcxx . . $ InetGetFile#AbortGet(49f6e7a06ebc5aa8).() {
126 if (m_bUseHTTPcxx . . $ InetGetFile#m_bUseHTTP.) {
127 httpcxx . . $ InetGetFile#http.->AbortGetcxx . . $ ChttpGet#AbortGet(49f6e7a06ebc5aa8).();
128 } else {
129 ftpcxx . . $ InetGetFile#ftp.->AbortGetcxx . . $ CFtpGet#AbortGet(49f6e7a06ebc5aa8).();
130 }
131 }
132
133 InetGetFilecxx . . $ InetGetFile#::InetGetFilecxx . . $ InetGetFile#InetGetFile(70b3d6b1f7183c65).(char *URL, char *localfile, char *proxyip, int16_t proxyport) {
134 m_HardErrorcxx . . $ InetGetFile#m_HardError. = 0;
135 httpcxx . . $ InetGetFile#http. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
136 ftpcxx . . $ InetGetFile#ftp. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
137 if ((URL == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) || (localfile == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)) {
138 m_HardErrorcxx . . $ InetGetFile#m_HardError. = INET_ERROR_BADPARMScxx . . $ `netcon/includes/inetgetfile.h:153:9`!;
139 }
140 if (strstr(URL, "http:")) {
141 m_bUseHTTPcxx . . $ InetGetFile#m_bUseHTTP. = true;
142 httpcxx . . $ InetGetFile#http. = new ChttpGetcxx . . $ ChttpGet#(URL, localfile, proxyip, proxyport);
143 if (httpcxx . . $ InetGetFile#http. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
144 m_HardErrorcxx . . $ InetGetFile#m_HardError. = INET_ERROR_NO_MEMORYcxx . . $ `netcon/includes/inetgetfile.h:159:9`!;
145 } else if (strstr(URL, "HTTP:")) {
146 m_bUseHTTPcxx . . $ InetGetFile#m_bUseHTTP. = true;
147 httpcxx . . $ InetGetFile#http. = new ChttpGetcxx . . $ ChttpGet#(URL, localfile, proxyip, proxyport);
148 if (httpcxx . . $ InetGetFile#http. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
149 m_HardErrorcxx . . $ InetGetFile#m_HardError. = INET_ERROR_NO_MEMORYcxx . . $ `netcon/includes/inetgetfile.h:159:9`!;
150 } else if (strstr(URL, "FTP:")) {
151 m_bUseHTTPcxx . . $ InetGetFile#m_bUseHTTP. = false;
152 ftpcxx . . $ InetGetFile#ftp. = new CFtpGetcxx . . $ CFtpGet#(URL, localfile);
153 if (ftpcxx . . $ InetGetFile#ftp. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
154 m_HardErrorcxx . . $ InetGetFile#m_HardError. = INET_ERROR_NO_MEMORYcxx . . $ `netcon/includes/inetgetfile.h:159:9`!;
155 } else if (strstr(URL, "ftp:")) {
156 m_bUseHTTPcxx . . $ InetGetFile#m_bUseHTTP. = false;
157 ftpcxx . . $ InetGetFile#ftp. = new CFtpGetcxx . . $ CFtpGet#(URL, localfile);
158 if (ftpcxx . . $ InetGetFile#ftp. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
159 m_HardErrorcxx . . $ InetGetFile#m_HardError. = INET_ERROR_NO_MEMORYcxx . . $ `netcon/includes/inetgetfile.h:159:9`!;
160 } else {
161 m_HardErrorcxx . . $ InetGetFile#m_HardError. = INET_ERROR_CANT_PARSE_URLcxx . . $ `netcon/includes/inetgetfile.h:155:9`!;
162 }
163 Sleepcxx . . $ Sleep(d4f767463ce0a6b3).(1000);
164 }
165
166 InetGetFilecxx . . $ InetGetFile#::InetGetFilecxx . . $ InetGetFile#InetGetFile(d0489a02ea06dfc6).(char *URL, char *localfile) {
167 m_HardErrorcxx . . $ InetGetFile#m_HardError. = 0;
168 httpcxx . . $ InetGetFile#http. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
169 ftpcxx . . $ InetGetFile#ftp. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
170 if ((URL == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) || (localfile == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)) {
171 m_HardErrorcxx . . $ InetGetFile#m_HardError. = INET_ERROR_BADPARMScxx . . $ `netcon/includes/inetgetfile.h:153:9`!;
172 }
173 if (strstr(URL, "http:")) {
174 m_bUseHTTPcxx . . $ InetGetFile#m_bUseHTTP. = true;
175 httpcxx . . $ InetGetFile#http. = new ChttpGetcxx . . $ ChttpGet#(URL, localfile);
176 if (httpcxx . . $ InetGetFile#http. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
177 m_HardErrorcxx . . $ InetGetFile#m_HardError. = INET_ERROR_NO_MEMORYcxx . . $ `netcon/includes/inetgetfile.h:159:9`!;
178 } else if (strstr(URL, "HTTP:")) {
179 m_bUseHTTPcxx . . $ InetGetFile#m_bUseHTTP. = true;
180 httpcxx . . $ InetGetFile#http. = new ChttpGetcxx . . $ ChttpGet#(URL, localfile);
181 if (httpcxx . . $ InetGetFile#http. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
182 m_HardErrorcxx . . $ InetGetFile#m_HardError. = INET_ERROR_NO_MEMORYcxx . . $ `netcon/includes/inetgetfile.h:159:9`!;
183 } else if (strstr(URL, "FTP:")) {
184 m_bUseHTTPcxx . . $ InetGetFile#m_bUseHTTP. = false;
185 ftpcxx . . $ InetGetFile#ftp. = new CFtpGetcxx . . $ CFtpGet#(URL, localfile);
186 if (ftpcxx . . $ InetGetFile#ftp. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
187 m_HardErrorcxx . . $ InetGetFile#m_HardError. = INET_ERROR_NO_MEMORYcxx . . $ `netcon/includes/inetgetfile.h:159:9`!;
188 } else if (strstr(URL, "ftp:")) {
189 m_bUseHTTPcxx . . $ InetGetFile#m_bUseHTTP. = false;
190 ftpcxx . . $ InetGetFile#ftp. = new CFtpGetcxx . . $ CFtpGet#(URL, localfile);
191 if (ftpcxx . . $ InetGetFile#ftp. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
192 m_HardErrorcxx . . $ InetGetFile#m_HardError. = INET_ERROR_NO_MEMORYcxx . . $ `netcon/includes/inetgetfile.h:159:9`!;
193 } else {
194 m_HardErrorcxx . . $ InetGetFile#m_HardError. = INET_ERROR_CANT_PARSE_URLcxx . . $ `netcon/includes/inetgetfile.h:155:9`!;
195 }
196 Sleepcxx . . $ Sleep(d4f767463ce0a6b3).(1000);
197 }
198
199 InetGetFilecxx . . $ InetGetFile#::~cxx . . $ InetGetFile#`~InetGetFile`(ced63f7c635d850d).InetGetFilecxx . . $ InetGetFile#() {
200 if (httpcxx . . $ InetGetFile#http. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
201 delete httpcxx . . $ InetGetFile#http.;
202 if (ftpcxx . . $ InetGetFile#ftp. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
203 delete ftpcxx . . $ InetGetFile#ftp.;
204 }
205
206 BOOLcxx . . $ `lib/networking.h:218:9`! InetGetFilecxx . . $ InetGetFile#::IsConnectingcxx . . $ InetGetFile#IsConnecting(c9857a73d68e59ba).() {
207 int state;
208 if (m_bUseHTTPcxx . . $ InetGetFile#m_bUseHTTP.) {
209 state = httpcxx . . $ InetGetFile#http.->GetStatuscxx . . $ ChttpGet#GetStatus(b126dc7c1de90089).();
210 } else if (ftpcxx . . $ InetGetFile#ftp.) {
211 state = ftpcxx . . $ InetGetFile#ftp.->GetStatuscxx . . $ CFtpGet#GetStatus(b126dc7c1de90089).();
212 } else {
213 return false;
214 }
215 if (state == FTP_STATE_CONNECTINGcxx . . $ `netcon/includes/CFtp.h:65:9`!) {
216 return true;
217 } else {
218 return false;
219 }
220 }
221
222 BOOLcxx . . $ `lib/networking.h:218:9`! InetGetFilecxx . . $ InetGetFile#::IsReceivingcxx . . $ InetGetFile#IsReceiving(c9857a73d68e59ba).() {
223 int state = 0;
224 if (m_bUseHTTPcxx . . $ InetGetFile#m_bUseHTTP.) {
225 state = httpcxx . . $ InetGetFile#http.->GetStatuscxx . . $ ChttpGet#GetStatus(b126dc7c1de90089).();
226 } else if (ftpcxx . . $ InetGetFile#ftp.) {
227 state = ftpcxx . . $ InetGetFile#ftp.->GetStatuscxx . . $ CFtpGet#GetStatus(b126dc7c1de90089).();
228 }
229 if (state == FTP_STATE_RECEIVINGcxx . . $ `netcon/includes/CFtp.h:73:9`!) {
230 return true;
231 } else {
232 return false;
233 }
234 }
235
236 BOOLcxx . . $ `lib/networking.h:218:9`! InetGetFilecxx . . $ InetGetFile#::IsFileReceivedcxx . . $ InetGetFile#IsFileReceived(c9857a73d68e59ba).() {
237 int state = 0;
238 if (m_bUseHTTPcxx . . $ InetGetFile#m_bUseHTTP.) {
239 state = httpcxx . . $ InetGetFile#http.->GetStatuscxx . . $ ChttpGet#GetStatus(b126dc7c1de90089).();
240 } else if (ftpcxx . . $ InetGetFile#ftp.) {
241 state = ftpcxx . . $ InetGetFile#ftp.->GetStatuscxx . . $ CFtpGet#GetStatus(b126dc7c1de90089).();
242 }
243 if (state == FTP_STATE_FILE_RECEIVEDcxx . . $ `netcon/includes/CFtp.h:74:9`!) {
244 return true;
245 } else {
246 return false;
247 }
248 }
249
250 BOOLcxx . . $ `lib/networking.h:218:9`! InetGetFilecxx . . $ InetGetFile#::IsFileErrorcxx . . $ InetGetFile#IsFileError(c9857a73d68e59ba).() {
251 int state = FTP_STATE_INTERNAL_ERRORcxx . . $ `netcon/includes/CFtp.h:62:9`!;
252 if (m_HardErrorcxx . . $ InetGetFile#m_HardError.)
253 return true;
254 if (m_bUseHTTPcxx . . $ InetGetFile#m_bUseHTTP.) {
255 state = httpcxx . . $ InetGetFile#http.->GetStatuscxx . . $ ChttpGet#GetStatus(b126dc7c1de90089).();
256 } else if (ftpcxx . . $ InetGetFile#ftp.) {
257 state = ftpcxx . . $ InetGetFile#ftp.->GetStatuscxx . . $ CFtpGet#GetStatus(b126dc7c1de90089).();
258 }
259 switch (state) {
260
261 case FTP_STATE_URL_PARSING_ERRORcxx . . $ `netcon/includes/CFtp.h:64:9`!:
262 case FTP_STATE_HOST_NOT_FOUNDcxx . . $ `netcon/includes/CFtp.h:66:9`!:
263 case FTP_STATE_DIRECTORY_INVALIDcxx . . $ `netcon/includes/CFtp.h:71:9`!:
264 case FTP_STATE_FILE_NOT_FOUNDcxx . . $ `netcon/includes/CFtp.h:72:9`!:
265 case FTP_STATE_CANT_CONNECTcxx . . $ `netcon/includes/CFtp.h:67:9`!:
266 case FTP_STATE_LOGIN_ERRORcxx . . $ `netcon/includes/CFtp.h:69:9`!:
267 case FTP_STATE_INTERNAL_ERRORcxx . . $ `netcon/includes/CFtp.h:62:9`!:
268 case FTP_STATE_SOCKET_ERRORcxx . . $ `netcon/includes/CFtp.h:63:9`!:
269 case FTP_STATE_UNKNOWN_ERRORcxx . . $ `netcon/includes/CFtp.h:75:9`!:
270 case FTP_STATE_RECV_FAILEDcxx . . $ `netcon/includes/CFtp.h:76:9`!:
271 case FTP_STATE_CANT_WRITE_FILEcxx . . $ `netcon/includes/CFtp.h:77:9`!:
272 return true;
273 case FTP_STATE_CONNECTINGcxx . . $ `netcon/includes/CFtp.h:65:9`!:
274 return false;
275 default:
276 return false;
277 }
278 }
279
280 int InetGetFilecxx . . $ InetGetFile#::GetErrorCodecxx . . $ InetGetFile#GetErrorCode(b126dc7c1de90089).() {
281 int state = FTP_STATE_INTERNAL_ERRORcxx . . $ `netcon/includes/CFtp.h:62:9`!;
282 if (m_HardErrorcxx . . $ InetGetFile#m_HardError.)
283 return m_HardErrorcxx . . $ InetGetFile#m_HardError.;
284 if (m_bUseHTTPcxx . . $ InetGetFile#m_bUseHTTP.) {
285 state = httpcxx . . $ InetGetFile#http.->GetStatuscxx . . $ ChttpGet#GetStatus(b126dc7c1de90089).();
286 } else if (ftpcxx . . $ InetGetFile#ftp.) {
287 state = ftpcxx . . $ InetGetFile#ftp.->GetStatuscxx . . $ CFtpGet#GetStatus(b126dc7c1de90089).();
288 }
289 switch (state) {
290
291 case FTP_STATE_URL_PARSING_ERRORcxx . . $ `netcon/includes/CFtp.h:64:9`!:
292 return INET_ERROR_CANT_PARSE_URLcxx . . $ `netcon/includes/inetgetfile.h:155:9`!;
293
294 case FTP_STATE_HOST_NOT_FOUNDcxx . . $ `netcon/includes/CFtp.h:66:9`!:
295 return INET_ERROR_HOST_NOT_FOUNDcxx . . $ `netcon/includes/inetgetfile.h:157:9`!;
296
297 case FTP_STATE_DIRECTORY_INVALIDcxx . . $ `netcon/includes/CFtp.h:71:9`!:
298 case FTP_STATE_FILE_NOT_FOUNDcxx . . $ `netcon/includes/CFtp.h:72:9`!:
299 return INET_ERROR_BAD_FILE_OR_DIRcxx . . $ `netcon/includes/inetgetfile.h:156:9`!;
300
301 case FTP_STATE_CANT_CONNECTcxx . . $ `netcon/includes/CFtp.h:67:9`!:
302 case FTP_STATE_LOGIN_ERRORcxx . . $ `netcon/includes/CFtp.h:69:9`!:
303 case FTP_STATE_INTERNAL_ERRORcxx . . $ `netcon/includes/CFtp.h:62:9`!:
304 case FTP_STATE_SOCKET_ERRORcxx . . $ `netcon/includes/CFtp.h:63:9`!:
305 case FTP_STATE_UNKNOWN_ERRORcxx . . $ `netcon/includes/CFtp.h:75:9`!:
306 case FTP_STATE_RECV_FAILEDcxx . . $ `netcon/includes/CFtp.h:76:9`!:
307
308 return INET_ERROR_UNKNOWN_ERRORcxx . . $ `netcon/includes/inetgetfile.h:158:9`!;
309
310 case FTP_STATE_CANT_WRITE_FILEcxx . . $ `netcon/includes/CFtp.h:77:9`!:
311 return INET_ERROR_CANT_WRITE_FILEcxx . . $ `netcon/includes/inetgetfile.h:154:9`!;
312 default:
313 return INET_ERROR_NO_ERRORcxx . . $ `netcon/includes/inetgetfile.h:152:9`!;
314 }
315 }
316
317 int InetGetFilecxx . . $ InetGetFile#::GetTotalBytescxx . . $ InetGetFile#GetTotalBytes(b126dc7c1de90089).() {
318 if (m_bUseHTTPcxx . . $ InetGetFile#m_bUseHTTP.) {
319 return httpcxx . . $ InetGetFile#http.->GetTotalBytescxx . . $ ChttpGet#GetTotalBytes(db52760e79bf9054).();
320 } else if (ftpcxx . . $ InetGetFile#ftp.) {
321 return ftpcxx . . $ InetGetFile#ftp.->GetTotalBytescxx . . $ CFtpGet#GetTotalBytes(db52760e79bf9054).();
322 } else
323 return 0;
324 }
325
326 int InetGetFilecxx . . $ InetGetFile#::GetBytesIncxx . . $ InetGetFile#GetBytesIn(b126dc7c1de90089).() {
327 if (m_bUseHTTPcxx . . $ InetGetFile#m_bUseHTTP.) {
328 return httpcxx . . $ InetGetFile#http.->GetBytesIncxx . . $ ChttpGet#GetBytesIn(db52760e79bf9054).();
329 } else if (ftpcxx . . $ InetGetFile#ftp.) {
330 return ftpcxx . . $ InetGetFile#ftp.->GetBytesIncxx . . $ CFtpGet#GetBytesIn(db52760e79bf9054).();
331 } else
332 return 0;
333 }