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