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