Sync to trunk head (r47736)
[reactos.git] / 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 #ifndef __WINE_CONFIG_H
27 # error You must include config.h to use this header
28 #endif
29
30 #include "wine/unicode.h"
31 #include "wine/list.h"
32
33 #include <time.h>
34 #ifdef HAVE_NETDB_H
35 # include <netdb.h>
36 #endif
37 #ifdef HAVE_NETINET_IN_H
38 # include <sys/types.h>
39 # include <netinet/in.h>
40 #endif
41 #ifdef HAVE_SYS_SOCKET_H
42 # include <sys/socket.h>
43 #endif
44
45 #if !defined(__MINGW32__) && !defined(_MSC_VER)
46 #define closesocket close
47 #define ioctlsocket ioctl
48 #endif /* __MINGW32__ */
49
50 /* ReactOS-specific definitions */
51 #undef CP_UNIXCP
52 #define CP_UNIXCP CP_THREAD_ACP
53
54 /* used for netconnection.c stuff */
55 typedef struct
56 {
57 BOOL useSSL;
58 int socketFD;
59 void *ssl_s;
60 } WININET_NETCONNECTION;
61
62 static inline LPWSTR heap_strdupW(LPCWSTR str)
63 {
64 LPWSTR ret = NULL;
65
66 if(str) {
67 DWORD size;
68
69 size = (strlenW(str)+1)*sizeof(WCHAR);
70 ret = HeapAlloc(GetProcessHeap(), 0, size);
71 if(ret)
72 memcpy(ret, str, size);
73 }
74
75 return ret;
76 }
77
78 static inline WCHAR *heap_strdupAtoW(const char *str)
79 {
80 LPWSTR ret = NULL;
81
82 if(str) {
83 DWORD len;
84
85 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
86 ret = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
87 if(ret)
88 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
89 }
90
91 return ret;
92 }
93
94 static inline char *heap_strdupWtoA(LPCWSTR str)
95 {
96 char *ret = NULL;
97
98 if(str) {
99 DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
100 ret = HeapAlloc(GetProcessHeap(), 0, size);
101 if(ret)
102 WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
103 }
104
105 return ret;
106 }
107
108 static inline void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW, LPWIN32_FIND_DATAA dataA)
109 {
110 dataA->dwFileAttributes = dataW->dwFileAttributes;
111 dataA->ftCreationTime = dataW->ftCreationTime;
112 dataA->ftLastAccessTime = dataW->ftLastAccessTime;
113 dataA->ftLastWriteTime = dataW->ftLastWriteTime;
114 dataA->nFileSizeHigh = dataW->nFileSizeHigh;
115 dataA->nFileSizeLow = dataW->nFileSizeLow;
116 dataA->dwReserved0 = dataW->dwReserved0;
117 dataA->dwReserved1 = dataW->dwReserved1;
118 WideCharToMultiByte(CP_ACP, 0, dataW->cFileName, -1,
119 dataA->cFileName, sizeof(dataA->cFileName),
120 NULL, NULL);
121 WideCharToMultiByte(CP_ACP, 0, dataW->cAlternateFileName, -1,
122 dataA->cAlternateFileName, sizeof(dataA->cAlternateFileName),
123 NULL, NULL);
124 }
125
126 typedef enum
127 {
128 WH_HINIT = INTERNET_HANDLE_TYPE_INTERNET,
129 WH_HFTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_FTP,
130 WH_HGOPHERSESSION = INTERNET_HANDLE_TYPE_CONNECT_GOPHER,
131 WH_HHTTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_HTTP,
132 WH_HFILE = INTERNET_HANDLE_TYPE_FTP_FILE,
133 WH_HFTPFINDNEXT = INTERNET_HANDLE_TYPE_FTP_FIND,
134 WH_HHTTPREQ = INTERNET_HANDLE_TYPE_HTTP_REQUEST,
135 } WH_TYPE;
136
137 #define INET_OPENURL 0x0001
138 #define INET_CALLBACKW 0x0002
139
140 typedef struct _object_header_t object_header_t;
141
142 typedef struct {
143 void (*Destroy)(object_header_t*);
144 void (*CloseConnection)(object_header_t*);
145 DWORD (*QueryOption)(object_header_t*,DWORD,void*,DWORD*,BOOL);
146 DWORD (*SetOption)(object_header_t*,DWORD,void*,DWORD);
147 DWORD (*ReadFile)(object_header_t*,void*,DWORD,DWORD*);
148 DWORD (*ReadFileExA)(object_header_t*,INTERNET_BUFFERSA*,DWORD,DWORD_PTR);
149 DWORD (*ReadFileExW)(object_header_t*,INTERNET_BUFFERSW*,DWORD,DWORD_PTR);
150 DWORD (*WriteFile)(object_header_t*,const void*,DWORD,DWORD*);
151 DWORD (*QueryDataAvailable)(object_header_t*,DWORD*,DWORD,DWORD_PTR);
152 DWORD (*FindNextFileW)(object_header_t*,void*);
153 } object_vtbl_t;
154
155 struct _object_header_t
156 {
157 WH_TYPE htype;
158 const object_vtbl_t *vtbl;
159 HINTERNET hInternet;
160 DWORD dwFlags;
161 DWORD_PTR dwContext;
162 DWORD dwError;
163 ULONG ErrorMask;
164 DWORD dwInternalFlags;
165 LONG refs;
166 INTERNET_STATUS_CALLBACK lpfnStatusCB;
167 struct list entry;
168 struct list children;
169 };
170
171
172 typedef struct
173 {
174 object_header_t hdr;
175 LPWSTR lpszAgent;
176 LPWSTR lpszProxy;
177 LPWSTR lpszProxyBypass;
178 LPWSTR lpszProxyUsername;
179 LPWSTR lpszProxyPassword;
180 DWORD dwAccessType;
181 } appinfo_t;
182
183
184 typedef struct
185 {
186 object_header_t hdr;
187 appinfo_t *lpAppInfo;
188 LPWSTR lpszHostName; /* the final destination of the request */
189 LPWSTR lpszServerName; /* the name of the server we directly connect to */
190 LPWSTR lpszUserName;
191 LPWSTR lpszPassword;
192 INTERNET_PORT nHostPort; /* the final destination port of the request */
193 INTERNET_PORT nServerPort; /* the port of the server we directly connect to */
194 struct sockaddr_storage socketAddress;
195 socklen_t sa_len;
196 } http_session_t;
197
198 #define HDR_ISREQUEST 0x0001
199 #define HDR_COMMADELIMITED 0x0002
200 #define HDR_SEMIDELIMITED 0x0004
201
202 typedef struct
203 {
204 LPWSTR lpszField;
205 LPWSTR lpszValue;
206 WORD wFlags;
207 WORD wCount;
208 } HTTPHEADERW, *LPHTTPHEADERW;
209
210
211 struct HttpAuthInfo;
212
213 typedef struct gzip_stream_t gzip_stream_t;
214
215 typedef struct
216 {
217 object_header_t hdr;
218 http_session_t *lpHttpSession;
219 LPWSTR lpszPath;
220 LPWSTR lpszVerb;
221 LPWSTR lpszRawHeaders;
222 WININET_NETCONNECTION netConnection;
223 LPWSTR lpszVersion;
224 LPWSTR lpszStatusText;
225 DWORD dwBytesToWrite;
226 DWORD dwBytesWritten;
227 HTTPHEADERW *pCustHeaders;
228 DWORD nCustHeaders;
229 HANDLE hCacheFile;
230 LPWSTR lpszCacheFile;
231 struct HttpAuthInfo *pAuthInfo;
232 struct HttpAuthInfo *pProxyAuthInfo;
233
234 CRITICAL_SECTION read_section; /* section to protect the following fields */
235 DWORD dwContentLength; /* total number of bytes to be read */
236 DWORD dwContentRead; /* bytes of the content read so far */
237 BOOL read_chunked; /* are we reading in chunked mode? */
238 DWORD read_pos; /* current read position in read_buf */
239 DWORD read_size; /* valid data size in read_buf */
240 BYTE read_buf[4096]; /* buffer for already read but not returned data */
241
242 BOOL decoding;
243 gzip_stream_t *gzip_stream;
244 } http_request_t;
245
246
247
248 struct WORKREQ_FTPPUTFILEW
249 {
250 LPWSTR lpszLocalFile;
251 LPWSTR lpszNewRemoteFile;
252 DWORD dwFlags;
253 DWORD_PTR dwContext;
254 };
255
256 struct WORKREQ_FTPSETCURRENTDIRECTORYW
257 {
258 LPWSTR lpszDirectory;
259 };
260
261 struct WORKREQ_FTPCREATEDIRECTORYW
262 {
263 LPWSTR lpszDirectory;
264 };
265
266 struct WORKREQ_FTPFINDFIRSTFILEW
267 {
268 LPWSTR lpszSearchFile;
269 LPWIN32_FIND_DATAW lpFindFileData;
270 DWORD dwFlags;
271 DWORD_PTR dwContext;
272 };
273
274 struct WORKREQ_FTPGETCURRENTDIRECTORYW
275 {
276 LPWSTR lpszDirectory;
277 DWORD *lpdwDirectory;
278 };
279
280 struct WORKREQ_FTPOPENFILEW
281 {
282 LPWSTR lpszFilename;
283 DWORD dwAccess;
284 DWORD dwFlags;
285 DWORD_PTR dwContext;
286 };
287
288 struct WORKREQ_FTPGETFILEW
289 {
290 LPWSTR lpszRemoteFile;
291 LPWSTR lpszNewFile;
292 BOOL fFailIfExists;
293 DWORD dwLocalFlagsAttribute;
294 DWORD dwFlags;
295 DWORD_PTR dwContext;
296 };
297
298 struct WORKREQ_FTPDELETEFILEW
299 {
300 LPWSTR lpszFilename;
301 };
302
303 struct WORKREQ_FTPREMOVEDIRECTORYW
304 {
305 LPWSTR lpszDirectory;
306 };
307
308 struct WORKREQ_FTPRENAMEFILEW
309 {
310 LPWSTR lpszSrcFile;
311 LPWSTR lpszDestFile;
312 };
313
314 struct WORKREQ_FTPFINDNEXTW
315 {
316 LPWIN32_FIND_DATAW lpFindFileData;
317 };
318
319 struct WORKREQ_HTTPSENDREQUESTW
320 {
321 LPWSTR lpszHeader;
322 DWORD dwHeaderLength;
323 LPVOID lpOptional;
324 DWORD dwOptionalLength;
325 DWORD dwContentLength;
326 BOOL bEndRequest;
327 };
328
329 struct WORKREQ_HTTPENDREQUESTW
330 {
331 DWORD dwFlags;
332 DWORD_PTR dwContext;
333 };
334
335 struct WORKREQ_SENDCALLBACK
336 {
337 DWORD_PTR dwContext;
338 DWORD dwInternetStatus;
339 LPVOID lpvStatusInfo;
340 DWORD dwStatusInfoLength;
341 };
342
343 struct WORKREQ_INTERNETOPENURLW
344 {
345 HINTERNET hInternet;
346 LPWSTR lpszUrl;
347 LPWSTR lpszHeaders;
348 DWORD dwHeadersLength;
349 DWORD dwFlags;
350 DWORD_PTR dwContext;
351 };
352
353 struct WORKREQ_INTERNETREADFILEEXA
354 {
355 LPINTERNET_BUFFERSA lpBuffersOut;
356 };
357
358 struct WORKREQ_INTERNETREADFILEEXW
359 {
360 LPINTERNET_BUFFERSW lpBuffersOut;
361 };
362
363 typedef struct WORKREQ
364 {
365 void (*asyncproc)(struct WORKREQ*);
366 object_header_t *hdr;
367
368 union {
369 struct WORKREQ_FTPPUTFILEW FtpPutFileW;
370 struct WORKREQ_FTPSETCURRENTDIRECTORYW FtpSetCurrentDirectoryW;
371 struct WORKREQ_FTPCREATEDIRECTORYW FtpCreateDirectoryW;
372 struct WORKREQ_FTPFINDFIRSTFILEW FtpFindFirstFileW;
373 struct WORKREQ_FTPGETCURRENTDIRECTORYW FtpGetCurrentDirectoryW;
374 struct WORKREQ_FTPOPENFILEW FtpOpenFileW;
375 struct WORKREQ_FTPGETFILEW FtpGetFileW;
376 struct WORKREQ_FTPDELETEFILEW FtpDeleteFileW;
377 struct WORKREQ_FTPREMOVEDIRECTORYW FtpRemoveDirectoryW;
378 struct WORKREQ_FTPRENAMEFILEW FtpRenameFileW;
379 struct WORKREQ_FTPFINDNEXTW FtpFindNextW;
380 struct WORKREQ_HTTPSENDREQUESTW HttpSendRequestW;
381 struct WORKREQ_HTTPENDREQUESTW HttpEndRequestW;
382 struct WORKREQ_SENDCALLBACK SendCallback;
383 struct WORKREQ_INTERNETOPENURLW InternetOpenUrlW;
384 struct WORKREQ_INTERNETREADFILEEXA InternetReadFileExA;
385 struct WORKREQ_INTERNETREADFILEEXW InternetReadFileExW;
386 } u;
387
388 } WORKREQUEST, *LPWORKREQUEST;
389
390 HINTERNET WININET_AllocHandle( object_header_t *info );
391 object_header_t *WININET_GetObject( HINTERNET hinternet );
392 object_header_t *WININET_AddRef( object_header_t *info );
393 BOOL WININET_Release( object_header_t *info );
394 BOOL WININET_FreeHandle( HINTERNET hinternet );
395
396 DWORD INET_QueryOption( object_header_t *, DWORD, void *, DWORD *, BOOL );
397
398 time_t ConvertTimeString(LPCWSTR asctime);
399
400 HINTERNET FTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName,
401 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
402 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
403 DWORD dwInternalFlags);
404
405 DWORD HTTP_Connect(appinfo_t*,LPCWSTR,
406 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
407 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
408 DWORD dwInternalFlags, HINTERNET*);
409
410 BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
411 struct sockaddr *psa, socklen_t *sa_len);
412
413 void INTERNET_SetLastError(DWORD dwError);
414 DWORD INTERNET_GetLastError(void);
415 DWORD INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest);
416 LPSTR INTERNET_GetResponseBuffer(void);
417 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen);
418
419 VOID SendAsyncCallback(object_header_t *hdr, DWORD_PTR dwContext,
420 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
421 DWORD dwStatusInfoLength);
422
423 VOID INTERNET_SendCallback(object_header_t *hdr, DWORD_PTR dwContext,
424 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
425 DWORD dwStatusInfoLength);
426 BOOL INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto, WCHAR *foundProxy, DWORD *foundProxyLen);
427
428 BOOL NETCON_connected(WININET_NETCONNECTION *connection);
429 DWORD NETCON_init(WININET_NETCONNECTION *connnection, BOOL useSSL);
430 void NETCON_unload(void);
431 DWORD NETCON_create(WININET_NETCONNECTION *connection, int domain,
432 int type, int protocol);
433 DWORD NETCON_close(WININET_NETCONNECTION *connection);
434 DWORD NETCON_connect(WININET_NETCONNECTION *connection, const struct sockaddr *serv_addr,
435 unsigned int addrlen);
436 DWORD NETCON_secure_connect(WININET_NETCONNECTION *connection, LPWSTR hostname);
437 DWORD NETCON_send(WININET_NETCONNECTION *connection, const void *msg, size_t len, int flags,
438 int *sent /* out */);
439 DWORD NETCON_recv(WININET_NETCONNECTION *connection, void *buf, size_t len, int flags,
440 int *recvd /* out */);
441 BOOL NETCON_query_data_available(WININET_NETCONNECTION *connection, DWORD *available);
442 LPCVOID NETCON_GetCert(WININET_NETCONNECTION *connection);
443 DWORD NETCON_set_timeout(WININET_NETCONNECTION *connection, BOOL send, int value);
444 int sock_get_error(int);
445
446 extern void URLCacheContainers_CreateDefaults(void);
447 extern void URLCacheContainers_DeleteAll(void);
448
449 #define MAX_REPLY_LEN 0x5B4
450
451 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
452 typedef struct
453 {
454 DWORD val;
455 const char* name;
456 } wininet_flag_info;
457
458 #endif /* _WINE_INTERNET_H_ */