- Implement ProtocolResetComplete
[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 /* 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_OPENSSL_SSL_H
45 #define DSA __ssl_DSA /* avoid conflict with commctrl.h */
46 #undef FAR
47 /* avoid conflict with wincrypt.h */
48 #undef PKCS7_SIGNER_INFO
49 #undef X509_NAME
50 #undef X509_CERT_PAIR
51 # include <openssl/ssl.h>
52 #undef FAR
53 #define FAR do_not_use_this_in_wine
54 #undef DSA
55 #endif
56 #ifdef HAVE_SYS_SOCKET_H
57 # include <sys/socket.h>
58 #endif
59
60 #if defined(__MINGW32__) || defined (_MSC_VER)
61 #include "ws2tcpip.h"
62 #ifndef MSG_WAITALL
63 #define MSG_WAITALL 0
64 #endif
65 #else
66 #define closesocket close
67 #define ioctlsocket ioctl
68 #endif /* __MINGW32__ */
69
70 /* used for netconnection.c stuff */
71 typedef struct
72 {
73 BOOL useSSL;
74 int socketFD;
75 #ifdef HAVE_OPENSSL_SSL_H
76 SSL *ssl_s;
77 char *peek_msg;
78 char *peek_msg_mem;
79 size_t peek_len;
80 #endif
81 } WININET_NETCONNECTION;
82
83 static inline LPWSTR WININET_strdupW( LPCWSTR str )
84 {
85 LPWSTR ret = HeapAlloc( GetProcessHeap(), 0, (strlenW(str) + 1)*sizeof(WCHAR) );
86 if (ret) strcpyW( ret, str );
87 return ret;
88 }
89
90 static inline LPWSTR WININET_strdup_AtoW( LPCSTR str )
91 {
92 int len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0);
93 LPWSTR ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
94 if (ret)
95 MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len);
96 return ret;
97 }
98
99 static inline LPSTR WININET_strdup_WtoA( LPCWSTR str )
100 {
101 int len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
102 LPSTR ret = HeapAlloc( GetProcessHeap(), 0, len );
103 if (ret)
104 WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL);
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 _WININETHANDLEHEADER WININETHANDLEHEADER, *LPWININETHANDLEHEADER;
141
142 typedef struct {
143 void (*Destroy)(WININETHANDLEHEADER*);
144 void (*CloseConnection)(WININETHANDLEHEADER*);
145 DWORD (*QueryOption)(WININETHANDLEHEADER*,DWORD,void*,DWORD*,BOOL);
146 DWORD (*SetOption)(WININETHANDLEHEADER*,DWORD,void*,DWORD);
147 DWORD (*ReadFile)(WININETHANDLEHEADER*,void*,DWORD,DWORD*);
148 DWORD (*ReadFileExA)(WININETHANDLEHEADER*,INTERNET_BUFFERSA*,DWORD,DWORD_PTR);
149 BOOL (*WriteFile)(WININETHANDLEHEADER*,const void*,DWORD,DWORD*);
150 DWORD (*QueryDataAvailable)(WININETHANDLEHEADER*,DWORD*,DWORD,DWORD_PTR);
151 DWORD (*FindNextFileW)(WININETHANDLEHEADER*,void*);
152 } HANDLEHEADERVtbl;
153
154 struct _WININETHANDLEHEADER
155 {
156 WH_TYPE htype;
157 const HANDLEHEADERVtbl *vtbl;
158 HINTERNET hInternet;
159 DWORD dwFlags;
160 DWORD_PTR dwContext;
161 DWORD dwError;
162 DWORD dwInternalFlags;
163 LONG refs;
164 INTERNET_STATUS_CALLBACK lpfnStatusCB;
165 struct list entry;
166 struct list children;
167 };
168
169
170 typedef struct
171 {
172 WININETHANDLEHEADER hdr;
173 LPWSTR lpszAgent;
174 LPWSTR lpszProxy;
175 LPWSTR lpszProxyBypass;
176 LPWSTR lpszProxyUsername;
177 LPWSTR lpszProxyPassword;
178 DWORD dwAccessType;
179 } WININETAPPINFOW, *LPWININETAPPINFOW;
180
181
182 typedef struct
183 {
184 WININETHANDLEHEADER hdr;
185 WININETAPPINFOW *lpAppInfo;
186 LPWSTR lpszHostName; /* the final destination of the request */
187 LPWSTR lpszServerName; /* the name of the server we directly connect to */
188 LPWSTR lpszUserName;
189 LPWSTR lpszPassword;
190 INTERNET_PORT nHostPort; /* the final destination port of the request */
191 INTERNET_PORT nServerPort; /* the port of the server we directly connect to */
192 struct sockaddr_in socketAddress;
193 } WININETHTTPSESSIONW, *LPWININETHTTPSESSIONW;
194
195 #define HDR_ISREQUEST 0x0001
196 #define HDR_COMMADELIMITED 0x0002
197 #define HDR_SEMIDELIMITED 0x0004
198
199 typedef struct
200 {
201 LPWSTR lpszField;
202 LPWSTR lpszValue;
203 WORD wFlags;
204 WORD wCount;
205 } HTTPHEADERW, *LPHTTPHEADERW;
206
207
208 struct HttpAuthInfo;
209
210 typedef struct
211 {
212 WININETHANDLEHEADER hdr;
213 WININETHTTPSESSIONW *lpHttpSession;
214 LPWSTR lpszPath;
215 LPWSTR lpszVerb;
216 LPWSTR lpszRawHeaders;
217 WININET_NETCONNECTION netConnection;
218 LPWSTR lpszVersion;
219 LPWSTR lpszStatusText;
220 DWORD dwContentLength; /* total number of bytes to be read */
221 DWORD dwContentRead; /* bytes of the content read so far */
222 HTTPHEADERW *pCustHeaders;
223 DWORD nCustHeaders;
224 HANDLE hCacheFile;
225 LPWSTR lpszCacheFile;
226 struct HttpAuthInfo *pAuthInfo;
227 struct HttpAuthInfo *pProxyAuthInfo;
228 } WININETHTTPREQW, *LPWININETHTTPREQW;
229
230
231
232 struct WORKREQ_FTPPUTFILEW
233 {
234 LPWSTR lpszLocalFile;
235 LPWSTR lpszNewRemoteFile;
236 DWORD dwFlags;
237 DWORD_PTR dwContext;
238 };
239
240 struct WORKREQ_FTPSETCURRENTDIRECTORYW
241 {
242 LPWSTR lpszDirectory;
243 };
244
245 struct WORKREQ_FTPCREATEDIRECTORYW
246 {
247 LPWSTR lpszDirectory;
248 };
249
250 struct WORKREQ_FTPFINDFIRSTFILEW
251 {
252 LPWSTR lpszSearchFile;
253 LPWIN32_FIND_DATAW lpFindFileData;
254 DWORD dwFlags;
255 DWORD_PTR dwContext;
256 };
257
258 struct WORKREQ_FTPGETCURRENTDIRECTORYW
259 {
260 LPWSTR lpszDirectory;
261 DWORD *lpdwDirectory;
262 };
263
264 struct WORKREQ_FTPOPENFILEW
265 {
266 LPWSTR lpszFilename;
267 DWORD dwAccess;
268 DWORD dwFlags;
269 DWORD_PTR dwContext;
270 };
271
272 struct WORKREQ_FTPGETFILEW
273 {
274 LPWSTR lpszRemoteFile;
275 LPWSTR lpszNewFile;
276 BOOL fFailIfExists;
277 DWORD dwLocalFlagsAttribute;
278 DWORD dwFlags;
279 DWORD_PTR dwContext;
280 };
281
282 struct WORKREQ_FTPDELETEFILEW
283 {
284 LPWSTR lpszFilename;
285 };
286
287 struct WORKREQ_FTPREMOVEDIRECTORYW
288 {
289 LPWSTR lpszDirectory;
290 };
291
292 struct WORKREQ_FTPRENAMEFILEW
293 {
294 LPWSTR lpszSrcFile;
295 LPWSTR lpszDestFile;
296 };
297
298 struct WORKREQ_FTPFINDNEXTW
299 {
300 LPWIN32_FIND_DATAW lpFindFileData;
301 };
302
303 struct WORKREQ_HTTPSENDREQUESTW
304 {
305 LPWSTR lpszHeader;
306 DWORD dwHeaderLength;
307 LPVOID lpOptional;
308 DWORD dwOptionalLength;
309 DWORD dwContentLength;
310 BOOL bEndRequest;
311 };
312
313 struct WORKREQ_SENDCALLBACK
314 {
315 DWORD_PTR dwContext;
316 DWORD dwInternetStatus;
317 LPVOID lpvStatusInfo;
318 DWORD dwStatusInfoLength;
319 };
320
321 struct WORKREQ_INTERNETOPENURLW
322 {
323 HINTERNET hInternet;
324 LPWSTR lpszUrl;
325 LPWSTR lpszHeaders;
326 DWORD dwHeadersLength;
327 DWORD dwFlags;
328 DWORD_PTR dwContext;
329 };
330
331 struct WORKREQ_INTERNETREADFILEEXA
332 {
333 LPINTERNET_BUFFERSA lpBuffersOut;
334 };
335
336 typedef struct WORKREQ
337 {
338 void (*asyncproc)(struct WORKREQ*);
339 WININETHANDLEHEADER *hdr;
340
341 union {
342 struct WORKREQ_FTPPUTFILEW FtpPutFileW;
343 struct WORKREQ_FTPSETCURRENTDIRECTORYW FtpSetCurrentDirectoryW;
344 struct WORKREQ_FTPCREATEDIRECTORYW FtpCreateDirectoryW;
345 struct WORKREQ_FTPFINDFIRSTFILEW FtpFindFirstFileW;
346 struct WORKREQ_FTPGETCURRENTDIRECTORYW FtpGetCurrentDirectoryW;
347 struct WORKREQ_FTPOPENFILEW FtpOpenFileW;
348 struct WORKREQ_FTPGETFILEW FtpGetFileW;
349 struct WORKREQ_FTPDELETEFILEW FtpDeleteFileW;
350 struct WORKREQ_FTPREMOVEDIRECTORYW FtpRemoveDirectoryW;
351 struct WORKREQ_FTPRENAMEFILEW FtpRenameFileW;
352 struct WORKREQ_FTPFINDNEXTW FtpFindNextW;
353 struct WORKREQ_HTTPSENDREQUESTW HttpSendRequestW;
354 struct WORKREQ_SENDCALLBACK SendCallback;
355 struct WORKREQ_INTERNETOPENURLW InternetOpenUrlW;
356 struct WORKREQ_INTERNETREADFILEEXA InternetReadFileExA;
357 } u;
358
359 } WORKREQUEST, *LPWORKREQUEST;
360
361 HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info );
362 LPWININETHANDLEHEADER WININET_GetObject( HINTERNET hinternet );
363 LPWININETHANDLEHEADER WININET_AddRef( LPWININETHANDLEHEADER info );
364 BOOL WININET_Release( LPWININETHANDLEHEADER info );
365 BOOL WININET_FreeHandle( HINTERNET hinternet );
366
367 time_t ConvertTimeString(LPCWSTR asctime);
368
369 HINTERNET FTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
370 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
371 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
372 DWORD dwInternalFlags);
373
374 HINTERNET HTTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
375 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
376 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
377 DWORD dwInternalFlags);
378
379 BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
380 struct sockaddr_in *psa);
381
382 void INTERNET_SetLastError(DWORD dwError);
383 DWORD INTERNET_GetLastError(void);
384 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest);
385 LPSTR INTERNET_GetResponseBuffer(void);
386 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen);
387
388 BOOLAPI HTTP_HttpSendRequestW(LPWININETHTTPREQW lpwhr, LPCWSTR lpszHeaders,
389 DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength,
390 DWORD dwContentLength, BOOL bEndRequest);
391 INTERNETAPI HINTERNET WINAPI HTTP_HttpOpenRequestW(LPWININETHTTPSESSIONW lpwhs,
392 LPCWSTR lpszVerb, LPCWSTR lpszObjectName, LPCWSTR lpszVersion,
393 LPCWSTR lpszReferrer , LPCWSTR *lpszAcceptTypes,
394 DWORD dwFlags, DWORD_PTR dwContext);
395 BOOL HTTP_FinishedReading(LPWININETHTTPREQW lpwhr);
396
397 VOID SendAsyncCallback(LPWININETHANDLEHEADER hdr, DWORD_PTR dwContext,
398 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
399 DWORD dwStatusInfoLength);
400
401 VOID INTERNET_SendCallback(LPWININETHANDLEHEADER hdr, DWORD_PTR dwContext,
402 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
403 DWORD dwStatusInfoLength);
404
405 LPHTTPHEADERW HTTP_GetHeader(LPWININETHTTPREQW lpwhr, LPCWSTR header);
406
407 BOOL NETCON_connected(WININET_NETCONNECTION *connection);
408 BOOL NETCON_init(WININET_NETCONNECTION *connnection, BOOL useSSL);
409 BOOL NETCON_create(WININET_NETCONNECTION *connection, int domain,
410 int type, int protocol);
411 BOOL NETCON_close(WININET_NETCONNECTION *connection);
412 BOOL NETCON_connect(WININET_NETCONNECTION *connection, const struct sockaddr *serv_addr,
413 unsigned int addrlen);
414 BOOL NETCON_secure_connect(WININET_NETCONNECTION *connection, LPCWSTR hostname);
415 BOOL NETCON_send(WININET_NETCONNECTION *connection, const void *msg, size_t len, int flags,
416 int *sent /* out */);
417 BOOL NETCON_recv(WININET_NETCONNECTION *connection, void *buf, size_t len, int flags,
418 int *recvd /* out */);
419 BOOL NETCON_query_data_available(WININET_NETCONNECTION *connection, DWORD *available);
420 BOOL NETCON_getNextLine(WININET_NETCONNECTION *connection, LPSTR lpszBuffer, LPDWORD dwBuffer);
421 LPCVOID NETCON_GetCert(WININET_NETCONNECTION *connection);
422 DWORD NETCON_set_timeout(WININET_NETCONNECTION *connection, BOOL send, int value);
423
424 extern void URLCacheContainers_CreateDefaults(void);
425 extern void URLCacheContainers_DeleteAll(void);
426
427 #define MAX_REPLY_LEN 0x5B4
428
429 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
430 typedef struct
431 {
432 DWORD val;
433 const char* name;
434 } wininet_flag_info;
435
436 #endif /* _WINE_INTERNET_H_ */