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