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