comctl32: We can now store binary files in the repository.
[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_function)( LPWININETHANDLEHEADER );
139
140 struct _WININETHANDLEHEADER
141 {
142     WH_TYPE htype;
143     HINTERNET hInternet;
144     DWORD  dwFlags;
145     DWORD_PTR dwContext;
146     DWORD  dwError;
147     DWORD  dwInternalFlags;
148     DWORD  dwRefCount;
149     WININET_object_function close_connection;
150     WININET_object_function destroy;
151     INTERNET_STATUS_CALLBACK lpfnStatusCB;
152 };
153
154
155 typedef struct
156 {
157     WININETHANDLEHEADER hdr;
158     LPWSTR  lpszAgent;
159     LPWSTR  lpszProxy;
160     LPWSTR  lpszProxyBypass;
161     LPWSTR  lpszProxyUsername;
162     LPWSTR  lpszProxyPassword;
163     DWORD   dwAccessType;
164 } WININETAPPINFOW, *LPWININETAPPINFOW;
165
166
167 typedef struct
168 {
169     WININETHANDLEHEADER hdr;
170     WININETAPPINFOW *lpAppInfo;
171     LPWSTR  lpszHostName; /* the final destination of the request */
172     LPWSTR  lpszServerName; /* the name of the server we directly connect to */
173     LPWSTR  lpszUserName;
174     LPWSTR  lpszPassword;
175     INTERNET_PORT nHostPort; /* the final destination port of the request */
176     INTERNET_PORT nServerPort; /* the port of the server we directly connect to */
177     struct sockaddr_in socketAddress;
178 } WININETHTTPSESSIONW, *LPWININETHTTPSESSIONW;
179
180 #define HDR_ISREQUEST           0x0001
181 #define HDR_COMMADELIMITED      0x0002
182 #define HDR_SEMIDELIMITED       0x0004
183
184 typedef struct
185 {
186     LPWSTR lpszField;
187     LPWSTR lpszValue;
188     WORD wFlags;
189     WORD wCount;
190 } HTTPHEADERW, *LPHTTPHEADERW;
191
192
193 struct HttpAuthInfo;
194
195 typedef struct
196 {
197     WININETHANDLEHEADER hdr;
198     WININETHTTPSESSIONW *lpHttpSession;
199     LPWSTR lpszPath;
200     LPWSTR lpszVerb;
201     LPWSTR lpszRawHeaders;
202     WININET_NETCONNECTION netConnection;
203     LPWSTR lpszVersion;
204     LPWSTR lpszStatusText;
205     DWORD dwContentLength; /* total number of bytes to be read */
206     DWORD dwContentRead; /* bytes of the content read so far */
207     HTTPHEADERW *pCustHeaders;
208     DWORD nCustHeaders;
209     struct HttpAuthInfo *pAuthInfo;
210     struct HttpAuthInfo *pProxyAuthInfo;
211 } WININETHTTPREQW, *LPWININETHTTPREQW;
212
213
214 struct _WININETFTPSESSIONW;
215
216 typedef struct
217 {
218     WININETHANDLEHEADER hdr;
219     struct _WININETFTPSESSIONW *lpFtpSession;
220     BOOL session_deleted;
221     int nDataSocket;
222 } WININETFTPFILE, *LPWININETFTPFILE;
223
224
225 typedef struct _WININETFTPSESSIONW
226 {
227     WININETHANDLEHEADER hdr;
228     WININETAPPINFOW *lpAppInfo;
229     int sndSocket;
230     int lstnSocket;
231     int pasvSocket; /* data socket connected by us in case of passive FTP */
232     LPWININETFTPFILE download_in_progress;
233     struct sockaddr_in socketAddress;
234     struct sockaddr_in lstnSocketAddress;
235     LPWSTR  lpszPassword;
236     LPWSTR  lpszUserName;
237 } WININETFTPSESSIONW, *LPWININETFTPSESSIONW;
238
239
240 typedef struct
241 {
242     BOOL bIsDirectory;
243     LPWSTR lpszName;
244     DWORD nSize;
245     struct tm tmLastModified;
246     unsigned short permissions;
247 } FILEPROPERTIESW, *LPFILEPROPERTIESW;
248
249
250 typedef struct
251 {
252     WININETHANDLEHEADER hdr;
253     WININETFTPSESSIONW *lpFtpSession;
254     DWORD index;
255     DWORD size;
256     LPFILEPROPERTIESW lpafp;
257 } WININETFTPFINDNEXTW, *LPWININETFTPFINDNEXTW;
258
259 struct WORKREQ_FTPPUTFILEW
260 {
261     LPWSTR lpszLocalFile;
262     LPWSTR lpszNewRemoteFile;
263     DWORD  dwFlags;
264     DWORD_PTR dwContext;
265 };
266
267 struct WORKREQ_FTPSETCURRENTDIRECTORYW
268 {
269     LPWSTR lpszDirectory;
270 };
271
272 struct WORKREQ_FTPCREATEDIRECTORYW
273 {
274     LPWSTR lpszDirectory;
275 };
276
277 struct WORKREQ_FTPFINDFIRSTFILEW
278 {
279     LPWSTR lpszSearchFile;
280     LPWIN32_FIND_DATAW lpFindFileData;
281     DWORD  dwFlags;
282     DWORD_PTR dwContext;
283 };
284
285 struct WORKREQ_FTPGETCURRENTDIRECTORYW
286 {
287     LPWSTR lpszDirectory;
288     DWORD *lpdwDirectory;
289 };
290
291 struct WORKREQ_FTPOPENFILEW
292 {
293     LPWSTR lpszFilename;
294     DWORD  dwAccess;
295     DWORD  dwFlags;
296     DWORD_PTR dwContext;
297 };
298
299 struct WORKREQ_FTPGETFILEW
300 {
301     LPWSTR lpszRemoteFile;
302     LPWSTR lpszNewFile;
303     BOOL   fFailIfExists;
304     DWORD  dwLocalFlagsAttribute;
305     DWORD  dwFlags;
306     DWORD_PTR dwContext;
307 };
308
309 struct WORKREQ_FTPDELETEFILEW
310 {
311     LPWSTR lpszFilename;
312 };
313
314 struct WORKREQ_FTPREMOVEDIRECTORYW
315 {
316     LPWSTR lpszDirectory;
317 };
318
319 struct WORKREQ_FTPRENAMEFILEW
320 {
321     LPWSTR lpszSrcFile;
322     LPWSTR lpszDestFile;
323 };
324
325 struct WORKREQ_FTPFINDNEXTW
326 {
327     LPWIN32_FIND_DATAW lpFindFileData;
328 };
329
330 struct WORKREQ_HTTPSENDREQUESTW
331 {
332     LPWSTR lpszHeader;
333     DWORD  dwHeaderLength;
334     LPVOID lpOptional;
335     DWORD  dwOptionalLength;
336     DWORD  dwContentLength;
337     BOOL   bEndRequest;
338 };
339
340 struct WORKREQ_SENDCALLBACK
341 {
342     DWORD_PTR dwContext;
343     DWORD     dwInternetStatus;
344     LPVOID    lpvStatusInfo;
345     DWORD     dwStatusInfoLength;
346 };
347
348 struct WORKREQ_INTERNETOPENURLW
349 {
350     HINTERNET hInternet;
351     LPWSTR     lpszUrl;
352     LPWSTR     lpszHeaders;
353     DWORD     dwHeadersLength;
354     DWORD     dwFlags;
355     DWORD_PTR dwContext;
356 };
357
358 struct WORKREQ_INTERNETREADFILEEXA
359 {
360     LPINTERNET_BUFFERSA lpBuffersOut;
361 };
362
363 typedef struct WORKREQ
364 {
365     void (*asyncproc)(struct WORKREQ*);
366     WININETHANDLEHEADER *hdr;
367
368     union {
369         struct WORKREQ_FTPPUTFILEW              FtpPutFileW;
370         struct WORKREQ_FTPSETCURRENTDIRECTORYW  FtpSetCurrentDirectoryW;
371         struct WORKREQ_FTPCREATEDIRECTORYW      FtpCreateDirectoryW;
372         struct WORKREQ_FTPFINDFIRSTFILEW        FtpFindFirstFileW;
373         struct WORKREQ_FTPGETCURRENTDIRECTORYW  FtpGetCurrentDirectoryW;
374         struct WORKREQ_FTPOPENFILEW             FtpOpenFileW;
375         struct WORKREQ_FTPGETFILEW              FtpGetFileW;
376         struct WORKREQ_FTPDELETEFILEW           FtpDeleteFileW;
377         struct WORKREQ_FTPREMOVEDIRECTORYW      FtpRemoveDirectoryW;
378         struct WORKREQ_FTPRENAMEFILEW           FtpRenameFileW;
379         struct WORKREQ_FTPFINDNEXTW             FtpFindNextW;
380         struct WORKREQ_HTTPSENDREQUESTW         HttpSendRequestW;
381         struct WORKREQ_SENDCALLBACK             SendCallback;
382         struct WORKREQ_INTERNETOPENURLW         InternetOpenUrlW;
383         struct WORKREQ_INTERNETREADFILEEXA      InternetReadFileExA;
384     } u;
385
386 } WORKREQUEST, *LPWORKREQUEST;
387
388 HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info );
389 LPWININETHANDLEHEADER WININET_GetObject( HINTERNET hinternet );
390 LPWININETHANDLEHEADER WININET_AddRef( LPWININETHANDLEHEADER info );
391 BOOL WININET_Release( LPWININETHANDLEHEADER info );
392 BOOL WININET_FreeHandle( HINTERNET hinternet );
393
394 time_t ConvertTimeString(LPCWSTR asctime);
395
396 HINTERNET FTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
397         INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
398         LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
399         DWORD dwInternalFlags);
400
401 HINTERNET HTTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
402         INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
403         LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
404         DWORD dwInternalFlags);
405
406 BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
407         struct sockaddr_in *psa);
408
409 void INTERNET_SetLastError(DWORD dwError);
410 DWORD INTERNET_GetLastError(void);
411 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest);
412 LPSTR INTERNET_GetResponseBuffer(void);
413 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen);
414 BOOL INTERNET_ReadFile(LPWININETHANDLEHEADER lpwh, LPVOID lpBuffer,
415                        DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead,
416                        BOOL bWait, BOOL bSendCompletionStatus);
417
418 BOOLAPI FTP_FtpPutFileW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszLocalFile,
419     LPCWSTR lpszNewRemoteFile, DWORD dwFlags, DWORD_PTR dwContext);
420 BOOLAPI FTP_FtpSetCurrentDirectoryW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszDirectory);
421 BOOLAPI FTP_FtpCreateDirectoryW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszDirectory);
422 INTERNETAPI HINTERNET WINAPI FTP_FtpFindFirstFileW(LPWININETFTPSESSIONW lpwfs,
423     LPCWSTR lpszSearchFile, LPWIN32_FIND_DATAW lpFindFileData, DWORD dwFlags, DWORD_PTR dwContext);
424 BOOL WINAPI FTP_FindNextFileW(LPWININETFTPFINDNEXTW lpwh, LPVOID lpvFindData);
425 BOOLAPI FTP_FtpGetCurrentDirectoryW(LPWININETFTPSESSIONW lpwfs, LPWSTR lpszCurrentDirectory,
426         LPDWORD lpdwCurrentDirectory);
427 BOOL FTP_ConvertFileProp(LPFILEPROPERTIESW lpafp, LPWIN32_FIND_DATAW lpFindFileData);
428 BOOL FTP_FtpRenameFileW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszSrc, LPCWSTR lpszDest);
429 BOOL FTP_FtpRemoveDirectoryW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszDirectory);
430 BOOL FTP_FtpDeleteFileW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszFileName);
431 HINTERNET FTP_FtpOpenFileW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszFileName,
432         DWORD fdwAccess, DWORD dwFlags, DWORD_PTR dwContext);
433 BOOLAPI FTP_FtpGetFileW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszRemoteFile, LPCWSTR lpszNewFile,
434         BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags,
435         DWORD_PTR dwContext);
436
437 BOOLAPI HTTP_HttpSendRequestW(LPWININETHTTPREQW lpwhr, LPCWSTR lpszHeaders,
438         DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength,
439         DWORD dwContentLength, BOOL bEndRequest);
440 INTERNETAPI HINTERNET WINAPI HTTP_HttpOpenRequestW(LPWININETHTTPSESSIONW lpwhs,
441         LPCWSTR lpszVerb, LPCWSTR lpszObjectName, LPCWSTR lpszVersion,
442         LPCWSTR lpszReferrer , LPCWSTR *lpszAcceptTypes,
443         DWORD dwFlags, DWORD_PTR dwContext);
444 BOOL HTTP_FinishedReading(LPWININETHTTPREQW lpwhr);
445
446 VOID SendAsyncCallback(LPWININETHANDLEHEADER hdr, DWORD_PTR dwContext,
447                        DWORD dwInternetStatus, LPVOID lpvStatusInfo,
448                        DWORD dwStatusInfoLength);
449
450 VOID INTERNET_SendCallback(LPWININETHANDLEHEADER hdr, DWORD_PTR dwContext,
451                            DWORD dwInternetStatus, LPVOID lpvStatusInfo,
452                            DWORD dwStatusInfoLength);
453
454 LPHTTPHEADERW HTTP_GetHeader(LPWININETHTTPREQW lpwhr, LPCWSTR header);
455
456 BOOL NETCON_connected(WININET_NETCONNECTION *connection);
457 BOOL NETCON_init(WININET_NETCONNECTION *connnection, BOOL useSSL);
458 BOOL NETCON_create(WININET_NETCONNECTION *connection, int domain,
459               int type, int protocol);
460 BOOL NETCON_close(WININET_NETCONNECTION *connection);
461 BOOL NETCON_connect(WININET_NETCONNECTION *connection, const struct sockaddr *serv_addr,
462                     unsigned int addrlen);
463 BOOL NETCON_secure_connect(WININET_NETCONNECTION *connection, LPCWSTR hostname);
464 BOOL NETCON_send(WININET_NETCONNECTION *connection, const void *msg, size_t len, int flags,
465                 int *sent /* out */);
466 BOOL NETCON_recv(WININET_NETCONNECTION *connection, void *buf, size_t len, int flags,
467                 int *recvd /* out */);
468 BOOL NETCON_query_data_available(WININET_NETCONNECTION *connection, DWORD *available);
469 BOOL NETCON_getNextLine(WININET_NETCONNECTION *connection, LPSTR lpszBuffer, LPDWORD dwBuffer);
470 LPCVOID NETCON_GetCert(WININET_NETCONNECTION *connection);
471 BOOL NETCON_set_timeout(WININET_NETCONNECTION *connection, BOOL send, int value);
472
473 extern void URLCacheContainers_CreateDefaults(void);
474 extern void URLCacheContainers_DeleteAll(void);
475
476 #define MAX_REPLY_LEN           0x5B4
477
478 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
479 typedef struct
480 {
481     DWORD val;
482     const char* name;
483 } wininet_flag_info;
484
485 #endif /* _WINE_INTERNET_H_ */