user32: Simplify some maximized MDI child checks.
[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 #include "wine/unicode.h"
27
28 #include <time.h>
29 #ifdef HAVE_NETDB_H
30 # include <netdb.h>
31 #endif
32 #ifdef HAVE_NETINET_IN_H
33 # include <sys/types.h>
34 # include <netinet/in.h>
35 #endif
36 #ifdef HAVE_OPENSSL_SSL_H
37 #define DSA __ssl_DSA  /* avoid conflict with commctrl.h */
38 #undef FAR
39 # include <openssl/ssl.h>
40 #undef FAR
41 #define FAR do_not_use_this_in_wine
42 #undef DSA
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 "winsock2.h"
50 #ifndef MSG_WAITALL
51 #define MSG_WAITALL 0
52 #endif
53 #else
54 #define closesocket close
55 #endif /* __MINGW32__ */
56
57 /* used for netconnection.c stuff */
58 typedef struct
59 {
60     BOOL useSSL;
61     int socketFD;
62 #ifdef HAVE_OPENSSL_SSL_H
63     SSL *ssl_s;
64     char *peek_msg;
65     char *peek_msg_mem;
66     size_t peek_len;
67 #endif
68 } WININET_NETCONNECTION;
69
70 inline static LPSTR WININET_strdup( LPCSTR str )
71 {
72     LPSTR ret = HeapAlloc( GetProcessHeap(), 0, strlen(str) + 1 );
73     if (ret) strcpy( ret, str );
74     return ret;
75 }
76
77 inline static LPWSTR WININET_strdupW( LPCWSTR str )
78 {
79     LPWSTR ret = HeapAlloc( GetProcessHeap(), 0, (strlenW(str) + 1)*sizeof(WCHAR) );
80     if (ret) strcpyW( ret, str );
81     return ret;
82 }
83
84 inline static LPWSTR WININET_strdup_AtoW( LPCSTR str )
85 {
86     int len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0);
87     LPWSTR ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
88     if (ret)
89         MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len);
90     return ret;
91 }
92
93 inline static LPSTR WININET_strdup_WtoA( LPCWSTR str )
94 {
95     int len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
96     LPSTR ret = HeapAlloc( GetProcessHeap(), 0, len );
97     if (ret)
98         WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL);
99     return ret;
100 }
101
102 inline static void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW, LPWIN32_FIND_DATAA dataA)
103 {
104     dataA->dwFileAttributes = dataW->dwFileAttributes;
105     dataA->ftCreationTime   = dataW->ftCreationTime;
106     dataA->ftLastAccessTime = dataW->ftLastAccessTime;
107     dataA->ftLastWriteTime  = dataW->ftLastWriteTime;
108     dataA->nFileSizeHigh    = dataW->nFileSizeHigh;
109     dataA->nFileSizeLow     = dataW->nFileSizeLow;
110     dataA->dwReserved0      = dataW->dwReserved0;
111     dataA->dwReserved1      = dataW->dwReserved1;
112     WideCharToMultiByte(CP_ACP, 0, dataW->cFileName, -1, 
113         dataA->cFileName, sizeof(dataA->cFileName),
114         NULL, NULL);
115     WideCharToMultiByte(CP_ACP, 0, dataW->cAlternateFileName, -1, 
116         dataA->cAlternateFileName, sizeof(dataA->cAlternateFileName),
117         NULL, NULL);
118 }
119
120 typedef enum
121 {
122     WH_HINIT = INTERNET_HANDLE_TYPE_INTERNET,
123     WH_HFTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_FTP,
124     WH_HGOPHERSESSION = INTERNET_HANDLE_TYPE_CONNECT_GOPHER,
125     WH_HHTTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_HTTP,
126     WH_HFILE = INTERNET_HANDLE_TYPE_FTP_FILE,
127     WH_HFTPFINDNEXT = INTERNET_HANDLE_TYPE_FTP_FIND,
128     WH_HHTTPREQ = INTERNET_HANDLE_TYPE_HTTP_REQUEST,
129 } WH_TYPE;
130
131 #define INET_OPENURL 0x0001
132 #define INET_CALLBACKW 0x0002
133
134 struct _WININETHANDLEHEADER;
135 typedef struct _WININETHANDLEHEADER WININETHANDLEHEADER, *LPWININETHANDLEHEADER;
136
137 typedef void (*WININET_object_destructor)( LPWININETHANDLEHEADER );
138
139 struct _WININETHANDLEHEADER
140 {
141     WH_TYPE htype;
142     HINTERNET hInternet;
143     DWORD  dwFlags;
144     DWORD  dwContext;
145     DWORD  dwError;
146     DWORD  dwInternalFlags;
147     DWORD  dwRefCount;
148     WININET_object_destructor destroy;
149     INTERNET_STATUS_CALLBACK lpfnStatusCB;
150 };
151
152
153 typedef struct
154 {
155     WININETHANDLEHEADER hdr;
156     LPWSTR  lpszAgent;
157     LPWSTR  lpszProxy;
158     LPWSTR  lpszProxyBypass;
159     LPWSTR  lpszProxyUsername;
160     LPWSTR  lpszProxyPassword;
161     DWORD   dwAccessType;
162 } WININETAPPINFOW, *LPWININETAPPINFOW;
163
164
165 typedef struct
166 {
167     WININETHANDLEHEADER hdr;
168     WININETAPPINFOW *lpAppInfo;
169     LPWSTR  lpszHostName; /* the final destination of the request */
170     LPWSTR  lpszServerName; /* the name of the server we directly connect to */
171     LPWSTR  lpszUserName;
172     INTERNET_PORT nHostPort; /* the final destination port of the request */
173     INTERNET_PORT nServerPort; /* the port of the server we directly connect to */
174     struct sockaddr_in socketAddress;
175 } WININETHTTPSESSIONW, *LPWININETHTTPSESSIONW;
176
177 #define HDR_ISREQUEST           0x0001
178 #define HDR_COMMADELIMITED      0x0002
179 #define HDR_SEMIDELIMITED       0x0004
180
181 typedef struct
182 {
183     LPWSTR lpszField;
184     LPWSTR lpszValue;
185     WORD wFlags;
186     WORD wCount;
187 } HTTPHEADERW, *LPHTTPHEADERW;
188
189
190 typedef struct
191 {
192     WININETHANDLEHEADER hdr;
193     WININETHTTPSESSIONW *lpHttpSession;
194     LPWSTR lpszPath;
195     LPWSTR lpszVerb;
196     LPWSTR lpszRawHeaders;
197     WININET_NETCONNECTION netConnection;
198     LPWSTR lpszVersion;
199     LPWSTR lpszStatusText;
200     DWORD dwContentLength; /* total number of bytes to be read */
201     DWORD dwContentRead; /* bytes of the content read so far */
202     HTTPHEADERW *pCustHeaders;
203     DWORD nCustHeaders;
204 } WININETHTTPREQW, *LPWININETHTTPREQW;
205
206
207 struct _WININETFTPSESSIONW;
208
209 typedef struct
210 {
211     WININETHANDLEHEADER hdr;
212     struct _WININETFTPSESSIONW *lpFtpSession;
213     BOOL session_deleted;
214     int nDataSocket;
215 } WININETFTPFILE, *LPWININETFTPFILE;
216
217
218 typedef struct _WININETFTPSESSIONW
219 {
220     WININETHANDLEHEADER hdr;
221     WININETAPPINFOW *lpAppInfo;
222     int sndSocket;
223     int lstnSocket;
224     int pasvSocket; /* data socket connected by us in case of passive FTP */
225     LPWININETFTPFILE download_in_progress;
226     struct sockaddr_in socketAddress;
227     struct sockaddr_in lstnSocketAddress;
228     LPWSTR  lpszPassword;
229     LPWSTR  lpszUserName;
230 } WININETFTPSESSIONW, *LPWININETFTPSESSIONW;
231
232
233 typedef struct
234 {
235     BOOL bIsDirectory;
236     LPWSTR lpszName;
237     DWORD nSize;
238     struct tm tmLastModified;
239     unsigned short permissions;
240 } FILEPROPERTIESW, *LPFILEPROPERTIESW;
241
242
243 typedef struct
244 {
245     WININETHANDLEHEADER hdr;
246     WININETFTPSESSIONW *lpFtpSession;
247     DWORD index;
248     DWORD size;
249     LPFILEPROPERTIESW lpafp;
250 } WININETFTPFINDNEXTW, *LPWININETFTPFINDNEXTW;
251
252 struct WORKREQ_FTPPUTFILEW
253 {
254     LPWSTR lpszLocalFile;
255     LPWSTR lpszNewRemoteFile;
256     DWORD  dwFlags;
257     DWORD  dwContext;
258 };
259
260 struct WORKREQ_FTPSETCURRENTDIRECTORYW
261 {
262     LPWSTR lpszDirectory;
263 };
264
265 struct WORKREQ_FTPCREATEDIRECTORYW
266 {
267     LPWSTR lpszDirectory;
268 };
269
270 struct WORKREQ_FTPFINDFIRSTFILEW
271 {
272     LPWSTR lpszSearchFile;
273     LPWIN32_FIND_DATAW lpFindFileData;
274     DWORD  dwFlags;
275     DWORD  dwContext;
276 };
277
278 struct WORKREQ_FTPGETCURRENTDIRECTORYW
279 {
280     LPWSTR lpszDirectory;
281     DWORD *lpdwDirectory;
282 };
283
284 struct WORKREQ_FTPOPENFILEW
285 {
286     LPWSTR lpszFilename;
287     DWORD  dwAccess;
288     DWORD  dwFlags;
289     DWORD  dwContext;
290 };
291
292 struct WORKREQ_FTPGETFILEW
293 {
294     LPWSTR lpszRemoteFile;
295     LPWSTR lpszNewFile;
296     BOOL   fFailIfExists;
297     DWORD  dwLocalFlagsAttribute;
298     DWORD  dwFlags;
299     DWORD  dwContext;
300 };
301
302 struct WORKREQ_FTPDELETEFILEW
303 {
304     LPWSTR lpszFilename;
305 };
306
307 struct WORKREQ_FTPREMOVEDIRECTORYW
308 {
309     LPWSTR lpszDirectory;
310 };
311
312 struct WORKREQ_FTPRENAMEFILEW
313 {
314     LPWSTR lpszSrcFile;
315     LPWSTR lpszDestFile;
316 };
317
318 struct WORKREQ_FTPFINDNEXTW
319 {
320     LPWIN32_FIND_DATAW lpFindFileData;
321 };
322
323 struct WORKREQ_HTTPSENDREQUESTW
324 {
325     LPWSTR lpszHeader;
326     DWORD  dwHeaderLength;
327     LPVOID lpOptional;
328     DWORD  dwOptionalLength;
329     DWORD  dwContentLength;
330     BOOL   bEndRequest;
331 };
332
333 struct WORKREQ_SENDCALLBACK
334 {
335     DWORD     dwContext;
336     DWORD     dwInternetStatus;
337     LPVOID    lpvStatusInfo;
338     DWORD     dwStatusInfoLength;
339 };
340
341 struct WORKREQ_INTERNETOPENURLW
342 {
343     HINTERNET hInternet;
344     LPWSTR     lpszUrl;
345     LPWSTR     lpszHeaders;
346     DWORD     dwHeadersLength;
347     DWORD     dwFlags;
348     DWORD     dwContext;
349 };
350
351 struct WORKREQ_INTERNETREADFILEEXA
352 {
353     LPINTERNET_BUFFERSA lpBuffersOut;
354 };
355
356 typedef struct WORKREQ
357 {
358     void (*asyncproc)(struct WORKREQ*);
359     WININETHANDLEHEADER *hdr;
360
361     union {
362         struct WORKREQ_FTPPUTFILEW              FtpPutFileW;
363         struct WORKREQ_FTPSETCURRENTDIRECTORYW  FtpSetCurrentDirectoryW;
364         struct WORKREQ_FTPCREATEDIRECTORYW      FtpCreateDirectoryW;
365         struct WORKREQ_FTPFINDFIRSTFILEW        FtpFindFirstFileW;
366         struct WORKREQ_FTPGETCURRENTDIRECTORYW  FtpGetCurrentDirectoryW;
367         struct WORKREQ_FTPOPENFILEW             FtpOpenFileW;
368         struct WORKREQ_FTPGETFILEW              FtpGetFileW;
369         struct WORKREQ_FTPDELETEFILEW           FtpDeleteFileW;
370         struct WORKREQ_FTPREMOVEDIRECTORYW      FtpRemoveDirectoryW;
371         struct WORKREQ_FTPRENAMEFILEW           FtpRenameFileW;
372         struct WORKREQ_FTPFINDNEXTW             FtpFindNextW;
373         struct WORKREQ_HTTPSENDREQUESTW         HttpSendRequestW;
374         struct WORKREQ_SENDCALLBACK             SendCallback;
375         struct WORKREQ_INTERNETOPENURLW         InternetOpenUrlW;
376         struct WORKREQ_INTERNETREADFILEEXA      InternetReadFileExA;
377     } u;
378
379 } WORKREQUEST, *LPWORKREQUEST;
380
381 HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info );
382 LPWININETHANDLEHEADER WININET_GetObject( HINTERNET hinternet );
383 LPWININETHANDLEHEADER WININET_AddRef( LPWININETHANDLEHEADER info );
384 BOOL WININET_Release( LPWININETHANDLEHEADER info );
385 BOOL WININET_FreeHandle( HINTERNET hinternet );
386
387 time_t ConvertTimeString(LPCWSTR asctime);
388
389 HINTERNET FTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
390         INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
391         LPCWSTR lpszPassword, DWORD dwFlags, DWORD dwContext,
392         DWORD dwInternalFlags);
393
394 HINTERNET HTTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
395         INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
396         LPCWSTR lpszPassword, DWORD dwFlags, DWORD dwContext,
397         DWORD dwInternalFlags);
398
399 BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
400         struct sockaddr_in *psa);
401
402 void INTERNET_SetLastError(DWORD dwError);
403 DWORD INTERNET_GetLastError(void);
404 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest);
405 LPSTR INTERNET_GetResponseBuffer(void);
406 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen);
407 BOOL INTERNET_ReadFile(LPWININETHANDLEHEADER lpwh, LPVOID lpBuffer,
408                        DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead,
409                        BOOL bWait, BOOL bSendCompletionStatus);
410
411 BOOLAPI FTP_FtpPutFileW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszLocalFile,
412     LPCWSTR lpszNewRemoteFile, DWORD dwFlags, DWORD dwContext);
413 BOOLAPI FTP_FtpSetCurrentDirectoryW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszDirectory);
414 BOOLAPI FTP_FtpCreateDirectoryW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszDirectory);
415 INTERNETAPI HINTERNET WINAPI FTP_FtpFindFirstFileW(LPWININETFTPSESSIONW lpwfs,
416     LPCWSTR lpszSearchFile, LPWIN32_FIND_DATAW lpFindFileData, DWORD dwFlags, DWORD dwContext);
417 BOOL WINAPI FTP_FindNextFileW(LPWININETFTPFINDNEXTW lpwh, LPVOID lpvFindData);
418 BOOLAPI FTP_FtpGetCurrentDirectoryW(LPWININETFTPSESSIONW lpwfs, LPWSTR lpszCurrentDirectory,
419         LPDWORD lpdwCurrentDirectory);
420 BOOL FTP_ConvertFileProp(LPFILEPROPERTIESW lpafp, LPWIN32_FIND_DATAW lpFindFileData);
421 BOOL FTP_FtpRenameFileW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszSrc, LPCWSTR lpszDest);
422 BOOL FTP_FtpRemoveDirectoryW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszDirectory);
423 BOOL FTP_FtpDeleteFileW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszFileName);
424 HINTERNET FTP_FtpOpenFileW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszFileName,
425         DWORD fdwAccess, DWORD dwFlags, DWORD dwContext);
426 BOOLAPI FTP_FtpGetFileW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszRemoteFile, LPCWSTR lpszNewFile,
427         BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags,
428         DWORD dwContext);
429
430 BOOLAPI HTTP_HttpSendRequestW(LPWININETHTTPREQW lpwhr, LPCWSTR lpszHeaders,
431         DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength,
432         DWORD dwContentLength, BOOL bEndRequest);
433 INTERNETAPI HINTERNET WINAPI HTTP_HttpOpenRequestW(LPWININETHTTPSESSIONW lpwhs,
434         LPCWSTR lpszVerb, LPCWSTR lpszObjectName, LPCWSTR lpszVersion,
435         LPCWSTR lpszReferrer , LPCWSTR *lpszAcceptTypes,
436         DWORD dwFlags, DWORD dwContext);
437 BOOL HTTP_FinishedReading(LPWININETHTTPREQW lpwhr);
438
439 VOID SendAsyncCallback(LPWININETHANDLEHEADER hdr, DWORD dwContext,
440                        DWORD dwInternetStatus, LPVOID lpvStatusInfo,
441                        DWORD dwStatusInfoLength);
442
443 VOID INTERNET_SendCallback(LPWININETHANDLEHEADER hdr, DWORD dwContext,
444                            DWORD dwInternetStatus, LPVOID lpvStatusInfo,
445                            DWORD dwStatusInfoLength);
446
447 LPHTTPHEADERW HTTP_GetHeader(LPWININETHTTPREQW lpwhr, LPCWSTR header);
448
449 BOOL NETCON_connected(WININET_NETCONNECTION *connection);
450 BOOL NETCON_init(WININET_NETCONNECTION *connnection, BOOL useSSL);
451 BOOL NETCON_create(WININET_NETCONNECTION *connection, int domain,
452               int type, int protocol);
453 BOOL NETCON_close(WININET_NETCONNECTION *connection);
454 BOOL NETCON_connect(WININET_NETCONNECTION *connection, const struct sockaddr *serv_addr,
455                     unsigned int addrlen);
456 BOOL NETCON_secure_connect(WININET_NETCONNECTION *connection, LPCWSTR hostname);
457 BOOL NETCON_send(WININET_NETCONNECTION *connection, const void *msg, size_t len, int flags,
458                 int *sent /* out */);
459 BOOL NETCON_recv(WININET_NETCONNECTION *connection, void *buf, size_t len, int flags,
460                 int *recvd /* out */);
461 BOOL NETCON_getNextLine(WININET_NETCONNECTION *connection, LPSTR lpszBuffer, LPDWORD dwBuffer);
462 LPCVOID NETCON_GetCert(WININET_NETCONNECTION *connection);
463 BOOL NETCON_set_timeout(WININET_NETCONNECTION *connection, BOOL send, int value);
464
465 extern void URLCacheContainers_CreateDefaults(void);
466 extern void URLCacheContainers_DeleteAll(void);
467
468 #define MAX_REPLY_LEN           0x5B4
469
470 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
471 typedef struct
472 {
473     DWORD val;
474     const char* name;
475 } wininet_flag_info;
476
477 #endif /* _WINE_INTERNET_H_ */