mmdevapi/tests: Add tests for IAudioClient::GetCurrentPadding.
[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 extern HMODULE WININET_hModule;
51
52 /* used for netconnection.c stuff */
53 typedef struct
54 {
55     BOOL useSSL;
56     int socketFD;
57     void *ssl_s;
58     DWORD security_flags;
59 } WININET_NETCONNECTION;
60
61 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t len)
62 {
63     return HeapAlloc(GetProcessHeap(), 0, len);
64 }
65
66 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len)
67 {
68     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
69 }
70
71 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t len)
72 {
73     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
74 }
75
76 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem, size_t len)
77 {
78     return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
79 }
80
81 static inline BOOL heap_free(void *mem)
82 {
83     return HeapFree(GetProcessHeap(), 0, mem);
84 }
85
86 static inline LPWSTR heap_strdupW(LPCWSTR str)
87 {
88     LPWSTR ret = NULL;
89
90     if(str) {
91         DWORD size;
92
93         size = (strlenW(str)+1)*sizeof(WCHAR);
94         ret = heap_alloc(size);
95         if(ret)
96             memcpy(ret, str, size);
97     }
98
99     return ret;
100 }
101
102 static inline LPWSTR heap_strndupW(LPCWSTR str, UINT max_len)
103 {
104     LPWSTR ret;
105     UINT len;
106
107     if(!str)
108         return NULL;
109
110     for(len=0; len<max_len; len++)
111         if(str[len] == '\0')
112             break;
113
114     ret = heap_alloc(sizeof(WCHAR)*(len+1));
115     if(ret) {
116         memcpy(ret, str, sizeof(WCHAR)*len);
117         ret[len] = '\0';
118     }
119
120     return ret;
121 }
122
123 static inline WCHAR *heap_strdupAtoW(const char *str)
124 {
125     LPWSTR ret = NULL;
126
127     if(str) {
128         DWORD len;
129
130         len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
131         ret = heap_alloc(len*sizeof(WCHAR));
132         if(ret)
133             MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
134     }
135
136     return ret;
137 }
138
139 static inline char *heap_strdupWtoA(LPCWSTR str)
140 {
141     char *ret = NULL;
142
143     if(str) {
144         DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
145         ret = heap_alloc(size);
146         if(ret)
147             WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
148     }
149
150     return ret;
151 }
152
153 static inline void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW, LPWIN32_FIND_DATAA dataA)
154 {
155     dataA->dwFileAttributes = dataW->dwFileAttributes;
156     dataA->ftCreationTime   = dataW->ftCreationTime;
157     dataA->ftLastAccessTime = dataW->ftLastAccessTime;
158     dataA->ftLastWriteTime  = dataW->ftLastWriteTime;
159     dataA->nFileSizeHigh    = dataW->nFileSizeHigh;
160     dataA->nFileSizeLow     = dataW->nFileSizeLow;
161     dataA->dwReserved0      = dataW->dwReserved0;
162     dataA->dwReserved1      = dataW->dwReserved1;
163     WideCharToMultiByte(CP_ACP, 0, dataW->cFileName, -1, 
164         dataA->cFileName, sizeof(dataA->cFileName),
165         NULL, NULL);
166     WideCharToMultiByte(CP_ACP, 0, dataW->cAlternateFileName, -1, 
167         dataA->cAlternateFileName, sizeof(dataA->cAlternateFileName),
168         NULL, NULL);
169 }
170
171 typedef enum
172 {
173     WH_HINIT = INTERNET_HANDLE_TYPE_INTERNET,
174     WH_HFTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_FTP,
175     WH_HGOPHERSESSION = INTERNET_HANDLE_TYPE_CONNECT_GOPHER,
176     WH_HHTTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_HTTP,
177     WH_HFILE = INTERNET_HANDLE_TYPE_FTP_FILE,
178     WH_HFTPFINDNEXT = INTERNET_HANDLE_TYPE_FTP_FIND,
179     WH_HHTTPREQ = INTERNET_HANDLE_TYPE_HTTP_REQUEST,
180 } WH_TYPE;
181
182 #define INET_OPENURL 0x0001
183 #define INET_CALLBACKW 0x0002
184
185 typedef struct _object_header_t object_header_t;
186
187 typedef struct {
188     void (*Destroy)(object_header_t*);
189     void (*CloseConnection)(object_header_t*);
190     DWORD (*QueryOption)(object_header_t*,DWORD,void*,DWORD*,BOOL);
191     DWORD (*SetOption)(object_header_t*,DWORD,void*,DWORD);
192     DWORD (*ReadFile)(object_header_t*,void*,DWORD,DWORD*);
193     DWORD (*ReadFileExA)(object_header_t*,INTERNET_BUFFERSA*,DWORD,DWORD_PTR);
194     DWORD (*ReadFileExW)(object_header_t*,INTERNET_BUFFERSW*,DWORD,DWORD_PTR);
195     DWORD (*WriteFile)(object_header_t*,const void*,DWORD,DWORD*);
196     DWORD (*QueryDataAvailable)(object_header_t*,DWORD*,DWORD,DWORD_PTR);
197     DWORD (*FindNextFileW)(object_header_t*,void*);
198 } object_vtbl_t;
199
200 #define INTERNET_HANDLE_IN_USE 1
201
202 struct _object_header_t
203 {
204     WH_TYPE htype;
205     const object_vtbl_t *vtbl;
206     HINTERNET hInternet;
207     BOOL valid_handle;
208     DWORD  dwFlags;
209     DWORD_PTR dwContext;
210     DWORD  dwError;
211     ULONG  ErrorMask;
212     DWORD  dwInternalFlags;
213     LONG   refs;
214     INTERNET_STATUS_CALLBACK lpfnStatusCB;
215     struct list entry;
216     struct list children;
217 };
218
219
220 typedef struct
221 {
222     object_header_t hdr;
223     LPWSTR  agent;
224     LPWSTR  proxy;
225     LPWSTR  proxyBypass;
226     LPWSTR  proxyUsername;
227     LPWSTR  proxyPassword;
228     DWORD   accessType;
229 } appinfo_t;
230
231
232 typedef struct
233 {
234     object_header_t hdr;
235     appinfo_t *appInfo;
236     LPWSTR  hostName; /* the final destination of the request */
237     LPWSTR  serverName; /* the name of the server we directly connect to */
238     LPWSTR  userName;
239     LPWSTR  password;
240     INTERNET_PORT hostPort; /* the final destination port of the request */
241     INTERNET_PORT serverPort; /* the port of the server we directly connect to */
242     struct sockaddr_storage socketAddress;
243     socklen_t sa_len;
244 } http_session_t;
245
246 #define HDR_ISREQUEST           0x0001
247 #define HDR_COMMADELIMITED      0x0002
248 #define HDR_SEMIDELIMITED       0x0004
249
250 typedef struct
251 {
252     LPWSTR lpszField;
253     LPWSTR lpszValue;
254     WORD wFlags;
255     WORD wCount;
256 } HTTPHEADERW, *LPHTTPHEADERW;
257
258
259 struct HttpAuthInfo;
260
261 typedef struct data_stream_vtbl_t data_stream_vtbl_t;
262
263 typedef struct {
264     const data_stream_vtbl_t *vtbl;
265 }  data_stream_t;
266
267 typedef struct {
268     data_stream_t data_stream;
269     DWORD content_length;
270     DWORD content_read;
271 } netconn_stream_t;
272
273 #define READ_BUFFER_SIZE 8192
274
275 typedef struct
276 {
277     object_header_t hdr;
278     http_session_t *session;
279     LPWSTR path;
280     LPWSTR verb;
281     LPWSTR rawHeaders;
282     WININET_NETCONNECTION netConnection;
283     LPWSTR version;
284     LPWSTR statusText;
285     DWORD bytesToWrite;
286     DWORD bytesWritten;
287     HTTPHEADERW *custHeaders;
288     DWORD nCustHeaders;
289     FILETIME last_modified;
290     HANDLE hCacheFile;
291     LPWSTR cacheFile;
292     FILETIME expires;
293     struct HttpAuthInfo *authInfo;
294     struct HttpAuthInfo *proxyAuthInfo;
295
296     CRITICAL_SECTION read_section;  /* section to protect the following fields */
297     DWORD contentLength;  /* total number of bytes to be read */
298     BOOL  read_chunked;   /* are we reading in chunked mode? */
299     BOOL  read_gzip;      /* are we reading in gzip mode? */
300     DWORD read_pos;       /* current read position in read_buf */
301     DWORD read_size;      /* valid data size in read_buf */
302     BYTE  read_buf[READ_BUFFER_SIZE]; /* buffer for already read but not returned data */
303
304     BOOL decoding;
305     data_stream_t *data_stream;
306     netconn_stream_t netconn_stream;
307 } http_request_t;
308
309
310
311 struct WORKREQ_FTPPUTFILEW
312 {
313     LPWSTR lpszLocalFile;
314     LPWSTR lpszNewRemoteFile;
315     DWORD  dwFlags;
316     DWORD_PTR dwContext;
317 };
318
319 struct WORKREQ_FTPSETCURRENTDIRECTORYW
320 {
321     LPWSTR lpszDirectory;
322 };
323
324 struct WORKREQ_FTPCREATEDIRECTORYW
325 {
326     LPWSTR lpszDirectory;
327 };
328
329 struct WORKREQ_FTPFINDFIRSTFILEW
330 {
331     LPWSTR lpszSearchFile;
332     LPWIN32_FIND_DATAW lpFindFileData;
333     DWORD  dwFlags;
334     DWORD_PTR dwContext;
335 };
336
337 struct WORKREQ_FTPGETCURRENTDIRECTORYW
338 {
339     LPWSTR lpszDirectory;
340     DWORD *lpdwDirectory;
341 };
342
343 struct WORKREQ_FTPOPENFILEW
344 {
345     LPWSTR lpszFilename;
346     DWORD  dwAccess;
347     DWORD  dwFlags;
348     DWORD_PTR dwContext;
349 };
350
351 struct WORKREQ_FTPGETFILEW
352 {
353     LPWSTR lpszRemoteFile;
354     LPWSTR lpszNewFile;
355     BOOL   fFailIfExists;
356     DWORD  dwLocalFlagsAttribute;
357     DWORD  dwFlags;
358     DWORD_PTR dwContext;
359 };
360
361 struct WORKREQ_FTPDELETEFILEW
362 {
363     LPWSTR lpszFilename;
364 };
365
366 struct WORKREQ_FTPREMOVEDIRECTORYW
367 {
368     LPWSTR lpszDirectory;
369 };
370
371 struct WORKREQ_FTPRENAMEFILEW
372 {
373     LPWSTR lpszSrcFile;
374     LPWSTR lpszDestFile;
375 };
376
377 struct WORKREQ_FTPFINDNEXTW
378 {
379     LPWIN32_FIND_DATAW lpFindFileData;
380 };
381
382 struct WORKREQ_HTTPSENDREQUESTW
383 {
384     LPWSTR lpszHeader;
385     DWORD  dwHeaderLength;
386     LPVOID lpOptional;
387     DWORD  dwOptionalLength;
388     DWORD  dwContentLength;
389     BOOL   bEndRequest;
390 };
391
392 struct WORKREQ_HTTPENDREQUESTW
393 {
394     DWORD     dwFlags;
395     DWORD_PTR dwContext;
396 };
397
398 struct WORKREQ_SENDCALLBACK
399 {
400     DWORD_PTR dwContext;
401     DWORD     dwInternetStatus;
402     LPVOID    lpvStatusInfo;
403     DWORD     dwStatusInfoLength;
404 };
405
406 struct WORKREQ_INTERNETOPENURLW
407 {
408     HINTERNET hInternet;
409     LPWSTR     lpszUrl;
410     LPWSTR     lpszHeaders;
411     DWORD     dwHeadersLength;
412     DWORD     dwFlags;
413     DWORD_PTR dwContext;
414 };
415
416 struct WORKREQ_INTERNETREADFILEEXA
417 {
418     LPINTERNET_BUFFERSA lpBuffersOut;
419 };
420
421 struct WORKREQ_INTERNETREADFILEEXW
422 {
423     LPINTERNET_BUFFERSW lpBuffersOut;
424 };
425
426 typedef struct WORKREQ
427 {
428     void (*asyncproc)(struct WORKREQ*);
429     object_header_t *hdr;
430
431     union {
432         struct WORKREQ_FTPPUTFILEW              FtpPutFileW;
433         struct WORKREQ_FTPSETCURRENTDIRECTORYW  FtpSetCurrentDirectoryW;
434         struct WORKREQ_FTPCREATEDIRECTORYW      FtpCreateDirectoryW;
435         struct WORKREQ_FTPFINDFIRSTFILEW        FtpFindFirstFileW;
436         struct WORKREQ_FTPGETCURRENTDIRECTORYW  FtpGetCurrentDirectoryW;
437         struct WORKREQ_FTPOPENFILEW             FtpOpenFileW;
438         struct WORKREQ_FTPGETFILEW              FtpGetFileW;
439         struct WORKREQ_FTPDELETEFILEW           FtpDeleteFileW;
440         struct WORKREQ_FTPREMOVEDIRECTORYW      FtpRemoveDirectoryW;
441         struct WORKREQ_FTPRENAMEFILEW           FtpRenameFileW;
442         struct WORKREQ_FTPFINDNEXTW             FtpFindNextW;
443         struct WORKREQ_HTTPSENDREQUESTW         HttpSendRequestW;
444         struct WORKREQ_HTTPENDREQUESTW          HttpEndRequestW;
445         struct WORKREQ_SENDCALLBACK             SendCallback;
446         struct WORKREQ_INTERNETOPENURLW         InternetOpenUrlW;
447         struct WORKREQ_INTERNETREADFILEEXA      InternetReadFileExA;
448         struct WORKREQ_INTERNETREADFILEEXW      InternetReadFileExW;
449     } u;
450
451 } WORKREQUEST, *LPWORKREQUEST;
452
453 void *alloc_object(object_header_t*,const object_vtbl_t*,size_t);
454 object_header_t *get_handle_object( HINTERNET hinternet );
455 object_header_t *WININET_AddRef( object_header_t *info );
456 BOOL WININET_Release( object_header_t *info );
457
458 DWORD INET_QueryOption( object_header_t *, DWORD, void *, DWORD *, BOOL );
459
460 time_t ConvertTimeString(LPCWSTR asctime);
461
462 HINTERNET FTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName,
463         INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
464         LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
465         DWORD dwInternalFlags);
466
467 DWORD HTTP_Connect(appinfo_t*,LPCWSTR,
468         INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
469         LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
470         DWORD dwInternalFlags, HINTERNET*);
471
472 BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
473         struct sockaddr *psa, socklen_t *sa_len);
474
475 void INTERNET_SetLastError(DWORD dwError);
476 DWORD INTERNET_GetLastError(void);
477 DWORD INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest);
478 LPSTR INTERNET_GetResponseBuffer(void);
479 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen);
480
481 VOID SendAsyncCallback(object_header_t *hdr, DWORD_PTR dwContext,
482                        DWORD dwInternetStatus, LPVOID lpvStatusInfo,
483                        DWORD dwStatusInfoLength);
484
485 VOID INTERNET_SendCallback(object_header_t *hdr, DWORD_PTR dwContext,
486                            DWORD dwInternetStatus, LPVOID lpvStatusInfo,
487                            DWORD dwStatusInfoLength);
488 BOOL INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto, WCHAR *foundProxy, DWORD *foundProxyLen);
489
490 BOOL NETCON_connected(WININET_NETCONNECTION *connection);
491 DWORD NETCON_init(WININET_NETCONNECTION *connnection, BOOL useSSL);
492 void NETCON_unload(void);
493 DWORD NETCON_create(WININET_NETCONNECTION *connection, int domain,
494               int type, int protocol);
495 DWORD NETCON_close(WININET_NETCONNECTION *connection);
496 DWORD NETCON_connect(WININET_NETCONNECTION *connection, const struct sockaddr *serv_addr,
497                     unsigned int addrlen);
498 DWORD NETCON_secure_connect(WININET_NETCONNECTION *connection, LPWSTR hostname);
499 DWORD NETCON_send(WININET_NETCONNECTION *connection, const void *msg, size_t len, int flags,
500                 int *sent /* out */);
501 DWORD NETCON_recv(WININET_NETCONNECTION *connection, void *buf, size_t len, int flags,
502                 int *recvd /* out */);
503 BOOL NETCON_query_data_available(WININET_NETCONNECTION *connection, DWORD *available);
504 LPCVOID NETCON_GetCert(WININET_NETCONNECTION *connection);
505 int NETCON_GetCipherStrength(WININET_NETCONNECTION *connection);
506 DWORD NETCON_set_timeout(WININET_NETCONNECTION *connection, BOOL send, int value);
507 int sock_get_error(int);
508
509 extern void URLCacheContainers_CreateDefaults(void);
510 extern void URLCacheContainers_DeleteAll(void);
511
512 #define MAX_REPLY_LEN           0x5B4
513
514 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
515 typedef struct
516 {
517     DWORD val;
518     const char* name;
519 } wininet_flag_info;
520
521 #endif /* _WINE_INTERNET_H_ */