- Sync wininet to Wine HEAD
[reactos.git] / reactos / dll / win32 / wininet / internet.h
1 /*
2 * Wininet
3 *
4 * Copyright 1999 Corel Corporation
5 *
6 * Ulrich Czekalla
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22
23 #ifndef _WINE_INTERNET_H_
24 #define _WINE_INTERNET_H_
25
26 /* ReactOS-specific definitions */
27 #define CP_UNIXCP CP_THREAD_ACP
28
29 #ifndef __WINE_CONFIG_H
30 # error You must include config.h to use this header
31 #endif
32
33 #include "wine/unicode.h"
34 #include "wine/list.h"
35
36 #include <time.h>
37 #ifdef HAVE_NETDB_H
38 # include <netdb.h>
39 #endif
40 #ifdef HAVE_NETINET_IN_H
41 # include <sys/types.h>
42 # include <netinet/in.h>
43 #endif
44 #ifdef HAVE_SYS_SOCKET_H
45 # include <sys/socket.h>
46 #endif
47
48 #if defined(__MINGW32__) || defined (_MSC_VER)
49 #include "ws2tcpip.h"
50 #ifndef MSG_WAITALL
51 #define MSG_WAITALL 0
52 #endif
53 #else
54 #define closesocket close
55 #define ioctlsocket ioctl
56 #endif /* __MINGW32__ */
57
58 /* used for netconnection.c stuff */
59 typedef struct
60 {
61 BOOL useSSL;
62 int socketFD;
63 void *ssl_s;
64 char *peek_msg;
65 char *peek_msg_mem;
66 size_t peek_len;
67 } WININET_NETCONNECTION;
68
69 static inline LPWSTR WININET_strdupW( LPCWSTR str )
70 {
71 LPWSTR ret = HeapAlloc( GetProcessHeap(), 0, (strlenW(str) + 1)*sizeof(WCHAR) );
72 if (ret) strcpyW( ret, str );
73 return ret;
74 }
75
76 static inline LPWSTR WININET_strdup_AtoW( LPCSTR str )
77 {
78 int len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0);
79 LPWSTR ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
80 if (ret)
81 MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len);
82 return ret;
83 }
84
85 static inline LPSTR WININET_strdup_WtoA( LPCWSTR str )
86 {
87 int len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
88 LPSTR ret = HeapAlloc( GetProcessHeap(), 0, len );
89 if (ret)
90 WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL);
91 return ret;
92 }
93
94 static inline void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW, LPWIN32_FIND_DATAA dataA)
95 {
96 dataA->dwFileAttributes = dataW->dwFileAttributes;
97 dataA->ftCreationTime = dataW->ftCreationTime;
98 dataA->ftLastAccessTime = dataW->ftLastAccessTime;
99 dataA->ftLastWriteTime = dataW->ftLastWriteTime;
100 dataA->nFileSizeHigh = dataW->nFileSizeHigh;
101 dataA->nFileSizeLow = dataW->nFileSizeLow;
102 dataA->dwReserved0 = dataW->dwReserved0;
103 dataA->dwReserved1 = dataW->dwReserved1;
104 WideCharToMultiByte(CP_ACP, 0, dataW->cFileName, -1,
105 dataA->cFileName, sizeof(dataA->cFileName),
106 NULL, NULL);
107 WideCharToMultiByte(CP_ACP, 0, dataW->cAlternateFileName, -1,
108 dataA->cAlternateFileName, sizeof(dataA->cAlternateFileName),
109 NULL, NULL);
110 }
111
112 typedef enum
113 {
114 WH_HINIT = INTERNET_HANDLE_TYPE_INTERNET,
115 WH_HFTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_FTP,
116 WH_HGOPHERSESSION = INTERNET_HANDLE_TYPE_CONNECT_GOPHER,
117 WH_HHTTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_HTTP,
118 WH_HFILE = INTERNET_HANDLE_TYPE_FTP_FILE,
119 WH_HFTPFINDNEXT = INTERNET_HANDLE_TYPE_FTP_FIND,
120 WH_HHTTPREQ = INTERNET_HANDLE_TYPE_HTTP_REQUEST,
121 } WH_TYPE;
122
123 #define INET_OPENURL 0x0001
124 #define INET_CALLBACKW 0x0002
125
126 typedef struct _WININETHANDLEHEADER WININETHANDLEHEADER, *LPWININETHANDLEHEADER;
127
128 typedef struct {
129 void (*Destroy)(WININETHANDLEHEADER*);
130 void (*CloseConnection)(WININETHANDLEHEADER*);
131 DWORD (*QueryOption)(WININETHANDLEHEADER*,DWORD,void*,DWORD*,BOOL);
132 DWORD (*SetOption)(WININETHANDLEHEADER*,DWORD,void*,DWORD);
133 DWORD (*ReadFile)(WININETHANDLEHEADER*,void*,DWORD,DWORD*);
134 DWORD (*ReadFileExA)(WININETHANDLEHEADER*,INTERNET_BUFFERSA*,DWORD,DWORD_PTR);
135 BOOL (*WriteFile)(WININETHANDLEHEADER*,const void*,DWORD,DWORD*);
136 DWORD (*QueryDataAvailable)(WININETHANDLEHEADER*,DWORD*,DWORD,DWORD_PTR);
137 DWORD (*FindNextFileW)(WININETHANDLEHEADER*,void*);
138 } HANDLEHEADERVtbl;
139
140 struct _WININETHANDLEHEADER
141 {
142 WH_TYPE htype;
143 const HANDLEHEADERVtbl *vtbl;
144 HINTERNET hInternet;
145 DWORD dwFlags;
146 DWORD_PTR dwContext;
147 DWORD dwError;
148 DWORD dwInternalFlags;
149 LONG refs;
150 INTERNET_STATUS_CALLBACK lpfnStatusCB;
151 struct list entry;
152 struct list children;
153 };
154
155
156 typedef struct
157 {
158 WININETHANDLEHEADER hdr;
159 LPWSTR lpszAgent;
160 LPWSTR lpszProxy;
161 LPWSTR lpszProxyBypass;
162 LPWSTR lpszProxyUsername;
163 LPWSTR lpszProxyPassword;
164 DWORD dwAccessType;
165 } WININETAPPINFOW, *LPWININETAPPINFOW;
166
167
168 typedef struct
169 {
170 WININETHANDLEHEADER hdr;
171 WININETAPPINFOW *lpAppInfo;
172 LPWSTR lpszHostName; /* the final destination of the request */
173 LPWSTR lpszServerName; /* the name of the server we directly connect to */
174 LPWSTR lpszUserName;
175 LPWSTR lpszPassword;
176 INTERNET_PORT nHostPort; /* the final destination port of the request */
177 INTERNET_PORT nServerPort; /* the port of the server we directly connect to */
178 struct sockaddr_in socketAddress;
179 } WININETHTTPSESSIONW, *LPWININETHTTPSESSIONW;
180
181 #define HDR_ISREQUEST 0x0001
182 #define HDR_COMMADELIMITED 0x0002
183 #define HDR_SEMIDELIMITED 0x0004
184
185 typedef struct
186 {
187 LPWSTR lpszField;
188 LPWSTR lpszValue;
189 WORD wFlags;
190 WORD wCount;
191 } HTTPHEADERW, *LPHTTPHEADERW;
192
193
194 struct HttpAuthInfo;
195
196 typedef struct
197 {
198 WININETHANDLEHEADER hdr;
199 WININETHTTPSESSIONW *lpHttpSession;
200 LPWSTR lpszPath;
201 LPWSTR lpszVerb;
202 LPWSTR lpszRawHeaders;
203 WININET_NETCONNECTION netConnection;
204 LPWSTR lpszVersion;
205 LPWSTR lpszStatusText;
206 DWORD dwContentLength; /* total number of bytes to be read */
207 DWORD dwContentRead; /* bytes of the content read so far */
208 HTTPHEADERW *pCustHeaders;
209 DWORD nCustHeaders;
210 HANDLE hCacheFile;
211 LPWSTR lpszCacheFile;
212 struct HttpAuthInfo *pAuthInfo;
213 struct HttpAuthInfo *pProxyAuthInfo;
214 } WININETHTTPREQW, *LPWININETHTTPREQW;
215
216
217
218 struct WORKREQ_FTPPUTFILEW
219 {
220 LPWSTR lpszLocalFile;
221 LPWSTR lpszNewRemoteFile;
222 DWORD dwFlags;
223 DWORD_PTR dwContext;
224 };
225
226 struct WORKREQ_FTPSETCURRENTDIRECTORYW
227 {
228 LPWSTR lpszDirectory;
229 };
230
231 struct WORKREQ_FTPCREATEDIRECTORYW
232 {
233 LPWSTR lpszDirectory;
234 };
235
236 struct WORKREQ_FTPFINDFIRSTFILEW
237 {
238 LPWSTR lpszSearchFile;
239 LPWIN32_FIND_DATAW lpFindFileData;
240 DWORD dwFlags;
241 DWORD_PTR dwContext;
242 };
243
244 struct WORKREQ_FTPGETCURRENTDIRECTORYW
245 {
246 LPWSTR lpszDirectory;
247 DWORD *lpdwDirectory;
248 };
249
250 struct WORKREQ_FTPOPENFILEW
251 {
252 LPWSTR lpszFilename;
253 DWORD dwAccess;
254 DWORD dwFlags;
255 DWORD_PTR dwContext;
256 };
257
258 struct WORKREQ_FTPGETFILEW
259 {
260 LPWSTR lpszRemoteFile;
261 LPWSTR lpszNewFile;
262 BOOL fFailIfExists;
263 DWORD dwLocalFlagsAttribute;
264 DWORD dwFlags;
265 DWORD_PTR dwContext;
266 };
267
268 struct WORKREQ_FTPDELETEFILEW
269 {
270 LPWSTR lpszFilename;
271 };
272
273 struct WORKREQ_FTPREMOVEDIRECTORYW
274 {
275 LPWSTR lpszDirectory;
276 };
277
278 struct WORKREQ_FTPRENAMEFILEW
279 {
280 LPWSTR lpszSrcFile;
281 LPWSTR lpszDestFile;
282 };
283
284 struct WORKREQ_FTPFINDNEXTW
285 {
286 LPWIN32_FIND_DATAW lpFindFileData;
287 };
288
289 struct WORKREQ_HTTPSENDREQUESTW
290 {
291 LPWSTR lpszHeader;
292 DWORD dwHeaderLength;
293 LPVOID lpOptional;
294 DWORD dwOptionalLength;
295 DWORD dwContentLength;
296 BOOL bEndRequest;
297 };
298
299 struct WORKREQ_SENDCALLBACK
300 {
301 DWORD_PTR dwContext;
302 DWORD dwInternetStatus;
303 LPVOID lpvStatusInfo;
304 DWORD dwStatusInfoLength;
305 };
306
307 struct WORKREQ_INTERNETOPENURLW
308 {
309 HINTERNET hInternet;
310 LPWSTR lpszUrl;
311 LPWSTR lpszHeaders;
312 DWORD dwHeadersLength;
313 DWORD dwFlags;
314 DWORD_PTR dwContext;
315 };
316
317 struct WORKREQ_INTERNETREADFILEEXA
318 {
319 LPINTERNET_BUFFERSA lpBuffersOut;
320 };
321
322 typedef struct WORKREQ
323 {
324 void (*asyncproc)(struct WORKREQ*);
325 WININETHANDLEHEADER *hdr;
326
327 union {
328 struct WORKREQ_FTPPUTFILEW FtpPutFileW;
329 struct WORKREQ_FTPSETCURRENTDIRECTORYW FtpSetCurrentDirectoryW;
330 struct WORKREQ_FTPCREATEDIRECTORYW FtpCreateDirectoryW;
331 struct WORKREQ_FTPFINDFIRSTFILEW FtpFindFirstFileW;
332 struct WORKREQ_FTPGETCURRENTDIRECTORYW FtpGetCurrentDirectoryW;
333 struct WORKREQ_FTPOPENFILEW FtpOpenFileW;
334 struct WORKREQ_FTPGETFILEW FtpGetFileW;
335 struct WORKREQ_FTPDELETEFILEW FtpDeleteFileW;
336 struct WORKREQ_FTPREMOVEDIRECTORYW FtpRemoveDirectoryW;
337 struct WORKREQ_FTPRENAMEFILEW FtpRenameFileW;
338 struct WORKREQ_FTPFINDNEXTW FtpFindNextW;
339 struct WORKREQ_HTTPSENDREQUESTW HttpSendRequestW;
340 struct WORKREQ_SENDCALLBACK SendCallback;
341 struct WORKREQ_INTERNETOPENURLW InternetOpenUrlW;
342 struct WORKREQ_INTERNETREADFILEEXA InternetReadFileExA;
343 } u;
344
345 } WORKREQUEST, *LPWORKREQUEST;
346
347 HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info );
348 LPWININETHANDLEHEADER WININET_GetObject( HINTERNET hinternet );
349 LPWININETHANDLEHEADER WININET_AddRef( LPWININETHANDLEHEADER info );
350 BOOL WININET_Release( LPWININETHANDLEHEADER info );
351 BOOL WININET_FreeHandle( HINTERNET hinternet );
352
353 DWORD INET_QueryOption(DWORD,void*,DWORD*,BOOL);
354
355 time_t ConvertTimeString(LPCWSTR asctime);
356
357 HINTERNET FTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
358 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
359 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
360 DWORD dwInternalFlags);
361
362 HINTERNET HTTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
363 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
364 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
365 DWORD dwInternalFlags);
366
367 BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
368 struct sockaddr_in *psa);
369
370 void INTERNET_SetLastError(DWORD dwError);
371 DWORD INTERNET_GetLastError(void);
372 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest);
373 LPSTR INTERNET_GetResponseBuffer(void);
374 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen);
375
376 BOOLAPI HTTP_HttpSendRequestW(LPWININETHTTPREQW lpwhr, LPCWSTR lpszHeaders,
377 DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength,
378 DWORD dwContentLength, BOOL bEndRequest);
379 INTERNETAPI HINTERNET WINAPI HTTP_HttpOpenRequestW(LPWININETHTTPSESSIONW lpwhs,
380 LPCWSTR lpszVerb, LPCWSTR lpszObjectName, LPCWSTR lpszVersion,
381 LPCWSTR lpszReferrer , LPCWSTR *lpszAcceptTypes,
382 DWORD dwFlags, DWORD_PTR dwContext);
383 BOOL HTTP_FinishedReading(LPWININETHTTPREQW lpwhr);
384
385 VOID SendAsyncCallback(LPWININETHANDLEHEADER hdr, DWORD_PTR dwContext,
386 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
387 DWORD dwStatusInfoLength);
388
389 VOID INTERNET_SendCallback(LPWININETHANDLEHEADER hdr, DWORD_PTR dwContext,
390 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
391 DWORD dwStatusInfoLength);
392
393 LPHTTPHEADERW HTTP_GetHeader(LPWININETHTTPREQW lpwhr, LPCWSTR header);
394
395 BOOL NETCON_connected(WININET_NETCONNECTION *connection);
396 BOOL NETCON_init(WININET_NETCONNECTION *connnection, BOOL useSSL);
397 BOOL NETCON_create(WININET_NETCONNECTION *connection, int domain,
398 int type, int protocol);
399 BOOL NETCON_close(WININET_NETCONNECTION *connection);
400 BOOL NETCON_connect(WININET_NETCONNECTION *connection, const struct sockaddr *serv_addr,
401 unsigned int addrlen);
402 BOOL NETCON_secure_connect(WININET_NETCONNECTION *connection, LPCWSTR hostname);
403 BOOL NETCON_send(WININET_NETCONNECTION *connection, const void *msg, size_t len, int flags,
404 int *sent /* out */);
405 BOOL NETCON_recv(WININET_NETCONNECTION *connection, void *buf, size_t len, int flags,
406 int *recvd /* out */);
407 BOOL NETCON_query_data_available(WININET_NETCONNECTION *connection, DWORD *available);
408 BOOL NETCON_getNextLine(WININET_NETCONNECTION *connection, LPSTR lpszBuffer, LPDWORD dwBuffer);
409 LPCVOID NETCON_GetCert(WININET_NETCONNECTION *connection);
410 DWORD NETCON_set_timeout(WININET_NETCONNECTION *connection, BOOL send, int value);
411
412 extern void URLCacheContainers_CreateDefaults(void);
413 extern void URLCacheContainers_DeleteAll(void);
414
415 #define MAX_REPLY_LEN 0x5B4
416
417 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
418 typedef struct
419 {
420 DWORD val;
421 const char* name;
422 } wininet_flag_info;
423
424 #endif /* _WINE_INTERNET_H_ */