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