Debian Codegraph @

netcon/inetfile/Chttpget.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/Chttpget.cpp $
21 * $Revision: 1.4 $
22 * $Date: 2001/01/13 21:48:46 $
23 * $Author: icculus $
24 *
25 * HTTP Client class (get only)
26 *
27 * $Log: Chttpget.cpp,v $
28 * Revision 1.4 2001/01/13 21:48:46 icculus
29 * patched to (re)compile on win32.
30 *
31 * Revision 1.3 2000/06/29 06:41:23 icculus
32 * mad commits.
33 *
34 * Revision 1.2 2000/06/03 14:30:21 icculus
35 * 1.4 code merge and pthread->SDL thread conversion.
36 *
37 * Revision 1.1.1.1 2000/04/18 00:00:38 icculus
38 * initial checkin
39 *
40 *
41 * 26 10/22/99 3:40p Kevin
42 * mac merge fixes
43 *
44 * 25 10/21/99 9:28p Jeff
45 * B.A. Macintosh code merge
46 *
47 * 24 9/08/99 6:37p Jeff
48 * fixed http/ftp downloading for Linux, should all work fine now.
49 *
50 * 23 8/22/99 12:32a Jeff
51 * fixed select calls for Linux. Ported Kevin's new http stuff to Linux
52 *
53 * 22 8/21/99 9:14p Kevin
54 * Added support for redirection
55 *
56 * 21 8/21/99 6:33p Kevin
57 * Fixed Proxy Stuff
58 *
59 * 20 8/21/99 6:48a Jeff
60 * Linux port
61 *
62 * 19 8/20/99 3:01p Kevin
63 * Added support for Proxies (I hope!)
64 *
65 * 18 8/15/99 6:38p Jeff
66 * fixed compile error
67 *
68 * 17 8/15/99 6:26p Kevin
69 *
70 * 16 4/14/99 1:20a Jeff
71 * fixed case mismatched #includes
72 *
73 * 15 3/03/99 12:28a Nate
74 * sped up something or other when the connection is done
75 *
76 * 14 2/03/99 4:20p Kevin
77 * Got multiplayer working with .mn3 files, and setup autodownloading
78 *
79 * 13 1/27/99 5:49p Kevin
80 *
81 * 12 1/27/99 5:38p Kevin
82 *
83 * 11 12/30/98 12:15p Kevin
84 * Auto Mission Download system
85 *
86 * 10 10/12/98 4:59p Kevin
87 * Added delay to thread when cancelled...
88 *
89 * 9 10/12/98 4:49p Nate
90 * More fixes
91 *
92 * 8 10/12/98 1:54p Nate
93 * Fixed bug
94 *
95 * 7 10/12/98 11:30a Kevin
96 * More memory stuff
97 *
98 * 6 10/08/98 12:59p Nate
99 * fixed cancel
100 *
101 * 5 10/08/98 9:57a Kevin
102 * made transfer cancellable
103 *
104 * 4 7/31/98 12:19p Nate
105 * Fixed http abort problem.
106 *
107 * 3 7/31/98 11:57a Kevin
108 * Added new functions for getting state
109 *
110 * 2 6/01/98 10:10a Kevin
111 * Added DLL connection interface and auto update DLL
112 *
113 * 1 5/27/98 9:52a Kevin
114 *
115 * 1 5/25/98 5:31p Kevin
116 * Initial version
117 *
118 * $NoKeywords: $
119 */
120
121 #ifdef WIN32
122 #include <windows.h>
123 #include <winsock.h>
124 #include <process.h>
125 #endif
126
127 #include <string.h>
128 #include <stdio.h>
129 #include <stdlib.h>
130
131 #include "inetgetfile.h"cxx . . $ `<file>/netcon/includes/inetgetfile.h`/
132 #include "Chttpget.h"cxx . . $ `<file>/netcon/includes/Chttpget.h`/
133
134 #ifndef WIN32
135 #include "mem.h"cxx . . $ `<file>/mem/mem.h`/
136 #else
137 #define mem_malloc(a) malloc(a)
138 #define mem_free(a) free(a)
139 #endif
140
141 #if defined(POSIXcxx . . $ `<built-in>:478:9`!)
142
143 #include "SDL_thread.h"
144
145 inline void Sleepcxx . . $ Sleep(d4f767463ce0a6b3).(int millis) {
146 struct timeval tv;
147 tv.tv_sec = 0;
148 tv.tv_usec = millis * 1000;
149 select(0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, &tv);
150 }
151 #endif
152
153 #define NW_AGHBN_CANCELcxx . . $ `netcon/inetfile/Chttpget.cpp:153:9`! 1
154 #define NW_AGHBN_LOOKUPcxx . . $ `netcon/inetfile/Chttpget.cpp:154:9`! 2
155 #define NW_AGHBN_READcxx . . $ `netcon/inetfile/Chttpget.cpp:155:9`! 3
156
157 #if !defined(POSIXcxx . . $ `<built-in>:478:9`!)
158 static void HTTPObjThread(void *obj);
159 static void __cdecl http_gethostbynameworker(void *parm);
160 #else
161 static int HTTPObjThreadcxx . . $ HTTPObjThread(dedf1e9b1c614a07).(void *obj);
162 static int http_gethostbynameworkercxx . . $ http_gethostbynameworker(dedf1e9b1c614a07).(void *parm);
163 #endif
164
165 static int http_Asyncgethostbynamecxx . . $ http_Asyncgethostbyname(d1564d04be42e0f9).(uint32_tcxx . . $ uint32_t# *ip, int command, char *hostname);
166
167 #if !defined(POSIXcxx . . $ `<built-in>:478:9`!)
168 void HTTPObjThread(void *obj)
169 #else
170 int HTTPObjThreadcxx . . $ HTTPObjThread(dedf1e9b1c614a07).(void *obj)
171 #endif
172 {
173 ((ChttpGetcxx . . $ ChttpGet# *)obj)->WorkerThreadcxx . . $ ChttpGet#WorkerThread(49f6e7a06ebc5aa8).();
174 ((ChttpGetcxx . . $ ChttpGet# *)obj)->m_Abortedcxx . . $ ChttpGet#m_Aborted. = true;
175 // OutputDebugString("http transfer exiting....\n");
176
177 #if defined(POSIXcxx . . $ `<built-in>:478:9`!)
178 return 0;
179 #endif
180 }
181
182 void ChttpGetcxx . . $ ChttpGet#::AbortGetcxx . . $ ChttpGet#AbortGet(49f6e7a06ebc5aa8).() {
183 #ifdef WIN32
184 OutputDebugString("Aborting....\n");
185 #endif
186 m_Abortingcxx . . $ ChttpGet#m_Aborting. = true;
187 while (!m_Abortedcxx . . $ ChttpGet#m_Aborted.)
188 Sleepcxx . . $ Sleep(d4f767463ce0a6b3).(50); // Wait for the thread to end
189 #ifdef WIN32
190 OutputDebugString("Aborted....\n");
191 #endif
192 }
193
194 ChttpGetcxx . . $ ChttpGet#::ChttpGetcxx . . $ ChttpGet#ChttpGet(1905cbfd26227f9c).(char *URL, char *localfile, char *proxyip, uint16_tcxx . . $ uint16_t# proxyport) {
195 m_ProxyEnabledcxx . . $ ChttpGet#m_ProxyEnabled. = true;
196 m_ProxyIPcxx . . $ ChttpGet#m_ProxyIP. = proxyip;
197 m_ProxyPortcxx . . $ ChttpGet#m_ProxyPort. = proxyport;
198 GetFilecxx . . $ ChttpGet#GetFile(d0489a02ea06dfc6).(URL, localfile);
199 }
200
201 ChttpGetcxx . . $ ChttpGet#::ChttpGetcxx . . $ ChttpGet#ChttpGet(d0489a02ea06dfc6).(char *URL, char *localfile) {
202 m_ProxyEnabledcxx . . $ ChttpGet#m_ProxyEnabled. = false;
203 GetFilecxx . . $ ChttpGet#GetFile(d0489a02ea06dfc6).(URL, localfile);
204 }
205
206 void ChttpGetcxx . . $ ChttpGet#::PrepSocketcxx . . $ ChttpGet#PrepSocket(fda57c8427c60377).(char *URL) {
207
208 m_DataSockcxx . . $ ChttpGet#m_DataSock. = socket(AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!, SOCK_STREAMcxx . . $ `<external>/5956532346368192945/socket_type.h:28:9`!, 0);
209 if (INVALID_SOCKETcxx . . $ `lib/networking.h:221:9`! == m_DataSockcxx . . $ ChttpGet#m_DataSock.) {
210 m_Statecxx . . $ ChttpGet#m_State. = HTTP_STATE_SOCKET_ERRORcxx . . $ `netcon/includes/Chttpget.h:71:9`!;
211 return;
212 }
213
214 #ifdef WIN32
215 unsigned long arg = 1;
216 ioctlsocket(m_DataSock, FIONBIO, &arg);
217 #else // WIN32
218 fcntl(m_DataSockcxx . . $ ChttpGet#m_DataSock., F_SETFLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:169:9`!, fcntl(m_DataSockcxx . . $ ChttpGet#m_DataSock., F_GETFLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:168:9`!, 0) | O_NONBLOCKcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:62:10`!);
219 #endif
220
221 char *pURL = URL;
222 if (strnicmpcxx . . $ `linux/linux_fix.h:44:9`!(URL, "http:", 5) == 0) {
223 pURL += 5;
224 while (*pURL == '/') {
225 pURL++;
226 }
227 }
228 // There shouldn't be any : in this string
229 if (strchr(pURL, ':')) {
230 m_Statecxx . . $ ChttpGet#m_State. = HTTP_STATE_URL_PARSING_ERRORcxx . . $ `netcon/includes/Chttpget.h:72:9`!;
231 return;
232 }
233 // read the filename by searching backwards for a /
234 // then keep reading until you find the first /
235 // when you found it, you have the host and dir
236 char *filestart = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
237 char *dirstart = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
238 for (int i = strlen(pURL); i >= 0; i--) {
239 if (pURL[i] == '/') {
240 if (!filestart) {
241 filestart = pURL + i + 1;
242 dirstart = pURL + i + 1;
243 strcpy(m_szFilenamecxx . . $ ChttpGet#m_szFilename., filestart);
244 } else {
245 dirstart = pURL + i + 1;
246 }
247 }
248 }
249 if ((dirstart == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) || (filestart == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)) {
250 m_Statecxx . . $ ChttpGet#m_State. = HTTP_STATE_URL_PARSING_ERRORcxx . . $ `netcon/includes/Chttpget.h:72:9`!;
251 return;
252 } else {
253 strcpy(m_szDircxx . . $ ChttpGet#m_szDir., dirstart); //,(filestart-dirstart));
254 // m_szDir[(filestart-dirstart)] = NULL;
255 strncpy(m_szHostcxx . . $ ChttpGet#m_szHost., pURL, (dirstart - pURL));
256 m_szHostcxx . . $ ChttpGet#m_szHost.[(dirstart - pURL) - 1] = '\0';
257 }
258 }
259
260 void ChttpGetcxx . . $ ChttpGet#::GetFilecxx . . $ ChttpGet#GetFile(d0489a02ea06dfc6).(char *URL, char *localfile) {
261 m_DataSockcxx . . $ ChttpGet#m_DataSock. = INVALID_SOCKETcxx . . $ `lib/networking.h:221:9`!;
262 m_iBytesIncxx . . $ ChttpGet#m_iBytesIn. = 0;
263 m_iBytesTotalcxx . . $ ChttpGet#m_iBytesTotal. = 0;
264 m_Statecxx . . $ ChttpGet#m_State. = HTTP_STATE_STARTUPcxx . . $ `netcon/includes/Chttpget.h:83:9`!;
265 ;
266 m_Abortingcxx . . $ ChttpGet#m_Aborting. = false;
267 m_Abortedcxx . . $ ChttpGet#m_Aborted. = false;
268
269 strncpy(m_URLcxx . . $ ChttpGet#m_URL., URL, MAX_URL_LENcxx . . $ `netcon/includes/Chttpget.h:85:9`! - 1);
270 m_URLcxx . . $ ChttpGet#m_URL.[MAX_URL_LENcxx . . $ `netcon/includes/Chttpget.h:85:9`! - 1] = 0;
271
272 LOCALFILEcxx . . $ ChttpGet#LOCALFILE. = fopen(localfile, "wb");
273 if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! == LOCALFILEcxx . . $ ChttpGet#LOCALFILE.) {
274 m_Statecxx . . $ ChttpGet#m_State. = HTTP_STATE_CANT_WRITE_FILEcxx . . $ `netcon/includes/Chttpget.h:82:9`!;
275 return;
276 }
277
278 PrepSocketcxx . . $ ChttpGet#PrepSocket(fda57c8427c60377).(URL);
279
280 #ifdef WIN32
281 if (NULL == _beginthread(HTTPObjThread, 0, this)) {
282 m_State = HTTP_STATE_INTERNAL_ERROR;
283 return;
284 }
285 #elif defined(POSIXcxx . . $ `<built-in>:478:9`!)
286 // pthread_t thread;
287 SDL_Thread *thread;
288
289 if (!inet_LoadThreadLibcxx . . $ inet_LoadThreadLib(c9857a73d68e59ba).()) {
290 m_Statecxx . . $ ChttpGet#m_State. = HTTP_STATE_INTERNAL_ERRORcxx . . $ `netcon/includes/Chttpget.h:70:9`!;
291 return;
292 }
293
294 // if(df_pthread_create(&thread,NULL,HTTPObjThread,this)!=0)
295 thread = SDL_CreateThread(HTTPObjThreadcxx . . $ HTTPObjThread(dedf1e9b1c614a07)., "httpget", this);
296 if (thread == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
297 m_Statecxx . . $ ChttpGet#m_State. = HTTP_STATE_INTERNAL_ERRORcxx . . $ `netcon/includes/Chttpget.h:70:9`!;
298 return;
299 }
300 #endif
301 }
302
303 ChttpGetcxx . . $ ChttpGet#::~cxx . . $ ChttpGet#`~ChttpGet`(ced63f7c635d850d).ChttpGetcxx . . $ ChttpGet#() {
304 if (m_DataSockcxx . . $ ChttpGet#m_DataSock. != INVALID_SOCKETcxx . . $ `lib/networking.h:221:9`!) {
305 shutdown(m_DataSockcxx . . $ ChttpGet#m_DataSock., 2);
306 #if !defined(POSIXcxx . . $ `<built-in>:478:9`!)
307 closesocket(m_DataSock);
308 #else
309 close(m_DataSockcxx . . $ ChttpGet#m_DataSock.);
310 #endif
311 }
312 }
313
314 int ChttpGetcxx . . $ ChttpGet#::GetStatuscxx . . $ ChttpGet#GetStatus(b126dc7c1de90089).() { return m_Statecxx . . $ ChttpGet#m_State.; }
315
316 uint32_tcxx . . $ uint32_t# ChttpGetcxx . . $ ChttpGet#::GetBytesIncxx . . $ ChttpGet#GetBytesIn(db52760e79bf9054).() { return m_iBytesIncxx . . $ ChttpGet#m_iBytesIn.; }
317
318 uint32_tcxx . . $ uint32_t# ChttpGetcxx . . $ ChttpGet#::GetTotalBytescxx . . $ ChttpGet#GetTotalBytes(db52760e79bf9054).() { return m_iBytesTotalcxx . . $ ChttpGet#m_iBytesTotal.; }
319
320 void ChttpGetcxx . . $ ChttpGet#::WorkerThreadcxx . . $ ChttpGet#WorkerThread(49f6e7a06ebc5aa8).() {
321 char szCommand[1000];
322 char *p;
323 int irsp = 0;
324 ConnectSocketcxx . . $ ChttpGet#ConnectSocket(b126dc7c1de90089).();
325 if (m_Abortingcxx . . $ ChttpGet#m_Aborting.) {
326 fclose(LOCALFILEcxx . . $ ChttpGet#LOCALFILE.);
327 return;
328 }
329 if (m_Statecxx . . $ ChttpGet#m_State. != HTTP_STATE_CONNECTEDcxx . . $ `netcon/includes/Chttpget.h:76:9`!) {
330 fclose(LOCALFILEcxx . . $ ChttpGet#LOCALFILE.);
331 return;
332 }
333 snprintf(szCommand, sizeof(szCommand), "GET %s%s HTTP/1.1\nAccept: */*\nAccept-Encoding: deflate\nHost: %s\n\n\n",
334 m_ProxyEnabledcxx . . $ ChttpGet#m_ProxyEnabled. ? "" : "/", m_ProxyEnabledcxx . . $ ChttpGet#m_ProxyEnabled. ? m_URLcxx . . $ ChttpGet#m_URL. : m_szDircxx . . $ ChttpGet#m_szDir., m_szHostcxx . . $ ChttpGet#m_szHost.);
335 send(m_DataSockcxx . . $ ChttpGet#m_DataSock., szCommand, strlen(szCommand), 0);
336 p = GetHTTPLinecxx . . $ ChttpGet#GetHTTPLine(41208ce6ca65dd58).();
337 if (p && strnicmpcxx . . $ `linux/linux_fix.h:44:9`!("HTTP/", p, 5) == 0) {
338 char *pcode;
339 pcode = strchr(p, ' ') + 1;
340 if (!pcode) {
341 m_Statecxx . . $ ChttpGet#m_State. = HTTP_STATE_UNKNOWN_ERRORcxx . . $ `netcon/includes/Chttpget.h:80:9`!;
342 fclose(LOCALFILEcxx . . $ ChttpGet#LOCALFILE.);
343 return;
344 }
345 pcode[3] = '\0';
346 irsp = atoicxx . . $ atoi(f5ecf3191ed0cd93).(pcode);
347
348 if (irsp == 0) {
349 m_Statecxx . . $ ChttpGet#m_State. = HTTP_STATE_UNKNOWN_ERRORcxx . . $ `netcon/includes/Chttpget.h:80:9`!;
350 fclose(LOCALFILEcxx . . $ ChttpGet#LOCALFILE.);
351 return;
352 }
353 if (irsp == 301) {
354
355 // This is a redirection! woohoo, what fun we are going to have.
356 // Next thing we need to do is find where it's redirected to.
357 // We do that by looking for a "Location: xxxx" line.
358
359 int idataready = 0;
360 do {
361 p = GetHTTPLinecxx . . $ ChttpGet#GetHTTPLine(41208ce6ca65dd58).();
362 if (p == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
363 m_Statecxx . . $ ChttpGet#m_State. = HTTP_STATE_UNKNOWN_ERRORcxx . . $ `netcon/includes/Chttpget.h:80:9`!;
364 fclose(LOCALFILEcxx . . $ ChttpGet#LOCALFILE.);
365 return;
366 }
367 if (*p == '\0') {
368 idataready = 1;
369 break;
370 }
371 if (strnicmpcxx . . $ `linux/linux_fix.h:44:9`!(p, "Location:", strlen("Location:")) == 0) {
372 char *s = strchr(p, ' ') + 1;
373
374 // Then, once we've found that, we close the sockets & reissue the whole freakin request.
375 shutdown(m_DataSockcxx . . $ ChttpGet#m_DataSock., 2);
376
377 #ifdef WIN32
378 closesocket(m_DataSock);
379 #else
380 close(m_DataSockcxx . . $ ChttpGet#m_DataSock.);
381 #endif
382
383 m_DataSockcxx . . $ ChttpGet#m_DataSock. = INVALID_SOCKETcxx . . $ `lib/networking.h:221:9`!;
384
385 // New location to look at is in 's'
386 PrepSocketcxx . . $ ChttpGet#PrepSocket(fda57c8427c60377).(s);
387 WorkerThreadcxx . . $ ChttpGet#WorkerThread(49f6e7a06ebc5aa8).();
388 return;
389 }
390 } while (!idataready);
391 }
392 if (irsp == 200) {
393 int idataready = 0;
394 do {
395 p = GetHTTPLinecxx . . $ ChttpGet#GetHTTPLine(41208ce6ca65dd58).();
396 if (p == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
397 m_Statecxx . . $ ChttpGet#m_State. = HTTP_STATE_UNKNOWN_ERRORcxx . . $ `netcon/includes/Chttpget.h:80:9`!;
398 fclose(LOCALFILEcxx . . $ ChttpGet#LOCALFILE.);
399 return;
400 }
401 if (*p == '\0') {
402 idataready = 1;
403 break;
404 }
405 if (strnicmpcxx . . $ `linux/linux_fix.h:44:9`!(p, "Content-Length:", strlen("Content-Length:")) == 0) {
406 char *s = strchr(p, ' ') + 1;
407 p = s;
408 if (s) {
409 while (*s) {
410 if (!isdigit(*s)) {
411 *s = '\0';
412 }
413 s++;
414 };
415 m_iBytesTotalcxx . . $ ChttpGet#m_iBytesTotal. = atoicxx . . $ atoi(f5ecf3191ed0cd93).(p);
416 }
417 }
418 } while (!idataready);
419 ReadDataChannelcxx . . $ ChttpGet#ReadDataChannel(db52760e79bf9054).();
420 return;
421 }
422 m_Statecxx . . $ ChttpGet#m_State. = HTTP_STATE_FILE_NOT_FOUNDcxx . . $ `netcon/includes/Chttpget.h:77:9`!;
423 fclose(LOCALFILEcxx . . $ ChttpGet#LOCALFILE.);
424 return;
425 } else {
426 m_Statecxx . . $ ChttpGet#m_State. = HTTP_STATE_UNKNOWN_ERRORcxx . . $ `netcon/includes/Chttpget.h:80:9`!;
427 fclose(LOCALFILEcxx . . $ ChttpGet#LOCALFILE.);
428 return;
429 }
430 }
431
432 int ChttpGetcxx . . $ ChttpGet#::ConnectSocketcxx . . $ ChttpGet#ConnectSocket(b126dc7c1de90089).() {
433 // HOSTENT *he;
434 uint32_tcxx . . $ uint32_t# ip;
435 SERVENTcxx . . $ `netcon/includes/inetgetfile.h:118:9`! *se;
436 SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! hostaddr;
437
438 int rcode = 0;
439
440 if (m_Abortingcxx . . $ ChttpGet#m_Aborting.)
441 return 0;
442
443 ip = inet_addr((const char *)m_szHostcxx . . $ ChttpGet#m_szHost.);
444
445 if (ip == INADDR_NONEcxx . . $ `<external>/9581057695539925927/in.h:202:9`!) {
446 http_Asyncgethostbynamecxx . . $ http_Asyncgethostbyname(d1564d04be42e0f9).(&ip, NW_AGHBN_LOOKUPcxx . . $ `netcon/inetfile/Chttpget.cpp:154:9`!, m_szHostcxx . . $ ChttpGet#m_szHost.);
447 rcode = 0;
448 do {
449 if (m_Abortingcxx . . $ ChttpGet#m_Aborting.) {
450 http_Asyncgethostbynamecxx . . $ http_Asyncgethostbyname(d1564d04be42e0f9).(&ip, NW_AGHBN_CANCELcxx . . $ `netcon/inetfile/Chttpget.cpp:153:9`!, m_szHostcxx . . $ ChttpGet#m_szHost.);
451 return 0;
452 }
453 rcode = http_Asyncgethostbynamecxx . . $ http_Asyncgethostbyname(d1564d04be42e0f9).(&ip, NW_AGHBN_READcxx . . $ `netcon/inetfile/Chttpget.cpp:155:9`!, m_szHostcxx . . $ ChttpGet#m_szHost.);
454 } while (rcode == 0);
455 }
456
457 if (rcode == -1) {
458 m_Statecxx . . $ ChttpGet#m_State. = HTTP_STATE_HOST_NOT_FOUNDcxx . . $ `netcon/includes/Chttpget.h:74:9`!;
459 return 0;
460 }
461 // m_ControlSock
462 if (m_Abortingcxx . . $ ChttpGet#m_Aborting.)
463 return 0;
464 se = getservbyname("http", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
465 if (m_Abortingcxx . . $ ChttpGet#m_Aborting.)
466 return 0;
467 if (se == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
468 hostaddr.sin_port = htons(80);
469 } else {
470 hostaddr.sin_port = se->s_port;
471 }
472 hostaddr.sin_family = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
473 // ip = htonl(ip);
474 memcpy(&hostaddr.sin_addr, &ip, 4);
475
476 if (m_ProxyEnabledcxx . . $ ChttpGet#m_ProxyEnabled.) {
477 // This is on a proxy, so we need to make sure to connect to the proxy machine
478 ip = inet_addr((const char *)m_ProxyIPcxx . . $ ChttpGet#m_ProxyIP.);
479
480 if (ip == INADDR_NONEcxx . . $ `<external>/9581057695539925927/in.h:202:9`!) {
481 http_Asyncgethostbynamecxx . . $ http_Asyncgethostbyname(d1564d04be42e0f9).(&ip, NW_AGHBN_LOOKUPcxx . . $ `netcon/inetfile/Chttpget.cpp:154:9`!, m_ProxyIPcxx . . $ ChttpGet#m_ProxyIP.);
482 rcode = 0;
483 do {
484 if (m_Abortingcxx . . $ ChttpGet#m_Aborting.) {
485 http_Asyncgethostbynamecxx . . $ http_Asyncgethostbyname(d1564d04be42e0f9).(&ip, NW_AGHBN_CANCELcxx . . $ `netcon/inetfile/Chttpget.cpp:153:9`!, m_ProxyIPcxx . . $ ChttpGet#m_ProxyIP.);
486 return 0;
487 }
488 rcode = http_Asyncgethostbynamecxx . . $ http_Asyncgethostbyname(d1564d04be42e0f9).(&ip, NW_AGHBN_READcxx . . $ `netcon/inetfile/Chttpget.cpp:155:9`!, m_ProxyIPcxx . . $ ChttpGet#m_ProxyIP.);
489 } while (rcode == 0);
490
491 if (rcode == -1) {
492 m_Statecxx . . $ ChttpGet#m_State. = HTTP_STATE_HOST_NOT_FOUNDcxx . . $ `netcon/includes/Chttpget.h:74:9`!;
493 return 0;
494 }
495 }
496 // Use either the proxy port or 80 if none specified
497 hostaddr.sin_port = htons(m_ProxyPortcxx . . $ ChttpGet#m_ProxyPort. ? m_ProxyPortcxx . . $ ChttpGet#m_ProxyPort. : 80);
498 // Copy the proxy address...
499 memcpy(&hostaddr.sin_addr, &ip, 4);
500 }
501 // Now we will connect to the host
502 fd_set wfds;
503
504 timeval timeout;
505 timeout.tv_sec = 0;
506 timeout.tv_usec = 0;
507 int serr = connect(m_DataSockcxx . . $ ChttpGet#m_DataSock., (SOCKADDRcxx . . $ `lib/networking.h:220:9`! *)&hostaddr, sizeof(SOCKADDRcxx . . $ `lib/networking.h:220:9`!));
508 int cerr = WSAGetLastErrorcxx . . $ `netcon/includes/inetgetfile.h:129:9`!();
509 if (serr) {
510 #if defined(POSIXcxx . . $ `<built-in>:478:9`!)
511 while ((cerr == WSAEALREADYcxx . . $ `netcon/includes/inetgetfile.h:124:9`!) || (cerr == WSAEINVALcxx . . $ `lib/networking.h:237:9`!) || (cerr == WSAEWOULDBLOCKcxx . . $ `lib/networking.h:236:9`!) || (cerr == EINPROGRESScxx . . $ `<external>/17922322188510340118/errno.h:99:9`!))
512 #else
513 while ((cerr == WSAEALREADY) || (cerr == WSAEINVAL) || (cerr == WSAEWOULDBLOCK))
514 #endif
515 {
516 FD_ZEROcxx . . $ `<external>/946878812840035423/select.h:88:9`!(&wfds);
517 FD_SETcxx . . $ `<external>/946878812840035423/select.h:85:9`!(m_DataSock, &wfds);
518 if (select(m_DataSockcxx . . $ ChttpGet#m_DataSock. + 1, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, &wfds, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, &timeout)) {
519 serr = 0;
520 break;
521 }
522 if (m_Abortingcxx . . $ ChttpGet#m_Aborting.)
523 return 0;
524 serr = connect(m_DataSockcxx . . $ ChttpGet#m_DataSock., (SOCKADDRcxx . . $ `lib/networking.h:220:9`! *)&hostaddr, sizeof(SOCKADDRcxx . . $ `lib/networking.h:220:9`!));
525 if (serr == 0)
526 break;
527 cerr = WSAGetLastErrorcxx . . $ `netcon/includes/inetgetfile.h:129:9`!();
528 if (cerr == WSAEISCONNcxx . . $ `netcon/includes/inetgetfile.h:125:9`!) {
529 serr = 0;
530 break;
531 }
532 };
533 }
534 if (serr) {
535 m_Statecxx . . $ ChttpGet#m_State. = HTTP_STATE_CANT_CONNECTcxx . . $ `netcon/includes/Chttpget.h:75:9`!;
536 return 0;
537 }
538 m_Statecxx . . $ ChttpGet#m_State. = HTTP_STATE_CONNECTEDcxx . . $ `netcon/includes/Chttpget.h:76:9`!;
539 return 1;
540 }
541
542 char *ChttpGetcxx . . $ ChttpGet#::GetHTTPLinecxx . . $ ChttpGet#GetHTTPLine(41208ce6ca65dd58).() {
543 uint32_tcxx . . $ uint32_t# iBytesRead;
544 char chunk[2];
545 uint32_tcxx . . $ uint32_t# igotcrlf = 0;
546 memset(recv_buffercxx . . $ ChttpGet#recv_buffer., 0, 1000);
547 do {
548 chunk[0] = '\0';
549 bool gotdata = false;
550 do {
551 iBytesRead = recv(m_DataSockcxx . . $ ChttpGet#m_DataSock., chunk, 1, 0);
552
553 if (SOCKET_ERRORcxx . . $ `lib/networking.h:233:9`! == iBytesRead) {
554 int error = WSAGetLastErrorcxx . . $ `netcon/includes/inetgetfile.h:129:9`!();
555 #if defined(POSIXcxx . . $ `<built-in>:478:9`!)
556 if (WSAEWOULDBLOCKcxx . . $ `lib/networking.h:236:9`! == error || 0 == error)
557 #else
558 if (WSAEWOULDBLOCK == error)
559 #endif
560 {
561 gotdata = false;
562 continue;
563 } else {
564 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
565 }
566 } else {
567 gotdata = true;
568 }
569 } while (!gotdata);
570
571 if (chunk[0] == 0x0d) {
572 // This should always read a 0x0a
573 do {
574 iBytesRead = recv(m_DataSockcxx . . $ ChttpGet#m_DataSock., chunk, 1, 0);
575
576 if (SOCKET_ERRORcxx . . $ `lib/networking.h:233:9`! == iBytesRead) {
577 int error = WSAGetLastErrorcxx . . $ `netcon/includes/inetgetfile.h:129:9`!();
578 #if defined(POSIXcxx . . $ `<built-in>:478:9`!)
579 if (WSAEWOULDBLOCKcxx . . $ `lib/networking.h:236:9`! == error || 0 == error)
580 #else
581 if (WSAEWOULDBLOCK == error)
582 #endif
583 {
584 gotdata = false;
585 continue;
586 } else {
587 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
588 }
589 } else {
590 gotdata = true;
591 }
592 } while (!gotdata);
593 igotcrlf = 1;
594 } else {
595 chunk[1] = '\0';
596 strcat(recv_buffercxx . . $ ChttpGet#recv_buffer., chunk);
597 }
598
599 } while (igotcrlf == 0);
600 return recv_buffercxx . . $ ChttpGet#recv_buffer.;
601 }
602
603 uint32_tcxx . . $ uint32_t# ChttpGetcxx . . $ ChttpGet#::ReadDataChannelcxx . . $ ChttpGet#ReadDataChannel(db52760e79bf9054).() {
604 char sDataBuffer[4096]; // Data-storage buffer for the data channel
605 int nBytesRecv = 0; // Bytes received from the data channel
606
607 fd_set wfds;
608
609 timeval timeout;
610 timeout.tv_sec = 0;
611 timeout.tv_usec = 500;
612
613 m_Statecxx . . $ ChttpGet#m_State. = HTTP_STATE_RECEIVINGcxx . . $ `netcon/includes/Chttpget.h:78:9`!;
614 do {
615 FD_ZEROcxx . . $ `<external>/946878812840035423/select.h:88:9`!(&wfds);
616 FD_SETcxx . . $ `<external>/946878812840035423/select.h:85:9`!(m_DataSock, &wfds);
617
618 if ((m_iBytesTotalcxx . . $ ChttpGet#m_iBytesTotal.) && (m_iBytesIncxx . . $ ChttpGet#m_iBytesIn. == m_iBytesTotalcxx . . $ ChttpGet#m_iBytesTotal.)) {
619 break;
620 }
621
622 select(m_DataSockcxx . . $ ChttpGet#m_DataSock. + 1, &wfds, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, &timeout);
623
624 if (m_Abortingcxx . . $ ChttpGet#m_Aborting.) {
625 fclose(LOCALFILEcxx . . $ ChttpGet#LOCALFILE.);
626 return 0;
627 }
628
629 nBytesRecv = recv(m_DataSockcxx . . $ ChttpGet#m_DataSock., (char *)&sDataBuffer, sizeof(sDataBuffer), 0);
630
631 if (m_Abortingcxx . . $ ChttpGet#m_Aborting.) {
632 fclose(LOCALFILEcxx . . $ ChttpGet#LOCALFILE.);
633 return 0;
634 }
635
636 if (SOCKET_ERRORcxx . . $ `lib/networking.h:233:9`! == nBytesRecv) {
637 int error = WSAGetLastErrorcxx . . $ `netcon/includes/inetgetfile.h:129:9`!();
638 #if defined(POSIXcxx . . $ `<built-in>:478:9`!)
639 if (WSAEWOULDBLOCKcxx . . $ `lib/networking.h:236:9`! == error || 0 == error)
640 #else
641 if (WSAEWOULDBLOCK == error)
642 #endif
643 {
644 nBytesRecv = 1;
645 continue;
646 }
647 }
648 m_iBytesIncxx . . $ ChttpGet#m_iBytesIn. += nBytesRecv;
649 if (nBytesRecv > 0) {
650 fwrite(sDataBuffer, nBytesRecv, 1, LOCALFILEcxx . . $ ChttpGet#LOCALFILE.);
651 // Write sDataBuffer, nBytesRecv
652 }
653
654 } while (nBytesRecv > 0);
655
656 fclose(LOCALFILEcxx . . $ ChttpGet#LOCALFILE.);
657
658 // Close the file and check for error returns.
659 if (nBytesRecv == SOCKET_ERRORcxx . . $ `lib/networking.h:233:9`!) {
660 // Ok, we got a socket error -- xfer aborted?
661 m_Statecxx . . $ ChttpGet#m_State. = HTTP_STATE_RECV_FAILEDcxx . . $ `netcon/includes/Chttpget.h:81:9`!;
662 return 0;
663 } else {
664 // OutputDebugString("HTTP File complete!\n");
665 // done!
666 m_Statecxx . . $ ChttpGet#m_State. = HTTP_STATE_FILE_RECEIVEDcxx . . $ `netcon/includes/Chttpget.h:79:9`!;
667 return 1;
668 }
669 }
670
671 static async_dns_lookupcxx . . $ async_dns_lookup# httpaslucxx . . $ httpaslu.;
672 static async_dns_lookupcxx . . $ async_dns_lookup# *http_lastaslucxx . . $ http_lastaslu. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
673
674 int http_Asyncgethostbynamecxx . . $ http_Asyncgethostbyname(d1564d04be42e0f9).(uint32_tcxx . . $ uint32_t# *ip, int command, char *hostname) {
675
676 if (command == NW_AGHBN_LOOKUPcxx . . $ `netcon/inetfile/Chttpget.cpp:154:9`!) {
677 if (http_lastaslucxx . . $ http_lastaslu.)
678 http_lastaslucxx . . $ http_lastaslu.->abortcxx . . $ async_dns_lookup#abort. = true;
679
680 async_dns_lookupcxx . . $ async_dns_lookup# *newaslu;
681 newaslu = (async_dns_lookupcxx . . $ async_dns_lookup# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(sizeof(async_dns_lookup));
682 memset(&newaslu->ipcxx . . $ async_dns_lookup#ip., 0, sizeof(uint32_tcxx . . $ uint32_t#));
683 newaslu->hostcxx . . $ async_dns_lookup#host. = hostname;
684 newaslu->donecxx . . $ async_dns_lookup#done. = false;
685 newaslu->errorcxx . . $ async_dns_lookup#error. = false;
686 newaslu->abortcxx . . $ async_dns_lookup#abort. = false;
687 http_lastaslucxx . . $ http_lastaslu. = newaslu;
688 httpaslucxx . . $ httpaslu..donecxx . . $ async_dns_lookup#done. = false;
689
690 #ifdef WIN32
691 _beginthread(http_gethostbynameworker, 0, newaslu);
692 #elif defined(POSIXcxx . . $ `<built-in>:478:9`!)
693 // pthread_t thread;
694 if (!inet_LoadThreadLibcxx . . $ inet_LoadThreadLib(c9857a73d68e59ba).()) {
695 return 0;
696 }
697
698 // df_pthread_create(&thread,NULL,http_gethostbynameworker,newaslu);
699 newaslu->threadIdcxx . . $ async_dns_lookup#threadId. = SDL_CreateThread(http_gethostbynameworkercxx . . $ http_gethostbynameworker(dedf1e9b1c614a07)., "httpdns", newaslu);
700 #endif
701 return 1;
702 } else if (command == NW_AGHBN_CANCELcxx . . $ `netcon/inetfile/Chttpget.cpp:153:9`!) {
703 if (http_lastaslucxx . . $ http_lastaslu.)
704 http_lastaslucxx . . $ http_lastaslu.->abortcxx . . $ async_dns_lookup#abort. = true;
705
706 #if defined(POSIXcxx . . $ `<built-in>:478:9`!)
707 SDL_WaitThread(http_lastaslucxx . . $ http_lastaslu.->threadIdcxx . . $ async_dns_lookup#threadId., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
708 #endif
709
710 http_lastaslucxx . . $ http_lastaslu. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
711 } else if (command == NW_AGHBN_READcxx . . $ `netcon/inetfile/Chttpget.cpp:155:9`!) {
712 if (!http_lastaslucxx . . $ http_lastaslu.)
713 return -1;
714 if (httpaslucxx . . $ httpaslu..donecxx . . $ async_dns_lookup#done.) {
715 // free(http_lastaslu);
716 #if defined(POSIXcxx . . $ `<built-in>:478:9`!)
717 SDL_WaitThread(http_lastaslucxx . . $ http_lastaslu.->threadIdcxx . . $ async_dns_lookup#threadId., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
718 #endif
719
720 http_lastaslucxx . . $ http_lastaslu. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
721 memcpy(ip, &httpaslucxx . . $ httpaslu..ipcxx . . $ async_dns_lookup#ip., sizeof(uint32_tcxx . . $ uint32_t#));
722 return 1;
723 } else if (httpaslucxx . . $ httpaslu..errorcxx . . $ async_dns_lookup#error.) {
724 #if defined(POSIXcxx . . $ `<built-in>:478:9`!)
725 SDL_WaitThread(http_lastaslucxx . . $ http_lastaslu.->threadIdcxx . . $ async_dns_lookup#threadId., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
726 #endif
727
728 mem_freecxx . . $ `mem/mem.h:80:9`!(http_lastaslu);
729 http_lastaslucxx . . $ http_lastaslu. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
730 return -1;
731 } else
732 return 0;
733 }
734 return -2;
735 }
736
737 // This is the worker thread which does the lookup.
738 #if !defined(POSIXcxx . . $ `<built-in>:478:9`!)
739 void __cdecl http_gethostbynameworker(void *parm)
740 #else
741 int http_gethostbynameworkercxx . . $ http_gethostbynameworker(dedf1e9b1c614a07).(void *parm)
742 #endif
743 {
744 #if defined(POSIXcxx . . $ `<built-in>:478:9`!)
745 // df_pthread_detach(df_pthread_self());
746 #endif
747 async_dns_lookupcxx . . $ async_dns_lookup# *lookup = (async_dns_lookupcxx . . $ async_dns_lookup# *)parm;
748 HOSTENTcxx . . $ `lib/networking.h:232:9`! *he = gethostbyname(lookup->hostcxx . . $ async_dns_lookup#host.);
749 if (he == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
750 lookup->errorcxx . . $ async_dns_lookup#error. = true;
751 #if defined(POSIXcxx . . $ `<built-in>:478:9`!)
752 return 0;
753 #else
754 return;
755 #endif
756 } else if (!lookup->abortcxx . . $ async_dns_lookup#abort.) {
757 memcpy(&lookup->ipcxx . . $ async_dns_lookup#ip., he->h_addr_list[0], sizeof(uint32_tcxx . . $ uint32_t#));
758 lookup->donecxx . . $ async_dns_lookup#done. = true;
759 memcpy(&httpaslucxx . . $ httpaslu., lookup, sizeof(async_dns_lookupcxx . . $ async_dns_lookup#));
760 }
761 mem_freecxx . . $ `mem/mem.h:80:9`!(lookup);
762
763 #if defined(POSIXcxx . . $ `<built-in>:478:9`!)
764 return 0;
765 #endif
766 }