Debian Codegraph @

netcon/includes/inetgetfile.h

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/Lib/inetgetfile.h $
21 * $Revision: 1.6 $
22 * $Date: 2004/03/21 17:11:39 $
23 * $Author: kevinb $
24 *
25 * InternetGetFile Class header
26 *
27 * $Log: inetgetfile.h,v $
28 * Revision 1.6 2004/03/21 17:11:39 kevinb
29 * Fixes so linux will compile again. Tested with gcc-2.96
30 *
31 * Revision 1.5 2004/02/25 00:04:06 ryan
32 * Removed loki_utils dependency and ported to MacOS X (runs, but incomplete).
33 *
34 * Revision 1.4 2004/02/09 04:14:51 kevinb
35 * Added newlines to all headers to reduce number of warnings printed
36 *
37 * Made some small changes to get everything compiling.
38 *
39 * All Ready to merge the 1.5 tree.
40 *
41 * Revision 1.3 2000/09/22 19:05:09 icculus
42 * updated.
43 *
44 * Revision 1.2 2000/06/03 14:33:51 icculus
45 * Merge with Outrage 1.4 tree...
46 *
47 * Revision 1.1.1.1 2000/04/18 00:00:38 icculus
48 * initial checkin
49 *
50 *
51 * 10 10/21/99 9:27p Jeff
52 * B.A. Macintosh code merge
53 *
54 * 9 8/23/99 5:12p Kevin
55 * Proxy support for http
56 *
57 * 8 8/21/99 6:48a Jeff
58 * Linux port
59 *
60 * 7 4/17/99 5:49a Jeff
61 * changes made so it compiles under Linux
62 *
63 * 6 4/14/99 3:59a Jeff
64 * fixed case mismatches in #includes
65 *
66 * 5 7/31/98 11:57a Kevin
67 * Added new functions for getting state
68 *
69 * 4 7/31/98 11:40a Kevin
70 *
71 * 3 7/31/98 11:17a Nate
72 * Fixed memory leak and added memory alloc checking.
73 *
74 * 2 6/01/98 10:10a Kevin
75 * Added DLL connection interface and auto update DLL
76 *
77 * 1 5/27/98 9:54a Kevin
78 *
79 * 1 5/25/98 5:31p Kevin
80 * Initial version
81 *
82 * $NoKeywords: $
83 */
84 #ifndef _INET_GETFILE_HEADER_
85 #define _INET_GETFILE_HEADER_
86
87 // At the end of this file is an example of usage
88
89 #if defined(POSIX)
90 #include <ctype.h>
91 #include <errno.h>
92 #include <netinet/in.h>
93 #include <arpa/inet.h>
94 #include <sys/types.h>
95 #include <sys/socket.h>
96 #include <netdb.h>
97 #include <sys/time.h>
98 #include <unistd.h>
99
100 #include "linux_fix.h"
101
102 // Linux includes/defines
103 #if defined(__LINUX__)
104 #include <linux/types.h>
105 // #include <linux/if.h>
106 #endif
107
108 #define BOOL bool
109
110 #ifndef SOCKET
111 #define SOCKET int
112 #endif
113
114 #define SOCKADDR_IN sockaddr_in
115 #define SOCKADDR sockaddr
116 #define INVALID_SOCKET -1
117 #define HOSTENT struct hostent
118 #define SERVENT struct servent
119 #define TIMEVAL struct timeval
120 // Winsock = sockets error translation
121 #define WSAEWOULDBLOCK EWOULDBLOCK
122 #define WSAEINVAL EINVAL
123 #define WSAENOPROTOOPT ENOPROTOOPT
124 #define WSAEALREADY EALREADY
125 #define WSAEISCONN EISCONN
126 #define SOCKET_ERROR -1
127
128 #ifndef WSAGetLastError
129 #define WSAGetLastError() errno
130 #endif
131
132
133
134 /*
135 typedef int (*pthread_create_fp)(pthread_t *__thread,__const pthread_attr_t *__attr,void *(*__start_routine) (void
136 *),void *__arg); typedef void (*pthread_exit_fp)(void *__retval); typedef int (*pthread_detach_fp)(pthread_t __th);
137 typedef pthread_t (*pthread_self_fp)(void);
138
139 extern pthread_create_fp df_pthread_create;
140 extern pthread_exit_fp df_pthread_exit;
141 extern pthread_detach_fp df_pthread_detach;
142 extern pthread_self_fp df_pthread_self;
143 */
144
145 bool inet_LoadThreadLib(void);
146
147 #endif
148
149 #include "CFtp.h"
150 #include "Chttpget.h"
151
152 #define INET_ERROR_NO_ERROR 0
153 #define INET_ERROR_BADPARMS 1
154 #define INET_ERROR_CANT_WRITE_FILE 2
155 #define INET_ERROR_CANT_PARSE_URL 3
156 #define INET_ERROR_BAD_FILE_OR_DIR 4
157 #define INET_ERROR_HOST_NOT_FOUND 5
158 #define INET_ERROR_UNKNOWN_ERROR 6
159 #define INET_ERROR_NO_MEMORY 7
160
161 #define INET_STATE_CONNECTING 1
162 #define INET_STATE_ERROR 2
163 #define INET_STATE_RECEIVING 3
164 #define INET_STATE_GOT_FILE 4
165
166 class InetGetFile {
167 public:
168 InetGetFile(char *URL, char *localfile);
169 InetGetFile(char *URL, char *localfile, char *proxyip, int16_t proxyport);
170 ~InetGetFile();
171 BOOL IsFileReceived();
172 BOOL IsFileError();
173 BOOL IsConnecting();
174 BOOL IsReceiving();
175 int GetErrorCode();
176 int GetBytesIn();
177 int GetTotalBytes();
178 void AbortGet();
179
180 protected:
181 CFtpGet *ftp;
182 ChttpGet *http;
183 BOOL m_bUseHTTP;
184 int m_ErrorCode;
185 int m_State;
186 int m_HardError;
187 };
188
189 #endif
190
191 /*
192
193 #include <stdio.h>
194 #include <windows.h>
195 #include <conio.h>
196 #include <time.h>
197
198 #include "inetgetfile.h"
199
200 int main(int argc,char **argv)
201 {
202 uint32_t LastPrintbytes = time(NULL);
203 InetGetFile *inetfile;
204 WSADATA ws_data;
205 WORD ver=MAKEWORD(1,1);
206
207 int error=WSAStartup(ver,&ws_data);
208 inetfile = new
209 InetGetFile("http://www.volition-inc.com/images/download/freespace/fsdemo1x-12u.exe","e:\\fsdemo1x-12u.exe"); do
210 {
211 if(inetfile->IsFileReceived())
212 {
213 printf("File received\n");
214 break;
215 }
216 if(inetfile->IsFileError())
217 {
218 printf("File not received. Error code: %d\n",inetfile->GetErrorCode());
219 break;
220 }
221 if(time(NULL)-LastPrintbytes>=1)
222 {
223 int ipct = 0;
224 if(inetfile->GetTotalBytes())
225 {
226 ipct = 100*(float)((float)inetfile->GetBytesIn()/(float)inetfile->GetTotalBytes());
227 }
228 printf("Received %d Bytes out of %d
229 (%d%%).\n",inetfile->GetBytesIn(),inetfile->GetTotalBytes(),ipct); LastPrintbytes = time(NULL);
230 }
231
232
233 }while(!kbhit());
234 return 0;
235
236 }
237
238
239
240 */