ddraw: Added a todo_wine test for SetCooperativeLevel.
[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 } WININET_NETCONNECTION;
57
58 static inline LPWSTR heap_strdupW(LPCWSTR str)
59 {
60     LPWSTR ret = NULL;
61
62     if(str) {
63         DWORD size;
64
65         size = (strlenW(str)+1)*sizeof(WCHAR);
66         ret = HeapAlloc(GetProcessHeap(), 0, size);
67         if(ret)
68             memcpy(ret, str, size);
69     }
70
71     return ret;
72 }
73
74 static inline LPWSTR heap_strndupW(LPCWSTR str, UINT max_len)
75 {
76     LPWSTR ret;
77     UINT len;
78
79     if(!str)
80         return NULL;
81
82     for(len=0; len<max_len; len++)
83         if(str[len] == '\0')
84             break;
85
86     ret = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*(len+1));
87     if(ret) {
88         memcpy(ret, str, sizeof(WCHAR)*len);
89         ret[len] = '\0';
90     }
91
92     return ret;
93 }
94
95 static inline WCHAR *heap_strdupAtoW(const char *str)
96 {
97     LPWSTR ret = NULL;
98
99     if(str) {
100         DWORD len;
101
102         len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
103         ret = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
104         if(ret)
105             MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
106     }
107
108     return ret;
109 }
110
111 static inline char *heap_strdupWtoA(LPCWSTR str)
112 {
113     char *ret = NULL;
114
115     if(str) {
116         DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
117         ret = HeapAlloc(GetProcessHeap(), 0, size);
118         if(ret)
119             WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
120     }
121
122     return ret;
123 }
124
125 static inline void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW, LPWIN32_FIND_DATAA dataA)
126 {
127     dataA->dwFileAttributes = dataW->dwFileAttributes;
128     dataA->ftCreationTime   = dataW->ftCreationTime;
129     dataA->ftLastAccessTime = dataW->ftLastAccessTime;
130     dataA->ftLastWriteTime  = dataW->ftLastWriteTime;
131     dataA->nFileSizeHigh    = dataW->nFileSizeHigh;
132     dataA->nFileSizeLow     = dataW->nFileSizeLow;
133     dataA->dwReserved0      = dataW->dwReserved0;
134     dataA->dwReserved1      = dataW->dwReserved1;
135     WideCharToMultiByte(CP_ACP, 0, dataW->cFileName, -1, 
136         dataA->cFileName, sizeof(dataA->cFileName),
137         NULL, NULL);
138     WideCharToMultiByte(CP_ACP, 0, dataW->cAlternateFileName, -1, 
139         dataA->cAlternateFileName, sizeof(dataA->cAlternateFileName),
140         NULL, NULL);
141 }
142
143 typedef enum
144 {
145     WH_HINIT = INTERNET_HANDLE_TYPE_INTERNET,
146     WH_HFTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_FTP,
147     WH_HGOPHERSESSION = INTERNET_HANDLE_TYPE_CONNECT_GOPHER,
148     WH_HHTTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_HTTP,
149     WH_HFILE = INTERNET_HANDLE_TYPE_FTP_FILE,
150     WH_HFTPFINDNEXT = INTERNET_HANDLE_TYPE_FTP_FIND,
151     WH_HHTTPREQ = INTERNET_HANDLE_TYPE_HTTP_REQUEST,
152 } WH_TYPE;
153
154 #define INET_OPENURL 0x0001
155 #define INET_CALLBACKW 0x0002
156
157 typedef struct _object_header_t object_header_t;
158
159 typedef struct {
160     void (*Destroy)(object_header_t*);
161     void (*CloseConnection)(object_header_t*);
162     DWORD (*QueryOption)(object_header_t*,DWORD,void*,DWORD*,BOOL);
163     DWORD (*SetOption)(object_header_t*,DWORD,void*,DWORD);
164     DWORD (*ReadFile)(object_header_t*,void*,DWORD,DWORD*);
165     DWORD (*ReadFileExA)(object_header_t*,INTERNET_BUFFERSA*,DWORD,DWORD_PTR);
166     DWORD (*ReadFileExW)(object_header_t*,INTERNET_BUFFERSW*,DWORD,DWORD_PTR);
167     DWORD (*WriteFile)(object_header_t*,const void*,DWORD,DWORD*);
168     DWORD (*QueryDataAvailable)(object_header_t*,DWORD*,DWORD,DWORD_PTR);
169     DWORD (*FindNextFileW)(object_header_t*,void*);
170 } object_vtbl_t;
171
172 #define INTERNET_HANDLE_IN_USE 1
173
174 struct _object_header_t
175 {
176     WH_TYPE htype;
177     const object_vtbl_t *vtbl;
178     HINTERNET hInternet;
179     DWORD  dwFlags;
180     DWORD_PTR dwContext;
181     DWORD  dwError;
182     ULONG  ErrorMask;
183     DWORD  dwInternalFlags;
184     LONG   refs;
185     INTERNET_STATUS_CALLBACK lpfnStatusCB;
186     struct list entry;
187     struct list children;
188 };
189
190
191 typedef struct
192 {
193     object_header_t hdr;
194     LPWSTR  lpszAgent;
195     LPWSTR  lpszProxy;
196     LPWSTR  lpszProxyBypass;
197     LPWSTR  lpszProxyUsername;
198     LPWSTR  lpszProxyPassword;
199     DWORD   dwAccessType;
200 } appinfo_t;
201
202
203 typedef struct
204 {
205     object_header_t hdr;
206     appinfo_t *lpAppInfo;
207     LPWSTR  lpszHostName; /* the final destination of the request */
208     LPWSTR  lpszServerName; /* the name of the server we directly connect to */
209     LPWSTR  lpszUserName;
210     LPWSTR  lpszPassword;
211     INTERNET_PORT nHostPort; /* the final destination port of the request */
212     INTERNET_PORT nServerPort; /* the port of the server we directly connect to */
213     struct sockaddr_storage socketAddress;
214     socklen_t sa_len;
215 } http_session_t;
216
217 #define HDR_ISREQUEST           0x0001
218 #define HDR_COMMADELIMITED      0x0002
219 #define HDR_SEMIDELIMITED       0x0004
220
221 typedef struct
222 {
223     LPWSTR lpszField;
224     LPWSTR lpszValue;
225     WORD wFlags;
226     WORD wCount;
227 } HTTPHEADERW, *LPHTTPHEADERW;
228
229
230 struct HttpAuthInfo;
231
232 typedef struct gzip_stream_t gzip_stream_t;
233
234 typedef struct
235 {
236     object_header_t hdr;
237     http_session_t *lpHttpSession;
238     LPWSTR lpszPath;
239     LPWSTR lpszVerb;
240     LPWSTR lpszRawHeaders;
241     WININET_NETCONNECTION netConnection;
242     LPWSTR lpszVersion;
243     LPWSTR lpszStatusText;
244     DWORD dwBytesToWrite;
245     DWORD dwBytesWritten;
246     HTTPHEADERW *pCustHeaders;
247     DWORD nCustHeaders;
248     HANDLE hCacheFile;
249     LPWSTR lpszCacheFile;
250     struct HttpAuthInfo *pAuthInfo;
251     struct HttpAuthInfo *pProxyAuthInfo;
252
253     CRITICAL_SECTION read_section;  /* section to protect the following fields */
254     DWORD dwContentLength; /* total number of bytes to be read */
255     DWORD dwContentRead;  /* bytes of the content read so far */
256     BOOL  read_chunked;   /* are we reading in chunked mode? */
257     DWORD read_pos;       /* current read position in read_buf */
258     DWORD read_size;      /* valid data size in read_buf */
259     BYTE  read_buf[4096]; /* buffer for already read but not returned data */
260
261     BOOL decoding;
262     gzip_stream_t *gzip_stream;
263 } http_request_t;
264
265
266
267 struct WORKREQ_FTPPUTFILEW
268 {
269     LPWSTR lpszLocalFile;
270     LPWSTR lpszNewRemoteFile;
271     DWORD  dwFlags;
272     DWORD_PTR dwContext;
273 };
274
275 struct WORKREQ_FTPSETCURRENTDIRECTORYW
276 {
277     LPWSTR lpszDirectory;
278 };
279
280 struct WORKREQ_FTPCREATEDIRECTORYW
281 {
282     LPWSTR lpszDirectory;
283 };
284
285 struct WORKREQ_FTPFINDFIRSTFILEW
286 {
287     LPWSTR lpszSearchFile;
288     LPWIN32_FIND_DATAW lpFindFileData;
289     DWORD  dwFlags;
290     DWORD_PTR dwContext;
291 };
292
293 struct WORKREQ_FTPGETCURRENTDIRECTORYW
294 {
295     LPWSTR lpszDirectory;
296     DWORD *lpdwDirectory;
297 };
298
299 struct WORKREQ_FTPOPENFILEW
300 {
301     LPWSTR lpszFilename;
302     DWORD  dwAccess;
303     DWORD  dwFlags;
304     DWORD_PTR dwContext;
305 };
306
307 struct WORKREQ_FTPGETFILEW
308 {
309     LPWSTR lpszRemoteFile;
310     LPWSTR lpszNewFile;
311     BOOL   fFailIfExists;
312     DWORD  dwLocalFlagsAttribute;
313     DWORD  dwFlags;
314     DWORD_PTR dwContext;
315 };
316
317 struct WORKREQ_FTPDELETEFILEW
318 {
319     LPWSTR lpszFilename;
320 };
321
322 struct WORKREQ_FTPREMOVEDIRECTORYW
323 {
324     LPWSTR lpszDirectory;
325 };
326
327 struct WORKREQ_FTPRENAMEFILEW
328 {
329     LPWSTR lpszSrcFile;
330     LPWSTR lpszDestFile;
331 };
332
333 struct WORKREQ_FTPFINDNEXTW
334 {
335     LPWIN32_FIND_DATAW lpFindFileData;
336 };
337
338 struct WORKREQ_HTTPSENDREQUESTW
339 {
340     LPWSTR lpszHeader;
341     DWORD  dwHeaderLength;
342     LPVOID lpOptional;
343     DWORD  dwOptionalLength;
344     DWORD  dwContentLength;
345     BOOL   bEndRequest;
346 };
347
348 struct WORKREQ_HTTPENDREQUESTW
349 {
350     DWORD     dwFlags;
351     DWORD_PTR dwContext;
352 };
353
354 struct WORKREQ_SENDCALLBACK
355 {
356     DWORD_PTR 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_PTR dwContext;
370 };
371
372 struct WORKREQ_INTERNETREADFILEEXA
373 {
374     LPINTERNET_BUFFERSA lpBuffersOut;
375 };
376
377 struct WORKREQ_INTERNETREADFILEEXW
378 {
379     LPINTERNET_BUFFERSW lpBuffersOut;
380 };
381
382 typedef struct WORKREQ
383 {
384     void (*asyncproc)(struct WORKREQ*);
385     object_header_t *hdr;
386
387     union {
388         struct WORKREQ_FTPPUTFILEW              FtpPutFileW;
389         struct WORKREQ_FTPSETCURRENTDIRECTORYW  FtpSetCurrentDirectoryW;
390         struct WORKREQ_FTPCREATEDIRECTORYW      FtpCreateDirectoryW;
391         struct WORKREQ_FTPFINDFIRSTFILEW        FtpFindFirstFileW;
392         struct WORKREQ_FTPGETCURRENTDIRECTORYW  FtpGetCurrentDirectoryW;
393         struct WORKREQ_FTPOPENFILEW             FtpOpenFileW;
394         struct WORKREQ_FTPGETFILEW              FtpGetFileW;
395         struct WORKREQ_FTPDELETEFILEW           FtpDeleteFileW;
396         struct WORKREQ_FTPREMOVEDIRECTORYW      FtpRemoveDirectoryW;
397         struct WORKREQ_FTPRENAMEFILEW           FtpRenameFileW;
398         struct WORKREQ_FTPFINDNEXTW             FtpFindNextW;
399         struct WORKREQ_HTTPSENDREQUESTW         HttpSendRequestW;
400         struct WORKREQ_HTTPENDREQUESTW          HttpEndRequestW;
401         struct WORKREQ_SENDCALLBACK             SendCallback;
402         struct WORKREQ_INTERNETOPENURLW         InternetOpenUrlW;
403         struct WORKREQ_INTERNETREADFILEEXA      InternetReadFileExA;
404         struct WORKREQ_INTERNETREADFILEEXW      InternetReadFileExW;
405     } u;
406
407 } WORKREQUEST, *LPWORKREQUEST;
408
409 HINTERNET WININET_AllocHandle( object_header_t *info );
410 object_header_t *WININET_GetObject( HINTERNET hinternet );
411 object_header_t *WININET_AddRef( object_header_t *info );
412 BOOL WININET_Release( object_header_t *info );
413 BOOL WININET_FreeHandle( HINTERNET hinternet );
414
415 DWORD INET_QueryOption( object_header_t *, DWORD, void *, DWORD *, BOOL );
416
417 time_t ConvertTimeString(LPCWSTR asctime);
418
419 HINTERNET FTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName,
420         INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
421         LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
422         DWORD dwInternalFlags);
423
424 DWORD HTTP_Connect(appinfo_t*,LPCWSTR,
425         INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
426         LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
427         DWORD dwInternalFlags, HINTERNET*);
428
429 BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
430         struct sockaddr *psa, socklen_t *sa_len);
431
432 void INTERNET_SetLastError(DWORD dwError);
433 DWORD INTERNET_GetLastError(void);
434 DWORD INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest);
435 LPSTR INTERNET_GetResponseBuffer(void);
436 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen);
437
438 VOID SendAsyncCallback(object_header_t *hdr, DWORD_PTR dwContext,
439                        DWORD dwInternetStatus, LPVOID lpvStatusInfo,
440                        DWORD dwStatusInfoLength);
441
442 VOID INTERNET_SendCallback(object_header_t *hdr, DWORD_PTR dwContext,
443                            DWORD dwInternetStatus, LPVOID lpvStatusInfo,
444                            DWORD dwStatusInfoLength);
445 BOOL INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto, WCHAR *foundProxy, DWORD *foundProxyLen);
446
447 BOOL NETCON_connected(WININET_NETCONNECTION *connection);
448 DWORD NETCON_init(WININET_NETCONNECTION *connnection, BOOL useSSL);
449 void NETCON_unload(void);
450 DWORD NETCON_create(WININET_NETCONNECTION *connection, int domain,
451               int type, int protocol);
452 DWORD NETCON_close(WININET_NETCONNECTION *connection);
453 DWORD NETCON_connect(WININET_NETCONNECTION *connection, const struct sockaddr *serv_addr,
454                     unsigned int addrlen);
455 DWORD NETCON_secure_connect(WININET_NETCONNECTION *connection, LPWSTR hostname);
456 DWORD NETCON_send(WININET_NETCONNECTION *connection, const void *msg, size_t len, int flags,
457                 int *sent /* out */);
458 DWORD NETCON_recv(WININET_NETCONNECTION *connection, void *buf, size_t len, int flags,
459                 int *recvd /* out */);
460 BOOL NETCON_query_data_available(WININET_NETCONNECTION *connection, DWORD *available);
461 LPCVOID NETCON_GetCert(WININET_NETCONNECTION *connection);
462 DWORD NETCON_set_timeout(WININET_NETCONNECTION *connection, BOOL send, int value);
463 int sock_get_error(int);
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_ */